xref: /onnv-gate/usr/src/lib/libzfs/common/libzfs.h (revision 11149)
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 /*
238584SLori.Alt@Sun.COM  * Copyright 2009 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 */
892082Seschrock 	EZFS_IO,		/* I/O error */
902082Seschrock 	EZFS_INTR,		/* signal received */
912082Seschrock 	EZFS_ISSPARE,		/* device is a hot spare */
922082Seschrock 	EZFS_INVALCONFIG,	/* invalid vdev configuration */
932474Seschrock 	EZFS_RECURSIVE,		/* recursive dependency */
942926Sek110237 	EZFS_NOHISTORY,		/* no history object */
953126Sahl 	EZFS_UNSHAREISCSIFAILED, /* iscsitgtd failed request to unshare */
963126Sahl 	EZFS_SHAREISCSIFAILED,	/* iscsitgtd failed request to share */
973912Slling 	EZFS_POOLPROPS,		/* couldn't retrieve pool props */
983912Slling 	EZFS_POOL_NOTSUP,	/* ops not supported for this type of pool */
993912Slling 	EZFS_POOL_INVALARG,	/* invalid argument for this pool operation */
1003978Smmusante 	EZFS_NAMETOOLONG,	/* dataset name is too long */
1014276Staylor 	EZFS_OPENFAILED,	/* open of device failed */
1024276Staylor 	EZFS_NOCAP,		/* couldn't get capacity */
1034276Staylor 	EZFS_LABELFAILED,	/* write of label failed */
1044543Smarks 	EZFS_ISCSISVCUNAVAIL,	/* iscsi service unavailable */
1054543Smarks 	EZFS_BADWHO,		/* invalid permission who */
1064543Smarks 	EZFS_BADPERM,		/* invalid permission */
1074543Smarks 	EZFS_BADPERMSET,	/* invalid permission set name */
1084543Smarks 	EZFS_NODELEGATION,	/* delegated administration is disabled */
1094543Smarks 	EZFS_PERMRDONLY,	/* pemissions are readonly */
1105331Samw 	EZFS_UNSHARESMBFAILED,	/* failed to unshare over smb */
1115331Samw 	EZFS_SHARESMBFAILED,	/* failed to share over smb */
1125363Seschrock 	EZFS_BADCACHE,		/* bad cache file */
1135450Sbrendan 	EZFS_ISL2CACHE,		/* device is for the level 2 ARC */
1146423Sgw25295 	EZFS_VDEVNOTSUP,	/* unsupported vdev type */
1157042Sgw25295 	EZFS_NOTSUP,		/* ops not supported on this dataset */
1167214Slling 	EZFS_ACTIVE_SPARE,	/* pool has active shared spare devices */
1179701SGeorge.Wilson@Sun.COM 	EZFS_UNPLAYED_LOGS,	/* log device has unplayed logs */
11810242Schris.kirby@sun.com 	EZFS_REFTAG_RELE,	/* snapshot release: tag not found */
11910242Schris.kirby@sun.com 	EZFS_REFTAG_HOLD,	/* snapshot hold: tag already exists */
12010342Schris.kirby@sun.com 	EZFS_TAGTOOLONG,	/* snapshot hold/rele: tag too long */
12111007SLori.Alt@Sun.COM 	EZFS_PIPEFAILED,	/* pipe create failed */
12211007SLori.Alt@Sun.COM 	EZFS_THREADCREATEFAILED, /* thread create failed */
1233912Slling 	EZFS_UNKNOWN
1242082Seschrock };
1252082Seschrock 
1262082Seschrock /*
1274543Smarks  * The following data structures are all part
1284543Smarks  * of the zfs_allow_t data structure which is
1294543Smarks  * used for printing 'allow' permissions.
1304543Smarks  * It is a linked list of zfs_allow_t's which
1314543Smarks  * then contain avl tree's for user/group/sets/...
1324543Smarks  * and each one of the entries in those trees have
1334543Smarks  * avl tree's for the permissions they belong to and
1344543Smarks  * whether they are local,descendent or local+descendent
1354543Smarks  * permissions.  The AVL trees are used primarily for
1364543Smarks  * sorting purposes, but also so that we can quickly find
1374543Smarks  * a given user and or permission.
1384543Smarks  */
1394543Smarks typedef struct zfs_perm_node {
1404543Smarks 	avl_node_t z_node;
1414543Smarks 	char z_pname[MAXPATHLEN];
1424543Smarks } zfs_perm_node_t;
1434543Smarks 
1444543Smarks typedef struct zfs_allow_node {
1454543Smarks 	avl_node_t z_node;
1464543Smarks 	char z_key[MAXPATHLEN];		/* name, such as joe */
1474543Smarks 	avl_tree_t z_localdescend;	/* local+descendent perms */
1484543Smarks 	avl_tree_t z_local;		/* local permissions */
1494543Smarks 	avl_tree_t z_descend;		/* descendent permissions */
1504543Smarks } zfs_allow_node_t;
1514543Smarks 
1524543Smarks typedef struct zfs_allow {
1534543Smarks 	struct zfs_allow *z_next;
1544543Smarks 	char z_setpoint[MAXPATHLEN];
1554543Smarks 	avl_tree_t z_sets;
1564543Smarks 	avl_tree_t z_crperms;
1574543Smarks 	avl_tree_t z_user;
1584543Smarks 	avl_tree_t z_group;
1594543Smarks 	avl_tree_t z_everyone;
1604543Smarks } zfs_allow_t;
1614543Smarks 
1624543Smarks /*
163789Sahrens  * Basic handle types
164789Sahrens  */
165789Sahrens typedef struct zfs_handle zfs_handle_t;
166789Sahrens typedef struct zpool_handle zpool_handle_t;
1672082Seschrock typedef struct libzfs_handle libzfs_handle_t;
1682082Seschrock 
1692082Seschrock /*
1702082Seschrock  * Library initialization
1712082Seschrock  */
1722082Seschrock extern libzfs_handle_t *libzfs_init(void);
1732082Seschrock extern void libzfs_fini(libzfs_handle_t *);
1742082Seschrock 
1752082Seschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
1762082Seschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
1772082Seschrock 
1782082Seschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
1792082Seschrock 
1802082Seschrock extern int libzfs_errno(libzfs_handle_t *);
1812082Seschrock extern const char *libzfs_error_action(libzfs_handle_t *);
1822082Seschrock extern const char *libzfs_error_description(libzfs_handle_t *);
1838228SEric.Taylor@Sun.COM extern void libzfs_mnttab_init(libzfs_handle_t *);
1848228SEric.Taylor@Sun.COM extern void libzfs_mnttab_fini(libzfs_handle_t *);
1858811SEric.Taylor@Sun.COM extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t);
1868228SEric.Taylor@Sun.COM extern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
1878228SEric.Taylor@Sun.COM     struct mnttab *);
1888228SEric.Taylor@Sun.COM extern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
1898228SEric.Taylor@Sun.COM     const char *, const char *);
1908228SEric.Taylor@Sun.COM extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
191789Sahrens 
192789Sahrens /*
193789Sahrens  * Basic handle functions
194789Sahrens  */
1952082Seschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
1962082Seschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
197789Sahrens extern void zpool_close(zpool_handle_t *);
198789Sahrens extern const char *zpool_get_name(zpool_handle_t *);
199789Sahrens extern int zpool_get_state(zpool_handle_t *);
2005094Slling extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
2016865Srm160521 extern void zpool_free_handles(libzfs_handle_t *);
202789Sahrens 
203789Sahrens /*
204789Sahrens  * Iterate over all active pools in the system.
205789Sahrens  */
206789Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
2072082Seschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
208789Sahrens 
209789Sahrens /*
210789Sahrens  * Functions to create and destroy pools
211789Sahrens  */
2122082Seschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
2137184Stimh     nvlist_t *, nvlist_t *);
214789Sahrens extern int zpool_destroy(zpool_handle_t *);
215789Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *);
216789Sahrens 
217789Sahrens /*
218789Sahrens  * Functions to manipulate pool and vdev state
219789Sahrens  */
220789Sahrens extern int zpool_scrub(zpool_handle_t *, pool_scrub_type_t);
22110921STim.Haley@Sun.COM extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *);
222789Sahrens 
2234451Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
2244451Seschrock     vdev_state_t *);
2254451Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
2264451Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *,
2274451Seschrock     const char *, nvlist_t *, int);
228789Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *);
2292082Seschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *);
2304451Seschrock 
23110817SEric.Schrock@Sun.COM extern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t);
23210817SEric.Schrock@Sun.COM extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t);
2334451Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
2344451Seschrock 
2355450Sbrendan extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *,
2367326SEric.Schrock@Sun.COM     boolean_t *, boolean_t *);
2379816SGeorge.Wilson@Sun.COM extern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *,
2389816SGeorge.Wilson@Sun.COM     boolean_t *, boolean_t *, boolean_t *);
2394276Staylor extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *);
240789Sahrens 
241789Sahrens /*
2423912Slling  * Functions to manage pool properties
2433912Slling  */
2443912Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
2454451Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
2465094Slling     size_t proplen, zprop_source_t *);
2475094Slling extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t,
2485094Slling     zprop_source_t *);
2495094Slling 
2503912Slling extern const char *zpool_prop_to_name(zpool_prop_t);
2513912Slling extern const char *zpool_prop_values(zpool_prop_t);
2523912Slling 
2533912Slling /*
254789Sahrens  * Pool health statistics.
255789Sahrens  */
256789Sahrens typedef enum {
257789Sahrens 	/*
258789Sahrens 	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
2591003Slling 	 * event namespace.  Each is associated with a corresponding message ID.
260789Sahrens 	 */
261789Sahrens 	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
262789Sahrens 	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
263789Sahrens 	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
264789Sahrens 	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
2651003Slling 	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device label with no replicas */
266789Sahrens 	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
267789Sahrens 	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
268789Sahrens 	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
269789Sahrens 	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
2701760Seschrock 	ZPOOL_STATUS_VERSION_NEWER,	/* newer on-disk version */
2713975Sek110237 	ZPOOL_STATUS_HOSTID_MISMATCH,	/* last accessed by another system */
2726523Sek110237 	ZPOOL_STATUS_IO_FAILURE_WAIT,	/* failed I/O, failmode 'wait' */
2736523Sek110237 	ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */
2748343SEric.Schrock@Sun.COM 	ZPOOL_STATUS_BAD_LOG,		/* cannot read log chain(s) */
2758343SEric.Schrock@Sun.COM 
2768343SEric.Schrock@Sun.COM 	/*
2778343SEric.Schrock@Sun.COM 	 * These faults have no corresponding message ID.  At the time we are
2788343SEric.Schrock@Sun.COM 	 * checking the status, the original reason for the FMA fault (I/O or
2798343SEric.Schrock@Sun.COM 	 * checksum errors) has been lost.
2808343SEric.Schrock@Sun.COM 	 */
2814451Seschrock 	ZPOOL_STATUS_FAULTED_DEV_R,	/* faulted device with replicas */
2824451Seschrock 	ZPOOL_STATUS_FAULTED_DEV_NR,	/* faulted device with no replicas */
283789Sahrens 
284789Sahrens 	/*
285789Sahrens 	 * The following are not faults per se, but still an error possibly
2861003Slling 	 * requiring administrative attention.  There is no corresponding
287789Sahrens 	 * message ID.
288789Sahrens 	 */
2891760Seschrock 	ZPOOL_STATUS_VERSION_OLDER,	/* older on-disk version */
290789Sahrens 	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
291789Sahrens 	ZPOOL_STATUS_OFFLINE_DEV,	/* device online */
29210151SGeorge.Wilson@Sun.COM 	ZPOOL_STATUS_REMOVED_DEV,	/* removed device */
293789Sahrens 
294789Sahrens 	/*
295789Sahrens 	 * Finally, the following indicates a healthy pool.
296789Sahrens 	 */
297789Sahrens 	ZPOOL_STATUS_OK
298789Sahrens } zpool_status_t;
299789Sahrens 
3001544Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **);
3011544Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **);
302*11149SGeorge.Wilson@Sun.COM extern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh);
303789Sahrens 
304789Sahrens /*
305789Sahrens  * Statistics and configuration functions.
306789Sahrens  */
3071544Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
3082142Seschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
3093444Sek110237 extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
3101544Seschrock 
311789Sahrens /*
312789Sahrens  * Import and export functions
313789Sahrens  */
3147214Slling extern int zpool_export(zpool_handle_t *, boolean_t);
3158211SGeorge.Wilson@Sun.COM extern int zpool_export_force(zpool_handle_t *);
3162082Seschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
3175094Slling     char *altroot);
3185094Slling extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
3196643Seschrock     nvlist_t *, boolean_t);
320789Sahrens 
321789Sahrens /*
322789Sahrens  * Search for pools to import
323789Sahrens  */
3246807Sck153898 extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
3255994Sck153898 extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *,
3266957Sck153898     char *, uint64_t);
3276807Sck153898 extern nvlist_t *zpool_find_import_byname(libzfs_handle_t *, int, char **,
3286807Sck153898     char *);
3296807Sck153898 extern nvlist_t *zpool_find_import_byguid(libzfs_handle_t *, int, char **,
3306807Sck153898     uint64_t);
3316807Sck153898 extern nvlist_t *zpool_find_import_activeok(libzfs_handle_t *, int, char **);
332789Sahrens 
333789Sahrens /*
3341354Seschrock  * Miscellaneous pool functions
3351354Seschrock  */
3364543Smarks struct zfs_cmd;
3374543Smarks 
33810685SGeorge.Wilson@Sun.COM extern const char *hist_event_table[LOG_END];
33910685SGeorge.Wilson@Sun.COM 
34010594SGeorge.Wilson@Sun.COM extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *,
34110594SGeorge.Wilson@Sun.COM     boolean_t verbose);
3425094Slling extern int zpool_upgrade(zpool_handle_t *, uint64_t);
3432926Sek110237 extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
34410685SGeorge.Wilson@Sun.COM extern int zpool_history_unpack(char *, uint64_t, uint64_t *,
34510685SGeorge.Wilson@Sun.COM     nvlist_t ***, uint_t *);
3464988Sek110237 extern void zpool_set_history_str(const char *subcommand, int argc,
3474988Sek110237     char **argv, char *history_str);
3484988Sek110237 extern int zpool_stage_history(libzfs_handle_t *, const char *);
3493444Sek110237 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
3503444Sek110237     size_t len);
3514543Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
3529160SSherry.Moore@Sun.COM extern int zpool_get_physpath(zpool_handle_t *, char *, size_t);
35310921STim.Haley@Sun.COM extern void zpool_explain_recover(libzfs_handle_t *, const char *, int,
35410921STim.Haley@Sun.COM     nvlist_t *);
3559160SSherry.Moore@Sun.COM 
3561354Seschrock /*
357789Sahrens  * Basic handle manipulations.  These functions do not create or destroy the
358789Sahrens  * underlying datasets, only the references to them.
359789Sahrens  */
3602082Seschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
361789Sahrens extern void zfs_close(zfs_handle_t *);
362789Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *);
363789Sahrens extern const char *zfs_get_name(const zfs_handle_t *);
3647538SRichard.Morris@Sun.COM extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
365789Sahrens 
366789Sahrens /*
367789Sahrens  * Property management functions.  Some functions are shared with the kernel,
3681003Slling  * and are found in sys/fs/zfs.h.
369789Sahrens  */
3705094Slling 
3715094Slling /*
3725094Slling  * zfs dataset property management
3735094Slling  */
3745094Slling extern const char *zfs_prop_default_string(zfs_prop_t);
3752676Seschrock extern uint64_t zfs_prop_default_numeric(zfs_prop_t);
3762676Seschrock extern const char *zfs_prop_column_name(zfs_prop_t);
3772676Seschrock extern boolean_t zfs_prop_align_right(zfs_prop_t);
3782676Seschrock 
3797184Stimh extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t,
3807184Stimh     nvlist_t *, uint64_t, zfs_handle_t *, const char *);
3817184Stimh 
3825094Slling extern const char *zfs_prop_to_name(zfs_prop_t);
3835094Slling extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
3845094Slling extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
3855094Slling     zprop_source_t *, char *, size_t, boolean_t);
38611022STom.Erickson@Sun.COM extern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t,
38711022STom.Erickson@Sun.COM     boolean_t);
3885094Slling extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
3895094Slling     zprop_source_t *, char *, size_t);
3909469SLin.Ling@Sun.COM extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname,
3919469SLin.Ling@Sun.COM     uint64_t *propvalue);
3929396SMatthew.Ahrens@Sun.COM extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname,
3939396SMatthew.Ahrens@Sun.COM     char *propbuf, int proplen, boolean_t literal);
3945094Slling extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
39511022STom.Erickson@Sun.COM extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t);
3965094Slling extern const char *zfs_prop_values(zfs_prop_t);
3975094Slling extern int zfs_prop_is_string(zfs_prop_t prop);
3985094Slling extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
39911022STom.Erickson@Sun.COM extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *);
4005094Slling 
4015094Slling typedef struct zprop_list {
4025094Slling 	int		pl_prop;
4032676Seschrock 	char		*pl_user_prop;
4045094Slling 	struct zprop_list *pl_next;
4052676Seschrock 	boolean_t	pl_all;
4062676Seschrock 	size_t		pl_width;
40711022STom.Erickson@Sun.COM 	size_t		pl_recvd_width;
4082676Seschrock 	boolean_t	pl_fixed;
4095094Slling } zprop_list_t;
4103912Slling 
41111022STom.Erickson@Sun.COM extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t);
4128802SSanjeev.Bagewadi@Sun.COM extern void zfs_prune_proplist(zfs_handle_t *, uint8_t *);
413789Sahrens 
414789Sahrens #define	ZFS_MOUNTPOINT_NONE	"none"
415789Sahrens #define	ZFS_MOUNTPOINT_LEGACY	"legacy"
416789Sahrens 
417789Sahrens /*
4185094Slling  * zpool property management
4195094Slling  */
4205094Slling extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **);
4215094Slling extern const char *zpool_prop_default_string(zpool_prop_t);
4225094Slling extern uint64_t zpool_prop_default_numeric(zpool_prop_t);
4235094Slling extern const char *zpool_prop_column_name(zpool_prop_t);
4245094Slling extern boolean_t zpool_prop_align_right(zpool_prop_t);
4255094Slling 
4265094Slling /*
4275094Slling  * Functions shared by zfs and zpool property management.
4283912Slling  */
4295094Slling extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all,
4305094Slling     boolean_t ordered, zfs_type_t type);
4315094Slling extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **,
4325094Slling     zfs_type_t);
4335094Slling extern void zprop_free_list(zprop_list_t *);
4345094Slling 
43511022STom.Erickson@Sun.COM #define	ZFS_GET_NCOLS	5
43611022STom.Erickson@Sun.COM 
43711022STom.Erickson@Sun.COM typedef enum {
43811022STom.Erickson@Sun.COM 	GET_COL_NONE,
43911022STom.Erickson@Sun.COM 	GET_COL_NAME,
44011022STom.Erickson@Sun.COM 	GET_COL_PROPERTY,
44111022STom.Erickson@Sun.COM 	GET_COL_VALUE,
44211022STom.Erickson@Sun.COM 	GET_COL_RECVD,
44311022STom.Erickson@Sun.COM 	GET_COL_SOURCE
44411022STom.Erickson@Sun.COM } zfs_get_column_t;
44511022STom.Erickson@Sun.COM 
4465094Slling /*
4475094Slling  * Functions for printing zfs or zpool properties
4485094Slling  */
4495094Slling typedef struct zprop_get_cbdata {
4503912Slling 	int cb_sources;
45111022STom.Erickson@Sun.COM 	zfs_get_column_t cb_columns[ZFS_GET_NCOLS];
45211022STom.Erickson@Sun.COM 	int cb_colwidths[ZFS_GET_NCOLS + 1];
4533912Slling 	boolean_t cb_scripted;
4543912Slling 	boolean_t cb_literal;
4553912Slling 	boolean_t cb_first;
4565094Slling 	zprop_list_t *cb_proplist;
4575094Slling 	zfs_type_t cb_type;
4585094Slling } zprop_get_cbdata_t;
4593912Slling 
4605094Slling void zprop_print_one_property(const char *, zprop_get_cbdata_t *,
46111022STom.Erickson@Sun.COM     const char *, const char *, zprop_source_t, const char *,
46211022STom.Erickson@Sun.COM     const char *);
4633912Slling 
4643912Slling /*
465789Sahrens  * Iterator functions.
466789Sahrens  */
467789Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
4682082Seschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
469789Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
4702474Seschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
4711356Seschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
4721356Seschrock extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *);
47310342Schris.kirby@sun.com extern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *);
474789Sahrens 
475789Sahrens /*
476789Sahrens  * Functions to create and destroy datasets.
477789Sahrens  */
4782082Seschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
4792676Seschrock     nvlist_t *);
4804490Svb160487 extern int zfs_create_ancestors(libzfs_handle_t *, const char *);
48110242Schris.kirby@sun.com extern int zfs_destroy(zfs_handle_t *, boolean_t);
48210242Schris.kirby@sun.com extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t);
4832676Seschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
4847265Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
4855749Sahrens extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
4864490Svb160487 extern int zfs_rename(zfs_handle_t *, const char *, boolean_t);
48711007SLori.Alt@Sun.COM 
48811007SLori.Alt@Sun.COM typedef struct sendflags {
48911007SLori.Alt@Sun.COM 	/* print informational messages (ie, -v was specified) */
49011007SLori.Alt@Sun.COM 	int verbose : 1;
49111007SLori.Alt@Sun.COM 
49211022STom.Erickson@Sun.COM 	/* recursive send  (ie, -R) */
49311007SLori.Alt@Sun.COM 	int replicate : 1;
49411007SLori.Alt@Sun.COM 
49511007SLori.Alt@Sun.COM 	/* for incrementals, do all intermediate snapshots */
49611022STom.Erickson@Sun.COM 	int doall : 1; /* (ie, -I) */
49711007SLori.Alt@Sun.COM 
49811007SLori.Alt@Sun.COM 	/* if dataset is a clone, do incremental from its origin */
49911007SLori.Alt@Sun.COM 	int fromorigin : 1;
50011007SLori.Alt@Sun.COM 
50111007SLori.Alt@Sun.COM 	/* do deduplication */
50211007SLori.Alt@Sun.COM 	int dedup : 1;
50311022STom.Erickson@Sun.COM 
50411022STom.Erickson@Sun.COM 	/* send properties (ie, -p) */
50511022STom.Erickson@Sun.COM 	int props : 1;
50611007SLori.Alt@Sun.COM } sendflags_t;
50711007SLori.Alt@Sun.COM 
50811007SLori.Alt@Sun.COM typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *);
50911007SLori.Alt@Sun.COM 
5105367Sahrens extern int zfs_send(zfs_handle_t *, const char *, const char *,
51111007SLori.Alt@Sun.COM     sendflags_t, int, snapfilter_cb_t, void *);
51211007SLori.Alt@Sun.COM 
5132082Seschrock extern int zfs_promote(zfs_handle_t *);
51410342Schris.kirby@sun.com extern int zfs_hold(zfs_handle_t *, const char *, const char *, boolean_t,
51510342Schris.kirby@sun.com     boolean_t);
51610342Schris.kirby@sun.com extern int zfs_hold_range(zfs_handle_t *, const char *, const char *,
51710342Schris.kirby@sun.com     const char *, boolean_t);
51810242Schris.kirby@sun.com extern int zfs_release(zfs_handle_t *, const char *, const char *, boolean_t);
51910342Schris.kirby@sun.com extern int zfs_release_range(zfs_handle_t *, const char *, const char *,
52010342Schris.kirby@sun.com     const char *);
521789Sahrens 
5229554SMatthew.Ahrens@Sun.COM typedef int (*zfs_userspace_cb_t)(void *arg, const char *domain,
5239396SMatthew.Ahrens@Sun.COM     uid_t rid, uint64_t space);
5249396SMatthew.Ahrens@Sun.COM 
5259396SMatthew.Ahrens@Sun.COM extern int zfs_userspace(zfs_handle_t *zhp, zfs_userquota_prop_t type,
5269396SMatthew.Ahrens@Sun.COM     zfs_userspace_cb_t func, void *arg);
5279396SMatthew.Ahrens@Sun.COM 
5285367Sahrens typedef struct recvflags {
5295446Sahrens 	/* print informational messages (ie, -v was specified) */
5305501Seschrock 	int verbose : 1;
5315446Sahrens 
5325446Sahrens 	/* the destination is a prefix, not the exact fs (ie, -d) */
5335501Seschrock 	int isprefix : 1;
5345446Sahrens 
5355446Sahrens 	/* do not actually do the recv, just check if it would work (ie, -n) */
5365501Seschrock 	int dryrun : 1;
5375446Sahrens 
5385446Sahrens 	/* rollback/destroy filesystems as necessary (eg, -F) */
5395501Seschrock 	int force : 1;
5405446Sahrens 
5415446Sahrens 	/* set "canmount=off" on all modified filesystems */
5425501Seschrock 	int canmountoff : 1;
5435446Sahrens 
5445446Sahrens 	/* byteswap flag is used internally; callers need not specify */
5455501Seschrock 	int byteswap : 1;
5468584SLori.Alt@Sun.COM 
5478584SLori.Alt@Sun.COM 	/* do not mount file systems as they are extracted (private) */
5488584SLori.Alt@Sun.COM 	int nomount : 1;
5495367Sahrens } recvflags_t;
5505367Sahrens 
5515367Sahrens extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t,
5525367Sahrens     int, avl_tree_t *);
5535367Sahrens 
554789Sahrens /*
555789Sahrens  * Miscellaneous functions.
556789Sahrens  */
557789Sahrens extern const char *zfs_type_to_name(zfs_type_t);
558789Sahrens extern void zfs_refresh_properties(zfs_handle_t *);
559789Sahrens extern int zfs_name_valid(const char *, zfs_type_t);
5603635Sck153898 extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t);
5614490Svb160487 extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *,
5624490Svb160487     zfs_type_t);
5635713Srm160521 extern int zfs_spa_version(zfs_handle_t *, int *);
564789Sahrens 
565789Sahrens /*
566789Sahrens  * Mount support functions.
567789Sahrens  */
5683444Sek110237 extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **);
5692082Seschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **);
570789Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int);
571789Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int);
572789Sahrens extern int zfs_unmountall(zfs_handle_t *, int);
573789Sahrens 
574789Sahrens /*
575789Sahrens  * Share support functions.
576789Sahrens  */
5773126Sahl extern boolean_t zfs_is_shared(zfs_handle_t *);
578789Sahrens extern int zfs_share(zfs_handle_t *);
5793126Sahl extern int zfs_unshare(zfs_handle_t *);
5803126Sahl 
5813126Sahl /*
5824451Seschrock  * Protocol-specific share support functions.
5833126Sahl  */
5843126Sahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **);
5855331Samw extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **);
5863126Sahl extern int zfs_share_nfs(zfs_handle_t *);
5875331Samw extern int zfs_share_smb(zfs_handle_t *);
5885331Samw extern int zfs_shareall(zfs_handle_t *);
5893126Sahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *);
5905331Samw extern int zfs_unshare_smb(zfs_handle_t *, const char *);
5913126Sahl extern int zfs_unshareall_nfs(zfs_handle_t *);
5925331Samw extern int zfs_unshareall_smb(zfs_handle_t *);
5935331Samw extern int zfs_unshareall_bypath(zfs_handle_t *, const char *);
5945331Samw extern int zfs_unshareall(zfs_handle_t *);
5953126Sahl extern boolean_t zfs_is_shared_iscsi(zfs_handle_t *);
5963126Sahl extern int zfs_share_iscsi(zfs_handle_t *);
5973126Sahl extern int zfs_unshare_iscsi(zfs_handle_t *);
5984543Smarks extern int zfs_iscsi_perm_check(libzfs_handle_t *, char *, ucred_t *);
5998845Samw@Sun.COM extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *,
6005331Samw     void *, void *, int, zfs_share_op_t);
601789Sahrens 
602789Sahrens /*
603789Sahrens  * When dealing with nvlists, verify() is extremely useful
604789Sahrens  */
605789Sahrens #ifdef NDEBUG
606789Sahrens #define	verify(EX)	((void)(EX))
607789Sahrens #else
608789Sahrens #define	verify(EX)	assert(EX)
609789Sahrens #endif
610789Sahrens 
611789Sahrens /*
612789Sahrens  * Utility function to convert a number to a human-readable form.
613789Sahrens  */
614789Sahrens extern void zfs_nicenum(uint64_t, char *, size_t);
6152676Seschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
616789Sahrens 
617789Sahrens /*
618789Sahrens  * Given a device or file, determine if it is part of a pool.
619789Sahrens  */
6202082Seschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **,
6212082Seschrock     boolean_t *);
622789Sahrens 
623789Sahrens /*
62410830SEric.Schrock@Sun.COM  * Label manipulation.
625789Sahrens  */
6262082Seschrock extern int zpool_read_label(int, nvlist_t **);
62710830SEric.Schrock@Sun.COM extern int zpool_clear_label(int);
628789Sahrens 
6296423Sgw25295 /* is this zvol valid for use as a dump device? */
6306423Sgw25295 extern int zvol_check_dump_config(char *);
6316423Sgw25295 
6322474Seschrock /*
6338845Samw@Sun.COM  * Management interfaces for SMB ACL files
6348845Samw@Sun.COM  */
6358845Samw@Sun.COM 
6368845Samw@Sun.COM int zfs_smb_acl_add(libzfs_handle_t *, char *, char *, char *);
6378845Samw@Sun.COM int zfs_smb_acl_remove(libzfs_handle_t *, char *, char *, char *);
6388845Samw@Sun.COM int zfs_smb_acl_purge(libzfs_handle_t *, char *, char *);
6398845Samw@Sun.COM int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *);
6408845Samw@Sun.COM 
6418845Samw@Sun.COM /*
6423126Sahl  * Enable and disable datasets within a pool by mounting/unmounting and
6433126Sahl  * sharing/unsharing them.
6442474Seschrock  */
6453126Sahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int);
6463126Sahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t);
6472474Seschrock 
64810817SEric.Schrock@Sun.COM /*
64910817SEric.Schrock@Sun.COM  * Mappings between vdev and FRU.
65010817SEric.Schrock@Sun.COM  */
65110817SEric.Schrock@Sun.COM extern void libzfs_fru_refresh(libzfs_handle_t *);
65210817SEric.Schrock@Sun.COM extern const char *libzfs_fru_lookup(libzfs_handle_t *, const char *);
65310817SEric.Schrock@Sun.COM extern const char *libzfs_fru_devpath(libzfs_handle_t *, const char *);
65410817SEric.Schrock@Sun.COM extern boolean_t libzfs_fru_compare(libzfs_handle_t *, const char *,
65510817SEric.Schrock@Sun.COM     const char *);
65610817SEric.Schrock@Sun.COM extern boolean_t libzfs_fru_notself(libzfs_handle_t *, const char *);
65710817SEric.Schrock@Sun.COM extern int zpool_fru_set(zpool_handle_t *, uint64_t, const char *);
65810817SEric.Schrock@Sun.COM 
659789Sahrens #ifdef	__cplusplus
660789Sahrens }
661789Sahrens #endif
662789Sahrens 
663789Sahrens #endif	/* _LIBZFS_H */
664