Commit f5c416b4 authored by Theodore Y. Ts'o's avatar Theodore Y. Ts'o Committed by Linus Torvalds

[PATCH] /dev/random: Add pool name to entropy store

This adds a pool name to the entropy_store data structure, which simplifies
the debugging code, and makes the code more generic for adding additional
entropy pools.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 0dd0219b
...@@ -493,6 +493,7 @@ struct entropy_store { ...@@ -493,6 +493,7 @@ struct entropy_store {
/* mostly-read data: */ /* mostly-read data: */
struct poolinfo poolinfo; struct poolinfo poolinfo;
__u32 *pool; __u32 *pool;
const char *name;
/* read-write data: */ /* read-write data: */
spinlock_t lock ____cacheline_aligned_in_smp; spinlock_t lock ____cacheline_aligned_in_smp;
...@@ -507,7 +508,8 @@ struct entropy_store { ...@@ -507,7 +508,8 @@ struct entropy_store {
* *
* Returns an negative error if there is a problem. * Returns an negative error if there is a problem.
*/ */
static int create_entropy_store(int size, struct entropy_store **ret_bucket) static int create_entropy_store(int size, const char *name,
struct entropy_store **ret_bucket)
{ {
struct entropy_store *r; struct entropy_store *r;
struct poolinfo *p; struct poolinfo *p;
...@@ -538,6 +540,7 @@ static int create_entropy_store(int size, struct entropy_store **ret_bucket) ...@@ -538,6 +540,7 @@ static int create_entropy_store(int size, struct entropy_store **ret_bucket)
} }
memset(r->pool, 0, POOLBYTES); memset(r->pool, 0, POOLBYTES);
r->lock = SPIN_LOCK_UNLOCKED; r->lock = SPIN_LOCK_UNLOCKED;
r->name = name;
*ret_bucket = r; *ret_bucket = r;
return 0; return 0;
} }
...@@ -643,12 +646,8 @@ static void credit_entropy_store(struct entropy_store *r, int nbits) ...@@ -643,12 +646,8 @@ static void credit_entropy_store(struct entropy_store *r, int nbits)
} else { } else {
r->entropy_count += nbits; r->entropy_count += nbits;
if (nbits) if (nbits)
DEBUG_ENT("%04d %04d : added %d bits to %s\n", DEBUG_ENT("Added %d entropy credits to %s, now %d\n",
random_state->entropy_count, nbits, r->name, r->entropy_count);
sec_random_state->entropy_count,
nbits,
r == sec_random_state ? "secondary" :
r == random_state ? "primary" : "unknown");
} }
spin_unlock_irqrestore(&r->lock, flags); spin_unlock_irqrestore(&r->lock, flags);
...@@ -1328,8 +1327,7 @@ static inline void xfer_secondary_pool(struct entropy_store *r, ...@@ -1328,8 +1327,7 @@ static inline void xfer_secondary_pool(struct entropy_store *r,
"(%d of %d requested)\n", "(%d of %d requested)\n",
random_state->entropy_count, random_state->entropy_count,
sec_random_state->entropy_count, sec_random_state->entropy_count,
r == sec_random_state ? "secondary" : "unknown", r->name, bytes * 8, nbytes * 8, r->entropy_count);
bytes * 8, nbytes * 8, r->entropy_count);
bytes=extract_entropy(random_state, tmp, bytes, bytes=extract_entropy(random_state, tmp, bytes,
EXTRACT_ENTROPY_LIMIT); EXTRACT_ENTROPY_LIMIT);
...@@ -1373,9 +1371,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void * buf, ...@@ -1373,9 +1371,7 @@ static ssize_t extract_entropy(struct entropy_store *r, void * buf,
DEBUG_ENT("%04d %04d : trying to extract %d bits from %s\n", DEBUG_ENT("%04d %04d : trying to extract %d bits from %s\n",
random_state->entropy_count, random_state->entropy_count,
sec_random_state->entropy_count, sec_random_state->entropy_count,
nbytes * 8, nbytes * 8, r->name);
r == sec_random_state ? "secondary" :
r == random_state ? "primary" : "unknown");
if (flags & EXTRACT_ENTROPY_LIMIT && nbytes >= r->entropy_count / 8) if (flags & EXTRACT_ENTROPY_LIMIT && nbytes >= r->entropy_count / 8)
nbytes = r->entropy_count / 8; nbytes = r->entropy_count / 8;
...@@ -1388,12 +1384,8 @@ static ssize_t extract_entropy(struct entropy_store *r, void * buf, ...@@ -1388,12 +1384,8 @@ static ssize_t extract_entropy(struct entropy_store *r, void * buf,
if (r->entropy_count < random_write_wakeup_thresh) if (r->entropy_count < random_write_wakeup_thresh)
wake_up_interruptible(&random_write_wait); wake_up_interruptible(&random_write_wait);
DEBUG_ENT("%04d %04d : debiting %d bits from %s%s\n", DEBUG_ENT("Debiting %d entropy credits from %s%s\n",
random_state->entropy_count, nbytes * 8, r->name,
sec_random_state->entropy_count,
nbytes * 8,
r == sec_random_state ? "secondary" :
r == random_state ? "primary" : "unknown",
flags & EXTRACT_ENTROPY_LIMIT ? "" : " (unlimited)"); flags & EXTRACT_ENTROPY_LIMIT ? "" : " (unlimited)");
spin_unlock_irqrestore(&r->lock, cpuflags); spin_unlock_irqrestore(&r->lock, cpuflags);
...@@ -1533,11 +1525,12 @@ static int __init rand_initialize(void) ...@@ -1533,11 +1525,12 @@ static int __init rand_initialize(void)
{ {
int i; int i;
if (create_entropy_store(DEFAULT_POOL_SIZE, &random_state)) if (create_entropy_store(DEFAULT_POOL_SIZE, "primary", &random_state))
goto err; goto err;
if (batch_entropy_init(BATCH_ENTROPY_SIZE, random_state)) if (batch_entropy_init(BATCH_ENTROPY_SIZE, random_state))
goto err; goto err;
if (create_entropy_store(SECONDARY_POOL_SIZE, &sec_random_state)) if (create_entropy_store(SECONDARY_POOL_SIZE, "secondary",
&sec_random_state))
goto err; goto err;
clear_entropy_store(random_state); clear_entropy_store(random_state);
clear_entropy_store(sec_random_state); clear_entropy_store(sec_random_state);
...@@ -1885,7 +1878,8 @@ static int change_poolsize(int poolsize) ...@@ -1885,7 +1878,8 @@ static int change_poolsize(int poolsize)
struct entropy_store *new_store, *old_store; struct entropy_store *new_store, *old_store;
int ret; int ret;
if ((ret = create_entropy_store(poolsize, &new_store))) if ((ret = create_entropy_store(poolsize, random_state->name,
&new_store)))
return ret; return ret;
add_entropy_words(new_store, random_state->pool, add_entropy_words(new_store, random_state->pool,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment