]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: make libxfs_buf_get_map return an error code
authorDarrick J. Wong <darrick.wong@oracle.com>
Sat, 14 Mar 2020 03:00:59 +0000 (23:00 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Sat, 14 Mar 2020 03:00:59 +0000 (23:00 -0400)
Convert libxfs_buf_get_map() to return numeric error codes like most
everywhere else in xfsprogs.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/libxfs_io.h
libxfs/rdwr.c
libxfs/trans.c
repair/prefetch.c

index a0605882bcd210d94d8dfd78755ddc33b5b02c8b..98bce31170fc3d3b4c5bf821a47b753b779c95ef 100644 (file)
@@ -139,9 +139,9 @@ extern struct cache_operations      libxfs_bcache_operations;
 #define libxfs_buf_get(dev, daddr, len) \
        libxfs_trace_getbuf(__FUNCTION__, __FILE__, __LINE__, \
                            (dev), (daddr), (len))
-#define libxfs_buf_get_map(dev, map, nmaps, flags) \
+#define libxfs_buf_get_map(dev, map, nmaps, flags, bpp) \
        libxfs_trace_getbuf_map(__FUNCTION__, __FILE__, __LINE__, \
-                           (dev), (map), (nmaps), (flags))
+                           (dev), (map), (nmaps), (flags), (bpp))
 #define libxfs_buf_relse(buf) \
        libxfs_trace_putbuf(__FUNCTION__, __FILE__, __LINE__, (buf))
 
@@ -156,8 +156,9 @@ void libxfs_trace_dirtybuf(const char *func, const char *file, int line,
 struct xfs_buf *libxfs_trace_getbuf(const char *func, const char *file,
                        int line, struct xfs_buftarg *btp, xfs_daddr_t daddr,
                        size_t len);
-extern xfs_buf_t *libxfs_trace_getbuf_map(const char *, const char *, int,
-                       struct xfs_buftarg *, struct xfs_buf_map *, int, int);
+int libxfs_trace_getbuf_map(const char *func, const char *file, int line,
+                       struct xfs_buftarg *btp, struct xfs_buf_map *map,
+                       int nmaps, int flags, struct xfs_buf **bpp);
 extern void    libxfs_trace_putbuf (const char *, const char *, int,
                        xfs_buf_t *);
 
@@ -167,8 +168,8 @@ struct xfs_buf *libxfs_buf_read_map(struct xfs_buftarg *btp,
                        struct xfs_buf_map *map, int nmaps, int flags,
                        const struct xfs_buf_ops *ops);
 void libxfs_buf_mark_dirty(struct xfs_buf *bp);
-struct xfs_buf *libxfs_buf_get_map(struct xfs_buftarg *btp,
-                       struct xfs_buf_map *map, int nmaps, int flags);
+int libxfs_buf_get_map(struct xfs_buftarg *btp, struct xfs_buf_map *maps,
+                       int nmaps, int flags, struct xfs_buf **bpp);
 void   libxfs_buf_relse(struct xfs_buf *bp);
 
 static inline struct xfs_buf*
@@ -177,9 +178,14 @@ libxfs_buf_get(
        xfs_daddr_t             blkno,
        size_t                  numblks)
 {
+       struct xfs_buf          *bp;
+       int                     error;
        DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
 
-       return libxfs_buf_get_map(target, &map, 1, 0);
+       error = libxfs_buf_get_map(target, &map, 1, 0, &bp);
+       if (error)
+               return NULL;
+       return bp;
 }
 
 static inline struct xfs_buf*
index c102f124abe6f28d21f4098bd30d8ee8d07e2771..890eecbdbb13bc593b4e28039980b06400cfbfcf 100644 (file)
@@ -162,10 +162,9 @@ struct xfs_buf     *libxfs_buf_read_map(struct xfs_buftarg *btp,
                        struct xfs_buf_map *map, int nmaps, int flags,
                        const struct xfs_buf_ops *ops);
 int            libxfs_writebuf(xfs_buf_t *, int);
-struct xfs_buf *libxfs_buf_get(struct xfs_buftarg *btp, xfs_daddr_t daddr,
-                               size_t len);
-struct xfs_buf *libxfs_buf_get_map(struct xfs_buftarg *btp,
-                       struct xfs_buf_map *map, int nmaps, int flags);
+int            libxfs_buf_get_map(struct xfs_buftarg *btp,
+                               struct xfs_buf_map *maps, int nmaps, int flags,
+                               struct xfs_buf **bpp);
 void           libxfs_buf_relse(struct xfs_buf *bp);
 
 #define        __add_trace(bp, func, file, line)       \
@@ -219,19 +218,27 @@ libxfs_trace_getbuf(
        struct xfs_buf          *bp;
        DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
 
-       bp = libxfs_buf_get_map(target, &map, 1, 0);
+       libxfs_buf_get_map(target, &map, 1, 0, &bp);
        __add_trace(bp, func, file, line);
        return bp;
 }
 
-xfs_buf_t *
-libxfs_trace_getbuf_map(const char *func, const char *file, int line,
-               struct xfs_buftarg *btp, struct xfs_buf_map *map, int nmaps,
-               int flags)
+int
+libxfs_trace_getbuf_map(
+       const char              *func,
+       const char              *file,
+       int                     line,
+       struct xfs_buftarg      *btp,
+       struct xfs_buf_map      *map,
+       int                     nmaps,
+       int                     flags,
+       struct xfs_buf          **bpp)
 {
-       xfs_buf_t       *bp = libxfs_buf_get_map(btp, map, nmaps, flags);
-       __add_trace(bp, func, file, line);
-       return bp;
+       int                     error;
+
+       error = libxfs_buf_get_map(btp, map, nmaps, flags, bpp);
+       __add_trace(*bpp, func, file, line);
+       return error;
 }
 
 void
@@ -582,25 +589,20 @@ reset_buf_state(
                                LIBXFS_B_UPTODATE);
 }
 
