Whamcloud - gitweb
LU-12043 llite: switch to use ll_fsname directly
[fs/lustre-release.git] / lustre / llite / xattr.c
index 5581ee2..3958dd6 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;
 }
 
@@ -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,8 +395,8 @@ 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:
@@ -450,7 +450,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);
 
@@ -761,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,
@@ -776,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,