[SCM] CTDB repository - branch libctdb updated - ctdb-1.0.114-102-g92953f7
Ronnie Sahlberg
sahlberg at samba.org
Thu May 13 21:19:21 MDT 2010
The branch, libctdb has been updated
via 92953f7b0bee7f5312f5ef340a9638fbe4ba8f54 (commit)
via 016c664a1fe96c901b895c45934ede8200b9f2bb (commit)
via 5cacc95d6ad644f94809c3c96cf60348c88eef62 (commit)
via d22ef520174e10aeab8898542e2680c0c1892df6 (commit)
via ef0efc2840290aeaec96acd302ef5bfde5598cc2 (commit)
from f5ca198445ec9b6c6e989c52057a46c144e3a033 (commit)
http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=libctdb
- Log -----------------------------------------------------------------
commit 92953f7b0bee7f5312f5ef340a9638fbe4ba8f54
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Fri May 14 13:13:49 2010 +1000
change ctdb_ctrl_attach to use the new libctdb versions to create the database
commit 016c664a1fe96c901b895c45934ede8200b9f2bb
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Fri May 14 13:05:38 2010 +1000
we sometimes need to send special flags when asking ctdb to create a new database sicne ctdbd will also open the same database internally
commit 5cacc95d6ad644f94809c3c96cf60348c88eef62
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Fri May 14 12:43:00 2010 +1000
let the ctdb_createdb*() fucntions return the db_id
commit d22ef520174e10aeab8898542e2680c0c1892df6
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Fri May 14 11:16:31 2010 +1000
update the internal ctdb_ctrl_createdb() call to use the async libctdb code
commit ef0efc2840290aeaec96acd302ef5bfde5598cc2
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Fri May 14 10:59:45 2010 +1000
add a libctdb version of the control to create a database
-----------------------------------------------------------------------
Summary of changes:
client/ctdb_client.c | 57 +++++++++++++----------
include/ctdb.h | 24 +++++++++-
include/ctdb_protocol.h | 2 +-
libctdb/libctdb.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++-
libctdb/tst.c | 2 -
server/ctdb_recoverd.c | 4 +-
6 files changed, 173 insertions(+), 34 deletions(-)
Changeset truncated at 500 lines:
diff --git a/client/ctdb_client.c b/client/ctdb_client.c
index a3349e0..14005bc 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, 0, 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, NULL);
+ if (ret != 0) {
+ DEBUG(DEBUG_ERR,(__location__ " ctdb control for createdb failed\n"));
return -1;
}
@@ -1028,9 +1032,9 @@ static int ctdb_fetch_func(struct ctdb_call_info *call)
struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent, uint32_t tdb_flags)
{
struct ctdb_db_context *ctdb_db;
- TDB_DATA data;
int ret;
- int32_t res;
+ uint32_t db_id;
+ ctdb_handle *handle;
ctdb_db = ctdb_db_handle(ctdb, name);
if (ctdb_db) {
@@ -1044,21 +1048,24 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name,
ctdb_db->db_name = talloc_strdup(ctdb_db, name);
CTDB_NO_MEMORY_NULL(ctdb, ctdb_db->db_name);
- data.dptr = discard_const(name);
- data.dsize = strlen(name)+1;
-
/* tell ctdb daemon to attach */
- ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, tdb_flags,
- persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH,
- 0, data, ctdb_db, &data, &res, NULL, NULL);
- if (ret != 0 || res != 0 || data.dsize != sizeof(uint32_t)) {
+ handle = ctdb_createdb_send(ctdb, CTDB_CURRENT_NODE,
+ name, persistent, tdb_flags,
+ NULL, NULL);
+ if (handle == NULL) {
+ DEBUG(DEBUG_ERR, (__location__ " Failed to send CREATEDB control\n"));
+ talloc_free(ctdb_db);
+ return NULL;
+ }
+
+ ret = ctdb_createdb_recv(ctdb, handle, &db_id);
+ if (ret != 0) {
DEBUG(DEBUG_ERR,("Failed to attach to database '%s'\n", name));
talloc_free(ctdb_db);
return NULL;
}
- ctdb_db->db_id = *(uint32_t *)data.dptr;
- talloc_free(data.dptr);
+ ctdb_db->db_id = db_id;
ret = ctdb_ctrl_getdbpath(ctdb, timeval_current_ofs(2, 0), CTDB_CURRENT_NODE, ctdb_db->db_id, ctdb_db, &ctdb_db->db_path);
if (ret != 0) {
@@ -1213,7 +1220,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 +1228,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 +1415,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 b074876..9f87f0b 100644
--- a/include/ctdb.h
+++ b/include/ctdb.h
@@ -99,8 +99,9 @@ ctdb_remove_message_handler_send(struct ctdb_context *ctdb, uint64_t srvid,
int ctdb_remove_message_handler_recv(struct ctdb_context *ctdb,
ctdb_handle *handle);
-int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
- void *private_data);
+int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid);
+
+
/*
* send a message to a specific node/port
@@ -152,6 +153,25 @@ int ctdb_getrecmaster(struct ctdb_context *ctdb,
/*
+ * functions to create a database
+ * if the database already exists this function is a NOP
+ */
+typedef void (*ctdb_createdb_cb)(int32_t status, uint32_t db_id, void *private_data);
+
+ctdb_handle *
+ctdb_createdb_send(struct ctdb_context *ctdb, uint32_t destnode,
+ const char *name, int persistent, uint32_t tdb_flags,
+ ctdb_createdb_cb callback,
+ void *private_data);
+int ctdb_createdb_recv(struct ctdb_context *ctdb,
+ ctdb_handle *handle, uint32_t *db_id);
+int ctdb_createdb(struct ctdb_context *ctdb, uint32_t destnode,
+ const char *name, int persistent, uint32_t tdb_flags,
+ uint32_t *db_id);
+
+
+
+/*
* cancel a request/call
*/
int ctdb_cancel(ctdb_handle *);
diff --git a/include/ctdb_protocol.h b/include/ctdb_protocol.h
index 22ea63d..16f8d1e 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 19ec8ce..4bf4095 100644
--- a/libctdb/libctdb.c
+++ b/libctdb/libctdb.c
@@ -143,6 +143,7 @@ int ctdb_cancel(ctdb_handle *handle)
struct ctdb_control_cb_data {
void *callback;
void *private_data;
+ uint32_t db_id;
};
@@ -450,11 +451,11 @@ int ctdb_remove_message_handler_recv(struct ctdb_context *ctdb, ctdb_handle *han
/*
tell the daemon we no longer want a srvid
*/
-int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data)
+int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid)
{
struct ctdb_client_control_state *state;
- state = ctdb_remove_message_handler_send(ctdb, srvid, NULL, private_data);
+ state = ctdb_remove_message_handler_send(ctdb, srvid, NULL, NULL);
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_remove_message_handler_send() failed.\n"));
return -1;
@@ -462,3 +463,116 @@ int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void
return ctdb_remove_message_handler_recv(ctdb, state);
}
+
+
+
+
+
+
+
+/*
+ * Create a database. If the database already exists this is a NOP.
+ */
+static void
+ctdb_createdb_recv_cb(struct ctdb_client_control_state *state)
+{
+ struct ctdb_control_cb_data *cb_data = state->async.private_data;
+ ctdb_createdb_cb callback = (ctdb_createdb_cb)cb_data->callback;
+ uint32_t db_id;
+
+ if (state->state == CTDB_CONTROL_DONE && state->status == 0) {
+ if (state->outdata.dsize != sizeof(uint32_t)) {
+ DEBUG(DEBUG_ERR, (" Wrond size of data returned for CREATEDB control. Got %zd bytes but expected %zd\n", state->outdata.dsize, sizeof(uint32_t)));
+
+ callback(CTDB_CONTROL_ERROR, 0, cb_data->private_data);
+ return;
+ }
+
+ db_id = *(uint32_t *)state->outdata.dptr;
+ }
+
+ callback(state->status, db_id, cb_data->private_data);
+}
+
+
+ctdb_handle *
+ctdb_createdb_send(struct ctdb_context *ctdb, uint32_t destnode,
+ const char *name, int persistent,
+ uint32_t tdb_flags,
+ ctdb_createdb_cb callback,
+ void *private_data)
+
+{
+ struct ctdb_client_control_state *state;
+ struct ctdb_control_cb_data *cb_data;
+ TDB_DATA data;
+
+ data.dptr = discard_const(name);
+ data.dsize = strlen(name)+1;
+
+ state = ctdb_control_send(ctdb, destnode, tdb_flags,
+ persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH,
+ 0, data,
+ ctdb, NULL);
+ if (state == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to send CREATEDB control\n"));
+ return NULL;
+ }
+
+ if (callback != NULL) {
+ cb_data = talloc(state, struct ctdb_control_cb_data);
+ cb_data->callback = callback;
+ cb_data->private_data = private_data;
+
+ state->async.fn = ctdb_createdb_recv_cb;
+ state->async.private_data = cb_data;
+ }
+
+ return (ctdb_handle *)state;
+}
+
+
+int ctdb_createdb_recv(struct ctdb_context *ctdb, ctdb_handle *handle, uint32_t *db_id)
+{
+ struct ctdb_client_control_state *state = talloc_get_type(handle, struct ctdb_client_control_state);
+ int ret;
+ int32_t res;
+ TALLOC_CTX *tmp_ctx = talloc_new(NULL);
+ TDB_DATA data;
+
+ ret = ctdb_control_recv(ctdb, state, tmp_ctx, &data, &res, NULL);
+ if (ret != 0 || res != 0) {
+ DEBUG(DEBUG_ERR,(__location__ " ctdb_createdb_recv failed\n"));
+ talloc_free(tmp_ctx);
+ return -1;
+ }
+
+ if (data.dsize != sizeof(uint32_t)) {
+ DEBUG(DEBUG_ERR, (__location__ " Wrong size of returned data. Got %zd bytes but expected %zd\n", data.dsize, sizeof(uint32_t)));
+ talloc_free(tmp_ctx);
+ return -1;
+ }
+
+ if (db_id != NULL) {
+ *db_id = *(uint32_t *)data.dptr;
+ }
+
+ talloc_free(tmp_ctx);
+ return state->status;
+}
+
+int ctdb_createdb(struct ctdb_context *ctdb, uint32_t destnode, const char *name, int persistent, uint32_t tdb_flags, uint32_t *db_id)
+{
+ struct ctdb_client_control_state *state;
+
+ state = ctdb_createdb_send(ctdb, destnode, name, persistent, tdb_flags, NULL, NULL);
+ if (state == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " ctdb_createdb_send() failed.\n"));
+ return -1;
+ }
+
+ return ctdb_createdb_recv(ctdb, state, db_id);
+}
+
+
+
diff --git a/libctdb/tst.c b/libctdb/tst.c
index 17d7f6e..821ea7f 100644
--- a/libctdb/tst.c
+++ b/libctdb/tst.c
@@ -33,7 +33,6 @@ int main(int argc, char *argv[])
ctdb_context = ctdb_connect("/tmp/ctdb.socket");
-
handle = ctdb_set_message_handler_send(ctdb_context, 55, NULL, msg_h, NULL);
if (handle == NULL) {
printf("Failed to register message port\n");
@@ -66,7 +65,6 @@ int main(int argc, char *argv[])
exit(10);
}
-
pfd.fd = ctdb_get_fd(ctdb_context);
for (;;) {
pfd.events = ctdb_which_events(ctdb_context);
diff --git a/server/ctdb_recoverd.c b/server/ctdb_recoverd.c
index d3e6a3c..0174509 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));
--
CTDB repository
More information about the samba-cvs
mailing list