return 0;
}
-/*
- this is the dummy null procedure that all databases support
-*/
-static int ctdb_null_func(struct ctdb_call_info *call)
-{
- return 0;
-}
-
-/*
- this is a plain fetch procedure that all databases support
-*/
-static int ctdb_fetch_func(struct ctdb_call_info *call)
-{
- call->reply_data = &call->record_data;
- return 0;
-}
-
-
-
-/*
- attach to a specific database - client 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;
- int ret;
- uint32_t db_id;
- ctdb_handle *handle;
-
- ctdb_db = ctdb_db_handle(ctdb, name);
- if (ctdb_db) {
- return ctdb_db;
- }
-
- ctdb_db = talloc_zero(ctdb, struct ctdb_db_context);
- CTDB_NO_MEMORY_NULL(ctdb, ctdb_db);
-
- ctdb_db->ctdb = ctdb;
- ctdb_db->db_name = talloc_strdup(ctdb_db, name);
- CTDB_NO_MEMORY_NULL(ctdb, ctdb_db->db_name);
-
- /* tell ctdb daemon to attach */
- 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 = 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) {
- DEBUG(DEBUG_ERR,("Failed to get dbpath for database '%s'\n", name));
- talloc_free(ctdb_db);
- return NULL;
- }
-
- tdb_flags = persistent?TDB_DEFAULT:TDB_NOSYNC;
- if (ctdb->valgrinding) {
- tdb_flags |= TDB_NOMMAP;
- }
- tdb_flags |= TDB_DISALLOW_NESTING;
-
- ctdb_db->ltdb = tdb_wrap_open(ctdb, ctdb_db->db_path, 0, tdb_flags, O_RDWR, 0);
- if (ctdb_db->ltdb == NULL) {
- ctdb_set_error(ctdb, "Failed to open tdb '%s'\n", ctdb_db->db_path);
- talloc_free(ctdb_db);
- return NULL;
- }
-
- ctdb_db->persistent = persistent;
-
- DLIST_ADD(ctdb->db_list, ctdb_db);
-
- /* add well known functions */
- ctdb_set_call(ctdb_db, ctdb_null_func, CTDB_NULL_FUNC);
- ctdb_set_call(ctdb_db, ctdb_fetch_func, CTDB_FETCH_FUNC);
-
- return ctdb_db;
-}
-
-
-
-
struct traverse_state {
bool done;
uint32_t count;
typedef void (*ctdb_attachdb_cb)(int32_t status, struct ctdb_db_context *ctdb_db, void *private_data);
ctdb_handle *
-ctdb_attachdb_send(struct ctdb_context *ctdb, uint32_t destnode,
+ctdb_attachdb_send(struct ctdb_context *ctdb,
const char *name, int persistent, uint32_t tdb_flags,
ctdb_attachdb_cb callback,
void *private_data);
int ctdb_attachdb_recv(struct ctdb_context *ctdb,
ctdb_handle *handle, struct ctdb_db_context **);
-int ctdb_attachdb(struct ctdb_context *ctdb, uint32_t destnode,
+int ctdb_attachdb(struct ctdb_context *ctdb,
const char *name, int persistent, uint32_t tdb_flags,
struct ctdb_db_context **);
int ctdb_start(struct ctdb_context *ctdb);
int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog);
-/*
- attach to a ctdb database
-*/
-struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent, uint32_t tdb_flags);
-
/*
find an attached ctdb_db handle given a name
*/
struct ctdb_attachdb_state {
enum control_state state;
- uint32_t destnode;
struct ctdb_context *ctdb;
struct ctdb_db_context *ctdb_db;
struct ctdb_client_control_state *cdb_state;
adb_state->ctdb_db->db_id = *(uint32_t *)state->outdata.dptr;
- adb_state->gdp_state = ctdb_getdbpath_send(adb_state->ctdb, adb_state->destnode, adb_state->ctdb_db->db_id, NULL, NULL);
+ adb_state->gdp_state = ctdb_getdbpath_send(adb_state->ctdb, CTDB_CURRENT_NODE, adb_state->ctdb_db->db_id, NULL, NULL);
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_getdbpath_send() failed.\n"));
adb_state->state = CTDB_CONTROL_ERROR;
}
ctdb_handle *
-ctdb_attachdb_send(struct ctdb_context *ctdb, uint32_t destnode,
+ctdb_attachdb_send(struct ctdb_context *ctdb,
const char *name, int persistent, uint32_t tdb_flags,
ctdb_attachdb_cb callback,
void *private_data)
state->state = CTDB_CONTROL_WAIT;
state->ctdb = ctdb;
state->ctdb_db = ctdb_db;
- state->destnode = destnode;
state->tdb_flags = tdb_flags;
state->persistent = persistent?True:False;
return 0;
}
+int ctdb_attachdb(struct ctdb_context *ctdb,
+ const char *name, int persistent, uint32_t tdb_flags,
+ struct ctdb_db_context **ctdb_db)
+{
+ ctdb_handle *handle;
+ int ret;
+ handle = ctdb_attachdb_send(ctdb, name, persistent, tdb_flags, NULL, NULL);
+ if (handle == NULL) {
+ DEBUG(DEBUG_ERR, (__location__ " Failed to send attachdb control\n"));
+ return -1;
+ }
+ ret = ctdb_attachdb_recv(ctdb, handle, ctdb_db);
+ if (ret != 0) {
+ DEBUG(DEBUG_ERR, (__location__ " receive of attachdb reply failed\n"));
+ return -1;
+ }
-int ctdb_attachdb(struct ctdb_context *ctdb, uint32_t destnode,
- const char *name, int persistent, uint32_t tdb_flags,
- struct ctdb_db_context **);
+ return 0;
+}
}
/* attach to it */
- ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
- if (ctdb_db == NULL) {
+ ret = ctdb_attachdb(ctdb, name, persistent, 0, &ctdb_db);
+ if (ret != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
talloc_free(tmp_ctx);
return;
ctdb = ctdb_cmdline_client(ev);
/* attach to a specific database */
- ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
- if (!ctdb_db) {
+ ret = ctdb_attachdb(ctdb, "test.tdb", false, 0, &ctdb_db);
+ if (ret) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
}
{ NULL, 'n', POPT_ARG_INT, &num_nodes, 0, "num_nodes", "integer" },
POPT_TABLEEND
};
- int opt;
+ int ret, opt;
const char **extra_argv;
int extra_argc = 0;
poptContext pc;
&cluster_ready);
/* attach to a specific database */
- ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
- if (!ctdb_db) {
+ ret = ctdb_attachdb(ctdb, "test.tdb", false, 0, &ctdb_db);
+ if (ret) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
}
{ "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" },
POPT_TABLEEND
};
- int opt;
+ int ret, opt;
const char **extra_argv;
int extra_argc = 0;
poptContext pc;
ctdb = ctdb_cmdline_client(ev);
/* attach to a specific database */
- ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
- if (!ctdb_db) {
+ ret = ctdb_attachdb(ctdb, "test.tdb", false, 0, &ctdb_db);
+ if (ret) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
}
{ "unsafe-writes", 'u', POPT_ARG_NONE, &unsafe_writes, 0, "do not use tdb transactions when writing", NULL },
POPT_TABLEEND
};
- int opt;
+ int ret, opt;
const char **extra_argv;
int extra_argc = 0;
poptContext pc;
/* attach to a specific database */
if (unsafe_writes == 1) {
- ctdb_db = ctdb_attach(ctdb, "persistent.tdb", true, TDB_NOSYNC);
+ ret = ctdb_attachdb(ctdb, "persistent.tdb", true, TDB_NOSYNC, &ctdb_db);
} else {
- ctdb_db = ctdb_attach(ctdb, "persistent.tdb", true, 0);
+ ret = ctdb_attachdb(ctdb, "persistent.tdb", true, 0, &ctdb_db);
}
- if (!ctdb_db) {
+ if (ret) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
}
{ "delete-pct", 'p', POPT_ARG_INT, &delete_pct, 0, "delete_pct", "integer" },
POPT_TABLEEND
};
- int opt;
+ int ret, opt;
const char **extra_argv;
int extra_argc = 0;
poptContext pc;
ctdb = ctdb_cmdline_client(ev);
/* attach to a specific database */
- ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
- if (!ctdb_db) {
+ ret = ctdb_attachdb(ctdb, "test.tdb", false, 0, &ctdb_db);
+ if (ret) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
}
{ "base-rec", 'b', POPT_ARG_INT, &base_rec, 0, "base_rec", "integer" },
POPT_TABLEEND
};
- int opt;
+ int ret, opt;
const char **extra_argv;
int extra_argc = 0;
poptContext pc;
ctdb = ctdb_cmdline_client(ev);
/* attach to a specific database */
- ctdb_db = ctdb_attach(ctdb, "test.tdb", false, 0);
- if (!ctdb_db) {
+ ret = ctdb_attachdb(ctdb, "test.tdb", false, 0, &ctdb_db);
+ if (ret) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
}
{ "unsafe-writes", 'u', POPT_ARG_NONE, &unsafe_writes, 0, "do not use tdb transactions when writing", NULL },
POPT_TABLEEND
};
- int opt;
+ int ret, opt;
const char **extra_argv;
int extra_argc = 0;
poptContext pc;
/* attach to a specific database */
if (unsafe_writes == 1) {
- ctdb_db = ctdb_attach(ctdb, "transaction.tdb", true, TDB_NOSYNC);
+ ret = ctdb_attachdb(ctdb, "transaction.tdb", true, TDB_NOSYNC, &ctdb_db);
} else {
- ctdb_db = ctdb_attach(ctdb, "transaction.tdb", true, 0);
+ ret = ctdb_attachdb(ctdb, "transaction.tdb", true, 0, &ctdb_db);
}
- if (!ctdb_db) {
+ if (ret) {
DEBUG(DEBUG_ERR, ("ctdb_attach failed - %s\n", ctdb_errstr(ctdb)));
exit(1);
}
{ "database", 0, POPT_ARG_STRING, &dbname, 0, "database to traverse", "name" },
POPT_TABLEEND
};
- int opt;
+ int ret, opt;
const char **extra_argv;
int extra_argc = 0;
poptContext pc;
ctdb = ctdb_cmdline_client(ev);
/* attach to a specific database */
- ctdb_db = ctdb_attach(ctdb, dbname, false, 0);
- if (!ctdb_db) {
+ ret = ctdb_attachdb(ctdb, dbname, false, 0, &ctdb_db);
+ if (ret) {
printf("ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
exit(1);
}
return -1;
}
- ctdb_db = ctdb_attach(ctdb, db_name, false, 0);
+ ret = ctdb_attachdb(ctdb, db_name, false, 0, &ctdb_db);
- if (ctdb_db == NULL) {
+ if (ret != 0) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
return -1;
}
{
const char *db_name;
struct ctdb_db_context *ctdb_db;
+ int ret;
if (argc < 1) {
usage();
}
db_name = argv[0];
- ctdb_db = ctdb_attach(ctdb, db_name, false, 0);
- if (ctdb_db == NULL) {
+ ret = ctdb_attachdb(ctdb, db_name, false, 0, &ctdb_db);
+ if (ret != 0) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", db_name));
return -1;
}
allow_unhealthy));
}
- ctdb_db = ctdb_attach(ctdb, argv[0], dbmap->dbs[i].persistent, 0);
- if (ctdb_db == NULL) {
+ ret = ctdb_attachdb(ctdb, argv[0], dbmap->dbs[i].persistent, 0, &ctdb_db);
+ if (ret != 0) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", argv[0]));
talloc_free(tmp_ctx);
return -1;
dbhdr.name, tbuf);
- ctdb_db = ctdb_attach(ctdb, dbhdr.name, dbhdr.persistent, 0);
- if (ctdb_db == NULL) {
+ ret = ctdb_attachdb(ctdb, dbhdr.name, dbhdr.persistent, 0, &ctdb_db);
+ if (ret != 0) {
DEBUG(DEBUG_ERR,("Unable to attach to database '%s'\n", dbhdr.name));
talloc_free(tmp_ctx);
return -1;
return -1;
}
- ctdb_db = ctdb_attach(ctdb, argv[0], dbmap->dbs[i].persistent, 0);
- if (ctdb_db == NULL) {
+ ret = ctdb_attachdb(ctdb, argv[0], dbmap->dbs[i].persistent, 0, &ctdb_db);
+ if (ret != 0) {
DEBUG(DEBUG_ERR, ("Unable to attach to database '%s'\n",
argv[0]));
talloc_free(tmp_ctx);
struct ctdb_db_context *ctdb_db;
const char *name;
struct vacuum_data *vdata;
- int i;
+ int ret, i;
vdata = talloc_zero(ctdb, struct vacuum_data);
if (vdata == NULL) {
return -1;
}
- ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
- if (ctdb_db == NULL) {
+ ret = ctdb_attachdb(ctdb, name, persistent, 0, &ctdb_db);
+ if (ret != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
talloc_free(vdata);
return -1;
if (vdata->delete_count > 0) {
struct delete_records_list *recs;
TDB_DATA indata, outdata;
- int ret;
int32_t res;
uint32_t count;
{
struct ctdb_db_context *ctdb_db;
const char *name;
- int size;
+ int ret, size;
if (ctdb_ctrl_getdbname(ctdb, TIMELIMIT(), CTDB_CURRENT_NODE, db_id, ctdb, &name) != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to get name of db 0x%x\n", db_id));
return -1;
}
- ctdb_db = ctdb_attach(ctdb, name, persistent, 0);
- if (ctdb_db == NULL) {
+ ret = ctdb_attachdb(ctdb, name, persistent, 0, &ctdb_db);
+ if (ret != 0) {
DEBUG(DEBUG_ERR,(__location__ " Failed to attach to database '%s'\n", name));
return -1;
}