Whamcloud - gitweb
LU-6024 nodemap: fix ACL handling in mdt_finish_open 62/13062/3
authorKit Westneat <kit.westneat@gmail.com>
Sat, 13 Dec 2014 16:11:53 +0000 (11:11 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Sun, 21 Dec 2014 09:36:40 +0000 (09:36 +0000)
This patch adds ACL mapping code to mdt_finish_open so that clients
get a correctly mapped list. The code is essentially the same as in
mdt_getattr_internal.

Signed-off-by: Kit Westneat <kit.westneat@gmail.com>
Change-Id: I3cf0ba2128ba8c4027359329f423d2327005f082
Reviewed-on: http://review.whamcloud.com/13062
Tested-by: Jenkins
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Nathaniel Clark <nathaniel.l.clark@intel.com>
Reviewed-by: Andrew Perepechko <andrew.perepechko@seagate.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/mdt/mdt_handler.c
lustre/mdt/mdt_internal.h
lustre/mdt/mdt_open.c

index 2379caf..619fa79 100644 (file)
@@ -389,6 +389,62 @@ static void mdt_pack_size2body(struct mdt_thread_info *info,
        b->mbo_blocks = ma->ma_som->msd_blocks;
 }
 
        b->mbo_blocks = ma->ma_som->msd_blocks;
 }
 
+#ifdef CONFIG_FS_POSIX_ACL
+/*
+ * Pack ACL data into the reply. UIDs/GIDs are mapped and filtered by nodemap.
+ *
+ * \param      info    thread info object
+ * \param      repbody reply to pack ACLs into
+ * \param      o       mdt object of file to examine
+ * \param      nodemap nodemap of client to reply to
+ * \retval     0       success
+ * \retval     -errno  error getting or parsing ACL from disk
+ */
+int mdt_pack_acl2body(struct mdt_thread_info *info, struct mdt_body *repbody,
+                     struct mdt_object *o, struct lu_nodemap *nodemap)
+{
+       const struct lu_env     *env = info->mti_env;
+       struct md_object        *next = mdt_object_child(o);
+       struct lu_buf           *buf = &info->mti_buf;
+       int rc;
+
+       buf->lb_buf = req_capsule_server_get(info->mti_pill, &RMF_ACL);
+       buf->lb_len = req_capsule_get_size(info->mti_pill, &RMF_ACL,
+                                          RCL_SERVER);
+       if (buf->lb_len == 0)
+               return 0;
+
+       rc = mo_xattr_get(env, next, buf, XATTR_NAME_ACL_ACCESS);
+       if (rc < 0) {
+               if (rc == -ENODATA) {
+                       repbody->mbo_aclsize = 0;
+                       repbody->mbo_valid |= OBD_MD_FLACL;
+                       rc = 0;
+               } else if (rc == -EOPNOTSUPP) {
+                       rc = 0;
+               } else {
+                       CERROR("%s: unable to read "DFID" ACL: rc = %d\n",
+                              mdt_obd_name(info->mti_mdt),
+                              PFID(mdt_object_fid(o)), rc);
+               }
+       } else {
+               rc = nodemap_map_acl(nodemap, buf->lb_buf,
+                                    rc, NODEMAP_FS_TO_CLIENT);
+               /* if all ACLs mapped out, rc is still >= 0 */
+               if (rc < 0) {
+                       CERROR("%s: nodemap_map_acl unable to parse "DFID
+                              " ACL: rc = %d\n", mdt_obd_name(info->mti_mdt),
+                              PFID(mdt_object_fid(o)), rc);
+               } else {
+                       repbody->mbo_aclsize = rc;
+                       repbody->mbo_valid |= OBD_MD_FLACL;
+                       rc = 0;
+               }
+       }
+       return rc;
+}
+#endif
+
 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
                         const struct lu_attr *attr, const struct lu_fid *fid)
 {
 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
                         const struct lu_attr *attr, const struct lu_fid *fid)
 {
@@ -1006,43 +1062,8 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
        }
 #ifdef CONFIG_FS_POSIX_ACL
        else if ((exp_connect_flags(req->rq_export) & OBD_CONNECT_ACL) &&
        }
 #ifdef CONFIG_FS_POSIX_ACL
        else if ((exp_connect_flags(req->rq_export) & OBD_CONNECT_ACL) &&
-                (reqbody->mbo_valid & OBD_MD_FLACL)) {
-                buffer->lb_buf = req_capsule_server_get(pill, &RMF_ACL);
-                buffer->lb_len = req_capsule_get_size(pill,
-                                                      &RMF_ACL, RCL_SERVER);
-                if (buffer->lb_len > 0) {
-                        rc = mo_xattr_get(env, next, buffer,
-                                          XATTR_NAME_ACL_ACCESS);
-                        if (rc < 0) {
-                                if (rc == -ENODATA) {
-                                       repbody->mbo_aclsize = 0;
-                                       repbody->mbo_valid |= OBD_MD_FLACL;
-                                        rc = 0;
-                                } else if (rc == -EOPNOTSUPP) {
-                                        rc = 0;
-                               } else {
-                                       CERROR("%s: unable to read "DFID
-                                              " ACL: rc = %d\n",
-                                              mdt_obd_name(info->mti_mdt),
-                                              PFID(mdt_object_fid(o)), rc);
-                               }
-                        } else {
-                               rc = nodemap_map_acl(nodemap, buffer->lb_buf,
-                                                    rc, NODEMAP_FS_TO_CLIENT);
-                               /* if all ACLs mapped out, rc is still >= 0 */
-                               if (rc < 0) {
-                                       CERROR("%s: nodemap_map_acl unable to"
-                                              " parse "DFID" ACL: rc = %d\n",
-                                              mdt_obd_name(info->mti_mdt),
-                                              PFID(mdt_object_fid(o)), rc);
-                               } else {
-                                       repbody->mbo_aclsize = rc;
-                                       repbody->mbo_valid |= OBD_MD_FLACL;
-                                       rc = 0;
-                               }
-                       }
-               }
-       }
+                (reqbody->mbo_valid & OBD_MD_FLACL))
+               rc = mdt_pack_acl2body(info, repbody, o, nodemap);
 #endif
 
        if (reqbody->mbo_valid & OBD_MD_FLMDSCAPA &&
 #endif
 
        if (reqbody->mbo_valid & OBD_MD_FLMDSCAPA &&
index 68750e0..6897b70 100644 (file)
@@ -680,6 +680,10 @@ int mdt_name_unpack(struct req_capsule *pill,
 int mdt_close_unpack(struct mdt_thread_info *info);
 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op);
 int mdt_reint_rec(struct mdt_thread_info *, struct mdt_lock_handle *);
 int mdt_close_unpack(struct mdt_thread_info *info);
 int mdt_reint_unpack(struct mdt_thread_info *info, __u32 op);
 int mdt_reint_rec(struct mdt_thread_info *, struct mdt_lock_handle *);
+#ifdef CONFIG_FS_POSIX_ACL
+int mdt_pack_acl2body(struct mdt_thread_info *info, struct mdt_body *repbody,
+                     struct mdt_object *o, struct lu_nodemap *nodemap);
+#endif
 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
                         const struct lu_attr *attr, const struct lu_fid *fid);
 
 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
                         const struct lu_attr *attr, const struct lu_fid *fid);
 
