From patchwork Wed Jan 3 12:54:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13509988 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 539BE1946B; Wed, 3 Jan 2024 12:55:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hlB+lqRU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA75BC433C9; Wed, 3 Jan 2024 12:55:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286530; bh=PUDxaO+PBRRStY0joJC5Nk+ZL+hdUQrEKGcabVfxCDs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hlB+lqRU4zZv5TFnrUWjrSqeS120nm/AIQTjOLLnN/iqJySyeW+/eedRL3fDLl1nW W72ah8UWmDd+dbWWR4SophdzCztnutcEzJRX202SqMcpcjhcf0xWf3Z/lGKUSy+A+q bEbzFQm2HdQbPihl+8+H404qbEtG+2kCqNMOdWTMlmLYcXJ1z/8kiff/EImJsWeBti pCNkjjO21jm2BOtvwAaDfoJK+aRPO7+KjDo3vaTXglQ2z/MvrZb1GJJnA6xG0/EscP YRG9gfRlbLMuK8VmyyugabyS/cvBYT4mdVLCcm9iEevQN8xXbKMkKsqJ4qEBXMgVE4 GqoXdWS/AA85w== From: Christian Brauner Date: Wed, 03 Jan 2024 13:54:59 +0100 Subject: [PATCH RFC 01/34] bdev: open block device as files Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-1-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=11083; i=brauner@kernel.org; h=from:subject:message-id; bh=PUDxaO+PBRRStY0joJC5Nk+ZL+hdUQrEKGcabVfxCDs=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbS+E/WnjW0X31XvJbt0FpqocqybPj3rrwrz9UTZ9 GtC29JlOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACYS8JThv6vRIwUxi0cKc1i8 FZh6p0YfTbH40i54YV8TE3/rj7j/NxgZ7t24kc7+Jdhz8R9dDtUL0y/dCH6h3/WyvfPDKjvX42J rGAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- block/bdev.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++-- fs/cramfs/inode.c | 2 +- fs/f2fs/super.c | 2 +- fs/jfs/jfs_logmgr.c | 2 +- fs/romfs/super.c | 2 +- fs/super.c | 18 ++++----- fs/xfs/xfs_super.c | 2 +- include/linux/blkdev.h | 6 +++ include/linux/fs.h | 10 ++++- 9 files changed, 128 insertions(+), 20 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index e9f1b12bd75c..853731fb41ed 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -49,6 +49,15 @@ struct block_device *I_BDEV(struct inode *inode) } EXPORT_SYMBOL(I_BDEV); +/* @bdev_handle will become private to block/blk.h soon. */ +struct block_device *F_BDEV(struct file *f_bdev) +{ + struct bdev_handle *handle = f_bdev->private_data; + WARN_ON(f_bdev->f_op != &def_blk_fops); + return handle->bdev; +} +EXPORT_SYMBOL(F_BDEV); + static void bdev_write_inode(struct block_device *bdev) { struct inode *inode = bdev->bd_inode; @@ -368,12 +377,12 @@ static struct file_system_type bd_type = { }; struct super_block *blockdev_superblock __ro_after_init; +struct vfsmount *blockdev_mnt __ro_after_init; EXPORT_SYMBOL_GPL(blockdev_superblock); void __init bdev_cache_init(void) { int err; - static struct vfsmount *bd_mnt __ro_after_init; bdev_cachep = kmem_cache_create("bdev_cache", sizeof(struct bdev_inode), 0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT| @@ -382,10 +391,10 @@ void __init bdev_cache_init(void) err = register_filesystem(&bd_type); if (err) panic("Cannot register bdev pseudo-fs"); - bd_mnt = kern_mount(&bd_type); - if (IS_ERR(bd_mnt)) + blockdev_mnt = kern_mount(&bd_type); + if (IS_ERR(blockdev_mnt)) panic("Cannot create bdev pseudo-fs"); - blockdev_superblock = bd_mnt->mnt_sb; /* For writeback */ + blockdev_superblock = blockdev_mnt->mnt_sb; /* For writeback */ } struct block_device *bdev_alloc(struct gendisk *disk, u8 partno) @@ -911,6 +920,93 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, } EXPORT_SYMBOL(bdev_open_by_dev); +static unsigned blk_to_file_flags(blk_mode_t mode) +{ + unsigned int flags = 0; + + if ((mode & (BLK_OPEN_READ | BLK_OPEN_WRITE)) == + (BLK_OPEN_READ | BLK_OPEN_WRITE)) + flags |= O_RDWR; + else if (mode & BLK_OPEN_WRITE) + flags |= O_WRONLY; + else + flags |= O_RDONLY; + + /* + * O_EXCL is one of those flags that the VFS clears once it's done with + * the operation. So don't raise it here either. + */ + if (mode & BLK_OPEN_NDELAY) + flags |= O_NDELAY; + + /* + * If BLK_OPEN_WRITE_IOCTL is set then this is a historical quirk + * associated with the floppy driver where it has allowed ioctls if the + * file was opened for writing, but does not allow reads or writes. + * Make sure that this quirk is reflected in @f_flags. + */ + if (mode & BLK_OPEN_WRITE_IOCTL) + flags |= O_RDWR | O_WRONLY; + + return flags; +} + +struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, + const struct blk_holder_ops *hops) +{ + struct file *file; + struct bdev_handle *handle; + unsigned int flags; + + handle = bdev_open_by_dev(dev, mode, holder, hops); + if (IS_ERR(handle)) + return ERR_CAST(handle); + + flags = blk_to_file_flags(mode); + file = alloc_file_pseudo(handle->bdev->bd_inode, blockdev_mnt, "", + flags | O_LARGEFILE, &def_blk_fops); + if (IS_ERR(file)) { + bdev_release(handle); + return file; + } + ihold(handle->bdev->bd_inode); + + file->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT | FMODE_NOACCOUNT; + if (bdev_nowait(handle->bdev)) + file->f_mode |= FMODE_NOWAIT; + + file->f_mapping = handle->bdev->bd_inode->i_mapping; + file->f_wb_err = filemap_sample_wb_err(file->f_mapping); + file->private_data = handle; + return file; +} +EXPORT_SYMBOL(bdev_file_open_by_dev); + +struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode, + void *holder, + const struct blk_holder_ops *hops) +{ + struct file *file; + dev_t dev; + int error; + + error = lookup_bdev(path, &dev); + if (error) + return ERR_PTR(error); + + file = bdev_file_open_by_dev(dev, mode, holder, hops); + if (!IS_ERR(file) && (mode & BLK_OPEN_WRITE)) { + struct bdev_handle *handle = file->private_data; + if (bdev_read_only(handle->bdev)) { + fput(file); + file = ERR_PTR(-EACCES); + } + } + + return file; +} +EXPORT_SYMBOL(bdev_file_open_by_path); + /** * bdev_open_by_path - open a block device by name * @path: path to the block device to open diff --git a/fs/cramfs/inode.c b/fs/cramfs/inode.c index 60dbfa0f8805..14d1758daa52 100644 --- a/fs/cramfs/inode.c +++ b/fs/cramfs/inode.c @@ -495,7 +495,7 @@ static void cramfs_kill_sb(struct super_block *sb) sb->s_mtd = NULL; } else if (IS_ENABLED(CONFIG_CRAMFS_BLOCKDEV) && sb->s_bdev) { sync_blockdev(sb->s_bdev); - bdev_release(sb->s_bdev_handle); + fput(sb->s_f_bdev); } kfree(sbi); } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 033af907c3b1..93b8a844b207 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4247,7 +4247,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) for (i = 0; i < max_devices; i++) { if (i == 0) - FDEV(0).bdev_handle = sbi->sb->s_bdev_handle; + FDEV(0).bdev_handle = sb_bdev_handle(sbi->sb); else if (!RDEV(i).path[0]) break; diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c index cb6d1fda66a7..8691463956d1 100644 --- a/fs/jfs/jfs_logmgr.c +++ b/fs/jfs/jfs_logmgr.c @@ -1162,7 +1162,7 @@ static int open_inline_log(struct super_block *sb) init_waitqueue_head(&log->syncwait); set_bit(log_INLINELOG, &log->flag); - log->bdev_handle = sb->s_bdev_handle; + log->bdev_handle = sb_bdev_handle(sb); log->base = addressPXD(&JFS_SBI(sb)->logpxd); log->size = lengthPXD(&JFS_SBI(sb)->logpxd) >> (L2LOGPSIZE - sb->s_blocksize_bits); diff --git a/fs/romfs/super.c b/fs/romfs/super.c index 545ad44f96b8..b392ae877ac7 100644 --- a/fs/romfs/super.c +++ b/fs/romfs/super.c @@ -594,7 +594,7 @@ static void romfs_kill_sb(struct super_block *sb) #ifdef CONFIG_ROMFS_ON_BLOCK if (sb->s_bdev) { sync_blockdev(sb->s_bdev); - bdev_release(sb->s_bdev_handle); + fput(sb->s_f_bdev); } #endif } diff --git a/fs/super.c b/fs/super.c index e35936000408..77cc67b8bf44 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1532,16 +1532,16 @@ int setup_bdev_super(struct super_block *sb, int sb_flags, struct fs_context *fc) { blk_mode_t mode = sb_open_mode(sb_flags); - struct bdev_handle *bdev_handle; + struct file *file; struct block_device *bdev; - bdev_handle = bdev_open_by_dev(sb->s_dev, mode, sb, &fs_holder_ops); - if (IS_ERR(bdev_handle)) { + file = bdev_file_open_by_dev(sb->s_dev, mode, sb, &fs_holder_ops); + if (IS_ERR(file)) { if (fc) errorf(fc, "%s: Can't open blockdev", fc->source); - return PTR_ERR(bdev_handle); + return PTR_ERR(file); } - bdev = bdev_handle->bdev; + bdev = F_BDEV(file); /* * This really should be in blkdev_get_by_dev, but right now can't due @@ -1549,7 +1549,7 @@ int setup_bdev_super(struct super_block *sb, int sb_flags, * writable from userspace even for a read-only block device. */ if ((mode & BLK_OPEN_WRITE) && bdev_read_only(bdev)) { - bdev_release(bdev_handle); + fput(file); return -EACCES; } @@ -1560,11 +1560,11 @@ int setup_bdev_super(struct super_block *sb, int sb_flags, if (atomic_read(&bdev->bd_fsfreeze_count) > 0) { if (fc) warnf(fc, "%pg: Can't mount, blockdev is frozen", bdev); - bdev_release(bdev_handle); + fput(file); return -EBUSY; } spin_lock(&sb_lock); - sb->s_bdev_handle = bdev_handle; + sb->s_f_bdev = file; sb->s_bdev = bdev; sb->s_bdi = bdi_get(bdev->bd_disk->bdi); if (bdev_stable_writes(bdev)) @@ -1680,7 +1680,7 @@ void kill_block_super(struct super_block *sb) generic_shutdown_super(sb); if (bdev) { sync_blockdev(bdev); - bdev_release(sb->s_bdev_handle); + fput(sb->s_f_bdev); } } diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 07857d967ee8..0e64220bffdc 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -467,7 +467,7 @@ xfs_open_devices( * Setup xfs_mount buffer target pointers */ error = -ENOMEM; - mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb->s_bdev_handle); + mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb_bdev_handle(sb)); if (!mp->m_ddev_targp) goto out_close_rtdev; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 9f6c3373f9fc..e8d11083acbc 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -24,6 +24,7 @@ #include #include #include +#include struct module; struct request_queue; @@ -1507,6 +1508,10 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, const struct blk_holder_ops *hops); struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode, void *holder, const struct blk_holder_ops *hops); +struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, + const struct blk_holder_ops *hops); +struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode, + void *holder, const struct blk_holder_ops *hops); int bd_prepare_to_claim(struct block_device *bdev, void *holder, const struct blk_holder_ops *hops); void bd_abort_claiming(struct block_device *bdev, void *holder); @@ -1517,6 +1522,7 @@ struct block_device *blkdev_get_no_open(dev_t dev); void blkdev_put_no_open(struct block_device *bdev); struct block_device *I_BDEV(struct inode *inode); +struct block_device *F_BDEV(struct file *file); #ifdef CONFIG_BLOCK void invalidate_bdev(struct block_device *bdev); diff --git a/include/linux/fs.h b/include/linux/fs.h index 8e0d77f9464e..b0a5e94e8c3a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1227,8 +1227,8 @@ struct super_block { #endif struct hlist_bl_head s_roots; /* alternate root dentries for NFS */ struct list_head s_mounts; /* list of mounts; _not_ for fs use */ - struct block_device *s_bdev; - struct bdev_handle *s_bdev_handle; + struct block_device *s_bdev; /* can go away once we use an accessor for @s_f_bdev */ + struct file *s_f_bdev; struct backing_dev_info *s_bdi; struct mtd_info *s_mtd; struct hlist_node s_instances; @@ -1326,6 +1326,12 @@ struct super_block { struct list_head s_inodes_wb; /* writeback inodes */ } __randomize_layout; +/* Temporary helper that will go away. */ +static inline struct bdev_handle *sb_bdev_handle(struct super_block *sb) +{ + return sb->s_f_bdev->private_data; +} + static inline struct user_namespace *i_user_ns(const struct inode *inode) { return inode->i_sb->s_user_ns; From patchwork Wed Jan 3 12:55:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13509989 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B651419465; Wed, 3 Jan 2024 12:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YVaLnsEf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEF00C433CB; Wed, 3 Jan 2024 12:55:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286532; bh=L1B+sEXRETIx3ANuEWFkg77MUvIZc1j2UlM5lbdWQt8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YVaLnsEfZjcAWDZHX2QkgEjc11sr64xbacMRlSMH8MrpdFxdgmi482Yf2/POihtu9 p/xzWp3sulgX5j0u89WN3g+VuGBmjvgbtYr1ZtIQWmjH1DYOooMzuONSs9lhrZYKv0 7I8oX8okMZLcQvHpTI1DOqIz6xg1ag2oHn3sMQ9SXaf/+oMGCTWzXcxwyAP7nRyK+7 D26IPfoN9NhPP07D1DDzMCUknEjD273gK0Uq7S8R8sIqpFB16ZbGfVlv2+FMIEOgip ILkMI7uGPpwB5E3py+ygrYue8ZeC7W5pyCyTs0I0u7X4wQxydirL3/tD92VVEWrrGJ muOjgZ6ma3Zgw== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:00 +0100 Subject: [PATCH RFC 02/34] block/ioctl: port blkdev_bszset() to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-2-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=972; i=brauner@kernel.org; h=from:subject:message-id; bh=L1B+sEXRETIx3ANuEWFkg77MUvIZc1j2UlM5lbdWQt8=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTWn3Bqj9DrX462r0x+PXS7XKfnIf2i6aW4YIHC4 VXNlnFfOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACaixcDw383nYcvBy7Lpyo8j E9i9bXiOxnLkfF4uu5X99bsEs48uzgz/gx5viLRqzonetUgmZOk8We/LT8rMXr3M9J2bK/Dq4Nc 9zAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- block/ioctl.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/block/ioctl.c b/block/ioctl.c index 4160f4e6bd5b..d04641fe541c 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -468,7 +468,7 @@ static int blkdev_bszset(struct block_device *bdev, blk_mode_t mode, int __user *argp) { int ret, n; - struct bdev_handle *handle; + struct file *file; if (!capable(CAP_SYS_ADMIN)) return -EACCES; @@ -480,12 +480,11 @@ static int blkdev_bszset(struct block_device *bdev, blk_mode_t mode, if (mode & BLK_OPEN_EXCL) return set_blocksize(bdev, n); - handle = bdev_open_by_dev(bdev->bd_dev, mode, &bdev, NULL); - if (IS_ERR(handle)) + file = bdev_file_open_by_dev(bdev->bd_dev, mode, &bdev, NULL); + if (IS_ERR(file)) return -EBUSY; ret = set_blocksize(bdev, n); - bdev_release(handle); - + fput(file); return ret; } From patchwork Wed Jan 3 12:55:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13509990 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 124CA199AD; Wed, 3 Jan 2024 12:55:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fRy/LJxM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09DA7C433CA; Wed, 3 Jan 2024 12:55:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286534; bh=+u2K3zuRzOORkTxeWdFEGbJR7iIhi6M9uJ5rQ5EvY4w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=fRy/LJxMUHpsfN7q4RaNhKIg0yFM2QQw+RgM/HsHEcl+ORS979wddE7r30eAbPLMQ 1NsxfQIfm5tWQ4LI1XCI7axXYL+Ly9QiXbiUyCzWAOZE00rymwu9qrPMF3kSDHpQM8 xNZO4ag5Y+Aa88BtciuA7V2lP0Au13xEUy39vKydmcmb506jzAt45BZ/UkK6Pequnm EeQkId6kG93F64LTqFS7wggK33DEIaqjzVgttfGq6MV+epmRT9DxPDOQY1kQl3sJUE Yt4BFxgZn/TGmcIpz8V2FobXBqNzob4nzkKVR74TtFQltBK7Kxa4bzRs0MQke2bw6k bUiUemlBJ4UeA== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:01 +0100 Subject: [PATCH RFC 03/34] block/genhd: port disk_scan_partitions() to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-3-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=1101; i=brauner@kernel.org; h=from:subject:message-id; bh=+u2K3zuRzOORkTxeWdFEGbJR7iIhi6M9uJ5rQ5EvY4w=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTWF3M9JJj8o2rHo76/S4/mHV/SInAhPyTQPbBxi +7Fh4cKO0pZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACbiXMLI0HA248CXVo6f/fxN G28JRedE3OZc+GMf922NGmfLPe9qWBkZDnVs+cCyI4nx5Wfu/kfeZw/Ux/Z53jnEa7CKcz+jqe1 JDgA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- block/genhd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index c9d06f72c587..bae0503fe6a2 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -342,7 +342,7 @@ EXPORT_SYMBOL_GPL(disk_uevent); int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode) { - struct bdev_handle *handle; + struct file *file; int ret = 0; if (disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN)) @@ -366,12 +366,12 @@ int disk_scan_partitions(struct gendisk *disk, blk_mode_t mode) } set_bit(GD_NEED_PART_SCAN, &disk->state); - handle = bdev_open_by_dev(disk_devt(disk), mode & ~BLK_OPEN_EXCL, NULL, - NULL); - if (IS_ERR(handle)) - ret = PTR_ERR(handle); + file = bdev_file_open_by_dev(disk_devt(disk), mode & ~BLK_OPEN_EXCL, + NULL, NULL); + if (IS_ERR(file)) + ret = PTR_ERR(file); else - bdev_release(handle); + fput(file); /* * If blkdev_get_by_dev() failed early, GD_NEED_PART_SCAN is still set, From patchwork Wed Jan 3 12:55:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13509991 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E5FF5199AD; Wed, 3 Jan 2024 12:55:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IIblHZms" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B931C433C9; Wed, 3 Jan 2024 12:55:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286536; bh=cB/ONpG3pRu8P63Oq88NUsbpgGRdyHmqXBst1QNeyyw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IIblHZmsT5ZjOD82RfKkBTT5OrtFIw+z33enGg307livlThPrRtUXAdg1jhPwtzOW ZgqMtjcmAQ1Hf8NaQWavmwTV+jp91KrJTBUBkApKu1AvWVrjSZ7yDNbTve+ELG5oBD UjMf/lIn3iCjvIVWBRj2JlLePcrr8RqR28VEzVT/veUeAbGEGvbJAHPtF8yeMUz2N5 Q6YxQeHV5Vb4F8ckU7KOrJwQ7GQoLtibYYhGFCm8JCyRFf82vmQ8v2vlS28p6f/nT3 EDBHbjhwa6H7dyCsREQGDc48/JUt2KDTrIwGG3FiRfpOIGkmZpFExMXkxt6Rxt5lYT uZMf2hK29dGWQ== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:02 +0100 Subject: [PATCH RFC 04/34] md: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-4-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=4717; i=brauner@kernel.org; h=from:subject:message-id; bh=cB/ONpG3pRu8P63Oq88NUsbpgGRdyHmqXBst1QNeyyw=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbRO8lq081jVJj6vUxdC+HRUJvD9trsoaxUq0yVm2 3D4acKujlIWBjEuBlkxRRaHdpNwueU8FZuNMjVg5rAygQxh4OIUgIn4azH8r4yQU1ZbX6+kPXuq jprZnC7JeTduWSW/Whi/WdMxoG+xBSPDqiwHz1WlN+W42UKLnPa9Z9Exa625bXB6z/JXcYwfsiW ZAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- drivers/md/dm.c | 23 +++++++++++++---------- drivers/md/md.c | 12 ++++++------ drivers/md/md.h | 2 +- include/linux/device-mapper.h | 2 +- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 8dcabf84d866..5f45dda430d7 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -726,7 +726,8 @@ static struct table_device *open_table_device(struct mapped_device *md, dev_t dev, blk_mode_t mode) { struct table_device *td; - struct bdev_handle *bdev_handle; + struct file *f_bdev; + struct block_device *bdev; u64 part_off; int r; @@ -735,34 +736,36 @@ static struct table_device *open_table_device(struct mapped_device *md, return ERR_PTR(-ENOMEM); refcount_set(&td->count, 1); - bdev_handle = bdev_open_by_dev(dev, mode, _dm_claim_ptr, NULL); - if (IS_ERR(bdev_handle)) { - r = PTR_ERR(bdev_handle); + f_bdev = bdev_file_open_by_dev(dev, mode, _dm_claim_ptr, NULL); + if (IS_ERR(f_bdev)) { + r = PTR_ERR(f_bdev); goto out_free_td; } + bdev = F_BDEV(f_bdev); + /* * We can be called before the dm disk is added. In that case we can't * register the holder relation here. It will be done once add_disk was * called. */ if (md->disk->slave_dir) { - r = bd_link_disk_holder(bdev_handle->bdev, md->disk); + r = bd_link_disk_holder(bdev, md->disk); if (r) goto out_blkdev_put; } td->dm_dev.mode = mode; - td->dm_dev.bdev = bdev_handle->bdev; - td->dm_dev.bdev_handle = bdev_handle; - td->dm_dev.dax_dev = fs_dax_get_by_bdev(bdev_handle->bdev, &part_off, + td->dm_dev.bdev = bdev; + td->dm_dev.f_bdev = f_bdev; + td->dm_dev.dax_dev = fs_dax_get_by_bdev(bdev, &part_off, NULL, NULL); format_dev_t(td->dm_dev.name, dev); list_add(&td->list, &md->table_devices); return td; out_blkdev_put: - bdev_release(bdev_handle); + fput(f_bdev); out_free_td: kfree(td); return ERR_PTR(r); @@ -775,7 +778,7 @@ static void close_table_device(struct table_device *td, struct mapped_device *md { if (md->disk->slave_dir) bd_unlink_disk_holder(td->dm_dev.bdev, md->disk); - bdev_release(td->dm_dev.bdev_handle); + fput(td->dm_dev.f_bdev); put_dax(td->dm_dev.dax_dev); list_del(&td->list); kfree(td); diff --git a/drivers/md/md.c b/drivers/md/md.c index 9bdd57324c37..2235285ac58a 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -2549,7 +2549,7 @@ static void export_rdev(struct md_rdev *rdev, struct mddev *mddev) if (test_bit(AutoDetected, &rdev->flags)) md_autodetect_dev(rdev->bdev->bd_dev); #endif - bdev_release(rdev->bdev_handle); + fput(rdev->f_bdev); rdev->bdev = NULL; kobject_put(&rdev->kobj); } @@ -3748,16 +3748,16 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe if (err) goto out_clear_rdev; - rdev->bdev_handle = bdev_open_by_dev(newdev, + rdev->f_bdev = bdev_file_open_by_dev(newdev, BLK_OPEN_READ | BLK_OPEN_WRITE, super_format == -2 ? &claim_rdev : rdev, NULL); - if (IS_ERR(rdev->bdev_handle)) { + if (IS_ERR(rdev->f_bdev)) { pr_warn("md: could not open device unknown-block(%u,%u).\n", MAJOR(newdev), MINOR(newdev)); - err = PTR_ERR(rdev->bdev_handle); + err = PTR_ERR(rdev->f_bdev); goto out_clear_rdev; } - rdev->bdev = rdev->bdev_handle->bdev; + rdev->bdev = F_BDEV(rdev->f_bdev); kobject_init(&rdev->kobj, &rdev_ktype); @@ -3788,7 +3788,7 @@ static struct md_rdev *md_import_device(dev_t newdev, int super_format, int supe return rdev; out_blkdev_put: - bdev_release(rdev->bdev_handle); + fput(rdev->f_bdev); out_clear_rdev: md_rdev_clear(rdev); out_free_rdev: diff --git a/drivers/md/md.h b/drivers/md/md.h index ade83af123a2..67d3a62a11f9 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -59,7 +59,7 @@ struct md_rdev { */ struct block_device *meta_bdev; struct block_device *bdev; /* block device handle */ - struct bdev_handle *bdev_handle; /* Handle from open for bdev */ + struct file *f_bdev; /* Handle from open for bdev */ struct page *sb_page, *bb_page; int sb_loaded; diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index 772ab4d74d94..c6eaa66d753b 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -165,7 +165,7 @@ void dm_error(const char *message); struct dm_dev { struct block_device *bdev; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct dax_device *dax_dev; blk_mode_t mode; char name[16]; From patchwork Wed Jan 3 12:55:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13509992 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15AC5199D5; Wed, 3 Jan 2024 12:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GdbpF7Mq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FEA8C433C9; Wed, 3 Jan 2024 12:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286538; bh=nuaXhZGdEQBqmp82NwU4XEExLM7A9/tXXoYdDuIdD3I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GdbpF7MqcjlVDe5Xfgvlkb4GGX72GjhOgb7rZNinWk2dK0jXy7uKWEm1ap35vxTb4 QKIbwcmSAqhBSh1U8HvJf2PBAKhQkQfDC7gdT7tNzzpwAfSvrwVQ8WMlbeBQ85HF99 X2SbOjEerPHalsFjaHzQkNayVwbfD7at6Rpf7WEPaVkQWTe50kO4NtBdcNPi77pztp opZDuNgkN2x0O3ttP32MUT3KBiYqVAM4pbJWQLA1xq8acFkbq1Ace4HJfoMSpVPeSu pcpe4BRGMsE1viKDmRuqo1ASq+rGLzlppnROLW8gcCZ7kOPB44qO9JV1bCfG9iAYDj mrnR/gGpFdEgQ== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:03 +0100 Subject: [PATCH RFC 05/34] swap: port block device usage to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-5-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=2583; i=brauner@kernel.org; h=from:subject:message-id; bh=nuaXhZGdEQBqmp82NwU4XEExLM7A9/tXXoYdDuIdD3I=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbT+MVcvTdZY5vLR8g+xK33mM7x1M7t65enqdYFbJ wb+swm43VHKwiDGxSArpsji0G4SLrecp2KzUaYGzBxWJpAhDFycAjCR098YGVasFt5jdyXCdvLs ivMHWu/f+sunfjxU8vuNfSc4e5fPduZi+F/s47udZWl7oIzDztgft7b0s2zdWfLx2wOm5/IxxlG 3HnEAAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- include/linux/swap.h | 2 +- mm/swapfile.c | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index f6dd6575b905..1c1114867637 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -298,7 +298,7 @@ struct swap_info_struct { unsigned int __percpu *cluster_next_cpu; /*percpu index for next allocation */ struct percpu_cluster __percpu *percpu_cluster; /* per cpu's swap location */ struct rb_root swap_extent_root;/* root of the swap extent rbtree */ - struct bdev_handle *bdev_handle;/* open handle of the bdev */ + struct file *f_bdev; /* open handle of the bdev */ struct block_device *bdev; /* swap device or bdev of swap file */ struct file *swap_file; /* seldom referenced */ unsigned int old_block_size; /* seldom referenced */ diff --git a/mm/swapfile.c b/mm/swapfile.c index 4bc70f459164..3b2ac701815b 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2530,10 +2530,10 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile) exit_swap_address_space(p->type); inode = mapping->host; - if (p->bdev_handle) { + if (p->f_bdev) { set_blocksize(p->bdev, old_block_size); - bdev_release(p->bdev_handle); - p->bdev_handle = NULL; + fput(p->f_bdev); + p->f_bdev = NULL; } inode_lock(inode); @@ -2763,14 +2763,14 @@ static int claim_swapfile(struct swap_info_struct *p, struct inode *inode) int error; if (S_ISBLK(inode->i_mode)) { - p->bdev_handle = bdev_open_by_dev(inode->i_rdev, + p->f_bdev = bdev_file_open_by_dev(inode->i_rdev, BLK_OPEN_READ | BLK_OPEN_WRITE, p, NULL); - if (IS_ERR(p->bdev_handle)) { - error = PTR_ERR(p->bdev_handle); - p->bdev_handle = NULL; + if (IS_ERR(p->f_bdev)) { + error = PTR_ERR(p->f_bdev); + p->f_bdev = NULL; return error; } - p->bdev = p->bdev_handle->bdev; + p->bdev = F_BDEV(p->f_bdev); p->old_block_size = block_size(p->bdev); error = set_blocksize(p->bdev, PAGE_SIZE); if (error < 0) @@ -3206,10 +3206,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) p->percpu_cluster = NULL; free_percpu(p->cluster_next_cpu); p->cluster_next_cpu = NULL; - if (p->bdev_handle) { + if (p->f_bdev) { set_blocksize(p->bdev, p->old_block_size); - bdev_release(p->bdev_handle); - p->bdev_handle = NULL; + fput(p->f_bdev); + p->f_bdev = NULL; } inode = NULL; destroy_swap_extents(p); From patchwork Wed Jan 3 12:55:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13509993 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3556319BCA; Wed, 3 Jan 2024 12:55:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PwfRSoXP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74B90C433C9; Wed, 3 Jan 2024 12:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286541; bh=HdL7l0XFXtIix3/XTatQNJYZC7y762IMtLbRHvdEu3o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PwfRSoXPlt7OsW5sEPSWtsrqEKk/kCP4b+b2pr6oDyWGoNOgNQddrueE5nXJNfxxY RMm/pye5ZyU0xxdCvGQUXdqqFm1fsCgQTzwtL8mR5MHLw9Q3/rtiF7oPFLFkU1okB4 ixga5pg+3HiutqEzb+6gEmi0h7ZaXuT8INTqmTIXM6hpEwuyUwwuihsNyPQDuAEOUf D8USJvq6FTbSEgKlqmCy8q5fF8xucqNoZKZ9mPTgRJqRTC217f5tVR+iuSGJ2hsCT7 zu7DWvx/8q/+955c8zZGLPfHqtnDhiLSXmGRoYwP5litviMol3vmzaYs12DKUcrALm 1CZowBlIn36HA== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:04 +0100 Subject: [PATCH RFC 06/34] power: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-6-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=2841; i=brauner@kernel.org; h=from:subject:message-id; bh=HdL7l0XFXtIix3/XTatQNJYZC7y762IMtLbRHvdEu3o=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTZ2ZMzqYwxKkNh32rd0OXhj5QnuKV8nXSz81xG/ 9xfWwI3dZSyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEzErZaR4e/Wv5sfFyZuYXTW E0q1Psr/QXrGOsNZHxe+v/H4uFpkRScjwwK1HYd2vPPt5p5xI+nJqQOuHDV8DdypD+dU5f/Qz1V J5wQA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- kernel/power/swap.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/kernel/power/swap.c b/kernel/power/swap.c index a2cb0babb5ec..e363c80d6259 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -222,7 +222,7 @@ int swsusp_swap_in_use(void) */ static unsigned short root_swap = 0xffff; -static struct bdev_handle *hib_resume_bdev_handle; +static struct file *hib_resume_f_bdev; struct hib_bio_batch { atomic_t count; @@ -276,7 +276,7 @@ static int hib_submit_io(blk_opf_t opf, pgoff_t page_off, void *addr, struct bio *bio; int error = 0; - bio = bio_alloc(hib_resume_bdev_handle->bdev, 1, opf, + bio = bio_alloc(F_BDEV(hib_resume_f_bdev), 1, opf, GFP_NOIO | __GFP_HIGH); bio->bi_iter.bi_sector = page_off * (PAGE_SIZE >> 9); @@ -357,14 +357,14 @@ static int swsusp_swap_check(void) return res; root_swap = res; - hib_resume_bdev_handle = bdev_open_by_dev(swsusp_resume_device, + hib_resume_f_bdev = bdev_file_open_by_dev(swsusp_resume_device, BLK_OPEN_WRITE, NULL, NULL); - if (IS_ERR(hib_resume_bdev_handle)) - return PTR_ERR(hib_resume_bdev_handle); + if (IS_ERR(hib_resume_f_bdev)) + return PTR_ERR(hib_resume_f_bdev); - res = set_blocksize(hib_resume_bdev_handle->bdev, PAGE_SIZE); + res = set_blocksize(F_BDEV(hib_resume_f_bdev), PAGE_SIZE); if (res < 0) - bdev_release(hib_resume_bdev_handle); + fput(hib_resume_f_bdev); return res; } @@ -1523,10 +1523,10 @@ int swsusp_check(bool exclusive) void *holder = exclusive ? &swsusp_holder : NULL; int error; - hib_resume_bdev_handle = bdev_open_by_dev(swsusp_resume_device, + hib_resume_f_bdev = bdev_file_open_by_dev(swsusp_resume_device, BLK_OPEN_READ, holder, NULL); - if (!IS_ERR(hib_resume_bdev_handle)) { - set_blocksize(hib_resume_bdev_handle->bdev, PAGE_SIZE); + if (!IS_ERR(hib_resume_f_bdev)) { + set_blocksize(F_BDEV(hib_resume_f_bdev), PAGE_SIZE); clear_page(swsusp_header); error = hib_submit_io(REQ_OP_READ, swsusp_resume_block, swsusp_header, NULL); @@ -1551,11 +1551,11 @@ int swsusp_check(bool exclusive) put: if (error) - bdev_release(hib_resume_bdev_handle); + fput(hib_resume_f_bdev); else pr_debug("Image signature found, resuming\n"); } else { - error = PTR_ERR(hib_resume_bdev_handle); + error = PTR_ERR(hib_resume_f_bdev); } if (error) @@ -1571,12 +1571,12 @@ int swsusp_check(bool exclusive) void swsusp_close(void) { - if (IS_ERR(hib_resume_bdev_handle)) { + if (IS_ERR(hib_resume_f_bdev)) { pr_debug("Image device not initialised\n"); return; } - bdev_release(hib_resume_bdev_handle); + fput(hib_resume_f_bdev); } /** From patchwork Wed Jan 3 12:55:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13509994 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96B661A58B; Wed, 3 Jan 2024 12:55:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kaMMUeLY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DD90C43397; Wed, 3 Jan 2024 12:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286543; bh=SUWQhrFleGuumt8/1sW8NuFvQDVTinRTMZf3WP5XVts=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kaMMUeLYYbZ78IpD3F7jMhKX+z+KvLH5HDY/nqkFdFOhaxSylfPnKhZUTRh+j4azH pofD4Tudko5IplARBFSBPg/2+PgpxPzI0AKFBzvStvB3Pg+CThQ3+jcE8sSQ2Hb1Ip ioXhx8BLFEAYguKt3BZaeEs8hmtyGzxAKw5yMM2Vr00nhlGBzEMxdf6d/T6Q7lNcFR 22ALwPCWQ8YZMO66ntbWeD7+YER4Sz/AjAu5/lzpTnt3ToQCfvJGRLlwKedHPzGErK pDvVcAZIrZxpwjOqJDHxYXvLqRb7fIAWmCwQm2OzioutOFemL2c0I1F3QdGHPsLfCp PogC6gpewChvQ== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:05 +0100 Subject: [PATCH RFC 07/34] xfs: port block device access to files Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-7-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=5349; i=brauner@kernel.org; h=from:subject:message-id; bh=SUWQhrFleGuumt8/1sW8NuFvQDVTinRTMZf3WP5XVts=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTZMX/qS8Ffbmv/7qhSXq6y4M7Byek67MYL9Dh65 tj07vn+oKOUhUGMi0FWTJHFod0kXG45T8Vmo0wNmDmsTCBDGLg4BWAiSV2MDD9908/YWmm2Vzl/ P/PFYrtJvpdRNrN36ErWfR857v8pW8DI8ED50vIks4o4NZv0f3W96TVyS0OWXzTNyro6c9NpC69 QZgA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- fs/xfs/xfs_buf.c | 10 +++++----- fs/xfs/xfs_buf.h | 4 ++-- fs/xfs/xfs_super.c | 43 +++++++++++++++++++++---------------------- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 545c7991b9b5..685eb2a9f9d2 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -1951,7 +1951,7 @@ xfs_free_buftarg( fs_put_dax(btp->bt_daxdev, btp->bt_mount); /* the main block device is closed by kill_block_super */ if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev) - bdev_release(btp->bt_bdev_handle); + fput(btp->bt_f_bdev); kmem_free(btp); } @@ -1994,7 +1994,7 @@ xfs_setsize_buftarg_early( struct xfs_buftarg * xfs_alloc_buftarg( struct xfs_mount *mp, - struct bdev_handle *bdev_handle) + struct file *f_bdev) { xfs_buftarg_t *btp; const struct dax_holder_operations *ops = NULL; @@ -2005,9 +2005,9 @@ xfs_alloc_buftarg( btp = kmem_zalloc(sizeof(*btp), KM_NOFS); btp->bt_mount = mp; - btp->bt_bdev_handle = bdev_handle; - btp->bt_dev = bdev_handle->bdev->bd_dev; - btp->bt_bdev = bdev_handle->bdev; + btp->bt_f_bdev = f_bdev; + btp->bt_bdev = F_BDEV(f_bdev); + btp->bt_dev = btp->bt_bdev->bd_dev; btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off, mp, ops); diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index c86e16419656..4005dcffb792 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -98,7 +98,7 @@ typedef unsigned int xfs_buf_flags_t; */ typedef struct xfs_buftarg { dev_t bt_dev; - struct bdev_handle *bt_bdev_handle; + struct file *bt_f_bdev; struct block_device *bt_bdev; struct dax_device *bt_daxdev; u64 bt_dax_part_off; @@ -365,7 +365,7 @@ xfs_buf_update_cksum(struct xfs_buf *bp, unsigned long cksum_offset) * Handling of buftargs. */ struct xfs_buftarg *xfs_alloc_buftarg(struct xfs_mount *mp, - struct bdev_handle *bdev_handle); + struct file *f_bdev); extern void xfs_free_buftarg(struct xfs_buftarg *); extern void xfs_buftarg_wait(struct xfs_buftarg *); extern void xfs_buftarg_drain(struct xfs_buftarg *); diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index 0e64220bffdc..01ef0ef83c41 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -362,16 +362,16 @@ STATIC int xfs_blkdev_get( xfs_mount_t *mp, const char *name, - struct bdev_handle **handlep) + struct file **f_bdevp) { int error = 0; - *handlep = bdev_open_by_path(name, + *f_bdevp = bdev_file_open_by_path(name, BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES, mp->m_super, &fs_holder_ops); - if (IS_ERR(*handlep)) { - error = PTR_ERR(*handlep); - *handlep = NULL; + if (IS_ERR(*f_bdevp)) { + error = PTR_ERR(*f_bdevp); + *f_bdevp = NULL; xfs_warn(mp, "Invalid device [%s], error=%d", name, error); } @@ -436,26 +436,25 @@ xfs_open_devices( { struct super_block *sb = mp->m_super; struct block_device *ddev = sb->s_bdev; - struct bdev_handle *logdev_handle = NULL, *rtdev_handle = NULL; + struct file *f_logdev = NULL, *f_rtdev = NULL; int error; /* * Open real time and log devices - order is important. */ if (mp->m_logname) { - error = xfs_blkdev_get(mp, mp->m_logname, &logdev_handle); + error = xfs_blkdev_get(mp, mp->m_logname, &f_logdev); if (error) return error; } if (mp->m_rtname) { - error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev_handle); + error = xfs_blkdev_get(mp, mp->m_rtname, &f_rtdev); if (error) goto out_close_logdev; - if (rtdev_handle->bdev == ddev || - (logdev_handle && - rtdev_handle->bdev == logdev_handle->bdev)) { + if (F_BDEV(f_rtdev) == ddev || + (f_logdev && F_BDEV(f_rtdev) == F_BDEV(f_logdev))) { xfs_warn(mp, "Cannot mount filesystem with identical rtdev and ddev/logdev."); error = -EINVAL; @@ -467,25 +466,25 @@ xfs_open_devices( * Setup xfs_mount buffer target pointers */ error = -ENOMEM; - mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb_bdev_handle(sb)); + mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb->s_f_bdev); if (!mp->m_ddev_targp) goto out_close_rtdev; - if (rtdev_handle) { - mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_handle); + if (f_rtdev) { + mp->m_rtdev_targp = xfs_alloc_buftarg(mp, f_rtdev); if (!mp->m_rtdev_targp) goto out_free_ddev_targ; } - if (logdev_handle && logdev_handle->bdev != ddev) { - mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_handle); + if (f_logdev && F_BDEV(f_logdev) != ddev) { + mp->m_logdev_targp = xfs_alloc_buftarg(mp, f_logdev); if (!mp->m_logdev_targp) goto out_free_rtdev_targ; } else { mp->m_logdev_targp = mp->m_ddev_targp; /* Handle won't be used, drop it */ - if (logdev_handle) - bdev_release(logdev_handle); + if (f_logdev) + fput(f_logdev); } return 0; @@ -496,11 +495,11 @@ xfs_open_devices( out_free_ddev_targ: xfs_free_buftarg(mp->m_ddev_targp); out_close_rtdev: - if (rtdev_handle) - bdev_release(rtdev_handle); + if (f_rtdev) + fput(f_rtdev); out_close_logdev: - if (logdev_handle) - bdev_release(logdev_handle); + if (f_logdev) + fput(f_logdev); return error; } From patchwork Wed Jan 3 12:55:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13509995 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A1101A58B; Wed, 3 Jan 2024 12:55:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="grxu89kJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C096C433C8; Wed, 3 Jan 2024 12:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286545; bh=E1pb3tWRhbIb1ThnWwVIbSlHfg+upza6Ty2NR9Cnaeo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=grxu89kJ+vydYrrXOCzqK7V1iNBZwNjTe1Vu6CBbIB6DlYRbSKRhWqkvcklp+SIls F+lO9QL3sB1bFNut4UAZAt0SAV1Mia6ENpM1hWWzNSLGvyC/UnS6PqC+emxYSX/lag H/Yuo2tQkjmYfI2C7XBU/Uogj071XL9f5hqWQ2UWRUNag4ezPFxf2y3Tk0Lb7VAGSe jMz+mtZQBtaN7XZdHbRXCxpNwCjiGX3dYEg+FcztR+DWbkcuvXD3YM1yXuqgpW7LBQ PfDQnSW25qlfjolbUwhJGic26KUrBlJ2a4JRWoDYfC5tFCVJhoiHczckAnvpLpcJdP K80I/LgSuJlJQ== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:06 +0100 Subject: [PATCH RFC 08/34] drbd: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-8-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=5353; i=brauner@kernel.org; h=from:subject:message-id; bh=E1pb3tWRhbIb1ThnWwVIbSlHfg+upza6Ty2NR9Cnaeo=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbThjwlW8Ln7f37nk4Lzx67FHp36eGZLAsfZ/2vch QUic2dP7ChhYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZjI5HaGv4Knar7VNfZ9KT9t 5GLzoJfz2KaeRZwsmUc3V2t9XGX4fTnDN31nz6+fvVYwFgtYnpBYIzVvxuPpF//bGs+Zr5jYadD PCQA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- drivers/block/drbd/drbd_int.h | 4 +-- drivers/block/drbd/drbd_nl.c | 58 +++++++++++++++++++++---------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h index c21e3732759e..3f57b3a04f39 100644 --- a/drivers/block/drbd/drbd_int.h +++ b/drivers/block/drbd/drbd_int.h @@ -524,9 +524,9 @@ struct drbd_md { struct drbd_backing_dev { struct block_device *backing_bdev; - struct bdev_handle *backing_bdev_handle; + struct file *f_backing_bdev; struct block_device *md_bdev; - struct bdev_handle *md_bdev_handle; + struct file *f_md_bdev; struct drbd_md md; struct disk_conf *disk_conf; /* RCU, for updates: resource->conf_update */ sector_t known_size; /* last known size of that backing device */ diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c index 43747a1aae43..d53a681286cd 100644 --- a/drivers/block/drbd/drbd_nl.c +++ b/drivers/block/drbd/drbd_nl.c @@ -1635,45 +1635,45 @@ int drbd_adm_disk_opts(struct sk_buff *skb, struct genl_info *info) return 0; } -static struct bdev_handle *open_backing_dev(struct drbd_device *device, +static struct file *open_backing_dev(struct drbd_device *device, const char *bdev_path, void *claim_ptr, bool do_bd_link) { - struct bdev_handle *handle; + struct file *file; int err = 0; - handle = bdev_open_by_path(bdev_path, BLK_OPEN_READ | BLK_OPEN_WRITE, - claim_ptr, NULL); - if (IS_ERR(handle)) { + file = bdev_file_open_by_path(bdev_path, BLK_OPEN_READ | BLK_OPEN_WRITE, + claim_ptr, NULL); + if (IS_ERR(file)) { drbd_err(device, "open(\"%s\") failed with %ld\n", - bdev_path, PTR_ERR(handle)); - return handle; + bdev_path, PTR_ERR(file)); + return file; } if (!do_bd_link) - return handle; + return file; - err = bd_link_disk_holder(handle->bdev, device->vdisk); + err = bd_link_disk_holder(F_BDEV(file), device->vdisk); if (err) { - bdev_release(handle); + fput(file); drbd_err(device, "bd_link_disk_holder(\"%s\", ...) failed with %d\n", bdev_path, err); - handle = ERR_PTR(err); + file = ERR_PTR(err); } - return handle; + return file; } static int open_backing_devices(struct drbd_device *device, struct disk_conf *new_disk_conf, struct drbd_backing_dev *nbc) { - struct bdev_handle *handle; + struct file *file; - handle = open_backing_dev(device, new_disk_conf->backing_dev, device, + file = open_backing_dev(device, new_disk_conf->backing_dev, device, true); - if (IS_ERR(handle)) + if (IS_ERR(file)) return ERR_OPEN_DISK; - nbc->backing_bdev = handle->bdev; - nbc->backing_bdev_handle = handle; + nbc->backing_bdev = F_BDEV(file); + nbc->f_backing_bdev = file; /* * meta_dev_idx >= 0: external fixed size, possibly multiple @@ -1683,7 +1683,7 @@ static int open_backing_devices(struct drbd_device *device, * should check it for you already; but if you don't, or * someone fooled it, we need to double check here) */ - handle = open_backing_dev(device, new_disk_conf->meta_dev, + file = open_backing_dev(device, new_disk_conf->meta_dev, /* claim ptr: device, if claimed exclusively; shared drbd_m_holder, * if potentially shared with other drbd minors */ (new_disk_conf->meta_dev_idx < 0) ? (void*)device : (void*)drbd_m_holder, @@ -1691,21 +1691,21 @@ static int open_backing_devices(struct drbd_device *device, * as would happen with internal metadata. */ (new_disk_conf->meta_dev_idx != DRBD_MD_INDEX_FLEX_INT && new_disk_conf->meta_dev_idx != DRBD_MD_INDEX_INTERNAL)); - if (IS_ERR(handle)) + if (IS_ERR(file)) return ERR_OPEN_MD_DISK; - nbc->md_bdev = handle->bdev; - nbc->md_bdev_handle = handle; + nbc->md_bdev = F_BDEV(file); + nbc->f_md_bdev = file; return NO_ERROR; } static void close_backing_dev(struct drbd_device *device, - struct bdev_handle *handle, bool do_bd_unlink) + struct file *f_bdev, bool do_bd_unlink) { - if (!handle) + if (!f_bdev) return; if (do_bd_unlink) - bd_unlink_disk_holder(handle->bdev, device->vdisk); - bdev_release(handle); + bd_unlink_disk_holder(F_BDEV(f_bdev), device->vdisk); + fput(f_bdev); } void drbd_backing_dev_free(struct drbd_device *device, struct drbd_backing_dev *ldev) @@ -1713,9 +1713,9 @@ void drbd_backing_dev_free(struct drbd_device *device, struct drbd_backing_dev * if (ldev == NULL) return; - close_backing_dev(device, ldev->md_bdev_handle, + close_backing_dev(device, ldev->f_md_bdev, ldev->md_bdev != ldev->backing_bdev); - close_backing_dev(device, ldev->backing_bdev_handle, true); + close_backing_dev(device, ldev->f_backing_bdev, true); kfree(ldev->disk_conf); kfree(ldev); @@ -2131,9 +2131,9 @@ int drbd_adm_attach(struct sk_buff *skb, struct genl_info *info) fail: conn_reconfig_done(connection); if (nbc) { - close_backing_dev(device, nbc->md_bdev_handle, + close_backing_dev(device, nbc->f_md_bdev, nbc->md_bdev != nbc->backing_bdev); - close_backing_dev(device, nbc->backing_bdev_handle, true); + close_backing_dev(device, nbc->f_backing_bdev, true); kfree(nbc); } kfree(new_disk_conf); From patchwork Wed Jan 3 12:55:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13509996 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD3DC1A5A6; Wed, 3 Jan 2024 12:55:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="J7UkfKkL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 928A3C433CC; Wed, 3 Jan 2024 12:55:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286547; bh=9fpEPAsW69T9BRTbIsSVjhgwkRf2MLnDuWXV8LEcSF8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=J7UkfKkLUdEPvfbtgxkC9mO3TduR7KA2yefMDL/OwmAQ+do4UCdTi3+pwEriHgVeg Tub1uSvayBb+cEONgF8yvjrXlauB+Y1ZXFZ1soMM8M9sU4PLzIU61tGiY5gwmbzTUW JKDl/WlwpoYHDn1NT5a3pSfc2rZynOrht4o4hESG/UlJq/8ZWTvYYcu6wPef3CksYn vKS2YGAcdQn+kk2E90nhqmSCdkM0GNjM2KsqJfF2vAjHOh9HMV6lOQ143KSK07pVvd OvCm920slGe6he1KSsL/CMQdO9JR4gyzp3qIfzp14WQhKl5G0x3U/BGuv+9YkDm7Ct NKbbJHVB6AtSQ== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:07 +0100 Subject: [PATCH RFC 09/34] pktcdvd: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-9-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=8695; i=brauner@kernel.org; h=from:subject:message-id; bh=9fpEPAsW69T9BRTbIsSVjhgwkRf2MLnDuWXV8LEcSF8=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTZrPGoOq3q+dLMy5HhERLfZn/7HHJtrU5cyu/VW rPmn5UU6ihlYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZjIBxdGhi2iShnTT+6vqH/T G85dtubaxAOqH1PsVS7ZyAtkmcotyWJkWHF75ZXNtr7+6lP1rhXqXWyayb0w5Z9otsN9gUqliTN 52AA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- drivers/block/pktcdvd.c | 68 ++++++++++++++++++++++++------------------------- include/linux/pktcdvd.h | 4 +-- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index d56d972aadb3..02ab52e55229 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -340,8 +340,8 @@ static ssize_t device_map_show(const struct class *c, const struct class_attribu n += sysfs_emit_at(data, n, "%s %u:%u %u:%u\n", pd->disk->disk_name, MAJOR(pd->pkt_dev), MINOR(pd->pkt_dev), - MAJOR(pd->bdev_handle->bdev->bd_dev), - MINOR(pd->bdev_handle->bdev->bd_dev)); + MAJOR(F_BDEV(pd->f_bdev)->bd_dev), + MINOR(F_BDEV(pd->f_bdev)->bd_dev)); } mutex_unlock(&ctl_mutex); return n; @@ -438,7 +438,7 @@ static int pkt_seq_show(struct seq_file *m, void *p) int states[PACKET_NUM_STATES]; seq_printf(m, "Writer %s mapped to %pg:\n", pd->disk->disk_name, - pd->bdev_handle->bdev); + F_BDEV(pd->f_bdev)); seq_printf(m, "\nSettings:\n"); seq_printf(m, "\tpacket size:\t\t%dkB\n", pd->settings.size / 2); @@ -715,7 +715,7 @@ static void pkt_rbtree_insert(struct pktcdvd_device *pd, struct pkt_rb_node *nod */ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *cgc) { - struct request_queue *q = bdev_get_queue(pd->bdev_handle->bdev); + struct request_queue *q = bdev_get_queue(F_BDEV(pd->f_bdev)); struct scsi_cmnd *scmd; struct request *rq; int ret = 0; @@ -1048,7 +1048,7 @@ static void pkt_gather_data(struct pktcdvd_device *pd, struct packet_data *pkt) continue; bio = pkt->r_bios[f]; - bio_init(bio, pd->bdev_handle->bdev, bio->bi_inline_vecs, 1, + bio_init(bio, F_BDEV(pd->f_bdev), bio->bi_inline_vecs, 1, REQ_OP_READ); bio->bi_iter.bi_sector = pkt->sector + f * (CD_FRAMESIZE >> 9); bio->bi_end_io = pkt_end_io_read; @@ -1264,7 +1264,7 @@ static void pkt_start_write(struct pktcdvd_device *pd, struct packet_data *pkt) struct device *ddev = disk_to_dev(pd->disk); int f; - bio_init(pkt->w_bio, pd->bdev_handle->bdev, pkt->w_bio->bi_inline_vecs, + bio_init(pkt->w_bio, F_BDEV(pd->f_bdev), pkt->w_bio->bi_inline_vecs, pkt->frames, REQ_OP_WRITE); pkt->w_bio->bi_iter.bi_sector = pkt->sector; pkt->w_bio->bi_end_io = pkt_end_io_packet_write; @@ -2162,20 +2162,20 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write) int ret; long lba; struct request_queue *q; - struct bdev_handle *bdev_handle; + struct file *f_bdev; /* * We need to re-open the cdrom device without O_NONBLOCK to be able * to read/write from/to it. It is already opened in O_NONBLOCK mode * so open should not fail. */ - bdev_handle = bdev_open_by_dev(pd->bdev_handle->bdev->bd_dev, + f_bdev = bdev_file_open_by_dev(F_BDEV(pd->f_bdev)->bd_dev, BLK_OPEN_READ, pd, NULL); - if (IS_ERR(bdev_handle)) { - ret = PTR_ERR(bdev_handle); + if (IS_ERR(f_bdev)) { + ret = PTR_ERR(f_bdev); goto out; } - pd->open_bdev_handle = bdev_handle; + pd->f_open_bdev = f_bdev; ret = pkt_get_last_written(pd, &lba); if (ret) { @@ -2184,9 +2184,9 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write) } set_capacity(pd->disk, lba << 2); - set_capacity_and_notify(pd->bdev_handle->bdev->bd_disk, lba << 2); + set_capacity_and_notify(F_BDEV(pd->f_bdev)->bd_disk, lba << 2); - q = bdev_get_queue(pd->bdev_handle->bdev); + q = bdev_get_queue(F_BDEV(pd->f_bdev)); if (write) { ret = pkt_open_write(pd); if (ret) @@ -2218,7 +2218,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, bool write) return 0; out_putdev: - bdev_release(bdev_handle); + fput(f_bdev); out: return ret; } @@ -2237,8 +2237,8 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush) pkt_lock_door(pd, 0); pkt_set_speed(pd, MAX_SPEED, MAX_SPEED); - bdev_release(pd->open_bdev_handle); - pd->open_bdev_handle = NULL; + fput(pd->f_open_bdev); + pd->f_open_bdev = NULL; pkt_shrink_pktlist(pd); } @@ -2326,7 +2326,7 @@ static void pkt_end_io_read_cloned(struct bio *bio) static void pkt_make_request_read(struct pktcdvd_device *pd, struct bio *bio) { - struct bio *cloned_bio = bio_alloc_clone(pd->bdev_handle->bdev, bio, + struct bio *cloned_bio = bio_alloc_clone(F_BDEV(pd->f_bdev), bio, GFP_NOIO, &pkt_bio_set); struct packet_stacked_data *psd = mempool_alloc(&psd_pool, GFP_NOIO); @@ -2497,7 +2497,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) { struct device *ddev = disk_to_dev(pd->disk); int i; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct scsi_device *sdev; if (pd->pkt_dev == dev) { @@ -2508,9 +2508,9 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) struct pktcdvd_device *pd2 = pkt_devs[i]; if (!pd2) continue; - if (pd2->bdev_handle->bdev->bd_dev == dev) { + if (F_BDEV(pd2->f_bdev)->bd_dev == dev) { dev_err(ddev, "%pg already setup\n", - pd2->bdev_handle->bdev); + F_BDEV(pd2->f_bdev)); return -EBUSY; } if (pd2->pkt_dev == dev) { @@ -2519,13 +2519,13 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) } } - bdev_handle = bdev_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_NDELAY, + f_bdev = bdev_file_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_NDELAY, NULL, NULL); - if (IS_ERR(bdev_handle)) - return PTR_ERR(bdev_handle); - sdev = scsi_device_from_queue(bdev_handle->bdev->bd_disk->queue); + if (IS_ERR(f_bdev)) + return PTR_ERR(f_bdev); + sdev = scsi_device_from_queue(F_BDEV(f_bdev)->bd_disk->queue); if (!sdev) { - bdev_release(bdev_handle); + fput(f_bdev); return -EINVAL; } put_device(&sdev->sdev_gendev); @@ -2533,8 +2533,8 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) /* This is safe, since we have a reference from open(). */ __module_get(THIS_MODULE); - pd->bdev_handle = bdev_handle; - set_blocksize(bdev_handle->bdev, CD_FRAMESIZE); + pd->f_bdev = f_bdev; + set_blocksize(F_BDEV(f_bdev), CD_FRAMESIZE); pkt_init_queue(pd); @@ -2546,11 +2546,11 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) } proc_create_single_data(pd->disk->disk_name, 0, pkt_proc, pkt_seq_show, pd); - dev_notice(ddev, "writer mapped to %pg\n", bdev_handle->bdev); + dev_notice(ddev, "writer mapped to %pg\n", F_BDEV(f_bdev)); return 0; out_mem: - bdev_release(bdev_handle); + fput(f_bdev); /* This is safe: open() is still holding a reference. */ module_put(THIS_MODULE); return -ENOMEM; @@ -2605,9 +2605,9 @@ static unsigned int pkt_check_events(struct gendisk *disk, if (!pd) return 0; - if (!pd->bdev_handle) + if (!pd->f_bdev) return 0; - attached_disk = pd->bdev_handle->bdev->bd_disk; + attached_disk = F_BDEV(pd->f_bdev)->bd_disk; if (!attached_disk || !attached_disk->fops->check_events) return 0; return attached_disk->fops->check_events(attached_disk, clearing); @@ -2692,7 +2692,7 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev) goto out_mem2; /* inherit events of the host device */ - disk->events = pd->bdev_handle->bdev->bd_disk->events; + disk->events = F_BDEV(pd->f_bdev)->bd_disk->events; ret = add_disk(disk); if (ret) @@ -2757,7 +2757,7 @@ static int pkt_remove_dev(dev_t pkt_dev) pkt_debugfs_dev_remove(pd); pkt_sysfs_dev_remove(pd); - bdev_release(pd->bdev_handle); + fput(pd->f_bdev); remove_proc_entry(pd->disk->disk_name, pkt_proc); dev_notice(ddev, "writer unmapped\n"); @@ -2784,7 +2784,7 @@ static void pkt_get_status(struct pkt_ctrl_command *ctrl_cmd) pd = pkt_find_dev_from_minor(ctrl_cmd->dev_index); if (pd) { - ctrl_cmd->dev = new_encode_dev(pd->bdev_handle->bdev->bd_dev); + ctrl_cmd->dev = new_encode_dev(F_BDEV(pd->f_bdev)->bd_dev); ctrl_cmd->pkt_dev = new_encode_dev(pd->pkt_dev); } else { ctrl_cmd->dev = 0; diff --git a/include/linux/pktcdvd.h b/include/linux/pktcdvd.h index 79594aeb160d..e202ec04b7e0 100644 --- a/include/linux/pktcdvd.h +++ b/include/linux/pktcdvd.h @@ -154,9 +154,9 @@ struct packet_stacked_data struct pktcdvd_device { - struct bdev_handle *bdev_handle; /* dev attached */ + struct file *f_bdev; /* dev attached */ /* handle acquired for bdev during pkt_open_dev() */ - struct bdev_handle *open_bdev_handle; + struct file *f_open_bdev; dev_t pkt_dev; /* our dev */ struct packet_settings settings; struct packet_stats stats; From patchwork Wed Jan 3 12:55:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13509997 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 843221A5B5; Wed, 3 Jan 2024 12:55:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="peFQDMso" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCBB6C433C8; Wed, 3 Jan 2024 12:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286549; bh=gUlJGbwQM/Tvz70GqGux5aXGVz5fJJJBN/HbpMr9nDQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=peFQDMsoJfyTel+udKHo75p1FUK6i6ssJ10+X0J8w8VW/t2GNRW9dXACJ4Hpw4FoO nqgydYrVQHUX8zhpSJOcZLP4tb55v2HnJwASTBgfsYdOggl80Y4c/Hyovo20D+k1Jf XF5f1TUlgahEUw45qw3R6CgV5W6w5PCBvSsi9mrJxK+Auuo4/xVQfl3GQEE/cOmqwb 2D7Ej9SvrknJWhGN3O7HIULI+eN+yW3M8kr9A8FesG1wyWrw3gpcOE+XvW35Wye1s3 Zh8SzTCQzW6mDt8KhGtuPnkYi4+m5CSDakV7Gl7SLFDNn9hamZmLnirnRgvx7tmsdf 3iRTySsBnSafQ== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:08 +0100 Subject: [PATCH RFC 10/34] rnbd: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-10-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=4955; i=brauner@kernel.org; h=from:subject:message-id; bh=gUlJGbwQM/Tvz70GqGux5aXGVz5fJJJBN/HbpMr9nDQ=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbRxm3UlVWgG43IvGfnkqDdhfZGzlwQvnTBXbPLjL ofpi61Wd5SyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEykX4yRYd368yacAs7X7u3n KNifdP6E3xaz7DtpKkECi013hT+6ZcvIcPaDX1Xg3x2fZVgCdEyEFOZkl1VaRu+cJVd6+n9z3fP l/AA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- drivers/block/rnbd/rnbd-srv.c | 26 +++++++++++++------------- drivers/block/rnbd/rnbd-srv.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c index 65de51f3dfd9..2aeedca4ba21 100644 --- a/drivers/block/rnbd/rnbd-srv.c +++ b/drivers/block/rnbd/rnbd-srv.c @@ -145,7 +145,7 @@ static int process_rdma(struct rnbd_srv_session *srv_sess, priv->sess_dev = sess_dev; priv->id = id; - bio = bio_alloc(sess_dev->bdev_handle->bdev, 1, + bio = bio_alloc(F_BDEV(sess_dev->f_bdev), 1, rnbd_to_bio_flags(le32_to_cpu(msg->rw)), GFP_KERNEL); if (bio_add_page(bio, virt_to_page(data), datalen, offset_in_page(data)) != datalen) { @@ -219,7 +219,7 @@ void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id) rnbd_put_sess_dev(sess_dev); wait_for_completion(&dc); /* wait for inflights to drop to zero */ - bdev_release(sess_dev->bdev_handle); + fput(sess_dev->f_bdev); mutex_lock(&sess_dev->dev->lock); list_del(&sess_dev->dev_list); if (!sess_dev->readonly) @@ -534,7 +534,7 @@ rnbd_srv_get_or_create_srv_dev(struct block_device *bdev, static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp, struct rnbd_srv_sess_dev *sess_dev) { - struct block_device *bdev = sess_dev->bdev_handle->bdev; + struct block_device *bdev = F_BDEV(sess_dev->f_bdev); rsp->hdr.type = cpu_to_le16(RNBD_MSG_OPEN_RSP); rsp->device_id = cpu_to_le32(sess_dev->device_id); @@ -559,7 +559,7 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp, static struct rnbd_srv_sess_dev * rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess, const struct rnbd_msg_open *open_msg, - struct bdev_handle *handle, bool readonly, + struct file *f_bdev, bool readonly, struct rnbd_srv_dev *srv_dev) { struct rnbd_srv_sess_dev *sdev = rnbd_sess_dev_alloc(srv_sess); @@ -571,7 +571,7 @@ rnbd_srv_create_set_sess_dev(struct rnbd_srv_session *srv_sess, strscpy(sdev->pathname, open_msg->dev_name, sizeof(sdev->pathname)); - sdev->bdev_handle = handle; + sdev->f_bdev = f_bdev; sdev->sess = srv_sess; sdev->dev = srv_dev; sdev->readonly = readonly; @@ -676,7 +676,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, struct rnbd_srv_dev *srv_dev; struct rnbd_srv_sess_dev *srv_sess_dev; const struct rnbd_msg_open *open_msg = msg; - struct bdev_handle *bdev_handle; + struct file *f_bdev; blk_mode_t open_flags = BLK_OPEN_READ; char *full_path; struct rnbd_msg_open_rsp *rsp = data; @@ -714,15 +714,15 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, goto reject; } - bdev_handle = bdev_open_by_path(full_path, open_flags, NULL, NULL); - if (IS_ERR(bdev_handle)) { - ret = PTR_ERR(bdev_handle); + f_bdev = bdev_file_open_by_path(full_path, open_flags, NULL, NULL); + if (IS_ERR(f_bdev)) { + ret = PTR_ERR(f_bdev); pr_err("Opening device '%s' on session %s failed, failed to open the block device, err: %d\n", full_path, srv_sess->sessname, ret); goto free_path; } - srv_dev = rnbd_srv_get_or_create_srv_dev(bdev_handle->bdev, srv_sess, + srv_dev = rnbd_srv_get_or_create_srv_dev(F_BDEV(f_bdev), srv_sess, open_msg->access_mode); if (IS_ERR(srv_dev)) { pr_err("Opening device '%s' on session %s failed, creating srv_dev failed, err: %ld\n", @@ -732,7 +732,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, } srv_sess_dev = rnbd_srv_create_set_sess_dev(srv_sess, open_msg, - bdev_handle, + f_bdev, open_msg->access_mode == RNBD_ACCESS_RO, srv_dev); if (IS_ERR(srv_sess_dev)) { @@ -748,7 +748,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, */ mutex_lock(&srv_dev->lock); if (!srv_dev->dev_kobj.state_in_sysfs) { - ret = rnbd_srv_create_dev_sysfs(srv_dev, bdev_handle->bdev); + ret = rnbd_srv_create_dev_sysfs(srv_dev, F_BDEV(f_bdev)); if (ret) { mutex_unlock(&srv_dev->lock); rnbd_srv_err(srv_sess_dev, @@ -791,7 +791,7 @@ static int process_msg_open(struct rnbd_srv_session *srv_sess, } rnbd_put_srv_dev(srv_dev); blkdev_put: - bdev_release(bdev_handle); + fput(f_bdev); free_path: kfree(full_path); reject: diff --git a/drivers/block/rnbd/rnbd-srv.h b/drivers/block/rnbd/rnbd-srv.h index 343cc682b617..c91973f4326e 100644 --- a/drivers/block/rnbd/rnbd-srv.h +++ b/drivers/block/rnbd/rnbd-srv.h @@ -46,7 +46,7 @@ struct rnbd_srv_dev { struct rnbd_srv_sess_dev { /* Entry inside rnbd_srv_dev struct */ struct list_head dev_list; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct rnbd_srv_session *sess; struct rnbd_srv_dev *dev; struct kobject kobj; From patchwork Wed Jan 3 12:55:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13509998 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A58941A70B; Wed, 3 Jan 2024 12:55:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gyns0UGT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1887C433C7; Wed, 3 Jan 2024 12:55:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286551; bh=JuWJr6+7i2yrkqNGwt5xMzLZMnlqBoh0zK4VKx+/xgY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gyns0UGT80aOIXTU22XaTj+sY1rI8jgOcB7Nvtq5mbyBwdc2B0KNzWkIUHCOFtonm vxJuLMliguRFSe3C42yLVYLhcYJQFUiEkXWmJLlqmXAmr7eywRhs9r9KW7iHfksDCr acC6hhPur5omS5mXt3ZXbeW4P/jHC273Bp/7YMfhRuvU4XuzgNM0YcAteDeJaEiR1B Dh1NMYGHcX6jkhNWsyErpsgr+dIyhfbG+j5nXawFyRonWpM47MOPgnVEwi6lvf9EOe kXM5diV6i+2h5b70JibgrnP2duNYG2oiqL0TXXgTa0BKcjqoIXS+WILX+2e1vj3H9f mnLaOOF8oF2VA== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:09 +0100 Subject: [PATCH RFC 11/34] xen: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-11-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=6117; i=brauner@kernel.org; h=from:subject:message-id; bh=JuWJr6+7i2yrkqNGwt5xMzLZMnlqBoh0zK4VKx+/xgY=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbSpPF9yTOnL0bPxU9g+M1+3/WWalemnkbll0XFum wS/yT1pHaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABPZps/I8KdRdv7Wh1FRz/bH b1W/VPXmU4NoG2v2NOdtZx+bF1eIJzAy7N1rHGVYeJXjl9uk306XDnNVhmy4IRJtOv3I47Vdzl9 7eQA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- drivers/block/xen-blkback/blkback.c | 4 ++-- drivers/block/xen-blkback/common.h | 4 ++-- drivers/block/xen-blkback/xenbus.c | 36 ++++++++++++++++++------------------ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c index 4defd7f387c7..752fd41c5ed9 100644 --- a/drivers/block/xen-blkback/blkback.c +++ b/drivers/block/xen-blkback/blkback.c @@ -465,7 +465,7 @@ static int xen_vbd_translate(struct phys_req *req, struct xen_blkif *blkif, } req->dev = vbd->pdevice; - req->bdev = vbd->bdev_handle->bdev; + req->bdev = F_BDEV(vbd->f_bdev); rc = 0; out: @@ -969,7 +969,7 @@ static int dispatch_discard_io(struct xen_blkif_ring *ring, int err = 0; int status = BLKIF_RSP_OKAY; struct xen_blkif *blkif = ring->blkif; - struct block_device *bdev = blkif->vbd.bdev_handle->bdev; + struct block_device *bdev = F_BDEV(blkif->vbd.f_bdev); struct phys_req preq; xen_blkif_get(blkif); diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h index 5ff50e76cee5..44070e38e5c2 100644 --- a/drivers/block/xen-blkback/common.h +++ b/drivers/block/xen-blkback/common.h @@ -221,7 +221,7 @@ struct xen_vbd { unsigned char type; /* phys device that this vbd maps to. */ u32 pdevice; - struct bdev_handle *bdev_handle; + struct file *f_bdev; /* Cached size parameter. */ sector_t size; unsigned int flush_support:1; @@ -360,7 +360,7 @@ struct pending_req { }; -#define vbd_sz(_v) bdev_nr_sectors((_v)->bdev_handle->bdev) +#define vbd_sz(_v) bdev_nr_sectors(F_BDEV((_v)->f_bdev)) #define xen_blkif_get(_b) (atomic_inc(&(_b)->refcnt)) #define xen_blkif_put(_b) \ diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c index e34219ea2b05..5386e123fada 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -81,7 +81,7 @@ static void xen_update_blkif_status(struct xen_blkif *blkif) int i; /* Not ready to connect? */ - if (!blkif->rings || !blkif->rings[0].irq || !blkif->vbd.bdev_handle) + if (!blkif->rings || !blkif->rings[0].irq || !blkif->vbd.f_bdev) return; /* Already connected? */ @@ -99,13 +99,13 @@ static void xen_update_blkif_status(struct xen_blkif *blkif) return; } - err = sync_blockdev(blkif->vbd.bdev_handle->bdev); + err = sync_blockdev(F_BDEV(blkif->vbd.f_bdev)); if (err) { xenbus_dev_error(blkif->be->dev, err, "block flush"); return; } invalidate_inode_pages2( - blkif->vbd.bdev_handle->bdev->bd_inode->i_mapping); + file_inode(blkif->vbd.f_bdev)->i_mapping); for (i = 0; i < blkif->nr_rings; i++) { ring = &blkif->rings[i]; @@ -473,9 +473,9 @@ static void xenvbd_sysfs_delif(struct xenbus_device *dev) static void xen_vbd_free(struct xen_vbd *vbd) { - if (vbd->bdev_handle) - bdev_release(vbd->bdev_handle); - vbd->bdev_handle = NULL; + if (vbd->f_bdev) + fput(vbd->f_bdev); + vbd->f_bdev = NULL; } static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, @@ -483,7 +483,7 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, int cdrom) { struct xen_vbd *vbd; - struct bdev_handle *bdev_handle; + struct file *f_bdev; vbd = &blkif->vbd; vbd->handle = handle; @@ -492,17 +492,17 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, vbd->pdevice = MKDEV(major, minor); - bdev_handle = bdev_open_by_dev(vbd->pdevice, vbd->readonly ? + f_bdev = bdev_file_open_by_dev(vbd->pdevice, vbd->readonly ? BLK_OPEN_READ : BLK_OPEN_WRITE, NULL, NULL); - if (IS_ERR(bdev_handle)) { + if (IS_ERR(f_bdev)) { pr_warn("xen_vbd_create: device %08x could not be opened\n", vbd->pdevice); return -ENOENT; } - vbd->bdev_handle = bdev_handle; - if (vbd->bdev_handle->bdev->bd_disk == NULL) { + vbd->f_bdev = f_bdev; + if (F_BDEV(vbd->f_bdev)->bd_disk == NULL) { pr_warn("xen_vbd_create: device %08x doesn't exist\n", vbd->pdevice); xen_vbd_free(vbd); @@ -510,14 +510,14 @@ static int xen_vbd_create(struct xen_blkif *blkif, blkif_vdev_t handle, } vbd->size = vbd_sz(vbd); - if (cdrom || disk_to_cdi(vbd->bdev_handle->bdev->bd_disk)) + if (cdrom || disk_to_cdi(F_BDEV(vbd->f_bdev)->bd_disk)) vbd->type |= VDISK_CDROM; - if (vbd->bdev_handle->bdev->bd_disk->flags & GENHD_FL_REMOVABLE) + if (F_BDEV(vbd->f_bdev)->bd_disk->flags & GENHD_FL_REMOVABLE) vbd->type |= VDISK_REMOVABLE; - if (bdev_write_cache(bdev_handle->bdev)) + if (bdev_write_cache(F_BDEV(f_bdev))) vbd->flush_support = true; - if (bdev_max_secure_erase_sectors(bdev_handle->bdev)) + if (bdev_max_secure_erase_sectors(F_BDEV(f_bdev))) vbd->discard_secure = true; pr_debug("Successful creation of handle=%04x (dom=%u)\n", @@ -570,7 +570,7 @@ static void xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info struct xen_blkif *blkif = be->blkif; int err; int state = 0; - struct block_device *bdev = be->blkif->vbd.bdev_handle->bdev; + struct block_device *bdev = F_BDEV(be->blkif->vbd.f_bdev); if (!xenbus_read_unsigned(dev->nodename, "discard-enable", 1)) return; @@ -932,7 +932,7 @@ static void connect(struct backend_info *be) } err = xenbus_printf(xbt, dev->nodename, "sector-size", "%lu", (unsigned long)bdev_logical_block_size( - be->blkif->vbd.bdev_handle->bdev)); + F_BDEV(be->blkif->vbd.f_bdev))); if (err) { xenbus_dev_fatal(dev, err, "writing %s/sector-size", dev->nodename); @@ -940,7 +940,7 @@ static void connect(struct backend_info *be) } err = xenbus_printf(xbt, dev->nodename, "physical-sector-size", "%u", bdev_physical_block_size( - be->blkif->vbd.bdev_handle->bdev)); + F_BDEV(be->blkif->vbd.f_bdev))); if (err) xenbus_dev_error(dev, err, "writing %s/physical-sector-size", dev->nodename); From patchwork Wed Jan 3 12:55:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13509999 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FB1319445; Wed, 3 Jan 2024 12:55:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="G556tMuT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11ECBC433CC; Wed, 3 Jan 2024 12:55:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286553; bh=/ll1XHivVArMWvaVV2mzYuNe9BlTI/z4SH3I5iJyfBk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=G556tMuT1fjUnUcycMLt+2boX9n6kgitrhgkyqhc42HrbsAbNN0+NmS9GAnqMx0hM JkCIGHGL59exrTQr5gQRAh2rztqRTF+A2WqLvjUtcq+NQcP11UsZOG7dYa3DAC0VhY 1G6vEEve9A84vTy/7EZha4v7AsFQNMemvFZ9MoDhMB/miVTtjrZSdPdrCnCHKSwHr7 5VhhNV7aV//Shz5aRr7ss0S1w9Qb9duNW3ThQhM8DMFivMNhxSfCsPi1RCn/vRL8yN Gu+aK3kVlLfT3+sWsdlO4ETs697Hm/tjU2VYrdYrTkyNvO+Jj3FboEFXjEhAPLwRS3 LszD3B8Lwt13A== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:10 +0100 Subject: [PATCH RFC 12/34] zram: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-12-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=3622; i=brauner@kernel.org; h=from:subject:message-id; bh=/ll1XHivVArMWvaVV2mzYuNe9BlTI/z4SH3I5iJyfBk=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbQJ8nn+IFLxkdWj7/zuNT7/ZzGsmLJ+WXlRU8Keb 96Vm2JYOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACYS94Hhf951y4XtJtEtK9da THXi2SOYEhJSIv9P4N7B08t1PyWv/MXw3zPhQGif6op1AdyCnWcV7wgUaD212D1txY72oMfObAe W8AEA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- drivers/block/zram/zram_drv.c | 26 +++++++++++++------------- drivers/block/zram/zram_drv.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index d77d3664ca08..7bf8360831b7 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -417,11 +417,11 @@ static void reset_bdev(struct zram *zram) if (!zram->backing_dev) return; - bdev_release(zram->bdev_handle); + fput(zram->f_bdev); /* hope filp_close flush all of IO */ filp_close(zram->backing_dev, NULL); zram->backing_dev = NULL; - zram->bdev_handle = NULL; + zram->f_bdev = NULL; zram->disk->fops = &zram_devops; kvfree(zram->bitmap); zram->bitmap = NULL; @@ -467,7 +467,7 @@ static ssize_t backing_dev_store(struct device *dev, struct address_space *mapping; unsigned int bitmap_sz; unsigned long nr_pages, *bitmap = NULL; - struct bdev_handle *bdev_handle = NULL; + struct file *f_bdev = NULL; int err; struct zram *zram = dev_to_zram(dev); @@ -504,11 +504,11 @@ static ssize_t backing_dev_store(struct device *dev, goto out; } - bdev_handle = bdev_open_by_dev(inode->i_rdev, + f_bdev = bdev_file_open_by_dev(inode->i_rdev, BLK_OPEN_READ | BLK_OPEN_WRITE, zram, NULL); - if (IS_ERR(bdev_handle)) { - err = PTR_ERR(bdev_handle); - bdev_handle = NULL; + if (IS_ERR(f_bdev)) { + err = PTR_ERR(f_bdev); + f_bdev = NULL; goto out; } @@ -522,7 +522,7 @@ static ssize_t backing_dev_store(struct device *dev, reset_bdev(zram); - zram->bdev_handle = bdev_handle; + zram->f_bdev = f_bdev; zram->backing_dev = backing_dev; zram->bitmap = bitmap; zram->nr_pages = nr_pages; @@ -535,8 +535,8 @@ static ssize_t backing_dev_store(struct device *dev, out: kvfree(bitmap); - if (bdev_handle) - bdev_release(bdev_handle); + if (f_bdev) + fput(f_bdev); if (backing_dev) filp_close(backing_dev, NULL); @@ -578,7 +578,7 @@ static void read_from_bdev_async(struct zram *zram, struct page *page, { struct bio *bio; - bio = bio_alloc(zram->bdev_handle->bdev, 1, parent->bi_opf, GFP_NOIO); + bio = bio_alloc(F_BDEV(zram->f_bdev), 1, parent->bi_opf, GFP_NOIO); bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9); __bio_add_page(bio, page, PAGE_SIZE, 0); bio_chain(bio, parent); @@ -694,7 +694,7 @@ static ssize_t writeback_store(struct device *dev, continue; } - bio_init(&bio, zram->bdev_handle->bdev, &bio_vec, 1, + bio_init(&bio, F_BDEV(zram->f_bdev), &bio_vec, 1, REQ_OP_WRITE | REQ_SYNC); bio.bi_iter.bi_sector = blk_idx * (PAGE_SIZE >> 9); __bio_add_page(&bio, page, PAGE_SIZE, 0); @@ -776,7 +776,7 @@ static void zram_sync_read(struct work_struct *work) struct bio_vec bv; struct bio bio; - bio_init(&bio, zw->zram->bdev_handle->bdev, &bv, 1, REQ_OP_READ); + bio_init(&bio, F_BDEV(zw->zram->f_bdev), &bv, 1, REQ_OP_READ); bio.bi_iter.bi_sector = zw->entry * (PAGE_SIZE >> 9); __bio_add_page(&bio, zw->page, PAGE_SIZE, 0); zw->error = submit_bio_wait(&bio); diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index d090753f97be..6d02e678483e 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -132,7 +132,7 @@ struct zram { spinlock_t wb_limit_lock; bool wb_limit_enable; u64 bd_wb_limit; - struct bdev_handle *bdev_handle; + struct file *f_bdev; unsigned long *bitmap; unsigned long nr_pages; #endif From patchwork Wed Jan 3 12:55:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510000 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F11FF19472; Wed, 3 Jan 2024 12:55:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SK5ru5pG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 228E1C433C7; Wed, 3 Jan 2024 12:55:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286555; bh=SB7+ux+/SnqsQ3wYEQi/h04VDB+2G1xzuBQj59RBeRI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SK5ru5pGhKN0Lf/Nisib+jfJcL61Ow8czGyaMmdvoxcrL8ZPLEIZzg5mqiiZ8YM8b N/7tO8Qyd0lJIWbm7K/Ou/aVxCG659OuKfy0PN84u7VpUsT3Sw6wjPgSC03SDFKGd1 hJYNGI/VIgksi6hPdBANs38HVqedVLnjoWD/Uum56yIt6Hn7/ggxaGi+6KvkRMJd8Y 4IMqDCNAXE2QzM8lbEj+WZk3kDDzfp9z7VT1i+5wI5U15gMvOCex36BTbVW37CmazH RM7jFZPtp7lb9ZUvGtHqOIsnVVNrdA8DhoGQgS0mf36uGJMH4JwPh02a270Lxysf6c eMr2stGZat24A== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:11 +0100 Subject: [PATCH RFC 13/34] bcache: port block device access to files Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-13-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=8318; i=brauner@kernel.org; h=from:subject:message-id; bh=SB7+ux+/SnqsQ3wYEQi/h04VDB+2G1xzuBQj59RBeRI=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbRpyZv+SiH2+kT1JydcG+c7Os9+8/5G/SwlP7EHe 25m/Ghc1VHKwiDGxSArpsji0G4SLrecp2KzUaYGzBxWJpAhDFycAjARBVaG/zl/n3uf+HPGq8lX WTyBY9Vrxm+7X0zwtq45Ic/ux5C+dQIjw4WSKOsff94lbrzouay/+FBHe9nWu9uD7sqVpSUdK85 pYwIA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- drivers/md/bcache/bcache.h | 4 +-- drivers/md/bcache/super.c | 74 +++++++++++++++++++++++----------------------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index 6ae2329052c9..f1579b0acd8d 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -300,7 +300,7 @@ struct cached_dev { struct list_head list; struct bcache_device disk; struct block_device *bdev; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct cache_sb sb; struct cache_sb_disk *sb_disk; @@ -423,7 +423,7 @@ struct cache { struct kobject kobj; struct block_device *bdev; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct task_struct *alloc_thread; diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 1402096b8076..8f7ed34ba1c8 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -1370,8 +1370,8 @@ static CLOSURE_CALLBACK(cached_dev_free) if (dc->sb_disk) put_page(virt_to_page(dc->sb_disk)); - if (dc->bdev_handle) - bdev_release(dc->bdev_handle); + if (dc->f_bdev) + fput(dc->f_bdev); wake_up(&unregister_wait); @@ -1446,7 +1446,7 @@ static int cached_dev_init(struct cached_dev *dc, unsigned int block_size) /* Cached device - bcache superblock */ static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk, - struct bdev_handle *bdev_handle, + struct file *f_bdev, struct cached_dev *dc) { const char *err = "cannot allocate memory"; @@ -1454,8 +1454,8 @@ static int register_bdev(struct cache_sb *sb, struct cache_sb_disk *sb_disk, int ret = -ENOMEM; memcpy(&dc->sb, sb, sizeof(struct cache_sb)); - dc->bdev_handle = bdev_handle; - dc->bdev = bdev_handle->bdev; + dc->f_bdev = f_bdev; + dc->bdev = F_BDEV(f_bdev); dc->sb_disk = sb_disk; if (cached_dev_init(dc, sb->block_size << 9)) @@ -2219,8 +2219,8 @@ void bch_cache_release(struct kobject *kobj) if (ca->sb_disk) put_page(virt_to_page(ca->sb_disk)); - if (ca->bdev_handle) - bdev_release(ca->bdev_handle); + if (ca->f_bdev) + fput(ca->f_bdev); kfree(ca); module_put(THIS_MODULE); @@ -2340,18 +2340,18 @@ static int cache_alloc(struct cache *ca) } static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk, - struct bdev_handle *bdev_handle, + struct file *f_bdev, struct cache *ca) { const char *err = NULL; /* must be set for any error case */ int ret = 0; memcpy(&ca->sb, sb, sizeof(struct cache_sb)); - ca->bdev_handle = bdev_handle; - ca->bdev = bdev_handle->bdev; + ca->f_bdev = f_bdev; + ca->bdev = F_BDEV(f_bdev); ca->sb_disk = sb_disk; - if (bdev_max_discard_sectors((bdev_handle->bdev))) + if (bdev_max_discard_sectors(F_BDEV(f_bdev))) ca->discard = CACHE_DISCARD(&ca->sb); ret = cache_alloc(ca); @@ -2362,20 +2362,20 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk, err = "cache_alloc(): cache device is too small"; else err = "cache_alloc(): unknown error"; - pr_notice("error %pg: %s\n", bdev_handle->bdev, err); + pr_notice("error %pg: %s\n", F_BDEV(f_bdev), err); /* * If we failed here, it means ca->kobj is not initialized yet, * kobject_put() won't be called and there is no chance to - * call bdev_release() to bdev in bch_cache_release(). So - * we explicitly call bdev_release() here. + * call fput() to bdev in bch_cache_release(). So + * we explicitly call fput() on the block device here. */ - bdev_release(bdev_handle); + fput(f_bdev); return ret; } - if (kobject_add(&ca->kobj, bdev_kobj(bdev_handle->bdev), "bcache")) { + if (kobject_add(&ca->kobj, bdev_kobj(F_BDEV(f_bdev)), "bcache")) { pr_notice("error %pg: error calling kobject_add\n", - bdev_handle->bdev); + F_BDEV(f_bdev)); ret = -ENOMEM; goto out; } @@ -2389,7 +2389,7 @@ static int register_cache(struct cache_sb *sb, struct cache_sb_disk *sb_disk, goto out; } - pr_info("registered cache device %pg\n", ca->bdev_handle->bdev); + pr_info("registered cache device %pg\n", F_BDEV(ca->f_bdev)); out: kobject_put(&ca->kobj); @@ -2447,7 +2447,7 @@ struct async_reg_args { char *path; struct cache_sb *sb; struct cache_sb_disk *sb_disk; - struct bdev_handle *bdev_handle; + struct file *f_bdev; void *holder; }; @@ -2458,7 +2458,7 @@ static void register_bdev_worker(struct work_struct *work) container_of(work, struct async_reg_args, reg_work.work); mutex_lock(&bch_register_lock); - if (register_bdev(args->sb, args->sb_disk, args->bdev_handle, + if (register_bdev(args->sb, args->sb_disk, args->f_bdev, args->holder) < 0) fail = true; mutex_unlock(&bch_register_lock); @@ -2479,7 +2479,7 @@ static void register_cache_worker(struct work_struct *work) container_of(work, struct async_reg_args, reg_work.work); /* blkdev_put() will be called in bch_cache_release() */ - if (register_cache(args->sb, args->sb_disk, args->bdev_handle, + if (register_cache(args->sb, args->sb_disk, args->f_bdev, args->holder)) fail = true; @@ -2517,7 +2517,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, char *path = NULL; struct cache_sb *sb; struct cache_sb_disk *sb_disk; - struct bdev_handle *bdev_handle, *bdev_handle2; + struct file *f_bdev, *f_bdev2; void *holder = NULL; ssize_t ret; bool async_registration = false; @@ -2550,15 +2550,15 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, ret = -EINVAL; err = "failed to open device"; - bdev_handle = bdev_open_by_path(strim(path), BLK_OPEN_READ, NULL, NULL); - if (IS_ERR(bdev_handle)) + f_bdev = bdev_file_open_by_path(strim(path), BLK_OPEN_READ, NULL, NULL); + if (IS_ERR(f_bdev)) goto out_free_sb; err = "failed to set blocksize"; - if (set_blocksize(bdev_handle->bdev, 4096)) + if (set_blocksize(F_BDEV(f_bdev), 4096)) goto out_blkdev_put; - err = read_super(sb, bdev_handle->bdev, &sb_disk); + err = read_super(sb, F_BDEV(f_bdev), &sb_disk); if (err) goto out_blkdev_put; @@ -2570,13 +2570,13 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, } /* Now reopen in exclusive mode with proper holder */ - bdev_handle2 = bdev_open_by_dev(bdev_handle->bdev->bd_dev, + f_bdev2 = bdev_file_open_by_dev(F_BDEV(f_bdev)->bd_dev, BLK_OPEN_READ | BLK_OPEN_WRITE, holder, NULL); - bdev_release(bdev_handle); - bdev_handle = bdev_handle2; - if (IS_ERR(bdev_handle)) { - ret = PTR_ERR(bdev_handle); - bdev_handle = NULL; + fput(f_bdev); + f_bdev = f_bdev2; + if (IS_ERR(f_bdev)) { + ret = PTR_ERR(f_bdev); + f_bdev = NULL; if (ret == -EBUSY) { dev_t dev; @@ -2611,7 +2611,7 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, args->path = path; args->sb = sb; args->sb_disk = sb_disk; - args->bdev_handle = bdev_handle; + args->f_bdev = f_bdev; args->holder = holder; register_device_async(args); /* No wait and returns to user space */ @@ -2620,14 +2620,14 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, if (SB_IS_BDEV(sb)) { mutex_lock(&bch_register_lock); - ret = register_bdev(sb, sb_disk, bdev_handle, holder); + ret = register_bdev(sb, sb_disk, f_bdev, holder); mutex_unlock(&bch_register_lock); /* blkdev_put() will be called in cached_dev_free() */ if (ret < 0) goto out_free_sb; } else { /* blkdev_put() will be called in bch_cache_release() */ - ret = register_cache(sb, sb_disk, bdev_handle, holder); + ret = register_cache(sb, sb_disk, f_bdev, holder); if (ret) goto out_free_sb; } @@ -2643,8 +2643,8 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr, out_put_sb_page: put_page(virt_to_page(sb_disk)); out_blkdev_put: - if (bdev_handle) - bdev_release(bdev_handle); + if (f_bdev) + fput(f_bdev); out_free_sb: kfree(sb); out_free_path: From patchwork Wed Jan 3 12:55:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510001 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A594199A1; Wed, 3 Jan 2024 12:55:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rfK1dCYa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45571C433CA; Wed, 3 Jan 2024 12:55:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286557; bh=kwAJtLc8apI/Uo1XL1vD3tPPin09CwI62esGwHw4y7g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rfK1dCYaX6Sla+BymY9Zw20WtndmhVWsUY9p7ezEGzEdxKI+a98FL4mkAw6cYWWj/ 9UsftS4SbQts7OW6eAhmeP7gOPTDggMgPERobVypi4D4Rj7N/9tB5TSCg7pcNDJV/J Kd/u6CJU8RG0rkLpc09kgGYOG6YBUwFmGzexdVWrGkMqufIu01DsOicR5F7kXzm8TX jVBjs5vDkQ4rya6Ho2sTF4kUMLVg2uc4AXnEzA1RLM423osOfqv7Y0S+0vS235lP2Z T7BNT4sXlXdFmb9fJlFcC3ZPL1eEgy38aCf0S5aRYxs+ipRJ1xW6EK3u3awdJv5XNd +QPMgpeA6j6TQ== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:12 +0100 Subject: [PATCH RFC 14/34] block2mtd: port device access to files Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-14-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=4922; i=brauner@kernel.org; h=from:subject:message-id; bh=kwAJtLc8apI/Uo1XL1vD3tPPin09CwI62esGwHw4y7g=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTJ3/Y3VEC25IPEn2O37JvSAvwai8Ujvj+ZXqaTW /uDv1C1o5SFQYyLQVZMkcWh3SRcbjlPxWajTA2YOaxMIEMYuDgF4CYHMPxTu5y29ua3ZO0ijtZH D++1890LCPP0uP/Ke9kheY+7m3KXMzIs8NJIiuBnKVJ89iru2avGA12J11XnT2tbFG5Y9OKFfR4 vAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- drivers/mtd/devices/block2mtd.c | 42 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c index aa44a23ec045..290e08afb8d0 100644 --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c @@ -37,7 +37,7 @@ /* Info for the block device */ struct block2mtd_dev { struct list_head list; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct mtd_info mtd; struct mutex write_mutex; }; @@ -56,7 +56,7 @@ static struct page *page_read(struct address_space *mapping, pgoff_t index) static int _block2mtd_erase(struct block2mtd_dev *dev, loff_t to, size_t len) { struct address_space *mapping = - dev->bdev_handle->bdev->bd_inode->i_mapping; + file_inode(dev->f_bdev)->i_mapping; struct page *page; pgoff_t index = to >> PAGE_SHIFT; // page index int pages = len >> PAGE_SHIFT; @@ -107,7 +107,7 @@ static int block2mtd_read(struct mtd_info *mtd, loff_t from, size_t len, { struct block2mtd_dev *dev = mtd->priv; struct address_space *mapping = - dev->bdev_handle->bdev->bd_inode->i_mapping; + file_inode(dev->f_bdev)->i_mapping; struct page *page; pgoff_t index = from >> PAGE_SHIFT; int offset = from & (PAGE_SIZE-1); @@ -143,7 +143,7 @@ static int _block2mtd_write(struct block2mtd_dev *dev, const u_char *buf, { struct page *page; struct address_space *mapping = - dev->bdev_handle->bdev->bd_inode->i_mapping; + file_inode(dev->f_bdev)->i_mapping; pgoff_t index = to >> PAGE_SHIFT; // page index int offset = to & ~PAGE_MASK; // page offset int cpylen; @@ -198,7 +198,7 @@ static int block2mtd_write(struct mtd_info *mtd, loff_t to, size_t len, static void block2mtd_sync(struct mtd_info *mtd) { struct block2mtd_dev *dev = mtd->priv; - sync_blockdev(dev->bdev_handle->bdev); + sync_blockdev(F_BDEV(dev->f_bdev)); return; } @@ -210,10 +210,10 @@ static void block2mtd_free_device(struct block2mtd_dev *dev) kfree(dev->mtd.name); - if (dev->bdev_handle) { + if (dev->f_bdev) { invalidate_mapping_pages( - dev->bdev_handle->bdev->bd_inode->i_mapping, 0, -1); - bdev_release(dev->bdev_handle); + file_inode(dev->f_bdev)->i_mapping, 0, -1); + fput(dev->f_bdev); } kfree(dev); @@ -223,10 +223,10 @@ static void block2mtd_free_device(struct block2mtd_dev *dev) * This function is marked __ref because it calls the __init marked * early_lookup_bdev when called from the early boot code. */ -static struct bdev_handle __ref *mdtblock_early_get_bdev(const char *devname, +static struct file __ref *mdtblock_early_get_bdev(const char *devname, blk_mode_t mode, int timeout, struct block2mtd_dev *dev) { - struct bdev_handle *bdev_handle = ERR_PTR(-ENODEV); + struct file *f_bdev = ERR_PTR(-ENODEV); #ifndef MODULE int i; @@ -234,7 +234,7 @@ static struct bdev_handle __ref *mdtblock_early_get_bdev(const char *devname, * We can't use early_lookup_bdev from a running system. */ if (system_state >= SYSTEM_RUNNING) - return bdev_handle; + return f_bdev; /* * We might not have the root device mounted at this point. @@ -253,20 +253,20 @@ static struct bdev_handle __ref *mdtblock_early_get_bdev(const char *devname, wait_for_device_probe(); if (!early_lookup_bdev(devname, &devt)) { - bdev_handle = bdev_open_by_dev(devt, mode, dev, NULL); - if (!IS_ERR(bdev_handle)) + f_bdev = bdev_file_open_by_dev(devt, mode, dev, NULL); + if (!IS_ERR(f_bdev)) break; } } #endif - return bdev_handle; + return f_bdev; } static struct block2mtd_dev *add_device(char *devname, int erase_size, char *label, int timeout) { const blk_mode_t mode = BLK_OPEN_READ | BLK_OPEN_WRITE; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct block_device *bdev; struct block2mtd_dev *dev; char *name; @@ -279,16 +279,16 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size, return NULL; /* Get a handle on the device */ - bdev_handle = bdev_open_by_path(devname, mode, dev, NULL); - if (IS_ERR(bdev_handle)) - bdev_handle = mdtblock_early_get_bdev(devname, mode, timeout, + f_bdev = bdev_file_open_by_path(devname, mode, dev, NULL); + if (IS_ERR(f_bdev)) + f_bdev = mdtblock_early_get_bdev(devname, mode, timeout, dev); - if (IS_ERR(bdev_handle)) { + if (IS_ERR(f_bdev)) { pr_err("error: cannot open device %s\n", devname); goto err_free_block2mtd; } - dev->bdev_handle = bdev_handle; - bdev = bdev_handle->bdev; + dev->f_bdev = f_bdev; + bdev = F_BDEV(f_bdev); if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) { pr_err("attempting to use an MTD device as a block device\n"); From patchwork Wed Jan 3 12:55:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510002 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 165BF199A2; Wed, 3 Jan 2024 12:56:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rIvASnEw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5886DC433C7; Wed, 3 Jan 2024 12:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286559; bh=qvHa0SQvBTTp9hnRUTS52VRn92SrlHZBR1JnfbI+qME=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rIvASnEw1d06Gju2+1iknAmts/pG5OURqXES7oXF0Owr5nodJQiAlz5vcMag2hHgf wv6q0p9xNRwfGGvwkDypCohVp/AIQ8POyXPJbNz1ZRPS7m2ry161dKVGcNl0yuTx1M SD616U9xSp4d4ISZlmkqvcMD3kgJNXs+qP4gnuu4EAs/GwQRPChWPZb0q/Ko7HewMn t2BRketaoPzzjZz9+stVa68nOw7wnZC12d5KhLh7c9sD9LvXELvwZGEZ2YA8sEW7IX iTEZ1aY+HTrrwptSdfttccdwkWULWNieeyJAorYYyJdABKsHZiqYksv8yzybWveEdR 9k+IksadzosTQ== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:13 +0100 Subject: [PATCH RFC 15/34] nvme: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-15-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=1947; i=brauner@kernel.org; h=from:subject:message-id; bh=qvHa0SQvBTTp9hnRUTS52VRn92SrlHZBR1JnfbI+qME=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbQJbHnrZfZzsfsVvWVxZ6rCeiaI8BQdfn+tLa9wy 8KYwtkxHaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABPRXc/wPzAmYnaGUCL/B2uL uFnfzzKk63dUfjuXW7+491Vj46/t0xj+x3zeu0cg/tQmkzPZoi4Nks6KvwqNz5nZJKvPrJp07V0 5PwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- drivers/nvme/target/io-cmd-bdev.c | 16 ++++++++-------- drivers/nvme/target/nvmet.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/nvme/target/io-cmd-bdev.c b/drivers/nvme/target/io-cmd-bdev.c index f11400a908f2..60dff841aa97 100644 --- a/drivers/nvme/target/io-cmd-bdev.c +++ b/drivers/nvme/target/io-cmd-bdev.c @@ -50,10 +50,10 @@ void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id) void nvmet_bdev_ns_disable(struct nvmet_ns *ns) { - if (ns->bdev_handle) { - bdev_release(ns->bdev_handle); + if (ns->f_bdev) { + fput(ns->f_bdev); ns->bdev = NULL; - ns->bdev_handle = NULL; + ns->f_bdev = NULL; } } @@ -85,18 +85,18 @@ int nvmet_bdev_ns_enable(struct nvmet_ns *ns) if (ns->buffered_io) return -ENOTBLK; - ns->bdev_handle = bdev_open_by_path(ns->device_path, + ns->f_bdev = bdev_file_open_by_path(ns->device_path, BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL); - if (IS_ERR(ns->bdev_handle)) { - ret = PTR_ERR(ns->bdev_handle); + if (IS_ERR(ns->f_bdev)) { + ret = PTR_ERR(ns->f_bdev); if (ret != -ENOTBLK) { pr_err("failed to open block device %s: (%d)\n", ns->device_path, ret); } - ns->bdev_handle = NULL; + ns->f_bdev = NULL; return ret; } - ns->bdev = ns->bdev_handle->bdev; + ns->bdev = F_BDEV(ns->f_bdev); ns->size = bdev_nr_bytes(ns->bdev); ns->blksize_shift = blksize_bits(bdev_logical_block_size(ns->bdev)); diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h index 6c8acebe1a1a..1d8a007e572d 100644 --- a/drivers/nvme/target/nvmet.h +++ b/drivers/nvme/target/nvmet.h @@ -58,7 +58,7 @@ struct nvmet_ns { struct percpu_ref ref; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct block_device *bdev; struct file *file; bool readonly; From patchwork Wed Jan 3 12:55:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510003 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C65A61A71A; Wed, 3 Jan 2024 12:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FRv1KCYE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EB6AC433C8; Wed, 3 Jan 2024 12:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286562; bh=QlHJ9MNHMXpTsM70DGdZLedAO8BPnf7wsRiAtwSFLCI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FRv1KCYEt9z5x+77pK/EtbdPkewFeuRYgE1QFrDznku1v35VpOMVJSaykSjvyBKwy lzxPZ8rAg6quW3ZpDOTi1y1EzymzsCZyI+qKPVXEDAGKcy26PA/dxPxtZRGUkDRNj5 yxzpMTIgKT34LmLzMX6uDUKnaQjXU73lcMrXvNpX2tvL216cWH0TVzOSrn8OWUDc9S 8skZCFUrxxoib3Om+2m3bc0FH1kuwfkfRSPacqq0VqGUXb8vMhsYi7nLZT4a3M+e/a WcRHVJg8wFJ+8ieyLR5B+Mx84thhBphjCdyXt0Dx/QZH7AY3KiiE+xPrtBh5X54+Ut sBJzcFHr7/57Q== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:14 +0100 Subject: [PATCH RFC 16/34] s390: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-16-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=5814; i=brauner@kernel.org; h=from:subject:message-id; bh=QlHJ9MNHMXpTsM70DGdZLedAO8BPnf7wsRiAtwSFLCI=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTR6/+2/OyNM7MW93qoHH7UPHvbCvlXJ9+aLHtle P1v45GZHztKWRjEuBhkxRRZHNpNwuWW81RsNsrUgJnDygQyhIGLUwAmYn+HkeF+5c05Pw8oLBNX fct+bvLR0A/GTzt4vjDJSHJOOLvi0r4fDP+d+hiONr49cvnWmjvKcyynRF84/+dt5c5p+RYb5wh 9usfMCgA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- drivers/s390/block/dasd.c | 10 +++++----- drivers/s390/block/dasd_genhd.c | 36 ++++++++++++++++++------------------ drivers/s390/block/dasd_int.h | 2 +- drivers/s390/block/dasd_ioctl.c | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c index 833cfab7d877..e462dcad84b1 100644 --- a/drivers/s390/block/dasd.c +++ b/drivers/s390/block/dasd.c @@ -412,7 +412,7 @@ dasd_state_ready_to_online(struct dasd_device * device) KOBJ_CHANGE); return 0; } - disk_uevent(device->block->bdev_handle->bdev->bd_disk, + disk_uevent(F_BDEV(device->block->f_bdev)->bd_disk, KOBJ_CHANGE); } return 0; @@ -433,7 +433,7 @@ static int dasd_state_online_to_ready(struct dasd_device *device) device->state = DASD_STATE_READY; if (device->block && !(device->features & DASD_FEATURE_USERAW)) - disk_uevent(device->block->bdev_handle->bdev->bd_disk, + disk_uevent(F_BDEV(device->block->f_bdev)->bd_disk, KOBJ_CHANGE); return 0; } @@ -3594,7 +3594,7 @@ int dasd_generic_set_offline(struct ccw_device *cdev) * in the other openers. */ if (device->block) { - max_count = device->block->bdev_handle ? 0 : -1; + max_count = device->block->f_bdev ? 0 : -1; open_count = atomic_read(&device->block->open_count); if (open_count > max_count) { if (open_count > 0) @@ -3640,8 +3640,8 @@ int dasd_generic_set_offline(struct ccw_device *cdev) * so sync bdev first and then wait for our queues to become * empty */ - if (device->block && device->block->bdev_handle) - bdev_mark_dead(device->block->bdev_handle->bdev, false); + if (device->block && device->block->f_bdev) + bdev_mark_dead(F_BDEV(device->block->f_bdev), false); dasd_schedule_device_bh(device); rc = wait_event_interruptible(shutdown_waitq, _wait_for_empty_queues(device)); diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c index 55e3abe94cde..4c389b7416f8 100644 --- a/drivers/s390/block/dasd_genhd.c +++ b/drivers/s390/block/dasd_genhd.c @@ -127,15 +127,15 @@ void dasd_gendisk_free(struct dasd_block *block) */ int dasd_scan_partitions(struct dasd_block *block) { - struct bdev_handle *bdev_handle; + struct file *f_bdev; int rc; - bdev_handle = bdev_open_by_dev(disk_devt(block->gdp), BLK_OPEN_READ, + f_bdev = bdev_file_open_by_dev(disk_devt(block->gdp), BLK_OPEN_READ, NULL, NULL); - if (IS_ERR(bdev_handle)) { + if (IS_ERR(f_bdev)) { DBF_DEV_EVENT(DBF_ERR, block->base, "scan partitions error, blkdev_get returned %ld", - PTR_ERR(bdev_handle)); + PTR_ERR(f_bdev)); return -ENODEV; } @@ -147,15 +147,15 @@ int dasd_scan_partitions(struct dasd_block *block) "scan partitions error, rc %d", rc); /* - * Since the matching bdev_release() call to the - * bdev_open_by_path() in this function is not called before + * Since the matching fput() call to the + * bdev_file_open_by_path() in this function is not called before * dasd_destroy_partitions the offline open_count limit needs to be - * increased from 0 to 1. This is done by setting device->bdev_handle + * increased from 0 to 1. This is done by setting device->f_bdev * (see dasd_generic_set_offline). As long as the partition detection * is running no offline should be allowed. That is why the assignment - * to block->bdev_handle is done AFTER the BLKRRPART ioctl. + * to block->f_bdev is done AFTER the BLKRRPART ioctl. */ - block->bdev_handle = bdev_handle; + block->f_bdev = f_bdev; return 0; } @@ -165,21 +165,21 @@ int dasd_scan_partitions(struct dasd_block *block) */ void dasd_destroy_partitions(struct dasd_block *block) { - struct bdev_handle *bdev_handle; + struct file *f_bdev; /* - * Get the bdev_handle pointer from the device structure and clear - * device->bdev_handle to lower the offline open_count limit again. + * Get the f_bdev pointer from the device structure and clear + * device->f_bdev to lower the offline open_count limit again. */ - bdev_handle = block->bdev_handle; - block->bdev_handle = NULL; + f_bdev = block->f_bdev; + block->f_bdev = NULL; - mutex_lock(&bdev_handle->bdev->bd_disk->open_mutex); - bdev_disk_changed(bdev_handle->bdev->bd_disk, true); - mutex_unlock(&bdev_handle->bdev->bd_disk->open_mutex); + mutex_lock(&F_BDEV(f_bdev)->bd_disk->open_mutex); + bdev_disk_changed(F_BDEV(f_bdev)->bd_disk, true); + mutex_unlock(&F_BDEV(f_bdev)->bd_disk->open_mutex); /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */ - bdev_release(bdev_handle); + fput(f_bdev); } int dasd_gendisk_init(void) diff --git a/drivers/s390/block/dasd_int.h b/drivers/s390/block/dasd_int.h index 1b1b8a41c4d4..a2c16434d89f 100644 --- a/drivers/s390/block/dasd_int.h +++ b/drivers/s390/block/dasd_int.h @@ -650,7 +650,7 @@ struct dasd_block { struct gendisk *gdp; spinlock_t request_queue_lock; struct blk_mq_tag_set tag_set; - struct bdev_handle *bdev_handle; + struct file *f_bdev; atomic_t open_count; unsigned long blocks; /* size of volume in blocks */ diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c index 61b9675e2a67..c73419a09bbd 100644 --- a/drivers/s390/block/dasd_ioctl.c +++ b/drivers/s390/block/dasd_ioctl.c @@ -537,7 +537,7 @@ static int __dasd_ioctl_information(struct dasd_block *block, * This must be hidden from user-space. */ dasd_info->open_count = atomic_read(&block->open_count); - if (!block->bdev_handle) + if (!block->f_bdev) dasd_info->open_count++; /* From patchwork Wed Jan 3 12:55:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510004 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 777651A72B; Wed, 3 Jan 2024 12:56:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="triuUe03" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE5CEC433C9; Wed, 3 Jan 2024 12:56:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286564; bh=xoHXT+wi01B2qt/2QyF+kX91Rlyli//ZnLVNdODMNk0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=triuUe03rOkQXGCwJK+UFtbc7uR86ltVsd/DFTL2V4bjQybzP0zK7NZX5na0URvCy z0sGgDDpPJvdS6TCR7j6/6S9NUBDVK1HUePUP0gVjapLJO1LF8V4t2XD91Asd5aeZs 0cBeWIMGNMgpahmFnQjIbQIE6ZXHhHzougkAPwoht6T3kbiDwfQPgtTxEPuSGbm4N6 g3mFWA0QWmoB64e2vGLDvaZV6KZYwf7KoYI4Y6oPJJ52ak9Ts9GlUBBhF38KorQlTS fOnhUbkZQqzfTYP3dAyN+IeUvyFhJfDNcUusQbDuc90EAiyLfkPSv/u7stC+cOFJ4x qCQJEpRz4l5Qw== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:15 +0100 Subject: [PATCH RFC 17/34] target: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-17-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=5156; i=brauner@kernel.org; h=from:subject:message-id; bh=xoHXT+wi01B2qt/2QyF+kX91Rlyli//ZnLVNdODMNk0=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbSZGrI7t7/1yGn+qQsLvsu6XvkR/+l9Q/2OAv+/y 8/HXf92v6OUhUGMi0FWTJHFod0kXG45T8Vmo0wNmDmsTCBDGLg4BWAicp2MDHcfmTDHG7cd/Vy+ 5vxh5Qe127rYWXae23Foo+X29fs7fM8w/FNpuKt85dh8Tiv2kkSpxctOsDTKqPKovjj93vRTLvd zLQYA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- drivers/target/target_core_iblock.c | 18 +++++++++--------- drivers/target/target_core_iblock.h | 2 +- drivers/target/target_core_pscsi.c | 22 +++++++++++----------- drivers/target/target_core_pscsi.h | 2 +- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c index 8eb9eb7ce5df..79e79ec06856 100644 --- a/drivers/target/target_core_iblock.c +++ b/drivers/target/target_core_iblock.c @@ -91,7 +91,7 @@ static int iblock_configure_device(struct se_device *dev) { struct iblock_dev *ib_dev = IBLOCK_DEV(dev); struct request_queue *q; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct block_device *bd; struct blk_integrity *bi; blk_mode_t mode = BLK_OPEN_READ; @@ -117,14 +117,14 @@ static int iblock_configure_device(struct se_device *dev) else dev->dev_flags |= DF_READ_ONLY; - bdev_handle = bdev_open_by_path(ib_dev->ibd_udev_path, mode, ib_dev, + f_bdev = bdev_file_open_by_path(ib_dev->ibd_udev_path, mode, ib_dev, NULL); - if (IS_ERR(bdev_handle)) { - ret = PTR_ERR(bdev_handle); + if (IS_ERR(f_bdev)) { + ret = PTR_ERR(f_bdev); goto out_free_bioset; } - ib_dev->ibd_bdev_handle = bdev_handle; - ib_dev->ibd_bd = bd = bdev_handle->bdev; + ib_dev->ibd_f_bdev = f_bdev; + ib_dev->ibd_bd = bd = F_BDEV(f_bdev); q = bdev_get_queue(bd); @@ -180,7 +180,7 @@ static int iblock_configure_device(struct se_device *dev) return 0; out_blkdev_put: - bdev_release(ib_dev->ibd_bdev_handle); + fput(ib_dev->ibd_f_bdev); out_free_bioset: bioset_exit(&ib_dev->ibd_bio_set); out: @@ -205,8 +205,8 @@ static void iblock_destroy_device(struct se_device *dev) { struct iblock_dev *ib_dev = IBLOCK_DEV(dev); - if (ib_dev->ibd_bdev_handle) - bdev_release(ib_dev->ibd_bdev_handle); + if (ib_dev->ibd_f_bdev) + fput(ib_dev->ibd_f_bdev); bioset_exit(&ib_dev->ibd_bio_set); } diff --git a/drivers/target/target_core_iblock.h b/drivers/target/target_core_iblock.h index 683f9a55945b..769b6b7731a9 100644 --- a/drivers/target/target_core_iblock.h +++ b/drivers/target/target_core_iblock.h @@ -32,7 +32,7 @@ struct iblock_dev { u32 ibd_flags; struct bio_set ibd_bio_set; struct block_device *ibd_bd; - struct bdev_handle *ibd_bdev_handle; + struct file *ibd_f_bdev; bool ibd_readonly; struct iblock_dev_plug *ibd_plug; } ____cacheline_aligned; diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c index 41b7489d37ce..9f7e423ed11b 100644 --- a/drivers/target/target_core_pscsi.c +++ b/drivers/target/target_core_pscsi.c @@ -352,7 +352,7 @@ static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd) struct pscsi_hba_virt *phv = dev->se_hba->hba_ptr; struct pscsi_dev_virt *pdv = PSCSI_DEV(dev); struct Scsi_Host *sh = sd->host; - struct bdev_handle *bdev_handle; + struct file *f_bdev; int ret; if (scsi_device_get(sd)) { @@ -366,18 +366,18 @@ static int pscsi_create_type_disk(struct se_device *dev, struct scsi_device *sd) * Claim exclusive struct block_device access to struct scsi_device * for TYPE_DISK and TYPE_ZBC using supplied udev_path */ - bdev_handle = bdev_open_by_path(dev->udev_path, + f_bdev = bdev_file_open_by_path(dev->udev_path, BLK_OPEN_WRITE | BLK_OPEN_READ, pdv, NULL); - if (IS_ERR(bdev_handle)) { + if (IS_ERR(f_bdev)) { pr_err("pSCSI: bdev_open_by_path() failed\n"); scsi_device_put(sd); - return PTR_ERR(bdev_handle); + return PTR_ERR(f_bdev); } - pdv->pdv_bdev_handle = bdev_handle; + pdv->pdv_f_bdev = f_bdev; ret = pscsi_add_device_to_list(dev, sd); if (ret) { - bdev_release(bdev_handle); + fput(f_bdev); scsi_device_put(sd); return ret; } @@ -564,9 +564,9 @@ static void pscsi_destroy_device(struct se_device *dev) * from pscsi_create_type_disk() */ if ((sd->type == TYPE_DISK || sd->type == TYPE_ZBC) && - pdv->pdv_bdev_handle) { - bdev_release(pdv->pdv_bdev_handle); - pdv->pdv_bdev_handle = NULL; + pdv->pdv_f_bdev) { + fput(pdv->pdv_f_bdev); + pdv->pdv_f_bdev = NULL; } /* * For HBA mode PHV_LLD_SCSI_HOST_NO, release the reference @@ -994,8 +994,8 @@ static sector_t pscsi_get_blocks(struct se_device *dev) { struct pscsi_dev_virt *pdv = PSCSI_DEV(dev); - if (pdv->pdv_bdev_handle) - return bdev_nr_sectors(pdv->pdv_bdev_handle->bdev); + if (pdv->pdv_f_bdev) + return bdev_nr_sectors(F_BDEV(pdv->pdv_f_bdev)); return 0; } diff --git a/drivers/target/target_core_pscsi.h b/drivers/target/target_core_pscsi.h index b0a3ef136592..8cdbe3f32262 100644 --- a/drivers/target/target_core_pscsi.h +++ b/drivers/target/target_core_pscsi.h @@ -37,7 +37,7 @@ struct pscsi_dev_virt { int pdv_channel_id; int pdv_target_id; int pdv_lun_id; - struct bdev_handle *pdv_bdev_handle; + struct file *pdv_f_bdev; struct scsi_device *pdv_sd; struct Scsi_Host *pdv_lld_host; } ____cacheline_aligned; From patchwork Wed Jan 3 12:55:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510005 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9926D1A733; Wed, 3 Jan 2024 12:56:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lcPK9l93" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6D3CC433C7; Wed, 3 Jan 2024 12:56:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286566; bh=DGMPHqDOdVU2hPlZg/YQJTJ2I0ikPmmqIEvDLQ0peHM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lcPK9l93kSioco0uhOyzlB65SqNqbhu1/BM+NjC9ojDE3rLskpVRvuvQ9IEDpnnct rjFhHepApsZeov1dxct/jAnh3bJ87Auldmsw2An5lI+Z52Yuy9/lIEU/Wje20q0mcx SuGWc8HX/gdzclWQ+/kDcTkt24UmdllUQIbkZDxTKKorMah/xYpPlWIZTcw45Z6M8U DUjrUNmowRmAbBydnkF+xiN8e9+qdaCSIBt1XXD02k247I+l3ztZJKdP0SUS1C5r/U k8dzK7in6IrapH6jlDRxqQYIKx3pTKoiM2RqPq56svpS04M2Op2ndzBui8rNwrSMJp FalPAA/z6TNxg== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:16 +0100 Subject: [PATCH RFC 18/34] bcachefs: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-18-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=2240; i=brauner@kernel.org; h=from:subject:message-id; bh=DGMPHqDOdVU2hPlZg/YQJTJ2I0ikPmmqIEvDLQ0peHM=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbR5ych+dF94wtXlP8OmHmZufPpxzU5rwYmWTOI1I Vu+a2od6ChlYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZjISy1Ghp2rL6oKrkzZOnEB k0e7//7Mldyzl51pun1rU+CXTadPFCYwMqw32qRaep7pxxeOFzeEv26fqqN7bm676w1WvX4/B60 jx7gB X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- fs/bcachefs/super-io.c | 20 ++++++++++---------- fs/bcachefs/super_types.h | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c index 801590bbc68c..927b977dfbda 100644 --- a/fs/bcachefs/super-io.c +++ b/fs/bcachefs/super-io.c @@ -163,8 +163,8 @@ void bch2_sb_field_delete(struct bch_sb_handle *sb, void bch2_free_super(struct bch_sb_handle *sb) { kfree(sb->bio); - if (!IS_ERR_OR_NULL(sb->bdev_handle)) - bdev_release(sb->bdev_handle); + if (!IS_ERR_OR_NULL(sb->s_f_bdev)) + fput(sb->s_f_bdev); kfree(sb->holder); kfree(sb->sb_name); @@ -691,22 +691,22 @@ int bch2_read_super(const char *path, struct bch_opts *opts, if (!opt_get(*opts, nochanges)) sb->mode |= BLK_OPEN_WRITE; - sb->bdev_handle = bdev_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops); - if (IS_ERR(sb->bdev_handle) && - PTR_ERR(sb->bdev_handle) == -EACCES && + sb->s_f_bdev = bdev_file_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops); + if (IS_ERR(sb->s_f_bdev) && + PTR_ERR(sb->s_f_bdev) == -EACCES && opt_get(*opts, read_only)) { sb->mode &= ~BLK_OPEN_WRITE; - sb->bdev_handle = bdev_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops); - if (!IS_ERR(sb->bdev_handle)) + sb->s_f_bdev = bdev_file_open_by_path(path, sb->mode, sb->holder, &bch2_sb_handle_bdev_ops); + if (!IS_ERR(sb->s_f_bdev)) opt_set(*opts, nochanges, true); } - if (IS_ERR(sb->bdev_handle)) { - ret = PTR_ERR(sb->bdev_handle); + if (IS_ERR(sb->s_f_bdev)) { + ret = PTR_ERR(sb->s_f_bdev); goto out; } - sb->bdev = sb->bdev_handle->bdev; + sb->bdev = F_BDEV(sb->s_f_bdev); ret = bch2_sb_realloc(sb, 0); if (ret) { diff --git a/fs/bcachefs/super_types.h b/fs/bcachefs/super_types.h index b2119686e2e1..e98df6428d38 100644 --- a/fs/bcachefs/super_types.h +++ b/fs/bcachefs/super_types.h @@ -4,7 +4,7 @@ struct bch_sb_handle { struct bch_sb *sb; - struct bdev_handle *bdev_handle; + struct file *s_f_bdev; struct block_device *bdev; char *sb_name; struct bio *bio; From patchwork Wed Jan 3 12:55:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510006 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1052C1B274; Wed, 3 Jan 2024 12:56:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VpbyKaKz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E73E2C433C8; Wed, 3 Jan 2024 12:56:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286568; bh=0scOEoK8nI/0sgEwQ10FnDv3pe9VS6iqwfSWS4IvgXI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VpbyKaKzx3UZa5/9KMBL/QSaSl9mhLoNQ9/UmOiMKj699yZsEYVBk1k3o8wWmua03 6sFy4QSTkOqqPGxyvbG8OyOBMrJEli6LWXpupoouHt6NBUE1iCvs5LcwtEetuXX6xB 5jPN+p6+u/KcislYOFNT611vay2sJiOVml10H0/S0RnRD9f0mgppxJrJrRjQmYbBUC gXyHrLAoymDDy1AJCXOIQ21JBO3vGGs3b5Uj4iyZGlw0Q8dRzSiXli/Th0oSU0ad5Y uLHlbJc235tXGHRsDYxZAFqDMNgGqVaHA0vZcXFRuPzaQ8F7ZT6GeZM9R7k5gGXNkM NlxIFe90Y8vOw== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:17 +0100 Subject: [PATCH RFC 19/34] btrfs: port device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-19-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=14776; i=brauner@kernel.org; h=from:subject:message-id; bh=0scOEoK8nI/0sgEwQ10FnDv3pe9VS6iqwfSWS4IvgXI=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbR9OXX+se4q+ecz91XIHvpss6bJMK0t+cPOq7MqJ /bmvkmW7ihlYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZiIxCyG/6W3982QvPLBpOSB yOIb4qJlsVWWH+z1W0Kl+353yqRN2sTwz7Rvzsc1JgaiIa/EdE0ONC+d5XjaZnp2QcT0dQ6bout q+AE= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- fs/btrfs/dev-replace.c | 14 ++++---- fs/btrfs/ioctl.c | 16 ++++----- fs/btrfs/volumes.c | 92 +++++++++++++++++++++++++------------------------- fs/btrfs/volumes.h | 4 +-- 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index f9544fda38e9..74d171f91369 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -246,7 +246,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, { struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; struct btrfs_device *device; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct block_device *bdev; u64 devid = BTRFS_DEV_REPLACE_DEVID; int ret = 0; @@ -257,13 +257,13 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, return -EINVAL; } - bdev_handle = bdev_open_by_path(device_path, BLK_OPEN_WRITE, + f_bdev = bdev_file_open_by_path(device_path, BLK_OPEN_WRITE, fs_info->bdev_holder, NULL); - if (IS_ERR(bdev_handle)) { + if (IS_ERR(f_bdev)) { btrfs_err(fs_info, "target device %s is invalid!", device_path); - return PTR_ERR(bdev_handle); + return PTR_ERR(f_bdev); } - bdev = bdev_handle->bdev; + bdev = F_BDEV(f_bdev); if (!btrfs_check_device_zone_type(fs_info, bdev)) { btrfs_err(fs_info, @@ -314,7 +314,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, device->commit_bytes_used = device->bytes_used; device->fs_info = fs_info; device->bdev = bdev; - device->bdev_handle = bdev_handle; + device->f_bdev = f_bdev; set_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state); set_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state); device->dev_stats_valid = 1; @@ -335,7 +335,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, return 0; error: - bdev_release(bdev_handle); + fput(f_bdev); return ret; } diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 41b479861b3c..2bd9e137661a 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2691,7 +2691,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg) struct inode *inode = file_inode(file); struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_ioctl_vol_args_v2 *vol_args; - struct bdev_handle *bdev_handle = NULL; + struct file *f_bdev = NULL; int ret; bool cancel = false; @@ -2728,7 +2728,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg) goto err_drop; /* Exclusive operation is now claimed */ - ret = btrfs_rm_device(fs_info, &args, &bdev_handle); + ret = btrfs_rm_device(fs_info, &args, &f_bdev); btrfs_exclop_finish(fs_info); @@ -2742,8 +2742,8 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg) } err_drop: mnt_drop_write_file(file); - if (bdev_handle) - bdev_release(bdev_handle); + if (f_bdev) + fput(f_bdev); out: btrfs_put_dev_args_from_path(&args); kfree(vol_args); @@ -2756,7 +2756,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg) struct inode *inode = file_inode(file); struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_ioctl_vol_args *vol_args; - struct bdev_handle *bdev_handle = NULL; + struct file *f_bdev = NULL; int ret; bool cancel = false; @@ -2783,15 +2783,15 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg) ret = exclop_start_or_cancel_reloc(fs_info, BTRFS_EXCLOP_DEV_REMOVE, cancel); if (ret == 0) { - ret = btrfs_rm_device(fs_info, &args, &bdev_handle); + ret = btrfs_rm_device(fs_info, &args, &f_bdev); if (!ret) btrfs_info(fs_info, "disk deleted %s", vol_args->name); btrfs_exclop_finish(fs_info); } mnt_drop_write_file(file); - if (bdev_handle) - bdev_release(bdev_handle); + if (f_bdev) + fput(f_bdev); out: btrfs_put_dev_args_from_path(&args); kfree(vol_args); diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index f627674b37db..0295731d0b76 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -457,39 +457,39 @@ static noinline struct btrfs_fs_devices *find_fsid( static int btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder, - int flush, struct bdev_handle **bdev_handle, + int flush, struct file **f_bdev, struct btrfs_super_block **disk_super) { struct block_device *bdev; int ret; - *bdev_handle = bdev_open_by_path(device_path, flags, holder, NULL); + *f_bdev = bdev_file_open_by_path(device_path, flags, holder, NULL); - if (IS_ERR(*bdev_handle)) { - ret = PTR_ERR(*bdev_handle); + if (IS_ERR(*f_bdev)) { + ret = PTR_ERR(*f_bdev); goto error; } - bdev = (*bdev_handle)->bdev; + bdev = F_BDEV(*f_bdev); if (flush) sync_blockdev(bdev); ret = set_blocksize(bdev, BTRFS_BDEV_BLOCKSIZE); if (ret) { - bdev_release(*bdev_handle); + fput(*f_bdev); goto error; } invalidate_bdev(bdev); *disk_super = btrfs_read_dev_super(bdev); if (IS_ERR(*disk_super)) { ret = PTR_ERR(*disk_super); - bdev_release(*bdev_handle); + fput(*f_bdev); goto error; } return 0; error: - *bdev_handle = NULL; + *f_bdev = NULL; return ret; } @@ -632,7 +632,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, struct btrfs_device *device, blk_mode_t flags, void *holder) { - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct btrfs_super_block *disk_super; u64 devid; int ret; @@ -643,7 +643,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, return -EINVAL; ret = btrfs_get_bdev_and_sb(device->name->str, flags, holder, 1, - &bdev_handle, &disk_super); + &f_bdev, &disk_super); if (ret) return ret; @@ -667,20 +667,20 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state); fs_devices->seeding = true; } else { - if (bdev_read_only(bdev_handle->bdev)) + if (bdev_read_only(F_BDEV(f_bdev))) clear_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state); else set_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state); } - if (!bdev_nonrot(bdev_handle->bdev)) + if (!bdev_nonrot(F_BDEV(f_bdev))) fs_devices->rotating = true; - if (bdev_max_discard_sectors(bdev_handle->bdev)) + if (bdev_max_discard_sectors(F_BDEV(f_bdev))) fs_devices->discardable = true; - device->bdev_handle = bdev_handle; - device->bdev = bdev_handle->bdev; + device->f_bdev = f_bdev; + device->bdev = F_BDEV(f_bdev); clear_bit(BTRFS_DEV_STATE_IN_FS_METADATA, &device->dev_state); fs_devices->open_devices++; @@ -695,7 +695,7 @@ static int btrfs_open_one_device(struct btrfs_fs_devices *fs_devices, error_free_page: btrfs_release_disk_super(disk_super); - bdev_release(bdev_handle); + fput(f_bdev); return -EINVAL; } @@ -1004,10 +1004,10 @@ static void __btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, if (device->devid == BTRFS_DEV_REPLACE_DEVID) continue; - if (device->bdev_handle) { - bdev_release(device->bdev_handle); + if (device->f_bdev) { + fput(device->f_bdev); device->bdev = NULL; - device->bdev_handle = NULL; + device->f_bdev = NULL; fs_devices->open_devices--; } if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) { @@ -1052,7 +1052,7 @@ static void btrfs_close_bdev(struct btrfs_device *device) invalidate_bdev(device->bdev); } - bdev_release(device->bdev_handle); + fput(device->f_bdev); } static void btrfs_close_one_device(struct btrfs_device *device) @@ -1305,7 +1305,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, struct btrfs_super_block *disk_super; bool new_device_added = false; struct btrfs_device *device = NULL; - struct bdev_handle *bdev_handle; + struct file *f_bdev; u64 bytenr, bytenr_orig; int ret; @@ -1328,18 +1328,18 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, * values temporarily, as the device paths of the fsid are the only * required information for assembling the volume. */ - bdev_handle = bdev_open_by_path(path, flags, NULL, NULL); - if (IS_ERR(bdev_handle)) - return ERR_CAST(bdev_handle); + f_bdev = bdev_file_open_by_path(path, flags, NULL, NULL); + if (IS_ERR(f_bdev)) + return ERR_CAST(f_bdev); bytenr_orig = btrfs_sb_offset(0); - ret = btrfs_sb_log_location_bdev(bdev_handle->bdev, 0, READ, &bytenr); + ret = btrfs_sb_log_location_bdev(F_BDEV(f_bdev), 0, READ, &bytenr); if (ret) { device = ERR_PTR(ret); goto error_bdev_put; } - disk_super = btrfs_read_disk_super(bdev_handle->bdev, bytenr, + disk_super = btrfs_read_disk_super(F_BDEV(f_bdev), bytenr, bytenr_orig); if (IS_ERR(disk_super)) { device = ERR_CAST(disk_super); @@ -1370,7 +1370,7 @@ struct btrfs_device *btrfs_scan_one_device(const char *path, blk_mode_t flags, btrfs_release_disk_super(disk_super); error_bdev_put: - bdev_release(bdev_handle); + fput(f_bdev); return device; } @@ -2047,7 +2047,7 @@ void btrfs_scratch_superblocks(struct btrfs_fs_info *fs_info, int btrfs_rm_device(struct btrfs_fs_info *fs_info, struct btrfs_dev_lookup_args *args, - struct bdev_handle **bdev_handle) + struct file **f_bdev) { struct btrfs_trans_handle *trans; struct btrfs_device *device; @@ -2156,7 +2156,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, btrfs_assign_next_active_device(device, NULL); - if (device->bdev_handle) { + if (device->f_bdev) { cur_devices->open_devices--; /* remove sysfs entry */ btrfs_sysfs_remove_device(device); @@ -2172,9 +2172,9 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, * free the device. * * We cannot call btrfs_close_bdev() here because we're holding the sb - * write lock, and bdev_release() will pull in the ->open_mutex on - * the block device and it's dependencies. Instead just flush the - * device and let the caller do the final bdev_release. + * write lock, and fput() on the block device will pull in the + * ->open_mutex on the block device and it's dependencies. Instead + * just flush the device and let the caller do the final bdev_release. */ if (test_bit(BTRFS_DEV_STATE_WRITEABLE, &device->dev_state)) { btrfs_scratch_superblocks(fs_info, device->bdev, @@ -2185,7 +2185,7 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, } } - *bdev_handle = device->bdev_handle; + *f_bdev = device->f_bdev; synchronize_rcu(); btrfs_free_device(device); @@ -2322,7 +2322,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info, const char *path) { struct btrfs_super_block *disk_super; - struct bdev_handle *bdev_handle; + struct file *f_bdev; int ret; if (!path || !path[0]) @@ -2340,7 +2340,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info, } ret = btrfs_get_bdev_and_sb(path, BLK_OPEN_READ, NULL, 0, - &bdev_handle, &disk_super); + &f_bdev, &disk_super); if (ret) { btrfs_put_dev_args_from_path(args); return ret; @@ -2353,7 +2353,7 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info, else memcpy(args->fsid, disk_super->fsid, BTRFS_FSID_SIZE); btrfs_release_disk_super(disk_super); - bdev_release(bdev_handle); + fput(f_bdev); return 0; } @@ -2573,7 +2573,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path struct btrfs_root *root = fs_info->dev_root; struct btrfs_trans_handle *trans; struct btrfs_device *device; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct super_block *sb = fs_info->sb; struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; struct btrfs_fs_devices *seed_devices = NULL; @@ -2586,12 +2586,12 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path if (sb_rdonly(sb) && !fs_devices->seeding) return -EROFS; - bdev_handle = bdev_open_by_path(device_path, BLK_OPEN_WRITE, + f_bdev = bdev_file_open_by_path(device_path, BLK_OPEN_WRITE, fs_info->bdev_holder, NULL); - if (IS_ERR(bdev_handle)) - return PTR_ERR(bdev_handle); + if (IS_ERR(f_bdev)) + return PTR_ERR(f_bdev); - if (!btrfs_check_device_zone_type(fs_info, bdev_handle->bdev)) { + if (!btrfs_check_device_zone_type(fs_info, F_BDEV(f_bdev))) { ret = -EINVAL; goto error; } @@ -2603,11 +2603,11 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path locked = true; } - sync_blockdev(bdev_handle->bdev); + sync_blockdev(F_BDEV(f_bdev)); rcu_read_lock(); list_for_each_entry_rcu(device, &fs_devices->devices, dev_list) { - if (device->bdev == bdev_handle->bdev) { + if (device->bdev == F_BDEV(f_bdev)) { ret = -EEXIST; rcu_read_unlock(); goto error; @@ -2623,8 +2623,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path } device->fs_info = fs_info; - device->bdev_handle = bdev_handle; - device->bdev = bdev_handle->bdev; + device->f_bdev = f_bdev; + device->bdev = F_BDEV(f_bdev); ret = lookup_bdev(device_path, &device->devt); if (ret) goto error_free_device; @@ -2807,7 +2807,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path error_free_device: btrfs_free_device(device); error: - bdev_release(bdev_handle); + fput(f_bdev); if (locked) { mutex_unlock(&uuid_mutex); up_write(&sb->s_umount); diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 9cc374864a79..78de9ab6652a 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -90,7 +90,7 @@ struct btrfs_device { u64 generation; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct block_device *bdev; struct btrfs_zoned_device_info *zone_info; @@ -646,7 +646,7 @@ struct btrfs_device *btrfs_alloc_device(struct btrfs_fs_info *fs_info, void btrfs_put_dev_args_from_path(struct btrfs_dev_lookup_args *args); int btrfs_rm_device(struct btrfs_fs_info *fs_info, struct btrfs_dev_lookup_args *args, - struct bdev_handle **bdev_handle); + struct file **f_bdev); void __exit btrfs_cleanup_fs_uuids(void); int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len); int btrfs_grow_device(struct btrfs_trans_handle *trans, From patchwork Wed Jan 3 12:55:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510007 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 315161B28C; Wed, 3 Jan 2024 12:56:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="thfgqDA0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A9E4C433C8; Wed, 3 Jan 2024 12:56:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286570; bh=P3DXc6r93q4e/bSDxN5TyqBmcIjNYn5UWCDVsifWszU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=thfgqDA09nh49/RzY8JNhY3zhkwtaXlvzDntgW5a+G6oNUs6Nz4X+EWp7t7nHlfnh 4trCXGreQqQ/h6jtRRh0GOUYmZ92VT9a29v6xgLB2wWpe2jkQFFPryP6V0q+RWbW5N O6dv2578mO7wfV9h3SI21aN1hPIgO/pHyIMysdMUCsY3AQluWdFgcyQHhmSL1jKhku KpJrPXUY5jCTz5hMVi6nOAGHA36u5IqRyahYpYmJWWw8W5xzVfRODXuGDKagYweeWV 9/5QrK1zx+t2qv+F5vPFqoGkwo/FtmaFfUU9+Slx2mxdNnTloQHxvGTD/JfUisoqbA fjqt3ZxpacedA== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:18 +0100 Subject: [PATCH RFC 20/34] erofs: port device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-20-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=3160; i=brauner@kernel.org; h=from:subject:message-id; bh=P3DXc6r93q4e/bSDxN5TyqBmcIjNYn5UWCDVsifWszU=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTdN0dE2n/XlVUHnI17a9X3yjALbeX/pvjP92371 XuNbdm1HaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABP5coXhv8t//Ui5vxnTV62T i2Q7yxK10XhX8F1Xg7BiYT/ugJM7oxj+GX48/V2er07fYv3HqltnlM/tW7Eo4Okq3pCwlA0P/+a bsQIA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- fs/erofs/data.c | 6 +++--- fs/erofs/internal.h | 2 +- fs/erofs/super.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index c98aeda8abb2..fed9153f2b83 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -220,7 +220,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map) up_read(&devs->rwsem); return 0; } - map->m_bdev = dif->bdev_handle ? dif->bdev_handle->bdev : NULL; + map->m_bdev = dif->f_bdev ? F_BDEV(dif->f_bdev) : NULL; map->m_daxdev = dif->dax_dev; map->m_dax_part_off = dif->dax_part_off; map->m_fscache = dif->fscache; @@ -238,8 +238,8 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map) if (map->m_pa >= startoff && map->m_pa < startoff + length) { map->m_pa -= startoff; - map->m_bdev = dif->bdev_handle ? - dif->bdev_handle->bdev : NULL; + map->m_bdev = dif->f_bdev ? + F_BDEV(dif->f_bdev) : NULL; map->m_daxdev = dif->dax_dev; map->m_dax_part_off = dif->dax_part_off; map->m_fscache = dif->fscache; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index b0409badb017..8ad8957de64c 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -49,7 +49,7 @@ typedef u32 erofs_blk_t; struct erofs_device_info { char *path; struct erofs_fscache *fscache; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct dax_device *dax_dev; u64 dax_part_off; diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 3789d6224513..bc0772445ad5 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -171,7 +171,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, struct erofs_sb_info *sbi = EROFS_SB(sb); struct erofs_fscache *fscache; struct erofs_deviceslot *dis; - struct bdev_handle *bdev_handle; + struct file *f_bdev; void *ptr; ptr = erofs_read_metabuf(buf, sb, erofs_blknr(sb, *pos), EROFS_KMAP); @@ -195,12 +195,12 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb, return PTR_ERR(fscache); dif->fscache = fscache; } else if (!sbi->devs->flatdev) { - bdev_handle = bdev_open_by_path(dif->path, BLK_OPEN_READ, + f_bdev = bdev_file_open_by_path(dif->path, BLK_OPEN_READ, sb->s_type, NULL); - if (IS_ERR(bdev_handle)) - return PTR_ERR(bdev_handle); - dif->bdev_handle = bdev_handle; - dif->dax_dev = fs_dax_get_by_bdev(bdev_handle->bdev, + if (IS_ERR(f_bdev)) + return PTR_ERR(f_bdev); + dif->f_bdev = f_bdev; + dif->dax_dev = fs_dax_get_by_bdev(F_BDEV(f_bdev), &dif->dax_part_off, NULL, NULL); } @@ -748,8 +748,8 @@ static int erofs_release_device_info(int id, void *ptr, void *data) struct erofs_device_info *dif = ptr; fs_put_dax(dif->dax_dev, NULL); - if (dif->bdev_handle) - bdev_release(dif->bdev_handle); + if (dif->f_bdev) + fput(dif->f_bdev); erofs_fscache_unregister_cookie(dif->fscache); dif->fscache = NULL; kfree(dif->path); From patchwork Wed Jan 3 12:55:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510008 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 142BC1B298; Wed, 3 Jan 2024 12:56:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hEGNaleu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50177C433C9; Wed, 3 Jan 2024 12:56:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286572; bh=SID0U4+F+emBv7sTRDN938vHGyc2XiVVgq2ljE3R5GY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hEGNaleuS9FdrFAtvpRLClDeHlXiHjQ4tvM5AnC661f8vTm5qF2NmC/2sHl74FuoB 83PBtdfUcMsMqCYveUEU5RIuuhW5ndZQCsvIxok8KQK/+AIsv0jzIHj0duMkZsNOP9 IqiXz6iyUrxSs04d+HC+1GHUASzS7u3IgYfDKHWTLetjYnAlXZelEv17gqZEyPZpVp 07QcdDCScVUmLD0XxWnAtVPdZdhSWwtA8d0QtClIJ69wr6Yn/DcN1mHtCbh6roj91m jYZNaIfqkwQBXJAz/se0+BZ5LKzzCa+MseOD/3UidNw5vwmZqY8cfi37EJFO+AeD3h dJEjJRBraIhHg== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:19 +0100 Subject: [PATCH RFC 21/34] ext4: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-21-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=6883; i=brauner@kernel.org; h=from:subject:message-id; bh=SID0U4+F+emBv7sTRDN938vHGyc2XiVVgq2ljE3R5GY=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTV1N37Y/q6t+UJW+zfHRPd5bRvmXyM8sQ5Nvd/d j5/bZRyt6OUhUGMi0FWTJHFod0kXG45T8Vmo0wNmDmsTCBDGLg4BWAiTRcZGY4ceNMetV0q2lnG UOSZbpDS1taklitR7FyJYQ8ELecY/GNk2LmY0z50f69/iqBncMAfoYvbfBdpbtFgmbj8ktOLvbr XWQA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- fs/ext4/ext4.h | 2 +- fs/ext4/fsmap.c | 8 ++++---- fs/ext4/super.c | 52 ++++++++++++++++++++++++++-------------------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index a5d784872303..fa0de10ae12b 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1548,7 +1548,7 @@ struct ext4_sb_info { unsigned long s_commit_interval; u32 s_max_batch_time; u32 s_min_batch_time; - struct bdev_handle *s_journal_bdev_handle; + struct file *s_journal_f_bdev; #ifdef CONFIG_QUOTA /* Names of quota files with journalled quota */ char __rcu *s_qf_names[EXT4_MAXQUOTAS]; diff --git a/fs/ext4/fsmap.c b/fs/ext4/fsmap.c index 11e6f33677a2..6dac2866c3f1 100644 --- a/fs/ext4/fsmap.c +++ b/fs/ext4/fsmap.c @@ -576,9 +576,9 @@ static bool ext4_getfsmap_is_valid_device(struct super_block *sb, if (fm->fmr_device == 0 || fm->fmr_device == UINT_MAX || fm->fmr_device == new_encode_dev(sb->s_bdev->bd_dev)) return true; - if (EXT4_SB(sb)->s_journal_bdev_handle && + if (EXT4_SB(sb)->s_journal_f_bdev && fm->fmr_device == - new_encode_dev(EXT4_SB(sb)->s_journal_bdev_handle->bdev->bd_dev)) + new_encode_dev(F_BDEV(EXT4_SB(sb)->s_journal_f_bdev)->bd_dev)) return true; return false; } @@ -648,9 +648,9 @@ int ext4_getfsmap(struct super_block *sb, struct ext4_fsmap_head *head, memset(handlers, 0, sizeof(handlers)); handlers[0].gfd_dev = new_encode_dev(sb->s_bdev->bd_dev); handlers[0].gfd_fn = ext4_getfsmap_datadev; - if (EXT4_SB(sb)->s_journal_bdev_handle) { + if (EXT4_SB(sb)->s_journal_f_bdev) { handlers[1].gfd_dev = new_encode_dev( - EXT4_SB(sb)->s_journal_bdev_handle->bdev->bd_dev); + F_BDEV(EXT4_SB(sb)->s_journal_f_bdev)->bd_dev); handlers[1].gfd_fn = ext4_getfsmap_logdev; } diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 0980845c8b8f..3fec1decccbf 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1359,14 +1359,14 @@ static void ext4_put_super(struct super_block *sb) sync_blockdev(sb->s_bdev); invalidate_bdev(sb->s_bdev); - if (sbi->s_journal_bdev_handle) { + if (sbi->s_journal_f_bdev) { /* * Invalidate the journal device's buffers. We don't want them * floating about in memory - the physical journal device may * hotswapped, and it breaks the `ro-after' testing code. */ - sync_blockdev(sbi->s_journal_bdev_handle->bdev); - invalidate_bdev(sbi->s_journal_bdev_handle->bdev); + sync_blockdev(F_BDEV(sbi->s_journal_f_bdev)); + invalidate_bdev(F_BDEV(sbi->s_journal_f_bdev)); } ext4_xattr_destroy_cache(sbi->s_ea_inode_cache); @@ -4242,7 +4242,7 @@ int ext4_calculate_overhead(struct super_block *sb) * Add the internal journal blocks whether the journal has been * loaded or not */ - if (sbi->s_journal && !sbi->s_journal_bdev_handle) + if (sbi->s_journal && !sbi->s_journal_f_bdev) overhead += EXT4_NUM_B2C(sbi, sbi->s_journal->j_total_len); else if (ext4_has_feature_journal(sb) && !sbi->s_journal && j_inum) { /* j_inum for internal journal is non-zero */ @@ -5679,9 +5679,9 @@ failed_mount9: __maybe_unused #endif fscrypt_free_dummy_policy(&sbi->s_dummy_enc_policy); brelse(sbi->s_sbh); - if (sbi->s_journal_bdev_handle) { - invalidate_bdev(sbi->s_journal_bdev_handle->bdev); - bdev_release(sbi->s_journal_bdev_handle); + if (sbi->s_journal_f_bdev) { + invalidate_bdev(F_BDEV(sbi->s_journal_f_bdev)); + fput(sbi->s_journal_f_bdev); } out_fail: invalidate_bdev(sb->s_bdev); @@ -5851,30 +5851,30 @@ static journal_t *ext4_open_inode_journal(struct super_block *sb, return journal; } -static struct bdev_handle *ext4_get_journal_blkdev(struct super_block *sb, +static struct file *ext4_get_journal_blkdev(struct super_block *sb, dev_t j_dev, ext4_fsblk_t *j_start, ext4_fsblk_t *j_len) { struct buffer_head *bh; struct block_device *bdev; - struct bdev_handle *bdev_handle; + struct file *f_bdev; int hblock, blocksize; ext4_fsblk_t sb_block; unsigned long offset; struct ext4_super_block *es; int errno; - bdev_handle = bdev_open_by_dev(j_dev, + f_bdev = bdev_file_open_by_dev(j_dev, BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES, sb, &fs_holder_ops); - if (IS_ERR(bdev_handle)) { + if (IS_ERR(f_bdev)) { ext4_msg(sb, KERN_ERR, "failed to open journal device unknown-block(%u,%u) %ld", - MAJOR(j_dev), MINOR(j_dev), PTR_ERR(bdev_handle)); - return bdev_handle; + MAJOR(j_dev), MINOR(j_dev), PTR_ERR(f_bdev)); + return f_bdev; } - bdev = bdev_handle->bdev; + bdev = F_BDEV(f_bdev); blocksize = sb->s_blocksize; hblock = bdev_logical_block_size(bdev); if (blocksize < hblock) { @@ -5921,12 +5921,12 @@ static struct bdev_handle *ext4_get_journal_blkdev(struct super_block *sb, *j_start = sb_block + 1; *j_len = ext4_blocks_count(es); brelse(bh); - return bdev_handle; + return f_bdev; out_bh: brelse(bh); out_bdev: - bdev_release(bdev_handle); + fput(f_bdev); return ERR_PTR(errno); } @@ -5936,14 +5936,14 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb, journal_t *journal; ext4_fsblk_t j_start; ext4_fsblk_t j_len; - struct bdev_handle *bdev_handle; + struct file *f_bdev; int errno = 0; - bdev_handle = ext4_get_journal_blkdev(sb, j_dev, &j_start, &j_len); - if (IS_ERR(bdev_handle)) - return ERR_CAST(bdev_handle); + f_bdev = ext4_get_journal_blkdev(sb, j_dev, &j_start, &j_len); + if (IS_ERR(f_bdev)) + return ERR_CAST(f_bdev); - journal = jbd2_journal_init_dev(bdev_handle->bdev, sb->s_bdev, j_start, + journal = jbd2_journal_init_dev(F_BDEV(f_bdev), sb->s_bdev, j_start, j_len, sb->s_blocksize); if (IS_ERR(journal)) { ext4_msg(sb, KERN_ERR, "failed to create device journal"); @@ -5958,14 +5958,14 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb, goto out_journal; } journal->j_private = sb; - EXT4_SB(sb)->s_journal_bdev_handle = bdev_handle; + EXT4_SB(sb)->s_journal_f_bdev = f_bdev; ext4_init_journal_params(sb, journal); return journal; out_journal: jbd2_journal_destroy(journal); out_bdev: - bdev_release(bdev_handle); + fput(f_bdev); return ERR_PTR(errno); } @@ -7323,12 +7323,12 @@ static inline int ext3_feature_set_ok(struct super_block *sb) static void ext4_kill_sb(struct super_block *sb) { struct ext4_sb_info *sbi = EXT4_SB(sb); - struct bdev_handle *handle = sbi ? sbi->s_journal_bdev_handle : NULL; + struct file *f_bdev = sbi ? sbi->s_journal_f_bdev : NULL; kill_block_super(sb); - if (handle) - bdev_release(handle); + if (f_bdev) + fput(f_bdev); } static struct file_system_type ext4_fs_type = { From patchwork Wed Jan 3 12:55:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510009 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FB641BDCA; Wed, 3 Jan 2024 12:56:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="THAGyi1R" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74E8CC433C7; Wed, 3 Jan 2024 12:56:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286575; bh=KmWYP0GscjNbvBwwX9No72a/eIfdzPd72udKmZAR8WI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=THAGyi1R2XgBcsGmVbZlmPq/BHcQgXYU4ICawo+pMFKZH4triQWj6elQVVq2qe0gO bDvK+5/RfL834aqX7EnYLxN9F5vM8v9azSXBXS+qeYVQYacpucbVAEtrbABSapHdQy p7zwecCVTaW/+e/spYhTliBxPPgREPqNa1W7rrBfpU5hn0vO65iqz9N3hciyVBgBgb DQxopo6ZaXxT1uIpiYiaDnRVE+zb5KRcTEu1rKGcBc2spLLmAVYRragXm6NAVNdm6V Rl9FkIZZQUCwJJA7FWbbLQ7Z/DUsJJXk5xjm8QTWMjOfp7lK17zEXuYwdbk1idbyBl PpJuuHGuJvo9A== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:20 +0100 Subject: [PATCH RFC 22/34] f2fs: port block device access to files Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-22-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=1956; i=brauner@kernel.org; h=from:subject:message-id; bh=KmWYP0GscjNbvBwwX9No72a/eIfdzPd72udKmZAR8WI=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTVt5eS/Gt96IKZWj3rw4OCa5Ln6ex7pdvRF+O13 DEhLWdvRykLgxgXg6yYIotDu0m43HKeis1GmRowc1iZQIYwcHEKwEQO3GRkuCKxzdWg7hP/fmmm tL8bzN/8eWjS/m/nxXMPv94SFviynY3hf8LSPdz7zvKfk/E56Mvc4KxW/vKFYLbZrqOzbtxg0d1 5nBUA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- fs/f2fs/f2fs.h | 2 +- fs/f2fs/super.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 9043cedfa12b..9a73eed3b424 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1234,7 +1234,7 @@ struct f2fs_bio_info { #define FDEV(i) (sbi->devs[i]) #define RDEV(i) (raw_super->devs[i]) struct f2fs_dev_info { - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct block_device *bdev; char path[MAX_PATH_LEN]; unsigned int total_segments; diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 93b8a844b207..5e0687a85b4d 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1610,7 +1610,7 @@ static void destroy_device_list(struct f2fs_sb_info *sbi) for (i = 0; i < sbi->s_ndevs; i++) { if (i > 0) - bdev_release(FDEV(i).bdev_handle); + fput(FDEV(i).f_bdev); #ifdef CONFIG_BLK_DEV_ZONED kvfree(FDEV(i).blkz_seq); #endif @@ -4247,7 +4247,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) for (i = 0; i < max_devices; i++) { if (i == 0) - FDEV(0).bdev_handle = sb_bdev_handle(sbi->sb); + FDEV(0).f_bdev = sbi->sb->s_f_bdev; else if (!RDEV(i).path[0]) break; @@ -4267,14 +4267,14 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) FDEV(i).end_blk = FDEV(i).start_blk + (FDEV(i).total_segments << sbi->log_blocks_per_seg) - 1; - FDEV(i).bdev_handle = bdev_open_by_path( + FDEV(i).f_bdev = bdev_file_open_by_path( FDEV(i).path, mode, sbi->sb, NULL); } } - if (IS_ERR(FDEV(i).bdev_handle)) - return PTR_ERR(FDEV(i).bdev_handle); + if (IS_ERR(FDEV(i).f_bdev)) + return PTR_ERR(FDEV(i).f_bdev); - FDEV(i).bdev = FDEV(i).bdev_handle->bdev; + FDEV(i).bdev = F_BDEV(FDEV(i).f_bdev); /* to release errored devices */ sbi->s_ndevs = i + 1; From patchwork Wed Jan 3 12:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510010 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DFDF1BDDA; Wed, 3 Jan 2024 12:56:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DqEiOYe+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83CBDC433CB; Wed, 3 Jan 2024 12:56:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286577; bh=7+5QOJ3fzNoJt3ZM8Bte3iZde2IiCDpBP+rwce7BPr0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=DqEiOYe+CfkuKcG3qQ3ZrKHenT45sotVFtKbQTsEqHT9UY0eAOwjw+LTj4pTynJ6a 2H75j4xDsTAVQorp4F4D23yfLocJaQbpjULsjQjMTKwSQzDr+AaJ3+0fZw4nCxQSVg 9tYvKsflYDf0LxP3kXxMQnOFBvIPB/VXXMCUKNNsCvaoS1KyYXG4HOn371cjTDRiE8 q9paBo+08AJQy/QbznyLHEF+A/txEVXE1IKf1S41JdAVJT+913EPbb1SZsh1jkJiL5 mS0Q2S1/rNkdgc7ewc+KZQLAnp0TmchvI+75BTz3zx9qTzgP0/KgrpbHyvqjT4ngOp PfpSA4m6xi5yg== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:21 +0100 Subject: [PATCH RFC 23/34] jfs: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-23-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=4516; i=brauner@kernel.org; h=from:subject:message-id; bh=7+5QOJ3fzNoJt3ZM8Bte3iZde2IiCDpBP+rwce7BPr0=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTlij+26o/1iriGLqH4m68mls+70dbJLNryMffE+ 19/lqy36ChlYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZhI6j9GhkfxxbNeblGa/+Ll i5PX1H5dXVzMbht/4tHW3RODEmdET5zAyHBujnm1nb3trvieX+liCwPvOATwGE0q+raHKfPorW3 fTrICAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- fs/jfs/jfs_logmgr.c | 26 +++++++++++++------------- fs/jfs/jfs_logmgr.h | 2 +- fs/jfs/jfs_mount.c | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c index 8691463956d1..7dd6b3b6fde0 100644 --- a/fs/jfs/jfs_logmgr.c +++ b/fs/jfs/jfs_logmgr.c @@ -1058,7 +1058,7 @@ void jfs_syncpt(struct jfs_log *log, int hard_sync) int lmLogOpen(struct super_block *sb) { int rc; - struct bdev_handle *bdev_handle; + struct file *f_bdev; struct jfs_log *log; struct jfs_sb_info *sbi = JFS_SBI(sb); @@ -1070,7 +1070,7 @@ int lmLogOpen(struct super_block *sb) mutex_lock(&jfs_log_mutex); list_for_each_entry(log, &jfs_external_logs, journal_list) { - if (log->bdev_handle->bdev->bd_dev == sbi->logdev) { + if (F_BDEV(log->f_bdev)->bd_dev == sbi->logdev) { if (!uuid_equal(&log->uuid, &sbi->loguuid)) { jfs_warn("wrong uuid on JFS journal"); mutex_unlock(&jfs_log_mutex); @@ -1100,14 +1100,14 @@ int lmLogOpen(struct super_block *sb) * file systems to log may have n-to-1 relationship; */ - bdev_handle = bdev_open_by_dev(sbi->logdev, + f_bdev = bdev_file_open_by_dev(sbi->logdev, BLK_OPEN_READ | BLK_OPEN_WRITE, log, NULL); - if (IS_ERR(bdev_handle)) { - rc = PTR_ERR(bdev_handle); + if (IS_ERR(f_bdev)) { + rc = PTR_ERR(f_bdev); goto free; } - log->bdev_handle = bdev_handle; + log->f_bdev = f_bdev; uuid_copy(&log->uuid, &sbi->loguuid); /* @@ -1141,7 +1141,7 @@ int lmLogOpen(struct super_block *sb) lbmLogShutdown(log); close: /* close external log device */ - bdev_release(bdev_handle); + fput(f_bdev); free: /* free log descriptor */ mutex_unlock(&jfs_log_mutex); @@ -1162,7 +1162,7 @@ static int open_inline_log(struct super_block *sb) init_waitqueue_head(&log->syncwait); set_bit(log_INLINELOG, &log->flag); - log->bdev_handle = sb_bdev_handle(sb); + log->f_bdev = sb->s_f_bdev; log->base = addressPXD(&JFS_SBI(sb)->logpxd); log->size = lengthPXD(&JFS_SBI(sb)->logpxd) >> (L2LOGPSIZE - sb->s_blocksize_bits); @@ -1436,7 +1436,7 @@ int lmLogClose(struct super_block *sb) { struct jfs_sb_info *sbi = JFS_SBI(sb); struct jfs_log *log = sbi->log; - struct bdev_handle *bdev_handle; + struct file *f_bdev; int rc = 0; jfs_info("lmLogClose: log:0x%p", log); @@ -1482,10 +1482,10 @@ int lmLogClose(struct super_block *sb) * external log as separate logical volume */ list_del(&log->journal_list); - bdev_handle = log->bdev_handle; + f_bdev = log->f_bdev; rc = lmLogShutdown(log); - bdev_release(bdev_handle); + fput(f_bdev); kfree(log); @@ -1972,7 +1972,7 @@ static int lbmRead(struct jfs_log * log, int pn, struct lbuf ** bpp) bp->l_flag |= lbmREAD; - bio = bio_alloc(log->bdev_handle->bdev, 1, REQ_OP_READ, GFP_NOFS); + bio = bio_alloc(F_BDEV(log->f_bdev), 1, REQ_OP_READ, GFP_NOFS); bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9); __bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset); BUG_ON(bio->bi_iter.bi_size != LOGPSIZE); @@ -2115,7 +2115,7 @@ static void lbmStartIO(struct lbuf * bp) jfs_info("lbmStartIO"); if (!log->no_integrity) - bdev = log->bdev_handle->bdev; + bdev = F_BDEV(log->f_bdev); bio = bio_alloc(bdev, 1, REQ_OP_WRITE | REQ_SYNC, GFP_NOFS); diff --git a/fs/jfs/jfs_logmgr.h b/fs/jfs/jfs_logmgr.h index 84aa2d253907..c7d2d8fb0204 100644 --- a/fs/jfs/jfs_logmgr.h +++ b/fs/jfs/jfs_logmgr.h @@ -356,7 +356,7 @@ struct jfs_log { * before writing syncpt. */ struct list_head journal_list; /* Global list */ - struct bdev_handle *bdev_handle; /* 4: log lv pointer */ + struct file *f_bdev; /* 4: log lv pointer */ int serial; /* 4: log mount serial number */ s64 base; /* @8: log extent address (inline log ) */ diff --git a/fs/jfs/jfs_mount.c b/fs/jfs/jfs_mount.c index 415eb65a36ff..035ab9de4b4f 100644 --- a/fs/jfs/jfs_mount.c +++ b/fs/jfs/jfs_mount.c @@ -431,7 +431,7 @@ int updateSuper(struct super_block *sb, uint state) if (state == FM_MOUNT) { /* record log's dev_t and mount serial number */ j_sb->s_logdev = cpu_to_le32( - new_encode_dev(sbi->log->bdev_handle->bdev->bd_dev)); + new_encode_dev(F_BDEV(sbi->log->f_bdev)->bd_dev)); j_sb->s_logserial = cpu_to_le32(sbi->log->serial); } else if (state == FM_CLEAN) { /* From patchwork Wed Jan 3 12:55:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510011 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9CC71BDE2; Wed, 3 Jan 2024 12:56:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ev+/135N" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE92FC433C7; Wed, 3 Jan 2024 12:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286579; bh=rz5i3p27iNGMZq3H+CpgPLh9W7l4W+LguQEvw+kLKyI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ev+/135N9BWwr0aYQlv2/LQj9SW2BgsdQk3inDoOwcFy68N6JrurnmMafZ0aCaZJk gxxi1uv2ymTXtK3QyH9CneN6L/iYYXiSDuU35tVmqA9edkWEbTmdl3q8arFQG5uUdG 4Xu5Xt8EAlq7sDm+gOecJksQWkvdHJza4IiLgo4uQdzI28Hvw4qpfJE7wFyPU9PVJX fp7QUc9GIF93daZSptMUxwWau6DFfrj/DDoX95w42Gz2ZjfXAcITTcKmjZFK1JijHw 9Zht0ohFG6CsVOQ5xUmxABMgknKBQTVt3VuRWHJZXqWFQk0lzzWlQbEwB0acBj7A3c k3TYzK9UjuFNg== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:22 +0100 Subject: [PATCH RFC 24/34] nfs: port block device access to files Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-24-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=5967; i=brauner@kernel.org; h=from:subject:message-id; bh=rz5i3p27iNGMZq3H+CpgPLh9W7l4W+LguQEvw+kLKyI=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbT13FJoar1SZPe3+MLPbM7Wadv8ti68qbRhFf8iw 28zP/t1d5SyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAExkUhIjw7pTb1gVHh6zXuyg WC0txy99d5NA0ZG5l3PMudpMZ+gcvMXw36ft+dT65JyW911m06ZM8p90r++Wf8jhqr6KF0qeLlu VeAE= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- fs/nfs/blocklayout/blocklayout.h | 2 +- fs/nfs/blocklayout/dev.c | 68 ++++++++++++++++++++-------------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/fs/nfs/blocklayout/blocklayout.h b/fs/nfs/blocklayout/blocklayout.h index b4294a8aa2d4..5f9d9a823c9b 100644 --- a/fs/nfs/blocklayout/blocklayout.h +++ b/fs/nfs/blocklayout/blocklayout.h @@ -108,7 +108,7 @@ struct pnfs_block_dev { struct pnfs_block_dev *children; u64 chunk_size; - struct bdev_handle *bdev_handle; + struct file *f_bdev; u64 disk_offset; u64 pr_key; diff --git a/fs/nfs/blocklayout/dev.c b/fs/nfs/blocklayout/dev.c index f318a05a80e1..d6534ae9eef7 100644 --- a/fs/nfs/blocklayout/dev.c +++ b/fs/nfs/blocklayout/dev.c @@ -25,17 +25,17 @@ bl_free_device(struct pnfs_block_dev *dev) } else { if (dev->pr_registered) { const struct pr_ops *ops = - dev->bdev_handle->bdev->bd_disk->fops->pr_ops; + F_BDEV(dev->f_bdev)->bd_disk->fops->pr_ops; int error; - error = ops->pr_register(dev->bdev_handle->bdev, + error = ops->pr_register(F_BDEV(dev->f_bdev), dev->pr_key, 0, false); if (error) pr_err("failed to unregister PR key.\n"); } - if (dev->bdev_handle) - bdev_release(dev->bdev_handle); + if (dev->f_bdev) + fput(dev->f_bdev); } } @@ -169,7 +169,7 @@ static bool bl_map_simple(struct pnfs_block_dev *dev, u64 offset, map->start = dev->start; map->len = dev->len; map->disk_offset = dev->disk_offset; - map->bdev = dev->bdev_handle->bdev; + map->bdev = F_BDEV(dev->f_bdev); return true; } @@ -236,26 +236,26 @@ bl_parse_simple(struct nfs_server *server, struct pnfs_block_dev *d, struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask) { struct pnfs_block_volume *v = &volumes[idx]; - struct bdev_handle *bdev_handle; + struct file *f_bdev; dev_t dev; dev = bl_resolve_deviceid(server, v, gfp_mask); if (!dev) return -EIO; - bdev_handle = bdev_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_WRITE, + f_bdev = bdev_file_open_by_dev(dev, BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL); - if (IS_ERR(bdev_handle)) { + if (IS_ERR(f_bdev)) { printk(KERN_WARNING "pNFS: failed to open device %d:%d (%ld)\n", - MAJOR(dev), MINOR(dev), PTR_ERR(bdev_handle)); - return PTR_ERR(bdev_handle); + MAJOR(dev), MINOR(dev), PTR_ERR(f_bdev)); + return PTR_ERR(f_bdev); } - d->bdev_handle = bdev_handle; - d->len = bdev_nr_bytes(bdev_handle->bdev); + d->f_bdev = f_bdev; + d->len = bdev_nr_bytes(F_BDEV(f_bdev)); d->map = bl_map_simple; printk(KERN_INFO "pNFS: using block device %s\n", - bdev_handle->bdev->bd_disk->disk_name); + F_BDEV(f_bdev)->bd_disk->disk_name); return 0; } @@ -300,10 +300,10 @@ bl_validate_designator(struct pnfs_block_volume *v) } } -static struct bdev_handle * +static struct file * bl_open_path(struct pnfs_block_volume *v, const char *prefix) { - struct bdev_handle *bdev_handle; + struct file *f_bdev; const char *devname; devname = kasprintf(GFP_KERNEL, "/dev/disk/by-id/%s%*phN", @@ -311,15 +311,15 @@ bl_open_path(struct pnfs_block_volume *v, const char *prefix) if (!devname) return ERR_PTR(-ENOMEM); - bdev_handle = bdev_open_by_path(devname, BLK_OPEN_READ | BLK_OPEN_WRITE, + f_bdev = bdev_file_open_by_path(devname, BLK_OPEN_READ | BLK_OPEN_WRITE, NULL, NULL); - if (IS_ERR(bdev_handle)) { + if (IS_ERR(f_bdev)) { pr_warn("pNFS: failed to open device %s (%ld)\n", - devname, PTR_ERR(bdev_handle)); + devname, PTR_ERR(f_bdev)); } kfree(devname); - return bdev_handle; + return f_bdev; } static int @@ -327,7 +327,7 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d, struct pnfs_block_volume *volumes, int idx, gfp_t gfp_mask) { struct pnfs_block_volume *v = &volumes[idx]; - struct bdev_handle *bdev_handle; + struct file *f_bdev; const struct pr_ops *ops; int error; @@ -340,32 +340,32 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d, * On other distributions like Debian, the default SCSI by-id path will * point to the dm-multipath device if one exists. */ - bdev_handle = bl_open_path(v, "dm-uuid-mpath-0x"); - if (IS_ERR(bdev_handle)) - bdev_handle = bl_open_path(v, "wwn-0x"); - if (IS_ERR(bdev_handle)) - return PTR_ERR(bdev_handle); - d->bdev_handle = bdev_handle; - - d->len = bdev_nr_bytes(d->bdev_handle->bdev); + f_bdev = bl_open_path(v, "dm-uuid-mpath-0x"); + if (IS_ERR(f_bdev)) + f_bdev = bl_open_path(v, "wwn-0x"); + if (IS_ERR(f_bdev)) + return PTR_ERR(f_bdev); + d->f_bdev = f_bdev; + + d->len = bdev_nr_bytes(F_BDEV(d->f_bdev)); d->map = bl_map_simple; d->pr_key = v->scsi.pr_key; pr_info("pNFS: using block device %s (reservation key 0x%llx)\n", - d->bdev_handle->bdev->bd_disk->disk_name, d->pr_key); + F_BDEV(d->f_bdev)->bd_disk->disk_name, d->pr_key); - ops = d->bdev_handle->bdev->bd_disk->fops->pr_ops; + ops = F_BDEV(d->f_bdev)->bd_disk->fops->pr_ops; if (!ops) { pr_err("pNFS: block device %s does not support reservations.", - d->bdev_handle->bdev->bd_disk->disk_name); + F_BDEV(d->f_bdev)->bd_disk->disk_name); error = -EINVAL; goto out_blkdev_put; } - error = ops->pr_register(d->bdev_handle->bdev, 0, d->pr_key, true); + error = ops->pr_register(F_BDEV(d->f_bdev), 0, d->pr_key, true); if (error) { pr_err("pNFS: failed to register key for block device %s.", - d->bdev_handle->bdev->bd_disk->disk_name); + F_BDEV(d->f_bdev)->bd_disk->disk_name); goto out_blkdev_put; } @@ -373,7 +373,7 @@ bl_parse_scsi(struct nfs_server *server, struct pnfs_block_dev *d, return 0; out_blkdev_put: - bdev_release(d->bdev_handle); + fput(d->f_bdev); return error; } From patchwork Wed Jan 3 12:55:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510012 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D2931BDDA; Wed, 3 Jan 2024 12:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UA1o5p8x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF4B9C433C9; Wed, 3 Jan 2024 12:56:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286581; bh=7sfYV/mhryxnVrcvVKVN+lciO7NJYo09pExkMvO7T7A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UA1o5p8xm8/2TDGhP9A4o6/e7mB+WudnvqmlO8Plu0HMjqnUb3PeYLfC99oiyFWmi aOvFXWU5mbaJ9i6wSYGafKwovjNY9q9WCpeckh/1SDWdPMmGMbWJwBo/xkl2QvT4+0 Y6oQGn8v2M1ne3i2I6h6CCB/Vs/yLzFgpurSkohBf9sZSVY5br0zctI2ESMC/AaLTM DuYo+CsTVUFiZXTpTYUDSneFwsUYU6f/L28dRkvJ26B6VmZ39KBEK332ghvq2CX34z QPN7kGzj/StnL1cs+dwDw6UkV7b3bHPB0N6rOaGJcbr6jjuhDb99McTtPrPpdraJnb tWcTzVlLLu5OQ== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:23 +0100 Subject: [PATCH RFC 25/34] ocfs2: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-25-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=3722; i=brauner@kernel.org; h=from:subject:message-id; bh=7sfYV/mhryxnVrcvVKVN+lciO7NJYo09pExkMvO7T7A=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbQ1jvQ+ukBpZnhtY4btv/d3eGbtf7P964cpl/Tq+ S0l3NdP7ihlYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZhISQXD/2qWiS7rzq58aTuX 5yT/9OD6BsM+PzG1uugdEgdcT56OVWdkeL1HwtHo6A8bj5iiK6/5Sy49WfpqsvScf62VkYI67Vs ruAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- fs/ocfs2/cluster/heartbeat.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c index 4d7efefa98c5..e212961493d4 100644 --- a/fs/ocfs2/cluster/heartbeat.c +++ b/fs/ocfs2/cluster/heartbeat.c @@ -213,7 +213,7 @@ struct o2hb_region { unsigned int hr_num_pages; struct page **hr_slot_data; - struct bdev_handle *hr_bdev_handle; + struct file *hr_f_bdev; struct o2hb_disk_slot *hr_slots; /* live node map of this region */ @@ -263,7 +263,7 @@ struct o2hb_region { static inline struct block_device *reg_bdev(struct o2hb_region *reg) { - return reg->hr_bdev_handle ? reg->hr_bdev_handle->bdev : NULL; + return reg->hr_f_bdev ? F_BDEV(reg->hr_f_bdev) : NULL; } struct o2hb_bio_wait_ctxt { @@ -1509,8 +1509,8 @@ static void o2hb_region_release(struct config_item *item) kfree(reg->hr_slot_data); } - if (reg->hr_bdev_handle) - bdev_release(reg->hr_bdev_handle); + if (reg->hr_f_bdev) + fput(reg->hr_f_bdev); kfree(reg->hr_slots); @@ -1569,7 +1569,7 @@ static ssize_t o2hb_region_block_bytes_store(struct config_item *item, unsigned long block_bytes; unsigned int block_bits; - if (reg->hr_bdev_handle) + if (reg->hr_f_bdev) return -EINVAL; status = o2hb_read_block_input(reg, page, &block_bytes, @@ -1598,7 +1598,7 @@ static ssize_t o2hb_region_start_block_store(struct config_item *item, char *p = (char *)page; ssize_t ret; - if (reg->hr_bdev_handle) + if (reg->hr_f_bdev) return -EINVAL; ret = kstrtoull(p, 0, &tmp); @@ -1623,7 +1623,7 @@ static ssize_t o2hb_region_blocks_store(struct config_item *item, unsigned long tmp; char *p = (char *)page; - if (reg->hr_bdev_handle) + if (reg->hr_f_bdev) return -EINVAL; tmp = simple_strtoul(p, &p, 0); @@ -1642,7 +1642,7 @@ static ssize_t o2hb_region_dev_show(struct config_item *item, char *page) { unsigned int ret = 0; - if (to_o2hb_region(item)->hr_bdev_handle) + if (to_o2hb_region(item)->hr_f_bdev) ret = sprintf(page, "%pg\n", reg_bdev(to_o2hb_region(item))); return ret; @@ -1753,7 +1753,7 @@ static int o2hb_populate_slot_data(struct o2hb_region *reg) } /* - * this is acting as commit; we set up all of hr_bdev_handle and hr_task or + * this is acting as commit; we set up all of hr_f_bdev and hr_task or * nothing */ static ssize_t o2hb_region_dev_store(struct config_item *item, @@ -1769,7 +1769,7 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, ssize_t ret = -EINVAL; int live_threshold; - if (reg->hr_bdev_handle) + if (reg->hr_f_bdev) goto out; /* We can't heartbeat without having had our node number @@ -1795,11 +1795,11 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, if (!S_ISBLK(f.file->f_mapping->host->i_mode)) goto out2; - reg->hr_bdev_handle = bdev_open_by_dev(f.file->f_mapping->host->i_rdev, + reg->hr_f_bdev = bdev_file_open_by_dev(f.file->f_mapping->host->i_rdev, BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL); - if (IS_ERR(reg->hr_bdev_handle)) { - ret = PTR_ERR(reg->hr_bdev_handle); - reg->hr_bdev_handle = NULL; + if (IS_ERR(reg->hr_f_bdev)) { + ret = PTR_ERR(reg->hr_f_bdev); + reg->hr_f_bdev = NULL; goto out2; } @@ -1903,8 +1903,8 @@ static ssize_t o2hb_region_dev_store(struct config_item *item, out3: if (ret < 0) { - bdev_release(reg->hr_bdev_handle); - reg->hr_bdev_handle = NULL; + fput(reg->hr_f_bdev); + reg->hr_f_bdev = NULL; } out2: fdput(f); From patchwork Wed Jan 3 12:55:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510013 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD67B1C291; Wed, 3 Jan 2024 12:56:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EufAEbFw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D731EC433C9; Wed, 3 Jan 2024 12:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286583; bh=VeQ5X6STl1UPSpfWkHXbTgSmv5B3HWmkIlnZ+Gc7KiU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EufAEbFw7i6quxIaVUMcxAtSpFAlfUVyhpBfzXJej+7HkR8WE6U2sms9tAM5fxiJH 6Z/1poXtFYD+GjReLgybRWLoDDjbBm3rJBdva/gFP/43juGzPeFOANsvDquizLUpGB nLVS3GVmG+9BD6chH96cr0Zqh1/b9NtjJ0TQHT0pCTt6y23SkeqUFb7knatbDZDB3M vI6JyPLIFfF2OFi4hoF6EmvL/Izbwyvw90yZhZ4RPnoXdU5AI+2AEYKfbe5x8+kg/s HvgJXiRqV7vzobXA5C0Bs0bp4p2BQI0gd+oocV08YOyugfZ4rTZ2HCTYnBQMBXw6xA S5EXJ/8H9v5Rw== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:24 +0100 Subject: [PATCH RFC 26/34] reiserfs: port block device access to file Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-26-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=6027; i=brauner@kernel.org; h=from:subject:message-id; bh=VeQ5X6STl1UPSpfWkHXbTgSmv5B3HWmkIlnZ+Gc7KiU=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbR1TLoYebOisLp/5tFKgW8TFzwz6dLh4lm5btvcy 8Fv4q+od5SyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEwkaybDP6NE/udzD7OdeC18 yOL3XpEpsbd2xh3QrPx0LbnSdKWbeRQjw03blwuvPha7/2Mxe4Qt79nlmRvWvZ25KHReWM3yXTu FNrMDAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- fs/reiserfs/journal.c | 38 +++++++++++++++++++------------------- fs/reiserfs/procfs.c | 2 +- fs/reiserfs/reiserfs.h | 8 ++++---- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index 171c912af50f..177ccb4d9bc3 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -2386,7 +2386,7 @@ static int journal_read(struct super_block *sb) cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(sb); reiserfs_info(sb, "checking transaction log (%pg)\n", - journal->j_bdev_handle->bdev); + F_BDEV(journal->j_f_bdev)); start = ktime_get_seconds(); /* @@ -2447,7 +2447,7 @@ static int journal_read(struct super_block *sb) * device and journal device to be the same */ d_bh = - reiserfs_breada(journal->j_bdev_handle->bdev, cur_dblock, + reiserfs_breada(F_BDEV(journal->j_f_bdev), cur_dblock, sb->s_blocksize, SB_ONDISK_JOURNAL_1st_BLOCK(sb) + SB_ONDISK_JOURNAL_SIZE(sb)); @@ -2588,9 +2588,9 @@ static void journal_list_init(struct super_block *sb) static void release_journal_dev(struct reiserfs_journal *journal) { - if (journal->j_bdev_handle) { - bdev_release(journal->j_bdev_handle); - journal->j_bdev_handle = NULL; + if (journal->j_f_bdev) { + fput(journal->j_f_bdev); + journal->j_f_bdev = NULL; } } @@ -2605,7 +2605,7 @@ static int journal_init_dev(struct super_block *super, result = 0; - journal->j_bdev_handle = NULL; + journal->j_f_bdev = NULL; jdev = SB_ONDISK_JOURNAL_DEVICE(super) ? new_decode_dev(SB_ONDISK_JOURNAL_DEVICE(super)) : super->s_dev; @@ -2616,37 +2616,37 @@ static int journal_init_dev(struct super_block *super, if ((!jdev_name || !jdev_name[0])) { if (jdev == super->s_dev) holder = NULL; - journal->j_bdev_handle = bdev_open_by_dev(jdev, blkdev_mode, + journal->j_f_bdev = bdev_file_open_by_dev(jdev, blkdev_mode, holder, NULL); - if (IS_ERR(journal->j_bdev_handle)) { - result = PTR_ERR(journal->j_bdev_handle); - journal->j_bdev_handle = NULL; + if (IS_ERR(journal->j_f_bdev)) { + result = PTR_ERR(journal->j_f_bdev); + journal->j_f_bdev = NULL; reiserfs_warning(super, "sh-458", "cannot init journal device unknown-block(%u,%u): %i", MAJOR(jdev), MINOR(jdev), result); return result; } else if (jdev != super->s_dev) - set_blocksize(journal->j_bdev_handle->bdev, + set_blocksize(F_BDEV(journal->j_f_bdev), super->s_blocksize); return 0; } - journal->j_bdev_handle = bdev_open_by_path(jdev_name, blkdev_mode, + journal->j_f_bdev = bdev_file_open_by_path(jdev_name, blkdev_mode, holder, NULL); - if (IS_ERR(journal->j_bdev_handle)) { - result = PTR_ERR(journal->j_bdev_handle); - journal->j_bdev_handle = NULL; + if (IS_ERR(journal->j_f_bdev)) { + result = PTR_ERR(journal->j_f_bdev); + journal->j_f_bdev = NULL; reiserfs_warning(super, "sh-457", "journal_init_dev: Cannot open '%s': %i", jdev_name, result); return result; } - set_blocksize(journal->j_bdev_handle->bdev, super->s_blocksize); + set_blocksize(F_BDEV(journal->j_f_bdev), super->s_blocksize); reiserfs_info(super, "journal_init_dev: journal device: %pg\n", - journal->j_bdev_handle->bdev); + F_BDEV(journal->j_f_bdev)); return 0; } @@ -2804,7 +2804,7 @@ int journal_init(struct super_block *sb, const char *j_dev_name, "journal header magic %x (device %pg) does " "not match to magic found in super block %x", jh->jh_journal.jp_journal_magic, - journal->j_bdev_handle->bdev, + F_BDEV(journal->j_f_bdev), sb_jp_journal_magic(rs)); brelse(bhjh); goto free_and_return; @@ -2828,7 +2828,7 @@ int journal_init(struct super_block *sb, const char *j_dev_name, reiserfs_info(sb, "journal params: device %pg, size %u, " "journal first block %u, max trans len %u, max batch %u, " "max commit age %u, max trans age %u\n", - journal->j_bdev_handle->bdev, + F_BDEV(journal->j_f_bdev), SB_ONDISK_JOURNAL_SIZE(sb), SB_ONDISK_JOURNAL_1st_BLOCK(sb), journal->j_trans_max, diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c index 83cb9402e0f9..ff90a822e8eb 100644 --- a/fs/reiserfs/procfs.c +++ b/fs/reiserfs/procfs.c @@ -354,7 +354,7 @@ static int show_journal(struct seq_file *m, void *unused) "prepare: \t%12lu\n" "prepare_retry: \t%12lu\n", DJP(jp_journal_1st_block), - SB_JOURNAL(sb)->j_bdev_handle->bdev, + F_BDEV(SB_JOURNAL(sb)->j_f_bdev), DJP(jp_journal_dev), DJP(jp_journal_size), DJP(jp_journal_trans_max), diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h index 725667880e62..ea2f5950e5c6 100644 --- a/fs/reiserfs/reiserfs.h +++ b/fs/reiserfs/reiserfs.h @@ -299,7 +299,7 @@ struct reiserfs_journal { /* oldest journal block. start here for traverse */ struct reiserfs_journal_cnode *j_first; - struct bdev_handle *j_bdev_handle; + struct file *j_f_bdev; /* first block on s_dev of reserved area journal */ int j_1st_reserved_block; @@ -2810,10 +2810,10 @@ struct reiserfs_journal_header { /* We need these to make journal.c code more readable */ #define journal_find_get_block(s, block) __find_get_block(\ - SB_JOURNAL(s)->j_bdev_handle->bdev, block, s->s_blocksize) -#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_bdev_handle->bdev,\ + F_BDEV(SB_JOURNAL(s)->j_f_bdev), block, s->s_blocksize) +#define journal_getblk(s, block) __getblk(F_BDEV(SB_JOURNAL(s)->j_f_bdev),\ block, s->s_blocksize) -#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_bdev_handle->bdev,\ +#define journal_bread(s, block) __bread(F_BDEV(SB_JOURNAL(s)->j_f_bdev),\ block, s->s_blocksize) enum reiserfs_bh_state_bits { From patchwork Wed Jan 3 12:55:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510014 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDE3D1C289; Wed, 3 Jan 2024 12:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="azIPV4j5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3C45C433CA; Wed, 3 Jan 2024 12:56:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286585; bh=zKpbTwDSSErN4oTBoA1ZuGoBeMNaSB+oZPYayS5Lk6o=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=azIPV4j5i8sXVlFKxTcc+cifAalu3DiBAlAYD83XDFzXllfB6tJZqTbzxtO+4t6w2 pqJc3rkdgU57o/wBcpfXq1PvlpPrbDneDnHbyAhUyRaukXJ0SO0HbKWKhYKpRxT3ve 2fvrp6q5UeZvRnEV8iEvMFaCXKuGirFXiL0tyLv5WllDsklQMZXcKpSSfisIZWwPrc uQ+VY9m2Rz5cYVDfxJLWjLHu+Kzbsmlhk/vVEZ4yolp/S3X8HsA6ZeVBO9NKg4QZXK 7afZAHHpUgGivqNPGPiAElZWYDr5IlI4HXBB3iFS+zR4fnatNXKwuGH7OEaGcQfFs3 XTUEMYMIdnwdQ== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:25 +0100 Subject: [PATCH RFC 27/34] bdev: remove bdev_open_by_path() Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-27-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=2348; i=brauner@kernel.org; h=from:subject:message-id; bh=zKpbTwDSSErN4oTBoA1ZuGoBeMNaSB+oZPYayS5Lk6o=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTN4Mxgk3v7OfZnpMXtzn29Z29vvvum3dfn1FnLZ xO+Mt6u7ChlYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZiI1B5GhsubN4ov3bi9/h1f 2ZYrHBtvRC49Lvpq1SnhCK77/IySWfcZ/ucXFCypmsfP+a7wlUfPxv2b8nKXXf507NmivbOf3Dt 7kIkdAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- block/bdev.c | 40 ---------------------------------------- include/linux/blkdev.h | 2 -- 2 files changed, 42 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 853731fb41ed..a5a1b6cd51ee 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1007,46 +1007,6 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode, } EXPORT_SYMBOL(bdev_file_open_by_path); -/** - * bdev_open_by_path - open a block device by name - * @path: path to the block device to open - * @mode: open mode (BLK_OPEN_*) - * @holder: exclusive holder identifier - * @hops: holder operations - * - * Open the block device described by the device file at @path. If @holder is - * not %NULL, the block device is opened with exclusive access. Exclusive opens - * may nest for the same @holder. - * - * CONTEXT: - * Might sleep. - * - * RETURNS: - * Handle with a reference to the block_device on success, ERR_PTR(-errno) on - * failure. - */ -struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode, - void *holder, const struct blk_holder_ops *hops) -{ - struct bdev_handle *handle; - dev_t dev; - int error; - - error = lookup_bdev(path, &dev); - if (error) - return ERR_PTR(error); - - handle = bdev_open_by_dev(dev, mode, holder, hops); - if (!IS_ERR(handle) && (mode & BLK_OPEN_WRITE) && - bdev_read_only(handle->bdev)) { - bdev_release(handle); - return ERR_PTR(-EACCES); - } - - return handle; -} -EXPORT_SYMBOL(bdev_open_by_path); - void bdev_release(struct bdev_handle *handle) { struct block_device *bdev = handle->bdev; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index e8d11083acbc..8864b978fdb0 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1506,8 +1506,6 @@ struct bdev_handle { struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, const struct blk_holder_ops *hops); -struct bdev_handle *bdev_open_by_path(const char *path, blk_mode_t mode, - void *holder, const struct blk_holder_ops *hops); struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, const struct blk_holder_ops *hops); struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode, From patchwork Wed Jan 3 12:55:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510015 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E16C31C2B3; Wed, 3 Jan 2024 12:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jsvIqS88" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A6CCC433C8; Wed, 3 Jan 2024 12:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286587; bh=8qIsmshufKI60D0UjWvmcqCWK21AUsfl5fAH9rp0xZU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jsvIqS88Eh0VWnK3xgOP45wbSmiSkS6wMejaNrgBNXxETSkCu9M+WMBo16riVozE2 R8cIZRB5mhyk7Nk251mDyOL7C4MetGxlDDh/DiKWLJOZW0/o4w/eMZP9b2Tn20iuNU hM0k5cO7O1hFILMzf7atZYKhkhjua+p7LwoHHoDODDi7XB1pIj2NkSKFUu2Aic0ZDS agoNQhR6qUoMGKXl6fjCdUULremzM/TabYjm5j/T/FA2vlEuEGMwKAnhIHPurG39eW JSvehDpMzRxH3JHfAWdeVCiLeAYDfyjoyYz4C6hgnpst1RWJkpIRZiuHLBTMa8ooHU 1FM02h2xaAkgA== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:26 +0100 Subject: [PATCH RFC 28/34] bdev: make bdev_release() private to block layer Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-28-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=2336; i=brauner@kernel.org; h=from:subject:message-id; bh=8qIsmshufKI60D0UjWvmcqCWK21AUsfl5fAH9rp0xZU=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbT9z/NL60D2Jeaiq37CZ8WvLwj9UO7RKmn5K/7m8 pxrzxY0dJSyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEykz47hf4pAiP2Z+WrnLewF rn17qNGwcNOmhEOX7jm8f9HcybD3PwMjQ0O41rw9+3e8m3g+YFvn08tzNf94PzVLslrRk3tjWn0 0My8A X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 and move both of them to the private block header. There's no caller in the tree anymore that uses them directly. Signed-off-by: Christian Brauner --- block/bdev.c | 2 -- block/blk.h | 4 ++++ include/linux/blkdev.h | 3 --- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index a5a1b6cd51ee..80caa71a65db 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -918,7 +918,6 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, kfree(handle); return ERR_PTR(ret); } -EXPORT_SYMBOL(bdev_open_by_dev); static unsigned blk_to_file_flags(blk_mode_t mode) { @@ -1045,7 +1044,6 @@ void bdev_release(struct bdev_handle *handle) blkdev_put_no_open(bdev); kfree(handle); } -EXPORT_SYMBOL(bdev_release); /** * lookup_bdev() - Look up a struct block_device by name. diff --git a/block/blk.h b/block/blk.h index 08a358bc0919..3ec5e9b5c26c 100644 --- a/block/blk.h +++ b/block/blk.h @@ -518,4 +518,8 @@ static inline int req_ref_read(struct request *req) return atomic_read(&req->ref); } +void bdev_release(struct bdev_handle *handle); +struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, + const struct blk_holder_ops *hops); + #endif /* BLK_INTERNAL_H */ diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 8864b978fdb0..2d06f02f6d5e 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1504,8 +1504,6 @@ struct bdev_handle { blk_mode_t mode; }; -struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, - const struct blk_holder_ops *hops); struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, const struct blk_holder_ops *hops); struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode, @@ -1513,7 +1511,6 @@ struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode, int bd_prepare_to_claim(struct block_device *bdev, void *holder, const struct blk_holder_ops *hops); void bd_abort_claiming(struct block_device *bdev, void *holder); -void bdev_release(struct bdev_handle *handle); /* just for blk-cgroup, don't use elsewhere */ struct block_device *blkdev_get_no_open(dev_t dev); From patchwork Wed Jan 3 12:55:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510016 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15BB51C68D; Wed, 3 Jan 2024 12:56:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jGHsMjcD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4EE51C43391; Wed, 3 Jan 2024 12:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286589; bh=JzT+e7AdbW0Z5pIn/Ln0oNmceQKsqemFTpG7JXYqnig=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jGHsMjcD/5f7djlJ9tHxZhaaAq12aw+DB4qLwYSaE1qHxtgVzwl1ILuV4IUG9NDCH JswJxzoJx/kYuQ6Kt5aVX0Gg+x3JJ+m2yxx7rOY4hz1yAdSS+suno856ZBSp6gb0WW z1f92kAvpS5ag2keSkXa/m0gPWI11Y7R80vj30AVQwuJPw4rzuiSqdyX7Lztb+7qKF xgzqJBqbNxxtablL1y4IuFOKtxxbmAnlFldbPT24jacw3mDkuxisq5YaycmTRg7XM9 3TFfcCUq8vwXUaAuwzXJA8PXw1+b8FZFo/s2mPtEtlfJdYaLEOEDhmztzp7+f8hx3v kExatBq3q+E0g== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:27 +0100 Subject: [PATCH RFC 29/34] bdev: make struct bdev_handle private to the block layer Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-29-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=2264; i=brauner@kernel.org; h=from:subject:message-id; bh=JzT+e7AdbW0Z5pIn/Ln0oNmceQKsqemFTpG7JXYqnig=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTVefon69fNpWafrOZ/2JheqCctP8v982k1vntZr OFr4noUO0pZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACbCIMLIsKBx34G1BXu/LtUR uPIq61Br8YSMJZ0OfYsMyjW9DmZk+jAyND+efbp1xqNrNhHHvv9Yt9SHPSvHZweDac79T7kNbww u8AMA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- block/bdev.c | 1 - block/blk.h | 6 ++++++ include/linux/blkdev.h | 6 ------ include/linux/fs.h | 6 ------ 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 80caa71a65db..b276ef994858 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -49,7 +49,6 @@ struct block_device *I_BDEV(struct inode *inode) } EXPORT_SYMBOL(I_BDEV); -/* @bdev_handle will become private to block/blk.h soon. */ struct block_device *F_BDEV(struct file *f_bdev) { struct bdev_handle *handle = f_bdev->private_data; diff --git a/block/blk.h b/block/blk.h index 3ec5e9b5c26c..d1a2030fa5c3 100644 --- a/block/blk.h +++ b/block/blk.h @@ -25,6 +25,12 @@ struct blk_flush_queue { struct request *flush_rq; }; +struct bdev_handle { + struct block_device *bdev; + void *holder; + blk_mode_t mode; +}; + bool is_flush_rq(struct request *req); struct blk_flush_queue *blk_alloc_flush_queue(int node, int cmd_size, diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 2d06f02f6d5e..5599a33e78a6 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1498,12 +1498,6 @@ extern const struct blk_holder_ops fs_holder_ops; (BLK_OPEN_READ | BLK_OPEN_RESTRICT_WRITES | \ (((flags) & SB_RDONLY) ? 0 : BLK_OPEN_WRITE)) -struct bdev_handle { - struct block_device *bdev; - void *holder; - blk_mode_t mode; -}; - struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, const struct blk_holder_ops *hops); struct file *bdev_file_open_by_path(const char *path, blk_mode_t mode, diff --git a/include/linux/fs.h b/include/linux/fs.h index b0a5e94e8c3a..b23d49f7adfe 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1326,12 +1326,6 @@ struct super_block { struct list_head s_inodes_wb; /* writeback inodes */ } __randomize_layout; -/* Temporary helper that will go away. */ -static inline struct bdev_handle *sb_bdev_handle(struct super_block *sb) -{ - return sb->s_f_bdev->private_data; -} - static inline struct user_namespace *i_user_ns(const struct inode *inode) { return inode->i_sb->s_user_ns; From patchwork Wed Jan 3 12:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510017 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8144B1C692; Wed, 3 Jan 2024 12:56:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KVIP+wyC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 739F6C433CA; Wed, 3 Jan 2024 12:56:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286592; bh=3QdoyKimZ2MzZfuqTDgI4se0zTrQjYhFaZCp+W/qXJU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KVIP+wyC2QC19bsWt70J1tV9mvM5YqTuCiIr7UgMfZCuaELahybc/CmfLUYdn0G/6 vFTl/EgoGBS9vDvCPfsk8cqZNaRYMdBm7ItZafO1o8kZCsp36eXDiDhsHNyNe/sR8/ WBAchS0ihR36Eh+FvTd2rXB2/L1ibRBa3xbtzzb9Q8iyChZju9PiYWwt+oI+oTwxvz PJo194/X0gyOSybmHXxowe7JnGt5QUhw2NtIQESS4TAZRlbxOAJ9C1MoGXFaMn1cKK C5THkQptFIKMXdXgsnrc4VennDWtqv9uLrDsgf8+HTxKogVJ7yj9sYwySEpLdKDEyU ZrnvM7yO5AwJA== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:28 +0100 Subject: [PATCH RFC 30/34] bdev: rework bdev_open_by_dev() Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-30-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=9361; i=brauner@kernel.org; h=from:subject:message-id; bh=3QdoyKimZ2MzZfuqTDgI4se0zTrQjYhFaZCp+W/qXJU=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbS9NfdLwgMGbUm+lufS6/3svDIuq91Yprd4/+HXD GZsM+YwdpSyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEzkJR8jw/b7sRbrituP3eKc e7BAnimN6/bxtxK/Ci7Pusy8YMmu0LsM/33Zp+85dO4ZU3987tfcP2VXDMT8QlP+Cefe9Quv4Td Q4QAA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Now that we always use files when opening block devices rework bdev_open_by_dev() to work well with both bdev_file_open_by_*() and blkdev_open(). Signed-off-by: Christian Brauner --- block/bdev.c | 139 +++++++++++++++++++++++++++++++++-------------------------- block/blk.h | 6 +-- block/fops.c | 34 ++++++--------- 3 files changed, 94 insertions(+), 85 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index b276ef994858..2867edba0169 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -704,6 +704,24 @@ static int blkdev_get_part(struct block_device *part, blk_mode_t mode) return ret; } +int bdev_permission(dev_t dev, blk_mode_t mode, void *holder) +{ + int ret; + + ret = devcgroup_check_permission( + DEVCG_DEV_BLOCK, MAJOR(dev), MINOR(dev), + ((mode & BLK_OPEN_READ) ? DEVCG_ACC_READ : 0) | + ((mode & BLK_OPEN_WRITE) ? DEVCG_ACC_WRITE : 0)); + if (ret) + return ret; + + /* Blocking writes requires exclusive opener */ + if (mode & BLK_OPEN_RESTRICT_WRITES && !holder) + return -EINVAL; + + return 0; +} + static void blkdev_put_part(struct block_device *part) { struct block_device *whole = bdev_whole(part); @@ -796,15 +814,15 @@ static void bdev_yield_write_access(struct block_device *bdev, blk_mode_t mode) } /** - * bdev_open_by_dev - open a block device by device number - * @dev: device number of block device to open + * bdev_open - open a block device + * @bdev: block device to open * @mode: open mode (BLK_OPEN_*) * @holder: exclusive holder identifier * @hops: holder operations + * @f_bdev: file for the block device * - * Open the block device described by device number @dev. If @holder is not - * %NULL, the block device is opened with exclusive access. Exclusive opens may - * nest for the same @holder. + * Open the block device. If @holder is not %NULL, the block device is opened + * with exclusive access. Exclusive opens may nest for the same @holder. * * Use this interface ONLY if you really do not have anything better - i.e. when * you are behind a truly sucky interface and all you are given is a device @@ -814,52 +832,29 @@ static void bdev_yield_write_access(struct block_device *bdev, blk_mode_t mode) * Might sleep. * * RETURNS: - * Handle with a reference to the block_device on success, ERR_PTR(-errno) on - * failure. + * zero on success, -errno on failure. */ -struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, - const struct blk_holder_ops *hops) +int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder, + const struct blk_holder_ops *hops, struct file *f_bdev) { struct bdev_handle *handle = kmalloc(sizeof(struct bdev_handle), GFP_KERNEL); - struct block_device *bdev; bool unblock_events = true; - struct gendisk *disk; + struct gendisk *disk = bdev->bd_disk; int ret; + handle = kmalloc(sizeof(struct bdev_handle), GFP_KERNEL); if (!handle) - return ERR_PTR(-ENOMEM); - - ret = devcgroup_check_permission(DEVCG_DEV_BLOCK, - MAJOR(dev), MINOR(dev), - ((mode & BLK_OPEN_READ) ? DEVCG_ACC_READ : 0) | - ((mode & BLK_OPEN_WRITE) ? DEVCG_ACC_WRITE : 0)); - if (ret) - goto free_handle; - - /* Blocking writes requires exclusive opener */ - if (mode & BLK_OPEN_RESTRICT_WRITES && !holder) { - ret = -EINVAL; - goto free_handle; - } - - bdev = blkdev_get_no_open(dev); - if (!bdev) { - ret = -ENXIO; - goto free_handle; - } - disk = bdev->bd_disk; + return -ENOMEM; if (holder) { mode |= BLK_OPEN_EXCL; ret = bd_prepare_to_claim(bdev, holder, hops); if (ret) - goto put_blkdev; + return ret; } else { - if (WARN_ON_ONCE(mode & BLK_OPEN_EXCL)) { - ret = -EIO; - goto put_blkdev; - } + if (WARN_ON_ONCE(mode & BLK_OPEN_EXCL)) + return -EIO; } disk_block_events(disk); @@ -903,7 +898,22 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, handle->bdev = bdev; handle->holder = holder; handle->mode = mode; - return handle; + + /* + * Preserve backwards compatibility and allow large file access + * even if userspace doesn't ask for it explicitly. Some mkfs + * binary needs it. We might want to drop this workaround + * during an unstable branch. + */ + f_bdev->f_flags |= O_LARGEFILE; + f_bdev->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT; + if (bdev_nowait(bdev)) + f_bdev->f_mode |= FMODE_NOWAIT; + f_bdev->f_mapping = handle->bdev->bd_inode->i_mapping; + f_bdev->f_wb_err = filemap_sample_wb_err(f_bdev->f_mapping); + f_bdev->private_data = handle; + + return 0; put_module: module_put(disk->fops->owner); abort_claiming: @@ -911,11 +921,8 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, bd_abort_claiming(bdev, holder); mutex_unlock(&disk->open_mutex); disk_unblock_events(disk); -put_blkdev: - blkdev_put_no_open(bdev); -free_handle: kfree(handle); - return ERR_PTR(ret); + return ret; } static unsigned blk_to_file_flags(blk_mode_t mode) @@ -927,8 +934,10 @@ static unsigned blk_to_file_flags(blk_mode_t mode) flags |= O_RDWR; else if (mode & BLK_OPEN_WRITE) flags |= O_WRONLY; - else + else if (mode & BLK_OPEN_READ) flags |= O_RDONLY; + else /* Neither read nor write for a block device requested? */ + WARN_ON_ONCE(true); /* * O_EXCL is one of those flags that the VFS clears once it's done with @@ -952,31 +961,37 @@ static unsigned blk_to_file_flags(blk_mode_t mode) struct file *bdev_file_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, const struct blk_holder_ops *hops) { - struct file *file; - struct bdev_handle *handle; + struct file *f_bdev; + struct block_device *bdev; unsigned int flags; + int ret; - handle = bdev_open_by_dev(dev, mode, holder, hops); - if (IS_ERR(handle)) - return ERR_CAST(handle); + ret = bdev_permission(dev, 0, holder); + if (ret) + return ERR_PTR(ret); + + bdev = blkdev_get_no_open(dev); + if (!bdev) + return ERR_PTR(-ENXIO); flags = blk_to_file_flags(mode); - file = alloc_file_pseudo(handle->bdev->bd_inode, blockdev_mnt, "", - flags | O_LARGEFILE, &def_blk_fops); - if (IS_ERR(file)) { - bdev_release(handle); - return file; + f_bdev = alloc_file_pseudo(bdev->bd_inode, blockdev_mnt, "", + flags | O_LARGEFILE, &def_blk_fops); + if (IS_ERR(f_bdev)) { + blkdev_put_no_open(bdev); + return f_bdev; } - ihold(handle->bdev->bd_inode); - - file->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT | FMODE_NOACCOUNT; - if (bdev_nowait(handle->bdev)) - file->f_mode |= FMODE_NOWAIT; + f_bdev->f_mode &= ~FMODE_OPENED; - file->f_mapping = handle->bdev->bd_inode->i_mapping; - file->f_wb_err = filemap_sample_wb_err(file->f_mapping); - file->private_data = handle; - return file; + ihold(bdev->bd_inode); + ret = bdev_open(bdev, mode, holder, hops, f_bdev); + if (ret) { + fput(f_bdev); + return ERR_PTR(ret); + } + /* Now that thing is opened. */ + f_bdev->f_mode |= FMODE_OPENED; + return f_bdev; } EXPORT_SYMBOL(bdev_file_open_by_dev); diff --git a/block/blk.h b/block/blk.h index d1a2030fa5c3..ab1a5ab8cd2e 100644 --- a/block/blk.h +++ b/block/blk.h @@ -525,7 +525,7 @@ static inline int req_ref_read(struct request *req) } void bdev_release(struct bdev_handle *handle); -struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, - const struct blk_holder_ops *hops); - +int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder, + const struct blk_holder_ops *hops, struct file *f_bdev); +int bdev_permission(dev_t dev, blk_mode_t mode, void *holder); #endif /* BLK_INTERNAL_H */ diff --git a/block/fops.c b/block/fops.c index 0abaac705daf..ed7be8b5810e 100644 --- a/block/fops.c +++ b/block/fops.c @@ -584,31 +584,25 @@ blk_mode_t file_to_blk_mode(struct file *file) static int blkdev_open(struct inode *inode, struct file *filp) { - struct bdev_handle *handle; + struct block_device *bdev; blk_mode_t mode; - - /* - * Preserve backwards compatibility and allow large file access - * even if userspace doesn't ask for it explicitly. Some mkfs - * binary needs it. We might want to drop this workaround - * during an unstable branch. - */ - filp->f_flags |= O_LARGEFILE; - filp->f_mode |= FMODE_BUF_RASYNC | FMODE_CAN_ODIRECT; + void *holder; + int ret; mode = file_to_blk_mode(filp); - handle = bdev_open_by_dev(inode->i_rdev, mode, - mode & BLK_OPEN_EXCL ? filp : NULL, NULL); - if (IS_ERR(handle)) - return PTR_ERR(handle); + holder = mode & BLK_OPEN_EXCL ? filp : NULL; + ret = bdev_permission(inode->i_rdev, mode, holder); + if (ret) + return ret; - if (bdev_nowait(handle->bdev)) - filp->f_mode |= FMODE_NOWAIT; + bdev = blkdev_get_no_open(inode->i_rdev); + if (!bdev) + return -ENXIO; - filp->f_mapping = handle->bdev->bd_inode->i_mapping; - filp->f_wb_err = filemap_sample_wb_err(filp->f_mapping); - filp->private_data = handle; - return 0; + ret = bdev_open(bdev, mode, holder, NULL, filp); + if (ret) + blkdev_put_no_open(bdev); + return ret; } static int blkdev_release(struct inode *inode, struct file *filp) From patchwork Wed Jan 3 12:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510018 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2E021C696; Wed, 3 Jan 2024 12:56:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JIiE1LN9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F543C433C7; Wed, 3 Jan 2024 12:56:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286594; bh=SNksmdREYQ4G4E9enbuAVrHtdHDfuHJxBC6kFZXSeMc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JIiE1LN9TuT3otlMK8p4cQarxYhmikjja9bRzW0+Sff/+XTEUKS7WoJt4UxhreaIE Sh2QwbH1CywvpwM3pXt++f04lJ3aUb9Rh1Cp2z5gojzv0JVBZ9EZvJDUuHbSSXCHjT u1TFEh7D5tx5StHVH7UFW9twKnGpSqM9FpRuLphN8MbGbyAshux9+TKogSHxuOglXe +8z2joTahRWS6Ir+t0KcoWGNZw/JONDZ7/zTiSQFpTxVr3LsjDs8QoswUB0rVnKs09 y3PDTSihwRko6j0l5dM49z8a0aVWJ91OLe6nMMiWk3Qs+2/uAZqn3j5C3B9n/N3KEs YhFU4U29xigGw== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:29 +0100 Subject: [PATCH RFC 31/34] ext4: rely on sb->f_bdev only Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-31-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=8254; i=brauner@kernel.org; h=from:subject:message-id; bh=SNksmdREYQ4G4E9enbuAVrHtdHDfuHJxBC6kFZXSeMc=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbTNFLwgcerw4gPXfT84WrhsVVw5Va+bfZ/817T1l frLTzdGd5SyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEykvYeRoUcp2903k0Nt5bxM xkPuGxaJ3Pv1xjTc69HcasUTfAu3VjAyHOtQPB5XE2jweZJ63kbzNkGROR9fG1946NPHJX8nprW GEwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- fs/ext4/dir.c | 2 +- fs/ext4/ext4_jbd2.c | 2 +- fs/ext4/fast_commit.c | 2 +- fs/ext4/super.c | 36 ++++++++++++++++++------------------ 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index 3985f8c33f95..992f09aff438 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -192,7 +192,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) (PAGE_SHIFT - inode->i_blkbits); if (!ra_has_index(&file->f_ra, index)) page_cache_sync_readahead( - sb->s_bdev->bd_inode->i_mapping, + F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping, &file->f_ra, file, index, 1); file->f_ra.prev_pos = (loff_t)index << PAGE_SHIFT; diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index d1a2e6624401..97f9ba412f1e 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -206,7 +206,7 @@ static void ext4_journal_abort_handle(const char *caller, unsigned int line, static void ext4_check_bdev_write_error(struct super_block *sb) { - struct address_space *mapping = sb->s_bdev->bd_inode->i_mapping; + struct address_space *mapping = F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping; struct ext4_sb_info *sbi = EXT4_SB(sb); int err; diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 87c009e0c59a..60ca93b7df81 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1605,7 +1605,7 @@ static int ext4_fc_replay_inode(struct super_block *sb, out: iput(inode); if (!ret) - blkdev_issue_flush(sb->s_bdev); + blkdev_issue_flush(F_BDEV(sb->s_f_bdev)); return 0; } diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 3fec1decccbf..6ea654105076 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -244,7 +244,7 @@ static struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb, struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block, blk_opf_t op_flags) { - gfp_t gfp = mapping_gfp_constraint(sb->s_bdev->bd_inode->i_mapping, + gfp_t gfp = mapping_gfp_constraint(F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping, ~__GFP_FS) | __GFP_MOVABLE; return __ext4_sb_bread_gfp(sb, block, op_flags, gfp); @@ -253,7 +253,7 @@ struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block, struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb, sector_t block) { - gfp_t gfp = mapping_gfp_constraint(sb->s_bdev->bd_inode->i_mapping, + gfp_t gfp = mapping_gfp_constraint(F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping, ~__GFP_FS); return __ext4_sb_bread_gfp(sb, block, 0, gfp); @@ -261,7 +261,7 @@ struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb, void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block) { - struct buffer_head *bh = bdev_getblk(sb->s_bdev, block, + struct buffer_head *bh = bdev_getblk(F_BDEV(sb->s_f_bdev), block, sb->s_blocksize, GFP_NOWAIT | __GFP_NOWARN); if (likely(bh)) { @@ -477,7 +477,7 @@ static void ext4_maybe_update_superblock(struct super_block *sb) return; lifetime_write_kbytes = sbi->s_kbytes_written + - ((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) - + ((part_stat_read(F_BDEV(sb->s_f_bdev), sectors[STAT_WRITE]) - sbi->s_sectors_written_start) >> 1); /* Get the number of kilobytes not written to disk to account @@ -502,7 +502,7 @@ static void ext4_maybe_update_superblock(struct super_block *sb) */ static int block_device_ejected(struct super_block *sb) { - struct inode *bd_inode = sb->s_bdev->bd_inode; + struct inode *bd_inode = F_BDEV(sb->s_f_bdev)->bd_inode; struct backing_dev_info *bdi = inode_to_bdi(bd_inode); return bdi->dev == NULL; @@ -722,7 +722,7 @@ static void ext4_handle_error(struct super_block *sb, bool force_ro, int error, jbd2_journal_abort(journal, -EIO); } - if (!bdev_read_only(sb->s_bdev)) { + if (!bdev_read_only(F_BDEV(sb->s_f_bdev))) { save_error_info(sb, error, ino, block, func, line); /* * In case the fs should keep running, we need to writeout @@ -1084,7 +1084,7 @@ __acquires(bitlock) if (test_opt(sb, WARN_ON_ERROR)) WARN_ON_ONCE(1); EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; - if (!bdev_read_only(sb->s_bdev)) { + if (!bdev_read_only(F_BDEV(sb->s_f_bdev))) { save_error_info(sb, EFSCORRUPTED, ino, block, function, line); schedule_work(&EXT4_SB(sb)->s_sb_upd_work); @@ -1357,8 +1357,8 @@ static void ext4_put_super(struct super_block *sb) dump_orphan_list(sb, sbi); ASSERT(list_empty(&sbi->s_orphan)); - sync_blockdev(sb->s_bdev); - invalidate_bdev(sb->s_bdev); + sync_blockdev(F_BDEV(sb->s_f_bdev)); + invalidate_bdev(F_BDEV(sb->s_f_bdev)); if (sbi->s_journal_f_bdev) { /* * Invalidate the journal device's buffers. We don't want them @@ -4338,7 +4338,7 @@ static struct ext4_sb_info *ext4_alloc_sbi(struct super_block *sb) if (!sbi) return NULL; - sbi->s_daxdev = fs_dax_get_by_bdev(sb->s_bdev, &sbi->s_dax_part_off, + sbi->s_daxdev = fs_dax_get_by_bdev(F_BDEV(sb->s_f_bdev), &sbi->s_dax_part_off, NULL, NULL); sbi->s_blockgroup_lock = @@ -5231,7 +5231,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; sbi->s_sectors_written_start = - part_stat_read(sb->s_bdev, sectors[STAT_WRITE]); + part_stat_read(F_BDEV(sb->s_f_bdev), sectors[STAT_WRITE]); err = ext4_load_super(sb, &logical_sb_block, silent); if (err) @@ -5585,7 +5585,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) * used to detect the metadata async write error. */ spin_lock_init(&sbi->s_bdev_wb_lock); - errseq_check_and_advance(&sb->s_bdev->bd_inode->i_mapping->wb_err, + errseq_check_and_advance(&F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping->wb_err, &sbi->s_bdev_wb_err); EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; ext4_orphan_cleanup(sb, es); @@ -5605,7 +5605,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) goto failed_mount10; } - if (test_opt(sb, DISCARD) && !bdev_max_discard_sectors(sb->s_bdev)) + if (test_opt(sb, DISCARD) && !bdev_max_discard_sectors(F_BDEV(sb->s_f_bdev))) ext4_msg(sb, KERN_WARNING, "mounting with \"discard\" option, but the device does not support discard"); @@ -5684,7 +5684,7 @@ failed_mount9: __maybe_unused fput(sbi->s_journal_f_bdev); } out_fail: - invalidate_bdev(sb->s_bdev); + invalidate_bdev(F_BDEV(sb->s_f_bdev)); sb->s_fs_info = NULL; return err; } @@ -5943,7 +5943,7 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb, if (IS_ERR(f_bdev)) return ERR_CAST(f_bdev); - journal = jbd2_journal_init_dev(F_BDEV(f_bdev), sb->s_bdev, j_start, + journal = jbd2_journal_init_dev(F_BDEV(f_bdev), F_BDEV(sb->s_f_bdev), j_start, j_len, sb->s_blocksize); if (IS_ERR(journal)) { ext4_msg(sb, KERN_ERR, "failed to create device journal"); @@ -6008,7 +6008,7 @@ static int ext4_load_journal(struct super_block *sb, } journal_dev_ro = bdev_read_only(journal->j_dev); - really_read_only = bdev_read_only(sb->s_bdev) | journal_dev_ro; + really_read_only = bdev_read_only(F_BDEV(sb->s_f_bdev)) | journal_dev_ro; if (journal_dev_ro && !sb_rdonly(sb)) { ext4_msg(sb, KERN_ERR, @@ -6125,7 +6125,7 @@ static void ext4_update_super(struct super_block *sb) ext4_update_tstamp(es, s_wtime); es->s_kbytes_written = cpu_to_le64(sbi->s_kbytes_written + - ((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) - + ((part_stat_read(F_BDEV(sb->s_f_bdev), sectors[STAT_WRITE]) - sbi->s_sectors_written_start) >> 1)); if (percpu_counter_initialized(&sbi->s_freeclusters_counter)) ext4_free_blocks_count_set(es, @@ -6359,7 +6359,7 @@ static int ext4_sync_fs(struct super_block *sb, int wait) needs_barrier = true; if (needs_barrier) { int err; - err = blkdev_issue_flush(sb->s_bdev); + err = blkdev_issue_flush(F_BDEV(sb->s_f_bdev)); if (!ret) ret = err; } From patchwork Wed Jan 3 12:55:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510019 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81F4C1CA80; Wed, 3 Jan 2024 12:56:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nQX0LUdT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4962C433D9; Wed, 3 Jan 2024 12:56:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286596; bh=9hbRiu68kYsy/jUGxdkcNWylp3C8+yNikd5BhdPMZsM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nQX0LUdT3jsjKtIH9qbxIAVt5YU+FjMjTLUnZ34+3mWlyUSjEYnUSp+r/VbM7ZBDO 5dRIeoAn8TsKms7UoH4jKUJca+UMTOGCgJ5mne/uUGzB0Qr56Z8L/b1qKB++am9oRZ LZDTFG9R5ae8/NPcsg/W8Fq9uLolXDKJhVNuG3cdDgL8sSKNCqnH3t726WPdkE9jfO c52dny5YLAEMo5sdGdxuw5APgjsf2KA2ftlumwEVayoqHNckxBOVj2eMc8+sOOFqtC bxl28LjwE/L4gjKMsowkxG8lXPFQlu8Cfn5whwn+efIh1FLR8sqAiDZYszvXF1pFLi DraIEHYSdIsZg== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:30 +0100 Subject: [PATCH RFC 32/34] block: expose bdev_file_inode() Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-32-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=1312; i=brauner@kernel.org; h=from:subject:message-id; bh=9hbRiu68kYsy/jUGxdkcNWylp3C8+yNikd5BhdPMZsM=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbR7kD5B5OIefrvauRVLTwQJCoktChd+m+oZyfjpC F/2Oxf5jlIWBjEuBlkxRRaHdpNwueU8FZuNMjVg5rAygQxh4OIUgIlcOszwv2jW4QP5CXq5d0L2 MQfui15QX5VwIJp7/s7Sxxen/98TFsTI8IZ1xY+Oe9Pu+ZX/zJ4suPJrZMPsvw1yTmYMT7k/K4e VMQMA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Now that we open block devices as files we don't need to rely on bd_inode to get to the correct inode. Use the helper. Signed-off-by: Christian Brauner --- block/fops.c | 5 ----- include/linux/blkdev.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/block/fops.c b/block/fops.c index ed7be8b5810e..e831196dafac 100644 --- a/block/fops.c +++ b/block/fops.c @@ -19,11 +19,6 @@ #include #include "blk.h" -static inline struct inode *bdev_file_inode(struct file *file) -{ - return file->f_mapping->host; -} - static blk_opf_t dio_bio_write_op(struct kiocb *iocb) { blk_opf_t opf = REQ_OP_WRITE | REQ_SYNC | REQ_IDLE; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 5599a33e78a6..4bde3e87817d 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1513,6 +1513,11 @@ void blkdev_put_no_open(struct block_device *bdev); struct block_device *I_BDEV(struct inode *inode); struct block_device *F_BDEV(struct file *file); +static inline struct inode *bdev_file_inode(struct file *file) +{ + return file->f_mapping->host; +} + #ifdef CONFIG_BLOCK void invalidate_bdev(struct block_device *bdev); int sync_blockdev(struct block_device *bdev); From patchwork Wed Jan 3 12:55:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510020 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6C901CA91; Wed, 3 Jan 2024 12:56:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YGMJdUHO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E205CC433C7; Wed, 3 Jan 2024 12:56:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286598; bh=tPqM8fijq6blpWamnlfJkZOMMoILtCDc5JxFYa0RI7M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YGMJdUHOSZ0JJJZ3y9VWIhncM60aZg5+psgdZE0iMo7ARQjaCbBSm5C+CoTbSVvZ8 lQGYEdrwE46Q2nVeOL7wctZaqRlsQv4r3s6GHWxqoqd/MI/U1dhIVRILumUUf1XASG UnoKESje6PjCPbYLDbq7JSjzzHb08yC20BiGQmPgmC7DzHGof58XitASLPZ3YEQCmk dO76PrFMhU7JklFgE0crbjkKtBid/I9UjPF4FJ6jXRY9pSCEAxzP0Y1Xd5rp4X3HM8 awoXVNMcM1QBIsFVlmvtMLdhfjphHORp9M7ieNA8G3Ne8FkKV9EecVkh1+QayJ2Uma DcrnO4QTcbaEg== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:31 +0100 Subject: [PATCH RFC 33/34] ext4: use bdev_file_inode() Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-33-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=3248; i=brauner@kernel.org; h=from:subject:message-id; bh=tPqM8fijq6blpWamnlfJkZOMMoILtCDc5JxFYa0RI7M=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbQTWdJRz7R2XeMuheR1fqbubS1P+iyNZ3C55igWq lxcKhbQUcrCIMbFICumyOLQbhIut5ynYrNRpgbMHFYmkCEMXJwCMBH1pQx/eA8LZ7Y5rhTPr2t9 4uJrcdfc2rhgwr83nwrjJeY7HZ5YyfCHS8FjKqNz5/uVebuVC95FxbWVcPXoJC2wazNUimZ2f8c NAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 There's no need to access bd_inode directly anymore now that we use a struct file for block device opening. Signed-off-by: Christian Brauner --- fs/ext4/dir.c | 2 +- fs/ext4/ext4_jbd2.c | 2 +- fs/ext4/super.c | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index 992f09aff438..5037329f35c7 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -192,7 +192,7 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) (PAGE_SHIFT - inode->i_blkbits); if (!ra_has_index(&file->f_ra, index)) page_cache_sync_readahead( - F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping, + bdev_file_inode(sb->s_f_bdev)->i_mapping, &file->f_ra, file, index, 1); file->f_ra.prev_pos = (loff_t)index << PAGE_SHIFT; diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c index 97f9ba412f1e..eaec6d2429cc 100644 --- a/fs/ext4/ext4_jbd2.c +++ b/fs/ext4/ext4_jbd2.c @@ -206,7 +206,7 @@ static void ext4_journal_abort_handle(const char *caller, unsigned int line, static void ext4_check_bdev_write_error(struct super_block *sb) { - struct address_space *mapping = F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping; + struct address_space *mapping = bdev_file_inode(sb->s_f_bdev)->i_mapping; struct ext4_sb_info *sbi = EXT4_SB(sb); int err; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 6ea654105076..40387ba598f4 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -244,7 +244,7 @@ static struct buffer_head *__ext4_sb_bread_gfp(struct super_block *sb, struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block, blk_opf_t op_flags) { - gfp_t gfp = mapping_gfp_constraint(F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping, + gfp_t gfp = mapping_gfp_constraint(bdev_file_inode(sb->s_f_bdev)->i_mapping, ~__GFP_FS) | __GFP_MOVABLE; return __ext4_sb_bread_gfp(sb, block, op_flags, gfp); @@ -253,7 +253,7 @@ struct buffer_head *ext4_sb_bread(struct super_block *sb, sector_t block, struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb, sector_t block) { - gfp_t gfp = mapping_gfp_constraint(F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping, + gfp_t gfp = mapping_gfp_constraint(bdev_file_inode(sb->s_f_bdev)->i_mapping, ~__GFP_FS); return __ext4_sb_bread_gfp(sb, block, 0, gfp); @@ -502,7 +502,7 @@ static void ext4_maybe_update_superblock(struct super_block *sb) */ static int block_device_ejected(struct super_block *sb) { - struct inode *bd_inode = F_BDEV(sb->s_f_bdev)->bd_inode; + struct inode *bd_inode = bdev_file_inode(sb->s_f_bdev); struct backing_dev_info *bdi = inode_to_bdi(bd_inode); return bdi->dev == NULL; @@ -5585,7 +5585,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb) * used to detect the metadata async write error. */ spin_lock_init(&sbi->s_bdev_wb_lock); - errseq_check_and_advance(&F_BDEV(sb->s_f_bdev)->bd_inode->i_mapping->wb_err, + errseq_check_and_advance(&bdev_file_inode(sb->s_f_bdev)->i_mapping->wb_err, &sbi->s_bdev_wb_err); EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; ext4_orphan_cleanup(sb, es); From patchwork Wed Jan 3 12:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13510021 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0ACBA1CA91; Wed, 3 Jan 2024 12:56:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="g5pgGJ2c" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14368C4339A; Wed, 3 Jan 2024 12:56:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704286600; bh=DkTQ2uWC2bPHGoGYF7ID+i42KGRRC/cXMHjU4dFopLw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=g5pgGJ2c8l2INmEdUgOxoMeGhUE2UgS31/w/4r5F756oKIEZ7HooaDc6lhjKnDUM+ U7VJ7YZ8KVVQfMIM93754H80rbgULEHXG4+mijCJ8+U7TfI0IK3Md9nCIfUGczp5oR bFFSnxPY/U05Hsryut6YNytVuxJKG77+PnG1RIMq33ApFH+VwcZrcdFFogCiBGll5h 2dQnEA2aqdoQxToijs2YwODpHevT4u5zoksMUqURwQjqVkUTHzHSjddxLQ334hXFSt n3rWkOboM1ZXBBBKDHxPE1oD8isJ8UbwClwqpoHzLs2RstiZzEZYteEFWoDkqgJaai bG1SSxt5T8vjA== From: Christian Brauner Date: Wed, 03 Jan 2024 13:55:32 +0100 Subject: [PATCH DRAFT RFC 34/34] buffer: port block device access to files and get rid of bd_inode access Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240103-vfs-bdev-file-v1-34-6c8ee55fb6ef@kernel.org> References: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> In-Reply-To: <20240103-vfs-bdev-file-v1-0-6c8ee55fb6ef@kernel.org> To: Jan Kara , Christoph Hellwig , Jens Axboe Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christian Brauner X-Mailer: b4 0.13-dev-4e032 X-Developer-Signature: v=1; a=openpgp-sha256; l=52787; i=brauner@kernel.org; h=from:subject:message-id; bh=DkTQ2uWC2bPHGoGYF7ID+i42KGRRC/cXMHjU4dFopLw=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaROjbSbI5bXVsaXbHd8QXCr5edpD3P51yzjPvQ/RvbGe 47jfbt+dJSyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEwkcDLD/6SDtdlL1f93xsyp edpU+EbZlndG0YfPsvw7T7JPsrx9I53hn9YOqcJQ94aoA9cPPnydfXx/sBMby6vz/42zEvVF76z gYAYA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Signed-off-by: Christian Brauner --- block/fops.c | 1 + drivers/md/md-bitmap.c | 1 + fs/affs/file.c | 1 + fs/btrfs/inode.c | 1 + fs/buffer.c | 69 ++++++++++++++++++++++--------------------- fs/direct-io.c | 2 +- fs/erofs/data.c | 7 +++-- fs/erofs/internal.h | 1 + fs/erofs/zmap.c | 1 + fs/ext2/inode.c | 8 +++-- fs/ext4/inode.c | 6 ++-- fs/ext4/super.c | 6 ++-- fs/f2fs/data.c | 6 +++- fs/f2fs/f2fs.h | 1 + fs/fuse/dax.c | 1 + fs/gfs2/aops.c | 1 + fs/gfs2/bmap.c | 1 + fs/hpfs/file.c | 1 + fs/jbd2/commit.c | 1 + fs/jbd2/journal.c | 26 +++++++++------- fs/jbd2/recovery.c | 6 ++-- fs/jbd2/revoke.c | 10 +++---- fs/jbd2/transaction.c | 1 + fs/mpage.c | 5 +++- fs/nilfs2/btnode.c | 2 ++ fs/nilfs2/gcinode.c | 1 + fs/nilfs2/mdt.c | 1 + fs/nilfs2/page.c | 2 ++ fs/nilfs2/recovery.c | 20 ++++++------- fs/nilfs2/the_nilfs.c | 1 + fs/ntfs/aops.c | 3 ++ fs/ntfs/file.c | 1 + fs/ntfs/mft.c | 2 ++ fs/ntfs3/fsntfs.c | 8 ++--- fs/ntfs3/inode.c | 1 + fs/ntfs3/super.c | 2 +- fs/ocfs2/journal.c | 2 +- fs/reiserfs/journal.c | 8 ++--- fs/reiserfs/reiserfs.h | 6 ++-- fs/reiserfs/tail_conversion.c | 1 + fs/xfs/xfs_iomap.c | 7 +++-- fs/zonefs/file.c | 2 ++ include/linux/buffer_head.h | 45 +++++++++++++++------------- include/linux/iomap.h | 1 + include/linux/jbd2.h | 6 ++-- 45 files changed, 172 insertions(+), 114 deletions(-) diff --git a/block/fops.c b/block/fops.c index e831196dafac..6557b71c7657 100644 --- a/block/fops.c +++ b/block/fops.c @@ -381,6 +381,7 @@ static int blkdev_iomap_begin(struct inode *inode, loff_t offset, loff_t length, loff_t isize = i_size_read(inode); iomap->bdev = bdev; + BUG_ON(true /* TODO(brauner): This is the only place where we don't go from inode->i_sb->s_f_bdev for obvious reasons. Thoughts? */); iomap->offset = ALIGN_DOWN(offset, bdev_logical_block_size(bdev)); if (iomap->offset >= isize) return -EIO; diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index 9672f75c3050..489d9c74e1af 100644 --- a/drivers/md/md-bitmap.c +++ b/drivers/md/md-bitmap.c @@ -380,6 +380,7 @@ static int read_file_page(struct file *file, unsigned long index, } bh->b_blocknr = block; + bh->f_b_bdev = inode->i_sb->s_f_bdev; bh->b_bdev = inode->i_sb->s_bdev; if (count < blocksize) count = 0; diff --git a/fs/affs/file.c b/fs/affs/file.c index 04c018e19602..7b62430d7052 100644 --- a/fs/affs/file.c +++ b/fs/affs/file.c @@ -366,6 +366,7 @@ affs_get_block(struct inode *inode, sector_t block, struct buffer_head *bh_resul brelse(ext_bh); clear_buffer_mapped(bh_result); bh_result->b_bdev = NULL; + bh_result->f_b_bdev = NULL; // unlock cache affs_unlock_ext(inode); return -ENOSPC; diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index fb3c3f43c3fa..ee895a8be28d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -7647,6 +7647,7 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start, } iomap->offset = start; iomap->bdev = fs_info->fs_devices->latest_dev->bdev; + iomap->f_bdev = fs_info->fs_devices->latest_dev->f_bdev; iomap->length = len; free_extent_map(em); diff --git a/fs/buffer.c b/fs/buffer.c index 5ffc44ab4854..17191d33974f 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -187,9 +187,9 @@ EXPORT_SYMBOL(end_buffer_write_sync); * succeeds, there is no need to take i_private_lock. */ static struct buffer_head * -__find_get_block_slow(struct block_device *bdev, sector_t block) +__find_get_block_slow(struct file *f_bdev, sector_t block) { - struct inode *bd_inode = bdev->bd_inode; + struct inode *bd_inode = bdev_file_inode(f_bdev); struct address_space *bd_mapping = bd_inode->i_mapping; struct buffer_head *ret = NULL; pgoff_t index; @@ -232,7 +232,7 @@ __find_get_block_slow(struct block_device *bdev, sector_t block) "device %pg blocksize: %d\n", (unsigned long long)block, (unsigned long long)bh->b_blocknr, - bh->b_state, bh->b_size, bdev, + bh->b_state, bh->b_size, F_BDEV(f_bdev), 1 << bd_inode->i_blkbits); } out_unlock: @@ -656,10 +656,10 @@ EXPORT_SYMBOL(generic_buffers_fsync); * `bblock + 1' is probably a dirty indirect block. Hunt it down and, if it's * dirty, schedule it for IO. So that indirects merge nicely with their data. */ -void write_boundary_block(struct block_device *bdev, +void write_boundary_block(struct file *f_bdev, sector_t bblock, unsigned blocksize) { - struct buffer_head *bh = __find_get_block(bdev, bblock + 1, blocksize); + struct buffer_head *bh = __find_get_block(f_bdev, bblock + 1, blocksize); if (bh) { if (buffer_dirty(bh)) write_dirty_buffer(bh, 0); @@ -995,18 +995,19 @@ static sector_t blkdev_max_block(struct block_device *bdev, unsigned int size) * Initialise the state of a blockdev folio's buffers. */ static sector_t folio_init_buffers(struct folio *folio, - struct block_device *bdev, sector_t block, int size) + struct file *f_bdev, sector_t block, int size) { struct buffer_head *head = folio_buffers(folio); struct buffer_head *bh = head; bool uptodate = folio_test_uptodate(folio); - sector_t end_block = blkdev_max_block(bdev, size); + sector_t end_block = blkdev_max_block(F_BDEV(f_bdev), size); do { if (!buffer_mapped(bh)) { bh->b_end_io = NULL; bh->b_private = NULL; - bh->b_bdev = bdev; + bh->b_bdev = F_BDEV(f_bdev); + bh->f_b_bdev = f_bdev; bh->b_blocknr = block; if (uptodate) set_buffer_uptodate(bh); @@ -1029,10 +1030,10 @@ static sector_t folio_init_buffers(struct folio *folio, * This is used purely for blockdev mappings. */ static int -grow_dev_page(struct block_device *bdev, sector_t block, +grow_dev_page(struct file *f_bdev, sector_t block, pgoff_t index, int size, int sizebits, gfp_t gfp) { - struct inode *inode = bdev->bd_inode; + struct inode *inode = bdev_file_inode(f_bdev); struct folio *folio; struct buffer_head *bh; sector_t end_block; @@ -1046,7 +1047,7 @@ grow_dev_page(struct block_device *bdev, sector_t block, bh = folio_buffers(folio); if (bh) { if (bh->b_size == size) { - end_block = folio_init_buffers(folio, bdev, + end_block = folio_init_buffers(folio, f_bdev, (sector_t)index << sizebits, size); goto done; } @@ -1066,7 +1067,7 @@ grow_dev_page(struct block_device *bdev, sector_t block, */ spin_lock(&inode->i_mapping->i_private_lock); link_dev_buffers(folio, bh); - end_block = folio_init_buffers(folio, bdev, + end_block = folio_init_buffers(folio, f_bdev, (sector_t)index << sizebits, size); spin_unlock(&inode->i_mapping->i_private_lock); done: @@ -1082,7 +1083,7 @@ grow_dev_page(struct block_device *bdev, sector_t block, * that page was dirty, the buffers are set dirty also. */ static int -grow_buffers(struct block_device *bdev, sector_t block, int size, gfp_t gfp) +grow_buffers(struct file *f_bdev, sector_t block, int size, gfp_t gfp) { pgoff_t index; int sizebits; @@ -1098,25 +1099,25 @@ grow_buffers(struct block_device *bdev, sector_t block, int size, gfp_t gfp) printk(KERN_ERR "%s: requested out-of-range block %llu for " "device %pg\n", __func__, (unsigned long long)block, - bdev); + F_BDEV(f_bdev)); return -EIO; } /* Create a page with the proper size buffers.. */ - return grow_dev_page(bdev, block, index, size, sizebits, gfp); + return grow_dev_page(f_bdev, block, index, size, sizebits, gfp); } static struct buffer_head * -__getblk_slow(struct block_device *bdev, sector_t block, +__getblk_slow(struct file *f_bdev, sector_t block, unsigned size, gfp_t gfp) { /* Size must be multiple of hard sectorsize */ - if (unlikely(size & (bdev_logical_block_size(bdev)-1) || + if (unlikely(size & (bdev_logical_block_size(F_BDEV(f_bdev))-1) || (size < 512 || size > PAGE_SIZE))) { printk(KERN_ERR "getblk(): invalid block size %d requested\n", size); printk(KERN_ERR "logical block size: %d\n", - bdev_logical_block_size(bdev)); + bdev_logical_block_size(F_BDEV(f_bdev))); dump_stack(); return NULL; @@ -1126,11 +1127,11 @@ __getblk_slow(struct block_device *bdev, sector_t block, struct buffer_head *bh; int ret; - bh = __find_get_block(bdev, block, size); + bh = __find_get_block(f_bdev, block, size); if (bh) return bh; - ret = grow_buffers(bdev, block, size, gfp); + ret = grow_buffers(f_bdev, block, size, gfp); if (ret < 0) return NULL; } @@ -1392,13 +1393,13 @@ lookup_bh_lru(struct block_device *bdev, sector_t block, unsigned size) * NULL */ struct buffer_head * -__find_get_block(struct block_device *bdev, sector_t block, unsigned size) +__find_get_block(struct file *f_bdev, sector_t block, unsigned size) { - struct buffer_head *bh = lookup_bh_lru(bdev, block, size); + struct buffer_head *bh = lookup_bh_lru(F_BDEV(f_bdev), block, size); if (bh == NULL) { /* __find_get_block_slow will mark the page accessed */ - bh = __find_get_block_slow(bdev, block); + bh = __find_get_block_slow(f_bdev, block); if (bh) bh_lru_install(bh); } else @@ -1417,25 +1418,25 @@ EXPORT_SYMBOL(__find_get_block); * * Return: The buffer head, or NULL if memory could not be allocated. */ -struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block, +struct buffer_head *bdev_getblk(struct file *f_bdev, sector_t block, unsigned size, gfp_t gfp) { - struct buffer_head *bh = __find_get_block(bdev, block, size); + struct buffer_head *bh = __find_get_block(f_bdev, block, size); might_alloc(gfp); if (bh) return bh; - return __getblk_slow(bdev, block, size, gfp); + return __getblk_slow(f_bdev, block, size, gfp); } EXPORT_SYMBOL(bdev_getblk); /* * Do async read-ahead on a buffer.. */ -void __breadahead(struct block_device *bdev, sector_t block, unsigned size) +void __breadahead(struct file *f_bdev, sector_t block, unsigned size) { - struct buffer_head *bh = bdev_getblk(bdev, block, size, + struct buffer_head *bh = bdev_getblk(f_bdev, block, size, GFP_NOWAIT | __GFP_MOVABLE); if (likely(bh)) { @@ -1458,12 +1459,12 @@ EXPORT_SYMBOL(__breadahead); * It returns NULL if the block was unreadable. */ struct buffer_head * -__bread_gfp(struct block_device *bdev, sector_t block, +__bread_gfp(struct file *f_bdev, sector_t block, unsigned size, gfp_t gfp) { struct buffer_head *bh; - gfp |= mapping_gfp_constraint(bdev->bd_inode->i_mapping, ~__GFP_FS); + gfp |= mapping_gfp_constraint(bdev_file_inode(f_bdev)->i_mapping, ~__GFP_FS); /* * Prefer looping in the allocator rather than here, at least that @@ -1471,7 +1472,7 @@ __bread_gfp(struct block_device *bdev, sector_t block, */ gfp |= __GFP_NOFAIL; - bh = bdev_getblk(bdev, block, size, gfp); + bh = bdev_getblk(f_bdev, block, size, gfp); if (likely(bh) && !buffer_uptodate(bh)) bh = __bread_slow(bh); @@ -1565,6 +1566,7 @@ static void discard_buffer(struct buffer_head * bh) lock_buffer(bh); clear_buffer_dirty(bh); bh->b_bdev = NULL; + bh->f_b_bdev = NULL; b_state = READ_ONCE(bh->b_state); do { } while (!try_cmpxchg(&bh->b_state, &b_state, @@ -1694,9 +1696,9 @@ EXPORT_SYMBOL(create_empty_buffers); * I/O in bforget() - it's more efficient to wait on the I/O only if we really * need to. That happens here. */ -void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len) +void clean_bdev_aliases(struct file *f_bdev, sector_t block, sector_t len) { - struct inode *bd_inode = bdev->bd_inode; + struct inode *bd_inode = bdev_file_inode(f_bdev); struct address_space *bd_mapping = bd_inode->i_mapping; struct folio_batch fbatch; pgoff_t index = block >> (PAGE_SHIFT - bd_inode->i_blkbits); @@ -2017,6 +2019,7 @@ iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh, loff_t offset = block << inode->i_blkbits; bh->b_bdev = iomap->bdev; + bh->f_b_bdev = iomap->f_bdev; /* * Block points to offset in file we need to map, iomap contains diff --git a/fs/direct-io.c b/fs/direct-io.c index 60456263a338..7ee66552bddc 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -946,7 +946,7 @@ static int do_direct_IO(struct dio *dio, struct dio_submit *sdio, map_bh->b_blocknr << sdio->blkfactor; if (buffer_new(map_bh)) { clean_bdev_aliases( - map_bh->b_bdev, + map_bh->f_b_bdev, map_bh->b_blocknr, map_bh->b_size >> i_blkbits); } diff --git a/fs/erofs/data.c b/fs/erofs/data.c index fed9153f2b83..a7cdec57e226 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -204,6 +204,7 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map) int id; map->m_bdev = sb->s_bdev; + map->f_m_bdev = sb->s_f_bdev; map->m_daxdev = EROFS_SB(sb)->dax_dev; map->m_dax_part_off = EROFS_SB(sb)->dax_part_off; map->m_fscache = EROFS_SB(sb)->s_fscache; @@ -275,10 +276,12 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, return ret; iomap->offset = map.m_la; - if (flags & IOMAP_DAX) + if (flags & IOMAP_DAX) { iomap->dax_dev = mdev.m_daxdev; - else + } else { iomap->bdev = mdev.m_bdev; + iomap->f_bdev = mdev.f_m_bdev; + } iomap->length = map.m_llen; iomap->flags = 0; iomap->private = NULL; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 8ad8957de64c..2c55d7a7b79d 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -377,6 +377,7 @@ enum { struct erofs_map_dev { struct erofs_fscache *m_fscache; + struct file *f_m_bdev; struct block_device *m_bdev; struct dax_device *m_daxdev; u64 m_dax_part_off; diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 7b55111fd533..90f6fb155400 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -741,6 +741,7 @@ static int z_erofs_iomap_begin_report(struct inode *inode, loff_t offset, return ret; iomap->bdev = inode->i_sb->s_bdev; + iomap->f_bdev = inode->i_sb->s_f_bdev; iomap->offset = map.m_la; iomap->length = map.m_llen; if (map.m_flags & EROFS_MAP_MAPPED) { diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index 464faf6c217e..f92cd53a1b5c 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -744,7 +744,7 @@ static int ext2_get_blocks(struct inode *inode, * We must unmap blocks before zeroing so that writeback cannot * overwrite zeros with stale data from block device page cache. */ - clean_bdev_aliases(inode->i_sb->s_bdev, + clean_bdev_aliases(inode->i_sb->s_f_bdev, le32_to_cpu(chain[depth-1].key), count); /* @@ -839,10 +839,12 @@ static int ext2_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->flags = 0; iomap->offset = (u64)first_block << blkbits; - if (flags & IOMAP_DAX) + if (flags & IOMAP_DAX) { iomap->dax_dev = sbi->s_daxdev; - else + } else { iomap->bdev = inode->i_sb->s_bdev; + iomap->f_bdev = inode->i_sb->s_f_bdev; + } if (ret == 0) { /* diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 0558c8c986d4..6685801dde6f 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3237,10 +3237,12 @@ static void ext4_set_iomap(struct inode *inode, struct iomap *iomap, if (map->m_flags & EXT4_MAP_NEW) iomap->flags |= IOMAP_F_NEW; - if (flags & IOMAP_DAX) + if (flags & IOMAP_DAX) { iomap->dax_dev = EXT4_SB(inode->i_sb)->s_daxdev; - else + } else { iomap->bdev = inode->i_sb->s_bdev; + iomap->f_bdev = inode->i_sb->s_f_bdev; + } iomap->offset = (u64) map->m_lblk << blkbits; iomap->length = (u64) map->m_len << blkbits; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 40387ba598f4..97fa9f36c1dd 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -261,7 +261,7 @@ struct buffer_head *ext4_sb_bread_unmovable(struct super_block *sb, void ext4_sb_breadahead_unmovable(struct super_block *sb, sector_t block) { - struct buffer_head *bh = bdev_getblk(F_BDEV(sb->s_f_bdev), block, + struct buffer_head *bh = bdev_getblk(sb->s_f_bdev, block, sb->s_blocksize, GFP_NOWAIT | __GFP_NOWARN); if (likely(bh)) { @@ -5887,7 +5887,7 @@ static struct file *ext4_get_journal_blkdev(struct super_block *sb, sb_block = EXT4_MIN_BLOCK_SIZE / blocksize; offset = EXT4_MIN_BLOCK_SIZE % blocksize; set_blocksize(bdev, blocksize); - bh = __bread(bdev, sb_block, blocksize); + bh = __bread(f_bdev, sb_block, blocksize); if (!bh) { ext4_msg(sb, KERN_ERR, "couldn't read superblock of " "external journal"); @@ -5943,7 +5943,7 @@ static journal_t *ext4_open_dev_journal(struct super_block *sb, if (IS_ERR(f_bdev)) return ERR_CAST(f_bdev); - journal = jbd2_journal_init_dev(F_BDEV(f_bdev), F_BDEV(sb->s_f_bdev), j_start, + journal = jbd2_journal_init_dev(f_bdev, sb->s_f_bdev, j_start, j_len, sb->s_blocksize); if (IS_ERR(journal)) { ext4_msg(sb, KERN_ERR, "failed to create device journal"); diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 4e42b5f24deb..dee05c392f88 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1615,6 +1615,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag) goto out; map->m_bdev = inode->i_sb->s_bdev; + map->f_m_bdev = inode->i_sb->s_f_bdev; map->m_multidev_dio = f2fs_allow_multi_device_dio(F2FS_I_SB(inode), flag); @@ -1733,8 +1734,10 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag) map->m_pblk = blkaddr; map->m_len = 1; - if (map->m_multidev_dio) + if (map->m_multidev_dio) { map->m_bdev = FDEV(bidx).bdev; + map->f_m_bdev = FDEV(bidx).f_bdev; + } } else if ((map->m_pblk != NEW_ADDR && blkaddr == (map->m_pblk + ofs)) || (map->m_pblk == NEW_ADDR && blkaddr == NEW_ADDR) || @@ -4263,6 +4266,7 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->type = IOMAP_MAPPED; iomap->flags |= IOMAP_F_MERGED; iomap->bdev = map.m_bdev; + iomap->f_bdev = map.f_m_bdev; iomap->addr = blks_to_bytes(inode, map.m_pblk); } else { if (flags & IOMAP_WRITE) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 9a73eed3b424..831d3f43a157 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -684,6 +684,7 @@ struct extent_tree_info { F2FS_MAP_DELALLOC) struct f2fs_map_blocks { + struct file *f_m_bdev; /* for multi-device dio */ struct block_device *m_bdev; /* for multi-device dio */ block_t m_pblk; block_t m_lblk; diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c index 12ef91d170bb..44ad0468e1da 100644 --- a/fs/fuse/dax.c +++ b/fs/fuse/dax.c @@ -576,6 +576,7 @@ static int fuse_iomap_begin(struct inode *inode, loff_t pos, loff_t length, iomap->offset = pos; iomap->flags = 0; iomap->bdev = NULL; + iomap->f_bdev = NULL; iomap->dax_dev = fc->dax->dev; /* diff --git a/fs/gfs2/aops.c b/fs/gfs2/aops.c index 9611bfceda4b..6b327f6589b5 100644 --- a/fs/gfs2/aops.c +++ b/fs/gfs2/aops.c @@ -626,6 +626,7 @@ static void gfs2_discard(struct gfs2_sbd *sdp, struct buffer_head *bh) } } bh->b_bdev = NULL; + bh->f_b_bdev = NULL; clear_buffer_mapped(bh); clear_buffer_req(bh); clear_buffer_new(bh); diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index d9ccfd27e4f1..eaf6346ee602 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -927,6 +927,7 @@ static int __gfs2_iomap_get(struct inode *inode, loff_t pos, loff_t length, out: iomap->bdev = inode->i_sb->s_bdev; + iomap->f_bdev = inode->i_sb->s_f_bdev; unlock: up_read(&ip->i_rw_mutex); return ret; diff --git a/fs/hpfs/file.c b/fs/hpfs/file.c index 1bb8d97cd9ae..a4d16f72c0de 100644 --- a/fs/hpfs/file.c +++ b/fs/hpfs/file.c @@ -129,6 +129,7 @@ static int hpfs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, return -EINVAL; iomap->bdev = inode->i_sb->s_bdev; + iomap->f_bdev = inode->i_sb->s_f_bdev; iomap->offset = offset; hpfs_lock(sb); diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index 5e122586e06e..2a0d8c8cc94d 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c @@ -1015,6 +1015,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) clear_buffer_new(bh); clear_buffer_req(bh); bh->b_bdev = NULL; + bh->f_b_bdev = NULL; } } diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 206cb53ef2b0..4f5165ba7ff1 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -435,6 +435,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction, folio_set_bh(new_bh, new_folio, new_offset); new_bh->b_size = bh_in->b_size; new_bh->b_bdev = journal->j_dev; + new_bh->f_b_bdev = journal->f_j_dev; new_bh->b_blocknr = blocknr; new_bh->b_private = bh_in; set_buffer_mapped(new_bh); @@ -880,7 +881,7 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out) if (ret) return ret; - bh = __getblk(journal->j_dev, pblock, journal->j_blocksize); + bh = __getblk(journal->f_j_dev, pblock, journal->j_blocksize); if (!bh) return -ENOMEM; @@ -1007,7 +1008,7 @@ jbd2_journal_get_descriptor_buffer(transaction_t *transaction, int type) if (err) return NULL; - bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize); + bh = __getblk(journal->f_j_dev, blocknr, journal->j_blocksize); if (!bh) return NULL; atomic_dec(&transaction->t_outstanding_credits); @@ -1461,7 +1462,7 @@ static int journal_load_superblock(journal_t *journal) struct buffer_head *bh; journal_superblock_t *sb; - bh = getblk_unmovable(journal->j_dev, journal->j_blk_offset, + bh = getblk_unmovable(journal->f_j_dev, journal->j_blk_offset, journal->j_blocksize); if (bh) err = bh_read(bh, 0); @@ -1516,11 +1517,12 @@ static int journal_load_superblock(journal_t *journal) * very few fields yet: that has to wait until we have created the * journal structures from from scratch, or loaded them from disk. */ -static journal_t *journal_init_common(struct block_device *bdev, - struct block_device *fs_dev, +static journal_t *journal_init_common(struct file *f_bdev, + struct file *fs_dev, unsigned long long start, int len, int blocksize) { static struct lock_class_key jbd2_trans_commit_key; + struct block_device *bdev = F_BDEV(f_bdev); journal_t *journal; int err; int n; @@ -1530,8 +1532,10 @@ static journal_t *journal_init_common(struct block_device *bdev, return ERR_PTR(-ENOMEM); journal->j_blocksize = blocksize; - journal->j_dev = bdev; - journal->j_fs_dev = fs_dev; + journal->f_j_dev = f_bdev; + journal->f_j_fs_dev = fs_dev; + journal->j_dev = F_BDEV(f_bdev); + journal->j_fs_dev = F_BDEV(fs_dev); journal->j_blk_offset = start; journal->j_total_len = len; @@ -1639,13 +1643,13 @@ static journal_t *journal_init_common(struct block_device *bdev, * range of blocks on an arbitrary block device. * */ -journal_t *jbd2_journal_init_dev(struct block_device *bdev, - struct block_device *fs_dev, +journal_t *jbd2_journal_init_dev(struct file *f_bdev, + struct file *fs_dev, unsigned long long start, int len, int blocksize) { journal_t *journal; - journal = journal_init_common(bdev, fs_dev, start, len, blocksize); + journal = journal_init_common(f_bdev, fs_dev, start, len, blocksize); if (IS_ERR(journal)) return ERR_CAST(journal); @@ -1682,7 +1686,7 @@ journal_t *jbd2_journal_init_inode(struct inode *inode) inode->i_sb->s_id, inode->i_ino, (long long) inode->i_size, inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize); - journal = journal_init_common(inode->i_sb->s_bdev, inode->i_sb->s_bdev, + journal = journal_init_common(inode->i_sb->s_f_bdev, inode->i_sb->s_f_bdev, blocknr, inode->i_size >> inode->i_sb->s_blocksize_bits, inode->i_sb->s_blocksize); if (IS_ERR(journal)) diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c index 01f744cb97a4..6a2edc91b378 100644 --- a/fs/jbd2/recovery.c +++ b/fs/jbd2/recovery.c @@ -92,7 +92,7 @@ static int do_readahead(journal_t *journal, unsigned int start) goto failed; } - bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize); + bh = __getblk(journal->f_j_dev, blocknr, journal->j_blocksize); if (!bh) { err = -ENOMEM; goto failed; @@ -148,7 +148,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal, return err; } - bh = __getblk(journal->j_dev, blocknr, journal->j_blocksize); + bh = __getblk(journal->f_j_dev, blocknr, journal->j_blocksize); if (!bh) return -ENOMEM; @@ -677,7 +677,7 @@ static int do_one_pass(journal_t *journal, /* Find a buffer for the new * data being restored */ - nbh = __getblk(journal->j_fs_dev, + nbh = __getblk(journal->f_j_fs_dev, blocknr, journal->j_blocksize); if (nbh == NULL) { diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c index 4556e4689024..8d21b2995ff8 100644 --- a/fs/jbd2/revoke.c +++ b/fs/jbd2/revoke.c @@ -328,7 +328,6 @@ int jbd2_journal_revoke(handle_t *handle, unsigned long long blocknr, { struct buffer_head *bh = NULL; journal_t *journal; - struct block_device *bdev; int err; might_sleep(); @@ -341,11 +340,10 @@ int jbd2_journal_revoke(handle_t *handle, unsigned long long blocknr, return -EINVAL; } - bdev = journal->j_fs_dev; bh = bh_in; if (!bh) { - bh = __find_get_block(bdev, blocknr, journal->j_blocksize); + bh = __find_get_block(journal->f_j_fs_dev, blocknr, journal->j_blocksize); if (bh) BUFFER_TRACE(bh, "found on hash"); } @@ -355,7 +353,7 @@ int jbd2_journal_revoke(handle_t *handle, unsigned long long blocknr, /* If there is a different buffer_head lying around in * memory anywhere... */ - bh2 = __find_get_block(bdev, blocknr, journal->j_blocksize); + bh2 = __find_get_block(journal->f_j_fs_dev, blocknr, journal->j_blocksize); if (bh2) { /* ... and it has RevokeValid status... */ if (bh2 != bh && buffer_revokevalid(bh2)) @@ -466,7 +464,7 @@ int jbd2_journal_cancel_revoke(handle_t *handle, struct journal_head *jh) * state machine will get very upset later on. */ if (need_cancel) { struct buffer_head *bh2; - bh2 = __find_get_block(bh->b_bdev, bh->b_blocknr, bh->b_size); + bh2 = __find_get_block(bh->f_b_bdev, bh->b_blocknr, bh->b_size); if (bh2) { if (bh2 != bh) clear_buffer_revoked(bh2); @@ -495,7 +493,7 @@ void jbd2_clear_buffer_revoked_flags(journal_t *journal) struct jbd2_revoke_record_s *record; struct buffer_head *bh; record = (struct jbd2_revoke_record_s *)list_entry; - bh = __find_get_block(journal->j_fs_dev, + bh = __find_get_block(journal->f_j_fs_dev, record->blocknr, journal->j_blocksize); if (bh) { diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index 5f08b5fd105a..b7309b894c91 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -2415,6 +2415,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh, clear_buffer_delay(bh); clear_buffer_unwritten(bh); bh->b_bdev = NULL; + bh->f_b_bdev = NULL; return may_free; } diff --git a/fs/mpage.c b/fs/mpage.c index ffb064ed9d04..f526ad5a8386 100644 --- a/fs/mpage.c +++ b/fs/mpage.c @@ -483,6 +483,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, int boundary = 0; sector_t boundary_block = 0; struct block_device *boundary_bdev = NULL; + struct file *f_boundary_bdev = NULL; size_t length; struct buffer_head map_bh; loff_t i_size = i_size_read(inode); @@ -522,6 +523,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, if (boundary) { boundary_block = bh->b_blocknr; boundary_bdev = bh->b_bdev; + f_boundary_bdev = bh->f_b_bdev; } bdev = bh->b_bdev; } while ((bh = bh->b_this_page) != head); @@ -564,6 +566,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, if (buffer_boundary(&map_bh)) { boundary_block = map_bh.b_blocknr; boundary_bdev = map_bh.b_bdev; + f_boundary_bdev = map_bh.f_b_bdev; } if (page_block) { if (map_bh.b_blocknr != blocks[page_block-1] + 1) @@ -633,7 +636,7 @@ static int __mpage_writepage(struct folio *folio, struct writeback_control *wbc, if (boundary || (first_unmapped != blocks_per_page)) { bio = mpage_bio_submit_write(bio); if (boundary_block) { - write_boundary_block(boundary_bdev, + write_boundary_block(f_boundary_bdev, boundary_block, 1 << blkbits); } } else { diff --git a/fs/nilfs2/btnode.c b/fs/nilfs2/btnode.c index 5710833ac1cc..9c6314e5cd7a 100644 --- a/fs/nilfs2/btnode.c +++ b/fs/nilfs2/btnode.c @@ -60,6 +60,7 @@ nilfs_btnode_create_block(struct address_space *btnc, __u64 blocknr) } memset(bh->b_data, 0, i_blocksize(inode)); bh->b_bdev = inode->i_sb->s_bdev; + bh->f_b_bdev = inode->i_sb->f_s_bdev; bh->b_blocknr = blocknr; set_buffer_mapped(bh); set_buffer_uptodate(bh); @@ -119,6 +120,7 @@ int nilfs_btnode_submit_block(struct address_space *btnc, __u64 blocknr, } set_buffer_mapped(bh); bh->b_bdev = inode->i_sb->s_bdev; + bh->f_b_bdev = inode->i_sb->f_s_bdev; bh->b_blocknr = pblocknr; /* set block address for read */ bh->b_end_io = end_buffer_read_sync; get_bh(bh); diff --git a/fs/nilfs2/gcinode.c b/fs/nilfs2/gcinode.c index 8beb2730929d..f15f3b012d92 100644 --- a/fs/nilfs2/gcinode.c +++ b/fs/nilfs2/gcinode.c @@ -85,6 +85,7 @@ int nilfs_gccache_submit_read_data(struct inode *inode, sector_t blkoff, if (!buffer_mapped(bh)) { bh->b_bdev = inode->i_sb->s_bdev; + bh->f_b_bdev = inode->i_sb->f_s_bdev; set_buffer_mapped(bh); } bh->b_blocknr = pbn; diff --git a/fs/nilfs2/mdt.c b/fs/nilfs2/mdt.c index c97c77a39668..a7205ca74937 100644 --- a/fs/nilfs2/mdt.c +++ b/fs/nilfs2/mdt.c @@ -90,6 +90,7 @@ static int nilfs_mdt_create_block(struct inode *inode, unsigned long block, goto failed_bh; bh->b_bdev = sb->s_bdev; + bh->f_b_bdev = sb->f_s_bdev; err = nilfs_mdt_insert_new_block(inode, block, bh, init_block); if (likely(!err)) { get_bh(bh); diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c index 06b04758f289..5809cfc99781 100644 --- a/fs/nilfs2/page.c +++ b/fs/nilfs2/page.c @@ -112,6 +112,7 @@ void nilfs_copy_buffer(struct buffer_head *dbh, struct buffer_head *sbh) dbh->b_state = sbh->b_state & NILFS_BUFFER_INHERENT_BITS; dbh->b_blocknr = sbh->b_blocknr; dbh->b_bdev = sbh->b_bdev; + dbh->f_b_bdev = sbh->f_b_bdev; bh = dbh; bits = sbh->b_state & (BIT(BH_Uptodate) | BIT(BH_Mapped)); @@ -216,6 +217,7 @@ static void nilfs_copy_folio(struct folio *dst, struct folio *src, dbh->b_state = sbh->b_state & mask; dbh->b_blocknr = sbh->b_blocknr; dbh->b_bdev = sbh->b_bdev; + dbh->f_b_bdev = sbh->f_b_bdev; sbh = sbh->b_this_page; dbh = dbh->b_this_page; } while (dbh != dbufs); diff --git a/fs/nilfs2/recovery.c b/fs/nilfs2/recovery.c index 0955b657938f..cbd30496fca2 100644 --- a/fs/nilfs2/recovery.c +++ b/fs/nilfs2/recovery.c @@ -107,7 +107,7 @@ static int nilfs_compute_checksum(struct the_nilfs *nilfs, do { struct buffer_head *bh; - bh = __bread(nilfs->ns_bdev, ++start, blocksize); + bh = __bread(nilfs->ns_f_bdev, ++start, blocksize); if (!bh) return -EIO; check_bytes -= size; @@ -136,7 +136,7 @@ int nilfs_read_super_root_block(struct the_nilfs *nilfs, sector_t sr_block, int ret; *pbh = NULL; - bh_sr = __bread(nilfs->ns_bdev, sr_block, nilfs->ns_blocksize); + bh_sr = __bread(nilfs->ns_f_bdev, sr_block, nilfs->ns_blocksize); if (unlikely(!bh_sr)) { ret = NILFS_SEG_FAIL_IO; goto failed; @@ -183,7 +183,7 @@ nilfs_read_log_header(struct the_nilfs *nilfs, sector_t start_blocknr, { struct buffer_head *bh_sum; - bh_sum = __bread(nilfs->ns_bdev, start_blocknr, nilfs->ns_blocksize); + bh_sum = __bread(nilfs->ns_f_bdev, start_blocknr, nilfs->ns_blocksize); if (bh_sum) *sum = (struct nilfs_segment_summary *)bh_sum->b_data; return bh_sum; @@ -250,7 +250,7 @@ static void *nilfs_read_summary_info(struct the_nilfs *nilfs, if (bytes > (*pbh)->b_size - *offset) { blocknr = (*pbh)->b_blocknr; brelse(*pbh); - *pbh = __bread(nilfs->ns_bdev, blocknr + 1, + *pbh = __bread(nilfs->ns_f_bdev, blocknr + 1, nilfs->ns_blocksize); if (unlikely(!*pbh)) return NULL; @@ -289,7 +289,7 @@ static void nilfs_skip_summary_info(struct the_nilfs *nilfs, *offset = bytes * (count - (bcnt - 1) * nitem_per_block); brelse(*pbh); - *pbh = __bread(nilfs->ns_bdev, blocknr + bcnt, + *pbh = __bread(nilfs->ns_f_bdev, blocknr + bcnt, nilfs->ns_blocksize); } } @@ -318,7 +318,7 @@ static int nilfs_scan_dsync_log(struct the_nilfs *nilfs, sector_t start_blocknr, sumbytes = le32_to_cpu(sum->ss_sumbytes); blocknr = start_blocknr + DIV_ROUND_UP(sumbytes, nilfs->ns_blocksize); - bh = __bread(nilfs->ns_bdev, start_blocknr, nilfs->ns_blocksize); + bh = __bread(nilfs->ns_f_bdev, start_blocknr, nilfs->ns_blocksize); if (unlikely(!bh)) goto out; @@ -477,7 +477,7 @@ static int nilfs_recovery_copy_block(struct the_nilfs *nilfs, struct buffer_head *bh_org; void *kaddr; - bh_org = __bread(nilfs->ns_bdev, rb->blocknr, nilfs->ns_blocksize); + bh_org = __bread(nilfs->ns_f_bdev, rb->blocknr, nilfs->ns_blocksize); if (unlikely(!bh_org)) return -EIO; @@ -696,7 +696,7 @@ static void nilfs_finish_roll_forward(struct the_nilfs *nilfs, nilfs_get_segnum_of_block(nilfs, ri->ri_super_root)) return; - bh = __getblk(nilfs->ns_bdev, ri->ri_lsegs_start, nilfs->ns_blocksize); + bh = __getblk(nilfs->ns_f_bdev, ri->ri_lsegs_start, nilfs->ns_blocksize); BUG_ON(!bh); memset(bh->b_data, 0, bh->b_size); set_buffer_dirty(bh); @@ -822,7 +822,7 @@ int nilfs_search_super_root(struct the_nilfs *nilfs, /* Read ahead segment */ b = seg_start; while (b <= seg_end) - __breadahead(nilfs->ns_bdev, b++, nilfs->ns_blocksize); + __breadahead(nilfs->ns_f_bdev, b++, nilfs->ns_blocksize); for (;;) { brelse(bh_sum); @@ -868,7 +868,7 @@ int nilfs_search_super_root(struct the_nilfs *nilfs, if (pseg_start == seg_start) { nilfs_get_segment_range(nilfs, nextnum, &b, &end); while (b <= end) - __breadahead(nilfs->ns_bdev, b++, + __breadahead(nilfs->ns_f_bdev, b++, nilfs->ns_blocksize); } if (!(flags & NILFS_SS_SR)) { diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c index 71400496ed36..6908dd87f44c 100644 --- a/fs/nilfs2/the_nilfs.c +++ b/fs/nilfs2/the_nilfs.c @@ -63,6 +63,7 @@ struct the_nilfs *alloc_nilfs(struct super_block *sb) nilfs->ns_sb = sb; nilfs->ns_bdev = sb->s_bdev; + nilfs->ns_f_bdev = sb->s_f_bdev; atomic_set(&nilfs->ns_ndirtyblks, 0); init_rwsem(&nilfs->ns_sem); mutex_init(&nilfs->ns_snapshot_mount_mutex); diff --git a/fs/ntfs/aops.c b/fs/ntfs/aops.c index 548f3b51aa5f..cc31e38479ac 100644 --- a/fs/ntfs/aops.c +++ b/fs/ntfs/aops.c @@ -228,6 +228,7 @@ static int ntfs_read_block(struct folio *folio) continue; } bh->b_bdev = vol->sb->s_bdev; + bh->f_b_bdev = vol->sb->s_f_bdev; /* Is the block within the allowed limits? */ if (iblock < lblock) { bool is_retry = false; @@ -679,6 +680,7 @@ static int ntfs_write_block(struct folio *folio, struct writeback_control *wbc) /* Unmapped, dirty buffer. Need to map it. */ bh->b_bdev = vol->sb->s_bdev; + bh->f_b_bdev = vol->sb->s_f_bdev; /* Convert block into corresponding vcn and offset. */ vcn = (VCN)block << blocksize_bits; @@ -989,6 +991,7 @@ static int ntfs_write_mst_block(struct page *page, unsigned int vcn_ofs; bh->b_bdev = vol->sb->s_bdev; + bh->f_b_bdev = vol->sb->s_f_bdev; /* Obtain the vcn and offset of the current block. */ vcn = (VCN)block << bh_size_bits; vcn_ofs = vcn & vol->cluster_size_mask; diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c index 297c0b9db621..e3f35d1550ed 100644 --- a/fs/ntfs/file.c +++ b/fs/ntfs/file.c @@ -681,6 +681,7 @@ static int ntfs_prepare_pages_for_non_resident_write(struct page **pages, } /* Unmapped buffer. Need to map it. */ bh->b_bdev = vol->sb->s_bdev; + bh->f_b_bdev = vol->sb->s_f_bdev; /* * If the current buffer is in the same clusters as the map * cache, there is no need to check the runlist again. The diff --git a/fs/ntfs/mft.c b/fs/ntfs/mft.c index 6fd1dc4b08c8..9193f2516d06 100644 --- a/fs/ntfs/mft.c +++ b/fs/ntfs/mft.c @@ -527,6 +527,7 @@ int ntfs_sync_mft_mirror(ntfs_volume *vol, const unsigned long mft_no, unsigned int vcn_ofs; bh->b_bdev = vol->sb->s_bdev; + bh->f_b_bdev = vol->sb->s_f_bdev; /* Obtain the vcn and offset of the current block. */ vcn = ((VCN)mft_no << vol->mft_record_size_bits) + (block_start - m_start); @@ -720,6 +721,7 @@ int write_mft_record_nolock(ntfs_inode *ni, MFT_RECORD *m, int sync) unsigned int vcn_ofs; bh->b_bdev = vol->sb->s_bdev; + bh->f_b_bdev = vol->sb->s_f_bdev; /* Obtain the vcn and offset of the current block. */ vcn = ((VCN)ni->mft_no << vol->mft_record_size_bits) + (block_start - m_start); diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index fbfe21dbb425..c58efca1427b 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -1015,7 +1015,7 @@ int ntfs_sb_read(struct super_block *sb, u64 lbo, size_t bytes, void *buffer) u32 op = blocksize - off; for (; bytes; block += 1, off = 0, op = blocksize) { - struct buffer_head *bh = __bread(bdev, block, blocksize); + struct buffer_head *bh = __bread(sb->s_f_bdev, block, blocksize); if (!bh) return -EIO; @@ -1052,14 +1052,14 @@ int ntfs_sb_write(struct super_block *sb, u64 lbo, size_t bytes, op = bytes; if (op < blocksize) { - bh = __bread(bdev, block, blocksize); + bh = __bread(sb->s_f_bdev, block, blocksize); if (!bh) { ntfs_err(sb, "failed to read block %llx", (u64)block); return -EIO; } } else { - bh = __getblk(bdev, block, blocksize); + bh = __getblk(sb->s_f_bdev, block, blocksize); if (!bh) return -ENOMEM; } @@ -2673,4 +2673,4 @@ int ntfs_set_label(struct ntfs_sb_info *sbi, u8 *label, int len) out: __putname(uni); return err; -} \ No newline at end of file +} diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 5e3d71374918..daa8976c137c 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -612,6 +612,7 @@ static noinline int ntfs_get_block_vbo(struct inode *inode, u64 vbo, set_buffer_mapped(bh); bh->b_bdev = sb->s_bdev; + bh->f_b_bdev = sb->s_f_bdev; bh->b_blocknr = lbo >> sb->s_blocksize_bits; valid = ni->i_valid; diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 9153dffde950..f0f969d35b83 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -1632,7 +1632,7 @@ void ntfs_unmap_meta(struct super_block *sb, CLST lcn, CLST len) limit >>= 1; while (blocks--) { - clean_bdev_aliases(bdev, devblock++, 1); + clean_bdev_aliases(sb->s_f_bdev, devblock++, 1); if (cnt++ >= limit) { sync_blockdev(bdev); cnt = 0; diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index 604fea3a26ff..20485bac26d2 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -1209,7 +1209,7 @@ static int ocfs2_force_read_journal(struct inode *inode) } for (i = 0; i < p_blocks; i++, p_blkno++) { - bh = __find_get_block(osb->sb->s_bdev, p_blkno, + bh = __find_get_block(osb->sb->s_f_bdev, p_blkno, osb->sb->s_blocksize); /* block not cached. */ if (!bh) diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index 177ccb4d9bc3..94b2663130c2 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -2315,7 +2315,7 @@ static int journal_read_transaction(struct super_block *sb, * from other places. * Note: Do not use journal_getblk/sb_getblk functions here! */ -static struct buffer_head *reiserfs_breada(struct block_device *dev, +static struct buffer_head *reiserfs_breada(struct file *f_dev, b_blocknr_t block, int bufsize, b_blocknr_t max_block) { @@ -2324,7 +2324,7 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev, struct buffer_head *bh; int i, j; - bh = __getblk(dev, block, bufsize); + bh = __getblk(f_dev, block, bufsize); if (!bh || buffer_uptodate(bh)) return (bh); @@ -2334,7 +2334,7 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev, bhlist[0] = bh; j = 1; for (i = 1; i < blocks; i++) { - bh = __getblk(dev, block + i, bufsize); + bh = __getblk(f_dev, block + i, bufsize); if (!bh) break; if (buffer_uptodate(bh)) { @@ -2447,7 +2447,7 @@ static int journal_read(struct super_block *sb) * device and journal device to be the same */ d_bh = - reiserfs_breada(F_BDEV(journal->j_f_bdev), cur_dblock, + reiserfs_breada(journal->j_f_bdev, cur_dblock, sb->s_blocksize, SB_ONDISK_JOURNAL_1st_BLOCK(sb) + SB_ONDISK_JOURNAL_SIZE(sb)); diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h index ea2f5950e5c6..61f5146e876f 100644 --- a/fs/reiserfs/reiserfs.h +++ b/fs/reiserfs/reiserfs.h @@ -2810,10 +2810,10 @@ struct reiserfs_journal_header { /* We need these to make journal.c code more readable */ #define journal_find_get_block(s, block) __find_get_block(\ - F_BDEV(SB_JOURNAL(s)->j_f_bdev), block, s->s_blocksize) -#define journal_getblk(s, block) __getblk(F_BDEV(SB_JOURNAL(s)->j_f_bdev),\ + SB_JOURNAL(s)->j_f_bdev, block, s->s_blocksize) +#define journal_getblk(s, block) __getblk(SB_JOURNAL(s)->j_f_bdev,\ block, s->s_blocksize) -#define journal_bread(s, block) __bread(F_BDEV(SB_JOURNAL(s)->j_f_bdev),\ +#define journal_bread(s, block) __bread(SB_JOURNAL(s)->j_f_bdev,\ block, s->s_blocksize) enum reiserfs_bh_state_bits { diff --git a/fs/reiserfs/tail_conversion.c b/fs/reiserfs/tail_conversion.c index 2cec61af2a9e..0978a0a73a64 100644 --- a/fs/reiserfs/tail_conversion.c +++ b/fs/reiserfs/tail_conversion.c @@ -188,6 +188,7 @@ void reiserfs_unmap_buffer(struct buffer_head *bh) clear_buffer_req(bh); clear_buffer_new(bh); bh->b_bdev = NULL; + bh->f_b_bdev = NULL; unlock_buffer(bh); } diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 18c8f168b153..e0f38fafc5df 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -122,10 +122,12 @@ xfs_bmbt_to_iomap( } iomap->offset = XFS_FSB_TO_B(mp, imap->br_startoff); iomap->length = XFS_FSB_TO_B(mp, imap->br_blockcount); - if (mapping_flags & IOMAP_DAX) + if (mapping_flags & IOMAP_DAX) { iomap->dax_dev = target->bt_daxdev; - else + } else { iomap->bdev = target->bt_bdev; + iomap->f_bdev = target->bt_f_bdev; + } iomap->flags = iomap_flags; if (xfs_ipincount(ip) && @@ -151,6 +153,7 @@ xfs_hole_to_iomap( iomap->offset = XFS_FSB_TO_B(ip->i_mount, offset_fsb); iomap->length = XFS_FSB_TO_B(ip->i_mount, end_fsb - offset_fsb); iomap->bdev = target->bt_bdev; + iomap->f_bdev = target->bt_f_bdev; iomap->dax_dev = target->bt_daxdev; } diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c index b2c9b35df8f7..2c79506ca7b6 100644 --- a/fs/zonefs/file.c +++ b/fs/zonefs/file.c @@ -39,6 +39,7 @@ static int zonefs_read_iomap_begin(struct inode *inode, loff_t offset, */ mutex_lock(&zi->i_truncate_mutex); iomap->bdev = inode->i_sb->s_bdev; + iomap->f_bdev = inode->i_sb->s_f_bdev; iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize); isize = i_size_read(inode); if (iomap->offset >= isize) { @@ -89,6 +90,7 @@ static int zonefs_write_iomap_begin(struct inode *inode, loff_t offset, */ mutex_lock(&zi->i_truncate_mutex); iomap->bdev = inode->i_sb->s_bdev; + iomap->f_bdev = inode->i_sb->s_f_bdev; iomap->offset = ALIGN_DOWN(offset, sb->s_blocksize); iomap->addr = (z->z_sector << SECTOR_SHIFT) + iomap->offset; isize = i_size_read(inode); diff --git a/include/linux/buffer_head.h b/include/linux/buffer_head.h index 5f23ee599889..61747b88c073 100644 --- a/include/linux/buffer_head.h +++ b/include/linux/buffer_head.h @@ -9,6 +9,7 @@ #define _LINUX_BUFFER_HEAD_H #include +#include #include #include #include @@ -68,6 +69,7 @@ struct buffer_head { size_t b_size; /* size of mapping */ char *b_data; /* pointer to data within the page */ + struct file *f_b_bdev; struct block_device *b_bdev; bh_end_io_t *b_end_io; /* I/O completion */ void *b_private; /* reserved for b_end_io */ @@ -213,24 +215,24 @@ int generic_buffers_fsync_noflush(struct file *file, loff_t start, loff_t end, bool datasync); int generic_buffers_fsync(struct file *file, loff_t start, loff_t end, bool datasync); -void clean_bdev_aliases(struct block_device *bdev, sector_t block, +void clean_bdev_aliases(struct file *f_bdev, sector_t block, sector_t len); static inline void clean_bdev_bh_alias(struct buffer_head *bh) { - clean_bdev_aliases(bh->b_bdev, bh->b_blocknr, 1); + clean_bdev_aliases(bh->f_b_bdev, bh->b_blocknr, 1); } void mark_buffer_async_write(struct buffer_head *bh); void __wait_on_buffer(struct buffer_head *); wait_queue_head_t *bh_waitq_head(struct buffer_head *bh); -struct buffer_head *__find_get_block(struct block_device *bdev, sector_t block, +struct buffer_head *__find_get_block(struct file *f_bdev, sector_t block, unsigned size); -struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block, +struct buffer_head *bdev_getblk(struct file *f_bdev, sector_t block, unsigned size, gfp_t gfp); void __brelse(struct buffer_head *); void __bforget(struct buffer_head *); -void __breadahead(struct block_device *, sector_t block, unsigned int size); -struct buffer_head *__bread_gfp(struct block_device *, +void __breadahead(struct file *, sector_t block, unsigned int size); +struct buffer_head *__bread_gfp(struct file *, sector_t block, unsigned size, gfp_t gfp); struct buffer_head *alloc_buffer_head(gfp_t gfp_flags); void free_buffer_head(struct buffer_head * bh); @@ -240,7 +242,7 @@ int sync_dirty_buffer(struct buffer_head *bh); int __sync_dirty_buffer(struct buffer_head *bh, blk_opf_t op_flags); void write_dirty_buffer(struct buffer_head *bh, blk_opf_t op_flags); void submit_bh(blk_opf_t, struct buffer_head *); -void write_boundary_block(struct block_device *bdev, +void write_boundary_block(struct file *f_bdev, sector_t bblock, unsigned blocksize); int bh_uptodate_or_lock(struct buffer_head *bh); int __bh_read(struct buffer_head *bh, blk_opf_t op_flags, bool wait); @@ -321,59 +323,59 @@ static inline void bforget(struct buffer_head *bh) static inline struct buffer_head * sb_bread(struct super_block *sb, sector_t block) { - return __bread_gfp(sb->s_bdev, block, sb->s_blocksize, __GFP_MOVABLE); + return __bread_gfp(sb->s_f_bdev, block, sb->s_blocksize, __GFP_MOVABLE); } static inline struct buffer_head * sb_bread_unmovable(struct super_block *sb, sector_t block) { - return __bread_gfp(sb->s_bdev, block, sb->s_blocksize, 0); + return __bread_gfp(sb->s_f_bdev, block, sb->s_blocksize, 0); } static inline void sb_breadahead(struct super_block *sb, sector_t block) { - __breadahead(sb->s_bdev, block, sb->s_blocksize); + __breadahead(sb->s_f_bdev, block, sb->s_blocksize); } -static inline struct buffer_head *getblk_unmovable(struct block_device *bdev, +static inline struct buffer_head *getblk_unmovable(struct file *f_bdev, sector_t block, unsigned size) { gfp_t gfp; - gfp = mapping_gfp_constraint(bdev->bd_inode->i_mapping, ~__GFP_FS); + gfp = mapping_gfp_constraint(bdev_file_inode(f_bdev)->i_mapping, ~__GFP_FS); gfp |= __GFP_NOFAIL; - return bdev_getblk(bdev, block, size, gfp); + return bdev_getblk(f_bdev, block, size, gfp); } -static inline struct buffer_head *__getblk(struct block_device *bdev, +static inline struct buffer_head *__getblk(struct file *f_bdev, sector_t block, unsigned size) { gfp_t gfp; - gfp = mapping_gfp_constraint(bdev->bd_inode->i_mapping, ~__GFP_FS); + gfp = mapping_gfp_constraint(bdev_file_inode(f_bdev)->i_mapping, ~__GFP_FS); gfp |= __GFP_MOVABLE | __GFP_NOFAIL; - return bdev_getblk(bdev, block, size, gfp); + return bdev_getblk(f_bdev, block, size, gfp); } static inline struct buffer_head *sb_getblk(struct super_block *sb, sector_t block) { - return __getblk(sb->s_bdev, block, sb->s_blocksize); + return __getblk(sb->s_f_bdev, block, sb->s_blocksize); } static inline struct buffer_head *sb_getblk_gfp(struct super_block *sb, sector_t block, gfp_t gfp) { - return bdev_getblk(sb->s_bdev, block, sb->s_blocksize, gfp); + return bdev_getblk(sb->s_f_bdev, block, sb->s_blocksize, gfp); } static inline struct buffer_head * sb_find_get_block(struct super_block *sb, sector_t block) { - return __find_get_block(sb->s_bdev, block, sb->s_blocksize); + return __find_get_block(sb->s_f_bdev, block, sb->s_blocksize); } static inline void @@ -381,6 +383,7 @@ map_bh(struct buffer_head *bh, struct super_block *sb, sector_t block) { set_buffer_mapped(bh); bh->b_bdev = sb->s_bdev; + bh->f_b_bdev = sb->s_f_bdev; bh->b_blocknr = block; bh->b_size = sb->s_blocksize; } @@ -450,9 +453,9 @@ static inline void bh_readahead_batch(int nr, struct buffer_head *bhs[], * It returns NULL if the block was unreadable. */ static inline struct buffer_head * -__bread(struct block_device *bdev, sector_t block, unsigned size) +__bread(struct file *f_bdev, sector_t block, unsigned size) { - return __bread_gfp(bdev, block, size, __GFP_MOVABLE); + return __bread_gfp(f_bdev, block, size, __GFP_MOVABLE); } /** diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 96dd0acbba44..91f1e434cab3 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -97,6 +97,7 @@ struct iomap { u64 length; /* length of mapping, bytes */ u16 type; /* type of mapping */ u16 flags; /* flags for mapping */ + struct file *f_bdev; struct block_device *bdev; /* block device for I/O */ struct dax_device *dax_dev; /* dax_dev for dax operations */ void *inline_data; diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index beb30719ee16..d357ba510df6 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -972,6 +972,7 @@ struct journal_s * @j_dev: Device where we store the journal. */ struct block_device *j_dev; + struct file *f_j_dev; /** * @j_blocksize: Block size for the location where we store the journal. @@ -997,6 +998,7 @@ struct journal_s * equal to j_dev. */ struct block_device *j_fs_dev; + struct file *f_j_fs_dev; /** * @j_total_len: Total maximum capacity of the journal region on disk. @@ -1537,8 +1539,8 @@ extern void jbd2_journal_unlock_updates (journal_t *); void jbd2_journal_wait_updates(journal_t *); -extern journal_t * jbd2_journal_init_dev(struct block_device *bdev, - struct block_device *fs_dev, +extern journal_t * jbd2_journal_init_dev(struct file *f_bdev, + struct file *fs_dev, unsigned long long start, int len, int bsize); extern journal_t * jbd2_journal_init_inode (struct inode *); extern int jbd2_journal_update_format (journal_t *);