diff --git a/scst/include/backport.h b/scst/include/backport.h index 809d22062..2b97997ab 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -30,15 +30,11 @@ (defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 8) #include #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0) #include /* struct bsg_job */ -#endif #include #include #include -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36) #include -#endif #include /* struct scatterlist */ #include /* kmalloc() */ #include /* sizeof_field() */ @@ -46,9 +42,7 @@ #include #include #include /* sync_page_range() */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) #include /* init_net */ -#endif #include #include /* struct scsi_cmnd */ #include /* scsi_build_sense_buffer() */ @@ -65,26 +59,6 @@ struct scsi_target; #define smp_mb__after_atomic_dec smp_mb__after_atomic #endif -/* */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27) && !defined(WARN) -/* See also commit a8f18b909c0a3f22630846207035c8b84bb252b8 */ -#define WARN(condition, format...) do { \ - if (unlikely(condition)) { \ - printk(KERN_WARNING format); \ - WARN_ON(true); \ - } \ -} while (0) -#endif - -/* */ - -#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 32) -#ifndef O_DSYNC -#define O_DSYNC O_SYNC -#endif -#endif - /* */ #ifdef CONFIG_X86 @@ -148,13 +122,7 @@ enum { static inline unsigned int scst_blk_rq_cpu(struct request *rq) { -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28) - /* - * See also commit c7c22e4d5c1f ("block: add support for IO CPU - * affinity") # v2.6.28. - */ - return 0; -#elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 21, 0) && \ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 21, 0) && \ (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 8) return rq->cpu; #else @@ -162,46 +130,6 @@ static inline unsigned int scst_blk_rq_cpu(struct request *rq) #endif } -/* */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) -static inline unsigned int queue_max_hw_sectors(struct request_queue *q) -{ - return q->max_hw_sectors; -} -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32) -/* See also commit ac481c20ef8f ("block: Topology ioctls") # v2.6.32 */ -static inline int bdev_io_opt(struct block_device *bdev) -{ - return 0; -} -#endif - -/* - * See also commit d4d77629953e ("block: clean up blkdev_get() wrappers and - * their users") # v2.6.38. - */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38) -static inline struct block_device * -blkdev_get_by_path(const char *path, fmode_t mode, void *holder) -{ - struct block_device *bdev; - int err; - - bdev = lookup_bdev(path); - if (IS_ERR(bdev)) - return bdev; - - err = blkdev_get(bdev, mode); - if (err) - return ERR_PTR(err); - - return bdev; -} -#endif - #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 12, 0) /* * See also commit 8eeed0b554b9 ("block: remove unnecessary argument from @@ -222,7 +150,6 @@ static inline void blk_execute_rq_nowait_backport(struct gendisk *bd_disk, * Note: the function bsg_job_sense() exists only in SCST but not in any * upstream kernel. */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31) #if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 10, 0) && \ !defined(CONFIG_SUSE_KERNEL)) || \ (LINUX_VERSION_CODE < KERNEL_VERSION(4, 4, 0) && \ @@ -244,7 +171,6 @@ static inline void *bsg_job_sense(struct bsg_job *job) #endif } #endif -#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31) */ /* */ /* @@ -274,21 +200,6 @@ static inline void be32_to_cpu_array(u32 *dst, const __be32 *src, size_t len) /* */ -#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 20) -#ifndef __printf -#define __printf(a, b) __attribute__((format(printf, a, b))) -#endif -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 21) -#ifndef __aligned -#define __aligned(x) __attribute__((aligned(x))) -#endif -#ifndef __packed -#define __packed __attribute__((packed)) -#endif -#endif - #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) && !defined(READ_ONCE) /* * See also patch "kernel: Provide READ_ONCE and ASSIGN_ONCE" (commit ID @@ -296,18 +207,6 @@ static inline void be32_to_cpu_array(u32 *dst, const __be32 *src, size_t len) */ #define READ_ONCE(x) (*(volatile typeof(x) *)&(x)) -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26) -#define ACCESS_ONCE(x) READ_ONCE(x) -#endif - -#endif - -/* - * See also commit e0fdb0e050ea ("percpu: add __percpu for sparse.") - * # v2.6.34. - */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) && !defined(__percpu) -#define __percpu #endif /* */ @@ -328,122 +227,6 @@ static inline void be32_to_cpu_array(u32 *dst, const __be32 *src, size_t len) #endif #endif -/* */ - -#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 20) && !defined(BACKPORT_LINUX_CPUMASK_H) -#define nr_cpu_ids NR_CPUS -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28) && defined(__LINUX_CPUMASK_H) -/* - * See also patch "cpumask: introduce new API, without changing anything" - * (commit ID 2d3854a37e8b). - */ -typedef cpumask_t cpumask_var_t[1]; -#define cpumask_bits(maskp) ((maskp)->bits) -#ifdef CONFIG_CPUMASK_OFFSTACK -/* - * Assuming NR_CPUS is huge, a runtime limit is more efficient. Also, - * not all bits may be allocated. - */ -#define nr_cpumask_bits nr_cpu_ids -#else -#define nr_cpumask_bits NR_CPUS -#endif - -#ifdef CONFIG_CPUMASK_OFFSTACK -bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags); -void free_cpumask_var(cpumask_var_t mask); -#else -static inline void free_cpumask_var(cpumask_var_t mask) -{ -} - -static inline bool alloc_cpumask_var(cpumask_var_t *mask, gfp_t flags) -{ - return true; -} -#endif - -/* verify cpu argument to cpumask_* operators */ -static inline unsigned int cpumask_check(unsigned int cpu) -{ -#ifdef CONFIG_DEBUG_PER_CPU_MAPS - WARN_ON_ONCE(cpu >= nr_cpumask_bits); -#endif /* CONFIG_DEBUG_PER_CPU_MAPS */ - return cpu; -} - -/** - * cpumask_next - get the next cpu in a cpumask - * @n: the cpu prior to the place to search (ie. return will be > @n) - * @srcp: the cpumask pointer - * - * Returns >= nr_cpu_ids if no further cpus set. - */ -static inline unsigned int cpumask_next(int n, const cpumask_t *srcp) -{ - /* -1 is a legal arg here. */ - if (n != -1) - cpumask_check(n); - return find_next_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1); -} - -/** - * for_each_cpu - iterate over every cpu in a mask - * @cpu: the (optionally unsigned) integer iterator - * @mask: the cpumask pointer - * - * After the loop, cpu is >= nr_cpu_ids. - */ -#define for_each_cpu(cpu, mask) \ - for ((cpu) = -1; \ - (cpu) = cpumask_next((cpu), (mask)), \ - (cpu) < nr_cpu_ids;) - -/** - * cpumask_set_cpu - set a cpu in a cpumask - * @cpu: cpu number (< nr_cpu_ids) - * @dstp: the cpumask pointer - */ -static inline void cpumask_set_cpu(unsigned int cpu, cpumask_t *dstp) -{ - set_bit(cpu, cpumask_bits(dstp)); -} - -/** - * cpumask_copy - *dstp = *srcp - * @dstp: the result - * @srcp: the input cpumask - */ -static inline void cpumask_copy(cpumask_t *dstp, - const cpumask_t *srcp) -{ - bitmap_copy(cpumask_bits(dstp), cpumask_bits(srcp), nr_cpumask_bits); -} - -/** - * cpumask_setall - set all cpus (< nr_cpu_ids) in a cpumask - * @dstp: the cpumask pointer - */ -static inline void cpumask_setall(cpumask_t *dstp) -{ - bitmap_fill(cpumask_bits(dstp), nr_cpumask_bits); -} - -/** - * cpumask_equal - *src1p == *src2p - * @src1p: the first input - * @src2p: the second input - */ -static inline bool cpumask_equal(const cpumask_t *src1p, - const cpumask_t *src2p) -{ - return bitmap_equal(cpumask_bits(src1p), cpumask_bits(src2p), - nr_cpumask_bits); -} -#endif - /* */ /* @@ -491,13 +274,6 @@ static inline ssize_t debugfs_attr_write(struct file *file, /* */ -/* See also commit 0f8e0d9a317406612700426fad3efab0b7bbc467 */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28) -enum { - DLM_LSFL_NEWEXCL = 0 -}; -#endif - /* */ #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) && \ @@ -564,34 +340,6 @@ typedef unsigned int __poll_t; /* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0) && \ - !defined(CONFIG_COMPAT_KERNEL_3_12) -/* - * See also patch "new helper: file_inode(file)" (commit ID - * 496ad9aa8ef448058e36ca7a787c61f2e63f0f54). See also patch - * "kill f_dentry macro" (commit ID 78d28e651f97). - */ -static inline struct inode *file_inode(const struct file *f) -{ - return f->f_dentry->d_inode; -} -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) -static inline int vfs_fsync_backport(struct file *file, int datasync) -{ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) - struct inode *inode = file_inode(file); - - return sync_page_range(inode, file->f_mapping, 0, i_size_read(inode)); -#else - return vfs_fsync(file, file->f_path.dentry, datasync); -#endif -} - -#define vfs_fsync vfs_fsync_backport -#endif - #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 7, 0) /* See also commit dde0c2e79848 ("fs: add IOCB_SYNC and IOCB_DSYNC") */ #define IOCB_DSYNC 0 @@ -636,7 +384,6 @@ kernel_read_backport(struct file *file, void *buf, size_t count, loff_t *pos) #define kernel_read(file, buf, count, pos) \ kernel_read_backport((file), (buf), (count), (pos)) -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) || defined(RHEL_MAJOR) /* * See also commit 7bb307e894d5 ("export kernel_write(), convert open-coded * instances") # v3.9. @@ -658,30 +405,11 @@ kernel_write_backport(struct file *file, const void *buf, size_t count, } #define kernel_write kernel_write_backport -#else -ssize_t kernel_write(struct file *file, const void *buf, size_t count, - loff_t *pos); -#endif -#endif - -/* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) && !defined(RHEL_MAJOR) -/* - * See also commit cd7eab44e994 ("genirq: Add IRQ affinity notifiers"; - * v2.6.39). - */ -struct irq_affinity_notify; -static inline int -irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify) -{ - return 0; -} #endif /* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) || \ - LINUX_VERSION_CODE >= KERNEL_VERSION(4, 21, 0) || \ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 21, 0) || \ (defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 8) static inline struct io_context * @@ -703,146 +431,6 @@ static inline void scst_ioc_task_link(struct io_context *ioc) #define put_io_context scst_put_io_context #define ioc_task_link scst_ioc_task_link -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25) && \ - LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0) -static inline struct io_context *get_task_io_context(struct task_struct *task, - gfp_t gfp_flags, int node) -{ - WARN_ON_ONCE(task != current); - return get_io_context(gfp_flags, node); -} -#endif - -/* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0) && !defined(RHEL_MAJOR) -/* - * See also commit 2a11c8ea20bf ("kconfig: Introduce IS_ENABLED(), IS_BUILTIN() - * and IS_MODULE()") # v3.1. - */ -#define __ARG_PLACEHOLDER_1 0, -#define __take_second_arg(__ignored, val, ...) val -#define __or(x, y) ___or(x, y) -#define ___or(x, y) ____or(__ARG_PLACEHOLDER_##x, y) -#define ____or(arg1_or_junk, y) __take_second_arg(arg1_or_junk 1, y) -#define __is_defined(x) ___is_defined(x) -#define ___is_defined(val) ____is_defined(__ARG_PLACEHOLDER_##val) -#define ____is_defined(arg1_or_junk) __take_second_arg(arg1_or_junk 1, 0) -#define IS_BUILTIN(option) __is_defined(option) -#define IS_MODULE(option) __is_defined(option##_MODULE) -#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option)) -#endif - -/* */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) -#ifndef RHEL_RELEASE_CODE -typedef _Bool bool; -#endif -#define true 1 -#define false 0 -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29) -#ifndef swap -#define swap(a, b) \ - do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) -#endif -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) && \ - (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 6 || \ - RHEL_MAJOR -0 == 6 && RHEL_MINOR -0 < 1) -extern int hex_to_bin(char ch); -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) && !defined(RHEL_MAJOR) -/* See also commit 9b3be9f99203 ("Move round_up/down to kernel.h") # v2.6.34 */ -/* - * This looks more complex than it should be. But we need to - * get the type for the ~ right in round_down (it needs to be - * as wide as the result!), and we want to evaluate the macro - * arguments just once each. - */ -#define __round_mask(x, y) ((__typeof__(x))((y)-1)) -/** - * round_up - round up to next specified power of 2 - * @x: the value to round - * @y: multiple to round up to (must be a power of 2) - * - * Rounds @x up to next multiple of @y (which must be a power of 2). - * To perform arbitrary rounding up, use roundup() below. - */ -#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) -/** - * round_down - round down to next specified power of 2 - * @x: the value to round - * @y: multiple to round down to (must be a power of 2) - * - * Rounds @x down to next multiple of @y (which must be a power of 2). - * To perform arbitrary rounding down, use rounddown() below. - */ -#define round_down(x, y) ((x) & ~__round_mask(x, y)) -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38) -/* - * See also "lib: hex2bin converts ascii hexadecimal string to binary" (commit - * dc88e46029486ed475c71fe1bb696d39511ac8fe). - */ -static inline void hex2bin(u8 *dst, const char *src, size_t count) -{ - while (count--) { - *dst = hex_to_bin(*src++) << 4; - *dst += hex_to_bin(*src++); - dst++; - } -} -#endif - -/* - * See also commit 33ee3b2e2eb9. That commit was introduced in kernel v2.6.39 - * and later backported to kernel v2.6.38.4. - */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) && \ - LINUX_VERSION_CODE != KERNEL_VERSION(2, 6, 38) && \ - (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 6) -static inline int __must_check kstrtoull(const char *s, unsigned int base, - unsigned long long *res) -{ - return strict_strtoull(s, base, res); -} - -static inline int __must_check kstrtoll(const char *s, unsigned int base, - long long *res) -{ - return strict_strtoll(s, base, res); -} - -static inline int __must_check kstrtoul(const char *s, unsigned int base, - unsigned long *res) -{ - return strict_strtoul(s, base, res); -} - -static inline int __must_check kstrtol(const char *s, unsigned int base, - long *res) -{ - return strict_strtol(s, base, res); -} - -static inline int __must_check kstrtoint(const char *s, unsigned int base, - int *result) -{ - long val; - int ret = strict_strtol(s, base, &val); - - if (ret) - return ret; - *result = val; - if (*result != val) - return -EINVAL; - return 0; -} #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 17, 0) @@ -920,30 +508,9 @@ static inline long get_user_pages_backport(unsigned long start, #define get_user_pages get_user_pages_backport #endif -/* */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) -enum umh_wait { - UMH_NO_WAIT = -1, /* don't wait at all */ - UMH_WAIT_EXEC = 0, /* wait for the exec, but not the process */ - UMH_WAIT_PROC = 1, /* wait for the process to complete */ -}; -#endif - /* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) -/* - * See also commit 608b4b9548de ("netns: Teach network device kobjects which - * namespace they are in.") # v2.6.35. - */ -enum kobj_ns_type { - KOBJ_NS_TYPE_NET = 1, -}; -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) && \ - LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0) && \ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0) && \ (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 7) /* * See also commit 5f256becd868 ("[NET]: Basic network namespace @@ -968,46 +535,14 @@ static inline void kobj_ns_drop_backport(enum kobj_ns_type type, void *ns) /* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0) && \ - !(LINUX_VERSION_CODE >> 8 == KERNEL_VERSION(3, 4, 0) >> 8 && \ - LINUX_VERSION_CODE >= KERNEL_VERSION(3, 4, 41)) && \ - !(LINUX_VERSION_CODE >> 8 == KERNEL_VERSION(3, 2, 0) >> 8 && \ - LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 44)) && \ - (!defined(CONFIG_SUSE_KERNEL) || \ - LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 101)) && \ - (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 6 || \ - (RHEL_MAJOR -0 == 6 && RHEL_MINOR -0 < 6)) -/* - * See also commit 4b20db3 (kref: Implement kref_get_unless_zero v3 -- v3.8). - * See also commit e3a5505 in branch stable/linux-3.4.y (v3.4.41). - * See also commit 3fa8ee5 in branch stable/linux-3.2.y (v3.2.44). - * See also commit 6b9508d in the SuSE kernel tree. - */ -static inline int __must_check kref_get_unless_zero(struct kref *kref) -{ - return atomic_add_unless(&kref->refcount, 1, 0); -} -#endif - /* See also commit 2c935bc57221 */ #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) #define kref_read(kref) (atomic_read(&(kref)->refcount)) #endif -/* */ - -/* See also commit 207205a2ba26 */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 39) && \ - (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 6 || \ - RHEL_MAJOR -0 == 6 && RHEL_MINOR -0 < 9) -#define kthread_create_on_node(threadfn, data, node, namefmt, arg...)\ - kthread_create((threadfn), (data), (namefmt), ##arg) -#endif - /* */ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) && \ - LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0)) && \ +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0)) && \ (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 7) /** * ktime_before - Compare if a ktime_t value is smaller than another one. @@ -1040,10 +575,6 @@ static inline bool list_entry_in_list(const struct list_head *entry) /* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32) -#define lockdep_assert_held(l) (void)(l) -#endif - /* * See also commit 108c14858b9e ("locking/lockdep: Add support for dynamic * keys"). @@ -1237,30 +768,6 @@ struct nvmefc_fcp_req { } __aligned(sizeof(u64)); /* alignment for other things alloc'd with */ #endif -/* */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0) && !defined(RHEL_MAJOR) -/* - * See also commit 8c0d3a02c130 ("PCI: Add accessors for PCI Express - * Capability") # v3.7. - */ -static inline int pcie_capability_read_word(struct pci_dev *dev, int pos, - u16 *val) -{ - WARN_ON_ONCE(true); - *val = 0; - return -EOPNOTSUPP; -} - -static inline int pcie_capability_read_dword(struct pci_dev *dev, int pos, - u32 *val) -{ - WARN_ON_ONCE(true); - *val = 0; - return -EOPNOTSUPP; -} -#endif - /* */ #if defined(RHEL_MAJOR) && RHEL_MAJOR -0 >= 7 || \ @@ -1534,144 +1041,8 @@ static inline unsigned long percpu_ref_read(struct percpu_ref *ref) return READ_REF_COUNT(ref) - !percpu_ref_is_dying(ref); } -/* */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) -/* - * See also patch "sched: Fix softirq time accounting" (commit ID - * 75e1056f5c57050415b64cb761a3acc35d91f013). - */ -#ifndef in_serving_softirq -#define in_serving_softirq() in_softirq() -#endif -#endif - -/* */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) && !defined(RHEL_MAJOR) -#define KERN_CONT "" -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28) -/* - * See also the following commits: - * d091c2f5 - Introduction of pr_info() etc. in . - * 311d0761 - Introduction of pr_cont() in . - * 968ab183 - Moved pr_info() etc. from to - */ -#ifndef pr_emerg - -#ifndef pr_fmt -#define pr_fmt(fmt) fmt -#endif - -#define pr_emerg(fmt, ...) printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) -#define pr_alert(fmt, ...) printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) -#define pr_crit(fmt, ...) printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) -#define pr_err(fmt, ...) printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) -#define pr_warn(fmt, ...) printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) -#define pr_notice(fmt, ...) printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) - -#endif /* pr_emerg */ - -#ifndef pr_info -#define pr_info(fmt, ...) printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) -#endif - -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28) */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30) -#ifndef pr_cont -#define pr_cont(fmt, ...) printk(KERN_CONT fmt, ##__VA_ARGS__) -#endif -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30) */ - -/* See also commit f036be96dd9c ("printk: introduce printk_once()") */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 30) -#define printk_once(fmt, ...) \ -({ \ - static bool __print_once __read_mostly; \ - bool __ret_print_once = !__print_once; \ - \ - if (!__print_once) { \ - __print_once = true; \ - printk(fmt, ##__VA_ARGS__); \ - } \ - unlikely(__ret_print_once); \ -}) -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38) -/* - * See also commit 16cb839f1332 ("include/linux/printk.h: add pr__once - * macros") # v2.6.38. - */ -#define pr_warn_once(fmt, ...) \ - printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35) -/* - * See also patch "kernel.h: add pr_warn for symmetry to dev_warn, - * netdev_warn" (commit fc62f2f19edf46c9bdbd1a54725b56b18c43e94f). - */ -#ifndef pr_warn -#define pr_warn pr_warning -#endif -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) && \ - (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 6) -/* - * See also patch "Add a dummy printk function for the maintenance of unused - * printks" (commit 12fdff3fc2483f906ae6404a6e8dcf2550310b6f). - */ -static inline __attribute__ ((format (printf, 1, 2))) -int no_printk(const char *s, ...) { return 0; } -#endif - -/* */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27) -/* See also commit 717115e1a585 */ - -#define DEFAULT_RATELIMIT_INTERVAL (5 * HZ) -#define DEFAULT_RATELIMIT_BURST 10 - -struct ratelimit_state { - int interval; - int burst; -}; - -#define DEFINE_RATELIMIT_STATE(name, interval, burst) \ - struct ratelimit_state name = {interval, burst,} - -static inline int __ratelimit(struct ratelimit_state *rs) -{ - return 1; -} -#endif - /* */ -/* See also commit b62730baea32 */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 34) -#define rcu_dereference_protected(p, c) rcu_dereference(p) -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 0, 0) && !defined(kfree_rcu) -typedef void (*rcu_callback_t)(struct rcu_head *); -#define __is_kfree_rcu_offset(offset) ((offset) < 4096) -#define kfree_call_rcu(head, rcb) call_rcu(head, rcb) -#define __kfree_rcu(head, offset) \ - do { \ - BUILD_BUG_ON(!__is_kfree_rcu_offset(offset)); \ - kfree_call_rcu(head, (rcu_callback_t)(unsigned long)(offset)); \ - } while (0) -#define kfree_rcu(ptr, rcu_head) \ - __kfree_rcu(&((ptr)->rcu_head), offsetof(typeof(*(ptr)), rcu_head)) -#endif - #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) && \ (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 7 || \ RHEL_MAJOR -0 == 7 && RHEL_MINOR -0 < 7) @@ -1683,95 +1054,6 @@ static inline void init_rcu_head(struct rcu_head *head) { } static inline void destroy_rcu_head(struct rcu_head *head) { } #endif -/* */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) -/* - * The macro's sg_page(), sg_virt(), sg_init_table(), sg_assign_page() and - * sg_set_page() have been introduced in the 2.6.24 kernel. The definitions - * below are backports of the 2.6.24 macro's for older kernels. There is one - * exception however: when compiling SCST on a system with a pre-2.6.24 kernel - * (e.g. RHEL 5.x) where the OFED kernel headers have been installed, do not - * define the backported macro's because OFED has already defined these. - */ - -static inline bool sg_is_chain(struct scatterlist *sg) -{ - return false; -} - -static inline struct scatterlist *sg_chain_ptr(struct scatterlist *sg) -{ - return NULL; -} - -#define sg_is_last(sg) false - -#ifndef sg_page -static inline struct page *sg_page(struct scatterlist *sg) -{ - return sg->page; -} -#endif - -static inline void *sg_virt(struct scatterlist *sg) -{ - return page_address(sg_page(sg)) + sg->offset; -} - -static inline void sg_mark_end(struct scatterlist *sg) -{ -} - -static inline void sg_unmark_end(struct scatterlist *sg) -{ -} - -#ifndef __BACKPORT_LINUX_SCATTERLIST_H_TO_2_6_23__ - -static inline void sg_init_table(struct scatterlist *sgl, unsigned int nents) -{ - memset(sgl, 0, sizeof(*sgl) * nents); -} - -static inline void sg_assign_page(struct scatterlist *sg, struct page *page) -{ - sg->page = page; -} - -static inline void sg_set_page(struct scatterlist *sg, struct page *page, - unsigned int len, unsigned int offset) -{ - sg_assign_page(sg, page); - sg->offset = offset; - sg->length = len; -} - -#ifndef for_each_sg -/* See also commit 96b418c960af0d5c7185ff5c4af9376eb37ac9d3 */ -#define for_each_sg(sglist, sg, nr, __i) \ - for (__i = 0, sg = (sglist); __i < (nr); __i++, sg = sg_next_inline(sg)) -#endif /* for_each_sg */ - -#endif /* __BACKPORT_LINUX_SCATTERLIST_H_TO_2_6_23__ */ -#elif LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) -/* - * See also commit c8164d8931fd ("scatterlist: introduce sg_unmark_end"; - * v3.10). - */ -static inline void sg_unmark_end(struct scatterlist *sg) -{ - sg->page_link &= ~0x02; -} -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) */ - -/* */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26) && \ - (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 6) -#define set_cpus_allowed_ptr(p, new_mask) set_cpus_allowed((p), *(new_mask)) -#endif - /* */ /* @@ -1806,12 +1088,6 @@ static const struct file_operations __name ## _fops = { \ /* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22) -#define KMEM_CACHE(__struct, __flags) kmem_cache_create(#__struct,\ - sizeof(struct __struct), __alignof__(struct __struct),\ - (__flags), NULL, NULL) -#endif - #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) && \ !defined(_COMPAT_LINUX_MM_H) /* @@ -1827,36 +1103,14 @@ static inline void kmem_cache_destroy_backport(struct kmem_cache *s) #define kmem_cache_destroy kmem_cache_destroy_backport #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0) && \ - !(LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 52) && \ - LINUX_VERSION_CODE < KERNEL_VERSION(3, 3, 0)) && \ - (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 6) -static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) -{ - if (size != 0 && n > ULONG_MAX / size) - return NULL; - return kmalloc(n * size, flags); -} -#endif - /* * See also commit 8eb8284b4129 ("usercopy: Prepare for usercopy * whitelisting"). - */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) -static inline struct kmem_cache *kmem_cache_create_usercopy(const char *name, - unsigned int size, unsigned int align, - unsigned long flags, - unsigned int useroffset, unsigned int usersize, - void (*ctor)(void *)) -{ - return kmem_cache_create(name, size, align, flags, ctor, NULL); -} -/* + * * UEK4 is based on kernel v4.1.12 and does not have a backport of the v4.16 * API. UEK5 is based on kernel v4.14.35 and has a backport of the v4.16 API. */ -#elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0) && \ +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0) && \ (!defined(UEK_KABI_RENAME) || \ LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)) static inline struct kmem_cache *kmem_cache_create_usercopy(const char *name, @@ -1980,20 +1234,6 @@ struct t10_pi_tuple { (unsigned long)&(_name)) #endif -/* */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) -/* - * See also patch "fix abuses of ptrdiff_t" (commit ID - * 142956af525002c5378e7d91d81a01189841a785). - */ -typedef unsigned long uintptr_t; -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22) -char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap); -#endif - /* */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) @@ -2071,56 +1311,13 @@ static inline void put_unaligned_be24(const uint32_t v, uint8_t *const p) } #endif -/* */ - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) && \ - (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 5 || \ - RHEL_MAJOR -0 == 5 && RHEL_MINOR -0 < 10 || \ - RHEL_MAJOR -0 == 6 && RHEL_MINOR -0 < 1) -/* - * See also patch "mm: add vzalloc() and vzalloc_node() helpers" (commit - * e1ca7788dec6773b1a2bce51b7141948f2b8bccf). - */ -static inline void *vzalloc(unsigned long size) -{ - return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, - PAGE_KERNEL); -} -#endif - /* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) /* - * See also commit d320c03830b1 ("workqueue: s/__create_workqueue()/ - * alloc_workqueue()/, and add system workqueues") # v2.6.36. - */ -static inline struct workqueue_struct *alloc_workqueue(const char *fmt, - unsigned int flags, - int max_active, ...) -{ - WARN_ON_ONCE(flags | max_active); - return create_workqueue(fmt); -} -#endif - -/* - * See also commits 18aa9effad4a ("workqueue: implement WQ_NON_REENTRANT"; - * v2.6.36) and commits dbf2576e37da ("workqueue: make all workqueues + * See also commits dbf2576e37da ("workqueue: make all workqueues * non-reentrant"; v3.7). */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) || \ - LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0) #define WQ_NON_REENTRANT 0 -#endif - -/* - * See also commit 226223ab3c41 ("workqueue: implement sysfs interface for - * workqueues"; v3.10). - */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 10, 0) -#define WQ_SYSFS 0 -#endif /* * To do: backport alloc_ordered_workqueue(). See also commit 81dcaf6516d8 @@ -2178,8 +1375,7 @@ static inline uint8_t driver_byte(uint32_t result) /* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24) || \ - LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0) || \ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0) || \ (defined(RHEL_RELEASE_CODE) && \ RHEL_RELEASE_CODE -0 >= RHEL_RELEASE_VERSION(8, 3)) /* @@ -2289,13 +1485,8 @@ static inline void scsi_req_init(struct request *rq) { #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0) rq->cmd_type = REQ_TYPE_BLOCK_PC; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31) - rq->data_len = 0; - rq->sector = (sector_t) -1; -#else rq->__data_len = 0; rq->__sector = (sector_t) -1; -#endif rq->bio = rq->biotail = NULL; memset(rq->__cmd, 0, sizeof(rq->__cmd)); rq->cmd = rq->__cmd;