#define set_bit(i, a) setbit(a, i)
#define clear_bit(i, a) clrbit(a, i)
-#define get_random_bytes(buf, len) read_random(buf, len)
+#define cfs_get_random_bytes_prim(buf, len) read_random(buf, len)
#endif /* __KERNEL__ */
/* convert universal open flags to local open flags */
int cfs_univ2oflags(int flags);
+/*
+ * Random number handling
+ */
+
+/* returns a random 32-bit integer */
+unsigned int cfs_rand(void);
+/* seed the generator */
+void cfs_srand(unsigned int, unsigned int);
+void cfs_get_random_bytes(void *buf, int size);
+
#include <libcfs/libcfs_debug.h>
#include <libcfs/libcfs_private.h>
#include <libcfs/libcfs_ioctl.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/kthread.h>
+#ifdef HAVE_LINUX_RANDOM_H
+#include <linux/random.h>
+#endif
#include <linux/miscdevice.h>
#include <libcfs/linux/portals_compat25.h>
/*
* Random bytes
*/
-#define cfs_get_random_bytes(buf, nbytes) get_random_bytes(buf, nbytes)
+#define cfs_get_random_bytes_prim(buf, nbytes) get_random_bytes(buf, nbytes)
#endif
# define max(x,y) ((x)>(y) ? (x) : (y))
#endif
+#define cfs_get_random_bytes_prim(val, size) (*val) = 0
+
/* utility libcfs init/fini entries */
#ifdef __WINNT__
extern int libcfs_arch_init(void);
}
}
-#define cfs_get_random_bytes(buf, len) read_random(buf, len)
+#define cfs_get_random_bytes_prim(buf, len) read_random(buf, len)
/* do NOT use function or expression as parameters ... */
endif
libcfs-all-objs := debug.o nidstrings.o lwt.o module.o tracefile.o watchdog.o \
- libcfs_string.o hash.o kernel_user_comm.o
+ libcfs_string.o hash.o kernel_user_comm.o prng.o
libcfs-objs := $(libcfs-linux-objs) $(libcfs-all-objs)
if LIBLUSTRE
noinst_LIBRARIES= libcfs.a
libcfs_a_SOURCES= posix/posix-debug.c user-prim.c user-lock.c user-tcpip.c \
- user-bitops.c user-mem.c hash.c kernel_user_comm.c
+ prng.c user-bitops.c user-mem.c hash.c kernel_user_comm.c
libcfs_a_CPPFLAGS = $(LLCPPFLAGS)
libcfs_a_CFLAGS = $(LLCFLAGS)
endif
EXTRA_DIST := Info.plist
MOSTLYCLEANFILES := @MOSTLYCLEANFILES@ linux-*.c linux/*.o darwin/*.o libcfs
-DIST_SOURCES := $(libcfs-all-objs:%.o=%.c) tracefile.h user-prim.c \
+DIST_SOURCES := $(libcfs-all-objs:%.o=%.c) tracefile.h user-prim.c prng.c \
user-lock.c user-tcpip.c user-bitops.c\
user-mem.c kernel_user_comm.c linux/linux-tracefile.h
* This file is part of Lustre, http://www.lustre.org/
* Lustre is a trademark of Sun Microsystems, Inc.
*
- * lustre/lvfs/prng.c
+ * libcfs/libcfs/prng.c
*
* concatenation of following two 16-bit multiply with carry generators
* x(n)=a*x(n-1)+carry mod 2^16 and y(n)=b*y(n-1)+carry mod 2^16,
# define EXPORT_SYMTAB
#endif
-#ifndef __KERNEL__
-#include <liblustre.h>
-#define cfs_get_random_bytes(val, size) (*val) = 0
-#endif
-#include <obd_class.h>
-#if defined(HAVE_LINUX_RANDOM_H)
-#include <linux/random.h>
-#endif
+#include <libcfs/libcfs.h>
/*
From: George Marsaglia <geo@stat.fsu.edu>
static unsigned int seed_x = 521288629;
static unsigned int seed_y = 362436069;
-unsigned int ll_rand(void)
-{
- seed_x = RANDOM_CONST_A * (seed_x & 65535) + (seed_x >> 16);
- seed_y = RANDOM_CONST_B * (seed_y & 65535) + (seed_y >> 16);
+/**
+ * cfs_rand - creates new seeds
+ *
+ * First it creates new seeds from the previous seeds. Then it generates a
+ * new psuedo random number for use.
+ *
+ * Returns a pseudo-random 32-bit integer
+ */
+unsigned int cfs_rand(void)
+{
+ seed_x = RANDOM_CONST_A * (seed_x & 65535) + (seed_x >> 16);
+ seed_y = RANDOM_CONST_B * (seed_y & 65535) + (seed_y >> 16);
- return ((seed_x << 16) + (seed_y & 65535));
+ return ((seed_x << 16) + (seed_y & 65535));
}
-EXPORT_SYMBOL(ll_rand);
+CFS_EXPORT_SYMBOL(cfs_rand);
-/* Note that if the input seeds are not completely random, then there is
- * a preferred location for the entropy in the two seeds, in order to avoid
- * the initial values from the PRNG to be the same each time.
+/**
+ * cfs_srand - sets the inital seed
+ * @seed1 : (seed_x) should have the most entropy in the low bits of the word
+ * @seed2 : (seed_y) should have the most entropy in the high bits of the word
*
- * seed1 (seed_x) should have the most entropy in the low bits of the word
- * seed2 (seed_y) should have the most entropy in the high bits of the word */
-void ll_srand(unsigned int seed1, unsigned int seed2)
+ * Replaces the original seeds with new values. Used to generate a new pseudo
+ * random numbers.
+ */
+void cfs_srand(unsigned int seed1, unsigned int seed2)
{
- if (seed1)
- seed_x = seed1; /* use default seeds if parameter is 0 */
- if (seed2)
- seed_y = seed2;
+ if (seed1)
+ seed_x = seed1; /* use default seeds if parameter is 0 */
+ if (seed2)
+ seed_y = seed2;
}
-EXPORT_SYMBOL(ll_srand);
+CFS_EXPORT_SYMBOL(cfs_srand);
-void ll_get_random_bytes(void *buf, int size)
+/**
+ * cfs_get_random_bytes - generate a bunch of random numbers
+ * @buf : buffer to fill with random numbers
+ * @size: size of passed in buffer
+ *
+ * Fills a buffer with random bytes
+ */
+void cfs_get_random_bytes(void *buf, int size)
{
int *p = buf;
int rem, tmp;
rem = min((int)((unsigned long)buf & (sizeof(int) - 1)), size);
if (rem) {
- cfs_get_random_bytes(&tmp, sizeof(tmp));
- tmp ^= ll_rand();
+ cfs_get_random_bytes_prim(&tmp, sizeof(tmp));
+ tmp ^= cfs_rand();
memcpy(buf, &tmp, rem);
p = buf + rem;
size -= rem;
}
while (size >= sizeof(int)) {
- cfs_get_random_bytes(&tmp, sizeof(tmp));
- *p = ll_rand() ^ tmp;
+ cfs_get_random_bytes_prim(&tmp, sizeof(tmp));
+ *p = cfs_rand() ^ tmp;
size -= sizeof(int);
p++;
}
buf = p;
if (size) {
- cfs_get_random_bytes(&tmp, sizeof(tmp));
- tmp ^= ll_rand();
+ cfs_get_random_bytes_prim(&tmp, sizeof(tmp));
+ tmp ^= cfs_rand();
memcpy(buf, &tmp, size);
}
}
-EXPORT_SYMBOL(ll_get_random_bytes);
-
-void ll_generate_random_uuid(class_uuid_t uuid_out)
-{
- ll_get_random_bytes(uuid_out, sizeof(class_uuid_t));
-}
-EXPORT_SYMBOL(ll_generate_random_uuid);
+CFS_EXPORT_SYMBOL(cfs_get_random_bytes);
#include <linux/list.h>
#include <linux/kmod.h>
#include <linux/sysctl.h>
-#include <linux/random.h>
#include <linux/pci.h>
#include <net/sock.h>
#include <asm/types.h>
#include <asm/atomic.h>
#include <linux/list.h>
-#include <linux/random.h>
#include <linux/version.h>
#include <linux/spinlock.h>
#include <linux/types.h>
#error Unsupported operating system.
#endif
-/* prng.c */
-unsigned int ll_rand(void); /* returns a random 32-bit integer */
-void ll_srand(unsigned int, unsigned int); /* seed the generator */
-void ll_get_random_bytes(void *buf, int size);
-
/* target.c */
struct ptlrpc_request;
struct obd_export;
int raw_name2idx(int hashtype, int count, const char *name, int namelen);
/* prng.c */
-void ll_generate_random_uuid(class_uuid_t uuid_out);
+#define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
#endif /* __LINUX_OBD_CLASS_H */
if (_rand_dev_fd >= 0) {
if (syscall(SYS_read, _rand_dev_fd,
&seed, sizeof(seed)) == sizeof(seed)) {
- ll_srand(seed[0], seed[1]);
+ cfs_srand(seed[0], seed[1]);
syscall(SYS_close, _rand_dev_fd);
return;
}
seed[0] = _my_pnid;
#endif
gettimeofday(&tv, NULL);
- ll_srand(tv.tv_sec ^ __swab32(seed[0]), tv.tv_usec ^__swab32(getpid()));
+ cfs_srand(tv.tv_sec ^ __swab32(seed[0]), tv.tv_usec ^__swab32(getpid()));
}
static void init_capability(__u32 *res)
#include <linux/module.h>
#include <linux/types.h>
-#include <linux/random.h>
#include <linux/version.h>
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/types.h>
-#include <linux/random.h>
#include <linux/version.h>
#include <lustre_lite.h>
#include <linux/module.h>
#include <linux/types.h>
-#include <linux/random.h>
#include <linux/version.h>
#include <lustre_lite.h>
#include <lustre_ha.h>
lustre_register_client_process_config(ll_process_config);
- ll_get_random_bytes(seed, sizeof(seed));
+ cfs_get_random_bytes(seed, sizeof(seed));
/* Nodes with small feet have little entropy
* the NID for this node gives the most entropy in the low bits */
}
cfs_gettimeofday(&tv);
- ll_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
+ cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
init_timer(&ll_capa_timer);
ll_capa_timer.function = ll_capa_timer_callback;
GOTO(out, rc);
if (--lqr->lqr_start_count <= 0) {
- lqr->lqr_start_idx = ll_rand() % osts->op_count;
+ lqr->lqr_start_idx = cfs_rand() % 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);
if (total_weight) {
#if BITS_PER_LONG == 32
- rand = ll_rand() % (unsigned)total_weight;
+ 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)(ll_rand() %
+ rand = (__u64)(cfs_rand() %
(unsigned)(total_weight >> 32)) << 32;
else
rand = 0;
if (rand == (total_weight & 0xffffffff00000000ULL))
- rand |= ll_rand() % (unsigned)total_weight;
+ rand |= cfs_rand() % (unsigned)total_weight;
else
- rand |= ll_rand();
+ rand |= cfs_rand();
#else
- rand = ((__u64)ll_rand() << 32 | ll_rand()) %
+ rand = ((__u64)cfs_rand() << 32 | cfs_rand()) %
total_weight;
#endif
} else {
@SERVER_TRUE@MODULES += fsfilt_@BACKINGFS@
@QUOTA_TRUE@MODULES += quotafmt_test
-lvfs-objs := lvfs_common.o lvfs_linux.o fsfilt.o upcall_cache.o prng.o lvfs_lib.o
+lvfs-objs := lvfs_common.o lvfs_linux.o fsfilt.o upcall_cache.o lvfs_lib.o
@QUOTA_TRUE@quotafmt-objs := quotafmt_test.o
if LIBLUSTRE
noinst_LIBRARIES = liblvfs.a
-liblvfs_a_SOURCES = lvfs_userfs.c prng.c lvfs_lib.c
+liblvfs_a_SOURCES = lvfs_userfs.c lvfs_lib.c
liblvfs_a_CFLAGS = $(LLCFLAGS)
liblvfs_a_CPPFLAGS = $(LLCPPFLAGS)
*/
#ifdef __KERNEL__
#include <linux/module.h>
-#include <linux/random.h>
#else
#include <liblustre.h>
#endif
size_t size, const char *file, int line)
{
if (ptr == NULL ||
- (ll_rand() & OBD_ALLOC_FAIL_MASK) < obd_alloc_fail_rate) {
+ (cfs_rand() & OBD_ALLOC_FAIL_MASK) < obd_alloc_fail_rate) {
CERROR("%s%salloc of %s ("LPU64" bytes) failed at %s:%d\n",
ptr ? "force " :"", type, name, (__u64)size, file,
line);
/* Fail 1/obd_fail_val times */
if (obd_fail_loc & OBD_FAIL_RAND) {
- if (obd_fail_val < 2 || ll_rand() % obd_fail_val > 0)
+ if (obd_fail_val < 2 || cfs_rand() % obd_fail_val > 0)
return 0;
}
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/kernel.h>
-#include <linux/random.h>
#include <lustre_quota.h>
#include <obd_class.h>
if (dquot == NULL)
return NULL;
- ll_get_random_bytes(&rand, sizeof(rand));
+ cfs_get_random_bytes(&rand, sizeof(rand));
if (!rand)
rand = 1000;
#include <lustre_mds.h>
#include <linux/module.h>
#include <linux/init.h>
-#include <linux/random.h>
#include <linux/fs.h>
#include <linux/jbd.h>
#include <linux/smp_lock.h>
{
struct mds_obd *mds = &exp->exp_obd->u.mds;
struct inode *parent_inode = mds->mds_objects_dir->d_inode;
- unsigned int tmpname = ll_rand();
+ unsigned int tmpname = cfs_rand();
struct file *filp;
struct dentry *new_child;
struct lvfs_run_ctxt saved;
{
key->lk_seq = mdsnum;
key->lk_keyid = keyid + 1;
- ll_get_random_bytes(key->lk_key, sizeof(key->lk_key));
+ cfs_get_random_bytes(key->lk_key, sizeof(key->lk_key));
}
static inline void lck_cpu_to_le(struct lustre_capa_key *tgt,
/* Always wait a few seconds to allow the server who
caused the lock revocation to finish its setup, plus some
random so everyone doesn't try to reconnect at once. */
- lwi_now = LWI_TIMEOUT(3 * CFS_HZ + (ll_rand() & 0xff) * \
+ lwi_now = LWI_TIMEOUT(3 * CFS_HZ + (cfs_rand() & 0xff) * \
(CFS_HZ / 100),
NULL, NULL);
l_wait_event(rq_waitq, rq_state & RQ_STOP, &lwi_now);
if (rc)
RETURN(rc);
- llog_test_rand = ll_rand();
+ llog_test_rand = cfs_rand();
rc = llog_run_tests(obd);
if (rc)
}
/** bug 21430: add randomness to the initial base */
- ll_get_random_bytes(seed, sizeof(seed));
+ cfs_get_random_bytes(seed, sizeof(seed));
cfs_gettimeofday(&tv);
- ll_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
+ cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
- ll_get_random_bytes(&handle_base, sizeof(handle_base));
+ cfs_get_random_bytes(&handle_base, sizeof(handle_base));
LASSERT(handle_base != 0ULL);
return 0;
#ifdef __KERNEL__
#include <linux/kmod.h> /* for request_module() */
#include <linux/module.h>
-#include <linux/random.h>
#include <linux/slab.h>
#include <linux/pagemap.h>
#else
if (lsm->lsm_stripe_size == 0)
lsm->lsm_stripe_size = CFS_PAGE_SIZE;
- idx = ll_rand();
+ idx = cfs_rand();
/* setup stripes: indices + default ids if required */
for (i = 0; i < lsm->lsm_stripe_count; i++) {
__u32 d[4], s[4];
s[0] = obj->oo_inode->i_uid;
- ll_get_random_bytes(&(s[1]), sizeof(__u32));
+ cfs_get_random_bytes(&(s[1]), sizeof(__u32));
s[2] = obj->oo_inode->i_gid;
- ll_get_random_bytes(&(s[3]), sizeof(__u32));
+ cfs_get_random_bytes(&(s[3]), sizeof(__u32));
rc = capa_encrypt_id(d, s, key->lk_key, CAPA_HMAC_KEY_MAX_LEN);
if (unlikely(rc))
RETURN(ERR_PTR(rc));
cfs_spin_lock_init(&ptlrpc_last_xid_lock);
if (now < YEAR_2004) {
- ll_get_random_bytes(&ptlrpc_last_xid, sizeof(ptlrpc_last_xid));
+ cfs_get_random_bytes(&ptlrpc_last_xid, sizeof(ptlrpc_last_xid));
ptlrpc_last_xid >>= 2;
ptlrpc_last_xid |= (1ULL << 61);
} else {
#include <linux/slab.h>
#include <linux/dcache.h>
#include <linux/fs.h>
-#include <linux/random.h>
#include <linux/mutex.h>
#include <linux/crypto.h>
#else
#include <linux/dcache.h>
#include <linux/fs.h>
#include <linux/mutex.h>
-#include <linux/random.h>
#else
#include <liblustre.h>
#endif
#include <linux/slab.h>
#include <linux/dcache.h>
#include <linux/fs.h>
-#include <linux/random.h>
#include <linux/crypto.h>
#include <linux/key.h>
#include <linux/keyctl.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/crypto.h>
-#include <linux/random.h>
#include <linux/mutex.h>
#else
#include <liblustre.h>
fill_krb5_header(kctx, khdr, 1);
/* generate confounder */
- ll_get_random_bytes(conf, ke->ke_conf_size);
+ cfs_get_random_bytes(conf, ke->ke_conf_size);
/* get encryption blocksize. note kc_keye might not associated with
* a tfm, currently only for arcfour-hmac */
fill_krb5_header(kctx, khdr, 1);
/* generate confounder */
- ll_get_random_bytes(conf, ke->ke_conf_size);
+ cfs_get_random_bytes(conf, ke->ke_conf_size);
/* get encryption blocksize. note kc_keye might not associated with
* a tfm, currently only for arcfour-hmac */
#include <linux/slab.h>
#include <linux/dcache.h>
#include <linux/fs.h>
-#include <linux/random.h>
#include <linux/mutex.h>
#include <linux/crypto.h>
#include <asm/atomic.h>
* sequence number checking, thus no chance to sent error notification
* back to clients.
*/
- ll_get_random_bytes(&__ctx_index, sizeof(__ctx_index));
+ cfs_get_random_bytes(&__ctx_index, sizeof(__ctx_index));
cache_register(&rsi_cache);
#include <linux/slab.h>
#include <linux/dcache.h>
#include <linux/fs.h>
-#include <linux/random.h>
#include <linux/mutex.h>
#else
#include <liblustre.h>
#include <linux/slab.h>
#include <linux/dcache.h>
#include <linux/fs.h>
-#include <linux/random.h>
#include <linux/mutex.h>
#include <asm/atomic.h>
#else