mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-23 02:44:41 +03:00
Add libzutil for libzfs or libzpool consumers
Adds a libzutil for utility functions that are common to libzfs and libzpool consumers (most of what was in libzfs_import.c). This removes the need for utilities to link against both libzpool and libzfs. Reviewed-by: Matthew Ahrens <mahrens@delphix.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Don Brady <don.brady@delphix.com> Closes #8050
This commit is contained in:
committed by
Brian Behlendorf
parent
6644e5bb6e
commit
e89f1295d4
@@ -16,6 +16,7 @@ USER_H = \
|
||||
$(top_srcdir)/include/libzfs.h \
|
||||
$(top_srcdir)/include/libzfs_core.h \
|
||||
$(top_srcdir)/include/libzfs_impl.h \
|
||||
$(top_srcdir)/include/libzutil.h \
|
||||
$(top_srcdir)/include/thread_pool.h
|
||||
|
||||
EXTRA_DIST = $(COMMON_H) $(USER_H)
|
||||
|
||||
@@ -54,25 +54,6 @@ extern "C" {
|
||||
#define ZFS_MAXPROPLEN MAXPATHLEN
|
||||
#define ZPOOL_MAXPROPLEN MAXPATHLEN
|
||||
|
||||
/*
|
||||
* Default device paths
|
||||
*/
|
||||
#define DISK_ROOT "/dev"
|
||||
#define UDISK_ROOT "/dev/disk"
|
||||
#define ZVOL_ROOT "/dev/zvol"
|
||||
|
||||
/*
|
||||
* Default wait time for a device name to be created.
|
||||
*/
|
||||
#define DISK_LABEL_WAIT (30 * 1000) /* 30 seconds */
|
||||
|
||||
#define IMPORT_ORDER_PREFERRED_1 1
|
||||
#define IMPORT_ORDER_PREFERRED_2 2
|
||||
#define IMPORT_ORDER_SCAN_OFFSET 10
|
||||
#define IMPORT_ORDER_DEFAULT 100
|
||||
#define DEFAULT_IMPORT_PATH_SIZE 9
|
||||
extern char *zpool_default_import_path[DEFAULT_IMPORT_PATH_SIZE];
|
||||
|
||||
/*
|
||||
* libzfs errors
|
||||
*/
|
||||
@@ -298,15 +279,9 @@ extern nvlist_t *zpool_find_vdev(zpool_handle_t *, const char *, boolean_t *,
|
||||
boolean_t *, boolean_t *);
|
||||
extern nvlist_t *zpool_find_vdev_by_physpath(zpool_handle_t *, const char *,
|
||||
boolean_t *, boolean_t *, boolean_t *);
|
||||
extern int zpool_label_disk_wait(char *, int);
|
||||
extern int zpool_label_disk(libzfs_handle_t *, zpool_handle_t *, char *);
|
||||
extern uint64_t zpool_vdev_path_to_guid(zpool_handle_t *zhp, const char *path);
|
||||
|
||||
int zfs_dev_is_dm(char *dev_name);
|
||||
int zfs_dev_is_whole_disk(char *dev_name);
|
||||
char *zfs_get_underlying_path(char *dev_name);
|
||||
char *zfs_get_enclosure_sysfs_path(char *dev_name);
|
||||
|
||||
const char *zpool_get_state_str(zpool_handle_t *);
|
||||
|
||||
/*
|
||||
@@ -386,7 +361,6 @@ extern zpool_status_t zpool_get_status(zpool_handle_t *, char **,
|
||||
zpool_errata_t *);
|
||||
extern zpool_status_t zpool_import_status(nvlist_t *, char **,
|
||||
zpool_errata_t *);
|
||||
extern void zpool_dump_ddt(const ddt_stat_t *dds, const ddt_histogram_t *ddh);
|
||||
|
||||
/*
|
||||
* Statistics and configuration functions.
|
||||
@@ -407,32 +381,6 @@ extern int zpool_import_props(libzfs_handle_t *, nvlist_t *, const char *,
|
||||
nvlist_t *, int);
|
||||
extern void zpool_print_unsup_feat(nvlist_t *config);
|
||||
|
||||
/*
|
||||
* Search for pools to import
|
||||
*/
|
||||
|
||||
typedef struct importargs {
|
||||
char **path; /* a list of paths to search */
|
||||
int paths; /* number of paths to search */
|
||||
char *poolname; /* name of a pool to find */
|
||||
uint64_t guid; /* guid of a pool to find */
|
||||
char *cachefile; /* cachefile to use for import */
|
||||
int can_be_active : 1; /* can the pool be active? */
|
||||
int unique : 1; /* does 'poolname' already exist? */
|
||||
int exists : 1; /* set on return if pool already exists */
|
||||
int scan : 1; /* prefer scanning to libblkid cache */
|
||||
nvlist_t *policy; /* load policy (max txg, rewind, etc.) */
|
||||
} importargs_t;
|
||||
|
||||
extern nvlist_t *zpool_search_import(libzfs_handle_t *, importargs_t *);
|
||||
extern int zpool_tryimport(libzfs_handle_t *hdl, char *target,
|
||||
nvlist_t **configp, importargs_t *args);
|
||||
|
||||
/* legacy pool search routines */
|
||||
extern nvlist_t *zpool_find_import(libzfs_handle_t *, int, char **);
|
||||
extern nvlist_t *zpool_find_import_cached(libzfs_handle_t *, const char *,
|
||||
char *, uint64_t);
|
||||
|
||||
/*
|
||||
* Miscellaneous pool functions
|
||||
*/
|
||||
@@ -451,8 +399,6 @@ extern char *zpool_vdev_name(libzfs_handle_t *, zpool_handle_t *, nvlist_t *,
|
||||
int name_flags);
|
||||
extern int zpool_upgrade(zpool_handle_t *, uint64_t);
|
||||
extern int zpool_get_history(zpool_handle_t *, nvlist_t **);
|
||||
extern int zpool_history_unpack(char *, uint64_t, uint64_t *,
|
||||
nvlist_t ***, uint_t *);
|
||||
extern int zpool_events_next(libzfs_handle_t *, nvlist_t **, int *, unsigned,
|
||||
int);
|
||||
extern int zpool_events_clear(libzfs_handle_t *, int *);
|
||||
@@ -780,10 +726,6 @@ extern boolean_t zfs_dataset_exists(libzfs_handle_t *, const char *,
|
||||
zfs_type_t);
|
||||
extern int zfs_spa_version(zfs_handle_t *, int *);
|
||||
extern boolean_t zfs_bookmark_exists(const char *path);
|
||||
extern int zfs_append_partition(char *path, size_t max_len);
|
||||
extern int zfs_resolve_shortname(const char *name, char *path, size_t pathlen);
|
||||
extern int zfs_strcmp_pathname(char *name, char *cmp_name, int wholedisk);
|
||||
extern int zfs_path_order(char *path, int *order);
|
||||
|
||||
/*
|
||||
* Mount support functions.
|
||||
@@ -819,33 +761,6 @@ extern int zfs_unshareall(zfs_handle_t *);
|
||||
extern int zfs_deleg_share_nfs(libzfs_handle_t *, char *, char *, char *,
|
||||
void *, void *, int, zfs_share_op_t);
|
||||
|
||||
/*
|
||||
* Formats for iostat numbers. Examples: "12K", "30ms", "4B", "2321234", "-".
|
||||
*
|
||||
* ZFS_NICENUM_1024: Print kilo, mega, tera, peta, exa..
|
||||
* ZFS_NICENUM_BYTES: Print single bytes ("13B"), kilo, mega, tera...
|
||||
* ZFS_NICENUM_TIME: Print nanosecs, microsecs, millisecs, seconds...
|
||||
* ZFS_NICENUM_RAW: Print the raw number without any formatting
|
||||
* ZFS_NICENUM_RAWTIME: Same as RAW, but print dashes ('-') for zero.
|
||||
*/
|
||||
enum zfs_nicenum_format {
|
||||
ZFS_NICENUM_1024 = 0,
|
||||
ZFS_NICENUM_BYTES = 1,
|
||||
ZFS_NICENUM_TIME = 2,
|
||||
ZFS_NICENUM_RAW = 3,
|
||||
ZFS_NICENUM_RAWTIME = 4
|
||||
};
|
||||
|
||||
/*
|
||||
* Utility function to convert a number to a human-readable form.
|
||||
*/
|
||||
extern void zfs_nicenum(uint64_t, char *, size_t);
|
||||
extern void zfs_nicenum_format(uint64_t num, char *buf, size_t buflen,
|
||||
enum zfs_nicenum_format type);
|
||||
|
||||
|
||||
extern void zfs_nicetime(uint64_t, char *, size_t);
|
||||
extern void zfs_nicebytes(uint64_t, char *, size_t);
|
||||
extern int zfs_nicestrtonum(libzfs_handle_t *, const char *, uint64_t *);
|
||||
|
||||
/*
|
||||
@@ -874,7 +789,6 @@ extern int zpool_in_use(libzfs_handle_t *, int, pool_state_t *, char **,
|
||||
/*
|
||||
* Label manipulation.
|
||||
*/
|
||||
extern int zpool_read_label(int, nvlist_t **, int *);
|
||||
extern int zpool_clear_label(int);
|
||||
|
||||
/*
|
||||
@@ -893,22 +807,6 @@ int zfs_smb_acl_rename(libzfs_handle_t *, char *, char *, char *, char *);
|
||||
extern int zpool_enable_datasets(zpool_handle_t *, const char *, int);
|
||||
extern int zpool_disable_datasets(zpool_handle_t *, boolean_t);
|
||||
|
||||
/*
|
||||
* Support for Linux libudev derived persistent device strings
|
||||
*/
|
||||
extern boolean_t is_mpath_whole_disk(const char *);
|
||||
extern void update_vdev_config_dev_strs(nvlist_t *);
|
||||
extern char *zfs_strip_partition(char *);
|
||||
extern char *zfs_strip_partition_path(char *);
|
||||
|
||||
#ifdef HAVE_LIBUDEV
|
||||
struct udev_device;
|
||||
|
||||
extern boolean_t udev_is_mpath(struct udev_device *dev);
|
||||
extern int zfs_device_get_devid(struct udev_device *, char *, size_t);
|
||||
extern int zfs_device_get_physical(struct udev_device *, char *, size_t);
|
||||
#endif
|
||||
|
||||
extern int zfs_remap_indirects(libzfs_handle_t *hdl, const char *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* CDDL HEADER START
|
||||
*
|
||||
* The contents of this file are subject to the terms of the
|
||||
* Common Development and Distribution License (the "License").
|
||||
* You may not use this file except in compliance with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
||||
* or http://www.opensolaris.org/os/licensing.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL HEADER in each
|
||||
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
||||
* If applicable, add the following below this CDDL HEADER, with the
|
||||
* fields enclosed by brackets "[]" replaced with your own identifying
|
||||
* information: Portions Copyright [yyyy] [name of copyright owner]
|
||||
*
|
||||
* CDDL HEADER END
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018 by Delphix. All rights reserved.
|
||||
*/
|
||||
|
||||
#ifndef _LIBZUTIL_H
|
||||
#define _LIBZUTIL_H
|
||||
|
||||
#include <sys/nvpair.h>
|
||||
#include <sys/fs/zfs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Default wait time for a device name to be created.
|
||||
*/
|
||||
#define DISK_LABEL_WAIT (30 * 1000) /* 30 seconds */
|
||||
|
||||
|
||||
/*
|
||||
* Pool Config Operations
|
||||
*
|
||||
* These are specific to the library libzfs or libzpool instance.
|
||||
*/
|
||||
typedef nvlist_t *refresh_config_func_t(void *, nvlist_t *);
|
||||
|
||||
typedef int pool_active_func_t(void *, const char *, uint64_t, boolean_t *);
|
||||
|
||||
typedef const struct pool_config_ops {
|
||||
refresh_config_func_t *pco_refresh_config;
|
||||
pool_active_func_t *pco_pool_active;
|
||||
} pool_config_ops_t;
|
||||
|
||||
/*
|
||||
* An instance of pool_config_ops_t is expected in the caller's binary.
|
||||
*/
|
||||
extern const pool_config_ops_t libzfs_config_ops;
|
||||
extern const pool_config_ops_t libzpool_config_ops;
|
||||
|
||||
typedef struct importargs {
|
||||
char **path; /* a list of paths to search */
|
||||
int paths; /* number of paths to search */
|
||||
const char *poolname; /* name of a pool to find */
|
||||
uint64_t guid; /* guid of a pool to find */
|
||||
const char *cachefile; /* cachefile to use for import */
|
||||
boolean_t can_be_active; /* can the pool be active? */
|
||||
boolean_t scan; /* prefer scanning to libblkid cache */
|
||||
nvlist_t *policy; /* load policy (max txg, rewind, etc.) */
|
||||
} importargs_t;
|
||||
|
||||
extern nvlist_t *zpool_search_import(void *, importargs_t *,
|
||||
const pool_config_ops_t *);
|
||||
extern int zpool_find_config(void *, const char *, nvlist_t **, importargs_t *,
|
||||
const pool_config_ops_t *);
|
||||
|
||||
extern const char * const * zpool_default_search_paths(size_t *count);
|
||||
extern int zpool_read_label(int, nvlist_t **, int *);
|
||||
extern int zpool_label_disk_wait(const char *, int);
|
||||
|
||||
struct udev_device;
|
||||
|
||||
extern int zfs_device_get_devid(struct udev_device *, char *, size_t);
|
||||
extern int zfs_device_get_physical(struct udev_device *, char *, size_t);
|
||||
extern void update_vdev_config_dev_strs(nvlist_t *);
|
||||
|
||||
/*
|
||||
* Default device paths
|
||||
*/
|
||||
#define DISK_ROOT "/dev"
|
||||
#define UDISK_ROOT "/dev/disk"
|
||||
#define ZVOL_ROOT "/dev/zvol"
|
||||
|
||||
extern int zfs_append_partition(char *path, size_t max_len);
|
||||
extern int zfs_resolve_shortname(const char *name, char *path, size_t pathlen);
|
||||
|
||||
extern char *zfs_strip_partition(char *);
|
||||
extern char *zfs_strip_partition_path(char *);
|
||||
|
||||
extern int zfs_strcmp_pathname(const char *, const char *, int);
|
||||
|
||||
extern int zfs_dev_is_dm(const char *);
|
||||
extern int zfs_dev_is_whole_disk(const char *);
|
||||
extern char *zfs_get_underlying_path(const char *);
|
||||
extern char *zfs_get_enclosure_sysfs_path(const char *);
|
||||
|
||||
#ifdef HAVE_LIBUDEV
|
||||
extern boolean_t is_mpath_whole_disk(const char *);
|
||||
#else
|
||||
#define is_mpath_whole_disk(path) (B_FALSE);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Formats for iostat numbers. Examples: "12K", "30ms", "4B", "2321234", "-".
|
||||
*
|
||||
* ZFS_NICENUM_1024: Print kilo, mega, tera, peta, exa..
|
||||
* ZFS_NICENUM_BYTES: Print single bytes ("13B"), kilo, mega, tera...
|
||||
* ZFS_NICENUM_TIME: Print nanosecs, microsecs, millisecs, seconds...
|
||||
* ZFS_NICENUM_RAW: Print the raw number without any formatting
|
||||
* ZFS_NICENUM_RAWTIME: Same as RAW, but print dashes ('-') for zero.
|
||||
*/
|
||||
enum zfs_nicenum_format {
|
||||
ZFS_NICENUM_1024 = 0,
|
||||
ZFS_NICENUM_BYTES = 1,
|
||||
ZFS_NICENUM_TIME = 2,
|
||||
ZFS_NICENUM_RAW = 3,
|
||||
ZFS_NICENUM_RAWTIME = 4
|
||||
};
|
||||
|
||||
/*
|
||||
* Convert a number to a human-readable form.
|
||||
*/
|
||||
extern void zfs_nicebytes(uint64_t, char *, size_t);
|
||||
extern void zfs_nicenum(uint64_t, char *, size_t);
|
||||
extern void zfs_nicenum_format(uint64_t, char *, size_t,
|
||||
enum zfs_nicenum_format);
|
||||
extern void zfs_nicetime(uint64_t, char *, size_t);
|
||||
|
||||
#define nicenum(num, buf, size) zfs_nicenum(num, buf, size)
|
||||
|
||||
extern void zpool_dump_ddt(const ddt_stat_t *, const ddt_histogram_t *);
|
||||
extern int zpool_history_unpack(char *, uint64_t, uint64_t *, nvlist_t ***,
|
||||
uint_t *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _LIBZUTIL_H */
|
||||
@@ -663,7 +663,6 @@ extern void random_init(void);
|
||||
extern void random_fini(void);
|
||||
|
||||
struct spa;
|
||||
extern void nicenum(uint64_t num, char *buf, size_t);
|
||||
extern void show_pool_stats(struct spa *);
|
||||
extern int set_global_var(char *arg);
|
||||
|
||||
|
||||
@@ -372,6 +372,7 @@ typedef struct zinject_record {
|
||||
#define ZINJECT_NULL 0x1
|
||||
#define ZINJECT_FLUSH_ARC 0x2
|
||||
#define ZINJECT_UNLOAD_SPA 0x4
|
||||
#define ZINJECT_CALC_RANGE 0x8
|
||||
|
||||
#define ZEVENT_NONE 0x0
|
||||
#define ZEVENT_NONBLOCK 0x1
|
||||
|
||||
Reference in New Issue
Block a user