From c9680a33ec34059928a7677691084d57205b17c0 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 10 Mar 2019 05:14:42 +0000 Subject: [PATCH 1/2] scst: Add a percpu_ref backport for kernel versions before 3.11, e.g. RHEL 6 git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8036 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 68 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/scst/include/backport.h b/scst/include/backport.h index c13c2c1bb..ad993b748 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -30,6 +30,9 @@ #endif #include #include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0) +#include +#endif #include /* struct scatterlist */ #include /* kmalloc() */ #include /* sizeof_field() */ @@ -871,6 +874,71 @@ static inline struct ib_pd *ib_alloc_pd_backport(struct ib_device *device) #define set_cpus_allowed_ptr(p, new_mask) set_cpus_allowed((p), *(new_mask)) #endif +/* */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) +struct percpu_ref; +typedef void (percpu_ref_func_t)(struct percpu_ref *); + +struct percpu_ref { + atomic_long_t count; + percpu_ref_func_t *release; +}; + +/* @flags for percpu_ref_init() */ +enum { + PERCPU_REF_INIT_ATOMIC = 1 << 0, + PERCPU_REF_INIT_DEAD = 1 << 1, +}; + +static inline int __must_check percpu_ref_init(struct percpu_ref *ref, + percpu_ref_func_t *release, unsigned int flags, + gfp_t gfp) +{ + WARN_ON_ONCE(flags != PERCPU_REF_INIT_ATOMIC); + atomic_long_set(&ref->count, 1); + ref->release = release; + return 0; +} + +static inline void percpu_ref_exit(struct percpu_ref *ref) +{ +} + +static inline void percpu_ref_switch_to_atomic(struct percpu_ref *ref, + percpu_ref_func_t *confirm_switch) +{ +} + +static inline void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref) +{ +} + +static inline void percpu_ref_switch_to_percpu(struct percpu_ref *ref) +{ +} + +static inline void percpu_ref_get(struct percpu_ref *ref) +{ + atomic_long_inc(&ref->count); +} + +static inline void percpu_ref_put(struct percpu_ref *ref) +{ + if (unlikely(atomic_long_dec_and_test(&ref->count))) + ref->release(ref); +} + +static inline void percpu_ref_kill(struct percpu_ref *ref) +{ + percpu_ref_put(ref); +} + +static inline bool percpu_ref_is_zero(struct percpu_ref *ref) +{ + return !atomic_long_read(&ref->count); +} +#endif + /* */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) From c03a6ffd5efc7511a864683498f129b0ba78309a Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 10 Mar 2019 05:18:41 +0000 Subject: [PATCH 2/2] scst, backport.h: Fix RHEL 7 build git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8037 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/include/backport.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index ad993b748..19e4cd246 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -875,7 +875,7 @@ static inline struct ib_pd *ib_alloc_pd_backport(struct ib_device *device) #endif /* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 11, 0) && RHEL_MAJOR -0 <= 6 struct percpu_ref; typedef void (percpu_ref_func_t)(struct percpu_ref *);