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