X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ffree.c;h=7633eb772c7ff925f9cba7779234d1371b4427e0;hp=d2285567eb0efdf56dfd8d96ec0650845ef403e0;hb=74b0109ebd2a30d57d19ae9a56f16c0f3b3637eb;hpb=b21004624683be5bf1d8f75e3b5be4e9618049ee diff --git a/ccan/tdb2/free.c b/ccan/tdb2/free.c index d2285567..7633eb77 100644 --- a/ccan/tdb2/free.c +++ b/ccan/tdb2/free.c @@ -287,7 +287,7 @@ static tdb_bool_err coalesce(struct tdb_context *tdb, add_stat(tdb, alloc_coalesce_tried, 1); end = off + sizeof(struct tdb_used_record) + data_len; - while (end < tdb->map_size) { + while (end < tdb->file->map_size) { const struct tdb_free_record *r; tdb_off_t nb_off; unsigned ftable, bucket; @@ -523,6 +523,15 @@ again: goto unlock_err; } + /* For futureproofing, we put a 0 in any unused space. */ + if (rec_extra_padding(&rec)) { + ecode = tdb->methods->twrite(tdb, best_off + sizeof(rec) + + keylen + datalen, "", 1); + if (ecode != TDB_SUCCESS) { + goto unlock_err; + } + } + /* Bucket of leftover will be <= current bucket, so nested * locking is allowed. */ if (leftover) { @@ -652,17 +661,17 @@ static enum TDB_ERROR tdb_expand(struct tdb_context *tdb, tdb_len_t size) /* Need to hold a hash lock to expand DB: transactions rely on it. */ if (!(tdb->flags & TDB_NOLOCK) - && !tdb->allrecord_lock.count && !tdb_has_hash_locks(tdb)) { + && !tdb->file->allrecord_lock.count && !tdb_has_hash_locks(tdb)) { return tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR, "tdb_expand: must hold lock during expand"); } /* always make room for at least 100 more records, and at least 25% more space. */ - if (size * TDB_EXTENSION_FACTOR > tdb->map_size / 4) + if (size * TDB_EXTENSION_FACTOR > tdb->file->map_size / 4) wanted = size * TDB_EXTENSION_FACTOR; else - wanted = tdb->map_size / 4; + wanted = tdb->file->map_size / 4; wanted = adjust_size(0, wanted); /* Only one person can expand file at a time. */ @@ -672,9 +681,9 @@ static enum TDB_ERROR tdb_expand(struct tdb_context *tdb, tdb_len_t size) } /* Someone else may have expanded the file, so retry. */ - old_size = tdb->map_size; - tdb->methods->oob(tdb, tdb->map_size + 1, true); - if (tdb->map_size != old_size) { + old_size = tdb->file->map_size; + tdb->methods->oob(tdb, tdb->file->map_size + 1, true); + if (tdb->file->map_size != old_size) { tdb_unlock_expand(tdb, F_WRLCK); return TDB_SUCCESS; }