Whamcloud - gitweb
LU-601 mdd: Fix transaction credits
[fs/lustre-release.git] / lustre / lov / lov_ea.c
index 4785944..25017a2 100755 (executable)
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  */
 /*
+ * Copyright (c) 2011 Whamcloud, Inc.
+ */
+/*
  * This file is part of Lustre, http://www.lustre.org/
  * Lustre is a trademark of Sun Microsystems, Inc.
  *
@@ -105,7 +108,7 @@ struct lov_stripe_md *lsm_alloc_plain(int stripe_count, int *size)
         oinfo_ptrs_size = sizeof(struct lov_oinfo *) * stripe_count;
         *size = sizeof(struct lov_stripe_md) + oinfo_ptrs_size;
 
-        OBD_ALLOC(lsm, *size);
+        OBD_ALLOC_LARGE(lsm, *size);
         if (!lsm)
                 return NULL;;
 
@@ -122,7 +125,7 @@ struct lov_stripe_md *lsm_alloc_plain(int stripe_count, int *size)
 err:
         while (--i >= 0)
                 OBD_SLAB_FREE(lsm->lsm_oinfo[i], lov_oinfo_slab, sizeof(*loi));
-        OBD_FREE(lsm, *size);
+        OBD_FREE_LARGE(lsm, *size);
         return NULL;
 }
 
@@ -134,8 +137,8 @@ void lsm_free_plain(struct lov_stripe_md *lsm)
         for (i = 0; i < stripe_count; i++)
                 OBD_SLAB_FREE(lsm->lsm_oinfo[i], lov_oinfo_slab,
                               sizeof(struct lov_oinfo));
-        OBD_FREE(lsm, sizeof(struct lov_stripe_md) +
-                 stripe_count * sizeof(struct lov_oinfo *));
+        OBD_FREE_LARGE(lsm, sizeof(struct lov_stripe_md) +
+                       stripe_count * sizeof(struct lov_oinfo *));
 }
 
 static void lsm_unpackmd_common(struct lov_stripe_md *lsm,
@@ -174,6 +177,29 @@ static int lsm_destroy_plain(struct lov_stripe_md *lsm, struct obdo *oa,
         return 0;
 }
 
+/* Find minimum stripe maxbytes value.  For inactive or
+ * reconnecting targets use LUSTRE_STRIPE_MAXBYTES. */
+static void lov_tgt_maxbytes(struct lov_tgt_desc *tgt, __u64 *stripe_maxbytes)
+{
+        struct obd_import *imp = tgt->ltd_obd->u.cli.cl_import;
+
+        if (imp == NULL || !tgt->ltd_active) {
+                *stripe_maxbytes = LUSTRE_STRIPE_MAXBYTES;
+                return;
+        }
+
+        cfs_spin_lock(&imp->imp_lock);
+        if (imp->imp_state == LUSTRE_IMP_FULL &&
+           (imp->imp_connect_data.ocd_connect_flags & OBD_CONNECT_MAXBYTES) &&
+           imp->imp_connect_data.ocd_maxbytes > 0) {
+                if (*stripe_maxbytes > imp->imp_connect_data.ocd_maxbytes)
+                        *stripe_maxbytes = imp->imp_connect_data.ocd_maxbytes;
+        } else {
+                *stripe_maxbytes = LUSTRE_STRIPE_MAXBYTES;
+        }
+        cfs_spin_unlock(&imp->imp_lock);
+}
+
 static int lsm_lmm_verify_v1(struct lov_mds_md_v1 *lmm, int lmm_bytes,
                              int *stripe_count)
 {
@@ -200,6 +226,7 @@ int lsm_unpackmd_v1(struct lov_obd *lov, struct lov_stripe_md *lsm,
 {
         struct lov_oinfo *loi;
         int i;
+        __u64 stripe_maxbytes = OBD_OBJECT_EOF;
 
         lsm_unpackmd_common(lsm, lmm);
 
@@ -221,8 +248,13 @@ int lsm_unpackmd_v1(struct lov_obd *lov, struct lov_stripe_md *lsm,
                         lov_dump_lmm_v1(D_WARNING, lmm);
                         return -EINVAL;
                 }
+                /* calculate the minimum stripe max bytes */
+                lov_tgt_maxbytes(lov->lov_tgts[loi->loi_ost_idx],
+                                 &stripe_maxbytes);
         }
 
+        lsm->lsm_maxbytes = stripe_maxbytes * lsm->lsm_stripe_count;
+
         return 0;
 }
 
@@ -267,6 +299,7 @@ int lsm_unpackmd_v3(struct lov_obd *lov, struct lov_stripe_md *lsm,
         struct lov_mds_md_v3 *lmm;
         struct lov_oinfo *loi;
         int i;
+        __u64 stripe_maxbytes = OBD_OBJECT_EOF;
 
         lmm = (struct lov_mds_md_v3 *)lmmv1;
 
@@ -291,8 +324,13 @@ int lsm_unpackmd_v3(struct lov_obd *lov, struct lov_stripe_md *lsm,
                         lov_dump_lmm_v3(D_WARNING, lmm);
                         return -EINVAL;
                 }
+                /* calculate the minimum stripe max bytes */
+                lov_tgt_maxbytes(lov->lov_tgts[loi->loi_ost_idx],
+                                 &stripe_maxbytes);
         }
 
+        lsm->lsm_maxbytes = stripe_maxbytes * lsm->lsm_stripe_count;
+
         return 0;
 }