From a4c05a4b31eaaacac765a7b103af9277e5e16ceb Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 11 Mar 2019 02:53:24 +0000 Subject: [PATCH] scst: Backport the percpu-ref code to kernel version 3.17 and before git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8046 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index b222ab2b2..4a9e65f48 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -872,8 +872,42 @@ static inline struct ib_pd *ib_alloc_pd_backport(struct ib_device *device) #endif /* */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0) || RHEL_MAJOR -0 >= 7 +#if defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 7 #include +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0) +#include +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 18, 0) +/* + * See also commit 2aad2a86f668 ("percpu_ref: add PERCPU_REF_INIT_* flags") + * # v3.18. + */ +static inline int __must_check percpu_ref_init_backport(struct percpu_ref *ref, + percpu_ref_func_t *release, unsigned int flags, + gfp_t gfp) +{ + WARN_ON_ONCE(flags != 0); + WARN_ON_ONCE(gfp != GFP_KERNEL); + return percpu_ref_init(ref, release); +} +#define percpu_ref_init percpu_ref_init_backport +#endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 17, 0) +/* + * See also commit 2d7227828e14 ("percpu-refcount: implement percpu_ref_reinit() + * and percpu_ref_is_zero()") # v3.17. + */ +static inline bool percpu_ref_is_zero(struct percpu_ref *ref) +{ + return !atomic_read(&ref->count); +} +/* + * See also commit 9a1049da9bd2 ("percpu-refcount: require percpu_ref to be + * exited explicitly") # v3.17. + */ +static inline void percpu_ref_exit(struct percpu_ref *ref) +{ +} +#endif #else struct percpu_ref; typedef void (percpu_ref_func_t)(struct percpu_ref *);