libzfs_impl.h revision 205198
1230592Sken/* 2281564Sslm * CDDL HEADER SART 3281564Sslm * 4230592Sken * The contents of this file are subject to the terms of the 5230592Sken * Common Development and Distribution License (the "License"). 6230592Sken * You may not use this file except in compliance with the License. 7230592Sken * 8230592Sken * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9230592Sken * or http://www.opensolaris.org/os/licensing. 10230592Sken * See the License for the specific language governing permissions 11230592Sken * and limitations under the License. 12230592Sken * 13230592Sken * When distributing Covered Code, include this CDDL HEADER in each 14230592Sken * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15230592Sken * If applicable, add the following below this CDDL HEADER, with the 16230592Sken * fields enclosed by brackets "[]" replaced with your own identifying 17230592Sken * information: Portions Copyright [yyyy] [name of copyright owner] 18230592Sken * 19230592Sken * CDDL HEADER END 20230592Sken */ 21230592Sken 22230592Sken/* 23230592Sken * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24230592Sken * Use is subject to license terms. 25230592Sken */ 26230592Sken 27281564Sslm#ifndef _LIBFS_IMPL_H 28230592Sken#define _LIBFS_IMPL_H 29230592Sken 30230592Sken#include <sys/dmu.h> 31230592Sken#include <sys/fs/zfs.h> 32230592Sken#include <sys/zfs_ioctl.h> 33230592Sken#include <sys/zfs_acl.h> 34230592Sken#include <sys/spa.h> 35230592Sken#include <sys/nvpair.h> 36230592Sken 37230592Sken#include <libshare.h> 38230592Sken#include <libuutil.h> 39230592Sken#include <libzfs.h> 40230592Sken 41230592Sken#ifdef __cplusplus 42230592Skenextern "C" { 43230592Sken#endif 44230592Sken 45230592Sken#ifdef VERIFY 46230592Sken#undef VERIFY 47230592Sken#endif 48230592Sken#define VERIFY verify 49230592Sken 50230592Skenstruct libzfs_handle { 51230592Sken int libzfs_error; 52230592Sken int libzfs_fd; 53230592Sken FILE *libzfs_mnttab; 54230592Sken FILE *libzfs_sharetab; 55230592Sken zpool_handle_t *libzfs_pool_handles; 56230592Sken uu_avl_pool_t *libzfs_ns_avlpool; 57230592Sken uu_avl_t *libzfs_ns_avl; 58230592Sken uint64_t libzfs_ns_gen; 59230592Sken int libzfs_desc_active; 60230592Sken char libzfs_action[1024]; 61230592Sken char libzfs_desc[1024]; 62230592Sken char *libzfs_log_str; 63230592Sken int libzfs_printerr; 64230592Sken void *libzfs_sharehdl; /* libshare handle */ 65230592Sken uint_t libzfs_shareflags; 66230592Sken}; 67230592Sken#define ZFSSHARE_MISS 0x01 /* Didn't find entry in cache */ 68230592Sken 69230592Skenstruct zfs_handle { 70230592Sken libzfs_handle_t *zfs_hdl; 71230592Sken zpool_handle_t *zpool_hdl; 72230592Sken char zfs_name[ZFS_MAXNAMELEN]; 73230592Sken zfs_type_t zfs_type; /* type including snapshot */ 74230592Sken zfs_type_t zfs_head_type; /* type excluding snapshot */ 75230592Sken dmu_objset_stats_t zfs_dmustats; 76230592Sken nvlist_t *zfs_props; 77230592Sken nvlist_t *zfs_user_props; 78230592Sken boolean_t zfs_mntcheck; 79230592Sken char *zfs_mntopts; 80230592Sken uint8_t *zfs_props_table; 81230592Sken}; 82230592Sken 83230592Sken/* 84230592Sken * This is different from checking zfs_type, because it will also catch 85230592Sken * snapshots of volumes. 86230592Sken */ 87230592Sken#define ZFS_IS_VOLUME(zhp) ((zhp)->zfs_head_type == ZFS_TYPE_VOLUME) 88230592Sken 89230592Skenstruct zpool_handle { 90230592Sken libzfs_handle_t *zpool_hdl; 91230592Sken zpool_handle_t *zpool_next; 92230592Sken char zpool_name[ZPOOL_MAXNAMELEN]; 93230592Sken int zpool_state; 94230592Sken size_t zpool_config_size; 95230592Sken nvlist_t *zpool_config; 96230592Sken nvlist_t *zpool_old_config; 97253550Sken nvlist_t *zpool_props; 98230592Sken diskaddr_t zpool_start_block; 99230592Sken}; 100230592Sken 101253550Skentypedef enum { 102253550Sken PROTO_NFS = 0, 103253550Sken PROTO_SMB = 1, 104253550Sken PROTO_END = 2 105253550Sken} zfs_share_proto_t; 106230592Sken 107230592Sken/* 108230592Sken * The following can be used as a bitmask and any new values 109230592Sken * added must preserve that capability. 110230592Sken */ 111230592Skentypedef enum { 112230592Sken SHARED_NOT_SHARED = 0x0, 113230592Sken SHARED_ISCSI = 0x1, 114253550Sken SHARED_NFS = 0x2, 115253550Sken SHARED_SMB = 0x4 116253550Sken} zfs_share_type_t; 117253550Sken 118230592Skenint zfs_error(libzfs_handle_t *, int, const char *); 119230592Skenint zfs_error_fmt(libzfs_handle_t *, int, const char *, ...); 120230592Skenvoid zfs_error_aux(libzfs_handle_t *, const char *, ...); 121230592Skenvoid *zfs_alloc(libzfs_handle_t *, size_t); 122230592Skenvoid *zfs_realloc(libzfs_handle_t *, void *, size_t, size_t); 123230592Skenchar *zfs_strdup(libzfs_handle_t *, const char *); 124230592Skenint no_memory(libzfs_handle_t *); 125230592Sken 126230592Skenint zfs_standard_error(libzfs_handle_t *, int, const char *); 127230592Skenint zfs_standard_error_fmt(libzfs_handle_t *, int, const char *, ...); 128230592Skenint zpool_standard_error(libzfs_handle_t *, int, const char *); 129230592Skenint zpool_standard_error_fmt(libzfs_handle_t *, int, const char *, ...); 130230592Sken 131230592Skenint get_dependents(libzfs_handle_t *, boolean_t, const char *, char ***, 132230592Sken size_t *); 133230592Sken 134230592Sken 135230592Skenint zprop_parse_value(libzfs_handle_t *, nvpair_t *, int, zfs_type_t, 136230592Sken nvlist_t *, char **, uint64_t *, const char *); 137230592Skenint zprop_expand_list(libzfs_handle_t *hdl, zprop_list_t **plp, 138230592Sken zfs_type_t type); 139230592Sken 140230592Sken/* 141230592Sken * Use this changelist_gather() flag to force attempting mounts 142230592Sken * on each change node regardless of whether or not it is currently 143230592Sken * mounted. 144230592Sken */ 145230592Sken#define CL_GATHER_MOUNT_ALWAYS 1 146230592Sken 147230592Skentypedef struct prop_changelist prop_changelist_t; 148230592Sken 149230592Skenint zcmd_alloc_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, size_t); 150230592Skenint zcmd_write_src_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *); 151230592Skenint zcmd_write_conf_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *); 152230592Skenint zcmd_expand_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *); 153230592Skenint zcmd_read_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t **); 154253550Skenvoid zcmd_free_nvlists(zfs_cmd_t *); 155253550Sken 156230592Skenint changelist_prefix(prop_changelist_t *); 157230592Skenint changelist_postfix(prop_changelist_t *); 158230592Skenvoid changelist_rename(prop_changelist_t *, const char *, const char *); 159253550Skenvoid changelist_remove(prop_changelist_t *, const char *); 160253550Skenvoid changelist_free(prop_changelist_t *); 161253550Skenprop_changelist_t *changelist_gather(zfs_handle_t *, zfs_prop_t, int, int); 162253550Skenint changelist_unshare(prop_changelist_t *, zfs_share_proto_t *); 163253550Skenint changelist_haszonedchild(prop_changelist_t *); 164230592Sken 165230592Skenvoid remove_mountpoint(zfs_handle_t *); 166230592Skenint create_parents(libzfs_handle_t *, char *, int); 167230592Skenboolean_t isa_child_of(const char *dataset, const char *parent); 168230592Sken 169230592Skenzfs_handle_t *make_dataset_handle(libzfs_handle_t *, const char *); 170230592Sken 171230592Skenint zpool_open_silent(libzfs_handle_t *, const char *, zpool_handle_t **); 172253550Sken 173253550Skenint zvol_create_link(libzfs_handle_t *, const char *); 174253550Skenint zvol_remove_link(libzfs_handle_t *, const char *); 175253550Skenint zpool_iter_zvol(zpool_handle_t *, int (*)(const char *, void *), void *); 176230592Skenboolean_t zpool_name_valid(libzfs_handle_t *, boolean_t, const char *); 177230592Sken 178230592Skenvoid namespace_clear(libzfs_handle_t *); 179230592Sken 180230592Sken/* 181230592Sken * libshare (sharemgr) interfaces used internally. 182230592Sken */ 183230592Sken 184230592Skenextern int zfs_init_libshare(libzfs_handle_t *, int); 185230592Skenextern void zfs_uninit_libshare(libzfs_handle_t *); 186230592Skenextern int zfs_parse_options(char *, zfs_share_proto_t); 187230592Sken 188230592Skenextern int zfs_unshare_proto(zfs_handle_t *zhp, 189230592Sken const char *, zfs_share_proto_t *); 190230592Sken 191230592Sken#ifdef __FreeBSD__ 192230592Sken 193230592Sken/* 194230592Sken * This is FreeBSD version of ioctl, because Solaris' ioctl() updates 195230592Sken * zc_nvlist_dst_size even if an error is returned, on FreeBSD if an 196230592Sken * error is returned zc_nvlist_dst_size won't be updated. 197230592Sken */ 198230592Skenstatic __inline int 199230592Skenzcmd_ioctl(int fd, unsigned long cmd, zfs_cmd_t *zc) 200230592Sken{ 201230592Sken size_t oldsize; 202230592Sken int ret; 203230592Sken 204230592Sken oldsize = zc->zc_nvlist_dst_size; 205230592Sken ret = ioctl(fd, cmd, zc); 206230592Sken if (ret == 0 && oldsize < zc->zc_nvlist_dst_size) { 207230592Sken ret = -1; 208230592Sken errno = ENOMEM; 209230592Sken } 210230592Sken 211230592Sken return (ret); 212230592Sken} 213230592Sken#define ioctl(fd, cmd, zc) zcmd_ioctl((fd), (cmd), (zc)) 214230592Sken#endif 215230592Sken 216230592Sken#ifdef __cplusplus 217230592Sken} 218230592Sken#endif 219230592Sken 220230592Sken#endif /* _LIBFS_IMPL_H */ 221230592Sken