[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH 2/8] Unify 'del' functions



No need to keep 2 copies with almost the same logic inside - better to add if..
else clause.

Signed-off-by: Dmitry Mishin <dim parallels com>
---
 config/tools/ccs_tool/ccs_tool.c |    2 +-
 config/tools/ccs_tool/editconf.c |   59 ++-----------------------------------
 config/tools/ccs_tool/editconf.h |    1 -
 3 files changed, 5 insertions(+), 57 deletions(-)

diff --git a/config/tools/ccs_tool/ccs_tool.c b/config/tools/ccs_tool/ccs_tool.c
index 2fe6f78..8062549 100644
--- a/config/tools/ccs_tool/ccs_tool.c
+++ b/config/tools/ccs_tool/ccs_tool.c
@@ -230,7 +230,7 @@ static int tool_main(int argc, char *argv[])
 	    exit(EXIT_SUCCESS);
     }
     else if(!strcmp(argv[optind], "delservice")){
-	    del_service(argc-1, argv+1);
+	    del_node(argc-1, argv+1);
 	    exit(EXIT_SUCCESS);
     }
     else if(!strcmp(argv[optind], "addfence")){
diff --git a/config/tools/ccs_tool/editconf.c b/config/tools/ccs_tool/editconf.c
index d63dc37..d68f395 100644
--- a/config/tools/ccs_tool/editconf.c
+++ b/config/tools/ccs_tool/editconf.c
@@ -128,15 +128,6 @@ static void delnode_usage(const char *name)
 	exit(0);
 }
 
-static void delservice_usage(const char *name)
-{
-	fprintf(stderr, "Usage: %s %s [options] <name>\n", prog_name, name);
-	config_usage(1);
-	help_usage();
-
-	exit(0);
-}
-
 static void addnodeid_usage(const char *name)
 {
 	fprintf(stderr, "Add node IDs to all nodes in the config file that don't have them.\n");
@@ -1045,7 +1036,10 @@ void del_node(int argc, char **argv)
 
 	increment_version(root_element);
 
-	del_clusternode(root_element, &ninfo);
+	if (!strcmp(argv[0], "delnode"))
+		del_clusternode(root_element, &ninfo);
+	else if (!strcmp(argv[0], "delservice"))
+		del_clusterservice(root_element, &ninfo);
 
 	/* Write it out */
 	save_file(doc, &ninfo);
@@ -1209,51 +1203,6 @@ void add_service(int argc, char **argv)
 
 }
 
-void del_service(int argc, char **argv)
-{
-	struct option_info ninfo;
-	int opt;
-	xmlDoc *doc;
-	xmlNode *root_element;
-
-	memset(&ninfo, 0, sizeof(ninfo));
-
-	while ( (opt = getopt_long(argc, argv, "o:c:CFh?", delservice_options, NULL)) != EOF)
-	{
-		switch(opt)
-		{
-		case 'c':
-			ninfo.configfile = strdup(optarg);
-			break;
-
-		case 'o':
-			ninfo.outputfile = strdup(optarg);
-			break;
-
-		case '?':
-		default:
-			delservice_usage(argv[0]);
-		}
-	}
-
-	/* Get service name parameter */
-	if (optind < argc)
-		ninfo.name = strdup(argv[optind]);
-	else
-		delservice_usage(argv[0]);
-
-	doc = open_configfile(&ninfo);
-
-	root_element = xmlDocGetRootElement(doc);
-
-	increment_version(root_element);
-
-	del_clusterservice(root_element, &ninfo);
-
-	/* Write it out */
-	save_file(doc, &ninfo);
-}
-
 void list_services(int argc, char **argv)
 {
 	xmlNode *cur_service;
diff --git a/config/tools/ccs_tool/editconf.h b/config/tools/ccs_tool/editconf.h
index be8945e..0090ab6 100644
--- a/config/tools/ccs_tool/editconf.h
+++ b/config/tools/ccs_tool/editconf.h
@@ -3,7 +3,6 @@ void add_nodeids(int argc, char **argv);
 void add_service(int argc, char **argv);
 void add_fence(int argc, char **argv);
 void del_node(int argc, char **argv);
-void del_service(int argc, char **argv);
 void del_fence(int argc, char **argv);
 void list_nodes(int argc, char **argv);
 void list_services(int argc, char **argv);
-- 
1.7.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]