su.static: link with proto area libs (esp. libc)
[unleashed.git] / kernel / fs / ctfs / ctfs_cdir.c
blobdd106c2f44d7577ab9794887c30e9d1560bf1855
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <sys/types.h>
29 #include <sys/param.h>
30 #include <sys/time.h>
31 #include <sys/cred.h>
32 #include <sys/vfs.h>
33 #include <sys/gfs.h>
34 #include <sys/vnode.h>
35 #include <sys/systm.h>
36 #include <sys/errno.h>
37 #include <sys/sysmacros.h>
38 #include <sys/fs_subr.h>
39 #include <sys/contract.h>
40 #include <sys/contract_impl.h>
41 #include <sys/ctfs.h>
42 #include <sys/ctfs_impl.h>
43 #include <sys/file.h>
44 #include <sys/pathname.h>
47 * Entries in a /system/contract/<type>/<ctid> directory.
49 static gfs_dirent_t ctfs_ctls[] = {
50 { "ctl", ctfs_create_ctlnode, GFS_CACHE_VNODE, },
51 { "status", ctfs_create_statnode, GFS_CACHE_VNODE },
52 { "events", ctfs_create_evnode },
53 { NULL }
55 #define CTFS_NCTLS ((sizeof ctfs_ctls / sizeof (gfs_dirent_t)) - 1)
57 static ino64_t ctfs_cdir_do_inode(vnode_t *, int);
60 * ctfs_create_cdirnode
62 * If necessary, creates a cdirnode for the specified contract and
63 * inserts it into the contract's list of vnodes. Returns either the
64 * existing vnode or the new one.
66 vnode_t *
67 ctfs_create_cdirnode(vnode_t *pvp, contract_t *ct)
69 vnode_t *vp;
70 ctfs_cdirnode_t *cdir;
72 if ((vp = contract_vnode_get(ct, pvp->v_vfsp)) != NULL)
73 return (vp);
75 vp = gfs_dir_create(sizeof (ctfs_cdirnode_t), pvp, &ctfs_ops_cdir,
76 ctfs_ctls, ctfs_cdir_do_inode, CTFS_NAME_MAX, NULL, NULL);
77 cdir = vp->v_data;
80 * We must set the inode because this is called explicitly rather than
81 * through GFS callbacks.
83 gfs_file_set_inode(vp, CTFS_INO_CT_DIR(ct->ct_id));
85 cdir->ctfs_cn_contract = ct;
86 contract_hold(ct);
87 contract_vnode_set(ct, &cdir->ctfs_cn_linkage, vp);
89 return (vp);
93 * ctfs_cdir_getattr - fop_getattr entry point
95 /* ARGSUSED */
96 static int
97 ctfs_cdir_getattr(
98 vnode_t *vp,
99 vattr_t *vap,
100 int flags,
101 cred_t *cr,
102 caller_context_t *ct)
104 ctfs_cdirnode_t *cdirnode = vp->v_data;
106 vap->va_type = VDIR;
107 vap->va_mode = 0555;
108 vap->va_nlink = 2 + CTFS_NCTLS;
109 vap->va_size = vap->va_nlink;
110 vap->va_ctime = cdirnode->ctfs_cn_contract->ct_ctime;
111 mutex_enter(&cdirnode->ctfs_cn_contract->ct_events.ctq_lock);
112 vap->va_atime = vap->va_mtime =
113 cdirnode->ctfs_cn_contract->ct_events.ctq_atime;
114 mutex_exit(&cdirnode->ctfs_cn_contract->ct_events.ctq_lock);
115 ctfs_common_getattr(vp, vap);
117 return (0);
121 * ctfs_cdir_do_inode - return inode number based on static index
123 static ino64_t
124 ctfs_cdir_do_inode(vnode_t *vp, int index)
126 ctfs_cdirnode_t *cdirnode = vp->v_data;
128 return (CTFS_INO_CT_FILE(cdirnode->ctfs_cn_contract->ct_id, index));
132 * ctfs_cdir_inactive - fop_inactive entry point
134 /* ARGSUSED */
135 static void
136 ctfs_cdir_inactive(vnode_t *vp, cred_t *cr, caller_context_t *cct)
138 ctfs_cdirnode_t *cdirnode = vp->v_data;
139 contract_t *ct = cdirnode->ctfs_cn_contract;
141 mutex_enter(&ct->ct_lock);
142 if (gfs_dir_inactive(vp) == NULL) {
143 mutex_exit(&ct->ct_lock);
144 return;
147 list_remove(&ct->ct_vnodes, &cdirnode->ctfs_cn_linkage);
148 mutex_exit(&ct->ct_lock);
150 contract_rele(ct);
151 kmem_free(cdirnode, sizeof (ctfs_cdirnode_t));
155 const struct vnodeops ctfs_ops_cdir = {
156 .vnop_name = "ctfs contract directory",
157 .vop_open = ctfs_open,
158 .vop_close = ctfs_close,
159 .vop_ioctl = fs_inval,
160 .vop_getattr = ctfs_cdir_getattr,
161 .vop_access = ctfs_access_dir,
162 .vop_readdir = gfs_vop_readdir,
163 .vop_lookup = gfs_vop_lookup,
164 .vop_seek = fs_seek,
165 .vop_inactive = ctfs_cdir_inactive,