summaryrefslogtreecommitdiff
path: root/ctdb
diff options
context:
space:
mode:
authorDavid Disseldorp <ddiss@samba.org>2018-07-19 18:46:27 +0200
committerKarolin Seeger <kseeger@samba.org>2018-08-23 10:38:27 +0200
commitaf08da45716f713ed1897a23d814cb679f3f24bf (patch)
tree970edd39aaa309fea56ef0ec97230d201531ce4a /ctdb
parent6dc7dc9300014485ec5e6e1e9bfb8eb2d89c4033 (diff)
downloadsamba-af08da45716f713ed1897a23d814cb679f3f24bf.tar.gz
ctdb_mutex_ceph_rados_helper: use talloc destructor for cleanup
Signed-off-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Samuel Cabrero <scabrero@suse.de> Reviewed-by: Amitay Isaacs <amitay@gmail.com> (cherry picked from commit 8d30fd591600ac17c742cd78c7bc4056bba6b877)
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/utils/ceph/ctdb_mutex_ceph_rados_helper.c51
1 files changed, 24 insertions, 27 deletions
diff --git a/ctdb/utils/ceph/ctdb_mutex_ceph_rados_helper.c b/ctdb/utils/ceph/ctdb_mutex_ceph_rados_helper.c
index b5cd1ebad12..9c31e310b91 100644
--- a/ctdb/utils/ceph/ctdb_mutex_ceph_rados_helper.c
+++ b/ctdb/utils/ceph/ctdb_mutex_ceph_rados_helper.c
@@ -88,13 +88,6 @@ static int ctdb_mutex_rados_ctx_create(const char *ceph_cluster_name,
return 0;
}
-static void ctdb_mutex_rados_ctx_destroy(rados_t ceph_cluster,
- rados_ioctx_t ioctx)
-{
- rados_ioctx_destroy(ioctx);
- rados_shutdown(ceph_cluster);
-}
-
static int ctdb_mutex_rados_lock(rados_ioctx_t *ioctx,
const char *oid)
{
@@ -162,18 +155,13 @@ static void ctdb_mutex_rados_sigterm_cb(struct tevent_context *ev,
void *private_data)
{
struct ctdb_mutex_rados_state *cmr_state = private_data;
- int ret;
+ int ret = 0;
if (!cmr_state->holding_mutex) {
fprintf(stderr, "Sigterm callback invoked without mutex!\n");
ret = -EINVAL;
- goto err_ctx_cleanup;
}
- ret = ctdb_mutex_rados_unlock(cmr_state->ioctx, cmr_state->object);
-err_ctx_cleanup:
- ctdb_mutex_rados_ctx_destroy(cmr_state->ceph_cluster,
- cmr_state->ioctx);
talloc_free(cmr_state);
exit(ret ? 1 : 0);
}
@@ -184,7 +172,7 @@ static void ctdb_mutex_rados_timer_cb(struct tevent_context *ev,
void *private_data)
{
struct ctdb_mutex_rados_state *cmr_state = private_data;
- int ret;
+ int ret = 0;
if (!cmr_state->holding_mutex) {
fprintf(stderr, "Timer callback invoked without mutex!\n");
@@ -205,15 +193,26 @@ static void ctdb_mutex_rados_timer_cb(struct tevent_context *ev,
return;
}
- /* parent ended, drop lock and exit */
- ret = ctdb_mutex_rados_unlock(cmr_state->ioctx, cmr_state->object);
+ /* parent ended, drop lock (via destructor) and exit */
err_ctx_cleanup:
- ctdb_mutex_rados_ctx_destroy(cmr_state->ceph_cluster,
- cmr_state->ioctx);
talloc_free(cmr_state);
exit(ret ? 1 : 0);
}
+static int ctdb_mutex_rados_state_destroy(struct ctdb_mutex_rados_state *cmr_state)
+{
+ if (cmr_state->holding_mutex) {
+ ctdb_mutex_rados_unlock(cmr_state->ioctx, cmr_state->object);
+ }
+ if (cmr_state->ioctx != NULL) {
+ rados_ioctx_destroy(cmr_state->ioctx);
+ }
+ if (cmr_state->ceph_cluster != NULL) {
+ rados_shutdown(cmr_state->ceph_cluster);
+ }
+ return 0;
+}
+
int main(int argc, char *argv[])
{
int ret;
@@ -241,6 +240,7 @@ int main(int argc, char *argv[])
goto err_out;
}
+ talloc_set_destructor(cmr_state, ctdb_mutex_rados_state_destroy);
cmr_state->ceph_cluster_name = argv[1];
cmr_state->ceph_auth_name = argv[2];
cmr_state->pool_name = argv[3];
@@ -258,7 +258,7 @@ int main(int argc, char *argv[])
*/
fprintf(stderr, "%s: PPID == 1\n", progname);
ret = -EPIPE;
- goto err_state_free;
+ goto err_ctx_cleanup;
}
cmr_state->ev = tevent_context_init(cmr_state);
@@ -266,7 +266,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "tevent_context_init failed\n");
fprintf(stdout, CTDB_MUTEX_STATUS_ERROR);
ret = -ENOMEM;
- goto err_state_free;
+ goto err_ctx_cleanup;
}
/* wait for sigterm */
@@ -277,7 +277,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Failed to create term signal event\n");
fprintf(stdout, CTDB_MUTEX_STATUS_ERROR);
ret = -ENOMEM;
- goto err_state_free;
+ goto err_ctx_cleanup;
}
cmr_state->sigint_ev = tevent_add_signal(cmr_state->ev, cmr_state, SIGINT, 0,
@@ -287,7 +287,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Failed to create int signal event\n");
fprintf(stdout, CTDB_MUTEX_STATUS_ERROR);
ret = -ENOMEM;
- goto err_state_free;
+ goto err_ctx_cleanup;
}
/* periodically check parent */
@@ -299,7 +299,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "Failed to create timer event\n");
fprintf(stdout, CTDB_MUTEX_STATUS_ERROR);
ret = -ENOMEM;
- goto err_state_free;
+ goto err_ctx_cleanup;
}
ret = ctdb_mutex_rados_ctx_create(cmr_state->ceph_cluster_name,
@@ -309,7 +309,7 @@ int main(int argc, char *argv[])
&cmr_state->ioctx);
if (ret < 0) {
fprintf(stdout, CTDB_MUTEX_STATUS_ERROR);
- goto err_state_free;
+ goto err_ctx_cleanup;
}
ret = ctdb_mutex_rados_lock(cmr_state->ioctx, cmr_state->object);
@@ -330,9 +330,6 @@ int main(int argc, char *argv[])
goto err_ctx_cleanup;
}
err_ctx_cleanup:
- ctdb_mutex_rados_ctx_destroy(cmr_state->ceph_cluster,
- cmr_state->ioctx);
-err_state_free:
talloc_free(cmr_state);
err_out:
return ret ? 1 : 0;