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>


  37 #include <sys/varargs.h>
  38 #include <sys/fs/zfs.h>
  39 #include <sys/avl.h>
  40 #include <ucred.h>
  41 
  42 #ifdef  __cplusplus
  43 extern "C" {
  44 #endif
  45 
  46 /*
  47  * Miscellaneous ZFS constants
  48  */
  49 #define ZFS_MAXNAMELEN          MAXNAMELEN
  50 #define ZPOOL_MAXNAMELEN        MAXNAMELEN
  51 #define ZFS_MAXPROPLEN          MAXPATHLEN
  52 #define ZPOOL_MAXPROPLEN        MAXPATHLEN
  53 
  54 /*
  55  * libzfs errors
  56  */
  57 enum {

  58         EZFS_NOMEM = 2000,      /* out of memory */
  59         EZFS_BADPROP,           /* invalid property value */
  60         EZFS_PROPREADONLY,      /* cannot set readonly property */
  61         EZFS_PROPTYPE,          /* property does not apply to dataset type */
  62         EZFS_PROPNONINHERIT,    /* property is not inheritable */
  63         EZFS_PROPSPACE,         /* bad quota or reservation */
  64         EZFS_BADTYPE,           /* dataset is not of appropriate type */
  65         EZFS_BUSY,              /* pool or dataset is busy */
  66         EZFS_EXISTS,            /* pool or dataset already exists */
  67         EZFS_NOENT,             /* no such pool or dataset */
  68         EZFS_BADSTREAM,         /* bad backup stream */
  69         EZFS_DSREADONLY,        /* dataset is readonly */
  70         EZFS_VOLTOOBIG,         /* volume is too large for 32-bit system */
  71         EZFS_INVALIDNAME,       /* invalid dataset name */
  72         EZFS_BADRESTORE,        /* unable to restore to destination */
  73         EZFS_BADBACKUP,         /* backup failed */
  74         EZFS_BADTARGET,         /* bad attach/detach/replace target */
  75         EZFS_NODEVICE,          /* no such device in pool */
  76         EZFS_BADDEV,            /* invalid device to add */
  77         EZFS_NOREPLICAS,        /* no valid replicas */


 109         EZFS_UNSHARESMBFAILED,  /* failed to unshare over smb */
 110         EZFS_SHARESMBFAILED,    /* failed to share over smb */
 111         EZFS_BADCACHE,          /* bad cache file */
 112         EZFS_ISL2CACHE,         /* device is for the level 2 ARC */
 113         EZFS_VDEVNOTSUP,        /* unsupported vdev type */
 114         EZFS_NOTSUP,            /* ops not supported on this dataset */
 115         EZFS_ACTIVE_SPARE,      /* pool has active shared spare devices */
 116         EZFS_UNPLAYED_LOGS,     /* log device has unplayed logs */
 117         EZFS_REFTAG_RELE,       /* snapshot release: tag not found */
 118         EZFS_REFTAG_HOLD,       /* snapshot hold: tag already exists */
 119         EZFS_TAGTOOLONG,        /* snapshot hold/rele: tag too long */
 120         EZFS_PIPEFAILED,        /* pipe create failed */
 121         EZFS_THREADCREATEFAILED, /* thread create failed */
 122         EZFS_POSTSPLIT_ONLINE,  /* onlining a disk after splitting it */
 123         EZFS_SCRUBBING,         /* currently scrubbing */
 124         EZFS_NO_SCRUB,          /* no active scrub */
 125         EZFS_DIFF,              /* general failure of zfs diff */
 126         EZFS_DIFFDATA,          /* bad zfs diff data */
 127         EZFS_POOLREADONLY,      /* pool is in read-only mode */
 128         EZFS_UNKNOWN
 129 };
 130 
 131 /*
 132  * The following data structures are all part
 133  * of the zfs_allow_t data structure which is
 134  * used for printing 'allow' permissions.
 135  * It is a linked list of zfs_allow_t's which
 136  * then contain avl tree's for user/group/sets/...
 137  * and each one of the entries in those trees have
 138  * avl tree's for the permissions they belong to and
 139  * whether they are local,descendent or local+descendent
 140  * permissions.  The AVL trees are used primarily for
 141  * sorting purposes, but also so that we can quickly find
 142  * a given user and or permission.
 143  */
 144 typedef struct zfs_perm_node {
 145         avl_node_t z_node;
 146         char z_pname[MAXPATHLEN];
 147 } zfs_perm_node_t;
 148 
 149 typedef struct zfs_allow_node {


 165 } zfs_allow_t;
 166 
 167 /*
 168  * Basic handle types
 169  */
 170 typedef struct zfs_handle zfs_handle_t;
 171 typedef struct zpool_handle zpool_handle_t;
 172 typedef struct libzfs_handle libzfs_handle_t;
 173 
 174 /*
 175  * Library initialization
 176  */
 177 extern libzfs_handle_t *libzfs_init(void);
 178 extern void libzfs_fini(libzfs_handle_t *);
 179 
 180 extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
 181 extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
 182 
 183 extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
 184 



 185 extern int libzfs_errno(libzfs_handle_t *);
 186 extern const char *libzfs_error_action(libzfs_handle_t *);
 187 extern const char *libzfs_error_description(libzfs_handle_t *);
 188 extern void libzfs_mnttab_init(libzfs_handle_t *);
 189 extern void libzfs_mnttab_fini(libzfs_handle_t *);
 190 extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t);
 191 extern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
 192     struct mnttab *);
 193 extern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
 194     const char *, const char *);
 195 extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
 196 
 197 /*
 198  * Basic handle functions
 199  */
 200 extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
 201 extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
 202 extern void zpool_close(zpool_handle_t *);
 203 extern const char *zpool_get_name(zpool_handle_t *);
 204 extern int zpool_get_state(zpool_handle_t *);
 205 extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
 206 extern void zpool_free_handles(libzfs_handle_t *);
 207 
 208 /*
 209  * Iterate over all active pools in the system.
 210  */
 211 typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
 212 extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
 213 
 214 /*
 215  * Functions to create and destroy pools
 216  */
 217 extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
 218     nvlist_t *, nvlist_t *);
 219 extern int zpool_destroy(zpool_handle_t *);
 220 extern int zpool_add(zpool_handle_t *, nvlist_t *);
 221 
 222 typedef struct splitflags {
 223         /* do not split, but return the config that would be split off */
 224         int dryrun : 1;
 225 
 226         /* after splitting, import the pool */
 227         int import : 1;
 228 } splitflags_t;
 229 
 230 /*
 231  * Functions to manipulate pool and vdev state
 232  */
 233 extern int zpool_scan(zpool_handle_t *, pool_scan_func_t);
 234 extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *);
 235 extern int zpool_reguid(zpool_handle_t *);
 236 extern int zpool_reopen(zpool_handle_t *);
 237 
 238 extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
 239     vdev_state_t *);


 321          * Finally, the following indicates a healthy pool.
 322          */
 323         ZPOOL_STATUS_OK
 324 } zpool_status_t;
 325 
 326 extern zpool_status_t zpool_get_status(zpool_handle_t *, char **);
 327 extern zpool_status_t zpool_import_status(nvlist_t *, char **);
 328 extern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh);
 329 
 330 /*
 331  * Statistics and configuration functions.
 332  */
 333 extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
 334 extern nvlist_t *zpool_get_features(zpool_handle_t *);
 335 extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
 336 extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
 337 
 338 /*
 339  * Import and export functions
 340  */
 341 extern int zpool_export(zpool_handle_t *, boolean_t);
 342 extern int zpool_export_force(zpool_handle_t *);
 343 extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
 344     char *altroot);
 345 extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
 346     nvlist_t *, int);
 347 extern void zpool_print_unsup_feat(nvlist_t *config);
 348 
 349 /*
 350  * Search for pools to import
 351  */
 352 
 353 typedef struct importargs {
 354         char **path;            /* a list of paths to search            */
 355         int paths;              /* number of paths to search            */
 356         char *poolname;         /* name of a pool to find               */
 357         uint64_t guid;          /* guid of a pool to find               */
 358         char *cachefile;        /* cachefile to use for import          */
 359         int can_be_active : 1;  /* can the pool be active?              */
 360         int unique : 1;         /* does 'poolname' already exist?       */
 361         int exists : 1;         /* set on return if pool already exists */
 362 } importargs_t;
 363 
 364 extern nvlist_t *zpool_search_import(libzfs_handle_t *, importargs_t *);
 365 
 366 /* legacy pool search routines */
 367 extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
 368 extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *,
 369     char *, uint64_t);
 370 
 371 /*
 372  * Miscellaneous pool functions
 373  */
 374 struct zfs_cmd;
 375 
 376 extern const char *zfs_history_event_names[LOG_END];
 377 
 378 extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *,
 379     boolean_t verbose);
 380 extern int zpool_upgrade(zpool_handle_t *, uint64_t);
 381 extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
 382 extern int zpool_history_unpack(char *, uint64_t, uint64_t *,
 383     nvlist_t ***, uint_t *);
 384 extern void zpool_set_history_str(const char *subcommand, int argc,
 385     char **argv, char *history_str);
 386 extern int zpool_stage_history(libzfs_handle_t *, const char *);
 387 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
 388     size_t len);
 389 extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
 390 extern int zpool_get_physpath(zpool_handle_t *, char *, size_t);
 391 extern void zpool_explain_recover(libzfs_handle_t *, const char *, int,
 392     nvlist_t *);
 393 
 394 /*
 395  * Basic handle manipulations.  These functions do not create or destroy the
 396  * underlying datasets, only the references to them.
 397  */
 398 extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
 399 extern zfs_handle_t *zfs_handle_dup(zfs_handle_t *);
 400 extern void zfs_close(zfs_handle_t *);
 401 extern zfs_type_t zfs_get_type(const zfs_handle_t *);
 402 extern const char *zfs_get_name(const zfs_handle_t *);
 403 extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
 404 
 405 /*
 406  * Property management functions.  Some functions are shared with the kernel,


 419     nvlist_t *, uint64_t, zfs_handle_t *, const char *);
 420 
 421 extern const char *zfs_prop_to_name(zfs_prop_t);
 422 extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
 423 extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
 424     zprop_source_t *, char *, size_t, boolean_t);
 425 extern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t,
 426     boolean_t);
 427 extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
 428     zprop_source_t *, char *, size_t);
 429 extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname,
 430     uint64_t *propvalue);
 431 extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname,
 432     char *propbuf, int proplen, boolean_t literal);
 433 extern int zfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname,
 434     uint64_t *propvalue);
 435 extern int zfs_prop_get_written(zfs_handle_t *zhp, const char *propname,
 436     char *propbuf, int proplen, boolean_t literal);
 437 extern int zfs_prop_get_feature(zfs_handle_t *zhp, const char *propname,
 438     char *buf, size_t len);
 439 extern int zfs_get_snapused_int(zfs_handle_t *firstsnap, zfs_handle_t *lastsnap,
 440     uint64_t *usedp);
 441 extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
 442 extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t);
 443 extern const char *zfs_prop_values(zfs_prop_t);
 444 extern int zfs_prop_is_string(zfs_prop_t prop);
 445 extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
 446 extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *);
 447 extern nvlist_t *zfs_get_clones_nvl(zfs_handle_t *);
 448 
 449 
 450 typedef struct zprop_list {
 451         int             pl_prop;
 452         char            *pl_user_prop;
 453         struct zprop_list *pl_next;
 454         boolean_t       pl_all;
 455         size_t          pl_width;
 456         size_t          pl_recvd_width;
 457         boolean_t       pl_fixed;
 458 } zprop_list_t;
 459 
 460 extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t);


 536         size_t          cb_alloc;
 537         size_t          cb_used;
 538         boolean_t       cb_verbose;
 539         int             (*cb_getone)(zfs_handle_t *, void *);
 540 } get_all_cb_t;
 541 
 542 void libzfs_add_handle(get_all_cb_t *, zfs_handle_t *);
 543 int libzfs_dataset_cmp(const void *, const void *);
 544 
 545 /*
 546  * Functions to create and destroy datasets.
 547  */
 548 extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
 549     nvlist_t *);
 550 extern int zfs_create_ancestors(libzfs_handle_t *, const char *);
 551 extern int zfs_destroy(zfs_handle_t *, boolean_t);
 552 extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t);
 553 extern int zfs_destroy_snaps_nvl(zfs_handle_t *, nvlist_t *, boolean_t);
 554 extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
 555 extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);


 556 extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
 557 extern int zfs_rename(zfs_handle_t *, const char *, boolean_t, boolean_t);
 558 
 559 typedef struct sendflags {
 560         /* print informational messages (ie, -v was specified) */
 561         boolean_t verbose;
 562 
 563         /* recursive send  (ie, -R) */
 564         boolean_t replicate;
 565 
 566         /* for incrementals, do all intermediate snapshots */
 567         boolean_t doall;
 568 
 569         /* if dataset is a clone, do incremental from its origin */
 570         boolean_t fromorigin;
 571 
 572         /* do deduplication */
 573         boolean_t dedup;
 574 
 575         /* send properties (ie, -p) */




  37 #include <sys/varargs.h>
  38 #include <sys/fs/zfs.h>
  39 #include <sys/avl.h>
  40 #include <ucred.h>
  41 
  42 #ifdef  __cplusplus
  43 extern "C" {
  44 #endif
  45 
  46 /*
  47  * Miscellaneous ZFS constants
  48  */
  49 #define ZFS_MAXNAMELEN          MAXNAMELEN
  50 #define ZPOOL_MAXNAMELEN        MAXNAMELEN
  51 #define ZFS_MAXPROPLEN          MAXPATHLEN
  52 #define ZPOOL_MAXPROPLEN        MAXPATHLEN
  53 
  54 /*
  55  * libzfs errors
  56  */
  57 typedef enum zfs_error {
  58         EZFS_SUCCESS = 0,       /* no error -- success */
  59         EZFS_NOMEM = 2000,      /* out of memory */
  60         EZFS_BADPROP,           /* invalid property value */
  61         EZFS_PROPREADONLY,      /* cannot set readonly property */
  62         EZFS_PROPTYPE,          /* property does not apply to dataset type */
  63         EZFS_PROPNONINHERIT,    /* property is not inheritable */
  64         EZFS_PROPSPACE,         /* bad quota or reservation */
  65         EZFS_BADTYPE,           /* dataset is not of appropriate type */
  66         EZFS_BUSY,              /* pool or dataset is busy */
  67         EZFS_EXISTS,            /* pool or dataset already exists */
  68         EZFS_NOENT,             /* no such pool or dataset */
  69         EZFS_BADSTREAM,         /* bad backup stream */
  70         EZFS_DSREADONLY,        /* dataset is readonly */
  71         EZFS_VOLTOOBIG,         /* volume is too large for 32-bit system */
  72         EZFS_INVALIDNAME,       /* invalid dataset name */
  73         EZFS_BADRESTORE,        /* unable to restore to destination */
  74         EZFS_BADBACKUP,         /* backup failed */
  75         EZFS_BADTARGET,         /* bad attach/detach/replace target */
  76         EZFS_NODEVICE,          /* no such device in pool */
  77         EZFS_BADDEV,            /* invalid device to add */
  78         EZFS_NOREPLICAS,        /* no valid replicas */


 110         EZFS_UNSHARESMBFAILED,  /* failed to unshare over smb */
 111         EZFS_SHARESMBFAILED,    /* failed to share over smb */
 112         EZFS_BADCACHE,          /* bad cache file */
 113         EZFS_ISL2CACHE,         /* device is for the level 2 ARC */
 114         EZFS_VDEVNOTSUP,        /* unsupported vdev type */
 115         EZFS_NOTSUP,            /* ops not supported on this dataset */
 116         EZFS_ACTIVE_SPARE,      /* pool has active shared spare devices */
 117         EZFS_UNPLAYED_LOGS,     /* log device has unplayed logs */
 118         EZFS_REFTAG_RELE,       /* snapshot release: tag not found */
 119         EZFS_REFTAG_HOLD,       /* snapshot hold: tag already exists */
 120         EZFS_TAGTOOLONG,        /* snapshot hold/rele: tag too long */
 121         EZFS_PIPEFAILED,        /* pipe create failed */
 122         EZFS_THREADCREATEFAILED, /* thread create failed */
 123         EZFS_POSTSPLIT_ONLINE,  /* onlining a disk after splitting it */
 124         EZFS_SCRUBBING,         /* currently scrubbing */
 125         EZFS_NO_SCRUB,          /* no active scrub */
 126         EZFS_DIFF,              /* general failure of zfs diff */
 127         EZFS_DIFFDATA,          /* bad zfs diff data */
 128         EZFS_POOLREADONLY,      /* pool is in read-only mode */
 129         EZFS_UNKNOWN
 130 } zfs_error_t;
 131 
 132 /*
 133  * The following data structures are all part
 134  * of the zfs_allow_t data structure which is
 135  * used for printing 'allow' permissions.
 136  * It is a linked list of zfs_allow_t's which
 137  * then contain avl tree's for user/group/sets/...
 138  * and each one of the entries in those trees have
 139  * avl tree's for the permissions they belong to and
 140  * whether they are local,descendent or local+descendent
 141  * permissions.  The AVL trees are used primarily for
 142  * sorting purposes, but also so that we can quickly find
 143  * a given user and or permission.
 144  */
 145 typedef struct zfs_perm_node {
 146         avl_node_t z_node;
 147         char z_pname[MAXPATHLEN];
 148 } zfs_perm_node_t;
 149 
 150 typedef struct zfs_allow_node {


 166 } zfs_allow_t;
 167 
 168 /*
 169  * Basic handle types
 170  */
 171 typedef struct zfs_handle zfs_handle_t;
 172 typedef struct zpool_handle zpool_handle_t;
 173 typedef struct libzfs_handle libzfs_handle_t;
 174 
 175 /*
 176  * Library initialization
 177  */
 178 extern libzfs_handle_t *libzfs_init(void);
 179 extern void libzfs_fini(libzfs_handle_t *);
 180 
 181 extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
 182 extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
 183 
 184 extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
 185 
 186 extern void zfs_save_arguments(int argc, char **, char *, int);
 187 extern int zpool_log_history(libzfs_handle_t *, const char *);
 188 
 189 extern int libzfs_errno(libzfs_handle_t *);
 190 extern const char *libzfs_error_action(libzfs_handle_t *);
 191 extern const char *libzfs_error_description(libzfs_handle_t *);
 192 extern void libzfs_mnttab_init(libzfs_handle_t *);
 193 extern void libzfs_mnttab_fini(libzfs_handle_t *);
 194 extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t);
 195 extern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
 196     struct mnttab *);
 197 extern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
 198     const char *, const char *);
 199 extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
 200 
 201 /*
 202  * Basic handle functions
 203  */
 204 extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
 205 extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
 206 extern void zpool_close(zpool_handle_t *);
 207 extern const char *zpool_get_name(zpool_handle_t *);
 208 extern int zpool_get_state(zpool_handle_t *);
 209 extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
 210 extern void zpool_free_handles(libzfs_handle_t *);
 211 
 212 /*
 213  * Iterate over all active pools in the system.
 214  */
 215 typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
 216 extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
 217 
 218 /*
 219  * Functions to create and destroy pools
 220  */
 221 extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
 222     nvlist_t *, nvlist_t *);
 223 extern int zpool_destroy(zpool_handle_t *, const char *);
 224 extern int zpool_add(zpool_handle_t *, nvlist_t *);
 225 
 226 typedef struct splitflags {
 227         /* do not split, but return the config that would be split off */
 228         int dryrun : 1;
 229 
 230         /* after splitting, import the pool */
 231         int import : 1;
 232 } splitflags_t;
 233 
 234 /*
 235  * Functions to manipulate pool and vdev state
 236  */
 237 extern int zpool_scan(zpool_handle_t *, pool_scan_func_t);
 238 extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *);
 239 extern int zpool_reguid(zpool_handle_t *);
 240 extern int zpool_reopen(zpool_handle_t *);
 241 
 242 extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
 243     vdev_state_t *);


 325          * Finally, the following indicates a healthy pool.
 326          */
 327         ZPOOL_STATUS_OK
 328 } zpool_status_t;
 329 
 330 extern zpool_status_t zpool_get_status(zpool_handle_t *, char **);
 331 extern zpool_status_t zpool_import_status(nvlist_t *, char **);
 332 extern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh);
 333 
 334 /*
 335  * Statistics and configuration functions.
 336  */
 337 extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
 338 extern nvlist_t *zpool_get_features(zpool_handle_t *);
 339 extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
 340 extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
 341 
 342 /*
 343  * Import and export functions
 344  */
 345 extern int zpool_export(zpool_handle_t *, boolean_t, const char *);
 346 extern int zpool_export_force(zpool_handle_t *, const char *);
 347 extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
 348     char *altroot);
 349 extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
 350     nvlist_t *, int);
 351 extern void zpool_print_unsup_feat(nvlist_t *config);
 352 
 353 /*
 354  * Search for pools to import
 355  */
 356 
 357 typedef struct importargs {
 358         char **path;            /* a list of paths to search            */
 359         int paths;              /* number of paths to search            */
 360         char *poolname;         /* name of a pool to find               */
 361         uint64_t guid;          /* guid of a pool to find               */
 362         char *cachefile;        /* cachefile to use for import          */
 363         int can_be_active : 1;  /* can the pool be active?              */
 364         int unique : 1;         /* does 'poolname' already exist?       */
 365         int exists : 1;         /* set on return if pool already exists */
 366 } importargs_t;
 367 
 368 extern nvlist_t *zpool_search_import(libzfs_handle_t *, importargs_t *);
 369 
 370 /* legacy pool search routines */
 371 extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
 372 extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *,
 373     char *, uint64_t);
 374 
 375 /*
 376  * Miscellaneous pool functions
 377  */
 378 struct zfs_cmd;
 379 
 380 extern const char *zfs_history_event_names[];
 381 
 382 extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *,
 383     boolean_t verbose);
 384 extern int zpool_upgrade(zpool_handle_t *, uint64_t);
 385 extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
 386 extern int zpool_history_unpack(char *, uint64_t, uint64_t *,
 387     nvlist_t ***, uint_t *);



 388 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
 389     size_t len);
 390 extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
 391 extern int zpool_get_physpath(zpool_handle_t *, char *, size_t);
 392 extern void zpool_explain_recover(libzfs_handle_t *, const char *, int,
 393     nvlist_t *);
 394 
 395 /*
 396  * Basic handle manipulations.  These functions do not create or destroy the
 397  * underlying datasets, only the references to them.
 398  */
 399 extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
 400 extern zfs_handle_t *zfs_handle_dup(zfs_handle_t *);
 401 extern void zfs_close(zfs_handle_t *);
 402 extern zfs_type_t zfs_get_type(const zfs_handle_t *);
 403 extern const char *zfs_get_name(const zfs_handle_t *);
 404 extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
 405 
 406 /*
 407  * Property management functions.  Some functions are shared with the kernel,


 420     nvlist_t *, uint64_t, zfs_handle_t *, const char *);
 421 
 422 extern const char *zfs_prop_to_name(zfs_prop_t);
 423 extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
 424 extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
 425     zprop_source_t *, char *, size_t, boolean_t);
 426 extern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t,
 427     boolean_t);
 428 extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
 429     zprop_source_t *, char *, size_t);
 430 extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname,
 431     uint64_t *propvalue);
 432 extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname,
 433     char *propbuf, int proplen, boolean_t literal);
 434 extern int zfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname,
 435     uint64_t *propvalue);
 436 extern int zfs_prop_get_written(zfs_handle_t *zhp, const char *propname,
 437     char *propbuf, int proplen, boolean_t literal);
 438 extern int zfs_prop_get_feature(zfs_handle_t *zhp, const char *propname,
 439     char *buf, size_t len);


 440 extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
 441 extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t);
 442 extern const char *zfs_prop_values(zfs_prop_t);
 443 extern int zfs_prop_is_string(zfs_prop_t prop);
 444 extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
 445 extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *);
 446 extern nvlist_t *zfs_get_clones_nvl(zfs_handle_t *);
 447 
 448 
 449 typedef struct zprop_list {
 450         int             pl_prop;
 451         char            *pl_user_prop;
 452         struct zprop_list *pl_next;
 453         boolean_t       pl_all;
 454         size_t          pl_width;
 455         size_t          pl_recvd_width;
 456         boolean_t       pl_fixed;
 457 } zprop_list_t;
 458 
 459 extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t);


 535         size_t          cb_alloc;
 536         size_t          cb_used;
 537         boolean_t       cb_verbose;
 538         int             (*cb_getone)(zfs_handle_t *, void *);
 539 } get_all_cb_t;
 540 
 541 void libzfs_add_handle(get_all_cb_t *, zfs_handle_t *);
 542 int libzfs_dataset_cmp(const void *, const void *);
 543 
 544 /*
 545  * Functions to create and destroy datasets.
 546  */
 547 extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
 548     nvlist_t *);
 549 extern int zfs_create_ancestors(libzfs_handle_t *, const char *);
 550 extern int zfs_destroy(zfs_handle_t *, boolean_t);
 551 extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t);
 552 extern int zfs_destroy_snaps_nvl(zfs_handle_t *, nvlist_t *, boolean_t);
 553 extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
 554 extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
 555 extern int zfs_snapshot_nvl(libzfs_handle_t *hdl, nvlist_t *snaps,
 556     nvlist_t *props);
 557 extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
 558 extern int zfs_rename(zfs_handle_t *, const char *, boolean_t, boolean_t);
 559 
 560 typedef struct sendflags {
 561         /* print informational messages (ie, -v was specified) */
 562         boolean_t verbose;
 563 
 564         /* recursive send  (ie, -R) */
 565         boolean_t replicate;
 566 
 567         /* for incrementals, do all intermediate snapshots */
 568         boolean_t doall;
 569 
 570         /* if dataset is a clone, do incremental from its origin */
 571         boolean_t fromorigin;
 572 
 573         /* do deduplication */
 574         boolean_t dedup;
 575 
 576         /* send properties (ie, -p) */