1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-12 09:18:10 +03:00

gencache: Convert gencache.tdb to tdb_wrap

This change is not strictly necessary, but for consistency both gencache
tdbs are now opened through tdb_wrap.

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
This commit is contained in:
Christof Schmitt 2014-11-17 15:44:47 -07:00 committed by Volker Lendecke
parent 139bd9589a
commit f80bbba287

View File

@ -37,7 +37,7 @@
#define BLOB_TYPE "DATA_BLOB"
#define BLOB_TYPE_LEN 9
static struct tdb_context *cache;
static struct tdb_wrap *cache;
static struct tdb_wrap *cache_notrans;
static int cache_notrans_seqnum;
@ -72,12 +72,14 @@ static bool gencache_init(void)
DEBUG(5, ("Opening cache file at %s\n", cache_fname));
cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT|TDB_INCOMPATIBLE_HASH, open_flags, 0644);
cache = tdb_wrap_open(NULL, cache_fname, 0,
TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
open_flags, 0644);
if (cache) {
int ret;
ret = tdb_check(cache, NULL, NULL);
ret = tdb_check(cache->tdb, NULL, NULL);
if (ret != 0) {
tdb_close(cache);
TALLOC_FREE(cache);
/*
* Retry with CLEAR_IF_FIRST.
@ -89,18 +91,19 @@ static bool gencache_init(void)
* CLEAR_IF_FIRST databases, so lets use it here to
* clean up a broken database.
*/
cache = tdb_open_log(cache_fname, 0,
TDB_DEFAULT|
TDB_INCOMPATIBLE_HASH|
TDB_CLEAR_IF_FIRST,
open_flags, 0644);
cache = tdb_wrap_open(NULL, cache_fname, 0,
TDB_DEFAULT|
TDB_INCOMPATIBLE_HASH|
TDB_CLEAR_IF_FIRST,
open_flags, 0644);
}
}
if (!cache && (errno == EACCES)) {
open_flags = O_RDONLY;
cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT|TDB_INCOMPATIBLE_HASH, open_flags,
0644);
cache = tdb_wrap_open(NULL, cache_fname, 0,
TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
open_flags, 0644);
if (cache) {
DEBUG(5, ("gencache_init: Opening cache file %s read-only.\n", cache_fname));
}
@ -114,8 +117,7 @@ static bool gencache_init(void)
cache_fname = lock_path("gencache_notrans.tdb");
if (cache_fname == NULL) {
tdb_close(cache);
cache = NULL;
TALLOC_FREE(cache);
return false;
}
@ -131,8 +133,7 @@ static bool gencache_init(void)
DEBUG(5, ("Opening %s failed: %s\n", cache_fname,
strerror(errno)));
TALLOC_FREE(cache_fname);
tdb_close(cache);
cache = NULL;
TALLOC_FREE(cache);
return false;
}
TALLOC_FREE(cache_fname);
@ -521,7 +522,7 @@ bool gencache_parse(const char *keystr,
if (ret == 0) {
return true;
}
ret = tdb_parse_record(cache, key, gencache_parse_fn, &state);
ret = tdb_parse_record(cache->tdb, key, gencache_parse_fn, &state);
return (ret == 0);
}
@ -640,9 +641,9 @@ bool gencache_stabilize(void)
return false;
}
res = tdb_transaction_start_nonblock(cache);
res = tdb_transaction_start_nonblock(cache->tdb);
if (res != 0) {
if (tdb_error(cache) == TDB_ERR_NOLOCK)
if (tdb_error(cache->tdb) == TDB_ERR_NOLOCK)
{
/*
* Someone else already does the stabilize,
@ -652,13 +653,13 @@ bool gencache_stabilize(void)
}
DEBUG(10, ("Could not start transaction on gencache.tdb: "
"%s\n", tdb_errorstr_compat(cache)));
"%s\n", tdb_errorstr_compat(cache->tdb)));
return false;
}
res = tdb_lockall(cache_notrans->tdb);
if (res != 0) {
tdb_transaction_cancel(cache);
tdb_transaction_cancel(cache->tdb);
DEBUG(10, ("Could not get allrecord lock on "
"gencache_notrans.tdb: %s\n",
tdb_errorstr_compat(cache_notrans->tdb)));
@ -670,20 +671,20 @@ bool gencache_stabilize(void)
res = tdb_traverse(cache_notrans->tdb, stabilize_fn, &state);
if (res < 0) {
tdb_unlockall(cache_notrans->tdb);
tdb_transaction_cancel(cache);
tdb_transaction_cancel(cache->tdb);
return false;
}
if (!state.written) {
tdb_unlockall(cache_notrans->tdb);
tdb_transaction_cancel(cache);
tdb_transaction_cancel(cache->tdb);
return true;
}
res = tdb_transaction_commit(cache);
res = tdb_transaction_commit(cache->tdb);
if (res != 0) {
DEBUG(10, ("tdb_transaction_commit on gencache.tdb failed: "
"%s\n", tdb_errorstr_compat(cache)));
"%s\n", tdb_errorstr_compat(cache->tdb)));
tdb_unlockall(cache_notrans->tdb);
return false;
}
@ -700,7 +701,7 @@ bool gencache_stabilize(void)
res = tdb_unlockall(cache_notrans->tdb);
if (res != 0) {
DEBUG(10, ("tdb_unlockall on gencache.tdb failed: "
"%s\n", tdb_errorstr_compat(cache)));
"%s\n", tdb_errorstr_compat(cache->tdb)));
return false;
}
@ -730,14 +731,14 @@ static int stabilize_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA val,
return 0;
}
if ((timeout < time(NULL)) || (val.dsize == 0)) {
res = tdb_delete(cache, key);
res = tdb_delete(cache->tdb, key);
if (res == 0) {
state->written = true;
} else if (tdb_error(cache) == TDB_ERR_NOEXIST) {
} else if (tdb_error(cache->tdb) == TDB_ERR_NOEXIST) {
res = 0;
}
} else {
res = tdb_store(cache, key, val, 0);
res = tdb_store(cache->tdb, key, val, 0);
if (res == 0) {
state->written = true;
}
@ -745,7 +746,7 @@ static int stabilize_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA val,
if (res != 0) {
DEBUG(10, ("Transfer to gencache.tdb failed: %s\n",
tdb_errorstr_compat(cache)));
tdb_errorstr_compat(cache->tdb)));
return -1;
}
@ -922,7 +923,7 @@ void gencache_iterate_blobs(void (*fn)(const char *key, DATA_BLOB value,
tdb_traverse(cache_notrans->tdb, gencache_iterate_blobs_fn, &state);
state.in_persistent = true;
tdb_traverse(cache, gencache_iterate_blobs_fn, &state);
tdb_traverse(cache->tdb, gencache_iterate_blobs_fn, &state);
}
/**