1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2011 by Delphix. All rights reserved.
  24  */
  25 /*
  26  * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
  27  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
  28  */
  29 
  30 /* Portions Copyright 2010 Robert Milkowski */
  31 
  32 #ifndef _SYS_DMU_H
  33 #define _SYS_DMU_H
  34 
  35 /*
  36  * This file describes the interface that the DMU provides for its
  37  * consumers.
  38  *
  39  * The DMU also interacts with the SPA.  That interface is described in
  40  * dmu_spa.h.
  41  */
  42 
  43 #include <sys/inttypes.h>
  44 #include <sys/types.h>
  45 #include <sys/param.h>
 
 
  58 struct zilog;
  59 struct zio;
  60 struct blkptr;
  61 struct zap_cursor;
  62 struct dsl_dataset;
  63 struct dsl_pool;
  64 struct dnode;
  65 struct drr_begin;
  66 struct drr_end;
  67 struct zbookmark;
  68 struct spa;
  69 struct nvlist;
  70 struct arc_buf;
  71 struct zio_prop;
  72 struct sa_handle;
  73 
  74 typedef struct objset objset_t;
  75 typedef struct dmu_tx dmu_tx_t;
  76 typedef struct dsl_dir dsl_dir_t;
  77 
  78 typedef enum dmu_object_type {
  79         DMU_OT_NONE,
  80         /* general: */
  81         DMU_OT_OBJECT_DIRECTORY,        /* ZAP */
  82         DMU_OT_OBJECT_ARRAY,            /* UINT64 */
  83         DMU_OT_PACKED_NVLIST,           /* UINT8 (XDR by nvlist_pack/unpack) */
  84         DMU_OT_PACKED_NVLIST_SIZE,      /* UINT64 */
  85         DMU_OT_BPOBJ,                   /* UINT64 */
  86         DMU_OT_BPOBJ_HDR,               /* UINT64 */
  87         /* spa: */
  88         DMU_OT_SPACE_MAP_HEADER,        /* UINT64 */
  89         DMU_OT_SPACE_MAP,               /* UINT64 */
  90         /* zil: */
  91         DMU_OT_INTENT_LOG,              /* UINT64 */
  92         /* dmu: */
  93         DMU_OT_DNODE,                   /* DNODE */
  94         DMU_OT_OBJSET,                  /* OBJSET */
  95         /* dsl: */
  96         DMU_OT_DSL_DIR,                 /* UINT64 */
  97         DMU_OT_DSL_DIR_CHILD_MAP,       /* ZAP */
 
 122         DMU_OT_SYSACL,                  /* SYSACL */
 123         DMU_OT_FUID,                    /* FUID table (Packed NVLIST UINT8) */
 124         DMU_OT_FUID_SIZE,               /* FUID table size UINT64 */
 125         DMU_OT_NEXT_CLONES,             /* ZAP */
 126         DMU_OT_SCAN_QUEUE,              /* ZAP */
 127         DMU_OT_USERGROUP_USED,          /* ZAP */
 128         DMU_OT_USERGROUP_QUOTA,         /* ZAP */
 129         DMU_OT_USERREFS,                /* ZAP */
 130         DMU_OT_DDT_ZAP,                 /* ZAP */
 131         DMU_OT_DDT_STATS,               /* ZAP */
 132         DMU_OT_SA,                      /* System attr */
 133         DMU_OT_SA_MASTER_NODE,          /* ZAP */
 134         DMU_OT_SA_ATTR_REGISTRATION,    /* ZAP */
 135         DMU_OT_SA_ATTR_LAYOUTS,         /* ZAP */
 136         DMU_OT_SCAN_XLATE,              /* ZAP */
 137         DMU_OT_DEDUP,                   /* fake dedup BP from ddt_bp_create() */
 138         DMU_OT_DEADLIST,                /* ZAP */
 139         DMU_OT_DEADLIST_HDR,            /* UINT64 */
 140         DMU_OT_DSL_CLONES,              /* ZAP */
 141         DMU_OT_BPOBJ_SUBOBJ,            /* UINT64 */
 142         DMU_OT_NUMTYPES
 143 } dmu_object_type_t;
 144 
 145 typedef enum dmu_objset_type {
 146         DMU_OST_NONE,
 147         DMU_OST_META,
 148         DMU_OST_ZFS,
 149         DMU_OST_ZVOL,
 150         DMU_OST_OTHER,                  /* For testing only! */
 151         DMU_OST_ANY,                    /* Be careful! */
 152         DMU_OST_NUMTYPES
 153 } dmu_objset_type_t;
 154 
 155 void byteswap_uint64_array(void *buf, size_t size);
 156 void byteswap_uint32_array(void *buf, size_t size);
 157 void byteswap_uint16_array(void *buf, size_t size);
 158 void byteswap_uint8_array(void *buf, size_t size);
 159 void zap_byteswap(void *buf, size_t size);
 160 void zfs_oldacl_byteswap(void *buf, size_t size);
 161 void zfs_acl_byteswap(void *buf, size_t size);
 162 void zfs_znode_byteswap(void *buf, size_t size);
 
 202 int dmu_objset_rename(const char *name, const char *newname,
 203     boolean_t recursive);
 204 int dmu_objset_find(char *name, int func(const char *, void *), void *arg,
 205     int flags);
 206 void dmu_objset_byteswap(void *buf, size_t size);
 207 
 208 typedef struct dmu_buf {
 209         uint64_t db_object;             /* object that this buffer is part of */
 210         uint64_t db_offset;             /* byte offset in this object */
 211         uint64_t db_size;               /* size of buffer in bytes */
 212         void *db_data;                  /* data in buffer */
 213 } dmu_buf_t;
 214 
 215 typedef void dmu_buf_evict_func_t(struct dmu_buf *db, void *user_ptr);
 216 
 217 /*
 218  * The names of zap entries in the DIRECTORY_OBJECT of the MOS.
 219  */
 220 #define DMU_POOL_DIRECTORY_OBJECT       1
 221 #define DMU_POOL_CONFIG                 "config"
 222 #define DMU_POOL_ROOT_DATASET           "root_dataset"
 223 #define DMU_POOL_SYNC_BPOBJ             "sync_bplist"
 224 #define DMU_POOL_ERRLOG_SCRUB           "errlog_scrub"
 225 #define DMU_POOL_ERRLOG_LAST            "errlog_last"
 226 #define DMU_POOL_SPARES                 "spares"
 227 #define DMU_POOL_DEFLATE                "deflate"
 228 #define DMU_POOL_HISTORY                "history"
 229 #define DMU_POOL_PROPS                  "pool_props"
 230 #define DMU_POOL_L2CACHE                "l2cache"
 231 #define DMU_POOL_TMP_USERREFS           "tmp_userrefs"
 232 #define DMU_POOL_DDT                    "DDT-%s-%s-%s"
 233 #define DMU_POOL_DDT_STATS              "DDT-statistics"
 234 #define DMU_POOL_CREATION_VERSION       "creation_version"
 235 #define DMU_POOL_SCAN                   "scan"
 236 #define DMU_POOL_FREE_BPOBJ             "free_bpobj"
 237 
 238 /*
 239  * Allocate an object from this objset.  The range of object numbers
 240  * available is (0, DN_MAX_OBJECT).  Object 0 is the meta-dnode.
 241  *
 242  * The transaction must be assigned to a txg.  The newly allocated
 243  * object will be "held" in the transaction (ie. you can modify the
 244  * newly allocated object in this transaction).
 245  *
 246  * dmu_object_alloc() chooses an object and returns it in *objectp.
 247  *
 248  * dmu_object_claim() allocates a specific object number.  If that
 249  * number is already allocated, it fails and returns EEXIST.
 250  *
 251  * Return 0 on success, or ENOSPC or EEXIST as specified above.
 252  */
 253 uint64_t dmu_object_alloc(objset_t *os, dmu_object_type_t ot,
 254     int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx);
 255 int dmu_object_claim(objset_t *os, uint64_t object, dmu_object_type_t ot,
 256     int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx);
 
 477  *
 478  * dcb_data is a pointer to caller private data that is passed on as a
 479  * callback parameter. The caller is responsible for properly allocating and
 480  * freeing it.
 481  *
 482  * When registering a callback, the transaction must be already created, but
 483  * it cannot be committed or aborted. It can be assigned to a txg or not.
 484  *
 485  * The callback will be called after the transaction has been safely written
 486  * to stable storage and will also be called if the dmu_tx is aborted.
 487  * If there is any error which prevents the transaction from being committed to
 488  * disk, the callback will be called with a value of error != 0.
 489  */
 490 typedef void dmu_tx_callback_func_t(void *dcb_data, int error);
 491 
 492 void dmu_tx_callback_register(dmu_tx_t *tx, dmu_tx_callback_func_t *dcb_func,
 493     void *dcb_data);
 494 
 495 /*
 496  * Free up the data blocks for a defined range of a file.  If size is
 497  * zero, the range from offset to end-of-file is freed.
 498  */
 499 int dmu_free_range(objset_t *os, uint64_t object, uint64_t offset,
 500         uint64_t size, dmu_tx_t *tx);
 501 int dmu_free_long_range(objset_t *os, uint64_t object, uint64_t offset,
 502         uint64_t size);
 503 int dmu_free_object(objset_t *os, uint64_t object);
 504 
 505 /*
 506  * Convenience functions.
 507  *
 508  * Canfail routines will return 0 on success, or an errno if there is a
 509  * nonrecoverable I/O error.
 510  */
 511 #define DMU_READ_PREFETCH       0 /* prefetch */
 512 #define DMU_READ_NO_PREFETCH    1 /* don't prefetch */
 513 int dmu_read(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
 514         void *buf, uint32_t flags);
 515 void dmu_write(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
 516         const void *buf, dmu_tx_t *tx);
 517 void dmu_prealloc(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
 
 
 547 
 548 typedef struct dmu_object_info {
 549         /* All sizes are in bytes unless otherwise indicated. */
 550         uint32_t doi_data_block_size;
 551         uint32_t doi_metadata_block_size;
 552         dmu_object_type_t doi_type;
 553         dmu_object_type_t doi_bonus_type;
 554         uint64_t doi_bonus_size;
 555         uint8_t doi_indirection;                /* 2 = dnode->indirect->data */
 556         uint8_t doi_checksum;
 557         uint8_t doi_compress;
 558         uint8_t doi_pad[5];
 559         uint64_t doi_physical_blocks_512;       /* data + metadata, 512b blks */
 560         uint64_t doi_max_offset;
 561         uint64_t doi_fill_count;                /* number of non-empty blocks */
 562 } dmu_object_info_t;
 563 
 564 typedef void arc_byteswap_func_t(void *buf, size_t size);
 565 
 566 typedef struct dmu_object_type_info {
 567         arc_byteswap_func_t     *ot_byteswap;
 568         boolean_t               ot_metadata;
 569         char                    *ot_name;
 570 } dmu_object_type_info_t;
 571 
 572 extern const dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES];
 573 
 574 /*
 575  * Get information on a DMU object.
 576  *
 577  * Return 0 on success or ENOENT if object is not allocated.
 578  *
 579  * If doi is NULL, just indicates whether the object exists.
 580  */
 581 int dmu_object_info(objset_t *os, uint64_t object, dmu_object_info_t *doi);
 582 void dmu_object_info_from_dnode(struct dnode *dn, dmu_object_info_t *doi);
 583 void dmu_object_info_from_db(dmu_buf_t *db, dmu_object_info_t *doi);
 584 void dmu_object_size_from_db(dmu_buf_t *db, uint32_t *blksize,
 585     u_longlong_t *nblk512);
 586 
 587 typedef struct dmu_objset_stats {
 588         uint64_t dds_num_clones; /* number of clones of this */
 589         uint64_t dds_creation_txg;
 590         uint64_t dds_guid;
 591         dmu_objset_type_t dds_type;
 592         uint8_t dds_is_snapshot;
 
 | 
   1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  24  * Copyright (c) 2012 by Delphix. All rights reserved.
  25  * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
  26  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
  27  */
  28 
  29 /* Portions Copyright 2010 Robert Milkowski */
  30 
  31 #ifndef _SYS_DMU_H
  32 #define _SYS_DMU_H
  33 
  34 /*
  35  * This file describes the interface that the DMU provides for its
  36  * consumers.
  37  *
  38  * The DMU also interacts with the SPA.  That interface is described in
  39  * dmu_spa.h.
  40  */
  41 
  42 #include <sys/inttypes.h>
  43 #include <sys/types.h>
  44 #include <sys/param.h>
 
 
  57 struct zilog;
  58 struct zio;
  59 struct blkptr;
  60 struct zap_cursor;
  61 struct dsl_dataset;
  62 struct dsl_pool;
  63 struct dnode;
  64 struct drr_begin;
  65 struct drr_end;
  66 struct zbookmark;
  67 struct spa;
  68 struct nvlist;
  69 struct arc_buf;
  70 struct zio_prop;
  71 struct sa_handle;
  72 
  73 typedef struct objset objset_t;
  74 typedef struct dmu_tx dmu_tx_t;
  75 typedef struct dsl_dir dsl_dir_t;
  76 
  77 typedef enum dmu_object_byteswap {
  78         DMU_BSWAP_UINT8,
  79         DMU_BSWAP_UINT16,
  80         DMU_BSWAP_UINT32,
  81         DMU_BSWAP_UINT64,
  82         DMU_BSWAP_ZAP,
  83         DMU_BSWAP_DNODE,
  84         DMU_BSWAP_OBJSET,
  85         DMU_BSWAP_ZNODE,
  86         DMU_BSWAP_OLDACL,
  87         DMU_BSWAP_ACL,
  88         /*
  89          * Allocating a new byteswap type number makes the on-disk format
  90          * incompatible with any other format that uses the same number.
  91          *
  92          * Data can usually be structured to work with one of the
  93          * DMU_BSWAP_UINT* or DMU_BSWAP_ZAP types.
  94          */
  95         DMU_BSWAP_NUMFUNCS
  96 } dmu_object_byteswap_t;
  97 
  98 #define DMU_OT_NEWTYPE 0x80
  99 #define DMU_OT_METADATA 0x40
 100 #define DMU_OT_BYTESWAP_MASK 0x3f
 101 
 102 /*
 103  * Defines a uint8_t object type. Object types specify if the data
 104  * in the object is metadata (boolean) and how to byteswap the data
 105  * (dmu_object_byteswap_t).
 106  */
 107 #define DMU_OT(byteswap, metadata) \
 108         (DMU_OT_NEWTYPE | \
 109         ((metadata) ? DMU_OT_METADATA : 0) | \
 110         ((byteswap) & DMU_OT_BYTESWAP_MASK))
 111 
 112 #define DMU_OT_IS_VALID(ot) (((ot) & DMU_OT_NEWTYPE) ? \
 113         ((ot) & DMU_OT_BYTESWAP_MASK) < DMU_BSWAP_NUMFUNCS : \
 114         (ot) < DMU_OT_NUMTYPES)
 115 
 116 #define DMU_OT_IS_METADATA(ot) (((ot) & DMU_OT_NEWTYPE) ? \
 117         ((ot) & DMU_OT_METADATA) : \
 118         dmu_ot[(ot)].ot_metadata)
 119 
 120 #define DMU_OT_BYTESWAP(ot) (((ot) & DMU_OT_NEWTYPE) ? \
 121         ((ot) & DMU_OT_BYTESWAP_MASK) : \
 122         dmu_ot[(ot)].ot_byteswap)
 123 
 124 typedef enum dmu_object_type {
 125         DMU_OT_NONE,
 126         /* general: */
 127         DMU_OT_OBJECT_DIRECTORY,        /* ZAP */
 128         DMU_OT_OBJECT_ARRAY,            /* UINT64 */
 129         DMU_OT_PACKED_NVLIST,           /* UINT8 (XDR by nvlist_pack/unpack) */
 130         DMU_OT_PACKED_NVLIST_SIZE,      /* UINT64 */
 131         DMU_OT_BPOBJ,                   /* UINT64 */
 132         DMU_OT_BPOBJ_HDR,               /* UINT64 */
 133         /* spa: */
 134         DMU_OT_SPACE_MAP_HEADER,        /* UINT64 */
 135         DMU_OT_SPACE_MAP,               /* UINT64 */
 136         /* zil: */
 137         DMU_OT_INTENT_LOG,              /* UINT64 */
 138         /* dmu: */
 139         DMU_OT_DNODE,                   /* DNODE */
 140         DMU_OT_OBJSET,                  /* OBJSET */
 141         /* dsl: */
 142         DMU_OT_DSL_DIR,                 /* UINT64 */
 143         DMU_OT_DSL_DIR_CHILD_MAP,       /* ZAP */
 
 168         DMU_OT_SYSACL,                  /* SYSACL */
 169         DMU_OT_FUID,                    /* FUID table (Packed NVLIST UINT8) */
 170         DMU_OT_FUID_SIZE,               /* FUID table size UINT64 */
 171         DMU_OT_NEXT_CLONES,             /* ZAP */
 172         DMU_OT_SCAN_QUEUE,              /* ZAP */
 173         DMU_OT_USERGROUP_USED,          /* ZAP */
 174         DMU_OT_USERGROUP_QUOTA,         /* ZAP */
 175         DMU_OT_USERREFS,                /* ZAP */
 176         DMU_OT_DDT_ZAP,                 /* ZAP */
 177         DMU_OT_DDT_STATS,               /* ZAP */
 178         DMU_OT_SA,                      /* System attr */
 179         DMU_OT_SA_MASTER_NODE,          /* ZAP */
 180         DMU_OT_SA_ATTR_REGISTRATION,    /* ZAP */
 181         DMU_OT_SA_ATTR_LAYOUTS,         /* ZAP */
 182         DMU_OT_SCAN_XLATE,              /* ZAP */
 183         DMU_OT_DEDUP,                   /* fake dedup BP from ddt_bp_create() */
 184         DMU_OT_DEADLIST,                /* ZAP */
 185         DMU_OT_DEADLIST_HDR,            /* UINT64 */
 186         DMU_OT_DSL_CLONES,              /* ZAP */
 187         DMU_OT_BPOBJ_SUBOBJ,            /* UINT64 */
 188         /*
 189          * Do not allocate new object types here. Doing so makes the on-disk
 190          * format incompatible with any other format that uses the same object
 191          * type number.
 192          *
 193          * When creating an object which does not have one of the above types
 194          * use the DMU_OTN_* type with the correct byteswap and metadata
 195          * values.
 196          *
 197          * The DMU_OTN_* types do not have entries in the dmu_ot table,
 198          * use the DMU_OT_IS_METDATA() and DMU_OT_BYTESWAP() macros instead
 199          * of indexing into dmu_ot directly (this works for both DMU_OT_* types
 200          * and DMU_OTN_* types).
 201          */
 202         DMU_OT_NUMTYPES,
 203 
 204         /*
 205          * Names for valid types declared with DMU_OT().
 206          */
 207         DMU_OTN_UINT8_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE),
 208         DMU_OTN_UINT8_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE),
 209         DMU_OTN_UINT16_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE),
 210         DMU_OTN_UINT16_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE),
 211         DMU_OTN_UINT32_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE),
 212         DMU_OTN_UINT32_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE),
 213         DMU_OTN_UINT64_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE),
 214         DMU_OTN_UINT64_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE),
 215         DMU_OTN_ZAP_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE),
 216         DMU_OTN_ZAP_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE),
 217 } dmu_object_type_t;
 218 
 219 typedef enum dmu_objset_type {
 220         DMU_OST_NONE,
 221         DMU_OST_META,
 222         DMU_OST_ZFS,
 223         DMU_OST_ZVOL,
 224         DMU_OST_OTHER,                  /* For testing only! */
 225         DMU_OST_ANY,                    /* Be careful! */
 226         DMU_OST_NUMTYPES
 227 } dmu_objset_type_t;
 228 
 229 void byteswap_uint64_array(void *buf, size_t size);
 230 void byteswap_uint32_array(void *buf, size_t size);
 231 void byteswap_uint16_array(void *buf, size_t size);
 232 void byteswap_uint8_array(void *buf, size_t size);
 233 void zap_byteswap(void *buf, size_t size);
 234 void zfs_oldacl_byteswap(void *buf, size_t size);
 235 void zfs_acl_byteswap(void *buf, size_t size);
 236 void zfs_znode_byteswap(void *buf, size_t size);
 
 276 int dmu_objset_rename(const char *name, const char *newname,
 277     boolean_t recursive);
 278 int dmu_objset_find(char *name, int func(const char *, void *), void *arg,
 279     int flags);
 280 void dmu_objset_byteswap(void *buf, size_t size);
 281 
 282 typedef struct dmu_buf {
 283         uint64_t db_object;             /* object that this buffer is part of */
 284         uint64_t db_offset;             /* byte offset in this object */
 285         uint64_t db_size;               /* size of buffer in bytes */
 286         void *db_data;                  /* data in buffer */
 287 } dmu_buf_t;
 288 
 289 typedef void dmu_buf_evict_func_t(struct dmu_buf *db, void *user_ptr);
 290 
 291 /*
 292  * The names of zap entries in the DIRECTORY_OBJECT of the MOS.
 293  */
 294 #define DMU_POOL_DIRECTORY_OBJECT       1
 295 #define DMU_POOL_CONFIG                 "config"
 296 #define DMU_POOL_FEATURES_FOR_WRITE     "features_for_write"
 297 #define DMU_POOL_FEATURES_FOR_READ      "features_for_read"
 298 #define DMU_POOL_FEATURE_DESCRIPTIONS   "feature_descriptions"
 299 #define DMU_POOL_ROOT_DATASET           "root_dataset"
 300 #define DMU_POOL_SYNC_BPOBJ             "sync_bplist"
 301 #define DMU_POOL_ERRLOG_SCRUB           "errlog_scrub"
 302 #define DMU_POOL_ERRLOG_LAST            "errlog_last"
 303 #define DMU_POOL_SPARES                 "spares"
 304 #define DMU_POOL_DEFLATE                "deflate"
 305 #define DMU_POOL_HISTORY                "history"
 306 #define DMU_POOL_PROPS                  "pool_props"
 307 #define DMU_POOL_L2CACHE                "l2cache"
 308 #define DMU_POOL_TMP_USERREFS           "tmp_userrefs"
 309 #define DMU_POOL_DDT                    "DDT-%s-%s-%s"
 310 #define DMU_POOL_DDT_STATS              "DDT-statistics"
 311 #define DMU_POOL_CREATION_VERSION       "creation_version"
 312 #define DMU_POOL_SCAN                   "scan"
 313 #define DMU_POOL_FREE_BPOBJ             "free_bpobj"
 314 #define DMU_POOL_BPTREE_OBJ             "bptree_obj"
 315 
 316 /*
 317  * Allocate an object from this objset.  The range of object numbers
 318  * available is (0, DN_MAX_OBJECT).  Object 0 is the meta-dnode.
 319  *
 320  * The transaction must be assigned to a txg.  The newly allocated
 321  * object will be "held" in the transaction (ie. you can modify the
 322  * newly allocated object in this transaction).
 323  *
 324  * dmu_object_alloc() chooses an object and returns it in *objectp.
 325  *
 326  * dmu_object_claim() allocates a specific object number.  If that
 327  * number is already allocated, it fails and returns EEXIST.
 328  *
 329  * Return 0 on success, or ENOSPC or EEXIST as specified above.
 330  */
 331 uint64_t dmu_object_alloc(objset_t *os, dmu_object_type_t ot,
 332     int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx);
 333 int dmu_object_claim(objset_t *os, uint64_t object, dmu_object_type_t ot,
 334     int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx);
 
 555  *
 556  * dcb_data is a pointer to caller private data that is passed on as a
 557  * callback parameter. The caller is responsible for properly allocating and
 558  * freeing it.
 559  *
 560  * When registering a callback, the transaction must be already created, but
 561  * it cannot be committed or aborted. It can be assigned to a txg or not.
 562  *
 563  * The callback will be called after the transaction has been safely written
 564  * to stable storage and will also be called if the dmu_tx is aborted.
 565  * If there is any error which prevents the transaction from being committed to
 566  * disk, the callback will be called with a value of error != 0.
 567  */
 568 typedef void dmu_tx_callback_func_t(void *dcb_data, int error);
 569 
 570 void dmu_tx_callback_register(dmu_tx_t *tx, dmu_tx_callback_func_t *dcb_func,
 571     void *dcb_data);
 572 
 573 /*
 574  * Free up the data blocks for a defined range of a file.  If size is
 575  * -1, the range from offset to end-of-file is freed.
 576  */
 577 int dmu_free_range(objset_t *os, uint64_t object, uint64_t offset,
 578         uint64_t size, dmu_tx_t *tx);
 579 int dmu_free_long_range(objset_t *os, uint64_t object, uint64_t offset,
 580         uint64_t size);
 581 int dmu_free_object(objset_t *os, uint64_t object);
 582 
 583 /*
 584  * Convenience functions.
 585  *
 586  * Canfail routines will return 0 on success, or an errno if there is a
 587  * nonrecoverable I/O error.
 588  */
 589 #define DMU_READ_PREFETCH       0 /* prefetch */
 590 #define DMU_READ_NO_PREFETCH    1 /* don't prefetch */
 591 int dmu_read(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
 592         void *buf, uint32_t flags);
 593 void dmu_write(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
 594         const void *buf, dmu_tx_t *tx);
 595 void dmu_prealloc(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
 
 
 625 
 626 typedef struct dmu_object_info {
 627         /* All sizes are in bytes unless otherwise indicated. */
 628         uint32_t doi_data_block_size;
 629         uint32_t doi_metadata_block_size;
 630         dmu_object_type_t doi_type;
 631         dmu_object_type_t doi_bonus_type;
 632         uint64_t doi_bonus_size;
 633         uint8_t doi_indirection;                /* 2 = dnode->indirect->data */
 634         uint8_t doi_checksum;
 635         uint8_t doi_compress;
 636         uint8_t doi_pad[5];
 637         uint64_t doi_physical_blocks_512;       /* data + metadata, 512b blks */
 638         uint64_t doi_max_offset;
 639         uint64_t doi_fill_count;                /* number of non-empty blocks */
 640 } dmu_object_info_t;
 641 
 642 typedef void arc_byteswap_func_t(void *buf, size_t size);
 643 
 644 typedef struct dmu_object_type_info {
 645         dmu_object_byteswap_t   ot_byteswap;
 646         boolean_t               ot_metadata;
 647         char                    *ot_name;
 648 } dmu_object_type_info_t;
 649 
 650 typedef struct dmu_object_byteswap_info {
 651         arc_byteswap_func_t     *ob_func;
 652         char                    *ob_name;
 653 } dmu_object_byteswap_info_t;
 654 
 655 extern const dmu_object_type_info_t dmu_ot[DMU_OT_NUMTYPES];
 656 extern const dmu_object_byteswap_info_t dmu_ot_byteswap[DMU_BSWAP_NUMFUNCS];
 657 
 658 /*
 659  * Get information on a DMU object.
 660  *
 661  * Return 0 on success or ENOENT if object is not allocated.
 662  *
 663  * If doi is NULL, just indicates whether the object exists.
 664  */
 665 int dmu_object_info(objset_t *os, uint64_t object, dmu_object_info_t *doi);
 666 void dmu_object_info_from_dnode(struct dnode *dn, dmu_object_info_t *doi);
 667 void dmu_object_info_from_db(dmu_buf_t *db, dmu_object_info_t *doi);
 668 void dmu_object_size_from_db(dmu_buf_t *db, uint32_t *blksize,
 669     u_longlong_t *nblk512);
 670 
 671 typedef struct dmu_objset_stats {
 672         uint64_t dds_num_clones; /* number of clones of this */
 673         uint64_t dds_creation_txg;
 674         uint64_t dds_guid;
 675         dmu_objset_type_t dds_type;
 676         uint8_t dds_is_snapshot;
 
 |