Whamcloud - gitweb
LU-10785 llite: use xattr_handler name for ACLs 95/31595/5
authorJohn L. Hammond <john.hammond@intel.com>
Thu, 8 Mar 2018 21:27:28 +0000 (15:27 -0600)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 9 Apr 2018 19:50:05 +0000 (19:50 +0000)
If struct xattr_handler has a name member then use it (rather than
prefix) for the ACL xattrs. This avoids a bug where ACL operations
failed for some kernels.

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: I28f6c5dbe3cdc4155e93d388d2c413092e02c082
Reviewed-on: https://review.whamcloud.com/31595
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/autoconf/lustre-core.m4
lustre/llite/xattr.c

index f104079..6ef83ff 100644 (file)
@@ -2327,6 +2327,26 @@ key_payload_data_array, [
 ]) #LC_HAVE_KEY_PAYLOAD_DATA_ARRAY
 
 #
+# LC_HAVE_XATTR_HANDLER_NAME
+#
+# Kernel version 4.4 commit 98e9cb5711c68223f0e4d5201b9a6add255ec550
+# add a name member to struct xattr_handler
+#
+AC_DEFUN([LC_HAVE_XATTR_HANDLER_NAME], [
+tmp_flags="$EXTRA_KCFLAGS"
+EXTRA_KCFLAGS="-Werror"
+LB_CHECK_COMPILE([if 'struct xattr_handler' has a name member],
+xattr_handler_name, [
+       #include <linux/xattr.h>
+],[
+       ((struct xattr_handler *)NULL)->name = NULL;
+],[
+       AC_DEFINE(HAVE_XATTR_HANDLER_NAME, 1, [xattr_handler has a name member])
+])
+EXTRA_KCFLAGS="$tmp_flags"
+]) # LC_HAVE_XATTR_HANDLER_NAME
+
+#
 # LC_HAVE_FILE_DENTRY
 #
 # 4.5 adds wrapper file_dentry
@@ -2913,6 +2933,7 @@ AC_DEFUN([LC_PROG_LINUX], [
        # 4.4
        LC_HAVE_LOCKS_LOCK_FILE_WAIT
        LC_HAVE_KEY_PAYLOAD_DATA_ARRAY
+       LC_HAVE_XATTR_HANDLER_NAME
        LC_HAVE_BI_CNT
        LC_HAVE_BI_RW
        LC_HAVE_SUBMIT_BIO_2ARGS
index b2c0407..ac1dd91 100644 (file)
 
 #include "llite_internal.h"
 
+#ifndef HAVE_XATTR_HANDLER_NAME
+static inline const char *xattr_prefix(const struct xattr_handler *handler)
+{
+       return handler->prefix;
+}
+#endif
+
 const struct xattr_handler *get_xattr_type(const char *name)
 {
-       int i = 0;
+       int i;
 
-       while (ll_xattr_handlers[i]) {
-               size_t len = strlen(ll_xattr_handlers[i]->prefix);
+       for (i = 0; ll_xattr_handlers[i]; i++) {
+               const char *prefix = xattr_prefix(ll_xattr_handlers[i]);
+               size_t prefix_len = strlen(prefix);
 
-               if (!strncmp(ll_xattr_handlers[i]->prefix, name, len))
+               if (!strncmp(prefix, name, prefix_len))
                        return ll_xattr_handlers[i];
-               i++;
        }
+
        return NULL;
 }
 
@@ -143,7 +151,7 @@ static int ll_xattr_set_common(const struct xattr_handler *handler,
                        RETURN(-EPERM);
        }
 
-       fullname = kasprintf(GFP_KERNEL, "%s%s", handler->prefix, name);
+       fullname = kasprintf(GFP_KERNEL, "%s%s", xattr_prefix(handler), name);
        if (!fullname)
                RETURN(-ENOMEM);
 
@@ -453,7 +461,7 @@ static int ll_xattr_get_common(const struct xattr_handler *handler,
                RETURN(-ENODATA);
 #endif
 
-       fullname = kasprintf(GFP_KERNEL, "%s%s", handler->prefix, name);
+       fullname = kasprintf(GFP_KERNEL, "%s%s", xattr_prefix(handler), name);
        if (!fullname)
                RETURN(-ENOMEM);
 
@@ -764,7 +772,11 @@ static const struct xattr_handler ll_security_xattr_handler = {
 };
 
 static const struct xattr_handler ll_acl_access_xattr_handler = {
+#ifdef HAVE_XATTR_HANDLER_NAME
+       .name = XATTR_NAME_POSIX_ACL_ACCESS,
+#else
        .prefix = XATTR_NAME_POSIX_ACL_ACCESS,
+#endif
        .flags = XATTR_ACL_ACCESS_T,
 #if defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
        .get = ll_xattr_get_common_4_3,
@@ -779,7 +791,11 @@ static const struct xattr_handler ll_acl_access_xattr_handler = {
 };
 
 static const struct xattr_handler ll_acl_default_xattr_handler = {
+#ifdef HAVE_XATTR_HANDLER_NAME
+       .name = XATTR_NAME_POSIX_ACL_DEFAULT,
+#else
        .prefix = XATTR_NAME_POSIX_ACL_DEFAULT,
+#endif
        .flags = XATTR_ACL_DEFAULT_T,
 #if defined(HAVE_XATTR_HANDLER_SIMPLIFIED)
        .get = ll_xattr_get_common_4_3,