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. 23248571Smm * Copyright (c) 2012 by Delphix. All rights reserved. 24251478Sdelphij * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. 25168404Spjd */ 26168404Spjd 27219089Spjd/* Portions Copyright 2010 Robert Milkowski */ 28219089Spjd 29168404Spjd#ifndef _SYS_DMU_OBJSET_H 30168404Spjd#define _SYS_DMU_OBJSET_H 31168404Spjd 32168404Spjd#include <sys/spa.h> 33168404Spjd#include <sys/arc.h> 34168404Spjd#include <sys/txg.h> 35168404Spjd#include <sys/zfs_context.h> 36168404Spjd#include <sys/dnode.h> 37168404Spjd#include <sys/zio.h> 38168404Spjd#include <sys/zil.h> 39219089Spjd#include <sys/sa.h> 40168404Spjd 41168404Spjd#ifdef __cplusplus 42168404Spjdextern "C" { 43168404Spjd#endif 44168404Spjd 45219089Spjdextern krwlock_t os_lock; 46219089Spjd 47248571Smmstruct dsl_pool; 48168404Spjdstruct dsl_dataset; 49168404Spjdstruct dmu_tx; 50168404Spjd 51209962Smm#define OBJSET_PHYS_SIZE 2048 52209962Smm#define OBJSET_OLD_PHYS_SIZE 1024 53209962Smm 54219089Spjd#define OBJSET_BUF_HAS_USERUSED(buf) \ 55219089Spjd (arc_buf_size(buf) > OBJSET_OLD_PHYS_SIZE) 56219089Spjd 57209962Smm#define OBJSET_FLAG_USERACCOUNTING_COMPLETE (1ULL<<0) 58209962Smm 59168404Spjdtypedef struct objset_phys { 60168404Spjd dnode_phys_t os_meta_dnode; 61168404Spjd zil_header_t os_zil_header; 62168404Spjd uint64_t os_type; 63209962Smm uint64_t os_flags; 64209962Smm char os_pad[OBJSET_PHYS_SIZE - sizeof (dnode_phys_t)*3 - 65209962Smm sizeof (zil_header_t) - sizeof (uint64_t)*2]; 66209962Smm dnode_phys_t os_userused_dnode; 67209962Smm dnode_phys_t os_groupused_dnode; 68168404Spjd} objset_phys_t; 69168404Spjd 70168404Spjdstruct objset { 71168404Spjd /* Immutable: */ 72168404Spjd struct dsl_dataset *os_dsl_dataset; 73168404Spjd spa_t *os_spa; 74168404Spjd arc_buf_t *os_phys_buf; 75168404Spjd objset_phys_t *os_phys; 76219089Spjd /* 77219089Spjd * The following "special" dnodes have no parent and are exempt from 78219089Spjd * dnode_move(), but they root their descendents in this objset using 79219089Spjd * handles anyway, so that all access to dnodes from dbufs consistently 80219089Spjd * uses handles. 81219089Spjd */ 82219089Spjd dnode_handle_t os_meta_dnode; 83219089Spjd dnode_handle_t os_userused_dnode; 84219089Spjd dnode_handle_t os_groupused_dnode; 85168404Spjd zilog_t *os_zil; 86168404Spjd 87219089Spjd /* can change, under dsl_dir's locks: */ 88219089Spjd uint8_t os_checksum; 89219089Spjd uint8_t os_compress; 90219089Spjd uint8_t os_copies; 91219089Spjd uint8_t os_dedup_checksum; 92219089Spjd uint8_t os_dedup_verify; 93219089Spjd uint8_t os_logbias; 94219089Spjd uint8_t os_primary_cache; 95219089Spjd uint8_t os_secondary_cache; 96219089Spjd uint8_t os_sync; 97219089Spjd 98168404Spjd /* no lock needed: */ 99168404Spjd struct dmu_tx *os_synctx; /* XXX sketchy */ 100168404Spjd blkptr_t *os_rootbp; 101185029Spjd zil_header_t os_zil_header; 102209962Smm list_t os_synced_dnodes; 103209962Smm uint64_t os_flags; 104168404Spjd 105168404Spjd /* Protected by os_obj_lock */ 106168404Spjd kmutex_t os_obj_lock; 107168404Spjd uint64_t os_obj_next; 108168404Spjd 109168404Spjd /* Protected by os_lock */ 110168404Spjd kmutex_t os_lock; 111168404Spjd list_t os_dirty_dnodes[TXG_SIZE]; 112168404Spjd list_t os_free_dnodes[TXG_SIZE]; 113168404Spjd list_t os_dnodes; 114168404Spjd list_t os_downgraded_dbufs; 115185029Spjd 116185029Spjd /* stuff we store for the user */ 117185029Spjd kmutex_t os_user_ptr_lock; 118185029Spjd void *os_user_ptr; 119219089Spjd sa_os_t *os_sa; 120219089Spjd}; 121219089Spjd 122219089Spjd#define DMU_META_OBJSET 0 123168404Spjd#define DMU_META_DNODE_OBJECT 0 124209962Smm#define DMU_OBJECT_IS_SPECIAL(obj) ((int64_t)(obj) <= 0) 125219089Spjd#define DMU_META_DNODE(os) ((os)->os_meta_dnode.dnh_dnode) 126219089Spjd#define DMU_USERUSED_DNODE(os) ((os)->os_userused_dnode.dnh_dnode) 127219089Spjd#define DMU_GROUPUSED_DNODE(os) ((os)->os_groupused_dnode.dnh_dnode) 128168404Spjd 129185029Spjd#define DMU_OS_IS_L2CACHEABLE(os) \ 130185029Spjd ((os)->os_secondary_cache == ZFS_CACHE_ALL || \ 131185029Spjd (os)->os_secondary_cache == ZFS_CACHE_METADATA) 132185029Spjd 133251478Sdelphij#define DMU_OS_IS_L2COMPRESSIBLE(os) ((os)->os_compress != ZIO_COMPRESS_OFF) 134251478Sdelphij 135168404Spjd/* called from zpl */ 136219089Spjdint dmu_objset_hold(const char *name, void *tag, objset_t **osp); 137219089Spjdint dmu_objset_own(const char *name, dmu_objset_type_t type, 138219089Spjd boolean_t readonly, void *tag, objset_t **osp); 139253816Sdelphijvoid dmu_objset_refresh_ownership(objset_t *os, void *tag); 140219089Spjdvoid dmu_objset_rele(objset_t *os, void *tag); 141219089Spjdvoid dmu_objset_disown(objset_t *os, void *tag); 142219089Spjdint dmu_objset_from_ds(struct dsl_dataset *ds, objset_t **osp); 143219089Spjd 144168404Spjdvoid dmu_objset_stats(objset_t *os, nvlist_t *nv); 145168404Spjdvoid dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat); 146168404Spjdvoid dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp, 147168404Spjd uint64_t *usedobjsp, uint64_t *availobjsp); 148168404Spjduint64_t dmu_objset_fsid_guid(objset_t *os); 149248571Smmint dmu_objset_find_dp(struct dsl_pool *dp, uint64_t ddobj, 150248571Smm int func(struct dsl_pool *, struct dsl_dataset *, void *), 151248571Smm void *arg, int flags); 152219089Spjdint dmu_objset_prefetch(const char *name, void *arg); 153248571Smmvoid dmu_objset_evict_dbufs(objset_t *os); 154219089Spjdtimestruc_t dmu_objset_snap_cmtime(objset_t *os); 155168404Spjd 156168404Spjd/* called from dsl */ 157219089Spjdvoid dmu_objset_sync(objset_t *os, zio_t *zio, dmu_tx_t *tx); 158219089Spjdboolean_t dmu_objset_is_dirty(objset_t *os, uint64_t txg); 159219089Spjdobjset_t *dmu_objset_create_impl(spa_t *spa, struct dsl_dataset *ds, 160168404Spjd blkptr_t *bp, dmu_objset_type_t type, dmu_tx_t *tx); 161168404Spjdint dmu_objset_open_impl(spa_t *spa, struct dsl_dataset *ds, blkptr_t *bp, 162219089Spjd objset_t **osp); 163219089Spjdvoid dmu_objset_evict(objset_t *os); 164219089Spjdvoid dmu_objset_do_userquota_updates(objset_t *os, dmu_tx_t *tx); 165219089Spjdvoid dmu_objset_userquota_get_ids(dnode_t *dn, boolean_t before, dmu_tx_t *tx); 166219089Spjdboolean_t dmu_objset_userused_enabled(objset_t *os); 167209962Smmint dmu_objset_userspace_upgrade(objset_t *os); 168209962Smmboolean_t dmu_objset_userspace_present(objset_t *os); 169248571Smmint dmu_fsname(const char *snapname, char *buf); 170168404Spjd 171219089Spjdvoid dmu_objset_init(void); 172219089Spjdvoid dmu_objset_fini(void); 173219089Spjd 174168404Spjd#ifdef __cplusplus 175168404Spjd} 176168404Spjd#endif 177168404Spjd 178168404Spjd#endif /* _SYS_DMU_OBJSET_H */ 179