1*25e8c5aaSvikram /*
2*25e8c5aaSvikram * CDDL HEADER START
3*25e8c5aaSvikram *
4*25e8c5aaSvikram * The contents of this file are subject to the terms of the
5*25e8c5aaSvikram * Common Development and Distribution License (the "License").
6*25e8c5aaSvikram * You may not use this file except in compliance with the License.
7*25e8c5aaSvikram *
8*25e8c5aaSvikram * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*25e8c5aaSvikram * or http://www.opensolaris.org/os/licensing.
10*25e8c5aaSvikram * See the License for the specific language governing permissions
11*25e8c5aaSvikram * and limitations under the License.
12*25e8c5aaSvikram *
13*25e8c5aaSvikram * When distributing Covered Code, include this CDDL HEADER in each
14*25e8c5aaSvikram * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*25e8c5aaSvikram * If applicable, add the following below this CDDL HEADER, with the
16*25e8c5aaSvikram * fields enclosed by brackets "[]" replaced with your own identifying
17*25e8c5aaSvikram * information: Portions Copyright [yyyy] [name of copyright owner]
18*25e8c5aaSvikram *
19*25e8c5aaSvikram * CDDL HEADER END
20*25e8c5aaSvikram */
21*25e8c5aaSvikram /*
22*25e8c5aaSvikram * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23*25e8c5aaSvikram * Use is subject to license terms.
24*25e8c5aaSvikram */
25*25e8c5aaSvikram
26*25e8c5aaSvikram #pragma ident "%Z%%M% %I% %E% SMI"
27*25e8c5aaSvikram
28*25e8c5aaSvikram #include <sys/contract/device.h>
29*25e8c5aaSvikram #include <sys/wait.h>
30*25e8c5aaSvikram #include <sys/ctfs.h>
31*25e8c5aaSvikram #include <unistd.h>
32*25e8c5aaSvikram #include <fcntl.h>
33*25e8c5aaSvikram #include <errno.h>
34*25e8c5aaSvikram #include <string.h>
35*25e8c5aaSvikram #include <limits.h>
36*25e8c5aaSvikram #include <stdio.h>
37*25e8c5aaSvikram #include <assert.h>
38*25e8c5aaSvikram #include <signal.h>
39*25e8c5aaSvikram #include <libuutil.h>
40*25e8c5aaSvikram #include <libintl.h>
41*25e8c5aaSvikram #include <libcontract.h>
42*25e8c5aaSvikram #include <libcontract_priv.h>
43*25e8c5aaSvikram #include "libcontract_impl.h"
44*25e8c5aaSvikram #include "libcontract_priv.h"
45*25e8c5aaSvikram
46*25e8c5aaSvikram /*ARGSUSED*/
47*25e8c5aaSvikram void
event_device(FILE * file,ct_evthdl_t ev,int verbose)48*25e8c5aaSvikram event_device(FILE *file, ct_evthdl_t ev, int verbose)
49*25e8c5aaSvikram {
50*25e8c5aaSvikram uint_t type;
51*25e8c5aaSvikram char *device;
52*25e8c5aaSvikram char *s;
53*25e8c5aaSvikram ctid_t ctid;
54*25e8c5aaSvikram ct_stathdl_t stathdl;
55*25e8c5aaSvikram int statfd;
56*25e8c5aaSvikram
57*25e8c5aaSvikram type = ct_event_get_type(ev);
58*25e8c5aaSvikram ctid = ct_event_get_ctid(ev);
59*25e8c5aaSvikram
60*25e8c5aaSvikram statfd = contract_open(ctid, "device", "status", O_RDONLY);
61*25e8c5aaSvikram if (statfd == -1) {
62*25e8c5aaSvikram (void) fprintf(file, dgettext(TEXT_DOMAIN, "[bad contract]\n"));
63*25e8c5aaSvikram return;
64*25e8c5aaSvikram }
65*25e8c5aaSvikram
66*25e8c5aaSvikram if (ct_status_read(statfd, CTD_ALL, &stathdl) != 0) {
67*25e8c5aaSvikram (void) fprintf(file, dgettext(TEXT_DOMAIN, "[status error]\n"));
68*25e8c5aaSvikram return;
69*25e8c5aaSvikram }
70*25e8c5aaSvikram
71*25e8c5aaSvikram if (ct_dev_status_get_minor(stathdl, &device) != 0) {
72*25e8c5aaSvikram (void) fprintf(file, dgettext(TEXT_DOMAIN, "[bad status]\n"));
73*25e8c5aaSvikram return;
74*25e8c5aaSvikram }
75*25e8c5aaSvikram
76*25e8c5aaSvikram
77*25e8c5aaSvikram switch (type) {
78*25e8c5aaSvikram case CT_DEV_EV_OFFLINE:
79*25e8c5aaSvikram s = dgettext(TEXT_DOMAIN, "device %s offlining\n");
80*25e8c5aaSvikram break;
81*25e8c5aaSvikram case CT_DEV_EV_DEGRADED:
82*25e8c5aaSvikram s = dgettext(TEXT_DOMAIN, "device %s degrading\n");
83*25e8c5aaSvikram break;
84*25e8c5aaSvikram case CT_DEV_EV_ONLINE:
85*25e8c5aaSvikram s = dgettext(TEXT_DOMAIN, "device %s online\n");
86*25e8c5aaSvikram break;
87*25e8c5aaSvikram case CT_EV_NEGEND:
88*25e8c5aaSvikram contract_negend_dump(file, ev);
89*25e8c5aaSvikram s = NULL;
90*25e8c5aaSvikram break;
91*25e8c5aaSvikram default:
92*25e8c5aaSvikram s = dgettext(TEXT_DOMAIN, "device %s sent an unknown event\n");
93*25e8c5aaSvikram break;
94*25e8c5aaSvikram }
95*25e8c5aaSvikram
96*25e8c5aaSvikram if (s) {
97*25e8c5aaSvikram /*LINTED*/
98*25e8c5aaSvikram (void) fprintf(file, s, device);
99*25e8c5aaSvikram }
100*25e8c5aaSvikram
101*25e8c5aaSvikram ct_status_free(stathdl);
102*25e8c5aaSvikram (void) close(statfd);
103*25e8c5aaSvikram }
104