]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
bindings: fix struct lxcfs_opts by making it versioned
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 27 May 2021 15:17:24 +0000 (17:17 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 27 May 2021 15:54:38 +0000 (17:54 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/bindings.c
src/bindings.h
src/lxcfs.c

index 6f395fb42f98656dc89181e47401f1416a86b9c5..70906c67d6d019b3997ce31dad5d85692f90ddc2 100644 (file)
@@ -58,6 +58,8 @@
 
 static bool can_use_pidfd;
 static bool can_use_swap;
+static bool can_use_sys_cpu;
+static bool has_versioned_opts;
 
 static volatile sig_atomic_t reload_successful;
 
@@ -71,6 +73,16 @@ bool liblxcfs_can_use_swap(void)
        return can_use_swap;
 }
 
+bool liblxcfs_can_use_sys_cpu(void)
+{
+       return can_use_sys_cpu;
+}
+
+bool liblxcfs_has_versioned_opts(void)
+{
+       return has_versioned_opts;
+}
+
 /* Define pivot_root() if missing from the C library */
 #ifndef HAVE_PIVOT_ROOT
 static int pivot_root(const char *new_root, const char *put_old)
@@ -929,3 +941,11 @@ static void __attribute__((destructor)) lxcfs_exit(void)
        free_cpuview();
        cgroup_exit(cgroup_ops);
 }
+
+void *lxcfs_fuse_init(struct fuse_conn_info *conn, struct fuse_config *cfg)
+{
+       struct fuse_context *fc = fuse_get_context();
+       can_use_sys_cpu = true;
+       has_versioned_opts = true;
+       return fc->private_data;
+}
index 81ed8be10ef06ab18f634146d0e478eb6ac00fb3..c79b81b0e05603d6e7955416ff4a6830db448176 100644 (file)
@@ -14,6 +14,7 @@
 #define _FILE_OFFSET_BITS 64
 
 #include <fuse.h>
+#include <linux/types.h>
 #include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -91,6 +92,11 @@ struct lxcfs_opts {
        bool swap_off;
        bool use_pidfd;
        bool use_cfs;
+       /*
+        * Ideally we'd version by size but because of backwards compatability
+        * and the use of bool instead of explicited __u32 and __u64 we can't.
+        */
+       __u32 version;
 };
 
 typedef enum lxcfs_opt_t {
@@ -106,6 +112,8 @@ extern void prune_init_slice(char *cg);
 extern bool supports_pidfd(void);
 extern bool liblxcfs_functional(void);
 extern bool liblxcfs_can_use_swap(void);
+extern bool liblxcfs_can_use_sys_cpu(void);
+extern bool liblxcfs_has_versioned_opts(void);
 
 static inline bool lxcfs_has_opt(struct lxcfs_opts *opts, lxcfs_opt_t opt)
 {
@@ -156,4 +164,7 @@ static inline pid_t lxcfs_clone(int (*fn)(void *), void *arg, int flags)
        return pid;
 }
 
+__visible extern void *lxcfs_fuse_init(struct fuse_conn_info *conn,
+                                      struct fuse_config *cfg);
+
 #endif /* __LXCFS_BINDINGS_H */
index 42d27b05612cf4399c8405ac2ccf8d09288b3dd3..ab34c09f0cbeddeb7ffa9be5131c4b07728ecb71 100644 (file)
@@ -1015,6 +1015,20 @@ int lxcfs_chmod(const char *path, mode_t mode)
        return -ENOENT;
 }
 
+static void *lxcfs_init(struct fuse_conn_info *conn, struct fuse_config *cfg)
+{
+       char *error;
+       void *(*__lxcfs_fuse_init)(struct fuse_conn_info * conn, struct fuse_config * cfg);
+
+       dlerror();
+       __lxcfs_fuse_init = (void *(*)(struct fuse_conn_info * conn, struct fuse_config * cfg))dlsym(dlopen_handle, "lxcfs_fuse_init");
+       error = dlerror();
+       if (error)
+               return log_error(NULL, "%s - Failed to find lxcfs_fuse_init()", error);
+
+       return __lxcfs_fuse_init(conn, cfg);
+}
+
 const struct fuse_operations lxcfs_ops = {
        .access         = lxcfs_access,
        .chmod          = lxcfs_chmod,
@@ -1022,6 +1036,7 @@ const struct fuse_operations lxcfs_ops = {
        .flush          = lxcfs_flush,
        .fsync          = lxcfs_fsync,
        .getattr        = lxcfs_getattr,
+       .init           = lxcfs_init,
        .mkdir          = lxcfs_mkdir,
        .open           = lxcfs_open,
        .opendir        = lxcfs_opendir,
@@ -1045,7 +1060,6 @@ const struct fuse_operations lxcfs_ops = {
        .getdir         = NULL,
 #endif
        .getxattr       = NULL,
-       .init           = NULL,
        .link           = NULL,
        .listxattr      = NULL,
        .mknod          = NULL,
@@ -1195,6 +1209,7 @@ int main(int argc, char *argv[])
        opts->swap_off = false;
        opts->use_pidfd = false;
        opts->use_cfs = false;
+       opts->version = 1;
 
        while ((c = getopt_long(argc, argv, "dulfhvso:p:", long_options, &idx)) != -1) {
                switch (c) {