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 /* 238802SSanjeev.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; 66*8811SEric.Taylor@Sun.COM boolean_t libzfs_mnttab_enable; 678228SEric.Taylor@Sun.COM avl_tree_t libzfs_mnttab_cache; 682082Seschrock }; 695951Sdougm #define ZFSSHARE_MISS 0x01 /* Didn't find entry in cache */ 702082Seschrock 71789Sahrens struct zfs_handle { 722082Seschrock libzfs_handle_t *zfs_hdl; 736865Srm160521 zpool_handle_t *zpool_hdl; 74789Sahrens char zfs_name[ZFS_MAXNAMELEN]; 752885Sahrens zfs_type_t zfs_type; /* type including snapshot */ 762885Sahrens zfs_type_t zfs_head_type; /* type excluding snapshot */ 77789Sahrens dmu_objset_stats_t zfs_dmustats; 781356Seschrock nvlist_t *zfs_props; 792676Seschrock nvlist_t *zfs_user_props; 802474Seschrock boolean_t zfs_mntcheck; 81789Sahrens char *zfs_mntopts; 828802SSanjeev.Bagewadi@Sun.COM uint8_t *zfs_props_table; 83789Sahrens }; 84789Sahrens 852676Seschrock /* 862676Seschrock * This is different from checking zfs_type, because it will also catch 872676Seschrock * snapshots of volumes. 882676Seschrock */ 892885Sahrens #define ZFS_IS_VOLUME(zhp) ((zhp)->zfs_head_type == ZFS_TYPE_VOLUME) 902676Seschrock 91789Sahrens struct zpool_handle { 922082Seschrock libzfs_handle_t *zpool_hdl; 936865Srm160521 zpool_handle_t *zpool_next; 94789Sahrens char zpool_name[ZPOOL_MAXNAMELEN]; 95789Sahrens int zpool_state; 96789Sahrens size_t zpool_config_size; 97789Sahrens nvlist_t *zpool_config; 98952Seschrock nvlist_t *zpool_old_config; 993912Slling nvlist_t *zpool_props; 1004276Staylor diskaddr_t zpool_start_block; 101789Sahrens }; 102789Sahrens 1035331Samw typedef enum { 1045331Samw PROTO_NFS = 0, 1055331Samw PROTO_SMB = 1, 1065331Samw PROTO_END = 2 1075331Samw } zfs_share_proto_t; 1085331Samw 1095331Samw /* 1105331Samw * The following can be used as a bitmask and any new values 1115331Samw * added must preserve that capability. 1125331Samw */ 1135331Samw typedef enum { 1145331Samw SHARED_NOT_SHARED = 0x0, 1155331Samw SHARED_ISCSI = 0x1, 1165331Samw SHARED_NFS = 0x2, 1175331Samw SHARED_SMB = 0x4 1185331Samw } zfs_share_type_t; 1195331Samw 1203237Slling int zfs_error(libzfs_handle_t *, int, const char *); 1213237Slling int zfs_error_fmt(libzfs_handle_t *, int, const char *, ...); 1222082Seschrock void zfs_error_aux(libzfs_handle_t *, const char *, ...); 1232082Seschrock void *zfs_alloc(libzfs_handle_t *, size_t); 1242676Seschrock void *zfs_realloc(libzfs_handle_t *, void *, size_t, size_t); 1252082Seschrock char *zfs_strdup(libzfs_handle_t *, const char *); 1262082Seschrock int no_memory(libzfs_handle_t *); 127789Sahrens 1283237Slling int zfs_standard_error(libzfs_handle_t *, int, const char *); 1293237Slling int zfs_standard_error_fmt(libzfs_handle_t *, int, const char *, ...); 1303237Slling int zpool_standard_error(libzfs_handle_t *, int, const char *); 1313237Slling int zpool_standard_error_fmt(libzfs_handle_t *, int, const char *, ...); 132789Sahrens 1332474Seschrock int get_dependents(libzfs_handle_t *, boolean_t, const char *, char ***, 1342474Seschrock size_t *); 135789Sahrens 1363912Slling 1375094Slling int zprop_parse_value(libzfs_handle_t *, nvpair_t *, int, zfs_type_t, 1385094Slling nvlist_t *, char **, uint64_t *, const char *); 1395094Slling int zprop_expand_list(libzfs_handle_t *hdl, zprop_list_t **plp, 1405094Slling zfs_type_t type); 1413912Slling 1427366STim.Haley@Sun.COM /* 1437366STim.Haley@Sun.COM * Use this changelist_gather() flag to force attempting mounts 1447366STim.Haley@Sun.COM * on each change node regardless of whether or not it is currently 1457366STim.Haley@Sun.COM * mounted. 1467366STim.Haley@Sun.COM */ 1477366STim.Haley@Sun.COM #define CL_GATHER_MOUNT_ALWAYS 1 1487366STim.Haley@Sun.COM 149789Sahrens typedef struct prop_changelist prop_changelist_t; 150789Sahrens 1512676Seschrock int zcmd_alloc_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, size_t); 1525094Slling int zcmd_write_src_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *); 1535094Slling int zcmd_write_conf_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *); 1542676Seschrock int zcmd_expand_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *); 1552676Seschrock int zcmd_read_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t **); 1562676Seschrock void zcmd_free_nvlists(zfs_cmd_t *); 1572676Seschrock 158789Sahrens int changelist_prefix(prop_changelist_t *); 159789Sahrens int changelist_postfix(prop_changelist_t *); 160789Sahrens void changelist_rename(prop_changelist_t *, const char *, const char *); 1615367Sahrens void changelist_remove(prop_changelist_t *, const char *); 162789Sahrens void changelist_free(prop_changelist_t *); 1637366STim.Haley@Sun.COM prop_changelist_t *changelist_gather(zfs_handle_t *, zfs_prop_t, int, int); 1645331Samw int changelist_unshare(prop_changelist_t *, zfs_share_proto_t *); 165789Sahrens int changelist_haszonedchild(prop_changelist_t *); 166789Sahrens 167789Sahrens void remove_mountpoint(zfs_handle_t *); 1685367Sahrens int create_parents(libzfs_handle_t *, char *, int); 1696027Srm160521 boolean_t isa_child_of(const char *dataset, const char *parent); 170789Sahrens 1712082Seschrock zfs_handle_t *make_dataset_handle(libzfs_handle_t *, const char *); 1721544Seschrock 1732142Seschrock int zpool_open_silent(libzfs_handle_t *, const char *, zpool_handle_t **); 174789Sahrens 1752082Seschrock int zvol_create_link(libzfs_handle_t *, const char *); 1762082Seschrock int zvol_remove_link(libzfs_handle_t *, const char *); 1773126Sahl int zpool_iter_zvol(zpool_handle_t *, int (*)(const char *, void *), void *); 1786423Sgw25295 boolean_t zpool_name_valid(libzfs_handle_t *, boolean_t, const char *); 179789Sahrens 1802082Seschrock void namespace_clear(libzfs_handle_t *); 181789Sahrens 1824180Sdougm /* 1834180Sdougm * libshare (sharemgr) interfaces used internally. 1844180Sdougm */ 1854180Sdougm 1864180Sdougm extern int zfs_init_libshare(libzfs_handle_t *, int); 1874180Sdougm extern void zfs_uninit_libshare(libzfs_handle_t *); 1885331Samw extern int zfs_parse_options(char *, zfs_share_proto_t); 1894180Sdougm 1905331Samw extern int zfs_unshare_proto(zfs_handle_t *zhp, 1915331Samw const char *, zfs_share_proto_t *); 192789Sahrens #ifdef __cplusplus 193789Sahrens } 194789Sahrens #endif 195789Sahrens 196789Sahrens #endif /* _LIBFS_IMPL_H */ 197