[SCM] Samba Shared Repository - branch master updated

Michael Adam obnox at samba.org
Thu Nov 29 12:22:02 MST 2012


The branch, master has been updated
       via  2f38a77 dbwrap: Do not rely on dbwrap_record_get_value to return a talloc object
       via  e271db4 dbwrap: Remove an unnecessary if-statement
       via  c7af12d dbwrap: No need to NULL out a talloc_zero'ed structure element
       via  a022513 dbwrap: Use talloc_zero in db_open_rbt
       via  0c0815c dbwrap: Use talloc_zero in db_open_cache
       via  343ce16 s3: Remove db_ctdb_fetch
       via  6b8a37f s3: Directly parse local existing records in db_ctdb_parse_record
       via  9dd047d s3: Factor out db_ctdb_can_use_local_hdr from db_ctdb_can_use_local_copy
       via  55d75a3 s3: Remove unused code for fetching persistent ctdb records
       via  7b43362 s3: Avoid db_ctdb_fetch for persistent databases
       via  93219f9 s3: Factor out parse_newest_in_marshall_buffer from pull_newest_from_marshall_buffer
       via  850d5de s3: reduce db_ctdb_marshall_loop_next to specialized db_ctdb_marshall_buf_parse
       via  a742b6e s3: Factor out db_ctdb_marshall_loop_next_key from db_ctdb_marshall_loop_next
       via  664b170 s3: Slightly simplify db_ctdb_marshall_loop_next
       via  af608cd s3: Use db_ctdb_ltdb_parse in db_ctdb_fetch_db_seqnum_from_db
       via  7127344 s3: Use db_ctdb_ltdb_parse in db_ctdb_ltdb_fetch
       via  560ed93 s3: Add db_ctdb_ltdb_parse
       via  6e0259d s3: Slightly simplify db_ctdb_transaction_commit
       via  b206b52 s3: Remove header==NULL code from db_ctdb_marshall_record
       via  24c36e7 s3: test dbwrap_ctdb
       via  8300791 dbwrap: Use dbwrap_parse_record in dbwrap_fetch_uint32_bystring
      from  26a0ee5 docs: man oLschema2ldif: Add missing meta data.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 2f38a77a2dfc72ccd94f5027807c9484dae54358
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Nov 29 16:45:15 2012 +0100

    dbwrap: Do not rely on dbwrap_record_get_value to return a talloc object
    
    db_tdb_fetch_locked returns the value as part of a larger talloc object
    that also contains the key.  This means we can not realloc, but have to
    freshly alloc.
    
    Reviewed-by: Michael Adam <obnox at samba.org>
    
    Autobuild-User(master): Michael Adam <obnox at samba.org>
    Autobuild-Date(master): Thu Nov 29 20:21:51 CET 2012 on sn-devel-104

