Print this page
fixup .text where possible
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/ctfs/ctfs_ctl.c
+++ new/usr/src/uts/common/fs/ctfs/ctfs_ctl.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 -#pragma ident "%Z%%M% %I% %E% SMI"
27 26
27 +
28 28 #include <sys/types.h>
29 29 #include <sys/param.h>
30 30 #include <sys/time.h>
31 31 #include <sys/cred.h>
32 32 #include <sys/vfs.h>
33 33 #include <sys/vfs_opreg.h>
34 34 #include <sys/gfs.h>
35 35 #include <sys/vnode.h>
36 36 #include <sys/systm.h>
37 37 #include <sys/errno.h>
38 38 #include <sys/sysmacros.h>
39 39 #include <fs/fs_subr.h>
40 40 #include <sys/contract.h>
41 41 #include <sys/contract_impl.h>
42 42 #include <sys/ctfs.h>
43 43 #include <sys/ctfs_impl.h>
44 44 #include <sys/file.h>
45 45
46 46 /*
47 47 * CTFS routines for the /system/contract/<type>/<ctid>/ctl vnode.
48 48 * CTFS routines for the /system/contract/<type>/<ctid>/status vnode.
49 49 */
50 50
51 51 /*
52 52 * ctfs_create_ctlnode
53 53 *
54 54 * If necessary, creates a ctlnode for a ctl file and inserts it into
55 55 * the specified cdirnode's gfs_dir_t. Returns either the existing
56 56 * vnode or the new one.
57 57 */
58 58 vnode_t *
59 59 ctfs_create_ctlnode(vnode_t *pvp)
60 60 {
61 61 ctfs_ctlnode_t *ctlnode;
62 62 ctfs_cdirnode_t *cdirnode = pvp->v_data;
63 63 vnode_t *vp;
64 64
65 65 vp = gfs_file_create(sizeof (ctfs_ctlnode_t), pvp, ctfs_ops_ctl);
66 66 ctlnode = vp->v_data;
67 67 /*
68 68 * We transitively have a hold on the contract through our
69 69 * parent directory.
70 70 */
71 71 ctlnode->ctfs_ctl_contract = cdirnode->ctfs_cn_contract;
72 72
73 73 return (vp);
74 74 }
75 75
76 76 /*
77 77 * ctfs_ctl_access - VOP_ACCESS entry point
78 78 *
79 79 * You only get to access ctl files for contracts you own or were
80 80 * abandoned and inherited by your containing process contract.
81 81 */
82 82 /* ARGSUSED */
83 83 static int
84 84 ctfs_ctl_access(
85 85 vnode_t *vp,
86 86 int mode,
87 87 int flags,
88 88 cred_t *cr,
89 89 caller_context_t *cct)
90 90 {
91 91 ctfs_ctlnode_t *ctlnode = vp->v_data;
92 92 contract_t *ct = ctlnode->ctfs_ctl_contract;
93 93
94 94 if (mode & (VEXEC | VREAD))
95 95 return (EACCES);
96 96
97 97 mutex_enter(&ct->ct_lock);
98 98 if ((curproc == ct->ct_owner) ||
99 99 (ct->ct_owner == NULL && ct->ct_regent != NULL &&
100 100 ct->ct_regent->ct_data == curproc->p_ct_process)) {
101 101 mutex_exit(&ct->ct_lock);
102 102 return (0);
103 103 }
104 104
105 105 mutex_exit(&ct->ct_lock);
106 106 return (EACCES);
107 107 }
108 108
109 109 /*
110 110 * ctfs_ctl_open - VOP_OPEN entry point
111 111 *
112 112 * Just checks to make sure the mode bits are set, and that the
113 113 * constraints imposed by ctfs_ctl_access are met.
114 114 */
115 115 static int
116 116 ctfs_ctl_open(vnode_t **vpp, int flag, cred_t *cr, caller_context_t *ct)
117 117 {
118 118 if (flag != (FWRITE | FOFFMAX))
119 119 return (EINVAL);
120 120
121 121 return (ctfs_ctl_access(*vpp, VWRITE, 0, cr, ct));
122 122 }
123 123
124 124 /*
125 125 * ctfs_ctl_common_getattr
126 126 * Implements functionality common to ctl and status ctfs VOP_GETATTR
127 127 * entry points. It assumes vp->v_data is set
128 128 */
129 129 static int
130 130 ctfs_ctl_common_getattr(vnode_t *vp, vattr_t *vap)
131 131 {
132 132 ctfs_ctlnode_t *ctlnode = vp->v_data;
133 133
134 134 vap->va_type = VREG;
135 135 vap->va_nlink = 1;
136 136 vap->va_size = 0;
137 137 vap->va_ctime = ctlnode->ctfs_ctl_contract->ct_ctime;
138 138 mutex_enter(&ctlnode->ctfs_ctl_contract->ct_events.ctq_lock);
139 139 vap->va_atime = vap->va_mtime =
140 140 ctlnode->ctfs_ctl_contract->ct_events.ctq_atime;
141 141 mutex_exit(&ctlnode->ctfs_ctl_contract->ct_events.ctq_lock);
142 142 ctfs_common_getattr(vp, vap);
143 143
144 144 return (0);
145 145 }
146 146
147 147 /*
148 148 * ctfs_ctl_getattr - VOP_GETATTR entry point
149 149 */
150 150 /* ARGSUSED */
151 151 static int
152 152 ctfs_ctl_getattr(vnode_t *vp, vattr_t *vap, int flags,
153 153 cred_t *cr, caller_context_t *ct)
154 154 {
155 155 vap->va_mode = 0222;
156 156
157 157 return (ctfs_ctl_common_getattr(vp, vap));
158 158 }
159 159
160 160 /*
161 161 * ctfs_stat_getattr - VOP_GETATTR entry point
162 162 */
163 163 /* ARGSUSED */
164 164 static int
165 165 ctfs_stat_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
166 166 caller_context_t *ct)
167 167 {
168 168 vap->va_mode = 0444;
169 169
170 170 return (ctfs_ctl_common_getattr(vp, vap));
171 171 }
172 172
173 173 /*
174 174 * ctfs_ctl_ioctl - VOP_IOCTL entry point
175 175 *
176 176 * All the ct_ctl_*(3contract) interfaces point here.
177 177 */
178 178 /* ARGSUSED */
179 179 static int
180 180 ctfs_ctl_ioctl(
181 181 vnode_t *vp,
182 182 int cmd,
183 183 intptr_t arg,
184 184 int flag,
185 185 cred_t *cr,
186 186 int *rvalp,
187 187 caller_context_t *cct)
188 188 {
189 189 ctfs_ctlnode_t *ctlnode = vp->v_data;
190 190 contract_t *ct = ctlnode->ctfs_ctl_contract;
191 191 int error = 0;
192 192 uint64_t event;
193 193 int ack;
194 194
195 195 switch (cmd) {
196 196 case CT_CABANDON:
197 197 error = contract_abandon(ct, curproc, 1);
198 198 break;
199 199
200 200 case CT_CACK:
201 201 case CT_CNACK:
202 202 if (copyin((void *)arg, &event, sizeof (uint64_t)))
203 203 return (EFAULT);
204 204 ack = (cmd == CT_CACK) ? CT_ACK : CT_NACK;
205 205 error = contract_ack(ct, event, ack);
206 206 break;
207 207
208 208 case CT_CNEWCT:
209 209 error = contract_newct(ct);
210 210 break;
211 211
212 212 case CT_CQREQ:
213 213 if (copyin((void *)arg, &event, sizeof (uint64_t)))
214 214 return (EFAULT);
215 215 error = contract_qack(ct, event);
216 216 break;
217 217
218 218 case CT_CADOPT:
219 219 error = contract_adopt(ct, curproc);
220 220 break;
221 221
222 222 default:
223 223 return (EINVAL);
224 224 }
225 225
226 226 return (error);
227 227 }
↓ open down ↓ |
190 lines elided |
↑ open up ↑ |
228 228
229 229 const fs_operation_def_t ctfs_tops_ctl[] = {
230 230 { VOPNAME_OPEN, { .vop_open = ctfs_ctl_open } },
231 231 { VOPNAME_CLOSE, { .vop_close = ctfs_close } },
232 232 { VOPNAME_IOCTL, { .vop_ioctl = ctfs_ctl_ioctl } },
233 233 { VOPNAME_GETATTR, { .vop_getattr = ctfs_ctl_getattr } },
234 234 { VOPNAME_ACCESS, { .vop_access = ctfs_ctl_access } },
235 235 { VOPNAME_READDIR, { .error = fs_notdir } },
236 236 { VOPNAME_LOOKUP, { .error = fs_notdir } },
237 237 { VOPNAME_INACTIVE, { .vop_inactive = gfs_vop_inactive } },
238 - { NULL, NULL }
238 + { NULL, { NULL } }
239 239 };
240 240
241 241 /*
242 242 * ctfs_create_statnode
243 243 *
244 244 * If necessary, creates a ctlnode for a status file and inserts it
245 245 * into the specified cdirnode's gfs_dir_t. Returns either the
246 246 * existing vnode or the new one.
247 247 */
248 248 vnode_t *
249 249 ctfs_create_statnode(vnode_t *pvp)
250 250 {
251 251 vnode_t *vp;
252 252 ctfs_cdirnode_t *cdirnode = pvp->v_data;
253 253 ctfs_ctlnode_t *ctlnode;
254 254
255 255 vp = gfs_file_create(sizeof (ctfs_ctlnode_t), pvp, ctfs_ops_stat);
256 256 ctlnode = vp->v_data;
257 257 /*
258 258 * We transitively have a hold on the contract through our
259 259 * parent directory.
260 260 */
261 261 ctlnode->ctfs_ctl_contract = cdirnode->ctfs_cn_contract;
262 262
263 263 return (vp);
264 264 }
265 265
266 266 /*
267 267 * ctfs_stat_ioctl - VOP_IOCTL entry point
268 268 *
269 269 * The kernel half of ct_status_read(3contract).
270 270 */
271 271 /* ARGSUSED */
272 272 static int
273 273 ctfs_stat_ioctl(
274 274 vnode_t *vp,
275 275 int cmd,
276 276 intptr_t arg,
277 277 int flag,
278 278 cred_t *cr,
279 279 int *rvalp,
280 280 caller_context_t *cct)
281 281 {
282 282 ctfs_ctlnode_t *statnode = vp->v_data;
283 283 contract_t *ct = statnode->ctfs_ctl_contract;
284 284 ct_type_t *type = ct->ct_type;
285 285 STRUCT_DECL(ct_status, st);
286 286 nvlist_t *foo;
287 287 char *bufp = NULL;
288 288 size_t len;
289 289 model_t mdl = get_udatamodel();
290 290 uint_t detail;
291 291
292 292 STRUCT_INIT(st, mdl);
293 293
294 294 if (cmd != CT_SSTATUS)
295 295 return (EINVAL);
296 296
297 297 if (copyin((void *)arg, STRUCT_BUF(st), STRUCT_SIZE(st)))
298 298 return (EFAULT);
299 299 detail = STRUCT_FGET(st, ctst_detail);
300 300 if (detail == CTD_COMMON) {
301 301 mutex_enter(&ct->ct_lock);
302 302 contract_status_common(ct, VTOZONE(vp), STRUCT_BUF(st), mdl);
303 303 mutex_exit(&ct->ct_lock);
304 304 } else if (detail <= CTD_ALL) {
305 305 VERIFY(nvlist_alloc(&foo, NV_UNIQUE_NAME, KM_SLEEP) == 0);
306 306 type->ct_type_ops->contop_status(ct, VTOZONE(vp), detail, foo,
307 307 STRUCT_BUF(st), mdl);
308 308 VERIFY(nvlist_pack(foo, &bufp, &len, NV_ENCODE_NATIVE,
309 309 KM_SLEEP) == 0);
310 310 nvlist_free(foo);
311 311
312 312 if ((len <= STRUCT_FGET(st, ctst_nbytes)) &&
313 313 (copyout(bufp, STRUCT_FGETP(st, ctst_buffer), len) == -1)) {
314 314 kmem_free(bufp, len);
315 315 return (EFAULT);
316 316 }
317 317 kmem_free(bufp, len);
318 318 STRUCT_FSET(st, ctst_nbytes, len);
319 319 } else {
320 320 return (EINVAL);
321 321 }
322 322 if (copyout(STRUCT_BUF(st), (void *)arg, STRUCT_SIZE(st)))
323 323 return (EFAULT);
324 324
325 325 return (0);
326 326 }
↓ open down ↓ |
78 lines elided |
↑ open up ↑ |
327 327
328 328 const fs_operation_def_t ctfs_tops_stat[] = {
329 329 { VOPNAME_OPEN, { .vop_open = ctfs_open } },
330 330 { VOPNAME_CLOSE, { .vop_close = ctfs_close } },
331 331 { VOPNAME_IOCTL, { .vop_ioctl = ctfs_stat_ioctl } },
332 332 { VOPNAME_GETATTR, { .vop_getattr = ctfs_stat_getattr } },
333 333 { VOPNAME_ACCESS, { .vop_access = ctfs_access_readonly } },
334 334 { VOPNAME_READDIR, { .error = fs_notdir } },
335 335 { VOPNAME_LOOKUP, { .error = fs_notdir } },
336 336 { VOPNAME_INACTIVE, { .vop_inactive = gfs_vop_inactive } },
337 - { NULL, NULL }
337 + { NULL, { NULL } }
338 338 };
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX