From nobody Sat Feb 04 18:32:45 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P8Ljp0dRLz3nj4T; Sat, 4 Feb 2023 18:32:46 +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 4P8Ljp08jnz3FQJ; Sat, 4 Feb 2023 18:32:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675535566; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mCLj+6nygwNcHjmQ43iMxOTKWkmh78s/6WF0+nSCqhI=; b=gSKf157+byjlfck9t6Wg7ksRQcgCzM3iIE24p1dILzMONxKr8aOm3Z6BJoJ6BJrbdQCOl9 WRtY+cTbuaXdkVrn6Tl7pjo3PdFgGU+2qjImde5TUie4e0IdwpqKsAbl7jSD4SoRV+/aJe SX9J43t2LH4aG0T5OoQJJDigW6ExUqDRglu2EDuvHEjpC4gejTk/fE54iHwwWWU/YLk4K1 VNMh9viJEGeXUoFZ+ijRX0VN0vtyxNtHldcH3bcBLXi6mkYeAfelvRO1WCdZYpYl7caW96 g8T9BXZ5YOMFiLFwan0Uz/vmB/i0yxUWrdNCFD8zgixWAaOpuODabA8ZZREHWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675535566; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mCLj+6nygwNcHjmQ43iMxOTKWkmh78s/6WF0+nSCqhI=; b=h7eKFiPfSaTmqa2o0soGyxxZgkFjGUuBmSRLnl7eIRvCX67XwAVtbpNkFvuOwMjgrqJSKI Jz9l4DgN2RJ10VhZ6H8I+4x7tGtOW+tv2rugNtOZB/aovra+QtboInF4J91+KQPwjnxXLw Nt6h39f/deSyjFYl+HC6noXFGZLc8EgAjQHX3elOMVGWpR0MRM+OaS7m4aYkfKwS+Toyun 1ZvP8UhTtYRO5uUxJtUyImcmU38KFxhm8VkVLRPzJQ43skeJatc/HEgPEKnII08bKWRL/G CtEOv9M/Q9Q1OuK4z3+7+BesPbJtPSubn8LX5TMwQvxZKQTUrpFAKz2TDtlNNQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675535566; a=rsa-sha256; cv=none; b=gNVS+2UnMwTwCQed50NQaGctcWsh/dITuPtAdEE7VE/nPB94Mqs2PxYSD+GX8xdXsxQW+n 2U6kE7hXDsssnPKKS2+IFA87xO/k/hA2vhEd17hN211rpt8YBGy+6oPl0WNxYQSKU3li9K x1TgSr3/V67QaW2qQhRL5Zj/9N13wBBHhfGTCy14LklrKVEFvfNhzoK+xKQdAMywQmWrnz sFFwePAHNjk6GCItJz+KSJOIU5PCk6dLZ8MkKFznenUz3Kptde+MV+49wQ+l/JE6gSz22H SbuWV0eHPtliwlg4iDoMvStisOP9IGWdp/tBMqEQz/JqzFOsgcEvRKBEPMMOcQ== 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 4P8Ljn6L4pzQNg; Sat, 4 Feb 2023 18:32:45 +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 314IWjLt003386; Sat, 4 Feb 2023 18:32:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 314IWjFq003385; Sat, 4 Feb 2023 18:32:45 GMT (envelope-from git) Date: Sat, 4 Feb 2023 18:32:45 GMT Message-Id: <202302041832.314IWjFq003385@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: 3b6056204dd8 - main - FIOSEEKHOLE/FIOSEEKDATA: correct consistency for bmap-based implementation List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org 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: 3b6056204dd80cc866b7998ef0776247ebc42ce4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=3b6056204dd80cc866b7998ef0776247ebc42ce4 commit 3b6056204dd80cc866b7998ef0776247ebc42ce4 Author: Konstantin Belousov AuthorDate: 2023-02-04 01:20:19 +0000 Commit: Konstantin Belousov CommitDate: 2023-02-04 18:32:07 +0000 FIOSEEKHOLE/FIOSEEKDATA: correct consistency for bmap-based implementation Writes on UFS through a mapped region do not allocate disk blocks in holes immediately. The blocks are allocated when the pages are paged out first time. This breaks the algorithm in vn_bmap_seekhole() and ufs_bmap_seekdata(), because VOP_BMAP() reports hole for the place which already contains a valid data. Clean the pages before doing VOP_BMAP() in the affected functions. In principle, we could clean less by only requesting clean starting from the offset, but it is probably not very important. PR: 269261 Reported by: asomers Reviewed by: asomers, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D38379 --- sys/kern/vfs_vnops.c | 14 ++++++++++++-- sys/ufs/ufs/ufs_bmap.c | 18 ++++++++++++++++++ sys/ufs/ufs/ufs_vnops.c | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index a49070b6060d..1d90f76f9cd6 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -2556,6 +2556,7 @@ int vn_bmap_seekhole_locked(struct vnode *vp, u_long cmd, off_t *off, struct ucred *cred) { + vm_object_t obj; off_t size; daddr_t bn, bnp; uint64_t bsize; @@ -2564,7 +2565,7 @@ vn_bmap_seekhole_locked(struct vnode *vp, u_long cmd, off_t *off, KASSERT(cmd == FIOSEEKHOLE || cmd == FIOSEEKDATA, ("%s: Wrong command %lu", __func__, cmd)); - ASSERT_VOP_LOCKED(vp, "vn_bmap_seekhole_locked"); + ASSERT_VOP_ELOCKED(vp, "vn_bmap_seekhole_locked"); if (vp->v_type != VREG) { error = ENOTTY; @@ -2578,6 +2579,15 @@ vn_bmap_seekhole_locked(struct vnode *vp, u_long cmd, off_t *off, error = ENXIO; goto out; } + + /* See the comment in ufs_bmap_seekdata(). */ + obj = vp->v_object; + if (obj != NULL) { + VM_OBJECT_WLOCK(obj); + vm_object_page_clean(obj, 0, 0, OBJPC_SYNC); + VM_OBJECT_WUNLOCK(obj); + } + bsize = vp->v_mount->mnt_stat.f_iosize; for (bn = noff / bsize; noff < size; bn++, noff += bsize - noff % bsize) { @@ -2613,7 +2623,7 @@ vn_bmap_seekhole(struct vnode *vp, u_long cmd, off_t *off, struct ucred *cred) KASSERT(cmd == FIOSEEKHOLE || cmd == FIOSEEKDATA, ("%s: Wrong command %lu", __func__, cmd)); - if (vn_lock(vp, LK_SHARED) != 0) + if (vn_lock(vp, LK_EXCLUSIVE) != 0) return (EBADF); error = vn_bmap_seekhole_locked(vp, cmd, off, cred); VOP_UNLOCK(vp); diff --git a/sys/ufs/ufs/ufs_bmap.c b/sys/ufs/ufs/ufs_bmap.c index 4ac8ca149279..acdd334f6c7b 100644 --- a/sys/ufs/ufs/ufs_bmap.c +++ b/sys/ufs/ufs/ufs_bmap.c @@ -44,12 +44,16 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include #include #include +#include +#include + #include #include #include @@ -348,6 +352,7 @@ ufs_bmap_seekdata(struct vnode *vp, off_t *offp) struct inode *ip; struct mount *mp; struct ufsmount *ump; + vm_object_t obj; ufs2_daddr_t bn, daddr, nextbn; uint64_t bsize; off_t numblks; @@ -364,6 +369,19 @@ ufs_bmap_seekdata(struct vnode *vp, off_t *offp) if (*offp < 0 || *offp >= ip->i_size) return (ENXIO); + /* + * We could have pages on the vnode' object queue which still + * do not have the data blocks allocated. Convert all dirty + * pages into buffer writes to ensure that we see all + * allocated data. + */ + obj = vp->v_object; + if (obj != NULL) { + VM_OBJECT_WLOCK(obj); + vm_object_page_clean(obj, 0, 0, OBJPC_SYNC); + VM_OBJECT_WUNLOCK(obj); + } + bsize = mp->mnt_stat.f_iosize; for (bn = *offp / bsize, numblks = howmany(ip->i_size, bsize); bn < numblks; bn = nextbn) { diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c index 93a5b173b785..ae6d963920f3 100644 --- a/sys/ufs/ufs/ufs_vnops.c +++ b/sys/ufs/ufs/ufs_vnops.c @@ -2944,7 +2944,7 @@ ufs_ioctl(struct vop_ioctl_args *ap) vp = ap->a_vp; switch (ap->a_command) { case FIOSEEKDATA: - error = vn_lock(vp, LK_SHARED); + error = vn_lock(vp, LK_EXCLUSIVE); if (error == 0) { error = ufs_bmap_seekdata(vp, (off_t *)ap->a_data); VOP_UNLOCK(vp);