From: Neil Brown Date: Mon, 26 May 2008 23:18:43 +0000 (+1000) Subject: allow --incremental to reuse devices that already exist X-Git-Tag: devel~18 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=25dbe93ab48b6cb45e1fc72b27aaa75d4c1fa48c;p=thirdparty%2Fmdadm.git allow --incremental to reuse devices that already exist .. and other fixes. --- diff --git a/Incremental.c b/Incremental.c index 2c03a146..18cdf3fa 100644 --- a/Incremental.c +++ b/Incremental.c @@ -237,6 +237,7 @@ int Incremental(char *devname, int verbose, int runstop, /* Have to guess a bit. */ int use_partitions = 1; char *np, *ep; + char *nm, nbuf[1024]; if ((autof&7) == 3 || (autof&7) == 5) use_partitions = 0; np = strchr(info.name, ':'); @@ -252,6 +253,24 @@ int Incremental(char *devname, int verbose, int runstop, } else devnum = -1; + if (match) + nm = match->devname; + else { + sprintf(nbuf, "/dev/md/%s", np); + nm = nbuf; + } + if (stat(nm, &stb) == 0 && + S_ISBLK(stb.st_mode) && + major(stb.st_rdev) == (use_partitions ? + get_mdp_major() : MD_MAJOR)) { + if (use_partitions) + devnum = minor(stb.st_rdev) >> MdpMinorShift; + else + devnum = minor(stb.st_rdev); + if (mddev_busy(use_partitions ? (-1-devnum) : devnum)) + devnum = -1; + } + if (devnum < 0) { /* Haven't found anything yet, choose something free */ devnum = find_free_devnum(use_partitions); @@ -774,6 +793,28 @@ int Incremental_container(struct supertype *st, char *devname, int verbose, devnum = -1; } + if (devnum < 0) { + char *nm = ra->name; + char nbuf[1024]; + struct stat stb; + if (strchr(nm, ':')) + nm = strchr(nm, ':')+1; + sprintf(nbuf, "/dev/md/%s", nm); + + if (stat(nbuf, &stb) == 0 && + S_ISBLK(stb.st_mode) && + major(stb.st_rdev) == (usepart ? + get_mdp_major() : MD_MAJOR)){ + if (usepart) + devnum = minor(stb.st_rdev) + >> MdpMinorShift; + else + devnum = minor(stb.st_rdev); + if (mddev_busy(usepart ? (-1-devnum) : devnum)) + devnum = -1; + } + } + if (devnum >= 0) devnum = usepart ? (-1-devnum) : devnum; else diff --git a/super-ddf.c b/super-ddf.c index 285563b4..f0cb1f1f 100644 --- a/super-ddf.c +++ b/super-ddf.c @@ -2670,7 +2670,6 @@ struct superswitch super_ddf = { /* for mdmon */ .open_new = ddf_open_new, - .load_super = load_super_ddf, .mark_clean = ddf_mark_clean, .set_disk = ddf_set_disk, .sync_metadata = ddf_sync_metadata, @@ -2687,8 +2686,10 @@ struct superswitch super_ddf_container = { .write_init_super = write_init_super_ddf, #endif + .load_super = load_super_ddf, .init_super = init_super_ddf, .add_to_super = add_to_super_ddf, + .getinfo_super = getinfo_super_ddf, .free_super = free_super_ddf,