X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftdb.c;h=a7aa4572382b0f8b10ef03c4adc08599fd7e7293;hp=bb181732c90a541f832c5f6ea936d218ff7f1c1a;hb=98c754ffe65bc335f66161d6cc8705d4ea2710ec;hpb=b87e14495d5b07e1b247218a72329f10ecb3da7f diff --git a/ccan/tdb2/tdb.c b/ccan/tdb2/tdb.c index bb181732..a7aa4572 100644 --- a/ccan/tdb2/tdb.c +++ b/ccan/tdb2/tdb.c @@ -70,13 +70,13 @@ static enum TDB_ERROR replace_data(struct tdb_context *tdb, } new_off += sizeof(struct tdb_used_record); - ecode = tdb->methods->twrite(tdb, new_off, key.dptr, key.dsize); + ecode = tdb->tdb2.io->twrite(tdb, new_off, key.dptr, key.dsize); if (ecode != TDB_SUCCESS) { return ecode; } new_off += key.dsize; - ecode = tdb->methods->twrite(tdb, new_off, dbuf.dptr, dbuf.dsize); + ecode = tdb->tdb2.io->twrite(tdb, new_off, dbuf.dptr, dbuf.dsize); if (ecode != TDB_SUCCESS) { return ecode; } @@ -94,10 +94,10 @@ static enum TDB_ERROR update_data(struct tdb_context *tdb, { enum TDB_ERROR ecode; - ecode = tdb->methods->twrite(tdb, off, dbuf.dptr, dbuf.dsize); + ecode = tdb->tdb2.io->twrite(tdb, off, dbuf.dptr, dbuf.dsize); if (ecode == TDB_SUCCESS && extra) { /* Put a zero in; future versions may append other data. */ - ecode = tdb->methods->twrite(tdb, off + dbuf.dsize, "", 1); + ecode = tdb->tdb2.io->twrite(tdb, off + dbuf.dsize, "", 1); } if (tdb->flags & TDB_SEQNUM) tdb_inc_seqnum(tdb); @@ -114,6 +114,12 @@ enum TDB_ERROR tdb_store(struct tdb_context *tdb, struct tdb_used_record rec; enum TDB_ERROR ecode; + if (tdb->flags & TDB_VERSION1) { + if (tdb1_store(tdb, key, dbuf, flag) == -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; @@ -211,7 +217,7 @@ enum TDB_ERROR tdb_append(struct tdb_context *tdb, + dbuf.dsize)); goto out; } - ecode = tdb->methods->tread(tdb, off + sizeof(rec) + key.dsize, + ecode = tdb->tdb2.io->tread(tdb, off + sizeof(rec) + key.dsize, newdata, old_dlen); if (ecode != TDB_SUCCESS) { goto out_free_newdata; @@ -324,9 +330,17 @@ unsigned int tdb_get_flags(struct tdb_context *tdb) return tdb->flags; } +static bool inside_transaction(const struct tdb_context *tdb) +{ + if (tdb->flags & TDB_VERSION1) + return tdb->tdb1.transaction != NULL; + else + return tdb->tdb2.transaction != NULL; +} + static bool readonly_changable(struct tdb_context *tdb, const char *caller) { - if (tdb->transaction) { + if (inside_transaction(tdb)) { tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR, "%s: can't change"