diff options
Diffstat (limited to 'usr/src/lib/libcontract')
-rw-r--r-- | usr/src/lib/libcontract/Makefile | 8 | ||||
-rw-r--r-- | usr/src/lib/libcontract/Makefile.com | 6 | ||||
-rw-r--r-- | usr/src/lib/libcontract/common/device.c | 177 | ||||
-rw-r--r-- | usr/src/lib/libcontract/common/device_dump.c | 103 | ||||
-rw-r--r-- | usr/src/lib/libcontract/common/device_dump.h | 43 | ||||
-rw-r--r-- | usr/src/lib/libcontract/common/libcontract.c | 31 | ||||
-rw-r--r-- | usr/src/lib/libcontract/common/libcontract.h | 25 | ||||
-rw-r--r-- | usr/src/lib/libcontract/common/libcontract_impl.h | 10 | ||||
-rw-r--r-- | usr/src/lib/libcontract/common/libcontract_priv.c | 32 | ||||
-rw-r--r-- | usr/src/lib/libcontract/common/libcontract_priv.h | 8 | ||||
-rw-r--r-- | usr/src/lib/libcontract/common/mapfile-vers | 14 |
11 files changed, 427 insertions, 30 deletions
diff --git a/usr/src/lib/libcontract/Makefile b/usr/src/lib/libcontract/Makefile index a042993bfc..8d05db4980 100644 --- a/usr/src/lib/libcontract/Makefile +++ b/usr/src/lib/libcontract/Makefile @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -32,7 +32,8 @@ HDRDIR = common SUBDIRS = $(MACH) $(BUILD64)SUBDIRS += $(MACH64) -MSGFILES = common/process_dump.c +MSGFILES = common/process_dump.c common/device_dump.c \ + common/libcontract_priv.c POFILE = libcontract.po all := TARGET = all @@ -45,7 +46,8 @@ lint := TARGET = lint all clean clobber install lint: $(SUBDIRS) -$(POFILE): pofile_MSGFILES +$(POFILE): $(MSGFILES) + $(BUILDPO.msgfiles) install_h: $(ROOTHDRS) diff --git a/usr/src/lib/libcontract/Makefile.com b/usr/src/lib/libcontract/Makefile.com index 7d5ab8b471..050d42944e 100644 --- a/usr/src/lib/libcontract/Makefile.com +++ b/usr/src/lib/libcontract/Makefile.com @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -32,7 +32,9 @@ OBJECTS = \ libcontract.o \ libcontract_priv.o \ process.o \ - process_dump.o + process_dump.o \ + device.o \ + device_dump.o # include library definition include ../../Makefile.lib diff --git a/usr/src/lib/libcontract/common/device.c b/usr/src/lib/libcontract/common/device.c new file mode 100644 index 0000000000..99e9bd1203 --- /dev/null +++ b/usr/src/lib/libcontract/common/device.c @@ -0,0 +1,177 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/ctfs.h> +#include <sys/contract.h> +#include <sys/contract/device.h> +#include <errno.h> +#include <unistd.h> +#include <string.h> +#include <libnvpair.h> +#include <limits.h> +#include <sys/stat.h> +#include <libcontract.h> +#include "libcontract_impl.h" + +/* + * Device contract template routines + */ + +int +ct_dev_tmpl_set_minor(int fd, char *minor) +{ + return (ct_tmpl_set_internal(fd, CTDP_MINOR, (uintptr_t)minor)); +} + +int +ct_dev_tmpl_set_aset(int fd, uint_t aset) +{ + return (ct_tmpl_set_internal(fd, CTDP_ACCEPT, aset)); +} + +int +ct_dev_tmpl_set_noneg(int fd) +{ + return (ct_tmpl_set_internal(fd, CTDP_NONEG, CTDP_NONEG_SET)); +} + +int +ct_dev_tmpl_clear_noneg(int fd) +{ + return (ct_tmpl_set_internal(fd, CTDP_NONEG, CTDP_NONEG_CLEAR)); +} + +int +ct_dev_tmpl_get_minor(int fd, char *buf, size_t *buflenp) +{ + char path[PATH_MAX]; + int error; + size_t len; + + error = ct_tmpl_get_internal_string(fd, CTDP_MINOR, path); + if (error) { + return (error); + } + + len = strlcpy(buf, path, *buflenp); + if (len >= *buflenp) { + *buflenp = len + 1; + return (EOVERFLOW); + } + + return (0); +} + +int +ct_dev_tmpl_get_aset(int fd, uint_t *aset) +{ + return (ct_tmpl_get_internal(fd, CTDP_ACCEPT, aset)); +} + +int +ct_dev_tmpl_get_noneg(int fd, uint_t *negp) +{ + return (ct_tmpl_get_internal(fd, CTDP_NONEG, negp)); +} + +/* + * Device contract event routines + */ + +/* + * No device contract specific event routines + */ + + +/* + * Device contract status routines + */ + +int +ct_dev_status_get_aset(ct_stathdl_t stathdl, uint_t *aset) +{ + struct ctlib_status_info *info = stathdl; + + if (info->status.ctst_type != CTT_DEVICE) + return (EINVAL); + + if (info->nvl == NULL) + return (ENOENT); + + return (nvlist_lookup_uint32(info->nvl, CTDS_ASET, aset)); +} + +int +ct_dev_status_get_noneg(ct_stathdl_t stathdl, uint_t *negp) +{ + struct ctlib_status_info *info = stathdl; + + if (info->status.ctst_type != CTT_DEVICE) + return (EINVAL); + + if (info->nvl == NULL) + return (ENOENT); + + return (nvlist_lookup_uint32(info->nvl, CTDS_NONEG, negp)); +} + +int +ct_dev_status_get_dev_state(ct_stathdl_t stathdl, uint_t *statep) +{ + struct ctlib_status_info *info = stathdl; + + if (info->status.ctst_type != CTT_DEVICE) + return (EINVAL); + + if (info->nvl == NULL) + return (ENOENT); + + return (nvlist_lookup_uint32(info->nvl, CTDS_STATE, statep)); +} + +int +ct_dev_status_get_minor(ct_stathdl_t stathdl, char **bufp) +{ + int error; + struct ctlib_status_info *info = stathdl; + + if (bufp == NULL) + return (EINVAL); + + if (info->status.ctst_type != CTT_DEVICE) + return (EINVAL); + + if (info->nvl == NULL) + return (ENOENT); + + error = nvlist_lookup_string(info->nvl, CTDS_MINOR, bufp); + if (error != 0) { + return (error); + } + + return (0); +} diff --git a/usr/src/lib/libcontract/common/device_dump.c b/usr/src/lib/libcontract/common/device_dump.c new file mode 100644 index 0000000000..fb6d45cf10 --- /dev/null +++ b/usr/src/lib/libcontract/common/device_dump.c @@ -0,0 +1,103 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/contract/device.h> +#include <sys/wait.h> +#include <sys/ctfs.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> +#include <limits.h> +#include <stdio.h> +#include <assert.h> +#include <signal.h> +#include <libuutil.h> +#include <libintl.h> +#include <libcontract.h> +#include <libcontract_priv.h> +#include "libcontract_impl.h" +#include "libcontract_priv.h" + +/*ARGSUSED*/ +void +event_device(FILE *file, ct_evthdl_t ev, int verbose) +{ + uint_t type; + char *device; + char *s; + ctid_t ctid; + ct_stathdl_t stathdl; + int statfd; + + type = ct_event_get_type(ev); + ctid = ct_event_get_ctid(ev); + + statfd = contract_open(ctid, "device", "status", O_RDONLY); + if (statfd == -1) { + (void) fprintf(file, dgettext(TEXT_DOMAIN, "[bad contract]\n")); + return; + } + + if (ct_status_read(statfd, CTD_ALL, &stathdl) != 0) { + (void) fprintf(file, dgettext(TEXT_DOMAIN, "[status error]\n")); + return; + } + + if (ct_dev_status_get_minor(stathdl, &device) != 0) { + (void) fprintf(file, dgettext(TEXT_DOMAIN, "[bad status]\n")); + return; + } + + + switch (type) { + case CT_DEV_EV_OFFLINE: + s = dgettext(TEXT_DOMAIN, "device %s offlining\n"); + break; + case CT_DEV_EV_DEGRADED: + s = dgettext(TEXT_DOMAIN, "device %s degrading\n"); + break; + case CT_DEV_EV_ONLINE: + s = dgettext(TEXT_DOMAIN, "device %s online\n"); + break; + case CT_EV_NEGEND: + contract_negend_dump(file, ev); + s = NULL; + break; + default: + s = dgettext(TEXT_DOMAIN, "device %s sent an unknown event\n"); + break; + } + + if (s) { + /*LINTED*/ + (void) fprintf(file, s, device); + } + + ct_status_free(stathdl); + (void) close(statfd); +} diff --git a/usr/src/lib/libcontract/common/device_dump.h b/usr/src/lib/libcontract/common/device_dump.h new file mode 100644 index 0000000000..8c90400a52 --- /dev/null +++ b/usr/src/lib/libcontract/common/device_dump.h @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _DEVICE_DUMP_H +#define _DEVICE_DUMP_H + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "libcontract_impl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern void event_device(FILE *, ct_evthdl_t, int); + +#ifdef __cplusplus +} +#endif + +#endif /* _DEVICE_DUMP_H */ diff --git a/usr/src/lib/libcontract/common/libcontract.c b/usr/src/lib/libcontract/common/libcontract.c index 7cb35c4cfe..d2739cd1cd 100644 --- a/usr/src/lib/libcontract/common/libcontract.c +++ b/usr/src/lib/libcontract/common/libcontract.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -66,11 +65,11 @@ ct_tmpl_create(int fd, ctid_t *ctidp) } int -ct_tmpl_set_internal(int fd, uint_t id, uint_t value) +ct_tmpl_set_internal(int fd, uint_t id, uintptr_t value) { ct_param_t param; param.ctpm_id = id; - param.ctpm_value = value; + param.ctpm_value = (uint64_t)value; if (ioctl(fd, CT_TSET, ¶m) == -1) return (errno); return (0); @@ -112,6 +111,18 @@ ct_tmpl_get_internal(int fd, uint_t id, uint_t *value) } int +ct_tmpl_get_internal_string(int fd, uint_t id, char *value) +{ + ct_param_t param; + + param.ctpm_id = id; + param.ctpm_value = (uint64_t)(uintptr_t)value; + if (ioctl(fd, CT_TGET, ¶m) == -1) + return (errno); + return (0); +} + +int ct_tmpl_get_critical(int fd, uint_t *events) { return (ct_tmpl_get_internal(fd, CTP_EV_CRITICAL, events)); @@ -173,6 +184,14 @@ ct_ctl_ack(int fd, ctevid_t event) } int +ct_ctl_nack(int fd, ctevid_t event) +{ + if (ioctl(fd, CT_CNACK, &event) == -1) + return (errno); + return (0); +} + +int ct_ctl_qack(int fd, ctevid_t event) { if (ioctl(fd, CT_CQREQ, &event) == -1) diff --git a/usr/src/lib/libcontract/common/libcontract.h b/usr/src/lib/libcontract/common/libcontract.h index 98092b7db0..27453e5c83 100644 --- a/usr/src/lib/libcontract/common/libcontract.h +++ b/usr/src/lib/libcontract/common/libcontract.h @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -55,6 +54,7 @@ extern int ct_tmpl_get_informative(int, uint_t *); extern int ct_ctl_adopt(int); extern int ct_ctl_abandon(int); extern int ct_ctl_ack(int, ctevid_t); +extern int ct_ctl_nack(int, ctevid_t); extern int ct_ctl_qack(int, ctevid_t); extern int ct_ctl_newct(int, ctevid_t, int); @@ -113,6 +113,23 @@ extern int ct_pr_status_get_fatal(ct_stathdl_t, uint_t *); extern int ct_pr_status_get_members(ct_stathdl_t, pid_t **, uint_t *); extern int ct_pr_status_get_contracts(ct_stathdl_t, ctid_t **, uint_t *); +/* + * Device contract routines + */ +int ct_dev_tmpl_set_minor(int, char *); +int ct_dev_tmpl_set_aset(int, uint_t); +int ct_dev_tmpl_set_noneg(int); +int ct_dev_tmpl_clear_noneg(int); +int ct_dev_tmpl_get_minor(int, char *, size_t *); +int ct_dev_tmpl_get_aset(int, uint_t *); +int ct_dev_tmpl_get_noneg(int, uint_t *); +int ct_dev_status_get_aset(ct_stathdl_t, uint_t *); +int ct_dev_status_get_noneg(ct_stathdl_t, uint_t *); +int ct_dev_status_get_dev_state(ct_stathdl_t, uint_t *); +int ct_dev_status_get_minor(ct_stathdl_t, char **); + + + #ifdef __cplusplus } #endif diff --git a/usr/src/lib/libcontract/common/libcontract_impl.h b/usr/src/lib/libcontract/common/libcontract_impl.h index d8504cb5cf..ad50cd3dcc 100644 --- a/usr/src/lib/libcontract/common/libcontract_impl.h +++ b/usr/src/lib/libcontract/common/libcontract_impl.h @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -48,8 +47,9 @@ struct ctlib_event_info { nvlist_t *nvl; }; -extern int ct_tmpl_set_internal(int, uint_t, uint_t); +extern int ct_tmpl_set_internal(int, uint_t, uintptr_t); extern int ct_tmpl_get_internal(int, uint_t, uint_t *); +extern int ct_tmpl_get_internal_string(int, uint_t, char *); typedef struct contract_type { const char *type_name; diff --git a/usr/src/lib/libcontract/common/libcontract_priv.c b/usr/src/lib/libcontract/common/libcontract_priv.c index 1db8ea2d95..d74e8409c6 100644 --- a/usr/src/lib/libcontract/common/libcontract_priv.c +++ b/usr/src/lib/libcontract/common/libcontract_priv.c @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -34,16 +33,19 @@ #include <stdio.h> #include <assert.h> #include <libuutil.h> +#include <libintl.h> #include <string.h> #include <procfs.h> #include <libcontract.h> #include <libcontract_priv.h> #include "libcontract_impl.h" #include "process_dump.h" +#include "device_dump.h" contract_type_t types[CTT_MAXTYPE] = { - { "process", event_process } + { "process", event_process }, + { "device", event_device } }; static int @@ -147,3 +149,23 @@ contract_event_dump(FILE *file, ct_evthdl_t hdl, int verbose) type = info->event.ctev_cttype; types[type].type_event(file, hdl, verbose); } + +void +contract_negend_dump(FILE *file, ct_evthdl_t ev) +{ + ctevid_t nevid = 0; + ctid_t my_ctid = ct_event_get_ctid(ev); + ctid_t new_ctid = 0; + char *s; + + (void) ct_event_get_nevid(ev, &nevid); + (void) ct_event_get_newct(ev, &new_ctid); + + if (new_ctid != my_ctid) { + s = dgettext(TEXT_DOMAIN, "negotiation %llu succeeded\n"); + } else { + s = dgettext(TEXT_DOMAIN, "negotiation %llu failed\n"); + } + /*LINTED*/ + (void) fprintf(file, s, (unsigned long long)nevid); +} diff --git a/usr/src/lib/libcontract/common/libcontract_priv.h b/usr/src/lib/libcontract/common/libcontract_priv.h index a1069efb35..639f190aff 100644 --- a/usr/src/lib/libcontract/common/libcontract_priv.h +++ b/usr/src/lib/libcontract/common/libcontract_priv.h @@ -2,9 +2,8 @@ * CDDL HEADER START * * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. @@ -20,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -42,6 +41,7 @@ extern int contract_open(ctid_t, const char *, const char *, int); extern int contract_abandon_id(ctid_t); extern ctid_t getctid(void); extern void contract_event_dump(FILE *, ct_evthdl_t, int); +extern void contract_negend_dump(FILE *, ct_evthdl_t); #ifdef __cplusplus } diff --git a/usr/src/lib/libcontract/common/mapfile-vers b/usr/src/lib/libcontract/common/mapfile-vers index 2f220b60ad..a64cbfd047 100644 --- a/usr/src/lib/libcontract/common/mapfile-vers +++ b/usr/src/lib/libcontract/common/mapfile-vers @@ -19,7 +19,7 @@ # CDDL HEADER END # # -# Copyright 2006 Sun Microsystems, Inc. All rights reserved. +# Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "%Z%%M% %I% %E% SMI" @@ -29,6 +29,7 @@ SUNW_1.1 { global: ct_ctl_abandon; ct_ctl_ack; + ct_ctl_nack; ct_ctl_adopt; ct_ctl_newct; ct_ctl_qack; @@ -85,6 +86,17 @@ SUNW_1.1 { ct_tmpl_set_cookie; ct_tmpl_set_critical; ct_tmpl_set_informative; + ct_dev_tmpl_set_minor; + ct_dev_tmpl_set_aset; + ct_dev_tmpl_set_noneg; + ct_dev_tmpl_clear_noneg; + ct_dev_tmpl_get_minor; + ct_dev_tmpl_get_aset; + ct_dev_tmpl_get_noneg; + ct_dev_status_get_aset; + ct_dev_status_get_noneg; + ct_dev_status_get_dev_state; + ct_dev_status_get_minor; }; SUNWprivate_1.1 { |