Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit e340dd6

Browse files
jankarabrauner
authored andcommitted
xfs: Convert to bdev_open_by_path()
Convert xfs to use bdev_open_by_path() and pass the handle around. CC: "Darrick J. Wong" <[email protected]> CC: [email protected] Acked-by: Christoph Hellwig <[email protected]> Reviewed-by: Dave Chinner <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: "Darrick J. Wong" <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent ba1787a commit e340dd6

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

fs/xfs/xfs_buf.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,17 +1945,15 @@ void
19451945
xfs_free_buftarg(
19461946
struct xfs_buftarg *btp)
19471947
{
1948-
struct block_device *bdev = btp->bt_bdev;
1949-
19501948
unregister_shrinker(&btp->bt_shrinker);
19511949
ASSERT(percpu_counter_sum(&btp->bt_io_count) == 0);
19521950
percpu_counter_destroy(&btp->bt_io_count);
19531951
list_lru_destroy(&btp->bt_lru);
19541952

19551953
fs_put_dax(btp->bt_daxdev, btp->bt_mount);
19561954
/* the main block device is closed by kill_block_super */
1957-
if (bdev != btp->bt_mount->m_super->s_bdev)
1958-
blkdev_put(bdev, btp->bt_mount->m_super);
1955+
if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev)
1956+
bdev_release(btp->bt_bdev_handle);
19591957

19601958
kmem_free(btp);
19611959
}
@@ -1990,16 +1988,15 @@ xfs_setsize_buftarg(
19901988
*/
19911989
STATIC int
19921990
xfs_setsize_buftarg_early(
1993-
xfs_buftarg_t *btp,
1994-
struct block_device *bdev)
1991+
xfs_buftarg_t *btp)
19951992
{
1996-
return xfs_setsize_buftarg(btp, bdev_logical_block_size(bdev));
1993+
return xfs_setsize_buftarg(btp, bdev_logical_block_size(btp->bt_bdev));
19971994
}
19981995

