Whamcloud - gitweb
LU-12616 obclass: fix MDS start/stop race
[fs/lustre-release.git] / lustre / mdd / mdd_permission.c
index 1ce1fe5..5d00907 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2015, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -40,7 +40,6 @@
 #define DEBUG_SUBSYSTEM S_MDS
 
 #include <obd_class.h>
-#include <lustre_ver.h>
 #include <lprocfs_status.h>
 #include <lustre_mds.h>
 #include <lustre_idmap.h>
@@ -54,7 +53,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;
@@ -62,19 +61,26 @@ 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));
+       lu_buf_check_and_alloc(&mdd_env_info(env)->mti_xattr_buf,
+                       MIN(mdd_obj2mdd_dev(o)->mdd_dt_conf.ddp_max_ea_size,
+                           XATTR_SIZE_MAX));
+       buf = mdd_env_info(env)->mti_xattr_buf;
+       if (buf.lb_buf == NULL)
+               RETURN(-ENOMEM);
 
-       rc = mdo_xattr_get(env, o, buf, XATTR_NAME_ACL_ACCESS);
+       if (buf.lb_len > XATTR_SIZE_MAX)
+               buf.lb_len  = XATTR_SIZE_MAX;
+
+       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);
@@ -83,7 +89,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);
 }
@@ -102,7 +108,7 @@ int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
        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)
@@ -141,7 +147,7 @@ int mdd_acl_set(const struct lu_env *env, struct mdd_object *obj,
        if (rc)
                GOTO(stop, rc);
 
-       mdd_write_lock(env, obj, MOR_TGT_CHILD);
+       mdd_write_lock(env, obj, DT_TGT_CHILD);
        /* whether ACL can be represented by i_mode only */
        if (not_equiv)
                rc = mdo_xattr_set(env, obj, buf, XATTR_NAME_ACL_ACCESS, fl,
@@ -182,7 +188,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)
@@ -205,21 +211,29 @@ 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,
+                       MIN(mdd_obj2mdd_dev(obj)->mdd_dt_conf.ddp_max_ea_size,
+                           XATTR_SIZE_MAX));
+       buf = mdd_env_info(env)->mti_xattr_buf;
+       if (buf.lb_buf == NULL)
+               RETURN(-ENOMEM);
+
+       if (buf.lb_len > XATTR_SIZE_MAX)
+               buf.lb_len  = XATTR_SIZE_MAX;
+
+       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 */
@@ -301,9 +315,8 @@ check_capabilities:
        RETURN(-EACCES);
 }
 
-int mdd_permission(const struct lu_env *env,
-                   struct md_object *pobj, struct md_object *cobj,
-                   struct md_attr *ma, int mask)
+int mdd_permission(const struct lu_env *env, struct md_object *pobj,
+                  struct md_object *cobj, struct md_attr *ma, int mask)
 {
        struct mdd_object *mdd_pobj = NULL;
        struct mdd_object *mdd_cobj;
@@ -327,15 +340,9 @@ int mdd_permission(const struct lu_env *env,
        if (rc)
                RETURN(rc);
 
-       /* For cross_open case, the "mask" is open flags,
-        * so convert it to permission mask first.
-        * XXX: MDS_OPEN_CROSS must be NOT equal to permission mask MAY_*. */
-       if (unlikely(mask & MDS_OPEN_CROSS))
-               mask = accmode(env, cattr, mask & ~MDS_OPEN_CROSS);
-
        rc = mdd_permission_internal_locked(env, mdd_cobj, cattr,
                                            mask & ~MAY_RGETFACL,
-                                           MOR_TGT_CHILD);
+                                           DT_TGT_CHILD);
 
        if (unlikely(rc == 0 && (mask & MAY_RGETFACL))) {
                if (likely(!uc))