ulfs_vfsops.c revision 1.8.2.2 1 1.8.2.2 tls /* $NetBSD: ulfs_vfsops.c,v 1.8.2.2 2013/06/23 06:18:39 tls Exp $ */
2 1.8.2.2 tls /* from NetBSD: ufs_vfsops.c,v 1.52 2013/01/22 09:39:18 dholland Exp */
3 1.8.2.2 tls
4 1.8.2.2 tls /*
5 1.8.2.2 tls * Copyright (c) 1991, 1993, 1994
6 1.8.2.2 tls * The Regents of the University of California. All rights reserved.
7 1.8.2.2 tls * (c) UNIX System Laboratories, Inc.
8 1.8.2.2 tls * All or some portions of this file are derived from material licensed
9 1.8.2.2 tls * to the University of California by American Telephone and Telegraph
10 1.8.2.2 tls * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11 1.8.2.2 tls * the permission of UNIX System Laboratories, Inc.
12 1.8.2.2 tls *
13 1.8.2.2 tls * Redistribution and use in source and binary forms, with or without
14 1.8.2.2 tls * modification, are permitted provided that the following conditions
15 1.8.2.2 tls * are met:
16 1.8.2.2 tls * 1. Redistributions of source code must retain the above copyright
17 1.8.2.2 tls * notice, this list of conditions and the following disclaimer.
18 1.8.2.2 tls * 2. Redistributions in binary form must reproduce the above copyright
19 1.8.2.2 tls * notice, this list of conditions and the following disclaimer in the
20 1.8.2.2 tls * documentation and/or other materials provided with the distribution.
21 1.8.2.2 tls * 3. Neither the name of the University nor the names of its contributors
22 1.8.2.2 tls * may be used to endorse or promote products derived from this software
23 1.8.2.2 tls * without specific prior written permission.
24 1.8.2.2 tls *
25 1.8.2.2 tls * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.8.2.2 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.8.2.2 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.8.2.2 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.8.2.2 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.8.2.2 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.8.2.2 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.8.2.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.8.2.2 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.8.2.2 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.8.2.2 tls * SUCH DAMAGE.
36 1.8.2.2 tls *
37 1.8.2.2 tls * @(#)ufs_vfsops.c 8.8 (Berkeley) 5/20/95
38 1.8.2.2 tls */
39 1.8.2.2 tls
40 1.8.2.2 tls #include <sys/cdefs.h>
41 1.8.2.2 tls __KERNEL_RCSID(0, "$NetBSD: ulfs_vfsops.c,v 1.8.2.2 2013/06/23 06:18:39 tls Exp $");
42 1.8.2.2 tls
43 1.8.2.2 tls #if defined(_KERNEL_OPT)
44 1.8.2.2 tls #include "opt_lfs.h"
45 1.8.2.2 tls #include "opt_quota.h"
46 1.8.2.2 tls #endif
47 1.8.2.2 tls
48 1.8.2.2 tls #include <sys/param.h>
49 1.8.2.2 tls #include <sys/mbuf.h>
50 1.8.2.2 tls #include <sys/mount.h>
51 1.8.2.2 tls #include <sys/proc.h>
52 1.8.2.2 tls #include <sys/buf.h>
53 1.8.2.2 tls #include <sys/vnode.h>
54 1.8.2.2 tls #include <sys/kmem.h>
55 1.8.2.2 tls #include <sys/kauth.h>
56 1.8.2.2 tls #include <sys/quotactl.h>
57 1.8.2.2 tls
58 1.8.2.2 tls #include <miscfs/specfs/specdev.h>
59 1.8.2.2 tls
60 1.8.2.2 tls #include <ufs/lfs/lfs.h>
61 1.8.2.2 tls #include <ufs/lfs/ulfs_quotacommon.h>
62 1.8.2.2 tls #include <ufs/lfs/ulfs_inode.h>
63 1.8.2.2 tls #include <ufs/lfs/ulfsmount.h>
64 1.8.2.2 tls #include <ufs/lfs/ulfs_extern.h>
65 1.8.2.2 tls #ifdef LFS_DIRHASH
66 1.8.2.2 tls #include <ufs/lfs/ulfs_dirhash.h>
67 1.8.2.2 tls #endif
68 1.8.2.2 tls
69 1.8.2.2 tls /* how many times ulfs_init() was called */
70 1.8.2.2 tls static int ulfs_initcount = 0;
71 1.8.2.2 tls
72 1.8.2.2 tls pool_cache_t ulfs_direct_cache;
73 1.8.2.2 tls
74 1.8.2.2 tls /*
75 1.8.2.2 tls * Make a filesystem operational.
76 1.8.2.2 tls * Nothing to do at the moment.
77 1.8.2.2 tls */
78 1.8.2.2 tls /* ARGSUSED */
79 1.8.2.2 tls int
80 1.8.2.2 tls ulfs_start(struct mount *mp, int flags)
81 1.8.2.2 tls {
82 1.8.2.2 tls
83 1.8.2.2 tls return (0);
84 1.8.2.2 tls }
85 1.8.2.2 tls
86 1.8.2.2 tls /*
87 1.8.2.2 tls * Return the root of a filesystem.
88 1.8.2.2 tls */
89 1.8.2.2 tls int
90 1.8.2.2 tls ulfs_root(struct mount *mp, struct vnode **vpp)
91 1.8.2.2 tls {
92 1.8.2.2 tls struct vnode *nvp;
93 1.8.2.2 tls int error;
94 1.8.2.2 tls
95 1.8.2.2 tls if ((error = VFS_VGET(mp, (ino_t)ULFS_ROOTINO, &nvp)) != 0)
96 1.8.2.2 tls return (error);
97 1.8.2.2 tls *vpp = nvp;
98 1.8.2.2 tls return (0);
99 1.8.2.2 tls }
100 1.8.2.2 tls
101 1.8.2.2 tls /*
102 1.8.2.2 tls * Do operations associated with quotas
103 1.8.2.2 tls */
104 1.8.2.2 tls int
105 1.8.2.2 tls ulfs_quotactl(struct mount *mp, struct quotactl_args *args)
106 1.8.2.2 tls {
107 1.8.2.2 tls
108 1.8.2.2 tls #if !defined(LFS_QUOTA) && !defined(LFS_QUOTA2)
109 1.8.2.2 tls (void) mp;
110 1.8.2.2 tls (void) args;
111 1.8.2.2 tls return (EOPNOTSUPP);
112 1.8.2.2 tls #else
113 1.8.2.2 tls struct lwp *l = curlwp;
114 1.8.2.2 tls int error;
115 1.8.2.2 tls
116 1.8.2.2 tls /* Mark the mount busy, as we're passing it to kauth(9). */
117 1.8.2.2 tls error = vfs_busy(mp, NULL);
118 1.8.2.2 tls if (error) {
119 1.8.2.2 tls return (error);
120 1.8.2.2 tls }
121 1.8.2.2 tls mutex_enter(&mp->mnt_updating);
122 1.8.2.2 tls
123 1.8.2.2 tls error = lfsquota_handle_cmd(mp, l, args);
124 1.8.2.2 tls
125 1.8.2.2 tls mutex_exit(&mp->mnt_updating);
126 1.8.2.2 tls vfs_unbusy(mp, false, NULL);
127 1.8.2.2 tls return (error);
128 1.8.2.2 tls #endif
129 1.8.2.2 tls }
130 1.8.2.2 tls
131 1.8.2.2 tls #if 0
132 1.8.2.2 tls switch (cmd) {
133 1.8.2.2 tls case Q_SYNC:
134 1.8.2.2 tls break;
135 1.8.2.2 tls
136 1.8.2.2 tls case Q_GETQUOTA:
137 1.8.2.2 tls /* The user can always query about his own quota. */
138 1.8.2.2 tls if (uid == kauth_cred_getuid(l->l_cred))
139 1.8.2.2 tls break;
140 1.8.2.2 tls
141 1.8.2.2 tls error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
142 1.8.2.2 tls KAUTH_REQ_SYSTEM_FS_QUOTA_GET, mp, KAUTH_ARG(uid), NULL);
143 1.8.2.2 tls
144 1.8.2.2 tls break;
145 1.8.2.2 tls
146 1.8.2.2 tls case Q_QUOTAON:
147 1.8.2.2 tls case Q_QUOTAOFF:
148 1.8.2.2 tls error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
149 1.8.2.2 tls KAUTH_REQ_SYSTEM_FS_QUOTA_ONOFF, mp, NULL, NULL);
150 1.8.2.2 tls
151 1.8.2.2 tls break;
152 1.8.2.2 tls
153 1.8.2.2 tls case Q_SETQUOTA:
154 1.8.2.2 tls case Q_SETUSE:
155 1.8.2.2 tls error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_FS_QUOTA,
156 1.8.2.2 tls KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE, mp, KAUTH_ARG(uid), NULL);
157 1.8.2.2 tls
158 1.8.2.2 tls break;
159 1.8.2.2 tls
160 1.8.2.2 tls default:
161 1.8.2.2 tls error = EINVAL;
162 1.8.2.2 tls break;
163 1.8.2.2 tls }
164 1.8.2.2 tls
165 1.8.2.2 tls type = cmds & SUBCMDMASK;
166 1.8.2.2 tls if (!error) {
167 1.8.2.2 tls /* Only check if there was no error above. */
168 1.8.2.2 tls if ((u_int)type >= MAXQUOTAS)
169 1.8.2.2 tls error = EINVAL;
170 1.8.2.2 tls }
171 1.8.2.2 tls
172 1.8.2.2 tls if (error) {
173 1.8.2.2 tls vfs_unbusy(mp, false, NULL);
174 1.8.2.2 tls return (error);
175 1.8.2.2 tls }
176 1.8.2.2 tls
177 1.8.2.2 tls mutex_enter(&mp->mnt_updating);
178 1.8.2.2 tls switch (cmd) {
179 1.8.2.2 tls
180 1.8.2.2 tls case Q_QUOTAON:
181 1.8.2.2 tls error = quotaon(l, mp, type, arg);
182 1.8.2.2 tls break;
183 1.8.2.2 tls
184 1.8.2.2 tls case Q_QUOTAOFF:
185 1.8.2.2 tls error = quotaoff(l, mp, type);
186 1.8.2.2 tls break;
187 1.8.2.2 tls
188 1.8.2.2 tls case Q_SETQUOTA:
189 1.8.2.2 tls error = setquota(mp, uid, type, arg);
190 1.8.2.2 tls break;
191 1.8.2.2 tls
192 1.8.2.2 tls case Q_SETUSE:
193 1.8.2.2 tls error = setuse(mp, uid, type, arg);
194 1.8.2.2 tls break;
195 1.8.2.2 tls
196 1.8.2.2 tls case Q_GETQUOTA:
197 1.8.2.2 tls error = getquota(mp, uid, type, arg);
198 1.8.2.2 tls break;
199 1.8.2.2 tls
200 1.8.2.2 tls case Q_SYNC:
201 1.8.2.2 tls error = lfs_qsync(mp);
202 1.8.2.2 tls break;
203 1.8.2.2 tls
204 1.8.2.2 tls default:
205 1.8.2.2 tls error = EINVAL;
206 1.8.2.2 tls }
207 1.8.2.2 tls mutex_exit(&mp->mnt_updating);
208 1.8.2.2 tls vfs_unbusy(mp, false, NULL);
209 1.8.2.2 tls return (error);
210 1.8.2.2 tls #endif
211 1.8.2.2 tls
212 1.8.2.2 tls /*
213 1.8.2.2 tls * This is the generic part of fhtovp called after the underlying
214 1.8.2.2 tls * filesystem has validated the file handle.
215 1.8.2.2 tls */
216 1.8.2.2 tls int
217 1.8.2.2 tls ulfs_fhtovp(struct mount *mp, struct ulfs_ufid *ufhp, struct vnode **vpp)
218 1.8.2.2 tls {
219 1.8.2.2 tls struct vnode *nvp;
220 1.8.2.2 tls struct inode *ip;
221 1.8.2.2 tls int error;
222 1.8.2.2 tls
223 1.8.2.2 tls if ((error = VFS_VGET(mp, ufhp->ufid_ino, &nvp)) != 0) {
224 1.8.2.2 tls *vpp = NULLVP;
225 1.8.2.2 tls return (error);
226 1.8.2.2 tls }
227 1.8.2.2 tls ip = VTOI(nvp);
228 1.8.2.2 tls KASSERT(ip != NULL);
229 1.8.2.2 tls if (ip->i_mode == 0 || ip->i_gen != ufhp->ufid_gen) {
230 1.8.2.2 tls vput(nvp);
231 1.8.2.2 tls *vpp = NULLVP;
232 1.8.2.2 tls return (ESTALE);
233 1.8.2.2 tls }
234 1.8.2.2 tls *vpp = nvp;
235 1.8.2.2 tls return (0);
236 1.8.2.2 tls }
237 1.8.2.2 tls
238 1.8.2.2 tls /*
239 1.8.2.2 tls * Initialize ULFS filesystems, done only once.
240 1.8.2.2 tls */
241 1.8.2.2 tls void
242 1.8.2.2 tls ulfs_init(void)
243 1.8.2.2 tls {
244 1.8.2.2 tls if (ulfs_initcount++ > 0)
245 1.8.2.2 tls return;
246 1.8.2.2 tls
247 1.8.2.2 tls ulfs_direct_cache = pool_cache_init(sizeof(struct lfs_direct), 0, 0, 0,
248 1.8.2.2 tls "ulfsdir", NULL, IPL_NONE, NULL, NULL, NULL);
249 1.8.2.2 tls
250 1.8.2.2 tls ulfs_ihashinit();
251 1.8.2.2 tls #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
252 1.8.2.2 tls lfs_dqinit();
253 1.8.2.2 tls #endif
254 1.8.2.2 tls #ifdef LFS_DIRHASH
255 1.8.2.2 tls ulfsdirhash_init();
256 1.8.2.2 tls #endif
257 1.8.2.2 tls #ifdef LFS_EXTATTR
258 1.8.2.2 tls ulfs_extattr_init();
259 1.8.2.2 tls #endif
260 1.8.2.2 tls }
261 1.8.2.2 tls
262 1.8.2.2 tls void
263 1.8.2.2 tls ulfs_reinit(void)
264 1.8.2.2 tls {
265 1.8.2.2 tls ulfs_ihashreinit();
266 1.8.2.2 tls #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
267 1.8.2.2 tls lfs_dqreinit();
268 1.8.2.2 tls #endif
269 1.8.2.2 tls }
270 1.8.2.2 tls
271 1.8.2.2 tls /*
272 1.8.2.2 tls * Free ULFS filesystem resources, done only once.
273 1.8.2.2 tls */
274 1.8.2.2 tls void
275 1.8.2.2 tls ulfs_done(void)
276 1.8.2.2 tls {
277 1.8.2.2 tls if (--ulfs_initcount > 0)
278 1.8.2.2 tls return;
279 1.8.2.2 tls
280 1.8.2.2 tls ulfs_ihashdone();
281 1.8.2.2 tls #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
282 1.8.2.2 tls lfs_dqdone();
283 1.8.2.2 tls #endif
284 1.8.2.2 tls pool_cache_destroy(ulfs_direct_cache);
285 1.8.2.2 tls #ifdef LFS_DIRHASH
286 1.8.2.2 tls ulfsdirhash_done();
287 1.8.2.2 tls #endif
288 1.8.2.2 tls #ifdef LFS_EXTATTR
289 1.8.2.2 tls ulfs_extattr_done();
290 1.8.2.2 tls #endif
291 1.8.2.2 tls }
292