gencache: Simplify gencache_stabilize
authorVolker Lendecke <vl@samba.org>
Wed, 16 Aug 2017 15:37:41 +0000 (17:37 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 17 Aug 2017 13:49:00 +0000 (15:49 +0200)
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

source3/lib/gencache.c

index 24edcc7..e73d1c5 100644 (file)
@@ -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.
  *