1789Sahrens /* 2789Sahrens * CDDL HEADER START 3789Sahrens * 4789Sahrens * The contents of this file are subject to the terms of the 51485Slling * Common Development and Distribution License (the "License"). 61485Slling * You may not use this file except in compliance with the License. 7789Sahrens * 8789Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9789Sahrens * or http://www.opensolaris.org/os/licensing. 10789Sahrens * See the License for the specific language governing permissions 11789Sahrens * and limitations under the License. 12789Sahrens * 13789Sahrens * When distributing Covered Code, include this CDDL HEADER in each 14789Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15789Sahrens * If applicable, add the following below this CDDL HEADER, with the 16789Sahrens * fields enclosed by brackets "[]" replaced with your own identifying 17789Sahrens * information: Portions Copyright [yyyy] [name of copyright owner] 18789Sahrens * 19789Sahrens * CDDL HEADER END 20789Sahrens */ 213126Sahl 22789Sahrens /* 2312296SLin.Ling@Sun.COM * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 24789Sahrens */ 25789Sahrens 26789Sahrens #ifndef _LIBZFS_H 27789Sahrens #define _LIBZFS_H 28789Sahrens 29789Sahrens #include <assert.h> 30789Sahrens #include <libnvpair.h> 318228SEric.Taylor@Sun.COM #include <sys/mnttab.h> 32789Sahrens #include <sys/param.h> 33789Sahrens #include <sys/types.h> 34789Sahrens #include <sys/varargs.h> 35789Sahrens #include <sys/fs/zfs.h> 364543Smarks #include <sys/avl.h> 374543Smarks #include <ucred.h> 38789Sahrens 39789Sahrens #ifdef __cplusplus 40789Sahrens extern "C" { 41789Sahrens #endif 42789Sahrens 43789Sahrens /* 44789Sahrens * Miscellaneous ZFS constants 45789Sahrens */ 46789Sahrens #define ZFS_MAXNAMELEN MAXNAMELEN 47789Sahrens #define ZPOOL_MAXNAMELEN MAXNAMELEN 48789Sahrens #define ZFS_MAXPROPLEN MAXPATHLEN 495094Slling #define ZPOOL_MAXPROPLEN MAXPATHLEN 50789Sahrens 51789Sahrens /* 522082Seschrock * libzfs errors 532082Seschrock */ 542082Seschrock enum { 552082Seschrock EZFS_NOMEM = 2000, /* out of memory */ 562082Seschrock EZFS_BADPROP, /* invalid property value */ 572082Seschrock EZFS_PROPREADONLY, /* cannot set readonly property */ 582082Seschrock EZFS_PROPTYPE, /* property does not apply to dataset type */ 592082Seschrock EZFS_PROPNONINHERIT, /* property is not inheritable */ 602082Seschrock EZFS_PROPSPACE, /* bad quota or reservation */ 612082Seschrock EZFS_BADTYPE, /* dataset is not of appropriate type */ 622082Seschrock EZFS_BUSY, /* pool or dataset is busy */ 632082Seschrock EZFS_EXISTS, /* pool or dataset already exists */ 642082Seschrock EZFS_NOENT, /* no such pool or dataset */ 652082Seschrock EZFS_BADSTREAM, /* bad backup stream */ 662082Seschrock EZFS_DSREADONLY, /* dataset is readonly */ 672082Seschrock EZFS_VOLTOOBIG, /* volume is too large for 32-bit system */ 682082Seschrock EZFS_INVALIDNAME, /* invalid dataset name */ 692082Seschrock EZFS_BADRESTORE, /* unable to restore to destination */ 702082Seschrock EZFS_BADBACKUP, /* backup failed */ 712082Seschrock EZFS_BADTARGET, /* bad attach/detach/replace target */ 722082Seschrock EZFS_NODEVICE, /* no such device in pool */ 732082Seschrock EZFS_BADDEV, /* invalid device to add */ 742082Seschrock EZFS_NOREPLICAS, /* no valid replicas */ 752082Seschrock EZFS_RESILVERING, /* currently resilvering */ 762082Seschrock EZFS_BADVERSION, /* unsupported version */ 772082Seschrock EZFS_POOLUNAVAIL, /* pool is currently unavailable */ 782082Seschrock EZFS_DEVOVERFLOW, /* too many devices in one vdev */ 792082Seschrock EZFS_BADPATH, /* must be an absolute path */ 802082Seschrock EZFS_CROSSTARGET, /* rename or clone across pool or dataset */ 812082Seschrock EZFS_ZONED, /* used improperly in local zone */ 822082Seschrock EZFS_MOUNTFAILED, /* failed to mount dataset */ 832082Seschrock EZFS_UMOUNTFAILED, /* failed to unmount dataset */ 843126Sahl EZFS_UNSHARENFSFAILED, /* unshare(1M) failed */ 853126Sahl EZFS_SHARENFSFAILED, /* share(1M) failed */ 862082Seschrock EZFS_PERM, /* permission denied */ 872082Seschrock EZFS_NOSPC, /* out of space */ 8811807SSam.Falkner@Sun.COM EZFS_FAULT, /* bad address */ 892082Seschrock EZFS_IO, /* I/O error */ 902082Seschrock EZFS_INTR, /* signal received */ 912082Seschrock EZFS_ISSPARE, /* device is a hot spare */ 922082Seschrock EZFS_INVALCONFIG, /* invalid vdev configuration */ 932474Seschrock EZFS_RECURSIVE, /* recursive dependency */ 942926Sek110237 EZFS_NOHISTORY, /* no history object */ 953912Slling EZFS_POOLPROPS, /* couldn't retrieve pool props */ 963912Slling EZFS_POOL_NOTSUP, /* ops not supported for this type of pool */ 973912Slling EZFS_POOL_INVALARG, /* invalid argument for this pool operation */ 983978Smmusante EZFS_NAMETOOLONG, /* dataset name is too long */ 994276Staylor EZFS_OPENFAILED, /* open of device failed */ 1004276Staylor EZFS_NOCAP, /* couldn't get capacity */ 1014276Staylor EZFS_LABELFAILED, /* write of label failed */ 1024543Smarks EZFS_BADWHO, /* invalid permission who */ 1034543Smarks EZFS_BADPERM, /* invalid permission */ 1044543Smarks EZFS_BADPERMSET, /* invalid permission set name */ 1054543Smarks EZFS_NODELEGATION, /* delegated administration is disabled */ 1064543Smarks EZFS_PERMRDONLY, /* pemissions are readonly */ 1075331Samw EZFS_UNSHARESMBFAILED, /* failed to unshare over smb */ 1085331Samw EZFS_SHARESMBFAILED, /* failed to share over smb */ 1095363Seschrock EZFS_BADCACHE, /* bad cache file */ 1105450Sbrendan EZFS_ISL2CACHE, /* device is for the level 2 ARC */ 1116423Sgw25295 EZFS_VDEVNOTSUP, /* unsupported vdev type */ 1127042Sgw25295 EZFS_NOTSUP, /* ops not supported on this dataset */ 1137214Slling EZFS_ACTIVE_SPARE, /* pool has active shared spare devices */ 1149701SGeorge.Wilson@Sun.COM EZFS_UNPLAYED_LOGS, /* log device has unplayed logs */ 11510242Schris.kirby@sun.com EZFS_REFTAG_RELE, /* snapshot release: tag not found */ 11610242Schris.kirby@sun.com EZFS_REFTAG_HOLD, /* snapshot hold: tag already exists */ 11710342Schris.kirby@sun.com EZFS_TAGTOOLONG, /* snapshot hold/rele: tag too long */ 11811007SLori.Alt@Sun.COM EZFS_PIPEFAILED, /* pipe create failed */ 11911007SLori.Alt@Sun.COM EZFS_THREADCREATEFAILED, /* thread create failed */ 12011422SMark.Musante@Sun.COM EZFS_POSTSPLIT_ONLINE, /* onlining a disk after splitting it */ 12112296SLin.Ling@Sun.COM EZFS_SCRUBBING, /* currently scrubbing */ 12212296SLin.Ling@Sun.COM EZFS_NO_SCRUB, /* no active scrub */ 1233912Slling EZFS_UNKNOWN 1242082Seschrock }; 1252082Seschrock 1262082Seschrock /* 1274543Smarks * The following data structures are all part 1284543Smarks * of the zfs_allow_t data structure which is 1294543Smarks * used for printing 'allow' permissions. 1304543Smarks * It is a linked list of zfs_allow_t's which 1314543Smarks * then contain avl tree's for user/group/sets/... 1324543Smarks * and each one of the entries in those trees have 1334543Smarks * avl tree's for the permissions they belong to and 1344543Smarks * whether they are local,descendent or local+descendent 1354543Smarks * permissions. The AVL trees are used primarily for 1364543Smarks * sorting purposes, but also so that we can quickly find 1374543Smarks * a given user and or permission. 1384543Smarks */ 1394543Smarks typedef struct zfs_perm_node { 1404543Smarks avl_node_t z_node; 1414543Smarks char z_pname[MAXPATHLEN]; 1424543Smarks } zfs_perm_node_t; 1434543Smarks 1444543Smarks typedef struct zfs_allow_node { 1454543Smarks avl_node_t z_node; 1464543Smarks char z_key[MAXPATHLEN]; /* name, such as joe */ 1474543Smarks avl_tree_t z_localdescend; /* local+descendent perms */ 1484543Smarks avl_tree_t z_local; /* local permissions */ 1494543Smarks avl_tree_t z_descend; /* descendent permissions */ 1504543Smarks } zfs_allow_node_t; 1514543Smarks 1524543Smarks typedef struct zfs_allow { 1534543Smarks struct zfs_allow *z_next; 1544543Smarks char z_setpoint[MAXPATHLEN]; 1554543Smarks avl_tree_t z_sets; 1564543Smarks avl_tree_t z_crperms; 1574543Smarks avl_tree_t z_user; 1584543Smarks avl_tree_t z_group; 1594543Smarks avl_tree_t z_everyone; 1604543Smarks } zfs_allow_t; 1614543Smarks 1624543Smarks /* 163789Sahrens * Basic handle types 164789Sahrens */ 165789Sahrens typedef struct zfs_handle zfs_handle_t; 166789Sahrens typedef struct zpool_handle zpool_handle_t; 1672082Seschrock typedef struct libzfs_handle libzfs_handle_t; 1682082Seschrock 1692082Seschrock /* 1702082Seschrock * Library initialization 1712082Seschrock */ 1722082Seschrock extern libzfs_handle_t *libzfs_init(void); 1732082Seschrock extern void libzfs_fini(libzfs_handle_t *); 1742082Seschrock 1752082Seschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *); 1762082Seschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *); 1772082Seschrock 1782082Seschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t); 1792082Seschrock 1802082Seschrock extern int libzfs_errno(libzfs_handle_t *); 1812082Seschrock extern const char *libzfs_error_action(libzfs_handle_t *); 1822082Seschrock extern const char *libzfs_error_description(libzfs_handle_t *); 1838228SEric.Taylor@Sun.COM extern void libzfs_mnttab_init(libzfs_handle_t *); 1848228SEric.Taylor@Sun.COM extern void libzfs_mnttab_fini(libzfs_handle_t *); 1858811SEric.Taylor@Sun.COM extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t); 1868228SEric.Taylor@Sun.COM extern int libzfs_mnttab_find(libzfs_handle_t *, const char *, 1878228SEric.Taylor@Sun.COM struct mnttab *); 1888228SEric.Taylor@Sun.COM extern void libzfs_mnttab_add(libzfs_handle_t *, const char *, 1898228SEric.Taylor@Sun.COM const char *, const char *); 1908228SEric.Taylor@Sun.COM extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *); 191789Sahrens 192789Sahrens /* 193789Sahrens * Basic handle functions 194789Sahrens */ 1952082Seschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *); 1962082Seschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *); 197789Sahrens extern void zpool_close(zpool_handle_t *); 198789Sahrens extern const char *zpool_get_name(zpool_handle_t *); 199789Sahrens extern int zpool_get_state(zpool_handle_t *); 2005094Slling extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t); 2016865Srm160521 extern void zpool_free_handles(libzfs_handle_t *); 202789Sahrens 203789Sahrens /* 204789Sahrens * Iterate over all active pools in the system. 205789Sahrens */ 206789Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *); 2072082Seschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *); 208789Sahrens 209789Sahrens /* 210789Sahrens * Functions to create and destroy pools 211789Sahrens */ 2122082Seschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *, 2137184Stimh nvlist_t *, nvlist_t *); 214789Sahrens extern int zpool_destroy(zpool_handle_t *); 215789Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *); 216789Sahrens 21711422SMark.Musante@Sun.COM typedef struct splitflags { 21811422SMark.Musante@Sun.COM /* do not split, but return the config that would be split off */ 21911422SMark.Musante@Sun.COM int dryrun : 1; 22011422SMark.Musante@Sun.COM 22111422SMark.Musante@Sun.COM /* after splitting, import the pool */ 22211422SMark.Musante@Sun.COM int import : 1; 22311422SMark.Musante@Sun.COM } splitflags_t; 22411422SMark.Musante@Sun.COM 225789Sahrens /* 226789Sahrens * Functions to manipulate pool and vdev state 227789Sahrens */ 22812296SLin.Ling@Sun.COM extern int zpool_scan(zpool_handle_t *, pool_scan_func_t); 22910921STim.Haley@Sun.COM extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *); 230789Sahrens 2314451Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int, 2324451Seschrock vdev_state_t *); 2334451Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t); 2344451Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *, 2354451Seschrock const char *, nvlist_t *, int); 236789Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *); 2372082Seschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *); 23811422SMark.Musante@Sun.COM extern int zpool_vdev_split(zpool_handle_t *, char *, nvlist_t **, nvlist_t *, 23911422SMark.Musante@Sun.COM splitflags_t); 2404451Seschrock 24110817SEric.Schrock@Sun.COM extern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t); 24210817SEric.Schrock@Sun.COM extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t); 2434451Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t); 2444451Seschrock 2455450Sbrendan extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *, 2467326SEric.Schrock@Sun.COM boolean_t *, boolean_t *); 2479816SGeorge.Wilson@Sun.COM extern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *, 2489816SGeorge.Wilson@Sun.COM boolean_t *, boolean_t *, boolean_t *); 2494276Staylor extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *); 250789Sahrens 251789Sahrens /* 2523912Slling * Functions to manage pool properties 2533912Slling */ 2543912Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *); 2554451Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *, 2565094Slling size_t proplen, zprop_source_t *); 2575094Slling extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t, 2585094Slling zprop_source_t *); 2595094Slling 2603912Slling extern const char *zpool_prop_to_name(zpool_prop_t); 2613912Slling extern const char *zpool_prop_values(zpool_prop_t); 2623912Slling 2633912Slling /* 264789Sahrens * Pool health statistics. 265789Sahrens */ 266789Sahrens typedef enum { 267789Sahrens /* 268789Sahrens * The following correspond to faults as defined in the (fault.fs.zfs.*) 2691003Slling * event namespace. Each is associated with a corresponding message ID. 270789Sahrens */ 271789Sahrens ZPOOL_STATUS_CORRUPT_CACHE, /* corrupt /kernel/drv/zpool.cache */ 272789Sahrens ZPOOL_STATUS_MISSING_DEV_R, /* missing device with replicas */ 273789Sahrens ZPOOL_STATUS_MISSING_DEV_NR, /* missing device with no replicas */ 274789Sahrens ZPOOL_STATUS_CORRUPT_LABEL_R, /* bad device label with replicas */ 2751003Slling ZPOOL_STATUS_CORRUPT_LABEL_NR, /* bad device label with no replicas */ 276789Sahrens ZPOOL_STATUS_BAD_GUID_SUM, /* sum of device guids didn't match */ 277789Sahrens ZPOOL_STATUS_CORRUPT_POOL, /* pool metadata is corrupted */ 278789Sahrens ZPOOL_STATUS_CORRUPT_DATA, /* data errors in user (meta)data */ 279789Sahrens ZPOOL_STATUS_FAILING_DEV, /* device experiencing errors */ 2801760Seschrock ZPOOL_STATUS_VERSION_NEWER, /* newer on-disk version */ 2813975Sek110237 ZPOOL_STATUS_HOSTID_MISMATCH, /* last accessed by another system */ 2826523Sek110237 ZPOOL_STATUS_IO_FAILURE_WAIT, /* failed I/O, failmode 'wait' */ 2836523Sek110237 ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */ 2848343SEric.Schrock@Sun.COM ZPOOL_STATUS_BAD_LOG, /* cannot read log chain(s) */ 2858343SEric.Schrock@Sun.COM 2868343SEric.Schrock@Sun.COM /* 2878343SEric.Schrock@Sun.COM * These faults have no corresponding message ID. At the time we are 2888343SEric.Schrock@Sun.COM * checking the status, the original reason for the FMA fault (I/O or 2898343SEric.Schrock@Sun.COM * checksum errors) has been lost. 2908343SEric.Schrock@Sun.COM */ 2914451Seschrock ZPOOL_STATUS_FAULTED_DEV_R, /* faulted device with replicas */ 2924451Seschrock ZPOOL_STATUS_FAULTED_DEV_NR, /* faulted device with no replicas */ 293789Sahrens 294789Sahrens /* 295789Sahrens * The following are not faults per se, but still an error possibly 2961003Slling * requiring administrative attention. There is no corresponding 297789Sahrens * message ID. 298789Sahrens */ 2991760Seschrock ZPOOL_STATUS_VERSION_OLDER, /* older on-disk version */ 300789Sahrens ZPOOL_STATUS_RESILVERING, /* device being resilvered */ 301789Sahrens ZPOOL_STATUS_OFFLINE_DEV, /* device online */ 30210151SGeorge.Wilson@Sun.COM ZPOOL_STATUS_REMOVED_DEV, /* removed device */ 303789Sahrens 304789Sahrens /* 305789Sahrens * Finally, the following indicates a healthy pool. 306789Sahrens */ 307789Sahrens ZPOOL_STATUS_OK 308789Sahrens } zpool_status_t; 309789Sahrens 3101544Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **); 3111544Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **); 31211149SGeorge.Wilson@Sun.COM extern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh); 313789Sahrens 314789Sahrens /* 315789Sahrens * Statistics and configuration functions. 316789Sahrens */ 3171544Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **); 3182142Seschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *); 3193444Sek110237 extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **); 3201544Seschrock 321789Sahrens /* 322789Sahrens * Import and export functions 323789Sahrens */ 3247214Slling extern int zpool_export(zpool_handle_t *, boolean_t); 3258211SGeorge.Wilson@Sun.COM extern int zpool_export_force(zpool_handle_t *); 3262082Seschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *, 3275094Slling char *altroot); 3285094Slling extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *, 32912949SGeorge.Wilson@Sun.COM nvlist_t *, int); 330789Sahrens 331789Sahrens /* 332789Sahrens * Search for pools to import 333789Sahrens */ 33411497SMark.Musante@Sun.COM 33511497SMark.Musante@Sun.COM typedef struct importargs { 33611497SMark.Musante@Sun.COM char **path; /* a list of paths to search */ 33711497SMark.Musante@Sun.COM int paths; /* number of paths to search */ 33811497SMark.Musante@Sun.COM char *poolname; /* name of a pool to find */ 33911497SMark.Musante@Sun.COM uint64_t guid; /* guid of a pool to find */ 34011497SMark.Musante@Sun.COM char *cachefile; /* cachefile to use for import */ 34111497SMark.Musante@Sun.COM int can_be_active : 1; /* can the pool be active? */ 34211497SMark.Musante@Sun.COM int unique : 1; /* does 'poolname' already exist? */ 34311497SMark.Musante@Sun.COM int exists : 1; /* set on return if pool already exists */ 34411497SMark.Musante@Sun.COM } importargs_t; 34511497SMark.Musante@Sun.COM 34611497SMark.Musante@Sun.COM extern nvlist_t *zpool_search_import(libzfs_handle_t *, importargs_t *); 34711497SMark.Musante@Sun.COM 34811497SMark.Musante@Sun.COM /* legacy pool search routines */ 3496807Sck153898 extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **); 3505994Sck153898 extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *, 3516957Sck153898 char *, uint64_t); 352789Sahrens 353789Sahrens /* 3541354Seschrock * Miscellaneous pool functions 3551354Seschrock */ 3564543Smarks struct zfs_cmd; 3574543Smarks 35812296SLin.Ling@Sun.COM extern const char *zfs_history_event_names[LOG_END]; 35910685SGeorge.Wilson@Sun.COM 36010594SGeorge.Wilson@Sun.COM extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *, 36110594SGeorge.Wilson@Sun.COM boolean_t verbose); 3625094Slling extern int zpool_upgrade(zpool_handle_t *, uint64_t); 3632926Sek110237 extern int zpool_get_history(zpool_handle_t *, nvlist_t **); 36410685SGeorge.Wilson@Sun.COM extern int zpool_history_unpack(char *, uint64_t, uint64_t *, 36510685SGeorge.Wilson@Sun.COM nvlist_t ***, uint_t *); 3664988Sek110237 extern void zpool_set_history_str(const char *subcommand, int argc, 3674988Sek110237 char **argv, char *history_str); 3684988Sek110237 extern int zpool_stage_history(libzfs_handle_t *, const char *); 3693444Sek110237 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *, 3703444Sek110237 size_t len); 3714543Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *); 3729160SSherry.Moore@Sun.COM extern int zpool_get_physpath(zpool_handle_t *, char *, size_t); 37310921STim.Haley@Sun.COM extern void zpool_explain_recover(libzfs_handle_t *, const char *, int, 37410921STim.Haley@Sun.COM nvlist_t *); 3759160SSherry.Moore@Sun.COM 3761354Seschrock /* 377789Sahrens * Basic handle manipulations. These functions do not create or destroy the 378789Sahrens * underlying datasets, only the references to them. 379789Sahrens */ 3802082Seschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int); 381789Sahrens extern void zfs_close(zfs_handle_t *); 382789Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *); 383789Sahrens extern const char *zfs_get_name(const zfs_handle_t *); 3847538SRichard.Morris@Sun.COM extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *); 385789Sahrens 386789Sahrens /* 387789Sahrens * Property management functions. Some functions are shared with the kernel, 3881003Slling * and are found in sys/fs/zfs.h. 389789Sahrens */ 3905094Slling 3915094Slling /* 3925094Slling * zfs dataset property management 3935094Slling */ 3945094Slling extern const char *zfs_prop_default_string(zfs_prop_t); 3952676Seschrock extern uint64_t zfs_prop_default_numeric(zfs_prop_t); 3962676Seschrock extern const char *zfs_prop_column_name(zfs_prop_t); 3972676Seschrock extern boolean_t zfs_prop_align_right(zfs_prop_t); 3982676Seschrock 3997184Stimh extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t, 4007184Stimh nvlist_t *, uint64_t, zfs_handle_t *, const char *); 4017184Stimh 4025094Slling extern const char *zfs_prop_to_name(zfs_prop_t); 4035094Slling extern int zfs_prop_set(zfs_handle_t *, const char *, const char *); 4045094Slling extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t, 4055094Slling zprop_source_t *, char *, size_t, boolean_t); 40611022STom.Erickson@Sun.COM extern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t, 40711022STom.Erickson@Sun.COM boolean_t); 4085094Slling extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *, 4095094Slling zprop_source_t *, char *, size_t); 4109469SLin.Ling@Sun.COM extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname, 4119469SLin.Ling@Sun.COM uint64_t *propvalue); 4129396SMatthew.Ahrens@Sun.COM extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname, 4139396SMatthew.Ahrens@Sun.COM char *propbuf, int proplen, boolean_t literal); 4145094Slling extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t); 41511022STom.Erickson@Sun.COM extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t); 4165094Slling extern const char *zfs_prop_values(zfs_prop_t); 4175094Slling extern int zfs_prop_is_string(zfs_prop_t prop); 4185094Slling extern nvlist_t *zfs_get_user_props(zfs_handle_t *); 41911022STom.Erickson@Sun.COM extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *); 4205094Slling 4215094Slling typedef struct zprop_list { 4225094Slling int pl_prop; 4232676Seschrock char *pl_user_prop; 4245094Slling struct zprop_list *pl_next; 4252676Seschrock boolean_t pl_all; 4262676Seschrock size_t pl_width; 42711022STom.Erickson@Sun.COM size_t pl_recvd_width; 4282676Seschrock boolean_t pl_fixed; 4295094Slling } zprop_list_t; 4303912Slling 43111022STom.Erickson@Sun.COM extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t); 4328802SSanjeev.Bagewadi@Sun.COM extern void zfs_prune_proplist(zfs_handle_t *, uint8_t *); 433789Sahrens 434789Sahrens #define ZFS_MOUNTPOINT_NONE "none" 435789Sahrens #define ZFS_MOUNTPOINT_LEGACY "legacy" 436789Sahrens 437789Sahrens /* 4385094Slling * zpool property management 4395094Slling */ 4405094Slling extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **); 4415094Slling extern const char *zpool_prop_default_string(zpool_prop_t); 4425094Slling extern uint64_t zpool_prop_default_numeric(zpool_prop_t); 4435094Slling extern const char *zpool_prop_column_name(zpool_prop_t); 4445094Slling extern boolean_t zpool_prop_align_right(zpool_prop_t); 4455094Slling 4465094Slling /* 4475094Slling * Functions shared by zfs and zpool property management. 4483912Slling */ 4495094Slling extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all, 4505094Slling boolean_t ordered, zfs_type_t type); 4515094Slling extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **, 4525094Slling zfs_type_t); 4535094Slling extern void zprop_free_list(zprop_list_t *); 4545094Slling 45511022STom.Erickson@Sun.COM #define ZFS_GET_NCOLS 5 45611022STom.Erickson@Sun.COM 45711022STom.Erickson@Sun.COM typedef enum { 45811022STom.Erickson@Sun.COM GET_COL_NONE, 45911022STom.Erickson@Sun.COM GET_COL_NAME, 46011022STom.Erickson@Sun.COM GET_COL_PROPERTY, 46111022STom.Erickson@Sun.COM GET_COL_VALUE, 46211022STom.Erickson@Sun.COM GET_COL_RECVD, 46311022STom.Erickson@Sun.COM GET_COL_SOURCE 46411022STom.Erickson@Sun.COM } zfs_get_column_t; 46511022STom.Erickson@Sun.COM 4665094Slling /* 4675094Slling * Functions for printing zfs or zpool properties 4685094Slling */ 4695094Slling typedef struct zprop_get_cbdata { 4703912Slling int cb_sources; 47111022STom.Erickson@Sun.COM zfs_get_column_t cb_columns[ZFS_GET_NCOLS]; 47211022STom.Erickson@Sun.COM int cb_colwidths[ZFS_GET_NCOLS + 1]; 4733912Slling boolean_t cb_scripted; 4743912Slling boolean_t cb_literal; 4753912Slling boolean_t cb_first; 4765094Slling zprop_list_t *cb_proplist; 4775094Slling zfs_type_t cb_type; 4785094Slling } zprop_get_cbdata_t; 4793912Slling 4805094Slling void zprop_print_one_property(const char *, zprop_get_cbdata_t *, 48111022STom.Erickson@Sun.COM const char *, const char *, zprop_source_t, const char *, 48211022STom.Erickson@Sun.COM const char *); 4833912Slling 4843912Slling /* 485789Sahrens * Iterator functions. 486789Sahrens */ 487789Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *); 4882082Seschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *); 489789Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *); 4902474Seschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *); 4911356Seschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *); 4921356Seschrock extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *); 49310342Schris.kirby@sun.com extern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *); 494789Sahrens 495*13025SEric.Taylor@oracle.com typedef struct get_all_cb { 496*13025SEric.Taylor@oracle.com zfs_handle_t **cb_handles; 497*13025SEric.Taylor@oracle.com size_t cb_alloc; 498*13025SEric.Taylor@oracle.com size_t cb_used; 499*13025SEric.Taylor@oracle.com boolean_t cb_verbose; 500*13025SEric.Taylor@oracle.com int (*cb_getone)(zfs_handle_t *, void *); 501*13025SEric.Taylor@oracle.com } get_all_cb_t; 502*13025SEric.Taylor@oracle.com 503*13025SEric.Taylor@oracle.com void libzfs_add_handle(get_all_cb_t *, zfs_handle_t *); 504*13025SEric.Taylor@oracle.com int libzfs_dataset_cmp(const void *, const void *); 505*13025SEric.Taylor@oracle.com 506789Sahrens /* 507789Sahrens * Functions to create and destroy datasets. 508789Sahrens */ 5092082Seschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t, 5102676Seschrock nvlist_t *); 5114490Svb160487 extern int zfs_create_ancestors(libzfs_handle_t *, const char *); 51210242Schris.kirby@sun.com extern int zfs_destroy(zfs_handle_t *, boolean_t); 51310242Schris.kirby@sun.com extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t); 5142676Seschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *); 5157265Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *); 5165749Sahrens extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t); 5174490Svb160487 extern int zfs_rename(zfs_handle_t *, const char *, boolean_t); 51811007SLori.Alt@Sun.COM 51911007SLori.Alt@Sun.COM typedef struct sendflags { 52011007SLori.Alt@Sun.COM /* print informational messages (ie, -v was specified) */ 52111007SLori.Alt@Sun.COM int verbose : 1; 52211007SLori.Alt@Sun.COM 52311022STom.Erickson@Sun.COM /* recursive send (ie, -R) */ 52411007SLori.Alt@Sun.COM int replicate : 1; 52511007SLori.Alt@Sun.COM 52611007SLori.Alt@Sun.COM /* for incrementals, do all intermediate snapshots */ 52711022STom.Erickson@Sun.COM int doall : 1; /* (ie, -I) */ 52811007SLori.Alt@Sun.COM 52911007SLori.Alt@Sun.COM /* if dataset is a clone, do incremental from its origin */ 53011007SLori.Alt@Sun.COM int fromorigin : 1; 53111007SLori.Alt@Sun.COM 53211007SLori.Alt@Sun.COM /* do deduplication */ 53311007SLori.Alt@Sun.COM int dedup : 1; 53411022STom.Erickson@Sun.COM 53511022STom.Erickson@Sun.COM /* send properties (ie, -p) */ 53611022STom.Erickson@Sun.COM int props : 1; 53711007SLori.Alt@Sun.COM } sendflags_t; 53811007SLori.Alt@Sun.COM 53911007SLori.Alt@Sun.COM typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *); 54011007SLori.Alt@Sun.COM 54112296SLin.Ling@Sun.COM extern int zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, 54212296SLin.Ling@Sun.COM sendflags_t flags, int outfd, snapfilter_cb_t filter_func, 54312296SLin.Ling@Sun.COM void *cb_arg, nvlist_t **debugnvp); 54411007SLori.Alt@Sun.COM 5452082Seschrock extern int zfs_promote(zfs_handle_t *); 54610342Schris.kirby@sun.com extern int zfs_hold(zfs_handle_t *, const char *, const char *, boolean_t, 54712786SChris.Kirby@oracle.com boolean_t, boolean_t, int, uint64_t, uint64_t); 54810242Schris.kirby@sun.com extern int zfs_release(zfs_handle_t *, const char *, const char *, boolean_t); 54911449SEric.Taylor@Sun.COM extern uint64_t zvol_volsize_to_reservation(uint64_t, nvlist_t *); 550789Sahrens 5519554SMatthew.Ahrens@Sun.COM typedef int (*zfs_userspace_cb_t)(void *arg, const char *domain, 5529396SMatthew.Ahrens@Sun.COM uid_t rid, uint64_t space); 5539396SMatthew.Ahrens@Sun.COM 5549396SMatthew.Ahrens@Sun.COM extern int zfs_userspace(zfs_handle_t *zhp, zfs_userquota_prop_t type, 5559396SMatthew.Ahrens@Sun.COM zfs_userspace_cb_t func, void *arg); 5569396SMatthew.Ahrens@Sun.COM 5575367Sahrens typedef struct recvflags { 5585446Sahrens /* print informational messages (ie, -v was specified) */ 5595501Seschrock int verbose : 1; 5605446Sahrens 5615446Sahrens /* the destination is a prefix, not the exact fs (ie, -d) */ 5625501Seschrock int isprefix : 1; 5635446Sahrens 56411461STom.Erickson@Sun.COM /* 56511461STom.Erickson@Sun.COM * Only the tail of the sent snapshot path is appended to the 56611461STom.Erickson@Sun.COM * destination to determine the received snapshot name (ie, -e). 56711461STom.Erickson@Sun.COM */ 56811461STom.Erickson@Sun.COM int istail : 1; 56911461STom.Erickson@Sun.COM 5705446Sahrens /* do not actually do the recv, just check if it would work (ie, -n) */ 5715501Seschrock int dryrun : 1; 5725446Sahrens 5735446Sahrens /* rollback/destroy filesystems as necessary (eg, -F) */ 5745501Seschrock int force : 1; 5755446Sahrens 5765446Sahrens /* set "canmount=off" on all modified filesystems */ 5775501Seschrock int canmountoff : 1; 5785446Sahrens 5795446Sahrens /* byteswap flag is used internally; callers need not specify */ 5805501Seschrock int byteswap : 1; 5818584SLori.Alt@Sun.COM 5828584SLori.Alt@Sun.COM /* do not mount file systems as they are extracted (private) */ 5838584SLori.Alt@Sun.COM int nomount : 1; 5845367Sahrens } recvflags_t; 5855367Sahrens 5865367Sahrens extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t, 5875367Sahrens int, avl_tree_t *); 5885367Sahrens 589789Sahrens /* 590789Sahrens * Miscellaneous functions. 591789Sahrens */ 592789Sahrens extern const char *zfs_type_to_name(zfs_type_t); 593789Sahrens extern void zfs_refresh_properties(zfs_handle_t *); 594789Sahrens extern int zfs_name_valid(const char *, zfs_type_t); 5953635Sck153898 extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t); 5964490Svb160487 extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *, 5974490Svb160487 zfs_type_t); 5985713Srm160521 extern int zfs_spa_version(zfs_handle_t *, int *); 599789Sahrens 600789Sahrens /* 601789Sahrens * Mount support functions. 602789Sahrens */ 6033444Sek110237 extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **); 6042082Seschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **); 605789Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int); 606789Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int); 607789Sahrens extern int zfs_unmountall(zfs_handle_t *, int); 608789Sahrens 609789Sahrens /* 610789Sahrens * Share support functions. 611789Sahrens */ 6123126Sahl extern boolean_t zfs_is_shared(zfs_handle_t *); 613789Sahrens extern int zfs_share(zfs_handle_t *); 6143126Sahl extern int zfs_unshare(zfs_handle_t *); 6153126Sahl 6163126Sahl /* 6174451Seschrock * Protocol-specific share support functions. 6183126Sahl */ 6193126Sahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **); 6205331Samw extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **); 6213126Sahl extern int zfs_share_nfs(zfs_handle_t *); 6225331Samw extern int zfs_share_smb(zfs_handle_t *); 6235331Samw extern int zfs_shareall(zfs_handle_t *); 6243126Sahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *); 6255331Samw extern int zfs_unshare_smb(zfs_handle_t *, const char *); 6263126Sahl extern int zfs_unshareall_nfs(zfs_handle_t *); 6275331Samw extern int zfs_unshareall_smb(zfs_handle_t *); 6285331Samw extern int zfs_unshareall_bypath(zfs_handle_t *, const char *); 6295331Samw extern int zfs_unshareall(zfs_handle_t *); 6308845Samw@Sun.COM extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *, 6315331Samw void *, void *, int, zfs_share_op_t); 632789Sahrens 633789Sahrens /* 634789Sahrens * When dealing with nvlists, verify() is extremely useful 635789Sahrens */ 636789Sahrens #ifdef NDEBUG 637789Sahrens #define verify(EX) ((void)(EX)) 638789Sahrens #else 639789Sahrens #define verify(EX) assert(EX) 640789Sahrens #endif 641789Sahrens 642789Sahrens /* 643789Sahrens * Utility function to convert a number to a human-readable form. 644789Sahrens */ 645789Sahrens extern void zfs_nicenum(uint64_t, char *, size_t); 6462676Seschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *); 647789Sahrens 648789Sahrens /* 649789Sahrens * Given a device or file, determine if it is part of a pool. 650789Sahrens */ 6512082Seschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **, 6522082Seschrock boolean_t *); 653789Sahrens 654789Sahrens /* 65510830SEric.Schrock@Sun.COM * Label manipulation. 656789Sahrens */ 6572082Seschrock extern int zpool_read_label(int, nvlist_t **); 65810830SEric.Schrock@Sun.COM extern int zpool_clear_label(int); 659789Sahrens 6606423Sgw25295 /* is this zvol valid for use as a dump device? */ 6616423Sgw25295 extern int zvol_check_dump_config(char *); 6626423Sgw25295 6632474Seschrock /* 6648845Samw@Sun.COM * Management interfaces for SMB ACL files 6658845Samw@Sun.COM */ 6668845Samw@Sun.COM 6678845Samw@Sun.COM int zfs_smb_acl_add(libzfs_handle_t *, char *, char *, char *); 6688845Samw@Sun.COM int zfs_smb_acl_remove(libzfs_handle_t *, char *, char *, char *); 6698845Samw@Sun.COM int zfs_smb_acl_purge(libzfs_handle_t *, char *, char *); 6708845Samw@Sun.COM int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *); 6718845Samw@Sun.COM 6728845Samw@Sun.COM /* 6733126Sahl * Enable and disable datasets within a pool by mounting/unmounting and 6743126Sahl * sharing/unsharing them. 6752474Seschrock */ 6763126Sahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int); 6773126Sahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t); 6782474Seschrock 67910817SEric.Schrock@Sun.COM /* 68010817SEric.Schrock@Sun.COM * Mappings between vdev and FRU. 68110817SEric.Schrock@Sun.COM */ 68210817SEric.Schrock@Sun.COM extern void libzfs_fru_refresh(libzfs_handle_t *); 68310817SEric.Schrock@Sun.COM extern const char *libzfs_fru_lookup(libzfs_handle_t *, const char *); 68410817SEric.Schrock@Sun.COM extern const char *libzfs_fru_devpath(libzfs_handle_t *, const char *); 68510817SEric.Schrock@Sun.COM extern boolean_t libzfs_fru_compare(libzfs_handle_t *, const char *, 68610817SEric.Schrock@Sun.COM const char *); 68710817SEric.Schrock@Sun.COM extern boolean_t libzfs_fru_notself(libzfs_handle_t *, const char *); 68810817SEric.Schrock@Sun.COM extern int zpool_fru_set(zpool_handle_t *, uint64_t, const char *); 68910817SEric.Schrock@Sun.COM 690789Sahrens #ifdef __cplusplus 691789Sahrens } 692789Sahrens #endif 693789Sahrens 694789Sahrens #endif /* _LIBZFS_H */ 695