From 67d8e01d2455677606046f50bcf1b4a07316b804 Mon Sep 17 00:00:00 2001
From: bwzhou <bwzhou>
Date: Tue, 6 Nov 2007 10:02:59 +0000
Subject: [PATCH] Branch HEAD b=13933 i=adilger i=johann

Set an upper limit for stripe count
---
 lustre/include/lustre/lustre_idl.h |  1 +
 lustre/lov/lov_ea.c                |  2 +-
 lustre/lov/lov_pack.c              | 20 ++++++++++++++------
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/lustre/include/lustre/lustre_idl.h b/lustre/include/lustre/lustre_idl.h
index 5495b1108d..2a39b4820e 100644
--- a/lustre/include/lustre/lustre_idl.h
+++ b/lustre/include/lustre/lustre_idl.h
@@ -1462,6 +1462,7 @@ enum seq_op {
 
 #define LOV_MIN_STRIPE_SIZE 65536   /* maximum PAGE_SIZE (ia64), power of 2 */
 #define LOV_MAX_STRIPE_COUNT  160   /* until bug 4424 is fixed */
+#define LOV_V1_INSANE_STRIPE_COUNT 65532 /* maximum stripe count bz13933 */
 
 #define LOV_MAX_UUID_BUFFER_SIZE  8192
 /* The size of the buffer the lov/mdc reserves for the
diff --git a/lustre/lov/lov_ea.c b/lustre/lov/lov_ea.c
index 4a9f996f91..3c4ac5b127 100755
--- a/lustre/lov/lov_ea.c
+++ b/lustre/lov/lov_ea.c
@@ -51,7 +51,7 @@ static int lsm_lmm_verify_common(struct lov_mds_md *lmm, int lmm_bytes,
                                  int stripe_count)
 {
 
-        if (stripe_count == 0) {
+        if (stripe_count == 0 || stripe_count > LOV_V1_INSANE_STRIPE_COUNT) {
                 CERROR("bad stripe count %d\n", stripe_count);
                 lov_dump_lmm_v1(D_WARNING, lmm);
                 return -EINVAL;
diff --git a/lustre/lov/lov_pack.c b/lustre/lov/lov_pack.c
index c4cf95705c..b13a0674dd 100644
--- a/lustre/lov/lov_pack.c
+++ b/lustre/lov/lov_pack.c
@@ -48,12 +48,20 @@ void lov_dump_lmm_v1(int level, struct lov_mds_md_v1 *lmm)
         CDEBUG(level,"stripe_size %u, stripe_count %u\n",
                le32_to_cpu(lmm->lmm_stripe_size),
                le32_to_cpu(lmm->lmm_stripe_count));
-        for (i = 0, lod = lmm->lmm_objects;
-             i < (int)le32_to_cpu(lmm->lmm_stripe_count); i++, lod++)
-                CDEBUG(level, "stripe %u idx %u subobj "LPX64"/"LPX64"\n",
-                       i, le32_to_cpu(lod->l_ost_idx),
-                       le64_to_cpu(lod->l_object_gr),
-                       le64_to_cpu(lod->l_object_id));
+
+        if (le32_to_cpu(lmm->lmm_stripe_count) <= LOV_V1_INSANE_STRIPE_COUNT) {
+                for (i = 0, lod = lmm->lmm_objects;
+                     i < (int)le32_to_cpu(lmm->lmm_stripe_count); i++, lod++)
+                         CDEBUG(level,
+                                "stripe %u idx %u subobj "LPX64"/"LPX64"\n",
+                                i, le32_to_cpu(lod->l_ost_idx),
+                                le64_to_cpu(lod->l_object_gr),
+                                le64_to_cpu(lod->l_object_id));
+        } else {
+                CDEBUG(level, "bad stripe_count %u > max_stripe_count %u\n",
+                       le32_to_cpu(lmm->lmm_stripe_count),
+                       LOV_V1_INSANE_STRIPE_COUNT);
+        }
 }
 
 void lov_dump_lmm_join(int level, struct lov_mds_md_join *lmmj)
-- 
GitLab