]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
re-initialize library after reload
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 5 Jul 2022 08:26:26 +0000 (10:26 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 5 Jul 2022 08:50:53 +0000 (10:50 +0200)
When introducing versioned options, we started using fuse's
"init" callback in order to tell the library to set
`can_use_sys_cpu` and `has_versioned_opts` accordingly.

However, we forgot to also do this on a reload. Fix this by
simply calling `lxcfs_fuse_init()` in `do_reload()` as well.

Additionaly: ignore lxcfs_fuse_init()'s return value.
We just "passed through" the private_data from fuse which is
set via the `fuse_main()` call.

It's better to not leave this up to the library anyway in
order to make it easier to be fuse version agnostic in the
future.

Without this, issuing a reload to lxcfs would cause
files in `/sys/devices/system/cpu/` to be visible via
`readdir`, but accessing them would fail:

    ~ # ls /sys/devices/system/cpu/
    ls: /sys/devices/system/cpu/cpuidle: No such file or directory
    ls: /sys/devices/system/cpu/uevent: No such file or directory
    (...)

    ~ # echo /sys/devices/system/cpu/*
    /sys/devices/system/cpu/cpu0 /sys/devices/system/cpu/cpu1 (...)

    ~ # strace stat /sys/devices/system/cpu/cpu0
    lstat("/sys/devices/system/cpu/cpu0", 0x7ffdb2c57a00) = -1 ENOENT (No such file or directory)

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/lxcfs.c

index eb1d91edf1ee0b1f956b0952ad8db21e24558db4..d1a3d805c0c9cdf805453335c4b2d00cc30e2084 100644 (file)
@@ -105,6 +105,22 @@ static int stop_loadavg(void)
 
 static volatile sig_atomic_t need_reload;
 
+static int lxcfs_init_library(void)
+{
+       char *error;
+       void *(*__lxcfs_fuse_init)(struct fuse_conn_info * conn, void * cfg);
+
+       dlerror();
+       __lxcfs_fuse_init = (void *(*)(struct fuse_conn_info * conn, void * cfg))dlsym(dlopen_handle, "lxcfs_fuse_init");
+       error = dlerror();
+       if (error)
+               return log_error(-1, "%s - Failed to find lxcfs_fuse_init()", error);
+
+       __lxcfs_fuse_init(NULL, NULL);
+
+       return 0;
+}
+
 /* do_reload - reload the dynamic library.  Done under
  * lock and when we know the user_count was 0 */
 static void do_reload(void)
@@ -147,6 +163,11 @@ static void do_reload(void)
                lxcfs_debug("Opened %s", lxcfs_lib_path);
 
 good:
+       /* initialize the library */
+       if (lxcfs_init_library() < 0) {
+               log_exit("Failed to initialize liblxcfs.so");
+       }
+
        if (loadavg_pid > 0)
                start_loadavg();
 
@@ -1006,16 +1027,10 @@ static void *lxcfs_init(struct fuse_conn_info *conn, struct fuse_config *cfg)
 static void *lxcfs_init(struct fuse_conn_info *conn)
 #endif
 {
-       char *error;
-       void *(*__lxcfs_fuse_init)(struct fuse_conn_info * conn, void * cfg);
-
-       dlerror();
-       __lxcfs_fuse_init = (void *(*)(struct fuse_conn_info * conn, void * cfg))dlsym(dlopen_handle, "lxcfs_fuse_init");
-       error = dlerror();
-       if (error)
-               return log_error(NULL, "%s - Failed to find lxcfs_fuse_init()", error);
+       if (lxcfs_init_library() < 0)
+               return NULL;
 
-       return __lxcfs_fuse_init(conn, NULL);
+       return fuse_get_context()->private_data;
 }
 
 const struct fuse_operations lxcfs_ops = {