summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c47
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h6
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volume-ops.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h2
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 26a67184f5d..9ad4963beb1 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;
}
@@ -6181,7 +6222,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 9ef09d7b089..05d5c7172b2 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 23b4205b0be..ab383ac1c9a 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_ {