-/*
- 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;
-}
-
-
-
-