From nobody Tue Jan 18 01:06:27 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 30B361952238; Tue, 18 Jan 2022 01:06:28 +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 4Jd9Zr0qpbz3sdW; Tue, 18 Jan 2022 01:06:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642467988; 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=LXnUAjaIur//1JLSpFCDORhGwjjhqkh8Rlpdpy3C8c0=; b=V4ljeAIsvOP8yWTXEiSgwt5uyxQOPiE4adBEnL5K4xTQwxtoivEPm6j5fgS7+UkSy0YXPv NrbWIZ5w0ZU4/5AedpR8COZ4YXg/FP/AXiEhTJPgWPC9f7M+Es9VxHAAF4+f9zPKgAuQz1 2Nm0pK2IdgRqigDxQC/gzuxTAGL+yeTplfJU0/2C4/EpRp0bHCB73eZlooOU98hWuvrnEX ci0SFhARgJtzPclyzx3Yt7tjIIUb96xwkUbvVgIPpYOZ5wEsHW+x5bEKyTbgH79UbSKz7G EgAZKwe/IZb7wwi7tRNig/NM4ZIrX2mXMduUo92/rgmJiwiXHs0kB4ns0q2Z+w== 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 EBF991838B; Tue, 18 Jan 2022 01:06:27 +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 20I16RHD015121; Tue, 18 Jan 2022 01:06:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20I16RqM015120; Tue, 18 Jan 2022 01:06:27 GMT (envelope-from git) Date: Tue, 18 Jan 2022 01:06:27 GMT Message-Id: <202201180106.20I16RqM015120@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: 449d02a12e50 - stable/13 - 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 449d02a12e503e228ca24fcab747ee003b8c31ce Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642467988; 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=LXnUAjaIur//1JLSpFCDORhGwjjhqkh8Rlpdpy3C8c0=; b=uwhqAAUG0c87Y5N+nc2SYPvau2RCJJQeFbP6t8XDPSp/PeTAS8izbttcHbICqIriO/Kg1u 4xX4kc2LcdFPeb8UdpcuAvHgmW47r2yC5SV2n/qUj+Q0EAFYMpj4rCs0QviQKQJ8bL6eKZ nVIOvMhTrrLU8ICp1paAlvwSn35QAlbLLEBuV/sSeibYYVwyox2x4CL8U7Ip6tbnq53Lu6 ZP6Jpc7ntCZnih5F1hItyQKVAW5jvwBsiBqstFpMztTWdGrdiMfHI0R5BHoVYt9zFPP7wO 9Q3WEwncmWnkTjbduwF182adQCZGO5wViAKtuuLMl9Qu3I8ydheudHW+w8w0Gg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642467988; a=rsa-sha256; cv=none; b=GunNJLle7SCA4Kpo2SPTGdN9q2lYjOLOFJ0+c7tkltDR6cG7heBrbd7/Q4+5BNJ5u46pTy w296daUEFZvFPB6WmYyzTYC/Swb/fw/QT6thB9G7xc2PPMvHkK5mCR08BtJbsA05zSqNTQ XRongibmCX1NX952F08pklV5VTxvfH2KCpNU2McXo6vLqbK5Mn2scu2Jg6Ugjqj0Z+7Cs+ zozrJPrQidOaHEiuHm3ey4gwuVZSehAHlJa9xwpI8edpcOmiUehGVRggFF5z7tRExmSgv1 +40jh500VchDiQVdlRKJufwALXZyhDZy8k4cP5tijPw48mkC6sJ7pVSwCemPGw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=449d02a12e503e228ca24fcab747ee003b8c31ce commit 449d02a12e503e228ca24fcab747ee003b8c31ce Author: Alan Somers AuthorDate: 2021-11-29 02:50:56 +0000 Commit: Alan Somers CommitDate: 2022-01-18 01:02:55 +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. Reviewers: pfg Differential Revision: https://reviews.freebsd.org/D33159 (cherry picked from commit 5169832c96451e0c939338d8ef34cd0875a24b83) --- 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 1655c3200eed..5cef2a7ea62a 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); +}