FreeBSD ZFS
The Zettabyte File System

sys/dsl_dataset.h

Go to the documentation of this file.
00001 /*
00002  * CDDL HEADER START
00003  *
00004  * The contents of this file are subject to the terms of the
00005  * Common Development and Distribution License (the "License").
00006  * You may not use this file except in compliance with the License.
00007  *
00008  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
00009  * or http://www.opensolaris.org/os/licensing.
00010  * See the License for the specific language governing permissions
00011  * and limitations under the License.
00012  *
00013  * When distributing Covered Code, include this CDDL HEADER in each
00014  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
00015  * If applicable, add the following below this CDDL HEADER, with the
00016  * fields enclosed by brackets "[]" replaced with your own identifying
00017  * information: Portions Copyright [yyyy] [name of copyright owner]
00018  *
00019  * CDDL HEADER END
00020  */
00021 /*
00022  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
00023  * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>.
00024  * All rights reserved.
00025  * Copyright (c) 2012 by Delphix. All rights reserved.
00026  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
00027  */
00028 
00029 #ifndef _SYS_DSL_DATASET_H
00030 #define _SYS_DSL_DATASET_H
00031 
00032 #include <sys/dmu.h>
00033 #include <sys/spa.h>
00034 #include <sys/txg.h>
00035 #include <sys/zio.h>
00036 #include <sys/bplist.h>
00037 #include <sys/dsl_synctask.h>
00038 #include <sys/zfs_context.h>
00039 #include <sys/dsl_deadlist.h>
00040 
00041 #ifdef  __cplusplus
00042 extern "C" {
00043 #endif
00044 
00045 struct dsl_dataset;
00046 struct dsl_dir;
00047 struct dsl_pool;
00048 
00049 #define DS_FLAG_INCONSISTENT    (1ULL<<0)
00050 #define DS_IS_INCONSISTENT(ds)  \
00051         ((ds)->ds_phys->ds_flags & DS_FLAG_INCONSISTENT)
00052 
00058 #define DS_FLAG_NOPROMOTE       (1ULL<<1)
00059 
00065 #define DS_FLAG_UNIQUE_ACCURATE (1ULL<<2)
00066 
00071 #define DS_FLAG_DEFER_DESTROY   (1ULL<<3)
00072 #define DS_IS_DEFER_DESTROY(ds) \
00073         ((ds)->ds_phys->ds_flags & DS_FLAG_DEFER_DESTROY)
00074 
00079 #define DS_FLAG_CI_DATASET      (1ULL<<16)
00080 
00081 typedef struct dsl_dataset_phys {
00082         uint64_t ds_dir_obj;            
00083         uint64_t ds_prev_snap_obj;      
00084         uint64_t ds_prev_snap_txg;
00085         uint64_t ds_next_snap_obj;      
00086         uint64_t ds_snapnames_zapobj;
00087         uint64_t ds_num_children;
00088         uint64_t ds_creation_time;      
00089         uint64_t ds_creation_txg;
00090         uint64_t ds_deadlist_obj;       
00091         /*
00092          * ds_referenced_bytes, ds_compressed_bytes, and ds_uncompressed_bytes
00093          * include all blocks referenced by this dataset, including those
00094          * shared with any other datasets.
00095          */
00096         uint64_t ds_referenced_bytes;
00097         uint64_t ds_compressed_bytes;
00098         uint64_t ds_uncompressed_bytes;
00099         uint64_t ds_unique_bytes;       
00101         uint64_t ds_fsid_guid;
00106         uint64_t ds_guid;
00107         uint64_t ds_flags;              
00108         blkptr_t ds_bp;
00109         uint64_t ds_next_clones_obj;    
00110         uint64_t ds_props_obj;          
00111         uint64_t ds_userrefs_obj;       
00112         uint64_t ds_pad[5]; /* pad out to 320 bytes for good measure */
00113 } dsl_dataset_phys_t;
00114 
00115 typedef struct dsl_dataset {
00119         struct dsl_dir *ds_dir;
00120         dsl_dataset_phys_t *ds_phys;
00121         dmu_buf_t *ds_dbuf;
00122         uint64_t ds_object;
00123         uint64_t ds_fsid_guid;
00124 
00129         struct dsl_dataset *ds_prev;
00130 
00135         dsl_deadlist_t ds_deadlist;
00136         bplist_t ds_pending_deadlist;
00137 
00142         kmutex_t ds_recvlock;
00143 
00148         txg_node_t ds_dirty_link;
00149         list_node_t ds_synced_link;
00150 
00157         kmutex_t ds_lock;
00158         objset_t *ds_objset;
00159         uint64_t ds_userrefs;
00160 
00166         krwlock_t ds_rwlock;
00167         kcondvar_t ds_exclusive_cv;
00168         void *ds_owner;
00169 
00174         uint64_t ds_trysnap_txg;
00175 
00180         kmutex_t ds_opening_lock;
00183         uint64_t ds_reserved;   
00184         uint64_t ds_quota;      
00186         kmutex_t ds_sendstream_lock;
00187         list_t ds_sendstreams;
00188 
00192         char ds_snapname[MAXNAMELEN];
00194 } dsl_dataset_t;
00195 
00196 struct dsl_ds_destroyarg {
00197         dsl_dataset_t *ds;              
00198         dsl_dataset_t *rm_origin;       
00199         boolean_t is_origin_rm;         
00200         boolean_t defer;                
00201         boolean_t releasing;            
00202         boolean_t need_prep;            
00203 };
00204 
00209 #define MAX_TAG_PREFIX_LEN      17
00210 
00211 struct dsl_ds_holdarg {
00212         dsl_sync_task_group_t *dstg;
00213         char *htag;
00214         char *snapname;
00215         boolean_t recursive;
00216         boolean_t gotone;
00217         boolean_t temphold;
00218         char failed[MAXPATHLEN];
00219 };
00220 
00221 /*
00222  * Flags for dsl_dataset_rename().
00223  */
00224 #define ZFS_RENAME_RECURSIVE            0x01
00225 #define ZFS_RENAME_ALLOW_MOUNTED        0x02
00226 
00227 #define dsl_dataset_is_snapshot(ds) \
00228         ((ds)->ds_phys->ds_num_children != 0)
00229 
00230 #define DS_UNIQUE_IS_ACCURATE(ds)       \
00231         (((ds)->ds_phys->ds_flags & DS_FLAG_UNIQUE_ACCURATE) != 0)
00232 
00233 int dsl_dataset_hold(const char *name, void *tag, dsl_dataset_t **dsp);
00234 int dsl_dataset_hold_obj(struct dsl_pool *dp, uint64_t dsobj,
00235     void *tag, dsl_dataset_t **);
00236 int dsl_dataset_own(const char *name, boolean_t inconsistentok,
00237     void *tag, dsl_dataset_t **dsp);
00238 int dsl_dataset_own_obj(struct dsl_pool *dp, uint64_t dsobj,
00239     boolean_t inconsistentok, void *tag, dsl_dataset_t **dsp);
00240 void dsl_dataset_name(dsl_dataset_t *ds, char *name);
00241 void dsl_dataset_rele(dsl_dataset_t *ds, void *tag);
00242 void dsl_dataset_disown(dsl_dataset_t *ds, void *tag);
00243 void dsl_dataset_drop_ref(dsl_dataset_t *ds, void *tag);
00244 boolean_t dsl_dataset_tryown(dsl_dataset_t *ds, boolean_t inconsistentok,
00245     void *tag);
00246 void dsl_dataset_make_exclusive(dsl_dataset_t *ds, void *tag);
00247 void dsl_register_onexit_hold_cleanup(dsl_dataset_t *ds, const char *htag,
00248     minor_t minor);
00249 uint64_t dsl_dataset_create_sync(dsl_dir_t *pds, const char *lastname,
00250     dsl_dataset_t *origin, uint64_t flags, cred_t *, dmu_tx_t *);
00251 uint64_t dsl_dataset_create_sync_dd(dsl_dir_t *dd, dsl_dataset_t *origin,
00252     uint64_t flags, dmu_tx_t *tx);
00253 int dsl_dataset_destroy(dsl_dataset_t *ds, void *tag, boolean_t defer);
00254 int dsl_snapshots_destroy(char *fsname, char *snapname, boolean_t defer);
00255 dsl_checkfunc_t dsl_dataset_destroy_check;
00256 dsl_syncfunc_t dsl_dataset_destroy_sync;
00257 dsl_checkfunc_t dsl_dataset_snapshot_check;
00258 dsl_syncfunc_t dsl_dataset_snapshot_sync;
00259 dsl_syncfunc_t dsl_dataset_user_hold_sync;
00260 int dsl_dataset_rename(char *name, const char *newname, int flags);
00261 int dsl_dataset_promote(const char *name, char *conflsnap);
00262 int dsl_dataset_clone_swap(dsl_dataset_t *clone, dsl_dataset_t *origin_head,
00263     boolean_t force);
00264 int dsl_dataset_user_hold(char *dsname, char *snapname, char *htag,
00265     boolean_t recursive, boolean_t temphold, int cleanup_fd);
00266 int dsl_dataset_user_hold_for_send(dsl_dataset_t *ds, char *htag,
00267     boolean_t temphold);
00268 int dsl_dataset_user_release(char *dsname, char *snapname, char *htag,
00269     boolean_t recursive);
00270 int dsl_dataset_user_release_tmp(struct dsl_pool *dp, uint64_t dsobj,
00271     char *htag, boolean_t retry);
00272 int dsl_dataset_get_holds(const char *dsname, nvlist_t **nvp);
00273 
00274 blkptr_t *dsl_dataset_get_blkptr(dsl_dataset_t *ds);
00275 void dsl_dataset_set_blkptr(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx);
00276 
00277 spa_t *dsl_dataset_get_spa(dsl_dataset_t *ds);
00278 
00279 boolean_t dsl_dataset_modified_since_lastsnap(dsl_dataset_t *ds);
00280 
00281 void dsl_dataset_sync(dsl_dataset_t *os, zio_t *zio, dmu_tx_t *tx);
00282 
00283 void dsl_dataset_block_born(dsl_dataset_t *ds, const blkptr_t *bp,
00284     dmu_tx_t *tx);
00285 int dsl_dataset_block_kill(dsl_dataset_t *ds, const blkptr_t *bp,
00286     dmu_tx_t *tx, boolean_t async);
00287 boolean_t dsl_dataset_block_freeable(dsl_dataset_t *ds, const blkptr_t *bp,
00288     uint64_t blk_birth);
00289 uint64_t dsl_dataset_prev_snap_txg(dsl_dataset_t *ds);
00290 
00291 void dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx);
00292 void dsl_dataset_stats(dsl_dataset_t *os, nvlist_t *nv);
00293 void dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat);
00294 void dsl_dataset_space(dsl_dataset_t *ds,
00295     uint64_t *refdbytesp, uint64_t *availbytesp,
00296     uint64_t *usedobjsp, uint64_t *availobjsp);
00297 uint64_t dsl_dataset_fsid_guid(dsl_dataset_t *ds);
00298 int dsl_dataset_space_written(dsl_dataset_t *oldsnap, dsl_dataset_t *new,
00299     uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
00300 int dsl_dataset_space_wouldfree(dsl_dataset_t *firstsnap, dsl_dataset_t *last,
00301     uint64_t *usedp, uint64_t *compp, uint64_t *uncompp);
00302 boolean_t dsl_dataset_is_dirty(dsl_dataset_t *ds);
00303 
00304 int dsl_dsobj_to_dsname(char *pname, uint64_t obj, char *buf);
00305 
00306 int dsl_dataset_check_quota(dsl_dataset_t *ds, boolean_t check_quota,
00307     uint64_t asize, uint64_t inflight, uint64_t *used,
00308     uint64_t *ref_rsrv);
00309 int dsl_dataset_set_quota(const char *dsname, zprop_source_t source,
00310     uint64_t quota);
00311 dsl_syncfunc_t dsl_dataset_set_quota_sync;
00312 int dsl_dataset_set_reservation(const char *dsname, zprop_source_t source,
00313     uint64_t reservation);
00314 
00315 int dsl_destroy_inconsistent(const char *dsname, void *arg);
00316 
00317 #ifdef ZFS_DEBUG
00318 #define dprintf_ds(ds, fmt, ...) do { \
00319         if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
00320         char *__ds_name = kmem_alloc(MAXNAMELEN, KM_SLEEP); \
00321         dsl_dataset_name(ds, __ds_name); \
00322         dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \
00323         kmem_free(__ds_name, MAXNAMELEN); \
00324         } \
00325 _NOTE(CONSTCOND) } while (0)
00326 #else
00327 #define dprintf_ds(dd, fmt, ...)
00328 #endif
00329 
00330 #ifdef  __cplusplus
00331 }
00332 #endif
00333 
00334 #endif /* _SYS_DSL_DATASET_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines