Change Create to take a struct context

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2012-07-09 17:19:24 +10:00
parent 0c9e4afb1f
commit 171dccc813
3 changed files with 42 additions and 43 deletions

View File

@ -65,12 +65,11 @@ static int default_layout(struct supertype *st, int level, int verbose)
int Create(struct supertype *st, char *mddev, int Create(struct supertype *st, char *mddev,
int chunk, int level, int layout, unsigned long long size, int chunk, int level, int layout, unsigned long long size,
int raiddisks, int sparedisks, int raiddisks, int sparedisks,
char *name, char *homehost, int *uuid, char *name, int *uuid,
int subdevs, struct mddev_dev *devlist, int subdevs, struct mddev_dev *devlist,
int runstop, int readonly, int verbose, int assume_clean,
int force, int assume_clean,
char *bitmap_file, int bitmap_chunk, int write_behind, char *bitmap_file, int bitmap_chunk, int write_behind,
int delay, int autof) struct context *c)
{ {
/* /*
* Create a new raid array. * Create a new raid array.
@ -205,7 +204,7 @@ int Create(struct supertype *st, char *mddev,
if (layout == UnSet) { if (layout == UnSet) {
do_default_layout = 1; do_default_layout = 1;
layout = default_layout(st, level, verbose); layout = default_layout(st, level, c->verbose);
} }
if (level == 10) if (level == 10)
@ -232,7 +231,7 @@ int Create(struct supertype *st, char *mddev,
/* a chunksize of zero 0s perfectly valid (and preferred) since 2.6.16 */ /* a chunksize of zero 0s perfectly valid (and preferred) since 2.6.16 */
if (get_linux_version() < 2006016 && chunk == 0) { if (get_linux_version() < 2006016 && chunk == 0) {
chunk = 64; chunk = 64;
if (verbose > 0) if (c->verbose > 0)
pr_err("chunk size defaults to 64K\n"); pr_err("chunk size defaults to 64K\n");
} }
break; break;
@ -242,7 +241,7 @@ int Create(struct supertype *st, char *mddev,
case LEVEL_CONTAINER: case LEVEL_CONTAINER:
if (chunk) { if (chunk) {
chunk = 0; chunk = 0;
if (verbose > 0) if (c->verbose > 0)
pr_err("chunk size ignored for this level\n"); pr_err("chunk size ignored for this level\n");
} }
break; break;
@ -255,14 +254,14 @@ int Create(struct supertype *st, char *mddev,
size &= ~(unsigned long long)(chunk - 1); size &= ~(unsigned long long)(chunk - 1);
newsize = size * 2; newsize = size * 2;
if (st && ! st->ss->validate_geometry(st, level, layout, raiddisks, if (st && ! st->ss->validate_geometry(st, level, layout, raiddisks,
&chunk, size*2, NULL, &newsize, verbose>=0)) &chunk, size*2, NULL, &newsize, c->verbose>=0))
return 1; return 1;
if (chunk && chunk != UnSet) { if (chunk && chunk != UnSet) {
newsize &= ~(unsigned long long)(chunk*2 - 1); newsize &= ~(unsigned long long)(chunk*2 - 1);
if (do_default_chunk) { if (do_default_chunk) {
/* default chunk was just set */ /* default chunk was just set */
if (verbose > 0) if (c->verbose > 0)
pr_err("chunk size " pr_err("chunk size "
"defaults to %dK\n", chunk); "defaults to %dK\n", chunk);
size &= ~(unsigned long long)(chunk - 1); size &= ~(unsigned long long)(chunk - 1);
@ -279,7 +278,7 @@ int Create(struct supertype *st, char *mddev,
*/ */
size &= ~(64ULL-1); size &= ~(64ULL-1);
if (size && verbose > 0) if (size && c->verbose > 0)
pr_err("setting size to %lluK\n", pr_err("setting size to %lluK\n",
(unsigned long long)size); (unsigned long long)size);
} }
@ -334,11 +333,11 @@ int Create(struct supertype *st, char *mddev,
if (!st) if (!st)
continue; continue;
if (do_default_layout) if (do_default_layout)
layout = default_layout(st, level, verbose); layout = default_layout(st, level, c->verbose);
switch (st->ss->validate_geometry( switch (st->ss->validate_geometry(
st, level, layout, raiddisks, st, level, layout, raiddisks,
&chunk, size*2, dname, &freesize, &chunk, size*2, dname, &freesize,
verbose > 0)) { c->verbose > 0)) {
case -1: /* Not valid, message printed, and not case -1: /* Not valid, message printed, and not
* worth checking any further */ * worth checking any further */
exit(2); exit(2);
@ -375,7 +374,7 @@ int Create(struct supertype *st, char *mddev,
raiddisks, raiddisks,
&chunk, size*2, dname, &chunk, size*2, dname,
&freesize, &freesize,
verbose >= 0)) { c->verbose >= 0)) {
pr_err("%s is not suitable for " pr_err("%s is not suitable for "
"this array.\n", "this array.\n",
@ -391,7 +390,7 @@ int Create(struct supertype *st, char *mddev,
freesize = freesize & ~(chunk-1); freesize = freesize & ~(chunk-1);
if (do_default_chunk) { if (do_default_chunk) {
/* default chunk was just set */ /* default chunk was just set */
if (verbose > 0) if (c->verbose > 0)
pr_err("chunk size " pr_err("chunk size "
"defaults to %dK\n", chunk); "defaults to %dK\n", chunk);
size &= ~(unsigned long long)(chunk - 1); size &= ~(unsigned long long)(chunk - 1);
@ -414,7 +413,7 @@ int Create(struct supertype *st, char *mddev,
mindisc = dname; mindisc = dname;
minsize = freesize; minsize = freesize;
} }
if (runstop != 1 || verbose >= 0) { if (c->runstop != 1 || c->verbose >= 0) {
int fd = open(dname, O_RDONLY); int fd = open(dname, O_RDONLY);
if (fd <0 ) { if (fd <0 ) {
pr_err("Cannot open %s: %s\n", pr_err("Cannot open %s: %s\n",
@ -486,19 +485,19 @@ int Create(struct supertype *st, char *mddev,
* now just to be safe * now just to be safe
*/ */
size &= ~(64ULL-1); size &= ~(64ULL-1);
if (verbose > 0) if (c->verbose > 0)
pr_err("size set to %lluK\n", size); pr_err("size set to %lluK\n", size);
} }
} }
if (!have_container && level > 0 && ((maxsize-size)*100 > maxsize)) { if (!have_container && level > 0 && ((maxsize-size)*100 > maxsize)) {
if (runstop != 1 || verbose >= 0) if (c->runstop != 1 || c->verbose >= 0)
pr_err("largest drive (%s) exceeds size (%lluK) by more than 1%%\n", pr_err("largest drive (%s) exceeds size (%lluK) by more than 1%%\n",
maxdisc, size); maxdisc, size);
warn = 1; warn = 1;
} }
if (st->ss->detail_platform && st->ss->detail_platform(0, 1) != 0) { if (st->ss->detail_platform && st->ss->detail_platform(0, 1) != 0) {
if (runstop != 1 || verbose >= 0) if (c->runstop != 1 || c->verbose >= 0)
pr_err("%s unable to enumerate platform support\n" pr_err("%s unable to enumerate platform support\n"
" array may not be compatible with hardware/firmware\n", " array may not be compatible with hardware/firmware\n",
st->ss->name); st->ss->name);
@ -506,13 +505,13 @@ int Create(struct supertype *st, char *mddev,
} }
if (warn) { if (warn) {
if (runstop!= 1) { if (c->runstop!= 1) {
if (!ask("Continue creating array? ")) { if (!ask("Continue creating array? ")) {
pr_err("create aborted.\n"); pr_err("create aborted.\n");
return 1; return 1;
} }
} else { } else {
if (verbose > 0) if (c->verbose > 0)
pr_err("creation continuing despite oddities due to --run\n"); pr_err("creation continuing despite oddities due to --run\n");
} }
} }
@ -522,7 +521,7 @@ int Create(struct supertype *st, char *mddev,
* FIX: Can we do this for raid6 as well? * FIX: Can we do this for raid6 as well?
*/ */
if (st->ss->external == 0 && if (st->ss->external == 0 &&
assume_clean==0 && force == 0 && first_missing >= raiddisks) { assume_clean==0 && c->force == 0 && first_missing >= raiddisks) {
switch ( level ) { switch ( level ) {
case 4: case 4:
case 5: case 5:
@ -538,7 +537,7 @@ int Create(struct supertype *st, char *mddev,
/* For raid6, if creating with 1 missing drive, make a good drive /* For raid6, if creating with 1 missing drive, make a good drive
* into a spare, else the create will fail * into a spare, else the create will fail
*/ */
if (assume_clean == 0 && force == 0 && first_missing < raiddisks && if (assume_clean == 0 && c->force == 0 && first_missing < raiddisks &&
st->ss->external == 0 && st->ss->external == 0 &&
second_missing >= raiddisks && level == 6) { second_missing >= raiddisks && level == 6) {
insert_point = raiddisks - 1; insert_point = raiddisks - 1;
@ -556,7 +555,7 @@ int Create(struct supertype *st, char *mddev,
/* We need to create the device */ /* We need to create the device */
map_lock(&map); map_lock(&map);
mdfd = create_mddev(mddev, name, autof, LOCAL, chosen_name); mdfd = create_mddev(mddev, name, c->autof, LOCAL, chosen_name);
if (mdfd < 0) { if (mdfd < 0) {
map_unlock(&map); map_unlock(&map);
return 1; return 1;
@ -681,14 +680,14 @@ int Create(struct supertype *st, char *mddev,
name += 2; name += 2;
} }
} }
if (!st->ss->init_super(st, &info.array, size, name, homehost, uuid)) if (!st->ss->init_super(st, &info.array, size, name, c->homehost, uuid))
goto abort_locked; goto abort_locked;
total_slots = info.array.nr_disks; total_slots = info.array.nr_disks;
st->ss->getinfo_super(st, &info, NULL); st->ss->getinfo_super(st, &info, NULL);
sysfs_init(&info, mdfd, 0); sysfs_init(&info, mdfd, 0);
if (did_default && verbose >= 0) { if (did_default && c->verbose >= 0) {
if (is_subarray(info.text_version)) { if (is_subarray(info.text_version)) {
int dnum = devname2devnum(info.text_version+1); int dnum = devname2devnum(info.text_version+1);
char *path; char *path;
@ -733,7 +732,7 @@ int Create(struct supertype *st, char *mddev,
goto abort; goto abort;
} }
if (!st->ss->add_internal_bitmap(st, &bitmap_chunk, if (!st->ss->add_internal_bitmap(st, &bitmap_chunk,
delay, write_behind, c->delay, write_behind,
bitmapsize, 1, major_num)) { bitmapsize, 1, major_num)) {
pr_err("Given bitmap chunk size not supported.\n"); pr_err("Given bitmap chunk size not supported.\n");
goto abort; goto abort;
@ -766,7 +765,7 @@ int Create(struct supertype *st, char *mddev,
goto abort; goto abort;
} }
if (mdmon_running(st->container_dev)) { if (mdmon_running(st->container_dev)) {
if (verbose) if (c->verbose)
pr_err("reusing mdmon " pr_err("reusing mdmon "
"for %s.\n", "for %s.\n",
devnum2devname(st->container_dev)); devnum2devname(st->container_dev));
@ -785,8 +784,8 @@ int Create(struct supertype *st, char *mddev,
int uuid[4]; int uuid[4];
st->ss->uuid_from_super(st, uuid); st->ss->uuid_from_super(st, uuid);
if (CreateBitmap(bitmap_file, force, (char*)uuid, bitmap_chunk, if (CreateBitmap(bitmap_file, c->force, (char*)uuid, bitmap_chunk,
delay, write_behind, c->delay, write_behind,
bitmapsize, bitmapsize,
major_num)) { major_num)) {
goto abort; goto abort;
@ -873,7 +872,7 @@ int Create(struct supertype *st, char *mddev,
st->ss->getinfo_super(st, inf, NULL); st->ss->getinfo_super(st, inf, NULL);
safe_mode_delay = inf->safe_mode_delay; safe_mode_delay = inf->safe_mode_delay;
if (have_container && verbose > 0) if (have_container && c->verbose > 0)
pr_err("Using %s for device %d\n", pr_err("Using %s for device %d\n",
map_dev(inf->disk.major, map_dev(inf->disk.major,
inf->disk.minor, inf->disk.minor,
@ -948,10 +947,10 @@ int Create(struct supertype *st, char *mddev,
/* No need to start. But we should signal udev to /* No need to start. But we should signal udev to
* create links */ * create links */
sysfs_uevent(&info, "change"); sysfs_uevent(&info, "change");
if (verbose >= 0) if (c->verbose >= 0)
pr_err("container %s prepared.\n", mddev); pr_err("container %s prepared.\n", mddev);
wait_for(chosen_name, mdfd); wait_for(chosen_name, mdfd);
} else if (runstop == 1 || subdevs >= raiddisks) { } else if (c->runstop == 1 || subdevs >= raiddisks) {
if (st->ss->external) { if (st->ss->external) {
int err; int err;
switch(level) { switch(level) {
@ -959,7 +958,7 @@ int Create(struct supertype *st, char *mddev,
case LEVEL_MULTIPATH: case LEVEL_MULTIPATH:
case 0: case 0:
err = sysfs_set_str(&info, NULL, "array_state", err = sysfs_set_str(&info, NULL, "array_state",
readonly c->readonly
? "readonly" ? "readonly"
: "active"); : "active");
need_mdmon = 0; need_mdmon = 0;
@ -976,7 +975,7 @@ int Create(struct supertype *st, char *mddev,
ioctl(mdfd, STOP_ARRAY, NULL); ioctl(mdfd, STOP_ARRAY, NULL);
goto abort; goto abort;
} }
} else if (readonly && } else if (c->readonly &&
sysfs_attribute_available( sysfs_attribute_available(
&info, NULL, "array_state")) { &info, NULL, "array_state")) {
if (sysfs_set_str(&info, NULL, if (sysfs_set_str(&info, NULL,
@ -1000,7 +999,7 @@ int Create(struct supertype *st, char *mddev,
goto abort; goto abort;
} }
} }
if (verbose >= 0) if (c->verbose >= 0)
pr_err("array %s started.\n", mddev); pr_err("array %s started.\n", mddev);
if (st->ss->external && st->container_dev != NoMdDev) { if (st->ss->external && st->container_dev != NoMdDev) {
if (need_mdmon) if (need_mdmon)

View File

@ -1332,11 +1332,11 @@ int main(int argc, char *argv[])
} }
rv = Create(ss, devlist->devname, chunk, level, layout, size<0 ? 0 : size, rv = Create(ss, devlist->devname, chunk, level, layout, size<0 ? 0 : size,
raiddisks, sparedisks, ident.name, c.homehost, raiddisks, sparedisks, ident.name,
ident.uuid_set ? ident.uuid : NULL, ident.uuid_set ? ident.uuid : NULL,
devs_found-1, devlist->next, c.runstop, devs_found-1, devlist->next,
c.readonly, c.verbose, c.force, assume_clean, assume_clean,
bitmap_file, bitmap_chunk, write_behind, c.delay, c.autof); bitmap_file, bitmap_chunk, write_behind, &c);
break; break;
case MISC: case MISC:
if (devmode == 'E') { if (devmode == 'E') {

View File

@ -1107,11 +1107,11 @@ extern int Build(char *mddev, int chunk, int level, int layout,
extern int Create(struct supertype *st, char *mddev, extern int Create(struct supertype *st, char *mddev,
int chunk, int level, int layout, unsigned long long size, int chunk, int level, int layout, unsigned long long size,
int raiddisks, int sparedisks, int raiddisks, int sparedisks,
char *name, char *homehost, int *uuid, char *name, int *uuid,
int subdevs, struct mddev_dev *devlist, int subdevs, struct mddev_dev *devlist,
int runstop, int readonly, int verbose, int assume_clean,
int force, int assume_clean, char *bitmap_file, int bitmap_chunk, int write_behind,
char *bitmap_file, int bitmap_chunk, int write_behind, int delay, int autof); struct context *c);
extern int Detail(char *dev, int brief, int export, int test, char *homehost, char *prefer); extern int Detail(char *dev, int brief, int export, int test, char *homehost, char *prefer);
extern int Detail_Platform(struct superswitch *ss, int scan, int verbose); extern int Detail_Platform(struct superswitch *ss, int scan, int verbose);