Skip to content

Commit

Permalink
Compile fixes 4x 5x kernels (#148)
Browse files Browse the repository at this point in the history
* Compile fixes for 5.8.x, 4.12.x & 4.13.x EL7 kernels.

* Merge in master 'Suse compile fixes PR #147 (bc03ffa)'
  • Loading branch information
jrivera-px authored Aug 29, 2020
1 parent a15dc63 commit 4db086a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 28 deletions.
10 changes: 5 additions & 5 deletions Makefile.in
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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

Expand Down
16 changes: 6 additions & 10 deletions pxd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down
12 changes: 10 additions & 2 deletions pxd_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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
44 changes: 33 additions & 11 deletions pxd_fastpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4db086a

Please sign in to comment.