[SCM] Samba Shared Repository - branch master updated

Amitay Isaacs amitay at samba.org
Tue Mar 27 07:07:03 UTC 2018


The branch, master has been updated
       via  ce5116c ctdb-tests: Don't expand octal escapes in unit test output
       via  7da9802 ctdb-tests: Add debug messages for unimplemented functions
       via  c865658 ctdb-tests: Add database traverse tests
       via  a5fb33e ctdb-tests: Implement traverse control in fake_ctdbd
       via  2a8e425 ctdb-tests: Add persistent database tests
       via  8250956 ctdb-tests: Implement transaction control in fake_ctdbd
       via  7c30d47 ctdb-tests: Add volatile database tests
       via  5be29b7 ctdb-tests: Add req_call processing in fake_ctdbd
       via  0e5e846 ctdb-tests: Use seqnum from tdb if available in fake_ctdbd
       via  14bdbef ctdb-tests: Add database attach tests
       via  50e2541 ctdb-tests: Implement database attach control in fake_ctdbd
       via  2de6607 ctdb-tests: Add dbdir option for creating databases in fake_ctdbd
       via  147ff85 ctdb-tests: Convert database map to a linked list in fake_ctdbd
       via  4e37be9 ctdb-client: Add missing initialization of tevent_context
       via  92a68af ctdb-client: Do not try to allocate 0 sized record
      from  2610a3f winbindd: Use talloc_zero_array for consistency with other winbindd_domain allocators

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


- Log -----------------------------------------------------------------
commit ce5116cfb3990de8a088012bee9fd9f94bd21c97
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon Mar 26 18:32:57 2018 +1100

    ctdb-tests: Don't expand octal escapes in unit test output
    
    The echo command in dash expands octal escapes in strings by default
    but the echo command in bash doesn't.  Since the behaviour is
    ill-defined, use printf to handle affected strings.  However, ensure
    that these strings aren't used as format strings.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>
    
    Autobuild-User(master): Amitay Isaacs <amitay at samba.org>
    Autobuild-Date(master): Tue Mar 27 09:06:14 CEST 2018 on sn-devel-144

commit 7da9802acdb1ec1d76050064f54aae38b21a03d4
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Mar 19 14:26:09 2018 +1100

    ctdb-tests: Add debug messages for unimplemented functions
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit c86565885d8aefc3d67ed80165332bfaa3f33ea4
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Feb 5 16:08:32 2018 +1100

    ctdb-tests: Add database traverse tests
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit a5fb33e277217fc8526f409a04ba0718c20cefe8
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Feb 5 15:59:26 2018 +1100

    ctdb-tests: Implement traverse control in fake_ctdbd
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 2a8e425767faf1dbe671eb25bb4cfcddfb5a7bb5
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Aug 28 15:29:58 2017 +1000

    ctdb-tests: Add persistent database tests
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 8250956c9222264a774bf4fb7c86527630ee2655
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Feb 5 14:03:27 2018 +1100

    ctdb-tests: Implement transaction control in fake_ctdbd
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 7c30d4791d0b3c7e47bf8f12a66d0450d1190270
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Mar 19 14:00:02 2018 +1100

    ctdb-tests: Add volatile database tests
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 5be29b792d2a48efcddc9137cbee250f42d31a2d
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Feb 5 15:56:57 2018 +1100

    ctdb-tests: Add req_call processing in fake_ctdbd
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 0e5e8469262344f60b7ecca9e2d1cc6aba54f6f9
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Feb 5 14:01:29 2018 +1100

    ctdb-tests: Use seqnum from tdb if available in fake_ctdbd
    
    This also adds the lower level ltdb read/write functions required to
    read seqnum from database.
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 14bdbef9c111a358e7f6e64abd8d2e4bae997976
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Fri Aug 25 17:20:04 2017 +1000

    ctdb-tests: Add database attach tests
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 50e25418e0807ec8ef0afd9b529b975fa3bcba18
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Feb 5 13:59:22 2018 +1100

    ctdb-tests: Implement database attach control in fake_ctdbd
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 2de660722d4e4faf01d7cb251746af6497a777a9
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Feb 5 12:43:02 2018 +1100

    ctdb-tests: Add dbdir option for creating databases in fake_ctdbd
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 147ff850aada14b4930e705ed5b065c5eca22bac
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Feb 5 12:11:32 2018 +1100

    ctdb-tests: Convert database map to a linked list in fake_ctdbd
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 4e37be92bfb790150b3791bef552aa4acf8f78b7
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Mar 19 13:58:43 2018 +1100

    ctdb-client: Add missing initialization of tevent_context
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13356
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

