xref: /minix3/lib/libpuffs/puffs_framebuf.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: puffs_framebuf.3,v 1.30 2015/02/16 10:48:50 wiz Exp $
284d9c625SLionel Sambuc.\"
384d9c625SLionel Sambuc.\" Copyright (c) 2007 Antti Kantee.  All rights reserved.
484d9c625SLionel Sambuc.\"
584d9c625SLionel Sambuc.\" Redistribution and use in source and binary forms, with or without
684d9c625SLionel Sambuc.\" modification, are permitted provided that the following conditions
784d9c625SLionel Sambuc.\" are met:
884d9c625SLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright
984d9c625SLionel Sambuc.\"    notice, this list of conditions and the following disclaimer.
1084d9c625SLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright
1184d9c625SLionel Sambuc.\"    notice, this list of conditions and the following disclaimer in the
1284d9c625SLionel Sambuc.\"    documentation and/or other materials provided with the distribution.
1384d9c625SLionel Sambuc.\"
1484d9c625SLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1584d9c625SLionel Sambuc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1684d9c625SLionel Sambuc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1784d9c625SLionel Sambuc.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1884d9c625SLionel Sambuc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1984d9c625SLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2084d9c625SLionel Sambuc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2184d9c625SLionel Sambuc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2284d9c625SLionel Sambuc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2384d9c625SLionel Sambuc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2484d9c625SLionel Sambuc.\" SUCH DAMAGE.
2584d9c625SLionel Sambuc.\"
2684d9c625SLionel Sambuc.Dd September 6, 2008
2784d9c625SLionel Sambuc.Dt PUFFS_FRAMEBUF 3
2884d9c625SLionel Sambuc.Os
2984d9c625SLionel Sambuc.Sh NAME
3084d9c625SLionel Sambuc.Nm puffs_framebuf
3184d9c625SLionel Sambuc.Nd buffering and event handling for networked file systems
3284d9c625SLionel Sambuc.Sh LIBRARY
3384d9c625SLionel Sambuc.Lb libpuffs
3484d9c625SLionel Sambuc.Sh SYNOPSIS
3584d9c625SLionel Sambuc.In puffs.h
3684d9c625SLionel Sambuc.Ft struct puffs_framebuf *
3784d9c625SLionel Sambuc.Fn puffs_framebuf_make
3884d9c625SLionel Sambuc.Ft void
3984d9c625SLionel Sambuc.Fn puffs_framebuf_destroy "struct puffs_framebuf *pufbuf"
4084d9c625SLionel Sambuc.Ft void
4184d9c625SLionel Sambuc.Fn puffs_framebuf_recycle "struct puffs_framebuf *pufbuf"
4284d9c625SLionel Sambuc.Ft int
4384d9c625SLionel Sambuc.Fn puffs_framebuf_reserve_space "struct puffs_framebuf *pufbuf" "size_t space"
4484d9c625SLionel Sambuc.Ft int
4584d9c625SLionel Sambuc.Fo puffs_framebuf_putdata
4684d9c625SLionel Sambuc.Fa "struct puffs_framebuf *pufbuf" "const void *data" "size_t dlen"
4784d9c625SLionel Sambuc.Fc
4884d9c625SLionel Sambuc.Ft int
4984d9c625SLionel Sambuc.Fo puffs_framebuf_putdata_atoff
5084d9c625SLionel Sambuc.Fa "struct puffs_framebuf *pufbuf" "size_t offset" "const void *data"
5184d9c625SLionel Sambuc.Fa "size_t dlen"
5284d9c625SLionel Sambuc.Fc
5384d9c625SLionel Sambuc.Ft int
5484d9c625SLionel Sambuc.Fo puffs_framebuf_getdata
5584d9c625SLionel Sambuc.Fa "struct puffs_framebuf *pufbuf" "void *data" "size_t dlen"
5684d9c625SLionel Sambuc.Fc
5784d9c625SLionel Sambuc.Ft int
5884d9c625SLionel Sambuc.Fo puffs_framebuf_getdata_atoff
5984d9c625SLionel Sambuc.Fa "struct puffs_framebuf *pufbuf" "size_t offset"
6084d9c625SLionel Sambuc.Fa "void *data" "size_t dlen"
6184d9c625SLionel Sambuc.Fc
6284d9c625SLionel Sambuc.Ft size_t
6384d9c625SLionel Sambuc.Fn puffs_framebuf_telloff "struct puffs_framebuf *pufbuf"
6484d9c625SLionel Sambuc.Ft size_t
6584d9c625SLionel Sambuc.Fn puffs_framebuf_tellsize "struct puffs_framebuf *pufbuf"
6684d9c625SLionel Sambuc.Ft size_t
6784d9c625SLionel Sambuc.Fn puffs_framebuf_remaining "struct puffs_framebuf *pufbuf"
6884d9c625SLionel Sambuc.Ft int
6984d9c625SLionel Sambuc.Fn puffs_framebuf_seekset "struct puffs_framebuf *pufbuf" "size_t offset"
7084d9c625SLionel Sambuc.Ft int
7184d9c625SLionel Sambuc.Fo puffs_framebuf_getwindow
7284d9c625SLionel Sambuc.Fa "struct puffs_framebuf *pufbuf" "size_t offset"
7384d9c625SLionel Sambuc.Fa "void **winp" "size_t *winlen"
7484d9c625SLionel Sambuc.Fc
7584d9c625SLionel Sambuc.Ft int
7684d9c625SLionel Sambuc.Fo puffs_framev_enqueue_cc
7784d9c625SLionel Sambuc.Fa "struct puffs_cc *pcc" "int fd" "struct puffs_framebuf *pufbuf" "int flags"
7884d9c625SLionel Sambuc.Fc
7984d9c625SLionel Sambuc.Ft void
8084d9c625SLionel Sambuc.Fo puffs_framev_cb
8184d9c625SLionel Sambuc.Fa "struct puffs_usermount *pu" "int fd" "struct puffs_framebuf *pufbuf"
8284d9c625SLionel Sambuc.Fa "void *arg" "int flags"
8384d9c625SLionel Sambuc.Fa "int error"
8484d9c625SLionel Sambuc.Fc
8584d9c625SLionel Sambuc.Ft void
8684d9c625SLionel Sambuc.Fo puffs_framev_enqueue_cb
8784d9c625SLionel Sambuc.Fa "struct puffs_usermount *pu" "int fd" "struct puffs_framebuf *pufbuf"
8884d9c625SLionel Sambuc.Fa "puffs_framebuf_cb fcb" "void *fcb_arg" "int flags"
8984d9c625SLionel Sambuc.Fc
9084d9c625SLionel Sambuc.Ft void
9184d9c625SLionel Sambuc.Fo puffs_framev_enqueue_justsend
9284d9c625SLionel Sambuc.Fa "struct puffs_usermount *pu" "int fd" "struct puffs_framebuf *pufbuf"
9384d9c625SLionel Sambuc.Fa "int waitreply" "int flags"
9484d9c625SLionel Sambuc.Fc
9584d9c625SLionel Sambuc.Ft void
9684d9c625SLionel Sambuc.Fo puffs_framev_enqueue_directsend
9784d9c625SLionel Sambuc.Fa "struct puffs_usermount *pu" "int fd" "struct puffs_framebuf *pufbuf"
9884d9c625SLionel Sambuc.Fa "int flags"
9984d9c625SLionel Sambuc.Fc
10084d9c625SLionel Sambuc.Ft void
10184d9c625SLionel Sambuc.Fo puffs_framev_enqueue_directreceive
10284d9c625SLionel Sambuc.Fa "struct puffs_usermount *pu" "int fd" "struct puffs_framebuf *pufbuf"
10384d9c625SLionel Sambuc.Fa "int flags"
10484d9c625SLionel Sambuc.Fc
10584d9c625SLionel Sambuc.Ft int
10684d9c625SLionel Sambuc.Fo puffs_framev_framebuf_ccpromote
10784d9c625SLionel Sambuc.Fa "struct puffs_framebuf *pufbuf" "struct puffs_cc *pcc"
10884d9c625SLionel Sambuc.Fc
10984d9c625SLionel Sambuc.Ft int
11084d9c625SLionel Sambuc.Fn puffs_framev_enqueue_waitevent "struct puffs_cc *pcc" "int fd" "int *what"
11184d9c625SLionel Sambuc.Ft int
11284d9c625SLionel Sambuc.Fo puffs_framev_readframe_fn
11384d9c625SLionel Sambuc.Fa "struct puffs_usermount *pu" "struct puffs_framebuf *pufbuf"
11484d9c625SLionel Sambuc.Fa "int fd" "int *done"
11584d9c625SLionel Sambuc.Fc
11684d9c625SLionel Sambuc.Ft int
11784d9c625SLionel Sambuc.Fo puffs_framev_writeframe_fn
11884d9c625SLionel Sambuc.Fa "struct puffs_usermount *pu" "struct puffs_framebuf *pufbuf"
11984d9c625SLionel Sambuc.Fa "int fd" "int *done"
12084d9c625SLionel Sambuc.Fc
12184d9c625SLionel Sambuc.Ft int
12284d9c625SLionel Sambuc.Fo puffs_framev_cmpframe_fn
12384d9c625SLionel Sambuc.Fa "struct puffs_usermount *pu"
12484d9c625SLionel Sambuc.Fa "struct puffs_framebuf *cmp1" "struct puffs_framebuf *cmp2" "int *notresp"
12584d9c625SLionel Sambuc.Fc
12684d9c625SLionel Sambuc.Ft void
12784d9c625SLionel Sambuc.Fo puffs_framev_gotframe_fn
12884d9c625SLionel Sambuc.Fa "struct puffs_usermount *pu" "struct puffs_framebuf *pufbuf"
12984d9c625SLionel Sambuc.Fc
13084d9c625SLionel Sambuc.Ft void
13184d9c625SLionel Sambuc.Fo puffs_framev_fdnotify_fn
13284d9c625SLionel Sambuc.Fa "struct puffs_usermount *pu" "int fd" "int what"
13384d9c625SLionel Sambuc.Fc
13484d9c625SLionel Sambuc.Ft void
13584d9c625SLionel Sambuc.Fo puffs_framev_init
13684d9c625SLionel Sambuc.Fa "struct puffs_usermount *pu"
13784d9c625SLionel Sambuc.Fa "puffs_framev_readframe_fn rfb" "puffs_framev_writeframe_fn wfb"
13884d9c625SLionel Sambuc.Fa "puffs_framev_cmpframe_fn cmpfb" "puffs_framev_gotframe_fn gotfb"
13984d9c625SLionel Sambuc.Fa "puffs_framev_fdnotify_fn fdnotfn"
14084d9c625SLionel Sambuc.Fc
14184d9c625SLionel Sambuc.Ft int
14284d9c625SLionel Sambuc.Fn puffs_framev_addfd "struct puffs_usermount *pu" "int fd" "int what"
14384d9c625SLionel Sambuc.Ft int
14484d9c625SLionel Sambuc.Fn puffs_framev_enablefd "struct puffs_usermount *pu" "int fd" "int what"
14584d9c625SLionel Sambuc.Ft int
14684d9c625SLionel Sambuc.Fn puffs_framev_disablefd "struct puffs_usermount *pu" "int fd" "int what"
14784d9c625SLionel Sambuc.Ft int
14884d9c625SLionel Sambuc.Fn puffs_framev_removefd "struct puffs_usermount *pu" "int fd" "int error"
14984d9c625SLionel Sambuc.Ft void
15084d9c625SLionel Sambuc.Fo puffs_framev_unmountonclose
15184d9c625SLionel Sambuc.Fa "struct puffs_usermount *pu" "int fd" "int what"
15284d9c625SLionel Sambuc.Fc
15384d9c625SLionel Sambuc.Sh DESCRIPTION
15484d9c625SLionel SambucThe
15584d9c625SLionel Sambuc.Nm
15684d9c625SLionel Sambucroutines provide buffering and an event loop structured around the
15784d9c625SLionel Sambucbuffers.
15884d9c625SLionel SambucIt operates on top of the puffs continuation framework,
15984d9c625SLionel Sambuc.Xr puffs_cc 3 ,
16084d9c625SLionel Sambucand multiplexes execution automatically to an instance whenever
16184d9c625SLionel Sambucone is runnable.
16284d9c625SLionel Sambuc.Pp
16384d9c625SLionel SambucThe file system is entered in three different ways:
16484d9c625SLionel Sambuc.Bl -bullet -offset indent
16584d9c625SLionel Sambuc.It
16684d9c625SLionel SambucAn event arrives from the kernel and the
16784d9c625SLionel Sambuc.Xr puffs_ops 3
16884d9c625SLionel Sambuccallbacks are called to start processing the event.
16984d9c625SLionel Sambuc.It
17084d9c625SLionel SambucA file system which has sent out a request receives a response.
17184d9c625SLionel SambucExecution is resumed from the place where the file system yielded.
17284d9c625SLionel Sambuc.It
17384d9c625SLionel SambucA request from a peer arrives.
17484d9c625SLionel SambucA request is an incoming PDU which is not a response to any outstanding
17584d9c625SLionel Sambucrequest.
17684d9c625SLionel Sambuc.El
17784d9c625SLionel Sambuc.Pp
17884d9c625SLionel Sambuc.Nm
17984d9c625SLionel Sambucis used by defining various callbacks and providing I/O descriptors,
18084d9c625SLionel Sambucwhich are then monitored for activity by the library.
18184d9c625SLionel SambucA descriptor, when present, can be either enabled or disabled for
18284d9c625SLionel Sambucinput and output.
18384d9c625SLionel SambucIf a descriptor is not enabled for a certain direction, the callbacks
18484d9c625SLionel Sambucwill not be called even if there were activity on the descriptor.
18584d9c625SLionel SambucFor example, even if a network socket has been added and there is
18684d9c625SLionel Sambucinput data in the socket buffer, the read callback will be called
18784d9c625SLionel Sambuconly if the socket has been enabled for reading.
18884d9c625SLionel Sambuc.Pp
18984d9c625SLionel SambucFile descriptors are treated like sockets: they have two sides, a read
19084d9c625SLionel Sambucside and a write side.
19184d9c625SLionel SambucThe framework determines that one side of the descriptor has been
19284d9c625SLionel Sambucclosed if the supplied I/O callbacks return an error or if the I/O
19384d9c625SLionel Sambucmultiplexing call says a side has been closed.
19484d9c625SLionel SambucIt is still possible, from the framework perspective, to write to a
19584d9c625SLionel Sambucfile descriptor whose read side is closed.
19684d9c625SLionel SambucHowever, it is not possible to wait for a response on such a file
19784d9c625SLionel Sambucdescriptor.
19884d9c625SLionel SambucConversely, it is possible to read responses from a descriptor whose
19984d9c625SLionel Sambucwrite side is closed.
20084d9c625SLionel SambucIt should be stressed that the implementation underlying the file
20184d9c625SLionel Sambucdescriptor might not support this.
20284d9c625SLionel Sambuc.Pp
20384d9c625SLionel SambucThe following callbacks can be defined, cf.
20484d9c625SLionel Sambuc.Fn puffs_framev_init ,
20584d9c625SLionel Sambucand all are optional.
20684d9c625SLionel SambucNone of them should block, because this would cause the entire file server
20784d9c625SLionel Sambucto block.
20884d9c625SLionel SambucOne option is to make the descriptors non-blocking before adding them.
20984d9c625SLionel Sambuc.Bl -tag -width "xfdnotfnx"
21084d9c625SLionel Sambuc.It rfb
21184d9c625SLionel SambucRead a frame from the file descriptor onto the specified buffer.
21284d9c625SLionel Sambuc.It wfb
21384d9c625SLionel SambucWrite a frame from the specified buffer into the file descriptor.
21484d9c625SLionel Sambuc.It cmpfb
21584d9c625SLionel SambucIdentify if a buffer is the response to the specified buffer.
21684d9c625SLionel Sambuc.It gotfb
21784d9c625SLionel SambucCalled iff no outstanding request matches the incoming frame.
21884d9c625SLionel SambucIn other words, this is called when we receive a request from a peer.
21984d9c625SLionel Sambuc.It fdnotfn
22084d9c625SLionel SambucReceive notifications about a change-of-state in a file descriptor's
22184d9c625SLionel Sambucstatus.
22284d9c625SLionel Sambuc.El
22384d9c625SLionel Sambuc.Pp
22484d9c625SLionel SambucBetter descriptions for each callback are given below.
22584d9c625SLionel Sambuc.Pp
22684d9c625SLionel SambucThe buffers of
22784d9c625SLionel Sambuc.Nm
22884d9c625SLionel Sambucprovide automatic memory management of buffers for the file servers.
22984d9c625SLionel SambucThey provide a cursor to the current buffer offset.
23084d9c625SLionel SambucReading or writing data through the normal routines will advance that cursor.
23184d9c625SLionel SambucAdditionally, the buffer size is provided to the user.
23284d9c625SLionel SambucIt represents the maximum offset where data was written.
23384d9c625SLionel Sambuc.Pp
23484d9c625SLionel SambucGenerally the write functions will fail if the cannot allocate enough
23584d9c625SLionel Sambucmemory to satisfy the buffer length requirements.
23684d9c625SLionel SambucRead functions will fail if the amount of data written to the buffer
23784d9c625SLionel Sambucis not large enough to satisfy the read.
23884d9c625SLionel Sambuc.Bl -tag -width xxxx
23984d9c625SLionel Sambuc.It Fn puffs_framebuf_make
24084d9c625SLionel SambucCreate a buffer.
24184d9c625SLionel SambucReturn the address of the buffer or
24284d9c625SLionel Sambuc.Dv NULL
24384d9c625SLionel Sambucin case no memory was available.
24484d9c625SLionel Sambuc.It Fn puffs_framebuf_destroy pufbuf
24584d9c625SLionel SambucFree memory used by buffer.
24684d9c625SLionel Sambuc.It Fn puffs_framebuf_recycle pufbuf
24784d9c625SLionel SambucReset offsets so that buffer can be reused.
24884d9c625SLionel SambucDoes not free memory or reallocate memory.
24984d9c625SLionel Sambuc.It Fn puffs_framebuf_reserve_space pufbuf space
25084d9c625SLionel SambucMake sure that the buffer has
25184d9c625SLionel Sambuc.Ar space
25284d9c625SLionel Sambucbytes of available memory starting from the current offset.
25384d9c625SLionel SambucThis is not strictly necessary, but can be used for optimizations
25484d9c625SLionel Sambucwhere it is known in advance how much memory will be required.
25584d9c625SLionel Sambuc.It Fn puffs_framebuf_putdata pufbuf data dlen
25684d9c625SLionel SambucWrite
25784d9c625SLionel Sambuc.Ar dlen
25884d9c625SLionel Sambucamount of data from the address
25984d9c625SLionel Sambuc.Ar data
26084d9c625SLionel Sambucinto the buffer.
26184d9c625SLionel SambucMoves the offset cursor forward
26284d9c625SLionel Sambuc.Ar dlen
26384d9c625SLionel Sambucbytes.
26484d9c625SLionel Sambuc.It Fn puffs_framebuf_putdata_atoff pufbuf offset data dlen
26584d9c625SLionel SambucLike
26684d9c625SLionel Sambuc.Fn puffs_framebuf_putdata ,
26784d9c625SLionel Sambucexcept writes data at buffer offset
26884d9c625SLionel Sambuc.Ar offset .
26984d9c625SLionel SambucIt is legal to write past the current end of the buffer.
27084d9c625SLionel SambucDoes NOT modify the current offset cursor.
27184d9c625SLionel Sambuc.It Fn puffs_framebuf_getdata pufbuf data dlen
27284d9c625SLionel SambucRead
27384d9c625SLionel Sambuc.Ar dlen
27484d9c625SLionel Sambucbytes of data from the buffer into
27584d9c625SLionel Sambuc.Ar data .
27684d9c625SLionel SambucAdvances the offset cursor.
27784d9c625SLionel Sambuc.It Fn puffs_framebuf_getdata_atoff pufbuf offset data dlen
27884d9c625SLionel SambucRead data from buffer position
27984d9c625SLionel Sambuc.Ar offset .
28084d9c625SLionel SambucDoes NOT modify the offset cursor.
28184d9c625SLionel Sambuc.It Fn puffs_framebuf_telloff pufbuf
28284d9c625SLionel SambucReturn the offset into the buffer.
28384d9c625SLionel Sambuc.It Fn puffs_framebuf_tellsize pufbuf
28484d9c625SLionel SambucReturn the maximum offset where data has been written, i.e. buffer size.
28584d9c625SLionel Sambuc.It Fn puffs_framebuf_remaining pufbuf
28684d9c625SLionel SambucDistance from current offset to the end of the buffer, i.e. size-offset.
28784d9c625SLionel Sambuc.It Fn puffs_framebuf_seekset pufbuf offset
28884d9c625SLionel SambucSet the offset cursor to the position
28984d9c625SLionel Sambuc.Ar offset .
29084d9c625SLionel SambucThis does NOT modify the buffer size, but reserves at least
29184d9c625SLionel Sambucenough memory memory for a write to
29284d9c625SLionel Sambuc.Ar offset
29384d9c625SLionel Sambucand will fail if memory cannot be allocated.
29484d9c625SLionel Sambuc.It Fn puffs_framebuf_getwindow pufbuf offset winp winlen
29584d9c625SLionel SambucGet a direct memory window into the buffer starting from
29684d9c625SLionel Sambuc.Ar offset .
29784d9c625SLionel SambucThe maximum mapped window size will be
29884d9c625SLionel Sambuc.Ar winlen
29984d9c625SLionel Sambucbytes, but this routine might return a smaller window and the caller
30084d9c625SLionel Sambucshould always check the actual mapped size after the call.
30184d9c625SLionel SambucThe window is returned in
30284d9c625SLionel Sambuc.Ar winp .
30384d9c625SLionel SambucThis function not modify the buffer offset, but it DOES set the buffer
30484d9c625SLionel Sambucsize to
30584d9c625SLionel Sambuc.Ar offset +
30684d9c625SLionel Sambuc.Ar winlen
30784d9c625SLionel Sambucin case that value is greater than the current size.
30884d9c625SLionel SambucThe window is valid until the next until the next
30984d9c625SLionel Sambuc.Fn puffs_framebuf
31084d9c625SLionel Sambuccall operating on the buffer in question.
31184d9c625SLionel Sambuc.It Fn puffs_framev_enqueue_cc pcc fd pufbuf flags
31284d9c625SLionel SambucAdd the buffer
31384d9c625SLionel Sambuc.Ar pufbuf
31484d9c625SLionel Sambucto outgoing queue of descriptor
31584d9c625SLionel Sambuc.Ar fd
31684d9c625SLionel Sambucand yield with the continuation
31784d9c625SLionel Sambuc.Ar pcc .
31884d9c625SLionel SambucExecution is resumed once a response is received.
31984d9c625SLionel SambucReturns 0 if the buffer was successfully enqueued (not necessarily
32084d9c625SLionel Sambucdelivered) and non-zero to signal a non-recoverable error.
32184d9c625SLionel Sambuc.Pp
32284d9c625SLionel SambucUsually the buffer is placed at the end of the output queue.
32384d9c625SLionel SambucHowever, if
32484d9c625SLionel Sambuc.Ar flags
32584d9c625SLionel Sambuccontains
32684d9c625SLionel Sambuc.Dv PUFFS_FBQUEUE_URGENT ,
32784d9c625SLionel Sambuc.Ar pufbuf
32884d9c625SLionel Sambucis placed in the front of the queue to be sent immediately after
32984d9c625SLionel Sambucthe current PDU (if any) has been sent.
33084d9c625SLionel Sambuc.It Fn puffs_framev_enqueue_cb pu fd pufbuf fcb fcb_arg flags
33184d9c625SLionel SambucEnqueue the buffer
33284d9c625SLionel Sambuc.Ar pufbuf
33384d9c625SLionel Sambucfor outgoing data and immediately return.
33484d9c625SLionel SambucOnce a response arrives, the callback
33584d9c625SLionel Sambuc.Fn fcb
33684d9c625SLionel Sambucwill be called with the argument
33784d9c625SLionel Sambuc.Ar fcb_arg .
33884d9c625SLionel SambucThe callback function
33984d9c625SLionel Sambuc.Fn fcb
34084d9c625SLionel Sambucis responsible for freeing the buffer.
34184d9c625SLionel SambucReturns 0 if the buffer was successfully enqueued (not necessarily
34284d9c625SLionel Sambucdelivered) and non-zero to signal a non-recoverable error.
34384d9c625SLionel Sambuc.Pp
34484d9c625SLionel SambucSee
34584d9c625SLionel Sambuc.Fn puffs_framev_enqueue_cc
34684d9c625SLionel Sambucfor
34784d9c625SLionel Sambuc.Ar flags .
34884d9c625SLionel Sambuc.It Fn puffs_framev_cb pu pufbuf arg error
34984d9c625SLionel SambucCallback function.
35084d9c625SLionel SambucCalled when a response to a specific request arrives from the server.
35184d9c625SLionel SambucIf
35284d9c625SLionel Sambuc.Ar error
35384d9c625SLionel Sambucis non-zero, the framework was unable to obtain a response and the
35484d9c625SLionel Sambucfunction should not examine the contents of
35584d9c625SLionel Sambuc.Ar pufbuf ,
35684d9c625SLionel Sambuconly do resource cleanup.
35784d9c625SLionel SambucMay not block.
35884d9c625SLionel Sambuc.It Fn puffs_framev_enqueue_justsend pu fd pufbuf waitreply flags
35984d9c625SLionel SambucEnqueue the buffer
36084d9c625SLionel Sambuc.Ar pufbuf
36184d9c625SLionel Sambucfor outgoing traffic and immediately return.
36284d9c625SLionel SambucThe parameter
36384d9c625SLionel Sambuc.Ar waitreply
36484d9c625SLionel Sambuccan be used to control if the buffer is to be freed immediately after
36584d9c625SLionel Sambucsending of if a response is expected and the buffer should be freed
36684d9c625SLionel Sambuconly after the response arrives (receiving an unexpected message from
36784d9c625SLionel Sambucthe server is treated as an error).
36884d9c625SLionel SambucReturns 0 if the buffer was successfully enqueued (not necessarily
36984d9c625SLionel Sambucdelivered) and non-zero to signal a non-recoverable error.
37084d9c625SLionel Sambuc.Pp
37184d9c625SLionel SambucSee
37284d9c625SLionel Sambuc.Fn puffs_framev_enqueue_cc
37384d9c625SLionel Sambucfor
37484d9c625SLionel Sambuc.Ar flags .
37584d9c625SLionel Sambuc.It Fn puffs_framev_enqueue_directsend pcc fd pufbuf flags
37684d9c625SLionel SambucActs like
37784d9c625SLionel Sambuc.Fn puffs_framev_enqueue_justsend
37884d9c625SLionel Sambucwith the exception that the call yields until the frame has been sent.
37984d9c625SLionel SambucAs opposed to
38084d9c625SLionel Sambuc.Fn puffs_framev_enqueue_cc ,
38184d9c625SLionel Sambucthe routine does not wait for input, but returns immediately after
38284d9c625SLionel Sambucsending the frame.
38384d9c625SLionel Sambuc.Pp
38484d9c625SLionel SambucSee
38584d9c625SLionel Sambuc.Fn puffs_framev_enqueue_cc
38684d9c625SLionel Sambucfor
38784d9c625SLionel Sambuc.Ar flags .
38884d9c625SLionel Sambuc.It Fn puffs_framev_enqueue_directreceive pcc fd pufbuf flags
38984d9c625SLionel SambucReceive data into
39084d9c625SLionel Sambuc.Ar pufbuf .
39184d9c625SLionel SambucThis routine yields until a complete frame has been read into
39284d9c625SLionel Sambucthe buffer by the readframe routine.
39384d9c625SLionel Sambuc.Pp
39484d9c625SLionel SambucSee
39584d9c625SLionel Sambuc.Fn puffs_framev_enqueue_cc
39684d9c625SLionel Sambucfor
39784d9c625SLionel Sambuc.Ar flags .
39884d9c625SLionel Sambuc.It Fn puffs_framev_framebuf_ccpromote pufbuf pcc
39984d9c625SLionel SambucPromote the framebuffer
40084d9c625SLionel Sambuc.Ar pufbuf
40184d9c625SLionel Sambucsent with
40284d9c625SLionel Sambuc.Fn puffs_framev_enqueue_cb
40384d9c625SLionel Sambucor
40484d9c625SLionel Sambuc.Fn puffs_framev_enqueue_justsend
40584d9c625SLionel Sambucto a wait using
40684d9c625SLionel Sambuc.Ar pcc
40784d9c625SLionel Sambucand yield until the result arrives.
40884d9c625SLionel SambucThe response from the file server for
40984d9c625SLionel Sambuc.Ar pufbuf
41084d9c625SLionel Sambucmust not yet have arrived.
41184d9c625SLionel SambucIf sent with
41284d9c625SLionel Sambuc.Fn puffs_framev_enqueue_justsend ,
41384d9c625SLionel Sambucthe call must be expecting a response.
41484d9c625SLionel Sambuc.It Fn puffs_framev_enqueue_waitevent pcc fd what
41584d9c625SLionel SambucWaits for an event in
41684d9c625SLionel Sambuc.Ar what
41784d9c625SLionel Sambucto happen on file descriptor
41884d9c625SLionel Sambuc.Ar fd .
41984d9c625SLionel SambucThe events which happened are returned back in
42084d9c625SLionel Sambuc.Ar what .
42184d9c625SLionel SambucThe possible events are
42284d9c625SLionel Sambuc.Dv PUFFS_FBIO_READ ,
42384d9c625SLionel Sambuc.Dv PUFFS_FBIO_WRITE ,
42484d9c625SLionel Sambucand
42584d9c625SLionel Sambuc.Dv PUFFS_FBIO_ERROR ,
42684d9c625SLionel Sambucspecifying read, write and error conditions, respectively.
42784d9c625SLionel SambucError is always checked.
42884d9c625SLionel Sambuc.Pp
42984d9c625SLionel SambucThis call does not depend on if the events were previously enabled on
43084d9c625SLionel Sambucthe file descriptor - the specified events are always checked
43184d9c625SLionel Sambucregardless.
43284d9c625SLionel Sambuc.Pp
43384d9c625SLionel SambucThere is currently no other way to cancel or timeout a call except by
43484d9c625SLionel Sambucremoving the file descriptor in question.
43584d9c625SLionel SambucThis may change in the future.
43684d9c625SLionel Sambuc.It Fn puffs_framev_readframe_fn pu pufbuf fd done
43784d9c625SLionel SambucCallback function.
43884d9c625SLionel SambucRead at most one frame from file descriptor
43984d9c625SLionel Sambuc.Ar fd
44084d9c625SLionel Sambucinto the buffer
44184d9c625SLionel Sambuc.Ar pufbuf .
44284d9c625SLionel SambucIf a complete frame is read, the value pointed to by
44384d9c625SLionel Sambuc.Ar done
44484d9c625SLionel Sambucmust be set to 1.
44584d9c625SLionel SambucThis function should return 0 on success (even if a complete frame was not
44684d9c625SLionel Sambucyet read) and a non-zero
44784d9c625SLionel Sambuc.Er errno
44884d9c625SLionel Sambucto signal a fatal error.
44984d9c625SLionel SambucIn case a fatal error is returned, the read side of the file descriptor
45084d9c625SLionel Sambucis marked closed.
45184d9c625SLionel SambucThis routine will be called with the same buffer argument until a
45284d9c625SLionel Sambuccomplete frame has been read.
45384d9c625SLionel SambucMay not block.
45484d9c625SLionel Sambuc.It Fn puffs_framev_writeframe_fn pu pufbuf fd done
45584d9c625SLionel SambucWrite the frame contained in
45684d9c625SLionel Sambuc.Ar pufbuf
45784d9c625SLionel Sambucto the file descriptor
45884d9c625SLionel Sambuc.Ar fd .
45984d9c625SLionel SambucIn case the entire frame is successfully written,
46084d9c625SLionel Sambuc.Ar *done
46184d9c625SLionel Sambucshould be set to 1.
46284d9c625SLionel SambucThis function should return 0 on success (even if a complete frame was not
46384d9c625SLionel Sambucyet written) and a non-zero
46484d9c625SLionel Sambuc.Er errno
46584d9c625SLionel Sambucto signal a fatal error.
46684d9c625SLionel SambucIn case a fatal error is returned, the write side of the file descriptor
46784d9c625SLionel Sambucis marked closed.
46884d9c625SLionel SambucThis routine will be called with the same buffer argument until the
46984d9c625SLionel Sambuccomplete frame has been written.
47084d9c625SLionel SambucMay not block.
47184d9c625SLionel Sambuc.Pp
47284d9c625SLionel SambucIt is a good idea to make sure that this function can handle a possible
47384d9c625SLionel Sambuc.Dv SIGPIPE
47484d9c625SLionel Sambuccaused by a closed connection.
47584d9c625SLionel SambucFor example, the file server can opt to trap
47684d9c625SLionel Sambuc.Dv SIGPIPE
47784d9c625SLionel Sambucor, if writing to a socket, call
47884d9c625SLionel Sambuc.Fn send
47984d9c625SLionel Sambucwith the flag
48084d9c625SLionel Sambuc.Dv MSG_NOSIGNAL
48184d9c625SLionel Sambucinstead of using
48284d9c625SLionel Sambuc.Fn write .
48384d9c625SLionel Sambuc.It Fn puffs_framev_cmpframe_fn pu pufbuf_cmp1 pufbuf_cmp2 notresp
48484d9c625SLionel SambucCompare the file system internal request tags in
48584d9c625SLionel Sambuc.Ar pufbuf_cmp1
48684d9c625SLionel Sambucand
48784d9c625SLionel Sambuc.Ar pufbuf_cmp2 .
48884d9c625SLionel SambucShould return 0 if the tags are equal, 1 if first buffer's tag is
48984d9c625SLionel Sambucgreater than the second and \-1 if it is smaller.
49084d9c625SLionel SambucThe definitions "greater" and "smaller" are used transparently by
49184d9c625SLionel Sambucthe library, e.g. like
49284d9c625SLionel Sambuc.Xr qsort 3 .
49384d9c625SLionel SambucIf it can be determined from
49484d9c625SLionel Sambuc.Ar pufbuf_cmp1
49584d9c625SLionel Sambucthat it is not a response to any outstanding request,
49684d9c625SLionel Sambuc.Ar notresp
49784d9c625SLionel Sambucshould be set to non-zero.
49884d9c625SLionel SambucThis will cause
49984d9c625SLionel Sambuc.Nm
50084d9c625SLionel Sambucto skip the test of the buffer against the rest of the outstanding
50184d9c625SLionel Sambucrequest.
50284d9c625SLionel SambucMay not block.
50384d9c625SLionel Sambuc.It Fn puffs_framev_gotframe_fn pu pufbuf
50484d9c625SLionel SambucCalled when no outstanding request matches an incoming frame.
50584d9c625SLionel SambucThe ownership of
50684d9c625SLionel Sambuc.Ar pufbuf
50784d9c625SLionel Sambucis transferred to the called function and must be destroyed once
50884d9c625SLionel Sambucprocessing is over.
50984d9c625SLionel SambucMay not block.
51084d9c625SLionel Sambuc.It Fn puffs_framev_fdnotify_fn pu fd what
51184d9c625SLionel SambucIs called when the read or write side of the file descriptor
51284d9c625SLionel Sambuc.Ar fd
51384d9c625SLionel Sambucis closed.
51484d9c625SLionel SambucIt is called once for each side, the bitmask parameter
51584d9c625SLionel Sambuc.Ar what
51684d9c625SLionel Sambucspecified what is currently closed:
51784d9c625SLionel Sambuc.Dv PUFFS_FBIO_READ
51884d9c625SLionel Sambucand
51984d9c625SLionel Sambuc.Dv PUFFS_FBIO_WRITE
52084d9c625SLionel Sambucfor read and write, respectively.
52184d9c625SLionel Sambuc.It Fn puffs_framev_init pu rfb wfb cmpfb gotfb fdnotfn
52284d9c625SLionel SambucInitializes the given callbacks to the system.
52384d9c625SLionel SambucThey will be used when
52484d9c625SLionel Sambuc.Fn puffs_mainloop
52584d9c625SLionel Sambucis called.
52684d9c625SLionel SambucThe framework provides the routines
52784d9c625SLionel Sambuc.Fn puffs_framev_removeonclose
52884d9c625SLionel Sambucand
52984d9c625SLionel Sambuc.Fn puffs_framev_unmountonclose ,
53084d9c625SLionel Sambucwhich can be given as
53184d9c625SLionel Sambuc.Ar fdnotfn .
53284d9c625SLionel SambucThe first one removes the file descriptor once both sides are closed
53384d9c625SLionel Sambucwhile the second one unmounts the file system and exits the mainloop.
53484d9c625SLionel Sambuc.It Fn puffs_framev_addfd pu fd what
53584d9c625SLionel SambucAdd file descriptor
53684d9c625SLionel Sambuc.Ar fd
53784d9c625SLionel Sambucto be handled by the framework.
53884d9c625SLionel SambucIt is legal to add a file descriptor either before calling
53984d9c625SLionel Sambuc.Fn puffs_mainloop
54084d9c625SLionel Sambucor at time when running.
54184d9c625SLionel SambucThe parameter
54284d9c625SLionel Sambuc.Ar what
54384d9c625SLionel Sambuccontrols enabling of input and output events and can be a bitwise
54484d9c625SLionel Sambuccombination of
54584d9c625SLionel Sambuc.Dv PUFFS_FBIO_READ
54684d9c625SLionel Sambucand
54784d9c625SLionel Sambuc.Dv PUFFS_FBIO_WRITE .
54884d9c625SLionel SambucIf not specified, the descriptor will be in a disabled state.
54984d9c625SLionel Sambuc.It Fn puffs_framev_enablefd pu fd what
55084d9c625SLionel SambucEnable events of type
55184d9c625SLionel Sambuc.Ar what
55284d9c625SLionel Sambucfor file descriptor
55384d9c625SLionel Sambuc.Ar fd .
55484d9c625SLionel Sambuc.It Fn puffs_framev_disablefd pu fd what
55584d9c625SLionel SambucDisable events of type
55684d9c625SLionel Sambuc.Ar what
55784d9c625SLionel Sambucfor file descriptor
55884d9c625SLionel Sambuc.Ar fd .
55984d9c625SLionel Sambuc.It Fn puffs_framev_removefd pu fd error
56084d9c625SLionel SambucRemove file descriptor
56184d9c625SLionel Sambuc.Ar fd
56284d9c625SLionel Sambucfrom the list of descriptors handled by the framework.
56384d9c625SLionel SambucRemoving a file descriptor causes all operations blocked either on
56484d9c625SLionel Sambucoutput or input to be released with the error value
56584d9c625SLionel Sambuc.Ar error .
56684d9c625SLionel SambucIn case 0 is supplied as this parameter,
56784d9c625SLionel Sambuc.Er ECONNRESET
56884d9c625SLionel Sambucis used.
56984d9c625SLionel Sambuc.Pp
57084d9c625SLionel SambucThe file system
57184d9c625SLionel Sambuc.Em must
57284d9c625SLionel Sambucexplicitly remove each fd it has added.
57384d9c625SLionel SambucA good place to do this is
57484d9c625SLionel Sambuc.Fn puffs_framev_fdnotify_fn
57584d9c625SLionel Sambucor
57684d9c625SLionel Sambuc.Fn puffs_node_reclaim ,
57784d9c625SLionel Sambucdepending a little on the structure of the file system.
57884d9c625SLionel Sambuc.It Fn puffs_framev_unmountonclose pu fd what
57984d9c625SLionel SambucThis is library provided convenience routine for
58084d9c625SLionel Sambuc.Fn puffs_framev_fdnotify_fn .
58184d9c625SLionel SambucIt unmounts the file system when both the read and write side are
58284d9c625SLionel Sambucclosed.
58384d9c625SLionel SambucIt is useful for file systems such as
58484d9c625SLionel Sambuc.Xr mount_psshfs 8
58584d9c625SLionel Sambucwhich depend on a single connection.
58684d9c625SLionel Sambuc.El
587*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES
588*0a6a1f1dSLionel SambucThese functions generally return \-1 to signal error and set
589*0a6a1f1dSLionel Sambuc.Er errno
590*0a6a1f1dSLionel Sambucto indicate the type of error.
59184d9c625SLionel Sambuc.Sh CODE REFERENCES
59284d9c625SLionel SambucThe current users of
59384d9c625SLionel Sambuc.Nm
59484d9c625SLionel Sambucin the tree are
59584d9c625SLionel Sambuc.Xr mount_psshfs 8
59684d9c625SLionel Sambucand
59784d9c625SLionel Sambuc.Xr mount_9p 8 .
59884d9c625SLionel SambucSee
59984d9c625SLionel Sambuc.Pa src/usr.sbin/puffs/mount_psshfs
60084d9c625SLionel Sambucand
60184d9c625SLionel Sambuc.Pa src/usr.sbin/puffs/mount_9p
60284d9c625SLionel Sambucfor the respective usage examples.
60384d9c625SLionel Sambuc.Sh SEE ALSO
60484d9c625SLionel Sambuc.Xr puffs 3 ,
60584d9c625SLionel Sambuc.Xr puffs_cc 3 ,
60684d9c625SLionel Sambuc.Xr puffs_ops 3
60784d9c625SLionel Sambuc.Rs
60884d9c625SLionel Sambuc.%A Antti Kantee
60984d9c625SLionel Sambuc.%D September 2007
61084d9c625SLionel Sambuc.%I Helsinki University of Technology
61184d9c625SLionel Sambuc.%R Tech Report TKK-TKO-B157
61284d9c625SLionel Sambuc.%T Using puffs for Implementing Client-Server Distributed File Systems
61384d9c625SLionel Sambuc.Re
61484d9c625SLionel Sambuc.Rs
61584d9c625SLionel Sambuc.%A Antti Kantee
61684d9c625SLionel Sambuc.%D March 2008
61784d9c625SLionel Sambuc.%J Proceedings of AsiaBSDCon 2008
61884d9c625SLionel Sambuc.%P pp. 55-70
61984d9c625SLionel Sambuc.%T Send and Receive of File System Protocols: Userspace Approach With puffs
62084d9c625SLionel Sambuc.Re
621