From nobody Tue Apr 4 15:02:05 2023 X-Original-To: dev-commits-src-main@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 4PrWFZ02YGz43hhF; Tue, 4 Apr 2023 15:02:10 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Received: from omta001.cacentral1.a.cloudfilter.net (omta001.cacentral1.a.cloudfilter.net [3.97.99.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "Client", Issuer "CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PrWFY4CdRz3h7M; Tue, 4 Apr 2023 15:02:09 +0000 (UTC) (envelope-from cy.schubert@cschubert.com) Authentication-Results: mx1.freebsd.org; none Received: from shw-obgw-4004a.ext.cloudfilter.net ([10.228.9.227]) by cmsmtp with ESMTP id jefcpqCymuZMSjiAipwxEH; Tue, 04 Apr 2023 15:02:08 +0000 Received: from spqr.komquats.com ([70.66.148.124]) by cmsmtp with ESMTPA id jiAgpZaog3fOSjiAhpL24h; Tue, 04 Apr 2023 15:02:08 +0000 X-Authority-Analysis: v=2.4 cv=J8G5USrS c=1 sm=1 tr=0 ts=642c3bf0 a=Cwc3rblV8FOMdVN/wOAqyQ==:117 a=Cwc3rblV8FOMdVN/wOAqyQ==:17 a=kj9zAlcOel0A:10 a=dKHAf1wccvYA:10 a=YxBL1-UpAAAA:8 a=6I5d2MoRAAAA:8 a=pGLkceISAAAA:8 a=EkcXrb_YAAAA:8 a=j200Wlr0vxhBlC_MzVoA:9 a=CjuIK1q_8ugA:10 a=UJ0tAi3fqDAA:10 a=Ia-lj3WSrqcvXOmTRaiG:22 a=IjZwj45LgO3ly-622nXo:22 a=LK5xJRSDVpKd5WXXoEvA:22 Received: from slippy.cwsent.com (slippy [10.1.1.91]) by spqr.komquats.com (Postfix) with ESMTP id 38329A74; Tue, 4 Apr 2023 08:02:06 -0700 (PDT) Received: by slippy.cwsent.com (Postfix, from userid 1000) id 0A0512A7; Tue, 4 Apr 2023 08:02:05 -0700 (PDT) X-Mailer: exmh version 2.9.0 11/07/2018 with nmh-1.8+dev Reply-to: Cy Schubert From: Cy Schubert X-os: FreeBSD X-Sender: cy@cwsent.com X-URL: http://www.cschubert.com/ To: Mateusz Guzik cc: Cy Schubert , Martin Matuska , src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 8ee579abe09e - main - zfs: fall back if block_cloning feature is disabled In-reply-to: References: <202304041145.334Bjx6l035872@gitrepo.freebsd.org> <20230404141717.B976D31C@slippy.cwsent.com> Comments: In-reply-to Mateusz Guzik message dated "Tue, 04 Apr 2023 16:37:56 +0200." List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Tue, 04 Apr 2023 08:02:05 -0700 Message-Id: <20230404150206.0A0512A7@slippy.cwsent.com> X-CMAE-Envelope: MS4xfLJnwLsNdrN3x1MX5ITBUYyeFLI8H/RTYhdCHwpYbV81Z+QMKbyebz0/rBSTtksv7d6+oJS79kGQy0TqBIVObuFGGUg5cIOB0LattV4b0QdliCb6x5Nl dckKM+ewcnn86p7Iiufensd/kDjKkdBEi4ZOdctBwjNhWHRCKIC10iplCPxC422aCZdH1+KLe7uI9/h6Rf7c17/te7jB0BPaUjeaaLEoLbX6YNcbRg4PkWVn tYkJeshQC/ovquDEj3uTBot6z3lGC7fppbrWdgAB+NWuvx6rp1ngrVMrbfmG815/KkAFA8lggVtCkQwCUJxR5PoaCqQEZUYGrVUrMdpXO6GZS0i+fuIHkJU4 /qUlisu2 X-Rspamd-Queue-Id: 4PrWFY4CdRz3h7M X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:16509, ipnet:3.96.0.0/15, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N In message , Mateusz Guzik writes: > On 4/4/23, Cy Schubert wrote: > > In message <202304041145.334Bjx6l035872@gitrepo.freebsd.org>, Martin > > Matuska wr > > ites: > >> The branch main has been updated by mm: > >> > >> URL: > >> https://cgit.FreeBSD.org/src/commit/?id=8ee579abe09ec1fe15c588fc9a08370b > >> 83b81cd6 > >> > >> commit 8ee579abe09ec1fe15c588fc9a08370b83b81cd6 > >> Author: Martin Matuska > >> AuthorDate: 2023-04-04 11:40:41 +0000 > >> Commit: Martin Matuska > >> CommitDate: 2023-04-04 11:43:34 +0000 > >> > >> zfs: fall back if block_cloning feature is disabled > >> > >> If block_cloning is disabled, or other errors from zfs_clone_range() > >> return an EXDEV we should fall back to vn_generic_copy_file_range(). > >> > >> This fixes issues when copying files on the same dataset with > >> block_cloning disabled. > >> > >> Upstreamed as pull request to OpenZFS. > >> > >> Reviewed by: Mateusz Guzik > >> OpenZFS pull request: 14713 > >> --- > >> .../openzfs/module/os/freebsd/zfs/zfs_vnops_os.c | 17 > >> ++++++++++----- > >> -- > >> 1 file changed, 10 insertions(+), 7 deletions(-) > >> > >> diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c > >> b/sys/c > >> ontrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c > >> index 97429b360a36..2cd1d27e37bc 100644 > >> --- a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c > >> +++ b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c > >> @@ -6243,13 +6243,6 @@ zfs_freebsd_copy_file_range(struct > >> vop_copy_file_range > >> _args *ap) > >> int error; > >> uint64_t len = *ap->a_lenp; > >> > >> - /* > >> - * TODO: If offset/length is not aligned to recordsize, use > >> - * vn_generic_copy_file_range() on this fragment. > >> - * It would be better to do this after we lock the vnodes, but then we > >> - * need something else than vn_generic_copy_file_range(). > >> - */ > >> - > >> /* Lock both vnodes, avoiding risk of deadlock. */ > >> do { > >> mp = NULL; > >> @@ -6300,6 +6293,16 @@ unlock: > >> if (mp != NULL) > >> vn_finished_write(mp); > >> > >> + /* > >> + * Fall back if block_cloning feature is disabled > >> + * or other EXDEV failures from zfs_vnops.c > >> + */ > >> + if (error == EXDEV) { > >> + error = vn_generic_copy_file_range(ap->a_invp, ap->a_inoffp, > >> + ap->a_outvp, ap->a_outoffp, ap->a_lenp, ap->a_flags > >> , > >> + ap->a_incred, ap->a_outcred, ap->a_fsizetd); > >> + } > >> + > >> return (error); > >> } > >> > >> > > > > This is too late to fall back. On Rick's suggestion the following makes the > > > > determination at > > zfs_freebsd_copy_file_range() entry much earlier. > > > > It's not too late, but I agree it is faster to bail out early. > > The proposed patch adds a condition which *differs* from the one in > zfs_clone_range: > if (dmu_objset_spa(inos) != dmu_objset_spa(outos)) { > zfs_exit_two(inzfsvfs, outzfsvfs, FTAG); > return (SET_ERROR(EXDEV)); > } > > ... meaning with the proposed patch the routine can still fail with > EXDEV, making zfs_freebsd_copy_file_range also do it, which must not > happen. > > That aside the code looks rather suspicious for the case where target > and source vnode are the same. iow more work is needed here. > > As the vnode is unlocked, you *can't* safely access zfsvfs_t > *outzfsvfs = ZTOZSB(outzp); in that spot in this manner -- a forced > unmount at the same time can free it. > > iow this patch does *NOT* work. > > With the committed variant the situation is damage controlled enough > that there is time to sort it out correctly. > > > diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c > > b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c [...] Gotcha. What you're suggesting is something more like this. Check for block_cloning and also retry should zfs_clone_range() return EXDEV for any other reason. diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c index baa2ee5b3824..60916bfcfbc3 100644 --- a/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c +++ b/sys/contrib/openzfs/module/os/freebsd/zfs/zfs_vnops_os.c @@ -6239,6 +6239,9 @@ zfs_freebsd_copy_file_range(struct vop_copy_file_range_args *ap) struct vnode *invp = ap->a_invp; struct vnode *outvp = ap->a_outvp; struct mount *mp; + znode_t *outzp; + zfsvfs_t *outzfsvfs; + objset_t *outos; struct uio io; int error; uint64_t len = *ap->a_lenp; @@ -6276,6 +6279,19 @@ zfs_freebsd_copy_file_range(struct vop_copy_file_range_args *ap) } while (error == 0); if (error != 0) return (error); + + outzp = VTOZ(ap->a_outvp); + outzfsvfs = ZTOZSB(outzp); + outos = outzfsvfs->z_os; + + if (!spa_feature_is_enabled(dmu_objset_spa(outos), + SPA_FEATURE_BLOCK_CLONING)) { + error = vn_generic_copy_file_range(ap->a_invp, ap->a_inoffp, + ap->a_outvp, ap->a_outoffp, ap->a_lenp, ap->a_flags, + ap->a_incred, ap->a_outcred, ap->a_fsizetd); + goto unlock; + } + #ifdef MAC error = mac_vnode_check_write(curthread->td_ucred, ap->a_outcred, outvp); @@ -6291,6 +6307,11 @@ zfs_freebsd_copy_file_range(struct vop_copy_file_range_args *ap) error = zfs_clone_range(VTOZ(invp), ap->a_inoffp, VTOZ(outvp), ap->a_outoffp, &len, ap->a_outcred); + + if (error == EXDEV) + error = vn_generic_copy_file_range(ap->a_invp, ap->a_inoffp, + ap->a_outvp, ap->a_outoffp, ap->a_lenp, ap->a_flags, + ap->a_incred, ap->a_outcred, ap->a_fsizetd); *ap->a_lenp = (size_t)len; unlock: -- Cheers, Cy Schubert FreeBSD UNIX: Web: https://FreeBSD.org NTP: Web: https://nwtime.org e^(i*pi)+1=0