Add global -d and -e options to either print device numbers

(usually default) or enclosure:slot information as (Exx:Sxx)
or both.

Discussed with:		jhb
Reviewed by:		jhb
Sponsored by:		Sandvine Incorporated
MFC after:		1 week
This commit is contained in:
Bjoern A. Zeeb 2011-06-20 21:28:50 +00:00
parent 7afed3bf78
commit 7bbae305a1
7 changed files with 161 additions and 39 deletions

View File

@ -419,8 +419,10 @@ build_array(int fd, char *arrayp, struct array_info *array_info,
ar->array_ref = find_next_array(state); ar->array_ref = find_next_array(state);
for (i = 0; i < array_info->drive_count; i++) { for (i = 0; i < array_info->drive_count; i++) {
if (verbose) if (verbose)
printf("Adding drive %u to array %u\n", printf("Adding drive %s to array %u\n",
mfi_drive_name(NULL,
array_info->drives[i].ref.v.device_id, array_info->drives[i].ref.v.device_id,
MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS),
ar->array_ref); ar->array_ref);
if (ar->size > array_info->drives[i].coerced_size) if (ar->size > array_info->drives[i].coerced_size)
ar->size = array_info->drives[i].coerced_size; ar->size = array_info->drives[i].coerced_size;

View File

@ -45,6 +45,87 @@
MFI_TABLE(top, drive); MFI_TABLE(top, drive);
/*
* Print the name of a drive either by drive number as %2u or by enclosure:slot
* as Exx:Sxx (or both). Use default unless command line options override it
* and the command allows this (which we usually do unless we already print
* both). We prefer pinfo if given, otherwise try to look it up by device_id.
*/
const char *
mfi_drive_name(struct mfi_pd_info *pinfo, uint16_t device_id, uint32_t def)
{
struct mfi_pd_info info;
static char buf[16];
char *p;
int error, fd, len;
if ((def & MFI_DNAME_HONOR_OPTS) != 0 &&
(mfi_opts & (MFI_DNAME_ES|MFI_DNAME_DEVICE_ID)) != 0)
def = mfi_opts & (MFI_DNAME_ES|MFI_DNAME_DEVICE_ID);
buf[0] = '\0';
if (pinfo == NULL && def & MFI_DNAME_ES) {
/* Fallback in case of error, just ignore flags. */
if (device_id == 0xffff)
snprintf(buf, sizeof(buf), "MISSING");
else
snprintf(buf, sizeof(buf), "%2u", device_id);
fd = mfi_open(mfi_unit);
if (fd < 0) {
warn("mfi_open");
return (buf);
}
/* Get the info for this drive. */
if (mfi_pd_get_info(fd, device_id, &info, NULL) < 0) {
warn("Failed to fetch info for drive %2u", device_id);
close(fd);
return (buf);
}
close(fd);
pinfo = &info;
}
p = buf;
len = sizeof(buf);
if (def & MFI_DNAME_DEVICE_ID) {
if (device_id == 0xffff)
error = snprintf(p, len, "MISSING");
else
error = snprintf(p, len, "%2u", device_id);
if (error >= 0) {
p += error;
len -= error;
}
}
if ((def & (MFI_DNAME_ES|MFI_DNAME_DEVICE_ID)) ==
(MFI_DNAME_ES|MFI_DNAME_DEVICE_ID) && len >= 2) {
*p++ = ' ';
len--;
*p = '\0';
len--;
}
if (def & MFI_DNAME_ES) {
if (pinfo->encl_device_id == 0xffff)
error = snprintf(p, len, "S%u",
pinfo->slot_number);
else if (pinfo->encl_device_id == pinfo->ref.v.device_id)
error = snprintf(p, len, "E%u",
pinfo->encl_index);
else
error = snprintf(p, len, "E%u:S%u",
pinfo->encl_index, pinfo->slot_number);
if (error >= 0) {
p += error;
len -= error;
}
}
return (buf);
}
const char * const char *
mfi_pdstate(enum mfi_pd_state state) mfi_pdstate(enum mfi_pd_state state)
{ {
@ -547,7 +628,9 @@ drive_progress(int ac, char **av)
mfi_display_progress("Clear", &info.prog_info.clear); mfi_display_progress("Clear", &info.prog_info.clear);
if ((info.prog_info.active & (MFI_PD_PROGRESS_REBUILD | if ((info.prog_info.active & (MFI_PD_PROGRESS_REBUILD |
MFI_PD_PROGRESS_PATROL | MFI_PD_PROGRESS_CLEAR)) == 0) MFI_PD_PROGRESS_PATROL | MFI_PD_PROGRESS_CLEAR)) == 0)
printf("No activity in progress for drive %u.\n", device_id); printf("No activity in progress for drive %s.\n",
mfi_drive_name(NULL, device_id,
MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
return (0); return (0);
} }

View File

@ -80,7 +80,7 @@ show_patrol(int ac, char **av)
struct mfi_pr_status status; struct mfi_pr_status status;
struct mfi_pd_list *list; struct mfi_pd_list *list;
struct mfi_pd_info info; struct mfi_pd_info info;
char label[16]; char label[24];
time_t now; time_t now;
uint32_t at; uint32_t at;
int error, fd; int error, fd;
@ -174,8 +174,10 @@ show_patrol(int ac, char **av)
return (error); return (error);
} }
if (info.prog_info.active & MFI_PD_PROGRESS_PATROL) { if (info.prog_info.active & MFI_PD_PROGRESS_PATROL) {
snprintf(label, sizeof(label), " Drive %u", snprintf(label, sizeof(label), " Drive %s",
list->addr[i].device_id); mfi_drive_name(NULL,
list->addr[i].device_id,
MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
mfi_display_progress(label, mfi_display_progress(label,
&info.prog_info.patrol); &info.prog_info.patrol);
} }

View File

@ -258,7 +258,7 @@ print_ld(struct mfi_ld_info *info, int state_len)
} }
static void static void
print_pd(struct mfi_pd_info *info, int state_len, int location) print_pd(struct mfi_pd_info *info, int state_len)
{ {
const char *s; const char *s;
char buf[6]; char buf[6];
@ -273,15 +273,6 @@ print_pd(struct mfi_pd_info *info, int state_len, int location)
s = mfi_pd_inq_string(info); s = mfi_pd_inq_string(info);
if (s != NULL) if (s != NULL)
printf(" %s", s); printf(" %s", s);
if (!location)
return;
if (info->encl_device_id == 0xffff)
printf(" slot %d", info->slot_number);
else if (info->encl_device_id == info->ref.v.device_id)
printf(" enclosure %d", info->encl_index);
else
printf(" enclosure %d, slot %d", info->encl_index,
info->slot_number);
} }
static int static int
@ -329,16 +320,16 @@ show_config(int ac, char **av)
ar->num_drives); ar->num_drives);
for (j = 0; j < ar->num_drives; j++) { for (j = 0; j < ar->num_drives; j++) {
device_id = ar->pd[j].ref.v.device_id; device_id = ar->pd[j].ref.v.device_id;
if (device_id == 0xffff) printf(" drive %s ", mfi_drive_name(NULL,
printf(" drive MISSING\n"); device_id,
else { MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
printf(" drive %u ", device_id); if (device_id != 0xffff) {
if (mfi_pd_get_info(fd, device_id, &pinfo, if (mfi_pd_get_info(fd, device_id, &pinfo,
NULL) < 0) NULL) < 0)
printf("%s", printf("%s",
mfi_pdstate(ar->pd[j].fw_state)); mfi_pdstate(ar->pd[j].fw_state));
else else
print_pd(&pinfo, -1, 1); print_pd(&pinfo, -1);
printf("\n"); printf("\n");
} }
} }
@ -367,13 +358,14 @@ show_config(int ac, char **av)
for (i = 0; i < config->spares_count; i++) { for (i = 0; i < config->spares_count; i++) {
sp = (struct mfi_spare *)p; sp = (struct mfi_spare *)p;
printf(" %s spare %u ", printf(" %s spare %s ",
sp->spare_type & MFI_SPARE_DEDICATED ? "dedicated" : sp->spare_type & MFI_SPARE_DEDICATED ? "dedicated" :
"global", sp->ref.v.device_id); "global", mfi_drive_name(NULL, sp->ref.v.device_id,
MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
if (mfi_pd_get_info(fd, sp->ref.v.device_id, &pinfo, NULL) < 0) if (mfi_pd_get_info(fd, sp->ref.v.device_id, &pinfo, NULL) < 0)
printf("%s", mfi_pdstate(MFI_PD_STATE_HOT_SPARE)); printf("%s", mfi_pdstate(MFI_PD_STATE_HOT_SPARE));
else else
print_pd(&pinfo, -1, 1); print_pd(&pinfo, -1);
if (sp->spare_type & MFI_SPARE_DEDICATED) { if (sp->spare_type & MFI_SPARE_DEDICATED) {
printf(" backs:\n"); printf(" backs:\n");
for (j = 0; j < sp->array_count; j++) for (j = 0; j < sp->array_count; j++)
@ -534,7 +526,11 @@ show_drives(int ac, char **av)
goto error; goto error;
} }
print_pd(&info, state_len, 1); printf("%s ", mfi_drive_name(&info, list->addr[i].device_id,
MFI_DNAME_DEVICE_ID));
print_pd(&info, state_len);
printf(" %s", mfi_drive_name(&info, list->addr[i].device_id,
MFI_DNAME_ES));
printf("\n"); printf("\n");
} }
error: error:
@ -719,18 +715,21 @@ show_progress(int ac, char **av)
} }
if (pinfo.prog_info.active & MFI_PD_PROGRESS_REBUILD) { if (pinfo.prog_info.active & MFI_PD_PROGRESS_REBUILD) {
printf("drive %u ", device_id); printf("drive %s ", mfi_drive_name(NULL, device_id,
MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
mfi_display_progress("Rebuild", &pinfo.prog_info.rbld); mfi_display_progress("Rebuild", &pinfo.prog_info.rbld);
busy = 1; busy = 1;
} }
if (pinfo.prog_info.active & MFI_PD_PROGRESS_PATROL) { if (pinfo.prog_info.active & MFI_PD_PROGRESS_PATROL) {
printf("drive %u ", device_id); printf("drive %s ", mfi_drive_name(NULL, device_id,
MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
mfi_display_progress("Patrol Read", mfi_display_progress("Patrol Read",
&pinfo.prog_info.patrol); &pinfo.prog_info.patrol);
busy = 1; busy = 1;
} }
if (pinfo.prog_info.active & MFI_PD_PROGRESS_CLEAR) { if (pinfo.prog_info.active & MFI_PD_PROGRESS_CLEAR) {
printf("drive %u ", device_id); printf("drive %s ", mfi_drive_name(NULL, device_id,
MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS));
mfi_display_progress("Clear", &pinfo.prog_info.clear); mfi_display_progress("Clear", &pinfo.prog_info.clear);
busy = 1; busy = 1;
} }

View File

@ -27,7 +27,7 @@
.\" .\"
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd April 29, 2011 .Dd June 20, 2011
.Dt MFIUTIL 8 .Dt MFIUTIL 8
.Os .Os
.Sh NAME .Sh NAME
@ -43,6 +43,8 @@
.Op Fl u Ar unit .Op Fl u Ar unit
.Cm show battery .Cm show battery
.Nm .Nm
.Op Fl d
.Op Fl e
.Op Fl u Ar unit .Op Fl u Ar unit
.Cm show config .Cm show config
.Nm .Nm
@ -63,9 +65,13 @@
.Op Fl u Ar unit .Op Fl u Ar unit
.Cm show logstate .Cm show logstate
.Nm .Nm
.Op Fl d
.Op Fl e
.Op Fl u Ar unit .Op Fl u Ar unit
.Cm show patrol .Cm show patrol
.Nm .Nm
.Op Fl d
.Op Fl e
.Op Fl u Ar unit .Op Fl u Ar unit
.Cm show progress .Cm show progress
.Nm .Nm
@ -155,15 +161,19 @@ If no unit is specified,
then unit 0 is used. then unit 0 is used.
.El .El
.Pp .Pp
Volumes may be specified in two forms. Various commands accept either or both of the two options:
First, .Bl -tag -width indent
a volume may be identified by its target ID. .It Fl d
Second, Print numeric device IDs as drive identifier.
on the volume may be specified by the corresponding This is the default.
.Em mfidX Useful in combination with
device, .Fl e
such as to print both, numeric device IDs and enclosure:slot information.
.Em mfid0 . .It Fl e
Print drive identifiers in enclosure:slot form.
See next paragraph on format details in context of input rather than
output.
.El
.Pp .Pp
Drives may be specified in two forms. Drives may be specified in two forms.
First, First,
@ -184,6 +194,16 @@ and
is the slot for each drive as displayed in is the slot for each drive as displayed in
.Cm show drives . .Cm show drives .
.Pp .Pp
Volumes may be specified in two forms.
First,
a volume may be identified by its target ID.
Second,
on the volume may be specified by the corresponding
.Em mfidX
device,
such as
.Em mfid0 .
.Pp
The The
.Nm .Nm
utility supports several different groups of commands. utility supports several different groups of commands.

View File

@ -45,11 +45,13 @@ MFI_TABLE(top, abort);
int mfi_unit; int mfi_unit;
u_int mfi_opts;
static void static void
usage(void) usage(void)
{ {
fprintf(stderr, "usage: mfiutil [-u unit] <command> ...\n\n"); fprintf(stderr, "usage: mfiutil [-de] [-u unit] <command> ...\n\n");
fprintf(stderr, "Commands include:\n"); fprintf(stderr, "Commands include:\n");
fprintf(stderr, " version\n"); fprintf(stderr, " version\n");
fprintf(stderr, " show adapter - display controller information\n"); fprintf(stderr, " show adapter - display controller information\n");
@ -108,8 +110,14 @@ main(int ac, char **av)
struct mfiutil_command **cmd; struct mfiutil_command **cmd;
int ch; int ch;
while ((ch = getopt(ac, av, "u:")) != -1) { while ((ch = getopt(ac, av, "deu:")) != -1) {
switch (ch) { switch (ch) {
case 'd':
mfi_opts |= MFI_DNAME_DEVICE_ID;
break;
case 'e':
mfi_opts |= MFI_DNAME_ES;
break;
case 'u': case 'u':
mfi_unit = atoi(optarg); mfi_unit = atoi(optarg);
break; break;

View File

@ -115,7 +115,13 @@ struct mfiutil_command {
} \ } \
MFI_COMMAND(set, name, mfiutil_ ## name ## _table_handler) MFI_COMMAND(set, name, mfiutil_ ## name ## _table_handler)
/* Drive name printing options */
#define MFI_DNAME_ES 0x0001 /* E%u:S%u */
#define MFI_DNAME_DEVICE_ID 0x0002 /* %u */
#define MFI_DNAME_HONOR_OPTS 0x8000 /* Allow cmd line to override default */
extern int mfi_unit; extern int mfi_unit;
extern u_int mfi_opts;
void mbox_store_ldref(uint8_t *mbox, union mfi_ld_ref *ref); void mbox_store_ldref(uint8_t *mbox, union mfi_ld_ref *ref);
void mbox_store_pdref(uint8_t *mbox, union mfi_pd_ref *ref); void mbox_store_pdref(uint8_t *mbox, union mfi_pd_ref *ref);
@ -143,5 +149,7 @@ int mfi_pd_get_info(int fd, uint16_t device_id, struct mfi_pd_info *info,
int mfi_pd_get_list(int fd, struct mfi_pd_list **listp, uint8_t *statusp); int mfi_pd_get_list(int fd, struct mfi_pd_list **listp, uint8_t *statusp);
int mfi_reconfig_supported(void); int mfi_reconfig_supported(void);
const char *mfi_status(u_int status_code); const char *mfi_status(u_int status_code);
const char *mfi_drive_name(struct mfi_pd_info *pinfo, uint16_t device_id,
uint32_t def);
#endif /* !__MFIUTIL_H__ */ #endif /* !__MFIUTIL_H__ */