Whamcloud - gitweb
LU-19098 hsm: don't print progname twice with lhsmtool
[fs/lustre-release.git] / lustre / utils / libmount_utils_ldiskfs.c
index 32b19a1..01036df 100644 (file)
@@ -78,7 +78,6 @@
 #include "mount_utils.h"
 
 #define MAX_HW_SECTORS_KB_PATH "queue/max_hw_sectors_kb"
-#define MAX_SECTORS_KB_PATH    "queue/max_sectors_kb"
 #define SCHEDULER_PATH         "queue/scheduler"
 #define STRIPE_CACHE_SIZE      "md/stripe_cache_size"
 
@@ -143,9 +142,10 @@ int ldiskfs_write_ldd(struct mkfs_opts *mop)
        char mntpt[] = "/tmp/mntXXXXXX";
        char filepnm[192];
        char *dev;
-       FILE *filep;
+       size_t total_written, remaining;
+       ssize_t write_cnt;
+       int fd;
        int ret = 0;
-       size_t num;
 
        /* Mount this device temporarily in order to write these files */
        if (!mkdtemp(mntpt)) {
@@ -173,8 +173,7 @@ int ldiskfs_write_ldd(struct mkfs_opts *mop)
                                ret = run_command(command, sizeof(filepnm));
                                if (ret)
                                        fprintf(stderr,
-                                               "%s: Unable to set 'mmp' "
-                                               "on %s: %d\n",
+                                               "%s: Unable to set 'mmp' on %s: %d\n",
                                                progname, dev, ret);
                        } else {
                                disp_old_e2fsprogs_msg("mmp", 1);
@@ -207,6 +206,7 @@ int ldiskfs_write_ldd(struct mkfs_opts *mop)
        if ((ret != 0) && (errno != EEXIST)) {
                fprintf(stderr, "%s: Can't make configs dir %s (%s)\n",
                        progname, filepnm, strerror(errno));
+               ret = errno;
                goto out_umnt;
        } else if (errno == EEXIST) {
                ret = 0;
@@ -216,22 +216,45 @@ int ldiskfs_write_ldd(struct mkfs_opts *mop)
           this file to get the real mount options. */
        vprint("Writing %s\n", MOUNT_DATA_FILE);
        sprintf(filepnm, "%s/%s", mntpt, MOUNT_DATA_FILE);
-       filep = fopen(filepnm, "w");
-       if (!filep) {
-               fprintf(stderr, "%s: Unable to create %s file: %s\n",
-                       progname, filepnm, strerror(errno));
+       fd = open(filepnm, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+       if (fd < 0) {
+               fprintf(stderr, "%s: Unable to create %s file: %s\n", progname,
+                       filepnm, strerror(errno));
+               ret = errno;
                goto out_umnt;
        }
-       num = fwrite(&mop->mo_ldd, sizeof(mop->mo_ldd), 1, filep);
-       if (num < 1 && ferror(filep)) {
-               fprintf(stderr, "%s: Unable to write to file (%s): %s\n",
-                       progname, filepnm, strerror(errno));
-               fclose(filep);
-               goto out_umnt;
+
+       total_written = 0;
+       remaining = sizeof(mop->mo_ldd);
+       while (remaining > 0) {
+               write_cnt = write(fd,
+                                 (const char *)&mop->mo_ldd + total_written,
+                                 remaining);
+               if (write_cnt < 0) {
+                       fprintf(stderr,
+                               "%s: Unable to write to file (%s): %s\n",
+                               progname, filepnm, strerror(errno));
+                       ret = errno;
+                       goto close_fd;
+               }
+               total_written += write_cnt;
+               remaining -= write_cnt;
        }
-       fsync(filep->_fileno);
-       fclose(filep);
 
+       if (fsync(fd) < 0) {
+               fprintf(stderr, "%s: Unable to fsync file (%s): %s\n", progname,
+                       filepnm, strerror(errno));
+               ret = errno;
+       }
+
+close_fd:
+       if (close(fd) < 0) {
+               fprintf(stderr, "%s: Error while closing file (%s): %s\n",
+                       progname, filepnm, strerror(errno));
+               /* Don't overwrite errno if already set in previous failure */
+               if (ret == 0)
+                       ret = errno;
+       }
 out_umnt:
        umount(mntpt);
 out_rmdir:
@@ -411,12 +434,13 @@ static bool is_e2fsprogs_feature_supp(const char *feature)
                   strncmp(feature, "-O ", 3) ? feature : feature + 3))
                return true;
 
-       if ((fd = mkstemp(imgname)) < 0)
+       fd = mkstemp(imgname);
+       if (fd < 0)
                return false;
 
        close(fd);
 
-       snprintf(cmd, sizeof(cmd), "%s -F %s %s 100 >/dev/null 2>&1",
+       snprintf(cmd, sizeof(cmd), "%s -F %s %s 200 >/dev/null 2>&1",
                 MKE2FS, feature, imgname);
        /* run_command() displays the output of mke2fs when it fails for
         * some feature, so use system() directly */
@@ -515,8 +539,6 @@ static int enable_default_ext4_features(struct mkfs_opts *mop, char *anchor,
 
        if (enable_64bit) {
                append_unique(anchor, ",", "64bit", NULL, maxbuflen);
-               if (is_e2fsprogs_feature_supp("-O meta_bg"))
-                       append_unique(anchor, ",", "meta_bg", NULL, maxbuflen);
                append_unique(anchor, ",", "^resize_inode", NULL, maxbuflen);
        }
 
@@ -879,16 +901,21 @@ int ldiskfs_make_lustre(struct mkfs_opts *mop)
        }
 
        /* Avoid zeroing out the full journal - speeds up mkfs */
-       if (is_e2fsprogs_feature_supp("-E lazy_journal_init=0")) {
+       if (is_e2fsprogs_feature_supp("-E lazy_journal_init")) {
                append_unique(start, ext_opts ? "," : " -E ",
-                             "lazy_journal_init", "0", maxbuflen);
+                             "lazy_journal_init", NULL, maxbuflen);
                ext_opts = 1;
        }
        if (is_e2fsprogs_feature_supp("-E lazy_itable_init=0")) {
-               append_unique(start, ext_opts ? "," : "-E",
+               append_unique(start, ext_opts ? "," : " -E ",
                            "lazy_itable_init", "0", maxbuflen);
                ext_opts = 1;
        }
+       if (is_e2fsprogs_feature_supp("-E packed_meta_blocks")) {
+               append_unique(start, ext_opts ? "," : " -E ",
+                             "packed_meta_blocks", NULL, maxbuflen);
+               ext_opts = 1;
+       }
 
        /* end handle -E mkfs options */
 
@@ -1037,77 +1064,6 @@ static int tune_md_stripe_cache_size(const char *sys_path,
        return 0;
 }
 
-static int tune_max_sectors_kb(const char *sys_path, struct mount_opts *mop)
-{
-       char path[PATH_MAX];
-       unsigned long max_hw_sectors_kb;
-       unsigned long old_max_sectors_kb;
-       unsigned long new_max_sectors_kb;
-       char buf[3 * sizeof(old_max_sectors_kb) + 2];
-       int rc;
-
-       if (mop->mo_max_sectors_kb >= 0) {
-               new_max_sectors_kb = mop->mo_max_sectors_kb;
-               goto have_new_max_sectors_kb;
-       }
-
-       snprintf(path, sizeof(path), "%s/%s", sys_path, MAX_HW_SECTORS_KB_PATH);
-       rc = read_file(path, buf, sizeof(buf));
-       if (rc != 0) {
-               /* No MAX_HW_SECTORS_KB_PATH isn't necessary an
-                * error for some devices. */
-               return 0;
-       }
-
-       max_hw_sectors_kb = strtoul(buf, NULL, 0);
-       if (max_hw_sectors_kb == 0 || max_hw_sectors_kb == ULLONG_MAX) {
-               /* No digits at all or something weird. */
-               return 0;
-       }
-
-       new_max_sectors_kb = max_hw_sectors_kb;
-
-       /* Don't increase IO request size limit past 16MB.  It is
-        * about PTLRPC_MAX_BRW_SIZE, but that isn't in a public
-        * header.  Note that even though the block layer allows
-        * larger values, setting max_sectors_kb = 32768 causes
-        * crashes (LU-6974). */
-       if (new_max_sectors_kb > 16 * 1024)
-               new_max_sectors_kb = 16 * 1024;
-
-have_new_max_sectors_kb:
-       snprintf(path, sizeof(path), "%s/%s", sys_path, MAX_SECTORS_KB_PATH);
-       rc = read_file(path, buf, sizeof(buf));
-       if (rc != 0) {
-               /* No MAX_SECTORS_KB_PATH isn't necessary an error for
-                * some devices. */
-               return 0;
-       }
-
-       old_max_sectors_kb = strtoul(buf, NULL, 0);
-       if (old_max_sectors_kb == 0 || old_max_sectors_kb == ULLONG_MAX) {
-               /* No digits at all or something weird. */
-               return 0;
-       }
-
-       if (new_max_sectors_kb <= old_max_sectors_kb)
-               return 0;
-
-       snprintf(buf, sizeof(buf), "%lu", new_max_sectors_kb);
-       rc = write_file(path, buf);
-       if (rc != 0) {
-               if (verbose)
-                       fprintf(stderr, "warning: cannot write '%s': %s\n",
-                               path, strerror(errno));
-               return rc;
-       }
-
-       fprintf(stderr, "%s: increased '%s' from %lu to %lu\n",
-               progname, path, old_max_sectors_kb, new_max_sectors_kb);
-
-       return 0;
-}
-
 static int tune_block_dev_scheduler(const char *sys_path, const char *new_sched)
 {
        char path[PATH_MAX];
@@ -1206,9 +1162,7 @@ static int tune_block_dev_slaves(const char *sys_path, struct mount_opts *mop)
        return rc;
 }
 
-/* This is to tune the kernel for good SCSI performance.
- * For that we set the value of /sys/block/{dev}/queue/max_sectors_kb
- * to the value of /sys/block/{dev}/queue/max_hw_sectors_kb */
+/* This is to tune the kernel for good SCSI performance. */
 static int tune_block_dev(const char *src, struct mount_opts *mop)
 {
        struct stat st;
@@ -1278,10 +1232,9 @@ have_whole_dev:
        if (major(st.st_rdev) == MD_MAJOR) {
                rc = tune_md_stripe_cache_size(real_sys_path, mop);
        } else {
-               /* Ignore errors from tune_max_sectors_kb() and
-                * tune_scheduler(). The worst that will happen is a block
-                * device with an "incorrect" scheduler. */
-               tune_max_sectors_kb(real_sys_path, mop);
+               /* Ignore errors from tune_scheduler(). The worst that will
+                * happen is a block device with an "incorrect" scheduler.
+                */
                tune_block_dev_scheduler(real_sys_path, DEFAULT_SCHEDULER);
 
                /* If device is multipath device then tune its slave