Skip to content

Commit 99be3f6

Browse files
committed
Merge tag 'xfs-5.6-merge-8' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull moar xfs updates from Darrick Wong: "This contains the buffer error code refactoring I mentioned last week, now that it has had extra time to complete the full xfs fuzz testing suite to make sure there aren't any obvious new bugs" * tag 'xfs-5.6-merge-8' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: xfs: fix xfs_buf_ioerror_alert location reporting xfs: remove unnecessary null pointer checks from _read_agf callers xfs: make xfs_*read_agf return EAGAIN to ALLOC_FLAG_TRYLOCK callers xfs: remove the xfs_btree_get_buf[ls] functions xfs: make xfs_trans_get_buf return an error code xfs: make xfs_trans_get_buf_map return an error code xfs: make xfs_buf_read return an error code xfs: make xfs_buf_get_uncached return an error code xfs: make xfs_buf_get return an error code xfs: make xfs_buf_read_map return an error code xfs: make xfs_buf_get_map return an error code xfs: make xfs_buf_alloc return an error code
2 parents e310396 + cdbcf82 commit 99be3f6

27 files changed

+278
-365
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/libxfs/xfs_alloc.c

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,11 +1070,11 @@ xfs_alloc_ag_vextent_small(
10701070
if (args->datatype & XFS_ALLOC_USERDATA) {
10711071
struct xfs_buf *bp;
10721072

1073-
bp = xfs_btree_get_bufs(args->mp, args->tp, args->agno, fbno);
1074-
if (XFS_IS_CORRUPT(args->mp, !bp)) {
1075-
error = -EFSCORRUPTED;
1073+
error = xfs_trans_get_buf(args->tp, args->mp->m_ddev_targp,
1074+
XFS_AGB_TO_DADDR(args->mp, args->agno, fbno),
1075+
args->mp->m_bsize, 0, &bp);
1076+
if (error)
10761077
goto error;
1077-
}
10781078
xfs_trans_binval(args->tp, bp);
10791079
}
10801080
*fbnop = args->agbno = fbno;
@@ -2347,9 +2347,11 @@ xfs_free_agfl_block(
23472347
if (error)
23482348
return error;
23492349

2350-
bp = xfs_btree_get_bufs(tp->t_mountp, tp, agno, agbno);
2351-
if (XFS_IS_CORRUPT(tp->t_mountp, !bp))
2352-
return -EFSCORRUPTED;
2350+
error = xfs_trans_get_buf(tp, tp->t_mountp->m_ddev_targp,
2351+
XFS_AGB_TO_DADDR(tp->t_mountp, agno, agbno),
2352+
tp->t_mountp->m_bsize, 0, &bp);
2353+
if (error)
2354+
return error;
23532355
xfs_trans_binval(tp, bp);
23542356

23552357
return 0;
@@ -2500,12 +2502,11 @@ xfs_alloc_fix_freelist(
25002502

25012503
if (!pag->pagf_init) {
25022504
error = xfs_alloc_read_agf(mp, tp, args->agno, flags, &agbp);
2503-
if (error)
2505+
if (error) {
2506+
/* Couldn't lock the AGF so skip this AG. */
2507+
if (error == -EAGAIN)
2508+
error = 0;
25042509
goto out_no_agbp;
2505-
if (!pag->pagf_init) {
2506-
ASSERT(flags & XFS_ALLOC_FLAG_TRYLOCK);
2507-
ASSERT(!(flags & XFS_ALLOC_FLAG_FREEING));
2508-
goto out_agbp_relse;
25092510
}
25102511
}
25112512

@@ -2531,11 +2532,10 @@ xfs_alloc_fix_freelist(
25312532
*/
25322533
if (!agbp) {
25332534
error = xfs_alloc_read_agf(mp, tp, args->agno, flags, &agbp);
2534-
if (error)
2535-
goto out_no_agbp;
2536-
if (!agbp) {
2537-
ASSERT(flags & XFS_ALLOC_FLAG_TRYLOCK);
2538-
ASSERT(!(flags & XFS_ALLOC_FLAG_FREEING));
2535+
if (error) {
2536+
/* Couldn't lock the AGF so skip this AG. */
2537+
if (error == -EAGAIN)
2538+
error = 0;
25392539
goto out_no_agbp;
25402540
}
25412541
}
@@ -2766,11 +2766,10 @@ xfs_alloc_pagf_init(
27662766
xfs_buf_t *bp;
27672767
int error;
27682768

2769-
if ((error = xfs_alloc_read_agf(mp, tp, agno, flags, &bp)))
2770-
return error;
2771-
if (bp)
2769+
error = xfs_alloc_read_agf(mp, tp, agno, flags, &bp);
2770+
if (!error)
27722771
xfs_trans_brelse(tp, bp);
2773-
return 0;
2772+
return error;
27742773
}
27752774

27762775
/*
@@ -2956,14 +2955,11 @@ xfs_read_agf(
29562955
trace_xfs_read_agf(mp, agno);
29572956

29582957
ASSERT(agno != NULLAGNUMBER);
2959-
error = xfs_trans_read_buf(
2960-
mp, tp, mp->m_ddev_targp,
2958+
error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
29612959
XFS_AG_DADDR(mp, agno, XFS_AGF_DADDR(mp)),
29622960
XFS_FSS_TO_BB(mp, 1), flags, bpp, &xfs_agf_buf_ops);
29632961
if (error)
29642962
return error;
2965-
if (!*bpp)
2966-
return 0;
29672963

29682964
ASSERT(!(*bpp)->b_error);
29692965
xfs_buf_set_ref(*bpp, XFS_AGF_REF);
@@ -2987,14 +2983,15 @@ xfs_alloc_read_agf(
29872983

29882984
trace_xfs_alloc_read_agf(mp, agno);
29892985

2986+
/* We don't support trylock when freeing. */
2987+
ASSERT((flags & (XFS_ALLOC_FLAG_FREEING | XFS_ALLOC_FLAG_TRYLOCK)) !=
2988+
(XFS_ALLOC_FLAG_FREEING | XFS_ALLOC_FLAG_TRYLOCK));
29902989
ASSERT(agno != NULLAGNUMBER);
29912990
error = xfs_read_agf(mp, tp, agno,
29922991
(flags & XFS_ALLOC_FLAG_TRYLOCK) ? XBF_TRYLOCK : 0,
29932992
bpp);
29942993
if (error)
29952994
return error;
2996-
if (!*bpp)
2997-
return 0;
29982995
ASSERT(!(*bpp)->b_error);
29992996

30002997
agf = XFS_BUF_TO_AGF(*bpp);

fs/xfs/libxfs/xfs_attr_remote.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -418,20 +418,10 @@ xfs_attr_rmtval_get(
418418
(map[i].br_startblock != HOLESTARTBLOCK));
419419
dblkno = XFS_FSB_TO_DADDR(mp, map[i].br_startblock);
420420
dblkcnt = XFS_FSB_TO_BB(mp, map[i].br_blockcount);
421-
bp = xfs_buf_read(mp->m_ddev_targp, dblkno, dblkcnt, 0,
422-
&xfs_attr3_rmt_buf_ops);
423-
if (!bp)
424-
return -ENOMEM;
425-
error = bp->b_error;
426-
if (error) {
427-
xfs_buf_ioerror_alert(bp, __func__);
428-
xfs_buf_relse(bp);
429-
430-
/* bad CRC means corrupted metadata */
431-
if (error == -EFSBADCRC)
432-
error = -EFSCORRUPTED;
421+
error = xfs_buf_read(mp->m_ddev_targp, dblkno, dblkcnt,
422+
0, &bp, &xfs_attr3_rmt_buf_ops);
423+
if (error)
433424
return error;
434-
}
435425

436426
error = xfs_attr_rmtval_copyout(mp, bp, args->dp->i_ino,
437427
&offset, &valuelen,
@@ -555,9 +545,9 @@ xfs_attr_rmtval_set(
555545
dblkno = XFS_FSB_TO_DADDR(mp, map.br_startblock),
556546
dblkcnt = XFS_FSB_TO_BB(mp, map.br_blockcount);
557547

558-
bp = xfs_buf_get(mp->m_ddev_targp, dblkno, dblkcnt);
559-
if (!bp)
560-
return -ENOMEM;
548+
error = xfs_buf_get(mp->m_ddev_targp, dblkno, dblkcnt, &bp);
549+
if (error)
550+
return error;
561551
bp->b_ops = &xfs_attr3_rmt_buf_ops;
562552

563553
xfs_attr_rmtval_copyin(mp, bp, args->dp->i_ino, &offset,

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -730,11 +730,11 @@ xfs_bmap_extents_to_btree(
730730
cur->bc_private.b.allocated++;
731731
ip->i_d.di_nblocks++;
732732
xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, 1L);
733-
abp = xfs_btree_get_bufl(mp, tp, args.fsbno);
734-
if (XFS_IS_CORRUPT(mp, !abp)) {
735-
error = -EFSCORRUPTED;
733+
error = xfs_trans_get_buf(tp, mp->m_ddev_targp,
734+
XFS_FSB_TO_DADDR(mp, args.fsbno),
735+
mp->m_bsize, 0, &abp);
736+
if (error)
736737
goto out_unreserve_dquot;
737-
}
738738

739739
/*
740740
* Fill in the child block.
@@ -878,7 +878,11 @@ xfs_bmap_local_to_extents(
878878
ASSERT(args.fsbno != NULLFSBLOCK);
879879
ASSERT(args.len == 1);
880880
tp->t_firstblock = args.fsbno;
881-
bp = xfs_btree_get_bufl(args.mp, tp, args.fsbno);
881+
error = xfs_trans_get_buf(tp, args.mp->m_ddev_targp,
882+
XFS_FSB_TO_DADDR(args.mp, args.fsbno),
883+
args.mp->m_bsize, 0, &bp);
884+
if (error)
885+
goto done;
882886

883887
/*
884888
* Initialize the block, copy the data and log the remote buffer.
@@ -3307,11 +3311,12 @@ xfs_bmap_longest_free_extent(
33073311
pag = xfs_perag_get(mp, ag);
33083312
if (!pag->pagf_init) {
33093313
error = xfs_alloc_pagf_init(mp, tp, ag, XFS_ALLOC_FLAG_TRYLOCK);
3310-
if (error)
3311-
goto out;
3312-
3313-
if (!pag->pagf_init) {
3314-
*notinit = 1;
3314+
if (error) {
3315+
/* Couldn't lock the AGF, so skip this AG. */
3316+
if (error == -EAGAIN) {
3317+
*notinit = 1;
3318+
error = 0;
3319+
}
33153320
goto out;
33163321
}
33173322
}

fs/xfs/libxfs/xfs_btree.c

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -678,42 +678,6 @@ xfs_btree_get_block(
678678
return XFS_BUF_TO_BLOCK(*bpp);
679679
}
680680

681-
/*
682-
* Get a buffer for the block, return it with no data read.
683-
* Long-form addressing.
684-
*/
685-
xfs_buf_t * /* buffer for fsbno */
686-
xfs_btree_get_bufl(
687-
xfs_mount_t *mp, /* file system mount point */
688-
xfs_trans_t *tp, /* transaction pointer */
689-
xfs_fsblock_t fsbno) /* file system block number */
690-
{
691-
xfs_daddr_t d; /* real disk block address */
692-
693-
ASSERT(fsbno != NULLFSBLOCK);
694-
d = XFS_FSB_TO_DADDR(mp, fsbno);
695-
return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0);
696-
}
697-
698-
/*
699-
* Get a buffer for the block, return it with no data read.
700-
* Short-form addressing.
701-
*/
702-
xfs_buf_t * /* buffer for agno/agbno */
703-
xfs_btree_get_bufs(
704-
xfs_mount_t *mp, /* file system mount point */
705-
xfs_trans_t *tp, /* transaction pointer */
706-
xfs_agnumber_t agno, /* allocation group number */
707-
xfs_agblock_t agbno) /* allocation group block number */
708-
{
709-
xfs_daddr_t d; /* real disk block address */
710-
711-
ASSERT(agno != NULLAGNUMBER);
712-
ASSERT(agbno != NULLAGBLOCK);
713-
d = XFS_AGB_TO_DADDR(mp, agno, agbno);
714-
return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0);
715-
}
716-
717681
/*
718682
* Change the cursor to point to the first record at the given level.
719683
* Other levels are unaffected.
@@ -1270,11 +1234,10 @@ xfs_btree_get_buf_block(
12701234
error = xfs_btree_ptr_to_daddr(cur, ptr, &d);
12711235
if (error)
12721236
return error;
1273-
*bpp = xfs_trans_get_buf(cur->bc_tp, mp->m_ddev_targp, d,
1274-
mp->m_bsize, 0);
1275-
1276-
if (!*bpp)
1277-
return -ENOMEM;
1237+
error = xfs_trans_get_buf(cur->bc_tp, mp->m_ddev_targp, d, mp->m_bsize,
1238+
0, bpp);
1239+
if (error)
1240+
return error;
12781241

12791242
(*bpp)->b_ops = cur->bc_ops->buf_ops;
12801243
*block = XFS_BUF_TO_BLOCK(*bpp);

fs/xfs/libxfs/xfs_btree.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -296,27 +296,6 @@ xfs_btree_dup_cursor(
296296
xfs_btree_cur_t *cur, /* input cursor */
297297
xfs_btree_cur_t **ncur);/* output cursor */
298298

299-
/*
300-
* Get a buffer for the block, return it with no data read.
301-
* Long-form addressing.
302-
*/
303-
struct xfs_buf * /* buffer for fsbno */
304-
xfs_btree_get_bufl(
305-
struct xfs_mount *mp, /* file system mount point */
306-
struct xfs_trans *tp, /* transaction pointer */
307-
xfs_fsblock_t fsbno); /* file system block number */
308-
309-
/*
310-
* Get a buffer for the block, return it with no data read.
311-
* Short-form addressing.
312-
*/
313-
struct xfs_buf * /* buffer for agno/agbno */
314-
xfs_btree_get_bufs(
315-
struct xfs_mount *mp, /* file system mount point */
316-
struct xfs_trans *tp, /* transaction pointer */
317-
xfs_agnumber_t agno, /* allocation group number */
318-
xfs_agblock_t agbno); /* allocation group block number */
319-
320299
/*
321300
* Compute first and last byte offsets for the fields given.
322301
* Interprets the offsets table, which contains struct field offsets.

fs/xfs/libxfs/xfs_da_btree.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,13 +2591,9 @@ xfs_da_get_buf(
25912591
if (error || nmap == 0)
25922592
goto out_free;
25932593

2594-
bp = xfs_trans_get_buf_map(tp, mp->m_ddev_targp, mapp, nmap, 0);
2595-
error = bp ? bp->b_error : -EIO;
2596-
if (error) {
2597-
if (bp)
2598-
xfs_trans_brelse(tp, bp);
2594+
error = xfs_trans_get_buf_map(tp, mp->m_ddev_targp, mapp, nmap, 0, &bp);
2595+
if (error)
25992596
goto out_free;
2600-
}
26012597

26022598
*bpp = bp;
26032599

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ xfs_ialloc_inode_init(
276276
int i, j;
277277
xfs_daddr_t d;
278278
xfs_ino_t ino = 0;
279+
int error;
279280

280281
/*
281282
* Loop over the new block(s), filling in the inodes. For small block
@@ -327,12 +328,11 @@ xfs_ialloc_inode_init(
327328
*/
328329
d = XFS_AGB_TO_DADDR(mp, agno, agbno +
329330
(j * M_IGEO(mp)->blocks_per_cluster));
330-
fbuf = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
331-
mp->m_bsize *
332-
M_IGEO(mp)->blocks_per_cluster,
333-
XBF_UNMAPPED);
334-
if (!fbuf)
335-
return -ENOMEM;
331+
error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
332+
mp->m_bsize * M_IGEO(mp)->blocks_per_cluster,
333+
XBF_UNMAPPED, &fbuf);
334+
if (error)
335+
return error;
336336

337337
/* Initialize the inode buffers and log them appropriately. */
338338
fbuf->b_ops = &xfs_inode_buf_ops;

fs/xfs/libxfs/xfs_refcount.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,6 @@ xfs_refcount_finish_one(
11771177
XFS_ALLOC_FLAG_FREEING, &agbp);
11781178
if (error)
11791179
return error;
1180-
if (XFS_IS_CORRUPT(tp->t_mountp, !agbp))
1181-
return -EFSCORRUPTED;
11821180

11831181
rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno);
11841182
if (!rcur) {
@@ -1718,10 +1716,6 @@ xfs_refcount_recover_cow_leftovers(
17181716
error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp);
17191717
if (error)
17201718
goto out_trans;
1721-
if (!agbp) {
1722-
error = -ENOMEM;
1723-
goto out_trans;
1724-
}
17251719
cur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno);
17261720

17271721
/* Find all the leftover CoW staging extents. */

0 commit comments

Comments
 (0)