22c213
From 9d3788b1c2fa5cb4f14e292232a05c6a5217802d Mon Sep 17 00:00:00 2001
22c213
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
Date: Mon, 27 Jan 2020 19:00:44 +0100
22c213
Subject: [PATCH 013/116] virtiofsd: Trim down imported files
22c213
MIME-Version: 1.0
22c213
Content-Type: text/plain; charset=UTF-8
22c213
Content-Transfer-Encoding: 8bit
22c213
22c213
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
Message-id: <20200127190227.40942-10-dgilbert@redhat.com>
22c213
Patchwork-id: 93463
22c213
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 009/112] virtiofsd: Trim down imported files
22c213
Bugzilla: 1694164
22c213
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
22c213
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
22c213
22c213
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
22c213
There's a lot of the original fuse code we don't need; trim them down.
22c213
22c213
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
with additional trimming by:
22c213
Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
22c213
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
22c213
Reviewed-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
22c213
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
(cherry picked from commit a3e23f325439a290c504d6bbc48c2e742149ecab)
22c213
22c213
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
22c213
---
22c213
 tools/virtiofsd/buffer.c              |  71 +---
22c213
 tools/virtiofsd/fuse.h                |  46 ---
22c213
 tools/virtiofsd/fuse_common.h         |  32 --
22c213
 tools/virtiofsd/fuse_i.h              |  41 ---
22c213
 tools/virtiofsd/fuse_log.h            |   8 -
22c213
 tools/virtiofsd/fuse_lowlevel.c       | 675 +---------------------------------
22c213
 tools/virtiofsd/fuse_lowlevel.h       |  28 --
22c213
 tools/virtiofsd/fuse_opt.h            |   8 -
22c213
 tools/virtiofsd/helper.c              | 143 -------
22c213
 tools/virtiofsd/passthrough_helpers.h |  26 --
22c213
 tools/virtiofsd/passthrough_ll.c      |   1 -
22c213
 11 files changed, 8 insertions(+), 1071 deletions(-)
22c213
22c213
diff --git a/tools/virtiofsd/buffer.c b/tools/virtiofsd/buffer.c
22c213
index 5ab9b87..aefb7db 100644
22c213
--- a/tools/virtiofsd/buffer.c
22c213
+++ b/tools/virtiofsd/buffer.c
22c213
@@ -157,73 +157,6 @@ static ssize_t fuse_buf_fd_to_fd(const struct fuse_buf *dst, size_t dst_off,
22c213
 	return copied;
22c213
 }
22c213
 
22c213
-#ifdef HAVE_SPLICE
22c213
-static ssize_t fuse_buf_splice(const struct fuse_buf *dst, size_t dst_off,
22c213
-			       const struct fuse_buf *src, size_t src_off,
22c213
-			       size_t len, enum fuse_buf_copy_flags flags)
22c213
-{
22c213
-	int splice_flags = 0;
22c213
-	off_t *srcpos = NULL;
22c213
-	off_t *dstpos = NULL;
22c213
-	off_t srcpos_val;
22c213
-	off_t dstpos_val;
22c213
-	ssize_t res;
22c213
-	size_t copied = 0;
22c213
-
22c213
-	if (flags & FUSE_BUF_SPLICE_MOVE)
22c213
-		splice_flags |= SPLICE_F_MOVE;
22c213
-	if (flags & FUSE_BUF_SPLICE_NONBLOCK)
22c213
-		splice_flags |= SPLICE_F_NONBLOCK;
22c213
-
22c213
-	if (src->flags & FUSE_BUF_FD_SEEK) {
22c213
-		srcpos_val = src->pos + src_off;
22c213
-		srcpos = &srcpos_val;
22c213
-	}
22c213
-	if (dst->flags & FUSE_BUF_FD_SEEK) {
22c213
-		dstpos_val = dst->pos + dst_off;
22c213
-		dstpos = &dstpos_val;
22c213
-	}
22c213
-
22c213
-	while (len) {
22c213
-		res = splice(src->fd, srcpos, dst->fd, dstpos, len,
22c213
-			     splice_flags);
22c213
-		if (res == -1) {
22c213
-			if (copied)
22c213
-				break;
22c213
-
22c213
-			if (errno != EINVAL || (flags & FUSE_BUF_FORCE_SPLICE))
22c213
-				return -errno;
22c213
-
22c213
-			/* Maybe splice is not supported for this combination */
22c213
-			return fuse_buf_fd_to_fd(dst, dst_off, src, src_off,
22c213
-						 len);
22c213
-		}
22c213
-		if (res == 0)
22c213
-			break;
22c213
-
22c213
-		copied += res;
22c213
-		if (!(src->flags & FUSE_BUF_FD_RETRY) &&
22c213
-		    !(dst->flags & FUSE_BUF_FD_RETRY)) {
22c213
-			break;
22c213
-		}
22c213
-
22c213
-		len -= res;
22c213
-	}
22c213
-
22c213
-	return copied;
22c213
-}
22c213
-#else
22c213
-static ssize_t fuse_buf_splice(const struct fuse_buf *dst, size_t dst_off,
22c213
-			       const struct fuse_buf *src, size_t src_off,
22c213
-			       size_t len, enum fuse_buf_copy_flags flags)
22c213
-{
22c213
-	(void) flags;
22c213
-
22c213
-	return fuse_buf_fd_to_fd(dst, dst_off, src, src_off, len);
22c213
-}
22c213
-#endif
22c213
-
22c213
-
22c213
 static ssize_t fuse_buf_copy_one(const struct fuse_buf *dst, size_t dst_off,
22c213
 				 const struct fuse_buf *src, size_t src_off,
22c213
 				 size_t len, enum fuse_buf_copy_flags flags)
22c213
@@ -247,10 +180,8 @@ static ssize_t fuse_buf_copy_one(const struct fuse_buf *dst, size_t dst_off,
22c213
 		return fuse_buf_write(dst, dst_off, src, src_off, len);
22c213
 	} else if (!dst_is_fd) {
22c213
 		return fuse_buf_read(dst, dst_off, src, src_off, len);
22c213
-	} else if (flags & FUSE_BUF_NO_SPLICE) {
22c213
-		return fuse_buf_fd_to_fd(dst, dst_off, src, src_off, len);
22c213
 	} else {
22c213
-		return fuse_buf_splice(dst, dst_off, src, src_off, len, flags);
22c213
+		return fuse_buf_fd_to_fd(dst, dst_off, src, src_off, len);
22c213
 	}
22c213
 }
22c213
 
22c213
diff --git a/tools/virtiofsd/fuse.h b/tools/virtiofsd/fuse.h
22c213
index 883f6e5..3202fba 100644
22c213
--- a/tools/virtiofsd/fuse.h
22c213
+++ b/tools/virtiofsd/fuse.h
22c213
@@ -25,10 +25,6 @@
22c213
 #include <sys/statvfs.h>
22c213
 #include <sys/uio.h>
22c213
 
22c213
-#ifdef __cplusplus
22c213
-extern "C" {
22c213
-#endif
22c213
-
22c213
 /* ----------------------------------------------------------- *
22c213
  * Basic FUSE API					       *
22c213
  * ----------------------------------------------------------- */
22c213
@@ -979,44 +975,6 @@ int fuse_loop(struct fuse *f);
22c213
 void fuse_exit(struct fuse *f);
22c213
 
22c213
 /**
22c213
- * FUSE event loop with multiple threads
22c213
- *
22c213
- * Requests from the kernel are processed, and the appropriate
22c213
- * operations are called.  Request are processed in parallel by
22c213
- * distributing them between multiple threads.
22c213
- *
22c213
- * For a description of the return value and the conditions when the
22c213
- * event loop exits, refer to the documentation of
22c213
- * fuse_session_loop().
22c213
- *
22c213
- * Note: using fuse_loop() instead of fuse_loop_mt() means you are running in
22c213
- * single-threaded mode, and that you will not have to worry about reentrancy,
22c213
- * though you will have to worry about recursive lookups. In single-threaded
22c213
- * mode, FUSE will wait for one callback to return before calling another.
22c213
- *
22c213
- * Enabling multiple threads, by using fuse_loop_mt(), will cause FUSE to make
22c213
- * multiple simultaneous calls into the various callback functions given by your
22c213
- * fuse_operations record.
22c213
- *
22c213
- * If you are using multiple threads, you can enjoy all the parallel execution
22c213
- * and interactive response benefits of threads, and you get to enjoy all the
22c213
- * benefits of race conditions and locking bugs, too. Ensure that any code used
22c213
- * in the callback function of fuse_operations is also thread-safe.
22c213
- *
22c213
- * @param f the FUSE handle
22c213
- * @param config loop configuration
22c213
- * @return see fuse_session_loop()
22c213
- *
22c213
- * See also: fuse_loop()
22c213
- */
22c213
-#if FUSE_USE_VERSION < 32
22c213
-int fuse_loop_mt_31(struct fuse *f, int clone_fd);
22c213
-#define fuse_loop_mt(f, clone_fd) fuse_loop_mt_31(f, clone_fd)
22c213
-#else
22c213
-int fuse_loop_mt(struct fuse *f, struct fuse_loop_config *config);
22c213
-#endif
22c213
-
22c213
-/**
22c213
  * Get the current context
22c213
  *
22c213
  * The context is only valid for the duration of a filesystem
22c213
@@ -1268,8 +1226,4 @@ struct fuse_session *fuse_get_session(struct fuse *f);
22c213
  */
22c213
 int fuse_open_channel(const char *mountpoint, const char *options);
22c213
 
22c213
-#ifdef __cplusplus
22c213
-}
22c213
-#endif
22c213
-
22c213
 #endif /* FUSE_H_ */
