From: Alex Zhuravlev Date: Tue, 30 Mar 2021 05:57:14 +0000 (+0300) Subject: LU-13358 libcfs: add timeout to cfs_race() to fix race X-Git-Tag: 2.14.56~96 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=2d2d381f35ee004319a20f5d2d8e70d13480d6c7;hp=e6c7fcdaf40b130c39af2e3ee8b108c6e31a8ca8;ds=sidebyside LU-13358 libcfs: add timeout to cfs_race() to fix race there is no guarantee for the branches in cfs_race() to be executed in strict order, thus it's possible that the second branch (with cfs_race_state=1) is executed before the first branch and then another thread executing the first branch gets stuck. this construction is used for testing only and as a workaround it's enough to timeout. Signed-off-by: Alex Zhuravlev Change-Id: Ie1cc0accedb3e1a198d4b17d1ab00ce298c560f2 Reviewed-on: https://review.whamcloud.com/43161 Reviewed-by: James Simmons Reviewed-by: Neil Brown Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/libcfs/include/libcfs/libcfs_fail.h b/libcfs/include/libcfs/libcfs_fail.h index 18a51d9..511db02 100644 --- a/libcfs/include/libcfs/libcfs_fail.h +++ b/libcfs/include/libcfs/libcfs_fail.h @@ -167,8 +167,14 @@ static inline void cfs_race(__u32 id) int rc; cfs_race_state = 0; CERROR("cfs_race id %x sleeping\n", id); - rc = wait_event_interruptible(cfs_race_waitq, - cfs_race_state != 0); + /* + * XXX: don't wait forever as there is no guarantee + * that this branch is executed first. for testing + * purposes this construction works good enough + */ + rc = wait_event_interruptible_timeout(cfs_race_waitq, + cfs_race_state != 0, + cfs_time_seconds(5)); CERROR("cfs_fail_race id %x awake: rc=%d\n", id, rc); } else { CERROR("cfs_fail_race id %x waking\n", id);