ext2/3: use prandom_u32() instead of get_random_bytes()
authorZhangZhen <zhenzhang.zhang@huawei.com>
Wed, 26 Feb 2014 02:32:41 +0000 (10:32 +0800)
committerJan Kara <jack@suse.cz>
Tue, 4 Mar 2014 11:19:03 +0000 (12:19 +0100)
Many of the uses of get_random_bytes() do not actually need
cryptographically secure random numbers.  Replace those uses with a
call to prandom_u32(), which is faster and which doesn't consume
entropy from the /dev/random driver.

The commit dd1f723bf56bd96efc9d90e9e60dc511c79de48f has made that for
ext4, and i did the same for ext2/3.

Signed-off-by: Zhang Zhen <zhenzhang.zhang@huawei.com>
Signed-off-by: Jan Kara <jack@suse.cz>
fs/ext2/ialloc.c
fs/ext3/ialloc.c

index 7cadd823bb311643a6cb7042222870767224b4c9..7d66fb0e4cca87e2ae9be18fb5f7862d1df1a2af 100644 (file)
@@ -284,7 +284,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
                int best_ndir = inodes_per_group;
                int best_group = -1;
 
-               get_random_bytes(&group, sizeof(group));
+               group = prandom_u32();
                parent_group = (unsigned)group % ngroups;
                for (i = 0; i < ngroups; i++) {
                        group = (parent_group + i) % ngroups;
index 082afd78b10788ed8b1645f0f26c76bf3ea91b0e..a1b810230cc503708fa5cb2a91598684a0c3ca41 100644 (file)
@@ -215,7 +215,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
                int best_ndir = inodes_per_group;
                int best_group = -1;
 
-               get_random_bytes(&group, sizeof(group));
+               group = prandom_u32();
                parent_group = (unsigned)group % ngroups;
                for (i = 0; i < ngroups; i++) {
                        group = (parent_group + i) % ngroups;