]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - sysfs.c
Increase raid456 stripe cache size if needed to --grow the array.
[thirdparty/mdadm.git] / sysfs.c
diff --git a/sysfs.c b/sysfs.c
index 989476068da6eb0aee77e5aef68e09e03574653d..166481f1a54580f652d191a932251dfbfa4190bd 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -69,7 +69,7 @@ struct sysarray *sysfs_read(int fd, int devnum, unsigned long options)
                        sprintf(sra->name, "md%d", minor(stb.st_rdev));
                else
                        sprintf(sra->name, "md_d%d",
-                               minor(stb.st_rdev)/16);
+                               minor(stb.st_rdev)>>MdpMinorShift);
        } else {
                if (devnum >= 0)
                        sprintf(sra->name, "md%d", devnum);
@@ -98,6 +98,8 @@ struct sysarray *sysfs_read(int fd, int devnum, unsigned long options)
                if (load_sys(fname, buf))
                        goto abort;
                sra->component_size = strtoull(buf, NULL, 0);
+               /* sysfs reports "K", but we want sectors */
+               sra->component_size *= 2;
        }
        if (options & GET_CHUNK) {
                strcpy(base, "chunk_size");
@@ -105,6 +107,12 @@ struct sysarray *sysfs_read(int fd, int devnum, unsigned long options)
                        goto abort;
                sra->chunk = strtoul(buf, NULL, 0);
        }
+       if (options & GET_CACHE) {
+               strcpy(base, "stripe_cache_size");
+               if (load_sys(fname, buf))
+                       goto abort;
+               sra->cache_size = strtoul(buf, NULL, 0);
+       }
 
        if (! (options & GET_DEVS))
                return sra;
@@ -192,6 +200,8 @@ unsigned long long get_component_size(int fd)
         * We cannot trust GET_ARRAY_INFO ioctl as it's
         * size field is only 32bits.
         * So look in /sys/block/mdXXX/md/component_size
+        *
+        * This returns in units of sectors.
         */
        struct stat stb;
        char fname[50];
@@ -202,7 +212,7 @@ unsigned long long get_component_size(int fd)
                        minor(stb.st_rdev));
        else
                sprintf(fname, "/sys/block/md_d%d/md/component_size",
-                       minor(stb.st_rdev)/16);
+                       minor(stb.st_rdev)>>MdpMinorShift);
        fd = open(fname, O_RDONLY);
        if (fd < 0)
                return 0;
@@ -211,7 +221,7 @@ unsigned long long get_component_size(int fd)
        if (n == sizeof(fname))
                return 0;
        fname[n] = 0;
-       return strtoull(fname, NULL, 10);
+       return strtoull(fname, NULL, 10) * 2;
 }
 
 int sysfs_set_str(struct sysarray *sra, struct sysdev *dev,