]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Grow.c
Remove partitions from components of an md array
[thirdparty/mdadm.git] / Grow.c
diff --git a/Grow.c b/Grow.c
index 4a225c7342dbd17833015c2e562105afc0ff3215..1ab4fbc9bb542e18af6029a360190d12502b246c 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -1,7 +1,7 @@
 /*
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2001-2004 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
@@ -92,13 +92,13 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
                                d);
                        return 1;
                }
-               dv = map_dev(disk.major, disk.minor);
+               dv = map_dev(disk.major, disk.minor, 1);
                if (!dv) {
                        fprintf(stderr, Name ": cannot find device file for device %d\n",
                                d);
                        return 1;
                }
-               fd2 = open(dv, O_RDWR);
+               fd2 = dev_open(dv, O_RDWR);
                if (!fd2) {
                        fprintf(stderr, Name ": cannot open device file %s\n", dv);
                        return 1;
@@ -121,7 +121,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
        info.disk.minor = minor(stb.st_rdev);
        info.disk.raid_disk = d;
        info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
-       st->ss->update_super(&info, super, "grow", newdev, 0);
+       st->ss->update_super(&info, super, "grow", newdev, 0, 0, NULL);
 
        if (st->ss->store_super(st, nfd, super)) {
                fprintf(stderr, Name ": Cannot store new superblock on %s\n", newdev);
@@ -154,13 +154,13 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
                                d);
                        return 1;
                }
-               dv = map_dev(disk.major, disk.minor);
+               dv = map_dev(disk.major, disk.minor, 1);
                if (!dv) {
                        fprintf(stderr, Name ": cannot find device file for device %d\n",
                                d);
                        return 1;
                }
-               fd2 = open(dv, O_RDWR);
+               fd2 = dev_open(dv, O_RDWR);
                if (fd2 < 0) {
                        fprintf(stderr, Name ": cannot open device file %s\n", dv);
                        return 1;
@@ -179,7 +179,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
                info.disk.minor = minor(stb.st_rdev);
                info.disk.raid_disk = nd;
                info.disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
-               st->ss->update_super(&info, super, "grow", dv, 0);
+               st->ss->update_super(&info, super, "grow", dv, 0, 0, NULL);
                
                if (st->ss->store_super(st, fd2, super)) {
                        fprintf(stderr, Name ": Cannot store new superblock on %s\n", dv);
@@ -272,7 +272,7 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int
        }
 
        if (array.level == 10) {
-               int ncopies = (array.layout&255)*(array.layout>>8);
+               int ncopies = (array.layout&255)*((array.layout>>8)&255);
                bitmapsize = bitmapsize * array.raid_disks / ncopies;
        }
 
@@ -298,10 +298,10 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int
                                continue;
                        if ((disk.state & (1<<MD_DISK_SYNC))==0)
                                continue;
-                       dv = map_dev(disk.major, disk.minor);
+                       dv = map_dev(disk.major, disk.minor, 1);
                        if (dv) {
                                void *super;
-                               int fd2 = open(dv, O_RDWR);
+                               int fd2 = dev_open(dv, O_RDWR);
                                if (fd2 < 0)
                                        continue;
                                if (st->ss->load_super(st, fd2, &super, NULL)==0) {
@@ -329,8 +329,6 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int
                int d;
                int max_devs = st->max_devs;
                void *super = NULL;
-               if (chunk == UnSet)
-                       chunk = DEFAULT_BITMAP_CHUNK;
 
                /* try to load a superblock */
                for (d=0; d<max_devs; d++) {
@@ -343,9 +341,9 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int
                        if ((disk.major==0 && disk.minor==0) ||
                            (disk.state & (1<<MD_DISK_REMOVED)))
                                continue;
-                       dv = map_dev(disk.major, disk.minor);
+                       dv = map_dev(disk.major, disk.minor, 1);
                        if (!dv) continue;
-                       fd2 = open(dv, O_RDONLY);
+                       fd2 = dev_open(dv, O_RDONLY);
                        if (fd2 >= 0 &&
                            st->ss->load_super(st, fd2, &super, NULL) == 0) {
                                close(fd2);
@@ -500,14 +498,21 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                 * other from happening.  Later we could block
                 * resync for the duration via 'sync_action'...
                 */
-               if (raid_disks >= 0)
+               if (raid_disks > 0) {
                        array.raid_disks = raid_disks;
-               if (size >= 0)
+                       if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) {
+                               fprintf(stderr, Name ": Cannot set raid-devices for %s: %s\n",
+                                       devname, strerror(errno));
+                               return 1;
+                       }
+               }
+               if (size >= 0) {
                        array.size = size;
-               if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) {
-                       fprintf(stderr, Name ": Cannot set device size/shape for %s: %s\n",
-                               devname, strerror(errno));
-                       return 1;
+                       if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) {
+                               fprintf(stderr, Name ": Cannot set device size for %s: %s\n",
+                                       devname, strerror(errno));
+                               return 1;
+                       }
                }
                return 0;
 
