diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2011-09-14 07:18:13 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2011-09-14 07:18:13 +0930 |
commit | 617c1fcfa476d65320dc2c14b21016b6b438c090 (patch) | |
tree | 7a5560477526214b1b39f126feda3e97e5e3bb20 /lib/tdb2 | |
parent | 73e4f35e3d4dd7043a140355e4cd0f10f54c7337 (diff) | |
download | samba-617c1fcfa476d65320dc2c14b21016b6b438c090.tar.gz samba-617c1fcfa476d65320dc2c14b21016b6b438c090.tar.bz2 samba-617c1fcfa476d65320dc2c14b21016b6b438c090.zip |
tdb2: save openhook, allow tdb_get_attribute() on it.
This makes it easy to call it again after a fork(), such as for
re-establishing the CLEAR_IF_FIRST files locks.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(Imported from CCAN commit 937d0babe99dcd315040a9e48430140e63e4a7df)
Diffstat (limited to 'lib/tdb2')
-rw-r--r-- | lib/tdb2/open.c | 27 | ||||
-rw-r--r-- | lib/tdb2/private.h | 4 | ||||
-rw-r--r-- | lib/tdb2/tdb2.h | 2 | ||||
-rw-r--r-- | lib/tdb2/test/failtest_helper.h | 6 |
4 files changed, 21 insertions, 18 deletions
diff --git a/lib/tdb2/open.c b/lib/tdb2/open.c index 757cfd416c..95ed558c57 100644 --- a/lib/tdb2/open.c +++ b/lib/tdb2/open.c @@ -270,11 +270,11 @@ enum TDB_ERROR tdb_get_attribute(struct tdb_context *tdb, attr->seed.seed = tdb->hash_seed; break; case TDB_ATTRIBUTE_OPENHOOK: - return tdb->last_error - = tdb_logerr(tdb, TDB_ERR_EINVAL, - TDB_LOG_USE_ERROR, - "tdb_get_attribute:" - " cannot get TDB_ATTRIBUTE_OPENHOOK"); + if (!tdb->openhook) + return tdb->last_error = TDB_ERR_NOEXIST; + attr->openhook.fn = tdb->openhook; + attr->openhook.data = tdb->openhook_data; + break; case TDB_ATTRIBUTE_STATS: { size_t size = attr->stats.size; if (size > tdb->stats.size) @@ -306,16 +306,16 @@ void tdb_unset_attribute(struct tdb_context *tdb, case TDB_ATTRIBUTE_LOG: tdb->log_fn = NULL; break; + case TDB_ATTRIBUTE_OPENHOOK: + tdb->openhook = NULL; + break; case TDB_ATTRIBUTE_HASH: case TDB_ATTRIBUTE_SEED: - case TDB_ATTRIBUTE_OPENHOOK: tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR, "tdb_unset_attribute: cannot unset %s after opening", type == TDB_ATTRIBUTE_HASH ? "TDB_ATTRIBUTE_HASH" - : type == TDB_ATTRIBUTE_SEED - ? "TDB_ATTRIBUTE_SEED" - : "TDB_ATTRIBUTE_OPENHOOK"); + : "TDB_ATTRIBUTE_SEED"); break; case TDB_ATTRIBUTE_STATS: tdb_logerr(tdb, TDB_ERR_EINVAL, @@ -347,7 +347,6 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags, ssize_t rlen; struct tdb_header hdr; struct tdb_attribute_seed *seed = NULL; - struct tdb_attribute_openhook *openhook = NULL; tdb_bool_err berr; enum TDB_ERROR ecode; int openlock; @@ -372,6 +371,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags, tdb->open_flags = open_flags; tdb->last_error = TDB_SUCCESS; tdb->file = NULL; + tdb->openhook = NULL; tdb->lock_fn = tdb_fcntl_lock; tdb->unlock_fn = tdb_fcntl_unlock; tdb->hash_fn = jenkins_hash; @@ -390,7 +390,8 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags, seed = &attr->seed; break; case TDB_ATTRIBUTE_OPENHOOK: - openhook = &attr->openhook; + tdb->openhook = attr->openhook.fn; + tdb->openhook_data = attr->openhook.data; break; default: /* These are set as normal. */ @@ -498,8 +499,8 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags, } /* call their open hook if they gave us one. */ - if (openhook) { - ecode = openhook->fn(tdb->file->fd, openhook->data); + if (tdb->openhook) { + ecode = tdb->openhook(tdb->file->fd, tdb->openhook_data); if (ecode != TDB_SUCCESS) { tdb_logerr(tdb, ecode, TDB_LOG_ERROR, "tdb_open: open hook failed"); diff --git a/lib/tdb2/private.h b/lib/tdb2/private.h index 163649953b..d7db41bf74 100644 --- a/lib/tdb2/private.h +++ b/lib/tdb2/private.h @@ -374,6 +374,10 @@ struct tdb_context { tdb_off_t ftable_off; unsigned int ftable; + /* Our open hook, if any. */ + enum TDB_ERROR (*openhook)(int fd, void *data); + void *openhook_data; + /* IO methods: changes for transactions. */ const struct tdb_methods *methods; diff --git a/lib/tdb2/tdb2.h b/lib/tdb2/tdb2.h index bbe60a8936..65f55d41fb 100644 --- a/lib/tdb2/tdb2.h +++ b/lib/tdb2/tdb2.h @@ -619,8 +619,6 @@ enum tdb_attribute_type { * This gets an attribute from a TDB which has previously been set (or * may return the default values). Set @attr.base.attr to the * attribute type you want get. - * - * Currently this does not work for TDB_ATTRIBUTE_OPENHOOK. */ enum TDB_ERROR tdb_get_attribute(struct tdb_context *tdb, union tdb_attribute *attr); diff --git a/lib/tdb2/test/failtest_helper.h b/lib/tdb2/test/failtest_helper.h index a62efbad58..73cd1aeb1e 100644 --- a/lib/tdb2/test/failtest_helper.h +++ b/lib/tdb2/test/failtest_helper.h @@ -4,9 +4,9 @@ #include <stdbool.h> /* FIXME: Check these! */ -#define INITIAL_TDB_MALLOC "open.c", 338, FAILTEST_MALLOC -#define URANDOM_OPEN "open.c", 45, FAILTEST_OPEN -#define URANDOM_READ "open.c", 25, FAILTEST_READ +#define INITIAL_TDB_MALLOC "open.c", 354, FAILTEST_MALLOC +#define URANDOM_OPEN "open.c", 62, FAILTEST_OPEN +#define URANDOM_READ "open.c", 42, FAILTEST_READ bool exit_check_log(struct failtest_call *history, unsigned num); bool failmatch(const struct failtest_call *call, |