main: factor out code to parse layout for raid10 and faulty.
This will soon be called from multiple places. Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
parent
84e11361aa
commit
4a06e2c270
27
mdadm.c
27
mdadm.c
|
@ -107,7 +107,6 @@ int main(int argc, char *argv[])
|
|||
int rebuild_map = 0;
|
||||
int auto_update_home = 0;
|
||||
|
||||
int copies;
|
||||
int print_help = 0;
|
||||
FILE *outf;
|
||||
|
||||
|
@ -478,38 +477,22 @@ int main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case 10:
|
||||
/* 'f', 'o' or 'n' followed by a number <= raid_disks */
|
||||
if ((optarg[0] != 'n' && optarg[0] != 'f' && optarg[0] != 'o') ||
|
||||
(copies = strtoul(optarg+1, &cp, 10)) < 1 ||
|
||||
copies > 200 ||
|
||||
*cp) {
|
||||
layout = parse_layout_10(optarg);
|
||||
if (layout < 0) {
|
||||
fprintf(stderr, Name ": layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg);
|
||||
exit(2);
|
||||
}
|
||||
if (optarg[0] == 'n')
|
||||
layout = 256 + copies;
|
||||
else if (optarg[0] == 'o')
|
||||
layout = 0x10000 + (copies<<8) + 1;
|
||||
else
|
||||
layout = 1 + (copies<<8);
|
||||
break;
|
||||
case -5: /* Faulty
|
||||
* modeNNN
|
||||
*/
|
||||
|
||||
{
|
||||
int ln = strcspn(optarg, "0123456789");
|
||||
char *m = strdup(optarg);
|
||||
int mode;
|
||||
m[ln] = 0;
|
||||
mode = map_name(faultylayout, m);
|
||||
if (mode == UnSet) {
|
||||
layout = parse_layout_faulty(optarg);
|
||||
if (layout == -1) {
|
||||
fprintf(stderr, Name ": layout %s not understood for faulty.\n",
|
||||
optarg);
|
||||
exit(2);
|
||||
}
|
||||
layout = mode | (atoi(optarg+ln)<< ModeShift);
|
||||
}
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
|
||||
|
|
2
mdadm.h
2
mdadm.h
|
@ -776,6 +776,8 @@ extern int md_get_version(int fd);
|
|||
extern int get_linux_version(void);
|
||||
extern long long parse_size(char *size);
|
||||
extern int parse_uuid(char *str, int uuid[4]);
|
||||
extern int parse_layout_10(char *layout);
|
||||
extern int parse_layout_faulty(char *layout);
|
||||
extern int check_ext2(int fd, char *name);
|
||||
extern int check_reiser(int fd, char *name);
|
||||
extern int check_raid(int fd, char *name);
|
||||
|
|
34
util.c
34
util.c
|
@ -185,6 +185,40 @@ long long parse_size(char *size)
|
|||
return s;
|
||||
}
|
||||
|
||||
int parse_layout_10(char *layout)
|
||||
{
|
||||
int copies, rv;
|
||||
char *cp;
|
||||
/* Parse the layout string for raid10 */
|
||||
/* 'f', 'o' or 'n' followed by a number <= raid_disks */
|
||||
if ((layout[0] != 'n' && layout[0] != 'f' && layout[0] != 'o') ||
|
||||
(copies = strtoul(layout+1, &cp, 10)) < 1 ||
|
||||
copies > 200 ||
|
||||
*cp)
|
||||
return -1;
|
||||
if (layout[0] == 'n')
|
||||
rv = 256 + copies;
|
||||
else if (layout[0] == 'o')
|
||||
rv = 0x10000 + (copies<<8) + 1;
|
||||
else
|
||||
rv = 1 + (copies<<8);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int parse_layout_faulty(char *layout)
|
||||
{
|
||||
/* Parse the layout string for 'faulty' */
|
||||
int ln = strcspn(layout, "0123456789");
|
||||
char *m = strdup(layout);
|
||||
int mode;
|
||||
m[ln] = 0;
|
||||
mode = map_name(faultylayout, m);
|
||||
if (mode == UnSet)
|
||||
return -1;
|
||||
|
||||
return mode | (atoi(layout+ln)<< ModeShift);
|
||||
}
|
||||
|
||||
void remove_partitions(int fd)
|
||||
{
|
||||
/* remove partitions from this block devices.
|
||||
|
|
Loading…
Reference in New Issue