Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/fs/fusefs/release.cc
| Show All 23 Lines | |||||
| * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
| * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
| * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * 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 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
| * SUCH DAMAGE. | * SUCH DAMAGE. | ||||
| */ | */ | ||||
| extern "C" { | extern "C" { | ||||
| #include <sys/socket.h> | |||||
| #include <sys/un.h> | |||||
| #include <fcntl.h> | #include <fcntl.h> | ||||
| #include <unistd.h> | #include <unistd.h> | ||||
| } | } | ||||
| #include "mockfs.hh" | #include "mockfs.hh" | ||||
| #include "utils.hh" | #include "utils.hh" | ||||
| using namespace testing; | using namespace testing; | ||||
| ▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | TEST_F(Release, ok) | ||||
| expect_open(ino, 0, 1); | expect_open(ino, 0, 1); | ||||
| expect_flush(ino, 1, ReturnErrno(0)); | expect_flush(ino, 1, ReturnErrno(0)); | ||||
| expect_release(ino, getpid(), O_RDONLY, 0); | expect_release(ino, getpid(), O_RDONLY, 0); | ||||
| fd = open(FULLPATH, O_RDONLY); | fd = open(FULLPATH, O_RDONLY); | ||||
| ASSERT_LE(0, fd) << strerror(errno); | ASSERT_LE(0, fd) << strerror(errno); | ||||
| ASSERT_EQ(0, close(fd)) << strerror(errno); | ASSERT_EQ(0, close(fd)) << strerror(errno); | ||||
| } | |||||
| /* | |||||
| * Nothing bad should happen when closing a Unix-domain named socket that | |||||
| * contains a fusefs file descriptor within its receive buffer. | |||||
| * Regression test for | |||||
| * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=289686 | |||||
| */ | |||||
| TEST_F(Release, scm_rights) | |||||
| { | |||||
| const char FULLPATH[] = "mountpoint/some_file.txt"; | |||||
| const char RELPATH[] = "some_file.txt"; | |||||
| struct msghdr msg; | |||||
| struct iovec iov; | |||||
| char message[CMSG_SPACE(sizeof(int))]; | |||||
| uint64_t ino = 42; | |||||
| int fd; | |||||
| int s[2]; | |||||
| union { | |||||
| char buf[CMSG_SPACE(sizeof(fd))]; | |||||
| struct cmsghdr align; | |||||
| } u; | |||||
| expect_lookup(RELPATH, ino, 1); | |||||
| expect_open(ino, 0, 1); | |||||
| expect_flush(ino, 1, ReturnErrno(0)); | |||||
| expect_release(ino, getpid(), O_RDONLY, 0); | |||||
| ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, s)) << strerror(errno); | |||||
| fd = open(FULLPATH, O_RDONLY); | |||||
| ASSERT_LE(0, fd) << strerror(errno); | |||||
| memset(&message, 0, sizeof(message)); | |||||
| memset(&msg, 0, sizeof(msg)); | |||||
| iov.iov_base = NULL; | |||||
| iov.iov_len = 0; | |||||
| msg.msg_iov = &iov; | |||||
| msg.msg_iovlen = 1; | |||||
| msg.msg_control = u.buf, | |||||
| msg.msg_controllen = sizeof(u.buf); | |||||
| struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); | |||||
| cmsg->cmsg_level = SOL_SOCKET; | |||||
| cmsg->cmsg_type = SCM_RIGHTS; | |||||
| cmsg->cmsg_len = CMSG_LEN(sizeof(fd)); | |||||
| memcpy(CMSG_DATA(cmsg), &fd, sizeof(fd)); | |||||
| ASSERT_GE(sendmsg(s[0], &msg, 0), 0) << strerror(errno); | |||||
| close(fd); // Close fd within our process | |||||
| close(s[0]); | |||||
| close(s[1]); // The last copy of fd is within this socket's rcvbuf | |||||
| } | } | ||||
| /* When closing a file with a POSIX file lock, release should release the lock*/ | /* When closing a file with a POSIX file lock, release should release the lock*/ | ||||
| TEST_F(ReleaseWithLocks, unlock_on_close) | TEST_F(ReleaseWithLocks, unlock_on_close) | ||||
| { | { | ||||
| const char FULLPATH[] = "mountpoint/some_file.txt"; | const char FULLPATH[] = "mountpoint/some_file.txt"; | ||||
| const char RELPATH[] = "some_file.txt"; | const char RELPATH[] = "some_file.txt"; | ||||
| uint64_t ino = 42; | uint64_t ino = 42; | ||||
| Show All 39 Lines | |||||