summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2009-11-03 00:55:41 +0100
committerMichael Adam <obnox@samba.org>2009-11-03 01:02:35 +0100
commit4973ff66ac775d58c95cc6bd5665ed0d1e4a7718 (patch)
treeb9614c6145115209170a1c476452e231083fea65 /source3
parent6a898348fa701a6d89ea939d1ba4a11da3d0c598 (diff)
downloadsamba-4973ff66ac775d58c95cc6bd5665ed0d1e4a7718.tar.gz
samba-4973ff66ac775d58c95cc6bd5665ed0d1e4a7718.tar.bz2
samba-4973ff66ac775d58c95cc6bd5665ed0d1e4a7718.zip
s3:dbwrap_ctdb: add a function db_ctdb_ltdb_fetch()
This fetches a record from the db and splits out the ctdb header. Michael
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/dbwrap_ctdb.c53
1 files changed, 53 insertions, 0 deletions
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.