Whamcloud - gitweb
LU-12043 llite: switch to use ll_fsname directly
[fs/lustre-release.git] / lustre / llite / xattr.c
index 34e46cd..3958dd6 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2016, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #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;
 }
 
@@ -94,7 +102,10 @@ static int ll_xattr_set_common(const struct xattr_handler *handler,
        int rc;
        ENTRY;
 
-       if (flags == XATTR_REPLACE) {
+       /* When setxattr() is called with a size of 0 the value is
+        * unconditionally replaced by "". When removexattr() is
+        * called we get a NULL value and XATTR_REPLACE for flags. */
+       if (!value && flags == XATTR_REPLACE) {
                ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_REMOVEXATTR, 1);
                valid = OBD_MD_FLXATTRRM;
        } else {
@@ -140,12 +151,12 @@ 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);
 
        rc = md_setxattr(sbi->ll_md_exp, ll_inode2fid(inode), valid, fullname,
-                        pv, size, 0, flags, ll_i2suppgid(inode), &req);
+                        pv, size, flags, ll_i2suppgid(inode), &req);
        kfree(fullname);
        if (rc) {
                if (rc == -EOPNOTSUPP && handler->flags == XATTR_USER_T) {
@@ -332,7 +343,6 @@ int ll_xattr_list(struct inode *inode, const char *name, int type, void *buffer,
        struct ll_inode_info *lli = ll_i2info(inode);
         struct ll_sb_info *sbi = ll_i2sbi(inode);
         struct ptlrpc_request *req = NULL;
-        struct mdt_body *body;
         void *xdata;
        int rc;
        ENTRY;
@@ -359,35 +369,25 @@ int ll_xattr_list(struct inode *inode, const char *name, int type, void *buffer,
                }
        } else {
 getxattr_nocache:
-               rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode),
-                                valid, name, NULL, 0, size, 0, &req);
+               rc = md_getxattr(sbi->ll_md_exp, ll_inode2fid(inode), valid,
+                                name, size, &req);
                if (rc < 0)
                        GOTO(out_xattr, rc);
 
-               body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
-               LASSERT(body);
-
                /* only detect the xattr size */
                if (size == 0)
-                       GOTO(out, rc = body->mbo_eadatasize);
+                       GOTO(out, rc);
 
-               if (size < body->mbo_eadatasize) {
-                       CERROR("server bug: replied size %u > %u\n",
-                               body->mbo_eadatasize, (int)size);
+               if (size < rc)
                        GOTO(out, rc = -ERANGE);
-               }
-
-               if (body->mbo_eadatasize == 0)
-                       GOTO(out, rc = -ENODATA);
 
                /* do not need swab xattr data */
                xdata = req_capsule_server_sized_get(&req->rq_pill, &RMF_EADATA,
-                                                       body->mbo_eadatasize);
+                                                    rc);
                if (!xdata)
-                       GOTO(out, rc = -EFAULT);
+                       GOTO(out, rc = -EPROTO);
 
-               memcpy(buffer, xdata, body->mbo_eadatasize);
-               rc = body->mbo_eadatasize;
+               memcpy(buffer, xdata, rc);
        }
 
        EXIT;
@@ -395,13 +395,13 @@ getxattr_nocache:
 out_xattr:
        if (rc == -EOPNOTSUPP && type == XATTR_USER_T) {
                LCONSOLE_INFO("%s: disabling user_xattr feature because "
-                               "it is not supported on the server: rc = %d\n",
-                               ll_get_fsname(inode->i_sb, NULL, 0), rc);
+                             "it is not supported on the server: rc = %d\n",
+                             sbi->ll_fsname, rc);
                sbi->ll_flags &= ~LL_SBI_USER_XATTR;
        }
 out:
         ptlrpc_req_finished(req);
-        return rc;
+       RETURN(rc);
 }
 
 static int ll_xattr_get_common(const struct xattr_handler *handler,
@@ -413,6 +413,8 @@ static int ll_xattr_get_common(const struct xattr_handler *handler,
        char *fullname;
        int rc;
 
+       ENTRY;
+
        ll_stats_ops_tally(ll_i2sbi(inode), LPROC_LL_GETXATTR, 1);
 
        rc = xattr_type_filter(sbi, handler);
@@ -448,14 +450,14 @@ 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);
 
        rc = ll_xattr_list(inode, fullname, handler->flags, buffer, size,
                           OBD_MD_FLXATTR);
        kfree(fullname);
-       return rc;
+       RETURN(rc);
 }
 
 static ssize_t ll_getxattr_lov(struct inode *inode, void *buf, size_t buf_size)
@@ -528,7 +530,7 @@ out_req:
                if (req)
                        ptlrpc_req_finished(req);
 
-               return rc;
+               RETURN(rc);
        } else {
                RETURN(-ENODATA);
        }
@@ -759,7 +761,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,
@@ -774,7 +780,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,