From: Volker Lendecke Date: Wed, 16 Aug 2017 15:37:41 +0000 (+0200) Subject: gencache: Simplify gencache_stabilize X-Git-Tag: tdb-1.3.15~63 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=988a67d17d0ffe7da5b3faf84b708ad1154bd55c;p=thirdparty%2Fsamba.git gencache: Simplify gencache_stabilize The only record that must remain in gencache_notrans.tdb is the last_stabilize marker. Use tdb_wipe_all and store the marker under the allrecord lock. Signed-off-by: Volker Lendecke Reviewed-by: Andreas Schneider Autobuild-User(master): Andreas Schneider Autobuild-Date(master): Thu Aug 17 15:49:00 CEST 2017 on sn-devel-144 --- diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c index 24edcc7fc4e..e73d1c52a0e 100644 --- a/source3/lib/gencache.c +++ b/source3/lib/gencache.c @@ -599,9 +599,6 @@ struct stabilize_state { static int stabilize_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA val, void *priv); -static int wipe_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA val, - void *priv); - /** * Stabilize gencache * @@ -667,20 +664,10 @@ bool gencache_stabilize(void) return false; } - res = tdb_traverse(cache_notrans->tdb, wipe_fn, NULL); + res = tdb_wipe_all(cache_notrans->tdb); if (res < 0) { - DEBUG(10, ("tdb_traverse with wipe_fn on gencache_notrans.tdb " - "failed: %s\n", - tdb_errorstr(cache_notrans->tdb))); - tdb_unlockall(cache_notrans->tdb); - return false; - } - - res = tdb_unlockall(cache_notrans->tdb); - if (res != 0) { - DEBUG(10, ("tdb_unlockall on gencache.tdb failed: " - "%s\n", tdb_errorstr(cache->tdb))); - return false; + DBG_DEBUG("tdb_wipe_all on gencache_notrans.tdb failed: %s\n", + tdb_errorstr(cache_notrans->tdb)); } now = talloc_asprintf(talloc_tos(), "%d", (int)time(NULL)); @@ -690,6 +677,13 @@ bool gencache_stabilize(void) TALLOC_FREE(now); } + res = tdb_unlockall(cache_notrans->tdb); + if (res != 0) { + DEBUG(10, ("tdb_unlockall on gencache.tdb failed: " + "%s\n", tdb_errorstr(cache->tdb))); + return false; + } + return true; } @@ -731,35 +725,6 @@ static int stabilize_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA val, return 0; } -static int wipe_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA val, - void *priv) -{ - int res; - bool ok; - time_t timeout; - - res = tdb_data_cmp(key, last_stabilize_key()); - if (res == 0) { - return 0; - } - - ok = gencache_pull_timeout(val.dptr, &timeout, NULL); - if (!ok) { - DEBUG(10, ("Ignoring invalid entry\n")); - return 0; - } - - res = tdb_delete(tdb, key); - if (res != 0) { - DEBUG(10, ("tdb_delete from gencache_notrans.tdb failed: " - "%s\n", tdb_errorstr(cache_notrans->tdb))); - return -1; - } - - return 0; -} - - /** * Get existing entry from the cache file. *