From: Darrick J. Wong <djwong@xxxxxxxxxx> Enable the new dynamic iocache I/O manager in the fuse server, and turn off all the other cache control. Signed-off-by: "Darrick J. Wong" <djwong@xxxxxxxxxx> --- misc/Makefile.in | 7 ++++- misc/fuse2fs.c | 71 ++++-------------------------------------------------- misc/fuse4fs.c | 69 ++-------------------------------------------------- 3 files changed, 13 insertions(+), 134 deletions(-) diff --git a/misc/Makefile.in b/misc/Makefile.in index 36694d682d3b59..8a31b7fc42e643 100644 --- a/misc/Makefile.in +++ b/misc/Makefile.in @@ -891,7 +891,9 @@ fuse2fs.o: $(srcdir)/fuse2fs.c $(top_builddir)/lib/config.h \ $(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \ $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/ext2fsP.h \ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/version.h \ - $(top_srcdir)/lib/e2p/e2p.h + $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/cache.h \ + $(top_srcdir)/lib/support/list.h $(top_srcdir)/lib/support/xbitops.h \ + $(top_srcdir)/lib/support/iocache.h fuse4fs.o: $(srcdir)/fuse4fs.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \ @@ -901,7 +903,8 @@ fuse4fs.o: $(srcdir)/fuse4fs.c $(top_builddir)/lib/config.h \ $(top_srcdir)/lib/ext2fs/bitops.h $(top_srcdir)/lib/ext2fs/ext2fsP.h \ $(top_srcdir)/lib/ext2fs/ext2fs.h $(top_srcdir)/version.h \ $(top_srcdir)/lib/e2p/e2p.h $(top_srcdir)/lib/support/cache.h \ - $(top_srcdir)/lib/support/list.h $(top_srcdir)/lib/support/xbitops.h + $(top_srcdir)/lib/support/list.h $(top_srcdir)/lib/support/xbitops.h \ + $(top_srcdir)/lib/support/iocache.h e2fuzz.o: $(srcdir)/e2fuzz.c $(top_builddir)/lib/config.h \ $(top_builddir)/lib/dirpaths.h $(top_srcdir)/lib/ext2fs/ext2_fs.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(top_srcdir)/lib/ext2fs/ext2fs.h \ diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index f5d68cc549ad69..d3ac5f7b6627cd 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -50,6 +50,9 @@ #include "ext2fs/ext2fs.h" #include "ext2fs/ext2_fs.h" #include "ext2fs/ext2fsP.h" +#include "support/list.h" +#include "support/cache.h" +#include "support/iocache.h" #if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0) # define FUSE_PLATFORM_OPTS "" #else @@ -290,7 +293,6 @@ struct fuse2fs { unsigned int blockmask; unsigned long offset; unsigned int next_generation; - unsigned long long cache_size; char *lockfile; #ifdef HAVE_CLOCK_MONOTONIC struct timespec lock_start_time; @@ -1122,7 +1124,7 @@ static errcode_t fuse2fs_open(struct fuse2fs *ff, int libext2_flags) dbg_printf(ff, "opening with flags=0x%x\n", flags); - err = ext2fs_open2(ff->device, options, flags, 0, 0, unix_io_manager, + err = ext2fs_open2(ff->device, options, flags, 0, 0, iocache_io_manager, &ff->fs); if (err == EPERM) { err_printf(ff, "%s.\n", @@ -1150,25 +1152,6 @@ static inline bool fuse2fs_on_bdev(const struct fuse2fs *ff) return ff->fs->io->flags & CHANNEL_FLAGS_BLOCK_DEVICE; } -static errcode_t fuse2fs_config_cache(struct fuse2fs *ff) -{ - char buf[128]; - errcode_t err; - - snprintf(buf, sizeof(buf), "cache_blocks=%llu", - FUSE2FS_B_TO_FSBT(ff, ff->cache_size)); - err = io_channel_set_options(ff->fs->io, buf); - if (err) { - err_printf(ff, "%s %lluk: %s\n", - _("cannot set disk cache size to"), - ff->cache_size >> 10, - error_message(err)); - return err; - } - - return 0; -} - static errcode_t fuse2fs_check_support(struct fuse2fs *ff) { ext2_filsys fs = ff->fs; @@ -6829,7 +6812,6 @@ enum { FUSE2FS_VERSION, FUSE2FS_HELP, FUSE2FS_HELPFULL, - FUSE2FS_CACHE_SIZE, FUSE2FS_DIRSYNC, FUSE2FS_ERRORS_BEHAVIOR, #ifdef HAVE_FUSE_IOMAP @@ -6879,7 +6861,6 @@ static struct fuse_opt fuse2fs_opts[] = { FUSE_OPT_KEY("user_xattr", FUSE2FS_IGNORED), FUSE_OPT_KEY("noblock_validity", FUSE2FS_IGNORED), FUSE_OPT_KEY("nodelalloc", FUSE2FS_IGNORED), - FUSE_OPT_KEY("cache_size=%s", FUSE2FS_CACHE_SIZE), FUSE_OPT_KEY("dirsync", FUSE2FS_DIRSYNC), FUSE_OPT_KEY("errors=%s", FUSE2FS_ERRORS_BEHAVIOR), #ifdef HAVE_FUSE_IOMAP @@ -6918,16 +6899,6 @@ static int fuse2fs_opt_proc(void *data, const char *arg, return 0; } return 1; - case FUSE2FS_CACHE_SIZE: - ff->cache_size = parse_num_blocks2(arg + 11, -1); - if (ff->cache_size < 1 || ff->cache_size > INT32_MAX) { - fprintf(stderr, "%s: %s\n", arg, - _("cache size must be between 1 block and 2GB.")); - return -1; - } - - /* do not pass through to libfuse */ - return 0; case FUSE2FS_ERRORS_BEHAVIOR: if (strcmp(arg + 7, "continue") == 0) ff->errors_behavior = EXT2_ERRORS_CONTINUE; @@ -6984,7 +6955,6 @@ static int fuse2fs_opt_proc(void *data, const char *arg, " -o kernel run this as if it were the kernel, which sets:\n" " allow_others,default_permissions,suid,dev\n" " -o directio use O_DIRECT to read and write the disk\n" - " -o cache_size=N[KMG] use a disk cache of this size\n" " -o errors= behavior when an error is encountered:\n" " continue|remount-ro|panic\n" #ifdef HAVE_FUSE_IOMAP @@ -7028,28 +6998,6 @@ static const char *get_subtype(const char *argv0) return "ext4"; } -/* Figure out a reasonable default size for the disk cache */ -static unsigned long long default_cache_size(void) -{ - long pages = 0, pagesize = 0; - unsigned long long max_cache; - unsigned long long ret = 32ULL << 20; /* 32 MB */ - -#ifdef _SC_PHYS_PAGES - pages = sysconf(_SC_PHYS_PAGES); -#endif -#ifdef _SC_PAGESIZE - pagesize = sysconf(_SC_PAGESIZE); -#endif - if (pages > 0 && pagesize > 0) { - max_cache = (unsigned long long)pagesize * pages / 20; - - if (max_cache > 0 && ret > max_cache) - ret = max_cache; - } - return ret; -} - #ifdef HAVE_FUSE_IOMAP static inline bool fuse2fs_discover_iomap(struct fuse2fs *ff) { @@ -7170,6 +7118,7 @@ int main(int argc, char *argv[]) fctx.alloc_all_blocks = 1; } + iocache_set_backing_manager(unix_io_manager); err = fuse2fs_open(&fctx, EXT2_FLAG_EXCLUSIVE); if (err) { ret = 32; @@ -7206,16 +7155,6 @@ int main(int argc, char *argv[]) goto out; } - if (!fctx.cache_size) - fctx.cache_size = default_cache_size(); - if (fctx.cache_size) { - err = fuse2fs_config_cache(&fctx); - if (err) { - ret = 32; - goto out; - } - } - err = fuse2fs_check_support(&fctx); if (err) { ret = 32; diff --git a/misc/fuse4fs.c b/misc/fuse4fs.c index 6f03c6a0933a3d..85d73a9088d237 100644 --- a/misc/fuse4fs.c +++ b/misc/fuse4fs.c @@ -53,6 +53,7 @@ #include "ext2fs/ext2fsP.h" #include "support/list.h" #include "support/cache.h" +#include "support/iocache.h" #include "../version.h" #include "uuid/uuid.h" @@ -286,7 +287,6 @@ struct fuse4fs { unsigned int blockmask; unsigned long offset; unsigned int next_generation; - unsigned long long cache_size; char *lockfile; #ifdef HAVE_CLOCK_MONOTONIC struct timespec lock_start_time; @@ -1281,7 +1281,7 @@ static errcode_t fuse4fs_open(struct fuse4fs *ff, int libext2_flags) dbg_printf(ff, "opening with flags=0x%x\n", flags); - err = ext2fs_open2(ff->device, options, flags, 0, 0, unix_io_manager, + err = ext2fs_open2(ff->device, options, flags, 0, 0, iocache_io_manager, &ff->fs); if (err == EPERM) { err_printf(ff, "%s.\n", @@ -1313,25 +1313,6 @@ static inline bool fuse4fs_on_bdev(const struct fuse4fs *ff) return ff->fs->io->flags & CHANNEL_FLAGS_BLOCK_DEVICE; } -static errcode_t fuse4fs_config_cache(struct fuse4fs *ff) -{ - char buf[128]; - errcode_t err; - - snprintf(buf, sizeof(buf), "cache_blocks=%llu", - FUSE4FS_B_TO_FSBT(ff, ff->cache_size)); - err = io_channel_set_options(ff->fs->io, buf); - if (err) { - err_printf(ff, "%s %lluk: %s\n", - _("cannot set disk cache size to"), - ff->cache_size >> 10, - error_message(err)); - return err; - } - - return 0; -} - static errcode_t fuse4fs_check_support(struct fuse4fs *ff) { ext2_filsys fs = ff->fs; @@ -7113,7 +7094,6 @@ enum { FUSE4FS_VERSION, FUSE4FS_HELP, FUSE4FS_HELPFULL, - FUSE4FS_CACHE_SIZE, FUSE4FS_DIRSYNC, FUSE4FS_ERRORS_BEHAVIOR, #ifdef HAVE_FUSE_IOMAP @@ -7163,7 +7143,6 @@ static struct fuse_opt fuse4fs_opts[] = { FUSE_OPT_KEY("user_xattr", FUSE4FS_IGNORED), FUSE_OPT_KEY("noblock_validity", FUSE4FS_IGNORED), FUSE_OPT_KEY("nodelalloc", FUSE4FS_IGNORED), - FUSE_OPT_KEY("cache_size=%s", FUSE4FS_CACHE_SIZE), FUSE_OPT_KEY("dirsync", FUSE4FS_DIRSYNC), FUSE_OPT_KEY("errors=%s", FUSE4FS_ERRORS_BEHAVIOR), #ifdef HAVE_FUSE_IOMAP @@ -7202,16 +7181,6 @@ static int fuse4fs_opt_proc(void *data, const char *arg, return 0; } return 1; - case FUSE4FS_CACHE_SIZE: - ff->cache_size = parse_num_blocks2(arg + 11, -1); - if (ff->cache_size < 1 || ff->cache_size > INT32_MAX) { - fprintf(stderr, "%s: %s\n", arg, - _("cache size must be between 1 block and 2GB.")); - return -1; - } - - /* do not pass through to libfuse */ - return 0; case FUSE4FS_ERRORS_BEHAVIOR: if (strcmp(arg + 7, "continue") == 0) ff->errors_behavior = EXT2_ERRORS_CONTINUE; @@ -7268,7 +7237,6 @@ static int fuse4fs_opt_proc(void *data, const char *arg, " -o kernel run this as if it were the kernel, which sets:\n" " allow_others,default_permissions,suid,dev\n" " -o directio use O_DIRECT to read and write the disk\n" - " -o cache_size=N[KMG] use a disk cache of this size\n" " -o errors= behavior when an error is encountered:\n" " continue|remount-ro|panic\n" #ifdef HAVE_FUSE_IOMAP @@ -7311,28 +7279,6 @@ static const char *get_subtype(const char *argv0) return "ext4"; } -/* Figure out a reasonable default size for the disk cache */ -static unsigned long long default_cache_size(void) -{ - long pages = 0, pagesize = 0; - unsigned long long max_cache; - unsigned long long ret = 32ULL << 20; /* 32 MB */ - -#ifdef _SC_PHYS_PAGES - pages = sysconf(_SC_PHYS_PAGES); -#endif -#ifdef _SC_PAGESIZE - pagesize = sysconf(_SC_PAGESIZE); -#endif - if (pages > 0 && pagesize > 0) { - max_cache = (unsigned long long)pagesize * pages / 20; - - if (max_cache > 0 && ret > max_cache) - ret = max_cache; - } - return ret; -} - #ifdef HAVE_FUSE_IOMAP static inline bool fuse4fs_discover_iomap(struct fuse4fs *ff) { @@ -7554,6 +7500,7 @@ int main(int argc, char *argv[]) fctx.alloc_all_blocks = 1; } + iocache_set_backing_manager(unix_io_manager); err = fuse4fs_open(&fctx, EXT2_FLAG_EXCLUSIVE); if (err) { ret = 32; @@ -7603,16 +7550,6 @@ int main(int argc, char *argv[]) fctx.translate_inums = 0; } - if (!fctx.cache_size) - fctx.cache_size = default_cache_size(); - if (fctx.cache_size) { - err = fuse4fs_config_cache(&fctx); - if (err) { - ret = 32; - goto out; - } - } - err = fuse4fs_check_support(&fctx); if (err) { ret = 32;