Skip to content

Commit

Permalink
meson: handle fuse versions with buggy dt_type handling
Browse files Browse the repository at this point in the history
Link: libfuse/libfuse#591
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
  • Loading branch information
Christian Brauner (Microsoft) committed Mar 13, 2022
1 parent 6dc6057 commit 28b7746
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,17 @@ libfuse = dependency('fuse3', required: false)
if libfuse.found()
conf.set10('HAVE_FUSE3', true)
conf.set('FUSE_USE_VERSION', 35)
if libfuse.version().version_compare('>=3.10.3')
conf.set10('HAVE_FUSE_RETURNS_DT_TYPE', true)
else
conf.set10('HAVE_FUSE_RETURNS_DT_TYPE', false)
endif
else
libfuse = dependency('fuse', version: '>= 2.6')
if libfuse.found()
conf.set10('HAVE_FUSE', true)
conf.set('FUSE_USE_VERSION', 26)
conf.set10('HAVE_FUSE_RETURNS_DT_TYPE', true)
endif
endif

Expand Down
2 changes: 2 additions & 0 deletions src/bindings.c
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,9 @@ static void __attribute__((destructor)) lxcfs_exit(void)
void *lxcfs_fuse_init(struct fuse_conn_info *conn, void *data)
{
struct fuse_context *fc = fuse_get_context();
#if HAVE_FUSE_RETURNS_DT_TYPE
can_use_sys_cpu = true;
#endif
has_versioned_opts = true;
return fc->private_data;
}
20 changes: 16 additions & 4 deletions src/lxcfs_fuse_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
#include "memory_utils.h"

#ifdef HAVE_FUSE3
#define DIR_FILLER(F,B,N,S,O) F(B,N,S,O,FUSE_FILL_DIR_PLUS)
#if HAVE_FUSE_RETURNS_DT_TYPE
#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,0)
#endif
#else
#define DIR_FILLER(F,B,N,S,O) F(B,N,S,O)
#endif
Expand All @@ -26,19 +30,22 @@ static inline int dir_filler(fuse_fill_dir_t filler, void *buf,
static inline int dirent_filler(fuse_fill_dir_t filler, const char *path,
const char *name, void *buf, off_t off)
{
#if HAVE_FUSE_RETURNS_DT_TYPE
__do_closedir DIR *dirp = NULL;
struct stat st;

dirp = opendir(path);
if (dirp && !fstatat(dirfd(dirp), name, &st, AT_SYMLINK_NOFOLLOW))
return DIR_FILLER(filler, buf, name, &st, off);
#endif

return DIR_FILLER(filler, buf, name, NULL, off);
}

static inline int dirent_fillerat(fuse_fill_dir_t filler, DIR *dp,
struct dirent *dentry, void *buf, off_t off)
{
#if HAVE_FUSE_RETURNS_DT_TYPE
struct stat st;
int ret;

Expand All @@ -51,18 +58,23 @@ static inline int dirent_fillerat(fuse_fill_dir_t filler, DIR *dp,
}

return DIR_FILLER(filler, buf, dentry->d_name, &st, off);
#else
return DIR_FILLER(filler, buf, dentry->d_name, NULL, off);
#endif
}
static inline int dir_fillerat(fuse_fill_dir_t filler, DIR *dp,
const char *name, void *buf, off_t off)
{
#if HAVE_FUSE_RETURNS_DT_TYPE
struct stat st;
int ret;

ret = fstatat(dirfd(dp), name, &st, AT_SYMLINK_NOFOLLOW);
if (ret)
return DIR_FILLER(filler, buf, name, NULL, off);
if (!ret)
return DIR_FILLER(filler, buf, name, &st, off);
#endif

return DIR_FILLER(filler, buf, name, &st, off);
return DIR_FILLER(filler, buf, name, NULL, off);
}

#endif /* __LXCFS_FUSE_COMPAT_H */

0 comments on commit 28b7746

Please sign in to comment.