22c213
diff --git a/tools/virtiofsd/fuse_common.h b/tools/virtiofsd/fuse_common.h
22c213
index 2d686b2..bf8f8cc 100644
22c213
--- a/tools/virtiofsd/fuse_common.h
22c213
+++ b/tools/virtiofsd/fuse_common.h
22c213
@@ -28,10 +28,6 @@
22c213
 #define FUSE_MAKE_VERSION(maj, min)  ((maj) * 10 + (min))
22c213
 #define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
22c213
 
22c213
-#ifdef __cplusplus
22c213
-extern "C" {
22c213
-#endif
22c213
-
22c213
 /**
22c213
  * Information about an open file.
22c213
  *
22c213
@@ -100,30 +96,6 @@ struct fuse_file_info {
22c213
 	uint32_t poll_events;
22c213
 };
22c213
 
22c213
-/**
22c213
- * Configuration parameters passed to fuse_session_loop_mt() and
22c213
- * fuse_loop_mt().
22c213
- */
22c213
-struct fuse_loop_config {
22c213
-	/**
22c213
-	 * whether to use separate device fds for each thread
22c213
-	 * (may increase performance)
22c213
-	 */
22c213
-	int clone_fd;
22c213
-
22c213
-	/**
22c213
-	 * The maximum number of available worker threads before they
22c213
-	 * start to get deleted when they become idle. If not
22c213
-	 * specified, the default is 10.
22c213
-	 *
22c213
-	 * Adjusting this has performance implications; a very small number
22c213
-	 * of threads in the pool will cause a lot of thread creation and
22c213
-	 * deletion overhead and performance may suffer. When set to 0, a new
22c213
-	 * thread will be created to service every operation.
22c213
-	 */
22c213
-	unsigned int max_idle_threads;
22c213
-};
22c213
-
22c213
 /**************************************************************************
22c213
  * Capability bits for 'fuse_conn_info.capable' and 'fuse_conn_info.want' *
22c213
  **************************************************************************/
22c213
@@ -802,10 +774,6 @@ void fuse_remove_signal_handlers(struct fuse_session *se);
22c213
 #  error only API version 30 or greater is supported
22c213
 #endif
22c213
 
22c213
-#ifdef __cplusplus
22c213
-}
22c213
-#endif
22c213
-
22c213
 
22c213
 /*
22c213
  * This interface uses 64 bit off_t.
22c213
diff --git a/tools/virtiofsd/fuse_i.h b/tools/virtiofsd/fuse_i.h
22c213
index d38b630..b39522e 100644
22c213
--- a/tools/virtiofsd/fuse_i.h
22c213
+++ b/tools/virtiofsd/fuse_i.h
22c213
@@ -9,8 +9,6 @@
22c213
 #include "fuse.h"
22c213
 #include "fuse_lowlevel.h"
22c213
 
22c213
-struct mount_opts;
22c213
-
22c213
 struct fuse_req {
22c213
 	struct fuse_session *se;
22c213
 	uint64_t unique;
22c213
@@ -45,7 +43,6 @@ struct fuse_session {
22c213
 	char *mountpoint;
22c213
 	volatile int exited;
22c213
 	int fd;
22c213
-	struct mount_opts *mo;
22c213
 	int debug;
22c213
 	int deny_others;
22c213
 	struct fuse_lowlevel_ops op;
22c213
@@ -58,7 +55,6 @@ struct fuse_session {
22c213
 	struct fuse_req interrupts;
22c213
 	pthread_mutex_t lock;
22c213
 	int got_destroy;
22c213
-	pthread_key_t pipe_key;
22c213
 	int broken_splice_nonblock;
22c213
 	uint64_t notify_ctr;
22c213
 	struct fuse_notify_req notify_list;
22c213
@@ -87,53 +83,16 @@ struct fuse_module {
22c213
 	int ctr;
22c213
 };
22c213
 
22c213
-/* ----------------------------------------------------------- *
22c213
- * Channel interface (when using -o clone_fd)		       *
22c213
- * ----------------------------------------------------------- */
22c213
-
22c213
-/**
22c213
- * Obtain counted reference to the channel
22c213
- *
22c213
- * @param ch the channel
22c213
- * @return the channel
22c213
- */
22c213
-struct fuse_chan *fuse_chan_get(struct fuse_chan *ch);
22c213
-
22c213
-/**
22c213
- * Drop counted reference to a channel
22c213
- *
22c213
- * @param ch the channel
22c213
- */
22c213
-void fuse_chan_put(struct fuse_chan *ch);
22c213
-
22c213
-struct mount_opts *parse_mount_opts(struct fuse_args *args);
22c213
-void destroy_mount_opts(struct mount_opts *mo);
22c213
-void fuse_mount_version(void);
22c213
-unsigned get_max_read(struct mount_opts *o);
22c213
-void fuse_kern_unmount(const char *mountpoint, int fd);
22c213
-int fuse_kern_mount(const char *mountpoint, struct mount_opts *mo);
22c213
-
22c213
 int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
22c213
 			       int count);
22c213
 void fuse_free_req(fuse_req_t req);
22c213
 
22c213
-void cuse_lowlevel_init(fuse_req_t req, fuse_ino_t nodeide, const void *inarg);
22c213
-
22c213
-int fuse_start_thread(pthread_t *thread_id, void *(*func)(void *), void *arg);
22c213
-
22c213
-int fuse_session_receive_buf_int(struct fuse_session *se, struct fuse_buf *buf,
22c213
-				 struct fuse_chan *ch);
22c213
 void fuse_session_process_buf_int(struct fuse_session *se,
22c213
 				  const struct fuse_buf *buf, struct fuse_chan *ch);
22c213
 
22c213
-struct fuse *fuse_new_31(struct fuse_args *args, const struct fuse_operations *op,
22c213
-		      size_t op_size, void *private_data);
22c213
-int fuse_loop_mt_32(struct fuse *f, struct fuse_loop_config *config);
22c213
-int fuse_session_loop_mt_32(struct fuse_session *se, struct fuse_loop_config *config);
22c213
 
22c213
 #define FUSE_MAX_MAX_PAGES 256
22c213
 #define FUSE_DEFAULT_MAX_PAGES_PER_REQ 32
22c213
 
22c213
 /* room needed in buffer to accommodate header */
22c213
 #define FUSE_BUFFER_HEADER_SIZE 0x1000
22c213
-
22c213
diff --git a/tools/virtiofsd/fuse_log.h b/tools/virtiofsd/fuse_log.h
22c213
index 5e112e0..0af700d 100644
22c213
--- a/tools/virtiofsd/fuse_log.h
22c213
+++ b/tools/virtiofsd/fuse_log.h
22c213
@@ -16,10 +16,6 @@
22c213
 
22c213
 #include <stdarg.h>
22c213
 
22c213
-#ifdef __cplusplus
22c213
-extern "C" {
22c213
-#endif
22c213
-
22c213
 /**
22c213
  * Log severity level
22c213
  *
22c213
@@ -75,8 +71,4 @@ void fuse_set_log_func(fuse_log_func_t func);
22c213
  */
22c213
 void fuse_log(enum fuse_log_level level, const char *fmt, ...);
22c213
 
22c213
-#ifdef __cplusplus
22c213
-}
22c213
-#endif
22c213
-
22c213
 #endif /* FUSE_LOG_H_ */
22c213
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
22c213
index f2d7038..e6fa247 100644
22c213
--- a/tools/virtiofsd/fuse_lowlevel.c
22c213
+++ b/tools/virtiofsd/fuse_lowlevel.c
22c213
@@ -16,7 +16,6 @@
22c213
 #include "fuse_kernel.h"
22c213
 #include "fuse_opt.h"
22c213
 #include "fuse_misc.h"
22c213
-#include "mount_util.h"
22c213
 
22c213
 #include <stdio.h>
22c213
 #include <stdlib.h>
22c213
@@ -28,12 +27,6 @@
22c213
 #include <assert.h>
22c213
 #include <sys/file.h>
22c213
 
