diff options
author | Martin Schwenke <martin@meltin.net> | 2016-06-01 17:45:36 +1000 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2016-06-08 00:51:29 +0200 |
commit | 8cf74f335e442733cbcc02cf33eaa2226b70a8a5 (patch) | |
tree | 36db3a501465976185e7cb2d846f6e39e8a2c1e3 /ctdb/server/ctdb_recover.c | |
parent | a192364a1254172329b0b5d687105eed2c537f21 (diff) | |
download | samba-8cf74f335e442733cbcc02cf33eaa2226b70a8a5.tar.gz |
ctdb-recovery: Wrap private data for reclock test callback
This will allow a simplification of the cluster mutex API, so the
private data can be registered when calling ctdb_cluster_mutex().
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/server/ctdb_recover.c')
-rw-r--r-- | ctdb/server/ctdb_recover.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/ctdb/server/ctdb_recover.c b/ctdb/server/ctdb_recover.c index 2f5e570dd0a..94732a8c5d5 100644 --- a/ctdb/server/ctdb_recover.c +++ b/ctdb/server/ctdb_recover.c @@ -749,18 +749,18 @@ int32_t ctdb_control_db_push_confirm(struct ctdb_context *ctdb, return 0; } +struct set_recmode_state { + struct ctdb_req_control_old *c; +}; + static void set_recmode_handler(struct ctdb_context *ctdb, char status, double latency, struct ctdb_cluster_mutex_handle *h, void *private_data) { - /* It would be good to use talloc_get_type() here. However, - * the name of the packet is manually set - not sure why. - * Could use talloc_check_name() but this seems like a lot of - * manual overkill. */ - struct ctdb_req_control_old *c = - (struct ctdb_req_control_old *) private_data; + struct set_recmode_state *state = talloc_get_type_abort( + private_data, struct set_recmode_state); int s = 0; const char *err = NULL; @@ -808,8 +808,8 @@ static void set_recmode_handler(struct ctdb_context *ctdb, err = "Unexpected error when testing recovery lock"; } - ctdb_request_control_reply(ctdb, c, NULL, s, err); - talloc_free(h); + ctdb_request_control_reply(ctdb, state->c, NULL, s, err); + talloc_free(state); } static void @@ -854,6 +854,7 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, uint32_t recmode = *(uint32_t *)indata.dptr; int i; struct ctdb_db_context *ctdb_db; + struct set_recmode_state *state; struct ctdb_cluster_mutex_handle *h; /* if we enter recovery but stay in recovery for too long @@ -908,15 +909,25 @@ int32_t ctdb_control_set_recmode(struct ctdb_context *ctdb, return 0; } - h = ctdb_cluster_mutex(ctdb, ctdb, ctdb->recovery_lock, 5); + state = talloc_zero(ctdb, struct set_recmode_state); + if (state == NULL) { + DEBUG(DEBUG_ERR, (__location__ " out of memory\n")); + return -1; + } + state->c = NULL; + + h = ctdb_cluster_mutex(state, ctdb, ctdb->recovery_lock, 5); if (h == NULL) { + talloc_free(state); return -1; } - /* set_recmode_handler() frees h */ + state->c = talloc_steal(state, c); + + /* set_recmode_handler() frees state/h */ ctdb_cluster_mutex_set_handler(h, set_recmode_handler, - talloc_steal(h, c)); + state); *async_reply = true; return 0; |