Whamcloud - gitweb
delete test_12 in sanity-quota.sh
[fs/lustre-release.git] / lustre / mds / mds_xattr.c
index d37fa65..cd84bc5 100644 (file)
@@ -1,28 +1,41 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  linux/mds/mds_xattr.c
- *  Lustre Metadata Server (mds) extended attributes handling
+ * GPL HEADER START
  *
- *  Copyright (C) 2004-2005 Cluster File Systems, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   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 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.
  *
- *   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.
+ * 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).
  *
- *   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.
+ * 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
  *
- *   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.
+ * 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.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/mds/mds_xattr.c
+ *
+ * Lustre Metadata Server (mds) extended attributes handling
  */
 
 #ifndef EXPORT_SYMTAB
 #define DEBUG_SUBSYSTEM S_MDS
 
 #include <linux/fs.h>
-#include <linux/obd_support.h>
-#include <linux/obd_class.h>
-#include <linux/obd.h>
-#include <linux/lustre_lib.h>
-#include <linux/lustre_idl.h>
-#include <linux/lustre_mds.h>
-#include <linux/lustre_dlm.h>
-#include <linux/lustre_fsfilt.h>
-#include <linux/lustre_ucache.h>
-
-#include "mds_internal.h"
+#include <obd_support.h>
+#include <obd_class.h>
+#include <obd.h>
+#include <lustre_lib.h>
+#include <lustre/lustre_idl.h>
+#include <lustre_mds.h>
+#include <lustre_dlm.h>
+#include <lustre_fsfilt.h>
+#include <lustre_ucache.h>
+
+#include "mds_internal.h" 
+
+#ifndef XATTR_NAME_ACL_ACCESS
+#define XATTR_NAME_ACL_ACCESS   "system.posix_acl_access"
+#endif
 
 static int mds_getxattr_pack_msg(struct ptlrpc_request *req,
                                  struct dentry *de,
                                  struct mds_body *body)
 {
         struct inode *inode = de->d_inode;
-        int size[2] = {sizeof(*body)}, bufcnt = 1;
         char *xattr_name;
-        int rc = -EOPNOTSUPP, rc2;
+        int size[3] = { sizeof(struct ptlrpc_body), sizeof(*body) };
+        int bufcnt = 2, rc = -EOPNOTSUPP, rc2;
 
         if (inode == NULL)
                 return -ENOENT;
 
         if (body->valid & OBD_MD_FLXATTR) {
-                xattr_name = lustre_msg_string(req->rq_reqmsg, 1, 0);
+                xattr_name = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF+1,0);
                 if (!xattr_name) {
                         CERROR("can't extract xattr name\n");
                         return -EFAULT;
@@ -80,7 +97,7 @@ static int mds_getxattr_pack_msg(struct ptlrpc_request *req,
                 if (rc != -ENODATA && rc != -EOPNOTSUPP)
                         CWARN("get inode %lu EA size error: %d\n",
                               inode->i_ino, rc);
-                bufcnt = 0;
+                bufcnt = 1;
         } else {
                 size[bufcnt++] = min_t(int, body->eadatasize, rc);
         }
@@ -115,35 +132,31 @@ static int mds_getxattr_internal(struct obd_device *obd,
         if (inode == NULL)
                 GOTO(out, rc = -ENOENT);
 
-        repbody = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*repbody));
+        repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,
+                                 sizeof(*repbody));
         LASSERT(repbody != NULL);
 
-        buflen = lustre_msg_buflen(req->rq_repmsg, 1);
+        buflen = lustre_msg_buflen(req->rq_repmsg, REPLY_REC_OFF + 1);
         if (buflen)
-                buf = lustre_msg_buf(req->rq_repmsg, 1, buflen);
+                buf = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1, buflen);
 
         if (reqbody->valid & OBD_MD_FLXATTR) {
-                xattr_name = lustre_msg_string(req->rq_reqmsg, 1, 0);
-                DEBUG_REQ(D_INODE, req, "getxattr %s\n", xattr_name);
+                xattr_name = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF+1,0);
+                DEBUG_REQ(D_INODE, req, "getxattr %s", xattr_name);
 
                 if (inode->i_op && inode->i_op->getxattr) {
-                        lock_24kernel();
                         rc = inode->i_op->getxattr(dentry, xattr_name,
                                                    buf, buflen);
-                        unlock_24kernel();
                 }
 
                 if (rc < 0 && rc != -ENODATA && rc != -EOPNOTSUPP &&
                     rc != -ERANGE)
                         CDEBUG(D_OTHER, "getxattr failed: %d\n", rc);
         } else if (reqbody->valid & OBD_MD_FLXATTRLS) {
-                DEBUG_REQ(D_INODE, req, "listxattr\n");
+                DEBUG_REQ(D_INODE, req, "listxattr");
 
-                if (inode->i_op && inode->i_op->listxattr) {
-                        lock_24kernel();
+                if (inode->i_op && inode->i_op->listxattr)
                         rc = inode->i_op->listxattr(dentry, buf, buflen);
-                        unlock_24kernel();
-                }
                 if (rc < 0)
                         CDEBUG(D_OTHER, "listxattr failed: %d\n", rc);
         } else
