svn commit: r346868 - in projects/fuse2: sys/fs/fuse tests/sys/fs/fusefs

Alan Somers asomers at FreeBSD.org
Mon Apr 29 01:40:37 UTC 2019


Author: asomers
Date: Mon Apr 29 01:40:35 2019
New Revision: 346868
URL: https://svnweb.freebsd.org/changeset/base/346868

Log:
  fusefs: FIFO support
  
  Sponsored by:	The FreeBSD Foundation

Added:
  projects/fuse2/tests/sys/fs/fusefs/fifo.cc   (contents, props changed)
Modified:
  projects/fuse2/sys/fs/fuse/fuse_main.c
  projects/fuse2/sys/fs/fuse/fuse_node.c
  projects/fuse2/sys/fs/fuse/fuse_node.h
  projects/fuse2/sys/fs/fuse/fuse_vnops.c
  projects/fuse2/tests/sys/fs/fusefs/Makefile

Modified: projects/fuse2/sys/fs/fuse/fuse_main.c
==============================================================================
--- projects/fuse2/sys/fs/fuse/fuse_main.c	Mon Apr 29 01:22:58 2019	(r346867)
+++ projects/fuse2/sys/fs/fuse/fuse_main.c	Mon Apr 29 01:40:35 2019	(r346868)
@@ -85,6 +85,7 @@ struct mtx fuse_mtx;
 
 extern struct vfsops fuse_vfsops;
 extern struct cdevsw fuse_cdevsw;
+extern struct vop_vector fuse_fifonops;
 extern struct vop_vector fuse_vnops;
 extern uma_zone_t fuse_pbuf_zone;
 

Modified: projects/fuse2/sys/fs/fuse/fuse_node.c
==============================================================================
--- projects/fuse2/sys/fs/fuse/fuse_node.c	Mon Apr 29 01:22:58 2019	(r346867)
+++ projects/fuse2/sys/fs/fuse/fuse_node.c	Mon Apr 29 01:40:35 2019	(r346868)
@@ -248,7 +248,14 @@ fuse_vnode_alloc(struct mount *mp,
 		return (0);
 	}
 	fvdat = malloc(sizeof(*fvdat), M_FUSEVN, M_WAITOK | M_ZERO);
