From nobody Wed Oct 04 23:39:22 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 4S1B472QSqz4wgNl for ; Wed, 4 Oct 2023 23:39:35 +0000 (UTC) (envelope-from rick.macklem@gmail.com) Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (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 4S1B464Hd9z4gt6; Wed, 4 Oct 2023 23:39:34 +0000 (UTC) (envelope-from rick.macklem@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20230601 header.b="k/NbmUl4"; spf=pass (mx1.freebsd.org: domain of rick.macklem@gmail.com designates 2607:f8b0:4864:20::1030 as permitted sender) smtp.mailfrom=rick.macklem@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-27751ac0653so258406a91.3; Wed, 04 Oct 2023 16:39:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696462773; x=1697067573; darn=freebsd.org; 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=axqlC1rm/jRffZiQDVToWtEwBKHMxXRjJgaDlbyY5YQ=; b=k/NbmUl4IsY97Ku+OgaHPd0u4Hb6AME2LEh71YW1EX1eCQcwnXbY4ZqLvm3XIq+6Bc dobcVkUCN6zBChW9gkY3MTJfr7of5/HbtjiMuCPs4fW/Ug9mfYQCaO6XuNDrssC98xPu wqF2WfjWkj+Ss22G5KxWNqF+bNmnJJpCRmmjLNjEtvkbdAUBH1sRy7Tq8n6Hirp+PZMg hwiEAkJGBGO03GoWLjsCC2Q9VgtkSkRxWxBR3Jid+A0pMTZZBeDyTOMQOyDlR6i9NGFF B466SPlwq+8vhrFWnwBS/a6F7yOIrueUAbsfX2bRyNpV4khXCFDfBWD7Pti72beGCIWH E/wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696462773; x=1697067573; 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=axqlC1rm/jRffZiQDVToWtEwBKHMxXRjJgaDlbyY5YQ=; b=snIdNnOrmAO26jALs5vsMTfNaQ02LVxCbTFC0KkZmKRqJk65I53ig4J+Kr8+a+0KGI 7smJdUI/mvqZfQdJ9wbsddXBHp/2ThkzcFuQAvDpqAcL6wjbyH0UDVBtoWooa5pdMQGR bEhrNOwmZt96HBd4S/qy/iuVCs5fPWqTY07m0fRo/oqaiUb010SwS0eJhSgU9Xcpz3x7 UsZ/D6aOKhqEUyaRzQfyLmDT2SRZT+6lCHDMu+mMRD/qh0vex4Xe468hsfyZcORSZO5k v+kXdDs6iuYlOUjBPimQXYJ0fyofyjXypojkOk8wlxglapGxj8lxYTXP5mwo0CZj9+b6 SZXA== X-Gm-Message-State: AOJu0YwrB2U/Z/LutWiuOIaDxrBk7w1yNxbFNPGhSIYDRwvFOc41EE9u 1Q9OLP3ATYQ+S4861Qub7IEzaNVghDWsWeAHhn4HU3g= X-Google-Smtp-Source: AGHT+IEAWpWHYeUmQamqUCChYETzxv329Xce7r1RRng6D6biDoNZUmNtqE80YPSaljHmbRobjvl6+qU5pFL1jqhnqQU= X-Received: by 2002:a17:90b:180d:b0:26b:6095:bc3f with SMTP id lw13-20020a17090b180d00b0026b6095bc3fmr3399311pjb.33.1696462773359; Wed, 04 Oct 2023 16:39:33 -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: Rick Macklem Date: Wed, 4 Oct 2023 16:39:22 -0700 Message-ID: Subject: Re: copy_file_range() doesn't update the atime of an empty file To: Alan Somers 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 [-3.96 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.96)[-0.956]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20230601]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; MIME_GOOD(-0.10)[text/plain]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::1030:from]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ONE(0.00)[1]; FROM_EQ_ENVFROM(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROMTLD(0.00)[]; TAGGED_FROM(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; FROM_HAS_DN(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_TLS_LAST(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim] X-Rspamd-Queue-Id: 4S1B464Hd9z4gt6 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 Guelph= . Do not click links or open attachments unless you recognize the sender an= d know the content is safe. If in doubt, forward suspicious emails to IThel= p@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 tests= is > > > failing: > > > https://ci.freebsd.org/job/FreeBSD-main-amd64-test/23814/testReport/j= unit/sys.fs.tmpfs/times_test/empty/ > > > > > > This has been happening since commit > > > 8113cc827611a88540736c92ced7d3a7020a1723, which converted cat(1) to u= se > > > copy_file_range(2). The test in question creates an empty file, wait= s > > > for a second, then cat(1)s it and checks that the file's atime was > > > updated. After the aforementioned commit, the atime is not updated. > > > > > > I believe the essential difference is that a zero-length read(2) resu= lts > > > in a call to VOP_READ(), which results in an updated atime even if 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_WRIT= E > > > 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 *invp, = off_t *inoffp, > > > xfer -=3D (*inoffp % blksize); > > > } > > > /* Loop copying the data block. */ > > > - while (copylen > 0 && error =3D=3D 0 && !eof && inter= rupted =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 *invp, = 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 || aresi= d > 0)) { > > > /* Stop the copy at EOF on the input = file. */ > > > xfer -=3D aresid; > > > eof =3D true; > > > > > > > From POSIX: "Note that a read() of zero bytes does not modify the last > > 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 was > my original intent. (I consider Linux as the defacto standard for *nix* l= ike > 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 that > 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 upda= te > atime. (I did modify the file via "cat /dev/null > file" so that the atim= e would > be updated for "relatime". A similar test using "cp" did update the atime= .) > > 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_range(= 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