From: Gleb C. <lna...@ya...> - 2023-07-10 07:35:42
|
Commit: 76750f3 GitHub URL: https://github.com/SCST-project/scst/commit/76750f3352d095e6a544d02a10d84b15147bcb0a Author: Gleb Chesnokov Date: 2023-07-10T10:34:57+03:00 Log Message: ----------- scst: Port to Linux kernel v6.5 Support for the following block layer changes in the Linux kernel v6.5: - 05bdb9965305 ("block: replace fmode_t with a block-specific type for block open flags") - 0718afd47f70 ("block: introduce holder ops") - 2736e8eeb0cc ("block: use the holder as indication for exclusive opens") Modified Paths: -------------- .github/workflows/checkpatch_pull.yml | 1 + .github/workflows/checkpatch_push.yml | 1 + scst/include/backport.h | 53 ++++++++++++++- scst/src/dev_handlers/scst_vdisk.c | 24 +++---- scst/src/scst_lib.c | 4 +- 5 files changed, 66 insertions(+), 17 deletions(-) =================================================================== diff --git a/.github/workflows/checkpatch_pull.yml b/.github/workflows/checkpatch_pull.yml index dfee81f..a9ced98 100644 --- a/.github/workflows/checkpatch_pull.yml +++ b/.github/workflows/checkpatch_pull.yml @@ -35,6 +35,7 @@ jobs: SPDX_LICENSE_TAG LINUX_VERSION_CODE CONSTANT_COMPARISON + NEW_TYPEDEFS SPACING ) ignore_str=${ignore[*]} diff --git a/.github/workflows/checkpatch_push.yml b/.github/workflows/checkpatch_push.yml index e517ccc..28acad5 100644 --- a/.github/workflows/checkpatch_push.yml +++ b/.github/workflows/checkpatch_push.yml @@ -40,6 +40,7 @@ jobs: SPDX_LICENSE_TAG LINUX_VERSION_CODE CONSTANT_COMPARISON + NEW_TYPEDEFS SPACING ) ignore_str=${ignore[*]} diff --git a/scst/include/backport.h b/scst/include/backport.h index d8e873a..dd784cf 100644 --- a/scst/include/backport.h +++ b/scst/include/backport.h @@ -228,6 +228,55 @@ void blk_execute_rq_nowait_backport(struct request *rq, bool at_head) /* <linux/blkdev.h> */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 5, 0) +/* + * See also commit 05bdb9965305 ("block: replace fmode_t with a block-specific + * type for block open flags") # v6.5. + */ +typedef fmode_t blk_mode_t; + +#define BLK_OPEN_READ ((__force blk_mode_t)FMODE_READ) +#define BLK_OPEN_WRITE ((__force blk_mode_t)FMODE_WRITE) +#define BLK_OPEN_EXCL ((__force blk_mode_t)FMODE_EXCL) + +/* + * See also commit 0718afd47f70 ("block: introduce holder ops") # v6.5. + */ +struct blk_holder_ops { + /* empty dummy */ +}; + +static inline struct block_device * +blkdev_get_by_path_backport(const char *path, blk_mode_t mode, + void *holder, const struct blk_holder_ops *hops) +{ + WARN_ON_ONCE(hops); + + /* + * See also commit 2736e8eeb0cc ("block: use the holder as + * indication for exclusive opens") # v6.5. + */ + if (holder) + mode |= BLK_OPEN_EXCL; + + return blkdev_get_by_path(path, mode, holder); +} + +#define blkdev_get_by_path blkdev_get_by_path_backport + +/* + * See also commit 2736e8eeb0cc ("block: use the holder as indication for + * exclusive opens") # v6.5. + */ +static inline void blkdev_put_backport(struct block_device *bdev, void *holder) +{ + blkdev_put(bdev, holder ? BLK_OPEN_EXCL : 0); +} + +#define blkdev_put blkdev_put_backport + +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0) && \ (!defined(RHEL_RELEASE_CODE) || \ RHEL_RELEASE_CODE -0 < RHEL_RELEASE_VERSION(9, 1)) @@ -235,8 +284,8 @@ void blk_execute_rq_nowait_backport(struct request *rq, bool at_head) * See also commit 44abff2c0b97 ("block: decouple REQ_OP_SECURE_ERASE * from REQ_OP_DISCARD") # v5.19. */ -static inline -int blkdev_issue_discard_backport(struct block_device *bdev, sector_t sector, +static inline int +blkdev_issue_discard_backport(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask) { return blkdev_issue_discard(bdev, sector, nr_sects, gfp_mask, 0); diff --git a/scst/src/dev_handlers/scst_vdisk.c b/scst/src/dev_handlers/scst_vdisk.c index eaa61c5..cf6907c 100644 --- a/scst/src/dev_handlers/scst_vdisk.c +++ b/scst/src/dev_handlers/scst_vdisk.c @@ -191,7 +191,6 @@ struct scst_vdisk_dev { struct file *fd; struct file *dif_fd; struct block_device *bdev; - fmode_t bdev_mode; struct bio_set *vdisk_bioset; #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0) struct bio_set vdisk_bioset_struct; @@ -503,7 +502,7 @@ static void vdisk_blockio_check_flush_support(struct scst_vdisk_dev *virt_dev) virt_dev->wt_flag || !virt_dev->dev_active) goto out; - bdev = blkdev_get_by_path(virt_dev->filename, FMODE_READ, NULL); + bdev = blkdev_get_by_path(virt_dev->filename, BLK_OPEN_READ, NULL, NULL); if (IS_ERR(bdev)) { if (PTR_ERR(bdev) == -EMEDIUMTYPE) TRACE(TRACE_MINOR, @@ -522,7 +521,7 @@ static void vdisk_blockio_check_flush_support(struct scst_vdisk_dev *virt_dev) virt_dev->nv_cache = 1; } - blkdev_put(bdev, FMODE_READ); + blkdev_put(bdev, NULL); out: TRACE_EXIT(); @@ -544,7 +543,7 @@ static void vdisk_check_tp_support(struct scst_vdisk_dev *virt_dev) goto check; if (virt_dev->blockio) { - bdev = blkdev_get_by_path(virt_dev->filename, FMODE_READ, NULL); + bdev = blkdev_get_by_path(virt_dev->filename, BLK_OPEN_READ, NULL, NULL); res = PTR_ERR_OR_ZERO(bdev); } else { fd = filp_open(virt_dev->filename, O_LARGEFILE, 0600); @@ -640,7 +639,7 @@ check: if (fd_open) { if (virt_dev->blockio) - blkdev_put(bdev, FMODE_READ); + blkdev_put(bdev, NULL); else filp_close(fd, NULL); } @@ -965,7 +964,7 @@ static int vdisk_init_block_integrity(struct scst_vdisk_dev *virt_dev) TRACE_ENTRY(); - bdev = blkdev_get_by_path(virt_dev->filename, FMODE_READ, NULL); + bdev = blkdev_get_by_path(virt_dev->filename, BLK_OPEN_READ, NULL, NULL); if (IS_ERR(bdev)) { res = PTR_ERR(bdev); goto out; @@ -1043,7 +1042,7 @@ out_no_bi: res = 0; out_close: - blkdev_put(bdev, FMODE_READ); + blkdev_put(bdev, NULL); out: TRACE_EXIT_RES(res); @@ -1307,13 +1306,12 @@ static int vdisk_open_fd(struct scst_vdisk_dev *virt_dev, bool read_only) virt_dev->dev->virt_name); res = -EMEDIUMTYPE; } else if (virt_dev->blockio) { - virt_dev->bdev_mode = FMODE_READ | FMODE_EXCL; + blk_mode_t bdev_mode = BLK_OPEN_READ; if (!read_only) - virt_dev->bdev_mode |= FMODE_WRITE; + bdev_mode |= BLK_OPEN_WRITE; - virt_dev->bdev = blkdev_get_by_path(virt_dev->filename, - virt_dev->bdev_mode, virt_dev); + virt_dev->bdev = blkdev_get_by_path(virt_dev->filename, bdev_mode, virt_dev, NULL); res = PTR_ERR_OR_ZERO(virt_dev->bdev); } else { virt_dev->fd = vdev_open_fd(virt_dev, virt_dev->filename, @@ -1352,7 +1350,7 @@ out: out_close_fd: if (virt_dev->blockio) { - blkdev_put(virt_dev->bdev, virt_dev->bdev_mode); + blkdev_put(virt_dev->bdev, virt_dev); virt_dev->bdev = NULL; } else { filp_close(virt_dev->fd, NULL); @@ -1367,7 +1365,7 @@ static void vdisk_close_fd(struct scst_vdisk_dev *virt_dev) virt_dev->fd, virt_dev->bdev, virt_dev->dif_fd); if (virt_dev->bdev) { - blkdev_put(virt_dev->bdev, virt_dev->bdev_mode); + blkdev_put(virt_dev->bdev, virt_dev); virt_dev->bdev = NULL; } else if (virt_dev->fd) { filp_close(virt_dev->fd, NULL); diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index bdb45c4..283a28b 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -5983,11 +5983,11 @@ loff_t scst_bdev_size(const char *path) struct block_device *bdev; loff_t res; - bdev = blkdev_get_by_path(path, FMODE_READ, NULL); + bdev = blkdev_get_by_path(path, BLK_OPEN_READ, NULL, NULL); if (IS_ERR(bdev)) return PTR_ERR(bdev); res = i_size_read(bdev->bd_inode); - blkdev_put(bdev, FMODE_READ); + blkdev_put(bdev, NULL); return res; } EXPORT_SYMBOL(scst_bdev_size); |