From owner-dev-commits-src-all@freebsd.org Wed Jun 23 20:47:31 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id A4BD665726C; Wed, 23 Jun 2021 20:47:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4G9Fh113BBz3sBZ; Wed, 23 Jun 2021 20:47:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 98B142EED; Wed, 23 Jun 2021 20:47:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 15NKlStK009845; Wed, 23 Jun 2021 20:47:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 15NKlSQF009844; Wed, 23 Jun 2021 20:47:28 GMT (envelope-from git) Date: Wed, 23 Jun 2021 20:47:28 GMT Message-Id: <202106232047.15NKlSQF009844@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: d4d289cd5107 - main - ffs: mark block (re-)allocations as seqc writes MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d4d289cd51078de9e82c9d83977cfa614032cd06 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jun 2021 20:47:31 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=d4d289cd51078de9e82c9d83977cfa614032cd06 commit d4d289cd51078de9e82c9d83977cfa614032cd06 Author: Konstantin Belousov AuthorDate: 2021-05-21 14:12:08 +0000 Commit: Konstantin Belousov CommitDate: 2021-06-23 20:46:15 +0000 ffs: mark block (re-)allocations as seqc writes Reviewed by: mckusick Discussed with: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D30041 --- sys/ufs/ffs/ffs_alloc.c | 9 ++-- sys/ufs/ffs/ffs_balloc.c | 116 ++++++++++++++++++++++++++++------------------- 2 files changed, 75 insertions(+), 50 deletions(-) diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c index c895c8c7bf07..771377b7cefc 100644 --- a/sys/ufs/ffs/ffs_alloc.c +++ b/sys/ufs/ffs/ffs_alloc.c @@ -517,6 +517,7 @@ ffs_reallocblks(ap) } */ *ap; { struct ufsmount *ump; + int error; /* * We used to skip reallocating the blocks of a file into a @@ -546,9 +547,11 @@ ffs_reallocblks(ap) if (DOINGSUJ(ap->a_vp)) if (softdep_prealloc(ap->a_vp, MNT_NOWAIT) != 0) return (ENOSPC); - if (ump->um_fstype == UFS1) - return (ffs_reallocblks_ufs1(ap)); - return (ffs_reallocblks_ufs2(ap)); + vn_seqc_write_begin(ap->a_vp); + error = ump->um_fstype == UFS1 ? ffs_reallocblks_ufs1(ap) : + ffs_reallocblks_ufs2(ap); + vn_seqc_write_end(ap->a_vp); + return (error); } static int diff --git a/sys/ufs/ffs/ffs_balloc.c b/sys/ufs/ffs/ffs_balloc.c index 1b53a90a48c4..d7718e56dd87 100644 --- a/sys/ufs/ffs/ffs_balloc.c +++ b/sys/ufs/ffs/ffs_balloc.c @@ -128,6 +128,8 @@ ffs_balloc_ufs1(struct vnode *vp, off_t startoffset, int size, return (EFBIG); gbflags = (flags & BA_UNMAPPED) != 0 ? GB_UNMAPPED : 0; + vn_seqc_write_begin(vp); + /* * If the next write will extend the file into a new block, * and the file is currently composed of a fragment @@ -144,7 +146,7 @@ ffs_balloc_ufs1(struct vnode *vp, off_t startoffset, int size, &dp->di_db[0]), osize, (int)fs->fs_bsize, flags, cred, &bp); if (error) - return (error); + goto done; if (DOINGSOFTDEP(vp)) softdep_setup_allocdirect(ip, nb, dbtofsb(fs, bp->b_blkno), dp->di_db[nb], @@ -174,17 +176,20 @@ ffs_balloc_ufs1(struct vnode *vp, off_t startoffset, int size, error = bread(vp, lbn, fs->fs_bsize, NOCRED, &bp); if (error != 0) - return (error); + goto done; } else { bp = getblk(vp, lbn, fs->fs_bsize, 0, 0, gbflags); - if (bp == NULL) - return (EIO); + if (bp == NULL) { + error = EIO; + goto done; + } vfs_bio_clrbuf(bp); } bp->b_blkno = fsbtodb(fs, nb); *bpp = bp; - return (0); + error = 0; + goto done; } if (nb != 0) { /* @@ -194,9 +199,8 @@ ffs_balloc_ufs1(struct vnode *vp, off_t startoffset, int size, nsize = fragroundup(fs, size); if (nsize <= osize) { error = bread(vp, lbn, osize, NOCRED, &bp); - if (error) { - return (error); - } + if (error) + goto done; bp->b_blkno = fsbtodb(fs, nb); } else { UFS_LOCK(ump); @@ -205,7 +209,7 @@ ffs_balloc_ufs1(struct vnode *vp, off_t startoffset, int size, &dp->di_db[0]), osize, nsize, flags, cred, &bp); if (error) - return (error); + goto done; if (DOINGSOFTDEP(vp)) softdep_setup_allocdirect(ip, lbn, dbtofsb(fs, bp->b_blkno), nb, @@ -221,7 +225,7 @@ ffs_balloc_ufs1(struct vnode *vp, off_t startoffset, int size, ffs_blkpref_ufs1(ip, lbn, (int)lbn, &dp->di_db[0]), nsize, flags, cred, &newb); if (error) - return (error); + goto done; bp = getblk(vp, lbn, nsize, 0, 0, gbflags); bp->b_blkno = fsbtodb(fs, newb); if (flags & BA_CLRBUF) @@ -233,14 +237,15 @@ ffs_balloc_ufs1(struct vnode *vp, off_t startoffset, int size, dp->di_db[lbn] = dbtofsb(fs, bp->b_blkno); UFS_INODE_SET_FLAG(ip, IN_CHANGE | IN_UPDATE | IN_IBLKDATA); *bpp = bp; - return (0); + error = 0; + goto done; } /* * Determine the number of levels of indirection. */ pref = 0; if ((error = ufs_getlbns(vp, lbn, indirs, &num)) != 0) - return(error); + goto done; #ifdef INVARIANTS if (num < 1) panic ("ffs_balloc_ufs1: ufs_getlbns returned indirect block"); @@ -261,7 +266,7 @@ ffs_balloc_ufs1(struct vnode *vp, off_t startoffset, int size, if ((error = ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize, flags, cred, &newb)) != 0) { curthread_pflags_restore(saved_inbdflush); - return (error); + goto done; } pref = newb + fs->fs_frag; nb = newb; @@ -387,7 +392,8 @@ retry: if (flags & BA_METAONLY) { curthread_pflags_restore(saved_inbdflush); *bpp = bp; - return (0); + error = 0; + goto done; } /* * Get the data block, allocating if necessary. @@ -453,7 +459,8 @@ retry: } curthread_pflags_restore(saved_inbdflush); *bpp = nbp; - return (0); + error = 0; + goto done; } brelse(bp); if (flags & BA_CLRBUF) { @@ -478,7 +485,8 @@ retry: } curthread_pflags_restore(saved_inbdflush); *bpp = nbp; - return (0); + error = 0; + goto done; fail: curthread_pflags_restore(saved_inbdflush); /* @@ -486,7 +494,7 @@ fail: * This is the usual case and avoids the need to fsync the file. */ if (allocblk == allociblk && allocib == NULL && unwindidx == -1) - return (error); + goto done; /* * If we have failed part way through block allocation, we * have to deallocate any indirect blocks that we have allocated. @@ -574,6 +582,8 @@ fail: ffs_blkfree(ump, fs, ump->um_devvp, *blkp, fs->fs_bsize, ip->i_number, vp->v_type, NULL, SINGLETON_KEY); } +done: + vn_seqc_write_end(vp); return (error); } @@ -619,12 +629,17 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, return (EFBIG); gbflags = (flags & BA_UNMAPPED) != 0 ? GB_UNMAPPED : 0; + vn_seqc_write_begin(vp); + /* * Check for allocating external data. */ if (flags & IO_EXT) { - if (lbn >= UFS_NXADDR) - return (EFBIG); + if (lbn >= UFS_NXADDR) { + error = EFBIG; + goto done; + } + /* * If the next write will extend the data into a new block, * and the data is currently composed of a fragment @@ -642,7 +657,7 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, &dp->di_extb[0]), osize, (int)fs->fs_bsize, flags, cred, &bp); if (error) - return (error); + goto done; if (DOINGSOFTDEP(vp)) softdep_setup_allocext(ip, nb, dbtofsb(fs, bp->b_blkno), @@ -668,13 +683,12 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, if (nb != 0 && dp->di_extsize >= smalllblktosize(fs, lbn + 1)) { error = bread_gb(vp, -1 - lbn, fs->fs_bsize, NOCRED, gbflags, &bp); - if (error) { - return (error); - } + if (error) + goto done; bp->b_blkno = fsbtodb(fs, nb); bp->b_xflags |= BX_ALTDATA; *bpp = bp; - return (0); + goto done; } if (nb != 0) { /* @@ -685,9 +699,8 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, if (nsize <= osize) { error = bread_gb(vp, -1 - lbn, osize, NOCRED, gbflags, &bp); - if (error) { - return (error); - } + if (error) + goto done; bp->b_blkno = fsbtodb(fs, nb); bp->b_xflags |= BX_ALTDATA; } else { @@ -698,7 +711,7 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, &dp->di_extb[0]), osize, nsize, flags, cred, &bp); if (error) - return (error); + goto done; bp->b_xflags |= BX_ALTDATA; if (DOINGSOFTDEP(vp)) softdep_setup_allocext(ip, lbn, @@ -715,7 +728,7 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, ffs_blkpref_ufs2(ip, lbn, (int)lbn, &dp->di_extb[0]), nsize, flags, cred, &newb); if (error) - return (error); + goto done; bp = getblk(vp, -1 - lbn, nsize, 0, 0, gbflags); bp->b_blkno = fsbtodb(fs, newb); bp->b_xflags |= BX_ALTDATA; @@ -728,7 +741,8 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, dp->di_extb[lbn] = dbtofsb(fs, bp->b_blkno); UFS_INODE_SET_FLAG(ip, IN_CHANGE | IN_IBLKDATA); *bpp = bp; - return (0); + error = 0; + goto done; } /* * If the next write will extend the file into a new block, @@ -746,7 +760,7 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, &dp->di_db[0]), osize, (int)fs->fs_bsize, flags, cred, &bp); if (error) - return (error); + goto done; if (DOINGSOFTDEP(vp)) softdep_setup_allocdirect(ip, nb, dbtofsb(fs, bp->b_blkno), @@ -775,17 +789,20 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, error = bread_gb(vp, lbn, fs->fs_bsize, NOCRED, gbflags, &bp); if (error != 0) - return (error); + goto done; } else { bp = getblk(vp, lbn, fs->fs_bsize, 0, 0, gbflags); - if (bp == NULL) - return (EIO); + if (bp == NULL) { + error = EIO; + goto done; + } vfs_bio_clrbuf(bp); } bp->b_blkno = fsbtodb(fs, nb); *bpp = bp; - return (0); + error = 0; + goto done; } if (nb != 0) { /* @@ -796,9 +813,8 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, if (nsize <= osize) { error = bread_gb(vp, lbn, osize, NOCRED, gbflags, &bp); - if (error) { - return (error); - } + if (error) + goto done; bp->b_blkno = fsbtodb(fs, nb); } else { UFS_LOCK(ump); @@ -807,7 +823,7 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, &dp->di_db[0]), osize, nsize, flags, cred, &bp); if (error) - return (error); + goto done; if (DOINGSOFTDEP(vp)) softdep_setup_allocdirect(ip, lbn, dbtofsb(fs, bp->b_blkno), nb, @@ -823,7 +839,7 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, ffs_blkpref_ufs2(ip, lbn, (int)lbn, &dp->di_db[0]), nsize, flags, cred, &newb); if (error) - return (error); + goto done; bp = getblk(vp, lbn, nsize, 0, 0, gbflags); bp->b_blkno = fsbtodb(fs, newb); if (flags & BA_CLRBUF) @@ -835,14 +851,15 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, dp->di_db[lbn] = dbtofsb(fs, bp->b_blkno); UFS_INODE_SET_FLAG(ip, IN_CHANGE | IN_UPDATE | IN_IBLKDATA); *bpp = bp; - return (0); + error = 0; + goto done; } /* * Determine the number of levels of indirection. */ pref = 0; if ((error = ufs_getlbns(vp, lbn, indirs, &num)) != 0) - return(error); + goto done; #ifdef INVARIANTS if (num < 1) panic ("ffs_balloc_ufs2: ufs_getlbns returned indirect block"); @@ -863,7 +880,7 @@ ffs_balloc_ufs2(struct vnode *vp, off_t startoffset, int size, if ((error = ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize, flags, cred, &newb)) != 0) { curthread_pflags_restore(saved_inbdflush); - return (error); + goto done; } pref = newb + fs->fs_frag; nb = newb; @@ -991,7 +1008,8 @@ retry: if (flags & BA_METAONLY) { curthread_pflags_restore(saved_inbdflush); *bpp = bp; - return (0); + error = 0; + goto done; } /* * Get the data block, allocating if necessary. @@ -1057,7 +1075,8 @@ retry: } curthread_pflags_restore(saved_inbdflush); *bpp = nbp; - return (0); + error = 0; + goto done; } brelse(bp); /* @@ -1088,7 +1107,8 @@ retry: } curthread_pflags_restore(saved_inbdflush); *bpp = nbp; - return (0); + error = 0; + goto done; fail: curthread_pflags_restore(saved_inbdflush); /* @@ -1096,7 +1116,7 @@ fail: * This is the usual case and avoids the need to fsync the file. */ if (allocblk == allociblk && allocib == NULL && unwindidx == -1) - return (error); + goto done; /* * If we have failed part way through block allocation, we * have to deallocate any indirect blocks that we have allocated. @@ -1184,5 +1204,7 @@ fail: ffs_blkfree(ump, fs, ump->um_devvp, *blkp, fs->fs_bsize, ip->i_number, vp->v_type, NULL, SINGLETON_KEY); } +done: + vn_seqc_write_end(vp); return (error); }