diff options
author | bz <bz@FreeBSD.org> | 2011-06-20 21:28:50 +0000 |
---|---|---|
committer | bz <bz@FreeBSD.org> | 2011-06-20 21:28:50 +0000 |
commit | 418b801093824d8d298b6dac4f1dac43eb52a0ec (patch) | |
tree | 9b146b4b19dcdc9fe6f849ee5a19cf61b1569869 /usr.sbin | |
parent | f715e0405adbd428c4c1f522fbff184fd36a83eb (diff) | |
download | FreeBSD-src-418b801093824d8d298b6dac4f1dac43eb52a0ec.zip FreeBSD-src-418b801093824d8d298b6dac4f1dac43eb52a0ec.tar.gz |
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
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/mfiutil/mfi_config.c | 4 | ||||
-rw-r--r-- | usr.sbin/mfiutil/mfi_drive.c | 85 | ||||
-rw-r--r-- | usr.sbin/mfiutil/mfi_patrol.c | 8 | ||||
-rw-r--r-- | usr.sbin/mfiutil/mfi_show.c | 43 | ||||
-rw-r--r-- | usr.sbin/mfiutil/mfiutil.8 | 40 | ||||
-rw-r--r-- | usr.sbin/mfiutil/mfiutil.c | 12 | ||||
-rw-r--r-- | usr.sbin/mfiutil/mfiutil.h | 8 |
7 files changed, 161 insertions, 39 deletions
diff --git a/usr.sbin/mfiutil/mfi_config.c b/usr.sbin/mfiutil/mfi_config.c index f1e6516..f6f1a9d 100644 --- a/usr.sbin/mfiutil/mfi_config.c +++ b/usr.sbin/mfiutil/mfi_config.c @@ -419,8 +419,10 @@ build_array(int fd, char *arrayp, struct array_info *array_info, ar->array_ref = find_next_array(state); for (i = 0; i < array_info->drive_count; i++) { 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, + MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS), ar->array_ref); if (ar->size > array_info->drives[i].coerced_size) ar->size = array_info->drives[i].coerced_size; diff --git a/usr.sbin/mfiutil/mfi_drive.c b/usr.sbin/mfiutil/mfi_drive.c index 5c2ab5d..6341fd8 100644 --- a/usr.sbin/mfiutil/mfi_drive.c +++ b/usr.sbin/mfiutil/mfi_drive.c @@ -45,6 +45,87 @@ 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 * 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); if ((info.prog_info.active & (MFI_PD_PROGRESS_REBUILD | 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); } diff --git a/usr.sbin/mfiutil/mfi_patrol.c b/usr.sbin/mfiutil/mfi_patrol.c index d70c4ab..dd348ad 100644 --- a/usr.sbin/mfiutil/mfi_patrol.c +++ b/usr.sbin/mfiutil/mfi_patrol.c @@ -80,7 +80,7 @@ show_patrol(int ac, char **av) struct mfi_pr_status status; struct mfi_pd_list *list; struct mfi_pd_info info; - char label[16]; + char label[24]; time_t now; uint32_t at; int error, fd; @@ -174,8 +174,10 @@ show_patrol(int ac, char **av) return (error); } if (info.prog_info.active & MFI_PD_PROGRESS_PATROL) { - snprintf(label, sizeof(label), " Drive %u", - list->addr[i].device_id); + snprintf(label, sizeof(label), " Drive %s", + mfi_drive_name(NULL, + list->addr[i].device_id, + MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS)); mfi_display_progress(label, &info.prog_info.patrol); } diff --git a/usr.sbin/mfiutil/mfi_show.c b/usr.sbin/mfiutil/mfi_show.c index 76fd6b9..d1f0071 100644 --- a/usr.sbin/mfiutil/mfi_show.c +++ b/usr.sbin/mfiutil/mfi_show.c @@ -258,7 +258,7 @@ print_ld(struct mfi_ld_info *info, int state_len) } 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; 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); if (s != NULL) 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 @@ -329,16 +320,16 @@ show_config(int ac, char **av) ar->num_drives); for (j = 0; j < ar->num_drives; j++) { device_id = ar->pd[j].ref.v.device_id; - if (device_id == 0xffff) - printf(" drive MISSING\n"); - else { - printf(" drive %u ", device_id); + printf(" drive %s ", mfi_drive_name(NULL, + device_id, + MFI_DNAME_DEVICE_ID|MFI_DNAME_HONOR_OPTS)); + if (device_id != 0xffff) { if (mfi_pd_get_info(fd, device_id, &pinfo, NULL) < 0) printf("%s", mfi_pdstate(ar->pd[j].fw_state)); else - print_pd(&pinfo, -1, 1); + print_pd(&pinfo, -1); printf("\n"); } } @@ -367,13 +358,14 @@ show_config(int ac, char **av) for (i = 0; i < config->spares_count; i++) { sp = (struct mfi_spare *)p; - printf(" %s spare %u ", + printf(" %s spare %s ", 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) printf("%s", mfi_pdstate(MFI_PD_STATE_HOT_SPARE)); else - print_pd(&pinfo, -1, 1); + print_pd(&pinfo, -1); if (sp->spare_type & MFI_SPARE_DEDICATED) { printf(" backs:\n"); for (j = 0; j < sp->array_count; j++) @@ -534,7 +526,11 @@ show_drives(int ac, char **av) 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"); } error: @@ -719,18 +715,21 @@ show_progress(int ac, char **av) } 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); busy = 1; } 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", &pinfo.prog_info.patrol); busy = 1; } 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); busy = 1; } diff --git a/usr.sbin/mfiutil/mfiutil.8 b/usr.sbin/mfiutil/mfiutil.8 index d5178a0..dcd17f5 100644 --- a/usr.sbin/mfiutil/mfiutil.8 +++ b/usr.sbin/mfiutil/mfiutil.8 @@ -27,7 +27,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 29, 2011 +.Dd June 20, 2011 .Dt MFIUTIL 8 .Os .Sh NAME @@ -43,6 +43,8 @@ .Op Fl u Ar unit .Cm show battery .Nm +.Op Fl d +.Op Fl e .Op Fl u Ar unit .Cm show config .Nm @@ -63,9 +65,13 @@ .Op Fl u Ar unit .Cm show logstate .Nm +.Op Fl d +.Op Fl e .Op Fl u Ar unit .Cm show patrol .Nm +.Op Fl d +.Op Fl e .Op Fl u Ar unit .Cm show progress .Nm @@ -155,15 +161,19 @@ If no unit is specified, then unit 0 is used. .El .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 . +Various commands accept either or both of the two options: +.Bl -tag -width indent +.It Fl d +Print numeric device IDs as drive identifier. +This is the default. +Useful in combination with +.Fl e +to print both, numeric device IDs and enclosure:slot information. +.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 Drives may be specified in two forms. First, @@ -184,6 +194,16 @@ and is the slot for each drive as displayed in .Cm show drives . .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 .Nm utility supports several different groups of commands. diff --git a/usr.sbin/mfiutil/mfiutil.c b/usr.sbin/mfiutil/mfiutil.c index 4cf8747..43bb6bb 100644 --- a/usr.sbin/mfiutil/mfiutil.c +++ b/usr.sbin/mfiutil/mfiutil.c @@ -45,11 +45,13 @@ MFI_TABLE(top, abort); int mfi_unit; +u_int mfi_opts; + static 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, " version\n"); fprintf(stderr, " show adapter - display controller information\n"); @@ -108,8 +110,14 @@ main(int ac, char **av) struct mfiutil_command **cmd; int ch; - while ((ch = getopt(ac, av, "u:")) != -1) { + while ((ch = getopt(ac, av, "deu:")) != -1) { switch (ch) { + case 'd': + mfi_opts |= MFI_DNAME_DEVICE_ID; + break; + case 'e': + mfi_opts |= MFI_DNAME_ES; + break; case 'u': mfi_unit = atoi(optarg); break; diff --git a/usr.sbin/mfiutil/mfiutil.h b/usr.sbin/mfiutil/mfiutil.h index b080b50..232831e 100644 --- a/usr.sbin/mfiutil/mfiutil.h +++ b/usr.sbin/mfiutil/mfiutil.h @@ -115,7 +115,13 @@ struct mfiutil_command { } \ 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 u_int mfi_opts; void mbox_store_ldref(uint8_t *mbox, union mfi_ld_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_reconfig_supported(void); 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__ */ |