]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Allow homehost to be set on command line or in config file
authorNeil Brown <neilb@suse.de>
Fri, 19 May 2006 05:50:08 +0000 (05:50 +0000)
committerNeil Brown <neilb@suse.de>
Fri, 19 May 2006 05:50:08 +0000 (05:50 +0000)
Signed-off-by: Neil Brown <neilb@suse.de>
ReadMe.c
config.c
mdadm.c
mdadm.h

index db06795c1034131ade8d359bbfcb188a4f6fa804..ca2bc77ded9501dfd81e7678c3a7a218dc8f8b06 100644 (file)
--- a/ReadMe.c
+++ b/ReadMe.c
@@ -130,13 +130,14 @@ struct option long_options[] = {
     {"spare-devices",1,0, 'x'},
     {"size",     1, 0, 'z'},
     {"auto",     1, 0, 'a'}, /* also for --assemble */
-    {"assume-clean",0,0, 3 },
+    {"assume-clean",0,0, AssumeClean },
     {"metadata",  1, 0, 'e'}, /* superblock format */
     {"bitmap",   1, 0, 'b'},
-    {"bitmap-chunk", 1, 0, 4},
-    {"write-behind", 2, 0, 5},
+    {"bitmap-chunk", 1, 0, BitmapChunk},
+    {"write-behind", 2, 0, WriteBehind},
     {"write-mostly",0, 0, 'W'},
-    {"re-add",    0, 0,  6},
+    {"re-add",    0, 0,  ReAdd},
+    {"homehost",  1, 0,  HomeHost},
 
     /* For assemble */
     {"uuid",      1, 0, 'u'},
@@ -156,11 +157,11 @@ struct option long_options[] = {
     {"stop",      0, 0, 'S'},
     {"readonly",  0, 0, 'o'},
     {"readwrite", 0, 0, 'w'},
-    {"no-degraded",0,0,  4 },
+    {"no-degraded",0,0,  NoDegraded },
 
     /* For Detail/Examine */
     {"brief",    0, 0, 'b'},
-    {"sparc2.2",  0, 0, 22},
+    {"sparc2.2",  0, 0, Sparc22},
     {"test",      0, 0, 't'},
 
     /* For Follow/monitor */
@@ -173,7 +174,7 @@ struct option long_options[] = {
     {"oneshot",   0, 0, '1'},
     {"pid-file",  1, 0, 'i'},
     /* For Grow */
-    {"backup-file", 1,0, 7},
+    {"backup-file", 1,0, BackupFile},
     
     {0, 0, 0, 0}
 };
index ec9e3e16d82ba7e218e9a9cf55d45a9ababc496f..8382cdfe44174c6ea81b42bd49ff62e7c01bae27 100644 (file)
--- a/config.c
+++ b/config.c
@@ -553,6 +553,20 @@ void programline(char *line)
        }
 }
 
+static char *home_host = NULL;
+void homehostline(char *line)
+{
+       char *w;
+
+       for (w=dl_next(line); w != line ; w=dl_next(w)) {
+               if (home_host == NULL)
+                       home_host = strdup(w);
+               else
+                       fprintf(stderr, Name ": excess host name on HOMEHOST line: %s - ignored\n",
+                               w);
+       }
+}
+
 
 int loaded = 0;
 
@@ -614,6 +628,9 @@ void load_conffile(char *conffile)
                case CreateDev:
                        createline(line);
                        break;
+               case Homehost:
+                       homehostline(line);
+                       break;
                default:
                        fprintf(stderr, Name ": Unknown keyword %s\n", line);
                }
@@ -643,6 +660,12 @@ char *conf_get_program(char *conffile)
        return alert_program;
 }
 
+char *conf_get_homehost(char *conffile)
+{
+       load_conffile(conffile);
+       return home_host;
+}
+
 struct createinfo *conf_get_create_info(char *conffile)
 {
        load_conffile(conffile);
diff --git a/mdadm.c b/mdadm.c
index 902d401fbc9d1b5b0ea2883b3d142a88a4248468..df8d904b1313f0a3a2958affb7034d91e81bea5e 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -87,6 +87,7 @@ int main(int argc, char *argv[])
         */
        int autof = 0;
 
+       char *homehost = NULL;
        char *mailaddr = NULL;
        char *program = NULL;
        int delay = 0;
@@ -153,6 +154,10 @@ int main(int argc, char *argv[])
                        }
                        continue;
 
+               case HomeHost:
+                       homehost = optarg;
+                       continue;
+
                case ':':
                case '?':
                        fputs(Usage, stderr);
@@ -441,8 +446,8 @@ int main(int argc, char *argv[])
                        }
                        continue;
 
