[PATCH] remove "header" from tdb_context

Volker Lendecke Volker.Lendecke at SerNet.DE
Fri Feb 1 12:49:25 MST 2013


Hi!

As part of my mutex work I've shrunk the tdb_context a bit.
Attached.

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de

**********************************************************
visit us at CeBIT: March 5th - 9th 2013, hall 6, booth E15
all about SAMBA and verinice, firewalls, Linux and Windows
free tickets available via email here : cebit at sernet.com !
**********************************************************
-------------- next part --------------
From bc31243a9e1ed69db6bf589745d90796fac226f9 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 20 Dec 2012 16:14:23 +0100
Subject: [PATCH 1/3] tdb: Pass argument "header" to tdb_new_database

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/tdb/common/open.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c
index b10f5eb..6079463 100644
--- a/lib/tdb/common/open.c
+++ b/lib/tdb/common/open.c
@@ -51,7 +51,8 @@ void tdb_header_hash(struct tdb_context *tdb,
 }
 
 /* initialise a new database with a specified hash size */
-static int tdb_new_database(struct tdb_context *tdb, int hash_size)
+static int tdb_new_database(struct tdb_context *tdb, struct tdb_header *header,
+			    int hash_size)
 {
 	struct tdb_header *newdb;
 	size_t size;
@@ -78,7 +79,7 @@ static int tdb_new_database(struct tdb_context *tdb, int hash_size)
 	if (tdb->flags & TDB_INTERNAL) {
 		tdb->map_size = size;
 		tdb->map_ptr = (char *)newdb;
-		memcpy(&tdb->header, newdb, sizeof(tdb->header));
+		memcpy(header, newdb, sizeof(*header));
 		/* Convert the `ondisk' version if asked. */
 		CONVERT(*newdb);
 		return 0;
@@ -91,7 +92,7 @@ static int tdb_new_database(struct tdb_context *tdb, int hash_size)
 
 	/* This creates an endian-converted header, as if read from disk */
 	CONVERT(*newdb);
-	memcpy(&tdb->header, newdb, sizeof(tdb->header));
+	memcpy(header, newdb, sizeof(*header));
 	/* Don't endian-convert the magic food! */
 	memcpy(newdb->magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1);
 
@@ -286,7 +287,7 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
 	if (tdb->flags & TDB_INTERNAL) {
 		tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP);
 		tdb->flags &= ~TDB_CLEAR_IF_FIRST;
-		if (tdb_new_database(tdb, hash_size) != 0) {
+		if (tdb_new_database(tdb, &tdb->header, hash_size) != 0) {
 			TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: tdb_new_database failed!"));
 			goto fail;
 		}
@@ -323,7 +324,7 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
 				 name, strerror(errno)));
 			goto fail;
 		}
