1234285Sdim/*
2234285Sdim * CDDL HEADER START
3234285Sdim *
4234285Sdim * The contents of this file are subject to the terms of the
5234285Sdim * Common Development and Distribution License (the "License").
6234285Sdim * You may not use this file except in compliance with the License.
7234285Sdim *
8234285Sdim * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9234285Sdim * or http://www.opensolaris.org/os/licensing.
10234285Sdim * See the License for the specific language governing permissions
11234285Sdim * and limitations under the License.
12234285Sdim *
13234285Sdim * When distributing Covered Code, include this CDDL HEADER in each
14234285Sdim * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15234285Sdim * If applicable, add the following below this CDDL HEADER, with the
16234285Sdim * fields enclosed by brackets "[]" replaced with your own identifying
17234285Sdim * information: Portions Copyright [yyyy] [name of copyright owner]
18249423Sdim *
19234285Sdim * CDDL HEADER END
20234285Sdim */
21234285Sdim/*
22234285Sdim * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23234285Sdim * Use is subject to license terms.
24234285Sdim */
25234285Sdim
26234285Sdim#ifndef	_SYS_BPLIST_H
27234285Sdim#define	_SYS_BPLIST_H
28234285Sdim
29234285Sdim#include <sys/dmu.h>
30234285Sdim#include <sys/spa.h>
31234285Sdim#include <sys/txg.h>
32234285Sdim#include <sys/zio.h>
33234285Sdim#include <sys/zfs_context.h>
34234285Sdim
35234285Sdim#ifdef	__cplusplus
36234285Sdimextern "C" {
37234285Sdim#endif
38234285Sdim
39234285Sdimtypedef struct bplist_phys {
40234285Sdim	/*
41234285Sdim	 * This is the bonus buffer for the dead lists.  The object's
42234285Sdim	 * contents is an array of bpl_entries blkptr_t's, representing
43234285Sdim	 * a total of bpl_bytes physical space.
44234285Sdim	 */
45234285Sdim	uint64_t	bpl_entries;
46234285Sdim	uint64_t	bpl_bytes;
47234285Sdim	uint64_t	bpl_comp;
48234285Sdim	uint64_t	bpl_uncomp;
49234285Sdim} bplist_phys_t;
50234285Sdim
51234285Sdim#define	BPLIST_SIZE_V0	(2 * sizeof (uint64_t))
52234285Sdim
53234285Sdimtypedef struct bplist_q {
54234285Sdim	blkptr_t	bpq_blk;
55234285Sdim	void		*bpq_next;
56234285Sdim} bplist_q_t;
57234285Sdim
58234285Sdimtypedef struct bplist {
59234285Sdim	kmutex_t	bpl_lock;
60234285Sdim	objset_t	*bpl_mos;
61234285Sdim	uint64_t	bpl_object;
62234285Sdim	uint8_t		bpl_blockshift;
63234285Sdim	uint8_t		bpl_bpshift;
64234285Sdim	uint8_t		bpl_havecomp;
65234285Sdim	bplist_q_t	*bpl_queue;
66234285Sdim	bplist_phys_t	*bpl_phys;
67	dmu_buf_t	*bpl_dbuf;
68	dmu_buf_t	*bpl_cached_dbuf;
69} bplist_t;
70
71typedef void bplist_sync_cb_t(void *arg, const blkptr_t *bp, dmu_tx_t *tx);
72
73extern void bplist_init(bplist_t *bpl);
74extern void bplist_fini(bplist_t *bpl);
75extern uint64_t bplist_create(objset_t *mos, int blocksize, dmu_tx_t *tx);
76extern void bplist_destroy(objset_t *mos, uint64_t object, dmu_tx_t *tx);
77extern int bplist_open(bplist_t *bpl, objset_t *mos, uint64_t object);
78extern void bplist_close(bplist_t *bpl);
79extern boolean_t bplist_empty(bplist_t *bpl);
80extern int bplist_iterate(bplist_t *bpl, uint64_t *itorp, blkptr_t *bp);
81extern int bplist_enqueue(bplist_t *bpl, const blkptr_t *bp, dmu_tx_t *tx);
82extern void bplist_enqueue_cb(void *bpl, const blkptr_t *bp, dmu_tx_t *tx);
83extern void bplist_enqueue_deferred(bplist_t *bpl, const blkptr_t *bp);
84extern void bplist_sync(bplist_t *bpl, bplist_sync_cb_t *func,
85    void *arg, dmu_tx_t *tx);
86extern void bplist_vacate(bplist_t *bpl, dmu_tx_t *tx);
87extern int bplist_space(bplist_t *bpl,
88    uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
89extern int bplist_space_birthrange(bplist_t *bpl,
90    uint64_t mintxg, uint64_t maxtxg, uint64_t *dsizep);
91
92#ifdef	__cplusplus
93}
94#endif
95
96#endif /* _SYS_BPLIST_H */
97