From owner-svn-src-projects@freebsd.org Wed Mar 13 22:16:02 2019 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 475071543556 for ; Wed, 13 Mar 2019 22:16:02 +0000 (UTC) (envelope-from asomers@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C7AFB72BB3; Wed, 13 Mar 2019 22:16:01 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B619A18DB7; Wed, 13 Mar 2019 22:16:01 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x2DMG1xK097995; Wed, 13 Mar 2019 22:16:01 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x2DMG0FF097989; Wed, 13 Mar 2019 22:16:00 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201903132216.x2DMG0FF097989@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Wed, 13 Mar 2019 22:16:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r345118 - projects/fuse2/tests/sys/fs/fuse X-SVN-Group: projects X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: projects/fuse2/tests/sys/fs/fuse X-SVN-Commit-Revision: 345118 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: C7AFB72BB3 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.997,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.960,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Mar 2019 22:16:02 -0000 Author: asomers Date: Wed Mar 13 22:16:00 2019 New Revision: 345118 URL: https://svnweb.freebsd.org/changeset/base/345118 Log: fuse(4): add tests for POSIX file locking operations PR: 234581 Sponsored by: The FreeBSD Foundation Added: projects/fuse2/tests/sys/fs/fuse/locks.cc (contents, props changed) Modified: projects/fuse2/tests/sys/fs/fuse/Makefile projects/fuse2/tests/sys/fs/fuse/mockfs.cc projects/fuse2/tests/sys/fs/fuse/mockfs.hh projects/fuse2/tests/sys/fs/fuse/utils.cc projects/fuse2/tests/sys/fs/fuse/utils.hh Modified: projects/fuse2/tests/sys/fs/fuse/Makefile ============================================================================== --- projects/fuse2/tests/sys/fs/fuse/Makefile Wed Mar 13 21:53:10 2019 (r345117) +++ projects/fuse2/tests/sys/fs/fuse/Makefile Wed Mar 13 22:16:00 2019 (r345118) @@ -11,6 +11,7 @@ ATF_TESTS_CXX+= fsync ATF_TESTS_CXX+= fsyncdir ATF_TESTS_CXX+= getattr ATF_TESTS_CXX+= link +ATF_TESTS_CXX+= locks ATF_TESTS_CXX+= lookup ATF_TESTS_CXX+= mkdir ATF_TESTS_CXX+= mknod @@ -63,6 +64,11 @@ SRCS.link+= getmntopts.c SRCS.link+= link.cc SRCS.link+= mockfs.cc SRCS.link+= utils.cc + +SRCS.locks+= locks.cc +SRCS.locks+= getmntopts.c +SRCS.locks+= mockfs.cc +SRCS.locks+= utils.cc SRCS.lookup+= getmntopts.c SRCS.lookup+= lookup.cc Added: projects/fuse2/tests/sys/fs/fuse/locks.cc ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/fuse2/tests/sys/fs/fuse/locks.cc Wed Mar 13 22:16:00 2019 (r345118) @@ -0,0 +1,475 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2019 The FreeBSD Foundation + * + * This software was developed by BFF Storage Systems, LLC under sponsorship + * from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +extern "C" { +#include +} + +#include "mockfs.hh" +#include "utils.hh" + +/* This flag value should probably be defined in fuse_kernel.h */ +#define OFFSET_MAX 0x7fffffffffffffffLL + +using namespace testing; + +/* For testing filesystems without posix locking support */ +class Fallback: public FuseTest { +public: +const static uint64_t FH = 0xdeadbeef1a7ebabe; + +void expect_getattr(uint64_t ino) +{ + /* Until the attr cache is working, we may send an additional GETATTR */ + EXPECT_CALL(*m_mock, process( + ResultOf([=](auto in) { + return (in->header.opcode == FUSE_GETATTR && + in->header.nodeid == ino); + }, Eq(true)), + _) + ).WillRepeatedly(Invoke([=](auto in, auto out) { + out->header.unique = in->header.unique; + SET_OUT_HEADER_LEN(out, attr); + out->body.attr.attr.ino = ino; // Must match nodeid + out->body.attr.attr.mode = S_IFREG | 0644; + out->body.attr.attr_valid = UINT64_MAX; + })); +} + +void expect_lookup(const char *relpath, uint64_t ino) +{ + EXPECT_LOOKUP(1, relpath).WillRepeatedly(Invoke([=](auto in, auto out) { + out->header.unique = in->header.unique; + SET_OUT_HEADER_LEN(out, entry); + out->body.entry.attr.mode = S_IFREG | 0644; + out->body.entry.nodeid = ino; + out->body.entry.attr_valid = UINT64_MAX; + })); +} + +void expect_open(uint64_t ino) +{ + EXPECT_CALL(*m_mock, process( + ResultOf([=](auto in) { + return (in->header.opcode == FUSE_OPEN && + in->header.nodeid == ino); + }, Eq(true)), + _) + ).WillOnce(Invoke([=](auto in, auto out) { + out->header.unique = in->header.unique; + out->header.len = sizeof(out->header); + SET_OUT_HEADER_LEN(out, open); + out->body.open.fh = FH; + })); +} + +}; + +/* For testing filesystems with posix locking support */ +class Locks: public Fallback { + virtual void SetUp() { + m_init_flags = FUSE_POSIX_LOCKS; + Fallback::SetUp(); + } +}; + +class GetlkFallback: public Fallback {}; +class Getlk: public Locks {}; +class SetlkFallback: public Fallback {}; +class Setlk: public Locks {}; +class SetlkwFallback: public Fallback {}; +class Setlkw: public Locks {}; + +/* + * If the fuse filesystem does not support posix file locks, then the kernel + * should fall back to local locks. + */ +TEST_F(GetlkFallback, local) +{ + const char FULLPATH[] = "mountpoint/some_file.txt"; + const char RELPATH[] = "some_file.txt"; + uint64_t ino = 42; + struct flock fl; + int fd; + + expect_lookup(RELPATH, ino); + expect_open(ino); + expect_getattr(ino); + + fd = open(FULLPATH, O_RDWR); + ASSERT_LE(0, fd) << strerror(errno); + fl.l_start = 10; + fl.l_len = 1000; + fl.l_pid = getpid(); + fl.l_type = F_RDLCK; + fl.l_whence = SEEK_SET; + fl.l_sysid = 0; + ASSERT_NE(-1, fcntl(fd, F_GETLK, &fl)) << strerror(errno); + /* Deliberately leak fd. close(2) will be tested in release.cc */ +} + +/* + * If the filesystem has no locks that fit the description, the filesystem + * should return F_UNLCK + */ +/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=234581 */ +TEST_F(Getlk, DISABLED_no_locks) +{ + 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 = 1234; + + expect_lookup(RELPATH, ino); + expect_open(ino); + expect_getattr(ino); + EXPECT_CALL(*m_mock, process( + ResultOf([=](auto in) { + return (in->header.opcode == FUSE_GETLK && + in->header.nodeid == ino && + in->body.getlk.fh == FH && + in->body.getlk.owner == (uint32_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 == 10); + }, Eq(true)), + _) + ).WillOnce(Invoke([=](auto in, auto out) { + out->header.unique = in->header.unique; + SET_OUT_HEADER_LEN(out, getlk); + out->body.getlk.lk = in->body.getlk.lk; + out->body.getlk.lk.type = F_UNLCK; + })); + + fd = open(FULLPATH, O_RDWR); + ASSERT_LE(0, fd) << strerror(errno); + fl.l_start = 10; + fl.l_len = 1000; + fl.l_pid = pid; + fl.l_type = F_RDLCK; + fl.l_whence = SEEK_SET; + fl.l_sysid = 0; + ASSERT_NE(-1, fcntl(fd, F_GETLK, &fl)) << strerror(errno); + ASSERT_EQ(F_UNLCK, fl.l_type); + /* Deliberately leak fd. close(2) will be tested in release.cc */ +} + +/* A different pid does have a lock */ +/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=234581 */ +TEST_F(Getlk, DISABLED_lock_exists) +{ + 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 = 1234; + pid_t pid2 = 1234; + + expect_lookup(RELPATH, ino); + expect_open(ino); + expect_getattr(ino); + EXPECT_CALL(*m_mock, process( + ResultOf([=](auto in) { + return (in->header.opcode == FUSE_GETLK && + in->header.nodeid == ino && + in->body.getlk.fh == FH && + in->body.getlk.owner == (uint32_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 == 10); + }, Eq(true)), + _) + ).WillOnce(Invoke([=](auto in, auto out) { + out->header.unique = in->header.unique; + SET_OUT_HEADER_LEN(out, getlk); + out->body.getlk.lk.start = 100; + out->body.getlk.lk.end = 199; + out->body.getlk.lk.type = F_WRLCK; + out->body.getlk.lk.pid = (uint32_t)pid2;; + })); + + fd = open(FULLPATH, O_RDWR); + ASSERT_LE(0, fd) << strerror(errno); + fl.l_start = 10; + fl.l_len = 1000; + fl.l_pid = pid; + fl.l_type = F_RDLCK; + fl.l_whence = SEEK_SET; + fl.l_sysid = 0; + ASSERT_NE(-1, fcntl(fd, F_GETLK, &fl)) << strerror(errno); + EXPECT_EQ(100, fl.l_start); + EXPECT_EQ(100, fl.l_len); + EXPECT_EQ(pid2, fl.l_pid); + EXPECT_EQ(F_WRLCK, fl.l_type); + EXPECT_EQ(SEEK_SET, fl.l_whence); + EXPECT_EQ(0, fl.l_sysid); + /* Deliberately leak fd. close(2) will be tested in release.cc */ +} + +/* + * If the fuse filesystem does not support posix file locks, then the kernel + * should fall back to local locks. + */ +TEST_F(SetlkFallback, local) +{ + const char FULLPATH[] = "mountpoint/some_file.txt"; + const char RELPATH[] = "some_file.txt"; + uint64_t ino = 42; + struct flock fl; + int fd; + + expect_lookup(RELPATH, ino); + expect_open(ino); + expect_getattr(ino); + + fd = open(FULLPATH, O_RDWR); + ASSERT_LE(0, fd) << strerror(errno); + fl.l_start = 10; + fl.l_len = 1000; + fl.l_pid = getpid(); + fl.l_type = F_RDLCK; + fl.l_whence = SEEK_SET; + fl.l_sysid = 0; + ASSERT_NE(-1, fcntl(fd, F_SETLK, &fl)) << strerror(errno); + /* Deliberately leak fd. close(2) will be tested in release.cc */ +} + +/* Set a new lock with FUSE_SETLK */ +/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=234581 */ +TEST_F(Setlk, DISABLED_set) +{ + 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 = 1234; + + expect_lookup(RELPATH, ino); + expect_open(ino); + expect_getattr(ino); + EXPECT_CALL(*m_mock, process( + ResultOf([=](auto in) { + return (in->header.opcode == FUSE_SETLK && + in->header.nodeid == ino && + in->body.getlk.fh == FH && + in->body.getlk.owner == (uint32_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 == 10); + }, Eq(true)), + _) + ).WillOnce(Invoke([=](auto in, auto out) { + out->header.unique = in->header.unique; + SET_OUT_HEADER_LEN(out, getlk); + out->body.getlk.lk = in->body.getlk.lk; + out->body.getlk.lk.type = F_UNLCK; + })); + + fd = open(FULLPATH, O_RDWR); + ASSERT_LE(0, fd) << strerror(errno); + fl.l_start = 10; + fl.l_len = 1000; + fl.l_pid = pid; + fl.l_type = F_RDLCK; + fl.l_whence = SEEK_SET; + fl.l_sysid = 0; + ASSERT_NE(-1, fcntl(fd, F_SETLK, &fl)) << strerror(errno); + /* Deliberately leak fd. close(2) will be tested in release.cc */ +} + +/* l_len = 0 is a flag value that means to lock until EOF */ +/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=234581 */ +TEST_F(Setlk, DISABLED_set_eof) +{ + 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 = 1234; + + expect_lookup(RELPATH, ino); + expect_open(ino); + expect_getattr(ino); + EXPECT_CALL(*m_mock, process( + ResultOf([=](auto in) { + return (in->header.opcode == FUSE_SETLK && + in->header.nodeid == ino && + in->body.getlk.fh == FH && + in->body.getlk.owner == (uint32_t)pid && + in->body.getlk.lk.start == 10 && + in->body.getlk.lk.end == OFFSET_MAX && + in->body.getlk.lk.type == F_RDLCK && + in->body.getlk.lk.pid == 10); + }, Eq(true)), + _) + ).WillOnce(Invoke([=](auto in, auto out) { + out->header.unique = in->header.unique; + SET_OUT_HEADER_LEN(out, getlk); + out->body.getlk.lk = in->body.getlk.lk; + out->body.getlk.lk.type = F_UNLCK; + })); + + fd = open(FULLPATH, O_RDWR); + ASSERT_LE(0, fd) << strerror(errno); + fl.l_start = 10; + fl.l_len = 0; + fl.l_pid = pid; + fl.l_type = F_RDLCK; + fl.l_whence = SEEK_SET; + fl.l_sysid = 0; + ASSERT_NE(-1, fcntl(fd, F_SETLK, &fl)) << strerror(errno); + /* Deliberately leak fd. close(2) will be tested in release.cc */ +} + +/* Fail to set a new lock with FUSE_SETLK due to a conflict */ +/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=234581 */ +TEST_F(Setlk, DISABLED_eagain) +{ + 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 = 1234; + + expect_lookup(RELPATH, ino); + expect_open(ino); + expect_getattr(ino); + EXPECT_CALL(*m_mock, process( + ResultOf([=](auto in) { + return (in->header.opcode == FUSE_SETLK && + in->header.nodeid == ino && + in->body.getlk.fh == FH && + in->body.getlk.owner == (uint32_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 == 10); + }, Eq(true)), + _) + ).WillOnce(Invoke(ReturnErrno(EAGAIN))); + + fd = open(FULLPATH, O_RDWR); + ASSERT_LE(0, fd) << strerror(errno); + fl.l_start = 10; + fl.l_len = 1000; + fl.l_pid = pid; + fl.l_type = F_RDLCK; + fl.l_whence = SEEK_SET; + fl.l_sysid = 0; + ASSERT_EQ(-1, fcntl(fd, F_SETLK, &fl)); + ASSERT_EQ(EAGAIN, errno); + /* Deliberately leak fd. close(2) will be tested in release.cc */ +} + +/* + * If the fuse filesystem does not support posix file locks, then the kernel + * should fall back to local locks. + */ +TEST_F(SetlkwFallback, local) +{ + const char FULLPATH[] = "mountpoint/some_file.txt"; + const char RELPATH[] = "some_file.txt"; + uint64_t ino = 42; + struct flock fl; + int fd; + + expect_lookup(RELPATH, ino); + expect_open(ino); + expect_getattr(ino); + + fd = open(FULLPATH, O_RDWR); + ASSERT_LE(0, fd) << strerror(errno); + fl.l_start = 10; + fl.l_len = 1000; + fl.l_pid = getpid(); + fl.l_type = F_RDLCK; + fl.l_whence = SEEK_SET; + fl.l_sysid = 0; + ASSERT_NE(-1, fcntl(fd, F_SETLKW, &fl)) << strerror(errno); + /* Deliberately leak fd. close(2) will be tested in release.cc */ +} + +/* + * Set a new lock with FUSE_SETLK. If the lock is not available, then the + * command should block. But to the kernel, that's the same as just being + * slow, so we don't need a separate test method + */ +/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=234581 */ +TEST_F(Setlkw, DISABLED_set) +{ + 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 = 1234; + + expect_lookup(RELPATH, ino); + expect_open(ino); + expect_getattr(ino); + EXPECT_CALL(*m_mock, process( + ResultOf([=](auto in) { + return (in->header.opcode == FUSE_SETLK && + in->header.nodeid == ino && + in->body.getlk.fh == FH && + in->body.getlk.owner == (uint32_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 == 10); + }, Eq(true)), + _) + ).WillOnce(Invoke([=](auto in, auto out) { + out->header.unique = in->header.unique; + SET_OUT_HEADER_LEN(out, getlk); + out->body.getlk.lk = in->body.getlk.lk; + out->body.getlk.lk.type = F_UNLCK; + })); + + fd = open(FULLPATH, O_RDWR); + ASSERT_LE(0, fd) << strerror(errno); + fl.l_start = 10; + fl.l_len = 1000; + fl.l_pid = pid; + fl.l_type = F_RDLCK; + fl.l_whence = SEEK_SET; + fl.l_sysid = 0; + ASSERT_NE(-1, fcntl(fd, F_SETLKW, &fl)) << strerror(errno); + /* Deliberately leak fd. close(2) will be tested in release.cc */ +} Modified: projects/fuse2/tests/sys/fs/fuse/mockfs.cc ============================================================================== --- projects/fuse2/tests/sys/fs/fuse/mockfs.cc Wed Mar 13 21:53:10 2019 (r345117) +++ projects/fuse2/tests/sys/fs/fuse/mockfs.cc Wed Mar 13 22:16:00 2019 (r345118) @@ -183,7 +183,7 @@ void debug_fuseop(const mockfs_buf_in *in) printf("\n"); } -MockFS::MockFS(int max_readahead) { +MockFS::MockFS(int max_readahead, uint32_t flags) { struct iovec *iov = NULL; int iovlen = 0; char fdstr[15]; @@ -225,7 +225,7 @@ MockFS::MockFS(int max_readahead) { ON_CALL(*this, process(_, _)) .WillByDefault(Invoke(this, &MockFS::process_default)); - init(); + init(flags); signal(SIGUSR1, sigint_handler); if (pthread_create(&m_daemon_id, NULL, service, (void*)this)) throw(std::system_error(errno, std::system_category(), @@ -238,7 +238,7 @@ MockFS::~MockFS() { rmdir("mountpoint"); } -void MockFS::init() { +void MockFS::init(uint32_t flags) { mockfs_buf_in *in; mockfs_buf_out *out; @@ -255,6 +255,7 @@ void MockFS::init() { out->header.error = 0; out->body.init.major = FUSE_KERNEL_VERSION; out->body.init.minor = FUSE_KERNEL_MINOR_VERSION; + out->body.init.flags = in->body.init.flags & flags; /* * The default max_write is set to this formula in libfuse, though @@ -311,6 +312,10 @@ void MockFS::loop() { } if (in->header.opcode == FUSE_FORGET) { /*Alone among the opcodes, FORGET expects no response*/ + continue; + } + if (out.header.error == FUSE_NORESPONSE) { + /* Used by tests of slow opcodes. No response ATM */ continue; } ASSERT_TRUE(write(m_fuse_fd, &out, out.header.len) > 0 || Modified: projects/fuse2/tests/sys/fs/fuse/mockfs.hh ============================================================================== --- projects/fuse2/tests/sys/fs/fuse/mockfs.hh Wed Mar 13 21:53:10 2019 (r345117) +++ projects/fuse2/tests/sys/fs/fuse/mockfs.hh Wed Mar 13 22:16:00 2019 (r345118) @@ -40,6 +40,12 @@ extern "C" { #define TIME_T_MAX (std::numeric_limits::max()) +/* + * A pseudo-fuse errno used indicate that a fuse operation should have no + * response, at least not immediately + */ +#define FUSE_NORESPONSE 9999 + #define SET_OUT_HEADER_LEN(out, variant) { \ (out)->header.len = (sizeof((out)->header) + \ sizeof((out)->body.variant)); \ @@ -78,6 +84,8 @@ union fuse_payloads_in { fuse_fsync_in fsync; fuse_fsync_in fsyncdir; fuse_forget_in forget; + fuse_interrupt_in interrupt; + fuse_lk_in getlk; fuse_init_in init; fuse_link_in link; char lookup[0]; @@ -92,6 +100,7 @@ union fuse_payloads_in { fuse_rename_in rename; char rmdir[0]; fuse_setattr_in setattr; + fuse_lk_in setlk; char unlink[0]; fuse_write_in write; }; @@ -107,8 +116,10 @@ union fuse_payloads_out { /* The protocol places no limits on the size of bytes */ uint8_t bytes[0x20000]; fuse_entry_out entry; + fuse_lk_out getlk; fuse_init_out init; fuse_open_out open; + fuse_lk_out setlk; fuse_statfs_out statfs; /* * The protocol places no limits on the length of the string. This is @@ -165,7 +176,7 @@ class MockFS { pid_t m_pid; /* Initialize a session after mounting */ - void init(); + void init(uint32_t flags); /* Is pid from a process that might be involved in the test? */ bool pid_ok(pid_t pid); @@ -184,7 +195,7 @@ class MockFS { uint32_t m_max_write; /* Create a new mockfs and mount it to a tempdir */ - MockFS(int max_readahead); + MockFS(int max_readahead, uint32_t flags); virtual ~MockFS(); /* Kill the filesystem daemon without unmounting the filesystem */ Modified: projects/fuse2/tests/sys/fs/fuse/utils.cc ============================================================================== --- projects/fuse2/tests/sys/fs/fuse/utils.cc Wed Mar 13 21:53:10 2019 (r345117) +++ projects/fuse2/tests/sys/fs/fuse/utils.cc Wed Mar 13 22:16:00 2019 (r345118) @@ -76,7 +76,7 @@ void FuseTest::SetUp() { m_maxbcachebuf = val; try { - m_mock = new MockFS(m_maxreadahead); + m_mock = new MockFS(m_maxreadahead, m_init_flags); } catch (std::system_error err) { FAIL() << err.what(); } Modified: projects/fuse2/tests/sys/fs/fuse/utils.hh ============================================================================== --- projects/fuse2/tests/sys/fs/fuse/utils.hh Wed Mar 13 21:53:10 2019 (r345117) +++ projects/fuse2/tests/sys/fs/fuse/utils.hh Wed Mar 13 22:16:00 2019 (r345118) @@ -31,6 +31,7 @@ class FuseTest : public ::testing::Test { protected: uint32_t m_maxreadahead; + uint32_t m_init_flags; MockFS *m_mock = NULL; public: @@ -40,8 +41,10 @@ class FuseTest : public ::testing::Test { * libfuse's default max_readahead is UINT_MAX, though it can be * lowered */ - FuseTest(): FuseTest(UINT_MAX) {} + FuseTest(): FuseTest(UINT_MAX, 0) {} FuseTest(uint32_t maxreadahead): m_maxreadahead(maxreadahead) {} + FuseTest(uint32_t maxreadahead, uint32_t init_flags): + m_maxreadahead(maxreadahead), m_init_flags(init_flags) {} virtual void SetUp();