xref: /illumos-gate/usr/src/uts/common/sys/fdbuffer.h (revision b94c9724)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright (c) 1998 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate  * All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _SYS_FDBUFFER_H
287c478bd9Sstevel@tonic-gate #define	_SYS_FDBUFFER_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef __cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <vm/page.h>
357c478bd9Sstevel@tonic-gate #include <sys/buf.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate typedef enum {
387c478bd9Sstevel@tonic-gate 	FDB_PAGEIO,		/* fdbuffer is a page buffer */
397c478bd9Sstevel@tonic-gate 	FDB_VADDR		/* fdbuffer is a address buffer */
407c478bd9Sstevel@tonic-gate } fdb_type_t;
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #define	FDB_READ	0x01		/* fdbuffer is readable */
437c478bd9Sstevel@tonic-gate #define	FDB_WRITE	0x02		/* fdbuffer is asked for write */
447c478bd9Sstevel@tonic-gate #define	FDB_DONE	0x04		/* fdbuffer buffer io done */
457c478bd9Sstevel@tonic-gate #define	FDB_ERROR	0x08		/* fdbuffer in error state */
467c478bd9Sstevel@tonic-gate #define	FDB_ASYNC	0x10		/* fdbuffer using async i/o requests */
477c478bd9Sstevel@tonic-gate #define	FDB_SYNC	0x20		/* fdbuffer using direct i/o requests */
487c478bd9Sstevel@tonic-gate #define	FDB_ICALLBACK	0x40		/* fdbuffer immediate call back */
497c478bd9Sstevel@tonic-gate #define	FDB_ZEROHOLE	0x80		/* fdbuffer auto-zero holes */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate typedef struct fdb_holes {
527c478bd9Sstevel@tonic-gate 	struct fdb_holes *next_hole;
537c478bd9Sstevel@tonic-gate 	u_offset_t off;		/* start offset for this hole */
547c478bd9Sstevel@tonic-gate 	size_t len;		/* length of this hole */
557c478bd9Sstevel@tonic-gate } fdb_holes_t;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate struct fdbuffer;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate typedef void (*fdb_iodone_t)(struct fdbuffer *fdbuf, void *kargp, buf_t *bp);
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * Implementation notes in the fdbuffer structure members:
647c478bd9Sstevel@tonic-gate  *
657c478bd9Sstevel@tonic-gate  * fd_state: The state variable carries four distinct types of information
667c478bd9Sstevel@tonic-gate  *           it could probably be a bit field as such.
677c478bd9Sstevel@tonic-gate  *
687c478bd9Sstevel@tonic-gate  *	READ/WRITE:
697c478bd9Sstevel@tonic-gate  *		This information is stored in fdbuffer at the time the
707c478bd9Sstevel@tonic-gate  *		The buffer is created and is used for sanity check in
717c478bd9Sstevel@tonic-gate  *		subsequent calls to fdb_iosetup(). This information
727c478bd9Sstevel@tonic-gate  *		persists for the entire life of the buffer.
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  *	[A]SYNC:
757c478bd9Sstevel@tonic-gate  *		The buffer can be either in sync or async mode. In
767c478bd9Sstevel@tonic-gate  *		async mode all calls are to be async and the i/o
777c478bd9Sstevel@tonic-gate  *		must take place for the entire range or the fdbuf
787c478bd9Sstevel@tonic-gate  *		i/o must be ended with a call to fdb_ioerrdone()
797c478bd9Sstevel@tonic-gate  *		In the async case the call back is made either
807c478bd9Sstevel@tonic-gate  *		for every i/o completed or only once at the end
817c478bd9Sstevel@tonic-gate  *		of i/o. This depends on how the call back function
827c478bd9Sstevel@tonic-gate  *		is registered. See fdb_set_iofunc(). The fdbuf has
837c478bd9Sstevel@tonic-gate  *		to be freed by the call back function.
847c478bd9Sstevel@tonic-gate  *
857c478bd9Sstevel@tonic-gate  *	ZEROHOLE:
867c478bd9Sstevel@tonic-gate  *		This is the case the holes are to be zeroed. Note
877c478bd9Sstevel@tonic-gate  *		that we do not zero the holes when fdb_add_hole() is
887c478bd9Sstevel@tonic-gate  *		getting called. We leave the zeroing of the holes to
897c478bd9Sstevel@tonic-gate  *		when a list is requested or the buffer is freed. This
907c478bd9Sstevel@tonic-gate  *		so that we can avoid zeroing pages while holding ufs
917c478bd9Sstevel@tonic-gate  *		locks.
927c478bd9Sstevel@tonic-gate  */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate typedef struct fdbuffer {
967c478bd9Sstevel@tonic-gate 	fdb_type_t fd_type;	/* type of buffer */
977c478bd9Sstevel@tonic-gate 	int	fd_state;	/* state of the fdbfer */
987c478bd9Sstevel@tonic-gate 	size_t	fd_len;		/* length of this fdbuffer */
997c478bd9Sstevel@tonic-gate 	size_t	fd_iocount;	/* total io acked, includes errors and holes */
1007c478bd9Sstevel@tonic-gate 	int	fd_iodispatch;	/* # of io's dispatched */
1017c478bd9Sstevel@tonic-gate 	int	fd_err;		/* last i/o error due from buf_t */
1027c478bd9Sstevel@tonic-gate 	ssize_t	fd_resid;	/* total len in error */
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	buf_t *fd_parentbp;	/* buf associated with parent buf */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	union {
1077c478bd9Sstevel@tonic-gate 		page_t *pages;	/* page list for FDPAGE_BUF */
1087c478bd9Sstevel@tonic-gate 		caddr_t	addr;	/* address for FDADDR_BUF */
1097c478bd9Sstevel@tonic-gate 	} fd_un;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	fdb_holes_t *fd_holes;	/* holes list if this fdbuffer has holes */
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	page_t **fd_shadow;	/* shadow pages used for direct i/o to uspace */
1147c478bd9Sstevel@tonic-gate 	struct proc *fd_procp;	/* procp used in bp for direct i/o to uspace */
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	/*
1177c478bd9Sstevel@tonic-gate 	 * Call this function when the I/O on the full range of fdbuffer
1187c478bd9Sstevel@tonic-gate 	 * is completed. The call is made only if the i/o requests
1197c478bd9Sstevel@tonic-gate 	 * are asynchronous.
1207c478bd9Sstevel@tonic-gate 	 */
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	fdb_iodone_t fd_iofunc;
1237c478bd9Sstevel@tonic-gate 	void *fd_iargp;		/* iodone function argument to be passed */
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	/*
1267c478bd9Sstevel@tonic-gate 	 * The mutex protects iodispatch, iocount, state, and resid
1277c478bd9Sstevel@tonic-gate 	 * flags and variables since they are examined and updated by
1287c478bd9Sstevel@tonic-gate 	 * async call backs. All other structure members are modified
1297c478bd9Sstevel@tonic-gate 	 * in a single threaded fashion and do not require a lock.
1307c478bd9Sstevel@tonic-gate 	 */
1317c478bd9Sstevel@tonic-gate 	kmutex_t fd_mutex;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate } fdbuffer_t;
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate #define	fd_pages	fd_un.pages
1367c478bd9Sstevel@tonic-gate #define	fd_addr		fd_un.addr
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate extern fdbuffer_t *fdb_page_create(page_t *pp, size_t len, int flag);
1397c478bd9Sstevel@tonic-gate extern fdbuffer_t *fdb_addr_create(caddr_t addr, size_t len, int flag,
1407c478bd9Sstevel@tonic-gate     page_t **pplist, struct proc *procp);
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate extern void fdb_set_iofunc(fdbuffer_t *fdbuf, fdb_iodone_t iofunc, void *ioarg,
1437c478bd9Sstevel@tonic-gate     int flags);
1447c478bd9Sstevel@tonic-gate extern fdb_holes_t *fdb_get_holes(fdbuffer_t *fdbuf);
1457c478bd9Sstevel@tonic-gate extern int fdb_get_error(fdbuffer_t *fdbuf);
1467c478bd9Sstevel@tonic-gate extern void fdb_free(fdbuffer_t *fdbuf);
1477c478bd9Sstevel@tonic-gate /*
1487c478bd9Sstevel@tonic-gate  * Need to add:
1497c478bd9Sstevel@tonic-gate  * fdb_get_iolen
1507c478bd9Sstevel@tonic-gate  */
1517c478bd9Sstevel@tonic-gate extern void fdb_add_hole(fdbuffer_t *fdbuf, u_offset_t off, size_t len);
1527c478bd9Sstevel@tonic-gate extern buf_t *fdb_iosetup(fdbuffer_t *fdbuf, u_offset_t off, size_t len,
1537c478bd9Sstevel@tonic-gate     struct vnode *vn, int flags);
154*b94c9724SToomas Soome extern int fdb_iodone(buf_t *bufp);
1557c478bd9Sstevel@tonic-gate extern void fdb_ioerrdone(fdbuffer_t *fdbuf, int error);
1567c478bd9Sstevel@tonic-gate extern void fdb_init(void);
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate #endif
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate #endif	/* _SYS_FDBUFFER_H */
163