Whamcloud - gitweb
LU-5092 nodemap: users of ted_nodemap should take ref
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index e997be8..290b130 100644 (file)
@@ -501,9 +501,9 @@ int mdt_pack_acl2body(struct mdt_thread_info *info, struct mdt_body *repbody,
 void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
                         const struct lu_attr *attr, const struct lu_fid *fid)
 {
-       struct md_attr          *ma = &info->mti_attr;
-       struct obd_export       *exp = info->mti_exp;
-       struct lu_nodemap       *nodemap = exp->exp_target_data.ted_nodemap;
+       struct md_attr *ma = &info->mti_attr;
+       struct obd_export *exp = info->mti_exp;
+       struct lu_nodemap *nodemap = NULL;
 
        LASSERT(ma->ma_valid & MA_INODE);
 
@@ -527,6 +527,11 @@ void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
                b->mbo_nlink = attr->la_nlink;
                b->mbo_valid |= OBD_MD_FLNLINK;
        }
+       if (attr->la_valid & (LA_UID|LA_GID)) {
+               nodemap = nodemap_get_from_exp(exp);
+               if (IS_ERR(nodemap))
+                       goto out;
+       }
        if (attr->la_valid & LA_UID) {
                b->mbo_uid = nodemap_map_id(nodemap, NODEMAP_UID,
                                            NODEMAP_FS_TO_CLIENT,
@@ -539,6 +544,7 @@ void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
                                            attr->la_gid);
                b->mbo_valid |= OBD_MD_FLGID;
        }
+
        b->mbo_mode = attr->la_mode;
        if (attr->la_valid & LA_MODE)
                b->mbo_valid |= OBD_MD_FLMODE;
@@ -588,6 +594,10 @@ void mdt_pack_attr2body(struct mdt_thread_info *info, struct mdt_body *b,
        if (fid != NULL && (b->mbo_valid & OBD_MD_FLSIZE))
                CDEBUG(D_VFSTRACE, DFID": returning size %llu\n",
                       PFID(fid), (unsigned long long)b->mbo_size);
+
+out:
+       if (!IS_ERR_OR_NULL(nodemap))
+               nodemap_putref(nodemap);
 }
 
 static inline int mdt_body_has_lov(const struct lu_attr *la,
@@ -915,7 +925,6 @@ static int mdt_getattr_internal(struct mdt_thread_info *info,
        struct mdt_body         *repbody;
        struct lu_buf           *buffer = &info->mti_buf;
        struct obd_export       *exp = info->mti_exp;
-       struct lu_nodemap       *nodemap = exp->exp_target_data.ted_nodemap;
        int                      rc;
        int                      is_root;
        ENTRY;
@@ -1122,8 +1131,14 @@ 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) &&
-                (reqbody->mbo_valid & OBD_MD_FLACL))
+                (reqbody->mbo_valid & OBD_MD_FLACL)) {
+               struct lu_nodemap *nodemap = nodemap_get_from_exp(exp);
+               if (IS_ERR(nodemap))
+                       RETURN(PTR_ERR(nodemap));
+
                rc = mdt_pack_acl2body(info, repbody, o, nodemap);
+               nodemap_putref(nodemap);
+       }
 #endif
 
 out:
@@ -2021,7 +2036,7 @@ static int mdt_quotactl(struct tgt_session_info *tsi)
        int                      id, rc;
        struct mdt_device       *mdt = mdt_exp2dev(exp);
        struct lu_device        *qmt = mdt->mdt_qmt_dev;
-       struct lu_nodemap       *nodemap = exp->exp_target_data.ted_nodemap;
+       struct lu_nodemap       *nodemap;
        ENTRY;
 
        oqctl = req_capsule_client_get(pill, &RMF_OBD_QUOTACTL);
@@ -2032,23 +2047,27 @@ static int mdt_quotactl(struct tgt_session_info *tsi)
        if (rc)
                RETURN(err_serious(rc));
 
+       nodemap = nodemap_get_from_exp(exp);
+       if (IS_ERR(nodemap))
+               RETURN(PTR_ERR(nodemap));
+
        switch (oqctl->qc_cmd) {
                /* master quotactl */
        case Q_SETINFO:
        case Q_SETQUOTA:
                if (!nodemap_can_setquota(nodemap))
-                       RETURN(-EPERM);
+                       GOTO(out_nodemap, rc = -EPERM);
        case Q_GETINFO:
        case Q_GETQUOTA:
                if (qmt == NULL)
-                       RETURN(-EOPNOTSUPP);
+                       GOTO(out_nodemap, rc = -EOPNOTSUPP);
                /* slave quotactl */
        case Q_GETOINFO:
        case Q_GETOQUOTA:
                break;
        default:
                CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
-               RETURN(-EFAULT);
+               GOTO(out_nodemap, rc = -EFAULT);
        }
 
        /* map uid/gid for remote client */
@@ -2060,7 +2079,7 @@ static int mdt_quotactl(struct tgt_session_info *tsi)
 
                if (unlikely(oqctl->qc_cmd != Q_GETQUOTA &&
                             oqctl->qc_cmd != Q_GETINFO))
-                       RETURN(-EPERM);
+                       GOTO(out_nodemap, rc = -EPERM);
 
                if (oqctl->qc_type == USRQUOTA)
                        id = lustre_idmap_lookup_uid(NULL, idmap, 0,
@@ -2069,11 +2088,11 @@ static int mdt_quotactl(struct tgt_session_info *tsi)
                        id = lustre_idmap_lookup_gid(NULL, idmap, 0,
                                                     oqctl->qc_id);
                else
-                       RETURN(-EINVAL);
+                       GOTO(out_nodemap, rc = -EINVAL);
 
                if (id == CFS_IDMAP_NOTFOUND) {
                        CDEBUG(D_QUOTA, "no mapping for id %u\n", oqctl->qc_id);
-                       RETURN(-EACCES);
+                       GOTO(out_nodemap, rc = -EACCES);
                }
        }
 
@@ -2086,7 +2105,7 @@ static int mdt_quotactl(struct tgt_session_info *tsi)
 
        repoqc = req_capsule_server_get(pill, &RMF_OBD_QUOTACTL);
        if (repoqc == NULL)
-               RETURN(err_serious(-EFAULT));
+               GOTO(out_nodemap, rc = err_serious(-EFAULT));
 
        if (oqctl->qc_id != id)
                swap(oqctl->qc_id, id);
@@ -2110,14 +2129,20 @@ static int mdt_quotactl(struct tgt_session_info *tsi)
 
        default:
                CERROR("Unsupported quotactl command: %d\n", oqctl->qc_cmd);
-               RETURN(-EFAULT);
+               GOTO(out_nodemap, rc = -EFAULT);
        }
 
        if (oqctl->qc_id != id)
                swap(oqctl->qc_id, id);
 
        *repoqc = *oqctl;
-       RETURN(rc);
+
+       EXIT;
+
+out_nodemap:
+       nodemap_putref(nodemap);
+
+       return rc;
 }
 
 /** clone llog ctxt from child (mdd)