]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
add a call to register the pid for a messengin service
authorRonnie sahlberg <ronniesahlberg@gmail.com>
Tue, 10 Apr 2007 11:05:29 +0000 (21:05 +1000)
committerRonnie sahlberg <ronniesahlberg@gmail.com>
Tue, 10 Apr 2007 11:05:29 +0000 (21:05 +1000)
store this pid inside the client structure in the ctdb daemon

(This used to be ctdb commit d4499c5e0403b0348fa36b259164b1cbfcd671b8)

ctdb/common/ctdb_daemon.c
ctdb/include/ctdb.h
ctdb/include/ctdb_private.h
ctdb/tests/bench.sh
ctdb/tests/ctdb_bench.c

index 0908b8c99298d0860c8318f634e5cb042776c557..cfc283ce5a2ba06c5b5fa3f4d132a5b38f970f03 100644 (file)
@@ -58,6 +58,7 @@ static void set_non_blocking(int fd)
 struct ctdb_client {
        struct ctdb_context *ctdb;
        int fd;
+       uint32_t id;
        struct ctdb_queue *queue;
 };
 
@@ -138,6 +139,16 @@ static void client_request_call(struct ctdb_client *client, struct ctdb_req_call
 }
 
 
+
+/*
+   we have received a register message from hte client
+ */
+static void client_register_message(struct ctdb_client *client, struct ctdb_register_call *r)
+{
+       client->id = *((uint32_t *)r->data);
+}
+
+
 /* data contains a packet from the client */
 static void client_incoming_packet(struct ctdb_client *client, void *data, size_t nread)
 {
@@ -157,7 +168,9 @@ static void client_incoming_packet(struct ctdb_client *client, void *data, size_
        case CTDB_REQ_CALL:
                client_request_call(client, (struct ctdb_req_call *)hdr);
                break;
-
+       case CTDB_REGISTER_CALL:
+               client_register_message(client, (struct ctdb_register_call *)hdr);
+               break;
        }
 
        talloc_free(data);
@@ -576,5 +589,32 @@ struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct
        return state;
 }
 
+int ctdb_register_message_local_id(struct ctdb_context *ctdb, uint32_t id)
+{
+       int res;
+       struct ctdb_register_call rc;
+
+       if (!(ctdb->flags&CTDB_FLAG_DAEMON_MODE)) {
+               return 0;
+       }
+
+       /* if the domain socket is not yet open, open it */
+       if (ctdb->daemon.sd==-1) {
+               ux_socket_connect(ctdb);
+       }
+
+       ZERO_STRUCT(rc);
+       rc.hdr.ctdb_magic = CTDB_MAGIC;
+       rc.hdr.ctdb_version = CTDB_VERSION;
+       rc.hdr.operation = CTDB_REGISTER_CALL;
+       rc.datalen=4;
+       *((uint32_t *)rc.data) = id;
+       rc.hdr.length = offsetof(struct ctdb_register_call, data) + rc.datalen;
+
+/*XXX need to handle the case of partial writes    logic for partial writes in tcp/ctdb_tcp_node_write */
+       res = write(ctdb->daemon.sd, &rc, rc.hdr.length);
+
+       return 0;
+}
 
 
index e3d5b1f5aa70dd647cc6b46be167d15c6e94e2d8..74735a77b290609d0108808ce02afb76c879e452 100644 (file)
@@ -180,5 +180,11 @@ struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALL
  */
 int ctdb_record_store(struct ctdb_record_handle *rec, TDB_DATA data);
 
+/* when running in daemon mode this function is used by a client to tell 
+   ctdb daemon what its local identifier is.
+   when in non-daemon mode this is a noop.
+ */
+int ctdb_register_message_local_id(struct ctdb_context *ctdb, uint32_t id);
 
 #endif
index 792fb75ba4897eb7643838a70320f36912ccd4bd..1d390eb247cf2a073b8f13cb0c4433742a253c2e 100644 (file)
@@ -183,13 +183,14 @@ struct ctdb_call_state {
   operation IDs
 */
 enum ctdb_operation {
-       CTDB_REQ_CALL       = 0,
-       CTDB_REPLY_CALL     = 1,
-       CTDB_REPLY_REDIRECT = 2,
-       CTDB_REQ_DMASTER    = 3,
-       CTDB_REPLY_DMASTER  = 4,
-       CTDB_REPLY_ERROR    = 5,
-       CTDB_REQ_MESSAGE    = 6
+       CTDB_REQ_CALL         = 0,
+       CTDB_REPLY_CALL       = 1,
+       CTDB_REPLY_REDIRECT   = 2,
+       CTDB_REQ_DMASTER      = 3,
+       CTDB_REPLY_DMASTER    = 4,
+       CTDB_REPLY_ERROR      = 5,
+       CTDB_REGISTER_CALL    = 6,
+       CTDB_REQ_MESSAGE      = 7
 };
 
 #define CTDB_MAGIC 0x43544442 /* CTDB */
@@ -252,6 +253,12 @@ struct ctdb_reply_dmaster {
        uint8_t  data[1];
 };
 
+struct ctdb_register_call {
+       struct ctdb_req_header hdr;
+       uint32_t datalen;
+       uint8_t data[4];
+};
+
 struct ctdb_req_message {
        struct ctdb_req_header hdr;
        uint32_t srvid;
index 50e9e08f995dbc6aa85ea3b4aa960c0c69a7e815..b9b93b01b68c74f71794e16aa40e943bfab4bdd5 100755 (executable)
@@ -3,7 +3,7 @@
 killall -q ctdb_bench
 
 echo "Trying 2 nodes"
-bin/ctdb_bench --nlist tests/nodes.txt --listen 127.0.0.2:9001 $* &
-bin/ctdb_bench --nlist tests/nodes.txt --listen 127.0.0.1:9001 $*
+bin/ctdb_bench --nlist tests/nodes.txt --listen 127.0.0.2:9001 --pid=55 $* &
+bin/ctdb_bench --nlist tests/nodes.txt --listen 127.0.0.1:9001 --pid=66 $*
 
 killall -q ctdb_bench
index 368353877e36b2e5161a786ae70fd18d7d17ffe3..149382cd51476142f290c962a1ae3c3a68073320 100644 (file)
@@ -201,6 +201,7 @@ int main(int argc, const char *argv[])
        const char *myaddress = NULL;
        int self_connect=0;
        int daemon_mode=0;
+       int pid;
 
        struct poptOption popt_options[] = {
                POPT_AUTOHELP
@@ -212,6 +213,7 @@ int main(int argc, const char *argv[])
                { "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" },
                { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" },
                { "num-msgs", 'n', POPT_ARG_INT, &num_msgs, 0, "num_msgs", "integer" },
+               { "pid", 0, POPT_ARG_INT, &pid, 0, "pid", "integer" },
                POPT_TABLEEND
        };
        int opt;
@@ -296,6 +298,13 @@ int main(int argc, const char *argv[])
        /* start the protocol running */
        ret = ctdb_start(ctdb);
 
+       /* register our 'pid' so that ctdb knows who we are */
+       if (!pid) {
+               pid = getpid();
+               printf("no pid specified, using real pid:%d\n",pid);
+       }
+       ctdb_register_message_local_id(ctdb, pid);
+
        /* wait until all nodes are connected (should not be needed
           outside of test code) */
        ctdb_connect_wait(ctdb);