Whamcloud - gitweb
LU-12538 lod: Add missed qos_rr_init
[fs/lustre-release.git] / lustre / lod / lod_qos.c
index aca8fc7..7d738f3 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>
@@ -76,8 +78,9 @@
  * \retval negative    negated errno on error
 
  */
-static int lod_statfs_and_check(const struct lu_env *env, struct lod_device *d,
-                               int index, struct obd_statfs *sfs)
+int lod_statfs_and_check(const struct lu_env *env, struct lod_device *d,
+                        int index, struct obd_statfs *sfs,
+                        struct obd_statfs_info *info)
 {
        struct lod_tgt_desc *ost;
        int                  rc;
@@ -87,7 +90,7 @@ static int lod_statfs_and_check(const struct lu_env *env, struct lod_device *d,
        ost = OST_TGT(d,index);
        LASSERT(ost);
 
-       rc = dt_statfs(env, ost->ltd_ost, sfs);
+       rc = dt_statfs(env, ost->ltd_ost, sfs, info);
 
        if (rc == 0 && ((sfs->os_state & OS_STATE_ENOSPC) ||
            (sfs->os_state & OS_STATE_ENOINO && sfs->os_fprecreated == 0)))
@@ -177,7 +180,7 @@ void lod_qos_statfs_update(const struct lu_env *env, struct lod_device *lod)
                idx = osts->op_array[i];
                avail = OST_TGT(lod,idx)->ltd_statfs.os_bavail;
                if (lod_statfs_and_check(env, lod, idx,
-                                        &OST_TGT(lod, idx)->ltd_statfs))
+                                        &OST_TGT(lod, idx)->ltd_statfs, NULL))
                        continue;
                if (OST_TGT(lod,idx)->ltd_statfs.os_bavail != avail)
                        /* recalculate weigths */
@@ -432,12 +435,6 @@ static int lod_qos_used(struct lod_device *lod, struct ost_pool *osts,
        RETURN(0);
 }
 
-void lod_qos_rr_init(struct lu_qos_rr *lqr)
-{
-       spin_lock_init(&lqr->lqr_alloc);
-       lqr->lqr_dirty = 1;
-}
-
 #define LOV_QOS_EMPTY ((__u32)-1)
 
 /**
@@ -835,7 +832,7 @@ static int lod_check_and_reserve_ost(const struct lu_env *env,
        int rc;
        ENTRY;
 
-       rc = lod_statfs_and_check(env, lod, ost_idx, sfs);
+       rc = lod_statfs_and_check(env, lod, ost_idx, sfs, NULL);
        if (rc)
                RETURN(rc);
 
@@ -979,7 +976,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);
@@ -1160,7 +1157,7 @@ static int lod_alloc_ost_list(const struct lu_env *env, struct lod_object *lo,
                        break;
                }
 
-               rc = lod_statfs_and_check(env, m, ost_idx, sfs);
+               rc = lod_statfs_and_check(env, m, ost_idx, sfs, NULL);
                if (rc < 0) /* this OSP doesn't feel well */
                        break;
 
@@ -1304,7 +1301,7 @@ repeat_find:
                 * start OST, then it can be skipped, otherwise skip it only
                 * if it is inactive/recovering/out-of-space." */
 
-               rc = lod_statfs_and_check(env, m, ost_idx, sfs);
+               rc = lod_statfs_and_check(env, m, ost_idx, sfs, NULL);
                if (rc) {
                        /* this OSP doesn't feel well */
                        continue;
@@ -1505,7 +1502,8 @@ static int lod_alloc_qos(const struct lu_env *env, struct lod_object *lo,
                ost = OST_TGT(lod, osts->op_array[i]);
                ost->ltd_qos.ltq_usable = 0;
 
-               rc = lod_statfs_and_check(env, lod, osts->op_array[i], sfs);
+               rc = lod_statfs_and_check(env, lod, osts->op_array[i],
+                                         sfs, NULL);
                if (rc) {
                        /* this OSP doesn't feel well */
                        continue;
@@ -1541,35 +1539,12 @@ static int lod_alloc_qos(const struct lu_env *env, struct lod_object *lo,
        /* 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) */
@@ -2050,7 +2025,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;
@@ -2309,6 +2284,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)