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