]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Kill old superblocks on create.
authorNeil Brown <neilb@suse.de>
Tue, 28 Mar 2006 23:22:58 +0000 (23:22 +0000)
committerNeil Brown <neilb@suse.de>
Tue, 28 Mar 2006 23:22:58 +0000 (23:22 +0000)
Make sure old-version superblocks are not around to confuse anything
when a new array is created.

Signed-off-by: Neil Brown <neilb@suse.de>
Create.c
Kill.c
mdadm.c
mdadm.h

index 71bab18b7f414b10810fb5ed1cb30758c05b4f94..df6d850ce249730e24af536d2c1ca119a56ff990 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -502,6 +502,8 @@ int Create(struct supertype *st, char *mddev, int mdfd,
                                break;
                        case 2:
                                if (disk.state == 1) break;
+                               Kill(dv->devname, 0, 1); /* Just be sure it is clean */
+                               Kill(dv->devname, 0, 1); /* and again, there could be two superblocks */
                                st->ss->write_init_super(st, super, &disk, dv->devname);
 
                                if (ioctl(mdfd, ADD_NEW_DISK, &disk)) {
diff --git a/Kill.c b/Kill.c
index 95ab15ca374b0955724c86b7954a0d1ac0e8dd45..2f28b9901d1dd706424c0a0a949ea716bfd3a880 100644 (file)
--- a/Kill.c
+++ b/Kill.c
@@ -34,7 +34,7 @@
 #include       "md_u.h"
 #include       "md_p.h"
 
-int Kill(char *dev, int force)
+int Kill(char *dev, int force, int quiet)
 {
        /*
         * Nothing fancy about Kill.  It just zeroes out a superblock
@@ -47,13 +47,15 @@ int Kill(char *dev, int force)
                
        fd = open(dev, O_RDWR|O_EXCL);
        if (fd < 0) {
-               fprintf(stderr, Name ": Couldn't open %s for write - not zeroing\n",
-                       dev);
+               if (!quiet)
+                       fprintf(stderr, Name ": Couldn't open %s for write - not zeroing\n",
+                               dev);
                return 1;
        }
        st = guess_super(fd);
        if (st == NULL) {
-               fprintf(stderr, Name ": Unrecognised md component device - %s\n", dev);
+               if (!quiet)
+                       fprintf(stderr, Name ": Unrecognised md component device - %s\n", dev);
                return 1;
        }
        rv = st->ss->load_super(st, fd, &super, dev);
@@ -65,11 +67,13 @@ int Kill(char *dev, int force)
                free(super);
                st->ss->init_super(st, &super, &info, 0, "");
                if (st->ss->store_super(st, fd, super)) {
-                       fprintf(stderr, Name ": Could not zero superblock on %s\n",
-                               dev);
+                       if (!quiet)
+                               fprintf(stderr, Name ": Could not zero superblock on %s\n",
+                                       dev);
                        rv = 1;
                } else if (rv) {
-                       fprintf(stderr, Name ": superblock zeroed anyway\n");
+                       if (!quiet)
+                               fprintf(stderr, Name ": superblock zeroed anyway\n");
                        rv = 0;
                }
        }
diff --git a/mdadm.c b/mdadm.c
index b32158ed7bdbdca9287de71b4672e4de051fd326..6a5fac3f2e3fc28ebc820022cfb0b2243984a20e 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -1124,7 +1124,7 @@ int main(int argc, char *argv[])
                                case 'D':
                                        rv |= Detail(dv->devname, brief?1+verbose:0, test); continue;
                                case 'K': /* Zero superblock */
-                                       rv |= Kill(dv->devname, force); continue;
+                                       rv |= Kill(dv->devname, force, quiet); continue;
                                case 'Q':
                                        rv |= Query(dv->devname); continue;
                                case 'X':
diff --git a/mdadm.h b/mdadm.h
index a9ae698d36a1b2e7fe07f7b8e15050387b4454cc..b16c75a99759be347d7c78fb35ede31e599d5c46 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -346,7 +346,7 @@ extern int Monitor(mddev_dev_t devlist,
                   int period, int daemonise, int scan, int oneshot,
                   int dosyslog, char *config, int test, char *pidfile);
 
-extern int Kill(char *dev, int force);
+extern int Kill(char *dev, int force, int quiet);
 
 extern int CreateBitmap(char *filename, int force, char uuid[16],
                        unsigned long chunksize, unsigned long daemon_sleep,