From d22ef520174e10aeab8898542e2680c0c1892df6 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Fri, 14 May 2010 11:16:31 +1000 Subject: [PATCH] update the internal ctdb_ctrl_createdb() call to use the async libctdb code --- client/ctdb_client.c | 32 ++++++++++++++++++-------------- include/ctdb.h | 4 ++-- include/ctdb_protocol.h | 2 +- libctdb/libctdb.c | 4 ++-- server/ctdb_recoverd.c | 4 ++-- 5 files changed, 25 insertions(+), 21 deletions(-) diff --git a/client/ctdb_client.c b/client/ctdb_client.c index a3349e0b..3032213e 100644 --- a/client/ctdb_client.c +++ b/client/ctdb_client.c @@ -885,22 +885,26 @@ int ctdb_ctrl_getdbhealth(struct ctdb_context *ctdb, /* create a database */ -int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, - TALLOC_CTX *mem_ctx, const char *name, bool persistent) +int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, + uint32_t destnode, + const char *name, bool persistent) { int ret; - int32_t res; - TDB_DATA data; + ctdb_handle *handle; - data.dptr = discard_const(name); - data.dsize = strlen(name)+1; + handle = ctdb_createdb_send(ctdb, destnode, name, persistent, NULL, NULL); + if (handle == NULL) { + DEBUG(DEBUG_ERR, (__location__ " Failed to send createdb control\n")); + return -1; + } - ret = ctdb_control(ctdb, destnode, 0, - persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH, - 0, data, - mem_ctx, &data, &res, &timeout, NULL); + if (!timeval_is_zero(&timeout)) { + event_add_timed(ctdb->ev, handle, timeout, ctdb_control_timeout_func, handle); + } - if (ret != 0 || res != 0) { + ret = ctdb_createdb_recv(ctdb, handle); + if (ret != 0) { + DEBUG(DEBUG_ERR,(__location__ " ctdb control for createdb failed\n")); return -1; } @@ -1213,7 +1217,7 @@ int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void * data, NULL, NULL, &status, NULL, NULL); if (ret != 0 || status != 0) { DEBUG(DEBUG_ERR,("ctdb_traverse_all failed\n")); - ctdb_remove_message_handler(ctdb_db->ctdb, srvid, &state); + ctdb_remove_message_handler(ctdb_db->ctdb, srvid); return -1; } @@ -1221,7 +1225,7 @@ int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void * event_loop_once(ctdb_db->ctdb->ev); } - ret = ctdb_remove_message_handler(ctdb_db->ctdb, srvid, &state); + ret = ctdb_remove_message_handler(ctdb_db->ctdb, srvid); if (ret != 0) { DEBUG(DEBUG_ERR,("Failed to remove ctdb_traverse handler\n")); return -1; @@ -1408,7 +1412,7 @@ int ctdb_ctrl_getpnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t ret = ctdb_getpnn_recv(ctdb, handle, &pnn); if (ret != 0) { - DEBUG(DEBUG_ERR,(__location__ " ctdb_control for getpnn failed\n")); + DEBUG(DEBUG_ERR,(__location__ " ctdb control for getpnn failed\n")); return -1; } diff --git a/include/ctdb.h b/include/ctdb.h index bebf8042..cf616583 100644 --- a/include/ctdb.h +++ b/include/ctdb.h @@ -160,13 +160,13 @@ typedef void (*ctdb_createdb_cb)(int32_t status, void *private_data); ctdb_handle * ctdb_createdb_send(struct ctdb_context *ctdb, uint32_t destnode, - const char *name, bool persistent, + const char *name, int persistent, ctdb_createdb_cb callback, void *private_data); int ctdb_createdb_recv(struct ctdb_context *ctdb, ctdb_handle *handle); int ctdb_createdb(struct ctdb_context *ctdb, uint32_t destnode, - const char *name, bool persistent); + const char *name, int persistent); diff --git a/include/ctdb_protocol.h b/include/ctdb_protocol.h index 22ea63d5..16f8d1ef 100644 --- a/include/ctdb_protocol.h +++ b/include/ctdb_protocol.h @@ -377,7 +377,7 @@ int ctdb_ctrl_getdbhealth(struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **reason); -int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, const char *name, bool persistent); +int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, const char *name, bool persistent); int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid); diff --git a/libctdb/libctdb.c b/libctdb/libctdb.c index f91dd93f..3314f4b1 100644 --- a/libctdb/libctdb.c +++ b/libctdb/libctdb.c @@ -484,7 +484,7 @@ ctdb_createdb_recv_cb(struct ctdb_client_control_state *state) ctdb_handle * ctdb_createdb_send(struct ctdb_context *ctdb, uint32_t destnode, - const char *name, bool persistent, + const char *name, int persistent, ctdb_createdb_cb callback, void *private_data) @@ -533,7 +533,7 @@ int ctdb_createdb_recv(struct ctdb_context *ctdb, ctdb_handle *handle) return state->status; } -int ctdb_createdb(struct ctdb_context *ctdb, uint32_t destnode, const char *name, bool persistent) +int ctdb_createdb(struct ctdb_context *ctdb, uint32_t destnode, const char *name, int persistent) { struct ctdb_client_control_state *state; diff --git a/server/ctdb_recoverd.c b/server/ctdb_recoverd.c index d3e6a3c5..01745099 100644 --- a/server/ctdb_recoverd.c +++ b/server/ctdb_recoverd.c @@ -438,7 +438,7 @@ static int create_missing_remote_databases(struct ctdb_context *ctdb, struct ctd return -1; } ctdb_ctrl_createdb(ctdb, CONTROL_TIMEOUT(), nodemap->nodes[j].pnn, - mem_ctx, name, dbmap->dbs[db].persistent); + name, dbmap->dbs[db].persistent); if (ret != 0) { DEBUG(DEBUG_ERR, (__location__ " Unable to create remote db:%s\n", name)); return -1; @@ -500,7 +500,7 @@ static int create_missing_local_databases(struct ctdb_context *ctdb, struct ctdb nodemap->nodes[j].pnn)); return -1; } - ctdb_ctrl_createdb(ctdb, CONTROL_TIMEOUT(), pnn, mem_ctx, name, + ctdb_ctrl_createdb(ctdb, CONTROL_TIMEOUT(), pnn, name, remote_dbmap->dbs[db].persistent); if (ret != 0) { DEBUG(DEBUG_ERR, (__location__ " Unable to create local db:%s\n", name)); -- 2.34.1