1fa9e406ahrens/*
2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5441d80alling * Common Development and Distribution License (the "License").
6441d80alling * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
21f3861e1ahl
22fa9e406ahrens/*
233f9d6adLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
240d8fa8fMartin Matuska * Copyright (c) 2011 Pawel Jakub Dawidek. All rights reserved.
257ac8935Don Brady * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
26d8ab6e1Don Brady * Copyright 2020 Joyent, Inc.
27a7a845eSteven Hartland * Copyright (c) 2013 Steven Hartland. All rights reserved.
28c3d26abMatthew Ahrens * Copyright (c) 2014 Integros [integros.com]
298808ac5Yuri Pankov * Copyright 2016 Nexenta Systems, Inc.
301702cceAlek Pinchuk * Copyright (c) 2017 Datto Inc.
31fa9e406ahrens */
32fa9e406ahrens
33fa9e406ahrens#ifndef	_LIBZFS_H
34fa9e406ahrens#define	_LIBZFS_H
35fa9e406ahrens
36fa9e406ahrens#include <assert.h>
37fa9e406ahrens#include <libnvpair.h>
38ebedde8Eric Taylor#include <sys/mnttab.h>
39fa9e406ahrens#include <sys/param.h>
40fa9e406ahrens#include <sys/types.h>
41fa9e406ahrens#include <sys/varargs.h>
42fa9e406ahrens#include <sys/fs/zfs.h>
43ecd6cf8marks#include <sys/avl.h>
44ecd6cf8marks#include <ucred.h>
455d7b4d4Matthew Ahrens#include <libzfs_core.h>
46fa9e406ahrens
47fa9e406ahrens#ifdef	__cplusplus
48fa9e406ahrensextern "C" {
49fa9e406ahrens#endif
50fa9e406ahrens
51fa9e406ahrens/*
52fa9e406ahrens * Miscellaneous ZFS constants
53fa9e406ahrens */
54fa9e406ahrens#define	ZFS_MAXPROPLEN		MAXPATHLEN
55990b485lling#define	ZPOOL_MAXPROPLEN	MAXPATHLEN
56fa9e406ahrens
57fa9e406ahrens/*
5899653d4eschrock * libzfs errors
5999653d4eschrock */
604445fffMatthew Ahrenstypedef enum zfs_error {
614445fffMatthew Ahrens	EZFS_SUCCESS = 0,	/* no error -- success */
6299653d4eschrock	EZFS_NOMEM = 2000,	/* out of memory */
6399653d4eschrock	EZFS_BADPROP,		/* invalid property value */
6499653d4eschrock	EZFS_PROPREADONLY,	/* cannot set readonly property */
6599653d4eschrock	EZFS_PROPTYPE,		/* property does not apply to dataset type */
6699653d4eschrock	EZFS_PROPNONINHERIT,	/* property is not inheritable */
6799653d4eschrock	EZFS_PROPSPACE,		/* bad quota or reservation */
6899653d4eschrock	EZFS_BADTYPE,		/* dataset is not of appropriate type */
6999653d4eschrock	EZFS_BUSY,		/* pool or dataset is busy */
7099653d4eschrock	EZFS_EXISTS,		/* pool or dataset already exists */
7199653d4eschrock	EZFS_NOENT,		/* no such pool or dataset */
7299653d4eschrock	EZFS_BADSTREAM,		/* bad backup stream */
7399653d4eschrock	EZFS_DSREADONLY,	/* dataset is readonly */
7499653d4eschrock	EZFS_VOLTOOBIG,		/* volume is too large for 32-bit system */
7599653d4eschrock	EZFS_INVALIDNAME,	/* invalid dataset name */
7699653d4eschrock	EZFS_BADRESTORE,	/* unable to restore to destination */
7799653d4eschrock	EZFS_BADBACKUP,		/* backup failed */
7899653d4eschrock	EZFS_BADTARGET,		/* bad attach/detach/replace target */
7999653d4eschrock	EZFS_NODEVICE,		/* no such device in pool */
8099653d4eschrock	EZFS_BADDEV,		/* invalid device to add */
8199653d4eschrock	EZFS_NOREPLICAS,	/* no valid replicas */
8299653d4eschrock	EZFS_RESILVERING,	/* currently resilvering */
8399653d4eschrock	EZFS_BADVERSION,	/* unsupported version */
8499653d4eschrock	EZFS_POOLUNAVAIL,	/* pool is currently unavailable */
8599653d4eschrock	EZFS_DEVOVERFLOW,	/* too many devices in one vdev */
8699653d4eschrock	EZFS_BADPATH,		/* must be an absolute path */
8799653d4eschrock	EZFS_CROSSTARGET,	/* rename or clone across pool or dataset */
8899653d4eschrock	EZFS_ZONED,		/* used improperly in local zone */
8999653d4eschrock	EZFS_MOUNTFAILED,	/* failed to mount dataset */
9099653d4eschrock	EZFS_UMOUNTFAILED,	/* failed to unmount dataset */
91f3861e1ahl	EZFS_UNSHARENFSFAILED,	/* unshare(1M) failed */
92f3861e1ahl	EZFS_SHARENFSFAILED,	/* share(1M) failed */
9399653d4eschrock	EZFS_PERM,		/* permission denied */
9499653d4eschrock	EZFS_NOSPC,		/* out of space */
956e27f86Sam Falkner	EZFS_FAULT,		/* bad address */
9699653d4eschrock	EZFS_IO,		/* I/O error */
9799653d4eschrock	EZFS_INTR,		/* signal received */
9899653d4eschrock	EZFS_ISSPARE,		/* device is a hot spare */
9999653d4eschrock	EZFS_INVALCONFIG,	/* invalid vdev configuration */
1003bb79beeschrock	EZFS_RECURSIVE,		/* recursive dependency */
10106eeb2aek	EZFS_NOHISTORY,		/* no history object */
102b1b8ab3lling	EZFS_POOLPROPS,		/* couldn't retrieve pool props */
103b1b8ab3lling	EZFS_POOL_NOTSUP,	/* ops not supported for this type of pool */
104b1b8ab3lling	EZFS_POOL_INVALARG,	/* invalid argument for this pool operation */
105b7661ccmmusante	EZFS_NAMETOOLONG,	/* dataset name is too long */
1068488aebtaylor	EZFS_OPENFAILED,	/* open of device failed */
1078488aebtaylor	EZFS_NOCAP,		/* couldn't get capacity */
1088488aebtaylor	EZFS_LABELFAILED,	/* write of label failed */
109ecd6cf8marks	EZFS_BADWHO,		/* invalid permission who */
110ecd6cf8marks	EZFS_BADPERM,		/* invalid permission */
111ecd6cf8marks	EZFS_BADPERMSET,	/* invalid permission set name */
112ecd6cf8marks	EZFS_NODELEGATION,	/* delegated administration is disabled */
113da6c28aamw	EZFS_UNSHARESMBFAILED,	/* failed to unshare over smb */
114da6c28aamw	EZFS_SHARESMBFAILED,	/* failed to share over smb */
1152f8aaabeschrock	EZFS_BADCACHE,		/* bad cache file */
116fa94a07brendan	EZFS_ISL2CACHE,		/* device is for the level 2 ARC */
117e7cbe64gw	EZFS_VDEVNOTSUP,	/* unsupported vdev type */
11815e6edfgw	EZFS_NOTSUP,		/* ops not supported on this dataset */
11989a89eblling	EZFS_ACTIVE_SPARE,	/* pool has active shared spare devices */
120e6ca193George Wilson	EZFS_UNPLAYED_LOGS,	/* log device has unplayed logs */
121842727cChris Kirby	EZFS_REFTAG_RELE,	/* snapshot release: tag not found */
122842727cChris Kirby	EZFS_REFTAG_HOLD,	/* snapshot hold: tag already exists */
123ca45db4Chris Kirby	EZFS_TAGTOOLONG,	/* snapshot hold/rele: tag too long */
1249e69d7dLori Alt	EZFS_PIPEFAILED,	/* pipe create failed */
1259e69d7dLori Alt	EZFS_THREADCREATEFAILED, /* thread create failed */
1261195e68Mark J Musante	EZFS_POSTSPLIT_ONLINE,	/* onlining a disk after splitting it */
1273f9d6adLin Ling	EZFS_SCRUBBING,		/* currently scrubbing */
1283f9d6adLin Ling	EZFS_NO_SCRUB,		/* no active scrub */
12999d5e17Tim Haley	EZFS_DIFF,		/* general failure of zfs diff */
13099d5e17Tim Haley	EZFS_DIFFDATA,		/* bad zfs diff data */
131f9af39bGeorge Wilson	EZFS_POOLREADONLY,	/* pool is in read-only mode */
1321702cceAlek Pinchuk	EZFS_SCRUB_PAUSED,	/* scrub currently paused */
133e0f1c0aOlaf Faaland	EZFS_ACTIVE_POOL,	/* pool is imported on a different system */
134084fd14Brian Behlendorf	EZFS_CRYPTOFAILED,	/* failed to setup encryption */
1355cabbc6Prashanth Sreenivasa	EZFS_NO_PENDING,	/* cannot cancel, no operation is pending */
1368671400Serapheim Dimitropoulos	EZFS_CHECKPOINT_EXISTS,	/* checkpoint exists */
1378671400Serapheim Dimitropoulos	EZFS_DISCARDING_CHECKPOINT,	/* currently discarding a checkpoint */
1388671400Serapheim Dimitropoulos	EZFS_NO_CHECKPOINT,	/* pool has no checkpoint */
1398671400Serapheim Dimitropoulos	EZFS_DEVRM_IN_PROGRESS,	/* a device is currently being removed */
1408671400Serapheim Dimitropoulos	EZFS_VDEV_TOO_BIG,	/* a device is too big to be used */
141094e47eGeorge Wilson	EZFS_TOOMANY,		/* argument list too long */
142094e47eGeorge Wilson	EZFS_INITIALIZING,	/* currently initializing */
143094e47eGeorge Wilson	EZFS_NO_INITIALIZE,	/* no active initialize */
1446ccda74loli	EZFS_WRONG_PARENT,	/* invalid parent dataset (e.g ZVOL) */
145084fd14Brian Behlendorf	EZFS_TRIMMING,		/* currently trimming */
146084fd14Brian Behlendorf	EZFS_NO_TRIM,		/* no active trim */
147084fd14Brian Behlendorf	EZFS_TRIM_NOTSUP,	/* device does not support trim */
148e4c795bTom Caputi	EZFS_NO_RESILVER_DEFER,	/* pool doesn't support resilver_defer */
1497ac8935Don Brady	EZFS_IOC_NOTSUPPORTED,	/* operation not supported by zfs module */
150b1b8ab3lling	EZFS_UNKNOWN
1514445fffMatthew Ahrens} zfs_error_t;
15299653d4eschrock
15399653d4eschrock/*
1547855d95Toomas Soome * UEFI boot support parameters. When creating whole disk boot pool,
1557855d95Toomas Soome * zpool create should allow to create EFI System partition for UEFI boot
1567855d95Toomas Soome * program. In case of BIOS, the EFI System partition is not used
1577855d95Toomas Soome * even if it does exist.
1587855d95Toomas Soome */
1597855d95Toomas Soometypedef enum zpool_boot_label {
1607855d95Toomas Soome	ZPOOL_NO_BOOT_LABEL = 0,
1617855d95Toomas Soome	ZPOOL_CREATE_BOOT_LABEL,
1627855d95Toomas Soome	ZPOOL_COPY_BOOT_LABEL
1637855d95Toomas Soome} zpool_boot_label_t;
1647855d95Toomas Soome
1657855d95Toomas Soome/*
166ecd6cf8marks * The following data structures are all part
167ecd6cf8marks * of the zfs_allow_t data structure which is
168ecd6cf8marks * used for printing 'allow' permissions.
169ecd6cf8marks * It is a linked list of zfs_allow_t's which
170ecd6cf8marks * then contain avl tree's for user/group/sets/...
171ecd6cf8marks * and each one of the entries in those trees have
172ecd6cf8marks * avl tree's for the permissions they belong to and
173ecd6cf8marks * whether they are local,descendent or local+descendent
174ecd6cf8marks * permissions.  The AVL trees are used primarily for
175ecd6cf8marks * sorting purposes, but also so that we can quickly find
176ecd6cf8marks * a given user and or permission.
177ecd6cf8marks */
178ecd6cf8markstypedef struct zfs_perm_node {
179ecd6cf8marks	avl_node_t z_node;
180ecd6cf8marks	char z_pname[MAXPATHLEN];
181ecd6cf8marks} zfs_perm_node_t;
182ecd6cf8marks
183ecd6cf8markstypedef struct zfs_allow_node {
184ecd6cf8marks	avl_node_t z_node;
185ecd6cf8marks	char z_key[MAXPATHLEN];		/* name, such as joe */
186ecd6cf8marks	avl_tree_t z_localdescend;	/* local+descendent perms */
187ecd6cf8marks	avl_tree_t z_local;		/* local permissions */
188ecd6cf8marks	avl_tree_t z_descend;		/* descendent permissions */
189ecd6cf8marks} zfs_allow_node_t;
190ecd6cf8marks
191ecd6cf8markstypedef struct zfs_allow {
192ecd6cf8marks	struct zfs_allow *z_next;
193ecd6cf8marks	char z_setpoint[MAXPATHLEN];
194ecd6cf8marks	avl_tree_t z_sets;
195ecd6cf8marks	avl_tree_t z_crperms;
196ecd6cf8marks	avl_tree_t z_user;
197ecd6cf8marks	avl_tree_t z_group;
198ecd6cf8marks	avl_tree_t z_everyone;
199ecd6cf8marks} zfs_allow_t;
200ecd6cf8marks
201ecd6cf8marks/*
202fa9e406ahrens * Basic handle types
203fa9e406ahrens */
204fa9e406ahrenstypedef struct zfs_handle zfs_handle_t;
205fa9e406ahrenstypedef struct zpool_handle zpool_handle_t;
20699653d4eschrocktypedef struct libzfs_handle libzfs_handle_t;
20799653d4eschrock
20899653d4eschrock/*
20999653d4eschrock * Library initialization
21099653d4eschrock */
21199653d4eschrockextern libzfs_handle_t *libzfs_init(void);
21299653d4eschrockextern void libzfs_fini(libzfs_handle_t *);
21399653d4eschrock
21499653d4eschrockextern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
21599653d4eschrockextern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
21699653d4eschrock
21799653d4eschrockextern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
21899653d4eschrock
2194445fffMatthew Ahrensextern void zfs_save_arguments(int argc, char **, char *, int);
2204445fffMatthew Ahrensextern int zpool_log_history(libzfs_handle_t *, const char *);
2214445fffMatthew Ahrens
22299653d4eschrockextern int libzfs_errno(libzfs_handle_t *);
22399653d4eschrockextern const char *libzfs_error_action(libzfs_handle_t *);
22499653d4eschrockextern const char *libzfs_error_description(libzfs_handle_t *);
22578f1710Matthew Ahrensextern int zfs_standard_error(libzfs_handle_t *, int, const char *);
226ebedde8Eric Taylorextern void libzfs_mnttab_init(libzfs_handle_t *);
227ebedde8Eric Taylorextern void libzfs_mnttab_fini(libzfs_handle_t *);
228b2634b9Eric Taylorextern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t);
229ebedde8Eric Taylorextern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
230ebedde8Eric Taylor    struct mnttab *);
231ebedde8Eric Taylorextern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
232ebedde8Eric Taylor    const char *, const char *);
233ebedde8Eric Taylorextern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
234fa9e406ahrens
235fa9e406ahrens/*
236fa9e406ahrens * Basic handle functions
237fa9e406ahrens */
23899653d4eschrockextern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
23999653d4eschrockextern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
240fa9e406ahrensextern void zpool_close(zpool_handle_t *);
241fa9e406ahrensextern const char *zpool_get_name(zpool_handle_t *);
242fa9e406ahrensextern int zpool_get_state(zpool_handle_t *);
2436401734Will Andrewsextern const char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
2446401734Will Andrewsextern const char *zpool_pool_state_to_name(pool_state_t);
24529ab75crmextern void zpool_free_handles(libzfs_handle_t *);
246fa9e406ahrens
247fa9e406ahrens/*
248fa9e406ahrens * Iterate over all active pools in the system.
249fa9e406ahrens */
250fa9e406ahrenstypedef int (*zpool_iter_f)(zpool_handle_t *, void *);
25199653d4eschrockextern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
2528808ac5Yuri Pankovextern boolean_t zpool_skip_pool(const char *);
253fa9e406ahrens
254fa9e406ahrens/*
255fa9e406ahrens * Functions to create and destroy pools
256fa9e406ahrens */
25799653d4eschrockextern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
2580a48a24timh    nvlist_t *, nvlist_t *);
2594445fffMatthew Ahrensextern int zpool_destroy(zpool_handle_t *, const char *);
260fa9e406ahrensextern int zpool_add(zpool_handle_t *, nvlist_t *);
261fa9e406ahrens
2621195e68Mark J Musantetypedef struct splitflags {
2631195e68Mark J Musante	/* do not split, but return the config that would be split off */
2641195e68Mark J Musante	int dryrun : 1;
2651195e68Mark J Musante
2661195e68Mark J Musante	/* after splitting, import the pool */
2671195e68Mark J Musante	int import : 1;
268663207aDon Brady	int name_flags;
2691195e68Mark J Musante} splitflags_t;
2701195e68Mark J Musante
271084fd14Brian Behlendorftypedef struct trimflags {
272084fd14Brian Behlendorf	/* requested vdevs are for the entire pool */
273084fd14Brian Behlendorf	boolean_t fullpool;
274084fd14Brian Behlendorf
275084fd14Brian Behlendorf	/* request a secure trim, requires support from device */
276084fd14Brian Behlendorf	boolean_t secure;
277084fd14Brian Behlendorf
278084fd14Brian Behlendorf	/* trim at the requested rate in bytes/second */
279084fd14Brian Behlendorf	uint64_t rate;
280084fd14Brian Behlendorf} trimflags_t;
281084fd14Brian Behlendorf
282fa9e406ahrens/*
283fa9e406ahrens * Functions to manipulate pool and vdev state
284fa9e406ahrens */
2851702cceAlek Pinchukextern int zpool_scan(zpool_handle_t *, pool_scan_func_t, pool_scrub_cmd_t);
286094e47eGeorge Wilsonextern int zpool_initialize(zpool_handle_t *, pool_initialize_func_t,
287094e47eGeorge Wilson    nvlist_t *);
288084fd14Brian Behlendorfextern int zpool_trim(zpool_handle_t *, pool_trim_func_t, nvlist_t *,
289084fd14Brian Behlendorf    trimflags_t *);
290084fd14Brian Behlendorf
291468c413Tim Haleyextern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *);
292e9103aaGarrett D'Amoreextern int zpool_reguid(zpool_handle_t *);
2934263d13George Wilsonextern int zpool_reopen(zpool_handle_t *);
294fa9e406ahrens
2959c2acf0Alek Pinchukextern int zpool_sync_one(zpool_handle_t *, void *);
2969c2acf0Alek Pinchuk
2973d7072feschrockextern int zpool_vdev_online(zpool_handle_t *, const char *, int,
2983d7072feschrock    vdev_state_t *);
2993d7072feschrockextern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
3003d7072feschrockextern int zpool_vdev_attach(zpool_handle_t *, const char *,
3013d7072feschrock    const char *, nvlist_t *, int);
302fa9e406ahrensextern int zpool_vdev_detach(zpool_handle_t *, const char *);
30399653d4eschrockextern int zpool_vdev_remove(zpool_handle_t *, const char *);
3045cabbc6Prashanth Sreenivasaextern int zpool_vdev_remove_cancel(zpool_handle_t *);
3055cabbc6Prashanth Sreenivasaextern int zpool_vdev_indirect_size(zpool_handle_t *, const char *, uint64_t *);
3061195e68Mark J Musanteextern int zpool_vdev_split(zpool_handle_t *, char *, nvlist_t **, nvlist_t *,
3071195e68Mark J Musante    splitflags_t);
3083d7072feschrock
309069f55eEric Schrockextern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t);
310069f55eEric Schrockextern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t);
3113d7072feschrockextern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
3123d7072feschrock
313fa94a07brendanextern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *,
314ee0eb9fEric Schrock    boolean_t *, boolean_t *);
315573ca77George Wilsonextern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *,
316573ca77George Wilson    boolean_t *, boolean_t *, boolean_t *);
3177855d95Toomas Soomeextern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, const char *,
3187855d95Toomas Soome    zpool_boot_label_t, uint64_t, int *);
319fa9e406ahrens
320fa9e406ahrens/*
321b1b8ab3lling * Functions to manage pool properties
322b1b8ab3lling */
323b1b8ab3llingextern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
3243d7072feschrockextern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
325c58b352Adam Stevko    size_t proplen, zprop_source_t *, boolean_t);
326990b485llingextern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t,
327990b485lling    zprop_source_t *);
328990b485lling
329b1b8ab3llingextern const char *zpool_prop_to_name(zpool_prop_t);
330b1b8ab3llingextern const char *zpool_prop_values(zpool_prop_t);
331b1b8ab3lling
332b1b8ab3lling/*
333fa9e406ahrens * Pool health statistics.
334fa9e406ahrens */
335fa9e406ahrenstypedef enum {
336fa9e406ahrens	/*
337fa9e406ahrens	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
338b81d61alling	 * event namespace.  Each is associated with a corresponding message ID.
339e0f1c0aOlaf Faaland	 * This must be kept in sync with the zfs_msgid_table in
340e0f1c0aOlaf Faaland	 * lib/libzfs/libzfs_status.c.
341fa9e406ahrens	 */
342fa9e406ahrens	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
343fa9e406ahrens	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
344fa9e406ahrens	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
345fa9e406ahrens	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
346b81d61alling	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device label with no replicas */
347fa9e406ahrens	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
348fa9e406ahrens	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
349fa9e406ahrens	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
350fa9e406ahrens	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
351eaca9bbeschrock	ZPOOL_STATUS_VERSION_NEWER,	/* newer on-disk version */
3529517395ek	ZPOOL_STATUS_HOSTID_MISMATCH,	/* last accessed by another system */
353e0f1c0aOlaf Faaland	ZPOOL_STATUS_HOSTID_ACTIVE,	/* currently active on another system */
354e0f1c0aOlaf Faaland	ZPOOL_STATUS_HOSTID_REQUIRED,	/* multihost=on and hostid=0 */
35532b8793ek	ZPOOL_STATUS_IO_FAILURE_WAIT,	/* failed I/O, failmode 'wait' */
35632b8793ek	ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */
357e0f1c0aOlaf Faaland	ZPOOL_STATUS_IO_FAILURE_MMP,	/* failed MMP, failmode not 'panic' */
358f67f35cEric Schrock	ZPOOL_STATUS_BAD_LOG,		/* cannot read log chain(s) */
359eb63303Tom Caputi	ZPOOL_STATUS_ERRATA,		/* informational errata available */
360f67f35cEric Schrock
361f67f35cEric Schrock	/*
362ad135b5Christopher Siden	 * If the pool has unsupported features but can still be opened in
363ad135b5Christopher Siden	 * read-only mode, its status is ZPOOL_STATUS_UNSUP_FEAT_WRITE. If the
364ad135b5Christopher Siden	 * pool has unsupported features but cannot be opened at all, its
365ad135b5Christopher Siden	 * status is ZPOOL_STATUS_UNSUP_FEAT_READ.
366ad135b5Christopher Siden	 */
367ad135b5Christopher Siden	ZPOOL_STATUS_UNSUP_FEAT_READ,	/* unsupported features for read */
368ad135b5Christopher Siden	ZPOOL_STATUS_UNSUP_FEAT_WRITE,	/* unsupported features for write */
369ad135b5Christopher Siden
370ad135b5Christopher Siden	/*
371f67f35cEric Schrock	 * These faults have no corresponding message ID.  At the time we are
372f67f35cEric Schrock	 * checking the status, the original reason for the FMA fault (I/O or
373f67f35cEric Schrock	 * checksum errors) has been lost.
374f67f35cEric Schrock	 */
3753d7072feschrock	ZPOOL_STATUS_FAULTED_DEV_R,	/* faulted device with replicas */
3763d7072feschrock	ZPOOL_STATUS_FAULTED_DEV_NR,	/* faulted device with no replicas */
377fa9e406ahrens
378fa9e406ahrens	/*
379fa9e406ahrens	 * The following are not faults per se, but still an error possibly
380b81d61alling	 * requiring administrative attention.  There is no corresponding
381fa9e406ahrens	 * message ID.
382fa9e406ahrens	 */
3835722177Christopher Siden	ZPOOL_STATUS_VERSION_OLDER,	/* older legacy on-disk version */
3845722177Christopher Siden	ZPOOL_STATUS_FEAT_DISABLED,	/* supported features are disabled */
385fa9e406ahrens	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
386cb605c4Gerhard Roethlin	ZPOOL_STATUS_OFFLINE_DEV,	/* device offline */
387c25309dGeorge Wilson	ZPOOL_STATUS_REMOVED_DEV,	/* removed device */
388fa9e406ahrens
389fa9e406ahrens	/*
390fa9e406ahrens	 * Finally, the following indicates a healthy pool.
391fa9e406ahrens	 */
392fa9e406ahrens	ZPOOL_STATUS_OK
393fa9e406ahrens} zpool_status_t;
394fa9e406ahrens
395eb63303Tom Caputiextern zpool_status_t zpool_get_status(zpool_handle_t *, char **,
396eb63303Tom Caputi    zpool_errata_t *);
397eb63303Tom Caputiextern zpool_status_t zpool_import_status(nvlist_t *, char **,
398eb63303Tom Caputi    zpool_errata_t *);
399fa9e406ahrens
400fa9e406ahrens/*
401fa9e406ahrens * Statistics and configuration functions.
402fa9e406ahrens */
403ea8dc4beschrockextern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
404ad135b5Christopher Sidenextern nvlist_t *zpool_get_features(zpool_handle_t *);
40594de1d4eschrockextern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
40655434c7ekextern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
4077855d95Toomas Soomeextern boolean_t zpool_is_bootable(zpool_handle_t *);
408ea8dc4beschrock
409fa9e406ahrens/*
410fa9e406ahrens * Import and export functions
411fa9e406ahrens */
4124445fffMatthew Ahrensextern int zpool_export(zpool_handle_t *, boolean_t, const char *);
4134445fffMatthew Ahrensextern int zpool_export_force(zpool_handle_t *, const char *);
41499653d4eschrockextern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
415990b485lling    char *altroot);
416990b485llingextern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
4174b964adGeorge Wilson    nvlist_t *, int);
418ad135b5Christopher Sidenextern void zpool_print_unsup_feat(nvlist_t *config);
419fa9e406ahrens
420fa9e406ahrens/*
421c67d967eschrock * Miscellaneous pool functions
422c67d967eschrock */
423ecd6cf8marksstruct zfs_cmd;
424ecd6cf8marks
4254445fffMatthew Ahrensextern const char *zfs_history_event_names[];
4268f18d1fGeorge Wilson
427663207aDon Bradytypedef enum {
428663207aDon Brady	VDEV_NAME_PATH		= 1 << 0,
429663207aDon Brady	VDEV_NAME_GUID		= 1 << 1,
430663207aDon Brady	VDEV_NAME_FOLLOW_LINKS	= 1 << 2,
431663207aDon Brady	VDEV_NAME_TYPE_ID	= 1 << 3,
432663207aDon Brady} vdev_name_t;
433663207aDon Brady
43488ecc94George Wilsonextern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *,
435663207aDon Brady    int name_flags);
436990b485llingextern int zpool_upgrade(zpool_handle_t *, uint64_t);
437a52121eChunwei Chenextern int zpool_get_history(zpool_handle_t *, nvlist_t **, uint64_t *,
438a52121eChunwei Chen    boolean_t *);
43955434c7ekextern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
44055434c7ek    size_t len);
441ecd6cf8marksextern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
442753a6d4Sherry Mooreextern int zpool_get_physpath(zpool_handle_t *, char *, size_t);
443468c413Tim Haleyextern void zpool_explain_recover(libzfs_handle_t *, const char *, int,
444468c413Tim Haley    nvlist_t *);
4458671400Serapheim Dimitropoulosextern int zpool_checkpoint(zpool_handle_t *);
4468671400Serapheim Dimitropoulosextern int zpool_discard_checkpoint(zpool_handle_t *);
447753a6d4Sherry Moore
448c67d967eschrock/*
449fa9e406ahrens * Basic handle manipulations.  These functions do not create or destroy the
450fa9e406ahrens * underlying datasets, only the references to them.
451fa9e406ahrens */
45299653d4eschrockextern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
45319b94dfMatthew Ahrensextern zfs_handle_t *zfs_handle_dup(zfs_handle_t *);
454fa9e406ahrensextern void zfs_close(zfs_handle_t *);
455fa9e406ahrensextern zfs_type_t zfs_get_type(const zfs_handle_t *);
456fa9e406ahrensextern const char *zfs_get_name(const zfs_handle_t *);
457d5b5bb2Rich Morrisextern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
4588808ac5Yuri Pankovextern const char *zfs_get_pool_name(const zfs_handle_t *);
459fa9e406ahrens
460fa9e406ahrens/*
461fa9e406ahrens * Property management functions.  Some functions are shared with the kernel,
462b81d61alling * and are found in sys/fs/zfs.h.
463fa9e406ahrens */
464990b485lling
465990b485lling/*
466990b485lling * zfs dataset property management
467990b485lling */
468990b485llingextern const char *zfs_prop_default_string(zfs_prop_t);
469990b485llingextern uint64_t zfs_prop_default_numeric(zfs_prop_t);
470990b485llingextern const char *zfs_prop_column_name(zfs_prop_t);
471990b485llingextern boolean_t zfs_prop_align_right(zfs_prop_t);
472990b485lling
473eb63303Tom Caputiextern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t, nvlist_t *,
474eb63303Tom Caputi    uint64_t, zfs_handle_t *, zpool_handle_t *, boolean_t, const char *);
4750a48a24timh
476e9dbad6eschrockextern const char *zfs_prop_to_name(zfs_prop_t);
477e9dbad6eschrockextern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
4783092556Chris Williamsonextern int zfs_prop_set_list(zfs_handle_t *, nvlist_t *);
479e9dbad6eschrockextern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
480990b485lling    zprop_source_t *, char *, size_t, boolean_t);
48192241e0Tom Ericksonextern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t,
48292241e0Tom Erickson    boolean_t);
483e9dbad6eschrockextern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
484990b485lling    zprop_source_t *, char *, size_t);
485edea4b5Lin Lingextern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname,
486edea4b5Lin Ling    uint64_t *propvalue);
4871484342Matthew Ahrensextern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname,
4881484342Matthew Ahrens    char *propbuf, int proplen, boolean_t literal);
48919b94dfMatthew Ahrensextern int zfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname,
49019b94dfMatthew Ahrens    uint64_t *propvalue);
49119b94dfMatthew Ahrensextern int zfs_prop_get_written(zfs_handle_t *zhp, const char *propname,
49219b94dfMatthew Ahrens    char *propbuf, int proplen, boolean_t literal);
493ad135b5Christopher Sidenextern int zfs_prop_get_feature(zfs_handle_t *zhp, const char *propname,
494ad135b5Christopher Siden    char *buf, size_t len);
495e9dbad6eschrockextern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
49692241e0Tom Ericksonextern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t);
497e9dbad6eschrockextern const char *zfs_prop_values(zfs_prop_t);
498e9dbad6eschrockextern int zfs_prop_is_string(zfs_prop_t prop);
499990b485llingextern nvlist_t *zfs_get_user_props(zfs_handle_t *);
50092241e0Tom Ericksonextern nvlist_t *zfs_get_recvd_props(zfs_handle_t *);
50119b94dfMatthew Ahrensextern nvlist_t *zfs_get_clones_nvl(zfs_handle_t *);
50219b94dfMatthew Ahrens
503e9dbad6eschrock
504eb63303Tom Caputi/*
505eb63303Tom Caputi * zfs encryption management
506eb63303Tom Caputi */
507eb63303Tom Caputiextern int zfs_crypto_get_encryption_root(zfs_handle_t *, boolean_t *, char *);
508eb63303Tom Caputiextern int zfs_crypto_create(libzfs_handle_t *, char *, nvlist_t *, nvlist_t *,
5096ccda74loli    boolean_t stdin_available, uint8_t **, uint_t *);
510eb63303Tom Caputiextern int zfs_crypto_clone_check(libzfs_handle_t *, zfs_handle_t *, char *,
511eb63303Tom Caputi    nvlist_t *);
512eb63303Tom Caputiextern int zfs_crypto_attempt_load_keys(libzfs_handle_t *, char *);
513eb63303Tom Caputiextern int zfs_crypto_load_key(zfs_handle_t *, boolean_t, char *);
514eb63303Tom Caputiextern int zfs_crypto_unload_key(zfs_handle_t *);
515eb63303Tom Caputiextern int zfs_crypto_rewrap(zfs_handle_t *, nvlist_t *, boolean_t);
516eb63303Tom Caputi
517990b485llingtypedef struct zprop_list {
518990b485lling	int		pl_prop;
519e9dbad6eschrock	char		*pl_user_prop;
520990b485lling	struct zprop_list *pl_next;
521e9dbad6eschrock	boolean_t	pl_all;
522e9dbad6eschrock	size_t		pl_width;
52392241e0Tom Erickson	size_t		pl_recvd_width;
524e9dbad6eschrock	boolean_t	pl_fixed;
525990b485lling} zprop_list_t;
526e9dbad6eschrock
52743d68d6Yuri Pankovextern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t,
52843d68d6Yuri Pankov    boolean_t);
5292e5e9e1Sanjeev Bagewadiextern void zfs_prune_proplist(zfs_handle_t *, uint8_t *);
530fa9e406ahrens
531fa9e406ahrens#define	ZFS_MOUNTPOINT_NONE	"none"
532fa9e406ahrens#define	ZFS_MOUNTPOINT_LEGACY	"legacy"
533fa9e406ahrens
534ad135b5Christopher Siden#define	ZFS_FEATURE_DISABLED	"disabled"
535ad135b5Christopher Siden#define	ZFS_FEATURE_ENABLED	"enabled"
536ad135b5Christopher Siden#define	ZFS_FEATURE_ACTIVE	"active"
537ad135b5Christopher Siden
538ad135b5Christopher Siden#define	ZFS_UNSUPPORTED_INACTIVE	"inactive"
539ad135b5Christopher Siden#define	ZFS_UNSUPPORTED_READONLY	"readonly"
540ad135b5Christopher Siden
541fa9e406ahrens/*
542990b485lling * zpool property management
543990b485lling */
544990b485llingextern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **);
545ad135b5Christopher Sidenextern int zpool_prop_get_feature(zpool_handle_t *, const char *, char *,
546ad135b5Christopher Siden    size_t);
547990b485llingextern const char *zpool_prop_default_string(zpool_prop_t);
548990b485llingextern uint64_t zpool_prop_default_numeric(zpool_prop_t);
549990b485llingextern const char *zpool_prop_column_name(zpool_prop_t);
550990b485llingextern boolean_t zpool_prop_align_right(zpool_prop_t);
551990b485lling
552990b485lling/*
553990b485lling * Functions shared by zfs and zpool property management.
554b1b8ab3lling */
555990b485llingextern int zprop_iter(zprop_func func, void *cb, boolean_t show_all,
556990b485lling    boolean_t ordered, zfs_type_t type);
557990b485llingextern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **,
558990b485lling    zfs_type_t);
559990b485llingextern void zprop_free_list(zprop_list_t *);
560990b485lling
56192241e0Tom Erickson#define	ZFS_GET_NCOLS	5
56292241e0Tom Erickson
56392241e0Tom Ericksontypedef enum {
56492241e0Tom Erickson	GET_COL_NONE,
56592241e0Tom Erickson	GET_COL_NAME,
56692241e0Tom Erickson	GET_COL_PROPERTY,
56792241e0Tom Erickson	GET_COL_VALUE,
56892241e0Tom Erickson	GET_COL_RECVD,
56992241e0Tom Erickson	GET_COL_SOURCE
57092241e0Tom Erickson} zfs_get_column_t;
57192241e0Tom Erickson
572990b485lling/*
573990b485lling * Functions for printing zfs or zpool properties
574990b485lling */
575990b485llingtypedef struct zprop_get_cbdata {
576b1b8ab3lling	int cb_sources;
57792241e0Tom Erickson	zfs_get_column_t cb_columns[ZFS_GET_NCOLS];
57892241e0Tom Erickson	int cb_colwidths[ZFS_GET_NCOLS + 1];
579b1b8ab3lling	boolean_t cb_scripted;
580b1b8ab3lling	boolean_t cb_literal;
581b1b8ab3lling	boolean_t cb_first;
582990b485lling	zprop_list_t *cb_proplist;
583990b485lling	zfs_type_t cb_type;
584990b485lling} zprop_get_cbdata_t;
585b1b8ab3lling
586990b485llingvoid zprop_print_one_property(const char *, zprop_get_cbdata_t *,
58792241e0Tom Erickson    const char *, const char *, zprop_source_t, const char *,
58892241e0Tom Erickson    const char *);
589b1b8ab3lling
590b1b8ab3lling/*
591fa9e406ahrens * Iterator functions.
592fa9e406ahrens */
593fa9e406ahrenstypedef int (*zfs_iter_f)(zfs_handle_t *, void *);
59499653d4eschrockextern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
595fa9e406ahrensextern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
5963bb79beeschrockextern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
5977f7322feschrockextern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
5980d8fa8fMartin Matuskaextern int zfs_iter_snapshots(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
599ca45db4Chris Kirbyextern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *);
60019b94dfMatthew Ahrensextern int zfs_iter_snapspec(zfs_handle_t *, const char *, zfs_iter_f, void *);
60178f1710Matthew Ahrensextern int zfs_iter_bookmarks(zfs_handle_t *, zfs_iter_f, void *);
602fa9e406ahrens
6039d9a58eEric Taylortypedef struct get_all_cb {
6049d9a58eEric Taylor	zfs_handle_t	**cb_handles;
6059d9a58eEric Taylor	size_t		cb_alloc;
6069d9a58eEric Taylor	size_t		cb_used;
6079d9a58eEric Taylor} get_all_cb_t;
6089d9a58eEric Taylor
609591e0e1Sebastien Royvoid zfs_foreach_mountpoint(libzfs_handle_t *, zfs_handle_t **, size_t,
610591e0e1Sebastien Roy    zfs_iter_f, void *, boolean_t);
6119d9a58eEric Taylorvoid libzfs_add_handle(get_all_cb_t *, zfs_handle_t *);
6129d9a58eEric Taylor
613fa9e406ahrens/*
614fa9e406ahrens * Functions to create and destroy datasets.
615fa9e406ahrens */
61699653d4eschrockextern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
617e9dbad6eschrock    nvlist_t *);
6187f1f55evbextern int zfs_create_ancestors(libzfs_handle_t *, const char *);
619842727cChris Kirbyextern int zfs_destroy(zfs_handle_t *, boolean_t);
620842727cChris Kirbyextern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t);
6213b2aab1Matthew Ahrensextern int zfs_destroy_snaps_nvl(libzfs_handle_t *, nvlist_t *, boolean_t);
622e9dbad6eschrockextern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
623bb0ade0ahrensextern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
6244445fffMatthew Ahrensextern int zfs_snapshot_nvl(libzfs_handle_t *hdl, nvlist_t *snaps,
6254445fffMatthew Ahrens    nvlist_t *props);
626c391e32ahrensextern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
6276a9cb0eEric Schrockextern int zfs_rename(zfs_handle_t *, const char *, boolean_t, boolean_t);
6289e69d7dLori Alt
6299e69d7dLori Alttypedef struct sendflags {
6309e69d7dLori Alt	/* print informational messages (ie, -v was specified) */
63119b94dfMatthew Ahrens	boolean_t verbose;
6329e69d7dLori Alt
63392241e0Tom Erickson	/* recursive send  (ie, -R) */
63419b94dfMatthew Ahrens	boolean_t replicate;
6359e69d7dLori Alt
6369e69d7dLori Alt	/* for incrementals, do all intermediate snapshots */
63719b94dfMatthew Ahrens	boolean_t doall;
6389e69d7dLori Alt
6399e69d7dLori Alt	/* if dataset is a clone, do incremental from its origin */
64019b94dfMatthew Ahrens	boolean_t fromorigin;
6419e69d7dLori Alt
6429e69d7dLori Alt	/* do deduplication */
64319b94dfMatthew Ahrens	boolean_t dedup;
64492241e0Tom Erickson
64592241e0Tom Erickson	/* send properties (ie, -p) */
64619b94dfMatthew Ahrens	boolean_t props;
64719b94dfMatthew Ahrens
64819b94dfMatthew Ahrens	/* do not send (no-op, ie. -n) */
64919b94dfMatthew Ahrens	boolean_t dryrun;
65019b94dfMatthew Ahrens
65119b94dfMatthew Ahrens	/* parsable verbose output (ie. -P) */
65219b94dfMatthew Ahrens	boolean_t parsable;
6534e3c9f4Bill Pijewski
6544e3c9f4Bill Pijewski	/* show progress (ie. -v) */
6554e3c9f4Bill Pijewski	boolean_t progress;
6565d7b4d4Matthew Ahrens
657b515258Matthew Ahrens	/* large blocks (>128K) are permitted */
658