[PATCH] remove lp_ctx from tdb_wrap_open
Volker Lendecke
Volker.Lendecke at SerNet.DE
Fri Mar 28 09:16:35 MDT 2014
Hi!
If we want to merge with ctdb, this is required. Also find
some messaging4 cosmetic patches.
Review would be appreciated.
Thanks,
Volker
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From aadcf45db59fe14cf306104b4a8eeff773ddfad9 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 13:08:13 +0000
Subject: [PATCH 01/26] lib: Fix blank line endings
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/lib/messaging/messaging.c | 58 ++++++++++++++++++-------------------
1 file changed, 29 insertions(+), 29 deletions(-)
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index c37c91e..7a92eb0 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -1,20 +1,20 @@
-/*
+/*
Unix SMB/CIFS implementation.
Samba internal messaging functions
Copyright (C) Andrew Tridgell 2004
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -122,7 +122,7 @@ static void ping_message(struct imessaging_context *msg, void *private_data,
/*
return uptime of messaging server via irpc
*/
-static NTSTATUS irpc_uptime(struct irpc_message *msg,
+static NTSTATUS irpc_uptime(struct irpc_message *msg,
struct irpc_uptime *r)
{
struct imessaging_context *ctx = talloc_get_type(msg->private_data, struct imessaging_context);
@@ -130,7 +130,7 @@ static NTSTATUS irpc_uptime(struct irpc_message *msg,
return NT_STATUS_OK;
}
-/*
+/*
return the path to a messaging socket
*/
static char *imessaging_path(struct imessaging_context *msg, struct server_id server_id)
@@ -159,7 +159,7 @@ static void imessaging_dispatch(struct imessaging_context *msg, struct imessagin
/* temporary IDs use an idtree, the rest use a array of pointers */
if (rec->header->msg_type >= MSG_TMP_BASE) {
- d = (struct dispatch_fn *)idr_find(msg->dispatch_tree,
+ d = (struct dispatch_fn *)idr_find(msg->dispatch_tree,
rec->header->msg_type);
} else if (rec->header->msg_type < msg->num_types) {
d = msg->dispatch[rec->header->msg_type];
@@ -196,7 +196,7 @@ static void cluster_message_handler(struct imessaging_context *msg, DATA_BLOB pa
rec->retries = 0;
if (packet.length != sizeof(*rec->header) + rec->header->length) {
- DEBUG(0,("messaging: bad message header size %d should be %d\n",
+ DEBUG(0,("messaging: bad message header size %d should be %d\n",
rec->header->length, (int)(packet.length - sizeof(*rec->header))));
talloc_free(rec);
return;
@@ -221,7 +221,7 @@ static NTSTATUS try_send(struct imessaging_rec *rec)
/* rec->path is the path of the *other* socket, where we want
* this to end up */
- path = socket_address_from_strings(msg, msg->sock->backend_name,
+ path = socket_address_from_strings(msg, msg->sock->backend_name,
rec->path, 0);
if (!path) {
return NT_STATUS_NO_MEMORY;
@@ -239,7 +239,7 @@ static NTSTATUS try_send(struct imessaging_rec *rec)
/*
retry backed off messages
*/
-static void msg_retry_timer(struct tevent_context *ev, struct tevent_timer *te,
+static void msg_retry_timer(struct tevent_context *ev, struct tevent_timer *te,
struct timeval t, void *private_data)
{
struct imessaging_context *msg = talloc_get_type(private_data,
@@ -271,12 +271,12 @@ static void imessaging_send_handler(struct imessaging_context *msg)
/* we're getting continuous write errors -
backoff this record */
DLIST_REMOVE(msg->pending, rec);
- DLIST_ADD_END(msg->retry_queue, rec,
+ DLIST_ADD_END(msg->retry_queue, rec,
struct imessaging_rec *);
if (msg->retry_te == NULL) {
- msg->retry_te =
+ msg->retry_te =
tevent_add_timer(msg->event.ev, msg,
- timeval_current_ofs(1, 0),
+ timeval_current_ofs(1, 0),
msg_retry_timer, msg);
}
}
@@ -285,10 +285,10 @@ static void imessaging_send_handler(struct imessaging_context *msg)
rec->retries = 0;
if (!NT_STATUS_IS_OK(status)) {
TALLOC_CTX *tmp_ctx = talloc_new(msg);
- DEBUG(1,("messaging: Lost message from %s to %s of type %u - %s\n",
+ DEBUG(1,("messaging: Lost message from %s to %s of type %u - %s\n",
server_id_str(tmp_ctx, &rec->header->from),
server_id_str(tmp_ctx, &rec->header->to),
- rec->header->msg_type,
+ rec->header->msg_type,
nt_errstr(status)));
talloc_free(tmp_ctx);
}
@@ -313,17 +313,17 @@ static void imessaging_recv_handler(struct imessaging_context *msg)
/* see how many bytes are in the next packet */
status = socket_pending(msg->sock, &msize);
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(0,("socket_pending failed in messaging - %s\n",
+ DEBUG(0,("socket_pending failed in messaging - %s\n",
nt_errstr(status)));
return;
}
-
+
packet = data_blob_talloc(msg, NULL, msize);
if (packet.data == NULL) {
/* assume this is temporary and retry */
return;
}
-
+
status = socket_recv(msg->sock, packet.data, msize, &msize);
if (!NT_STATUS_IS_OK(status)) {
data_blob_free(&packet);
@@ -349,7 +349,7 @@ static void imessaging_recv_handler(struct imessaging_context *msg)
rec->retries = 0;
if (msize != sizeof(*rec->header) + rec->header->length) {
- DEBUG(0,("messaging: bad message header size %d should be %d\n",
+ DEBUG(0,("messaging: bad message header size %d should be %d\n",
rec->header->length, (int)(msize - sizeof(*rec->header))));
talloc_free(rec);
return;
@@ -444,7 +444,7 @@ void imessaging_deregister(struct imessaging_context *msg, uint32_t msg_type, vo
struct dispatch_fn *d, *next;
if (msg_type >= msg->num_types) {
- d = (struct dispatch_fn *)idr_find(msg->dispatch_tree,
+ d = (struct dispatch_fn *)idr_find(msg->dispatch_tree,
msg_type);
if (!d) return;
idr_remove(msg->dispatch_tree, msg_type);
@@ -493,7 +493,7 @@ NTSTATUS imessaging_send(struct imessaging_context *msg, struct server_id server
rec->header->to = server;
rec->header->length = dlength;
if (dlength != 0) {
- memcpy(rec->packet.data + sizeof(*rec->header),
+ memcpy(rec->packet.data + sizeof(*rec->header),
data->data, dlength);
}
@@ -622,11 +622,11 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
return NULL;
}
- /* by stealing here we ensure that the socket is cleaned up (and even
+ /* by stealing here we ensure that the socket is cleaned up (and even
deleted) on exit */
talloc_steal(msg, msg->sock);
- path = socket_address_from_strings(msg, msg->sock->backend_name,
+ path = socket_address_from_strings(msg, msg->sock->backend_name,
msg->path, 0);
if (!path) {
talloc_free(msg);
@@ -651,7 +651,7 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
if (auto_remove) {
talloc_set_destructor(msg, imessaging_cleanup);
}
-
+
imessaging_register(msg, NULL, MSG_PING, ping_message);
imessaging_register(msg, NULL, MSG_IRPC, irpc_handler);
IRPC_REGISTER(msg, irpc, IRPC_UPTIME, irpc_uptime, msg);
@@ -659,8 +659,8 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
return msg;
}
-/*
- A hack, for the short term until we get 'client only' messaging in place
+/*
+ A hack, for the short term until we get 'client only' messaging in place
*/
struct imessaging_context *imessaging_client_init(TALLOC_CTX *mem_ctx,
struct loadparm_context *lp_ctx,
@@ -694,7 +694,7 @@ struct irpc_list {
register a irpc server function
*/
NTSTATUS irpc_register(struct imessaging_context *msg_ctx,
- const struct ndr_interface_table *table,
+ const struct ndr_interface_table *table,
int callnum, irpc_function_t fn, void *private_data)
{
struct irpc_list *irpc;
@@ -903,7 +903,7 @@ static struct tdb_wrap *irpc_namedb_open(struct imessaging_context *msg_ctx)
talloc_free(path);
return t;
}
-
+
/*
add a string name that this irpc server can be called on
@@ -1099,7 +1099,7 @@ void irpc_remove_name(struct imessaging_context *msg_ctx, const char *name)
for (i=0;i<count;i++) {
if (cluster_id_equal(&ids[i], &msg_ctx->server_id)) {
if (i < count-1) {
- memmove(ids+i, ids+i+1,
+ memmove(ids+i, ids+i+1,
sizeof(struct server_id) * (count-(i+1)));
}
rec.dsize -= sizeof(struct server_id);
--
1.7.9.5
From 32eccfaac84677b6a6b834523374fb1cc8cfb8e4 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 13:32:16 +0000
Subject: [PATCH 02/26] lib: Pull up lp_ctx use one level
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/tdb_wrap/tdb_wrap.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/lib/tdb_wrap/tdb_wrap.c b/lib/tdb_wrap/tdb_wrap.c
index 312d17f..4b5b8f2 100644
--- a/lib/tdb_wrap/tdb_wrap.c
+++ b/lib/tdb_wrap/tdb_wrap.c
@@ -88,8 +88,7 @@ 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,
- struct loadparm_context *lp_ctx)
+ mode_t mode)
{
struct tdb_wrap_private *result;
struct tdb_logging_context lctx;
@@ -103,22 +102,6 @@ static struct tdb_wrap_private *tdb_wrap_private_open(TALLOC_CTX *mem_ctx,
goto fail;
}
- if (!lpcfg_use_mmap(lp_ctx)) {
- tdb_flags |= TDB_NOMMAP;
- }
-
- if ((hash_size == 0) && (name != NULL)) {
- const char *base;
- base = strrchr_m(name, '/');
-
- if (base != NULL) {
- base += 1;
- } else {
- base = name;
- }
- hash_size = lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
- }
-
lctx.log_fn = tdb_wrap_log;
lctx.log_private = NULL;
@@ -167,8 +150,25 @@ struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx,
}
if (w == NULL) {
+ if (!lpcfg_use_mmap(lp_ctx)) {
+ tdb_flags |= TDB_NOMMAP;
+ }
+
+ if ((hash_size == 0) && (name != NULL)) {
+ const char *base;
+ base = strrchr_m(name, '/');
+
+ if (base != NULL) {
+ base += 1;
+ } else {
+ base = name;
+ }
+ hash_size = lpcfg_parm_int(lp_ctx, NULL,
+ "tdb_hashsize", base, 0);
+ }
+
w = tdb_wrap_private_open(result, name, hash_size, tdb_flags,
- open_flags, mode, lp_ctx);
+ open_flags, mode);
} else {
/*
* Correctly use talloc_reference: The tdb will be
--
1.7.9.5
From b2b8d59fefe3e2783c89c909016c2c91a6a9309c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 13:36:48 +0000
Subject: [PATCH 03/26] lib: Add interim tdb_wrap_open_ without lp_ctx
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/tdb_wrap/tdb_wrap.c | 49 +++++++++++++++++++++++++++--------------------
lib/tdb_wrap/tdb_wrap.h | 3 +++
2 files changed, 31 insertions(+), 21 deletions(-)
diff --git a/lib/tdb_wrap/tdb_wrap.c b/lib/tdb_wrap/tdb_wrap.c
index 4b5b8f2..cf24b97 100644
--- a/lib/tdb_wrap/tdb_wrap.c
+++ b/lib/tdb_wrap/tdb_wrap.c
@@ -123,10 +123,9 @@ fail:
wrapped connection to a tdb database
to close just talloc_free() the tdb_wrap pointer
*/
-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,
- struct loadparm_context *lp_ctx)
+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)
{
struct tdb_wrap *result;
struct tdb_wrap_private *w;
@@ -150,23 +149,6 @@ struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx,
}
if (w == NULL) {
- if (!lpcfg_use_mmap(lp_ctx)) {
- tdb_flags |= TDB_NOMMAP;
- }
-
- if ((hash_size == 0) && (name != NULL)) {
- const char *base;
- base = strrchr_m(name, '/');
-
- if (base != NULL) {
- base += 1;
- } else {
- base = name;
- }
- hash_size = lpcfg_parm_int(lp_ctx, NULL,
- "tdb_hashsize", base, 0);
- }
-
w = tdb_wrap_private_open(result, name, hash_size, tdb_flags,
open_flags, mode);
} else {
@@ -194,3 +176,28 @@ fail:
return NULL;
}
+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,
+ struct loadparm_context *lp_ctx)
+{
+ if (!lpcfg_use_mmap(lp_ctx)) {
+ tdb_flags |= TDB_NOMMAP;
+ }
+
+ if ((hash_size == 0) && (name != NULL)) {
+ const char *base;
+ base = strrchr_m(name, '/');
+
+ if (base != NULL) {
+ base += 1;
+ } else {
+ base = name;
+ }
+ hash_size = lpcfg_parm_int(lp_ctx, NULL,
+ "tdb_hashsize", base, 0);
+ }
+
+ return tdb_wrap_open_(mem_ctx, name, hash_size, tdb_flags, open_flags,
+ mode);
+}
diff --git a/lib/tdb_wrap/tdb_wrap.h b/lib/tdb_wrap/tdb_wrap.h
index 3e1fb83..54d9a0a 100644
--- a/lib/tdb_wrap/tdb_wrap.h
+++ b/lib/tdb_wrap/tdb_wrap.h
@@ -37,6 +37,9 @@ struct tdb_wrap {
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);
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,
--
1.7.9.5
From 91069c0f289d225d9eb6ef6056d2282b800a4dba Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:04:41 +0000
Subject: [PATCH 04/26] param: Add lpcfg_tdb_hash_size()
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/param/loadparm.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index 51053ba..9ad14d8 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -2778,3 +2778,21 @@ bool lpcfg_server_signing_allowed(struct loadparm_context *lp_ctx, bool *mandato
return allowed;
}
+
+int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
+{
+ const char *base;
+
+ if (name == NULL) {
+ return 0;
+ }
+
+ base = strrchr_m(name, '/');
+ if (base != NULL) {
+ base += 1;
+ } else {
+ base = name;
+ }
+ return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
+
+}
--
1.7.9.5
From 04645d9737175b11f2fe304c0aa2f8b744d44162 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:06:08 +0000
Subject: [PATCH 05/26] param: Add lpcfg_tdb_flags()
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/param/loadparm.c | 9 +++++++++
lib/param/wscript_build | 2 +-
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index 9ad14d8..fd5e5e3 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -66,6 +66,7 @@
#include "lib/param/s3_param.h"
#include "lib/util/bitmap.h"
#include "libcli/smb/smb_constants.h"
+#include "tdb.h"
#define standard_sub_basic talloc_strdup
@@ -2796,3 +2797,11 @@ int lpcfg_tdb_hash_size(struct loadparm_context *lp_ctx, const char *name)
return lpcfg_parm_int(lp_ctx, NULL, "tdb_hashsize", base, 0);
}
+
+int lpcfg_tdb_flags(struct loadparm_context *lp_ctx, int tdb_flags)
+{
+ if (!lpcfg_use_mmap(lp_ctx)) {
+ tdb_flags |= TDB_NOMMAP;
+ }
+ return tdb_flags;
+}
diff --git a/lib/param/wscript_build b/lib/param/wscript_build
index 8fe751c..3c72a73 100644
--- a/lib/param/wscript_build
+++ b/lib/param/wscript_build
@@ -33,7 +33,7 @@ bld.SAMBA_LIBRARY('samba-hostconfig',
source='loadparm.c generic.c util.c',
pc_files='samba-hostconfig.pc',
vnum='0.0.1',
- deps='DYNCONFIG server-role',
+ deps='DYNCONFIG server-role tdb',
public_deps='samba-util param_local.h',
public_headers='param.h',
autoproto='param_proto.h'
--
1.7.9.5
From ce7b344780534b6a0c7dcd26adde82c744a1723f Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:08:40 +0000
Subject: [PATCH 06/26] secrets: Avoid passing lp_ctx to tdb_wrap_open in
randseed_init
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/param/secrets.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/source4/param/secrets.c b/source4/param/secrets.c
index aaf6259..e27524e 100644
--- a/source4/param/secrets.c
+++ b/source4/param/secrets.c
@@ -59,7 +59,10 @@ 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, lp_ctx);
+ tdb = tdb_wrap_open_(mem_ctx, fname,
+ lpcfg_tdb_hash_size(lp_ctx, fname),
+ lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT),
+ O_RDWR|O_CREAT, 0600);
if (!tdb) {
DEBUG(0,("Failed to open %s\n", fname));
--
1.7.9.5
From 848f5f404413445e4fb37e401b1e2c32e2535ca2 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:11:21 +0000
Subject: [PATCH 07/26] dsdb: Avoid passing lp_ctx to tdb_wrap_open in
schema_metadata_open
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/dsdb/samdb/ldb_modules/schema_load.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/source4/dsdb/samdb/ldb_modules/schema_load.c b/source4/dsdb/samdb/ldb_modules/schema_load.c
index 93e8e97..2e9eb5c 100644
--- a/source4/dsdb/samdb/ldb_modules/schema_load.c
+++ b/source4/dsdb/samdb/ldb_modules/schema_load.c
@@ -90,9 +90,9 @@ static int schema_metadata_open(struct ldb_module *module)
lp_ctx = talloc_get_type_abort(ldb_get_opaque(ldb, "loadparm"),
struct loadparm_context);
- data->metadata = tdb_wrap_open(data, filename, 10,
- TDB_DEFAULT, open_flags, 0660,
- lp_ctx);
+ data->metadata = tdb_wrap_open_(data, filename, 10,
+ lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT),
+ open_flags, 0660);
if (data->metadata == NULL) {
talloc_free(tmp_ctx);
return LDB_ERR_OPERATIONS_ERROR;
--
1.7.9.5
From aff2d64ba3c1d8d9c51d9cda05de42d9ce337ed6 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:12:24 +0000
Subject: [PATCH 08/26] dsdb: Avoid passing lp_ctx to tdb_wrap_open in
partition_metadata_open
Signed-off-by: Volker Lendecke <vl at samba.org>
---
.../dsdb/samdb/ldb_modules/partition_metadata.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/source4/dsdb/samdb/ldb_modules/partition_metadata.c b/source4/dsdb/samdb/ldb_modules/partition_metadata.c
index b3b5744..8441b13 100644
--- a/source4/dsdb/samdb/ldb_modules/partition_metadata.c
+++ b/source4/dsdb/samdb/ldb_modules/partition_metadata.c
@@ -240,9 +240,9 @@ static int partition_metadata_open(struct ldb_module *module, bool create)
lp_ctx = talloc_get_type_abort(ldb_get_opaque(ldb, "loadparm"),
struct loadparm_context);
- data->metadata->db = tdb_wrap_open(data->metadata, filename, 10,
- TDB_DEFAULT, open_flags, 0660,
- lp_ctx);
+ data->metadata->db = tdb_wrap_open_(
+ data->metadata, filename, 10,
+ lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT), open_flags, 0660);
if (data->metadata->db == NULL) {
talloc_free(tmp_ctx);
if (create) {
--
1.7.9.5
From 61feba1425b570db08b7e09fda16771a728a4b67 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:14:45 +0000
Subject: [PATCH 09/26] torture: Avoid passing lp_ctx to tdb_wrap_open in
test_tdb_speed
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/torture/local/dbspeed.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/source4/torture/local/dbspeed.c b/source4/torture/local/dbspeed.c
index 51ea8ea..27d1e0c 100644
--- a/source4/torture/local/dbspeed.c
+++ b/source4/torture/local/dbspeed.c
@@ -64,8 +64,9 @@ 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, torture->lp_ctx);
+ tdbw = tdb_wrap_open_(tmp_ctx, "test.tdb", 10000,
+ lpcfg_tdb_flags(torture->lp_ctx, 0),
+ O_RDWR|O_CREAT|O_TRUNC, 0600);
if (!tdbw) {
torture_result(torture, TORTURE_FAIL, "Failed to open test.tdb");
goto failed;
--
1.7.9.5
From 5997d47bc031311170eff5ee36eb7845eba27d2e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:17:07 +0000
Subject: [PATCH 10/26] ntvfs: Avoid passing lp_ctx to tdb_wrap_open in
pvfs_setup_options
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/ntvfs/posix/vfs_posix.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/source4/ntvfs/posix/vfs_posix.c b/source4/ntvfs/posix/vfs_posix.c
index afa3f23..a9ba44f 100644
--- a/source4/ntvfs/posix/vfs_posix.c
+++ b/source4/ntvfs/posix/vfs_posix.c
@@ -120,9 +120,10 @@ static void pvfs_setup_options(struct pvfs_state *pvfs)
/* allow xattrs to be stored in a external tdb */
eadb = share_string_option(pvfs, scfg, PVFS_EADB, NULL);
if (eadb != NULL) {
- pvfs->ea_db = tdb_wrap_open(pvfs, eadb, 50000,
- TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
- pvfs->ntvfs->ctx->lp_ctx);
+ pvfs->ea_db = tdb_wrap_open_(
+ pvfs, eadb, 50000,
+ lpcfg_tdb_flags(pvfs->ntvfs->ctx->lp_ctx, TDB_DEFAULT),
+ O_RDWR|O_CREAT, 0600);
TALLOC_FREE(eadb);
if (pvfs->ea_db != NULL) {
pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
--
1.7.9.5
From 915bac4577f54220c7f36c2a9ded38d8b22f3a7d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:19:16 +0000
Subject: [PATCH 11/26] ntvfs: Avoid passing lp_ctx to tdb_wrap_open in
py_wrap_getxattr
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/ntvfs/posix/python/pyposix_eadb.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/source4/ntvfs/posix/python/pyposix_eadb.c b/source4/ntvfs/posix/python/pyposix_eadb.c
index 48310cc..d891a27 100644
--- a/source4/ntvfs/posix/python/pyposix_eadb.c
+++ b/source4/ntvfs/posix/python/pyposix_eadb.c
@@ -83,8 +83,11 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
return NULL;
mem_ctx = talloc_new(NULL);
- eadb = tdb_wrap_open(mem_ctx, tdbname, 50000,
- TDB_DEFAULT, O_RDWR|O_CREAT, 0600, py_default_loadparm_context(mem_ctx));
+ eadb = tdb_wrap_open_(
+ mem_ctx, tdbname, 50000,
+ lpcfg_tdb_flags(py_default_loadparm_context(mem_ctx),
+ TDB_DEFAULT),
+ O_RDWR|O_CREAT, 0600);
if (eadb == NULL) {
PyErr_SetFromErrno(PyExc_IOError);
talloc_free(mem_ctx);
--
1.7.9.5
From 55fcdfc14518f86f29023f372fdbbcca090c28d0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:20:44 +0000
Subject: [PATCH 12/26] imessaging: Avoid passing lp_ctx to tdb_wrap_open in
irpc_namedb_open
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/lib/messaging/messaging.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index 7a92eb0..e182acd 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -899,7 +899,10 @@ 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, msg_ctx->lp_ctx);
+ t = tdb_wrap_open_(msg_ctx, path,
+ lpcfg_tdb_hash_size(msg_ctx->lp_ctx, path),
+ lpcfg_tdb_flags(msg_ctx->lp_ctx, 0),
+ O_RDWR|O_CREAT, 0660);
talloc_free(path);
return t;
}
--
1.7.9.5
From 9453029ade87cddca3cbfb7b15b29dc59dbcec12 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:26:24 +0000
Subject: [PATCH 13/26] dbwrap: Avoid passing lp_ctx to tdb_wrap_open in
db_open_tdb
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/dbwrap/dbwrap_tdb.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lib/dbwrap/dbwrap_tdb.c b/lib/dbwrap/dbwrap_tdb.c
index 1b061e3..82a9916 100644
--- a/lib/dbwrap/dbwrap_tdb.c
+++ b/lib/dbwrap/dbwrap_tdb.c
@@ -25,6 +25,7 @@
#include "lib/util/util_tdb.h"
#include "system/filesys.h"
#include "ccan/str/str.h"
+#include "lib/param/param.h"
struct db_tdb_ctx {
struct tdb_wrap *wtdb;
@@ -427,8 +428,13 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
}
result->lock_order = lock_order;
- db_tdb->wtdb = tdb_wrap_open(db_tdb, name, hash_size, tdb_flags,
- open_flags, mode, lp_ctx);
+ if (hash_size == 0) {
+ hash_size = lpcfg_tdb_hash_size(lp_ctx, name);
+ }
+
+ db_tdb->wtdb = tdb_wrap_open_(db_tdb, name, hash_size,
+ lpcfg_tdb_flags(lp_ctx, tdb_flags),
+ open_flags, mode);
if (db_tdb->wtdb == NULL) {
DEBUG(3, ("Could not open tdb: %s\n", strerror(errno)));
goto fail;
--
1.7.9.5
From 98c056954c705a2435de476642aad21dcf70be0d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:35:31 +0000
Subject: [PATCH 14/26] messaging: Avoid passing lp_ctx to tdb_wrap_open in
messaging_tdb_init
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/messages_local.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c
index acc5ba6..295646a 100644
--- a/source3/lib/messages_local.c
+++ b/source3/lib/messages_local.c
@@ -92,6 +92,7 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx,
struct messaging_tdb_context *ctx;
struct loadparm_context *lp_ctx;
static bool have_context = false;
+ const char *fname;
if (have_context) {
DEBUG(0, ("No two messaging contexts per process\n"));
@@ -122,9 +123,14 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx,
ctx->msg_ctx = msg_ctx;
ctx->have_context = &have_context;
- 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, lp_ctx);
+ fname = lock_path("messages.tdb");
+
+ ctx->tdb = tdb_wrap_open_(
+ ctx, fname, lpcfg_tdb_hash_size(lp_ctx, fname),
+ lpcfg_tdb_flags(lp_ctx, TDB_CLEAR_IF_FIRST|TDB_DEFAULT|
+ TDB_VOLATILE| TDB_INCOMPATIBLE_HASH),
+ O_RDWR|O_CREAT,0600);
+
talloc_unlink(result, lp_ctx);
if (!ctx->tdb) {
--
1.7.9.5
From a4a70d5a3bbf388850e03d6358cd9d4419614501 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:35:31 +0000
Subject: [PATCH 15/26] messaging: Avoid passing lp_ctx to tdb_wrap_open in
messaging_tdb_parent_init
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/messages_local.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c
index 295646a..1a3f3b2 100644
--- a/source3/lib/messages_local.c
+++ b/source3/lib/messages_local.c
@@ -174,6 +174,7 @@ bool messaging_tdb_parent_init(TALLOC_CTX *mem_ctx)
{
struct tdb_wrap *db;
struct loadparm_context *lp_ctx;
+ const char *fname;
lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_helpers());
if (lp_ctx == NULL) {
@@ -187,9 +188,12 @@ bool messaging_tdb_parent_init(TALLOC_CTX *mem_ctx)
* work.
*/
- 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, lp_ctx);
+ fname = lock_path("messages.tdb");
+ db = tdb_wrap_open_(
+ mem_ctx, fname, lpcfg_tdb_hash_size(lp_ctx, fname),
+ lpcfg_tdb_flags(lp_ctx, TDB_CLEAR_IF_FIRST|TDB_DEFAULT|
+ TDB_VOLATILE|TDB_INCOMPATIBLE_HASH),
+ O_RDWR|O_CREAT,0600);
talloc_unlink(mem_ctx, lp_ctx);
if (db == NULL) {
DEBUG(1, ("could not open messaging.tdb: %s\n",
--
1.7.9.5
From 17eb9b81ed20e68c8c4472f834a7ab9ed7d81a51 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:28:57 +0000
Subject: [PATCH 16/26] vfs: Avoid passing lp_ctx to tdb_wrap_open in
posix_eadb_init
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/modules/vfs_posix_eadb.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/source3/modules/vfs_posix_eadb.c b/source3/modules/vfs_posix_eadb.c
index d188780..7f65bea 100644
--- a/source3/modules/vfs_posix_eadb.c
+++ b/source3/modules/vfs_posix_eadb.c
@@ -256,9 +256,9 @@ static bool posix_eadb_init(int snum, struct tdb_wrap **p_db)
lp_ctx = loadparm_init_s3(NULL, loadparm_s3_helpers());
become_root();
- db = tdb_wrap_open(NULL, eadb, 50000,
- TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
- lp_ctx);
+ db = tdb_wrap_open_(NULL, eadb, 50000,
+ lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT),
+ O_RDWR|O_CREAT, 0600);
unbecome_root();
talloc_unlink(NULL, lp_ctx);
--
1.7.9.5
From 6e440e5507cb240eaa0f44f4f86952b7794a0e08 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:31:16 +0000
Subject: [PATCH 17/26] serverid: Avoid passing lp_ctx to tdb_wrap_open in
serverid_parent_init
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/serverid.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c
index 5d59818..4253da6 100644
--- a/source3/lib/serverid.c
+++ b/source3/lib/serverid.c
@@ -43,6 +43,7 @@ bool serverid_parent_init(TALLOC_CTX *mem_ctx)
{
struct tdb_wrap *db;
struct loadparm_context *lp_ctx;
+ const char *fname;
lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_helpers());
if (lp_ctx == NULL) {
@@ -56,9 +57,14 @@ bool serverid_parent_init(TALLOC_CTX *mem_ctx)
* work.
*/
- 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, lp_ctx);
+ fname = lock_path("serverid.tdb");
+
+ db = tdb_wrap_open_(mem_ctx, fname,
+ lpcfg_tdb_hash_size(lp_ctx, fname),
+ lpcfg_tdb_flags(lp_ctx,
+ TDB_DEFAULT|TDB_CLEAR_IF_FIRST|
+ TDB_INCOMPATIBLE_HASH),
+ O_RDWR|O_CREAT, 0644);
talloc_unlink(mem_ctx, lp_ctx);
if (db == NULL) {
DEBUG(1, ("could not open serverid.tdb: %s\n",
--
1.7.9.5
From a6f133620a03392cf297307bb2c9c904dcf2702c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:32:58 +0000
Subject: [PATCH 18/26] dbwrap: Avoid passing lp_ctx to tdb_wrap_open in
db_open_ctdb
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/dbwrap/dbwrap_ctdb.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index b113344..32d0446 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -1661,8 +1661,13 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
lp_ctx = loadparm_init_s3(db_path, loadparm_s3_helpers());
- db_ctdb->wtdb = tdb_wrap_open(db_ctdb, db_path, hash_size, tdb_flags,
- O_RDWR, 0, lp_ctx);
+ if (hash_size == 0) {
+ hash_size = lpcfg_tdb_hash_size(lp_ctx, db_path);
+ }
+
+ db_ctdb->wtdb = tdb_wrap_open_(db_ctdb, db_path, hash_size,
+ lpcfg_tdb_flags(lp_ctx, tdb_flags),
+ O_RDWR, 0);
talloc_unlink(db_path, lp_ctx);
if (db_ctdb->wtdb == NULL) {
DEBUG(0, ("Could not open tdb %s: %s\n", db_path, strerror(errno)));
--
1.7.9.5
From 2ca22c7f98379c38c3949f49a718382c43233c3b Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:35:31 +0000
Subject: [PATCH 19/26] mutex: Avoid passing lp_ctx to tdb_wrap_open in
grab_named_mutex
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/server_mutex.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c
index c86047b..24a301b 100644
--- a/source3/lib/server_mutex.c
+++ b/source3/lib/server_mutex.c
@@ -48,6 +48,8 @@ struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name,
{
struct named_mutex *result;
struct loadparm_context *lp_ctx;
+ const char *fname;
+
result = talloc(mem_ctx, struct named_mutex);
if (result == NULL) {
DEBUG(0, ("talloc failed\n"));
@@ -68,11 +70,15 @@ struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name,
return NULL;
}
- result->tdb = tdb_wrap_open(result, lock_path("mutex.tdb"), 0,
- TDB_DEFAULT |
- TDB_CLEAR_IF_FIRST |
- TDB_INCOMPATIBLE_HASH,
- O_RDWR|O_CREAT, 0600, lp_ctx);
+ fname = lock_path("mutex.tdb");
+
+ result->tdb = tdb_wrap_open_(result, fname,
+ lpcfg_tdb_hash_size(lp_ctx, fname),
+ lpcfg_tdb_flags(lp_ctx,
+ TDB_DEFAULT |
+ TDB_CLEAR_IF_FIRST |
+ TDB_INCOMPATIBLE_HASH),
+ O_RDWR|O_CREAT, 0600);
talloc_unlink(result, lp_ctx);
if (result->tdb == NULL) {
DEBUG(1, ("Could not open mutex.tdb: %s\n",
--
1.7.9.5
From e77521ca45d9be7eaae4f29975bd7fa45b82c7a1 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:19:16 +0000
Subject: [PATCH 20/26] ntvfs: Avoid passing lp_ctx to tdb_wrap_open in
py_wrap_setxattr
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/ntvfs/posix/python/pyposix_eadb.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/source4/ntvfs/posix/python/pyposix_eadb.c b/source4/ntvfs/posix/python/pyposix_eadb.c
index d891a27..c04d329 100644
--- a/source4/ntvfs/posix/python/pyposix_eadb.c
+++ b/source4/ntvfs/posix/python/pyposix_eadb.c
@@ -50,9 +50,11 @@ 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,
- py_default_loadparm_context(mem_ctx));
+ eadb = tdb_wrap_open_(
+ mem_ctx, tdbname, 50000,
+ lpcfg_tdb_flags(py_default_loadparm_context(mem_ctx),
+ TDB_DEFAULT),
+ O_RDWR|O_CREAT, 0600);
if (eadb == NULL) {
PyErr_SetFromErrno(PyExc_IOError);
--
1.7.9.5
From adf27235051e66c3069bfbf9e8a1622125e312da Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 26 Mar 2014 14:41:03 +0000
Subject: [PATCH 21/26] tdb_wrap: Remove tdb_wrap_open_ again
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/dbwrap/dbwrap_tdb.c | 6 ++--
lib/tdb_wrap/tdb_wrap.c | 32 ++------------------
lib/tdb_wrap/tdb_wrap.h | 6 +---
source3/lib/dbwrap/dbwrap_ctdb.c | 6 ++--
source3/lib/messages_local.c | 4 +--
source3/lib/server_mutex.c | 14 ++++-----
source3/lib/serverid.c | 12 ++++----
source3/modules/vfs_posix_eadb.c | 6 ++--
.../dsdb/samdb/ldb_modules/partition_metadata.c | 2 +-
source4/dsdb/samdb/ldb_modules/schema_load.c | 6 ++--
source4/lib/messaging/messaging.c | 8 ++---
source4/ntvfs/posix/python/pyposix_eadb.c | 4 +--
source4/ntvfs/posix/vfs_posix.c | 2 +-
source4/param/secrets.c | 8 ++---
source4/torture/local/dbspeed.c | 6 ++--
15 files changed, 46 insertions(+), 76 deletions(-)
diff --git a/lib/dbwrap/dbwrap_tdb.c b/lib/dbwrap/dbwrap_tdb.c
index 82a9916..a76d90f 100644
--- a/lib/dbwrap/dbwrap_tdb.c
+++ b/lib/dbwrap/dbwrap_tdb.c
@@ -432,9 +432,9 @@ struct db_context *db_open_tdb(TALLOC_CTX *mem_ctx,
hash_size = lpcfg_tdb_hash_size(lp_ctx, name);
}
- db_tdb->wtdb = tdb_wrap_open_(db_tdb, name, hash_size,
- lpcfg_tdb_flags(lp_ctx, tdb_flags),
- open_flags, mode);
+ db_tdb->wtdb = tdb_wrap_open(db_tdb, name, hash_size,
+ lpcfg_tdb_flags(lp_ctx, tdb_flags),
+ open_flags, mode);
if (db_tdb->wtdb == NULL) {
DEBUG(3, ("Could not open tdb: %s\n", strerror(errno)));
goto fail;
diff --git a/lib/tdb_wrap/tdb_wrap.c b/lib/tdb_wrap/tdb_wrap.c
index cf24b97..970c91f 100644
--- a/lib/tdb_wrap/tdb_wrap.c
+++ b/lib/tdb_wrap/tdb_wrap.c
@@ -123,9 +123,9 @@ fail:
wrapped connection to a tdb database
to close just talloc_free() the tdb_wrap pointer
*/
-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)
+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)
{
struct tdb_wrap *result;
struct tdb_wrap_private *w;
@@ -175,29 +175,3 @@ fail:
TALLOC_FREE(result);
return NULL;
}
-
-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,
- struct loadparm_context *lp_ctx)
-{
- if (!lpcfg_use_mmap(lp_ctx)) {
- tdb_flags |= TDB_NOMMAP;
- }
-
- if ((hash_size == 0) && (name != NULL)) {
- const char *base;
- base = strrchr_m(name, '/');
-
- if (base != NULL) {
- base += 1;
- } else {
- base = name;
- }
- hash_size = lpcfg_parm_int(lp_ctx, NULL,
- "tdb_hashsize", base, 0);
- }
-
- return tdb_wrap_open_(mem_ctx, name, hash_size, tdb_flags, open_flags,
- mode);
-}
diff --git a/lib/tdb_wrap/tdb_wrap.h b/lib/tdb_wrap/tdb_wrap.h
index 54d9a0a..e44aed6 100644
--- a/lib/tdb_wrap/tdb_wrap.h
+++ b/lib/tdb_wrap/tdb_wrap.h
@@ -37,12 +37,8 @@ struct tdb_wrap {
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);
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,
- struct loadparm_context *lp_ctx);
+ int open_flags, mode_t mode);
#endif /* _TDB_WRAP_H_ */
diff --git a/source3/lib/dbwrap/dbwrap_ctdb.c b/source3/lib/dbwrap/dbwrap_ctdb.c
index 32d0446..7cf90ce 100644
--- a/source3/lib/dbwrap/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap/dbwrap_ctdb.c
@@ -1665,9 +1665,9 @@ struct db_context *db_open_ctdb(TALLOC_CTX *mem_ctx,
hash_size = lpcfg_tdb_hash_size(lp_ctx, db_path);
}
- db_ctdb->wtdb = tdb_wrap_open_(db_ctdb, db_path, hash_size,
- lpcfg_tdb_flags(lp_ctx, tdb_flags),
- O_RDWR, 0);
+ db_ctdb->wtdb = tdb_wrap_open(db_ctdb, db_path, hash_size,
+ lpcfg_tdb_flags(lp_ctx, tdb_flags),
+ O_RDWR, 0);
talloc_unlink(db_path, lp_ctx);
if (db_ctdb->wtdb == NULL) {
DEBUG(0, ("Could not open tdb %s: %s\n", db_path, strerror(errno)));
diff --git a/source3/lib/messages_local.c b/source3/lib/messages_local.c
index 1a3f3b2..1fe89c3 100644
--- a/source3/lib/messages_local.c
+++ b/source3/lib/messages_local.c
@@ -125,7 +125,7 @@ NTSTATUS messaging_tdb_init(struct messaging_context *msg_ctx,
fname = lock_path("messages.tdb");
- ctx->tdb = tdb_wrap_open_(
+ ctx->tdb = tdb_wrap_open(
ctx, fname, lpcfg_tdb_hash_size(lp_ctx, fname),
lpcfg_tdb_flags(lp_ctx, TDB_CLEAR_IF_FIRST|TDB_DEFAULT|
TDB_VOLATILE| TDB_INCOMPATIBLE_HASH),
@@ -189,7 +189,7 @@ bool messaging_tdb_parent_init(TALLOC_CTX *mem_ctx)
*/
fname = lock_path("messages.tdb");
- db = tdb_wrap_open_(
+ db = tdb_wrap_open(
mem_ctx, fname, lpcfg_tdb_hash_size(lp_ctx, fname),
lpcfg_tdb_flags(lp_ctx, TDB_CLEAR_IF_FIRST|TDB_DEFAULT|
TDB_VOLATILE|TDB_INCOMPATIBLE_HASH),
diff --git a/source3/lib/server_mutex.c b/source3/lib/server_mutex.c
index 24a301b..43cf77b 100644
--- a/source3/lib/server_mutex.c
+++ b/source3/lib/server_mutex.c
@@ -72,13 +72,13 @@ struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name,
fname = lock_path("mutex.tdb");
- result->tdb = tdb_wrap_open_(result, fname,
- lpcfg_tdb_hash_size(lp_ctx, fname),
- lpcfg_tdb_flags(lp_ctx,
- TDB_DEFAULT |
- TDB_CLEAR_IF_FIRST |
- TDB_INCOMPATIBLE_HASH),
- O_RDWR|O_CREAT, 0600);
+ result->tdb = tdb_wrap_open(result, fname,
+ lpcfg_tdb_hash_size(lp_ctx, fname),
+ lpcfg_tdb_flags(lp_ctx,
+ TDB_DEFAULT |
+ TDB_CLEAR_IF_FIRST |
+ TDB_INCOMPATIBLE_HASH),
+ O_RDWR|O_CREAT, 0600);
talloc_unlink(result, lp_ctx);
if (result->tdb == NULL) {
DEBUG(1, ("Could not open mutex.tdb: %s\n",
diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c
index 4253da6..48b09f7 100644
--- a/source3/lib/serverid.c
+++ b/source3/lib/serverid.c
@@ -59,12 +59,12 @@ bool serverid_parent_init(TALLOC_CTX *mem_ctx)
fname = lock_path("serverid.tdb");
- db = tdb_wrap_open_(mem_ctx, fname,
- lpcfg_tdb_hash_size(lp_ctx, fname),
- lpcfg_tdb_flags(lp_ctx,
- TDB_DEFAULT|TDB_CLEAR_IF_FIRST|
- TDB_INCOMPATIBLE_HASH),
- O_RDWR|O_CREAT, 0644);
+ db = tdb_wrap_open(mem_ctx, fname,
+ lpcfg_tdb_hash_size(lp_ctx, fname),
+ lpcfg_tdb_flags(lp_ctx,
+ TDB_DEFAULT|TDB_CLEAR_IF_FIRST|
+ TDB_INCOMPATIBLE_HASH),
+ O_RDWR|O_CREAT, 0644);
talloc_unlink(mem_ctx, lp_ctx);
if (db == NULL) {
DEBUG(1, ("could not open serverid.tdb: %s\n",
diff --git a/source3/modules/vfs_posix_eadb.c b/source3/modules/vfs_posix_eadb.c
index 7f65bea..27996db 100644
--- a/source3/modules/vfs_posix_eadb.c
+++ b/source3/modules/vfs_posix_eadb.c
@@ -256,9 +256,9 @@ static bool posix_eadb_init(int snum, struct tdb_wrap **p_db)
lp_ctx = loadparm_init_s3(NULL, loadparm_s3_helpers());
become_root();
- db = tdb_wrap_open_(NULL, eadb, 50000,
- lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT),
- O_RDWR|O_CREAT, 0600);
+ db = tdb_wrap_open(NULL, eadb, 50000,
+ lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT),
+ O_RDWR|O_CREAT, 0600);
unbecome_root();
talloc_unlink(NULL, lp_ctx);
diff --git a/source4/dsdb/samdb/ldb_modules/partition_metadata.c b/source4/dsdb/samdb/ldb_modules/partition_metadata.c
index 8441b13..1db800e 100644
--- a/source4/dsdb/samdb/ldb_modules/partition_metadata.c
+++ b/source4/dsdb/samdb/ldb_modules/partition_metadata.c
@@ -240,7 +240,7 @@ static int partition_metadata_open(struct ldb_module *module, bool create)
lp_ctx = talloc_get_type_abort(ldb_get_opaque(ldb, "loadparm"),
struct loadparm_context);
- data->metadata->db = tdb_wrap_open_(
+ data->metadata->db = tdb_wrap_open(
data->metadata, filename, 10,
lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT), open_flags, 0660);
if (data->metadata->db == NULL) {
diff --git a/source4/dsdb/samdb/ldb_modules/schema_load.c b/source4/dsdb/samdb/ldb_modules/schema_load.c
index 2e9eb5c..25a7801 100644
--- a/source4/dsdb/samdb/ldb_modules/schema_load.c
+++ b/source4/dsdb/samdb/ldb_modules/schema_load.c
@@ -90,9 +90,9 @@ static int schema_metadata_open(struct ldb_module *module)
lp_ctx = talloc_get_type_abort(ldb_get_opaque(ldb, "loadparm"),
struct loadparm_context);
- data->metadata = tdb_wrap_open_(data, filename, 10,
- lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT),
- open_flags, 0660);
+ data->metadata = tdb_wrap_open(data, filename, 10,
+ lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT),
+ open_flags, 0660);
if (data->metadata == NULL) {
talloc_free(tmp_ctx);
return LDB_ERR_OPERATIONS_ERROR;
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index e182acd..ba1c5bd 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -899,10 +899,10 @@ static struct tdb_wrap *irpc_namedb_open(struct imessaging_context *msg_ctx)
if (path == NULL) {
return NULL;
}
- t = tdb_wrap_open_(msg_ctx, path,
- lpcfg_tdb_hash_size(msg_ctx->lp_ctx, path),
- lpcfg_tdb_flags(msg_ctx->lp_ctx, 0),
- O_RDWR|O_CREAT, 0660);
+ t = tdb_wrap_open(msg_ctx, path,
+ lpcfg_tdb_hash_size(msg_ctx->lp_ctx, path),
+ lpcfg_tdb_flags(msg_ctx->lp_ctx, 0),
+ O_RDWR|O_CREAT, 0660);
talloc_free(path);
return t;
}
diff --git a/source4/ntvfs/posix/python/pyposix_eadb.c b/source4/ntvfs/posix/python/pyposix_eadb.c
index c04d329..9db0ddb 100644
--- a/source4/ntvfs/posix/python/pyposix_eadb.c
+++ b/source4/ntvfs/posix/python/pyposix_eadb.c
@@ -50,7 +50,7 @@ static PyObject *py_wrap_setxattr(PyObject *self, PyObject *args)
blob.length = blobsize;
mem_ctx = talloc_new(NULL);
- eadb = tdb_wrap_open_(
+ eadb = tdb_wrap_open(
mem_ctx, tdbname, 50000,
lpcfg_tdb_flags(py_default_loadparm_context(mem_ctx),
TDB_DEFAULT),
@@ -85,7 +85,7 @@ static PyObject *py_wrap_getxattr(PyObject *self, PyObject *args)
return NULL;
mem_ctx = talloc_new(NULL);
- eadb = tdb_wrap_open_(
+ eadb = tdb_wrap_open(
mem_ctx, tdbname, 50000,
lpcfg_tdb_flags(py_default_loadparm_context(mem_ctx),
TDB_DEFAULT),
diff --git a/source4/ntvfs/posix/vfs_posix.c b/source4/ntvfs/posix/vfs_posix.c
index a9ba44f..304a9ff 100644
--- a/source4/ntvfs/posix/vfs_posix.c
+++ b/source4/ntvfs/posix/vfs_posix.c
@@ -120,7 +120,7 @@ static void pvfs_setup_options(struct pvfs_state *pvfs)
/* allow xattrs to be stored in a external tdb */
eadb = share_string_option(pvfs, scfg, PVFS_EADB, NULL);
if (eadb != NULL) {
- pvfs->ea_db = tdb_wrap_open_(
+ pvfs->ea_db = tdb_wrap_open(
pvfs, eadb, 50000,
lpcfg_tdb_flags(pvfs->ntvfs->ctx->lp_ctx, TDB_DEFAULT),
O_RDWR|O_CREAT, 0600);
diff --git a/source4/param/secrets.c b/source4/param/secrets.c
index e27524e..92e338a 100644
--- a/source4/param/secrets.c
+++ b/source4/param/secrets.c
@@ -59,10 +59,10 @@ 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,
- lpcfg_tdb_hash_size(lp_ctx, fname),
- lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT),
- O_RDWR|O_CREAT, 0600);
+ tdb = tdb_wrap_open(mem_ctx, fname,
+ lpcfg_tdb_hash_size(lp_ctx, fname),
+ lpcfg_tdb_flags(lp_ctx, TDB_DEFAULT),
+ O_RDWR|O_CREAT, 0600);
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 27d1e0c..185faec 100644
--- a/source4/torture/local/dbspeed.c
+++ b/source4/torture/local/dbspeed.c
@@ -64,9 +64,9 @@ 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,
- lpcfg_tdb_flags(torture->lp_ctx, 0),
- O_RDWR|O_CREAT|O_TRUNC, 0600);
+ tdbw = tdb_wrap_open(tmp_ctx, "test.tdb", 10000,
+ lpcfg_tdb_flags(torture->lp_ctx, 0),
+ O_RDWR|O_CREAT|O_TRUNC, 0600);
if (!tdbw) {
torture_result(torture, TORTURE_FAIL, "Failed to open test.tdb");
goto failed;
--
1.7.9.5
From 1f75571b6d8017a5aebeeda50bd2f555a0927c7e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 27 Mar 2014 10:07:34 +0000
Subject: [PATCH 22/26] messaging4: Add "goto fail" to imessaging_init
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/lib/messaging/messaging.c | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index ba1c5bd..b1b0003 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -590,24 +590,21 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
/* setup a handler for messages from other cluster nodes, if appropriate */
status = cluster_message_init(msg, server_id, cluster_message_handler);
if (!NT_STATUS_IS_OK(status)) {
- talloc_free(msg);
- return NULL;
+ goto fail;
}
/* create the messaging directory if needed */
msg->lp_ctx = talloc_reference(msg, lp_ctx);
if (!msg->lp_ctx) {
- talloc_free(msg);
- return NULL;
+ goto fail;
}
msg->base_path = lpcfg_imessaging_path(msg, lp_ctx);
ok = directory_create_or_exist_strict(msg->base_path, geteuid(), 0700);
if (!ok) {
- talloc_free(msg);
- return NULL;
+ goto fail;
}
msg->path = imessaging_path(msg, server_id);
@@ -618,8 +615,7 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
status = socket_create("unix", SOCKET_TYPE_DGRAM, &msg->sock, 0);
if (!NT_STATUS_IS_OK(status)) {
- talloc_free(msg);
- return NULL;
+ goto fail;
}
/* by stealing here we ensure that the socket is cleaned up (and even
@@ -629,15 +625,13 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
path = socket_address_from_strings(msg, msg->sock->backend_name,
msg->path, 0);
if (!path) {
- talloc_free(msg);
- return NULL;
+ goto fail;
}
status = socket_listen(msg->sock, path, 50, 0);
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("Unable to setup messaging listener for '%s':%s\n", msg->path, nt_errstr(status)));
- talloc_free(msg);
- return NULL;
+ goto fail;
}
/* it needs to be non blocking for sends */
@@ -657,6 +651,9 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
IRPC_REGISTER(msg, irpc, IRPC_UPTIME, irpc_uptime, msg);
return msg;
+fail:
+ talloc_free(msg);
+ return NULL;
}
/*
--
1.7.9.5
From 366d555e85b0d60420f2251431f2acee7ab5c66b Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 27 Mar 2014 10:08:55 +0000
Subject: [PATCH 23/26] messaging4: Add some NULL checks
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/lib/messaging/messaging.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index b1b0003..42e59a9 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -601,6 +601,9 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
}
msg->base_path = lpcfg_imessaging_path(msg, lp_ctx);
+ if (msg->base_path == NULL) {
+ goto fail;
+ }
ok = directory_create_or_exist_strict(msg->base_path, geteuid(), 0700);
if (!ok) {
@@ -608,9 +611,21 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
}
msg->path = imessaging_path(msg, server_id);
+ if (msg->path == NULL) {
+ goto fail;
+ }
+
msg->server_id = server_id;
msg->idr = idr_init(msg);
+ if (msg->idr == NULL) {
+ goto fail;
+ }
+
msg->dispatch_tree = idr_init(msg);
+ if (msg->dispatch_tree == NULL) {
+ goto fail;
+ }
+
msg->start_time = timeval_current();
status = socket_create("unix", SOCKET_TYPE_DGRAM, &msg->sock, 0);
--
1.7.9.5
From 2c94c8989bc8f47ad410f70329148b10723f0492 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 27 Mar 2014 10:16:08 +0000
Subject: [PATCH 24/26] messaging4: Store a names_db handle in the
imessaging_context
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/lib/messaging/messaging.c | 48 ++++++++++---------------------------
1 file changed, 12 insertions(+), 36 deletions(-)
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index 42e59a9..5933693 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -39,6 +39,8 @@
/* change the message version with any incompatible changes in the protocol */
#define IMESSAGING_VERSION 1
+static struct tdb_wrap *irpc_namedb_open(struct imessaging_context *msg_ctx);
+
/*
a pending irpc call
*/
@@ -65,6 +67,7 @@ struct imessaging_context {
struct irpc_list *irpc;
struct idr_context *idr;
const char **names;
+ struct tdb_wrap *names_db;
struct timeval start_time;
struct tevent_timer *retry_te;
struct {
@@ -628,6 +631,11 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
msg->start_time = timeval_current();
+ msg->names_db = irpc_namedb_open(msg);
+ if (msg->names_db == NULL) {
+ goto fail;
+ }
+
status = socket_create("unix", SOCKET_TYPE_DGRAM, &msg->sock, 0);
if (!NT_STATUS_IS_OK(status)) {
goto fail;
@@ -925,16 +933,12 @@ static struct tdb_wrap *irpc_namedb_open(struct imessaging_context *msg_ctx)
*/
NTSTATUS irpc_add_name(struct imessaging_context *msg_ctx, const char *name)
{
- struct tdb_wrap *t;
+ struct tdb_wrap *t = msg_ctx->names_db;
TDB_DATA rec;
int count;
NTSTATUS status = NT_STATUS_OK;
- t = irpc_namedb_open(msg_ctx);
- NT_STATUS_HAVE_NO_MEMORY(t);
-
if (tdb_lock_bystring(t->tdb, name) != 0) {
- talloc_free(t);
return NT_STATUS_LOCK_NOT_GRANTED;
}
rec = tdb_fetch_bystring(t->tdb, name);
@@ -943,7 +947,6 @@ NTSTATUS irpc_add_name(struct imessaging_context *msg_ctx, const char *name)
rec.dsize += sizeof(struct server_id);
if (rec.dptr == NULL) {
tdb_unlock_bystring(t->tdb, name);
- talloc_free(t);
return NT_STATUS_NO_MEMORY;
}
((struct server_id *)rec.dptr)[count] = msg_ctx->server_id;
@@ -952,7 +955,6 @@ NTSTATUS irpc_add_name(struct imessaging_context *msg_ctx, const char *name)
}
free(rec.dptr);
tdb_unlock_bystring(t->tdb, name);
- talloc_free(t);
msg_ctx->names = str_list_add(msg_ctx->names, name);
talloc_steal(msg_ctx, msg_ctx->names);
@@ -967,31 +969,23 @@ struct server_id *irpc_servers_byname(struct imessaging_context *msg_ctx,
TALLOC_CTX *mem_ctx,
const char *name)
{
- struct tdb_wrap *t;
+ struct tdb_wrap *t = msg_ctx->names_db;
TDB_DATA rec;
int count, i;
struct server_id *ret;
- t = irpc_namedb_open(msg_ctx);
- if (t == NULL) {
- return NULL;
- }
-
if (tdb_lock_bystring(t->tdb, name) != 0) {
- talloc_free(t);
return NULL;
}
rec = tdb_fetch_bystring(t->tdb, name);
if (rec.dptr == NULL) {
tdb_unlock_bystring(t->tdb, name);
- talloc_free(t);
return NULL;
}
count = rec.dsize / sizeof(struct server_id);
ret = talloc_array(mem_ctx, struct server_id, count+1);
if (ret == NULL) {
tdb_unlock_bystring(t->tdb, name);
- talloc_free(t);
return NULL;
}
for (i=0;i<count;i++) {
@@ -1000,7 +994,6 @@ struct server_id *irpc_servers_byname(struct imessaging_context *msg_ctx,
server_id_set_disconnected(&ret[i]);
free(rec.dptr);
tdb_unlock_bystring(t->tdb, name);
- talloc_free(t);
return ret;
}
@@ -1053,26 +1046,18 @@ static int all_servers_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data
struct irpc_name_records *irpc_all_servers(struct imessaging_context *msg_ctx,
TALLOC_CTX *mem_ctx)
{
- struct tdb_wrap *t;
+ struct tdb_wrap *t = msg_ctx->names_db;
int ret;
struct irpc_name_records *name_records = talloc_zero(mem_ctx, struct irpc_name_records);
if (name_records == NULL) {
return NULL;
}
- t = irpc_namedb_open(msg_ctx);
- if (t == NULL) {
- return NULL;
- }
-
ret = tdb_traverse_read(t->tdb, all_servers_func, name_records);
if (ret == -1) {
- talloc_free(t);
return NULL;
}
- talloc_free(t);
-
return name_records;
}
@@ -1081,33 +1066,25 @@ struct irpc_name_records *irpc_all_servers(struct imessaging_context *msg_ctx,
*/
void irpc_remove_name(struct imessaging_context *msg_ctx, const char *name)
{
- struct tdb_wrap *t;
+ struct tdb_wrap *t = msg_ctx->names_db;
TDB_DATA rec;
int count, i;
struct server_id *ids;
str_list_remove(msg_ctx->names, name);
- t = irpc_namedb_open(msg_ctx);
- if (t == NULL) {
- return;
- }
-
if (tdb_lock_bystring(t->tdb, name) != 0) {
- talloc_free(t);
return;
}
rec = tdb_fetch_bystring(t->tdb, name);
if (rec.dptr == NULL) {
tdb_unlock_bystring(t->tdb, name);
- talloc_free(t);
return;
}
count = rec.dsize / sizeof(struct server_id);
if (count == 0) {
free(rec.dptr);
tdb_unlock_bystring(t->tdb, name);
- talloc_free(t);
return;
}
ids = (struct server_id *)rec.dptr;
@@ -1124,7 +1101,6 @@ void irpc_remove_name(struct imessaging_context *msg_ctx, const char *name)
tdb_store_bystring(t->tdb, name, rec, 0);
free(rec.dptr);
tdb_unlock_bystring(t->tdb, name);
- talloc_free(t);
}
struct server_id imessaging_get_server_id(struct imessaging_context *msg_ctx)
--
1.7.9.5
From 6deaf4faf2ba406c07685eee2acf5182afcea672 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 27 Mar 2014 10:18:05 +0000
Subject: [PATCH 25/26] messaging4: Remove lp_ctx from imessaging_context
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/lib/messaging/messaging.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index 5933693..fbdfd95 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -39,7 +39,8 @@
/* change the message version with any incompatible changes in the protocol */
#define IMESSAGING_VERSION 1
-static struct tdb_wrap *irpc_namedb_open(struct imessaging_context *msg_ctx);
+static struct tdb_wrap *irpc_namedb_open(struct imessaging_context *msg_ctx,
+ struct loadparm_context *lp_ctx);
/*
a pending irpc call
@@ -58,7 +59,6 @@ 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;
@@ -598,11 +598,6 @@ 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) {
- goto fail;
- }
-
msg->base_path = lpcfg_imessaging_path(msg, lp_ctx);
if (msg->base_path == NULL) {
goto fail;
@@ -631,7 +626,7 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
msg->start_time = timeval_current();
- msg->names_db = irpc_namedb_open(msg);
+ msg->names_db = irpc_namedb_open(msg, lp_ctx);
if (msg->names_db == NULL) {
goto fail;
}
@@ -912,17 +907,16 @@ static int irpc_destructor(struct irpc_request *irpc)
/*
open the naming database
*/
-static struct tdb_wrap *irpc_namedb_open(struct imessaging_context *msg_ctx)
+static struct tdb_wrap *irpc_namedb_open(struct imessaging_context *msg_ctx,
+ struct loadparm_context *lp_ctx)
{
struct tdb_wrap *t;
char *path = talloc_asprintf(msg_ctx, "%s/names.tdb", msg_ctx->base_path);
if (path == NULL) {
return NULL;
}
- t = tdb_wrap_open(msg_ctx, path,
- lpcfg_tdb_hash_size(msg_ctx->lp_ctx, path),
- lpcfg_tdb_flags(msg_ctx->lp_ctx, 0),
- O_RDWR|O_CREAT, 0660);
+ t = tdb_wrap_open(msg_ctx, path, lpcfg_tdb_hash_size(lp_ctx, path),
+ lpcfg_tdb_flags(lp_ctx, 0), O_RDWR|O_CREAT, 0660);
talloc_free(path);
return t;
}
--
1.7.9.5
From 109ea0aadaa74c7347885b2325fc2f0f9398d468 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 27 Mar 2014 10:42:34 +0000
Subject: [PATCH 26/26] messaging4: Simplify irpc_namedb_open a bit
It does not really need the msg_ctx, and it also removes the implicit talloc
hierarchy.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/lib/messaging/messaging.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index fbdfd95..c33aae3 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -39,7 +39,7 @@
/* change the message version with any incompatible changes in the protocol */
#define IMESSAGING_VERSION 1
-static struct tdb_wrap *irpc_namedb_open(struct imessaging_context *msg_ctx,
+static struct tdb_wrap *irpc_namedb_open(TALLOC_CTX *mem_ctx, const char *base_path,
struct loadparm_context *lp_ctx);
/*
@@ -626,7 +626,7 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
msg->start_time = timeval_current();
- msg->names_db = irpc_namedb_open(msg, lp_ctx);
+ msg->names_db = irpc_namedb_open(msg, msg->base_path, lp_ctx);
if (msg->names_db == NULL) {
goto fail;
}
@@ -907,15 +907,15 @@ static int irpc_destructor(struct irpc_request *irpc)
/*
open the naming database
*/
-static struct tdb_wrap *irpc_namedb_open(struct imessaging_context *msg_ctx,
+static struct tdb_wrap *irpc_namedb_open(TALLOC_CTX *mem_ctx, const char *base_path,
struct loadparm_context *lp_ctx)
{
struct tdb_wrap *t;
- char *path = talloc_asprintf(msg_ctx, "%s/names.tdb", msg_ctx->base_path);
+ char *path = talloc_asprintf(mem_ctx, "%s/names.tdb", base_path);
if (path == NULL) {
return NULL;
}
- t = tdb_wrap_open(msg_ctx, path, lpcfg_tdb_hash_size(lp_ctx, path),
+ t = tdb_wrap_open(mem_ctx, path, lpcfg_tdb_hash_size(lp_ctx, path),
lpcfg_tdb_flags(lp_ctx, 0), O_RDWR|O_CREAT, 0660);
talloc_free(path);
return t;
--
1.7.9.5
More information about the samba-technical
mailing list