[Ocfs2-tools-commits] jlbec commits r535 - in branches/kabi: clusterbo libo2cb/include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Wed Jan 5 13:14:44 CST 2005


Author: jlbec
Date: 2005-01-05 13:14:42 -0600 (Wed, 05 Jan 2005)
New Revision: 535

Modified:
   branches/kabi/clusterbo/o2cb_config.c
   branches/kabi/clusterbo/o2cb_config.h
   branches/kabi/clusterbo/o2cb_ctl.c
   branches/kabi/libo2cb/include/o2cb_kabi.h
Log:

o Move actions to a processing stage.



Modified: branches/kabi/clusterbo/o2cb_config.c
===================================================================
--- branches/kabi/clusterbo/o2cb_config.c	2005-01-05 02:45:23 UTC (rev 534)
+++ branches/kabi/clusterbo/o2cb_config.c	2005-01-05 19:14:42 UTC (rev 535)
@@ -40,9 +40,11 @@
     guint c_num_nodes;
     GList *c_nodes;
     gboolean c_valid;
+    gboolean c_changed;
 };
 
 struct _O2CBNode {
+    O2CBConfig *n_config;
     guint n_number;
     gchar *n_name;
     gchar *n_addr;
@@ -231,7 +233,10 @@
             config = NULL;
         }
         else
+        {
+            config->c_changed = FALSE;
             config->c_valid = TRUE;
+        }
     }
 
     j_config_free(cf);
@@ -294,6 +299,9 @@
     gchar *count;
     GList *list;
 
+    if (!config->c_valid)
+        return -EINVAL;
+
     cf = j_config_parse_memory("", strlen(""));
     if (!cf)
         return -ENOMEM;
@@ -324,6 +332,9 @@
             rc = -EIO;
     }
 
+    if (!rc)
+        config->c_changed = FALSE;
+
     return rc;
 }  /* o2cb_config_store() */
 
@@ -378,6 +389,7 @@
     config->c_name = new_name;
 
     config->c_valid = TRUE;
+    config->c_changed = TRUE;
 
     return 0;
 }  /* o2cb_config_set_cluster_name() */
@@ -422,7 +434,9 @@
     node->n_number = config->c_num_nodes;
     config->c_num_nodes++;
 
+    node->n_config = config;
     config->c_nodes = g_list_append(config->c_nodes, node);
+    config->c_changed = TRUE;
 
     return node;
 }  /* o2cb_config_add_node() */
@@ -485,6 +499,7 @@
 
     g_free(node->n_name);
     node->n_name = new_name;
+    node->n_config->c_changed = TRUE;
 
     return 0;
 }  /* o2cb_node_set_name() */
@@ -508,6 +523,7 @@
 
     g_free(node->n_addr);
     node->n_addr = new_addr;
+    node->n_config->c_changed = TRUE;
 
     return 0;
 }  /* o2cb_node_set_ip_string() */
@@ -528,6 +544,7 @@
     }
 
     node->n_addr = new_addr;
+    node->n_config->c_changed = TRUE;
 
     return 0;
 }  /* o2cb_node_set_ipv4() */
@@ -537,5 +554,11 @@
     g_return_if_fail(node != NULL);
 
     node->n_port = port;
+    node->n_config->c_changed = TRUE;
 }  /* o2cb_node_set_port() */
 
+gboolean o2cb_config_changed(O2CBConfig *config)
+{
+    return config->c_changed;
+}  /* o2cb_config_changed() */
+

Modified: branches/kabi/clusterbo/o2cb_config.h
===================================================================
--- branches/kabi/clusterbo/o2cb_config.h	2005-01-05 02:45:23 UTC (rev 534)
+++ branches/kabi/clusterbo/o2cb_config.h	2005-01-05 19:14:42 UTC (rev 535)
@@ -53,5 +53,6 @@
 gint o2cb_node_set_ipv4(O2CBNode *node, struct in_addr *addr);
 void o2cb_node_set_port(O2CBNode *node, guint port);
 
+gboolean o2cb_config_changed(O2CBConfig *config);
 #endif  /* _O2CB_CONFIG_H */
 

Modified: branches/kabi/clusterbo/o2cb_ctl.c
===================================================================
--- branches/kabi/clusterbo/o2cb_ctl.c	2005-01-05 02:45:23 UTC (rev 534)
+++ branches/kabi/clusterbo/o2cb_ctl.c	2005-01-05 19:14:42 UTC (rev 535)
@@ -57,6 +57,8 @@
 
 typedef struct _O2CBContext O2CBContext;
 typedef struct _OptionAttr OptionAttr;
+typedef struct _O2CBAction O2CBAction;
+typedef gint (*O2CBActionFunc)(gpointer user_data);
 
 struct _O2CBContext
 {
@@ -68,6 +70,7 @@
     gboolean oc_compact_info;
     gboolean oc_modify_running;
     O2CBConfig *oc_config;
+    GList *oc_actions;
 };
 
 struct _OptionAttr
@@ -77,7 +80,13 @@
     gchar *oa_value;
 };
 