-static struct xfs_buf *
+static int
 __libxfs_buf_get_map(
        struct xfs_buftarg      *btp,
        struct xfs_buf_map      *map,
        int                     nmaps,
-       int                     flags)
+       int                     flags,
+       struct xfs_buf          **bpp)
 {
        struct xfs_bufkey       key = {NULL};
-       struct xfs_buf          *bp;
        int                     i;
-       int                     error;
 
-       if (nmaps == 1) {
-               error = libxfs_getbuf_flags(btp, map[0].bm_bn, map[0].bm_len,
-                               flags, &bp);
-               if (error)
-                       return NULL;
-               return bp;
-       }
+       if (nmaps == 1)
+               return libxfs_getbuf_flags(btp, map[0].bm_bn, map[0].bm_len,
+                               flags, bpp);
 
        key.buftarg = btp;
        key.blkno = map[0].bm_bn;
@@ -610,21 +612,25 @@ __libxfs_buf_get_map(
        key.map = map;
        key.nmaps = nmaps;
 
-       error = __cache_lookup(&key, flags, &bp);
-       if (error)
-               return NULL;
-       return bp;
+       return __cache_lookup(&key, flags, bpp);
 }
 
-struct xfs_buf *
-libxfs_buf_get_map(struct xfs_buftarg *btp, struct xfs_buf_map *map,
-                 int nmaps, int flags)
+int
+libxfs_buf_get_map(
+       struct xfs_buftarg      *btp,
+       struct xfs_buf_map      *map,
+       int                     nmaps,
+       int                     flags,
+       struct xfs_buf          **bpp)
 {
-       struct xfs_buf  *bp;
+       int                     error;
 
-       bp = __libxfs_buf_get_map(btp, map, nmaps, flags);
-       reset_buf_state(bp);
-       return bp;
+       error = __libxfs_buf_get_map(btp, map, nmaps, flags, bpp);
+       if (error)
+               return error;
+
+       reset_buf_state(*bpp);
+       return 0;
 }
 
 void
@@ -827,8 +833,8 @@ libxfs_buf_read_map(struct xfs_buftarg *btp, struct xfs_buf_map *map, int nmaps,
                return libxfs_readbuf(btp, map[0].bm_bn, map[0].bm_len,
                                        flags, ops);
 
-       bp = __libxfs_buf_get_map(btp, map, nmaps, 0);
-       if (!bp)
+       error = __libxfs_buf_get_map(btp, map, nmaps, 0, &bp);
+       if (error)
                return NULL;
 
        bp->b_error = 0;
index b78bca865bfcebc4de12b5ac394d8d8c28f89ca1..21dd66cbf7d2f5544eb3415662d4176b20854ea7 100644 (file)
@@ -423,11 +423,16 @@ libxfs_trans_get_buf_map(
        int                     nmaps,
        xfs_buf_flags_t         flags)
 {
-       xfs_buf_t               *bp;
+       struct xfs_buf          *bp;
        struct xfs_buf_log_item *bip;
+       int                     error;
 
-       if (!tp)
-               return libxfs_buf_get_map(target, map, nmaps, 0);
+       if (!tp) {
+               error = libxfs_buf_get_map(target, map, nmaps, 0, &bp);
+               if (error)
+                       return NULL;
+               return bp;
+       }
 
        /*
         * If we find the buffer in the cache with this transaction
@@ -445,10 +450,9 @@ libxfs_trans_get_buf_map(
                return bp;
        }
 
-       bp = libxfs_buf_get_map(target, map, nmaps, 0);
-       if (bp == NULL) {
+       error = libxfs_buf_get_map(target, map, nmaps, 0, &bp);
+       if (error)
                return NULL;
-       }
 
        ASSERT(!bp->b_error);
 
index 243d03a7fbb23eb0e685560868b0be8d3d178976..d310805012b2ba292f32057b2f743bc7e5f41c6e 100644 (file)
@@ -113,6 +113,7 @@ pf_queue_io(
 {
        struct xfs_buf          *bp;
        xfs_fsblock_t           fsbno = XFS_DADDR_TO_FSB(mp, map[0].bm_bn);
+       int                     error;
 
        /*
         * Never block on a buffer lock here, given that the actual repair
@@ -120,8 +121,9 @@ pf_queue_io(
         * the lock holder is either reading it from disk himself or
         * completely overwriting it this behaviour is perfectly fine.
         */
-       bp = libxfs_buf_get_map(mp->m_dev, map, nmaps, LIBXFS_GETBUF_TRYLOCK);
-       if (!bp)
+       error = -libxfs_buf_get_map(mp->m_dev, map, nmaps,
+                       LIBXFS_GETBUF_TRYLOCK, &bp);
+       if (error)
                return;
 
        if (bp->b_flags & LIBXFS_B_UPTODATE) {