commit e271db4fd82d03b39a5872b1a3fde5e2a16e1633
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Nov 29 15:04:33 2012 +0100

    dbwrap: Remove an unnecessary if-statement
    
    TALLOC_FREE can live with a NULL pointer
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit c7af12dd30f9670806b161b94d91b741d06813e2
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Nov 29 15:03:20 2012 +0100

    dbwrap: No need to NULL out a talloc_zero'ed structure element
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit a02251333fc185aee176b565a85fd42e9ff4cfbc
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Nov 29 15:02:43 2012 +0100

    dbwrap: Use talloc_zero in db_open_rbt
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 0c0815cfe3cce09ef7dffa62235967e954915513
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Nov 29 15:02:15 2012 +0100

    dbwrap: Use talloc_zero in db_open_cache
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 343ce16e0b52acd3d109eb619f60e394c1e04abb
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Nov 12 13:42:23 2012 +0100

    s3: Remove db_ctdb_fetch
    
    Note that this also makes the request for read only copies
    much more explicity visible in the code.
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 6b8a37f5ca83c45e2cac262f4d9eee5c7750c283
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Nov 12 13:36:48 2012 +0100

    s3: Directly parse local existing records in db_ctdb_parse_record
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 9dd047d67e4b53f1240956e20af986a1d03dce32
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Nov 12 13:27:07 2012 +0100

    s3: Factor out db_ctdb_can_use_local_hdr from db_ctdb_can_use_local_copy
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 55d75a3fbe95ea3b95dc83551cca742bcddb6e9b
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Nov 12 13:06:38 2012 +0100

    s3: Remove unused code for fetching persistent ctdb records
    
    The only entry point here is parse_record, and this catches the persistent
    case with a direct parse now
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 7b43362a9ea942e6759fd9298b2a67cb3328520f
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Nov 12 13:03:56 2012 +0100

    s3: Avoid db_ctdb_fetch for persistent databases
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 93219f92bb4294f0d7be7ba91f6a2e312336469d
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Nov 12 12:13:39 2012 +0100

    s3: Factor out parse_newest_in_marshall_buffer from pull_newest_from_marshall_buffer
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 850d5de96702b8c4bd8a285b4bd44a15350dfca8
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Nov 10 15:03:35 2012 +0100

    s3: reduce db_ctdb_marshall_loop_next to specialized db_ctdb_marshall_buf_parse
    
    now that the db_ctdb_marshall_loop_next_key has been factored out.
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit a742b6edd5dc23378ec1926777af67ad54e75e10
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Nov 10 14:46:10 2012 +0100

    s3: Factor out db_ctdb_marshall_loop_next_key from db_ctdb_marshall_loop_next
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 664b170b13674c26c94ec1d3603570e707f8f1e5
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Nov 10 14:42:21 2012 +0100

    s3: Slightly simplify db_ctdb_marshall_loop_next
    
    Both callers give a key argument
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit af608cdd8c6c2d5eaddcca90ccd8d075ddcb6c7e
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Nov 8 12:00:11 2012 +0100

    s3: Use db_ctdb_ltdb_parse in db_ctdb_fetch_db_seqnum_from_db
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 71273448637e65b920535c077959e8dbb5444299
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Nov 8 11:52:43 2012 +0100

    s3: Use db_ctdb_ltdb_parse in db_ctdb_ltdb_fetch
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 560ed93147b4da8b6124837133b90b4f95dbd6fc
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Nov 8 11:37:30 2012 +0100

    s3: Add db_ctdb_ltdb_parse
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 6e0259d8ec4698384be803e0dc75f3ed2eef4ab1
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Nov 7 16:39:16 2012 +0100

    s3: Slightly simplify db_ctdb_transaction_commit
    
    Avoid an unnecessary "else".
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit b206b5274878bbf47cd19db0fccc025a1ac16784
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Nov 7 16:25:31 2012 +0100

    s3: Remove header==NULL code from db_ctdb_marshall_record
    
    The only call chain (via db_ctdb_marshall_add) has header != NULL
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 24c36e748414d70ede930e8418455a2c11068d49
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Nov 7 21:24:27 2012 +0100

    s3: test dbwrap_ctdb
    
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 8300791a6765499bcc8b892863d319f59332d9e3
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Nov 8 14:15:25 2012 +0100

    dbwrap: Use dbwrap_parse_record in dbwrap_fetch_uint32_bystring
    
    Reviewed-by: Michael Adam <obnox at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/dbwrap/dbwrap_cache.c          |    7 +-
 lib/dbwrap/dbwrap_rbt.c            |    6 +-
 lib/dbwrap/dbwrap_tdb.c            |    5 +-
 lib/dbwrap/dbwrap_util.c           |   40 ++-
 source3/Makefile.in                |    1 +
 source3/lib/dbwrap/dbwrap_ctdb.c   |  460 +++++++++++++++++-------------------
 source3/lib/dbwrap/dbwrap_watch.c  |    5 +-
 source3/torture/proto.h            |    1 +
 source3/torture/test_dbwrap_ctdb.c |  149 ++++++++++++
 source3/torture/torture.c          |    1 +
 source3/wscript_build              |    1 +
 11 files changed, 402 insertions(+), 274 deletions(-)
 create mode 100644 source3/torture/test_dbwrap_ctdb.c


Changeset truncated at 500 lines:

