Browse Source

tdb2: add write flag to tdb_direct

This is a precursor to direct access during transactions: they care about
whether we are going to read or write to the file.
Rusty Russell 15 years ago
parent
commit
a56db4a5cb
3 changed files with 11 additions and 8 deletions
  1. 9 6
      ccan/tdb2/io.c
  2. 1 1
      ccan/tdb2/private.h
  3. 1 1
      ccan/tdb2/transaction.c

+ 9 - 6
ccan/tdb2/io.c

@@ -173,7 +173,7 @@ uint64_t tdb_find_zero_off(struct tdb_context *tdb, tdb_off_t off,
 int zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len)
 int zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len)
 {
 {
 	char buf[8192] = { 0 };
 	char buf[8192] = { 0 };
-	void *p = tdb->methods->direct(tdb, off, len);
+	void *p = tdb->methods->direct(tdb, off, len, true);
 
 
 	assert(!tdb->read_only);
 	assert(!tdb->read_only);
 	if (p) {
 	if (p) {
@@ -195,7 +195,8 @@ tdb_off_t tdb_read_off(struct tdb_context *tdb, tdb_off_t off)
 	tdb_off_t ret;
 	tdb_off_t ret;
 
 
 	if (likely(!(tdb->flags & TDB_CONVERT))) {
 	if (likely(!(tdb->flags & TDB_CONVERT))) {
-		tdb_off_t *p = tdb->methods->direct(tdb, off, sizeof(*p));
+		tdb_off_t *p = tdb->methods->direct(tdb, off, sizeof(*p),
+						    false);
 		if (p)
 		if (p)
 			return *p;
 			return *p;
 	}
 	}
@@ -356,7 +357,8 @@ int tdb_write_off(struct tdb_context *tdb, tdb_off_t off, tdb_off_t val)
 	}
 	}
 
 
 	if (likely(!(tdb->flags & TDB_CONVERT))) {
 	if (likely(!(tdb->flags & TDB_CONVERT))) {
-		tdb_off_t *p = tdb->methods->direct(tdb, off, sizeof(*p));
+		tdb_off_t *p = tdb->methods->direct(tdb, off, sizeof(*p),
+						    true);
 		if (p) {
 		if (p) {
 			*p = val;
 			*p = val;
 			return 0;
 			return 0;
@@ -463,7 +465,7 @@ const void *tdb_access_read(struct tdb_context *tdb,
 	const void *ret = NULL;	
 	const void *ret = NULL;	
 
 
 	if (likely(!(tdb->flags & TDB_CONVERT)))
 	if (likely(!(tdb->flags & TDB_CONVERT)))
-		ret = tdb->methods->direct(tdb, off, len);
+		ret = tdb->methods->direct(tdb, off, len, false);
 
 
 	if (!ret) {
 	if (!ret) {
 		struct tdb_access_hdr *hdr;
 		struct tdb_access_hdr *hdr;
@@ -491,7 +493,7 @@ void *tdb_access_write(struct tdb_context *tdb,
 	}
 	}
 
 
 	if (likely(!(tdb->flags & TDB_CONVERT)))
 	if (likely(!(tdb->flags & TDB_CONVERT)))
-		ret = tdb->methods->direct(tdb, off, len);
+		ret = tdb->methods->direct(tdb, off, len, true);
 
 
 	if (!ret) {
 	if (!ret) {
 		struct tdb_access_hdr *hdr;
 		struct tdb_access_hdr *hdr;
@@ -546,7 +548,8 @@ int tdb_access_commit(struct tdb_context *tdb, void *p)
 	return ret;
 	return ret;
 }
 }
 
 
-static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len)
+static void *tdb_direct(struct tdb_context *tdb, tdb_off_t off, size_t len,
+			bool write)
 {
 {
 	if (unlikely(!tdb->map_ptr))
 	if (unlikely(!tdb->map_ptr))
 		return NULL;
 		return NULL;

+ 1 - 1
ccan/tdb2/private.h

@@ -355,7 +355,7 @@ struct tdb_methods {
 	int (*write)(struct tdb_context *, tdb_off_t, const void *, tdb_len_t);
 	int (*write)(struct tdb_context *, tdb_off_t, const void *, tdb_len_t);
 	int (*oob)(struct tdb_context *, tdb_off_t, bool);
 	int (*oob)(struct tdb_context *, tdb_off_t, bool);
 	int (*expand_file)(struct tdb_context *, tdb_len_t);
 	int (*expand_file)(struct tdb_context *, tdb_len_t);
-	void *(*direct)(struct tdb_context *, tdb_off_t, size_t);
+	void *(*direct)(struct tdb_context *, tdb_off_t, size_t, bool);
 };
 };
 
 
 /*
 /*

+ 1 - 1
ccan/tdb2/transaction.c

@@ -363,7 +363,7 @@ static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t addition)
 }
 }
 
 
 static void *transaction_direct(struct tdb_context *tdb, tdb_off_t off,
 static void *transaction_direct(struct tdb_context *tdb, tdb_off_t off,
-				size_t len)
+				size_t len, bool write)
 {
 {
 	/* FIXME */
 	/* FIXME */
 	return NULL;
 	return NULL;