xref: /illumos-gate/usr/src/uts/common/sys/ctfs_impl.h (revision 2d6eb4a5)
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
5*da6c28aaSamw  * Common Development and Distribution License (the "License").
6*da6c28aaSamw  * 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 /*
22*da6c28aaSamw  * Copyright 2007 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_CTFS_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_SYS_CTFS_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/contract.h>
307c478bd9Sstevel@tonic-gate #include <sys/gfs.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * Inode numbers
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /*
417c478bd9Sstevel@tonic-gate  * Root inode:
427c478bd9Sstevel@tonic-gate  * ---------------------------------------------------
437c478bd9Sstevel@tonic-gate  * |                       0                         |
447c478bd9Sstevel@tonic-gate  * ---------------------------------------------------
457c478bd9Sstevel@tonic-gate  * 63						     0
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #define	CTFS_INO_ROOT 0
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /*
517c478bd9Sstevel@tonic-gate  * Contract-specific file:
527c478bd9Sstevel@tonic-gate  * ---------------------------------------------------
537c478bd9Sstevel@tonic-gate  * |1|    file (62:32)     |   contract id (31:0)    |
547c478bd9Sstevel@tonic-gate  * ---------------------------------------------------
557c478bd9Sstevel@tonic-gate  * 63						     0
567c478bd9Sstevel@tonic-gate  *	file = 0 : directory
577c478bd9Sstevel@tonic-gate  *	file = 1 : "all" directory symlink
587c478bd9Sstevel@tonic-gate  *	file > 1 : special files ("ctl", "status", etc.)
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #define	CTFS_INO_CT_SHIFT	32
627c478bd9Sstevel@tonic-gate #define	CTFS_INO_CT(ctid, file)	\
637c478bd9Sstevel@tonic-gate 	((1ULL << 63) | \
647c478bd9Sstevel@tonic-gate 	((unsigned long long)(file) << CTFS_INO_CT_SHIFT) | \
657c478bd9Sstevel@tonic-gate 	(ctid))
667c478bd9Sstevel@tonic-gate #define	CTFS_INO_CT_DIR(ctid)		CTFS_INO_CT((ctid), 0)
677c478bd9Sstevel@tonic-gate #define	CTFS_INO_CT_LINK(ctid)		CTFS_INO_CT((ctid), 1)
687c478bd9Sstevel@tonic-gate #define	CTFS_INO_CT_FILE(ctid, file)	CTFS_INO_CT((ctid), (file) + 2)
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * Type-specific file:
727c478bd9Sstevel@tonic-gate  * ---------------------------------------------------
737c478bd9Sstevel@tonic-gate  * |          0         | type (31:16) | file (15:0) |
747c478bd9Sstevel@tonic-gate  * ---------------------------------------------------
757c478bd9Sstevel@tonic-gate  * 63						     0
767c478bd9Sstevel@tonic-gate  *	type = 0 : invalid
777c478bd9Sstevel@tonic-gate  *	type > 0 : contract type index + 1 ("all" is #types + 1)
787c478bd9Sstevel@tonic-gate  *	file = 0 : directory
797c478bd9Sstevel@tonic-gate  *	file > 0 : special files ("template", "latest", etc.)
807c478bd9Sstevel@tonic-gate  */
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #define	CTFS_INO_TYPE_SHIFT	16
837c478bd9Sstevel@tonic-gate #define	CTFS_INO_TYPE(type, file)	\
847c478bd9Sstevel@tonic-gate 	(((type) + 1) << CTFS_INO_TYPE_SHIFT | (file))
857c478bd9Sstevel@tonic-gate #define	CTFS_INO_TYPE_DIR(type)		CTFS_INO_TYPE((type), 0)
867c478bd9Sstevel@tonic-gate #define	CTFS_INO_TYPE_FILE(type, file)	CTFS_INO_TYPE((type), (file) + 1)
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * Other constants
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate #define	CTFS_NAME_MAX		32
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * Possible values for ctfs_endpt_flags, below.
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate #define	CTFS_ENDPT_SETUP	0x1
977c478bd9Sstevel@tonic-gate #define	CTFS_ENDPT_NBLOCK	0x2
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate /*
1007c478bd9Sstevel@tonic-gate  * Common endpoint object.
1017c478bd9Sstevel@tonic-gate  */
1027c478bd9Sstevel@tonic-gate typedef struct ctfs_endpoint {
1037c478bd9Sstevel@tonic-gate 	kmutex_t	ctfs_endpt_lock;
1047c478bd9Sstevel@tonic-gate 	ct_listener_t	ctfs_endpt_listener;
1057c478bd9Sstevel@tonic-gate 	uint_t		ctfs_endpt_flags;
1067c478bd9Sstevel@tonic-gate } ctfs_endpoint_t;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate  * root directory data
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate typedef gfs_dir_t	ctfs_rootnode_t;
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate  * /all directory data
1157c478bd9Sstevel@tonic-gate  */
1167c478bd9Sstevel@tonic-gate typedef gfs_dir_t	ctfs_adirnode_t;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate /*
1197c478bd9Sstevel@tonic-gate  * /all symlink data
1207c478bd9Sstevel@tonic-gate  */
1217c478bd9Sstevel@tonic-gate typedef struct ctfs_symnode {
1227c478bd9Sstevel@tonic-gate 	gfs_file_t	ctfs_sn_file;		/* gfs file */
1237c478bd9Sstevel@tonic-gate 	contract_t	*ctfs_sn_contract;	/* target contract */
1247c478bd9Sstevel@tonic-gate 	char		*ctfs_sn_string;	/* target path */
1257c478bd9Sstevel@tonic-gate 	size_t		ctfs_sn_size;		/* length of target path */
1267c478bd9Sstevel@tonic-gate } ctfs_symnode_t;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate /*
1297c478bd9Sstevel@tonic-gate  * contract type directory data
1307c478bd9Sstevel@tonic-gate  */
1317c478bd9Sstevel@tonic-gate typedef	gfs_dir_t	ctfs_tdirnode_t;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * contract directory data
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate typedef struct ctfs_cdirnode {
1377c478bd9Sstevel@tonic-gate 	gfs_dir_t	ctfs_cn_dir;		/* directory contents */
1387c478bd9Sstevel@tonic-gate 	contract_t	*ctfs_cn_contract;	/* contract pointer */
1397c478bd9Sstevel@tonic-gate 	contract_vnode_t ctfs_cn_linkage;	/* contract vnode list node */
1407c478bd9Sstevel@tonic-gate } ctfs_cdirnode_t;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * template file data
1447c478bd9Sstevel@tonic-gate  */
1457c478bd9Sstevel@tonic-gate typedef struct ctfs_tmplnode {
1467c478bd9Sstevel@tonic-gate 	gfs_file_t	ctfs_tmn_file;		/* gfs file */
1477c478bd9Sstevel@tonic-gate 	ct_template_t	*ctfs_tmn_tmpl;		/* template pointer */
1487c478bd9Sstevel@tonic-gate } ctfs_tmplnode_t;
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * ctl and status file data
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate typedef struct ctfs_ctlnode {
1547c478bd9Sstevel@tonic-gate 	gfs_file_t	ctfs_ctl_file;		/* gfs file */
1557c478bd9Sstevel@tonic-gate 	contract_t	*ctfs_ctl_contract;	/* contract pointer */
1567c478bd9Sstevel@tonic-gate } ctfs_ctlnode_t;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate /*
1597c478bd9Sstevel@tonic-gate  * latest file data
1607c478bd9Sstevel@tonic-gate  */
1617c478bd9Sstevel@tonic-gate typedef gfs_dir_t	ctfs_latenode_t;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate /*
1647c478bd9Sstevel@tonic-gate  * events file data
1657c478bd9Sstevel@tonic-gate  */
1667c478bd9Sstevel@tonic-gate typedef struct ctfs_evnode {
1677c478bd9Sstevel@tonic-gate 	gfs_file_t	ctfs_ev_file;		/* gfs file */
1687c478bd9Sstevel@tonic-gate 	contract_t	*ctfs_ev_contract;	/* contract we're watching */
1697c478bd9Sstevel@tonic-gate 	ctfs_endpoint_t	ctfs_ev_listener;	/* common endpoint data */
1707c478bd9Sstevel@tonic-gate } ctfs_evnode_t;
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate /*
1737c478bd9Sstevel@tonic-gate  * bundle and pbundle file data
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate typedef struct ctfs_bunode {
1767c478bd9Sstevel@tonic-gate 	gfs_file_t	ctfs_bu_file;		/* gfs file */
1777c478bd9Sstevel@tonic-gate 	ct_equeue_t	*ctfs_bu_queue;		/* queue we're watching */
1787c478bd9Sstevel@tonic-gate 	ctfs_endpoint_t	ctfs_bu_listener;	/* common endpoint data */
1797c478bd9Sstevel@tonic-gate } ctfs_bunode_t;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate /*
1827c478bd9Sstevel@tonic-gate  * VFS data object
1837c478bd9Sstevel@tonic-gate  */
1847c478bd9Sstevel@tonic-gate typedef struct ctfs_vfs {
1857c478bd9Sstevel@tonic-gate 	vnode_t	*ctvfs_root;		/* root vnode pointer */
1867c478bd9Sstevel@tonic-gate } ctfs_vfs_t;
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate /*
1897c478bd9Sstevel@tonic-gate  * vnode creation routines
1907c478bd9Sstevel@tonic-gate  */
1917c478bd9Sstevel@tonic-gate extern vnode_t *ctfs_create_tdirnode(vnode_t *);
1927c478bd9Sstevel@tonic-gate extern vnode_t *ctfs_create_tmplnode(vnode_t *);
1937c478bd9Sstevel@tonic-gate extern vnode_t *ctfs_create_latenode(vnode_t *);
1947c478bd9Sstevel@tonic-gate extern vnode_t *ctfs_create_pbundle(vnode_t *);
1957c478bd9Sstevel@tonic-gate extern vnode_t *ctfs_create_bundle(vnode_t *);
1967c478bd9Sstevel@tonic-gate extern vnode_t *ctfs_create_ctlnode(vnode_t *);
1977c478bd9Sstevel@tonic-gate extern vnode_t *ctfs_create_statnode(vnode_t *);
1987c478bd9Sstevel@tonic-gate extern vnode_t *ctfs_create_evnode(vnode_t *);
1997c478bd9Sstevel@tonic-gate extern vnode_t *ctfs_create_adirnode(vnode_t *);
2007c478bd9Sstevel@tonic-gate extern vnode_t *ctfs_create_cdirnode(vnode_t *, contract_t *);
2017c478bd9Sstevel@tonic-gate extern vnode_t *ctfs_create_symnode(vnode_t *, contract_t *);
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate /*
2047c478bd9Sstevel@tonic-gate  * common ctfs routines
2057c478bd9Sstevel@tonic-gate  */
2067c478bd9Sstevel@tonic-gate extern void ctfs_common_getattr(vnode_t *, vattr_t *);
207*da6c28aaSamw extern int ctfs_close(vnode_t *, int, int, offset_t, cred_t *,
208*da6c28aaSamw 		caller_context_t *);
209*da6c28aaSamw extern int ctfs_access_dir(vnode_t *, int, int, cred_t *,
210*da6c28aaSamw 		caller_context_t *);
211*da6c28aaSamw extern int ctfs_access_readonly(vnode_t *, int, int, cred_t *,
212*da6c28aaSamw 		caller_context_t *);
213*da6c28aaSamw extern int ctfs_access_readwrite(vnode_t *, int, int, cred_t *,
214*da6c28aaSamw 		caller_context_t *);
215*da6c28aaSamw extern int ctfs_open(vnode_t **, int, cred_t *,
216*da6c28aaSamw 		caller_context_t *);
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate /*
2197c478bd9Sstevel@tonic-gate  * vnode ops vector templates
2207c478bd9Sstevel@tonic-gate  */
2217c478bd9Sstevel@tonic-gate extern vnodeops_t *ctfs_ops_root;
2227c478bd9Sstevel@tonic-gate extern vnodeops_t *ctfs_ops_adir;
2237c478bd9Sstevel@tonic-gate extern vnodeops_t *ctfs_ops_sym;
2247c478bd9Sstevel@tonic-gate extern vnodeops_t *ctfs_ops_tdir;
2257c478bd9Sstevel@tonic-gate extern vnodeops_t *ctfs_ops_tmpl;
2267c478bd9Sstevel@tonic-gate extern vnodeops_t *ctfs_ops_cdir;
2277c478bd9Sstevel@tonic-gate extern vnodeops_t *ctfs_ops_ctl;
2287c478bd9Sstevel@tonic-gate extern vnodeops_t *ctfs_ops_stat;
2297c478bd9Sstevel@tonic-gate extern vnodeops_t *ctfs_ops_event;
2307c478bd9Sstevel@tonic-gate extern vnodeops_t *ctfs_ops_bundle;
2317c478bd9Sstevel@tonic-gate extern vnodeops_t *ctfs_ops_latest;
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate #endif
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate #endif	/* _SYS_CTFS_IMPL_H */
238