Whamcloud - gitweb
LU-5888 utils: limit max_sectors_kb tunable setting 40/13240/12
authorAndreas Dilger <andreas.dilger@intel.com>
Wed, 1 Apr 2015 16:35:29 +0000 (12:35 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 3 Aug 2015 01:57:17 +0000 (01:57 +0000)
Properly limit the max_sectors_kb tunable if larger than 32MB, as
added in commit 73bd456e896 (http://review.whamcloud.com/12723).
It was using the old value in "buf" instead of the updated "newval".

Change write_file() to use a file descriptor directly instead of
streams, since it only writes a single value before closing again.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Change-Id: I43a5b4c9d0e45649e0666fd58634286de53ebbe5
Reviewed-on: http://review.whamcloud.com/13240
Tested-by: Jenkins
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/mount_utils_ldiskfs.c

index e7e39a5..d07e996 100644 (file)
@@ -974,15 +974,16 @@ static int read_file(const char *path, char *buf, int size)
 
 static int write_file(const char *path, const char *buf)
 {
-       FILE *fd;
+       int fd, rc;
 
-       fd = fopen(path, "w");
-       if (fd == NULL)
+       fd = open(path, O_WRONLY);
+       if (fd < 0)
                return errno;
 
-       fputs(buf, fd);
-       fclose(fd);
-       return 0;
+       rc = write(fd, buf, strlen(buf));
+       close(fd);
+
+       return rc < 0 ? errno : 0;
 }
 
 static int set_blockdev_scheduler(const char *path, const char *scheduler)
@@ -1156,7 +1157,7 @@ set_params:
                        snprintf(buf, sizeof(buf), "%d",
                                 mop->mo_md_stripe_cache_size);
                        rc = write_file(real_path, buf);
-                       if (rc && verbose)
+                       if (rc != 0 && verbose)
                                fprintf(stderr, "warning: opening %s: %s\n",
                                        real_path, strerror(errno));
                }
@@ -1195,9 +1196,11 @@ set_params:
                        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)
+                * 2x PTLRPC_MAX_BRW_SIZE, but that isn't in a public header. */
+               if (newval > 32 * 1024) {
                        newval = 32 * 1024;
+                       snprintf(buf, sizeof(buf), "%llu", newval);
+               }
 
                oldval = strtoull(oldbuf, &end, 0);
                /* Don't shrink the current limit. */
@@ -1205,7 +1208,7 @@ set_params:
                        goto subdevs;
 
                rc = write_file(real_path, buf);
-               if (rc) {
+               if (rc != 0) {
                        if (verbose)
                                fprintf(stderr, "warning: writing to %s: %s\n",
                                        real_path, strerror(errno));