From 66156220ebf5dc212e9aa86015b7301d1b665b50 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 5 Apr 2007 03:51:49 +0000 Subject: r22082: merged the ctdb changes from bzr added opendb ctdb backend from ronnie (This used to be commit b0da25cb79f860bfa14ba7a8419c7996d936292b) --- source4/cluster/ctdb/common/ctdb_ltdb.c | 42 ++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'source4/cluster/ctdb/common/ctdb_ltdb.c') diff --git a/source4/cluster/ctdb/common/ctdb_ltdb.c b/source4/cluster/ctdb/common/ctdb_ltdb.c index 189816229f..ceedb6c5ce 100644 --- a/source4/cluster/ctdb/common/ctdb_ltdb.c +++ b/source4/cluster/ctdb/common/ctdb_ltdb.c @@ -41,6 +41,17 @@ struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *na return NULL; } + +/* + this is the dummy null 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 */ @@ -49,6 +60,7 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, { struct ctdb_db_context *ctdb_db, *tmp_db; TDB_DATA data; + int ret; ctdb_db = talloc_zero(ctdb, struct ctdb_db_context); CTDB_NO_MEMORY_NULL(ctdb, ctdb_db); @@ -80,7 +92,18 @@ struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, return NULL; } + + /* + all databases support the "fetch" function. we need this in order to do forced migration of records + */ + ret = ctdb_set_call(ctdb_db, ctdb_fetch_func, CTDB_FETCH_FUNC); + if (ret != 0) { + talloc_free(ctdb_db); + return NULL; + } + DLIST_ADD(ctdb->db_list, ctdb_db); + return ctdb_db; } @@ -124,18 +147,25 @@ int ctdb_ltdb_fetch(struct ctdb_db_context *ctdb_db, /* return an initial header */ free(rec.dptr); ltdb_initial_header(ctdb_db, key, header); - data->dptr = NULL; - data->dsize = 0; + if (data) { + data->dptr = NULL; + data->dsize = 0; + } return 0; } *header = *(struct ctdb_ltdb_header *)rec.dptr; - data->dsize = rec.dsize - sizeof(struct ctdb_ltdb_header); - data->dptr = talloc_memdup(ctdb_db, sizeof(struct ctdb_ltdb_header)+rec.dptr, - data->dsize); + if (data) { + data->dsize = rec.dsize - sizeof(struct ctdb_ltdb_header); + data->dptr = talloc_memdup(ctdb_db, sizeof(struct ctdb_ltdb_header)+rec.dptr, + data->dsize); + } + free(rec.dptr); - CTDB_NO_MEMORY(ctdb, data->dptr); + if (data) { + CTDB_NO_MEMORY(ctdb, data->dptr); + } return 0; } -- cgit