]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Grow.c
Add --auto-detect for in-kernel autodetect.
[thirdparty/mdadm.git] / Grow.c
diff --git a/Grow.c b/Grow.c
index 2a13a710b9775027f3da89f26c62fd1d065bd55e..c28c1ac59e9881671b5f07e5c30fc24089b906d9 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -121,10 +121,12 @@ 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, 0, NULL);
+       st->ss->update_super(&info, super, "linear-grow-new", newdev,
+                            0, 0, NULL);
 
        if (st->ss->store_super(st, nfd, super)) {
-               fprintf(stderr, Name ": Cannot store new superblock on %s\n", newdev);
+               fprintf(stderr, Name ": Cannot store new superblock on %s\n",
+                       newdev);
                close(nfd);
                return 1;
        }
@@ -174,12 +176,9 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
                info.array.nr_disks = nd+1;
                info.array.active_disks = nd+1;
                info.array.working_disks = nd+1;
-               info.disk.number = nd;
-               info.disk.major = major(stb.st_rdev);
-               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, 0, NULL);
+
+               st->ss->update_super(&info, super, "linear-grow-update", dv,
+                                    0, 0, NULL);
                
                if (st->ss->store_super(st, fd2, super)) {
                        fprintf(stderr, Name ": Cannot store new superblock on %s\n", dv);
@@ -257,15 +256,13 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int
        }
        bitmapsize = array.size;
        bitmapsize <<= 1;
-#ifdef BLKGETSIZE64
-       if (ioctl(fd, BLKGETSIZE64, &array_size) == 0 &&
+       if (get_dev_size(fd, NULL, &array_size) &&
            array_size > (0x7fffffffULL<<9)) {
                /* Array is big enough that we cannot trust array.size
                 * try other approaches
                 */
                bitmapsize = get_component_size(fd);
        }
-#endif
        if (bitmapsize == 0) {
                fprintf(stderr, Name ": Cannot reliably determine size of array to create bitmap - sorry.\n");
                return 1;
@@ -523,7 +520,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
        case 6:
                st = super_by_version(array.major_version,
                                      array.minor_version);
-               /* size can be changed independantly.
+               /* size can be changed independently.
                 * layout/chunksize/raid_disks/level can be changed
                 * though the kernel may not support it all.
                 * If 'suspend_lo' is not present in devfs, then
@@ -620,7 +617,8 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                printf("mdadm: Need to backup %lluK of critical section..\n", last_block/2);
 
                sra = sysfs_read(fd, 0,
-                                GET_COMPONENT|GET_DEVS|GET_OFFSET|GET_STATE);
+                                GET_COMPONENT|GET_DEVS|GET_OFFSET|GET_STATE|
+                                GET_CACHE);
                if (!sra) {
                        fprintf(stderr, Name ": %s: Cannot get array details from sysfs\n",
                                devname);
@@ -742,10 +740,25 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                array.chunk_size = nchunk;
                array.layout = nlayout;
                if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) {
+                       if (errno == ENOSPC) {
+                               /* stripe cache is not big enough.
+                                * It needs to be 4 times chunksize_size,
+                                * and we assume pagesize is 4K
+                                */
+                               if (sra->cache_size < 4 * (nchunk/4096)) {
+                                       sysfs_set_num(sra, NULL,
+                                                     "stripe_cache_size",
+                                                     4 * (nchunk/4096) +1);
+                                       if (ioctl(fd, SET_ARRAY_INFO,
+                                                 &array) == 0)
+                                               goto ok;
+                               }
+                       }
                        fprintf(stderr, Name ": Cannot set device size/shape for %s: %s\n",
                                devname, strerror(errno));
                        goto abort;
                }
+               ok: ;
 
                /* suspend the relevant region */
                sysfs_set_num(sra, NULL, "suspend_hi", 0); /* just in case */