From nobody Sat Jan 01 00:59:34 2022 X-Original-To: dev-commits-src-all@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 780241922DA1; Sat, 1 Jan 2022 00:59:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JQkDl19m3z3JyS; Sat, 1 Jan 2022 00:59:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 046C015A6B; Sat, 1 Jan 2022 00:59:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2010xYlH081315; Sat, 1 Jan 2022 00:59:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2010xYAN081314; Sat, 1 Jan 2022 00:59:34 GMT (envelope-from git) Date: Sat, 1 Jan 2022 00:59:34 GMT Message-Id: <202201010059.2010xYAN081314@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: 5169832c9645 - main - fusefs: copy_file_range must update file timestamps List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 5169832c96451e0c939338d8ef34cd0875a24b83 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1640998775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4rqhzapScOQ3zGtpDZQmXIFlp/ChOp8Ufohu5ATlOeg=; b=Nk80b4TJ1zkOMJsL+8nGC57dshcMyGbONYptcODm3v4y86WehVbDfzhnWSJvb+Czg4iZC7 nz4XQX2Rw1u4NhP3QDBZrvbBgdzgLCcAGmTao7DfiMhRry5KeJK1Kv5VaZB0eQzJ0EUCay ZTMBosWXNJlSjYxnvpq4/uMRqutQ7K3Ni8J/f0MUZQe46Y3PJawpRBy7Ar88veEmg1YBxl Z7O0RJL1agbpHBnJdpAtaIPDvu4z1HKEinoSkgBADg0RzzaukqxLEjmmbMeHlV/3hgdoAg GjjF4nYjlQ+BdBBr+eEJWeiX3XjEHgxHatVgYpUHfjfIX4glGbj9krRZbP5Cuw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1640998775; a=rsa-sha256; cv=none; b=QkAUrP7znKKED5pO4ucLNNR41bzEWs398RWcMtDQUp1FWQnFvYrdILxTcxjgwV7SJBTq9A n1SxDYrfP8fkO/pxAtv2ALYaN1/ovTzXcy96qxIMZWsax682dQk186DGN/HaGRdXZY05gk vYB8yyq7N/NI2ey81kIqnt28tTJgGTsfOTQIuIVWngsDuvalu+iy/9LxrmsqklxC3H9kT6 gh5BxJf5d9/psKT3xfVEJ1FlJfAh+4BbDC3kMrOZu4/kIdBSjJarkqmVoVP9gxtXQhekBW RjGLFWOfsjN0cKCHT7I8Vy/G3Qt361Dg+2XERHPxG1Bt8FPIPl6Wuh/cF9SbJQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=5169832c96451e0c939338d8ef34cd0875a24b83 commit 5169832c96451e0c939338d8ef34cd0875a24b83 Author: Alan Somers AuthorDate: 2021-11-29 02:50:56 +0000 Commit: Alan Somers CommitDate: 2022-01-01 00:43:57 +0000 fusefs: copy_file_range must update file timestamps If FUSE_COPY_FILE_RANGE returns successfully, update the atime of the source and the mtime and ctime of the destination. MFC after: 2 weeks Reviewers: pfg Differential Revision: https://reviews.freebsd.org/D33159 --- sys/fs/fuse/fuse_vnops.c | 2 + tests/sys/fs/fusefs/copy_file_range.cc | 142 +++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c index 5dc5ed8ed468..ada7dc1dcc81 100644 --- a/sys/fs/fuse/fuse_vnops.c +++ b/sys/fs/fuse/fuse_vnops.c @@ -807,6 +807,8 @@ fuse_vnop_copy_file_range(struct vop_copy_file_range_args *ap) fuse_vnode_setsize(outvp, *ap->a_outoffp, false); getnanouptime(&outfvdat->last_local_modify); } + fuse_vnode_update(invp, FN_ATIMECHANGE); + fuse_vnode_update(outvp, FN_MTIMECHANGE | FN_CTIMECHANGE); } fdisp_destroy(&fdi); diff --git a/tests/sys/fs/fusefs/copy_file_range.cc b/tests/sys/fs/fusefs/copy_file_range.cc index a9dc9679cb6a..974dc474f77b 100644 --- a/tests/sys/fs/fusefs/copy_file_range.cc +++ b/tests/sys/fs/fusefs/copy_file_range.cc @@ -129,6 +129,14 @@ virtual void SetUp() { } }; +class CopyFileRangeNoAtime: public CopyFileRange { +public: +virtual void SetUp() { + m_noatime = true; + CopyFileRange::SetUp(); +} +}; + TEST_F(CopyFileRange, eio) { const char FULLPATH1[] = "mountpoint/src.txt"; @@ -431,6 +439,74 @@ TEST_F(CopyFileRange, same_file) ASSERT_EQ(len, copy_file_range(fd, &off_in, fd, &off_out, len, 0)); } +/* + * copy_file_range should update the destination's mtime and ctime, and + * the source's atime. + */ +TEST_F(CopyFileRange, timestamps) +{ + const char FULLPATH1[] = "mountpoint/src.txt"; + const char RELPATH1[] = "src.txt"; + const char FULLPATH2[] = "mountpoint/dst.txt"; + const char RELPATH2[] = "dst.txt"; + struct stat sb1a, sb1b, sb2a, sb2b; + const uint64_t ino1 = 42; + const uint64_t ino2 = 43; + const uint64_t fh1 = 0xdeadbeef1a7ebabe; + const uint64_t fh2 = 0xdeadc0de88c0ffee; + off_t fsize1 = 1 << 20; /* 1 MiB */ + off_t fsize2 = 1 << 19; /* 512 KiB */ + off_t start1 = 1 << 18; + off_t start2 = 3 << 17; + ssize_t len = 65536; + int fd1, fd2; + + expect_lookup(RELPATH1, ino1, S_IFREG | 0644, fsize1, 1); + expect_lookup(RELPATH2, ino2, S_IFREG | 0644, fsize2, 1); + expect_open(ino1, 0, 1, fh1); + expect_open(ino2, 0, 1, fh2); + EXPECT_CALL(*m_mock, process( + ResultOf([=](auto in) { + return (in.header.opcode == FUSE_COPY_FILE_RANGE && + in.header.nodeid == ino1 && + in.body.copy_file_range.fh_in == fh1 && + (off_t)in.body.copy_file_range.off_in == start1 && + in.body.copy_file_range.nodeid_out == ino2 && + in.body.copy_file_range.fh_out == fh2 && + (off_t)in.body.copy_file_range.off_out == start2 && + in.body.copy_file_range.len == (size_t)len && + in.body.copy_file_range.flags == 0); + }, Eq(true)), + _) + ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { + SET_OUT_HEADER_LEN(out, write); + out.body.write.size = len; + }))); + + fd1 = open(FULLPATH1, O_RDONLY); + ASSERT_GE(fd1, 0); + fd2 = open(FULLPATH2, O_WRONLY); + ASSERT_GE(fd2, 0); + ASSERT_EQ(0, fstat(fd1, &sb1a)) << strerror(errno); + ASSERT_EQ(0, fstat(fd2, &sb2a)) << strerror(errno); + + nap(); + + ASSERT_EQ(len, copy_file_range(fd1, &start1, fd2, &start2, len, 0)); + ASSERT_EQ(0, fstat(fd1, &sb1b)) << strerror(errno); + ASSERT_EQ(0, fstat(fd2, &sb2b)) << strerror(errno); + + EXPECT_NE(sb1a.st_atime, sb1b.st_atime); + EXPECT_EQ(sb1a.st_mtime, sb1b.st_mtime); + EXPECT_EQ(sb1a.st_ctime, sb1b.st_ctime); + EXPECT_EQ(sb2a.st_atime, sb2b.st_atime); + EXPECT_NE(sb2a.st_mtime, sb2b.st_mtime); + EXPECT_NE(sb2a.st_ctime, sb2b.st_ctime); + + leak(fd1); + leak(fd2); +} + /* * copy_file_range can extend the size of a file * */ @@ -523,4 +599,70 @@ TEST_F(CopyFileRange_7_27, fallback) ASSERT_EQ(len, copy_file_range(fd1, &start1, fd2, &start2, len, 0)); } +/* + * With -o noatime, copy_file_range should update the destination's mtime and + * ctime, but not the source's atime. + */ +TEST_F(CopyFileRangeNoAtime, timestamps) +{ + const char FULLPATH1[] = "mountpoint/src.txt"; + const char RELPATH1[] = "src.txt"; + const char FULLPATH2[] = "mountpoint/dst.txt"; + const char RELPATH2[] = "dst.txt"; + struct stat sb1a, sb1b, sb2a, sb2b; + const uint64_t ino1 = 42; + const uint64_t ino2 = 43; + const uint64_t fh1 = 0xdeadbeef1a7ebabe; + const uint64_t fh2 = 0xdeadc0de88c0ffee; + off_t fsize1 = 1 << 20; /* 1 MiB */ + off_t fsize2 = 1 << 19; /* 512 KiB */ + off_t start1 = 1 << 18; + off_t start2 = 3 << 17; + ssize_t len = 65536; + int fd1, fd2; + expect_lookup(RELPATH1, ino1, S_IFREG | 0644, fsize1, 1); + expect_lookup(RELPATH2, ino2, S_IFREG | 0644, fsize2, 1); + expect_open(ino1, 0, 1, fh1); + expect_open(ino2, 0, 1, fh2); + EXPECT_CALL(*m_mock, process( + ResultOf([=](auto in) { + return (in.header.opcode == FUSE_COPY_FILE_RANGE && + in.header.nodeid == ino1 && + in.body.copy_file_range.fh_in == fh1 && + (off_t)in.body.copy_file_range.off_in == start1 && + in.body.copy_file_range.nodeid_out == ino2 && + in.body.copy_file_range.fh_out == fh2 && + (off_t)in.body.copy_file_range.off_out == start2 && + in.body.copy_file_range.len == (size_t)len && + in.body.copy_file_range.flags == 0); + }, Eq(true)), + _) + ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { + SET_OUT_HEADER_LEN(out, write); + out.body.write.size = len; + }))); + + fd1 = open(FULLPATH1, O_RDONLY); + ASSERT_GE(fd1, 0); + fd2 = open(FULLPATH2, O_WRONLY); + ASSERT_GE(fd2, 0); + ASSERT_EQ(0, fstat(fd1, &sb1a)) << strerror(errno); + ASSERT_EQ(0, fstat(fd2, &sb2a)) << strerror(errno); + + nap(); + + ASSERT_EQ(len, copy_file_range(fd1, &start1, fd2, &start2, len, 0)); + ASSERT_EQ(0, fstat(fd1, &sb1b)) << strerror(errno); + ASSERT_EQ(0, fstat(fd2, &sb2b)) << strerror(errno); + + EXPECT_EQ(sb1a.st_atime, sb1b.st_atime); + EXPECT_EQ(sb1a.st_mtime, sb1b.st_mtime); + EXPECT_EQ(sb1a.st_ctime, sb1b.st_ctime); + EXPECT_EQ(sb2a.st_atime, sb2b.st_atime); + EXPECT_NE(sb2a.st_mtime, sb2b.st_mtime); + EXPECT_NE(sb2a.st_ctime, sb2b.st_ctime); + + leak(fd1); + leak(fd2); +}