Whamcloud - gitweb
LU-3201 lmv: check result of lmv_find_target()
authorJohn L. Hammond <john.hammond@intel.com>
Mon, 22 Apr 2013 18:42:23 +0000 (13:42 -0500)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 25 Apr 2013 16:04:50 +0000 (12:04 -0400)
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 <john.hammond@intel.com>
Change-Id: I8cfce869e4be329fd432a7b6a88f48fbc81d69dd
Reviewed-on: http://review.whamcloud.com/6116
Tested-by: Hudson
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: wangdi <di.wang@intel.com>
lustre/lmv/lmv_internal.h
lustre/lmv/lmv_obd.c

index bef090c..04c092e 100644 (file)
@@ -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];
        }
                if (lmv->tgts[i]->ltd_idx == mds)
                        return lmv->tgts[i];
        }
-       return NULL;
+
+       return ERR_PTR(-ENODEV);
 }
 
 static inline struct lmv_tgt_desc *
 }
 
 static inline struct lmv_tgt_desc *
index 15aa738..39982f0 100644 (file)
@@ -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);
                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);
                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);
 
                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,
 }
 
 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);
 
        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);
 
         /*
                GOTO(out, rc = -ENODEV);
 
         /*
@@ -1491,6 +1499,9 @@ struct lmv_tgt_desc
        struct lmv_tgt_desc *tgt;
 
        tgt = lmv_find_target(lmv, fid);
        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;
        op_data->op_mds = tgt->ltd_idx;
 
        return tgt;