create a helper function that converts a ctdb instance in daemon mode to become
authorroot <root@rcn1.VSOFS1.COM>
Mon, 23 Mar 2009 01:37:30 +0000 (12:37 +1100)
committerroot <root@rcn1.VSOFS1.COM>
Mon, 23 Mar 2009 01:37:30 +0000 (12:37 +1100)
a ctdb client instance.

use this from the recovery daemon child process to switch to client mode
and connect back to the main daemon

client/ctdb_client.c
include/ctdb.h
server/ctdb_recoverd.c

index 16fc03b48ab2a6878cd8104c6ae9aa90d0071e8a..1f68c242a13e6a1f1c4daa73679ceb443d993bff 100644 (file)
@@ -3472,3 +3472,39 @@ int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb)
 
        return 0;
 }
+
+/* when forking the main daemon and the child process needs to connect back
+ * to the daemon as a client process, this function can be used to change
+ * the ctdb context from daemon into client mode
+ */
+int switch_from_server_to_client(struct ctdb_context *ctdb)
+{
+       int ret;
+
+       /* shutdown the transport */
+       if (ctdb->methods) {
+               ctdb->methods->shutdown(ctdb);
+       }
+
+       /* get a new event context */
+       talloc_free(ctdb->ev);
+       ctdb->ev = event_context_init(ctdb);
+
+       close(ctdb->daemon.sd);
+       ctdb->daemon.sd = -1;
+
+       /* the client does not need to be realtime */
+       if (ctdb->do_setsched) {
+               ctdb_restore_scheduler(ctdb);
+       }
+
+       /* initialise ctdb */
+       ret = ctdb_socket_connect(ctdb);
+       if (ret != 0) {
+               DEBUG(DEBUG_ALERT, (__location__ " Failed to init ctdb client\n"));
+               return -1;
+       }
+
+        return 0;
+}
+
index 2ec477f608f591b31a6a37412ad1b9b512e45345..f0f510abd32e44c5222db0eaf836600900c619e3 100644 (file)
@@ -610,4 +610,6 @@ int ctdb_transaction_commit(struct ctdb_transaction_handle *h);
 
 int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb);
 
+int switch_from_server_to_client(struct ctdb_context *ctdb);
+
 #endif
index 540749d12f8317e32e1e81d6e7cfab438c78187b..28be460c98f250cf677cd8732c392192ce06b2ab 100644 (file)
@@ -2906,7 +2906,6 @@ static void recd_sig_child_handler(struct event_context *ev,
  */
 int ctdb_start_recoverd(struct ctdb_context *ctdb)
 {
-       int ret;
        int fd[2];
        struct signal_event *se;
 
@@ -2931,35 +2930,16 @@ int ctdb_start_recoverd(struct ctdb_context *ctdb)
 
        close(fd[1]);
 
-       /* shutdown the transport */
-       if (ctdb->methods) {
-               ctdb->methods->shutdown(ctdb);
-       }
-
-       /* get a new event context */
-       talloc_free(ctdb->ev);
-       ctdb->ev = event_context_init(ctdb);
-
-       event_add_fd(ctdb->ev, ctdb, fd[0], EVENT_FD_READ|EVENT_FD_AUTOCLOSE, 
-                    ctdb_recoverd_parent, &fd[0]);     
-
-       close(ctdb->daemon.sd);
-       ctdb->daemon.sd = -1;
-
        srandom(getpid() ^ time(NULL));
 
-       /* the recovery daemon does not need to be realtime */
-       if (ctdb->do_setsched) {
-               ctdb_restore_scheduler(ctdb);
-       }
-
-       /* initialise ctdb */
-       ret = ctdb_socket_connect(ctdb);
-       if (ret != 0) {
-               DEBUG(DEBUG_ALERT, (__location__ " Failed to init ctdb\n"));
+       if (switch_from_server_to_client(ctdb) != 0) {
+               DEBUG(DEBUG_CRIT, (__location__ "ERROR: failed to switch recovery daemon into client mode. shutting down.\n"));
                exit(1);
        }
 
+       event_add_fd(ctdb->ev, ctdb, fd[0], EVENT_FD_READ|EVENT_FD_AUTOCLOSE, 
+                    ctdb_recoverd_parent, &fd[0]);     
+
        /* set up a handler to pick up sigchld */
        se = event_add_signal(ctdb->ev, ctdb,
                                     SIGCHLD, 0,