]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
Add support for fuse3
authorScott Parlane <scott.parlane@alliedtelesis.co.nz>
Thu, 3 Sep 2020 00:54:39 +0000 (12:54 +1200)
committerScott Parlane <scott.parlane@alliedtelesis.co.nz>
Thu, 3 Sep 2020 02:15:56 +0000 (14:15 +1200)
Signed-off-by: Scott Parlane <scott.parlane@alliedtelesis.co.nz>
15 files changed:
configure.ac
src/bindings.c
src/cgroup_fuse.c
src/cgroups/cgfsng.c
src/cgroups/cgroup.c
src/cgroups/cgroup2_devices.c
src/cgroups/cgroup_utils.c
src/cpuset_parse.c
src/fuse_compat.h [new file with mode: 0644]
src/lxcfs.c
src/proc_cpuview.c
src/proc_fuse.c
src/proc_loadavg.c
src/sysfs_fuse.c
src/utils.c

index 40928831e530e837eb37a7cc94928fd332844af8..90bcd8d6da342c33e3f4831b1e19ae6fb6c21f89 100644 (file)
@@ -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 //" ])
index 74716d1c0a93190a45885c492b4a77043803ae3e..6f395fb42f98656dc89181e47401f1416a86b9c5 100644 (file)
@@ -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"
index d4bdac139c3f4f6f2cab4c9229bf9c7bd130f200..b9d09f93f10fe0236ac769d188aa11f5ba4cf602 100644 (file)
@@ -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;
                        }
index cf891b3ba0429810463df3e03b155917a323df0d..824b0e7c5ae1dedc58bfed83f61907b949339be8 100644 (file)
 #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"
index 6fe19027ac6268bdc233b944fe43ed18a585ccb9..26c87aeb063648286c2f06cd4d3c7d5ada1b955d 100644 (file)
@@ -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"
index 30e2e461a5128d8a9cc6298769046f60da774166..c40b087d130f9559d453db4c6247c3e304d3f5e7 100644 (file)
@@ -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"
index 078f86462d58b7e3b6d69c8d3a71e97adabd75b5..5165a0900f0b382efc7e7a435a1b17ec8edb1d97 100644 (file)
@@ -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"
index 55534d6ff632323fb793acc156cf5c3361daafba..58453f06d9a2254f0cc05d10363e3e7339fd0875 100644 (file)
@@ -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/fuse_compat.h b/src/fuse_compat.h
new file mode 100644 (file)
index 0000000..a610e7e
--- /dev/null
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#ifndef __LXC_FUSE_COMPAT_H
+#define __LXC_FUSE_COMPAT_H
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#ifdef HAVE_FUSE3
+#define DIR_FILLER(F,B,N,S,O) F(B,N,S,O,FUSE_FILL_DIR_PLUS)
+#else
+#define DIR_FILLER(F,B,N,S,O) F(B,N,S,O)
+#endif
+#endif /* __LXC_FUSE_COMPAT_H */
index 94256d43acb173bd295ee7e3e934a960ffa9f039..cde5f4a6843c5df72f6af3ffbbdbc21d56f34420 100644 (file)
@@ -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()
index 7d6c0bdd86baa5d080316f788efc4f4e7e2b7c3e..b0046638d70a9aff47286829982b20675ff0ddb7 100644 (file)
@@ -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"
index a99162c31afee5d8bb667575cae295223e517d74..517c57ee916ebdd46a46cec532d2bfae2f463fd2 100644 (file)
@@ -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
 
 #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;
index 7a7a39efb8e58d167891c58a409e271c97048d11..ca90b06a1aad0eb1b9e73c6d6c440793a6af38b2 100644 (file)
@@ -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"
index d6f78764711c5142af59c99ee9dddca3bf15dd02..575e932389ee44999e7f5a64fca3557da2821725 100644 (file)
@@ -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;
index fcb7d618980459ea626ec8e15bb017843ca7814a..65629eb6850c35118b66e338e103508bf952fa9d 100644 (file)
@@ -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"