22c213
-#ifndef F_LINUX_SPECIFIC_BASE
22c213
-#define F_LINUX_SPECIFIC_BASE       1024
22c213
-#endif
22c213
-#ifndef F_SETPIPE_SZ
22c213
-#define F_SETPIPE_SZ	(F_LINUX_SPECIFIC_BASE + 7)
22c213
-#endif
22c213
 
22c213
 
22c213
 #define PARAM(inarg) (((char *)(inarg)) + sizeof(*(inarg)))
22c213
@@ -137,7 +130,6 @@ void fuse_free_req(fuse_req_t req)
22c213
 	req->u.ni.data = NULL;
22c213
 	list_del_req(req);
22c213
 	ctr = --req->ctr;
22c213
-	fuse_chan_put(req->ch);
22c213
 	req->ch = NULL;
22c213
 	pthread_mutex_unlock(&se->lock);
22c213
 	if (!ctr)
22c213
@@ -184,19 +176,7 @@ static int fuse_send_msg(struct fuse_session *se, struct fuse_chan *ch,
22c213
 		}
22c213
 	}
22c213
 
22c213
-	ssize_t res = writev(ch ? ch->fd : se->fd,
22c213
-			     iov, count);
22c213
-	int err = errno;
22c213
-
22c213
-	if (res == -1) {
22c213
-		assert(se != NULL);
22c213
-
22c213
-		/* ENOENT means the operation was interrupted */
22c213
-		if (!fuse_session_exited(se) && err != ENOENT)
22c213
-			perror("fuse: writing device");
22c213
-		return -err;
22c213
-	}
22c213
-
22c213
+	abort(); /* virtio should have taken it before here */
22c213
 	return 0;
22c213
 }
22c213
 
22c213
@@ -480,10 +460,6 @@ static int fuse_send_data_iov_fallback(struct fuse_session *se,
22c213
 				       struct fuse_bufvec *buf,
22c213
 				       size_t len)
22c213
 {
22c213
-	struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len);
22c213
-	void *mbuf;
22c213
-	int res;
22c213
-
22c213
 	/* Optimize common case */
