xref: /minix3/lib/libpuffs/puffs.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: puffs.3,v 1.61 2015/02/16 10:48:34 wiz Exp $
2490e0de5SThomas Veerman.\"
3490e0de5SThomas Veerman.\" Copyright (c) 2006, 2007, 2008 Antti Kantee.  All rights reserved.
4490e0de5SThomas Veerman.\"
5490e0de5SThomas Veerman.\" Redistribution and use in source and binary forms, with or without
6490e0de5SThomas Veerman.\" modification, are permitted provided that the following conditions
7490e0de5SThomas Veerman.\" are met:
8490e0de5SThomas Veerman.\" 1. Redistributions of source code must retain the above copyright
9490e0de5SThomas Veerman.\"    notice, this list of conditions and the following disclaimer.
10490e0de5SThomas Veerman.\" 2. Redistributions in binary form must reproduce the above copyright
11490e0de5SThomas Veerman.\"    notice, this list of conditions and the following disclaimer in the
12490e0de5SThomas Veerman.\"    documentation and/or other materials provided with the distribution.
13490e0de5SThomas Veerman.\"
14490e0de5SThomas Veerman.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15490e0de5SThomas Veerman.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16490e0de5SThomas Veerman.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17490e0de5SThomas Veerman.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18490e0de5SThomas Veerman.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19490e0de5SThomas Veerman.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20490e0de5SThomas Veerman.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21490e0de5SThomas Veerman.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22490e0de5SThomas Veerman.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23490e0de5SThomas Veerman.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24490e0de5SThomas Veerman.\" SUCH DAMAGE.
25490e0de5SThomas Veerman.\"
26*0a6a1f1dSLionel Sambuc.Dd February 15, 2015
27490e0de5SThomas Veerman.Dt PUFFS 3
28490e0de5SThomas Veerman.Os
29490e0de5SThomas Veerman.Sh NAME
30490e0de5SThomas Veerman.Nm puffs
31490e0de5SThomas Veerman.Nd Pass-to-Userspace Framework File System development interface
32490e0de5SThomas Veerman.Sh LIBRARY
33490e0de5SThomas Veerman.Lb libpuffs
34490e0de5SThomas Veerman.Sh SYNOPSIS
35490e0de5SThomas Veerman.In puffs.h
36490e0de5SThomas Veerman.Ft struct puffs_usermount *
37490e0de5SThomas Veerman.Fo puffs_init
38490e0de5SThomas Veerman.Fa "struct puffs_ops *pops" "const char *mntfromname" "const char *puffsname"
39490e0de5SThomas Veerman.Fa "void *private" "uint32_t flags"
40490e0de5SThomas Veerman.Fc
41490e0de5SThomas Veerman.Ft int
42490e0de5SThomas Veerman.Fo puffs_mount
43490e0de5SThomas Veerman.Fa "struct puffs_usermount *pu" "const char *dir" "int mntflags"
44490e0de5SThomas Veerman.Fa "puffs_cookie_t root_cookie"
45490e0de5SThomas Veerman.Fc
46490e0de5SThomas Veerman.Ft int
47490e0de5SThomas Veerman.Fn puffs_getselectable "struct puffs_usermount *pu"
48490e0de5SThomas Veerman.Ft int
49490e0de5SThomas Veerman.Fn puffs_setblockingmode "struct puffs_usermount *pu" "int mode"
50490e0de5SThomas Veerman.Ft int
51490e0de5SThomas Veerman.Fn puffs_getstate "struct puffs_usermount *pu"
52490e0de5SThomas Veerman.Ft int
53490e0de5SThomas Veerman.Fn puffs_setstacksize "struct puffs_usermount *pu" "size_t stacksize"
54490e0de5SThomas Veerman.Ft void
55490e0de5SThomas Veerman.Fn puffs_setroot "struct puffs_usermount *pu" "struct puffs_node *node"
56490e0de5SThomas Veerman.Ft void
57490e0de5SThomas Veerman.Fo puffs_setrootinfo
58490e0de5SThomas Veerman.Fa "struct puffs_usermount *pu" "enum vtype vt" "vsize_t vsize" "dev_t rdev"
59490e0de5SThomas Veerman.Fc
60490e0de5SThomas Veerman.Ft struct puffs_node *
61490e0de5SThomas Veerman.Fn puffs_getroot "struct puffs_usermount *pu"
62490e0de5SThomas Veerman.Ft void *
63490e0de5SThomas Veerman.Fn puffs_getspecific "struct puffs_usermount *pu"
64490e0de5SThomas Veerman.Ft void
65490e0de5SThomas Veerman.Fn puffs_setspecific "struct puffs_usermount *pu" "void *private"
66490e0de5SThomas Veerman.Ft void
67490e0de5SThomas Veerman.Fn puffs_setmaxreqlen "struct puffs_usermount *pu" "size_t maxreqlen"
68490e0de5SThomas Veerman.Ft size_t
69490e0de5SThomas Veerman.Fn puffs_getmaxreqlen "struct puffs_usermount *pu"
70490e0de5SThomas Veerman.Ft void
71490e0de5SThomas Veerman.Fn puffs_setfhsize "struct puffs_usermount *pu" "size_t fhsize" "int flags"
72490e0de5SThomas Veerman.Ft void
73490e0de5SThomas Veerman.Fn puffs_setncookiehash "struct puffs_usermount *pu" "int nhashes"
74490e0de5SThomas Veerman.Ft void
75490e0de5SThomas Veerman.Fn puffs_ml_loop_fn "struct puffs_usermount *pu"
76490e0de5SThomas Veerman.Ft void
77490e0de5SThomas Veerman.Fn puffs_ml_setloopfn "struct puffs_usermount *pu" "puffs_ml_loop_fn lfn"
78490e0de5SThomas Veerman.Ft void
79490e0de5SThomas Veerman.Fn puffs_ml_settimeout "struct puffs_usermount *pu" "struct timespec *ts"
80490e0de5SThomas Veerman.Ft int
81490e0de5SThomas Veerman.Fn puffs_daemon "struct puffs_usermount *pu" "int nochdir" "int noclose"
82490e0de5SThomas Veerman.Ft int
83490e0de5SThomas Veerman.Fn puffs_mainloop "struct puffs_usermount *pu"
84490e0de5SThomas Veerman.Ft int
8584d9c625SLionel Sambuc.Fn puffs_unmountonsignal "int sig" "bool ignoresig"
8684d9c625SLionel Sambuc.Ft int
87490e0de5SThomas Veerman.Fo puffs_dispatch_create
88490e0de5SThomas Veerman.Fa "struct puffs_usermount *pu" "struct puffs_framebuf *pb"
89490e0de5SThomas Veerman.Fa "struct puffs_cc **pccp"
90490e0de5SThomas Veerman.Fc
91490e0de5SThomas Veerman.Ft int
9284d9c625SLionel Sambuc.Fn puffs_dispatch_exec "struct puffs_cc *pcc" "struct puffs_framebuf **pbp"
93490e0de5SThomas Veerman.Sh DESCRIPTION
94490e0de5SThomas Veerman.Nm
95490e0de5SThomas Veermanprovides a framework for creating file systems as userspace servers.
96490e0de5SThomas VeermanOperations are transported from the kernel virtual file system layer
97490e0de5SThomas Veermanto the concrete implementation behind
98490e0de5SThomas Veerman.Nm ,
99490e0de5SThomas Veermanwhere they are processed and results are sent back to the kernel.
100490e0de5SThomas Veerman.Pp
101490e0de5SThomas VeermanIt is possible to use
102490e0de5SThomas Veerman.Nm
103490e0de5SThomas Veermanin two different ways.
104490e0de5SThomas VeermanCalling
105490e0de5SThomas Veerman.Fn puffs_mainloop
106490e0de5SThomas Veermantakes execution context away from the caller and automatically handles
107490e0de5SThomas Veermanall requests by using the callbacks.
108490e0de5SThomas VeermanBy using
109490e0de5SThomas Veerman.Xr puffs_framebuf 3
110490e0de5SThomas Veermanin conjuction with
111490e0de5SThomas Veerman.Fn puffs_mainloop ,
112490e0de5SThomas Veermanit is possible to handle I/O to and from file descriptors.
113490e0de5SThomas VeermanThis is suited e.g. for distributed file servers.
114490e0de5SThomas Veerman.Ss Library operation
115490e0de5SThomas VeermanOperations on the library always require a pointer to the opaque context
116490e0de5SThomas Veermanidentifier,
117490e0de5SThomas Veerman.Va struct puffs_usermount .
118490e0de5SThomas VeermanIt is obtained by calling
119490e0de5SThomas Veerman.Fn puffs_init .
120490e0de5SThomas Veerman.Pp
121490e0de5SThomas Veerman.Nm
122490e0de5SThomas Veermanoperates using operation callbacks.
123490e0de5SThomas VeermanThey can be initialized using the macro
124490e0de5SThomas Veerman.Fn PUFFSOP_SET pops fsname type opname ,
125490e0de5SThomas Veermanwhich will initialize the operation
126490e0de5SThomas Veerman.Fn puffs_type_opname
127490e0de5SThomas Veermanin
128490e0de5SThomas Veerman.Fa pops
129490e0de5SThomas Veermanto
130490e0de5SThomas Veerman.Fn fsname_type_opname .
131490e0de5SThomas VeermanAll operations are initialized to a default state with the call
132490e0de5SThomas Veerman.Fn PUFFSOP_INIT pops .
133490e0de5SThomas VeermanAll of the VFS routines are mandatory, but all of the node operations
134490e0de5SThomas Veermanwith the exception of
135490e0de5SThomas Veerman.Fn puffs_node_lookup
136490e0de5SThomas Veermanare optional.
137490e0de5SThomas VeermanHowever, leaving operations blank will naturally have an effect on the
138490e0de5SThomas Veermanfeatures available from the file system implementation.
139490e0de5SThomas Veerman.Bl -tag -width xxxx
140490e0de5SThomas Veerman.It Fn puffs_init pops mntfromname puffsname private flags
141490e0de5SThomas VeermanInitializes the library context.
142490e0de5SThomas Veerman.Ar pops
143490e0de5SThomas Veermanspecifies the callback operations vector.
144490e0de5SThomas Veerman.Ar mntfromname
145490e0de5SThomas Veermanis device the file system is mounted from.
146490e0de5SThomas VeermanThis can be for example a block device such as
147490e0de5SThomas Veerman.Pa /dev/wd0a
148490e0de5SThomas Veermanor, if the file system is pseudo file system, the
149490e0de5SThomas Veerman.Nm
150490e0de5SThomas Veermandevice name can be given by
151490e0de5SThomas Veerman.Dv _PATH_PUFFS .
152490e0de5SThomas VeermanThis value is used for example in the first column of the output of
153490e0de5SThomas Veerman.Xr mount 8
154490e0de5SThomas Veermanand
155490e0de5SThomas Veerman.Xr df 1 .
156490e0de5SThomas Veerman.Ar puffsname
157490e0de5SThomas Veermanis the file system type.
158490e0de5SThomas VeermanIt will always be prepended with the string "puffs|".
159490e0de5SThomas VeermanIf possible, file server binaries should be named using the format
160490e0de5SThomas Veerman"mount_myfsnamehere" and this value should equal "myfsnamehere".
161490e0de5SThomas VeermanA file system specific context pointer can optionally be given in
162490e0de5SThomas Veerman.Ar private .
163490e0de5SThomas VeermanThis can be retrieved by
164490e0de5SThomas Veerman.Fn puffs_getspecific .
165490e0de5SThomas VeermanFlags for
166490e0de5SThomas Veerman.Nm
167490e0de5SThomas Veermancan be given via
168490e0de5SThomas Veerman.Fa pflags .
169490e0de5SThomas VeermanCurrently the following flags are supported:
170490e0de5SThomas Veerman.Bl -tag -width "XPUFFS_KFLAG_LOOKUP_FULLPNBUF"
171490e0de5SThomas Veerman.It Dv PUFFS_KFLAG_NOCACHE_NAME
172490e0de5SThomas VeermanDo not enter pathname components into the name cache.
173490e0de5SThomas VeermanThis means that every time the kernel does a lookup for a
174490e0de5SThomas Veermancomponentname, the file server will be consulted.
175490e0de5SThomas Veerman.It Dv PUFFS_KFLAG_NOCACHE_PAGE
176490e0de5SThomas VeermanDo not use the page cache.
177490e0de5SThomas VeermanThis means that all reads and writes to regular file are
178490e0de5SThomas Veermanpropagated to the file server for handling.
179490e0de5SThomas VeermanThis option makes a difference only for regular files.
180490e0de5SThomas Veerman.It Dv PUFFS_KFLAG_NOCACHE
181490e0de5SThomas VeermanAn alias for both
182490e0de5SThomas Veerman.Dv PUFFS_KFLAG_NOCACHE_NAME
183490e0de5SThomas Veermanand
184490e0de5SThomas Veerman.Dv PUFFS_KFLAG_NOCACHE_PAGE .
185490e0de5SThomas Veerman.It Dv PUFFS_KFLAG_ALLOPS
186490e0de5SThomas VeermanThis flag requests that all operations are sent to userspace.
187490e0de5SThomas VeermanNormally the kernel shortcircuits unimplemented operations.
188490e0de5SThomas VeermanThis flag is mostly useful for debugging purposes.
189490e0de5SThomas Veerman.It Dv PUFFS_KFLAG_WTCACHE
190490e0de5SThomas VeermanSet the file system cache behavior as write-through.
191490e0de5SThomas VeermanThis means that all writes are immediately issued to the file server
192490e0de5SThomas Veermaninstead of being flushed in file system sync.
193490e0de5SThomas VeermanThis is useful especially for distributed file systems.
194490e0de5SThomas Veerman.It Dv PUFFS_KFLAG_IAONDEMAND
195490e0de5SThomas VeermanIssue inactive only on demand.
196490e0de5SThomas VeermanIf a file server defines the inactive method, call it only if the file
197490e0de5SThomas Veermanserver has explicitly requested that inactive be called for the
198490e0de5SThomas Veermannode in question.
199490e0de5SThomas VeermanOnce inactive has been called for a node, it will not be called
200490e0de5SThomas Veermanagain unless the request to call inactive is reissued by the file server.
201490e0de5SThomas VeermanSee
202490e0de5SThomas Veerman.Fn puffs_setback
203490e0de5SThomas Veermanin
204490e0de5SThomas Veerman.Xr puffs_ops 3
205490e0de5SThomas Veermanfor more information.
206490e0de5SThomas Veerman.It Dv PUFFS_KFLAG_LOOKUP_FULLPNBUF
207490e0de5SThomas VeermanThis flag affects only the parameter
208490e0de5SThomas Veerman.Ar pcn to
209490e0de5SThomas Veerman.Fn puffs_node_lookup .
210490e0de5SThomas VeermanIf this flag is not given, only the next pathname component under
211490e0de5SThomas Veermanlookup is found from
212490e0de5SThomas Veerman.Ar pcn-\*[Gt]pcn_name .
213490e0de5SThomas VeermanIf this flag is given, the full path the kernel was
214490e0de5SThomas Veermanasked to resolve can be found from there.
215490e0de5SThomas Veerman.It Dv PUFFS_FLAG_BUILDPATH
216490e0de5SThomas VeermanThe framework will build a complete path name, which is supplied
217490e0de5SThomas Veermanwith each operation and can be found from the
218490e0de5SThomas Veerman.Va pcn_po_full.po_path
219490e0de5SThomas Veermanfield in a
220490e0de5SThomas Veerman.Vt struct puffs_cn .
221490e0de5SThomas VeermanThe option assumes that the framework can map a cookie to a
222490e0de5SThomas Veerman.Vt struct puffs_node .
223490e0de5SThomas VeermanSee
224490e0de5SThomas Veerman.Sx Cookies
225490e0de5SThomas Veermanfor more information on cookie mapping.
226490e0de5SThomas VeermanSee
227490e0de5SThomas Veerman.Xr puffs_path 3
228490e0de5SThomas Veermanfor more information on library calls involving paths.
229490e0de5SThomas Veerman.It Dv PUFFS_FLAG_HASHPATH
230490e0de5SThomas VeermanCalculate a hash of the path into the path object field
231490e0de5SThomas Veerman.Va po_hash .
232490e0de5SThomas VeermanThis hash value is used by
233490e0de5SThomas Veerman.Fn puffs_path_walkcmp
234490e0de5SThomas Veermanto avoid doing a full comparison for every path equal in length to
235490e0de5SThomas Veermanthe one searched for.
236490e0de5SThomas VeermanEspecially if the file system uses the abovementioned function, it
237490e0de5SThomas Veermanis a good idea to define this flag.
23884d9c625SLionel Sambuc.It Dv PUFFS_FLAG_PNCOOKIE
23984d9c625SLionel SambucTell puffs that cookies map to
24084d9c625SLionel Sambuc.Vt struct pnode .
24184d9c625SLionel SambucThis is automagically set if
24284d9c625SLionel Sambuc.Fn puffs_pn_new
24384d9c625SLionel Sambucis called.
24484d9c625SLionel Sambuc.It Dv PUFFS_KFLAG_CACHE_FS_TTL
24584d9c625SLionel SambucEnforce name and attribute caches based on file system-supplied TTL.
24684d9c625SLionel SambucIn lookup, create, mknod, mkdir, and symlink, the file system must
24784d9c625SLionel Sambucupdate the node attributes, their TTL, and the node name TTL through
24884d9c625SLionel Sambuc.Fn puffs_newinfo_setva ,
24984d9c625SLionel Sambuc.Fn puffs_newinfo_setvattl ,
25084d9c625SLionel Sambucand
25184d9c625SLionel Sambuc.Fn puffs_newinfo_setcnttl .
25284d9c625SLionel Sambuc.Pp
25384d9c625SLionel SambucAdditionally,
25484d9c625SLionel Sambuc.Fn puffs_node_getattr_ttl
25584d9c625SLionel Sambucand
25684d9c625SLionel Sambuc.Fn puffs_node_setattr_ttl
25784d9c625SLionel Sambucwill be called instead of
25884d9c625SLionel Sambuc.Fn puffs_node_getattr
25984d9c625SLionel Sambucand
26084d9c625SLionel Sambuc.Fn puffs_node_setattr .
26184d9c625SLionel Sambuc.It Dv PUFFS_KFLAG_CACHE_DOTDOT
26284d9c625SLionel SambucNever send lookups for
26384d9c625SLionel Sambuc.Dq ..
26484d9c625SLionel Sambucto the file system.
26584d9c625SLionel SambucParent vnodes are all kept active until their children are reclaimed.
266*0a6a1f1dSLionel Sambuc.It Dv PUFFS_KFLAG_NOFLUSH_META
267*0a6a1f1dSLionel SambucDo not send metadata cache flushes for time and size to the file system,
268*0a6a1f1dSLionel Sambucwhich should take care of updating the values on its own.
269490e0de5SThomas Veerman.It Dv PUFFS_FLAG_OPDUMP
270490e0de5SThomas VeermanThis option makes the framework dump a textual representation of
271490e0de5SThomas Veermaneach operation before executing it.
272490e0de5SThomas VeermanIt is useful for debugging purposes.
273490e0de5SThomas Veerman.El
274490e0de5SThomas Veerman.El
275490e0de5SThomas Veerman.Pp
276490e0de5SThomas VeermanThe following functions can be used to query or modify the global
277490e0de5SThomas Veermanstate of the file system.
278490e0de5SThomas VeermanNote, that all calls are not available at all times.
279490e0de5SThomas Veerman.Bl -tag -width xxxx
280490e0de5SThomas Veerman.It Fn puffs_getselectable "pu"
281490e0de5SThomas VeermanReturns a handle to do I/O multiplexing with:
282490e0de5SThomas Veerman.Xr select 2 ,
283490e0de5SThomas Veerman.Xr poll 2 ,
284490e0de5SThomas Veermanand
285490e0de5SThomas Veerman.Xr kqueue 2
286490e0de5SThomas Veermanare all examples of acceptable operations.
287490e0de5SThomas Veerman.It Fn puffs_setblockingmode "pu" "mode"
288490e0de5SThomas VeermanSets the file system upstream access to blocking or non-blocking mode.
289490e0de5SThomas VeermanAcceptable values for the argument are
290490e0de5SThomas Veerman.Dv PUFFSDEV_BLOCK
291490e0de5SThomas Veermanand
292490e0de5SThomas Veerman.Dv PUFFSDEV_NONBLOCK .
293490e0de5SThomas Veerman.Pp
294490e0de5SThomas VeermanThis routine can be called only after calling
295490e0de5SThomas Veerman.Fn puffs_mount .
296490e0de5SThomas Veerman.It Fn puffs_getstate "pu"
297490e0de5SThomas VeermanReturns the state of the file system.
298490e0de5SThomas VeermanIt is maintained by the framework and is mostly useful for the framework
299490e0de5SThomas Veermanitself.
300490e0de5SThomas VeermanPossible values are
301490e0de5SThomas Veerman.Dv PUFFS_STATE_BEFOREMOUNT ,
302490e0de5SThomas Veerman.Dv PUFFS_STATE_RUNNING ,
303490e0de5SThomas Veerman.Dv PUFFS_STATE_UNMOUNTING
304490e0de5SThomas Veermanand
305490e0de5SThomas Veerman.Dv PUFFS_STATE_UNMOUNTED .
306490e0de5SThomas Veerman.It Fn puffs_setstacksize "pu" "stacksize"
307490e0de5SThomas VeermanSets the stack size used when running callbacks.
308490e0de5SThomas VeermanThe default is
309490e0de5SThomas Veerman.Dv PUFFS_STACKSIZE_DEFAULT
310490e0de5SThomas Veermanbytes of stack space per request.
311490e0de5SThomas VeermanThe minimum stacksize is architecture-dependent and can be specified
312490e0de5SThomas Veermanby using the opaque constant
313490e0de5SThomas Veerman.Dv PUFFS_STACKSIZE_MIN .
314490e0de5SThomas Veerman.It Fn puffs_setroot "pu" "node"
315490e0de5SThomas VeermanSets the root node of mount
316490e0de5SThomas Veerman.Fa pu
317490e0de5SThomas Veermanto
318490e0de5SThomas Veerman.Fa "node" .
319490e0de5SThomas VeermanSetting the root node is currently required only if the path
320490e0de5SThomas Veermanframework is used, see
321490e0de5SThomas Veerman.Xr puffs_path 3 .
322490e0de5SThomas Veerman.It Fn puffs_setrootinfo pu vt vsize rdev
323490e0de5SThomas VeermanThe default root node is a directory.
324490e0de5SThomas VeermanIn case the file system wants something different, it can call this
325490e0de5SThomas Veermanfunction and set the type, size and possible device type to whatever
326490e0de5SThomas Veermanit wants.
327490e0de5SThomas VeermanThis routine is independent of
328490e0de5SThomas Veerman.Fn puffs_setroot .
329490e0de5SThomas Veerman.It Fn puffs_getroot "pu"
330490e0de5SThomas VeermanReturns the root node set earlier.
331490e0de5SThomas Veerman.It Fn puffs_getspecific "pu"
332490e0de5SThomas VeermanReturns the
333490e0de5SThomas Veerman.Fa private
334490e0de5SThomas Veermanargument of
335490e0de5SThomas Veerman.Fn puffs_init .
336490e0de5SThomas Veerman.It Fn puffs_setspecific "pu" "private"
337490e0de5SThomas VeermanCan be used to set the specific data after the call to
338490e0de5SThomas Veerman.Fn puffs_init .
339490e0de5SThomas Veerman.It Fn puffs_setmaxreqlen "pu" "maxreqlen"
340490e0de5SThomas VeermanIn case the file system desires a maximum buffer length different from
341490e0de5SThomas Veermanthe default, the amount
342490e0de5SThomas Veerman.Fa maxreqlen
343490e0de5SThomas Veermanwill be requested from the kernel when the file system is mounted.
344490e0de5SThomas Veerman.Pp
345490e0de5SThomas VeermanIt is legal to call this function only between
346490e0de5SThomas Veerman.Fn puffs_init
347490e0de5SThomas Veermanand
348490e0de5SThomas Veerman.Fn puffs_mount .
349490e0de5SThomas Veerman.Pp
350490e0de5SThomas Veerman.Em NOTE
351490e0de5SThomas VeermanThis does not currently work.
352490e0de5SThomas Veerman.It Fn puffs_getmaxreqlen "pu"
353490e0de5SThomas VeermanReturns the maximum request length the kernel will need for a single
354490e0de5SThomas Veermanrequest.
355490e0de5SThomas Veerman.Pp
356490e0de5SThomas Veerman.Em NOTE
357490e0de5SThomas VeermanThis does not currently work.
358490e0de5SThomas Veerman.It Fn puffs_setfhsize "pu" "fhsize" "flags"
359490e0de5SThomas VeermanSets the desired file handle size.
360490e0de5SThomas VeermanThis must be called if the file system wishes to support NFS exporting
361490e0de5SThomas Veermanfile systems of the
362490e0de5SThomas Veerman.Fn fh*
363490e0de5SThomas Veermanfamily of function calls.
364490e0de5SThomas Veerman.Pp
365490e0de5SThomas VeermanIn case all nodes in the file system produce the same length file handle,
366490e0de5SThomas Veermanit must be supplied as
367490e0de5SThomas Veerman.Fa fhsize .
368490e0de5SThomas VeermanIn this case, the file system may ignore the length parameters in the
369490e0de5SThomas Veermanfile handle callback routines, as the kernel will always pass the
370490e0de5SThomas Veermancorrect length buffer.
371490e0de5SThomas VeermanHowever, if the file handle size varies according to file, the argument
372490e0de5SThomas Veerman.Fa fhsize
373490e0de5SThomas Veermandefines the maximum size of a file handle for the file system.
374490e0de5SThomas VeermanIn this case the file system must take care of the handle lengths by
375490e0de5SThomas Veermanitself in the file handle callbacks, see
376490e0de5SThomas Veerman.Xr puffs_ops 3
377490e0de5SThomas Veermanfor more information.
378490e0de5SThomas VeermanAlso, the flag
379490e0de5SThomas Veerman.Dv PUFFS_FHFLAG_DYNAMIC
380490e0de5SThomas Veermanmust be provided in the argument
381490e0de5SThomas Veerman.Fa flags .
382490e0de5SThomas Veerman.Pp
383490e0de5SThomas VeermanIn case the file system wants to sanity check its file handle lengths
384490e0de5SThomas Veermanfor the limits of NFS, it can supply
385490e0de5SThomas Veerman.Dv PUFFS_FHFLAG_NFSV2
386490e0de5SThomas Veermanand
387490e0de5SThomas Veerman.Dv PUFFS_FHFLAG_NFSV3
388490e0de5SThomas Veermanin the
389490e0de5SThomas Veerman.Fa flags
390490e0de5SThomas Veermanparameter.
391490e0de5SThomas VeermanIt is especially important to note that these are not directly the
392490e0de5SThomas Veermanlimits specified by the protocols, as the kernel uses some bytes from
393490e0de5SThomas Veermanthe buffer space.
394490e0de5SThomas VeermanIn case the file handles are too large, mount will return an error.
395490e0de5SThomas Veerman.Pp
396490e0de5SThomas VeermanIt is legal to call this function only between
397490e0de5SThomas Veerman.Fn puffs_init
398490e0de5SThomas Veermanand
399490e0de5SThomas Veerman.Fn puffs_mount .
400490e0de5SThomas Veerman.It Fn puffs_setncookiehash "pu" "ncookiehash"
401490e0de5SThomas VeermanThe parameter
402490e0de5SThomas Veerman.Fa ncookiehash
403490e0de5SThomas Veermancontrols the amount of hash buckets the kernel has for reverse lookups
404490e0de5SThomas Veermanfrom cookie to vnode.
405490e0de5SThomas VeermanTechnically the default is enough, but a memory/time tradeoff can be
406490e0de5SThomas Veermanmade by increasing this for file systems which know they will have
407490e0de5SThomas Veermanvery many active files.
408490e0de5SThomas Veerman.Pp
409490e0de5SThomas VeermanIt is legal to call this function only between
410490e0de5SThomas Veerman.Fn puffs_init
411490e0de5SThomas Veermanand
412490e0de5SThomas Veerman.Fn puffs_mount .
413490e0de5SThomas Veerman.El
414490e0de5SThomas Veerman.Pp
415490e0de5SThomas VeermanAfter the correct setup for the library has been established and the
416490e0de5SThomas Veermanbackend has been initialized the file system is made operational by calling
417490e0de5SThomas Veerman.Fn puffs_mount .
418490e0de5SThomas VeermanAfter this function returns the file system should start processing requests.
419490e0de5SThomas Veerman.Bl -tag -width xxxx
420490e0de5SThomas Veerman.It Fn puffs_mount pu dir mntflags root_cookie
421490e0de5SThomas Veerman.Ar pu
422490e0de5SThomas Veermanis the library context pointer from
423490e0de5SThomas Veerman.Fn puffs_init .
424490e0de5SThomas VeermanThe argument
425490e0de5SThomas Veerman.Fa dir
426490e0de5SThomas Veermansignifies the mount point and
427490e0de5SThomas Veerman.Fa mntflags
428490e0de5SThomas Veermanis the flagset given to
429490e0de5SThomas Veerman.Xr mount 2 .
430490e0de5SThomas VeermanThe value
431490e0de5SThomas Veerman.Ar root_cookie
432490e0de5SThomas Veermanwill be used as the cookie for the file system root node.
433490e0de5SThomas Veerman.El
434490e0de5SThomas Veerman.Ss Using the built-in eventloop
435490e0de5SThomas Veerman.Bl -tag -width xxxx
436490e0de5SThomas Veerman.It Fn puffs_ml_loop_fn pu
437490e0de5SThomas VeermanLoop function signature.
438490e0de5SThomas Veerman.It Fn puffs_ml_setloopfn pu lfn
439490e0de5SThomas VeermanSet loop function to
440490e0de5SThomas Veerman.Ar lfn .
441490e0de5SThomas VeermanThis function is called once each time the event loop loops.
442490e0de5SThomas VeermanIt is not a well-defined interval, but it can be made fairly regular
443490e0de5SThomas Veermanby setting the loop timeout by
444490e0de5SThomas Veerman.Fn puffs_ml_settimeout .
445490e0de5SThomas Veerman.It Fn puffs_ml_settimeout pu ts
446490e0de5SThomas VeermanSets the loop timeout to
447490e0de5SThomas Veerman.Ar ts
448490e0de5SThomas Veermanor disables it if
449490e0de5SThomas Veerman.Ar ts
450490e0de5SThomas Veermanis
451490e0de5SThomas Veerman.Dv NULL .
452490e0de5SThomas VeermanThis can be used to roughly control how often the loop callback
453490e0de5SThomas Veerman.Fn lfn
454490e0de5SThomas Veermanis called
455490e0de5SThomas Veerman.It Fn puffs_daemon pu nochdir noclose
456490e0de5SThomas VeermanDetach from the console like
457490e0de5SThomas Veerman.Fn daemon 3 .
458490e0de5SThomas VeermanThis call synchronizes with
459490e0de5SThomas Veerman.Fn puffs_mount
460490e0de5SThomas Veermanand the foreground process does not exit before the file system mount
461490e0de5SThomas Veermancall has returned from the kernel.
46284d9c625SLionel SambucSince this routine internally calls fork, it has to be called
46384d9c625SLionel Sambuc.Em before
46484d9c625SLionel Sambuc.Fn puffs_mount .
465490e0de5SThomas Veerman.It Fn puffs_mainloop pu flags
466490e0de5SThomas VeermanHandle all requests automatically until the file system is unmounted.
467490e0de5SThomas VeermanIt returns 0 if the file system was successfully unmounted or \-1 if it
468490e0de5SThomas Veermanwas killed in action.
469490e0de5SThomas Veerman.Pp
470490e0de5SThomas VeermanIn case
471490e0de5SThomas Veerman.Xr puffs_framebuf 3
472490e0de5SThomas Veermanhas been initialized, I/O from the relevant descriptors is processed
473490e0de5SThomas Veermanautomatically by the eventloop.
47484d9c625SLionel Sambuc.It Fn puffs_unmountonsignal signum ignoresig
47584d9c625SLionel SambucCause all file servers within the process to initiate unmount upon
47684d9c625SLionel Sambucreceipt of signal
47784d9c625SLionel Sambuc.Ar signum .
47884d9c625SLionel SambucThis works only for servers which call
47984d9c625SLionel Sambuc.Fn puffs_mainloop
48084d9c625SLionel Sambucand must be called before any server within the process enters the mainloop.
48184d9c625SLionel SambucThe process signal handler is still called before starting the unmount
48284d9c625SLionel Sambucprocedure.
48384d9c625SLionel SambucThe parameter
48484d9c625SLionel Sambuc.Ar ignoresig
48584d9c625SLionel Sambucis provided as a convenience and tells if to install a signal handler
48684d9c625SLionel Sambucto ignore
48784d9c625SLionel Sambuc.Ar sig
48884d9c625SLionel Sambucso that the process will not e.g. terminate based on the default action
48984d9c625SLionel Sambucbefore the file system unmount can be initiated.
490490e0de5SThomas Veerman.It Fn puffs_dispatch_create pu pb pccp
491490e0de5SThomas Veerman.It Fn puffs_dispatch_exec pcc pbp
492490e0de5SThomas VeermanIn case the use of
493490e0de5SThomas Veerman.Fn puffs_mainloop
494490e0de5SThomas Veermanis not possible, requests may be dispatched manually.
495490e0de5SThomas VeermanHowever, as this is less efficient than using the mainloop,
496490e0de5SThomas Veermanit should never be the first preference.
497490e0de5SThomas Veerman.Pp
498490e0de5SThomas VeermanCalling
499490e0de5SThomas Veerman.Fn puffs_dispatch_create
500490e0de5SThomas Veermancreates a dispatch request.
501490e0de5SThomas VeermanThe argument
502490e0de5SThomas Veerman.Ar pb
503490e0de5SThomas Veermanshould contains a valid request and upon success
504490e0de5SThomas Veerman.Ar pccp
505490e0de5SThomas Veermanwill contain a valid request context.
506490e0de5SThomas VeermanThis context is passed to
507490e0de5SThomas Veerman.Fn puffs_dispatch_exec
508490e0de5SThomas Veermanto execute the request.
509490e0de5SThomas VeermanIf the request yielded before completing, the routine returns 0,
510490e0de5SThomas Veermanotherwise 1.
511490e0de5SThomas VeermanWhen the routine completes,
512490e0de5SThomas Veerman.Ar pcc
513490e0de5SThomas Veermanis made invalid and a pointer to the processed buffer is placed in
514490e0de5SThomas Veerman.Ar pbp .
515490e0de5SThomas VeermanIt is the responsibility of the caller to send the response (if
516490e0de5SThomas Veermannecessary) and destroy the buffer.
517490e0de5SThomas Veerman.Pp
518490e0de5SThomas VeermanSee
519490e0de5SThomas Veerman.Xr puffs_cc 3
520490e0de5SThomas Veermanand
521490e0de5SThomas Veerman.Xr puffs_framebuf 3
522490e0de5SThomas Veermanfor further information.
523490e0de5SThomas Veerman.El
524490e0de5SThomas Veerman.Ss Cookies
525490e0de5SThomas VeermanEvery file (regular file, directory, device node, ...) instance is
526490e0de5SThomas Veermanattached to the kernel using a cookie.
527490e0de5SThomas VeermanA cookie should uniquely map to a file during its lifetime.
528490e0de5SThomas VeermanIf file instances are kept in memory, a simple strategy is to use
529490e0de5SThomas Veermanthe virtual address of the structure describing the file.
530490e0de5SThomas VeermanThe cookie can be recycled when
531490e0de5SThomas Veerman.Fn puffs_node_reclaim
532490e0de5SThomas Veermanis called for a node.
533490e0de5SThomas Veerman.Pp
534490e0de5SThomas VeermanFor some operations (such as building paths) the framework needs to map
535490e0de5SThomas Veermanthe cookie to the framework-level structure describing a file,
536490e0de5SThomas Veerman.Vt struct puffs_node .
537490e0de5SThomas VeermanIt is advisable to simply use the
538490e0de5SThomas Veerman.Vt struct puffs_node
539490e0de5SThomas Veermanaddress as a cookie and store file system specific data in the private
540490e0de5SThomas Veermanportion of
541490e0de5SThomas Veerman.Vt struct puffs_node .
542490e0de5SThomas VeermanThe library assumes this by default.
543490e0de5SThomas VeermanIf it is not desirable, the file system implementation can call
544490e0de5SThomas Veerman.Fn puffs_set_cookiemap
545490e0de5SThomas Veermanto provide an alternative cookie-to-node mapping function.
546490e0de5SThomas Veerman.Sh SEE ALSO
547490e0de5SThomas Veerman.Xr mount 2 ,
548490e0de5SThomas Veerman.Xr puffs_cc 3 ,
549490e0de5SThomas Veerman.Xr puffs_cred 3 ,
550490e0de5SThomas Veerman.Xr puffs_flush 3 ,
551490e0de5SThomas Veerman.Xr puffs_framebuf 3 ,
552490e0de5SThomas Veerman.Xr puffs_node 3 ,
553490e0de5SThomas Veerman.Xr puffs_ops 3 ,
554490e0de5SThomas Veerman.Xr puffs_path 3 ,
555490e0de5SThomas Veerman.Xr refuse 3 ,
556490e0de5SThomas Veerman.Xr puffs 4
557490e0de5SThomas Veerman.Rs
558490e0de5SThomas Veerman.%A Antti Kantee
559490e0de5SThomas Veerman.%D March 2007
560490e0de5SThomas Veerman.%J Proceedings of AsiaBSDCon 2007
561490e0de5SThomas Veerman.%P pp. 29-42
562490e0de5SThomas Veerman.%T puffs - Pass-to-Userspace Framework File System
563490e0de5SThomas Veerman.Re
564490e0de5SThomas Veerman.Rs
565490e0de5SThomas Veerman.%A Antti Kantee
566490e0de5SThomas Veerman.%D September 2007
567490e0de5SThomas Veerman.%I Helsinki University of Technology
568490e0de5SThomas Veerman.%R Tech Report TKK-TKO-B157
569490e0de5SThomas Veerman.%T Using puffs for Implementing Client-Server Distributed File Systems
570490e0de5SThomas Veerman.Re
571490e0de5SThomas Veerman.Rs
572490e0de5SThomas Veerman.%A Antti Kantee
573490e0de5SThomas Veerman.%A Alistair Crooks
574490e0de5SThomas Veerman.%D September 2007
575490e0de5SThomas Veerman.%J EuroBSDCon 2007
576490e0de5SThomas Veerman.%T ReFUSE: Userspace FUSE Reimplementation Using puffs
577490e0de5SThomas Veerman.Re
578490e0de5SThomas Veerman.Rs
579490e0de5SThomas Veerman.%A Antti Kantee
580490e0de5SThomas Veerman.%D March 2008
581490e0de5SThomas Veerman.%J Proceedings of AsiaBSDCon 2008
582490e0de5SThomas Veerman.%P pp. 55-70
583490e0de5SThomas Veerman.%T Send and Receive of File System Protocols: Userspace Approach With puffs
584490e0de5SThomas Veerman.Re
585490e0de5SThomas Veerman.Sh HISTORY
586490e0de5SThomas VeermanAn unsupported experimental version of
587490e0de5SThomas Veerman.Nm
588490e0de5SThomas Veermanfirst appeared in
589490e0de5SThomas Veerman.Nx 4.0 .
590490e0de5SThomas VeermanA stable version appeared in
591490e0de5SThomas Veerman.Nx 5.0 .
592490e0de5SThomas Veerman.Sh AUTHORS
59384d9c625SLionel Sambuc.An Antti Kantee Aq Mt pooka@iki.fi
594