1*d8ab6e12SDon Brady /*
2*d8ab6e12SDon Brady  * CDDL HEADER START
3*d8ab6e12SDon Brady  *
4*d8ab6e12SDon Brady  * The contents of this file are subject to the terms of the
5*d8ab6e12SDon Brady  * Common Development and Distribution License (the "License").
6*d8ab6e12SDon Brady  * You may not use this file except in compliance with the License.
7*d8ab6e12SDon Brady  *
8*d8ab6e12SDon Brady  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*d8ab6e12SDon Brady  * or http://www.opensolaris.org/os/licensing.
10*d8ab6e12SDon Brady  * See the License for the specific language governing permissions
11*d8ab6e12SDon Brady  * and limitations under the License.
12*d8ab6e12SDon Brady  *
13*d8ab6e12SDon Brady  * When distributing Covered Code, include this CDDL HEADER in each
14*d8ab6e12SDon Brady  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*d8ab6e12SDon Brady  * If applicable, add the following below this CDDL HEADER, with the
16*d8ab6e12SDon Brady  * fields enclosed by brackets "[]" replaced with your own identifying
17*d8ab6e12SDon Brady  * information: Portions Copyright [yyyy] [name of copyright owner]
18*d8ab6e12SDon Brady  *
19*d8ab6e12SDon Brady  * CDDL HEADER END
20*d8ab6e12SDon Brady  */
21*d8ab6e12SDon Brady /*
22*d8ab6e12SDon Brady  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23*d8ab6e12SDon Brady  * Copyright (c) 2018 by Delphix. All rights reserved.
24*d8ab6e12SDon Brady  * Copyright 2020 Joyent, Inc.
25*d8ab6e12SDon Brady  */
26*d8ab6e12SDon Brady 
27*d8ab6e12SDon Brady #ifndef	_LIBZUTIL_H
28*d8ab6e12SDon Brady #define	_LIBZUTIL_H
29*d8ab6e12SDon Brady 
30*d8ab6e12SDon Brady #include <sys/nvpair.h>
31*d8ab6e12SDon Brady #include <sys/fs/zfs.h>
32*d8ab6e12SDon Brady 
33*d8ab6e12SDon Brady #ifdef	__cplusplus
34*d8ab6e12SDon Brady extern "C" {
35*d8ab6e12SDon Brady #endif
36*d8ab6e12SDon Brady 
37*d8ab6e12SDon Brady /*
38*d8ab6e12SDon Brady  * Default wait time for a device name to be created.
39*d8ab6e12SDon Brady  */
40*d8ab6e12SDon Brady #define	DISK_LABEL_WAIT		(30 * 1000)  /* 30 seconds */
41*d8ab6e12SDon Brady 
42*d8ab6e12SDon Brady 
43*d8ab6e12SDon Brady /*
44*d8ab6e12SDon Brady  * Pool Config Operations
45*d8ab6e12SDon Brady  *
46*d8ab6e12SDon Brady  * These are specific to the library libzfs or libzpool instance.
47*d8ab6e12SDon Brady  */
48*d8ab6e12SDon Brady typedef nvlist_t *refresh_config_func_t(void *, nvlist_t *);
49*d8ab6e12SDon Brady 
50*d8ab6e12SDon Brady typedef int pool_active_func_t(void *, const char *, uint64_t, boolean_t *);
51*d8ab6e12SDon Brady 
52*d8ab6e12SDon Brady typedef struct pool_config_ops {
53*d8ab6e12SDon Brady 	refresh_config_func_t	*pco_refresh_config;
54*d8ab6e12SDon Brady 	pool_active_func_t	*pco_pool_active;
55*d8ab6e12SDon Brady } pool_config_ops_t;
56*d8ab6e12SDon Brady 
57*d8ab6e12SDon Brady /*
58*d8ab6e12SDon Brady  * An instance of pool_config_ops_t is expected in the caller's binary.
59*d8ab6e12SDon Brady  */
60*d8ab6e12SDon Brady extern const pool_config_ops_t libzfs_config_ops;
61*d8ab6e12SDon Brady extern const pool_config_ops_t libzpool_config_ops;
62*d8ab6e12SDon Brady 
63*d8ab6e12SDon Brady typedef struct importargs {
64*d8ab6e12SDon Brady 	char **path;		/* a list of paths to search		*/
65*d8ab6e12SDon Brady 	int paths;		/* number of paths to search		*/
66*d8ab6e12SDon Brady 	const char *poolname;	/* name of a pool to find		*/
67*d8ab6e12SDon Brady 	uint64_t guid;		/* guid of a pool to find		*/
68*d8ab6e12SDon Brady 	const char *cachefile;	/* cachefile to use for import		*/
69*d8ab6e12SDon Brady 	boolean_t can_be_active; /* can the pool be active?		*/
70*d8ab6e12SDon Brady 	boolean_t scan;		/* prefer scanning to libblkid cache    */
71*d8ab6e12SDon Brady 	nvlist_t *policy;	/* load policy (max txg, rewind, etc.)	*/
72*d8ab6e12SDon Brady } importargs_t;
73*d8ab6e12SDon Brady 
74*d8ab6e12SDon Brady extern nvlist_t *zpool_search_import(void *, importargs_t *,
75*d8ab6e12SDon Brady     const pool_config_ops_t *);
76*d8ab6e12SDon Brady extern int zpool_find_config(void *, const char *, nvlist_t **, importargs_t *,
77*d8ab6e12SDon Brady     const pool_config_ops_t *);
78*d8ab6e12SDon Brady 
79*d8ab6e12SDon Brady extern int zpool_read_label(int, nvlist_t **, int *);
80*d8ab6e12SDon Brady 
81*d8ab6e12SDon Brady extern boolean_t zfs_isnumber(const char *);
82*d8ab6e12SDon Brady 
83*d8ab6e12SDon Brady /*
84*d8ab6e12SDon Brady  * Formats for iostat numbers.  Examples: "12K", "30ms", "4B", "2321234", "-".
85*d8ab6e12SDon Brady  *
86*d8ab6e12SDon Brady  * ZFS_NICENUM_1024:	Print kilo, mega, tera, peta, exa..
87*d8ab6e12SDon Brady  * ZFS_NICENUM_BYTES:	Print single bytes ("13B"), kilo, mega, tera...
88*d8ab6e12SDon Brady  * ZFS_NICENUM_TIME:	Print nanosecs, microsecs, millisecs, seconds...
89*d8ab6e12SDon Brady  * ZFS_NICENUM_RAW:	Print the raw number without any formatting
90*d8ab6e12SDon Brady  * ZFS_NICENUM_RAWTIME:	Same as RAW, but print dashes ('-') for zero.
91*d8ab6e12SDon Brady  */
92*d8ab6e12SDon Brady enum zfs_nicenum_format {
93*d8ab6e12SDon Brady 	ZFS_NICENUM_1024 = 0,
94*d8ab6e12SDon Brady 	ZFS_NICENUM_BYTES = 1,
95*d8ab6e12SDon Brady 	ZFS_NICENUM_TIME = 2,
96*d8ab6e12SDon Brady 	ZFS_NICENUM_RAW = 3,
97*d8ab6e12SDon Brady 	ZFS_NICENUM_RAWTIME = 4
98*d8ab6e12SDon Brady };
99*d8ab6e12SDon Brady 
100*d8ab6e12SDon Brady /*
101*d8ab6e12SDon Brady  * Convert a number to a human-readable form.
102*d8ab6e12SDon Brady  */
103*d8ab6e12SDon Brady extern void zfs_nicebytes(uint64_t, char *, size_t);
104*d8ab6e12SDon Brady extern void zfs_nicenum(uint64_t, char *, size_t);
105*d8ab6e12SDon Brady extern void zfs_nicenum_format(uint64_t, char *, size_t,
106*d8ab6e12SDon Brady     enum zfs_nicenum_format);
107*d8ab6e12SDon Brady extern void zfs_nicetime(uint64_t, char *, size_t);
108*d8ab6e12SDon Brady 
109*d8ab6e12SDon Brady #define	nicenum(num, buf, size)	zfs_nicenum(num, buf, size)
110*d8ab6e12SDon Brady 
111*d8ab6e12SDon Brady extern void zpool_dump_ddt(const ddt_stat_t *, const ddt_histogram_t *);
112*d8ab6e12SDon Brady extern int zpool_history_unpack(char *, uint64_t, uint64_t *, nvlist_t ***,
113*d8ab6e12SDon Brady     uint_t *);
114*d8ab6e12SDon Brady 
115*d8ab6e12SDon Brady /* Part of SPL in OpenZFS */
116*d8ab6e12SDon Brady extern ulong_t get_system_hostid(void);
117*d8ab6e12SDon Brady 
118*d8ab6e12SDon Brady #ifdef	__cplusplus
119*d8ab6e12SDon Brady }
120*d8ab6e12SDon Brady #endif
121*d8ab6e12SDon Brady 
122*d8ab6e12SDon Brady #endif	/* _LIBZUTIL_H */
123