]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - Grow.c
Define sysfs max buffer size
[thirdparty/mdadm.git] / Grow.c
diff --git a/Grow.c b/Grow.c
index 06001f2d334a8a6782e43adfa9789d61104599cc..8ca8ee781d1b4dd5f24c0ae717b7da64e5b519db 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -545,7 +545,7 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha
        char *subarray = NULL;
        int ret = 0;
        char container_dev[PATH_MAX];
-       char buf[20];
+       char buf[SYSFS_MAX_BUF_SIZE];
 
        if (s->consistency_policy != CONSISTENCY_POLICY_RESYNC &&
            s->consistency_policy != CONSISTENCY_POLICY_PPL) {
@@ -594,7 +594,7 @@ int Grow_consistency_policy(char *devname, int fd, struct context *c, struct sha
        }
 
        if (s->consistency_policy == CONSISTENCY_POLICY_PPL) {
-               if (sysfs_get_str(sra, NULL, "sync_action", buf, 20) <= 0) {
+               if (sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) <= 0) {
                        ret = 1;
                        goto free_info;
                } else if (strcmp(buf, "reshape\n") == 0) {
@@ -817,12 +817,12 @@ static int freeze(struct supertype *st)
        else {
                struct mdinfo *sra = sysfs_read(-1, st->devnm, GET_VERSION);
                int err;
-               char buf[20];
+               char buf[SYSFS_MAX_BUF_SIZE];
 
                if (!sra)
                        return -1;
                /* Need to clear any 'read-auto' status */
-               if (sysfs_get_str(sra, NULL, "array_state", buf, 20) > 0 &&
+               if (sysfs_get_str(sra, NULL, "array_state", buf, sizeof(buf)) > 0 &&
                    strncmp(buf, "read-auto", 9) == 0)
                        sysfs_set_str(sra, NULL, "array_state", "clean");
 
@@ -838,10 +838,10 @@ static void unfreeze(struct supertype *st)
                return unfreeze_container(st);
        else {
                struct mdinfo *sra = sysfs_read(-1, st->devnm, GET_VERSION);
-               char buf[20];
+               char buf[SYSFS_MAX_BUF_SIZE];
 
                if (sra &&
-                   sysfs_get_str(sra, NULL, "sync_action", buf, 20) > 0 &&
+                   sysfs_get_str(sra, NULL, "sync_action", buf, sizeof(buf)) > 0 &&
                    strcmp(buf, "frozen\n") == 0)
                        sysfs_set_str(sra, NULL, "sync_action", "idle");
                sysfs_free(sra);
@@ -851,12 +851,12 @@ static void unfreeze(struct supertype *st)
 static void wait_reshape(struct mdinfo *sra)
 {
        int fd = sysfs_get_fd(sra, NULL, "sync_action");
-       char action[20];
+       char action[SYSFS_MAX_BUF_SIZE];
 
        if (fd < 0)
                return;
 
-       while (sysfs_fd_get_str(fd, action, 20) > 0 &&
+       while (sysfs_fd_get_str(fd, action, sizeof(action)) > 0 &&
               strncmp(action, "reshape", 7) == 0)
                sysfs_wait(fd, NULL);
        close(fd);
@@ -902,7 +902,7 @@ static int subarray_set_num(char *container, struct mdinfo *sra, char *name, int
         * to close a race with the array_state going clean before the
         * next write to raid_disks / stripe_cache_size
         */
-       char safe[50];
+       char safe[SYSFS_MAX_BUF_SIZE];
        int rc;
 
        /* only 'raid_disks' and 'stripe_cache_size' trigger md_allow_write */
@@ -1708,14 +1708,6 @@ char *analyse_change(char *devname, struct mdinfo *info, struct reshape *re)
                return NULL;
        }
 
-       if (re->after.data_disks == re->before.data_disks &&
-           get_linux_version() < 2006032)
-               return "in-place reshape is not safe before 2.6.32 - sorry.";
-
-       if (re->after.data_disks < re->before.data_disks &&
-           get_linux_version() < 2006030)
-               return "reshape to fewer devices is not supported before 2.6.30 - sorry.";
-
        re->backup_blocks = compute_backup_blocks(
                info->new_chunk, info->array.chunk_size,
                re->after.data_disks, re->before.data_disks);
@@ -1895,14 +1887,6 @@ int Grow_reshape(char *devname, int fd,
                return 1;
        }
 
-       if (s->raiddisks && s->raiddisks < array.raid_disks &&
-           array.level > 1 && get_linux_version() < 2006032 &&
-           !check_env("MDADM_FORCE_FEWER")) {
-               pr_err("reducing the number of devices is not safe before Linux 2.6.32\n"
-                       "       Please use a newer kernel\n");
-               return 1;
-       }
-
        if (array.level > 1 && s->size > 1 &&
            (unsigned long long) (array.chunk_size / 1024) > s->size) {
                pr_err("component size must be larger than chunk size.\n");
@@ -2412,11 +2396,11 @@ release:
 static int verify_reshape_position(struct mdinfo *info, int level)
 {
        int ret_val = 0;
-       char buf[40];
+       char buf[SYSFS_MAX_BUF_SIZE];
        int rv;
 
        /* read sync_max, failure can mean raid0 array */
-       rv = sysfs_get_str(info, NULL, "sync_max", buf, 40);
+       rv = sysfs_get_str(info, NULL, "sync_max", buf, sizeof(buf));
 
        if (rv > 0) {
                char *ep;
@@ -3056,7 +3040,7 @@ static int reshape_array(char *container, int fd, char *devname,
        unsigned long long array_size;
        int done;
        struct mdinfo *sra = NULL;
-       char buf[20];
+       char buf[SYSFS_MAX_BUF_SIZE];
 
        /* when reshaping a RAID0, the component_size might be zero.
         * So try to fix that up.
@@ -3932,7 +3916,7 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,
        unsigned long long array_size = (info->component_size
                                         * reshape->before.data_disks);
        int fd;
-       char buf[20];
+       char buf[SYSFS_MAX_BUF_SIZE];
 
        /* First, we unsuspend any region that is now known to be safe.
         * If suspend_point is on the 'wrong' side of reshape_progress, then
@@ -4110,8 +4094,8 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,
                /* Check that sync_action is still 'reshape' to avoid
                 * waiting forever on a dead array
                 */
-               char action[20];
-               if (sysfs_get_str(info, NULL, "sync_action", action, 20) <= 0 ||
+               char action[SYSFS_MAX_BUF_SIZE];
+               if (sysfs_get_str(info, NULL, "sync_action", action, sizeof(action)) <= 0 ||
                    strncmp(action, "reshape", 7) != 0)
                        break;
                /* Some kernels reset 'sync_completed' to zero
@@ -4137,8 +4121,8 @@ int progress_reshape(struct mdinfo *info, struct reshape *reshape,
         */
        if (completed == 0) {
                unsigned long long reshapep;
-               char action[20];
-               if (sysfs_get_str(info, NULL, "sync_action", action, 20) > 0 &&
+               char action[SYSFS_MAX_BUF_SIZE];
+               if (sysfs_get_str(info, NULL, "sync_action", action, sizeof(action)) > 0 &&
                    strncmp(action, "idle", 4) == 0 &&
                    sysfs_get_ll(info, NULL,
                                 "reshape_position", &reshapep) == 0)
@@ -4256,7 +4240,7 @@ static int grow_backup(struct mdinfo *sra,
                        if (sd->disk.state & (1<<MD_DISK_FAULTY))
                                continue;
                        if (sd->disk.state & (1<<MD_DISK_SYNC)) {
-                               char sbuf[100];
+                               char sbuf[SYSFS_MAX_BUF_SIZE];
 
                                if (sysfs_get_str(sra, sd, "state",
                                                  sbuf, sizeof(sbuf)) < 0 ||