From e8c99bf81371739a8de0a039d07dc440964d100b Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sun, 29 Jul 2018 04:43:50 +0000 Subject: [PATCH] scst: Simplify blk_make_request() and blk_map_kern_sg() For kernel versions >= 4.11.0, pass REQ_OP_SCSI_* as second argument to blk_get_request() instead of READ or WRITE and setting REQ_OP_SCSI_* later. For kernels < 4.11.0, instead of calling blk_rq_set_block_pc() directly, call it indirectly through scsi_req_init(). git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@7445 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst/src/scst_lib.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index a46836113..354088812 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -7955,7 +7955,14 @@ static struct request *blk_make_request(struct request_queue *q, struct bio *bio, gfp_t gfp_mask) { - struct request *rq = blk_get_request(q, bio_data_dir(bio), gfp_mask); + struct request *rq; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) + rq = blk_get_request(q, bio_data_dir(bio), gfp_mask); +#else + rq = blk_get_request(q, bio_data_dir(bio) == READ ? REQ_OP_SCSI_IN : + REQ_OP_SCSI_OUT, gfp_mask); +#endif if (IS_ERR(rq)) return rq; @@ -7965,12 +7972,6 @@ static struct request *blk_make_request(struct request_queue *q, #else scsi_req_init(rq); #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) - rq->cmd_flags = bio_data_dir(bio) == READ ? REQ_OP_SCSI_IN : - REQ_OP_SCSI_OUT; -#else - blk_rq_set_block_pc(rq); -#endif for_each_bio(bio) { int ret; @@ -8155,9 +8156,6 @@ static struct request *__blk_map_kern_sg(struct request_queue *q, */ rq->cmd_type = REQ_TYPE_BLOCK_PC; #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) - rq->cmd_flags = reading ? REQ_OP_SCSI_IN : REQ_OP_SCSI_OUT; -#endif if (bw != NULL) { atomic_set(&bw->bios_inflight, bios); @@ -8203,7 +8201,12 @@ static struct request *blk_map_kern_sg(struct request_queue *q, struct request *rq; if (!sgl) { +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) rq = blk_get_request(q, reading ? READ : WRITE, gfp); +#else + rq = blk_get_request(q, reading ? REQ_OP_SCSI_IN : + REQ_OP_SCSI_OUT, gfp); +#endif if (unlikely(!rq)) return ERR_PTR(-ENOMEM); @@ -8211,9 +8214,6 @@ static struct request *blk_map_kern_sg(struct request_queue *q, scsi_req_init(scsi_req(rq)); #else scsi_req_init(rq); -#endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) - rq->cmd_flags = reading ? REQ_OP_SCSI_IN : REQ_OP_SCSI_OUT; #endif goto out; }