[Ocfs2-tools-commits] jlbec commits r1075 - branches/global-heartbeat/o2cb_ctl

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Sep 6 20:55:25 CDT 2005


Author: jlbec
Date: 2005-09-06 20:55:25 -0500 (Tue, 06 Sep 2005)
New Revision: 1075

Modified:
   branches/global-heartbeat/o2cb_ctl/o2cb_ctl.c
   branches/global-heartbeat/o2cb_ctl/o2cb_hb_config.c
Log:

o Teach o2cb_ctl to only check the online version if it will be
  doing online work.
o Validate cluster before modifying heartbeat.conf



Modified: branches/global-heartbeat/o2cb_ctl/o2cb_ctl.c
===================================================================
--- branches/global-heartbeat/o2cb_ctl/o2cb_ctl.c	2005-09-07 01:19:28 UTC (rev 1074)
+++ branches/global-heartbeat/o2cb_ctl/o2cb_ctl.c	2005-09-07 01:55:25 UTC (rev 1075)
@@ -1375,11 +1375,14 @@
     if (rc)
         print_usage(rc);
 
-    ret = o2cb_init();
-    if (ret) {
-	com_err(PROGNAME, ret, "Cannot initialize cluster\n");
-	rc = -EINVAL;
-	goto out_error;
+    if (ctxt.oc_modify_running)
+    {
+        ret = o2cb_init();
+        if (ret) {
+	        com_err(PROGNAME, ret, "Cannot initialize cluster\n");
+	        rc = -EINVAL;
+	        goto out_error;
+        }
     }
 
     switch (ctxt.oc_op)

Modified: branches/global-heartbeat/o2cb_ctl/o2cb_hb_config.c
===================================================================
--- branches/global-heartbeat/o2cb_ctl/o2cb_hb_config.c	2005-09-07 01:19:28 UTC (rev 1074)
+++ branches/global-heartbeat/o2cb_ctl/o2cb_hb_config.c	2005-09-07 01:55:25 UTC (rev 1075)
@@ -210,6 +210,72 @@
     return rc;
 }
 
+static gint cluster_exists(const gchar *cluster)
+{
+    gint rc;
+    gint ret;
+    gchar *argv[] =
+    {
+        "o2cb_ctl",
+        "-I",
+        "-o",
+        "-t",
+        "cluster",
+        "-n",
+        (gchar *)cluster,
+        NULL
+    };
+    GError *error = NULL;
+    gchar *errput = NULL;
+
+    if (!g_spawn_sync(NULL, argv, NULL,
+                      G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL,
+                      NULL, NULL,
+                      NULL, &errput, &ret, &error))
+    {
+        fprintf(stderr, PROGNAME ": Could not run \"%s\": %s\n",
+                argv[0], error->message);
+        goto out;
+    }
+
+    if (WIFEXITED(ret))
+    {
+        rc = WEXITSTATUS(ret);
+        if (rc)
+        {
+            if (strstr(errput, "does not exist"))
+            {
+                fprintf(stderr,
+                        PROGNAME ": Cluster \"%s\" does not exist.\n",
+                        cluster);
+            }
+            else
+            {
+                fprintf(stderr, PROGNAME ": Error from \"%s\": %s\n",
+                        argv[0], errput);
+            }
+        }
+    }
+    else if (WIFSIGNALED(ret))
+    {
+        rc = -EINTR;
+        fprintf(stderr,
+                PROGNAME ": Program \"%s\" exited with signal %d\n",
+                argv[0], WTERMSIG(ret));
+    }
+    else
+    {
+        rc = -ENXIO;
+        fprintf(stderr,
+                PROGNAME ": Program \"%s\" exited unexpectedly\n",
+                argv[0]);
+    }
+
+out:
+
+    return rc;
+}
+
 static gint hbconf_mode_show_one(HBConfContext *ctxt,
                                  JConfigStanza *cfs)
 {
@@ -258,6 +324,9 @@
         goto out_error;
     }
 
+    if (ctxt->c_print_mode == HBCONF_PRINT_PARSEABLE)
+        fprintf(stdout, "#cluster:mode\n");
+
     rc = -ENOENT;
     if (!j_iterator_has_more(iter))
     {
@@ -267,11 +336,6 @@
                     PROGNAME ": Cluster \"%s\" does not exist.\n",
                     ctxt->c_cluster);
         }
-        else
-        {
-            fprintf(stderr,
-                    PROGNAME ": There are no configured clusters.\n");
-        }
 
         goto out_iter;
     }
@@ -321,6 +385,10 @@
         print_usage(-EINVAL);
     }
 
+    rc = cluster_exists(ctxt->c_cluster);
+    if (rc)
+        goto out;
+
     rc = -ENOMEM;
     iter = j_config_get_stanzas(ctxt->c_cf, "cluster", &match, 1);
     if (!iter)
@@ -453,6 +521,10 @@
         print_usage(-EINVAL);
     }
 
+    rc = cluster_exists(ctxt->c_cluster);
+    if (rc)
+        goto out;
+
     if (ctxt->c_dev)
     {
         rc = dev_to_uuid(ctxt->c_layout, ctxt->c_dev, &ctxt->c_uuid);



More information about the Ocfs2-tools-commits mailing list