22c213
 	if (buf->count == 1 && buf->idx == 0 && buf->off == 0 &&
22c213
 	    !(buf->buf[0].flags & FUSE_BUF_IS_FD)) {
22c213
@@ -496,350 +472,10 @@ static int fuse_send_data_iov_fallback(struct fuse_session *se,
22c213
 		return fuse_send_msg(se, ch, iov, iov_count);
22c213
 	}
22c213
 
22c213
-	res = posix_memalign(&mbuf, pagesize, len);
22c213
-	if (res != 0)
22c213
-		return res;
22c213
-
22c213
-	mem_buf.buf[0].mem = mbuf;
22c213
-	res = fuse_buf_copy(&mem_buf, buf, 0);
22c213
-	if (res < 0) {
22c213
-		free(mbuf);
22c213
-		return -res;
22c213
-	}
22c213
-	len = res;
22c213
-
22c213
-	iov[iov_count].iov_base = mbuf;
22c213
-	iov[iov_count].iov_len = len;
22c213
-	iov_count++;
22c213
-	res = fuse_send_msg(se, ch, iov, iov_count);
22c213
-	free(mbuf);
22c213
-
22c213
-	return res;
22c213
-}
22c213
-
22c213
-struct fuse_ll_pipe {
22c213
-	size_t size;
22c213
-	int can_grow;
22c213
-	int pipe[2];
22c213
-};
22c213
-
22c213
-static void fuse_ll_pipe_free(struct fuse_ll_pipe *llp)
22c213
-{
22c213
-	close(llp->pipe[0]);
22c213
-	close(llp->pipe[1]);
22c213
-	free(llp);
22c213
-}
22c213
-
22c213
-#ifdef HAVE_SPLICE
22c213
-#if !defined(HAVE_PIPE2) || !defined(O_CLOEXEC)
22c213
-static int fuse_pipe(int fds[2])
22c213
-{
22c213
-	int rv = pipe(fds);
22c213
-
22c213
-	if (rv == -1)
22c213
-		return rv;
22c213
-
22c213
-	if (fcntl(fds[0], F_SETFL, O_NONBLOCK) == -1 ||
22c213
-	    fcntl(fds[1], F_SETFL, O_NONBLOCK) == -1 ||
22c213
-	    fcntl(fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
22c213
-	    fcntl(fds[1], F_SETFD, FD_CLOEXEC) == -1) {
22c213
-		close(fds[0]);
22c213
-		close(fds[1]);
22c213
-		rv = -1;
22c213
-	}
22c213
-	return rv;
22c213
-}
22c213
-#else
22c213
-static int fuse_pipe(int fds[2])
22c213
-{
22c213
-	return pipe2(fds, O_CLOEXEC | O_NONBLOCK);
22c213
-}
22c213
-#endif
22c213
-
22c213
-static struct fuse_ll_pipe *fuse_ll_get_pipe(struct fuse_session *se)
22c213
-{
22c213
-	struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
22c213
-	if (llp == NULL) {
22c213
-		int res;
22c213
-
22c213
-		llp = malloc(sizeof(struct fuse_ll_pipe));
22c213
-		if (llp == NULL)
22c213
-			return NULL;
22c213
-
22c213
-		res = fuse_pipe(llp->pipe);
22c213
-		if (res == -1) {
22c213
-			free(llp);
22c213
-			return NULL;
22c213
-		}
22c213
-
22c213
-		/*
22c213
-		 *the default size is 16 pages on linux
22c213
-		 */
22c213
-		llp->size = pagesize * 16;
22c213
-		llp->can_grow = 1;
22c213
-
22c213
-		pthread_setspecific(se->pipe_key, llp);
22c213
-	}
22c213
-
22c213
-	return llp;
22c213
-}
22c213
-#endif
22c213
-
22c213
-static void fuse_ll_clear_pipe(struct fuse_session *se)
22c213
-{
22c213
-	struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
22c213
-	if (llp) {
22c213
-		pthread_setspecific(se->pipe_key, NULL);
22c213
-		fuse_ll_pipe_free(llp);
22c213
-	}
22c213
-}
22c213
-
22c213
-#if defined(HAVE_SPLICE) && defined(HAVE_VMSPLICE)
22c213
-static int read_back(int fd, char *buf, size_t len)
22c213
-{
22c213
-	int res;
22c213
-
22c213
-	res = read(fd, buf, len);
22c213
-	if (res == -1) {
22c213
-		fuse_log(FUSE_LOG_ERR, "fuse: internal error: failed to read back from pipe: %s\n", strerror(errno));
22c213
-		return -EIO;
22c213
-	}
22c213
-	if (res != len) {
22c213
-		fuse_log(FUSE_LOG_ERR, "fuse: internal error: short read back from pipe: %i from %zi\n", res, len);
22c213
-		return -EIO;
22c213
-	}
22c213
+	abort(); /* Will have taken vhost path */
22c213
 	return 0;
22c213
 }
22c213
 
22c213
-static int grow_pipe_to_max(int pipefd)
22c213
-{
22c213
-	int max;
22c213
-	int res;
22c213
-	int maxfd;
22c213
-	char buf[32];
22c213
-
22c213
-	maxfd = open("/proc/sys/fs/pipe-max-size", O_RDONLY);
22c213
-	if (maxfd < 0)
22c213
-		return -errno;
22c213
-
22c213
-	res = read(maxfd, buf, sizeof(buf) - 1);
22c213
-	if (res < 0) {
22c213
-		int saved_errno;
22c213
-
22c213
-		saved_errno = errno;
22c213
-		close(maxfd);
22c213
-		return -saved_errno;
22c213
-	}
22c213
-	close(maxfd);
22c213
-	buf[res] = '\0';
22c213
-
22c213
-	max = atoi(buf);
22c213
-	res = fcntl(pipefd, F_SETPIPE_SZ, max);
22c213
-	if (res < 0)
22c213
-		return -errno;
22c213
-	return max;
22c213
-}
22c213
-
22c213
-static int fuse_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
22c213
-			       struct iovec *iov, int iov_count,
22c213
-			       struct fuse_bufvec *buf, unsigned int flags)
22c213
-{
22c213
-	int res;
22c213
-	size_t len = fuse_buf_size(buf);
22c213
-	struct fuse_out_header *out = iov[0].iov_base;
22c213
-	struct fuse_ll_pipe *llp;
22c213
-	int splice_flags;
22c213
-	size_t pipesize;
22c213
-	size_t total_fd_size;
22c213
-	size_t idx;
22c213
-	size_t headerlen;
22c213
-	struct fuse_bufvec pipe_buf = FUSE_BUFVEC_INIT(len);
22c213
-
22c213
-	if (se->broken_splice_nonblock)
22c213
-		goto fallback;
22c213
-
22c213
-	if (flags & FUSE_BUF_NO_SPLICE)
22c213
-		goto fallback;
22c213
-
22c213
-	total_fd_size = 0;
22c213
-	for (idx = buf->idx; idx < buf->count; idx++) {
22c213
-		if (buf->buf[idx].flags & FUSE_BUF_IS_FD) {
22c213
-			total_fd_size = buf->buf[idx].size;
22c213
-			if (idx == buf->idx)
22c213
-				total_fd_size -= buf->off;
22c213
-		}
22c213
-	}
22c213
-	if (total_fd_size < 2 * pagesize)
22c213
-		goto fallback;
22c213
-
22c213
-	if (se->conn.proto_minor < 14 ||
22c213
-	    !(se->conn.want & FUSE_CAP_SPLICE_WRITE))
22c213
-		goto fallback;
22c213
-
22c213
-	llp = fuse_ll_get_pipe(se);
22c213
-	if (llp == NULL)
22c213
-		goto fallback;
22c213
-
22c213
-
22c213
-	headerlen = iov_length(iov, iov_count);
22c213
-
22c213
-	out->len = headerlen + len;
22c213
-
22c213
-	/*
22c213
-	 * Heuristic for the required pipe size, does not work if the
22c213
-	 * source contains less than page size fragments
22c213
-	 */
22c213
-	pipesize = pagesize * (iov_count + buf->count + 1) + out->len;
22c213
-
22c213
-	if (llp->size < pipesize) {
22c213
-		if (llp->can_grow) {
22c213
-			res = fcntl(llp->pipe[0], F_SETPIPE_SZ, pipesize);
22c213
-			if (res == -1) {
22c213
-				res = grow_pipe_to_max(llp->pipe[0]);
22c213
-				if (res > 0)
22c213
-					llp->size = res;
22c213
-				llp->can_grow = 0;
22c213
-				goto fallback;
22c213
-			}
22c213
-			llp->size = res;
22c213
-		}
22c213
-		if (llp->size < pipesize)
22c213
-			goto fallback;
22c213
-	}
22c213
-
22c213
-
22c213
-	res = vmsplice(llp->pipe[1], iov, iov_count, SPLICE_F_NONBLOCK);
22c213
-	if (res == -1)
22c213
-		goto fallback;
22c213
-
22c213
-	if (res != headerlen) {
22c213
-		res = -EIO;
22c213
-		fuse_log(FUSE_LOG_ERR, "fuse: short vmsplice to pipe: %u/%zu\n", res,
22c213
-			headerlen);
22c213
-		goto clear_pipe;
22c213
-	}
22c213
-
22c213
-	pipe_buf.buf[0].flags = FUSE_BUF_IS_FD;
22c213
-	pipe_buf.buf[0].fd = llp->pipe[1];
22c213
-
22c213
-	res = fuse_buf_copy(&pipe_buf, buf,
22c213
-			    FUSE_BUF_FORCE_SPLICE | FUSE_BUF_SPLICE_NONBLOCK);
22c213
-	if (res < 0) {
22c213
-		if (res == -EAGAIN || res == -EINVAL) {
22c213
-			/*
22c213
-			 * Should only get EAGAIN on kernels with
22c213
-			 * broken SPLICE_F_NONBLOCK support (<=
22c213
-			 * 2.6.35) where this error or a short read is
22c213
-			 * returned even if the pipe itself is not
22c213
-			 * full
22c213
-			 *
22c213
-			 * EINVAL might mean that splice can't handle
22c213
-			 * this combination of input and output.
22c213
-			 */
22c213
-			if (res == -EAGAIN)
22c213
-				se->broken_splice_nonblock = 1;
22c213
-
22c213
-			pthread_setspecific(se->pipe_key, NULL);
22c213
-			fuse_ll_pipe_free(llp);
22c213
-			goto fallback;
22c213
-		}
22c213
-		res = -res;
22c213
-		goto clear_pipe;
22c213
-	}
22c213
-
22c213
-	if (res != 0 && res < len) {
22c213
-		struct fuse_bufvec mem_buf = FUSE_BUFVEC_INIT(len);
22c213
-		void *mbuf;
22c213
-		size_t now_len = res;
22c213
-		/*
22c213
-		 * For regular files a short count is either
22c213
-		 *  1) due to EOF, or
22c213
-		 *  2) because of broken SPLICE_F_NONBLOCK (see above)
22c213
-		 *
22c213
-		 * For other inputs it's possible that we overflowed
22c213
-		 * the pipe because of small buffer fragments.
22c213
-		 */
22c213
-
22c213
-		res = posix_memalign(&mbuf, pagesize, len);
22c213
-		if (res != 0)
22c213
-			goto clear_pipe;
22c213
-
22c213
-		mem_buf.buf[0].mem = mbuf;
22c213
-		mem_buf.off = now_len;
22c213
-		res = fuse_buf_copy(&mem_buf, buf, 0);
22c213
-		if (res > 0) {
22c213
-			char *tmpbuf;
22c213
-			size_t extra_len = res;
22c213
-			/*
22c213
-			 * Trickiest case: got more data.  Need to get
22c213
-			 * back the data from the pipe and then fall
22c213
-			 * back to regular write.
22c213
-			 */
22c213
-			tmpbuf = malloc(headerlen);
22c213
-			if (tmpbuf == NULL) {
22c213
-				free(mbuf);
22c213
-				res = ENOMEM;
22c213
-				goto clear_pipe;
22c213
-			}
22c213
-			res = read_back(llp->pipe[0], tmpbuf, headerlen);
22c213
-			free(tmpbuf);
22c213
-			if (res != 0) {
22c213
-				free(mbuf);
22c213
-				goto clear_pipe;
22c213
-			}
22c213
-			res = read_back(llp->pipe[0], mbuf, now_len);
22c213
-			if (res != 0) {
22c213
-				free(mbuf);
22c213
-				goto clear_pipe;
22c213
-			}
22c213
-			len = now_len + extra_len;
22c213
-			iov[iov_count].iov_base = mbuf;
22c213
-			iov[iov_count].iov_len = len;
22c213
-			iov_count++;
22c213
-			res = fuse_send_msg(se, ch, iov, iov_count);
22c213
-			free(mbuf);
22c213
-			return res;
22c213
-		}
22c213
-		free(mbuf);
22c213
-		res = now_len;
22c213
-	}
22c213
-	len = res;
22c213
-	out->len = headerlen + len;
22c213
-
22c213
-	if (se->debug) {
22c213
-		fuse_log(FUSE_LOG_DEBUG,
22c213
-			"   unique: %llu, success, outsize: %i (splice)\n",
22c213
-			(unsigned long long) out->unique, out->len);
22c213
-	}
22c213
-
22c213
-	splice_flags = 0;
22c213
-	if ((flags & FUSE_BUF_SPLICE_MOVE) &&
22c213
-	    (se->conn.want & FUSE_CAP_SPLICE_MOVE))
22c213
-		splice_flags |= SPLICE_F_MOVE;
22c213
-
22c213
-	res = splice(llp->pipe[0], NULL, ch ? ch->fd : se->fd,
22c213
-		     NULL, out->len, splice_flags);
22c213
-	if (res == -1) {
22c213
-		res = -errno;
22c213
-		perror("fuse: splice from pipe");
22c213
-		goto clear_pipe;
22c213
-	}
22c213
-	if (res != out->len) {
22c213
-		res = -EIO;
22c213
-		fuse_log(FUSE_LOG_ERR, "fuse: short splice from pipe: %u/%u\n",
22c213
-			res, out->len);
22c213
-		goto clear_pipe;
22c213
-	}
22c213
-	return 0;
22c213
-
22c213
-clear_pipe:
22c213
-	fuse_ll_clear_pipe(se);
22c213
-	return res;
22c213
-
22c213
-fallback:
22c213
-	return fuse_send_data_iov_fallback(se, ch, iov, iov_count, buf, len);
22c213
-}
22c213
-#else
22c213
 static int fuse_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
22c213
 			       struct iovec *iov, int iov_count,
22c213
 			       struct fuse_bufvec *buf, unsigned int flags)
22c213
@@ -849,7 +485,6 @@ static int fuse_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
22c213
 
22c213
 	return fuse_send_data_iov_fallback(se, ch, iov, iov_count, buf, len);
22c213
 }
22c213
-#endif
22c213
 
22c213
 int fuse_reply_data(fuse_req_t req, struct fuse_bufvec *bufv,
22c213
 		    enum fuse_buf_copy_flags flags)
22c213
@@ -1408,16 +1043,11 @@ static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid, const void *inarg,
22c213
 	if (bufv.buf[0].size < arg->size) {
22c213
 		fuse_log(FUSE_LOG_ERR, "fuse: do_write_buf: buffer size too small\n");
22c213
 		fuse_reply_err(req, EIO);
22c213
-		goto out;
22c213
+		return;
22c213
 	}
22c213
 	bufv.buf[0].size = arg->size;
22c213
 
22c213
 	se->op.write_buf(req, nodeid, &bufv, arg->offset, &fi);
