xref: /titanic_52/usr/src/uts/common/fs/zfs/sys/bpobj.h (revision 732885fca09e11183dd0ea69aaaab5588fb7dbff)
1cde58dbcSMatthew Ahrens /*
2cde58dbcSMatthew Ahrens  * CDDL HEADER START
3cde58dbcSMatthew Ahrens  *
4cde58dbcSMatthew Ahrens  * The contents of this file are subject to the terms of the
5cde58dbcSMatthew Ahrens  * Common Development and Distribution License (the "License").
6cde58dbcSMatthew Ahrens  * You may not use this file except in compliance with the License.
7cde58dbcSMatthew Ahrens  *
8cde58dbcSMatthew Ahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9cde58dbcSMatthew Ahrens  * or http://www.opensolaris.org/os/licensing.
10cde58dbcSMatthew Ahrens  * See the License for the specific language governing permissions
11cde58dbcSMatthew Ahrens  * and limitations under the License.
12cde58dbcSMatthew Ahrens  *
13cde58dbcSMatthew Ahrens  * When distributing Covered Code, include this CDDL HEADER in each
14cde58dbcSMatthew Ahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15cde58dbcSMatthew Ahrens  * If applicable, add the following below this CDDL HEADER, with the
16cde58dbcSMatthew Ahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17cde58dbcSMatthew Ahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18cde58dbcSMatthew Ahrens  *
19cde58dbcSMatthew Ahrens  * CDDL HEADER END
20cde58dbcSMatthew Ahrens  */
21cde58dbcSMatthew Ahrens /*
22cde58dbcSMatthew Ahrens  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23*732885fcSMatthew Ahrens  * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
24cde58dbcSMatthew Ahrens  */
25cde58dbcSMatthew Ahrens 
26cde58dbcSMatthew Ahrens #ifndef	_SYS_BPOBJ_H
27cde58dbcSMatthew Ahrens #define	_SYS_BPOBJ_H
28cde58dbcSMatthew Ahrens 
29cde58dbcSMatthew Ahrens #include <sys/dmu.h>
30cde58dbcSMatthew Ahrens #include <sys/spa.h>
31cde58dbcSMatthew Ahrens #include <sys/txg.h>
32cde58dbcSMatthew Ahrens #include <sys/zio.h>
33cde58dbcSMatthew Ahrens #include <sys/zfs_context.h>
34cde58dbcSMatthew Ahrens 
35cde58dbcSMatthew Ahrens #ifdef	__cplusplus
36cde58dbcSMatthew Ahrens extern "C" {
37cde58dbcSMatthew Ahrens #endif
38cde58dbcSMatthew Ahrens 
39cde58dbcSMatthew Ahrens typedef struct bpobj_phys {
40cde58dbcSMatthew Ahrens 	/*
41cde58dbcSMatthew Ahrens 	 * This is the bonus buffer for the dead lists.  The object's
42cde58dbcSMatthew Ahrens 	 * contents is an array of bpo_entries blkptr_t's, representing
43cde58dbcSMatthew Ahrens 	 * a total of bpo_bytes physical space.
44cde58dbcSMatthew Ahrens 	 */
45cde58dbcSMatthew Ahrens 	uint64_t	bpo_num_blkptrs;
46cde58dbcSMatthew Ahrens 	uint64_t	bpo_bytes;
47cde58dbcSMatthew Ahrens 	uint64_t	bpo_comp;
48cde58dbcSMatthew Ahrens 	uint64_t	bpo_uncomp;
49cde58dbcSMatthew Ahrens 	uint64_t	bpo_subobjs;
50cde58dbcSMatthew Ahrens 	uint64_t	bpo_num_subobjs;
51cde58dbcSMatthew Ahrens } bpobj_phys_t;
52cde58dbcSMatthew Ahrens 
53cde58dbcSMatthew Ahrens #define	BPOBJ_SIZE_V0	(2 * sizeof (uint64_t))
54cde58dbcSMatthew Ahrens #define	BPOBJ_SIZE_V1	(4 * sizeof (uint64_t))
55cde58dbcSMatthew Ahrens 
56cde58dbcSMatthew Ahrens typedef struct bpobj {
57cde58dbcSMatthew Ahrens 	kmutex_t	bpo_lock;
58cde58dbcSMatthew Ahrens 	objset_t	*bpo_os;
59cde58dbcSMatthew Ahrens 	uint64_t	bpo_object;
60cde58dbcSMatthew Ahrens 	int		bpo_epb;
61cde58dbcSMatthew Ahrens 	uint8_t		bpo_havecomp;
62cde58dbcSMatthew Ahrens 	uint8_t		bpo_havesubobj;
63cde58dbcSMatthew Ahrens 	bpobj_phys_t	*bpo_phys;
64cde58dbcSMatthew Ahrens 	dmu_buf_t	*bpo_dbuf;
65cde58dbcSMatthew Ahrens 	dmu_buf_t	*bpo_cached_dbuf;
66cde58dbcSMatthew Ahrens } bpobj_t;
67cde58dbcSMatthew Ahrens 
68cde58dbcSMatthew Ahrens typedef int bpobj_itor_t(void *arg, const blkptr_t *bp, dmu_tx_t *tx);
69cde58dbcSMatthew Ahrens 
70cde58dbcSMatthew Ahrens uint64_t bpobj_alloc(objset_t *mos, int blocksize, dmu_tx_t *tx);
71f1745736SMatthew Ahrens uint64_t bpobj_alloc_empty(objset_t *os, int blocksize, dmu_tx_t *tx);
72cde58dbcSMatthew Ahrens void bpobj_free(objset_t *os, uint64_t obj, dmu_tx_t *tx);
73f1745736SMatthew Ahrens void bpobj_decr_empty(objset_t *os, dmu_tx_t *tx);
74cde58dbcSMatthew Ahrens 
75cde58dbcSMatthew Ahrens int bpobj_open(bpobj_t *bpo, objset_t *mos, uint64_t object);
76cde58dbcSMatthew Ahrens void bpobj_close(bpobj_t *bpo);
77cde58dbcSMatthew Ahrens 
78cde58dbcSMatthew Ahrens int bpobj_iterate(bpobj_t *bpo, bpobj_itor_t func, void *arg, dmu_tx_t *tx);
79cde58dbcSMatthew Ahrens int bpobj_iterate_nofree(bpobj_t *bpo, bpobj_itor_t func, void *, dmu_tx_t *);
80cde58dbcSMatthew Ahrens 
81cde58dbcSMatthew Ahrens void bpobj_enqueue_subobj(bpobj_t *bpo, uint64_t subobj, dmu_tx_t *tx);
82cde58dbcSMatthew Ahrens void bpobj_enqueue(bpobj_t *bpo, const blkptr_t *bp, dmu_tx_t *tx);
83cde58dbcSMatthew Ahrens 
84cde58dbcSMatthew Ahrens int bpobj_space(bpobj_t *bpo,
85cde58dbcSMatthew Ahrens     uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
86cde58dbcSMatthew Ahrens int bpobj_space_range(bpobj_t *bpo, uint64_t mintxg, uint64_t maxtxg,
87cde58dbcSMatthew Ahrens     uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
88cde58dbcSMatthew Ahrens 
89cde58dbcSMatthew Ahrens #ifdef	__cplusplus
90cde58dbcSMatthew Ahrens }
91cde58dbcSMatthew Ahrens #endif
92cde58dbcSMatthew Ahrens 
93cde58dbcSMatthew Ahrens #endif /* _SYS_BPOBJ_H */
94