diff options
author | Alexander Motin <mav@FreeBSD.org> | 2019-02-04 01:24:10 +0000 |
---|---|---|
committer | Alexander Motin <mav@FreeBSD.org> | 2019-02-04 01:24:10 +0000 |
commit | fe74eaab7cab7d0a61b3f274df940b0bd0e6be67 (patch) | |
tree | 49b2f6f8f091fc65e7b6f4dd527a5af8529a0160 /usr.sbin/sesutil | |
parent | 6a69d2a40030779dfd5ff2d284a85735d9ca1dcf (diff) | |
download | src-fe74eaab7cab7d0a61b3f274df940b0bd0e6be67.tar.gz src-fe74eaab7cab7d0a61b3f274df940b0bd0e6be67.zip |
Check element type before setting LEDs.
With r319610, sesutil started twiddling the bits of every SES device.
Not everything is a disk slot, there are also fan controllers, temperature
sensors, even power supplies, among other things controlled by SES.
Add a type check to make sure we are only operating on device slot and array
device slot elements. Other type elements will be skipped, but it would be
simple to add additional cases for controlling the ident LEDs of other
element types (which are not necessarily the same bits).
Rather than doing raw bit manipulation of an unstructured byte array using
unnamed numeric constants, leverage existing code abstractions.
Submitted by: Ryan Moeller <ryan@freqlabs.com>
MFC after: 1 week
Sponsored by: iXsystems, Inc.
Differential Revision: https://reviews.freebsd.org/D19052
Notes
Notes:
svn path=/head/; revision=343728
Diffstat (limited to 'usr.sbin/sesutil')
-rw-r--r-- | usr.sbin/sesutil/sesutil.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/usr.sbin/sesutil/sesutil.c b/usr.sbin/sesutil/sesutil.c index b31c1980fc0c..21c48cc38c6f 100644 --- a/usr.sbin/sesutil/sesutil.c +++ b/usr.sbin/sesutil/sesutil.c @@ -112,28 +112,30 @@ usage(FILE *out, const char *subcmd) } static void -do_led(int fd, unsigned int idx, bool onoff, bool setfault) +do_led(int fd, unsigned int idx, elm_type_t type, bool onoff, bool setfault) { + int state = onoff ? 1 : 0; encioc_elm_status_t o; + struct ses_ctrl_dev_slot *slot; o.elm_idx = idx; if (ioctl(fd, ENCIOC_GETELMSTAT, (caddr_t) &o) < 0) { close(fd); xo_err(EXIT_FAILURE, "ENCIOC_GETELMSTAT"); } - o.cstat[0] |= 0x80; - if (setfault) { - if (onoff) - o.cstat[3] |= 0x20; - else - o.cstat[3] &= 0xdf; - } else { - if (onoff) - o.cstat[2] |= 0x02; + slot = (struct ses_ctrl_dev_slot *) &o.cstat[0]; + switch (type) { + case ELMTYP_DEVICE: + case ELMTYP_ARRAY_DEV: + ses_ctrl_common_set_select(&slot->common, 1); + if (setfault) + ses_ctrl_dev_slot_set_rqst_fault(slot, state); else - o.cstat[2] &= 0xfd; + ses_ctrl_dev_slot_set_rqst_ident(slot, state); + break; + default: + return; } - if (ioctl(fd, ENCIOC_SETELMSTAT, (caddr_t) &o) < 0) { close(fd); xo_err(EXIT_FAILURE, "ENCIOC_SETELMSTAT"); @@ -250,14 +252,15 @@ sesled(int argc, char **argv, bool setfault) xo_errx(EXIT_FAILURE, "Requested SES ID does not exist"); } - do_led(fd, sesid, onoff, setfault); + do_led(fd, sesid, objp[sesid].elm_type, onoff, setfault); ndisks++; close(fd); break; } for (j = 0; j < nobj; j++) { if (all) { - do_led(fd, objp[j].elm_idx, onoff, setfault); + do_led(fd, objp[j].elm_idx, objp[j].elm_type, + onoff, setfault); continue; } memset(&objdn, 0, sizeof(objdn)); @@ -274,7 +277,7 @@ sesled(int argc, char **argv, bool setfault) } if (objdn.elm_names_len > 0) { if (disk_match(objdn.elm_devnames, disk, len)) { - do_led(fd, objdn.elm_idx, + do_led(fd, objdn.elm_idx, objp[j].elm_type, onoff, setfault); ndisks++; break; |