Whamcloud - gitweb
LU-5707 lfsck: store namespace LFSCK statistics info in new EA
[fs/lustre-release.git] / lustre / mdt / mdt_xattr.c
index 83ecc74..8364fab 100644 (file)
@@ -1,46 +1,54 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/*
+ * GPL HEADER START
  *
- *  linux/mdt/mdt_xattr.c
- *  Lustre Metadata Target (mdt) extended attributes management.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *  Copyright (C) 2002-2006 Cluster File Systems, Inc.
- *   Author: Peter Braam <braam@clusterfs.com>
- *   Author: Andreas Dilger <adilger@clusterfs.com>
- *   Author: Phil Schwan <phil@clusterfs.com>
- *   Author: Huang Hua <huanghua@clusterfs.com>
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   This file is part of the Lustre file system, http://www.lustre.org
- *   Lustre is a trademark of Cluster File Systems, Inc.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   You may have signed or agreed to another license before downloading
- *   this software.  If so, you are bound by the terms and conditions
- *   of that agreement, and the following does not apply to you.  See the
- *   LICENSE file included with this distribution for more information.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  *
- *   If you did not agree to a different license, then this copy of Lustre
- *   is open source software; you can redistribute it and/or modify it
- *   under the terms of version 2 of the GNU General Public License as
- *   published by the Free Software Foundation.
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
  *
- *   In either case, Lustre is distributed in the hope that it will be
- *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   license text for more details.
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2013, Intel Corporation.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/mdt/mdt_xattr.c
+ *
+ * Lustre Metadata Target (mdt) extended attributes management.
+ *
+ * Author: Peter Braam <braam@clusterfs.com>
+ * Author: Andreas Dilger <adilger@clusterfs.com>
+ * Author: Phil Schwan <phil@clusterfs.com>
+ * Author: Huang Hua <huanghua@clusterfs.com>
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
 #define DEBUG_SUBSYSTEM S_MDS
 
-/* prerequisite for linux/xattr.h */
-#include <linux/types.h>
-/* prerequisite for linux/xattr.h */
-#include <linux/fs.h>
-/* XATTR_{REPLACE,CREATE} */
 #include <linux/xattr.h>
-
+#include <obd_class.h>
+#include <lustre_nodemap.h>
+#include <lustre_acl.h>
 #include "mdt_internal.h"
 
 
@@ -50,52 +58,56 @@ static int mdt_getxattr_pack_reply(struct mdt_thread_info * info)
         struct req_capsule     *pill = info->mti_pill ;
         struct ptlrpc_request  *req = mdt_info_req(info);
         char                   *xattr_name;
-        __u64                   valid = info->mti_body->valid;
+        __u64                   valid;
         static const char       user_string[] = "user.";
         int                     size, rc;
         ENTRY;
-        
+
         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETXATTR_PACK))
                 RETURN(-ENOMEM);
 
+       valid = info->mti_body->mbo_valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLS);
+
         /* Determine how many bytes we need */