commit 92a68af1a8473dc2a5d9d6036830f944e968606d
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Mon Mar 19 13:38:28 2018 +1100

    ctdb-client: Do not try to allocate 0 sized record
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13356
    
    Signed-off-by: Amitay Isaacs <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>

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

Summary of changes:
 ctdb/client/client_db.c                            |  20 +-
 ctdb/tests/scripts/unit.sh                         |  15 +-
 ctdb/tests/src/fake_ctdbd.c                        | 803 ++++++++++++++++++++-
 ctdb/tests/takeover_helper/scripts/local.sh        |   6 +-
 ctdb/tests/tool/ctdb.attach.001.sh                 |  35 +
 ctdb/tests/tool/ctdb.attach.002.sh                 |  35 +
 ctdb/tests/tool/ctdb.attach.003.sh                 |  35 +
 ctdb/tests/tool/ctdb.catdb.001.sh                  |  80 ++
 ctdb/tests/tool/ctdb.catdb.002.sh                  |  86 +++
 ctdb/tests/tool/ctdb.cattdb.001.sh                 |  80 ++
 ctdb/tests/tool/ctdb.cattdb.002.sh                 |  86 +++
 ctdb/tests/tool/ctdb.deletekey.001.sh              |  34 +
 ctdb/tests/tool/ctdb.getdbmap.001.sh               |  14 +-
 ctdb/tests/tool/ctdb.getdbstatus.001.sh            |  14 +-
 ctdb/tests/tool/ctdb.getdbstatus.002.sh            |  14 +-
 ctdb/tests/tool/ctdb.pdelete.001.sh                |  27 +
 ctdb/tests/tool/ctdb.pstore.001.sh                 |  24 +
 ctdb/tests/tool/ctdb.ptrans.001.sh                 |  49 ++
 ...{ctdb.getreclock.001.sh => ctdb.readkey.001.sh} |   8 +-
 ctdb/tests/tool/ctdb.setdbreadonly.001.sh          |  28 +-
 ctdb/tests/tool/ctdb.setdbreadonly.002.sh          |  14 +-
 ctdb/tests/tool/ctdb.setdbreadonly.003.sh          |  14 +-
 ctdb/tests/tool/ctdb.setdbreadonly.004.sh          |  14 +-
 ctdb/tests/tool/ctdb.setdbreadonly.005.sh          |  14 +-
 ctdb/tests/tool/ctdb.setdbsticky.001.sh            |  28 +-
 ctdb/tests/tool/ctdb.setdbsticky.002.sh            |  14 +-
 ctdb/tests/tool/ctdb.setdbsticky.003.sh            |  14 +-
 ctdb/tests/tool/ctdb.setdbsticky.004.sh            |  14 +-
 ctdb/tests/tool/ctdb.setdbsticky.005.sh            |  14 +-
 ctdb/tests/tool/ctdb.writekey.001.sh               |  31 +
 ctdb/tests/tool/scripts/local.sh                   |   6 +-
 31 files changed, 1518 insertions(+), 152 deletions(-)
 create mode 100755 ctdb/tests/tool/ctdb.attach.001.sh
 create mode 100755 ctdb/tests/tool/ctdb.attach.002.sh
 create mode 100755 ctdb/tests/tool/ctdb.attach.003.sh
 create mode 100755 ctdb/tests/tool/ctdb.catdb.001.sh
 create mode 100755 ctdb/tests/tool/ctdb.catdb.002.sh
 create mode 100755 ctdb/tests/tool/ctdb.cattdb.001.sh
 create mode 100755 ctdb/tests/tool/ctdb.cattdb.002.sh
 create mode 100755 ctdb/tests/tool/ctdb.deletekey.001.sh
 create mode 100755 ctdb/tests/tool/ctdb.pdelete.001.sh
 create mode 100755 ctdb/tests/tool/ctdb.pstore.001.sh
 create mode 100755 ctdb/tests/tool/ctdb.ptrans.001.sh
 copy ctdb/tests/tool/{ctdb.getreclock.001.sh => ctdb.readkey.001.sh} (58%)
 create mode 100755 ctdb/tests/tool/ctdb.writekey.001.sh