index 4aacc8c..2d8ac64 100644 (file)
@@ -45,6 +45,7 @@
 #include <lustre_acl.h>
 #include <lustre_mds.h>
 #include "mdt_internal.h"
 #include <lustre_acl.h>
 #include <lustre_mds.h>
 #include "mdt_internal.h"
+#include <lustre_nodemap.h>
 
 /* we do nothing because we do not have refcount now */
 static void mdt_mfd_get(void *mfdp)
 
 /* we do nothing because we do not have refcount now */
 static void mdt_mfd_get(void *mfdp)
@@ -904,34 +905,9 @@ int mdt_finish_open(struct mdt_thread_info *info,
                 }
         }
 #ifdef CONFIG_FS_POSIX_ACL
                 }
         }
 #ifdef CONFIG_FS_POSIX_ACL
-       else if (exp_connect_flags(exp) & OBD_CONNECT_ACL) {
-                const struct lu_env *env = info->mti_env;
-                struct md_object *next = mdt_object_child(o);
-                struct lu_buf *buf = &info->mti_buf;
-
-                buf->lb_buf = req_capsule_server_get(info->mti_pill, &RMF_ACL);
-                buf->lb_len = req_capsule_get_size(info->mti_pill, &RMF_ACL,
-                                                   RCL_SERVER);
-                if (buf->lb_len > 0) {
-                        rc = mo_xattr_get(env, next, buf,
-                                          XATTR_NAME_ACL_ACCESS);
-                        if (rc < 0) {
-                                if (rc == -ENODATA) {
-                                       repbody->mbo_aclsize = 0;
-                                       repbody->mbo_valid |= OBD_MD_FLACL;
-                                        rc = 0;
-                                } else if (rc == -EOPNOTSUPP) {
-                                        rc = 0;
-                                } else {
-                                        CERROR("got acl size: %d\n", rc);
-                                }
-                        } else {
-                               repbody->mbo_aclsize = rc;
-                               repbody->mbo_valid |= OBD_MD_FLACL;
-                                rc = 0;
-                        }
-                }
-        }
+       else if (exp_connect_flags(exp) & OBD_CONNECT_ACL)
+               rc = mdt_pack_acl2body(info, repbody, o,
+                                      exp->exp_target_data.ted_nodemap);
 #endif
 
        if (info->mti_mdt->mdt_lut.lut_mds_capa &&
 #endif
 
        if (info->mti_mdt->mdt_lut.lut_mds_capa &&