22c213
-
22c213
-out:
22c213
-	/* Need to reset the pipe if ->write_buf() didn't consume all data */
22c213
-	if ((ibuf->flags & FUSE_BUF_IS_FD) && bufv.idx < bufv.count)
22c213
-		fuse_ll_clear_pipe(se);
22c213
 }
22c213
 
22c213
 static void do_flush(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
@@ -2038,17 +1668,6 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
 		return;
22c213
 	}
22c213
 
22c213
-	unsigned max_read_mo = get_max_read(se->mo);
22c213
-	if (se->conn.max_read != max_read_mo) {
22c213
-		fuse_log(FUSE_LOG_ERR, "fuse: error: init() and fuse_session_new() "
22c213
-			"requested different maximum read size (%u vs %u)\n",
22c213
-			se->conn.max_read, max_read_mo);
22c213
-		fuse_reply_err(req, EPROTO);
22c213
-		se->error = -EPROTO;
22c213
-		fuse_session_exit(se);
22c213
-		return;
22c213
-	}
22c213
-
22c213
 	if (se->conn.max_write < bufsize - FUSE_BUFFER_HEADER_SIZE) {
22c213
 		se->bufsize = se->conn.max_write + FUSE_BUFFER_HEADER_SIZE;
22c213
 	}
22c213
@@ -2364,8 +1983,6 @@ static void fuse_ll_retrieve_reply(struct fuse_notify_req *nreq,
22c213
 	}
22c213
 out:
22c213
 	free(rreq);
22c213
-	if ((ibuf->flags & FUSE_BUF_IS_FD) && bufv.idx < bufv.count)
22c213
-		fuse_ll_clear_pipe(se);
22c213
 }
22c213
 
22c213
 int fuse_lowlevel_notify_retrieve(struct fuse_session *se, fuse_ino_t ino,
22c213
@@ -2496,7 +2113,6 @@ static struct {
22c213
 	[FUSE_RENAME2]     = { do_rename2,      "RENAME2"    },
22c213
 	[FUSE_COPY_FILE_RANGE] = { do_copy_file_range, "COPY_FILE_RANGE" },
22c213
 	[FUSE_LSEEK]	   = { do_lseek,       "LSEEK"	     },
22c213
-	[CUSE_INIT]	   = { cuse_lowlevel_init, "CUSE_INIT"   },
22c213
 };
22c213
 
22c213
 #define FUSE_MAXOP (sizeof(fuse_ll_ops) / sizeof(fuse_ll_ops[0]))
22c213
@@ -2509,21 +2125,6 @@ static const char *opname(enum fuse_opcode opcode)
22c213
 		return fuse_ll_ops[opcode].name;
22c213
 }
22c213
 
22c213
-static int fuse_ll_copy_from_pipe(struct fuse_bufvec *dst,
22c213
-				  struct fuse_bufvec *src)
22c213
-{
22c213
-	ssize_t res = fuse_buf_copy(dst, src, 0);
22c213
-	if (res < 0) {
22c213
-		fuse_log(FUSE_LOG_ERR, "fuse: copy from pipe: %s\n", strerror(-res));
22c213
-		return res;
22c213
-	}
22c213
-	if ((size_t)res < fuse_buf_size(dst)) {
22c213
-		fuse_log(FUSE_LOG_ERR, "fuse: copy from pipe: short read\n");
22c213
-		return -1;
22c213
-	}
22c213
-	return 0;
22c213
-}
22c213
-
22c213
 void fuse_session_process_buf(struct fuse_session *se,
22c213
 			      const struct fuse_buf *buf)
