ctdb-client: Optionally return database id from ctdb_ctrl_createdb()
authorAmitay Isaacs <amitay@gmail.com>
Wed, 23 Aug 2017 02:09:22 +0000 (12:09 +1000)
committerMartin Schwenke <martins@samba.org>
Fri, 25 Aug 2017 07:41:26 +0000 (09:41 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12978

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/client/ctdb_client.c
ctdb/include/ctdb_client.h
ctdb/server/ctdb_recoverd.c

index 74874bab2b288b6ff94cc1159794251a247fc842..05710c964faf2c586e0a7107dcc777d2aa75cbbc 100644 (file)
@@ -1912,7 +1912,7 @@ int ctdb_ctrl_getdbseqnum(struct ctdb_context *ctdb, struct timeval timeout,
  */
 int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout,
                       uint32_t destnode, TALLOC_CTX *mem_ctx,
-                      const char *name, uint8_t db_flags)
+                      const char *name, uint8_t db_flags, uint32_t *db_id)
 {
        int ret;
        int32_t res;
@@ -1937,6 +1937,15 @@ int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout,
                return -1;
        }
 
+       if (data.dsize != sizeof(uint32_t)) {
+               TALLOC_FREE(data.dptr);
+               return -1;
+       }
+       if (db_id != NULL) {
+               *db_id = *(uint32_t *)data.dptr;
+       }
+       talloc_free(data.dptr);
+
        return 0;
 }
 
index 8aaf9c4d64352448bd5599c5db0588a5d65f59b1..7314760fdc858d46ddd397d102df4fb65467cdc9 100644 (file)
@@ -251,7 +251,7 @@ int ctdb_ctrl_getdbseqnum(struct ctdb_context *ctdb, struct timeval timeout,
 
 int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout,
                       uint32_t destnode, TALLOC_CTX *mem_ctx,
-                      const char *name, uint8_t db_flags);
+                      const char *name, uint8_t db_flags, uint32_t *db_id);
 
 int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode,
                             int32_t *level);
index 05aee463bef55573e11577f01254b5a807d9689c..386b72065e4601d251452d3aa38e26029bfa4fe9 100644 (file)
@@ -472,7 +472,7 @@ static int create_missing_remote_databases(struct ctdb_context *ctdb, struct ctd
                        ret = ctdb_ctrl_createdb(ctdb, CONTROL_TIMEOUT(),
                                                 nodemap->nodes[j].pnn,
                                                 mem_ctx, name,
-                                                dbmap->dbs[db].flags);
+                                                dbmap->dbs[db].flags, NULL);
                        if (ret != 0) {
                                DEBUG(DEBUG_ERR, (__location__ " Unable to create remote db:%s\n", name));
                                return -1;
@@ -536,7 +536,7 @@ static int create_missing_local_databases(struct ctdb_context *ctdb, struct ctdb
                        }
                        ctdb_ctrl_createdb(ctdb, CONTROL_TIMEOUT(), pnn,
                                           mem_ctx, name,
-                                          remote_dbmap->dbs[db].flags);
+                                          remote_dbmap->dbs[db].flags, NULL);
                        if (ret != 0) {
                                DEBUG(DEBUG_ERR, (__location__ " Unable to create local db:%s\n", name));
                                return -1;