Message ID | 20230811110504.27514-28-jack@suse.cz (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | block: Make blkdev_get_by_*() return handle | expand |
Hi Jan, On Fri, Aug 11, 2023 at 01:04:59PM +0200, Jan Kara wrote: > 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 > Signed-off-by: Jan Kara <jack@suse.cz> > --- > fs/xfs/xfs_buf.c | 11 +++++----- > fs/xfs/xfs_buf.h | 3 ++- > fs/xfs/xfs_super.c | 54 +++++++++++++++++++++++++--------------------- > 3 files changed, 37 insertions(+), 31 deletions(-) > > diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c > index 15d1e5a7c2d3..461a5fb6155b 100644 > --- a/fs/xfs/xfs_buf.c > +++ b/fs/xfs/xfs_buf.c > @@ -1989,7 +1989,7 @@ xfs_setsize_buftarg_early( > struct xfs_buftarg * > xfs_alloc_buftarg( > struct xfs_mount *mp, > - struct block_device *bdev) > + struct bdev_handle *bdev_handle) > { > xfs_buftarg_t *btp; > const struct dax_holder_operations *ops = NULL; > @@ -2000,9 +2000,10 @@ xfs_alloc_buftarg( > btp = kmem_zalloc(sizeof(*btp), KM_NOFS); > > btp->bt_mount = mp; > - btp->bt_dev = bdev->bd_dev; > - btp->bt_bdev = bdev; > - btp->bt_daxdev = fs_dax_get_by_bdev(bdev, &btp->bt_dax_part_off, > + btp->bt_bdev_handle = bdev_handle; > + btp->bt_dev = bdev_handle->bdev->bd_dev; > + btp->bt_bdev = bdev_handle->bdev; > + btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off, > mp, ops); > > /* > @@ -2012,7 +2013,7 @@ xfs_alloc_buftarg( > ratelimit_state_init(&btp->bt_ioerror_rl, 30 * HZ, > DEFAULT_RATELIMIT_BURST); > > - if (xfs_setsize_buftarg_early(btp, bdev)) > + if (xfs_setsize_buftarg_early(btp, btp->bt_bdev)) This can now be simplified to one parameter. And use the btp->bt_bdev directly when invoking bdev_logical_block_size. > goto error_free; > > if (list_lru_init(&btp->bt_lru)) > diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h > index 549c60942208..f6418c1312f5 100644 > --- a/fs/xfs/xfs_buf.h > +++ b/fs/xfs/xfs_buf.h > @@ -92,6 +92,7 @@ typedef unsigned int xfs_buf_flags_t; > */ > typedef struct xfs_buftarg { > dev_t bt_dev; > + struct bdev_handle *bt_bdev_handle; > struct block_device *bt_bdev; > struct dax_device *bt_daxdev; > u64 bt_dax_part_off; > @@ -351,7 +352,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 block_device *bdev); > + struct bdev_handle *bdev_handle); > 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 5340f2dc28bd..6189f726b309 100644 > --- a/fs/xfs/xfs_super.c > +++ b/fs/xfs/xfs_super.c > @@ -381,14 +381,15 @@ STATIC int > xfs_blkdev_get( > xfs_mount_t *mp, > const char *name, > - struct block_device **bdevp) > + struct bdev_handle **handlep) > { > int error = 0; > > - *bdevp = blkdev_get_by_path(name, BLK_OPEN_READ | BLK_OPEN_WRITE, > - mp->m_super, &fs_holder_ops); > - if (IS_ERR(*bdevp)) { > - error = PTR_ERR(*bdevp); > + *handlep = bdev_open_by_path(name, BLK_OPEN_READ | BLK_OPEN_WRITE, > + mp->m_super, &fs_holder_ops); > + if (IS_ERR(*handlep)) { > + error = PTR_ERR(*handlep); > + *handlep = NULL; > xfs_warn(mp, "Invalid device [%s], error=%d", name, error); > } > > @@ -397,11 +398,10 @@ xfs_blkdev_get( > > STATIC void > xfs_blkdev_put( > - struct xfs_mount *mp, > - struct block_device *bdev) > + struct bdev_handle *handle) > { > - if (bdev) > - blkdev_put(bdev, mp->m_super); > + if (handle) > + bdev_release(handle); > } > > STATIC void > @@ -409,16 +409,18 @@ xfs_close_devices( > struct xfs_mount *mp) > { > if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { > - struct block_device *logdev = mp->m_logdev_targp->bt_bdev; > + struct bdev_handle *logdev_handle = > + mp->m_logdev_targp->bt_bdev_handle; > > xfs_free_buftarg(mp->m_logdev_targp); > - xfs_blkdev_put(mp, logdev); > + xfs_blkdev_put(logdev_handle); > } > if (mp->m_rtdev_targp) { > - struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev; > + struct bdev_handle *rtdev_handle = > + mp->m_rtdev_targp->bt_bdev_handle; > > xfs_free_buftarg(mp->m_rtdev_targp); > - xfs_blkdev_put(mp, rtdev); > + xfs_blkdev_put(rtdev_handle); > } > xfs_free_buftarg(mp->m_ddev_targp); > } > @@ -439,7 +441,7 @@ xfs_open_devices( > { > struct super_block *sb = mp->m_super; > 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; > > /* > @@ -452,17 +454,19 @@ xfs_open_devices( > * Open real time and log devices - order is important. > */ > 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) > goto out_relock; > } > > 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) > 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, > "Cannot mount filesystem with identical rtdev and ddev/logdev."); > error = -EINVAL; > @@ -474,18 +478,18 @@ xfs_open_devices( > * Setup xfs_mount buffer target pointers > */ > 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) > goto out_close_rtdev; > > - if (rtdev) { > - mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev); > + if (rtdev_handle) { > + mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_handle); > if (!mp->m_rtdev_targp) > goto out_free_ddev_targ; > } > > - if (logdev && logdev != ddev) { > - mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev); > + if (logdev_handle && logdev_handle->bdev != ddev) { > + mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_handle); > if (!mp->m_logdev_targp) > goto out_free_rtdev_targ; > } else { > @@ -503,10 +507,10 @@ xfs_open_devices( > out_free_ddev_targ: > xfs_free_buftarg(mp->m_ddev_targp); > out_close_rtdev: > - xfs_blkdev_put(mp, rtdev); > + xfs_blkdev_put(rtdev_handle); > out_close_logdev: > - if (logdev && logdev != ddev) > - xfs_blkdev_put(mp, logdev); > + if (logdev_handle && logdev_handle->bdev != ddev) > + xfs_blkdev_put(logdev_handle); > goto out_relock; > } > > -- > 2.35.3 >
On Mon 14-08-23 10:27:46, Daniel Gomez wrote: > > Hi Jan, > > On Fri, Aug 11, 2023 at 01:04:59PM +0200, Jan Kara wrote: > > 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 > > Signed-off-by: Jan Kara <jack@suse.cz> ... > > @@ -2012,7 +2013,7 @@ xfs_alloc_buftarg( > > ratelimit_state_init(&btp->bt_ioerror_rl, 30 * HZ, > > DEFAULT_RATELIMIT_BURST); > > > > - if (xfs_setsize_buftarg_early(btp, bdev)) > > + if (xfs_setsize_buftarg_early(btp, btp->bt_bdev)) > > This can now be simplified to one parameter. And use the btp->bt_bdev > directly when invoking bdev_logical_block_size. Fair point. Done. Honza
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index 15d1e5a7c2d3..461a5fb6155b 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -1989,7 +1989,7 @@ xfs_setsize_buftarg_early( struct xfs_buftarg * xfs_alloc_buftarg( struct xfs_mount *mp, - struct block_device *bdev) + struct bdev_handle *bdev_handle) { xfs_buftarg_t *btp; const struct dax_holder_operations *ops = NULL; @@ -2000,9 +2000,10 @@ xfs_alloc_buftarg( btp = kmem_zalloc(sizeof(*btp), KM_NOFS); btp->bt_mount = mp; - btp->bt_dev = bdev->bd_dev; - btp->bt_bdev = bdev; - btp->bt_daxdev = fs_dax_get_by_bdev(bdev, &btp->bt_dax_part_off, + btp->bt_bdev_handle = bdev_handle; + btp->bt_dev = bdev_handle->bdev->bd_dev; + btp->bt_bdev = bdev_handle->bdev; + btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off, mp, ops); /* @@ -2012,7 +2013,7 @@ xfs_alloc_buftarg( ratelimit_state_init(&btp->bt_ioerror_rl, 30 * HZ, DEFAULT_RATELIMIT_BURST); - if (xfs_setsize_buftarg_early(btp, bdev)) + if (xfs_setsize_buftarg_early(btp, btp->bt_bdev)) goto error_free; if (list_lru_init(&btp->bt_lru)) diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h index 549c60942208..f6418c1312f5 100644 --- a/fs/xfs/xfs_buf.h +++ b/fs/xfs/xfs_buf.h @@ -92,6 +92,7 @@ typedef unsigned int xfs_buf_flags_t; */ typedef struct xfs_buftarg { dev_t bt_dev; + struct bdev_handle *bt_bdev_handle; struct block_device *bt_bdev; struct dax_device *bt_daxdev; u64 bt_dax_part_off; @@ -351,7 +352,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 block_device *bdev); + struct bdev_handle *bdev_handle); 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 5340f2dc28bd..6189f726b309 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -381,14 +381,15 @@ STATIC int xfs_blkdev_get( xfs_mount_t *mp, const char *name, - struct block_device **bdevp) + struct bdev_handle **handlep) { int error = 0; - *bdevp = blkdev_get_by_path(name, BLK_OPEN_READ | BLK_OPEN_WRITE, - mp->m_super, &fs_holder_ops); - if (IS_ERR(*bdevp)) { - error = PTR_ERR(*bdevp); + *handlep = bdev_open_by_path(name, BLK_OPEN_READ | BLK_OPEN_WRITE, + mp->m_super, &fs_holder_ops); + if (IS_ERR(*handlep)) { + error = PTR_ERR(*handlep); + *handlep = NULL; xfs_warn(mp, "Invalid device [%s], error=%d", name, error); } @@ -397,11 +398,10 @@ xfs_blkdev_get( STATIC void xfs_blkdev_put( - struct xfs_mount *mp, - struct block_device *bdev) + struct bdev_handle *handle) { - if (bdev) - blkdev_put(bdev, mp->m_super); + if (handle) + bdev_release(handle); } STATIC void @@ -409,16 +409,18 @@ xfs_close_devices( struct xfs_mount *mp) { if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { - struct block_device *logdev = mp->m_logdev_targp->bt_bdev; + struct bdev_handle *logdev_handle = + mp->m_logdev_targp->bt_bdev_handle; xfs_free_buftarg(mp->m_logdev_targp); - xfs_blkdev_put(mp, logdev); + xfs_blkdev_put(logdev_handle); } if (mp->m_rtdev_targp) { - struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev; + struct bdev_handle *rtdev_handle = + mp->m_rtdev_targp->bt_bdev_handle; xfs_free_buftarg(mp->m_rtdev_targp); - xfs_blkdev_put(mp, rtdev); + xfs_blkdev_put(rtdev_handle); } xfs_free_buftarg(mp->m_ddev_targp); } @@ -439,7 +441,7 @@ xfs_open_devices( { struct super_block *sb = mp->m_super; 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; /* @@ -452,17 +454,19 @@ xfs_open_devices( * Open real time and log devices - order is important. */ 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) goto out_relock; } 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) 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, "Cannot mount filesystem with identical rtdev and ddev/logdev."); error = -EINVAL; @@ -474,18 +478,18 @@ xfs_open_devices( * Setup xfs_mount buffer target pointers */ 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) goto out_close_rtdev; - if (rtdev) { - mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev); + if (rtdev_handle) { + mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_handle); if (!mp->m_rtdev_targp) goto out_free_ddev_targ; } - if (logdev && logdev != ddev) { - mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev); + if (logdev_handle && logdev_handle->bdev != ddev) { + mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_handle); if (!mp->m_logdev_targp) goto out_free_rtdev_targ; } else { @@ -503,10 +507,10 @@ xfs_open_devices( out_free_ddev_targ: xfs_free_buftarg(mp->m_ddev_targp); out_close_rtdev: - xfs_blkdev_put(mp, rtdev); + xfs_blkdev_put(rtdev_handle); out_close_logdev: - if (logdev && logdev != ddev) - xfs_blkdev_put(mp, logdev); + if (logdev_handle && logdev_handle->bdev != ddev) + xfs_blkdev_put(logdev_handle); goto out_relock; }
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 Signed-off-by: Jan Kara <jack@suse.cz> --- fs/xfs/xfs_buf.c | 11 +++++----- fs/xfs/xfs_buf.h | 3 ++- fs/xfs/xfs_super.c | 54 +++++++++++++++++++++++++--------------------- 3 files changed, 37 insertions(+), 31 deletions(-)