From nobody Tue Dec 14 22:11:56 2021 X-Original-To: dev-commits-src-branches@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 D788418EF3F8; Tue, 14 Dec 2021 22:11:56 +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 4JDCK84NSCz4TG8; Tue, 14 Dec 2021 22:11:56 +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 77294109A1; Tue, 14 Dec 2021 22:11:56 +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 1BEMBuci037411; Tue, 14 Dec 2021 22:11:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BEMBuce037410; Tue, 14 Dec 2021 22:11:56 GMT (envelope-from git) Date: Tue, 14 Dec 2021 22:11:56 GMT Message-Id: <202112142211.1BEMBuce037410@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: 000ce6dee1fa - stable/13 - fusefs: fix copy_file_range when extending a file List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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: 000ce6dee1fa387d526762f8bc1946d13823312e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639519916; 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=ciLTgNN6ju9hJH7Ix3NIWXXWp+MULuxpCHlLnJCvetU=; b=qZSa/ZodWjNRNJAgf4hDUh/RD88fQmJxL6QGQJWGuFegrosSWxNZ+7o1LxKeSDKPYdp2Cx MJ0gMFsC3cOfpbMTPHbBoPURI274d47/iu+E0ZilJoKqwSgRj3FH/C8HKGkvWNmTh++yct ppMUnsTkdP2Q1h+W/GNLqrEZI8hdI3y8LznkP3LicHYqGOFfIR3WIi8A5byMCi9nK+JbHy PAaRc5xAxuQlxdbbuXzcFhUCHp/NwVVOueP90Mx/cvn2Y1Tf/uk9qFMy+wUUdx/DDiCQjb 6WYV3PihXMWJO4Nbvo0nV3KE44p0Xph/YOyQ/4hl9kVaQMFtreKVcH2zTqIa6w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639519916; a=rsa-sha256; cv=none; b=KuyFh/dq8JY+OPrrNqvmK11VaZnJpbn8G3/r4lPYJPsO4rC58nKtfN4EC4OvSaA5X9S3Lm t4lIdlDyWqc8EmuzIb54AYLNSMqmORicw5BSPtyAIB8/y5wjvMXBAFpwgff6yZVp7ocmfE VQWk/mj7IzTJPkY9u0CS3NgAVw4FwfNZahjxZN+t7PyswdlXcQPKXDnR4aKH5C6TAXEnGW +rtkftGL68QstmuImyVtzE1Deyvknxk/U11zGT5jd7QT0Hk1JK3dBw4srIzX9yDPIXWVLc JpL8crGEvlT8daJwOMp99ql/v7+HpbcjK/TrPL0G8ekoTfrMvE5g9D3Kvc1ePg== 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=000ce6dee1fa387d526762f8bc1946d13823312e commit 000ce6dee1fa387d526762f8bc1946d13823312e Author: Alan Somers AuthorDate: 2021-11-29 01:35:58 +0000 Commit: Alan Somers CommitDate: 2021-12-14 21:49:56 +0000 fusefs: fix copy_file_range when extending a file When copy_file_range extends a file, it must update the cached file size. Reviewed by: rmacklem, pfg Differential Revision: https://reviews.freebsd.org/D33151 (cherry picked from commit 65d70b3bae0c70798b0a2b8ed129bc146fed1cce) --- sys/fs/fuse/fuse_vnops.c | 3 +++ tests/sys/fs/fusefs/copy_file_range.cc | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c index 22f1733dd10b..5630eeeb9e65 100644 --- a/sys/fs/fuse/fuse_vnops.c +++ b/sys/fs/fuse/fuse_vnops.c @@ -650,6 +650,7 @@ fuse_vnop_copy_file_range(struct vop_copy_file_range_args *ap) struct vnode *invp = ap->a_invp; struct vnode *outvp = ap->a_outvp; struct mount *mp = vnode_mount(invp); + struct fuse_vnode_data *outfvdat = VTOFUD(outvp); struct fuse_dispatcher fdi; struct fuse_filehandle *infufh, *outfufh; struct fuse_copy_file_range_in *fcfri; @@ -731,6 +732,8 @@ fuse_vnop_copy_file_range(struct vop_copy_file_range_args *ap) *ap->a_inoffp += fwo->size; *ap->a_outoffp += fwo->size; fuse_internal_clear_suid_on_write(outvp, outcred, td); + if (*ap->a_outoffp > outfvdat->cached_attrs.va_size) + fuse_vnode_setsize(outvp, *ap->a_outoffp, false); } fdisp_destroy(&fdi); diff --git a/tests/sys/fs/fusefs/copy_file_range.cc b/tests/sys/fs/fusefs/copy_file_range.cc index bb8eecf8b862..03a892d35d29 100644 --- a/tests/sys/fs/fusefs/copy_file_range.cc +++ b/tests/sys/fs/fusefs/copy_file_range.cc @@ -353,6 +353,53 @@ TEST_F(CopyFileRange, same_file) ASSERT_EQ(len, copy_file_range(fd, &off_in, fd, &off_out, len, 0)); } +/* + * copy_file_range can extend the size of a file + * */ +TEST_F(CopyFileRange, extend) +{ + const char FULLPATH[] = "mountpoint/src.txt"; + const char RELPATH[] = "src.txt"; + struct stat sb; + const uint64_t ino = 4; + const uint64_t fh = 0xdeadbeefa7ebabe; + off_t fsize = 65536; + off_t off_in = 0; + off_t off_out = 65536; + ssize_t len = 65536; + int fd; + + expect_lookup(RELPATH, ino, S_IFREG | 0644, fsize, 1); + expect_open(ino, 0, 1, fh); + EXPECT_CALL(*m_mock, process( + ResultOf([=](auto in) { + return (in.header.opcode == FUSE_COPY_FILE_RANGE && + in.header.nodeid == ino && + in.body.copy_file_range.fh_in == fh && + (off_t)in.body.copy_file_range.off_in == off_in && + in.body.copy_file_range.nodeid_out == ino && + in.body.copy_file_range.fh_out == fh && + (off_t)in.body.copy_file_range.off_out == off_out && + 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; + }))); + + fd = open(FULLPATH, O_RDWR); + ASSERT_GE(fd, 0); + ASSERT_EQ(len, copy_file_range(fd, &off_in, fd, &off_out, len, 0)); + + /* Check that cached attributes were updated appropriately */ + ASSERT_EQ(0, fstat(fd, &sb)) << strerror(errno); + EXPECT_EQ(fsize + len, sb.st_size); + + leak(fd); +} + /* With older protocol versions, no FUSE_COPY_FILE_RANGE should be attempted */ TEST_F(CopyFileRange_7_27, fallback) {