Path: blob/main/sys/contrib/openzfs/cmd/zpool/zpool_util.h
48288 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*/21/*22* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.23*/2425#ifndef ZPOOL_UTIL_H26#define ZPOOL_UTIL_H2728#include <libnvpair.h>29#include <libzfs.h>30#include <libzutil.h>3132#ifdef __cplusplus33extern "C" {34#endif3536/* Path to scripts you can run with "zpool status/iostat -c" */37#define ZPOOL_SCRIPTS_DIR SYSCONFDIR"/zfs/zpool.d"3839/*40* Basic utility functions41*/42void *safe_malloc(size_t);43void *safe_realloc(void *, size_t);44void zpool_no_memory(void);45uint_t num_logs(nvlist_t *nv);46uint64_t array64_max(uint64_t array[], unsigned int len);47int highbit64(uint64_t i);48int lowbit64(uint64_t i);4950/*51* Misc utility functions52*/53char *zpool_get_cmd_search_path(void);5455/*56* Virtual device functions57*/5859nvlist_t *make_root_vdev(zpool_handle_t *zhp, nvlist_t *props, int force,60int check_rep, boolean_t replacing, boolean_t dryrun, int argc,61char **argv);62nvlist_t *split_mirror_vdev(zpool_handle_t *zhp, char *newname,63nvlist_t *props, splitflags_t flags, int argc, char **argv);6465/*66* Pool list functions67*/68int for_each_pool(int, char **, boolean_t unavail, zprop_list_t **, zfs_type_t,69boolean_t, zpool_iter_f, void *);7071/* Vdev list functions */72int for_each_vdev(zpool_handle_t *zhp, pool_vdev_iter_f func, void *data);7374typedef struct zpool_list zpool_list_t;7576zpool_list_t *pool_list_get(int, char **, zprop_list_t **, zfs_type_t,77boolean_t, int *);78int pool_list_refresh(zpool_list_t *);79int pool_list_iter(zpool_list_t *, int unavail, zpool_iter_f, void *);80void pool_list_free(zpool_list_t *);81int pool_list_count(zpool_list_t *);8283extern libzfs_handle_t *g_zfs;848586typedef struct vdev_cmd_data87{88char **lines; /* Array of lines of output, minus the column name */89int lines_cnt; /* Number of lines in the array */9091char **cols; /* Array of column names */92int cols_cnt; /* Number of column names */939495char *path; /* vdev path */96char *upath; /* vdev underlying path */97char *pool; /* Pool name */98char *cmd; /* backpointer to cmd */99char *vdev_enc_sysfs_path; /* enclosure sysfs path (if any) */100} vdev_cmd_data_t;101102typedef struct vdev_cmd_data_list103{104char *cmd; /* Command to run */105unsigned int count; /* Number of vdev_cmd_data items (vdevs) */106107/* fields used to select only certain vdevs, if requested */108libzfs_handle_t *g_zfs;109char **vdev_names;110int vdev_names_count;111int cb_name_flags;112113vdev_cmd_data_t *data; /* Array of vdevs */114115/* List of unique column names and widths */116char **uniq_cols;117int uniq_cols_cnt;118int *uniq_cols_width;119120} vdev_cmd_data_list_t;121122vdev_cmd_data_list_t *all_pools_for_each_vdev_run(int argc, char **argv,123char *cmd, libzfs_handle_t *g_zfs, char **vdev_names, int vdev_names_count,124int cb_name_flags);125126void free_vdev_cmd_data_list(vdev_cmd_data_list_t *vcdl);127128void free_vdev_cmd_data(vdev_cmd_data_t *data);129130int vdev_run_cmd_simple(char *path, char *cmd);131132int check_device(const char *path, boolean_t force,133boolean_t isspare, boolean_t iswholedisk);134boolean_t check_sector_size_database(char *path, int *sector_size);135void vdev_error(const char *fmt, ...) __attribute__((format(printf, 1, 2)));136int check_file(const char *file, boolean_t force, boolean_t isspare);137void after_zpool_upgrade(zpool_handle_t *zhp);138int check_file_generic(const char *file, boolean_t force, boolean_t isspare);139140int zpool_power(zpool_handle_t *zhp, char *vdev, boolean_t turn_on);141int zpool_power_current_state(zpool_handle_t *zhp, char *vdev);142143#ifdef __cplusplus144}145#endif146147#endif /* ZPOOL_UTIL_H */148149150