Whamcloud - gitweb
LU-9183 ptlrpc: handle posix_acl: xattr representation cleanups
[fs/lustre-release.git] / lustre / mdd / mdd_permission.c
index 2814800..4b4f9b9 100644 (file)
  *
  * 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
- *
- * 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.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -58,7 +54,7 @@
 int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
                  struct thandle *handle)
 {
-       struct lu_buf           *buf;
+       struct lu_buf            buf;
        posix_acl_xattr_header  *head;
        posix_acl_xattr_entry   *entry;
        int                      entry_count;
@@ -66,19 +62,19 @@ int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
 
        ENTRY;
 
-       buf = mdd_buf_get(env, mdd_env_info(env)->mti_xattr_buf,
-                         sizeof(mdd_env_info(env)->mti_xattr_buf));
-
-       rc = mdo_xattr_get(env, o, buf, XATTR_NAME_ACL_ACCESS);
+       lu_buf_check_and_alloc(&mdd_env_info(env)->mti_xattr_buf,
+                       mdd_obj2mdd_dev(o)->mdd_dt_conf.ddp_max_ea_size);
+       buf = mdd_env_info(env)->mti_xattr_buf;
+       rc = mdo_xattr_get(env, o, &buf, XATTR_NAME_ACL_ACCESS);
        if ((rc == -EOPNOTSUPP) || (rc == -ENODATA))
                RETURN(0);
        else if (rc <= 0)
                RETURN(rc);
 
-       buf->lb_len = rc;
-       head = (posix_acl_xattr_header *)(buf->lb_buf);
-       entry = head->a_entries;
-       entry_count = (buf->lb_len - sizeof(head->a_version)) /
+       buf.lb_len = rc;
+       head = (posix_acl_xattr_header *)(buf.lb_buf);
+       entry = GET_POSIX_ACL_XATTR_ENTRY(head);
+       entry_count = (buf.lb_len - sizeof(head->a_version)) /
                sizeof(posix_acl_xattr_entry);
        if (entry_count <= 0)
                RETURN(0);
@@ -87,7 +83,7 @@ int mdd_acl_chmod(const struct lu_env *env, struct mdd_object *o, __u32 mode,
        if (rc)
                RETURN(rc);
 
-       rc = mdo_xattr_set(env, o, buf, XATTR_NAME_ACL_ACCESS,
+       rc = mdo_xattr_set(env, o, &buf, XATTR_NAME_ACL_ACCESS,
                           0, handle);
        RETURN(rc);
 }
@@ -99,13 +95,14 @@ int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
        struct thandle          *handle;
        posix_acl_xattr_header  *head;
        posix_acl_xattr_entry   *entry;
-       int                      rc, entry_count;
+       int                      entry_count;
        bool                     not_equiv, mode_change;
        mode_t                   mode;
+       int                      rc;
        ENTRY;
 
        head = (posix_acl_xattr_header *)(buf->lb_buf);
-       entry = head->a_entries;
+       entry = GET_POSIX_ACL_XATTR_ENTRY(head);
        entry_count = (buf->lb_len - sizeof(head->a_version)) /
                sizeof(posix_acl_xattr_entry);
        if (entry_count <= 0)
@@ -163,7 +160,7 @@ int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
 unlock:
        mdd_write_unlock(env, obj);
 stop:
-       mdd_trans_stop(env, mdd, rc, handle);
+       rc = mdd_trans_stop(env, mdd, rc, handle);
 
        RETURN(rc);
 }
@@ -185,7 +182,7 @@ int __mdd_fix_mode_acl(const struct lu_env *env, struct lu_buf *buf,
        ENTRY;
 
        head = (posix_acl_xattr_header *)(buf->lb_buf);
-       entry = head->a_entries;
+       entry = GET_POSIX_ACL_XATTR_ENTRY(head);
        entry_count = (buf->lb_len - sizeof(head->a_version)) /
                      sizeof(posix_acl_xattr_entry);
        if (entry_count <= 0)
@@ -208,21 +205,22 @@ static int mdd_check_acl(const struct lu_env *env, struct mdd_object *obj,
        struct lu_ucred  *uc  = lu_ucred_assert(env);
        posix_acl_xattr_header *head;
        posix_acl_xattr_entry *entry;
-       struct lu_buf   *buf;
+       struct lu_buf buf;
        int entry_count;
        int rc;
        ENTRY;
 
-       buf = mdd_buf_get(env, mdd_env_info(env)->mti_xattr_buf,
-                         sizeof(mdd_env_info(env)->mti_xattr_buf));
-       rc = mdo_xattr_get(env, obj, buf, XATTR_NAME_ACL_ACCESS);
+       lu_buf_check_and_alloc(&mdd_env_info(env)->mti_xattr_buf,
+                       mdd_obj2mdd_dev(obj)->mdd_dt_conf.ddp_max_ea_size);
+       buf = mdd_env_info(env)->mti_xattr_buf;
+       rc = mdo_xattr_get(env, obj, &buf, XATTR_NAME_ACL_ACCESS);
        if (rc <= 0)
                RETURN(rc ? : -EACCES);
 
-       buf->lb_len = rc;
-       head = (posix_acl_xattr_header *)(buf->lb_buf);
-       entry = head->a_entries;
-       entry_count = posix_acl_xattr_count(buf->lb_len);
+       buf.lb_len = rc;
+       head = (posix_acl_xattr_header *)(buf.lb_buf);
+       entry = GET_POSIX_ACL_XATTR_ENTRY(head);
+       entry_count = posix_acl_xattr_count(buf.lb_len);
 
        /* Disregard empty ACLs and fall back to
         * standard UNIX permissions. See LU-5434 */