Whamcloud - gitweb
LU-12635 build: Support for gcc -Wimplicit-fallthrough
[fs/lustre-release.git] / lustre / lod / lod_qos.c
index 934d6bc..739720f 100644 (file)
@@ -38,6 +38,8 @@
 #define DEBUG_SUBSYSTEM S_LOV
 
 #include <asm/div64.h>
+#include <linux/random.h>
+
 #include <libcfs/libcfs.h>
 #include <uapi/linux/lustre/lustre_idl.h>
 #include <lustre_swab.h>
                       OST_TGT(lod,i)->ltd_statfs.os_bsize)
 
 /**
- * Add a new target to Quality of Service (QoS) target table.
- *
- * Add a new OST target to the structure representing an OSS. Resort the list
- * of known OSSs by the number of OSTs attached to each OSS. The OSS list is
- * protected internally and no external locking is required.
- *
- * \param[in] lod              LOD device
- * \param[in] ost_desc         OST description
- *
- * \retval 0                   on success
- * \retval -ENOMEM             on error
- */
-int qos_add_tgt(struct lod_device *lod, struct lod_tgt_desc *ost_desc)
-{
-       struct lod_qos_oss *oss = NULL, *temposs;
-       struct obd_export  *exp = ost_desc->ltd_exp;
-       int                 rc = 0, found = 0;
-       struct list_head   *list;
-       __u32 id = 0;
-       ENTRY;
-
-       down_write(&lod->lod_qos.lq_rw_sem);
-       /*
-        * a bit hacky approach to learn NID of corresponding connection
-        * but there is no official API to access information like this
-        * with OSD API.
-        */
-       list_for_each_entry(oss, &lod->lod_qos.lq_oss_list, lqo_oss_list) {
-               if (obd_uuid_equals(&oss->lqo_uuid,
-                                   &exp->exp_connection->c_remote_uuid)) {
-                       found++;
-                       break;
-               }
-               if (oss->lqo_id > id)
-                       id = oss->lqo_id;
-       }
-
-       if (!found) {
-               OBD_ALLOC_PTR(oss);
-               if (!oss)
-                       GOTO(out, rc = -ENOMEM);
-               memcpy(&oss->lqo_uuid, &exp->exp_connection->c_remote_uuid,
-                      sizeof(oss->lqo_uuid));
-               ++id;
-               oss->lqo_id = id;
-       } else {
-               /* Assume we have to move this one */
-               list_del(&oss->lqo_oss_list);
-       }
-
-       oss->lqo_ost_count++;
-       ost_desc->ltd_qos.ltq_oss = oss;
-
-       CDEBUG(D_QOS, "add tgt %s to OSS %s (%d OSTs)\n",
-              obd_uuid2str(&ost_desc->ltd_uuid), obd_uuid2str(&oss->lqo_uuid),
-              oss->lqo_ost_count);
-
-       /* Add sorted by # of OSTs.  Find the first entry that we're
-          bigger than... */
-       list = &lod->lod_qos.lq_oss_list;
-       list_for_each_entry(temposs, list, lqo_oss_list) {
-               if (oss->lqo_ost_count > temposs->lqo_ost_count)
-                       break;
-       }
-       /* ...and add before it.  If we're the first or smallest, temposs
-          points to the list head, and we add to the end. */
-       list_add_tail(&oss->lqo_oss_list, &temposs->lqo_oss_list);
-
-       lod->lod_qos.lq_dirty = 1;
-       lod->lod_qos.lq_rr.lqr_dirty = 1;
-
-out:
-       up_write(&lod->lod_qos.lq_rw_sem);
-       RETURN(rc);
-}
-
-/**
- * Remove OST target from QoS table.
- *
- * Removes given OST target from QoS table and releases related OSS structure
- * if no OSTs remain on the OSS.
- *
- * \param[in] lod              LOD device
- * \param[in] ost_desc         OST description
- *
- * \retval 0                   on success
- * \retval -ENOENT             if no OSS was found
- */
-int qos_del_tgt(struct lod_device *lod, struct lod_tgt_desc *ost_desc)
-{
-       struct lod_qos_oss *oss;
-       int                 rc = 0;
-       ENTRY;
-
-       down_write(&lod->lod_qos.lq_rw_sem);
-       oss = ost_desc->ltd_qos.ltq_oss;
-       if (!oss)
-               GOTO(out, rc = -ENOENT);
-
-       oss->lqo_ost_count--;
-       if (oss->lqo_ost_count == 0) {
-               CDEBUG(D_QOS, "removing OSS %s\n",
-                      obd_uuid2str(&oss->lqo_uuid));
-               list_del(&oss->lqo_oss_list);
-               ost_desc->ltd_qos.ltq_oss = NULL;
-               OBD_FREE_PTR(oss);
-       }
-
-       lod->lod_qos.lq_dirty = 1;
-       lod->lod_qos.lq_rr.lqr_dirty = 1;
-out:
-       up_write(&lod->lod_qos.lq_rw_sem);
-       RETURN(rc);
-}
-
-/**
  * Check whether the target is available for new OST objects.
  *
  * Request statfs data from the given target and verify it's active and not
@@ -324,12 +210,13 @@ out:
  */
 static int lod_qos_calc_ppo(struct lod_device *lod)
 {
-       struct lod_qos_oss *oss;
-       __u64               ba_max, ba_min, temp;
-       __u32               num_active;
-       unsigned int        i;
-       int                 rc, prio_wide;
-       time64_t            now, age;
+       struct lu_svr_qos *oss;
+       __u64 ba_max, ba_min, temp;
+       __u32 num_active;
+       unsigned int i;
+       int rc, prio_wide;
+       time64_t now, age;
+
        ENTRY;
 
        if (!lod->lod_qos.lq_dirty)
@@ -340,9 +227,9 @@ static int lod_qos_calc_ppo(struct lod_device *lod)
                GOTO(out, rc = -EAGAIN);
 
        /* find bavail on each OSS */
-       list_for_each_entry(oss, &lod->lod_qos.lq_oss_list, lqo_oss_list)
-                           oss->lqo_bavail = 0;
-       lod->lod_qos.lq_active_oss_count = 0;
+       list_for_each_entry(oss, &lod->lod_qos.lq_svr_list, lsq_svr_list)
+               oss->lsq_bavail = 0;
+       lod->lod_qos.lq_active_svr_count = 0;
 
        /*
         * How badly user wants to select OSTs "widely" (not recently chosen
@@ -366,9 +253,9 @@ static int lod_qos_calc_ppo(struct lod_device *lod)
                ba_max = max(temp, ba_max);
 
                /* Count the number of usable OSS's */
-               if (OST_TGT(lod,i)->ltd_qos.ltq_oss->lqo_bavail == 0)
-                       lod->lod_qos.lq_active_oss_count++;
-               OST_TGT(lod,i)->ltd_qos.ltq_oss->lqo_bavail += temp;
+               if (OST_TGT(lod, i)->ltd_qos.ltq_svr->lsq_bavail == 0)
+                       lod->lod_qos.lq_active_svr_count++;
+               OST_TGT(lod, i)->ltd_qos.ltq_svr->lsq_bavail += temp;
 
                /* per-OST penalty is prio * TGT_bavail / (num_ost - 1) / 2 */
                temp >>= 1;
@@ -386,7 +273,7 @@ static int lod_qos_calc_ppo(struct lod_device *lod)
                                (age / lod->lod_desc.ld_qos_maxage);
        }
 