diff --git a/lib/dbwrap/dbwrap_cache.c b/lib/dbwrap/dbwrap_cache.c
index f2a9c5f..d97242e 100644
--- a/lib/dbwrap/dbwrap_cache.c
+++ b/lib/dbwrap/dbwrap_cache.c
@@ -180,7 +180,7 @@ struct db_context *db_open_cache(TALLOC_CTX *mem_ctx,
 	struct db_context *db;
 	struct db_cache_ctx *ctx;
 
-	db = talloc(mem_ctx, struct db_context);
+	db = talloc_zero(mem_ctx, struct db_context);
 	if (db == NULL) {
 		return NULL;
 	}
@@ -199,7 +199,6 @@ struct db_context *db_open_cache(TALLOC_CTX *mem_ctx,
 	}
 
 	db->fetch_locked = dbwrap_cache_fetch_locked;
-	db->try_fetch_locked = NULL;
 	db->traverse = dbwrap_cache_traverse;
 	db->traverse_read = dbwrap_cache_traverse_read;
 	db->get_seqnum = dbwrap_cache_get_seqnum;
@@ -211,9 +210,5 @@ struct db_context *db_open_cache(TALLOC_CTX *mem_ctx,
 	db->id = dbwrap_cache_id;
 	db->name = dbwrap_name(ctx->backing);
 	db->hash_size = dbwrap_hash_size(ctx->backing);
-	db->stored_callback = NULL;
-	db->wipe = NULL;
-	db->lock_order = 0;
-	db->persistent = false;
 	return db;
 }
diff --git a/lib/dbwrap/dbwrap_rbt.c b/lib/dbwrap/dbwrap_rbt.c
index afe9974..3f97086 100644
--- a/lib/dbwrap/dbwrap_rbt.c
+++ b/lib/dbwrap/dbwrap_rbt.c
@@ -480,7 +480,7 @@ struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx)
 {
 	struct db_context *result;
 
-	result = talloc(mem_ctx, struct db_context);
+	result = talloc_zero(mem_ctx, struct db_context);
 
 	if (result == NULL) {
 		return NULL;
@@ -494,7 +494,6 @@ struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx)
 	}
 
 	result->fetch_locked = db_rbt_fetch_locked;
-	result->try_fetch_locked = NULL;
 	result->traverse = db_rbt_traverse;
 	result->traverse_read = db_rbt_traverse_read;
 	result->get_seqnum = db_rbt_get_seqnum;
@@ -504,11 +503,8 @@ struct db_context *db_open_rbt(TALLOC_CTX *mem_ctx)
 	result->exists = db_rbt_exists;
 	result->wipe = db_rbt_wipe;
 	result->parse_record = db_rbt_parse_record;
-	result->lock_order = 0;
 	result->id = db_rbt_id;
 	result->name = "dbwrap rbt";
-	result->hash_size = 0;
-	result->stored_callback = NULL;
 
 	return result;
 }
diff --git a/lib/dbwrap/dbwrap_tdb.c b/lib/dbwrap/dbwrap_tdb.c
index a3a6c87..b62dcdf 100644
--- a/lib/dbwrap/dbwrap_tdb.c
+++ b/lib/dbwrap/dbwrap_tdb.c
@@ -473,14 +473,11 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
 	result->wipe = db_tdb_wipe;
 	result->id = db_tdb_id;
 	result->check = db_tdb_check;
-	result->stored_callback = NULL;
 	result->name = tdb_name(db_tdb->wtdb->tdb);
 	result->hash_size = hash_size;
 	return result;
 
  fail:
-	if (result != NULL) {
-		TALLOC_FREE(result);
-	}
+	TALLOC_FREE(result);
 	return NULL;
 }
diff --git a/lib/dbwrap/dbwrap_util.c b/lib/dbwrap/dbwrap_util.c
index d0a34cc..4185fff 100644
--- a/lib/dbwrap/dbwrap_util.c
+++ b/lib/dbwrap/dbwrap_util.c
@@ -97,32 +97,46 @@ NTSTATUS dbwrap_store_int32_bystring(struct db_context *db, const char *keystr,
 	return status;
 }
 
