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