From bbfe5c8d211c8285a7d426f3efc92b13028e638d Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Tue, 13 Jun 2023 03:33:37 +0000 Subject: [PATCH] LU-12610 cfs: add unlikely to CFS_ macros Fix the (hopefully) last few OBD_ users to use CFS_ macros instead. Add an 'unlikely()' to CFS_ macros. Some of the OBD_ macros included this hint. Once those macros are removed, the hint will be lost. Add it to the CFS_ macros instead. The libcfs_fail.h only has a couple style issues left. Just fix them in this patch. Test-Parameters: trivial Signed-off-by: Timothy Day Change-Id: Ie06533b8b408cacf6f6fe2d29a1a8e727ca4280b Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/51291 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin --- libcfs/include/libcfs/libcfs_fail.h | 93 +++++++++++++++++++++++-------------- lustre/llite/rw.c | 2 +- lustre/llite/vvp_page.c | 2 +- lustre/mdt/mdt_open.c | 2 +- lustre/mdt/mdt_reint.c | 4 +- 5 files changed, 62 insertions(+), 41 deletions(-) diff --git a/libcfs/include/libcfs/libcfs_fail.h b/libcfs/include/libcfs/libcfs_fail.h index 9e57506..71b5900 100644 --- a/libcfs/include/libcfs/libcfs_fail.h +++ b/libcfs/include/libcfs/libcfs_fail.h @@ -43,16 +43,19 @@ int __cfs_fail_check_set(__u32 id, __u32 value, int set); int __cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set); enum { - CFS_FAIL_LOC_NOSET = 0, - CFS_FAIL_LOC_ORSET = 1, - CFS_FAIL_LOC_RESET = 2, - CFS_FAIL_LOC_VALUE = 3 + CFS_FAIL_LOC_NOSET = 0, + CFS_FAIL_LOC_ORSET = 1, + CFS_FAIL_LOC_RESET = 2, + CFS_FAIL_LOC_VALUE = 3 }; -/* Failure ranges - "0x0100 - 0x3fff" for Lustre - "0xe000 - 0xefff" for LNet - "0xf000 - 0xffff" for LNDs */ +/* + * Failure ranges: + * "0x0100 - 0x3fff" for Lustre + * "0xe000 - 0xefff" for LNet + * "0xf000 - 0xffff" for LNDs + */ + /* Failure injection control */ #define CFS_FAIL_MASK_SYS 0x0000FF00 #define CFS_FAIL_MASK_LOC (0x000000FF | CFS_FAIL_MASK_SYS) @@ -81,6 +84,9 @@ static inline bool CFS_FAIL_PRECHECK(__u32 id) (cfs_fail_loc & id & CFS_FAULT)); } +#define UNLIKELY_CHECK_SET(id, value, set, quiet) \ + (unlikely(cfs_fail_check_set(id, value, set, quiet))) + static inline int cfs_fail_check_set(__u32 id, __u32 value, int set, int quiet) { unsigned long failed_once = cfs_fail_loc & CFS_FAILED; /* ok if racy */ @@ -100,66 +106,81 @@ static inline int cfs_fail_check_set(__u32 id, __u32 value, int set, int quiet) return ret; } -/* If id hit cfs_fail_loc, return 1, otherwise return 0 */ +/* + *If id hit cfs_fail_loc, return 1, otherwise return 0 + */ #define CFS_FAIL_CHECK(id) \ - cfs_fail_check_set(id, 0, CFS_FAIL_LOC_NOSET, 0) + UNLIKELY_CHECK_SET(id, 0, CFS_FAIL_LOC_NOSET, 0) #define CFS_FAIL_CHECK_QUIET(id) \ - cfs_fail_check_set(id, 0, CFS_FAIL_LOC_NOSET, 1) + UNLIKELY_CHECK_SET(id, 0, CFS_FAIL_LOC_NOSET, 1) -/* If id hit cfs_fail_loc and cfs_fail_val == (-1 or value) return 1, - * otherwise return 0 */ +/* + * If id hit cfs_fail_loc and cfs_fail_val == (-1 or value) return 1, + * otherwise return 0 + */ #define CFS_FAIL_CHECK_VALUE(id, value) \ - cfs_fail_check_set(id, value, CFS_FAIL_LOC_VALUE, 0) + UNLIKELY_CHECK_SET(id, value, CFS_FAIL_LOC_VALUE, 0) #define CFS_FAIL_CHECK_VALUE_QUIET(id, value) \ - cfs_fail_check_set(id, value, CFS_FAIL_LOC_VALUE, 1) + UNLIKELY_CHECK_SET(id, value, CFS_FAIL_LOC_VALUE, 1) -/* If id hit cfs_fail_loc, cfs_fail_loc |= value and return 1, - * otherwise return 0 */ +/* + * If id hit cfs_fail_loc, cfs_fail_loc |= value and return 1, + * otherwise return 0 + */ #define CFS_FAIL_CHECK_ORSET(id, value) \ - cfs_fail_check_set(id, value, CFS_FAIL_LOC_ORSET, 0) + UNLIKELY_CHECK_SET(id, value, CFS_FAIL_LOC_ORSET, 0) #define CFS_FAIL_CHECK_ORSET_QUIET(id, value) \ - cfs_fail_check_set(id, value, CFS_FAIL_LOC_ORSET, 1) + UNLIKELY_CHECK_SET(id, value, CFS_FAIL_LOC_ORSET, 1) -/* If id hit cfs_fail_loc, cfs_fail_loc = value and return 1, - * otherwise return 0 */ +/* + * If id hit cfs_fail_loc, cfs_fail_loc = value and return 1, + * otherwise return 0 + */ #define CFS_FAIL_CHECK_RESET(id, value) \ - cfs_fail_check_set(id, value, CFS_FAIL_LOC_RESET, 0) + UNLIKELY_CHECK_SET(id, value, CFS_FAIL_LOC_RESET, 0) #define CFS_FAIL_CHECK_RESET_QUIET(id, value) \ - cfs_fail_check_set(id, value, CFS_FAIL_LOC_RESET, 1) + UNLIKELY_CHECK_SET(id, value, CFS_FAIL_LOC_RESET, 1) + +#define UNLIKELY_TIMEOUT_SET(id, value, ms, set) \ + (unlikely(cfs_fail_timeout_set(id, value, ms, set))) static inline int cfs_fail_timeout_set(__u32 id, __u32 value, int ms, int set) { - if (unlikely(CFS_FAIL_PRECHECK(id))) - return __cfs_fail_timeout_set(id, value, ms, set); - else - return 0; + if (unlikely(CFS_FAIL_PRECHECK(id))) + return __cfs_fail_timeout_set(id, value, ms, set); + else + return 0; } /* If id hit cfs_fail_loc, sleep for seconds or milliseconds */ #define CFS_FAIL_TIMEOUT(id, secs) \ - cfs_fail_timeout_set(id, 0, (secs) * 1000, CFS_FAIL_LOC_NOSET) + UNLIKELY_TIMEOUT_SET(id, 0, (secs) * 1000, CFS_FAIL_LOC_NOSET) #define CFS_FAIL_TIMEOUT_MS(id, ms) \ - cfs_fail_timeout_set(id, 0, ms, CFS_FAIL_LOC_NOSET) + UNLIKELY_TIMEOUT_SET(id, 0, ms, CFS_FAIL_LOC_NOSET) -/* If id hit cfs_fail_loc, cfs_fail_loc |= value and - * sleep seconds or milliseconds */ +/* + * If id hit cfs_fail_loc, cfs_fail_loc |= value and + * sleep seconds or milliseconds + */ #define CFS_FAIL_TIMEOUT_ORSET(id, value, secs) \ - cfs_fail_timeout_set(id, value, (secs) * 1000, CFS_FAIL_LOC_ORSET) + UNLIKELY_TIMEOUT_SET(id, value, (secs) * 1000, CFS_FAIL_LOC_ORSET) #define CFS_FAIL_TIMEOUT_RESET(id, value, secs) \ - cfs_fail_timeout_set(id, value, secs * 1000, CFS_FAIL_LOC_RESET) + UNLIKELY_TIMEOUT_SET(id, value, secs * 1000, CFS_FAIL_LOC_RESET) #define CFS_FAIL_TIMEOUT_MS_ORSET(id, value, ms) \ - cfs_fail_timeout_set(id, value, ms, CFS_FAIL_LOC_ORSET) + UNLIKELY_TIMEOUT_SET(id, value, ms, CFS_FAIL_LOC_ORSET) #define CFS_FAULT_CHECK(id) \ CFS_FAIL_CHECK(CFS_FAULT | (id)) -/* The idea here is to synchronise two threads to force a race. The +/* + * The idea here is to synchronise two threads to force a race. The * first thread that calls this with a matching fail_loc is put to * sleep. The next thread that calls with the same fail_loc wakes up - * the first and continues. */ + * the first and continues. + */ static inline void cfs_race(__u32 id) { if (CFS_FAIL_PRECHECK(id)) { diff --git a/lustre/llite/rw.c b/lustre/llite/rw.c index 0fc48f0..bdc0cd8 100644 --- a/lustre/llite/rw.c +++ b/lustre/llite/rw.c @@ -2057,7 +2057,7 @@ out: * races with the page being unlocked after readpage() but before it's * used by the caller */ - OBD_FAIL_TIMEOUT(OBD_FAIL_LLITE_READPAGE_PAUSE2, cfs_fail_val); + CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_READPAGE_PAUSE2, cfs_fail_val); RETURN(result); } diff --git a/lustre/llite/vvp_page.c b/lustre/llite/vvp_page.c index 5cdcda3..90af3f5 100644 --- a/lustre/llite/vvp_page.c +++ b/lustre/llite/vvp_page.c @@ -117,7 +117,7 @@ static void vvp_vmpage_error(struct inode *inode, struct page *vmpage, if (ioret == -ENOSPC) { set_bit(AS_ENOSPC, &inode->i_mapping->flags); } else { - if (OBD_FAIL_CHECK(OBD_FAIL_LLITE_PANIC_ON_ESTALE)) + if (CFS_FAIL_CHECK(OBD_FAIL_LLITE_PANIC_ON_ESTALE)) LBUG(); set_bit(AS_EIO, &inode->i_mapping->flags); } diff --git a/lustre/mdt/mdt_open.c b/lustre/mdt/mdt_open.c index fcfd8cd..a00924b 100644 --- a/lustre/mdt/mdt_open.c +++ b/lustre/mdt/mdt_open.c @@ -1669,7 +1669,7 @@ again_pw: } else { /* get openlock if this isn't replay and client requested it */ if (!req_is_replay(req)) { - OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_DELAY_OPEN, cfs_fail_val); + CFS_FAIL_TIMEOUT(OBD_FAIL_MDS_DELAY_OPEN, cfs_fail_val); rc = mdt_object_open_lock(info, child, lhc, &ibits); object_locked = 1; if (rc != 0) diff --git a/lustre/mdt/mdt_reint.c b/lustre/mdt/mdt_reint.c index ce0e657..01f87f1 100644 --- a/lustre/mdt/mdt_reint.c +++ b/lustre/mdt/mdt_reint.c @@ -355,7 +355,7 @@ int mdt_object_stripes_lock(struct mdt_thread_info *info, /* lock stripes for striped directory */ rc = mdt_stripes_lock(info, child, lh->mlh_reg_mode, ibits, einfo); - if (rc == -EIO && OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_SLAVE_NAME)) + if (rc == -EIO && CFS_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_SLAVE_NAME)) rc = 0; unlock: @@ -1986,7 +1986,7 @@ static int mdt_migrate_lookup(struct mdt_thread_info *info, &info->mti_spec); if ((rc == -ENOENT || rc == 0) && lmv_is_layout_changing(lmv)) { /* fail check here to let top dir migration succeed. */ - if (OBD_FAIL_CHECK_RESET(OBD_FAIL_MIGRATE_ENTRIES, 0)) + if (CFS_FAIL_CHECK_RESET(OBD_FAIL_MIGRATE_ENTRIES, 0)) GOTO(spobj_put, rc = -EIO); /* -- 1.8.3.1