diff options
author | NeilBrown <neilb@suse.de> | 2009-11-24 16:32:01 +1100 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2009-11-24 16:32:01 +1100 |
commit | 9277cc7752ae6eb4b10dff7b5fc9ec75d3d52b66 (patch) | |
tree | 08d95ee3f170369863288356c84e45d87b93d876 | |
parent | 40bc78f5cd292d90917cb0a8c177498a516494c3 (diff) | |
download | mdadm-9277cc7752ae6eb4b10dff7b5fc9ec75d3d52b66.tar.gz mdadm-9277cc7752ae6eb4b10dff7b5fc9ec75d3d52b66.tar.xz mdadm-9277cc7752ae6eb4b10dff7b5fc9ec75d3d52b66.zip |
Various fixes for --kill
- When --kill-superblock is used with --metadata, find every
different superblock if there are several and kill them all.
- When creating a new array, kill off any old metadata. The code
to do this was already present but has become broken over time.
Signed-off-by: NeilBrown <neilb@suse.de>
-rw-r--r-- | Kill.c | 10 | ||||
-rw-r--r-- | mdadm.c | 11 | ||||
-rw-r--r-- | mdadm.h | 2 | ||||
-rw-r--r-- | super0.c | 4 | ||||
-rw-r--r-- | super1.c | 4 |
5 files changed, 20 insertions, 11 deletions
@@ -29,7 +29,7 @@ #include "md_u.h" #include "md_p.h" -int Kill(char *dev, int force, int quiet, int noexcl) +int Kill(char *dev, struct supertype *st, int force, int quiet, int noexcl) { /* * Nothing fancy about Kill. It just zeroes out a superblock @@ -37,11 +37,10 @@ int Kill(char *dev, int force, int quiet, int noexcl) */ int fd, rv = 0; - struct supertype *st; if (force) noexcl = 1; - fd = open(dev, O_RDWR|(force ? 0 : O_EXCL)); + fd = open(dev, O_RDWR|(noexcl ? 0 : O_EXCL)); if (fd < 0) { if (!quiet) fprintf(stderr, Name ": Couldn't open %s for write - not zeroing\n", @@ -49,12 +48,13 @@ int Kill(char *dev, int force, int quiet, int noexcl) close(fd); return 1; } - st = guess_super(fd); + if (st == NULL) + st = guess_super(fd); if (st == NULL) { if (!quiet) fprintf(stderr, Name ": Unrecognised md component device - %s\n", dev); close(fd); - return 1; + return 2; } rv = st->ss->load_super(st, fd, dev); if (force && rv >= 2) @@ -1361,7 +1361,16 @@ int main(int argc, char *argv[]) export, test, homehost); continue; case 'K': /* Zero superblock */ - rv |= Kill(dv->devname, force, quiet,0); + if (ss) + rv |= Kill(dv->devname, ss, force, quiet,0); + else { + int q = quiet; + do { + rv |= Kill(dv->devname, NULL, force, q, 0); + q = 1; + } while ((rv & 2) == 0); + rv &= ~2; + } continue; case 'Q': rv |= Query(dv->devname); continue; @@ -756,7 +756,7 @@ extern int Monitor(mddev_dev_t devlist, int period, int daemonise, int scan, int oneshot, int dosyslog, int test, char *pidfile, int increments); -extern int Kill(char *dev, int force, int quiet, int noexcl); +extern int Kill(char *dev, struct supertype *st, int force, int quiet, int noexcl); extern int Wait(char *dev); extern int WaitClean(char *dev, int sock, int verbose); @@ -725,8 +725,8 @@ static int write_init_super0(struct supertype *st) continue; if (di->fd == -1) continue; - Kill(di->devname, 0, 1, 1); - Kill(di->devname, 0, 1, 1); + while (Kill(di->devname, NULL, 0, 1, 1) == 0) + ; sb->disks[di->disk.number].state &= ~(1<<MD_DISK_FAULTY); @@ -1016,8 +1016,8 @@ static int write_init_super1(struct supertype *st) if (di->fd < 0) continue; - Kill(di->devname, 0, 1, 1); - Kill(di->devname, 0, 1, 1); + while (Kill(di->devname, NULL, 0, 1, 1) == 0) + ; sb->dev_number = __cpu_to_le32(di->disk.number); if (di->disk.state & (1<<MD_DISK_WRITEMOSTLY)) |