[DRBD-cvs] svn commit by phil - r2051 - in trunk: . user - drbdadm can now also show its secret commands.

drbd-cvs at lists.linbit.com drbd-cvs at lists.linbit.com
Thu Jan 19 18:39:53 CET 2006


Author: phil
Date: 2006-01-19 18:39:52 +0100 (Thu, 19 Jan 2006)
New Revision: 2051

Modified:
   trunk/ROADMAP
   trunk/user/drbdadm_main.c
   trunk/user/drbdmeta.c
Log:
drbdadm can now also show its secret commands.


Modified: trunk/ROADMAP
===================================================================
--- trunk/ROADMAP	2006-01-19 15:28:44 UTC (rev 2050)
+++ trunk/ROADMAP	2006-01-19 17:39:52 UTC (rev 2051)
@@ -667,9 +667,11 @@
    set gets generated, the 'call home' is initiated. The user might
    of course opt out of this.
 
-29 Make all the commands to have 'expert' switches to also show
+29 Make drbdadm to have 'hidden-commands' command to also show
    the hidden sub-commands in the ussage.
 
+   99% DONE
+
 30 The current drbdadm_scanner is 1MB in source and as binary.
    Use a _basic_ flex scanner, and a hand written parser for superb
    errror reporting.

Modified: trunk/user/drbdadm_main.c
===================================================================
--- trunk/user/drbdadm_main.c	2006-01-19 15:28:44 UTC (rev 2050)
+++ trunk/user/drbdadm_main.c	2006-01-19 17:39:52 UTC (rev 2051)
@@ -64,9 +64,9 @@
 struct adm_cmd {
   const char* name;
   int (* function)(struct d_resource*,const char* );
-  int show_in_usage     :1;
-  int res_name_required :1;
-  int verify_ips        :1;
+  unsigned int show_in_usage     :3;
+  unsigned int res_name_required :1;
+  unsigned int verify_ips        :1;
 };
 
 struct deferred_cmd
@@ -100,6 +100,7 @@
 static int admm_generic(struct d_resource* ,const char* );
 static int adm_khelper(struct d_resource* ,const char* );
 static int adm_generic_b(struct d_resource* ,const char* );
+static int hidden_cmds(struct d_resource* ,const char* );
 
 char ss_buffer[255];
 struct utsname nodeinfo;
@@ -201,17 +202,18 @@
   { "show-gi",           adm_generic_b, 1,1,0 },
   { "get-gi",            adm_generic_b, 1,1,0 },
   { "dump-md",           admm_generic,  1,1,0 },
-  { "set-gi",            admm_generic,  0,1,0 },
-  { "pri-on-incon-degr", adm_khelper,   0,1,0 },
-  { "pri-lost-after-sb", adm_khelper,   0,1,0 },
-  { "outdate-peer",      adm_khelper,   0,1,0 },
   { "wait_con_int",      adm_wait_ci,   1,0,1 },
-  { "sh-resources",      sh_resources,  0,0,0 },
-  { "sh-mod-parms",      sh_mod_parms,  0,0,0 },
-  { "sh-dev",            sh_dev,        0,1,0 },
-  { "sh-ll-dev",         sh_ll_dev,     0,1,0 },
-  { "sh-md-dev",         sh_md_dev,     0,1,0 },
-  { "sh-md-idx",         sh_md_idx,     0,1,0 },
+  { "hidden-commands",   hidden_cmds,   1,0,0 },
+  { "sh-resources",      sh_resources,  2,0,0 },
+  { "sh-mod-parms",      sh_mod_parms,  2,0,0 },
+  { "sh-dev",            sh_dev,        2,1,0 },
+  { "sh-ll-dev",         sh_ll_dev,     2,1,0 },
+  { "sh-md-dev",         sh_md_dev,     2,1,0 },
+  { "sh-md-idx",         sh_md_idx,     2,1,0 },
+  { "pri-on-incon-degr", adm_khelper,   3,1,0 },
+  { "pri-lost-after-sb", adm_khelper,   3,1,0 },
+  { "outdate-peer",      adm_khelper,   3,1,0 },
+  { "set-gi",            admm_generic,  4,1,0 },
 };
 
 /*** These functions are used to the print the config ***/
@@ -1048,9 +1050,46 @@
   return 0;
 }
 
+static void print_cmds(int level)
+{
+  size_t i;
+  int j=0;
+
+  for(i=0;i<ARRY_SIZE(cmds);i++) {
+    if(cmds[i].show_in_usage!=level) continue;
+    if(j++ % 2) {
+      printf("%-35s\n",cmds[i].name);
+    } else {
+      printf(" %-35s",cmds[i].name);
+    }
+  }
+  if(j % 2) printf("\n");
+}
+
+static int hidden_cmds(struct d_resource* ignored __attribute((unused)),
+		       const char* ignored2 __attribute((unused)) )
+{
+  printf("\nThese additional commands might be usefull for writing\n"
+	 "nifty shell scripts around drbdadm\n\n");
+
+  print_cmds(2);
+
+  printf("\nThese command are used by the kernel part of DRBD to\n"
+	 "invoke user mode helper programs\n\n");
+
+  print_cmds(3);
+
+  printf("\nThese commands ought to be used by experts and developers\n\n");
+  
+  print_cmds(4);
+
+  printf("\n");
+
+  exit(0);
+}
+
 void print_usage_and_exit(const char* addinfo)
 {
-  size_t i;
   struct option *opt;
 
   printf("\nUSAGE: %s [OPTION...] [-- DRBDSETUP-OPTION...] COMMAND "
@@ -1068,14 +1107,7 @@
 
   printf("\nCOMMANDS:\n");
 
-  for(i=0;i<ARRY_SIZE(cmds);i++) {
-    if(cmds[i].show_in_usage==0) break;
-    if(i%2) {
-      printf("%-35s\n",cmds[i].name);
-    } else {
-      printf(" %-35s",cmds[i].name);
-    }
-  }
+  print_cmds(1);
 
   printf("\nVersion: "REL_VERSION" (api:%d)\n%s\n",
 		  API_VERSION, drbd_buildtag());
@@ -1400,6 +1432,12 @@
   }
   if (optind == argc) print_usage_and_exit(0);
 
+  if(!strcmp("hidden-commands",argv[optind])) {
+    // before parsing the configuration file...
+    hidden_cmds(NULL,NULL);
+    exit(0);
+  }
+
   cmd=NULL;
   for(i=0;i<ARRY_SIZE(cmds);i++) {
       if(!strcmp(cmds[i].name,argv[optind])) {

Modified: trunk/user/drbdmeta.c
===================================================================
--- trunk/user/drbdmeta.c	2006-01-19 15:28:44 UTC (rev 2050)
+++ trunk/user/drbdmeta.c	2006-01-19 17:39:52 UTC (rev 2051)
@@ -801,9 +801,8 @@
 int meta_dump_md(struct format *cfg, char **argv, int argc);
 int meta_restore_md(struct format *cfg, char **argv, int argc);
 int meta_create_md(struct format *cfg, char **argv, int argc);
-int meta_set_gi(struct format *cfg, char **argv, int argc);
 int meta_outdate(struct format *cfg, char **argv, int argc);
-int meta_set_uuid(struct format *cfg, char **argv, int argc);
+int meta_set_gi(struct format *cfg, char **argv, int argc);
 
 struct meta_cmd cmds[] = {
 	{"get-gi", 0, meta_get_gi, 1},



More information about the drbd-cvs mailing list