xref: /titanic_41/usr/src/uts/common/fs/ctfs/ctfs_latest.c (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/time.h>
32 #include <sys/cred.h>
33 #include <sys/vfs.h>
34 #include <sys/gfs.h>
35 #include <sys/vnode.h>
36 #include <sys/systm.h>
37 #include <sys/errno.h>
38 #include <sys/sysmacros.h>
39 #include <fs/fs_subr.h>
40 #include <sys/contract.h>
41 #include <sys/contract_impl.h>
42 #include <sys/ctfs.h>
43 #include <sys/ctfs_impl.h>
44 #include <sys/file.h>
45 
46 /*
47  * CTFS routines for the /system/contract/<type>/latest vnode.
48  */
49 
50 /*
51  * ctfs_create_latenode
52  */
53 vnode_t *
54 ctfs_create_latenode(vnode_t *pvp)
55 {
56 	return (gfs_file_create(sizeof (ctfs_latenode_t), pvp,
57 	    ctfs_ops_latest));
58 }
59 
60 /*
61  * ctfs_latest_nested_open
62  *
63  * The latest node is just a doorway to the status file; this function
64  * is used by ctfs_latest_access, ctfs_latest_open, and
65  * ctfs_latest_getattr to obtain that file.
66  */
67 static vnode_t *
68 ctfs_latest_nested_open(vnode_t *vp)
69 {
70 	contract_t *ct = ttolwp(curthread)->lwp_ct_latest[
71 	    gfs_file_index(gfs_file_parent(vp))];
72 
73 	if (ct) {
74 		vnode_t *cvp, *svp;
75 
76 		cvp = ctfs_create_cdirnode(gfs_file_parent(vp), ct);
77 
78 		gfs_file_set_index(cvp, -1);
79 
80 		VERIFY(gfs_dir_lookup(cvp, "status", &svp) == 0);
81 
82 		VN_RELE(cvp);
83 
84 		return (svp);
85 	}
86 
87 	return (NULL);
88 }
89 
90 /*
91  * ctfs_latest_access - VOP_ACCESS entry point
92  *
93  * Fails if there isn't a latest contract.
94  */
95 /* ARGSUSED */
96 static int
97 ctfs_latest_access(vnode_t *vp, int mode, int flags, cred_t *cr)
98 {
99 	vnode_t *nvp;
100 
101 	if (mode & (VEXEC | VWRITE))
102 		return (EACCES);
103 
104 	if (nvp = ctfs_latest_nested_open(vp)) {
105 		VN_RELE(nvp);
106 		return (0);
107 	}
108 
109 	return (ESRCH);
110 }
111 
112 /*
113  * ctfs_latest_open - VOP_OPEN entry point
114  *
115  * After checking the mode bits, opens and returns the status file for
116  * the LWP's latest contract.
117  */
118 static int
119 ctfs_latest_open(vnode_t **vpp, int flag, cred_t *cr)
120 {
121 	vnode_t *nvp;
122 
123 	if (flag != (FREAD | FOFFMAX))
124 		return (EINVAL);
125 
126 	if (nvp = ctfs_latest_nested_open(*vpp)) {
127 		VN_RELE(*vpp);
128 		*vpp = nvp;
129 		return (VOP_OPEN(vpp, flag, cr));
130 	}
131 
132 	return (ESRCH);
133 }
134 
135 /*
136  * ctfs_latest_getattr - the VOP_GETATTR entry point
137  *
138  * Fetches and calls VOP_GETATTR on the status file for the LWP's
139  * latest contract.  Otherwise it fakes up something bland.
140  */
141 static int
142 ctfs_latest_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr)
143 {
144 	vnode_t *nvp;
145 
146 	if (nvp = ctfs_latest_nested_open(vp)) {
147 		int res = VOP_GETATTR(nvp, vap, flags, cr);
148 		VN_RELE(nvp);
149 		return (res);
150 	}
151 
152 	vap->va_type = VREG;
153 	vap->va_mode = 0444;
154 	vap->va_nlink = 1;
155 	vap->va_size = 0;
156 	vap->va_ctime.tv_sec = vp->v_vfsp->vfs_mtime;
157 	vap->va_ctime.tv_nsec = 0;
158 	vap->va_atime = vap->va_mtime = vap->va_ctime;
159 	ctfs_common_getattr(vp, vap);
160 
161 	return (0);
162 }
163 
164 const fs_operation_def_t ctfs_tops_latest[] = {
165 	{ VOPNAME_OPEN,		ctfs_latest_open },
166 	{ VOPNAME_CLOSE,	fs_inval },
167 	{ VOPNAME_IOCTL,	fs_inval },
168 	{ VOPNAME_GETATTR,	ctfs_latest_getattr },
169 	{ VOPNAME_ACCESS,	ctfs_latest_access },
170 	{ VOPNAME_READDIR,	fs_notdir },
171 	{ VOPNAME_LOOKUP,	fs_notdir },
172 	{ VOPNAME_INACTIVE,	(fs_generic_func_p) gfs_vop_inactive },
173 	{ NULL, NULL }
174 };
175