tdb2: unify tdb1_firstkey/tdb1_nextkey into tdb_firstkey/tdb_nextkey.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 31 Aug 2011 06:01:07 +0000 (15:31 +0930)
Switch on the TDB_VERSION1 flag.

ccan/tdb2/private.h
ccan/tdb2/tdb1.h
ccan/tdb2/traverse.c

index f92d91fdce4b7e24563d7eba64cc6210e60578b9..3af1b1d0db1bed8a6b8665ce0ded865e90c43d0c 100644 (file)
@@ -685,6 +685,10 @@ int tdb1_transaction_start(struct tdb_context *tdb);
 int tdb1_transaction_prepare_commit(struct tdb_context *tdb);
 int tdb1_transaction_commit(struct tdb_context *tdb);
 
+/* tdb1_traverse.c: */
+TDB_DATA tdb1_firstkey(struct tdb_context *tdb);
+TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key);
+
 /* tdb.c: */
 enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
                               enum TDB_ERROR ecode,
index 2855d0c1b033828acdb50b546f04ebf3f66ff898..59c2dd0d1dd591bec45bdc9968fe1feecc573351 100644 (file)
 
 void tdb1_set_max_dead(struct tdb_context *tdb, int max_dead);
 
-TDB_DATA tdb1_firstkey(struct tdb_context *tdb);
-
-TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key);
-
 int tdb1_get_seqnum(struct tdb_context *tdb);
 
 void tdb1_increment_seqnum_nonblock(struct tdb_context *tdb);
index d93c05abbd76996f66b5a376431648fd30645e3e..8d9eeb45823a0809d0117f77488e0aaeddb19481 100644 (file)
@@ -61,6 +61,16 @@ enum TDB_ERROR tdb_firstkey(struct tdb_context *tdb, struct tdb_data *key)
 {
        struct traverse_info tinfo;
 
+       if (tdb->flags & TDB_VERSION1) {
+               tdb->last_error = TDB_SUCCESS;
+               *key = tdb1_firstkey(tdb);
+               /* TDB1 didn't set error for last key. */
+               if (!key->dptr && tdb->last_error == TDB_SUCCESS) {
+                       tdb->last_error = TDB_ERR_NOEXIST;
+               }
+               return tdb->last_error;
+       }
+
        return tdb->last_error = first_in_hash(tdb, &tinfo, key, NULL);
 }
 
@@ -71,6 +81,18 @@ enum TDB_ERROR tdb_nextkey(struct tdb_context *tdb, struct tdb_data *key)
        struct hash_info h;
        struct tdb_used_record rec;
 
+       if (tdb->flags & TDB_VERSION1) {
+               struct tdb_data last_key = *key;
+               tdb->last_error = TDB_SUCCESS;
+               *key = tdb1_nextkey(tdb, last_key);
+               free(last_key.dptr);
+               /* TDB1 didn't set error for last key. */
+               if (!key->dptr && tdb->last_error == TDB_SUCCESS) {
+                       tdb->last_error = TDB_ERR_NOEXIST;
+               }
+               return tdb->last_error;
+       }
+
        tinfo.prev = find_and_lock(tdb, *key, F_RDLCK, &h, &rec, &tinfo);
        free(key->dptr);
        if (TDB_OFF_IS_ERR(tinfo.prev)) {