libzfs_impl.h revision 4445fffbbb1ea25fd0e9ea68b9380dd7a6709025
843e19887f64dde75055cf8842fc4db2171eff45johnlev/*
843e19887f64dde75055cf8842fc4db2171eff45johnlev * CDDL HEADER SART
843e19887f64dde75055cf8842fc4db2171eff45johnlev *
843e19887f64dde75055cf8842fc4db2171eff45johnlev * The contents of this file are subject to the terms of the
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Common Development and Distribution License (the "License").
843e19887f64dde75055cf8842fc4db2171eff45johnlev * You may not use this file except in compliance with the License.
843e19887f64dde75055cf8842fc4db2171eff45johnlev *
843e19887f64dde75055cf8842fc4db2171eff45johnlev * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
843e19887f64dde75055cf8842fc4db2171eff45johnlev * or http://www.opensolaris.org/os/licensing.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * See the License for the specific language governing permissions
843e19887f64dde75055cf8842fc4db2171eff45johnlev * and limitations under the License.
843e19887f64dde75055cf8842fc4db2171eff45johnlev *
843e19887f64dde75055cf8842fc4db2171eff45johnlev * When distributing Covered Code, include this CDDL HEADER in each
843e19887f64dde75055cf8842fc4db2171eff45johnlev * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * If applicable, add the following below this CDDL HEADER, with the
843e19887f64dde75055cf8842fc4db2171eff45johnlev * fields enclosed by brackets "[]" replaced with your own identifying
843e19887f64dde75055cf8842fc4db2171eff45johnlev * information: Portions Copyright [yyyy] [name of copyright owner]
843e19887f64dde75055cf8842fc4db2171eff45johnlev *
843e19887f64dde75055cf8842fc4db2171eff45johnlev * CDDL HEADER END
843e19887f64dde75055cf8842fc4db2171eff45johnlev */
843e19887f64dde75055cf8842fc4db2171eff45johnlev
0dc2366f7b9f9f36e10909b1e95edbf2a261c2acVenugopal Iyer/*
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
1a41ca239310955ae95b2569b707432432a58580Jerry Jelinek * Copyright (c) 2012 by Delphix. All rights reserved.
843e19887f64dde75055cf8842fc4db2171eff45johnlev */
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev#ifndef _LIBZFS_IMPL_H
843e19887f64dde75055cf8842fc4db2171eff45johnlev#define _LIBZFS_IMPL_H
843e19887f64dde75055cf8842fc4db2171eff45johnlev
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy#include <sys/dmu.h>
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng#include <sys/fs/zfs.h>
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng#include <sys/zfs_ioctl.h>
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng#include <sys/spa.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <sys/nvpair.h>
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <libuutil.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <libzfs.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <libshare.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <libzfs_core.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <fm/libtopo.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng#ifdef __cplusplus
843e19887f64dde75055cf8842fc4db2171eff45johnlevextern "C" {
2c4ec68272805fba7d569318536bd680e9c52e03Eric Cheng#endif
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng#ifdef VERIFY
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng#undef VERIFY
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng#endif
1a41ca239310955ae95b2569b707432432a58580Jerry Jelinek#define VERIFY verify
1a41ca239310955ae95b2569b707432432a58580Jerry Jelinek
1a41ca239310955ae95b2569b707432432a58580Jerry Jelinektypedef struct libzfs_fru {
1a41ca239310955ae95b2569b707432432a58580Jerry Jelinek char *zf_device;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng char *zf_fru;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng struct libzfs_fru *zf_chain;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng struct libzfs_fru *zf_next;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng} libzfs_fru_t;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng
da14cebe459d3275048785f25bd869cb09b5307fEric Chengstruct libzfs_handle {
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou int libzfs_error;
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou int libzfs_fd;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng FILE *libzfs_mnttab;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng FILE *libzfs_sharetab;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng zpool_handle_t *libzfs_pool_handles;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng uu_avl_pool_t *libzfs_ns_avlpool;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng uu_avl_t *libzfs_ns_avl;
843e19887f64dde75055cf8842fc4db2171eff45johnlev uint64_t libzfs_ns_gen;
843e19887f64dde75055cf8842fc4db2171eff45johnlev int libzfs_desc_active;
1a41ca239310955ae95b2569b707432432a58580Jerry Jelinek char libzfs_action[1024];
1a41ca239310955ae95b2569b707432432a58580Jerry Jelinek char libzfs_desc[1024];
1a41ca239310955ae95b2569b707432432a58580Jerry Jelinek int libzfs_printerr;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng int libzfs_storeerr; /* stuff error messages into buffer */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou void *libzfs_sharehdl; /* libshare handle */
1cb875ae88fb9463b368e725c2444776595895cbCathy Zhou uint_t libzfs_shareflags;
d62bc4badc1c1f1549c961cfb8b420e650e1272byz boolean_t libzfs_mnttab_enable;
da14cebe459d3275048785f25bd869cb09b5307fEric Cheng avl_tree_t libzfs_mnttab_cache;
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy int libzfs_pool_iter;
843e19887f64dde75055cf8842fc4db2171eff45johnlev topo_hdl_t *libzfs_topo_hdl;
843e19887f64dde75055cf8842fc4db2171eff45johnlev libzfs_fru_t **libzfs_fru_hash;
843e19887f64dde75055cf8842fc4db2171eff45johnlev libzfs_fru_t *libzfs_fru_list;
843e19887f64dde75055cf8842fc4db2171eff45johnlev char libzfs_chassis_id[256];
843e19887f64dde75055cf8842fc4db2171eff45johnlev};
843e19887f64dde75055cf8842fc4db2171eff45johnlev
2b24ab6b3865caeede9eeb9db6b83e1d89dcd1eaSebastien Roy#define ZFSSHARE_MISS 0x01 /* Didn't find entry in cache */
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlevstruct zfs_handle {
843e19887f64dde75055cf8842fc4db2171eff45johnlev libzfs_handle_t *zfs_hdl;
843e19887f64dde75055cf8842fc4db2171eff45johnlev zpool_handle_t *zpool_hdl;
843e19887f64dde75055cf8842fc4db2171eff45johnlev char zfs_name[ZFS_MAXNAMELEN];
843e19887f64dde75055cf8842fc4db2171eff45johnlev zfs_type_t zfs_type; /* type including snapshot */
zfs_type_t zfs_head_type; /* type excluding snapshot */
dmu_objset_stats_t zfs_dmustats;
nvlist_t *zfs_props;
nvlist_t *zfs_user_props;
nvlist_t *zfs_recvd_props;
boolean_t zfs_mntcheck;
char *zfs_mntopts;
uint8_t *zfs_props_table;
};
/*
* This is different from checking zfs_type, because it will also catch
* snapshots of volumes.
*/
#define ZFS_IS_VOLUME(zhp) ((zhp)->zfs_head_type == ZFS_TYPE_VOLUME)
struct zpool_handle {
libzfs_handle_t *zpool_hdl;
zpool_handle_t *zpool_next;
char zpool_name[ZPOOL_MAXNAMELEN];
int zpool_state;
size_t zpool_config_size;
nvlist_t *zpool_config;
nvlist_t *zpool_old_config;
nvlist_t *zpool_props;
diskaddr_t zpool_start_block;
};
typedef enum {
PROTO_NFS = 0,
PROTO_SMB = 1,
PROTO_END = 2
} zfs_share_proto_t;
/*
* The following can be used as a bitmask and any new values
* added must preserve that capability.
*/
typedef enum {
SHARED_NOT_SHARED = 0x0,
SHARED_NFS = 0x2,
SHARED_SMB = 0x4
} zfs_share_type_t;
int zfs_error(libzfs_handle_t *, int, const char *);
int zfs_error_fmt(libzfs_handle_t *, int, const char *, ...);
void zfs_error_aux(libzfs_handle_t *, const char *, ...);
void *zfs_alloc(libzfs_handle_t *, size_t);
void *zfs_realloc(libzfs_handle_t *, void *, size_t, size_t);
char *zfs_asprintf(libzfs_handle_t *, const char *, ...);
char *zfs_strdup(libzfs_handle_t *, const char *);
int no_memory(libzfs_handle_t *);
int zfs_standard_error(libzfs_handle_t *, int, const char *);
int zfs_standard_error_fmt(libzfs_handle_t *, int, const char *, ...);
int zpool_standard_error(libzfs_handle_t *, int, const char *);
int zpool_standard_error_fmt(libzfs_handle_t *, int, const char *, ...);
int get_dependents(libzfs_handle_t *, boolean_t, const char *, char ***,
size_t *);
zfs_handle_t *make_dataset_handle_zc(libzfs_handle_t *, zfs_cmd_t *);
int zprop_parse_value(libzfs_handle_t *, nvpair_t *, int, zfs_type_t,
nvlist_t *, char **, uint64_t *, const char *);
int zprop_expand_list(libzfs_handle_t *hdl, zprop_list_t **plp,
zfs_type_t type);
/*
* Use this changelist_gather() flag to force attempting mounts
* on each change node regardless of whether or not it is currently
* mounted.
*/
#define CL_GATHER_MOUNT_ALWAYS 1
typedef struct prop_changelist prop_changelist_t;
int zcmd_alloc_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, size_t);
int zcmd_write_src_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *);
int zcmd_write_conf_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *);
int zcmd_expand_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *);
int zcmd_read_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t **);
void zcmd_free_nvlists(zfs_cmd_t *);
int changelist_prefix(prop_changelist_t *);
int changelist_postfix(prop_changelist_t *);
void changelist_rename(prop_changelist_t *, const char *, const char *);
void changelist_remove(prop_changelist_t *, const char *);
void changelist_free(prop_changelist_t *);
prop_changelist_t *changelist_gather(zfs_handle_t *, zfs_prop_t, int, int);
int changelist_unshare(prop_changelist_t *, zfs_share_proto_t *);
int changelist_haszonedchild(prop_changelist_t *);
void remove_mountpoint(zfs_handle_t *);
int create_parents(libzfs_handle_t *, char *, int);
boolean_t isa_child_of(const char *dataset, const char *parent);
zfs_handle_t *make_dataset_handle(libzfs_handle_t *, const char *);
int zpool_open_silent(libzfs_handle_t *, const char *, zpool_handle_t **);
boolean_t zpool_name_valid(libzfs_handle_t *, boolean_t, const char *);
int zfs_validate_name(libzfs_handle_t *hdl, const char *path, int type,
boolean_t modifying);
void namespace_clear(libzfs_handle_t *);
/*
* libshare (sharemgr) interfaces used internally.
*/
extern int zfs_init_libshare(libzfs_handle_t *, int);
extern void zfs_uninit_libshare(libzfs_handle_t *);
extern int zfs_parse_options(char *, zfs_share_proto_t);
extern int zfs_unshare_proto(zfs_handle_t *,
const char *, zfs_share_proto_t *);
extern void libzfs_fru_clear(libzfs_handle_t *, boolean_t);
#ifdef __cplusplus
}
#endif
#endif /* _LIBZFS_IMPL_H */