diff --git a/tests/sys/fs/fusefs/bmap.cc b/tests/sys/fs/fusefs/bmap.cc --- a/tests/sys/fs/fusefs/bmap.cc +++ b/tests/sys/fs/fusefs/bmap.cc @@ -83,10 +83,14 @@ TEST_F(Bmap, bmap) { struct fiobmap2_arg arg; - const off_t filesize = 1 << 20; - const ino_t ino = 42; - int64_t lbn = 10; + /* + * Pick fsize and lbn large enough that max length runs won't reach + * either beginning or end of file + */ + const off_t filesize = 1 << 30; + int64_t lbn = 100; int64_t pbn = 12345; + const ino_t ino = 42; int fd; expect_lookup(RELPATH, 42, filesize); @@ -112,7 +116,7 @@ TEST_F(Bmap, default_) { struct fiobmap2_arg arg; - const off_t filesize = 1 << 20; + const off_t filesize = 1 << 30; const ino_t ino = 42; int64_t lbn; int fd; diff --git a/tests/sys/fs/fusefs/mockfs.hh b/tests/sys/fs/fusefs/mockfs.hh --- a/tests/sys/fs/fusefs/mockfs.hh +++ b/tests/sys/fs/fusefs/mockfs.hh @@ -72,6 +72,14 @@ extern int verbosity; +/* + * The maximum that a test case can set max_write, limited by the buffer + * supplied when reading from /dev/fuse. This limitation is imposed by + * fusefs-libs, but not by the FUSE protocol. + */ +const uint32_t max_max_write = 0x20000; + + /* This struct isn't defined by fuse_kernel.h or libfuse, but it should be */ struct fuse_create_out { struct fuse_entry_out entry; @@ -138,8 +146,17 @@ union fuse_payloads_in { fuse_access_in access; fuse_bmap_in bmap; - /* value is from fuse_kern_chan.c in fusefs-libs */ - uint8_t bytes[0x21000 - sizeof(struct fuse_in_header)]; + /* + * In fusefs-libs 3.4.2 and below the buffer size is fixed at 0x21000 + * minus the header sizes. fusefs-libs 3.4.3 (and FUSE Protocol 7.29) + * add a FUSE_MAX_PAGES option that allows it to be greater. + * + * See fuse_kern_chan.c in fusefs-libs 2.9.9 and below, or + * FUSE_DEFAULT_MAX_PAGES_PER_REQ in fusefs-libs 3.4.3 and above. + */ + uint8_t bytes[ + max_max_write + 0x1000 - sizeof(struct fuse_in_header) + ]; fuse_create_in create; fuse_flush_in flush; fuse_fsync_in fsync; diff --git a/tests/sys/fs/fusefs/mockfs.cc b/tests/sys/fs/fusefs/mockfs.cc --- a/tests/sys/fs/fusefs/mockfs.cc +++ b/tests/sys/fs/fusefs/mockfs.cc @@ -365,7 +365,7 @@ m_daemon_id = NULL; m_kernel_minor_version = kernel_minor_version; m_maxreadahead = max_readahead; - m_maxwrite = max_write; + m_maxwrite = MIN(max_write, max_max_write); m_nready = -1; m_pm = pm; m_time_gran = time_gran; diff --git a/tests/sys/fs/fusefs/utils.hh b/tests/sys/fs/fusefs/utils.hh --- a/tests/sys/fs/fusefs/utils.hh +++ b/tests/sys/fs/fusefs/utils.hh @@ -55,7 +55,6 @@ bool is_unsafe_aio_enabled(void); extern const uint32_t libfuse_max_write; -extern const uint32_t default_max_write; class FuseTest : public ::testing::Test { protected: uint32_t m_maxreadahead; @@ -80,7 +79,7 @@ FuseTest(): m_maxreadahead(0), - m_maxwrite(default_max_write), + m_maxwrite(0), m_init_flags(0), m_allow_other(false), m_default_permissions(false), diff --git a/tests/sys/fs/fusefs/utils.cc b/tests/sys/fs/fusefs/utils.cc --- a/tests/sys/fs/fusefs/utils.cc +++ b/tests/sys/fs/fusefs/utils.cc @@ -59,13 +59,6 @@ */ const uint32_t libfuse_max_write = 32 * getpagesize() + 0x1000 - 4096; -/* - * Set the default max_write to a distinct value from MAXPHYS to catch bugs - * that confuse the two. - */ -const uint32_t default_max_write = MIN(libfuse_max_write, MAXPHYS / 2); - - /* Check that fusefs(4) is accessible and the current user can mount(2) */ void check_environment() { @@ -156,6 +149,12 @@ ASSERT_EQ(0, sysctlbyname(maxphys_node, &val, &size, NULL, 0)) << strerror(errno); m_maxphys = val; + /* + * Set the default max_write to a distinct value from MAXPHYS to catch + * bugs that confuse the two. + */ + if (m_maxwrite == 0) + m_maxwrite = MIN(libfuse_max_write, (uint32_t)m_maxphys / 2); try { m_mock = new MockFS(m_maxreadahead, m_allow_other, diff --git a/tests/sys/fs/fusefs/write.cc b/tests/sys/fs/fusefs/write.cc --- a/tests/sys/fs/fusefs/write.cc +++ b/tests/sys/fs/fusefs/write.cc @@ -166,6 +166,7 @@ public: virtual void SetUp() { m_async = true; + m_maxwrite = 65536; WriteBack::SetUp(); } }; @@ -194,6 +195,19 @@ } }; +/* Tests relating to the server's max_write property */ +class WriteMaxWrite: public Write { +public: +virtual void SetUp() { + /* + * For this test, m_maxwrite must be less than either m_maxbcachebuf or + * maxphys. + */ + m_maxwrite = 32768; + Write::SetUp(); +} +}; + void sigxfsz_handler(int __unused sig) { Write::s_sigxfsz = 1; } @@ -643,7 +657,7 @@ } /* fuse(4) should not issue writes of greater size than the daemon requests */ -TEST_F(Write, write_large) +TEST_F(WriteMaxWrite, write) { const char FULLPATH[] = "mountpoint/some_file.txt"; const char RELPATH[] = "some_file.txt"; @@ -653,6 +667,8 @@ ssize_t halfbufsize, bufsize; halfbufsize = m_mock->m_maxwrite; + if (halfbufsize >= m_maxbcachebuf || halfbufsize >= m_maxphys) + GTEST_SKIP() << "Must lower m_maxwrite for this test"; bufsize = halfbufsize * 2; contents = (int*)malloc(bufsize); ASSERT_NE(nullptr, contents);