@@ -647,22 +652,22 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                        if (sd->state & (1<<MD_DISK_FAULTY))
                                continue;
                        if (sd->state & (1<<MD_DISK_SYNC)) {
-                               char *dn = map_dev(sd->major, sd->minor);
-                               fdlist[sd->role] = open(dn, O_RDONLY);
+                               char *dn = map_dev(sd->major, sd->minor, 1);
+                               fdlist[sd->role] = dev_open(dn, O_RDONLY);
                                offsets[sd->role] = sd->offset;
                                if (fdlist[sd->role] < 0) {
                                        fprintf(stderr, Name ": %s: cannot open component %s\n",
-                                               devname, dn);
+                                               devname, dn?dn:"-unknown-");
                                        goto abort;
                                }
                        } else {
                                /* spare */
-                               char *dn = map_dev(sd->major, sd->minor);
-                               fdlist[d] = open(dn, O_RDWR);
+                               char *dn = map_dev(sd->major, sd->minor, 1);
+                               fdlist[d] = dev_open(dn, O_RDWR);
                                offsets[d] = sd->offset;
                                if (fdlist[d]<0) {
                                        fprintf(stderr, Name ": %s: cannot open component %s\n",
-                                               devname, dn);
+                                               devname, dn?dn:"-unknown");
                                        goto abort;
                                }
                                d++;
@@ -796,7 +801,10 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                memset(&bsb, 0, sizeof(bsb));
                for (i=odisks; i<d ; i++) {
                        lseek64(fdlist[i], (offsets[i]+last_block)<<9, 0);
-                       write(fdlist[i], &bsb, sizeof(bsb));
+                       if (write(fdlist[i], &bsb, sizeof(bsb)) < 0) {
+                               fprintf(stderr, Name ": %s: failed to invalidate metadata for raid disk %d\n",
+                                       devname, i);
+                       }
                }
 
                /* unsuspend. */
@@ -869,8 +877,6 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
                        fd = open(backup_file, O_RDONLY);
                        if (fd<0)
                                continue;
-                       if (lseek(fd, 4096, 0) != 4096)
-                               continue;
                } else {
                        fd = fdlist[i];
                        if (fd < 0)
@@ -909,7 +915,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
                /* There should be a duplicate backup superblock 4k before here */
                if (lseek64(fd, -4096, 1) < 0 ||
                    read(fd, buf, 4096) != 4096 ||
-                   memcmp(buf, &bsb, sizeof(buf)) != 0)
+                   memcmp(buf, &bsb, sizeof(bsb)) != 0)
                        continue; /* Cannot find leading superblock */
 
                /* Now need the data offsets for all devices. */
@@ -945,7 +951,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt
                                continue;
                        st->ss->getinfo_super(&dinfo, super);
                        dinfo.reshape_progress = __le64_to_cpu(bsb.length);
-                       st->ss->update_super(&dinfo, super, "_reshape_progress",NULL,0);
+                       st->ss->update_super(&dinfo, super, "_reshape_progress",NULL,0, 0, NULL);
                        st->ss->store_super(st, fdlist[j], super);
                        free(super);
                }