xfs
[Top] [All Lists]

[PATCH 19/37] libxfs: refactor libxfs_buf_read_map for xfs_db

To: xfs@xxxxxxxxxxx
Subject: [PATCH 19/37] libxfs: refactor libxfs_buf_read_map for xfs_db
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Wed, 6 Nov 2013 12:07:05 +1100
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1383700043-32305-1-git-send-email-david@xxxxxxxxxxxxx>
References: <1383700043-32305-1-git-send-email-david@xxxxxxxxxxxxx>
From: Dave Chinner <dchinner@xxxxxxxxxx>

xfs_db requires low level read/write buffer primitives that are the
equivalent of libxfs_readbufr/writebufr. The implementation of
libxfs_writebufr already handles discontiguous buffers, but there is
no equivalent libxfs_readbufr_map support in the code.

Refactor libxfs_readbuf_map into two parts - one that does the
buffer cache lookup, and the other that does the read IO. This
provides the implementation of libxfs_readbufr_map that is required
for xfs_db.

Signed-off-by: Dave Chinner <dchinner@xxxxxxxxxx>
---
 include/libxfs.h |  3 +++
 libxfs/rdwr.c    | 61 +++++++++++++++++++++++++++++++++++++-------------------
 2 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/include/libxfs.h b/include/libxfs.h
index e017b32..b097bd2 100644
--- a/include/libxfs.h
+++ b/include/libxfs.h
@@ -444,7 +444,10 @@ extern xfs_buf_t *libxfs_getbufr(struct xfs_buftarg *, 
xfs_daddr_t, int);
 extern void    libxfs_putbufr(xfs_buf_t *);
 
 extern int     libxfs_writebuf_int(xfs_buf_t *, int);
+extern int     libxfs_writebufr(struct xfs_buf *);
 extern int     libxfs_readbufr(struct xfs_buftarg *, xfs_daddr_t, xfs_buf_t *, 
int, int);
+extern int     libxfs_readbufr_map(struct xfs_buftarg *, struct xfs_buf *,
+                                   struct xfs_buf_map *, int, int);
 
 extern int libxfs_bhash_size;
 
diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
index f507855..7eaea0a 100644
--- a/libxfs/rdwr.c
+++ b/libxfs/rdwr.c
@@ -719,30 +719,18 @@ libxfs_readbuf(struct xfs_buftarg *btp, xfs_daddr_t 
blkno, int len, int flags,
        return bp;
 }
 
-struct xfs_buf *
-libxfs_readbuf_map(struct xfs_buftarg *btp, struct xfs_buf_map *map, int nmaps,
-               int flags, const struct xfs_buf_ops *ops)
+int
+libxfs_readbufr_map(struct xfs_buftarg *btp, struct xfs_buf *bp,
+                   struct xfs_buf_map *map, int nmaps, int flags)
 {
-       xfs_buf_t       *bp;
-       int             error = 0;
-       int             fd;
-       int             i;
-       char            *buf;
-
-       if (nmaps == 1)
-               return libxfs_readbuf(btp, map[0].bm_bn, map[0].bm_len,
-                                       flags, ops);
-
-       bp = libxfs_getbuf_map(btp, map, nmaps);
-       if (!bp)
-               return NULL;
+       int     fd = libxfs_device_to_fd(btp->dev);
+       int     error = 0;
+       char    *buf;
+       int     i;
 
-       bp->b_error = 0;
-       bp->b_ops = ops;
-       if ((bp->b_flags & (LIBXFS_B_UPTODATE|LIBXFS_B_DIRTY)))
-               return bp;
+       ASSERT(BBTOB(len) <= bp->b_bcount);
 
-       ASSERT(bp->b_nmaps = nmaps);
+       ASSERT(bp->b_nmaps == nmaps);
 
        fd = libxfs_device_to_fd(btp->dev);
        buf = bp->b_addr;
@@ -762,6 +750,37 @@ libxfs_readbuf_map(struct xfs_buftarg *btp, struct 
xfs_buf_map *map, int nmaps,
                offset += len;
        }
 
+       if (!error);
+               bp->b_flags |= LIBXFS_B_UPTODATE;
+#ifdef IO_DEBUG
+       printf("%lx: %s: read %u bytes, error %d, blkno=0x%llx(0x%llx), %p\n",
+               pthread_self(), __FUNCTION__, , error,
+               (long long)LIBXFS_BBTOOFF64(blkno), (long long)blkno, bp);
+#endif
+       return error;
+}
+
+struct xfs_buf *
+libxfs_readbuf_map(struct xfs_buftarg *btp, struct xfs_buf_map *map, int nmaps,
+               int flags, const struct xfs_buf_ops *ops)
+{
+       struct xfs_buf  *bp;
+       int             error = 0;
+
+       if (nmaps == 1)
+               return libxfs_readbuf(btp, map[0].bm_bn, map[0].bm_len,
+                                       flags, ops);
+
+       bp = libxfs_getbuf_map(btp, map, nmaps);
+       if (!bp)
+               return NULL;
+
+       bp->b_error = 0;
+       bp->b_ops = ops;
+       if ((bp->b_flags & (LIBXFS_B_UPTODATE|LIBXFS_B_DIRTY)))
+               return bp;
+
+       error = libxfs_readbufr_map(btp, bp, map, nmaps, flags);
        if (!error) {
                bp->b_flags |= LIBXFS_B_UPTODATE;
                if (bp->b_ops)
-- 
1.8.4.rc3

<Prev in Thread] Current Thread [Next in Thread>