Add -c option to sesd to make it clear enclosure status after reading it

in case if it is not permanent and was fixed.
This commit is contained in:
Alexander Motin 2012-11-06 00:22:33 +00:00
parent 23ec103f3f
commit 3364718004
2 changed files with 38 additions and 22 deletions

View File

@ -31,7 +31,7 @@
.\" .\"
.\" $FreeBSD$ .\" $FreeBSD$
.\" .\"
.Dd February 21, 2000 .Dd November 5, 2012
.Dt SESD 8 .Dt SESD 8
.Os .Os
.Sh NAME .Sh NAME
@ -39,6 +39,7 @@
.Nd monitor SCSI Environmental Services Devices .Nd monitor SCSI Environmental Services Devices
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op Fl c
.Op Fl d .Op Fl d
.Op Fl t Ar poll-interval .Op Fl t Ar poll-interval
.Ar device .Ar device
@ -57,7 +58,9 @@ poll each device for a change in state.
.Pp .Pp
The following options may be used: The following options may be used:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Fl p Ar poll-interval .It Fl c
Try to clear enclosure status after read.
.It Fl t Ar poll-interval
Change the interval of polling from the default 30 seconds to the number Change the interval of polling from the default 30 seconds to the number
of seconds specified. of seconds specified.
.It Fl d .It Fl d

View File

@ -40,6 +40,7 @@
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <syslog.h> #include <syslog.h>
#include <unistd.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <cam/scsi/scsi_all.h> #include <cam/scsi/scsi_all.h>
#include <cam/scsi/scsi_enc.h> #include <cam/scsi/scsi_enc.h>
@ -55,29 +56,33 @@ int
main(int a, char **v) main(int a, char **v)
{ {
static const char *usage = static const char *usage =
"usage: %s [ -d ] [ -t pollinterval ] device [ device ]\n"; "usage: %s [ -c ] [ -d ] [ -t pollinterval ] device [ device ]\n";
int fd, polltime, dev, devbase, nodaemon; int fd, polltime, dev, nodaemon, clear, c;
encioc_enc_status_t stat, *carray; encioc_enc_status_t stat, nstat, *carray;
if (a < 2) { if (a < 2) {
fprintf(stderr, usage, *v); fprintf(stderr, usage, *v);
return (1); return (1);
} }
devbase = 1; nodaemon = 0;
polltime = 30;
if (strcmp(v[1], "-d") == 0) { clear = 0;
nodaemon = 1; while ((c = getopt(a, v, "cdt:")) != -1) {
devbase++; switch (c) {
} else { case 'c':
nodaemon = 0; clear = 1;
} break;
case 'd':
if (a > 2 && strcmp(v[2], "-t") == 0) { nodaemon = 1;
devbase += 2; break;
polltime = atoi(v[3]); case 't':
} else { polltime = atoi(optarg);
polltime = 30; break;
default:
fprintf(stderr, usage, *v);
return (1);
}
} }
carray = malloc(a); carray = malloc(a);
@ -85,13 +90,13 @@ main(int a, char **v)
perror("malloc"); perror("malloc");
return (1); return (1);
} }
for (dev = devbase; dev < a; dev++) for (dev = optind; dev < a; dev++)
carray[dev] = (encioc_enc_status_t) -1; carray[dev] = (encioc_enc_status_t) -1;
/* /*
* Check to make sure we can open all devices * Check to make sure we can open all devices
*/ */
for (dev = devbase; dev < a; dev++) { for (dev = optind; dev < a; dev++) {
fd = open(v[dev], O_RDWR); fd = open(v[dev], O_RDWR);
if (fd < 0) { if (fd < 0) {
perror(v[dev]); perror(v[dev]);
@ -115,7 +120,7 @@ main(int a, char **v)
} }
for (;;) { for (;;) {
for (dev = devbase; dev < a; dev++) { for (dev = optind; dev < a; dev++) {
fd = open(v[dev], O_RDWR); fd = open(v[dev], O_RDWR);
if (fd < 0) { if (fd < 0) {
syslog(LOG_ERR, "%s: %m", v[dev]); syslog(LOG_ERR, "%s: %m", v[dev]);
@ -131,6 +136,14 @@ main(int a, char **v)
(void) close(fd); (void) close(fd);
continue; continue;
} }
if (stat != 0 && clear) {
nstat = 0;
if (ioctl(fd, ENCIOC_SETENCSTAT,
(caddr_t) &nstat) < 0) {
syslog(LOG_ERR,
"%s: ENCIOC_SETENCSTAT- %m", v[dev]);
}
}
(void) close(fd); (void) close(fd);
if (stat == carray[dev]) if (stat == carray[dev])