change ctdb_ctrl_attach to use the new libctdb versions to create the database
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 14 May 2010 03:13:49 +0000 (13:13 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 14 May 2010 03:13:49 +0000 (13:13 +1000)
client/ctdb_client.c

index 27f25ce1e7e82f8e1d01186b2c5069134857088b..14005bca36c69f5cf7a5b22055e8e18d0c3fa9da 100644 (file)
@@ -1032,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) {
@@ -1048,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) {