1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_DSL_DATASET_H 27 #define _SYS_DSL_DATASET_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #include <sys/dmu.h> 32 #include <sys/spa.h> 33 #include <sys/txg.h> 34 #include <sys/bplist.h> 35 #include <sys/zfs_context.h> 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 struct dsl_dataset; 42 struct dsl_dir; 43 struct dsl_pool; 44 45 typedef void dsl_dataset_evict_func_t(struct dsl_dataset *, void *); 46 47 typedef struct dsl_dataset_phys { 48 uint64_t ds_dir_obj; 49 uint64_t ds_prev_snap_obj; 50 uint64_t ds_prev_snap_txg; 51 uint64_t ds_next_snap_obj; 52 uint64_t ds_snapnames_zapobj; /* zap obj of snaps; ==0 for snaps */ 53 uint64_t ds_num_children; /* clone/snap children; ==0 for head */ 54 uint64_t ds_creation_time; /* seconds since 1970 */ 55 uint64_t ds_creation_txg; 56 uint64_t ds_deadlist_obj; 57 uint64_t ds_used_bytes; 58 uint64_t ds_compressed_bytes; 59 uint64_t ds_uncompressed_bytes; 60 uint64_t ds_unique_bytes; /* only relavent to snapshots */ 61 /* 62 * The ds_fsid_guid is a 56-bit ID that can change to avoid 63 * collisions. The ds_guid is a 64-bit ID that will never 64 * change, so there is a small probability that it will collide. 65 */ 66 uint64_t ds_fsid_guid; 67 uint64_t ds_guid; 68 uint64_t ds_restoring; /* boolean */ 69 blkptr_t ds_bp; 70 uint64_t ds_pad[8]; /* pad out to 256 bytes for good measure */ 71 } dsl_dataset_phys_t; 72 73 typedef struct dsl_dataset { 74 /* Immutable: */ 75 struct dsl_dir *ds_dir; 76 dsl_dataset_phys_t *ds_phys; 77 dmu_buf_t *ds_dbuf; 78 uint64_t ds_object; 79 80 /* only used in syncing context: */ 81 struct dsl_dataset *ds_prev; /* only valid for non-snapshots */ 82 83 /* has internal locking: */ 84 bplist_t ds_deadlist; 85 86 /* protected by lock on pool's dp_dirty_datasets list */ 87 txg_node_t ds_dirty_link; 88 list_node_t ds_synced_link; 89 90 /* 91 * ds_phys->ds_<accounting> is also protected by ds_lock. 92 * Protected by ds_lock: 93 */ 94 kmutex_t ds_lock; 95 void *ds_user_ptr; 96 dsl_dataset_evict_func_t *ds_user_evict_func; 97 uint64_t ds_open_refcount; 98 99 /* Protected by ds_lock; keep at end of struct for better locality */ 100 char ds_snapname[MAXNAMELEN]; 101 } dsl_dataset_t; 102 103 #define dsl_dataset_is_snapshot(ds) \ 104 ((ds)->ds_phys->ds_num_children != 0) 105 106 int dsl_dataset_open_spa(spa_t *spa, const char *name, int mode, 107 void *tag, dsl_dataset_t **dsp); 108 int dsl_dataset_open(const char *name, int mode, void *tag, 109 dsl_dataset_t **dsp); 110 int dsl_dataset_open_obj(struct dsl_pool *dp, uint64_t dsobj, 111 const char *tail, int mode, void *tag, dsl_dataset_t **); 112 void dsl_dataset_name(dsl_dataset_t *ds, char *name); 113 void dsl_dataset_close(dsl_dataset_t *ds, int mode, void *tag); 114 int dsl_dataset_create_sync(dsl_dir_t *pds, const char *fullname, 115 const char *lastname, dsl_dataset_t *clone_parent, dmu_tx_t *tx); 116 int dsl_dataset_snapshot_sync(dsl_dir_t *dd, void *arg, dmu_tx_t *tx); 117 int dsl_dataset_destroy(const char *name); 118 int dsl_dataset_destroy_sync(dsl_dir_t *dd, void *arg, dmu_tx_t *tx); 119 int dsl_dataset_rollback(const char *name); 120 int dsl_dataset_rollback_sync(dsl_dir_t *dd, void *arg, dmu_tx_t *tx); 121 int dsl_dataset_rename(const char *name, const char *newname); 122 123 void *dsl_dataset_set_user_ptr(dsl_dataset_t *ds, 124 void *p, dsl_dataset_evict_func_t func); 125 void *dsl_dataset_get_user_ptr(dsl_dataset_t *ds); 126 127 void dsl_dataset_get_blkptr(dsl_dataset_t *ds, blkptr_t *bp); 128 void dsl_dataset_set_blkptr(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx); 129 130 spa_t *dsl_dataset_get_spa(dsl_dataset_t *ds); 131 132 void dsl_dataset_sync(dsl_dataset_t *os, dmu_tx_t *tx); 133 134 void dsl_dataset_block_born(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx); 135 void dsl_dataset_block_kill(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx); 136 int dsl_dataset_block_freeable(dsl_dataset_t *ds, uint64_t blk_birth); 137 uint64_t dsl_dataset_prev_snap_txg(dsl_dataset_t *ds); 138 139 void dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx); 140 void dsl_dataset_stats(dsl_dataset_t *os, dmu_objset_stats_t *dds); 141 struct dsl_pool *dsl_dataset_pool(dsl_dataset_t *ds); 142 143 void dsl_dataset_create_root(struct dsl_pool *dp, uint64_t *ddobjp, 144 dmu_tx_t *tx); 145 146 #ifdef ZFS_DEBUG 147 #define dprintf_ds(ds, fmt, ...) do { \ 148 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ 149 char *__ds_name = kmem_alloc(MAXNAMELEN, KM_SLEEP); \ 150 dsl_dataset_name(ds, __ds_name); \ 151 dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \ 152 kmem_free(__ds_name, MAXNAMELEN); \ 153 } \ 154 _NOTE(CONSTCOND) } while (0) 155 #else 156 #define dprintf_ds(dd, fmt, ...) 157 #endif 158 159 #ifdef __cplusplus 160 } 161 #endif 162 163 #endif /* _SYS_DSL_DATASET_H */ 164