2015-09-05 00:06:01 +00:00
|
|
|
/*-
|
2019-12-14 10:58:06 +00:00
|
|
|
* Copyright (c) 2019 Klara Inc.
|
2015-09-05 00:06:01 +00:00
|
|
|
* Copyright (c) 2015 Baptiste Daroussin <bapt@FreeBSD.org>
|
2015-09-19 16:36:45 +00:00
|
|
|
* Copyright (c) 2015 Allan Jude <allanjude@FreeBSD.org>
|
|
|
|
* Copyright (c) 2000 by Matthew Jacob
|
2015-09-05 00:06:01 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2019-12-14 10:58:06 +00:00
|
|
|
* Portions of this software were developed by Edward Tomasz Napierala
|
|
|
|
* under sponsorship from Klara Inc.
|
|
|
|
*
|
2015-09-05 00:06:01 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer
|
|
|
|
* in this position and unchanged.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2017-06-23 15:09:08 +00:00
|
|
|
#include <sys/endian.h>
|
2015-09-05 00:06:01 +00:00
|
|
|
#include <sys/param.h>
|
2019-12-14 10:58:06 +00:00
|
|
|
#include <sys/disk.h>
|
2015-09-05 00:06:01 +00:00
|
|
|
#include <sys/ioctl.h>
|
2015-12-11 20:45:39 +00:00
|
|
|
#include <sys/types.h>
|
2015-09-05 00:06:01 +00:00
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2015-09-19 16:36:45 +00:00
|
|
|
#include <getopt.h>
|
2015-09-05 00:06:01 +00:00
|
|
|
#include <glob.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2017-06-29 18:52:36 +00:00
|
|
|
#include <libxo/xo.h>
|
2015-09-05 00:06:01 +00:00
|
|
|
|
|
|
|
#include <cam/scsi/scsi_enc.h>
|
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
#include "eltsub.h"
|
|
|
|
|
2017-06-29 18:52:36 +00:00
|
|
|
#define SESUTIL_XO_VERSION "1"
|
|
|
|
|
2019-12-14 10:58:06 +00:00
|
|
|
#define TEMPERATURE_OFFSET 20
|
|
|
|
|
|
|
|
#define PRINT_STYLE_DASHED 0
|
|
|
|
#define PRINT_STYLE_DASHED_2 1
|
|
|
|
#define PRINT_STYLE_CSV 2
|
|
|
|
#define PRINT_STYLE_CSV_2 3
|
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
static int encstatus(int argc, char **argv);
|
|
|
|
static int fault(int argc, char **argv);
|
2015-09-05 00:06:01 +00:00
|
|
|
static int locate(int argc, char **argv);
|
2015-09-19 16:36:45 +00:00
|
|
|
static int objmap(int argc, char **argv);
|
|
|
|
static int sesled(int argc, char **argv, bool fault);
|
2019-12-14 10:58:06 +00:00
|
|
|
static int show(int argc, char **argv);
|
|
|
|
static void sesutil_print(int *style, const char *fmt, ...) __printflike(2,3);
|
2015-09-05 00:06:01 +00:00
|
|
|
|
|
|
|
static struct command {
|
|
|
|
const char *name;
|
2015-09-19 16:36:45 +00:00
|
|
|
const char *param;
|
2015-09-05 00:06:01 +00:00
|
|
|
const char *desc;
|
|
|
|
int (*exec)(int argc, char **argv);
|
|
|
|
} cmds[] = {
|
2015-09-19 16:36:45 +00:00
|
|
|
{ "fault",
|
|
|
|
"(<disk>|<sesid>|all) (on|off)",
|
|
|
|
"Change the state of the fault LED associated with a disk",
|
|
|
|
fault },
|
|
|
|
{ "locate",
|
|
|
|
"(<disk>|<sesid>|all) (on|off)",
|
|
|
|
"Change the state of the locate LED associated with a disk",
|
|
|
|
locate },
|
|
|
|
{ "map", "",
|
|
|
|
"Print a map of the devices managed by the enclosure", objmap } ,
|
2019-12-14 10:58:06 +00:00
|
|
|
{ "show", "",
|
|
|
|
"Print a human-friendly summary of the enclosure", show } ,
|
2015-09-19 16:36:45 +00:00
|
|
|
{ "status", "", "Print the status of the enclosure",
|
|
|
|
encstatus },
|
2015-09-05 00:06:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const int nbcmds = nitems(cmds);
|
2015-09-19 16:36:45 +00:00
|
|
|
static const char *uflag;
|
2015-09-05 00:06:01 +00:00
|
|
|
|
|
|
|
static void
|
2015-09-19 16:36:45 +00:00
|
|
|
usage(FILE *out, const char *subcmd)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (subcmd == NULL) {
|
|
|
|
fprintf(out, "Usage: %s [-u /dev/ses<N>] <command> [options]\n",
|
|
|
|
getprogname());
|
|
|
|
fprintf(out, "Commands supported:\n");
|
|
|
|
}
|
|
|
|
for (i = 0; i < nbcmds; i++) {
|
|
|
|
if (subcmd != NULL) {
|
|
|
|
if (strcmp(subcmd, cmds[i].name) == 0) {
|
|
|
|
fprintf(out, "Usage: %s %s [-u /dev/ses<N>] "
|
|
|
|
"%s\n\t%s\n", getprogname(), subcmd,
|
|
|
|
cmds[i].param, cmds[i].desc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fprintf(out, " %-12s%s\n\t\t%s\n\n", cmds[i].name,
|
|
|
|
cmds[i].param, cmds[i].desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-02-04 01:24:10 +00:00
|
|
|
do_led(int fd, unsigned int idx, elm_type_t type, bool onoff, bool setfault)
|
2015-09-05 00:06:01 +00:00
|
|
|
{
|
2019-02-04 01:24:10 +00:00
|
|
|
int state = onoff ? 1 : 0;
|
2015-09-05 00:06:01 +00:00
|
|
|
encioc_elm_status_t o;
|
2019-02-04 01:24:10 +00:00
|
|
|
struct ses_ctrl_dev_slot *slot;
|
2015-09-05 00:06:01 +00:00
|
|
|
|
|
|
|
o.elm_idx = idx;
|
|
|
|
if (ioctl(fd, ENCIOC_GETELMSTAT, (caddr_t) &o) < 0) {
|
|
|
|
close(fd);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_GETELMSTAT");
|
2015-09-05 00:06:01 +00:00
|
|
|
}
|
2022-01-13 18:45:28 +00:00
|
|
|
ses_status_to_ctrl(type, &o.cstat[0]);
|
2019-02-04 01:24:10 +00:00
|
|
|
switch (type) {
|
|
|
|
case ELMTYP_DEVICE:
|
|
|
|
case ELMTYP_ARRAY_DEV:
|
2022-01-13 18:45:28 +00:00
|
|
|
slot = (struct ses_ctrl_dev_slot *) &o.cstat[0];
|
2019-02-04 01:24:10 +00:00
|
|
|
ses_ctrl_common_set_select(&slot->common, 1);
|
|
|
|
if (setfault)
|
|
|
|
ses_ctrl_dev_slot_set_rqst_fault(slot, state);
|
2016-09-30 20:35:12 +00:00
|
|
|
else
|
2019-02-04 01:24:10 +00:00
|
|
|
ses_ctrl_dev_slot_set_rqst_ident(slot, state);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2015-09-05 00:06:01 +00:00
|
|
|
if (ioctl(fd, ENCIOC_SETELMSTAT, (caddr_t) &o) < 0) {
|
|
|
|
close(fd);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_SETELMSTAT");
|
2015-09-05 00:06:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
disk_match(const char *devnames, const char *disk, size_t len)
|
|
|
|
{
|
2015-09-05 22:33:40 +00:00
|
|
|
const char *dname;
|
2015-09-05 00:06:01 +00:00
|
|
|
|
2015-09-05 22:33:40 +00:00
|
|
|
dname = devnames;
|
|
|
|
while ((dname = strstr(dname, disk)) != NULL) {
|
2015-09-19 16:36:45 +00:00
|
|
|
if (dname[len] == '\0' || dname[len] == ',') {
|
2015-09-05 00:06:01 +00:00
|
|
|
return (true);
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2015-09-05 22:33:40 +00:00
|
|
|
dname++;
|
2015-09-05 00:06:01 +00:00
|
|
|
}
|
2015-09-19 16:36:45 +00:00
|
|
|
|
2015-09-05 00:06:01 +00:00
|
|
|
return (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2015-09-19 18:41:24 +00:00
|
|
|
sesled(int argc, char **argv, bool setfault)
|
2015-09-05 00:06:01 +00:00
|
|
|
{
|
|
|
|
encioc_elm_devnames_t objdn;
|
|
|
|
encioc_element_t *objp;
|
|
|
|
glob_t g;
|
2015-09-19 16:36:45 +00:00
|
|
|
char *disk, *endptr;
|
|
|
|
size_t len, i, ndisks;
|
|
|
|
int fd;
|
|
|
|
unsigned int nobj, j, sesid;
|
|
|
|
bool all, isses, onoff;
|
|
|
|
|
|
|
|
isses = false;
|
|
|
|
all = false;
|
|
|
|
onoff = false;
|
|
|
|
|
|
|
|
if (argc != 3) {
|
2015-09-19 18:41:24 +00:00
|
|
|
usage(stderr, (setfault ? "fault" : "locate"));
|
2015-09-05 00:06:01 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
disk = argv[1];
|
2015-09-05 00:06:01 +00:00
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
sesid = strtoul(disk, &endptr, 10);
|
|
|
|
if (*endptr == '\0') {
|
|
|
|
endptr = strrchr(uflag, '*');
|
2015-12-11 21:11:02 +00:00
|
|
|
if (endptr != NULL && *endptr == '*') {
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_warnx("Must specifying a SES device (-u) to use a SES "
|
2015-09-19 16:36:45 +00:00
|
|
|
"id# to identify a disk");
|
2015-09-19 18:41:24 +00:00
|
|
|
usage(stderr, (setfault ? "fault" : "locate"));
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
|
|
|
isses = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(argv[2], "on") == 0) {
|
2015-09-05 16:59:30 +00:00
|
|
|
onoff = true;
|
2015-09-19 16:36:45 +00:00
|
|
|
} else if (strcmp(argv[2], "off") == 0) {
|
2015-09-05 16:59:30 +00:00
|
|
|
onoff = false;
|
2015-09-05 00:06:01 +00:00
|
|
|
} else {
|
2015-09-19 18:41:24 +00:00
|
|
|
usage(stderr, (setfault ? "fault" : "locate"));
|
2015-09-05 00:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(disk, "all") == 0) {
|
|
|
|
all = true;
|
|
|
|
}
|
|
|
|
len = strlen(disk);
|
|
|
|
|
|
|
|
/* Get the list of ses devices */
|
2015-09-19 16:36:45 +00:00
|
|
|
if (glob((uflag != NULL ? uflag : "/dev/ses[0-9]*"), 0, NULL, &g) ==
|
|
|
|
GLOB_NOMATCH) {
|
2015-09-05 00:06:01 +00:00
|
|
|
globfree(&g);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_errx(EXIT_FAILURE, "No SES devices found");
|
2015-09-05 00:06:01 +00:00
|
|
|
}
|
2015-09-19 16:36:45 +00:00
|
|
|
|
|
|
|
ndisks = 0;
|
2015-09-05 00:06:01 +00:00
|
|
|
for (i = 0; i < g.gl_pathc; i++) {
|
|
|
|
/* ensure we only got numbers after ses */
|
|
|
|
if (strspn(g.gl_pathv[i] + 8, "0123456789") !=
|
2015-09-19 16:36:45 +00:00
|
|
|
strlen(g.gl_pathv[i] + 8)) {
|
2015-09-05 00:06:01 +00:00
|
|
|
continue;
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2015-09-05 00:06:01 +00:00
|
|
|
if ((fd = open(g.gl_pathv[i], O_RDWR)) < 0) {
|
2015-09-19 16:36:45 +00:00
|
|
|
/*
|
|
|
|
* Don't treat non-access errors as critical if we are
|
|
|
|
* accessing all devices
|
|
|
|
*/
|
|
|
|
if (errno == EACCES && g.gl_pathc > 1) {
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "unable to access SES device");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_warn("unable to access SES device: %s", g.gl_pathv[i]);
|
2015-09-19 16:36:45 +00:00
|
|
|
continue;
|
2015-09-05 00:06:01 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
if (ioctl(fd, ENCIOC_GETNELM, (caddr_t) &nobj) < 0) {
|
|
|
|
close(fd);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_GETNELM");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2015-09-05 00:06:01 +00:00
|
|
|
|
|
|
|
objp = calloc(nobj, sizeof(encioc_element_t));
|
2015-09-19 16:36:45 +00:00
|
|
|
if (objp == NULL) {
|
|
|
|
close(fd);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "calloc()");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2015-09-05 00:06:01 +00:00
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
if (ioctl(fd, ENCIOC_GETELMMAP, (caddr_t) objp) < 0) {
|
2019-11-12 23:09:55 +00:00
|
|
|
free(objp);
|
2015-09-19 16:36:45 +00:00
|
|
|
close(fd);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_GETELMMAP");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2015-09-05 00:06:01 +00:00
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
if (isses) {
|
2019-11-12 23:03:52 +00:00
|
|
|
if (sesid >= nobj) {
|
2019-11-12 23:09:55 +00:00
|
|
|
free(objp);
|
2015-09-19 16:36:45 +00:00
|
|
|
close(fd);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_errx(EXIT_FAILURE,
|
2015-09-19 16:36:45 +00:00
|
|
|
"Requested SES ID does not exist");
|
|
|
|
}
|
2019-02-04 01:24:10 +00:00
|
|
|
do_led(fd, sesid, objp[sesid].elm_type, onoff, setfault);
|
2015-09-19 16:36:45 +00:00
|
|
|
ndisks++;
|
2019-11-12 23:09:55 +00:00
|
|
|
free(objp);
|
2015-09-19 16:36:45 +00:00
|
|
|
close(fd);
|
|
|
|
break;
|
|
|
|
}
|
2015-09-05 00:06:01 +00:00
|
|
|
for (j = 0; j < nobj; j++) {
|
2019-11-12 23:57:57 +00:00
|
|
|
const int devnames_size = 128;
|
|
|
|
char devnames[devnames_size];
|
|
|
|
|
2017-06-06 02:03:22 +00:00
|
|
|
if (all) {
|
2023-03-10 17:47:08 +00:00
|
|
|
encioc_elm_status_t es;
|
|
|
|
memset(&es, 0, sizeof(es));
|
|
|
|
es.elm_idx = objp[j].elm_idx;
|
|
|
|
if (ioctl(fd, ENCIOC_GETELMSTAT, &es) < 0) {
|
|
|
|
close(fd);
|
|
|
|
xo_err(EXIT_FAILURE,
|
|
|
|
"ENCIOC_GETELMSTAT");
|
|
|
|
}
|
|
|
|
if ((es.cstat[0] & 0xf) == SES_OBJSTAT_NOACCESS)
|
|
|
|
continue;
|
2019-02-04 01:24:10 +00:00
|
|
|
do_led(fd, objp[j].elm_idx, objp[j].elm_type,
|
|
|
|
onoff, setfault);
|
2017-06-06 02:03:22 +00:00
|
|
|
continue;
|
|
|
|
}
|
2015-09-05 00:06:01 +00:00
|
|
|
memset(&objdn, 0, sizeof(objdn));
|
2019-11-12 23:57:57 +00:00
|
|
|
memset(devnames, 0, devnames_size);
|
2015-09-05 00:06:01 +00:00
|
|
|
objdn.elm_idx = objp[j].elm_idx;
|
2019-11-12 23:57:57 +00:00
|
|
|
objdn.elm_names_size = devnames_size;
|
|
|
|
objdn.elm_devnames = devnames;
|
2015-09-05 00:06:01 +00:00
|
|
|
if (ioctl(fd, ENCIOC_GETELMDEVNAMES,
|
2015-09-19 16:36:45 +00:00
|
|
|
(caddr_t) &objdn) <0) {
|
2015-09-05 00:06:01 +00:00
|
|
|
continue;
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2015-09-05 00:06:01 +00:00
|
|
|
if (objdn.elm_names_len > 0) {
|
|
|
|
if (disk_match(objdn.elm_devnames, disk, len)) {
|
2019-02-04 01:24:10 +00:00
|
|
|
do_led(fd, objdn.elm_idx, objp[j].elm_type,
|
2015-09-19 18:41:24 +00:00
|
|
|
onoff, setfault);
|
2015-09-19 16:36:45 +00:00
|
|
|
ndisks++;
|
2015-09-05 00:06:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2016-04-20 21:37:32 +00:00
|
|
|
free(objp);
|
2015-09-05 00:06:01 +00:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
globfree(&g);
|
2015-09-19 16:36:45 +00:00
|
|
|
if (ndisks == 0 && all == false) {
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_errx(EXIT_FAILURE, "Count not find the SES id of device '%s'",
|
2015-09-19 16:36:45 +00:00
|
|
|
disk);
|
|
|
|
}
|
2015-09-05 00:06:01 +00:00
|
|
|
|
|
|
|
return (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
static int
|
|
|
|
locate(int argc, char **argv)
|
2015-09-05 00:06:01 +00:00
|
|
|
{
|
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
return (sesled(argc, argv, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fault(int argc, char **argv)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (sesled(argc, argv, true));
|
|
|
|
}
|
|
|
|
|
2017-06-23 15:09:08 +00:00
|
|
|
static void
|
2019-12-14 10:58:06 +00:00
|
|
|
sesutil_print(int *style, const char *fmt, ...)
|
2017-06-23 15:09:08 +00:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
|
2019-12-14 10:58:06 +00:00
|
|
|
if (*style == PRINT_STYLE_DASHED) {
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_open_container("extra_status");
|
|
|
|
xo_emit("\t\tExtra status:\n");
|
2019-12-14 10:58:06 +00:00
|
|
|
*style = PRINT_STYLE_DASHED_2;
|
|
|
|
} else if (*style == PRINT_STYLE_CSV) {
|
|
|
|
xo_open_container("extra_status");
|
|
|
|
*style = PRINT_STYLE_CSV_2;
|
2017-06-23 15:09:08 +00:00
|
|
|
}
|
2019-12-14 10:58:06 +00:00
|
|
|
|
|
|
|
if (*style == PRINT_STYLE_DASHED_2)
|
|
|
|
xo_emit("\t\t- ");
|
|
|
|
else if (*style == PRINT_STYLE_CSV_2)
|
|
|
|
xo_emit(", ");
|
2017-06-23 15:09:08 +00:00
|
|
|
va_start(args, fmt);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_emit_hv(NULL, fmt, args);
|
2017-06-23 15:09:08 +00:00
|
|
|
va_end(args);
|
2019-12-14 10:58:06 +00:00
|
|
|
if (*style == PRINT_STYLE_DASHED_2)
|
|
|
|
xo_emit("\n");
|
2017-06-23 15:09:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-12-14 10:58:06 +00:00
|
|
|
print_extra_status(int eletype, u_char *cstat, int style)
|
2017-06-23 15:09:08 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (cstat[0] & 0x40) {
|
2019-12-14 10:58:06 +00:00
|
|
|
sesutil_print(&style, "{e:predicted_failure/true} Predicted Failure");
|
2017-06-23 15:09:08 +00:00
|
|
|
}
|
|
|
|
if (cstat[0] & 0x20) {
|
2019-12-14 10:58:06 +00:00
|
|
|
sesutil_print(&style, "{e:disabled/true} Disabled");
|
2017-06-23 15:09:08 +00:00
|
|
|
}
|
|
|
|
if (cstat[0] & 0x10) {
|
2019-12-14 10:58:06 +00:00
|
|
|
sesutil_print(&style, "{e:swapped/true} Swapped");
|
2017-06-23 15:09:08 +00:00
|
|
|
}
|
|
|
|
switch (eletype) {
|
|
|
|
case ELMTYP_DEVICE:
|
|
|
|
case ELMTYP_ARRAY_DEV:
|
|
|
|
if (cstat[2] & 0x02) {
|
2019-12-14 10:58:06 +00:00
|
|
|
sesutil_print(&style, "LED={q:led/locate}");
|
2017-06-23 15:09:08 +00:00
|
|
|
}
|
|
|
|
if (cstat[2] & 0x20) {
|
2019-12-14 10:58:06 +00:00
|
|
|
sesutil_print(&style, "LED={q:led/fault}");
|
2017-06-23 15:09:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ELMTYP_FAN:
|
2019-12-14 10:58:06 +00:00
|
|
|
sesutil_print(&style, "Speed: {:speed/%d}{Uw:rpm}",
|
2017-06-23 15:09:08 +00:00
|
|
|
(((0x7 & cstat[1]) << 8) + cstat[2]) * 10);
|
|
|
|
break;
|
|
|
|
case ELMTYP_THERM:
|
|
|
|
if (cstat[2]) {
|
2019-12-14 10:58:06 +00:00
|
|
|
sesutil_print(&style, "Temperature: {:temperature/%d}{Uw:C}",
|
2017-06-23 15:09:08 +00:00
|
|
|
cstat[2] - TEMPERATURE_OFFSET);
|
|
|
|
} else {
|
2019-12-14 10:58:06 +00:00
|
|
|
sesutil_print(&style, "Temperature: -{q:temperature/reserved}");
|
2017-06-23 15:09:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ELMTYP_VOM:
|
2019-12-14 10:58:06 +00:00
|
|
|
sesutil_print(&style, "Voltage: {:voltage/%.2f}{Uw:V}",
|
2017-06-23 15:09:08 +00:00
|
|
|
be16dec(cstat + 2) / 100.0);
|
|
|
|
break;
|
|
|
|
}
|
2019-12-14 10:58:06 +00:00
|
|
|
if (style) {
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_close_container("extra_status");
|
|
|
|
}
|
2017-06-23 15:09:08 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
static int
|
|
|
|
objmap(int argc, char **argv __unused)
|
|
|
|
{
|
2015-12-15 13:01:14 +00:00
|
|
|
encioc_string_t stri;
|
2015-09-19 16:36:45 +00:00
|
|
|
encioc_elm_devnames_t e_devname;
|
|
|
|
encioc_elm_status_t e_status;
|
|
|
|
encioc_elm_desc_t e_desc;
|
|
|
|
encioc_element_t *e_ptr;
|
|
|
|
glob_t g;
|
|
|
|
int fd;
|
|
|
|
unsigned int j, nobj;
|
|
|
|
size_t i;
|
2015-12-15 13:01:14 +00:00
|
|
|
char str[32];
|
2015-09-19 16:36:45 +00:00
|
|
|
|
|
|
|
if (argc != 1) {
|
|
|
|
usage(stderr, "map");
|
|
|
|
}
|
|
|
|
|
2023-02-09 22:23:51 +00:00
|
|
|
memset(&e_desc, 0, sizeof(e_desc));
|
|
|
|
/* SES4r02 allows element descriptors of up to 65536 characters */
|
|
|
|
e_desc.elm_desc_str = calloc(UINT16_MAX, sizeof(char));
|
|
|
|
if (e_desc.elm_desc_str == NULL)
|
|
|
|
xo_err(EXIT_FAILURE, "calloc()");
|
|
|
|
|
|
|
|
e_devname.elm_devnames = calloc(128, sizeof(char));
|
|
|
|
if (e_devname.elm_devnames == NULL)
|
|
|
|
xo_err(EXIT_FAILURE, "calloc()");
|
|
|
|
e_devname.elm_names_size = 128;
|
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
/* Get the list of ses devices */
|
|
|
|
if (glob(uflag, 0, NULL, &g) == GLOB_NOMATCH) {
|
|
|
|
globfree(&g);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_errx(EXIT_FAILURE, "No SES devices found");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_set_version(SESUTIL_XO_VERSION);
|
|
|
|
xo_open_container("sesutil");
|
|
|
|
xo_open_list("enclosures");
|
2015-09-19 16:36:45 +00:00
|
|
|
for (i = 0; i < g.gl_pathc; i++) {
|
|
|
|
/* ensure we only got numbers after ses */
|
|
|
|
if (strspn(g.gl_pathv[i] + 8, "0123456789") !=
|
|
|
|
strlen(g.gl_pathv[i] + 8)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((fd = open(g.gl_pathv[i], O_RDWR)) < 0) {
|
|
|
|
/*
|
|
|
|
* Don't treat non-access errors as critical if we are
|
|
|
|
* accessing all devices
|
|
|
|
*/
|
|
|
|
if (errno == EACCES && g.gl_pathc > 1) {
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "unable to access SES device");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_warn("unable to access SES device: %s", g.gl_pathv[i]);
|
2015-09-19 16:36:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(fd, ENCIOC_GETNELM, (caddr_t) &nobj) < 0) {
|
|
|
|
close(fd);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_GETNELM");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
e_ptr = calloc(nobj, sizeof(encioc_element_t));
|
|
|
|
if (e_ptr == NULL) {
|
|
|
|
close(fd);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "calloc()");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(fd, ENCIOC_GETELMMAP, (caddr_t) e_ptr) < 0) {
|
|
|
|
close(fd);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_GETELMMAP");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
|
|
|
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_open_instance("enclosures");
|
|
|
|
xo_emit("{t:enc/%s}:\n", g.gl_pathv[i] + 5);
|
2015-12-15 13:01:14 +00:00
|
|
|
stri.bufsiz = sizeof(str);
|
|
|
|
stri.buf = &str[0];
|
|
|
|
if (ioctl(fd, ENCIOC_GETENCNAME, (caddr_t) &stri) == 0)
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_emit("\tEnclosure Name: {t:name/%s}\n", stri.buf);
|
2015-12-15 13:01:14 +00:00
|
|
|
stri.bufsiz = sizeof(str);
|
|
|
|
stri.buf = &str[0];
|
|
|
|
if (ioctl(fd, ENCIOC_GETENCID, (caddr_t) &stri) == 0)
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_emit("\tEnclosure ID: {t:id/%s}\n", stri.buf);
|
2015-12-15 13:01:14 +00:00
|
|
|
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_open_list("elements");
|
2015-09-19 16:36:45 +00:00
|
|
|
for (j = 0; j < nobj; j++) {
|
|
|
|
/* Get the status of the element */
|
|
|
|
memset(&e_status, 0, sizeof(e_status));
|
|
|
|
e_status.elm_idx = e_ptr[j].elm_idx;
|
|
|
|
if (ioctl(fd, ENCIOC_GETELMSTAT,
|
|
|
|
(caddr_t) &e_status) < 0) {
|
|
|
|
close(fd);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_GETELMSTAT");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
|
|
|
/* Get the description of the element */
|
|
|
|
e_desc.elm_idx = e_ptr[j].elm_idx;
|
|
|
|
e_desc.elm_desc_len = UINT16_MAX;
|
|
|
|
if (ioctl(fd, ENCIOC_GETELMDESC,
|
|
|
|
(caddr_t) &e_desc) < 0) {
|
|
|
|
close(fd);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_GETELMDESC");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2023-02-09 22:23:51 +00:00
|
|
|
e_desc.elm_desc_str[e_desc.elm_desc_len] = '\0';
|
2015-09-19 16:36:45 +00:00
|
|
|
/* Get the device name(s) of the element */
|
|
|
|
e_devname.elm_idx = e_ptr[j].elm_idx;
|
|
|
|
if (ioctl(fd, ENCIOC_GETELMDEVNAMES,
|
|
|
|
(caddr_t) &e_devname) <0) {
|
2021-08-30 23:39:38 +00:00
|
|
|
/* Continue even if we can't look up devnames */
|
2015-09-19 16:36:45 +00:00
|
|
|
e_devname.elm_devnames[0] = '\0';
|
|
|
|
}
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_open_instance("elements");
|
|
|
|
xo_emit("\tElement {:id/%u}, Type: {:type/%s}\n", e_ptr[j].elm_idx,
|
2015-09-19 16:36:45 +00:00
|
|
|
geteltnm(e_ptr[j].elm_type));
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_emit("\t\tStatus: {:status/%s} ({q:status_code/0x%02x 0x%02x 0x%02x 0x%02x})\n",
|
2015-12-11 20:45:39 +00:00
|
|
|
scode2ascii(e_status.cstat[0]), e_status.cstat[0],
|
|
|
|
e_status.cstat[1], e_status.cstat[2],
|
|
|
|
e_status.cstat[3]);
|
2015-09-19 16:36:45 +00:00
|
|
|
if (e_desc.elm_desc_len > 0) {
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_emit("\t\tDescription: {:description/%s}\n",
|
2015-09-19 16:36:45 +00:00
|
|
|
e_desc.elm_desc_str);
|
|
|
|
}
|
|
|
|
if (e_devname.elm_names_len > 0) {
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_emit("\t\tDevice Names: {:device_names/%s}\n",
|
2015-09-19 16:36:45 +00:00
|
|
|
e_devname.elm_devnames);
|
|
|
|
}
|
2019-12-14 10:58:06 +00:00
|
|
|
print_extra_status(e_ptr[j].elm_type, e_status.cstat, PRINT_STYLE_DASHED);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_close_instance("elements");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_close_list("elements");
|
2016-04-20 21:37:32 +00:00
|
|
|
free(e_ptr);
|
2015-09-19 16:36:45 +00:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
globfree(&g);
|
2023-02-09 22:23:51 +00:00
|
|
|
free(e_devname.elm_devnames);
|
|
|
|
free(e_desc.elm_desc_str);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_close_list("enclosures");
|
|
|
|
xo_close_container("sesutil");
|
|
|
|
xo_finish();
|
2015-09-19 16:36:45 +00:00
|
|
|
|
|
|
|
return (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2019-12-14 10:58:06 +00:00
|
|
|
/*
|
|
|
|
* Get rid of the 'passN' devices, unless there's nothing else to show.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
skip_pass_devices(char *devnames, size_t devnameslen)
|
|
|
|
{
|
|
|
|
char *dev, devs[128], passes[128], *tmp;
|
|
|
|
|
|
|
|
devs[0] = passes[0] = '\0';
|
|
|
|
tmp = devnames;
|
|
|
|
|
|
|
|
while ((dev = strsep(&tmp, ",")) != NULL) {
|
|
|
|
if (strncmp(dev, "pass", 4) == 0) {
|
|
|
|
if (passes[0] != '\0')
|
|
|
|
strlcat(passes, ",", sizeof(passes));
|
|
|
|
strlcat(passes, dev, sizeof(passes));
|
|
|
|
} else {
|
|
|
|
if (devs[0] != '\0')
|
|
|
|
strlcat(devs, ",", sizeof(devs));
|
|
|
|
strlcat(devs, dev, sizeof(devs));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
strlcpy(devnames, devs, devnameslen);
|
|
|
|
if (devnames[0] == '\0')
|
|
|
|
strlcpy(devnames, passes, devnameslen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fetch_device_details(char *devnames, char **model, char **serial, off_t *size)
|
|
|
|
{
|
|
|
|
char ident[DISK_IDENT_SIZE];
|
|
|
|
struct diocgattr_arg arg;
|
2020-02-13 15:28:56 +00:00
|
|
|
char *tmp;
|
2019-12-14 10:58:06 +00:00
|
|
|
off_t mediasize;
|
2020-02-13 15:28:56 +00:00
|
|
|
int comma;
|
2019-12-14 10:58:06 +00:00
|
|
|
int fd;
|
|
|
|
|
2020-02-13 15:28:56 +00:00
|
|
|
comma = (int)strcspn(devnames, ",");
|
|
|
|
asprintf(&tmp, "/dev/%.*s", comma, devnames);
|
2019-12-14 10:58:06 +00:00
|
|
|
if (tmp == NULL)
|
2020-02-13 15:28:56 +00:00
|
|
|
err(1, "asprintf");
|
2019-12-14 10:58:06 +00:00
|
|
|
fd = open(tmp, O_RDONLY);
|
2020-02-13 15:28:56 +00:00
|
|
|
free(tmp);
|
2019-12-14 10:58:06 +00:00
|
|
|
if (fd < 0) {
|
|
|
|
/*
|
|
|
|
* This can happen with a disk so broken it cannot
|
|
|
|
* be probed by GEOM.
|
|
|
|
*/
|
|
|
|
*model = strdup("?");
|
|
|
|
*serial = strdup("?");
|
|
|
|
*size = -1;
|
2020-02-13 15:28:56 +00:00
|
|
|
close(fd);
|
2019-12-14 10:58:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
strlcpy(arg.name, "GEOM::descr", sizeof(arg.name));
|
|
|
|
arg.len = sizeof(arg.value.str);
|
|
|
|
if (ioctl(fd, DIOCGATTR, &arg) == 0)
|
|
|
|
*model = strdup(arg.value.str);
|
|
|
|
else
|
|
|
|
*model = NULL;
|
|
|
|
|
|
|
|
if (ioctl(fd, DIOCGIDENT, ident) == 0)
|
|
|
|
*serial = strdup(ident);
|
|
|
|
else
|
|
|
|
*serial = NULL;
|
|
|
|
|
|
|
|
if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) == 0)
|
|
|
|
*size = mediasize;
|
|
|
|
else
|
|
|
|
*size = -1;
|
2020-02-13 15:28:56 +00:00
|
|
|
close(fd);
|
2019-12-14 10:58:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_device(int fd, int elm_idx, encioc_elm_status_t e_status, encioc_elm_desc_t e_desc)
|
|
|
|
{
|
|
|
|
encioc_elm_devnames_t e_devname;
|
2022-01-19 21:57:27 +00:00
|
|
|
char *model = NULL, *serial = NULL;
|
2019-12-14 10:58:06 +00:00
|
|
|
off_t size;
|
|
|
|
|
|
|
|
/* Get the device name(s) of the element */
|
|
|
|
memset(&e_devname, 0, sizeof(e_devname));
|
|
|
|
e_devname.elm_idx = elm_idx;
|
|
|
|
e_devname.elm_names_size = 128;
|
|
|
|
e_devname.elm_devnames = calloc(128, sizeof(char));
|
|
|
|
if (e_devname.elm_devnames == NULL) {
|
|
|
|
close(fd);
|
|
|
|
xo_err(EXIT_FAILURE, "calloc()");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(fd, ENCIOC_GETELMDEVNAMES,
|
|
|
|
(caddr_t) &e_devname) < 0) {
|
|
|
|
/* We don't care if this fails */
|
|
|
|
e_devname.elm_devnames[0] = '\0';
|
|
|
|
size = -1;
|
|
|
|
} else {
|
|
|
|
skip_pass_devices(e_devname.elm_devnames, 128);
|
|
|
|
fetch_device_details(e_devname.elm_devnames, &model, &serial, &size);
|
|
|
|
}
|
|
|
|
xo_open_instance("elements");
|
|
|
|
xo_emit("{e:type/device_slot}");
|
2022-01-02 11:44:02 +00:00
|
|
|
xo_emit("{d:description/%-15s} ", e_desc.elm_desc_len > 0 ? e_desc.elm_desc_str : "-");
|
|
|
|
xo_emit("{e:description/%-15s}", e_desc.elm_desc_len > 0 ? e_desc.elm_desc_str : "");
|
2019-12-14 10:58:06 +00:00
|
|
|
xo_emit("{d:device_names/%-7s} ", e_devname.elm_names_len > 0 ? e_devname.elm_devnames : "-");
|
|
|
|
xo_emit("{e:device_names/%s}", e_devname.elm_names_len > 0 ? e_devname.elm_devnames : "");
|
|
|
|
xo_emit("{d:model/%-25s} ", model ? model : "-");
|
|
|
|
xo_emit("{e:model/%s}", model ? model : "");
|
|
|
|
xo_emit("{d:serial/%-20s} ", serial != NULL ? serial : "-");
|
|
|
|
xo_emit("{e:serial/%s}", serial != NULL ? serial : "");
|
2021-07-21 09:14:21 +00:00
|
|
|
if ((e_status.cstat[0] & 0xf) == SES_OBJSTAT_OK && size >= 0) {
|
2019-12-14 10:58:06 +00:00
|
|
|
xo_emit("{h,hn-1000:size/%ld}{e:status/%s}",
|
|
|
|
size, scode2ascii(e_status.cstat[0]));
|
|
|
|
} else {
|
|
|
|
xo_emit("{:status/%s}", scode2ascii(e_status.cstat[0]));
|
|
|
|
}
|
|
|
|
print_extra_status(ELMTYP_ARRAY_DEV, e_status.cstat, PRINT_STYLE_CSV);
|
|
|
|
xo_emit("\n");
|
|
|
|
xo_close_instance("elements");
|
2022-01-19 21:57:27 +00:00
|
|
|
free(serial);
|
|
|
|
free(model);
|
2019-12-14 10:58:06 +00:00
|
|
|
free(e_devname.elm_devnames);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_therm(encioc_elm_status_t e_status, encioc_elm_desc_t e_desc)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (e_desc.elm_desc_len <= 0) {
|
|
|
|
/* We don't have a label to display; might as well skip it. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e_status.cstat[2] == 0) {
|
|
|
|
/* No temperature to show. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xo_open_instance("elements");
|
|
|
|
xo_emit("{e:type/temperature_sensor}");
|
|
|
|
xo_emit("{:description/%s}: {:temperature/%d}{Uw:C}",
|
|
|
|
e_desc.elm_desc_str, e_status.cstat[2] - TEMPERATURE_OFFSET);
|
|
|
|
xo_close_instance("elements");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
show_vom(encioc_elm_status_t e_status, encioc_elm_desc_t e_desc)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (e_desc.elm_desc_len <= 0) {
|
|
|
|
/* We don't have a label to display; might as well skip it. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e_status.cstat[2] == 0) {
|
|
|
|
/* No voltage to show. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xo_open_instance("elements");
|
|
|
|
xo_emit("{e:type/voltage_sensor}");
|
|
|
|
xo_emit("{:description/%s}: {:voltage/%.2f}{Uw:V}",
|
|
|
|
e_desc.elm_desc_str, be16dec(e_status.cstat + 2) / 100.0);
|
|
|
|
xo_close_instance("elements");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
show(int argc, char **argv __unused)
|
|
|
|
{
|
|
|
|
encioc_string_t stri;
|
|
|
|
encioc_elm_status_t e_status;
|
|
|
|
encioc_elm_desc_t e_desc;
|
|
|
|
encioc_element_t *e_ptr;
|
|
|
|
glob_t g;
|
|
|
|
elm_type_t prev_type;
|
|
|
|
int fd;
|
|
|
|
unsigned int j, nobj;
|
|
|
|
size_t i;
|
|
|
|
bool first_ses;
|
|
|
|
char str[32];
|
|
|
|
|
|
|
|
if (argc != 1) {
|
|
|
|
usage(stderr, "map");
|
|
|
|
}
|
|
|
|
|
|
|
|
first_ses = true;
|
|
|
|
|
2023-02-09 22:23:51 +00:00
|
|
|
e_desc.elm_desc_str = calloc(UINT16_MAX, sizeof(char));
|
|
|
|
if (e_desc.elm_desc_str == NULL)
|
|
|
|
xo_err(EXIT_FAILURE, "calloc()");
|
|
|
|
|
2019-12-14 10:58:06 +00:00
|
|
|
/* Get the list of ses devices */
|
|
|
|
if (glob(uflag, 0, NULL, &g) == GLOB_NOMATCH) {
|
|
|
|
globfree(&g);
|
|
|
|
xo_errx(EXIT_FAILURE, "No SES devices found");
|
|
|
|
}
|
|
|
|
xo_set_version(SESUTIL_XO_VERSION);
|
|
|
|
xo_open_container("sesutil");
|
|
|
|
xo_open_list("enclosures");
|
|
|
|
for (i = 0; i < g.gl_pathc; i++) {
|
|
|
|
/* ensure we only got numbers after ses */
|
|
|
|
if (strspn(g.gl_pathv[i] + 8, "0123456789") !=
|
|
|
|
strlen(g.gl_pathv[i] + 8)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((fd = open(g.gl_pathv[i], O_RDWR)) < 0) {
|
|
|
|
/*
|
|
|
|
* Don't treat non-access errors as critical if we are
|
|
|
|
* accessing all devices
|
|
|
|
*/
|
|
|
|
if (errno == EACCES && g.gl_pathc > 1) {
|
|
|
|
xo_err(EXIT_FAILURE, "unable to access SES device");
|
|
|
|
}
|
|
|
|
xo_warn("unable to access SES device: %s", g.gl_pathv[i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(fd, ENCIOC_GETNELM, (caddr_t) &nobj) < 0) {
|
|
|
|
close(fd);
|
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_GETNELM");
|
|
|
|
}
|
|
|
|
|
|
|
|
e_ptr = calloc(nobj, sizeof(encioc_element_t));
|
|
|
|
if (e_ptr == NULL) {
|
|
|
|
close(fd);
|
|
|
|
xo_err(EXIT_FAILURE, "calloc()");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(fd, ENCIOC_GETELMMAP, (caddr_t) e_ptr) < 0) {
|
|
|
|
close(fd);
|
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_GETELMMAP");
|
|
|
|
}
|
|
|
|
|
|
|
|
xo_open_instance("enclosures");
|
|
|
|
|
|
|
|
if (first_ses)
|
|
|
|
first_ses = false;
|
|
|
|
else
|
|
|
|
xo_emit("\n");
|
|
|
|
|
|
|
|
xo_emit("{t:enc/%s}: ", g.gl_pathv[i] + 5);
|
|
|
|
stri.bufsiz = sizeof(str);
|
|
|
|
stri.buf = &str[0];
|
|
|
|
if (ioctl(fd, ENCIOC_GETENCNAME, (caddr_t) &stri) == 0)
|
|
|
|
xo_emit("<{t:name/%s}>; ", stri.buf);
|
|
|
|
stri.bufsiz = sizeof(str);
|
|
|
|
stri.buf = &str[0];
|
|
|
|
if (ioctl(fd, ENCIOC_GETENCID, (caddr_t) &stri) == 0)
|
|
|
|
xo_emit("ID: {t:id/%s}", stri.buf);
|
|
|
|
xo_emit("\n");
|
|
|
|
|
|
|
|
xo_open_list("elements");
|
|
|
|
prev_type = -1;
|
|
|
|
for (j = 0; j < nobj; j++) {
|
|
|
|
/* Get the status of the element */
|
|
|
|
memset(&e_status, 0, sizeof(e_status));
|
|
|
|
e_status.elm_idx = e_ptr[j].elm_idx;
|
|
|
|
if (ioctl(fd, ENCIOC_GETELMSTAT,
|
|
|
|
(caddr_t) &e_status) < 0) {
|
|
|
|
close(fd);
|
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_GETELMSTAT");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip "Unsupported" elements; those usually precede
|
|
|
|
* the actual device entries and are not particularly
|
|
|
|
* interesting.
|
|
|
|
*/
|
|
|
|
if (e_status.cstat[0] == SES_OBJSTAT_UNSUPPORTED)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Get the description of the element */
|
|
|
|
e_desc.elm_idx = e_ptr[j].elm_idx;
|
|
|
|
e_desc.elm_desc_len = UINT16_MAX;
|
|
|
|
if (ioctl(fd, ENCIOC_GETELMDESC,
|
|
|
|
(caddr_t) &e_desc) < 0) {
|
|
|
|
close(fd);
|
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_GETELMDESC");
|
|
|
|
}
|
2023-02-09 22:23:51 +00:00
|
|
|
e_desc.elm_desc_str[e_desc.elm_desc_len] = '\0';
|
2019-12-14 10:58:06 +00:00
|
|
|
|
|
|
|
switch (e_ptr[j].elm_type) {
|
|
|
|
case ELMTYP_DEVICE:
|
|
|
|
case ELMTYP_ARRAY_DEV:
|
|
|
|
if (e_ptr[j].elm_type != prev_type)
|
2022-01-02 11:44:02 +00:00
|
|
|
xo_emit("Desc Dev Model Ident Size/Status\n");
|
2019-12-14 10:58:06 +00:00
|
|
|
|
|
|
|
show_device(fd, e_ptr[j].elm_idx, e_status, e_desc);
|
|
|
|
prev_type = e_ptr[j].elm_type;
|
|
|
|
break;
|
|
|
|
case ELMTYP_THERM:
|
|
|
|
if (e_ptr[j].elm_type != prev_type)
|
2020-06-30 16:49:43 +00:00
|
|
|
xo_emit("\nTemperatures: ");
|
2019-12-14 10:58:06 +00:00
|
|
|
else
|
|
|
|
xo_emit(", ");
|
|
|
|
prev_type = e_ptr[j].elm_type;
|
|
|
|
show_therm(e_status, e_desc);
|
|
|
|
break;
|
|
|
|
case ELMTYP_VOM:
|
|
|
|
if (e_ptr[j].elm_type != prev_type)
|
2020-06-30 16:49:43 +00:00
|
|
|
xo_emit("\nVoltages: ");
|
2019-12-14 10:58:06 +00:00
|
|
|
else
|
|
|
|
xo_emit(", ");
|
|
|
|
prev_type = e_ptr[j].elm_type;
|
|
|
|
show_vom(e_status, e_desc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* Ignore stuff not interesting to the user.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (prev_type != (elm_type_t)-1 &&
|
|
|
|
prev_type != ELMTYP_DEVICE && prev_type != ELMTYP_ARRAY_DEV)
|
|
|
|
xo_emit("\n");
|
|
|
|
xo_close_list("elements");
|
|
|
|
free(e_ptr);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
globfree(&g);
|
2023-02-09 22:23:51 +00:00
|
|
|
free(e_desc.elm_desc_str);
|
2019-12-14 10:58:06 +00:00
|
|
|
xo_close_list("enclosures");
|
|
|
|
xo_close_container("sesutil");
|
|
|
|
xo_finish();
|
|
|
|
|
|
|
|
return (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
static int
|
|
|
|
encstatus(int argc, char **argv __unused)
|
|
|
|
{
|
|
|
|
glob_t g;
|
|
|
|
int fd, status;
|
|
|
|
size_t i, e;
|
|
|
|
u_char estat;
|
|
|
|
|
|
|
|
status = 0;
|
|
|
|
if (argc != 1) {
|
|
|
|
usage(stderr, "status");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the list of ses devices */
|
|
|
|
if (glob(uflag, 0, NULL, &g) == GLOB_NOMATCH) {
|
|
|
|
globfree(&g);
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_errx(EXIT_FAILURE, "No SES devices found");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2017-06-29 18:52:36 +00:00
|
|
|
|
|
|
|
xo_set_version(SESUTIL_XO_VERSION);
|
|
|
|
xo_open_container("sesutil");
|
|
|
|
xo_open_list("enclosures");
|
2015-09-19 16:36:45 +00:00
|
|
|
for (i = 0; i < g.gl_pathc; i++) {
|
|
|
|
/* ensure we only got numbers after ses */
|
|
|
|
if (strspn(g.gl_pathv[i] + 8, "0123456789") !=
|
|
|
|
strlen(g.gl_pathv[i] + 8)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((fd = open(g.gl_pathv[i], O_RDWR)) < 0) {
|
|
|
|
/*
|
|
|
|
* Don't treat non-access errors as critical if we are
|
|
|
|
* accessing all devices
|
|
|
|
*/
|
|
|
|
if (errno == EACCES && g.gl_pathc > 1) {
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "unable to access SES device");
|
2015-09-19 16:36:45 +00:00
|
|
|
}
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_warn("unable to access SES device: %s", g.gl_pathv[i]);
|
2015-09-19 16:36:45 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(fd, ENCIOC_GETENCSTAT, (caddr_t) &estat) < 0) {
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_err(EXIT_FAILURE, "ENCIOC_GETENCSTAT");
|
2015-09-19 16:36:45 +00:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_open_instance("enclosures");
|
|
|
|
xo_emit("{:enc/%s}: ", g.gl_pathv[i] + 5);
|
2015-09-19 16:36:45 +00:00
|
|
|
e = 0;
|
|
|
|
if (estat == 0) {
|
|
|
|
if (status == 0) {
|
|
|
|
status = 1;
|
|
|
|
}
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_emit("{q:status/OK}");
|
2015-09-19 16:36:45 +00:00
|
|
|
} else {
|
|
|
|
if (estat & SES_ENCSTAT_INFO) {
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_emit("{lq:status/INFO}");
|
2015-09-19 16:36:45 +00:00
|
|
|
e++;
|
|
|
|
}
|
|
|
|
if (estat & SES_ENCSTAT_NONCRITICAL) {
|
|
|
|
if (e)
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_emit(",");
|
|
|
|
xo_emit("{lq:status/NONCRITICAL}");
|
2015-09-19 16:36:45 +00:00
|
|
|
e++;
|
|
|
|
}
|
|
|
|
if (estat & SES_ENCSTAT_CRITICAL) {
|
|
|
|
if (e)
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_emit(",");
|
|
|
|
xo_emit("{lq:status/CRITICAL}");
|
2015-09-19 16:36:45 +00:00
|
|
|
e++;
|
|
|
|
status = -1;
|
|
|
|
}
|
|
|
|
if (estat & SES_ENCSTAT_UNRECOV) {
|
|
|
|
if (e)
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_emit(",");
|
|
|
|
xo_emit("{lq:status/UNRECOV}");
|
2015-09-19 16:36:45 +00:00
|
|
|
e++;
|
|
|
|
status = -1;
|
|
|
|
}
|
|
|
|
}
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_close_instance("enclosures");
|
|
|
|
xo_emit("\n");
|
2015-09-19 16:36:45 +00:00
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
globfree(&g);
|
|
|
|
|
2017-06-29 18:52:36 +00:00
|
|
|
xo_close_list("enclosures");
|
|
|
|
xo_close_container("sesutil");
|
|
|
|
xo_finish();
|
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
if (status == 1) {
|
|
|
|
return (EXIT_SUCCESS);
|
|
|
|
} else {
|
|
|
|
return (EXIT_FAILURE);
|
|
|
|
}
|
2015-09-05 00:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2015-09-19 16:36:45 +00:00
|
|
|
int i, ch;
|
2015-09-05 00:06:01 +00:00
|
|
|
struct command *cmd = NULL;
|
|
|
|
|
2017-06-29 18:52:36 +00:00
|
|
|
argc = xo_parse_args(argc, argv);
|
|
|
|
if (argc < 0)
|
|
|
|
exit(1);
|
|
|
|
|
2015-09-19 16:36:45 +00:00
|
|
|
uflag = "/dev/ses[0-9]*";
|
|
|
|
while ((ch = getopt_long(argc, argv, "u:", NULL, NULL)) != -1) {
|
|
|
|
switch (ch) {
|
|
|
|
case 'u':
|
|
|
|
uflag = optarg;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage(stderr, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
if (argc < 1) {
|
2015-09-05 00:06:01 +00:00
|
|
|
warnx("Missing command");
|
2015-09-19 16:36:45 +00:00
|
|
|
usage(stderr, NULL);
|
2015-09-05 00:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nbcmds; i++) {
|
2015-09-19 16:36:45 +00:00
|
|
|
if (strcmp(argv[0], cmds[i].name) == 0) {
|
2015-09-05 00:06:01 +00:00
|
|
|
cmd = &cmds[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd == NULL) {
|
2015-09-19 16:36:45 +00:00
|
|
|
warnx("unknown command %s", argv[0]);
|
|
|
|
usage(stderr, NULL);
|
2015-09-05 00:06:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (cmd->exec(argc, argv));
|
|
|
|
}
|