libzfs.h revision 332550
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2011 Pawel Jakub Dawidek. All rights reserved.
25 * Copyright (c) 2011, 2017 by Delphix. All rights reserved.
26 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
27 * Copyright (c) 2012 Martin Matuska <mm@FreeBSD.org>. All rights reserved.
28 * Copyright (c) 2013 Steven Hartland. All rights reserved.
29 * Copyright (c) 2014 Integros [integros.com]
30 * Copyright 2016 Nexenta Systems, Inc.
31 * Copyright (c) 2017 Datto Inc.
32 */
33
34#ifndef	_LIBZFS_H
35#define	_LIBZFS_H
36
37#include <assert.h>
38#include <libnvpair.h>
39#include <sys/mnttab.h>
40#include <sys/param.h>
41#include <sys/types.h>
42#include <sys/varargs.h>
43#include <sys/fs/zfs.h>
44#include <sys/avl.h>
45#include <sys/zfs_ioctl.h>
46#include <libzfs_core.h>
47
48#ifdef	__cplusplus
49extern "C" {
50#endif
51
52/*
53 * Miscellaneous ZFS constants
54 */
55#define	ZFS_MAXPROPLEN		MAXPATHLEN
56#define	ZPOOL_MAXPROPLEN	MAXPATHLEN
57
58/*
59 * libzfs errors
60 */
61typedef enum zfs_error {
62	EZFS_SUCCESS = 0,	/* no error -- success */
63	EZFS_NOMEM = 2000,	/* out of memory */
64	EZFS_BADPROP,		/* invalid property value */
65	EZFS_PROPREADONLY,	/* cannot set readonly property */
66	EZFS_PROPTYPE,		/* property does not apply to dataset type */
67	EZFS_PROPNONINHERIT,	/* property is not inheritable */
68	EZFS_PROPSPACE,		/* bad quota or reservation */
69	EZFS_BADTYPE,		/* dataset is not of appropriate type */
70	EZFS_BUSY,		/* pool or dataset is busy */
71	EZFS_EXISTS,		/* pool or dataset already exists */
72	EZFS_NOENT,		/* no such pool or dataset */
73	EZFS_BADSTREAM,		/* bad backup stream */
74	EZFS_DSREADONLY,	/* dataset is readonly */
75	EZFS_VOLTOOBIG,		/* volume is too large for 32-bit system */
76	EZFS_INVALIDNAME,	/* invalid dataset name */
77	EZFS_BADRESTORE,	/* unable to restore to destination */
78	EZFS_BADBACKUP,		/* backup failed */
79	EZFS_BADTARGET,		/* bad attach/detach/replace target */
80	EZFS_NODEVICE,		/* no such device in pool */
81	EZFS_BADDEV,		/* invalid device to add */
82	EZFS_NOREPLICAS,	/* no valid replicas */
83	EZFS_RESILVERING,	/* currently resilvering */
84	EZFS_BADVERSION,	/* unsupported version */
85	EZFS_POOLUNAVAIL,	/* pool is currently unavailable */
86	EZFS_DEVOVERFLOW,	/* too many devices in one vdev */
87	EZFS_BADPATH,		/* must be an absolute path */
88	EZFS_CROSSTARGET,	/* rename or clone across pool or dataset */
89	EZFS_ZONED,		/* used improperly in local zone */
90	EZFS_MOUNTFAILED,	/* failed to mount dataset */
91	EZFS_UMOUNTFAILED,	/* failed to unmount dataset */
92	EZFS_UNSHARENFSFAILED,	/* unshare(1M) failed */
93	EZFS_SHARENFSFAILED,	/* share(1M) failed */
94	EZFS_PERM,		/* permission denied */
95	EZFS_NOSPC,		/* out of space */
96	EZFS_FAULT,		/* bad address */
97	EZFS_IO,		/* I/O error */
98	EZFS_INTR,		/* signal received */
99	EZFS_ISSPARE,		/* device is a hot spare */
100	EZFS_INVALCONFIG,	/* invalid vdev configuration */
101	EZFS_RECURSIVE,		/* recursive dependency */
102	EZFS_NOHISTORY,		/* no history object */
103	EZFS_POOLPROPS,		/* couldn't retrieve pool props */
104	EZFS_POOL_NOTSUP,	/* ops not supported for this type of pool */
105	EZFS_POOL_INVALARG,	/* invalid argument for this pool operation */
106	EZFS_NAMETOOLONG,	/* dataset name is too long */
107	EZFS_OPENFAILED,	/* open of device failed */
108	EZFS_NOCAP,		/* couldn't get capacity */
109	EZFS_LABELFAILED,	/* write of label failed */
110	EZFS_BADWHO,		/* invalid permission who */
111	EZFS_BADPERM,		/* invalid permission */
112	EZFS_BADPERMSET,	/* invalid permission set name */
113	EZFS_NODELEGATION,	/* delegated administration is disabled */
114	EZFS_UNSHARESMBFAILED,	/* failed to unshare over smb */
115	EZFS_SHARESMBFAILED,	/* failed to share over smb */
116	EZFS_BADCACHE,		/* bad cache file */
117	EZFS_ISL2CACHE,		/* device is for the level 2 ARC */
118	EZFS_VDEVNOTSUP,	/* unsupported vdev type */
119	EZFS_NOTSUP,		/* ops not supported on this dataset */
120	EZFS_ACTIVE_SPARE,	/* pool has active shared spare devices */
121	EZFS_UNPLAYED_LOGS,	/* log device has unplayed logs */
122	EZFS_REFTAG_RELE,	/* snapshot release: tag not found */
123	EZFS_REFTAG_HOLD,	/* snapshot hold: tag already exists */
124	EZFS_TAGTOOLONG,	/* snapshot hold/rele: tag too long */
125	EZFS_PIPEFAILED,	/* pipe create failed */
126	EZFS_THREADCREATEFAILED, /* thread create failed */
127	EZFS_POSTSPLIT_ONLINE,	/* onlining a disk after splitting it */
128	EZFS_SCRUBBING,		/* currently scrubbing */
129	EZFS_NO_SCRUB,		/* no active scrub */
130	EZFS_DIFF,		/* general failure of zfs diff */
131	EZFS_DIFFDATA,		/* bad zfs diff data */
132	EZFS_POOLREADONLY,	/* pool is in read-only mode */
133	EZFS_SCRUB_PAUSED,	/* scrub currently paused */
134	EZFS_NO_PENDING,	/* cannot cancel, no operation is pending */
135	EZFS_CHECKPOINT_EXISTS,	/* checkpoint exists */
136	EZFS_DISCARDING_CHECKPOINT,	/* currently discarding a checkpoint */
137	EZFS_NO_CHECKPOINT,	/* pool has no checkpoint */
138	EZFS_DEVRM_IN_PROGRESS,	/* a device is currently being removed */
139	EZFS_VDEV_TOO_BIG,	/* a device is too big to be used */
140	EZFS_UNKNOWN
141} zfs_error_t;
142
143/*
144 * UEFI boot support parameters. When creating whole disk boot pool,
145 * zpool create should allow to create EFI System partition for UEFI boot
146 * program. In case of BIOS, the EFI System partition is not used
147 * even if it does exist.
148 */
149typedef enum zpool_boot_label {
150	ZPOOL_NO_BOOT_LABEL = 0,
151	ZPOOL_CREATE_BOOT_LABEL,
152	ZPOOL_COPY_BOOT_LABEL
153} zpool_boot_label_t;
154
155/*
156 * The following data structures are all part
157 * of the zfs_allow_t data structure which is
158 * used for printing 'allow' permissions.
159 * It is a linked list of zfs_allow_t's which
160 * then contain avl tree's for user/group/sets/...
161 * and each one of the entries in those trees have
162 * avl tree's for the permissions they belong to and
163 * whether they are local,descendent or local+descendent
164 * permissions.  The AVL trees are used primarily for
165 * sorting purposes, but also so that we can quickly find
166 * a given user and or permission.
167 */
168typedef struct zfs_perm_node {
169	avl_node_t z_node;
170	char z_pname[MAXPATHLEN];
171} zfs_perm_node_t;
172
173typedef struct zfs_allow_node {
174	avl_node_t z_node;
175	char z_key[MAXPATHLEN];		/* name, such as joe */
176	avl_tree_t z_localdescend;	/* local+descendent perms */
177	avl_tree_t z_local;		/* local permissions */
178	avl_tree_t z_descend;		/* descendent permissions */
179} zfs_allow_node_t;
180
181typedef struct zfs_allow {
182	struct zfs_allow *z_next;
183	char z_setpoint[MAXPATHLEN];
184	avl_tree_t z_sets;
185	avl_tree_t z_crperms;
186	avl_tree_t z_user;
187	avl_tree_t z_group;
188	avl_tree_t z_everyone;
189} zfs_allow_t;
190
191/*
192 * Basic handle types
193 */
194typedef struct zfs_handle zfs_handle_t;
195typedef struct zpool_handle zpool_handle_t;
196typedef struct libzfs_handle libzfs_handle_t;
197
198/*
199 * Library initialization
200 */
201extern libzfs_handle_t *libzfs_init(void);
202extern void libzfs_fini(libzfs_handle_t *);
203
204extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *);
205extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *);
206
207extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t);
208
209extern void zfs_save_arguments(int argc, char **, char *, int);
210extern int zpool_log_history(libzfs_handle_t *, const char *);
211
212extern int libzfs_errno(libzfs_handle_t *);
213extern const char *libzfs_error_action(libzfs_handle_t *);
214extern const char *libzfs_error_description(libzfs_handle_t *);
215extern int zfs_standard_error(libzfs_handle_t *, int, const char *);
216extern void libzfs_mnttab_init(libzfs_handle_t *);
217extern void libzfs_mnttab_fini(libzfs_handle_t *);
218extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t);
219extern int libzfs_mnttab_find(libzfs_handle_t *, const char *,
220    struct mnttab *);
221extern void libzfs_mnttab_add(libzfs_handle_t *, const char *,
222    const char *, const char *);
223extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *);
224
225/*
226 * Basic handle functions
227 */
228extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *);
229extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *);
230extern void zpool_close(zpool_handle_t *);
231extern const char *zpool_get_name(zpool_handle_t *);
232extern int zpool_get_state(zpool_handle_t *);
233extern const char *zpool_state_to_name(vdev_state_t, vdev_aux_t);
234extern const char *zpool_pool_state_to_name(pool_state_t);
235extern void zpool_free_handles(libzfs_handle_t *);
236extern int zpool_nextboot(libzfs_handle_t *, uint64_t, uint64_t, const char *);
237
238/*
239 * Iterate over all active pools in the system.
240 */
241typedef int (*zpool_iter_f)(zpool_handle_t *, void *);
242extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *);
243extern boolean_t zpool_skip_pool(const char *);
244
245/*
246 * Functions to create and destroy pools
247 */
248extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *,
249    nvlist_t *, nvlist_t *);
250extern int zpool_destroy(zpool_handle_t *, const char *);
251extern int zpool_add(zpool_handle_t *, nvlist_t *);
252
253typedef struct splitflags {
254	/* do not split, but return the config that would be split off */
255	int dryrun : 1;
256
257	/* after splitting, import the pool */
258	int import : 1;
259} splitflags_t;
260
261/*
262 * Functions to manipulate pool and vdev state
263 */
264extern int zpool_scan(zpool_handle_t *, pool_scan_func_t, pool_scrub_cmd_t);
265extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *);
266extern int zpool_reguid(zpool_handle_t *);
267extern int zpool_reopen(zpool_handle_t *);
268
269extern int zpool_vdev_online(zpool_handle_t *, const char *, int,
270    vdev_state_t *);
271extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t);
272extern int zpool_vdev_attach(zpool_handle_t *, const char *,
273    const char *, nvlist_t *, int);
274extern int zpool_vdev_detach(zpool_handle_t *, const char *);
275extern int zpool_vdev_remove(zpool_handle_t *, const char *);
276extern int zpool_vdev_remove_cancel(zpool_handle_t *);
277extern int zpool_vdev_indirect_size(zpool_handle_t *, const char *, uint64_t *);
278extern int zpool_vdev_split(zpool_handle_t *, char *, nvlist_t **, nvlist_t *,
279    splitflags_t);
280
281extern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t);
282extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t);
283extern int zpool_vdev_clear(zpool_handle_t *, uint64_t);
284
285extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *,
286    boolean_t *, boolean_t *);
287extern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *,
288    boolean_t *, boolean_t *, boolean_t *);
289extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, const char *,
290    zpool_boot_label_t, uint64_t, int *);
291
292/*
293 * Functions to manage pool properties
294 */
295extern int zpool_set_prop(zpool_handle_t *, const char *, const char *);
296extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *,
297    size_t proplen, zprop_source_t *, boolean_t);
298extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t,
299    zprop_source_t *);
300
301extern const char *zpool_prop_to_name(zpool_prop_t);
302extern const char *zpool_prop_values(zpool_prop_t);
303
304/*
305 * Pool health statistics.
306 */
307typedef enum {
308	/*
309	 * The following correspond to faults as defined in the (fault.fs.zfs.*)
310	 * event namespace.  Each is associated with a corresponding message ID.
311	 */
312	ZPOOL_STATUS_CORRUPT_CACHE,	/* corrupt /kernel/drv/zpool.cache */
313	ZPOOL_STATUS_MISSING_DEV_R,	/* missing device with replicas */
314	ZPOOL_STATUS_MISSING_DEV_NR,	/* missing device with no replicas */
315	ZPOOL_STATUS_CORRUPT_LABEL_R,	/* bad device label with replicas */
316	ZPOOL_STATUS_CORRUPT_LABEL_NR,	/* bad device label with no replicas */
317	ZPOOL_STATUS_BAD_GUID_SUM,	/* sum of device guids didn't match */
318	ZPOOL_STATUS_CORRUPT_POOL,	/* pool metadata is corrupted */
319	ZPOOL_STATUS_CORRUPT_DATA,	/* data errors in user (meta)data */
320	ZPOOL_STATUS_FAILING_DEV,	/* device experiencing errors */
321	ZPOOL_STATUS_VERSION_NEWER,	/* newer on-disk version */
322	ZPOOL_STATUS_HOSTID_MISMATCH,	/* last accessed by another system */
323	ZPOOL_STATUS_IO_FAILURE_WAIT,	/* failed I/O, failmode 'wait' */
324	ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */
325	ZPOOL_STATUS_BAD_LOG,		/* cannot read log chain(s) */
326
327	/*
328	 * If the pool has unsupported features but can still be opened in
329	 * read-only mode, its status is ZPOOL_STATUS_UNSUP_FEAT_WRITE. If the
330	 * pool has unsupported features but cannot be opened at all, its
331	 * status is ZPOOL_STATUS_UNSUP_FEAT_READ.
332	 */
333	ZPOOL_STATUS_UNSUP_FEAT_READ,	/* unsupported features for read */
334	ZPOOL_STATUS_UNSUP_FEAT_WRITE,	/* unsupported features for write */
335
336	/*
337	 * These faults have no corresponding message ID.  At the time we are
338	 * checking the status, the original reason for the FMA fault (I/O or
339	 * checksum errors) has been lost.
340	 */
341	ZPOOL_STATUS_FAULTED_DEV_R,	/* faulted device with replicas */
342	ZPOOL_STATUS_FAULTED_DEV_NR,	/* faulted device with no replicas */
343
344	/*
345	 * The following are not faults per se, but still an error possibly
346	 * requiring administrative attention.  There is no corresponding
347	 * message ID.
348	 */
349	ZPOOL_STATUS_VERSION_OLDER,	/* older legacy on-disk version */
350	ZPOOL_STATUS_FEAT_DISABLED,	/* supported features are disabled */
351	ZPOOL_STATUS_RESILVERING,	/* device being resilvered */
352	ZPOOL_STATUS_OFFLINE_DEV,	/* device offline */
353	ZPOOL_STATUS_REMOVED_DEV,	/* removed device */
354	ZPOOL_STATUS_NON_NATIVE_ASHIFT,	/* (e.g. 512e dev with ashift of 9) */
355
356	/*
357	 * Finally, the following indicates a healthy pool.
358	 */
359	ZPOOL_STATUS_OK
360} zpool_status_t;
361
362extern zpool_status_t zpool_get_status(zpool_handle_t *, char **);
363extern zpool_status_t zpool_import_status(nvlist_t *, char **);
364extern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh);
365
366/*
367 * Statistics and configuration functions.
368 */
369extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **);
370extern nvlist_t *zpool_get_features(zpool_handle_t *);
371extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *);
372extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **);
373extern boolean_t zpool_is_bootable(zpool_handle_t *);
374
375/*
376 * Import and export functions
377 */
378extern int zpool_export(zpool_handle_t *, boolean_t, const char *);
379extern int zpool_export_force(zpool_handle_t *, const char *);
380extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *,
381    char *altroot);
382extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
383    nvlist_t *, int);
384extern void zpool_print_unsup_feat(nvlist_t *config);
385
386/*
387 * Search for pools to import
388 */
389
390typedef struct importargs {
391	char **path;		/* a list of paths to search		*/
392	int paths;		/* number of paths to search		*/
393	char *poolname;		/* name of a pool to find		*/
394	uint64_t guid;		/* guid of a pool to find		*/
395	char *cachefile;	/* cachefile to use for import		*/
396	int can_be_active : 1;	/* can the pool be active?		*/
397	int unique : 1;		/* does 'poolname' already exist?	*/
398	int exists : 1;		/* set on return if pool already exists	*/
399	nvlist_t *policy;	/* load policy (max txg, rewind, etc.)	*/
400} importargs_t;
401
402extern nvlist_t *zpool_search_import(libzfs_handle_t *, importargs_t *);
403
404/* legacy pool search routines */
405extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
406extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *,
407    char *, uint64_t);
408
409/*
410 * Miscellaneous pool functions
411 */
412struct zfs_cmd;
413
414extern const char *zfs_history_event_names[];
415
416extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *,
417    boolean_t verbose);
418extern int zpool_upgrade(zpool_handle_t *, uint64_t);
419extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
420extern int zpool_history_unpack(char *, uint64_t, uint64_t *,
421    nvlist_t ***, uint_t *);
422extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *,
423    size_t len);
424extern int zfs_ioctl(libzfs_handle_t *, int request, struct zfs_cmd *);
425extern int zpool_get_physpath(zpool_handle_t *, char *, size_t);
426extern void zpool_explain_recover(libzfs_handle_t *, const char *, int,
427    nvlist_t *);
428extern int zpool_checkpoint(zpool_handle_t *);
429extern int zpool_discard_checkpoint(zpool_handle_t *);
430
431/*
432 * Basic handle manipulations.  These functions do not create or destroy the
433 * underlying datasets, only the references to them.
434 */
435extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int);
436extern zfs_handle_t *zfs_handle_dup(zfs_handle_t *);
437extern void zfs_close(zfs_handle_t *);
438extern zfs_type_t zfs_get_type(const zfs_handle_t *);
439extern const char *zfs_get_name(const zfs_handle_t *);
440extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *);
441extern const char *zfs_get_pool_name(const zfs_handle_t *);
442
443/*
444 * Property management functions.  Some functions are shared with the kernel,
445 * and are found in sys/fs/zfs.h.
446 */
447
448/*
449 * zfs dataset property management
450 */
451extern const char *zfs_prop_default_string(zfs_prop_t);
452extern uint64_t zfs_prop_default_numeric(zfs_prop_t);
453extern const char *zfs_prop_column_name(zfs_prop_t);
454extern boolean_t zfs_prop_align_right(zfs_prop_t);
455
456extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t,
457    nvlist_t *, uint64_t, zfs_handle_t *, zpool_handle_t *, const char *);
458
459extern const char *zfs_prop_to_name(zfs_prop_t);
460extern int zfs_prop_set(zfs_handle_t *, const char *, const char *);
461extern int zfs_prop_set_list(zfs_handle_t *, nvlist_t *);
462extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t,
463    zprop_source_t *, char *, size_t, boolean_t);
464extern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t,
465    boolean_t);
466extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *,
467    zprop_source_t *, char *, size_t);
468extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname,
469    uint64_t *propvalue);
470extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname,
471    char *propbuf, int proplen, boolean_t literal);
472extern int zfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname,
473    uint64_t *propvalue);
474extern int zfs_prop_get_written(zfs_handle_t *zhp, const char *propname,
475    char *propbuf, int proplen, boolean_t literal);
476extern int zfs_prop_get_feature(zfs_handle_t *zhp, const char *propname,
477    char *buf, size_t len);
478extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t);
479extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t);
480extern const char *zfs_prop_values(zfs_prop_t);
481extern int zfs_prop_is_string(zfs_prop_t prop);
482extern nvlist_t *zfs_get_user_props(zfs_handle_t *);
483extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *);
484extern nvlist_t *zfs_get_clones_nvl(zfs_handle_t *);
485
486
487typedef struct zprop_list {
488	int		pl_prop;
489	char		*pl_user_prop;
490	struct zprop_list *pl_next;
491	boolean_t	pl_all;
492	size_t		pl_width;
493	size_t		pl_recvd_width;
494	boolean_t	pl_fixed;
495} zprop_list_t;
496
497extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t,
498    boolean_t);
499extern void zfs_prune_proplist(zfs_handle_t *, uint8_t *);
500
501#define	ZFS_MOUNTPOINT_NONE	"none"
502#define	ZFS_MOUNTPOINT_LEGACY	"legacy"
503
504#define	ZFS_FEATURE_DISABLED	"disabled"
505#define	ZFS_FEATURE_ENABLED	"enabled"
506#define	ZFS_FEATURE_ACTIVE	"active"
507
508#define	ZFS_UNSUPPORTED_INACTIVE	"inactive"
509#define	ZFS_UNSUPPORTED_READONLY	"readonly"
510
511/*
512 * zpool property management
513 */
514extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **);
515extern int zpool_prop_get_feature(zpool_handle_t *, const char *, char *,
516    size_t);
517extern const char *zpool_prop_default_string(zpool_prop_t);
518extern uint64_t zpool_prop_default_numeric(zpool_prop_t);
519extern const char *zpool_prop_column_name(zpool_prop_t);
520extern boolean_t zpool_prop_align_right(zpool_prop_t);
521
522/*
523 * Functions shared by zfs and zpool property management.
524 */
525extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all,
526    boolean_t ordered, zfs_type_t type);
527extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **,
528    zfs_type_t);
529extern void zprop_free_list(zprop_list_t *);
530
531#define	ZFS_GET_NCOLS	5
532
533typedef enum {
534	GET_COL_NONE,
535	GET_COL_NAME,
536	GET_COL_PROPERTY,
537	GET_COL_VALUE,
538	GET_COL_RECVD,
539	GET_COL_SOURCE
540} zfs_get_column_t;
541
542/*
543 * Functions for printing zfs or zpool properties
544 */
545typedef struct zprop_get_cbdata {
546	int cb_sources;
547	zfs_get_column_t cb_columns[ZFS_GET_NCOLS];
548	int cb_colwidths[ZFS_GET_NCOLS + 1];
549	boolean_t cb_scripted;
550	boolean_t cb_literal;
551	boolean_t cb_first;
552	zprop_list_t *cb_proplist;
553	zfs_type_t cb_type;
554} zprop_get_cbdata_t;
555
556void zprop_print_one_property(const char *, zprop_get_cbdata_t *,
557    const char *, const char *, zprop_source_t, const char *,
558    const char *);
559
560/*
561 * Iterator functions.
562 */
563typedef int (*zfs_iter_f)(zfs_handle_t *, void *);
564extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *);
565extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *);
566extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
567extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *);
568extern int zfs_iter_snapshots(zfs_handle_t *, boolean_t, zfs_iter_f, void *);
569extern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *);
570extern int zfs_iter_snapspec(zfs_handle_t *, const char *, zfs_iter_f, void *);
571extern int zfs_iter_bookmarks(zfs_handle_t *, zfs_iter_f, void *);
572
573typedef struct get_all_cb {
574	zfs_handle_t	**cb_handles;
575	size_t		cb_alloc;
576	size_t		cb_used;
577	boolean_t	cb_verbose;
578	int		(*cb_getone)(zfs_handle_t *, void *);
579} get_all_cb_t;
580
581void libzfs_add_handle(get_all_cb_t *, zfs_handle_t *);
582int libzfs_dataset_cmp(const void *, const void *);
583
584/*
585 * Functions to create and destroy datasets.
586 */
587extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t,
588    nvlist_t *);
589extern int zfs_create_ancestors(libzfs_handle_t *, const char *);
590extern int zfs_destroy(zfs_handle_t *, boolean_t);
591extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t);
592extern int zfs_destroy_snaps_nvl(libzfs_handle_t *, nvlist_t *, boolean_t);
593extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *);
594extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *);
595extern int zfs_snapshot_nvl(libzfs_handle_t *hdl, nvlist_t *snaps,
596    nvlist_t *props);
597extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t);
598
599typedef struct renameflags {
600	/* recursive rename */
601	int recurse : 1;
602
603	/* don't unmount file systems */
604	int nounmount : 1;
605
606	/* force unmount file systems */
607	int forceunmount : 1;
608} renameflags_t;
609
610extern int zfs_rename(zfs_handle_t *, const char *, const char *,
611    renameflags_t flags);
612
613typedef struct sendflags {
614	/* print informational messages (ie, -v was specified) */
615	boolean_t verbose;
616
617	/* recursive send  (ie, -R) */
618	boolean_t replicate;
619
620	/* for incrementals, do all intermediate snapshots */
621	boolean_t doall;
622
623	/* if dataset is a clone, do incremental from its origin */
624	boolean_t fromorigin;
625
626	/* do deduplication */
627	boolean_t dedup;
628
629	/* send properties (ie, -p) */
630	boolean_t props;
631
632	/* do not send (no-op, ie. -n) */
633	boolean_t dryrun;
634
635	/* parsable verbose output (ie. -P) */
636	boolean_t parsable;
637
638	/* show progress (ie. -v) */
639	boolean_t progress;
640
641	/* large blocks (>128K) are permitted */
642	boolean_t largeblock;
643
644	/* WRITE_EMBEDDED records of type DATA are permitted */
645	boolean_t embed_data;
646
647	/* compressed WRITE records are permitted */
648	boolean_t compress;
649} sendflags_t;
650
651typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *);
652
653extern int zfs_send(zfs_handle_t *, const char *, const char *,
654    sendflags_t *, int, snapfilter_cb_t, void *, nvlist_t **);
655extern int zfs_send_one(zfs_handle_t *, const char *, int, enum lzc_send_flags);
656extern int zfs_send_resume(libzfs_handle_t *, sendflags_t *, int outfd,
657    const char *);
658extern nvlist_t *zfs_send_resume_token_to_nvlist(libzfs_handle_t *hdl,
659    const char *token);
660
661extern int zfs_promote(zfs_handle_t *);
662extern int zfs_hold(zfs_handle_t *, const char *, const char *,
663    boolean_t, int);
664extern int zfs_hold_nvl(zfs_handle_t *, int, nvlist_t *);
665extern int zfs_release(zfs_handle_t *, const char *, const char *, boolean_t);
666extern int zfs_get_holds(zfs_handle_t *, nvlist_t **);
667extern uint64_t zvol_volsize_to_reservation(uint64_t, nvlist_t *);
668
669typedef int (*zfs_userspace_cb_t)(void *arg, const char *domain,
670    uid_t rid, uint64_t space);
671
672extern int zfs_userspace(zfs_handle_t *, zfs_userquota_prop_t,
673    zfs_userspace_cb_t, void *);
674
675extern int zfs_get_fsacl(zfs_handle_t *, nvlist_t **);
676extern int zfs_set_fsacl(zfs_handle_t *, boolean_t, nvlist_t *);
677
678typedef struct recvflags {
679	/* print informational messages (ie, -v was specified) */
680	boolean_t verbose;
681
682	/* the destination is a prefix, not the exact fs (ie, -d) */
683	boolean_t isprefix;
684
685	/*
686	 * Only the tail of the sent snapshot path is appended to the
687	 * destination to determine the received snapshot name (ie, -e).
688	 */
689	boolean_t istail;
690
691	/* do not actually do the recv, just check if it would work (ie, -n) */
692	boolean_t dryrun;
693
694	/* rollback/destroy filesystems as necessary (eg, -F) */
695	boolean_t force;
696
697	/* set "canmount=off" on all modified filesystems */
698	boolean_t canmountoff;
699
700	/*
701	 * Mark the file systems as "resumable" and do not destroy them if the
702	 * receive is interrupted
703	 */
704	boolean_t resumable;
705
706	/* byteswap flag is used internally; callers need not specify */
707	boolean_t byteswap;
708
709	/* do not mount file systems as they are extracted (private) */
710	boolean_t nomount;
711} recvflags_t;
712
713extern int zfs_receive(libzfs_handle_t *, const char *, nvlist_t *,
714    recvflags_t *, int, avl_tree_t *);
715
716typedef enum diff_flags {
717	ZFS_DIFF_PARSEABLE = 0x1,
718	ZFS_DIFF_TIMESTAMP = 0x2,
719	ZFS_DIFF_CLASSIFY = 0x4
720} diff_flags_t;
721
722extern int zfs_show_diffs(zfs_handle_t *, int, const char *, const char *,
723    int);
724
725/*
726 * Miscellaneous functions.
727 */
728extern const char *zfs_type_to_name(zfs_type_t);
729extern void zfs_refresh_properties(zfs_handle_t *);
730extern int zfs_name_valid(const char *, zfs_type_t);
731extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t);
732extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *,
733    zfs_type_t);
734extern int zfs_spa_version(zfs_handle_t *, int *);
735extern boolean_t zfs_bookmark_exists(const char *path);
736
737/*
738 * Mount support functions.
739 */
740extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **);
741extern boolean_t zfs_is_mounted(zfs_handle_t *, char **);
742extern int zfs_mount(zfs_handle_t *, const char *, int);
743extern int zfs_unmount(zfs_handle_t *, const char *, int);
744extern int zfs_unmountall(zfs_handle_t *, int);
745
746/*
747 * Share support functions.
748 */
749extern boolean_t zfs_is_shared(zfs_handle_t *);
750extern int zfs_share(zfs_handle_t *);
751extern int zfs_unshare(zfs_handle_t *);
752
753/*
754 * Protocol-specific share support functions.
755 */
756extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **);
757extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **);
758extern int zfs_share_nfs(zfs_handle_t *);
759extern int zfs_share_smb(zfs_handle_t *);
760extern int zfs_shareall(zfs_handle_t *);
761extern int zfs_unshare_nfs(zfs_handle_t *, const char *);
762extern int zfs_unshare_smb(zfs_handle_t *, const char *);
763extern int zfs_unshareall_nfs(zfs_handle_t *);
764extern int zfs_unshareall_smb(zfs_handle_t *);
765extern int zfs_unshareall_bypath(zfs_handle_t *, const char *);
766extern int zfs_unshareall(zfs_handle_t *);
767extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *,
768    void *, void *, int, zfs_share_op_t);
769
770/*
771 * FreeBSD-specific jail support function.
772 */
773extern int zfs_jail(zfs_handle_t *, int, int);
774
775/*
776 * When dealing with nvlists, verify() is extremely useful
777 */
778#ifndef verify
779#ifdef NDEBUG
780#define	verify(EX)	((void)(EX))
781#else
782#define	verify(EX)	assert(EX)
783#endif
784#endif
785
786/*
787 * Utility function to convert a number to a human-readable form.
788 */
789extern void zfs_nicenum(uint64_t, char *, size_t);
790extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
791
792/*
793 * Given a device or file, determine if it is part of a pool.
794 */
795extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **,
796    boolean_t *);
797
798/*
799 * Label manipulation.
800 */
801extern int zpool_read_label(int, nvlist_t **);
802extern int zpool_read_all_labels(int, nvlist_t **);
803extern int zpool_clear_label(int);
804
805/* is this zvol valid for use as a dump device? */
806extern int zvol_check_dump_config(char *);
807
808/*
809 * Management interfaces for SMB ACL files
810 */
811
812int zfs_smb_acl_add(libzfs_handle_t *, char *, char *, char *);
813int zfs_smb_acl_remove(libzfs_handle_t *, char *, char *, char *);
814int zfs_smb_acl_purge(libzfs_handle_t *, char *, char *);
815int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *);
816
817/*
818 * Enable and disable datasets within a pool by mounting/unmounting and
819 * sharing/unsharing them.
820 */
821extern int zpool_enable_datasets(zpool_handle_t *, const char *, int);
822extern int zpool_disable_datasets(zpool_handle_t *, boolean_t);
823
824/*
825 * Mappings between vdev and FRU.
826 */
827extern void libzfs_fru_refresh(libzfs_handle_t *);
828extern const char *libzfs_fru_lookup(libzfs_handle_t *, const char *);
829extern const char *libzfs_fru_devpath(libzfs_handle_t *, const char *);
830extern boolean_t libzfs_fru_compare(libzfs_handle_t *, const char *,
831    const char *);
832extern boolean_t libzfs_fru_notself(libzfs_handle_t *, const char *);
833extern int zpool_fru_set(zpool_handle_t *, uint64_t, const char *);
834
835#ifndef illumos
836extern int zmount(const char *, const char *, int, char *, char *, int, char *,
837    int);
838#endif
839extern int zfs_remap_indirects(libzfs_handle_t *hdl, const char *);
840
841#ifdef	__cplusplus
842}
843#endif
844
845#endif	/* _LIBZFS_H */
846