fuse(4): add tests for FUSE_OPENDIR, FUSE_FSYNC, and FUSE_FSYNCDIR
And one more for FUSE_WRITE, too. PR: 236379 PR: 236473 PR: 236474 Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
da1200c90f
commit
4459896e18
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/projects/fuse2/; revision=345035
@ -7,12 +7,15 @@ TESTSDIR= ${TESTSBASE}/sys/fs/fuse
|
||||
ATF_TESTS_CXX+= access
|
||||
ATF_TESTS_CXX+= create
|
||||
ATF_TESTS_CXX+= flush
|
||||
ATF_TESTS_CXX+= fsync
|
||||
ATF_TESTS_CXX+= fsyncdir
|
||||
ATF_TESTS_CXX+= getattr
|
||||
ATF_TESTS_CXX+= link
|
||||
ATF_TESTS_CXX+= lookup
|
||||
ATF_TESTS_CXX+= mkdir
|
||||
ATF_TESTS_CXX+= mknod
|
||||
ATF_TESTS_CXX+= open
|
||||
ATF_TESTS_CXX+= opendir
|
||||
ATF_TESTS_CXX+= read
|
||||
ATF_TESTS_CXX+= readlink
|
||||
ATF_TESTS_CXX+= release
|
||||
@ -39,6 +42,16 @@ SRCS.flush+= getmntopts.c
|
||||
SRCS.flush+= mockfs.cc
|
||||
SRCS.flush+= utils.cc
|
||||
|
||||
SRCS.fsync+= fsync.cc
|
||||
SRCS.fsync+= getmntopts.c
|
||||
SRCS.fsync+= mockfs.cc
|
||||
SRCS.fsync+= utils.cc
|
||||
|
||||
SRCS.fsyncdir+= fsyncdir.cc
|
||||
SRCS.fsyncdir+= getmntopts.c
|
||||
SRCS.fsyncdir+= mockfs.cc
|
||||
SRCS.fsyncdir+= utils.cc
|
||||
|
||||
SRCS.getattr+= getattr.cc
|
||||
SRCS.getattr+= getmntopts.c
|
||||
SRCS.getattr+= mockfs.cc
|
||||
@ -69,6 +82,11 @@ SRCS.open+= mockfs.cc
|
||||
SRCS.open+= open.cc
|
||||
SRCS.open+= utils.cc
|
||||
|
||||
SRCS.opendir+= getmntopts.c
|
||||
SRCS.opendir+= mockfs.cc
|
||||
SRCS.opendir+= opendir.cc
|
||||
SRCS.opendir+= utils.cc
|
||||
|
||||
SRCS.read+= getmntopts.c
|
||||
SRCS.read+= mockfs.cc
|
||||
SRCS.read+= read.cc
|
||||
|
349
tests/sys/fs/fuse/fsync.cc
Normal file
349
tests/sys/fs/fuse/fsync.cc
Normal file
@ -0,0 +1,349 @@
|
||||
/*-
|
||||
* 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 <aio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
}
|
||||
|
||||
#include "mockfs.hh"
|
||||
#include "utils.hh"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
/*
|
||||
* TODO: remove FUSE_FSYNC_FDATASYNC definition when upgrading to protocol 7.28.
|
||||
* This bit was actually part of kernel protocol version 5.2, but never
|
||||
* documented until after 7.28
|
||||
*/
|
||||
#ifndef FUSE_FSYNC_FDATASYNC
|
||||
#define FUSE_FSYNC_FDATASYNC 1
|
||||
#endif
|
||||
|
||||
class Fsync: public FuseTest {
|
||||
public:
|
||||
const static uint64_t FH = 0xdeadbeef1a7ebabe;
|
||||
void expect_fsync(uint64_t ino, uint32_t flags, int error)
|
||||
{
|
||||
EXPECT_CALL(*m_mock, process(
|
||||
ResultOf([=](auto in) {
|
||||
return (in->header.opcode == FUSE_FSYNC &&
|
||||
in->header.nodeid == ino &&
|
||||
//(pid_t)in->header.pid == getpid() &&
|
||||
in->body.fsync.fh == FH &&
|
||||
in->body.fsync.fsync_flags == flags);
|
||||
}, Eq(true)),
|
||||
_)
|
||||
).WillOnce(Invoke(ReturnErrno(error)));
|
||||
}
|
||||
|
||||
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;
|
||||
}));
|
||||
}
|
||||
|
||||
void expect_release(uint64_t ino)
|
||||
{
|
||||
EXPECT_CALL(*m_mock, process(
|
||||
ResultOf([=](auto in) {
|
||||
return (in->header.opcode == FUSE_RELEASE &&
|
||||
in->header.nodeid == ino);
|
||||
}, Eq(true)),
|
||||
_)
|
||||
).WillOnce(Invoke(ReturnErrno(0)));
|
||||
}
|
||||
|
||||
void expect_write(uint64_t ino, uint64_t size, const void *contents)
|
||||
{
|
||||
EXPECT_CALL(*m_mock, process(
|
||||
ResultOf([=](auto in) {
|
||||
const char *buf = (const char*)in->body.bytes +
|
||||
sizeof(struct fuse_write_in);
|
||||
|
||||
return (in->header.opcode == FUSE_WRITE &&
|
||||
in->header.nodeid == ino &&
|
||||
0 == bcmp(buf, contents, size));
|
||||
}, Eq(true)),
|
||||
_)
|
||||
).WillOnce(Invoke([=](auto in, auto out) {
|
||||
out->header.unique = in->header.unique;
|
||||
SET_OUT_HEADER_LEN(out, write);
|
||||
out->body.write.size = size;
|
||||
}));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236379 */
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236473 */
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236474 */
|
||||
TEST_F(Fsync, DISABLED_aio_fsync)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_file.txt";
|
||||
const char RELPATH[] = "some_file.txt";
|
||||
const char *CONTENTS = "abcdefgh";
|
||||
ssize_t bufsize = strlen(CONTENTS);
|
||||
uint64_t ino = 42;
|
||||
struct aiocb iocb, *piocb;
|
||||
int fd;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
expect_open(ino);
|
||||
expect_getattr(ino);
|
||||
expect_write(ino, bufsize, CONTENTS);
|
||||
expect_fsync(ino, 0, 0);
|
||||
|
||||
fd = open(FULLPATH, O_RDWR);
|
||||
ASSERT_LE(0, fd) << strerror(errno);
|
||||
ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
|
||||
|
||||
bzero(&iocb, sizeof(iocb));
|
||||
iocb.aio_fildes = fd;
|
||||
|
||||
ASSERT_EQ(0, aio_fsync(O_SYNC, &iocb)) << strerror(errno);
|
||||
ASSERT_EQ(0, aio_waitcomplete(&piocb, NULL)) << strerror(errno);
|
||||
|
||||
/* Deliberately leak fd. close(2) will be tested in release.cc */
|
||||
}
|
||||
|
||||
/*
|
||||
* fuse(4) should NOT fsync during VOP_RELEASE or VOP_INACTIVE
|
||||
*
|
||||
* This test only really make sense in writeback caching mode, but it should
|
||||
* still pass in any cache mode.
|
||||
*/
|
||||
TEST_F(Fsync, close)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_file.txt";
|
||||
const char RELPATH[] = "some_file.txt";
|
||||
const char *CONTENTS = "abcdefgh";
|
||||
ssize_t bufsize = strlen(CONTENTS);
|
||||
uint64_t ino = 42;
|
||||
int fd;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
expect_open(ino);
|
||||
expect_getattr(ino);
|
||||
expect_write(ino, bufsize, CONTENTS);
|
||||
EXPECT_CALL(*m_mock, process(
|
||||
ResultOf([=](auto in) {
|
||||
return (in->header.opcode == FUSE_SETATTR);
|
||||
}, 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
|
||||
}));
|
||||
EXPECT_CALL(*m_mock, process(
|
||||
ResultOf([=](auto in) {
|
||||
return (in->header.opcode == FUSE_FSYNC);
|
||||
}, Eq(true)),
|
||||
_)
|
||||
).Times(0);
|
||||
expect_release(ino);
|
||||
|
||||
fd = open(FULLPATH, O_RDWR);
|
||||
ASSERT_LE(0, fd) << strerror(errno);
|
||||
ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236474 */
|
||||
TEST_F(Fsync, DISABLED_eio)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_file.txt";
|
||||
const char RELPATH[] = "some_file.txt";
|
||||
const char *CONTENTS = "abcdefgh";
|
||||
ssize_t bufsize = strlen(CONTENTS);
|
||||
uint64_t ino = 42;
|
||||
int fd;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
expect_open(ino);
|
||||
expect_getattr(ino);
|
||||
expect_write(ino, bufsize, CONTENTS);
|
||||
expect_fsync(ino, FUSE_FSYNC_FDATASYNC, EIO);
|
||||
|
||||
fd = open(FULLPATH, O_RDWR);
|
||||
ASSERT_LE(0, fd) << strerror(errno);
|
||||
ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
|
||||
ASSERT_NE(0, fdatasync(fd));
|
||||
ASSERT_EQ(EIO, errno);
|
||||
|
||||
/* Deliberately leak fd. close(2) will be tested in release.cc */
|
||||
}
|
||||
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236474 */
|
||||
TEST_F(Fsync, DISABLED_fdatasync)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_file.txt";
|
||||
const char RELPATH[] = "some_file.txt";
|
||||
const char *CONTENTS = "abcdefgh";
|
||||
ssize_t bufsize = strlen(CONTENTS);
|
||||
uint64_t ino = 42;
|
||||
int fd;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
expect_open(ino);
|
||||
expect_getattr(ino);
|
||||
expect_write(ino, bufsize, CONTENTS);
|
||||
expect_fsync(ino, FUSE_FSYNC_FDATASYNC, 0);
|
||||
|
||||
fd = open(FULLPATH, O_RDWR);
|
||||
ASSERT_LE(0, fd) << strerror(errno);
|
||||
ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
|
||||
ASSERT_EQ(0, fdatasync(fd)) << strerror(errno);
|
||||
|
||||
/* Deliberately leak fd. close(2) will be tested in release.cc */
|
||||
}
|
||||
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236473 */
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236474 */
|
||||
TEST_F(Fsync, DISABLED_fsync)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_file.txt";
|
||||
const char RELPATH[] = "some_file.txt";
|
||||
const char *CONTENTS = "abcdefgh";
|
||||
ssize_t bufsize = strlen(CONTENTS);
|
||||
uint64_t ino = 42;
|
||||
int fd;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
expect_open(ino);
|
||||
expect_getattr(ino);
|
||||
expect_write(ino, bufsize, CONTENTS);
|
||||
expect_fsync(ino, 0, 0);
|
||||
|
||||
fd = open(FULLPATH, O_RDWR);
|
||||
ASSERT_LE(0, fd) << strerror(errno);
|
||||
ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
|
||||
ASSERT_EQ(0, fsync(fd)) << strerror(errno);
|
||||
|
||||
/* Deliberately leak fd. close(2) will be tested in release.cc */
|
||||
}
|
||||
|
||||
/* Fsync should sync a file with dirty metadata but clean data */
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236473 */
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236474 */
|
||||
TEST_F(Fsync, DISABLED_fsync_metadata_only)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_file.txt";
|
||||
const char RELPATH[] = "some_file.txt";
|
||||
uint64_t ino = 42;
|
||||
int fd;
|
||||
mode_t mode = 0755;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
expect_open(ino);
|
||||
expect_getattr(ino);
|
||||
EXPECT_CALL(*m_mock, process(
|
||||
ResultOf([=](auto in) {
|
||||
return (in->header.opcode == FUSE_SETATTR);
|
||||
}, Eq(true)),
|
||||
_)
|
||||
).WillOnce(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 | mode;
|
||||
}));
|
||||
|
||||
expect_fsync(ino, 0, 0);
|
||||
|
||||
fd = open(FULLPATH, O_RDWR);
|
||||
ASSERT_LE(0, fd) << strerror(errno);
|
||||
ASSERT_EQ(0, fchmod(fd, mode)) << strerror(errno);
|
||||
ASSERT_EQ(0, fsync(fd)) << strerror(errno);
|
||||
/* Deliberately leak fd. close(2) will be tested in release.cc */
|
||||
}
|
||||
|
||||
// fsync()ing a file that isn't dirty should be a no-op
|
||||
TEST_F(Fsync, nop)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_file.txt";
|
||||
const char RELPATH[] = "some_file.txt";
|
||||
uint64_t ino = 42;
|
||||
int fd;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
expect_open(ino);
|
||||
expect_getattr(ino);
|
||||
|
||||
fd = open(FULLPATH, O_WRONLY);
|
||||
ASSERT_LE(0, fd) << strerror(errno);
|
||||
|
||||
ASSERT_EQ(0, fsync(fd)) << strerror(errno);
|
||||
|
||||
/* Deliberately leak fd. close(2) will be tested in release.cc */
|
||||
}
|
||||
|
||||
|
186
tests/sys/fs/fuse/fsyncdir.cc
Normal file
186
tests/sys/fs/fuse/fsyncdir.cc
Normal file
@ -0,0 +1,186 @@
|
||||
/*-
|
||||
* 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 <aio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
}
|
||||
|
||||
#include "mockfs.hh"
|
||||
#include "utils.hh"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
/*
|
||||
* TODO: remove FUSE_FSYNC_FDATASYNC definition when upgrading to protocol 7.28.
|
||||
* This bit was actually part of kernel protocol version 5.2, but never
|
||||
* documented until after 7.28
|
||||
*/
|
||||
#ifndef FUSE_FSYNC_FDATASYNC
|
||||
#define FUSE_FSYNC_FDATASYNC 1
|
||||
#endif
|
||||
|
||||
class FsyncDir: public FuseTest {
|
||||
public:
|
||||
const static uint64_t FH = 0xdeadbeef1a7ebabe;
|
||||
void expect_fsyncdir(uint64_t ino, uint32_t flags, int error)
|
||||
{
|
||||
EXPECT_CALL(*m_mock, process(
|
||||
ResultOf([=](auto in) {
|
||||
return (in->header.opcode == FUSE_FSYNCDIR &&
|
||||
in->header.nodeid == ino &&
|
||||
//(pid_t)in->header.pid == getpid() &&
|
||||
in->body.fsyncdir.fh == FH &&
|
||||
in->body.fsyncdir.fsync_flags == flags);
|
||||
}, Eq(true)),
|
||||
_)
|
||||
).WillOnce(Invoke(ReturnErrno(error)));
|
||||
}
|
||||
|
||||
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_IFDIR | 0755;
|
||||
out->body.entry.nodeid = ino;
|
||||
out->body.entry.attr_valid = UINT64_MAX;
|
||||
}));
|
||||
}
|
||||
|
||||
void expect_opendir(uint64_t ino)
|
||||
{
|
||||
EXPECT_CALL(*m_mock, process(
|
||||
ResultOf([=](auto in) {
|
||||
return (in->header.opcode == FUSE_OPENDIR &&
|
||||
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;
|
||||
}));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236379 */
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236473 */
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236474 */
|
||||
TEST_F(FsyncDir, DISABLED_aio_fsync)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_file.txt";
|
||||
const char RELPATH[] = "some_file.txt";
|
||||
uint64_t ino = 42;
|
||||
struct aiocb iocb, *piocb;
|
||||
int fd;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
expect_opendir(ino);
|
||||
expect_fsyncdir(ino, 0, 0);
|
||||
|
||||
fd = open(FULLPATH, O_DIRECTORY);
|
||||
ASSERT_LE(0, fd) << strerror(errno);
|
||||
|
||||
bzero(&iocb, sizeof(iocb));
|
||||
iocb.aio_fildes = fd;
|
||||
|
||||
ASSERT_EQ(0, aio_fsync(O_SYNC, &iocb)) << strerror(errno);
|
||||
ASSERT_EQ(0, aio_waitcomplete(&piocb, NULL)) << strerror(errno);
|
||||
|
||||
/* Deliberately leak fd. close(2) will be tested in release.cc */
|
||||
}
|
||||
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236473 */
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236474 */
|
||||
TEST_F(FsyncDir, DISABLED_eio)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_dir";
|
||||
const char RELPATH[] = "some_dir";
|
||||
uint64_t ino = 42;
|
||||
int fd;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
expect_opendir(ino);
|
||||
expect_fsyncdir(ino, 0, EIO);
|
||||
|
||||
fd = open(FULLPATH, O_DIRECTORY);
|
||||
ASSERT_LE(0, fd) << strerror(errno);
|
||||
ASSERT_NE(0, fsync(fd));
|
||||
ASSERT_EQ(EIO, errno);
|
||||
|
||||
/* Deliberately leak fd. close(2) will be tested in release.cc */
|
||||
}
|
||||
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236474 */
|
||||
TEST_F(FsyncDir, DISABLED_fsyncdata)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_dir";
|
||||
const char RELPATH[] = "some_dir";
|
||||
uint64_t ino = 42;
|
||||
int fd;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
expect_opendir(ino);
|
||||
expect_fsyncdir(ino, FUSE_FSYNC_FDATASYNC, 0);
|
||||
|
||||
fd = open(FULLPATH, O_DIRECTORY);
|
||||
ASSERT_LE(0, fd) << strerror(errno);
|
||||
ASSERT_EQ(0, fdatasync(fd)) << strerror(errno);
|
||||
|
||||
/* Deliberately leak fd. close(2) will be tested in release.cc */
|
||||
}
|
||||
|
||||
/*
|
||||
* Unlike regular files, the kernel doesn't know whether a directory is or
|
||||
* isn't dirty, so fuse(4) should always send FUSE_FSYNCDIR on fsync(2)
|
||||
*/
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236473 */
|
||||
/* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236474 */
|
||||
TEST_F(FsyncDir, DISABLED_fsync)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_dir";
|
||||
const char RELPATH[] = "some_dir";
|
||||
uint64_t ino = 42;
|
||||
int fd;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
expect_opendir(ino);
|
||||
expect_fsyncdir(ino, 0, 0);
|
||||
|
||||
fd = open(FULLPATH, O_DIRECTORY);
|
||||
ASSERT_LE(0, fd) << strerror(errno);
|
||||
ASSERT_EQ(0, fsync(fd)) << strerror(errno);
|
||||
|
||||
/* Deliberately leak fd. close(2) will be tested in release.cc */
|
||||
}
|
@ -144,6 +144,12 @@ void debug_fuseop(const mockfs_buf_in *in)
|
||||
in->header.unique, in->header.len);
|
||||
}
|
||||
switch (in->header.opcode) {
|
||||
case FUSE_FSYNC:
|
||||
printf(" flags=%#x", in->body.fsync.fsync_flags);
|
||||
break;
|
||||
case FUSE_FSYNCDIR:
|
||||
printf(" flags=%#x", in->body.fsyncdir.fsync_flags);
|
||||
break;
|
||||
case FUSE_LOOKUP:
|
||||
printf(" %s", in->body.lookup);
|
||||
break;
|
||||
@ -155,6 +161,9 @@ void debug_fuseop(const mockfs_buf_in *in)
|
||||
printf(" offset=%lu size=%u", in->body.read.offset,
|
||||
in->body.read.size);
|
||||
break;
|
||||
case FUSE_SETATTR:
|
||||
printf(" valid=%#x", in->body.setattr.valid);
|
||||
break;
|
||||
case FUSE_WRITE:
|
||||
printf(" offset=%lu size=%u flags=%u",
|
||||
in->body.write.offset, in->body.write.size,
|
||||
|
@ -75,6 +75,8 @@ union fuse_payloads_in {
|
||||
/* value is from fuse_kern_chan.c in fusefs-libs */
|
||||
uint8_t bytes[0x21000 - sizeof(struct fuse_in_header)];
|
||||
fuse_flush_in flush;
|
||||
fuse_fsync_in fsync;
|
||||
fuse_fsync_in fsyncdir;
|
||||
fuse_forget_in forget;
|
||||
fuse_init_in init;
|
||||
fuse_link_in link;
|
||||
|
123
tests/sys/fs/fuse/opendir.cc
Normal file
123
tests/sys/fs/fuse/opendir.cc
Normal file
@ -0,0 +1,123 @@
|
||||
/*-
|
||||
* 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 <fcntl.h>
|
||||
}
|
||||
|
||||
#include "mockfs.hh"
|
||||
#include "utils.hh"
|
||||
|
||||
using namespace testing;
|
||||
|
||||
class Opendir: public FuseTest {
|
||||
public:
|
||||
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_IFDIR | 0755;
|
||||
out->body.entry.nodeid = ino;
|
||||
out->body.entry.attr_valid = UINT64_MAX;
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* The fuse daemon fails the request with enoent. This usually indicates a
|
||||
* race condition: some other FUSE client removed the file in between when the
|
||||
* kernel checked for it with lookup and tried to open it
|
||||
*/
|
||||
TEST_F(Opendir, enoent)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_dir";
|
||||
const char RELPATH[] = "some_dir";
|
||||
uint64_t ino = 42;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
|
||||
EXPECT_CALL(*m_mock, process(
|
||||
ResultOf([=](auto in) {
|
||||
return (in->header.opcode == FUSE_OPENDIR &&
|
||||
in->header.nodeid == ino);
|
||||
}, Eq(true)),
|
||||
_)
|
||||
).WillOnce(Invoke(ReturnErrno(ENOENT)));
|
||||
EXPECT_NE(0, open(FULLPATH, O_DIRECTORY));
|
||||
EXPECT_EQ(ENOENT, errno);
|
||||
}
|
||||
|
||||
/*
|
||||
* The daemon is responsible for checking file permissions (unless the
|
||||
* default_permissions mount option was used)
|
||||
*/
|
||||
TEST_F(Opendir, eperm)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_dir";
|
||||
const char RELPATH[] = "some_dir";
|
||||
uint64_t ino = 42;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
|
||||
EXPECT_CALL(*m_mock, process(
|
||||
ResultOf([=](auto in) {
|
||||
return (in->header.opcode == FUSE_OPENDIR &&
|
||||
in->header.nodeid == ino);
|
||||
}, Eq(true)),
|
||||
_)
|
||||
).WillOnce(Invoke(ReturnErrno(EPERM)));
|
||||
|
||||
EXPECT_NE(0, open(FULLPATH, O_DIRECTORY));
|
||||
EXPECT_EQ(EPERM, errno);
|
||||
}
|
||||
|
||||
TEST_F(Opendir, ok)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_dir";
|
||||
const char RELPATH[] = "some_dir";
|
||||
uint64_t ino = 42;
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
|
||||
EXPECT_CALL(*m_mock, process(
|
||||
ResultOf([=](auto in) {
|
||||
return (in->header.opcode == FUSE_OPENDIR &&
|
||||
in->header.nodeid == ino);
|
||||
}, Eq(true)),
|
||||
_)
|
||||
).WillOnce(Invoke([=](auto in, auto out) {
|
||||
out->header.unique = in->header.unique;
|
||||
SET_OUT_HEADER_LEN(out, open);
|
||||
}));
|
||||
|
||||
EXPECT_LE(0, open(FULLPATH, O_DIRECTORY)) << strerror(errno);
|
||||
}
|
@ -580,6 +580,39 @@ TEST_F(Write, write_nothing)
|
||||
/* Deliberately leak fd. close(2) will be tested in release.cc */
|
||||
}
|
||||
|
||||
/* In writeback mode, dirty data should be written on close */
|
||||
TEST_F(WriteBack, close)
|
||||
{
|
||||
const char FULLPATH[] = "mountpoint/some_file.txt";
|
||||
const char RELPATH[] = "some_file.txt";
|
||||
const char *CONTENTS = "abcdefgh";
|
||||
uint64_t ino = 42;
|
||||
int fd;
|
||||
ssize_t bufsize = strlen(CONTENTS);
|
||||
|
||||
expect_lookup(RELPATH, ino);
|
||||
expect_open(ino, 0, 1);
|
||||
expect_getattr(ino, 0);
|
||||
expect_write(ino, 0, bufsize, bufsize, 0, CONTENTS);
|
||||
EXPECT_CALL(*m_mock, process(
|
||||
ResultOf([=](auto in) {
|
||||
return (in->header.opcode == FUSE_SETATTR);
|
||||
}, 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
|
||||
}));
|
||||
expect_release(ino, ReturnErrno(0));
|
||||
|
||||
fd = open(FULLPATH, O_RDWR);
|
||||
ASSERT_LE(0, fd) << strerror(errno);
|
||||
|
||||
ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Without direct_io, writes should be committed to cache
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user