From 2171228b200bfd1e1c9e993f7cac6567e6c94609 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 26 May 2016 10:56:51 +0800 Subject: btrfs-progs: Use new random number API Replace old and not so informal srand()/rand() calls to new random number API. Including btrfs-corrupt-block(main user), btrfs-image and btrfs-crc. Some tests like dir-test/random-test/quick-test is not modified. As random-test itself can't even pass build. Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- btrfs-corrupt-block.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'btrfs-corrupt-block.c') diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c index fb6fcaad..020afab5 100644 --- a/btrfs-corrupt-block.c +++ b/btrfs-corrupt-block.c @@ -131,8 +131,8 @@ static void corrupt_keys(struct btrfs_trans_handle *trans, if (nr == 0) return; - slot = rand() % nr; - bad_slot = rand() % nr; + slot = rand_range(nr); + bad_slot = rand_range(nr); if (bad_slot == slot) return; @@ -181,7 +181,7 @@ static int corrupt_extent(struct btrfs_trans_handle *trans, struct btrfs_path *path; int ret; int slot; - int should_del = rand() % 3; + int should_del = rand_range(3); path = btrfs_alloc_path(); if (!path) @@ -258,7 +258,7 @@ static void btrfs_corrupt_extent_leaf(struct btrfs_trans_handle *trans, struct extent_buffer *eb) { u32 nr = btrfs_header_nritems(eb); - u32 victim = rand() % nr; + u32 victim = rand_range(nr); u64 objectid; struct btrfs_key key; @@ -282,7 +282,7 @@ static void btrfs_corrupt_extent_tree(struct btrfs_trans_handle *trans, } if (btrfs_header_level(eb) == 1 && eb != root->node) { - if (rand() % 5) + if (rand_range(5)) return; } @@ -391,7 +391,7 @@ static u64 generate_u64(u64 orig) { u64 ret; do { - ret = rand(); + ret = rand_u64(); } while (ret == orig); return ret; } @@ -400,7 +400,7 @@ static u32 generate_u32(u32 orig) { u32 ret; do { - ret = rand(); + ret = rand_u32(); } while (ret == orig); return ret; } @@ -409,7 +409,7 @@ static u8 generate_u8(u8 orig) { u8 ret; do { - ret = rand(); + ret = rand_u8(); } while (ret == orig); return ret; } @@ -945,7 +945,7 @@ static int corrupt_chunk_tree(struct btrfs_trans_handle *trans, while (!btrfs_previous_item(root, path, 0, BTRFS_DEV_ITEM_KEY)) { slot = path->slots[0]; leaf = path->nodes[0]; - del = rand() % 3; + del = rand_range(3); /* Never delete the first item to keep the leaf structure */ if (path->slots[0] == 0) del = 0; @@ -972,7 +972,7 @@ static int corrupt_chunk_tree(struct btrfs_trans_handle *trans, while (!btrfs_previous_item(root, path, 0, BTRFS_CHUNK_ITEM_KEY)) { slot = path->slots[0]; leaf = path->nodes[0]; - del = rand() % 3; + del = rand_range(3); btrfs_item_key_to_cpu(leaf, &found_key, slot); ret = corrupt_item_nocow(trans, root, path, del); if (ret) @@ -1041,7 +1041,6 @@ int main(int argc, char **argv) char field[FIELD_BUF_LEN]; field[0] = '\0'; - srand(128); memset(&key, 0, sizeof(key)); while(1) { @@ -1180,7 +1179,7 @@ int main(int argc, char **argv) if (logical == (u64)-1) print_usage(1); - del = rand() % 3; + del = rand_range(3); path = btrfs_alloc_path(); if (!path) { fprintf(stderr, "path allocation failed\n"); -- cgit v1.2.3