diff options
author | Andrew Bartlett <abartlet@samba.org> | 2011-10-12 23:01:08 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2011-10-13 14:06:07 +0200 |
commit | 01c934c81e55b79601122d8e0740c7946077c37e (patch) | |
tree | f6e7909690bc399c3036ef80e22997aadbf88884 | |
parent | 3cdb1fe4404e26ae383cfb73bfa8af36cb1d7f7c (diff) | |
download | samba-01c934c81e55b79601122d8e0740c7946077c37e.tar.gz samba-01c934c81e55b79601122d8e0740c7946077c37e.tar.bz2 samba-01c934c81e55b79601122d8e0740c7946077c37e.zip |
lib/util: Add back control of mmap and hash size in tdb for top level build
This passes down a struct loadparm_context to allow these
parameters to be checked. This may be s3 or s4 context, allowing the
#if _SAMBA_BUILD_ macro to go away safely.
Andrew Bartlett
-rw-r--r-- | lib/util/tdb_wrap.c | 21 | ||||
-rw-r--r-- | lib/util/tdb_wrap.h | 5 | ||||
-rwxr-xr-x | lib/util/wscript_build | 2 | ||||
-rw-r--r-- | libcli/auth/schannel_state_tdb.c | 2 | ||||
-rw-r--r-- | source3/lib/dbwrap/dbwrap_tdb.c | 8 | ||||
-rw-r--r-- | source3/lib/messages_local.c | 21 | ||||
-rw-r--r-- | source3/lib/server_mutex.c | 13 | ||||
-rw-r--r-- | source3/lib/serverid.c | 11 | ||||
-rw-r--r-- | source3/smbd/notify_internal.c | 13 | ||||
-rw-r--r-- | source4/cluster/local.c | 2 | ||||
-rw-r--r-- | source4/lib/messaging/messaging.c | 9 | ||||
-rw-r--r-- | source4/ntvfs/posix/python/pyxattr_tdb.c | 6 | ||||
-rw-r--r-- | source4/ntvfs/posix/vfs_posix.c | 3 | ||||
-rw-r--r-- | source4/param/secrets.c | 2 | ||||
-rw-r--r-- | source4/torture/local/dbspeed.c | 2 |
15 files changed, 88 insertions, 32 deletions
diff --git a/lib/util/tdb_wrap.c b/lib/util/tdb_wrap.c index a3dc76d6b7..7c3318bcad 100644 --- a/lib/util/tdb_wrap.c +++ b/lib/util/tdb_wrap.c @@ -22,6 +22,7 @@ #include "includes.h" #include "lib/util/dlinklist.h" #include "lib/util/tdb_wrap.h" +#include "lib/param/param.h" /* FIXME: TDB2 does this internally, so no need to wrap multiple opens! */ #if BUILD_TDB2 @@ -114,7 +115,8 @@ static struct tdb_wrap_private *tdb_wrap_private_open(TALLOC_CTX *mem_ctx, int hash_size, int tdb_flags, int open_flags, - mode_t mode) + mode_t mode, + struct loadparm_context *lp_ctx) { struct tdb_wrap_private *result; @@ -127,14 +129,7 @@ static struct tdb_wrap_private *tdb_wrap_private_open(TALLOC_CTX *mem_ctx, goto fail; } -#if _SAMBA_BUILD_ == 3 - /* This #if _SAMBA_BUILD == 3 is very unfortunate, as it means - * that in the top level build, these options are not - * available for these databases. However, having two - * different tdb_wrap lists is a worse fate, so this will do - * for now */ - - if (!lp_use_mmap()) { + if (!lpcfg_use_mmap(lp_ctx)) { tdb_flags |= TDB_NOMMAP; } @@ -147,9 +142,8 @@ static struct tdb_wrap_private *tdb_wrap_private_open(TALLOC_CTX *mem_ctx, } else { base = name; } - hash_size = lp_parm_int(-1, "tdb_hashsize", base, 0); + hash_size = lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0); } -#endif result->tdb = tdb_open_compat(name, hash_size, tdb_flags, open_flags, mode, tdb_wrap_log, NULL); @@ -171,7 +165,8 @@ fail: */ struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode) + int open_flags, mode_t mode, + struct loadparm_context *lp_ctx) { struct tdb_wrap *result; struct tdb_wrap_private *w; @@ -189,7 +184,7 @@ struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, if (w == NULL) { w = tdb_wrap_private_open(result, name, hash_size, tdb_flags, - open_flags, mode); + open_flags, mode, lp_ctx); } else { /* * Correctly use talloc_reference: The tdb will be diff --git a/lib/util/tdb_wrap.h b/lib/util/tdb_wrap.h index 6f9f3834d4..81e77e76a4 100644 --- a/lib/util/tdb_wrap.h +++ b/lib/util/tdb_wrap.h @@ -35,8 +35,11 @@ struct tdb_wrap { struct tdb_context *tdb; }; +struct loadparm_context; + struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode); + int open_flags, mode_t mode, + struct loadparm_context *lp_ctx); #endif /* _TDB_WRAP_H_ */ diff --git a/lib/util/wscript_build b/lib/util/wscript_build index 8b4901a7de..1dc65fab5e 100755 --- a/lib/util/wscript_build +++ b/lib/util/wscript_build @@ -88,7 +88,7 @@ bld.SAMBA_SUBSYSTEM('UTIL_PW', bld.SAMBA_LIBRARY('tdb-wrap', source='tdb_wrap.c', - deps='tdb_compat talloc samba-util', + deps='tdb_compat talloc samba-util samba-hostconfig', private_library=True, local_include=False ) diff --git a/libcli/auth/schannel_state_tdb.c b/libcli/auth/schannel_state_tdb.c index 8910041f99..f2b918816a 100644 --- a/libcli/auth/schannel_state_tdb.c +++ b/libcli/auth/schannel_state_tdb.c @@ -47,7 +47,7 @@ struct tdb_wrap *open_schannel_session_store(TALLOC_CTX *mem_ctx, return NULL; } - tdb_sc = tdb_wrap_open(mem_ctx, fname, 0, TDB_CLEAR_IF_FIRST|TDB_NOSYNC, O_RDWR|O_CREAT, 0600); + tdb_sc = tdb_wrap_open(mem_ctx, fname, 0, TDB_CLEAR_IF_FIRST|TDB_NOSYNC, O_RDWR|O_CREAT, 0600, lp_ctx); if (!tdb_sc) { DEBUG(0,("open_schannel_session_store: Failed to open %s - %s\n", diff --git a/source3/lib/dbwrap/dbwrap_tdb.c b/source3/lib/dbwrap/dbwrap_tdb.c index 4330c961ec..e9e4900068 100644 --- a/source3/lib/dbwrap/dbwrap_tdb.c +++ b/source3/lib/dbwrap/dbwrap_tdb.c @@ -22,6 +22,7 @@ #include "dbwrap/dbwrap_private.h" #include "dbwrap/dbwrap_tdb.h" #include "lib/util/tdb_wrap.h" +#include "lib/param/param.h" struct db_tdb_ctx { struct tdb_wrap *wtdb; @@ -359,12 +360,14 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx, { struct db_context *result = NULL; struct db_tdb_ctx *db_tdb; - + struct loadparm_context *lp_ctx; + result = talloc_zero(mem_ctx, struct db_context); if (result == NULL) { DEBUG(0, ("talloc failed\n")); goto fail; } + lp_ctx = loadparm_init_s3(result, loadparm_s3_context()); result->private_data = db_tdb = talloc(result, struct db_tdb_ctx); if (db_tdb == NULL) { @@ -373,7 +376,8 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx, } db_tdb->wtdb = tdb_wrap_open(db_tdb, name, hash_size, tdb_flags, - open_flags, mode); + open_flags, mode, lp_ctx); + talloc_unlink(result, lp_ctx); if (db_tdb->wtdb == NULL) { DEBUG(3, ("Could not open tdb: %s\n", strerror(errno))); goto fail; diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c index 67234d4d76..9b4e3c5e43 100644 --- a/source3/lib/messages_local.c +++ b/source3/lib/messages_local.c @@ -46,6 +46,7 @@ #include "system/filesys.h" #include "messages.h" #include "lib/util/tdb_wrap.h" +#include "lib/param/param.h" struct messaging_tdb_context { struct messaging_context *msg_ctx; @@ -86,12 +87,19 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, { struct messaging_backend *result; struct messaging_tdb_context *ctx; + struct loadparm_context *lp_ctx; if (!(result = talloc(mem_ctx, struct messaging_backend))) { DEBUG(0, ("talloc failed\n")); return NT_STATUS_NO_MEMORY; } + lp_ctx = loadparm_init_s3(result, loadparm_s3_context()); + if (lp_ctx == NULL) { + DEBUG(0, ("loadparm_init_s3 failed\n")); + return NT_STATUS_INTERNAL_ERROR; + } + ctx = talloc_zero(result, struct messaging_tdb_context); if (!ctx) { DEBUG(0, ("talloc failed\n")); @@ -105,7 +113,8 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, ctx->tdb = tdb_wrap_open(ctx, lock_path("messages.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE|TDB_INCOMPATIBLE_HASH, - O_RDWR|O_CREAT,0600); + O_RDWR|O_CREAT,0600, lp_ctx); + talloc_unlink(result, lp_ctx); if (!ctx->tdb) { NTSTATUS status = map_nt_error_from_unix(errno); @@ -137,6 +146,13 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx, bool messaging_tdb_parent_init(TALLOC_CTX *mem_ctx) { struct tdb_wrap *db; + struct loadparm_context *lp_ctx; + + lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_context()); + if (lp_ctx == NULL) { + DEBUG(0, ("loadparm_init_s3 failed\n")); + return false; + } /* * Open the tdb in the parent process (smbd) so that our @@ -146,7 +162,8 @@ bool messaging_tdb_parent_init(TALLOC_CTX *mem_ctx) db = tdb_wrap_open(mem_ctx, lock_path("messages.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_VOLATILE|TDB_INCOMPATIBLE_HASH, - O_RDWR|O_CREAT,0600); + O_RDWR|O_CREAT,0600, lp_ctx); + talloc_unlink(mem_ctx, lp_ctx); if (db == NULL) { DEBUG(1, ("could not open messaging.tdb: %s\n", strerror(errno))); diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c index dc65819197..7ceecfe770 100644 --- a/source3/lib/server_mutex.c +++ b/source3/lib/server_mutex.c @@ -22,6 +22,7 @@ #include "system/filesys.h" #include "lib/util/tdb_wrap.h" #include "util_tdb.h" +#include "lib/param/param.h" /* For reasons known only to MS, many of their NT/Win2k versions need serialised access only. Two connections at the same time @@ -46,13 +47,20 @@ struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name, int timeout) { struct named_mutex *result; - + struct loadparm_context *lp_ctx; result = talloc(mem_ctx, struct named_mutex); if (result == NULL) { DEBUG(0, ("talloc failed\n")); return NULL; } + lp_ctx = loadparm_init_s3(result, loadparm_s3_context()); + if (lp_ctx == NULL) { + DEBUG(0, ("loadparm_init_s3 failed\n")); + talloc_free(result); + return NULL; + } + result->name = talloc_strdup(result, name); if (result->name == NULL) { DEBUG(0, ("talloc failed\n")); @@ -61,7 +69,8 @@ struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name, } result->tdb = tdb_wrap_open(result, lock_path("mutex.tdb"), 0, - TDB_DEFAULT, O_RDWR|O_CREAT, 0600); + TDB_DEFAULT, O_RDWR|O_CREAT, 0600, lp_ctx); + talloc_unlink(result, lp_ctx); if (result->tdb == NULL) { DEBUG(1, ("Could not open mutex.tdb: %s\n", strerror(errno))); diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c index 151d1d605d..b3b294f893 100644 --- a/source3/lib/serverid.c +++ b/source3/lib/serverid.c @@ -24,6 +24,7 @@ #include "dbwrap/dbwrap.h" #include "dbwrap/dbwrap_open.h" #include "lib/util/tdb_wrap.h" +#include "lib/param/param.h" struct serverid_key { pid_t pid; @@ -39,6 +40,13 @@ struct serverid_data { bool serverid_parent_init(TALLOC_CTX *mem_ctx) { struct tdb_wrap *db; + struct loadparm_context *lp_ctx; + + lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_context()); + if (lp_ctx == NULL) { + DEBUG(0, ("loadparm_init_s3 failed\n")); + return false; + } /* * Open the tdb in the parent process (smbd) so that our @@ -48,7 +56,8 @@ bool serverid_parent_init(TALLOC_CTX *mem_ctx) db = tdb_wrap_open(mem_ctx, lock_path("serverid.tdb"), 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT, - 0644); + 0644, lp_ctx); + talloc_unlink(mem_ctx, lp_ctx); if (db == NULL) { DEBUG(1, ("could not open serverid.tdb: %s\n", strerror(errno))); diff --git a/source3/smbd/notify_internal.c b/source3/smbd/notify_internal.c index 4f2749e17d..484a31c5be 100644 --- a/source3/smbd/notify_internal.c +++ b/source3/smbd/notify_internal.c @@ -32,6 +32,7 @@ #include "messages.h" #include "lib/util/tdb_wrap.h" #include "util_tdb.h" +#include "lib/param/param.h" struct notify_context { struct db_context *db_recursive; @@ -137,11 +138,17 @@ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server, bool notify_internal_parent_init(TALLOC_CTX *mem_ctx) { struct tdb_wrap *db1, *db2; + struct loadparm_context *lp_ctx; if (lp_clustering()) { return true; } + lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_context()); + if (lp_ctx == NULL) { + DEBUG(0, ("loadparm_init_s3 failed\n")); + return false; + } /* * Open the tdbs in the parent process (smbd) so that our * CLEAR_IF_FIRST optimization in tdb_reopen_all can properly @@ -150,13 +157,15 @@ bool notify_internal_parent_init(TALLOC_CTX *mem_ctx) db1 = tdb_wrap_open(mem_ctx, lock_path("notify.tdb"), 0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, - O_RDWR|O_CREAT, 0644); + O_RDWR|O_CREAT, 0644, lp_ctx); if (db1 == NULL) { + talloc_unlink(mem_ctx, lp_ctx); DEBUG(1, ("could not open notify.tdb: %s\n", strerror(errno))); return false; } db2 = tdb_wrap_open(mem_ctx, lock_path("notify_onelevel.tdb"), - 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT, 0644); + 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT, 0644, lp_ctx); + talloc_unlink(mem_ctx, lp_ctx); if (db2 == NULL) { DEBUG(1, ("could not open notify_onelevel.tdb: %s\n", strerror(errno))); diff --git a/source4/cluster/local.c b/source4/cluster/local.c index 0a294b4d1d..c62c5cf405 100644 --- a/source4/cluster/local.c +++ b/source4/cluster/local.c @@ -53,7 +53,7 @@ static struct tdb_wrap *local_tdb_tmp_open(struct cluster_ops *ops, char *path = smbd_tmp_path(mem_ctx, lp_ctx, dbname); struct tdb_wrap *w; w = tdb_wrap_open(mem_ctx, path, 0, flags, - O_RDWR|O_CREAT, 0600); + O_RDWR|O_CREAT, 0600, lp_ctx); talloc_free(path); return w; } diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index 51fc8e26ed..21ff1b456a 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -56,6 +56,7 @@ struct imessaging_context { struct socket_context *sock; const char *base_path; const char *path; + struct loadparm_context *lp_ctx; struct dispatch_fn **dispatch; uint32_t num_types; struct idr_context *dispatch_tree; @@ -594,6 +595,12 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx, /* create the messaging directory if needed */ + msg->lp_ctx = talloc_reference(msg, lp_ctx); + if (!msg->lp_ctx) { + talloc_free(msg); + return NULL; + } + msg->base_path = lpcfg_imessaging_path(msg, lp_ctx); mkdir(msg->base_path, 0700); @@ -881,7 +888,7 @@ static struct tdb_wrap *irpc_namedb_open(struct imessaging_context *msg_ctx) if (path == NULL) { return NULL; } - t = tdb_wrap_open(msg_ctx, path, 0, 0, O_RDWR|O_CREAT, 0660); + t = tdb_wrap_open(msg_ctx, path, 0, 0, O_RDWR|O_CREAT, 0660, msg_ctx->lp_ctx); talloc_free(path); return t; } diff --git a/source4/ntvfs/posix/python/pyxattr_tdb.c b/source4/ntvfs/posix/python/pyxattr_tdb.c index 768dcbcafd..7e59b54ee2 100644 --- a/source4/ntvfs/posix/python/pyxattr_tdb.c +++ b/source4/ntvfs/posix/python/pyxattr_tdb.c @@ -26,6 +26,7 @@ #include "lib/util/wrap_xattr.h" #include "ntvfs/posix/vfs_posix.h" #include "libcli/util/pyerrors.h" +#include "param/pyparam.h" void initxattr_tdb(void); @@ -50,7 +51,8 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args) blob.length = blobsize; mem_ctx = talloc_new(NULL); eadb = tdb_wrap_open(mem_ctx, tdbname, 50000, - TDB_DEFAULT, O_RDWR|O_CREAT, 0600); + TDB_DEFAULT, O_RDWR|O_CREAT, 0600, + py_default_loadparm_context(mem_ctx)); if (eadb == NULL) { PyErr_SetFromErrno(PyExc_IOError); @@ -82,7 +84,7 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args) mem_ctx = talloc_new(NULL); eadb = tdb_wrap_open(mem_ctx, tdbname, 50000, - TDB_DEFAULT, O_RDWR|O_CREAT, 0600); + TDB_DEFAULT, O_RDWR|O_CREAT, 0600, py_default_loadparm_context(mem_ctx)); if (eadb == NULL) { PyErr_SetFromErrno(PyExc_IOError); talloc_free(mem_ctx); diff --git a/source4/ntvfs/posix/vfs_posix.c b/source4/ntvfs/posix/vfs_posix.c index 00ed146c96..cecaee00cc 100644 --- a/source4/ntvfs/posix/vfs_posix.c +++ b/source4/ntvfs/posix/vfs_posix.c @@ -120,7 +120,8 @@ static void pvfs_setup_options(struct pvfs_state *pvfs) eadb = share_string_option(scfg, PVFS_EADB, NULL); if (eadb != NULL) { pvfs->ea_db = tdb_wrap_open(pvfs, eadb, 50000, - TDB_DEFAULT, O_RDWR|O_CREAT, 0600); + TDB_DEFAULT, O_RDWR|O_CREAT, 0600, + pvfs->ntvfs->ctx->lp_ctx); if (pvfs->ea_db != NULL) { pvfs->flags |= PVFS_FLAG_XATTR_ENABLE; } else { diff --git a/source4/param/secrets.c b/source4/param/secrets.c index 55d1aa779b..32a97453d4 100644 --- a/source4/param/secrets.c +++ b/source4/param/secrets.c @@ -59,7 +59,7 @@ bool randseed_init(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx) fname = lpcfg_private_path(mem_ctx, lp_ctx, "randseed.tdb"); - tdb = tdb_wrap_open(mem_ctx, fname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600); + tdb = tdb_wrap_open(mem_ctx, fname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600, lp_ctx); if (!tdb) { DEBUG(0,("Failed to open %s\n", fname)); diff --git a/source4/torture/local/dbspeed.c b/source4/torture/local/dbspeed.c index 614a9b52ae..60721cc2c0 100644 --- a/source4/torture/local/dbspeed.c +++ b/source4/torture/local/dbspeed.c @@ -65,7 +65,7 @@ static bool test_tdb_speed(struct torture_context *torture, const void *_data) torture_comment(torture, "Testing tdb speed for sidmap\n"); tdbw = tdb_wrap_open(tmp_ctx, "test.tdb", - 10000, 0, O_RDWR|O_CREAT|O_TRUNC, 0600); + 10000, 0, O_RDWR|O_CREAT|O_TRUNC, 0600, torture->lp_ctx); if (!tdbw) { torture_result(torture, TORTURE_FAIL, "Failed to open test.tdb"); goto failed; |