From owner-svn-src-all@freebsd.org Mon Feb 11 14:48:46 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1DE5114D90B4; Mon, 11 Feb 2019 14:48:45 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9854770622; Mon, 11 Feb 2019 14:48:45 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8C09814A3; Mon, 11 Feb 2019 14:48:45 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x1BEmjq2015260; Mon, 11 Feb 2019 14:48:45 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x1BEmjeb015259; Mon, 11 Feb 2019 14:48:45 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201902111448.x1BEmjeb015259@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Mon, 11 Feb 2019 14:48:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r344006 - stable/12/usr.sbin/sesutil X-SVN-Group: stable-12 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/12/usr.sbin/sesutil X-SVN-Commit-Revision: 344006 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 9854770622 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.996,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.95)[-0.953,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Feb 2019 14:48:46 -0000 Author: mav Date: Mon Feb 11 14:48:45 2019 New Revision: 344006 URL: https://svnweb.freebsd.org/changeset/base/344006 Log: MFC r343728: 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 Sponsored by: iXsystems, Inc. Modified: stable/12/usr.sbin/sesutil/sesutil.c Directory Properties: stable/12/ (props changed) Modified: stable/12/usr.sbin/sesutil/sesutil.c ============================================================================== --- stable/12/usr.sbin/sesutil/sesutil.c Mon Feb 11 14:47:26 2019 (r344005) +++ stable/12/usr.sbin/sesutil/sesutil.c Mon Feb 11 14:48:45 2019 (r344006) @@ -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; + 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[3] &= 0xdf; - } else { - if (onoff) - o.cstat[2] |= 0x02; - 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;