-        if ((valid & OBD_MD_FLXATTR) == OBD_MD_FLXATTR) {
+        if (valid == OBD_MD_FLXATTR) {
                 xattr_name = req_capsule_client_get(pill, &RMF_NAME);
                 if (!xattr_name)
                         RETURN(-EFAULT);
 
-                if (!(req->rq_export->exp_connect_flags & OBD_CONNECT_XATTR) &&
-                    !strncmp(xattr_name, user_string, sizeof(user_string) - 1))
-                        RETURN(-EOPNOTSUPP);
-                
+               if (!(exp_connect_flags(req->rq_export) & OBD_CONNECT_XATTR) &&
+                   !strncmp(xattr_name, user_string, sizeof(user_string) - 1))
+                       RETURN(-EOPNOTSUPP);
+
                 size = mo_xattr_get(info->mti_env,
                                     mdt_object_child(info->mti_object),
                                     &LU_BUF_NULL, xattr_name);
-        } else if ((valid & OBD_MD_FLXATTRLS) == OBD_MD_FLXATTRLS) {
+        } else if (valid == OBD_MD_FLXATTRLS) {
                 size = mo_xattr_list(info->mti_env,
                                      mdt_object_child(info->mti_object),
                                      &LU_BUF_NULL);
-        } else {
-                CDEBUG(D_INFO, "Valid bits: "LPX64"\n", info->mti_body->valid);
+       } else if (valid == OBD_MD_FLXATTRALL) {
+               /* N.B. eadatasize = 0 is not valid for FLXATTRALL */
+               /* We could calculate accurate sizes, but this would
+                * introduce a lot of overhead, let's do it later... */
+               size = info->mti_body->mbo_eadatasize;
+               req_capsule_set_size(pill, &RMF_EAVALS, RCL_SERVER, size);
+               req_capsule_set_size(pill, &RMF_EAVALS_LENS, RCL_SERVER, size);
+       } else {
+               CDEBUG(D_INFO, "Valid bits: "LPX64"\n",
+                      info->mti_body->mbo_valid);
                 RETURN(-EINVAL);
         }
 
-        if (size < 0) {
-                if (size == -ENODATA)
-                        size = 0;
-                else if (size != -EOPNOTSUPP) {
-                        CDEBUG(D_INFO, "Error geting EA size: %d\n", size);
-                        RETURN(size);
-                }
-        }
-
-        if (info->mti_body->eadatasize != 0 &&
-            info->mti_body->eadatasize < size)
-                RETURN(-ERANGE);
+       if (size == -ENODATA) {
+               size = 0;
+       } else if (size < 0) {
+               if (size != -EOPNOTSUPP)
+                       CERROR("Error geting EA size: %d\n", size);
+               RETURN(size);
+       }
 
         req_capsule_set_size(pill, &RMF_EADATA, RCL_SERVER,
-                             min_t(int, size, info->mti_body->eadatasize));
-
+                            info->mti_body->mbo_eadatasize == 0 ? 0 : size);
         rc = req_capsule_server_pack(pill);
         if (rc) {
                 LASSERT(rc < 0);
@@ -105,39 +117,142 @@ static int mdt_getxattr_pack_reply(struct mdt_thread_info * info)
         RETURN(size);
 }
 
