Whamcloud - gitweb
b=18143 Make VBR compatible with pdirops.
[fs/lustre-release.git] / lustre / mdt / mdt_xattr.c
index 70739b1..27fc03a 100644 (file)
@@ -16,8 +16,8 @@
  * in the LICENSE file that accompanied this code).
  *
  * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see [sun.com URL with a
- * copy of GPLv2].
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  *
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
 #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 <lustre_acl.h>
 #include "mdt_internal.h"
 
 
@@ -68,7 +62,7 @@ static int mdt_getxattr_pack_reply(struct mdt_thread_info * info)
         static const char       user_string[] = "user.";
         int                     size, rc;
         ENTRY;
-        
+
         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_GETXATTR_PACK))
                 RETURN(-ENOMEM);
 
@@ -81,7 +75,7 @@ static int mdt_getxattr_pack_reply(struct mdt_thread_info * info)
                 if (!(req->rq_export->exp_connect_flags & 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);
@@ -128,6 +122,8 @@ int mdt_getxattr(struct mdt_thread_info *info)
         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;
         ENTRY;
 
@@ -147,11 +143,11 @@ int mdt_getxattr(struct mdt_thread_info *info)
         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 (unlikely(!remote))
+                        GOTO(out, rc = err_serious(-EINVAL));
 
-                LASSERT(med->med_rmtclient);
+                perm = mdt_identity_get_perm(uc->mu_identity, remote,
+                                             req->rq_peer.nid);
                 if (!(perm & CFS_RMTACL_PERM))
                         GOTO(out, rc = err_serious(-EPERM));
 
@@ -197,7 +193,9 @@ int mdt_getxattr(struct mdt_thread_info *info)
                 if (rc > 0 && flags != CFS_IC_NOTHING) {
                         int rc1;
 
-                        LASSERT(med->med_rmtclient);
+                        if (unlikely(!remote))
+                                GOTO(out, rc = -EINVAL);
+
                         rc1 = lustre_posix_acl_xattr_id2client(uc,
                                         med->med_idmap,
                                         (posix_acl_xattr_header *)(buf->lb_buf),
@@ -275,10 +273,7 @@ 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;
@@ -294,6 +289,8 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
         __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));
@@ -311,11 +308,11 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
                 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));
 
-                LASSERT(med->med_rmtclient);
+                perm = mdt_identity_get_perm(uc->mu_identity, remote,
+                                             req->rq_peer.nid);
                 if (!(perm & CFS_RMTACL_PERM))
                         GOTO(out, rc = err_serious(-EPERM));
         }
@@ -325,14 +322,24 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
         if (!xattr_name)
                 GOTO(out, rc = err_serious(-EFAULT));
 
-        if (strncmp(xattr_name, trust_string, sizeof(trust_string) - 1) == 0) {
-                if (strcmp(xattr_name + 8, XATTR_NAME_LOV) == 0)
+        if (strncmp(xattr_name, XATTR_USER_PREFIX,
+                    sizeof(XATTR_USER_PREFIX) - 1) == 0) {
+                if (!(req->rq_export->exp_connect_flags & OBD_CONNECT_XATTR))
+                        GOTO(out, rc = -EOPNOTSUPP);
+                if (strcmp(xattr_name, XATTR_NAME_LOV) == 0)
                         GOTO(out, rc = -EACCES);
-        }
+                if (strcmp(xattr_name, XATTR_NAME_LMA) == 0)
+                        GOTO(out, rc = 0);
+                if (strcmp(xattr_name, XATTR_NAME_LINK) == 0)
+                        GOTO(out, rc = 0);
+        } else if ((valid & OBD_MD_FLXATTR) &&
+                   (strncmp(xattr_name, XATTR_NAME_ACL_ACCESS,
+                             sizeof(XATTR_NAME_ACL_ACCESS) - 1) == 0)) {
+                /* currently lustre limit acl access size */
+                xattr_len = req_capsule_get_size(pill, &RMF_EADATA, RCL_CLIENT);
 
-        if (!(req->rq_export->exp_connect_flags & OBD_CONNECT_XATTR) &&
-            (strncmp(xattr_name, user_string, sizeof(user_string) - 1) == 0)) {
-                GOTO(out, rc = -EOPNOTSUPP);
+                if (xattr_len > LUSTRE_POSIX_ACL_MAX_SIZE)
+                        GOTO(out, -ERANGE);
         }
 
         lockpart = MDS_INODELOCK_UPDATE;
@@ -345,9 +352,14 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
         if (IS_ERR(obj))
                 GOTO(out, rc =  PTR_ERR(obj));
 
+        info->mti_mos = obj;
+        rc = mdt_version_get_check_save(info, obj, 0);
+        if (rc)
+                GOTO(out_unlock, rc);
+
         if (unlikely(!(valid & OBD_MD_FLCTIME))) {
                 CWARN("client miss to set OBD_MD_FLCTIME when "
-                      "setxattr: [object "DFID"] [valid %llu]\n",
+                      "setxattr: [object "DFID"] [valid "LPU64"]\n",
                       PFID(rr->rr_fid1), valid);
                 attr->la_ctime = cfs_time_current_sec();
         }
@@ -368,7 +380,9 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
                         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,