xref: /freebsd/sys/fs/fuse/fuse_ipc.h (revision 37df9d3b)
151369649SPedro F. Giffuni /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
45fe58019SAttilio Rao  * Copyright (c) 2007-2009 Google Inc. and Amit Singh
55fe58019SAttilio Rao  * All rights reserved.
65fe58019SAttilio Rao  *
75fe58019SAttilio Rao  * Redistribution and use in source and binary forms, with or without
85fe58019SAttilio Rao  * modification, are permitted provided that the following conditions are
95fe58019SAttilio Rao  * met:
105fe58019SAttilio Rao  *
115fe58019SAttilio Rao  * * Redistributions of source code must retain the above copyright
125fe58019SAttilio Rao  *   notice, this list of conditions and the following disclaimer.
135fe58019SAttilio Rao  * * Redistributions in binary form must reproduce the above
145fe58019SAttilio Rao  *   copyright notice, this list of conditions and the following disclaimer
155fe58019SAttilio Rao  *   in the documentation and/or other materials provided with the
165fe58019SAttilio Rao  *   distribution.
175fe58019SAttilio Rao  * * Neither the name of Google Inc. nor the names of its
185fe58019SAttilio Rao  *   contributors may be used to endorse or promote products derived from
195fe58019SAttilio Rao  *   this software without specific prior written permission.
205fe58019SAttilio Rao  *
215fe58019SAttilio Rao  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
225fe58019SAttilio Rao  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
235fe58019SAttilio Rao  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
245fe58019SAttilio Rao  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
255fe58019SAttilio Rao  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
265fe58019SAttilio Rao  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
275fe58019SAttilio Rao  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
285fe58019SAttilio Rao  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
295fe58019SAttilio Rao  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
305fe58019SAttilio Rao  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
315fe58019SAttilio Rao  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
325fe58019SAttilio Rao  *
335fe58019SAttilio Rao  * Copyright (C) 2005 Csaba Henk.
345fe58019SAttilio Rao  * All rights reserved.
355fe58019SAttilio Rao  *
368aafc8c3SAlan Somers  * Copyright (c) 2019 The FreeBSD Foundation
378aafc8c3SAlan Somers  *
388aafc8c3SAlan Somers  * Portions of this software were developed by BFF Storage Systems, LLC under
398aafc8c3SAlan Somers  * sponsorship from the FreeBSD Foundation.
408aafc8c3SAlan Somers  *
415fe58019SAttilio Rao  * Redistribution and use in source and binary forms, with or without
425fe58019SAttilio Rao  * modification, are permitted provided that the following conditions
435fe58019SAttilio Rao  * are met:
445fe58019SAttilio Rao  * 1. Redistributions of source code must retain the above copyright
455fe58019SAttilio Rao  *    notice, this list of conditions and the following disclaimer.
465fe58019SAttilio Rao  * 2. Redistributions in binary form must reproduce the above copyright
475fe58019SAttilio Rao  *    notice, this list of conditions and the following disclaimer in the
485fe58019SAttilio Rao  *    documentation and/or other materials provided with the distribution.
495fe58019SAttilio Rao  *
505fe58019SAttilio Rao  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
515fe58019SAttilio Rao  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
525fe58019SAttilio Rao  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
535fe58019SAttilio Rao  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
545fe58019SAttilio Rao  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
555fe58019SAttilio Rao  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
565fe58019SAttilio Rao  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
575fe58019SAttilio Rao  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
585fe58019SAttilio Rao  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
595fe58019SAttilio Rao  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
605fe58019SAttilio Rao  * SUCH DAMAGE.
615fe58019SAttilio Rao  *
625fe58019SAttilio Rao  * $FreeBSD$
635fe58019SAttilio Rao  */
645fe58019SAttilio Rao 
655fe58019SAttilio Rao #ifndef _FUSE_IPC_H_
665fe58019SAttilio Rao #define _FUSE_IPC_H_
675fe58019SAttilio Rao 
685fe58019SAttilio Rao #include <sys/param.h>
695fe58019SAttilio Rao #include <sys/refcount.h>
705fe58019SAttilio Rao 
71f8ebf1cdSAlan Somers enum fuse_data_cache_mode {
72f8ebf1cdSAlan Somers 	FUSE_CACHE_UC,
73f8ebf1cdSAlan Somers 	FUSE_CACHE_WT,
74f8ebf1cdSAlan Somers 	FUSE_CACHE_WB,
75f8ebf1cdSAlan Somers };
76f8ebf1cdSAlan Somers 
775fe58019SAttilio Rao struct fuse_iov {
785fe58019SAttilio Rao 	void   *base;
795fe58019SAttilio Rao 	size_t  len;
805fe58019SAttilio Rao 	size_t  allocated_size;
815fe58019SAttilio Rao 	int     credit;
825fe58019SAttilio Rao };
835fe58019SAttilio Rao 
845fe58019SAttilio Rao void fiov_init(struct fuse_iov *fiov, size_t size);
855fe58019SAttilio Rao void fiov_teardown(struct fuse_iov *fiov);
865fe58019SAttilio Rao void fiov_refresh(struct fuse_iov *fiov);
875fe58019SAttilio Rao void fiov_adjust(struct fuse_iov *fiov, size_t size);
885fe58019SAttilio Rao 
8902295cafSConrad Meyer #define FUSE_DIMALLOC(fiov, spc1, spc2, amnt) do {		\
905fe58019SAttilio Rao 	fiov_adjust(fiov, (sizeof(*(spc1)) + (amnt)));		\
915fe58019SAttilio Rao 	(spc1) = (fiov)->base;					\
925fe58019SAttilio Rao 	(spc2) = (char *)(fiov)->base + (sizeof(*(spc1)));	\
935fe58019SAttilio Rao } while (0)
945fe58019SAttilio Rao 
955fe58019SAttilio Rao #define FU_AT_LEAST(siz) max((siz), 160)
965fe58019SAttilio Rao 
975fe58019SAttilio Rao #define FUSE_ASSERT_AW_DONE(ftick)					\
985fe58019SAttilio Rao 	KASSERT((ftick)->tk_aw_link.tqe_next == NULL &&			\
995fe58019SAttilio Rao 	    (ftick)->tk_aw_link.tqe_prev == NULL,			\
10002295cafSConrad Meyer 	    ("FUSE: ticket still on answer delivery list %p", (ftick)))
1015fe58019SAttilio Rao 
1025fe58019SAttilio Rao #define FUSE_ASSERT_MS_DONE(ftick)				\
1035fe58019SAttilio Rao 	KASSERT((ftick)->tk_ms_link.stqe_next == NULL,		\
1045fe58019SAttilio Rao 	    ("FUSE: ticket still on message list %p", (ftick)))
1055fe58019SAttilio Rao 
1065fe58019SAttilio Rao struct fuse_ticket;
1075fe58019SAttilio Rao struct fuse_data;
1085fe58019SAttilio Rao 
1095fe58019SAttilio Rao typedef int fuse_handler_t(struct fuse_ticket *ftick, struct uio *uio);
1105fe58019SAttilio Rao 
1115fe58019SAttilio Rao struct fuse_ticket {
1125fe58019SAttilio Rao 	/* fields giving the identity of the ticket */
1135fe58019SAttilio Rao 	uint64_t			tk_unique;
1145fe58019SAttilio Rao 	struct fuse_data		*tk_data;
1155fe58019SAttilio Rao 	int				tk_flag;
1165fe58019SAttilio Rao 	u_int				tk_refcount;
117a1542146SAlan Somers 	/*
118a1542146SAlan Somers 	 * If this ticket's operation has been interrupted, this will hold the
119a1542146SAlan Somers 	 * unique value of the FUSE_INTERRUPT operation.  Otherwise, it will be
120a1542146SAlan Somers 	 * 0.
121a1542146SAlan Somers 	 */
122a1542146SAlan Somers 	uint64_t			irq_unique;
1235fe58019SAttilio Rao 
1245fe58019SAttilio Rao 	/* fields for initiating an upgoing message */
1255fe58019SAttilio Rao 	struct fuse_iov			tk_ms_fiov;
1265fe58019SAttilio Rao 	STAILQ_ENTRY(fuse_ticket)	tk_ms_link;
1275fe58019SAttilio Rao 
1285fe58019SAttilio Rao 	/* fields for handling answers coming from userspace */
1295fe58019SAttilio Rao 	struct fuse_iov			tk_aw_fiov;
1305fe58019SAttilio Rao 	struct fuse_out_header		tk_aw_ohead;
1315fe58019SAttilio Rao 	int				tk_aw_errno;
1325fe58019SAttilio Rao 	struct mtx			tk_aw_mtx;
1335fe58019SAttilio Rao 	fuse_handler_t			*tk_aw_handler;
1345fe58019SAttilio Rao 	TAILQ_ENTRY(fuse_ticket)	tk_aw_link;
1355fe58019SAttilio Rao };
1365fe58019SAttilio Rao 
1375fe58019SAttilio Rao #define FT_ANSW  0x01  /* request of ticket has already been answered */
1385fe58019SAttilio Rao #define FT_DIRTY 0x04  /* ticket has been used */
1395fe58019SAttilio Rao 
14002295cafSConrad Meyer static inline struct fuse_iov *
1415fe58019SAttilio Rao fticket_resp(struct fuse_ticket *ftick)
1425fe58019SAttilio Rao {
1435fe58019SAttilio Rao 	return (&ftick->tk_aw_fiov);
1445fe58019SAttilio Rao }
1455fe58019SAttilio Rao 
14602295cafSConrad Meyer static inline bool
1475fe58019SAttilio Rao fticket_answered(struct fuse_ticket *ftick)
1485fe58019SAttilio Rao {
1495fe58019SAttilio Rao 	mtx_assert(&ftick->tk_aw_mtx, MA_OWNED);
1505fe58019SAttilio Rao 	return (ftick->tk_flag & FT_ANSW);
1515fe58019SAttilio Rao }
1525fe58019SAttilio Rao 
15302295cafSConrad Meyer static inline void
1545fe58019SAttilio Rao fticket_set_answered(struct fuse_ticket *ftick)
1555fe58019SAttilio Rao {
1565fe58019SAttilio Rao 	mtx_assert(&ftick->tk_aw_mtx, MA_OWNED);
1575fe58019SAttilio Rao 	ftick->tk_flag |= FT_ANSW;
1585fe58019SAttilio Rao }
1595fe58019SAttilio Rao 
160723c7768SAlan Somers static inline struct fuse_in_header*
161723c7768SAlan Somers fticket_in_header(struct fuse_ticket *ftick)
162723c7768SAlan Somers {
163723c7768SAlan Somers 	return (struct fuse_in_header *)(ftick->tk_ms_fiov.base);
164723c7768SAlan Somers }
165723c7768SAlan Somers 
16602295cafSConrad Meyer static inline enum fuse_opcode
1675fe58019SAttilio Rao fticket_opcode(struct fuse_ticket *ftick)
1685fe58019SAttilio Rao {
169723c7768SAlan Somers 	return fticket_in_header(ftick)->opcode;
1705fe58019SAttilio Rao }
1715fe58019SAttilio Rao 
1725fe58019SAttilio Rao int fticket_pull(struct fuse_ticket *ftick, struct uio *uio);
1735fe58019SAttilio Rao 
1745fe58019SAttilio Rao /*
1755fe58019SAttilio Rao  * The data representing a FUSE session.
1765fe58019SAttilio Rao  */
1775fe58019SAttilio Rao struct fuse_data {
1785fe58019SAttilio Rao 	struct cdev			*fdev;
1795fe58019SAttilio Rao 	struct mount			*mp;
1805fe58019SAttilio Rao 	struct vnode			*vroot;
1815fe58019SAttilio Rao 	struct ucred			*daemoncred;
1825fe58019SAttilio Rao 	int				dataflags;
1835fe58019SAttilio Rao 	int				ref;
1845fe58019SAttilio Rao 
1855fe58019SAttilio Rao 	struct mtx			ms_mtx;
1865fe58019SAttilio Rao 	STAILQ_HEAD(, fuse_ticket)	ms_head;
1870a7c63e0SAlan Somers 	int				ms_count;
1885fe58019SAttilio Rao 
1895fe58019SAttilio Rao 	struct mtx			aw_mtx;
1905fe58019SAttilio Rao 	TAILQ_HEAD(, fuse_ticket)	aw_head;
1915fe58019SAttilio Rao 
192723c7768SAlan Somers 	/*
193723c7768SAlan Somers 	 * Holds the next value of the FUSE operation unique value.
194723c7768SAlan Somers 	 * Also, serves as a wakeup channel to prevent any operations from
195723c7768SAlan Somers 	 * being created before INIT completes.
196723c7768SAlan Somers 	 */
1975fe58019SAttilio Rao 	u_long				ticketer;
1985fe58019SAttilio Rao 
1995fe58019SAttilio Rao 	struct sx			rename_lock;
2005fe58019SAttilio Rao 
2015fe58019SAttilio Rao 	uint32_t			fuse_libabi_major;
2025fe58019SAttilio Rao 	uint32_t			fuse_libabi_minor;
2035fe58019SAttilio Rao 
204a1c9f4adSAlan Somers 	uint32_t			max_readahead_blocks;
2055fe58019SAttilio Rao 	uint32_t			max_write;
2065fe58019SAttilio Rao 	uint32_t			max_read;
2075fe58019SAttilio Rao 	uint32_t			subtype;
2085fe58019SAttilio Rao 	char				volname[MAXPATHLEN];
2095fe58019SAttilio Rao 
2105fe58019SAttilio Rao 	struct selinfo			ks_rsel;
2115fe58019SAttilio Rao 
2125fe58019SAttilio Rao 	int				daemon_timeout;
213e3b1c847SEdward Tomasz Napierala 	int				linux_errnos;
214fef46454SAlan Somers 	unsigned			time_gran;
21537df9d3bSAlan Somers 	/* A bitmask of FUSE RPCs that are not implemented by the server */
2165fe58019SAttilio Rao 	uint64_t			notimpl;
21737df9d3bSAlan Somers 	/*
21837df9d3bSAlan Somers 	 * A bitmask of FUSE RPCs that are implemented by the server.
21937df9d3bSAlan Somers 	 * If an operation is not present in either notimpl or isimpl, then it
22037df9d3bSAlan Somers 	 * may be implemented by the server, but the kernel doesn't know for
22137df9d3bSAlan Somers 	 * sure.
22237df9d3bSAlan Somers 	 */
22337df9d3bSAlan Somers 	uint64_t			isimpl;
224a6fac00cSAlan Somers 	uint64_t			mnt_flag;
225f8ebf1cdSAlan Somers 	enum fuse_data_cache_mode	cache_mode;
2265fe58019SAttilio Rao };
2275fe58019SAttilio Rao 
2285fe58019SAttilio Rao #define FSESS_DEAD                0x0001 /* session is to be closed */
2295fe58019SAttilio Rao #define FSESS_INITED              0x0004 /* session has been inited */
2305fe58019SAttilio Rao #define FSESS_DAEMON_CAN_SPY      0x0010 /* let non-owners access this fs */
2315fe58019SAttilio Rao                                          /* (and being observed by the daemon) */
2325fe58019SAttilio Rao #define FSESS_PUSH_SYMLINKS_IN    0x0020 /* prefix absolute symlinks with mp */
2335fe58019SAttilio Rao #define FSESS_DEFAULT_PERMISSIONS 0x0040 /* kernel does permission checking */
234e97ae4adSAlan Somers #define FSESS_ASYNC_READ          0x1000 /* allow multiple reads of some file */
235f067b609SAlan Somers #define FSESS_POSIX_LOCKS         0x2000 /* daemon supports POSIX locks */
236e5b50fe7SAlan Somers #define FSESS_EXPORT_SUPPORT      0x10000 /* daemon supports NFS-style lookups */
237ed74f781SAlan Somers #define FSESS_INTR                0x20000 /* interruptible mounts */
238a6fac00cSAlan Somers #define FSESS_MNTOPTS_MASK	( \
239a6fac00cSAlan Somers 	FSESS_DAEMON_CAN_SPY | FSESS_PUSH_SYMLINKS_IN | \
240ed74f781SAlan Somers 	FSESS_DEFAULT_PERMISSIONS | FSESS_INTR)
2415fe58019SAttilio Rao 
242c4af8b17SConrad Meyer extern int fuse_data_cache_mode;
2435fe58019SAttilio Rao 
24402295cafSConrad Meyer static inline struct fuse_data *
2455fe58019SAttilio Rao fuse_get_mpdata(struct mount *mp)
2465fe58019SAttilio Rao {
2475fe58019SAttilio Rao 	return mp->mnt_data;
2485fe58019SAttilio Rao }
2495fe58019SAttilio Rao 
25002295cafSConrad Meyer static inline bool
25137df9d3bSAlan Somers fsess_is_impl(struct mount *mp, int opcode)
25237df9d3bSAlan Somers {
25337df9d3bSAlan Somers 	struct fuse_data *data = fuse_get_mpdata(mp);
25437df9d3bSAlan Somers 
25537df9d3bSAlan Somers 	return ((data->isimpl & (1ULL << opcode)) != 0);
25637df9d3bSAlan Somers 
25737df9d3bSAlan Somers }
25837df9d3bSAlan Somers 
25937df9d3bSAlan Somers static inline bool
26037df9d3bSAlan Somers fsess_maybe_impl(struct mount *mp, int opcode)
2615fe58019SAttilio Rao {
2625fe58019SAttilio Rao 	struct fuse_data *data = fuse_get_mpdata(mp);
2635fe58019SAttilio Rao 
26402295cafSConrad Meyer 	return ((data->notimpl & (1ULL << opcode)) == 0);
2655fe58019SAttilio Rao 
2665fe58019SAttilio Rao }
26737df9d3bSAlan Somers 
26837df9d3bSAlan Somers static inline bool
26937df9d3bSAlan Somers fsess_not_impl(struct mount *mp, int opcode)
27037df9d3bSAlan Somers {
27137df9d3bSAlan Somers 	struct fuse_data *data = fuse_get_mpdata(mp);
27237df9d3bSAlan Somers 
27337df9d3bSAlan Somers 	return ((data->notimpl & (1ULL << opcode)) != 0);
27437df9d3bSAlan Somers 
27537df9d3bSAlan Somers }
27637df9d3bSAlan Somers 
27737df9d3bSAlan Somers static inline void
27837df9d3bSAlan Somers fsess_set_impl(struct mount *mp, int opcode)
27937df9d3bSAlan Somers {
28037df9d3bSAlan Somers 	struct fuse_data *data = fuse_get_mpdata(mp);
28137df9d3bSAlan Somers 
28237df9d3bSAlan Somers 	data->isimpl |= (1ULL << opcode);
28337df9d3bSAlan Somers }
28437df9d3bSAlan Somers 
28502295cafSConrad Meyer static inline void
2865fe58019SAttilio Rao fsess_set_notimpl(struct mount *mp, int opcode)
2875fe58019SAttilio Rao {
2885fe58019SAttilio Rao 	struct fuse_data *data = fuse_get_mpdata(mp);
2895fe58019SAttilio Rao 
2905fe58019SAttilio Rao 	data->notimpl |= (1ULL << opcode);
2915fe58019SAttilio Rao }
2925fe58019SAttilio Rao 
29302295cafSConrad Meyer static inline bool
2945fe58019SAttilio Rao fsess_opt_datacache(struct mount *mp)
2955fe58019SAttilio Rao {
296f8ebf1cdSAlan Somers 	struct fuse_data *data = fuse_get_mpdata(mp);
297f8ebf1cdSAlan Somers 
298f8ebf1cdSAlan Somers 	return (data->cache_mode != FUSE_CACHE_UC);
2995fe58019SAttilio Rao }
3005fe58019SAttilio Rao 
30102295cafSConrad Meyer static inline bool
3025fe58019SAttilio Rao fsess_opt_mmap(struct mount *mp)
3035fe58019SAttilio Rao {
304f8ebf1cdSAlan Somers 	return (fsess_opt_datacache(mp));
305f8ebf1cdSAlan Somers }
306f8ebf1cdSAlan Somers 
307f8ebf1cdSAlan Somers static inline bool
308f8ebf1cdSAlan Somers fsess_opt_writeback(struct mount *mp)
309f8ebf1cdSAlan Somers {
310f8ebf1cdSAlan Somers 	struct fuse_data *data = fuse_get_mpdata(mp);
311f8ebf1cdSAlan Somers 
312f8ebf1cdSAlan Somers 	return (data->cache_mode == FUSE_CACHE_WB);
3135fe58019SAttilio Rao }
3145fe58019SAttilio Rao 
315268c28edSAlan Somers /* Insert a new upgoing message */
31602295cafSConrad Meyer static inline void
3175fe58019SAttilio Rao fuse_ms_push(struct fuse_ticket *ftick)
3185fe58019SAttilio Rao {
3195fe58019SAttilio Rao 	mtx_assert(&ftick->tk_data->ms_mtx, MA_OWNED);
3205fe58019SAttilio Rao 	refcount_acquire(&ftick->tk_refcount);
3215fe58019SAttilio Rao 	STAILQ_INSERT_TAIL(&ftick->tk_data->ms_head, ftick, tk_ms_link);
3220a7c63e0SAlan Somers 	ftick->tk_data->ms_count++;
3235fe58019SAttilio Rao }
3245fe58019SAttilio Rao 
325268c28edSAlan Somers /* Insert a new upgoing message to the front of the queue */
326268c28edSAlan Somers static inline void
327268c28edSAlan Somers fuse_ms_push_head(struct fuse_ticket *ftick)
328268c28edSAlan Somers {
329268c28edSAlan Somers 	mtx_assert(&ftick->tk_data->ms_mtx, MA_OWNED);
330268c28edSAlan Somers 	refcount_acquire(&ftick->tk_refcount);
331268c28edSAlan Somers 	STAILQ_INSERT_HEAD(&ftick->tk_data->ms_head, ftick, tk_ms_link);
3320a7c63e0SAlan Somers 	ftick->tk_data->ms_count++;
333268c28edSAlan Somers }
334268c28edSAlan Somers 
33502295cafSConrad Meyer static inline struct fuse_ticket *
3365fe58019SAttilio Rao fuse_ms_pop(struct fuse_data *data)
3375fe58019SAttilio Rao {
3385fe58019SAttilio Rao 	struct fuse_ticket *ftick = NULL;
3395fe58019SAttilio Rao 
3405fe58019SAttilio Rao 	mtx_assert(&data->ms_mtx, MA_OWNED);
3415fe58019SAttilio Rao 
3425fe58019SAttilio Rao 	if ((ftick = STAILQ_FIRST(&data->ms_head))) {
3435fe58019SAttilio Rao 		STAILQ_REMOVE_HEAD(&data->ms_head, tk_ms_link);
3440a7c63e0SAlan Somers 		data->ms_count--;
3455fe58019SAttilio Rao #ifdef INVARIANTS
3460a7c63e0SAlan Somers 		MPASS(data->ms_count >= 0);
3475fe58019SAttilio Rao 		ftick->tk_ms_link.stqe_next = NULL;
3485fe58019SAttilio Rao #endif
3495fe58019SAttilio Rao 	}
3505fe58019SAttilio Rao 
35102295cafSConrad Meyer 	return (ftick);
3525fe58019SAttilio Rao }
3535fe58019SAttilio Rao 
35402295cafSConrad Meyer static inline void
3555fe58019SAttilio Rao fuse_aw_push(struct fuse_ticket *ftick)
3565fe58019SAttilio Rao {
3575fe58019SAttilio Rao 	mtx_assert(&ftick->tk_data->aw_mtx, MA_OWNED);
3585fe58019SAttilio Rao 	refcount_acquire(&ftick->tk_refcount);
3595fe58019SAttilio Rao 	TAILQ_INSERT_TAIL(&ftick->tk_data->aw_head, ftick, tk_aw_link);
3605fe58019SAttilio Rao }
3615fe58019SAttilio Rao 
36202295cafSConrad Meyer static inline void
3635fe58019SAttilio Rao fuse_aw_remove(struct fuse_ticket *ftick)
3645fe58019SAttilio Rao {
3655fe58019SAttilio Rao 	mtx_assert(&ftick->tk_data->aw_mtx, MA_OWNED);
3665fe58019SAttilio Rao 	TAILQ_REMOVE(&ftick->tk_data->aw_head, ftick, tk_aw_link);
3675fe58019SAttilio Rao #ifdef INVARIANTS
3685fe58019SAttilio Rao 	ftick->tk_aw_link.tqe_next = NULL;
3695fe58019SAttilio Rao 	ftick->tk_aw_link.tqe_prev = NULL;
3705fe58019SAttilio Rao #endif
3715fe58019SAttilio Rao }
3725fe58019SAttilio Rao 
37302295cafSConrad Meyer static inline struct fuse_ticket *
3745fe58019SAttilio Rao fuse_aw_pop(struct fuse_data *data)
3755fe58019SAttilio Rao {
37602295cafSConrad Meyer 	struct fuse_ticket *ftick;
3775fe58019SAttilio Rao 
3785fe58019SAttilio Rao 	mtx_assert(&data->aw_mtx, MA_OWNED);
3795fe58019SAttilio Rao 
38002295cafSConrad Meyer 	if ((ftick = TAILQ_FIRST(&data->aw_head)) != NULL)
3815fe58019SAttilio Rao 		fuse_aw_remove(ftick);
3825fe58019SAttilio Rao 
38302295cafSConrad Meyer 	return (ftick);
3845fe58019SAttilio Rao }
3855fe58019SAttilio Rao 
3865fe58019SAttilio Rao struct fuse_ticket *fuse_ticket_fetch(struct fuse_data *data);
3875fe58019SAttilio Rao int fuse_ticket_drop(struct fuse_ticket *ftick);
3885fe58019SAttilio Rao void fuse_insert_callback(struct fuse_ticket *ftick, fuse_handler_t *handler);
389268c28edSAlan Somers void fuse_insert_message(struct fuse_ticket *ftick, bool irq);
3905fe58019SAttilio Rao 
39102295cafSConrad Meyer static inline bool
3925fe58019SAttilio Rao fuse_libabi_geq(struct fuse_data *data, uint32_t abi_maj, uint32_t abi_min)
3935fe58019SAttilio Rao {
3945fe58019SAttilio Rao 	return (data->fuse_libabi_major > abi_maj ||
39502295cafSConrad Meyer 	    (data->fuse_libabi_major == abi_maj &&
39602295cafSConrad Meyer 	     data->fuse_libabi_minor >= abi_min));
3975fe58019SAttilio Rao }
3985fe58019SAttilio Rao 
3995fe58019SAttilio Rao struct fuse_data *fdata_alloc(struct cdev *dev, struct ucred *cred);
4005fe58019SAttilio Rao void fdata_trydestroy(struct fuse_data *data);
4015fe58019SAttilio Rao void fdata_set_dead(struct fuse_data *data);
4025fe58019SAttilio Rao 
40302295cafSConrad Meyer static inline bool
4045fe58019SAttilio Rao fdata_get_dead(struct fuse_data *data)
4055fe58019SAttilio Rao {
4065fe58019SAttilio Rao 	return (data->dataflags & FSESS_DEAD);
4075fe58019SAttilio Rao }
4085fe58019SAttilio Rao 
4095fe58019SAttilio Rao struct fuse_dispatcher {
4105fe58019SAttilio Rao 	struct fuse_ticket    *tick;
4115fe58019SAttilio Rao 	struct fuse_in_header *finh;
4125fe58019SAttilio Rao 
4135fe58019SAttilio Rao 	void    *indata;
4145fe58019SAttilio Rao 	size_t   iosize;
4155fe58019SAttilio Rao 	uint64_t nodeid;
4165fe58019SAttilio Rao 	int      answ_stat;
4175fe58019SAttilio Rao 	void    *answ;
4185fe58019SAttilio Rao };
4195fe58019SAttilio Rao 
42002295cafSConrad Meyer static inline void
4215fe58019SAttilio Rao fdisp_init(struct fuse_dispatcher *fdisp, size_t iosize)
4225fe58019SAttilio Rao {
4235fe58019SAttilio Rao 	fdisp->iosize = iosize;
4245fe58019SAttilio Rao 	fdisp->tick = NULL;
4255fe58019SAttilio Rao }
4265fe58019SAttilio Rao 
42702295cafSConrad Meyer static inline void
4285fe58019SAttilio Rao fdisp_destroy(struct fuse_dispatcher *fdisp)
4295fe58019SAttilio Rao {
4305fe58019SAttilio Rao 	fuse_ticket_drop(fdisp->tick);
4315fe58019SAttilio Rao #ifdef INVARIANTS
4325fe58019SAttilio Rao 	fdisp->tick = NULL;
4335fe58019SAttilio Rao #endif
4345fe58019SAttilio Rao }
4355fe58019SAttilio Rao 
43612292a99SAlan Somers void fdisp_refresh(struct fuse_dispatcher *fdip);
43712292a99SAlan Somers 
4385fe58019SAttilio Rao void fdisp_make(struct fuse_dispatcher *fdip, enum fuse_opcode op,
43902295cafSConrad Meyer     struct mount *mp, uint64_t nid, struct thread *td, struct ucred *cred);
4405fe58019SAttilio Rao 
4415fe58019SAttilio Rao void fdisp_make_vp(struct fuse_dispatcher *fdip, enum fuse_opcode op,
4425fe58019SAttilio Rao     struct vnode *vp, struct thread *td, struct ucred *cred);
4435fe58019SAttilio Rao 
44412292a99SAlan Somers void fdisp_refresh_vp(struct fuse_dispatcher *fdip, enum fuse_opcode op,
44512292a99SAlan Somers     struct vnode *vp, struct thread *td, struct ucred *cred);
44612292a99SAlan Somers 
4475fe58019SAttilio Rao int fdisp_wait_answ(struct fuse_dispatcher *fdip);
4485fe58019SAttilio Rao 
44902295cafSConrad Meyer static inline int
4505fe58019SAttilio Rao fdisp_simple_putget_vp(struct fuse_dispatcher *fdip, enum fuse_opcode op,
4515fe58019SAttilio Rao     struct vnode *vp, struct thread *td, struct ucred *cred)
4525fe58019SAttilio Rao {
4535fe58019SAttilio Rao 	fdisp_make_vp(fdip, op, vp, td, cred);
45402295cafSConrad Meyer 	return (fdisp_wait_answ(fdip));
4555fe58019SAttilio Rao }
4565fe58019SAttilio Rao 
4575fe58019SAttilio Rao #endif /* _FUSE_IPC_H_ */
458