Skip to content

Commit ce92464

Browse files
committed
xfs: make xfs_trans_get_buf return an error code
Convert xfs_trans_get_buf() 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 9676b54 commit ce92464

File tree

10 files changed

+67
-62
lines changed

10 files changed

+67
-62
lines changed

fs/xfs/libxfs/xfs_btree.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -688,11 +688,16 @@ xfs_btree_get_bufl(
688688
xfs_trans_t *tp, /* transaction pointer */
689689
xfs_fsblock_t fsbno) /* file system block number */
690690
{
691+
struct xfs_buf *bp;
691692
xfs_daddr_t d; /* real disk block address */
693+
int error;
692694

693695
ASSERT(fsbno != NULLFSBLOCK);
694696
d = XFS_FSB_TO_DADDR(mp, fsbno);
695-
return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0);
697+
error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, &bp);
698+
if (error)
699+
return NULL;
700+
return bp;
696701
}
697702

698703
/*
@@ -706,12 +711,17 @@ xfs_btree_get_bufs(
706711
xfs_agnumber_t agno, /* allocation group number */
707712
xfs_agblock_t agbno) /* allocation group block number */
708713
{
714+
struct xfs_buf *bp;
709715
xfs_daddr_t d; /* real disk block address */
716+
int error;
710717

711718
ASSERT(agno != NULLAGNUMBER);
712719
ASSERT(agbno != NULLAGBLOCK);
713720
d = XFS_AGB_TO_DADDR(mp, agno, agbno);
714-
return xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0);
721+
error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d, mp->m_bsize, 0, &bp);
722+
if (error)
723+
return NULL;
724+
return bp;
715725
}
716726

