yeahuh / rpms / qemu-kvm

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