]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Various fixes for --kill
authorNeilBrown <neilb@suse.de>
Tue, 24 Nov 2009 05:32:01 +0000 (16:32 +1100)
committerNeilBrown <neilb@suse.de>
Tue, 24 Nov 2009 05:32:01 +0000 (16:32 +1100)
- 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>
Kill.c
mdadm.c
mdadm.h
super0.c
super1.c

diff --git a/Kill.c b/Kill.c
index f5c582180ac28d7a8593657f42b02d481aa352be..63442a628313b5dce794455c9a17220c2435b34d 100644 (file)
--- a/Kill.c
+++ b/Kill.c
@@ -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)
diff --git a/mdadm.c b/mdadm.c
index 3dc8be950121cadb279498d787c653c70be91d76..74a39a88584b9bf4ac9885d9b21f534f8d8175f2 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -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;
diff --git a/mdadm.h b/mdadm.h
index 261cdb729244d8793f38e91b3d691e09114fb053..c7f864bba4485a80239a85b85dd9e04834a982ca 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -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);
 
index 15b3ca2f6ba5069f9146eb63a1fa5ffb58ee58b7..0485a3a103df69ecc90f5479de0c37fdf1441ee6 100644 (file)
--- a/super0.c
+++ b/super0.c
@@ -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);
 
index 5a2df0e18ff8560a65490faafc2dbeefedb674ce..2c992a4b1590f7198c10aed8555a3130ad9ec85c 100644 (file)
--- a/super1.c
+++ b/super1.c
@@ -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))