]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: refactor libxfs_readbuf out of existence
authorDarrick J. Wong <darrick.wong@oracle.com>
Sat, 14 Mar 2020 03:01:00 +0000 (23:01 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Sat, 14 Mar 2020 03:01:00 +0000 (23:01 -0400)
The two libxfs_readbuf* functions are awfully similar, so refactor one
into the other to reduce duplicated code.

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/rdwr.c

index 890eecbdbb13bc593b4e28039980b06400cfbfcf..9429d86ba4a89705e5fbacf97d217eccf26da5ee 100644 (file)
@@ -743,53 +743,6 @@ libxfs_readbuf_verify(
        return bp->b_error;
 }
 
-static struct xfs_buf *
-libxfs_readbuf(
-       struct xfs_buftarg      *btp,
-       xfs_daddr_t             blkno,
-       size_t                  len,
-       int                     flags,
-       const struct xfs_buf_ops *ops)
-{
-       struct xfs_buf          *bp;
-       int                     error;
-
-       error = libxfs_getbuf_flags(btp, blkno, len, 0, &bp);
-       if (error)
-               return NULL;
-
-       /*
-        * if the buffer was prefetched, it is likely that it was not validated.
-        * Hence if we are supplied an ops function and the buffer is marked as
-        * unchecked, we need to validate it now.
-        *
-        * We do this verification even if the buffer is dirty - the
-        * verification is almost certainly going to fail the CRC check in this
-        * case as a dirty buffer has not had the CRC recalculated. However, we
-        * should not be dirtying unchecked buffers and therefore failing it
-        * here because it's dirty and unchecked indicates we've screwed up
-        * somewhere else.
-        */
-       bp->b_error = 0;
-       if ((bp->b_flags & (LIBXFS_B_UPTODATE|LIBXFS_B_DIRTY))) {
-               if (bp->b_flags & LIBXFS_B_UNCHECKED)
-                       libxfs_readbuf_verify(bp, ops);
-               return bp;
-       }
-
-       /*
-        * Set the ops on a cache miss (i.e. first physical read) as the
-        * verifier may change the ops to match the type of buffer it contains.
-        * A cache hit might reset the verifier to the original type if we set
-        * it again, but it won't get called again and set to match the buffer
-        * contents. *cough* xfs_da_node_buf_ops *cough*.
-        */
-       error = libxfs_readbufr(btp, blkno, bp, len, flags);
-       if (!error)
-               libxfs_readbuf_verify(bp, ops);
-       return bp;
-}
-
 int
 libxfs_readbufr_map(struct xfs_buftarg *btp, struct xfs_buf *bp, int flags)
 {
@@ -830,20 +783,44 @@ libxfs_buf_read_map(struct xfs_buftarg *btp, struct xfs_buf_map *map, int nmaps,
        int             error = 0;
 
        if (nmaps == 1)
-               return libxfs_readbuf(btp, map[0].bm_bn, map[0].bm_len,
-                                       flags, ops);
-
-       error = __libxfs_buf_get_map(btp, map, nmaps, 0, &bp);
+               error = libxfs_getbuf_flags(btp, map[0].bm_bn, map[0].bm_len,
+                               0, &bp);
+       else
+               error = __libxfs_buf_get_map(btp, map, nmaps, 0, &bp);
        if (error)
                return NULL;
 
+       /*
+        * If the buffer was prefetched, it is likely that it was not validated.
+        * Hence if we are supplied an ops function and the buffer is marked as
+        * unchecked, we need to validate it now.
+        *
+        * We do this verification even if the buffer is dirty - the
+        * verification is almost certainly going to fail the CRC check in this
+        * case as a dirty buffer has not had the CRC recalculated. However, we
+        * should not be dirtying unchecked buffers and therefore failing it
+        * here because it's dirty and unchecked indicates we've screwed up
+        * somewhere else.
+        */
        bp->b_error = 0;
-       if ((bp->b_flags & (LIBXFS_B_UPTODATE|LIBXFS_B_DIRTY))) {
+       if (bp->b_flags & (LIBXFS_B_UPTODATE | LIBXFS_B_DIRTY)) {
                if (bp->b_flags & LIBXFS_B_UNCHECKED)
                        libxfs_readbuf_verify(bp, ops);
                return bp;
        }
-       error = libxfs_readbufr_map(btp, bp, flags);
+
+       /*
+        * Set the ops on a cache miss (i.e. first physical read) as the
+        * verifier may change the ops to match the type of buffer it contains.
+        * A cache hit might reset the verifier to the original type if we set
+        * it again, but it won't get called again and set to match the buffer
+        * contents. *cough* xfs_da_node_buf_ops *cough*.
+        */
+       if (nmaps == 1)
+               error = libxfs_readbufr(btp, map[0].bm_bn, bp, map[0].bm_len,
+                               flags);
+       else
+               error = libxfs_readbufr_map(btp, bp, flags);
        if (!error)
                libxfs_readbuf_verify(bp, ops);