From 4db086ac5d528335d3364089041a798c834ddaa5 Mon Sep 17 00:00:00 2001 From: jrivera-px Date: Sat, 29 Aug 2020 15:35:04 -0700 Subject: [PATCH] Compile fixes 4x 5x kernels (#148) * Compile fixes for 5.8.x, 4.12.x & 4.13.x EL7 kernels. * Merge in master 'Suse compile fixes PR #147 (bc03ffa)' --- Makefile.in | 10 +++++----- pxd.c | 16 ++++++---------- pxd_compat.h | 12 ++++++++++-- pxd_fastpath.c | 44 +++++++++++++++++++++++++++++++++----------- 4 files changed, 54 insertions(+), 28 deletions(-) mode change 100755 => 100644 Makefile.in diff --git a/Makefile.in b/Makefile.in old mode 100755 new mode 100644 index ee67a348..8940a96c --- a/Makefile.in +++ b/Makefile.in @@ -31,7 +31,7 @@ endif MINKVER=3.10 FPATH_MINKVER=4.10 BLKMQ_MINKVER=4.18 -KERNELVER=$(shell echo $(KVERSION) | /bin/sed 's/\([0-9].[0-9]\+\).*/\1/g') +KERNELVER=$(shell echo $(CHK_KVER) | /bin/sed 's/\([0-9].[0-9]\+\).*/\1/g') majorfn=$(shell echo "$1" | /bin/sed 's/\(.*\)\.\(.*\)/\1/g') minorfn=$(shell echo "$1" | /bin/sed 's/\(.*\)\.\(.*\)/\2/g') @@ -85,20 +85,20 @@ endif ifeq ($(call verlater,${kmajor},${fp_major}),0) PXDEFINES += -D__PX_FASTPATH__ px-objs += pxd_fastpath.o -$(info Kernel fast path enabled, current kernel version $(KVERSION) need minimum $(FPATH_MINKVER)) +$(info Kernel fast path enabled, current kernel version $(CHK_KVER) need minimum $(FPATH_MINKVER)) else ifeq ($(call versame,${kmajor},${fp_major}),0) ifeq ($(call versameorlater,${kminor},${fp_minor}),0) PXDEFINES += -D__PX_FASTPATH__ px-objs += pxd_fastpath.o -$(info Kernel fast path enabled, current kernel version $(KVERSION) need minimum $(FPATH_MINKVER)) +$(info Kernel fast path enabled, current kernel version $(CHK_KVER) need minimum $(FPATH_MINKVER)) else px-objs += pxd_fastpath_stub.o -$(info Kernel fast path disabled, current kernel version $(KVERSION) need minimum $(FPATH_MINKVER)) +$(info Kernel fast path disabled, current kernel version $(CHK_KVER) need minimum $(FPATH_MINKVER)) endif else px-objs += pxd_fastpath_stub.o -$(info Kernel fast path disabled, current kernel version $(KVERSION) need minimum $(FPATH_MINKVER)) +$(info Kernel fast path disabled, current kernel version $(CHK_KVER) need minimum $(FPATH_MINKVER)) endif endif diff --git a/pxd.c b/pxd.c index 0fc5f8a7..09a719e9 100644 --- a/pxd.c +++ b/pxd.c @@ -678,11 +678,9 @@ static int pxd_init_disk(struct pxd_device *pxd_dev, struct pxd_add_ext_out *add set_capacity(disk, add->size / SECTOR_SIZE); /* Enable discard support. */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(4,17,0) - queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q); -#else - blk_queue_flag_set(QUEUE_FLAG_DISCARD, q); -#endif + + QUEUE_FLAG_SET(QUEUE_FLAG_DISCARD,q); + q->limits.discard_granularity = PXD_LBS; q->limits.discard_alignment = PXD_LBS; if (add->discard_size < SECTOR_SIZE) @@ -859,11 +857,9 @@ ssize_t pxd_remove(struct fuse_conn *fc, struct pxd_remove_out *remove) /* Make sure the req_fn isn't called anymore even if the device hangs around */ if (pxd_dev->disk && pxd_dev->disk->queue){ mutex_lock(&pxd_dev->disk->queue->sysfs_lock); -#if LINUX_VERSION_CODE < KERNEL_VERSION(4,17,0) - queue_flag_set_unlocked(QUEUE_FLAG_DYING, pxd_dev->disk->queue); -#else - blk_queue_flag_set(QUEUE_FLAG_DYING, pxd_dev->disk->queue); -#endif + + QUEUE_FLAG_SET(QUEUE_FLAG_DYING, pxd_dev->disk->queue); + mutex_unlock(&pxd_dev->disk->queue->sysfs_lock); } diff --git a/pxd_compat.h b/pxd_compat.h index 5b09179c..333d77f2 100644 --- a/pxd_compat.h +++ b/pxd_compat.h @@ -49,13 +49,13 @@ #define SUBMIT_BIO(bio) submit_bio(BIO_OP(bio), bio) #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) #define BIOSET_CREATE(sz, pad) bioset_create(sz, pad, 0) #else #define BIOSET_CREATE(sz, pad) bioset_create(sz, pad) #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) +#if defined(bio_set_dev) #define BIO_SET_DEV(bio, bdev) bio_set_dev(bio, bdev) #else #define BIO_SET_DEV(bio, bdev) \ @@ -87,4 +87,12 @@ #define BLK_RQ_IS_PASSTHROUGH(rq) (rq->cmd_type != REQ_TYPE_FS) #endif +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0) || \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) && \ + defined(QUEUE_FLAG_PREEMPT_ONLY)) +#define QUEUE_FLAG_SET(flag,q) blk_queue_flag_set(flag, q); +#else +#define QUEUE_FLAG_SET(flag,q) queue_flag_set_unlocked(flag, q); +#endif + #endif //GDFS_PXD_COMPAT_H diff --git a/pxd_fastpath.c b/pxd_fastpath.c index ae80f375..266dae72 100644 --- a/pxd_fastpath.c +++ b/pxd_fastpath.c @@ -9,7 +9,9 @@ static int __px_ncpus; // A private global bio mempool for punting requests bypassing vfs -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0) || \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) && \ + defined(bvec_iter_sectors)) static struct bio_set pxd_bio_set; #endif #define PXD_MIN_POOL_PAGES (128) @@ -212,8 +214,10 @@ int fastpath_init(void) return err; } } - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0) + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0) || \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) && \ + defined(bvec_iter_sectors)) if (bioset_init(&pxd_bio_set, PXD_MIN_POOL_PAGES, offsetof(struct pxd_io_tracker, clone), 0)) { printk(KERN_ERR "pxd: failed to initialize bioset_init: -ENOMEM\n"); @@ -366,7 +370,7 @@ static int _pxd_write(uint64_t dev_id, struct file *file, struct bio_vec *bvec, file_start_write(file); bw = vfs_iter_write(file, &i, pos, 0); file_end_write(file); -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) iov_iter_bvec(&i, ITER_BVEC | WRITE, bvec, 1, bvec->bv_len); file_start_write(file); bw = vfs_iter_write(file, &i, pos, 0); @@ -445,7 +449,7 @@ ssize_t _pxd_read(uint64_t dev_id, struct file *file, struct bio_vec *bvec, loff iov_iter_bvec(&i, READ, bvec, 1, bvec->bv_len); result = vfs_iter_read(file, &i, pos, 0); -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0) +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) struct iov_iter i; iov_iter_bvec(&i, ITER_BVEC|READ, bvec, 1, bvec->bv_len); @@ -536,7 +540,9 @@ static void pxd_complete_io(struct bio* bio) if (!atomic_dec_and_test(&head->active)) { // not all responses have come back // but update head status if this is a failure -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) || \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) && \ + defined(bvec_iter_sectors)) if (bio->bi_status) { atomic_inc(&head->fails); } @@ -551,7 +557,11 @@ static void pxd_complete_io(struct bio* bio) return; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,1) + bio_end_io_acct(bio, iot->start); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) || \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) && \ + defined(bvec_iter_sectors)) generic_end_io_acct(pxd_dev->disk->queue, bio_op(bio), &pxd_dev->disk->part0, iot->start); #else generic_end_io_acct(bio_data_dir(bio), &pxd_dev->disk->part0, iot->start); @@ -560,7 +570,9 @@ static void pxd_complete_io(struct bio* bio) pxd_printk("pxd_complete_io for bio %p (pxd %p) with head %p active %d - completing orig %p\n", bio, pxd_dev, head, atomic_read(&head->active), iot->orig); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) || \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) && \ + defined(bvec_iter_sectors)) { iot->orig->bi_status = bio->bi_status; if (atomic_read(&head->fails)) { @@ -718,7 +730,11 @@ static int __do_bio_filebacked(struct pxd_device *pxd_dev, struct pxd_io_tracker unsigned int op = bio_op(bio); int ret; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,1) + bio_start_io_acct(bio); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) || \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) && \ + defined(bvec_iter_sectors)) generic_start_io_acct(pxd_dev->disk->queue, bio_op(bio), REQUEST_GET_SECTORS(bio), &pxd_dev->disk->part0); #else generic_start_io_acct(bio_data_dir(bio), REQUEST_GET_SECTORS(bio), &pxd_dev->disk->part0); @@ -771,7 +787,9 @@ static int __do_bio_filebacked(struct pxd_device *pxd_dev, struct pxd_io_tracker out: if (ret < 0) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) || \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) && \ + defined(bvec_iter_sectors)) bio->bi_status = ret; #else bio->bi_error = ret; @@ -863,7 +881,11 @@ static inline int pxd_handle_io(struct thread_context *tc, struct pxd_io_tracker return -ENXIO; } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,1) + bio_start_io_acct(bio); +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)|| \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0) && \ + defined(bvec_iter_sectors)) generic_start_io_acct(pxd_dev->disk->queue, bio_op(bio), REQUEST_GET_SECTORS(bio), &pxd_dev->disk->part0); #else generic_start_io_acct(bio_data_dir(bio), REQUEST_GET_SECTORS(bio), &pxd_dev->disk->part0);