-       num_active = lod->lod_qos.lq_active_oss_count - 1;
+       num_active = lod->lod_qos.lq_active_svr_count - 1;
        if (num_active < 1) {
                /* If there's only 1 OSS, we can't penalize it, so instead
                   we have to double the OST penalty */
@@ -396,18 +283,18 @@ static int lod_qos_calc_ppo(struct lod_device *lod)
        }
 
        /* Per-OSS penalty is prio * oss_avail / oss_osts / (num_oss - 1) / 2 */
-       list_for_each_entry(oss, &lod->lod_qos.lq_oss_list, lqo_oss_list) {
-               temp = oss->lqo_bavail >> 1;
-               do_div(temp, oss->lqo_ost_count * num_active);
-               oss->lqo_penalty_per_obj = (temp * prio_wide) >> 8;
+       list_for_each_entry(oss, &lod->lod_qos.lq_svr_list, lsq_svr_list) {
+               temp = oss->lsq_bavail >> 1;
+               do_div(temp, oss->lsq_tgt_count * num_active);
+               oss->lsq_penalty_per_obj = (temp * prio_wide) >> 8;
 
-               age = (now - oss->lqo_used) >> 3;
+               age = (now - oss->lsq_used) >> 3;
                if (lod->lod_qos.lq_reset ||
                    age > 32 * lod->lod_desc.ld_qos_maxage)
-                       oss->lqo_penalty = 0;
+                       oss->lsq_penalty = 0;
                else if (age > lod->lod_desc.ld_qos_maxage)
                        /* Decay OSS penalty. */
-                       oss->lqo_penalty >>= age / lod->lod_desc.ld_qos_maxage;
+                       oss->lsq_penalty >>= age / lod->lod_desc.ld_qos_maxage;
        }
 
        lod->lod_qos.lq_dirty = 0;
@@ -447,12 +334,12 @@ static int lod_qos_calc_weight(struct lod_device *lod, int i)
        __u64 temp, temp2;
 
        temp = TGT_BAVAIL(i);
-       temp2 = OST_TGT(lod,i)->ltd_qos.ltq_penalty +
-               OST_TGT(lod,i)->ltd_qos.ltq_oss->lqo_penalty;
+       temp2 = OST_TGT(lod, i)->ltd_qos.ltq_penalty +
+               OST_TGT(lod, i)->ltd_qos.ltq_svr->lsq_penalty;
        if (temp < temp2)
-               OST_TGT(lod,i)->ltd_qos.ltq_weight = 0;
+               OST_TGT(lod, i)->ltd_qos.ltq_weight = 0;
        else
-               OST_TGT(lod,i)->ltd_qos.ltq_weight = temp - temp2;
+               OST_TGT(lod, i)->ltd_qos.ltq_weight = temp - temp2;
        return 0;
 }
 
