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) 2018, 2019 by Delphix. All rights reserved. 15 */ 16 17 #ifndef _SYS_DSL_DEADLIST_H 18 #define _SYS_DSL_DEADLIST_H 19 20 #include <sys/bpobj.h> 21 #include <sys/zfs_context.h> 22 #include <sys/zthr.h> 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 struct dmu_buf; 29 struct dsl_pool; 30 struct dsl_dataset; 31 32 typedef struct dsl_deadlist_phys { 33 uint64_t dl_used; 34 uint64_t dl_comp; 35 uint64_t dl_uncomp; 36 uint64_t dl_pad[37]; /* pad out to 320b for future expansion */ 37 } dsl_deadlist_phys_t; 38 39 typedef struct dsl_deadlist { 40 objset_t *dl_os; 41 uint64_t dl_object; 42 avl_tree_t dl_tree; /* contains dsl_deadlist_entry_t */ 43 avl_tree_t dl_cache; /* contains dsl_deadlist_cache_entry_t */ 44 boolean_t dl_havetree; 45 boolean_t dl_havecache; 46 struct dmu_buf *dl_dbuf; 47 dsl_deadlist_phys_t *dl_phys; 48 kmutex_t dl_lock; 49 50 /* if it's the old on-disk format: */ 51 bpobj_t dl_bpobj; 52 boolean_t dl_oldfmt; 53 } dsl_deadlist_t; 54 55 typedef struct dsl_deadlist_cache_entry { 56 avl_node_t dlce_node; 57 uint64_t dlce_mintxg; 58 uint64_t dlce_bpobj; 59 uint64_t dlce_bytes; 60 uint64_t dlce_comp; 61 uint64_t dlce_uncomp; 62 } dsl_deadlist_cache_entry_t; 63 64 typedef struct dsl_deadlist_entry { 65 avl_node_t dle_node; 66 uint64_t dle_mintxg; 67 bpobj_t dle_bpobj; 68 } dsl_deadlist_entry_t; 69 70 typedef struct livelist_condense_entry { 71 struct dsl_dataset *ds; 72 dsl_deadlist_entry_t *first; 73 dsl_deadlist_entry_t *next; 74 boolean_t syncing; 75 boolean_t cancelled; 76 } livelist_condense_entry_t; 77 78 extern uint64_t zfs_livelist_max_entries; 79 extern int zfs_livelist_min_percent_shared; 80 81 typedef int deadlist_iter_t(void *args, dsl_deadlist_entry_t *dle); 82 83 int dsl_deadlist_open(dsl_deadlist_t *dl, objset_t *os, uint64_t object); 84 void dsl_deadlist_close(dsl_deadlist_t *dl); 85 void dsl_deadlist_iterate(dsl_deadlist_t *dl, deadlist_iter_t func, void *arg); 86 uint64_t dsl_deadlist_alloc(objset_t *os, dmu_tx_t *tx); 87 void dsl_deadlist_free(objset_t *os, uint64_t dlobj, dmu_tx_t *tx); 88 void dsl_deadlist_insert(dsl_deadlist_t *dl, const blkptr_t *bp, 89 boolean_t free, dmu_tx_t *tx); 90 int dsl_deadlist_insert_alloc_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx); 91 int dsl_deadlist_insert_free_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx); 92 void dsl_deadlist_add_key(dsl_deadlist_t *dl, uint64_t mintxg, dmu_tx_t *tx); 93 void dsl_deadlist_remove_key(dsl_deadlist_t *dl, uint64_t mintxg, dmu_tx_t *tx); 94 void dsl_deadlist_remove_entry(dsl_deadlist_t *dl, uint64_t mintxg, 95 dmu_tx_t *tx); 96 dsl_deadlist_entry_t *dsl_deadlist_first(dsl_deadlist_t *dl); 97 dsl_deadlist_entry_t *dsl_deadlist_last(dsl_deadlist_t *dl); 98 uint64_t dsl_deadlist_clone(dsl_deadlist_t *dl, uint64_t maxtxg, 99 uint64_t mrs_obj, dmu_tx_t *tx); 100 void dsl_deadlist_space(dsl_deadlist_t *dl, 101 uint64_t *usedp, uint64_t *compp, uint64_t *uncompp); 102 void dsl_deadlist_space_range(dsl_deadlist_t *dl, 103 uint64_t mintxg, uint64_t maxtxg, 104 uint64_t *usedp, uint64_t *compp, uint64_t *uncompp); 105 void dsl_deadlist_merge(dsl_deadlist_t *dl, uint64_t obj, dmu_tx_t *tx); 106 void dsl_deadlist_move_bpobj(dsl_deadlist_t *dl, bpobj_t *bpo, uint64_t mintxg, 107 dmu_tx_t *tx); 108 boolean_t dsl_deadlist_is_open(dsl_deadlist_t *dl); 109 int dsl_process_sub_livelist(bpobj_t *bpobj, struct bplist *to_free, 110 zthr_t *t, uint64_t *size); 111 void dsl_deadlist_clear_entry(dsl_deadlist_entry_t *dle, dsl_deadlist_t *dl, 112 dmu_tx_t *tx); 113 void dsl_deadlist_discard_tree(dsl_deadlist_t *dl); 114 115 #ifdef __cplusplus 116 } 117 #endif 118 119 #endif /* _SYS_DSL_DEADLIST_H */ 120