1168404Spjd/* 2168404Spjd * CDDL HEADER START 3168404Spjd * 4168404Spjd * The contents of this file are subject to the terms of the 5168404Spjd * Common Development and Distribution License (the "License"). 6168404Spjd * You may not use this file except in compliance with the License. 7168404Spjd * 8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9168404Spjd * or http://www.opensolaris.org/os/licensing. 10168404Spjd * See the License for the specific language governing permissions 11168404Spjd * and limitations under the License. 12168404Spjd * 13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each 14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15168404Spjd * If applicable, add the following below this CDDL HEADER, with the 16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying 17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner] 18168404Spjd * 19168404Spjd * CDDL HEADER END 20168404Spjd */ 21168404Spjd/* 22219089Spjd * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23260764Savg * Copyright (c) 2013 by Delphix. All rights reserved. 24265754Sdelphij * Copyright (c) 2014, Joyent, Inc. All rights reserved. 25168404Spjd */ 26168404Spjd 27168404Spjd#ifndef _SYS_DSL_DIR_H 28168404Spjd#define _SYS_DSL_DIR_H 29168404Spjd 30168404Spjd#include <sys/dmu.h> 31168404Spjd#include <sys/dsl_pool.h> 32168404Spjd#include <sys/dsl_synctask.h> 33168404Spjd#include <sys/refcount.h> 34168404Spjd#include <sys/zfs_context.h> 35168404Spjd 36168404Spjd#ifdef __cplusplus 37168404Spjdextern "C" { 38168404Spjd#endif 39168404Spjd 40168404Spjdstruct dsl_dataset; 41168404Spjd 42265754Sdelphij/* 43265754Sdelphij * DD_FIELD_* are strings that are used in the "extensified" dsl_dir zap object. 44265754Sdelphij * They should be of the format <reverse-dns>:<field>. 45265754Sdelphij */ 46265754Sdelphij 47265754Sdelphij#define DD_FIELD_FILESYSTEM_COUNT "com.joyent:filesystem_count" 48265754Sdelphij#define DD_FIELD_SNAPSHOT_COUNT "com.joyent:snapshot_count" 49265754Sdelphij 50185029Spjdtypedef enum dd_used { 51185029Spjd DD_USED_HEAD, 52185029Spjd DD_USED_SNAP, 53185029Spjd DD_USED_CHILD, 54185029Spjd DD_USED_CHILD_RSRV, 55185029Spjd DD_USED_REFRSRV, 56185029Spjd DD_USED_NUM 57185029Spjd} dd_used_t; 58185029Spjd 59185029Spjd#define DD_FLAG_USED_BREAKDOWN (1<<0) 60185029Spjd 61168404Spjdtypedef struct dsl_dir_phys { 62168404Spjd uint64_t dd_creation_time; /* not actually used */ 63168404Spjd uint64_t dd_head_dataset_obj; 64168404Spjd uint64_t dd_parent_obj; 65185029Spjd uint64_t dd_origin_obj; 66168404Spjd uint64_t dd_child_dir_zapobj; 67168404Spjd /* 68168404Spjd * how much space our children are accounting for; for leaf 69168404Spjd * datasets, == physical space used by fs + snaps 70168404Spjd */ 71168404Spjd uint64_t dd_used_bytes; 72168404Spjd uint64_t dd_compressed_bytes; 73168404Spjd uint64_t dd_uncompressed_bytes; 74168404Spjd /* Administrative quota setting */ 75168404Spjd uint64_t dd_quota; 76168404Spjd /* Administrative reservation setting */ 77168404Spjd uint64_t dd_reserved; 78168404Spjd uint64_t dd_props_zapobj; 79185029Spjd uint64_t dd_deleg_zapobj; /* dataset delegation permissions */ 80185029Spjd uint64_t dd_flags; 81185029Spjd uint64_t dd_used_breakdown[DD_USED_NUM]; 82219089Spjd uint64_t dd_clones; /* dsl_dir objects */ 83219089Spjd uint64_t dd_pad[13]; /* pad out to 256 bytes for good measure */ 84168404Spjd} dsl_dir_phys_t; 85168404Spjd 86168404Spjdstruct dsl_dir { 87168404Spjd /* These are immutable; no lock needed: */ 88168404Spjd uint64_t dd_object; 89168404Spjd dsl_dir_phys_t *dd_phys; 90168404Spjd dmu_buf_t *dd_dbuf; 91168404Spjd dsl_pool_t *dd_pool; 92168404Spjd 93168404Spjd /* protected by lock on pool's dp_dirty_dirs list */ 94168404Spjd txg_node_t dd_dirty_link; 95168404Spjd 96168404Spjd /* protected by dp_config_rwlock */ 97168404Spjd dsl_dir_t *dd_parent; 98168404Spjd 99168404Spjd /* Protected by dd_lock */ 100168404Spjd kmutex_t dd_lock; 101168404Spjd list_t dd_prop_cbs; /* list of dsl_prop_cb_record_t's */ 102219089Spjd timestruc_t dd_snap_cmtime; /* last time snapshot namespace changed */ 103219089Spjd uint64_t dd_origin_txg; 104168404Spjd 105168404Spjd /* gross estimate of space used by in-flight tx's */ 106168404Spjd uint64_t dd_tempreserved[TXG_SIZE]; 107168404Spjd /* amount of space we expect to write; == amount of dirty data */ 108168404Spjd int64_t dd_space_towrite[TXG_SIZE]; 109168404Spjd 110168404Spjd /* protected by dd_lock; keep at end of struct for better locality */ 111168404Spjd char dd_myname[MAXNAMELEN]; 112168404Spjd}; 113168404Spjd 114249643Smmvoid dsl_dir_rele(dsl_dir_t *dd, void *tag); 115249643Smmint dsl_dir_hold(dsl_pool_t *dp, const char *name, void *tag, 116249643Smm dsl_dir_t **, const char **tail); 117249643Smmint dsl_dir_hold_obj(dsl_pool_t *dp, uint64_t ddobj, 118168404Spjd const char *tail, void *tag, dsl_dir_t **); 119168404Spjdvoid dsl_dir_name(dsl_dir_t *dd, char *buf); 120168498Spjdint dsl_dir_namelen(dsl_dir_t *dd); 121185029Spjduint64_t dsl_dir_create_sync(dsl_pool_t *dp, dsl_dir_t *pds, 122185029Spjd const char *name, dmu_tx_t *tx); 123168404Spjdvoid dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv); 124168404Spjduint64_t dsl_dir_space_available(dsl_dir_t *dd, 125168404Spjd dsl_dir_t *ancestor, int64_t delta, int ondiskonly); 126168404Spjdvoid dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx); 127168404Spjdvoid dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx); 128168404Spjdint dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem, 129185029Spjd uint64_t asize, uint64_t fsize, uint64_t usize, void **tr_cookiep, 130185029Spjd dmu_tx_t *tx); 131168404Spjdvoid dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx); 132168404Spjdvoid dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx); 133185029Spjdvoid dsl_dir_diduse_space(dsl_dir_t *dd, dd_used_t type, 134168404Spjd int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx); 135185029Spjdvoid dsl_dir_transfer_space(dsl_dir_t *dd, int64_t delta, 136185029Spjd dd_used_t oldtype, dd_used_t newtype, dmu_tx_t *tx); 137219089Spjdint dsl_dir_set_quota(const char *ddname, zprop_source_t source, 138219089Spjd uint64_t quota); 139219089Spjdint dsl_dir_set_reservation(const char *ddname, zprop_source_t source, 140219089Spjd uint64_t reservation); 141265754Sdelphijint dsl_dir_activate_fs_ss_limit(const char *); 142265754Sdelphijint dsl_fs_ss_limit_check(dsl_dir_t *, uint64_t, zfs_prop_t, dsl_dir_t *, 143265754Sdelphij cred_t *); 144265754Sdelphijvoid dsl_fs_ss_count_adjust(dsl_dir_t *, int64_t, const char *, dmu_tx_t *); 145249643Smmint dsl_dir_rename(const char *oldname, const char *newname); 146265754Sdelphijint dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd, 147265754Sdelphij uint64_t fs_cnt, uint64_t ss_cnt, uint64_t space, cred_t *); 148185029Spjdboolean_t dsl_dir_is_clone(dsl_dir_t *dd); 149185029Spjdvoid dsl_dir_new_refreservation(dsl_dir_t *dd, struct dsl_dataset *ds, 150185029Spjd uint64_t reservation, cred_t *cr, dmu_tx_t *tx); 151219089Spjdvoid dsl_dir_snap_cmtime_update(dsl_dir_t *dd); 152219089Spjdtimestruc_t dsl_dir_snap_cmtime(dsl_dir_t *dd); 153249643Smmvoid dsl_dir_set_reservation_sync_impl(dsl_dir_t *dd, uint64_t value, 154249643Smm dmu_tx_t *tx); 155265754Sdelphijvoid dsl_dir_zapify(dsl_dir_t *dd, dmu_tx_t *tx); 156265754Sdelphijboolean_t dsl_dir_is_zapified(dsl_dir_t *dd); 157168404Spjd 158168404Spjd/* internal reserved dir name */ 159168404Spjd#define MOS_DIR_NAME "$MOS" 160185029Spjd#define ORIGIN_DIR_NAME "$ORIGIN" 161219089Spjd#define XLATION_DIR_NAME "$XLATION" 162219089Spjd#define FREE_DIR_NAME "$FREE" 163168404Spjd 164168404Spjd#ifdef ZFS_DEBUG 165168404Spjd#define dprintf_dd(dd, fmt, ...) do { \ 166168404Spjd if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ 167168404Spjd char *__ds_name = kmem_alloc(MAXNAMELEN + strlen(MOS_DIR_NAME) + 1, \ 168168404Spjd KM_SLEEP); \ 169168404Spjd dsl_dir_name(dd, __ds_name); \ 170168404Spjd dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \ 171168404Spjd kmem_free(__ds_name, MAXNAMELEN + strlen(MOS_DIR_NAME) + 1); \ 172168404Spjd } \ 173168404Spjd_NOTE(CONSTCOND) } while (0) 174168404Spjd#else 175168404Spjd#define dprintf_dd(dd, fmt, ...) 176168404Spjd#endif 177168404Spjd 178168404Spjd#ifdef __cplusplus 179168404Spjd} 180168404Spjd#endif 181168404Spjd 182168404Spjd#endif /* _SYS_DSL_DIR_H */ 183