From nobody Thu Oct 05 15:41:16 2023 X-Original-To: freebsd-hackers@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 4S1bQ41LPmz4vpFw for ; Thu, 5 Oct 2023 15:41:32 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-ua1-f50.google.com (mail-ua1-f50.google.com [209.85.222.50]) (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 4S1bQ31ThTz3J3Q; Thu, 5 Oct 2023 15:41:31 +0000 (UTC) (envelope-from asomers@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of asomers@gmail.com designates 209.85.222.50 as permitted sender) smtp.mailfrom=asomers@gmail.com; dmarc=none Received: by mail-ua1-f50.google.com with SMTP id a1e0cc1a2514c-7abbe1067d1so462946241.0; Thu, 05 Oct 2023 08:41:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696520490; x=1697125290; 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=fWXwfkRcbSs3kS8WvDAS6WjJ6/R8mTHN9gYOuBmDhjs=; b=Rm44C1lQUaaDZzei4ELXMcqlEzrhRJu2ufXwE/utr/ygB/AvZnCZpGWJircqb/MyXF c4n08ZjiX0CeBmIlwAOqiiWe94OWm2mcnDb0+DSfKl3FHx+M+/9rHfIFPDGhsMqClXap FOMiG7bEJgS2kBEaIzgym4JgTnMoL0eAyhS+mlskkfjUrJySXp93L9Z2cgTlbnSGTv+W 7iRvC0Wrkm5b3QxWVkaWGwyKXo6ecZy6yCIksrS0mowL64pnn+ExZTmdoQyOew5cExc0 DpiUm/lG8Of3HtaKvHFCrHf6lKxaTMDr5TCidvwQtjurkh6gnl/pT3x2PtLFTxKEhwT7 dW6w== X-Gm-Message-State: AOJu0YyBCrR07iXqa953sNjNkR/vc6tZC4LBTiv2QwwiuC+RMMx99zNG WwuAgfIHiQh7AGMk9eB9EiaaF4d4v23o1p9VSAgElW70 X-Google-Smtp-Source: AGHT+IFYbI2eQbYk6Q05be3vwi0mhRNbx+a+zlnjb2vrVrcjiWHgg/e2GzaHPyFJtnf+B7HyTwavXJKGMttvzDxp3Zg= X-Received: by 2002:a67:b641:0:b0:44d:4b8d:31e5 with SMTP id e1-20020a67b641000000b0044d4b8d31e5mr4591200vsm.35.1696520489691; Thu, 05 Oct 2023 08:41:29 -0700 (PDT) List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 References: In-Reply-To: From: Alan Somers Date: Thu, 5 Oct 2023 08:41:16 -0700 Message-ID: Subject: Re: copy_file_range() doesn't update the atime of an empty file To: Rick Macklem Cc: Mark Johnston , freebsd-hackers@freebsd.org, rmacklem@freebsd.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: -- X-Spamd-Result: default: False [-2.52 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.52)[-0.516]; FORGED_SENDER(0.30)[asomers@freebsd.org,asomers@gmail.com]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_ONE(0.00)[1]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; RCVD_TLS_LAST(0.00)[]; FREEMAIL_TO(0.00)[gmail.com]; MIME_TRACE(0.00)[0:+]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.222.50:from]; FREEMAIL_ENVFROM(0.00)[gmail.com]; R_DKIM_NA(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[209.85.222.50:from]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DMARC_NA(0.00)[freebsd.org]; FROM_HAS_DN(0.00)[]; FREEFALL_USER(0.00)[asomers]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; RCPT_COUNT_THREE(0.00)[4]; TAGGED_RCPT(0.00)[]; TO_DN_SOME(0.00)[]; ARC_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[asomers@freebsd.org,asomers@gmail.com] X-Rspamd-Queue-Id: 4S1bQ31ThTz3J3Q I don't think that Linux is a good model to copy from, where atime is concerned. It long ago gave up on POSIX-compliance for atime by default. In this case, I think it's better to stick as closely as we can to read(2). Preserving the existing behavior of tools like cat, too, is worthwhile I think. On Thu, Oct 5, 2023 at 7:53=E2=80=AFAM Rick Macklem wrote: > > Note that, although i'd prefer to keep copy_file_range(2) Linux compatibl= e, > I would like to hear others chime in w.r.t. their preference. > > rick > > On Wed, Oct 4, 2023 at 4:39=E2=80=AFPM Rick Macklem wrote: > > > > Resent now that I am subscribed to freebsd-hackers@, > > > > On Wed, Oct 4, 2023 at 4:25=E2=80=AFPM Rick Macklem wrote: > > > > > > On Wed, Oct 4, 2023 at 8:40=E2=80=AFAM Alan Somers wrote: > > > > > > > > CAUTION: This email originated from outside of the University of Gu= elph. Do not click links or open attachments unless you recognize the sende= r and know the content is safe. If in doubt, forward suspicious emails to I= Thelp@uoguelph.ca. > > > > > > > > > > > > On Wed, Oct 4, 2023 at 8:31=E2=80=AFAM Mark Johnston wrote: > > > > > > > > > > For a while, Jenkins has been complaining that one of the tmpfs t= ests is > > > > > failing: > > > > > https://ci.freebsd.org/job/FreeBSD-main-amd64-test/23814/testRepo= rt/junit/sys.fs.tmpfs/times_test/empty/ > > > > > > > > > > This has been happening since commit > > > > > 8113cc827611a88540736c92ced7d3a7020a1723, which converted cat(1) = to use > > > > > copy_file_range(2). The test in question creates an empty file, = waits > > > > > for a second, then cat(1)s it and checks that the file's atime wa= s > > > > > updated. After the aforementioned commit, the atime is not updat= ed. > > > > > > > > > > I believe the essential difference is that a zero-length read(2) = results > > > > > in a call to VOP_READ(), which results in an updated atime even i= f no > > > > > bytes were read. For instance, ffs_read() sets IN_ACCESS so long= as the > > > > > routine doesn't return an error. (I'm not sure if the mtime is > > > > > correspondingly updated upon a zero-length write.) > > > > > > > > > > copy_file_range() on the other hand elides calls to VOP_READ/VOP_= WRITE > > > > > when copylen is 0, so the atime doesn't get updated. I wonder if= we > > > > > could at least change it to call VOP_READ in that scenario, as in= the > > > > > untested patch below. Any thoughts? > > > > > > > > > > diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c > > > > > index 4e4161ef1a7f..d60608a6d3b9 100644 > > > > > --- a/sys/kern/vfs_vnops.c > > > > > +++ b/sys/kern/vfs_vnops.c > > > > > @@ -3499,7 +3499,7 @@ vn_generic_copy_file_range(struct vnode *in= vp, off_t *inoffp, > > > > > xfer -=3D (*inoffp % blksize); > > > > > } > > > > > /* Loop copying the data block. */ > > > > > - while (copylen > 0 && error =3D=3D 0 && !eof && i= nterrupted =3D=3D 0) { > > > > > + while (error =3D=3D 0 && !eof && interrupted =3D= =3D 0) { > > > > > if (copylen < xfer) > > > > > xfer =3D copylen; > > > > > error =3D vn_lock(invp, LK_SHARED); > > > > > @@ -3511,7 +3511,7 @@ vn_generic_copy_file_range(struct vnode *in= vp, off_t *inoffp, > > > > > curthread); > > > > > VOP_UNLOCK(invp); > > > > > lastblock =3D false; > > > > > - if (error =3D=3D 0 && aresid > 0) { > > > > > + if (error =3D=3D 0 && (xfer =3D=3D 0 || a= resid > 0)) { > > > > > /* Stop the copy at EOF on the in= put file. */ > > > > > xfer -=3D aresid; > > > > > eof =3D true; > > > > > > > > > > > > > From POSIX: "Note that a read() of zero bytes does not modify the l= ast > > > > data access timestamp. A read() that requests more than zero bytes, > > > > but returns zero, is required to modify the last data access > > > > timestamp." > > > > > > > > While copy_file_range is not standardized, it ought to comport to > > > > POSIX as closely as possible. I think we should change it as you > > > > suggest. > > > Well, I'd like to maintain the syscall as "Linux compatible", which w= as > > > my original intent. (I consider Linux as the defacto standard for *ni= x* like > > > operating systems). > > > > > > I've been ignoring a recent request for support for non-regular files= for > > > this reason. (I eventually intend to patch the man page to clarify t= hat > > > it only works for regular files, which is what Linux does.) > > > > > > As such, the first step is to figure out if Linux updates atime when = a > > > copy_file_range() returns 0 bytes. I just did a test on Linux (kernel > > > version 6.3) > > > using a ext4 fs mounted "relatime" and doing a copy_file_range(2) on = it > > > (using a trivial file copy program suing copy_file_range(2)) did not = update > > > atime. (I did modify the file via "cat /dev/null > file" so that the = atime would > > > be updated for "relatime". A similar test using "cp" did update the a= time.) > > > > > > Also, the above changes the "generic" copy loop, but changes will > > > also be required (or at least tested) for ZFS when block cloning is > > > enabled and NFSv4.2. The NFSv4.2 RFC does not specify whether > > > or not a "Copy" operation that returns 0 bytes updates atime > > > (called TimeAccess in NFSv4.2). > > > Oh, and the NFS protocol (up to and including NFSv4.2) cannot > > > provide a POSIX compliant file system (the NFS client tries to make > > > it look close to POSIX compliant). As such, expecting a copy_file_ra= nge(2) > > > over NFSv4.2 to behave in a POSIX-like way may not make sense? > > > > > > Personally, I'd rather see copy_file_range(2) remain Linux compatible= . > > > Does cat(1) really need to exhibit this behaviour or is it just read(= 2) > > > that specifies this? > > > > > > rick