Skip to content

Commit 2842b6d

Browse files
committed
xfs: make xfs_buf_get_uncached return an error code
Convert xfs_buf_get_uncached() to return numeric error codes like most everywhere else in xfs. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Dave Chinner <[email protected]>
1 parent 841263e commit 2842b6d

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

fs/xfs/libxfs/xfs_ag.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,28 @@
2323
#include "xfs_ag_resv.h"
2424
#include "xfs_health.h"
2525

26-
static struct xfs_buf *
26+
static int
2727
xfs_get_aghdr_buf(
2828
struct xfs_mount *mp,
2929
xfs_daddr_t blkno,
3030
size_t numblks,
31+
struct xfs_buf **bpp,
3132
const struct xfs_buf_ops *ops)
3233
{
3334
struct xfs_buf *bp;
35+
int error;
3436

35-
bp = xfs_buf_get_uncached(mp->m_ddev_targp, numblks, 0);
36-
if (!bp)
37-
return NULL;
37+
error = xfs_buf_get_uncached(mp->m_ddev_targp, numblks, 0, &bp);
38+
if (error)
39+
return error;
3840

3941
xfs_buf_zero(bp, 0, BBTOB(bp->b_length));
4042
bp->b_bn = blkno;
4143
bp->b_maps[0].bm_bn = blkno;
4244
bp->b_ops = ops;
4345

44-
return bp;
46+
*bpp = bp;
47+
return 0;
4548
}
4649

4750
static inline bool is_log_ag(struct xfs_mount *mp, struct aghdr_init_data *id)
@@ -340,13 +343,13 @@ xfs_ag_init_hdr(
340343
struct aghdr_init_data *id,
341344
aghdr_init_work_f work,
342345
const struct xfs_buf_ops *ops)
343-
344346
{
345347
struct xfs_buf *bp;
348+
int error;
346349

347-
bp = xfs_get_aghdr_buf(mp, id->daddr, id->numblks, ops);
348-
if (!bp)
349-
return -ENOMEM;
350+
error = xfs_get_aghdr_buf(mp, id->daddr, id->numblks, &bp, ops);
351+
if (error)
352+
return error;
350353

351354
(*work)(mp, bp, id);
352355

fs/xfs/xfs_buf.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -902,12 +902,13 @@ xfs_buf_read_uncached(
902902
const struct xfs_buf_ops *ops)
903903
{
904904
struct xfs_buf *bp;
905+
int error;
905906

906907
*bpp = NULL;
907908

908-
bp = xfs_buf_get_uncached(target, numblks, flags);
909-
if (!bp)
910-
return -ENOMEM;
909+
error = xfs_buf_get_uncached(target, numblks, flags, &bp);
910+
if (error)
911+
return error;
911912

912913
/* set up the buffer for a read IO */
913914
ASSERT(bp->b_map_count == 1);
@@ -918,7 +919,7 @@ xfs_buf_read_uncached(
918919

919920
xfs_buf_submit(bp);
920921
if (bp->b_error) {
921-
int error = bp->b_error;
922+
error = bp->b_error;
922923
xfs_buf_relse(bp);
923924
return error;
924925
}
@@ -927,17 +928,20 @@ xfs_buf_read_uncached(
927928
return 0;
928929
}
929930

930-
xfs_buf_t *
931+
int
931932
xfs_buf_get_uncached(
932933
struct xfs_buftarg *target,
933934
size_t numblks,
934-
int flags)
935+
int flags,
936+
struct xfs_buf **bpp)
935937
{
936938
unsigned long page_count;
937939
int error, i;
938940
struct xfs_buf *bp;
939941
DEFINE_SINGLE_BUF_MAP(map, XFS_BUF_DADDR_NULL, numblks);
940942

943+
*bpp = NULL;
944+
941945
/* flags might contain irrelevant bits, pass only what we care about */
942946
error = _xfs_buf_alloc(target, &map, 1, flags & XBF_NO_IOACCT, &bp);
943947
if (error)
@@ -950,8 +954,10 @@ xfs_buf_get_uncached(
950954

951955
for (i = 0; i < page_count; i++) {
952956
bp->b_pages[i] = alloc_page(xb_to_gfp(flags));
953-
if (!bp->b_pages[i])
957+
if (!bp->b_pages[i]) {
958+
error = -ENOMEM;
954959
goto fail_free_mem;
960+
}
955961
}
956962
bp->b_flags |= _XBF_PAGES;
957963

@@ -963,7 +969,8 @@ xfs_buf_get_uncached(
963969
}
964970

965971
trace_xfs_buf_get_uncached(bp, _RET_IP_);
966-
return bp;
972+
*bpp = bp;
973+
return 0;
967974

968975
fail_free_mem:
969976
while (--i >= 0)
@@ -973,7 +980,7 @@ xfs_buf_get_uncached(
973980
xfs_buf_free_maps(bp);
974981
kmem_cache_free(xfs_buf_zone, bp);
975982
fail:
976-
return NULL;
983+
return error;
977984
}
978985

979986
/*

fs/xfs/xfs_buf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ xfs_buf_readahead(
242242
return xfs_buf_readahead_map(target, &map, 1, ops);
243243
}
244244

245-
struct xfs_buf *xfs_buf_get_uncached(struct xfs_buftarg *target, size_t numblks,
246-
int flags);
245+
int xfs_buf_get_uncached(struct xfs_buftarg *target, size_t numblks, int flags,
246+
struct xfs_buf **bpp);
247247
int xfs_buf_read_uncached(struct xfs_buftarg *target, xfs_daddr_t daddr,
248248
size_t numblks, int flags, struct xfs_buf **bpp,
249249
const struct xfs_buf_ops *ops);

0 commit comments

Comments
 (0)