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 */ 1065331Samw EZFS_UNSHARESMBFAILED, /* failed to unshare over smb */ 1075331Samw EZFS_SHARESMBFAILED, /* failed to share over smb */ 1085363Seschrock EZFS_BADCACHE, /* bad cache file */ 1095450Sbrendan EZFS_ISL2CACHE, /* device is for the level 2 ARC */ 1106423Sgw25295 EZFS_VDEVNOTSUP, /* unsupported vdev type */ 1117042Sgw25295 EZFS_NOTSUP, /* ops not supported on this dataset */ 1127214Slling EZFS_ACTIVE_SPARE, /* pool has active shared spare devices */ 1139701SGeorge.Wilson@Sun.COM EZFS_UNPLAYED_LOGS, /* log device has unplayed logs */ 11410242Schris.kirby@sun.com EZFS_REFTAG_RELE, /* snapshot release: tag not found */ 11510242Schris.kirby@sun.com EZFS_REFTAG_HOLD, /* snapshot hold: tag already exists */ 11610342Schris.kirby@sun.com EZFS_TAGTOOLONG, /* snapshot hold/rele: tag too long */ 11711007SLori.Alt@Sun.COM EZFS_PIPEFAILED, /* pipe create failed */ 11811007SLori.Alt@Sun.COM EZFS_THREADCREATEFAILED, /* thread create failed */ 11911422SMark.Musante@Sun.COM EZFS_POSTSPLIT_ONLINE, /* onlining a disk after splitting it */ 12012296SLin.Ling@Sun.COM EZFS_SCRUBBING, /* currently scrubbing */ 12112296SLin.Ling@Sun.COM EZFS_NO_SCRUB, /* no active scrub */ 12213043STim.Haley@Sun.COM EZFS_DIFF, /* general failure of zfs diff */ 12313043STim.Haley@Sun.COM EZFS_DIFFDATA, /* bad zfs diff data */ 124*13049SGeorge.Wilson@Sun.COM EZFS_POOLREADONLY, /* pool is in read-only mode */ 1253912Slling EZFS_UNKNOWN 1262082Seschrock }; 1272082Seschrock 1282082Seschrock /* 1294543Smarks * The following data structures are all part 1304543Smarks * of the zfs_allow_t data structure which is 1314543Smarks * used for printing 'allow' permissions. 1324543Smarks * It is a linked list of zfs_allow_t's which 1334543Smarks * then contain avl tree's for user/group/sets/... 1344543Smarks * and each one of the entries in those trees have 1354543Smarks * avl tree's for the permissions they belong to and 1364543Smarks * whether they are local,descendent or local+descendent 1374543Smarks * permissions. The AVL trees are used primarily for 1384543Smarks * sorting purposes, but also so that we can quickly find 1394543Smarks * a given user and or permission. 1404543Smarks */ 1414543Smarks typedef struct zfs_perm_node { 1424543Smarks avl_node_t z_node; 1434543Smarks char z_pname[MAXPATHLEN]; 1444543Smarks } zfs_perm_node_t; 1454543Smarks 1464543Smarks typedef struct zfs_allow_node { 1474543Smarks avl_node_t z_node; 1484543Smarks char z_key[MAXPATHLEN]; /* name, such as joe */ 1494543Smarks avl_tree_t z_localdescend; /* local+descendent perms */ 1504543Smarks avl_tree_t z_local; /* local permissions */ 1514543Smarks avl_tree_t z_descend; /* descendent permissions */ 1524543Smarks } zfs_allow_node_t; 1534543Smarks 1544543Smarks typedef struct zfs_allow { 1554543Smarks struct zfs_allow *z_next; 1564543Smarks char z_setpoint[MAXPATHLEN]; 1574543Smarks avl_tree_t z_sets; 1584543Smarks avl_tree_t z_crperms; 1594543Smarks avl_tree_t z_user; 1604543Smarks avl_tree_t z_group; 1614543Smarks avl_tree_t z_everyone; 1624543Smarks } zfs_allow_t; 1634543Smarks 1644543Smarks /* 165789Sahrens * Basic handle types 166789Sahrens */ 167789Sahrens typedef struct zfs_handle zfs_handle_t; 168789Sahrens typedef struct zpool_handle zpool_handle_t; 1692082Seschrock typedef struct libzfs_handle libzfs_handle_t; 1702082Seschrock 1712082Seschrock /* 1722082Seschrock * Library initialization 1732082Seschrock */ 1742082Seschrock extern libzfs_handle_t *libzfs_init(void); 1752082Seschrock extern void libzfs_fini(libzfs_handle_t *); 1762082Seschrock 1772082Seschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *); 1782082Seschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *); 1792082Seschrock 1802082Seschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t); 1812082Seschrock 1822082Seschrock extern int libzfs_errno(libzfs_handle_t *); 1832082Seschrock extern const char *libzfs_error_action(libzfs_handle_t *); 1842082Seschrock extern const char *libzfs_error_description(libzfs_handle_t *); 1858228SEric.Taylor@Sun.COM extern void libzfs_mnttab_init(libzfs_handle_t *); 1868228SEric.Taylor@Sun.COM extern void libzfs_mnttab_fini(libzfs_handle_t *); 1878811SEric.Taylor@Sun.COM extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t); 1888228SEric.Taylor@Sun.COM extern int libzfs_mnttab_find(libzfs_handle_t *, const char *, 1898228SEric.Taylor@Sun.COM struct mnttab *); 1908228SEric.Taylor@Sun.COM extern void libzfs_mnttab_add(libzfs_handle_t *, const char *, 1918228SEric.Taylor@Sun.COM const char *, const char *); 1928228SEric.Taylor@Sun.COM extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *); 193789Sahrens 194789Sahrens /* 195789Sahrens * Basic handle functions 196789Sahrens */ 1972082Seschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *); 1982082Seschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *); 199789Sahrens extern void zpool_close(zpool_handle_t *); 200789Sahrens extern const char *zpool_get_name(zpool_handle_t *); 201789Sahrens extern int zpool_get_state(zpool_handle_t *); 2025094Slling extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t); 2036865Srm160521 extern void zpool_free_handles(libzfs_handle_t *); 204789Sahrens 205789Sahrens /* 206789Sahrens * Iterate over all active pools in the system. 207789Sahrens */ 208789Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *); 2092082Seschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *); 210789Sahrens 211789Sahrens /* 212789Sahrens * Functions to create and destroy pools 213789Sahrens */ 2142082Seschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *, 2157184Stimh nvlist_t *, nvlist_t *); 216789Sahrens extern int zpool_destroy(zpool_handle_t *); 217789Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *); 218789Sahrens 21911422SMark.Musante@Sun.COM typedef struct splitflags { 22011422SMark.Musante@Sun.COM /* do not split, but return the config that would be split off */ 22111422SMark.Musante@Sun.COM int dryrun : 1; 22211422SMark.Musante@Sun.COM 22311422SMark.Musante@Sun.COM /* after splitting, import the pool */ 22411422SMark.Musante@Sun.COM int import : 1; 22511422SMark.Musante@Sun.COM } splitflags_t; 22611422SMark.Musante@Sun.COM 227789Sahrens /* 228789Sahrens * Functions to manipulate pool and vdev state 229789Sahrens */ 23012296SLin.Ling@Sun.COM extern int zpool_scan(zpool_handle_t *, pool_scan_func_t); 23110921STim.Haley@Sun.COM extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *); 232789Sahrens 2334451Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int, 2344451Seschrock vdev_state_t *); 2354451Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t); 2364451Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *, 2374451Seschrock const char *, nvlist_t *, int); 238789Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *); 2392082Seschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *); 24011422SMark.Musante@Sun.COM extern int zpool_vdev_split(zpool_handle_t *, char *, nvlist_t **, nvlist_t *, 24111422SMark.Musante@Sun.COM splitflags_t); 2424451Seschrock 24310817SEric.Schrock@Sun.COM extern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t); 24410817SEric.Schrock@Sun.COM extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t); 2454451Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t); 2464451Seschrock 2475450Sbrendan extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *, 2487326SEric.Schrock@Sun.COM boolean_t *, boolean_t *); 2499816SGeorge.Wilson@Sun.COM extern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *, 2509816SGeorge.Wilson@Sun.COM boolean_t *, boolean_t *, boolean_t *); 2514276Staylor extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *); 252789Sahrens 253789Sahrens /* 2543912Slling * Functions to manage pool properties 2553912Slling */ 2563912Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *); 2574451Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *, 2585094Slling size_t proplen, zprop_source_t *); 2595094Slling extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t, 2605094Slling zprop_source_t *); 2615094Slling 2623912Slling extern const char *zpool_prop_to_name(zpool_prop_t); 2633912Slling extern const char *zpool_prop_values(zpool_prop_t); 2643912Slling 2653912Slling /* 266789Sahrens * Pool health statistics. 267789Sahrens */ 268789Sahrens typedef enum { 269789Sahrens /* 270789Sahrens * The following correspond to faults as defined in the (fault.fs.zfs.*) 2711003Slling * event namespace. Each is associated with a corresponding message ID. 272789Sahrens */ 273789Sahrens ZPOOL_STATUS_CORRUPT_CACHE, /* corrupt /kernel/drv/zpool.cache */ 274789Sahrens ZPOOL_STATUS_MISSING_DEV_R, /* missing device with replicas */ 275789Sahrens ZPOOL_STATUS_MISSING_DEV_NR, /* missing device with no replicas */ 276789Sahrens ZPOOL_STATUS_CORRUPT_LABEL_R, /* bad device label with replicas */ 2771003Slling ZPOOL_STATUS_CORRUPT_LABEL_NR, /* bad device label with no replicas */ 278789Sahrens ZPOOL_STATUS_BAD_GUID_SUM, /* sum of device guids didn't match */ 279789Sahrens ZPOOL_STATUS_CORRUPT_POOL, /* pool metadata is corrupted */ 280789Sahrens ZPOOL_STATUS_CORRUPT_DATA, /* data errors in user (meta)data */ 281789Sahrens ZPOOL_STATUS_FAILING_DEV, /* device experiencing errors */ 2821760Seschrock ZPOOL_STATUS_VERSION_NEWER, /* newer on-disk version */ 2833975Sek110237 ZPOOL_STATUS_HOSTID_MISMATCH, /* last accessed by another system */ 2846523Sek110237 ZPOOL_STATUS_IO_FAILURE_WAIT, /* failed I/O, failmode 'wait' */ 2856523Sek110237 ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */ 2868343SEric.Schrock@Sun.COM ZPOOL_STATUS_BAD_LOG, /* cannot read log chain(s) */ 2878343SEric.Schrock@Sun.COM 2888343SEric.Schrock@Sun.COM /* 2898343SEric.Schrock@Sun.COM * These faults have no corresponding message ID. At the time we are 2908343SEric.Schrock@Sun.COM * checking the status, the original reason for the FMA fault (I/O or 2918343SEric.Schrock@Sun.COM * checksum errors) has been lost. 2928343SEric.Schrock@Sun.COM */ 2934451Seschrock ZPOOL_STATUS_FAULTED_DEV_R, /* faulted device with replicas */ 2944451Seschrock ZPOOL_STATUS_FAULTED_DEV_NR, /* faulted device with no replicas */ 295789Sahrens 296789Sahrens /* 297789Sahrens * The following are not faults per se, but still an error possibly 2981003Slling * requiring administrative attention. There is no corresponding 299789Sahrens * message ID. 300789Sahrens */ 3011760Seschrock ZPOOL_STATUS_VERSION_OLDER, /* older on-disk version */ 302789Sahrens ZPOOL_STATUS_RESILVERING, /* device being resilvered */ 303789Sahrens ZPOOL_STATUS_OFFLINE_DEV, /* device online */ 30410151SGeorge.Wilson@Sun.COM ZPOOL_STATUS_REMOVED_DEV, /* removed device */ 305789Sahrens 306789Sahrens /* 307789Sahrens * Finally, the following indicates a healthy pool. 308789Sahrens */ 309789Sahrens ZPOOL_STATUS_OK 310789Sahrens } zpool_status_t; 311789Sahrens 3121544Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **); 3131544Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **); 31411149SGeorge.Wilson@Sun.COM extern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh); 315789Sahrens 316789Sahrens /* 317789Sahrens * Statistics and configuration functions. 318789Sahrens */ 3191544Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **); 3202142Seschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *); 3213444Sek110237 extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **); 3221544Seschrock 323789Sahrens /* 324789Sahrens * Import and export functions 325789Sahrens */ 3267214Slling extern int zpool_export(zpool_handle_t *, boolean_t); 3278211SGeorge.Wilson@Sun.COM extern int zpool_export_force(zpool_handle_t *); 3282082Seschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *, 3295094Slling char *altroot); 3305094Slling extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *, 33112949SGeorge.Wilson@Sun.COM nvlist_t *, int); 332789Sahrens 333789Sahrens /* 334789Sahrens * Search for pools to import 335789Sahrens */ 33611497SMark.Musante@Sun.COM 33711497SMark.Musante@Sun.COM typedef struct importargs { 33811497SMark.Musante@Sun.COM char **path; /* a list of paths to search */ 33911497SMark.Musante@Sun.COM int paths; /* number of paths to search */ 34011497SMark.Musante@Sun.COM char *poolname; /* name of a pool to find */ 34111497SMark.Musante@Sun.COM uint64_t guid; /* guid of a pool to find */ 34211497SMark.Musante@Sun.COM char *cachefile; /* cachefile to use for import */ 34311497SMark.Musante@Sun.COM int can_be_active : 1; /* can the pool be active? */ 34411497SMark.Musante@Sun.COM int unique : 1; /* does 'poolname' already exist? */ 34511497SMark.Musante@Sun.COM int exists : 1; /* set on return if pool already exists */ 34611497SMark.Musante@Sun.COM } importargs_t; 34711497SMark.Musante@Sun.COM 34811497SMark.Musante@Sun.COM extern nvlist_t *zpool_search_import(libzfs_handle_t *, importargs_t *); 34911497SMark.Musante@Sun.COM 35011497SMark.Musante@Sun.COM /* legacy pool search routines */ 3516807Sck153898 extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **); 3525994Sck153898 extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *, 3536957Sck153898 char *, uint64_t); 354789Sahrens 355789Sahrens /* 3561354Seschrock * Miscellaneous pool functions 3571354Seschrock */ 3584543Smarks struct zfs_cmd; 3594543Smarks 36012296SLin.Ling@Sun.COM extern const char *zfs_history_event_names[LOG_END]; 36110685SGeorge.Wilson@Sun.COM 36210594SGeorge.Wilson@Sun.COM extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *, 36310594SGeorge.Wilson@Sun.COM boolean_t verbose); 3645094Slling extern int zpool_upgrade(zpool_handle_t *, uint64_t); 3652926Sek110237 extern int zpool_get_history(zpool_handle_t *, nvlist_t **); 36610685SGeorge.Wilson@Sun.COM extern int zpool_history_unpack(char *, uint64_t, uint64_t *, 36710685SGeorge.Wilson@Sun.COM nvlist_t ***, uint_t *); 3684988Sek110237 extern void zpool_set_history_str(const char *subcommand, int argc, 3694988Sek110237 char **argv, char *history_str); 3704988Sek110237 extern int zpool_stage_history(libzfs_handle_t *, const char *); 3713444Sek110237 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *, 3723444Sek110237 size_t len); 3734543Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *); 3749160SSherry.Moore@Sun.COM extern int zpool_get_physpath(zpool_handle_t *, char *, size_t); 37510921STim.Haley@Sun.COM extern void zpool_explain_recover(libzfs_handle_t *, const char *, int, 37610921STim.Haley@Sun.COM nvlist_t *); 3779160SSherry.Moore@Sun.COM 3781354Seschrock /* 379789Sahrens * Basic handle manipulations. These functions do not create or destroy the 380789Sahrens * underlying datasets, only the references to them. 381789Sahrens */ 3822082Seschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int); 383789Sahrens extern void zfs_close(zfs_handle_t *); 384789Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *); 385789Sahrens extern const char *zfs_get_name(const zfs_handle_t *); 3867538SRichard.Morris@Sun.COM extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *); 387789Sahrens 388789Sahrens /* 389789Sahrens * Property management functions. Some functions are shared with the kernel, 3901003Slling * and are found in sys/fs/zfs.h. 391789Sahrens */ 3925094Slling 3935094Slling /* 3945094Slling * zfs dataset property management 3955094Slling */ 3965094Slling extern const char *zfs_prop_default_string(zfs_prop_t); 3972676Seschrock extern uint64_t zfs_prop_default_numeric(zfs_prop_t); 3982676Seschrock extern const char *zfs_prop_column_name(zfs_prop_t); 3992676Seschrock extern boolean_t zfs_prop_align_right(zfs_prop_t); 4002676Seschrock 4017184Stimh extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t, 4027184Stimh nvlist_t *, uint64_t, zfs_handle_t *, const char *); 4037184Stimh 4045094Slling extern const char *zfs_prop_to_name(zfs_prop_t); 4055094Slling extern int zfs_prop_set(zfs_handle_t *, const char *, const char *); 4065094Slling extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t, 4075094Slling zprop_source_t *, char *, size_t, boolean_t); 40811022STom.Erickson@Sun.COM extern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t, 40911022STom.Erickson@Sun.COM boolean_t); 4105094Slling extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *, 4115094Slling zprop_source_t *, char *, size_t); 4129469SLin.Ling@Sun.COM extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname, 4139469SLin.Ling@Sun.COM uint64_t *propvalue); 4149396SMatthew.Ahrens@Sun.COM extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname, 4159396SMatthew.Ahrens@Sun.COM char *propbuf, int proplen, boolean_t literal); 4165094Slling extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t); 41711022STom.Erickson@Sun.COM extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t); 4185094Slling extern const char *zfs_prop_values(zfs_prop_t); 4195094Slling extern int zfs_prop_is_string(zfs_prop_t prop); 4205094Slling extern nvlist_t *zfs_get_user_props(zfs_handle_t *); 42111022STom.Erickson@Sun.COM extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *); 4225094Slling 4235094Slling typedef struct zprop_list { 4245094Slling int pl_prop; 4252676Seschrock char *pl_user_prop; 4265094Slling struct zprop_list *pl_next; 4272676Seschrock boolean_t pl_all; 4282676Seschrock size_t pl_width; 42911022STom.Erickson@Sun.COM size_t pl_recvd_width; 4302676Seschrock boolean_t pl_fixed; 4315094Slling } zprop_list_t; 4323912Slling 43311022STom.Erickson@Sun.COM extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t); 4348802SSanjeev.Bagewadi@Sun.COM extern void zfs_prune_proplist(zfs_handle_t *, uint8_t *); 435789Sahrens 436789Sahrens #define ZFS_MOUNTPOINT_NONE "none" 437789Sahrens #define ZFS_MOUNTPOINT_LEGACY "legacy" 438789Sahrens 439789Sahrens /* 4405094Slling * zpool property management 4415094Slling */ 4425094Slling extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **); 4435094Slling extern const char *zpool_prop_default_string(zpool_prop_t); 4445094Slling extern uint64_t zpool_prop_default_numeric(zpool_prop_t); 4455094Slling extern const char *zpool_prop_column_name(zpool_prop_t); 4465094Slling extern boolean_t zpool_prop_align_right(zpool_prop_t); 4475094Slling 4485094Slling /* 4495094Slling * Functions shared by zfs and zpool property management. 4503912Slling */ 4515094Slling extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all, 4525094Slling boolean_t ordered, zfs_type_t type); 4535094Slling extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **, 4545094Slling zfs_type_t); 4555094Slling extern void zprop_free_list(zprop_list_t *); 4565094Slling 45711022STom.Erickson@Sun.COM #define ZFS_GET_NCOLS 5 45811022STom.Erickson@Sun.COM 45911022STom.Erickson@Sun.COM typedef enum { 46011022STom.Erickson@Sun.COM GET_COL_NONE, 46111022STom.Erickson@Sun.COM GET_COL_NAME, 46211022STom.Erickson@Sun.COM GET_COL_PROPERTY, 46311022STom.Erickson@Sun.COM GET_COL_VALUE, 46411022STom.Erickson@Sun.COM GET_COL_RECVD, 46511022STom.Erickson@Sun.COM GET_COL_SOURCE 46611022STom.Erickson@Sun.COM } zfs_get_column_t; 46711022STom.Erickson@Sun.COM 4685094Slling /* 4695094Slling * Functions for printing zfs or zpool properties 4705094Slling */ 4715094Slling typedef struct zprop_get_cbdata { 4723912Slling int cb_sources; 47311022STom.Erickson@Sun.COM zfs_get_column_t cb_columns[ZFS_GET_NCOLS]; 47411022STom.Erickson@Sun.COM int cb_colwidths[ZFS_GET_NCOLS + 1]; 4753912Slling boolean_t cb_scripted; 4763912Slling boolean_t cb_literal; 4773912Slling boolean_t cb_first; 4785094Slling zprop_list_t *cb_proplist; 4795094Slling zfs_type_t cb_type; 4805094Slling } zprop_get_cbdata_t; 4813912Slling 4825094Slling void zprop_print_one_property(const char *, zprop_get_cbdata_t *, 48311022STom.Erickson@Sun.COM const char *, const char *, zprop_source_t, const char *, 48411022STom.Erickson@Sun.COM const char *); 4853912Slling 4863912Slling /* 487789Sahrens * Iterator functions. 488789Sahrens */ 489789Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *); 4902082Seschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *); 491789Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *); 4922474Seschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *); 4931356Seschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *); 4941356Seschrock extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *); 49510342Schris.kirby@sun.com extern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *); 496789Sahrens 49713025SEric.Taylor@oracle.com typedef struct get_all_cb { 49813025SEric.Taylor@oracle.com zfs_handle_t **cb_handles; 49913025SEric.Taylor@oracle.com size_t cb_alloc; 50013025SEric.Taylor@oracle.com size_t cb_used; 50113025SEric.Taylor@oracle.com boolean_t cb_verbose; 50213025SEric.Taylor@oracle.com int (*cb_getone)(zfs_handle_t *, void *); 50313025SEric.Taylor@oracle.com } get_all_cb_t; 50413025SEric.Taylor@oracle.com 50513025SEric.Taylor@oracle.com void libzfs_add_handle(get_all_cb_t *, zfs_handle_t *); 50613025SEric.Taylor@oracle.com int libzfs_dataset_cmp(const void *, const void *); 50713025SEric.Taylor@oracle.com 508789Sahrens /* 509789Sahrens * Functions to create and destroy datasets. 510789Sahrens */ 5112082Seschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t, 5122676Seschrock nvlist_t *); 5134490Svb160487 extern int zfs_create_ancestors(libzfs_handle_t *, const char *); 51410242Schris.kirby@sun.com extern int zfs_destroy(zfs_handle_t *, boolean_t); 51510242Schris.kirby@sun.com extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t); 5162676Seschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *); 5177265Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *); 5185749Sahrens extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t); 5194490Svb160487 extern int zfs_rename(zfs_handle_t *, const char *, boolean_t); 52011007SLori.Alt@Sun.COM 52111007SLori.Alt@Sun.COM typedef struct sendflags { 52211007SLori.Alt@Sun.COM /* print informational messages (ie, -v was specified) */ 52311007SLori.Alt@Sun.COM int verbose : 1; 52411007SLori.Alt@Sun.COM 52511022STom.Erickson@Sun.COM /* recursive send (ie, -R) */ 52611007SLori.Alt@Sun.COM int replicate : 1; 52711007SLori.Alt@Sun.COM 52811007SLori.Alt@Sun.COM /* for incrementals, do all intermediate snapshots */ 52911022STom.Erickson@Sun.COM int doall : 1; /* (ie, -I) */ 53011007SLori.Alt@Sun.COM 53111007SLori.Alt@Sun.COM /* if dataset is a clone, do incremental from its origin */ 53211007SLori.Alt@Sun.COM int fromorigin : 1; 53311007SLori.Alt@Sun.COM 53411007SLori.Alt@Sun.COM /* do deduplication */ 53511007SLori.Alt@Sun.COM int dedup : 1; 53611022STom.Erickson@Sun.COM 53711022STom.Erickson@Sun.COM /* send properties (ie, -p) */ 53811022STom.Erickson@Sun.COM int props : 1; 53911007SLori.Alt@Sun.COM } sendflags_t; 54011007SLori.Alt@Sun.COM 54111007SLori.Alt@Sun.COM typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *); 54211007SLori.Alt@Sun.COM 54312296SLin.Ling@Sun.COM extern int zfs_send(zfs_handle_t *zhp, const char *fromsnap, const char *tosnap, 54412296SLin.Ling@Sun.COM sendflags_t flags, int outfd, snapfilter_cb_t filter_func, 54512296SLin.Ling@Sun.COM void *cb_arg, nvlist_t **debugnvp); 54611007SLori.Alt@Sun.COM 5472082Seschrock extern int zfs_promote(zfs_handle_t *); 54810342Schris.kirby@sun.com extern int zfs_hold(zfs_handle_t *, const char *, const char *, boolean_t, 54912786SChris.Kirby@oracle.com boolean_t, boolean_t, int, uint64_t, uint64_t); 55010242Schris.kirby@sun.com extern int zfs_release(zfs_handle_t *, const char *, const char *, boolean_t); 55111449SEric.Taylor@Sun.COM extern uint64_t zvol_volsize_to_reservation(uint64_t, nvlist_t *); 552789Sahrens 5539554SMatthew.Ahrens@Sun.COM typedef int (*zfs_userspace_cb_t)(void *arg, const char *domain, 5549396SMatthew.Ahrens@Sun.COM uid_t rid, uint64_t space); 5559396SMatthew.Ahrens@Sun.COM 5569396SMatthew.Ahrens@Sun.COM extern int zfs_userspace(zfs_handle_t *zhp, zfs_userquota_prop_t type, 5579396SMatthew.Ahrens@Sun.COM zfs_userspace_cb_t func, void *arg); 5589396SMatthew.Ahrens@Sun.COM 5595367Sahrens typedef struct recvflags { 5605446Sahrens /* print informational messages (ie, -v was specified) */ 5615501Seschrock int verbose : 1; 5625446Sahrens 5635446Sahrens /* the destination is a prefix, not the exact fs (ie, -d) */ 5645501Seschrock int isprefix : 1; 5655446Sahrens 56611461STom.Erickson@Sun.COM /* 56711461STom.Erickson@Sun.COM * Only the tail of the sent snapshot path is appended to the 56811461STom.Erickson@Sun.COM * destination to determine the received snapshot name (ie, -e). 56911461STom.Erickson@Sun.COM */ 57011461STom.Erickson@Sun.COM int istail : 1; 57111461STom.Erickson@Sun.COM 5725446Sahrens /* do not actually do the recv, just check if it would work (ie, -n) */ 5735501Seschrock int dryrun : 1; 5745446Sahrens 5755446Sahrens /* rollback/destroy filesystems as necessary (eg, -F) */ 5765501Seschrock int force : 1; 5775446Sahrens 5785446Sahrens /* set "canmount=off" on all modified filesystems */ 5795501Seschrock int canmountoff : 1; 5805446Sahrens 5815446Sahrens /* byteswap flag is used internally; callers need not specify */ 5825501Seschrock int byteswap : 1; 5838584SLori.Alt@Sun.COM 5848584SLori.Alt@Sun.COM /* do not mount file systems as they are extracted (private) */ 5858584SLori.Alt@Sun.COM int nomount : 1; 5865367Sahrens } recvflags_t; 5875367Sahrens 5885367Sahrens extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t, 5895367Sahrens int, avl_tree_t *); 5905367Sahrens 59113043STim.Haley@Sun.COM typedef enum diff_flags { 59213043STim.Haley@Sun.COM ZFS_DIFF_PARSEABLE = 0x1, 59313043STim.Haley@Sun.COM ZFS_DIFF_TIMESTAMP = 0x2, 59413043STim.Haley@Sun.COM ZFS_DIFF_CLASSIFY = 0x4 59513043STim.Haley@Sun.COM } diff_flags_t; 59613043STim.Haley@Sun.COM 59713043STim.Haley@Sun.COM extern int zfs_show_diffs(zfs_handle_t *, int, const char *, const char *, 59813043STim.Haley@Sun.COM int); 59913043STim.Haley@Sun.COM 600789Sahrens /* 601789Sahrens * Miscellaneous functions. 602789Sahrens */ 603789Sahrens extern const char *zfs_type_to_name(zfs_type_t); 604789Sahrens extern void zfs_refresh_properties(zfs_handle_t *); 605789Sahrens extern int zfs_name_valid(const char *, zfs_type_t); 6063635Sck153898 extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t); 6074490Svb160487 extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *, 6084490Svb160487 zfs_type_t); 6095713Srm160521 extern int zfs_spa_version(zfs_handle_t *, int *); 610789Sahrens 611789Sahrens /* 612789Sahrens * Mount support functions. 613789Sahrens */ 6143444Sek110237 extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **); 6152082Seschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **); 616789Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int); 617789Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int); 618789Sahrens extern int zfs_unmountall(zfs_handle_t *, int); 619789Sahrens 620789Sahrens /* 621789Sahrens * Share support functions. 622789Sahrens */ 6233126Sahl extern boolean_t zfs_is_shared(zfs_handle_t *); 624789Sahrens extern int zfs_share(zfs_handle_t *); 6253126Sahl extern int zfs_unshare(zfs_handle_t *); 6263126Sahl 6273126Sahl /* 6284451Seschrock * Protocol-specific share support functions. 6293126Sahl */ 6303126Sahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **); 6315331Samw extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **); 6323126Sahl extern int zfs_share_nfs(zfs_handle_t *); 6335331Samw extern int zfs_share_smb(zfs_handle_t *); 6345331Samw extern int zfs_shareall(zfs_handle_t *); 6353126Sahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *); 6365331Samw extern int zfs_unshare_smb(zfs_handle_t *, const char *); 6373126Sahl extern int zfs_unshareall_nfs(zfs_handle_t *); 6385331Samw extern int zfs_unshareall_smb(zfs_handle_t *); 6395331Samw extern int zfs_unshareall_bypath(zfs_handle_t *, const char *); 6405331Samw extern int zfs_unshareall(zfs_handle_t *); 6418845Samw@Sun.COM extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *, 6425331Samw void *, void *, int, zfs_share_op_t); 643789Sahrens 644789Sahrens /* 645789Sahrens * When dealing with nvlists, verify() is extremely useful 646789Sahrens */ 647789Sahrens #ifdef NDEBUG 648789Sahrens #define verify(EX) ((void)(EX)) 649789Sahrens #else 650789Sahrens #define verify(EX) assert(EX) 651789Sahrens #endif 652789Sahrens 653789Sahrens /* 654789Sahrens * Utility function to convert a number to a human-readable form. 655789Sahrens */ 656789Sahrens extern void zfs_nicenum(uint64_t, char *, size_t); 6572676Seschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *); 658789Sahrens 659789Sahrens /* 660789Sahrens * Given a device or file, determine if it is part of a pool. 661789Sahrens */ 6622082Seschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **, 6632082Seschrock boolean_t *); 664789Sahrens 665789Sahrens /* 66610830SEric.Schrock@Sun.COM * Label manipulation. 667789Sahrens */ 6682082Seschrock extern int zpool_read_label(int, nvlist_t **); 66910830SEric.Schrock@Sun.COM extern int zpool_clear_label(int); 670789Sahrens 6716423Sgw25295 /* is this zvol valid for use as a dump device? */ 6726423Sgw25295 extern int zvol_check_dump_config(char *); 6736423Sgw25295 6742474Seschrock /* 6758845Samw@Sun.COM * Management interfaces for SMB ACL files 6768845Samw@Sun.COM */ 6778845Samw@Sun.COM 6788845Samw@Sun.COM int zfs_smb_acl_add(libzfs_handle_t *, char *, char *, char *); 6798845Samw@Sun.COM int zfs_smb_acl_remove(libzfs_handle_t *, char *, char *, char *); 6808845Samw@Sun.COM int zfs_smb_acl_purge(libzfs_handle_t *, char *, char *); 6818845Samw@Sun.COM int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *); 6828845Samw@Sun.COM 6838845Samw@Sun.COM /* 6843126Sahl * Enable and disable datasets within a pool by mounting/unmounting and 6853126Sahl * sharing/unsharing them. 6862474Seschrock */ 6873126Sahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int); 6883126Sahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t); 6892474Seschrock 69010817SEric.Schrock@Sun.COM /* 69110817SEric.Schrock@Sun.COM * Mappings between vdev and FRU. 69210817SEric.Schrock@Sun.COM */ 69310817SEric.Schrock@Sun.COM extern void libzfs_fru_refresh(libzfs_handle_t *); 69410817SEric.Schrock@Sun.COM extern const char *libzfs_fru_lookup(libzfs_handle_t *, const char *); 69510817SEric.Schrock@Sun.COM extern const char *libzfs_fru_devpath(libzfs_handle_t *, const char *); 69610817SEric.Schrock@Sun.COM extern boolean_t libzfs_fru_compare(libzfs_handle_t *, const char *, 69710817SEric.Schrock@Sun.COM const char *); 69810817SEric.Schrock@Sun.COM extern boolean_t libzfs_fru_notself(libzfs_handle_t *, const char *); 69910817SEric.Schrock@Sun.COM extern int zpool_fru_set(zpool_handle_t *, uint64_t, const char *); 70010817SEric.Schrock@Sun.COM 701789Sahrens #ifdef __cplusplus 702789Sahrens } 703789Sahrens #endif 704789Sahrens 705789Sahrens #endif /* _LIBZFS_H */ 706