From nobody Wed Oct 04 15:31:29 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 4S0zF30x2rz4w6wj for ; Wed, 4 Oct 2023 15:31:35 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) (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 4S0zF164Kgz4SxW; Wed, 4 Oct 2023 15:31:33 +0000 (UTC) (envelope-from markjdb@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20230601 header.b=CxL6xYEJ; spf=pass (mx1.freebsd.org: domain of markjdb@gmail.com designates 2607:f8b0:4864:20::731 as permitted sender) smtp.mailfrom=markjdb@gmail.com; dmarc=none Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-7740aa4b545so155117085a.3; Wed, 04 Oct 2023 08:31:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696433492; x=1697038292; darn=freebsd.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :sender:from:to:cc:subject:date:message-id:reply-to; bh=ilFC+wInCSyKZnRw9bTBnfl9CBODfXIXag5z9xWZN8k=; b=CxL6xYEJ/N2Xh3inWbQTjYB7m98CqokTA0quCQuM3ziUz3vHAOAT89ja8m62dfXsTs 6yhFTI4qI6dTUbvzfMKf4gBy/+5hM1EscpM+qhoSUNgGimQZIXFBdN8I9lG3/mrDlfhK +kViTi7hEuXhaFJ9zruxth5ioIu8+SXcVWGebKbeTHx/M/dP7oasEzGikDew8LLaQC4M TqC8ssJKT4s9pjY7/GvmLCFpqVhfQmPUPomFpdS4K7fgOIru3V3mwAK+LPzmk02LmEq4 wh6DlPvMyOSccK0l7KC+WOBP+ih2WuSbimA8sModAIMC+impU8SY1VG/B3EGS3vPMMUR Dwjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696433492; x=1697038292; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ilFC+wInCSyKZnRw9bTBnfl9CBODfXIXag5z9xWZN8k=; b=neYGrhWo89thnGZ9ag82ab96sGXRKGZHjeSvfoUbdtDyFZ0HvcgNpJ4xi3nkxel1i4 21qaV2BePbbHHEBCKn7mpzwsROZiHTN4LJdVxLr9yUYmPUByQGj1EnTtfRDmulqU0L5J ryUfNar6wF6x2pZf/GQ7RcE4hGwA2YMTObcbKWhzdh+8yrVaTPqewv8UlxVWa6yZjP1J 3WlUBjsIWXIYC4mTD2Dw4hxrDqCFJazSMpX3qnRYPoORGNDn+HTPEmCsEwzE0hK+n5UE zp48A/3l/zPcEYdi5J76kpRN25z5i/EQ2zf90YM2pDDhuWX606WM+v73B8U0nYhbJFg3 0yVA== X-Gm-Message-State: AOJu0YzuLuFaw4stqh1J1BOqmRwJQPvm6mdqweoCjv7w6DjH6DbKW/k8 YtjKBeWwfGJfLrAa+PscujhPX2P0SEs= X-Google-Smtp-Source: AGHT+IGvjnsmMbf9uwKDZmDjg1FdPfWgLGdwVxQrVWjKmr97MmvBRmpXz6zBzNT0AKSg2V4+VOXf9w== X-Received: by 2002:a05:620a:3909:b0:76f:2c0f:9ddb with SMTP id qr9-20020a05620a390900b0076f2c0f9ddbmr3154931qkn.8.1696433491906; Wed, 04 Oct 2023 08:31:31 -0700 (PDT) Received: from nuc (192-0-220-237.cpe.teksavvy.com. [192.0.220.237]) by smtp.gmail.com with ESMTPSA id g4-20020ae9e104000000b007743360b3fasm1345621qkm.34.2023.10.04.08.31.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 08:31:31 -0700 (PDT) Date: Wed, 4 Oct 2023 11:31:29 -0400 From: Mark Johnston To: freebsd-hackers@freebsd.org Cc: rmacklem@freebsd.org Subject: copy_file_range() doesn't update the atime of an empty file Message-ID: 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spamd-Bar: -- X-Spamd-Result: default: False [-2.70 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-1.000]; MID_RHS_NOT_FQDN(0.50)[]; FORGED_SENDER(0.30)[markj@freebsd.org,markjdb@gmail.com]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36:c]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20230601]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; DMARC_NA(0.00)[freebsd.org]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::731:from]; BLOCKLISTDE_FAIL(0.00)[192.0.220.237:server fail,2607:f8b0:4864:20::731:server fail]; MLMMJ_DEST(0.00)[freebsd-hackers@freebsd.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim]; FROM_NEQ_ENVFROM(0.00)[markj@freebsd.org,markjdb@gmail.com]; RCPT_COUNT_TWO(0.00)[2]; DKIM_TRACE(0.00)[gmail.com:+]; TO_DN_NONE(0.00)[]; ARC_NA(0.00)[]; RCVD_TLS_LAST(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Queue-Id: 4S0zF164Kgz4SxW 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/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 was updated. After the aforementioned commit, the atime is not updated. 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 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_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 *invp, off_t *inoffp, xfer -= (*inoffp % blksize); } /* Loop copying the data block. */ - while (copylen > 0 && error == 0 && !eof && interrupted == 0) { + while (error == 0 && !eof && interrupted == 0) { if (copylen < xfer) xfer = copylen; error = 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 = false; - if (error == 0 && aresid > 0) { + if (error == 0 && (xfer == 0 || aresid > 0)) { /* Stop the copy at EOF on the input file. */ xfer -= aresid; eof = true;