Whamcloud - gitweb
LU-7890 lov: Ensure correct operation for large object sizes
[fs/lustre-release.git] / lustre / lov / lov_ea.c
index b98f924..e39acc3 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2014, Intel Corporation.
+ * Copyright (c) 2011, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -79,18 +79,20 @@ static int lsm_lmm_verify_common(struct lov_mds_md *lmm, int lmm_bytes,
        return 0;
 }
 
-struct lov_stripe_md *lsm_alloc_plain(__u16 stripe_count, int *size)
+struct lov_stripe_md *lsm_alloc_plain(u16 stripe_count)
 {
        struct lov_stripe_md *lsm;
        struct lov_oinfo     *loi;
-       int                   i, oinfo_ptrs_size;
+       size_t lsm_size;
+       size_t oinfo_ptrs_size;
+       int i;
 
        LASSERT(stripe_count <= LOV_MAX_STRIPE_COUNT);
 
        oinfo_ptrs_size = sizeof(struct lov_oinfo *) * stripe_count;
-       *size = sizeof(struct lov_stripe_md) + oinfo_ptrs_size;
+       lsm_size = sizeof(*lsm) + oinfo_ptrs_size;
 
-       OBD_ALLOC_LARGE(lsm, *size);
+       OBD_ALLOC_LARGE(lsm, lsm_size);
        if (!lsm)
                return NULL;
 
@@ -106,20 +108,22 @@ struct lov_stripe_md *lsm_alloc_plain(__u16 stripe_count, int *size)
 err:
        while (--i >= 0)
                OBD_SLAB_FREE(lsm->lsm_oinfo[i], lov_oinfo_slab, sizeof(*loi));
-       OBD_FREE_LARGE(lsm, *size);
+
+       OBD_FREE_LARGE(lsm, lsm_size);
+
        return NULL;
 }
 
 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
@@ -153,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;
 
@@ -177,31 +182,37 @@ static int lsm_unpackmd_common(struct lov_obd *lov,
                if (lov_oinfo_is_dummy(loi))
                        continue;
 
-               if (loi->loi_ost_idx >= lov->desc.ld_tgt_count) {
-                       CERROR("OST index %d more than OST count %d\n",
+               if (loi->loi_ost_idx >= lov->desc.ld_tgt_count &&
+                   !lov2obd(lov)->obd_process_conf) {
+                       CERROR("%s: OST index %d more than OST count %d\n",
+                              (char*)lov->desc.ld_uuid.uuid,
                               loi->loi_ost_idx, lov->desc.ld_tgt_count);
                        lov_dump_lmm_v1(D_WARNING, lmm);
                        return -EINVAL;
                }
 
-               if (!lov->lov_tgts[loi->loi_ost_idx]) {
-                       CERROR("OST index %d missing\n", loi->loi_ost_idx);
+               if (lov->lov_tgts[loi->loi_ost_idx] == NULL) {
+                       CERROR("%s: OST index %d missing\n",
+                              (char*)lov->desc.ld_uuid.uuid, loi->loi_ost_idx);
                        lov_dump_lmm_v1(D_WARNING, lmm);
-                       return -EINVAL;
+                       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;
 }