1168404Spjd/*
2168404Spjd * CDDL HEADER START
3168404Spjd *
4168404Spjd * The contents of this file are subject to the terms of the
5168404Spjd * Common Development and Distribution License (the "License").
6168404Spjd * You may not use this file except in compliance with the License.
7168404Spjd *
8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9168404Spjd * or http://www.opensolaris.org/os/licensing.
10168404Spjd * See the License for the specific language governing permissions
11168404Spjd * and limitations under the License.
12168404Spjd *
13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each
14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15168404Spjd * If applicable, add the following below this CDDL HEADER, with the
16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying
17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
18168404Spjd *
19168404Spjd * CDDL HEADER END
20168404Spjd */
21168404Spjd/*
22208130Smm * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23168404Spjd * Use is subject to license terms.
24168404Spjd */
25168404Spjd
26168404Spjd#ifndef	_DFETCH_H
27168404Spjd#define	_DFETCH_H
28168404Spjd
29168404Spjd#include <sys/zfs_context.h>
30168404Spjd
31168404Spjd#ifdef	__cplusplus
32168404Spjdextern "C" {
33168404Spjd#endif
34168404Spjd
35168404Spjdextern uint64_t	zfetch_array_rd_sz;
36168404Spjd
37168404Spjdstruct dnode;				/* so we can reference dnode */
38168404Spjd
39168404Spjdtypedef enum zfetch_dirn {
40168404Spjd	ZFETCH_FORWARD = 1,		/* prefetch increasing block numbers */
41168404Spjd	ZFETCH_BACKWARD	= -1		/* prefetch decreasing block numbers */
42168404Spjd} zfetch_dirn_t;
43168404Spjd
44168404Spjdtypedef struct zstream {
45168404Spjd	uint64_t	zst_offset;	/* offset of starting block in range */
46168404Spjd	uint64_t	zst_len;	/* length of range, in blocks */
47168404Spjd	zfetch_dirn_t	zst_direction;	/* direction of prefetch */
48168404Spjd	uint64_t	zst_stride;	/* length of stride, in blocks */
49168404Spjd	uint64_t	zst_ph_offset;	/* prefetch offset, in blocks */
50168404Spjd	uint64_t	zst_cap;	/* prefetch limit (cap), in blocks */
51168404Spjd	kmutex_t	zst_lock;	/* protects stream */
52168404Spjd	clock_t		zst_last;	/* lbolt of last prefetch */
53168404Spjd	avl_node_t	zst_node;	/* embed avl node here */
54168404Spjd} zstream_t;
55168404Spjd
56168404Spjdtypedef struct zfetch {
57168404Spjd	krwlock_t	zf_rwlock;	/* protects zfetch structure */
58168404Spjd	list_t		zf_stream;	/* AVL tree of zstream_t's */
59168404Spjd	struct dnode	*zf_dnode;	/* dnode that owns this zfetch */
60168404Spjd	uint32_t	zf_stream_cnt;	/* # of active streams */
61168404Spjd	uint64_t	zf_alloc_fail;	/* # of failed attempts to alloc strm */
62168404Spjd} zfetch_t;
63168404Spjd
64208130Smmvoid		zfetch_init(void);
65208130Smmvoid		zfetch_fini(void);
66208130Smm
67168404Spjdvoid		dmu_zfetch_init(zfetch_t *, struct dnode *);
68168404Spjdvoid		dmu_zfetch_rele(zfetch_t *);
69168404Spjdvoid		dmu_zfetch(zfetch_t *, uint64_t, uint64_t, int);
70168404Spjd
71168404Spjd
72168404Spjd#ifdef	__cplusplus
73168404Spjd}
74168404Spjd#endif
75168404Spjd
76168404Spjd#endif	/* _DFETCH_H */
77