From 6234c63ccc136a66be341c6bdc42eadc08c285d1 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 4 Nov 2008 20:51:11 +1100 Subject: Assemble: factor out assemble_container_content Factor out, from Incremental_container, the code for assembling an array based on information extracted from a container. We will shortly use this from Assemble too. Signed-off-by: Dan Williams Signed-off-by: NeilBrown --- Assemble.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'Assemble.c') diff --git a/Assemble.c b/Assemble.c index 6b1e8df..2fa574c 100644 --- a/Assemble.c +++ b/Assemble.c @@ -1069,3 +1069,71 @@ int Assemble(struct supertype *st, char *mddev, close(mdfd); return 0; } + +#ifndef MDASSEMBLE +int assemble_container_content(struct supertype *st, int mdfd, + struct mdinfo *content, int runstop, + char *chosen_name, int verbose) +{ + struct mdinfo *dev, *sra; + int working = 0, preexist = 0; + struct map_ent *map = NULL; + + sysfs_init(content, mdfd, 0); + + sra = sysfs_read(mdfd, 0, GET_VERSION); + if (sra == NULL || strcmp(sra->text_version, content->text_version) != 0) + if (sysfs_set_array(content, md_get_version(mdfd)) != 0) + return 1; + if (sra) + sysfs_free(sra); + + for (dev = content->devs; dev; dev = dev->next) + if (sysfs_add_disk(content, dev) == 0) + working++; + else if (errno == EEXIST) + preexist++; + if (working == 0) + /* Nothing new, don't try to start */ ; + else if (runstop > 0 || + (working + preexist) >= content->array.working_disks) { + switch(content->array.level) { + case LEVEL_LINEAR: + case LEVEL_MULTIPATH: + case 0: + sysfs_set_str(content, NULL, "array_state", + "active"); + break; + default: + sysfs_set_str(content, NULL, "array_state", + "readonly"); + /* start mdmon if needed. */ + if (!mdmon_running(st->container_dev)) + start_mdmon(st->container_dev); + ping_monitor(devnum2devname(st->container_dev)); + break; + } + sysfs_set_safemode(content, content->safe_mode_delay); + if (verbose >= 0) { + fprintf(stderr, Name + ": Started %s with %d devices", + chosen_name, working + preexist); + if (preexist) + fprintf(stderr, " (%d new)", working); + fprintf(stderr, "\n"); + } + /* FIXME should have an O_EXCL and wait for read-auto */ + } else + if (verbose >= 0) + fprintf(stderr, Name + ": %s assembled with %d devices but " + "not started\n", + chosen_name, working); + map_update(&map, fd2devnum(mdfd), + content->text_version, + content->uuid, chosen_name); + + return 0; +} +#endif + -- cgit