X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Ftdb.c;h=c6bd8072ea9c4b18d55ee7b1ca5c4e64e550805d;hb=57359c26e9626aa986ee0538efd13a44a466f39d;hp=a7aa4572382b0f8b10ef03c4adc08599fd7e7293;hpb=98c754ffe65bc335f66161d6cc8705d4ea2710ec;p=ccan diff --git a/ccan/tdb2/tdb.c b/ccan/tdb2/tdb.c index a7aa4572..c6bd8072 100644 --- a/ccan/tdb2/tdb.c +++ b/ccan/tdb2/tdb.c @@ -183,6 +183,12 @@ enum TDB_ERROR tdb_append(struct tdb_context *tdb, struct tdb_data new_dbuf; enum TDB_ERROR ecode; + if (tdb->flags & TDB_VERSION1) { + if (tdb1_append(tdb, key, dbuf) == -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; @@ -248,6 +254,9 @@ enum TDB_ERROR tdb_fetch(struct tdb_context *tdb, struct tdb_data key, struct hash_info h; enum TDB_ERROR ecode; + if (tdb->flags & TDB_VERSION1) + return tdb1_fetch(tdb, key, data); + off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL); if (TDB_OFF_IS_ERR(off)) { return tdb->last_error = off; @@ -275,6 +284,10 @@ bool tdb_exists(struct tdb_context *tdb, TDB_DATA key) struct tdb_used_record rec; struct hash_info h; + if (tdb->flags & TDB_VERSION1) { + return tdb1_exists(tdb, key); + } + off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL); if (TDB_OFF_IS_ERR(off)) { tdb->last_error = off; @@ -293,6 +306,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; @@ -507,6 +526,11 @@ enum TDB_ERROR tdb_parse_record_(struct tdb_context *tdb, struct hash_info h; enum TDB_ERROR ecode; + if (tdb->flags & TDB_VERSION1) { + return tdb->last_error = tdb1_parse_record(tdb, key, parse, + data); + } + off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL); if (TDB_OFF_IS_ERR(off)) { return tdb->last_error = off; @@ -539,7 +563,20 @@ const char *tdb_name(const struct tdb_context *tdb) int64_t tdb_get_seqnum(struct tdb_context *tdb) { - tdb_off_t off = tdb_read_off(tdb, offsetof(struct tdb_header, seqnum)); + tdb_off_t off; + + if (tdb->flags & TDB_VERSION1) { + tdb1_off_t val; + tdb->last_error = TDB_SUCCESS; + val = tdb1_get_seqnum(tdb); + + if (tdb->last_error != TDB_SUCCESS) + return tdb->last_error; + else + return val; + } + + off = tdb_read_off(tdb, offsetof(struct tdb_header, seqnum)); if (TDB_OFF_IS_ERR(off)) tdb->last_error = off; else