Skip to content

Commit 84270a1

Browse files
author
Darrick J. Wong
committed
xfs: only call xfs_setsize_buftarg once per buffer target
It's silly to call xfs_setsize_buftarg from xfs_alloc_buftarg with the block device LBA size because we don't need to ask the block layer to validate a geometry number that it provided us. Instead, set the preliminary bt_meta_sector* fields to the LBA size in preparation for reading the primary super. However, we still want to flush and invalidate the pagecache for all three block devices before we start reading metadata from those devices, so call sync_blockdev() per bdev in xfs_alloc_buftarg(). This will enable a subsequent patch to validate hw atomic write geometry against the filesystem geometry. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: John Garry <john.g.garry@oracle.com> [jpg: call sync_blockdev() from xfs_alloc_buftarg()] Signed-off-by: John Garry <john.g.garry@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
1 parent 5d89432 commit 84270a1

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

fs/xfs/xfs_buf.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,11 +1733,7 @@ xfs_setsize_buftarg(
17331733
return -EINVAL;
17341734
}
17351735

1736-
/*
1737-
* Flush the block device pagecache so our bios see anything dirtied
1738-
* before mount.
1739-
*/
1740-
return sync_blockdev(btp->bt_bdev);
1736+
return 0;
17411737
}
17421738

17431739
int
@@ -1786,6 +1782,8 @@ xfs_alloc_buftarg(
17861782
{
17871783
struct xfs_buftarg *btp;
17881784
const struct dax_holder_operations *ops = NULL;
1785+
int error;
1786+
17891787

17901788
#if defined(CONFIG_FS_DAX) && defined(CONFIG_MEMORY_FAILURE)
17911789
ops = &xfs_dax_holder_operations;
@@ -1806,21 +1804,31 @@ xfs_alloc_buftarg(
18061804
btp->bt_bdev);
18071805
}
18081806

1807+
/*
1808+
* Flush and invalidate all devices' pagecaches before reading any
1809+
* metadata because XFS doesn't use the bdev pagecache.
1810+
*/
1811+
error = sync_blockdev(btp->bt_bdev);
1812+
if (error)
1813+
goto error_free;
1814+
18091815
/*
18101816
* When allocating the buftargs we have not yet read the super block and
18111817
* thus don't know the file system sector size yet.
18121818
*/
1813-
if (xfs_setsize_buftarg(btp, bdev_logical_block_size(btp->bt_bdev)))
1814-
goto error_free;
1815-
if (xfs_init_buftarg(btp, bdev_logical_block_size(btp->bt_bdev),
1816-
mp->m_super->s_id))
1819+
btp->bt_meta_sectorsize = bdev_logical_block_size(btp->bt_bdev);
1820+
btp->bt_meta_sectormask = btp->bt_meta_sectorsize - 1;
1821+
1822+
error = xfs_init_buftarg(btp, btp->bt_meta_sectorsize,
1823+
mp->m_super->s_id);
1824+
if (error)
18171825
goto error_free;
18181826

18191827
return btp;
18201828

18211829
error_free:
18221830
kfree(btp);
1823-
return NULL;
1831+
return ERR_PTR(error);
18241832
}
18251833

18261834
static inline void

fs/xfs/xfs_super.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,21 +482,29 @@ xfs_open_devices(
482482
/*
483483
* Setup xfs_mount buffer target pointers
484484
*/
485-
error = -ENOMEM;
486485
mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb->s_bdev_file);
487-
if (!mp->m_ddev_targp)
486+
if (IS_ERR(mp->m_ddev_targp)) {
487+
error = PTR_ERR(mp->m_ddev_targp);
488+
mp->m_ddev_targp = NULL;
488489
goto out_close_rtdev;
490+
}
489491

490492
if (rtdev_file) {
491493
mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_file);
492-
if (!mp->m_rtdev_targp)
494+
if (IS_ERR(mp->m_rtdev_targp)) {
495+
error = PTR_ERR(mp->m_rtdev_targp);
496+
mp->m_rtdev_targp = NULL;
493497
goto out_free_ddev_targ;
498+
}
494499
}
495500

496501
if (logdev_file && file_bdev(logdev_file) != ddev) {
497502
mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_file);
498-
if (!mp->m_logdev_targp)
503+
if (IS_ERR(mp->m_logdev_targp)) {
504+
error = PTR_ERR(mp->m_logdev_targp);
505+
mp->m_logdev_targp = NULL;
499506
goto out_free_rtdev_targ;
507+
}
500508
} else {
501509
mp->m_logdev_targp = mp->m_ddev_targp;
502510
/* Handle won't be used, drop it */

0 commit comments

Comments
 (0)