libzfs_impl.h revision 78f171005391b928aaf1642b3206c534ed644332
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm * CDDL HEADER SART
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * or http://www.opensolaris.org/os/licensing.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
f3861e1a2ceec23a5b699c24d814b7775a9e0b52ahl
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
99d5e173470cf967aa87653364ed614299e7b511Tim Haley * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens * Copyright (c) 2013 by Delphix. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens#ifndef _LIBZFS_IMPL_H
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens#define _LIBZFS_IMPL_H
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/dmu.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/fs/zfs.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/zfs_ioctl.h>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks#include <sys/spa.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/nvpair.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens
99653d4ee642c6528e88224f12409a5f23060994eschrock#include <libuutil.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <libzfs.h>
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm#include <libshare.h>
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens#include <libzfs_core.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock#include <fm/libtopo.h>
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
fa9e4066f08beec538e775443c5be79dd423fcabahrens#ifdef __cplusplus
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern "C" {
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif
fa9e4066f08beec538e775443c5be79dd423fcabahrens
5da9ad7bc7967714b6c6e02dcfe8e6f7cc2d6098gw#ifdef VERIFY
5da9ad7bc7967714b6c6e02dcfe8e6f7cc2d6098gw#undef VERIFY
5da9ad7bc7967714b6c6e02dcfe8e6f7cc2d6098gw#endif
5da9ad7bc7967714b6c6e02dcfe8e6f7cc2d6098gw#define VERIFY verify
5da9ad7bc7967714b6c6e02dcfe8e6f7cc2d6098gw
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrocktypedef struct libzfs_fru {
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock char *zf_device;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock char *zf_fru;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock struct libzfs_fru *zf_chain;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock struct libzfs_fru *zf_next;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock} libzfs_fru_t;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
99653d4ee642c6528e88224f12409a5f23060994eschrockstruct libzfs_handle {
99653d4ee642c6528e88224f12409a5f23060994eschrock int libzfs_error;
99653d4ee642c6528e88224f12409a5f23060994eschrock int libzfs_fd;
99653d4ee642c6528e88224f12409a5f23060994eschrock FILE *libzfs_mnttab;
99653d4ee642c6528e88224f12409a5f23060994eschrock FILE *libzfs_sharetab;
29ab75c9a733dad2978c4860efd954b5625e3467rm zpool_handle_t *libzfs_pool_handles;
99653d4ee642c6528e88224f12409a5f23060994eschrock uu_avl_pool_t *libzfs_ns_avlpool;
99653d4ee642c6528e88224f12409a5f23060994eschrock uu_avl_t *libzfs_ns_avl;
99653d4ee642c6528e88224f12409a5f23060994eschrock uint64_t libzfs_ns_gen;
99653d4ee642c6528e88224f12409a5f23060994eschrock int libzfs_desc_active;
99653d4ee642c6528e88224f12409a5f23060994eschrock char libzfs_action[1024];
99653d4ee642c6528e88224f12409a5f23060994eschrock char libzfs_desc[1024];
99653d4ee642c6528e88224f12409a5f23060994eschrock int libzfs_printerr;
99d5e173470cf967aa87653364ed614299e7b511Tim Haley int libzfs_storeerr; /* stuff error messages into buffer */
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm void *libzfs_sharehdl; /* libshare handle */
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm uint_t libzfs_shareflags;
b2634b9c57bbcfa01bb5dec2e196aec32957925fEric Taylor boolean_t libzfs_mnttab_enable;
ebedde844eddf46049b2403f974b50bcba47356eEric Taylor avl_tree_t libzfs_mnttab_cache;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock int libzfs_pool_iter;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock topo_hdl_t *libzfs_topo_hdl;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock libzfs_fru_t **libzfs_fru_hash;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock libzfs_fru_t *libzfs_fru_list;
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock char libzfs_chassis_id[256];
99653d4ee642c6528e88224f12409a5f23060994eschrock};
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
5b6e0c463149a26dd0aeb4c1f70611c97161ff32dougm#define ZFSSHARE_MISS 0x01 /* Didn't find entry in cache */
99653d4ee642c6528e88224f12409a5f23060994eschrock
fa9e4066f08beec538e775443c5be79dd423fcabahrensstruct zfs_handle {
99653d4ee642c6528e88224f12409a5f23060994eschrock libzfs_handle_t *zfs_hdl;
29ab75c9a733dad2978c4860efd954b5625e3467rm zpool_handle_t *zpool_hdl;
fa9e4066f08beec538e775443c5be79dd423fcabahrens char zfs_name[ZFS_MAXNAMELEN];
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens zfs_type_t zfs_type; /* type including snapshot */
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens zfs_type_t zfs_head_type; /* type excluding snapshot */
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_objset_stats_t zfs_dmustats;
7f7322febbcfe774b7270abc3b191c094bfcc517eschrock nvlist_t *zfs_props;
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock nvlist_t *zfs_user_props;
92241e0b80813d0b83c08e730a29b9d1831794fcTom Erickson nvlist_t *zfs_recvd_props;
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock boolean_t zfs_mntcheck;
fa9e4066f08beec538e775443c5be79dd423fcabahrens char *zfs_mntopts;
2e5e9e19867a0d75685f5beb2fe1b0e31491d49bSanjeev Bagewadi uint8_t *zfs_props_table;
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock/*
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * This is different from checking zfs_type, because it will also catch
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock * snapshots of volumes.
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock */
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens#define ZFS_IS_VOLUME(zhp) ((zhp)->zfs_head_type == ZFS_TYPE_VOLUME)
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock
fa9e4066f08beec538e775443c5be79dd423fcabahrensstruct zpool_handle {
99653d4ee642c6528e88224f12409a5f23060994eschrock libzfs_handle_t *zpool_hdl;
29ab75c9a733dad2978c4860efd954b5625e3467rm zpool_handle_t *zpool_next;
fa9e4066f08beec538e775443c5be79dd423fcabahrens char zpool_name[ZPOOL_MAXNAMELEN];
fa9e4066f08beec538e775443c5be79dd423fcabahrens int zpool_state;
fa9e4066f08beec538e775443c5be79dd423fcabahrens size_t zpool_config_size;
fa9e4066f08beec538e775443c5be79dd423fcabahrens nvlist_t *zpool_config;
088e9d477eee66081e407fbc5a33c4da25f66f6aeschrock nvlist_t *zpool_old_config;
b1b8ab34de515a5e83206da22c3d7e563241b021lling nvlist_t *zpool_props;
8488aeb5df27784d479c16cde06a9e25cd9a1152taylor diskaddr_t zpool_start_block;
fa9e4066f08beec538e775443c5be79dd423fcabahrens};
fa9e4066f08beec538e775443c5be79dd423fcabahrens
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrenstypedef enum {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw PROTO_NFS = 0,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw PROTO_SMB = 1,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw PROTO_END = 2
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw} zfs_share_proto_t;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The following can be used as a bitmask and any new values
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * added must preserve that capability.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwtypedef enum {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw SHARED_NOT_SHARED = 0x0,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw SHARED_NFS = 0x2,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw SHARED_SMB = 0x4
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw} zfs_share_type_t;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
ece3d9b3bacef51a5f34d993935eedbb7bb87059llingint zfs_error(libzfs_handle_t *, int, const char *);
ece3d9b3bacef51a5f34d993935eedbb7bb87059llingint zfs_error_fmt(libzfs_handle_t *, int, const char *, ...);
99653d4ee642c6528e88224f12409a5f23060994eschrockvoid zfs_error_aux(libzfs_handle_t *, const char *, ...);
99653d4ee642c6528e88224f12409a5f23060994eschrockvoid *zfs_alloc(libzfs_handle_t *, size_t);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockvoid *zfs_realloc(libzfs_handle_t *, void *, size_t, size_t);
99d5e173470cf967aa87653364ed614299e7b511Tim Haleychar *zfs_asprintf(libzfs_handle_t *, const char *, ...);
99653d4ee642c6528e88224f12409a5f23060994eschrockchar *zfs_strdup(libzfs_handle_t *, const char *);
99653d4ee642c6528e88224f12409a5f23060994eschrockint no_memory(libzfs_handle_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ece3d9b3bacef51a5f34d993935eedbb7bb87059llingint zfs_standard_error(libzfs_handle_t *, int, const char *);
ece3d9b3bacef51a5f34d993935eedbb7bb87059llingint zfs_standard_error_fmt(libzfs_handle_t *, int, const char *, ...);
ece3d9b3bacef51a5f34d993935eedbb7bb87059llingint zpool_standard_error(libzfs_handle_t *, int, const char *);
ece3d9b3bacef51a5f34d993935eedbb7bb87059llingint zpool_standard_error_fmt(libzfs_handle_t *, int, const char *, ...);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrockint get_dependents(libzfs_handle_t *, boolean_t, const char *, char ***,
3bb79bece53191f2cf27aa61a72ea1784a7ce700eschrock size_t *);
19b94df933188a15d4f0d6c568f0bab3f127892eMatthew Ahrenszfs_handle_t *make_dataset_handle_zc(libzfs_handle_t *, zfs_cmd_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
b1b8ab34de515a5e83206da22c3d7e563241b021lling
990b4856d0eaada6f8140335733a1b1771ed2746llingint zprop_parse_value(libzfs_handle_t *, nvpair_t *, int, zfs_type_t,
990b4856d0eaada6f8140335733a1b1771ed2746lling nvlist_t *, char **, uint64_t *, const char *);
990b4856d0eaada6f8140335733a1b1771ed2746llingint zprop_expand_list(libzfs_handle_t *hdl, zprop_list_t **plp,
990b4856d0eaada6f8140335733a1b1771ed2746lling zfs_type_t type);
b1b8ab34de515a5e83206da22c3d7e563241b021lling
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley/*
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley * Use this changelist_gather() flag to force attempting mounts
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley * on each change node regardless of whether or not it is currently
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley * mounted.
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley */
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley#define CL_GATHER_MOUNT_ALWAYS 1
0069fd67511146f5f43175204d5b71d2b357be71Tim Haley
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct prop_changelist prop_changelist_t;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockint zcmd_alloc_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, size_t);
990b4856d0eaada6f8140335733a1b1771ed2746llingint zcmd_write_src_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *);
990b4856d0eaada6f8140335733a1b1771ed2746llingint zcmd_write_conf_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockint zcmd_expand_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockint zcmd_read_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t **);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrockvoid zcmd_free_nvlists(zfs_cmd_t *);
e9dbad6f263d5570ed7ff5443ec5b958af8c24d7eschrock
fa9e4066f08beec538e775443c5be79dd423fcabahrensint changelist_prefix(prop_changelist_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensint changelist_postfix(prop_changelist_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid changelist_rename(prop_changelist_t *, const char *, const char *);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrensvoid changelist_remove(prop_changelist_t *, const char *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid changelist_free(prop_changelist_t *);
0069fd67511146f5f43175204d5b71d2b357be71Tim Haleyprop_changelist_t *changelist_gather(zfs_handle_t *, zfs_prop_t, int, int);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwint changelist_unshare(prop_changelist_t *, zfs_share_proto_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrensint changelist_haszonedchild(prop_changelist_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid remove_mountpoint(zfs_handle_t *);
3cb34c601f3ef3016f638574f5982e80c3735c71ahrensint create_parents(libzfs_handle_t *, char *, int);
d87468da622d0a816b26cc636aa7dcc08249300ermboolean_t isa_child_of(const char *dataset, const char *parent);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
99653d4ee642c6528e88224f12409a5f23060994eschrockzfs_handle_t *make_dataset_handle(libzfs_handle_t *, const char *);
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrenszfs_handle_t *make_bookmark_handle(zfs_handle_t *, const char *,
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens nvlist_t *props);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
94de1d4cf6ec0a3bf040dcc4b8df107c4ed36b51eschrockint zpool_open_silent(libzfs_handle_t *, const char *, zpool_handle_t **);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
e7cbe64f7a72dae5cb44f100db60ca88f3313c65gwboolean_t zpool_name_valid(libzfs_handle_t *, boolean_t, const char *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
99d5e173470cf967aa87653364ed614299e7b511Tim Haleyint zfs_validate_name(libzfs_handle_t *hdl, const char *path, int type,
99d5e173470cf967aa87653364ed614299e7b511Tim Haley boolean_t modifying);
99d5e173470cf967aa87653364ed614299e7b511Tim Haley
99653d4ee642c6528e88224f12409a5f23060994eschrockvoid namespace_clear(libzfs_handle_t *);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm/*
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm * libshare (sharemgr) interfaces used internally.
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm */
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougmextern int zfs_init_libshare(libzfs_handle_t *, int);
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougmextern void zfs_uninit_libshare(libzfs_handle_t *);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwextern int zfs_parse_options(char *, zfs_share_proto_t);
6733190958bbcc0bd6d1d601e7ae0a6994dafb45dougm
743a77ed89085d3c232c4a2f65ab4e19576839e2Alan Wrightextern int zfs_unshare_proto(zfs_handle_t *,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw const char *, zfs_share_proto_t *);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrockextern void libzfs_fru_clear(libzfs_handle_t *, boolean_t);
069f55e237020c4a4907b235fc38fafc6442ce94Eric Schrock
fa9e4066f08beec538e775443c5be79dd423fcabahrens#ifdef __cplusplus
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif
fa9e4066f08beec538e775443c5be79dd423fcabahrens
4445fffbbb1ea25fd0e9ea68b9380dd7a6709025Matthew Ahrens#endif /* _LIBZFS_IMPL_H */