1168404Spjd/* 2168404Spjd * CDDL HEADER START 3168404Spjd * 4168404Spjd * The contents of this file are subject to the terms of the 5168404Spjd * Common Development and Distribution License (the "License"). 6168404Spjd * You may not use this file except in compliance with the License. 7168404Spjd * 8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9168404Spjd * or http://www.opensolaris.org/os/licensing. 10168404Spjd * See the License for the specific language governing permissions 11168404Spjd * and limitations under the License. 12168404Spjd * 13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each 14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15168404Spjd * If applicable, add the following below this CDDL HEADER, with the 16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying 17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner] 18168404Spjd * 19168404Spjd * CDDL HEADER END 20168404Spjd */ 21168404Spjd 22168404Spjd/* 23219089Spjd * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 24228103Smm * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 25230402Smm * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>. 26230404Smm * All rights reserved. 27236155Smm * Copyright (c) 2012 by Delphix. All rights reserved. 28235222Smm * Copyright (c) 2012, Joyent, Inc. All rights reserved. 29235216Smm * Copyright (c) 2012 Martin Matuska <mm@FreeBSD.org>. All rights reserved. 30251646Sdelphij * Copyright (c) 2013 Steven Hartland. All rights reserved. 31168404Spjd */ 32168404Spjd 33168404Spjd#ifndef _LIBZFS_H 34168404Spjd#define _LIBZFS_H 35168404Spjd 36168404Spjd#include <assert.h> 37168404Spjd#include <libnvpair.h> 38209962Smm#include <sys/mnttab.h> 39168404Spjd#include <sys/param.h> 40168404Spjd#include <sys/types.h> 41168404Spjd#include <sys/varargs.h> 42168404Spjd#include <sys/fs/zfs.h> 43185029Spjd#include <sys/avl.h> 44168404Spjd#include <sys/zfs_ioctl.h> 45168404Spjd 46168404Spjd#ifdef __cplusplus 47168404Spjdextern "C" { 48168404Spjd#endif 49168404Spjd 50168404Spjd/* 51168404Spjd * Miscellaneous ZFS constants 52168404Spjd */ 53168404Spjd#define ZFS_MAXNAMELEN MAXNAMELEN 54168404Spjd#define ZPOOL_MAXNAMELEN MAXNAMELEN 55168404Spjd#define ZFS_MAXPROPLEN MAXPATHLEN 56185029Spjd#define ZPOOL_MAXPROPLEN MAXPATHLEN 57168404Spjd 58168404Spjd/* 59168404Spjd * libzfs errors 60168404Spjd */ 61248571Smmtypedef enum zfs_error { 62248571Smm EZFS_SUCCESS = 0, /* no error -- success */ 63168404Spjd EZFS_NOMEM = 2000, /* out of memory */ 64168404Spjd EZFS_BADPROP, /* invalid property value */ 65168404Spjd EZFS_PROPREADONLY, /* cannot set readonly property */ 66168404Spjd EZFS_PROPTYPE, /* property does not apply to dataset type */ 67168404Spjd EZFS_PROPNONINHERIT, /* property is not inheritable */ 68168404Spjd EZFS_PROPSPACE, /* bad quota or reservation */ 69168404Spjd EZFS_BADTYPE, /* dataset is not of appropriate type */ 70168404Spjd EZFS_BUSY, /* pool or dataset is busy */ 71168404Spjd EZFS_EXISTS, /* pool or dataset already exists */ 72168404Spjd EZFS_NOENT, /* no such pool or dataset */ 73168404Spjd EZFS_BADSTREAM, /* bad backup stream */ 74168404Spjd EZFS_DSREADONLY, /* dataset is readonly */ 75168404Spjd EZFS_VOLTOOBIG, /* volume is too large for 32-bit system */ 76168404Spjd EZFS_INVALIDNAME, /* invalid dataset name */ 77168404Spjd EZFS_BADRESTORE, /* unable to restore to destination */ 78168404Spjd EZFS_BADBACKUP, /* backup failed */ 79168404Spjd EZFS_BADTARGET, /* bad attach/detach/replace target */ 80168404Spjd EZFS_NODEVICE, /* no such device in pool */ 81168404Spjd EZFS_BADDEV, /* invalid device to add */ 82168404Spjd EZFS_NOREPLICAS, /* no valid replicas */ 83168404Spjd EZFS_RESILVERING, /* currently resilvering */ 84168404Spjd EZFS_BADVERSION, /* unsupported version */ 85168404Spjd EZFS_POOLUNAVAIL, /* pool is currently unavailable */ 86168404Spjd EZFS_DEVOVERFLOW, /* too many devices in one vdev */ 87168404Spjd EZFS_BADPATH, /* must be an absolute path */ 88168404Spjd EZFS_CROSSTARGET, /* rename or clone across pool or dataset */ 89168404Spjd EZFS_ZONED, /* used improperly in local zone */ 90168404Spjd EZFS_MOUNTFAILED, /* failed to mount dataset */ 91168404Spjd EZFS_UMOUNTFAILED, /* failed to unmount dataset */ 92168404Spjd EZFS_UNSHARENFSFAILED, /* unshare(1M) failed */ 93168404Spjd EZFS_SHARENFSFAILED, /* share(1M) failed */ 94168404Spjd EZFS_PERM, /* permission denied */ 95168404Spjd EZFS_NOSPC, /* out of space */ 96219089Spjd EZFS_FAULT, /* bad address */ 97168404Spjd EZFS_IO, /* I/O error */ 98168404Spjd EZFS_INTR, /* signal received */ 99168404Spjd EZFS_ISSPARE, /* device is a hot spare */ 100168404Spjd EZFS_INVALCONFIG, /* invalid vdev configuration */ 101168404Spjd EZFS_RECURSIVE, /* recursive dependency */ 102168404Spjd EZFS_NOHISTORY, /* no history object */ 103168404Spjd EZFS_POOLPROPS, /* couldn't retrieve pool props */ 104168404Spjd EZFS_POOL_NOTSUP, /* ops not supported for this type of pool */ 105168404Spjd EZFS_POOL_INVALARG, /* invalid argument for this pool operation */ 106168498Spjd EZFS_NAMETOOLONG, /* dataset name is too long */ 107185029Spjd EZFS_OPENFAILED, /* open of device failed */ 108185029Spjd EZFS_NOCAP, /* couldn't get capacity */ 109185029Spjd EZFS_LABELFAILED, /* write of label failed */ 110185029Spjd EZFS_BADWHO, /* invalid permission who */ 111185029Spjd EZFS_BADPERM, /* invalid permission */ 112185029Spjd EZFS_BADPERMSET, /* invalid permission set name */ 113185029Spjd EZFS_NODELEGATION, /* delegated administration is disabled */ 114185029Spjd EZFS_UNSHARESMBFAILED, /* failed to unshare over smb */ 115185029Spjd EZFS_SHARESMBFAILED, /* failed to share over smb */ 116185029Spjd EZFS_BADCACHE, /* bad cache file */ 117185029Spjd EZFS_ISL2CACHE, /* device is for the level 2 ARC */ 118185029Spjd EZFS_VDEVNOTSUP, /* unsupported vdev type */ 119185029Spjd EZFS_NOTSUP, /* ops not supported on this dataset */ 120185029Spjd EZFS_ACTIVE_SPARE, /* pool has active shared spare devices */ 121213197Smm EZFS_UNPLAYED_LOGS, /* log device has unplayed logs */ 122219089Spjd EZFS_REFTAG_RELE, /* snapshot release: tag not found */ 123219089Spjd EZFS_REFTAG_HOLD, /* snapshot hold: tag already exists */ 124219089Spjd EZFS_TAGTOOLONG, /* snapshot hold/rele: tag too long */ 125219089Spjd EZFS_PIPEFAILED, /* pipe create failed */ 126219089Spjd EZFS_THREADCREATEFAILED, /* thread create failed */ 127219089Spjd EZFS_POSTSPLIT_ONLINE, /* onlining a disk after splitting it */ 128219089Spjd EZFS_SCRUBBING, /* currently scrubbing */ 129219089Spjd EZFS_NO_SCRUB, /* no active scrub */ 130219089Spjd EZFS_DIFF, /* general failure of zfs diff */ 131219089Spjd EZFS_DIFFDATA, /* bad zfs diff data */ 132219089Spjd EZFS_POOLREADONLY, /* pool is in read-only mode */ 133168404Spjd EZFS_UNKNOWN 134248571Smm} zfs_error_t; 135168404Spjd 136168404Spjd/* 137185029Spjd * The following data structures are all part 138185029Spjd * of the zfs_allow_t data structure which is 139185029Spjd * used for printing 'allow' permissions. 140185029Spjd * It is a linked list of zfs_allow_t's which 141185029Spjd * then contain avl tree's for user/group/sets/... 142185029Spjd * and each one of the entries in those trees have 143185029Spjd * avl tree's for the permissions they belong to and 144185029Spjd * whether they are local,descendent or local+descendent 145185029Spjd * permissions. The AVL trees are used primarily for 146185029Spjd * sorting purposes, but also so that we can quickly find 147185029Spjd * a given user and or permission. 148185029Spjd */ 149185029Spjdtypedef struct zfs_perm_node { 150185029Spjd avl_node_t z_node; 151185029Spjd char z_pname[MAXPATHLEN]; 152185029Spjd} zfs_perm_node_t; 153185029Spjd 154185029Spjdtypedef struct zfs_allow_node { 155185029Spjd avl_node_t z_node; 156185029Spjd char z_key[MAXPATHLEN]; /* name, such as joe */ 157185029Spjd avl_tree_t z_localdescend; /* local+descendent perms */ 158185029Spjd avl_tree_t z_local; /* local permissions */ 159185029Spjd avl_tree_t z_descend; /* descendent permissions */ 160185029Spjd} zfs_allow_node_t; 161185029Spjd 162185029Spjdtypedef struct zfs_allow { 163185029Spjd struct zfs_allow *z_next; 164185029Spjd char z_setpoint[MAXPATHLEN]; 165185029Spjd avl_tree_t z_sets; 166185029Spjd avl_tree_t z_crperms; 167185029Spjd avl_tree_t z_user; 168185029Spjd avl_tree_t z_group; 169185029Spjd avl_tree_t z_everyone; 170185029Spjd} zfs_allow_t; 171185029Spjd 172185029Spjd/* 173168404Spjd * Basic handle types 174168404Spjd */ 175168404Spjdtypedef struct zfs_handle zfs_handle_t; 176168404Spjdtypedef struct zpool_handle zpool_handle_t; 177168404Spjdtypedef struct libzfs_handle libzfs_handle_t; 178168404Spjd 179168404Spjd/* 180168404Spjd * Library initialization 181168404Spjd */ 182168404Spjdextern libzfs_handle_t *libzfs_init(void); 183168404Spjdextern void libzfs_fini(libzfs_handle_t *); 184168404Spjd 185168404Spjdextern libzfs_handle_t *zpool_get_handle(zpool_handle_t *); 186168404Spjdextern libzfs_handle_t *zfs_get_handle(zfs_handle_t *); 187168404Spjd 188168404Spjdextern void libzfs_print_on_error(libzfs_handle_t *, boolean_t); 189168404Spjd 190248571Smmextern void zfs_save_arguments(int argc, char **, char *, int); 191248571Smmextern int zpool_log_history(libzfs_handle_t *, const char *); 192248571Smm 193168404Spjdextern int libzfs_errno(libzfs_handle_t *); 194168404Spjdextern const char *libzfs_error_action(libzfs_handle_t *); 195168404Spjdextern const char *libzfs_error_description(libzfs_handle_t *); 196209962Smmextern void libzfs_mnttab_init(libzfs_handle_t *); 197209962Smmextern void libzfs_mnttab_fini(libzfs_handle_t *); 198209962Smmextern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t); 199209962Smmextern int libzfs_mnttab_find(libzfs_handle_t *, const char *, 200209962Smm struct mnttab *); 201209962Smmextern void libzfs_mnttab_add(libzfs_handle_t *, const char *, 202209962Smm const char *, const char *); 203209962Smmextern void libzfs_mnttab_remove(libzfs_handle_t *, const char *); 204168404Spjd 205168404Spjd/* 206168404Spjd * Basic handle functions 207168404Spjd */ 208168404Spjdextern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *); 209168404Spjdextern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *); 210168404Spjdextern void zpool_close(zpool_handle_t *); 211168404Spjdextern const char *zpool_get_name(zpool_handle_t *); 212168404Spjdextern int zpool_get_state(zpool_handle_t *); 213224169Sgibbsextern const char *zpool_state_to_name(vdev_state_t, vdev_aux_t); 214224169Sgibbsextern const char *zpool_pool_state_to_name(pool_state_t); 215185029Spjdextern void zpool_free_handles(libzfs_handle_t *); 216168404Spjd 217168404Spjd/* 218168404Spjd * Iterate over all active pools in the system. 219168404Spjd */ 220168404Spjdtypedef int (*zpool_iter_f)(zpool_handle_t *, void *); 221168404Spjdextern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *); 222168404Spjd 223168404Spjd/* 224168404Spjd * Functions to create and destroy pools 225168404Spjd */ 226168404Spjdextern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *, 227185029Spjd nvlist_t *, nvlist_t *); 228248571Smmextern int zpool_destroy(zpool_handle_t *, const char *); 229168404Spjdextern int zpool_add(zpool_handle_t *, nvlist_t *); 230168404Spjd 231219089Spjdtypedef struct splitflags { 232219089Spjd /* do not split, but return the config that would be split off */ 233219089Spjd int dryrun : 1; 234219089Spjd 235219089Spjd /* after splitting, import the pool */ 236219089Spjd int import : 1; 237219089Spjd} splitflags_t; 238219089Spjd 239168404Spjd/* 240168404Spjd * Functions to manipulate pool and vdev state 241168404Spjd */ 242219089Spjdextern int zpool_scan(zpool_handle_t *, pool_scan_func_t); 243219089Spjdextern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *); 244228103Smmextern int zpool_reguid(zpool_handle_t *); 245236155Smmextern int zpool_reopen(zpool_handle_t *); 246168404Spjd 247185029Spjdextern int zpool_vdev_online(zpool_handle_t *, const char *, int, 248185029Spjd vdev_state_t *); 249185029Spjdextern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t); 250185029Spjdextern int zpool_vdev_attach(zpool_handle_t *, const char *, 251185029Spjd const char *, nvlist_t *, int); 252168404Spjdextern int zpool_vdev_detach(zpool_handle_t *, const char *); 253168404Spjdextern int zpool_vdev_remove(zpool_handle_t *, const char *); 254219089Spjdextern int zpool_vdev_split(zpool_handle_t *, char *, nvlist_t **, nvlist_t *, 255219089Spjd splitflags_t); 256168404Spjd 257219089Spjdextern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t); 258219089Spjdextern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t); 259185029Spjdextern int zpool_vdev_clear(zpool_handle_t *, uint64_t); 260185029Spjd 261185029Spjdextern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *, 262185029Spjd boolean_t *, boolean_t *); 263219089Spjdextern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *, 264219089Spjd boolean_t *, boolean_t *, boolean_t *); 265224169Sgibbsextern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, const char *); 266185029Spjd 267168404Spjd/* 268168404Spjd * Functions to manage pool properties 269168404Spjd */ 270168404Spjdextern int zpool_set_prop(zpool_handle_t *, const char *, const char *); 271185029Spjdextern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *, 272185029Spjd size_t proplen, zprop_source_t *); 273185029Spjdextern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t, 274185029Spjd zprop_source_t *); 275185029Spjd 276168404Spjdextern const char *zpool_prop_to_name(zpool_prop_t); 277168404Spjdextern const char *zpool_prop_values(zpool_prop_t); 278168404Spjd 279168404Spjd/* 280168404Spjd * Pool health statistics. 281168404Spjd */ 282168404Spjdtypedef enum { 283168404Spjd /* 284168404Spjd * The following correspond to faults as defined in the (fault.fs.zfs.*) 285168404Spjd * event namespace. Each is associated with a corresponding message ID. 286168404Spjd */ 287168404Spjd ZPOOL_STATUS_CORRUPT_CACHE, /* corrupt /kernel/drv/zpool.cache */ 288168404Spjd ZPOOL_STATUS_MISSING_DEV_R, /* missing device with replicas */ 289168404Spjd ZPOOL_STATUS_MISSING_DEV_NR, /* missing device with no replicas */ 290168404Spjd ZPOOL_STATUS_CORRUPT_LABEL_R, /* bad device label with replicas */ 291168404Spjd ZPOOL_STATUS_CORRUPT_LABEL_NR, /* bad device label with no replicas */ 292168404Spjd ZPOOL_STATUS_BAD_GUID_SUM, /* sum of device guids didn't match */ 293168404Spjd ZPOOL_STATUS_CORRUPT_POOL, /* pool metadata is corrupted */ 294168404Spjd ZPOOL_STATUS_CORRUPT_DATA, /* data errors in user (meta)data */ 295168404Spjd ZPOOL_STATUS_FAILING_DEV, /* device experiencing errors */ 296168404Spjd ZPOOL_STATUS_VERSION_NEWER, /* newer on-disk version */ 297168498Spjd ZPOOL_STATUS_HOSTID_MISMATCH, /* last accessed by another system */ 298185029Spjd ZPOOL_STATUS_IO_FAILURE_WAIT, /* failed I/O, failmode 'wait' */ 299185029Spjd ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */ 300209962Smm ZPOOL_STATUS_BAD_LOG, /* cannot read log chain(s) */ 301209962Smm 302209962Smm /* 303236884Smm * If the pool has unsupported features but can still be opened in 304236884Smm * read-only mode, its status is ZPOOL_STATUS_UNSUP_FEAT_WRITE. If the 305236884Smm * pool has unsupported features but cannot be opened at all, its 306236884Smm * status is ZPOOL_STATUS_UNSUP_FEAT_READ. 307236884Smm */ 308236884Smm ZPOOL_STATUS_UNSUP_FEAT_READ, /* unsupported features for read */ 309236884Smm ZPOOL_STATUS_UNSUP_FEAT_WRITE, /* unsupported features for write */ 310236884Smm 311236884Smm /* 312209962Smm * These faults have no corresponding message ID. At the time we are 313209962Smm * checking the status, the original reason for the FMA fault (I/O or 314209962Smm * checksum errors) has been lost. 315209962Smm */ 316185029Spjd ZPOOL_STATUS_FAULTED_DEV_R, /* faulted device with replicas */ 317185029Spjd ZPOOL_STATUS_FAULTED_DEV_NR, /* faulted device with no replicas */ 318168404Spjd 319168404Spjd /* 320168404Spjd * The following are not faults per se, but still an error possibly 321168404Spjd * requiring administrative attention. There is no corresponding 322168404Spjd * message ID. 323168404Spjd */ 324238926Smm ZPOOL_STATUS_VERSION_OLDER, /* older legacy on-disk version */ 325238926Smm ZPOOL_STATUS_FEAT_DISABLED, /* supported features are disabled */ 326168404Spjd ZPOOL_STATUS_RESILVERING, /* device being resilvered */ 327168404Spjd ZPOOL_STATUS_OFFLINE_DEV, /* device online */ 328219089Spjd ZPOOL_STATUS_REMOVED_DEV, /* removed device */ 329254591Sgibbs ZPOOL_STATUS_NON_NATIVE_ASHIFT, /* (e.g. 512e dev with ashift of 9) */ 330168404Spjd 331168404Spjd /* 332168404Spjd * Finally, the following indicates a healthy pool. 333168404Spjd */ 334168404Spjd ZPOOL_STATUS_OK 335168404Spjd} zpool_status_t; 336168404Spjd 337168404Spjdextern zpool_status_t zpool_get_status(zpool_handle_t *, char **); 338168404Spjdextern zpool_status_t zpool_import_status(nvlist_t *, char **); 339219089Spjdextern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh); 340168404Spjd 341168404Spjd/* 342168404Spjd * Statistics and configuration functions. 343168404Spjd */ 344168404Spjdextern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **); 345236884Smmextern nvlist_t *zpool_get_features(zpool_handle_t *); 346168404Spjdextern int zpool_refresh_stats(zpool_handle_t *, boolean_t *); 347168404Spjdextern int zpool_get_errlog(zpool_handle_t *, nvlist_t **); 348168404Spjd 349168404Spjd/* 350168404Spjd * Import and export functions 351168404Spjd */ 352248571Smmextern int zpool_export(zpool_handle_t *, boolean_t, const char *); 353248571Smmextern int zpool_export_force(zpool_handle_t *, const char *); 354168404Spjdextern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *, 355185029Spjd char *altroot); 356185029Spjdextern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *, 357219089Spjd nvlist_t *, int); 358236884Smmextern void zpool_print_unsup_feat(nvlist_t *config); 359168404Spjd 360168404Spjd/* 361168404Spjd * Search for pools to import 362168404Spjd */ 363219089Spjd 364219089Spjdtypedef struct importargs { 365219089Spjd char **path; /* a list of paths to search */ 366219089Spjd int paths; /* number of paths to search */ 367219089Spjd char *poolname; /* name of a pool to find */ 368219089Spjd uint64_t guid; /* guid of a pool to find */ 369219089Spjd char *cachefile; /* cachefile to use for import */ 370219089Spjd int can_be_active : 1; /* can the pool be active? */ 371219089Spjd int unique : 1; /* does 'poolname' already exist? */ 372219089Spjd int exists : 1; /* set on return if pool already exists */ 373219089Spjd} importargs_t; 374219089Spjd 375219089Spjdextern nvlist_t *zpool_search_import(libzfs_handle_t *, importargs_t *); 376219089Spjd 377219089Spjd/* legacy pool search routines */ 378168404Spjdextern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **); 379185029Spjdextern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *, 380185029Spjd char *, uint64_t); 381168404Spjd 382168404Spjd/* 383168404Spjd * Miscellaneous pool functions 384168404Spjd */ 385185029Spjdstruct zfs_cmd; 386185029Spjd 387248571Smmextern const char *zfs_history_event_names[]; 388219089Spjd 389219089Spjdextern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *, 390219089Spjd boolean_t verbose); 391185029Spjdextern int zpool_upgrade(zpool_handle_t *, uint64_t); 392168404Spjdextern int zpool_get_history(zpool_handle_t *, nvlist_t **); 393219089Spjdextern int zpool_history_unpack(char *, uint64_t, uint64_t *, 394219089Spjd nvlist_t ***, uint_t *); 395168404Spjdextern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *, 396168404Spjd size_t len); 397248571Smmextern int zfs_ioctl(libzfs_handle_t *, int request, struct zfs_cmd *); 398219089Spjdextern int zpool_get_physpath(zpool_handle_t *, char *, size_t); 399219089Spjdextern void zpool_explain_recover(libzfs_handle_t *, const char *, int, 400219089Spjd nvlist_t *); 401219089Spjd 402168404Spjd/* 403168404Spjd * Basic handle manipulations. These functions do not create or destroy the 404168404Spjd * underlying datasets, only the references to them. 405168404Spjd */ 406168404Spjdextern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int); 407228103Smmextern zfs_handle_t *zfs_handle_dup(zfs_handle_t *); 408168404Spjdextern void zfs_close(zfs_handle_t *); 409168404Spjdextern zfs_type_t zfs_get_type(const zfs_handle_t *); 410168404Spjdextern const char *zfs_get_name(const zfs_handle_t *); 411185029Spjdextern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *); 412168404Spjd 413168404Spjd/* 414168404Spjd * Property management functions. Some functions are shared with the kernel, 415168404Spjd * and are found in sys/fs/zfs.h. 416168404Spjd */ 417185029Spjd 418185029Spjd/* 419185029Spjd * zfs dataset property management 420185029Spjd */ 421185029Spjdextern const char *zfs_prop_default_string(zfs_prop_t); 422185029Spjdextern uint64_t zfs_prop_default_numeric(zfs_prop_t); 423185029Spjdextern const char *zfs_prop_column_name(zfs_prop_t); 424185029Spjdextern boolean_t zfs_prop_align_right(zfs_prop_t); 425185029Spjd 426185029Spjdextern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t, 427185029Spjd nvlist_t *, uint64_t, zfs_handle_t *, const char *); 428185029Spjd 429168404Spjdextern const char *zfs_prop_to_name(zfs_prop_t); 430168404Spjdextern int zfs_prop_set(zfs_handle_t *, const char *, const char *); 431168404Spjdextern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t, 432185029Spjd zprop_source_t *, char *, size_t, boolean_t); 433219089Spjdextern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t, 434219089Spjd boolean_t); 435168404Spjdextern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *, 436185029Spjd zprop_source_t *, char *, size_t); 437209962Smmextern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname, 438209962Smm uint64_t *propvalue); 439209962Smmextern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname, 440209962Smm char *propbuf, int proplen, boolean_t literal); 441228103Smmextern int zfs_prop_get_written_int(zfs_handle_t *zhp, const char *propname, 442228103Smm uint64_t *propvalue); 443228103Smmextern int zfs_prop_get_written(zfs_handle_t *zhp, const char *propname, 444228103Smm char *propbuf, int proplen, boolean_t literal); 445236884Smmextern int zfs_prop_get_feature(zfs_handle_t *zhp, const char *propname, 446236884Smm char *buf, size_t len); 447168404Spjdextern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t); 448219089Spjdextern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t); 449168404Spjdextern const char *zfs_prop_values(zfs_prop_t); 450168404Spjdextern int zfs_prop_is_string(zfs_prop_t prop); 451185029Spjdextern nvlist_t *zfs_get_user_props(zfs_handle_t *); 452219089Spjdextern nvlist_t *zfs_get_recvd_props(zfs_handle_t *); 453228103Smmextern nvlist_t *zfs_get_clones_nvl(zfs_handle_t *); 454168404Spjd 455228103Smm 456185029Spjdtypedef struct zprop_list { 457185029Spjd int pl_prop; 458168404Spjd char *pl_user_prop; 459185029Spjd struct zprop_list *pl_next; 460168404Spjd boolean_t pl_all; 461168404Spjd size_t pl_width; 462219089Spjd size_t pl_recvd_width; 463168404Spjd boolean_t pl_fixed; 464185029Spjd} zprop_list_t; 465168404Spjd 466219089Spjdextern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t); 467205198Sdelphijextern void zfs_prune_proplist(zfs_handle_t *, uint8_t *); 468168404Spjd 469168404Spjd#define ZFS_MOUNTPOINT_NONE "none" 470168404Spjd#define ZFS_MOUNTPOINT_LEGACY "legacy" 471168404Spjd 472236884Smm#define ZFS_FEATURE_DISABLED "disabled" 473236884Smm#define ZFS_FEATURE_ENABLED "enabled" 474236884Smm#define ZFS_FEATURE_ACTIVE "active" 475236884Smm 476236884Smm#define ZFS_UNSUPPORTED_INACTIVE "inactive" 477236884Smm#define ZFS_UNSUPPORTED_READONLY "readonly" 478236884Smm 479168404Spjd/* 480185029Spjd * zpool property management 481168404Spjd */ 482185029Spjdextern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **); 483236884Smmextern int zpool_prop_get_feature(zpool_handle_t *, const char *, char *, 484236884Smm size_t); 485185029Spjdextern const char *zpool_prop_default_string(zpool_prop_t); 486185029Spjdextern uint64_t zpool_prop_default_numeric(zpool_prop_t); 487185029Spjdextern const char *zpool_prop_column_name(zpool_prop_t); 488185029Spjdextern boolean_t zpool_prop_align_right(zpool_prop_t); 489185029Spjd 490185029Spjd/* 491185029Spjd * Functions shared by zfs and zpool property management. 492185029Spjd */ 493185029Spjdextern int zprop_iter(zprop_func func, void *cb, boolean_t show_all, 494185029Spjd boolean_t ordered, zfs_type_t type); 495185029Spjdextern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **, 496185029Spjd zfs_type_t); 497185029Spjdextern void zprop_free_list(zprop_list_t *); 498185029Spjd 499219089Spjd#define ZFS_GET_NCOLS 5 500219089Spjd 501219089Spjdtypedef enum { 502219089Spjd GET_COL_NONE, 503219089Spjd GET_COL_NAME, 504219089Spjd GET_COL_PROPERTY, 505219089Spjd GET_COL_VALUE, 506219089Spjd GET_COL_RECVD, 507219089Spjd GET_COL_SOURCE 508219089Spjd} zfs_get_column_t; 509219089Spjd 510185029Spjd/* 511185029Spjd * Functions for printing zfs or zpool properties 512185029Spjd */ 513185029Spjdtypedef struct zprop_get_cbdata { 514168404Spjd int cb_sources; 515219089Spjd zfs_get_column_t cb_columns[ZFS_GET_NCOLS]; 516219089Spjd int cb_colwidths[ZFS_GET_NCOLS + 1]; 517168404Spjd boolean_t cb_scripted; 518168404Spjd boolean_t cb_literal; 519168404Spjd boolean_t cb_first; 520185029Spjd zprop_list_t *cb_proplist; 521185029Spjd zfs_type_t cb_type; 522185029Spjd} zprop_get_cbdata_t; 523168404Spjd 524185029Spjdvoid zprop_print_one_property(const char *, zprop_get_cbdata_t *, 525219089Spjd const char *, const char *, zprop_source_t, const char *, 526219089Spjd const char *); 527168404Spjd 528168404Spjd/* 529168404Spjd * Iterator functions. 530168404Spjd */ 531168404Spjdtypedef int (*zfs_iter_f)(zfs_handle_t *, void *); 532168404Spjdextern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *); 533168404Spjdextern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *); 534168404Spjdextern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *); 535168404Spjdextern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *); 536230438Spjdextern int zfs_iter_snapshots(zfs_handle_t *, boolean_t, zfs_iter_f, void *); 537219089Spjdextern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *); 538228103Smmextern int zfs_iter_snapspec(zfs_handle_t *, const char *, zfs_iter_f, void *); 539168404Spjd 540219089Spjdtypedef struct get_all_cb { 541219089Spjd zfs_handle_t **cb_handles; 542219089Spjd size_t cb_alloc; 543219089Spjd size_t cb_used; 544219089Spjd boolean_t cb_verbose; 545219089Spjd int (*cb_getone)(zfs_handle_t *, void *); 546219089Spjd} get_all_cb_t; 547219089Spjd 548219089Spjdvoid libzfs_add_handle(get_all_cb_t *, zfs_handle_t *); 549219089Spjdint libzfs_dataset_cmp(const void *, const void *); 550219089Spjd 551168404Spjd/* 552168404Spjd * Functions to create and destroy datasets. 553168404Spjd */ 554168404Spjdextern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t, 555168404Spjd nvlist_t *); 556185029Spjdextern int zfs_create_ancestors(libzfs_handle_t *, const char *); 557219089Spjdextern int zfs_destroy(zfs_handle_t *, boolean_t); 558219089Spjdextern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t); 559248571Smmextern int zfs_destroy_snaps_nvl(libzfs_handle_t *, nvlist_t *, boolean_t); 560168404Spjdextern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *); 561185029Spjdextern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *); 562248571Smmextern int zfs_snapshot_nvl(libzfs_handle_t *hdl, nvlist_t *snaps, 563248571Smm nvlist_t *props); 564185029Spjdextern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t); 565219089Spjd 566226705Spjdtypedef struct renameflags { 567226705Spjd /* recursive rename */ 568226705Spjd int recurse : 1; 569226705Spjd 570226705Spjd /* don't unmount file systems */ 571226705Spjd int nounmount : 1; 572235216Smm 573235216Smm /* force unmount file systems */ 574235216Smm int forceunmount : 1; 575226705Spjd} renameflags_t; 576226705Spjd 577240870Spjdextern int zfs_rename(zfs_handle_t *, const char *, const char *, 578240870Spjd renameflags_t flags); 579226705Spjd 580219089Spjdtypedef struct sendflags { 581219089Spjd /* print informational messages (ie, -v was specified) */ 582228103Smm boolean_t verbose; 583219089Spjd 584219089Spjd /* recursive send (ie, -R) */ 585228103Smm boolean_t replicate; 586219089Spjd 587219089Spjd /* for incrementals, do all intermediate snapshots */ 588228103Smm boolean_t doall; 589219089Spjd 590219089Spjd /* if dataset is a clone, do incremental from its origin */ 591228103Smm boolean_t fromorigin; 592219089Spjd 593219089Spjd /* do deduplication */ 594228103Smm boolean_t dedup; 595219089Spjd 596219089Spjd /* send properties (ie, -p) */ 597228103Smm boolean_t props; 598228103Smm 599228103Smm /* do not send (no-op, ie. -n) */ 600228103Smm boolean_t dryrun; 601228103Smm 602228103Smm /* parsable verbose output (ie. -P) */ 603228103Smm boolean_t parsable; 604235222Smm 605235222Smm /* show progress (ie. -v) */ 606235222Smm boolean_t progress; 607219089Spjd} sendflags_t; 608219089Spjd 609219089Spjdtypedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *); 610219089Spjd 611228103Smmextern int zfs_send(zfs_handle_t *, const char *, const char *, 612228103Smm sendflags_t *, int, snapfilter_cb_t, void *, nvlist_t **); 613219089Spjd 614168404Spjdextern int zfs_promote(zfs_handle_t *); 615248571Smmextern int zfs_hold(zfs_handle_t *, const char *, const char *, 616251646Sdelphij boolean_t, int); 617251646Sdelphijextern int zfs_hold_nvl(zfs_handle_t *, int, nvlist_t *); 618219089Spjdextern int zfs_release(zfs_handle_t *, const char *, const char *, boolean_t); 619219089Spjdextern int zfs_get_holds(zfs_handle_t *, nvlist_t **); 620219089Spjdextern uint64_t zvol_volsize_to_reservation(uint64_t, nvlist_t *); 621168404Spjd 622209962Smmtypedef int (*zfs_userspace_cb_t)(void *arg, const char *domain, 623209962Smm uid_t rid, uint64_t space); 624209962Smm 625219089Spjdextern int zfs_userspace(zfs_handle_t *, zfs_userquota_prop_t, 626219089Spjd zfs_userspace_cb_t, void *); 627209962Smm 628219089Spjdextern int zfs_get_fsacl(zfs_handle_t *, nvlist_t **); 629219089Spjdextern int zfs_set_fsacl(zfs_handle_t *, boolean_t, nvlist_t *); 630219089Spjd 631185029Spjdtypedef struct recvflags { 632185029Spjd /* print informational messages (ie, -v was specified) */ 633228103Smm boolean_t verbose; 634185029Spjd 635185029Spjd /* the destination is a prefix, not the exact fs (ie, -d) */ 636228103Smm boolean_t isprefix; 637185029Spjd 638219089Spjd /* 639219089Spjd * Only the tail of the sent snapshot path is appended to the 640219089Spjd * destination to determine the received snapshot name (ie, -e). 641219089Spjd */ 642228103Smm boolean_t istail; 643219089Spjd 644185029Spjd /* do not actually do the recv, just check if it would work (ie, -n) */ 645228103Smm boolean_t dryrun; 646185029Spjd 647185029Spjd /* rollback/destroy filesystems as necessary (eg, -F) */ 648228103Smm boolean_t force; 649185029Spjd 650185029Spjd /* set "canmount=off" on all modified filesystems */ 651228103Smm boolean_t canmountoff; 652185029Spjd 653185029Spjd /* byteswap flag is used internally; callers need not specify */ 654228103Smm boolean_t byteswap; 655200516Sdelphij 656200516Sdelphij /* do not mount file systems as they are extracted (private) */ 657228103Smm boolean_t nomount; 658185029Spjd} recvflags_t; 659185029Spjd 660228103Smmextern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t *, 661185029Spjd int, avl_tree_t *); 662185029Spjd 663219089Spjdtypedef enum diff_flags { 664219089Spjd ZFS_DIFF_PARSEABLE = 0x1, 665219089Spjd ZFS_DIFF_TIMESTAMP = 0x2, 666219089Spjd ZFS_DIFF_CLASSIFY = 0x4 667219089Spjd} diff_flags_t; 668219089Spjd 669219089Spjdextern int zfs_show_diffs(zfs_handle_t *, int, const char *, const char *, 670219089Spjd int); 671219089Spjd 672168404Spjd/* 673168404Spjd * Miscellaneous functions. 674168404Spjd */ 675168404Spjdextern const char *zfs_type_to_name(zfs_type_t); 676168404Spjdextern void zfs_refresh_properties(zfs_handle_t *); 677168404Spjdextern int zfs_name_valid(const char *, zfs_type_t); 678168404Spjdextern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t); 679185029Spjdextern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *, 680185029Spjd zfs_type_t); 681185029Spjdextern int zfs_spa_version(zfs_handle_t *, int *); 682168404Spjd 683168404Spjd/* 684168404Spjd * Mount support functions. 685168404Spjd */ 686168404Spjdextern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **); 687168404Spjdextern boolean_t zfs_is_mounted(zfs_handle_t *, char **); 688168404Spjdextern int zfs_mount(zfs_handle_t *, const char *, int); 689168404Spjdextern int zfs_unmount(zfs_handle_t *, const char *, int); 690168404Spjdextern int zfs_unmountall(zfs_handle_t *, int); 691168404Spjd 692168404Spjd/* 693168404Spjd * Share support functions. 694168404Spjd */ 695168404Spjdextern boolean_t zfs_is_shared(zfs_handle_t *); 696168404Spjdextern int zfs_share(zfs_handle_t *); 697168404Spjdextern int zfs_unshare(zfs_handle_t *); 698168404Spjd 699168404Spjd/* 700185029Spjd * Protocol-specific share support functions. 701168404Spjd */ 702168404Spjdextern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **); 703185029Spjdextern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **); 704168404Spjdextern int zfs_share_nfs(zfs_handle_t *); 705185029Spjdextern int zfs_share_smb(zfs_handle_t *); 706185029Spjdextern int zfs_shareall(zfs_handle_t *); 707168404Spjdextern int zfs_unshare_nfs(zfs_handle_t *, const char *); 708185029Spjdextern int zfs_unshare_smb(zfs_handle_t *, const char *); 709168404Spjdextern int zfs_unshareall_nfs(zfs_handle_t *); 710185029Spjdextern int zfs_unshareall_smb(zfs_handle_t *); 711185029Spjdextern int zfs_unshareall_bypath(zfs_handle_t *, const char *); 712185029Spjdextern int zfs_unshareall(zfs_handle_t *); 713209962Smmextern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *, 714185029Spjd void *, void *, int, zfs_share_op_t); 715168404Spjd 716168404Spjd/* 717168404Spjd * FreeBSD-specific jail support function. 718168404Spjd */ 719168404Spjdextern int zfs_jail(zfs_handle_t *, int, int); 720168404Spjd 721168404Spjd/* 722168404Spjd * When dealing with nvlists, verify() is extremely useful 723168404Spjd */ 724168404Spjd#ifndef verify 725168404Spjd#ifdef NDEBUG 726168404Spjd#define verify(EX) ((void)(EX)) 727168404Spjd#else 728168404Spjd#define verify(EX) assert(EX) 729168404Spjd#endif 730168404Spjd#endif 731168404Spjd 732168404Spjd/* 733168404Spjd * Utility function to convert a number to a human-readable form. 734168404Spjd */ 735168404Spjdextern void zfs_nicenum(uint64_t, char *, size_t); 736168404Spjdextern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *); 737168404Spjd 738168404Spjd/* 739168404Spjd * Given a device or file, determine if it is part of a pool. 740168404Spjd */ 741168404Spjdextern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **, 742168404Spjd boolean_t *); 743168404Spjd 744168404Spjd/* 745219089Spjd * Label manipulation. 746168404Spjd */ 747168404Spjdextern int zpool_read_label(int, nvlist_t **); 748219089Spjdextern int zpool_clear_label(int); 749168404Spjd 750185029Spjd/* is this zvol valid for use as a dump device? */ 751185029Spjdextern int zvol_check_dump_config(char *); 752185029Spjd 753168404Spjd/* 754209962Smm * Management interfaces for SMB ACL files 755209962Smm */ 756209962Smm 757209962Smmint zfs_smb_acl_add(libzfs_handle_t *, char *, char *, char *); 758209962Smmint zfs_smb_acl_remove(libzfs_handle_t *, char *, char *, char *); 759209962Smmint zfs_smb_acl_purge(libzfs_handle_t *, char *, char *); 760209962Smmint zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *); 761209962Smm 762209962Smm/* 763168404Spjd * Enable and disable datasets within a pool by mounting/unmounting and 764168404Spjd * sharing/unsharing them. 765168404Spjd */ 766168404Spjdextern int zpool_enable_datasets(zpool_handle_t *, const char *, int); 767168404Spjdextern int zpool_disable_datasets(zpool_handle_t *, boolean_t); 768168404Spjd 769219089Spjd/* 770219089Spjd * Mappings between vdev and FRU. 771219089Spjd */ 772219089Spjdextern void libzfs_fru_refresh(libzfs_handle_t *); 773219089Spjdextern const char *libzfs_fru_lookup(libzfs_handle_t *, const char *); 774219089Spjdextern const char *libzfs_fru_devpath(libzfs_handle_t *, const char *); 775219089Spjdextern boolean_t libzfs_fru_compare(libzfs_handle_t *, const char *, 776219089Spjd const char *); 777219089Spjdextern boolean_t libzfs_fru_notself(libzfs_handle_t *, const char *); 778219089Spjdextern int zpool_fru_set(zpool_handle_t *, uint64_t, const char *); 779219089Spjd 780219089Spjd#ifndef sun 781168404Spjdextern int zmount(const char *, const char *, int, char *, char *, int, char *, 782168404Spjd int); 783219089Spjd#endif /* !sun */ 784168404Spjd 785168404Spjd#ifdef __cplusplus 786168404Spjd} 787168404Spjd#endif 788168404Spjd 789168404Spjd#endif /* _LIBZFS_H */ 790