From b0aa1d588ca1e07ccdf2539033a99f5145cffc11 Mon Sep 17 00:00:00 2001 From: "John L. Hammond" Date: Mon, 22 Apr 2013 13:42:23 -0500 Subject: [PATCH] LU-3201 lmv: check result of lmv_find_target() In lmv_locate_mds() and lmv_iocontrol() check the result of lmv_find_target() using IS_ERR() before dereferencing it. In lmv_get_target() return ERR_PTR(-ENODEV) rather than NULL when the indicated MDS cannot be found among the members of lmv->tgts. In __lmv_fid_alloc() check the result of lmv_get_target() using IS_ERR(). Signed-off-by: John L. Hammond Change-Id: I8cfce869e4be329fd432a7b6a88f48fbc81d69dd Reviewed-on: http://review.whamcloud.com/6116 Tested-by: Hudson Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: wangdi --- lustre/lmv/lmv_internal.h | 3 ++- lustre/lmv/lmv_obd.c | 31 +++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lustre/lmv/lmv_internal.h b/lustre/lmv/lmv_internal.h index bef090c..04c092e 100644 --- a/lustre/lmv/lmv_internal.h +++ b/lustre/lmv/lmv_internal.h @@ -123,7 +123,8 @@ lmv_get_target(struct lmv_obd *lmv, mdsno_t mds) if (lmv->tgts[i]->ltd_idx == mds) return lmv->tgts[i]; } - return NULL; + + return ERR_PTR(-ENODEV); } static inline struct lmv_tgt_desc * diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index 15aa738..39982f0 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -943,7 +943,13 @@ static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp, struct lmv_tgt_desc *tgt1, *tgt2; tgt1 = lmv_find_target(lmv, &op_data->op_fid1); + if (IS_ERR(tgt1)) + RETURN(PTR_ERR(tgt1)); + tgt2 = lmv_find_target(lmv, &op_data->op_fid2); + if (IS_ERR(tgt2)) + RETURN(PTR_ERR(tgt2)); + if ((tgt1->ltd_exp == NULL) || (tgt2->ltd_exp == NULL)) RETURN(-EINVAL); @@ -1079,21 +1085,23 @@ static int lmv_placement_policy(struct obd_device *obd, } int __lmv_fid_alloc(struct lmv_obd *lmv, struct lu_fid *fid, - mdsno_t mds) + mdsno_t mds) { - struct lmv_tgt_desc *tgt; - int rc; - ENTRY; + struct lmv_tgt_desc *tgt; + int rc; + ENTRY; - tgt = lmv_get_target(lmv, mds); + tgt = lmv_get_target(lmv, mds); + if (IS_ERR(tgt)) + RETURN(PTR_ERR(tgt)); - /* - * New seq alloc and FLD setup should be atomic. Otherwise we may find - * on server that seq in new allocated fid is not yet known. - */ + /* + * New seq alloc and FLD setup should be atomic. Otherwise we may find + * on server that seq in new allocated fid is not yet known. + */ mutex_lock(&tgt->ltd_fid_mutex); - if (tgt == NULL || tgt->ltd_active == 0 || tgt->ltd_exp == NULL) + if (tgt->ltd_active == 0 || tgt->ltd_exp == NULL) GOTO(out, rc = -ENODEV); /* @@ -1491,6 +1499,9 @@ struct lmv_tgt_desc struct lmv_tgt_desc *tgt; tgt = lmv_find_target(lmv, fid); + if (IS_ERR(tgt)) + return tgt; + op_data->op_mds = tgt->ltd_idx; return tgt; -- 1.8.3.1