xref: /illumos-gate/usr/src/lib/libzfs/common/libzfs.h (revision e0f1c0afa46cc84d4b1e40124032a9a87310386e)
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 /*
233f9d6ad7SLin Ling  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
240d8fa8f8SMartin Matuska  * Copyright (c) 2011 Pawel Jakub Dawidek. All rights reserved.
255cabbc6bSPrashanth Sreenivasa  * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
26*e0f1c0afSOlaf Faaland  * Copyright 2019 Joyent, Inc.
27a7a845e4SSteven Hartland  * Copyright (c) 2013 Steven Hartland. All rights reserved.
28c3d26abcSMatthew Ahrens  * Copyright (c) 2014 Integros [integros.com]
298808ac5dSYuri Pankov  * Copyright 2016 Nexenta Systems, Inc.
301702cce7SAlek Pinchuk  * Copyright (c) 2017 Datto Inc.
31fa9e4066Sahrens  */
32fa9e4066Sahrens 
33fa9e4066Sahrens #ifndef	_LIBZFS_H
34fa9e4066Sahrens #define	_LIBZFS_H
35fa9e4066Sahrens 
36fa9e4066Sahrens #include <assert.h>
37fa9e4066Sahrens #include <libnvpair.h>
38ebedde84SEric Taylor #include <sys/mnttab.h>
39fa9e4066Sahrens #include <sys/param.h>
40fa9e4066Sahrens #include <sys/types.h>
41fa9e4066Sahrens #include <sys/varargs.h>
42fa9e4066Sahrens #include <sys/fs/zfs.h>
43ecd6cf80Smarks #include <sys/avl.h>
44ecd6cf80Smarks #include <ucred.h>
455d7b4d43SMatthew Ahrens #include <libzfs_core.h>
46fa9e4066Sahrens 
47fa9e4066Sahrens #ifdef	__cplusplus
48fa9e4066Sahrens extern "C" {
49fa9e4066Sahrens #endif
50fa9e4066Sahrens 
51fa9e4066Sahrens /*
52fa9e4066Sahrens  * Miscellaneous ZFS constants
53fa9e4066Sahrens  */
54fa9e4066Sahrens #define	ZFS_MAXPROPLEN		MAXPATHLEN
55990b4856Slling #define	ZPOOL_MAXPROPLEN	MAXPATHLEN
56fa9e4066Sahrens 
5799653d4eSeschrock /*
5899653d4eSeschrock  * libzfs errors
5999653d4eSeschrock  */
604445fffbSMatthew Ahrens typedef enum zfs_error {
614445fffbSMatthew Ahrens 	EZFS_SUCCESS = 0,	/* no error -- success */
6299653d4eSeschrock 	EZFS_NOMEM = 2000,	/* out of memory */
6399653d4eSeschrock 	EZFS_BADPROP,		/* invalid property value */
6499653d4eSeschrock 	EZFS_PROPREADONLY,	/* cannot set readonly property */
6599653d4eSeschrock 	EZFS_PROPTYPE,		/* property does not apply to dataset type */
6699653d4eSeschrock 	EZFS_PROPNONINHERIT,	/* property is not inheritable */
6799653d4eSeschrock 	EZFS_PROPSPACE,		/* bad quota or reservation */
6899653d4eSeschrock 	EZFS_BADTYPE,		/* dataset is not of appropriate type */
6999653d4eSeschrock 	EZFS_BUSY,		/* pool or dataset is busy */
7099653d4eSeschrock 	EZFS_EXISTS,		/* pool or dataset already exists */
7199653d4eSeschrock 	EZFS_NOENT,		/* no such pool or dataset */
7299653d4eSeschrock 	EZFS_BADSTREAM,		/* bad backup stream */
7399653d4eSeschrock 	EZFS_DSREADONLY,	/* dataset is readonly */
7499653d4eSeschrock 	EZFS_VOLTOOBIG,		/* volume is too large for 32-bit system */
7599653d4eSeschrock 	EZFS_INVALIDNAME,	/* invalid dataset name */
7699653d4eSeschrock 	EZFS_BADRESTORE,	/* unable to restore to destination */
7799653d4eSeschrock 	EZFS_BADBACKUP,		/* backup failed */
7899653d4eSeschrock 	EZFS_BADTARGET,		/* bad attach/detach/replace target */
7999653d4eSeschrock 	EZFS_NODEVICE,		/* no such device in pool */
8099653d4eSeschrock 	EZFS_BADDEV,		/* invalid device to add */
8199653d4eSeschrock 	EZFS_NOREPLICAS,	/* no valid replicas */
8299653d4eSeschrock 	EZFS_RESILVERING,	/* currently resilvering */
8399653d4eSeschrock 	EZFS_BADVERSION,	/* unsupported version */
8499653d4eSeschrock 	EZFS_POOLUNAVAIL,	/* pool is currently unavailable */
8599653d4eSeschrock 	EZFS_DEVOVERFLOW,	/* too many devices in one vdev */
8699653d4eSeschrock 	EZFS_BADPATH,		/* must be an absolute path */
8799653d4eSeschrock 	EZFS_CROSSTARGET,	/* rename or clone across pool or dataset */
8899653d4eSeschrock 	EZFS_ZONED,		/* used improperly in local zone */
8999653d4eSeschrock 	EZFS_MOUNTFAILED,	/* failed to mount dataset */
9099653d4eSeschrock 	EZFS_UMOUNTFAILED,	/* failed to unmount dataset */
91f3861e1aSahl 	EZFS_UNSHARENFSFAILED,	/* unshare(1M) failed */
92f3861e1aSahl 	EZFS_SHARENFSFAILED,	/* share(1M) failed */
9399653d4eSeschrock 	EZFS_PERM,		/* permission denied */
9499653d4eSeschrock 	EZFS_NOSPC,		/* out of space */
956e27f868SSam Falkner 	EZFS_FAULT,		/* bad address */
9699653d4eSeschrock 	EZFS_IO,		/* I/O error */
9799653d4eSeschrock 	EZFS_INTR,		/* signal received */
9899653d4eSeschrock 	EZFS_ISSPARE,		/* device is a hot spare */
9999653d4eSeschrock 	EZFS_INVALCONFIG,	/* invalid vdev configuration */
1003bb79becSeschrock 	EZFS_RECURSIVE,		/* recursive dependency */
10106eeb2adSek 	EZFS_NOHISTORY,		/* no history object */
102b1b8ab34Slling 	EZFS_POOLPROPS,		/* couldn't retrieve pool props */
103b1b8ab34Slling 	EZFS_POOL_NOTSUP,	/* ops not supported for this type of pool */
104b1b8ab34Slling 	EZFS_POOL_INVALARG,	/* invalid argument for this pool operation */
105b7661cccSmmusante 	EZFS_NAMETOOLONG,	/* dataset name is too long */
1068488aeb5Staylor 	EZFS_OPENFAILED,	/* open of device failed */
1078488aeb5Staylor 	EZFS_NOCAP,		/* couldn't get capacity */
1088488aeb5Staylor 	EZFS_LABELFAILED,	/* write of label failed */
109ecd6cf80Smarks 	EZFS_BADWHO,		/* invalid permission who */
110ecd6cf80Smarks 	EZFS_BADPERM,		/* invalid permission */
111ecd6cf80Smarks 	EZFS_BADPERMSET,	/* invalid permission set name */
112ecd6cf80Smarks 	EZFS_NODELEGATION,	/* delegated administration is disabled */
113da6c28aaSamw 	EZFS_UNSHARESMBFAILED,	/* failed to unshare over smb */
114da6c28aaSamw 	EZFS_SHARESMBFAILED,	/* failed to share over smb */
1152f8aaab3Seschrock 	EZFS_BADCACHE,		/* bad cache file */
116fa94a07fSbrendan 	EZFS_ISL2CACHE,		/* device is for the level 2 ARC */
117e7cbe64fSgw 	EZFS_VDEVNOTSUP,	/* unsupported vdev type */
11815e6edf1Sgw 	EZFS_NOTSUP,		/* ops not supported on this dataset */
11989a89ebfSlling 	EZFS_ACTIVE_SPARE,	/* pool has active shared spare devices */
120e6ca193dSGeorge Wilson 	EZFS_UNPLAYED_LOGS,	/* log device has unplayed logs */
121842727c2SChris Kirby 	EZFS_REFTAG_RELE,	/* snapshot release: tag not found */
122842727c2SChris Kirby 	EZFS_REFTAG_HOLD,	/* snapshot hold: tag already exists */
123ca45db41SChris Kirby 	EZFS_TAGTOOLONG,	/* snapshot hold/rele: tag too long */
1249e69d7d0SLori Alt 	EZFS_PIPEFAILED,	/* pipe create failed */
1259e69d7d0SLori Alt 	EZFS_THREADCREATEFAILED, /* thread create failed */
1261195e687SMark J Musante 	EZFS_POSTSPLIT_ONLINE,	/* onlining a disk after splitting it */
1273f9d6ad7SLin Ling 	EZFS_SCRUBBING,		/* currently scrubbing */
1283f9d6ad7SLin Ling 	EZFS_NO_SCRUB,		/* no active scrub */
12999d5e173STim Haley 	EZFS_DIFF,		/* general failure of zfs diff */
13099d5e173STim Haley 	EZFS_DIFFDATA,		/* bad zfs diff data */
131f9af39baSGeorge Wilson 	EZFS_POOLREADONLY,	/* pool is in read-only mode */
1321702cce7SAlek Pinchuk 	EZFS_SCRUB_PAUSED,	/* scrub currently paused */
133*e0f1c0afSOlaf Faaland 	EZFS_ACTIVE_POOL,	/* pool is imported on a different system */
1345cabbc6bSPrashanth Sreenivasa 	EZFS_NO_PENDING,	/* cannot cancel, no operation is pending */
13586714001SSerapheim Dimitropoulos 	EZFS_CHECKPOINT_EXISTS,	/* checkpoint exists */
13686714001SSerapheim Dimitropoulos 	EZFS_DISCARDING_CHECKPOINT,	/* currently discarding a checkpoint */
13786714001SSerapheim Dimitropoulos 	EZFS_NO_CHECKPOINT,	/* pool has no checkpoint */
13886714001SSerapheim Dimitropoulos 	EZFS_DEVRM_IN_PROGRESS,	/* a device is currently being removed */
13986714001SSerapheim Dimitropoulos 	EZFS_VDEV_TOO_BIG,	/* a device is too big to be used */
140094e47e9SGeorge Wilson 	EZFS_TOOMANY,		/* argument list too long */
141094e47e9SGeorge Wilson 	EZFS_INITIALIZING,	/* currently initializing */
142094e47e9SGeorge Wilson 	EZFS_NO_INITIALIZE,	/* no active initialize */
143b1b8ab34Slling 	EZFS_UNKNOWN
1444445fffbSMatthew Ahrens } zfs_error_t;
14599653d4eSeschrock 
1467855d95bSToomas Soome /*
1477855d95bSToomas Soome  * UEFI boot support parameters. When creating whole disk boot pool,
1487855d95bSToomas Soome  * zpool create should allow to create EFI System partition for UEFI boot
1497855d95bSToomas Soome  * program. In case of BIOS, the EFI System partition is not used
1507855d95bSToomas Soome  * even if it does exist.
1517855d95bSToomas Soome  */
1527855d95bSToomas Soome typedef enum zpool_boot_label {
1537855d95bSToomas Soome 	ZPOOL_NO_BOOT_LABEL = 0,
1547855d95bSToomas Soome 	ZPOOL_CREATE_BOOT_LABEL,
1557855d95bSToomas Soome 	ZPOOL_COPY_BOOT_LABEL
1567855d95bSToomas Soome } zpool_boot_label_t;
1577855d95bSToomas Soome 
158ecd6cf80Smarks /*
159ecd6cf80Smarks  * The following data structures are all part
160ecd6cf80Smarks  * of the zfs_allow_t data structure which is
161ecd6cf80Smarks  * used for printing 'allow' permissions.
162ecd6cf80Smarks  * It is a linked list of zfs_allow_t's which
163ecd6cf80Smarks  * then contain avl tree's for user/group/sets/...
164ecd6cf80Smarks  * and each one of the entries in those trees have
165ecd6cf80Smarks  * avl tree's for the permissions they belong to and
166ecd6cf80Smarks  * whether they are local,descendent or local+descendent
167ecd6cf80Smarks  * permissions.  The AVL trees are used primarily for
168ecd6cf80Smarks  * sorting purposes, but also so that we can quickly find
169ecd6cf80Smarks  * a given user and or permission.
170ecd6cf80Smarks  */
171ecd6cf80Smarks typedef struct zfs_perm_node {
172ecd6cf80Smarks 	avl_node_t z_node;
173ecd6cf80Smarks 	char z_pname[MAXPATHLEN];
174ecd6cf80Smarks } zfs_perm_node_t;
175ecd6cf80Smarks 
176ecd6cf80Smarks typedef struct zfs_allow_node {
177ecd6cf80Smarks 	avl_node_t z_node;
178ecd6cf80Smarks 	char z_key[MAXPATHLEN];		/* name, such as joe */
179ecd6cf80Smarks 	avl_tree_t z_localdescend;	/* local+descendent perms */
180ecd6cf80Smarks 	avl_tree_t z_local;		/* local permissions */
181ecd6cf80Smarks 	avl_tree_t z_descend;		/* descendent permissions */
182ecd6cf80Smarks } zfs_allow_node_t;
183ecd6cf80Smarks 
184ecd6cf80Smarks typedef struct zfs_allow {
185ecd6cf80Smarks 	struct zfs_allow *z_next;
186ecd6cf80Smarks 	char z_setpoint[MAXPATHLEN];
187ecd6cf80Smarks 	avl_tree_t z_sets;
188ecd6cf80Smarks 	avl_tree_t z_crperms;
189ecd6cf80Smarks 	avl_tree_t z_user;
190ecd6cf80Smarks 	avl_tree_t z_group;
191ecd6cf80Smarks 	avl_tree_t z_everyone;
192ecd6cf80Smarks } zfs_allow_t;
193ecd6cf80Smarks 
194fa9e4066Sahrens /*
195fa9e4066Sahrens  * Basic handle types
196fa9e4066Sahrens  */
197fa9e4066Sahrens typedef struct zfs_handle zfs_handle_t;
198fa9e4066Sahrens typedef struct zpool_handle zpool_handle_t;
19999653d4eSeschrock typedef struct libzfs_handle libzfs_handle_t;
20099653d4eSeschrock 
20199653d4eSeschrock /*
20299653d4eSeschrock  * Library initialization
20399653d4eSeschrock  */
20499653d4eSeschrock extern libzfs_handle_t *libzfs_init(void);
20599653d4eSeschrock extern void libzfs_fini(libzfs_handle_t *);
20699653d4eSeschrock 
20799653d4eSeschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
20899653d4eSeschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
20999653d4eSeschrock 
21099653d4eSeschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
21199653d4eSeschrock 
2124445fffbSMatthew Ahrens extern void zfs_save_arguments(int argc, char **, char *, int);
2134445fffbSMatthew Ahrens extern int zpool_log_history(libzfs_handle_t *, const char *);
2144445fffbSMatthew Ahrens 
21599653d4eSeschrock extern int libzfs_errno(libzfs_handle_t *);
21699653d4eSeschrock extern const char *libzfs_error_action(libzfs_handle_t *);
21799653d4eSeschrock extern const char *libzfs_error_description(libzfs_handle_t *);
21878f17100SMatthew Ahrens extern int zfs_standard_error(libzfs_handle_t *, int, const char *);
219ebedde84SEric Taylor extern void libzfs_mnttab_init(libzfs_handle_t *);
220ebedde84SEric Taylor extern void libzfs_mnttab_fini(libzfs_handle_t *);
221b2634b9cSEric Taylor extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t);
222ebedde84SEric Taylor extern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
223ebedde84SEric Taylor     struct mnttab *);
224ebedde84SEric Taylor extern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
225ebedde84SEric Taylor     const char *, const char *);
226ebedde84SEric Taylor extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
227fa9e4066Sahrens 
228fa9e4066Sahrens /*
229fa9e4066Sahrens  * Basic handle functions
230fa9e4066Sahrens  */
23199653d4eSeschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
23299653d4eSeschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
233fa9e4066Sahrens extern void zpool_close(zpool_handle_t *);
234fa9e4066Sahrens extern const char *zpool_get_name(zpool_handle_t *);
235fa9e4066Sahrens extern int zpool_get_state(zpool_handle_t *);
2366401734dSWill Andrews extern const char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
2376401734dSWill Andrews extern const char *zpool_pool_state_to_name(pool_state_t);
23829ab75c9Srm extern void zpool_free_handles(libzfs_handle_t *);
239fa9e4066Sahrens 
240fa9e4066Sahrens /*
241fa9e4066Sahrens  * Iterate over all active pools in the system.
242fa9e4066Sahrens  */
243fa9e4066Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
24499653d4eSeschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
2458808ac5dSYuri Pankov extern boolean_t zpool_skip_pool(const char *);
246fa9e4066Sahrens 
247fa9e4066Sahrens /*
248fa9e4066Sahrens  * Functions to create and destroy pools
249fa9e4066Sahrens  */
25099653d4eSeschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
2510a48a24eStimh     nvlist_t *, nvlist_t *);
2524445fffbSMatthew Ahrens extern int zpool_destroy(zpool_handle_t *, const char *);
253fa9e4066Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *);
254fa9e4066Sahrens 
2551195e687SMark J Musante typedef struct splitflags {
2561195e687SMark J Musante 	/* do not split, but return the config that would be split off */
2571195e687SMark J Musante 	int dryrun : 1;
2581195e687SMark J Musante 
2591195e687SMark J Musante 	/* after splitting, import the pool */
2601195e687SMark J Musante 	int import : 1;
2611195e687SMark J Musante } splitflags_t;
2621195e687SMark J Musante 
263fa9e4066Sahrens /*
264fa9e4066Sahrens  * Functions to manipulate pool and vdev state
265fa9e4066Sahrens  */
2661702cce7SAlek Pinchuk extern int zpool_scan(zpool_handle_t *, pool_scan_func_t, pool_scrub_cmd_t);
267094e47e9SGeorge Wilson extern int zpool_initialize(zpool_handle_t *, pool_initialize_func_t,
268094e47e9SGeorge Wilson     nvlist_t *);
269468c413aSTim Haley extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *);
270e9103aaeSGarrett D'Amore extern int zpool_reguid(zpool_handle_t *);
2714263d13fSGeorge Wilson extern int zpool_reopen(zpool_handle_t *);
272fa9e4066Sahrens 
2739c2acf00SAlek Pinchuk extern int zpool_sync_one(zpool_handle_t *, void *);
2749c2acf00SAlek Pinchuk 
2753d7072f8Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
2763d7072f8Seschrock     vdev_state_t *);
2773d7072f8Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
2783d7072f8Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *,
2793d7072f8Seschrock     const char *, nvlist_t *, int);
280fa9e4066Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *);
28199653d4eSeschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *);
2825cabbc6bSPrashanth Sreenivasa extern int zpool_vdev_remove_cancel(zpool_handle_t *);
2835cabbc6bSPrashanth Sreenivasa extern int zpool_vdev_indirect_size(zpool_handle_t *, const char *, uint64_t *);
2841195e687SMark J Musante extern int zpool_vdev_split(zpool_handle_t *, char *, nvlist_t **, nvlist_t *,
2851195e687SMark J Musante     splitflags_t);
2863d7072f8Seschrock 
287069f55e2SEric Schrock extern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t);
288069f55e2SEric Schrock extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t);
2893d7072f8Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
2903d7072f8Seschrock 
291fa94a07fSbrendan extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *,
292ee0eb9f2SEric Schrock     boolean_t *, boolean_t *);
293573ca77eSGeorge Wilson extern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *,
294573ca77eSGeorge Wilson     boolean_t *, boolean_t *, boolean_t *);
2957855d95bSToomas Soome extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, const char *,
2967855d95bSToomas Soome     zpool_boot_label_t, uint64_t, int *);
297fa9e4066Sahrens 
298b1b8ab34Slling /*
299b1b8ab34Slling  * Functions to manage pool properties
300b1b8ab34Slling  */
301b1b8ab34Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
3023d7072f8Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
303c58b3526SAdam Stevko     size_t proplen, zprop_source_t *, boolean_t);
304990b4856Slling extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t,
305990b4856Slling     zprop_source_t *);
306990b4856Slling 
307b1b8ab34Slling extern const char *zpool_prop_to_name(zpool_prop_t);
308b1b8ab34Slling extern const char *zpool_prop_values(zpool_prop_t);
309b1b8ab34Slling 
310fa9e4066Sahrens /*
311fa9e4066Sahrens  * Pool health statistics.
312fa9e4066Sahrens  */
313fa9e4066Sahrens typedef enum {
314fa9e4066Sahrens 	/*
315fa9e4066Sahrens 	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
316b81d61a6Slling 	 * event namespace.  Each is associated with a corresponding message ID.
317*e0f1c0afSOlaf Faaland 	 * This must be kept in sync with the zfs_msgid_table in
318*e0f1c0afSOlaf Faaland 	 * lib/libzfs/libzfs_status.c.
319fa9e4066Sahrens 	 */
320fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
321fa9e4066Sahrens 	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
322fa9e4066Sahrens 	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
323fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
324b81d61a6Slling 	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device label with no replicas */
325fa9e4066Sahrens 	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
326fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
327fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
328fa9e4066Sahrens 	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
329eaca9bbdSeschrock 	ZPOOL_STATUS_VERSION_NEWER,	/* newer on-disk version */
33095173954Sek 	ZPOOL_STATUS_HOSTID_MISMATCH,	/* last accessed by another system */
331*e0f1c0afSOlaf Faaland 	ZPOOL_STATUS_HOSTID_ACTIVE,	/* currently active on another system */
332*e0f1c0afSOlaf Faaland 	ZPOOL_STATUS_HOSTID_REQUIRED,	/* multihost=on and hostid=0 */
33332b87932Sek 	ZPOOL_STATUS_IO_FAILURE_WAIT,	/* failed I/O, failmode 'wait' */
33432b87932Sek 	ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */
335*e0f1c0afSOlaf Faaland 	ZPOOL_STATUS_IO_FAILURE_MMP,	/* failed MMP, failmode not 'panic' */
336f67f35c3SEric Schrock 	ZPOOL_STATUS_BAD_LOG,		/* cannot read log chain(s) */
337f67f35c3SEric Schrock 
338ad135b5dSChristopher Siden 	/*
339ad135b5dSChristopher Siden 	 * If the pool has unsupported features but can still be opened in
340ad135b5dSChristopher Siden 	 * read-only mode, its status is ZPOOL_STATUS_UNSUP_FEAT_WRITE. If the
341ad135b5dSChristopher Siden 	 * pool has unsupported features but cannot be opened at all, its
342ad135b5dSChristopher Siden 	 * status is ZPOOL_STATUS_UNSUP_FEAT_READ.
343ad135b5dSChristopher Siden 	 */
344ad135b5dSChristopher Siden 	ZPOOL_STATUS_UNSUP_FEAT_READ,	/* unsupported features for read */
345ad135b5dSChristopher Siden 	ZPOOL_STATUS_UNSUP_FEAT_WRITE,	/* unsupported features for write */
346ad135b5dSChristopher Siden 
347f67f35c3SEric Schrock 	/*
348f67f35c3SEric Schrock 	 * These faults have no corresponding message ID.  At the time we are
349f67f35c3SEric Schrock 	 * checking the status, the original reason for the FMA fault (I/O or
350f67f35c3SEric Schrock 	 * checksum errors) has been lost.
351f67f35c3SEric Schrock 	 */
3523d7072f8Seschrock 	ZPOOL_STATUS_FAULTED_DEV_R,	/* faulted device with replicas */
3533d7072f8Seschrock 	ZPOOL_STATUS_FAULTED_DEV_NR,	/* faulted device with no replicas */
354fa9e4066Sahrens 
355fa9e4066Sahrens 	/*
356fa9e4066Sahrens 	 * The following are not faults per se, but still an error possibly
357b81d61a6Slling 	 * requiring administrative attention.  There is no corresponding
358fa9e4066Sahrens 	 * message ID.
359fa9e4066Sahrens 	 */
36057221772SChristopher Siden 	ZPOOL_STATUS_VERSION_OLDER,	/* older legacy on-disk version */
36157221772SChristopher Siden 	ZPOOL_STATUS_FEAT_DISABLED,	/* supported features are disabled */
362fa9e4066Sahrens 	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
363cb605c4dSGerhard Roethlin 	ZPOOL_STATUS_OFFLINE_DEV,	/* device offline */
364c25309d4SGeorge Wilson 	ZPOOL_STATUS_REMOVED_DEV,	/* removed device */
365fa9e4066Sahrens 
366fa9e4066Sahrens 	/*
367fa9e4066Sahrens 	 * Finally, the following indicates a healthy pool.
368fa9e4066Sahrens 	 */
369fa9e4066Sahrens 	ZPOOL_STATUS_OK
370fa9e4066Sahrens } zpool_status_t;
371fa9e4066Sahrens 
372ea8dc4b6Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **);
373ea8dc4b6Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **);
3749eb19f4dSGeorge Wilson extern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh);
375fa9e4066Sahrens 
376fa9e4066Sahrens /*
377fa9e4066Sahrens  * Statistics and configuration functions.
378fa9e4066Sahrens  */
379ea8dc4b6Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
380ad135b5dSChristopher Siden extern nvlist_t *zpool_get_features(zpool_handle_t *);
38194de1d4cSeschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
38255434c77Sek extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
3837855d95bSToomas Soome extern boolean_t zpool_is_bootable(zpool_handle_t *);
384ea8dc4b6Seschrock 
385fa9e4066Sahrens /*
386fa9e4066Sahrens  * Import and export functions
387fa9e4066Sahrens  */
3884445fffbSMatthew Ahrens extern int zpool_export(zpool_handle_t *, boolean_t, const char *);
3894445fffbSMatthew Ahrens extern int zpool_export_force(zpool_handle_t *, const char *);
39099653d4eSeschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
391990b4856Slling     char *altroot);
392990b4856Slling extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
3934b964adaSGeorge Wilson     nvlist_t *, int);
394ad135b5dSChristopher Siden extern void zpool_print_unsup_feat(nvlist_t *config);
395fa9e4066Sahrens 
396fa9e4066Sahrens /*
397fa9e4066Sahrens  * Search for pools to import
398fa9e4066Sahrens  */
399d41c4376SMark J Musante 
400d41c4376SMark J Musante typedef struct importargs {
401d41c4376SMark J Musante 	char **path;		/* a list of paths to search		*/
402d41c4376SMark J Musante 	int paths;		/* number of paths to search		*/
403d41c4376SMark J Musante 	char *poolname;		/* name of a pool to find		*/
404d41c4376SMark J Musante 	uint64_t guid;		/* guid of a pool to find		*/
405d41c4376SMark J Musante 	char *cachefile;	/* cachefile to use for import		*/
406d41c4376SMark J Musante 	int can_be_active : 1;	/* can the pool be active?		*/
407d41c4376SMark J Musante 	int unique : 1;		/* does 'poolname' already exist?	*/
408d41c4376SMark J Musante 	int exists : 1;		/* set on return if pool already exists	*/
4095dafeea3SPavel Zakharov 	nvlist_t *policy;	/* load policy (max txg, rewind, etc.)	*/
410d41c4376SMark J Musante } importargs_t;
411d41c4376SMark J Musante 
412d41c4376SMark J Musante extern nvlist_t *zpool_search_import(libzfs_handle_t *, importargs_t *);
413*e0f1c0afSOlaf Faaland extern int zpool_tryimport(libzfs_handle_t *hdl, char *target,
414*e0f1c0afSOlaf Faaland     nvlist_t **configp, importargs_t *args);
415d41c4376SMark J Musante 
416d41c4376SMark J Musante /* legacy pool search routines */
41724e697d4Sck extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
4183a57275aSck extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *,
419e829d913Sck     char *, uint64_t);
420fa9e4066Sahrens 
421c67d9675Seschrock /*
422c67d9675Seschrock  * Miscellaneous pool functions
423c67d9675Seschrock  */
424ecd6cf80Smarks struct zfs_cmd;
425ecd6cf80Smarks 
4264445fffbSMatthew Ahrens extern const char *zfs_history_event_names[];
4278f18d1faSGeorge Wilson 
42888ecc943SGeorge Wilson extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *,
42988ecc943SGeorge Wilson     boolean_t verbose);
430990b4856Slling extern int zpool_upgrade(zpool_handle_t *, uint64_t);
43106eeb2adSek extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
4328f18d1faSGeorge Wilson extern int zpool_history_unpack(char *, uint64_t, uint64_t *,
4338f18d1faSGeorge Wilson     nvlist_t ***, uint_t *);
43455434c77Sek extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
43555434c77Sek     size_t len);
436ecd6cf80Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
437753a6d45SSherry Moore extern int zpool_get_physpath(zpool_handle_t *, char *, size_t);
438468c413aSTim Haley extern void zpool_explain_recover(libzfs_handle_t *, const char *, int,
439468c413aSTim Haley     nvlist_t *);
44086714001SSerapheim Dimitropoulos extern int zpool_checkpoint(zpool_handle_t *);
44186714001SSerapheim Dimitropoulos extern int zpool_discard_checkpoint(zpool_handle_t *);
442753a6d45SSherry Moore 
443fa9e4066Sahrens /*
444fa9e4066Sahrens  * Basic handle manipulations.  These functions do not create or destroy the
445fa9e4066Sahrens  * underlying datasets, only the references to them.
446fa9e4066Sahrens  */
44799653d4eSeschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
44819b94df9SMatthew Ahrens extern zfs_handle_t *zfs_handle_dup(zfs_handle_t *);
449fa9e4066Sahrens extern void zfs_close(zfs_handle_t *);
450fa9e4066Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *);
451fa9e4066Sahrens extern const char *zfs_get_name(const zfs_handle_t *);
452d5b5bb25SRich Morris extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
4538808ac5dSYuri Pankov extern const char *zfs_get_pool_name(const zfs_handle_t *);
454fa9e4066Sahrens 
455fa9e4066Sahrens /*
456fa9e4066Sahrens  * Property management functions.  Some functions are shared with the kernel,
457b81d61a6Slling  * and are found in sys/fs/zfs.h.
458fa9e4066Sahrens  */
459990b4856Slling 
460990b4856Slling /*
461990b4856Slling  * zfs dataset property management
462990b4856Slling  */
463990b4856Slling extern const char *zfs_prop_default_string(zfs_prop_t);
464990b4856Slling extern uint64_t zfs_prop_default_numeric(zfs_prop_t);
465990b4856Slling extern const char *zfs_prop_column_name(zfs_prop_t);
466990b4856Slling extern boolean_t zfs_prop_align_right(zfs_prop_t);
467990b4856Slling 
4680a48a24eStimh extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t,
469e9316f76SJoe Stein     nvlist_t *, uint64_t, zfs_handle_t *, zpool_handle_t *, const char *);
4700a48a24eStimh 
471e9dbad6fSeschrock extern const char *zfs_prop_to_name(zfs_prop_t);
472e9dbad6fSeschrock extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
47330925561SChris Williamson extern int zfs_prop_set_list(zfs_handle_t *, nvlist_t *);
474e9dbad6fSeschrock extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
475990b4856Slling     zprop_source_t *, char *, size_t, boolean_t);
47692241e0bSTom Erickson extern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t,
47792241e0bSTom Erickson     boolean_t);
478e9dbad6fSeschrock extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
479990b4856Slling     zprop_source_t *, char *, size_t);
480edea4b55SLin Ling extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname,
481edea4b55SLin Ling     uint64_t *propvalue);
48214843421SMatthew Ahrens extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname,
48314843421SMatthew Ahrens     char *propbuf, int proplen, boolean_t literal);
48419b94df9SMatthew Ahrens extern int zfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname,
48519b94df9SMatthew Ahrens     uint64_t *propvalue);
48619b94df9SMatthew Ahrens extern int zfs_prop_get_written(zfs_handle_t *zhp, const char *propname,
48719b94df9SMatthew Ahrens     char *propbuf, int proplen, boolean_t literal);
488ad135b5dSChristopher Siden extern int zfs_prop_get_feature(zfs_handle_t *zhp, const char *propname,
489ad135b5dSChristopher Siden     char *buf, size_t len);
490e9dbad6fSeschrock extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
49192241e0bSTom Erickson extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t);
492e9dbad6fSeschrock extern const char *zfs_prop_values(zfs_prop_t);
493e9dbad6fSeschrock extern int zfs_prop_is_string(zfs_prop_t prop);
494990b4856Slling extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
49592241e0bSTom Erickson extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *);
49619b94df9SMatthew Ahrens extern nvlist_t *zfs_get_clones_nvl(zfs_handle_t *);
49719b94df9SMatthew Ahrens 
498e9dbad6fSeschrock 
499990b4856Slling typedef struct zprop_list {
500990b4856Slling 	int		pl_prop;
501e9dbad6fSeschrock 	char		*pl_user_prop;
502990b4856Slling 	struct zprop_list *pl_next;
503e9dbad6fSeschrock 	boolean_t	pl_all;
504e9dbad6fSeschrock 	size_t		pl_width;
50592241e0bSTom Erickson 	size_t		pl_recvd_width;
506e9dbad6fSeschrock 	boolean_t	pl_fixed;
507990b4856Slling } zprop_list_t;
508e9dbad6fSeschrock 
50943d68d68SYuri Pankov extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t,
51043d68d68SYuri Pankov     boolean_t);
5112e5e9e19SSanjeev Bagewadi extern void zfs_prune_proplist(zfs_handle_t *, uint8_t *);
512fa9e4066Sahrens 
513fa9e4066Sahrens #define	ZFS_MOUNTPOINT_NONE	"none"
514fa9e4066Sahrens #define	ZFS_MOUNTPOINT_LEGACY	"legacy"
515fa9e4066Sahrens 
516ad135b5dSChristopher Siden #define	ZFS_FEATURE_DISABLED	"disabled"
517ad135b5dSChristopher Siden #define	ZFS_FEATURE_ENABLED	"enabled"
518ad135b5dSChristopher Siden #define	ZFS_FEATURE_ACTIVE	"active"
519ad135b5dSChristopher Siden 
520ad135b5dSChristopher Siden #define	ZFS_UNSUPPORTED_INACTIVE	"inactive"
521ad135b5dSChristopher Siden #define	ZFS_UNSUPPORTED_READONLY	"readonly"
522ad135b5dSChristopher Siden 
523b1b8ab34Slling /*
524990b4856Slling  * zpool property management
525990b4856Slling  */
526990b4856Slling extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **);
527ad135b5dSChristopher Siden extern int zpool_prop_get_feature(zpool_handle_t *, const char *, char *,
528ad135b5dSChristopher Siden     size_t);
529990b4856Slling extern const char *zpool_prop_default_string(zpool_prop_t);
530990b4856Slling extern uint64_t zpool_prop_default_numeric(zpool_prop_t);
531990b4856Slling extern const char *zpool_prop_column_name(zpool_prop_t);
532990b4856Slling extern boolean_t zpool_prop_align_right(zpool_prop_t);
533990b4856Slling 
534990b4856Slling /*
535990b4856Slling  * Functions shared by zfs and zpool property management.
536b1b8ab34Slling  */
537990b4856Slling extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all,
538990b4856Slling     boolean_t ordered, zfs_type_t type);
539990b4856Slling extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **,
540990b4856Slling     zfs_type_t);
541990b4856Slling extern void zprop_free_list(zprop_list_t *);
542990b4856Slling 
54392241e0bSTom Erickson #define	ZFS_GET_NCOLS	5
54492241e0bSTom Erickson 
54592241e0bSTom Erickson typedef enum {
54692241e0bSTom Erickson 	GET_COL_NONE,
54792241e0bSTom Erickson 	GET_COL_NAME,
54892241e0bSTom Erickson 	GET_COL_PROPERTY,
54992241e0bSTom Erickson 	GET_COL_VALUE,
55092241e0bSTom Erickson 	GET_COL_RECVD,
55192241e0bSTom Erickson 	GET_COL_SOURCE
55292241e0bSTom Erickson } zfs_get_column_t;
55392241e0bSTom Erickson 
554990b4856Slling /*
555990b4856Slling  * Functions for printing zfs or zpool properties
556990b4856Slling  */
557990b4856Slling typedef struct zprop_get_cbdata {
558b1b8ab34Slling 	int cb_sources;
55992241e0bSTom Erickson 	zfs_get_column_t cb_columns[ZFS_GET_NCOLS];
56092241e0bSTom Erickson 	int cb_colwidths[ZFS_GET_NCOLS + 1];
561b1b8ab34Slling 	boolean_t cb_scripted;
562b1b8ab34Slling 	boolean_t cb_literal;
563b1b8ab34Slling 	boolean_t cb_first;
564990b4856Slling 	zprop_list_t *cb_proplist;
565990b4856Slling 	zfs_type_t cb_type;
566990b4856Slling } zprop_get_cbdata_t;
567b1b8ab34Slling 
568990b4856Slling void zprop_print_one_property(const char *, zprop_get_cbdata_t *,
56992241e0bSTom Erickson     const char *, const char *, zprop_source_t, const char *,
57092241e0bSTom Erickson     const char *);
571b1b8ab34Slling 
572fa9e4066Sahrens /*
573fa9e4066Sahrens  * Iterator functions.
574fa9e4066Sahrens  */
575fa9e4066Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
57699653d4eSeschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
577fa9e4066Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
5783bb79becSeschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
5797f7322feSeschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
5800d8fa8f8SMartin Matuska extern int zfs_iter_snapshots(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
581ca45db41SChris Kirby extern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *);
58219b94df9SMatthew Ahrens extern int zfs_iter_snapspec(zfs_handle_t *, const char *, zfs_iter_f, void *);
58378f17100SMatthew Ahrens extern int zfs_iter_bookmarks(zfs_handle_t *, zfs_iter_f, void *);
584fa9e4066Sahrens 
5859d9a58e3SEric Taylor typedef struct get_all_cb {
5869d9a58e3SEric Taylor 	zfs_handle_t	**cb_handles;
5879d9a58e3SEric Taylor 	size_t		cb_alloc;
5889d9a58e3SEric Taylor 	size_t		cb_used;
5899d9a58e3SEric Taylor } get_all_cb_t;
5909d9a58e3SEric Taylor 
591591e0e13SSebastien Roy void zfs_foreach_mountpoint(libzfs_handle_t *, zfs_handle_t **, size_t,
592591e0e13SSebastien Roy     zfs_iter_f, void *, boolean_t);
5939d9a58e3SEric Taylor void libzfs_add_handle(get_all_cb_t *, zfs_handle_t *);
5949d9a58e3SEric Taylor 
595fa9e4066Sahrens /*
596fa9e4066Sahrens  * Functions to create and destroy datasets.
597fa9e4066Sahrens  */
59899653d4eSeschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
599e9dbad6fSeschrock     nvlist_t *);
6007f1f55eaSvb extern int zfs_create_ancestors(libzfs_handle_t *, const char *);
601842727c2SChris Kirby extern int zfs_destroy(zfs_handle_t *, boolean_t);
602842727c2SChris Kirby extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t);
6033b2aab18SMatthew Ahrens extern int zfs_destroy_snaps_nvl(libzfs_handle_t *, nvlist_t *, boolean_t);
604e9dbad6fSeschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
605bb0ade09Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
6064445fffbSMatthew Ahrens extern int zfs_snapshot_nvl(libzfs_handle_t *hdl, nvlist_t *snaps,
6074445fffbSMatthew Ahrens     nvlist_t *props);
608c391e322Sahrens extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
6096a9cb0eaSEric Schrock extern int zfs_rename(zfs_handle_t *, const char *, boolean_t, boolean_t);
6109e69d7d0SLori Alt 
6119e69d7d0SLori Alt typedef struct sendflags {
6129e69d7d0SLori Alt 	/* print informational messages (ie, -v was specified) */
61319b94df9SMatthew Ahrens 	boolean_t verbose;
6149e69d7d0SLori Alt 
61592241e0bSTom Erickson 	/* recursive send  (ie, -R) */
61619b94df9SMatthew Ahrens 	boolean_t replicate;
6179e69d7d0SLori Alt 
6189e69d7d0SLori Alt 	/* for incrementals, do all intermediate snapshots */
61919b94df9SMatthew Ahrens 	boolean_t doall;
6209e69d7d0SLori Alt 
6219e69d7d0SLori Alt 	/* if dataset is a clone, do incremental from its origin */
62219b94df9SMatthew Ahrens 	boolean_t fromorigin;
6239e69d7d0SLori Alt 
6249e69d7d0SLori Alt 	/* do deduplication */
62519b94df9SMatthew Ahrens 	boolean_t dedup;
62692241e0bSTom Erickson 
62792241e0bSTom Erickson 	/* send properties (ie, -p) */
62819b94df9SMatthew Ahrens 	boolean_t props;
62919b94df9SMatthew Ahrens 
63019b94df9SMatthew Ahrens 	/* do not send (no-op, ie. -n) */
63119b94df9SMatthew Ahrens 	boolean_t dryrun;
63219b94df9SMatthew Ahrens 
63319b94df9SMatthew Ahrens 	/* parsable verbose output (ie. -P) */
63419b94df9SMatthew Ahrens 	boolean_t parsable;
6354e3c9f44SBill Pijewski 
6364e3c9f44SBill Pijewski 	/* show progress (ie. -v) */
6374e3c9f44SBill Pijewski 	boolean_t progress;
6385d7b4d43SMatthew Ahrens 
639b5152584SMatthew Ahrens 	/* large blocks (>128K) are permitted */
640b5152584SMatthew Ahrens 	boolean_t largeblock;
641b5152584SMatthew Ahrens 
6425d7b4d43SMatthew Ahrens 	/* WRITE_EMBEDDED records of type DATA are permitted */
6435d7b4d43SMatthew Ahrens 	boolean_t embed_data;
6445602294fSDan Kimmel 
6455602294fSDan Kimmel 	/* compressed WRITE records are permitted */
6465602294fSDan Kimmel 	boolean_t compress;
6479e69d7d0SLori Alt } sendflags_t;
6489e69d7d0SLori Alt 
6499e69d7d0SLori Alt typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *);
6509e69d7d0SLori Alt 
65119b94df9SMatthew Ahrens extern int zfs_send(zfs_handle_t *, const char *, const char *,
65219b94df9SMatthew Ahrens     sendflags_t *, int, snapfilter_cb_t, void *, nvlist_t **);
6535d7b4d43SMatthew Ahrens extern int zfs_send_one(zfs_handle_t *, const char *, int, enum lzc_send_flags);
6549c3fd121SMatthew Ahrens extern int zfs_send_resume(libzfs_handle_t *, sendflags_t *, int outfd,
6559c3fd121SMatthew Ahrens     const char *);
6569c3fd121SMatthew Ahrens extern nvlist_t *zfs_send_resume_token_to_nvlist(libzfs_handle_t *hdl,
6579c3fd121SMatthew Ahrens     const char *token);
6589e69d7d0SLori Alt 
65999653d4eSeschrock extern int zfs_promote(zfs_handle_t *);
6603b2aab18SMatthew Ahrens extern int zfs_hold(zfs_handle_t *, const char *, const char *,
661a7a845e4SSteven Hartland     boolean_t, int);
662a7a845e4SSteven Hartland extern int zfs_hold_nvl(zfs_handle_t *, int, nvlist_t *);
663842727c2SChris Kirby extern int zfs_release(zfs_handle_t *, const char *, const char *, boolean_t);
6641af68beaSAlexander Stetsenko extern int zfs_get_holds(zfs_handle_t *, nvlist_t **);
665c1449561SEric Taylor extern uint64_t zvol_volsize_to_reservation(uint64_t, nvlist_t *);
666fa9e4066Sahrens 
6670aea4b19SMatthew Ahrens typedef int (*zfs_userspace_cb_t)(void *arg, const char *domain,
66814843421SMatthew Ahrens     uid_t rid, uint64_t space);
66914843421SMatthew Ahrens 
6701af68beaSAlexander Stetsenko extern int zfs_userspace(zfs_handle_t *, zfs_userquota_prop_t,
6711af68beaSAlexander Stetsenko     zfs_userspace_cb_t, void *);
6721af68beaSAlexander Stetsenko 
6731af68beaSAlexander Stetsenko extern int zfs_get_fsacl(zfs_handle_t *, nvlist_t **);
6741af68beaSAlexander Stetsenko extern int zfs_set_fsacl(zfs_handle_t *, boolean_t, nvlist_t *);
67514843421SMatthew Ahrens 
6763cb34c60Sahrens typedef struct recvflags {
6774ccbb6e7Sahrens 	/* print informational messages (ie, -v was specified) */
67819b94df9SMatthew Ahrens 	boolean_t verbose;
6794ccbb6e7Sahrens 
6804ccbb6e7Sahrens 	/* the destination is a prefix, not the exact fs (ie, -d) */
68119b94df9SMatthew Ahrens 	boolean_t isprefix;
6824ccbb6e7Sahrens 
683f64930f5STom Erickson 	/*
684f64930f5STom Erickson 	 * Only the tail of the sent snapshot path is appended to the
685f64930f5STom Erickson 	 * destination to determine the received snapshot name (ie, -e).
686f64930f5STom Erickson 	 */
68719b94df9SMatthew Ahrens 	boolean_t istail;
688f64930f5STom Erickson 
6894ccbb6e7Sahrens 	/* do not actually do the recv, just check if it would work (ie, -n) */
69019b94df9SMatthew Ahrens 	boolean_t dryrun;
6914ccbb6e7Sahrens 
6924ccbb6e7Sahrens 	/* rollback/destroy filesystems as necessary (eg, -F) */
69319b94df9SMatthew Ahrens 	boolean_t force;
6944ccbb6e7Sahrens 
6954ccbb6e7Sahrens 	/* set "canmount=off" on all modified filesystems */
69619b94df9SMatthew Ahrens 	boolean_t canmountoff;
6974ccbb6e7Sahrens 
6989c3fd121SMatthew Ahrens 	/*
6999c3fd121SMatthew Ahrens 	 * Mark the file systems as "resumable" and do not destroy them if the
7009c3fd121SMatthew Ahrens 	 * receive is interrupted
7019c3fd121SMatthew Ahrens 	 */
7029c3fd121SMatthew Ahrens 	boolean_t resumable;
7039c3fd121SMatthew Ahrens 
7044ccbb6e7Sahrens 	/* byteswap flag is used internally; callers need not specify */
70519b94df9SMatthew Ahrens 	boolean_t byteswap;
70633408eefSLori Alt 
70733408eefSLori Alt 	/* do not mount file systems as they are extracted (private) */
70819b94df9SMatthew Ahrens 	boolean_t nomount;
7093cb34c60Sahrens } recvflags_t;
7103cb34c60Sahrens 
711a2cdcdd2SPaul Dagnelie extern int zfs_receive(libzfs_handle_t *, const char *, nvlist_t *,
712a2cdcdd2SPaul Dagnelie     recvflags_t *, int, avl_tree_t *);
7133cb34c60Sahrens 
71499d5e173STim Haley typedef enum diff_flags {
71599d5e173STim Haley 	ZFS_DIFF_PARSEABLE = 0x1,
71699d5e173STim Haley 	ZFS_DIFF_TIMESTAMP = 0x2,
71799d5e173STim Haley 	ZFS_DIFF_CLASSIFY = 0x4
71899d5e173STim Haley } diff_flags_t;
71999d5e173STim Haley 
72099d5e173STim Haley extern int zfs_show_diffs(zfs_handle_t *, int, const char *, const char *,
72199d5e173STim Haley     int);
72299d5e173STim Haley 
723fa9e4066Sahrens /*
724fa9e4066Sahrens  * Miscellaneous functions.
725fa9e4066Sahrens  */
726fa9e4066Sahrens extern const char *zfs_type_to_name(zfs_type_t);
727fa9e4066Sahrens extern void zfs_refresh_properties(zfs_handle_t *);
728fa9e4066Sahrens extern int zfs_name_valid(const char *, zfs_type_t);
7295aba80dbSck extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t);
7307f1f55eaSvb extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *,
7317f1f55eaSvb     zfs_type_t);
7327b97dc1aSrm extern int zfs_spa_version(zfs_handle_t *, int *);
73378f17100SMatthew Ahrens extern boolean_t zfs_bookmark_exists(const char *path);
734*e0f1c0afSOlaf Faaland extern ulong_t get_system_hostid(void);
735fa9e4066Sahrens 
736fa9e4066Sahrens /*
737fa9e4066Sahrens  * Mount support functions.
738fa9e4066Sahrens  */
73955434c77Sek extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **);
74099653d4eSeschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **);
741fa9e4066Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int);
742fa9e4066Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int);
743fa9e4066Sahrens extern int zfs_unmountall(zfs_handle_t *, int);
744fa9e4066Sahrens 
745fa9e4066Sahrens /*
746fa9e4066Sahrens  * Share support functions.
747fa9e4066Sahrens  */
748f3861e1aSahl extern boolean_t zfs_is_shared(zfs_handle_t *);
749fa9e4066Sahrens extern int zfs_share(zfs_handle_t *);
750f3861e1aSahl extern int zfs_unshare(zfs_handle_t *);
751f3861e1aSahl 
752f3861e1aSahl /*
7533d7072f8Seschrock  * Protocol-specific share support functions.
754f3861e1aSahl  */
755f3861e1aSahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **);
756da6c28aaSamw extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **);
757f3861e1aSahl extern int zfs_share_nfs(zfs_handle_t *);
758da6c28aaSamw extern int zfs_share_smb(zfs_handle_t *);
759da6c28aaSamw extern int zfs_shareall(zfs_handle_t *);
760f3861e1aSahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *);
761da6c28aaSamw extern int zfs_unshare_smb(zfs_handle_t *, const char *);
762f3861e1aSahl extern int zfs_unshareall_nfs(zfs_handle_t *);
763da6c28aaSamw extern int zfs_unshareall_smb(zfs_handle_t *);
764da6c28aaSamw extern int zfs_unshareall_bypath(zfs_handle_t *, const char *);
765da6c28aaSamw extern int zfs_unshareall(zfs_handle_t *);
766743a77edSAlan Wright extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *,
767da6c28aaSamw     void *, void *, int, zfs_share_op_t);
768fa9e4066Sahrens 
769fa9e4066Sahrens /*
770fa9e4066Sahrens  * When dealing with nvlists, verify() is extremely useful
771fa9e4066Sahrens  */
772fa9e4066Sahrens #ifdef NDEBUG
773fa9e4066Sahrens #define	verify(EX)	((void)(EX))
774fa9e4066Sahrens #else
775fa9e4066Sahrens #define	verify(EX)	assert(EX)
776fa9e4066Sahrens #endif
777fa9e4066Sahrens 
778fa9e4066Sahrens /*
779fa9e4066Sahrens  * Utility function to convert a number to a human-readable form.
780fa9e4066Sahrens  */
781fa9e4066Sahrens extern void zfs_nicenum(uint64_t, char *, size_t);
782e9dbad6fSeschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
783fa9e4066Sahrens 
784fa9e4066Sahrens /*
785fa9e4066Sahrens  * Given a device or file, determine if it is part of a pool.
786fa9e4066Sahrens  */
78799653d4eSeschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **,
78899653d4eSeschrock     boolean_t *);
789fa9e4066Sahrens 
790fa9e4066Sahrens /*
791096d22d4SEric Schrock  * Label manipulation.
792fa9e4066Sahrens  */
79399653d4eSeschrock extern int zpool_read_label(int, nvlist_t **);
794096d22d4SEric Schrock extern int zpool_clear_label(int);
795fa9e4066Sahrens 
796e7cbe64fSgw /* is this zvol valid for use as a dump device? */
797e7cbe64fSgw extern int zvol_check_dump_config(char *);
798e7cbe64fSgw 
799743a77edSAlan Wright /*
800743a77edSAlan Wright  * Management interfaces for SMB ACL files
801743a77edSAlan Wright  */
802743a77edSAlan Wright 
803743a77edSAlan Wright int zfs_smb_acl_add(libzfs_handle_t *, char *, char *, char *);
804743a77edSAlan Wright int zfs_smb_acl_remove(libzfs_handle_t *, char *, char *, char *);
805743a77edSAlan Wright int zfs_smb_acl_purge(libzfs_handle_t *, char *, char *);
806743a77edSAlan Wright int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *);
807743a77edSAlan Wright 
8083bb79becSeschrock /*
809f3861e1aSahl  * Enable and disable datasets within a pool by mounting/unmounting and
810f3861e1aSahl  * sharing/unsharing them.
8113bb79becSeschrock  */
812f3861e1aSahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int);
813f3861e1aSahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t);
8143bb79becSeschrock 
815069f55e2SEric Schrock /*
816069f55e2SEric Schrock  * Mappings between vdev and FRU.
817069f55e2SEric Schrock  */
818069f55e2SEric Schrock extern void libzfs_fru_refresh(libzfs_handle_t *);
819069f55e2SEric Schrock extern const char *libzfs_fru_lookup(libzfs_handle_t *, const char *);
820069f55e2SEric Schrock extern const char *libzfs_fru_devpath(libzfs_handle_t *, const char *);
821069f55e2SEric Schrock extern boolean_t libzfs_fru_compare(libzfs_handle_t *, const char *,
822069f55e2SEric Schrock     const char *);
823069f55e2SEric Schrock extern boolean_t libzfs_fru_notself(libzfs_handle_t *, const char *);
824069f55e2SEric Schrock extern int zpool_fru_set(zpool_handle_t *, uint64_t, const char *);
825069f55e2SEric Schrock 
8262bcf0248SMax Grossman extern int zfs_get_hole_count(const char *, uint64_t *, uint64_t *);
8275cabbc6bSPrashanth Sreenivasa extern int zfs_remap_indirects(libzfs_handle_t *hdl, const char *);
8282bcf0248SMax Grossman 
8298a981c33SDaniel Hoffman /* Allow consumers to initialize libshare externally for optimal performance */
8308a981c33SDaniel Hoffman extern int zfs_init_libshare_arg(libzfs_handle_t *, int, void *);
8318a981c33SDaniel Hoffman /*
8328a981c33SDaniel Hoffman  * For most consumers, zfs_init_libshare_arg is sufficient on its own, and
8338a981c33SDaniel Hoffman  * zfs_uninit_libshare is unnecessary. zfs_uninit_libshare should only be called
8348a981c33SDaniel Hoffman  * if the caller has already initialized libshare for one set of zfs handles,
8358a981c33SDaniel Hoffman  * and wishes to share or unshare filesystems outside of that set. In that case,
8368a981c33SDaniel Hoffman  * the caller should uninitialize libshare, and then re-initialize it with the
8378a981c33SDaniel Hoffman  * new handles being shared or unshared.
8388a981c33SDaniel Hoffman  */
8398a981c33SDaniel Hoffman extern void zfs_uninit_libshare(libzfs_handle_t *);
840fa9e4066Sahrens #ifdef	__cplusplus
841fa9e4066Sahrens }
842fa9e4066Sahrens #endif
843fa9e4066Sahrens 
844fa9e4066Sahrens #endif	/* _LIBZFS_H */
845