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) {
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) {