From owner-svn-src-all@freebsd.org Tue Apr 9 20:20:06 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5E8D1156C5D6; Tue, 9 Apr 2019 20:20:06 +0000 (UTC) (envelope-from kib@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 00CAA8039E; Tue, 9 Apr 2019 20:20:06 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CEA8B18210; Tue, 9 Apr 2019 20:20:05 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x39KK5ui079833; Tue, 9 Apr 2019 20:20:05 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x39KK452079826; Tue, 9 Apr 2019 20:20:04 GMT (envelope-from kib@FreeBSD.org) Message-Id: <201904092020.x39KK452079826@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Tue, 9 Apr 2019 20:20:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r346065 - in head/sys: fs/fuse fs/msdosfs kern sys X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in head/sys: fs/fuse fs/msdosfs kern sys X-SVN-Commit-Revision: 346065 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 00CAA8039E X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.994,0]; NEURAL_HAM_SHORT(-0.96)[-0.963,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Apr 2019 20:20:06 -0000 Author: kib Date: Tue Apr 9 20:20:04 2019 New Revision: 346065 URL: https://svnweb.freebsd.org/changeset/base/346065 Log: Add vn_fsync_buf(). Provide a convenience function to avoid the hack with filling fake struct vop_fsync_args and then calling vop_stdfsync(). Sponsored by: The FreeBSD Foundation MFC after: 1 week Modified: head/sys/fs/fuse/fuse_io.c head/sys/fs/msdosfs/msdosfs_fat.c head/sys/kern/vfs_default.c head/sys/kern/vfs_vnops.c head/sys/sys/vnode.h Modified: head/sys/fs/fuse/fuse_io.c ============================================================================== --- head/sys/fs/fuse/fuse_io.c Tue Apr 9 19:55:02 2019 (r346064) +++ head/sys/fs/fuse/fuse_io.c Tue Apr 9 20:20:04 2019 (r346065) @@ -771,13 +771,8 @@ fuse_io_strategy(struct vnode *vp, struct buf *bp) int fuse_io_flushbuf(struct vnode *vp, int waitfor, struct thread *td) { - struct vop_fsync_args a = { - .a_vp = vp, - .a_waitfor = waitfor, - .a_td = td, - }; - return (vop_stdfsync(&a)); + return (vn_fsync_buf(vp, waitfor)); } /* Modified: head/sys/fs/msdosfs/msdosfs_fat.c ============================================================================== --- head/sys/fs/msdosfs/msdosfs_fat.c Tue Apr 9 19:55:02 2019 (r346064) +++ head/sys/fs/msdosfs/msdosfs_fat.c Tue Apr 9 20:20:04 2019 (r346065) @@ -980,7 +980,6 @@ extendfile(struct denode *dep, u_long count, struct bu u_long cn, got; struct msdosfsmount *pmp = dep->de_pmp; struct buf *bp; - struct vop_fsync_args fsync_ap; daddr_t blkno; /* @@ -1092,12 +1091,8 @@ extendfile(struct denode *dep, u_long count, struct bu bdwrite(bp); } if (vm_page_count_severe() || - buf_dirty_count_severe()) { - fsync_ap.a_vp = DETOV(dep); - fsync_ap.a_waitfor = MNT_WAIT; - fsync_ap.a_td = curthread; - vop_stdfsync(&fsync_ap); - } + buf_dirty_count_severe()) + vn_fsync_buf(DETOV(dep), MNT_WAIT); } } } Modified: head/sys/kern/vfs_default.c ============================================================================== --- head/sys/kern/vfs_default.c Tue Apr 9 19:55:02 2019 (r346064) +++ head/sys/kern/vfs_default.c Tue Apr 9 20:20:04 2019 (r346065) @@ -638,98 +638,8 @@ vop_stdfsync(ap) struct thread *a_td; } */ *ap; { - struct vnode *vp; - struct buf *bp, *nbp; - struct bufobj *bo; - struct mount *mp; - int error, maxretry; - error = 0; - maxretry = 10000; /* large, arbitrarily chosen */ - vp = ap->a_vp; - mp = NULL; - if (vp->v_type == VCHR) { - VI_LOCK(vp); - mp = vp->v_rdev->si_mountpt; - VI_UNLOCK(vp); - } - bo = &vp->v_bufobj; - BO_LOCK(bo); -loop1: - /* - * MARK/SCAN initialization to avoid infinite loops. - */ - TAILQ_FOREACH(bp, &bo->bo_dirty.bv_hd, b_bobufs) { - bp->b_vflags &= ~BV_SCANNED; - bp->b_error = 0; - } - - /* - * Flush all dirty buffers associated with a vnode. - */ -loop2: - TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) { - if ((bp->b_vflags & BV_SCANNED) != 0) - continue; - bp->b_vflags |= BV_SCANNED; - if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL)) { - if (ap->a_waitfor != MNT_WAIT) - continue; - if (BUF_LOCK(bp, - LK_EXCLUSIVE | LK_INTERLOCK | LK_SLEEPFAIL, - BO_LOCKPTR(bo)) != 0) { - BO_LOCK(bo); - goto loop1; - } - BO_LOCK(bo); - } - BO_UNLOCK(bo); - KASSERT(bp->b_bufobj == bo, - ("bp %p wrong b_bufobj %p should be %p", - bp, bp->b_bufobj, bo)); - if ((bp->b_flags & B_DELWRI) == 0) - panic("fsync: not dirty"); - if ((vp->v_object != NULL) && (bp->b_flags & B_CLUSTEROK)) { - vfs_bio_awrite(bp); - } else { - bremfree(bp); - bawrite(bp); - } - if (maxretry < 1000) - pause("dirty", hz < 1000 ? 1 : hz / 1000); - BO_LOCK(bo); - goto loop2; - } - - /* - * If synchronous the caller expects us to completely resolve all - * dirty buffers in the system. Wait for in-progress I/O to - * complete (which could include background bitmap writes), then - * retry if dirty blocks still exist. - */ - if (ap->a_waitfor == MNT_WAIT) { - bufobj_wwait(bo, 0, 0); - if (bo->bo_dirty.bv_cnt > 0) { - /* - * If we are unable to write any of these buffers - * then we fail now rather than trying endlessly - * to write them out. - */ - TAILQ_FOREACH(bp, &bo->bo_dirty.bv_hd, b_bobufs) - if ((error = bp->b_error) != 0) - break; - if ((mp != NULL && mp->mnt_secondary_writes > 0) || - (error == 0 && --maxretry >= 0)) - goto loop1; - if (error == 0) - error = EAGAIN; - } - } - BO_UNLOCK(bo); - if (error != 0) - vn_printf(vp, "fsync: giving up on dirty (error = %d) ", error); - - return (error); + return (vn_fsync_buf(ap->a_vp, ap->a_waitfor)); } static int @@ -742,12 +652,8 @@ vop_stdfdatasync(struct vop_fdatasync_args *ap) int vop_stdfdatasync_buf(struct vop_fdatasync_args *ap) { - struct vop_fsync_args apf; - apf.a_vp = ap->a_vp; - apf.a_waitfor = MNT_WAIT; - apf.a_td = ap->a_td; - return (vop_stdfsync(&apf)); + return (vn_fsync_buf(ap->a_vp, MNT_WAIT)); } /* XXX Needs good comment and more info in the manpage (VOP_GETPAGES(9)). */ Modified: head/sys/kern/vfs_vnops.c ============================================================================== --- head/sys/kern/vfs_vnops.c Tue Apr 9 19:55:02 2019 (r346064) +++ head/sys/kern/vfs_vnops.c Tue Apr 9 20:20:04 2019 (r346065) @@ -2494,3 +2494,98 @@ vn_fsid(struct vnode *vp, struct vattr *va) va->va_fsid <<= sizeof(f->val[1]) * NBBY; va->va_fsid += (uint32_t)f->val[0]; } + +int +vn_fsync_buf(struct vnode *vp, int waitfor) +{ + struct buf *bp, *nbp; + struct bufobj *bo; + struct mount *mp; + int error, maxretry; + + error = 0; + maxretry = 10000; /* large, arbitrarily chosen */ + mp = NULL; + if (vp->v_type == VCHR) { + VI_LOCK(vp); + mp = vp->v_rdev->si_mountpt; + VI_UNLOCK(vp); + } + bo = &vp->v_bufobj; + BO_LOCK(bo); +loop1: + /* + * MARK/SCAN initialization to avoid infinite loops. + */ + TAILQ_FOREACH(bp, &bo->bo_dirty.bv_hd, b_bobufs) { + bp->b_vflags &= ~BV_SCANNED; + bp->b_error = 0; + } + + /* + * Flush all dirty buffers associated with a vnode. + */ +loop2: + TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) { + if ((bp->b_vflags & BV_SCANNED) != 0) + continue; + bp->b_vflags |= BV_SCANNED; + if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL)) { + if (waitfor != MNT_WAIT) + continue; + if (BUF_LOCK(bp, + LK_EXCLUSIVE | LK_INTERLOCK | LK_SLEEPFAIL, + BO_LOCKPTR(bo)) != 0) { + BO_LOCK(bo); + goto loop1; + } + BO_LOCK(bo); + } + BO_UNLOCK(bo); + KASSERT(bp->b_bufobj == bo, + ("bp %p wrong b_bufobj %p should be %p", + bp, bp->b_bufobj, bo)); + if ((bp->b_flags & B_DELWRI) == 0) + panic("fsync: not dirty"); + if ((vp->v_object != NULL) && (bp->b_flags & B_CLUSTEROK)) { + vfs_bio_awrite(bp); + } else { + bremfree(bp); + bawrite(bp); + } + if (maxretry < 1000) + pause("dirty", hz < 1000 ? 1 : hz / 1000); + BO_LOCK(bo); + goto loop2; + } + + /* + * If synchronous the caller expects us to completely resolve all + * dirty buffers in the system. Wait for in-progress I/O to + * complete (which could include background bitmap writes), then + * retry if dirty blocks still exist. + */ + if (waitfor == MNT_WAIT) { + bufobj_wwait(bo, 0, 0); + if (bo->bo_dirty.bv_cnt > 0) { + /* + * If we are unable to write any of these buffers + * then we fail now rather than trying endlessly + * to write them out. + */ + TAILQ_FOREACH(bp, &bo->bo_dirty.bv_hd, b_bobufs) + if ((error = bp->b_error) != 0) + break; + if ((mp != NULL && mp->mnt_secondary_writes > 0) || + (error == 0 && --maxretry >= 0)) + goto loop1; + if (error == 0) + error = EAGAIN; + } + } + BO_UNLOCK(bo); + if (error != 0) + vn_printf(vp, "fsync: giving up on dirty (error = %d) ", error); + + return (error); +} Modified: head/sys/sys/vnode.h ============================================================================== --- head/sys/sys/vnode.h Tue Apr 9 19:55:02 2019 (r346064) +++ head/sys/sys/vnode.h Tue Apr 9 20:20:04 2019 (r346065) @@ -670,6 +670,7 @@ int vn_close(struct vnode *vp, int flags, struct ucred *file_cred, struct thread *td); void vn_finished_write(struct mount *mp); void vn_finished_secondary_write(struct mount *mp); +int vn_fsync_buf(struct vnode *vp, int waitfor); int vn_isdisk(struct vnode *vp, int *errp); int _vn_lock(struct vnode *vp, int flags, char *file, int line); #define vn_lock(vp, flags) _vn_lock(vp, flags, __FILE__, __LINE__)