Path: blob/main/sys/contrib/openzfs/lib/libzfs/libzfs_impl.h
105690 views
// SPDX-License-Identifier: CDDL-1.01/*2* CDDL HEADER START3*4* The contents of this file are subject to the terms of the5* Common Development and Distribution License (the "License").6* You may not use this file except in compliance with the License.7*8* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE9* or https://opensource.org/licenses/CDDL-1.0.10* See the License for the specific language governing permissions11* and limitations under the License.12*13* When distributing Covered Code, include this CDDL HEADER in each14* file and include the License file at usr/src/OPENSOLARIS.LICENSE.15* If applicable, add the following below this CDDL HEADER, with the16* fields enclosed by brackets "[]" replaced with your own identifying17* information: Portions Copyright [yyyy] [name of copyright owner]18*19* CDDL HEADER END20*/2122/*23* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.24* Copyright (c) 2011, 2020 by Delphix. All rights reserved.25* Copyright (c) 2018 Datto Inc.26* Copyright 2020 Joyent, Inc.27*/2829#ifndef _LIBZFS_IMPL_H30#define _LIBZFS_IMPL_H3132#include <sys/fs/zfs.h>33#include <sys/nvpair.h>34#include <sys/dmu.h>35#include <sys/zfs_ioctl.h>36#include <regex.h>3738#include <libzfs.h>39#include <libshare.h>40#include <libzfs_core.h>4142#ifdef __cplusplus43extern "C" {44#endif4546#define ERRBUFLEN 10244748struct libzfs_handle {49int libzfs_error;50int libzfs_fd;51zpool_handle_t *libzfs_pool_handles;52avl_tree_t libzfs_ns_avl;53uint64_t libzfs_ns_gen;54int libzfs_desc_active;55char libzfs_action[1024];56char libzfs_desc[1024];57int libzfs_printerr;58boolean_t libzfs_mnttab_enable;59/*60* We need a lock to handle the case where parallel mount61* threads are populating the mnttab cache simultaneously. The62* lock only protects the integrity of the avl tree, and does63* not protect the contents of the mnttab entries themselves.64*/65pthread_mutex_t libzfs_mnttab_cache_lock;66avl_tree_t libzfs_mnttab_cache;67int libzfs_pool_iter;68boolean_t libzfs_prop_debug;69regex_t libzfs_urire;70uint64_t libzfs_max_nvlist;71void *libfetch;72char *libfetch_load_error;73};7475struct zfs_handle {76libzfs_handle_t *zfs_hdl;77zpool_handle_t *zpool_hdl;78char zfs_name[ZFS_MAX_DATASET_NAME_LEN];79zfs_type_t zfs_type; /* type including snapshot */80zfs_type_t zfs_head_type; /* type excluding snapshot */81dmu_objset_stats_t zfs_dmustats;82nvlist_t *zfs_props;83nvlist_t *zfs_user_props;84nvlist_t *zfs_recvd_props;85boolean_t zfs_mntcheck;86char *zfs_mntopts;87uint8_t *zfs_props_table;88};8990/*91* This is different from checking zfs_type, because it will also catch92* snapshots of volumes.93*/94#define ZFS_IS_VOLUME(zhp) ((zhp)->zfs_head_type == ZFS_TYPE_VOLUME)95#define ZHP_MAX_PROPNAMES 49697struct zpool_handle {98libzfs_handle_t *zpool_hdl;99zpool_handle_t *zpool_next;100char zpool_name[ZFS_MAX_DATASET_NAME_LEN];101int zpool_state;102unsigned int zpool_n_propnames;103const char *zpool_propnames[ZHP_MAX_PROPNAMES];104size_t zpool_config_size;105nvlist_t *zpool_config;106nvlist_t *zpool_old_config;107nvlist_t *zpool_props;108diskaddr_t zpool_start_block;109};110111typedef int (*zfs_uri_handler_fn_t)(struct libzfs_handle *, const char *,112const char *, zfs_keyformat_t, boolean_t, uint8_t **, size_t *);113114typedef struct zfs_uri_handler {115const char *zuh_scheme;116zfs_uri_handler_fn_t zuh_handler;117} zfs_uri_handler_t;118119#define CONFIG_BUF_MINSIZE 262144120121extern int zfs_error(libzfs_handle_t *, int, const char *);122extern int zfs_error_fmt(libzfs_handle_t *, int, const char *, ...)123__attribute__((format(printf, 3, 4)));124extern void zfs_error_aux(libzfs_handle_t *, const char *, ...)125__attribute__((format(printf, 2, 3)));126extern void *zfs_alloc(libzfs_handle_t *, size_t);127extern void *zfs_realloc(libzfs_handle_t *, void *, size_t, size_t);128extern char *zfs_asprintf(libzfs_handle_t *, const char *, ...)129__attribute__((format(printf, 2, 3)));130extern char *zfs_strdup(libzfs_handle_t *, const char *);131extern int no_memory(libzfs_handle_t *);132133extern int zfs_standard_error_fmt(libzfs_handle_t *, int, const char *, ...)134__attribute__((format(printf, 3, 4)));135extern void zfs_setprop_error(libzfs_handle_t *, zfs_prop_t, int, char *);136extern int zpool_standard_error(libzfs_handle_t *, int, const char *);137extern int zpool_standard_error_fmt(libzfs_handle_t *, int, const char *, ...)138__attribute__((format(printf, 3, 4)));139140extern zfs_handle_t *make_dataset_handle_zc(libzfs_handle_t *, zfs_cmd_t *);141extern zfs_handle_t *make_dataset_simple_handle_zc(zfs_handle_t *, zfs_cmd_t *);142143extern int zprop_parse_value(libzfs_handle_t *, nvpair_t *, int, zfs_type_t,144nvlist_t *, const char **, uint64_t *, const char *);145extern int zprop_expand_list(libzfs_handle_t *hdl, zprop_list_t **plp,146zfs_type_t type);147148/*149* Use this changelist_gather() flag to force attempting mounts150* on each change node regardless of whether or not it is currently151* mounted.152*/153#define CL_GATHER_MOUNT_ALWAYS 1154/*155* changelist_gather() flag to force it to iterate on mounted datasets only156*/157#define CL_GATHER_ITER_MOUNTED 2158/*159* Use this changelist_gather() flag to prevent unmounting of file systems.160*/161#define CL_GATHER_DONT_UNMOUNT 4162163typedef struct prop_changelist prop_changelist_t;164165extern void zcmd_alloc_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, size_t);166extern void zcmd_write_src_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *);167extern void zcmd_write_conf_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t *);168extern void zcmd_expand_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *);169extern int zcmd_read_dst_nvlist(libzfs_handle_t *, zfs_cmd_t *, nvlist_t **);170extern void zcmd_free_nvlists(zfs_cmd_t *);171172extern int changelist_prefix(prop_changelist_t *);173extern int changelist_postfix(prop_changelist_t *);174extern void changelist_rename(prop_changelist_t *, const char *, const char *);175extern void changelist_remove(prop_changelist_t *, const char *);176extern void changelist_free(prop_changelist_t *);177extern prop_changelist_t *changelist_gather(zfs_handle_t *, zfs_prop_t, int,178int);179extern int changelist_unshare(prop_changelist_t *, const enum sa_protocol *);180extern int changelist_haszonedchild(prop_changelist_t *);181182extern void remove_mountpoint(zfs_handle_t *);183extern int create_parents(libzfs_handle_t *, char *, int);184185extern zfs_handle_t *make_dataset_handle(libzfs_handle_t *, const char *);186extern zfs_handle_t *make_bookmark_handle(zfs_handle_t *, const char *,187nvlist_t *props);188189extern int zpool_open_silent(libzfs_handle_t *, const char *,190zpool_handle_t **);191192extern boolean_t zpool_name_valid(libzfs_handle_t *, boolean_t, const char *);193194extern int zfs_validate_name(libzfs_handle_t *hdl, const char *path, int type,195boolean_t modifying);196197extern void namespace_clear(libzfs_handle_t *);198199typedef struct {200zfs_prop_t p_prop;201int p_share_err;202int p_unshare_err;203} proto_table_t;204205typedef struct differ_info {206zfs_handle_t *zhp;207char *fromsnap;208char *frommnt;209char *tosnap;210char *tomnt;211char *ds;212char *dsmnt;213char *tmpsnap;214char errbuf[ERRBUFLEN];215boolean_t isclone;216boolean_t scripted;217boolean_t classify;218boolean_t timestamped;219boolean_t no_mangle;220uint64_t shares;221int zerr;222int cleanupfd;223int outputfd;224int datafd;225} differ_info_t;226227extern int do_mount(zfs_handle_t *zhp, const char *mntpt, const char *opts,228int flags);229extern int do_unmount(zfs_handle_t *zhp, const char *mntpt, int flags);230extern int libzfs_load_module(void);231extern int zpool_relabel_disk(libzfs_handle_t *hdl, const char *path,232const char *msg);233extern int find_shares_object(differ_info_t *di);234235#ifdef __cplusplus236}237#endif238239#endif /* _LIBZFS_IMPL_H */240241242