]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: refactor dfops init to attach to transaction
authorBrian Foster <bfoster@redhat.com>
Thu, 4 Oct 2018 19:39:01 +0000 (14:39 -0500)
committerEric Sandeen <sandeen@redhat.com>
Thu, 4 Oct 2018 19:39:01 +0000 (14:39 -0500)
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 <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/util.c
libxfs/xfs_attr.c
libxfs/xfs_attr_remote.c
libxfs/xfs_bmap.c
libxfs/xfs_defer.c
libxfs/xfs_defer.h
libxfs/xfs_refcount.c
mkfs/proto.c
repair/phase6.c

index 5eb4e557d2970665fc5eed594625c2724eb6bf53..cf4dd83fc3de13ccbeffb903be32dff3274c2164 100644 (file)
@@ -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);
 
index 8b5ff6559d6396b5b7f96e1f30b55c0790eeae1b..92e445dfed2e0f60d13aaee71cc3c1cfbd1f53d4 100644 (file)
@@ -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)
index b81363a42ab226b39f9c38aa7cab233798c1eb72..bc5fc3c8c78efdfab29390eac7b6ffe91131832b 100644 (file)
@@ -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);
index 124132670745eb66e8e121f732c3505f1013bc76..f34fb3428221000c0d8e0640d3b863a2ff21101a 100644 (file)
@@ -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);
index 30aa33e7e5dc018853712fd46dfc83a6fdd917f2..3ddb58e9df3623987c23d339e19cf7e14900a625 100644 (file)
@@ -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_);
 }
index a02b2b748b6d062bc233f488b89d43ea70464b48..56eaaac31df558245089e00a7bf1a3ec080f274a 100644 (file)
@@ -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);
index d7d1bb8a890f3061da1345b5ae711ea138c4744d..7132ee1d10ff0acc13931386e35ba48446a94bbd 100644 (file)
@@ -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,
index 9d5d68db446c6b781166ca4e2234f8ec4aa5abed..671774fff1dbf1bc4c8413c9a7dbbe7dab011a20 100644 (file)
@@ -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));
index eb99638f88284b706c57c2d03719d30a650fbcb0..4b925e7e486a074daabce084356c9a08f14c67cb 100644 (file)
@@ -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);