Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/fs/fusefs/bmap.cc
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | |||||
void expect_lookup(const char *relpath, uint64_t ino, off_t size) | void expect_lookup(const char *relpath, uint64_t ino, off_t size) | ||||
{ | { | ||||
FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, size, 1, | FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, size, 1, | ||||
UINT64_MAX); | UINT64_MAX); | ||||
} | } | ||||
}; | }; | ||||
class BmapEof: public Bmap, public WithParamInterface<int> {}; | |||||
/* | /* | ||||
* Test FUSE_BMAP | * Test FUSE_BMAP | ||||
* XXX The FUSE protocol does not include the runp and runb variables, so those | * XXX The FUSE protocol does not include the runp and runb variables, so those | ||||
* must be guessed in-kernel. | * must be guessed in-kernel. | ||||
*/ | */ | ||||
TEST_F(Bmap, bmap) | TEST_F(Bmap, bmap) | ||||
{ | { | ||||
struct fiobmap2_arg arg; | struct fiobmap2_arg arg; | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | TEST_F(Bmap, default_) | ||||
arg.runb = -1; | arg.runb = -1; | ||||
ASSERT_EQ(0, ioctl(fd, FIOBMAP2, &arg)) << strerror(errno); | ASSERT_EQ(0, ioctl(fd, FIOBMAP2, &arg)) << strerror(errno); | ||||
EXPECT_EQ(arg.bn, lbn * m_maxbcachebuf / DEV_BSIZE); | EXPECT_EQ(arg.bn, lbn * m_maxbcachebuf / DEV_BSIZE); | ||||
EXPECT_EQ(arg.runp, 0); | EXPECT_EQ(arg.runp, 0); | ||||
EXPECT_EQ(arg.runb, m_maxphys / m_maxbcachebuf - 1); | EXPECT_EQ(arg.runb, m_maxphys / m_maxbcachebuf - 1); | ||||
leak(fd); | leak(fd); | ||||
} | } | ||||
/* | |||||
* VOP_BMAP should not query the server for the file's size, even if its cached | |||||
* attributes have expired. | |||||
* Regression test for https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=256937 | |||||
*/ | |||||
TEST_P(BmapEof, eof) | |||||
{ | |||||
/* | |||||
* Outline: | |||||
* 1) lookup the file, setting attr_valid=0 | |||||
* 2) Read more than one block, causing the kernel to issue VOP_BMAP to | |||||
* plan readahead. | |||||
* 3) Nothing should panic | |||||
* 4) Repeat the tests, truncating the file after different numbers of | |||||
* GETATTR operations. | |||||
*/ | |||||
Sequence seq; | |||||
const off_t filesize = 2 * m_maxbcachebuf; | |||||
const ino_t ino = 42; | |||||
mode_t mode = S_IFREG | 0644; | |||||
void *contents, *buf; | |||||
int fd; | |||||
int ngetattrs; | |||||
ngetattrs = GetParam(); | |||||
contents = calloc(1, filesize); | |||||
FuseTest::expect_lookup(RELPATH, ino, mode, filesize, 1, 0); | |||||
expect_open(ino, 0, 1); | |||||
// Depending on ngetattrs, FUSE_READ could be called with either | |||||
// filesize or filesize / 2 . | |||||
EXPECT_CALL(*m_mock, process( | |||||
ResultOf([=](auto in) { | |||||
return (in.header.opcode == FUSE_READ && | |||||
in.header.nodeid == ino && | |||||
in.body.read.offset == 0 && | |||||
( in.body.read.size == filesize || | |||||
in.body.read.size == filesize / 2)); | |||||
}, Eq(true)), | |||||
_) | |||||
).WillOnce(Invoke(ReturnImmediate([=](auto in, auto& out) { | |||||
size_t osize = in.body.read.size; | |||||
out.header.len = sizeof(struct fuse_out_header) + osize; | |||||
bzero(out.body.bytes, osize); | |||||
}))); | |||||
EXPECT_CALL(*m_mock, process( | |||||
ResultOf([](auto in) { | |||||
return (in.header.opcode == FUSE_GETATTR && | |||||
in.header.nodeid == ino); | |||||
}, Eq(true)), | |||||
_) | |||||
).Times(Between(ngetattrs - 1, ngetattrs)) | |||||
.InSequence(seq) | |||||
.WillRepeatedly(Invoke(ReturnImmediate([=](auto i __unused, auto& out) { | |||||
SET_OUT_HEADER_LEN(out, attr); | |||||
out.body.attr.attr_valid = 0; | |||||
out.body.attr.attr.ino = ino; | |||||
out.body.attr.attr.mode = S_IFREG | 0644; | |||||
out.body.attr.attr.size = filesize; | |||||
}))); | |||||
EXPECT_CALL(*m_mock, process( | |||||
ResultOf([](auto in) { | |||||
return (in.header.opcode == FUSE_GETATTR && | |||||
in.header.nodeid == ino); | |||||
}, Eq(true)), | |||||
_) | |||||
).InSequence(seq) | |||||
.WillRepeatedly(Invoke(ReturnImmediate([=](auto i __unused, auto& out) { | |||||
SET_OUT_HEADER_LEN(out, attr); | |||||
out.body.attr.attr_valid = 0; | |||||
out.body.attr.attr.ino = ino; | |||||
out.body.attr.attr.mode = S_IFREG | 0644; | |||||
out.body.attr.attr.size = filesize / 2; | |||||
}))); | |||||
buf = calloc(1, filesize); | |||||
fd = open(FULLPATH, O_RDWR); | |||||
ASSERT_LE(0, fd) << strerror(errno); | |||||
read(fd, buf, filesize); | |||||
} | |||||
INSTANTIATE_TEST_CASE_P(BE, BmapEof, | |||||
Values(1, 2, 3) | |||||
); |