Whamcloud - gitweb
LU-13903 utils: have liblustreapi support Linux client 07/39207/4
authorJames Simmons <jsimmons@infradead.org>
Thu, 11 Mar 2021 03:20:58 +0000 (22:20 -0500)
committerOleg Drokin <green@whamcloud.com>
Sat, 10 Apr 2021 17:39:49 +0000 (17:39 +0000)
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 <jsimmons@infradead.org>
Reviewed-on: https://review.whamcloud.com/39207
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Wang Shilong <wshilong@whamcloud.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Reviewed-by: Olaf Faaland-LLNL <faaland1@llnl.gov>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
config/lustre-build.m4
lustre/autoconf/lustre-core.m4
lustre/utils/liblustreapi_fid.c
lustre/utils/liblustreapi_util.c

index f2007de..9169a80 100644 (file)
@@ -344,8 +344,10 @@ AS_IF([test $target_cpu = powerpc64], [
        CC="$CC -m64"
 ])
 
        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)
 
 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_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
 ])
 AS_IF([test "x$enable_tests" = xyes], [
        LC_HAVE_LIBAIO
index b36260f..0c6643b 100644 (file)
@@ -66,6 +66,45 @@ AC_CHECK_FUNCS([copy_file_range],
 ]) # LC_GLIBC_SUPPORT_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 <linux/lustre/lustre_idl.h>
+
+       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 <sys/ioctl.h>
+       #include <linux/lustre/lustre_ioctl.h>
+
+       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)
 # LC_STACK_SIZE
 #
 # Ensure the stack size is at least 8k in Lustre server (all kernels)
index 578c6e6..131f3cb 100644 (file)
@@ -160,6 +160,15 @@ out:
        return rc;
 }
 
        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)
 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;
        }
 
                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;
 
        if (recno != NULL)
                *recno = gf->gf_recno;
index 60ded02..ad69d93 100644 (file)
@@ -315,6 +315,7 @@ retry_open:
 
 int llapi_direntry_remove(char *dname)
 {
 
 int llapi_direntry_remove(char *dname)
 {
+#ifdef HAVE_IOC_REMOVE_ENTRY
        char *dirpath = NULL;
        char *namepath = NULL;
        char *dir;
        char *dirpath = NULL;
        char *namepath = NULL;
        char *dir;
@@ -349,6 +350,9 @@ out:
        if (fd != -1)
                close(fd);
        return rc;
        if (fd != -1)
                close(fd);
        return rc;
+#else
+       return -ENOTSUP;
+#endif
 }
 
 int llapi_unlink_foreign(char *name)
 }
 
 int llapi_unlink_foreign(char *name)