1 /* 2 * CDDL HEADER START 3 * 4 * This file and its contents are supplied under the terms of the 5 * Common Development and Distribution License ("CDDL"), version 1.0. 6 * You may only use this file in accordance with the terms of version 7 * 1.0 of the CDDL. 8 * 9 * A full copy of the text of the CDDL should have accompanied this 10 * source. A copy of the CDDL is also available via the Internet at 11 * http://www.illumos.org/license/CDDL. 12 * 13 * CDDL HEADER END 14 */ 15 /* 16 * Copyright (c) 2013, 2018 by Delphix. All rights reserved. 17 */ 18 19 #ifndef _SYS_DSL_BOOKMARK_H 20 #define _SYS_DSL_BOOKMARK_H 21 22 #include <sys/zfs_context.h> 23 #include <sys/zfs_refcount.h> 24 #include <sys/dsl_dataset.h> 25 #include <sys/dsl_pool.h> 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 /* 32 * On disk zap object. 33 */ 34 typedef struct zfs_bookmark_phys { 35 uint64_t zbm_guid; /* guid of bookmarked dataset */ 36 uint64_t zbm_creation_txg; /* birth transaction group */ 37 uint64_t zbm_creation_time; /* bookmark creation time */ 38 39 /* fields used for redacted send / recv */ 40 uint64_t zbm_redaction_obj; /* redaction list object */ 41 uint64_t zbm_flags; /* ZBM_FLAG_* */ 42 43 /* fields used for bookmark written size */ 44 uint64_t zbm_referenced_bytes_refd; 45 uint64_t zbm_compressed_bytes_refd; 46 uint64_t zbm_uncompressed_bytes_refd; 47 uint64_t zbm_referenced_freed_before_next_snap; 48 uint64_t zbm_compressed_freed_before_next_snap; 49 uint64_t zbm_uncompressed_freed_before_next_snap; 50 51 /* fields used for raw sends */ 52 uint64_t zbm_ivset_guid; 53 } zfs_bookmark_phys_t; 54 55 56 #define BOOKMARK_PHYS_SIZE_V1 (3 * sizeof (uint64_t)) 57 #define BOOKMARK_PHYS_SIZE_V2 (12 * sizeof (uint64_t)) 58 59 typedef enum zbm_flags { 60 ZBM_FLAG_HAS_FBN = (1 << 0), 61 ZBM_FLAG_SNAPSHOT_EXISTS = (1 << 1), 62 } zbm_flags_t; 63 64 typedef struct redaction_list_phys { 65 uint64_t rlp_last_object; 66 uint64_t rlp_last_blkid; 67 uint64_t rlp_num_entries; 68 uint64_t rlp_num_snaps; 69 uint64_t rlp_snaps[]; /* variable length */ 70 } redaction_list_phys_t; 71 72 typedef struct redaction_list { 73 dmu_buf_user_t rl_dbu; 74 redaction_list_phys_t *rl_phys; 75 dmu_buf_t *rl_bonus; 76 dmu_buf_t *rl_dbuf; 77 uint64_t rl_object; 78 zfs_refcount_t rl_longholds; 79 objset_t *rl_mos; 80 } redaction_list_t; 81 82 /* node in ds_bookmarks */ 83 typedef struct dsl_bookmark_node { 84 char *dbn_name; /* free with strfree() */ 85 kmutex_t dbn_lock; /* protects dirty/phys in block_killed */ 86 boolean_t dbn_dirty; /* in currently syncing txg */ 87 zfs_bookmark_phys_t dbn_phys; 88 avl_node_t dbn_node; 89 } dsl_bookmark_node_t; 90 91 typedef struct redact_block_phys { 92 uint64_t rbp_object; 93 uint64_t rbp_blkid; 94 /* 95 * The top 16 bits of this field represent the block size in sectors of 96 * the blocks in question; the bottom 48 bits are used to store the 97 * number of consecutive blocks that are in the redaction list. They 98 * should be accessed using the inline functions below. 99 */ 100 uint64_t rbp_size_count; 101 uint64_t rbp_padding; 102 } redact_block_phys_t; 103 104 typedef int (*rl_traverse_callback_t)(redact_block_phys_t *, void *); 105 106 107 typedef struct dsl_bookmark_create_arg { 108 nvlist_t *dbca_bmarks; 109 nvlist_t *dbca_errors; 110 } dsl_bookmark_create_arg_t; 111 112 typedef struct dsl_bookmark_create_redacted_arg { 113 const char *dbcra_bmark; 114 const char *dbcra_snap; 115 redaction_list_t **dbcra_rl; 116 uint64_t dbcra_numsnaps; 117 uint64_t *dbcra_snaps; 118 const void *dbcra_tag; 119 } dsl_bookmark_create_redacted_arg_t; 120 121 int dsl_bookmark_create(nvlist_t *, nvlist_t *); 122 int dsl_bookmark_create_nvl_validate(nvlist_t *); 123 int dsl_bookmark_create_check(void *arg, dmu_tx_t *tx); 124 void dsl_bookmark_create_sync(void *arg, dmu_tx_t *tx); 125 int dsl_bookmark_create_redacted(const char *, const char *, uint64_t, 126 uint64_t *, const void *, redaction_list_t **); 127 int dsl_get_bookmarks(const char *, nvlist_t *, nvlist_t *); 128 int dsl_get_bookmarks_impl(dsl_dataset_t *, nvlist_t *, nvlist_t *); 129 int dsl_get_bookmark_props(const char *, const char *, nvlist_t *); 130 int dsl_bookmark_destroy(nvlist_t *, nvlist_t *); 131 int dsl_bookmark_lookup(struct dsl_pool *, const char *, 132 struct dsl_dataset *, zfs_bookmark_phys_t *); 133 int dsl_bookmark_lookup_impl(dsl_dataset_t *, const char *, 134 zfs_bookmark_phys_t *); 135 int dsl_redaction_list_hold_obj(struct dsl_pool *, uint64_t, const void *, 136 redaction_list_t **); 137 void dsl_redaction_list_rele(redaction_list_t *, const void *); 138 void dsl_redaction_list_long_hold(struct dsl_pool *, redaction_list_t *, 139 const void *); 140 void dsl_redaction_list_long_rele(redaction_list_t *, const void *); 141 boolean_t dsl_redaction_list_long_held(redaction_list_t *); 142 int dsl_bookmark_init_ds(dsl_dataset_t *); 143 void dsl_bookmark_fini_ds(dsl_dataset_t *); 144 boolean_t dsl_bookmark_ds_destroyed(dsl_dataset_t *, dmu_tx_t *); 145 void dsl_bookmark_snapshotted(dsl_dataset_t *, dmu_tx_t *); 146 void dsl_bookmark_block_killed(dsl_dataset_t *, const blkptr_t *, dmu_tx_t *); 147 void dsl_bookmark_sync_done(dsl_dataset_t *, dmu_tx_t *); 148 void dsl_bookmark_node_add(dsl_dataset_t *, dsl_bookmark_node_t *, dmu_tx_t *); 149 uint64_t dsl_bookmark_latest_txg(dsl_dataset_t *); 150 int dsl_redaction_list_traverse(redaction_list_t *, zbookmark_phys_t *, 151 rl_traverse_callback_t, void *); 152 void dsl_bookmark_next_changed(dsl_dataset_t *, dsl_dataset_t *, dmu_tx_t *); 153 154 #ifdef __cplusplus 155 } 156 #endif 157 158 #endif /* _SYS_DSL_BOOKMARK_H */ 159