@@ -474,7 +361,7 @@ static int lod_qos_used(struct lod_device *lod, struct ost_pool *osts,
                        __u32 index, __u64 *total_wt)
 {
        struct lod_tgt_desc *ost;
-       struct lod_qos_oss  *oss;
+       struct lu_svr_qos  *oss;
        unsigned int j;
        ENTRY;
 
@@ -484,28 +371,28 @@ static int lod_qos_used(struct lod_device *lod, struct ost_pool *osts,
        /* Don't allocate on this devuce anymore, until the next alloc_qos */
        ost->ltd_qos.ltq_usable = 0;
 
-       oss = ost->ltd_qos.ltq_oss;
+       oss = ost->ltd_qos.ltq_svr;
 
        /* Decay old penalty by half (we're adding max penalty, and don't
           want it to run away.) */
        ost->ltd_qos.ltq_penalty >>= 1;
-       oss->lqo_penalty >>= 1;
+       oss->lsq_penalty >>= 1;
 
        /* mark the OSS and OST as recently used */
-       ost->ltd_qos.ltq_used = oss->lqo_used = ktime_get_real_seconds();
+       ost->ltd_qos.ltq_used = oss->lsq_used = ktime_get_real_seconds();
 
        /* Set max penalties for this OST and OSS */
        ost->ltd_qos.ltq_penalty +=
                ost->ltd_qos.ltq_penalty_per_obj * lod->lod_ostnr;
-       oss->lqo_penalty += oss->lqo_penalty_per_obj *
-               lod->lod_qos.lq_active_oss_count;
+       oss->lsq_penalty += oss->lsq_penalty_per_obj *
+               lod->lod_qos.lq_active_svr_count;
 
        /* Decrease all OSS penalties */
-       list_for_each_entry(oss, &lod->lod_qos.lq_oss_list, lqo_oss_list) {
-               if (oss->lqo_penalty < oss->lqo_penalty_per_obj)
-                       oss->lqo_penalty = 0;
+       list_for_each_entry(oss, &lod->lod_qos.lq_svr_list, lsq_svr_list) {
+               if (oss->lsq_penalty < oss->lsq_penalty_per_obj)
+                       oss->lsq_penalty = 0;
                else
-                       oss->lqo_penalty -= oss->lqo_penalty_per_obj;
+                       oss->lsq_penalty -= oss->lsq_penalty_per_obj;
        }
 
        *total_wt = 0;
@@ -539,21 +426,14 @@ static int lod_qos_used(struct lod_device *lod, struct ost_pool *osts,
                          i, ost->ltd_qos.ltq_usable, TGT_BAVAIL(i) >> 10,
                          ost->ltd_qos.ltq_penalty_per_obj >> 10,
                          ost->ltd_qos.ltq_penalty >> 10,
-                         ost->ltd_qos.ltq_oss->lqo_penalty_per_obj >> 10,
-                         ost->ltd_qos.ltq_oss->lqo_penalty >> 10,
+                         ost->ltd_qos.ltq_svr->lsq_penalty_per_obj >> 10,
+                         ost->ltd_qos.ltq_svr->lsq_penalty >> 10,
                          ost->ltd_qos.ltq_weight >> 10);
        }
 
        RETURN(0);
 }
 
-void lod_qos_rr_init(struct lod_qos_rr *lqr)
-{
-       spin_lock_init(&lqr->lqr_alloc);
-       lqr->lqr_dirty = 1;
-}
-
-
 #define LOV_QOS_EMPTY ((__u32)-1)
 
 /**
@@ -573,9 +453,9 @@ void lod_qos_rr_init(struct lod_qos_rr *lqr)
  * \retval -ENOMEM     fails to allocate the array
  */
 static int lod_qos_calc_rr(struct lod_device *lod, struct ost_pool *src_pool,
-                          struct lod_qos_rr *lqr)
+                          struct lu_qos_rr *lqr)
 {
-       struct lod_qos_oss  *oss;
+       struct lu_svr_qos  *oss;
        struct lod_tgt_desc *ost;
        unsigned placed, real_count;
        unsigned int i;
@@ -617,7 +497,7 @@ static int lod_qos_calc_rr(struct lod_device *lod, struct ost_pool *src_pool,
 
        /* Place all the OSTs from 1 OSS at the same time. */
        placed = 0;
-       list_for_each_entry(oss, &lod->lod_qos.lq_oss_list, lqo_oss_list) {
+       list_for_each_entry(oss, &lod->lod_qos.lq_svr_list, lsq_svr_list) {
                int j = 0;
 
                for (i = 0; i < lqr->lqr_pool.op_count; i++) {
@@ -629,11 +509,11 @@ static int lod_qos_calc_rr(struct lod_device *lod, struct ost_pool *src_pool,
 
                        ost = OST_TGT(lod,src_pool->op_array[i]);
                        LASSERT(ost && ost->ltd_ost);
-                       if (ost->ltd_qos.ltq_oss != oss)
+                       if (ost->ltd_qos.ltq_svr != oss)
                                continue;
 
                        /* Evenly space these OSTs across arrayspace */
-                       next = j * lqr->lqr_pool.op_count / oss->lqo_ost_count;
+                       next = j * lqr->lqr_pool.op_count / oss->lsq_tgt_count;
                        while (lqr->lqr_pool.op_array[next] != LOV_QOS_EMPTY)
                                next = (next + 1) % lqr->lqr_pool.op_count;
 
@@ -894,7 +774,7 @@ static inline bool lod_should_avoid_ost(struct lod_object *lo,
 {
        struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
        struct lod_tgt_desc *ost = OST_TGT(lod, index);
-       struct lod_qos_oss *lqo = ost->ltd_qos.ltq_oss;
+       struct lu_svr_qos *lsq = ost->ltd_qos.ltq_svr;
        bool used = false;
        int i;
 
@@ -913,7 +793,7 @@ static inline bool lod_should_avoid_ost(struct lod_object *lo,
 
        /* check OSS use */
        for (i = 0; i < lag->lag_oaa_count; i++) {
-               if (lag->lag_oss_avoid_array[i] == lqo->lqo_id) {
+               if (lag->lag_oss_avoid_array[i] == lsq->lsq_id) {
                        used = true;
                        break;
                }
@@ -936,11 +816,13 @@ static inline bool lod_should_avoid_ost(struct lod_object *lo,
 
 static int lod_check_and_reserve_ost(const struct lu_env *env,
                                     struct lod_object *lo,
+                                    struct lod_layout_component *lod_comp,
                                     struct obd_statfs *sfs, __u32 ost_idx,
                                     __u32 speed, __u32 *s_idx,
                                     struct dt_object **stripe,
                                     __u32 *ost_indices,
-                                    struct thandle *th)
+                                    struct thandle *th,
+                                    bool *overstriped)
 {
        struct lod_device *lod = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
        struct lod_avoid_guide *lag = &lod_env_info(env)->lti_avoid;
@@ -989,11 +871,14 @@ static int lod_check_and_reserve_ost(const struct lu_env *env,
                          "component\n", speed, ost_idx);
                RETURN(rc);
        }
-       /*
-        * do not put >1 objects on a single OST
-        */
-       if (lod_qos_is_ost_used(env, ost_idx, stripe_idx))
-               RETURN(rc);
+
+       /* do not put >1 objects on a single OST, except for overstriping */
+       if (lod_qos_is_ost_used(env, ost_idx, stripe_idx)) {
+               if (lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)
+                       *overstriped = true;
+               else
+                       RETURN(rc);
+       }
 
        o = lod_qos_declare_object_on(env, lod, ost_idx, th);
        if (IS_ERR(o)) {
@@ -1052,12 +937,14 @@ static int lod_alloc_rr(const struct lu_env *env, struct lod_object *lo,
        struct obd_statfs *sfs = &lod_env_info(env)->lti_osfs;
        struct pool_desc  *pool = NULL;
        struct ost_pool   *osts;
-       struct lod_qos_rr *lqr;
+       struct lu_qos_rr *lqr;
        unsigned int    i, array_idx;
        __u32 ost_start_idx_temp;
        __u32 stripe_idx = 0;
        __u32 stripe_count, stripe_count_min, ost_idx;
        int rc, speed = 0, ost_connecting = 0;
+       int stripes_per_ost = 1;
+       bool overstriped = false;
        ENTRY;
 
        LASSERT(lo->ldo_comp_cnt > comp_idx && lo->ldo_comp_entries != NULL);
@@ -1088,7 +975,7 @@ static int lod_alloc_rr(const struct lu_env *env, struct lod_object *lo,
        down_read(&m->lod_qos.lq_rw_sem);
        spin_lock(&lqr->lqr_alloc);
        if (--lqr->lqr_start_count <= 0) {
-               lqr->lqr_start_idx = cfs_rand() % osts->op_count;
+               lqr->lqr_start_idx = prandom_u32_max(osts->op_count);
                lqr->lqr_start_count =
                        (LOV_CREATE_RESEED_MIN / max(osts->op_count, 1U) +
                         LOV_CREATE_RESEED_MULT) * max(osts->op_count, 1U);
@@ -1111,7 +998,12 @@ repeat_find:
                  stripe_count, lqr->lqr_start_idx, lqr->lqr_start_count,
                  lqr->lqr_offset_idx, osts->op_count, osts->op_count);
 
-       for (i = 0; i < osts->op_count && stripe_idx < stripe_count; i++) {
+       if (lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)
+               stripes_per_ost =
+                       (lod_comp->llc_stripe_count - 1)/osts->op_count + 1;
+
+       for (i = 0; i < osts->op_count * stripes_per_ost
+            && stripe_idx < stripe_count; i++) {
                array_idx = (lqr->lqr_start_idx + lqr->lqr_offset_idx) %
                                osts->op_count;
                ++lqr->lqr_start_idx;
@@ -1131,9 +1023,9 @@ repeat_find:
                        continue;
 
                spin_unlock(&lqr->lqr_alloc);
-               rc = lod_check_and_reserve_ost(env, lo, sfs, ost_idx, speed,
-                                              &stripe_idx, stripe, ost_indices,
-                                              th);
+               rc = lod_check_and_reserve_ost(env, lo, lod_comp, sfs, ost_idx,
+                                              speed, &stripe_idx, stripe,
+                                              ost_indices, th, &overstriped);
                spin_lock(&lqr->lqr_alloc);
 
                if (rc != 0 && OST_TGT(m, ost_idx)->ltd_connecting)
@@ -1151,6 +1043,12 @@ repeat_find:
        spin_unlock(&lqr->lqr_alloc);
        up_read(&m->lod_qos.lq_rw_sem);
 
+       /* If there are enough OSTs, a component with overstriping requested
+        * will not actually end up overstriped.  The comp should reflect this.
+        */
+       if (!overstriped)
+               lod_comp->llc_pattern &= ~LOV_PATTERN_OVERSTRIPING;
+
        if (stripe_idx) {
                lod_comp->llc_stripe_count = stripe_idx;
                /* at least one stripe is allocated */
@@ -1249,10 +1147,11 @@ static int lod_alloc_ost_list(const struct lu_env *env, struct lod_object *lo,
                        break;
                }
 
-               /*
-                * do not put >1 objects on a single OST
+               /* do not put >1 objects on a single OST, except for
+                * overstriping
                 */
-               if (lod_qos_is_ost_used(env, ost_idx, stripe_count)) {
+               if (lod_qos_is_ost_used(env, ost_idx, stripe_count) &&
+                   !(lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)) {
                        rc = -EINVAL;
                        break;
                }
@@ -1315,13 +1214,15 @@ static int lod_alloc_specific(const struct lu_env *env, struct lod_object *lo,
        struct lod_layout_component *lod_comp;
        struct lod_device *m = lu2lod_dev(lo->ldo_obj.do_lu.lo_dev);
        struct obd_statfs *sfs = &lod_env_info(env)->lti_osfs;
-       struct dt_object  *o;
-       __u32              ost_idx;
-       unsigned int       i, array_idx, ost_count;
-       int                rc, stripe_num = 0;
-       int                speed = 0;
+       struct dt_object *o;
+       __u32 ost_idx;
+       unsigned int i, array_idx, ost_count;
+       int rc, stripe_num = 0;
+       int speed = 0;
        struct pool_desc  *pool = NULL;
        struct ost_pool   *osts;
+       int stripes_per_ost = 1;
+       bool overstriped = false;
        ENTRY;
 
        LASSERT(lo->ldo_comp_cnt > comp_idx && lo->ldo_comp_entries != NULL);
@@ -1359,7 +1260,11 @@ repeat_find:
                GOTO(out, rc = -EINVAL);
        }
 
-       for (i = 0; i < ost_count;
+       if (lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)
+               stripes_per_ost =
+                       (lod_comp->llc_stripe_count - 1)/ost_count + 1;
+
+       for (i = 0; i < ost_count * stripes_per_ost;
                        i++, array_idx = (array_idx + 1) % ost_count) {
                ost_idx = osts->op_array[array_idx];
 
@@ -1372,10 +1277,15 @@ repeat_find:
                        continue;
 
                /*
-                * do not put >1 objects on a single OST
+                * do not put >1 objects on a single OST, except for
+                * overstriping, where it is intended
                 */
-               if (lod_qos_is_ost_used(env, ost_idx, stripe_num))
-                       continue;
+               if (lod_qos_is_ost_used(env, ost_idx, stripe_num)) {
+                       if (lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)
+                               overstriped = true;
+                       else
+                               continue;
+               }
 
                /*
                 * try not allocate on the OST used by other component
@@ -1437,6 +1347,13 @@ repeat_find:
               PFID(lu_object_fid(lod2lu_obj(lo))), stripe_num,
               lod_comp->llc_stripe_count);
        rc = stripe_num == 0 ? -ENOSPC : -EFBIG;
+
+       /* If there are enough OSTs, a component with overstriping requessted
+        * will not actually end up overstriped.  The comp should reflect this.
+        */
+       if (rc == 0 && !overstriped)
+               lod_comp->llc_pattern &= ~LOV_PATTERN_OVERSTRIPING;
+
 out:
        if (pool != NULL) {
                up_read(&pool_tgt_rw_sem(pool));
@@ -1527,6 +1444,8 @@ static int lod_alloc_qos(const struct lu_env *env, struct lod_object *lo,
        struct ost_pool *osts;
        unsigned int i;
        __u32 nfound, good_osts, stripe_count, stripe_count_min;
+       bool overstriped = false;
+       int stripes_per_ost = 1;
        int rc = 0;
        ENTRY;
 
@@ -1551,6 +1470,10 @@ static int lod_alloc_qos(const struct lu_env *env, struct lod_object *lo,
        if (!lod_qos_is_usable(lod))
                GOTO(out_nolock, rc = -EAGAIN);
 
+       if (lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING)
+               stripes_per_ost =
+                       (lod_comp->llc_stripe_count - 1)/osts->op_count + 1;
+
        /* Do actual allocation, use write lock here. */
        down_write(&lod->lod_qos.lq_rw_sem);
 
@@ -1605,42 +1528,21 @@ static int lod_alloc_qos(const struct lu_env *env, struct lod_object *lo,
        if (good_osts < stripe_count_min)
                GOTO(out, rc = -EAGAIN);
 
-       /* We have enough osts */
-       if (good_osts < stripe_count)
-               stripe_count = good_osts;
+       /* If we do not have enough OSTs for the requested stripe count, do not
+        * put more stripes per OST than requested.
+        */
+       if (stripe_count / stripes_per_ost > good_osts)
+               stripe_count = good_osts * stripes_per_ost;
 
        /* Find enough OSTs with weighted random allocation. */
        nfound = 0;
        while (nfound < stripe_count) {
-               __u64 rand, cur_weight;
+               u64 rand, cur_weight;
 
                cur_weight = 0;
                rc = -ENOSPC;
 
-               if (total_weight) {
-#if BITS_PER_LONG == 32
-                       rand = cfs_rand() % (unsigned)total_weight;
-                       /* If total_weight > 32-bit, first generate the high
-                        * 32 bits of the random number, then add in the low
-                        * 32 bits (truncated to the upper limit, if needed) */
-                       if (total_weight > 0xffffffffULL)
-                               rand = (__u64)(cfs_rand() %
-                                       (unsigned)(total_weight >> 32)) << 32;
-                       else
-                               rand = 0;
-
-                       if (rand == (total_weight & 0xffffffff00000000ULL))
-                               rand |= cfs_rand() % (unsigned)total_weight;
-                       else
-                               rand |= cfs_rand();
-
-#else
-                       rand = ((__u64)cfs_rand() << 32 | cfs_rand()) %
-                               total_weight;
-#endif
-               } else {
-                       rand = 0;
-               }
+               rand = lu_prandom_u64_max(total_weight);
 
                /* On average, this will hit larger-weighted OSTs more often.
                 * 0-weight OSTs will always get used last (only when rand=0) */
@@ -1666,12 +1568,21 @@ static int lod_alloc_qos(const struct lu_env *env, struct lod_object *lo,
 
                        QOS_DEBUG("stripe=%d to idx=%d\n", nfound, idx);
                        /*
-                        * do not put >1 objects on a single OST
+                        * do not put >1 objects on a single OST, except for
+                        * overstriping
                         */
-                       if (lod_qos_is_ost_used(env, idx, nfound) ||
-                           lod_comp_is_ost_used(env, lo, idx))
+                       if ((lod_comp_is_ost_used(env, lo, idx)) &&
+                           !(lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING))
                                continue;
 
+                       if (lod_qos_is_ost_used(env, idx, nfound)) {
+                               if (lod_comp->llc_pattern &
+                                   LOV_PATTERN_OVERSTRIPING)
+                                       overstriped = true;
+                               else
+                                       continue;
+                       }
+
                        o = lod_qos_declare_object_on(env, lod, idx, th);
                        if (IS_ERR(o)) {
                                QOS_DEBUG("can't declare object on #%u: %d\n",
@@ -1718,6 +1629,12 @@ static int lod_alloc_qos(const struct lu_env *env, struct lod_object *lo,
                rc = -EAGAIN;
        }
 
+       /* If there are enough OSTs, a component with overstriping requessted
+        * will not actually end up overstriped.  The comp should reflect this.
+        */
+       if (rc == 0 && !overstriped)
+               lod_comp->llc_pattern &= ~LOV_PATTERN_OVERSTRIPING;
+
 out:
        up_write(&lod->lod_qos.lq_rw_sem);
 
@@ -1749,7 +1666,7 @@ out_nolock:
  * \retval             the maximum usable stripe count
  */
 __u16 lod_get_stripe_count(struct lod_device *lod, struct lod_object *lo,
-                          __u16 stripe_count)
+                          __u16 stripe_count, bool overstriping)
 {
        __u32 max_stripes = LOV_MAX_STRIPE_COUNT_OLD;
        /* max stripe count is based on OSD ea size */
@@ -1759,10 +1676,11 @@ __u16 lod_get_stripe_count(struct lod_device *lod, struct lod_object *lo,
 
        if (!stripe_count)
                stripe_count = lod->lod_desc.ld_default_stripe_count;
-       if (stripe_count > lod->lod_desc.ld_active_tgt_count)
-               stripe_count = lod->lod_desc.ld_active_tgt_count;
        if (!stripe_count)
                stripe_count = 1;
+       /* Overstriping allows more stripes than targets */
+       if (stripe_count > lod->lod_desc.ld_active_tgt_count && !overstriping)
+               stripe_count = lod->lod_desc.ld_active_tgt_count;
 
        if (lo->ldo_is_composite) {
                struct lod_layout_component *lod_comp;
@@ -2105,7 +2023,7 @@ int lod_qos_parse_config(const struct lu_env *env, struct lod_object *lo,
                        lod_comp->llc_extent = *ext;
                        lod_comp->llc_flags =
                                comp_v1->lcm_entries[i].lcme_flags &
-                                       LCME_USER_FLAGS;
+                                       LCME_CL_COMP_FLAGS;
                }
 
                pool_name = NULL;
@@ -2128,7 +2046,9 @@ int lod_qos_parse_config(const struct lu_env *env, struct lod_object *lo,
                if (v1->lmm_pattern == 0)
                        v1->lmm_pattern = LOV_PATTERN_RAID0;
                if (lov_pattern(v1->lmm_pattern) != LOV_PATTERN_RAID0 &&
-                   lov_pattern(v1->lmm_pattern) != LOV_PATTERN_MDT) {
+                   lov_pattern(v1->lmm_pattern) != LOV_PATTERN_MDT &&
+                   lov_pattern(v1->lmm_pattern) !=
+                       (LOV_PATTERN_RAID0 | LOV_PATTERN_OVERSTRIPING)) {
                        CDEBUG(D_LAYOUT, "%s: invalid pattern: %x\n",
                               lod2obd(d)->obd_name, v1->lmm_pattern);
                        GOTO(free_comp, rc = -EINVAL);
@@ -2172,7 +2092,8 @@ int lod_qos_parse_config(const struct lu_env *env, struct lod_object *lo,
                        }
                }
 
-               if (lod_comp->llc_stripe_count > pool_tgt_count(pool))
+               if (lod_comp->llc_stripe_count > pool_tgt_count(pool) &&
+                   !(lod_comp->llc_pattern & LOV_PATTERN_OVERSTRIPING))
                        lod_comp->llc_stripe_count = pool_tgt_count(pool);
 
                lod_pool_putref(pool);
@@ -2297,11 +2218,11 @@ void lod_collect_avoidance(struct lod_object *lo, struct lod_avoid_guide *lag,
                         */
                        for (j = 0; j < comp->llc_stripe_count; j++) {
                                struct lod_tgt_desc *ost;
-                               struct lod_qos_oss *lqo;
+                               struct lu_svr_qos *lsq;
                                int k;
 
                                ost = OST_TGT(lod, comp->llc_ost_indices[j]);
-                               lqo = ost->ltd_qos.ltq_oss;
+                               lsq = ost->ltd_qos.ltq_svr;
 
                                if (cfs_bitmap_check(bitmap, ost->ltd_index))
                                        continue;
@@ -2313,12 +2234,12 @@ void lod_collect_avoidance(struct lod_object *lo, struct lod_avoid_guide *lag,
 
                                for (k = 0; k < lag->lag_oaa_count; k++) {
                                        if (lag->lag_oss_avoid_array[k] ==
-                                           lqo->lqo_id)
+                                           lsq->lsq_id)
                                                break;
                                }
                                if (k == lag->lag_oaa_count) {
                                        lag->lag_oss_avoid_array[k] =
-                                                               lqo->lqo_id;
+                                                               lsq->lsq_id;
                                        lag->lag_oaa_count++;
                                }
                        }
@@ -2361,6 +2282,7 @@ int lod_qos_prep_create(const struct lu_env *env, struct lod_object *lo,
        LASSERT(lo);
        LASSERT(lo->ldo_comp_cnt > comp_idx && lo->ldo_comp_entries != NULL);
        lod_comp = &lo->ldo_comp_entries[comp_idx];
+       LASSERT(!(lod_comp->llc_flags & LCME_FL_EXTENSION));
 
        /* A released component is being created */
        if (lod_comp->llc_pattern & LOV_PATTERN_F_RELEASED)
@@ -2381,7 +2303,10 @@ int lod_qos_prep_create(const struct lu_env *env, struct lod_object *lo,
                 */
                lod_qos_statfs_update(env, d);
                stripe_len = lod_get_stripe_count(d, lo,
-                                                 lod_comp->llc_stripe_count);
+                                                 lod_comp->llc_stripe_count,
+                                                 lod_comp->llc_pattern &
+                                                 LOV_PATTERN_OVERSTRIPING);
+
                if (stripe_len == 0)
                        GOTO(out, rc = -ERANGE);
                lod_comp->llc_stripe_count = stripe_len;