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