From: Brian Foster Date: Fri, 5 Oct 2018 02:36:10 +0000 (-0500) Subject: xfs: remove all boilerplate defer init/finish code X-Git-Tag: v4.19.0-rc0~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=29ae66ebd62799f211f9bdba72966d98b0bf4d9a;p=thirdparty%2Fxfsprogs-dev.git xfs: remove all boilerplate defer init/finish code Source kernel commit: c8eac49ef798a7d00240847f63902caa1388241a At this point, the transaction subsystem completely manages deferred items internally such that the common and boilerplate xfs_trans_alloc() -> xfs_defer_init() -> xfs_defer_finish() -> xfs_trans_commit() sequence can be replaced with a simple transaction allocation and commit. Remove all such boilerplate deferred ops code. In doing so, we change each case over to use the dfops in the transaction and specifically eliminate: - The on-stack dfops and associated xfs_defer_init() call, as the internal dfops is initialized on transaction allocation. - xfs_bmap_finish() calls that precede a final xfs_trans_commit() of a transaction. - xfs_defer_cancel() calls in error handlers that precede a transaction cancel. The only deferred ops calls that remain are those that are non-deterministic with respect to the final commit of the associated transaction or are open-coded due to special handling. Signed-off-by: Brian Foster Reviewed-by: Bill O'Donnell 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 6f73a77ad..273c88775 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; - struct xfs_defer_ops free_list; xfs_bmbt_irec_t *imapp; xfs_bmbt_irec_t imaps[1]; int reccount; @@ -581,7 +580,6 @@ libxfs_alloc_file_space( } xfs_trans_ijoin(tp, ip, 0); - xfs_defer_init(NULL, &free_list); error = xfs_bmapi_write(tp, ip, startoffset_fsb, allocatesize_fsb, xfs_bmapi_flags, 0, imapp, &reccount); @@ -591,10 +589,6 @@ libxfs_alloc_file_space( /* * Complete the transaction */ - error = xfs_defer_finish(&tp, &free_list); - if (error) - goto error0; - error = xfs_trans_commit(tp); if (error) break; @@ -609,7 +603,6 @@ libxfs_alloc_file_space( return error; error0: /* Cancel bmap, cancel trans */ - xfs_defer_cancel(&free_list); xfs_trans_cancel(tp); return error; } diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c index 36f513ec8..f280f929b 100644 --- a/libxfs/xfs_bmap.c +++ b/libxfs/xfs_bmap.c @@ -1009,7 +1009,6 @@ xfs_bmap_add_attrfork( int size, /* space new attribute needs */ int rsvd) /* xact may use reserved blks */ { - struct xfs_defer_ops dfops; /* freed extent records */ xfs_mount_t *mp; /* mount structure */ xfs_trans_t *tp; /* transaction pointer */ int blks; /* space reservation */ @@ -1028,7 +1027,6 @@ xfs_bmap_add_attrfork( rsvd ? XFS_TRANS_RESERVE : 0, &tp); if (error) return error; - xfs_defer_init(tp, &dfops); xfs_ilock(ip, XFS_ILOCK_EXCL); error = xfs_trans_reserve_quota_nblks(tp, ip, blks, 0, rsvd ? @@ -1093,7 +1091,7 @@ xfs_bmap_add_attrfork( if (logflags) xfs_trans_log_inode(tp, ip, logflags); if (error) - goto bmap_cancel; + goto trans_cancel; if (!xfs_sb_version_hasattr(&mp->m_sb) || (!xfs_sb_version_hasattr2(&mp->m_sb) && version == 2)) { bool log_sb = false; @@ -1112,15 +1110,10 @@ xfs_bmap_add_attrfork( xfs_log_sb(tp); } - error = xfs_defer_finish(&tp, &dfops); - if (error) - goto bmap_cancel; error = xfs_trans_commit(tp); xfs_iunlock(ip, XFS_ILOCK_EXCL); return error; -bmap_cancel: - xfs_defer_cancel(&dfops); trans_cancel: xfs_trans_cancel(tp); xfs_iunlock(ip, XFS_ILOCK_EXCL); @@ -5944,14 +5937,12 @@ xfs_bmap_split_extent( { struct xfs_mount *mp = ip->i_mount; struct xfs_trans *tp; - struct xfs_defer_ops dfops; int error; error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, XFS_DIOSTRAT_SPACE_RES(mp, 0), 0, 0, &tp); if (error) return error; - xfs_defer_init(tp, &dfops); xfs_ilock(ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); @@ -5960,14 +5951,9 @@ xfs_bmap_split_extent( if (error) goto out; - error = xfs_defer_finish(&tp, &dfops); - if (error) - goto out; - return xfs_trans_commit(tp); out: - xfs_defer_cancel(&dfops); xfs_trans_cancel(tp); return error; } diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c index 8900d89e1..0807bf55c 100644 --- a/libxfs/xfs_refcount.c +++ b/libxfs/xfs_refcount.c @@ -1634,7 +1634,6 @@ xfs_refcount_recover_cow_leftovers( struct list_head debris; union xfs_btree_irec low; union xfs_btree_irec high; - struct xfs_defer_ops dfops; xfs_fsblock_t fsb; xfs_agblock_t agbno; int error; @@ -1690,22 +1689,17 @@ xfs_refcount_recover_cow_leftovers( trace_xfs_refcount_recover_extent(mp, agno, &rr->rr_rrec); /* Free the orphan record */ - 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, rr->rr_rrec.rc_blockcount); if (error) - goto out_defer; + goto out_trans; /* Free the block. */ xfs_bmap_add_free(mp, tp->t_dfops, fsb, rr->rr_rrec.rc_blockcount, NULL); - error = xfs_defer_finish(&tp, tp->t_dfops); - if (error) - goto out_defer; - error = xfs_trans_commit(tp); if (error) goto out_free; @@ -1715,8 +1709,6 @@ xfs_refcount_recover_cow_leftovers( } return error; -out_defer: - xfs_defer_cancel(tp->t_dfops); out_trans: xfs_trans_cancel(tp); out_free: diff --git a/mkfs/proto.c b/mkfs/proto.c index 9b63a3286..3d59fbfb3 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -440,7 +440,6 @@ parseproto( case IF_REGULAR: buf = newregfile(pp, &len); tp = getres(mp, XFS_B_TO_FSB(mp, len)); - libxfs_defer_init(tp, &dfops); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFREG, 1, 0, &creds, fsxp, &ip); if (error) @@ -464,7 +463,6 @@ parseproto( exit(1); } tp = getres(mp, XFS_B_TO_FSB(mp, llen)); - libxfs_defer_init(tp, &dfops); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFREG, 1, 0, &creds, fsxp, &ip); @@ -478,9 +476,6 @@ parseproto( libxfs_trans_log_inode(tp, ip, flags); libxfs_defer_ijoin(&dfops, ip); - error = -libxfs_defer_finish(&tp, &dfops); - if (error) - fail(_("Pre-allocated file creation failed"), error); libxfs_trans_commit(tp); rsvfile(mp, ip, llen); IRELE(ip); @@ -488,7 +483,6 @@ parseproto( case IF_BLOCK: tp = getres(mp, 0); - 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, @@ -504,7 +498,6 @@ parseproto( case IF_CHAR: tp = getres(mp, 0); - 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, @@ -519,7 +512,6 @@ parseproto( case IF_FIFO: tp = getres(mp, 0); - libxfs_defer_init(tp, &dfops); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFIFO, 1, 0, &creds, fsxp, &ip); if (error) @@ -532,7 +524,6 @@ parseproto( buf = getstr(pp); len = (int)strlen(buf); tp = getres(mp, XFS_B_TO_FSB(mp, len)); - libxfs_defer_init(tp, &dfops); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFLNK, 1, 0, &creds, fsxp, &ip); if (error) @@ -544,7 +535,6 @@ parseproto( break; case IF_DIRECTORY: tp = getres(mp, 0); - libxfs_defer_init(tp, &dfops); error = -libxfs_inode_alloc(&tp, pip, mode|S_IFDIR, 1, 0, &creds, fsxp, &ip); if (error) @@ -565,9 +555,6 @@ parseproto( newdirectory(mp, tp, ip, pip); libxfs_trans_log_inode(tp, ip, flags); libxfs_defer_ijoin(&dfops, ip); - error = -libxfs_defer_finish(&tp, &dfops); - if (error) - fail(_("Directory creation failed"), error); libxfs_trans_commit(tp); /* * RT initialization. Do this here to ensure that @@ -592,11 +579,6 @@ parseproto( } libxfs_trans_log_inode(tp, ip, flags); libxfs_defer_ijoin(&dfops, ip); - error = -libxfs_defer_finish(&tp, &dfops); - if (error) { - fail(_("Error encountered creating file from prototype file"), - error); - } libxfs_trans_commit(tp); IRELE(ip); } @@ -681,7 +663,6 @@ rtinit( libxfs_trans_ijoin(tp, rbmip, 0); bno = 0; - libxfs_defer_init(tp, &dfops); while (bno < mp->m_sb.sb_rbmblocks) { nmap = XFS_BMAP_MAX_NMAP; error = -libxfs_bmapi_write(tp, rbmip, bno, @@ -700,10 +681,6 @@ rtinit( } libxfs_defer_ijoin(&dfops, rbmip); - error = -libxfs_defer_finish(&tp, &dfops); - if (error) { - fail(_("Completion of the realtime bitmap failed"), error); - } libxfs_trans_commit(tp); /* @@ -716,7 +693,6 @@ rtinit( res_failed(i); libxfs_trans_ijoin(tp, rsumip, 0); bno = 0; - libxfs_defer_init(tp, &dfops); while (bno < nsumblocks) { nmap = XFS_BMAP_MAX_NMAP; error = -libxfs_bmapi_write(tp, rsumip, bno, @@ -734,10 +710,6 @@ rtinit( } } libxfs_defer_ijoin(&dfops, rsumip); - error = -libxfs_defer_finish(&tp, &dfops); - if (error) { - fail(_("Completion of the realtime summary failed"), error); - } libxfs_trans_commit(tp); /* @@ -750,7 +722,6 @@ rtinit( if (i) res_failed(i); libxfs_trans_ijoin(tp, rbmip, 0); - 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)); @@ -759,10 +730,6 @@ rtinit( error); } libxfs_defer_ijoin(&dfops, rbmip); - error = -libxfs_defer_finish(&tp, &dfops); - if (error) { - fail(_("Error completing the realtime space"), error); - } libxfs_trans_commit(tp); } } diff --git a/repair/phase6.c b/repair/phase6.c index c4228a6f8..215bef4a5 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -588,7 +588,6 @@ mk_rbmino(xfs_mount_t *mp) libxfs_trans_ijoin(tp, ip, 0); bno = 0; - libxfs_defer_init(tp, &dfops); while (bno < mp->m_sb.sb_rbmblocks) { nmap = XFS_BMAP_MAX_NMAP; error = -libxfs_bmapi_write(tp, ip, bno, @@ -607,12 +606,6 @@ mk_rbmino(xfs_mount_t *mp) } } libxfs_defer_ijoin(&dfops, ip); - error = -libxfs_defer_finish(&tp, &dfops); - if (error) { - do_error( - _("allocation of the realtime bitmap failed, error = %d\n"), - error); - } libxfs_trans_commit(tp); IRELE(ip); } @@ -826,7 +819,6 @@ mk_rsumino(xfs_mount_t *mp) libxfs_trans_ijoin(tp, ip, 0); bno = 0; - libxfs_defer_init(tp, &dfops); while (bno < nsumblocks) { nmap = XFS_BMAP_MAX_NMAP; error = -libxfs_bmapi_write(tp, ip, bno, @@ -845,12 +837,6 @@ mk_rsumino(xfs_mount_t *mp) } } libxfs_defer_ijoin(&dfops, ip); - error = -libxfs_defer_finish(&tp, &dfops); - if (error) { - do_error( - _("allocation of the realtime summary ino failed, error = %d\n"), - error); - } libxfs_trans_commit(tp); IRELE(ip); } @@ -972,7 +958,6 @@ 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); /* * use iget/ijoin instead of trans_iget because the ialloc @@ -1052,13 +1037,6 @@ mk_orphanage(xfs_mount_t *mp) libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); libxfs_defer_ijoin(&dfops, ip); - error = -libxfs_defer_finish(&tp, &dfops); - if (error) { - do_error(_("%s directory creation failed -- bmapf error %d\n"), - ORPHANAGE, error); - } - - libxfs_trans_commit(tp); IRELE(ip); IRELE(pip); @@ -1136,7 +1114,6 @@ mv_orphanage( libxfs_trans_ijoin(tp, orphanage_ip, 0); libxfs_trans_ijoin(tp, ino_p, 0); - libxfs_defer_init(tp, &dfops); err = -libxfs_dir_createname(tp, orphanage_ip, &xname, ino, nres); if (err) @@ -1161,12 +1138,6 @@ mv_orphanage( libxfs_trans_log_inode(tp, ino_p, XFS_ILOG_CORE); libxfs_defer_ijoin(&dfops, ino_p); - err = -libxfs_defer_finish(&tp, &dfops); - if (err) - do_error( - _("bmap finish failed (err - %d), filesystem may be out of space\n"), - err); - libxfs_trans_commit(tp); } else { err = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_rename, @@ -1179,7 +1150,6 @@ mv_orphanage( libxfs_trans_ijoin(tp, orphanage_ip, 0); libxfs_trans_ijoin(tp, ino_p, 0); - libxfs_defer_init(tp, &dfops); err = -libxfs_dir_createname(tp, orphanage_ip, &xname, ino, nres); @@ -1209,12 +1179,6 @@ mv_orphanage( } libxfs_defer_ijoin(&dfops, ino_p); - err = -libxfs_defer_finish(&tp, &dfops); - if (err) - do_error( - _("bmap finish failed (%d), filesystem may be out of space\n"), - err); - libxfs_trans_commit(tp); } @@ -1236,7 +1200,6 @@ mv_orphanage( libxfs_trans_ijoin(tp, orphanage_ip, 0); libxfs_trans_ijoin(tp, ino_p, 0); - libxfs_defer_init(tp, &dfops); err = -libxfs_dir_createname(tp, orphanage_ip, &xname, ino, nres); if (err) @@ -1249,12 +1212,6 @@ mv_orphanage( libxfs_trans_log_inode(tp, ino_p, XFS_ILOG_CORE); libxfs_defer_ijoin(&dfops, ino_p); - err = -libxfs_defer_finish(&tp, &dfops); - if (err) - do_error( - _("bmap finish failed (%d), filesystem may be out of space\n"), - err); - libxfs_trans_commit(tp); } IRELE(ino_p); @@ -1362,8 +1319,6 @@ longform_dir2_rebuild( libxfs_dir_ino_validate(mp, pip.i_ino)) pip.i_ino = mp->m_sb.sb_rootino; - 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); if (error) @@ -1395,8 +1350,6 @@ longform_dir2_rebuild( } libxfs_defer_ijoin(&dfops, ip); - error = -libxfs_defer_finish(&tp, &dfops); - libxfs_trans_commit(tp); if (ino == mp->m_sb.sb_rootino) @@ -1419,7 +1372,6 @@ longform_dir2_rebuild( libxfs_trans_ijoin(tp, ip, 0); - libxfs_defer_init(tp, &dfops); error = -libxfs_dir_createname(tp, ip, &p->name, p->inum, nres); if (error) { @@ -1430,21 +1382,12 @@ _("name create failed in ino %" PRIu64 " (%d), filesystem may be out of space\n" } libxfs_defer_ijoin(&dfops, ip); - error = -libxfs_defer_finish(&tp, &dfops); - if (error) { - do_warn( - _("bmap finish failed (%d), filesystem may be out of space\n"), - error); - goto out_bmap_cancel; - } - libxfs_trans_commit(tp); } return; out_bmap_cancel: - libxfs_defer_cancel(&dfops); libxfs_trans_cancel(tp); return; } @@ -1474,7 +1417,6 @@ dir2_kill_block( libxfs_trans_ijoin(tp, ip, 0); libxfs_trans_bjoin(tp, bp); memset(&args, 0, sizeof(args)); - libxfs_defer_init(tp, &dfops); args.dp = ip; args.trans = tp; args.whichfork = XFS_DATA_FORK; @@ -1488,7 +1430,6 @@ dir2_kill_block( do_error(_("shrink_inode failed inode %" PRIu64 " block %u\n"), ip->i_ino, da_bno); libxfs_defer_ijoin(&dfops, ip); - libxfs_defer_finish(&tp, &dfops); libxfs_trans_commit(tp); } @@ -1663,7 +1604,6 @@ 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); if (be32_to_cpu(d->magic) != wantmagic) { do_warn( _("bad directory block magic # %#x for directory inode %" PRIu64 " block %d: "), @@ -1965,7 +1905,6 @@ _("entry \"%s\" in dir inode %" PRIu64 " inconsistent with .. value (%" PRIu64 " if (needlog) libxfs_dir2_data_log_header(&da, bp); libxfs_defer_ijoin(&dfops, ip); - libxfs_defer_finish(&tp, &dfops); libxfs_trans_commit(tp); /* record the largest free space in the freetab for later checking */ @@ -3017,8 +2956,6 @@ process_dir_inode( libxfs_trans_ijoin(tp, ip, 0); - libxfs_defer_init(tp, &dfops); - error = -libxfs_dir_createname(tp, ip, &xfs_name_dotdot, ip->i_ino, nres); if (error) @@ -3028,8 +2965,6 @@ process_dir_inode( libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); libxfs_defer_ijoin(&dfops, ip); - error = -libxfs_defer_finish(&tp, &dfops); - ASSERT(error == 0); libxfs_trans_commit(tp); need_root_dotdot = 0; @@ -3075,8 +3010,6 @@ process_dir_inode( libxfs_trans_ijoin(tp, ip, 0); - libxfs_defer_init(tp, &dfops); - error = -libxfs_dir_createname(tp, ip, &xfs_name_dot, ip->i_ino, nres); if (error) @@ -3087,8 +3020,6 @@ process_dir_inode( libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); libxfs_defer_ijoin(&dfops, ip); - error = -libxfs_defer_finish(&tp, &dfops); - ASSERT(error == 0); libxfs_trans_commit(tp); } }