Commit e340dd63 authored by Jan Kara's avatar Jan Kara Committed by Christian Brauner

xfs: Convert to bdev_open_by_path()

Convert xfs to use bdev_open_by_path() and pass the handle around.

CC: "Darrick J. Wong" <djwong@kernel.org>
CC: linux-xfs@vger.kernel.org
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristian Brauner <brauner@kernel.org>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230927093442.25915-28-jack@suse.czAcked-by: default avatar"Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: default avatar"Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent ba1787a5
...@@ -1945,8 +1945,6 @@ void ...@@ -1945,8 +1945,6 @@ void
xfs_free_buftarg( xfs_free_buftarg(
struct xfs_buftarg *btp) struct xfs_buftarg *btp)
{ {
struct block_device *bdev = btp->bt_bdev;
unregister_shrinker(&btp->bt_shrinker); unregister_shrinker(&btp->bt_shrinker);
ASSERT(percpu_counter_sum(&btp->bt_io_count) == 0); ASSERT(percpu_counter_sum(&btp->bt_io_count) == 0);
percpu_counter_destroy(&btp->bt_io_count); percpu_counter_destroy(&btp->bt_io_count);
...@@ -1954,8 +1952,8 @@ xfs_free_buftarg( ...@@ -1954,8 +1952,8 @@ xfs_free_buftarg(
fs_put_dax(btp->bt_daxdev, btp->bt_mount); fs_put_dax(btp->bt_daxdev, btp->bt_mount);
/* the main block device is closed by kill_block_super */ /* the main block device is closed by kill_block_super */
if (bdev != btp->bt_mount->m_super->s_bdev) if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev)
blkdev_put(bdev, btp->bt_mount->m_super); bdev_release(btp->bt_bdev_handle);
kmem_free(btp); kmem_free(btp);
} }
...@@ -1990,16 +1988,15 @@ xfs_setsize_buftarg( ...@@ -1990,16 +1988,15 @@ xfs_setsize_buftarg(
*/ */
STATIC int STATIC int
xfs_setsize_buftarg_early( xfs_setsize_buftarg_early(
xfs_buftarg_t *btp, xfs_buftarg_t *btp)
struct block_device *bdev)
{ {
return xfs_setsize_buftarg(btp, bdev_logical_block_size(bdev)); return xfs_setsize_buftarg(btp, bdev_logical_block_size(btp->bt_bdev));
} }
struct xfs_buftarg * struct xfs_buftarg *
xfs_alloc_buftarg( xfs_alloc_buftarg(
struct xfs_mount *mp, struct xfs_mount *mp,
struct block_device *bdev) struct bdev_handle *bdev_handle)
{ {
xfs_buftarg_t *btp; xfs_buftarg_t *btp;
const struct dax_holder_operations *ops = NULL; const struct dax_holder_operations *ops = NULL;
...@@ -2010,9 +2007,10 @@ xfs_alloc_buftarg( ...@@ -2010,9 +2007,10 @@ xfs_alloc_buftarg(
btp = kmem_zalloc(sizeof(*btp), KM_NOFS); btp = kmem_zalloc(sizeof(*btp), KM_NOFS);
btp->bt_mount = mp; btp->bt_mount = mp;
btp->bt_dev = bdev->bd_dev; btp->bt_bdev_handle = bdev_handle;
btp->bt_bdev = bdev; btp->bt_dev = bdev_handle->bdev->bd_dev;
btp->bt_daxdev = fs_dax_get_by_bdev(bdev, &btp->bt_dax_part_off, btp->bt_bdev = bdev_handle->bdev;
btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off,
mp, ops); mp, ops);
/* /*
...@@ -2022,7 +2020,7 @@ xfs_alloc_buftarg( ...@@ -2022,7 +2020,7 @@ xfs_alloc_buftarg(
ratelimit_state_init(&btp->bt_ioerror_rl, 30 * HZ, ratelimit_state_init(&btp->bt_ioerror_rl, 30 * HZ,
DEFAULT_RATELIMIT_BURST); DEFAULT_RATELIMIT_BURST);
if (xfs_setsize_buftarg_early(btp, bdev)) if (xfs_setsize_buftarg_early(btp))
goto error_free; goto error_free;
if (list_lru_init(&btp->bt_lru)) if (list_lru_init(&btp->bt_lru))
......
...@@ -98,6 +98,7 @@ typedef unsigned int xfs_buf_flags_t; ...@@ -98,6 +98,7 @@ typedef unsigned int xfs_buf_flags_t;
*/ */
typedef struct xfs_buftarg { typedef struct xfs_buftarg {
dev_t bt_dev; dev_t bt_dev;
struct bdev_handle *bt_bdev_handle;
struct block_device *bt_bdev; struct block_device *bt_bdev;
struct dax_device *bt_daxdev; struct dax_device *bt_daxdev;
u64 bt_dax_part_off; u64 bt_dax_part_off;
...@@ -364,7 +365,7 @@ xfs_buf_update_cksum(struct xfs_buf *bp, unsigned long cksum_offset) ...@@ -364,7 +365,7 @@ xfs_buf_update_cksum(struct xfs_buf *bp, unsigned long cksum_offset)
* Handling of buftargs. * Handling of buftargs.
*/ */
struct xfs_buftarg *xfs_alloc_buftarg(struct xfs_mount *mp, struct xfs_buftarg *xfs_alloc_buftarg(struct xfs_mount *mp,
struct block_device *bdev); struct bdev_handle *bdev_handle);
extern void xfs_free_buftarg(struct xfs_buftarg *); extern void xfs_free_buftarg(struct xfs_buftarg *);
extern void xfs_buftarg_wait(struct xfs_buftarg *); extern void xfs_buftarg_wait(struct xfs_buftarg *);
extern void xfs_buftarg_drain(struct xfs_buftarg *); extern void xfs_buftarg_drain(struct xfs_buftarg *);
......
...@@ -361,14 +361,15 @@ STATIC int ...@@ -361,14 +361,15 @@ STATIC int
xfs_blkdev_get( xfs_blkdev_get(
xfs_mount_t *mp, xfs_mount_t *mp,
const char *name, const char *name,
struct block_device **bdevp) struct bdev_handle **handlep)
{ {
int error = 0; int error = 0;
*bdevp = blkdev_get_by_path(name, BLK_OPEN_READ | BLK_OPEN_WRITE, *handlep = bdev_open_by_path(name, BLK_OPEN_READ | BLK_OPEN_WRITE,
mp->m_super, &fs_holder_ops); mp->m_super, &fs_holder_ops);
if (IS_ERR(*bdevp)) { if (IS_ERR(*handlep)) {
error = PTR_ERR(*bdevp); error = PTR_ERR(*handlep);
*handlep = NULL;
xfs_warn(mp, "Invalid device [%s], error=%d", name, error); xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
} }
...@@ -433,7 +434,7 @@ xfs_open_devices( ...@@ -433,7 +434,7 @@ xfs_open_devices(
{ {
struct super_block *sb = mp->m_super; struct super_block *sb = mp->m_super;
struct block_device *ddev = sb->s_bdev; struct block_device *ddev = sb->s_bdev;
struct block_device *logdev = NULL, *rtdev = NULL; struct bdev_handle *logdev_handle = NULL, *rtdev_handle = NULL;
int error; int error;
/* /*
...@@ -446,17 +447,19 @@ xfs_open_devices( ...@@ -446,17 +447,19 @@ xfs_open_devices(
* Open real time and log devices - order is important. * Open real time and log devices - order is important.
*/ */
if (mp->m_logname) { if (mp->m_logname) {
error = xfs_blkdev_get(mp, mp->m_logname, &logdev); error = xfs_blkdev_get(mp, mp->m_logname, &logdev_handle);
if (error) if (error)
goto out_relock; goto out_relock;
} }
if (mp->m_rtname) { if (mp->m_rtname) {
error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev); error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev_handle);
if (error) if (error)
goto out_close_logdev; goto out_close_logdev;
if (rtdev == ddev || rtdev == logdev) { if (rtdev_handle->bdev == ddev ||
(logdev_handle &&
rtdev_handle->bdev == logdev_handle->bdev)) {
xfs_warn(mp, xfs_warn(mp,
"Cannot mount filesystem with identical rtdev and ddev/logdev."); "Cannot mount filesystem with identical rtdev and ddev/logdev.");
error = -EINVAL; error = -EINVAL;
...@@ -468,22 +471,25 @@ xfs_open_devices( ...@@ -468,22 +471,25 @@ xfs_open_devices(
* Setup xfs_mount buffer target pointers * Setup xfs_mount buffer target pointers
*/ */
error = -ENOMEM; error = -ENOMEM;
mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev); mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb->s_bdev_handle);
if (!mp->m_ddev_targp) if (!mp->m_ddev_targp)
goto out_close_rtdev; goto out_close_rtdev;
if (rtdev) { if (rtdev_handle) {
mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev); mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_handle);
if (!mp->m_rtdev_targp) if (!mp->m_rtdev_targp)
goto out_free_ddev_targ; goto out_free_ddev_targ;
} }
if (logdev && logdev != ddev) { if (logdev_handle && logdev_handle->bdev != ddev) {
mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev); mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_handle);
if (!mp->m_logdev_targp) if (!mp->m_logdev_targp)
goto out_free_rtdev_targ; goto out_free_rtdev_targ;
} else { } else {
mp->m_logdev_targp = mp->m_ddev_targp; mp->m_logdev_targp = mp->m_ddev_targp;
/* Handle won't be used, drop it */
if (logdev_handle)
bdev_release(logdev_handle);
} }
error = 0; error = 0;
...@@ -497,11 +503,11 @@ xfs_open_devices( ...@@ -497,11 +503,11 @@ xfs_open_devices(
out_free_ddev_targ: out_free_ddev_targ:
xfs_free_buftarg(mp->m_ddev_targp); xfs_free_buftarg(mp->m_ddev_targp);
out_close_rtdev: out_close_rtdev:
if (rtdev) if (rtdev_handle)
blkdev_put(rtdev, sb); bdev_release(rtdev_handle);
out_close_logdev: out_close_logdev:
if (logdev && logdev != ddev) if (logdev_handle)
blkdev_put(logdev, sb); bdev_release(logdev_handle);
goto out_relock; goto out_relock;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment