1fa9e4066Sahrens /* 2fa9e4066Sahrens * CDDL HEADER START 3fa9e4066Sahrens * 4fa9e4066Sahrens * The contents of this file are subject to the terms of the 5441d80aaSlling * Common Development and Distribution License (the "License"). 6441d80aaSlling * You may not use this file except in compliance with the License. 7fa9e4066Sahrens * 8fa9e4066Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fa9e4066Sahrens * or http://www.opensolaris.org/os/licensing. 10fa9e4066Sahrens * See the License for the specific language governing permissions 11fa9e4066Sahrens * and limitations under the License. 12fa9e4066Sahrens * 13fa9e4066Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14fa9e4066Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fa9e4066Sahrens * If applicable, add the following below this CDDL HEADER, with the 16fa9e4066Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17fa9e4066Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18fa9e4066Sahrens * 19fa9e4066Sahrens * CDDL HEADER END 20fa9e4066Sahrens */ 21f3861e1aSahl 22fa9e4066Sahrens /* 233f9d6ad7SLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 240d8fa8f8SMartin Matuska * Copyright (c) 2011 Pawel Jakub Dawidek. All rights reserved. 255cabbc6bSPrashanth Sreenivasa * Copyright (c) 2011, 2017 by Delphix. All rights reserved. 264e3c9f44SBill Pijewski * Copyright (c) 2012, Joyent, Inc. All rights reserved. 27a7a845e4SSteven Hartland * Copyright (c) 2013 Steven Hartland. All rights reserved. 28c3d26abcSMatthew Ahrens * Copyright (c) 2014 Integros [integros.com] 298808ac5dSYuri Pankov * Copyright 2016 Nexenta Systems, Inc. 301702cce7SAlek Pinchuk * Copyright (c) 2017 Datto Inc. 31fa9e4066Sahrens */ 32fa9e4066Sahrens 33fa9e4066Sahrens #ifndef _LIBZFS_H 34fa9e4066Sahrens #define _LIBZFS_H 35fa9e4066Sahrens 36fa9e4066Sahrens #include <assert.h> 37fa9e4066Sahrens #include <libnvpair.h> 38ebedde84SEric Taylor #include <sys/mnttab.h> 39fa9e4066Sahrens #include <sys/param.h> 40fa9e4066Sahrens #include <sys/types.h> 41fa9e4066Sahrens #include <sys/varargs.h> 42fa9e4066Sahrens #include <sys/fs/zfs.h> 43ecd6cf80Smarks #include <sys/avl.h> 44ecd6cf80Smarks #include <ucred.h> 455d7b4d43SMatthew Ahrens #include <libzfs_core.h> 46fa9e4066Sahrens 47fa9e4066Sahrens #ifdef __cplusplus 48fa9e4066Sahrens extern "C" { 49fa9e4066Sahrens #endif 50fa9e4066Sahrens 51fa9e4066Sahrens /* 52fa9e4066Sahrens * Miscellaneous ZFS constants 53fa9e4066Sahrens */ 54fa9e4066Sahrens #define ZFS_MAXPROPLEN MAXPATHLEN 55990b4856Slling #define ZPOOL_MAXPROPLEN MAXPATHLEN 56fa9e4066Sahrens 57fa9e4066Sahrens /* 5899653d4eSeschrock * libzfs errors 5999653d4eSeschrock */ 604445fffbSMatthew Ahrens typedef enum zfs_error { 614445fffbSMatthew Ahrens EZFS_SUCCESS = 0, /* no error -- success */ 6299653d4eSeschrock EZFS_NOMEM = 2000, /* out of memory */ 6399653d4eSeschrock EZFS_BADPROP, /* invalid property value */ 6499653d4eSeschrock EZFS_PROPREADONLY, /* cannot set readonly property */ 6599653d4eSeschrock EZFS_PROPTYPE, /* property does not apply to dataset type */ 6699653d4eSeschrock EZFS_PROPNONINHERIT, /* property is not inheritable */ 6799653d4eSeschrock EZFS_PROPSPACE, /* bad quota or reservation */ 6899653d4eSeschrock EZFS_BADTYPE, /* dataset is not of appropriate type */ 6999653d4eSeschrock EZFS_BUSY, /* pool or dataset is busy */ 7099653d4eSeschrock EZFS_EXISTS, /* pool or dataset already exists */ 7199653d4eSeschrock EZFS_NOENT, /* no such pool or dataset */ 7299653d4eSeschrock EZFS_BADSTREAM, /* bad backup stream */ 7399653d4eSeschrock EZFS_DSREADONLY, /* dataset is readonly */ 7499653d4eSeschrock EZFS_VOLTOOBIG, /* volume is too large for 32-bit system */ 7599653d4eSeschrock EZFS_INVALIDNAME, /* invalid dataset name */ 7699653d4eSeschrock EZFS_BADRESTORE, /* unable to restore to destination */ 7799653d4eSeschrock EZFS_BADBACKUP, /* backup failed */ 7899653d4eSeschrock EZFS_BADTARGET, /* bad attach/detach/replace target */ 7999653d4eSeschrock EZFS_NODEVICE, /* no such device in pool */ 8099653d4eSeschrock EZFS_BADDEV, /* invalid device to add */ 8199653d4eSeschrock EZFS_NOREPLICAS, /* no valid replicas */ 8299653d4eSeschrock EZFS_RESILVERING, /* currently resilvering */ 8399653d4eSeschrock EZFS_BADVERSION, /* unsupported version */ 8499653d4eSeschrock EZFS_POOLUNAVAIL, /* pool is currently unavailable */ 8599653d4eSeschrock EZFS_DEVOVERFLOW, /* too many devices in one vdev */ 8699653d4eSeschrock EZFS_BADPATH, /* must be an absolute path */ 8799653d4eSeschrock EZFS_CROSSTARGET, /* rename or clone across pool or dataset */ 8899653d4eSeschrock EZFS_ZONED, /* used improperly in local zone */ 8999653d4eSeschrock EZFS_MOUNTFAILED, /* failed to mount dataset */ 9099653d4eSeschrock EZFS_UMOUNTFAILED, /* failed to unmount dataset */ 91f3861e1aSahl EZFS_UNSHARENFSFAILED, /* unshare(1M) failed */ 92f3861e1aSahl EZFS_SHARENFSFAILED, /* share(1M) failed */ 9399653d4eSeschrock EZFS_PERM, /* permission denied */ 9499653d4eSeschrock EZFS_NOSPC, /* out of space */ 956e27f868SSam Falkner EZFS_FAULT, /* bad address */ 9699653d4eSeschrock EZFS_IO, /* I/O error */ 9799653d4eSeschrock EZFS_INTR, /* signal received */ 9899653d4eSeschrock EZFS_ISSPARE, /* device is a hot spare */ 9999653d4eSeschrock EZFS_INVALCONFIG, /* invalid vdev configuration */ 1003bb79becSeschrock EZFS_RECURSIVE, /* recursive dependency */ 10106eeb2adSek110237 EZFS_NOHISTORY, /* no history object */ 102b1b8ab34Slling EZFS_POOLPROPS, /* couldn't retrieve pool props */ 103b1b8ab34Slling EZFS_POOL_NOTSUP, /* ops not supported for this type of pool */ 104b1b8ab34Slling EZFS_POOL_INVALARG, /* invalid argument for this pool operation */ 105b7661cccSmmusante EZFS_NAMETOOLONG, /* dataset name is too long */ 1068488aeb5Staylor EZFS_OPENFAILED, /* open of device failed */ 1078488aeb5Staylor EZFS_NOCAP, /* couldn't get capacity */ 1088488aeb5Staylor EZFS_LABELFAILED, /* write of label failed */ 109ecd6cf80Smarks EZFS_BADWHO, /* invalid permission who */ 110ecd6cf80Smarks EZFS_BADPERM, /* invalid permission */ 111ecd6cf80Smarks EZFS_BADPERMSET, /* invalid permission set name */ 112ecd6cf80Smarks EZFS_NODELEGATION, /* delegated administration is disabled */ 113da6c28aaSamw EZFS_UNSHARESMBFAILED, /* failed to unshare over smb */ 114da6c28aaSamw EZFS_SHARESMBFAILED, /* failed to share over smb */ 1152f8aaab3Seschrock EZFS_BADCACHE, /* bad cache file */ 116fa94a07fSbrendan EZFS_ISL2CACHE, /* device is for the level 2 ARC */ 117e7cbe64fSgw25295 EZFS_VDEVNOTSUP, /* unsupported vdev type */ 11815e6edf1Sgw25295 EZFS_NOTSUP, /* ops not supported on this dataset */ 11989a89ebfSlling EZFS_ACTIVE_SPARE, /* pool has active shared spare devices */ 120e6ca193dSGeorge Wilson EZFS_UNPLAYED_LOGS, /* log device has unplayed logs */ 121842727c2SChris Kirby EZFS_REFTAG_RELE, /* snapshot release: tag not found */ 122842727c2SChris Kirby EZFS_REFTAG_HOLD, /* snapshot hold: tag already exists */ 123ca45db41SChris Kirby EZFS_TAGTOOLONG, /* snapshot hold/rele: tag too long */ 1249e69d7d0SLori Alt EZFS_PIPEFAILED, /* pipe create failed */ 1259e69d7d0SLori Alt EZFS_THREADCREATEFAILED, /* thread create failed */ 1261195e687SMark J Musante EZFS_POSTSPLIT_ONLINE, /* onlining a disk after splitting it */ 1273f9d6ad7SLin Ling EZFS_SCRUBBING, /* currently scrubbing */ 1283f9d6ad7SLin Ling EZFS_NO_SCRUB, /* no active scrub */ 12999d5e173STim Haley EZFS_DIFF, /* general failure of zfs diff */ 13099d5e173STim Haley EZFS_DIFFDATA, /* bad zfs diff data */ 131f9af39baSGeorge Wilson EZFS_POOLREADONLY, /* pool is in read-only mode */ 1321702cce7SAlek Pinchuk EZFS_SCRUB_PAUSED, /* scrub currently paused */ 1335cabbc6bSPrashanth Sreenivasa EZFS_NO_PENDING, /* cannot cancel, no operation is pending */ 134*86714001SSerapheim Dimitropoulos EZFS_CHECKPOINT_EXISTS, /* checkpoint exists */ 135*86714001SSerapheim Dimitropoulos EZFS_DISCARDING_CHECKPOINT, /* currently discarding a checkpoint */ 136*86714001SSerapheim Dimitropoulos EZFS_NO_CHECKPOINT, /* pool has no checkpoint */ 137*86714001SSerapheim Dimitropoulos EZFS_DEVRM_IN_PROGRESS, /* a device is currently being removed */ 138*86714001SSerapheim Dimitropoulos EZFS_VDEV_TOO_BIG, /* a device is too big to be used */ 139b1b8ab34Slling EZFS_UNKNOWN 1404445fffbSMatthew Ahrens } zfs_error_t; 14199653d4eSeschrock 14299653d4eSeschrock /* 1437855d95bSToomas Soome * UEFI boot support parameters. When creating whole disk boot pool, 1447855d95bSToomas Soome * zpool create should allow to create EFI System partition for UEFI boot 1457855d95bSToomas Soome * program. In case of BIOS, the EFI System partition is not used 1467855d95bSToomas Soome * even if it does exist. 1477855d95bSToomas Soome */ 1487855d95bSToomas Soome typedef enum zpool_boot_label { 1497855d95bSToomas Soome ZPOOL_NO_BOOT_LABEL = 0, 1507855d95bSToomas Soome ZPOOL_CREATE_BOOT_LABEL, 1517855d95bSToomas Soome ZPOOL_COPY_BOOT_LABEL 1527855d95bSToomas Soome } zpool_boot_label_t; 1537855d95bSToomas Soome 1547855d95bSToomas Soome /* 155ecd6cf80Smarks * The following data structures are all part 156ecd6cf80Smarks * of the zfs_allow_t data structure which is 157ecd6cf80Smarks * used for printing 'allow' permissions. 158ecd6cf80Smarks * It is a linked list of zfs_allow_t's which 159ecd6cf80Smarks * then contain avl tree's for user/group/sets/... 160ecd6cf80Smarks * and each one of the entries in those trees have 161ecd6cf80Smarks * avl tree's for the permissions they belong to and 162ecd6cf80Smarks * whether they are local,descendent or local+descendent 163ecd6cf80Smarks * permissions. The AVL trees are used primarily for 164ecd6cf80Smarks * sorting purposes, but also so that we can quickly find 165ecd6cf80Smarks * a given user and or permission. 166ecd6cf80Smarks */ 167ecd6cf80Smarks typedef struct zfs_perm_node { 168ecd6cf80Smarks avl_node_t z_node; 169ecd6cf80Smarks char z_pname[MAXPATHLEN]; 170ecd6cf80Smarks } zfs_perm_node_t; 171ecd6cf80Smarks 172ecd6cf80Smarks typedef struct zfs_allow_node { 173ecd6cf80Smarks avl_node_t z_node; 174ecd6cf80Smarks char z_key[MAXPATHLEN]; /* name, such as joe */ 175ecd6cf80Smarks avl_tree_t z_localdescend; /* local+descendent perms */ 176ecd6cf80Smarks avl_tree_t z_local; /* local permissions */ 177ecd6cf80Smarks avl_tree_t z_descend; /* descendent permissions */ 178ecd6cf80Smarks } zfs_allow_node_t; 179ecd6cf80Smarks 180ecd6cf80Smarks typedef struct zfs_allow { 181ecd6cf80Smarks struct zfs_allow *z_next; 182ecd6cf80Smarks char z_setpoint[MAXPATHLEN]; 183ecd6cf80Smarks avl_tree_t z_sets; 184ecd6cf80Smarks avl_tree_t z_crperms; 185ecd6cf80Smarks avl_tree_t z_user; 186ecd6cf80Smarks avl_tree_t z_group; 187ecd6cf80Smarks avl_tree_t z_everyone; 188ecd6cf80Smarks } zfs_allow_t; 189ecd6cf80Smarks 190ecd6cf80Smarks /* 191fa9e4066Sahrens * Basic handle types 192fa9e4066Sahrens */ 193fa9e4066Sahrens typedef struct zfs_handle zfs_handle_t; 194fa9e4066Sahrens typedef struct zpool_handle zpool_handle_t; 19599653d4eSeschrock typedef struct libzfs_handle libzfs_handle_t; 19699653d4eSeschrock 19799653d4eSeschrock /* 19899653d4eSeschrock * Library initialization 19999653d4eSeschrock */ 20099653d4eSeschrock extern libzfs_handle_t *libzfs_init(void); 20199653d4eSeschrock extern void libzfs_fini(libzfs_handle_t *); 20299653d4eSeschrock 20399653d4eSeschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *); 20499653d4eSeschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *); 20599653d4eSeschrock 20699653d4eSeschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t); 20799653d4eSeschrock 2084445fffbSMatthew Ahrens extern void zfs_save_arguments(int argc, char **, char *, int); 2094445fffbSMatthew Ahrens extern int zpool_log_history(libzfs_handle_t *, const char *); 2104445fffbSMatthew Ahrens 21199653d4eSeschrock extern int libzfs_errno(libzfs_handle_t *); 21299653d4eSeschrock extern const char *libzfs_error_action(libzfs_handle_t *); 21399653d4eSeschrock extern const char *libzfs_error_description(libzfs_handle_t *); 21478f17100SMatthew Ahrens extern int zfs_standard_error(libzfs_handle_t *, int, const char *); 215ebedde84SEric Taylor extern void libzfs_mnttab_init(libzfs_handle_t *); 216ebedde84SEric Taylor extern void libzfs_mnttab_fini(libzfs_handle_t *); 217b2634b9cSEric Taylor extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t); 218ebedde84SEric Taylor extern int libzfs_mnttab_find(libzfs_handle_t *, const char *, 219ebedde84SEric Taylor struct mnttab *); 220ebedde84SEric Taylor extern void libzfs_mnttab_add(libzfs_handle_t *, const char *, 221ebedde84SEric Taylor const char *, const char *); 222ebedde84SEric Taylor extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *); 223fa9e4066Sahrens 224fa9e4066Sahrens /* 225fa9e4066Sahrens * Basic handle functions 226fa9e4066Sahrens */ 22799653d4eSeschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *); 22899653d4eSeschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *); 229fa9e4066Sahrens extern void zpool_close(zpool_handle_t *); 230fa9e4066Sahrens extern const char *zpool_get_name(zpool_handle_t *); 231fa9e4066Sahrens extern int zpool_get_state(zpool_handle_t *); 2326401734dSWill Andrews extern const char *zpool_state_to_name(vdev_state_t, vdev_aux_t); 2336401734dSWill Andrews extern const char *zpool_pool_state_to_name(pool_state_t); 23429ab75c9Srm160521 extern void zpool_free_handles(libzfs_handle_t *); 235fa9e4066Sahrens 236fa9e4066Sahrens /* 237fa9e4066Sahrens * Iterate over all active pools in the system. 238fa9e4066Sahrens */ 239fa9e4066Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *); 24099653d4eSeschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *); 2418808ac5dSYuri Pankov extern boolean_t zpool_skip_pool(const char *); 242fa9e4066Sahrens 243fa9e4066Sahrens /* 244fa9e4066Sahrens * Functions to create and destroy pools 245fa9e4066Sahrens */ 24699653d4eSeschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *, 2470a48a24eStimh nvlist_t *, nvlist_t *); 2484445fffbSMatthew Ahrens extern int zpool_destroy(zpool_handle_t *, const char *); 249fa9e4066Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *); 250fa9e4066Sahrens 2511195e687SMark J Musante typedef struct splitflags { 2521195e687SMark J Musante /* do not split, but return the config that would be split off */ 2531195e687SMark J Musante int dryrun : 1; 2541195e687SMark J Musante 2551195e687SMark J Musante /* after splitting, import the pool */ 2561195e687SMark J Musante int import : 1; 2571195e687SMark J Musante } splitflags_t; 2581195e687SMark J Musante 259fa9e4066Sahrens /* 260fa9e4066Sahrens * Functions to manipulate pool and vdev state 261fa9e4066Sahrens */ 2621702cce7SAlek Pinchuk extern int zpool_scan(zpool_handle_t *, pool_scan_func_t, pool_scrub_cmd_t); 263468c413aSTim Haley extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *); 264e9103aaeSGarrett D'Amore extern int zpool_reguid(zpool_handle_t *); 2654263d13fSGeorge Wilson extern int zpool_reopen(zpool_handle_t *); 266fa9e4066Sahrens 2673d7072f8Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int, 2683d7072f8Seschrock vdev_state_t *); 2693d7072f8Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t); 2703d7072f8Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *, 2713d7072f8Seschrock const char *, nvlist_t *, int); 272fa9e4066Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *); 27399653d4eSeschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *); 2745cabbc6bSPrashanth Sreenivasa extern int zpool_vdev_remove_cancel(zpool_handle_t *); 2755cabbc6bSPrashanth Sreenivasa extern int zpool_vdev_indirect_size(zpool_handle_t *, const char *, uint64_t *); 2761195e687SMark J Musante extern int zpool_vdev_split(zpool_handle_t *, char *, nvlist_t **, nvlist_t *, 2771195e687SMark J Musante splitflags_t); 2783d7072f8Seschrock 279069f55e2SEric Schrock extern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t); 280069f55e2SEric Schrock extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t); 2813d7072f8Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t); 2823d7072f8Seschrock 283fa94a07fSbrendan extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *, 284ee0eb9f2SEric Schrock boolean_t *, boolean_t *); 285573ca77eSGeorge Wilson extern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *, 286573ca77eSGeorge Wilson boolean_t *, boolean_t *, boolean_t *); 2877855d95bSToomas Soome extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, const char *, 2887855d95bSToomas Soome zpool_boot_label_t, uint64_t, int *); 289fa9e4066Sahrens 290fa9e4066Sahrens /* 291b1b8ab34Slling * Functions to manage pool properties 292b1b8ab34Slling */ 293b1b8ab34Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *); 2943d7072f8Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *, 295c58b3526SAdam Stevko size_t proplen, zprop_source_t *, boolean_t); 296990b4856Slling extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t, 297990b4856Slling zprop_source_t *); 298990b4856Slling 299b1b8ab34Slling extern const char *zpool_prop_to_name(zpool_prop_t); 300b1b8ab34Slling extern const char *zpool_prop_values(zpool_prop_t); 301b1b8ab34Slling 302b1b8ab34Slling /* 303fa9e4066Sahrens * Pool health statistics. 304fa9e4066Sahrens */ 305fa9e4066Sahrens typedef enum { 306fa9e4066Sahrens /* 307fa9e4066Sahrens * The following correspond to faults as defined in the (fault.fs.zfs.*) 308b81d61a6Slling * event namespace. Each is associated with a corresponding message ID. 309fa9e4066Sahrens */ 310fa9e4066Sahrens ZPOOL_STATUS_CORRUPT_CACHE, /* corrupt /kernel/drv/zpool.cache */ 311fa9e4066Sahrens ZPOOL_STATUS_MISSING_DEV_R, /* missing device with replicas */ 312fa9e4066Sahrens ZPOOL_STATUS_MISSING_DEV_NR, /* missing device with no replicas */ 313fa9e4066Sahrens ZPOOL_STATUS_CORRUPT_LABEL_R, /* bad device label with replicas */ 314b81d61a6Slling ZPOOL_STATUS_CORRUPT_LABEL_NR, /* bad device label with no replicas */ 315fa9e4066Sahrens ZPOOL_STATUS_BAD_GUID_SUM, /* sum of device guids didn't match */ 316fa9e4066Sahrens ZPOOL_STATUS_CORRUPT_POOL, /* pool metadata is corrupted */ 317fa9e4066Sahrens ZPOOL_STATUS_CORRUPT_DATA, /* data errors in user (meta)data */ 318fa9e4066Sahrens ZPOOL_STATUS_FAILING_DEV, /* device experiencing errors */ 319eaca9bbdSeschrock ZPOOL_STATUS_VERSION_NEWER, /* newer on-disk version */ 32095173954Sek110237 ZPOOL_STATUS_HOSTID_MISMATCH, /* last accessed by another system */ 32132b87932Sek110237 ZPOOL_STATUS_IO_FAILURE_WAIT, /* failed I/O, failmode 'wait' */ 32232b87932Sek110237 ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */ 323f67f35c3SEric Schrock ZPOOL_STATUS_BAD_LOG, /* cannot read log chain(s) */ 324f67f35c3SEric Schrock 325f67f35c3SEric Schrock /* 326ad135b5dSChristopher Siden * If the pool has unsupported features but can still be opened in 327ad135b5dSChristopher Siden * read-only mode, its status is ZPOOL_STATUS_UNSUP_FEAT_WRITE. If the 328ad135b5dSChristopher Siden * pool has unsupported features but cannot be opened at all, its 329ad135b5dSChristopher Siden * status is ZPOOL_STATUS_UNSUP_FEAT_READ. 330ad135b5dSChristopher Siden */ 331ad135b5dSChristopher Siden ZPOOL_STATUS_UNSUP_FEAT_READ, /* unsupported features for read */ 332ad135b5dSChristopher Siden ZPOOL_STATUS_UNSUP_FEAT_WRITE, /* unsupported features for write */ 333ad135b5dSChristopher Siden 334ad135b5dSChristopher Siden /* 335f67f35c3SEric Schrock * These faults have no corresponding message ID. At the time we are 336f67f35c3SEric Schrock * checking the status, the original reason for the FMA fault (I/O or 337f67f35c3SEric Schrock * checksum errors) has been lost. 338f67f35c3SEric Schrock */ 3393d7072f8Seschrock ZPOOL_STATUS_FAULTED_DEV_R, /* faulted device with replicas */ 3403d7072f8Seschrock ZPOOL_STATUS_FAULTED_DEV_NR, /* faulted device with no replicas */ 341fa9e4066Sahrens 342fa9e4066Sahrens /* 343fa9e4066Sahrens * The following are not faults per se, but still an error possibly 344b81d61a6Slling * requiring administrative attention. There is no corresponding 345fa9e4066Sahrens * message ID. 346fa9e4066Sahrens */ 34757221772SChristopher Siden ZPOOL_STATUS_VERSION_OLDER, /* older legacy on-disk version */ 34857221772SChristopher Siden ZPOOL_STATUS_FEAT_DISABLED, /* supported features are disabled */ 349fa9e4066Sahrens ZPOOL_STATUS_RESILVERING, /* device being resilvered */ 350cb605c4dSGerhard Roethlin ZPOOL_STATUS_OFFLINE_DEV, /* device offline */ 351c25309d4SGeorge Wilson ZPOOL_STATUS_REMOVED_DEV, /* removed device */ 352fa9e4066Sahrens 353fa9e4066Sahrens /* 354fa9e4066Sahrens * Finally, the following indicates a healthy pool. 355fa9e4066Sahrens */ 356fa9e4066Sahrens ZPOOL_STATUS_OK 357fa9e4066Sahrens } zpool_status_t; 358fa9e4066Sahrens 359ea8dc4b6Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **); 360ea8dc4b6Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **); 3619eb19f4dSGeorge Wilson extern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh); 362fa9e4066Sahrens 363fa9e4066Sahrens /* 364fa9e4066Sahrens * Statistics and configuration functions. 365fa9e4066Sahrens */ 366ea8dc4b6Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **); 367ad135b5dSChristopher Siden extern nvlist_t *zpool_get_features(zpool_handle_t *); 36894de1d4cSeschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *); 36955434c77Sek110237 extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **); 3707855d95bSToomas Soome extern boolean_t zpool_is_bootable(zpool_handle_t *); 371ea8dc4b6Seschrock 372fa9e4066Sahrens /* 373fa9e4066Sahrens * Import and export functions 374fa9e4066Sahrens */ 3754445fffbSMatthew Ahrens extern int zpool_export(zpool_handle_t *, boolean_t, const char *); 3764445fffbSMatthew Ahrens extern int zpool_export_force(zpool_handle_t *, const char *); 37799653d4eSeschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *, 378990b4856Slling char *altroot); 379990b4856Slling extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *, 3804b964adaSGeorge Wilson nvlist_t *, int); 381ad135b5dSChristopher Siden extern void zpool_print_unsup_feat(nvlist_t *config); 382fa9e4066Sahrens 383fa9e4066Sahrens /* 384fa9e4066Sahrens * Search for pools to import 385fa9e4066Sahrens */ 386d41c4376SMark J Musante 387d41c4376SMark J Musante typedef struct importargs { 388d41c4376SMark J Musante char **path; /* a list of paths to search */ 389d41c4376SMark J Musante int paths; /* number of paths to search */ 390d41c4376SMark J Musante char *poolname; /* name of a pool to find */ 391d41c4376SMark J Musante uint64_t guid; /* guid of a pool to find */ 392d41c4376SMark J Musante char *cachefile; /* cachefile to use for import */ 393d41c4376SMark J Musante int can_be_active : 1; /* can the pool be active? */ 394d41c4376SMark J Musante int unique : 1; /* does 'poolname' already exist? */ 395d41c4376SMark J Musante int exists : 1; /* set on return if pool already exists */ 3966f793812SPavel Zakharov nvlist_t *policy; /* rewind policy (rewind txg, etc.) */ 397d41c4376SMark J Musante } importargs_t; 398d41c4376SMark J Musante 399d41c4376SMark J Musante extern nvlist_t *zpool_search_import(libzfs_handle_t *, importargs_t *); 400d41c4376SMark J Musante 401d41c4376SMark J Musante /* legacy pool search routines */ 40224e697d4Sck153898 extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **); 4033a57275aSck153898 extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *, 404e829d913Sck153898 char *, uint64_t); 405fa9e4066Sahrens 406fa9e4066Sahrens /* 407c67d9675Seschrock * Miscellaneous pool functions 408c67d9675Seschrock */ 409ecd6cf80Smarks struct zfs_cmd; 410ecd6cf80Smarks 4114445fffbSMatthew Ahrens extern const char *zfs_history_event_names[]; 4128f18d1faSGeorge Wilson 41388ecc943SGeorge Wilson extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *, 41488ecc943SGeorge Wilson boolean_t verbose); 415990b4856Slling extern int zpool_upgrade(zpool_handle_t *, uint64_t); 41606eeb2adSek110237 extern int zpool_get_history(zpool_handle_t *, nvlist_t **); 4178f18d1faSGeorge Wilson extern int zpool_history_unpack(char *, uint64_t, uint64_t *, 4188f18d1faSGeorge Wilson nvlist_t ***, uint_t *); 41955434c77Sek110237 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *, 42055434c77Sek110237 size_t len); 421ecd6cf80Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *); 422753a6d45SSherry Moore extern int zpool_get_physpath(zpool_handle_t *, char *, size_t); 423468c413aSTim Haley extern void zpool_explain_recover(libzfs_handle_t *, const char *, int, 424468c413aSTim Haley nvlist_t *); 425*86714001SSerapheim Dimitropoulos extern int zpool_checkpoint(zpool_handle_t *); 426*86714001SSerapheim Dimitropoulos extern int zpool_discard_checkpoint(zpool_handle_t *); 427753a6d45SSherry Moore 428c67d9675Seschrock /* 429fa9e4066Sahrens * Basic handle manipulations. These functions do not create or destroy the 430fa9e4066Sahrens * underlying datasets, only the references to them. 431fa9e4066Sahrens */ 43299653d4eSeschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int); 43319b94df9SMatthew Ahrens extern zfs_handle_t *zfs_handle_dup(zfs_handle_t *); 434fa9e4066Sahrens extern void zfs_close(zfs_handle_t *); 435fa9e4066Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *); 436fa9e4066Sahrens extern const char *zfs_get_name(const zfs_handle_t *); 437d5b5bb25SRich Morris extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *); 4388808ac5dSYuri Pankov extern const char *zfs_get_pool_name(const zfs_handle_t *); 439fa9e4066Sahrens 440fa9e4066Sahrens /* 441fa9e4066Sahrens * Property management functions. Some functions are shared with the kernel, 442b81d61a6Slling * and are found in sys/fs/zfs.h. 443fa9e4066Sahrens */ 444990b4856Slling 445990b4856Slling /* 446990b4856Slling * zfs dataset property management 447990b4856Slling */ 448990b4856Slling extern const char *zfs_prop_default_string(zfs_prop_t); 449e9dbad6fSeschrock extern uint64_t zfs_prop_default_numeric(zfs_prop_t); 450e9dbad6fSeschrock extern const char *zfs_prop_column_name(zfs_prop_t); 451e9dbad6fSeschrock extern boolean_t zfs_prop_align_right(zfs_prop_t); 452e9dbad6fSeschrock 4530a48a24eStimh extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t, 454e9316f76SJoe Stein nvlist_t *, uint64_t, zfs_handle_t *, zpool_handle_t *, const char *); 4550a48a24eStimh 456990b4856Slling extern const char *zfs_prop_to_name(zfs_prop_t); 457990b4856Slling extern int zfs_prop_set(zfs_handle_t *, const char *, const char *); 45830925561SChris Williamson extern int zfs_prop_set_list(zfs_handle_t *, nvlist_t *); 459990b4856Slling extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t, 460990b4856Slling zprop_source_t *, char *, size_t, boolean_t); 46192241e0bSTom Erickson extern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t, 46292241e0bSTom Erickson boolean_t); 463990b4856Slling extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *, 464990b4856Slling zprop_source_t *, char *, size_t); 465edea4b55SLin Ling extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname, 466edea4b55SLin Ling uint64_t *propvalue); 46714843421SMatthew Ahrens extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname, 46814843421SMatthew Ahrens char *propbuf, int proplen, boolean_t literal); 46919b94df9SMatthew Ahrens extern int zfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname, 47019b94df9SMatthew Ahrens uint64_t *propvalue); 47119b94df9SMatthew Ahrens extern int zfs_prop_get_written(zfs_handle_t *zhp, const char *propname, 47219b94df9SMatthew Ahrens char *propbuf, int proplen, boolean_t literal); 473ad135b5dSChristopher Siden extern int zfs_prop_get_feature(zfs_handle_t *zhp, const char *propname, 474ad135b5dSChristopher Siden char *buf, size_t len); 475990b4856Slling extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t); 47692241e0bSTom Erickson extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t); 477990b4856Slling extern const char *zfs_prop_values(zfs_prop_t); 478990b4856Slling extern int zfs_prop_is_string(zfs_prop_t prop); 479990b4856Slling extern nvlist_t *zfs_get_user_props(zfs_handle_t *); 48092241e0bSTom Erickson extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *); 48119b94df9SMatthew Ahrens extern nvlist_t *zfs_get_clones_nvl(zfs_handle_t *); 48219b94df9SMatthew Ahrens 483990b4856Slling 484990b4856Slling typedef struct zprop_list { 485990b4856Slling int pl_prop; 486e9dbad6fSeschrock char *pl_user_prop; 487990b4856Slling struct zprop_list *pl_next; 488e9dbad6fSeschrock boolean_t pl_all; 489e9dbad6fSeschrock size_t pl_width; 49092241e0bSTom Erickson size_t pl_recvd_width; 491e9dbad6fSeschrock boolean_t pl_fixed; 492990b4856Slling } zprop_list_t; 493e9dbad6fSeschrock 49443d68d68SYuri Pankov extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t, 49543d68d68SYuri Pankov boolean_t); 4962e5e9e19SSanjeev Bagewadi extern void zfs_prune_proplist(zfs_handle_t *, uint8_t *); 497fa9e4066Sahrens 498fa9e4066Sahrens #define ZFS_MOUNTPOINT_NONE "none" 499fa9e4066Sahrens #define ZFS_MOUNTPOINT_LEGACY "legacy" 500fa9e4066Sahrens 501ad135b5dSChristopher Siden #define ZFS_FEATURE_DISABLED "disabled" 502ad135b5dSChristopher Siden #define ZFS_FEATURE_ENABLED "enabled" 503ad135b5dSChristopher Siden #define ZFS_FEATURE_ACTIVE "active" 504ad135b5dSChristopher Siden 505ad135b5dSChristopher Siden #define ZFS_UNSUPPORTED_INACTIVE "inactive" 506ad135b5dSChristopher Siden #define ZFS_UNSUPPORTED_READONLY "readonly" 507ad135b5dSChristopher Siden 508fa9e4066Sahrens /* 509990b4856Slling * zpool property management 510b1b8ab34Slling */ 511990b4856Slling extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **); 512ad135b5dSChristopher Siden extern int zpool_prop_get_feature(zpool_handle_t *, const char *, char *, 513ad135b5dSChristopher Siden size_t); 514990b4856Slling extern const char *zpool_prop_default_string(zpool_prop_t); 515990b4856Slling extern uint64_t zpool_prop_default_numeric(zpool_prop_t); 516990b4856Slling extern const char *zpool_prop_column_name(zpool_prop_t); 517990b4856Slling extern boolean_t zpool_prop_align_right(zpool_prop_t); 518990b4856Slling 519990b4856Slling /* 520990b4856Slling * Functions shared by zfs and zpool property management. 521990b4856Slling */ 522990b4856Slling extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all, 523990b4856Slling boolean_t ordered, zfs_type_t type); 524990b4856Slling extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **, 525990b4856Slling zfs_type_t); 526990b4856Slling extern void zprop_free_list(zprop_list_t *); 527990b4856Slling 52892241e0bSTom Erickson #define ZFS_GET_NCOLS 5 52992241e0bSTom Erickson 53092241e0bSTom Erickson typedef enum { 53192241e0bSTom Erickson GET_COL_NONE, 53292241e0bSTom Erickson GET_COL_NAME, 53392241e0bSTom Erickson GET_COL_PROPERTY, 53492241e0bSTom Erickson GET_COL_VALUE, 53592241e0bSTom Erickson GET_COL_RECVD, 53692241e0bSTom Erickson GET_COL_SOURCE 53792241e0bSTom Erickson } zfs_get_column_t; 53892241e0bSTom Erickson 539990b4856Slling /* 540990b4856Slling * Functions for printing zfs or zpool properties 541990b4856Slling */ 542990b4856Slling typedef struct zprop_get_cbdata { 543b1b8ab34Slling int cb_sources; 54492241e0bSTom Erickson zfs_get_column_t cb_columns[ZFS_GET_NCOLS]; 54592241e0bSTom Erickson int cb_colwidths[ZFS_GET_NCOLS + 1]; 546b1b8ab34Slling boolean_t cb_scripted; 547b1b8ab34Slling boolean_t cb_literal; 548b1b8ab34Slling boolean_t cb_first; 549990b4856Slling zprop_list_t *cb_proplist; 550990b4856Slling zfs_type_t cb_type; 551990b4856Slling } zprop_get_cbdata_t; 552b1b8ab34Slling 553990b4856Slling void zprop_print_one_property(const char *, zprop_get_cbdata_t *, 55492241e0bSTom Erickson const char *, const char *, zprop_source_t, const char *, 55592241e0bSTom Erickson const char *); 556b1b8ab34Slling 557b1b8ab34Slling /* 558fa9e4066Sahrens * Iterator functions. 559fa9e4066Sahrens */ 560fa9e4066Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *); 56199653d4eSeschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *); 562fa9e4066Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *); 5633bb79becSeschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *); 5647f7322feSeschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *); 5650d8fa8f8SMartin Matuska extern int zfs_iter_snapshots(zfs_handle_t *, boolean_t, zfs_iter_f, void *); 566ca45db41SChris Kirby extern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *); 56719b94df9SMatthew Ahrens extern int zfs_iter_snapspec(zfs_handle_t *, const char *, zfs_iter_f, void *); 56878f17100SMatthew Ahrens extern int zfs_iter_bookmarks(zfs_handle_t *, zfs_iter_f, void *); 569fa9e4066Sahrens 5709d9a58e3SEric Taylor typedef struct get_all_cb { 5719d9a58e3SEric Taylor zfs_handle_t **cb_handles; 5729d9a58e3SEric Taylor size_t cb_alloc; 5739d9a58e3SEric Taylor size_t cb_used; 5749d9a58e3SEric Taylor boolean_t cb_verbose; 5759d9a58e3SEric Taylor int (*cb_getone)(zfs_handle_t *, void *); 5769d9a58e3SEric Taylor } get_all_cb_t; 5779d9a58e3SEric Taylor 5789d9a58e3SEric Taylor void libzfs_add_handle(get_all_cb_t *, zfs_handle_t *); 5799d9a58e3SEric Taylor int libzfs_dataset_cmp(const void *, const void *); 5809d9a58e3SEric Taylor 581fa9e4066Sahrens /* 582fa9e4066Sahrens * Functions to create and destroy datasets. 583fa9e4066Sahrens */ 58499653d4eSeschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t, 585e9dbad6fSeschrock nvlist_t *); 5867f1f55eaSvb160487 extern int zfs_create_ancestors(libzfs_handle_t *, const char *); 587842727c2SChris Kirby extern int zfs_destroy(zfs_handle_t *, boolean_t); 588842727c2SChris Kirby extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t); 5893b2aab18SMatthew Ahrens extern int zfs_destroy_snaps_nvl(libzfs_handle_t *, nvlist_t *, boolean_t); 590e9dbad6fSeschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *); 591bb0ade09Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *); 5924445fffbSMatthew Ahrens extern int zfs_snapshot_nvl(libzfs_handle_t *hdl, nvlist_t *snaps, 5934445fffbSMatthew Ahrens nvlist_t *props); 594c391e322Sahrens extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t); 5956a9cb0eaSEric Schrock extern int zfs_rename(zfs_handle_t *, const char *, boolean_t, boolean_t); 5969e69d7d0SLori Alt 5979e69d7d0SLori Alt typedef struct sendflags { 5989e69d7d0SLori Alt /* print informational messages (ie, -v was specified) */ 59919b94df9SMatthew Ahrens boolean_t verbose; 6009e69d7d0SLori Alt 60192241e0bSTom Erickson /* recursive send (ie, -R) */ 60219b94df9SMatthew Ahrens boolean_t replicate; 6039e69d7d0SLori Alt 6049e69d7d0SLori Alt /* for incrementals, do all intermediate snapshots */ 60519b94df9SMatthew Ahrens boolean_t doall; 6069e69d7d0SLori Alt 6079e69d7d0SLori Alt /* if dataset is a clone, do incremental from its origin */ 60819b94df9SMatthew Ahrens boolean_t fromorigin; 6099e69d7d0SLori Alt 6109e69d7d0SLori Alt /* do deduplication */ 61119b94df9SMatthew Ahrens boolean_t dedup; 61292241e0bSTom Erickson 61392241e0bSTom Erickson /* send properties (ie, -p) */ 61419b94df9SMatthew Ahrens boolean_t props; 61519b94df9SMatthew Ahrens 61619b94df9SMatthew Ahrens /* do not send (no-op, ie. -n) */ 61719b94df9SMatthew Ahrens boolean_t dryrun; 61819b94df9SMatthew Ahrens 61919b94df9SMatthew Ahrens /* parsable verbose output (ie. -P) */ 62019b94df9SMatthew Ahrens boolean_t parsable; 6214e3c9f44SBill Pijewski 6224e3c9f44SBill Pijewski /* show progress (ie. -v) */ 6234e3c9f44SBill Pijewski boolean_t progress; 6245d7b4d43SMatthew Ahrens 625b5152584SMatthew Ahrens /* large blocks (>128K) are permitted */ 626b5152584SMatthew Ahrens boolean_t largeblock; 627b5152584SMatthew Ahrens 6285d7b4d43SMatthew Ahrens /* WRITE_EMBEDDED records of type DATA are permitted */ 6295d7b4d43SMatthew Ahrens boolean_t embed_data; 6305602294fSDan Kimmel 6315602294fSDan Kimmel /* compressed WRITE records are permitted */ 6325602294fSDan Kimmel boolean_t compress; 6339e69d7d0SLori Alt } sendflags_t; 6349e69d7d0SLori Alt 6359e69d7d0SLori Alt typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *); 6369e69d7d0SLori Alt 63719b94df9SMatthew Ahrens extern int zfs_send(zfs_handle_t *, const char *, const char *, 63819b94df9SMatthew Ahrens sendflags_t *, int, snapfilter_cb_t, void *, nvlist_t **); 6395d7b4d43SMatthew Ahrens extern int zfs_send_one(zfs_handle_t *, const char *, int, enum lzc_send_flags); 6409c3fd121SMatthew Ahrens extern int zfs_send_resume(libzfs_handle_t *, sendflags_t *, int outfd, 6419c3fd121SMatthew Ahrens const char *); 6429c3fd121SMatthew Ahrens extern nvlist_t *zfs_send_resume_token_to_nvlist(libzfs_handle_t *hdl, 6439c3fd121SMatthew Ahrens const char *token); 6449e69d7d0SLori Alt 64599653d4eSeschrock extern int zfs_promote(zfs_handle_t *); 6463b2aab18SMatthew Ahrens extern int zfs_hold(zfs_handle_t *, const char *, const char *, 647a7a845e4SSteven Hartland boolean_t, int); 648a7a845e4SSteven Hartland extern int zfs_hold_nvl(zfs_handle_t *, int, nvlist_t *); 649842727c2SChris Kirby extern int zfs_release(zfs_handle_t *, const char *, const char *, boolean_t); 6501af68beaSAlexander Stetsenko extern int zfs_get_holds(zfs_handle_t *, nvlist_t **); 651c1449561SEric Taylor extern uint64_t zvol_volsize_to_reservation(uint64_t, nvlist_t *); 652fa9e4066Sahrens 6530aea4b19SMatthew Ahrens typedef int (*zfs_userspace_cb_t)(void *arg, const char *domain, 65414843421SMatthew Ahrens uid_t rid, uint64_t space); 65514843421SMatthew Ahrens 6561af68beaSAlexander Stetsenko extern int zfs_userspace(zfs_handle_t *, zfs_userquota_prop_t, 6571af68beaSAlexander Stetsenko zfs_userspace_cb_t, void *); 6581af68beaSAlexander Stetsenko 6591af68beaSAlexander Stetsenko extern int zfs_get_fsacl(zfs_handle_t *, nvlist_t **); 6601af68beaSAlexander Stetsenko extern int zfs_set_fsacl(zfs_handle_t *, boolean_t, nvlist_t *); 66114843421SMatthew Ahrens 6623cb34c60Sahrens typedef struct recvflags { 6634ccbb6e7Sahrens /* print informational messages (ie, -v was specified) */ 66419b94df9SMatthew Ahrens boolean_t verbose; 6654ccbb6e7Sahrens 6664ccbb6e7Sahrens /* the destination is a prefix, not the exact fs (ie, -d) */ 66719b94df9SMatthew Ahrens boolean_t isprefix; 6684ccbb6e7Sahrens 669f64930f5STom Erickson /* 670f64930f5STom Erickson * Only the tail of the sent snapshot path is appended to the 671f64930f5STom Erickson * destination to determine the received snapshot name (ie, -e). 672f64930f5STom Erickson */ 67319b94df9SMatthew Ahrens boolean_t istail; 674f64930f5STom Erickson 6754ccbb6e7Sahrens /* do not actually do the recv, just check if it would work (ie, -n) */ 67619b94df9SMatthew Ahrens boolean_t dryrun; 6774ccbb6e7Sahrens 6784ccbb6e7Sahrens /* rollback/destroy filesystems as necessary (eg, -F) */ 67919b94df9SMatthew Ahrens boolean_t force; 6804ccbb6e7Sahrens 6814ccbb6e7Sahrens /* set "canmount=off" on all modified filesystems */ 68219b94df9SMatthew Ahrens boolean_t canmountoff; 6834ccbb6e7Sahrens 6849c3fd121SMatthew Ahrens /* 6859c3fd121SMatthew Ahrens * Mark the file systems as "resumable" and do not destroy them if the 6869c3fd121SMatthew Ahrens * receive is interrupted 6879c3fd121SMatthew Ahrens */ 6889c3fd121SMatthew Ahrens boolean_t resumable; 6899c3fd121SMatthew Ahrens 6904ccbb6e7Sahrens /* byteswap flag is used internally; callers need not specify */ 69119b94df9SMatthew Ahrens boolean_t byteswap; 69233408eefSLori Alt 69333408eefSLori Alt /* do not mount file systems as they are extracted (private) */ 69419b94df9SMatthew Ahrens boolean_t nomount; 6953cb34c60Sahrens } recvflags_t; 6963cb34c60Sahrens 697a2cdcdd2SPaul Dagnelie extern int zfs_receive(libzfs_handle_t *, const char *, nvlist_t *, 698a2cdcdd2SPaul Dagnelie recvflags_t *, int, avl_tree_t *); 6993cb34c60Sahrens 70099d5e173STim Haley typedef enum diff_flags { 70199d5e173STim Haley ZFS_DIFF_PARSEABLE = 0x1, 70299d5e173STim Haley ZFS_DIFF_TIMESTAMP = 0x2, 70399d5e173STim Haley ZFS_DIFF_CLASSIFY = 0x4 70499d5e173STim Haley } diff_flags_t; 70599d5e173STim Haley 70699d5e173STim Haley extern int zfs_show_diffs(zfs_handle_t *, int, const char *, const char *, 70799d5e173STim Haley int); 70899d5e173STim Haley 709fa9e4066Sahrens /* 710fa9e4066Sahrens * Miscellaneous functions. 711fa9e4066Sahrens */ 712fa9e4066Sahrens extern const char *zfs_type_to_name(zfs_type_t); 713fa9e4066Sahrens extern void zfs_refresh_properties(zfs_handle_t *); 714fa9e4066Sahrens extern int zfs_name_valid(const char *, zfs_type_t); 7155aba80dbSck153898 extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t); 7167f1f55eaSvb160487 extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *, 7177f1f55eaSvb160487 zfs_type_t); 7187b97dc1aSrm160521 extern int zfs_spa_version(zfs_handle_t *, int *); 71978f17100SMatthew Ahrens extern boolean_t zfs_bookmark_exists(const char *path); 720fa9e4066Sahrens 721fa9e4066Sahrens /* 722fa9e4066Sahrens * Mount support functions. 723fa9e4066Sahrens */ 72455434c77Sek110237 extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **); 72599653d4eSeschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **); 726fa9e4066Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int); 727fa9e4066Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int); 728fa9e4066Sahrens extern int zfs_unmountall(zfs_handle_t *, int); 729fa9e4066Sahrens 730fa9e4066Sahrens /* 731fa9e4066Sahrens * Share support functions. 732fa9e4066Sahrens */ 733f3861e1aSahl extern boolean_t zfs_is_shared(zfs_handle_t *); 734fa9e4066Sahrens extern int zfs_share(zfs_handle_t *); 735f3861e1aSahl extern int zfs_unshare(zfs_handle_t *); 736f3861e1aSahl 737f3861e1aSahl /* 7383d7072f8Seschrock * Protocol-specific share support functions. 739f3861e1aSahl */ 740f3861e1aSahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **); 741da6c28aaSamw extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **); 742f3861e1aSahl extern int zfs_share_nfs(zfs_handle_t *); 743da6c28aaSamw extern int zfs_share_smb(zfs_handle_t *); 744da6c28aaSamw extern int zfs_shareall(zfs_handle_t *); 745f3861e1aSahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *); 746da6c28aaSamw extern int zfs_unshare_smb(zfs_handle_t *, const char *); 747f3861e1aSahl extern int zfs_unshareall_nfs(zfs_handle_t *); 748da6c28aaSamw extern int zfs_unshareall_smb(zfs_handle_t *); 749da6c28aaSamw extern int zfs_unshareall_bypath(zfs_handle_t *, const char *); 750da6c28aaSamw extern int zfs_unshareall(zfs_handle_t *); 751743a77edSAlan Wright extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *, 752da6c28aaSamw void *, void *, int, zfs_share_op_t); 753fa9e4066Sahrens 754fa9e4066Sahrens /* 755fa9e4066Sahrens * When dealing with nvlists, verify() is extremely useful 756fa9e4066Sahrens */ 757fa9e4066Sahrens #ifdef NDEBUG 758fa9e4066Sahrens #define verify(EX) ((void)(EX)) 759fa9e4066Sahrens #else 760fa9e4066Sahrens #define verify(EX) assert(EX) 761fa9e4066Sahrens #endif 762fa9e4066Sahrens 763fa9e4066Sahrens /* 764fa9e4066Sahrens * Utility function to convert a number to a human-readable form. 765fa9e4066Sahrens */ 766fa9e4066Sahrens extern void zfs_nicenum(uint64_t, char *, size_t); 767e9dbad6fSeschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *); 768fa9e4066Sahrens 769fa9e4066Sahrens /* 770fa9e4066Sahrens * Given a device or file, determine if it is part of a pool. 771fa9e4066Sahrens */ 77299653d4eSeschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **, 77399653d4eSeschrock boolean_t *); 774fa9e4066Sahrens 775fa9e4066Sahrens /* 776096d22d4SEric Schrock * Label manipulation. 777fa9e4066Sahrens */ 77899653d4eSeschrock extern int zpool_read_label(int, nvlist_t **); 779096d22d4SEric Schrock extern int zpool_clear_label(int); 780fa9e4066Sahrens 781e7cbe64fSgw25295 /* is this zvol valid for use as a dump device? */ 782e7cbe64fSgw25295 extern int zvol_check_dump_config(char *); 783e7cbe64fSgw25295 7843bb79becSeschrock /* 785743a77edSAlan Wright * Management interfaces for SMB ACL files 786743a77edSAlan Wright */ 787743a77edSAlan Wright 788743a77edSAlan Wright int zfs_smb_acl_add(libzfs_handle_t *, char *, char *, char *); 789743a77edSAlan Wright int zfs_smb_acl_remove(libzfs_handle_t *, char *, char *, char *); 790743a77edSAlan Wright int zfs_smb_acl_purge(libzfs_handle_t *, char *, char *); 791743a77edSAlan Wright int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *); 792743a77edSAlan Wright 793743a77edSAlan Wright /* 794f3861e1aSahl * Enable and disable datasets within a pool by mounting/unmounting and 795f3861e1aSahl * sharing/unsharing them. 7963bb79becSeschrock */ 797f3861e1aSahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int); 798f3861e1aSahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t); 7993bb79becSeschrock 800069f55e2SEric Schrock /* 801069f55e2SEric Schrock * Mappings between vdev and FRU. 802069f55e2SEric Schrock */ 803069f55e2SEric Schrock extern void libzfs_fru_refresh(libzfs_handle_t *); 804069f55e2SEric Schrock extern const char *libzfs_fru_lookup(libzfs_handle_t *, const char *); 805069f55e2SEric Schrock extern const char *libzfs_fru_devpath(libzfs_handle_t *, const char *); 806069f55e2SEric Schrock extern boolean_t libzfs_fru_compare(libzfs_handle_t *, const char *, 807069f55e2SEric Schrock const char *); 808069f55e2SEric Schrock extern boolean_t libzfs_fru_notself(libzfs_handle_t *, const char *); 809069f55e2SEric Schrock extern int zpool_fru_set(zpool_handle_t *, uint64_t, const char *); 810069f55e2SEric Schrock 8112bcf0248SMax Grossman extern int zfs_get_hole_count(const char *, uint64_t *, uint64_t *); 8125cabbc6bSPrashanth Sreenivasa extern int zfs_remap_indirects(libzfs_handle_t *hdl, const char *); 8132bcf0248SMax Grossman 8148a981c33SDaniel Hoffman /* Allow consumers to initialize libshare externally for optimal performance */ 8158a981c33SDaniel Hoffman extern int zfs_init_libshare_arg(libzfs_handle_t *, int, void *); 8168a981c33SDaniel Hoffman /* 8178a981c33SDaniel Hoffman * For most consumers, zfs_init_libshare_arg is sufficient on its own, and 8188a981c33SDaniel Hoffman * zfs_uninit_libshare is unnecessary. zfs_uninit_libshare should only be called 8198a981c33SDaniel Hoffman * if the caller has already initialized libshare for one set of zfs handles, 8208a981c33SDaniel Hoffman * and wishes to share or unshare filesystems outside of that set. In that case, 8218a981c33SDaniel Hoffman * the caller should uninitialize libshare, and then re-initialize it with the 8228a981c33SDaniel Hoffman * new handles being shared or unshared. 8238a981c33SDaniel Hoffman */ 8248a981c33SDaniel Hoffman extern void zfs_uninit_libshare(libzfs_handle_t *); 825fa9e4066Sahrens #ifdef __cplusplus 826fa9e4066Sahrens } 827fa9e4066Sahrens #endif 828fa9e4066Sahrens 829fa9e4066Sahrens #endif /* _LIBZFS_H */ 830