+static int
+mdt_getxattr_one(struct mdt_thread_info *info,
+               char *xattr_name, struct md_object *next,
+               struct lu_buf *buf, struct mdt_export_data *med,
+               struct lu_ucred *uc)
+{
+       __u32 remote = exp_connect_rmtclient(info->mti_exp);
+       int flags = CFS_IC_NOTHING, rc;
+
+       ENTRY;
+
+       CDEBUG(D_INODE, "getxattr %s\n", xattr_name);
+
+       rc = mo_xattr_get(info->mti_env, next, buf, xattr_name);
+       if (rc < 0)
+               GOTO(out, rc);
+
+       if (info->mti_body->mbo_valid &
+           (OBD_MD_FLRMTLSETFACL | OBD_MD_FLRMTLGETFACL))
+               flags = CFS_IC_ALL;
+       else if (info->mti_body->mbo_valid & OBD_MD_FLRMTRGETFACL)
+               flags = CFS_IC_MAPPED;
+
+       if (rc > 0 && flags != CFS_IC_NOTHING) {
+               int rc1;
+
+               if (unlikely(!remote))
+                       GOTO(out, rc = -EINVAL);
+
+               rc1 = lustre_posix_acl_xattr_id2client(uc,
+                               med->med_idmap,
+                               (posix_acl_xattr_header *)(buf->lb_buf),
+                               rc, flags);
+               if (unlikely(rc1 < 0))
+                       rc = rc1;
+       }
+
+out:
+       return rc;
+}
+
+static int mdt_getxattr_all(struct mdt_thread_info *info,
+                           struct mdt_body *reqbody, struct mdt_body *repbody,
+                           struct lu_buf *buf, struct md_object *next)
+{
+       const struct lu_env *env = info->mti_env;
+       struct ptlrpc_request *req = mdt_info_req(info);
+       struct mdt_export_data *med = mdt_req2med(req);
+       struct lu_ucred        *uc  = mdt_ucred(info);
+       char *v, *b, *eadatahead, *eadatatail;
+       __u32 *sizes;
+       int eadatasize, eavallen = 0, eavallens = 0, rc;
+
+       ENTRY;
+
+       /*
+        * The format of the pill is the following:
+        * EADATA:      attr1\0attr2\0...attrn\0
+        * EAVALS:      val1val2...valn
+        * EAVALS_LENS: 4,4,...4
+        */
+
+       eadatahead = buf->lb_buf;
+
+       /* Fill out EADATA first */
+       eadatasize = mo_xattr_list(env, next, buf);
+       if (eadatasize < 0)
+               GOTO(out, rc = eadatasize);
+
+       eadatatail = eadatahead + eadatasize;
+
+       v = req_capsule_server_get(info->mti_pill, &RMF_EAVALS);
+       sizes = req_capsule_server_get(info->mti_pill, &RMF_EAVALS_LENS);
+
+       /* Fill out EAVALS and EAVALS_LENS */
+       for (b = eadatahead; b < eadatatail; b += strlen(b) + 1, v += rc) {
+               buf->lb_buf = v;
+               buf->lb_len = reqbody->mbo_eadatasize - eavallen;
+               rc = mdt_getxattr_one(info, b, next, buf, med, uc);
+               if (rc < 0)
+                       GOTO(out, rc);
+
+               sizes[eavallens] = rc;
+               eavallens++;
+               eavallen += rc;
+       }
+
+       repbody->mbo_aclsize = eavallen;
+       repbody->mbo_max_mdsize = eavallens;
+
+       req_capsule_shrink(info->mti_pill, &RMF_EAVALS, eavallen, RCL_SERVER);
+       req_capsule_shrink(info->mti_pill, &RMF_EAVALS_LENS,
+                          eavallens * sizeof(__u32), RCL_SERVER);
+       req_capsule_shrink(info->mti_pill, &RMF_EADATA, eadatasize, RCL_SERVER);
+
+       GOTO(out, rc = eadatasize);
+out:
+       return rc;
+}
+
 int mdt_getxattr(struct mdt_thread_info *info)
 {
-        struct ptlrpc_request  *req = mdt_info_req(info);
-        struct mdt_export_data *med = mdt_req2med(req);
-        struct md_ucred        *uc  = mdt_ucred(info);
+       struct ptlrpc_request  *req = mdt_info_req(info);
+       struct mdt_export_data *med = mdt_req2med(req);
+       struct lu_ucred        *uc  = lu_ucred(info->mti_env);
         struct mdt_body        *reqbody;
         struct mdt_body        *repbody = NULL;
         struct md_object       *next;
         struct lu_buf          *buf;
+        __u32                   remote = exp_connect_rmtclient(info->mti_exp);
+        __u32                   perm;
         int                     easize, rc;
+       obd_valid               valid;
         ENTRY;
 
         LASSERT(info->mti_object != NULL);
-        LASSERT(lu_object_assert_exists(&info->mti_object->mot_obj.mo_lu));
+       LASSERT(lu_object_assert_exists(&info->mti_object->mot_obj));
 
-        CDEBUG(D_INODE, "getxattr "DFID"\n", PFID(&info->mti_body->fid1));
+       CDEBUG(D_INODE, "getxattr "DFID"\n", PFID(&info->mti_body->mbo_fid1));
 
         reqbody = req_capsule_client_get(info->mti_pill, &RMF_MDT_BODY);
         if (reqbody == NULL)
                 RETURN(err_serious(-EFAULT));
 
-        rc = mdt_init_ucred(info, reqbody);
+       rc = mdt_init_ucred(info, reqbody);
         if (rc)
                 RETURN(err_serious(rc));
 
         next = mdt_object_child(info->mti_object);
 
-        if (info->mti_body->valid & OBD_MD_FLRMTRGETFACL) {
-                __u32 perm = mdt_identity_get_perm(uc->mu_identity,
-                                                   med->med_rmtclient,
-                                                   req->rq_peer.nid);
+       if (info->mti_body->mbo_valid & OBD_MD_FLRMTRGETFACL) {
+                if (unlikely(!remote))
+                        GOTO(out, rc = err_serious(-EINVAL));
 
-                LASSERT(med->med_rmtclient);
+               perm = mdt_identity_get_perm(uc->uc_identity, remote,
+                                            req->rq_peer.nid);
                 if (!(perm & CFS_RMTACL_PERM))
                         GOTO(out, rc = err_serious(-EPERM));
 
@@ -155,59 +270,40 @@ int mdt_getxattr(struct mdt_thread_info *info)
         LASSERT(repbody != NULL);
 
         /* No need further getxattr. */
-        if (easize == 0 || reqbody->eadatasize == 0)
-                GOTO(out, rc = easize);
-
-        buf = &info->mti_buf;
-        buf->lb_buf = req_capsule_server_get(info->mti_pill, &RMF_EADATA);
-        buf->lb_len = easize;
-
-        if (info->mti_body->valid & OBD_MD_FLXATTR) {
-                int flags = CFS_IC_NOTHING;
-                char *xattr_name = req_capsule_client_get(info->mti_pill,
-                                                          &RMF_NAME);
-                CDEBUG(D_INODE, "getxattr %s\n", xattr_name);
-
-                rc = mo_xattr_get(info->mti_env, next, buf, xattr_name);
-                if (rc < 0) {
-                        CERROR("getxattr failed: %d\n", rc);
-                        GOTO(out, rc);
-                }
-
-                if (info->mti_body->valid &
-                    (OBD_MD_FLRMTLSETFACL | OBD_MD_FLRMTLGETFACL))
-                        flags = CFS_IC_ALL;
-                else if (info->mti_body->valid & OBD_MD_FLRMTRGETFACL)
-                        flags = CFS_IC_MAPPED;
-
-                if (rc > 0 && flags != CFS_IC_NOTHING) {
-                        int rc1;
-
-                        LASSERT(med->med_rmtclient);
-                        rc1 = lustre_posix_acl_xattr_id2client(uc,
-                                        med->med_idmap,
-                                        (posix_acl_xattr_header *)(buf->lb_buf),
-                                        rc, flags);
-                        if (unlikely(rc1 < 0))
-                                rc = rc1;
-                }
-        } else if (info->mti_body->valid & OBD_MD_FLXATTRLS) {
-                CDEBUG(D_INODE, "listxattr\n");
-
-                rc = mo_xattr_list(info->mti_env, next, buf);
-                if (rc < 0)
-                        CDEBUG(D_INFO, "listxattr failed: %d\n", rc);
-        } else
-                LBUG();
-
-        EXIT;
+       if (easize == 0 || reqbody->mbo_eadatasize == 0)
+               GOTO(out, rc = easize);
+
+       buf = &info->mti_buf;
+       buf->lb_buf = req_capsule_server_get(info->mti_pill, &RMF_EADATA);
+       buf->lb_len = easize;
+
+       valid = info->mti_body->mbo_valid & (OBD_MD_FLXATTR | OBD_MD_FLXATTRLS);
+
+       if (valid == OBD_MD_FLXATTR) {
+               char *xattr_name = req_capsule_client_get(info->mti_pill,
+                                                         &RMF_NAME);
+               rc = mdt_getxattr_one(info, xattr_name, next, buf, med, uc);
+       } else if (valid == OBD_MD_FLXATTRLS) {
+               CDEBUG(D_INODE, "listxattr\n");
+
+               rc = mo_xattr_list(info->mti_env, next, buf);
+               if (rc < 0)
+                       CDEBUG(D_INFO, "listxattr failed: %d\n", rc);
+       } else if (valid == OBD_MD_FLXATTRALL) {
+               rc = mdt_getxattr_all(info, reqbody, repbody,
+                                     buf, next);
+       } else
+               LBUG();
+
+       EXIT;
 out:
-        if (rc >= 0) {
-                repbody->eadatasize = rc;
-                rc = 0;
-        }
-        mdt_exit_ucred(info);
-        return rc;
+       if (rc >= 0) {
+               mdt_counter_incr(req, LPROC_MDT_GETXATTR);
+               repbody->mbo_eadatasize = rc;
+               rc = 0;
+       }
+       mdt_exit_ucred(info);
+       return rc;
 }
 
 static int mdt_rmtlsetfacl(struct mdt_thread_info *info,
@@ -218,7 +314,7 @@ static int mdt_rmtlsetfacl(struct mdt_thread_info *info,
 {
         struct ptlrpc_request  *req = mdt_info_req(info);
         struct mdt_export_data *med = mdt_req2med(req);
-        struct md_ucred        *uc = mdt_ucred(info);
+       struct lu_ucred        *uc = mdt_ucred(info);
         struct lu_buf          *buf = &info->mti_buf;
         int                     rc;
         ENTRY;
@@ -226,7 +322,7 @@ static int mdt_rmtlsetfacl(struct mdt_thread_info *info,
         rc = lustre_ext_acl_xattr_id2server(uc, med->med_idmap, header);
         if (rc)
                 RETURN(rc);
+
         rc = mo_xattr_get(info->mti_env, next, &LU_BUF_NULL, xattr_name);
         if (rc == -ENODATA)
                 rc = 0;
@@ -235,7 +331,7 @@ static int mdt_rmtlsetfacl(struct mdt_thread_info *info,
 
         buf->lb_len = rc;
         if (buf->lb_len > 0) {
-                OBD_ALLOC(buf->lb_buf, buf->lb_len);
+                OBD_ALLOC_LARGE(buf->lb_buf, buf->lb_len);
                 if (unlikely(buf->lb_buf == NULL))
                         RETURN(-ENOMEM);
 
@@ -253,100 +349,152 @@ static int mdt_rmtlsetfacl(struct mdt_thread_info *info,
 
 _out:
         if (rc <= 0 && buf->lb_buf != NULL)
-                OBD_FREE(buf->lb_buf, buf->lb_len);
+                OBD_FREE_LARGE(buf->lb_buf, buf->lb_len);
         return rc;
 }
 
 int mdt_reint_setxattr(struct mdt_thread_info *info,
                        struct mdt_lock_handle *unused)
 {
-        struct ptlrpc_request   *req = mdt_info_req(info);
-        struct mdt_export_data  *med = mdt_req2med(req);
-        struct md_ucred         *uc  = mdt_ucred(info);
-        const char               user_string[] = "user.";
-        const char               trust_string[] = "trusted.";
-        struct mdt_lock_handle  *lh;
-        struct req_capsule      *pill = info->mti_pill;
-        const struct lu_env     *env  = info->mti_env;
-        struct lu_buf           *buf  = &info->mti_buf;
-        struct mdt_reint_record *rr   = &info->mti_rr;
-        struct lu_attr          *attr = &info->mti_attr.ma_attr;
-        struct mdt_object       *obj; 
-        struct md_object        *child;
-        __u64                    valid = attr->la_valid;
-        const char              *xattr_name;
-        int                      xattr_len = 0;
-        __u64                    lockpart;
-        int                      rc;
-        posix_acl_xattr_header  *new_xattr = NULL;
-        ENTRY;
+       struct ptlrpc_request   *req = mdt_info_req(info);
+       struct lu_ucred         *uc  = lu_ucred(info->mti_env);
+       struct mdt_lock_handle  *lh;
+       const struct lu_env     *env  = info->mti_env;
+       struct lu_buf           *buf  = &info->mti_buf;
+       struct mdt_reint_record *rr   = &info->mti_rr;
+       struct md_attr          *ma = &info->mti_attr;
+       struct lu_attr          *attr = &info->mti_attr.ma_attr;
+       struct mdt_object       *obj;
+       struct md_object        *child;
+       struct obd_export       *exp = info->mti_exp;
+       struct lu_nodemap       *nodemap = exp->exp_target_data.ted_nodemap;
+       __u64                    valid = attr->la_valid;
+       const char              *xattr_name = rr->rr_name.ln_name;
+       int                      xattr_len = rr->rr_eadatalen;
+       __u64                    lockpart;
+       int                      rc;
+       posix_acl_xattr_header  *new_xattr = NULL;
+       __u32                    remote = exp_connect_rmtclient(info->mti_exp);
+       __u32                    perm;
+       ENTRY;
 
         CDEBUG(D_INODE, "setxattr for "DFID"\n", PFID(rr->rr_fid1));
 
+       if (info->mti_dlm_req)
+               ldlm_request_cancel(req, info->mti_dlm_req, 0, LATF_SKIP);
+
         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SETXATTR))
                 RETURN(err_serious(-ENOMEM));
 
-        xattr_name = rr->rr_name;
-
         CDEBUG(D_INODE, "%s xattr %s\n",
                valid & OBD_MD_FLXATTR ? "set" : "remove", xattr_name);
 
-        rc = mdt_init_ucred_reint(info);
+       rc = mdt_init_ucred_reint(info);
         if (rc != 0)
                 RETURN(rc);
 
         if (valid & OBD_MD_FLRMTRSETFACL) {
-                __u32 perm = mdt_identity_get_perm(uc->mu_identity,
-                                                   med->med_rmtclient,
-                                                   req->rq_peer.nid);
+                if (unlikely(!remote))
+                        GOTO(out, rc = err_serious(-EINVAL));
+
+               perm = mdt_identity_get_perm(uc->uc_identity, remote,
+                                            req->rq_peer.nid);
+               if (!(perm & CFS_RMTACL_PERM))
+                       GOTO(out, rc = err_serious(-EPERM));
+       }
+
+       if (strncmp(xattr_name, XATTR_USER_PREFIX,
+                   sizeof(XATTR_USER_PREFIX) - 1) == 0) {
+               if (!(exp_connect_flags(req->rq_export) & OBD_CONNECT_XATTR))
+                       GOTO(out, rc = -EOPNOTSUPP);
+       } else if (strncmp(xattr_name, XATTR_TRUSTED_PREFIX,
+                   sizeof(XATTR_TRUSTED_PREFIX) - 1) == 0) {
+
+               if (!md_capable(mdt_ucred(info), CFS_CAP_SYS_ADMIN))
+                       GOTO(out, rc = -EPERM);
+
+               if (strcmp(xattr_name, XATTR_NAME_LOV) == 0 ||
+                   strcmp(xattr_name, XATTR_NAME_LMA) == 0 ||
+                   strcmp(xattr_name, XATTR_NAME_LMV) == 0 ||
+                   strcmp(xattr_name, XATTR_NAME_LINK) == 0 ||
+                   strcmp(xattr_name, XATTR_NAME_FID) == 0 ||
+                   strcmp(xattr_name, XATTR_NAME_VERSION) == 0 ||
+                   strcmp(xattr_name, XATTR_NAME_SOM) == 0 ||
+                   strcmp(xattr_name, XATTR_NAME_HSM) == 0 ||
+                   strcmp(xattr_name, XATTR_NAME_LFSCK_NAMESPACE) == 0)
+                       GOTO(out, rc = 0);
+
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 8, 53, 0)
+               if (strcmp(xattr_name, XATTR_NAME_LFSCK_NAMESPACE_OLD) == 0)
+                       GOTO(out, rc = 0);
+#endif
+       } else if ((valid & OBD_MD_FLXATTR) &&
+                  (strcmp(xattr_name, XATTR_NAME_ACL_ACCESS) == 0 ||
+                   strcmp(xattr_name, XATTR_NAME_ACL_DEFAULT) == 0)) {
 
-                LASSERT(med->med_rmtclient);
-                if (!(perm & CFS_RMTACL_PERM))
-                        GOTO(out, rc = err_serious(-EPERM));
-        }
+               /* currently lustre limit acl access size */
+               if (xattr_len > LUSTRE_POSIX_ACL_MAX_SIZE)
+                       GOTO(out, rc = -ERANGE);
 
-        /* various sanity check for xattr name */
-        xattr_name = req_capsule_client_get(pill, &RMF_NAME);
-        if (!xattr_name)
-                GOTO(out, rc = err_serious(-EFAULT));
+               rc = nodemap_map_acl(nodemap, rr->rr_eadata, xattr_len,
+                                    NODEMAP_CLIENT_TO_FS);
+               if (rc < 0)
+                       GOTO(out, rc);
 
-        if (strncmp(xattr_name, trust_string, sizeof(trust_string) - 1) == 0) {
-                if (strcmp(xattr_name + 8, XATTR_NAME_LOV) == 0)
-                        GOTO(out, rc = -EACCES);
-        }
-
-        if (!(req->rq_export->exp_connect_flags & OBD_CONNECT_XATTR) &&
-            (strncmp(xattr_name, user_string, sizeof(user_string) - 1) == 0)) {
-                GOTO(out, rc = -EOPNOTSUPP);
-        }
+               /* ACLs were mapped out, return an error so the user knows */
+               if (rc != xattr_len)
+                       GOTO(out, rc = -EPERM);
+       }
 
         lockpart = MDS_INODELOCK_UPDATE;
+        /* Revoke all clients' lookup lock, since the access
+         * permissions for this inode is changed when ACL_ACCESS is
+         * set. This isn't needed for ACL_DEFAULT, since that does
+         * not change the access permissions of this inode, nor any
+         * other existing inodes. It is setting the ACLs inherited
+         * by new directories/files at create time. */
+       /* We need revoke both LOOKUP|PERM lock here, see mdt_attr_set. */
         if (!strcmp(xattr_name, XATTR_NAME_ACL_ACCESS))
-                lockpart |= MDS_INODELOCK_LOOKUP;
+               lockpart |= MDS_INODELOCK_PERM | MDS_INODELOCK_LOOKUP;
+       /* We need to take the lock on behalf of old clients so that newer
+        * clients flush their xattr caches */
+       else
+               lockpart |= MDS_INODELOCK_XATTR;
 
         lh = &info->mti_lh[MDT_LH_PARENT];
-        mdt_lock_reg_init(lh, LCK_PW);
+        /* ACLs were sent to clients under LCK_CR locks, so taking LCK_EX
+         * to cancel them. */
+        mdt_lock_reg_init(lh, LCK_EX);
         obj = mdt_object_find_lock(info, rr->rr_fid1, lh, lockpart);
-        if (IS_ERR(obj))
-                GOTO(out, rc =  PTR_ERR(obj));
-
-        child = mdt_object_child(obj);
-        if ((valid & OBD_MD_FLXATTR) == OBD_MD_FLXATTR) {
-                char * xattr;
-
-                if (!req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
-                        CDEBUG(D_INFO, "no xattr data supplied\n");
-                        GOTO(out_unlock, rc = -EFAULT);
-                }
-
-                xattr_len = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT);
-                if (xattr_len) {
+       if (IS_ERR(obj))
+               GOTO(out, rc = PTR_ERR(obj));
+
+       tgt_vbr_obj_set(env, mdt_obj2dt(obj));
+       rc = mdt_version_get_check_save(info, obj, 0);
+       if (rc)
+               GOTO(out_unlock, rc);
+
+       if (unlikely(!(valid & OBD_MD_FLCTIME))) {
+               /* This isn't strictly an error, but all current clients
+                * should set OBD_MD_FLCTIME when setting attributes. */
+               CWARN("%s: client miss to set OBD_MD_FLCTIME when "
+                     "setxattr %s: [object "DFID"] [valid "LPU64"]\n",
+                     mdt_obd_name(info->mti_mdt), xattr_name,
+                     PFID(rr->rr_fid1), valid);
+               attr->la_ctime = cfs_time_current_sec();
+       }
+       attr->la_valid = LA_CTIME;
+       child = mdt_object_child(obj);
+       if (valid & OBD_MD_FLXATTR) {
+               char *xattr = rr->rr_eadata;
+
+                if (xattr_len > 0) {
                         int flags = 0;
 
-                        xattr = req_capsule_client_get(pill, &RMF_EADATA);
-
                         if (valid & OBD_MD_FLRMTLSETFACL) {
-                                LASSERT(med->med_rmtclient);
+                                if (unlikely(!remote))
+                                        GOTO(out_unlock, rc = -EINVAL);
+
                                 xattr_len = mdt_rmtlsetfacl(info, child,
                                                 xattr_name,
                                                 (ext_acl_xattr_header *)xattr,
@@ -369,19 +517,32 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
                         buf->lb_buf = xattr;
                         buf->lb_len = xattr_len;
                         rc = mo_xattr_set(env, child, buf, xattr_name, flags);
+                        /* update ctime after xattr changed */
+                        if (rc == 0) {
+                                ma->ma_attr_flags |= MDS_PERM_BYPASS;
+                                mo_attr_set(env, child, ma);
+                        }
                 }
-        } else if ((valid & OBD_MD_FLXATTRRM) == OBD_MD_FLXATTRRM) {
+        } else if (valid & OBD_MD_FLXATTRRM) {
                 rc = mo_xattr_del(env, child, xattr_name);
+                /* update ctime after xattr changed */
+                if (rc == 0) {
+                        ma->ma_attr_flags |= MDS_PERM_BYPASS;
+                        mo_attr_set(env, child, ma);
+                }
         } else {
                 CDEBUG(D_INFO, "valid bits: "LPX64"\n", valid);
                 rc = -EINVAL;
         }
+        if (rc == 0)
+               mdt_counter_incr(req, LPROC_MDT_SETXATTR);
+
         EXIT;
 out_unlock:
         mdt_object_unlock_put(info, obj, lh, rc);
         if (unlikely(new_xattr != NULL))
                 lustre_posix_acl_xattr_free(new_xattr, xattr_len);
 out:
-        mdt_exit_ucred(info);
-        return rc;
+       mdt_exit_ucred(info);
+       return rc;
 }