Arrange the 'auto' setting in mdadm.conf can choose default type.
So when you say auto=md or auto=part in mdadm.conf, it give a preference for type of array, but standard name will override. But --auto=md is more insistant. FIXME I'm not at all happy about handling of names that already exist. I don't think that should be removed if the device is active. Signed-off-by: Neil Brown <neilb@suse.de>
This commit is contained in:
parent
8131b493df
commit
f1ae21c411
29
config.c
29
config.c
|
@ -254,17 +254,17 @@ struct createinfo createinfo = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
int parse_auto(char *str, char *msg)
|
int parse_auto(char *str, char *msg, int config)
|
||||||
{
|
{
|
||||||
int autof;
|
int autof;
|
||||||
if (str == NULL || *str == 0)
|
if (str == NULL || *str == 0)
|
||||||
autof = -2;
|
autof = 2;
|
||||||
else if (strcasecmp(str,"no")==0)
|
else if (strcasecmp(str,"no")==0)
|
||||||
autof = -3;
|
autof = 1;
|
||||||
else if (strcasecmp(str,"yes")==0)
|
else if (strcasecmp(str,"yes")==0)
|
||||||
autof = -2;
|
autof = 2;
|
||||||
else if (strcasecmp(str,"md")==0)
|
else if (strcasecmp(str,"md")==0)
|
||||||
autof = -1;
|
autof = config?5:3;
|
||||||
else {
|
else {
|
||||||
/* There might be digits, and maybe a hypen, at the end */
|
/* There might be digits, and maybe a hypen, at the end */
|
||||||
char *e = str + strlen(str);
|
char *e = str + strlen(str);
|
||||||
|
@ -279,19 +279,24 @@ int parse_auto(char *str, char *msg)
|
||||||
if (e > str && e[-1] == '-')
|
if (e > str && e[-1] == '-')
|
||||||
e--;
|
e--;
|
||||||
len = e - str;
|
len = e - str;
|
||||||
if ((len == 3 && strncasecmp(str,"mdp",3)==0) ||
|
if ((len == 2 && strncasecmp(str,"md",2)==0)) {
|
||||||
(len == 1 && strncasecmp(str,"p",1)==0) ||
|
autof = config ? 5 : 3;
|
||||||
(len >= 4 && strncasecmp(str,"part",4)==0))
|
} else if ((len == 3 && strncasecmp(str,"mdp",3)==0)) {
|
||||||
autof = num;
|
autof = config ? 6 : 4;
|
||||||
else {
|
} else if ((len == 1 && strncasecmp(str,"p",1)==0) ||
|
||||||
|
(len >= 4 && strncasecmp(str,"part",4)==0)) {
|
||||||
|
autof = 6;
|
||||||
|
} else {
|
||||||
fprintf(stderr, Name ": %s arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
|
fprintf(stderr, Name ": %s arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n"
|
||||||
" optionally followed by a number.\n",
|
" optionally followed by a number.\n",
|
||||||
msg, str);
|
msg, str);
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
autof |= num << 3;
|
||||||
}
|
}
|
||||||
return autof;
|
return autof;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void createline(char *line)
|
static void createline(char *line)
|
||||||
{
|
{
|
||||||
char *w;
|
char *w;
|
||||||
|
@ -299,7 +304,7 @@ static void createline(char *line)
|
||||||
|
|
||||||
for (w=dl_next(line); w!=line; w=dl_next(w)) {
|
for (w=dl_next(line); w!=line; w=dl_next(w)) {
|
||||||
if (strncasecmp(w, "auto=", 5) == 0)
|
if (strncasecmp(w, "auto=", 5) == 0)
|
||||||
createinfo.autof = parse_auto(w+5, "auto=");
|
createinfo.autof = parse_auto(w+5, "auto=", 1);
|
||||||
else if (strncasecmp(w, "owner=", 6) == 0) {
|
else if (strncasecmp(w, "owner=", 6) == 0) {
|
||||||
if (w[6] == 0) {
|
if (w[6] == 0) {
|
||||||
fprintf(stderr, Name ": missing owner name\n");
|
fprintf(stderr, Name ": missing owner name\n");
|
||||||
|
@ -475,7 +480,7 @@ void arrayline(char *line)
|
||||||
fprintf(stderr, Name ": metadata format %s unknown, ignored.\n", w+9);
|
fprintf(stderr, Name ": metadata format %s unknown, ignored.\n", w+9);
|
||||||
} else if (strncasecmp(w, "auto=", 5) == 0 ) {
|
} else if (strncasecmp(w, "auto=", 5) == 0 ) {
|
||||||
/* whether to create device special files as needed */
|
/* whether to create device special files as needed */
|
||||||
mis.autof = parse_auto(w+5, "auto type");
|
mis.autof = parse_auto(w+5, "auto type", 0);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, Name ": unrecognised word on ARRAY line: %s\n",
|
fprintf(stderr, Name ": unrecognised word on ARRAY line: %s\n",
|
||||||
w);
|
w);
|
||||||
|
|
22
mdadm.c
22
mdadm.c
|
@ -75,15 +75,17 @@ int main(int argc, char *argv[])
|
||||||
int force = 0;
|
int force = 0;
|
||||||
int test = 0;
|
int test = 0;
|
||||||
int assume_clean = 0;
|
int assume_clean = 0;
|
||||||
int autof = 0; /* -3 means don't create anything,
|
/* autof indicates whether and how to create device node.
|
||||||
* -2 means create device based on name:
|
* bottom 3 bits are style. Rest (when shifted) are number of parts
|
||||||
* if it ends mdN, then non-partitioned array N
|
* 0 - unset
|
||||||
* if it ends dN, then partitions array N
|
* 1 - don't create (no)
|
||||||
* -1 means create non-partitioned, choose N
|
* 2 - if is_standard, then create (yes)
|
||||||
* 1 or more to create partitioned
|
* 3 - create as 'md' - reject is_standard mdp (md)
|
||||||
* If -1 or 1 and name is a 'standard' name, then
|
* 4 - create as 'mdp' - reject is_standard md (mdp)
|
||||||
* insist on a match of type and number.
|
* 5 - default to md if not is_standard (md in config file)
|
||||||
*/
|
* 6 - default to mdp if not is_standard (part, or mdp in config file)
|
||||||
|
*/
|
||||||
|
int autof = 0;
|
||||||
|
|
||||||
char *mailaddr = NULL;
|
char *mailaddr = NULL;
|
||||||
char *program = NULL;
|
char *program = NULL;
|
||||||
|
@ -483,7 +485,7 @@ int main(int argc, char *argv[])
|
||||||
case O(CREATE,'a'):
|
case O(CREATE,'a'):
|
||||||
case O(BUILD,'a'):
|
case O(BUILD,'a'):
|
||||||
case O(ASSEMBLE,'a'): /* auto-creation of device node */
|
case O(ASSEMBLE,'a'): /* auto-creation of device node */
|
||||||
autof = parse_auto(optarg, "--auto flag");
|
autof = parse_auto(optarg, "--auto flag", 0);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case O(BUILD,'f'): /* force honouring '-n 1' */
|
case O(BUILD,'f'): /* force honouring '-n 1' */
|
||||||
|
|
2
mdadm.h
2
mdadm.h
|
@ -374,7 +374,7 @@ extern int get_mdp_major(void);
|
||||||
extern int dev_open(char *dev, int flags);
|
extern int dev_open(char *dev, int flags);
|
||||||
extern int is_standard(char *dev, int *nump);
|
extern int is_standard(char *dev, int *nump);
|
||||||
|
|
||||||
extern int parse_auto(char *str, char *msg);
|
extern int parse_auto(char *str, char *msg, int config);
|
||||||
extern mddev_ident_t conf_get_ident(char *conffile, char *dev);
|
extern mddev_ident_t conf_get_ident(char *conffile, char *dev);
|
||||||
extern mddev_dev_t conf_get_devs(char *conffile);
|
extern mddev_dev_t conf_get_devs(char *conffile);
|
||||||
extern struct createinfo *conf_get_create_info(char *conffile);
|
extern struct createinfo *conf_get_create_info(char *conffile);
|
||||||
|
|
93
mdopen.c
93
mdopen.c
|
@ -46,6 +46,7 @@ void make_parts(char *dev, int cnt)
|
||||||
char *name = malloc(nlen);
|
char *name = malloc(nlen);
|
||||||
int dig = isdigit(dev[strlen(dev)-1]);
|
int dig = isdigit(dev[strlen(dev)-1]);
|
||||||
|
|
||||||
|
if (cnt==0) cnt=4;
|
||||||
if (stat(dev, &stb)!= 0)
|
if (stat(dev, &stb)!= 0)
|
||||||
return;
|
return;
|
||||||
if (!S_ISBLK(stb.st_mode))
|
if (!S_ISBLK(stb.st_mode))
|
||||||
|
@ -94,27 +95,59 @@ int open_mddev(char *dev, int autof)
|
||||||
struct mdstat_ent *mdlist;
|
struct mdstat_ent *mdlist;
|
||||||
int num;
|
int num;
|
||||||
struct createinfo *ci = conf_get_create_info(NULL);
|
struct createinfo *ci = conf_get_create_info(NULL);
|
||||||
|
int parts;
|
||||||
|
|
||||||
if (autof == 0)
|
if (autof == 0)
|
||||||
autof = ci->autof;
|
autof = ci->autof;
|
||||||
|
|
||||||
if (autof && autof != -3) {
|
parts = autof >> 3;
|
||||||
|
autof &= 7;
|
||||||
|
|
||||||
|
if (autof && autof != 1) {
|
||||||
/* autof is set, so we need to check that the name is ok,
|
/* autof is set, so we need to check that the name is ok,
|
||||||
* and possibly create one if not
|
* and possibly create one if not
|
||||||
*/
|
*/
|
||||||
if (autof == -2 && !is_standard(dev, NULL)) {
|
int std;
|
||||||
fprintf(stderr, Name ": --auto=yes requires a 'standard' md device name, not %s\n", dev);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
stb.st_mode = 0;
|
stb.st_mode = 0;
|
||||||
if (stat(dev, &stb)==0 && ! S_ISBLK(stb.st_mode)) {
|
if (stat(dev, &stb)==0 && ! S_ISBLK(stb.st_mode)) {
|
||||||
fprintf(stderr, Name ": %s is not a block device.\n",
|
fprintf(stderr, Name ": %s is not a block device.\n",
|
||||||
dev);
|
dev);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (autof == 2 && stb.st_mode == 0 && !is_standard(dev, NULL)) {
|
||||||
|
fprintf(stderr, Name ": --auto=yes requires a 'standard' md device name, not %s\n", dev);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
/* check major number is correct */
|
/* check major number is correct */
|
||||||
if (autof>0)
|
num = -1;
|
||||||
major = get_mdp_major();
|
std = is_standard(dev, &num);
|
||||||
|
if (std>0) major = get_mdp_major();
|
||||||
|
switch(autof) {
|
||||||
|
case 2: /* only create is_standard names */
|
||||||
|
if (!std && !stb.st_mode) {
|
||||||
|
fprintf(stderr, Name ": --auto=yes requires a 'standard' md device name, not %s\n", dev);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3: /* create md, reject std>0 */
|
||||||
|
if (std > 0) {
|
||||||
|
fprintf(stderr, Name ": that --auto option not compatable with device named %s\n", dev);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4: /* create mdp, reject std<0 */
|
||||||
|
if (std < 0) {
|
||||||
|
fprintf(stderr, Name ": that --auto option not compatable with device named %s\n", dev);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 5: /* default to md if not standard */
|
||||||
|
break;
|
||||||
|
case 6: /* default to mdp if not standard */
|
||||||
|
if (std == 0) major = get_mdp_major();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* major is final. num is -1 if not standard */
|
||||||
if (stb.st_mode && major(stb.st_rdev) != major)
|
if (stb.st_mode && major(stb.st_rdev) != major)
|
||||||
must_remove = 1;
|
must_remove = 1;
|
||||||
if (stb.st_mode && !must_remove) {
|
if (stb.st_mode && !must_remove) {
|
||||||
|
@ -136,8 +169,8 @@ int open_mddev(char *dev, int autof)
|
||||||
must_remove = 1;
|
must_remove = 1;
|
||||||
close(mdfd);
|
close(mdfd);
|
||||||
} else {
|
} else {
|
||||||
if (autof > 0)
|
if (major != MD_MAJOR && parts > 0)
|
||||||
make_parts(dev, autof);
|
make_parts(dev, parts);
|
||||||
return mdfd;
|
return mdfd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,37 +180,25 @@ int open_mddev(char *dev, int autof)
|
||||||
* easiest to read /proc/mdstat, and hunt through for
|
* easiest to read /proc/mdstat, and hunt through for
|
||||||
* an unused number
|
* an unused number
|
||||||
*/
|
*/
|
||||||
switch(is_standard(dev, &num)) {
|
if (num < 0) {
|
||||||
case -1: /* non partitioned */
|
/* need to pick an unused number */
|
||||||
if (autof > 0) {
|
|
||||||
fprintf(stderr, Name ": that --auto option not compatable with device named %s\n", dev);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
minor = num;
|
|
||||||
num = -1-num;
|
|
||||||
break;
|
|
||||||
case 1: /* partitioned */
|
|
||||||
if (autof == -1) {
|
|
||||||
fprintf(stderr, Name ": that --auto option not compatable with device named %s\n", dev);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
minor = num << MdpMinorShift;
|
|
||||||
major = get_mdp_major();
|
|
||||||
break;
|
|
||||||
case 0: /* not standard, pick an unused number */
|
|
||||||
mdlist = mdstat_read(0, 0);
|
mdlist = mdstat_read(0, 0);
|
||||||
for (num= (autof>0)?-1:0 ; ; num+= (autof>2)?-1:1) {
|
for (num = 0 ; ; num++) {
|
||||||
struct mdstat_ent *me;
|
struct mdstat_ent *me;
|
||||||
|
int devnum = num;
|
||||||
|
if (major != MD_MAJOR)
|
||||||
|
devnum = -1-num;
|
||||||
|
|
||||||
for (me=mdlist; me; me=me->next)
|
for (me=mdlist; me; me=me->next)
|
||||||
if (me->devnum == num)
|
if (me->devnum == devnum)
|
||||||
break;
|
break;
|
||||||
if (!me) {
|
if (!me) {
|
||||||
/* doesn't exist if mdstat.
|
/* doesn't exist if mdstat.
|
||||||
* make sure it is new to /dev too
|
* make sure it is new to /dev too
|
||||||
*/
|
*/
|
||||||
char *dn;
|
char *dn;
|
||||||
if (autof > 0)
|
if (major != MD_MAJOR)
|
||||||
minor = (-1-num) << MdpMinorShift;
|
minor = num << MdpMinorShift;
|
||||||
else
|
else
|
||||||
minor = num;
|
minor = num;
|
||||||
dn = map_dev(major,minor, 0);
|
dn = map_dev(major,minor, 0);
|
||||||
|
@ -189,9 +210,12 @@ int open_mddev(char *dev, int autof)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (major == MD_MAJOR)
|
||||||
|
minor = num;
|
||||||
|
else
|
||||||
|
minor = num << MdpMinorShift;
|
||||||
/* major and minor have been chosen */
|
/* major and minor have been chosen */
|
||||||
|
|
||||||
/* If it was a 'standard' name and it is in-use, then
|
/* If it was a 'standard' name and it is in-use, then
|
||||||
* the device could already be correct
|
* the device could already be correct
|
||||||
*/
|
*/
|
||||||
|
@ -224,7 +248,8 @@ int open_mddev(char *dev, int autof)
|
||||||
}
|
}
|
||||||
stat(dev, &stb);
|
stat(dev, &stb);
|
||||||
add_dev(dev, &stb, 0, NULL);
|
add_dev(dev, &stb, 0, NULL);
|
||||||
make_parts(dev,autof);
|
if (major != MD_MAJOR)
|
||||||
|
make_parts(dev,parts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mdfd = open(dev, O_RDWR, 0);
|
mdfd = open(dev, O_RDWR, 0);
|
||||||
|
|
Loading…
Reference in New Issue