lib/util: Add back control of mmap and hash size in tdb for top level build
authorAndrew Bartlett <abartlet@samba.org>
Wed, 12 Oct 2011 12:01:08 +0000 (23:01 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 13 Oct 2011 12:06:07 +0000 (14:06 +0200)
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

15 files changed:
lib/util/tdb_wrap.c
lib/util/tdb_wrap.h
lib/util/wscript_build
libcli/auth/schannel_state_tdb.c
source3/lib/dbwrap/dbwrap_tdb.c
source3/lib/messages_local.c
source3/lib/server_mutex.c
source3/lib/serverid.c
source3/smbd/notify_internal.c
source4/cluster/local.c
source4/lib/messaging/messaging.c
source4/ntvfs/posix/python/pyxattr_tdb.c
source4/ntvfs/posix/vfs_posix.c
source4/param/secrets.c
source4/torture/local/dbspeed.c

index a3dc76d6b73216dc07ca5f82da95199af1bab202..7c3318bcadf9c10f58fb2608609c310bf6b03a87 100644 (file)
@@ -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
index 6f9f3834d430adb99e90f7eab203b56ac5c9abf9..81e77e76a45fc5b2fd23b59309324fd51d40c57a 100644 (file)
@@ -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_ */
index 8b4901a7dee4deaf982b84348d23d9b79f94e4b8..1dc65fab5e9f71658966782dde548f1e2ffa87ce 100755 (executable)
@@ -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
                  )
index 8910041f99b8bea08aa871652ff47865c5eed75d..f2b918816a77624e9f4870d8b516c8a0719f525f 100644 (file)
@@ -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",
index 4330c961ec55233a091d5a655a371689f3e7730f..e9e49000684dc110ebe6718eefd14eacdef9a056 100644 (file)
@@ -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;
index 67234d4d76dca6bfd6c4881c9cc058fe3d518caa..9b4e3c5e430aefc30479a838e5c49ba66219bec2 100644 (file)
@@ -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)));
index dc658191970f346d21666b9f19ecaf246bf6c9f6..7ceecfe770731bad0abd80984d785a723d522e13 100644 (file)
@@ -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)));
index 151d1d605df9e61d12a953a884505502d3dbaa7a..b3b294f893420bff5e5d4e985deb075207cf967e 100644 (file)
@@ -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)));
index 4f2749e17d0000815224fd6b1d8f9a2ed68cf8ac..484a31c5be8a287f051781c7a33ea08839149434 100644 (file)
@@ -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)));
index 0a294b4d1d16a5207c4e10f009f14d20f306c2ac..c62c5cf405e7de22614552352de393dd17340a29 100644 (file)
@@ -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;
 }
index 51fc8e26edfeca0546295ef06306dba37cde2235..21ff1b456a95ff1214471e1ae83e5ee45d30ce3d 100644 (file)
@@ -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;
 }
index 768dcbcafddf8c9993532200ccf88e082e07ea3f..7e59b54ee2e85fda46181b3b17c719e7f76088a0 100644 (file)
@@ -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);
index 00ed146c965c430591b3959a1452645f145da4f7..cecaee00cca1206980f219479a8e6050449b9282 100644 (file)
@@ -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 {
index 55d1aa779b261e6a33391d2e3fd56eda5490078b..32a97453d43325b1d0cdf1e468b8466e049dc8e9 100644 (file)
@@ -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));
index 614a9b52ae9b8a544143b7774cf2cd780820176d..60721cc2c087d001c0fc7a14f49e903a787b9843 100644 (file)
@@ -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;