From e1a0850c3570ae53df5779bc656f17b98b86f160 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Fri, 12 Jan 2018 09:36:26 -0800 Subject: [PATCH] Force ztest to always use /dev/urandom For ztest, which is solely for testing, using a pseudo random is entirely reasonable. Using /dev/urandom ensures the system entropy pool doesn't get depleted thus stalling the testing. This is a particular problem when testing in VMs. Reviewed-by: Tim Chase Reviewed by: Thomas Caputi Signed-off-by: Brian Behlendorf Closes #7017 Closes #7036 --- cmd/ztest/ztest.c | 7 ++++++- include/sys/zfs_context.h | 2 ++ lib/libzpool/kernel.c | 6 ++++-- rpm/generic/zfs.spec.in | 1 - scripts/zloop.sh | 12 ------------ 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/cmd/ztest/ztest.c b/cmd/ztest/ztest.c index 89ef1c4150..f07e11c836 100644 --- a/cmd/ztest/ztest.c +++ b/cmd/ztest/ztest.c @@ -7064,7 +7064,12 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } - ztest_fd_rand = open("/dev/urandom", O_RDONLY); + /* + * Force random_get_bytes() to use /dev/urandom in order to prevent + * ztest from needlessly depleting the system entropy pool. + */ + random_path = "/dev/urandom"; + ztest_fd_rand = open(random_path, O_RDONLY); ASSERT3S(ztest_fd_rand, >=, 0); if (!fd_data_str) { diff --git a/include/sys/zfs_context.h b/include/sys/zfs_context.h index 9da8ab5612..6f32b11c73 100644 --- a/include/sys/zfs_context.h +++ b/include/sys/zfs_context.h @@ -630,6 +630,8 @@ extern void delay(clock_t ticks); #define NN_NUMBUF_SZ (6) extern uint64_t physmem; +extern char *random_path; +extern char *urandom_path; extern int highbit64(uint64_t i); extern int lowbit64(uint64_t i); diff --git a/lib/libzpool/kernel.c b/lib/libzpool/kernel.c index c4b600d038..09e69ef6d2 100644 --- a/lib/libzpool/kernel.c +++ b/lib/libzpool/kernel.c @@ -907,13 +907,15 @@ lowbit64(uint64_t i) return (__builtin_ffsll(i)); } +char *random_path = "/dev/random"; +char *urandom_path = "/dev/urandom"; static int random_fd = -1, urandom_fd = -1; void random_init(void) { - VERIFY((random_fd = open("/dev/random", O_RDONLY)) != -1); - VERIFY((urandom_fd = open("/dev/urandom", O_RDONLY)) != -1); + VERIFY((random_fd = open(random_path, O_RDONLY)) != -1); + VERIFY((urandom_fd = open(urandom_path, O_RDONLY)) != -1); } void diff --git a/rpm/generic/zfs.spec.in b/rpm/generic/zfs.spec.in index b104e0d870..faa73e3b79 100644 --- a/rpm/generic/zfs.spec.in +++ b/rpm/generic/zfs.spec.in @@ -189,7 +189,6 @@ Requires: fio Requires: acl Requires: sudo Requires: sysstat -Requires: rng-tools AutoReqProv: no %description test diff --git a/scripts/zloop.sh b/scripts/zloop.sh index b6f6fc994d..2fcc807cd9 100755 --- a/scripts/zloop.sh +++ b/scripts/zloop.sh @@ -148,15 +148,6 @@ function store_core fi } -rngdpid="" -function on_exit -{ - if [ -n "$rngdpid" ]; then - kill -9 "$rngdpid" - fi -} -trap on_exit EXIT - # parse arguments # expected format: zloop [-t timeout] [-c coredir] [-- extra ztest args] coredir=$DEFAULTCOREDIR @@ -205,9 +196,6 @@ or_die rm -f ztest.history or_die rm -f ztest.ddt or_die rm -f ztest.cores -# start rngd in the background so we don't run out of entropy -or_die read -r rngdpid < <(rngd -f -r /dev/urandom & echo $!) - ztrc=0 # ztest return value foundcrashes=0 # number of crashes found so far starttime=$(date +%s)