diff mbox series

[RFC,07/34] xfs: port block device access to files

Message ID 20240103-vfs-bdev-file-v1-7-6c8ee55fb6ef@kernel.org (mailing list archive)
State New, archived
Headers show
Series Open block devices as files & a bd_inode proposal | expand

Commit Message

Christian Brauner Jan. 3, 2024, 12:55 p.m. UTC
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/xfs/xfs_buf.c   | 10 +++++-----
 fs/xfs/xfs_buf.h   |  4 ++--
 fs/xfs/xfs_super.c | 43 +++++++++++++++++++++----------------------
 3 files changed, 28 insertions(+), 29 deletions(-)

Comments

Dave Chinner Jan. 8, 2024, 5:34 a.m. UTC | #1
On Wed, Jan 03, 2024 at 01:55:05PM +0100, Christian Brauner wrote:
> Signed-off-by: Christian Brauner <brauner@kernel.org>
> ---
>  fs/xfs/xfs_buf.c   | 10 +++++-----
>  fs/xfs/xfs_buf.h   |  4 ++--
>  fs/xfs/xfs_super.c | 43 +++++++++++++++++++++----------------------
>  3 files changed, 28 insertions(+), 29 deletions(-)
> 
> diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
> index 545c7991b9b5..685eb2a9f9d2 100644
> --- a/fs/xfs/xfs_buf.c
> +++ b/fs/xfs/xfs_buf.c
> @@ -1951,7 +1951,7 @@ xfs_free_buftarg(
>  	fs_put_dax(btp->bt_daxdev, btp->bt_mount);
>  	/* the main block device is closed by kill_block_super */
>  	if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev)
> -		bdev_release(btp->bt_bdev_handle);
> +		fput(btp->bt_f_bdev);

bt_bdev_file, please.

"_f_" is not a meaningful prefix, and if we fill the code up with
single letter prefixes is becomes completely unreadable. 

>  
>  	kmem_free(btp);
>  }
> @@ -1994,7 +1994,7 @@ xfs_setsize_buftarg_early(
>  struct xfs_buftarg *
>  xfs_alloc_buftarg(
>  	struct xfs_mount	*mp,
> -	struct bdev_handle	*bdev_handle)
> +	struct file		*f_bdev)

	struct file		*bdev_file)
