diff options
Diffstat (limited to 'api/src/glfs.c')
| -rw-r--r-- | api/src/glfs.c | 64 | 
1 files changed, 49 insertions, 15 deletions
diff --git a/api/src/glfs.c b/api/src/glfs.c index 12c4ea4aebb..0dc535eb9e9 100644 --- a/api/src/glfs.c +++ b/api/src/glfs.c @@ -574,6 +574,7 @@ pub_glfs_new (const char *volname)  	pthread_mutex_init (&fs->mutex, NULL);  	pthread_cond_init (&fs->cond, NULL); +        pthread_cond_init (&fs->child_down_cond, NULL);  	INIT_LIST_HEAD (&fs->openfds); @@ -615,6 +616,7 @@ priv_glfs_free_from_ctx (struct glfs *fs)                  return;          (void) pthread_cond_destroy (&fs->cond); +        (void) pthread_cond_destroy (&fs->child_down_cond);          (void) pthread_mutex_destroy (&fs->mutex); @@ -802,15 +804,16 @@ priv_glfs_active_subvol (struct glfs *);  int  pub_glfs_fini (struct glfs *fs)  { -        int             ret = -1; -        int             countdown = 100; -        xlator_t        *subvol = NULL; -        glusterfs_ctx_t *ctx = NULL; -        call_pool_t     *call_pool = NULL; -        int             fs_init = 0; +        int                ret = -1; +        int                countdown = 100; +        xlator_t           *subvol = NULL; +        glusterfs_ctx_t    *ctx = NULL; +        glusterfs_graph_t  *graph = NULL; +        call_pool_t        *call_pool = NULL; +        int                fs_init = 0; +        int                err = -1;          ctx = fs->ctx; -          if (ctx->mgmt) {                  rpc_clnt_disable (ctx->mgmt);                  ctx->mgmt = NULL; @@ -841,24 +844,55 @@ pub_glfs_fini (struct glfs *fs)          if (fs_init != 0) {                  subvol = priv_glfs_active_subvol (fs);                  if (subvol) { -                        /* PARENT_DOWN within priv_glfs_subvol_done() is issued only -                           on graph switch (new graph should activiate and -                           decrement the extra @winds count taken in glfs_graph_setup() +                        /* 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 +                           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. +                        /* Here we wait for GF_EVENT_CHILD_DOWN before exiting, +                           in case of asynchrnous cleanup                          */ +                        graph = subvol->graph; +                        err = pthread_mutex_lock (&fs->mutex); +                        if (err != 0) { +                                gf_log ("glfs", GF_LOG_ERROR, +                                        "pthread lock on glfs mutex, " +                                        "returned error: (%s)", strerror (err)); +                                goto fail; +                        } +                        /* check and wait for CHILD_DOWN for active subvol*/ +                        { +                                while (graph->used) { +                                        err = pthread_cond_wait (&fs->child_down_cond, +                                                                 &fs->mutex); +                                        if (err != 0) +                                                gf_log ("glfs", GF_LOG_INFO, +                                                        "%s cond wait failed %s", +                                                        subvol->name, +                                                        strerror (err)); +                                } +                        } + +                        err = pthread_mutex_unlock (&fs->mutex); +                        if (err != 0) { +                                gf_log ("glfs", GF_LOG_ERROR, +                                        "pthread unlock on glfs mutex, " +                                        "returned error: (%s)", strerror (err)); +                                goto fail; +                        }                  }                  priv_glfs_subvol_done (fs, subvol);          }          if (gf_log_fini(ctx) != 0)                  ret = -1; - +fail: +        if (!ret) +                ret = err;          return ret;  }  | 
