summaryrefslogtreecommitdiff
path: root/usr/src/cmd
diff options
context:
space:
mode:
authorJoshua M. Clulow <josh@sysmgr.org>2022-09-20 17:38:58 -0700
committerJoshua M. Clulow <josh@sysmgr.org>2022-09-20 17:39:36 -0700
commite98897e3ff64095f1d7afa3f16c8c3dcbd805e3e (patch)
treec51d97fc03b5292967c32b379c43e341fbfd1aa9 /usr/src/cmd
parentbf2b3a2a0b16c017abff41fdb4f8c82e2aef82fd (diff)
downloadillumos-gate-e98897e3ff64095f1d7afa3f16c8c3dcbd805e3e.tar.gz
14972 some diskinfo error messages run into the next line
Reviewed by: Andy Fiddaman <illumos@fiddaman.net> Reviewed by: Robert Mustacchi <rm@fingolfin.org> Reviewed by: Yuri Pankov <ypankov@tintri.com> Approved by: Dan McDonald <danmcd@mnx.io>
Diffstat (limited to 'usr/src/cmd')
-rw-r--r--usr/src/cmd/diskinfo/diskinfo.c98
1 files changed, 43 insertions, 55 deletions
diff --git a/usr/src/cmd/diskinfo/diskinfo.c b/usr/src/cmd/diskinfo/diskinfo.c
index f7b352c0e6..2246d9f8b7 100644
--- a/usr/src/cmd/diskinfo/diskinfo.c
+++ b/usr/src/cmd/diskinfo/diskinfo.c
@@ -12,6 +12,7 @@
/*
* Copyright (c) 2018 Joyent Inc., All rights reserved.
* Copyright 2021 RackTop Systems, Inc.
+ * Copyright 2022 Oxide Computer Company
*/
#include <sys/types.h>
@@ -26,6 +27,7 @@
#include <ctype.h>
#include <stdarg.h>
#include <strings.h>
+#include <err.h>
#include <libdiskmgt.h>
#include <sys/nvpair.h>
@@ -55,18 +57,6 @@ typedef struct di_phys {
int dp_locate;
} di_phys_t;
-static void __NORETURN
-fatal(int rv, const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- (void) vfprintf(stderr, fmt, ap);
- va_end(ap);
-
- exit(rv);
-}
-
static void
usage(const char *execname)
{
@@ -115,7 +105,7 @@ disk_walker(topo_hdl_t *hp, tnode_t *np, void *arg)
tnode_t *ppnp;
topo_faclist_t fl;
topo_faclist_t *lp;
- int err;
+ int e;
topo_led_state_t mode;
topo_led_type_t type;
char *name, *slotname, *serial;
@@ -124,7 +114,7 @@ disk_walker(topo_hdl_t *hp, tnode_t *np, void *arg)
return (TOPO_WALK_NEXT);
if (topo_prop_get_string(np, TOPO_PGROUP_STORAGE,
- TOPO_STORAGE_LOGICAL_DISK_NAME, &name, &err) != 0) {
+ TOPO_STORAGE_LOGICAL_DISK_NAME, &name, &e) != 0) {
return (TOPO_WALK_NEXT);
}
@@ -132,7 +122,7 @@ disk_walker(topo_hdl_t *hp, tnode_t *np, void *arg)
return (TOPO_WALK_NEXT);
if (topo_prop_get_string(np, TOPO_PGROUP_STORAGE,
- TOPO_STORAGE_SERIAL_NUM, &serial, &err) == 0) {
+ TOPO_STORAGE_SERIAL_NUM, &serial, &e) == 0) {
pp->dp_serial = serial;
}
@@ -141,21 +131,21 @@ disk_walker(topo_hdl_t *hp, tnode_t *np, void *arg)
pp->dp_chassis = topo_node_instance(ppnp);
if (strcmp(topo_node_name(pnp), BAY) == 0) {
if (topo_node_facility(hp, pnp, TOPO_FAC_TYPE_INDICATOR,
- TOPO_FAC_TYPE_ANY, &fl, &err) == 0) {
+ TOPO_FAC_TYPE_ANY, &fl, &e) == 0) {
for (lp = topo_list_next(&fl.tf_list); lp != NULL;
lp = topo_list_next(lp)) {
uint32_t prop;
if (topo_prop_get_uint32(lp->tf_node,
TOPO_PGROUP_FACILITY, TOPO_FACILITY_TYPE,
- &prop, &err) != 0) {
+ &prop, &e) != 0) {
continue;
}
type = (topo_led_type_t)prop;
if (topo_prop_get_uint32(lp->tf_node,
TOPO_PGROUP_FACILITY, TOPO_LED_MODE,
- &prop, &err) != 0) {
+ &prop, &e) != 0) {
continue;
}
mode = (topo_led_state_t)prop;
@@ -174,14 +164,14 @@ disk_walker(topo_hdl_t *hp, tnode_t *np, void *arg)
}
if (topo_prop_get_string(pnp, TOPO_PGROUP_PROTOCOL,
- TOPO_PROP_LABEL, &slotname, &err) == 0) {
+ TOPO_PROP_LABEL, &slotname, &e) == 0) {
pp->dp_slotname = slotname;
}
pp->dp_slot = topo_node_instance(pnp);
} else if (strcmp(topo_node_name(pnp), USB_DEVICE) == 0) {
if (topo_prop_get_string(pnp, TOPO_PGROUP_PROTOCOL,
- TOPO_PROP_LABEL, &slotname, &err) == 0) {
+ TOPO_PROP_LABEL, &slotname, &e) == 0) {
pp->dp_slotname = slotname;
}
@@ -199,24 +189,24 @@ disk_walker(topo_hdl_t *hp, tnode_t *np, void *arg)
static void
populate_physical(topo_hdl_t *hp, di_phys_t *pp)
{
- int err;
+ int e;
topo_walk_t *wp;
pp->dp_faulty = pp->dp_locate = -1;
pp->dp_chassis = pp->dp_slot = -1;
- err = 0;
- wp = topo_walk_init(hp, FM_FMRI_SCHEME_HC, disk_walker, pp, &err);
+ e = 0;
+ wp = topo_walk_init(hp, FM_FMRI_SCHEME_HC, disk_walker, pp, &e);
if (wp == NULL) {
- fatal(-1, "unable to initialise topo walker: %s",
- topo_strerror(err));
+ errx(-1, "unable to initialise topo walker: %s",
+ topo_strerror(e));
}
- while ((err = topo_walk_step(wp, TOPO_WALK_CHILD)) == TOPO_WALK_NEXT)
+ while ((e = topo_walk_step(wp, TOPO_WALK_CHILD)) == TOPO_WALK_NEXT)
;
- if (err == TOPO_WALK_ERR)
- fatal(-1, "topo walk failed");
+ if (e == TOPO_WALK_ERR)
+ errx(-1, "topo walk failed");
topo_walk_fini(wp);
}
@@ -226,7 +216,7 @@ enumerate_disks(di_opts_t *opts)
{
topo_hdl_t *hp;
dm_descriptor_t *media;
- int err, i;
+ int e, i;
int filter[] = { DM_DT_FIXED, -1 };
dm_descriptor_t *disk, *controller;
nvlist_t *mattrs, *dattrs, *cattrs = NULL;
@@ -245,29 +235,27 @@ enumerate_disks(di_opts_t *opts)
di_phys_t phys;
size_t len;
- err = 0;
- if ((media = dm_get_descriptors(DM_MEDIA, filter, &err)) == NULL) {
- fatal(-1, "failed to obtain media descriptors: %s\n",
- strerror(err));
+ e = 0;
+ if ((media = dm_get_descriptors(DM_MEDIA, filter, &e)) == NULL) {
+ errno = e;
+ err(-1, "failed to obtain media descriptors");
}
- err = 0;
- hp = topo_open(TOPO_VERSION, NULL, &err);
+ e = 0;
+ hp = topo_open(TOPO_VERSION, NULL, &e);
if (hp == NULL) {
- fatal(-1, "unable to obtain topo handle: %s",
- topo_strerror(err));
+ errx(-1, "unable to obtain topo handle: %s", topo_strerror(e));
}
- err = 0;
- (void) topo_snap_hold(hp, NULL, &err);
- if (err != 0) {
- fatal(-1, "unable to hold topo snapshot: %s",
- topo_strerror(err));
+ e = 0;
+ (void) topo_snap_hold(hp, NULL, &e);
+ if (e != 0) {
+ errx(-1, "unable to hold topo snapshot: %s", topo_strerror(e));
}
for (i = 0; media != NULL && media[i] != 0; i++) {
if ((disk = dm_get_associated_descriptors(media[i],
- DM_DRIVE, &err)) == NULL) {
+ DM_DRIVE, &e)) == NULL) {
continue;
}
@@ -276,17 +264,17 @@ enumerate_disks(di_opts_t *opts)
* info with DKIOCGMEDIAINFO which may not be the case for
* disks which are failing.
*/
- if ((mattrs = dm_get_attributes(media[i], &err)) == NULL) {
+ if ((mattrs = dm_get_attributes(media[i], &e)) == NULL) {
continue;
}
- err = nvlist_lookup_uint64(mattrs, DM_SIZE, &size);
- assert(err == 0);
- err = nvlist_lookup_uint32(mattrs, DM_BLOCKSIZE, &blocksize);
- assert(err == 0);
+ e = nvlist_lookup_uint64(mattrs, DM_SIZE, &size);
+ assert(e == 0);
+ e = nvlist_lookup_uint32(mattrs, DM_BLOCKSIZE, &blocksize);
+ assert(e == 0);
nvlist_free(mattrs);
- dattrs = dm_get_attributes(disk[0], &err);
+ dattrs = dm_get_attributes(disk[0], &e);
nvlist_query_string(dattrs, DM_VENDOR_ID, &vid);
nvlist_query_string(dattrs, DM_PRODUCT_ID, &pid);
@@ -301,8 +289,8 @@ enumerate_disks(di_opts_t *opts)
ssd = B_TRUE;
if ((controller = dm_get_associated_descriptors(disk[0],
- DM_CONTROLLER, &err)) != NULL) {
- cattrs = dm_get_attributes(controller[0], &err);
+ DM_CONTROLLER, &e)) != NULL) {
+ cattrs = dm_get_attributes(controller[0], &e);
nvlist_query_string(cattrs, DM_CTYPE, &ctype);
ctype = strdup(ctype);
for (c = ctype; *c != '\0'; c++)
@@ -438,7 +426,7 @@ main(int argc, char *argv[])
case 'c':
if (opts.di_physical) {
usage(argv[0]);
- fatal(1, "-c and -P are mutually exclusive\n");
+ errx(1, "-c and -P are mutually exclusive");
}
opts.di_condensed = B_TRUE;
break;
@@ -448,7 +436,7 @@ main(int argc, char *argv[])
case 'P':
if (opts.di_condensed) {
usage(argv[0]);
- fatal(1, "-c and -P are mutually exclusive\n");
+ errx(1, "-c and -P are mutually exclusive");
}
opts.di_physical = B_TRUE;
break;
@@ -457,9 +445,9 @@ main(int argc, char *argv[])
break;
case '?':
usage(argv[0]);
- fatal(1, "unknown option -%c\n", optopt);
+ errx(1, "unknown option -%c", optopt);
default:
- fatal(-1, "unexpected error on option -%c\n", optopt);
+ errx(-1, "unexpected error on option -%c", optopt);
}
}