xref: /freebsd/sys/contrib/openzfs/cmd/zpool/zpool_util.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1*61145dc2SMartin Matuska // SPDX-License-Identifier: CDDL-1.0
2eda14cbcSMatt Macy /*
3eda14cbcSMatt Macy  * CDDL HEADER START
4eda14cbcSMatt Macy  *
5eda14cbcSMatt Macy  * The contents of this file are subject to the terms of the
6eda14cbcSMatt Macy  * Common Development and Distribution License (the "License").
7eda14cbcSMatt Macy  * You may not use this file except in compliance with the License.
8eda14cbcSMatt Macy  *
9eda14cbcSMatt Macy  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10271171e0SMartin Matuska  * or https://opensource.org/licenses/CDDL-1.0.
11eda14cbcSMatt Macy  * See the License for the specific language governing permissions
12eda14cbcSMatt Macy  * and limitations under the License.
13eda14cbcSMatt Macy  *
14eda14cbcSMatt Macy  * When distributing Covered Code, include this CDDL HEADER in each
15eda14cbcSMatt Macy  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16eda14cbcSMatt Macy  * If applicable, add the following below this CDDL HEADER, with the
17eda14cbcSMatt Macy  * fields enclosed by brackets "[]" replaced with your own identifying
18eda14cbcSMatt Macy  * information: Portions Copyright [yyyy] [name of copyright owner]
19eda14cbcSMatt Macy  *
20eda14cbcSMatt Macy  * CDDL HEADER END
21eda14cbcSMatt Macy  */
22eda14cbcSMatt Macy /*
23eda14cbcSMatt Macy  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24eda14cbcSMatt Macy  */
25eda14cbcSMatt Macy 
26eda14cbcSMatt Macy #ifndef	ZPOOL_UTIL_H
27eda14cbcSMatt Macy #define	ZPOOL_UTIL_H
28eda14cbcSMatt Macy 
29eda14cbcSMatt Macy #include <libnvpair.h>
30eda14cbcSMatt Macy #include <libzfs.h>
316ba2210eSMartin Matuska #include <libzutil.h>
32eda14cbcSMatt Macy 
33eda14cbcSMatt Macy #ifdef	__cplusplus
34eda14cbcSMatt Macy extern "C" {
35eda14cbcSMatt Macy #endif
36eda14cbcSMatt Macy 
37eda14cbcSMatt Macy /* Path to scripts you can run with "zpool status/iostat -c" */
38eda14cbcSMatt Macy #define	ZPOOL_SCRIPTS_DIR SYSCONFDIR"/zfs/zpool.d"
39eda14cbcSMatt Macy 
40eda14cbcSMatt Macy /*
41eda14cbcSMatt Macy  * Basic utility functions
42eda14cbcSMatt Macy  */
43eda14cbcSMatt Macy void *safe_malloc(size_t);
4416038816SMartin Matuska void *safe_realloc(void *, size_t);
45eda14cbcSMatt Macy void zpool_no_memory(void);
46eda14cbcSMatt Macy uint_t num_logs(nvlist_t *nv);
47eda14cbcSMatt Macy uint64_t array64_max(uint64_t array[], unsigned int len);
48eda14cbcSMatt Macy int highbit64(uint64_t i);
49eda14cbcSMatt Macy int lowbit64(uint64_t i);
50eda14cbcSMatt Macy 
51eda14cbcSMatt Macy /*
52eda14cbcSMatt Macy  * Misc utility functions
53eda14cbcSMatt Macy  */
54eda14cbcSMatt Macy char *zpool_get_cmd_search_path(void);
55eda14cbcSMatt Macy 
56eda14cbcSMatt Macy /*
57eda14cbcSMatt Macy  * Virtual device functions
58eda14cbcSMatt Macy  */
59eda14cbcSMatt Macy 
60eda14cbcSMatt Macy nvlist_t *make_root_vdev(zpool_handle_t *zhp, nvlist_t *props, int force,
61eda14cbcSMatt Macy     int check_rep, boolean_t replacing, boolean_t dryrun, int argc,
62eda14cbcSMatt Macy     char **argv);
63eda14cbcSMatt Macy nvlist_t *split_mirror_vdev(zpool_handle_t *zhp, char *newname,
64eda14cbcSMatt Macy     nvlist_t *props, splitflags_t flags, int argc, char **argv);
65eda14cbcSMatt Macy 
66eda14cbcSMatt Macy /*
67eda14cbcSMatt Macy  * Pool list functions
68eda14cbcSMatt Macy  */
69681ce946SMartin Matuska int for_each_pool(int, char **, boolean_t unavail, zprop_list_t **, zfs_type_t,
707877fdebSMatt Macy     boolean_t, zpool_iter_f, void *);
71eda14cbcSMatt Macy 
72eda14cbcSMatt Macy /* Vdev list functions */
73eda14cbcSMatt Macy int for_each_vdev(zpool_handle_t *zhp, pool_vdev_iter_f func, void *data);
74eda14cbcSMatt Macy 
75eda14cbcSMatt Macy typedef struct zpool_list zpool_list_t;
76eda14cbcSMatt Macy 
77681ce946SMartin Matuska zpool_list_t *pool_list_get(int, char **, zprop_list_t **, zfs_type_t,
78681ce946SMartin Matuska     boolean_t, int *);
79eda14cbcSMatt Macy void pool_list_update(zpool_list_t *);
80eda14cbcSMatt Macy int pool_list_iter(zpool_list_t *, int unavail, zpool_iter_f, void *);
81eda14cbcSMatt Macy void pool_list_free(zpool_list_t *);
82eda14cbcSMatt Macy int pool_list_count(zpool_list_t *);
83eda14cbcSMatt Macy void pool_list_remove(zpool_list_t *, zpool_handle_t *);
84eda14cbcSMatt Macy 
85eda14cbcSMatt Macy extern libzfs_handle_t *g_zfs;
86eda14cbcSMatt Macy 
87eda14cbcSMatt Macy 
88eda14cbcSMatt Macy typedef	struct vdev_cmd_data
89eda14cbcSMatt Macy {
90eda14cbcSMatt Macy 	char **lines;	/* Array of lines of output, minus the column name */
91eda14cbcSMatt Macy 	int lines_cnt;	/* Number of lines in the array */
92eda14cbcSMatt Macy 
93eda14cbcSMatt Macy 	char **cols;	/* Array of column names */
94eda14cbcSMatt Macy 	int cols_cnt;	/* Number of column names */
95eda14cbcSMatt Macy 
96eda14cbcSMatt Macy 
97eda14cbcSMatt Macy 	char *path;	/* vdev path */
98eda14cbcSMatt Macy 	char *upath;	/* vdev underlying path */
99eda14cbcSMatt Macy 	char *pool;	/* Pool name */
100eda14cbcSMatt Macy 	char *cmd;	/* backpointer to cmd */
101eda14cbcSMatt Macy 	char *vdev_enc_sysfs_path;	/* enclosure sysfs path (if any) */
102eda14cbcSMatt Macy } vdev_cmd_data_t;
103eda14cbcSMatt Macy 
104eda14cbcSMatt Macy typedef struct vdev_cmd_data_list
105eda14cbcSMatt Macy {
106eda14cbcSMatt Macy 	char *cmd;		/* Command to run */
107eda14cbcSMatt Macy 	unsigned int count;	/* Number of vdev_cmd_data items (vdevs) */
108eda14cbcSMatt Macy 
109eda14cbcSMatt Macy 	/* fields used to select only certain vdevs, if requested */
110eda14cbcSMatt Macy 	libzfs_handle_t *g_zfs;
111eda14cbcSMatt Macy 	char **vdev_names;
112eda14cbcSMatt Macy 	int vdev_names_count;
113eda14cbcSMatt Macy 	int cb_name_flags;
114eda14cbcSMatt Macy 
115eda14cbcSMatt Macy 	vdev_cmd_data_t *data;	/* Array of vdevs */
116eda14cbcSMatt Macy 
117eda14cbcSMatt Macy 	/* List of unique column names and widths */
118eda14cbcSMatt Macy 	char **uniq_cols;
119eda14cbcSMatt Macy 	int uniq_cols_cnt;
120eda14cbcSMatt Macy 	int *uniq_cols_width;
121eda14cbcSMatt Macy 
122eda14cbcSMatt Macy } vdev_cmd_data_list_t;
123eda14cbcSMatt Macy 
124eda14cbcSMatt Macy vdev_cmd_data_list_t *all_pools_for_each_vdev_run(int argc, char **argv,
125eda14cbcSMatt Macy     char *cmd, libzfs_handle_t *g_zfs, char **vdev_names, int vdev_names_count,
126eda14cbcSMatt Macy     int cb_name_flags);
127eda14cbcSMatt Macy 
128eda14cbcSMatt Macy void free_vdev_cmd_data_list(vdev_cmd_data_list_t *vcdl);
129eda14cbcSMatt Macy 
130abcdc1b9SMartin Matuska void free_vdev_cmd_data(vdev_cmd_data_t *data);
131abcdc1b9SMartin Matuska 
132abcdc1b9SMartin Matuska int vdev_run_cmd_simple(char *path, char *cmd);
133abcdc1b9SMartin Matuska 
134eda14cbcSMatt Macy int check_device(const char *path, boolean_t force,
135eda14cbcSMatt Macy     boolean_t isspare, boolean_t iswholedisk);
136eda14cbcSMatt Macy boolean_t check_sector_size_database(char *path, int *sector_size);
1371f88aa09SMartin Matuska void vdev_error(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
138eda14cbcSMatt Macy int check_file(const char *file, boolean_t force, boolean_t isspare);
13916038816SMartin Matuska void after_zpool_upgrade(zpool_handle_t *zhp);
1401f88aa09SMartin Matuska int check_file_generic(const char *file, boolean_t force, boolean_t isspare);
141eda14cbcSMatt Macy 
142b356da80SMartin Matuska int zpool_power(zpool_handle_t *zhp, char *vdev, boolean_t turn_on);
143b356da80SMartin Matuska int zpool_power_current_state(zpool_handle_t *zhp, char *vdev);
144b356da80SMartin Matuska 
145eda14cbcSMatt Macy #ifdef	__cplusplus
146eda14cbcSMatt Macy }
147eda14cbcSMatt Macy #endif
148eda14cbcSMatt Macy 
149eda14cbcSMatt Macy #endif	/* ZPOOL_UTIL_H */
150