1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * This file and its contents are supplied under the terms of the 4 * Common Development and Distribution License ("CDDL"), version 1.0. 5 * You may only use this file in accordance with the terms of version 6 * 1.0 of the CDDL. 7 * 8 * A full copy of the text of the CDDL should have accompanied this 9 * source. A copy of the CDDL is also available via the Internet at 10 * https://opensource.org/license/CDDL-1.0. 11 */ 12 /* 13 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 14 * Copyright (c) 2015, 2019 by Delphix. All rights reserved. 15 */ 16 17 #ifndef _SYS_BPOBJ_H 18 #define _SYS_BPOBJ_H 19 20 #include <sys/dmu.h> 21 #include <sys/spa.h> 22 #include <sys/txg.h> 23 #include <sys/zio.h> 24 #include <sys/zfs_context.h> 25 #include <sys/bplist.h> 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 typedef struct bpobj_phys { 32 /* 33 * This is the bonus buffer for the dead lists. The object's 34 * contents is an array of bpo_entries blkptr_t's, representing 35 * a total of bpo_bytes physical space. 36 */ 37 uint64_t bpo_num_blkptrs; 38 uint64_t bpo_bytes; 39 uint64_t bpo_comp; 40 uint64_t bpo_uncomp; 41 uint64_t bpo_subobjs; 42 uint64_t bpo_num_subobjs; 43 uint64_t bpo_num_freed; 44 } bpobj_phys_t; 45 46 #define BPOBJ_SIZE_V0 (2 * sizeof (uint64_t)) 47 #define BPOBJ_SIZE_V1 (4 * sizeof (uint64_t)) 48 #define BPOBJ_SIZE_V2 (6 * sizeof (uint64_t)) 49 50 typedef struct bpobj { 51 kmutex_t bpo_lock; 52 objset_t *bpo_os; 53 uint64_t bpo_object; 54 uint32_t bpo_epb; 55 uint8_t bpo_havecomp; 56 uint8_t bpo_havesubobj; 57 uint8_t bpo_havefreed; 58 bpobj_phys_t *bpo_phys; 59 dmu_buf_t *bpo_dbuf; 60 dmu_buf_t *bpo_cached_dbuf; 61 } bpobj_t; 62 63 typedef int bpobj_itor_t(void *arg, const blkptr_t *bp, boolean_t bp_freed, 64 dmu_tx_t *tx); 65 66 uint64_t bpobj_alloc(objset_t *mos, int blocksize, dmu_tx_t *tx); 67 uint64_t bpobj_alloc_empty(objset_t *os, int blocksize, dmu_tx_t *tx); 68 void bpobj_free(objset_t *os, uint64_t obj, dmu_tx_t *tx); 69 void bpobj_decr_empty(objset_t *os, dmu_tx_t *tx); 70 71 int bpobj_open(bpobj_t *bpo, objset_t *mos, uint64_t object); 72 void bpobj_close(bpobj_t *bpo); 73 boolean_t bpobj_is_open(const 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 *, uint64_t *); 77 int livelist_bpobj_iterate_from_nofree(bpobj_t *bpo, bpobj_itor_t func, 78 void *arg, int64_t start); 79 80 void bpobj_enqueue_subobj(bpobj_t *bpo, uint64_t subobj, dmu_tx_t *tx); 81 void bpobj_prefetch_subobj(bpobj_t *bpo, uint64_t subobj); 82 void bpobj_enqueue(bpobj_t *bpo, const blkptr_t *bp, boolean_t bp_freed, 83 dmu_tx_t *tx); 84 85 int bpobj_space(bpobj_t *bpo, 86 uint64_t *usedp, uint64_t *compp, uint64_t *uncompp); 87 int bpobj_space_range(bpobj_t *bpo, uint64_t mintxg, uint64_t maxtxg, 88 uint64_t *usedp, uint64_t *compp, uint64_t *uncompp); 89 boolean_t bpobj_is_empty(bpobj_t *bpo); 90 91 int bplist_append_cb(void *arg, const blkptr_t *bp, boolean_t bp_freed, 92 dmu_tx_t *tx); 93 94 #ifdef __cplusplus 95 } 96 #endif 97 98 #endif /* _SYS_BPOBJ_H */ 99