/* * Function: be_sort * Description: Sort BE node list * Parameters: * pointer to address of list head * sort order type * Return: * BE_SUCCESS - Success * be_errno_t - Failure * Side effect: * node list sorted by name * Scope: * Public */ int be_sort(be_node_list_t **be_nodes, int order) { int (*compar)(const void *, const void *) = be_qsort_compare_BEs_date; if (be_nodes == NULL) return (BE_ERR_INVAL); switch (order) { case BE_SORT_UNSPECIFIED: case BE_SORT_DATE: compar = be_qsort_compare_BEs_date; break; case BE_SORT_DATE_REV: compar = be_qsort_compare_BEs_date_rev; break; case BE_SORT_NAME: compar = be_qsort_compare_BEs_name; break; case BE_SORT_NAME_REV: compar = be_qsort_compare_BEs_name_rev; break; case BE_SORT_SPACE: compar = be_qsort_compare_BEs_space; break; case BE_SORT_SPACE_REV: compar = be_qsort_compare_BEs_space_rev; break; default: be_print_err(gettext("be_sort: invalid sort order %d\n"), order); return (BE_ERR_INVAL); } return (be_sort_list(be_nodes, compar)); }
/* * Function: _be_list * Description: This does the actual work described in be_list. * Parameters: * be_name - The name of the BE to look up. * If NULL a list of all BEs will be returned. * be_nodes - A reference pointer to the list of BEs. The list * structure will be allocated here and must * be freed by a call to be_free_list. If there are no * BEs found on the system this reference will be * set to NULL. * Return: * BE_SUCCESS - Success * be_errno_t - Failure * Scope: * Semi-private (library wide use only) */ int _be_list(char *be_name, be_node_list_t **be_nodes) { list_callback_data_t cb = { 0 }; be_transaction_data_t bt = { 0 }; int ret = BE_SUCCESS; zpool_handle_t *zphp; char *rpool = NULL; struct be_defaults be_defaults; if (be_nodes == NULL) return (BE_ERR_INVAL); be_get_defaults(&be_defaults); if (be_find_current_be(&bt) != BE_SUCCESS) { /* * We were unable to find a currently booted BE which * probably means that we're not booted in a BE envoronment. * None of the BE's will be marked as the active BE. */ (void) strcpy(cb.current_be, "-"); } else { (void) strncpy(cb.current_be, bt.obe_name, sizeof (cb.current_be)); rpool = bt.obe_zpool; } /* * If be_name is NULL we'll look for all BE's on the system. * If not then we will only return data for the specified BE. */ if (be_name != NULL) cb.be_name = strdup(be_name); if (be_defaults.be_deflt_rpool_container && rpool != NULL) { if ((zphp = zpool_open(g_zfs, rpool)) == NULL) { be_print_err(gettext("be_list: failed to " "open rpool (%s): %s\n"), rpool, libzfs_error_description(g_zfs)); free(cb.be_name); return (zfs_err_to_be_err(g_zfs)); } ret = be_get_list_callback(zphp, &cb); } else { if ((zpool_iter(g_zfs, be_get_list_callback, &cb)) != 0) { if (cb.be_nodes_head != NULL) { be_free_list(cb.be_nodes_head); cb.be_nodes_head = NULL; cb.be_nodes = NULL; } ret = BE_ERR_BE_NOENT; } } if (cb.be_nodes_head == NULL) { if (be_name != NULL) be_print_err(gettext("be_list: BE (%s) does not " "exist\n"), be_name); else be_print_err(gettext("be_list: No BE's found\n")); ret = BE_ERR_BE_NOENT; } *be_nodes = cb.be_nodes_head; free(cb.be_name); be_sort_list(be_nodes); return (ret); }