xref: /onnv-gate/usr/src/lib/libzfs/common/libzfs.h (revision 11807)
1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
51485Slling  * Common Development and Distribution License (the "License").
61485Slling  * You may not use this file except in compliance with the License.
7789Sahrens  *
8789Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9789Sahrens  * or http://www.opensolaris.org/os/licensing.
10789Sahrens  * See the License for the specific language governing permissions
11789Sahrens  * and limitations under the License.
12789Sahrens  *
13789Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14789Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15789Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16789Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17789Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18789Sahrens  *
19789Sahrens  * CDDL HEADER END
20789Sahrens  */
213126Sahl 
22789Sahrens /*
2311417SChris.Kirby@sun.com  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24789Sahrens  * Use is subject to license terms.
25789Sahrens  */
26789Sahrens 
27789Sahrens #ifndef	_LIBZFS_H
28789Sahrens #define	_LIBZFS_H
29789Sahrens 
30789Sahrens #include <assert.h>
31789Sahrens #include <libnvpair.h>
328228SEric.Taylor@Sun.COM #include <sys/mnttab.h>
33789Sahrens #include <sys/param.h>
34789Sahrens #include <sys/types.h>
35789Sahrens #include <sys/varargs.h>
36789Sahrens #include <sys/fs/zfs.h>
374543Smarks #include <sys/avl.h>
384543Smarks #include <ucred.h>
39789Sahrens 
40789Sahrens #ifdef	__cplusplus
41789Sahrens extern "C" {
42789Sahrens #endif
43789Sahrens 
44789Sahrens /*
45789Sahrens  * Miscellaneous ZFS constants
46789Sahrens  */
47789Sahrens #define	ZFS_MAXNAMELEN		MAXNAMELEN
48789Sahrens #define	ZPOOL_MAXNAMELEN	MAXNAMELEN
49789Sahrens #define	ZFS_MAXPROPLEN		MAXPATHLEN
505094Slling #define	ZPOOL_MAXPROPLEN	MAXPATHLEN
51789Sahrens 
52789Sahrens /*
532082Seschrock  * libzfs errors
542082Seschrock  */
552082Seschrock enum {
562082Seschrock 	EZFS_NOMEM = 2000,	/* out of memory */
572082Seschrock 	EZFS_BADPROP,		/* invalid property value */
582082Seschrock 	EZFS_PROPREADONLY,	/* cannot set readonly property */
592082Seschrock 	EZFS_PROPTYPE,		/* property does not apply to dataset type */
602082Seschrock 	EZFS_PROPNONINHERIT,	/* property is not inheritable */
612082Seschrock 	EZFS_PROPSPACE,		/* bad quota or reservation */
622082Seschrock 	EZFS_BADTYPE,		/* dataset is not of appropriate type */
632082Seschrock 	EZFS_BUSY,		/* pool or dataset is busy */
642082Seschrock 	EZFS_EXISTS,		/* pool or dataset already exists */
652082Seschrock 	EZFS_NOENT,		/* no such pool or dataset */
662082Seschrock 	EZFS_BADSTREAM,		/* bad backup stream */
672082Seschrock 	EZFS_DSREADONLY,	/* dataset is readonly */
682082Seschrock 	EZFS_VOLTOOBIG,		/* volume is too large for 32-bit system */
692082Seschrock 	EZFS_INVALIDNAME,	/* invalid dataset name */
702082Seschrock 	EZFS_BADRESTORE,	/* unable to restore to destination */
712082Seschrock 	EZFS_BADBACKUP,		/* backup failed */
722082Seschrock 	EZFS_BADTARGET,		/* bad attach/detach/replace target */
732082Seschrock 	EZFS_NODEVICE,		/* no such device in pool */
742082Seschrock 	EZFS_BADDEV,		/* invalid device to add */
752082Seschrock 	EZFS_NOREPLICAS,	/* no valid replicas */
762082Seschrock 	EZFS_RESILVERING,	/* currently resilvering */
772082Seschrock 	EZFS_BADVERSION,	/* unsupported version */
782082Seschrock 	EZFS_POOLUNAVAIL,	/* pool is currently unavailable */
792082Seschrock 	EZFS_DEVOVERFLOW,	/* too many devices in one vdev */
802082Seschrock 	EZFS_BADPATH,		/* must be an absolute path */
812082Seschrock 	EZFS_CROSSTARGET,	/* rename or clone across pool or dataset */
822082Seschrock 	EZFS_ZONED,		/* used improperly in local zone */
832082Seschrock 	EZFS_MOUNTFAILED,	/* failed to mount dataset */
842082Seschrock 	EZFS_UMOUNTFAILED,	/* failed to unmount dataset */
853126Sahl 	EZFS_UNSHARENFSFAILED,	/* unshare(1M) failed */
863126Sahl 	EZFS_SHARENFSFAILED,	/* share(1M) failed */
872082Seschrock 	EZFS_PERM,		/* permission denied */
882082Seschrock 	EZFS_NOSPC,		/* out of space */
89*11807SSam.Falkner@Sun.COM 	EZFS_FAULT,		/* bad address */
902082Seschrock 	EZFS_IO,		/* I/O error */
912082Seschrock 	EZFS_INTR,		/* signal received */
922082Seschrock 	EZFS_ISSPARE,		/* device is a hot spare */
932082Seschrock 	EZFS_INVALCONFIG,	/* invalid vdev configuration */
942474Seschrock 	EZFS_RECURSIVE,		/* recursive dependency */
952926Sek110237 	EZFS_NOHISTORY,		/* no history object */
963126Sahl 	EZFS_UNSHAREISCSIFAILED, /* iscsitgtd failed request to unshare */
973126Sahl 	EZFS_SHAREISCSIFAILED,	/* iscsitgtd failed request to share */
983912Slling 	EZFS_POOLPROPS,		/* couldn't retrieve pool props */
993912Slling 	EZFS_POOL_NOTSUP,	/* ops not supported for this type of pool */
1003912Slling 	EZFS_POOL_INVALARG,	/* invalid argument for this pool operation */
1013978Smmusante 	EZFS_NAMETOOLONG,	/* dataset name is too long */
1024276Staylor 	EZFS_OPENFAILED,	/* open of device failed */
1034276Staylor 	EZFS_NOCAP,		/* couldn't get capacity */
1044276Staylor 	EZFS_LABELFAILED,	/* write of label failed */
1054543Smarks 	EZFS_ISCSISVCUNAVAIL,	/* iscsi service unavailable */
1064543Smarks 	EZFS_BADWHO,		/* invalid permission who */
1074543Smarks 	EZFS_BADPERM,		/* invalid permission */
1084543Smarks 	EZFS_BADPERMSET,	/* invalid permission set name */
1094543Smarks 	EZFS_NODELEGATION,	/* delegated administration is disabled */
1104543Smarks 	EZFS_PERMRDONLY,	/* pemissions are readonly */
1115331Samw 	EZFS_UNSHARESMBFAILED,	/* failed to unshare over smb */
1125331Samw 	EZFS_SHARESMBFAILED,	/* failed to share over smb */
1135363Seschrock 	EZFS_BADCACHE,		/* bad cache file */
1145450Sbrendan 	EZFS_ISL2CACHE,		/* device is for the level 2 ARC */
1156423Sgw25295 	EZFS_VDEVNOTSUP,	/* unsupported vdev type */
1167042Sgw25295 	EZFS_NOTSUP,		/* ops not supported on this dataset */
1177214Slling 	EZFS_ACTIVE_SPARE,	/* pool has active shared spare devices */
1189701SGeorge.Wilson@Sun.COM 	EZFS_UNPLAYED_LOGS,	/* log device has unplayed logs */
11910242Schris.kirby@sun.com 	EZFS_REFTAG_RELE,	/* snapshot release: tag not found */
12010242Schris.kirby@sun.com 	EZFS_REFTAG_HOLD,	/* snapshot hold: tag already exists */
12110342Schris.kirby@sun.com 	EZFS_TAGTOOLONG,	/* snapshot hold/rele: tag too long */
12211007SLori.Alt@Sun.COM 	EZFS_PIPEFAILED,	/* pipe create failed */
12311007SLori.Alt@Sun.COM 	EZFS_THREADCREATEFAILED, /* thread create failed */
12411422SMark.Musante@Sun.COM 	EZFS_POSTSPLIT_ONLINE,	/* onlining a disk after splitting it */
1253912Slling 	EZFS_UNKNOWN
1262082Seschrock };
1272082Seschrock 
1282082Seschrock /*
1294543Smarks  * The following data structures are all part
1304543Smarks  * of the zfs_allow_t data structure which is
1314543Smarks  * used for printing 'allow' permissions.
1324543Smarks  * It is a linked list of zfs_allow_t's which
1334543Smarks  * then contain avl tree's for user/group/sets/...
1344543Smarks  * and each one of the entries in those trees have
1354543Smarks  * avl tree's for the permissions they belong to and
1364543Smarks  * whether they are local,descendent or local+descendent
1374543Smarks  * permissions.  The AVL trees are used primarily for
1384543Smarks  * sorting purposes, but also so that we can quickly find
1394543Smarks  * a given user and or permission.
1404543Smarks  */
1414543Smarks typedef struct zfs_perm_node {
1424543Smarks 	avl_node_t z_node;
1434543Smarks 	char z_pname[MAXPATHLEN];
1444543Smarks } zfs_perm_node_t;
1454543Smarks 
1464543Smarks typedef struct zfs_allow_node {
1474543Smarks 	avl_node_t z_node;
1484543Smarks 	char z_key[MAXPATHLEN];		/* name, such as joe */
1494543Smarks 	avl_tree_t z_localdescend;	/* local+descendent perms */
1504543Smarks 	avl_tree_t z_local;		/* local permissions */
1514543Smarks 	avl_tree_t z_descend;		/* descendent permissions */
1524543Smarks } zfs_allow_node_t;
1534543Smarks 
1544543Smarks typedef struct zfs_allow {
1554543Smarks 	struct zfs_allow *z_next;
1564543Smarks 	char z_setpoint[MAXPATHLEN];
1574543Smarks 	avl_tree_t z_sets;
1584543Smarks 	avl_tree_t z_crperms;
1594543Smarks 	avl_tree_t z_user;
1604543Smarks 	avl_tree_t z_group;
1614543Smarks 	avl_tree_t z_everyone;
1624543Smarks } zfs_allow_t;
1634543Smarks 
1644543Smarks /*
165789Sahrens  * Basic handle types
166789Sahrens  */
167789Sahrens typedef struct zfs_handle zfs_handle_t;
168789Sahrens typedef struct zpool_handle zpool_handle_t;
1692082Seschrock typedef struct libzfs_handle libzfs_handle_t;
1702082Seschrock 
1712082Seschrock /*
1722082Seschrock  * Library initialization
1732082Seschrock  */
1742082Seschrock extern libzfs_handle_t *libzfs_init(void);
1752082Seschrock extern void libzfs_fini(libzfs_handle_t *);
1762082Seschrock 
1772082Seschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
1782082Seschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
1792082Seschrock 
1802082Seschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
1812082Seschrock 
1822082Seschrock extern int libzfs_errno(libzfs_handle_t *);
1832082Seschrock extern const char *libzfs_error_action(libzfs_handle_t *);
1842082Seschrock extern const char *libzfs_error_description(libzfs_handle_t *);
1858228SEric.Taylor@Sun.COM extern void libzfs_mnttab_init(libzfs_handle_t *);
1868228SEric.Taylor@Sun.COM extern void libzfs_mnttab_fini(libzfs_handle_t *);
1878811SEric.Taylor@Sun.COM extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t);
1888228SEric.Taylor@Sun.COM extern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
1898228SEric.Taylor@Sun.COM     struct mnttab *);
1908228SEric.Taylor@Sun.COM extern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
1918228SEric.Taylor@Sun.COM     const char *, const char *);
1928228SEric.Taylor@Sun.COM extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
193789Sahrens 
194789Sahrens /*
195789Sahrens  * Basic handle functions
196789Sahrens  */
1972082Seschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
1982082Seschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
199789Sahrens extern void zpool_close(zpool_handle_t *);
200789Sahrens extern const char *zpool_get_name(zpool_handle_t *);
201789Sahrens extern int zpool_get_state(zpool_handle_t *);
2025094Slling extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
2036865Srm160521 extern void zpool_free_handles(libzfs_handle_t *);
204789Sahrens 
205789Sahrens /*
206789Sahrens  * Iterate over all active pools in the system.
207789Sahrens  */
208789Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
2092082Seschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
210789Sahrens 
211789Sahrens /*
212789Sahrens  * Functions to create and destroy pools
213789Sahrens  */
2142082Seschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
2157184Stimh     nvlist_t *, nvlist_t *);
216789Sahrens extern int zpool_destroy(zpool_handle_t *);
217789Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *);
218789Sahrens 
21911422SMark.Musante@Sun.COM typedef struct splitflags {
22011422SMark.Musante@Sun.COM 	/* do not split, but return the config that would be split off */
22111422SMark.Musante@Sun.COM 	int dryrun : 1;
22211422SMark.Musante@Sun.COM 
22311422SMark.Musante@Sun.COM 	/* after splitting, import the pool */
22411422SMark.Musante@Sun.COM 	int import : 1;
22511422SMark.Musante@Sun.COM } splitflags_t;
22611422SMark.Musante@Sun.COM 
227789Sahrens /*
228789Sahrens  * Functions to manipulate pool and vdev state
229789Sahrens  */
230789Sahrens extern int zpool_scrub(zpool_handle_t *, pool_scrub_type_t);
23110921STim.Haley@Sun.COM extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *);
232789Sahrens 
2334451Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
2344451Seschrock     vdev_state_t *);
2354451Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
2364451Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *,
2374451Seschrock     const char *, nvlist_t *, int);
238789Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *);
2392082Seschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *);
24011422SMark.Musante@Sun.COM extern int zpool_vdev_split(zpool_handle_t *, char *, nvlist_t **, nvlist_t *,
24111422SMark.Musante@Sun.COM     splitflags_t);
2424451Seschrock 
24310817SEric.Schrock@Sun.COM extern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t);
24410817SEric.Schrock@Sun.COM extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t);
2454451Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
2464451Seschrock 
2475450Sbrendan extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *,
2487326SEric.Schrock@Sun.COM     boolean_t *, boolean_t *);
2499816SGeorge.Wilson@Sun.COM extern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *,
2509816SGeorge.Wilson@Sun.COM     boolean_t *, boolean_t *, boolean_t *);
2514276Staylor extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *);
252789Sahrens 
253789Sahrens /*
2543912Slling  * Functions to manage pool properties
2553912Slling  */
2563912Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
2574451Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
2585094Slling     size_t proplen, zprop_source_t *);
2595094Slling extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t,
2605094Slling     zprop_source_t *);
2615094Slling 
2623912Slling extern const char *zpool_prop_to_name(zpool_prop_t);
2633912Slling extern const char *zpool_prop_values(zpool_prop_t);
2643912Slling 
2653912Slling /*
266789Sahrens  * Pool health statistics.
267789Sahrens  */
268789Sahrens typedef enum {
269789Sahrens 	/*
270789Sahrens 	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
2711003Slling 	 * event namespace.  Each is associated with a corresponding message ID.
272789Sahrens 	 */
273789Sahrens 	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
274789Sahrens 	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
275789Sahrens 	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
276789Sahrens 	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
2771003Slling 	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device label with no replicas */
278789Sahrens 	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
279789Sahrens 	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
280789Sahrens 	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
281789Sahrens 	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
2821760Seschrock 	ZPOOL_STATUS_VERSION_NEWER,	/* newer on-disk version */
2833975Sek110237 	ZPOOL_STATUS_HOSTID_MISMATCH,	/* last accessed by another system */
2846523Sek110237 	ZPOOL_STATUS_IO_FAILURE_WAIT,	/* failed I/O, failmode 'wait' */
2856523Sek110237 	ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */
2868343SEric.Schrock@Sun.COM 	ZPOOL_STATUS_BAD_LOG,		/* cannot read log chain(s) */
2878343SEric.Schrock@Sun.COM 
2888343SEric.Schrock@Sun.COM 	/*
2898343SEric.Schrock@Sun.COM 	 * These faults have no corresponding message ID.  At the time we are
2908343SEric.Schrock@Sun.COM 	 * checking the status, the original reason for the FMA fault (I/O or
2918343SEric.Schrock@Sun.COM 	 * checksum errors) has been lost.
2928343SEric.Schrock@Sun.COM 	 */
2934451Seschrock 	ZPOOL_STATUS_FAULTED_DEV_R,	/* faulted device with replicas */
2944451Seschrock 	ZPOOL_STATUS_FAULTED_DEV_NR,	/* faulted device with no replicas */
295789Sahrens 
296789Sahrens 	/*
297789Sahrens 	 * The following are not faults per se, but still an error possibly
2981003Slling 	 * requiring administrative attention.  There is no corresponding
299789Sahrens 	 * message ID.
300789Sahrens 	 */
3011760Seschrock 	ZPOOL_STATUS_VERSION_OLDER,	/* older on-disk version */
302789Sahrens 	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
303789Sahrens 	ZPOOL_STATUS_OFFLINE_DEV,	/* device online */
30410151SGeorge.Wilson@Sun.COM 	ZPOOL_STATUS_REMOVED_DEV,	/* removed device */
305789Sahrens 
306789Sahrens 	/*
307789Sahrens 	 * Finally, the following indicates a healthy pool.
308789Sahrens 	 */
309789Sahrens 	ZPOOL_STATUS_OK
310789Sahrens } zpool_status_t;
311789Sahrens 
3121544Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **);
3131544Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **);
31411149SGeorge.Wilson@Sun.COM extern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh);
315789Sahrens 
316789Sahrens /*
317789Sahrens  * Statistics and configuration functions.
318789Sahrens  */
3191544Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
3202142Seschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
3213444Sek110237 extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
3221544Seschrock 
323789Sahrens /*
324789Sahrens  * Import and export functions
325789Sahrens  */
3267214Slling extern int zpool_export(zpool_handle_t *, boolean_t);
3278211SGeorge.Wilson@Sun.COM extern int zpool_export_force(zpool_handle_t *);
3282082Seschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
3295094Slling     char *altroot);
3305094Slling extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
3316643Seschrock     nvlist_t *, boolean_t);
332789Sahrens 
333789Sahrens /*
334789Sahrens  * Search for pools to import
335789Sahrens  */
33611497SMark.Musante@Sun.COM 
33711497SMark.Musante@Sun.COM typedef struct importargs {
33811497SMark.Musante@Sun.COM 	char **path;		/* a list of paths to search		*/
33911497SMark.Musante@Sun.COM 	int paths;		/* number of paths to search		*/
34011497SMark.Musante@Sun.COM 	char *poolname;		/* name of a pool to find		*/
34111497SMark.Musante@Sun.COM 	uint64_t guid;		/* guid of a pool to find		*/
34211497SMark.Musante@Sun.COM 	char *cachefile;	/* cachefile to use for import		*/
34311497SMark.Musante@Sun.COM 	int can_be_active : 1;	/* can the pool be active?		*/
34411497SMark.Musante@Sun.COM 	int unique : 1;		/* does 'poolname' already exist?	*/
34511497SMark.Musante@Sun.COM 	int exists : 1;		/* set on return if pool already exists	*/
34611497SMark.Musante@Sun.COM } importargs_t;
34711497SMark.Musante@Sun.COM 
34811497SMark.Musante@Sun.COM extern nvlist_t *zpool_search_import(libzfs_handle_t *, importargs_t *);
34911497SMark.Musante@Sun.COM 
35011497SMark.Musante@Sun.COM /* legacy pool search routines */
3516807Sck153898 extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
3525994Sck153898 extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *,
3536957Sck153898     char *, uint64_t);
354789Sahrens 
355789Sahrens /*
3561354Seschrock  * Miscellaneous pool functions
3571354Seschrock  */
3584543Smarks struct zfs_cmd;
3594543Smarks 
36010685SGeorge.Wilson@Sun.COM extern const char *hist_event_table[LOG_END];
36110685SGeorge.Wilson@Sun.COM 
36210594SGeorge.Wilson@Sun.COM extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *,
36310594SGeorge.Wilson@Sun.COM     boolean_t verbose);
3645094Slling extern int zpool_upgrade(zpool_handle_t *, uint64_t);
3652926Sek110237 extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
36610685SGeorge.Wilson@Sun.COM extern int zpool_history_unpack(char *, uint64_t, uint64_t *,
36710685SGeorge.Wilson@Sun.COM     nvlist_t ***, uint_t *);
3684988Sek110237 extern void zpool_set_history_str(const char *subcommand, int argc,
3694988Sek110237     char **argv, char *history_str);
3704988Sek110237 extern int zpool_stage_history(libzfs_handle_t *, const char *);
3713444Sek110237 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
3723444Sek110237     size_t len);
3734543Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
3749160SSherry.Moore@Sun.COM extern int zpool_get_physpath(zpool_handle_t *, char *, size_t);
37510921STim.Haley@Sun.COM extern void zpool_explain_recover(libzfs_handle_t *, const char *, int,
37610921STim.Haley@Sun.COM     nvlist_t *);
3779160SSherry.Moore@Sun.COM 
3781354Seschrock /*
379789Sahrens  * Basic handle manipulations.  These functions do not create or destroy the
380789Sahrens  * underlying datasets, only the references to them.
381789Sahrens  */
3822082Seschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
383789Sahrens extern void zfs_close(zfs_handle_t *);
384789Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *);
385789Sahrens extern const char *zfs_get_name(const zfs_handle_t *);
3867538SRichard.Morris@Sun.COM extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
387789Sahrens 
388789Sahrens /*
389789Sahrens  * Property management functions.  Some functions are shared with the kernel,
3901003Slling  * and are found in sys/fs/zfs.h.
391789Sahrens  */
3925094Slling 
3935094Slling /*
3945094Slling  * zfs dataset property management
3955094Slling  */
3965094Slling extern const char *zfs_prop_default_string(zfs_prop_t);
3972676Seschrock extern uint64_t zfs_prop_default_numeric(zfs_prop_t);
3982676Seschrock extern const char *zfs_prop_column_name(zfs_prop_t);
3992676Seschrock extern boolean_t zfs_prop_align_right(zfs_prop_t);
4002676Seschrock 
4017184Stimh extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t,
4027184Stimh     nvlist_t *, uint64_t, zfs_handle_t *, const char *);
4037184Stimh 
4045094Slling extern const char *zfs_prop_to_name(zfs_prop_t);
4055094Slling extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
4065094Slling extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
4075094Slling     zprop_source_t *, char *, size_t, boolean_t);
40811022STom.Erickson@Sun.COM extern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t,
40911022STom.Erickson@Sun.COM     boolean_t);
4105094Slling extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
4115094Slling     zprop_source_t *, char *, size_t);
4129469SLin.Ling@Sun.COM extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname,
4139469SLin.Ling@Sun.COM     uint64_t *propvalue);
4149396SMatthew.Ahrens@Sun.COM extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname,
4159396SMatthew.Ahrens@Sun.COM     char *propbuf, int proplen, boolean_t literal);
4165094Slling extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
41711022STom.Erickson@Sun.COM extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t);
4185094Slling extern const char *zfs_prop_values(zfs_prop_t);
4195094Slling extern int zfs_prop_is_string(zfs_prop_t prop);
4205094Slling extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
42111022STom.Erickson@Sun.COM extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *);
4225094Slling 
4235094Slling typedef struct zprop_list {
4245094Slling 	int		pl_prop;
4252676Seschrock 	char		*pl_user_prop;
4265094Slling 	struct zprop_list *pl_next;
4272676Seschrock 	boolean_t	pl_all;
4282676Seschrock 	size_t		pl_width;
42911022STom.Erickson@Sun.COM 	size_t		pl_recvd_width;
4302676Seschrock 	boolean_t	pl_fixed;
4315094Slling } zprop_list_t;
4323912Slling 
43311022STom.Erickson@Sun.COM extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t);
4348802SSanjeev.Bagewadi@Sun.COM extern void zfs_prune_proplist(zfs_handle_t *, uint8_t *);
435789Sahrens 
436789Sahrens #define	ZFS_MOUNTPOINT_NONE	"none"
437789Sahrens #define	ZFS_MOUNTPOINT_LEGACY	"legacy"
438789Sahrens 
439789Sahrens /*
4405094Slling  * zpool property management
4415094Slling  */
4425094Slling extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **);
4435094Slling extern const char *zpool_prop_default_string(zpool_prop_t);
4445094Slling extern uint64_t zpool_prop_default_numeric(zpool_prop_t);
4455094Slling extern const char *zpool_prop_column_name(zpool_prop_t);
4465094Slling extern boolean_t zpool_prop_align_right(zpool_prop_t);
4475094Slling 
4485094Slling /*
4495094Slling  * Functions shared by zfs and zpool property management.
4503912Slling  */
4515094Slling extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all,
4525094Slling     boolean_t ordered, zfs_type_t type);
4535094Slling extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **,
4545094Slling     zfs_type_t);
4555094Slling extern void zprop_free_list(zprop_list_t *);
4565094Slling 
45711022STom.Erickson@Sun.COM #define	ZFS_GET_NCOLS	5
45811022STom.Erickson@Sun.COM 
45911022STom.Erickson@Sun.COM typedef enum {
46011022STom.Erickson@Sun.COM 	GET_COL_NONE,
46111022STom.Erickson@Sun.COM 	GET_COL_NAME,
46211022STom.Erickson@Sun.COM 	GET_COL_PROPERTY,
46311022STom.Erickson@Sun.COM 	GET_COL_VALUE,
46411022STom.Erickson@Sun.COM 	GET_COL_RECVD,
46511022STom.Erickson@Sun.COM 	GET_COL_SOURCE
46611022STom.Erickson@Sun.COM } zfs_get_column_t;
46711022STom.Erickson@Sun.COM 
4685094Slling /*
4695094Slling  * Functions for printing zfs or zpool properties
4705094Slling  */
4715094Slling typedef struct zprop_get_cbdata {
4723912Slling 	int cb_sources;
47311022STom.Erickson@Sun.COM 	zfs_get_column_t cb_columns[ZFS_GET_NCOLS];
47411022STom.Erickson@Sun.COM 	int cb_colwidths[ZFS_GET_NCOLS + 1];
4753912Slling 	boolean_t cb_scripted;
4763912Slling 	boolean_t cb_literal;
4773912Slling 	boolean_t cb_first;
4785094Slling 	zprop_list_t *cb_proplist;
4795094Slling 	zfs_type_t cb_type;
4805094Slling } zprop_get_cbdata_t;
4813912Slling 
4825094Slling void zprop_print_one_property(const char *, zprop_get_cbdata_t *,
48311022STom.Erickson@Sun.COM     const char *, const char *, zprop_source_t, const char *,
48411022STom.Erickson@Sun.COM     const char *);
4853912Slling 
4863912Slling /*
487789Sahrens  * Iterator functions.
488789Sahrens  */
489789Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
4902082Seschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
491789Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
4922474Seschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
4931356Seschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
4941356Seschrock extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *);
49510342Schris.kirby@sun.com extern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *);
496789Sahrens 
497789Sahrens /*
498789Sahrens  * Functions to create and destroy datasets.
499789Sahrens  */
5002082Seschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
5012676Seschrock     nvlist_t *);
5024490Svb160487 extern int zfs_create_ancestors(libzfs_handle_t *, const char *);
50310242Schris.kirby@sun.com extern int zfs_destroy(zfs_handle_t *, boolean_t);
50410242Schris.kirby@sun.com extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t);
5052676Seschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
5067265Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
5075749Sahrens extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
5084490Svb160487 extern int zfs_rename(zfs_handle_t *, const char *, boolean_t);
50911007SLori.Alt@Sun.COM 
51011007SLori.Alt@Sun.COM typedef struct sendflags {
51111007SLori.Alt@Sun.COM 	/* print informational messages (ie, -v was specified) */
51211007SLori.Alt@Sun.COM 	int verbose : 1;
51311007SLori.Alt@Sun.COM 
51411022STom.Erickson@Sun.COM 	/* recursive send  (ie, -R) */
51511007SLori.Alt@Sun.COM 	int replicate : 1;
51611007SLori.Alt@Sun.COM 
51711007SLori.Alt@Sun.COM 	/* for incrementals, do all intermediate snapshots */
51811022STom.Erickson@Sun.COM 	int doall : 1; /* (ie, -I) */
51911007SLori.Alt@Sun.COM 
52011007SLori.Alt@Sun.COM 	/* if dataset is a clone, do incremental from its origin */
52111007SLori.Alt@Sun.COM 	int fromorigin : 1;
52211007SLori.Alt@Sun.COM 
52311007SLori.Alt@Sun.COM 	/* do deduplication */
52411007SLori.Alt@Sun.COM 	int dedup : 1;
52511022STom.Erickson@Sun.COM 
52611022STom.Erickson@Sun.COM 	/* send properties (ie, -p) */
52711022STom.Erickson@Sun.COM 	int props : 1;
52811007SLori.Alt@Sun.COM } sendflags_t;
52911007SLori.Alt@Sun.COM 
53011007SLori.Alt@Sun.COM typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *);
53111007SLori.Alt@Sun.COM 
5325367Sahrens extern int zfs_send(zfs_handle_t *, const char *, const char *,
53311007SLori.Alt@Sun.COM     sendflags_t, int, snapfilter_cb_t, void *);
53411007SLori.Alt@Sun.COM 
5352082Seschrock extern int zfs_promote(zfs_handle_t *);
53610342Schris.kirby@sun.com extern int zfs_hold(zfs_handle_t *, const char *, const char *, boolean_t,
53711417SChris.Kirby@sun.com     boolean_t, boolean_t);
53810342Schris.kirby@sun.com extern int zfs_hold_range(zfs_handle_t *, const char *, const char *,
53911546SChris.Kirby@sun.com     const char *, boolean_t, boolean_t);
54010242Schris.kirby@sun.com extern int zfs_release(zfs_handle_t *, const char *, const char *, boolean_t);
54110342Schris.kirby@sun.com extern int zfs_release_range(zfs_handle_t *, const char *, const char *,
54211546SChris.Kirby@sun.com     const char *, boolean_t);
54311449SEric.Taylor@Sun.COM extern uint64_t zvol_volsize_to_reservation(uint64_t, nvlist_t *);
544789Sahrens 
5459554SMatthew.Ahrens@Sun.COM typedef int (*zfs_userspace_cb_t)(void *arg, const char *domain,
5469396SMatthew.Ahrens@Sun.COM     uid_t rid, uint64_t space);
5479396SMatthew.Ahrens@Sun.COM 
5489396SMatthew.Ahrens@Sun.COM extern int zfs_userspace(zfs_handle_t *zhp, zfs_userquota_prop_t type,
5499396SMatthew.Ahrens@Sun.COM     zfs_userspace_cb_t func, void *arg);
5509396SMatthew.Ahrens@Sun.COM 
5515367Sahrens typedef struct recvflags {
5525446Sahrens 	/* print informational messages (ie, -v was specified) */
5535501Seschrock 	int verbose : 1;
5545446Sahrens 
5555446Sahrens 	/* the destination is a prefix, not the exact fs (ie, -d) */
5565501Seschrock 	int isprefix : 1;
5575446Sahrens 
55811461STom.Erickson@Sun.COM 	/*
55911461STom.Erickson@Sun.COM 	 * Only the tail of the sent snapshot path is appended to the
56011461STom.Erickson@Sun.COM 	 * destination to determine the received snapshot name (ie, -e).
56111461STom.Erickson@Sun.COM 	 */
56211461STom.Erickson@Sun.COM 	int istail : 1;
56311461STom.Erickson@Sun.COM 
5645446Sahrens 	/* do not actually do the recv, just check if it would work (ie, -n) */
5655501Seschrock 	int dryrun : 1;
5665446Sahrens 
5675446Sahrens 	/* rollback/destroy filesystems as necessary (eg, -F) */
5685501Seschrock 	int force : 1;
5695446Sahrens 
5705446Sahrens 	/* set "canmount=off" on all modified filesystems */
5715501Seschrock 	int canmountoff : 1;
5725446Sahrens 
5735446Sahrens 	/* byteswap flag is used internally; callers need not specify */
5745501Seschrock 	int byteswap : 1;
5758584SLori.Alt@Sun.COM 
5768584SLori.Alt@Sun.COM 	/* do not mount file systems as they are extracted (private) */
5778584SLori.Alt@Sun.COM 	int nomount : 1;
5785367Sahrens } recvflags_t;
5795367Sahrens 
5805367Sahrens extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t,
5815367Sahrens     int, avl_tree_t *);
5825367Sahrens 
583789Sahrens /*
584789Sahrens  * Miscellaneous functions.
585789Sahrens  */
586789Sahrens extern const char *zfs_type_to_name(zfs_type_t);
587789Sahrens extern void zfs_refresh_properties(zfs_handle_t *);
588789Sahrens extern int zfs_name_valid(const char *, zfs_type_t);
5893635Sck153898 extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t);
5904490Svb160487 extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *,
5914490Svb160487     zfs_type_t);
5925713Srm160521 extern int zfs_spa_version(zfs_handle_t *, int *);
593789Sahrens 
594789Sahrens /*
595789Sahrens  * Mount support functions.
596789Sahrens  */
5973444Sek110237 extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **);
5982082Seschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **);
599789Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int);
600789Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int);
601789Sahrens extern int zfs_unmountall(zfs_handle_t *, int);
602789Sahrens 
603789Sahrens /*
604789Sahrens  * Share support functions.
605789Sahrens  */
6063126Sahl extern boolean_t zfs_is_shared(zfs_handle_t *);
607789Sahrens extern int zfs_share(zfs_handle_t *);
6083126Sahl extern int zfs_unshare(zfs_handle_t *);
6093126Sahl 
6103126Sahl /*
6114451Seschrock  * Protocol-specific share support functions.
6123126Sahl  */
6133126Sahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **);
6145331Samw extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **);
6153126Sahl extern int zfs_share_nfs(zfs_handle_t *);
6165331Samw extern int zfs_share_smb(zfs_handle_t *);
6175331Samw extern int zfs_shareall(zfs_handle_t *);
6183126Sahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *);
6195331Samw extern int zfs_unshare_smb(zfs_handle_t *, const char *);
6203126Sahl extern int zfs_unshareall_nfs(zfs_handle_t *);
6215331Samw extern int zfs_unshareall_smb(zfs_handle_t *);
6225331Samw extern int zfs_unshareall_bypath(zfs_handle_t *, const char *);
6235331Samw extern int zfs_unshareall(zfs_handle_t *);
6243126Sahl extern boolean_t zfs_is_shared_iscsi(zfs_handle_t *);
6253126Sahl extern int zfs_share_iscsi(zfs_handle_t *);
6263126Sahl extern int zfs_unshare_iscsi(zfs_handle_t *);
6274543Smarks extern int zfs_iscsi_perm_check(libzfs_handle_t *, char *, ucred_t *);
6288845Samw@Sun.COM extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *,
6295331Samw     void *, void *, int, zfs_share_op_t);
630789Sahrens 
631789Sahrens /*
632789Sahrens  * When dealing with nvlists, verify() is extremely useful
633789Sahrens  */
634789Sahrens #ifdef NDEBUG
635789Sahrens #define	verify(EX)	((void)(EX))
636789Sahrens #else
637789Sahrens #define	verify(EX)	assert(EX)
638789Sahrens #endif
639789Sahrens 
640789Sahrens /*
641789Sahrens  * Utility function to convert a number to a human-readable form.
642789Sahrens  */
643789Sahrens extern void zfs_nicenum(uint64_t, char *, size_t);
6442676Seschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
645789Sahrens 
646789Sahrens /*
647789Sahrens  * Given a device or file, determine if it is part of a pool.
648789Sahrens  */
6492082Seschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **,
6502082Seschrock     boolean_t *);
651789Sahrens 
652789Sahrens /*
65310830SEric.Schrock@Sun.COM  * Label manipulation.
654789Sahrens  */
6552082Seschrock extern int zpool_read_label(int, nvlist_t **);
65610830SEric.Schrock@Sun.COM extern int zpool_clear_label(int);
657789Sahrens 
6586423Sgw25295 /* is this zvol valid for use as a dump device? */
6596423Sgw25295 extern int zvol_check_dump_config(char *);
6606423Sgw25295 
6612474Seschrock /*
6628845Samw@Sun.COM  * Management interfaces for SMB ACL files
6638845Samw@Sun.COM  */
6648845Samw@Sun.COM 
6658845Samw@Sun.COM int zfs_smb_acl_add(libzfs_handle_t *, char *, char *, char *);
6668845Samw@Sun.COM int zfs_smb_acl_remove(libzfs_handle_t *, char *, char *, char *);
6678845Samw@Sun.COM int zfs_smb_acl_purge(libzfs_handle_t *, char *, char *);
6688845Samw@Sun.COM int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *);
6698845Samw@Sun.COM 
6708845Samw@Sun.COM /*
6713126Sahl  * Enable and disable datasets within a pool by mounting/unmounting and
6723126Sahl  * sharing/unsharing them.
6732474Seschrock  */
6743126Sahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int);
6753126Sahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t);
6762474Seschrock 
67710817SEric.Schrock@Sun.COM /*
67810817SEric.Schrock@Sun.COM  * Mappings between vdev and FRU.
67910817SEric.Schrock@Sun.COM  */
68010817SEric.Schrock@Sun.COM extern void libzfs_fru_refresh(libzfs_handle_t *);
68110817SEric.Schrock@Sun.COM extern const char *libzfs_fru_lookup(libzfs_handle_t *, const char *);
68210817SEric.Schrock@Sun.COM extern const char *libzfs_fru_devpath(libzfs_handle_t *, const char *);
68310817SEric.Schrock@Sun.COM extern boolean_t libzfs_fru_compare(libzfs_handle_t *, const char *,
68410817SEric.Schrock@Sun.COM     const char *);
68510817SEric.Schrock@Sun.COM extern boolean_t libzfs_fru_notself(libzfs_handle_t *, const char *);
68610817SEric.Schrock@Sun.COM extern int zpool_fru_set(zpool_handle_t *, uint64_t, const char *);
68710817SEric.Schrock@Sun.COM 
688789Sahrens #ifdef	__cplusplus
689789Sahrens }
690789Sahrens #endif
691789Sahrens 
692789Sahrens #endif	/* _LIBZFS_H */
693