1789Sahrens /*
25951Sdougm  * CDDL HEADER SART
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
51544Seschrock  * Common Development and Distribution License (the "License").
61544Seschrock  * 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 /*
23*8802SSanjeev.Bagewadi@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24789Sahrens  * Use is subject to license terms.
25789Sahrens  */
26789Sahrens 
27789Sahrens #ifndef	_LIBFS_IMPL_H
28789Sahrens #define	_LIBFS_IMPL_H
29789Sahrens 
30789Sahrens #include <sys/dmu.h>
31789Sahrens #include <sys/fs/zfs.h>
32789Sahrens #include <sys/zfs_ioctl.h>
33789Sahrens #include <sys/zfs_acl.h>
344543Smarks #include <sys/spa.h>
35789Sahrens #include <sys/nvpair.h>
36789Sahrens 
372082Seschrock #include <libuutil.h>
38789Sahrens #include <libzfs.h>
394180Sdougm #include <libshare.h>
40789Sahrens 
41789Sahrens #ifdef	__cplusplus
42789Sahrens extern "C" {
43789Sahrens #endif
44789Sahrens 
456442Sgw25295 #ifdef	VERIFY
466442Sgw25295 #undef	VERIFY
476442Sgw25295 #endif
486442Sgw25295 #define	VERIFY	verify
496442Sgw25295 
502082Seschrock struct libzfs_handle {
512082Seschrock 	int libzfs_error;
522082Seschrock 	int libzfs_fd;
532082Seschrock 	FILE *libzfs_mnttab;
542082Seschrock 	FILE *libzfs_sharetab;
556865Srm160521 	zpool_handle_t *libzfs_pool_handles;
562082Seschrock 	uu_avl_pool_t *libzfs_ns_avlpool;
572082Seschrock 	uu_avl_t *libzfs_ns_avl;
582082Seschrock 	uint64_t libzfs_ns_gen;
592082Seschrock 	int libzfs_desc_active;
602082Seschrock 	char libzfs_action[1024];
612082Seschrock 	char libzfs_desc[1024];
624543Smarks 	char *libzfs_log_str;
632082Seschrock 	int libzfs_printerr;
644180Sdougm 	void *libzfs_sharehdl; /* libshare handle */
655951Sdougm 	uint_t libzfs_shareflags;
668228SEric.Taylor@Sun.COM 	avl_tree_t libzfs_mnttab_cache;
672082Seschrock };
685951Sdougm #define	ZFSSHARE_MISS	0x01	/* Didn't find entry in cache */
692082Seschrock 
70789Sahrens struct zfs_handle {
712082Seschrock 	libzfs_handle_t *zfs_hdl;
726865Srm160521 	zpool_handle_t *zpool_hdl;
73789Sahrens 	char zfs_name[ZFS_MAXNAMELEN];
742885Sahrens 	zfs_type_t zfs_type; /* type including snapshot */
752885Sahrens 	zfs_type_t zfs_head_type; /* type excluding snapshot */
76789Sahrens 	dmu_objset_stats_t zfs_dmustats;
771356Seschrock 	nvlist_t *zfs_props;
782676Seschrock 	nvlist_t *zfs_user_props;
792474Seschrock 	boolean_t zfs_mntcheck;
80789Sahrens 	char *zfs_mntopts;
81*8802SSanjeev.Bagewadi@Sun.COM 	uint8_t *zfs_props_table;
82789Sahrens };
83789Sahrens 
842676Seschrock /*
852676Seschrock  * This is different from checking zfs_type, because it will also catch
862676Seschrock  * snapshots of volumes.
872676Seschrock  */
882885Sahrens #define	ZFS_IS_VOLUME(zhp) ((zhp)->zfs_head_type == ZFS_TYPE_VOLUME)
892676Seschrock 
90789Sahrens struct zpool_handle {
912082Seschrock 	libzfs_handle_t *zpool_hdl;
926865Srm160521 	zpool_handle_t *zpool_next;
93789Sahrens 	char zpool_name[ZPOOL_MAXNAMELEN];
94789Sahrens 	int zpool_state;
95789Sahrens 	size_t zpool_config_size;
96789Sahrens 	nvlist_t *zpool_config;
97952Seschrock 	nvlist_t *zpool_old_config;
983912Slling 	nvlist_t *zpool_props;
994276Staylor 	diskaddr_t zpool_start_block;
100789Sahrens };
101789Sahrens 
1025331Samw typedef  enum {
1035331Samw 	PROTO_NFS = 0,
1045331Samw 	PROTO_SMB = 1,
1055331Samw 	PROTO_END = 2
1065331Samw } zfs_share_proto_t;
1075331Samw 
1085331Samw /*
1095331Samw  * The following can be used as a bitmask and any new values
1105331Samw  * added must preserve that capability.
1115331Samw  */
1125331Samw typedef enum {
1135331Samw 	SHARED_NOT_SHARED = 0x0,
1145331Samw 	SHARED_ISCSI = 0x1,
1155331Samw 	SHARED_NFS = 0x2,
1165331Samw 	SHARED_SMB = 0x4
1175331Samw } zfs_share_type_t;
1185331Samw 
1193237Slling int zfs_error(libzfs_handle_t *, int, const char *);
1203237Slling int zfs_error_fmt(libzfs_handle_t *, int, const char *, ...);
1212082Seschrock void zfs_error_aux(libzfs_handle_t *, const char *, ...);
1222082Seschrock void *zfs_alloc(libzfs_handle_t *, size_t);
1232676Seschrock void *zfs_realloc(libzfs_handle_t *, void *, size_t, size_t);
1242082Seschrock char *zfs_strdup(libzfs_handle_t *, const char *);
1252082Seschrock int no_memory(libzfs_handle_t *);
126789Sahrens 
1273237Slling int zfs_standard_error(libzfs_handle_t *, int, const char *);
1283237Slling int zfs_standard_error_fmt(libzfs_handle_t *, int, const char *, ...);
1293237Slling int zpool_standard_error(libzfs_handle_t *, int, const char *);
1303237Slling int zpool_standard_error_fmt(libzfs_handle_t *, int, const char *, ...);
131789Sahrens 
1322474Seschrock int get_dependents(libzfs_handle_t *, boolean_t, const char *, char ***,
1332474Seschrock     size_t *);
134789Sahrens 
1353912Slling 
1365094Slling int zprop_parse_value(libzfs_handle_t *, nvpair_t *, int, zfs_type_t,
1375094Slling     nvlist_t *, char **, uint64_t *, const char *);
1385094Slling int zprop_expand_list(libzfs_handle_t *hdl, zprop_list_t **plp,
1395094Slling     zfs_type_t type);
1403912Slling 
1417366STim.Haley@Sun.COM /*
1427366STim.Haley@Sun.COM  * Use this changelist_gather() flag to force attempting mounts
1437366STim.Haley@Sun.COM  * on each change node regardless of whether or not it is currently
1447366STim.Haley@Sun.COM  * mounted.
1457366STim.Haley@Sun.COM  */
1467366STim.Haley@Sun.COM #define	CL_GATHER_MOUNT_ALWAYS	1
1477366STim.Haley@Sun.COM 
148789Sahrens typedef struct prop_changelist prop_changelist_t;
149789Sahrens 
1502676Seschrock int zcmd_alloc_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, size_t);
1515094Slling int zcmd_write_src_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *);
1525094Slling int zcmd_write_conf_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *);
1532676Seschrock int zcmd_expand_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *);
1542676Seschrock int zcmd_read_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t **);
1552676Seschrock void zcmd_free_nvlists(zfs_cmd_t *);
1562676Seschrock 
157789Sahrens int changelist_prefix(prop_changelist_t *);
158789Sahrens int changelist_postfix(prop_changelist_t *);
159789Sahrens void changelist_rename(prop_changelist_t *, const char *, const char *);
1605367Sahrens void changelist_remove(prop_changelist_t *, const char *);
161789Sahrens void changelist_free(prop_changelist_t *);
1627366STim.Haley@Sun.COM prop_changelist_t *changelist_gather(zfs_handle_t *, zfs_prop_t, int, int);
1635331Samw int changelist_unshare(prop_changelist_t *, zfs_share_proto_t *);
164789Sahrens int changelist_haszonedchild(prop_changelist_t *);
165789Sahrens 
166789Sahrens void remove_mountpoint(zfs_handle_t *);
1675367Sahrens int create_parents(libzfs_handle_t *, char *, int);
1686027Srm160521 boolean_t isa_child_of(const char *dataset, const char *parent);
169789Sahrens 
1702082Seschrock zfs_handle_t *make_dataset_handle(libzfs_handle_t *, const char *);
1711544Seschrock 
1722142Seschrock int zpool_open_silent(libzfs_handle_t *, const char *, zpool_handle_t **);
173789Sahrens 
1742082Seschrock int zvol_create_link(libzfs_handle_t *, const char *);
1752082Seschrock int zvol_remove_link(libzfs_handle_t *, const char *);
1763126Sahl int zpool_iter_zvol(zpool_handle_t *, int (*)(const char *, void *), void *);
1776423Sgw25295 boolean_t zpool_name_valid(libzfs_handle_t *, boolean_t, const char *);
178789Sahrens 
1792082Seschrock void namespace_clear(libzfs_handle_t *);
180789Sahrens 
1814180Sdougm /*
1824180Sdougm  * libshare (sharemgr) interfaces used internally.
1834180Sdougm  */
1844180Sdougm 
1854180Sdougm extern int zfs_init_libshare(libzfs_handle_t *, int);
1864180Sdougm extern void zfs_uninit_libshare(libzfs_handle_t *);
1875331Samw extern int zfs_parse_options(char *, zfs_share_proto_t);
1884180Sdougm 
1895331Samw extern int zfs_unshare_proto(zfs_handle_t *zhp,
1905331Samw     const char *, zfs_share_proto_t *);
191789Sahrens #ifdef	__cplusplus
192789Sahrens }
193789Sahrens #endif
194789Sahrens 
195789Sahrens #endif	/* _LIBFS_IMPL_H */
196