Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230927093442.25915-28-jack@suse.cz
Acked-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Jan Kara and committed by
Christian Brauner
e340dd63 ba1787a5

+36 -31
+10 -12
fs/xfs/xfs_buf.c
··· 1945 1945 xfs_free_buftarg( 1946 1946 struct xfs_buftarg *btp) 1947 1947 { 1948 - struct block_device *bdev = btp->bt_bdev; 1949 - 1950 1948 unregister_shrinker(&btp->bt_shrinker); 1951 1949 ASSERT(percpu_counter_sum(&btp->bt_io_count) == 0); 1952 1950 percpu_counter_destroy(&btp->bt_io_count); ··· 1952 1954 1953 1955 fs_put_dax(btp->bt_daxdev, btp->bt_mount); 1954 1956 /* the main block device is closed by kill_block_super */ 1955 - if (bdev != btp->bt_mount->m_super->s_bdev) 1956 - blkdev_put(bdev, btp->bt_mount->m_super); 1957 + if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev) 1958 + bdev_release(btp->bt_bdev_handle); 1957 1959 1958 1960 kmem_free(btp); 1959 1961 } ··· 1988 1990 */ 1989 1991 STATIC int 1990 1992 xfs_setsize_buftarg_early( 1991 - xfs_buftarg_t *btp, 1992 - struct block_device *bdev) 1993 + xfs_buftarg_t *btp) 1993 1994 { 1994 - return xfs_setsize_buftarg(btp, bdev_logical_block_size(bdev)); 1995 + return xfs_setsize_buftarg(btp, bdev_logical_block_size(btp->bt_bdev)); 1995 1996 } 1996 1997 1997 1998 struct xfs_buftarg * 1998 1999 xfs_alloc_buftarg( 1999 2000 struct xfs_mount *mp, 2000 - struct block_device *bdev) 2001 + struct bdev_handle *bdev_handle) 2001 2002 { 2002 2003 xfs_buftarg_t *btp; 2003 2004 const struct dax_holder_operations *ops = NULL; ··· 2007 2010 btp = kmem_zalloc(sizeof(*btp), KM_NOFS); 2008 2011 2009 2012 btp->bt_mount = mp; 2010 - btp->bt_dev = bdev->bd_dev; 2011 - btp->bt_bdev = bdev; 2012 - btp->bt_daxdev = fs_dax_get_by_bdev(bdev, &btp->bt_dax_part_off, 2013 + btp->bt_bdev_handle = bdev_handle; 2014 + btp->bt_dev = bdev_handle->bdev->bd_dev; 2015 + btp->bt_bdev = bdev_handle->bdev; 2016 + btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off, 2013 2017 mp, ops); 2014 2018 2015 2019 /* ··· 2020 2022 ratelimit_state_init(&btp->bt_ioerror_rl, 30 * HZ, 2021 2023 DEFAULT_RATELIMIT_BURST); 2022 2024 2023 - if (xfs_setsize_buftarg_early(btp, bdev)) 2025 + if (xfs_setsize_buftarg_early(btp)) 2024 2026 goto error_free; 2025 2027 2026 2028 if (list_lru_init(&btp->bt_lru))
+2 -1
fs/xfs/xfs_buf.h
··· 98 98 */ 99 99 typedef struct xfs_buftarg { 100 100 dev_t bt_dev; 101 + struct bdev_handle *bt_bdev_handle; 101 102 struct block_device *bt_bdev; 102 103 struct dax_device *bt_daxdev; 103 104 u64 bt_dax_part_off; ··· 365 364 * Handling of buftargs. 366 365 */ 367 366 struct xfs_buftarg *xfs_alloc_buftarg(struct xfs_mount *mp, 368 - struct block_device *bdev); 367 + struct bdev_handle *bdev_handle); 369 368 extern void xfs_free_buftarg(struct xfs_buftarg *); 370 369 extern void xfs_buftarg_wait(struct xfs_buftarg *); 371 370 extern void xfs_buftarg_drain(struct xfs_buftarg *);
+24 -18
fs/xfs/xfs_super.c
··· 361 361 xfs_blkdev_get( 362 362 xfs_mount_t *mp, 363 363 const char *name, 364 - struct block_device **bdevp) 364 + struct bdev_handle **handlep) 365 365 { 366 366 int error = 0; 367 367 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; 372 373 xfs_warn(mp, "Invalid device [%s], error=%d", name, error); 373 374 } 374 375 ··· 434 433 { 435 434 struct super_block *sb = mp->m_super; 436 435 struct block_device *ddev = sb->s_bdev; 437 - struct block_device *logdev = NULL, *rtdev = NULL; 436 + struct bdev_handle *logdev_handle = NULL, *rtdev_handle = NULL; 438 437 int error; 439 438 440 439 /* ··· 447 446 * Open real time and log devices - order is important. 448 447 */ 449 448 if (mp->m_logname) { 450 - error = xfs_blkdev_get(mp, mp->m_logname, &logdev); 449 + error = xfs_blkdev_get(mp, mp->m_logname, &logdev_handle); 451 450 if (error) 452 451 goto out_relock; 453 452 } 454 453 455 454 if (mp->m_rtname) { 456 - error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev); 455 + error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev_handle); 457 456 if (error) 458 457 goto out_close_logdev; 459 458 460 - if (rtdev == ddev || rtdev == logdev) { 459 + if (rtdev_handle->bdev == ddev || 460 + (logdev_handle && 461 + rtdev_handle->bdev == logdev_handle->bdev)) { 461 462 xfs_warn(mp, 462 463 "Cannot mount filesystem with identical rtdev and ddev/logdev."); 463 464 error = -EINVAL; ··· 471 468 * Setup xfs_mount buffer target pointers 472 469 */ 473 470 error = -ENOMEM; 474 - mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev); 471 + mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb->s_bdev_handle); 475 472 if (!mp->m_ddev_targp) 476 473 goto out_close_rtdev; 477 474 478 - if (rtdev) { 479 - mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev); 475 + if (rtdev_handle) { 476 + mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_handle); 480 477 if (!mp->m_rtdev_targp) 481 478 goto out_free_ddev_targ; 482 479 } 483 480 484 - if (logdev && logdev != ddev) { 485 - mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev); 481 + if (logdev_handle && logdev_handle->bdev != ddev) { 482 + mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_handle); 486 483 if (!mp->m_logdev_targp) 487 484 goto out_free_rtdev_targ; 488 485 } else { 489 486 mp->m_logdev_targp = mp->m_ddev_targp; 487 + /* Handle won't be used, drop it */ 488 + if (logdev_handle) 489 + bdev_release(logdev_handle); 490 490 } 491 491 492 492 error = 0; ··· 503 497 out_free_ddev_targ: 504 498 xfs_free_buftarg(mp->m_ddev_targp); 505 499 out_close_rtdev: 506 - if (rtdev) 507 - blkdev_put(rtdev, sb); 500 + if (rtdev_handle) 501 + bdev_release(rtdev_handle); 508 502 out_close_logdev: 509 - if (logdev && logdev != ddev) 510 - blkdev_put(logdev, sb); 503 + if (logdev_handle) 504 + bdev_release(logdev_handle); 511 505 goto out_relock; 512 506 } 513 507