xref: /illumos-gate/usr/src/lib/libzfs/common/libzfs.h (revision f67f35c3)
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 /*
236949a980Smarks  * Copyright 2008 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_VOLHASDATA,	/* volume already contains data */
7099653d4eSeschrock 	EZFS_INVALIDNAME,	/* invalid dataset name */
7199653d4eSeschrock 	EZFS_BADRESTORE,	/* unable to restore to destination */
7299653d4eSeschrock 	EZFS_BADBACKUP,		/* backup failed */
7399653d4eSeschrock 	EZFS_BADTARGET,		/* bad attach/detach/replace target */
7499653d4eSeschrock 	EZFS_NODEVICE,		/* no such device in pool */
7599653d4eSeschrock 	EZFS_BADDEV,		/* invalid device to add */
7699653d4eSeschrock 	EZFS_NOREPLICAS,	/* no valid replicas */
7799653d4eSeschrock 	EZFS_RESILVERING,	/* currently resilvering */
7899653d4eSeschrock 	EZFS_BADVERSION,	/* unsupported version */
7999653d4eSeschrock 	EZFS_POOLUNAVAIL,	/* pool is currently unavailable */
8099653d4eSeschrock 	EZFS_DEVOVERFLOW,	/* too many devices in one vdev */
8199653d4eSeschrock 	EZFS_BADPATH,		/* must be an absolute path */
8299653d4eSeschrock 	EZFS_CROSSTARGET,	/* rename or clone across pool or dataset */
8399653d4eSeschrock 	EZFS_ZONED,		/* used improperly in local zone */
8499653d4eSeschrock 	EZFS_MOUNTFAILED,	/* failed to mount dataset */
8599653d4eSeschrock 	EZFS_UMOUNTFAILED,	/* failed to unmount dataset */
86f3861e1aSahl 	EZFS_UNSHARENFSFAILED,	/* unshare(1M) failed */
87f3861e1aSahl 	EZFS_SHARENFSFAILED,	/* share(1M) failed */
8899653d4eSeschrock 	EZFS_DEVLINKS,		/* failed to create zvol links */
8999653d4eSeschrock 	EZFS_PERM,		/* permission denied */
9099653d4eSeschrock 	EZFS_NOSPC,		/* out of space */
9199653d4eSeschrock 	EZFS_IO,		/* I/O error */
9299653d4eSeschrock 	EZFS_INTR,		/* signal received */
9399653d4eSeschrock 	EZFS_ISSPARE,		/* device is a hot spare */
9499653d4eSeschrock 	EZFS_INVALCONFIG,	/* invalid vdev configuration */
953bb79becSeschrock 	EZFS_RECURSIVE,		/* recursive dependency */
9606eeb2adSek 	EZFS_NOHISTORY,		/* no history object */
97f3861e1aSahl 	EZFS_UNSHAREISCSIFAILED, /* iscsitgtd failed request to unshare */
98f3861e1aSahl 	EZFS_SHAREISCSIFAILED,	/* iscsitgtd failed request to share */
99b1b8ab34Slling 	EZFS_POOLPROPS,		/* couldn't retrieve pool props */
100b1b8ab34Slling 	EZFS_POOL_NOTSUP,	/* ops not supported for this type of pool */
101b1b8ab34Slling 	EZFS_POOL_INVALARG,	/* invalid argument for this pool operation */
102b7661cccSmmusante 	EZFS_NAMETOOLONG,	/* dataset name is too long */
1038488aeb5Staylor 	EZFS_OPENFAILED,	/* open of device failed */
1048488aeb5Staylor 	EZFS_NOCAP,		/* couldn't get capacity */
1058488aeb5Staylor 	EZFS_LABELFAILED,	/* write of label failed */
106ecd6cf80Smarks 	EZFS_ISCSISVCUNAVAIL,	/* iscsi service unavailable */
107ecd6cf80Smarks 	EZFS_BADWHO,		/* invalid permission who */
108ecd6cf80Smarks 	EZFS_BADPERM,		/* invalid permission */
109ecd6cf80Smarks 	EZFS_BADPERMSET,	/* invalid permission set name */
110ecd6cf80Smarks 	EZFS_NODELEGATION,	/* delegated administration is disabled */
111ecd6cf80Smarks 	EZFS_PERMRDONLY,	/* pemissions are readonly */
112da6c28aaSamw 	EZFS_UNSHARESMBFAILED,	/* failed to unshare over smb */
113da6c28aaSamw 	EZFS_SHARESMBFAILED,	/* failed to share over smb */
1142f8aaab3Seschrock 	EZFS_BADCACHE,		/* bad cache file */
115fa94a07fSbrendan 	EZFS_ISL2CACHE,		/* device is for the level 2 ARC */
116e7cbe64fSgw 	EZFS_VDEVNOTSUP,	/* unsupported vdev type */
11715e6edf1Sgw 	EZFS_NOTSUP,		/* ops not supported on this dataset */
11889a89ebfSlling 	EZFS_ACTIVE_SPARE,	/* pool has active shared spare devices */
119b1b8ab34Slling 	EZFS_UNKNOWN
12099653d4eSeschrock };
12199653d4eSeschrock 
122ecd6cf80Smarks /*
123ecd6cf80Smarks  * The following data structures are all part
124ecd6cf80Smarks  * of the zfs_allow_t data structure which is
125ecd6cf80Smarks  * used for printing 'allow' permissions.
126ecd6cf80Smarks  * It is a linked list of zfs_allow_t's which
127ecd6cf80Smarks  * then contain avl tree's for user/group/sets/...
128ecd6cf80Smarks  * and each one of the entries in those trees have
129ecd6cf80Smarks  * avl tree's for the permissions they belong to and
130ecd6cf80Smarks  * whether they are local,descendent or local+descendent
131ecd6cf80Smarks  * permissions.  The AVL trees are used primarily for
132ecd6cf80Smarks  * sorting purposes, but also so that we can quickly find
133ecd6cf80Smarks  * a given user and or permission.
134ecd6cf80Smarks  */
135ecd6cf80Smarks typedef struct zfs_perm_node {
136ecd6cf80Smarks 	avl_node_t z_node;
137ecd6cf80Smarks 	char z_pname[MAXPATHLEN];
138ecd6cf80Smarks } zfs_perm_node_t;
139ecd6cf80Smarks 
140ecd6cf80Smarks typedef struct zfs_allow_node {
141ecd6cf80Smarks 	avl_node_t z_node;
142ecd6cf80Smarks 	char z_key[MAXPATHLEN];		/* name, such as joe */
143ecd6cf80Smarks 	avl_tree_t z_localdescend;	/* local+descendent perms */
144ecd6cf80Smarks 	avl_tree_t z_local;		/* local permissions */
145ecd6cf80Smarks 	avl_tree_t z_descend;		/* descendent permissions */
146ecd6cf80Smarks } zfs_allow_node_t;
147ecd6cf80Smarks 
148ecd6cf80Smarks typedef struct zfs_allow {
149ecd6cf80Smarks 	struct zfs_allow *z_next;
150ecd6cf80Smarks 	char z_setpoint[MAXPATHLEN];
151ecd6cf80Smarks 	avl_tree_t z_sets;
152ecd6cf80Smarks 	avl_tree_t z_crperms;
153ecd6cf80Smarks 	avl_tree_t z_user;
154ecd6cf80Smarks 	avl_tree_t z_group;
155ecd6cf80Smarks 	avl_tree_t z_everyone;
156ecd6cf80Smarks } zfs_allow_t;
157ecd6cf80Smarks 
158fa9e4066Sahrens /*
159fa9e4066Sahrens  * Basic handle types
160fa9e4066Sahrens  */
161fa9e4066Sahrens typedef struct zfs_handle zfs_handle_t;
162fa9e4066Sahrens typedef struct zpool_handle zpool_handle_t;
16399653d4eSeschrock typedef struct libzfs_handle libzfs_handle_t;
16499653d4eSeschrock 
16599653d4eSeschrock /*
16699653d4eSeschrock  * Library initialization
16799653d4eSeschrock  */
16899653d4eSeschrock extern libzfs_handle_t *libzfs_init(void);
16999653d4eSeschrock extern void libzfs_fini(libzfs_handle_t *);
17099653d4eSeschrock 
17199653d4eSeschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
17299653d4eSeschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
17399653d4eSeschrock 
17499653d4eSeschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
17599653d4eSeschrock 
17699653d4eSeschrock extern int libzfs_errno(libzfs_handle_t *);
17799653d4eSeschrock extern const char *libzfs_error_action(libzfs_handle_t *);
17899653d4eSeschrock extern const char *libzfs_error_description(libzfs_handle_t *);
179ebedde84SEric Taylor extern void libzfs_mnttab_init(libzfs_handle_t *);
180ebedde84SEric Taylor extern void libzfs_mnttab_fini(libzfs_handle_t *);
181ebedde84SEric Taylor extern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
182ebedde84SEric Taylor     struct mnttab *);
183ebedde84SEric Taylor extern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
184ebedde84SEric Taylor     const char *, const char *);
185ebedde84SEric Taylor extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
186fa9e4066Sahrens 
187fa9e4066Sahrens /*
188fa9e4066Sahrens  * Basic handle functions
189fa9e4066Sahrens  */
19099653d4eSeschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
19199653d4eSeschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
192fa9e4066Sahrens extern void zpool_close(zpool_handle_t *);
193fa9e4066Sahrens extern const char *zpool_get_name(zpool_handle_t *);
194fa9e4066Sahrens extern int zpool_get_state(zpool_handle_t *);
195990b4856Slling extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
19629ab75c9Srm extern void zpool_free_handles(libzfs_handle_t *);
197fa9e4066Sahrens 
198fa9e4066Sahrens /*
199fa9e4066Sahrens  * Iterate over all active pools in the system.
200fa9e4066Sahrens  */
201fa9e4066Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
20299653d4eSeschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
203fa9e4066Sahrens 
204fa9e4066Sahrens /*
205fa9e4066Sahrens  * Functions to create and destroy pools
206fa9e4066Sahrens  */
20799653d4eSeschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
2080a48a24eStimh     nvlist_t *, nvlist_t *);
209fa9e4066Sahrens extern int zpool_destroy(zpool_handle_t *);
210fa9e4066Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *);
211fa9e4066Sahrens 
212fa9e4066Sahrens /*
213fa9e4066Sahrens  * Functions to manipulate pool and vdev state
214fa9e4066Sahrens  */
215fa9e4066Sahrens extern int zpool_scrub(zpool_handle_t *, pool_scrub_type_t);
2163d7072f8Seschrock extern int zpool_clear(zpool_handle_t *, const char *);
217fa9e4066Sahrens 
2183d7072f8Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
2193d7072f8Seschrock     vdev_state_t *);
2203d7072f8Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
2213d7072f8Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *,
2223d7072f8Seschrock     const char *, nvlist_t *, int);
223fa9e4066Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *);
22499653d4eSeschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *);
2253d7072f8Seschrock 
2263d7072f8Seschrock extern int zpool_vdev_fault(zpool_handle_t *, uint64_t);
2273d7072f8Seschrock extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t);
2283d7072f8Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
2293d7072f8Seschrock 
230fa94a07fSbrendan extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *,
231ee0eb9f2SEric Schrock     boolean_t *, boolean_t *);
2328488aeb5Staylor extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *);
233fa9e4066Sahrens 
234b1b8ab34Slling /*
235b1b8ab34Slling  * Functions to manage pool properties
236b1b8ab34Slling  */
237b1b8ab34Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
2383d7072f8Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
239990b4856Slling     size_t proplen, zprop_source_t *);
240990b4856Slling extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t,
241990b4856Slling     zprop_source_t *);
242990b4856Slling 
243b1b8ab34Slling extern const char *zpool_prop_to_name(zpool_prop_t);
244b1b8ab34Slling extern const char *zpool_prop_values(zpool_prop_t);
245b1b8ab34Slling 
246fa9e4066Sahrens /*
247fa9e4066Sahrens  * Pool health statistics.
248fa9e4066Sahrens  */
249fa9e4066Sahrens typedef enum {
250fa9e4066Sahrens 	/*
251fa9e4066Sahrens 	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
252b81d61a6Slling 	 * event namespace.  Each is associated with a corresponding message ID.
253fa9e4066Sahrens 	 */
254fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
255fa9e4066Sahrens 	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
256fa9e4066Sahrens 	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
257fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
258b81d61a6Slling 	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device label with no replicas */
259fa9e4066Sahrens 	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
260fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
261fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
262fa9e4066Sahrens 	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
263eaca9bbdSeschrock 	ZPOOL_STATUS_VERSION_NEWER,	/* newer on-disk version */
26495173954Sek 	ZPOOL_STATUS_HOSTID_MISMATCH,	/* last accessed by another system */
26532b87932Sek 	ZPOOL_STATUS_IO_FAILURE_WAIT,	/* failed I/O, failmode 'wait' */
26632b87932Sek 	ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */
267*f67f35c3SEric Schrock 	ZPOOL_STATUS_BAD_LOG,		/* cannot read log chain(s) */
268*f67f35c3SEric Schrock 
269*f67f35c3SEric Schrock 	/*
270*f67f35c3SEric Schrock 	 * These faults have no corresponding message ID.  At the time we are
271*f67f35c3SEric Schrock 	 * checking the status, the original reason for the FMA fault (I/O or
272*f67f35c3SEric Schrock 	 * checksum errors) has been lost.
273*f67f35c3SEric Schrock 	 */
2743d7072f8Seschrock 	ZPOOL_STATUS_FAULTED_DEV_R,	/* faulted device with replicas */
2753d7072f8Seschrock 	ZPOOL_STATUS_FAULTED_DEV_NR,	/* faulted device with no replicas */
276fa9e4066Sahrens 
277fa9e4066Sahrens 	/*
278fa9e4066Sahrens 	 * The following are not faults per se, but still an error possibly
279b81d61a6Slling 	 * requiring administrative attention.  There is no corresponding
280fa9e4066Sahrens 	 * message ID.
281fa9e4066Sahrens 	 */
282eaca9bbdSeschrock 	ZPOOL_STATUS_VERSION_OLDER,	/* older on-disk version */
283fa9e4066Sahrens 	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
284fa9e4066Sahrens 	ZPOOL_STATUS_OFFLINE_DEV,	/* device online */
285fa9e4066Sahrens 
286fa9e4066Sahrens 	/*
287fa9e4066Sahrens 	 * Finally, the following indicates a healthy pool.
288fa9e4066Sahrens 	 */
289fa9e4066Sahrens 	ZPOOL_STATUS_OK
290fa9e4066Sahrens } zpool_status_t;
291fa9e4066Sahrens 
292ea8dc4b6Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **);
293ea8dc4b6Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **);
294fa9e4066Sahrens 
295fa9e4066Sahrens /*
296fa9e4066Sahrens  * Statistics and configuration functions.
297fa9e4066Sahrens  */
298ea8dc4b6Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
29994de1d4cSeschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
30055434c77Sek extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
301ea8dc4b6Seschrock 
302fa9e4066Sahrens /*
303fa9e4066Sahrens  * Import and export functions
304fa9e4066Sahrens  */
30589a89ebfSlling extern int zpool_export(zpool_handle_t *, boolean_t);
306394ab0cbSGeorge Wilson extern int zpool_export_force(zpool_handle_t *);
30799653d4eSeschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
308990b4856Slling     char *altroot);
309990b4856Slling extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
310c5904d13Seschrock     nvlist_t *, boolean_t);
311fa9e4066Sahrens 
312fa9e4066Sahrens /*
313fa9e4066Sahrens  * Search for pools to import
314fa9e4066Sahrens  */
31524e697d4Sck extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
3163a57275aSck extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *,
317e829d913Sck     char *, uint64_t);
31824e697d4Sck extern nvlist_t *zpool_find_import_byname(libzfs_handle_t *, int, char **,
31924e697d4Sck     char *);
32024e697d4Sck extern nvlist_t *zpool_find_import_byguid(libzfs_handle_t *, int, char **,
32124e697d4Sck     uint64_t);
32224e697d4Sck extern nvlist_t *zpool_find_import_activeok(libzfs_handle_t *, int, char **);
323fa9e4066Sahrens 
324c67d9675Seschrock /*
325c67d9675Seschrock  * Miscellaneous pool functions
326c67d9675Seschrock  */
327ecd6cf80Smarks struct zfs_cmd;
328ecd6cf80Smarks 
32999653d4eSeschrock extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *);
330990b4856Slling extern int zpool_upgrade(zpool_handle_t *, uint64_t);
33106eeb2adSek extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
3322a6b87f0Sek extern void zpool_set_history_str(const char *subcommand, int argc,
3332a6b87f0Sek     char **argv, char *history_str);
3342a6b87f0Sek extern int zpool_stage_history(libzfs_handle_t *, const char *);
33555434c77Sek extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
33655434c77Sek     size_t len);
337ecd6cf80Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
33819397407SSherry Moore extern int zpool_get_physpath(zpool_handle_t *, char *);
339fa9e4066Sahrens /*
340fa9e4066Sahrens  * Basic handle manipulations.  These functions do not create or destroy the
341fa9e4066Sahrens  * underlying datasets, only the references to them.
342fa9e4066Sahrens  */
34399653d4eSeschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
344fa9e4066Sahrens extern void zfs_close(zfs_handle_t *);
345fa9e4066Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *);
346fa9e4066Sahrens extern const char *zfs_get_name(const zfs_handle_t *);
347d5b5bb25SRich Morris extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
348fa9e4066Sahrens 
349fa9e4066Sahrens /*
350fa9e4066Sahrens  * Property management functions.  Some functions are shared with the kernel,
351b81d61a6Slling  * and are found in sys/fs/zfs.h.
352fa9e4066Sahrens  */
353990b4856Slling 
354990b4856Slling /*
355990b4856Slling  * zfs dataset property management
356990b4856Slling  */
357990b4856Slling extern const char *zfs_prop_default_string(zfs_prop_t);
358990b4856Slling extern uint64_t zfs_prop_default_numeric(zfs_prop_t);
359990b4856Slling extern const char *zfs_prop_column_name(zfs_prop_t);
360990b4856Slling extern boolean_t zfs_prop_align_right(zfs_prop_t);
361990b4856Slling 
3620a48a24eStimh extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t,
3630a48a24eStimh     nvlist_t *, uint64_t, zfs_handle_t *, const char *);
3640a48a24eStimh 
365e9dbad6fSeschrock extern const char *zfs_prop_to_name(zfs_prop_t);
366e9dbad6fSeschrock extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
367e9dbad6fSeschrock extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
368990b4856Slling     zprop_source_t *, char *, size_t, boolean_t);
369e9dbad6fSeschrock extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
370990b4856Slling     zprop_source_t *, char *, size_t);
371e9dbad6fSeschrock extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
372e9dbad6fSeschrock extern int zfs_prop_inherit(zfs_handle_t *, const char *);
373e9dbad6fSeschrock extern const char *zfs_prop_values(zfs_prop_t);
374e9dbad6fSeschrock extern int zfs_prop_is_string(zfs_prop_t prop);
375990b4856Slling extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
376e9dbad6fSeschrock 
377990b4856Slling typedef struct zprop_list {
378990b4856Slling 	int		pl_prop;
379e9dbad6fSeschrock 	char		*pl_user_prop;
380990b4856Slling 	struct zprop_list *pl_next;
381e9dbad6fSeschrock 	boolean_t	pl_all;
382e9dbad6fSeschrock 	size_t		pl_width;
383e9dbad6fSeschrock 	boolean_t	pl_fixed;
384990b4856Slling } zprop_list_t;
385e9dbad6fSeschrock 
386990b4856Slling extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **);
387fa9e4066Sahrens 
388fa9e4066Sahrens #define	ZFS_MOUNTPOINT_NONE	"none"
389fa9e4066Sahrens #define	ZFS_MOUNTPOINT_LEGACY	"legacy"
390fa9e4066Sahrens 
391b1b8ab34Slling /*
392990b4856Slling  * zpool property management
393990b4856Slling  */
394990b4856Slling extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **);
395990b4856Slling extern const char *zpool_prop_default_string(zpool_prop_t);
396990b4856Slling extern uint64_t zpool_prop_default_numeric(zpool_prop_t);
397990b4856Slling extern const char *zpool_prop_column_name(zpool_prop_t);
398990b4856Slling extern boolean_t zpool_prop_align_right(zpool_prop_t);
399990b4856Slling 
400990b4856Slling /*
401990b4856Slling  * Functions shared by zfs and zpool property management.
402b1b8ab34Slling  */
403990b4856Slling extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all,
404990b4856Slling     boolean_t ordered, zfs_type_t type);
405990b4856Slling extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **,
406990b4856Slling     zfs_type_t);
407990b4856Slling extern void zprop_free_list(zprop_list_t *);
408990b4856Slling 
409990b4856Slling /*
410990b4856Slling  * Functions for printing zfs or zpool properties
411990b4856Slling  */
412990b4856Slling typedef struct zprop_get_cbdata {
413b1b8ab34Slling 	int cb_sources;
414b1b8ab34Slling 	int cb_columns[4];
415b1b8ab34Slling 	int cb_colwidths[5];
416b1b8ab34Slling 	boolean_t cb_scripted;
417b1b8ab34Slling 	boolean_t cb_literal;
418b1b8ab34Slling 	boolean_t cb_first;
419990b4856Slling 	zprop_list_t *cb_proplist;
420990b4856Slling 	zfs_type_t cb_type;
421990b4856Slling } zprop_get_cbdata_t;
422b1b8ab34Slling 
423990b4856Slling void zprop_print_one_property(const char *, zprop_get_cbdata_t *,
424990b4856Slling     const char *, const char *, zprop_source_t, const char *);
425b1b8ab34Slling 
426b1b8ab34Slling #define	GET_COL_NAME		1
427b1b8ab34Slling #define	GET_COL_PROPERTY	2
428b1b8ab34Slling #define	GET_COL_VALUE		3
429b1b8ab34Slling #define	GET_COL_SOURCE		4
430b1b8ab34Slling 
431fa9e4066Sahrens /*
432fa9e4066Sahrens  * Iterator functions.
433fa9e4066Sahrens  */
434fa9e4066Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
43599653d4eSeschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
436fa9e4066Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
4373bb79becSeschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
4387f7322feSeschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
4397f7322feSeschrock extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *);
440fa9e4066Sahrens 
441fa9e4066Sahrens /*
442fa9e4066Sahrens  * Functions to create and destroy datasets.
443fa9e4066Sahrens  */
44499653d4eSeschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
445e9dbad6fSeschrock     nvlist_t *);
4467f1f55eaSvb extern int zfs_create_ancestors(libzfs_handle_t *, const char *);
447fa9e4066Sahrens extern int zfs_destroy(zfs_handle_t *);
4481d452cf5Sahrens extern int zfs_destroy_snaps(zfs_handle_t *, char *);
449e9dbad6fSeschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
450bb0ade09Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
451c391e322Sahrens extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
4527f1f55eaSvb extern int zfs_rename(zfs_handle_t *, const char *, boolean_t);
4533cb34c60Sahrens extern int zfs_send(zfs_handle_t *, const char *, const char *,
4543cb34c60Sahrens     boolean_t, boolean_t, boolean_t, boolean_t, int);
45599653d4eSeschrock extern int zfs_promote(zfs_handle_t *);
456fa9e4066Sahrens 
4573cb34c60Sahrens typedef struct recvflags {
4584ccbb6e7Sahrens 	/* print informational messages (ie, -v was specified) */
459c6765aabSeschrock 	int verbose : 1;
4604ccbb6e7Sahrens 
4614ccbb6e7Sahrens 	/* the destination is a prefix, not the exact fs (ie, -d) */
462c6765aabSeschrock 	int isprefix : 1;
4634ccbb6e7Sahrens 
4644ccbb6e7Sahrens 	/* do not actually do the recv, just check if it would work (ie, -n) */
465c6765aabSeschrock 	int dryrun : 1;
4664ccbb6e7Sahrens 
4674ccbb6e7Sahrens 	/* rollback/destroy filesystems as necessary (eg, -F) */
468c6765aabSeschrock 	int force : 1;
4694ccbb6e7Sahrens 
4704ccbb6e7Sahrens 	/* set "canmount=off" on all modified filesystems */
471c6765aabSeschrock 	int canmountoff : 1;
4724ccbb6e7Sahrens 
4734ccbb6e7Sahrens 	/* byteswap flag is used internally; callers need not specify */
474c6765aabSeschrock 	int byteswap : 1;
4753cb34c60Sahrens } recvflags_t;
4763cb34c60Sahrens 
4773cb34c60Sahrens extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t,
4783cb34c60Sahrens     int, avl_tree_t *);
4793cb34c60Sahrens 
480fa9e4066Sahrens /*
481fa9e4066Sahrens  * Miscellaneous functions.
482fa9e4066Sahrens  */
483fa9e4066Sahrens extern const char *zfs_type_to_name(zfs_type_t);
484fa9e4066Sahrens extern void zfs_refresh_properties(zfs_handle_t *);
485fa9e4066Sahrens extern int zfs_name_valid(const char *, zfs_type_t);
4865aba80dbSck extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t);
4877f1f55eaSvb extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *,
4887f1f55eaSvb     zfs_type_t);
4897b97dc1aSrm extern int zfs_spa_version(zfs_handle_t *, int *);
490fa9e4066Sahrens 
491ecd6cf80Smarks /*
492ecd6cf80Smarks  * dataset permission functions.
493ecd6cf80Smarks  */
494ecd6cf80Smarks extern int zfs_perm_set(zfs_handle_t *, nvlist_t *);
495ecd6cf80Smarks extern int zfs_perm_remove(zfs_handle_t *, nvlist_t *);
496ecd6cf80Smarks extern int zfs_build_perms(zfs_handle_t *, char *, char *,
497ecd6cf80Smarks     zfs_deleg_who_type_t, zfs_deleg_inherit_t, nvlist_t **nvlist_t);
498ecd6cf80Smarks extern int zfs_perm_get(zfs_handle_t *, zfs_allow_t **);
499ecd6cf80Smarks extern void zfs_free_allows(zfs_allow_t *);
5006949a980Smarks extern void zfs_deleg_permissions(void);
501ecd6cf80Smarks 
502fa9e4066Sahrens /*
503fa9e4066Sahrens  * Mount support functions.
504fa9e4066Sahrens  */
50555434c77Sek extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **);
50699653d4eSeschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **);
507fa9e4066Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int);
508fa9e4066Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int);
509fa9e4066Sahrens extern int zfs_unmountall(zfs_handle_t *, int);
510fa9e4066Sahrens 
511fa9e4066Sahrens /*
512fa9e4066Sahrens  * Share support functions.
513fa9e4066Sahrens  */
514f3861e1aSahl extern boolean_t zfs_is_shared(zfs_handle_t *);
515fa9e4066Sahrens extern int zfs_share(zfs_handle_t *);
516f3861e1aSahl extern int zfs_unshare(zfs_handle_t *);
517f3861e1aSahl 
518f3861e1aSahl /*
5193d7072f8Seschrock  * Protocol-specific share support functions.
520f3861e1aSahl  */
521f3861e1aSahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **);
522da6c28aaSamw extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **);
523f3861e1aSahl extern int zfs_share_nfs(zfs_handle_t *);
524da6c28aaSamw extern int zfs_share_smb(zfs_handle_t *);
525da6c28aaSamw extern int zfs_shareall(zfs_handle_t *);
526f3861e1aSahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *);
527da6c28aaSamw extern int zfs_unshare_smb(zfs_handle_t *, const char *);
528f3861e1aSahl extern int zfs_unshareall_nfs(zfs_handle_t *);
529da6c28aaSamw extern int zfs_unshareall_smb(zfs_handle_t *);
530da6c28aaSamw extern int zfs_unshareall_bypath(zfs_handle_t *, const char *);
531da6c28aaSamw extern int zfs_unshareall(zfs_handle_t *);
532f3861e1aSahl extern boolean_t zfs_is_shared_iscsi(zfs_handle_t *);
533f3861e1aSahl extern int zfs_share_iscsi(zfs_handle_t *);
534f3861e1aSahl extern int zfs_unshare_iscsi(zfs_handle_t *);
535ecd6cf80Smarks extern int zfs_iscsi_perm_check(libzfs_handle_t *, char *, ucred_t *);
536ecd6cf80Smarks extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *,
537da6c28aaSamw     void *, void *, int, zfs_share_op_t);
538fa9e4066Sahrens 
539fa9e4066Sahrens /*
540fa9e4066Sahrens  * When dealing with nvlists, verify() is extremely useful
541fa9e4066Sahrens  */
542fa9e4066Sahrens #ifdef NDEBUG
543fa9e4066Sahrens #define	verify(EX)	((void)(EX))
544fa9e4066Sahrens #else
545fa9e4066Sahrens #define	verify(EX)	assert(EX)
546fa9e4066Sahrens #endif
547fa9e4066Sahrens 
548fa9e4066Sahrens /*
549fa9e4066Sahrens  * Utility function to convert a number to a human-readable form.
550fa9e4066Sahrens  */
551fa9e4066Sahrens extern void zfs_nicenum(uint64_t, char *, size_t);
552e9dbad6fSeschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
553fa9e4066Sahrens 
554fa9e4066Sahrens /*
555fa9e4066Sahrens  * Given a device or file, determine if it is part of a pool.
556fa9e4066Sahrens  */
55799653d4eSeschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **,
55899653d4eSeschrock     boolean_t *);
559fa9e4066Sahrens 
560fa9e4066Sahrens /*
561fa9e4066Sahrens  * ftyp special.  Read the label from a given device.
562fa9e4066Sahrens  */
56399653d4eSeschrock extern int zpool_read_label(int, nvlist_t **);
564fa9e4066Sahrens 
565fa9e4066Sahrens /*
566f3861e1aSahl  * Create and remove zvol /dev links.
567fa9e4066Sahrens  */
568fa9e4066Sahrens extern int zpool_create_zvol_links(zpool_handle_t *);
569fa9e4066Sahrens extern int zpool_remove_zvol_links(zpool_handle_t *);
570fa9e4066Sahrens 
571e7cbe64fSgw /* is this zvol valid for use as a dump device? */
572e7cbe64fSgw extern int zvol_check_dump_config(char *);
573e7cbe64fSgw 
5743bb79becSeschrock /*
575f3861e1aSahl  * Enable and disable datasets within a pool by mounting/unmounting and
576f3861e1aSahl  * sharing/unsharing them.
5773bb79becSeschrock  */
578f3861e1aSahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int);
579f3861e1aSahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t);
5803bb79becSeschrock 
581fa9e4066Sahrens #ifdef	__cplusplus
582fa9e4066Sahrens }
583fa9e4066Sahrens #endif
584fa9e4066Sahrens 
585fa9e4066Sahrens #endif	/* _LIBZFS_H */
586