xref: /freebsd/sys/sys/aio.h (revision 96b8882a9648e5008cd1bc4d3bc6ce5df72b2953)
10f606585SJohn Dyson /*
20f606585SJohn Dyson  * Copyright (c) 1997 John S. Dyson.  All rights reserved.
30f606585SJohn Dyson  *
40f606585SJohn Dyson  * Redistribution and use in source and binary forms, with or without
50f606585SJohn Dyson  * modification, are permitted provided that the following conditions
60f606585SJohn Dyson  * are met:
70f606585SJohn Dyson  * 1. Redistributions of source code must retain the above copyright
80f606585SJohn Dyson  *    notice, this list of conditions and the following disclaimer.
90f606585SJohn Dyson  * 2. John S. Dyson's name may not be used to endorse or promote products
100f606585SJohn Dyson  *    derived from this software without specific prior written permission.
110f606585SJohn Dyson  *
120f606585SJohn Dyson  * DISCLAIMER:  This code isn't warranted to do anything useful.  Anything
130f606585SJohn Dyson  * bad that happens because of using this software isn't the responsibility
140f606585SJohn Dyson  * of the author.  This software is distributed AS-IS.
150f606585SJohn Dyson  *
16c3aac50fSPeter Wemm  * $FreeBSD$
170f606585SJohn Dyson  */
180f606585SJohn Dyson 
19f0231545SDmitrij Tejblum #ifndef _SYS_AIO_H_
20f0231545SDmitrij Tejblum #define	_SYS_AIO_H_
21f0231545SDmitrij Tejblum 
22501bebb5SNik Clayton #include <sys/time.h>
230f606585SJohn Dyson #include <sys/types.h>
248a6472b7SPeter Dufault #include <sys/signal.h>
25f0231545SDmitrij Tejblum 
260f606585SJohn Dyson /*
270f606585SJohn Dyson  * Returned by aio_cancel:
280f606585SJohn Dyson  *  (Note that FreeBSD's aio is not cancellable -- yet.)
290f606585SJohn Dyson  */
300f606585SJohn Dyson #define	AIO_CANCELED		0x1
3178922e41SJohn Dyson #define	AIO_NOTCANCELED		0x2
320f606585SJohn Dyson #define	AIO_ALLDONE		0x3
330f606585SJohn Dyson 
340f606585SJohn Dyson /*
350f606585SJohn Dyson  * LIO opcodes
360f606585SJohn Dyson  */
370f606585SJohn Dyson #define	LIO_NOP			0x0
380f606585SJohn Dyson #define LIO_WRITE		0x1
390f606585SJohn Dyson #define	LIO_READ		0x2
400f606585SJohn Dyson 
410f606585SJohn Dyson /*
420f606585SJohn Dyson  * LIO modes
430f606585SJohn Dyson  */
440f606585SJohn Dyson #define	LIO_NOWAIT		0x0
450f606585SJohn Dyson #define	LIO_WAIT		0x1
460f606585SJohn Dyson 
470f606585SJohn Dyson /*
487a2ac24cSPeter Dufault  * Maximum number of allowed LIO operations
497a2ac24cSPeter Dufault  */
507a2ac24cSPeter Dufault #define	AIO_LISTIO_MAX		16
517a2ac24cSPeter Dufault 
527a2ac24cSPeter Dufault /*
530f606585SJohn Dyson  * Private mode bit for aio.
540f606585SJohn Dyson  * (This bit is set by the library routine
550f606585SJohn Dyson  *  to allow the kernel to support sync
560f606585SJohn Dyson  *  or async operations in the future.)
570f606585SJohn Dyson  */
580f606585SJohn Dyson #define AIO_PMODE_SYNC		0x1
590f606585SJohn Dyson #define AIO_PMODE_DONE		0x2
600f606585SJohn Dyson #define AIO_PMODE_SUSPEND	0x4
610f606585SJohn Dyson #define AIO_PMODE_ACTIVE	0x2357c0de
620f606585SJohn Dyson 
630f606585SJohn Dyson /*
640f606585SJohn Dyson  * Private members for aiocb -- don't access
650f606585SJohn Dyson  * directly.
660f606585SJohn Dyson  */
670f606585SJohn Dyson struct __aiocb_private {
6896b8882aSAlan Cox 	long	status;
6996b8882aSAlan Cox 	long	error;
7096b8882aSAlan Cox 	long	privatemodes;
710f606585SJohn Dyson 	int	active;
720f606585SJohn Dyson 	int	tid;
730f606585SJohn Dyson 	int	threadinfo;
740f606585SJohn Dyson 	void	*userinfo;
750f606585SJohn Dyson 	void	*kernelinfo;
760f606585SJohn Dyson };
770f606585SJohn Dyson 
780f606585SJohn Dyson /*
790f606585SJohn Dyson  * I/O control block
800f606585SJohn Dyson  */
810f606585SJohn Dyson typedef struct aiocb {
820f606585SJohn Dyson 	int	aio_fildes;		/* File descriptor */
830f606585SJohn Dyson 	off_t	aio_offset;		/* File offset for I/O */
8478922e41SJohn Dyson 	volatile void *aio_buf;         /* I/O buffer in process space */
850f606585SJohn Dyson 	size_t	aio_nbytes;		/* Number of bytes for I/O */
860f606585SJohn Dyson 	struct	sigevent aio_sigevent;	/* Signal to deliver */
870f606585SJohn Dyson 	int	aio_lio_opcode;		/* LIO opcode */
880f606585SJohn Dyson 	int	aio_reqprio;		/* Request priority -- ignored */
890f606585SJohn Dyson 	struct	__aiocb_private	_aiocb_private;
900f606585SJohn Dyson } aiocb_t;
910f606585SJohn Dyson 
92664a31e4SPeter Wemm #ifndef _KERNEL
93f0231545SDmitrij Tejblum 
94f0231545SDmitrij Tejblum __BEGIN_DECLS
950f606585SJohn Dyson /*
960f606585SJohn Dyson  * Asynchronously read from a file
970f606585SJohn Dyson  */
98f0231545SDmitrij Tejblum int	aio_read(struct aiocb *);
990f606585SJohn Dyson 
1000f606585SJohn Dyson /*
1010f606585SJohn Dyson  * Asynchronously write to file
1020f606585SJohn Dyson  */
103f0231545SDmitrij Tejblum int	aio_write(struct aiocb *);
1040f606585SJohn Dyson 
1050f606585SJohn Dyson /*
1060f606585SJohn Dyson  * List I/O Asynchronously/synchronously read/write to/from file
1070f606585SJohn Dyson  *	"lio_mode" specifies whether or not the I/O is synchronous.
1080f606585SJohn Dyson  *	"acb_list" is an array of "nacb_listent" I/O control blocks.
1090f606585SJohn Dyson  *	when all I/Os are complete, the optional signal "sig" is sent.
1100f606585SJohn Dyson  */
111f0231545SDmitrij Tejblum int	lio_listio(int, struct aiocb * const [], int, struct sigevent *);
1120f606585SJohn Dyson 
1130f606585SJohn Dyson /*
1140f606585SJohn Dyson  * Get completion status
1150f606585SJohn Dyson  *	returns EINPROGRESS until I/O is complete.
1160f606585SJohn Dyson  *	this routine does not block.
1170f606585SJohn Dyson  */
118f0231545SDmitrij Tejblum int	aio_error(const struct aiocb *);
1190f606585SJohn Dyson 
1200f606585SJohn Dyson /*
1210f606585SJohn Dyson  * Finish up I/O, releasing I/O resources and returns the value
1220f606585SJohn Dyson  *	that would have been associated with a synchronous I/O request.
1230f606585SJohn Dyson  *	This routine must be called once and only once for each
1240f606585SJohn Dyson  *	I/O control block who has had I/O associated with it.
1250f606585SJohn Dyson  */
126f0231545SDmitrij Tejblum ssize_t	aio_return(struct aiocb *);
1270f606585SJohn Dyson 
1280f606585SJohn Dyson /*
1290f606585SJohn Dyson  * Cancel I/O -- implemented only to return AIO_NOTCANCELLED or
1300f606585SJohn Dyson  *	AIO_ALLDONE.  No cancellation operation will occur.
1310f606585SJohn Dyson  */
132f0231545SDmitrij Tejblum int	aio_cancel(int, struct aiocb *);
1330f606585SJohn Dyson 
1340f606585SJohn Dyson /*
1350f606585SJohn Dyson  * Suspend until all specified I/O or timeout is complete.
1360f606585SJohn Dyson  */
137f0231545SDmitrij Tejblum int	aio_suspend(const struct aiocb * const[], int, const struct timespec *);
1380f606585SJohn Dyson 
13971af8fbaSJohn Dyson /*
14071af8fbaSJohn Dyson  * Retrieve the status of the specified I/O request.
14171af8fbaSJohn Dyson  */
142f0231545SDmitrij Tejblum int	aio_error(const struct aiocb *);
143f0231545SDmitrij Tejblum 
144bfbbc4aaSJason Evans int	aio_waitcomplete(struct aiocb **, struct timespec *);
145bfbbc4aaSJason Evans 
146f0231545SDmitrij Tejblum __END_DECLS
14771af8fbaSJohn Dyson 
1485aaef07cSJohn Dyson #else
149bfbbc4aaSJason Evans /*
150bfbbc4aaSJason Evans  * Job queue item
151bfbbc4aaSJason Evans  */
152bfbbc4aaSJason Evans 
153bfbbc4aaSJason Evans #define AIOCBLIST_CANCELLED     0x1
154bfbbc4aaSJason Evans #define AIOCBLIST_RUNDOWN       0x4
155bfbbc4aaSJason Evans #define AIOCBLIST_ASYNCFREE     0x8
156bfbbc4aaSJason Evans #define AIOCBLIST_DONE          0x10
157bfbbc4aaSJason Evans 
158bfbbc4aaSJason Evans struct aiocblist {
159e3975643SJake Burkholder         TAILQ_ENTRY	(aiocblist) list;	/* List of jobs */
160e3975643SJake Burkholder         TAILQ_ENTRY	(aiocblist) plist;	/* List of jobs for proc */
161bfbbc4aaSJason Evans         int	jobflags;
162bfbbc4aaSJason Evans         int	jobstate;
163bfbbc4aaSJason Evans         int	inputcharge, outputcharge;
164bfbbc4aaSJason Evans         struct	buf *bp;		/* Buffer pointer */
165bfbbc4aaSJason Evans         struct	proc *userproc;		/* User process */
166bfbbc4aaSJason Evans         struct	file *fd_file;		/* Pointer to file structure */
167bfbbc4aaSJason Evans 	struct	aioproclist *jobaioproc;/* AIO process descriptor */
168bfbbc4aaSJason Evans         struct	aio_liojob *lio;	/* Optional lio job */
169bfbbc4aaSJason Evans         struct	aiocb *uuaiocb;		/* Pointer in userspace of aiocb */
170cb679c38SJonathan Lemon 	struct	klist klist;		/* list of knotes */
171bfbbc4aaSJason Evans         struct	aiocb uaiocb;		/* Kernel I/O control block */
172bfbbc4aaSJason Evans };
1735aaef07cSJohn Dyson 
1744807c4ebSGarrett Wollman /* Forward declarations for prototypes below. */
1754807c4ebSGarrett Wollman struct socket;
1764807c4ebSGarrett Wollman struct sockbuf;
1774807c4ebSGarrett Wollman 
1785aaef07cSJohn Dyson void	aio_proc_rundown(struct proc *p);
179bfbbc4aaSJason Evans void	aio_swake(struct socket *, struct sockbuf *);
1805aaef07cSJohn Dyson 
1810f606585SJohn Dyson #endif
1820f606585SJohn Dyson 
183bfbbc4aaSJason Evans #endif
184