Whamcloud - gitweb
LU-12368 obdclass: don't send multiple statfs RPCs
[fs/lustre-release.git] / lustre / lmv / lmv_qos.c
index 685cc01..1708c00 100644 (file)
@@ -33,6 +33,8 @@
 #define DEBUG_SUBSYSTEM S_LMV
 
 #include <asm/div64.h>
+#include <linux/random.h>
+
 #include <libcfs/libcfs.h>
 #include <uapi/linux/lustre/lustre_idl.h>
 #include <lustre_swab.h>
@@ -370,31 +372,7 @@ struct lu_tgt_desc *lmv_locate_tgt_qos(struct lmv_obd *lmv, __u32 *mdt)
                total_weight += tgt->ltd_qos.ltq_weight;
        }
 
-       if (total_weight) {
-#if BITS_PER_LONG == 32
-               rand = cfs_rand() % (unsigned int)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 int)(total_weight >> 32)) << 32;
-               else
-                       rand = 0;
-
-               if (rand == (total_weight & 0xffffffff00000000ULL))
-                       rand |= cfs_rand() % (unsigned int)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);
 
        for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
                tgt = lmv->tgts[i];