int rv;
int bitmap_fd;
int have_container = 0;
+ int container_fd;
+ int need_mdmon = 0;
unsigned long long bitmapsize;
struct mdinfo *sra;
struct mdinfo info;
}
}
if (level == UnSet) {
- /* "ddf" metadata only supports one level - should possibly
+ /* "ddf" and "imsm" metadata only supports one level - should possibly
* push this into metadata handler??
*/
- if (st && st->ss == &super_ddf)
+ if (st && (st->ss == &super_ddf || st->ss == &super_imsm))
level = LEVEL_CONTAINER;
}
if (!st->ss->init_super(st, &info.array, size, name, homehost, uuid))
return 1;
+ st->ss->getinfo_super(st, &info);
+
if (bitmap_file && vers < 9003) {
major_num = BITMAP_MAJOR_HOSTENDIAN;
#ifdef __BIG_ENDIAN
if (st->ss->external) {
char ver[100];
- strcat(strcpy(ver, "external:"), st->ss->text_version);
+ if (st->ss->external == 1)
+ /* container */
+ strcat(strcpy(ver, "external:"),
+ info.text_version);
+ else {
+ /* member */
+ sprintf(ver, "external:/%s/%d",
+ devnum2devname(st->container_dev),
+ st->container_member);
+ /* When creating a member, we need to be careful
+ * to negotiate with mdmon properly.
+ * If it is already running, we cannot write to
+ * the devices and must ask it to do that part.
+ * If it isn't running, we write to the devices,
+ * and then start it.
+ * We hold an exclusive open on the container
+ * device to make sure mdmon doesn't exit after
+ * we checked that it is running.
+ *
+ * For now, fail if it is already running.
+ */
+ container_fd = open_dev_excl(st->container_dev);
+ if (container_fd < 0) {
+ fprintf(stderr, Name ": Cannot get exclusive "
+ "open on container - weird.\n");
+ return 1;
+ }
+ if (mdmon_running(st->container_dev)) {
+ fprintf(stderr, Name ": mdmon already running "
+ "for %s - sorry\n",
+ devnum2devname(st->container_dev));
+ return 1;
+ }
+ need_mdmon = 1;
+ }
if ((vers % 100) < 2 ||
sra == NULL ||
sysfs_set_str(sra, NULL, "metadata_version",
fd, dv->devname);
break;
case 2:
+ close(fd);
info.component_size = info.array.size * 2;
info.errors = 0;
rv = 0;
if (st->ss->external) {
st->ss->getinfo_super_n(st, &info);
- rv = sysfs_add_disk(sra, fd, &info);
- close(fd);
+ rv = sysfs_add_disk(sra, &info);
} else {
- close(fd);
rv = ioctl(mdfd, ADD_NEW_DISK,
&info.disk);
}
case 0:
sysfs_set_str(sra, NULL, "array_state",
"active");
+ need_mdmon = 0;
break;
default:
sysfs_set_str(sra, NULL, "array_state",
}
if (verbose >= 0)
fprintf(stderr, Name ": array %s started.\n", mddev);
+ if (st->ss->external == 2) {
+ if (need_mdmon) {
+ int dn = st->container_dev;
+ int i;
+ switch(fork()) {
+ case 0:
+ /* FIXME yuk. CLOSE_EXEC?? */
+ for (i=3; i < 100; i++)
+ close(i);
+ execl("./mdmon", "mdmon",
+ map_dev(dev2major(dn),
+ dev2minor(dn),
+ 1), NULL);
+ exit(1);
+ case -1: fprintf(stderr, Name ": cannot fork. "
+ "Array remains readonly\n");
+ return 1;
+ default: ; /* parent - good */
+ }
+ } else
+ signal_mdmon(st->container_dev);
+ /* FIXME wait for mdmon to set array to read-auto */
+ sleep(1);
+ close(container_fd);
+ }
} else {
fprintf(stderr, Name ": not starting array - not enough devices.\n");
}