From 5cebfb2309a2b163aa6831c565dfbe186421271c Mon Sep 17 00:00:00 2001 From: Brian Foster Date: Thu, 4 Oct 2018 21:36:09 -0500 Subject: [PATCH] xfs: remove xfs_defer_init() firstblock param Source kernel commit: 5fdd97944ee5ae0fcdd88227224d0c2c87aa6db9 All but one caller of xfs_defer_init() passes in the ->t_firstblock of the associated transaction. The one outlier is xlog_recover_process_intents(), which simply passes a dummy value because a valid pointer is required. This firstblock variable can simply be removed. At this point we could remove the xfs_defer_init() firstblock parameter and initialize ->t_firstblock directly. Even that is not necessary, however, because ->t_firstblock is automatically reinitialized in the new transaction on a transaction roll. Since xfs_defer_init() should never occur more than once on a particular transaction (since the corresponding finish will roll it), replace the reinit from xfs_defer_init() with an assert that verifies the transaction has a NULLFSBLOCK firstblock. Signed-off-by: Brian Foster Reviewed-by: Christoph Hellwig Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Eric Sandeen --- libxfs/util.c | 3 +-- libxfs/xfs_attr.c | 28 ++++++++++------------------ libxfs/xfs_attr_remote.c | 9 +++------ libxfs/xfs_bmap.c | 4 ++-- libxfs/xfs_defer.c | 5 ++--- libxfs/xfs_defer.h | 3 +-- libxfs/xfs_refcount.c | 2 +- mkfs/proto.c | 22 ++++++++++------------ repair/phase6.c | 34 +++++++++++++--------------------- 9 files changed, 43 insertions(+), 67 deletions(-) diff --git a/libxfs/util.c b/libxfs/util.c index 33f531a4b..6f73a77ad 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -543,7 +543,6 @@ libxfs_alloc_file_space( xfs_filblks_t datablocks; xfs_filblks_t allocated_fsb; xfs_filblks_t allocatesize_fsb; - xfs_fsblock_t firstfsb; struct xfs_defer_ops free_list; xfs_bmbt_irec_t *imapp; xfs_bmbt_irec_t imaps[1]; @@ -582,7 +581,7 @@ libxfs_alloc_file_space( } xfs_trans_ijoin(tp, ip, 0); - xfs_defer_init(NULL, &free_list, &firstfsb); + xfs_defer_init(NULL, &free_list); error = xfs_bmapi_write(tp, ip, startoffset_fsb, allocatesize_fsb, xfs_bmapi_flags, 0, imapp, &reccount); diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 2b6e0cf33..2cce9e386 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -246,7 +246,7 @@ xfs_attr_set( rsvd ? XFS_TRANS_RESERVE : 0, &args.trans); if (error) return error; - xfs_defer_init(args.trans, &dfops, &args.trans->t_firstblock); + xfs_defer_init(args.trans, &dfops); xfs_ilock(dp, XFS_ILOCK_EXCL); error = xfs_trans_reserve_quota_nblks(args.trans, dp, args.total, 0, @@ -417,7 +417,7 @@ xfs_attr_remove( &args.trans); if (error) return error; - xfs_defer_init(args.trans, &dfops, &args.trans->t_firstblock); + xfs_defer_init(args.trans, &dfops); xfs_ilock(dp, XFS_ILOCK_EXCL); /* @@ -588,8 +588,7 @@ xfs_attr_leaf_addname( * Commit that transaction so that the node_addname() call * can manage its own transactions. */ - xfs_defer_init(args->trans, args->trans->t_dfops, - &args->trans->t_firstblock); + xfs_defer_init(args->trans, args->trans->t_dfops); error = xfs_attr3_leaf_to_node(args); if (error) goto out_defer_cancel; @@ -678,8 +677,7 @@ xfs_attr_leaf_addname( * If the result is small enough, shrink it all into the inode. */ if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) { - xfs_defer_init(args->trans, args->trans->t_dfops, - &args->trans->t_firstblock); + xfs_defer_init(args->trans, args->trans->t_dfops); error = xfs_attr3_leaf_to_shortform(bp, args, forkoff); /* bp is gone due to xfs_da_shrink_inode */ if (error) @@ -744,8 +742,7 @@ xfs_attr_leaf_removename( * If the result is small enough, shrink it all into the inode. */ if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) { - xfs_defer_init(args->trans, args->trans->t_dfops, - &args->trans->t_firstblock); + xfs_defer_init(args->trans, args->trans->t_dfops); error = xfs_attr3_leaf_to_shortform(bp, args, forkoff); /* bp is gone due to xfs_da_shrink_inode */ if (error) @@ -874,8 +871,7 @@ restart: */ xfs_da_state_free(state); state = NULL; - xfs_defer_init(args->trans, args->trans->t_dfops, - &args->trans->t_firstblock); + xfs_defer_init(args->trans, args->trans->t_dfops); error = xfs_attr3_leaf_to_node(args); if (error) goto out_defer_cancel; @@ -902,8 +898,7 @@ restart: * in the index/blkno/rmtblkno/rmtblkcnt fields and * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields. */ - xfs_defer_init(args->trans, args->trans->t_dfops, - &args->trans->t_firstblock); + xfs_defer_init(args->trans, args->trans->t_dfops); error = xfs_da3_split(state); if (error) goto out_defer_cancel; @@ -1001,8 +996,7 @@ restart: * Check to see if the tree needs to be collapsed. */ if (retval && (state->path.active > 1)) { - xfs_defer_init(args->trans, args->trans->t_dfops, - &args->trans->t_firstblock); + xfs_defer_init(args->trans, args->trans->t_dfops); error = xfs_da3_join(state); if (error) goto out_defer_cancel; @@ -1127,8 +1121,7 @@ xfs_attr_node_removename( * Check to see if the tree needs to be collapsed. */ if (retval && (state->path.active > 1)) { - xfs_defer_init(args->trans, args->trans->t_dfops, - &args->trans->t_firstblock); + xfs_defer_init(args->trans, args->trans->t_dfops); error = xfs_da3_join(state); if (error) goto out_defer_cancel; @@ -1160,8 +1153,7 @@ xfs_attr_node_removename( goto out; if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) { - xfs_defer_init(args->trans, args->trans->t_dfops, - &args->trans->t_firstblock); + xfs_defer_init(args->trans, args->trans->t_dfops); error = xfs_attr3_leaf_to_shortform(bp, args, forkoff); /* bp is gone due to xfs_da_shrink_inode */ if (error) diff --git a/libxfs/xfs_attr_remote.c b/libxfs/xfs_attr_remote.c index d6ac356e8..5841ac3a6 100644 --- a/libxfs/xfs_attr_remote.c +++ b/libxfs/xfs_attr_remote.c @@ -475,8 +475,7 @@ xfs_attr_rmtval_set( * extent and then crash then the block may not contain the * correct metadata after log recovery occurs. */ - xfs_defer_init(args->trans, args->trans->t_dfops, - &args->trans->t_firstblock); + xfs_defer_init(args->trans, args->trans->t_dfops); nmap = 1; error = xfs_bmapi_write(args->trans, dp, (xfs_fileoff_t)lblkno, blkcnt, XFS_BMAPI_ATTRFORK, args->total, &map, @@ -518,8 +517,7 @@ xfs_attr_rmtval_set( ASSERT(blkcnt > 0); - xfs_defer_init(args->trans, args->trans->t_dfops, - &args->trans->t_firstblock); + xfs_defer_init(args->trans, args->trans->t_dfops); nmap = 1; error = xfs_bmapi_read(dp, (xfs_fileoff_t)lblkno, blkcnt, &map, &nmap, @@ -623,8 +621,7 @@ xfs_attr_rmtval_remove( blkcnt = args->rmtblkcnt; done = 0; while (!done) { - xfs_defer_init(args->trans, args->trans->t_dfops, - &args->trans->t_firstblock); + xfs_defer_init(args->trans, args->trans->t_dfops); error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt, XFS_BMAPI_ATTRFORK, 1, &done); if (error) diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 2934c54de..d2c6e58b3 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -1029,7 +1029,7 @@ xfs_bmap_add_attrfork( rsvd ? XFS_TRANS_RESERVE : 0, &tp); if (error) return error; - xfs_defer_init(tp, &dfops, &tp->t_firstblock); + xfs_defer_init(tp, &dfops); xfs_ilock(ip, XFS_ILOCK_EXCL); error = xfs_trans_reserve_quota_nblks(tp, ip, blks, 0, rsvd ? @@ -5959,7 +5959,7 @@ xfs_bmap_split_extent( XFS_DIOSTRAT_SPACE_RES(mp, 0), 0, 0, &tp); if (error) return error; - xfs_defer_init(tp, &dfops, &tp->t_firstblock); + xfs_defer_init(tp, &dfops); xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c index 3ddb58e9d..ce5d216d2 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -524,16 +524,15 @@ xfs_defer_init_op_type( void xfs_defer_init( struct xfs_trans *tp, - struct xfs_defer_ops *dop, - xfs_fsblock_t *fbp) + struct xfs_defer_ops *dop) { struct xfs_mount *mp = NULL; memset(dop, 0, sizeof(struct xfs_defer_ops)); - *fbp = NULLFSBLOCK; INIT_LIST_HEAD(&dop->dop_intake); INIT_LIST_HEAD(&dop->dop_pending); if (tp) { + ASSERT(tp->t_firstblock == NULLFSBLOCK); tp->t_dfops = dop; mp = tp->t_mountp; } diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index 56eaaac31..c17c9deda 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -63,8 +63,7 @@ void xfs_defer_add(struct xfs_defer_ops *dop, enum xfs_defer_ops_type type, struct list_head *h); int xfs_defer_finish(struct xfs_trans **tp, struct xfs_defer_ops *dop); void xfs_defer_cancel(struct xfs_defer_ops *dop); -void xfs_defer_init(struct xfs_trans *tp, struct xfs_defer_ops *dop, - xfs_fsblock_t *fbp); +void xfs_defer_init(struct xfs_trans *tp, struct xfs_defer_ops *dop); bool xfs_defer_has_unfinished_work(struct xfs_defer_ops *dop); int xfs_defer_ijoin(struct xfs_defer_ops *dop, struct xfs_inode *ip); int xfs_defer_bjoin(struct xfs_defer_ops *dop, struct xfs_buf *bp); diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 2cacb95bc..b21003e15 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -1690,7 +1690,7 @@ xfs_refcount_recover_cow_leftovers( trace_xfs_refcount_recover_extent(mp, agno, &rr->rr_rrec); /* Free the orphan record */ - xfs_defer_init(tp, &dfops, &tp->t_firstblock); + xfs_defer_init(tp, &dfops); agbno = rr->rr_rrec.rc_startblock - XFS_REFC_COW_START; fsb = XFS_AGB_TO_FSB(mp, agno, agbno); error = xfs_refcount_free_cow_extent(mp, tp->t_dfops, fsb, diff --git a/mkfs/proto.c b/mkfs/proto.c index dbac6d398..9b63a3286 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -350,7 +350,6 @@ parseproto( char *buf; int error; - xfs_fsblock_t first; int flags; struct xfs_defer_ops dfops; int fmt; @@ -441,7 +440,7 @@ parseproto( case IF_REGULAR: buf = newregfile(pp, &len); tp = getres(mp, XFS_B_TO_FSB(mp, len)); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFREG, 1, 0, &creds, fsxp, &ip); if (error) @@ -465,7 +464,7 @@ parseproto( exit(1); } tp = getres(mp, XFS_B_TO_FSB(mp, llen)); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFREG, 1, 0, &creds, fsxp, &ip); @@ -489,7 +488,7 @@ parseproto( case IF_BLOCK: tp = getres(mp, 0); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); majdev = getnum(getstr(pp), 0, 0, false); mindev = getnum(getstr(pp), 0, 0, false); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFBLK, 1, @@ -505,7 +504,7 @@ parseproto( case IF_CHAR: tp = getres(mp, 0); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); majdev = getnum(getstr(pp), 0, 0, false); mindev = getnum(getstr(pp), 0, 0, false); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFCHR, 1, @@ -520,7 +519,7 @@ parseproto( case IF_FIFO: tp = getres(mp, 0); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFIFO, 1, 0, &creds, fsxp, &ip); if (error) @@ -533,7 +532,7 @@ parseproto( buf = getstr(pp); len = (int)strlen(buf); tp = getres(mp, XFS_B_TO_FSB(mp, len)); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFLNK, 1, 0, &creds, fsxp, &ip); if (error) @@ -545,7 +544,7 @@ parseproto( break; case IF_DIRECTORY: tp = getres(mp, 0); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFDIR, 1, 0, &creds, fsxp, &ip); if (error) @@ -622,7 +621,6 @@ rtinit( xfs_fileoff_t ebno; xfs_bmbt_irec_t *ep; int error; - xfs_fsblock_t first; struct xfs_defer_ops dfops; int i; xfs_bmbt_irec_t map[XFS_BMAP_MAX_NMAP]; @@ -683,7 +681,7 @@ rtinit( libxfs_trans_ijoin(tp, rbmip, 0); bno = 0; - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); while (bno < mp->m_sb.sb_rbmblocks) { nmap = XFS_BMAP_MAX_NMAP; error = -libxfs_bmapi_write(tp, rbmip, bno, @@ -718,7 +716,7 @@ rtinit( res_failed(i); libxfs_trans_ijoin(tp, rsumip, 0); bno = 0; - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); while (bno < nsumblocks) { nmap = XFS_BMAP_MAX_NMAP; error = -libxfs_bmapi_write(tp, rsumip, bno, @@ -752,7 +750,7 @@ rtinit( if (i) res_failed(i); libxfs_trans_ijoin(tp, rbmip, 0); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); ebno = XFS_RTMIN(mp->m_sb.sb_rextents, bno + NBBY * mp->m_sb.sb_blocksize); error = -libxfs_rtfree_extent(tp, bno, (xfs_extlen_t)(ebno-bno)); diff --git a/repair/phase6.c b/repair/phase6.c index 550f6892f..c4228a6f8 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -519,7 +519,6 @@ mk_rbmino(xfs_mount_t *mp) xfs_trans_t *tp; xfs_inode_t *ip; xfs_bmbt_irec_t *ep; - xfs_fsblock_t first; int i; int nmap; int error; @@ -589,7 +588,7 @@ mk_rbmino(xfs_mount_t *mp) libxfs_trans_ijoin(tp, ip, 0); bno = 0; - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); while (bno < mp->m_sb.sb_rbmblocks) { nmap = XFS_BMAP_MAX_NMAP; error = -libxfs_bmapi_write(tp, ip, bno, @@ -757,7 +756,6 @@ mk_rsumino(xfs_mount_t *mp) xfs_trans_t *tp; xfs_inode_t *ip; xfs_bmbt_irec_t *ep; - xfs_fsblock_t first; int i; int nmap; int error; @@ -828,7 +826,7 @@ mk_rsumino(xfs_mount_t *mp) libxfs_trans_ijoin(tp, ip, 0); bno = 0; - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); while (bno < nsumblocks) { nmap = XFS_BMAP_MAX_NMAP; error = -libxfs_bmapi_write(tp, ip, bno, @@ -939,7 +937,6 @@ mk_orphanage(xfs_mount_t *mp) xfs_trans_t *tp; xfs_inode_t *ip; xfs_inode_t *pip; - xfs_fsblock_t first; ino_tree_node_t *irec; int ino_offset = 0; int i; @@ -975,7 +972,7 @@ mk_orphanage(xfs_mount_t *mp) i = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_mkdir, nres, 0, 0, &tp); if (i) res_failed(i); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); /* * use iget/ijoin instead of trans_iget because the ialloc @@ -1083,8 +1080,7 @@ mv_orphanage( xfs_ino_t entry_ino_num; xfs_inode_t *ino_p; xfs_trans_t *tp; - xfs_fsblock_t first; - struct xfs_defer_ops dfops; + struct xfs_defer_ops dfops; int err; unsigned char fname[MAXPATHLEN + 1]; int nres; @@ -1140,7 +1136,7 @@ mv_orphanage( libxfs_trans_ijoin(tp, orphanage_ip, 0); libxfs_trans_ijoin(tp, ino_p, 0); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); err = -libxfs_dir_createname(tp, orphanage_ip, &xname, ino, nres); if (err) @@ -1183,7 +1179,7 @@ mv_orphanage( libxfs_trans_ijoin(tp, orphanage_ip, 0); libxfs_trans_ijoin(tp, ino_p, 0); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); err = -libxfs_dir_createname(tp, orphanage_ip, &xname, ino, nres); @@ -1240,7 +1236,7 @@ mv_orphanage( libxfs_trans_ijoin(tp, orphanage_ip, 0); libxfs_trans_ijoin(tp, ino_p, 0); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); err = -libxfs_dir_createname(tp, orphanage_ip, &xname, ino, nres); if (err) @@ -1343,7 +1339,6 @@ longform_dir2_rebuild( int nres; xfs_trans_t *tp; xfs_fileoff_t lastblock; - xfs_fsblock_t firstblock; struct xfs_defer_ops dfops; xfs_inode_t pip; dir_hash_ent_t *p; @@ -1367,7 +1362,7 @@ longform_dir2_rebuild( libxfs_dir_ino_validate(mp, pip.i_ino)) pip.i_ino = mp->m_sb.sb_rootino; - libxfs_defer_init(NULL, &dfops, &firstblock); + libxfs_defer_init(NULL, &dfops); nres = XFS_REMOVE_SPACE_RES(mp); error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_remove, nres, 0, 0, &tp); @@ -1424,7 +1419,7 @@ longform_dir2_rebuild( libxfs_trans_ijoin(tp, ip, 0); - libxfs_defer_init(tp, &dfops, &firstblock); + libxfs_defer_init(tp, &dfops); error = -libxfs_dir_createname(tp, ip, &p->name, p->inum, nres); if (error) { @@ -1468,7 +1463,6 @@ dir2_kill_block( { xfs_da_args_t args; int error; - xfs_fsblock_t firstblock; struct xfs_defer_ops dfops; int nres; xfs_trans_t *tp; @@ -1480,7 +1474,7 @@ dir2_kill_block( libxfs_trans_ijoin(tp, ip, 0); libxfs_trans_bjoin(tp, bp); memset(&args, 0, sizeof(args)); - libxfs_defer_init(tp, &dfops, &firstblock); + libxfs_defer_init(tp, &dfops); args.dp = ip; args.trans = tp; args.whichfork = XFS_DATA_FORK; @@ -1527,7 +1521,6 @@ longform_dir2_entry_check_data( struct xfs_dir2_data_free *bf; char *endptr; int error; - xfs_fsblock_t firstblock; struct xfs_defer_ops dfops; char fname[MAXNAMELEN + 1]; freetab_t *freetab; @@ -1670,7 +1663,7 @@ longform_dir2_entry_check_data( libxfs_trans_ijoin(tp, ip, 0); libxfs_trans_bjoin(tp, bp); libxfs_trans_bhold(tp, bp); - libxfs_defer_init(tp, &dfops, &firstblock); + libxfs_defer_init(tp, &dfops); if (be32_to_cpu(d->magic) != wantmagic) { do_warn( _("bad directory block magic # %#x for directory inode %" PRIu64 " block %d: "), @@ -2889,7 +2882,6 @@ process_dir_inode( { xfs_ino_t ino; struct xfs_defer_ops dfops; - xfs_fsblock_t first; xfs_inode_t *ip; xfs_trans_t *tp; dir_hash_tab_t *hashtab; @@ -3025,7 +3017,7 @@ process_dir_inode( libxfs_trans_ijoin(tp, ip, 0); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); error = -libxfs_dir_createname(tp, ip, &xfs_name_dotdot, ip->i_ino, nres); @@ -3083,7 +3075,7 @@ process_dir_inode( libxfs_trans_ijoin(tp, ip, 0); - libxfs_defer_init(tp, &dfops, &first); + libxfs_defer_init(tp, &dfops); error = -libxfs_dir_createname(tp, ip, &xfs_name_dot, ip->i_ino, nres); -- 2.47.3