xref: /titanic_52/usr/src/uts/common/fs/zfs/sys/bpobj.h (revision 602423772f52c941d73a9f5aa3ea7249711300fb)
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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef	_SYS_BPOBJ_H
26 #define	_SYS_BPOBJ_H
27 
28 #include <sys/dmu.h>
29 #include <sys/spa.h>
30 #include <sys/txg.h>
31 #include <sys/zio.h>
32 #include <sys/zfs_context.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 typedef struct bpobj_phys {
39 	/*
40 	 * This is the bonus buffer for the dead lists.  The object's
41 	 * contents is an array of bpo_entries blkptr_t's, representing
42 	 * a total of bpo_bytes physical space.
43 	 */
44 	uint64_t	bpo_num_blkptrs;
45 	uint64_t	bpo_bytes;
46 	uint64_t	bpo_comp;
47 	uint64_t	bpo_uncomp;
48 	uint64_t	bpo_subobjs;
49 	uint64_t	bpo_num_subobjs;
50 } bpobj_phys_t;
51 
52 #define	BPOBJ_SIZE_V0	(2 * sizeof (uint64_t))
53 #define	BPOBJ_SIZE_V1	(4 * sizeof (uint64_t))
54 
55 typedef struct bpobj {
56 	kmutex_t	bpo_lock;
57 	objset_t	*bpo_os;
58 	uint64_t	bpo_object;
59 	int		bpo_epb;
60 	uint8_t		bpo_havecomp;
61 	uint8_t		bpo_havesubobj;
62 	bpobj_phys_t	*bpo_phys;
63 	dmu_buf_t	*bpo_dbuf;
64 	dmu_buf_t	*bpo_cached_dbuf;
65 } bpobj_t;
66 
67 typedef int bpobj_itor_t(void *arg, const blkptr_t *bp, dmu_tx_t *tx);
68 
69 uint64_t bpobj_alloc(objset_t *mos, int blocksize, dmu_tx_t *tx);
70 void bpobj_free(objset_t *os, uint64_t obj, dmu_tx_t *tx);
71 
72 int bpobj_open(bpobj_t *bpo, objset_t *mos, uint64_t object);
73 void bpobj_close(bpobj_t *bpo);
74 
75 int bpobj_iterate(bpobj_t *bpo, bpobj_itor_t func, void *arg, dmu_tx_t *tx);
76 int bpobj_iterate_nofree(bpobj_t *bpo, bpobj_itor_t func, void *, dmu_tx_t *);
77 int bpobj_iterate_dbg(bpobj_t *bpo, uint64_t *itorp, blkptr_t *bp);
78 
79 void bpobj_enqueue_subobj(bpobj_t *bpo, uint64_t subobj, dmu_tx_t *tx);
80 void bpobj_enqueue(bpobj_t *bpo, const blkptr_t *bp, dmu_tx_t *tx);
81 
82 int bpobj_space(bpobj_t *bpo,
83     uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
84 int bpobj_space_range(bpobj_t *bpo, uint64_t mintxg, uint64_t maxtxg,
85     uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
86 
87 #ifdef	__cplusplus
88 }
89 #endif
90 
91 #endif /* _SYS_BPOBJ_H */
92