diff options
author | Krishnan Parthasarathi <kparthas@redhat.com> | 2013-12-16 10:29:19 +0530 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2013-12-23 07:00:24 -0800 |
commit | 94ed403ec213ee955acc55cc4a04f7c39470855b (patch) | |
tree | 418b0821b4fb34333494d01d886c978bd9bdf2d3 | |
parent | 0a99ef20b8e8f3486f5ada8e82e4634eb9fbf62b (diff) |
glusterd: make volinfo a refcnt'ed object.
Backport of http://review.gluster.org/6521
Add glusterd_volinfo_remove(..) which removes @volinfo from the list
of volumes in the cluster and performs an unref on @volinfo
Change-Id: I5f546ca58f61bc334ab1bab4c51c4a21e1f66161
BUG: 1038051
Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com>
Reviewed-on: http://review.gluster.org/6569
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-store.c | 2 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.c | 47 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-utils.h | 6 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 2 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 2 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd.h | 2 |
6 files changed, 55 insertions, 6 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index 2ba2548d20d..3a4b090096b 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -166,7 +166,7 @@ out: if (brickinfo) glusterd_brickinfo_delete (brickinfo); if (volinfo) - glusterd_volinfo_delete (volinfo); + glusterd_volinfo_unref (volinfo); return ret; } diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index bdfa8eebcc2..9a4072ce819 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -445,6 +445,37 @@ glusterd_check_volume_exists (char *volname) return _gf_true; } +glusterd_volinfo_t * +glusterd_volinfo_unref (glusterd_volinfo_t *volinfo) +{ + int refcnt = -1; + + pthread_mutex_lock (&volinfo->reflock); + { + refcnt = --volinfo->refcnt; + } + pthread_mutex_unlock (&volinfo->reflock); + + if (!refcnt) { + glusterd_volinfo_delete (volinfo); + return NULL; + } + + return volinfo; +} + +glusterd_volinfo_t * +glusterd_volinfo_ref (glusterd_volinfo_t *volinfo) +{ + pthread_mutex_lock (&volinfo->reflock); + { + ++volinfo->refcnt; + } + pthread_mutex_unlock (&volinfo->reflock); + + return volinfo; +} + int32_t glusterd_volinfo_new (glusterd_volinfo_t **volinfo) { @@ -478,7 +509,8 @@ glusterd_volinfo_new (glusterd_volinfo_t **volinfo) new_volinfo->xl = THIS; - *volinfo = new_volinfo; + pthread_mutex_init (&new_volinfo->reflock, NULL); + *volinfo = glusterd_volinfo_ref (new_volinfo); ret = 0; @@ -571,6 +603,14 @@ out: return ret; } +int +glusterd_volinfo_remove (glusterd_volinfo_t *volinfo) +{ + list_del_init (&volinfo->vol_list); + glusterd_volinfo_unref (volinfo); + return 0; +} + int32_t glusterd_volinfo_delete (glusterd_volinfo_t *volinfo) { @@ -595,6 +635,7 @@ glusterd_volinfo_delete (glusterd_volinfo_t *volinfo) glusterd_auth_cleanup (volinfo); + pthread_mutex_destroy (&volinfo->reflock); GF_FREE (volinfo); ret = 0; @@ -3404,7 +3445,7 @@ glusterd_delete_stale_volume (glusterd_volinfo_t *stale_volinfo, (void) gf_store_handle_destroy (stale_volinfo->shandle); stale_volinfo->shandle = NULL; } - (void) glusterd_volinfo_delete (stale_volinfo); + (void) glusterd_volinfo_remove (stale_volinfo); return 0; } @@ -6128,7 +6169,7 @@ glusterd_delete_volume (glusterd_volinfo_t *volinfo) if (ret) goto out; - ret = glusterd_volinfo_delete (volinfo); + glusterd_volinfo_remove (volinfo); out: gf_log (THIS->name, GF_LOG_DEBUG, "returning %d", ret); return ret; diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index fd3f5772922..ec515591885 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -137,6 +137,12 @@ glusterd_volume_stop_glusterfs (glusterd_volinfo_t *volinfo, glusterd_brickinfo_t *brickinfo, gf_boolean_t del_brick); +glusterd_volinfo_t * +glusterd_volinfo_ref (glusterd_volinfo_t *volinfo); + +glusterd_volinfo_t * +glusterd_volinfo_unref (glusterd_volinfo_t *volinfo); + int32_t glusterd_volinfo_delete (glusterd_volinfo_t *volinfo); diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index dcff8c30517..0a674634956 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -3184,7 +3184,7 @@ out: if (brickinfo) glusterd_brickinfo_delete (brickinfo); if (volinfo) - glusterd_volinfo_delete (volinfo); + glusterd_volinfo_unref (volinfo); return ret; } diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index 41555230e92..df2562ba69f 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -1696,7 +1696,7 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr) out: GF_FREE(free_ptr); if (!vol_added && volinfo) - glusterd_volinfo_delete (volinfo); + glusterd_volinfo_unref (volinfo); return ret; } diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h index e1e9e591f39..adef551280e 100644 --- a/xlators/mgmt/glusterd/src/glusterd.h +++ b/xlators/mgmt/glusterd/src/glusterd.h @@ -318,6 +318,8 @@ struct glusterd_volinfo_ { int op_version; int client_op_version; + pthread_mutex_t reflock; + int refcnt; }; typedef enum gd_node_type_ { |