#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>
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];