717727
/*
@@ -1270,11 +1280,10 @@ xfs_btree_get_buf_block(
12701280
error = xfs_btree_ptr_to_daddr(cur, ptr, &d);
12711281
if (error)
12721282
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;
1283+
error = xfs_trans_get_buf(cur->bc_tp, mp->m_ddev_targp, d, mp->m_bsize,
1284+
0, bpp);
1285+
if (error)
1286+
return error;
12781287

12791288
(*bpp)->b_ops = cur->bc_ops->buf_ops;
12801289
*block = XFS_BUF_TO_BLOCK(*bpp);

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_sb.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,13 +1185,14 @@ xfs_sb_get_secondary(
11851185
struct xfs_buf **bpp)
11861186
{
11871187
struct xfs_buf *bp;
1188+
int error;
11881189

11891190
ASSERT(agno != 0 && agno != NULLAGNUMBER);
1190-
bp = xfs_trans_get_buf(tp, mp->m_ddev_targp,
1191+
error = xfs_trans_get_buf(tp, mp->m_ddev_targp,
11911192
XFS_AG_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
1192-
XFS_FSS_TO_BB(mp, 1), 0);
1193-
if (!bp)
1194-
return -ENOMEM;
1193+
XFS_FSS_TO_BB(mp, 1), 0, &bp);
1194+
if (error)
1195+
return error;
11951196
bp->b_ops = &xfs_sb_buf_ops;
11961197
xfs_buf_oneshot(bp);
11971198
*bpp = bp;

fs/xfs/scrub/repair.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,17 @@ xrep_init_btblock(
341341
struct xfs_trans *tp = sc->tp;
342342
struct xfs_mount *mp = sc->mp;
343343
struct xfs_buf *bp;
344+
int error;
344345

345346
trace_xrep_init_btblock(mp, XFS_FSB_TO_AGNO(mp, fsb),
346347
XFS_FSB_TO_AGBNO(mp, fsb), btnum);
347348

348349
ASSERT(XFS_FSB_TO_AGNO(mp, fsb) == sc->sa.agno);
349-
bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, XFS_FSB_TO_DADDR(mp, fsb),
350-
XFS_FSB_TO_BB(mp, 1), 0);
350+
error = xfs_trans_get_buf(tp, mp->m_ddev_targp,
351+
XFS_FSB_TO_DADDR(mp, fsb), XFS_FSB_TO_BB(mp, 1), 0,
352+
&bp);
353+
if (error)
354+
return error;
351355
xfs_buf_zero(bp, 0, BBTOB(bp->b_length));
352356
xfs_btree_init_block(mp, bp, btnum, 0, 0, sc->sa.agno);
353357
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_BTREE_BUF);

fs/xfs/xfs_attr_inactive.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,12 @@ xfs_attr3_node_inactive(
205205
/*
206206
* Remove the subsidiary block from the cache and from the log.
207207
*/
208-
child_bp = xfs_trans_get_buf(*trans, mp->m_ddev_targp,
208+
error = xfs_trans_get_buf(*trans, mp->m_ddev_targp,
209209
child_blkno,
210-
XFS_FSB_TO_BB(mp, mp->m_attr_geo->fsbcount), 0);
211-
if (!child_bp)
212-
return -EIO;
210+
XFS_FSB_TO_BB(mp, mp->m_attr_geo->fsbcount), 0,
211+
&child_bp);
212+
if (error)
213+
return error;
213214
error = bp->b_error;
214215
if (error) {
215216
xfs_trans_brelse(*trans, child_bp);
@@ -298,10 +299,10 @@ xfs_attr3_root_inactive(
298299
/*
299300
* Invalidate the incore copy of the root block.
300301
*/
301-
bp = xfs_trans_get_buf(*trans, mp->m_ddev_targp, blkno,
302-
XFS_FSB_TO_BB(mp, mp->m_attr_geo->fsbcount), 0);
303-
if (!bp)
304-
return -EIO;
302+
error = xfs_trans_get_buf(*trans, mp->m_ddev_targp, blkno,
303+
XFS_FSB_TO_BB(mp, mp->m_attr_geo->fsbcount), 0, &bp);
304+
if (error)
305+
return error;
305306
error = bp->b_error;
306307
if (error) {
307308
xfs_trans_brelse(*trans, bp);

fs/xfs/xfs_dquot.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ xfs_dquot_disk_alloc(
320320
dqp->q_blkno = XFS_FSB_TO_DADDR(mp, map.br_startblock);
321321

322322
/* now we can just get the buffer (there's nothing to read yet) */
323-
bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, dqp->q_blkno,
324-
mp->m_quotainfo->qi_dqchunklen, 0);
325-
if (!bp)
326-
return -ENOMEM;
323+
error = xfs_trans_get_buf(tp, mp->m_ddev_targp, dqp->q_blkno,
324+
mp->m_quotainfo->qi_dqchunklen, 0, &bp);
325+
if (error)
326+
return error;
327327
bp->b_ops = &xfs_dquot_buf_ops;
328328

329329
/*

fs/xfs/xfs_inode.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2546,6 +2546,7 @@ xfs_ifree_cluster(
25462546
struct xfs_perag *pag;
25472547
struct xfs_ino_geometry *igeo = M_IGEO(mp);
25482548
xfs_ino_t inum;
2549+
int error;
25492550

25502551
inum = xic->first_ino;
25512552
pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, inum));
@@ -2574,12 +2575,11 @@ xfs_ifree_cluster(
25742575
* complete before we get a lock on it, and hence we may fail
25752576
* to mark all the active inodes on the buffer stale.
25762577
*/
2577-
bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, blkno,
2578-
mp->m_bsize * igeo->blocks_per_cluster,
2579-
XBF_UNMAPPED);
2580-
2581-
if (!bp)
2582-
return -ENOMEM;
2578+
error = xfs_trans_get_buf(tp, mp->m_ddev_targp, blkno,
2579+
mp->m_bsize * igeo->blocks_per_cluster,
2580+
XBF_UNMAPPED, &bp);
2581+
if (error)
2582+
return error;
25832583

25842584
/*
25852585
* This buffer may not have been correctly initialised as we

fs/xfs/xfs_rtalloc.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -826,12 +826,10 @@ xfs_growfs_rt_alloc(
826826
* Get a buffer for the block.
827827
*/
828828
d = XFS_FSB_TO_DADDR(mp, fsbno);
829-
bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
830-
mp->m_bsize, 0);
831-
if (bp == NULL) {
832-
error = -EIO;
829+
error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
830+
mp->m_bsize, 0, &bp);
831+
if (error)
833832
goto out_trans_cancel;
834-
}
835833
memset(bp->b_addr, 0, mp->m_sb.sb_blocksize);
836834
xfs_trans_log_buf(tp, bp, 0, mp->m_sb.sb_blocksize - 1);
837835
/*

fs/xfs/xfs_symlink.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,10 @@ xfs_symlink(
280280

281281
d = XFS_FSB_TO_DADDR(mp, mval[n].br_startblock);
282282
byte_cnt = XFS_FSB_TO_B(mp, mval[n].br_blockcount);
283-
bp = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
284-
BTOBB(byte_cnt), 0);
285-
if (!bp) {
286-
error = -ENOMEM;
283+
error = xfs_trans_get_buf(tp, mp->m_ddev_targp, d,
284+
BTOBB(byte_cnt), 0, &bp);
285+
if (error)
287286
goto out_trans_cancel;
288-
}
289287
bp->b_ops = &xfs_symlink_buf_ops;
290288

291289
byte_cnt = XFS_SYMLINK_BUF_SPACE(mp, byte_cnt);
@@ -423,13 +421,12 @@ xfs_inactive_symlink_rmt(
423421
* Invalidate the block(s). No validation is done.
424422
*/
425423
for (i = 0; i < nmaps; i++) {
426-
bp = xfs_trans_get_buf(tp, mp->m_ddev_targp,
427-
XFS_FSB_TO_DADDR(mp, mval[i].br_startblock),
428-
XFS_FSB_TO_BB(mp, mval[i].br_blockcount), 0);
429-
if (!bp) {
430-
error = -ENOMEM;
424+
error = xfs_trans_get_buf(tp, mp->m_ddev_targp,
425+
XFS_FSB_TO_DADDR(mp, mval[i].br_startblock),
426+
XFS_FSB_TO_BB(mp, mval[i].br_blockcount), 0,
427+
&bp);
428+
if (error)
431429
goto error_trans_cancel;
432-
}
433430
xfs_trans_binval(tp, bp);
434431
}
435432
/*

fs/xfs/xfs_trans.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,17 @@ int xfs_trans_get_buf_map(struct xfs_trans *tp, struct xfs_buftarg *target,
173173
struct xfs_buf_map *map, int nmaps, xfs_buf_flags_t flags,
174174
struct xfs_buf **bpp);
175175

176-
static inline struct xfs_buf *
176+
static inline int
177177
xfs_trans_get_buf(
178178
struct xfs_trans *tp,
179179
struct xfs_buftarg *target,
180180
xfs_daddr_t blkno,
181181
int numblks,
182-
uint flags)
182+
uint flags,
183+
struct xfs_buf **bpp)
183184
{
184-
struct xfs_buf *bp;
185-
int error;
186-
187185
DEFINE_SINGLE_BUF_MAP(map, blkno, numblks);
188-
error = xfs_trans_get_buf_map(tp, target, &map, 1, flags, &bp);
189-
if (error)
190-
return NULL;
191-
return bp;
186+
return xfs_trans_get_buf_map(tp, target, &map, 1, flags, bpp);
192187
}
193188

194189
int xfs_trans_read_buf_map(struct xfs_mount *mp,

0 commit comments

Comments
 (0)