Whamcloud - gitweb
LU-9611 lod: allow -1 for default stripe count/offset
[fs/lustre-release.git] / lustre / lod / lod_lov.c
index bc1b70d..43375f2 100644 (file)
@@ -789,6 +789,8 @@ static int lod_gen_component_ea(const struct lu_env *env,
                objs = &v3->lmm_objects[0];
        }
        stripecnt = lod_comp_entry_stripecnt(lo, lod_comp, is_dir);
+       if (!is_dir && lo->ldo_is_composite)
+               lod_comp_shrink_stripecount(lod_comp, &stripecnt);
 
        if (is_dir || lod_comp->llc_pattern & LOV_PATTERN_F_RELEASED)
                GOTO(done, rc = 0);
@@ -869,9 +871,9 @@ static __u32 lod_gen_component_id(struct lod_object *lo, int comp_idx)
 
        /* Layout generation wraps, need to check collisions. */
        start = id & LCME_ID_MASK;
-       end = (__u32)LCME_ID_MAX + 1;
+       end = LCME_ID_MAX;
 again:
-       for (id = start; id < end; id++) {
+       for (id = start; id <= end; id++) {
                for (i = 0; i < lo->ldo_comp_cnt; i++) {
                        lod_comp = &lo->ldo_comp_entries[i];
                        if (id == lod_comp->llc_id)
@@ -881,9 +883,10 @@ again:
                if (i == lo->ldo_comp_cnt)
                        return id;
        }
-       if (end == (__u32)LCME_ID_MAX + 1) {
-               start = 0;
-               end = lo->ldo_layout_gen & LCME_ID_MASK;
+       if (end == LCME_ID_MAX) {
+               start = 1;
+               end = min(lo->ldo_layout_gen & LCME_ID_MASK,
+                         (__u32)(LCME_ID_MAX - 1));
                goto again;
        }
 
@@ -1272,26 +1275,42 @@ int lod_parse_striping(const struct lu_env *env, struct lod_object *lo,
 
                /**
                 * If uninstantiated template component has valid l_ost_idx,
-                * then use has specified ost list for this component.
+                * then user has specified ost list for this component.
                 */
-               if (!lod_comp_inited(lod_comp) &&
-                   objs[0].l_ost_idx != (__u32)-1UL) {
-                       /**
-                        * load the user specified ost list, when this
-                        * component is instantiated later, it will be used
-                        * in lod_alloc_ost_list().
-                        */
-                       lod_comp->llc_ostlist.op_count = lod_comp->llc_stripenr;
-                       lod_comp->llc_ostlist.op_size =
+               if (!lod_comp_inited(lod_comp)) {
+                       if (objs[0].l_ost_idx != (__u32)-1UL) {
+                               /**
+                                * load the user specified ost list, when this
+                                * component is instantiated later, it will be
+                                * used in lod_alloc_ost_list().
+                                */
+                               lod_comp->llc_ostlist.op_count =
+                                       lod_comp->llc_stripenr;
+                               lod_comp->llc_ostlist.op_size =
                                        lod_comp->llc_stripenr * sizeof(__u32);
-                       OBD_ALLOC(lod_comp->llc_ostlist.op_array,
-                                 lod_comp->llc_ostlist.op_size);
-                       if (!lod_comp->llc_ostlist.op_array)
-                               GOTO(out, rc = -ENOMEM);
+                               OBD_ALLOC(lod_comp->llc_ostlist.op_array,
+                                         lod_comp->llc_ostlist.op_size);
+                               if (!lod_comp->llc_ostlist.op_array)
+                                       GOTO(out, rc = -ENOMEM);
 
-                       for (j = 0; j < lod_comp->llc_stripenr; j++)
-                               lod_comp->llc_ostlist.op_array[j] =
+                               for (j = 0; j < lod_comp->llc_stripenr; j++)
+                                       lod_comp->llc_ostlist.op_array[j] =
                                                le32_to_cpu(objs[j].l_ost_idx);
+
+                               /**
+                                * this component OST objects starts from the
+                                * first ost_idx, lod_alloc_ost_list() will
+                                * check this.
+                                */
+                               lod_comp->llc_stripe_offset = objs[0].l_ost_idx;
+                       } else {
+                               /**
+                                * for uninstantiated component,
+                                * lmm_layout_gen stores default stripe offset.
+                                */
+                               lod_comp->llc_stripe_offset =
+                                                       lmm->lmm_layout_gen;
+                       }
                }
 
                /* skip un-instantiated component object initialization */
@@ -1699,6 +1718,15 @@ int lod_verify_striping(struct lod_device *d, const struct lu_buf *buf,
        RETURN(rc);
 }
 
+/**
+ * set the default stripe size, if unset.
+ *
+ * \param[in,out] val  number of bytes per OST stripe
+ *
+ * The minimum stripe size is 64KB to ensure that a single stripe is an
+ * even multiple of a client PAGE_SIZE (IA64, PPC, etc).  Otherwise, it
+ * is difficult to split dirty pages across OSCs during writes.
+ */
 void lod_fix_desc_stripe_size(__u64 *val)
 {
        if (*val < LOV_MIN_STRIPE_SIZE) {
@@ -1715,12 +1743,30 @@ void lod_fix_desc_stripe_size(__u64 *val)
        }
 }
 
+/**
+ * set the filesystem default number of stripes, if unset.
+ *
+ * \param[in,out] val  number of stripes
+ *
+ * A value of "0" means "use the system-wide default stripe count", which
+ * has either been inherited by now, or falls back to 1 stripe per file.
+ * A value of "-1" (0xffffffff) means "stripe over all available OSTs",
+ * and is a valid value, so is left unchanged here.
+ */
 void lod_fix_desc_stripe_count(__u32 *val)
 {
        if (*val == 0)
                *val = 1;
 }
 
+/**
+ * set the filesystem default layout pattern
+ *
+ * \param[in,out] val  LOV_PATTERN_* layout
+ *
+ * A value of "0" means "use the system-wide default layout type", which
+ * has either been inherited by now, or falls back to plain RAID0 striping.
+ */
 void lod_fix_desc_pattern(__u32 *val)
 {
        /* from lov_setstripe */