-               case O(CREATE,3):
-               case O(BUILD,3): /* assume clean */
+               case O(CREATE,AssumeClean):
+               case O(BUILD,AssumeClean): /* assume clean */
                        assume_clean = 1;
                        continue;
 
@@ -577,7 +582,7 @@ int main(int argc, char *argv[])
                        fprintf(stderr, Name ": '--update %s' invalid.  Only 'sparc2.2', 'super-minor', 'uuid', 'resync' or 'summaries' supported\n",update);
                        exit(2);
 
-               case O(ASSEMBLE,4): /* --no-degraded */
+               case O(ASSEMBLE,NoDegraded): /* --no-degraded */
                        runstop = -1; /* --stop isn't allowed for --assemble, so we overload slightly */
                        continue;
 
@@ -659,7 +664,7 @@ int main(int argc, char *argv[])
                        devmode = 'a';
                        re_add = 0;
                        continue;
-               case O(MANAGE,6):
+               case O(MANAGE,ReAdd):
                        devmode = 'a';
                        re_add = 1;
                        continue;
@@ -723,7 +728,7 @@ int main(int argc, char *argv[])
                        test = 1;
                        continue;
 
-               case O(MISC, 22):
+               case O(MISC, Sparc22):
                        if (devmode != 'E') {
                                fprintf(stderr, Name ": --sparc2.2 only allowed with --examine\n");
                                exit(2);
@@ -748,8 +753,8 @@ int main(int argc, char *argv[])
                        ident.bitmap_fd = bitmap_fd; /* for Assemble */
                        continue;
 
-               case O(ASSEMBLE, 7):
-               case O(GROW, 7):
+               case O(ASSEMBLE, BackupFile):
+               case O(GROW, BackupFile):
                        /* Specify a file into which grow might place a backup,
                         * or from which assemble might recover a backup
                         */
@@ -773,9 +778,9 @@ int main(int argc, char *argv[])
                        fprintf(stderr, Name ": bitmap file must contain a '/', or be 'internal', or 'none'\n");
                        exit(2);
 
-               case O(GROW,4):
-               case O(BUILD,4):
-               case O(CREATE,4): /* bitmap chunksize */
+               case O(GROW,BitmapChunk):
+               case O(BUILD,BitmapChunk):
+               case O(CREATE,BitmapChunk): /* bitmap chunksize */
                        bitmap_chunk = strtol(optarg, &c, 10);
                        if (!optarg[0] || *c || bitmap_chunk < 0 ||
                                        bitmap_chunk & (bitmap_chunk - 1)) {
@@ -787,8 +792,8 @@ int main(int argc, char *argv[])
                        bitmap_chunk = bitmap_chunk ? bitmap_chunk * 1024 : 512;
                        continue;
 
-               case O(BUILD, 5):
-               case O(CREATE, 5): /* write-behind mode */
+               case O(BUILD, WriteBehind):
+               case O(CREATE, WriteBehind): /* write-behind mode */
                        write_behind = DEFAULT_MAX_WRITE_BEHIND;
                        if (optarg) {
                                write_behind = strtol(optarg, &c, 10);
@@ -893,6 +898,9 @@ int main(int argc, char *argv[])
                }
        }
 
+       if (homehost == NULL)
+               homehost = conf_get_homehost(configfile);
+
        rv = 0;
        switch(mode) {
        case MANAGE:
diff --git a/mdadm.h b/mdadm.h
index df4351658989fe00c0b17cb6a4b9e2ad5959c849..991dc8e0f5dfbb46da3696e499c202d6c0dbf299 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -125,6 +125,20 @@ extern char Version[], Usage[], Help[], OptionHelp[],
        Help_create[], Help_build[], Help_assemble[], Help_grow[],
        Help_manage[], Help_misc[], Help_monitor[], Help_config[];
 
+/* for option that don't have short equivilents, we assign arbitrary
+ * small numbers.  '1' means an undecorated option, so we start at '2'.
+ */
+enum special_options {
+       AssumeClean = 2,
+       BitmapChunk,
+       WriteBehind,
+       ReAdd,
+       NoDegraded,
+       Sparc22,
+       BackupFile,
+       HomeHost,
+};
+
 /* structures read from config file */
 /* List of mddevice names and identifiers
  * Identifiers can be:
@@ -381,6 +395,7 @@ extern struct createinfo *conf_get_create_info(char *conffile);
 extern char *conf_get_mailaddr(char *conffile);
 extern char *conf_get_mailfrom(char *conffile);
 extern char *conf_get_program(char *conffile);
+extern char *conf_get_homehost(char *conffile);
 extern char *conf_line(FILE *file);
 extern char *conf_word(FILE *file, int allow_key);
 extern void free_line(char *line);