From nobody Tue Apr 4 15:26:02 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 4PrWnL0nbwz43kTt; Tue, 4 Apr 2023 15:26:14 +0000 (UTC) (envelope-from rick.macklem@gmail.com) Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PrWnK3RTrz3jsn; Tue, 4 Apr 2023 15:26:13 +0000 (UTC) (envelope-from rick.macklem@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-pj1-x1032.google.com with SMTP id fy10-20020a17090b020a00b0023b4bcf0727so34350818pjb.0; Tue, 04 Apr 2023 08:26:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680621972; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=uhv5dG3aoAiA7jFmYUtPH3pRQmf8yEQig4TqRDb6Y2M=; b=d3KivTjpR8ompfVvCl7v2Nugd0CuqW1unQdaTZUZSy0zUsctBLeOFzILhq+DT5gGNM E90U2FcTGocrb5uP+GqCpYFDeadYuUl52/WjaPbSmLkHLlJ1lr41Pn/XDdkUm6cslSGf wZYltoaljQmpcQEzJx4UXoGzFvsUgALqUZUybT8BTfI06km83ityem+lsXXrcyPzXF6n O4qYlLLRvfqNlwnO178VOY1dVac31Aao5NHr3hetwtpwPxj3TQAbaPBfOmHMRvOyCmmg nmOPgzoh6Hp41os1NeV2JxQiGVOmlqMaOEDhHPmmcsUsh+ukSNGFQJGE74z5FSpgbKs4 0ugA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680621972; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uhv5dG3aoAiA7jFmYUtPH3pRQmf8yEQig4TqRDb6Y2M=; b=YeQiphfvSdZrxm9vpHPrqjGjOtHSqt8lFzFpL7lloEYxP4kN9G1qOsfumWoQsKF/tf IMuGzgxWS33QudMMfKQQiRmMwPLHJmvcU1Y/tsC/bX6rA1DDrRKurL8OBmG/prOyXjaU NCTUiWH4701cuhfQec7tlfxscNjwg9nw8fzcWPkC5JtMLXYuihy2R4EL7epvgjbnt3CX bu8ks9s4Tk+S4afOmBkG0sUJFiVFF8DDMabFJh3q5ofk10BnDe46lquwvwDtuyLeXhnc 9J9DyUql6Hn6Uzz1WPmufaFXYqaEcFsarCe8skii3N7zKfRONZABnsUVfFy64xCrsoxJ DPkA== X-Gm-Message-State: AAQBX9dVe7wvfUhmt//MtSBDri0s0gBCR1EtASd0xc/zj6JFWjgDldhV 89qPliq49UqTI/0lVIYPNL8OdTl9fUC5kUE8TA== X-Google-Smtp-Source: AKy350Y1HSpf2V3He2jzcOYl3yVTgx9GkcvSObmY8Xw+rJlZ1X7h6H8EExzA2Ug5g7Rh794Aotg8Q6+PuFg+mFfEKy4= X-Received: by 2002:a17:902:e80c:b0:1a2:8fa0:fbd7 with SMTP id u12-20020a170902e80c00b001a28fa0fbd7mr5983963plg.2.1680621972146; Tue, 04 Apr 2023 08:26:12 -0700 (PDT) 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 References: <202304041145.334Bjx6l035872@gitrepo.freebsd.org> <20230404141717.B976D31C@slippy.cwsent.com> In-Reply-To: From: Rick Macklem Date: Tue, 4 Apr 2023 08:26:02 -0700 Message-ID: Subject: Re: git: 8ee579abe09e - main - zfs: fall back if block_cloning feature is disabled To: Mateusz Guzik Cc: Cy Schubert , Martin Matuska , src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4PrWnK3RTrz3jsn X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; TAGGED_FROM(0.00)[] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On Tue, Apr 4, 2023 at 7:38=E2=80=AFAM Mateusz Guzik wr= ote: > > CAUTION: This email originated from outside of the University of Guelph. = Do not click links or open attachments unless you recognize the sender and = know the content is safe. If in doubt, forward suspicious emails to IThelp@= uoguelph.ca > > > 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=3D8ee579abe09ec1fe15c588fc9a08= 370b > >> 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 =3D *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 th= en we > >> - * need something else than vn_generic_copy_file_range(). > >> - */ > >> - > >> /* Lock both vnodes, avoiding risk of deadlock. */ > >> do { > >> mp =3D NULL; > >> @@ -6300,6 +6293,16 @@ unlock: > >> if (mp !=3D NULL) > >> vn_finished_write(mp); > >> > >> + /* > >> + * Fall back if block_cloning feature is disabled > >> + * or other EXDEV failures from zfs_vnops.c > >> + */ > >> + if (error =3D=3D EXDEV) { > >> + error =3D vn_generic_copy_file_range(ap->a_invp, ap->a_in= offp, > >> + 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) !=3D 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. Since VOP_COPY_FILE_RANGE() is only called when invp and outvp are on the same mount point, I don't think this can happen now. However, there is a TO DO comment that suggests a call with invp and outvp on different mount points may be in the future. As such, leaving Martin's patch in so that it calls vn_generic_copy_file_ra= nge() when zfs_clone_range() returns EXDEV seems like a good idea to me. > > That aside the code looks rather suspicious for the case where target > and source vnode are the same. iow more work is needed here. Definitely needs to be tested. I'll do that later to-day. rick > > As the vnode is unlocked, you *can't* safely access zfsvfs_t > *outzfsvfs =3D 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 > > index d41821ff67f1..e18dcca58192 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,6 +6243,18 @@ zfs_freebsd_copy_file_range(struct > > vop_copy_file_range_args *ap) > > int error; > > uint64_t len =3D *ap->a_lenp; > > > > + znode_t *outzp =3D VTOZ(ap->a_outvp); > > + zfsvfs_t *outzfsvfs =3D ZTOZSB(outzp); > > + objset_t *outos =3D outzfsvfs->z_os; > > + > > + if (!spa_feature_is_enabled(dmu_objset_spa(outos), > > + SPA_FEATURE_BLOCK_CLONING)) { > > + error =3D vn_generic_copy_file_range(ap->a_invp, ap->a_in= offp, > > + ap->a_outvp, ap->a_outoffp, ap->a_lenp, ap->a_fla= gs, > > + ap->a_incred, ap->a_outcred, ap->a_fsizetd); > > + return (error); > > + } > > + > > /* > > * TODO: If offset/length is not aligned to recordsize, use > > * vn_generic_copy_file_range() on this fragment. > > > > > > Can you revert your commit and commit this, please. > > > > > > -- > > Cheers, > > Cy Schubert > > FreeBSD UNIX: Web: https://FreeBSD.org > > NTP: Web: https://nwtime.org > > > > e^(i*pi)+1=3D0 > > > > > > > > > > > -- > Mateusz Guzik