Allow homehost to be set on command line or in config file

Signed-off-by: Neil Brown <neilb@suse.de>
This commit is contained in:
Neil Brown 2006-05-19 05:50:08 +00:00
parent 8fe9db0ffe
commit 997aed5dee
4 changed files with 66 additions and 19 deletions

View File

@ -130,13 +130,14 @@ struct option long_options[] = {
{"spare-devices",1,0, 'x'}, {"spare-devices",1,0, 'x'},
{"size", 1, 0, 'z'}, {"size", 1, 0, 'z'},
{"auto", 1, 0, 'a'}, /* also for --assemble */ {"auto", 1, 0, 'a'}, /* also for --assemble */
{"assume-clean",0,0, 3 }, {"assume-clean",0,0, AssumeClean },
{"metadata", 1, 0, 'e'}, /* superblock format */ {"metadata", 1, 0, 'e'}, /* superblock format */
{"bitmap", 1, 0, 'b'}, {"bitmap", 1, 0, 'b'},
{"bitmap-chunk", 1, 0, 4}, {"bitmap-chunk", 1, 0, BitmapChunk},
{"write-behind", 2, 0, 5}, {"write-behind", 2, 0, WriteBehind},
{"write-mostly",0, 0, 'W'}, {"write-mostly",0, 0, 'W'},
{"re-add", 0, 0, 6}, {"re-add", 0, 0, ReAdd},
{"homehost", 1, 0, HomeHost},
/* For assemble */ /* For assemble */
{"uuid", 1, 0, 'u'}, {"uuid", 1, 0, 'u'},
@ -156,11 +157,11 @@ struct option long_options[] = {
{"stop", 0, 0, 'S'}, {"stop", 0, 0, 'S'},
{"readonly", 0, 0, 'o'}, {"readonly", 0, 0, 'o'},
{"readwrite", 0, 0, 'w'}, {"readwrite", 0, 0, 'w'},
{"no-degraded",0,0, 4 }, {"no-degraded",0,0, NoDegraded },
/* For Detail/Examine */ /* For Detail/Examine */
{"brief", 0, 0, 'b'}, {"brief", 0, 0, 'b'},
{"sparc2.2", 0, 0, 22}, {"sparc2.2", 0, 0, Sparc22},
{"test", 0, 0, 't'}, {"test", 0, 0, 't'},
/* For Follow/monitor */ /* For Follow/monitor */
@ -173,7 +174,7 @@ struct option long_options[] = {
{"oneshot", 0, 0, '1'}, {"oneshot", 0, 0, '1'},
{"pid-file", 1, 0, 'i'}, {"pid-file", 1, 0, 'i'},
/* For Grow */ /* For Grow */
{"backup-file", 1,0, 7}, {"backup-file", 1,0, BackupFile},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };

View File

@ -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; int loaded = 0;
@ -614,6 +628,9 @@ void load_conffile(char *conffile)
case CreateDev: case CreateDev:
createline(line); createline(line);
break; break;
case Homehost:
homehostline(line);
break;
default: default:
fprintf(stderr, Name ": Unknown keyword %s\n", line); fprintf(stderr, Name ": Unknown keyword %s\n", line);
} }
@ -643,6 +660,12 @@ char *conf_get_program(char *conffile)
return alert_program; return alert_program;
} }
char *conf_get_homehost(char *conffile)
{
load_conffile(conffile);
return home_host;
}
struct createinfo *conf_get_create_info(char *conffile) struct createinfo *conf_get_create_info(char *conffile)
{ {
load_conffile(conffile); load_conffile(conffile);

32
mdadm.c
View File

@ -87,6 +87,7 @@ int main(int argc, char *argv[])
*/ */
int autof = 0; int autof = 0;
char *homehost = NULL;
char *mailaddr = NULL; char *mailaddr = NULL;
char *program = NULL; char *program = NULL;
int delay = 0; int delay = 0;
@ -153,6 +154,10 @@ int main(int argc, char *argv[])
} }
continue; continue;
case HomeHost:
homehost = optarg;
continue;
case ':': case ':':
case '?': case '?':
fputs(Usage, stderr); fputs(Usage, stderr);
@ -441,8 +446,8 @@ int main(int argc, char *argv[])
} }
continue; continue;
case O(CREATE,3): case O(CREATE,AssumeClean):
case O(BUILD,3): /* assume clean */ case O(BUILD,AssumeClean): /* assume clean */
assume_clean = 1; assume_clean = 1;
continue; 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); fprintf(stderr, Name ": '--update %s' invalid. Only 'sparc2.2', 'super-minor', 'uuid', 'resync' or 'summaries' supported\n",update);
exit(2); 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 */ runstop = -1; /* --stop isn't allowed for --assemble, so we overload slightly */
continue; continue;
@ -659,7 +664,7 @@ int main(int argc, char *argv[])
devmode = 'a'; devmode = 'a';
re_add = 0; re_add = 0;
continue; continue;
case O(MANAGE,6): case O(MANAGE,ReAdd):
devmode = 'a'; devmode = 'a';
re_add = 1; re_add = 1;
continue; continue;
@ -723,7 +728,7 @@ int main(int argc, char *argv[])
test = 1; test = 1;
continue; continue;
case O(MISC, 22): case O(MISC, Sparc22):
if (devmode != 'E') { if (devmode != 'E') {
fprintf(stderr, Name ": --sparc2.2 only allowed with --examine\n"); fprintf(stderr, Name ": --sparc2.2 only allowed with --examine\n");
exit(2); exit(2);
@ -748,8 +753,8 @@ int main(int argc, char *argv[])
ident.bitmap_fd = bitmap_fd; /* for Assemble */ ident.bitmap_fd = bitmap_fd; /* for Assemble */
continue; continue;
case O(ASSEMBLE, 7): case O(ASSEMBLE, BackupFile):
case O(GROW, 7): case O(GROW, BackupFile):
/* Specify a file into which grow might place a backup, /* Specify a file into which grow might place a backup,
* or from which assemble might recover 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"); fprintf(stderr, Name ": bitmap file must contain a '/', or be 'internal', or 'none'\n");
exit(2); exit(2);
case O(GROW,4): case O(GROW,BitmapChunk):
case O(BUILD,4): case O(BUILD,BitmapChunk):
case O(CREATE,4): /* bitmap chunksize */ case O(CREATE,BitmapChunk): /* bitmap chunksize */
bitmap_chunk = strtol(optarg, &c, 10); bitmap_chunk = strtol(optarg, &c, 10);
if (!optarg[0] || *c || bitmap_chunk < 0 || if (!optarg[0] || *c || bitmap_chunk < 0 ||
bitmap_chunk & (bitmap_chunk - 1)) { bitmap_chunk & (bitmap_chunk - 1)) {
@ -787,8 +792,8 @@ int main(int argc, char *argv[])
bitmap_chunk = bitmap_chunk ? bitmap_chunk * 1024 : 512; bitmap_chunk = bitmap_chunk ? bitmap_chunk * 1024 : 512;
continue; continue;
case O(BUILD, 5): case O(BUILD, WriteBehind):
case O(CREATE, 5): /* write-behind mode */ case O(CREATE, WriteBehind): /* write-behind mode */
write_behind = DEFAULT_MAX_WRITE_BEHIND; write_behind = DEFAULT_MAX_WRITE_BEHIND;
if (optarg) { if (optarg) {
write_behind = strtol(optarg, &c, 10); 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; rv = 0;
switch(mode) { switch(mode) {
case MANAGE: case MANAGE:

15
mdadm.h
View File

@ -125,6 +125,20 @@ extern char Version[], Usage[], Help[], OptionHelp[],
Help_create[], Help_build[], Help_assemble[], Help_grow[], Help_create[], Help_build[], Help_assemble[], Help_grow[],
Help_manage[], Help_misc[], Help_monitor[], Help_config[]; 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 */ /* structures read from config file */
/* List of mddevice names and identifiers /* List of mddevice names and identifiers
* Identifiers can be: * 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_mailaddr(char *conffile);
extern char *conf_get_mailfrom(char *conffile); extern char *conf_get_mailfrom(char *conffile);
extern char *conf_get_program(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_line(FILE *file);
extern char *conf_word(FILE *file, int allow_key); extern char *conf_word(FILE *file, int allow_key);
extern void free_line(char *line); extern void free_line(char *line);