1789Sahrens /* 2789Sahrens * CDDL HEADER START 3789Sahrens * 4789Sahrens * The contents of this file are subject to the terms of the 51544Seschrock * Common Development and Distribution License (the "License"). 61544Seschrock * You may not use this file except in compliance with the License. 7789Sahrens * 8789Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9789Sahrens * or http://www.opensolaris.org/os/licensing. 10789Sahrens * See the License for the specific language governing permissions 11789Sahrens * and limitations under the License. 12789Sahrens * 13789Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14789Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15789Sahrens * If applicable, add the following below this CDDL HEADER, with the 16789Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17789Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18789Sahrens * 19789Sahrens * CDDL HEADER END 20789Sahrens */ 21789Sahrens /* 2212123STim.Haley@Sun.COM * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23789Sahrens */ 24789Sahrens 2512294SMark.Musante@Sun.COM /* Portions Copyright 2010 Robert Milkowski */ 2612294SMark.Musante@Sun.COM 27789Sahrens #ifndef _SYS_DMU_H 28789Sahrens #define _SYS_DMU_H 29789Sahrens 30789Sahrens /* 31789Sahrens * This file describes the interface that the DMU provides for its 32789Sahrens * consumers. 33789Sahrens * 34789Sahrens * The DMU also interacts with the SPA. That interface is described in 35789Sahrens * dmu_spa.h. 36789Sahrens */ 37789Sahrens 38789Sahrens #include <sys/inttypes.h> 39789Sahrens #include <sys/types.h> 40789Sahrens #include <sys/param.h> 414543Smarks #include <sys/cred.h> 4210373Schris.kirby@sun.com #include <sys/time.h> 43789Sahrens 44789Sahrens #ifdef __cplusplus 45789Sahrens extern "C" { 46789Sahrens #endif 47789Sahrens 48789Sahrens struct uio; 4911539SChunli.Zhang@Sun.COM struct xuio; 502688Smaybee struct page; 51789Sahrens struct vnode; 52789Sahrens struct spa; 53789Sahrens struct zilog; 54789Sahrens struct zio; 55789Sahrens struct blkptr; 56789Sahrens struct zap_cursor; 57789Sahrens struct dsl_dataset; 58789Sahrens struct dsl_pool; 59789Sahrens struct dnode; 60789Sahrens struct drr_begin; 61789Sahrens struct drr_end; 621775Sbillm struct zbookmark; 631775Sbillm struct spa; 642885Sahrens struct nvlist; 659412SAleksandr.Guzovskiy@Sun.COM struct arc_buf; 6610922SJeff.Bonwick@Sun.COM struct zio_prop; 6711935SMark.Shellenbaum@Sun.COM struct sa_handle; 68789Sahrens 69789Sahrens typedef struct objset objset_t; 70789Sahrens typedef struct dmu_tx dmu_tx_t; 71789Sahrens typedef struct dsl_dir dsl_dir_t; 72789Sahrens 73789Sahrens typedef enum dmu_object_type { 74789Sahrens DMU_OT_NONE, 75789Sahrens /* general: */ 76789Sahrens DMU_OT_OBJECT_DIRECTORY, /* ZAP */ 77789Sahrens DMU_OT_OBJECT_ARRAY, /* UINT64 */ 78789Sahrens DMU_OT_PACKED_NVLIST, /* UINT8 (XDR by nvlist_pack/unpack) */ 79789Sahrens DMU_OT_PACKED_NVLIST_SIZE, /* UINT64 */ 8012470SMatthew.Ahrens@Sun.COM DMU_OT_BPOBJ, /* UINT64 */ 8112470SMatthew.Ahrens@Sun.COM DMU_OT_BPOBJ_HDR, /* UINT64 */ 82789Sahrens /* spa: */ 83789Sahrens DMU_OT_SPACE_MAP_HEADER, /* UINT64 */ 84789Sahrens DMU_OT_SPACE_MAP, /* UINT64 */ 85789Sahrens /* zil: */ 86789Sahrens DMU_OT_INTENT_LOG, /* UINT64 */ 87789Sahrens /* dmu: */ 88789Sahrens DMU_OT_DNODE, /* DNODE */ 89789Sahrens DMU_OT_OBJSET, /* OBJSET */ 90789Sahrens /* dsl: */ 91928Stabriz DMU_OT_DSL_DIR, /* UINT64 */ 92885Sahrens DMU_OT_DSL_DIR_CHILD_MAP, /* ZAP */ 93885Sahrens DMU_OT_DSL_DS_SNAP_MAP, /* ZAP */ 94789Sahrens DMU_OT_DSL_PROPS, /* ZAP */ 95928Stabriz DMU_OT_DSL_DATASET, /* UINT64 */ 96789Sahrens /* zpl: */ 97789Sahrens DMU_OT_ZNODE, /* ZNODE */ 985331Samw DMU_OT_OLDACL, /* Old ACL */ 99789Sahrens DMU_OT_PLAIN_FILE_CONTENTS, /* UINT8 */ 100789Sahrens DMU_OT_DIRECTORY_CONTENTS, /* ZAP */ 101789Sahrens DMU_OT_MASTER_NODE, /* ZAP */ 1023461Sahrens DMU_OT_UNLINKED_SET, /* ZAP */ 103789Sahrens /* zvol: */ 104789Sahrens DMU_OT_ZVOL, /* UINT8 */ 105789Sahrens DMU_OT_ZVOL_PROP, /* ZAP */ 106789Sahrens /* other; for testing only! */ 107789Sahrens DMU_OT_PLAIN_OTHER, /* UINT8 */ 108789Sahrens DMU_OT_UINT64_OTHER, /* UINT64 */ 109789Sahrens DMU_OT_ZAP_OTHER, /* ZAP */ 1101544Seschrock /* new object types: */ 1111544Seschrock DMU_OT_ERROR_LOG, /* ZAP */ 1122926Sek110237 DMU_OT_SPA_HISTORY, /* UINT8 */ 1132926Sek110237 DMU_OT_SPA_HISTORY_OFFSETS, /* spa_his_phys_t */ 1143912Slling DMU_OT_POOL_PROPS, /* ZAP */ 1154543Smarks DMU_OT_DSL_PERMS, /* ZAP */ 1165331Samw DMU_OT_ACL, /* ACL */ 1175331Samw DMU_OT_SYSACL, /* SYSACL */ 1185331Samw DMU_OT_FUID, /* FUID table (Packed NVLIST UINT8) */ 1195331Samw DMU_OT_FUID_SIZE, /* FUID table size UINT64 */ 1207046Sahrens DMU_OT_NEXT_CLONES, /* ZAP */ 12112296SLin.Ling@Sun.COM DMU_OT_SCAN_QUEUE, /* ZAP */ 1229396SMatthew.Ahrens@Sun.COM DMU_OT_USERGROUP_USED, /* ZAP */ 1239396SMatthew.Ahrens@Sun.COM DMU_OT_USERGROUP_QUOTA, /* ZAP */ 12410242Schris.kirby@sun.com DMU_OT_USERREFS, /* ZAP */ 12510922SJeff.Bonwick@Sun.COM DMU_OT_DDT_ZAP, /* ZAP */ 12610922SJeff.Bonwick@Sun.COM DMU_OT_DDT_STATS, /* ZAP */ 12711935SMark.Shellenbaum@Sun.COM DMU_OT_SA, /* System attr */ 12811935SMark.Shellenbaum@Sun.COM DMU_OT_SA_MASTER_NODE, /* ZAP */ 12911935SMark.Shellenbaum@Sun.COM DMU_OT_SA_ATTR_REGISTRATION, /* ZAP */ 13011935SMark.Shellenbaum@Sun.COM DMU_OT_SA_ATTR_LAYOUTS, /* ZAP */ 13112296SLin.Ling@Sun.COM DMU_OT_SCAN_XLATE, /* ZAP */ 13212296SLin.Ling@Sun.COM DMU_OT_DEDUP, /* fake dedup BP from ddt_bp_create() */ 13312470SMatthew.Ahrens@Sun.COM DMU_OT_DEADLIST, /* ZAP */ 13412470SMatthew.Ahrens@Sun.COM DMU_OT_DEADLIST_HDR, /* UINT64 */ 13512470SMatthew.Ahrens@Sun.COM DMU_OT_DSL_CLONES, /* ZAP */ 13612470SMatthew.Ahrens@Sun.COM DMU_OT_BPOBJ_SUBOBJ, /* UINT64 */ 137789Sahrens DMU_OT_NUMTYPES 138789Sahrens } dmu_object_type_t; 139789Sahrens 140789Sahrens typedef enum dmu_objset_type { 141789Sahrens DMU_OST_NONE, 142789Sahrens DMU_OST_META, 143789Sahrens DMU_OST_ZFS, 144789Sahrens DMU_OST_ZVOL, 145789Sahrens DMU_OST_OTHER, /* For testing only! */ 146789Sahrens DMU_OST_ANY, /* Be careful! */ 147789Sahrens DMU_OST_NUMTYPES 148789Sahrens } dmu_objset_type_t; 149789Sahrens 150789Sahrens void byteswap_uint64_array(void *buf, size_t size); 151789Sahrens void byteswap_uint32_array(void *buf, size_t size); 152789Sahrens void byteswap_uint16_array(void *buf, size_t size); 153789Sahrens void byteswap_uint8_array(void *buf, size_t size); 154789Sahrens void zap_byteswap(void *buf, size_t size); 1555331Samw void zfs_oldacl_byteswap(void *buf, size_t size); 156789Sahrens void zfs_acl_byteswap(void *buf, size_t size); 157789Sahrens void zfs_znode_byteswap(void *buf, size_t size); 158789Sahrens 1592417Sahrens #define DS_FIND_SNAPSHOTS (1<<0) 1602417Sahrens #define DS_FIND_CHILDREN (1<<1) 161789Sahrens 162789Sahrens /* 163789Sahrens * The maximum number of bytes that can be accessed as part of one 164789Sahrens * operation, including metadata. 165789Sahrens */ 166789Sahrens #define DMU_MAX_ACCESS (10<<20) /* 10MB */ 1676992Smaybee #define DMU_MAX_DELETEBLKCNT (20480) /* ~5MB of indirect blocks */ 168789Sahrens 1699396SMatthew.Ahrens@Sun.COM #define DMU_USERUSED_OBJECT (-1ULL) 1709396SMatthew.Ahrens@Sun.COM #define DMU_GROUPUSED_OBJECT (-2ULL) 17110922SJeff.Bonwick@Sun.COM #define DMU_DEADLIST_OBJECT (-3ULL) 1729396SMatthew.Ahrens@Sun.COM 173789Sahrens /* 17411935SMark.Shellenbaum@Sun.COM * artificial blkids for bonus buffer and spill blocks 17511935SMark.Shellenbaum@Sun.COM */ 17611935SMark.Shellenbaum@Sun.COM #define DMU_BONUS_BLKID (-1ULL) 17711935SMark.Shellenbaum@Sun.COM #define DMU_SPILL_BLKID (-2ULL) 17811935SMark.Shellenbaum@Sun.COM /* 179789Sahrens * Public routines to create, destroy, open, and close objsets. 180789Sahrens */ 18110298SMatthew.Ahrens@Sun.COM int dmu_objset_hold(const char *name, void *tag, objset_t **osp); 18210298SMatthew.Ahrens@Sun.COM int dmu_objset_own(const char *name, dmu_objset_type_t type, 18310298SMatthew.Ahrens@Sun.COM boolean_t readonly, void *tag, objset_t **osp); 18410298SMatthew.Ahrens@Sun.COM void dmu_objset_rele(objset_t *os, void *tag); 18510298SMatthew.Ahrens@Sun.COM void dmu_objset_disown(objset_t *os, void *tag); 18610298SMatthew.Ahrens@Sun.COM int dmu_objset_open_ds(struct dsl_dataset *ds, objset_t **osp); 18710298SMatthew.Ahrens@Sun.COM 1884944Smaybee int dmu_objset_evict_dbufs(objset_t *os); 18910272SMatthew.Ahrens@Sun.COM int dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags, 1904543Smarks void (*func)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx), void *arg); 19110272SMatthew.Ahrens@Sun.COM int dmu_objset_clone(const char *name, struct dsl_dataset *clone_origin, 19210272SMatthew.Ahrens@Sun.COM uint64_t flags); 19310242Schris.kirby@sun.com int dmu_objset_destroy(const char *name, boolean_t defer); 19410242Schris.kirby@sun.com int dmu_snapshots_destroy(char *fsname, char *snapname, boolean_t defer); 195*13043STim.Haley@Sun.COM int dmu_objset_snapshot(char *fsname, char *snapname, char *tag, 196*13043STim.Haley@Sun.COM struct nvlist *props, boolean_t recursive, boolean_t temporary, int fd); 1974007Smmusante int dmu_objset_rename(const char *name, const char *newname, 1984007Smmusante boolean_t recursive); 19911209SMatthew.Ahrens@Sun.COM int dmu_objset_find(char *name, int func(const char *, void *), void *arg, 200789Sahrens int flags); 201789Sahrens void dmu_objset_byteswap(void *buf, size_t size); 202789Sahrens 203789Sahrens typedef struct dmu_buf { 204789Sahrens uint64_t db_object; /* object that this buffer is part of */ 205789Sahrens uint64_t db_offset; /* byte offset in this object */ 206789Sahrens uint64_t db_size; /* size of buffer in bytes */ 207789Sahrens void *db_data; /* data in buffer */ 208789Sahrens } dmu_buf_t; 209789Sahrens 210789Sahrens typedef void dmu_buf_evict_func_t(struct dmu_buf *db, void *user_ptr); 211789Sahrens 212789Sahrens /* 2132082Seschrock * The names of zap entries in the DIRECTORY_OBJECT of the MOS. 2142082Seschrock */ 215789Sahrens #define DMU_POOL_DIRECTORY_OBJECT 1 216789Sahrens #define DMU_POOL_CONFIG "config" 217789Sahrens #define DMU_POOL_ROOT_DATASET "root_dataset" 21812470SMatthew.Ahrens@Sun.COM #define DMU_POOL_SYNC_BPOBJ "sync_bplist" 2191544Seschrock #define DMU_POOL_ERRLOG_SCRUB "errlog_scrub" 2201544Seschrock #define DMU_POOL_ERRLOG_LAST "errlog_last" 2212082Seschrock #define DMU_POOL_SPARES "spares" 2222082Seschrock #define DMU_POOL_DEFLATE "deflate" 2232926Sek110237 #define DMU_POOL_HISTORY "history" 2243912Slling #define DMU_POOL_PROPS "pool_props" 2255450Sbrendan #define DMU_POOL_L2CACHE "l2cache" 22610342Schris.kirby@sun.com #define DMU_POOL_TMP_USERREFS "tmp_userrefs" 22710922SJeff.Bonwick@Sun.COM #define DMU_POOL_DDT "DDT-%s-%s-%s" 22810922SJeff.Bonwick@Sun.COM #define DMU_POOL_DDT_STATS "DDT-statistics" 22912296SLin.Ling@Sun.COM #define DMU_POOL_CREATION_VERSION "creation_version" 23012296SLin.Ling@Sun.COM #define DMU_POOL_SCAN "scan" 23112470SMatthew.Ahrens@Sun.COM #define DMU_POOL_FREE_BPOBJ "free_bpobj" 2327046Sahrens 233789Sahrens /* 234789Sahrens * Allocate an object from this objset. The range of object numbers 235789Sahrens * available is (0, DN_MAX_OBJECT). Object 0 is the meta-dnode. 236789Sahrens * 237789Sahrens * The transaction must be assigned to a txg. The newly allocated 238789Sahrens * object will be "held" in the transaction (ie. you can modify the 239789Sahrens * newly allocated object in this transaction). 240789Sahrens * 241789Sahrens * dmu_object_alloc() chooses an object and returns it in *objectp. 242789Sahrens * 243789Sahrens * dmu_object_claim() allocates a specific object number. If that 244789Sahrens * number is already allocated, it fails and returns EEXIST. 245789Sahrens * 246789Sahrens * Return 0 on success, or ENOSPC or EEXIST as specified above. 247789Sahrens */ 248789Sahrens uint64_t dmu_object_alloc(objset_t *os, dmu_object_type_t ot, 249789Sahrens int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx); 250789Sahrens int dmu_object_claim(objset_t *os, uint64_t object, dmu_object_type_t ot, 251789Sahrens int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx); 252789Sahrens int dmu_object_reclaim(objset_t *os, uint64_t object, dmu_object_type_t ot, 2538986SMark.Maybee@Sun.COM int blocksize, dmu_object_type_t bonustype, int bonuslen); 254789Sahrens 255789Sahrens /* 256789Sahrens * Free an object from this objset. 257789Sahrens * 258789Sahrens * The object's data will be freed as well (ie. you don't need to call 259789Sahrens * dmu_free(object, 0, -1, tx)). 260789Sahrens * 261789Sahrens * The object need not be held in the transaction. 262789Sahrens * 263789Sahrens * If there are any holds on this object's buffers (via dmu_buf_hold()), 264789Sahrens * or tx holds on the object (via dmu_tx_hold_object()), you can not 265789Sahrens * free it; it fails and returns EBUSY. 266789Sahrens * 267789Sahrens * If the object is not allocated, it fails and returns ENOENT. 268789Sahrens * 269789Sahrens * Return 0 on success, or EBUSY or ENOENT as specified above. 270789Sahrens */ 271789Sahrens int dmu_object_free(objset_t *os, uint64_t object, dmu_tx_t *tx); 272789Sahrens 273789Sahrens /* 274789Sahrens * Find the next allocated or free object. 275789Sahrens * 276789Sahrens * The objectp parameter is in-out. It will be updated to be the next 2773025Sahrens * object which is allocated. Ignore objects which have not been 2783025Sahrens * modified since txg. 279789Sahrens * 280789Sahrens * XXX Can only be called on a objset with no dirty data. 281789Sahrens * 282789Sahrens * Returns 0 on success, or ENOENT if there are no more objects. 283789Sahrens */ 2843025Sahrens int dmu_object_next(objset_t *os, uint64_t *objectp, 2853025Sahrens boolean_t hole, uint64_t txg); 286789Sahrens 287789Sahrens /* 288789Sahrens * Set the data blocksize for an object. 289789Sahrens * 290789Sahrens * The object cannot have any blocks allcated beyond the first. If 291789Sahrens * the first block is allocated already, the new size must be greater 292789Sahrens * than the current block size. If these conditions are not met, 293789Sahrens * ENOTSUP will be returned. 294789Sahrens * 295789Sahrens * Returns 0 on success, or EBUSY if there are any holds on the object 296789Sahrens * contents, or ENOTSUP as described above. 297789Sahrens */ 298789Sahrens int dmu_object_set_blocksize(objset_t *os, uint64_t object, uint64_t size, 299789Sahrens int ibs, dmu_tx_t *tx); 300789Sahrens 301789Sahrens /* 302789Sahrens * Set the checksum property on a dnode. The new checksum algorithm will 303789Sahrens * apply to all newly written blocks; existing blocks will not be affected. 304789Sahrens */ 305789Sahrens void dmu_object_set_checksum(objset_t *os, uint64_t object, uint8_t checksum, 306789Sahrens dmu_tx_t *tx); 307789Sahrens 308789Sahrens /* 309789Sahrens * Set the compress property on a dnode. The new compression algorithm will 310789Sahrens * apply to all newly written blocks; existing blocks will not be affected. 311789Sahrens */ 312789Sahrens void dmu_object_set_compress(objset_t *os, uint64_t object, uint8_t compress, 313789Sahrens dmu_tx_t *tx); 314789Sahrens 315789Sahrens /* 31610922SJeff.Bonwick@Sun.COM * Decide how to write a block: checksum, compression, number of copies, etc. 3171775Sbillm */ 31810922SJeff.Bonwick@Sun.COM #define WP_NOFILL 0x1 31910922SJeff.Bonwick@Sun.COM #define WP_DMU_SYNC 0x2 32011935SMark.Shellenbaum@Sun.COM #define WP_SPILL 0x4 32110922SJeff.Bonwick@Sun.COM 32210922SJeff.Bonwick@Sun.COM void dmu_write_policy(objset_t *os, struct dnode *dn, int level, int wp, 32310922SJeff.Bonwick@Sun.COM struct zio_prop *zp); 3241775Sbillm /* 325789Sahrens * The bonus data is accessed more or less like a regular buffer. 326789Sahrens * You must dmu_bonus_hold() to get the buffer, which will give you a 327789Sahrens * dmu_buf_t with db_offset==-1ULL, and db_size = the size of the bonus 328789Sahrens * data. As with any normal buffer, you must call dmu_buf_read() to 329789Sahrens * read db_data, dmu_buf_will_dirty() before modifying it, and the 330789Sahrens * object must be held in an assigned transaction before calling 331789Sahrens * dmu_buf_will_dirty. You may use dmu_buf_set_user() on the bonus 332789Sahrens * buffer as well. You must release your hold with dmu_buf_rele(). 333789Sahrens */ 3341544Seschrock int dmu_bonus_hold(objset_t *os, uint64_t object, void *tag, dmu_buf_t **); 335789Sahrens int dmu_bonus_max(void); 3364944Smaybee int dmu_set_bonus(dmu_buf_t *, int, dmu_tx_t *); 33711935SMark.Shellenbaum@Sun.COM int dmu_set_bonustype(dmu_buf_t *, dmu_object_type_t, dmu_tx_t *); 33812684STom.Erickson@Sun.COM dmu_object_type_t dmu_get_bonustype(dmu_buf_t *); 33911935SMark.Shellenbaum@Sun.COM int dmu_rm_spill(objset_t *, uint64_t, dmu_tx_t *); 34011935SMark.Shellenbaum@Sun.COM 34111935SMark.Shellenbaum@Sun.COM /* 34211935SMark.Shellenbaum@Sun.COM * Special spill buffer support used by "SA" framework 34311935SMark.Shellenbaum@Sun.COM */ 34411935SMark.Shellenbaum@Sun.COM 34511935SMark.Shellenbaum@Sun.COM int dmu_spill_hold_by_bonus(dmu_buf_t *bonus, void *tag, dmu_buf_t **dbp); 34611935SMark.Shellenbaum@Sun.COM int dmu_spill_hold_by_dnode(struct dnode *dn, uint32_t flags, 34711935SMark.Shellenbaum@Sun.COM void *tag, dmu_buf_t **dbp); 34811935SMark.Shellenbaum@Sun.COM int dmu_spill_hold_existing(dmu_buf_t *bonus, void *tag, dmu_buf_t **dbp); 349789Sahrens 350789Sahrens /* 351789Sahrens * Obtain the DMU buffer from the specified object which contains the 352789Sahrens * specified offset. dmu_buf_hold() puts a "hold" on the buffer, so 353789Sahrens * that it will remain in memory. You must release the hold with 354789Sahrens * dmu_buf_rele(). You musn't access the dmu_buf_t after releasing your 355789Sahrens * hold. You must have a hold on any dmu_buf_t* you pass to the DMU. 356789Sahrens * 357789Sahrens * You must call dmu_buf_read, dmu_buf_will_dirty, or dmu_buf_will_fill 358789Sahrens * on the returned buffer before reading or writing the buffer's 359789Sahrens * db_data. The comments for those routines describe what particular 360789Sahrens * operations are valid after calling them. 361789Sahrens * 362789Sahrens * The object number must be a valid, allocated object number. 363789Sahrens */ 3641544Seschrock int dmu_buf_hold(objset_t *os, uint64_t object, uint64_t offset, 36512285SJeff.Bonwick@Sun.COM void *tag, dmu_buf_t **, int flags); 366789Sahrens void dmu_buf_add_ref(dmu_buf_t *db, void* tag); 3671544Seschrock void dmu_buf_rele(dmu_buf_t *db, void *tag); 368789Sahrens uint64_t dmu_buf_refcount(dmu_buf_t *db); 369789Sahrens 370789Sahrens /* 371789Sahrens * dmu_buf_hold_array holds the DMU buffers which contain all bytes in a 372789Sahrens * range of an object. A pointer to an array of dmu_buf_t*'s is 373789Sahrens * returned (in *dbpp). 374789Sahrens * 375789Sahrens * dmu_buf_rele_array releases the hold on an array of dmu_buf_t*'s, and 376789Sahrens * frees the array. The hold on the array of buffers MUST be released 377789Sahrens * with dmu_buf_rele_array. You can NOT release the hold on each buffer 378789Sahrens * individually with dmu_buf_rele. 379789Sahrens */ 3802391Smaybee int dmu_buf_hold_array_by_bonus(dmu_buf_t *db, uint64_t offset, 3812391Smaybee uint64_t length, int read, void *tag, int *numbufsp, dmu_buf_t ***dbpp); 3821544Seschrock void dmu_buf_rele_array(dmu_buf_t **, int numbufs, void *tag); 383789Sahrens 384789Sahrens /* 385789Sahrens * Returns NULL on success, or the existing user ptr if it's already 386789Sahrens * been set. 387789Sahrens * 388789Sahrens * user_ptr is for use by the user and can be obtained via dmu_buf_get_user(). 389789Sahrens * 390789Sahrens * user_data_ptr_ptr should be NULL, or a pointer to a pointer which 391789Sahrens * will be set to db->db_data when you are allowed to access it. Note 392789Sahrens * that db->db_data (the pointer) can change when you do dmu_buf_read(), 393789Sahrens * dmu_buf_tryupgrade(), dmu_buf_will_dirty(), or dmu_buf_will_fill(). 394789Sahrens * *user_data_ptr_ptr will be set to the new value when it changes. 395789Sahrens * 396789Sahrens * If non-NULL, pageout func will be called when this buffer is being 397789Sahrens * excised from the cache, so that you can clean up the data structure 398789Sahrens * pointed to by user_ptr. 399789Sahrens * 400789Sahrens * dmu_evict_user() will call the pageout func for all buffers in a 401789Sahrens * objset with a given pageout func. 402789Sahrens */ 403789Sahrens void *dmu_buf_set_user(dmu_buf_t *db, void *user_ptr, void *user_data_ptr_ptr, 404789Sahrens dmu_buf_evict_func_t *pageout_func); 405789Sahrens /* 406789Sahrens * set_user_ie is the same as set_user, but request immediate eviction 407789Sahrens * when hold count goes to zero. 408789Sahrens */ 409789Sahrens void *dmu_buf_set_user_ie(dmu_buf_t *db, void *user_ptr, 410789Sahrens void *user_data_ptr_ptr, dmu_buf_evict_func_t *pageout_func); 411789Sahrens void *dmu_buf_update_user(dmu_buf_t *db_fake, void *old_user_ptr, 412789Sahrens void *user_ptr, void *user_data_ptr_ptr, 413789Sahrens dmu_buf_evict_func_t *pageout_func); 414789Sahrens void dmu_evict_user(objset_t *os, dmu_buf_evict_func_t *func); 415789Sahrens 416789Sahrens /* 417789Sahrens * Returns the user_ptr set with dmu_buf_set_user(), or NULL if not set. 418789Sahrens */ 419789Sahrens void *dmu_buf_get_user(dmu_buf_t *db); 420789Sahrens 421789Sahrens /* 422789Sahrens * Indicate that you are going to modify the buffer's data (db_data). 423789Sahrens * 424789Sahrens * The transaction (tx) must be assigned to a txg (ie. you've called 425789Sahrens * dmu_tx_assign()). The buffer's object must be held in the tx 426789Sahrens * (ie. you've called dmu_tx_hold_object(tx, db->db_object)). 427789Sahrens */ 428789Sahrens void dmu_buf_will_dirty(dmu_buf_t *db, dmu_tx_t *tx); 429789Sahrens 430789Sahrens /* 4319653SSanjeev.Bagewadi@Sun.COM * Tells if the given dbuf is freeable. 4329653SSanjeev.Bagewadi@Sun.COM */ 4339653SSanjeev.Bagewadi@Sun.COM boolean_t dmu_buf_freeable(dmu_buf_t *); 4349653SSanjeev.Bagewadi@Sun.COM 4359653SSanjeev.Bagewadi@Sun.COM /* 436789Sahrens * You must create a transaction, then hold the objects which you will 437789Sahrens * (or might) modify as part of this transaction. Then you must assign 438789Sahrens * the transaction to a transaction group. Once the transaction has 439789Sahrens * been assigned, you can modify buffers which belong to held objects as 440789Sahrens * part of this transaction. You can't modify buffers before the 441789Sahrens * transaction has been assigned; you can't modify buffers which don't 442789Sahrens * belong to objects which this transaction holds; you can't hold 443789Sahrens * objects once the transaction has been assigned. You may hold an 444789Sahrens * object which you are going to free (with dmu_object_free()), but you 445789Sahrens * don't have to. 446789Sahrens * 447789Sahrens * You can abort the transaction before it has been assigned. 448789Sahrens * 449789Sahrens * Note that you may hold buffers (with dmu_buf_hold) at any time, 450789Sahrens * regardless of transaction state. 451789Sahrens */ 452789Sahrens 453789Sahrens #define DMU_NEW_OBJECT (-1ULL) 454789Sahrens #define DMU_OBJECT_END (-1ULL) 455789Sahrens 456789Sahrens dmu_tx_t *dmu_tx_create(objset_t *os); 457789Sahrens void dmu_tx_hold_write(dmu_tx_t *tx, uint64_t object, uint64_t off, int len); 458789Sahrens void dmu_tx_hold_free(dmu_tx_t *tx, uint64_t object, uint64_t off, 459789Sahrens uint64_t len); 4609396SMatthew.Ahrens@Sun.COM void dmu_tx_hold_zap(dmu_tx_t *tx, uint64_t object, int add, const char *name); 461789Sahrens void dmu_tx_hold_bonus(dmu_tx_t *tx, uint64_t object); 46211935SMark.Shellenbaum@Sun.COM void dmu_tx_hold_spill(dmu_tx_t *tx, uint64_t object); 46311935SMark.Shellenbaum@Sun.COM void dmu_tx_hold_sa(dmu_tx_t *tx, struct sa_handle *hdl, boolean_t may_grow); 46411935SMark.Shellenbaum@Sun.COM void dmu_tx_hold_sa_create(dmu_tx_t *tx, int total_size); 465789Sahrens void dmu_tx_abort(dmu_tx_t *tx); 466789Sahrens int dmu_tx_assign(dmu_tx_t *tx, uint64_t txg_how); 4672113Sahrens void dmu_tx_wait(dmu_tx_t *tx); 468789Sahrens void dmu_tx_commit(dmu_tx_t *tx); 469789Sahrens 470789Sahrens /* 47110612SRicardo.M.Correia@Sun.COM * To register a commit callback, dmu_tx_callback_register() must be called. 47210612SRicardo.M.Correia@Sun.COM * 47310612SRicardo.M.Correia@Sun.COM * dcb_data is a pointer to caller private data that is passed on as a 47410612SRicardo.M.Correia@Sun.COM * callback parameter. The caller is responsible for properly allocating and 47510612SRicardo.M.Correia@Sun.COM * freeing it. 47610612SRicardo.M.Correia@Sun.COM * 47710612SRicardo.M.Correia@Sun.COM * When registering a callback, the transaction must be already created, but 47810612SRicardo.M.Correia@Sun.COM * it cannot be committed or aborted. It can be assigned to a txg or not. 47910612SRicardo.M.Correia@Sun.COM * 48010612SRicardo.M.Correia@Sun.COM * The callback will be called after the transaction has been safely written 48110612SRicardo.M.Correia@Sun.COM * to stable storage and will also be called if the dmu_tx is aborted. 48210612SRicardo.M.Correia@Sun.COM * If there is any error which prevents the transaction from being committed to 48310612SRicardo.M.Correia@Sun.COM * disk, the callback will be called with a value of error != 0. 48410612SRicardo.M.Correia@Sun.COM */ 48510612SRicardo.M.Correia@Sun.COM typedef void dmu_tx_callback_func_t(void *dcb_data, int error); 48610612SRicardo.M.Correia@Sun.COM 48710612SRicardo.M.Correia@Sun.COM void dmu_tx_callback_register(dmu_tx_t *tx, dmu_tx_callback_func_t *dcb_func, 48810612SRicardo.M.Correia@Sun.COM void *dcb_data); 48910612SRicardo.M.Correia@Sun.COM 49010612SRicardo.M.Correia@Sun.COM /* 491789Sahrens * Free up the data blocks for a defined range of a file. If size is 492789Sahrens * zero, the range from offset to end-of-file is freed. 493789Sahrens */ 4941544Seschrock int dmu_free_range(objset_t *os, uint64_t object, uint64_t offset, 495789Sahrens uint64_t size, dmu_tx_t *tx); 4966992Smaybee int dmu_free_long_range(objset_t *os, uint64_t object, uint64_t offset, 4976992Smaybee uint64_t size); 4986992Smaybee int dmu_free_object(objset_t *os, uint64_t object); 499789Sahrens 500789Sahrens /* 501789Sahrens * Convenience functions. 502789Sahrens * 503789Sahrens * Canfail routines will return 0 on success, or an errno if there is a 504789Sahrens * nonrecoverable I/O error. 505789Sahrens */ 5069512SNeil.Perrin@Sun.COM #define DMU_READ_PREFETCH 0 /* prefetch */ 5079512SNeil.Perrin@Sun.COM #define DMU_READ_NO_PREFETCH 1 /* don't prefetch */ 5081544Seschrock int dmu_read(objset_t *os, uint64_t object, uint64_t offset, uint64_t size, 5099512SNeil.Perrin@Sun.COM void *buf, uint32_t flags); 510789Sahrens void dmu_write(objset_t *os, uint64_t object, uint64_t offset, uint64_t size, 511789Sahrens const void *buf, dmu_tx_t *tx); 5127872STim.Haley@Sun.COM void dmu_prealloc(objset_t *os, uint64_t object, uint64_t offset, uint64_t size, 5137872STim.Haley@Sun.COM dmu_tx_t *tx); 5143638Sbillm int dmu_read_uio(objset_t *os, uint64_t object, struct uio *uio, uint64_t size); 5153638Sbillm int dmu_write_uio(objset_t *os, uint64_t object, struct uio *uio, uint64_t size, 5163638Sbillm dmu_tx_t *tx); 51712123STim.Haley@Sun.COM int dmu_write_uio_dbuf(dmu_buf_t *zdb, struct uio *uio, uint64_t size, 51812123STim.Haley@Sun.COM dmu_tx_t *tx); 5192688Smaybee int dmu_write_pages(objset_t *os, uint64_t object, uint64_t offset, 5202688Smaybee uint64_t size, struct page *pp, dmu_tx_t *tx); 5219412SAleksandr.Guzovskiy@Sun.COM struct arc_buf *dmu_request_arcbuf(dmu_buf_t *handle, int size); 5229412SAleksandr.Guzovskiy@Sun.COM void dmu_return_arcbuf(struct arc_buf *buf); 5239412SAleksandr.Guzovskiy@Sun.COM void dmu_assign_arcbuf(dmu_buf_t *handle, uint64_t offset, struct arc_buf *buf, 5249412SAleksandr.Guzovskiy@Sun.COM dmu_tx_t *tx); 52511539SChunli.Zhang@Sun.COM int dmu_xuio_init(struct xuio *uio, int niov); 52611539SChunli.Zhang@Sun.COM void dmu_xuio_fini(struct xuio *uio); 52711539SChunli.Zhang@Sun.COM int dmu_xuio_add(struct xuio *uio, struct arc_buf *abuf, offset_t off, 52811539SChunli.Zhang@Sun.COM size_t n); 52911539SChunli.Zhang@Sun.COM int dmu_xuio_cnt(struct xuio *uio); 53011539SChunli.Zhang@Sun.COM struct arc_buf *dmu_xuio_arcbuf(struct xuio *uio, int i); 53111539SChunli.Zhang@Sun.COM void dmu_xuio_clear(struct xuio *uio, int i); 53211539SChunli.Zhang@Sun.COM void xuio_stat_wbuf_copied(); 53311539SChunli.Zhang@Sun.COM void xuio_stat_wbuf_nocopy(); 534789Sahrens 5352986Sek110237 extern int zfs_prefetch_disable; 5362986Sek110237 537789Sahrens /* 538789Sahrens * Asynchronously try to read in the data. 539789Sahrens */ 540789Sahrens void dmu_prefetch(objset_t *os, uint64_t object, uint64_t offset, 541789Sahrens uint64_t len); 542789Sahrens 543789Sahrens typedef struct dmu_object_info { 54410922SJeff.Bonwick@Sun.COM /* All sizes are in bytes unless otherwise indicated. */ 545789Sahrens uint32_t doi_data_block_size; 546789Sahrens uint32_t doi_metadata_block_size; 547789Sahrens dmu_object_type_t doi_type; 548789Sahrens dmu_object_type_t doi_bonus_type; 54910922SJeff.Bonwick@Sun.COM uint64_t doi_bonus_size; 550789Sahrens uint8_t doi_indirection; /* 2 = dnode->indirect->data */ 551789Sahrens uint8_t doi_checksum; 552789Sahrens uint8_t doi_compress; 553789Sahrens uint8_t doi_pad[5]; 55410922SJeff.Bonwick@Sun.COM uint64_t doi_physical_blocks_512; /* data + metadata, 512b blks */ 55510922SJeff.Bonwick@Sun.COM uint64_t doi_max_offset; 55610922SJeff.Bonwick@Sun.COM uint64_t doi_fill_count; /* number of non-empty blocks */ 557789Sahrens } dmu_object_info_t; 558789Sahrens 5594849Sahrens typedef void arc_byteswap_func_t(void *buf, size_t size); 5604849Sahrens 561789Sahrens typedef struct dmu_object_type_info { 5624849Sahrens arc_byteswap_func_t *ot_byteswap; 563789Sahrens boolean_t ot_metadata; 564789Sahrens char *ot_name; 565789Sahrens } dmu_object_type_info_t; 566789Sahrens 567789Sahrens extern const dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES]; 568789Sahrens 569789Sahrens /* 570789Sahrens * Get information on a DMU object. 571789Sahrens * 572789Sahrens * Return 0 on success or ENOENT if object is not allocated. 573789Sahrens * 574789Sahrens * If doi is NULL, just indicates whether the object exists. 575789Sahrens */ 576789Sahrens int dmu_object_info(objset_t *os, uint64_t object, dmu_object_info_t *doi); 577789Sahrens void dmu_object_info_from_dnode(struct dnode *dn, dmu_object_info_t *doi); 578789Sahrens void dmu_object_info_from_db(dmu_buf_t *db, dmu_object_info_t *doi); 579789Sahrens void dmu_object_size_from_db(dmu_buf_t *db, uint32_t *blksize, 580789Sahrens u_longlong_t *nblk512); 581789Sahrens 582789Sahrens typedef struct dmu_objset_stats { 5832885Sahrens uint64_t dds_num_clones; /* number of clones of this */ 5842885Sahrens uint64_t dds_creation_txg; 5855367Sahrens uint64_t dds_guid; 586789Sahrens dmu_objset_type_t dds_type; 587789Sahrens uint8_t dds_is_snapshot; 5881758Sahrens uint8_t dds_inconsistent; 5895367Sahrens char dds_origin[MAXNAMELEN]; 590789Sahrens } dmu_objset_stats_t; 591789Sahrens 592789Sahrens /* 593789Sahrens * Get stats on a dataset. 594789Sahrens */ 5952885Sahrens void dmu_objset_fast_stat(objset_t *os, dmu_objset_stats_t *stat); 5962885Sahrens 5972885Sahrens /* 5982885Sahrens * Add entries to the nvlist for all the objset's properties. See 5992885Sahrens * zfs_prop_table[] and zfs(1m) for details on the properties. 6002885Sahrens */ 6012885Sahrens void dmu_objset_stats(objset_t *os, struct nvlist *nv); 6022885Sahrens 6032885Sahrens /* 6042885Sahrens * Get the space usage statistics for statvfs(). 6052885Sahrens * 6062885Sahrens * refdbytes is the amount of space "referenced" by this objset. 6072885Sahrens * availbytes is the amount of space available to this objset, taking 6082885Sahrens * into account quotas & reservations, assuming that no other objsets 6092885Sahrens * use the space first. These values correspond to the 'referenced' and 6102885Sahrens * 'available' properties, described in the zfs(1m) manpage. 6112885Sahrens * 6122885Sahrens * usedobjs and availobjs are the number of objects currently allocated, 6132885Sahrens * and available. 6142885Sahrens */ 6152885Sahrens void dmu_objset_space(objset_t *os, uint64_t *refdbytesp, uint64_t *availbytesp, 6162885Sahrens uint64_t *usedobjsp, uint64_t *availobjsp); 6172885Sahrens 6182885Sahrens /* 6192885Sahrens * The fsid_guid is a 56-bit ID that can change to avoid collisions. 6202885Sahrens * (Contrast with the ds_guid which is a 64-bit ID that will never 6212885Sahrens * change, so there is a small probability that it will collide.) 6222885Sahrens */ 6232885Sahrens uint64_t dmu_objset_fsid_guid(objset_t *os); 624789Sahrens 62510373Schris.kirby@sun.com /* 62610373Schris.kirby@sun.com * Get the [cm]time for an objset's snapshot dir 62710373Schris.kirby@sun.com */ 62810373Schris.kirby@sun.com timestruc_t dmu_objset_snap_cmtime(objset_t *os); 62910373Schris.kirby@sun.com 630789Sahrens int dmu_objset_is_snapshot(objset_t *os); 631789Sahrens 632789Sahrens extern struct spa *dmu_objset_spa(objset_t *os); 633789Sahrens extern struct zilog *dmu_objset_zil(objset_t *os); 634789Sahrens extern struct dsl_pool *dmu_objset_pool(objset_t *os); 635789Sahrens extern struct dsl_dataset *dmu_objset_ds(objset_t *os); 636789Sahrens extern void dmu_objset_name(objset_t *os, char *buf); 637789Sahrens extern dmu_objset_type_t dmu_objset_type(objset_t *os); 638789Sahrens extern uint64_t dmu_objset_id(objset_t *os); 63912294SMark.Musante@Sun.COM extern uint64_t dmu_objset_syncprop(objset_t *os); 64010310SNeil.Perrin@Sun.COM extern uint64_t dmu_objset_logbias(objset_t *os); 641789Sahrens extern int dmu_snapshot_list_next(objset_t *os, int namelen, char *name, 6425663Sck153898 uint64_t *id, uint64_t *offp, boolean_t *case_conflict); 6436492Stimh extern int dmu_snapshot_realname(objset_t *os, char *name, char *real, 6446492Stimh int maxlen, boolean_t *conflict); 645885Sahrens extern int dmu_dir_list_next(objset_t *os, int namelen, char *name, 646885Sahrens uint64_t *idp, uint64_t *offp); 6479396SMatthew.Ahrens@Sun.COM 64810407SMatthew.Ahrens@Sun.COM typedef int objset_used_cb_t(dmu_object_type_t bonustype, 64910407SMatthew.Ahrens@Sun.COM void *bonus, uint64_t *userp, uint64_t *groupp); 6509396SMatthew.Ahrens@Sun.COM extern void dmu_objset_register_type(dmu_objset_type_t ost, 6519396SMatthew.Ahrens@Sun.COM objset_used_cb_t *cb); 6525326Sek110237 extern void dmu_objset_set_user(objset_t *os, void *user_ptr); 6535326Sek110237 extern void *dmu_objset_get_user(objset_t *os); 654789Sahrens 655789Sahrens /* 656789Sahrens * Return the txg number for the given assigned transaction. 657789Sahrens */ 658885Sahrens uint64_t dmu_tx_get_txg(dmu_tx_t *tx); 659789Sahrens 660789Sahrens /* 661789Sahrens * Synchronous write. 6622237Smaybee * If a parent zio is provided this function initiates a write on the 6632237Smaybee * provided buffer as a child of the parent zio. 6645331Samw * In the absence of a parent zio, the write is completed synchronously. 6652237Smaybee * At write completion, blk is filled with the bp of the written block. 666789Sahrens * Note that while the data covered by this function will be on stable 6672237Smaybee * storage when the write completes this new data does not become a 668789Sahrens * permanent part of the file until the associated transaction commits. 669789Sahrens */ 67010922SJeff.Bonwick@Sun.COM 67110922SJeff.Bonwick@Sun.COM /* 67210922SJeff.Bonwick@Sun.COM * {zfs,zvol,ztest}_get_done() args 67310922SJeff.Bonwick@Sun.COM */ 67410922SJeff.Bonwick@Sun.COM typedef struct zgd { 67510922SJeff.Bonwick@Sun.COM struct zilog *zgd_zilog; 67610922SJeff.Bonwick@Sun.COM struct blkptr *zgd_bp; 67710922SJeff.Bonwick@Sun.COM dmu_buf_t *zgd_db; 67810922SJeff.Bonwick@Sun.COM struct rl *zgd_rl; 67910922SJeff.Bonwick@Sun.COM void *zgd_private; 68010922SJeff.Bonwick@Sun.COM } zgd_t; 68110922SJeff.Bonwick@Sun.COM 68210922SJeff.Bonwick@Sun.COM typedef void dmu_sync_cb_t(zgd_t *arg, int error); 68310922SJeff.Bonwick@Sun.COM int dmu_sync(struct zio *zio, uint64_t txg, dmu_sync_cb_t *done, zgd_t *zgd); 684789Sahrens 685789Sahrens /* 686789Sahrens * Find the next hole or data block in file starting at *off 687789Sahrens * Return found offset in *off. Return ESRCH for end of file. 688789Sahrens */ 689789Sahrens int dmu_offset_next(objset_t *os, uint64_t object, boolean_t hole, 690789Sahrens uint64_t *off); 691789Sahrens 692789Sahrens /* 693789Sahrens * Initial setup and final teardown. 694789Sahrens */ 695789Sahrens extern void dmu_init(void); 696789Sahrens extern void dmu_fini(void); 697789Sahrens 698789Sahrens typedef void (*dmu_traverse_cb_t)(objset_t *os, void *arg, struct blkptr *bp, 699789Sahrens uint64_t object, uint64_t offset, int len); 700789Sahrens void dmu_traverse_objset(objset_t *os, uint64_t txg_start, 701789Sahrens dmu_traverse_cb_t cb, void *arg); 702789Sahrens 7035367Sahrens int dmu_sendbackup(objset_t *tosnap, objset_t *fromsnap, boolean_t fromorigin, 7045367Sahrens struct vnode *vp, offset_t *off); 7055367Sahrens 7065367Sahrens typedef struct dmu_recv_cookie { 7075367Sahrens /* 7085367Sahrens * This structure is opaque! 7095367Sahrens * 7105367Sahrens * If logical and real are different, we are recving the stream 7115367Sahrens * into the "real" temporary clone, and then switching it with 7125367Sahrens * the "logical" target. 7135367Sahrens */ 7145367Sahrens struct dsl_dataset *drc_logical_ds; 7155367Sahrens struct dsl_dataset *drc_real_ds; 7165367Sahrens struct drr_begin *drc_drrb; 7175367Sahrens char *drc_tosnap; 71811007SLori.Alt@Sun.COM char *drc_top_ds; 7195367Sahrens boolean_t drc_newfs; 7205367Sahrens boolean_t drc_force; 7215367Sahrens } dmu_recv_cookie_t; 7225367Sahrens 72311007SLori.Alt@Sun.COM int dmu_recv_begin(char *tofs, char *tosnap, char *topds, struct drr_begin *, 72410204SMatthew.Ahrens@Sun.COM boolean_t force, objset_t *origin, dmu_recv_cookie_t *); 72512527SChris.Kirby@oracle.com int dmu_recv_stream(dmu_recv_cookie_t *drc, struct vnode *vp, offset_t *voffp, 72612527SChris.Kirby@oracle.com int cleanup_fd, uint64_t *action_handlep); 7275367Sahrens int dmu_recv_end(dmu_recv_cookie_t *drc); 728789Sahrens 729*13043STim.Haley@Sun.COM int dmu_diff(objset_t *tosnap, objset_t *fromsnap, struct vnode *vp, 730*13043STim.Haley@Sun.COM offset_t *off); 731*13043STim.Haley@Sun.COM 732789Sahrens /* CRC64 table */ 733789Sahrens #define ZFS_CRC64_POLY 0xC96C5795D7870F42ULL /* ECMA-182, reflected form */ 734789Sahrens extern uint64_t zfs_crc64_table[256]; 735789Sahrens 736789Sahrens #ifdef __cplusplus 737789Sahrens } 738789Sahrens #endif 739789Sahrens 740789Sahrens #endif /* _SYS_DMU_H */ 741