22c213
 {
22c213
@@ -2533,36 +2134,12 @@ void fuse_session_process_buf(struct fuse_session *se,
22c213
 void fuse_session_process_buf_int(struct fuse_session *se,
22c213
 				  const struct fuse_buf *buf, struct fuse_chan *ch)
22c213
 {
22c213
-	const size_t write_header_size = sizeof(struct fuse_in_header) +
22c213
-		sizeof(struct fuse_write_in);
22c213
-	struct fuse_bufvec bufv = { .buf[0] = *buf, .count = 1 };
22c213
-	struct fuse_bufvec tmpbuf = FUSE_BUFVEC_INIT(write_header_size);
22c213
 	struct fuse_in_header *in;
22c213
 	const void *inarg;
22c213
 	struct fuse_req *req;
22c213
-	void *mbuf = NULL;
22c213
 	int err;
22c213
-	int res;
22c213
-
22c213
-	if (buf->flags & FUSE_BUF_IS_FD) {
22c213
-		if (buf->size < tmpbuf.buf[0].size)
22c213
-			tmpbuf.buf[0].size = buf->size;
22c213
 
22c213
-		mbuf = malloc(tmpbuf.buf[0].size);
22c213
-		if (mbuf == NULL) {
22c213
-			fuse_log(FUSE_LOG_ERR, "fuse: failed to allocate header\n");
22c213
-			goto clear_pipe;
22c213
-		}
22c213
-		tmpbuf.buf[0].mem = mbuf;
22c213
-
22c213
-		res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv);
22c213
-		if (res < 0)
22c213
-			goto clear_pipe;
22c213
-
22c213
-		in = mbuf;
22c213
-	} else {
22c213
-		in = buf->mem;
22c213
-	}
22c213
+	in = buf->mem;
22c213
 
22c213
 	if (se->debug) {
22c213
 		fuse_log(FUSE_LOG_DEBUG,
22c213
@@ -2584,14 +2161,14 @@ void fuse_session_process_buf_int(struct fuse_session *se,
22c213
 		};
22c213
 
22c213
 		fuse_send_msg(se, ch, &iov, 1);
22c213
-		goto clear_pipe;
22c213
+		return;
22c213
 	}
22c213
 
22c213
 	req->unique = in->unique;
22c213
 	req->ctx.uid = in->uid;
22c213
 	req->ctx.gid = in->gid;
22c213
 	req->ctx.pid = in->pid;
22c213
-	req->ch = ch ? fuse_chan_get(ch) : NULL;
22c213
+	req->ch = ch;
22c213
 
22c213
 	err = EIO;
22c213
 	if (!se->got_init) {
22c213
@@ -2627,28 +2204,6 @@ void fuse_session_process_buf_int(struct fuse_session *se,
22c213
 			fuse_reply_err(intr, EAGAIN);
22c213
 	}
22c213
 
22c213
-	if ((buf->flags & FUSE_BUF_IS_FD) && write_header_size < buf->size &&
22c213
-	    (in->opcode != FUSE_WRITE || !se->op.write_buf) &&
22c213
-	    in->opcode != FUSE_NOTIFY_REPLY) {
22c213
-		void *newmbuf;
22c213
-
22c213
-		err = ENOMEM;
22c213
-		newmbuf = realloc(mbuf, buf->size);
22c213
-		if (newmbuf == NULL)
22c213
-			goto reply_err;
22c213
-		mbuf = newmbuf;
22c213
-
22c213
-		tmpbuf = FUSE_BUFVEC_INIT(buf->size - write_header_size);
22c213
-		tmpbuf.buf[0].mem = (char *)mbuf + write_header_size;
22c213
-
22c213
-		res = fuse_ll_copy_from_pipe(&tmpbuf, &bufv);
22c213
-		err = -res;
22c213
-		if (res < 0)
22c213
-			goto reply_err;
22c213
-
22c213
-		in = mbuf;
22c213
-	}
22c213
-
22c213
 	inarg = (void *) &in[1];
22c213
 	if (in->opcode == FUSE_WRITE && se->op.write_buf)
22c213
 		do_write_buf(req, in->nodeid, inarg, buf);
22c213
@@ -2657,16 +2212,10 @@ void fuse_session_process_buf_int(struct fuse_session *se,
22c213
 	else
22c213
 		fuse_ll_ops[in->opcode].func(req, in->nodeid, inarg);
22c213
 
22c213
-out_free:
22c213
-	free(mbuf);
22c213
 	return;
22c213
 
22c213
 reply_err:
22c213
 	fuse_reply_err(req, err);
22c213
-clear_pipe:
22c213
-	if (buf->flags & FUSE_BUF_IS_FD)
22c213
-		fuse_ll_clear_pipe(se);
22c213
-	goto out_free;
22c213
 }
22c213
 
22c213
 #define LL_OPTION(n,o,v) \
22c213
@@ -2684,7 +2233,6 @@ void fuse_lowlevel_version(void)
22c213
 {
22c213
 	printf("using FUSE kernel interface version %i.%i\n",
22c213
 	       FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
22c213
-	fuse_mount_version();
22c213
 }
22c213
 
22c213
 void fuse_lowlevel_help(void)
22c213
@@ -2692,204 +2240,29 @@ void fuse_lowlevel_help(void)
22c213
 	/* These are not all options, but the ones that are
22c213
 	   potentially of interest to an end-user */
22c213
 	printf(
22c213
-"    -o allow_other         allow access by all users\n"
22c213
 "    -o allow_root          allow access by root\n"
22c213
-"    -o auto_unmount        auto unmount on process termination\n");
22c213
+);
22c213
 }
22c213
 
22c213
 void fuse_session_destroy(struct fuse_session *se)
22c213
 {
22c213
-	struct fuse_ll_pipe *llp;
22c213
-
22c213
 	if (se->got_init && !se->got_destroy) {
22c213
 		if (se->op.destroy)
22c213
 			se->op.destroy(se->userdata);
22c213
 	}
22c213
-	llp = pthread_getspecific(se->pipe_key);
22c213
-	if (llp != NULL)
22c213
-		fuse_ll_pipe_free(llp);
22c213
-	pthread_key_delete(se->pipe_key);
22c213
 	pthread_mutex_destroy(&se->lock);
22c213
 	free(se->cuse_data);
22c213
 	if (se->fd != -1)
22c213
 		close(se->fd);
22c213
-	destroy_mount_opts(se->mo);
22c213
 	free(se);
22c213
 }
22c213
 
22c213
 
22c213
-static void fuse_ll_pipe_destructor(void *data)
22c213
-{
22c213
-	struct fuse_ll_pipe *llp = data;
22c213
-	fuse_ll_pipe_free(llp);
22c213
-}
22c213
-
22c213
-int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf)
22c213
-{
22c213
-	return fuse_session_receive_buf_int(se, buf, NULL);
22c213
-}
22c213
-
22c213
-int fuse_session_receive_buf_int(struct fuse_session *se, struct fuse_buf *buf,
22c213
-				 struct fuse_chan *ch)
22c213
-{
22c213
-	int err;
22c213
-	ssize_t res;
22c213
-#ifdef HAVE_SPLICE
22c213
-	size_t bufsize = se->bufsize;
22c213
-	struct fuse_ll_pipe *llp;
22c213
-	struct fuse_buf tmpbuf;
22c213
-
22c213
-	if (se->conn.proto_minor < 14 || !(se->conn.want & FUSE_CAP_SPLICE_READ))
22c213
-		goto fallback;
22c213
-
22c213
-	llp = fuse_ll_get_pipe(se);
22c213
-	if (llp == NULL)
22c213
-		goto fallback;
22c213
-
22c213
-	if (llp->size < bufsize) {
22c213
-		if (llp->can_grow) {
22c213
-			res = fcntl(llp->pipe[0], F_SETPIPE_SZ, bufsize);
22c213
-			if (res == -1) {
22c213
-				llp->can_grow = 0;
22c213
-				res = grow_pipe_to_max(llp->pipe[0]);
22c213
-				if (res > 0)
22c213
-					llp->size = res;
22c213
-				goto fallback;
22c213
-			}
22c213
-			llp->size = res;
22c213
-		}
22c213
-		if (llp->size < bufsize)
22c213
-			goto fallback;
22c213
-	}
22c213
-
22c213
-	res = splice(ch ? ch->fd : se->fd,
22c213
-		     NULL, llp->pipe[1], NULL, bufsize, 0);
22c213
-	err = errno;
22c213
-
22c213
-	if (fuse_session_exited(se))
22c213
-		return 0;
22c213
-
22c213
-	if (res == -1) {
22c213
-		if (err == ENODEV) {
22c213
-			/* Filesystem was unmounted, or connection was aborted
22c213
-			   via /sys/fs/fuse/connections */
22c213
-			fuse_session_exit(se);
22c213
-			return 0;
22c213
-		}
22c213
-		if (err != EINTR && err != EAGAIN)
22c213
-			perror("fuse: splice from device");
22c213
-		return -err;
22c213
-	}
22c213
-
22c213
-	if (res < sizeof(struct fuse_in_header)) {
22c213
-		fuse_log(FUSE_LOG_ERR, "short splice from fuse device\n");
22c213
-		return -EIO;
22c213
-	}
22c213
-
22c213
-	tmpbuf = (struct fuse_buf) {
22c213
-		.size = res,
22c213
-		.flags = FUSE_BUF_IS_FD,
22c213
-		.fd = llp->pipe[0],
22c213
-	};
22c213
-
22c213
-	/*
22c213
-	 * Don't bother with zero copy for small requests.
22c213
-	 * fuse_loop_mt() needs to check for FORGET so this more than
22c213
-	 * just an optimization.
22c213
-	 */
22c213
-	if (res < sizeof(struct fuse_in_header) +
22c213
-	    sizeof(struct fuse_write_in) + pagesize) {
22c213
-		struct fuse_bufvec src = { .buf[0] = tmpbuf, .count = 1 };
22c213
-		struct fuse_bufvec dst = { .count = 1 };
22c213
-
22c213
-		if (!buf->mem) {
22c213
-			buf->mem = malloc(se->bufsize);
22c213
-			if (!buf->mem) {
22c213
-				fuse_log(FUSE_LOG_ERR,
22c213
-					"fuse: failed to allocate read buffer\n");
22c213
-				return -ENOMEM;
22c213
-			}
22c213
-		}
22c213
-		buf->size = se->bufsize;
22c213
-		buf->flags = 0;
22c213
-		dst.buf[0] = *buf;
22c213
-
22c213
-		res = fuse_buf_copy(&dst, &src, 0);
22c213
-		if (res < 0) {
22c213
-			fuse_log(FUSE_LOG_ERR, "fuse: copy from pipe: %s\n",
22c213
-				strerror(-res));
22c213
-			fuse_ll_clear_pipe(se);
22c213
-			return res;
22c213
-		}
22c213
-		if (res < tmpbuf.size) {
22c213
-			fuse_log(FUSE_LOG_ERR, "fuse: copy from pipe: short read\n");
22c213
-			fuse_ll_clear_pipe(se);
22c213
-			return -EIO;
22c213
-		}
22c213
-		assert(res == tmpbuf.size);
22c213
-
22c213
-	} else {
22c213
-		/* Don't overwrite buf->mem, as that would cause a leak */
22c213
-		buf->fd = tmpbuf.fd;
22c213
-		buf->flags = tmpbuf.flags;
22c213
-	}
22c213
-	buf->size = tmpbuf.size;
22c213
-
22c213
-	return res;
22c213
-
22c213
-fallback:
22c213
-#endif
22c213
-	if (!buf->mem) {
22c213
-		buf->mem = malloc(se->bufsize);
22c213
-		if (!buf->mem) {
22c213
-			fuse_log(FUSE_LOG_ERR,
22c213
-				"fuse: failed to allocate read buffer\n");
22c213
-			return -ENOMEM;
22c213
-		}
22c213
-	}
22c213
-
22c213
-restart:
22c213
-	res = read(ch ? ch->fd : se->fd, buf->mem, se->bufsize);
22c213
-	err = errno;
22c213
-
22c213
-	if (fuse_session_exited(se))
22c213
-		return 0;
22c213
-	if (res == -1) {
22c213
-		/* ENOENT means the operation was interrupted, it's safe
22c213
-		   to restart */
22c213
-		if (err == ENOENT)
22c213
-			goto restart;
22c213
-
22c213
-		if (err == ENODEV) {
22c213
-			/* Filesystem was unmounted, or connection was aborted
22c213
-			   via /sys/fs/fuse/connections */
22c213
-			fuse_session_exit(se);
22c213
-			return 0;
22c213
-		}
22c213
-		/* Errors occurring during normal operation: EINTR (read
22c213
-		   interrupted), EAGAIN (nonblocking I/O), ENODEV (filesystem
22c213
-		   umounted) */
22c213
-		if (err != EINTR && err != EAGAIN)
22c213
-			perror("fuse: reading device");
22c213
-		return -err;
22c213
-	}
22c213
-	if ((size_t) res < sizeof(struct fuse_in_header)) {
22c213
-		fuse_log(FUSE_LOG_ERR, "short read on fuse device\n");
22c213
-		return -EIO;
22c213
-	}
22c213
-
22c213
-	buf->size = res;
22c213
-
22c213
-	return res;
22c213
-}
22c213
-
22c213
 struct fuse_session *fuse_session_new(struct fuse_args *args,
22c213
 				      const struct fuse_lowlevel_ops *op,
22c213
 				      size_t op_size, void *userdata)
22c213
 {
22c213
-	int err;
22c213
 	struct fuse_session *se;
22c213
-	struct mount_opts *mo;
22c213
 
22c213
 	if (sizeof(struct fuse_lowlevel_ops) < op_size) {
22c213
 		fuse_log(FUSE_LOG_ERR, "fuse: warning: library too old, some operations may not work\n");
22c213
@@ -2913,20 +2286,6 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
22c213
 	/* Parse options */
22c213
 	if(fuse_opt_parse(args, se, fuse_ll_opts, NULL) == -1)
22c213
 		goto out2;
22c213
-	if(se->deny_others) {
22c213
-		/* Allowing access only by root is done by instructing
22c213
-		 * kernel to allow access by everyone, and then restricting
22c213
-		 * access to root and mountpoint owner in libfuse.
22c213
-		 */
22c213
-		// We may be adding the option a second time, but
22c213
-		// that doesn't hurt.
22c213
-		if(fuse_opt_add_arg(args, "-oallow_other") == -1)
22c213
-			goto out2;
22c213
-	}
22c213
-	mo = parse_mount_opts(args);
22c213
-	if (mo == NULL)
22c213
-		goto out3;
22c213
-
22c213
 	if(args->argc == 1 &&
22c213
 	   args->argv[0][0] == '-') {
22c213
 		fuse_log(FUSE_LOG_ERR, "fuse: warning: argv[0] looks like an option, but "
22c213
@@ -2940,9 +2299,6 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
22c213
 		goto out4;
22c213
 	}
22c213
 
22c213
-	if (se->debug)
22c213
-		fuse_log(FUSE_LOG_DEBUG, "FUSE library version: %s\n", PACKAGE_VERSION);
22c213
-
22c213
 	se->bufsize = FUSE_MAX_MAX_PAGES * getpagesize() +
22c213
 		FUSE_BUFFER_HEADER_SIZE;
22c213
 
22c213
@@ -2952,26 +2308,14 @@ struct fuse_session *fuse_session_new(struct fuse_args *args,
22c213
 	se->notify_ctr = 1;
22c213
 	fuse_mutex_init(&se->lock);
22c213
 
22c213
-	err = pthread_key_create(&se->pipe_key, fuse_ll_pipe_destructor);
22c213
-	if (err) {
22c213
-		fuse_log(FUSE_LOG_ERR, "fuse: failed to create thread specific key: %s\n",
22c213
-			strerror(err));
22c213
-		goto out5;
22c213
-	}
22c213
-
22c213
 	memcpy(&se->op, op, op_size);
22c213
 	se->owner = getuid();
22c213
 	se->userdata = userdata;
22c213
 
22c213
-	se->mo = mo;
22c213
 	return se;
22c213
 
22c213
-out5:
22c213
-	pthread_mutex_destroy(&se->lock);
22c213
 out4:
22c213
 	fuse_opt_free_args(args);
22c213
-out3:
22c213
-	free(mo);
22c213
 out2:
22c213
 	free(se);
22c213
 out1:
22c213
@@ -3035,11 +2379,6 @@ int fuse_session_fd(struct fuse_session *se)
22c213
 
22c213
 void fuse_session_unmount(struct fuse_session *se)
22c213
 {
22c213
-	if (se->mountpoint != NULL) {
22c213
-		fuse_kern_unmount(se->mountpoint, se->fd);
22c213
-		free(se->mountpoint);
22c213
-		se->mountpoint = NULL;
22c213
-	}
22c213
 }
22c213
 
22c213
 #ifdef linux
22c213
diff --git a/tools/virtiofsd/fuse_lowlevel.h b/tools/virtiofsd/fuse_lowlevel.h
22c213
index 18c6363..6b1adfc 100644
22c213
--- a/tools/virtiofsd/fuse_lowlevel.h
22c213
+++ b/tools/virtiofsd/fuse_lowlevel.h
22c213
@@ -31,10 +31,6 @@
22c213
 #include <sys/statvfs.h>
22c213
 #include <sys/uio.h>
22c213
 
22c213
-#ifdef __cplusplus
22c213
-extern "C" {
22c213
-#endif
22c213
-
22c213
 /* ----------------------------------------------------------- *
22c213
  * Miscellaneous definitions				       *
22c213
  * ----------------------------------------------------------- */
22c213
@@ -1863,14 +1859,12 @@ void fuse_cmdline_help(void);
22c213
  * ----------------------------------------------------------- */
22c213
 
22c213
 struct fuse_cmdline_opts {
22c213
-	int singlethread;
22c213
 	int foreground;
22c213
 	int debug;
22c213
 	int nodefault_subtype;
22c213
 	char *mountpoint;
22c213
 	int show_version;
22c213
 	int show_help;
22c213
-	int clone_fd;
22c213
 	unsigned int max_idle_threads;
22c213
 };
22c213
 
22c213
@@ -1962,24 +1956,6 @@ int fuse_session_mount(struct fuse_session *se, const char *mountpoint);
22c213
 int fuse_session_loop(struct fuse_session *se);
22c213
 
22c213
 /**
22c213
- * Enter a multi-threaded event loop.
22c213
- *
22c213
- * For a description of the return value and the conditions when the
22c213
- * event loop exits, refer to the documentation of
22c213
- * fuse_session_loop().
22c213
- *
22c213
- * @param se the session
22c213
- * @param config session loop configuration 
22c213
- * @return see fuse_session_loop()
22c213
- */
22c213
-#if FUSE_USE_VERSION < 32
22c213
-int fuse_session_loop_mt_31(struct fuse_session *se, int clone_fd);
22c213
-#define fuse_session_loop_mt(se, clone_fd) fuse_session_loop_mt_31(se, clone_fd)
22c213
-#else
22c213
-int fuse_session_loop_mt(struct fuse_session *se, struct fuse_loop_config *config);
22c213
-#endif
22c213
-
22c213
-/**
22c213
  * Flag a session as terminated.
22c213
  *
22c213
  * This function is invoked by the POSIX signal handlers, when
22c213
@@ -2082,8 +2058,4 @@ void fuse_session_process_buf(struct fuse_session *se,
22c213
  */
22c213
 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf);
22c213
 
22c213
-#ifdef __cplusplus
22c213
-}
22c213
-#endif
22c213
-
22c213
 #endif /* FUSE_LOWLEVEL_H_ */
22c213
diff --git a/tools/virtiofsd/fuse_opt.h b/tools/virtiofsd/fuse_opt.h
22c213
index d8573e7..6910255 100644
22c213
--- a/tools/virtiofsd/fuse_opt.h
22c213
+++ b/tools/virtiofsd/fuse_opt.h
22c213
@@ -14,10 +14,6 @@
22c213
  * This file defines the option parsing interface of FUSE
22c213
  */
22c213
 
22c213
-#ifdef __cplusplus
22c213
-extern "C" {
22c213
-#endif
22c213
-
22c213
 /**
22c213
  * Option description
22c213
  *
22c213
@@ -264,8 +260,4 @@ void fuse_opt_free_args(struct fuse_args *args);
22c213
  */
22c213
 int fuse_opt_match(const struct fuse_opt opts[], const char *opt);
22c213
 
22c213
-#ifdef __cplusplus
22c213
-}
22c213
-#endif
22c213
-
22c213
 #endif /* FUSE_OPT_H_ */
22c213
diff --git a/tools/virtiofsd/helper.c b/tools/virtiofsd/helper.c
22c213
index 64ff7ad..5a2e64c 100644
22c213
--- a/tools/virtiofsd/helper.c
22c213
+++ b/tools/virtiofsd/helper.c
22c213
@@ -41,14 +41,10 @@ static const struct fuse_opt fuse_helper_opts[] = {
22c213
 	FUSE_OPT_KEY("-d",		FUSE_OPT_KEY_KEEP),
22c213
 	FUSE_OPT_KEY("debug",		FUSE_OPT_KEY_KEEP),
22c213
 	FUSE_HELPER_OPT("-f",		foreground),
22c213
-	FUSE_HELPER_OPT("-s",		singlethread),
22c213
 	FUSE_HELPER_OPT("fsname=",	nodefault_subtype),
22c213
 	FUSE_OPT_KEY("fsname=",		FUSE_OPT_KEY_KEEP),
22c213
-#ifndef __FreeBSD__
22c213
 	FUSE_HELPER_OPT("subtype=",	nodefault_subtype),
22c213
 	FUSE_OPT_KEY("subtype=",	FUSE_OPT_KEY_KEEP),
22c213
-#endif
22c213
-	FUSE_HELPER_OPT("clone_fd",	clone_fd),
22c213
 	FUSE_HELPER_OPT("max_idle_threads=%u", max_idle_threads),
22c213
 	FUSE_OPT_END
22c213
 };
22c213
@@ -132,9 +128,6 @@ void fuse_cmdline_help(void)
22c213
 	       "    -V   --version         print version\n"
22c213
 	       "    -d   -o debug          enable debug output (implies -f)\n"
22c213
 	       "    -f                     foreground operation\n"
22c213
-	       "    -s                     disable multi-threaded operation\n"
22c213
-	       "    -o clone_fd            use separate fuse device fd for each thread\n"
22c213
-	       "                           (may improve performance)\n"
22c213
 	       "    -o max_idle_threads    the maximum number of idle worker threads\n"
22c213
 	       "                           allowed (default: 10)\n");
22c213
 }
22c213
@@ -171,34 +164,6 @@ static int fuse_helper_opt_proc(void *data, const char *arg, int key,
22c213
 	}
22c213
 }
22c213
 
22c213
-/* Under FreeBSD, there is no subtype option so this
22c213
-   function actually sets the fsname */
22c213
-static int add_default_subtype(const char *progname, struct fuse_args *args)
22c213
-{
22c213
-	int res;
22c213
-	char *subtype_opt;
22c213
-
22c213
-	const char *basename = strrchr(progname, '/');
22c213
-	if (basename == NULL)
22c213
-		basename = progname;
22c213
-	else if (basename[1] != '\0')
22c213
-		basename++;
22c213
-
22c213
-	subtype_opt = (char *) malloc(strlen(basename) + 64);
22c213
-	if (subtype_opt == NULL) {
22c213
-		fuse_log(FUSE_LOG_ERR, "fuse: memory allocation failed\n");
22c213
-		return -1;
22c213
-	}
22c213
-#ifdef __FreeBSD__
22c213
-	sprintf(subtype_opt, "-ofsname=%s", basename);
22c213
-#else
22c213
-	sprintf(subtype_opt, "-osubtype=%s", basename);
22c213
-#endif
22c213
-	res = fuse_opt_add_arg(args, subtype_opt);
22c213
-	free(subtype_opt);
22c213
-	return res;
22c213
-}
22c213
-
22c213
 int fuse_parse_cmdline(struct fuse_args *args,
22c213
 		       struct fuse_cmdline_opts *opts)
22c213
 {
22c213
@@ -210,14 +175,6 @@ int fuse_parse_cmdline(struct fuse_args *args,
22c213
 			   fuse_helper_opt_proc) == -1)
22c213
 		return -1;
22c213
 
22c213
-	/* *Linux*: if neither -o subtype nor -o fsname are specified,
22c213
-	   set subtype to program's basename.
22c213
-	   *FreeBSD*: if fsname is not specified, set to program's
22c213
-	   basename. */
22c213
-	if (!opts->nodefault_subtype)
22c213
-		if (add_default_subtype(args->argv[0], args) == -1)
22c213
-			return -1;
22c213
-
22c213
 	return 0;
22c213
 }
22c213
 
22c213
@@ -276,88 +233,6 @@ int fuse_daemonize(int foreground)
22c213
 	return 0;
22c213
 }
