Whamcloud - gitweb
LU-3161 lod: Added proper error handling instead of LASSERT 34/7234/9
authorGaurav Mahajan <gmahajan@ddn.com>
Fri, 26 Jul 2013 08:33:06 +0000 (14:03 +0530)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 21 Oct 2013 23:07:12 +0000 (23:07 +0000)
LASSERT are replaced with proper error handling in
lod_initialize_objects.

Signed-off-by: Gaurav Mahajan <gmahajan@ddn.com>
Change-Id: Ia8fbbb4956765835bf46b46b3a7addc99cb191fa
Reviewed-on: http://review.whamcloud.com/7234
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
lustre/lod/lod_lov.c

index 57c5023..5d74c88 100644 (file)
@@ -663,6 +663,30 @@ int lod_store_def_striping(const struct lu_env *env, struct dt_object *dt,
        RETURN(rc);
 }
 
        RETURN(rc);
 }
 
+static int validate_lod_and_idx(struct lod_device *md, int idx)
+{
+       if (unlikely(idx >= md->lod_ost_descs.ltd_tgts_size ||
+                    !cfs_bitmap_check(md->lod_ost_bitmap, idx))) {
+               CERROR("%s: bad idx: %d of %d\n", lod2obd(md)->obd_name, idx,
+                      md->lod_ost_descs.ltd_tgts_size);
+               return -EINVAL;
+       }
+
+       if (unlikely(OST_TGT(md, idx) == NULL)) {
+               CERROR("%s: bad lod_tgt_desc for idx: %d\n",
+                      lod2obd(md)->obd_name, idx);
+               return -EINVAL;
+       }
+
+       if (unlikely(OST_TGT(md, idx)->ltd_ost == NULL)) {
+               CERROR("%s: invalid lod device, for idx: %d\n",
+                      lod2obd(md)->obd_name , idx);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 /*
  * allocate array of objects pointers, find/create objects
  * stripenr and other fields should be initialized by this moment
 /*
  * allocate array of objects pointers, find/create objects
  * stripenr and other fields should be initialized by this moment
@@ -697,16 +721,14 @@ int lod_initialize_objects(const struct lu_env *env, struct lod_object *lo,
                        GOTO(out, rc);
                LASSERTF(fid_is_sane(&info->lti_fid), ""DFID" insane!\n",
                         PFID(&info->lti_fid));
                        GOTO(out, rc);
                LASSERTF(fid_is_sane(&info->lti_fid), ""DFID" insane!\n",
                         PFID(&info->lti_fid));
-               /*
-                * XXX: assertion is left for testing, to make
-                * sure we never process requests till configuration
-                * is completed. to be changed to -EINVAL
-                */
-
                lod_getref(&md->lod_ost_descs);
                lod_getref(&md->lod_ost_descs);
-               LASSERT(cfs_bitmap_check(md->lod_ost_bitmap, idx));
-               LASSERT(OST_TGT(md,idx));
-               LASSERTF(OST_TGT(md,idx)->ltd_ost, "idx %d\n", idx);
+
+               rc = validate_lod_and_idx(md, idx);
+               if (unlikely(rc != 0)) {
+                       lod_putref(md, &md->lod_ost_descs);
+                       GOTO(out, rc);
+               }
+
                nd = &OST_TGT(md,idx)->ltd_ost->dd_lu_dev;
                lod_putref(md, &md->lod_ost_descs);
 
                nd = &OST_TGT(md,idx)->ltd_ost->dd_lu_dev;
                lod_putref(md, &md->lod_ost_descs);
 
@@ -806,13 +828,8 @@ int lod_load_striping(const struct lu_env *env, struct lod_object *lo)
         */
        dt_write_lock(env, next, 0);
        /* already initialized? */
         */
        dt_write_lock(env, next, 0);
        /* already initialized? */
-       if (lo->ldo_stripe) {
-               int i;
-               /* check validity */
-               for (i = 0; i < lo->ldo_stripenr; i++)
-                       LASSERTF(lo->ldo_stripe[i], "stripe %d is NULL\n", i);
+       if (lo->ldo_stripe != NULL)
                GOTO(out, rc = 0);
                GOTO(out, rc = 0);
-       }
 
        if (!dt_object_exists(next))
                GOTO(out, rc = 0);
 
        if (!dt_object_exists(next))
                GOTO(out, rc = 0);
@@ -821,8 +838,6 @@ int lod_load_striping(const struct lu_env *env, struct lod_object *lo)
        if (!(lu_object_attr(lod2lu_obj(lo)) & S_IFREG))
                GOTO(out, rc = 0);
 
        if (!(lu_object_attr(lod2lu_obj(lo)) & S_IFREG))
                GOTO(out, rc = 0);
 
-       LASSERT(lo->ldo_stripenr == 0);
-
        rc = lod_get_lov_ea(env, lo);
        if (rc <= 0)
                GOTO(out, rc);
        rc = lod_get_lov_ea(env, lo);
        if (rc <= 0)
                GOTO(out, rc);