Changeset truncated at 500 lines:

diff --git a/ctdb/client/client_db.c b/ctdb/client/client_db.c
index e86830e..c0ecdeb 100644
--- a/ctdb/client/client_db.c
+++ b/ctdb/client/client_db.c
@@ -1191,6 +1191,7 @@ struct tevent_req *ctdb_fetch_lock_send(TALLOC_CTX *mem_ctx,
 	if (tevent_req_nomem(state->h, req)) {
 		return tevent_req_post(req, ev);
 	}
+	state->h->ev = ev;
 	state->h->client = client;
 	state->h->db = db;
 	state->h->key.dptr = talloc_memdup(state->h, key.dptr, key.dsize);
@@ -1413,14 +1414,19 @@ struct ctdb_record_handle *ctdb_fetch_lock_recv(struct tevent_req *req,
 		offset = ctdb_ltdb_header_len(&h->header);
 
 		data->dsize = h->data.dsize - offset;
-		data->dptr = talloc_memdup(mem_ctx, h->data.dptr + offset,
-					   data->dsize);
-		if (data->dptr == NULL) {
-			TALLOC_FREE(state->h);
-			if (perr != NULL) {
-				*perr = ENOMEM;
+		if (data->dsize == 0) {
+			data->dptr = NULL;
+		} else {
+			data->dptr = talloc_memdup(mem_ctx,
+						   h->data.dptr + offset,
+						   data->dsize);
+			if (data->dptr == NULL) {
+				TALLOC_FREE(state->h);
+				if (perr != NULL) {
+					*perr = ENOMEM;
+				}
+				return NULL;
 			}
-			return NULL;
 		}
 	}
 
diff --git a/ctdb/tests/scripts/unit.sh b/ctdb/tests/scripts/unit.sh
index 7a0296e..8e72803 100644
--- a/ctdb/tests/scripts/unit.sh
+++ b/ctdb/tests/scripts/unit.sh
@@ -75,7 +75,8 @@ cat <<EOF
 Output (Exit status: ${_rc}):
 --------------------------------------------------
 EOF
-	echo "$_out" | result_filter | cat $TEST_CAT_RESULTS_OPTS
+	# Avoid echo, which might expand unintentional escapes
+	printf '%s\n' "$_out" | result_filter | cat $TEST_CAT_RESULTS_OPTS
     fi
 
     if ! $_passed ; then
@@ -84,14 +85,17 @@ EOF
 Required output (Exit status: ${required_rc}):
 --------------------------------------------------
 EOF
-	echo "$required_output" | cat $TEST_CAT_RESULTS_OPTS
+	# Avoid echo, which might expand unintentional escapes
+	printf '%s\n' "$required_output" | cat $TEST_CAT_RESULTS_OPTS
 
 	if $TEST_DIFF_RESULTS ; then
 	    _outr=$(mktemp)
-	    echo "$required_output" >"$_outr"
+	    # Avoid echo, which might expand unintentional escapes
+	    printf '%s\n' "$required_output" >"$_outr"
 
 	    _outf=$(mktemp)
-	    echo "$_fout" >"$_outf"
+	    # Avoid echo, which might expand unintentional escapes
+	    printf '%s\n' "$_fout" >"$_outf"
 
 	    cat <<EOF
 --------------------------------------------------
@@ -143,7 +147,8 @@ result_check ()
 {
     _rc=$?
 
-    _fout=$(echo "$_out" | result_filter)
+    # Avoid echo, which might expand unintentional escapes
+    _fout=$(printf '%s\n' "$_out" | result_filter)
 
     if [ "$_fout" = "$required_output" -a $_rc = $required_rc ] ; then
 	_passed=true
diff --git a/ctdb/tests/src/fake_ctdbd.c b/ctdb/tests/src/fake_ctdbd.c
index 623f6df..7d18de4 100644
--- a/ctdb/tests/src/fake_ctdbd.c
+++ b/ctdb/tests/src/fake_ctdbd.c
@@ -20,6 +20,7 @@
 #include "replace.h"
 #include "system/network.h"
 #include "system/time.h"
+#include "system/filesys.h"
 
 #include <popt.h>
 #include <talloc.h>
@@ -35,6 +36,7 @@
 #include "protocol/protocol.h"
 #include "protocol/protocol_api.h"
 #include "protocol/protocol_util.h"
+#include "protocol/protocol_private.h"
 
 #include "common/comm.h"
 #include "common/logging.h"
@@ -84,15 +86,18 @@ struct vnn_map {
 };
 
 struct database {
+	struct database *prev, *next;
 	const char *name;
+	const char *path;
+	struct tdb_context *tdb;
 	uint32_t id;
 	uint8_t flags;
 	uint64_t seq_num;
 };
 
 struct database_map {
-	int num_dbs;
 	struct database *db;
+	const char *dbdir;
 };
 
 struct fake_control_failure {
@@ -629,7 +634,8 @@ fail:
 	return false;
 }
 
-static struct database_map *dbmap_init(TALLOC_CTX *mem_ctx)
+static struct database_map *dbmap_init(TALLOC_CTX *mem_ctx,
+				       const char *dbdir)
 {
 	struct database_map *db_map;
 
@@ -638,6 +644,12 @@ static struct database_map *dbmap_init(TALLOC_CTX *mem_ctx)
 		return NULL;
 	}
 
+	db_map->dbdir = talloc_strdup(db_map, dbdir);
+	if (db_map->dbdir == NULL) {
+		talloc_free(db_map);
+		return NULL;
+	}
+
 	return db_map;
 }
 
@@ -714,20 +726,22 @@ static bool dbmap_parse(struct database_map *db_map)
 			tok = strtok(NULL, " \t");
 		}
 
-		db_map->db = talloc_realloc(db_map, db_map->db,
-					    struct database,
-					    db_map->num_dbs + 1);
-		if (db_map->db == NULL) {
+		db = talloc_zero(db_map, struct database);
+		if (db == NULL) {
 			goto fail;
 		}
-		db = &db_map->db[db_map->num_dbs];
 
 		db->id = id;
-		db->name = name;
+		db->name = talloc_steal(db, name);
+		db->path = talloc_asprintf(db, "%s/%s", db_map->dbdir, name);
+		if (db->path == NULL) {
+			talloc_free(db);
+			goto fail;
+		}
 		db->flags = flags;
 		db->seq_num = seq_num;
 
-		db_map->num_dbs += 1;
+		DLIST_ADD_END(db_map->db, db);
 	}
 
 	DEBUG(DEBUG_INFO, ("Parsing dbmap done\n"));
@@ -739,14 +753,12 @@ fail:
 
 }
 
-static struct database *database_find(struct database_map *map,
+static struct database *database_find(struct database_map *db_map,
 				      uint32_t db_id)
 {
-	int i;
-
-	for (i = 0; i < map->num_dbs; i++) {
-		struct database *db = &map->db[i];
+	struct database *db;
 
+	for (db = db_map->db; db != NULL; db = db->next) {
 		if (db->id == db_id) {
 			return db;
 		}
@@ -755,6 +767,270 @@ static struct database *database_find(struct database_map *map,
 	return NULL;
 }
 
+static int database_count(struct database_map *db_map)
+{
+	struct database *db;
+	int count = 0;
+
+	for (db = db_map->db; db != NULL; db = db->next) {
+		count += 1;
+	}
+
+	return count;
+}
+
+static int database_flags(uint8_t db_flags)
+{
+	int tdb_flags = 0;
+
+	if (db_flags & CTDB_DB_FLAGS_PERSISTENT) {
+		tdb_flags = TDB_DEFAULT;
+	} else {
+		/* volatile and replicated use the same flags */
+		tdb_flags = TDB_NOSYNC |
+			    TDB_CLEAR_IF_FIRST |
+			    TDB_INCOMPATIBLE_HASH;
+	}
+
+	tdb_flags |= TDB_DISALLOW_NESTING;
+
+	return tdb_flags;
+}
+
+static struct database *database_new(struct database_map *db_map,
+				     const char *name, uint8_t flags)
+{
+	struct database *db;
+	TDB_DATA key;
+	int tdb_flags;
+
+	db = talloc_zero(db_map, struct database);
+	if (db == NULL) {
+		return NULL;
+	}
+
+	db->name = talloc_strdup(db, name);
+	if (db->name == NULL) {
+		goto fail;
+	}
+
+	db->path = talloc_asprintf(db, "%s/%s", db_map->dbdir, name);
+	if (db->path == NULL) {
+		goto fail;
+	}
+
+	key.dsize = strlen(db->name) + 1;
+	key.dptr = discard_const(db->name);
+
+	db->id = tdb_jenkins_hash(&key);
+	db->flags = flags;
+
+	tdb_flags = database_flags(flags);
+
+	db->tdb = tdb_open(db->path, 8192, tdb_flags, O_CREAT|O_RDWR, 0644);
+	if (db->tdb == NULL) {
+		DBG_ERR("tdb_open\n");
+		goto fail;
+	}
+
+	DLIST_ADD_END(db_map->db, db);
+	return db;
+
+fail:
+	DBG_ERR("Memory error\n");
+	talloc_free(db);
+	return NULL;
+
+}
+
+static int ltdb_store(struct database *db, TDB_DATA key,
+		      struct ctdb_ltdb_header *header, TDB_DATA data)
+{
+	int ret;
+	bool db_volatile = true;
+	bool keep = false;
+
+	if (db->tdb == NULL) {
+		return EINVAL;
+	}
+
+	if ((db->flags & CTDB_DB_FLAGS_PERSISTENT) ||
+	    (db->flags & CTDB_DB_FLAGS_REPLICATED)) {
+		db_volatile = false;
+	}
+
+	if (data.dsize > 0) {
+		keep = true;
+	} else {
+		if (db_volatile && header->rsn == 0) {
+			keep = true;
+		}
+	}
+
+	if (keep) {
+		TDB_DATA rec[2];
+
+		rec[0].dsize = ctdb_ltdb_header_len(header);
+		rec[0].dptr = (uint8_t *)header;
+
+		rec[1].dsize = data.dsize;
+		rec[1].dptr = data.dptr;
+
+		ret = tdb_storev(db->tdb, key, rec, 2, TDB_REPLACE);
+	} else {
+		if (header->rsn > 0) {
+			ret = tdb_delete(db->tdb, key);
+		} else {
+			ret = 0;
+		}
+	}
+
+	return ret;
+}
+
+static int ltdb_fetch(struct database *db, TDB_DATA key,
+		      struct ctdb_ltdb_header *header,
+		      TALLOC_CTX *mem_ctx, TDB_DATA *data)
+{
+	TDB_DATA rec;
+	size_t np;
+	int ret;
+
+	if (db->tdb == NULL) {
+		return EINVAL;
+	}
+
+	rec = tdb_fetch(db->tdb, key);
+	ret = ctdb_ltdb_header_pull(rec.dptr, rec.dsize, header, &np);
+	if (ret != 0) {
+		if (rec.dptr != NULL) {
+			free(rec.dptr);
+		}
+
+		*header = (struct ctdb_ltdb_header) {
+			.rsn = 0,
+			.dmaster = 0,
+			.flags = 0,
+		};
+
+		ret = ltdb_store(db, key, header, tdb_null);
+		if (ret != 0) {
+			return ret;
+		}
+
+		*data = tdb_null;
+		return 0;
+	}
+
+	data->dsize = rec.dsize - ctdb_ltdb_header_len(header);
+	data->dptr = talloc_memdup(mem_ctx,
+				   rec.dptr + ctdb_ltdb_header_len(header),
+				   data->dsize);
+	if (data->dptr == NULL) {
+		free(rec.dptr);
+		return ENOMEM;
+	}
+
+	return 0;
+}
+
+static int database_seqnum(struct database *db, uint64_t *seqnum)
+{
+	const char *keyname = CTDB_DB_SEQNUM_KEY;
+	TDB_DATA key, data;
+	struct ctdb_ltdb_header header;
+	size_t np;
+	int ret;
+
+	if (db->tdb == NULL) {
+		*seqnum = db->seq_num;
+		return 0;
+	}
+
+	key.dptr = discard_const(keyname);
+	key.dsize = strlen(keyname) + 1;
+
+	ret = ltdb_fetch(db, key, &header, db, &data);
+	if (ret != 0) {
+		return ret;
+	}
+
+	if (data.dsize == 0) {
+		*seqnum = 0;
+		return 0;
+	}
+
+	ret = ctdb_uint64_pull(data.dptr, data.dsize, seqnum, &np);
+	talloc_free(data.dptr);
+	if (ret != 0) {
+		*seqnum = 0;
+	}
+
+	return ret;
+}
+
+static int ltdb_transaction_update(uint32_t reqid,
+				   struct ctdb_ltdb_header *no_header,
+				   TDB_DATA key, TDB_DATA data,
+				   void *private_data)
+{
+	struct database *db = (struct database *)private_data;
+	TALLOC_CTX *tmp_ctx = talloc_new(db);
+	struct ctdb_ltdb_header header = { 0 }, oldheader;
+	TDB_DATA olddata;
+	int ret;
+
+	if (db->tdb == NULL) {
+		return EINVAL;
+	}
+
+	ret = ctdb_ltdb_header_extract(&data, &header);
+	if (ret != 0) {
+		return ret;
+	}
+
+	ret = ltdb_fetch(db, key, &oldheader, tmp_ctx, &olddata);
+	if (ret != 0) {
+		return ret;
+	}
+
+	if (olddata.dsize > 0) {
+		if (oldheader.rsn > header.rsn ||
+		    (oldheader.rsn == header.rsn &&
+		     olddata.dsize != data.dsize)) {
+			return -1;
+		}
+	}
+
+	talloc_free(tmp_ctx);
+
+	ret = ltdb_store(db, key, &header, data);
+	return ret;
+}
+
+static int ltdb_transaction(struct database *db,
+			    struct ctdb_rec_buffer *recbuf)
+{
+	int ret;
+
+	if (db->tdb == NULL) {
+		return EINVAL;
+	}
+
+	ret = tdb_transaction_start(db->tdb);
+	if (ret == -1) {
+		return ret;
+	}
+
+	ret = ctdb_rec_buffer_traverse(recbuf, ltdb_transaction_update, db);
+	if (ret != 0) {
+		tdb_transaction_cancel(db->tdb);
+	}
+
+	ret = tdb_transaction_commit(db->tdb);
+	return ret;
+}
+
 static bool public_ips_parse(struct ctdbd_context *ctdb,
 			     uint32_t numnodes)
 {
@@ -929,7 +1205,8 @@ static uint32_t new_generation(uint32_t old_generation)
 	return generation;
 }
 
-static struct ctdbd_context *ctdbd_setup(TALLOC_CTX *mem_ctx)
+static struct ctdbd_context *ctdbd_setup(TALLOC_CTX *mem_ctx,
+					 const char *dbdir)
 {
 	struct ctdbd_context *ctdb;
 	char line[1024];
@@ -956,7 +1233,7 @@ static struct ctdbd_context *ctdbd_setup(TALLOC_CTX *mem_ctx)
 		goto fail;
 	}
 
-	ctdb->db_map = dbmap_init(ctdb);
+	ctdb->db_map = dbmap_init(ctdb, dbdir);
 	if (ctdb->db_map == NULL) {
 		goto fail;
 	}
@@ -1191,6 +1468,25 @@ static void header_fix_pnn(struct ctdb_req_header *header,
 	}
 }
 
+static struct ctdb_req_header header_reply_call(
+					struct ctdb_req_header *header,
+					struct ctdbd_context *ctdb)
+{
+	struct ctdb_req_header reply_header;
+
+	reply_header = (struct ctdb_req_header) {
+		.ctdb_magic = CTDB_MAGIC,
+		.ctdb_version = CTDB_PROTOCOL,
+		.generation = ctdb->vnn_map->generation,
+		.operation = CTDB_REPLY_CALL,


-- 
Samba Shared Repository



More information about the samba-cvs mailing list