From owner-dev-commits-src-branches@freebsd.org Tue Jul 27 17:57:05 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8CD8A666094; Tue, 27 Jul 2021 17:57:05 +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 4GZ4Hj3JnTz4rnr; Tue, 27 Jul 2021 17:57:05 +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 591B171B7; Tue, 27 Jul 2021 17:57:05 +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 16RHv5VM063976; Tue, 27 Jul 2021 17:57:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 16RHv5ET063975; Tue, 27 Jul 2021 17:57:05 GMT (envelope-from git) Date: Tue, 27 Jul 2021 17:57:05 GMT Message-Id: <202107271757.16RHv5ET063975@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: c7fe00ae403f - stable/13 - fusefs: correctly set lock owner during FUSE_SETLK 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: c7fe00ae403f08b17e8376cc98195171234bf3d9 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Jul 2021 17:57:05 -0000 The branch stable/13 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=c7fe00ae403f08b17e8376cc98195171234bf3d9 commit c7fe00ae403f08b17e8376cc98195171234bf3d9 Author: Alan Somers AuthorDate: 2021-05-20 01:10:15 +0000 Commit: Alan Somers CommitDate: 2021-07-27 17:44:28 +0000 fusefs: correctly set lock owner during FUSE_SETLK During FUSE_SETLK, the owner field should uniquely identify the calling process. The fusefs module now sets it to the process's pid. Previously, it expected the calling process to set it directly, which was wrong. libfuse also apparently expects the owner field to be set during FUSE_GETLK, though I'm not sure why. PR: 256005 Reported by: Agata Reviewed by: pfg Differential Revision: https://reviews.freebsd.org/D30622 (cherry picked from commit 18b19f8c6e04935a63a951afe0e540674bc94455) --- sys/fs/fuse/fuse_vnops.c | 4 ++-- tests/sys/fs/fusefs/locks.cc | 50 ++++++++++++++++++++++++++------------------ 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c index c79d8d5b5223..adb297b6aacb 100644 --- a/sys/fs/fuse/fuse_vnops.c +++ b/sys/fs/fuse/fuse_vnops.c @@ -466,14 +466,14 @@ fuse_vnop_advlock(struct vop_advlock_args *ap) fdisp_make_vp(&fdi, op, vp, td, cred); fli = fdi.indata; fli->fh = fufh->fh_id; - fli->owner = fl->l_pid; + fli->owner = td->td_proc->p_pid; fli->lk.start = fl->l_start; if (fl->l_len != 0) fli->lk.end = fl->l_start + fl->l_len - 1; else fli->lk.end = INT64_MAX; fli->lk.type = fl->l_type; - fli->lk.pid = fl->l_pid; + fli->lk.pid = td->td_proc->p_pid; err = fdisp_wait_answ(&fdi); fdisp_destroy(&fdi); diff --git a/tests/sys/fs/fusefs/locks.cc b/tests/sys/fs/fusefs/locks.cc index 49f495412259..cace779e981a 100644 --- a/tests/sys/fs/fusefs/locks.cc +++ b/tests/sys/fs/fusefs/locks.cc @@ -228,7 +228,7 @@ TEST_F(GetlkFallback, local) ASSERT_LE(0, fd) << strerror(errno); fl.l_start = 10; fl.l_len = 1000; - fl.l_pid = getpid(); + fl.l_pid = 0; fl.l_type = F_RDLCK; fl.l_whence = SEEK_SET; fl.l_sysid = 0; @@ -247,7 +247,7 @@ TEST_F(Getlk, no_locks) uint64_t ino = 42; struct flock fl; int fd; - pid_t pid = 1234; + pid_t pid = getpid(); expect_lookup(RELPATH, ino); expect_open(ino, 0, 1); @@ -256,11 +256,16 @@ TEST_F(Getlk, no_locks) return (in.header.opcode == FUSE_GETLK && in.header.nodeid == ino && in.body.getlk.fh == FH && + /* + * Though it seems useless, libfuse expects the + * owner and pid fields to be set during + * FUSE_GETLK. + */ in.body.getlk.owner == (uint32_t)pid && + in.body.getlk.lk.pid == (uint64_t)pid && in.body.getlk.lk.start == 10 && in.body.getlk.lk.end == 1009 && - in.body.getlk.lk.type == F_RDLCK && - in.body.getlk.lk.pid == (uint64_t)pid); + in.body.getlk.lk.type == F_RDLCK); }, Eq(true)), _) ).WillOnce(Invoke(ReturnImmediate([=](auto in, auto& out) { @@ -273,7 +278,7 @@ TEST_F(Getlk, no_locks) ASSERT_LE(0, fd) << strerror(errno); fl.l_start = 10; fl.l_len = 1000; - fl.l_pid = pid; + fl.l_pid = 0; fl.l_type = F_RDLCK; fl.l_whence = SEEK_SET; fl.l_sysid = 0; @@ -290,7 +295,7 @@ TEST_F(Getlk, lock_exists) uint64_t ino = 42; struct flock fl; int fd; - pid_t pid = 1234; + pid_t pid = getpid(); pid_t pid2 = 1235; expect_lookup(RELPATH, ino); @@ -300,11 +305,16 @@ TEST_F(Getlk, lock_exists) return (in.header.opcode == FUSE_GETLK && in.header.nodeid == ino && in.body.getlk.fh == FH && + /* + * Though it seems useless, libfuse expects the + * owner and pid fields to be set during + * FUSE_GETLK. + */ in.body.getlk.owner == (uint32_t)pid && + in.body.getlk.lk.pid == (uint64_t)pid && in.body.getlk.lk.start == 10 && in.body.getlk.lk.end == 1009 && - in.body.getlk.lk.type == F_RDLCK && - in.body.getlk.lk.pid == (uint64_t)pid); + in.body.getlk.lk.type == F_RDLCK); }, Eq(true)), _) ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { @@ -319,7 +329,7 @@ TEST_F(Getlk, lock_exists) ASSERT_LE(0, fd) << strerror(errno); fl.l_start = 10; fl.l_len = 1000; - fl.l_pid = pid; + fl.l_pid = 0; fl.l_type = F_RDLCK; fl.l_whence = SEEK_SET; fl.l_sysid = 0; @@ -368,7 +378,7 @@ TEST_F(Setlk, clear) uint64_t ino = 42; struct flock fl; int fd; - pid_t pid = 1234; + pid_t pid = getpid(); expect_lookup(RELPATH, ino); expect_open(ino, 0, 1); @@ -378,7 +388,7 @@ TEST_F(Setlk, clear) ASSERT_LE(0, fd) << strerror(errno); fl.l_start = 10; fl.l_len = 1000; - fl.l_pid = pid; + fl.l_pid = 0; fl.l_type = F_UNLCK; fl.l_whence = SEEK_SET; fl.l_sysid = 0; @@ -394,7 +404,7 @@ TEST_F(Setlk, set) uint64_t ino = 42; struct flock fl; int fd; - pid_t pid = 1234; + pid_t pid = getpid(); expect_lookup(RELPATH, ino); expect_open(ino, 0, 1); @@ -404,7 +414,7 @@ TEST_F(Setlk, set) ASSERT_LE(0, fd) << strerror(errno); fl.l_start = 10; fl.l_len = 1000; - fl.l_pid = pid; + fl.l_pid = 0; fl.l_type = F_RDLCK; fl.l_whence = SEEK_SET; fl.l_sysid = 0; @@ -420,7 +430,7 @@ TEST_F(Setlk, set_eof) uint64_t ino = 42; struct flock fl; int fd; - pid_t pid = 1234; + pid_t pid = getpid(); expect_lookup(RELPATH, ino); expect_open(ino, 0, 1); @@ -430,7 +440,7 @@ TEST_F(Setlk, set_eof) ASSERT_LE(0, fd) << strerror(errno); fl.l_start = 10; fl.l_len = 0; - fl.l_pid = pid; + fl.l_pid = 0; fl.l_type = F_RDLCK; fl.l_whence = SEEK_SET; fl.l_sysid = 0; @@ -446,7 +456,7 @@ TEST_F(Setlk, eagain) uint64_t ino = 42; struct flock fl; int fd; - pid_t pid = 1234; + pid_t pid = getpid(); expect_lookup(RELPATH, ino); expect_open(ino, 0, 1); @@ -456,7 +466,7 @@ TEST_F(Setlk, eagain) ASSERT_LE(0, fd) << strerror(errno); fl.l_start = 10; fl.l_len = 1000; - fl.l_pid = pid; + fl.l_pid = 0; fl.l_type = F_RDLCK; fl.l_whence = SEEK_SET; fl.l_sysid = 0; @@ -484,7 +494,7 @@ TEST_F(SetlkwFallback, local) ASSERT_LE(0, fd) << strerror(errno); fl.l_start = 10; fl.l_len = 1000; - fl.l_pid = getpid(); + fl.l_pid = 0; fl.l_type = F_RDLCK; fl.l_whence = SEEK_SET; fl.l_sysid = 0; @@ -504,7 +514,7 @@ TEST_F(Setlkw, set) uint64_t ino = 42; struct flock fl; int fd; - pid_t pid = 1234; + pid_t pid = getpid(); expect_lookup(RELPATH, ino); expect_open(ino, 0, 1); @@ -514,7 +524,7 @@ TEST_F(Setlkw, set) ASSERT_LE(0, fd) << strerror(errno); fl.l_start = 10; fl.l_len = 1000; - fl.l_pid = pid; + fl.l_pid = 0; fl.l_type = F_RDLCK; fl.l_whence = SEEK_SET; fl.l_sysid = 0;