dsl_dataset.h revision 1d452cf5123cb6ac0a013a4dbd4dcceeb0da314d
bb5e3b2f129cc39517b925419c22f69a378ec023eh/*
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer * CDDL HEADER START
bb5e3b2f129cc39517b925419c22f69a378ec023eh *
bb5e3b2f129cc39517b925419c22f69a378ec023eh * The contents of this file are subject to the terms of the
bb5e3b2f129cc39517b925419c22f69a378ec023eh * Common Development and Distribution License (the "License").
bb5e3b2f129cc39517b925419c22f69a378ec023eh * You may not use this file except in compliance with the License.
bb5e3b2f129cc39517b925419c22f69a378ec023eh *
bb5e3b2f129cc39517b925419c22f69a378ec023eh * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
bb5e3b2f129cc39517b925419c22f69a378ec023eh * or http://www.opensolaris.org/os/licensing.
bb5e3b2f129cc39517b925419c22f69a378ec023eh * See the License for the specific language governing permissions
bb5e3b2f129cc39517b925419c22f69a378ec023eh * and limitations under the License.
bb5e3b2f129cc39517b925419c22f69a378ec023eh *
bb5e3b2f129cc39517b925419c22f69a378ec023eh * When distributing Covered Code, include this CDDL HEADER in each
bb5e3b2f129cc39517b925419c22f69a378ec023eh * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
bb5e3b2f129cc39517b925419c22f69a378ec023eh * If applicable, add the following below this CDDL HEADER, with the
bb5e3b2f129cc39517b925419c22f69a378ec023eh * fields enclosed by brackets "[]" replaced with your own identifying
bb5e3b2f129cc39517b925419c22f69a378ec023eh * information: Portions Copyright [yyyy] [name of copyright owner]
bb5e3b2f129cc39517b925419c22f69a378ec023eh *
bb5e3b2f129cc39517b925419c22f69a378ec023eh * CDDL HEADER END
bb5e3b2f129cc39517b925419c22f69a378ec023eh */
bb5e3b2f129cc39517b925419c22f69a378ec023eh/*
bb5e3b2f129cc39517b925419c22f69a378ec023eh * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
bb5e3b2f129cc39517b925419c22f69a378ec023eh * Use is subject to license terms.
bb5e3b2f129cc39517b925419c22f69a378ec023eh */
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh#ifndef _SYS_DSL_DATASET_H
bb5e3b2f129cc39517b925419c22f69a378ec023eh#define _SYS_DSL_DATASET_H
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh#pragma ident "%Z%%M% %I% %E% SMI"
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh#include <sys/dmu.h>
bb5e3b2f129cc39517b925419c22f69a378ec023eh#include <sys/spa.h>
bb5e3b2f129cc39517b925419c22f69a378ec023eh#include <sys/txg.h>
bb5e3b2f129cc39517b925419c22f69a378ec023eh#include <sys/bplist.h>
bb5e3b2f129cc39517b925419c22f69a378ec023eh#include <sys/dsl_synctask.h>
bb5e3b2f129cc39517b925419c22f69a378ec023eh#include <sys/zfs_context.h>
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh#ifdef __cplusplus
bb5e3b2f129cc39517b925419c22f69a378ec023ehextern "C" {
bb5e3b2f129cc39517b925419c22f69a378ec023eh#endif
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023ehstruct dsl_dataset;
bb5e3b2f129cc39517b925419c22f69a378ec023ehstruct dsl_dir;
bb5e3b2f129cc39517b925419c22f69a378ec023ehstruct dsl_pool;
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023ehtypedef void dsl_dataset_evict_func_t(struct dsl_dataset *, void *);
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh#define DS_FLAG_INCONSISTENT (1ULL<<0)
bb5e3b2f129cc39517b925419c22f69a378ec023eh/*
bb5e3b2f129cc39517b925419c22f69a378ec023eh * NB: nopromote can not yet be set, but we want support for it in this
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng * on-disk version, so that we don't need to upgrade for it later. It
e7801d59e8ceda0cde8ebdfdddd7582ee2ea96efsowmini * will be needed when we implement 'zfs split' (where the split off
bb5e3b2f129cc39517b925419c22f69a378ec023eh * clone should not be promoted).
bb5e3b2f129cc39517b925419c22f69a378ec023eh */
bb5e3b2f129cc39517b925419c22f69a378ec023eh#define DS_FLAG_NOPROMOTE (1ULL<<1)
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023ehtypedef struct dsl_dataset_phys {
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_dir_obj;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_prev_snap_obj;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_prev_snap_txg;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_next_snap_obj;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_snapnames_zapobj; /* zap obj of snaps; ==0 for snaps */
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_num_children; /* clone/snap children; ==0 for head */
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_creation_time; /* seconds since 1970 */
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_creation_txg;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_deadlist_obj;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_used_bytes;
193974072f41a843678abf5f61979c748687e66bSherry Moore uint64_t ds_compressed_bytes;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_uncompressed_bytes;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_unique_bytes; /* only relavent to snapshots */
bb5e3b2f129cc39517b925419c22f69a378ec023eh /*
bb5e3b2f129cc39517b925419c22f69a378ec023eh * The ds_fsid_guid is a 56-bit ID that can change to avoid
bb5e3b2f129cc39517b925419c22f69a378ec023eh * collisions. The ds_guid is a 64-bit ID that will never
bb5e3b2f129cc39517b925419c22f69a378ec023eh * change, so there is a small probability that it will collide.
bb5e3b2f129cc39517b925419c22f69a378ec023eh */
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_fsid_guid;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_guid;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_flags;
bb5e3b2f129cc39517b925419c22f69a378ec023eh blkptr_t ds_bp;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */
bb5e3b2f129cc39517b925419c22f69a378ec023eh} dsl_dataset_phys_t;
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023ehtypedef struct dsl_dataset {
bb5e3b2f129cc39517b925419c22f69a378ec023eh /* Immutable: */
bb5e3b2f129cc39517b925419c22f69a378ec023eh struct dsl_dir *ds_dir;
bb5e3b2f129cc39517b925419c22f69a378ec023eh dsl_dataset_phys_t *ds_phys;
bb5e3b2f129cc39517b925419c22f69a378ec023eh dmu_buf_t *ds_dbuf;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_object;
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh /* only used in syncing context: */
bb5e3b2f129cc39517b925419c22f69a378ec023eh struct dsl_dataset *ds_prev; /* only valid for non-snapshots */
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh /* has internal locking: */
bb5e3b2f129cc39517b925419c22f69a378ec023eh bplist_t ds_deadlist;
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh /* protected by lock on pool's dp_dirty_datasets list */
bb5e3b2f129cc39517b925419c22f69a378ec023eh txg_node_t ds_dirty_link;
bb5e3b2f129cc39517b925419c22f69a378ec023eh list_node_t ds_synced_link;
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh /*
bb5e3b2f129cc39517b925419c22f69a378ec023eh * ds_phys->ds_<accounting> is also protected by ds_lock.
bb5e3b2f129cc39517b925419c22f69a378ec023eh * Protected by ds_lock:
bb5e3b2f129cc39517b925419c22f69a378ec023eh */
bb5e3b2f129cc39517b925419c22f69a378ec023eh kmutex_t ds_lock;
bb5e3b2f129cc39517b925419c22f69a378ec023eh void *ds_user_ptr;
bb5e3b2f129cc39517b925419c22f69a378ec023eh dsl_dataset_evict_func_t *ds_user_evict_func;
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_open_refcount;
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh /* no locking; only for making guesses */
bb5e3b2f129cc39517b925419c22f69a378ec023eh uint64_t ds_trysnap_txg;
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh /* Protected by ds_lock; keep at end of struct for better locality */
bb5e3b2f129cc39517b925419c22f69a378ec023eh char ds_snapname[MAXNAMELEN];
bb5e3b2f129cc39517b925419c22f69a378ec023eh} dsl_dataset_t;
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh#define dsl_dataset_is_snapshot(ds) \
bb5e3b2f129cc39517b925419c22f69a378ec023eh ((ds)->ds_phys->ds_num_children != 0)
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023ehint dsl_dataset_open_spa(spa_t *spa, const char *name, int mode,
bb5e3b2f129cc39517b925419c22f69a378ec023eh void *tag, dsl_dataset_t **dsp);
bb5e3b2f129cc39517b925419c22f69a378ec023ehint dsl_dataset_open(const char *name, int mode, void *tag,
bb5e3b2f129cc39517b925419c22f69a378ec023eh dsl_dataset_t **dsp);
bb5e3b2f129cc39517b925419c22f69a378ec023ehint dsl_dataset_open_obj(struct dsl_pool *dp, uint64_t dsobj,
bb5e3b2f129cc39517b925419c22f69a378ec023eh const char *tail, int mode, void *tag, dsl_dataset_t **);
bb5e3b2f129cc39517b925419c22f69a378ec023ehvoid dsl_dataset_name(dsl_dataset_t *ds, char *name);
bb5e3b2f129cc39517b925419c22f69a378ec023ehvoid dsl_dataset_close(dsl_dataset_t *ds, int mode, void *tag);
bb5e3b2f129cc39517b925419c22f69a378ec023ehuint64_t dsl_dataset_create_sync(dsl_dir_t *pds,
bb5e3b2f129cc39517b925419c22f69a378ec023eh const char *lastname, dsl_dataset_t *clone_parent, dmu_tx_t *tx);
bb5e3b2f129cc39517b925419c22f69a378ec023ehint dsl_dataset_destroy(const char *name);
bb5e3b2f129cc39517b925419c22f69a378ec023ehint dsl_snapshots_destroy(char *fsname, char *snapname);
bb5e3b2f129cc39517b925419c22f69a378ec023ehdsl_checkfunc_t dsl_dataset_snapshot_check;
bb5e3b2f129cc39517b925419c22f69a378ec023ehdsl_syncfunc_t dsl_dataset_snapshot_sync;
bb5e3b2f129cc39517b925419c22f69a378ec023ehint dsl_dataset_rollback(dsl_dataset_t *ds);
bb5e3b2f129cc39517b925419c22f69a378ec023ehint dsl_dataset_rename(const char *name, const char *newname);
bb5e3b2f129cc39517b925419c22f69a378ec023ehint dsl_dataset_promote(const char *name);
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023ehvoid *dsl_dataset_set_user_ptr(dsl_dataset_t *ds,
bb5e3b2f129cc39517b925419c22f69a378ec023eh void *p, dsl_dataset_evict_func_t func);
bb5e3b2f129cc39517b925419c22f69a378ec023ehvoid *dsl_dataset_get_user_ptr(dsl_dataset_t *ds);
7efa17f5f4c3cc113e1b0a1e86f43d4bf2ede8fafei feng - Sun Microsystems - Beijing China
7efa17f5f4c3cc113e1b0a1e86f43d4bf2ede8fafei feng - Sun Microsystems - Beijing Chinavoid dsl_dataset_get_blkptr(dsl_dataset_t *ds, blkptr_t *bp);
7efa17f5f4c3cc113e1b0a1e86f43d4bf2ede8fafei feng - Sun Microsystems - Beijing Chinavoid dsl_dataset_set_blkptr(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyerspa_t *dsl_dataset_get_spa(dsl_dataset_t *ds);
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer
bb5e3b2f129cc39517b925419c22f69a378ec023ehvoid dsl_dataset_sync(dsl_dataset_t *os, dmu_tx_t *tx);
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023ehvoid dsl_dataset_block_born(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx);
bb5e3b2f129cc39517b925419c22f69a378ec023ehvoid dsl_dataset_block_kill(dsl_dataset_t *ds, blkptr_t *bp, dmu_tx_t *tx);
bb5e3b2f129cc39517b925419c22f69a378ec023ehint dsl_dataset_block_freeable(dsl_dataset_t *ds, uint64_t blk_birth);
bb5e3b2f129cc39517b925419c22f69a378ec023ehuint64_t dsl_dataset_prev_snap_txg(dsl_dataset_t *ds);
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023ehvoid dsl_dataset_dirty(dsl_dataset_t *ds, dmu_tx_t *tx);
bb5e3b2f129cc39517b925419c22f69a378ec023ehvoid dsl_dataset_stats(dsl_dataset_t *os, dmu_objset_stats_t *dds);
bb5e3b2f129cc39517b925419c22f69a378ec023ehstruct dsl_pool *dsl_dataset_pool(dsl_dataset_t *ds);
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023ehvoid dsl_dataset_create_root(struct dsl_pool *dp, uint64_t *ddobjp,
bb5e3b2f129cc39517b925419c22f69a378ec023eh dmu_tx_t *tx);
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh#ifdef ZFS_DEBUG
bb5e3b2f129cc39517b925419c22f69a378ec023eh#define dprintf_ds(ds, fmt, ...) do { \
bb5e3b2f129cc39517b925419c22f69a378ec023eh if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
bb5e3b2f129cc39517b925419c22f69a378ec023eh char *__ds_name = kmem_alloc(MAXNAMELEN, KM_SLEEP); \
bb5e3b2f129cc39517b925419c22f69a378ec023eh dsl_dataset_name(ds, __ds_name); \
bb5e3b2f129cc39517b925419c22f69a378ec023eh dprintf("ds=%s " fmt, __ds_name, __VA_ARGS__); \
bb5e3b2f129cc39517b925419c22f69a378ec023eh kmem_free(__ds_name, MAXNAMELEN); \
bb5e3b2f129cc39517b925419c22f69a378ec023eh } \
bb5e3b2f129cc39517b925419c22f69a378ec023eh_NOTE(CONSTCOND) } while (0)
bb5e3b2f129cc39517b925419c22f69a378ec023eh#else
bb5e3b2f129cc39517b925419c22f69a378ec023eh#define dprintf_ds(dd, fmt, ...)
bb5e3b2f129cc39517b925419c22f69a378ec023eh#endif
bb5e3b2f129cc39517b925419c22f69a378ec023eh
bb5e3b2f129cc39517b925419c22f69a378ec023eh#ifdef __cplusplus
0f1b305ee9e700c825d9e9ad1ea1e4311d212eb2Seth Goldberg}
0f1b305ee9e700c825d9e9ad1ea1e4311d212eb2Seth Goldberg#endif
0f1b305ee9e700c825d9e9ad1ea1e4311d212eb2Seth Goldberg
0f1b305ee9e700c825d9e9ad1ea1e4311d212eb2Seth Goldberg#endif /* _SYS_DSL_DATASET_H */
0f1b305ee9e700c825d9e9ad1ea1e4311d212eb2Seth Goldberg