From b59835f8b6c81befee23c5c3c0fafb63e98fbc0c Mon Sep 17 00:00:00 2001 From: James Simmons Date: Wed, 10 Mar 2021 22:20:58 -0500 Subject: [PATCH] LU-13903 utils: have liblustreapi support Linux client Handle two difference between the Linux client and the OpenSFS branch. The Linux client doesn't support the LL_IOC_REMOVE_ENTRY since its considered a security risk by the VFS maintainers. The other difference is that struct getinfo_fid2path doesn't name its union structure which is typical in the Linux kernel. Test-Parameters: trivial Change-Id: Ieb9ea749e8728f33621fd6ec28f78892466ec7a4 Signed-off-by: James Simmons Reviewed-on: https://review.whamcloud.com/39207 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Wang Shilong Reviewed-by: Jian Yu Reviewed-by: Olaf Faaland-LLNL Reviewed-by: Oleg Drokin --- config/lustre-build.m4 | 8 ++++++-- lustre/autoconf/lustre-core.m4 | 39 +++++++++++++++++++++++++++++++++++++++ lustre/utils/liblustreapi_fid.c | 11 ++++++++++- lustre/utils/liblustreapi_util.c | 4 ++++ 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/config/lustre-build.m4 b/config/lustre-build.m4 index f2007de..9169a80 100644 --- a/config/lustre-build.m4 +++ b/config/lustre-build.m4 @@ -344,8 +344,10 @@ AS_IF([test $target_cpu = powerpc64], [ CC="$CC -m64" ]) -# UAPI headers, libcfs/include for util headers, lustre/include for liblustreapi and friends -CPPFLAGS="-I$PWD/libcfs/include -I$PWD/lnet/utils/ -I$PWD/lnet/include/uapi -I$PWD/lustre/include -I$PWD/lustre/include/uapi $CPPFLAGS" +# libcfs/include for util headers, lustre/include for liblustreapi and friends +# UAPI headers from OpenSFS are included if modules support is enabled, otherwise +# it will use the native kernel implementation. +CPPFLAGS="-I$PWD/libcfs/include -I$PWD/lnet/utils/ -I$PWD/lustre/include $CPPFLAGS" CCASFLAGS="-Wall -fPIC -D_GNU_SOURCE" AC_SUBST(CCASFLAGS) @@ -667,6 +669,8 @@ AS_IF([test "x$enable_utils" = xyes], [ LC_GLIBC_SUPPORT_COPY_FILE_RANGE LC_OPENSSL_SSK LC_OPENSSL_GETSEPOL + LC_FID2PATH_ANON_UNION + LC_IOC_REMOVE_ENTRY ]) AS_IF([test "x$enable_tests" = xyes], [ LC_HAVE_LIBAIO diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index b36260f..0c6643b 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -66,6 +66,45 @@ AC_CHECK_FUNCS([copy_file_range], ]) # LC_GLIBC_SUPPORT_COPY_FILE_RANGE # +# LC_FID2PATH_UNION +# +AC_DEFUN([LC_FID2PATH_ANON_UNION], [ +AC_MSG_CHECKING([if 'struct getinfo_fid2path' has anony•mous union]) +AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #include + + int main(void) { + struct getinfo_fid2path gf; + struct lu_fid root_fid; + + *gf.gf_root_fid = root_fid; + return 0; + } +])],[ + AC_DEFINE(HAVE_FID2PATH_ANON_UNIONS, 1, [union is unnamed]) + AC_MSG_RESULT("yes") +]) +]) # LC_FID2PATH_ANON_UNION + +# +# LC_IOC_REMOVE_ENTRY +# +AC_DEFUN([LC_IOC_REMOVE_ENTRY], [ +AC_MSG_CHECKING([if ioctl IOC_REMOVE_ENTRY' is supported]) +AC_COMPILE_IFELSE([AC_LANG_SOURCE([ + #include + #include + + int main(void) { + return ioctl(0, LL_IOC_REMOVE_ENTRY, NULL); + } +])],[ + AC_DEFINE(HAVE_IOC_REMOVE_ENTRY, 1, + [IOC_REMOVE_ENTRY ioctl exists]) +]) +]) # LC_IOC_REMOVE_ENTRY + +# # LC_STACK_SIZE # # Ensure the stack size is at least 8k in Lustre server (all kernels) diff --git a/lustre/utils/liblustreapi_fid.c b/lustre/utils/liblustreapi_fid.c index 578c6e6..131f3cb 100644 --- a/lustre/utils/liblustreapi_fid.c +++ b/lustre/utils/liblustreapi_fid.c @@ -160,6 +160,15 @@ out: return rc; } +static inline char *get_gf_path(struct getinfo_fid2path *gf) +{ +#ifndef HAVE_FID2PATH_ANON_UNIONS + return gf->gf_u.gf_path; +#else + return gf->gf_path; +#endif +} + int llapi_fid2path_at(int mnt_fd, const struct lu_fid *fid, char *path_buf, int path_buf_size, long long *recno, int *linkno) @@ -188,7 +197,7 @@ int llapi_fid2path_at(int mnt_fd, const struct lu_fid *fid, goto out; } - rc = copy_strip_dne_path(gf->gf_u.gf_path, path_buf, path_buf_size); + rc = copy_strip_dne_path(get_gf_path(gf), path_buf, path_buf_size); if (recno != NULL) *recno = gf->gf_recno; diff --git a/lustre/utils/liblustreapi_util.c b/lustre/utils/liblustreapi_util.c index 60ded02..ad69d93 100644 --- a/lustre/utils/liblustreapi_util.c +++ b/lustre/utils/liblustreapi_util.c @@ -315,6 +315,7 @@ retry_open: int llapi_direntry_remove(char *dname) { +#ifdef HAVE_IOC_REMOVE_ENTRY char *dirpath = NULL; char *namepath = NULL; char *dir; @@ -349,6 +350,9 @@ out: if (fd != -1) close(fd); return rc; +#else + return -ENOTSUP; +#endif } int llapi_unlink_foreign(char *name) -- 1.8.3.1