From e53e0882f9c3d4cee1812674d5f59ce4d6b650c4 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Thu, 24 Mar 2022 15:48:20 +0300 Subject: [PATCH] scst_vdisk: Port to Linux kernel v5.18 Support for the following block/fs changes in the Linux Kernel v5.18: - 609be1066731 ("block: pass a block_device and opf to bio_alloc_bioset") - 07888c665b40 ("block: pass a block_device and opf to bio_alloc") - cbcc268bb1ce ("fs: Move many prototypes to pagemap.h") --- scst/include/backport.h | 48 ++++++++++++++++++++++++++++++ scst/src/dev_handlers/scst_vdisk.c | 15 ++++++---- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/scst/include/backport.h b/scst/include/backport.h index c357dd58d..74a4986a8 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -109,6 +109,54 @@ 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) +/* + * See also commit 609be1066731 ("block: pass a block_device and opf to + * bio_alloc_bioset") # v5.18 + */ +static inline +struct bio *bio_alloc_bioset_backport(struct block_device *bdev, + unsigned short nr_vecs, unsigned int opf, gfp_t gfp_mask, + struct bio_set *bs) +{ + /* + * Check that @bdev and @opf parameters are zeros. + * + * The old API expects these parameters to be set implicitly. + * Therefore, warn about using an explicit setting that would + * cause these parameters to be lost. + */ + WARN_ON_ONCE(bdev || opf); + + return bio_alloc_bioset(gfp_mask, nr_vecs, bs); +} + +#define bio_alloc_bioset bio_alloc_bioset_backport + +/* + * See also commit 07888c665b40 ("block: pass a block_device and opf to + * bio_alloc") # v5.18 + */ +static inline +struct bio *bio_alloc_backport(struct block_device *bdev, + unsigned short nr_vecs, unsigned int opf, gfp_t gfp_mask) +{ + /* + * Check that @bdev and @opf parameters are zeros. + * + * The old API expects these parameters to be set implicitly. + * Therefore, warn about using an explicit setting that would + * cause these parameters to be lost. + */ + WARN_ON_ONCE(bdev || opf); + + return bio_alloc(gfp_mask, nr_vecs); +} + +#define bio_alloc bio_alloc_backport + +#endif + /* */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0) diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index 3514fb949..8655c958a 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -428,15 +429,19 @@ static int vdisk_blockio_flush(struct block_device *bdev, gfp_t gfp_mask, TRACE_ENTRY(); if (async) { - struct bio *bio = bio_alloc(gfp_mask, 0); + struct bio *bio; + bio = bio_alloc(/*bdev=*/NULL, 0, /*opf=*/0, gfp_mask); if (bio == NULL) { res = -ENOMEM; goto out_rep; } + bio->bi_end_io = vdev_flush_end_io; bio->bi_private = cmd; + bio_set_dev(bio, bdev); + #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) || \ (defined(CONFIG_SUSE_KERNEL) && \ LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0)) @@ -2836,8 +2841,8 @@ static ssize_t blockio_read_sync(struct scst_vdisk_dev *virt_dev, void *buf, max_nr_vecs = min(bio_get_nr_vecs(bdev), BIO_MAX_VECS); #endif - bio = bio_alloc_bioset(GFP_KERNEL, max_nr_vecs, virt_dev->vdisk_bioset); - + bio = bio_alloc_bioset(/*bdev=*/NULL, max_nr_vecs, /*opf=*/0, + GFP_KERNEL, virt_dev->vdisk_bioset); if (!bio) goto out; @@ -5958,8 +5963,8 @@ static void blockio_exec_rw(struct vdisk_cmd_params *p, bool write, bool fua) int rc; if (need_new_bio) { - bio = bio_alloc_bioset(gfp_mask, max_nr_vecs, bs); - + bio = bio_alloc_bioset(/*bdev=*/NULL, max_nr_vecs, /*opf=*/0, + gfp_mask, bs); if (!bio) { PRINT_ERROR("Failed to create bio " "for data segment %d (cmd %p)",