diff mbox

[1/3] xfs: helper to set flags on uncached buffer reads

Message ID 1468426595-35032-2-git-send-email-bfoster@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Brian Foster July 13, 2016, 4:16 p.m. UTC
xfs_buf_read_uncached() allocates an uncached buffer and performs a read
in one go. As part of the upcoming buftarg I/O accounting mechanism,
some sites may need to set flags on a buffer before I/O submission.

Create a new helper to support the ability to set flags on a buffer
before it is submitted for I/O. This use case is the exception, so
create a wrapper for the original xfs_buf_read_uncached().

Signed-off-by: Brian Foster <bfoster@redhat.com>
---
 fs/xfs/xfs_buf.c | 20 +++++++++++++++++---
 fs/xfs/xfs_buf.h |  4 ++++
 2 files changed, 21 insertions(+), 3 deletions(-)

Comments

Dave Chinner July 14, 2016, 12:01 a.m. UTC | #1
On Wed, Jul 13, 2016 at 12:16:33PM -0400, Brian Foster wrote:
> xfs_buf_read_uncached() allocates an uncached buffer and performs a read
> in one go. As part of the upcoming buftarg I/O accounting mechanism,
> some sites may need to set flags on a buffer before I/O submission.
> 
> Create a new helper to support the ability to set flags on a buffer
> before it is submitted for I/O. This use case is the exception, so
> create a wrapper for the original xfs_buf_read_uncached().
> 
> Signed-off-by: Brian Foster <bfoster@redhat.com>
> ---
>  fs/xfs/xfs_buf.c | 20 +++++++++++++++++---
>  fs/xfs/xfs_buf.h |  4 ++++
>  2 files changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
> index 4665ff6..f007713 100644
> --- a/fs/xfs/xfs_buf.c
> +++ b/fs/xfs/xfs_buf.c
> @@ -693,13 +693,14 @@ xfs_buf_readahead_map(
>   * buffer containing the disk contents or nothing.
>   */
>  int
> -xfs_buf_read_uncached(
> +xfs_buf_read_uncached_flags(
>  	struct xfs_buftarg	*target,
>  	xfs_daddr_t		daddr,
>  	size_t			numblks,
>  	int			flags,
>  	struct xfs_buf		**bpp,
> -	const struct xfs_buf_ops *ops)
> +	const struct xfs_buf_ops *ops,
> +	int			bflags)
>  {

We already have a flags field being passed in. Why can't that be
used to pass the XBF_NO_IOACCT flag? i.e:

>  	ASSERT(bp->b_map_count == 1);
>  	bp->b_bn = XFS_BUF_DADDR_NULL;  /* always null for uncached buffers */
>  	bp->b_maps[0].bm_bn = daddr;
> -	bp->b_flags |= XBF_READ;
> +	bp->b_flags |= XBF_READ | bflags;

	bp->b_flags |= XBF_READ;
	bp->b_flags |= (flags & XBF_NO_IOACCT);

Cheers,

Dave.
Brian Foster July 14, 2016, 10:52 a.m. UTC | #2
On Thu, Jul 14, 2016 at 10:01:04AM +1000, Dave Chinner wrote:
> On Wed, Jul 13, 2016 at 12:16:33PM -0400, Brian Foster wrote:
> > xfs_buf_read_uncached() allocates an uncached buffer and performs a read
> > in one go. As part of the upcoming buftarg I/O accounting mechanism,
> > some sites may need to set flags on a buffer before I/O submission.
> > 
> > Create a new helper to support the ability to set flags on a buffer
> > before it is submitted for I/O. This use case is the exception, so
> > create a wrapper for the original xfs_buf_read_uncached().
> > 
> > Signed-off-by: Brian Foster <bfoster@redhat.com>
> > ---
> >  fs/xfs/xfs_buf.c | 20 +++++++++++++++++---
> >  fs/xfs/xfs_buf.h |  4 ++++
> >  2 files changed, 21 insertions(+), 3 deletions(-)
> > 
> > diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
> > index 4665ff6..f007713 100644
> > --- a/fs/xfs/xfs_buf.c
> > +++ b/fs/xfs/xfs_buf.c
> > @@ -693,13 +693,14 @@ xfs_buf_readahead_map(
> >   * buffer containing the disk contents or nothing.
> >   */
> >  int
> > -xfs_buf_read_uncached(
> > +xfs_buf_read_uncached_flags(
> >  	struct xfs_buftarg	*target,
> >  	xfs_daddr_t		daddr,
> >  	size_t			numblks,
> >  	int			flags,
> >  	struct xfs_buf		**bpp,
> > -	const struct xfs_buf_ops *ops)
> > +	const struct xfs_buf_ops *ops,
> > +	int			bflags)
> >  {
> 
> We already have a flags field being passed in. Why can't that be
> used to pass the XBF_NO_IOACCT flag? i.e:
> 

Oops, I read over that too quickly as I saw it being passed into
alloc_page() and assumed it was for memory allocation flags. It is in
fact for buffer flags.. we just use xb_to_gfp() to select GFP_* flags
based on the buffer flags. I'll drop this patch and fold the
xfs_buf_read_cached() fixup into patch 2. Thanks.

Brian

> >  	ASSERT(bp->b_map_count == 1);
> >  	bp->b_bn = XFS_BUF_DADDR_NULL;  /* always null for uncached buffers */
> >  	bp->b_maps[0].bm_bn = daddr;
> > -	bp->b_flags |= XBF_READ;
> > +	bp->b_flags |= XBF_READ | bflags;
> 
> 	bp->b_flags |= XBF_READ;
> 	bp->b_flags |= (flags & XBF_NO_IOACCT);
> 
> Cheers,
> 
> Dave.
> -- 
> Dave Chinner
> david@fromorbit.com
> 
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
diff mbox

Patch

diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 4665ff6..f007713 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -693,13 +693,14 @@  xfs_buf_readahead_map(
  * buffer containing the disk contents or nothing.
  */
 int
-xfs_buf_read_uncached(
+xfs_buf_read_uncached_flags(
 	struct xfs_buftarg	*target,
 	xfs_daddr_t		daddr,
 	size_t			numblks,
 	int			flags,
 	struct xfs_buf		**bpp,
-	const struct xfs_buf_ops *ops)
+	const struct xfs_buf_ops *ops,
+	int			bflags)
 {
 	struct xfs_buf		*bp;
 
@@ -713,7 +714,7 @@  xfs_buf_read_uncached(
 	ASSERT(bp->b_map_count == 1);
 	bp->b_bn = XFS_BUF_DADDR_NULL;  /* always null for uncached buffers */
 	bp->b_maps[0].bm_bn = daddr;
-	bp->b_flags |= XBF_READ;
+	bp->b_flags |= XBF_READ | bflags;
 	bp->b_ops = ops;
 
 	xfs_buf_submit_wait(bp);
@@ -727,6 +728,19 @@  xfs_buf_read_uncached(
 	return 0;
 }
 
+int
+xfs_buf_read_uncached(
+	struct xfs_buftarg	*target,
+	xfs_daddr_t		daddr,
+	size_t			numblks,
+	int			flags,
+	struct xfs_buf		**bpp,
+	const struct xfs_buf_ops *ops)
+{
+	return xfs_buf_read_uncached_flags(target, daddr, numblks, flags, bpp,
+					   ops, 0);
+}
+
 /*
  * Return a buffer allocated as an empty buffer and associated to external
  * memory via xfs_buf_associate_memory() back to it's empty state.
diff --git a/fs/xfs/xfs_buf.h b/fs/xfs/xfs_buf.h
index 8bfb974..a3c7ba4 100644
--- a/fs/xfs/xfs_buf.h
+++ b/fs/xfs/xfs_buf.h
@@ -295,6 +295,10 @@  struct xfs_buf *xfs_buf_get_uncached(struct xfs_buftarg *target, size_t numblks,
 int xfs_buf_read_uncached(struct xfs_buftarg *target, xfs_daddr_t daddr,
 			  size_t numblks, int flags, struct xfs_buf **bpp,
 			  const struct xfs_buf_ops *ops);
+int xfs_buf_read_uncached_flags(struct xfs_buftarg *target, xfs_daddr_t daddr,
+				size_t numblks, int flags, struct xfs_buf **bpp,
+				const struct xfs_buf_ops *ops, int blags);
+
 void xfs_buf_hold(struct xfs_buf *bp);
 
 /* Releasing Buffers */