From 66016e5ee078b41df9787ecc62f54690a50fab41 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Tue, 29 Nov 2022 12:08:19 +0300 Subject: [PATCH] scst: Unbreak the RHEL 9.1 build Fixes: https://github.com/SCST-project/scst/issues/101 --- scst/include/backport.h | 20 ++++++--- scst/src/dev_handlers/scst_vdisk.c | 10 +++-- scst/src/scst_lib.c | 71 +++++++++++++++++++----------- scst/src/scst_pres.c | 13 +++--- 4 files changed, 74 insertions(+), 40 deletions(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index 67886bc28..764cdef8a 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -109,7 +109,9 @@ static inline void bio_set_dev(struct bio *bio, struct block_device *bdev) #define BIO_MAX_VECS BIO_MAX_PAGES #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 18, 0) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(9, 1)) /* * See also commit 609be1066731 ("block: pass a block_device and opf to * bio_alloc_bioset") # v5.18 @@ -178,7 +180,9 @@ static inline unsigned int scst_blk_rq_cpu(struct request *rq) #endif } -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(9, 1)) /* * See also commit e2e530867245 ("blk-mq: remove the done argument to * blk_execute_rq_nowait") # v5.19. @@ -208,7 +212,9 @@ void blk_execute_rq_nowait_backport(struct request *rq, bool at_head) /* */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(9, 1)) /* * See also commit 44abff2c0b97 ("block: decouple REQ_OP_SECURE_ERASE * from REQ_OP_DISCARD") # v5.19. @@ -1446,7 +1452,9 @@ static inline void scsi_build_sense(struct scsi_cmnd *scmd, int desc, } #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(9, 1)) #if (!defined(RHEL_RELEASE_CODE) || \ RHEL_RELEASE_CODE -0 != RHEL_RELEASE_VERSION(8, 7)) @@ -1495,7 +1503,9 @@ static inline u32 scsi_prot_ref_tag(struct scsi_cmnd *scmd) #endif #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(9, 1)) /* * See also commit 11b68e36b167 ("scsi: core: Call scsi_done directly"; v5.16) */ diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index de23faab4..47811242e 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -563,12 +563,14 @@ static void vdisk_check_tp_support(struct scst_vdisk_dev *virt_dev) fd_open = true; if (virt_dev->blockio) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 0) - virt_dev->dev_thin_provisioned = - !!bdev_max_discard_sectors(bdev); -#else +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(9, 1)) virt_dev->dev_thin_provisioned = blk_queue_discard(bdev_get_queue(bdev)); +#else + virt_dev->dev_thin_provisioned = + !!bdev_max_discard_sectors(bdev); #endif } else { virt_dev->dev_thin_provisioned = (fd->f_op->fallocate != NULL); diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 39c597f13..178200acb 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -8072,7 +8072,9 @@ scst_alloc_passthrough_request(struct request_queue *q, int rw, gfp_t gfp_mask) #elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0) return blk_get_request(q, rw == READ ? REQ_OP_SCSI_IN : REQ_OP_SCSI_OUT, gfp_mask); -#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) +#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(9, 1)) return blk_get_request(q, rw == READ ? REQ_OP_SCSI_IN : REQ_OP_SCSI_OUT, scst_gfp_mask_to_flags(gfp_mask)); #else @@ -8081,6 +8083,43 @@ scst_alloc_passthrough_request(struct request_queue *q, int rw, gfp_t gfp_mask) #endif } +/** + * scst_init_passthrough_request - Init a SCSI pass-through request. + * @rq: Request pointer. + */ +static void +scst_init_passthrough_request(struct request *rq) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(9, 1)) + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0) || \ + defined(CONFIG_SUSE_KERNEL) + scsi_req_init(scsi_req(rq)); +#else + scsi_req_init(rq); +#endif + +#endif +} + +/** + * scst_free_passthrough_request - Free a SCSI pass-through request. + * @rq: Request pointer. + */ +static void +scst_free_passthrough_request(struct request *rq) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(9, 1)) + blk_put_request(rq); +#else + blk_mq_free_request(rq); +#endif +} + #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) || \ (defined(CONFIG_SUSE_KERNEL) && LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) static struct request *blk_make_request(struct request_queue *q, @@ -8093,14 +8132,7 @@ static struct request *blk_make_request(struct request_queue *q, if (IS_ERR_OR_NULL(rq)) return rq; -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0) -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0) || \ - defined(CONFIG_SUSE_KERNEL) - scsi_req_init(scsi_req(rq)); -#else - scsi_req_init(rq); -#endif -#endif + scst_init_passthrough_request(rq); for_each_bio(bio) { int ret; @@ -8125,11 +8157,7 @@ static struct request *blk_make_request(struct request_queue *q, ret = blk_rq_append_bio(rq, bio); #endif if (unlikely(ret)) { -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) - blk_put_request(rq); -#else - blk_mq_free_request(rq); -#endif + scst_free_passthrough_request(rq); return ERR_PTR(ret); } } @@ -8314,14 +8342,7 @@ static struct request *blk_map_kern_sg(struct request_queue *q, if (IS_ERR_OR_NULL(rq)) return ERR_PTR(-ENOMEM); -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0) -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0) || \ - defined(CONFIG_SUSE_KERNEL) - scsi_req_init(scsi_req(rq)); -#else - scsi_req_init(rq); -#endif -#endif + scst_init_passthrough_request(rq); goto out; } @@ -8537,10 +8558,8 @@ static RQ_END_IO_RET scsi_end_async(struct request *req, blk_status_t error) (!defined(RHEL_MAJOR) || RHEL_MAJOR -0 < 8) /* See also commit 92bc5a24844a ("block: remove __blk_put_request()") */ __blk_put_request(req->q, req); -#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) - blk_put_request(req); #else - blk_mq_free_request(req); + scst_free_passthrough_request(req); #endif return; #else @@ -8677,7 +8696,7 @@ out_free_unmap: } rq->bio = NULL; - blk_put_request(rq); + scst_free_passthrough_request(rq); #endif out_free_sioc: diff --git a/scst/src/scst_pres.c b/scst/src/scst_pres.c index 268ec9da0..ce860686a 100644 --- a/scst/src/scst_pres.c +++ b/scst/src/scst_pres.c @@ -41,11 +41,6 @@ #endif #include #include -#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) -#include -#else -#include -#endif #ifdef INSIDE_KERNEL_TREE #include @@ -57,6 +52,14 @@ #include "scst_priv.h" #include "scst_pres.h" +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 16, 0) && \ + (!defined(RHEL_RELEASE_CODE) || \ + RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(9, 1)) +#include +#else +#include +#endif + #define SCST_PR_ROOT_ENTRY "pr" #define SCST_PR_FILE_SIGN 0xBBEEEEAAEEBBDD77LLU #define SCST_PR_FILE_VERSION 1LLU