mirror of
https://github.com/samba-team/samba.git
synced 2025-02-28 01:58:17 +03:00
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 <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Thu Aug 17 15:49:00 CEST 2017 on sn-devel-144
This commit is contained in:
parent
2311d35f84
commit
988a67d17d
@ -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.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user