From d7f7510f218e656cf2ba3bd821b80c14ab53846a Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Wed, 28 Aug 2013 18:05:03 -0700 Subject: gfapi: implement a minimial glfs_fini() At the very least, we should PARENT_DOWN on the currently active graph and disconnect ourselves from glusterd. Further cleanups underway. Change-Id: I9276686a84b0975b5ce272b4cbec1b80920d5c5c BUG: 1004519 Signed-off-by: Anand Avati Reviewed-on: http://review.gluster.org/5788 Tested-by: Gluster Build System Reviewed-by: Raghavendra Bhat Reviewed-by: Amar Tumballi --- api/src/glfs.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- api/src/glfs.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 4 deletions(-) (limited to 'api') diff --git a/api/src/glfs.c b/api/src/glfs.c index 2200358c6..4a41db937 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -20,7 +20,6 @@ - handle SEEK_END failure in _lseek() - handle umask (per filesystem?) - make itables LRU based - - implement glfs_fini() - 0-copy for readv/writev - reconcile the open/creat mess */ @@ -51,6 +50,7 @@ #include "glfs.h" #include "glfs-internal.h" #include "hashfn.h" +#include "rpc-clnt.h" static gf_boolean_t @@ -595,7 +595,47 @@ glfs_init (struct glfs *fs) int glfs_fini (struct glfs *fs) { - int ret = -1; - - return ret; + int ret = -1; + xlator_t *subvol = NULL; + glusterfs_ctx_t *ctx = NULL; + call_pool_t *call_pool = NULL; + int countdown = 100; + + ctx = fs->ctx; + + if (ctx->mgmt) { + rpc_clnt_disable (ctx->mgmt); + ctx->mgmt = NULL; + } + + __glfs_entry_fs (fs); + + call_pool = fs->ctx->pool; + + while (countdown--) { + /* give some time for background frames to finish */ + if (!call_pool->cnt) + break; + usleep (100000); + } + /* leaked frames may exist, we ignore */ + + subvol = glfs_active_subvol (fs); + if (subvol) { + /* PARENT_DOWN within glfs_subvol_done() is issued only + on graph switch (new graph should activiate and + decrement the extra @winds count taken in glfs_graph_setup() + + Since we are explicitly destroying, PARENT_DOWN is necessary + */ + xlator_notify (subvol, GF_EVENT_PARENT_DOWN, subvol, 0); + /* TBD: wait for CHILD_DOWN before exiting, in case of + asynchronous cleanup like graceful socket disconnection + in the future. + */ + } + + glfs_subvol_done (fs, subvol); + + return ret; } diff --git a/api/src/glfs.h b/api/src/glfs.h index 519a04036..8aac6f8b6 100644 --- a/api/src/glfs.h +++ b/api/src/glfs.h @@ -218,6 +218,36 @@ int glfs_set_logging (glfs_t *fs, const char *logfile, int loglevel); int glfs_init (glfs_t *fs); +/* + SYNOPSIS + + glfs_fini: Cleanup and destroy the 'virtual mount' + + DESCRIPTION + + This function attempts to gracefully destroy glfs_t object. An attempt is + made to wait for all background processing to complete before returning. + + glfs_fini() must be called after all operations on glfs_t is finished. + + IMPORTANT + + IT IS NECESSARY TO CALL glfs_fini() ON ALL THE INITIALIZED glfs_t + OBJECTS BEFORE TERMINATING THE PROGRAM. THERE MAY BE CACHED AND + UNWRITTEN / INCOMPLETE OPERATIONS STILL IN PROGRESS EVEN THOUGH THE + API CALLS HAVE RETURNED. glfs_fini() WILL WAIT FOR BACKGROUND OPERATIONS + TO COMPLETE BEFORE RETURNING, THEREBY MAKING IT SAFE FOR THE PROGRAM TO + EXIT. + + PARAMETERS + + @fs: The 'virtual mount' object to be destroyed. + + RETURN VALUES + + 0 : Success. +*/ + int glfs_fini (glfs_t *fs); /* -- cgit