]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: refactor libxfs_buf_read_map for xfs_db
authorDave Chinner <dchinner@redhat.com>
Wed, 13 Nov 2013 06:40:43 +0000 (06:40 +0000)
committerRich Johnston <rjohnston@sgi.com>
Wed, 13 Nov 2013 17:10:20 +0000 (11:10 -0600)
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@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Rich Johnston <rjohnston@sgi.com>
include/libxfs.h
libxfs/rdwr.c

index e017b323f4f968b9ae170babe284fe143b5ec8d5..b097bd29db826a223b2e0335d557d9b5b48978e3 100644 (file)
@@ -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;
 
index f5078553a24a3f6d1b9f40bd1dc55f551cc341ef..7eaea0ab0379e658017df01c4532b38de65fcd23 100644 (file)
@@ -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)