22c213
 
22c213
-int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op,
22c213
-		   size_t op_size, void *user_data)
22c213
-{
22c213
-	struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
22c213
-	struct fuse *fuse;
22c213
-	struct fuse_cmdline_opts opts;
22c213
-	int res;
22c213
-
22c213
-	if (fuse_parse_cmdline(&args, &opts) != 0)
22c213
-		return 1;
22c213
-
22c213
-	if (opts.show_version) {
22c213
-		printf("FUSE library version %s\n", PACKAGE_VERSION);
22c213
-		fuse_lowlevel_version();
22c213
-		res = 0;
22c213
-		goto out1;
22c213
-	}
22c213
-
22c213
-	if (opts.show_help) {
22c213
-		if(args.argv[0][0] != '\0')
22c213
-			printf("usage: %s [options] <mountpoint>\n\n",
22c213
-			       args.argv[0]);
22c213
-		printf("FUSE options:\n");
22c213
-		fuse_cmdline_help();
22c213
-		fuse_lib_help(&args);
22c213
-		res = 0;
22c213
-		goto out1;
22c213
-	}
22c213
-
22c213
-	if (!opts.show_help &&
22c213
-	    !opts.mountpoint) {
22c213
-		fuse_log(FUSE_LOG_ERR, "error: no mountpoint specified\n");
22c213
-		res = 2;
22c213
-		goto out1;
22c213
-	}
22c213
-
22c213
-
22c213
-	fuse = fuse_new_31(&args, op, op_size, user_data);
22c213
-	if (fuse == NULL) {
22c213
-		res = 3;
22c213
-		goto out1;
22c213
-	}
22c213
-
22c213
-	if (fuse_mount(fuse,opts.mountpoint) != 0) {
22c213
-		res = 4;
22c213
-		goto out2;
22c213
-	}
22c213
-
22c213
-	if (fuse_daemonize(opts.foreground) != 0) {
22c213
-		res = 5;
22c213
-		goto out3;
22c213
-	}
22c213
-
22c213
-	struct fuse_session *se = fuse_get_session(fuse);
22c213
-	if (fuse_set_signal_handlers(se) != 0) {
22c213
-		res = 6;
22c213
-		goto out3;
22c213
-	}
22c213
-
22c213
-	if (opts.singlethread)
22c213
-		res = fuse_loop(fuse);
22c213
-	else {
22c213
-		struct fuse_loop_config loop_config;
22c213
-		loop_config.clone_fd = opts.clone_fd;
22c213
-		loop_config.max_idle_threads = opts.max_idle_threads;
22c213
-		res = fuse_loop_mt_32(fuse, &loop_config);
22c213
-	}
22c213
-	if (res)
22c213
-		res = 7;
22c213
-
22c213
-	fuse_remove_signal_handlers(se);
22c213
-out3:
22c213
-	fuse_unmount(fuse);
22c213
-out2:
22c213
-	fuse_destroy(fuse);
22c213
-out1:
22c213
-	free(opts.mountpoint);
22c213
-	fuse_opt_free_args(&args);
22c213
-	return res;
22c213
-}
22c213
-
22c213
-
22c213
 void fuse_apply_conn_info_opts(struct fuse_conn_info_opts *opts,
22c213
 			       struct fuse_conn_info *conn)
