Whamcloud - gitweb
LU-5888 utils: limit max_sectors_kb tunable setting 23/12723/2
authorAndreas Dilger <andreas.dilger@intel.com>
Fri, 14 Nov 2014 19:48:39 +0000 (12:48 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 26 Nov 2014 23:41:00 +0000 (23:41 +0000)
Limit the value set by mount.lustre set_blockdev_tunables() to a
reasonable 32MB instead of the maximum possible amount, since the
parsing of max_hw_sectors_kb might be bad, or it just returns a
value much larger than we need.

Also quiet the printing of the max_sectors_kb tunable that was added
in commit 9813961151e (http://review.whamcloud.com/9865) so that it
only prints something when the value is actually changed, instead of
printing it for every tunable even if the value is the same.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Change-Id: I648c2d8484ae5cef59ab62421cd01bc0ed02fcd6
Reviewed-on: http://review.whamcloud.com/12723
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Blake Caldwell <blakec@ornl.gov>
Reviewed-by: Niu Yawei <yawei.niu@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/mount_utils_ldiskfs.c

index 456267c..7679a68 100644 (file)
@@ -959,13 +959,18 @@ static int read_file(const char *path, char *buf, int size)
        if (fd == NULL)
                return errno;
 
-       /* should not ignore fgets(3)'s return value */
-       if (!fgets(buf, size, fd)) {
+       if (fgets(buf, size, fd) == NULL) {
                fprintf(stderr, "reading from %s: %s", path, strerror(errno));
                fclose(fd);
                return 1;
        }
        fclose(fd);
+
+       /* strip trailing newline */
+       size = strlen(buf);
+       if (buf[size - 1] == '\n')
+               buf[size - 1] = '\0';
+
        return 0;
 }
 
@@ -1170,12 +1175,37 @@ set_params:
                                real_path, strerror(errno));
                /* No MAX_HW_SECTORS_KB_PATH isn't necessary an
                 * error for some device. */
-               rc = 0;
+               goto subdevs;
        }
 
        if (strlen(buf) - 1 > 0) {
+               char oldbuf[32] = "", *end = NULL;
+               unsigned long long oldval, newval;
+
                snprintf(real_path, sizeof(real_path), "%s/%s", path,
                         MAX_SECTORS_KB_PATH);
+               rc = read_file(real_path, oldbuf, sizeof(oldbuf));
+               /* Only set new parameter if different from the old one. */
+               if (rc != 0 || strcmp(oldbuf, buf) == 0) {
+                       /* No MAX_SECTORS_KB_PATH isn't necessary an
+                        * error for some device. */
+                       goto subdevs;
+               }
+
+               newval = strtoull(buf, &end, 0);
+               if (newval == 0 || newval == ULLONG_MAX || end == buf)
+                       goto subdevs;
+
+               /* Don't increase IO request size limit past 32MB.  It is about
+                * 2x PTLRPC_MAX_BRW_SIZE, but that isn't defined publicly. */
+               if (newval > 32 * 1024)
+                       newval = 32 * 1024;
+
+               oldval = strtoull(oldbuf, &end, 0);
+               /* Don't shrink the current limit. */
+               if (oldval != ULLONG_MAX && newval <= oldval)
+                       goto subdevs;
+
                rc = write_file(real_path, buf);
                if (rc) {
                        if (verbose)
@@ -1183,13 +1213,13 @@ set_params:
                                        real_path, strerror(errno));
                        /* No MAX_SECTORS_KB_PATH isn't necessary an
                         * error for some device. */
-                       rc = 0;
-               } else {
-                       fprintf(stderr, "%s: set %s to %s\n", progname,
-                               real_path, buf);
+                       goto subdevs;
                }
+               fprintf(stderr, "%s: increased %s from %s to %s\n",
+                       progname, real_path, oldbuf, buf);
        }
 
+subdevs:
        /* Purposely ignore errors reported from set_blockdev_scheduler.
         * The worst that will happen is a block device with an "incorrect"
         * scheduler. */