+ struct obd_device *obd = exp->exp_obd;
+ struct lmv_obd *lmv = &obd->u.lmv;
+ struct lmv_tgt_desc *tgt;
+ int rc;
+
+ ENTRY;
+
+ tgt = lmv_fid2tgt(lmv, &op_data->op_fid1);
+ if (IS_ERR(tgt))
+ RETURN(PTR_ERR(tgt));
+
+ CDEBUG(D_INODE, "CLOSE "DFID"\n", PFID(&op_data->op_fid1));
+ rc = md_close(tgt->ltd_exp, op_data, mod, request);
+ RETURN(rc);
+}
+
+static struct lu_tgt_desc *lmv_locate_tgt_qos(struct lmv_obd *lmv, __u32 *mdt)
+{
+ struct lu_tgt_desc *tgt;
+ __u64 total_weight = 0;
+ __u64 cur_weight = 0;
+ __u64 rand;
+ int rc;
+
+ ENTRY;
+
+ if (!ltd_qos_is_usable(&lmv->lmv_mdt_descs))
+ RETURN(ERR_PTR(-EAGAIN));
+
+ down_write(&lmv->lmv_qos.lq_rw_sem);
+
+ if (!ltd_qos_is_usable(&lmv->lmv_mdt_descs))
+ GOTO(unlock, tgt = ERR_PTR(-EAGAIN));
+
+ rc = ltd_qos_penalties_calc(&lmv->lmv_mdt_descs);
+ if (rc)
+ GOTO(unlock, tgt = ERR_PTR(rc));
+
+ lmv_foreach_tgt(lmv, tgt) {
+ tgt->ltd_qos.ltq_usable = 0;
+ if (!tgt->ltd_exp || !tgt->ltd_active)
+ continue;
+
+ tgt->ltd_qos.ltq_usable = 1;
+ lu_tgt_qos_weight_calc(tgt);
+ total_weight += tgt->ltd_qos.ltq_weight;
+ }
+
+ rand = lu_prandom_u64_max(total_weight);
+
+ lmv_foreach_connected_tgt(lmv, tgt) {
+ if (!tgt->ltd_qos.ltq_usable)
+ continue;
+
+ cur_weight += tgt->ltd_qos.ltq_weight;
+ if (cur_weight < rand)
+ continue;
+
+ *mdt = tgt->ltd_index;
+ ltd_qos_update(&lmv->lmv_mdt_descs, tgt, &total_weight);
+ GOTO(unlock, rc = 0);
+ }
+
+ /* no proper target found */
+ GOTO(unlock, tgt = ERR_PTR(-EAGAIN));
+unlock:
+ up_write(&lmv->lmv_qos.lq_rw_sem);
+
+ return tgt;
+}
+
+static struct lu_tgt_desc *lmv_locate_tgt_rr(struct lmv_obd *lmv, __u32 *mdt)
+{
+ struct lu_tgt_desc *tgt;
+ int i;
+ int index;