stop shipping useless ksh93 builtins into /usr/bin
[unleashed.git] / kernel / fs / doorfs / door_vnops.c
blobd37a24beebaf4f473c80ccef3101910154ffe747
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 * Copyright (c) 2017 by Delphix. All rights reserved.
29 #include <sys/types.h>
30 #include <sys/vnode.h>
31 #include <sys/vfs.h>
32 #include <sys/door.h>
33 #include <sys/proc.h>
34 #include <sys/kmem.h>
35 #include <sys/debug.h>
36 #include <sys/cmn_err.h>
37 #include <sys/fs_subr.h>
38 #include <sys/zone.h>
40 kmutex_t door_knob;
41 static int door_open(struct vnode **vpp, int flag, struct cred *cr,
42 caller_context_t *ct);
43 static int door_close(struct vnode *vp, int flag, int count,
44 offset_t offset, struct cred *cr, caller_context_t *ct);
45 static int door_getattr(struct vnode *vp, struct vattr *vap,
46 int flags, struct cred *cr, caller_context_t *ct);
47 static void door_inactive(struct vnode *vp, struct cred *cr,
48 caller_context_t *ct);
49 static int door_access(struct vnode *vp, int mode, int flags,
50 struct cred *cr, caller_context_t *ct);
51 static int door_realvp(vnode_t *vp, vnode_t **vpp, caller_context_t *ct);
53 struct vfs door_vfs;
55 const struct vnodeops door_vnodeops = {
56 .vnop_name = "doorfs",
57 .vop_open = door_open,
58 .vop_close = door_close,
59 .vop_getattr = door_getattr,
60 .vop_access = door_access,
61 .vop_inactive = door_inactive,
62 .vop_frlock = fs_nosys,
63 .vop_realvp = door_realvp,
64 .vop_poll = fs_nosys_poll,
65 .vop_pathconf = fs_nosys,
66 .vop_dispose = fs_nodispose,
67 .vop_getsecattr = fs_nosys,
68 .vop_shrlock = fs_nosys,
71 /* ARGSUSED */
72 static int
73 door_open(struct vnode **vpp, int flag, struct cred *cr, caller_context_t *ct)
75 return (0);
78 /* ARGSUSED */
79 static int
80 door_close(struct vnode *vp, int flag, int count, offset_t offset,
81 struct cred *cr, caller_context_t *ct)
83 door_node_t *dp = VTOD(vp);
86 * If this is being called from closeall on exit, any doors created
87 * by this process should have been revoked already in door_exit.
89 ASSERT(dp->door_target != curproc ||
90 ((curthread->t_proc_flag & TP_LWPEXIT) == 0));
93 * Deliver an unref if needed.
95 * If the count is equal to 2, it means that I'm doing a fop_close
96 * on the next to last reference for *this* file struct. There may
97 * be multiple files pointing to this vnode in which case the v_count
98 * will be > 1.
100 * The door_active count is bumped during each invocation.
102 if (count == 2 && vp->v_count == 1 &&
103 (dp->door_flags & (DOOR_UNREF | DOOR_UNREF_MULTI))) {
104 mutex_enter(&door_knob);
105 if (dp->door_active == 0) {
106 /* o.k. to deliver unref now */
107 door_deliver_unref(dp);
108 } else {
109 /* do the unref later */
110 dp->door_flags |= DOOR_DELAY;
112 mutex_exit(&door_knob);
114 return (0);
117 /* ARGSUSED */
118 static int
119 door_getattr(struct vnode *vp, struct vattr *vap, int flags, struct cred *cr,
120 caller_context_t *ct)
122 static timestruc_t tzero = {0, 0};
123 extern dev_t doordev;
125 vap->va_mask = 0; /* bit-mask of attributes */
126 vap->va_type = vp->v_type; /* vnode type (for create) */
127 vap->va_mode = 0777; /* file access mode */
128 vap->va_uid = 0; /* owner user id */
129 vap->va_gid = 0; /* owner group id */
130 vap->va_fsid = doordev; /* file system id (dev for now) */
131 vap->va_nodeid = (ino64_t)0; /* node id */
132 vap->va_nlink = vp->v_count; /* number of references to file */
133 vap->va_size = 0; /* file size in bytes */
134 vap->va_atime = tzero; /* time of last access */
135 vap->va_mtime = tzero; /* time of last modification */
136 vap->va_ctime = tzero; /* time file ``created'' */
137 vap->va_rdev = doordev; /* device the file represents */
138 vap->va_blksize = 0; /* fundamental block size */
139 vap->va_nblocks = (fsblkcnt64_t)0; /* # of blocks allocated */
140 vap->va_seq = 0; /* sequence number */
142 return (0);
145 /* ARGSUSED */
146 static void
147 door_inactive(struct vnode *vp, struct cred *cr, caller_context_t *ct)
149 door_node_t *dp = VTOD(vp);
151 mutex_enter(&vp->v_lock);
153 * Once the door_node is unreferenced, it stays unreferenced,
154 * so we can simply return if there are active thread bindings;
155 * the final door_unbind_thread() will re-invoke us.
157 ASSERT(vp->v_count == 1);
158 if (dp->door_bound_threads > 0) {
159 VN_RELE_LOCKED(vp);
160 mutex_exit(&vp->v_lock);
161 return;
163 mutex_exit(&vp->v_lock);
165 /* if not revoked, remove door from per-process list */
166 if (dp->door_target) {
167 mutex_enter(&door_knob);
168 if (dp->door_target) /* recheck door_target under lock */
169 door_list_delete(dp);
170 mutex_exit(&door_knob);
172 vn_invalid(vp);
173 vn_free(vp);
174 kmem_free(dp, sizeof (door_node_t));
178 * To avoid having bound threads interfere with unref processing, we
179 * don't use VN_HOLD/VN_RELE to track threads bound to our private
180 * pool. Instead, we keep a separate counter, also under v_lock.
182 void
183 door_bind_thread(door_node_t *dp)
185 vnode_t *vp = DTOV(dp);
187 mutex_enter(&vp->v_lock);
188 dp->door_bound_threads++;
189 ASSERT(dp->door_bound_threads > 0 && vp->v_count > 0);
190 mutex_exit(&vp->v_lock);
193 void
194 door_unbind_thread(door_node_t *dp)
196 vnode_t *vp = DTOV(dp);
197 int do_inactive = 0;
199 mutex_enter(&vp->v_lock);
200 ASSERT(dp->door_bound_threads > 0);
201 if (--dp->door_bound_threads == 0 && vp->v_count == 0) {
202 /* set up for inactive handling */
203 VN_HOLD_LOCKED(vp);
204 do_inactive = 1;
206 mutex_exit(&vp->v_lock);
208 if (do_inactive)
209 door_inactive(vp, NULL, NULL);
212 /* ARGSUSED */
213 static int
214 door_access(struct vnode *vp, int mode, int flags, struct cred *cr,
215 caller_context_t *ct)
217 return (0);
220 /* ARGSUSED */
221 static int
222 door_realvp(vnode_t *vp, vnode_t **vpp, caller_context_t *ct)
224 *vpp = vp;
225 return (0);