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
39 using namespace testing;
41 class Release: public FuseTest {
44 void expect_lookup(const char *relpath, uint64_t ino, int times)
46 FuseTest::expect_lookup(relpath, ino, S_IFREG | 0644, times);
50 // TODO: lock owner stuff
52 /* If a file descriptor is duplicated, only the last close causes RELEASE */
55 const char FULLPATH[] = "mountpoint/some_file.txt";
56 const char RELPATH[] = "some_file.txt";
60 expect_lookup(RELPATH, ino, 1);
61 expect_open(ino, 0, 1);
62 expect_getattr(ino, 0);
63 expect_release(ino, 1, 0);
65 fd = open(FULLPATH, O_RDONLY);
66 EXPECT_LE(0, fd) << strerror(errno);
70 ASSERT_EQ(0, close(fd2)) << strerror(errno);
71 ASSERT_EQ(0, close(fd)) << strerror(errno);
75 * Some FUSE filesystem cache data internally and flush it on release. Such
76 * filesystems may generate errors during release. On Linux, these get
77 * returned by close(2). However, POSIX does not require close(2) to return
78 * this error. FreeBSD's fuse(4) should return EIO if it returns an error at
81 /* http://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html */
84 const char FULLPATH[] = "mountpoint/some_file.txt";
85 const char RELPATH[] = "some_file.txt";
89 expect_lookup(RELPATH, ino, 1);
90 expect_open(ino, 0, 1);
91 expect_getattr(ino, 0);
92 expect_release(ino, 1, EIO);
94 fd = open(FULLPATH, O_WRONLY);
95 EXPECT_LE(0, fd) << strerror(errno);
97 ASSERT_TRUE(0 == close(fd) || errno == EIO) << strerror(errno);
101 * fuse(4) will issue multiple FUSE_OPEN operations for the same file if it's
102 * opened with different modes. Each FUSE_OPEN should get its own
105 TEST_F(Release, multiple_opens)
107 const char FULLPATH[] = "mountpoint/some_file.txt";
108 const char RELPATH[] = "some_file.txt";
112 expect_lookup(RELPATH, ino, 2);
113 expect_open(ino, 0, 2);
114 expect_getattr(ino, 0);
115 expect_release(ino, 2, 0);
117 fd = open(FULLPATH, O_RDONLY);
118 EXPECT_LE(0, fd) << strerror(errno);
120 fd2 = open(FULLPATH, O_WRONLY);
121 EXPECT_LE(0, fd2) << strerror(errno);
123 ASSERT_EQ(0, close(fd2)) << strerror(errno);
124 ASSERT_EQ(0, close(fd)) << strerror(errno);
129 const char FULLPATH[] = "mountpoint/some_file.txt";
130 const char RELPATH[] = "some_file.txt";
134 expect_lookup(RELPATH, ino, 1);
135 expect_open(ino, 0, 1);
136 expect_getattr(ino, 0);
137 expect_release(ino, 1, 0);
139 fd = open(FULLPATH, O_RDONLY);
140 EXPECT_LE(0, fd) << strerror(errno);
142 ASSERT_EQ(0, close(fd)) << strerror(errno);