Whamcloud - gitweb
LU-7890 lov: Ensure correct operation for large object sizes
[fs/lustre-release.git] / lustre / lov / lov_ea.c
index d4d2262..e39acc3 100644 (file)
@@ -116,14 +116,14 @@ err:
 
 void lsm_free_plain(struct lov_stripe_md *lsm)
 {
-        __u16 stripe_count = lsm->lsm_stripe_count;
-        int i;
-
-        for (i = 0; i < stripe_count; i++)
-                OBD_SLAB_FREE(lsm->lsm_oinfo[i], lov_oinfo_slab,
-                              sizeof(struct lov_oinfo));
-        OBD_FREE_LARGE(lsm, sizeof(struct lov_stripe_md) +
-                       stripe_count * sizeof(struct lov_oinfo *));
+       __u16 stripe_count = lsm->lsm_stripe_count;
+       int i;
+
+       for (i = 0; i < stripe_count; i++)
+               OBD_SLAB_FREE(lsm->lsm_oinfo[i], lov_oinfo_slab,
+                             sizeof(struct lov_oinfo));
+       OBD_FREE_LARGE(lsm, sizeof(struct lov_stripe_md) +
+                      stripe_count * sizeof(struct lov_oinfo *));
 }
 
 /* Find minimum stripe maxbytes value.  For inactive or
@@ -157,7 +157,8 @@ static int lsm_unpackmd_common(struct lov_obd *lov,
                               struct lov_ost_data_v1 *objects)
 {
        struct lov_oinfo *loi;
-       loff_t stripe_maxbytes = LLONG_MAX;
+       loff_t min_stripe_maxbytes = 0;
+       loff_t lov_bytes;
        unsigned int stripe_count;
        unsigned int i;
 
@@ -197,18 +198,21 @@ static int lsm_unpackmd_common(struct lov_obd *lov,
                        continue;
                }
 
-               stripe_maxbytes = min_t(loff_t, stripe_maxbytes,
-                                       lov_tgt_maxbytes(
-                                       lov->lov_tgts[loi->loi_ost_idx]));
+               lov_bytes = lov_tgt_maxbytes(lov->lov_tgts[loi->loi_ost_idx]);
+               if (min_stripe_maxbytes == 0 || lov_bytes < min_stripe_maxbytes)
+                       min_stripe_maxbytes = lov_bytes;
        }
 
-       if (stripe_maxbytes == LLONG_MAX)
-               stripe_maxbytes = LUSTRE_EXT3_STRIPE_MAXBYTES;
+       if (min_stripe_maxbytes == 0)
+               min_stripe_maxbytes = LUSTRE_EXT3_STRIPE_MAXBYTES;
+
+       stripe_count = lsm->lsm_stripe_count ?: lov->desc.ld_tgt_count;
+       lov_bytes = min_stripe_maxbytes * stripe_count;
 
-       if (lsm->lsm_stripe_count == 0)
-               lsm->lsm_maxbytes = stripe_maxbytes * lov->desc.ld_tgt_count;
+       if (lov_bytes < min_stripe_maxbytes) /* handle overflow */
+               lsm->lsm_maxbytes = MAX_LFS_FILESIZE;
        else
-               lsm->lsm_maxbytes = stripe_maxbytes * lsm->lsm_stripe_count;
+               lsm->lsm_maxbytes = lov_bytes;
 
        return 0;
 }