[SCM] Samba Shared Repository - branch master updated
Andreas Schneider
asn at samba.org
Thu Aug 17 13:50:02 UTC 2017
The branch, master has been updated
via 988a67d gencache: Simplify gencache_stabilize
via 2311d35 gencache: Remove tdb_check from gencache_init()
via a90702f tdb: Clarify the CLEAR_IF_FIRST locked logic
from 9468d0f util: Add error handling to become_daemon()
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 988a67d17d0ffe7da5b3faf84b708ad1154bd55c
Author: Volker Lendecke <vl at samba.org>
Date: Wed Aug 16 17:37:41 2017 +0200
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 at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
Autobuild-User(master): Andreas Schneider <asn at cryptomilk.org>
Autobuild-Date(master): Thu Aug 17 15:49:00 CEST 2017 on sn-devel-144
commit 2311d35f84b5e71ec1e19ae9165d6be650e50d37
Author: Volker Lendecke <vl at samba.org>
Date: Wed Aug 16 16:22:27 2017 +0200
gencache: Remove tdb_check from gencache_init()
This was legacy from times when we had just one non-transactioned gencache.tdb.
With the split into transactioned gencache.tdb and fast, non-transactioned,
mutexed clear-if-first gencache_notrans.tdb this has become unnecessary.
Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
commit a90702fc5d5898b8a45e8335d8de8d46c08870fa
Author: Volker Lendecke <vl at samba.org>
Date: Wed Aug 16 15:21:14 2017 +0200
tdb: Clarify the CLEAR_IF_FIRST locked logic
This is another level of indentation, but it took me a while staring at the
if-condition to find that "locked" was assigned the result of "==0", not the
return value of tdb_nest_lock().
Best viewed with "git show -b".
Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
-----------------------------------------------------------------------
Summary of changes:
lib/tdb/common/open.c | 70 +++++++++++++++++++++++---------------------
source3/lib/gencache.c | 78 +++++++-------------------------------------------
2 files changed, 48 insertions(+), 100 deletions(-)
Changeset truncated at 500 lines:
diff --git a/lib/tdb/common/open.c b/lib/tdb/common/open.c
index f3ef856..cfb476d 100644
--- a/lib/tdb/common/open.c
+++ b/lib/tdb/common/open.c
@@ -300,7 +300,8 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
struct tdb_header header;
struct tdb_context *tdb;
struct stat st;
- int rev = 0, locked = 0;
+ int rev = 0;
+ bool locked = false;
unsigned char *vp;
uint32_t vertest;
unsigned v;
@@ -512,37 +513,42 @@ _PUBLIC_ struct tdb_context *tdb_open_ex(const char *name, int hash_size, int td
/* we need to zero database if we are the only one with it open */
if ((tdb_flags & TDB_CLEAR_IF_FIRST) &&
- (!tdb->read_only) &&
- (locked = (tdb_nest_lock(tdb, ACTIVE_LOCK, F_WRLCK, TDB_LOCK_NOWAIT|TDB_LOCK_PROBE) == 0))) {
- ret = tdb_brlock(tdb, F_WRLCK, FREELIST_TOP, 0,
- TDB_LOCK_WAIT);
- if (ret == -1) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
- "tdb_brlock failed for %s: %s\n",
- name, strerror(errno)));
- goto fail;
- }
- ret = tdb_new_database(tdb, &header, hash_size);
- if (ret == -1) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
- "tdb_new_database failed for %s: %s\n",
- name, strerror(errno)));
- tdb_unlockall(tdb);
- goto fail;
- }
- ret = tdb_brunlock(tdb, F_WRLCK, FREELIST_TOP, 0);
- if (ret == -1) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
- "tdb_unlockall failed for %s: %s\n",
- name, strerror(errno)));
- goto fail;
- }
- ret = lseek(tdb->fd, 0, SEEK_SET);
- if (ret == -1) {
- TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
- "lseek failed for %s: %s\n",
- name, strerror(errno)));
- goto fail;
+ (!tdb->read_only)) {
+ ret = tdb_nest_lock(tdb, ACTIVE_LOCK, F_WRLCK,
+ TDB_LOCK_NOWAIT|TDB_LOCK_PROBE);
+ locked = (ret == 0);
+
+ if (locked) {
+ ret = tdb_brlock(tdb, F_WRLCK, FREELIST_TOP, 0,
+ TDB_LOCK_WAIT);
+ if (ret == -1) {
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
+ "tdb_brlock failed for %s: %s\n",
+ name, strerror(errno)));
+ goto fail;
+ }
+ ret = tdb_new_database(tdb, &header, hash_size);
+ if (ret == -1) {
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
+ "tdb_new_database failed for "
+ "%s: %s\n", name, strerror(errno)));
+ tdb_unlockall(tdb);
+ goto fail;
+ }
+ ret = tdb_brunlock(tdb, F_WRLCK, FREELIST_TOP, 0);
+ if (ret == -1) {
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
+ "tdb_unlockall failed for %s: %s\n",
+ name, strerror(errno)));
+ goto fail;
+ }
+ ret = lseek(tdb->fd, 0, SEEK_SET);
+ if (ret == -1) {
+ TDB_LOG((tdb, TDB_DEBUG_FATAL, "tdb_open_ex: "
+ "lseek failed for %s: %s\n",
+ name, strerror(errno)));
+ goto fail;
+ }
}
}
diff --git a/source3/lib/gencache.c b/source3/lib/gencache.c
index 1572825..e73d1c5 100644
--- a/source3/lib/gencache.c
+++ b/source3/lib/gencache.c
@@ -74,29 +74,6 @@ static bool gencache_init(void)
cache = tdb_wrap_open(NULL, cache_fname, hash_size,
TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
open_flags, 0644);
- if (cache) {
- int ret;
- ret = tdb_check(cache->tdb, NULL, NULL);
- if (ret != 0) {
- TALLOC_FREE(cache);
-
- /*
- * Retry with CLEAR_IF_FIRST.
- *
- * Warning: Converting this to dbwrap won't work
- * directly. gencache.c does transactions on this tdb,
- * and dbwrap forbids this for CLEAR_IF_FIRST
- * databases. tdb does allow transactions on
- * CLEAR_IF_FIRST databases, so lets use it here to
- * clean up a broken database.
- */
- cache = tdb_wrap_open(NULL, cache_fname, hash_size,
- TDB_DEFAULT|
- TDB_INCOMPATIBLE_HASH|
- TDB_CLEAR_IF_FIRST,
- open_flags, 0644);
- }
- }
if (!cache && (errno == EACCES)) {
open_flags = O_RDONLY;
@@ -622,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
*
@@ -690,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));
@@ -713,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;
}
@@ -754,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.
*
--
Samba Shared Repository
More information about the samba-cvs
mailing list