17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
525e8c5aaSvikram  * Common Development and Distribution License (the "License").
625e8c5aaSvikram  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
227b209c2cSacruz  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_CONTRACT_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_SYS_CONTRACT_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/list.h>
317c478bd9Sstevel@tonic-gate #include <sys/poll.h>
327c478bd9Sstevel@tonic-gate #include <sys/condvar.h>
337c478bd9Sstevel@tonic-gate #include <sys/contract.h>
347c478bd9Sstevel@tonic-gate #include <sys/model.h>
357c478bd9Sstevel@tonic-gate #include <sys/cred.h>
367c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
377c478bd9Sstevel@tonic-gate #include <sys/list.h>
387c478bd9Sstevel@tonic-gate #include <sys/avl.h>
397c478bd9Sstevel@tonic-gate #include <sys/nvpair.h>
407c478bd9Sstevel@tonic-gate #include <sys/time.h>
417c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
427c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
437c478bd9Sstevel@tonic-gate #include <sys/zone.h>
447c478bd9Sstevel@tonic-gate #include <sys/project.h>
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
477c478bd9Sstevel@tonic-gate extern "C" {
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate 
5025e8c5aaSvikram extern int ct_debug;
5125e8c5aaSvikram 
5225e8c5aaSvikram #define	CT_DEBUG(args)	if (ct_debug) cmn_err args
5325e8c5aaSvikram 
547c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577b209c2cSacruz  * 32-bit versions of the event, status and parameter structures, for use
587b209c2cSacruz  * (only) by the 64-bit kernel.  See sys/contract.h for the normal versions.
597c478bd9Sstevel@tonic-gate  * Use pack(4) to get offsets and structure size correct on amd64.
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
637c478bd9Sstevel@tonic-gate #pragma pack(4)
647c478bd9Sstevel@tonic-gate #endif
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate typedef struct ct_event32 {
677c478bd9Sstevel@tonic-gate 	ctid_t	ctev_id;
687c478bd9Sstevel@tonic-gate 	uint32_t ctev_pad1;
697c478bd9Sstevel@tonic-gate 	ctevid_t ctev_evid;
707c478bd9Sstevel@tonic-gate 	ct_typeid_t ctev_cttype;
717c478bd9Sstevel@tonic-gate 	uint32_t ctev_flags;
727c478bd9Sstevel@tonic-gate 	uint32_t ctev_type;
737c478bd9Sstevel@tonic-gate 	uint32_t ctev_nbytes;
747c478bd9Sstevel@tonic-gate 	uint32_t ctev_goffset;
757c478bd9Sstevel@tonic-gate 	uint32_t ctev_pad2;
767c478bd9Sstevel@tonic-gate 	caddr32_t ctev_buffer;
777c478bd9Sstevel@tonic-gate } ct_event32_t;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate typedef struct ct_status32 {
807c478bd9Sstevel@tonic-gate 	ctid_t	ctst_id;
817c478bd9Sstevel@tonic-gate 	zoneid_t ctst_zoneid;
827c478bd9Sstevel@tonic-gate 	ct_typeid_t ctst_type;
837c478bd9Sstevel@tonic-gate 	pid_t	ctst_holder;
847c478bd9Sstevel@tonic-gate 	ctstate_t ctst_state;
857c478bd9Sstevel@tonic-gate 	int	ctst_nevents;
867c478bd9Sstevel@tonic-gate 	int	ctst_ntime;
877c478bd9Sstevel@tonic-gate 	int	ctst_qtime;
887c478bd9Sstevel@tonic-gate 	uint64_t ctst_nevid;
897c478bd9Sstevel@tonic-gate 	uint_t	ctst_detail;
907c478bd9Sstevel@tonic-gate 	uint_t	ctst_nbytes;
917c478bd9Sstevel@tonic-gate 	uint_t	ctst_critical;
927c478bd9Sstevel@tonic-gate 	uint_t	ctst_informative;
937c478bd9Sstevel@tonic-gate 	uint64_t ctst_cookie;
947c478bd9Sstevel@tonic-gate 	caddr32_t ctst_buffer;
957c478bd9Sstevel@tonic-gate } ct_status32_t;
967c478bd9Sstevel@tonic-gate 
977b209c2cSacruz typedef struct ct_param32 {
987b209c2cSacruz 	uint32_t  ctpm_id;
997b209c2cSacruz 	uint32_t  ctpm_size;
1007b209c2cSacruz 	caddr32_t ctpm_value;
1017b209c2cSacruz } ct_param32_t;
1027b209c2cSacruz 
1037c478bd9Sstevel@tonic-gate #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
1047c478bd9Sstevel@tonic-gate #pragma pack()
1057c478bd9Sstevel@tonic-gate #endif
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */
1087c478bd9Sstevel@tonic-gate 
109*c5a9a4fcSAntonello Cruz /*
110*c5a9a4fcSAntonello Cruz  * in kernel version of parameter structure.
111*c5a9a4fcSAntonello Cruz  */
112*c5a9a4fcSAntonello Cruz typedef struct ct_kparam {
113*c5a9a4fcSAntonello Cruz 	ct_param_t	param;		/* copy of user ct_param_t */
114*c5a9a4fcSAntonello Cruz 	void		*ctpm_kbuf;	/* kernel buffer for parameter value */
115*c5a9a4fcSAntonello Cruz 	uint32_t	ret_size;	/* parameter value size for copyout */
116*c5a9a4fcSAntonello Cruz } ct_kparam_t;
117*c5a9a4fcSAntonello Cruz 
1187c478bd9Sstevel@tonic-gate struct proc;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * Contract template ops vector
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate typedef struct ctmplops {
1247c478bd9Sstevel@tonic-gate 	struct ct_template	*(*ctop_dup)(struct ct_template *);
1257c478bd9Sstevel@tonic-gate 	void		(*ctop_free)(struct ct_template *);
126*c5a9a4fcSAntonello Cruz 	int		(*ctop_set)(struct ct_template *, ct_kparam_t *,
1277c478bd9Sstevel@tonic-gate 			const cred_t *);
128*c5a9a4fcSAntonello Cruz 	int		(*ctop_get)(struct ct_template *, ct_kparam_t *);
12925e8c5aaSvikram 	int		(*ctop_create)(struct ct_template *, ctid_t *);
1307c478bd9Sstevel@tonic-gate 	uint_t		allevents;
1317c478bd9Sstevel@tonic-gate } ctmplops_t;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * Contract template
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate typedef struct ct_template {
1377c478bd9Sstevel@tonic-gate 	kmutex_t	ctmpl_lock;
1387c478bd9Sstevel@tonic-gate 	ctmplops_t	*ctmpl_ops;
1397c478bd9Sstevel@tonic-gate 	struct ct_type	*ctmpl_type;
1407c478bd9Sstevel@tonic-gate 	void		*ctmpl_data;
1417c478bd9Sstevel@tonic-gate 	uint64_t	ctmpl_cookie;	/* term: contract cookie */
1427c478bd9Sstevel@tonic-gate 	uint_t		ctmpl_ev_crit;	/* term: critical events */
1437c478bd9Sstevel@tonic-gate 	uint_t		ctmpl_ev_info;	/* term: informative events */
1447c478bd9Sstevel@tonic-gate } ct_template_t;
1457c478bd9Sstevel@tonic-gate 
14625e8c5aaSvikram 
1477c478bd9Sstevel@tonic-gate typedef enum ct_listnum {
1487c478bd9Sstevel@tonic-gate 	CTEL_CONTRACT,			/* ../contracts/type/<id>/events */
1497c478bd9Sstevel@tonic-gate 	CTEL_BUNDLE,			/* ../contracts/type/bundle */
1507c478bd9Sstevel@tonic-gate 	CTEL_PBUNDLE,			/* ../contracts/type/pbundle */
1517c478bd9Sstevel@tonic-gate 	CTEL_MAX
1527c478bd9Sstevel@tonic-gate } ct_listnum_t;
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate typedef enum ctqflags {
1557c478bd9Sstevel@tonic-gate 	CTQ_DEAD = 1,	/* contract explicitly cancelled */
1567c478bd9Sstevel@tonic-gate 	CTQ_REFFED = 2	/* queue is reference counted */
1577c478bd9Sstevel@tonic-gate } ctqflags_t;
1587c478bd9Sstevel@tonic-gate 
15925e8c5aaSvikram typedef enum ct_ack {
16025e8c5aaSvikram 	CT_ACK = 1,	/* accept break */
16125e8c5aaSvikram 	CT_NACK,	/* disallow break */
16225e8c5aaSvikram 	CT_NONE		/* no matching contracts */
16325e8c5aaSvikram } ct_ack_t;
16425e8c5aaSvikram 
1657c478bd9Sstevel@tonic-gate /*
1667c478bd9Sstevel@tonic-gate  * Contract event queue
1677c478bd9Sstevel@tonic-gate  */
1687c478bd9Sstevel@tonic-gate typedef struct ct_equeue {
1697c478bd9Sstevel@tonic-gate 	kmutex_t ctq_lock;
1707c478bd9Sstevel@tonic-gate 	timespec_t ctq_atime;		/* access time */
1717c478bd9Sstevel@tonic-gate 	ct_listnum_t ctq_listno;	/* which list node */
1727c478bd9Sstevel@tonic-gate 	list_t	ctq_events;		/* list of events */
1737c478bd9Sstevel@tonic-gate 	list_t	ctq_listeners;		/* list of all listeners */
1747c478bd9Sstevel@tonic-gate 	list_t	ctq_tail;		/* list of tail listeners */
1757c478bd9Sstevel@tonic-gate 	int	ctq_nlisteners;		/* number of listeners */
1767c478bd9Sstevel@tonic-gate 	int	ctq_nreliable;		/* number of reliable listeners */
1777c478bd9Sstevel@tonic-gate 	int	ctq_ninf;		/* number of informative events */
1787c478bd9Sstevel@tonic-gate 	int	ctq_max;		/* max informative events */
1797c478bd9Sstevel@tonic-gate 	ctqflags_t ctq_flags;		/* queue flags */
1807c478bd9Sstevel@tonic-gate } ct_equeue_t;
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate typedef struct ct_member {
1837c478bd9Sstevel@tonic-gate 	list_node_t	ctm_node;	/* list membership */
1847c478bd9Sstevel@tonic-gate 	int		ctm_refs;	/* number of references per list */
1857c478bd9Sstevel@tonic-gate 	int		ctm_trimmed;	/* membership has been trimmed */
1867c478bd9Sstevel@tonic-gate 	int		ctm_nreliable;	/* reliable listeners */
1877c478bd9Sstevel@tonic-gate } ct_member_t;
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate typedef struct ct_kevent {
1907c478bd9Sstevel@tonic-gate 	kmutex_t	cte_lock;
1917c478bd9Sstevel@tonic-gate 	uint64_t	cte_id;		/* event id */
1927c478bd9Sstevel@tonic-gate 	uint_t		cte_type;	/* event type */
1937c478bd9Sstevel@tonic-gate 	int		cte_refs;
1947c478bd9Sstevel@tonic-gate 	ct_member_t	cte_nodes[CTEL_MAX]; /* event queue membership */
1957c478bd9Sstevel@tonic-gate 	int		cte_flags;	/* see above */
1967c478bd9Sstevel@tonic-gate 	nvlist_t 	*cte_data;	/* event data */
1977c478bd9Sstevel@tonic-gate 	nvlist_t 	*cte_gdata;	/* global-zone only data */
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	struct contract	*cte_contract;	/* contract */
2007c478bd9Sstevel@tonic-gate } ct_kevent_t;
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate /*
2037c478bd9Sstevel@tonic-gate  * Contract vnode linkage.
2047c478bd9Sstevel@tonic-gate  * Avoid having too much knowledge about the FS.
2057c478bd9Sstevel@tonic-gate  */
2067c478bd9Sstevel@tonic-gate typedef struct contract_vnode {
2077c478bd9Sstevel@tonic-gate 	list_node_t	ctv_node;
2087c478bd9Sstevel@tonic-gate 	vnode_t		*ctv_vnode;
2097c478bd9Sstevel@tonic-gate } contract_vnode_t;
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate /*
2127c478bd9Sstevel@tonic-gate  * Contract ops vector
2137c478bd9Sstevel@tonic-gate  *   free - when reference count drops to zero
2147c478bd9Sstevel@tonic-gate  *   abandon - when holding process dies or relinquishes interest
2157c478bd9Sstevel@tonic-gate  *   destroy - when contract is to be completely destroyed
2167c478bd9Sstevel@tonic-gate  *   status - when contractfs needs to return detailed status information
2177c478bd9Sstevel@tonic-gate  */
2187c478bd9Sstevel@tonic-gate typedef struct contops {
2197c478bd9Sstevel@tonic-gate 	void	(*contop_free)(struct contract *);
2207c478bd9Sstevel@tonic-gate 	void	(*contop_abandon)(struct contract *);
2217c478bd9Sstevel@tonic-gate 	void	(*contop_destroy)(struct contract *);
2227c478bd9Sstevel@tonic-gate 	void	(*contop_status)(struct contract *, zone_t *, int, nvlist_t *,
2237c478bd9Sstevel@tonic-gate 	    void *, model_t);
22425e8c5aaSvikram 	int	(*contop_ack)(struct contract *, uint_t evtype,
22525e8c5aaSvikram 	    uint64_t evid);
22625e8c5aaSvikram 	int	(*contop_nack)(struct contract *, uint_t evtype,
22725e8c5aaSvikram 	    uint64_t evid);
22825e8c5aaSvikram 	int	(*contop_qack)(struct contract *, uint_t, uint64_t);
22925e8c5aaSvikram 	int	(*contop_newct)(struct contract *);
2307c478bd9Sstevel@tonic-gate } contops_t;
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate typedef ct_template_t *(ct_f_default_t)(void);
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate /*
2357c478bd9Sstevel@tonic-gate  * Contract type information.
2367c478bd9Sstevel@tonic-gate  */
2377c478bd9Sstevel@tonic-gate typedef struct ct_type {
2387c478bd9Sstevel@tonic-gate 	uint64_t	ct_type_evid;	/* last event id */
2397c478bd9Sstevel@tonic-gate 	ct_typeid_t	ct_type_index;	/* index in ct_types array */
2407c478bd9Sstevel@tonic-gate 	const char	*ct_type_name;	/* type as a string */
2417c478bd9Sstevel@tonic-gate 	kmutex_t	ct_type_lock;	/* protects ct_type_avl */
2427c478bd9Sstevel@tonic-gate 	avl_tree_t	ct_type_avl;	/* ordered list of type contracts */
2437c478bd9Sstevel@tonic-gate 	timestruc_t	ct_type_timestruc; /* time last contract was written */
2447c478bd9Sstevel@tonic-gate 	ct_equeue_t	ct_type_events;	/* bundle queue */
2457c478bd9Sstevel@tonic-gate 	contops_t	*ct_type_ops;
2467c478bd9Sstevel@tonic-gate 	ct_f_default_t	*ct_type_default; /* creates a fresh template */
2477c478bd9Sstevel@tonic-gate } ct_type_t;
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate typedef enum ctflags {
2507c478bd9Sstevel@tonic-gate 	CTF_INHERIT = 0x1
2517c478bd9Sstevel@tonic-gate } ctflags_t;
2527c478bd9Sstevel@tonic-gate 
25325e8c5aaSvikram typedef struct ct_time {
25425e8c5aaSvikram 	long	ctm_total;	/* Total time allowed for event */
25525e8c5aaSvikram 	clock_t	ctm_start;	/* starting lbolt for event */
25625e8c5aaSvikram } ct_time_t;
25725e8c5aaSvikram 
2587c478bd9Sstevel@tonic-gate /*
2597c478bd9Sstevel@tonic-gate  * Contract
2607c478bd9Sstevel@tonic-gate  */
2617c478bd9Sstevel@tonic-gate typedef struct contract {
2627c478bd9Sstevel@tonic-gate 	uint64_t	ct_ref;		/* reference count */
2637c478bd9Sstevel@tonic-gate 	kmutex_t	ct_reflock;	/* reference count lock */
2647c478bd9Sstevel@tonic-gate 	kmutex_t	ct_evtlock;	/* event dispatch lock */
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 					/* Static data */
2677c478bd9Sstevel@tonic-gate 	kproject_t	*ct_proj;	/* project of creator */
2687c478bd9Sstevel@tonic-gate 	uid_t		ct_cuid;	/* uid of contract author */
2697c478bd9Sstevel@tonic-gate 	zoneid_t	ct_zoneid;	/* zoneid of creator */
2707c478bd9Sstevel@tonic-gate 	uint64_t	ct_czuniqid;	/* unique id of creator's zone */
2717c478bd9Sstevel@tonic-gate 	timespec_t	ct_ctime;	/* creation time */
2727c478bd9Sstevel@tonic-gate 	ct_type_t	*ct_type;	/* contract type information */
2737c478bd9Sstevel@tonic-gate 	void		*ct_data;	/* contract type data */
2747c478bd9Sstevel@tonic-gate 	ctid_t		ct_id;		/* contract ID */
2757c478bd9Sstevel@tonic-gate 	uint64_t	ct_cookie;	/* term: contract cookie */
2767c478bd9Sstevel@tonic-gate 	uint_t		ct_ev_crit;	/* term: critical events */
2777c478bd9Sstevel@tonic-gate 	uint_t		ct_ev_info;	/* term: informative events */
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 					/* Protected by other locks */
2807c478bd9Sstevel@tonic-gate 	uint64_t	ct_mzuniqid;	/* unique id of members' zone */
2817c478bd9Sstevel@tonic-gate 	avl_node_t	ct_ctavl;	/* avl membership */
2827c478bd9Sstevel@tonic-gate 	avl_node_t	ct_cttavl;	/* type avl membership */
2837c478bd9Sstevel@tonic-gate 	avl_node_t	ct_ctlist;	/* position in holder's list */
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 	kmutex_t	ct_lock;	/* lock for everything below */
2867c478bd9Sstevel@tonic-gate 	ctstate_t	ct_state;	/* contract's state */
2877c478bd9Sstevel@tonic-gate 	list_t		ct_vnodes;	/* vnodes list */
2887c478bd9Sstevel@tonic-gate 	ctflags_t	ct_flags;	/* contract flags */
2897c478bd9Sstevel@tonic-gate 	ct_equeue_t	ct_events;	/* contract event queue */
2907c478bd9Sstevel@tonic-gate 	struct proc	*ct_owner;	/* contract owner (if owned) */
2917c478bd9Sstevel@tonic-gate 	struct contract	*ct_regent;	/* [prospective] regent contract */
2927c478bd9Sstevel@tonic-gate 	int		ct_evcnt;	/* number of critical events */
2937c478bd9Sstevel@tonic-gate 	ct_kevent_t	*ct_nevent;	/* negotiation event */
29425e8c5aaSvikram 	ct_time_t	ct_ntime;	/* negotiation time tracker */
29525e8c5aaSvikram 	ct_time_t	ct_qtime;	/* quantum time tracker */
2967c478bd9Sstevel@tonic-gate } contract_t;
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate #define	CTLF_COPYOUT	0x1		/* performing copyout */
2997c478bd9Sstevel@tonic-gate #define	CTLF_RESET	0x2		/* event pointer reset or moved */
3007c478bd9Sstevel@tonic-gate #define	CTLF_DEAD	0x4		/* dead listener */
3017c478bd9Sstevel@tonic-gate #define	CTLF_RELIABLE	0x8		/* reliable listener */
3027c478bd9Sstevel@tonic-gate #define	CTLF_CRITICAL	0x10		/* waiting for critical event */
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate typedef struct ct_listener {
3057c478bd9Sstevel@tonic-gate 	list_node_t	ctl_allnode;	/* entry in list of all listeners */
3067c478bd9Sstevel@tonic-gate 	list_node_t	ctl_tailnode;	/* entry in list of tail listeners */
3077c478bd9Sstevel@tonic-gate 	ct_equeue_t	*ctl_equeue;	/* queue */
3087c478bd9Sstevel@tonic-gate 	ct_kevent_t	*ctl_position;	/* position in queue */
3097c478bd9Sstevel@tonic-gate 	int		ctl_flags;	/* state flags */
3107c478bd9Sstevel@tonic-gate 	kcondvar_t	ctl_cv;		/* for waiting for an event */
3117c478bd9Sstevel@tonic-gate 	pollhead_t	ctl_pollhead;	/* so we can poll(2) */
3127c478bd9Sstevel@tonic-gate } ct_listener_t;
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate /*
3157c478bd9Sstevel@tonic-gate  * Contract template interfaces
3167c478bd9Sstevel@tonic-gate  */
3177c478bd9Sstevel@tonic-gate void ctmpl_free(ct_template_t *);
318*c5a9a4fcSAntonello Cruz int ctmpl_set(ct_template_t *, ct_kparam_t *, const cred_t *);
319*c5a9a4fcSAntonello Cruz int ctmpl_get(ct_template_t *, ct_kparam_t *);
3207c478bd9Sstevel@tonic-gate ct_template_t *ctmpl_dup(ct_template_t *);
3217c478bd9Sstevel@tonic-gate void ctmpl_activate(ct_template_t *);
3227c478bd9Sstevel@tonic-gate void ctmpl_clear(ct_template_t *);
32325e8c5aaSvikram int ctmpl_create(ct_template_t *, ctid_t *);
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate /*
326*c5a9a4fcSAntonello Cruz  * Contract parameter functions
327*c5a9a4fcSAntonello Cruz  */
328*c5a9a4fcSAntonello Cruz int ctparam_copyin(const void *, ct_kparam_t *, int, int);
329*c5a9a4fcSAntonello Cruz int ctparam_copyout(ct_kparam_t *, void *, int);
330*c5a9a4fcSAntonello Cruz 
331*c5a9a4fcSAntonello Cruz /*
3327c478bd9Sstevel@tonic-gate  * Contract functions
3337c478bd9Sstevel@tonic-gate  */
3347c478bd9Sstevel@tonic-gate void contract_init(void);
3357c478bd9Sstevel@tonic-gate int contract_abandon(contract_t *, struct proc *, int);
3367c478bd9Sstevel@tonic-gate int contract_adopt(contract_t *, struct proc *);
3377c478bd9Sstevel@tonic-gate void contract_destroy(contract_t *);
3387c478bd9Sstevel@tonic-gate void contract_exit(struct proc *);
33925e8c5aaSvikram int contract_ack(contract_t *ct, uint64_t evid, int cmd);
34025e8c5aaSvikram int contract_qack(contract_t *ct, uint64_t evid);
34125e8c5aaSvikram int contract_newct(contract_t *ct);
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate /*
3447c478bd9Sstevel@tonic-gate  * Event interfaces
3457c478bd9Sstevel@tonic-gate  */
34625e8c5aaSvikram uint64_t cte_publish_all(contract_t *, ct_kevent_t *, nvlist_t *, nvlist_t *);
3477c478bd9Sstevel@tonic-gate void cte_add_listener(ct_equeue_t *, ct_listener_t *);
3487c478bd9Sstevel@tonic-gate void cte_remove_listener(ct_listener_t *);
3497c478bd9Sstevel@tonic-gate void cte_reset_listener(ct_listener_t *);
3507c478bd9Sstevel@tonic-gate int cte_get_event(ct_listener_t *, int, void *, const cred_t *, uint64_t, int);
3517c478bd9Sstevel@tonic-gate int cte_next_event(ct_listener_t *, uint64_t);
3527c478bd9Sstevel@tonic-gate int cte_set_reliable(ct_listener_t *, const cred_t *);
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate /*
3557c478bd9Sstevel@tonic-gate  * Contract implementation interfaces
3567c478bd9Sstevel@tonic-gate  */
3577c478bd9Sstevel@tonic-gate int contract_compar(const void *, const void *);
3587c478bd9Sstevel@tonic-gate void ctmpl_init(ct_template_t *, ctmplops_t *, ct_type_t *, void *);
3597c478bd9Sstevel@tonic-gate void ctmpl_copy(ct_template_t *, ct_template_t *);
36025e8c5aaSvikram int ctmpl_create_inval(ct_template_t *, ctid_t *);
3617c478bd9Sstevel@tonic-gate int contract_ctor(contract_t *, ct_type_t *, ct_template_t *, void *, ctflags_t,
3627c478bd9Sstevel@tonic-gate     struct proc *, int);
3637c478bd9Sstevel@tonic-gate void contract_hold(contract_t *);
3647c478bd9Sstevel@tonic-gate void contract_rele(contract_t *);
3657c478bd9Sstevel@tonic-gate uint64_t contract_getzuniqid(contract_t *);
3667c478bd9Sstevel@tonic-gate void contract_setzuniqid(contract_t *, uint64_t);
3677c478bd9Sstevel@tonic-gate void contract_rele_unlocked(contract_t *);
3687c478bd9Sstevel@tonic-gate void contract_status_common(contract_t *, zone_t *, void *, model_t);
3697c478bd9Sstevel@tonic-gate void contract_orphan(contract_t *);
3707c478bd9Sstevel@tonic-gate ctid_t contract_lookup(uint64_t, ctid_t);
3717c478bd9Sstevel@tonic-gate ctid_t contract_plookup(struct proc *, ctid_t, uint64_t);
3727c478bd9Sstevel@tonic-gate contract_t *contract_ptr(id_t, uint64_t);
3737c478bd9Sstevel@tonic-gate ctid_t contract_max(void);
3747c478bd9Sstevel@tonic-gate int contract_owned(contract_t *, const cred_t *, int);
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate /*
3777c478bd9Sstevel@tonic-gate  * Type interfaces
3787c478bd9Sstevel@tonic-gate  */
3797c478bd9Sstevel@tonic-gate extern int ct_ntypes;
3807c478bd9Sstevel@tonic-gate extern ct_type_t **ct_types;
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate ct_type_t *contract_type_init(ct_typeid_t, const char *, contops_t *,
3837c478bd9Sstevel@tonic-gate     ct_f_default_t *);
3847c478bd9Sstevel@tonic-gate int contract_type_count(ct_type_t *);
3857c478bd9Sstevel@tonic-gate ctid_t contract_type_max(ct_type_t *);
3867c478bd9Sstevel@tonic-gate ctid_t contract_type_lookup(ct_type_t *, uint64_t, ctid_t);
3877c478bd9Sstevel@tonic-gate contract_t *contract_type_ptr(ct_type_t *, ctid_t, uint64_t);
3887c478bd9Sstevel@tonic-gate void contract_type_time(ct_type_t *, timestruc_t *);
3897c478bd9Sstevel@tonic-gate ct_equeue_t *contract_type_bundle(ct_type_t *);
3907c478bd9Sstevel@tonic-gate ct_equeue_t *contract_type_pbundle(ct_type_t *, struct proc *);
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate /*
3937c478bd9Sstevel@tonic-gate  * FS interfaces
3947c478bd9Sstevel@tonic-gate  */
3957c478bd9Sstevel@tonic-gate vnode_t *contract_vnode_get(contract_t *, vfs_t *);
3967c478bd9Sstevel@tonic-gate void contract_vnode_set(contract_t *, contract_vnode_t *, vnode_t *);
3977c478bd9Sstevel@tonic-gate int contract_vnode_clear(contract_t *, contract_vnode_t *);
3987c478bd9Sstevel@tonic-gate 
39925e8c5aaSvikram /*
40025e8c5aaSvikram  * Negotiation stubs
40125e8c5aaSvikram  */
40225e8c5aaSvikram int contract_ack_inval(contract_t *, uint_t, uint64_t);
40325e8c5aaSvikram int contract_qack_inval(contract_t *, uint_t, uint64_t);
40425e8c5aaSvikram int contract_qack_notsup(contract_t *, uint_t, uint64_t);
40525e8c5aaSvikram 
4067c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate #endif
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate #endif	/* _SYS_CONTRACT_IMPL_H */
411