>  {
>  	xfs_buftarg_t		*btp;
>  	const struct dax_holder_operations *ops = NULL;
> @@ -2005,9 +2005,9 @@ xfs_alloc_buftarg(
>  	btp = kmem_zalloc(sizeof(*btp), KM_NOFS);
>  
>  	btp->bt_mount = mp;
> -	btp->bt_bdev_handle = bdev_handle;
> -	btp->bt_dev = bdev_handle->bdev->bd_dev;
> -	btp->bt_bdev = bdev_handle->bdev;
> +	btp->bt_f_bdev = f_bdev;
> +	btp->bt_bdev = F_BDEV(f_bdev);

file_bdev(), please. i.e. similar to file_inode().


> diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
> index 0e64220bffdc..01ef0ef83c41 100644
> --- a/fs/xfs/xfs_super.c
> +++ b/fs/xfs/xfs_super.c
> @@ -362,16 +362,16 @@ STATIC int
>  xfs_blkdev_get(
>  	xfs_mount_t		*mp,
>  	const char		*name,
> -	struct bdev_handle	**handlep)
> +	struct file		**f_bdevp)

	struct file		**filep

>  {
>  	int			error = 0;
>  
> -	*handlep = bdev_open_by_path(name,
> +	*f_bdevp = bdev_file_open_by_path(name,
>  		BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
>  		mp->m_super, &fs_holder_ops);
> -	if (IS_ERR(*handlep)) {
> -		error = PTR_ERR(*handlep);
> -		*handlep = NULL;
> +	if (IS_ERR(*f_bdevp)) {
> +		error = PTR_ERR(*f_bdevp);
> +		*f_bdevp = NULL;
>  		xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
>  	}
>  
> @@ -436,26 +436,25 @@ xfs_open_devices(
>  {
>  	struct super_block	*sb = mp->m_super;
>  	struct block_device	*ddev = sb->s_bdev;
> -	struct bdev_handle	*logdev_handle = NULL, *rtdev_handle = NULL;
> +	struct file		*f_logdev = NULL, *f_rtdev = NULL;

	struct file		*logdev_file = NULL;
	struct file		*rtdev_file = NULL;
...

-Dave.
Christian Brauner Jan. 8, 2024, 11:34 a.m. UTC | #2
On Mon, Jan 08, 2024 at 04:34:10PM +1100, Dave Chinner wrote:
> On Wed, Jan 03, 2024 at 01:55:05PM +0100, Christian Brauner wrote:
> > Signed-off-by: Christian Brauner <brauner@kernel.org>
> > ---
> >  fs/xfs/xfs_buf.c   | 10 +++++-----
> >  fs/xfs/xfs_buf.h   |  4 ++--
> >  fs/xfs/xfs_super.c | 43 +++++++++++++++++++++----------------------
> >  3 files changed, 28 insertions(+), 29 deletions(-)
> > 
> > diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
> > index 545c7991b9b5..685eb2a9f9d2 100644
> > --- a/fs/xfs/xfs_buf.c
> > +++ b/fs/xfs/xfs_buf.c
> > @@ -1951,7 +1951,7 @@ xfs_free_buftarg(
> >  	fs_put_dax(btp->bt_daxdev, btp->bt_mount);
> >  	/* the main block device is closed by kill_block_super */
> >  	if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev)
> > -		bdev_release(btp->bt_bdev_handle);
> > +		fput(btp->bt_f_bdev);
> 
> bt_bdev_file, please.
> 
> "_f_" is not a meaningful prefix, and if we fill the code up with
> single letter prefixes is becomes completely unreadable. 

Ack to all suggestions.

> 
> >  
> >  	kmem_free(btp);
> >  }
> > @@ -1994,7 +1994,7 @@ xfs_setsize_buftarg_early(
> >  struct xfs_buftarg *
> >  xfs_alloc_buftarg(
> >  	struct xfs_mount	*mp,
> > -	struct bdev_handle	*bdev_handle)
> > +	struct file		*f_bdev)
> 
> 	struct file		*bdev_file)
> >  {
> >  	xfs_buftarg_t		*btp;
> >  	const struct dax_holder_operations *ops = NULL;
> > @@ -2005,9 +2005,9 @@ xfs_alloc_buftarg(
> >  	btp = kmem_zalloc(sizeof(*btp), KM_NOFS);
> >  
> >  	btp->bt_mount = mp;
> > -	btp->bt_bdev_handle = bdev_handle;
> > -	btp->bt_dev = bdev_handle->bdev->bd_dev;
> > -	btp->bt_bdev = bdev_handle->bdev;
> > +	btp->bt_f_bdev = f_bdev;
> > +	btp->bt_bdev = F_BDEV(f_bdev);
> 
> file_bdev(), please. i.e. similar to file_inode().
> 
> 
> > diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c
> > index 0e64220bffdc..01ef0ef83c41 100644
> > --- a/fs/xfs/xfs_super.c
> > +++ b/fs/xfs/xfs_super.c
> > @@ -362,16 +362,16 @@ STATIC int
> >  xfs_blkdev_get(
> >  	xfs_mount_t		*mp,
> >  	const char		*name,
> > -	struct bdev_handle	**handlep)
> > +	struct file		**f_bdevp)
> 
> 	struct file		**filep
> 
> >  {
> >  	int			error = 0;
> >  
> > -	*handlep = bdev_open_by_path(name,
> > +	*f_bdevp = bdev_file_open_by_path(name,
> >  		BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
> >  		mp->m_super, &fs_holder_ops);
> > -	if (IS_ERR(*handlep)) {
> > -		error = PTR_ERR(*handlep);
> > -		*handlep = NULL;
> > +	if (IS_ERR(*f_bdevp)) {
> > +		error = PTR_ERR(*f_bdevp);
> > +		*f_bdevp = NULL;
> >  		xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
> >  	}
> >  
> > @@ -436,26 +436,25 @@ xfs_open_devices(
> >  {
> >  	struct super_block	*sb = mp->m_super;
> >  	struct block_device	*ddev = sb->s_bdev;
> > -	struct bdev_handle	*logdev_handle = NULL, *rtdev_handle = NULL;
> > +	struct file		*f_logdev = NULL, *f_rtdev = NULL;
> 
> 	struct file		*logdev_file = NULL;
> 	struct file		*rtdev_file = NULL;
> ...
> 
> -Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
diff mbox series

Patch

diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 545c7991b9b5..685eb2a9f9d2 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -1951,7 +1951,7 @@  xfs_free_buftarg(
 	fs_put_dax(btp->bt_daxdev, btp->bt_mount);
 	/* the main block device is closed by kill_block_super */
 	if (btp->bt_bdev != btp->bt_mount->m_super->s_bdev)
-		bdev_release(btp->bt_bdev_handle);
+		fput(btp->bt_f_bdev);
 
 	kmem_free(btp);
 }
@@ -1994,7 +1994,7 @@  xfs_setsize_buftarg_early(
 struct xfs_buftarg *
 xfs_alloc_buftarg(
 	struct xfs_mount	*mp,
-	struct bdev_handle	*bdev_handle)
+	struct file		*f_bdev)
 {
 	xfs_buftarg_t		*btp;
 	const struct dax_holder_operations *ops = NULL;
@@ -2005,9 +2005,9 @@  xfs_alloc_buftarg(
 	btp = kmem_zalloc(sizeof(*btp), KM_NOFS);
 
 	btp->bt_mount = mp;
-	btp->bt_bdev_handle = bdev_handle;
-	btp->bt_dev = bdev_handle->bdev->bd_dev;
-	btp->bt_bdev = bdev_handle->bdev;
+	btp->bt_f_bdev = f_bdev;
+	btp->bt_bdev = F_BDEV(f_bdev);
+	btp->bt_dev = btp->bt_bdev->bd_dev;
 	btp->bt_daxdev = fs_dax_get_by_bdev(btp->bt_bdev, &btp->bt_dax_part_off,
 					    mp, ops);
 
diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h
index c86e16419656..4005dcffb792 100644
--- a/fs/xfs/xfs_buf.h
+++ b/fs/xfs/xfs_buf.h
@@ -98,7 +98,7 @@  typedef unsigned int xfs_buf_flags_t;
  */
 typedef struct xfs_buftarg {
 	dev_t			bt_dev;
-	struct bdev_handle	*bt_bdev_handle;
+	struct file		*bt_f_bdev;
 	struct block_device	*bt_bdev;
 	struct dax_device	*bt_daxdev;
 	u64			bt_dax_part_off;
@@ -365,7 +365,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 bdev_handle *bdev_handle);
+		struct file *f_bdev);
 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 0e64220bffdc..01ef0ef83c41 100644
--- a/fs/xfs/xfs_super.c
+++ b/fs/xfs/xfs_super.c
@@ -362,16 +362,16 @@  STATIC int
 xfs_blkdev_get(
 	xfs_mount_t		*mp,
 	const char		*name,
-	struct bdev_handle	**handlep)
+	struct file		**f_bdevp)
 {
 	int			error = 0;
 
-	*handlep = bdev_open_by_path(name,
+	*f_bdevp = bdev_file_open_by_path(name,
 		BLK_OPEN_READ | BLK_OPEN_WRITE | BLK_OPEN_RESTRICT_WRITES,
 		mp->m_super, &fs_holder_ops);
-	if (IS_ERR(*handlep)) {
-		error = PTR_ERR(*handlep);
-		*handlep = NULL;
+	if (IS_ERR(*f_bdevp)) {
+		error = PTR_ERR(*f_bdevp);
+		*f_bdevp = NULL;
 		xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
 	}
 
@@ -436,26 +436,25 @@  xfs_open_devices(
 {
 	struct super_block	*sb = mp->m_super;
 	struct block_device	*ddev = sb->s_bdev;
-	struct bdev_handle	*logdev_handle = NULL, *rtdev_handle = NULL;
+	struct file		*f_logdev = NULL, *f_rtdev = NULL;
 	int			error;
 
 	/*
 	 * Open real time and log devices - order is important.
 	 */
 	if (mp->m_logname) {
-		error = xfs_blkdev_get(mp, mp->m_logname, &logdev_handle);
+		error = xfs_blkdev_get(mp, mp->m_logname, &f_logdev);
 		if (error)
 			return error;
 	}
 
 	if (mp->m_rtname) {
-		error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev_handle);
+		error = xfs_blkdev_get(mp, mp->m_rtname, &f_rtdev);
 		if (error)
 			goto out_close_logdev;
 
-		if (rtdev_handle->bdev == ddev ||
-		    (logdev_handle &&
-		     rtdev_handle->bdev == logdev_handle->bdev)) {
+		if (F_BDEV(f_rtdev) == ddev ||
+		    (f_logdev && F_BDEV(f_rtdev) == F_BDEV(f_logdev))) {
 			xfs_warn(mp,
 	"Cannot mount filesystem with identical rtdev and ddev/logdev.");
 			error = -EINVAL;
@@ -467,25 +466,25 @@  xfs_open_devices(
 	 * Setup xfs_mount buffer target pointers
 	 */
 	error = -ENOMEM;
-	mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb_bdev_handle(sb));
+	mp->m_ddev_targp = xfs_alloc_buftarg(mp, sb->s_f_bdev);
 	if (!mp->m_ddev_targp)
 		goto out_close_rtdev;
 
-	if (rtdev_handle) {
-		mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev_handle);
+	if (f_rtdev) {
+		mp->m_rtdev_targp = xfs_alloc_buftarg(mp, f_rtdev);
 		if (!mp->m_rtdev_targp)
 			goto out_free_ddev_targ;
 	}
 
-	if (logdev_handle && logdev_handle->bdev != ddev) {
-		mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev_handle);
+	if (f_logdev && F_BDEV(f_logdev) != ddev) {
+		mp->m_logdev_targp = xfs_alloc_buftarg(mp, f_logdev);
 		if (!mp->m_logdev_targp)
 			goto out_free_rtdev_targ;
 	} else {
 		mp->m_logdev_targp = mp->m_ddev_targp;
 		/* Handle won't be used, drop it */
-		if (logdev_handle)
-			bdev_release(logdev_handle);
+		if (f_logdev)
+			fput(f_logdev);
 	}
 
 	return 0;
@@ -496,11 +495,11 @@  xfs_open_devices(
  out_free_ddev_targ:
 	xfs_free_buftarg(mp->m_ddev_targp);
  out_close_rtdev:
-	 if (rtdev_handle)
-		bdev_release(rtdev_handle);
+	 if (f_rtdev)
+		fput(f_rtdev);
  out_close_logdev:
-	if (logdev_handle)
-		bdev_release(logdev_handle);
+	if (f_logdev)
+		fput(f_logdev);
 	return error;
 }