22c213
 {
22c213
@@ -420,21 +295,3 @@ struct fuse_conn_info_opts* fuse_parse_conn_info_opts(struct fuse_args *args)
22c213
 	}
22c213
 	return opts;
22c213
 }
22c213
-
22c213
-int fuse_open_channel(const char *mountpoint, const char* options)
22c213
-{
22c213
-	struct mount_opts *opts = NULL;
22c213
-	int fd = -1;
22c213
-	const char *argv[] = { "", "-o", options };
22c213
-	int argc = sizeof(argv) / sizeof(argv[0]);
22c213
-	struct fuse_args args = FUSE_ARGS_INIT(argc, (char**) argv);
22c213
-
22c213
-	opts = parse_mount_opts(&args);
22c213
-	if (opts == NULL)
22c213
-		return -1;
22c213
-
22c213
-	fd = fuse_kern_mount(mountpoint, opts);
22c213
-	destroy_mount_opts(opts);
22c213
-
22c213
-	return fd;
22c213
-}
22c213
diff --git a/tools/virtiofsd/passthrough_helpers.h b/tools/virtiofsd/passthrough_helpers.h
22c213
index 6b77c33..7c5f561 100644
22c213
--- a/tools/virtiofsd/passthrough_helpers.h
22c213
+++ b/tools/virtiofsd/passthrough_helpers.h
22c213
@@ -42,32 +42,6 @@ static int mknod_wrapper(int dirfd, const char *path, const char *link,
22c213
 		res = symlinkat(link, dirfd, path);
22c213
 	} else if (S_ISFIFO(mode)) {
22c213
 		res = mkfifoat(dirfd, path, mode);
22c213
-#ifdef __FreeBSD__
22c213
-	} else if (S_ISSOCK(mode)) {
22c213
-		struct sockaddr_un su;
22c213
-		int fd;
22c213
-
22c213
-		if (strlen(path) >= sizeof(su.sun_path)) {
22c213
-			errno = ENAMETOOLONG;
22c213
-			return -1;
22c213
-		}
22c213
-		fd = socket(AF_UNIX, SOCK_STREAM, 0);
22c213
-		if (fd >= 0) {
22c213
-			/*
22c213
-			 * We must bind the socket to the underlying file
22c213
-			 * system to create the socket file, even though
22c213
-			 * we'll never listen on this socket.
22c213
-			 */
22c213
-			su.sun_family = AF_UNIX;
22c213
-			strncpy(su.sun_path, path, sizeof(su.sun_path));
22c213
-			res = bindat(dirfd, fd, (struct sockaddr*)&su,
22c213
-				sizeof(su));
22c213
-			if (res == 0)
22c213
-				close(fd);
22c213
-		} else {
22c213
-			res = -1;
22c213
-		}
22c213
-#endif
22c213
 	} else {
22c213
 		res = mknodat(dirfd, path, mode, rdev);
22c213
 	}
22c213
diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
22c213
index e1a6056..e5f7115 100644
22c213
--- a/tools/virtiofsd/passthrough_ll.c
22c213
+++ b/tools/virtiofsd/passthrough_ll.c
22c213
@@ -1240,7 +1240,6 @@ int main(int argc, char *argv[])
22c213
 		ret = 0;
22c213
 		goto err_out1;
22c213
 	} else if (opts.show_version) {
22c213
-		printf("FUSE library version %s\n", fuse_pkgversion());
22c213
 		fuse_lowlevel_version();
22c213
 		ret = 0;
22c213
 		goto err_out1;
22c213
-- 
22c213
1.8.3.1
22c213