2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2019 The FreeBSD Foundation
6 * This software was developed by BFF Storage Systems, LLC under sponsorship
7 * from the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/types.h>
35 #include <sys/sysctl.h>
46 using namespace testing;
48 class Write: public FuseTest {
52 void expect_lookup(const char *relpath, uint64_t ino, uint64_t size)
54 FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, size, 1);
57 void expect_release(uint64_t ino, ProcessMockerT r)
59 EXPECT_CALL(*m_mock, process(
60 ResultOf([=](auto in) {
61 return (in->header.opcode == FUSE_RELEASE &&
62 in->header.nodeid == ino);
65 ).WillRepeatedly(Invoke(r));
68 void require_sync_resize_0() {
69 const char *sync_resize_node = "vfs.fusefs.sync_resize";
71 size_t size = sizeof(val);
73 ASSERT_EQ(0, sysctlbyname(sync_resize_node, &val, &size, NULL, 0))
77 "vfs.fusefs.sync_resize must be set to 0 for this test."
78 " That sysctl will probably be removed soon.";
83 class AioWrite: public Write {
84 virtual void SetUp() {
85 const char *node = "vfs.aio.enable_unsafe";
87 size_t size = sizeof(val);
91 ASSERT_EQ(0, sysctlbyname(node, &val, &size, NULL, 0))
95 "vfs.aio.enable_unsafe must be set for this test";
99 /* Tests for the write-through cache mode */
100 class WriteThrough: public Write {
102 virtual void SetUp() {
103 const char *cache_mode_node = "vfs.fusefs.data_cache_mode";
105 size_t size = sizeof(val);
111 ASSERT_EQ(0, sysctlbyname(cache_mode_node, &val, &size, NULL, 0))
114 GTEST_SKIP() << "vfs.fusefs.data_cache_mode must be set to 1 "
115 "(writethrough) for this test";
120 /* Tests for the writeback cache mode */
121 class WriteBack: public Write {
123 virtual void SetUp() {
124 const char *node = "vfs.fusefs.data_cache_mode";
126 size_t size = sizeof(val);
132 ASSERT_EQ(0, sysctlbyname(node, &val, &size, NULL, 0))
135 GTEST_SKIP() << "vfs.fusefs.data_cache_mode must be set to 2 "
136 "(writeback) for this test";
141 /* AIO writes need to set the header's pid field correctly */
142 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236379 */
143 TEST_F(AioWrite, DISABLED_aio_write)
145 const char FULLPATH[] = "mountpoint/some_file.txt";
146 const char RELPATH[] = "some_file.txt";
147 const char *CONTENTS = "abcdefgh";
149 uint64_t offset = 4096;
151 ssize_t bufsize = strlen(CONTENTS);
152 struct aiocb iocb, *piocb;
154 expect_lookup(RELPATH, ino, 0);
155 expect_open(ino, 0, 1);
156 expect_getattr(ino, 0);
157 expect_write(ino, offset, bufsize, bufsize, 0, CONTENTS);
159 fd = open(FULLPATH, O_WRONLY);
160 EXPECT_LE(0, fd) << strerror(errno);
162 iocb.aio_nbytes = bufsize;
163 iocb.aio_fildes = fd;
164 iocb.aio_buf = (void *)CONTENTS;
165 iocb.aio_offset = offset;
166 iocb.aio_sigevent.sigev_notify = SIGEV_NONE;
167 ASSERT_EQ(0, aio_write(&iocb)) << strerror(errno);
168 ASSERT_EQ(bufsize, aio_waitcomplete(&piocb, NULL)) << strerror(errno);
169 /* Deliberately leak fd. close(2) will be tested in release.cc */
173 * When a file is opened with O_APPEND, we should forward that flag to
174 * FUSE_OPEN (tested by Open.o_append) but still attempt to calculate the
175 * offset internally. That way we'll work both with filesystems that
176 * understand O_APPEND (and ignore the offset) and filesystems that don't (and
177 * simply use the offset).
179 * Note that verifying the O_APPEND flag in FUSE_OPEN is done in the
180 * Open.o_append test.
182 TEST_F(Write, append)
184 const ssize_t BUFSIZE = 9;
185 const char FULLPATH[] = "mountpoint/some_file.txt";
186 const char RELPATH[] = "some_file.txt";
187 const char CONTENTS[BUFSIZE] = "abcdefgh";
190 * Set offset to a maxbcachebuf boundary so we don't need to RMW when
191 * using writeback caching
193 uint64_t initial_offset = m_maxbcachebuf;
196 require_sync_resize_0();
198 expect_lookup(RELPATH, ino, initial_offset);
199 expect_open(ino, 0, 1);
200 expect_getattr(ino, initial_offset);
201 expect_write(ino, initial_offset, BUFSIZE, BUFSIZE, 0, CONTENTS);
203 /* Must open O_RDWR or fuse(4) implicitly sets direct_io */
204 fd = open(FULLPATH, O_RDWR | O_APPEND);
205 EXPECT_LE(0, fd) << strerror(errno);
207 ASSERT_EQ(BUFSIZE, write(fd, CONTENTS, BUFSIZE)) << strerror(errno);
208 /* Deliberately leak fd. close(2) will be tested in release.cc */
211 TEST_F(Write, append_direct_io)
213 const ssize_t BUFSIZE = 9;
214 const char FULLPATH[] = "mountpoint/some_file.txt";
215 const char RELPATH[] = "some_file.txt";
216 const char CONTENTS[BUFSIZE] = "abcdefgh";
218 uint64_t initial_offset = 4096;
221 expect_lookup(RELPATH, ino, initial_offset);
222 expect_open(ino, FOPEN_DIRECT_IO, 1);
223 expect_getattr(ino, initial_offset);
224 expect_write(ino, initial_offset, BUFSIZE, BUFSIZE, 0, CONTENTS);
226 fd = open(FULLPATH, O_WRONLY | O_APPEND);
227 EXPECT_LE(0, fd) << strerror(errno);
229 ASSERT_EQ(BUFSIZE, write(fd, CONTENTS, BUFSIZE)) << strerror(errno);
230 /* Deliberately leak fd. close(2) will be tested in release.cc */
233 /* A direct write should evict any overlapping cached data */
234 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235774 */
235 TEST_F(Write, DISABLED_direct_io_evicts_cache)
237 const char FULLPATH[] = "mountpoint/some_file.txt";
238 const char RELPATH[] = "some_file.txt";
239 const char CONTENTS0[] = "abcdefgh";
240 const char CONTENTS1[] = "ijklmnop";
243 ssize_t bufsize = strlen(CONTENTS0) + 1;
244 char readbuf[bufsize];
246 expect_lookup(RELPATH, ino, bufsize);
247 expect_open(ino, 0, 1);
248 expect_getattr(ino, bufsize);
249 expect_read(ino, 0, bufsize, bufsize, CONTENTS0);
250 expect_write(ino, 0, bufsize, bufsize, 0, CONTENTS1);
252 fd = open(FULLPATH, O_RDWR);
253 EXPECT_LE(0, fd) << strerror(errno);
256 ASSERT_EQ(bufsize, read(fd, readbuf, bufsize)) << strerror(errno);
258 // Write directly, evicting cache
259 ASSERT_EQ(0, fcntl(fd, F_SETFL, O_DIRECT)) << strerror(errno);
260 ASSERT_EQ(0, lseek(fd, 0, SEEK_SET)) << strerror(errno);
261 ASSERT_EQ(bufsize, write(fd, CONTENTS1, bufsize)) << strerror(errno);
263 // Read again. Cache should be bypassed
264 expect_read(ino, 0, bufsize, bufsize, CONTENTS1);
265 ASSERT_EQ(0, fcntl(fd, F_SETFL, 0)) << strerror(errno);
266 ASSERT_EQ(0, lseek(fd, 0, SEEK_SET)) << strerror(errno);
267 ASSERT_EQ(bufsize, read(fd, readbuf, bufsize)) << strerror(errno);
268 ASSERT_STREQ(readbuf, CONTENTS1);
270 /* Deliberately leak fd. close(2) will be tested in release.cc */
274 * When the direct_io option is used, filesystems are allowed to write less
275 * data than requested
277 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236381 */
278 TEST_F(Write, DISABLED_direct_io_short_write)
280 const char FULLPATH[] = "mountpoint/some_file.txt";
281 const char RELPATH[] = "some_file.txt";
282 const char *CONTENTS = "abcdefghijklmnop";
285 ssize_t bufsize = strlen(CONTENTS);
286 ssize_t halfbufsize = bufsize / 2;
287 const char *halfcontents = CONTENTS + halfbufsize;
289 expect_lookup(RELPATH, ino, 0);
290 expect_open(ino, FOPEN_DIRECT_IO, 1);
291 expect_getattr(ino, 0);
292 expect_write(ino, 0, bufsize, halfbufsize, 0, CONTENTS);
293 expect_write(ino, halfbufsize, halfbufsize, halfbufsize, 0,
296 fd = open(FULLPATH, O_WRONLY);
297 EXPECT_LE(0, fd) << strerror(errno);
299 ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
300 /* Deliberately leak fd. close(2) will be tested in release.cc */
304 * An insidious edge case: the filesystem returns a short write, and the
305 * difference between what we requested and what it actually wrote crosses an
306 * iov element boundary
308 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236381 */
309 TEST_F(Write, DISABLED_direct_io_short_write_iov)
311 const char FULLPATH[] = "mountpoint/some_file.txt";
312 const char RELPATH[] = "some_file.txt";
313 const char *CONTENTS0 = "abcdefgh";
314 const char *CONTENTS1 = "ijklmnop";
315 const char *EXPECTED0 = "abcdefghijklmnop";
316 const char *EXPECTED1 = "hijklmnop";
319 ssize_t size0 = strlen(CONTENTS0) - 1;
320 ssize_t size1 = strlen(CONTENTS1) + 1;
321 ssize_t totalsize = size0 + size1;
324 expect_lookup(RELPATH, ino, 0);
325 expect_open(ino, FOPEN_DIRECT_IO, 1);
326 expect_getattr(ino, 0);
327 expect_write(ino, 0, totalsize, size0, 0, EXPECTED0);
328 expect_write(ino, size0, size1, size1, 0, EXPECTED1);
330 fd = open(FULLPATH, O_WRONLY);
331 EXPECT_LE(0, fd) << strerror(errno);
333 iov[0].iov_base = (void*)CONTENTS0;
334 iov[0].iov_len = strlen(CONTENTS0);
335 iov[1].iov_base = (void*)CONTENTS1;
336 iov[1].iov_len = strlen(CONTENTS1);
337 ASSERT_EQ(totalsize, writev(fd, iov, 2)) << strerror(errno);
338 /* Deliberately leak fd. close(2) will be tested in release.cc */
342 * If the kernel cannot be sure which uid, gid, or pid was responsible for a
343 * write, then it must set the FUSE_WRITE_CACHE bit
345 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=236378 */
346 // TODO: check vfs.fusefs.mmap_enable
347 TEST_F(Write, DISABLED_mmap)
349 const char FULLPATH[] = "mountpoint/some_file.txt";
350 const char RELPATH[] = "some_file.txt";
351 const char *CONTENTS = "abcdefgh";
354 ssize_t bufsize = strlen(CONTENTS);
356 uint64_t offset = 10;
358 void *zeros, *expected;
362 zeros = calloc(1, len);
363 ASSERT_NE(NULL, zeros);
364 expected = calloc(1, len);
365 ASSERT_NE(NULL, expected);
366 memmove((uint8_t*)expected + offset, CONTENTS, bufsize);
368 expect_lookup(RELPATH, ino, len);
369 expect_open(ino, 0, 1);
370 expect_getattr(ino, len);
371 expect_read(ino, 0, len, len, zeros);
373 * Writes from the pager may or may not be associated with the correct
374 * pid, so they must set FUSE_WRITE_CACHE
376 expect_write(ino, 0, len, len, FUSE_WRITE_CACHE, expected);
377 expect_flush(ino, 1, ReturnErrno(0));
378 expect_release(ino, ReturnErrno(0));
380 fd = open(FULLPATH, O_RDWR);
381 EXPECT_LE(0, fd) << strerror(errno);
383 p = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
384 ASSERT_NE(MAP_FAILED, p) << strerror(errno);
386 memmove((uint8_t*)p + offset, CONTENTS, bufsize);
388 ASSERT_EQ(0, munmap(p, len)) << strerror(errno);
389 close(fd); // Write mmap'd data on close
395 TEST_F(WriteThrough, pwrite)
397 const char FULLPATH[] = "mountpoint/some_file.txt";
398 const char RELPATH[] = "some_file.txt";
399 const char *CONTENTS = "abcdefgh";
401 uint64_t offset = 4096;
403 ssize_t bufsize = strlen(CONTENTS);
405 expect_lookup(RELPATH, ino, 0);
406 expect_open(ino, 0, 1);
407 expect_getattr(ino, 0);
408 expect_write(ino, offset, bufsize, bufsize, 0, CONTENTS);
410 fd = open(FULLPATH, O_WRONLY);
411 EXPECT_LE(0, fd) << strerror(errno);
413 ASSERT_EQ(bufsize, pwrite(fd, CONTENTS, bufsize, offset))
415 /* Deliberately leak fd. close(2) will be tested in release.cc */
420 const char FULLPATH[] = "mountpoint/some_file.txt";
421 const char RELPATH[] = "some_file.txt";
422 const char *CONTENTS = "abcdefgh";
425 ssize_t bufsize = strlen(CONTENTS);
427 expect_lookup(RELPATH, ino, 0);
428 expect_open(ino, 0, 1);
429 expect_getattr(ino, 0);
430 expect_write(ino, 0, bufsize, bufsize, 0, CONTENTS);
432 fd = open(FULLPATH, O_WRONLY);
433 EXPECT_LE(0, fd) << strerror(errno);
435 ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
436 /* Deliberately leak fd. close(2) will be tested in release.cc */
439 /* fuse(4) should not issue writes of greater size than the daemon requests */
440 TEST_F(Write, write_large)
442 const char FULLPATH[] = "mountpoint/some_file.txt";
443 const char RELPATH[] = "some_file.txt";
447 ssize_t halfbufsize, bufsize;
449 halfbufsize = m_mock->m_max_write;
450 bufsize = halfbufsize * 2;
451 contents = (int*)malloc(bufsize);
452 ASSERT_NE(NULL, contents);
453 for (int i = 0; i < (int)bufsize / (int)sizeof(i); i++) {
457 expect_lookup(RELPATH, ino, 0);
458 expect_open(ino, 0, 1);
459 expect_getattr(ino, 0);
460 expect_write(ino, 0, halfbufsize, halfbufsize, 0, contents);
461 expect_write(ino, halfbufsize, halfbufsize, halfbufsize, 0,
462 &contents[halfbufsize / sizeof(int)]);
464 fd = open(FULLPATH, O_WRONLY);
465 EXPECT_LE(0, fd) << strerror(errno);
467 ASSERT_EQ(bufsize, write(fd, contents, bufsize)) << strerror(errno);
468 /* Deliberately leak fd. close(2) will be tested in release.cc */
473 TEST_F(Write, write_nothing)
475 const char FULLPATH[] = "mountpoint/some_file.txt";
476 const char RELPATH[] = "some_file.txt";
477 const char *CONTENTS = "";
482 expect_lookup(RELPATH, ino, 0);
483 expect_open(ino, 0, 1);
484 expect_getattr(ino, 0);
486 fd = open(FULLPATH, O_WRONLY);
487 EXPECT_LE(0, fd) << strerror(errno);
489 ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
490 /* Deliberately leak fd. close(2) will be tested in release.cc */
493 /* In writeback mode, dirty data should be written on close */
494 TEST_F(WriteBack, close)
496 const char FULLPATH[] = "mountpoint/some_file.txt";
497 const char RELPATH[] = "some_file.txt";
498 const char *CONTENTS = "abcdefgh";
501 ssize_t bufsize = strlen(CONTENTS);
503 expect_lookup(RELPATH, ino, 0);
504 expect_open(ino, 0, 1);
505 expect_getattr(ino, 0);
506 expect_write(ino, 0, bufsize, bufsize, 0, CONTENTS);
507 EXPECT_CALL(*m_mock, process(
508 ResultOf([=](auto in) {
509 return (in->header.opcode == FUSE_SETATTR);
512 ).WillRepeatedly(Invoke(ReturnImmediate([=](auto i __unused, auto out) {
513 SET_OUT_HEADER_LEN(out, attr);
514 out->body.attr.attr.ino = ino; // Must match nodeid
516 expect_flush(ino, 1, ReturnErrno(0));
517 expect_release(ino, ReturnErrno(0));
519 fd = open(FULLPATH, O_RDWR);
520 ASSERT_LE(0, fd) << strerror(errno);
522 ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
527 * In writeback mode, writes to an O_WRONLY file could trigger reads from the
528 * server. The FUSE protocol explicitly allows that.
530 TEST_F(WriteBack, rmw)
532 const char FULLPATH[] = "mountpoint/some_file.txt";
533 const char RELPATH[] = "some_file.txt";
534 const char *CONTENTS = "abcdefgh";
535 const char *INITIAL = "XXXXXXXXXX";
540 ssize_t bufsize = strlen(CONTENTS);
542 expect_lookup(RELPATH, ino, 0);
543 expect_open(ino, 0, 1);
544 expect_getattr(ino, fsize);
545 expect_read(ino, 0, fsize, fsize, INITIAL);
546 expect_write(ino, offset, bufsize, bufsize, 0, CONTENTS);
548 fd = open(FULLPATH, O_WRONLY);
549 EXPECT_LE(0, fd) << strerror(errno);
551 ASSERT_EQ(bufsize, pwrite(fd, CONTENTS, bufsize, offset))
553 /* Deliberately leak fd. close(2) will be tested in release.cc */
557 * Without direct_io, writes should be committed to cache
559 TEST_F(WriteBack, writeback)
561 const char FULLPATH[] = "mountpoint/some_file.txt";
562 const char RELPATH[] = "some_file.txt";
563 const char *CONTENTS = "abcdefgh";
566 ssize_t bufsize = strlen(CONTENTS);
567 char readbuf[bufsize];
569 expect_lookup(RELPATH, ino, 0);
570 expect_open(ino, 0, 1);
571 expect_getattr(ino, 0);
572 expect_write(ino, 0, bufsize, bufsize, 0, CONTENTS);
574 fd = open(FULLPATH, O_RDWR);
575 EXPECT_LE(0, fd) << strerror(errno);
577 ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
579 * A subsequent read should be serviced by cache, without querying the
582 ASSERT_EQ(0, lseek(fd, 0, SEEK_SET)) << strerror(errno);
583 ASSERT_EQ(bufsize, read(fd, readbuf, bufsize)) << strerror(errno);
584 /* Deliberately leak fd. close(2) will be tested in release.cc */
588 * With O_DIRECT, writes should be not committed to cache. Admittedly this is
589 * an odd test, because it would be unusual to use O_DIRECT for writes but not
592 TEST_F(WriteBack, o_direct)
594 const char FULLPATH[] = "mountpoint/some_file.txt";
595 const char RELPATH[] = "some_file.txt";
596 const char *CONTENTS = "abcdefgh";
599 ssize_t bufsize = strlen(CONTENTS);
600 char readbuf[bufsize];
602 expect_lookup(RELPATH, ino, 0);
603 expect_open(ino, 0, 1);
604 expect_getattr(ino, 0);
605 expect_write(ino, 0, bufsize, bufsize, 0, CONTENTS);
606 expect_read(ino, 0, bufsize, bufsize, CONTENTS);
608 fd = open(FULLPATH, O_RDWR | O_DIRECT);
609 EXPECT_LE(0, fd) << strerror(errno);
611 ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
612 /* A subsequent read must query the daemon because cache is empty */
613 ASSERT_EQ(0, lseek(fd, 0, SEEK_SET)) << strerror(errno);
614 ASSERT_EQ(0, fcntl(fd, F_SETFL, 0)) << strerror(errno);
615 ASSERT_EQ(bufsize, read(fd, readbuf, bufsize)) << strerror(errno);
616 /* Deliberately leak fd. close(2) will be tested in release.cc */
620 * Without direct_io, writes should be committed to cache
623 * Disabled because we don't yet implement write-through caching. No bugzilla
624 * entry, because that's a feature request, not a bug.
626 TEST_F(WriteThrough, DISABLED_writethrough)
628 const char FULLPATH[] = "mountpoint/some_file.txt";
629 const char RELPATH[] = "some_file.txt";
630 const char *CONTENTS = "abcdefgh";
633 ssize_t bufsize = strlen(CONTENTS);
634 char readbuf[bufsize];
636 expect_lookup(RELPATH, ino, 0);
637 expect_open(ino, 0, 1);
638 expect_getattr(ino, 0);
639 expect_write(ino, 0, bufsize, bufsize, 0, CONTENTS);
641 fd = open(FULLPATH, O_RDWR);
642 EXPECT_LE(0, fd) << strerror(errno);
644 ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
646 * A subsequent read should be serviced by cache, without querying the
649 ASSERT_EQ(bufsize, read(fd, readbuf, bufsize)) << strerror(errno);
650 /* Deliberately leak fd. close(2) will be tested in release.cc */
653 /* With writethrough caching, writes update the cached file size */
654 /* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235775 */
655 TEST_F(WriteThrough, DISABLED_update_file_size)
657 const char FULLPATH[] = "mountpoint/some_file.txt";
658 const char RELPATH[] = "some_file.txt";
659 const char *CONTENTS = "abcdefgh";
663 ssize_t bufsize = strlen(CONTENTS);
665 expect_lookup(RELPATH, ino, 0);
666 expect_open(ino, 0, 1);
667 EXPECT_CALL(*m_mock, process(
668 ResultOf([=](auto in) {
669 return (in->header.opcode == FUSE_GETATTR &&
670 in->header.nodeid == ino);
674 .WillRepeatedly(Invoke(ReturnImmediate([=](auto in __unused, auto out) {
675 SET_OUT_HEADER_LEN(out, attr);
676 out->body.attr.attr.ino = ino; // Must match nodeid
677 out->body.attr.attr.mode = S_IFREG | 0644;
678 out->body.attr.attr.size = 0;
679 out->body.attr.attr_valid = UINT64_MAX;
681 expect_write(ino, 0, bufsize, bufsize, 0, CONTENTS);
683 fd = open(FULLPATH, O_RDWR);
684 EXPECT_LE(0, fd) << strerror(errno);
686 ASSERT_EQ(bufsize, write(fd, CONTENTS, bufsize)) << strerror(errno);
687 /* Get cached attributes */
688 ASSERT_EQ(0, fstat(fd, &sb)) << strerror(errno);
689 ASSERT_EQ(bufsize, sb.st_size);
690 /* Deliberately leak fd. close(2) will be tested in release.cc */