Whamcloud - gitweb
LU-5577 ptlrpc: fix comparison between signed and unsigned
[fs/lustre-release.git] / lustre / utils / mount_utils_ldiskfs.c
index 3815d72..7679a68 100644 (file)
@@ -66,7 +66,6 @@
 #include <limits.h>
 #include <ctype.h>
 
-#ifdef __linux__
 /* libcfs.h is not really needed here, but on SLES10/PPC, fs.h includes idr.h
  * which requires BITS_PER_LONG to be defined */
 #include <libcfs/libcfs.h>
@@ -74,7 +73,6 @@
 #include <linux/fs.h> /* for BLKGETSIZE64 */
 #endif
 #include <linux/version.h>
-#endif
 #include <lustre_disk.h>
 #include <lustre_param.h>
 #include <lnet/lnetctl.h>
@@ -409,7 +407,7 @@ static void disp_old_e2fsprogs_msg(const char *feature, int make_backfs)
                E2FSPROGS, feature);
 #if !(HAVE_LDISKFSPROGS)
        fprintf(stderr, "Please install the latest version of e2fsprogs from\n"
-               "http://downloads.whamcloud.com/public/e2fsprogs/latest/\n"
+               "https://downloads.hpdd.intel.com/public/e2fsprogs/latest/\n"
                "to enable this feature.\n");
 #endif
        if (make_backfs)
@@ -961,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;
 }
 
@@ -986,7 +989,7 @@ static int write_file(const char *path, const char *buf)
 
 static int set_blockdev_scheduler(const char *path, const char *scheduler)
 {
-       char buf[PATH_MAX], *c;
+       char buf[PATH_MAX], *s, *e, orig_sched[50];
        int rc;
 
        /* Before setting the scheduler, we need to check to see if it's
@@ -1003,18 +1006,21 @@ static int set_blockdev_scheduler(const char *path, const char *scheduler)
        }
 
        /* The expected format of buf: noop anticipatory deadline [cfq] */
-       c = strchr(buf, '[');
+       s = strchr(buf, '[');
+       e = strchr(buf, ']');
 
-       /* If c is NULL, the format is not what we expect. Play it safe
-        * and error out. */
-       if (c == NULL) {
+       /* If the format is not what we expect. Play it safe and error out. */
+       if (s == NULL || e == NULL) {
                if (verbose)
                        fprintf(stderr, "%s: cannot parse scheduler "
                                        "options for '%s'\n", progname, path);
                return -EINVAL;
        }
 
-       if (strncmp(c+1, "noop", 4) == 0)
+       snprintf(orig_sched, e - s, "%s", s + 1);
+
+       if (strcmp(orig_sched, "noop") == 0 ||
+           strcmp(orig_sched, scheduler) == 0)
                return 0;
 
        rc = write_file(path, scheduler);
@@ -1024,6 +1030,9 @@ static int set_blockdev_scheduler(const char *path, const char *scheduler)
                                        "'%s': %s\n", progname, path,
                                        strerror(errno));
                return rc;
+       } else {
+               fprintf(stderr, "%s: change scheduler of %s from %s to %s\n",
+                       progname, path, orig_sched, scheduler);
        }
 
        return rc;
@@ -1166,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)
@@ -1179,10 +1213,13 @@ set_params:
                                        real_path, strerror(errno));
                        /* No MAX_SECTORS_KB_PATH isn't necessary an
                         * error for some device. */
-                       rc = 0;
+                       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. */