The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxcfs/pull/426
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Signed-off-by: Scott Parlane <scott.parl...@alliedtelesis.co.nz>
From 09dffa69e29f492cedc0d296be37e57c4e50f6fe Mon Sep 17 00:00:00 2001 From: Scott Parlane <scott.parl...@alliedtelesis.co.nz> Date: Thu, 3 Sep 2020 12:54:39 +1200 Subject: [PATCH] Add support for fuse3 Signed-off-by: Scott Parlane <scott.parl...@alliedtelesis.co.nz> --- configure.ac | 4 ++- src/bindings.c | 9 ++++++- src/cgroup_fuse.c | 20 ++++++++++----- src/cgroups/cgfsng.c | 9 ++++++- src/cgroups/cgroup.c | 9 ++++++- src/cgroups/cgroup2_devices.c | 9 ++++++- src/cgroups/cgroup_utils.c | 9 ++++++- src/cpuset_parse.c | 9 ++++++- src/lxcfs.c | 47 ++++++++++++++++++++++++++++++----- src/proc_cpuview.c | 9 ++++++- src/proc_fuse.c | 28 +++++++++++++-------- src/proc_loadavg.c | 9 ++++++- src/sysfs_fuse.c | 34 +++++++++++++++---------- src/utils.c | 9 ++++++- 14 files changed, 169 insertions(+), 45 deletions(-) diff --git a/configure.ac b/configure.ac index 4092883..90bcd8d 100644 --- a/configure.ac +++ b/configure.ac @@ -60,7 +60,9 @@ AC_CONFIG_FILES([ AC_CHECK_LIB(pthread, main) -PKG_CHECK_MODULES(FUSE, fuse) +PKG_CHECK_MODULES(FUSE, fuse, [], [ + PKG_CHECK_MODULES(FUSE, fuse3, [AC_DEFINE([HAVE_FUSE3], [1], [Use fuse3])]) +]) AC_PATH_PROG(HELP2MAN, help2man, false // No help2man //) AM_CONDITIONAL([HAVE_HELP2MAN], [test "x$HELP2MAN" != "xfalse // No help2man //" ]) diff --git a/src/bindings.c b/src/bindings.c index 74716d1..6f395fb 100644 --- a/src/bindings.c +++ b/src/bindings.c @@ -4,9 +4,17 @@ #define _GNU_SOURCE #endif +#include "config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -43,7 +51,6 @@ #include "cgroup_fuse.h" #include "cgroups/cgroup.h" #include "cgroups/cgroup_utils.h" -#include "config.h" #include "memory_utils.h" #include "proc_cpuview.h" #include "syscall_numbers.h" diff --git a/src/cgroup_fuse.c b/src/cgroup_fuse.c index d4bdac1..b9d09f9 100644 --- a/src/cgroup_fuse.c +++ b/src/cgroup_fuse.c @@ -4,9 +4,17 @@ #define _GNU_SOURCE #endif +#include "config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -40,9 +48,9 @@ #include <sys/vfs.h> #include "bindings.h" -#include "config.h" #include "cgroups/cgroup.h" #include "cgroups/cgroup_utils.h" +#include "fuse_compat.h" #include "memory_utils.h" #include "utils.h" @@ -1953,7 +1961,7 @@ __lxcfs_fuse_ops int cg_readdir(const char *path, void *buf, if (!fc || !cgroup_ops || pure_unified_layout(cgroup_ops)) return -EIO; - if (filler(buf, ".", NULL, 0) != 0 || filler(buf, "..", NULL, 0) != 0) + if (DIR_FILLER(filler, buf, ".", NULL, 0) != 0 || DIR_FILLER(filler, buf, "..", NULL, 0) != 0) return -EIO; if (d->type != LXC_TYPE_CGDIR) { @@ -1969,7 +1977,7 @@ __lxcfs_fuse_ops int cg_readdir(const char *path, void *buf, if (is_unified_hierarchy(*h)) continue; - if ((*h)->__controllers && filler(buf, (*h)->__controllers, NULL, 0)) + if ((*h)->__controllers && DIR_FILLER(filler, buf, (*h)->__controllers, NULL, 0)) return -EIO; } @@ -1987,7 +1995,7 @@ __lxcfs_fuse_ops int cg_readdir(const char *path, void *buf, initpid = fc->pid; if (!caller_is_in_ancestor(initpid, d->controller, d->cgroup, &nextcg)) { if (nextcg) { - ret = filler(buf, nextcg, NULL, 0); + ret = DIR_FILLER(filler, buf, nextcg, NULL, 0); free(nextcg); if (ret != 0) { ret = -EIO; @@ -1999,7 +2007,7 @@ __lxcfs_fuse_ops int cg_readdir(const char *path, void *buf, } for (i = 0; list && list[i]; i++) { - if (filler(buf, list[i]->name, NULL, 0) != 0) { + if (DIR_FILLER(filler, buf, list[i]->name, NULL, 0) != 0) { ret = -EIO; goto out; } @@ -2013,7 +2021,7 @@ __lxcfs_fuse_ops int cg_readdir(const char *path, void *buf, } if (clist) { for (i = 0; clist[i]; i++) { - if (filler(buf, clist[i], NULL, 0) != 0) { + if (DIR_FILLER(filler, buf, clist[i], NULL, 0) != 0) { ret = -EIO; goto out; } diff --git a/src/cgroups/cgfsng.c b/src/cgroups/cgfsng.c index cf891b3..824b0e7 100644 --- a/src/cgroups/cgfsng.c +++ b/src/cgroups/cgfsng.c @@ -16,9 +16,17 @@ #define _GNU_SOURCE #endif +#include "../config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -38,7 +46,6 @@ #include <sys/types.h> #include <unistd.h> -#include "../config.h" #include "../macro.h" #include "../memory_utils.h" #include "../utils.h" diff --git a/src/cgroups/cgroup.c b/src/cgroups/cgroup.c index 6fe1902..26c87ae 100644 --- a/src/cgroups/cgroup.c +++ b/src/cgroups/cgroup.c @@ -4,9 +4,17 @@ #define _GNU_SOURCE #endif +#include "../config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -30,7 +38,6 @@ #include <sys/vfs.h> #include <unistd.h> -#include "../config.h" #include "../macro.h" #include "../memory_utils.h" #include "cgroup.h" diff --git a/src/cgroups/cgroup2_devices.c b/src/cgroups/cgroup2_devices.c index 30e2e46..c40b087 100644 --- a/src/cgroups/cgroup2_devices.c +++ b/src/cgroups/cgroup2_devices.c @@ -6,9 +6,17 @@ #define _GNU_SOURCE #endif +#include "../config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -22,7 +30,6 @@ #include <sys/types.h> #include <unistd.h> -#include "../config.h" #include "../macro.h" #include "../memory_utils.h" #include "cgroup2_devices.h" diff --git a/src/cgroups/cgroup_utils.c b/src/cgroups/cgroup_utils.c index 078f864..5165a09 100644 --- a/src/cgroups/cgroup_utils.c +++ b/src/cgroups/cgroup_utils.c @@ -4,9 +4,17 @@ #define _GNU_SOURCE #endif +#include "../config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -22,7 +30,6 @@ #include <sys/vfs.h> #include <unistd.h> -#include "../config.h" #include "../macro.h" #include "../memory_utils.h" #include "cgroup.h" diff --git a/src/cpuset_parse.c b/src/cpuset_parse.c index 55534d6..58453f0 100644 --- a/src/cpuset_parse.c +++ b/src/cpuset_parse.c @@ -4,9 +4,17 @@ #define _GNU_SOURCE #endif +#include "config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -20,7 +28,6 @@ #include "bindings.h" #include "cgroups/cgroup.h" #include "cgroups/cgroup_utils.h" -#include "config.h" #include "memory_utils.h" #include "proc_loadavg.h" #include "utils.h" diff --git a/src/lxcfs.c b/src/lxcfs.c index 94256d4..cde5f4a 100644 --- a/src/lxcfs.c +++ b/src/lxcfs.c @@ -4,9 +4,17 @@ #define _GNU_SOURCE #endif +#include "config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -33,7 +41,7 @@ #include <linux/limits.h> #include "bindings.h" -#include "config.h" +#include "fuse_compat.h" #include "macro.h" #include "memory_utils.h" @@ -562,7 +570,11 @@ static int do_sys_releasedir(const char *path, struct fuse_file_info *fi) return __sys_releasedir(path, fi); } +#ifdef HAVE_FUSE3 +static int lxcfs_getattr(const char *path, struct stat *sb, struct fuse_file_info *fi) +#else static int lxcfs_getattr(const char *path, struct stat *sb) +#endif { int ret; struct timespec now; @@ -625,17 +637,22 @@ static int lxcfs_opendir(const char *path, struct fuse_file_info *fi) return -ENOENT; } +#ifdef HAVE_FUSE3 +static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, + off_t offset, struct fuse_file_info *fi, enum fuse_readdir_flags flags) +#else static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) +#endif { int ret; if (strcmp(path, "/") == 0) { - if (filler(buf, ".", NULL, 0) != 0 || - filler(buf, "..", NULL, 0) != 0 || - filler(buf, "proc", NULL, 0) != 0 || - filler(buf, "sys", NULL, 0) != 0 || - filler(buf, "cgroup", NULL, 0) != 0) + if (DIR_FILLER(filler, buf, ".", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "..", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "proc", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "sys", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "cgroup", NULL, 0) != 0) return -ENOMEM; return 0; @@ -847,7 +864,11 @@ int lxcfs_mkdir(const char *path, mode_t mode) return -EPERM; } +#ifdef HAVE_FUSE3 +int lxcfs_chown(const char *path, uid_t uid, gid_t gid, struct fuse_file_info *fi) +#else int lxcfs_chown(const char *path, uid_t uid, gid_t gid) +#endif { int ret; @@ -872,7 +893,11 @@ int lxcfs_chown(const char *path, uid_t uid, gid_t gid) * really make sense for cgroups. So just return 0 always but do * nothing. */ +#ifdef HAVE_FUSE3 +int lxcfs_truncate(const char *path, off_t newsize, struct fuse_file_info *fi) +#else int lxcfs_truncate(const char *path, off_t newsize) +#endif { if (strncmp(path, "/cgroup", 7) == 0) return 0; @@ -894,7 +919,11 @@ int lxcfs_rmdir(const char *path) return -EPERM; } +#ifdef HAVE_FUSE3 +int lxcfs_chmod(const char *path, mode_t mode, struct fuse_file_info *fi) +#else int lxcfs_chmod(const char *path, mode_t mode) +#endif { int ret; @@ -934,10 +963,14 @@ const struct fuse_operations lxcfs_ops = { .create = NULL, .destroy = NULL, +#ifndef HAVE_FUSE3 .fgetattr = NULL, +#endif .fsyncdir = NULL, +#ifndef HAVE_FUSE3 .ftruncate = NULL, .getdir = NULL, +#endif .getxattr = NULL, .init = NULL, .link = NULL, @@ -950,7 +983,9 @@ const struct fuse_operations lxcfs_ops = { .statfs = NULL, .symlink = NULL, .unlink = NULL, +#ifndef HAVE_FUSE3 .utime = NULL, +#endif }; static void usage() diff --git a/src/proc_cpuview.c b/src/proc_cpuview.c index 7d6c0bd..b004663 100644 --- a/src/proc_cpuview.c +++ b/src/proc_cpuview.c @@ -4,9 +4,17 @@ #define _GNU_SOURCE #endif +#include "config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -40,7 +48,6 @@ #include <sys/vfs.h> #include "bindings.h" -#include "config.h" #include "cgroup_fuse.h" #include "cpuset_parse.h" #include "cgroups/cgroup.h" diff --git a/src/proc_fuse.c b/src/proc_fuse.c index a99162c..517c57e 100644 --- a/src/proc_fuse.c +++ b/src/proc_fuse.c @@ -4,9 +4,17 @@ #define _GNU_SOURCE #endif +#include "config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -40,11 +48,11 @@ #include <sys/vfs.h> #include "bindings.h" -#include "config.h" #include "cgroup_fuse.h" #include "cgroups/cgroup.h" #include "cgroups/cgroup_utils.h" #include "cpuset_parse.h" +#include "fuse_compat.h" #include "memory_utils.h" #include "proc_loadavg.h" #include "proc_cpuview.h" @@ -108,15 +116,15 @@ __lxcfs_fuse_ops int proc_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { - if (filler(buf, ".", NULL, 0) != 0 || - filler(buf, "..", NULL, 0) != 0 || - filler(buf, "cpuinfo", NULL, 0) != 0 || - filler(buf, "meminfo", NULL, 0) != 0 || - filler(buf, "stat", NULL, 0) != 0 || - filler(buf, "uptime", NULL, 0) != 0 || - filler(buf, "diskstats", NULL, 0) != 0 || - filler(buf, "swaps", NULL, 0) != 0 || - filler(buf, "loadavg", NULL, 0) != 0) + if (DIR_FILLER(filler, buf, ".", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "..", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "cpuinfo", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "meminfo", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "stat", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "uptime", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "diskstats", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "swaps", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "loadavg", NULL, 0) != 0) return -EINVAL; return 0; diff --git a/src/proc_loadavg.c b/src/proc_loadavg.c index 7a7a39e..ca90b06 100644 --- a/src/proc_loadavg.c +++ b/src/proc_loadavg.c @@ -4,9 +4,17 @@ #define _GNU_SOURCE #endif +#include "config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -40,7 +48,6 @@ #include <sys/vfs.h> #include "bindings.h" -#include "config.h" #include "cgroup_fuse.h" #include "cgroups/cgroup.h" #include "cgroups/cgroup_utils.h" diff --git a/src/sysfs_fuse.c b/src/sysfs_fuse.c index d6f7876..575e932 100644 --- a/src/sysfs_fuse.c +++ b/src/sysfs_fuse.c @@ -4,9 +4,17 @@ #define _GNU_SOURCE #endif +#include "config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -41,7 +49,7 @@ #include "bindings.h" #include "memory_utils.h" #include "cgroups/cgroup.h" -#include "config.h" +#include "fuse_compat.h" #include "sysfs_fuse.h" #include "utils.h" @@ -184,33 +192,33 @@ __lxcfs_fuse_ops int sys_readdir(const char *path, void *buf, struct fuse_file_info *fi) { if (strcmp(path, "/sys") == 0) { - if (filler(buf, ".", NULL, 0) != 0 || - filler(buf, "..", NULL, 0) != 0 || - filler(buf, "devices", NULL, 0) != 0) + if (DIR_FILLER(filler, buf, ".", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "..", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "devices", NULL, 0) != 0) return -ENOENT; return 0; } if (strcmp(path, "/sys/devices") == 0) { - if (filler(buf, ".", NULL, 0) != 0 || - filler(buf, "..", NULL, 0) != 0 || - filler(buf, "system", NULL, 0) != 0) + if (DIR_FILLER(filler, buf, ".", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "..", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "system", NULL, 0) != 0) return -ENOENT; return 0; } if (strcmp(path, "/sys/devices/system") == 0) { - if (filler(buf, ".", NULL, 0) != 0 || - filler(buf, "..", NULL, 0) != 0 || - filler(buf, "cpu", NULL, 0) != 0) + if (DIR_FILLER(filler, buf, ".", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "..", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "cpu", NULL, 0) != 0) return -ENOENT; return 0; } if (strcmp(path, "/sys/devices/system/cpu") == 0) { - if (filler(buf, ".", NULL, 0) != 0 || - filler(buf, "..", NULL, 0) != 0 || - filler(buf, "online", NULL, 0) != 0) + if (DIR_FILLER(filler, buf, ".", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "..", NULL, 0) != 0 || + DIR_FILLER(filler, buf, "online", NULL, 0) != 0) return -ENOENT; return 0; diff --git a/src/utils.c b/src/utils.c index fcb7d61..65629eb 100644 --- a/src/utils.c +++ b/src/utils.c @@ -4,9 +4,17 @@ #define _GNU_SOURCE #endif +#include "config.h" + +#ifdef HAVE_FUSE3 +#ifndef FUSE_USE_VERSION +#define FUSE_USE_VERSION 30 +#endif +#else #ifndef FUSE_USE_VERSION #define FUSE_USE_VERSION 26 #endif +#endif #define _FILE_OFFSET_BITS 64 @@ -29,7 +37,6 @@ #include <unistd.h> #include "bindings.h" -#include "config.h" #include "macro.h" #include "memory_utils.h" #include "utils.h"
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel