Lines Matching +full:data +full:- +full:lines

1 // SPDX-License-Identifier: CDDL-1.0
10 * or https://opensource.org/licenses/CDDL-1.0.
73 zpool_handle_t *l = ((zpool_node_t *)larg)->zn_handle; in zpool_compare()
74 zpool_handle_t *r = ((zpool_node_t *)rarg)->zn_handle; in zpool_compare()
91 new->zn_handle = zhp; in add_pool()
92 uu_avl_node_init(new, &new->zn_avlnode, zlp->zl_pool); in add_pool()
94 node = uu_avl_find(zlp->zl_avl, new, NULL, &idx); in add_pool()
96 if (zlp->zl_proplist && in add_pool()
97 zpool_expand_proplist(zhp, zlp->zl_proplist, in add_pool()
98 zlp->zl_type, zlp->zl_literal) != 0) { in add_pool()
101 return (-1); in add_pool()
103 new->zn_last_refresh = zlp->zl_last_refresh; in add_pool()
104 uu_avl_insert(zlp->zl_avl, new, idx); in add_pool()
106 zpool_refresh_stats_from_handle(node->zn_handle, zhp); in add_pool()
107 node->zn_last_refresh = zlp->zl_last_refresh; in add_pool()
110 return (-1); in add_pool()
122 add_pool_cb(zpool_handle_t *zhp, void *data) in add_pool_cb() argument
124 (void) add_pool(zhp, data); in add_pool_cb()
142 zlp->zl_pool = uu_avl_pool_create("zfs_pool", sizeof (zpool_node_t), in pool_list_get()
145 if (zlp->zl_pool == NULL) in pool_list_get()
148 if ((zlp->zl_avl = uu_avl_create(zlp->zl_pool, NULL, in pool_list_get()
152 zlp->zl_proplist = proplist; in pool_list_get()
153 zlp->zl_type = type; in pool_list_get()
155 zlp->zl_literal = literal; in pool_list_get()
156 zlp->zl_last_refresh = gethrtime(); in pool_list_get()
160 zlp->zl_findall = B_TRUE; in pool_list_get()
188 zlp->zl_last_refresh = gethrtime(); in pool_list_refresh()
190 if (!zlp->zl_findall) { in pool_list_refresh()
197 for (zpool_node_t *node = uu_avl_first(zlp->zl_avl); in pool_list_refresh()
198 node != NULL; node = uu_avl_next(zlp->zl_avl, node)) { in pool_list_refresh()
200 zpool_refresh_stats(node->zn_handle, &missing); in pool_list_refresh()
202 node->zn_last_refresh = zlp->zl_last_refresh; in pool_list_refresh()
212 for (node = uu_avl_first(zlp->zl_avl); node != NULL; node = next) { in pool_list_refresh()
213 next = uu_avl_next(zlp->zl_avl, node); in pool_list_refresh()
219 if (node->zn_last_refresh == zlp->zl_last_refresh && in pool_list_refresh()
220 zpool_get_state(node->zn_handle) != POOL_STATE_UNAVAIL) in pool_list_refresh()
225 zpool_refresh_stats(node->zn_handle, &missing); in pool_list_refresh()
227 uu_avl_remove(zlp->zl_avl, node); in pool_list_refresh()
228 zpool_close(node->zn_handle); in pool_list_refresh()
231 node->zn_last_refresh = zlp->zl_last_refresh; in pool_list_refresh()
235 return (uu_avl_numnodes(zlp->zl_avl)); in pool_list_refresh()
243 void *data) in pool_list_iter() argument
248 for (node = uu_avl_first(zlp->zl_avl); node != NULL; node = next_node) { in pool_list_iter()
249 next_node = uu_avl_next(zlp->zl_avl, node); in pool_list_iter()
250 if (zpool_get_state(node->zn_handle) != POOL_STATE_UNAVAIL || in pool_list_iter()
252 ret |= func(node->zn_handle, data); in pool_list_iter()
267 if ((walk = uu_avl_walk_start(zlp->zl_avl, UU_WALK_ROBUST)) == NULL) { in pool_list_free()
274 uu_avl_remove(zlp->zl_avl, node); in pool_list_free()
275 zpool_close(node->zn_handle); in pool_list_free()
280 uu_avl_destroy(zlp->zl_avl); in pool_list_free()
281 uu_avl_pool_destroy(zlp->zl_pool); in pool_list_free()
292 return (uu_avl_numnodes(zlp->zl_avl)); in pool_list_count()
302 zpool_iter_f func, void *data) in for_each_pool() argument
311 if (pool_list_iter(list, unavail, func, data) != 0) in for_each_pool()
326 * @data: Custom data to pass to the function
329 for_each_vdev(zpool_handle_t *zhp, pool_vdev_iter_f func, void *data) in for_each_vdev() argument
337 return (for_each_vdev_cb((void *) zhp, nvroot, func, data)); in for_each_vdev()
341 * Process the vcdl->vdev_cmd_data[] array to figure out all the unique column
342 * names and their widths. When this function is done, vcdl->uniq_cols,
343 * vcdl->uniq_cols_cnt, and vcdl->uniq_cols_width will be filled in.
350 vdev_cmd_data_t *data; in process_unique_cmd_columns() local
355 for (int i = 0; i < vcdl->count; i++) { in process_unique_cmd_columns()
356 data = &vcdl->data[i]; in process_unique_cmd_columns()
358 for (int j = 0; j < data->cols_cnt; j++) { in process_unique_cmd_columns()
361 if (strcmp(data->cols[j], uniq_cols[k]) == 0) in process_unique_cmd_columns()
371 uniq_cols[cnt] = data->cols[j]; in process_unique_cmd_columns()
387 for (int j = 0; j < vcdl->count; j++) { in process_unique_cmd_columns()
389 data = &vcdl->data[j]; in process_unique_cmd_columns()
390 for (k = 0; k < data->cols_cnt; k++) { in process_unique_cmd_columns()
392 if (strcmp(data->cols[k], uniq_cols[i]) == 0) { in process_unique_cmd_columns()
396 strlen(data->lines[k])); in process_unique_cmd_columns()
402 vcdl->uniq_cols = uniq_cols; in process_unique_cmd_columns()
403 vcdl->uniq_cols_cnt = cnt; in process_unique_cmd_columns()
404 vcdl->uniq_cols_width = uniq_cols_width; in process_unique_cmd_columns()
411 * When running 'zpool iostat|status -c' the lines of output can either be
422 * Returns 0 if line was processed, and there are more lines can still be
428 vdev_process_cmd_output(vdev_cmd_data_t *data, char *line) in vdev_process_cmd_output() argument
454 for (int i = 0; i < data->cols_cnt; i++) { in vdev_process_cmd_output()
455 if (strcmp(col, data->cols[i]) == 0) in vdev_process_cmd_output()
461 tmp = realloc(data->lines, in vdev_process_cmd_output()
462 (data->lines_cnt + 1) * sizeof (*data->lines)); in vdev_process_cmd_output()
466 data->lines = tmp; in vdev_process_cmd_output()
467 data->lines[data->lines_cnt] = strdup(val); in vdev_process_cmd_output()
468 data->lines_cnt++; in vdev_process_cmd_output()
472 tmp = realloc(data->cols, in vdev_process_cmd_output()
473 (data->cols_cnt + 1) * sizeof (*data->cols)); in vdev_process_cmd_output()
477 data->cols = tmp; in vdev_process_cmd_output()
478 data->cols[data->cols_cnt] = strdup(col); in vdev_process_cmd_output()
479 data->cols_cnt++; in vdev_process_cmd_output()
489 * Run the cmd and store results in *data.
492 vdev_run_cmd(vdev_cmd_data_t *data, char *cmd) in vdev_run_cmd() argument
497 char **lines = NULL; in vdev_run_cmd() local
501 env = zpool_vdev_script_alloc_env(data->pool, data->path, data->upath, in vdev_run_cmd()
502 data->vdev_enc_sysfs_path, NULL, NULL); in vdev_run_cmd()
507 rc = libzfs_run_process_get_stdout_nopath(cmd, argv, env, &lines, in vdev_run_cmd()
517 if (vdev_process_cmd_output(data, lines[i]) != 0) in vdev_run_cmd()
521 if (lines != NULL) in vdev_run_cmd()
522 libzfs_free_str_array(lines, lines_cnt); in vdev_run_cmd()
526 * Generate the search path for zpool iostat/status -c scripts.
542 env, ZPOOL_SCRIPTS_DIR) != -1) { in zpool_get_cmd_search_path()
547 if (asprintf(&sp, "%s", ZPOOL_SCRIPTS_DIR) != -1) in zpool_get_cmd_search_path()
557 vdev_cmd_data_t *data = cb_cmd_data; in vdev_run_cmd_thread() local
560 cmddup = strdup(data->cmd); in vdev_run_cmd_thread()
579 "%s/%s", dir, cmd) == -1) in vdev_run_cmd_thread()
583 vdev_run_cmd(data, fullpath); in vdev_run_cmd_thread()
597 vdev_cmd_data_t *data; in for_each_vdev_run_cb() local
615 for (i = 0; i < vcdl->count; i++) { in for_each_vdev_run_cb()
616 if ((strcmp(vcdl->data[i].path, path) == 0) && in for_each_vdev_run_cb()
617 (strcmp(vcdl->data[i].pool, zpool_get_name(zhp)) == 0)) { in for_each_vdev_run_cb()
624 for (i = 0; i < vcdl->vdev_names_count; i++) { in for_each_vdev_run_cb()
625 vname = zpool_vdev_name(g_zfs, zhp, nv, vcdl->cb_name_flags); in for_each_vdev_run_cb()
626 if (strcmp(vcdl->vdev_names[i], vname) == 0) { in for_each_vdev_run_cb()
635 if (!match && vcdl->vdev_names_count) in for_each_vdev_run_cb()
641 if (!(vcdl->data = realloc(vcdl->data, in for_each_vdev_run_cb()
642 sizeof (*vcdl->data) * (vcdl->count + 1)))) in for_each_vdev_run_cb()
645 data = &vcdl->data[vcdl->count]; in for_each_vdev_run_cb()
647 data->pool = strdup(zpool_get_name(zhp)); in for_each_vdev_run_cb()
648 data->path = strdup(path); in for_each_vdev_run_cb()
649 data->upath = zfs_get_underlying_path(path); in for_each_vdev_run_cb()
650 data->cmd = vcdl->cmd; in for_each_vdev_run_cb()
651 data->lines = data->cols = NULL; in for_each_vdev_run_cb()
652 data->lines_cnt = data->cols_cnt = 0; in for_each_vdev_run_cb()
654 data->vdev_enc_sysfs_path = strdup(vdev_enc_sysfs_path); in for_each_vdev_run_cb()
656 data->vdev_enc_sysfs_path = NULL; in for_each_vdev_run_cb()
658 vcdl->count++; in for_each_vdev_run_cb()
684 for (int i = 0; i < vcdl->count; i++) { in all_pools_for_each_vdev_run_vcdl()
686 (void *) &vcdl->data[i]); in all_pools_for_each_vdev_run_vcdl()
696 * output from the command in vcdk->data[].line for all vdevs. If you want
710 vcdl->cmd = cmd; in all_pools_for_each_vdev_run()
712 vcdl->vdev_names = vdev_names; in all_pools_for_each_vdev_run()
713 vcdl->vdev_names_count = vdev_names_count; in all_pools_for_each_vdev_run()
714 vcdl->cb_name_flags = cb_name_flags; in all_pools_for_each_vdev_run()
715 vcdl->g_zfs = g_zfs; in all_pools_for_each_vdev_run()
725 * vcdl->data[] now contains all the column names and values for each in all_pools_for_each_vdev_run()
740 free(vcdl->uniq_cols); in free_vdev_cmd_data_list()
741 free(vcdl->uniq_cols_width); in free_vdev_cmd_data_list()
743 for (int i = 0; i < vcdl->count; i++) { in free_vdev_cmd_data_list()
744 free(vcdl->data[i].path); in free_vdev_cmd_data_list()
745 free(vcdl->data[i].pool); in free_vdev_cmd_data_list()
746 free(vcdl->data[i].upath); in free_vdev_cmd_data_list()
748 for (int j = 0; j < vcdl->data[i].lines_cnt; j++) in free_vdev_cmd_data_list()
749 free(vcdl->data[i].lines[j]); in free_vdev_cmd_data_list()
751 free(vcdl->data[i].lines); in free_vdev_cmd_data_list()
753 for (int j = 0; j < vcdl->data[i].cols_cnt; j++) in free_vdev_cmd_data_list()
754 free(vcdl->data[i].cols[j]); in free_vdev_cmd_data_list()
756 free(vcdl->data[i].cols); in free_vdev_cmd_data_list()
757 free(vcdl->data[i].vdev_enc_sysfs_path); in free_vdev_cmd_data_list()
759 free(vcdl->data); in free_vdev_cmd_data_list()