From a1c67eafa3eebd224a70cff5e9f26b71d8c695bb Mon Sep 17 00:00:00 2001
From: bobijam <bobijam>
Date: Mon, 28 Apr 2008 02:20:06 +0000
Subject: [PATCH] Branch HEAD b=14803 i=johann, adilger

Description: Don't update lov_desc members until making sure they are valid
Details    : When updating lov_desc members via proc fs, need fix their
             validities before doing the real update.
---
 lustre/ChangeLog          |  6 +++++
 lustre/lov/lov_internal.h |  4 ++++
 lustre/lov/lov_obd.c      | 46 +++++++++++++++++++++++++++------------
 lustre/lov/lproc_lov.c    |  7 +++---
 4 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/lustre/ChangeLog b/lustre/ChangeLog
index acf8c590eb..485a481d3b 100644
--- a/lustre/ChangeLog
+++ b/lustre/ChangeLog
@@ -12,6 +12,12 @@ tbd  Sun Microsystems, Inc.
        * RHEL 4 and RHEL 5/SLES 10 clients behaves differently on 'cd' to a
         removed cwd "./" (refer to Bugzilla 14399).
 
+Severity   : normal
+Bugzilla   : 14803
+Description: Don't update lov_desc members until making sure they are valid
+Details    : When updating lov_desc members via proc fs, need fix their
+             validities before doing the real update.
+
 Severity   : normal
 Bugzilla   : 15069
 Description: don't put request into delay list while invalidate in flight.
diff --git a/lustre/lov/lov_internal.h b/lustre/lov/lov_internal.h
index c8a97137f1..9981ed87db 100644
--- a/lustre/lov/lov_internal.h
+++ b/lustre/lov/lov_internal.h
@@ -227,6 +227,10 @@ int lov_fini_statfs_set(struct lov_request_set *set);
 
 /* lov_obd.c */
 void lov_fix_desc(struct lov_desc *desc);
+void lov_fix_desc_stripe_size(__u64 *val);
+void lov_fix_desc_stripe_count(__u32 *val);
+void lov_fix_desc_pattern(__u32 *val);
+void lov_fix_desc_qos_maxage(__u32 *val);
 int lov_get_stripecnt(struct lov_obd *lov, __u32 stripe_count);
 void lov_getref(struct obd_device *obd);
 void lov_putref(struct obd_device *obd);
diff --git a/lustre/lov/lov_obd.c b/lustre/lov/lov_obd.c
index dd9ab3839b..13215bc2d1 100644
--- a/lustre/lov/lov_obd.c
+++ b/lustre/lov/lov_obd.c
@@ -652,31 +652,49 @@ static void __lov_del_obd(struct obd_device *obd, __u32 index)
                 class_manual_cleanup(osc_obd);
 }
 
-void lov_fix_desc(struct lov_desc *desc)
+void lov_fix_desc_stripe_size(__u64 *val)
 {
-        if (desc->ld_default_stripe_size < PTLRPC_MAX_BRW_SIZE) {
+        if (*val < PTLRPC_MAX_BRW_SIZE) {
                 LCONSOLE_WARN("Increasing default stripe size to min %u\n",
                               PTLRPC_MAX_BRW_SIZE);
-                desc->ld_default_stripe_size = PTLRPC_MAX_BRW_SIZE;
-        } else if (desc->ld_default_stripe_size & (LOV_MIN_STRIPE_SIZE - 1)) {
-                desc->ld_default_stripe_size &= ~(LOV_MIN_STRIPE_SIZE - 1);
+                *val = PTLRPC_MAX_BRW_SIZE;
+        } else if (*val & (LOV_MIN_STRIPE_SIZE - 1)) {
+                *val &= ~(LOV_MIN_STRIPE_SIZE - 1);
                 LCONSOLE_WARN("Changing default stripe size to "LPU64" (a "
                               "multiple of %u)\n",
-                              desc->ld_default_stripe_size,LOV_MIN_STRIPE_SIZE);
+                              *val, LOV_MIN_STRIPE_SIZE);
         }
+}
 
-        if (desc->ld_default_stripe_count == 0)
-                desc->ld_default_stripe_count = 1;
+void lov_fix_desc_stripe_count(__u32 *val)
+{
+        if (*val == 0)
+                *val = 1;
+}
 
+void lov_fix_desc_pattern(__u32 *val)
+{
         /* from lov_setstripe */
-        if ((desc->ld_pattern != 0) &&
-            (desc->ld_pattern != LOV_PATTERN_RAID0)) {
-                LCONSOLE_WARN("Unknown stripe pattern: %#x\n",desc->ld_pattern);
-                desc->ld_pattern = 0;
+        if ((*val != 0) && (*val != LOV_PATTERN_RAID0)) {
+                LCONSOLE_WARN("Unknown stripe pattern: %#x\n", *val);
+                *val = 0;
         }
+}
 
-        if (desc->ld_qos_maxage == 0)
-                desc->ld_qos_maxage = QOS_DEFAULT_MAXAGE;
+void lov_fix_desc_qos_maxage(__u32 *val)
+{
+        /* fix qos_maxage */
+        if (*val == 0)
+                *val = QOS_DEFAULT_MAXAGE;
+}
+
+void lov_fix_desc(struct lov_desc *desc)
+{
+        lov_fix_desc_stripe_size(&desc->ld_default_stripe_size);
+        lov_fix_desc_stripe_count(&desc->ld_default_stripe_count);
+        lov_fix_desc_pattern(&desc->ld_pattern);
+        lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
+        lov_fix_desc_qos_maxage(&desc->ld_qos_maxage);
 }
 
 static int lov_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
diff --git a/lustre/lov/lproc_lov.c b/lustre/lov/lproc_lov.c
index 4cf90c8610..d95b1f0d93 100644
--- a/lustre/lov/lproc_lov.c
+++ b/lustre/lov/lproc_lov.c
@@ -58,8 +58,8 @@ static int lov_wr_stripesize(struct file *file, const char *buffer,
         if (rc)
                 return rc;
 
+        lov_fix_desc_stripe_size(&val);
         desc->ld_default_stripe_size = val;
-        lov_fix_desc(desc);
         return count;
 }
 
@@ -90,7 +90,6 @@ static int lov_wr_stripeoffset(struct file *file, const char *buffer,
                 return rc;
 
         desc->ld_default_stripe_offset = val;
-        lov_fix_desc(desc);
         return count;
 }
 
@@ -119,8 +118,8 @@ static int lov_wr_stripetype(struct file *file, const char *buffer,
         if (rc)
                 return rc;
 
+        lov_fix_desc_pattern(&val);
         desc->ld_pattern = val;
-        lov_fix_desc(desc);
         return count;
 }
 
@@ -150,8 +149,8 @@ static int lov_wr_stripecount(struct file *file, const char *buffer,
         if (rc)
                 return rc;
 
+        lov_fix_desc_stripe_count(&val);
         desc->ld_default_stripe_count = val;
-        lov_fix_desc(desc);
         return count;
 }
 
-- 
GitLab