+struct dbwrap_fetch_uint32_state {
+	NTSTATUS status;
+	uint32_t result;
+};
+
+static void dbwrap_fetch_uint32_parser(TDB_DATA key, TDB_DATA data,
+				       void *private_data)
+{
+	struct dbwrap_fetch_uint32_state *state =
+		(struct dbwrap_fetch_uint32_state *)private_data;
+
+	if (data.dsize != sizeof(state->result)) {
+		state->status = NT_STATUS_INTERNAL_DB_CORRUPTION;
+		return;
+	}
+	state->result = IVAL(data.dptr, 0);
+	state->status = NT_STATUS_OK;
+}
+
 NTSTATUS dbwrap_fetch_uint32_bystring(struct db_context *db,
 				      const char *keystr, uint32_t *val)
 {
-	TDB_DATA dbuf;
+	struct dbwrap_fetch_uint32_state state;
 	NTSTATUS status;
 
 	if (val == NULL) {
 		return NT_STATUS_INVALID_PARAMETER;
 	}
 
-	status = dbwrap_fetch_bystring(db, talloc_tos(), keystr, &dbuf);
+	state.status = NT_STATUS_INTERNAL_ERROR;
+
+	status = dbwrap_parse_record(db, string_term_tdb_data(keystr),
+				     dbwrap_fetch_uint32_parser, &state);
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
-
-	if ((dbuf.dptr == NULL) || (dbuf.dsize == 0)) {
-		return NT_STATUS_NOT_FOUND;
-	}
-	if (dbuf.dsize != sizeof(uint32_t)) {
-		TALLOC_FREE(dbuf.dptr);
-		return NT_STATUS_UNSUCCESSFUL;
+	if (NT_STATUS_IS_OK(state.status)) {
+		*val = state.result;
 	}
-
-	*val = IVAL(dbuf.dptr, 0);
-	TALLOC_FREE(dbuf.dptr);
-	return NT_STATUS_OK;
+	return state.status;
 }
 
 NTSTATUS dbwrap_store_uint32_bystring(struct db_context *db,
diff --git a/source3/Makefile.in b/source3/Makefile.in
index a2d7906..3555687 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -1267,6 +1267,7 @@ SMBTORTURE_OBJ1 = torture/torture.o torture/nbio.o torture/scanner.o torture/uta
 		torture/test_notify.o \
 		torture/test_dbwrap_watch.o \
 		torture/test_idmap_tdb_common.o \
+		torture/test_dbwrap_ctdb.o \
 		torture/t_strappend.o
 
 SMBTORTURE_OBJ = $(SMBTORTURE_OBJ1) $(PARAM_OBJ) $(TLDAP_OBJ) \
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index e4c87ea..c96dda2 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -88,58 +88,47 @@ static NTSTATUS tdb_error_to_ntstatus(struct tdb_context *tdb)
 	return map_nt_error_from_tdb(tret);
 }
 
+struct db_ctdb_ltdb_parse_state {
+	void (*parser)(TDB_DATA key, struct ctdb_ltdb_header *header,
+		       TDB_DATA data, void *private_data);
+	void *private_data;
+};
 
-/**
- * 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)
+static int db_ctdb_ltdb_parser(TDB_DATA key, TDB_DATA data,
+			       void *private_data)
 {
-	TDB_DATA rec;
-	NTSTATUS status;
-
-	rec = tdb_fetch_compat(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;
-	}
+	struct db_ctdb_ltdb_parse_state *state =
+		(struct db_ctdb_ltdb_parse_state *)private_data;
 
-	if (header) {
-		*header = *(struct ctdb_ltdb_header *)rec.dptr;
+	if (data.dsize < sizeof(struct ctdb_ltdb_header)) {
+		return -1;
 	}
+	state->parser(
+		key, (struct ctdb_ltdb_header *)data.dptr,
+		make_tdb_data(data.dptr + sizeof(struct ctdb_ltdb_header),
+			      data.dsize - sizeof(struct ctdb_ltdb_header)),
+		state->private_data);
+	return 0;
+}
 
-	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;
-			}
-		}
-	}
+static NTSTATUS db_ctdb_ltdb_parse(
+	struct db_ctdb_ctx *db, TDB_DATA key,
+	void (*parser)(TDB_DATA key, struct ctdb_ltdb_header *header,
+		       TDB_DATA data, void *private_data),
+	void *private_data)
+{
+	struct db_ctdb_ltdb_parse_state state;
+	int ret;
 
-	status = NT_STATUS_OK;
+	state.parser = parser;
+	state.private_data = private_data;
 
-done:
-	SAFE_FREE(rec.dptr);
-	return status;
+	ret = tdb_parse_record(db->wtdb->tdb, key, db_ctdb_ltdb_parser,
+			       &state);
+	if (ret == -1) {
+		return NT_STATUS_NOT_FOUND;
+	}
+	return NT_STATUS_OK;
 }
 
 /*
@@ -177,9 +166,6 @@ static NTSTATUS db_ctdb_ltdb_store(struct db_ctdb_ctx *db,
 
 /*
   form a ctdb_rec_data record from a key/data pair
-
-  note that header may be NULL. If not NULL then it is included in the data portion
-  of the record
  */
 static struct ctdb_rec_data *db_ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32_t reqid,
 						  TDB_DATA key,
@@ -190,7 +176,7 @@ static struct ctdb_rec_data *db_ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32
 	struct ctdb_rec_data *d;
 
 	length = offsetof(struct ctdb_rec_data, data) + key.dsize +
-		data.dsize + (header?sizeof(*header):0);
+		data.dsize + sizeof(*header);
 	d = (struct ctdb_rec_data *)talloc_size(mem_ctx, length);
 	if (d == NULL) {
 		return NULL;
@@ -199,14 +185,10 @@ static struct ctdb_rec_data *db_ctdb_marshall_record(TALLOC_CTX *mem_ctx, uint32
 	d->reqid = reqid;
 	d->keylen = key.dsize;
 	memcpy(&d->data[0], key.dptr, key.dsize);
-	if (header) {
-		d->datalen = data.dsize + sizeof(*header);
-		memcpy(&d->data[key.dsize], header, sizeof(*header));
-		memcpy(&d->data[key.dsize+sizeof(*header)], data.dptr, data.dsize);
-	} else {
-		d->datalen = data.dsize;
-		memcpy(&d->data[key.dsize], data.dptr, data.dsize);
-	}
+
+	d->datalen = data.dsize + sizeof(*header);
+	memcpy(&d->data[key.dsize], header, sizeof(*header));
+	memcpy(&d->data[key.dsize+sizeof(*header)], data.dptr, data.dsize);
 	return d;
 }
 
@@ -273,10 +255,8 @@ static TDB_DATA db_ctdb_marshall_finish(struct ctdb_marshall_buffer *m)
      - pass r==NULL to start
      - loop the number of times indicated by m->count
 */
-static struct ctdb_rec_data *db_ctdb_marshall_loop_next(struct ctdb_marshall_buffer *m, struct ctdb_rec_data *r,
-						     uint32_t *reqid,
-						     struct ctdb_ltdb_header *header,
-						     TDB_DATA *key, TDB_DATA *data)
+static struct ctdb_rec_data *db_ctdb_marshall_loop_next_key(
+	struct ctdb_marshall_buffer *m, struct ctdb_rec_data *r, TDB_DATA *key)
 {
 	if (r == NULL) {
 		r = (struct ctdb_rec_data *)&m->data[0];
@@ -284,31 +264,27 @@ static struct ctdb_rec_data *db_ctdb_marshall_loop_next(struct ctdb_marshall_buf
 		r = (struct ctdb_rec_data *)(r->length + (uint8_t *)r);
 	}
 
-	if (reqid != NULL) {
-		*reqid = r->reqid;
-	}
+	key->dptr   = &r->data[0];
+	key->dsize  = r->keylen;
+	return r;
+}
 
-	if (key != NULL) {
-		key->dptr   = &r->data[0];
-		key->dsize  = r->keylen;
-	}
-	if (data != NULL) {
-		data->dptr  = &r->data[r->keylen];
-		data->dsize = r->datalen;
-		if (header != NULL) {
-			data->dptr += sizeof(*header);
-			data->dsize -= sizeof(*header);
-		}
+static bool db_ctdb_marshall_buf_parse(
+	struct ctdb_rec_data *r, uint32_t *reqid,
+	struct ctdb_ltdb_header **header, TDB_DATA *data)
+{
+	if (r->datalen < sizeof(struct ctdb_ltdb_header)) {
+		return false;
 	}
 
-	if (header != NULL) {
-		if (r->datalen < sizeof(*header)) {
-			return NULL;
-		}
-		*header = *(struct ctdb_ltdb_header *)&r->data[r->keylen];
-	}
+	*reqid = r->reqid;
 
-	return r;
+	data->dptr  = &r->data[r->keylen] + sizeof(struct ctdb_ltdb_header);
+	data->dsize = r->datalen - sizeof(struct ctdb_ltdb_header);
+
+	*header = (struct ctdb_ltdb_header *)&r->data[r->keylen];
+
+	return true;
 }
 
 /**
@@ -387,15 +363,14 @@ static int db_ctdb_transaction_start(struct db_context *db)
 	return 0;
 }
 
-static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf,
-					     TDB_DATA key,
-					     struct ctdb_ltdb_header *pheader,
-					     TALLOC_CTX *mem_ctx,
-					     TDB_DATA *pdata)
+static bool parse_newest_in_marshall_buffer(
+	struct ctdb_marshall_buffer *buf, TDB_DATA key,
+	void (*parser)(TDB_DATA key, struct ctdb_ltdb_header *header,
+		       TDB_DATA data, void *private_data),
+	void *private_data)
 {
 	struct ctdb_rec_data *rec = NULL;
-	struct ctdb_ltdb_header h;
-	bool found = false;
+	struct ctdb_ltdb_header *h = NULL;
 	TDB_DATA data;
 	int i;
 
@@ -403,9 +378,6 @@ static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf,
 		return false;
 	}
 
-	ZERO_STRUCT(h);
-	ZERO_STRUCT(data);
-
 	/*
 	 * Walk the list of records written during this
 	 * transaction. If we want to read one we have already
@@ -415,95 +387,77 @@ static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf,
 	 */
 
 	for (i=0; i<buf->count; i++) {
-		TDB_DATA tkey, tdata;
+		TDB_DATA tkey;
 		uint32_t reqid;
-		struct ctdb_ltdb_header hdr;
 
-		ZERO_STRUCT(hdr);
-
-		rec = db_ctdb_marshall_loop_next(buf, rec, &reqid, &hdr, &tkey,
-						 &tdata);
+		rec = db_ctdb_marshall_loop_next_key(buf, rec, &tkey);
 		if (rec == NULL) {
 			return false;
 		}
 
-		if (tdb_data_equal(key, tkey)) {
-			found = true;
-			data = tdata;
-			h = hdr;
+		if (!tdb_data_equal(key, tkey)) {
+			continue;
 		}
-	}
-
-	if (!found) {
-		return false;
-	}
 
-	if (pdata != NULL) {
-		data.dptr = (uint8_t *)talloc_memdup(mem_ctx, data.dptr,
-						     data.dsize);
-		if ((data.dsize != 0) && (data.dptr == NULL)) {
+		if (!db_ctdb_marshall_buf_parse(rec, &reqid, &h, &data)) {
 			return false;
 		}
-		*pdata = data;
 	}
 
-	if (pheader != NULL) {
-		*pheader = h;
+	if (h == NULL) {
+		return false;
 	}
 
+	parser(key, h, data, private_data);
+
 	return true;
 }
 
-/*
-  fetch a record inside a transaction
- */
-static NTSTATUS db_ctdb_transaction_fetch(struct db_ctdb_ctx *db,
-					  TALLOC_CTX *mem_ctx,
-					  TDB_DATA key, TDB_DATA *data)
+struct pull_newest_from_marshall_buffer_state {
+	struct ctdb_ltdb_header *pheader;
+	TALLOC_CTX *mem_ctx;
+	TDB_DATA *pdata;
+};
+
+static void pull_newest_from_marshall_buffer_parser(
+	TDB_DATA key, struct ctdb_ltdb_header *header,
+	TDB_DATA data, void *private_data)
 {
-	struct db_ctdb_transaction_handle *h = db->transaction;
-	NTSTATUS status;
-	bool found;
+	struct pull_newest_from_marshall_buffer_state *state =
+		(struct pull_newest_from_marshall_buffer_state *)private_data;
 
-	found = pull_newest_from_marshall_buffer(h->m_write, key, NULL,
-						 mem_ctx, data);
-	if (found) {
-		return NT_STATUS_OK;
+	if (state->pheader != NULL) {
+		memcpy(state->pheader, header, sizeof(*state->pheader));
 	}
-
-	status = db_ctdb_ltdb_fetch(h->ctx, key, NULL, mem_ctx, data);
-
-	if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
-		*data = tdb_null;
+	if (state->pdata != NULL) {
+		state->pdata->dsize = data.dsize;
+		state->pdata->dptr = (uint8_t *)talloc_memdup(
+			state->mem_ctx, data.dptr, data.dsize);
 	}
-
-	return status;
 }
 
-/**
- * Fetch a record from a persistent database
- * without record locking and without an active transaction.
- *
- * This just fetches from the local database copy.
- * Since the databases are kept in syc cluster-wide,
- * there is no point in doing a ctdb call to fetch the
- * record from the lmaster. It does even harm since migration
- * of records bump their RSN and hence render the persistent
- * database inconsistent.
- */
-static NTSTATUS db_ctdb_fetch_persistent(struct db_ctdb_ctx *db,
-					 TALLOC_CTX *mem_ctx,
-					 TDB_DATA key, TDB_DATA *data)
+static bool pull_newest_from_marshall_buffer(struct ctdb_marshall_buffer *buf,
+					     TDB_DATA key,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list