Browse Source

tdb2: rename ->read and ->write functions.

Since failtest uses macros to override read and write, we need to avoid
those names, even inside our ops structure.
Rusty Russell 15 years ago
parent
commit
04cf551d15
6 changed files with 44 additions and 43 deletions
  1. 1 1
      ccan/tdb2/check.c
  2. 7 7
      ccan/tdb2/io.c
  3. 2 2
      ccan/tdb2/private.h
  4. 9 9
      ccan/tdb2/tdb.c
  5. 4 4
      ccan/tdb2/test/run-04-basichash.c
  6. 21 20
      ccan/tdb2/transaction.c

+ 1 - 1
ccan/tdb2/check.c

@@ -512,7 +512,7 @@ size_t dead_space(struct tdb_context *tdb, tdb_off_t off)
 
 	for (len = 0; off + len < tdb->map_size; len++) {
 		char c;
-		if (tdb->methods->read(tdb, off, &c, 1))
+		if (tdb->methods->tread(tdb, off, &c, 1))
 			return 0;
 		if (c != 0 && c != 0x43)
 			break;

+ 7 - 7
ccan/tdb2/io.c

@@ -182,7 +182,7 @@ int zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len)
 	}
 	while (len) {
 		unsigned todo = len < sizeof(buf) ? len : sizeof(buf);
-		if (tdb->methods->write(tdb, off, buf, todo) == -1)
+		if (tdb->methods->twrite(tdb, off, buf, todo) == -1)
 			return -1;
 		len -= todo;
 		off += todo;
@@ -282,11 +282,11 @@ int tdb_write_convert(struct tdb_context *tdb, tdb_off_t off,
 			return -1;
 		}
 		memcpy(conv, rec, len);
-		ret = tdb->methods->write(tdb, off,
-					  tdb_convert(tdb, conv, len), len);
+		ret = tdb->methods->twrite(tdb, off,
+					   tdb_convert(tdb, conv, len), len);
 		free(conv);
 	} else
-		ret = tdb->methods->write(tdb, off, rec, len);
+		ret = tdb->methods->twrite(tdb, off, rec, len);
 
 	return ret;
 }
@@ -294,7 +294,7 @@ int tdb_write_convert(struct tdb_context *tdb, tdb_off_t off,
 int tdb_read_convert(struct tdb_context *tdb, tdb_off_t off,
 		      void *rec, size_t len)
 {
-	int ret = tdb->methods->read(tdb, off, rec, len);
+	int ret = tdb->methods->tread(tdb, off, rec, len);
 	tdb_convert(tdb, rec, len);
 	return ret;
 }
@@ -329,8 +329,8 @@ static void *_tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset,
 		tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_ERROR,
 			   "tdb_alloc_read malloc failed len=%zu",
 			   (size_t)(prefix + len));
-	} else if (unlikely(tdb->methods->read(tdb, offset, buf+prefix,
-					       len) == -1)) {
+	} else if (unlikely(tdb->methods->tread(tdb, offset, buf+prefix, len)
+			    == -1)) {
 		free(buf);
 		buf = NULL;
 	}

+ 2 - 2
ccan/tdb2/private.h

@@ -366,8 +366,8 @@ struct tdb_context {
 };
 
 struct tdb_methods {
-	int (*read)(struct tdb_context *, tdb_off_t, void *, tdb_len_t);
-	int (*write)(struct tdb_context *, tdb_off_t, const void *, tdb_len_t);
+	int (*tread)(struct tdb_context *, tdb_off_t, void *, tdb_len_t);
+	int (*twrite)(struct tdb_context *, tdb_off_t, const void *, tdb_len_t);
 	int (*oob)(struct tdb_context *, tdb_off_t, bool);
 	int (*expand_file)(struct tdb_context *, tdb_len_t);
 	void *(*direct)(struct tdb_context *, tdb_off_t, size_t, bool);

+ 9 - 9
ccan/tdb2/tdb.c

@@ -453,11 +453,11 @@ static int replace_data(struct tdb_context *tdb,
 	}
 
 	new_off += sizeof(struct tdb_used_record);
-	if (tdb->methods->write(tdb, new_off, key.dptr, key.dsize) == -1)
+	if (tdb->methods->twrite(tdb, new_off, key.dptr, key.dsize) == -1)
 		return -1;
 
 	new_off += key.dsize;
-	if (tdb->methods->write(tdb, new_off, dbuf.dptr, dbuf.dsize) == -1)
+	if (tdb->methods->twrite(tdb, new_off, dbuf.dptr, dbuf.dsize) == -1)
 		return -1;
 
 	/* FIXME: tdb_increment_seqnum(tdb); */
@@ -493,9 +493,9 @@ int tdb_store(struct tdb_context *tdb,
 						   key.dsize, dbuf.dsize,
 						   &rec, h.h))
 					goto fail;