19991996
struct xfs_buftarg *
20001997
xfs_alloc_buftarg(
20011998
struct xfs_mount *mp,
2002-
struct block_device *bdev)
1999+
struct bdev_handle *bdev_handle)
20032000
{
20042001
xfs_buftarg_t *btp;
20052002
const struct dax_holder_operations *ops = NULL;
@@ -2010,9 +2007,10 @@ xfs_alloc_buftarg(
20102007
btp = kmem_zalloc(sizeof(*btp), KM_NOFS);
20112008

20122009
btp->bt_mount = mp;
2013-
btp->bt_dev = bdev->bd_dev;
2014-
btp->bt_bdev = bdev;
2015-
btp->bt_daxdev = fs_dax_get_by_bdev(bdev, &btp->bt_dax_part_off,
2010+
btp->bt_bdev_handle = bdev_handle;
2011+
btp->bt_dev = bdev_handle->bdev->bd_dev;
2012+
btp->bt_bdev = bdev_handle->bdev;
2013+
btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off,
20162014
mp, ops);
20172015

20182016
/*
@@ -2022,7 +2020,7 @@ xfs_alloc_buftarg(
20222020
ratelimit_state_init(&btp->bt_ioerror_rl, 30 * HZ,
20232021
DEFAULT_RATELIMIT_BURST);
20242022

2025-
if (xfs_setsize_buftarg_early(btp, bdev))
2023+
if (xfs_setsize_buftarg_early(btp))
20262024
goto error_free;
20272025

20282026
if (list_lru_init(&btp->bt_lru))

fs/xfs/xfs_buf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ typedef unsigned int xfs_buf_flags_t;
9898
*/
9999
typedef struct xfs_buftarg {
100100
dev_t bt_dev;
101+
struct bdev_handle *bt_bdev_handle;
101102
struct block_device *bt_bdev;
102103
struct dax_device *bt_daxdev;
103104
u64 bt_dax_part_off;
@@ -364,7 +365,7 @@ xfs_buf_update_cksum(struct xfs_buf *bp, unsigned long cksum_offset)
364365
* Handling of buftargs.
365366
*/
366367
struct xfs_buftarg *xfs_alloc_buftarg(struct xfs_mount *mp,
367-
struct block_device *bdev);
368+
struct bdev_handle *bdev_handle);
368369
extern void xfs_free_buftarg(struct xfs_buftarg *);
369370
extern void xfs_buftarg_wait(struct xfs_buftarg *);
370371
extern void xfs_buftarg_drain(struct xfs_buftarg *);

fs/xfs/xfs_super.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,15 @@ STATIC int
361361
xfs_blkdev_get(
362362
xfs_mount_t *mp,
363363
const char *name,
364-
struct block_device **bdevp)
364+
struct bdev_handle **handlep)
365365
{
366366
int error = 0;
367367

368-
*bdevp = blkdev_get_by_path(name, BLK_OPEN_READ | BLK_OPEN_WRITE,
369-
mp->m_super, &fs_holder_ops);
370-
if (IS_ERR(*bdevp)) {
371-
error = PTR_ERR(*bdevp);
368+
*handlep = bdev_open_by_path(name, BLK_OPEN_READ | BLK_OPEN_WRITE,
369+
mp->m_super, &fs_holder_ops);
370+
if (IS_ERR(*handlep)) {
371+
error = PTR_ERR(*handlep);
372+
*handlep = NULL;
372373
xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
373374
}
374375

@@ -433,7 +434,7 @@ xfs_open_devices(
433434
{
434435
struct super_block *sb = mp->m_super;
435436
struct block_device *ddev = sb->s_bdev;
436-
struct block_device *logdev = NULL, *rtdev = NULL;
437+
struct bdev_handle *logdev_handle = NULL, *rtdev_handle = NULL;
437438
int error;
438439

439440
/*
@@ -446,17 +447,19 @@ xfs_open_devices(
446447
* Open real time and log devices - order is important.
447448
*/
448449
if (mp->m_logname) {
449-
error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
450+
error = xfs_blkdev_get(mp, mp->m_logname, &logdev_handle);
450451
if (error)
451452
goto out_relock;
452453
}
453454

454455
if (mp->m_rtname) {
455-
error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
456+
error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev_handle);
456457
if (error)
457458
goto out_close_logdev;
458459

459-
if (rtdev == ddev || rtdev == logdev) {
460+
if (rtdev_handle->bdev == ddev ||
461+
(logdev_handle &&
462+
rtdev_handle->bdev == logdev_handle->bdev)) {
460463
xfs_warn(mp,
461464
"Cannot mount filesystem with identical rtdev and ddev/logdev.");
462465
error = -EINVAL;
@@ -468,22 +471,25 @@ xfs_open_devices(
468471
* Setup xfs_mount buffer target pointers
469472
*/
470473
error = -ENOMEM;
471-
mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev);
474+
mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb->s_bdev_handle);
472475
if (!mp->m_ddev_targp)
473476
goto out_close_rtdev;
474477

475-
if (rtdev) {
476-
mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev);
478+
if (rtdev_handle) {
479+
mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_handle);
477480
if (!mp->m_rtdev_targp)
478481
goto out_free_ddev_targ;
479482
}
480483

481-
if (logdev && logdev != ddev) {
482-
mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev);
484+
if (logdev_handle && logdev_handle->bdev != ddev) {
485+
mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_handle);
483486
if (!mp->m_logdev_targp)
484487
goto out_free_rtdev_targ;
485488
} else {
486489
mp->m_logdev_targp = mp->m_ddev_targp;
490+
/* Handle won't be used, drop it */
491+
if (logdev_handle)
492+
bdev_release(logdev_handle);
487493
}
488494

489495
error = 0;
@@ -497,11 +503,11 @@ xfs_open_devices(
497503
out_free_ddev_targ:
498504
xfs_free_buftarg(mp->m_ddev_targp);
499505
out_close_rtdev:
500-
if (rtdev)
501-
blkdev_put(rtdev, sb);
506+
if (rtdev_handle)
507+
bdev_release(rtdev_handle);
502508
out_close_logdev:
503-
if (logdev && logdev != ddev)
504-
blkdev_put(logdev, sb);
509+
if (logdev_handle)
510+
bdev_release(logdev_handle);
505511
goto out_relock;
506512
}
507513

0 commit comments

Comments
 (0)