1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 5441d80aaSlling * Common Development and Distribution License (the "License"). 6441d80aaSlling * You may not use this file except in compliance with the License. 7fa9e4066Sahrens * 8fa9e4066Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fa9e4066Sahrens * or http://www.opensolaris.org/os/licensing. 10fa9e4066Sahrens * See the License for the specific language governing permissions 11fa9e4066Sahrens * and limitations under the License. 12fa9e4066Sahrens * 13fa9e4066Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14fa9e4066Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fa9e4066Sahrens * If applicable, add the following below this CDDL HEADER, with the 16fa9e4066Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17fa9e4066Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18fa9e4066Sahrens * 19fa9e4066Sahrens * CDDL HEADER END 20fa9e4066Sahrens */ 21f3861e1aSahl 22fa9e4066Sahrens /* 2333408eefSLori Alt * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24fa9e4066Sahrens * Use is subject to license terms. 25fa9e4066Sahrens */ 26fa9e4066Sahrens 27fa9e4066Sahrens #ifndef _LIBZFS_H 28fa9e4066Sahrens #define _LIBZFS_H 29fa9e4066Sahrens 30fa9e4066Sahrens #include <assert.h> 31fa9e4066Sahrens #include <libnvpair.h> 32ebedde84SEric Taylor #include <sys/mnttab.h> 33fa9e4066Sahrens #include <sys/param.h> 34fa9e4066Sahrens #include <sys/types.h> 35fa9e4066Sahrens #include <sys/varargs.h> 36fa9e4066Sahrens #include <sys/fs/zfs.h> 37ecd6cf80Smarks #include <sys/avl.h> 38ecd6cf80Smarks #include <ucred.h> 39fa9e4066Sahrens 40fa9e4066Sahrens #ifdef __cplusplus 41fa9e4066Sahrens extern "C" { 42fa9e4066Sahrens #endif 43fa9e4066Sahrens 44fa9e4066Sahrens /* 45fa9e4066Sahrens * Miscellaneous ZFS constants 46fa9e4066Sahrens */ 47fa9e4066Sahrens #define ZFS_MAXNAMELEN MAXNAMELEN 48fa9e4066Sahrens #define ZPOOL_MAXNAMELEN MAXNAMELEN 49fa9e4066Sahrens #define ZFS_MAXPROPLEN MAXPATHLEN 50990b4856Slling #define ZPOOL_MAXPROPLEN MAXPATHLEN 51fa9e4066Sahrens 5299653d4eSeschrock /* 5399653d4eSeschrock * libzfs errors 5499653d4eSeschrock */ 5599653d4eSeschrock enum { 5699653d4eSeschrock EZFS_NOMEM = 2000, /* out of memory */ 5799653d4eSeschrock EZFS_BADPROP, /* invalid property value */ 5899653d4eSeschrock EZFS_PROPREADONLY, /* cannot set readonly property */ 5999653d4eSeschrock EZFS_PROPTYPE, /* property does not apply to dataset type */ 6099653d4eSeschrock EZFS_PROPNONINHERIT, /* property is not inheritable */ 6199653d4eSeschrock EZFS_PROPSPACE, /* bad quota or reservation */ 6299653d4eSeschrock EZFS_BADTYPE, /* dataset is not of appropriate type */ 6399653d4eSeschrock EZFS_BUSY, /* pool or dataset is busy */ 6499653d4eSeschrock EZFS_EXISTS, /* pool or dataset already exists */ 6599653d4eSeschrock EZFS_NOENT, /* no such pool or dataset */ 6699653d4eSeschrock EZFS_BADSTREAM, /* bad backup stream */ 6799653d4eSeschrock EZFS_DSREADONLY, /* dataset is readonly */ 6899653d4eSeschrock EZFS_VOLTOOBIG, /* volume is too large for 32-bit system */ 6999653d4eSeschrock EZFS_INVALIDNAME, /* invalid dataset name */ 7099653d4eSeschrock EZFS_BADRESTORE, /* unable to restore to destination */ 7199653d4eSeschrock EZFS_BADBACKUP, /* backup failed */ 7299653d4eSeschrock EZFS_BADTARGET, /* bad attach/detach/replace target */ 7399653d4eSeschrock EZFS_NODEVICE, /* no such device in pool */ 7499653d4eSeschrock EZFS_BADDEV, /* invalid device to add */ 7599653d4eSeschrock EZFS_NOREPLICAS, /* no valid replicas */ 7699653d4eSeschrock EZFS_RESILVERING, /* currently resilvering */ 7799653d4eSeschrock EZFS_BADVERSION, /* unsupported version */ 7899653d4eSeschrock EZFS_POOLUNAVAIL, /* pool is currently unavailable */ 7999653d4eSeschrock EZFS_DEVOVERFLOW, /* too many devices in one vdev */ 8099653d4eSeschrock EZFS_BADPATH, /* must be an absolute path */ 8199653d4eSeschrock EZFS_CROSSTARGET, /* rename or clone across pool or dataset */ 8299653d4eSeschrock EZFS_ZONED, /* used improperly in local zone */ 8399653d4eSeschrock EZFS_MOUNTFAILED, /* failed to mount dataset */ 8499653d4eSeschrock EZFS_UMOUNTFAILED, /* failed to unmount dataset */ 85f3861e1aSahl EZFS_UNSHARENFSFAILED, /* unshare(1M) failed */ 86f3861e1aSahl EZFS_SHARENFSFAILED, /* share(1M) failed */ 8799653d4eSeschrock EZFS_PERM, /* permission denied */ 8899653d4eSeschrock EZFS_NOSPC, /* out of space */ 8999653d4eSeschrock EZFS_IO, /* I/O error */ 9099653d4eSeschrock EZFS_INTR, /* signal received */ 9199653d4eSeschrock EZFS_ISSPARE, /* device is a hot spare */ 9299653d4eSeschrock EZFS_INVALCONFIG, /* invalid vdev configuration */ 933bb79becSeschrock EZFS_RECURSIVE, /* recursive dependency */ 9406eeb2adSek EZFS_NOHISTORY, /* no history object */ 95f3861e1aSahl EZFS_UNSHAREISCSIFAILED, /* iscsitgtd failed request to unshare */ 96f3861e1aSahl EZFS_SHAREISCSIFAILED, /* iscsitgtd failed request to share */ 97b1b8ab34Slling EZFS_POOLPROPS, /* couldn't retrieve pool props */ 98b1b8ab34Slling EZFS_POOL_NOTSUP, /* ops not supported for this type of pool */ 99b1b8ab34Slling EZFS_POOL_INVALARG, /* invalid argument for this pool operation */ 100b7661cccSmmusante EZFS_NAMETOOLONG, /* dataset name is too long */ 1018488aeb5Staylor EZFS_OPENFAILED, /* open of device failed */ 1028488aeb5Staylor EZFS_NOCAP, /* couldn't get capacity */ 1038488aeb5Staylor EZFS_LABELFAILED, /* write of label failed */ 104ecd6cf80Smarks EZFS_ISCSISVCUNAVAIL, /* iscsi service unavailable */ 105ecd6cf80Smarks EZFS_BADWHO, /* invalid permission who */ 106ecd6cf80Smarks EZFS_BADPERM, /* invalid permission */ 107ecd6cf80Smarks EZFS_BADPERMSET, /* invalid permission set name */ 108ecd6cf80Smarks EZFS_NODELEGATION, /* delegated administration is disabled */ 109ecd6cf80Smarks EZFS_PERMRDONLY, /* pemissions are readonly */ 110da6c28aaSamw EZFS_UNSHARESMBFAILED, /* failed to unshare over smb */ 111da6c28aaSamw EZFS_SHARESMBFAILED, /* failed to share over smb */ 1122f8aaab3Seschrock EZFS_BADCACHE, /* bad cache file */ 113fa94a07fSbrendan EZFS_ISL2CACHE, /* device is for the level 2 ARC */ 114e7cbe64fSgw EZFS_VDEVNOTSUP, /* unsupported vdev type */ 11515e6edf1Sgw EZFS_NOTSUP, /* ops not supported on this dataset */ 11689a89ebfSlling EZFS_ACTIVE_SPARE, /* pool has active shared spare devices */ 117e6ca193dSGeorge Wilson EZFS_UNPLAYED_LOGS, /* log device has unplayed logs */ 118842727c2SChris Kirby EZFS_REFTAG_RELE, /* snapshot release: tag not found */ 119842727c2SChris Kirby EZFS_REFTAG_HOLD, /* snapshot hold: tag already exists */ 120ca45db41SChris Kirby EZFS_TAGTOOLONG, /* snapshot hold/rele: tag too long */ 121*9e69d7d0SLori Alt EZFS_PIPEFAILED, /* pipe create failed */ 122*9e69d7d0SLori Alt EZFS_THREADCREATEFAILED, /* thread create failed */ 123b1b8ab34Slling EZFS_UNKNOWN 12499653d4eSeschrock }; 12599653d4eSeschrock 126ecd6cf80Smarks /* 127ecd6cf80Smarks * The following data structures are all part 128ecd6cf80Smarks * of the zfs_allow_t data structure which is 129ecd6cf80Smarks * used for printing 'allow' permissions. 130ecd6cf80Smarks * It is a linked list of zfs_allow_t's which 131ecd6cf80Smarks * then contain avl tree's for user/group/sets/... 132ecd6cf80Smarks * and each one of the entries in those trees have 133ecd6cf80Smarks * avl tree's for the permissions they belong to and 134ecd6cf80Smarks * whether they are local,descendent or local+descendent 135ecd6cf80Smarks * permissions. The AVL trees are used primarily for 136ecd6cf80Smarks * sorting purposes, but also so that we can quickly find 137ecd6cf80Smarks * a given user and or permission. 138ecd6cf80Smarks */ 139ecd6cf80Smarks typedef struct zfs_perm_node { 140ecd6cf80Smarks avl_node_t z_node; 141ecd6cf80Smarks char z_pname[MAXPATHLEN]; 142ecd6cf80Smarks } zfs_perm_node_t; 143ecd6cf80Smarks 144ecd6cf80Smarks typedef struct zfs_allow_node { 145ecd6cf80Smarks avl_node_t z_node; 146ecd6cf80Smarks char z_key[MAXPATHLEN]; /* name, such as joe */ 147ecd6cf80Smarks avl_tree_t z_localdescend; /* local+descendent perms */ 148ecd6cf80Smarks avl_tree_t z_local; /* local permissions */ 149ecd6cf80Smarks avl_tree_t z_descend; /* descendent permissions */ 150ecd6cf80Smarks } zfs_allow_node_t; 151ecd6cf80Smarks 152ecd6cf80Smarks typedef struct zfs_allow { 153ecd6cf80Smarks struct zfs_allow *z_next; 154ecd6cf80Smarks char z_setpoint[MAXPATHLEN]; 155ecd6cf80Smarks avl_tree_t z_sets; 156ecd6cf80Smarks avl_tree_t z_crperms; 157ecd6cf80Smarks avl_tree_t z_user; 158ecd6cf80Smarks avl_tree_t z_group; 159ecd6cf80Smarks avl_tree_t z_everyone; 160ecd6cf80Smarks } zfs_allow_t; 161ecd6cf80Smarks 162fa9e4066Sahrens /* 163fa9e4066Sahrens * Basic handle types 164fa9e4066Sahrens */ 165fa9e4066Sahrens typedef struct zfs_handle zfs_handle_t; 166fa9e4066Sahrens typedef struct zpool_handle zpool_handle_t; 16799653d4eSeschrock typedef struct libzfs_handle libzfs_handle_t; 16899653d4eSeschrock 16999653d4eSeschrock /* 17099653d4eSeschrock * Library initialization 17199653d4eSeschrock */ 17299653d4eSeschrock extern libzfs_handle_t *libzfs_init(void); 17399653d4eSeschrock extern void libzfs_fini(libzfs_handle_t *); 17499653d4eSeschrock 17599653d4eSeschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *); 17699653d4eSeschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *); 17799653d4eSeschrock 17899653d4eSeschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t); 17999653d4eSeschrock 18099653d4eSeschrock extern int libzfs_errno(libzfs_handle_t *); 18199653d4eSeschrock extern const char *libzfs_error_action(libzfs_handle_t *); 18299653d4eSeschrock extern const char *libzfs_error_description(libzfs_handle_t *); 183ebedde84SEric Taylor extern void libzfs_mnttab_init(libzfs_handle_t *); 184ebedde84SEric Taylor extern void libzfs_mnttab_fini(libzfs_handle_t *); 185b2634b9cSEric Taylor extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t); 186ebedde84SEric Taylor extern int libzfs_mnttab_find(libzfs_handle_t *, const char *, 187ebedde84SEric Taylor struct mnttab *); 188ebedde84SEric Taylor extern void libzfs_mnttab_add(libzfs_handle_t *, const char *, 189ebedde84SEric Taylor const char *, const char *); 190ebedde84SEric Taylor extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *); 191fa9e4066Sahrens 192fa9e4066Sahrens /* 193fa9e4066Sahrens * Basic handle functions 194fa9e4066Sahrens */ 19599653d4eSeschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *); 19699653d4eSeschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *); 197fa9e4066Sahrens extern void zpool_close(zpool_handle_t *); 198fa9e4066Sahrens extern const char *zpool_get_name(zpool_handle_t *); 199fa9e4066Sahrens extern int zpool_get_state(zpool_handle_t *); 200990b4856Slling extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t); 20129ab75c9Srm extern void zpool_free_handles(libzfs_handle_t *); 202fa9e4066Sahrens 203fa9e4066Sahrens /* 204fa9e4066Sahrens * Iterate over all active pools in the system. 205fa9e4066Sahrens */ 206fa9e4066Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *); 20799653d4eSeschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *); 208fa9e4066Sahrens 209fa9e4066Sahrens /* 210fa9e4066Sahrens * Functions to create and destroy pools 211fa9e4066Sahrens */ 21299653d4eSeschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *, 2130a48a24eStimh nvlist_t *, nvlist_t *); 214fa9e4066Sahrens extern int zpool_destroy(zpool_handle_t *); 215fa9e4066Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *); 216fa9e4066Sahrens 217fa9e4066Sahrens /* 218fa9e4066Sahrens * Functions to manipulate pool and vdev state 219fa9e4066Sahrens */ 220fa9e4066Sahrens extern int zpool_scrub(zpool_handle_t *, pool_scrub_type_t); 221468c413aSTim Haley extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *); 222fa9e4066Sahrens 2233d7072f8Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int, 2243d7072f8Seschrock vdev_state_t *); 2253d7072f8Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t); 2263d7072f8Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *, 2273d7072f8Seschrock const char *, nvlist_t *, int); 228fa9e4066Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *); 22999653d4eSeschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *); 2303d7072f8Seschrock 231069f55e2SEric Schrock extern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t); 232069f55e2SEric Schrock extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t); 2333d7072f8Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t); 2343d7072f8Seschrock 235fa94a07fSbrendan extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *, 236ee0eb9f2SEric Schrock boolean_t *, boolean_t *); 237573ca77eSGeorge Wilson extern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *, 238573ca77eSGeorge Wilson boolean_t *, boolean_t *, boolean_t *); 2398488aeb5Staylor extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *); 240fa9e4066Sahrens 241b1b8ab34Slling /* 242b1b8ab34Slling * Functions to manage pool properties 243b1b8ab34Slling */ 244b1b8ab34Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *); 2453d7072f8Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *, 246990b4856Slling size_t proplen, zprop_source_t *); 247990b4856Slling extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t, 248990b4856Slling zprop_source_t *); 249990b4856Slling 250b1b8ab34Slling extern const char *zpool_prop_to_name(zpool_prop_t); 251b1b8ab34Slling extern const char *zpool_prop_values(zpool_prop_t); 252b1b8ab34Slling 253fa9e4066Sahrens /* 254fa9e4066Sahrens * Pool health statistics. 255fa9e4066Sahrens */ 256fa9e4066Sahrens typedef enum { 257fa9e4066Sahrens /* 258fa9e4066Sahrens * The following correspond to faults as defined in the (fault.fs.zfs.*) 259b81d61a6Slling * event namespace. Each is associated with a corresponding message ID. 260fa9e4066Sahrens */ 261fa9e4066Sahrens ZPOOL_STATUS_CORRUPT_CACHE, /* corrupt /kernel/drv/zpool.cache */ 262fa9e4066Sahrens ZPOOL_STATUS_MISSING_DEV_R, /* missing device with replicas */ 263fa9e4066Sahrens ZPOOL_STATUS_MISSING_DEV_NR, /* missing device with no replicas */ 264fa9e4066Sahrens ZPOOL_STATUS_CORRUPT_LABEL_R, /* bad device label with replicas */ 265b81d61a6Slling ZPOOL_STATUS_CORRUPT_LABEL_NR, /* bad device label with no replicas */ 266fa9e4066Sahrens ZPOOL_STATUS_BAD_GUID_SUM, /* sum of device guids didn't match */ 267fa9e4066Sahrens ZPOOL_STATUS_CORRUPT_POOL, /* pool metadata is corrupted */ 268fa9e4066Sahrens ZPOOL_STATUS_CORRUPT_DATA, /* data errors in user (meta)data */ 269fa9e4066Sahrens ZPOOL_STATUS_FAILING_DEV, /* device experiencing errors */ 270eaca9bbdSeschrock ZPOOL_STATUS_VERSION_NEWER, /* newer on-disk version */ 27195173954Sek ZPOOL_STATUS_HOSTID_MISMATCH, /* last accessed by another system */ 27232b87932Sek ZPOOL_STATUS_IO_FAILURE_WAIT, /* failed I/O, failmode 'wait' */ 27332b87932Sek ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */ 274f67f35c3SEric Schrock ZPOOL_STATUS_BAD_LOG, /* cannot read log chain(s) */ 275f67f35c3SEric Schrock 276f67f35c3SEric Schrock /* 277f67f35c3SEric Schrock * These faults have no corresponding message ID. At the time we are 278f67f35c3SEric Schrock * checking the status, the original reason for the FMA fault (I/O or 279f67f35c3SEric Schrock * checksum errors) has been lost. 280f67f35c3SEric Schrock */ 2813d7072f8Seschrock ZPOOL_STATUS_FAULTED_DEV_R, /* faulted device with replicas */ 2823d7072f8Seschrock ZPOOL_STATUS_FAULTED_DEV_NR, /* faulted device with no replicas */ 283fa9e4066Sahrens 284fa9e4066Sahrens /* 285fa9e4066Sahrens * The following are not faults per se, but still an error possibly 286b81d61a6Slling * requiring administrative attention. There is no corresponding 287fa9e4066Sahrens * message ID. 288fa9e4066Sahrens */ 289eaca9bbdSeschrock ZPOOL_STATUS_VERSION_OLDER, /* older on-disk version */ 290fa9e4066Sahrens ZPOOL_STATUS_RESILVERING, /* device being resilvered */ 291fa9e4066Sahrens ZPOOL_STATUS_OFFLINE_DEV, /* device online */ 292c25309d4SGeorge Wilson ZPOOL_STATUS_REMOVED_DEV, /* removed device */ 293fa9e4066Sahrens 294fa9e4066Sahrens /* 295fa9e4066Sahrens * Finally, the following indicates a healthy pool. 296fa9e4066Sahrens */ 297fa9e4066Sahrens ZPOOL_STATUS_OK 298fa9e4066Sahrens } zpool_status_t; 299fa9e4066Sahrens 300ea8dc4b6Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **); 301ea8dc4b6Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **); 302fa9e4066Sahrens 303fa9e4066Sahrens /* 304fa9e4066Sahrens * Statistics and configuration functions. 305fa9e4066Sahrens */ 306ea8dc4b6Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **); 30794de1d4cSeschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *); 30855434c77Sek extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **); 309ea8dc4b6Seschrock 310fa9e4066Sahrens /* 311fa9e4066Sahrens * Import and export functions 312fa9e4066Sahrens */ 31389a89ebfSlling extern int zpool_export(zpool_handle_t *, boolean_t); 314394ab0cbSGeorge Wilson extern int zpool_export_force(zpool_handle_t *); 31599653d4eSeschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *, 316990b4856Slling char *altroot); 317990b4856Slling extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *, 318c5904d13Seschrock nvlist_t *, boolean_t); 319fa9e4066Sahrens 320fa9e4066Sahrens /* 321fa9e4066Sahrens * Search for pools to import 322fa9e4066Sahrens */ 32324e697d4Sck extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **); 3243a57275aSck extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *, 325e829d913Sck char *, uint64_t); 32624e697d4Sck extern nvlist_t *zpool_find_import_byname(libzfs_handle_t *, int, char **, 32724e697d4Sck char *); 32824e697d4Sck extern nvlist_t *zpool_find_import_byguid(libzfs_handle_t *, int, char **, 32924e697d4Sck uint64_t); 33024e697d4Sck extern nvlist_t *zpool_find_import_activeok(libzfs_handle_t *, int, char **); 331fa9e4066Sahrens 332c67d9675Seschrock /* 333c67d9675Seschrock * Miscellaneous pool functions 334c67d9675Seschrock */ 335ecd6cf80Smarks struct zfs_cmd; 336ecd6cf80Smarks 3378f18d1faSGeorge Wilson extern const char *hist_event_table[LOG_END]; 3388f18d1faSGeorge Wilson 33988ecc943SGeorge Wilson extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *, 34088ecc943SGeorge Wilson boolean_t verbose); 341990b4856Slling extern int zpool_upgrade(zpool_handle_t *, uint64_t); 34206eeb2adSek extern int zpool_get_history(zpool_handle_t *, nvlist_t **); 3438f18d1faSGeorge Wilson extern int zpool_history_unpack(char *, uint64_t, uint64_t *, 3448f18d1faSGeorge Wilson nvlist_t ***, uint_t *); 3452a6b87f0Sek extern void zpool_set_history_str(const char *subcommand, int argc, 3462a6b87f0Sek char **argv, char *history_str); 3472a6b87f0Sek extern int zpool_stage_history(libzfs_handle_t *, const char *); 34855434c77Sek extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *, 34955434c77Sek size_t len); 350ecd6cf80Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *); 351753a6d45SSherry Moore extern int zpool_get_physpath(zpool_handle_t *, char *, size_t); 352468c413aSTim Haley extern void zpool_explain_recover(libzfs_handle_t *, const char *, int, 353468c413aSTim Haley nvlist_t *); 354753a6d45SSherry Moore 355fa9e4066Sahrens /* 356fa9e4066Sahrens * Basic handle manipulations. These functions do not create or destroy the 357fa9e4066Sahrens * underlying datasets, only the references to them. 358fa9e4066Sahrens */ 35999653d4eSeschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int); 360fa9e4066Sahrens extern void zfs_close(zfs_handle_t *); 361fa9e4066Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *); 362fa9e4066Sahrens extern const char *zfs_get_name(const zfs_handle_t *); 363d5b5bb25SRich Morris extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *); 364fa9e4066Sahrens 365fa9e4066Sahrens /* 366fa9e4066Sahrens * Property management functions. Some functions are shared with the kernel, 367b81d61a6Slling * and are found in sys/fs/zfs.h. 368fa9e4066Sahrens */ 369990b4856Slling 370990b4856Slling /* 371990b4856Slling * zfs dataset property management 372990b4856Slling */ 373990b4856Slling extern const char *zfs_prop_default_string(zfs_prop_t); 374990b4856Slling extern uint64_t zfs_prop_default_numeric(zfs_prop_t); 375990b4856Slling extern const char *zfs_prop_column_name(zfs_prop_t); 376990b4856Slling extern boolean_t zfs_prop_align_right(zfs_prop_t); 377990b4856Slling 3780a48a24eStimh extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t, 3790a48a24eStimh nvlist_t *, uint64_t, zfs_handle_t *, const char *); 3800a48a24eStimh 381e9dbad6fSeschrock extern const char *zfs_prop_to_name(zfs_prop_t); 382e9dbad6fSeschrock extern int zfs_prop_set(zfs_handle_t *, const char *, const char *); 383e9dbad6fSeschrock extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t, 384990b4856Slling zprop_source_t *, char *, size_t, boolean_t); 385e9dbad6fSeschrock extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *, 386990b4856Slling zprop_source_t *, char *, size_t); 387edea4b55SLin Ling extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname, 388edea4b55SLin Ling uint64_t *propvalue); 38914843421SMatthew Ahrens extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname, 39014843421SMatthew Ahrens char *propbuf, int proplen, boolean_t literal); 391e9dbad6fSeschrock extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t); 392e9dbad6fSeschrock extern int zfs_prop_inherit(zfs_handle_t *, const char *); 393e9dbad6fSeschrock extern const char *zfs_prop_values(zfs_prop_t); 394e9dbad6fSeschrock extern int zfs_prop_is_string(zfs_prop_t prop); 395990b4856Slling extern nvlist_t *zfs_get_user_props(zfs_handle_t *); 396e9dbad6fSeschrock 397990b4856Slling typedef struct zprop_list { 398990b4856Slling int pl_prop; 399e9dbad6fSeschrock char *pl_user_prop; 400990b4856Slling struct zprop_list *pl_next; 401e9dbad6fSeschrock boolean_t pl_all; 402e9dbad6fSeschrock size_t pl_width; 403e9dbad6fSeschrock boolean_t pl_fixed; 404990b4856Slling } zprop_list_t; 405e9dbad6fSeschrock 406990b4856Slling extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **); 4072e5e9e19SSanjeev Bagewadi extern void zfs_prune_proplist(zfs_handle_t *, uint8_t *); 408fa9e4066Sahrens 409fa9e4066Sahrens #define ZFS_MOUNTPOINT_NONE "none" 410fa9e4066Sahrens #define ZFS_MOUNTPOINT_LEGACY "legacy" 411fa9e4066Sahrens 412b1b8ab34Slling /* 413990b4856Slling * zpool property management 414990b4856Slling */ 415990b4856Slling extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **); 416990b4856Slling extern const char *zpool_prop_default_string(zpool_prop_t); 417990b4856Slling extern uint64_t zpool_prop_default_numeric(zpool_prop_t); 418990b4856Slling extern const char *zpool_prop_column_name(zpool_prop_t); 419990b4856Slling extern boolean_t zpool_prop_align_right(zpool_prop_t); 420990b4856Slling 421990b4856Slling /* 422990b4856Slling * Functions shared by zfs and zpool property management. 423b1b8ab34Slling */ 424990b4856Slling extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all, 425990b4856Slling boolean_t ordered, zfs_type_t type); 426990b4856Slling extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **, 427990b4856Slling zfs_type_t); 428990b4856Slling extern void zprop_free_list(zprop_list_t *); 429990b4856Slling 430990b4856Slling /* 431990b4856Slling * Functions for printing zfs or zpool properties 432990b4856Slling */ 433990b4856Slling typedef struct zprop_get_cbdata { 434b1b8ab34Slling int cb_sources; 435b1b8ab34Slling int cb_columns[4]; 436b1b8ab34Slling int cb_colwidths[5]; 437b1b8ab34Slling boolean_t cb_scripted; 438b1b8ab34Slling boolean_t cb_literal; 439b1b8ab34Slling boolean_t cb_first; 440990b4856Slling zprop_list_t *cb_proplist; 441990b4856Slling zfs_type_t cb_type; 442990b4856Slling } zprop_get_cbdata_t; 443b1b8ab34Slling 444990b4856Slling void zprop_print_one_property(const char *, zprop_get_cbdata_t *, 445990b4856Slling const char *, const char *, zprop_source_t, const char *); 446b1b8ab34Slling 447b1b8ab34Slling #define GET_COL_NAME 1 448b1b8ab34Slling #define GET_COL_PROPERTY 2 449b1b8ab34Slling #define GET_COL_VALUE 3 450b1b8ab34Slling #define GET_COL_SOURCE 4 451b1b8ab34Slling 452fa9e4066Sahrens /* 453fa9e4066Sahrens * Iterator functions. 454fa9e4066Sahrens */ 455fa9e4066Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *); 45699653d4eSeschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *); 457fa9e4066Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *); 4583bb79becSeschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *); 4597f7322feSeschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *); 4607f7322feSeschrock extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *); 461ca45db41SChris Kirby extern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *); 462fa9e4066Sahrens 463fa9e4066Sahrens /* 464fa9e4066Sahrens * Functions to create and destroy datasets. 465fa9e4066Sahrens */ 46699653d4eSeschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t, 467e9dbad6fSeschrock nvlist_t *); 4687f1f55eaSvb extern int zfs_create_ancestors(libzfs_handle_t *, const char *); 469842727c2SChris Kirby extern int zfs_destroy(zfs_handle_t *, boolean_t); 470842727c2SChris Kirby extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t); 471e9dbad6fSeschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *); 472bb0ade09Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *); 473c391e322Sahrens extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t); 4747f1f55eaSvb extern int zfs_rename(zfs_handle_t *, const char *, boolean_t); 475*9e69d7d0SLori Alt 476*9e69d7d0SLori Alt typedef struct sendflags { 477*9e69d7d0SLori Alt /* print informational messages (ie, -v was specified) */ 478*9e69d7d0SLori Alt int verbose : 1; 479*9e69d7d0SLori Alt 480*9e69d7d0SLori Alt /* recursive send (i.e., -R) */ 481*9e69d7d0SLori Alt int replicate : 1; 482*9e69d7d0SLori Alt 483*9e69d7d0SLori Alt /* for incrementals, do all intermediate snapshots */ 484*9e69d7d0SLori Alt int doall : 1; /* (i.e., -I) */ 485*9e69d7d0SLori Alt 486*9e69d7d0SLori Alt /* if dataset is a clone, do incremental from its origin */ 487*9e69d7d0SLori Alt int fromorigin : 1; 488*9e69d7d0SLori Alt 489*9e69d7d0SLori Alt /* do deduplication */ 490*9e69d7d0SLori Alt int dedup : 1; 491*9e69d7d0SLori Alt } sendflags_t; 492*9e69d7d0SLori Alt 493*9e69d7d0SLori Alt typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *); 494*9e69d7d0SLori Alt 4953cb34c60Sahrens extern int zfs_send(zfs_handle_t *, const char *, const char *, 496*9e69d7d0SLori Alt sendflags_t, int, snapfilter_cb_t, void *); 497*9e69d7d0SLori Alt 49899653d4eSeschrock extern int zfs_promote(zfs_handle_t *); 499ca45db41SChris Kirby extern int zfs_hold(zfs_handle_t *, const char *, const char *, boolean_t, 500ca45db41SChris Kirby boolean_t); 501ca45db41SChris Kirby extern int zfs_hold_range(zfs_handle_t *, const char *, const char *, 502ca45db41SChris Kirby const char *, boolean_t); 503842727c2SChris Kirby extern int zfs_release(zfs_handle_t *, const char *, const char *, boolean_t); 504ca45db41SChris Kirby extern int zfs_release_range(zfs_handle_t *, const char *, const char *, 505ca45db41SChris Kirby const char *); 506fa9e4066Sahrens 5070aea4b19SMatthew Ahrens typedef int (*zfs_userspace_cb_t)(void *arg, const char *domain, 50814843421SMatthew Ahrens uid_t rid, uint64_t space); 50914843421SMatthew Ahrens 51014843421SMatthew Ahrens extern int zfs_userspace(zfs_handle_t *zhp, zfs_userquota_prop_t type, 51114843421SMatthew Ahrens zfs_userspace_cb_t func, void *arg); 51214843421SMatthew Ahrens 5133cb34c60Sahrens typedef struct recvflags { 5144ccbb6e7Sahrens /* print informational messages (ie, -v was specified) */ 515c6765aabSeschrock int verbose : 1; 5164ccbb6e7Sahrens 5174ccbb6e7Sahrens /* the destination is a prefix, not the exact fs (ie, -d) */ 518c6765aabSeschrock int isprefix : 1; 5194ccbb6e7Sahrens 5204ccbb6e7Sahrens /* do not actually do the recv, just check if it would work (ie, -n) */ 521c6765aabSeschrock int dryrun : 1; 5224ccbb6e7Sahrens 5234ccbb6e7Sahrens /* rollback/destroy filesystems as necessary (eg, -F) */ 524c6765aabSeschrock int force : 1; 5254ccbb6e7Sahrens 5264ccbb6e7Sahrens /* set "canmount=off" on all modified filesystems */ 527c6765aabSeschrock int canmountoff : 1; 5284ccbb6e7Sahrens 5294ccbb6e7Sahrens /* byteswap flag is used internally; callers need not specify */ 530c6765aabSeschrock int byteswap : 1; 53133408eefSLori Alt 53233408eefSLori Alt /* do not mount file systems as they are extracted (private) */ 53333408eefSLori Alt int nomount : 1; 5343cb34c60Sahrens } recvflags_t; 5353cb34c60Sahrens 5363cb34c60Sahrens extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t, 5373cb34c60Sahrens int, avl_tree_t *); 5383cb34c60Sahrens 539fa9e4066Sahrens /* 540fa9e4066Sahrens * Miscellaneous functions. 541fa9e4066Sahrens */ 542fa9e4066Sahrens extern const char *zfs_type_to_name(zfs_type_t); 543fa9e4066Sahrens extern void zfs_refresh_properties(zfs_handle_t *); 544fa9e4066Sahrens extern int zfs_name_valid(const char *, zfs_type_t); 5455aba80dbSck extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t); 5467f1f55eaSvb extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *, 5477f1f55eaSvb zfs_type_t); 5487b97dc1aSrm extern int zfs_spa_version(zfs_handle_t *, int *); 549fa9e4066Sahrens 550fa9e4066Sahrens /* 551fa9e4066Sahrens * Mount support functions. 552fa9e4066Sahrens */ 55355434c77Sek extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **); 55499653d4eSeschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **); 555fa9e4066Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int); 556fa9e4066Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int); 557fa9e4066Sahrens extern int zfs_unmountall(zfs_handle_t *, int); 558fa9e4066Sahrens 559fa9e4066Sahrens /* 560fa9e4066Sahrens * Share support functions. 561fa9e4066Sahrens */ 562f3861e1aSahl extern boolean_t zfs_is_shared(zfs_handle_t *); 563fa9e4066Sahrens extern int zfs_share(zfs_handle_t *); 564f3861e1aSahl extern int zfs_unshare(zfs_handle_t *); 565f3861e1aSahl 566f3861e1aSahl /* 5673d7072f8Seschrock * Protocol-specific share support functions. 568f3861e1aSahl */ 569f3861e1aSahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **); 570da6c28aaSamw extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **); 571f3861e1aSahl extern int zfs_share_nfs(zfs_handle_t *); 572da6c28aaSamw extern int zfs_share_smb(zfs_handle_t *); 573da6c28aaSamw extern int zfs_shareall(zfs_handle_t *); 574f3861e1aSahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *); 575da6c28aaSamw extern int zfs_unshare_smb(zfs_handle_t *, const char *); 576f3861e1aSahl extern int zfs_unshareall_nfs(zfs_handle_t *); 577da6c28aaSamw extern int zfs_unshareall_smb(zfs_handle_t *); 578da6c28aaSamw extern int zfs_unshareall_bypath(zfs_handle_t *, const char *); 579da6c28aaSamw extern int zfs_unshareall(zfs_handle_t *); 580f3861e1aSahl extern boolean_t zfs_is_shared_iscsi(zfs_handle_t *); 581f3861e1aSahl extern int zfs_share_iscsi(zfs_handle_t *); 582f3861e1aSahl extern int zfs_unshare_iscsi(zfs_handle_t *); 583ecd6cf80Smarks extern int zfs_iscsi_perm_check(libzfs_handle_t *, char *, ucred_t *); 584743a77edSAlan Wright extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *, 585da6c28aaSamw void *, void *, int, zfs_share_op_t); 586fa9e4066Sahrens 587fa9e4066Sahrens /* 588fa9e4066Sahrens * When dealing with nvlists, verify() is extremely useful 589fa9e4066Sahrens */ 590fa9e4066Sahrens #ifdef NDEBUG 591fa9e4066Sahrens #define verify(EX) ((void)(EX)) 592fa9e4066Sahrens #else 593fa9e4066Sahrens #define verify(EX) assert(EX) 594fa9e4066Sahrens #endif 595fa9e4066Sahrens 596fa9e4066Sahrens /* 597fa9e4066Sahrens * Utility function to convert a number to a human-readable form. 598fa9e4066Sahrens */ 599fa9e4066Sahrens extern void zfs_nicenum(uint64_t, char *, size_t); 600e9dbad6fSeschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *); 601fa9e4066Sahrens 602fa9e4066Sahrens /* 603fa9e4066Sahrens * Given a device or file, determine if it is part of a pool. 604fa9e4066Sahrens */ 60599653d4eSeschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **, 60699653d4eSeschrock boolean_t *); 607fa9e4066Sahrens 608fa9e4066Sahrens /* 609096d22d4SEric Schrock * Label manipulation. 610fa9e4066Sahrens */ 61199653d4eSeschrock extern int zpool_read_label(int, nvlist_t **); 612096d22d4SEric Schrock extern int zpool_clear_label(int); 613fa9e4066Sahrens 614e7cbe64fSgw /* is this zvol valid for use as a dump device? */ 615e7cbe64fSgw extern int zvol_check_dump_config(char *); 616e7cbe64fSgw 617743a77edSAlan Wright /* 618743a77edSAlan Wright * Management interfaces for SMB ACL files 619743a77edSAlan Wright */ 620743a77edSAlan Wright 621743a77edSAlan Wright int zfs_smb_acl_add(libzfs_handle_t *, char *, char *, char *); 622743a77edSAlan Wright int zfs_smb_acl_remove(libzfs_handle_t *, char *, char *, char *); 623743a77edSAlan Wright int zfs_smb_acl_purge(libzfs_handle_t *, char *, char *); 624743a77edSAlan Wright int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *); 625743a77edSAlan Wright 6263bb79becSeschrock /* 627f3861e1aSahl * Enable and disable datasets within a pool by mounting/unmounting and 628f3861e1aSahl * sharing/unsharing them. 6293bb79becSeschrock */ 630f3861e1aSahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int); 631f3861e1aSahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t); 6323bb79becSeschrock 633069f55e2SEric Schrock /* 634069f55e2SEric Schrock * Mappings between vdev and FRU. 635069f55e2SEric Schrock */ 636069f55e2SEric Schrock extern void libzfs_fru_refresh(libzfs_handle_t *); 637069f55e2SEric Schrock extern const char *libzfs_fru_lookup(libzfs_handle_t *, const char *); 638069f55e2SEric Schrock extern const char *libzfs_fru_devpath(libzfs_handle_t *, const char *); 639069f55e2SEric Schrock extern boolean_t libzfs_fru_compare(libzfs_handle_t *, const char *, 640069f55e2SEric Schrock const char *); 641069f55e2SEric Schrock extern boolean_t libzfs_fru_notself(libzfs_handle_t *, const char *); 642069f55e2SEric Schrock extern int zpool_fru_set(zpool_handle_t *, uint64_t, const char *); 643069f55e2SEric Schrock 644fa9e4066Sahrens #ifdef __cplusplus 645fa9e4066Sahrens } 646fa9e4066Sahrens #endif 647fa9e4066Sahrens 648fa9e4066Sahrens #endif /* _LIBZFS_H */ 649