1eda14cbcSMatt Macy /* 2eda14cbcSMatt Macy * CDDL HEADER START 3eda14cbcSMatt Macy * 4eda14cbcSMatt Macy * The contents of this file are subject to the terms of the 5eda14cbcSMatt Macy * Common Development and Distribution License (the "License"). 6eda14cbcSMatt Macy * You may not use this file except in compliance with the License. 7eda14cbcSMatt Macy * 8eda14cbcSMatt Macy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9271171e0SMartin Matuska * or https://opensource.org/licenses/CDDL-1.0. 10eda14cbcSMatt Macy * See the License for the specific language governing permissions 11eda14cbcSMatt Macy * and limitations under the License. 12eda14cbcSMatt Macy * 13eda14cbcSMatt Macy * When distributing Covered Code, include this CDDL HEADER in each 14eda14cbcSMatt Macy * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15eda14cbcSMatt Macy * If applicable, add the following below this CDDL HEADER, with the 16eda14cbcSMatt Macy * fields enclosed by brackets "[]" replaced with your own identifying 17eda14cbcSMatt Macy * information: Portions Copyright [yyyy] [name of copyright owner] 18eda14cbcSMatt Macy * 19eda14cbcSMatt Macy * CDDL HEADER END 20eda14cbcSMatt Macy */ 21eda14cbcSMatt Macy /* 22eda14cbcSMatt Macy * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23eda14cbcSMatt Macy * Copyright (c) 2011, 2020 by Delphix. All rights reserved. 24eda14cbcSMatt Macy * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 25eda14cbcSMatt Macy * Copyright (c) 2012, Joyent, Inc. All rights reserved. 26eda14cbcSMatt Macy * Copyright 2014 HybridCluster. All rights reserved. 27eda14cbcSMatt Macy * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved. 28eda14cbcSMatt Macy * Copyright 2013 Saso Kiselkov. All rights reserved. 29eda14cbcSMatt Macy * Copyright (c) 2017, Intel Corporation. 30dbd5678dSMartin Matuska * Copyright (c) 2022 Hewlett Packard Enterprise Development LP. 31eda14cbcSMatt Macy */ 32eda14cbcSMatt Macy 33eda14cbcSMatt Macy /* Portions Copyright 2010 Robert Milkowski */ 34eda14cbcSMatt Macy 35eda14cbcSMatt Macy #ifndef _SYS_DMU_H 36eda14cbcSMatt Macy #define _SYS_DMU_H 37eda14cbcSMatt Macy 38eda14cbcSMatt Macy /* 39eda14cbcSMatt Macy * This file describes the interface that the DMU provides for its 40eda14cbcSMatt Macy * consumers. 41eda14cbcSMatt Macy * 42eda14cbcSMatt Macy * The DMU also interacts with the SPA. That interface is described in 43eda14cbcSMatt Macy * dmu_spa.h. 44eda14cbcSMatt Macy */ 45eda14cbcSMatt Macy 46eda14cbcSMatt Macy #include <sys/zfs_context.h> 47eda14cbcSMatt Macy #include <sys/inttypes.h> 48eda14cbcSMatt Macy #include <sys/cred.h> 49eda14cbcSMatt Macy #include <sys/fs/zfs.h> 50eda14cbcSMatt Macy #include <sys/zio_compress.h> 51eda14cbcSMatt Macy #include <sys/zio_priority.h> 52eda14cbcSMatt Macy #include <sys/uio.h> 53eda14cbcSMatt Macy #include <sys/zfs_file.h> 54eda14cbcSMatt Macy 55eda14cbcSMatt Macy #ifdef __cplusplus 56eda14cbcSMatt Macy extern "C" { 57eda14cbcSMatt Macy #endif 58eda14cbcSMatt Macy 59eda14cbcSMatt Macy struct page; 60eda14cbcSMatt Macy struct vnode; 61eda14cbcSMatt Macy struct spa; 62eda14cbcSMatt Macy struct zilog; 63eda14cbcSMatt Macy struct zio; 64eda14cbcSMatt Macy struct blkptr; 65eda14cbcSMatt Macy struct zap_cursor; 66eda14cbcSMatt Macy struct dsl_dataset; 67eda14cbcSMatt Macy struct dsl_pool; 68eda14cbcSMatt Macy struct dnode; 69eda14cbcSMatt Macy struct drr_begin; 70eda14cbcSMatt Macy struct drr_end; 71eda14cbcSMatt Macy struct zbookmark_phys; 72eda14cbcSMatt Macy struct spa; 73eda14cbcSMatt Macy struct nvlist; 74eda14cbcSMatt Macy struct arc_buf; 75eda14cbcSMatt Macy struct zio_prop; 76eda14cbcSMatt Macy struct sa_handle; 77eda14cbcSMatt Macy struct dsl_crypto_params; 78eda14cbcSMatt Macy struct locked_range; 79eda14cbcSMatt Macy 80eda14cbcSMatt Macy typedef struct objset objset_t; 81eda14cbcSMatt Macy typedef struct dmu_tx dmu_tx_t; 82eda14cbcSMatt Macy typedef struct dsl_dir dsl_dir_t; 83eda14cbcSMatt Macy typedef struct dnode dnode_t; 84eda14cbcSMatt Macy 85eda14cbcSMatt Macy typedef enum dmu_object_byteswap { 86eda14cbcSMatt Macy DMU_BSWAP_UINT8, 87eda14cbcSMatt Macy DMU_BSWAP_UINT16, 88eda14cbcSMatt Macy DMU_BSWAP_UINT32, 89eda14cbcSMatt Macy DMU_BSWAP_UINT64, 90eda14cbcSMatt Macy DMU_BSWAP_ZAP, 91eda14cbcSMatt Macy DMU_BSWAP_DNODE, 92eda14cbcSMatt Macy DMU_BSWAP_OBJSET, 93eda14cbcSMatt Macy DMU_BSWAP_ZNODE, 94eda14cbcSMatt Macy DMU_BSWAP_OLDACL, 95eda14cbcSMatt Macy DMU_BSWAP_ACL, 96eda14cbcSMatt Macy /* 97eda14cbcSMatt Macy * Allocating a new byteswap type number makes the on-disk format 98eda14cbcSMatt Macy * incompatible with any other format that uses the same number. 99eda14cbcSMatt Macy * 100eda14cbcSMatt Macy * Data can usually be structured to work with one of the 101eda14cbcSMatt Macy * DMU_BSWAP_UINT* or DMU_BSWAP_ZAP types. 102eda14cbcSMatt Macy */ 103eda14cbcSMatt Macy DMU_BSWAP_NUMFUNCS 104eda14cbcSMatt Macy } dmu_object_byteswap_t; 105eda14cbcSMatt Macy 106eda14cbcSMatt Macy #define DMU_OT_NEWTYPE 0x80 107eda14cbcSMatt Macy #define DMU_OT_METADATA 0x40 108eda14cbcSMatt Macy #define DMU_OT_ENCRYPTED 0x20 109eda14cbcSMatt Macy #define DMU_OT_BYTESWAP_MASK 0x1f 110eda14cbcSMatt Macy 111eda14cbcSMatt Macy /* 112eda14cbcSMatt Macy * Defines a uint8_t object type. Object types specify if the data 113eda14cbcSMatt Macy * in the object is metadata (boolean) and how to byteswap the data 114eda14cbcSMatt Macy * (dmu_object_byteswap_t). All of the types created by this method 115eda14cbcSMatt Macy * are cached in the dbuf metadata cache. 116eda14cbcSMatt Macy */ 117eda14cbcSMatt Macy #define DMU_OT(byteswap, metadata, encrypted) \ 118eda14cbcSMatt Macy (DMU_OT_NEWTYPE | \ 119eda14cbcSMatt Macy ((metadata) ? DMU_OT_METADATA : 0) | \ 120eda14cbcSMatt Macy ((encrypted) ? DMU_OT_ENCRYPTED : 0) | \ 121eda14cbcSMatt Macy ((byteswap) & DMU_OT_BYTESWAP_MASK)) 122eda14cbcSMatt Macy 123eda14cbcSMatt Macy #define DMU_OT_IS_VALID(ot) (((ot) & DMU_OT_NEWTYPE) ? \ 124eda14cbcSMatt Macy ((ot) & DMU_OT_BYTESWAP_MASK) < DMU_BSWAP_NUMFUNCS : \ 125eda14cbcSMatt Macy (ot) < DMU_OT_NUMTYPES) 126eda14cbcSMatt Macy 127eda14cbcSMatt Macy #define DMU_OT_IS_METADATA_CACHED(ot) (((ot) & DMU_OT_NEWTYPE) ? \ 128eda14cbcSMatt Macy B_TRUE : dmu_ot[(ot)].ot_dbuf_metadata_cache) 129eda14cbcSMatt Macy 130eda14cbcSMatt Macy /* 131eda14cbcSMatt Macy * MDB doesn't have dmu_ot; it defines these macros itself. 132eda14cbcSMatt Macy */ 133eda14cbcSMatt Macy #ifndef ZFS_MDB 134eda14cbcSMatt Macy #define DMU_OT_IS_METADATA_IMPL(ot) (dmu_ot[ot].ot_metadata) 135eda14cbcSMatt Macy #define DMU_OT_IS_ENCRYPTED_IMPL(ot) (dmu_ot[ot].ot_encrypt) 136eda14cbcSMatt Macy #define DMU_OT_BYTESWAP_IMPL(ot) (dmu_ot[ot].ot_byteswap) 137eda14cbcSMatt Macy #endif 138eda14cbcSMatt Macy 139eda14cbcSMatt Macy #define DMU_OT_IS_METADATA(ot) (((ot) & DMU_OT_NEWTYPE) ? \ 140c7046f76SMartin Matuska (((ot) & DMU_OT_METADATA) != 0) : \ 141eda14cbcSMatt Macy DMU_OT_IS_METADATA_IMPL(ot)) 142eda14cbcSMatt Macy 143eda14cbcSMatt Macy #define DMU_OT_IS_DDT(ot) \ 144eda14cbcSMatt Macy ((ot) == DMU_OT_DDT_ZAP) 145eda14cbcSMatt Macy 146dbd5678dSMartin Matuska #define DMU_OT_IS_CRITICAL(ot) \ 147dbd5678dSMartin Matuska (DMU_OT_IS_METADATA(ot) && \ 148dbd5678dSMartin Matuska (ot) != DMU_OT_DNODE && \ 149dbd5678dSMartin Matuska (ot) != DMU_OT_DIRECTORY_CONTENTS && \ 150dbd5678dSMartin Matuska (ot) != DMU_OT_SA) 151dbd5678dSMartin Matuska 152eda14cbcSMatt Macy /* Note: ztest uses DMU_OT_UINT64_OTHER as a proxy for file blocks */ 153eda14cbcSMatt Macy #define DMU_OT_IS_FILE(ot) \ 154eda14cbcSMatt Macy ((ot) == DMU_OT_PLAIN_FILE_CONTENTS || (ot) == DMU_OT_UINT64_OTHER) 155eda14cbcSMatt Macy 156eda14cbcSMatt Macy #define DMU_OT_IS_ENCRYPTED(ot) (((ot) & DMU_OT_NEWTYPE) ? \ 157c7046f76SMartin Matuska (((ot) & DMU_OT_ENCRYPTED) != 0) : \ 158eda14cbcSMatt Macy DMU_OT_IS_ENCRYPTED_IMPL(ot)) 159eda14cbcSMatt Macy 160eda14cbcSMatt Macy /* 161eda14cbcSMatt Macy * These object types use bp_fill != 1 for their L0 bp's. Therefore they can't 162eda14cbcSMatt Macy * have their data embedded (i.e. use a BP_IS_EMBEDDED() bp), because bp_fill 163eda14cbcSMatt Macy * is repurposed for embedded BPs. 164eda14cbcSMatt Macy */ 165eda14cbcSMatt Macy #define DMU_OT_HAS_FILL(ot) \ 166eda14cbcSMatt Macy ((ot) == DMU_OT_DNODE || (ot) == DMU_OT_OBJSET) 167eda14cbcSMatt Macy 168eda14cbcSMatt Macy #define DMU_OT_BYTESWAP(ot) (((ot) & DMU_OT_NEWTYPE) ? \ 169eda14cbcSMatt Macy ((ot) & DMU_OT_BYTESWAP_MASK) : \ 170eda14cbcSMatt Macy DMU_OT_BYTESWAP_IMPL(ot)) 171eda14cbcSMatt Macy 172eda14cbcSMatt Macy typedef enum dmu_object_type { 173eda14cbcSMatt Macy DMU_OT_NONE, 174eda14cbcSMatt Macy /* general: */ 175eda14cbcSMatt Macy DMU_OT_OBJECT_DIRECTORY, /* ZAP */ 176eda14cbcSMatt Macy DMU_OT_OBJECT_ARRAY, /* UINT64 */ 177eda14cbcSMatt Macy DMU_OT_PACKED_NVLIST, /* UINT8 (XDR by nvlist_pack/unpack) */ 178eda14cbcSMatt Macy DMU_OT_PACKED_NVLIST_SIZE, /* UINT64 */ 179eda14cbcSMatt Macy DMU_OT_BPOBJ, /* UINT64 */ 180eda14cbcSMatt Macy DMU_OT_BPOBJ_HDR, /* UINT64 */ 181eda14cbcSMatt Macy /* spa: */ 182eda14cbcSMatt Macy DMU_OT_SPACE_MAP_HEADER, /* UINT64 */ 183eda14cbcSMatt Macy DMU_OT_SPACE_MAP, /* UINT64 */ 184eda14cbcSMatt Macy /* zil: */ 185eda14cbcSMatt Macy DMU_OT_INTENT_LOG, /* UINT64 */ 186eda14cbcSMatt Macy /* dmu: */ 187eda14cbcSMatt Macy DMU_OT_DNODE, /* DNODE */ 188eda14cbcSMatt Macy DMU_OT_OBJSET, /* OBJSET */ 189eda14cbcSMatt Macy /* dsl: */ 190eda14cbcSMatt Macy DMU_OT_DSL_DIR, /* UINT64 */ 191eda14cbcSMatt Macy DMU_OT_DSL_DIR_CHILD_MAP, /* ZAP */ 192eda14cbcSMatt Macy DMU_OT_DSL_DS_SNAP_MAP, /* ZAP */ 193eda14cbcSMatt Macy DMU_OT_DSL_PROPS, /* ZAP */ 194eda14cbcSMatt Macy DMU_OT_DSL_DATASET, /* UINT64 */ 195eda14cbcSMatt Macy /* zpl: */ 196eda14cbcSMatt Macy DMU_OT_ZNODE, /* ZNODE */ 197eda14cbcSMatt Macy DMU_OT_OLDACL, /* Old ACL */ 198eda14cbcSMatt Macy DMU_OT_PLAIN_FILE_CONTENTS, /* UINT8 */ 199eda14cbcSMatt Macy DMU_OT_DIRECTORY_CONTENTS, /* ZAP */ 200eda14cbcSMatt Macy DMU_OT_MASTER_NODE, /* ZAP */ 201eda14cbcSMatt Macy DMU_OT_UNLINKED_SET, /* ZAP */ 202eda14cbcSMatt Macy /* zvol: */ 203eda14cbcSMatt Macy DMU_OT_ZVOL, /* UINT8 */ 204eda14cbcSMatt Macy DMU_OT_ZVOL_PROP, /* ZAP */ 205eda14cbcSMatt Macy /* other; for testing only! */ 206eda14cbcSMatt Macy DMU_OT_PLAIN_OTHER, /* UINT8 */ 207eda14cbcSMatt Macy DMU_OT_UINT64_OTHER, /* UINT64 */ 208eda14cbcSMatt Macy DMU_OT_ZAP_OTHER, /* ZAP */ 209eda14cbcSMatt Macy /* new object types: */ 210eda14cbcSMatt Macy DMU_OT_ERROR_LOG, /* ZAP */ 211eda14cbcSMatt Macy DMU_OT_SPA_HISTORY, /* UINT8 */ 212eda14cbcSMatt Macy DMU_OT_SPA_HISTORY_OFFSETS, /* spa_his_phys_t */ 213eda14cbcSMatt Macy DMU_OT_POOL_PROPS, /* ZAP */ 214eda14cbcSMatt Macy DMU_OT_DSL_PERMS, /* ZAP */ 215eda14cbcSMatt Macy DMU_OT_ACL, /* ACL */ 216eda14cbcSMatt Macy DMU_OT_SYSACL, /* SYSACL */ 217eda14cbcSMatt Macy DMU_OT_FUID, /* FUID table (Packed NVLIST UINT8) */ 218eda14cbcSMatt Macy DMU_OT_FUID_SIZE, /* FUID table size UINT64 */ 219eda14cbcSMatt Macy DMU_OT_NEXT_CLONES, /* ZAP */ 220eda14cbcSMatt Macy DMU_OT_SCAN_QUEUE, /* ZAP */ 221eda14cbcSMatt Macy DMU_OT_USERGROUP_USED, /* ZAP */ 222eda14cbcSMatt Macy DMU_OT_USERGROUP_QUOTA, /* ZAP */ 223eda14cbcSMatt Macy DMU_OT_USERREFS, /* ZAP */ 224eda14cbcSMatt Macy DMU_OT_DDT_ZAP, /* ZAP */ 225eda14cbcSMatt Macy DMU_OT_DDT_STATS, /* ZAP */ 226eda14cbcSMatt Macy DMU_OT_SA, /* System attr */ 227eda14cbcSMatt Macy DMU_OT_SA_MASTER_NODE, /* ZAP */ 228eda14cbcSMatt Macy DMU_OT_SA_ATTR_REGISTRATION, /* ZAP */ 229eda14cbcSMatt Macy DMU_OT_SA_ATTR_LAYOUTS, /* ZAP */ 230eda14cbcSMatt Macy DMU_OT_SCAN_XLATE, /* ZAP */ 231eda14cbcSMatt Macy DMU_OT_DEDUP, /* fake dedup BP from ddt_bp_create() */ 232eda14cbcSMatt Macy DMU_OT_DEADLIST, /* ZAP */ 233eda14cbcSMatt Macy DMU_OT_DEADLIST_HDR, /* UINT64 */ 234eda14cbcSMatt Macy DMU_OT_DSL_CLONES, /* ZAP */ 235eda14cbcSMatt Macy DMU_OT_BPOBJ_SUBOBJ, /* UINT64 */ 236eda14cbcSMatt Macy /* 237eda14cbcSMatt Macy * Do not allocate new object types here. Doing so makes the on-disk 238eda14cbcSMatt Macy * format incompatible with any other format that uses the same object 239eda14cbcSMatt Macy * type number. 240eda14cbcSMatt Macy * 241eda14cbcSMatt Macy * When creating an object which does not have one of the above types 242eda14cbcSMatt Macy * use the DMU_OTN_* type with the correct byteswap and metadata 243eda14cbcSMatt Macy * values. 244eda14cbcSMatt Macy * 245eda14cbcSMatt Macy * The DMU_OTN_* types do not have entries in the dmu_ot table, 246eda14cbcSMatt Macy * use the DMU_OT_IS_METADATA() and DMU_OT_BYTESWAP() macros instead 247eda14cbcSMatt Macy * of indexing into dmu_ot directly (this works for both DMU_OT_* types 248eda14cbcSMatt Macy * and DMU_OTN_* types). 249eda14cbcSMatt Macy */ 250eda14cbcSMatt Macy DMU_OT_NUMTYPES, 251eda14cbcSMatt Macy 252eda14cbcSMatt Macy /* 253eda14cbcSMatt Macy * Names for valid types declared with DMU_OT(). 254eda14cbcSMatt Macy */ 255eda14cbcSMatt Macy DMU_OTN_UINT8_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE, B_FALSE), 256eda14cbcSMatt Macy DMU_OTN_UINT8_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE, B_FALSE), 257eda14cbcSMatt Macy DMU_OTN_UINT16_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE, B_FALSE), 258eda14cbcSMatt Macy DMU_OTN_UINT16_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE, B_FALSE), 259eda14cbcSMatt Macy DMU_OTN_UINT32_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE, B_FALSE), 260eda14cbcSMatt Macy DMU_OTN_UINT32_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE, B_FALSE), 261eda14cbcSMatt Macy DMU_OTN_UINT64_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE, B_FALSE), 262eda14cbcSMatt Macy DMU_OTN_UINT64_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE, B_FALSE), 263eda14cbcSMatt Macy DMU_OTN_ZAP_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE, B_FALSE), 264eda14cbcSMatt Macy DMU_OTN_ZAP_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE, B_FALSE), 265eda14cbcSMatt Macy 266eda14cbcSMatt Macy DMU_OTN_UINT8_ENC_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE, B_TRUE), 267eda14cbcSMatt Macy DMU_OTN_UINT8_ENC_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE, B_TRUE), 268eda14cbcSMatt Macy DMU_OTN_UINT16_ENC_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE, B_TRUE), 269eda14cbcSMatt Macy DMU_OTN_UINT16_ENC_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE, B_TRUE), 270eda14cbcSMatt Macy DMU_OTN_UINT32_ENC_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE, B_TRUE), 271eda14cbcSMatt Macy DMU_OTN_UINT32_ENC_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE, B_TRUE), 272eda14cbcSMatt Macy DMU_OTN_UINT64_ENC_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE, B_TRUE), 273eda14cbcSMatt Macy DMU_OTN_UINT64_ENC_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE, B_TRUE), 274eda14cbcSMatt Macy DMU_OTN_ZAP_ENC_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE, B_TRUE), 275eda14cbcSMatt Macy DMU_OTN_ZAP_ENC_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE, B_TRUE), 276eda14cbcSMatt Macy } dmu_object_type_t; 277eda14cbcSMatt Macy 278eda14cbcSMatt Macy /* 279eda14cbcSMatt Macy * These flags are intended to be used to specify the "txg_how" 280eda14cbcSMatt Macy * parameter when calling the dmu_tx_assign() function. See the comment 281eda14cbcSMatt Macy * above dmu_tx_assign() for more details on the meaning of these flags. 282eda14cbcSMatt Macy */ 283eda14cbcSMatt Macy #define TXG_NOWAIT (0ULL) 284eda14cbcSMatt Macy #define TXG_WAIT (1ULL<<0) 285eda14cbcSMatt Macy #define TXG_NOTHROTTLE (1ULL<<1) 286eda14cbcSMatt Macy 287eda14cbcSMatt Macy void byteswap_uint64_array(void *buf, size_t size); 288eda14cbcSMatt Macy void byteswap_uint32_array(void *buf, size_t size); 289eda14cbcSMatt Macy void byteswap_uint16_array(void *buf, size_t size); 290eda14cbcSMatt Macy void byteswap_uint8_array(void *buf, size_t size); 291eda14cbcSMatt Macy void zap_byteswap(void *buf, size_t size); 292eda14cbcSMatt Macy void zfs_oldacl_byteswap(void *buf, size_t size); 293eda14cbcSMatt Macy void zfs_acl_byteswap(void *buf, size_t size); 294eda14cbcSMatt Macy void zfs_znode_byteswap(void *buf, size_t size); 295eda14cbcSMatt Macy 296eda14cbcSMatt Macy #define DS_FIND_SNAPSHOTS (1<<0) 297eda14cbcSMatt Macy #define DS_FIND_CHILDREN (1<<1) 298eda14cbcSMatt Macy #define DS_FIND_SERIALIZE (1<<2) 299eda14cbcSMatt Macy 300eda14cbcSMatt Macy /* 301eda14cbcSMatt Macy * The maximum number of bytes that can be accessed as part of one 302eda14cbcSMatt Macy * operation, including metadata. 303eda14cbcSMatt Macy */ 304eda14cbcSMatt Macy #define DMU_MAX_ACCESS (64 * 1024 * 1024) /* 64MB */ 305eda14cbcSMatt Macy #define DMU_MAX_DELETEBLKCNT (20480) /* ~5MB of indirect blocks */ 306eda14cbcSMatt Macy 307eda14cbcSMatt Macy #define DMU_USERUSED_OBJECT (-1ULL) 308eda14cbcSMatt Macy #define DMU_GROUPUSED_OBJECT (-2ULL) 309eda14cbcSMatt Macy #define DMU_PROJECTUSED_OBJECT (-3ULL) 310eda14cbcSMatt Macy 311eda14cbcSMatt Macy /* 312eda14cbcSMatt Macy * Zap prefix for object accounting in DMU_{USER,GROUP,PROJECT}USED_OBJECT. 313eda14cbcSMatt Macy */ 314eda14cbcSMatt Macy #define DMU_OBJACCT_PREFIX "obj-" 315eda14cbcSMatt Macy #define DMU_OBJACCT_PREFIX_LEN 4 316eda14cbcSMatt Macy 317eda14cbcSMatt Macy /* 318eda14cbcSMatt Macy * artificial blkids for bonus buffer and spill blocks 319eda14cbcSMatt Macy */ 320eda14cbcSMatt Macy #define DMU_BONUS_BLKID (-1ULL) 321eda14cbcSMatt Macy #define DMU_SPILL_BLKID (-2ULL) 322eda14cbcSMatt Macy 323eda14cbcSMatt Macy /* 324eda14cbcSMatt Macy * Public routines to create, destroy, open, and close objsets. 325eda14cbcSMatt Macy */ 326eda14cbcSMatt Macy typedef void dmu_objset_create_sync_func_t(objset_t *os, void *arg, 327eda14cbcSMatt Macy cred_t *cr, dmu_tx_t *tx); 328eda14cbcSMatt Macy 329a0b956f5SMartin Matuska int dmu_objset_hold(const char *name, const void *tag, objset_t **osp); 330eda14cbcSMatt Macy int dmu_objset_own(const char *name, dmu_objset_type_t type, 331a0b956f5SMartin Matuska boolean_t readonly, boolean_t key_required, const void *tag, 332a0b956f5SMartin Matuska objset_t **osp); 333a0b956f5SMartin Matuska void dmu_objset_rele(objset_t *os, const void *tag); 334a0b956f5SMartin Matuska void dmu_objset_disown(objset_t *os, boolean_t key_required, const void *tag); 335eda14cbcSMatt Macy int dmu_objset_open_ds(struct dsl_dataset *ds, objset_t **osp); 336eda14cbcSMatt Macy 337eda14cbcSMatt Macy void dmu_objset_evict_dbufs(objset_t *os); 338eda14cbcSMatt Macy int dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags, 339eda14cbcSMatt Macy struct dsl_crypto_params *dcp, dmu_objset_create_sync_func_t func, 340eda14cbcSMatt Macy void *arg); 341eda14cbcSMatt Macy int dmu_objset_clone(const char *name, const char *origin); 342eda14cbcSMatt Macy int dsl_destroy_snapshots_nvl(struct nvlist *snaps, boolean_t defer, 343eda14cbcSMatt Macy struct nvlist *errlist); 344eda14cbcSMatt Macy int dmu_objset_snapshot_one(const char *fsname, const char *snapname); 345eda14cbcSMatt Macy int dmu_objset_find(const char *name, int func(const char *, void *), void *arg, 346eda14cbcSMatt Macy int flags); 347eda14cbcSMatt Macy void dmu_objset_byteswap(void *buf, size_t size); 348eda14cbcSMatt Macy int dsl_dataset_rename_snapshot(const char *fsname, 349eda14cbcSMatt Macy const char *oldsnapname, const char *newsnapname, boolean_t recursive); 350eda14cbcSMatt Macy 351eda14cbcSMatt Macy typedef struct dmu_buf { 352eda14cbcSMatt Macy uint64_t db_object; /* object that this buffer is part of */ 353eda14cbcSMatt Macy uint64_t db_offset; /* byte offset in this object */ 354eda14cbcSMatt Macy uint64_t db_size; /* size of buffer in bytes */ 355eda14cbcSMatt Macy void *db_data; /* data in buffer */ 356eda14cbcSMatt Macy } dmu_buf_t; 357eda14cbcSMatt Macy 358eda14cbcSMatt Macy /* 359eda14cbcSMatt Macy * The names of zap entries in the DIRECTORY_OBJECT of the MOS. 360eda14cbcSMatt Macy */ 361eda14cbcSMatt Macy #define DMU_POOL_DIRECTORY_OBJECT 1 362eda14cbcSMatt Macy #define DMU_POOL_CONFIG "config" 363eda14cbcSMatt Macy #define DMU_POOL_FEATURES_FOR_WRITE "features_for_write" 364eda14cbcSMatt Macy #define DMU_POOL_FEATURES_FOR_READ "features_for_read" 365eda14cbcSMatt Macy #define DMU_POOL_FEATURE_DESCRIPTIONS "feature_descriptions" 366eda14cbcSMatt Macy #define DMU_POOL_FEATURE_ENABLED_TXG "feature_enabled_txg" 367eda14cbcSMatt Macy #define DMU_POOL_ROOT_DATASET "root_dataset" 368eda14cbcSMatt Macy #define DMU_POOL_SYNC_BPOBJ "sync_bplist" 369eda14cbcSMatt Macy #define DMU_POOL_ERRLOG_SCRUB "errlog_scrub" 370eda14cbcSMatt Macy #define DMU_POOL_ERRLOG_LAST "errlog_last" 371eda14cbcSMatt Macy #define DMU_POOL_SPARES "spares" 372eda14cbcSMatt Macy #define DMU_POOL_DEFLATE "deflate" 373eda14cbcSMatt Macy #define DMU_POOL_HISTORY "history" 374eda14cbcSMatt Macy #define DMU_POOL_PROPS "pool_props" 375eda14cbcSMatt Macy #define DMU_POOL_L2CACHE "l2cache" 376eda14cbcSMatt Macy #define DMU_POOL_TMP_USERREFS "tmp_userrefs" 377eda14cbcSMatt Macy #define DMU_POOL_DDT "DDT-%s-%s-%s" 378e2df9bb4SMartin Matuska #define DMU_POOL_DDT_LOG "DDT-log-%s-%u" 379eda14cbcSMatt Macy #define DMU_POOL_DDT_STATS "DDT-statistics" 380e2df9bb4SMartin Matuska #define DMU_POOL_DDT_DIR "DDT-%s" 381eda14cbcSMatt Macy #define DMU_POOL_CREATION_VERSION "creation_version" 382eda14cbcSMatt Macy #define DMU_POOL_SCAN "scan" 383c0a83fe0SMartin Matuska #define DMU_POOL_ERRORSCRUB "error_scrub" 384*17aab35aSMartin Matuska #define DMU_POOL_LAST_SCRUBBED_TXG "last_scrubbed_txg" 385eda14cbcSMatt Macy #define DMU_POOL_FREE_BPOBJ "free_bpobj" 386eda14cbcSMatt Macy #define DMU_POOL_BPTREE_OBJ "bptree_obj" 387eda14cbcSMatt Macy #define DMU_POOL_EMPTY_BPOBJ "empty_bpobj" 388eda14cbcSMatt Macy #define DMU_POOL_CHECKSUM_SALT "org.illumos:checksum_salt" 389eda14cbcSMatt Macy #define DMU_POOL_VDEV_ZAP_MAP "com.delphix:vdev_zap_map" 390eda14cbcSMatt Macy #define DMU_POOL_REMOVING "com.delphix:removing" 391eda14cbcSMatt Macy #define DMU_POOL_OBSOLETE_BPOBJ "com.delphix:obsolete_bpobj" 392eda14cbcSMatt Macy #define DMU_POOL_CONDENSING_INDIRECT "com.delphix:condensing_indirect" 393eda14cbcSMatt Macy #define DMU_POOL_ZPOOL_CHECKPOINT "com.delphix:zpool_checkpoint" 394eda14cbcSMatt Macy #define DMU_POOL_LOG_SPACEMAP_ZAP "com.delphix:log_spacemap_zap" 395eda14cbcSMatt Macy #define DMU_POOL_DELETED_CLONES "com.delphix:deleted_clones" 396eda14cbcSMatt Macy 397eda14cbcSMatt Macy /* 398eda14cbcSMatt Macy * Allocate an object from this objset. The range of object numbers 399eda14cbcSMatt Macy * available is (0, DN_MAX_OBJECT). Object 0 is the meta-dnode. 400eda14cbcSMatt Macy * 401eda14cbcSMatt Macy * The transaction must be assigned to a txg. The newly allocated 402eda14cbcSMatt Macy * object will be "held" in the transaction (ie. you can modify the 403eda14cbcSMatt Macy * newly allocated object in this transaction). 404eda14cbcSMatt Macy * 405eda14cbcSMatt Macy * dmu_object_alloc() chooses an object and returns it in *objectp. 406eda14cbcSMatt Macy * 407eda14cbcSMatt Macy * dmu_object_claim() allocates a specific object number. If that 408eda14cbcSMatt Macy * number is already allocated, it fails and returns EEXIST. 409eda14cbcSMatt Macy * 410eda14cbcSMatt Macy * Return 0 on success, or ENOSPC or EEXIST as specified above. 411eda14cbcSMatt Macy */ 412eda14cbcSMatt Macy uint64_t dmu_object_alloc(objset_t *os, dmu_object_type_t ot, 413eda14cbcSMatt Macy int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx); 414eda14cbcSMatt Macy uint64_t dmu_object_alloc_ibs(objset_t *os, dmu_object_type_t ot, int blocksize, 415eda14cbcSMatt Macy int indirect_blockshift, 416eda14cbcSMatt Macy dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); 417eda14cbcSMatt Macy uint64_t dmu_object_alloc_dnsize(objset_t *os, dmu_object_type_t ot, 418eda14cbcSMatt Macy int blocksize, dmu_object_type_t bonus_type, int bonus_len, 419eda14cbcSMatt Macy int dnodesize, dmu_tx_t *tx); 420eda14cbcSMatt Macy uint64_t dmu_object_alloc_hold(objset_t *os, dmu_object_type_t ot, 421eda14cbcSMatt Macy int blocksize, int indirect_blockshift, dmu_object_type_t bonustype, 422a0b956f5SMartin Matuska int bonuslen, int dnodesize, dnode_t **allocated_dnode, const void *tag, 423eda14cbcSMatt Macy dmu_tx_t *tx); 424eda14cbcSMatt Macy int dmu_object_claim(objset_t *os, uint64_t object, dmu_object_type_t ot, 425eda14cbcSMatt Macy int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx); 426eda14cbcSMatt Macy int dmu_object_claim_dnsize(objset_t *os, uint64_t object, dmu_object_type_t ot, 427eda14cbcSMatt Macy int blocksize, dmu_object_type_t bonus_type, int bonus_len, 428eda14cbcSMatt Macy int dnodesize, dmu_tx_t *tx); 429eda14cbcSMatt Macy int dmu_object_reclaim(objset_t *os, uint64_t object, dmu_object_type_t ot, 430eda14cbcSMatt Macy int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *txp); 431eda14cbcSMatt Macy int dmu_object_reclaim_dnsize(objset_t *os, uint64_t object, 432eda14cbcSMatt Macy dmu_object_type_t ot, int blocksize, dmu_object_type_t bonustype, 433eda14cbcSMatt Macy int bonuslen, int dnodesize, boolean_t keep_spill, dmu_tx_t *tx); 434eda14cbcSMatt Macy int dmu_object_rm_spill(objset_t *os, uint64_t object, dmu_tx_t *tx); 435eda14cbcSMatt Macy 436eda14cbcSMatt Macy /* 437eda14cbcSMatt Macy * Free an object from this objset. 438eda14cbcSMatt Macy * 439eda14cbcSMatt Macy * The object's data will be freed as well (ie. you don't need to call 440eda14cbcSMatt Macy * dmu_free(object, 0, -1, tx)). 441eda14cbcSMatt Macy * 442eda14cbcSMatt Macy * The object need not be held in the transaction. 443eda14cbcSMatt Macy * 444eda14cbcSMatt Macy * If there are any holds on this object's buffers (via dmu_buf_hold()), 445eda14cbcSMatt Macy * or tx holds on the object (via dmu_tx_hold_object()), you can not 446eda14cbcSMatt Macy * free it; it fails and returns EBUSY. 447eda14cbcSMatt Macy * 448eda14cbcSMatt Macy * If the object is not allocated, it fails and returns ENOENT. 449eda14cbcSMatt Macy * 450eda14cbcSMatt Macy * Return 0 on success, or EBUSY or ENOENT as specified above. 451eda14cbcSMatt Macy */ 452eda14cbcSMatt Macy int dmu_object_free(objset_t *os, uint64_t object, dmu_tx_t *tx); 453eda14cbcSMatt Macy 454eda14cbcSMatt Macy /* 455eda14cbcSMatt Macy * Find the next allocated or free object. 456eda14cbcSMatt Macy * 457eda14cbcSMatt Macy * The objectp parameter is in-out. It will be updated to be the next 458eda14cbcSMatt Macy * object which is allocated. Ignore objects which have not been 459eda14cbcSMatt Macy * modified since txg. 460eda14cbcSMatt Macy * 461eda14cbcSMatt Macy * XXX Can only be called on a objset with no dirty data. 462eda14cbcSMatt Macy * 463eda14cbcSMatt Macy * Returns 0 on success, or ENOENT if there are no more objects. 464eda14cbcSMatt Macy */ 465eda14cbcSMatt Macy int dmu_object_next(objset_t *os, uint64_t *objectp, 466eda14cbcSMatt Macy boolean_t hole, uint64_t txg); 467eda14cbcSMatt Macy 468eda14cbcSMatt Macy /* 469eda14cbcSMatt Macy * Set the number of levels on a dnode. nlevels must be greater than the 470eda14cbcSMatt Macy * current number of levels or an EINVAL will be returned. 471eda14cbcSMatt Macy */ 472eda14cbcSMatt Macy int dmu_object_set_nlevels(objset_t *os, uint64_t object, int nlevels, 473eda14cbcSMatt Macy dmu_tx_t *tx); 474eda14cbcSMatt Macy 475eda14cbcSMatt Macy /* 476eda14cbcSMatt Macy * Set the data blocksize for an object. 477eda14cbcSMatt Macy * 478eda14cbcSMatt Macy * The object cannot have any blocks allocated beyond the first. If 479eda14cbcSMatt Macy * the first block is allocated already, the new size must be greater 480eda14cbcSMatt Macy * than the current block size. If these conditions are not met, 481eda14cbcSMatt Macy * ENOTSUP will be returned. 482eda14cbcSMatt Macy * 483eda14cbcSMatt Macy * Returns 0 on success, or EBUSY if there are any holds on the object 484eda14cbcSMatt Macy * contents, or ENOTSUP as described above. 485eda14cbcSMatt Macy */ 486eda14cbcSMatt Macy int dmu_object_set_blocksize(objset_t *os, uint64_t object, uint64_t size, 487eda14cbcSMatt Macy int ibs, dmu_tx_t *tx); 488eda14cbcSMatt Macy 489eda14cbcSMatt Macy /* 490eda14cbcSMatt Macy * Manually set the maxblkid on a dnode. This will adjust nlevels accordingly 491eda14cbcSMatt Macy * to accommodate the change. When calling this function, the caller must 492eda14cbcSMatt Macy * ensure that the object's nlevels can sufficiently support the new maxblkid. 493eda14cbcSMatt Macy */ 494eda14cbcSMatt Macy int dmu_object_set_maxblkid(objset_t *os, uint64_t object, uint64_t maxblkid, 495eda14cbcSMatt Macy dmu_tx_t *tx); 496eda14cbcSMatt Macy 497eda14cbcSMatt Macy /* 498eda14cbcSMatt Macy * Set the checksum property on a dnode. The new checksum algorithm will 499eda14cbcSMatt Macy * apply to all newly written blocks; existing blocks will not be affected. 500eda14cbcSMatt Macy */ 501eda14cbcSMatt Macy void dmu_object_set_checksum(objset_t *os, uint64_t object, uint8_t checksum, 502eda14cbcSMatt Macy dmu_tx_t *tx); 503eda14cbcSMatt Macy 504eda14cbcSMatt Macy /* 505eda14cbcSMatt Macy * Set the compress property on a dnode. The new compression algorithm will 506eda14cbcSMatt Macy * apply to all newly written blocks; existing blocks will not be affected. 507eda14cbcSMatt Macy */ 508eda14cbcSMatt Macy void dmu_object_set_compress(objset_t *os, uint64_t object, uint8_t compress, 509eda14cbcSMatt Macy dmu_tx_t *tx); 510eda14cbcSMatt Macy 511ce4dcb97SMartin Matuska /* 512ce4dcb97SMartin Matuska * Get an estimated cache size for an object. Caller must expect races. 513ce4dcb97SMartin Matuska */ 514ce4dcb97SMartin Matuska int dmu_object_cached_size(objset_t *os, uint64_t object, 515ce4dcb97SMartin Matuska uint64_t *l1sz, uint64_t *l2sz); 516ce4dcb97SMartin Matuska 517eda14cbcSMatt Macy void dmu_write_embedded(objset_t *os, uint64_t object, uint64_t offset, 518eda14cbcSMatt Macy void *data, uint8_t etype, uint8_t comp, int uncompressed_size, 519eda14cbcSMatt Macy int compressed_size, int byteorder, dmu_tx_t *tx); 520eda14cbcSMatt Macy void dmu_redact(objset_t *os, uint64_t object, uint64_t offset, uint64_t size, 521eda14cbcSMatt Macy dmu_tx_t *tx); 522eda14cbcSMatt Macy 523eda14cbcSMatt Macy /* 524eda14cbcSMatt Macy * Decide how to write a block: checksum, compression, number of copies, etc. 525eda14cbcSMatt Macy */ 526eda14cbcSMatt Macy #define WP_NOFILL 0x1 527eda14cbcSMatt Macy #define WP_DMU_SYNC 0x2 528eda14cbcSMatt Macy #define WP_SPILL 0x4 5297a7741afSMartin Matuska #define WP_DIRECT_WR 0x8 530eda14cbcSMatt Macy 531eda14cbcSMatt Macy void dmu_write_policy(objset_t *os, dnode_t *dn, int level, int wp, 532eda14cbcSMatt Macy struct zio_prop *zp); 533eda14cbcSMatt Macy 534eda14cbcSMatt Macy /* 535eda14cbcSMatt Macy * The bonus data is accessed more or less like a regular buffer. 536eda14cbcSMatt Macy * You must dmu_bonus_hold() to get the buffer, which will give you a 537eda14cbcSMatt Macy * dmu_buf_t with db_offset==-1ULL, and db_size = the size of the bonus 538eda14cbcSMatt Macy * data. As with any normal buffer, you must call dmu_buf_will_dirty() 539eda14cbcSMatt Macy * before modifying it, and the 540eda14cbcSMatt Macy * object must be held in an assigned transaction before calling 541eda14cbcSMatt Macy * dmu_buf_will_dirty. You may use dmu_buf_set_user() on the bonus 542eda14cbcSMatt Macy * buffer as well. You must release what you hold with dmu_buf_rele(). 543eda14cbcSMatt Macy * 544eda14cbcSMatt Macy * Returns ENOENT, EIO, or 0. 545eda14cbcSMatt Macy */ 546a0b956f5SMartin Matuska int dmu_bonus_hold(objset_t *os, uint64_t object, const void *tag, 547a0b956f5SMartin Matuska dmu_buf_t **dbp); 548a0b956f5SMartin Matuska int dmu_bonus_hold_by_dnode(dnode_t *dn, const void *tag, dmu_buf_t **dbp, 549eda14cbcSMatt Macy uint32_t flags); 550eda14cbcSMatt Macy int dmu_bonus_max(void); 551eda14cbcSMatt Macy int dmu_set_bonus(dmu_buf_t *, int, dmu_tx_t *); 552eda14cbcSMatt Macy int dmu_set_bonustype(dmu_buf_t *, dmu_object_type_t, dmu_tx_t *); 553eda14cbcSMatt Macy dmu_object_type_t dmu_get_bonustype(dmu_buf_t *); 554eda14cbcSMatt Macy int dmu_rm_spill(objset_t *, uint64_t, dmu_tx_t *); 555eda14cbcSMatt Macy 556eda14cbcSMatt Macy /* 557eda14cbcSMatt Macy * Special spill buffer support used by "SA" framework 558eda14cbcSMatt Macy */ 559eda14cbcSMatt Macy 560a0b956f5SMartin Matuska int dmu_spill_hold_by_bonus(dmu_buf_t *bonus, uint32_t flags, const void *tag, 561eda14cbcSMatt Macy dmu_buf_t **dbp); 562eda14cbcSMatt Macy int dmu_spill_hold_by_dnode(dnode_t *dn, uint32_t flags, 563a0b956f5SMartin Matuska const void *tag, dmu_buf_t **dbp); 564a0b956f5SMartin Matuska int dmu_spill_hold_existing(dmu_buf_t *bonus, const void *tag, dmu_buf_t **dbp); 565eda14cbcSMatt Macy 566eda14cbcSMatt Macy /* 567eda14cbcSMatt Macy * Obtain the DMU buffer from the specified object which contains the 568eda14cbcSMatt Macy * specified offset. dmu_buf_hold() puts a "hold" on the buffer, so 569eda14cbcSMatt Macy * that it will remain in memory. You must release the hold with 570eda14cbcSMatt Macy * dmu_buf_rele(). You must not access the dmu_buf_t after releasing 571eda14cbcSMatt Macy * what you hold. You must have a hold on any dmu_buf_t* you pass to the DMU. 572eda14cbcSMatt Macy * 573eda14cbcSMatt Macy * You must call dmu_buf_read, dmu_buf_will_dirty, or dmu_buf_will_fill 574eda14cbcSMatt Macy * on the returned buffer before reading or writing the buffer's 575eda14cbcSMatt Macy * db_data. The comments for those routines describe what particular 576eda14cbcSMatt Macy * operations are valid after calling them. 577eda14cbcSMatt Macy * 578eda14cbcSMatt Macy * The object number must be a valid, allocated object number. 579eda14cbcSMatt Macy */ 580eda14cbcSMatt Macy int dmu_buf_hold(objset_t *os, uint64_t object, uint64_t offset, 581a0b956f5SMartin Matuska const void *tag, dmu_buf_t **, int flags); 5826ba2210eSMartin Matuska int dmu_buf_hold_array(objset_t *os, uint64_t object, uint64_t offset, 583a0b956f5SMartin Matuska uint64_t length, int read, const void *tag, int *numbufsp, 584a0b956f5SMartin Matuska dmu_buf_t ***dbpp); 585315ee00fSMartin Matuska int dmu_buf_hold_noread(objset_t *os, uint64_t object, uint64_t offset, 586315ee00fSMartin Matuska const void *tag, dmu_buf_t **dbp); 587eda14cbcSMatt Macy int dmu_buf_hold_by_dnode(dnode_t *dn, uint64_t offset, 588a0b956f5SMartin Matuska const void *tag, dmu_buf_t **dbp, int flags); 589eda14cbcSMatt Macy int dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, 590a0b956f5SMartin Matuska uint64_t length, boolean_t read, const void *tag, int *numbufsp, 591eda14cbcSMatt Macy dmu_buf_t ***dbpp, uint32_t flags); 592315ee00fSMartin Matuska int dmu_buf_hold_noread_by_dnode(dnode_t *dn, uint64_t offset, const void *tag, 593315ee00fSMartin Matuska dmu_buf_t **dbp); 5947a7741afSMartin Matuska 595eda14cbcSMatt Macy /* 596eda14cbcSMatt Macy * Add a reference to a dmu buffer that has already been held via 597eda14cbcSMatt Macy * dmu_buf_hold() in the current context. 598eda14cbcSMatt Macy */ 599a0b956f5SMartin Matuska void dmu_buf_add_ref(dmu_buf_t *db, const void *tag); 600eda14cbcSMatt Macy 601eda14cbcSMatt Macy /* 602eda14cbcSMatt Macy * Attempt to add a reference to a dmu buffer that is in an unknown state, 603eda14cbcSMatt Macy * using a pointer that may have been invalidated by eviction processing. 604eda14cbcSMatt Macy * The request will succeed if the passed in dbuf still represents the 605eda14cbcSMatt Macy * same os/object/blkid, is ineligible for eviction, and has at least 606eda14cbcSMatt Macy * one hold by a user other than the syncer. 607eda14cbcSMatt Macy */ 608eda14cbcSMatt Macy boolean_t dmu_buf_try_add_ref(dmu_buf_t *, objset_t *os, uint64_t object, 609a0b956f5SMartin Matuska uint64_t blkid, const void *tag); 610eda14cbcSMatt Macy 611a0b956f5SMartin Matuska void dmu_buf_rele(dmu_buf_t *db, const void *tag); 612eda14cbcSMatt Macy uint64_t dmu_buf_refcount(dmu_buf_t *db); 613eda14cbcSMatt Macy uint64_t dmu_buf_user_refcount(dmu_buf_t *db); 614eda14cbcSMatt Macy 615eda14cbcSMatt Macy /* 616eda14cbcSMatt Macy * dmu_buf_hold_array holds the DMU buffers which contain all bytes in a 617eda14cbcSMatt Macy * range of an object. A pointer to an array of dmu_buf_t*'s is 618eda14cbcSMatt Macy * returned (in *dbpp). 619eda14cbcSMatt Macy * 620eda14cbcSMatt Macy * dmu_buf_rele_array releases the hold on an array of dmu_buf_t*'s, and 621eda14cbcSMatt Macy * frees the array. The hold on the array of buffers MUST be released 622eda14cbcSMatt Macy * with dmu_buf_rele_array. You can NOT release the hold on each buffer 623eda14cbcSMatt Macy * individually with dmu_buf_rele. 624eda14cbcSMatt Macy */ 625eda14cbcSMatt Macy int dmu_buf_hold_array_by_bonus(dmu_buf_t *db, uint64_t offset, 626a0b956f5SMartin Matuska uint64_t length, boolean_t read, const void *tag, 627eda14cbcSMatt Macy int *numbufsp, dmu_buf_t ***dbpp); 628a0b956f5SMartin Matuska void dmu_buf_rele_array(dmu_buf_t **, int numbufs, const void *tag); 629eda14cbcSMatt Macy 630eda14cbcSMatt Macy typedef void dmu_buf_evict_func_t(void *user_ptr); 631eda14cbcSMatt Macy 632eda14cbcSMatt Macy /* 633eda14cbcSMatt Macy * A DMU buffer user object may be associated with a dbuf for the 634eda14cbcSMatt Macy * duration of its lifetime. This allows the user of a dbuf (client) 635eda14cbcSMatt Macy * to attach private data to a dbuf (e.g. in-core only data such as a 636eda14cbcSMatt Macy * dnode_children_t, zap_t, or zap_leaf_t) and be optionally notified 637eda14cbcSMatt Macy * when that dbuf has been evicted. Clients typically respond to the 638eda14cbcSMatt Macy * eviction notification by freeing their private data, thus ensuring 639eda14cbcSMatt Macy * the same lifetime for both dbuf and private data. 640eda14cbcSMatt Macy * 641eda14cbcSMatt Macy * The mapping from a dmu_buf_user_t to any client private data is the 642eda14cbcSMatt Macy * client's responsibility. All current consumers of the API with private 643eda14cbcSMatt Macy * data embed a dmu_buf_user_t as the first member of the structure for 644eda14cbcSMatt Macy * their private data. This allows conversions between the two types 645eda14cbcSMatt Macy * with a simple cast. Since the DMU buf user API never needs access 646eda14cbcSMatt Macy * to the private data, other strategies can be employed if necessary 647eda14cbcSMatt Macy * or convenient for the client (e.g. using container_of() to do the 648eda14cbcSMatt Macy * conversion for private data that cannot have the dmu_buf_user_t as 649eda14cbcSMatt Macy * its first member). 650eda14cbcSMatt Macy * 651eda14cbcSMatt Macy * Eviction callbacks are executed without the dbuf mutex held or any 652eda14cbcSMatt Macy * other type of mechanism to guarantee that the dbuf is still available. 653eda14cbcSMatt Macy * For this reason, users must assume the dbuf has already been freed 654eda14cbcSMatt Macy * and not reference the dbuf from the callback context. 655eda14cbcSMatt Macy * 656eda14cbcSMatt Macy * Users requesting "immediate eviction" are notified as soon as the dbuf 657eda14cbcSMatt Macy * is only referenced by dirty records (dirties == holds). Otherwise the 658eda14cbcSMatt Macy * notification occurs after eviction processing for the dbuf begins. 659eda14cbcSMatt Macy */ 660eda14cbcSMatt Macy typedef struct dmu_buf_user { 661eda14cbcSMatt Macy /* 662eda14cbcSMatt Macy * Asynchronous user eviction callback state. 663eda14cbcSMatt Macy */ 664eda14cbcSMatt Macy taskq_ent_t dbu_tqent; 665eda14cbcSMatt Macy 666a2b560ccSMartin Matuska /* Size of user data, for inclusion in dbuf_cache accounting. */ 667a2b560ccSMartin Matuska uint64_t dbu_size; 668a2b560ccSMartin Matuska 669eda14cbcSMatt Macy /* 670eda14cbcSMatt Macy * This instance's eviction function pointers. 671eda14cbcSMatt Macy * 672eda14cbcSMatt Macy * dbu_evict_func_sync is called synchronously and then 673eda14cbcSMatt Macy * dbu_evict_func_async is executed asynchronously on a taskq. 674eda14cbcSMatt Macy */ 675eda14cbcSMatt Macy dmu_buf_evict_func_t *dbu_evict_func_sync; 676eda14cbcSMatt Macy dmu_buf_evict_func_t *dbu_evict_func_async; 677eda14cbcSMatt Macy #ifdef ZFS_DEBUG 678eda14cbcSMatt Macy /* 679eda14cbcSMatt Macy * Pointer to user's dbuf pointer. NULL for clients that do 680eda14cbcSMatt Macy * not associate a dbuf with their user data. 681eda14cbcSMatt Macy * 682eda14cbcSMatt Macy * The dbuf pointer is cleared upon eviction so as to catch 683eda14cbcSMatt Macy * use-after-evict bugs in clients. 684eda14cbcSMatt Macy */ 685eda14cbcSMatt Macy dmu_buf_t **dbu_clear_on_evict_dbufp; 686eda14cbcSMatt Macy #endif 687eda14cbcSMatt Macy } dmu_buf_user_t; 688eda14cbcSMatt Macy 689eda14cbcSMatt Macy /* 690eda14cbcSMatt Macy * Initialize the given dmu_buf_user_t instance with the eviction function 691eda14cbcSMatt Macy * evict_func, to be called when the user is evicted. 692eda14cbcSMatt Macy * 693eda14cbcSMatt Macy * NOTE: This function should only be called once on a given dmu_buf_user_t. 694eda14cbcSMatt Macy * To allow enforcement of this, dbu must already be zeroed on entry. 695eda14cbcSMatt Macy */ 696eda14cbcSMatt Macy static inline void 697eda14cbcSMatt Macy dmu_buf_init_user(dmu_buf_user_t *dbu, dmu_buf_evict_func_t *evict_func_sync, 698eda14cbcSMatt Macy dmu_buf_evict_func_t *evict_func_async, 699eda14cbcSMatt Macy dmu_buf_t **clear_on_evict_dbufp __maybe_unused) 700eda14cbcSMatt Macy { 701eda14cbcSMatt Macy ASSERT(dbu->dbu_evict_func_sync == NULL); 702eda14cbcSMatt Macy ASSERT(dbu->dbu_evict_func_async == NULL); 703eda14cbcSMatt Macy 704eda14cbcSMatt Macy /* must have at least one evict func */ 705eda14cbcSMatt Macy IMPLY(evict_func_sync == NULL, evict_func_async != NULL); 706eda14cbcSMatt Macy dbu->dbu_evict_func_sync = evict_func_sync; 707eda14cbcSMatt Macy dbu->dbu_evict_func_async = evict_func_async; 708eda14cbcSMatt Macy taskq_init_ent(&dbu->dbu_tqent); 709eda14cbcSMatt Macy #ifdef ZFS_DEBUG 710eda14cbcSMatt Macy dbu->dbu_clear_on_evict_dbufp = clear_on_evict_dbufp; 711eda14cbcSMatt Macy #endif 712eda14cbcSMatt Macy } 713eda14cbcSMatt Macy 714eda14cbcSMatt Macy /* 715eda14cbcSMatt Macy * Attach user data to a dbuf and mark it for normal (when the dbuf's 716eda14cbcSMatt Macy * data is cleared or its reference count goes to zero) eviction processing. 717eda14cbcSMatt Macy * 718eda14cbcSMatt Macy * Returns NULL on success, or the existing user if another user currently 719eda14cbcSMatt Macy * owns the buffer. 720eda14cbcSMatt Macy */ 721eda14cbcSMatt Macy void *dmu_buf_set_user(dmu_buf_t *db, dmu_buf_user_t *user); 722eda14cbcSMatt Macy 723eda14cbcSMatt Macy /* 724eda14cbcSMatt Macy * Attach user data to a dbuf and mark it for immediate (its dirty and 725eda14cbcSMatt Macy * reference counts are equal) eviction processing. 726eda14cbcSMatt Macy * 727eda14cbcSMatt Macy * Returns NULL on success, or the existing user if another user currently 728eda14cbcSMatt Macy * owns the buffer. 729eda14cbcSMatt Macy */ 730eda14cbcSMatt Macy void *dmu_buf_set_user_ie(dmu_buf_t *db, dmu_buf_user_t *user); 731eda14cbcSMatt Macy 732eda14cbcSMatt Macy /* 733eda14cbcSMatt Macy * Replace the current user of a dbuf. 734eda14cbcSMatt Macy * 735eda14cbcSMatt Macy * If given the current user of a dbuf, replaces the dbuf's user with 736eda14cbcSMatt Macy * "new_user" and returns the user data pointer that was replaced. 737eda14cbcSMatt Macy * Otherwise returns the current, and unmodified, dbuf user pointer. 738eda14cbcSMatt Macy */ 739eda14cbcSMatt Macy void *dmu_buf_replace_user(dmu_buf_t *db, 740eda14cbcSMatt Macy dmu_buf_user_t *old_user, dmu_buf_user_t *new_user); 741eda14cbcSMatt Macy 742eda14cbcSMatt Macy /* 743eda14cbcSMatt Macy * Remove the specified user data for a DMU buffer. 744eda14cbcSMatt Macy * 745eda14cbcSMatt Macy * Returns the user that was removed on success, or the current user if 746eda14cbcSMatt Macy * another user currently owns the buffer. 747eda14cbcSMatt Macy */ 748eda14cbcSMatt Macy void *dmu_buf_remove_user(dmu_buf_t *db, dmu_buf_user_t *user); 749eda14cbcSMatt Macy 750eda14cbcSMatt Macy /* 751a2b560ccSMartin Matuska * User data size accounting. This can be used to artifically inflate the size 752a2b560ccSMartin Matuska * of the dbuf during cache accounting, so that dbuf_evict_thread evicts enough 753a2b560ccSMartin Matuska * to satisfy memory reclaim requests. It's not used for anything else, and 754a2b560ccSMartin Matuska * defaults to 0. 755a2b560ccSMartin Matuska */ 756a2b560ccSMartin Matuska uint64_t dmu_buf_user_size(dmu_buf_t *db); 757a2b560ccSMartin Matuska void dmu_buf_add_user_size(dmu_buf_t *db, uint64_t nadd); 758a2b560ccSMartin Matuska void dmu_buf_sub_user_size(dmu_buf_t *db, uint64_t nsub); 759a2b560ccSMartin Matuska 760a2b560ccSMartin Matuska /* 761eda14cbcSMatt Macy * Returns the user data (dmu_buf_user_t *) associated with this dbuf. 762eda14cbcSMatt Macy */ 763eda14cbcSMatt Macy void *dmu_buf_get_user(dmu_buf_t *db); 764eda14cbcSMatt Macy 765eda14cbcSMatt Macy objset_t *dmu_buf_get_objset(dmu_buf_t *db); 766eda14cbcSMatt Macy 767eda14cbcSMatt Macy /* Block until any in-progress dmu buf user evictions complete. */ 768eda14cbcSMatt Macy void dmu_buf_user_evict_wait(void); 769eda14cbcSMatt Macy 770eda14cbcSMatt Macy /* 771eda14cbcSMatt Macy * Returns the blkptr associated with this dbuf, or NULL if not set. 772eda14cbcSMatt Macy */ 773eda14cbcSMatt Macy struct blkptr *dmu_buf_get_blkptr(dmu_buf_t *db); 774eda14cbcSMatt Macy 775eda14cbcSMatt Macy /* 776eda14cbcSMatt Macy * Indicate that you are going to modify the buffer's data (db_data). 777eda14cbcSMatt Macy * 778eda14cbcSMatt Macy * The transaction (tx) must be assigned to a txg (ie. you've called 779eda14cbcSMatt Macy * dmu_tx_assign()). The buffer's object must be held in the tx 780eda14cbcSMatt Macy * (ie. you've called dmu_tx_hold_object(tx, db->db_object)). 781eda14cbcSMatt Macy */ 782eda14cbcSMatt Macy void dmu_buf_will_dirty(dmu_buf_t *db, dmu_tx_t *tx); 783eda14cbcSMatt Macy boolean_t dmu_buf_is_dirty(dmu_buf_t *db, dmu_tx_t *tx); 784eda14cbcSMatt Macy void dmu_buf_set_crypt_params(dmu_buf_t *db_fake, boolean_t byteorder, 785eda14cbcSMatt Macy const uint8_t *salt, const uint8_t *iv, const uint8_t *mac, dmu_tx_t *tx); 786eda14cbcSMatt Macy 787eda14cbcSMatt Macy /* 788eda14cbcSMatt Macy * You must create a transaction, then hold the objects which you will 789eda14cbcSMatt Macy * (or might) modify as part of this transaction. Then you must assign 790eda14cbcSMatt Macy * the transaction to a transaction group. Once the transaction has 791eda14cbcSMatt Macy * been assigned, you can modify buffers which belong to held objects as 792eda14cbcSMatt Macy * part of this transaction. You can't modify buffers before the 793eda14cbcSMatt Macy * transaction has been assigned; you can't modify buffers which don't 794eda14cbcSMatt Macy * belong to objects which this transaction holds; you can't hold 795eda14cbcSMatt Macy * objects once the transaction has been assigned. You may hold an 796eda14cbcSMatt Macy * object which you are going to free (with dmu_object_free()), but you 797eda14cbcSMatt Macy * don't have to. 798eda14cbcSMatt Macy * 799eda14cbcSMatt Macy * You can abort the transaction before it has been assigned. 800eda14cbcSMatt Macy * 801eda14cbcSMatt Macy * Note that you may hold buffers (with dmu_buf_hold) at any time, 802eda14cbcSMatt Macy * regardless of transaction state. 803eda14cbcSMatt Macy */ 804eda14cbcSMatt Macy 805eda14cbcSMatt Macy #define DMU_NEW_OBJECT (-1ULL) 806eda14cbcSMatt Macy #define DMU_OBJECT_END (-1ULL) 807eda14cbcSMatt Macy 808eda14cbcSMatt Macy dmu_tx_t *dmu_tx_create(objset_t *os); 809eda14cbcSMatt Macy void dmu_tx_hold_write(dmu_tx_t *tx, uint64_t object, uint64_t off, int len); 810eda14cbcSMatt Macy void dmu_tx_hold_write_by_dnode(dmu_tx_t *tx, dnode_t *dn, uint64_t off, 811eda14cbcSMatt Macy int len); 812e639e0d2SMartin Matuska void dmu_tx_hold_append(dmu_tx_t *tx, uint64_t object, uint64_t off, int len); 813e639e0d2SMartin Matuska void dmu_tx_hold_append_by_dnode(dmu_tx_t *tx, dnode_t *dn, uint64_t off, 814e639e0d2SMartin Matuska int len); 8152a58b312SMartin Matuska void dmu_tx_hold_clone_by_dnode(dmu_tx_t *tx, dnode_t *dn, uint64_t off, 8162a58b312SMartin Matuska int len); 817eda14cbcSMatt Macy void dmu_tx_hold_free(dmu_tx_t *tx, uint64_t object, uint64_t off, 818eda14cbcSMatt Macy uint64_t len); 819eda14cbcSMatt Macy void dmu_tx_hold_free_by_dnode(dmu_tx_t *tx, dnode_t *dn, uint64_t off, 820eda14cbcSMatt Macy uint64_t len); 821eda14cbcSMatt Macy void dmu_tx_hold_zap(dmu_tx_t *tx, uint64_t object, int add, const char *name); 822eda14cbcSMatt Macy void dmu_tx_hold_zap_by_dnode(dmu_tx_t *tx, dnode_t *dn, int add, 823eda14cbcSMatt Macy const char *name); 824eda14cbcSMatt Macy void dmu_tx_hold_bonus(dmu_tx_t *tx, uint64_t object); 825eda14cbcSMatt Macy void dmu_tx_hold_bonus_by_dnode(dmu_tx_t *tx, dnode_t *dn); 826eda14cbcSMatt Macy void dmu_tx_hold_spill(dmu_tx_t *tx, uint64_t object); 827eda14cbcSMatt Macy void dmu_tx_hold_sa(dmu_tx_t *tx, struct sa_handle *hdl, boolean_t may_grow); 828eda14cbcSMatt Macy void dmu_tx_hold_sa_create(dmu_tx_t *tx, int total_size); 829eda14cbcSMatt Macy void dmu_tx_abort(dmu_tx_t *tx); 830eda14cbcSMatt Macy int dmu_tx_assign(dmu_tx_t *tx, uint64_t txg_how); 831eda14cbcSMatt Macy void dmu_tx_wait(dmu_tx_t *tx); 832eda14cbcSMatt Macy void dmu_tx_commit(dmu_tx_t *tx); 833eda14cbcSMatt Macy void dmu_tx_mark_netfree(dmu_tx_t *tx); 834eda14cbcSMatt Macy 835eda14cbcSMatt Macy /* 836eda14cbcSMatt Macy * To register a commit callback, dmu_tx_callback_register() must be called. 837eda14cbcSMatt Macy * 838eda14cbcSMatt Macy * dcb_data is a pointer to caller private data that is passed on as a 839eda14cbcSMatt Macy * callback parameter. The caller is responsible for properly allocating and 840eda14cbcSMatt Macy * freeing it. 841eda14cbcSMatt Macy * 842eda14cbcSMatt Macy * When registering a callback, the transaction must be already created, but 843eda14cbcSMatt Macy * it cannot be committed or aborted. It can be assigned to a txg or not. 844eda14cbcSMatt Macy * 845eda14cbcSMatt Macy * The callback will be called after the transaction has been safely written 846eda14cbcSMatt Macy * to stable storage and will also be called if the dmu_tx is aborted. 847eda14cbcSMatt Macy * If there is any error which prevents the transaction from being committed to 848eda14cbcSMatt Macy * disk, the callback will be called with a value of error != 0. 849eda14cbcSMatt Macy * 850eda14cbcSMatt Macy * When multiple callbacks are registered to the transaction, the callbacks 851eda14cbcSMatt Macy * will be called in reverse order to let Lustre, the only user of commit 852eda14cbcSMatt Macy * callback currently, take the fast path of its commit callback handling. 853eda14cbcSMatt Macy */ 854eda14cbcSMatt Macy typedef void dmu_tx_callback_func_t(void *dcb_data, int error); 855eda14cbcSMatt Macy 856eda14cbcSMatt Macy void dmu_tx_callback_register(dmu_tx_t *tx, dmu_tx_callback_func_t *dcb_func, 857eda14cbcSMatt Macy void *dcb_data); 858eda14cbcSMatt Macy void dmu_tx_do_callbacks(list_t *cb_list, int error); 859eda14cbcSMatt Macy 860eda14cbcSMatt Macy /* 861eda14cbcSMatt Macy * Free up the data blocks for a defined range of a file. If size is 862eda14cbcSMatt Macy * -1, the range from offset to end-of-file is freed. 863eda14cbcSMatt Macy */ 864eda14cbcSMatt Macy int dmu_free_range(objset_t *os, uint64_t object, uint64_t offset, 865eda14cbcSMatt Macy uint64_t size, dmu_tx_t *tx); 866eda14cbcSMatt Macy int dmu_free_long_range(objset_t *os, uint64_t object, uint64_t offset, 867eda14cbcSMatt Macy uint64_t size); 868eda14cbcSMatt Macy int dmu_free_long_object(objset_t *os, uint64_t object); 869eda14cbcSMatt Macy 870eda14cbcSMatt Macy /* 871eda14cbcSMatt Macy * Convenience functions. 872eda14cbcSMatt Macy * 873eda14cbcSMatt Macy * Canfail routines will return 0 on success, or an errno if there is a 874eda14cbcSMatt Macy * nonrecoverable I/O error. 875eda14cbcSMatt Macy */ 876eda14cbcSMatt Macy #define DMU_READ_PREFETCH 0 /* prefetch */ 877eda14cbcSMatt Macy #define DMU_READ_NO_PREFETCH 1 /* don't prefetch */ 878eda14cbcSMatt Macy #define DMU_READ_NO_DECRYPT 2 /* don't decrypt */ 8797a7741afSMartin Matuska #define DMU_DIRECTIO 4 /* use Direct I/O */ 8807a7741afSMartin Matuska 881eda14cbcSMatt Macy int dmu_read(objset_t *os, uint64_t object, uint64_t offset, uint64_t size, 882eda14cbcSMatt Macy void *buf, uint32_t flags); 883eda14cbcSMatt Macy int dmu_read_by_dnode(dnode_t *dn, uint64_t offset, uint64_t size, void *buf, 884eda14cbcSMatt Macy uint32_t flags); 885eda14cbcSMatt Macy void dmu_write(objset_t *os, uint64_t object, uint64_t offset, uint64_t size, 886eda14cbcSMatt Macy const void *buf, dmu_tx_t *tx); 8877a7741afSMartin Matuska int dmu_write_by_dnode(dnode_t *dn, uint64_t offset, uint64_t size, 888eda14cbcSMatt Macy const void *buf, dmu_tx_t *tx); 8897a7741afSMartin Matuska int dmu_write_by_dnode_flags(dnode_t *dn, uint64_t offset, uint64_t size, 8907a7741afSMartin Matuska const void *buf, dmu_tx_t *tx, uint32_t flags); 891eda14cbcSMatt Macy void dmu_prealloc(objset_t *os, uint64_t object, uint64_t offset, uint64_t size, 892eda14cbcSMatt Macy dmu_tx_t *tx); 893eda14cbcSMatt Macy #ifdef _KERNEL 894184c1b94SMartin Matuska int dmu_read_uio(objset_t *os, uint64_t object, zfs_uio_t *uio, uint64_t size); 895184c1b94SMartin Matuska int dmu_read_uio_dbuf(dmu_buf_t *zdb, zfs_uio_t *uio, uint64_t size); 896184c1b94SMartin Matuska int dmu_read_uio_dnode(dnode_t *dn, zfs_uio_t *uio, uint64_t size); 897184c1b94SMartin Matuska int dmu_write_uio(objset_t *os, uint64_t object, zfs_uio_t *uio, uint64_t size, 898eda14cbcSMatt Macy dmu_tx_t *tx); 899184c1b94SMartin Matuska int dmu_write_uio_dbuf(dmu_buf_t *zdb, zfs_uio_t *uio, uint64_t size, 900eda14cbcSMatt Macy dmu_tx_t *tx); 901184c1b94SMartin Matuska int dmu_write_uio_dnode(dnode_t *dn, zfs_uio_t *uio, uint64_t size, 902eda14cbcSMatt Macy dmu_tx_t *tx); 903eda14cbcSMatt Macy #endif 904eda14cbcSMatt Macy struct arc_buf *dmu_request_arcbuf(dmu_buf_t *handle, int size); 905eda14cbcSMatt Macy void dmu_return_arcbuf(struct arc_buf *buf); 906eda14cbcSMatt Macy int dmu_assign_arcbuf_by_dnode(dnode_t *dn, uint64_t offset, 907eda14cbcSMatt Macy struct arc_buf *buf, dmu_tx_t *tx); 908eda14cbcSMatt Macy int dmu_assign_arcbuf_by_dbuf(dmu_buf_t *handle, uint64_t offset, 909eda14cbcSMatt Macy struct arc_buf *buf, dmu_tx_t *tx); 910eda14cbcSMatt Macy #define dmu_assign_arcbuf dmu_assign_arcbuf_by_dbuf 911be181ee2SMartin Matuska extern uint_t zfs_max_recordsize; 912eda14cbcSMatt Macy 913eda14cbcSMatt Macy /* 914eda14cbcSMatt Macy * Asynchronously try to read in the data. 915eda14cbcSMatt Macy */ 916eda14cbcSMatt Macy void dmu_prefetch(objset_t *os, uint64_t object, int64_t level, uint64_t offset, 917eda14cbcSMatt Macy uint64_t len, enum zio_priority pri); 918783d3ff6SMartin Matuska void dmu_prefetch_by_dnode(dnode_t *dn, int64_t level, uint64_t offset, 919783d3ff6SMartin Matuska uint64_t len, enum zio_priority pri); 920315ee00fSMartin Matuska void dmu_prefetch_dnode(objset_t *os, uint64_t object, enum zio_priority pri); 921ce4dcb97SMartin Matuska int dmu_prefetch_wait(objset_t *os, uint64_t object, uint64_t offset, 922ce4dcb97SMartin Matuska uint64_t size); 923eda14cbcSMatt Macy 924eda14cbcSMatt Macy typedef struct dmu_object_info { 925eda14cbcSMatt Macy /* All sizes are in bytes unless otherwise indicated. */ 926eda14cbcSMatt Macy uint32_t doi_data_block_size; 927eda14cbcSMatt Macy uint32_t doi_metadata_block_size; 928eda14cbcSMatt Macy dmu_object_type_t doi_type; 929eda14cbcSMatt Macy dmu_object_type_t doi_bonus_type; 930eda14cbcSMatt Macy uint64_t doi_bonus_size; 931eda14cbcSMatt Macy uint8_t doi_indirection; /* 2 = dnode->indirect->data */ 932eda14cbcSMatt Macy uint8_t doi_checksum; 933eda14cbcSMatt Macy uint8_t doi_compress; 934eda14cbcSMatt Macy uint8_t doi_nblkptr; 935eda14cbcSMatt Macy uint8_t doi_pad[4]; 936eda14cbcSMatt Macy uint64_t doi_dnodesize; 937eda14cbcSMatt Macy uint64_t doi_physical_blocks_512; /* data + metadata, 512b blks */ 938eda14cbcSMatt Macy uint64_t doi_max_offset; 939eda14cbcSMatt Macy uint64_t doi_fill_count; /* number of non-empty blocks */ 940eda14cbcSMatt Macy } dmu_object_info_t; 941eda14cbcSMatt Macy 942eda14cbcSMatt Macy typedef void (*const arc_byteswap_func_t)(void *buf, size_t size); 943eda14cbcSMatt Macy 944eda14cbcSMatt Macy typedef struct dmu_object_type_info { 945eda14cbcSMatt Macy dmu_object_byteswap_t ot_byteswap; 946eda14cbcSMatt Macy boolean_t ot_metadata; 947eda14cbcSMatt Macy boolean_t ot_dbuf_metadata_cache; 948eda14cbcSMatt Macy boolean_t ot_encrypt; 949a0b956f5SMartin Matuska const char *ot_name; 950eda14cbcSMatt Macy } dmu_object_type_info_t; 951eda14cbcSMatt Macy 952eda14cbcSMatt Macy typedef const struct dmu_object_byteswap_info { 953eda14cbcSMatt Macy arc_byteswap_func_t ob_func; 954a0b956f5SMartin Matuska const char *ob_name; 955eda14cbcSMatt Macy } dmu_object_byteswap_info_t; 956eda14cbcSMatt Macy 957eda14cbcSMatt Macy extern const dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES]; 958be181ee2SMartin Matuska extern dmu_object_byteswap_info_t dmu_ot_byteswap[DMU_BSWAP_NUMFUNCS]; 959eda14cbcSMatt Macy 960eda14cbcSMatt Macy /* 961eda14cbcSMatt Macy * Get information on a DMU object. 962eda14cbcSMatt Macy * 963eda14cbcSMatt Macy * Return 0 on success or ENOENT if object is not allocated. 964eda14cbcSMatt Macy * 965eda14cbcSMatt Macy * If doi is NULL, just indicates whether the object exists. 966eda14cbcSMatt Macy */ 967eda14cbcSMatt Macy int dmu_object_info(objset_t *os, uint64_t object, dmu_object_info_t *doi); 968eda14cbcSMatt Macy void __dmu_object_info_from_dnode(struct dnode *dn, dmu_object_info_t *doi); 969eda14cbcSMatt Macy /* Like dmu_object_info, but faster if you have a held dnode in hand. */ 970eda14cbcSMatt Macy void dmu_object_info_from_dnode(dnode_t *dn, dmu_object_info_t *doi); 971eda14cbcSMatt Macy /* Like dmu_object_info, but faster if you have a held dbuf in hand. */ 972eda14cbcSMatt Macy void dmu_object_info_from_db(dmu_buf_t *db, dmu_object_info_t *doi); 973eda14cbcSMatt Macy /* 974eda14cbcSMatt Macy * Like dmu_object_info_from_db, but faster still when you only care about 975eda14cbcSMatt Macy * the size. 976eda14cbcSMatt Macy */ 977eda14cbcSMatt Macy void dmu_object_size_from_db(dmu_buf_t *db, uint32_t *blksize, 978eda14cbcSMatt Macy u_longlong_t *nblk512); 979eda14cbcSMatt Macy 980eda14cbcSMatt Macy void dmu_object_dnsize_from_db(dmu_buf_t *db, int *dnsize); 981eda14cbcSMatt Macy 982eda14cbcSMatt Macy typedef struct dmu_objset_stats { 983eda14cbcSMatt Macy uint64_t dds_num_clones; /* number of clones of this */ 984eda14cbcSMatt Macy uint64_t dds_creation_txg; 985eda14cbcSMatt Macy uint64_t dds_guid; 986eda14cbcSMatt Macy dmu_objset_type_t dds_type; 987eda14cbcSMatt Macy uint8_t dds_is_snapshot; 988eda14cbcSMatt Macy uint8_t dds_inconsistent; 989eda14cbcSMatt Macy uint8_t dds_redacted; 990eda14cbcSMatt Macy char dds_origin[ZFS_MAX_DATASET_NAME_LEN]; 991eda14cbcSMatt Macy } dmu_objset_stats_t; 992eda14cbcSMatt Macy 993eda14cbcSMatt Macy /* 994eda14cbcSMatt Macy * Get stats on a dataset. 995eda14cbcSMatt Macy */ 996eda14cbcSMatt Macy void dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat); 997eda14cbcSMatt Macy 998eda14cbcSMatt Macy /* 999eda14cbcSMatt Macy * Add entries to the nvlist for all the objset's properties. See 1000eda14cbcSMatt Macy * zfs_prop_table[] and zfs(1m) for details on the properties. 1001eda14cbcSMatt Macy */ 1002eda14cbcSMatt Macy void dmu_objset_stats(objset_t *os, struct nvlist *nv); 1003eda14cbcSMatt Macy 1004eda14cbcSMatt Macy /* 1005eda14cbcSMatt Macy * Get the space usage statistics for statvfs(). 1006eda14cbcSMatt Macy * 1007eda14cbcSMatt Macy * refdbytes is the amount of space "referenced" by this objset. 1008eda14cbcSMatt Macy * availbytes is the amount of space available to this objset, taking 1009eda14cbcSMatt Macy * into account quotas & reservations, assuming that no other objsets 1010eda14cbcSMatt Macy * use the space first. These values correspond to the 'referenced' and 1011eda14cbcSMatt Macy * 'available' properties, described in the zfs(1m) manpage. 1012eda14cbcSMatt Macy * 1013eda14cbcSMatt Macy * usedobjs and availobjs are the number of objects currently allocated, 1014eda14cbcSMatt Macy * and available. 1015eda14cbcSMatt Macy */ 1016eda14cbcSMatt Macy void dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp, 1017eda14cbcSMatt Macy uint64_t *usedobjsp, uint64_t *availobjsp); 1018eda14cbcSMatt Macy 1019eda14cbcSMatt Macy /* 1020eda14cbcSMatt Macy * The fsid_guid is a 56-bit ID that can change to avoid collisions. 1021eda14cbcSMatt Macy * (Contrast with the ds_guid which is a 64-bit ID that will never 1022eda14cbcSMatt Macy * change, so there is a small probability that it will collide.) 1023eda14cbcSMatt Macy */ 1024eda14cbcSMatt Macy uint64_t dmu_objset_fsid_guid(objset_t *os); 1025eda14cbcSMatt Macy 1026eda14cbcSMatt Macy /* 1027eda14cbcSMatt Macy * Get the [cm]time for an objset's snapshot dir 1028eda14cbcSMatt Macy */ 1029eda14cbcSMatt Macy inode_timespec_t dmu_objset_snap_cmtime(objset_t *os); 1030eda14cbcSMatt Macy 1031eda14cbcSMatt Macy int dmu_objset_is_snapshot(objset_t *os); 1032eda14cbcSMatt Macy 1033eda14cbcSMatt Macy extern struct spa *dmu_objset_spa(objset_t *os); 1034eda14cbcSMatt Macy extern struct zilog *dmu_objset_zil(objset_t *os); 1035eda14cbcSMatt Macy extern struct dsl_pool *dmu_objset_pool(objset_t *os); 1036eda14cbcSMatt Macy extern struct dsl_dataset *dmu_objset_ds(objset_t *os); 1037eda14cbcSMatt Macy extern void dmu_objset_name(objset_t *os, char *buf); 1038eda14cbcSMatt Macy extern dmu_objset_type_t dmu_objset_type(objset_t *os); 1039eda14cbcSMatt Macy extern uint64_t dmu_objset_id(objset_t *os); 1040eda14cbcSMatt Macy extern uint64_t dmu_objset_dnodesize(objset_t *os); 1041eda14cbcSMatt Macy extern zfs_sync_type_t dmu_objset_syncprop(objset_t *os); 1042eda14cbcSMatt Macy extern zfs_logbias_op_t dmu_objset_logbias(objset_t *os); 1043eda14cbcSMatt Macy extern int dmu_objset_blksize(objset_t *os); 1044eda14cbcSMatt Macy extern int dmu_snapshot_list_next(objset_t *os, int namelen, char *name, 1045eda14cbcSMatt Macy uint64_t *id, uint64_t *offp, boolean_t *case_conflict); 1046eda14cbcSMatt Macy extern int dmu_snapshot_lookup(objset_t *os, const char *name, uint64_t *val); 1047180f8225SMatt Macy extern int dmu_snapshot_realname(objset_t *os, const char *name, char *real, 1048eda14cbcSMatt Macy int maxlen, boolean_t *conflict); 1049eda14cbcSMatt Macy extern int dmu_dir_list_next(objset_t *os, int namelen, char *name, 1050eda14cbcSMatt Macy uint64_t *idp, uint64_t *offp); 1051eda14cbcSMatt Macy 1052eda14cbcSMatt Macy typedef struct zfs_file_info { 1053eda14cbcSMatt Macy uint64_t zfi_user; 1054eda14cbcSMatt Macy uint64_t zfi_group; 1055eda14cbcSMatt Macy uint64_t zfi_project; 1056eda14cbcSMatt Macy uint64_t zfi_generation; 1057eda14cbcSMatt Macy } zfs_file_info_t; 1058eda14cbcSMatt Macy 1059eda14cbcSMatt Macy typedef int file_info_cb_t(dmu_object_type_t bonustype, const void *data, 1060eda14cbcSMatt Macy struct zfs_file_info *zoi); 1061eda14cbcSMatt Macy extern void dmu_objset_register_type(dmu_objset_type_t ost, 1062eda14cbcSMatt Macy file_info_cb_t *cb); 1063eda14cbcSMatt Macy extern void dmu_objset_set_user(objset_t *os, void *user_ptr); 1064eda14cbcSMatt Macy extern void *dmu_objset_get_user(objset_t *os); 1065eda14cbcSMatt Macy 1066eda14cbcSMatt Macy /* 1067eda14cbcSMatt Macy * Return the txg number for the given assigned transaction. 1068eda14cbcSMatt Macy */ 1069eda14cbcSMatt Macy uint64_t dmu_tx_get_txg(dmu_tx_t *tx); 1070eda14cbcSMatt Macy 1071eda14cbcSMatt Macy /* 1072eda14cbcSMatt Macy * Synchronous write. 1073eda14cbcSMatt Macy * If a parent zio is provided this function initiates a write on the 1074eda14cbcSMatt Macy * provided buffer as a child of the parent zio. 1075eda14cbcSMatt Macy * In the absence of a parent zio, the write is completed synchronously. 1076eda14cbcSMatt Macy * At write completion, blk is filled with the bp of the written block. 1077eda14cbcSMatt Macy * Note that while the data covered by this function will be on stable 1078eda14cbcSMatt Macy * storage when the write completes this new data does not become a 1079eda14cbcSMatt Macy * permanent part of the file until the associated transaction commits. 1080eda14cbcSMatt Macy */ 1081eda14cbcSMatt Macy 1082eda14cbcSMatt Macy /* 1083eda14cbcSMatt Macy * {zfs,zvol,ztest}_get_done() args 1084eda14cbcSMatt Macy */ 1085eda14cbcSMatt Macy typedef struct zgd { 1086eda14cbcSMatt Macy struct lwb *zgd_lwb; 1087eda14cbcSMatt Macy struct blkptr *zgd_bp; 1088eda14cbcSMatt Macy dmu_buf_t *zgd_db; 1089eda14cbcSMatt Macy struct zfs_locked_range *zgd_lr; 1090eda14cbcSMatt Macy void *zgd_private; 1091eda14cbcSMatt Macy } zgd_t; 1092eda14cbcSMatt Macy 1093eda14cbcSMatt Macy typedef void dmu_sync_cb_t(zgd_t *arg, int error); 1094eda14cbcSMatt Macy int dmu_sync(struct zio *zio, uint64_t txg, dmu_sync_cb_t *done, zgd_t *zgd); 1095eda14cbcSMatt Macy 1096eda14cbcSMatt Macy /* 1097eda14cbcSMatt Macy * Find the next hole or data block in file starting at *off 1098eda14cbcSMatt Macy * Return found offset in *off. Return ESRCH for end of file. 1099eda14cbcSMatt Macy */ 1100eda14cbcSMatt Macy int dmu_offset_next(objset_t *os, uint64_t object, boolean_t hole, 1101eda14cbcSMatt Macy uint64_t *off); 1102eda14cbcSMatt Macy 11032a58b312SMartin Matuska int dmu_read_l0_bps(objset_t *os, uint64_t object, uint64_t offset, 1104e639e0d2SMartin Matuska uint64_t length, struct blkptr *bps, size_t *nbpsp); 1105e639e0d2SMartin Matuska int dmu_brt_clone(objset_t *os, uint64_t object, uint64_t offset, 1106525fe93dSMartin Matuska uint64_t length, dmu_tx_t *tx, const struct blkptr *bps, size_t nbps); 11072a58b312SMartin Matuska 1108eda14cbcSMatt Macy /* 1109eda14cbcSMatt Macy * Initial setup and final teardown. 1110eda14cbcSMatt Macy */ 1111eda14cbcSMatt Macy extern void dmu_init(void); 1112eda14cbcSMatt Macy extern void dmu_fini(void); 1113eda14cbcSMatt Macy 1114eda14cbcSMatt Macy typedef void (*dmu_traverse_cb_t)(objset_t *os, void *arg, struct blkptr *bp, 1115eda14cbcSMatt Macy uint64_t object, uint64_t offset, int len); 1116eda14cbcSMatt Macy void dmu_traverse_objset(objset_t *os, uint64_t txg_start, 1117eda14cbcSMatt Macy dmu_traverse_cb_t cb, void *arg); 1118eda14cbcSMatt Macy 1119eda14cbcSMatt Macy int dmu_diff(const char *tosnap_name, const char *fromsnap_name, 1120eda14cbcSMatt Macy zfs_file_t *fp, offset_t *offp); 1121eda14cbcSMatt Macy 1122eda14cbcSMatt Macy /* CRC64 table */ 1123eda14cbcSMatt Macy #define ZFS_CRC64_POLY 0xC96C5795D7870F42ULL /* ECMA-182, reflected form */ 1124eda14cbcSMatt Macy extern uint64_t zfs_crc64_table[256]; 1125eda14cbcSMatt Macy 1126be181ee2SMartin Matuska extern uint_t dmu_prefetch_max; 1127716fd348SMartin Matuska 1128eda14cbcSMatt Macy #ifdef __cplusplus 1129eda14cbcSMatt Macy } 1130eda14cbcSMatt Macy #endif 1131eda14cbcSMatt Macy 1132eda14cbcSMatt Macy #endif /* _SYS_DMU_H */ 1133