1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_DFETCH_H
28 #define	_DFETCH_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/zfs_context.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 extern uint64_t	zfetch_array_rd_sz;
39 
40 struct dnode;				/* so we can reference dnode */
41 
42 typedef enum zfetch_dirn {
43 	ZFETCH_FORWARD = 1,		/* prefetch increasing block numbers */
44 	ZFETCH_BACKWARD	= -1		/* prefetch decreasing block numbers */
45 } zfetch_dirn_t;
46 
47 typedef struct zstream {
48 	uint64_t	zst_offset;	/* offset of starting block in range */
49 	uint64_t	zst_len;	/* length of range, in blocks */
50 	zfetch_dirn_t	zst_direction;	/* direction of prefetch */
51 	uint64_t	zst_stride;	/* length of stride, in blocks */
52 	uint64_t	zst_ph_offset;	/* prefetch offset, in blocks */
53 	uint64_t	zst_cap;	/* prefetch limit (cap), in blocks */
54 	kmutex_t	zst_lock;	/* protects stream */
55 	clock_t		zst_last;	/* lbolt of last prefetch */
56 	avl_node_t	zst_node;	/* embed avl node here */
57 } zstream_t;
58 
59 typedef struct zfetch {
60 	krwlock_t	zf_rwlock;	/* protects zfetch structure */
61 	list_t		zf_stream;	/* AVL tree of zstream_t's */
62 	struct dnode	*zf_dnode;	/* dnode that owns this zfetch */
63 	uint32_t	zf_stream_cnt;	/* # of active streams */
64 	uint64_t	zf_alloc_fail;	/* # of failed attempts to alloc strm */
65 } zfetch_t;
66 
67 void		dmu_zfetch_init(zfetch_t *, struct dnode *);
68 void		dmu_zfetch_rele(zfetch_t *);
69 void		dmu_zfetch(zfetch_t *, uint64_t, uint64_t);
70 
71 
72 #ifdef	__cplusplus
73 }
74 #endif
75 
76 #endif	/* _DFETCH_H */
77