]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
sysfs_fuse: generate file info for cpu<nr> entries as well
authorChristian Brauner (Microsoft) <christian.brauner@ubuntu.com>
Sun, 13 Mar 2022 09:06:02 +0000 (10:06 +0100)
committerChristian Brauner (Microsoft) <christian.brauner@ubuntu.com>
Sun, 13 Mar 2022 09:28:00 +0000 (10:28 +0100)
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
src/lxcfs_fuse_compat.h
src/sysfs_fuse.c

index d12ecef35239e6ecafb0f498fcc4a7811e76bace..347f07390b0ddda56097069ef44299c85e2798d8 100644 (file)
 
 #include "memory_utils.h"
 
-#if HAVE_FUSE3
-static inline int dir_filler(fuse_fill_dir_t filler, void *buf,
-                            const char *name, off_t off)
-{
-       return filler(buf, name, NULL, off, FUSE_FILL_DIR_PLUS);
-}
-
-static inline int dirent_filler(fuse_fill_dir_t filler, const char *path,
-                               const char *name, void *buf, off_t off)
-{
-       return filler(buf, name, NULL, off, FUSE_FILL_DIR_PLUS);
-}
-
-static inline int dirent_fillerat(fuse_fill_dir_t filler, DIR *dp,
-                                 struct dirent *dentry, void *buf, off_t off)
-{
-       return filler(buf, dentry->d_name, NULL, off, FUSE_FILL_DIR_PLUS);
-}
+#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
+
 static inline int dir_filler(fuse_fill_dir_t filler, void *buf,
                             const char *name, off_t off)
 {
-       return filler(buf, name, NULL, off);
+       return DIR_FILLER(filler, buf, name, NULL, off);
 }
 
 static inline int dirent_filler(fuse_fill_dir_t filler, const char *path,
@@ -44,9 +31,9 @@ static inline int dirent_filler(fuse_fill_dir_t filler, const char *path,
 
        dirp = opendir(path);
        if (dirp && !fstatat(dirfd(dirp), name, &st, AT_SYMLINK_NOFOLLOW))
-               return filler(buf, name, &st, off);
+               return DIR_FILLER(filler, buf, name, &st, off);
 
-       return filler(buf, name, NULL, off);
+       return DIR_FILLER(filler, buf, name, NULL, off);
 }
 
 static inline int dirent_fillerat(fuse_fill_dir_t filler, DIR *dp,
@@ -63,8 +50,19 @@ static inline int dirent_fillerat(fuse_fill_dir_t filler, DIR *dp,
                };
        }
 
-       return filler(buf, dentry->d_name, &st, off);
+       return DIR_FILLER(filler, buf, dentry->d_name, &st, off);
+}
+static inline int dir_fillerat(fuse_fill_dir_t filler, DIR *dp,
+                              const char *name, void *buf, off_t off)
+{
+       struct stat st;
+       int ret;
+
+       ret = fstatat(dirfd(dp), name, &st, AT_SYMLINK_NOFOLLOW);
+       if (ret)
+               return DIR_FILLER(filler, buf, name, NULL, off);
+
+       return DIR_FILLER(filler, buf, name, &st, off);
 }
-#endif
 
 #endif /* __LXCFS_FUSE_COMPAT_H */
index 8220c2b1229fe8300ab663e94f8b7089aa6701db..a1e2e8ead225817f182285c75b3117fe2eeb850f 100644 (file)
@@ -269,7 +269,7 @@ static int filler_sys_devices_system_cpu(const char *path, void *buf,
 {
        __do_free __u32 *bitarr = NULL;
        __do_free char *cg = NULL, *cpuset = NULL;
-       __do_closedir DIR *dir = NULL;
+       __do_closedir DIR *dirp = NULL;
        struct fuse_context *fc = fuse_get_context();
        __u32 last_set_bit = 0;
        int ret;
@@ -293,6 +293,10 @@ static int filler_sys_devices_system_cpu(const char *path, void *buf,
        if (ret)
                return ret;
 
+       dirp = opendir(path);
+       if (!dirp)
+               return -ENOENT;
+
        for (__u32 bit = 0; bit <= last_set_bit; bit++) {
                char cpu[100];
 
@@ -303,15 +307,11 @@ static int filler_sys_devices_system_cpu(const char *path, void *buf,
                if (ret < 0 || (size_t)ret >= sizeof(cpu))
                        continue;
 
-               if (dir_filler(filler, buf, cpu, 0) != 0)
+               if (dir_fillerat(filler, dirp, cpu, buf, 0) != 0)
                        return -ENOENT;
        }
 
-       dir = opendir(path);
-       if (!dir)
-               return -ENOENT;
-
-       while ((dirent = readdir(dir))) {
+       while ((dirent = readdir(dirp))) {
                char *entry = dirent->d_name;
 
                if (strlen(entry) > 3) {
@@ -322,7 +322,7 @@ static int filler_sys_devices_system_cpu(const char *path, void *buf,
                                continue;
                }
 
-               if (dirent_fillerat(filler, dir, dirent, buf, 0) != 0)
+               if (dirent_fillerat(filler, dirp, dirent, buf, 0) != 0)
                        return -ENOENT;
        }