]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - sysfs.c
Grow: fix hang when reshape completes too fast
[thirdparty/mdadm.git] / sysfs.c
diff --git a/sysfs.c b/sysfs.c
index 2dad7d3fd8c9969aefc636ce46213576aa4e85b1..31c92f78b79b91c8472ae079c118b670de2a2cf7 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -466,6 +466,26 @@ int sysfs_get_ll(struct mdinfo *sra, struct mdinfo *dev,
        return 0;
 }
 
+int sysfs_get_str(struct mdinfo *sra, struct mdinfo *dev,
+                 char *name, char *buf, int buf_len)
+{
+       char fname[50];
+       int n;
+       int fd;
+
+       sprintf(fname, "/sys/block/%s/md/%s/%s",
+               sra->sys_name, dev?dev->sys_name:"", name);
+       fd = open(fname, O_RDONLY);
+       if (fd < 0)
+               return -1;
+       n = read(fd, buf, buf_len);
+       close(fd);
+       if (n <= 0)
+               return -1;
+       buf[n] = 0;
+       return 0;
+}
+
 int sysfs_set_safemode(struct mdinfo *sra, unsigned long ms)
 {
        unsigned long sec;
@@ -506,6 +526,20 @@ int sysfs_set_array(struct mdinfo *info, int vers)
        rv |= sysfs_set_num(info, NULL, "chunk_size", info->array.chunk_size);
        rv |= sysfs_set_num(info, NULL, "layout", info->array.layout);
        rv |= sysfs_set_num(info, NULL, "component_size", info->component_size/2);
+       if (info->custom_array_size) {
+               int rc;
+
+               rc = sysfs_set_num(info, NULL, "array_size",
+                                  info->custom_array_size/2);
+               if (rc && errno == ENOENT) {
+                       fprintf(stderr, Name ": This kernel does not "
+                               "have the md/array_size attribute, "
+                               "the array may be larger than expected\n");
+                       rc = 0;
+               }
+               rv |= rc;
+       }
+
        if (info->array.level > 0)
                rv |= sysfs_set_num(info, NULL, "resync_start", info->resync_start);
        return rv;