-				if (tdb->methods->write(tdb, off + sizeof(rec)
-							+ key.dsize,
-							dbuf.dptr, dbuf.dsize))
+				if (tdb->methods->twrite(tdb, off + sizeof(rec)
+							 + key.dsize,
+							 dbuf.dptr, dbuf.dsize))
 					goto fail;
 				tdb_unlock_hashes(tdb, h.hlock_start,
 						  h.hlock_range, F_WRLCK);
@@ -548,8 +548,8 @@ int tdb_append(struct tdb_context *tdb,
 				goto fail;
 
 			off += sizeof(rec) + key.dsize + old_dlen;
-			if (tdb->methods->write(tdb, off, dbuf.dptr,
-						dbuf.dsize) == -1)
+			if (tdb->methods->twrite(tdb, off, dbuf.dptr,
+						 dbuf.dsize) == -1)
 				goto fail;
 
 			/* FIXME: tdb_increment_seqnum(tdb); */
@@ -566,8 +566,8 @@ int tdb_append(struct tdb_context *tdb,
 				   (size_t)(key.dsize+old_dlen+dbuf.dsize));
 			goto fail;
 		}
-		if (tdb->methods->read(tdb, off + sizeof(rec) + key.dsize,
-				       newdata, old_dlen) != 0) {
+		if (tdb->methods->tread(tdb, off + sizeof(rec) + key.dsize,
+					newdata, old_dlen) != 0) {
 			free(newdata);
 			goto fail;
 		}

+ 4 - 4
ccan/tdb2/test/run-04-basichash.c

@@ -74,9 +74,9 @@ int main(int argc, char *argv[])
 
 		/* Make sure we fill it in for later finding. */
 		off = new_off + sizeof(struct tdb_used_record);
-		ok1(!tdb->methods->write(tdb, off, key.dptr, key.dsize));
+		ok1(!tdb->methods->twrite(tdb, off, key.dptr, key.dsize));
 		off += key.dsize;
-		ok1(!tdb->methods->write(tdb, off, dbuf.dptr, dbuf.dsize));
+		ok1(!tdb->methods->twrite(tdb, off, dbuf.dptr, dbuf.dsize));
 
 		/* We should be able to unlock that OK. */
 		ok1(tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range,
@@ -233,9 +233,9 @@ int main(int argc, char *argv[])
 
 		/* Make sure we fill it in for later finding. */
 		off = new_off + sizeof(struct tdb_used_record);
-		ok1(!tdb->methods->write(tdb, off, key.dptr, key.dsize));
+		ok1(!tdb->methods->twrite(tdb, off, key.dptr, key.dsize));
 		off += key.dsize;
-		ok1(!tdb->methods->write(tdb, off, dbuf.dptr, dbuf.dsize));
+		ok1(!tdb->methods->twrite(tdb, off, dbuf.dptr, dbuf.dsize));
 
 		/* We should be able to unlock that OK. */
 		ok1(tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range,

+ 21 - 20
ccan/tdb2/transaction.c

@@ -151,7 +151,8 @@ static int transaction_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
 	if (tdb->transaction->num_blocks <= blk ||
 	    tdb->transaction->blocks[blk] == NULL) {
 		/* nope, do a real read */
-		if (tdb->transaction->io_methods->read(tdb, off, buf, len) != 0) {
+		if (tdb->transaction->io_methods->tread(tdb, off, buf, len)
+		    != 0) {
 			goto fail;
 		}
 		return 0;
@@ -249,9 +250,9 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
 			if (len2 + (blk * getpagesize()) > tdb->transaction->old_map_size) {
 				len2 = tdb->transaction->old_map_size - (blk * getpagesize());
 			}
-			if (tdb->transaction->io_methods->read(tdb, blk * getpagesize(),
-							       tdb->transaction->blocks[blk],
-							       len2) != 0) {
+			if (tdb->transaction->io_methods->tread(tdb, blk * getpagesize(),
+								tdb->transaction->blocks[blk],
+								len2) != 0) {
 				tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
 					   "transaction_write: failed to"
 					   " read old block: %s",
@@ -468,8 +469,8 @@ static void _tdb_transaction_cancel(struct tdb_context *tdb)
 		uint64_t invalid = TDB_RECOVERY_INVALID_MAGIC;
 
 		/* remove the recovery marker */
-		if (methods->write(tdb, tdb->transaction->magic_offset,
-				   &invalid, sizeof(invalid)) == -1 ||
+		if (methods->twrite(tdb, tdb->transaction->magic_offset,
+				    &invalid, sizeof(invalid)) == -1 ||
 		    transaction_sync(tdb, tdb->transaction->magic_offset,
 				     sizeof(invalid)) == -1) {
 			tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
@@ -624,7 +625,7 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
 	}
 
 	if (recovery_head != 0) {
-		if (methods->read(tdb, recovery_head, &rec, sizeof(rec))) {
+		if (methods->tread(tdb, recovery_head, &rec, sizeof(rec))) {
 			tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
 				 "tdb_recovery_allocate:"
 				 " failed to read recovery record");
@@ -696,8 +697,8 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
 	/* write the recovery header offset and sync - we can sync without a race here
 	   as the magic ptr in the recovery record has not been set */
 	tdb_convert(tdb, &recovery_head, sizeof(recovery_head));
-	if (methods->write(tdb, offsetof(struct tdb_header, recovery),
-			   &recovery_head, sizeof(tdb_off_t)) == -1) {
+	if (methods->twrite(tdb, offsetof(struct tdb_header, recovery),
+			    &recovery_head, sizeof(tdb_off_t)) == -1) {
 		tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
 			 "tdb_recovery_allocate:"
 			 " failed to write recovery head");
@@ -790,9 +791,9 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
 		/* the recovery area contains the old data, not the
 		   new data, so we have to call the original tdb_read
 		   method to get it */
-		if (methods->read(tdb, offset,
-				  p + sizeof(offset) + sizeof(length),
-				  length) != 0) {
+		if (methods->tread(tdb, offset,
+				   p + sizeof(offset) + sizeof(length),
+				   length) != 0) {
 			free(data);
 			return -1;
 		}
@@ -805,8 +806,8 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
 	tdb_convert(tdb, p, sizeof(tailer));
 
 	/* write the recovery data to the recovery area */
-	if (methods->write(tdb, recovery_offset, data,
-			   sizeof(*rec) + recovery_size) == -1) {
+	if (methods->twrite(tdb, recovery_offset, data,
+			    sizeof(*rec) + recovery_size) == -1) {
 		tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
 			 "tdb_transaction_setup_recovery:"
 			 " failed to write recovery data");
@@ -833,7 +834,7 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
 	*magic_offset = recovery_offset + offsetof(struct tdb_recovery_record,
 						   magic);
 
-	if (methods->write(tdb, *magic_offset, &magic, sizeof(magic)) == -1) {
+	if (methods->twrite(tdb, *magic_offset, &magic, sizeof(magic)) == -1) {
 		tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
 			 "tdb_transaction_setup_recovery:"
 			 " failed to write recovery magic");
@@ -1007,8 +1008,8 @@ int tdb_transaction_commit(struct tdb_context *tdb)
 			length = tdb->transaction->last_block_size;
 		}
 
-		if (methods->write(tdb, offset, tdb->transaction->blocks[i],
-				   length) == -1) {
+		if (methods->twrite(tdb, offset, tdb->transaction->blocks[i],
+				    length) == -1) {
 			tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
 				   "tdb_transaction_commit:"
 				   " write failed during commit");
@@ -1113,8 +1114,8 @@ int tdb_transaction_recover(struct tdb_context *tdb)
 	}
 
 	/* read the full recovery data */
-	if (tdb->methods->read(tdb, recovery_head + sizeof(rec), data,
-			       rec.len) == -1) {
+	if (tdb->methods->tread(tdb, recovery_head + sizeof(rec), data,
+				rec.len) == -1) {
 		tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
 			   "tdb_transaction_recover:"
 			   " failed to read recovery data");
@@ -1131,7 +1132,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
 		memcpy(&len, p + sizeof(ofs), sizeof(len));
 		p += sizeof(ofs) + sizeof(len);
 
-		if (tdb->methods->write(tdb, ofs, p, len) == -1) {
+		if (tdb->methods->twrite(tdb, ofs, p, len) == -1) {
 			free(data);
 			tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
 				 "tdb_transaction_recover:"