X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;ds=sidebyside;f=ccan%2Ftdb%2Ftransaction.c;h=6909c261a2808ca50c33cb413a5597cde8d4cbd5;hb=bcf7916c5d694858766869dfd570e525127154a6;hp=1086c5f037793d9df00269ff78b14ae2ad126e72;hpb=c5316eef05ab024c44224a165282e8df8ad30285;p=ccan diff --git a/ccan/tdb/transaction.c b/ccan/tdb/transaction.c index 1086c5f0..6909c261 100644 --- a/ccan/tdb/transaction.c +++ b/ccan/tdb/transaction.c @@ -127,6 +127,9 @@ struct tdb_transaction { /* old file size before transaction */ tdb_len_t old_map_size; + + /* we should re-pack on commit */ + bool need_repack; }; @@ -382,7 +385,8 @@ static int transaction_oob(struct tdb_context *tdb, tdb_off_t len, int probe) if (len <= tdb->map_size) { return 0; } - return TDB_ERRCODE(TDB_ERR_IO, -1); + tdb->ecode = TDB_ERR_IO; + return -1; } /* @@ -397,6 +401,8 @@ static int transaction_expand_file(struct tdb_context *tdb, tdb_off_t size, return -1; } + tdb->transaction->need_repack = true; + return 0; } @@ -993,6 +999,7 @@ int tdb_transaction_commit(struct tdb_context *tdb) { const struct tdb_methods *methods; int i; + bool need_repack; if (tdb->transaction == NULL) { TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_commit: no transaction\n")); @@ -1092,10 +1099,16 @@ int tdb_transaction_commit(struct tdb_context *tdb) utime(tdb->name, NULL); #endif + need_repack = tdb->transaction->need_repack; + /* use a transaction cancel to free memory and remove the transaction locks */ tdb_transaction_cancel_internal(tdb); + if (need_repack) { + return tdb_repack(tdb); + } + return 0; }