From 3ee93d4c56f347adeb31d05fc9c314784d11fecb Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Mon, 16 Jan 2023 23:33:36 -0500 Subject: [PATCH] Remove 'nonempty' argument This makes it like all other filesystems and brings it into alignment with libfuse3's behavior. --- README.md | 2 +- libfuse/lib/mount_bsd.c | 1 - libfuse/lib/mount_generic.c | 11 -------- libfuse/lib/mount_util.c | 33 ------------------------ libfuse/lib/mount_util.h | 2 -- libfuse/util/fusermount.c | 7 ----- libfuse/util/mount_util.c | 33 ------------------------ src/option_parser.cpp | 51 ++++++++++++++----------------------- 8 files changed, 20 insertions(+), 120 deletions(-) diff --git a/README.md b/README.md index 2f685364..0d0f76a0 100644 --- a/README.md +++ b/README.md @@ -666,7 +666,7 @@ make LTO=1 - build with link time optimization mergerfs can be upgraded live by mounting on top of the previous instance. Simply install the new version of mergerfs and follow the instructions below. -Add `nonempty` to your mergerfs option list and call mergerfs again or if using `/etc/fstab` call for it to mount again. Existing open files and such will continue to work fine though they won't see runtime changes since any such change would be the new mount. If you plan on changing settings with the new mount you should / could apply those before mounting the new version. +Run mergerfs again or if using `/etc/fstab` call for it to mount again. Existing open files and such will continue to work fine though they won't see runtime changes since any such change would be the new mount. If you plan on changing settings with the new mount you should / could apply those before mounting the new version. ``` $ sudo mount /mnt/mergerfs diff --git a/libfuse/lib/mount_bsd.c b/libfuse/lib/mount_bsd.c index bc17bed3..b1a54575 100644 --- a/libfuse/lib/mount_bsd.c +++ b/libfuse/lib/mount_bsd.c @@ -90,7 +90,6 @@ static const struct fuse_opt fuse_mount_opts[] = { * handle them */ FUSE_OPT_KEY("fsname=", KEY_KERN), - FUSE_OPT_KEY("nonempty", KEY_KERN), FUSE_OPT_KEY("large_read", KEY_KERN), FUSE_OPT_END }; diff --git a/libfuse/lib/mount_generic.c b/libfuse/lib/mount_generic.c index 807f580f..7b98f739 100644 --- a/libfuse/lib/mount_generic.c +++ b/libfuse/lib/mount_generic.c @@ -64,7 +64,6 @@ struct mount_opts { int allow_other; int ishelp; int flags; - int nonempty; int auto_unmount; int blkdev; char *fsname; @@ -79,13 +78,11 @@ struct mount_opts { static const struct fuse_opt fuse_mount_opts[] = { FUSE_MOUNT_OPT("allow_other", allow_other), - FUSE_MOUNT_OPT("nonempty", nonempty), FUSE_MOUNT_OPT("blkdev", blkdev), FUSE_MOUNT_OPT("auto_unmount", auto_unmount), FUSE_MOUNT_OPT("fsname=%s", fsname), FUSE_MOUNT_OPT("subtype=%s", subtype), FUSE_OPT_KEY("allow_other", KEY_KERN_OPT), - FUSE_OPT_KEY("nonempty", KEY_FUSERMOUNT_OPT), FUSE_OPT_KEY("auto_unmount", KEY_FUSERMOUNT_OPT), FUSE_OPT_KEY("blkdev", KEY_FUSERMOUNT_OPT), FUSE_OPT_KEY("fsname=", KEY_FUSERMOUNT_OPT), @@ -126,7 +123,6 @@ static void mount_help(void) fprintf(stderr, " -o allow_other allow access to other users\n" " -o auto_unmount auto unmount on process termination\n" - " -o nonempty allow mounts over non-empty file/dir\n" " -o default_permissions enable permission checking by kernel\n" " -o fsname=NAME set filesystem name\n" " -o subtype=NAME set filesystem type\n" @@ -424,13 +420,6 @@ static int fuse_mount_sys(const char *mnt, struct mount_opts *mo, return -1; } - if (!mo->nonempty) { - res = fuse_mnt_check_empty("fuse", mnt, stbuf.st_mode, - stbuf.st_size); - if (res == -1) - return -1; - } - if (mo->auto_unmount) { /* Tell the caller to fallback to fusermount because auto-unmount does not work otherwise. */ diff --git a/libfuse/lib/mount_util.c b/libfuse/lib/mount_util.c index b9eefca8..afda1412 100644 --- a/libfuse/lib/mount_util.c +++ b/libfuse/lib/mount_util.c @@ -312,39 +312,6 @@ char *fuse_mnt_resolve_path(const char *progname, const char *orig) return dst; } -int fuse_mnt_check_empty(const char *progname, const char *mnt, - mode_t rootmode, off_t rootsize) -{ - int isempty = 1; - - if (S_ISDIR(rootmode)) { - struct dirent *ent; - DIR *dp = opendir(mnt); - if (dp == NULL) { - fprintf(stderr, - "%s: failed to open mountpoint for reading: %s\n", - progname, strerror(errno)); - return -1; - } - while ((ent = readdir(dp)) != NULL) { - if (strcmp(ent->d_name, ".") != 0 && - strcmp(ent->d_name, "..") != 0) { - isempty = 0; - break; - } - } - closedir(dp); - } else if (rootsize) - isempty = 0; - - if (!isempty) { - fprintf(stderr, "%s: mountpoint is not empty\n", progname); - fprintf(stderr, "%s: if you are sure this is safe, use the 'nonempty' mount option\n", progname); - return -1; - } - return 0; -} - int fuse_mnt_check_fuseblk(void) { char buf[256]; diff --git a/libfuse/lib/mount_util.h b/libfuse/lib/mount_util.h index bb447feb..5e8b0fb2 100644 --- a/libfuse/lib/mount_util.h +++ b/libfuse/lib/mount_util.h @@ -16,6 +16,4 @@ int fuse_mnt_remove_mount(const char *progname, const char *mnt); int fuse_mnt_umount(const char *progname, const char *abs_mnt, const char *rel_mnt, int lazy); char *fuse_mnt_resolve_path(const char *progname, const char *orig); -int fuse_mnt_check_empty(const char *progname, const char *mnt, - mode_t rootmode, off_t rootsize); int fuse_mnt_check_fuseblk(void); diff --git a/libfuse/util/fusermount.c b/libfuse/util/fusermount.c index 512e80de..1451dda2 100644 --- a/libfuse/util/fusermount.c +++ b/libfuse/util/fusermount.c @@ -726,7 +726,6 @@ static int do_mount(const char *mnt, char **typep, mode_t rootmode, char *subtype = NULL; char *source = NULL; char *type = NULL; - int check_empty = 1; int blkdev = 0; optbuf = (char *) malloc(strlen(opts) + 128); @@ -759,8 +758,6 @@ static int do_mount(const char *mnt, char **typep, mode_t rootmode, goto err; } blkdev = 1; - } else if (opt_eq(s, len, "nonempty")) { - check_empty = 0; } else if (opt_eq(s, len, "auto_unmount")) { auto_unmount = 1; } else if (!begins_with(s, "fd=") && @@ -811,10 +808,6 @@ static int do_mount(const char *mnt, char **typep, mode_t rootmode, sprintf(d, "fd=%i,rootmode=%o,user_id=%u,group_id=%u", fd, rootmode, getuid(), getgid()); - if (check_empty && - fuse_mnt_check_empty(progname, mnt, rootmode, rootsize) == -1) - goto err; - source = malloc((fsname ? strlen(fsname) : 0) + (subtype ? strlen(subtype) : 0) + strlen(dev) + 32); diff --git a/libfuse/util/mount_util.c b/libfuse/util/mount_util.c index defb92f6..6f094ec3 100644 --- a/libfuse/util/mount_util.c +++ b/libfuse/util/mount_util.c @@ -312,39 +312,6 @@ char *fuse_mnt_resolve_path(const char *progname, const char *orig) return dst; } -int fuse_mnt_check_empty(const char *progname, const char *mnt, - mode_t rootmode, off_t rootsize) -{ - int isempty = 1; - - if (S_ISDIR(rootmode)) { - struct dirent *ent; - DIR *dp = opendir(mnt); - if (dp == NULL) { - fprintf(stderr, - "%s: failed to open mountpoint for reading: %s\n", - progname, strerror(errno)); - return -1; - } - while ((ent = readdir(dp)) != NULL) { - if (strcmp(ent->d_name, ".") != 0 && - strcmp(ent->d_name, "..") != 0) { - isempty = 0; - break; - } - } - closedir(dp); - } else if (rootsize) - isempty = 0; - - if (!isempty) { - fprintf(stderr, "%s: mountpoint is not empty\n", progname); - fprintf(stderr, "%s: if you are sure this is safe, use the 'nonempty' mount option\n", progname); - return -1; - } - return 0; -} - int fuse_mnt_check_fuseblk(void) { char buf[256]; diff --git a/src/option_parser.cpp b/src/option_parser.cpp index 75cd48c7..df719f72 100644 --- a/src/option_parser.cpp +++ b/src/option_parser.cpp @@ -49,27 +49,6 @@ enum }; -namespace l -{ - static - int - calculate_thread_count(int threads_) - { - int tc; - - if(threads_ > 0) - return threads_; - - tc = hw::cpu::logical_core_count(); - if(threads_ < 0) - tc /= -threads_; - if(tc == 0) - tc = 1; - - return tc; - } -} - static void set_option(const std::string &option_, @@ -134,6 +113,24 @@ set_default_options(fuse_args *args_) set_option("default_permissions",args_); } +static +bool +should_ignore(const std::string &key_) +{ + static const std::set IGNORED_KEYS = + { + "atomic_o_trunc", + "big_writes", + "cache.open", + "defaults", + "hard_remove", + "nonempty", + "use_ino" + }; + + return (IGNORED_KEYS.find(key_) != IGNORED_KEYS.end()); +} + static int parse_and_process_kv_arg(Config::Write &cfg_, @@ -164,17 +161,7 @@ parse_and_process_kv_arg(Config::Write &cfg_, val = "true"; ef(key == "sync_read" && val.empty()) {key = "async_read", val = "false";} - ef(key == "defaults") - return 0; - ef(key == "hard_remove") - return 0; - ef(key == "atomic_o_trunc") - return 0; - ef(key == "big_writes") - return 0; - ef(key == "cache.open") - return 0; - ef(key == "use_ino") + ef(::should_ignore(key_)) return 0; if(cfg_->has_key(key) == false)