summaryrefslogtreecommitdiffstats
path: root/share/examples
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2012-05-24 14:07:44 +0000
committermav <mav@FreeBSD.org>2012-05-24 14:07:44 +0000
commit96f3e42ce2c9de14b3e9a1de338ed639c1c8b596 (patch)
tree40272ce66d9fbbbec27ad859c9e9a595d6716bd3 /share/examples
parent5b4a3e5f4a4045127c253ffac2a618946f83912b (diff)
downloadFreeBSD-src-96f3e42ce2c9de14b3e9a1de338ed639c1c8b596.zip
FreeBSD-src-96f3e42ce2c9de14b3e9a1de338ed639c1c8b596.tar.gz
MFprojects/zfsd:
Revamp the CAM enclosure services driver. This updated driver uses an in-kernel daemon to track state changes and publishes physical path location information\for disk elements into the CAM device database. Sponsored by: Spectra Logic Corporation Sponsored by: iXsystems, Inc. Submitted by: gibbs, will, mav
Diffstat (limited to 'share/examples')
-rw-r--r--share/examples/ses/Makefile.inc1
-rw-r--r--share/examples/ses/srcs/eltsub.c109
-rw-r--r--share/examples/ses/srcs/getencstat.c81
-rw-r--r--share/examples/ses/srcs/getnobj.c5
-rw-r--r--share/examples/ses/srcs/getobjmap.c5
-rw-r--r--share/examples/ses/srcs/getobjstat.c5
-rw-r--r--share/examples/ses/srcs/inienc.c5
-rw-r--r--share/examples/ses/srcs/sesd.c17
-rw-r--r--share/examples/ses/srcs/setencstat.c13
-rw-r--r--share/examples/ses/srcs/setobjstat.c13
10 files changed, 157 insertions, 97 deletions
diff --git a/share/examples/ses/Makefile.inc b/share/examples/ses/Makefile.inc
index 5ff1cd4..2b1e858 100644
--- a/share/examples/ses/Makefile.inc
+++ b/share/examples/ses/Makefile.inc
@@ -32,7 +32,6 @@
# mjacob@feral.com
#
-CFLAGS+= -I/usr/include/cam/scsi -DSESINC="<scsi_ses.h>"
BINDIR?= /usr/sbin
CLEANFILES+= ${MAN}
diff --git a/share/examples/ses/srcs/eltsub.c b/share/examples/ses/srcs/eltsub.c
index 8500fff..9500423 100644
--- a/share/examples/ses/srcs/eltsub.c
+++ b/share/examples/ses/srcs/eltsub.c
@@ -33,10 +33,13 @@
*/
#include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_enc.h>
#include "eltsub.h"
@@ -46,79 +49,82 @@ geteltnm(int type)
static char rbuf[132];
switch (type) {
- case SESTYP_UNSPECIFIED:
+ case ELMTYP_UNSPECIFIED:
sprintf(rbuf, "Unspecified");
break;
- case SESTYP_DEVICE:
- sprintf(rbuf, "Device");
+ case ELMTYP_DEVICE:
+ sprintf(rbuf, "Device Slot");
break;
- case SESTYP_POWER:
- sprintf(rbuf, "Power supply");
+ case ELMTYP_POWER:
+ sprintf(rbuf, "Power Supply");
break;
- case SESTYP_FAN:
- sprintf(rbuf, "Cooling element");
+ case ELMTYP_FAN:
+ sprintf(rbuf, "Cooling");
break;
- case SESTYP_THERM:
- sprintf(rbuf, "Temperature sensors");
+ case ELMTYP_THERM:
+ sprintf(rbuf, "Temperature Sensors");
break;
- case SESTYP_DOORLOCK:
+ case ELMTYP_DOORLOCK:
sprintf(rbuf, "Door Lock");
break;
- case SESTYP_ALARM:
+ case ELMTYP_ALARM:
sprintf(rbuf, "Audible alarm");
break;
- case SESTYP_ESCC:
- sprintf(rbuf, "Enclosure services controller electronics");
+ case ELMTYP_ESCC:
+ sprintf(rbuf, "Enclosure Eervices Controller Electronics");
break;
- case SESTYP_SCC:
- sprintf(rbuf, "SCC controller electronics");
+ case ELMTYP_SCC:
+ sprintf(rbuf, "SCC Controller Electronics");
break;
- case SESTYP_NVRAM:
- sprintf(rbuf, "Nonvolatile cache");
+ case ELMTYP_NVRAM:
+ sprintf(rbuf, "Nonvolatile Cache");
break;
- case SESTYP_UPS:
- sprintf(rbuf, "Uninterruptible power supply");
+ case ELMTYP_INV_OP_REASON:
+ sprintf(rbuf, "Invalid Operation Reason");
break;
- case SESTYP_DISPLAY:
+ case ELMTYP_UPS:
+ sprintf(rbuf, "Uninterruptible Power Supply");
+ break;
+ case ELMTYP_DISPLAY:
sprintf(rbuf, "Display");
break;
- case SESTYP_KEYPAD:
- sprintf(rbuf, "Key pad entry device");
+ case ELMTYP_KEYPAD:
+ sprintf(rbuf, "Key Pad Entry");
break;
- case SESTYP_ENCLOSURE:
+ case ELMTYP_ENCLOSURE:
sprintf(rbuf, "Enclosure");
break;
- case SESTYP_SCSIXVR:
- sprintf(rbuf, "SCSI port/transceiver");
+ case ELMTYP_SCSIXVR:
+ sprintf(rbuf, "SCSI Port/Transceiver");
break;
- case SESTYP_LANGUAGE:
+ case ELMTYP_LANGUAGE:
sprintf(rbuf, "Language");
break;
- case SESTYP_COMPORT:
+ case ELMTYP_COMPORT:
sprintf(rbuf, "Communication Port");
break;
- case SESTYP_VOM:
+ case ELMTYP_VOM:
sprintf(rbuf, "Voltage Sensor");
break;
- case SESTYP_AMMETER:
+ case ELMTYP_AMMETER:
sprintf(rbuf, "Current Sensor");
break;
- case SESTYP_SCSI_TGT:
- sprintf(rbuf, "SCSI target port");
+ case ELMTYP_SCSI_TGT:
+ sprintf(rbuf, "SCSI Target Port");
break;
- case SESTYP_SCSI_INI:
- sprintf(rbuf, "SCSI initiator port");
+ case ELMTYP_SCSI_INI:
+ sprintf(rbuf, "SCSI Initiator Port");
break;
- case SESTYP_SUBENC:
- sprintf(rbuf, "Simple sub-enclosure");
+ case ELMTYP_SUBENC:
+ sprintf(rbuf, "Simple Subenclosure");
break;
- case SESTYP_ARRAY:
- sprintf(rbuf, "Array device");
+ case ELMTYP_ARRAY_DEV:
+ sprintf(rbuf, "Array Device Slot");
break;
- case SESTYP_SASEXPANDER:
+ case ELMTYP_SAS_EXP:
sprintf(rbuf, "SAS Expander");
break;
- case SESTYP_SASCONNECTOR:
+ case ELMTYP_SAS_CONN:
sprintf(rbuf, "SAS Connector");
break;
default:
@@ -134,31 +140,34 @@ scode2ascii(u_char code)
static char rbuf[32];
switch (code & 0xf) {
case SES_OBJSTAT_UNSUPPORTED:
- sprintf(rbuf, "status not supported");
+ sprintf(rbuf, "Unsupported");
break;
case SES_OBJSTAT_OK:
- sprintf(rbuf, "ok");
+ sprintf(rbuf, "OK");
break;
case SES_OBJSTAT_CRIT:
- sprintf(rbuf, "critical");
+ sprintf(rbuf, "Critical");
break;
case SES_OBJSTAT_NONCRIT:
- sprintf(rbuf, "non-critical");
+ sprintf(rbuf, "Noncritical");
break;
case SES_OBJSTAT_UNRECOV:
- sprintf(rbuf, "unrecoverable");
+ sprintf(rbuf, "Unrecoverable");
break;
case SES_OBJSTAT_NOTINSTALLED:
- sprintf(rbuf, "not installed");
+ sprintf(rbuf, "Not Installed");
break;
case SES_OBJSTAT_UNKNOWN:
- sprintf(rbuf, "unknown status");
+ sprintf(rbuf, "Unknown");
break;
case SES_OBJSTAT_NOTAVAIL:
- sprintf(rbuf, "status not available");
+ sprintf(rbuf, "Not Available");
+ break;
+ case SES_OBJSTAT_NOACCESS:
+ sprintf(rbuf, "No Access Allowed");
break;
default:
- sprintf(rbuf, "unknown status code %x", code & 0xf);
+ sprintf(rbuf, "<Status 0x%x>", code & 0xf);
break;
}
return (rbuf);
@@ -171,7 +180,7 @@ stat2ascii(int eletype __unused, u_char *cstat)
static char ebuf[256], *scode;
scode = scode2ascii(cstat[0]);
- sprintf(ebuf, "Status=%s (bytes=0x%02x 0x%02x 0x%02x 0x%02x)",
+ sprintf(ebuf, "status: %s (0x%02x 0x%02x 0x%02x 0x%02x)",
scode, cstat[0], cstat[1], cstat[2], cstat[3]);
return (ebuf);
}
diff --git a/share/examples/ses/srcs/getencstat.c b/share/examples/ses/srcs/getencstat.c
index 3514fe4..9048f73 100644
--- a/share/examples/ses/srcs/getencstat.c
+++ b/share/examples/ses/srcs/getencstat.c
@@ -33,20 +33,25 @@
*/
#include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <fcntl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_enc.h>
#include "eltsub.h"
int
main(int a, char **v)
{
- ses_object *objp;
- ses_objstat ob;
+ encioc_element_t *objp;
+ encioc_elm_status_t ob;
+ encioc_elm_desc_t objd;
+ encioc_elm_devnames_t objdn;
int fd, nobj, f, i, verbose, quiet, errors;
u_char estat;
@@ -73,13 +78,13 @@ main(int a, char **v)
perror(*v);
continue;
}
- if (ioctl(fd, SESIOC_GETNOBJ, (caddr_t) &nobj) < 0) {
- perror("SESIOC_GETNOBJ");
+ if (ioctl(fd, ENCIOC_GETNELM, (caddr_t) &nobj) < 0) {
+ perror("ENCIOC_GETNELM");
(void) close(fd);
continue;
}
- if (ioctl(fd, SESIOC_GETENCSTAT, (caddr_t) &estat) < 0) {
- perror("SESIOC_GETENCSTAT");
+ if (ioctl(fd, ENCIOC_GETENCSTAT, (caddr_t) &estat) < 0) {
+ perror("ENCIOC_GETENCSTAT");
(void) close(fd);
continue;
}
@@ -113,38 +118,64 @@ main(int a, char **v)
}
}
fprintf(stdout, ">\n");
- objp = calloc(nobj, sizeof (ses_object));
+ objp = calloc(nobj, sizeof (encioc_element_t));
if (objp == NULL) {
perror("calloc");
(void) close(fd);
continue;
}
- if (ioctl(fd, SESIOC_GETOBJMAP, (caddr_t) objp) < 0) {
- perror("SESIOC_GETOBJMAP");
+ if (ioctl(fd, ENCIOC_GETELMMAP, (caddr_t) objp) < 0) {
+ perror("ENCIOC_GETELMMAP");
(void) close(fd);
continue;
}
for (i = 0; i < nobj; i++) {
- ob.obj_id = objp[i].obj_id;
- if (ioctl(fd, SESIOC_GETOBJSTAT, (caddr_t) &ob) < 0) {
- perror("SESIOC_GETOBJSTAT");
+ ob.elm_idx = objp[i].elm_idx;
+ if (ioctl(fd, ENCIOC_GETELMSTAT, (caddr_t) &ob) < 0) {
+ perror("ENCIOC_GETELMSTAT");
(void) close(fd);
break;
}
- if ((ob.cstat[0] & 0xf) == SES_OBJSTAT_OK) {
- if (verbose) {
- fprintf(stdout,
- "Element 0x%x: %s OK (%s)\n",
- ob.obj_id,
- geteltnm(objp[i].object_type),
- stat2ascii(objp[i].object_type,
- ob.cstat));
- }
+ bzero(&objd, sizeof(objd));
+ objd.elm_idx = objp[i].elm_idx;
+ objd.elm_desc_len = UINT16_MAX;
+ objd.elm_desc_str = calloc(UINT16_MAX, sizeof(char));
+ if (objd.elm_desc_str == NULL) {
+ perror("calloc");
+ (void) close(fd);
continue;
}
- fprintf(stdout, "Element 0x%x: %s, %s\n",
- ob.obj_id, geteltnm(objp[i].object_type),
- stat2ascii(objp[i].object_type, ob.cstat));
+ if (ioctl(fd, ENCIOC_GETELMDESC, (caddr_t)&objd) < 0) {
+ perror("ENCIOC_GETELMDESC");
+ (void) close(fd);
+ break;
+ }
+ bzero(&objdn, sizeof(objdn));
+ objdn.elm_idx = objp[i].elm_idx;
+ objdn.elm_names_size = 128;
+ objdn.elm_devnames = calloc(128, sizeof(char));
+ if (objdn.elm_devnames == NULL) {
+ perror("calloc");
+ (void) close(fd);
+ break;
+ }
+ /*
+ * This ioctl isn't critical and has a good chance
+ * of returning -1.
+ */
+ (void)ioctl(fd, ENCIOC_GETELMDEVNAMES, (caddr_t)&objdn);
+ fprintf(stdout, "Element 0x%x: %s", ob.elm_idx,
+ geteltnm(objp[i].elm_type));
+ fprintf(stdout, ", %s",
+ stat2ascii(objp[i].elm_type, ob.cstat));
+ if (objd.elm_desc_len > 0)
+ fprintf(stdout, ", descriptor: '%s'",
+ objd.elm_desc_str);
+ if (objdn.elm_names_len > 0)
+ fprintf(stdout, ", dev: '%s'",
+ objdn.elm_devnames);
+ fprintf(stdout, "\n");
+ free(objdn.elm_devnames);
}
free(objp);
(void) close(fd);
diff --git a/share/examples/ses/srcs/getnobj.c b/share/examples/ses/srcs/getnobj.c
index 17a26c6..92d3458 100644
--- a/share/examples/ses/srcs/getnobj.c
+++ b/share/examples/ses/srcs/getnobj.c
@@ -33,12 +33,15 @@
*/
#include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_ses.h>
int
main(int argc, char **argv)
diff --git a/share/examples/ses/srcs/getobjmap.c b/share/examples/ses/srcs/getobjmap.c
index 9798b4c..fbcc12e 100644
--- a/share/examples/ses/srcs/getobjmap.c
+++ b/share/examples/ses/srcs/getobjmap.c
@@ -33,11 +33,14 @@
*/
#include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_ses.h>
#include "eltsub.h"
diff --git a/share/examples/ses/srcs/getobjstat.c b/share/examples/ses/srcs/getobjstat.c
index 99fb185..d49f6f9 100644
--- a/share/examples/ses/srcs/getobjstat.c
+++ b/share/examples/ses/srcs/getobjstat.c
@@ -32,11 +32,14 @@
* mjacob@feral.com
*/
#include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_ses.h>
int
main(int a, char **v)
diff --git a/share/examples/ses/srcs/inienc.c b/share/examples/ses/srcs/inienc.c
index 7d6cc22..f418787 100644
--- a/share/examples/ses/srcs/inienc.c
+++ b/share/examples/ses/srcs/inienc.c
@@ -33,11 +33,14 @@
*/
#include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_ses.h>
int
main(int a, char **v)
diff --git a/share/examples/ses/srcs/sesd.c b/share/examples/ses/srcs/sesd.c
index 0793077..88627e9 100644
--- a/share/examples/ses/srcs/sesd.c
+++ b/share/examples/ses/srcs/sesd.c
@@ -32,6 +32,8 @@
* mjacob@feral.com
*/
#include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
@@ -39,7 +41,8 @@
#include <string.h>
#include <syslog.h>
#include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_enc.h>
#define ALLSTAT (SES_ENCSTAT_UNRECOV | SES_ENCSTAT_CRITICAL | \
SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
@@ -54,7 +57,7 @@ main(int a, char **v)
static const char *usage =
"usage: %s [ -d ] [ -t pollinterval ] device [ device ]\n";
int fd, polltime, dev, devbase, nodaemon;
- ses_encstat stat, *carray;
+ encioc_enc_status_t stat, *carray;
if (a < 2) {
fprintf(stderr, usage, *v);
@@ -83,7 +86,7 @@ main(int a, char **v)
return (1);
}
for (dev = devbase; dev < a; dev++)
- carray[dev] = (ses_encstat) -1;
+ carray[dev] = (encioc_enc_status_t) -1;
/*
* Check to make sure we can open all devices
@@ -94,8 +97,8 @@ main(int a, char **v)
perror(v[dev]);
return (1);
}
- if (ioctl(fd, SESIOC_INIT, NULL) < 0) {
- fprintf(stderr, "%s: SESIOC_INIT fails- %s\n",
+ if (ioctl(fd, ENCIOC_INIT, NULL) < 0) {
+ fprintf(stderr, "%s: ENCIOC_INIT fails- %s\n",
v[dev], strerror(errno));
return (1);
}
@@ -122,9 +125,9 @@ main(int a, char **v)
/*
* Get the actual current enclosure status.
*/
- if (ioctl(fd, SESIOC_GETENCSTAT, (caddr_t) &stat) < 0) {
+ if (ioctl(fd, ENCIOC_GETENCSTAT, (caddr_t) &stat) < 0) {
syslog(LOG_ERR,
- "%s: SESIOC_GETENCSTAT- %m", v[dev]);
+ "%s: ENCIOC_GETENCSTAT- %m", v[dev]);
(void) close(fd);
continue;
}
diff --git a/share/examples/ses/srcs/setencstat.c b/share/examples/ses/srcs/setencstat.c
index 127f68f..87a7fa2 100644
--- a/share/examples/ses/srcs/setencstat.c
+++ b/share/examples/ses/srcs/setencstat.c
@@ -33,18 +33,21 @@
*/
#include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_enc.h>
int
main(int a, char **v)
{
int fd;
long val;
- ses_encstat stat;
+ encioc_enc_status_t stat;
if (a != 3) {
fprintf(stderr, "usage: %s device enclosure_status\n", *v);
@@ -57,9 +60,9 @@ main(int a, char **v)
}
val = strtol(v[2], NULL, 0);
- stat = (ses_encstat) val;
- if (ioctl(fd, SESIOC_SETENCSTAT, (caddr_t) &stat) < 0) {
- perror("SESIOC_SETENCSTAT");
+ stat = (encioc_enc_status_t)val;
+ if (ioctl(fd, ENCIOC_SETENCSTAT, (caddr_t) &stat) < 0) {
+ perror("ENCIOC_SETENCSTAT");
}
(void) close(fd);
return (0);
diff --git a/share/examples/ses/srcs/setobjstat.c b/share/examples/ses/srcs/setobjstat.c
index 08fdb7b..26a5dd1 100644
--- a/share/examples/ses/srcs/setobjstat.c
+++ b/share/examples/ses/srcs/setobjstat.c
@@ -33,18 +33,21 @@
*/
#include <unistd.h>
+#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
-#include SESINC
+#include <cam/scsi/scsi_all.h>
+#include <cam/scsi/scsi_enc.h>
int
main(int a, char **v)
{
int fd;
int i;
- ses_objstat obj;
+ encioc_elm_status_t obj;
long cvt;
char *x;
@@ -64,7 +67,7 @@ usage:
if (x == v[2]) {
goto usage;
}
- obj.obj_id = cvt;
+ obj.elm_idx = cvt;
for (i = 0; i < 4; i++) {
x = v[3 + i];
cvt = strtol(v[3 + i], &x, 0);
@@ -73,8 +76,8 @@ usage:
}
obj.cstat[i] = cvt;
}
- if (ioctl(fd, SESIOC_SETOBJSTAT, (caddr_t) &obj) < 0) {
- perror("SESIOC_SETOBJSTAT");
+ if (ioctl(fd, ENCIOC_SETELMSTAT, (caddr_t) &obj) < 0) {
+ perror("ENCIOC_SETELMSTAT");
}
(void) close(fd);
return (0);
OpenPOWER on IntegriCloud