From 4973ff66ac775d58c95cc6bd5665ed0d1e4a7718 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 3 Nov 2009 00:55:41 +0100 Subject: s3:dbwrap_ctdb: add a function db_ctdb_ltdb_fetch() This fetches a record from the db and splits out the ctdb header. Michael --- source3/lib/dbwrap_ctdb.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/dbwrap_ctdb.c b/source3/lib/dbwrap_ctdb.c index 1d207e7abf..145c0f65ea 100644 --- a/source3/lib/dbwrap_ctdb.c +++ b/source3/lib/dbwrap_ctdb.c @@ -75,6 +75,59 @@ static NTSTATUS tdb_error_to_ntstatus(struct tdb_context *tdb) } +/** + * fetch a record from the tdb, separating out the header + * information and returning the body of the record. + */ +static NTSTATUS db_ctdb_ltdb_fetch(struct db_ctdb_ctx *db, + TDB_DATA key, + struct ctdb_ltdb_header *header, + TALLOC_CTX *mem_ctx, + TDB_DATA *data) +{ + TDB_DATA rec; + NTSTATUS status; + + rec = tdb_fetch(db->wtdb->tdb, key); + if (rec.dsize < sizeof(struct ctdb_ltdb_header)) { + status = NT_STATUS_NOT_FOUND; + if (data) { + ZERO_STRUCTP(data); + } + if (header) { + header->dmaster = (uint32_t)-1; + header->rsn = 0; + } + goto done; + } + + if (header) { + *header = *(struct ctdb_ltdb_header *)rec.dptr; + } + + if (data) { + data->dsize = rec.dsize - sizeof(struct ctdb_ltdb_header); + if (data->dsize == 0) { + data->dptr = NULL; + } else { + data->dptr = (unsigned char *)talloc_memdup(mem_ctx, + rec.dptr + + sizeof(struct ctdb_ltdb_header), + data->dsize); + if (data->dptr == NULL) { + status = NT_STATUS_NO_MEMORY; + goto done; + } + } + } + + status = NT_STATUS_OK; + +done: + SAFE_FREE(rec.dptr); + return status; +} + /* * Store a record together with the ctdb record header * in the local copy of the database. -- cgit