* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
+ * or https://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* that command. Otherwise, iterate over the entire command table and display
* a complete usage message.
*/
-static _Noreturn void
+static __attribute__((noreturn)) void
usage(boolean_t requested)
{
FILE *fp = requested ? stdout : stderr;
(strcmp(current_command->name, "get") == 0) ||
(strcmp(current_command->name, "list") == 0))) {
- (void) fprintf(fp,
+ (void) fprintf(fp, "%s",
gettext("\nthe following properties are supported:\n"));
(void) fprintf(fp, "\n\t%-19s %s %s\n\n",
for (c = 0; c < children; c++) {
uint64_t is_log = B_FALSE, is_hole = B_FALSE;
- char *class = "";
+ char *class = (char *)"";
(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_HOLE,
&is_hole);
(void) nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
&is_log);
if (is_log)
- class = VDEV_ALLOC_BIAS_LOG;
+ class = (char *)VDEV_ALLOC_BIAS_LOG;
(void) nvlist_lookup_string(child[c],
ZPOOL_CONFIG_ALLOCATION_BIAS, &class);
if (strcmp(match, class) != 0)
* Add a property pair (name, string-value) into a property nvlist.
*/
static int
-add_prop_list(const char *propname, char *propval, nvlist_t **props,
+add_prop_list(const char *propname, const char *propval, nvlist_t **props,
boolean_t poolprop)
{
zpool_prop_t prop = ZPOOL_PROP_INVAL;
* Set a default property pair (name, string-value) in a property nvlist
*/
static int
-add_prop_list_default(const char *propname, char *propval, nvlist_t **props)
+add_prop_list_default(const char *propname, const char *propval,
+ nvlist_t **props)
{
char *pval;
return (1);
if (stop && noop) {
+ zpool_close(zhp);
(void) fprintf(stderr, gettext("stop request ignored\n"));
return (0);
}
tname ? tname : poolname, ZFS_TYPE_FILESYSTEM);
if (pool != NULL) {
if (zfs_mount(pool, NULL, 0) == 0) {
- ret = zfs_shareall(pool);
- zfs_commit_all_shares();
+ ret = zfs_share(pool, NULL);
+ zfs_commit_shares(NULL);
}
zfs_close(pool);
}
max_width(zpool_handle_t *zhp, nvlist_t *nv, int depth, int max,
int name_flags)
{
- char *name;
- nvlist_t **child;
- uint_t c, children;
- int ret;
-
- name = zpool_vdev_name(g_zfs, zhp, nv, name_flags);
- if (strlen(name) + depth > max)
- max = strlen(name) + depth;
+ static const char *const subtypes[] =
+ {ZPOOL_CONFIG_SPARES, ZPOOL_CONFIG_L2CACHE, ZPOOL_CONFIG_CHILDREN};
+ char *name = zpool_vdev_name(g_zfs, zhp, nv, name_flags);
+ max = MAX(strlen(name) + depth, max);
free(name);
- if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_SPARES,
- &child, &children) == 0) {
- for (c = 0; c < children; c++)
- if ((ret = max_width(zhp, child[c], depth + 2,
- max, name_flags)) > max)
- max = ret;
- }
-
- if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_L2CACHE,
- &child, &children) == 0) {
- for (c = 0; c < children; c++)
- if ((ret = max_width(zhp, child[c], depth + 2,
- max, name_flags)) > max)
- max = ret;
- }
-
- if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
- &child, &children) == 0) {
- for (c = 0; c < children; c++)
- if ((ret = max_width(zhp, child[c], depth + 2,
- max, name_flags)) > max)
- max = ret;
- }
+ nvlist_t **child;
+ uint_t children;
+ for (size_t i = 0; i < ARRAY_SIZE(subtypes); ++i)
+ if (nvlist_lookup_nvlist_array(nv, subtypes[i],
+ &child, &children) == 0)
+ for (uint_t c = 0; c < children; ++c)
+ max = MAX(max_width(zhp, child[c], depth + 2,
+ max, name_flags), max);
return (max);
}
} status_cbdata_t;
/* Return 1 if string is NULL, empty, or whitespace; return 0 otherwise. */
-static int
-is_blank_str(char *str)
+static boolean_t
+is_blank_str(const char *str)
{
- while (str != NULL && *str != '\0') {
+ for (; str != NULL && *str != '\0'; ++str)
if (!isblank(*str))
- return (0);
- str++;
- }
- return (1);
+ return (B_FALSE);
+ return (B_TRUE);
}
/* Print command output lines for specific vdev in a specific pool */
{
vdev_cmd_data_t *data;
int i, j;
- char *val;
+ const char *val;
for (i = 0; i < vcdl->count; i++) {
if ((strcmp(vcdl->data[i].path, path) != 0) ||
printf("%*s", vcdl->uniq_cols_width[j], val);
if (j < vcdl->uniq_cols_cnt - 1)
- printf(" ");
+ fputs(" ", stdout);
}
/* Print out any values that aren't in a column at the end */
for (j = data->cols_cnt; j < data->lines_cnt; j++) {
/* Did we have any columns? If so print a spacer. */
if (vcdl->uniq_cols_cnt > 0)
- printf(" ");
+ fputs(" ", stdout);
val = data->lines[j];
- printf("%s", val ? val : "");
+ fputs(val ?: "", stdout);
}
break;
}
* Return the color associated with a health string. This includes returning
* NULL for no color change.
*/
-static char *
+static const char *
health_str_to_color(const char *health)
{
if (strcmp(health, gettext("FAULTED")) == 0 ||
const char *state;
char *type;
char *path = NULL;
- char *rcolor = NULL, *wcolor = NULL, *ccolor = NULL;
+ const char *rcolor = NULL, *wcolor = NULL, *ccolor = NULL;
if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN,
&child, &children) != 0)
ccolor = ANSI_RED;
if (cb->cb_literal) {
- printf(" ");
+ fputc(' ', stdout);
printf_color(rcolor, "%5llu",
(u_longlong_t)vs->vs_read_errors);
- printf(" ");
+ fputc(' ', stdout);
printf_color(wcolor, "%5llu",
(u_longlong_t)vs->vs_write_errors);
- printf(" ");
+ fputc(' ', stdout);
printf_color(ccolor, "%5llu",
(u_longlong_t)vs->vs_checksum_errors);
} else {
zfs_nicenum(vs->vs_write_errors, wbuf, sizeof (wbuf));
zfs_nicenum(vs->vs_checksum_errors, cbuf,
sizeof (cbuf));
- printf(" ");
+ fputc(' ', stdout);
printf_color(rcolor, "%5s", rbuf);
- printf(" ");
+ fputc(' ', stdout);
printf_color(wcolor, "%5s", wbuf);
- printf(" ");
+ fputc(' ', stdout);
printf_color(ccolor, "%5s", cbuf);
}
if (cb->cb_print_slow_ios) {
if (vs->vs_scan_removing != 0) {
(void) printf(gettext(" (removing)"));
- } else if (vs->vs_noalloc != 0) {
+ } else if (VDEV_STAT_VALID(vs_noalloc, vsc) && vs->vs_noalloc != 0) {
(void) printf(gettext(" (non-allocating)"));
}
(void) nvlist_lookup_uint64_array(root, ZPOOL_CONFIG_SCAN_STATS,
(uint64_t **)&ps, &c);
- if (ps != NULL && ps->pss_state == DSS_SCANNING && children == 0) {
+ /*
+ * If you force fault a drive that's resilvering, its scan stats can
+ * get frozen in time, giving the false impression that it's
+ * being resilvered. That's why we check the state to see if the vdev
+ * is healthy before reporting "resilvering" or "repairing".
+ */
+ if (ps != NULL && ps->pss_state == DSS_SCANNING && children == 0 &&
+ vs->vs_state == VDEV_STATE_HEALTHY) {
if (vs->vs_scan_processed != 0) {
(void) printf(gettext(" (%s)"),
(ps->pss_func == POOL_SCAN_RESILVER) ?
/* The top-level vdevs have the rebuild stats */
if (vrs != NULL && vrs->vrs_state == VDEV_REBUILD_ACTIVE &&
- children == 0) {
+ children == 0 && vs->vs_state == VDEV_STATE_HEALTHY) {
if (vs->vs_rebuild_processed != 0) {
(void) printf(gettext(" (resilvering)"));
}
&is_log);
if (is_log) {
- bias = VDEV_ALLOC_CLASS_LOGS;
+ bias = (char *)VDEV_ALLOC_CLASS_LOGS;
} else {
(void) nvlist_lookup_string(child[c],
ZPOOL_CONFIG_ALLOCATION_BIAS, &bias);
char *name;
uint64_t guid;
uint64_t hostid = 0;
- char *msgid;
- char *hostname = "unknown";
+ const char *msgid;
+ const char *hostname = "unknown";
nvlist_t *nvroot, *nvinfo;
zpool_status_t reason;
zpool_errata_t errata;
if (first)
first = B_FALSE;
else if (!do_all)
- (void) putchar('\n');
+ (void) fputc('\n', stdout);
if (do_all) {
err |= do_import(config, NULL, mntopts,
idata.scan = do_scan;
idata.policy = policy;
- pools = zpool_search_import(g_zfs, &idata, &libzfs_config_ops);
+ libpc_handle_t lpch = {
+ .lpc_lib_handle = g_zfs,
+ .lpc_ops = &libzfs_config_ops,
+ .lpc_printerr = B_TRUE
+ };
+ pools = zpool_search_import(&lpch, &idata);
if (pools != NULL && pool_exists &&
(argc == 1 || strcmp(argv[0], argv[1]) == 0)) {
*/
idata.scan = B_TRUE;
nvlist_free(pools);
- pools = zpool_search_import(g_zfs, &idata, &libzfs_config_ops);
+ pools = zpool_search_import(&lpch, &idata);
err = import_pools(pools, props, mntopts, flags,
argc >= 1 ? argv[0] : NULL,
(void) nvlist_lookup_uint64(newchild[c],
ZPOOL_CONFIG_IS_LOG, &islog);
if (islog) {
- bias = VDEV_ALLOC_CLASS_LOGS;
+ bias = (char *)VDEV_ALLOC_CLASS_LOGS;
} else {
(void) nvlist_lookup_string(newchild[c],
ZPOOL_CONFIG_ALLOCATION_BIAS, &bias);
static void
print_zpool_script_help(char *name, char *path)
{
- char *argv[] = {path, "-h", NULL};
+ char *argv[] = {path, (char *)"-h", NULL};
char **lines = NULL;
int lines_cnt = 0;
int rc;
* Print out help text for all zpool status/iostat -c scripts.
*/
static void
-print_zpool_script_list(char *subcommand)
+print_zpool_script_list(const char *subcommand)
{
char *dir, *sp, *tmp;
* get_namewidth() returns the maximum width of any name in that column
* for any pool/vdev/device line that will be output.
*/
- width = get_namewidth(zhp, cb->cb_namewidth, cb->cb_vdevs.cb_name_flags,
- cb->cb_verbose);
+ width = get_namewidth(zhp, cb->cb_namewidth,
+ cb->cb_vdevs.cb_name_flags | VDEV_NAME_TYPE_ID, cb->cb_verbose);
/*
* The width we are calculating is the width of the header and also the
first = B_FALSE;
right_justify = B_FALSE;
- if (pl->pl_prop != ZPROP_INVAL) {
+ if (pl->pl_prop != ZPROP_USERPROP) {
header = zpool_prop_column_name(pl->pl_prop);
right_justify = zpool_prop_align_right(pl->pl_prop);
} else {
zprop_list_t *pl = cb->cb_proplist;
boolean_t first = B_TRUE;
char property[ZPOOL_MAXPROPLEN];
- char *propstr;
+ const char *propstr;
boolean_t right_justify;
size_t width;
}
right_justify = B_FALSE;
- if (pl->pl_prop != ZPROP_INVAL) {
+ if (pl->pl_prop != ZPROP_USERPROP) {
if (zpool_get_prop(zhp, pl->pl_prop, property,
sizeof (property), NULL, cb->cb_literal) != 0)
propstr = "-";
* 'toplevel' boolean value is passed to the print_one_column()
* to indicate that the value is valid.
*/
- if (vs->vs_pspace)
+ if (VDEV_STAT_VALID(vs_pspace, c) && vs->vs_pspace)
print_one_column(ZPOOL_PROP_SIZE, vs->vs_pspace, NULL,
scripted, B_TRUE, format);
else
if (nvlist_lookup_uint64(child[c], ZPOOL_CONFIG_IS_LOG,
&islog) == 0 && islog) {
- bias = VDEV_ALLOC_CLASS_LOGS;
+ bias = (char *)VDEV_ALLOC_CLASS_LOGS;
} else {
(void) nvlist_lookup_string(child[c],
ZPOOL_CONFIG_ALLOCATION_BIAS, &bias);
list_cbdata_t *cb = data;
int width;
- width = get_namewidth(zhp, cb->cb_namewidth, cb->cb_name_flags,
- cb->cb_verbose);
+ width = get_namewidth(zhp, cb->cb_namewidth,
+ cb->cb_name_flags | VDEV_NAME_TYPE_ID, cb->cb_verbose);
if (width < 9)
width = 9;
{
status_cbdata_t *cbp = data;
nvlist_t *config, *nvroot;
- char *msgid;
+ const char *msgid;
zpool_status_t reason;
zpool_errata_t errata;
const char *health;
printf(" ");
printf_color(ANSI_BOLD, gettext("pool:"));
printf(" %s\n", zpool_get_name(zhp));
- printf(" ");
+ fputc(' ', stdout);
printf_color(ANSI_BOLD, gettext("state: "));
printf_color(health_str_to_color(health), "%s", health);
- printf("\n");
+ fputc('\n', stdout);
switch (reason) {
case ZPOOL_STATUS_MISSING_DEV_R:
pool_checkpoint_stat_t *pcs = NULL;
pool_scan_stat_t *pss = NULL;
pool_removal_stat_t *prs = NULL;
- char *headers[] = {"DISCARD", "FREE", "INITIALIZE", "REPLACE",
- "REMOVE", "RESILVER", "SCRUB", "TRIM"};
+ const char *const headers[] = {"DISCARD", "FREE", "INITIALIZE",
+ "REPLACE", "REMOVE", "RESILVER", "SCRUB", "TRIM"};
int col_widths[ZPOOL_WAIT_NUM_ACTIVITIES];
/* Calculate the width of each column */
if (wd->wd_enabled[i])
(void) printf("%*s", col_widths[i], headers[i]);
}
- (void) printf("\n");
+ (void) fputc('\n', stdout);
}
/* Bytes of work remaining in each activity */
}
static int
-find_command_idx(char *command, int *idx)
+find_command_idx(const char *command, int *idx)
{
- int i;
-
- for (i = 0; i < NCOMMAND; i++) {
+ for (int i = 0; i < NCOMMAND; ++i) {
if (command_table[i].name == NULL)
continue;
zpool_do_version(int argc, char **argv)
{
(void) argc, (void) argv;
-
- if (zfs_version_print() == -1)
- return (1);
-
- return (0);
+ return (zfs_version_print() != 0);
}
/*
* Many commands modify input strings for string parsing reasons.
* We create a copy to protect the original argv.
*/
- newargv = malloc((argc + 1) * sizeof (newargv[0]));
+ newargv = safe_malloc((argc + 1) * sizeof (newargv[0]));
for (i = 0; i < argc; i++)
newargv[i] = strdup(argv[i]);
newargv[argc] = NULL;