From nobody Mon Oct 17 13:11:06 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 4MrcnR19zNz4fwQ9; Mon, 17 Oct 2022 13:11:07 +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 4MrcnR0b8Jz4144; Mon, 17 Oct 2022 13:11:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666012267; 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=Q+z7t1kOOPsKI4qWaI42yNcrvvR2eTqUNYz/h+5s/bI=; b=B/IPS/O/vjrUAkAbl8bATavWlKXBRRKMlUrf/8UfZp1f75C62XQLXXkDy9nskC1Go0dfc2 DFhabwr1Ax6gcH/skrZW4cNWGgrKdtOLoc2BiWkxSB/nIbGSqANVvzFj8HAIKSUU9vP+lh FK6j4EM0Y+7eZZEOTEl7P1UUO0hPqA3eh7886FRSG9k/gRketat2MMBv28UPEC3X3Mb17Q xrhJzby+wuXW558dOG7V53IAwX/uUGgtYcnB86EptzQKK2WK5DaHocO+V5SflM5r1riTVb 9PHRqK0q8sGiiBvS/9tVDV+8iLA6nRS95+DhfV0jQu6tkjcDet1Xg8sBp2nN7A== 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 4MrcnQ6m3Rzr0L; Mon, 17 Oct 2022 13:11:06 +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 29HDB6PF029213; Mon, 17 Oct 2022 13:11:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29HDB6Hr029212; Mon, 17 Oct 2022 13:11:06 GMT (envelope-from git) Date: Mon, 17 Oct 2022 13:11:06 GMT Message-Id: <202210171311.29HDB6Hr029212@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: 3c3b906b5423 - main - fusefs: After successful F_GETLK, l_whence should be SEEK_SET 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: 3c3b906b54236841d813fd9a01b1e090f39558ea Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666012267; 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=Q+z7t1kOOPsKI4qWaI42yNcrvvR2eTqUNYz/h+5s/bI=; b=HxNoxaG0GBSVEY3GMc9CIB4Ph8f67vndvajg6L5/gyveTsDjQpUwVaOzZAbghBYgA1H5/4 udvoctdVvf8GsX0iJVy7o/NAgi4c8r1W54B/Qu5xhL5AN7WqAjkVfieb5HqDJgCo/tSjIa 0KL62V6ja7JaqCOVpdBj7OBUhpFQmCcGo2CeK5YXcAsR8Ou3P+nM/9BIaCfaLnKMSWRwkd yGFmZpHAz8rkcR/Z2AuwLTifaYsFhZRetoOtZEKSIr4Q/phIWPhPR4GdfawPhqEQqI+Hja iOe74nTGaVCsenuPr7+0buHLWpOk/lDVXLLUTJejOW1jyLynSVR468QE3TJ/0Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666012267; a=rsa-sha256; cv=none; b=TXGH8gkRu39q3hgRgtT5+fw2+XWgFAYO/dkxmmZ846Wc4V4ABHqBgh6H5oaERFd21d3+cy bFtsNHVEpC1UPTz1B2gvF6NOh25YphjYoIkKjb6uv0LWuyJCLkGtpQkMczo1Ao4onA9buN guw0wuQzc4gA1xGsMHjMzrKmTi1LjOZv7/jv5rHFmTJ0+sekyD75pao5MPOG+k/iVykkxU 3FV7W9mgWL+3vLePx/msbj349lfy1xdCWqN4apXz7yBwFzD34cVdPtkNGQLQ92XQGVYXKr SoxxfyQTCWDw1q3jegPdXjkdDD1kWun1kbVQ1qSr1TtBBudj0Kv3lnRBaj9hSw== 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=3c3b906b54236841d813fd9a01b1e090f39558ea commit 3c3b906b54236841d813fd9a01b1e090f39558ea Author: Alan Somers AuthorDate: 2022-10-11 23:00:07 +0000 Commit: Alan Somers CommitDate: 2022-10-17 13:09:50 +0000 fusefs: After successful F_GETLK, l_whence should be SEEK_SET PR: 266886 Reported by: John Millikin MFC after: 2 weeks Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D37014 --- sys/fs/fuse/fuse_vnops.c | 1 + tests/sys/fs/fusefs/locks.cc | 69 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/sys/fs/fuse/fuse_vnops.c b/sys/fs/fuse/fuse_vnops.c index 30d0e557feb5..5ad4f6bebd08 100644 --- a/sys/fs/fuse/fuse_vnops.c +++ b/sys/fs/fuse/fuse_vnops.c @@ -537,6 +537,7 @@ fuse_vnop_advlock(struct vop_advlock_args *ap) if (err == 0 && op == FUSE_GETLK) { flo = fdi.answ; fl->l_type = flo->lk.type; + fl->l_whence = SEEK_SET; if (flo->lk.type != F_UNLCK) { fl->l_pid = flo->lk.pid; fl->l_start = flo->lk.start; diff --git a/tests/sys/fs/fusefs/locks.cc b/tests/sys/fs/fusefs/locks.cc index aeb24704624b..f637c65cff24 100644 --- a/tests/sys/fs/fusefs/locks.cc +++ b/tests/sys/fs/fusefs/locks.cc @@ -47,9 +47,9 @@ using namespace testing; class Fallback: public FuseTest { public: -void expect_lookup(const char *relpath, uint64_t ino) +void expect_lookup(const char *relpath, uint64_t ino, uint64_t size = 0) { - FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, 0, 1); + FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, size, 1); } }; @@ -355,6 +355,71 @@ TEST_F(Getlk, lock_exists) leak(fd); } +/* + * F_GETLK with SEEK_CUR + */ +TEST_F(Getlk, seek_cur) +{ + const char FULLPATH[] = "mountpoint/some_file.txt"; + const char RELPATH[] = "some_file.txt"; + uint64_t ino = 42; + struct flock fl; + int fd; + pid_t pid = getpid(); + + expect_lookup(RELPATH, ino, 1024); + expect_open(ino, 0, 1); + EXPECT_CALL(*m_mock, process( + ResultOf([=](auto in) { + 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 == 500 && + in.body.getlk.lk.end == 509 && + in.body.getlk.lk.type == F_RDLCK); + }, Eq(true)), + _) + ).WillOnce(Invoke(ReturnImmediate([=](auto in __unused, auto& out) { + SET_OUT_HEADER_LEN(out, getlk); + out.body.getlk.lk.start = 400; + out.body.getlk.lk.end = 499; + out.body.getlk.lk.type = F_WRLCK; + out.body.getlk.lk.pid = (uint32_t)pid + 1; + }))); + + fd = open(FULLPATH, O_RDWR); + ASSERT_LE(0, fd) << strerror(errno); + ASSERT_NE(-1, lseek(fd, 500, SEEK_SET)); + + fl.l_start = 0; + fl.l_len = 10; + fl.l_pid = 42; + fl.l_type = F_RDLCK; + fl.l_whence = SEEK_CUR; + fl.l_sysid = 0; + ASSERT_NE(-1, fcntl(fd, F_GETLK, &fl)) << strerror(errno); + + /* + * After a successful F_GETLK request, the value of l_whence is + * SEEK_SET. + */ + EXPECT_EQ(F_WRLCK, fl.l_type); + EXPECT_EQ(fl.l_pid, pid + 1); + EXPECT_EQ(fl.l_start, 400); + EXPECT_EQ(fl.l_len, 100); + EXPECT_EQ(fl.l_whence, SEEK_SET); + ASSERT_EQ(fl.l_sysid, 0); + + leak(fd); +} + /* * If the fuse filesystem does not support posix file locks, then the kernel * should fall back to local locks.