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 */
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.
255cabbc6Prashanth Sreenivasa * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
26e0f1c0aOlaf Faaland * Copyright 2019 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 */
33fa9e406ahrens#ifndef	_LIBZFS_H
34fa9e406ahrens#define	_LIBZFS_H
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>
47fa9e406ahrens#ifdef	__cplusplus
48fa9e406ahrensextern "C" {
52fa9e406ahrens * Miscellaneous ZFS constants
53fa9e406ahrens */
54fa9e406ahrens#define	ZFS_MAXPROPLEN		MAXPATHLEN
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 */
149b1b8ab3lling	EZFS_UNKNOWN
1504445fffMatthew Ahrens} zfs_error_t;
1537855d95Toomas Soome * UEFI boot support parameters. When creating whole disk boot pool,
1547855d95Toomas Soome * zpool create should allow to create EFI System partition for UEFI boot
1557855d95Toomas Soome * program. In case of BIOS, the EFI System partition is not used
1567855d95Toomas Soome * even if it does exist.
1577855d95Toomas Soome */
1587855d95Toomas Soometypedef enum zpool_boot_label {
1597855d95Toomas Soome	ZPOOL_NO_BOOT_LABEL = 0,
1607855d95Toomas Soome	ZPOOL_CREATE_BOOT_LABEL,
1617855d95Toomas Soome	ZPOOL_COPY_BOOT_LABEL
1627855d95Toomas Soome} zpool_boot_label_t;
1637855d95Toomas Soome
1647855d95Toomas Soome/*
165ecd6cf8marks * The following data structures are all part
166ecd6cf8marks * of the zfs_allow_t data structure which is
167ecd6cf8marks * used for printing 'allow' permissions.
168ecd6cf8marks * It is a linked list of zfs_allow_t's which
169ecd6cf8marks * then contain avl tree's for user/group/sets/...
170ecd6cf8marks * and each one of the entries in those trees have
171ecd6cf8marks * avl tree's for the permissions they belong to and
172ecd6cf8marks * whether they are local,descendent or local+descendent
173ecd6cf8marks * permissions.  The AVL trees are used primarily for
174ecd6cf8marks * sorting purposes, but also so that we can quickly find
175ecd6cf8marks * a given user and or permission.
176ecd6cf8marks */
177ecd6cf8markstypedef struct zfs_perm_node {
178ecd6cf8marks	avl_node_t z_node;
179ecd6cf8marks	char z_pname[MAXPATHLEN];
180ecd6cf8marks} zfs_perm_node_t;
182ecd6cf8markstypedef struct zfs_allow_node {
183ecd6cf8marks	avl_node_t z_node;
184ecd6cf8marks	char z_key[MAXPATHLEN];		/* name, such as joe */
185ecd6cf8marks	avl_tree_t z_localdescend;	/* local+descendent perms */
186ecd6cf8marks	avl_tree_t z_local;		/* local permissions */
187ecd6cf8marks	avl_tree_t z_descend;		/* descendent permissions */
188ecd6cf8marks} zfs_allow_node_t;
190ecd6cf8markstypedef struct zfs_allow {
191ecd6cf8marks	struct zfs_allow *z_next;
192ecd6cf8marks	char z_setpoint[MAXPATHLEN];
193ecd6cf8marks	avl_tree_t z_sets;
194ecd6cf8marks	avl_tree_t z_crperms;
195ecd6cf8marks	avl_tree_t z_user;
196ecd6cf8marks	avl_tree_t z_group;
197ecd6cf8marks	avl_tree_t z_everyone;
198ecd6cf8marks} zfs_allow_t;
201fa9e406ahrens * Basic handle types
202fa9e406ahrens */
203fa9e406ahrenstypedef struct zfs_handle zfs_handle_t;
204fa9e406ahrenstypedef struct zpool_handle zpool_handle_t;
20599653d4eschrocktypedef struct libzfs_handle libzfs_handle_t;
20899653d4eschrock * Library initialization
20999653d4eschrock */
21099653d4eschrockextern libzfs_handle_t *libzfs_init(void);
21199653d4eschrockextern void libzfs_fini(libzfs_handle_t *);
21399653d4eschrockextern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
21499653d4eschrockextern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
21699653d4eschrockextern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
2184445fffMatthew Ahrensextern void zfs_save_arguments(int argc, char **, char *, int);
2194445fffMatthew Ahrensextern int zpool_log_history(libzfs_handle_t *, const char *);
2204445fffMatthew Ahrens
22199653d4eschrockextern int libzfs_errno(libzfs_handle_t *);
22299653d4eschrockextern const char *libzfs_error_action(libzfs_handle_t *);
22399653d4eschrockextern const char *libzfs_error_description(libzfs_handle_t *);
22478f1710Matthew Ahrensextern int zfs_standard_error(libzfs_handle_t *, int, const char *);
225ebedde8Eric Taylorextern void libzfs_mnttab_init(libzfs_handle_t *);
226ebedde8Eric Taylorextern void libzfs_mnttab_fini(libzfs_handle_t *);
227b2634b9Eric Taylorextern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t);
228ebedde8Eric Taylorextern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
229ebedde8Eric Taylor    struct mnttab *);
230ebedde8Eric Taylorextern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
231ebedde8Eric Taylor    const char *, const char *);
232ebedde8Eric Taylorextern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
235fa9e406ahrens * Basic handle functions
236fa9e406ahrens */
23799653d4eschrockextern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
23899653d4eschrockextern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
239fa9e406ahrensextern void zpool_close(zpool_handle_t *);
240fa9e406ahrensextern const char *zpool_get_name(zpool_handle_t *);
241fa9e406ahrensextern int zpool_get_state(zpool_handle_t *);
2426401734Will Andrewsextern const char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
2436401734Will Andrewsextern const char *zpool_pool_state_to_name(pool_state_t);
24429ab75crmextern void zpool_free_handles(libzfs_handle_t *);
247fa9e406ahrens * Iterate over all active pools in the system.
248fa9e406ahrens */
249fa9e406ahrenstypedef int (*zpool_iter_f)(zpool_handle_t *, void *);
25099653d4eschrockextern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
2518808ac5Yuri Pankovextern boolean_t zpool_skip_pool(const char *);
254fa9e406ahrens * Functions to create and destroy pools
255fa9e406ahrens */
25699653d4eschrockextern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
2570a48a24timh    nvlist_t *, nvlist_t *);
2584445fffMatthew Ahrensextern int zpool_destroy(zpool_handle_t *, const char *);
259fa9e406ahrensextern int zpool_add(zpool_handle_t *, nvlist_t *);
2611195e68Mark J Musantetypedef struct splitflags {
2621195e68Mark J Musante	/* do not split, but return the config that would be split off */
2631195e68Mark J Musante	int dryrun : 1;
2641195e68Mark J Musante
2651195e68Mark J Musante	/* after splitting, import the pool */
2661195e68Mark J Musante	int import : 1;
267663207aDon Brady	int name_flags;
2681195e68Mark J Musante} splitflags_t;
2691195e68Mark J Musante
270084fd14Brian Behlendorftypedef struct trimflags {
271084fd14Brian Behlendorf	/* requested vdevs are for the entire pool */
272084fd14Brian Behlendorf	boolean_t fullpool;
273084fd14Brian Behlendorf
274084fd14Brian Behlendorf	/* request a secure trim, requires support from device */
275084fd14Brian Behlendorf	boolean_t secure;
276084fd14Brian Behlendorf
277084fd14Brian Behlendorf	/* trim at the requested rate in bytes/second */
278084fd14Brian Behlendorf	uint64_t rate;
279084fd14Brian Behlendorf} trimflags_t;
280084fd14Brian Behlendorf
282fa9e406ahrens * Functions to manipulate pool and vdev state
283fa9e406ahrens */
2841702cceAlek Pinchukextern int zpool_scan(zpool_handle_t *, pool_scan_func_t, pool_scrub_cmd_t);
285094e47eGeorge Wilsonextern int zpool_initialize(zpool_handle_t *, pool_initialize_func_t,
286094e47eGeorge Wilson    nvlist_t *);
287084fd14Brian Behlendorfextern int zpool_trim(zpool_handle_t *, pool_trim_func_t, nvlist_t *,
288084fd14Brian Behlendorf    trimflags_t *);
289084fd14Brian Behlendorf
290468c413Tim Haleyextern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *);
291e9103aaGarrett D'Amoreextern int zpool_reguid(zpool_handle_t *);
2924263d13George Wilsonextern int zpool_reopen(zpool_handle_t *);
2949c2acf0Alek Pinchukextern int zpool_sync_one(zpool_handle_t *, void *);
2959c2acf0Alek Pinchuk
2963d7072feschrockextern int zpool_vdev_online(zpool_handle_t *, const char *, int,
2973d7072feschrock    vdev_state_t *);
2983d7072feschrockextern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
2993d7072feschrockextern int zpool_vdev_attach(zpool_handle_t *, const char *,
3003d7072feschrock    const char *, nvlist_t *, int);
301fa9e406ahrensextern int zpool_vdev_detach(zpool_handle_t *, const char *);
30299653d4eschrockextern int zpool_vdev_remove(zpool_handle_t *, const char *);
3035cabbc6Prashanth Sreenivasaextern int zpool_vdev_remove_cancel(zpool_handle_t *);
3045cabbc6Prashanth Sreenivasaextern int zpool_vdev_indirect_size(zpool_handle_t *, const char *, uint64_t *);
3051195e68Mark J Musanteextern int zpool_vdev_split(zpool_handle_t *, char *, nvlist_t **, nvlist_t *,
3061195e68Mark J Musante    splitflags_t);
308069f55eEric Schrockextern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t);
309069f55eEric Schrockextern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t);
3103d7072feschrockextern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
312fa94a07brendanextern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *,
313ee0eb9fEric Schrock    boolean_t *, boolean_t *);
314573ca77George Wilsonextern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *,
315573ca77George Wilson    boolean_t *, boolean_t *, boolean_t *);
3167855d95Toomas Soomeextern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, const char *,
3177855d95Toomas Soome    zpool_boot_label_t, uint64_t, int *);
320b1b8ab3lling * Functions to manage pool properties
321b1b8ab3lling */
322b1b8ab3llingextern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
3233d7072feschrockextern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
324c58b352Adam Stevko    size_t proplen, zprop_source_t *, boolean_t);
325990b485llingextern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t,
326990b485lling    zprop_source_t *);
328b1b8ab3llingextern const char *zpool_prop_to_name(zpool_prop_t);
329b1b8ab3llingextern const char *zpool_prop_values(zpool_prop_t);
332fa9e406ahrens * Pool health statistics.
333fa9e406ahrens */
334fa9e406ahrenstypedef enum {
335fa9e406ahrens	/*
336fa9e406ahrens	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
337b81d61alling	 * event namespace.  Each is associated with a corresponding message ID.
338e0f1c0aOlaf Faaland	 * This must be kept in sync with the zfs_msgid_table in
339e0f1c0aOlaf Faaland	 * lib/libzfs/libzfs_status.c.
340fa9e406ahrens	 */
341fa9e406ahrens	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
342fa9e406ahrens	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
343fa9e406ahrens	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
344fa9e406ahrens	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
345b81d61alling	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device label with no replicas */
346fa9e406ahrens	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
347fa9e406ahrens	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
348fa9e406ahrens	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
349fa9e406ahrens	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
350eaca9bbeschrock	ZPOOL_STATUS_VERSION_NEWER,	/* newer on-disk version */
3519517395ek	ZPOOL_STATUS_HOSTID_MISMATCH,	/* last accessed by another system */
352e0f1c0aOlaf Faaland	ZPOOL_STATUS_HOSTID_ACTIVE,	/* currently active on another system */
353e0f1c0aOlaf Faaland	ZPOOL_STATUS_HOSTID_REQUIRED,	/* multihost=on and hostid=0 */
35432b8793ek	ZPOOL_STATUS_IO_FAILURE_WAIT,	/* failed I/O, failmode 'wait' */
35532b8793ek	ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */
356e0f1c0aOlaf Faaland	ZPOOL_STATUS_IO_FAILURE_MMP,	/* failed MMP, failmode not 'panic' */
357f67f35cEric Schrock	ZPOOL_STATUS_BAD_LOG,		/* cannot read log chain(s) */
358eb63303Tom Caputi	ZPOOL_STATUS_ERRATA,		/* informational errata available */
359f67f35cEric Schrock
360f67f35cEric Schrock	/*
361ad135b5Christopher Siden	 * If the pool has unsupported features but can still be opened in
362ad135b5Christopher Siden	 * read-only mode, its status is ZPOOL_STATUS_UNSUP_FEAT_WRITE. If the
363ad135b5Christopher Siden	 * pool has unsupported features but cannot be opened at all, its
364ad135b5Christopher Siden	 * status is ZPOOL_STATUS_UNSUP_FEAT_READ.
365ad135b5Christopher Siden	 */
366ad135b5Christopher Siden	ZPOOL_STATUS_UNSUP_FEAT_READ,	/* unsupported features for read */
367ad135b5Christopher Siden	ZPOOL_STATUS_UNSUP_FEAT_WRITE,	/* unsupported features for write */
368ad135b5Christopher Siden
369ad135b5Christopher Siden	/*
370f67f35cEric Schrock	 * These faults have no corresponding message ID.  At the time we are
371f67f35cEric Schrock	 * checking the status, the original reason for the FMA fault (I/O or
372f67f35cEric Schrock	 * checksum errors) has been lost.
373f67f35cEric Schrock	 */
3743d7072feschrock	ZPOOL_STATUS_FAULTED_DEV_R,	/* faulted device with replicas */
3753d7072feschrock	ZPOOL_STATUS_FAULTED_DEV_NR,	/* faulted device with no replicas */
377fa9e406ahrens	/*
378fa9e406ahrens	 * The following are not faults per se, but still an error possibly
379b81d61alling	 * requiring administrative attention.  There is no corresponding
380fa9e406ahrens	 * message ID.
381fa9e406ahrens	 */
3825722177Christopher Siden	ZPOOL_STATUS_VERSION_OLDER,	/* older legacy on-disk version */
3835722177Christopher Siden	ZPOOL_STATUS_FEAT_DISABLED,	/* supported features are disabled */
384fa9e406ahrens	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
385cb605c4Gerhard Roethlin	ZPOOL_STATUS_OFFLINE_DEV,	/* device offline */
386c25309dGeorge Wilson	ZPOOL_STATUS_REMOVED_DEV,	/* removed device */
388fa9e406ahrens	/*
389fa9e406ahrens	 * Finally, the following indicates a healthy pool.
390fa9e406ahrens	 */
391fa9e406ahrens	ZPOOL_STATUS_OK
392fa9e406ahrens} zpool_status_t;
394eb63303Tom Caputiextern zpool_status_t zpool_get_status(zpool_handle_t *, char **,
395eb63303Tom Caputi    zpool_errata_t *);
396eb63303Tom Caputiextern zpool_status_t zpool_import_status(nvlist_t *, char **,
397eb63303Tom Caputi    zpool_errata_t *);
3989eb19f4George Wilsonextern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh);
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 *);
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);
421fa9e406ahrens * Search for pools to import
422fa9e406ahrens */
423d41c437Mark J Musante
424d41c437Mark J Musantetypedef struct importargs {
425d41c437Mark J Musante	char **path;		/* a list of paths to search		*/
426d41c437Mark J Musante	int paths;		/* number of paths to search		*/
427d41c437Mark J Musante	char *poolname;		/* name of a pool to find		*/
428d41c437Mark J Musante	uint64_t guid;		/* guid of a pool to find		*/
429d41c437Mark J Musante	char *cachefile;	/* cachefile to use for import		*/
430d41c437Mark J Musante	int can_be_active : 1;	/* can the pool be active?		*/
431d41c437Mark J Musante	int unique : 1;		/* does 'poolname' already exist?	*/
432d41c437Mark J Musante	int exists : 1;		/* set on return if pool already exists	*/
4335dafeeaPavel Zakharov	nvlist_t *policy;	/* load policy (max txg, rewind, etc.)	*/
434d41c437Mark J Musante} importargs_t;
435d41c437Mark J Musante
436d41c437Mark J Musanteextern nvlist_t *zpool_search_import(libzfs_handle_t *, importargs_t *);
437e0f1c0aOlaf Faalandextern int zpool_tryimport(libzfs_handle_t *hdl, char *target,
438e0f1c0aOlaf Faaland    nvlist_t **configp, importargs_t *args);
439d41c437Mark J Musante
440d41c437Mark J Musante/* legacy pool search routines */
44124e697dckextern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
4423a57275ckextern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *,
443e829d91ck    char *, uint64_t);
446c67d967eschrock * Miscellaneous pool functions
447c67d967eschrock */
448ecd6cf8marksstruct zfs_cmd;
4504445fffMatthew Ahrensextern const char *zfs_history_event_names[];
4518f18d1fGeorge Wilson
452663207aDon Bradytypedef enum {
453663207aDon Brady	VDEV_NAME_PATH		= 1 << 0,
454663207aDon Brady	VDEV_NAME_GUID		= 1 << 1,
455663207aDon Brady	VDEV_NAME_FOLLOW_LINKS	= 1 << 2,
456663207aDon Brady	VDEV_NAME_TYPE_ID	= 1 << 3,
457663207aDon Brady} vdev_name_t;
458663207aDon Brady
45988ecc94George Wilsonextern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *,
460663207aDon Brady    int name_flags);
461990b485llingextern int zpool_upgrade(zpool_handle_t *, uint64_t);
46206eeb2aekextern int zpool_get_history(zpool_handle_t *, nvlist_t **);
4638f18d1fGeorge Wilsonextern int zpool_history_unpack(char *, uint64_t, uint64_t *,
4648f18d1fGeorge Wilson    nvlist_t ***, uint_t *);
46555434c7ekextern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
46655434c7ek    size_t len);
467ecd6cf8marksextern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *);
468753a6d4Sherry Mooreextern int zpool_get_physpath(zpool_handle_t *, char *, size_t);
469468c413Tim Haleyextern void zpool_explain_recover(libzfs_handle_t *, const char *, int,
470468c413Tim Haley    nvlist_t *);
4718671400Serapheim Dimitropoulosextern int zpool_checkpoint(zpool_handle_t *);
4728671400Serapheim Dimitropoulosextern int zpool_discard_checkpoint(zpool_handle_t *);
473753a6d4Sherry Moore
475fa9e406ahrens * Basic handle manipulations.  These functions do not create or destroy the
476fa9e406ahrens * underlying datasets, only the references to them.
477fa9e406ahrens */
47899653d4eschrockextern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
47919b94dfMatthew Ahrensextern zfs_handle_t *zfs_handle_dup(zfs_handle_t *);
480fa9e406ahrensextern void zfs_close(zfs_handle_t *);
481fa9e406ahrensextern zfs_type_t zfs_get_type(const zfs_handle_t *);
482fa9e406ahrensextern const char *zfs_get_name(const zfs_handle_t *);
483d5b5bb2Rich Morrisextern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
4848808ac5Yuri Pankovextern const char *zfs_get_pool_name(const zfs_handle_t *);
487fa9e406ahrens * Property management functions.  Some functions are shared with the kernel,
488b81d61alling * and are found in sys/fs/zfs.h.
489fa9e406ahrens */
492990b485lling * zfs dataset property management
493990b485lling */
494990b485llingextern const char *zfs_prop_default_string(zfs_prop_t);
495990b485llingextern uint64_t zfs_prop_default_numeric(zfs_prop_t);
496990b485llingextern const char *zfs_prop_column_name(zfs_prop_t);
497990b485llingextern boolean_t zfs_prop_align_right(zfs_prop_t);
499eb63303Tom Caputiextern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t, nvlist_t *,
500eb63303Tom Caputi    uint64_t, zfs_handle_t *, zpool_handle_t *, boolean_t, const char *);
502e9dbad6eschrockextern const char *zfs_prop_to_name(zfs_prop_t);
503e9dbad6eschrockextern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
5043092556Chris Williamsonextern int zfs_prop_set_list(zfs_handle_t *, nvlist_t *);
505e9dbad6eschrockextern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
506990b485lling    zprop_source_t *, char *, size_t, boolean_t);
50792241e0Tom Ericksonextern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t,
50892241e0Tom Erickson    boolean_t);
509e9dbad6eschrockextern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
510990b485lling    zprop_source_t *, char *, size_t);
511edea4b5Lin Lingextern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname,
512edea4b5Lin Ling    uint64_t *propvalue);
5131484342Matthew Ahrensextern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname,
5141484342Matthew Ahrens    char *propbuf, int proplen, boolean_t literal);
51519b94dfMatthew Ahrensextern int zfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname,
51619b94dfMatthew Ahrens    uint64_t *propvalue);
51719b94dfMatthew Ahrensextern int zfs_prop_get_written(zfs_handle_t *zhp, const char *propname,
51819b94dfMatthew Ahrens    char *propbuf, int proplen, boolean_t literal);
519ad135b5Christopher Sidenextern int zfs_prop_get_feature(zfs_handle_t *zhp, const char *propname,
520ad135b5Christopher Siden    char *buf, size_t len);
521e9dbad6eschrockextern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
52292241e0Tom Ericksonextern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t);
523e9dbad6eschrockextern const char *zfs_prop_values(zfs_prop_t);
524e9dbad6eschrockextern int zfs_prop_is_string(zfs_prop_t prop);
525990b485llingextern nvlist_t *zfs_get_user_props(zfs_handle_t *);
52692241e0Tom Ericksonextern nvlist_t *zfs_get_recvd_props(zfs_handle_t *);
52719b94dfMatthew Ahrensextern nvlist_t *zfs_get_clones_nvl(zfs_handle_t *);
52819b94dfMatthew Ahrens
530eb63303Tom Caputi/*
531eb63303Tom Caputi * zfs encryption management
532eb63303Tom Caputi */
533eb63303Tom Caputiextern int zfs_crypto_get_encryption_root(zfs_handle_t *, boolean_t *, char *);
534eb63303Tom Caputiextern int zfs_crypto_create(libzfs_handle_t *, char *, nvlist_t *, nvlist_t *,
5356ccda74loli    boolean_t stdin_available, uint8_t **, uint_t *);
536eb63303Tom Caputiextern int zfs_crypto_clone_check(libzfs_handle_t *, zfs_handle_t *, char *,
537eb63303Tom Caputi    nvlist_t *);
538eb63303Tom Caputiextern int zfs_crypto_attempt_load_keys(libzfs_handle_t *, char *);
539eb63303Tom Caputiextern int zfs_crypto_load_key(zfs_handle_t *, boolean_t, char *);
540eb63303Tom Caputiextern int zfs_crypto_unload_key(zfs_handle_t *);
541eb63303Tom Caputiextern int zfs_crypto_rewrap(zfs_handle_t *, nvlist_t *, boolean_t);
542eb63303Tom Caputi
543990b485llingtypedef struct zprop_list {
544990b485lling	int		pl_prop;
545e9dbad6eschrock	char		*pl_user_prop;
546990b485lling	struct zprop_list *pl_next;
547e9dbad6eschrock	boolean_t	pl_all;
548e9dbad6eschrock	size_t		pl_width;
54992241e0Tom Erickson	size_t		pl_recvd_width;
550e9dbad6eschrock	boolean_t	pl_fixed;
551990b485lling} zprop_list_t;
55343d68d6Yuri Pankovextern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t,
55443d68d6Yuri Pankov    boolean_t);
5552e5e9e1Sanjeev Bagewadiextern void zfs_prune_proplist(zfs_handle_t *, uint8_t *);
557fa9e406ahrens#define	ZFS_MOUNTPOINT_NONE	"none"
558fa9e406ahrens#define	ZFS_MOUNTPOINT_LEGACY	"legacy"
560ad135b5Christopher Siden#define	ZFS_FEATURE_DISABLED	"disabled"
561ad135b5Christopher Siden#define	ZFS_FEATURE_ENABLED	"enabled"
562ad135b5Christopher Siden#define	ZFS_FEATURE_ACTIVE	"active"
563ad135b5Christopher Siden
564ad135b5Christopher Siden#define	ZFS_UNSUPPORTED_INACTIVE	"inactive"
565ad135b5Christopher Siden#define	ZFS_UNSUPPORTED_READONLY	"readonly"
566ad135b5Christopher Siden
568990b485lling * zpool property management
569990b485lling */
570990b485llingextern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **);
571ad135b5Christopher Sidenextern int zpool_prop_get_feature(zpool_handle_t *, const char *, char *,
572ad135b5Christopher Siden    size_t);
573990b485llingextern const char *zpool_prop_default_string(zpool_prop_t);
574990b485llingextern uint64_t zpool_prop_default_numeric(zpool_prop_t);
575990b485llingextern const char *zpool_prop_column_name(zpool_prop_t);
576990b485llingextern boolean_t zpool_prop_align_right(zpool_prop_t);
579990b485lling * Functions shared by zfs and zpool property management.
580b1b8ab3lling */
581990b485llingextern int zprop_iter(zprop_func func, void *cb, boolean_t show_all,
582990b485lling    boolean_t ordered, zfs_type_t type);
583990b485llingextern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **,
584990b485lling    zfs_type_t);
585990b485llingextern void zprop_free_list(zprop_list_t *);
58792241e0Tom Erickson#define	ZFS_GET_NCOLS	5
58892241e0Tom Erickson
58992241e0Tom Ericksontypedef enum {
59092241e0Tom Erickson	GET_COL_NONE,
59192241e0Tom Erickson	GET_COL_NAME,
59292241e0Tom Erickson	GET_COL_PROPERTY,
59392241e0Tom Erickson	GET_COL_VALUE,
59492241e0Tom Erickson	GET_COL_RECVD,
59592241e0Tom Erickson	GET_COL_SOURCE
59692241e0Tom Erickson} zfs_get_column_t;
59792241e0Tom Erickson
599990b485lling * Functions for printing zfs or zpool properties
600990b485lling */
601990b485llingtypedef struct zprop_get_cbdata {
602b1b8ab3lling	int cb_sources;
60392241e0Tom Erickson	zfs_get_column_t cb_columns[ZFS_GET_NCOLS];
60492241e0Tom Erickson	int cb_colwidths[ZFS_GET_NCOLS + 1];
605b1b8ab3lling	boolean_t cb_scripted;
606b1b8ab3lling	boolean_t cb_literal;
607b1b8ab3lling	boolean_t cb_first;
608990b485lling	zprop_list_t *cb_proplist;
609990b485lling	zfs_type_t cb_type;
610990b485lling} zprop_get_cbdata_t;
612990b485llingvoid zprop_print_one_property(const char *, zprop_get_cbdata_t *,
61392241e0Tom Erickson    const char *, const char *, zprop_source_t, const char *,
61492241e0Tom Erickson    const char *);
617fa9e406ahrens * Iterator functions.
618fa9e406ahrens */
619fa9e406ahrenstypedef int (*zfs_iter_f)(zfs_handle_t *, void *);
62099653d4eschrockextern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
621fa9e406ahrensextern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
6223bb79beeschrockextern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
6237f7322feschrockextern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
6240d8fa8fMartin Matuskaextern int zfs_iter_snapshots(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
625ca45db4Chris Kirbyextern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *);
62619b94dfMatthew Ahrensextern int zfs_iter_snapspec(zfs_handle_t *, const char *, zfs_iter_f, void *);
62778f1710Matthew Ahrensextern int zfs_iter_bookmarks(zfs_handle_t *, zfs_iter_f, void *);
6299d9a58eEric Taylortypedef struct get_all_cb {
6309d9a58eEric Taylor	zfs_handle_t	**cb_handles;
6319d9a58eEric Taylor	size_t		cb_alloc;
6329d9a58eEric Taylor	size_t		cb_used;
6339d9a58eEric Taylor} get_all_cb_t;
6349d9a58eEric Taylor
635591e0e1Sebastien Royvoid zfs_foreach_mountpoint(libzfs_handle_t *, zfs_handle_t **, size_t,
636591e0e1Sebastien Roy    zfs_iter_f, void *, boolean_t);
6379d9a58eEric Taylorvoid libzfs_add_handle(get_all_cb_t *, zfs_handle_t *);
6389d9a58eEric Taylor
640fa9e406ahrens * Functions to create and destroy datasets.
641fa9e406ahrens */
64299653d4eschrockextern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
643e9dbad6eschrock    nvlist_t *);
6447f1f55evbextern int zfs_create_ancestors(libzfs_handle_t *, const char *);
645842727cChris Kirbyextern int zfs_destroy(zfs_handle_t *, boolean_t);
646842727cChris Kirbyextern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t);
6473b2aab1Matthew Ahrensextern int zfs_destroy_snaps_nvl(libzfs_handle_t *, nvlist_t *, boolean_t);
648e9dbad6eschrockextern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
649bb0ade0ahrensextern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
6504445fffMatthew Ahrensextern int zfs_snapshot_nvl(libzfs_handle_t *hdl, nvlist_t *snaps,
6514445fffMatthew Ahrens    nvlist_t *props);
652c391e32ahrensextern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
6536a9cb0eEric Schrockextern int zfs_rename(zfs_handle_t *, const char *, boolean_t, boolean_t);
6549e69d7dLori Alt
6559e69d7dLori Alttypedef struct