The branch main has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=d4d289cd51078de9e82c9d83977cfa614032cd06

commit d4d289cd51078de9e82c9d83977cfa614032cd06
Author:     Konstantin Belousov <k...@freebsd.org>
AuthorDate: 2021-05-21 14:12:08 +0000
Commit:     Konstantin Belousov <k...@freebsd.org>
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);
 }
_______________________________________________
dev-commits-src-main@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "dev-commits-src-main-unsubscr...@freebsd.org"

Reply via email to