Fix the O3 developer build
[ctdb.git] / client / ctdb_client.c
index c8ab1cd6cb1b9bac33e879fd03fac770c88400d2..d09e1c64147accb16f2e1f76c879154859e1a0e5 100644 (file)
@@ -1138,7 +1138,7 @@ int ctdb_control_recv(struct ctdb_context *ctdb,
                        state->async.fn(state);
                }
                talloc_free(tmp_ctx);
-               return -1;
+               return (status == 0 ? -1 : state->status);
        }
 
        if (outdata) {
@@ -1283,7 +1283,7 @@ int ctdb_ctrl_dbstatistics(struct ctdb_context *ctdb, uint32_t destnode, uint32_
        }
 
        wire = (struct ctdb_db_statistics *)outdata.dptr;
-       *s = *wire;
+       memcpy(s, wire, offsetof(struct ctdb_db_statistics, hot_keys_wire));
        ptr = &wire->hot_keys_wire[0];
        for (i=0; i<wire->num_hot_keys; i++) {
                s->hot_keys[i].key.dptr = talloc_size(mem_ctx, s->hot_keys[i].key.dsize);
@@ -1926,6 +1926,12 @@ int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32
                tdb_flags = TDB_INCOMPATIBLE_HASH;
        }
 
+#ifdef TDB_MUTEX_LOCKING
+       if (!persistent && ctdb->tunable.mutex_enabled == 1) {
+               tdb_flags |= (TDB_MUTEX_LOCKING | TDB_CLEAR_IF_FIRST);
+       }
+#endif
+
        ret = ctdb_control(ctdb, destnode, tdb_flags,
                           persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH, 
                           0, data, 
@@ -2049,6 +2055,9 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
        TDB_DATA data;
        int ret;
        int32_t res;
+#ifdef TDB_MUTEX_LOCKING
+       uint32_t mutex_enabled = 0;
+#endif
 
        ctdb_db = ctdb_db_handle(ctdb, name);
        if (ctdb_db) {
@@ -2073,6 +2082,22 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
                tdb_flags |= TDB_INCOMPATIBLE_HASH;
        }
 
+#ifdef TDB_MUTEX_LOCKING
+       if (!persistent) {
+               ret = ctdb_ctrl_get_tunable(ctdb, timeval_current_ofs(3,0),
+                                           CTDB_CURRENT_NODE,
+                                           "TDBMutexEnabled",
+                                           &mutex_enabled);
+               if (ret != 0) {
+                       DEBUG(DEBUG_WARNING, ("Assuming no mutex support.\n"));
+               }
+
+               if (mutex_enabled == 1) {
+                       tdb_flags |= (TDB_MUTEX_LOCKING | TDB_CLEAR_IF_FIRST);
+               }
+       }
+#endif
+
        /* tell ctdb daemon to attach */
        ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, tdb_flags, 
                           persistent?CTDB_CONTROL_DB_ATTACH_PERSISTENT:CTDB_CONTROL_DB_ATTACH,
@@ -2093,7 +2118,16 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
                return NULL;
        }
 
-       tdb_flags = persistent?TDB_DEFAULT:TDB_NOSYNC;
+       if (persistent) {
+               tdb_flags = TDB_DEFAULT;
+       } else {
+               tdb_flags = TDB_NOSYNC;
+#ifdef TDB_MUTEX_LOCKING
+               if (mutex_enabled) {
+                       tdb_flags |= (TDB_MUTEX_LOCKING | TDB_CLEAR_IF_FIRST);
+               }
+#endif
+       }
        if (ctdb->valgrinding) {
                tdb_flags |= TDB_NOMMAP;
        }
@@ -2701,12 +2735,12 @@ int ctdb_ctrl_set_tunable(struct ctdb_context *ctdb,
        ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_SET_TUNABLE, 0, data, NULL,
                           NULL, &res, &timeout, NULL);
        talloc_free(data.dptr);
-       if (ret != 0 || res != 0) {
+       if ((ret != 0) || (res == -1)) {
                DEBUG(DEBUG_ERR,(__location__ " ctdb_control for set_tunable failed\n"));
                return -1;
        }
 
-       return 0;
+       return res;
 }
 
 /*
@@ -3811,7 +3845,7 @@ static bool server_id_exists(struct ctdb_context *ctdb, struct server_id *id)
 {
        struct ctdb_server_id sid;
        int ret;
-       uint32_t result;
+       uint32_t result = 0;
 
        sid.type = SERVER_TYPE_SAMBA;
        sid.pnn = id->vnn;