1219089Spjd/*
2219089Spjd * CDDL HEADER START
3219089Spjd *
4219089Spjd * The contents of this file are subject to the terms of the
5219089Spjd * Common Development and Distribution License (the "License").
6219089Spjd * You may not use this file except in compliance with the License.
7219089Spjd *
8219089Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9219089Spjd * or http://www.opensolaris.org/os/licensing.
10219089Spjd * See the License for the specific language governing permissions
11219089Spjd * and limitations under the License.
12219089Spjd *
13219089Spjd * When distributing Covered Code, include this CDDL HEADER in each
14219089Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15219089Spjd * If applicable, add the following below this CDDL HEADER, with the
16219089Spjd * fields enclosed by brackets "[]" replaced with your own identifying
17219089Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
18219089Spjd *
19219089Spjd * CDDL HEADER END
20219089Spjd */
21219089Spjd/*
22219089Spjd * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23332525Smav * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
24219089Spjd */
25219089Spjd
26219089Spjd#ifndef	_SYS_BPOBJ_H
27219089Spjd#define	_SYS_BPOBJ_H
28219089Spjd
29219089Spjd#include <sys/dmu.h>
30219089Spjd#include <sys/spa.h>
31219089Spjd#include <sys/txg.h>
32219089Spjd#include <sys/zio.h>
33219089Spjd#include <sys/zfs_context.h>
34219089Spjd
35219089Spjd#ifdef	__cplusplus
36219089Spjdextern "C" {
37219089Spjd#endif
38219089Spjd
39219089Spjdtypedef struct bpobj_phys {
40219089Spjd	/*
41219089Spjd	 * This is the bonus buffer for the dead lists.  The object's
42219089Spjd	 * contents is an array of bpo_entries blkptr_t's, representing
43219089Spjd	 * a total of bpo_bytes physical space.
44219089Spjd	 */
45219089Spjd	uint64_t	bpo_num_blkptrs;
46219089Spjd	uint64_t	bpo_bytes;
47219089Spjd	uint64_t	bpo_comp;
48219089Spjd	uint64_t	bpo_uncomp;
49219089Spjd	uint64_t	bpo_subobjs;
50219089Spjd	uint64_t	bpo_num_subobjs;
51219089Spjd} bpobj_phys_t;
52219089Spjd
53219089Spjd#define	BPOBJ_SIZE_V0	(2 * sizeof (uint64_t))
54219089Spjd#define	BPOBJ_SIZE_V1	(4 * sizeof (uint64_t))
55219089Spjd
56219089Spjdtypedef struct bpobj {
57219089Spjd	kmutex_t	bpo_lock;
58219089Spjd	objset_t	*bpo_os;
59219089Spjd	uint64_t	bpo_object;
60219089Spjd	int		bpo_epb;
61219089Spjd	uint8_t		bpo_havecomp;
62219089Spjd	uint8_t		bpo_havesubobj;
63219089Spjd	bpobj_phys_t	*bpo_phys;
64219089Spjd	dmu_buf_t	*bpo_dbuf;
65219089Spjd	dmu_buf_t	*bpo_cached_dbuf;
66219089Spjd} bpobj_t;
67219089Spjd
68219089Spjdtypedef int bpobj_itor_t(void *arg, const blkptr_t *bp, dmu_tx_t *tx);
69219089Spjd
70219089Spjduint64_t bpobj_alloc(objset_t *mos, int blocksize, dmu_tx_t *tx);
71239774Smmuint64_t bpobj_alloc_empty(objset_t *os, int blocksize, dmu_tx_t *tx);
72219089Spjdvoid bpobj_free(objset_t *os, uint64_t obj, dmu_tx_t *tx);
73239774Smmvoid bpobj_decr_empty(objset_t *os, dmu_tx_t *tx);
74219089Spjd
75219089Spjdint bpobj_open(bpobj_t *bpo, objset_t *mos, uint64_t object);
76219089Spjdvoid bpobj_close(bpobj_t *bpo);
77332525Smavboolean_t bpobj_is_open(const bpobj_t *bpo);
78219089Spjd
79219089Spjdint bpobj_iterate(bpobj_t *bpo, bpobj_itor_t func, void *arg, dmu_tx_t *tx);
80219089Spjdint bpobj_iterate_nofree(bpobj_t *bpo, bpobj_itor_t func, void *, dmu_tx_t *);
81219089Spjd
82219089Spjdvoid bpobj_enqueue_subobj(bpobj_t *bpo, uint64_t subobj, dmu_tx_t *tx);
83219089Spjdvoid bpobj_enqueue(bpobj_t *bpo, const blkptr_t *bp, dmu_tx_t *tx);
84219089Spjd
85219089Spjdint bpobj_space(bpobj_t *bpo,
86219089Spjd    uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
87219089Spjdint bpobj_space_range(bpobj_t *bpo, uint64_t mintxg, uint64_t maxtxg,
88219089Spjd    uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
89332525Smavboolean_t bpobj_is_empty(bpobj_t *bpo);
90219089Spjd
91219089Spjd#ifdef	__cplusplus
92219089Spjd}
93219089Spjd#endif
94219089Spjd
95219089Spjd#endif /* _SYS_BPOBJ_H */
96