summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2008-02-04 17:51:38 +1100
committerAndrew Bartlett <abartlet@samba.org>2008-02-04 17:51:38 +1100
commit77f71c1b65358723771354fd9ff1dc418b227ccc (patch)
tree2b1b96d1f3dcd55997fd6d48e75085ff506fb0a2
parent23d681caf9c1186999ac676d70a1eb0e8a43e358 (diff)
downloadsamba-77f71c1b65358723771354fd9ff1dc418b227ccc.tar.gz
samba-77f71c1b65358723771354fd9ff1dc418b227ccc.tar.bz2
samba-77f71c1b65358723771354fd9ff1dc418b227ccc.zip
Rework cluster_id() to take an additional argument, as we need
<node>.<pid>.<fd> to be unique in a prefork process environment. Andrew Bartlett and David Disseldorp (This used to be commit 931994a7f185bbc98924823e9e8cef1011dd0957)
-rw-r--r--source4/cluster/cluster.c6
-rw-r--r--source4/cluster/cluster.h2
-rw-r--r--source4/cluster/cluster_private.h2
-rw-r--r--source4/cluster/ctdb/ctdb_cluster.c5
-rw-r--r--source4/cluster/local.c5
-rw-r--r--source4/lib/messaging/messaging.c8
-rw-r--r--source4/lib/messaging/tests/irpc.c10
-rw-r--r--source4/lib/messaging/tests/messaging.c10
-rw-r--r--source4/librpc/idl/misc.idl3
-rw-r--r--source4/scripting/ejs/smbcalls_rpc.c2
-rw-r--r--source4/smbd/service_stream.c16
11 files changed, 42 insertions, 27 deletions
diff --git a/source4/cluster/cluster.c b/source4/cluster/cluster.c
index 6bac1dcbe5..cc61974cbd 100644
--- a/source4/cluster/cluster.c
+++ b/source4/cluster/cluster.c
@@ -47,12 +47,12 @@ static void cluster_init(void)
}
/*
- server a server_id for the local node
+ create a server_id for the local node
*/
-struct server_id cluster_id(uint32_t id)
+struct server_id cluster_id(uint64_t id, uint32_t id2)
{
cluster_init();
- return ops->cluster_id(ops, id);
+ return ops->cluster_id(ops, id, id2);
}
diff --git a/source4/cluster/cluster.h b/source4/cluster/cluster.h
index 7cd31282cc..203aef439c 100644
--- a/source4/cluster/cluster.h
+++ b/source4/cluster/cluster.h
@@ -36,7 +36,7 @@ struct messaging_context;
typedef void (*cluster_message_fn_t)(struct messaging_context *, DATA_BLOB);
/* prototypes */
-struct server_id cluster_id(uint32_t id);
+struct server_id cluster_id(uint64_t id, uint32_t id2);
const char *cluster_id_string(TALLOC_CTX *mem_ctx, struct server_id id);
struct tdb_wrap *cluster_tdb_tmp_open(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, const char *dbname, int flags);
void *cluster_backend_handle(void);
diff --git a/source4/cluster/cluster_private.h b/source4/cluster/cluster_private.h
index 1c895b8640..79394b46db 100644
--- a/source4/cluster/cluster_private.h
+++ b/source4/cluster/cluster_private.h
@@ -23,7 +23,7 @@
#define _CLUSTER_PRIVATE_H_
struct cluster_ops {
- struct server_id (*cluster_id)(struct cluster_ops *ops, uint32_t id);
+ struct server_id (*cluster_id)(struct cluster_ops *ops, uint64_t id, uint32_t id2);
const char *(*cluster_id_string)(struct cluster_ops *ops,
TALLOC_CTX *, struct server_id );
struct tdb_wrap *(*cluster_tdb_tmp_open)(struct cluster_ops *,
diff --git a/source4/cluster/ctdb/ctdb_cluster.c b/source4/cluster/ctdb/ctdb_cluster.c
index 53df1e968e..ce295c4474 100644
--- a/source4/cluster/ctdb/ctdb_cluster.c
+++ b/source4/cluster/ctdb/ctdb_cluster.c
@@ -52,13 +52,14 @@ struct cluster_state {
/*
return a server_id for a ctdb node
*/
-static struct server_id ctdb_id(struct cluster_ops *ops, uint32_t id)
+static struct server_id ctdb_id(struct cluster_ops *ops, uint64_t id, uint32_t id2)
{
struct cluster_state *state = (struct cluster_state *)ops->private;
struct ctdb_context *ctdb = state->ctdb;
struct server_id server_id;
server_id.node = ctdb_get_vnn(ctdb);
server_id.id = id;
+ server_id.id2 = id2;
return server_id;
}
@@ -69,7 +70,7 @@ static struct server_id ctdb_id(struct cluster_ops *ops, uint32_t id)
static const char *ctdb_id_string(struct cluster_ops *ops,
TALLOC_CTX *mem_ctx, struct server_id id)
{
- return talloc_asprintf(mem_ctx, "%u.%u", id.node, id.id);
+ return talloc_asprintf(mem_ctx, "%u.%llu.%u", id.node, (unsigned long long)id.id, id.id2);
}
/*
diff --git a/source4/cluster/local.c b/source4/cluster/local.c
index 539e47d271..96636927f1 100644
--- a/source4/cluster/local.c
+++ b/source4/cluster/local.c
@@ -31,11 +31,12 @@
/*
server a server_id for the local node
*/
-static struct server_id local_id(struct cluster_ops *ops, uint32_t id)
+static struct server_id local_id(struct cluster_ops *ops, uint64_t id, uint32_t id2)
{
struct server_id server_id;
ZERO_STRUCT(server_id);
server_id.id = id;
+ server_id.id2 = id2;
return server_id;
}
@@ -46,7 +47,7 @@ static struct server_id local_id(struct cluster_ops *ops, uint32_t id)
static const char *local_id_string(struct cluster_ops *ops,
TALLOC_CTX *mem_ctx, struct server_id id)
{
- return talloc_asprintf(mem_ctx, "%u.%u", id.node, id.id);
+ return talloc_asprintf(mem_ctx, "%u.%llu.%u", id.node, (unsigned long long)id.id, id.id2);
}
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c
index 811d5a85bf..9cb10f961c 100644
--- a/source4/lib/messaging/messaging.c
+++ b/source4/lib/messaging/messaging.c
@@ -263,8 +263,10 @@ static void messaging_send_handler(struct messaging_context *msg)
}
rec->retries = 0;
if (!NT_STATUS_IS_OK(status)) {
- DEBUG(1,("messaging: Lost message from %u to %u of type %u - %s\n",
- rec->header->from.id, rec->header->to.id, rec->header->msg_type,
+ DEBUG(1,("messaging: Lost message from %s to %s of type %u - %s\n",
+ cluster_id_string(debug_ctx(), rec->header->from),
+ cluster_id_string(debug_ctx(), rec->header->to),
+ rec->header->msg_type,
nt_errstr(status)));
}
DLIST_REMOVE(msg->pending, rec);
@@ -1051,7 +1053,7 @@ struct server_id *irpc_servers_byname(struct messaging_context *msg_ctx,
for (i=0;i<count;i++) {
ret[i] = ((struct server_id *)rec.dptr)[i];
}
- ret[i] = cluster_id(0);
+ ret[i] = cluster_id(0, 0);
free(rec.dptr);
tdb_unlock_bystring(t->tdb, name);
talloc_free(t);
diff --git a/source4/lib/messaging/tests/irpc.c b/source4/lib/messaging/tests/irpc.c
index a2995fc983..d9b0548643 100644
--- a/source4/lib/messaging/tests/irpc.c
+++ b/source4/lib/messaging/tests/irpc.c
@@ -93,7 +93,7 @@ static bool test_addone(struct torture_context *test, const void *_data,
r.in.in_data = value;
test_debug = true;
- status = IRPC_CALL(data->msg_ctx1, cluster_id(MSG_ID2),
+ status = IRPC_CALL(data->msg_ctx1, cluster_id(0, MSG_ID2),
rpcecho, ECHO_ADDONE, &r, test);
test_debug = false;
torture_assert_ntstatus_ok(test, status, "AddOne failed");
@@ -122,7 +122,7 @@ static bool test_echodata(struct torture_context *tctx,
r.in.in_data = (unsigned char *)talloc_strdup(mem_ctx, "0123456789");
r.in.len = strlen((char *)r.in.in_data);
- status = IRPC_CALL(data->msg_ctx1, cluster_id(MSG_ID2),
+ status = IRPC_CALL(data->msg_ctx1, cluster_id(0, MSG_ID2),
rpcecho, ECHO_ECHODATA, &r,
mem_ctx);
torture_assert_ntstatus_ok(tctx, status, "EchoData failed");
@@ -180,7 +180,7 @@ static bool test_speed(struct torture_context *tctx,
while (timeval_elapsed(&tv) < timelimit) {
struct irpc_request *irpc;
- irpc = IRPC_CALL_SEND(data->msg_ctx1, cluster_id(MSG_ID2),
+ irpc = IRPC_CALL_SEND(data->msg_ctx1, cluster_id(0, MSG_ID2),
rpcecho, ECHO_ADDONE,
&r, mem_ctx);
torture_assert(tctx, irpc != NULL, "AddOne send failed");
@@ -221,7 +221,7 @@ static bool irpc_setup(struct torture_context *tctx, void **_data)
torture_assert(tctx, data->msg_ctx1 =
messaging_init(tctx,
lp_messaging_path(tctx, tctx->lp_ctx),
- cluster_id(MSG_ID1),
+ cluster_id(0, MSG_ID1),
lp_iconv_convenience(tctx->lp_ctx),
data->ev),
"Failed to init first messaging context");
@@ -229,7 +229,7 @@ static bool irpc_setup(struct torture_context *tctx, void **_data)
torture_assert(tctx, data->msg_ctx2 =
messaging_init(tctx,
lp_messaging_path(tctx, tctx->lp_ctx),
- cluster_id(MSG_ID2),
+ cluster_id(0, MSG_ID2),
lp_iconv_convenience(tctx->lp_ctx),
data->ev),
"Failed to init second messaging context");
diff --git a/source4/lib/messaging/tests/messaging.c b/source4/lib/messaging/tests/messaging.c
index 0df04bce2b..45b573518c 100644
--- a/source4/lib/messaging/tests/messaging.c
+++ b/source4/lib/messaging/tests/messaging.c
@@ -73,7 +73,7 @@ static bool test_ping_speed(struct torture_context *tctx)
msg_server_ctx = messaging_init(tctx,
lp_messaging_path(tctx, tctx->lp_ctx),
- cluster_id(1),
+ cluster_id(0, 1),
lp_iconv_convenience(tctx->lp_ctx),
ev);
@@ -84,7 +84,7 @@ static bool test_ping_speed(struct torture_context *tctx)
msg_client_ctx = messaging_init(tctx,
lp_messaging_path(tctx, tctx->lp_ctx),
- cluster_id(2),
+ cluster_id(0, 2),
lp_iconv_convenience(tctx->lp_ctx),
ev);
@@ -103,8 +103,8 @@ static bool test_ping_speed(struct torture_context *tctx)
data.data = discard_const_p(uint8_t, "testing");
data.length = strlen((const char *)data.data);
- status1 = messaging_send(msg_client_ctx, cluster_id(1), msg_ping, &data);
- status2 = messaging_send(msg_client_ctx, cluster_id(1), msg_ping, NULL);
+ status1 = messaging_send(msg_client_ctx, cluster_id(0, 1), msg_ping, &data);
+ status2 = messaging_send(msg_client_ctx, cluster_id(0, 1), msg_ping, NULL);
torture_assert_ntstatus_ok(tctx, status1, "msg1 failed");
ping_count++;
@@ -124,7 +124,7 @@ static bool test_ping_speed(struct torture_context *tctx)
}
torture_comment(tctx, "sending exit\n");
- messaging_send(msg_client_ctx, cluster_id(1), msg_exit, NULL);
+ messaging_send(msg_client_ctx, cluster_id(0, 1), msg_exit, NULL);
torture_assert_int_equal(tctx, ping_count, pong_count, "ping test failed");
diff --git a/source4/librpc/idl/misc.idl b/source4/librpc/idl/misc.idl
index 0861758187..8331977398 100644
--- a/source4/librpc/idl/misc.idl
+++ b/source4/librpc/idl/misc.idl
@@ -51,7 +51,8 @@ interface misc
/* id used to identify a endpoint, possibly in a cluster */
typedef [public] struct {
- uint32 id;
+ hyper id;
+ uint32 id2;
uint32 node;
} server_id;
}
diff --git a/source4/scripting/ejs/smbcalls_rpc.c b/source4/scripting/ejs/smbcalls_rpc.c
index 2bfc8b5883..44cfa16d7e 100644
--- a/source4/scripting/ejs/smbcalls_rpc.c
+++ b/source4/scripting/ejs/smbcalls_rpc.c
@@ -80,7 +80,7 @@ static int ejs_irpc_connect(MprVarHandle eid, int argc, char **argv)
for (i=0;i<10000;i++) {
p->msg_ctx = messaging_init(p,
lp_messaging_path(p, global_loadparm),
- cluster_id(EJS_ID_BASE + i),
+ cluster_id(EJS_ID_BASE, i),
lp_iconv_convenience(global_loadparm),
ev);
if (p->msg_ctx) break;
diff --git a/source4/smbd/service_stream.c b/source4/smbd/service_stream.c
index 0d6f1b7281..7e1f6493ee 100644
--- a/source4/smbd/service_stream.c
+++ b/source4/smbd/service_stream.c
@@ -136,7 +136,7 @@ NTSTATUS stream_new_connection_merge(struct event_context *ev,
srv_conn->private = private_data;
srv_conn->model_ops = model_ops;
srv_conn->socket = sock;
- srv_conn->server_id = cluster_id(0);
+ srv_conn->server_id = cluster_id(0, 0);
srv_conn->ops = stream_ops;
srv_conn->msg_ctx = msg_ctx;
srv_conn->event.ctx = ev;
@@ -274,8 +274,11 @@ NTSTATUS stream_setup_socket(struct event_context *event_context,
NT_STATUS_NOT_OK_RETURN(status);
}
- /* TODO: set socket ACL's here when they're implemented */
+ /* TODO: set socket ACL's (host allow etc) here when they're
+ * implemented */
+ /* Some sockets don't have a port, or are just described from
+ * the string. We are indicating this by having port == NULL */
if (!port) {
socket_address = socket_address_from_strings(stream_socket,
stream_socket->sock->backend_name,
@@ -314,9 +317,16 @@ NTSTATUS stream_setup_socket(struct event_context *event_context,
return status;
}
- /* we will close the socket using the events system */
+ /* By specifying EVENT_FD_AUTOCLOSE below, we indicate that we
+ * will close the socket using the events system. This avoids
+ * nasty interactions with waiting for talloc to close the socket. */
+
socket_set_flags(stream_socket->sock, SOCKET_FLAG_NOCLOSE);
+ /* Add the FD from the newly created socket into the event
+ * subsystem. it will call the accept handler whenever we get
+ * new connections */
+
event_add_fd(event_context, stream_socket->sock,
socket_get_fd(stream_socket->sock),
EVENT_FD_READ|EVENT_FD_AUTOCLOSE,