]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Manage.c
--wait or -W will wait for resync activity to finish on the given devices.
[thirdparty/mdadm.git] / Manage.c
index 4cf40e10d04ae56cc697339d275f28e24baab115..0378b6ee1f68f2446214782911c1a71af0029c6b 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -1,7 +1,7 @@
 /*
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au>
+ * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
  *
  *
  *    This program is free software; you can redistribute it and/or modify
@@ -72,6 +72,8 @@ int Manage_ro(char *devname, int fd, int readonly)
        return 0;                       
 }
 
+#ifndef MDASSEMBLE
+
 int Manage_runstop(char *devname, int fd, int runstop, int quiet)
 {
        /* Run or stop the array. array must already be configured
@@ -106,11 +108,13 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet)
                }
        } else if (runstop < 0){
                if (ioctl(fd, STOP_ARRAY, NULL)) {
-                       if (!quiet)
+                       if (quiet==0)
                                fprintf(stderr, Name ": fail to stop array %s: %s\n",
                                        devname, strerror(errno));
                        return 1;
                }
+               if (quiet <= 0)
+                       fprintf(stderr, Name ": stopped %s\n", devname);
        }
        return 0;
 }
@@ -249,14 +253,15 @@ int Manage_subdevs(char *devname, int fd,
                                                continue;
                                        if ((disc.state & 4)==0) continue; /* sync */
                                        /* Looks like a good device to try */
-                                       dev = map_dev(disc.major, disc.minor);
+                                       dev = map_dev(disc.major, disc.minor, 1);
                                        if (!dev) continue;
-                                       dfd = open(dev, O_RDONLY);
+                                       dfd = dev_open(dev, O_RDONLY);
                                        if (dfd < 0) continue;
                                        if (st->ss->load_super(st, dfd, &dsuper, NULL)) {
                                                close(dfd);
                                                continue;
                                        }
+                                       remove_partitions(dfd);
                                        close(dfd);
                                        break;
                                }
@@ -269,8 +274,14 @@ int Manage_subdevs(char *devname, int fd,
                                 * If so, we can simply re-add it.
                                 */
                                st->ss->uuid_from_super(duuid, dsuper);
-                       
-                               if (osuper) {
+
+                               /* re-add doesn't work for version-1 superblocks
+                                * before 2.6.18 :-(
+                                */
+                               if (array.major_version == 1 &&
+                                   get_linux_version() <= 2006018)
+                                       ;
+                               else if (osuper) {
                                        st->ss->uuid_from_super(ouuid, osuper);
                                        if (memcmp(duuid, ouuid, sizeof(ouuid))==0) {
                                                /* look close enough for now.  Kernel
@@ -278,8 +289,7 @@ int Manage_subdevs(char *devname, int fd,
                                                 * based reconstruct is possible
                                                 */
                                                struct mdinfo mdi;
-                                               struct mddev_ident_s ident;
-                                               st->ss->getinfo_super(&mdi, &ident, osuper);
+                                               st->ss->getinfo_super(&mdi, osuper);
                                                disc.major = major(stb.st_rdev);
                                                disc.minor = minor(stb.st_rdev);
                                                disc.number = mdi.disk.number;
@@ -288,13 +298,18 @@ int Manage_subdevs(char *devname, int fd,
                                                if (ioctl(fd, ADD_NEW_DISK, &disc) == 0) {
                                                        if (verbose >= 0)
                                                                fprintf(stderr, Name ": re-added %s\n", dv->devname);
-                                                       return 0;
+                                                       continue;
                                                }
                                                /* fall back on normal-add */
                                        }
                                }
                        }
-                       for (j=0; j< st->max_devs; j++) {
+                       /* in 2.6.17 and earlier, version-1 superblocks won't
+                        * use the number we write, but will choose a free number.
+                        * we must choose the same free number, which requires
+                        * starting at 'raid_disks' and counting up
+                        */
+                       for (j = array.raid_disks; j< st->max_devs; j++) {
                                disc.number = j;
                                if (ioctl(fd, GET_DISK_INFO, &disc))
                                        break;
@@ -342,6 +357,8 @@ int Manage_subdevs(char *devname, int fd,
                                                break;
                                        }
                        }
+                       if (dv->writemostly)
+                               disc.state |= (1 << MD_DISK_WRITEMOSTLY);
                        if (ioctl(fd,ADD_NEW_DISK, &disc)) {
                                fprintf(stderr, Name ": add new device failed for %s as %d: %s\n",
                                        dv->devname, j, strerror(errno));
@@ -379,3 +396,4 @@ int Manage_subdevs(char *devname, int fd,
        return 0;
        
 }
+#endif