diff options
| author | Michael Adam <obnox@samba.org> | 2014-06-11 12:03:01 +0200 |
|---|---|---|
| committer | Volker Lendecke <vl@samba.org> | 2014-06-26 10:00:11 +0200 |
| commit | 4bec28bfa9c383327f6c9767868997e4b239cafd (patch) | |
| tree | d4beb6d9b867c115b5d848c513eb08d7e4b615c7 | |
| parent | 117807cd2dbb7cf2276b84e2b20f858cd6ec30e9 (diff) | |
| download | samba-4bec28bfa9c383327f6c9767868997e4b239cafd.tar.gz samba-4bec28bfa9c383327f6c9767868997e4b239cafd.tar.xz samba-4bec28bfa9c383327f6c9767868997e4b239cafd.zip | |
tdb: simplify tdb_free() using check_merge_with_left_record()
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
| -rw-r--r-- | lib/tdb/common/freelist.c | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/lib/tdb/common/freelist.c b/lib/tdb/common/freelist.c index 69b3c66ab8..47d6301114 100644 --- a/lib/tdb/common/freelist.c +++ b/lib/tdb/common/freelist.c @@ -253,8 +253,7 @@ static int check_merge_with_left_record(struct tdb_context *tdb, */ int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec) { - tdb_off_t left; - struct tdb_record l; + int ret; /* Allocation and tailer lock */ if (tdb_lock(tdb, -1, F_WRLCK) != 0) @@ -293,25 +292,17 @@ int tdb_free(struct tdb_context *tdb, tdb_off_t offset, struct tdb_record *rec) left: #endif - if (read_record_on_left(tdb, offset, &left, &l) != 0) { - goto update; - } - - if (l.magic != TDB_FREE_MAGIC) { - goto update; - } - - /* It's free - expand to include it. */ - if (merge_with_left_record(tdb, left, &l, rec) != 0) { + ret = check_merge_with_left_record(tdb, offset, rec, NULL, NULL); + if (ret == -1) { goto fail; } + if (ret == 1) { + /* merged */ + goto done; + } - tdb_unlock(tdb, -1, F_WRLCK); - return 0; - -update: + /* Nothing to merge, prepend to free list */ - /* Now, prepend to free list */ rec->magic = TDB_FREE_MAGIC; if (tdb_ofs_read(tdb, FREELIST_TOP, &rec->next) == -1 || @@ -321,6 +312,7 @@ update: goto fail; } +done: /* And we're done. */ tdb_unlock(tdb, -1, F_WRLCK); return 0; |
