cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens/*
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * CDDL HEADER START
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens *
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * The contents of this file are subject to the terms of the
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * Common Development and Distribution License (the "License").
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * You may not use this file except in compliance with the License.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens *
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * or http://www.opensolaris.org/os/licensing.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * See the License for the specific language governing permissions
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * and limitations under the License.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens *
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * When distributing Covered Code, include this CDDL HEADER in each
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * If applicable, add the following below this CDDL HEADER, with the
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * fields enclosed by brackets "[]" replaced with your own identifying
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens *
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * CDDL HEADER END
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens */
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens/*
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
732885fca09e11183dd0ea69aaaab5588fb7dbffMatthew Ahrens * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens */
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#ifndef _SYS_BPOBJ_H
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#define _SYS_BPOBJ_H
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#include <sys/dmu.h>
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#include <sys/spa.h>
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#include <sys/txg.h>
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#include <sys/zio.h>
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#include <sys/zfs_context.h>
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#ifdef __cplusplus
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensextern "C" {
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#endif
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrenstypedef struct bpobj_phys {
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens /*
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * This is the bonus buffer for the dead lists. The object's
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * contents is an array of bpo_entries blkptr_t's, representing
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * a total of bpo_bytes physical space.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens */
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint64_t bpo_num_blkptrs;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint64_t bpo_bytes;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint64_t bpo_comp;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint64_t bpo_uncomp;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint64_t bpo_subobjs;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint64_t bpo_num_subobjs;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens} bpobj_phys_t;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#define BPOBJ_SIZE_V0 (2 * sizeof (uint64_t))
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#define BPOBJ_SIZE_V1 (4 * sizeof (uint64_t))
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrenstypedef struct bpobj {
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens kmutex_t bpo_lock;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens objset_t *bpo_os;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint64_t bpo_object;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens int bpo_epb;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint8_t bpo_havecomp;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint8_t bpo_havesubobj;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens bpobj_phys_t *bpo_phys;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dmu_buf_t *bpo_dbuf;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dmu_buf_t *bpo_cached_dbuf;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens} bpobj_t;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrenstypedef int bpobj_itor_t(void *arg, const blkptr_t *bp, dmu_tx_t *tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensuint64_t bpobj_alloc(objset_t *mos, int blocksize, dmu_tx_t *tx);
f17457368189aa911f774c38c1f21875a568bdcaMatthew Ahrensuint64_t bpobj_alloc_empty(objset_t *os, int blocksize, dmu_tx_t *tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensvoid bpobj_free(objset_t *os, uint64_t obj, dmu_tx_t *tx);
f17457368189aa911f774c38c1f21875a568bdcaMatthew Ahrensvoid bpobj_decr_empty(objset_t *os, dmu_tx_t *tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensint bpobj_open(bpobj_t *bpo, objset_t *mos, uint64_t object);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensvoid bpobj_close(bpobj_t *bpo);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensint bpobj_iterate(bpobj_t *bpo, bpobj_itor_t func, void *arg, dmu_tx_t *tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensint bpobj_iterate_nofree(bpobj_t *bpo, bpobj_itor_t func, void *, dmu_tx_t *);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensvoid bpobj_enqueue_subobj(bpobj_t *bpo, uint64_t subobj, dmu_tx_t *tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensvoid bpobj_enqueue(bpobj_t *bpo, const blkptr_t *bp, dmu_tx_t *tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensint bpobj_space(bpobj_t *bpo,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensint bpobj_space_range(bpobj_t *bpo, uint64_t mintxg, uint64_t maxtxg,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#ifdef __cplusplus
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens}
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#endif
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#endif /* _SYS_BPOBJ_H */