xref: /illumos-gate/usr/src/lib/libzfs/common/libzfs.h (revision 09fcda9f)
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  */
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.
257ac89354SDon Brady  * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
26d8ab6e12SDon Brady  * Copyright 2020 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  */
33fa9e4066Sahrens #ifndef	_LIBZFS_H
34fa9e4066Sahrens #define	_LIBZFS_H
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>
47fa9e4066Sahrens #ifdef	__cplusplus
48fa9e4066Sahrens extern "C" {
49fa9e4066Sahrens #endif
51fa9e4066Sahrens /*
52fa9e4066Sahrens  * Miscellaneous ZFS constants
53fa9e4066Sahrens  */
54fa9e4066Sahrens #define	ZFS_MAXPROPLEN		MAXPATHLEN
55990b4856Slling #define	ZPOOL_MAXPROPLEN	MAXPATHLEN
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 */
133e0f1c0afSOlaf Faaland 	EZFS_ACTIVE_POOL,	/* pool is imported on a different system */
134084fd14fSBrian Behlendorf 	EZFS_CRYPTOFAILED,	/* failed to setup encryption */
1355cabbc6bSPrashanth Sreenivasa 	EZFS_NO_PENDING,	/* cannot cancel, no operation is pending */
13686714001SSerapheim Dimitropoulos 	EZFS_CHECKPOINT_EXISTS,	/* checkpoint exists */
13786714001SSerapheim Dimitropoulos 	EZFS_DISCARDING_CHECKPOINT,	/* currently discarding a checkpoint */
13886714001SSerapheim Dimitropoulos 	EZFS_NO_CHECKPOINT,	/* pool has no checkpoint */
13986714001SSerapheim Dimitropoulos 	EZFS_DEVRM_IN_PROGRESS,	/* a device is currently being removed */
14086714001SSerapheim Dimitropoulos 	EZFS_VDEV_TOO_BIG,	/* a device is too big to be used */
141094e47e9SGeorge Wilson 	EZFS_TOOMANY,		/* argument list too long */
142094e47e9SGeorge Wilson 	EZFS_INITIALIZING,	/* currently initializing */
143094e47e9SGeorge Wilson 	EZFS_NO_INITIALIZE,	/* no active initialize */
1446ccda740Sloli 	EZFS_WRONG_PARENT,	/* invalid parent dataset (e.g ZVOL) */
145084fd14fSBrian Behlendorf 	EZFS_TRIMMING,		/* currently trimming */
146084fd14fSBrian Behlendorf 	EZFS_NO_TRIM,		/* no active trim */
147084fd14fSBrian Behlendorf 	EZFS_TRIM_NOTSUP,	/* device does not support trim */
148e4c795beSTom Caputi 	EZFS_NO_RESILVER_DEFER,	/* pool doesn't support resilver_defer */
1497ac89354SDon Brady 	EZFS_IOC_NOTSUPPORTED,	/* operation not supported by zfs module */
150b1b8ab34Slling 	EZFS_UNKNOWN
1514445fffbSMatthew Ahrens } zfs_error_t;
1537855d95bSToomas Soome /*
1547855d95bSToomas Soome  * UEFI boot support parameters. When creating whole disk boot pool,
1557855d95bSToomas Soome  * zpool create should allow to create EFI System partition for UEFI boot
1567855d95bSToomas Soome  * program. In case of BIOS, the EFI System partition is not used
1577855d95bSToomas Soome  * even if it does exist.
1587855d95bSToomas Soome  */
1597855d95bSToomas Soome typedef enum zpool_boot_label {
1607855d95bSToomas Soome 	ZPOOL_NO_BOOT_LABEL = 0,
1617855d95bSToomas Soome 	ZPOOL_CREATE_BOOT_LABEL,
1627855d95bSToomas Soome 	ZPOOL_COPY_BOOT_LABEL
1637855d95bSToomas Soome } zpool_boot_label_t;
1647855d95bSToomas Soome 
165ecd6cf80Smarks /*
166ecd6cf80Smarks  * The following data structures are all part
167ecd6cf80Smarks  * of the zfs_allow_t data structure which is
168ecd6cf80Smarks  * used for printing 'allow' permissions.
169ecd6cf80Smarks  * It is a linked list of zfs_allow_t's which
170ecd6cf80Smarks  * then contain avl tree's for user/group/sets/...
171ecd6cf80Smarks  * and each one of the entries in those trees have
172ecd6cf80Smarks  * avl tree's for the permissions they belong to and
173ecd6cf80Smarks  * whether they are local,descendent or local+descendent
174ecd6cf80Smarks  * permissions.  The AVL trees are used primarily for
175ecd6cf80Smarks  * sorting purposes, but also so that we can quickly find
176ecd6cf80Smarks  * a given user and or permission.
177ecd6cf80Smarks  */
178ecd6cf80Smarks typedef struct zfs_perm_node {
179ecd6cf80Smarks 	avl_node_t z_node;
180ecd6cf80Smarks 	char z_pname[MAXPATHLEN];
181ecd6cf80Smarks } zfs_perm_node_t;
183ecd6cf80Smarks typedef struct zfs_allow_node {
184ecd6cf80Smarks 	avl_node_t z_node;
185ecd6cf80Smarks 	char z_key[MAXPATHLEN];		/* name, such as joe */
186ecd6cf80Smarks 	avl_tree_t z_localdescend;	/* local+descendent perms */
187ecd6cf80Smarks 	avl_tree_t z_local;		/* local permissions */
188ecd6cf80Smarks 	avl_tree_t z_descend;		/* descendent permissions */
189ecd6cf80Smarks } zfs_allow_node_t;
191ecd6cf80Smarks typedef struct zfs_allow {
192ecd6cf80Smarks 	struct zfs_allow *z_next;
193ecd6cf80Smarks 	char z_setpoint[MAXPATHLEN];
194ecd6cf80Smarks 	avl_tree_t z_sets;
195ecd6cf80Smarks 	avl_tree_t z_crperms;
196ecd6cf80Smarks 	avl_tree_t z_user;
197ecd6cf80Smarks 	avl_tree_t z_group;
198ecd6cf80Smarks 	avl_tree_t z_everyone;
199ecd6cf80Smarks } zfs_allow_t;
201fa9e4066Sahrens /*
202fa9e4066Sahrens  * Basic handle types
203fa9e4066Sahrens  */
204fa9e4066Sahrens typedef struct zfs_handle zfs_handle_t;
205fa9e4066Sahrens typedef struct zpool_handle zpool_handle_t;
20699653d4eSeschrock typedef struct libzfs_handle libzfs_handle_t;
20899653d4eSeschrock /*
20999653d4eSeschrock  * Library initialization
21099653d4eSeschrock  */
21199653d4eSeschrock extern libzfs_handle_t *libzfs_init(void);
21299653d4eSeschrock extern void libzfs_fini(libzfs_handle_t *);
21499653d4eSeschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
21599653d4eSeschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
21799653d4eSeschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
2194445fffbSMatthew Ahrens extern void zfs_save_arguments(int argc, char **, char *, int);
2204445fffbSMatthew Ahrens extern int zpool_log_history(libzfs_handle_t *, const char *);
2214445fffbSMatthew Ahrens 
22299653d4eSeschrock extern int libzfs_errno(libzfs_handle_t *);
22399653d4eSeschrock extern const char *libzfs_error_action(libzfs_handle_t *);
22499653d4eSeschrock extern const char *libzfs_error_description(libzfs_handle_t *);
22578f17100SMatthew Ahrens extern int zfs_standard_error(libzfs_handle_t *, int, const char *);
226ebedde84SEric Taylor extern void libzfs_mnttab_init(libzfs_handle_t *);
227ebedde84SEric Taylor extern void libzfs_mnttab_fini(libzfs_handle_t *);
228b2634b9cSEric Taylor extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t);
229ebedde84SEric Taylor extern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
230ebedde84SEric Taylor     struct mnttab *);
231ebedde84SEric Taylor extern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
232ebedde84SEric Taylor     const char *, const char *);
233ebedde84SEric Taylor extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
235fa9e4066Sahrens /*
236fa9e4066Sahrens  * Basic handle functions
237fa9e4066Sahrens  */
23899653d4eSeschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
23999653d4eSeschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
240fa9e4066Sahrens extern void zpool_close(zpool_handle_t *);
241fa9e4066Sahrens extern const char *zpool_get_name(zpool_handle_t *);
242fa9e4066Sahrens extern int zpool_get_state(zpool_handle_t *);
2436401734dSWill Andrews extern const char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
2446401734dSWill Andrews extern const char *zpool_pool_state_to_name(pool_state_t);
24529ab75c9Srm extern void zpool_free_handles(libzfs_handle_t *);
247fa9e4066Sahrens /*
248fa9e4066Sahrens  * Iterate over all active pools in the system.
249fa9e4066Sahrens  */
250fa9e4066Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
25199653d4eSeschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
2528808ac5dSYuri Pankov extern boolean_t zpool_skip_pool(const char *);
254fa9e4066Sahrens /*
255fa9e4066Sahrens  * Functions to create and destroy pools
256fa9e4066Sahrens  */
25799653d4eSeschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
2580a48a24eStimh     nvlist_t *, nvlist_t *);
2594445fffbSMatthew Ahrens extern int zpool_destroy(zpool_handle_t *, const char *);
260fa9e4066Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *);
2621195e687SMark J Musante typedef struct splitflags {
2631195e687SMark J Musante 	/* do not split, but return the config that would be split off */
2641195e687SMark J Musante 	int dryrun : 1;
2651195e687SMark J Musante 
2661195e687SMark J Musante 	/* after splitting, import the pool */
2671195e687SMark J Musante 	int import : 1;
268663207adSDon Brady 	int name_flags;
2691195e687SMark J Musante } splitflags_t;
2701195e687SMark J Musante 
271084fd14fSBrian Behlendorf typedef struct trimflags {
272084fd14fSBrian Behlendorf 	/* requested vdevs are for the entire pool */
273084fd14fSBrian Behlendorf 	boolean_t fullpool;
274084fd14fSBrian Behlendorf 
275084fd14fSBrian Behlendorf 	/* request a secure trim, requires support from device */
276084fd14fSBrian Behlendorf 	boolean_t secure;
277084fd14fSBrian Behlendorf 
278084fd14fSBrian Behlendorf 	/* trim at the requested rate in bytes/second */
279084fd14fSBrian Behlendorf 	uint64_t rate;
280084fd14fSBrian Behlendorf } trimflags_t;
281084fd14fSBrian Behlendorf 
282fa9e4066Sahrens /*
283fa9e4066Sahrens  * Functions to manipulate pool and vdev state
284fa9e4066Sahrens  */
2851702cce7SAlek Pinchuk extern int zpool_scan(zpool_handle_t *, pool_scan_func_t, pool_scrub_cmd_t);
286094e47e9SGeorge Wilson extern int zpool_initialize(zpool_handle_t *, pool_initialize_func_t,
287094e47e9SGeorge Wilson     nvlist_t *);
288084fd14fSBrian Behlendorf extern int zpool_trim(zpool_handle_t *, pool_trim_func_t, nvlist_t *,
289084fd14fSBrian Behlendorf     trimflags_t *);
290084fd14fSBrian Behlendorf 
291468c413aSTim Haley extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *);
292e9103aaeSGarrett D'Amore extern int zpool_reguid(zpool_handle_t *);
2934263d13fSGeorge Wilson extern int zpool_reopen(zpool_handle_t *);
2959c2acf00SAlek Pinchuk extern int zpool_sync_one(zpool_handle_t *, void *);
2969c2acf00SAlek Pinchuk 
2973d7072f8Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
2983d7072f8Seschrock     vdev_state_t *);
2993d7072f8Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
3003d7072f8Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *,
3013d7072f8Seschrock     const char *, nvlist_t *, int);
302fa9e4066Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *);
30399653d4eSeschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *);
3045cabbc6bSPrashanth Sreenivasa extern int zpool_vdev_remove_cancel(zpool_handle_t *);
3055cabbc6bSPrashanth Sreenivasa extern int zpool_vdev_indirect_size(zpool_handle_t *, const char *, uint64_t *);
3061195e687SMark J Musante extern int zpool_vdev_split(zpool_handle_t *, char *, nvlist_t **, nvlist_t *,
3071195e687SMark J Musante     splitflags_t);
309069f55e2SEric Schrock extern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t);
310069f55e2SEric Schrock extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t);
3113d7072f8Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
313fa94a07fSbrendan extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *,
314ee0eb9f2SEric Schrock     boolean_t *, boolean_t *);
315573ca77eSGeorge Wilson extern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *,
316573ca77eSGeorge Wilson     boolean_t *, boolean_t *, boolean_t *);
3177855d95bSToomas Soome extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, const char *,
3187855d95bSToomas Soome     zpool_boot_label_t, uint64_t, int *);
320b1b8ab34Slling /*
321b1b8ab34Slling  * Functions to manage pool properties
322b1b8ab34Slling  */
323b1b8ab34Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
3243d7072f8Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
325c58b3526SAdam Stevko     size_t proplen, zprop_source_t *, boolean_t);
326990b4856Slling extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t,
327990b4856Slling     zprop_source_t *);
329b1b8ab34Slling extern const char *zpool_prop_to_name(zpool_prop_t);
330b1b8ab34Slling extern const char *zpool_prop_values(zpool_prop_t);
332fa9e4066Sahrens /*
333fa9e4066Sahrens  * Pool health statistics.
334fa9e4066Sahrens  */
335fa9e4066Sahrens typedef enum {
336fa9e4066Sahrens 	/*
337fa9e4066Sahrens 	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
338b81d61a6Slling 	 * event namespace.  Each is associated with a corresponding message ID.
339e0f1c0afSOlaf Faaland 	 * This must be kept in sync with the zfs_msgid_table in
340e0f1c0afSOlaf Faaland 	 * lib/libzfs/libzfs_status.c.
341fa9e4066Sahrens 	 */
342fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
343fa9e4066Sahrens 	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
344fa9e4066Sahrens 	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
345fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
346b81d61a6Slling 	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device label with no replicas */
347fa9e4066Sahrens 	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
348fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
349fa9e4066Sahrens 	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
350fa9e4066Sahrens 	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
351eaca9bbdSeschrock 	ZPOOL_STATUS_VERSION_NEWER,	/* newer on-disk version */
35295173954Sek 	ZPOOL_STATUS_HOSTID_MISMATCH,	/* last accessed by another system */
353e0f1c0afSOlaf Faaland 	ZPOOL_STATUS_HOSTID_ACTIVE,	/* currently active on another system */
354e0f1c0afSOlaf Faaland 	ZPOOL_STATUS_HOSTID_REQUIRED,	/* multihost=on and hostid=0 */
35532b87932Sek 	ZPOOL_STATUS_IO_FAILURE_WAIT,	/* failed I/O, failmode 'wait' */
35632b87932Sek 	ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */
357e0f1c0afSOlaf Faaland 	ZPOOL_STATUS_IO_FAILURE_MMP,	/* failed MMP, failmode not 'panic' */
358f67f35c3SEric Schrock 	ZPOOL_STATUS_BAD_LOG,		/* cannot read log chain(s) */
359eb633035STom Caputi 	ZPOOL_STATUS_ERRATA,		/* informational errata available */
360f67f35c3SEric Schrock 
361ad135b5dSChristopher Siden 	/*
362ad135b5dSChristopher Siden 	 * If the pool has unsupported features but can still be opened in
363ad135b5dSChristopher Siden 	 * read-only mode, its status is ZPOOL_STATUS_UNSUP_FEAT_WRITE. If the
364ad135b5dSChristopher Siden 	 * pool has unsupported features but cannot be opened at all, its
365ad135b5dSChristopher Siden 	 * status is ZPOOL_STATUS_UNSUP_FEAT_READ.
366ad135b5dSChristopher Siden 	 */
367ad135b5dSChristopher Siden 	ZPOOL_STATUS_UNSUP_FEAT_READ,	/* unsupported features for read */
368ad135b5dSChristopher Siden 	ZPOOL_STATUS_UNSUP_FEAT_WRITE,	/* unsupported features for write */
369ad135b5dSChristopher Siden 
370f67f35c3SEric Schrock 	/*
371f67f35c3SEric Schrock 	 * These faults have no corresponding message ID.  At the time we are
372f67f35c3SEric Schrock 	 * checking the status, the original reason for the FMA fault (I/O or
373f67f35c3SEric Schrock 	 * checksum errors) has been lost.
374f67f35c3SEric Schrock 	 */
3753d7072f8Seschrock 	ZPOOL_STATUS_FAULTED_DEV_R,	/* faulted device with replicas */
3763d7072f8Seschrock 	ZPOOL_STATUS_FAULTED_DEV_NR,	/* faulted device with no replicas */
378fa9e4066Sahrens 	/*
379fa9e4066Sahrens 	 * The following are not faults per se, but still an error possibly
380b81d61a6Slling 	 * requiring administrative attention.  There is no corresponding
381fa9e4066Sahrens 	 * message ID.
382fa9e4066Sahrens 	 */
38357221772SChristopher Siden 	ZPOOL_STATUS_VERSION_OLDER,	/* older legacy on-disk version */
38457221772SChristopher Siden 	ZPOOL_STATUS_FEAT_DISABLED,	/* supported features are disabled */
385fa9e4066Sahrens 	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
386cb605c4dSGerhard Roethlin 	ZPOOL_STATUS_OFFLINE_DEV,	/* device offline */
387c25309d4SGeorge Wilson 	ZPOOL_STATUS_REMOVED_DEV,	/* removed device */
389fa9e4066Sahrens 	/*
390fa9e4066Sahrens 	 * Finally, the following indicates a healthy pool.
391fa9e4066Sahrens 	 */
392fa9e4066Sahrens 	ZPOOL_STATUS_OK
393fa9e4066Sahrens } zpool_status_t;
395eb633035STom Caputi extern zpool_status_t zpool_get_status(zpool_handle_t *, char **,
396eb633035STom Caputi     zpool_errata_t *);
397eb633035STom Caputi extern zpool_status_t zpool_import_status(nvlist_t *, char **,
398eb633035STom Caputi     zpool_errata_t *);
400fa9e4066Sahrens /*
401fa9e4066Sahrens  * Statistics and configuration functions.
402fa9e4066Sahrens  */
403ea8dc4b6Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
404ad135b5dSChristopher Siden extern nvlist_t *zpool_get_features(zpool_handle_t *);
40594de1d4cSeschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
40655434c77Sek extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
4077855d95bSToomas Soome extern boolean_t zpool_is_bootable(zpool_handle_t *);
409fa9e4066Sahrens /*
410fa9e4066Sahrens  * Import and export functions
411fa9e4066Sahrens  */
4124445fffbSMatthew Ahrens extern int zpool_export(zpool_handle_t *, boolean_t, const char *);
4134445fffbSMatthew Ahrens extern int zpool_export_force(zpool_handle_t *, const char *);
41499653d4eSeschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
415990b4856Slling     char *altroot);
416990b4856Slling extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
4174b964adaSGeorge Wilson     nvlist_t *, int);
418ad135b5dSChristopher Siden extern void zpool_print_unsup_feat(nvlist_t *config);
420c67d9675Seschrock /*
421c67d9675Seschrock  * Miscellaneous pool functions
422c67d9675Seschrock  */
423ecd6cf80Smarks struct zfs_cmd;
4254445fffbSMatthew Ahrens extern const char *zfs_history_event_names[];
4268f18d1faSGeorge Wilson 
427663207adSDon Brady typedef enum {
428663207adSDon Brady 	VDEV_NAME_PATH		= 1 << 0,
429663207adSDon Brady 	VDEV_NAME_GUID		= 1 << 1,
430663207adSDon Brady 	VDEV_NAME_FOLLOW_LINKS	= 1 << 2,
431663207adSDon Brady 	VDEV_NAME_TYPE_ID	= 1 << 3,
432663207adSDon Brady } vdev_name_t;
433663207adSDon Brady 
43488ecc943SGeorge Wilson extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *,
435663207adSDon Brady     int name_flags);
436990b4856Slling extern int zpool_upgrade(zpool_handle_t *, uint64_t);
437a52121eaSChunwei Chen extern int zpool_get_history(zpool_handle_t *, nvlist_t **, uint64_t *,
438a52121eaSChunwei Chen     boolean_t *);
43955434c77Sek extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
44055434c77Sek     size_t len);
441ecd6cf80Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
442753a6d45SSherry Moore extern int zpool_get_physpath(zpool_handle_t *, char *, size_t);
443468c413aSTim Haley extern void zpool_explain_recover(libzfs_handle_t *, const char *, int,
444468c413aSTim Haley     nvlist_t *);
44586714001SSerapheim Dimitropoulos extern int zpool_checkpoint(zpool_handle_t *);
44686714001SSerapheim Dimitropoulos extern int zpool_discard_checkpoint(zpool_handle_t *);
447753a6d45SSherry Moore 
448fa9e4066Sahrens /*
449fa9e4066Sahrens  * Basic handle manipulations.  These functions do not create or destroy the
450fa9e4066Sahrens  * underlying datasets, only the references to them.
451fa9e4066Sahrens  */
45299653d4eSeschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
45319b94df9SMatthew Ahrens extern zfs_handle_t *zfs_handle_dup(zfs_handle_t *);
454fa9e4066Sahrens extern void zfs_close(zfs_handle_t *);
455fa9e4066Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *);
456fa9e4066Sahrens extern const char *zfs_get_name(const zfs_handle_t *);
457d5b5bb25SRich Morris extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
4588808ac5dSYuri Pankov extern const char *zfs_get_pool_name(const zfs_handle_t *);
460fa9e4066Sahrens /*
461fa9e4066Sahrens  * Property management functions.  Some functions are shared with the kernel,
462b81d61a6Slling  * and are found in sys/fs/zfs.h.
463fa9e4066Sahrens  */
465990b4856Slling /*
466990b4856Slling  * zfs dataset property management
467990b4856Slling  */
468990b4856Slling extern const char *zfs_prop_default_string(zfs_prop_t);
469990b4856Slling extern uint64_t zfs_prop_default_numeric(zfs_prop_t);
470990b4856Slling extern const char *zfs_prop_column_name(zfs_prop_t);
471990b4856Slling extern boolean_t zfs_prop_align_right(zfs_prop_t);
473eb633035STom Caputi extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t, nvlist_t *,
474eb633035STom Caputi     uint64_t, zfs_handle_t *, zpool_handle_t *, boolean_t, const char *);
476e9dbad6fSeschrock extern const char *zfs_prop_to_name(zfs_prop_t);
477e9dbad6fSeschrock extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
47830925561SChris Williamson extern int zfs_prop_set_list(zfs_handle_t *, nvlist_t *);
479e9dbad6fSeschrock extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
480990b4856Slling     zprop_source_t *, char *, size_t, boolean_t);
48192241e0bSTom Erickson extern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t,
48292241e0bSTom Erickson     boolean_t);
483e9dbad6fSeschrock extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
484990b4856Slling     zprop_source_t *, char *, size_t);
485edea4b55SLin Ling extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname,
486edea4b55SLin Ling     uint64_t *propvalue);
48714843421SMatthew Ahrens extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname,
48814843421SMatthew Ahrens     char *propbuf, int proplen, boolean_t literal);
48919b94df9SMatthew Ahrens extern int zfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname,
49019b94df9SMatthew Ahrens     uint64_t *propvalue);
49119b94df9SMatthew Ahrens extern int zfs_prop_get_written(zfs_handle_t *zhp, const char *propname,
49219b94df9SMatthew Ahrens     char *propbuf, int proplen, boolean_t literal);
493ad135b5dSChristopher Siden extern int zfs_prop_get_feature(zfs_handle_t *zhp, const char *propname,
494ad135b5dSChristopher Siden     char *buf, size_t len);
495e9dbad6fSeschrock extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
49692241e0bSTom Erickson extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t);
497e9dbad6fSeschrock extern const char *zfs_prop_values(zfs_prop_t);
498e9dbad6fSeschrock extern int zfs_prop_is_string(zfs_prop_t prop);
499990b4856Slling extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
50092241e0bSTom Erickson extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *);
50119b94df9SMatthew Ahrens extern nvlist_t *zfs_get_clones_nvl(zfs_handle_t *);
50219b94df9SMatthew Ahrens 
504eb633035STom Caputi /*
505eb633035STom Caputi  * zfs encryption management
506eb633035STom Caputi  */
507eb633035STom Caputi extern int zfs_crypto_get_encryption_root(zfs_handle_t *, boolean_t *, char *);
508eb633035STom Caputi extern int zfs_crypto_create(libzfs_handle_t *, char *, nvlist_t *, nvlist_t *,
5096ccda740Sloli     boolean_t stdin_available, uint8_t **, uint_t *);
510eb633035STom Caputi extern int zfs_crypto_clone_check(libzfs_handle_t *, zfs_handle_t *, char *,
511eb633035STom Caputi     nvlist_t *);
512eb633035STom Caputi extern int zfs_crypto_attempt_load_keys(libzfs_handle_t *, char *);
513eb633035STom Caputi extern int zfs_crypto_load_key(zfs_handle_t *, boolean_t, char *);
514eb633035STom Caputi extern int zfs_crypto_unload_key(zfs_handle_t *);
515eb633035STom Caputi extern int zfs_crypto_rewrap(zfs_handle_t *, nvlist_t *, boolean_t);
516eb633035STom Caputi 
517990b4856Slling typedef struct zprop_list {
518990b4856Slling 	int		pl_prop;
519e9dbad6fSeschrock 	char		*pl_user_prop;
520990b4856Slling 	struct zprop_list *pl_next;
521e9dbad6fSeschrock 	boolean_t	pl_all;
522e9dbad6fSeschrock 	size_t		pl_width;
52392241e0bSTom Erickson 	size_t		pl_recvd_width;
524e9dbad6fSeschrock 	boolean_t	pl_fixed;
525990b4856Slling } zprop_list_t;
52743d68d68SYuri Pankov extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t,
52843d68d68SYuri Pankov     boolean_t);
5292e5e9e19SSanjeev Bagewadi extern void zfs_prune_proplist(zfs_handle_t *, uint8_t *);
531fa9e4066Sahrens #define	ZFS_MOUNTPOINT_NONE	"none"
532fa9e4066Sahrens #define	ZFS_MOUNTPOINT_LEGACY	"legacy"
534ad135b5dSChristopher Siden #define	ZFS_FEATURE_DISABLED	"disabled"
535ad135b5dSChristopher Siden #define	ZFS_FEATURE_ENABLED	"enabled"
536ad135b5dSChristopher Siden #define	ZFS_FEATURE_ACTIVE	"active"
537ad135b5dSChristopher Siden 
538ad135b5dSChristopher Siden #define	ZFS_UNSUPPORTED_INACTIVE	"inactive"
539ad135b5dSChristopher Siden #define	ZFS_UNSUPPORTED_READONLY	"readonly"
540ad135b5dSChristopher Siden 
541b1b8ab34Slling /*
542990b4856Slling  * zpool property management
543990b4856Slling  */
544990b4856Slling extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **);
545ad135b5dSChristopher Siden extern int zpool_prop_get_feature(zpool_handle_t *, const char *, char *,
546ad135b5dSChristopher Siden     size_t);
547990b4856Slling extern const char *zpool_prop_default_string(zpool_prop_t);
548990b4856Slling extern uint64_t zpool_prop_default_numeric(zpool_prop_t);
549990b4856Slling extern const char *zpool_prop_column_name(zpool_prop_t);
550990b4856Slling extern boolean_t zpool_prop_align_right(zpool_prop_t);
552990b4856Slling /*