-	err = getnewvnode("fuse", mp, &fuse_vnops, vpp);
+	switch (vtyp) {
+	case VFIFO:
+		err = getnewvnode("fuse", mp, &fuse_fifoops, vpp);
+		break;
+	default:
+		err = getnewvnode("fuse", mp, &fuse_vnops, vpp);
+		break;
+	}
 	if (err) {
 		free(fvdat, M_FUSEVN);
 		return (err);

Modified: projects/fuse2/sys/fs/fuse/fuse_node.h
==============================================================================
--- projects/fuse2/sys/fs/fuse/fuse_node.h	Mon Apr 29 01:22:58 2019	(r346867)
+++ projects/fuse2/sys/fs/fuse/fuse_node.h	Mon Apr 29 01:40:35 2019	(r346868)
@@ -114,6 +114,7 @@ VTOVA(struct vnode *vp)
 
 #define FUSE_NULL_ID 0
 
+extern struct vop_vector fuse_fifoops;
 extern struct vop_vector fuse_vnops;
 
 static inline void

Modified: projects/fuse2/sys/fs/fuse/fuse_vnops.c
==============================================================================
--- projects/fuse2/sys/fs/fuse/fuse_vnops.c	Mon Apr 29 01:22:58 2019	(r346867)
+++ projects/fuse2/sys/fs/fuse/fuse_vnops.c	Mon Apr 29 01:40:35 2019	(r346868)
@@ -120,6 +120,7 @@ SDT_PROBE_DEFINE2(fusefs, , vnops, trace, "int", "char
 /* vnode ops */
 static vop_access_t fuse_vnop_access;
 static vop_advlock_t fuse_vnop_advlock;
+static vop_close_t fuse_fifo_close;
 static vop_close_t fuse_vnop_close;
 static vop_create_t fuse_vnop_create;
 static vop_deleteextattr_t fuse_vnop_deleteextattr;
@@ -151,6 +152,21 @@ static vop_getpages_t fuse_vnop_getpages;
 static vop_putpages_t fuse_vnop_putpages;
 static vop_print_t fuse_vnop_print;
 
+struct vop_vector fuse_fifoops = {
+	.vop_default =		&fifo_specops,
+	.vop_access =		fuse_vnop_access,
+	.vop_close =		fuse_fifo_close,
+	.vop_fsync =		fuse_vnop_fsync,
+	.vop_getattr =		fuse_vnop_getattr,
+	.vop_inactive =		fuse_vnop_inactive,
+	.vop_pathconf =		fuse_vnop_pathconf,
+	.vop_print =		fuse_vnop_print,
+	.vop_read =		VOP_PANIC,
+	.vop_reclaim =		fuse_vnop_reclaim,
+	.vop_setattr =		fuse_vnop_setattr,
+	.vop_write =		VOP_PANIC,
+};
+
 struct vop_vector fuse_vnops = {
 	.vop_default = &default_vnodeops,
 	.vop_access = fuse_vnop_access,
@@ -290,6 +306,13 @@ fuse_flush(struct vnode *vp, struct ucred *cred, pid_t
 	}
 	fdisp_destroy(&fdi);
 	return err;
+}
+
+/* Close wrapper for fifos.  */
+static int
+fuse_fifo_close(struct vop_close_args *ap)
+{
+	return (fifo_specops.vop_close(ap));
 }
 
 /*

Modified: projects/fuse2/tests/sys/fs/fusefs/Makefile
==============================================================================
--- projects/fuse2/tests/sys/fs/fusefs/Makefile	Mon Apr 29 01:22:58 2019	(r346867)
+++ projects/fuse2/tests/sys/fs/fusefs/Makefile	Mon Apr 29 01:40:35 2019	(r346868)
@@ -12,6 +12,7 @@ GTESTS+=	allow_other
 GTESTS+=	create
 GTESTS+=	default_permissions
 GTESTS+=	destroy
+GTESTS+=	fifo
 GTESTS+=	flush
 GTESTS+=	fsync
 GTESTS+=	fsyncdir

Added: projects/fuse2/tests/sys/fs/fusefs/fifo.cc
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/fuse2/tests/sys/fs/fusefs/fifo.cc	Mon Apr 29 01:40:35 2019	(r346868)
@@ -0,0 +1,96 @@
+/*-
+ * 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 <sys/types.h>
+#include <fcntl.h>
+}
+
+#include "mockfs.hh"
+#include "utils.hh"
+
+using namespace testing;
+
+const char FULLPATH[] = "mountpoint/some_fifo";
+const char RELPATH[] = "some_fifo";
+const char MESSAGE[] = "Hello, World!\n";
+const int msgsize = sizeof(MESSAGE);
+
+class Fifo: public FuseTest {
+};
+
+/* Writer thread */
+static void* writer(void* arg) {
+	ssize_t sent = 0;
+	int fd;
+
+	fd = *(int*)arg;
+	while (sent < msgsize) {
+		ssize_t r;
+
+		r = write(fd, MESSAGE + sent, msgsize - sent);
+		if (r < 0)
+			return (void*)(intptr_t)errno;
+		else
+			sent += r;
+		
+	}
+	return 0;
+}
+
+/* 
+ * Reading and writing FIFOs works.  None of the I/O actually goes through FUSE
+ */
+TEST_F(Fifo, read_write)
+{
+	pthread_t th0;
+	mode_t mode = S_IFIFO | 0755;
+	const int bufsize = 80;
+	char message[bufsize];
+	ssize_t recvd = 0, r;
+	uint64_t ino = 42;
+	int fd;
+
+	expect_lookup(RELPATH, ino, mode, 0, 1);
+
+	fd = open(FULLPATH, O_RDWR);
+	ASSERT_LE(0, fd) << strerror(errno);
+	ASSERT_EQ(0, pthread_create(&th0, NULL, writer, &fd))
+		<< strerror(errno);
+	while (recvd < msgsize) {
+		r = read(fd, message + recvd, bufsize - recvd);
+		ASSERT_LE(0, r) << strerror(errno);
+		ASSERT_LT(0, r) << "unexpected EOF";
+		recvd += r;
+	}
+	ASSERT_STREQ(message, MESSAGE);
+
+	/* Deliberately leak fd */
+}


More information about the svn-src-projects mailing list