@@ -165,15 +178,18 @@ int mds_getxattr(struct ptlrpc_request *req)
         struct lvfs_run_ctxt saved;
         struct dentry *de;
         struct mds_body *body;
-        struct lvfs_ucred uc = {NULL,};
+        struct lvfs_ucred uc = { NULL, };
         int rc = 0;
         ENTRY;
 
-        body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
+        mds_counter_incr(req->rq_export, LPROC_MDS_GETXATTR);
+
+        body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
+                                  lustre_swab_mds_body);
         if (body == NULL)
                 RETURN(-EFAULT);
 
-        rc = mds_init_ucred(&uc, req, 0);
+        rc = mds_init_ucred(&uc, req, REQ_REC_OFF);
         if (rc)
                 GOTO(out_ucred, rc);
 
@@ -199,6 +215,10 @@ out_ucred:
         return rc;
 }
 
+/*
+ * alwasy return 0, and set req->rq_status as error number in case
+ * of failures.
+ */
 static
 int mds_setxattr_internal(struct ptlrpc_request *req, struct mds_body *body)
 {
@@ -206,16 +226,16 @@ int mds_setxattr_internal(struct ptlrpc_request *req, struct mds_body *body)
         struct obd_device *obd = req->rq_export->exp_obd;
         struct dentry *de;
         struct inode *inode = NULL;
+        struct inode *inodes[PTLRPC_NUM_VERSIONS] = { NULL };
         struct lustre_handle lockh;
         void *handle = NULL;
         char *xattr_name;
         char *xattr = NULL;
         int xattrlen;
-        int rc = -EOPNOTSUPP, err = 0;
+        int rc = -EOPNOTSUPP, err = 0, sync = 0;
         __u64 lockpart;
         ENTRY;
 
-        body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
         LASSERT(body);
 
         DEBUG_REQ(D_INODE, req, "setxattr "LPU64"/%u",
@@ -225,36 +245,58 @@ int mds_setxattr_internal(struct ptlrpc_request *req, struct mds_body *body)
 
         lockpart = MDS_INODELOCK_UPDATE;
 
-        de = mds_fid2locked_dentry(obd, &body->fid1, NULL, LCK_EX,
-                                   &lockh, NULL, 0, lockpart);
-        if (IS_ERR(de))
-                GOTO(out, rc = PTR_ERR(de));
-
-        inode = de->d_inode;
-        LASSERT(inode);
-
-        OBD_FAIL_WRITE(OBD_FAIL_MDS_SETXATTR_WRITE, inode->i_sb);
-
-        xattr_name = lustre_msg_string(req->rq_reqmsg, 1, 0);
+        /* various sanity check for xattr name */
+        xattr_name = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
         if (!xattr_name) {
                 CERROR("can't extract xattr name\n");
-                GOTO(out_dput, rc = -EPROTO);
+                GOTO(out, rc = -EPROTO);
         }
 
-        DEBUG_REQ(D_INODE, req, "%sxattr %s\n",
+        DEBUG_REQ(D_INODE, req, "%sxattr %s",
                   body->valid & OBD_MD_FLXATTR ? "set" : "remove",
                   xattr_name);
 
         if (strncmp(xattr_name, "trusted.", 8) == 0) {
                 if (strcmp(xattr_name + 8, XATTR_LUSTRE_MDS_LOV_EA) == 0)
-                        GOTO(out_dput, rc = -EACCES);
+                        GOTO(out, rc = -EACCES);
+                if (strcmp(xattr_name + 8, "lma") == 0 &&
+                    !OBD_FAIL_CHECK(OBD_FAIL_MDS_ALLOW_COMMON_EA_SETTING))
+                        GOTO(out, rc = 0);
         }
 
         if (!(req->rq_export->exp_connect_flags & OBD_CONNECT_XATTR) &&
             (strncmp(xattr_name, "user.", 5) == 0)) {
-                GOTO(out_dput, rc = -EOPNOTSUPP);
+                GOTO(out, rc = -EOPNOTSUPP);
         }
 
+        /* currently lustre limit xattr size */
+        if (body->valid & OBD_MD_FLXATTR && !strcmp(xattr_name, XATTR_NAME_ACL_ACCESS))  {
+                xattrlen = lustre_msg_buflen(req->rq_reqmsg,
+                                             REQ_REC_OFF + 2);
+
+                if (xattrlen > LUSTRE_POSIX_ACL_MAX_SIZE)
+                        GOTO(out, -ERANGE);
+        }
+
+
+        if (!strcmp(xattr_name, XATTR_NAME_ACL_ACCESS))
+                lockpart |= MDS_INODELOCK_LOOKUP;
+
+        de = mds_fid2locked_dentry(obd, &body->fid1, NULL, LCK_EX,
+                                   &lockh, NULL, 0, lockpart);
+        if (IS_ERR(de))
+                GOTO(out, rc = PTR_ERR(de));
+
+        inode = de->d_inode;
+        LASSERT(inode);
+
+        OBD_FAIL_WRITE(obd, OBD_FAIL_MDS_SETXATTR_WRITE, inode->i_sb);
+
+        /* version recovery check */
+        rc = mds_version_get_check(req, inode, 0);
+        if (rc)
+                GOTO(out_dput, rc);
+
         /* filter_op simply use setattr one */
         handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
         if (IS_ERR(handle))
@@ -262,30 +304,27 @@ int mds_setxattr_internal(struct ptlrpc_request *req, struct mds_body *body)
 
         if (body->valid & OBD_MD_FLXATTR) {
                 if (inode->i_op && inode->i_op->setxattr) {
-                        if (req->rq_reqmsg->bufcount < 3) {
+                        if (lustre_msg_bufcount(req->rq_reqmsg) < 4) {
                                 CERROR("no xattr data supplied\n");
                                 GOTO(out_trans, rc = -EFAULT);
                         }
 
-                        xattrlen = lustre_msg_buflen(req->rq_reqmsg, 2);
-                        if (xattrlen)
-                                xattr = lustre_msg_buf(req->rq_reqmsg, 2,
-                                                       xattrlen);
+                        xattrlen = lustre_msg_buflen(req->rq_reqmsg,
+                                                     REQ_REC_OFF + 2);
+
+                        xattr = lustre_msg_buf(req->rq_reqmsg,
+                                               REQ_REC_OFF+2, xattrlen);
 
-                        down(&inode->i_sem);
-                        lock_24kernel();
+                        LOCK_INODE_MUTEX(inode);
                         rc = inode->i_op->setxattr(de, xattr_name, xattr,
                                                    xattrlen, body->flags);
-                        unlock_24kernel();
-                        up(&inode->i_sem);
+                        UNLOCK_INODE_MUTEX(inode);
                 }
         } else if (body->valid & OBD_MD_FLXATTRRM) {
                 if (inode->i_op && inode->i_op->removexattr) {
-                        down(&inode->i_sem);
-                        lock_24kernel();
+                        LOCK_INODE_MUTEX(inode);
                         rc = inode->i_op->removexattr(de, xattr_name);
-                        unlock_24kernel();
-                        up(&inode->i_sem);
+                        UNLOCK_INODE_MUTEX(inode);
                 }
         } else {
                 CERROR("valid bits: "LPX64"\n", body->valid);
@@ -294,8 +333,11 @@ int mds_setxattr_internal(struct ptlrpc_request *req, struct mds_body *body)
 
         LASSERT(rc <= 0);
 out_trans:
-        err = mds_finish_transno(mds, inode, handle, req, rc, 0);
-
+        /* security-replated changes may require sync */
+        if (!strcmp(xattr_name, XATTR_NAME_ACL_ACCESS))
+                sync = mds->mds_sync_permission;
+        inodes[0] = inode;
+        err = mds_finish_transno(mds, inodes, handle, req, rc, 0, sync);
 out_dput:
         l_dput(de);
         if (rc)
@@ -316,24 +358,27 @@ int mds_setxattr(struct ptlrpc_request *req)
         struct obd_device *obd = req->rq_export->exp_obd;
         struct lvfs_run_ctxt saved;
         struct mds_body *body;
-        struct lvfs_ucred uc = {NULL,};
+        struct lvfs_ucred uc = { NULL, };
         int rc;
         ENTRY;
 
-        body = lustre_swab_reqbuf(req, 0, sizeof(*body), lustre_swab_mds_body);
+        mds_counter_incr(req->rq_export, LPROC_MDS_SETXATTR);
+
+        body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
+                                  lustre_swab_mds_body);
         if (body == NULL)
                 RETURN(-EFAULT);
 
-        if (req->rq_reqmsg->bufcount < 2)
+        if (lustre_msg_bufcount(req->rq_reqmsg) < 3)
                 RETURN(-EFAULT);
 
-        rc = mds_init_ucred(&uc, req, 0);
+        rc = mds_init_ucred(&uc, req, REQ_REC_OFF);
         if (rc)
                 GOTO(out_ucred, rc);
 
         push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);
 
-        rc = lustre_pack_reply(req, 0, NULL, NULL);
+        rc = lustre_pack_reply(req, 1, NULL, NULL);
         if (rc)
                 GOTO(out_pop, rc);