+struct _O2CBAction
+{
+    O2CBActionFunc oa_func;
+    gpointer oa_data;
+};
 
+
 static void print_version(void)
 {
     fprintf(stdout, PROGNAME " version %s\n", VERSION);
@@ -504,6 +513,9 @@
 
     g_return_val_if_fail(ctxt->oc_config != NULL, -EINVAL);
 
+    if (!o2cb_config_changed(ctxt->oc_config))
+        return 0;
+
     rc = o2cb_config_store(ctxt->oc_config, O2CB_CONFIG_FILE);
     if (rc)
     {
@@ -584,8 +596,44 @@
     return rc;
 }  /* find_type_for_objects() */
 
-static gint online_cluster(O2CBContext *ctxt)
+static gint append_action(O2CBContext *ctxt, O2CBActionFunc func,
+                          gpointer user_data)
 {
+    O2CBAction *action;
+
+    action = g_new0(O2CBAction, 1);
+    if (!action)
+        return -ENOMEM;
+
+    ctxt->oc_actions = g_list_append(ctxt->oc_actions, action);
+
+    return 0;
+}  /* append_action() */
+
+static gint process_actions(O2CBContext *ctxt)
+{
+    gint rc = 0;
+    GList *list;
+    O2CBAction *action;
+
+    while (ctxt->oc_actions)
+    {
+        list = ctxt->oc_actions;
+        action = (O2CBAction *)list->data;
+
+        rc = action->oa_func(action->oa_data);
+        if (rc)
+            break;
+
+        ctxt->oc_actions = g_list_delete_link(ctxt->oc_actions, list);
+    }
+
+    return rc;
+}  /* process_actions() */
+
+static gint online_cluster_action(gpointer user_data)
+{
+    O2CBContext *ctxt = user_data;
     errcode_t ret;
     gint rc;
     gchar *name, *node_name;
@@ -670,7 +718,7 @@
     return rc;
 }  /* online_cluster() */
 
-static gint offline_cluster(O2CBContext *ctxt)
+static gint offline_cluster_action(gpointer user_data)
 {
     fprintf(stderr,
             PROGNAME ": Offline of cluster not supported yet\n");
@@ -705,9 +753,9 @@
     if (attr_set(ctxt, "online"))
     {
         if (attr_boolean(ctxt, "online", FALSE))
-            rc = online_cluster(ctxt);
+            rc = append_action(ctxt, online_cluster_action, ctxt);
         else
-            rc = offline_cluster(ctxt);
+            rc = append_action(ctxt, offline_cluster_action, ctxt);
     }
 
     return rc;
@@ -768,6 +816,8 @@
 
 
     rc = write_config(ctxt);
+    if (rc)
+        rc = process_actions(ctxt);
 
 out_error:
     return rc;

Modified: branches/kabi/libo2cb/include/o2cb_kabi.h
===================================================================
--- branches/kabi/libo2cb/include/o2cb_kabi.h	2005-01-05 02:45:23 UTC (rev 534)
+++ branches/kabi/libo2cb/include/o2cb_kabi.h	2005-01-05 19:14:42 UTC (rev 535)
@@ -90,18 +90,21 @@
  *
  * If 'size' is bad, -EINVAL is returned.  Otherwise, the caller
  * must check ki_status for any ABI errors.
+ *
+ * This is a macro for the use of typeof().
  */
 #define o2cb_kabi_verify(k, member, size) ({ \
 	typeof(k) _k = (k);					\
 	struct o2cb_kabi_info *_i = &(_k->member);		\
-	int _rc = 						\
-	(_i->ki_size != (size)) ? -EINVAL :			\
-	((_i->ki_magic != O2CB_KABI_MAGIC) ?			\
-	 O2CB_KE_BAD_MAGIC :					\
-	 ((_i->ki_version != O2CB_KABI_VERSION) ?		\
-	  O2CB_KE_INVALID_ABI_VERSION :				\
-	  ((_i->ki_size != sizeof(typeof(*_k))) ?		\
-	   O2CB_KE_INVALID_REQUEST_SIZE : 0)));			\
+	int _rc = 0; 						\
+	if (_i->ki_size != (size))				\
+		_rc = -EINVAL;					\
+	else if (_i->ki_magic != O2CB_KABI_MAGIC)		\
+		_rc = O2CB_KE_BAD_MAGIC;			\
+	else if (_i->ki_version != O2CB_KABI_VERSION)		\
+		_rc = O2CB_KE_INVALID_ABI_VERSION;		\
+	else if (_i->ki_size != sizeof(typeof(*_k)))		\
+		_rc = O2CB_KE_INVALID_REQUEST_SIZE;		\
 	if (_rc != -EINVAL) {					\
 		_i->ki_status = _rc;				\
 		_rc = 0;					\
@@ -117,6 +120,8 @@
  *
  * Fills the struct o2cb_kabi_info part of the structure with the
  * appropriate magic numbers and sizes.
+ *
+ * This is a macro for the use of typeof().
  */
 #define o2cb_kabi_init(k, member, op) ({ \
 	typeof(k) _k = (k);				\



More information about the Ocfs2-tools-commits mailing list