Commit acb26c9c authored by Rusty Russell's avatar Rusty Russell

tdb2: unify tdb1_delete into tdb_delete.

Switch on the TDB_VERSION1 flag.
parent 8bc38cb1
......@@ -651,6 +651,7 @@ int tdb1_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
enum TDB_ERROR tdb1_fetch(struct tdb_context *tdb, TDB_DATA key,
TDB_DATA *data);
int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
int tdb1_delete(struct tdb_context *tdb, TDB_DATA key);
/* tdb.c: */
enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
......
......@@ -302,6 +302,12 @@ enum TDB_ERROR tdb_delete(struct tdb_context *tdb, struct tdb_data key)
struct hash_info h;
enum TDB_ERROR ecode;
if (tdb->flags & TDB_VERSION1) {
if (tdb1_delete(tdb, key) == -1)
return tdb->last_error;
return TDB_SUCCESS;
}
off = find_and_lock(tdb, key, F_WRLCK, &h, &rec, NULL);
if (TDB_OFF_IS_ERR(off)) {
return tdb->last_error = off;
......
......@@ -45,8 +45,6 @@ int tdb1_parse_record(struct tdb_context *tdb, TDB_DATA key,
void *private_data),
void *private_data);
int tdb1_delete(struct tdb_context *tdb, TDB_DATA key);
TDB_DATA tdb1_firstkey(struct tdb_context *tdb);
TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key);
......
......@@ -434,6 +434,7 @@ int tdb1_delete(struct tdb_context *tdb, TDB_DATA key)
uint32_t hash = tdb_hash(tdb, key.dptr, key.dsize);
int ret;
assert(tdb->flags & TDB_VERSION1);
ret = tdb1_delete_hash(tdb, key, hash);
return ret;
}
......
......@@ -104,7 +104,7 @@ int main(int argc, char *argv[])
ok1(tdb1_traverse(tdb, test_traverse, &orig_data) == 1);
/* Delete should work. */
ok1(tdb1_delete(tdb, key) == 0);
ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
ok1(tdb1_traverse(tdb, test_traverse, NULL) == 0);
......
......@@ -153,7 +153,7 @@ int main(int argc, char *argv[])
O_RDWR, 0600, &jhash_attr);
ok1(tdb);
ok1(log_count == 0);
ok1(tdb1_fetch(tdb, d, &d) == TDB_SUCCESS);
ok1(tdb_fetch(tdb, d, &d) == TDB_SUCCESS);
ok1(d.dsize == 5);
free(d.dptr);
ok1(tdb1_check(tdb, NULL, NULL) == 0);
......@@ -202,7 +202,7 @@ int main(int argc, char *argv[])
&dumbhash_attr);
ok1(tdb);
ok1(log_count == 0);
ok1(tdb1_fetch(tdb, d, &d) == TDB_SUCCESS);
ok1(tdb_fetch(tdb, d, &d) == TDB_SUCCESS);
ok1(d.dsize == 5);
free(d.dptr);
ok1(tdb1_check(tdb, NULL, NULL) == 0);
......
......@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
ok1(tdb1_transaction_start(tdb) == 0);
ok1(tdb1_transaction_start(tdb) == 0);
ok1(tdb1_delete(tdb, key) == 0);
ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
ok1(tdb1_transaction_commit(tdb) == 0);
ok1(!tdb1_exists(tdb, key));
ok1(tdb1_transaction_cancel(tdb) == 0);
......@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
ok1(tdb1_transaction_start(tdb) == 0);
ok1(tdb1_transaction_start(tdb) == 0);
ok1(tdb1_delete(tdb, key) == 0);
ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
ok1(tdb1_transaction_commit(tdb) == 0);
ok1(!tdb1_exists(tdb, key));
ok1(tdb1_transaction_commit(tdb) == 0);
......
......@@ -40,7 +40,7 @@ static void delete_entries(struct tdb_context *tdb)
key.dsize = sizeof(i);
key.dptr = (void *)&i;
ok1(tdb1_delete(tdb, key) == 0);
ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
}
}
......@@ -52,7 +52,7 @@ static int delete_other(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
memcpy(&i, key.dptr, 4);
i = (i + 1) % NUM_ENTRIES;
key.dptr = (void *)&i;
if (tdb1_delete(tdb, key) != 0)
if (tdb_delete(tdb, key) != TDB_SUCCESS)
(*(int *)private_data)++;
return 0;
}
......@@ -60,7 +60,7 @@ static int delete_other(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
static int delete_self(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
void *private_data)
{
ok1(tdb1_delete(tdb, key) == 0);
ok1(tdb_delete(tdb, key) == TDB_SUCCESS);
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment