Browse Source

Import 03b3682e3fa53c9f5fdf2c4beac8b5d030fd2630 from ctdb:

    tdb: rename 'struct list_struct' into 'struct tdb_record'
    
    metze
    (cherry picked from samba commit 3b62e250c066f44d0ab08a7db037b6b4f74a914b)
    
    Signed-off-by: Stefan Metzmacher <metze@samba.org>
Rusty Russell 16 years ago
parent
commit
03d4aa56b8

+ 4 - 4
ccan/tdb/check.c

@@ -64,7 +64,7 @@ corrupt:
 /* Generic record header check. */
 static bool tdb_check_record(struct tdb_context *tdb,
 			     tdb_off_t off,
-			     const struct list_struct *rec)
+			     const struct tdb_record *rec)
 {
 	tdb_off_t tailer;
 
@@ -229,7 +229,7 @@ static void record_offset(unsigned char bits[], tdb_off_t off)
 /* Check that an in-use record is valid. */
 static bool tdb_check_used_record(struct tdb_context *tdb,
 				  tdb_off_t off,
-				  const struct list_struct *rec,
+				  const struct tdb_record *rec,
 				  unsigned char **hashes,
 				  int (*check)(TDB_DATA, TDB_DATA, void *),
 				  void *private)
@@ -288,7 +288,7 @@ fail_put_key:
 /* Check that an unused record is valid. */
 static bool tdb_check_free_record(struct tdb_context *tdb,
 				  tdb_off_t off,
-				  const struct list_struct *rec,
+				  const struct tdb_record *rec,
 				  unsigned char **hashes)
 {
 	if (!tdb_check_record(tdb, off, rec))
@@ -309,7 +309,7 @@ int tdb_check(struct tdb_context *tdb,
 	unsigned int h;
 	unsigned char **hashes;
 	tdb_off_t off, recovery_start;
-	struct list_struct rec;
+	struct tdb_record rec;
 	bool found_recovery = false;
 
 	if (tdb_lockall(tdb) == -1)

+ 2 - 2
ccan/tdb/dump.c

@@ -30,7 +30,7 @@
 static tdb_off_t tdb_dump_record(struct tdb_context *tdb, int hash,
 				 tdb_off_t offset)
 {
-	struct list_struct rec;
+	struct tdb_record rec;
 	tdb_off_t tailer_ofs, tailer;
 
 	if (tdb->methods->tdb_read(tdb, offset, (char *)&rec, 
@@ -95,7 +95,7 @@ int tdb_printfreelist(struct tdb_context *tdb)
 	int ret;
 	long total_free = 0;
 	tdb_off_t offset, rec_ptr;
-	struct list_struct rec;
+	struct tdb_record rec;
 
 	if ((ret = tdb_lock(tdb, -1, F_WRLCK)) != 0)
 		return ret;

+ 9 - 9
ccan/tdb/freelist.c

@@ -34,7 +34,7 @@
 #define USE_RIGHT_MERGES 0
 
 /* read a freelist record and check for simple errors */
-int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, struct list_struct *rec)
+int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off, struct tdb_record *rec)
 {
 	if (tdb->methods->tdb_read(tdb, off, rec, sizeof(*rec),DOCONV()) == -1)
 		return -1;
@@ -87,7 +87,7 @@ static int remove_from_freelist(struct tdb_context *tdb, tdb_off_t off, tdb_off_
 
 /* update a record tailer (must hold allocation lock) */
 static int update_tailer(struct tdb_context *tdb, tdb_off_t offset,
-			 const struct list_struct *rec)
+			 const struct tdb_record *rec)
 {
 	tdb_off_t totalsize;
 
@@ -99,7 +99,7 @@ static int update_tailer(struct tdb_context *tdb, tdb_off_t offset,
 
 /* Add an element into the freelist. Merge adjacent records if
    neccessary. */
-int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec)
+int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec)
 {
 	/* Allocation and tailer lock */
 	if (tdb_lock(tdb, -1, F_WRLCK) != 0)
@@ -115,7 +115,7 @@ int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec)
 	/* Look right first (I'm an Australian, dammit) */
 	if (offset + sizeof(*rec) + rec->rec_len + sizeof(*rec) <= tdb->map_size) {
 		tdb_off_t right = offset + sizeof(*rec) + rec->rec_len;
-		struct list_struct r;
+		struct tdb_record r;
 
 		if (tdb->methods->tdb_read(tdb, right, &r, sizeof(r), DOCONV()) == -1) {
 			TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_free: right read failed at %u\n", right));
@@ -141,7 +141,7 @@ left:
 	/* Look left */
 	if (offset - sizeof(tdb_off_t) > TDB_DATA_START(tdb->header.hash_size)) {
 		tdb_off_t left = offset - sizeof(tdb_off_t);
-		struct list_struct l;
+		struct tdb_record l;
 		tdb_off_t leftsize;
 		
 		/* Read in tailer and jump back to header */
@@ -220,9 +220,9 @@ update:
  */
 static tdb_off_t tdb_allocate_ofs(struct tdb_context *tdb, 
 				  tdb_len_t length, tdb_off_t rec_ptr,
-				  struct list_struct *rec, tdb_off_t last_ptr)
+				  struct tdb_record *rec, tdb_off_t last_ptr)
 {
-#define MIN_REC_SIZE (sizeof(struct list_struct) + sizeof(tdb_off_t) + 8)
+#define MIN_REC_SIZE (sizeof(struct tdb_record) + sizeof(tdb_off_t) + 8)
 
 	if (rec->rec_len < length + MIN_REC_SIZE) {
 		/* we have to grab the whole record */
@@ -268,12 +268,12 @@ static tdb_off_t tdb_allocate_ofs(struct tdb_context *tdb,
 }
 
 /* allocate some space from the free list. The offset returned points
-   to a unconnected list_struct within the database with room for at
+   to a unconnected tdb_record within the database with room for at
    least length bytes of total data
 
    0 is returned if the space could not be allocated
  */
-tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct list_struct *rec)
+tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct tdb_record *rec)
 {
 	tdb_off_t rec_ptr, last_ptr, newrec_ptr;
 	struct {

+ 1 - 1
ccan/tdb/freelistcheck.c

@@ -46,7 +46,7 @@ static int seen_insert(struct tdb_context *mem_tdb, tdb_off_t rec_ptr)
 int tdb_validate_freelist(struct tdb_context *tdb, int *pnum_entries)
 {
 	struct tdb_context *mem_tdb = NULL;
-	struct list_struct rec;
+	struct tdb_record rec;
 	tdb_off_t rec_ptr, last_ptr;
 	int ret = -1;
 

+ 4 - 4
ccan/tdb/io.c

@@ -298,7 +298,7 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_off_t size, tdb_off_t ad
    file and doing the mmap again if necessary */
 int tdb_expand(struct tdb_context *tdb, tdb_off_t size)
 {
-	struct list_struct rec;
+	struct tdb_record rec;
 	tdb_off_t offset, new_size;	
 
 	if (tdb_lock(tdb, -1, F_WRLCK) == -1) {
@@ -435,7 +435,7 @@ int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key,
 }
 
 /* read/write a record */
-int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec)
+int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec)
 {
 	if (tdb->methods->tdb_read(tdb, offset, rec, sizeof(*rec),DOCONV()) == -1)
 		return -1;
@@ -448,9 +448,9 @@ int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *
 	return tdb->methods->tdb_oob(tdb, rec->next+sizeof(*rec), 0);
 }
 
-int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec)
+int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec)
 {
-	struct list_struct r = *rec;
+	struct tdb_record r = *rec;
 	return tdb->methods->tdb_write(tdb, offset, CONVERT(r), sizeof(r));
 }
 

+ 15 - 15
ccan/tdb/tdb.c

@@ -77,7 +77,7 @@ static int tdb_key_compare(TDB_DATA key, TDB_DATA data, void *private_data)
 /* Returns 0 on fail.  On success, return offset of record, and fills
    in rec */
 static tdb_off_t tdb_find(struct tdb_context *tdb, TDB_DATA key, uint32_t hash,
-			struct list_struct *r)
+			struct tdb_record *r)
 {
 	tdb_off_t rec_ptr;
 	
@@ -111,7 +111,7 @@ static tdb_off_t tdb_find(struct tdb_context *tdb, TDB_DATA key, uint32_t hash,
 
 /* As tdb_find, but if you succeed, keep the lock */
 tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, int locktype,
-			   struct list_struct *rec)
+			   struct tdb_record *rec)
 {
 	uint32_t rec_ptr;
 
@@ -129,7 +129,7 @@ tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t has
 */
 static int tdb_update_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, TDB_DATA dbuf)
 {
-	struct list_struct rec;
+	struct tdb_record rec;
 	tdb_off_t rec_ptr;
 
 	/* find entry */
@@ -164,7 +164,7 @@ static int tdb_update_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash,
 static TDB_DATA _tdb_fetch(struct tdb_context *tdb, TDB_DATA key)
 {
 	tdb_off_t rec_ptr;
-	struct list_struct rec;
+	struct tdb_record rec;
 	TDB_DATA ret;
 	uint32_t hash;
 
@@ -210,7 +210,7 @@ int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key,
 		     void *private_data)
 {
 	tdb_off_t rec_ptr;
-	struct list_struct rec;
+	struct tdb_record rec;
 	int ret;
 	uint32_t hash;
 
@@ -241,7 +241,7 @@ int tdb_parse_record(struct tdb_context *tdb, TDB_DATA key,
 */
 static int tdb_exists_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash)
 {
-	struct list_struct rec;
+	struct tdb_record rec;
 	
 	if (tdb_find_lock_hash(tdb, key, hash, F_RDLCK, &rec) == 0)
 		return 0;
@@ -260,10 +260,10 @@ int tdb_exists(struct tdb_context *tdb, TDB_DATA key)
 }
 
 /* actually delete an entry in the database given the offset */
-int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct list_struct *rec)
+int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct tdb_record *rec)
 {
 	tdb_off_t last_ptr, i;
-	struct list_struct lastrec;
+	struct tdb_record lastrec;
 
 	if (tdb->read_only || tdb->traverse_read) return -1;
 
@@ -299,7 +299,7 @@ static int tdb_count_dead(struct tdb_context *tdb, uint32_t hash)
 {
 	int res = 0;
 	tdb_off_t rec_ptr;
-	struct list_struct rec;
+	struct tdb_record rec;
 	
 	/* read in the hash top */
 	if (tdb_ofs_read(tdb, TDB_HASH_TOP(hash), &rec_ptr) == -1)
@@ -323,7 +323,7 @@ static int tdb_count_dead(struct tdb_context *tdb, uint32_t hash)
 static int tdb_purge_dead(struct tdb_context *tdb, uint32_t hash)
 {
 	int res = -1;
-	struct list_struct rec;
+	struct tdb_record rec;
 	tdb_off_t rec_ptr;
 
 	if (tdb_lock(tdb, -1, F_WRLCK) == -1) {
@@ -359,7 +359,7 @@ static int tdb_purge_dead(struct tdb_context *tdb, uint32_t hash)
 static int tdb_delete_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash)
 {
 	tdb_off_t rec_ptr;
-	struct list_struct rec;
+	struct tdb_record rec;
 	int ret;
 
 	if (tdb->max_dead_records != 0) {
@@ -422,7 +422,7 @@ int tdb_delete(struct tdb_context *tdb, TDB_DATA key)
  * See if we have a dead record around with enough space
  */
 static tdb_off_t tdb_find_dead(struct tdb_context *tdb, uint32_t hash,
-			       struct list_struct *r, tdb_len_t length)
+			       struct tdb_record *r, tdb_len_t length)
 {
 	tdb_off_t rec_ptr;
 	
@@ -450,7 +450,7 @@ static tdb_off_t tdb_find_dead(struct tdb_context *tdb, uint32_t hash,
 static int _tdb_store(struct tdb_context *tdb, TDB_DATA key,
 		      TDB_DATA dbuf, int flag, uint32_t hash)
 {
-	struct list_struct rec;
+	struct tdb_record rec;
 	tdb_off_t rec_ptr;
 	char *p = NULL;
 	int ret = -1;
@@ -739,7 +739,7 @@ void tdb_enable_seqnum(struct tdb_context *tdb)
  */
 static int tdb_free_region(struct tdb_context *tdb, tdb_off_t offset, ssize_t length)
 {
-	struct list_struct rec;
+	struct tdb_record rec;
 	if (length <= sizeof(rec)) {
 		/* the region is not worth adding */
 		return 0;
@@ -788,7 +788,7 @@ int tdb_wipe_all(struct tdb_context *tdb)
 	}
 
 	if (recovery_head != 0) {
-		struct list_struct rec;
+		struct tdb_record rec;
 		if (tdb->methods->tdb_read(tdb, recovery_head, &rec, sizeof(rec), DOCONV()) == -1) {
 			TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_wipe_all: failed to read recovery record\n"));
 			return -1;

+ 9 - 9
ccan/tdb/tdb_private.h

@@ -136,9 +136,9 @@ void tdb_trace_2rec_retrec(struct tdb_context *tdb, const char *op,
 #define CONVERT(x) (DOCONV() ? tdb_convert(&x, sizeof(x)) : &x)
 
 
-/* the body of the database is made of one list_struct for the free space
+/* the body of the database is made of one tdb_record for the free space
    plus a separate data list for each hash value */
-struct list_struct {
+struct tdb_record {
 	tdb_off_t next; /* offset of the next record in the list */
 	tdb_len_t rec_len; /* total byte length of record */
 	tdb_len_t key_len; /* byte length of key */
@@ -257,16 +257,16 @@ int tdb_write_unlock_record(struct tdb_context *tdb, tdb_off_t off);
 int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
 int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
 void *tdb_convert(void *buf, uint32_t size);
-int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec);
-tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct list_struct *rec);
+int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec);
+tdb_off_t tdb_allocate(struct tdb_context *tdb, tdb_len_t length, struct tdb_record *rec);
 int tdb_ofs_read(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
 int tdb_ofs_write(struct tdb_context *tdb, tdb_off_t offset, tdb_off_t *d);
 int tdb_lock_record(struct tdb_context *tdb, tdb_off_t off);
 int tdb_unlock_record(struct tdb_context *tdb, tdb_off_t off);
 int _tdb_transaction_cancel(struct tdb_context *tdb, int ltype);
-int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec);
-int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct list_struct *rec);
-int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct list_struct *rec);
+int tdb_rec_read(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec);
+int tdb_rec_write(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec);
+int tdb_do_delete(struct tdb_context *tdb, tdb_off_t rec_ptr, struct tdb_record *rec);
 unsigned char *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t len);
 int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key,
 		   tdb_off_t offset, tdb_len_t len,
@@ -274,11 +274,11 @@ int tdb_parse_data(struct tdb_context *tdb, TDB_DATA key,
 				 void *private_data),
 		   void *private_data);
 tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, int locktype,
-			   struct list_struct *rec);
+			   struct tdb_record *rec);
 void tdb_io_init(struct tdb_context *tdb);
 int tdb_expand(struct tdb_context *tdb, tdb_off_t size);
 int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off,
-		      struct list_struct *rec);
+		      struct tdb_record *rec);
 
 
 #endif

+ 1 - 1
ccan/tdb/test/run-3G-file.c

@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
 	TDB_DATA key, orig_data, data;
 	uint32_t hash;
 	tdb_off_t rec_ptr;
-	struct list_struct rec;
+	struct tdb_record rec;
 
 	plan_tests(24);
 	tdb = tdb_open("/tmp/test.tdb", 1024, TDB_CLEAR_IF_FIRST,

+ 2 - 2
ccan/tdb/test/run-corrupt.c

@@ -76,9 +76,9 @@ static void check_test(struct tdb_context *tdb)
 	/* From the free list chain and hash chains. */
 	verifiable += 3 * sizeof(tdb_off_t);
 	/* From the record headers & tailer */
-	verifiable += 5 * (sizeof(struct list_struct) + sizeof(uint32_t));
+	verifiable += 5 * (sizeof(struct tdb_record) + sizeof(uint32_t));
 	/* The free block: we ignore datalen, keylen, full_hash. */
-	verifiable += sizeof(struct list_struct) - 3*sizeof(uint32_t) +
+	verifiable += sizeof(struct tdb_record) - 3*sizeof(uint32_t) +
 		sizeof(uint32_t);
 	/* Our check function verifies the key and data. */
 	verifiable += ksize + dsize;

+ 6 - 6
ccan/tdb/transaction.c

@@ -680,7 +680,7 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
 				 tdb_off_t *recovery_offset,
 				 tdb_len_t *recovery_max_size)
 {
-	struct list_struct rec;
+	struct tdb_record rec;
 	const struct tdb_methods *methods = tdb->transaction->io_methods;
 	tdb_off_t recovery_head;
 
@@ -766,7 +766,7 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
 	tdb_len_t recovery_size;
 	unsigned char *data, *p;
 	const struct tdb_methods *methods = tdb->transaction->io_methods;
-	struct list_struct *rec;
+	struct tdb_record *rec;
 	tdb_off_t recovery_offset, recovery_max_size;
 	tdb_off_t old_map_size = tdb->transaction->old_map_size;
 	uint32_t magic, tailer;
@@ -786,7 +786,7 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
 		return -1;
 	}
 
-	rec = (struct list_struct *)data;
+	rec = (struct tdb_record *)data;
 	memset(rec, 0, sizeof(*rec));
 
 	rec->magic    = 0;
@@ -869,7 +869,7 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
 	magic = TDB_RECOVERY_MAGIC;
 	CONVERT(magic);
 
-	*magic_offset = recovery_offset + offsetof(struct list_struct, magic);
+	*magic_offset = recovery_offset + offsetof(struct tdb_record, magic);
 
 	if (methods->tdb_write(tdb, *magic_offset, &magic, sizeof(magic)) == -1) {
 		TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_setup_recovery: failed to write recovery magic\n"));
@@ -1118,7 +1118,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
 	tdb_off_t recovery_head, recovery_eof;
 	unsigned char *data, *p;
 	uint32_t zero = 0;
-	struct list_struct rec;
+	struct tdb_record rec;
 
 	/* find the recovery area */
 	if (tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &recovery_head) == -1) {
@@ -1205,7 +1205,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
 	}
 
 	/* remove the recovery magic */
-	if (tdb_ofs_write(tdb, recovery_head + offsetof(struct list_struct, magic), 
+	if (tdb_ofs_write(tdb, recovery_head + offsetof(struct tdb_record, magic),
 			  &zero) == -1) {
 		TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_transaction_recover: failed to remove recovery magic\n"));
 		tdb->ecode = TDB_ERR_IO;

+ 4 - 4
ccan/tdb/traverse.c

@@ -32,7 +32,7 @@
 /* Uses traverse lock: 0 = finish, TDB_NEXT_LOCK_ERR = error,
    other = record offset */
 static tdb_off_t tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock *tlock,
-			 struct list_struct *rec)
+			 struct tdb_record *rec)
 {
 	int want_next = (tlock->off != 0);
 
@@ -145,7 +145,7 @@ static int _tdb_traverse(struct tdb_context *tdb,
 			 struct tdb_traverse_lock *tl)
 {
 	TDB_DATA key, dbuf;
-	struct list_struct rec;
+	struct tdb_record rec;
 	int ret = 0, count = 0;
 	tdb_off_t off;
 
@@ -270,7 +270,7 @@ int tdb_traverse(struct tdb_context *tdb,
 TDB_DATA tdb_firstkey(struct tdb_context *tdb)
 {
 	TDB_DATA key;
-	struct list_struct rec;
+	struct tdb_record rec;
 	tdb_off_t off;
 
 	/* release any old lock */
@@ -302,7 +302,7 @@ TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA oldkey)
 {
 	uint32_t oldhash;
 	TDB_DATA key = tdb_null;
-	struct list_struct rec;
+	struct tdb_record rec;
 	unsigned char *k = NULL;
 	tdb_off_t off;