Print this page
2882 implement libzfs_core
2883 changing "canmount" property to "on" should not always remount dataset
2900 "zfs snapshot" should be able to create multiple, arbitrary snapshots at once
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Chris Siden <christopher.siden@delphix.com>
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Bill Pijewski <wdp@joyent.com>
Reviewed by: Dan Kruchinin <dan.kruchinin@gmail.com>


  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>
  45 #include <sys/cred.h>
  46 #include <sys/time.h>

  47 
  48 #ifdef  __cplusplus
  49 extern "C" {
  50 #endif
  51 
  52 struct uio;
  53 struct xuio;
  54 struct page;
  55 struct vnode;
  56 struct spa;
  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;


 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);
 237 
 238 #define DS_FIND_SNAPSHOTS       (1<<0)
 239 #define DS_FIND_CHILDREN        (1<<1)
 240 
 241 /*
 242  * The maximum number of bytes that can be accessed as part of one
 243  * operation, including metadata.
 244  */
 245 #define DMU_MAX_ACCESS (10<<20) /* 10MB */
 246 #define DMU_MAX_DELETEBLKCNT (20480) /* ~5MB of indirect blocks */
 247 
 248 #define DMU_USERUSED_OBJECT     (-1ULL)


 253  * artificial blkids for bonus buffer and spill blocks
 254  */
 255 #define DMU_BONUS_BLKID         (-1ULL)
 256 #define DMU_SPILL_BLKID         (-2ULL)
 257 /*
 258  * Public routines to create, destroy, open, and close objsets.
 259  */
 260 int dmu_objset_hold(const char *name, void *tag, objset_t **osp);
 261 int dmu_objset_own(const char *name, dmu_objset_type_t type,
 262     boolean_t readonly, void *tag, objset_t **osp);
 263 void dmu_objset_rele(objset_t *os, void *tag);
 264 void dmu_objset_disown(objset_t *os, void *tag);
 265 int dmu_objset_open_ds(struct dsl_dataset *ds, objset_t **osp);
 266 
 267 int dmu_objset_evict_dbufs(objset_t *os);
 268 int dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags,
 269     void (*func)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx), void *arg);
 270 int dmu_objset_clone(const char *name, struct dsl_dataset *clone_origin,
 271     uint64_t flags);
 272 int dmu_objset_destroy(const char *name, boolean_t defer);
 273 int dmu_snapshots_destroy_nvl(struct nvlist *snaps, boolean_t defer, char *);
 274 int dmu_objset_snapshot(char *fsname, char *snapname, char *tag,
 275     struct nvlist *props, boolean_t recursive, boolean_t temporary, int fd);


 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"


 772 int dmu_sync(struct zio *zio, uint64_t txg, dmu_sync_cb_t *done, zgd_t *zgd);
 773 
 774 /*
 775  * Find the next hole or data block in file starting at *off
 776  * Return found offset in *off. Return ESRCH for end of file.
 777  */
 778 int dmu_offset_next(objset_t *os, uint64_t object, boolean_t hole,
 779     uint64_t *off);
 780 
 781 /*
 782  * Initial setup and final teardown.
 783  */
 784 extern void dmu_init(void);
 785 extern void dmu_fini(void);
 786 
 787 typedef void (*dmu_traverse_cb_t)(objset_t *os, void *arg, struct blkptr *bp,
 788     uint64_t object, uint64_t offset, int len);
 789 void dmu_traverse_objset(objset_t *os, uint64_t txg_start,
 790     dmu_traverse_cb_t cb, void *arg);
 791 
 792 int dmu_send(objset_t *tosnap, objset_t *fromsnap, boolean_t fromorigin,
 793     int outfd, struct vnode *vp, offset_t *off);
 794 int dmu_send_estimate(objset_t *tosnap, objset_t *fromsnap, boolean_t fromorign,
 795     uint64_t *sizep);
 796 
 797 typedef struct dmu_recv_cookie {
 798         /*
 799          * This structure is opaque!
 800          *
 801          * If logical and real are different, we are recving the stream
 802          * into the "real" temporary clone, and then switching it with
 803          * the "logical" target.
 804          */
 805         struct dsl_dataset *drc_logical_ds;
 806         struct dsl_dataset *drc_real_ds;
 807         struct drr_begin *drc_drrb;
 808         char *drc_tosnap;
 809         char *drc_top_ds;
 810         boolean_t drc_newfs;
 811         boolean_t drc_force;
 812         struct avl_tree *drc_guid_to_ds_map;
 813 } dmu_recv_cookie_t;
 814 
 815 int dmu_recv_begin(char *tofs, char *tosnap, char *topds, struct drr_begin *,


  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>
  45 #include <sys/cred.h>
  46 #include <sys/time.h>
  47 #include <sys/fs/zfs.h>
  48 
  49 #ifdef  __cplusplus
  50 extern "C" {
  51 #endif
  52 
  53 struct uio;
  54 struct xuio;
  55 struct page;
  56 struct vnode;
  57 struct spa;
  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;


 200          * of indexing into dmu_ot directly (this works for both DMU_OT_* types
 201          * and DMU_OTN_* types).
 202          */
 203         DMU_OT_NUMTYPES,
 204 
 205         /*
 206          * Names for valid types declared with DMU_OT().
 207          */
 208         DMU_OTN_UINT8_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE),
 209         DMU_OTN_UINT8_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE),
 210         DMU_OTN_UINT16_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE),
 211         DMU_OTN_UINT16_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE),
 212         DMU_OTN_UINT32_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE),
 213         DMU_OTN_UINT32_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE),
 214         DMU_OTN_UINT64_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE),
 215         DMU_OTN_UINT64_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE),
 216         DMU_OTN_ZAP_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE),
 217         DMU_OTN_ZAP_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE),
 218 } dmu_object_type_t;
 219 










 220 void byteswap_uint64_array(void *buf, size_t size);
 221 void byteswap_uint32_array(void *buf, size_t size);
 222 void byteswap_uint16_array(void *buf, size_t size);
 223 void byteswap_uint8_array(void *buf, size_t size);
 224 void zap_byteswap(void *buf, size_t size);
 225 void zfs_oldacl_byteswap(void *buf, size_t size);
 226 void zfs_acl_byteswap(void *buf, size_t size);
 227 void zfs_znode_byteswap(void *buf, size_t size);
 228 
 229 #define DS_FIND_SNAPSHOTS       (1<<0)
 230 #define DS_FIND_CHILDREN        (1<<1)
 231 
 232 /*
 233  * The maximum number of bytes that can be accessed as part of one
 234  * operation, including metadata.
 235  */
 236 #define DMU_MAX_ACCESS (10<<20) /* 10MB */
 237 #define DMU_MAX_DELETEBLKCNT (20480) /* ~5MB of indirect blocks */
 238 
 239 #define DMU_USERUSED_OBJECT     (-1ULL)


 244  * artificial blkids for bonus buffer and spill blocks
 245  */
 246 #define DMU_BONUS_BLKID         (-1ULL)
 247 #define DMU_SPILL_BLKID         (-2ULL)
 248 /*
 249  * Public routines to create, destroy, open, and close objsets.
 250  */
 251 int dmu_objset_hold(const char *name, void *tag, objset_t **osp);
 252 int dmu_objset_own(const char *name, dmu_objset_type_t type,
 253     boolean_t readonly, void *tag, objset_t **osp);
 254 void dmu_objset_rele(objset_t *os, void *tag);
 255 void dmu_objset_disown(objset_t *os, void *tag);
 256 int dmu_objset_open_ds(struct dsl_dataset *ds, objset_t **osp);
 257 
 258 int dmu_objset_evict_dbufs(objset_t *os);
 259 int dmu_objset_create(const char *name, dmu_objset_type_t type, uint64_t flags,
 260     void (*func)(objset_t *os, void *arg, cred_t *cr, dmu_tx_t *tx), void *arg);
 261 int dmu_objset_clone(const char *name, struct dsl_dataset *clone_origin,
 262     uint64_t flags);
 263 int dmu_objset_destroy(const char *name, boolean_t defer);
 264 int dmu_snapshots_destroy_nvl(struct nvlist *snaps, boolean_t defer,
 265     struct nvlist *errlist);
 266 int dmu_objset_snapshot(struct nvlist *snaps, struct nvlist *, struct nvlist *);
 267 int dmu_objset_snapshot_one(const char *fsname, const char *snapname);
 268 int dmu_objset_snapshot_tmp(const char *, const char *, int);
 269 int dmu_objset_rename(const char *name, const char *newname,
 270     boolean_t recursive);
 271 int dmu_objset_find(char *name, int func(const char *, void *), void *arg,
 272     int flags);
 273 void dmu_objset_byteswap(void *buf, size_t size);
 274 
 275 typedef struct dmu_buf {
 276         uint64_t db_object;             /* object that this buffer is part of */
 277         uint64_t db_offset;             /* byte offset in this object */
 278         uint64_t db_size;               /* size of buffer in bytes */
 279         void *db_data;                  /* data in buffer */
 280 } dmu_buf_t;
 281 
 282 typedef void dmu_buf_evict_func_t(struct dmu_buf *db, void *user_ptr);
 283 
 284 /*
 285  * The names of zap entries in the DIRECTORY_OBJECT of the MOS.
 286  */
 287 #define DMU_POOL_DIRECTORY_OBJECT       1
 288 #define DMU_POOL_CONFIG                 "config"


 765 int dmu_sync(struct zio *zio, uint64_t txg, dmu_sync_cb_t *done, zgd_t *zgd);
 766 
 767 /*
 768  * Find the next hole or data block in file starting at *off
 769  * Return found offset in *off. Return ESRCH for end of file.
 770  */
 771 int dmu_offset_next(objset_t *os, uint64_t object, boolean_t hole,
 772     uint64_t *off);
 773 
 774 /*
 775  * Initial setup and final teardown.
 776  */
 777 extern void dmu_init(void);
 778 extern void dmu_fini(void);
 779 
 780 typedef void (*dmu_traverse_cb_t)(objset_t *os, void *arg, struct blkptr *bp,
 781     uint64_t object, uint64_t offset, int len);
 782 void dmu_traverse_objset(objset_t *os, uint64_t txg_start,
 783     dmu_traverse_cb_t cb, void *arg);
 784 
 785 int dmu_send(objset_t *tosnap, objset_t *fromsnap,
 786     int outfd, struct vnode *vp, offset_t *off);
 787 int dmu_send_estimate(objset_t *tosnap, objset_t *fromsnap, uint64_t *sizep);

 788 
 789 typedef struct dmu_recv_cookie {
 790         /*
 791          * This structure is opaque!
 792          *
 793          * If logical and real are different, we are recving the stream
 794          * into the "real" temporary clone, and then switching it with
 795          * the "logical" target.
 796          */
 797         struct dsl_dataset *drc_logical_ds;
 798         struct dsl_dataset *drc_real_ds;
 799         struct drr_begin *drc_drrb;
 800         char *drc_tosnap;
 801         char *drc_top_ds;
 802         boolean_t drc_newfs;
 803         boolean_t drc_force;
 804         struct avl_tree *drc_guid_to_ds_map;
 805 } dmu_recv_cookie_t;
 806 
 807 int dmu_recv_begin(char *tofs, char *tosnap, char *topds, struct drr_begin *,