#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"
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)) {
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);
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;
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:
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 */
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);
}
}
/* 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 */
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];
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;
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