Skip to content

Commit 285aea4

Browse files
author
Christian Brauner
committed
bindings: fix struct lxcfs_opts by making it versioned
Signed-off-by: Christian Brauner <[email protected]>
1 parent 4e73670 commit 285aea4

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/bindings.c

+20
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858

5959
static bool can_use_pidfd;
6060
static bool can_use_swap;
61+
static bool can_use_sys_cpu;
62+
static bool has_versioned_opts;
6163

6264
static volatile sig_atomic_t reload_successful;
6365

@@ -71,6 +73,16 @@ bool liblxcfs_can_use_swap(void)
7173
return can_use_swap;
7274
}
7375

76+
bool liblxcfs_can_use_sys_cpu(void)
77+
{
78+
return can_use_sys_cpu;
79+
}
80+
81+
bool liblxcfs_has_versioned_opts(void)
82+
{
83+
return has_versioned_opts;
84+
}
85+
7486
/* Define pivot_root() if missing from the C library */
7587
#ifndef HAVE_PIVOT_ROOT
7688
static int pivot_root(const char *new_root, const char *put_old)
@@ -929,3 +941,11 @@ static void __attribute__((destructor)) lxcfs_exit(void)
929941
free_cpuview();
930942
cgroup_exit(cgroup_ops);
931943
}
944+
945+
void *lxcfs_fuse_init(struct fuse_conn_info *conn, struct fuse_config *cfg)
946+
{
947+
struct fuse_context *fc = fuse_get_context();
948+
can_use_sys_cpu = true;
949+
has_versioned_opts = true;
950+
return fc->private_data;
951+
}

src/bindings.h

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define _FILE_OFFSET_BITS 64
1515

1616
#include <fuse.h>
17+
#include <linux/types.h>
1718
#include <signal.h>
1819
#include <stdbool.h>
1920
#include <stdio.h>
@@ -91,6 +92,11 @@ struct lxcfs_opts {
9192
bool swap_off;
9293
bool use_pidfd;
9394
bool use_cfs;
95+
/*
96+
* Ideally we'd version by size but because of backwards compatability
97+
* and the use of bool instead of explicited __u32 and __u64 we can't.
98+
*/
99+
__u32 version;
94100
};
95101

96102
typedef enum lxcfs_opt_t {
@@ -106,6 +112,8 @@ extern void prune_init_slice(char *cg);
106112
extern bool supports_pidfd(void);
107113
extern bool liblxcfs_functional(void);
108114
extern bool liblxcfs_can_use_swap(void);
115+
extern bool liblxcfs_can_use_sys_cpu(void);
116+
extern bool liblxcfs_has_versioned_opts(void);
109117

110118
static inline bool lxcfs_has_opt(struct lxcfs_opts *opts, lxcfs_opt_t opt)
111119
{
@@ -156,4 +164,7 @@ static inline pid_t lxcfs_clone(int (*fn)(void *), void *arg, int flags)
156164
return pid;
157165
}
158166

167+
__visible extern void *lxcfs_fuse_init(struct fuse_conn_info *conn,
168+
struct fuse_config *cfg);
169+
159170
#endif /* __LXCFS_BINDINGS_H */

src/lxcfs.c

+16-1
Original file line numberDiff line numberDiff line change
@@ -1015,13 +1015,28 @@ int lxcfs_chmod(const char *path, mode_t mode)
10151015
return -ENOENT;
10161016
}
10171017

1018+
static void *lxcfs_init(struct fuse_conn_info *conn, struct fuse_config *cfg)
1019+
{
1020+
char *error;
1021+
void *(*__lxcfs_fuse_init)(struct fuse_conn_info * conn, struct fuse_config * cfg);
1022+
1023+
dlerror();
1024+
__lxcfs_fuse_init = (void *(*)(struct fuse_conn_info * conn, struct fuse_config * cfg))dlsym(dlopen_handle, "lxcfs_fuse_init");
1025+
error = dlerror();
1026+
if (error)
1027+
return log_error(NULL, "%s - Failed to find lxcfs_fuse_init()", error);
1028+
1029+
return __lxcfs_fuse_init(conn, cfg);
1030+
}
1031+
10181032
const struct fuse_operations lxcfs_ops = {
10191033
.access = lxcfs_access,
10201034
.chmod = lxcfs_chmod,
10211035
.chown = lxcfs_chown,
10221036
.flush = lxcfs_flush,
10231037
.fsync = lxcfs_fsync,
10241038
.getattr = lxcfs_getattr,
1039+
.init = lxcfs_init,
10251040
.mkdir = lxcfs_mkdir,
10261041
.open = lxcfs_open,
10271042
.opendir = lxcfs_opendir,
@@ -1045,7 +1060,6 @@ const struct fuse_operations lxcfs_ops = {
10451060
.getdir = NULL,
10461061
#endif
10471062
.getxattr = NULL,
1048-
.init = NULL,
10491063
.link = NULL,
10501064
.listxattr = NULL,
10511065
.mknod = NULL,
@@ -1195,6 +1209,7 @@ int main(int argc, char *argv[])
11951209
opts->swap_off = false;
11961210
opts->use_pidfd = false;
11971211
opts->use_cfs = false;
1212+
opts->version = 1;
11981213

11991214
while ((c = getopt_long(argc, argv, "dulfhvso:p:", long_options, &idx)) != -1) {
12001215
switch (c) {

0 commit comments

Comments
 (0)