ctdb-tool: Update process-exists command to pass optional srvid
authorAmitay Isaacs <amitay@gmail.com>
Wed, 30 Aug 2017 06:29:01 +0000 (16:29 +1000)
committerMartin Schwenke <martins@samba.org>
Thu, 21 Sep 2017 06:53:26 +0000 (08:53 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13042

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/doc/ctdb.1.xml
ctdb/tools/ctdb.c

index c1d81071e58d2a91504e0a2cf4165811849ffd4e..8dfca3b1a498bd8bebab9fe869e8323667f1a0a3 100644 (file)
@@ -1681,9 +1681,13 @@ RUNNING
     </refsect2>
 
     <refsect2>
-      <title>process-exists <parameter>PID</parameter></title>
+      <title>process-exists <parameter>PID</parameter> <parameter>[SRVID]</parameter></title>
       <para>
-       This command checks if a specific process exists on the CTDB host. This is mainly used by Samba to check if remote instances of samba are still running or not.
+       This command checks if a specific process exists on the CTDB
+       host. This is mainly used by Samba to check if remote instances
+       of samba are still running or not.  When the optional SRVID
+       argument is specified, the command check if a specific process
+       exists on the CTDB host and has registered for specified SRVID.
       </para>
     </refsect2>
 
index 01edcf68e6bd0c025664137c05096cdd162058f4..f8f9a18fa7e2d65e197ebbb4c0f7f931d16ecc32 100644 (file)
@@ -1865,23 +1865,43 @@ static int control_process_exists(TALLOC_CTX *mem_ctx,
                                  int argc, const char **argv)
 {
        pid_t pid;
+       uint64_t srvid = 0;
        int ret, status;
 
-       if (argc != 1) {
+       if (argc != 1 && argc != 2) {
                usage("process-exists");
        }
 
        pid = atoi(argv[0]);
-       ret = ctdb_ctrl_process_exists(mem_ctx, ctdb->ev, ctdb->client,
+       if (argc == 2) {
+               srvid = strtoull(argv[1], NULL, 0);
+       }
+
+       if (srvid == 0) {
+               ret = ctdb_ctrl_process_exists(mem_ctx, ctdb->ev, ctdb->client,
                                       ctdb->cmd_pnn, TIMEOUT(), pid, &status);
+       } else {
+               struct ctdb_pid_srvid pid_srvid;
+
+               pid_srvid.pid = pid;
+               pid_srvid.srvid = srvid;
+
+               ret = ctdb_ctrl_check_pid_srvid(mem_ctx, ctdb->ev,
+                                               ctdb->client, ctdb->cmd_pnn,
+                                               TIMEOUT(), &pid_srvid,
+                                               &status);
+       }
+
        if (ret != 0) {
                return ret;
        }
 
-       if (status == 0) {
-               printf("PID %u exists\n", pid);
+       if (srvid == 0) {
+               printf("PID %d %s\n", pid,
+                      (status == 0 ? "exists" : "does not exist"));
        } else {
-               printf("PID %u does not exist\n", pid);
+               printf("PID %d with SRVID 0x%"PRIx64" %s\n", pid, srvid,
+                      (status == 0 ? "exists" : "does not exist"));
        }
        return status;
 }
@@ -5886,7 +5906,7 @@ static const struct ctdb_cmd {
        { "setifacelink", control_setifacelink, false, true,
                "set interface link status", "<iface> up|down" },
        { "process-exists", control_process_exists, false, true,
-               "check if a process exists on a node",  "<pid>" },
+               "check if a process exists on a node",  "<pid> [<srvid>]" },
        { "getdbmap", control_getdbmap, false, true,
                "show attached databases", NULL },
        { "getdbstatus", control_getdbstatus, false, true,