mirror of
https://github.com/samba-team/samba.git
synced 2025-03-25 14:50:24 +03:00
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
This commit is contained in:
parent
3cdb1fe440
commit
01c934c81e
@ -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
|
||||
|
@ -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_ */
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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",
|
||||
|
@ -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;
|
||||
|
@ -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)));
|
||||
|
@ -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)));
|
||||
|
@ -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)));
|
||||
|
@ -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)));
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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));
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user