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 /* 2311417SChris.Kirby@sun.com * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24789Sahrens * Use is subject to license terms. 25789Sahrens */ 26789Sahrens 27789Sahrens #ifndef _LIBZFS_H 28789Sahrens #define _LIBZFS_H 29789Sahrens 30789Sahrens #include <assert.h> 31789Sahrens #include <libnvpair.h> 328228SEric.Taylor@Sun.COM #include <sys/mnttab.h> 33789Sahrens #include <sys/param.h> 34789Sahrens #include <sys/types.h> 35789Sahrens #include <sys/varargs.h> 36789Sahrens #include <sys/fs/zfs.h> 374543Smarks #include <sys/avl.h> 384543Smarks #include <ucred.h> 39789Sahrens 40789Sahrens #ifdef __cplusplus 41789Sahrens extern "C" { 42789Sahrens #endif 43789Sahrens 44789Sahrens /* 45789Sahrens * Miscellaneous ZFS constants 46789Sahrens */ 47789Sahrens #define ZFS_MAXNAMELEN MAXNAMELEN 48789Sahrens #define ZPOOL_MAXNAMELEN MAXNAMELEN 49789Sahrens #define ZFS_MAXPROPLEN MAXPATHLEN 505094Slling #define ZPOOL_MAXPROPLEN MAXPATHLEN 51789Sahrens 52789Sahrens /* 532082Seschrock * libzfs errors 542082Seschrock */ 552082Seschrock enum { 562082Seschrock EZFS_NOMEM = 2000, /* out of memory */ 572082Seschrock EZFS_BADPROP, /* invalid property value */ 582082Seschrock EZFS_PROPREADONLY, /* cannot set readonly property */ 592082Seschrock EZFS_PROPTYPE, /* property does not apply to dataset type */ 602082Seschrock EZFS_PROPNONINHERIT, /* property is not inheritable */ 612082Seschrock EZFS_PROPSPACE, /* bad quota or reservation */ 622082Seschrock EZFS_BADTYPE, /* dataset is not of appropriate type */ 632082Seschrock EZFS_BUSY, /* pool or dataset is busy */ 642082Seschrock EZFS_EXISTS, /* pool or dataset already exists */ 652082Seschrock EZFS_NOENT, /* no such pool or dataset */ 662082Seschrock EZFS_BADSTREAM, /* bad backup stream */ 672082Seschrock EZFS_DSREADONLY, /* dataset is readonly */ 682082Seschrock EZFS_VOLTOOBIG, /* volume is too large for 32-bit system */ 692082Seschrock EZFS_INVALIDNAME, /* invalid dataset name */ 702082Seschrock EZFS_BADRESTORE, /* unable to restore to destination */ 712082Seschrock EZFS_BADBACKUP, /* backup failed */ 722082Seschrock EZFS_BADTARGET, /* bad attach/detach/replace target */ 732082Seschrock EZFS_NODEVICE, /* no such device in pool */ 742082Seschrock EZFS_BADDEV, /* invalid device to add */ 752082Seschrock EZFS_NOREPLICAS, /* no valid replicas */ 762082Seschrock EZFS_RESILVERING, /* currently resilvering */ 772082Seschrock EZFS_BADVERSION, /* unsupported version */ 782082Seschrock EZFS_POOLUNAVAIL, /* pool is currently unavailable */ 792082Seschrock EZFS_DEVOVERFLOW, /* too many devices in one vdev */ 802082Seschrock EZFS_BADPATH, /* must be an absolute path */ 812082Seschrock EZFS_CROSSTARGET, /* rename or clone across pool or dataset */ 822082Seschrock EZFS_ZONED, /* used improperly in local zone */ 832082Seschrock EZFS_MOUNTFAILED, /* failed to mount dataset */ 842082Seschrock EZFS_UMOUNTFAILED, /* failed to unmount dataset */ 853126Sahl EZFS_UNSHARENFSFAILED, /* unshare(1M) failed */ 863126Sahl EZFS_SHARENFSFAILED, /* share(1M) failed */ 872082Seschrock EZFS_PERM, /* permission denied */ 882082Seschrock EZFS_NOSPC, /* out of space */ 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 */ 953126Sahl EZFS_UNSHAREISCSIFAILED, /* iscsitgtd failed request to unshare */ 963126Sahl EZFS_SHAREISCSIFAILED, /* iscsitgtd failed request to share */ 973912Slling EZFS_POOLPROPS, /* couldn't retrieve pool props */ 983912Slling EZFS_POOL_NOTSUP, /* ops not supported for this type of pool */ 993912Slling EZFS_POOL_INVALARG, /* invalid argument for this pool operation */ 1003978Smmusante EZFS_NAMETOOLONG, /* dataset name is too long */ 1014276Staylor EZFS_OPENFAILED, /* open of device failed */ 1024276Staylor EZFS_NOCAP, /* couldn't get capacity */ 1034276Staylor EZFS_LABELFAILED, /* write of label failed */ 1044543Smarks EZFS_ISCSISVCUNAVAIL, /* iscsi service unavailable */ 1054543Smarks EZFS_BADWHO, /* invalid permission who */ 1064543Smarks EZFS_BADPERM, /* invalid permission */ 1074543Smarks EZFS_BADPERMSET, /* invalid permission set name */ 1084543Smarks EZFS_NODELEGATION, /* delegated administration is disabled */ 1094543Smarks EZFS_PERMRDONLY, /* pemissions are readonly */ 1105331Samw EZFS_UNSHARESMBFAILED, /* failed to unshare over smb */ 1115331Samw EZFS_SHARESMBFAILED, /* failed to share over smb */ 1125363Seschrock EZFS_BADCACHE, /* bad cache file */ 1135450Sbrendan EZFS_ISL2CACHE, /* device is for the level 2 ARC */ 1146423Sgw25295 EZFS_VDEVNOTSUP, /* unsupported vdev type */ 1157042Sgw25295 EZFS_NOTSUP, /* ops not supported on this dataset */ 1167214Slling EZFS_ACTIVE_SPARE, /* pool has active shared spare devices */ 1179701SGeorge.Wilson@Sun.COM EZFS_UNPLAYED_LOGS, /* log device has unplayed logs */ 11810242Schris.kirby@sun.com EZFS_REFTAG_RELE, /* snapshot release: tag not found */ 11910242Schris.kirby@sun.com EZFS_REFTAG_HOLD, /* snapshot hold: tag already exists */ 12010342Schris.kirby@sun.com EZFS_TAGTOOLONG, /* snapshot hold/rele: tag too long */ 12111007SLori.Alt@Sun.COM EZFS_PIPEFAILED, /* pipe create failed */ 12211007SLori.Alt@Sun.COM EZFS_THREADCREATEFAILED, /* thread create failed */ 12311422SMark.Musante@Sun.COM EZFS_POSTSPLIT_ONLINE, /* onlining a disk after splitting it */ 1243912Slling EZFS_UNKNOWN 1252082Seschrock }; 1262082Seschrock 1272082Seschrock /* 1284543Smarks * The following data structures are all part 1294543Smarks * of the zfs_allow_t data structure which is 1304543Smarks * used for printing 'allow' permissions. 1314543Smarks * It is a linked list of zfs_allow_t's which 1324543Smarks * then contain avl tree's for user/group/sets/... 1334543Smarks * and each one of the entries in those trees have 1344543Smarks * avl tree's for the permissions they belong to and 1354543Smarks * whether they are local,descendent or local+descendent 1364543Smarks * permissions. The AVL trees are used primarily for 1374543Smarks * sorting purposes, but also so that we can quickly find 1384543Smarks * a given user and or permission. 1394543Smarks */ 1404543Smarks typedef struct zfs_perm_node { 1414543Smarks avl_node_t z_node; 1424543Smarks char z_pname[MAXPATHLEN]; 1434543Smarks } zfs_perm_node_t; 1444543Smarks 1454543Smarks typedef struct zfs_allow_node { 1464543Smarks avl_node_t z_node; 1474543Smarks char z_key[MAXPATHLEN]; /* name, such as joe */ 1484543Smarks avl_tree_t z_localdescend; /* local+descendent perms */ 1494543Smarks avl_tree_t z_local; /* local permissions */ 1504543Smarks avl_tree_t z_descend; /* descendent permissions */ 1514543Smarks } zfs_allow_node_t; 1524543Smarks 1534543Smarks typedef struct zfs_allow { 1544543Smarks struct zfs_allow *z_next; 1554543Smarks char z_setpoint[MAXPATHLEN]; 1564543Smarks avl_tree_t z_sets; 1574543Smarks avl_tree_t z_crperms; 1584543Smarks avl_tree_t z_user; 1594543Smarks avl_tree_t z_group; 1604543Smarks avl_tree_t z_everyone; 1614543Smarks } zfs_allow_t; 1624543Smarks 1634543Smarks /* 164789Sahrens * Basic handle types 165789Sahrens */ 166789Sahrens typedef struct zfs_handle zfs_handle_t; 167789Sahrens typedef struct zpool_handle zpool_handle_t; 1682082Seschrock typedef struct libzfs_handle libzfs_handle_t; 1692082Seschrock 1702082Seschrock /* 1712082Seschrock * Library initialization 1722082Seschrock */ 1732082Seschrock extern libzfs_handle_t *libzfs_init(void); 1742082Seschrock extern void libzfs_fini(libzfs_handle_t *); 1752082Seschrock 1762082Seschrock extern libzfs_handle_t *zpool_get_handle(zpool_handle_t *); 1772082Seschrock extern libzfs_handle_t *zfs_get_handle(zfs_handle_t *); 1782082Seschrock 1792082Seschrock extern void libzfs_print_on_error(libzfs_handle_t *, boolean_t); 1802082Seschrock 1812082Seschrock extern int libzfs_errno(libzfs_handle_t *); 1822082Seschrock extern const char *libzfs_error_action(libzfs_handle_t *); 1832082Seschrock extern const char *libzfs_error_description(libzfs_handle_t *); 1848228SEric.Taylor@Sun.COM extern void libzfs_mnttab_init(libzfs_handle_t *); 1858228SEric.Taylor@Sun.COM extern void libzfs_mnttab_fini(libzfs_handle_t *); 1868811SEric.Taylor@Sun.COM extern void libzfs_mnttab_cache(libzfs_handle_t *, boolean_t); 1878228SEric.Taylor@Sun.COM extern int libzfs_mnttab_find(libzfs_handle_t *, const char *, 1888228SEric.Taylor@Sun.COM struct mnttab *); 1898228SEric.Taylor@Sun.COM extern void libzfs_mnttab_add(libzfs_handle_t *, const char *, 1908228SEric.Taylor@Sun.COM const char *, const char *); 1918228SEric.Taylor@Sun.COM extern void libzfs_mnttab_remove(libzfs_handle_t *, const char *); 192789Sahrens 193789Sahrens /* 194789Sahrens * Basic handle functions 195789Sahrens */ 1962082Seschrock extern zpool_handle_t *zpool_open(libzfs_handle_t *, const char *); 1972082Seschrock extern zpool_handle_t *zpool_open_canfail(libzfs_handle_t *, const char *); 198789Sahrens extern void zpool_close(zpool_handle_t *); 199789Sahrens extern const char *zpool_get_name(zpool_handle_t *); 200789Sahrens extern int zpool_get_state(zpool_handle_t *); 2015094Slling extern char *zpool_state_to_name(vdev_state_t, vdev_aux_t); 2026865Srm160521 extern void zpool_free_handles(libzfs_handle_t *); 203789Sahrens 204789Sahrens /* 205789Sahrens * Iterate over all active pools in the system. 206789Sahrens */ 207789Sahrens typedef int (*zpool_iter_f)(zpool_handle_t *, void *); 2082082Seschrock extern int zpool_iter(libzfs_handle_t *, zpool_iter_f, void *); 209789Sahrens 210789Sahrens /* 211789Sahrens * Functions to create and destroy pools 212789Sahrens */ 2132082Seschrock extern int zpool_create(libzfs_handle_t *, const char *, nvlist_t *, 2147184Stimh nvlist_t *, nvlist_t *); 215789Sahrens extern int zpool_destroy(zpool_handle_t *); 216789Sahrens extern int zpool_add(zpool_handle_t *, nvlist_t *); 217789Sahrens 21811422SMark.Musante@Sun.COM typedef struct splitflags { 21911422SMark.Musante@Sun.COM /* do not split, but return the config that would be split off */ 22011422SMark.Musante@Sun.COM int dryrun : 1; 22111422SMark.Musante@Sun.COM 22211422SMark.Musante@Sun.COM /* after splitting, import the pool */ 22311422SMark.Musante@Sun.COM int import : 1; 22411422SMark.Musante@Sun.COM } splitflags_t; 22511422SMark.Musante@Sun.COM 226789Sahrens /* 227789Sahrens * Functions to manipulate pool and vdev state 228789Sahrens */ 229789Sahrens extern int zpool_scrub(zpool_handle_t *, pool_scrub_type_t); 23010921STim.Haley@Sun.COM extern int zpool_clear(zpool_handle_t *, const char *, nvlist_t *); 231789Sahrens 2324451Seschrock extern int zpool_vdev_online(zpool_handle_t *, const char *, int, 2334451Seschrock vdev_state_t *); 2344451Seschrock extern int zpool_vdev_offline(zpool_handle_t *, const char *, boolean_t); 2354451Seschrock extern int zpool_vdev_attach(zpool_handle_t *, const char *, 2364451Seschrock const char *, nvlist_t *, int); 237789Sahrens extern int zpool_vdev_detach(zpool_handle_t *, const char *); 2382082Seschrock extern int zpool_vdev_remove(zpool_handle_t *, const char *); 23911422SMark.Musante@Sun.COM extern int zpool_vdev_split(zpool_handle_t *, char *, nvlist_t **, nvlist_t *, 24011422SMark.Musante@Sun.COM splitflags_t); 2414451Seschrock 24210817SEric.Schrock@Sun.COM extern int zpool_vdev_fault(zpool_handle_t *, uint64_t, vdev_aux_t); 24310817SEric.Schrock@Sun.COM extern int zpool_vdev_degrade(zpool_handle_t *, uint64_t, vdev_aux_t); 2444451Seschrock extern int zpool_vdev_clear(zpool_handle_t *, uint64_t); 2454451Seschrock 2465450Sbrendan extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *, 2477326SEric.Schrock@Sun.COM boolean_t *, boolean_t *); 2489816SGeorge.Wilson@Sun.COM extern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *, 2499816SGeorge.Wilson@Sun.COM boolean_t *, boolean_t *, boolean_t *); 2504276Staylor extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *); 251789Sahrens 252789Sahrens /* 2533912Slling * Functions to manage pool properties 2543912Slling */ 2553912Slling extern int zpool_set_prop(zpool_handle_t *, const char *, const char *); 2564451Seschrock extern int zpool_get_prop(zpool_handle_t *, zpool_prop_t, char *, 2575094Slling size_t proplen, zprop_source_t *); 2585094Slling extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t, 2595094Slling zprop_source_t *); 2605094Slling 2613912Slling extern const char *zpool_prop_to_name(zpool_prop_t); 2623912Slling extern const char *zpool_prop_values(zpool_prop_t); 2633912Slling 2643912Slling /* 265789Sahrens * Pool health statistics. 266789Sahrens */ 267789Sahrens typedef enum { 268789Sahrens /* 269789Sahrens * The following correspond to faults as defined in the (fault.fs.zfs.*) 2701003Slling * event namespace. Each is associated with a corresponding message ID. 271789Sahrens */ 272789Sahrens ZPOOL_STATUS_CORRUPT_CACHE, /* corrupt /kernel/drv/zpool.cache */ 273789Sahrens ZPOOL_STATUS_MISSING_DEV_R, /* missing device with replicas */ 274789Sahrens ZPOOL_STATUS_MISSING_DEV_NR, /* missing device with no replicas */ 275789Sahrens ZPOOL_STATUS_CORRUPT_LABEL_R, /* bad device label with replicas */ 2761003Slling ZPOOL_STATUS_CORRUPT_LABEL_NR, /* bad device label with no replicas */ 277789Sahrens ZPOOL_STATUS_BAD_GUID_SUM, /* sum of device guids didn't match */ 278789Sahrens ZPOOL_STATUS_CORRUPT_POOL, /* pool metadata is corrupted */ 279789Sahrens ZPOOL_STATUS_CORRUPT_DATA, /* data errors in user (meta)data */ 280789Sahrens ZPOOL_STATUS_FAILING_DEV, /* device experiencing errors */ 2811760Seschrock ZPOOL_STATUS_VERSION_NEWER, /* newer on-disk version */ 2823975Sek110237 ZPOOL_STATUS_HOSTID_MISMATCH, /* last accessed by another system */ 2836523Sek110237 ZPOOL_STATUS_IO_FAILURE_WAIT, /* failed I/O, failmode 'wait' */ 2846523Sek110237 ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */ 2858343SEric.Schrock@Sun.COM ZPOOL_STATUS_BAD_LOG, /* cannot read log chain(s) */ 2868343SEric.Schrock@Sun.COM 2878343SEric.Schrock@Sun.COM /* 2888343SEric.Schrock@Sun.COM * These faults have no corresponding message ID. At the time we are 2898343SEric.Schrock@Sun.COM * checking the status, the original reason for the FMA fault (I/O or 2908343SEric.Schrock@Sun.COM * checksum errors) has been lost. 2918343SEric.Schrock@Sun.COM */ 2924451Seschrock ZPOOL_STATUS_FAULTED_DEV_R, /* faulted device with replicas */ 2934451Seschrock ZPOOL_STATUS_FAULTED_DEV_NR, /* faulted device with no replicas */ 294789Sahrens 295789Sahrens /* 296789Sahrens * The following are not faults per se, but still an error possibly 2971003Slling * requiring administrative attention. There is no corresponding 298789Sahrens * message ID. 299789Sahrens */ 3001760Seschrock ZPOOL_STATUS_VERSION_OLDER, /* older on-disk version */ 301789Sahrens ZPOOL_STATUS_RESILVERING, /* device being resilvered */ 302789Sahrens ZPOOL_STATUS_OFFLINE_DEV, /* device online */ 30310151SGeorge.Wilson@Sun.COM ZPOOL_STATUS_REMOVED_DEV, /* removed device */ 304789Sahrens 305789Sahrens /* 306789Sahrens * Finally, the following indicates a healthy pool. 307789Sahrens */ 308789Sahrens ZPOOL_STATUS_OK 309789Sahrens } zpool_status_t; 310789Sahrens 3111544Seschrock extern zpool_status_t zpool_get_status(zpool_handle_t *, char **); 3121544Seschrock extern zpool_status_t zpool_import_status(nvlist_t *, char **); 31311149SGeorge.Wilson@Sun.COM extern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh); 314789Sahrens 315789Sahrens /* 316789Sahrens * Statistics and configuration functions. 317789Sahrens */ 3181544Seschrock extern nvlist_t *zpool_get_config(zpool_handle_t *, nvlist_t **); 3192142Seschrock extern int zpool_refresh_stats(zpool_handle_t *, boolean_t *); 3203444Sek110237 extern int zpool_get_errlog(zpool_handle_t *, nvlist_t **); 3211544Seschrock 322789Sahrens /* 323789Sahrens * Import and export functions 324789Sahrens */ 3257214Slling extern int zpool_export(zpool_handle_t *, boolean_t); 3268211SGeorge.Wilson@Sun.COM extern int zpool_export_force(zpool_handle_t *); 3272082Seschrock extern int zpool_import(libzfs_handle_t *, nvlist_t *, const char *, 3285094Slling char *altroot); 3295094Slling extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *, 3306643Seschrock nvlist_t *, boolean_t); 331789Sahrens 332789Sahrens /* 333789Sahrens * Search for pools to import 334789Sahrens */ 3356807Sck153898 extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **); 3365994Sck153898 extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *, 3376957Sck153898 char *, uint64_t); 3386807Sck153898 extern nvlist_t *zpool_find_import_byname(libzfs_handle_t *, int, char **, 3396807Sck153898 char *); 3406807Sck153898 extern nvlist_t *zpool_find_import_byguid(libzfs_handle_t *, int, char **, 3416807Sck153898 uint64_t); 3426807Sck153898 extern nvlist_t *zpool_find_import_activeok(libzfs_handle_t *, int, char **); 343789Sahrens 344789Sahrens /* 3451354Seschrock * Miscellaneous pool functions 3461354Seschrock */ 3474543Smarks struct zfs_cmd; 3484543Smarks 34910685SGeorge.Wilson@Sun.COM extern const char *hist_event_table[LOG_END]; 35010685SGeorge.Wilson@Sun.COM 35110594SGeorge.Wilson@Sun.COM extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *, 35210594SGeorge.Wilson@Sun.COM boolean_t verbose); 3535094Slling extern int zpool_upgrade(zpool_handle_t *, uint64_t); 3542926Sek110237 extern int zpool_get_history(zpool_handle_t *, nvlist_t **); 35510685SGeorge.Wilson@Sun.COM extern int zpool_history_unpack(char *, uint64_t, uint64_t *, 35610685SGeorge.Wilson@Sun.COM nvlist_t ***, uint_t *); 3574988Sek110237 extern void zpool_set_history_str(const char *subcommand, int argc, 3584988Sek110237 char **argv, char *history_str); 3594988Sek110237 extern int zpool_stage_history(libzfs_handle_t *, const char *); 3603444Sek110237 extern void zpool_obj_to_path(zpool_handle_t *, uint64_t, uint64_t, char *, 3613444Sek110237 size_t len); 3624543Smarks extern int zfs_ioctl(libzfs_handle_t *, int, struct zfs_cmd *); 3639160SSherry.Moore@Sun.COM extern int zpool_get_physpath(zpool_handle_t *, char *, size_t); 36410921STim.Haley@Sun.COM extern void zpool_explain_recover(libzfs_handle_t *, const char *, int, 36510921STim.Haley@Sun.COM nvlist_t *); 3669160SSherry.Moore@Sun.COM 3671354Seschrock /* 368789Sahrens * Basic handle manipulations. These functions do not create or destroy the 369789Sahrens * underlying datasets, only the references to them. 370789Sahrens */ 3712082Seschrock extern zfs_handle_t *zfs_open(libzfs_handle_t *, const char *, int); 372789Sahrens extern void zfs_close(zfs_handle_t *); 373789Sahrens extern zfs_type_t zfs_get_type(const zfs_handle_t *); 374789Sahrens extern const char *zfs_get_name(const zfs_handle_t *); 3757538SRichard.Morris@Sun.COM extern zpool_handle_t *zfs_get_pool_handle(const zfs_handle_t *); 376789Sahrens 377789Sahrens /* 378789Sahrens * Property management functions. Some functions are shared with the kernel, 3791003Slling * and are found in sys/fs/zfs.h. 380789Sahrens */ 3815094Slling 3825094Slling /* 3835094Slling * zfs dataset property management 3845094Slling */ 3855094Slling extern const char *zfs_prop_default_string(zfs_prop_t); 3862676Seschrock extern uint64_t zfs_prop_default_numeric(zfs_prop_t); 3872676Seschrock extern const char *zfs_prop_column_name(zfs_prop_t); 3882676Seschrock extern boolean_t zfs_prop_align_right(zfs_prop_t); 3892676Seschrock 3907184Stimh extern nvlist_t *zfs_valid_proplist(libzfs_handle_t *, zfs_type_t, 3917184Stimh nvlist_t *, uint64_t, zfs_handle_t *, const char *); 3927184Stimh 3935094Slling extern const char *zfs_prop_to_name(zfs_prop_t); 3945094Slling extern int zfs_prop_set(zfs_handle_t *, const char *, const char *); 3955094Slling extern int zfs_prop_get(zfs_handle_t *, zfs_prop_t, char *, size_t, 3965094Slling zprop_source_t *, char *, size_t, boolean_t); 39711022STom.Erickson@Sun.COM extern int zfs_prop_get_recvd(zfs_handle_t *, const char *, char *, size_t, 39811022STom.Erickson@Sun.COM boolean_t); 3995094Slling extern int zfs_prop_get_numeric(zfs_handle_t *, zfs_prop_t, uint64_t *, 4005094Slling zprop_source_t *, char *, size_t); 4019469SLin.Ling@Sun.COM extern int zfs_prop_get_userquota_int(zfs_handle_t *zhp, const char *propname, 4029469SLin.Ling@Sun.COM uint64_t *propvalue); 4039396SMatthew.Ahrens@Sun.COM extern int zfs_prop_get_userquota(zfs_handle_t *zhp, const char *propname, 4049396SMatthew.Ahrens@Sun.COM char *propbuf, int proplen, boolean_t literal); 4055094Slling extern uint64_t zfs_prop_get_int(zfs_handle_t *, zfs_prop_t); 40611022STom.Erickson@Sun.COM extern int zfs_prop_inherit(zfs_handle_t *, const char *, boolean_t); 4075094Slling extern const char *zfs_prop_values(zfs_prop_t); 4085094Slling extern int zfs_prop_is_string(zfs_prop_t prop); 4095094Slling extern nvlist_t *zfs_get_user_props(zfs_handle_t *); 41011022STom.Erickson@Sun.COM extern nvlist_t *zfs_get_recvd_props(zfs_handle_t *); 4115094Slling 4125094Slling typedef struct zprop_list { 4135094Slling int pl_prop; 4142676Seschrock char *pl_user_prop; 4155094Slling struct zprop_list *pl_next; 4162676Seschrock boolean_t pl_all; 4172676Seschrock size_t pl_width; 41811022STom.Erickson@Sun.COM size_t pl_recvd_width; 4192676Seschrock boolean_t pl_fixed; 4205094Slling } zprop_list_t; 4213912Slling 42211022STom.Erickson@Sun.COM extern int zfs_expand_proplist(zfs_handle_t *, zprop_list_t **, boolean_t); 4238802SSanjeev.Bagewadi@Sun.COM extern void zfs_prune_proplist(zfs_handle_t *, uint8_t *); 424789Sahrens 425789Sahrens #define ZFS_MOUNTPOINT_NONE "none" 426789Sahrens #define ZFS_MOUNTPOINT_LEGACY "legacy" 427789Sahrens 428789Sahrens /* 4295094Slling * zpool property management 4305094Slling */ 4315094Slling extern int zpool_expand_proplist(zpool_handle_t *, zprop_list_t **); 4325094Slling extern const char *zpool_prop_default_string(zpool_prop_t); 4335094Slling extern uint64_t zpool_prop_default_numeric(zpool_prop_t); 4345094Slling extern const char *zpool_prop_column_name(zpool_prop_t); 4355094Slling extern boolean_t zpool_prop_align_right(zpool_prop_t); 4365094Slling 4375094Slling /* 4385094Slling * Functions shared by zfs and zpool property management. 4393912Slling */ 4405094Slling extern int zprop_iter(zprop_func func, void *cb, boolean_t show_all, 4415094Slling boolean_t ordered, zfs_type_t type); 4425094Slling extern int zprop_get_list(libzfs_handle_t *, char *, zprop_list_t **, 4435094Slling zfs_type_t); 4445094Slling extern void zprop_free_list(zprop_list_t *); 4455094Slling 44611022STom.Erickson@Sun.COM #define ZFS_GET_NCOLS 5 44711022STom.Erickson@Sun.COM 44811022STom.Erickson@Sun.COM typedef enum { 44911022STom.Erickson@Sun.COM GET_COL_NONE, 45011022STom.Erickson@Sun.COM GET_COL_NAME, 45111022STom.Erickson@Sun.COM GET_COL_PROPERTY, 45211022STom.Erickson@Sun.COM GET_COL_VALUE, 45311022STom.Erickson@Sun.COM GET_COL_RECVD, 45411022STom.Erickson@Sun.COM GET_COL_SOURCE 45511022STom.Erickson@Sun.COM } zfs_get_column_t; 45611022STom.Erickson@Sun.COM 4575094Slling /* 4585094Slling * Functions for printing zfs or zpool properties 4595094Slling */ 4605094Slling typedef struct zprop_get_cbdata { 4613912Slling int cb_sources; 46211022STom.Erickson@Sun.COM zfs_get_column_t cb_columns[ZFS_GET_NCOLS]; 46311022STom.Erickson@Sun.COM int cb_colwidths[ZFS_GET_NCOLS + 1]; 4643912Slling boolean_t cb_scripted; 4653912Slling boolean_t cb_literal; 4663912Slling boolean_t cb_first; 4675094Slling zprop_list_t *cb_proplist; 4685094Slling zfs_type_t cb_type; 4695094Slling } zprop_get_cbdata_t; 4703912Slling 4715094Slling void zprop_print_one_property(const char *, zprop_get_cbdata_t *, 47211022STom.Erickson@Sun.COM const char *, const char *, zprop_source_t, const char *, 47311022STom.Erickson@Sun.COM const char *); 4743912Slling 4753912Slling /* 476789Sahrens * Iterator functions. 477789Sahrens */ 478789Sahrens typedef int (*zfs_iter_f)(zfs_handle_t *, void *); 4792082Seschrock extern int zfs_iter_root(libzfs_handle_t *, zfs_iter_f, void *); 480789Sahrens extern int zfs_iter_children(zfs_handle_t *, zfs_iter_f, void *); 4812474Seschrock extern int zfs_iter_dependents(zfs_handle_t *, boolean_t, zfs_iter_f, void *); 4821356Seschrock extern int zfs_iter_filesystems(zfs_handle_t *, zfs_iter_f, void *); 4831356Seschrock extern int zfs_iter_snapshots(zfs_handle_t *, zfs_iter_f, void *); 48410342Schris.kirby@sun.com extern int zfs_iter_snapshots_sorted(zfs_handle_t *, zfs_iter_f, void *); 485789Sahrens 486789Sahrens /* 487789Sahrens * Functions to create and destroy datasets. 488789Sahrens */ 4892082Seschrock extern int zfs_create(libzfs_handle_t *, const char *, zfs_type_t, 4902676Seschrock nvlist_t *); 4914490Svb160487 extern int zfs_create_ancestors(libzfs_handle_t *, const char *); 49210242Schris.kirby@sun.com extern int zfs_destroy(zfs_handle_t *, boolean_t); 49310242Schris.kirby@sun.com extern int zfs_destroy_snaps(zfs_handle_t *, char *, boolean_t); 4942676Seschrock extern int zfs_clone(zfs_handle_t *, const char *, nvlist_t *); 4957265Sahrens extern int zfs_snapshot(libzfs_handle_t *, const char *, boolean_t, nvlist_t *); 4965749Sahrens extern int zfs_rollback(zfs_handle_t *, zfs_handle_t *, boolean_t); 4974490Svb160487 extern int zfs_rename(zfs_handle_t *, const char *, boolean_t); 49811007SLori.Alt@Sun.COM 49911007SLori.Alt@Sun.COM typedef struct sendflags { 50011007SLori.Alt@Sun.COM /* print informational messages (ie, -v was specified) */ 50111007SLori.Alt@Sun.COM int verbose : 1; 50211007SLori.Alt@Sun.COM 50311022STom.Erickson@Sun.COM /* recursive send (ie, -R) */ 50411007SLori.Alt@Sun.COM int replicate : 1; 50511007SLori.Alt@Sun.COM 50611007SLori.Alt@Sun.COM /* for incrementals, do all intermediate snapshots */ 50711022STom.Erickson@Sun.COM int doall : 1; /* (ie, -I) */ 50811007SLori.Alt@Sun.COM 50911007SLori.Alt@Sun.COM /* if dataset is a clone, do incremental from its origin */ 51011007SLori.Alt@Sun.COM int fromorigin : 1; 51111007SLori.Alt@Sun.COM 51211007SLori.Alt@Sun.COM /* do deduplication */ 51311007SLori.Alt@Sun.COM int dedup : 1; 51411022STom.Erickson@Sun.COM 51511022STom.Erickson@Sun.COM /* send properties (ie, -p) */ 51611022STom.Erickson@Sun.COM int props : 1; 51711007SLori.Alt@Sun.COM } sendflags_t; 51811007SLori.Alt@Sun.COM 51911007SLori.Alt@Sun.COM typedef boolean_t (snapfilter_cb_t)(zfs_handle_t *, void *); 52011007SLori.Alt@Sun.COM 5215367Sahrens extern int zfs_send(zfs_handle_t *, const char *, const char *, 52211007SLori.Alt@Sun.COM sendflags_t, int, snapfilter_cb_t, void *); 52311007SLori.Alt@Sun.COM 5242082Seschrock extern int zfs_promote(zfs_handle_t *); 52510342Schris.kirby@sun.com extern int zfs_hold(zfs_handle_t *, const char *, const char *, boolean_t, 52611417SChris.Kirby@sun.com boolean_t, boolean_t); 52710342Schris.kirby@sun.com extern int zfs_hold_range(zfs_handle_t *, const char *, const char *, 52810342Schris.kirby@sun.com const char *, boolean_t); 52910242Schris.kirby@sun.com extern int zfs_release(zfs_handle_t *, const char *, const char *, boolean_t); 53010342Schris.kirby@sun.com extern int zfs_release_range(zfs_handle_t *, const char *, const char *, 53110342Schris.kirby@sun.com const char *); 53211449SEric.Taylor@Sun.COM extern uint64_t zvol_volsize_to_reservation(uint64_t, nvlist_t *); 533789Sahrens 5349554SMatthew.Ahrens@Sun.COM typedef int (*zfs_userspace_cb_t)(void *arg, const char *domain, 5359396SMatthew.Ahrens@Sun.COM uid_t rid, uint64_t space); 5369396SMatthew.Ahrens@Sun.COM 5379396SMatthew.Ahrens@Sun.COM extern int zfs_userspace(zfs_handle_t *zhp, zfs_userquota_prop_t type, 5389396SMatthew.Ahrens@Sun.COM zfs_userspace_cb_t func, void *arg); 5399396SMatthew.Ahrens@Sun.COM 5405367Sahrens typedef struct recvflags { 5415446Sahrens /* print informational messages (ie, -v was specified) */ 5425501Seschrock int verbose : 1; 5435446Sahrens 5445446Sahrens /* the destination is a prefix, not the exact fs (ie, -d) */ 5455501Seschrock int isprefix : 1; 5465446Sahrens 547*11461STom.Erickson@Sun.COM /* 548*11461STom.Erickson@Sun.COM * Only the tail of the sent snapshot path is appended to the 549*11461STom.Erickson@Sun.COM * destination to determine the received snapshot name (ie, -e). 550*11461STom.Erickson@Sun.COM */ 551*11461STom.Erickson@Sun.COM int istail : 1; 552*11461STom.Erickson@Sun.COM 5535446Sahrens /* do not actually do the recv, just check if it would work (ie, -n) */ 5545501Seschrock int dryrun : 1; 5555446Sahrens 5565446Sahrens /* rollback/destroy filesystems as necessary (eg, -F) */ 5575501Seschrock int force : 1; 5585446Sahrens 5595446Sahrens /* set "canmount=off" on all modified filesystems */ 5605501Seschrock int canmountoff : 1; 5615446Sahrens 5625446Sahrens /* byteswap flag is used internally; callers need not specify */ 5635501Seschrock int byteswap : 1; 5648584SLori.Alt@Sun.COM 5658584SLori.Alt@Sun.COM /* do not mount file systems as they are extracted (private) */ 5668584SLori.Alt@Sun.COM int nomount : 1; 5675367Sahrens } recvflags_t; 5685367Sahrens 5695367Sahrens extern int zfs_receive(libzfs_handle_t *, const char *, recvflags_t, 5705367Sahrens int, avl_tree_t *); 5715367Sahrens 572789Sahrens /* 573789Sahrens * Miscellaneous functions. 574789Sahrens */ 575789Sahrens extern const char *zfs_type_to_name(zfs_type_t); 576789Sahrens extern void zfs_refresh_properties(zfs_handle_t *); 577789Sahrens extern int zfs_name_valid(const char *, zfs_type_t); 5783635Sck153898 extern zfs_handle_t *zfs_path_to_zhandle(libzfs_handle_t *, char *, zfs_type_t); 5794490Svb160487 extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *, 5804490Svb160487 zfs_type_t); 5815713Srm160521 extern int zfs_spa_version(zfs_handle_t *, int *); 582789Sahrens 583789Sahrens /* 584789Sahrens * Mount support functions. 585789Sahrens */ 5863444Sek110237 extern boolean_t is_mounted(libzfs_handle_t *, const char *special, char **); 5872082Seschrock extern boolean_t zfs_is_mounted(zfs_handle_t *, char **); 588789Sahrens extern int zfs_mount(zfs_handle_t *, const char *, int); 589789Sahrens extern int zfs_unmount(zfs_handle_t *, const char *, int); 590789Sahrens extern int zfs_unmountall(zfs_handle_t *, int); 591789Sahrens 592789Sahrens /* 593789Sahrens * Share support functions. 594789Sahrens */ 5953126Sahl extern boolean_t zfs_is_shared(zfs_handle_t *); 596789Sahrens extern int zfs_share(zfs_handle_t *); 5973126Sahl extern int zfs_unshare(zfs_handle_t *); 5983126Sahl 5993126Sahl /* 6004451Seschrock * Protocol-specific share support functions. 6013126Sahl */ 6023126Sahl extern boolean_t zfs_is_shared_nfs(zfs_handle_t *, char **); 6035331Samw extern boolean_t zfs_is_shared_smb(zfs_handle_t *, char **); 6043126Sahl extern int zfs_share_nfs(zfs_handle_t *); 6055331Samw extern int zfs_share_smb(zfs_handle_t *); 6065331Samw extern int zfs_shareall(zfs_handle_t *); 6073126Sahl extern int zfs_unshare_nfs(zfs_handle_t *, const char *); 6085331Samw extern int zfs_unshare_smb(zfs_handle_t *, const char *); 6093126Sahl extern int zfs_unshareall_nfs(zfs_handle_t *); 6105331Samw extern int zfs_unshareall_smb(zfs_handle_t *); 6115331Samw extern int zfs_unshareall_bypath(zfs_handle_t *, const char *); 6125331Samw extern int zfs_unshareall(zfs_handle_t *); 6133126Sahl extern boolean_t zfs_is_shared_iscsi(zfs_handle_t *); 6143126Sahl extern int zfs_share_iscsi(zfs_handle_t *); 6153126Sahl extern int zfs_unshare_iscsi(zfs_handle_t *); 6164543Smarks extern int zfs_iscsi_perm_check(libzfs_handle_t *, char *, ucred_t *); 6178845Samw@Sun.COM extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *, 6185331Samw void *, void *, int, zfs_share_op_t); 619789Sahrens 620789Sahrens /* 621789Sahrens * When dealing with nvlists, verify() is extremely useful 622789Sahrens */ 623789Sahrens #ifdef NDEBUG 624789Sahrens #define verify(EX) ((void)(EX)) 625789Sahrens #else 626789Sahrens #define verify(EX) assert(EX) 627789Sahrens #endif 628789Sahrens 629789Sahrens /* 630789Sahrens * Utility function to convert a number to a human-readable form. 631789Sahrens */ 632789Sahrens extern void zfs_nicenum(uint64_t, char *, size_t); 6332676Seschrock extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *); 634789Sahrens 635789Sahrens /* 636789Sahrens * Given a device or file, determine if it is part of a pool. 637789Sahrens */ 6382082Seschrock extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **, 6392082Seschrock boolean_t *); 640789Sahrens 641789Sahrens /* 64210830SEric.Schrock@Sun.COM * Label manipulation. 643789Sahrens */ 6442082Seschrock extern int zpool_read_label(int, nvlist_t **); 64510830SEric.Schrock@Sun.COM extern int zpool_clear_label(int); 646789Sahrens 6476423Sgw25295 /* is this zvol valid for use as a dump device? */ 6486423Sgw25295 extern int zvol_check_dump_config(char *); 6496423Sgw25295 6502474Seschrock /* 6518845Samw@Sun.COM * Management interfaces for SMB ACL files 6528845Samw@Sun.COM */ 6538845Samw@Sun.COM 6548845Samw@Sun.COM int zfs_smb_acl_add(libzfs_handle_t *, char *, char *, char *); 6558845Samw@Sun.COM int zfs_smb_acl_remove(libzfs_handle_t *, char *, char *, char *); 6568845Samw@Sun.COM int zfs_smb_acl_purge(libzfs_handle_t *, char *, char *); 6578845Samw@Sun.COM int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *); 6588845Samw@Sun.COM 6598845Samw@Sun.COM /* 6603126Sahl * Enable and disable datasets within a pool by mounting/unmounting and 6613126Sahl * sharing/unsharing them. 6622474Seschrock */ 6633126Sahl extern int zpool_enable_datasets(zpool_handle_t *, const char *, int); 6643126Sahl extern int zpool_disable_datasets(zpool_handle_t *, boolean_t); 6652474Seschrock 66610817SEric.Schrock@Sun.COM /* 66710817SEric.Schrock@Sun.COM * Mappings between vdev and FRU. 66810817SEric.Schrock@Sun.COM */ 66910817SEric.Schrock@Sun.COM extern void libzfs_fru_refresh(libzfs_handle_t *); 67010817SEric.Schrock@Sun.COM extern const char *libzfs_fru_lookup(libzfs_handle_t *, const char *); 67110817SEric.Schrock@Sun.COM extern const char *libzfs_fru_devpath(libzfs_handle_t *, const char *); 67210817SEric.Schrock@Sun.COM extern boolean_t libzfs_fru_compare(libzfs_handle_t *, const char *, 67310817SEric.Schrock@Sun.COM const char *); 67410817SEric.Schrock@Sun.COM extern boolean_t libzfs_fru_notself(libzfs_handle_t *, const char *); 67510817SEric.Schrock@Sun.COM extern int zpool_fru_set(zpool_handle_t *, uint64_t, const char *); 67610817SEric.Schrock@Sun.COM 677789Sahrens #ifdef __cplusplus 678789Sahrens } 679789Sahrens #endif 680789Sahrens 681789Sahrens #endif /* _LIBZFS_H */ 682