We will shortly be feeding more information into the process of
creating array devices, so delay the creation. Still open them
early if the device already exists.
This involves making sure the autof flag is in the right place
so that it can be found at creation time.
Also, Assemble, Build, and Create now always close 'mdfd'.
Signed-off-by: NeilBrown <neilb@suse.de>
-int Assemble(struct supertype *st, char *mddev, int mdfd,
+int Assemble(struct supertype *st, char *mddev,
mddev_ident_t ident,
mddev_dev_t devlist, char *backup_file,
int readonly, int runstop,
mddev_ident_t ident,
mddev_dev_t devlist, char *backup_file,
int readonly, int runstop,
+ int auto_assem = (mddev == NULL);
int old_linux = 0;
int vers = 0; /* Keep gcc quite - it really is initialised */
struct {
int old_linux = 0;
int vers = 0; /* Keep gcc quite - it really is initialised */
struct {
int change = 0;
int inargv = 0;
int bitmap_done;
int change = 0;
int inargv = 0;
int bitmap_done;
- int start_partial_ok = (runstop >= 0) && (force || devlist==NULL || mdfd < 0);
+ int start_partial_ok = (runstop >= 0) &&
+ (force || devlist==NULL || auto_assem);
unsigned int num_devs;
mddev_dev_t tmpdev;
struct mdinfo info;
unsigned int num_devs;
mddev_dev_t tmpdev;
struct mdinfo info;
if (get_linux_version() < 2004000)
old_linux = 1;
if (get_linux_version() < 2004000)
old_linux = 1;
+ if (mddev != NULL) {
+ /* We need to create the device */
+ mdfd = create_mddev(mddev, 1);
+ if (mdfd < 0)
+ return 1;
+ }
+
if (mdfd >= 0) {
vers = md_get_version(mdfd);
if (vers <= 0) {
fprintf(stderr, Name ": %s appears not to be an md device.\n", mddev);
if (mdfd >= 0) {
vers = md_get_version(mdfd);
if (vers <= 0) {
fprintf(stderr, Name ": %s appears not to be an md device.\n", mddev);
return 1;
}
if (vers < 9000) {
fprintf(stderr, Name ": Assemble requires driver version 0.90.0 or later.\n"
" Upgrade your kernel or try --build\n");
return 1;
}
if (vers < 9000) {
fprintf(stderr, Name ": Assemble requires driver version 0.90.0 or later.\n"
" Upgrade your kernel or try --build\n");
return 1;
}
if (ioctl(mdfd, GET_ARRAY_INFO, &info.array)>=0) {
fprintf(stderr, Name ": device %s already active - cannot assemble it\n",
mddev);
return 1;
}
if (ioctl(mdfd, GET_ARRAY_INFO, &info.array)>=0) {
fprintf(stderr, Name ": device %s already active - cannot assemble it\n",
mddev);
return 1;
}
ioctl(mdfd, STOP_ARRAY, NULL); /* just incase it was started but has no content */
return 1;
}
ioctl(mdfd, STOP_ARRAY, NULL); /* just incase it was started but has no content */
ident->devices == NULL) {
fprintf(stderr, Name ": No identity information available for %s - cannot assemble.\n",
mddev ? mddev : "further assembly");
ident->devices == NULL) {
fprintf(stderr, Name ": No identity information available for %s - cannot assemble.\n",
mddev ? mddev : "further assembly");
+ if (mdfd >= 0)
+ close(mdfd);
#endif
if (devlist == NULL)
devlist = conf_get_devs();
#endif
if (devlist == NULL)
devlist = conf_get_devs();
devname);
if (st)
st->ss->free_super(st);
devname);
if (st)
st->ss->free_super(st);
+ if (mdfd >= 0)
+ close(mdfd);
devname);
tst->ss->free_super(tst);
st->ss->free_super(st);
devname);
tst->ss->free_super(tst);
st->ss->free_super(st);
+ if (mdfd >= 0)
+ close(mdfd);
fprintf(stderr, Name ": %s needed for %s...\n",
mddev, tmpdev->devname);
close(mdfd);
fprintf(stderr, Name ": %s needed for %s...\n",
mddev, tmpdev->devname);
close(mdfd);
st->ss->free_super(st);
free(devices);
goto try_again;
}
st->ss->free_super(st);
free(devices);
goto try_again;
}
}
/* Ok, no bad inconsistancy, we can try updating etc */
}
/* Ok, no bad inconsistancy, we can try updating etc */
inargv ? "the list" :
"the\n DEVICE list in mdadm.conf"
);
inargv ? "the list" :
"the\n DEVICE list in mdadm.conf"
);
- if (must_close) close(mdfd);
return 1;
}
if (best[i] == -1
return 1;
}
if (best[i] == -1
mddev);
if (st)
st->ss->free_super(st);
mddev);
if (st)
st->ss->free_super(st);
- if (must_close) close(mdfd);
if ((fd=dev_open(devices[j].devname, O_RDONLY|O_EXCL))< 0) {
fprintf(stderr, Name ": Cannot open %s: %s\n",
devices[j].devname, strerror(errno));
if ((fd=dev_open(devices[j].devname, O_RDONLY|O_EXCL))< 0) {
fprintf(stderr, Name ": Cannot open %s: %s\n",
devices[j].devname, strerror(errno));
- if (must_close) close(mdfd);
return 1;
}
if (st->ss->load_super(st,fd, NULL)) {
close(fd);
fprintf(stderr, Name ": RAID superblock has disappeared from %s\n",
devices[j].devname);
return 1;
}
if (st->ss->load_super(st,fd, NULL)) {
close(fd);
fprintf(stderr, Name ": RAID superblock has disappeared from %s\n",
devices[j].devname);
- if (must_close) close(mdfd);
return 1;
}
close(fd);
}
if (st->sb == NULL) {
fprintf(stderr, Name ": No suitable drives found for %s\n", mddev);
return 1;
}
close(fd);
}
if (st->sb == NULL) {
fprintf(stderr, Name ": No suitable drives found for %s\n", mddev);
- if (must_close) close(mdfd);
return 1;
}
st->ss->getinfo_super(st, &info);
return 1;
}
st->ss->getinfo_super(st, &info);
if (fd < 0) {
fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n",
devices[chosen_drive].devname);
if (fd < 0) {
fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n",
devices[chosen_drive].devname);
- if (must_close) close(mdfd);
return 1;
}
if (st->ss->store_super(st, fd)) {
close(fd);
fprintf(stderr, Name ": Could not re-write superblock on %s\n",
devices[chosen_drive].devname);
return 1;
}
if (st->ss->store_super(st, fd)) {
close(fd);
fprintf(stderr, Name ": Could not re-write superblock on %s\n",
devices[chosen_drive].devname);
- if (must_close) close(mdfd);
}
if (err) {
fprintf(stderr, Name ": Failed to restore critical section for reshape, sorry.\n");
}
if (err) {
fprintf(stderr, Name ": Failed to restore critical section for reshape, sorry.\n");
- if (must_close) close(mdfd);
if (rv) {
fprintf(stderr, Name ": failed to set array info for %s: %s\n",
mddev, strerror(errno));
if (rv) {
fprintf(stderr, Name ": failed to set array info for %s: %s\n",
mddev, strerror(errno));
- if (must_close) close(mdfd);
return 1;
}
if (ident->bitmap_fd >= 0) {
if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) {
fprintf(stderr, Name ": SET_BITMAP_FILE failed.\n");
return 1;
}
if (ident->bitmap_fd >= 0) {
if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) {
fprintf(stderr, Name ": SET_BITMAP_FILE failed.\n");
- if (must_close) close(mdfd);
return 1;
}
} else if (ident->bitmap_file) {
return 1;
}
} else if (ident->bitmap_file) {
if (bmfd < 0) {
fprintf(stderr, Name ": Could not open bitmap file %s\n",
ident->bitmap_file);
if (bmfd < 0) {
fprintf(stderr, Name ": Could not open bitmap file %s\n",
ident->bitmap_file);
- if (must_close) close(mdfd);
return 1;
}
if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) {
fprintf(stderr, Name ": Failed to set bitmapfile for %s\n", mddev);
close(bmfd);
return 1;
}
if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) {
fprintf(stderr, Name ": Failed to set bitmapfile for %s\n", mddev);
close(bmfd);
- if (must_close) close(mdfd);
info.array.raid_disks);
fprintf(stderr, "\n");
}
info.array.raid_disks);
fprintf(stderr, "\n");
}
- if (must_close)
- close(mdfd);
fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
fprintf(stderr, ".\n");
}
fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
fprintf(stderr, ".\n");
}
+ close(mdfd);
+ if (auto_assem) {
/* There is a nasty race with 'mdadm --monitor'.
* If it opens this device before we close it,
* it gets an incomplete open on which IO
/* There is a nasty race with 'mdadm --monitor'.
* If it opens this device before we close it,
* it gets an incomplete open on which IO
"start the array while not clean "
"- consider --force.\n");
"start the array while not clean "
"- consider --force.\n");
ioctl(mdfd, STOP_ARRAY, NULL);
ioctl(mdfd, STOP_ARRAY, NULL);
return 1;
}
if (runstop == -1) {
return 1;
}
if (runstop == -1) {
if (okcnt != info.array.raid_disks)
fprintf(stderr, " (out of %d)", info.array.raid_disks);
fprintf(stderr, ", but not started.\n");
if (okcnt != info.array.raid_disks)
fprintf(stderr, " (out of %d)", info.array.raid_disks);
fprintf(stderr, ", but not started.\n");
- if (must_close) close(mdfd);
return 0;
}
if (verbose >= -1) {
return 0;
}
if (verbose >= -1) {
fprintf(stderr, " (use --run to insist).\n");
}
}
fprintf(stderr, " (use --run to insist).\n");
}
}
ioctl(mdfd, STOP_ARRAY, NULL);
ioctl(mdfd, STOP_ARRAY, NULL);
return 1;
} else {
/* The "chosen_drive" is a good choice, and if necessary, the superblock has
return 1;
} else {
/* The "chosen_drive" is a good choice, and if necessary, the superblock has
- if (must_close) close(mdfd);
#define START_MD _IO (MD_MAJOR, 2)
#define STOP_MD _IO (MD_MAJOR, 3)
#define START_MD _IO (MD_MAJOR, 2)
#define STOP_MD _IO (MD_MAJOR, 3)
-int Build(char *mddev, int mdfd, int chunk, int level, int layout,
- int raiddisks,
- mddev_dev_t devlist, int assume_clean,
- char *bitmap_file, int bitmap_chunk, int write_behind, int delay, int verbose)
+int Build(char *mddev, int chunk, int level, int layout,
+ int raiddisks, mddev_dev_t devlist, int assume_clean,
+ char *bitmap_file, int bitmap_chunk, int write_behind,
+ int delay, int verbose, int autof)
{
/* Build a linear or raid0 arrays without superblocks
* We cannot really do any checks, we just do it.
{
/* Build a linear or raid0 arrays without superblocks
* We cannot really do any checks, we just do it.
int bitmap_fd;
unsigned long long size = ~0ULL;
unsigned long long bitmapsize;
int bitmap_fd;
unsigned long long size = ~0ULL;
unsigned long long bitmapsize;
/* scan all devices, make sure they really are block devices */
for (dv = devlist; dv; dv=dv->next) {
/* scan all devices, make sure they really are block devices */
for (dv = devlist; dv; dv=dv->next) {
+ /* We need to create the device */
+ mdfd = create_mddev(mddev, autof);
+ if (mdfd < 0)
+ return 1;
vers = md_get_version(mdfd);
vers = md_get_version(mdfd);
if (ioctl(mdfd, SET_ARRAY_INFO, &array)) {
fprintf(stderr, Name ": SET_ARRAY_INFO failed for %s: %s\n",
mddev, strerror(errno));
if (ioctl(mdfd, SET_ARRAY_INFO, &array)) {
fprintf(stderr, Name ": SET_ARRAY_INFO failed for %s: %s\n",
mddev, strerror(errno));
}
} else if (bitmap_file) {
fprintf(stderr, Name ": bitmaps not supported with this kernel\n");
}
} else if (bitmap_file) {
fprintf(stderr, Name ": bitmaps not supported with this kernel\n");
}
if (bitmap_file && level <= 0) {
fprintf(stderr, Name ": bitmaps not meaningful with level %s\n",
map_num(pers, level)?:"given");
}
if (bitmap_file && level <= 0) {
fprintf(stderr, Name ": bitmaps not meaningful with level %s\n",
map_num(pers, level)?:"given");
}
/* now add the devices */
for ((i=0), (dv = devlist) ; dv ; i++, dv=dv->next) {
}
/* now add the devices */
for ((i=0), (dv = devlist) ; dv ; i++, dv=dv->next) {
if (bitmap_chunk == UnSet) {
fprintf(stderr, Name ": %s cannot be openned.",
bitmap_file);
if (bitmap_chunk == UnSet) {
fprintf(stderr, Name ": %s cannot be openned.",
bitmap_file);
}
#endif
if (vers < 9003) {
}
#endif
if (vers < 9003) {
bitmapsize = size>>9; /* FIXME wrong for RAID10 */
if (CreateBitmap(bitmap_file, 1, NULL, bitmap_chunk,
delay, write_behind, bitmapsize, major)) {
bitmapsize = size>>9; /* FIXME wrong for RAID10 */
if (CreateBitmap(bitmap_file, 1, NULL, bitmap_chunk,
delay, write_behind, bitmapsize, major)) {
}
bitmap_fd = open(bitmap_file, O_RDWR);
if (bitmap_fd < 0) {
fprintf(stderr, Name ": %s cannot be openned.",
bitmap_file);
}
bitmap_fd = open(bitmap_file, O_RDWR);
if (bitmap_fd < 0) {
fprintf(stderr, Name ": %s cannot be openned.",
bitmap_file);
}
}
if (bitmap_fd >= 0) {
if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) {
fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n",
mddev, strerror(errno));
}
}
if (bitmap_fd >= 0) {
if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) {
fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n",
mddev, strerror(errno));
if (verbose >= 0)
fprintf(stderr, Name ": array %s built and started.\n",
mddev);
if (verbose >= 0)
fprintf(stderr, Name ": array %s built and started.\n",
mddev);
ioctl(mdfd, STOP_ARRAY, 0);
else
ioctl(mdfd, STOP_MD, 0);
ioctl(mdfd, STOP_ARRAY, 0);
else
ioctl(mdfd, STOP_MD, 0);
#include "md_p.h"
#include <ctype.h>
#include "md_p.h"
#include <ctype.h>
-int Create(struct supertype *st, char *mddev, int mdfd,
+int Create(struct supertype *st, char *mddev,
int chunk, int level, int layout, unsigned long long size, int raiddisks, int sparedisks,
char *name, char *homehost, int *uuid,
int subdevs, mddev_dev_t devlist,
int runstop, int verbose, int force, int assume_clean,
int chunk, int level, int layout, unsigned long long size, int raiddisks, int sparedisks,
char *name, char *homehost, int *uuid,
int subdevs, mddev_dev_t devlist,
int runstop, int verbose, int force, int assume_clean,
- char *bitmap_file, int bitmap_chunk, int write_behind, int delay)
+ char *bitmap_file, int bitmap_chunk, int write_behind, int delay, int autof)
{
/*
* Create a new raid array.
{
/*
* Create a new raid array.
* if runstop==run, or raiddisks disks were used,
* RUN_ARRAY
*/
* if runstop==run, or raiddisks disks were used,
* RUN_ARRAY
*/
unsigned long long minsize=0, maxsize=0;
char *mindisc = NULL;
char *maxdisc = NULL;
unsigned long long minsize=0, maxsize=0;
char *mindisc = NULL;
char *maxdisc = NULL;
memset(&info, 0, sizeof(info));
memset(&info, 0, sizeof(info));
- vers = md_get_version(mdfd);
- if (vers < 9000) {
- fprintf(stderr, Name ": Create requires md driver version 0.90.0 or later\n");
- return 1;
- } else {
- mdu_array_info_t inf;
- memset(&inf, 0, sizeof(inf));
- ioctl(mdfd, GET_ARRAY_INFO, &inf);
- if (inf.working_disks != 0) {
- fprintf(stderr, Name ": another array by this name"
- " is already running.\n");
- return 1;
- }
- }
if (level == UnSet) {
/* "ddf" and "imsm" metadata only supports one level - should possibly
* push this into metadata handler??
if (level == UnSet) {
/* "ddf" and "imsm" metadata only supports one level - should possibly
* push this into metadata handler??
+ /* We need to create the device */
+ mdfd = create_mddev(mddev, autof);
+ if (mdfd < 0)
+ return 1;
+
+ vers = md_get_version(mdfd);
+ if (vers < 9000) {
+ fprintf(stderr, Name ": Create requires md driver version 0.90.0 or later\n");
+ goto abort;
+ } else {
+ mdu_array_info_t inf;
+ memset(&inf, 0, sizeof(inf));
+ ioctl(mdfd, GET_ARRAY_INFO, &inf);
+ if (inf.working_disks != 0) {
+ fprintf(stderr, Name ": another array by this name"
+ " is already running.\n");
+ goto abort;
+ }
+ }
/* Ok, lets try some ioctls */
info.array.level = level;
/* Ok, lets try some ioctls */
info.array.level = level;
}
}
if (!st->ss->init_super(st, &info.array, size, name, homehost, uuid))
}
}
if (!st->ss->init_super(st, &info.array, size, name, homehost, uuid))
total_slots = info.array.nr_disks;
sysfs_init(&info, mdfd, 0);
total_slots = info.array.nr_disks;
sysfs_init(&info, mdfd, 0);
if (bitmap_file && strcmp(bitmap_file, "internal")==0) {
if ((vers%100) < 2) {
fprintf(stderr, Name ": internal bitmaps not supported by this kernel.\n");
if (bitmap_file && strcmp(bitmap_file, "internal")==0) {
if ((vers%100) < 2) {
fprintf(stderr, Name ": internal bitmaps not supported by this kernel.\n");
}
if (!st->ss->add_internal_bitmap(st, &bitmap_chunk,
delay, write_behind,
bitmapsize, 1, major_num)) {
fprintf(stderr, Name ": Given bitmap chunk size not supported.\n");
}
if (!st->ss->add_internal_bitmap(st, &bitmap_chunk,
delay, write_behind,
bitmapsize, 1, major_num)) {
fprintf(stderr, Name ": Given bitmap chunk size not supported.\n");
if (container_fd < 0) {
fprintf(stderr, Name ": Cannot get exclusive "
"open on container - weird.\n");
if (container_fd < 0) {
fprintf(stderr, Name ": Cannot get exclusive "
"open on container - weird.\n");
}
if (mdmon_running(st->container_dev)) {
if (verbose)
}
if (mdmon_running(st->container_dev)) {
if (verbose)
if (rv) {
fprintf(stderr, Name ": failed to set array info for %s: %s\n",
mddev, strerror(errno));
if (rv) {
fprintf(stderr, Name ": failed to set array info for %s: %s\n",
mddev, strerror(errno));
delay, write_behind,
bitmapsize,
major_num)) {
delay, write_behind,
bitmapsize,
major_num)) {
}
bitmap_fd = open(bitmap_file, O_RDWR);
if (bitmap_fd < 0) {
fprintf(stderr, Name ": weird: %s cannot be openned\n",
bitmap_file);
}
bitmap_fd = open(bitmap_file, O_RDWR);
if (bitmap_fd < 0) {
fprintf(stderr, Name ": weird: %s cannot be openned\n",
bitmap_file);
}
if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) {
fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n",
mddev, strerror(errno));
}
if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) {
fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n",
mddev, strerror(errno));
fprintf(stderr, Name ": failed to open %s "
"after earlier success - aborting\n",
dv->devname);
fprintf(stderr, Name ": failed to open %s "
"after earlier success - aborting\n",
dv->devname);
}
fstat(fd, &stb);
inf->disk.major = major(stb.st_rdev);
}
fstat(fd, &stb);
inf->disk.major = major(stb.st_rdev);
"failed: %s\n",
dv->devname, strerror(errno));
st->ss->free_super(st);
"failed: %s\n",
dv->devname, strerror(errno));
st->ss->free_super(st);
fprintf(stderr, Name ": RUN_ARRAY failed: %s\n",
strerror(errno));
Manage_runstop(mddev, mdfd, -1, 0);
fprintf(stderr, Name ": RUN_ARRAY failed: %s\n",
strerror(errno));
Manage_runstop(mddev, mdfd, -1, 0);
} else {
fprintf(stderr, Name ": not starting array - not enough devices.\n");
}
} else {
fprintf(stderr, Name ": not starting array - not enough devices.\n");
}
+
+ abort:
+ if (mdfd >= 0)
+ close(mdfd);
+ return 1;
fprintf(stderr, Name ": --super-minor=dev is incompatible with --auto\n");
exit(2);
}
fprintf(stderr, Name ": --super-minor=dev is incompatible with --auto\n");
exit(2);
}
- if (mode == MANAGE || mode == GROW)
+ if (mode == MANAGE || mode == GROW) {
mdfd = open_mddev(devlist->devname, 1);
mdfd = open_mddev(devlist->devname, 1);
- else
- mdfd = create_mddev(devlist->devname, autof);
- if (mdfd < 0)
+ if (mdfd < 0)
+ exit(1);
+ } else
+ /* non-existent device is OK */
+ mdfd = open_mddev(devlist->devname, 0);
+ if (mdfd == -2) {
+ fprintf(stderr, Name ": device %s exists but is not an "
+ "md array.\n", devlist->devname);
if ((int)ident.super_minor == -2) {
struct stat stb;
if ((int)ident.super_minor == -2) {
struct stat stb;
+ if (mdfd < 0) {
+ fprintf(stderr, Name ": --super-minor=dev given, and "
+ "listed device %s doesn't exist.\n",
+ devlist->devname);
+ exit(1);
+ }
fstat(mdfd, &stb);
ident.super_minor = minor(stb.st_rdev);
}
fstat(mdfd, &stb);
ident.super_minor = minor(stb.st_rdev);
}
+ if (mdfd >= 0 && mode != MANAGE && mode != GROW) {
+ /* We don't really want this open yet, we just might
+ * have wanted to check some things
+ */
+ close(mdfd);
+ mdfd = -1;
+ }
rv = 0;
switch(mode) {
case MANAGE:
rv = 0;
switch(mode) {
case MANAGE:
fprintf(stderr, Name ": %s not identified in config file.\n",
devlist->devname);
rv |= 1;
fprintf(stderr, Name ": %s not identified in config file.\n",
devlist->devname);
rv |= 1;
+ if (mdfd >= 0)
+ close(mdfd);
- rv |= Assemble(ss, devlist->devname, mdfd, array_ident,
- NULL, backup_file,
- readonly, runstop, update, homehost, verbose-quiet, force);
- close(mdfd);
+ if (array_ident->autof == 0)
+ array_ident->autof = autof;
+ rv |= Assemble(ss, devlist->devname, array_ident,
+ NULL, backup_file,
+ readonly, runstop, update, homehost, verbose-quiet, force);
- rv = Assemble(ss, devlist->devname, mdfd, &ident,
+ rv = Assemble(ss, devlist->devname, &ident,
devlist->next, backup_file,
readonly, runstop, update, homehost, verbose-quiet, force);
else if (devs_found>0) {
devlist->next, backup_file,
readonly, runstop, update, homehost, verbose-quiet, force);
else if (devs_found>0) {
- mdfd = create_mddev(dv->devname,
- array_ident->autof ?array_ident->autof : autof);
- if (mdfd < 0) {
- rv |= 1;
- continue;
- }
- rv |= Assemble(ss, dv->devname, mdfd, array_ident,
+ if (array_ident->autof == 0)
+ array_ident->autof = autof;
+ rv |= Assemble(ss, dv->devname, array_ident,
NULL, backup_file,
readonly, runstop, update, homehost, verbose-quiet, force);
NULL, backup_file,
readonly, runstop, update, homehost, verbose-quiet, force);
}
} else {
mddev_ident_t array_list = conf_get_ident(NULL);
}
} else {
mddev_ident_t array_list = conf_get_ident(NULL);
exit(1);
}
for (; array_list; array_list = array_list->next) {
exit(1);
}
for (; array_list; array_list = array_list->next) {
- mdu_array_info_t array;
- mdfd = create_mddev(array_list->devname,
- array_list->autof ? array_list->autof : autof);
- if (mdfd < 0) {
- rv |= 1;
- continue;
- }
- if (ioctl(mdfd, GET_ARRAY_INFO, &array)>=0)
- /* already assembled, skip */
- cnt++;
- else {
- rv |= Assemble(ss, array_list->devname, mdfd,
- array_list,
- NULL, NULL,
- readonly, runstop, NULL, homehost, verbose-quiet, force);
- if (rv == 0) cnt++;
+ mdfd = open_mddev(array_list->devname, 0);
+ if (mdfd >= 0) {
+ mdu_array_info_t array;
+ /* skip if already assembled */
+ if (ioctl(mdfd, GET_ARRAY_INFO, &array)>=0) {
+ cnt++;
+ close(mdfd);
+ continue;
+ }
+ if (array_list->autof == 0)
+ array_list->autof = autof;
+
+ rv |= Assemble(ss, array_list->devname,
+ array_list,
+ NULL, NULL,
+ readonly, runstop, NULL, homehost, verbose-quiet, force);
+ if (rv == 0) cnt++;
}
if (homehost) {
/* Maybe we can auto-assemble something.
}
if (homehost) {
/* Maybe we can auto-assemble something.
- * Repeatedly call Assemble in auto-assmble mode
+ * Repeatedly call Assemble in auto-assemble mode
* until it fails
*/
int rv2;
* until it fails
*/
int rv2;
mddev_dev_t devlist = conf_get_devs();
acnt = 0;
do {
mddev_dev_t devlist = conf_get_devs();
acnt = 0;
do {
- rv2 = Assemble(ss, NULL, -1,
+ rv2 = Assemble(ss, NULL,
&ident,
devlist, NULL,
readonly, runstop, NULL, homehost, verbose-quiet, force);
&ident,
devlist, NULL,
readonly, runstop, NULL, homehost, verbose-quiet, force);
- rv2 = Assemble(ss, NULL, -1,
+ rv2 = Assemble(ss, NULL,
&ident,
NULL, NULL,
readonly, runstop, "homehost", homehost, verbose-quiet, force);
&ident,
NULL, NULL,
readonly, runstop, "homehost", homehost, verbose-quiet, force);
- rv = Build(devlist->devname, mdfd, chunk, level, layout,
+ rv = Build(devlist->devname, chunk, level, layout,
raiddisks, devlist->next, assume_clean,
raiddisks, devlist->next, assume_clean,
- bitmap_file, bitmap_chunk, write_behind, delay, verbose-quiet);
+ bitmap_file, bitmap_chunk, write_behind,
+ delay, verbose-quiet, autof);
break;
case CREATE:
if (delay == 0) delay = DEFAULT_BITMAP_DELAY;
break;
case CREATE:
if (delay == 0) delay = DEFAULT_BITMAP_DELAY;
- rv = Create(ss, devlist->devname, mdfd, chunk, level, layout, size<0 ? 0 : size,
+ rv = Create(ss, devlist->devname, chunk, level, layout, size<0 ? 0 : size,
raiddisks, sparedisks, ident.name, homehost,
ident.uuid_set ? ident.uuid : NULL,
devs_found-1, devlist->next, runstop, verbose-quiet, force, assume_clean,
raiddisks, sparedisks, ident.name, homehost,
ident.uuid_set ? ident.uuid : NULL,
devs_found-1, devlist->next, runstop, verbose-quiet, force, assume_clean,
- bitmap_file, bitmap_chunk, write_behind, delay);
+ bitmap_file, bitmap_chunk, write_behind, delay, autof);
break;
case MISC:
if (devmode == 'E') {
break;
case MISC:
if (devmode == 'E') {
int *fdlist, int cnt, char *backup_file);
int *fdlist, int cnt, char *backup_file);
-extern int Assemble(struct supertype *st, char *mddev, int mdfd,
+extern int Assemble(struct supertype *st, char *mddev,
mddev_ident_t ident,
mddev_dev_t devlist, char *backup_file,
int readonly, int runstop,
char *update, char *homehost,
int verbose, int force);
mddev_ident_t ident,
mddev_dev_t devlist, char *backup_file,
int readonly, int runstop,
char *update, char *homehost,
int verbose, int force);
-extern int Build(char *mddev, int mdfd, int chunk, int level, int layout,
- int raiddisks,
- mddev_dev_t devlist, int assume_clean,
- char *bitmap_file, int bitmap_chunk, int write_behind, int delay, int verbose);
+extern int Build(char *mddev, int chunk, int level, int layout,
+ int raiddisks, mddev_dev_t devlist, int assume_clean,
+ char *bitmap_file, int bitmap_chunk, int write_behind,
+ int delay, int verbose, int autof);
-extern int Create(struct supertype *st, char *mddev, int mdfd,
+extern int Create(struct supertype *st, char *mddev,
int chunk, int level, int layout, unsigned long long size, int raiddisks, int sparedisks,
char *name, char *homehost, int *uuid,
int subdevs, mddev_dev_t devlist,
int runstop, int verbose, int force, int assume_clean,
int chunk, int level, int layout, unsigned long long size, int raiddisks, int sparedisks,
char *name, char *homehost, int *uuid,
int subdevs, mddev_dev_t devlist,
int runstop, int verbose, int force, int assume_clean,
- char *bitmap_file, int bitmap_chunk, int write_behind, int delay);
+ char *bitmap_file, int bitmap_chunk, int write_behind, int delay, int autof);
extern int Detail(char *dev, int brief, int export, int test, char *homehost);
extern int Query(char *dev);
extern int Detail(char *dev, int brief, int export, int test, char *homehost);
extern int Query(char *dev);
#ifndef MDASSEMBLE_AUTO
/* from mdopen.c */
#ifndef MDASSEMBLE_AUTO
/* from mdopen.c */
-int create_mddev(char *dev, int autof/*unused */)
+int open_mddev(char *dev, int report_errors/*unused*/)
{
int mdfd = open(dev, O_RDWR);
if (mdfd < 0)
{
int mdfd = open(dev, O_RDWR);
if (mdfd < 0)
+int create_mddev(char *dev, int autof/*unused*/)
+{
+ return open_mddev(dev, 0);
+}
} else
for (; array_list; array_list = array_list->next) {
mdu_array_info_t array;
} else
for (; array_list; array_list = array_list->next) {
mdu_array_info_t array;
- mdfd = create_mddev(array_list->devname, array_list->autof);
- if (mdfd < 0) {
- rv |= 1;
- continue;
- }
- if (ioctl(mdfd, GET_ARRAY_INFO, &array) < 0) {
- rv |= Assemble(array_list->st, array_list->devname, mdfd,
- array_list, NULL, NULL,
- readonly, runstop, NULL, NULL, verbose, force);
- } else {
+ mdfd = open_mddev(array_list->devname, 0);
+ if (mdfd >= 0 && ioctl(mdfd, GET_ARRAY_INFO, &array) == 0) {
rv |= Manage_ro(array_list->devname, mdfd, -1); /* make it readwrite */
rv |= Manage_ro(array_list->devname, mdfd, -1); /* make it readwrite */
+ if (mdfd >= 0)
+ close(mdfd);
+ rv |= Assemble(array_list->st, array_list->devname,
+ array_list, NULL, NULL,
+ readonly, runstop, NULL, NULL, verbose, force);