From: Brian Foster Date: Thu, 4 Oct 2018 19:39:01 +0000 (-0500) Subject: xfs: refactor dfops init to attach to transaction X-Git-Tag: v4.19.0-rc0~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe891182b62c237726414d803790d7b62cc31427;p=thirdparty%2Fxfsprogs-dev.git xfs: refactor dfops init to attach to transaction Source kernel commit: bcd2c9f33559764e0d306e226a8aa88bc2e1e6fb Most callers of xfs_defer_init() immediately attach the dfops structure to a transaction. Add a transaction parameter to eliminate much of this boilerplate code. This also helps self-document the fact that many codepaths now expect a dfops pointer implicitly via xfs_trans->t_dfops. 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 --- diff --git a/libxfs/util.c b/libxfs/util.c index 5eb4e557d..cf4dd83fc 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -582,7 +582,7 @@ libxfs_alloc_file_space( } xfs_trans_ijoin(tp, ip, 0); - xfs_defer_init(&free_list, &firstfsb); + xfs_defer_init(NULL, &free_list, &firstfsb); error = xfs_bmapi_write(tp, ip, startoffset_fsb, allocatesize_fsb, xfs_bmapi_flags, &firstfsb, 0, imapp, &reccount); diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c index 8b5ff6559..92e445dfe 100644 --- a/libxfs/xfs_attr.c +++ b/libxfs/xfs_attr.c @@ -248,8 +248,7 @@ xfs_attr_set( rsvd ? XFS_TRANS_RESERVE : 0, &args.trans); if (error) return error; - xfs_defer_init(&dfops, &firstblock); - args.trans->t_dfops = &dfops; + xfs_defer_init(args.trans, &dfops, &firstblock); xfs_ilock(dp, XFS_ILOCK_EXCL); error = xfs_trans_reserve_quota_nblks(args.trans, dp, args.total, 0, @@ -423,8 +422,7 @@ xfs_attr_remove( &args.trans); if (error) return error; - xfs_defer_init(&dfops, &firstblock); - args.trans->t_dfops = &dfops; + xfs_defer_init(args.trans, &dfops, &firstblock); xfs_ilock(dp, XFS_ILOCK_EXCL); /* @@ -595,7 +593,7 @@ xfs_attr_leaf_addname( * Commit that transaction so that the node_addname() call * can manage its own transactions. */ - xfs_defer_init(args->trans->t_dfops, args->firstblock); + xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock); error = xfs_attr3_leaf_to_node(args); if (error) goto out_defer_cancel; @@ -684,7 +682,8 @@ 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->t_dfops, args->firstblock); + xfs_defer_init(NULL, args->trans->t_dfops, + args->firstblock); error = xfs_attr3_leaf_to_shortform(bp, args, forkoff); /* bp is gone due to xfs_da_shrink_inode */ if (error) @@ -749,7 +748,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->t_dfops, args->firstblock); + xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock); error = xfs_attr3_leaf_to_shortform(bp, args, forkoff); /* bp is gone due to xfs_da_shrink_inode */ if (error) @@ -878,7 +877,8 @@ restart: */ xfs_da_state_free(state); state = NULL; - xfs_defer_init(args->trans->t_dfops, args->firstblock); + xfs_defer_init(NULL, args->trans->t_dfops, + args->firstblock); error = xfs_attr3_leaf_to_node(args); if (error) goto out_defer_cancel; @@ -905,7 +905,7 @@ restart: * in the index/blkno/rmtblkno/rmtblkcnt fields and * in the index2/blkno2/rmtblkno2/rmtblkcnt2 fields. */ - xfs_defer_init(args->trans->t_dfops, args->firstblock); + xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock); error = xfs_da3_split(state); if (error) goto out_defer_cancel; @@ -1003,7 +1003,8 @@ restart: * Check to see if the tree needs to be collapsed. */ if (retval && (state->path.active > 1)) { - xfs_defer_init(args->trans->t_dfops, args->firstblock); + xfs_defer_init(NULL, args->trans->t_dfops, + args->firstblock); error = xfs_da3_join(state); if (error) goto out_defer_cancel; @@ -1128,7 +1129,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->t_dfops, args->firstblock); + xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock); error = xfs_da3_join(state); if (error) goto out_defer_cancel; @@ -1160,7 +1161,8 @@ xfs_attr_node_removename( goto out; if ((forkoff = xfs_attr_shortform_allfit(bp, dp))) { - xfs_defer_init(args->trans->t_dfops, args->firstblock); + xfs_defer_init(NULL, args->trans->t_dfops, + args->firstblock); 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 b81363a42..bc5fc3c8c 100644 --- a/libxfs/xfs_attr_remote.c +++ b/libxfs/xfs_attr_remote.c @@ -475,7 +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->t_dfops, args->firstblock); + xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock); nmap = 1; error = xfs_bmapi_write(args->trans, dp, (xfs_fileoff_t)lblkno, blkcnt, XFS_BMAPI_ATTRFORK, args->firstblock, @@ -517,7 +517,7 @@ xfs_attr_rmtval_set( ASSERT(blkcnt > 0); - xfs_defer_init(args->trans->t_dfops, args->firstblock); + xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock); nmap = 1; error = xfs_bmapi_read(dp, (xfs_fileoff_t)lblkno, blkcnt, &map, &nmap, @@ -621,7 +621,7 @@ xfs_attr_rmtval_remove( blkcnt = args->rmtblkcnt; done = 0; while (!done) { - xfs_defer_init(args->trans->t_dfops, args->firstblock); + xfs_defer_init(NULL, args->trans->t_dfops, args->firstblock); error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt, XFS_BMAPI_ATTRFORK, 1, args->firstblock, &done); diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 124132670..f34fb3428 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -1041,8 +1041,7 @@ xfs_bmap_add_attrfork( rsvd ? XFS_TRANS_RESERVE : 0, &tp); if (error) return error; - xfs_defer_init(&dfops, &firstblock); - tp->t_dfops = &dfops; + xfs_defer_init(tp, &dfops, &firstblock); xfs_ilock(ip, XFS_ILOCK_EXCL); error = xfs_trans_reserve_quota_nblks(tp, ip, blks, 0, rsvd ? @@ -6016,8 +6015,7 @@ xfs_bmap_split_extent( XFS_DIOSTRAT_SPACE_RES(mp, 0), 0, 0, &tp); if (error) return error; - xfs_defer_init(&dfops, &firstfsb); - tp->t_dfops = &dfops; + xfs_defer_init(tp, &dfops, &firstfsb); 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 30aa33e7e..3ddb58e9d 100644 --- a/libxfs/xfs_defer.c +++ b/libxfs/xfs_defer.c @@ -523,12 +523,19 @@ xfs_defer_init_op_type( /* Initialize a deferred operation. */ void xfs_defer_init( + struct xfs_trans *tp, struct xfs_defer_ops *dop, xfs_fsblock_t *fbp) { + 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); - trace_xfs_defer_init(NULL, dop, _RET_IP_); + if (tp) { + tp->t_dfops = dop; + mp = tp->t_mountp; + } + trace_xfs_defer_init(mp, dop, _RET_IP_); } diff --git a/libxfs/xfs_defer.h b/libxfs/xfs_defer.h index a02b2b748..56eaaac31 100644 --- a/libxfs/xfs_defer.h +++ b/libxfs/xfs_defer.h @@ -63,7 +63,8 @@ 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_defer_ops *dop, xfs_fsblock_t *fbp); +void xfs_defer_init(struct xfs_trans *tp, struct xfs_defer_ops *dop, + xfs_fsblock_t *fbp); 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 d7d1bb8a8..7132ee1d1 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -1690,8 +1690,7 @@ xfs_refcount_recover_cow_leftovers( trace_xfs_refcount_recover_extent(mp, agno, &rr->rr_rrec); /* Free the orphan record */ - xfs_defer_init(&dfops, &fsb); - tp->t_dfops = &dfops; + xfs_defer_init(tp, &dfops, &fsb); 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 9d5d68db4..671774fff 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -444,8 +444,7 @@ parseproto( case IF_REGULAR: buf = newregfile(pp, &len); tp = getres(mp, XFS_B_TO_FSB(mp, len)); - libxfs_defer_init(&dfops, &first); - tp->t_dfops = &dfops; + libxfs_defer_init(tp, &dfops, &first); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFREG, 1, 0, &creds, fsxp, &ip); if (error) @@ -469,8 +468,7 @@ parseproto( exit(1); } tp = getres(mp, XFS_B_TO_FSB(mp, llen)); - libxfs_defer_init(&dfops, &first); - tp->t_dfops = &dfops; + libxfs_defer_init(tp, &dfops, &first); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFREG, 1, 0, &creds, fsxp, &ip); @@ -494,8 +492,7 @@ parseproto( case IF_BLOCK: tp = getres(mp, 0); - libxfs_defer_init(&dfops, &first); - tp->t_dfops = &dfops; + libxfs_defer_init(tp, &dfops, &first); majdev = getnum(getstr(pp), 0, 0, false); mindev = getnum(getstr(pp), 0, 0, false); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFBLK, 1, @@ -511,8 +508,7 @@ parseproto( case IF_CHAR: tp = getres(mp, 0); - libxfs_defer_init(&dfops, &first); - tp->t_dfops = &dfops; + libxfs_defer_init(tp, &dfops, &first); majdev = getnum(getstr(pp), 0, 0, false); mindev = getnum(getstr(pp), 0, 0, false); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFCHR, 1, @@ -527,8 +523,7 @@ parseproto( case IF_FIFO: tp = getres(mp, 0); - libxfs_defer_init(&dfops, &first); - tp->t_dfops = &dfops; + libxfs_defer_init(tp, &dfops, &first); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFIFO, 1, 0, &creds, fsxp, &ip); if (error) @@ -541,8 +536,7 @@ parseproto( buf = getstr(pp); len = (int)strlen(buf); tp = getres(mp, XFS_B_TO_FSB(mp, len)); - libxfs_defer_init(&dfops, &first); - tp->t_dfops = &dfops; + libxfs_defer_init(tp, &dfops, &first); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFLNK, 1, 0, &creds, fsxp, &ip); if (error) @@ -554,8 +548,7 @@ parseproto( break; case IF_DIRECTORY: tp = getres(mp, 0); - libxfs_defer_init(&dfops, &first); - tp->t_dfops = &dfops; + libxfs_defer_init(tp, &dfops, &first); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFDIR, 1, 0, &creds, fsxp, &ip); if (error) @@ -693,8 +686,7 @@ rtinit( libxfs_trans_ijoin(tp, rbmip, 0); bno = 0; - libxfs_defer_init(&dfops, &first); - tp->t_dfops = &dfops; + libxfs_defer_init(tp, &dfops, &first); while (bno < mp->m_sb.sb_rbmblocks) { nmap = XFS_BMAP_MAX_NMAP; error = -libxfs_bmapi_write(tp, rbmip, bno, @@ -729,8 +721,7 @@ rtinit( res_failed(i); libxfs_trans_ijoin(tp, rsumip, 0); bno = 0; - libxfs_defer_init(&dfops, &first); - tp->t_dfops = &dfops; + libxfs_defer_init(tp, &dfops, &first); while (bno < nsumblocks) { nmap = XFS_BMAP_MAX_NMAP; error = -libxfs_bmapi_write(tp, rsumip, bno, @@ -764,8 +755,7 @@ rtinit( if (i) res_failed(i); libxfs_trans_ijoin(tp, rbmip, 0); - libxfs_defer_init(&dfops, &first); - tp->t_dfops = &dfops; + libxfs_defer_init(tp, &dfops, &first); 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 eb99638f8..4b925e7e4 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -589,8 +589,7 @@ mk_rbmino(xfs_mount_t *mp) libxfs_trans_ijoin(tp, ip, 0); bno = 0; - libxfs_defer_init(&dfops, &first); - tp->t_dfops = &dfops; + libxfs_defer_init(tp, &dfops, &first); while (bno < mp->m_sb.sb_rbmblocks) { nmap = XFS_BMAP_MAX_NMAP; error = -libxfs_bmapi_write(tp, ip, bno, @@ -835,8 +834,7 @@ mk_rsumino(xfs_mount_t *mp) libxfs_trans_ijoin(tp, ip, 0); bno = 0; - libxfs_defer_init(&dfops, &first); - tp->t_dfops = &dfops; + libxfs_defer_init(tp, &dfops, &first); while (bno < nsumblocks) { nmap = XFS_BMAP_MAX_NMAP; error = -libxfs_bmapi_write(tp, ip, bno, @@ -979,11 +977,11 @@ mk_orphanage(xfs_mount_t *mp) /* * could not be found, create it */ - libxfs_defer_init(&dfops, &first); nres = XFS_MKDIR_SPACE_RES(mp, xname.len); 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); /* * use iget/ijoin instead of trans_iget because the ialloc @@ -1149,7 +1147,7 @@ mv_orphanage( libxfs_trans_ijoin(tp, orphanage_ip, 0); libxfs_trans_ijoin(tp, ino_p, 0); - libxfs_defer_init(&dfops, &first); + libxfs_defer_init(tp, &dfops, &first); err = -libxfs_dir_createname(tp, orphanage_ip, &xname, ino, &first, nres); if (err) @@ -1192,7 +1190,7 @@ mv_orphanage( libxfs_trans_ijoin(tp, orphanage_ip, 0); libxfs_trans_ijoin(tp, ino_p, 0); - libxfs_defer_init(&dfops, &first); + libxfs_defer_init(tp, &dfops, &first); err = -libxfs_dir_createname(tp, orphanage_ip, &xname, ino, &first, nres); @@ -1249,7 +1247,7 @@ mv_orphanage( libxfs_trans_ijoin(tp, orphanage_ip, 0); libxfs_trans_ijoin(tp, ino_p, 0); - libxfs_defer_init(&dfops, &first); + libxfs_defer_init(tp, &dfops, &first); err = -libxfs_dir_createname(tp, orphanage_ip, &xname, ino, &first, nres); if (err) @@ -1376,7 +1374,7 @@ longform_dir2_rebuild( libxfs_dir_ino_validate(mp, pip.i_ino)) pip.i_ino = mp->m_sb.sb_rootino; - libxfs_defer_init(&dfops, &firstblock); + libxfs_defer_init(NULL, &dfops, &firstblock); nres = XFS_REMOVE_SPACE_RES(mp); error = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_remove, nres, 0, 0, &tp); @@ -1433,7 +1431,7 @@ longform_dir2_rebuild( libxfs_trans_ijoin(tp, ip, 0); - libxfs_defer_init(&dfops, &firstblock); + libxfs_defer_init(tp, &dfops, &firstblock); error = -libxfs_dir_createname(tp, ip, &p->name, p->inum, &firstblock, nres); if (error) { @@ -1489,7 +1487,7 @@ dir2_kill_block( libxfs_trans_ijoin(tp, ip, 0); libxfs_trans_bjoin(tp, bp); memset(&args, 0, sizeof(args)); - libxfs_defer_init(&dfops, &firstblock); + libxfs_defer_init(tp, &dfops, &firstblock); args.dp = ip; args.trans = tp; args.firstblock = &firstblock; @@ -1680,7 +1678,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(&dfops, &firstblock); + libxfs_defer_init(tp, &dfops, &firstblock); if (be32_to_cpu(d->magic) != wantmagic) { do_warn( _("bad directory block magic # %#x for directory inode %" PRIu64 " block %d: "), @@ -3035,7 +3033,7 @@ process_dir_inode( libxfs_trans_ijoin(tp, ip, 0); - libxfs_defer_init(&dfops, &first); + libxfs_defer_init(tp, &dfops, &first); error = -libxfs_dir_createname(tp, ip, &xfs_name_dotdot, ip->i_ino, &first, nres); @@ -3093,7 +3091,7 @@ process_dir_inode( libxfs_trans_ijoin(tp, ip, 0); - libxfs_defer_init(&dfops, &first); + libxfs_defer_init(tp, &dfops, &first); error = -libxfs_dir_createname(tp, ip, &xfs_name_dot, ip->i_ino, &first, nres);