ctdb-client: Fix ctdb_attach() to use database flags
authorAmitay Isaacs <amitay@gmail.com>
Fri, 18 Aug 2017 04:00:47 +0000 (14:00 +1000)
committerMartin Schwenke <martins@samba.org>
Fri, 25 Aug 2017 11:32:58 +0000 (13:32 +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>
Autobuild-User(master): Martin Schwenke <martins@samba.org>
Autobuild-Date(master): Fri Aug 25 13:32:58 CEST 2017 on sn-devel-144

ctdb/client/ctdb_client.c
ctdb/include/ctdb_client.h
ctdb/server/ctdb_recoverd.c

index 05710c964faf2c586e0a7107dcc777d2aa75cbbc..25b96545866a75b96ce329b91ffd2a770b75eddd 100644 (file)
@@ -2086,12 +2086,10 @@ int ctdb_ctrl_db_open_flags(struct ctdb_context *ctdb, uint32_t db_id,
 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
                                    struct timeval timeout,
                                    const char *name,
-                                   bool persistent)
+                                   uint8_t db_flags)
 {
        struct ctdb_db_context *ctdb_db;
-       TDB_DATA data;
        int ret;
-       int32_t res;
        int tdb_flags;
 
        ctdb_db = ctdb_db_handle(ctdb, name);
@@ -2106,22 +2104,15 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
        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, 0,
-                          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)) {
+       ret = ctdb_ctrl_createdb(ctdb, timeout, CTDB_CURRENT_NODE,
+                                ctdb_db, name, db_flags, &ctdb_db->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);
-
        ret = ctdb_ctrl_getdbpath(ctdb, timeout, CTDB_CURRENT_NODE, ctdb_db->db_id, ctdb_db, &ctdb_db->db_path);
        if (ret != 0) {
                DEBUG(DEBUG_ERR,("Failed to get dbpath for database '%s'\n", name));
@@ -2144,9 +2135,7 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
                return NULL;
        }
 
-       if (persistent) {
-               ctdb_db->db_flags = CTDB_DB_FLAGS_PERSISTENT;
-       }
+       ctdb_db->db_flags = db_flags;
 
        DLIST_ADD(ctdb->db_list, ctdb_db);
 
@@ -3893,7 +3882,7 @@ struct ctdb_transaction_handle *ctdb_transaction_start(struct ctdb_db_context *c
        }
 
        h->g_lock_db = ctdb_attach(h->ctdb_db->ctdb, timeval_current_ofs(3,0),
-                                  "g_lock.tdb", false);
+                                  "g_lock.tdb", 0);
        if (!h->g_lock_db) {
                DEBUG(DEBUG_ERR, (__location__ " unable to attach to g_lock.tdb\n"));
                talloc_free(h);
index 7314760fdc858d46ddd397d102df4fb65467cdc9..13978954d074afc33af05a4c1ec2be133c3e626b 100644 (file)
@@ -273,7 +273,7 @@ int ctdb_ctrl_db_open_flags(struct ctdb_context *ctdb, uint32_t db_id,
 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
                                    struct timeval timeout,
                                    const char *name,
-                                   bool persistent);
+                                   uint8_t db_flags);
 
 int ctdb_detach(struct ctdb_context *ctdb, uint32_t db_id);
 
index 386b72065e4601d251452d3aa38e26029bfa4fe9..9488bc2c8428309ac83603c1f746e1e25f28aaba 100644 (file)
@@ -654,7 +654,7 @@ static void vacuum_fetch_handler(uint64_t srvid, TDB_DATA data,
        TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
        const char *name;
        struct ctdb_dbid_map_old *dbmap=NULL;
-       bool persistent = false;
+       uint8_t db_flags = 0;
        struct ctdb_db_context *ctdb_db;
        struct ctdb_rec_data_old *r;
 
@@ -673,7 +673,7 @@ static void vacuum_fetch_handler(uint64_t srvid, TDB_DATA data,
 
        for (i=0;i<dbmap->num;i++) {
                if (dbmap->dbs[i].db_id == recs->db_id) {
-                       persistent = dbmap->dbs[i].flags & CTDB_DB_FLAGS_PERSISTENT;
+                       db_flags = dbmap->dbs[i].flags;
                        break;
                }
        }
@@ -689,7 +689,7 @@ static void vacuum_fetch_handler(uint64_t srvid, TDB_DATA data,
        }
 
        /* attach to it */
-       ctdb_db = ctdb_attach(ctdb, CONTROL_TIMEOUT(), name, persistent);
+       ctdb_db = ctdb_attach(ctdb, CONTROL_TIMEOUT(), name, db_flags);
        if (ctdb_db == NULL) {
                DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
                goto done;