-		ret = tdb_new_database(tdb, hash_size);
+		ret = tdb_new_database(tdb, &tdb->header, hash_size);
 		if (ret == -1) {
 			TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
 				 "tdb_new_database failed for %s: %s\n",
@@ -350,7 +351,8 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
 	errno = 0;
 	if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header)
 	    || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0) {
-		if (!(open_flags & O_CREAT) || tdb_new_database(tdb, hash_size) == -1) {
+		if (!(open_flags & O_CREAT) ||
+		    tdb_new_database(tdb, &tdb->header, hash_size) == -1) {
 			if (errno == 0) {
 				errno = EIO; /* ie bad format or something */
 			}
-- 
1.7.9.5


From 61204b15caefa90d734bb9460edce70ae9c39a4f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 20 Dec 2012 16:14:23 +0100
Subject: [PATCH 2/3] tdb: Pass argument "header" to check_header_hash

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/tdb/common/open.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c
index 6079463..6630d64 100644
--- a/lib/tdb/common/open.c
+++ b/lib/tdb/common/open.c
@@ -144,11 +144,12 @@ static void null_log_fn(struct tdb_context *tdb, enum tdb_debug_level level, con
 }
 
 static bool check_header_hash(struct tdb_context *tdb,
+			      struct tdb_header *header,
 			      bool default_hash, uint32_t *m1, uint32_t *m2)
 {
 	tdb_header_hash(tdb, m1, m2);
-	if (tdb->header.magic1_hash == *m1 &&
-	    tdb->header.magic2_hash == *m2) {
+	if (header->magic1_hash == *m1 &&
+	    header->magic2_hash == *m2) {
 		return true;
 	}
 
@@ -161,7 +162,7 @@ static bool check_header_hash(struct tdb_context *tdb,
 		tdb->hash_fn = tdb_jenkins_hash;
 	else
 		tdb->hash_fn = tdb_old_hash;
-	return check_header_hash(tdb, false, m1, m2);
+	return check_header_hash(tdb, header, false, m1, m2);
 }
 
 _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int tdb_flags,
@@ -387,7 +388,8 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
 	if ((tdb->header.magic1_hash == 0) && (tdb->header.magic2_hash == 0)) {
 		/* older TDB without magic hash references */
 		tdb->hash_fn = tdb_old_hash;
-	} else if (!check_header_hash(tdb, !hash_fn, &magic1, &magic2)) {
+	} else if (!check_header_hash(tdb, &tdb->header, !hash_fn,
+				      &magic1, &magic2)) {
 		TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
 			 "%s was not created with %s hash function we are using\n"
 			 "magic1_hash[0x%08X %s 0x%08X] "
-- 
1.7.9.5


From 6299b49fe4a179d62511e3cec80ac1a02a55fd15 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 20 Dec 2012 16:36:02 +0100
Subject: [PATCH 3/3] tdb: Remove "header" from tdb_context

header.hash_size was the only thing we ever referenced outside of
tdb_open_ex and its direct callees. So this shrinks the tdb_context by
164 bytes.

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/tdb/common/check.c         |   22 +++++++++++-----------
 lib/tdb/common/dump.c          |    2 +-
 lib/tdb/common/freelist.c      |    4 ++--
 lib/tdb/common/freelistcheck.c |    2 +-
 lib/tdb/common/io.c            |    4 ++--
 lib/tdb/common/lock.c          |   12 ++++++------
 lib/tdb/common/open.c          |   37 ++++++++++++++++++++-----------------
 lib/tdb/common/rescue.c        |    6 +++---
 lib/tdb/common/summary.c       |    6 +++---
 lib/tdb/common/tdb.c           |   12 ++++++------
 lib/tdb/common/tdb_private.h   |    6 +++---
 lib/tdb/common/transaction.c   |    4 ++--
 lib/tdb/common/traverse.c      |    4 ++--
 13 files changed, 62 insertions(+), 59 deletions(-)

diff --git a/lib/tdb/common/check.c b/lib/tdb/common/check.c
index 313f55c..dc38102 100644
--- a/lib/tdb/common/check.c
+++ b/lib/tdb/common/check.c
@@ -50,11 +50,11 @@ static bool tdb_check_header(struct tdb_context *tdb, tdb_off_t *recovery)
 	if (hdr.hash_size == 0)
 		goto corrupt;
 
-	if (hdr.hash_size != tdb->header.hash_size)
+	if (hdr.hash_size != tdb->hash_size)
 		goto corrupt;
 
 	if (hdr.recovery_start != 0 &&
-	    hdr.recovery_start < TDB_DATA_START(tdb->header.hash_size))
+	    hdr.recovery_start < TDB_DATA_START(tdb->hash_size))
 		goto corrupt;
 
 	*recovery = hdr.recovery_start;
@@ -74,7 +74,7 @@ static bool tdb_check_record(struct tdb_context *tdb,
 	tdb_off_t tailer;
 
 	/* Check rec->next: 0 or points to record offset, aligned. */
-	if (rec->next > 0 && rec->next < TDB_DATA_START(tdb->header.hash_size)){
+	if (rec->next > 0 && rec->next < TDB_DATA_START(tdb->hash_size)){
 		TDB_LOG((tdb, TDB_DEBUG_ERROR,
 			 "Record offset %d too small next %d\n",
 			 off, rec->next));
@@ -352,7 +352,7 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb,
 		goto unlock;
 
 	/* We should have the whole header, too. */
-	if (tdb->map_size < TDB_DATA_START(tdb->header.hash_size)) {
+	if (tdb->map_size < TDB_DATA_START(tdb->hash_size)) {
 		tdb->ecode = TDB_ERR_CORRUPT;
 		TDB_LOG((tdb, TDB_DEBUG_ERROR, "File too short for hashes\n"));
 		goto unlock;
@@ -360,20 +360,20 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb,
 
 	/* One big malloc: pointers then bit arrays. */
 	hashes = (unsigned char **)calloc(
-			1, sizeof(hashes[0]) * (1+tdb->header.hash_size)
-			+ BITMAP_BITS / CHAR_BIT * (1+tdb->header.hash_size));
+			1, sizeof(hashes[0]) * (1+tdb->hash_size)
+			+ BITMAP_BITS / CHAR_BIT * (1+tdb->hash_size));
 	if (!hashes) {
 		tdb->ecode = TDB_ERR_OOM;
 		goto unlock;
 	}
 
 	/* Initialize pointers */
-	hashes[0] = (unsigned char *)(&hashes[1+tdb->header.hash_size]);
-	for (h = 1; h < 1+tdb->header.hash_size; h++)
+	hashes[0] = (unsigned char *)(&hashes[1+tdb->hash_size]);
+	for (h = 1; h < 1+tdb->hash_size; h++)
 		hashes[h] = hashes[h-1] + BITMAP_BITS / CHAR_BIT;
 
 	/* Freelist and hash headers are all in a row: read them. */
-	for (h = 0; h < 1+tdb->header.hash_size; h++) {
+	for (h = 0; h < 1+tdb->hash_size; h++) {
 		if (tdb_ofs_read(tdb, FREELIST_TOP + h*sizeof(tdb_off_t),
 				 &off) == -1)
 			goto free;
@@ -382,7 +382,7 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb,
 	}
 
 	/* For each record, read it in and check it's ok. */
-	for (off = TDB_DATA_START(tdb->header.hash_size);
+	for (off = TDB_DATA_START(tdb->hash_size);
 	     off < tdb->map_size;
 	     off += sizeof(rec) + rec.rec_len) {
 		if (tdb->methods->tdb_read(tdb, off, &rec, sizeof(rec),
@@ -436,7 +436,7 @@ _PUBLIC_ int tdb_check(struct tdb_context *tdb,
 
 	/* Now, hashes should all be empty: each record exists and is referred
 	 * to by one other. */
-	for (h = 0; h < 1+tdb->header.hash_size; h++) {
+	for (h = 0; h < 1+tdb->hash_size; h++) {
 		unsigned int i;
 		for (i = 0; i < BITMAP_BITS / CHAR_BIT; i++) {
 			if (hashes[h][i] != 0) {
diff --git a/lib/tdb/common/dump.c b/lib/tdb/common/dump.c
index 207bb24..f4682fa 100644
--- a/lib/tdb/common/dump.c
+++ b/lib/tdb/common/dump.c
@@ -83,7 +83,7 @@ static int tdb_dump_chain(struct tdb_context *tdb, int i)
 _PUBLIC_ void tdb_dump_all(struct tdb_context *tdb)
 {
 	int i;
-	for (i=0;i<tdb->header.hash_size;i++) {
+	for (i=0;i<tdb->hash_size;i++) {
 		tdb_dump_chain(tdb, i);
 	}
 	printf("freelist:\n");
diff --git a/lib/tdb/common/freelist.c b/lib/tdb/common/freelist.c
index 0de1fb4..2c58c69 100644
--- a/lib/tdb/common/freelist.c
+++ b/lib/tdb/common/freelist.c
@@ -139,7 +139,7 @@ left:
 #endif
 
 	/* Look left */
-	if (offset - sizeof(tdb_off_t) > TDB_DATA_START(tdb->header.hash_size)) {
+	if (offset - sizeof(tdb_off_t) > TDB_DATA_START(tdb->hash_size)) {
 		tdb_off_t left = offset - sizeof(tdb_off_t);
 		struct tdb_record l;
 		tdb_off_t leftsize;
@@ -158,7 +158,7 @@ left:
 		left = offset - leftsize;
 
 		if (leftsize > offset ||
-		    left < TDB_DATA_START(tdb->header.hash_size)) {
+		    left < TDB_DATA_START(tdb->hash_size)) {
 			goto update;
 		}
 
diff --git a/lib/tdb/common/freelistcheck.c b/lib/tdb/common/freelistcheck.c
index ab6e78f..3be7cfd 100644
--- a/lib/tdb/common/freelistcheck.c
+++ b/lib/tdb/common/freelistcheck.c
@@ -52,7 +52,7 @@ _PUBLIC_ int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries)
 
 	*pnum_entries = 0;
 
-	mem_tdb = tdb_open("flval", tdb->header.hash_size,
+	mem_tdb = tdb_open("flval", tdb->hash_size,
 				TDB_INTERNAL, O_RDWR, 0600);
 	if (!mem_tdb) {
 		return -1;
diff --git a/lib/tdb/common/io.c b/lib/tdb/common/io.c
index 2e0a206..0563635 100644
--- a/lib/tdb/common/io.c
+++ b/lib/tdb/common/io.c
@@ -204,14 +204,14 @@ static void tdb_next_hash_chain(struct tdb_context *tdb, uint32_t *chain)
 {
 	uint32_t h = *chain;
 	if (tdb->map_ptr) {
-		for (;h < tdb->header.hash_size;h++) {
+		for (;h < tdb->hash_size;h++) {
 			if (0 != *(uint32_t *)(TDB_HASH_TOP(h) + (unsigned char *)tdb->map_ptr)) {
 				break;
 			}
 		}
 	} else {
 		uint32_t off=0;
-		for (;h < tdb->header.hash_size;h++) {
+		for (;h < tdb->hash_size;h++) {
 			if (tdb_ofs_read(tdb, TDB_HASH_TOP(h), &off) != 0 || off != 0) {
 				break;
 			}
diff --git a/lib/tdb/common/lock.c b/lib/tdb/common/lock.c
index b530c6e..dadc69e 100644
--- a/lib/tdb/common/lock.c
+++ b/lib/tdb/common/lock.c
@@ -259,7 +259,7 @@ int tdb_nest_lock(struct tdb_context *tdb, uint32_t offset, int ltype,
 {
 	struct tdb_lock_type *new_lck;
 
-	if (offset >= lock_offset(tdb->header.hash_size)) {
+	if (offset >= lock_offset(tdb->hash_size)) {
 		tdb->ecode = TDB_ERR_LOCK;
 		TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_lock: invalid offset %u for ltype=%d\n",
 			 offset, ltype));
@@ -422,8 +422,8 @@ int tdb_nest_unlock(struct tdb_context *tdb, uint32_t offset, int ltype,
 		return 0;
 
 	/* Sanity checks */
-	if (offset >= lock_offset(tdb->header.hash_size)) {
-		TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: offset %u invalid (%d)\n", offset, tdb->header.hash_size));
+	if (offset >= lock_offset(tdb->hash_size)) {
+		TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_unlock: offset %u invalid (%d)\n", offset, tdb->hash_size));
 		return ret;
 	}
 
@@ -588,15 +588,15 @@ int tdb_allrecord_lock(struct tdb_context *tdb, int ltype,
 	 * It is (1) which cause the starvation problem, so we're only
 	 * gradual for that. */
 	if (tdb_chainlock_gradual(tdb, ltype, flags, FREELIST_TOP,
-				  tdb->header.hash_size * 4) == -1) {
+				  tdb->hash_size * 4) == -1) {
 		return -1;
 	}
 
 	/* Grab individual record locks. */
-	if (tdb_brlock(tdb, ltype, lock_offset(tdb->header.hash_size), 0,
+	if (tdb_brlock(tdb, ltype, lock_offset(tdb->hash_size), 0,
 		       flags) == -1) {
 		tdb_brunlock(tdb, ltype, FREELIST_TOP,
-			     tdb->header.hash_size * 4);
+			     tdb->hash_size * 4);
 		return -1;
 	}
 
diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c
index 6630d64..0caf8f8 100644
--- a/lib/tdb/common/open.c
+++ b/lib/tdb/common/open.c
@@ -170,6 +170,7 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
 				const struct tdb_logging_context *log_ctx,
 				tdb_hash_func hash_fn)
 {
+	struct tdb_header header;
 	struct tdb_context *tdb;
 	struct stat st;
 	int rev = 0, locked = 0;
@@ -288,10 +289,11 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
 	if (tdb->flags & TDB_INTERNAL) {
 		tdb->flags |= (TDB_NOLOCK | TDB_NOMMAP);
 		tdb->flags &= ~TDB_CLEAR_IF_FIRST;
-		if (tdb_new_database(tdb, &tdb->header, hash_size) != 0) {
+		if (tdb_new_database(tdb, &header, hash_size) != 0) {
 			TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: tdb_new_database failed!"));
 			goto fail;
 		}
+		tdb->hash_size = hash_size;
 		goto internal;
 	}
 
@@ -325,7 +327,7 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
 				 name, strerror(errno)));
 			goto fail;
 		}
-		ret = tdb_new_database(tdb, &tdb->header, hash_size);
+		ret = tdb_new_database(tdb, &header, hash_size);
 		if (ret == -1) {
 			TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
 				 "tdb_new_database failed for %s: %s\n",
@@ -350,23 +352,23 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
 	}
 
 	errno = 0;
-	if (read(tdb->fd, &tdb->header, sizeof(tdb->header)) != sizeof(tdb->header)
-	    || strcmp(tdb->header.magic_food, TDB_MAGIC_FOOD) != 0) {
+	if (read(tdb->fd, &header, sizeof(header)) != sizeof(header)
+	    || strcmp(header.magic_food, TDB_MAGIC_FOOD) != 0) {
 		if (!(open_flags & O_CREAT) ||
-		    tdb_new_database(tdb, &tdb->header, hash_size) == -1) {
+		    tdb_new_database(tdb, &header, hash_size) == -1) {
 			if (errno == 0) {
 				errno = EIO; /* ie bad format or something */
 			}
 			goto fail;
 		}
 		rev = (tdb->flags & TDB_CONVERT);
-	} else if (tdb->header.version != TDB_VERSION
-		   && !(rev = (tdb->header.version==TDB_BYTEREV(TDB_VERSION)))) {
+	} else if (header.version != TDB_VERSION
+		   && !(rev = (header.version==TDB_BYTEREV(TDB_VERSION)))) {
 		/* wrong version */
 		errno = EIO;
 		goto fail;
 	}
-	vp = (unsigned char *)&tdb->header.version;
+	vp = (unsigned char *)&header.version;
 	vertest = (((uint32_t)vp[0]) << 24) | (((uint32_t)vp[1]) << 16) |
 		  (((uint32_t)vp[2]) << 8) | (uint32_t)vp[3];
 	tdb->flags |= (vertest==TDB_VERSION) ? TDB_BIGENDIAN : 0;
@@ -374,32 +376,33 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
 		tdb->flags &= ~TDB_CONVERT;
 	else {
 		tdb->flags |= TDB_CONVERT;
-		tdb_convert(&tdb->header, sizeof(tdb->header));
+		tdb_convert(&header, sizeof(header));
 	}
 	if (fstat(tdb->fd, &st) == -1)
 		goto fail;
 
-	if (tdb->header.rwlocks != 0 &&
-	    tdb->header.rwlocks != TDB_HASH_RWLOCK_MAGIC) {
+	if (header.rwlocks != 0 &&
+	    header.rwlocks != TDB_HASH_RWLOCK_MAGIC) {
 		TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: spinlocks no longer supported\n"));
 		goto fail;
 	}
+	tdb->hash_size = header.hash_size;
 
-	if ((tdb->header.magic1_hash == 0) && (tdb->header.magic2_hash == 0)) {
+	if ((header.magic1_hash == 0) && (header.magic2_hash == 0)) {
 		/* older TDB without magic hash references */
 		tdb->hash_fn = tdb_old_hash;
-	} else if (!check_header_hash(tdb, &tdb->header, !hash_fn,
+	} else if (!check_header_hash(tdb, &header, !hash_fn,
 				      &magic1, &magic2)) {
 		TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
 			 "%s was not created with %s hash function we are using\n"
 			 "magic1_hash[0x%08X %s 0x%08X] "
 			 "magic2_hash[0x%08X %s 0x%08X]\n",
 			 name, hash_alg,
-			 tdb->header.magic1_hash,
-			 (tdb->header.magic1_hash == magic1) ? "==" : "!=",
+			 header.magic1_hash,
+			 (header.magic1_hash == magic1) ? "==" : "!=",
 			 magic1,
-			 tdb->header.magic2_hash,
-			 (tdb->header.magic2_hash == magic2) ? "==" : "!=",
+			 header.magic2_hash,
+			 (header.magic2_hash == magic2) ? "==" : "!=",
 			 magic2));
 		errno = EINVAL;
 		goto fail;
diff --git a/lib/tdb/common/rescue.c b/lib/tdb/common/rescue.c
index 03ae8d6..17e7ed8 100644
--- a/lib/tdb/common/rescue.c
+++ b/lib/tdb/common/rescue.c
@@ -57,7 +57,7 @@ static bool looks_like_valid_record(struct tdb_context *tdb,
 		return false;
 
 	/* Next pointer must make some sense. */
-	if (rec->next > 0 && rec->next < TDB_DATA_START(tdb->header.hash_size))
+	if (rec->next > 0 && rec->next < TDB_DATA_START(tdb->hash_size))
 		return false;
 
 	if (tdb->methods->tdb_oob(tdb, rec->next, sizeof(*rec), 1))
@@ -234,7 +234,7 @@ _PUBLIC_ int tdb_rescue(struct tdb_context *tdb,
 	tdb->log.log_fn = logging_suppressed;
 
 	/* Now walk entire db looking for records. */
-	for (off = TDB_DATA_START(tdb->header.hash_size);
+	for (off = TDB_DATA_START(tdb->hash_size);
 	     off < tdb->map_size;
 	     off += TDB_ALIGNMENT) {
 		if (tdb->methods->tdb_read(tdb, off, &rec, sizeof(rec),
@@ -249,7 +249,7 @@ _PUBLIC_ int tdb_rescue(struct tdb_context *tdb,
 	}
 
 	/* Walk hash chains to positive vet. */
-	for (h = 0; h < 1+tdb->header.hash_size; h++) {
+	for (h = 0; h < 1+tdb->hash_size; h++) {
 		bool slow_chase = false;
 		tdb_off_t slow_off = FREELIST_TOP + h*sizeof(tdb_off_t);
 
diff --git a/lib/tdb/common/summary.c b/lib/tdb/common/summary.c
index 8257261..f4e6d2c 100644
--- a/lib/tdb/common/summary.c
+++ b/lib/tdb/common/summary.c
@@ -116,7 +116,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
 	tally_init(&hash);
 	tally_init(&uncoal);
 
-	for (off = TDB_DATA_START(tdb->header.hash_size);
+	for (off = TDB_DATA_START(tdb->hash_size);
 	     off < tdb->map_size - 1;
 	     off += sizeof(rec) + rec.rec_len) {
 		if (tdb->methods->tdb_read(tdb, off, &rec, sizeof(rec),
@@ -159,7 +159,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
 	if (unc > 1)
 		tally_add(&uncoal, unc - 1);
 
-	for (off = 0; off < tdb->header.hash_size; off++)
+	for (off = 0; off < tdb->hash_size; off++)
 		tally_add(&hash, get_hash_length(tdb, off));
 
 	/* 20 is max length of a %zu. */
@@ -190,7 +190,7 @@ _PUBLIC_ char *tdb_summary(struct tdb_context *tdb)
 		 (keys.num + freet.num + dead.num)
 		 * (sizeof(struct tdb_record) + sizeof(uint32_t))
 		 * 100.0 / tdb->map_size,
-		 tdb->header.hash_size * sizeof(tdb_off_t)
+		 tdb->hash_size * sizeof(tdb_off_t)
 		 * 100.0 / tdb->map_size);
 
 unlock:
diff --git a/lib/tdb/common/tdb.c b/lib/tdb/common/tdb.c
index 7d1a40e..a2ae187 100644
--- a/lib/tdb/common/tdb.c
+++ b/lib/tdb/common/tdb.c
@@ -713,7 +713,7 @@ _PUBLIC_ int tdb_get_seqnum(struct tdb_context *tdb)
 
 _PUBLIC_ int tdb_hash_size(struct tdb_context *tdb)
 {
-	return tdb->header.hash_size;
+	return tdb->hash_size;
 }
 
 _PUBLIC_ size_t tdb_map_size(struct tdb_context *tdb)
@@ -840,7 +840,7 @@ _PUBLIC_ int tdb_wipe_all(struct tdb_context *tdb)
 	}
 
 	/* wipe the hashes */
-	for (i=0;i<tdb->header.hash_size;i++) {
+	for (i=0;i<tdb->hash_size;i++) {
 		if (tdb_ofs_write(tdb, TDB_HASH_TOP(i), &offset) == -1) {
 			TDB_LOG((tdb, TDB_DEBUG_FATAL,"tdb_wipe_all: failed to write hash %d\n", i));
 			goto failed;
@@ -857,8 +857,8 @@ _PUBLIC_ int tdb_wipe_all(struct tdb_context *tdb)
 	   for the recovery area */
 	if (recovery_size == 0) {
 		/* the simple case - the whole file can be used as a freelist */
-		data_len = (tdb->map_size - TDB_DATA_START(tdb->header.hash_size));
-		if (tdb_free_region(tdb, TDB_DATA_START(tdb->header.hash_size), data_len) != 0) {
+		data_len = (tdb->map_size - TDB_DATA_START(tdb->hash_size));
+		if (tdb_free_region(tdb, TDB_DATA_START(tdb->hash_size), data_len) != 0) {
 			goto failed;
 		}
 	} else {
@@ -870,8 +870,8 @@ _PUBLIC_ int tdb_wipe_all(struct tdb_context *tdb)
 		   move the recovery area or we risk subtle data
 		   corruption
 		*/
-		data_len = (recovery_head - TDB_DATA_START(tdb->header.hash_size));
-		if (tdb_free_region(tdb, TDB_DATA_START(tdb->header.hash_size), data_len) != 0) {
+		data_len = (recovery_head - TDB_DATA_START(tdb->hash_size));
+		if (tdb_free_region(tdb, TDB_DATA_START(tdb->hash_size), data_len) != 0) {
 			goto failed;
 		}
 		/* and the 2nd free list entry after the recovery area - if any */
diff --git a/lib/tdb/common/tdb_private.h b/lib/tdb/common/tdb_private.h
index bbe8977..406fc5f 100644
--- a/lib/tdb/common/tdb_private.h
+++ b/lib/tdb/common/tdb_private.h
@@ -61,7 +61,7 @@ typedef uint32_t tdb_off_t;
 #define TDB_DEAD(r) ((r)->magic == TDB_DEAD_MAGIC)
 #define TDB_BAD_MAGIC(r) ((r)->magic != TDB_MAGIC && !TDB_DEAD(r))
 #define TDB_HASH_TOP(hash) (FREELIST_TOP + (BUCKET(hash)+1)*sizeof(tdb_off_t))
-#define TDB_HASHTABLE_SIZE(tdb) ((tdb->header.hash_size+1)*sizeof(tdb_off_t))
+#define TDB_HASHTABLE_SIZE(tdb) ((tdb->hash_size+1)*sizeof(tdb_off_t))
 #define TDB_DATA_START(hash_size) (TDB_HASH_TOP(hash_size-1) + sizeof(tdb_off_t))
 #define TDB_RECOVERY_HEAD offsetof(struct tdb_header, recovery_start)
 #define TDB_SEQNUM_OFS    offsetof(struct tdb_header, sequence_number)
@@ -114,7 +114,7 @@ void tdb_trace_2rec_retrec(struct tdb_context *tdb, const char *op,
 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0)
 #endif
 
-#define BUCKET(hash) ((hash) % tdb->header.hash_size)
+#define BUCKET(hash) ((hash) % tdb->hash_size)
 
 #define DOCONV() (tdb->flags & TDB_CONVERT)
 #define CONVERT(x) (DOCONV() ? tdb_convert(&x, sizeof(x)) : &x)
@@ -198,7 +198,7 @@ struct tdb_context {
 	int num_lockrecs;
 	struct tdb_lock_type *lockrecs; /* only real locks, all with count>0 */
 	enum TDB_ERROR ecode; /* error code for last tdb error */
-	struct tdb_header header; /* a cached copy of the header */
+	uint32_t hash_size;
 	uint32_t flags; /* the flags passed to tdb_open */
 	struct tdb_traverse_lock travlocks; /* current traversal locks */
 	struct tdb_context *next; /* all tdbs to avoid multiple opens */
diff --git a/lib/tdb/common/transaction.c b/lib/tdb/common/transaction.c
index ee9beeb..42289fd 100644
--- a/lib/tdb/common/transaction.c
+++ b/lib/tdb/common/transaction.c
@@ -371,7 +371,7 @@ static int transaction_write_existing(struct tdb_context *tdb, tdb_off_t off,
 static void transaction_next_hash_chain(struct tdb_context *tdb, uint32_t *chain)
 {
 	uint32_t h = *chain;
-	for (;h < tdb->header.hash_size;h++) {
+	for (;h < tdb->hash_size;h++) {
 		/* the +1 takes account of the freelist */
 		if (0 != tdb->transaction->hash_heads[h+1]) {
 			break;
@@ -495,7 +495,7 @@ static int _tdb_transaction_start(struct tdb_context *tdb,
 	/* setup a copy of the hash table heads so the hash scan in
 	   traverse can be fast */
 	tdb->transaction->hash_heads = (uint32_t *)
-		calloc(tdb->header.hash_size+1, sizeof(uint32_t));
+		calloc(tdb->hash_size+1, sizeof(uint32_t));
 	if (tdb->transaction->hash_heads == NULL) {
 		tdb->ecode = TDB_ERR_OOM;
 		goto fail;
diff --git a/lib/tdb/common/traverse.c b/lib/tdb/common/traverse.c
index 46e4be7..a843359 100644
--- a/lib/tdb/common/traverse.c
+++ b/lib/tdb/common/traverse.c
@@ -37,7 +37,7 @@ static tdb_off_t tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock
 	int want_next = (tlock->off != 0);
 
 	/* Lock each chain from the start one. */
-	for (; tlock->hash < tdb->header.hash_size; tlock->hash++) {
+	for (; tlock->hash < tdb->hash_size; tlock->hash++) {
 		if (!tlock->off && tlock->hash != 0) {
 			/* this is an optimisation for the common case where
 			   the hash chain is empty, which is particularly
@@ -68,7 +68,7 @@ static tdb_off_t tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock
 			   system (testing using ldbtest).
 			*/
 			tdb->methods->next_hash_chain(tdb, &tlock->hash);
-			if (tlock->hash == tdb->header.hash_size) {
+			if (tlock->hash == tdb->hash_size) {
 				continue;
 			}
 		}
-- 
1.7.9.5



More information about the samba-technical mailing list