ffs_vnops.c revision 1.132 1 1.132 christos /* $NetBSD: ffs_vnops.c,v 1.132 2020/05/16 18:31:53 christos Exp $ */
2 1.100 simonb
3 1.100 simonb /*-
4 1.109 ad * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
5 1.100 simonb * All rights reserved.
6 1.100 simonb *
7 1.100 simonb * This code is derived from software contributed to The NetBSD Foundation
8 1.109 ad * by Wasabi Systems, Inc, and by Andrew Doran.
9 1.100 simonb *
10 1.100 simonb * Redistribution and use in source and binary forms, with or without
11 1.100 simonb * modification, are permitted provided that the following conditions
12 1.100 simonb * are met:
13 1.100 simonb * 1. Redistributions of source code must retain the above copyright
14 1.100 simonb * notice, this list of conditions and the following disclaimer.
15 1.100 simonb * 2. Redistributions in binary form must reproduce the above copyright
16 1.100 simonb * notice, this list of conditions and the following disclaimer in the
17 1.100 simonb * documentation and/or other materials provided with the distribution.
18 1.100 simonb *
19 1.100 simonb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.100 simonb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.100 simonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.100 simonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.100 simonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.100 simonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.100 simonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.100 simonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.100 simonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.100 simonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.100 simonb * POSSIBILITY OF SUCH DAMAGE.
30 1.100 simonb */
31 1.3 cgd
32 1.1 mycroft /*
33 1.1 mycroft * Copyright (c) 1982, 1986, 1989, 1993
34 1.1 mycroft * The Regents of the University of California. All rights reserved.
35 1.1 mycroft *
36 1.1 mycroft * Redistribution and use in source and binary forms, with or without
37 1.1 mycroft * modification, are permitted provided that the following conditions
38 1.1 mycroft * are met:
39 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
40 1.1 mycroft * notice, this list of conditions and the following disclaimer.
41 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
42 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
43 1.1 mycroft * documentation and/or other materials provided with the distribution.
44 1.60 agc * 3. Neither the name of the University nor the names of its contributors
45 1.1 mycroft * may be used to endorse or promote products derived from this software
46 1.1 mycroft * without specific prior written permission.
47 1.1 mycroft *
48 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 1.1 mycroft * SUCH DAMAGE.
59 1.1 mycroft *
60 1.12 fvdl * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
61 1.1 mycroft */
62 1.44 lukem
63 1.44 lukem #include <sys/cdefs.h>
64 1.132 christos __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.132 2020/05/16 18:31:53 christos Exp $");
65 1.100 simonb
66 1.100 simonb #if defined(_KERNEL_OPT)
67 1.100 simonb #include "opt_ffs.h"
68 1.100 simonb #include "opt_wapbl.h"
69 1.100 simonb #endif
70 1.11 mrg
71 1.1 mycroft #include <sys/param.h>
72 1.1 mycroft #include <sys/systm.h>
73 1.1 mycroft #include <sys/resourcevar.h>
74 1.1 mycroft #include <sys/kernel.h>
75 1.1 mycroft #include <sys/file.h>
76 1.1 mycroft #include <sys/stat.h>
77 1.1 mycroft #include <sys/buf.h>
78 1.50 jdolecek #include <sys/event.h>
79 1.1 mycroft #include <sys/proc.h>
80 1.1 mycroft #include <sys/mount.h>
81 1.1 mycroft #include <sys/vnode.h>
82 1.16 thorpej #include <sys/pool.h>
83 1.6 christos #include <sys/signalvar.h>
84 1.80 elad #include <sys/kauth.h>
85 1.100 simonb #include <sys/wapbl.h>
86 1.1 mycroft
87 1.8 mycroft #include <miscfs/fifofs/fifo.h>
88 1.8 mycroft #include <miscfs/genfs/genfs.h>
89 1.1 mycroft #include <miscfs/specfs/specdev.h>
90 1.1 mycroft
91 1.132 christos #include <ufs/ufs/acl.h>
92 1.1 mycroft #include <ufs/ufs/inode.h>
93 1.1 mycroft #include <ufs/ufs/dir.h>
94 1.1 mycroft #include <ufs/ufs/ufs_extern.h>
95 1.2 mycroft #include <ufs/ufs/ufsmount.h>
96 1.100 simonb #include <ufs/ufs/ufs_wapbl.h>
97 1.1 mycroft
98 1.1 mycroft #include <ufs/ffs/fs.h>
99 1.1 mycroft #include <ufs/ffs/ffs_extern.h>
100 1.1 mycroft
101 1.49 chs #include <uvm/uvm.h>
102 1.49 chs
103 1.1 mycroft /* Global vfs data structures for ufs. */
104 1.74 xtraeme int (**ffs_vnodeop_p)(void *);
105 1.37 jdolecek const struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
106 1.1 mycroft { &vop_default_desc, vn_default_error },
107 1.1 mycroft { &vop_lookup_desc, ufs_lookup }, /* lookup */
108 1.1 mycroft { &vop_create_desc, ufs_create }, /* create */
109 1.5 mycroft { &vop_whiteout_desc, ufs_whiteout }, /* whiteout */
110 1.1 mycroft { &vop_mknod_desc, ufs_mknod }, /* mknod */
111 1.1 mycroft { &vop_open_desc, ufs_open }, /* open */
112 1.1 mycroft { &vop_close_desc, ufs_close }, /* close */
113 1.132 christos { &vop_access_desc, genfs_access }, /* access */
114 1.132 christos { &vop_accessx_desc, ufs_accessx }, /* accessx */
115 1.1 mycroft { &vop_getattr_desc, ufs_getattr }, /* getattr */
116 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
117 1.1 mycroft { &vop_read_desc, ffs_read }, /* read */
118 1.1 mycroft { &vop_write_desc, ffs_write }, /* write */
119 1.125 dholland { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */
120 1.125 dholland { &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */
121 1.1 mycroft { &vop_ioctl_desc, ufs_ioctl }, /* ioctl */
122 1.19 wrstuden { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
123 1.9 mycroft { &vop_poll_desc, ufs_poll }, /* poll */
124 1.50 jdolecek { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */
125 1.12 fvdl { &vop_revoke_desc, ufs_revoke }, /* revoke */
126 1.1 mycroft { &vop_mmap_desc, ufs_mmap }, /* mmap */
127 1.1 mycroft { &vop_fsync_desc, ffs_fsync }, /* fsync */
128 1.1 mycroft { &vop_seek_desc, ufs_seek }, /* seek */
129 1.1 mycroft { &vop_remove_desc, ufs_remove }, /* remove */
130 1.1 mycroft { &vop_link_desc, ufs_link }, /* link */
131 1.1 mycroft { &vop_rename_desc, ufs_rename }, /* rename */
132 1.1 mycroft { &vop_mkdir_desc, ufs_mkdir }, /* mkdir */
133 1.1 mycroft { &vop_rmdir_desc, ufs_rmdir }, /* rmdir */
134 1.1 mycroft { &vop_symlink_desc, ufs_symlink }, /* symlink */
135 1.1 mycroft { &vop_readdir_desc, ufs_readdir }, /* readdir */
136 1.1 mycroft { &vop_readlink_desc, ufs_readlink }, /* readlink */
137 1.1 mycroft { &vop_abortop_desc, ufs_abortop }, /* abortop */
138 1.1 mycroft { &vop_inactive_desc, ufs_inactive }, /* inactive */
139 1.1 mycroft { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
140 1.113 hannken { &vop_lock_desc, ufs_lock }, /* lock */
141 1.113 hannken { &vop_unlock_desc, ufs_unlock }, /* unlock */
142 1.1 mycroft { &vop_bmap_desc, ufs_bmap }, /* bmap */
143 1.1 mycroft { &vop_strategy_desc, ufs_strategy }, /* strategy */
144 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
145 1.113 hannken { &vop_islocked_desc, ufs_islocked }, /* islocked */
146 1.1 mycroft { &vop_pathconf_desc, ufs_pathconf }, /* pathconf */
147 1.1 mycroft { &vop_advlock_desc, ufs_advlock }, /* advlock */
148 1.8 mycroft { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
149 1.88 yamt { &vop_getpages_desc, genfs_getpages }, /* getpages */
150 1.75 yamt { &vop_putpages_desc, genfs_putpages }, /* putpages */
151 1.73 thorpej { &vop_openextattr_desc, ffs_openextattr }, /* openextattr */
152 1.73 thorpej { &vop_closeextattr_desc, ffs_closeextattr }, /* closeextattr */
153 1.73 thorpej { &vop_getextattr_desc, ffs_getextattr }, /* getextattr */
154 1.73 thorpej { &vop_setextattr_desc, ffs_setextattr }, /* setextattr */
155 1.73 thorpej { &vop_listextattr_desc, ffs_listextattr }, /* listextattr */
156 1.73 thorpej { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
157 1.132 christos { &vop_getacl_desc, ufs_getacl }, /* getacl */
158 1.132 christos { &vop_setacl_desc, ufs_setacl }, /* setacl */
159 1.132 christos { &vop_aclcheck_desc, ufs_aclcheck }, /* aclcheck */
160 1.35 chs { NULL, NULL }
161 1.1 mycroft };
162 1.37 jdolecek const struct vnodeopv_desc ffs_vnodeop_opv_desc =
163 1.1 mycroft { &ffs_vnodeop_p, ffs_vnodeop_entries };
164 1.1 mycroft
165 1.74 xtraeme int (**ffs_specop_p)(void *);
166 1.37 jdolecek const struct vnodeopv_entry_desc ffs_specop_entries[] = {
167 1.1 mycroft { &vop_default_desc, vn_default_error },
168 1.1 mycroft { &vop_lookup_desc, spec_lookup }, /* lookup */
169 1.1 mycroft { &vop_create_desc, spec_create }, /* create */
170 1.1 mycroft { &vop_mknod_desc, spec_mknod }, /* mknod */
171 1.1 mycroft { &vop_open_desc, spec_open }, /* open */
172 1.1 mycroft { &vop_close_desc, ufsspec_close }, /* close */
173 1.132 christos { &vop_access_desc, genfs_access }, /* access */
174 1.132 christos { &vop_accessx_desc, ufs_accessx }, /* accessx */
175 1.1 mycroft { &vop_getattr_desc, ufs_getattr }, /* getattr */
176 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
177 1.1 mycroft { &vop_read_desc, ufsspec_read }, /* read */
178 1.1 mycroft { &vop_write_desc, ufsspec_write }, /* write */
179 1.125 dholland { &vop_fallocate_desc, spec_fallocate }, /* fallocate */
180 1.125 dholland { &vop_fdiscard_desc, spec_fdiscard }, /* fdiscard */
181 1.1 mycroft { &vop_ioctl_desc, spec_ioctl }, /* ioctl */
182 1.19 wrstuden { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
183 1.9 mycroft { &vop_poll_desc, spec_poll }, /* poll */
184 1.50 jdolecek { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */
185 1.12 fvdl { &vop_revoke_desc, spec_revoke }, /* revoke */
186 1.1 mycroft { &vop_mmap_desc, spec_mmap }, /* mmap */
187 1.118 hannken { &vop_fsync_desc, ffs_spec_fsync }, /* fsync */
188 1.1 mycroft { &vop_seek_desc, spec_seek }, /* seek */
189 1.1 mycroft { &vop_remove_desc, spec_remove }, /* remove */
190 1.1 mycroft { &vop_link_desc, spec_link }, /* link */
191 1.1 mycroft { &vop_rename_desc, spec_rename }, /* rename */
192 1.1 mycroft { &vop_mkdir_desc, spec_mkdir }, /* mkdir */
193 1.1 mycroft { &vop_rmdir_desc, spec_rmdir }, /* rmdir */
194 1.1 mycroft { &vop_symlink_desc, spec_symlink }, /* symlink */
195 1.1 mycroft { &vop_readdir_desc, spec_readdir }, /* readdir */
196 1.1 mycroft { &vop_readlink_desc, spec_readlink }, /* readlink */
197 1.1 mycroft { &vop_abortop_desc, spec_abortop }, /* abortop */
198 1.1 mycroft { &vop_inactive_desc, ufs_inactive }, /* inactive */
199 1.1 mycroft { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
200 1.113 hannken { &vop_lock_desc, ufs_lock }, /* lock */
201 1.113 hannken { &vop_unlock_desc, ufs_unlock }, /* unlock */
202 1.1 mycroft { &vop_bmap_desc, spec_bmap }, /* bmap */
203 1.1 mycroft { &vop_strategy_desc, spec_strategy }, /* strategy */
204 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
205 1.113 hannken { &vop_islocked_desc, ufs_islocked }, /* islocked */
206 1.1 mycroft { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
207 1.1 mycroft { &vop_advlock_desc, spec_advlock }, /* advlock */
208 1.8 mycroft { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
209 1.38 chs { &vop_getpages_desc, spec_getpages }, /* getpages */
210 1.38 chs { &vop_putpages_desc, spec_putpages }, /* putpages */
211 1.73 thorpej { &vop_openextattr_desc, ffs_openextattr }, /* openextattr */
212 1.73 thorpej { &vop_closeextattr_desc, ffs_closeextattr }, /* closeextattr */
213 1.73 thorpej { &vop_getextattr_desc, ffs_getextattr }, /* getextattr */
214 1.73 thorpej { &vop_setextattr_desc, ffs_setextattr }, /* setextattr */
215 1.73 thorpej { &vop_listextattr_desc, ffs_listextattr }, /* listextattr */
216 1.73 thorpej { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
217 1.132 christos { &vop_getacl_desc, ufs_getacl }, /* getacl */
218 1.132 christos { &vop_setacl_desc, ufs_setacl }, /* setacl */
219 1.132 christos { &vop_aclcheck_desc, ufs_aclcheck }, /* aclcheck */
220 1.35 chs { NULL, NULL }
221 1.1 mycroft };
222 1.37 jdolecek const struct vnodeopv_desc ffs_specop_opv_desc =
223 1.1 mycroft { &ffs_specop_p, ffs_specop_entries };
224 1.1 mycroft
225 1.74 xtraeme int (**ffs_fifoop_p)(void *);
226 1.37 jdolecek const struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
227 1.1 mycroft { &vop_default_desc, vn_default_error },
228 1.114 pooka { &vop_lookup_desc, vn_fifo_bypass }, /* lookup */
229 1.114 pooka { &vop_create_desc, vn_fifo_bypass }, /* create */
230 1.114 pooka { &vop_mknod_desc, vn_fifo_bypass }, /* mknod */
231 1.114 pooka { &vop_open_desc, vn_fifo_bypass }, /* open */
232 1.1 mycroft { &vop_close_desc, ufsfifo_close }, /* close */
233 1.132 christos { &vop_access_desc, genfs_access }, /* access */
234 1.132 christos { &vop_accessx_desc, ufs_accessx }, /* accessx */
235 1.1 mycroft { &vop_getattr_desc, ufs_getattr }, /* getattr */
236 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
237 1.1 mycroft { &vop_read_desc, ufsfifo_read }, /* read */
238 1.1 mycroft { &vop_write_desc, ufsfifo_write }, /* write */
239 1.125 dholland { &vop_fallocate_desc, vn_fifo_bypass }, /* fallocate */
240 1.125 dholland { &vop_fdiscard_desc, vn_fifo_bypass }, /* fdiscard */
241 1.114 pooka { &vop_ioctl_desc, vn_fifo_bypass }, /* ioctl */
242 1.19 wrstuden { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
243 1.114 pooka { &vop_poll_desc, vn_fifo_bypass }, /* poll */
244 1.114 pooka { &vop_kqfilter_desc, vn_fifo_bypass }, /* kqfilter */
245 1.114 pooka { &vop_revoke_desc, vn_fifo_bypass }, /* revoke */
246 1.114 pooka { &vop_mmap_desc, vn_fifo_bypass }, /* mmap */
247 1.1 mycroft { &vop_fsync_desc, ffs_fsync }, /* fsync */
248 1.114 pooka { &vop_seek_desc, vn_fifo_bypass }, /* seek */
249 1.114 pooka { &vop_remove_desc, vn_fifo_bypass }, /* remove */
250 1.114 pooka { &vop_link_desc, vn_fifo_bypass }, /* link */
251 1.114 pooka { &vop_rename_desc, vn_fifo_bypass }, /* rename */
252 1.114 pooka { &vop_mkdir_desc, vn_fifo_bypass }, /* mkdir */
253 1.114 pooka { &vop_rmdir_desc, vn_fifo_bypass }, /* rmdir */
254 1.114 pooka { &vop_symlink_desc, vn_fifo_bypass }, /* symlink */
255 1.114 pooka { &vop_readdir_desc, vn_fifo_bypass }, /* readdir */
256 1.114 pooka { &vop_readlink_desc, vn_fifo_bypass }, /* readlink */
257 1.114 pooka { &vop_abortop_desc, vn_fifo_bypass }, /* abortop */
258 1.1 mycroft { &vop_inactive_desc, ufs_inactive }, /* inactive */
259 1.1 mycroft { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
260 1.113 hannken { &vop_lock_desc, ufs_lock }, /* lock */
261 1.113 hannken { &vop_unlock_desc, ufs_unlock }, /* unlock */
262 1.114 pooka { &vop_bmap_desc, vn_fifo_bypass }, /* bmap */
263 1.114 pooka { &vop_strategy_desc, vn_fifo_bypass }, /* strategy */
264 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
265 1.113 hannken { &vop_islocked_desc, ufs_islocked }, /* islocked */
266 1.114 pooka { &vop_pathconf_desc, vn_fifo_bypass }, /* pathconf */
267 1.114 pooka { &vop_advlock_desc, vn_fifo_bypass }, /* advlock */
268 1.8 mycroft { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
269 1.114 pooka { &vop_putpages_desc, vn_fifo_bypass }, /* putpages */
270 1.73 thorpej { &vop_openextattr_desc, ffs_openextattr }, /* openextattr */
271 1.73 thorpej { &vop_closeextattr_desc, ffs_closeextattr }, /* closeextattr */
272 1.73 thorpej { &vop_getextattr_desc, ffs_getextattr }, /* getextattr */
273 1.73 thorpej { &vop_setextattr_desc, ffs_setextattr }, /* setextattr */
274 1.73 thorpej { &vop_listextattr_desc, ffs_listextattr }, /* listextattr */
275 1.73 thorpej { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
276 1.132 christos { &vop_getacl_desc, ufs_getacl }, /* getacl */
277 1.132 christos { &vop_setacl_desc, ufs_setacl }, /* setacl */
278 1.132 christos { &vop_aclcheck_desc, ufs_aclcheck }, /* aclcheck */
279 1.35 chs { NULL, NULL }
280 1.1 mycroft };
281 1.37 jdolecek const struct vnodeopv_desc ffs_fifoop_opv_desc =
282 1.1 mycroft { &ffs_fifoop_p, ffs_fifoop_entries };
283 1.1 mycroft
284 1.1 mycroft #include <ufs/ufs/ufs_readwrite.c>
285 1.20 fvdl
286 1.33 fvdl int
287 1.118 hannken ffs_spec_fsync(void *v)
288 1.118 hannken {
289 1.118 hannken struct vop_fsync_args /* {
290 1.118 hannken struct vnode *a_vp;
291 1.118 hannken kauth_cred_t a_cred;
292 1.118 hannken int a_flags;
293 1.118 hannken off_t a_offlo;
294 1.118 hannken off_t a_offhi;
295 1.118 hannken struct lwp *a_l;
296 1.118 hannken } */ *ap = v;
297 1.118 hannken int error, flags, uflags;
298 1.118 hannken struct vnode *vp;
299 1.118 hannken
300 1.118 hannken flags = ap->a_flags;
301 1.118 hannken uflags = UPDATE_CLOSE | ((flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
302 1.118 hannken vp = ap->a_vp;
303 1.118 hannken
304 1.118 hannken error = spec_fsync(v);
305 1.118 hannken if (error)
306 1.118 hannken goto out;
307 1.118 hannken
308 1.118 hannken #ifdef WAPBL
309 1.128 christos struct mount *mp = vp->v_mount;
310 1.128 christos
311 1.118 hannken if (mp && mp->mnt_wapbl) {
312 1.118 hannken /*
313 1.118 hannken * Don't bother writing out metadata if the syncer is
314 1.118 hannken * making the request. We will let the sync vnode
315 1.118 hannken * write it out in a single burst through a call to
316 1.118 hannken * VFS_SYNC().
317 1.118 hannken */
318 1.118 hannken if ((flags & (FSYNC_DATAONLY | FSYNC_LAZY)) != 0)
319 1.118 hannken goto out;
320 1.118 hannken if ((VTOI(vp)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE
321 1.118 hannken | IN_MODIFY | IN_MODIFIED | IN_ACCESSED)) != 0) {
322 1.118 hannken error = UFS_WAPBL_BEGIN(mp);
323 1.118 hannken if (error != 0)
324 1.118 hannken goto out;
325 1.118 hannken error = ffs_update(vp, NULL, NULL, uflags);
326 1.118 hannken UFS_WAPBL_END(mp);
327 1.118 hannken }
328 1.118 hannken goto out;
329 1.118 hannken }
330 1.118 hannken #endif /* WAPBL */
331 1.118 hannken
332 1.118 hannken error = ffs_update(vp, NULL, NULL, uflags);
333 1.118 hannken
334 1.118 hannken out:
335 1.118 hannken return error;
336 1.118 hannken }
337 1.118 hannken
338 1.118 hannken int
339 1.70 thorpej ffs_fsync(void *v)
340 1.33 fvdl {
341 1.33 fvdl struct vop_fsync_args /* {
342 1.33 fvdl struct vnode *a_vp;
343 1.80 elad kauth_cred_t a_cred;
344 1.33 fvdl int a_flags;
345 1.46 chs off_t a_offlo;
346 1.46 chs off_t a_offhi;
347 1.77 christos struct lwp *a_l;
348 1.33 fvdl } */ *ap = v;
349 1.35 chs struct buf *bp;
350 1.94 ad int num, error, i;
351 1.122 dholland struct indir ia[UFS_NIADDR + 1];
352 1.33 fvdl int bsize;
353 1.45 simonb daddr_t blk_high;
354 1.33 fvdl struct vnode *vp;
355 1.100 simonb struct mount *mp;
356 1.33 fvdl
357 1.84 hannken vp = ap->a_vp;
358 1.117 hannken mp = vp->v_mount;
359 1.84 hannken
360 1.111 ad if ((ap->a_offlo == 0 && ap->a_offhi == 0) || (vp->v_type != VREG)) {
361 1.111 ad error = ffs_full_fsync(vp, ap->a_flags);
362 1.84 hannken goto out;
363 1.84 hannken }
364 1.33 fvdl
365 1.117 hannken bsize = mp->mnt_stat.f_iosize;
366 1.33 fvdl blk_high = ap->a_offhi / bsize;
367 1.33 fvdl if (ap->a_offhi % bsize != 0)
368 1.33 fvdl blk_high++;
369 1.33 fvdl
370 1.33 fvdl /*
371 1.35 chs * First, flush all pages in range.
372 1.33 fvdl */
373 1.35 chs
374 1.130 ad rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
375 1.64 dbj error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
376 1.64 dbj round_page(ap->a_offhi), PGO_CLEANIT |
377 1.64 dbj ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0));
378 1.64 dbj if (error) {
379 1.84 hannken goto out;
380 1.39 chs }
381 1.33 fvdl
382 1.100 simonb #ifdef WAPBL
383 1.117 hannken KASSERT(vp->v_type == VREG);
384 1.100 simonb if (mp->mnt_wapbl) {
385 1.110 ad /*
386 1.110 ad * Don't bother writing out metadata if the syncer is
387 1.110 ad * making the request. We will let the sync vnode
388 1.110 ad * write it out in a single burst through a call to
389 1.110 ad * VFS_SYNC().
390 1.110 ad */
391 1.110 ad if ((ap->a_flags & (FSYNC_DATAONLY | FSYNC_LAZY)) != 0) {
392 1.100 simonb return 0;
393 1.100 simonb }
394 1.100 simonb error = 0;
395 1.100 simonb if (vp->v_tag == VT_UFS && VTOI(vp)->i_flag &
396 1.100 simonb (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY |
397 1.100 simonb IN_MODIFIED | IN_ACCESSED)) {
398 1.100 simonb error = UFS_WAPBL_BEGIN(mp);
399 1.100 simonb if (error) {
400 1.100 simonb return error;
401 1.100 simonb }
402 1.112 ad error = ffs_update(vp, NULL, NULL, UPDATE_CLOSE |
403 1.112 ad ((ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0));
404 1.100 simonb UFS_WAPBL_END(mp);
405 1.100 simonb }
406 1.110 ad if (error || (ap->a_flags & FSYNC_NOLOG) != 0) {
407 1.100 simonb return error;
408 1.100 simonb }
409 1.100 simonb error = wapbl_flush(mp->mnt_wapbl, 0);
410 1.100 simonb return error;
411 1.100 simonb }
412 1.100 simonb #endif /* WAPBL */
413 1.100 simonb
414 1.33 fvdl /*
415 1.35 chs * Then, flush indirect blocks.
416 1.33 fvdl */
417 1.35 chs
418 1.122 dholland if (blk_high >= UFS_NDADDR) {
419 1.33 fvdl error = ufs_getlbns(vp, blk_high, ia, &num);
420 1.94 ad if (error)
421 1.84 hannken goto out;
422 1.94 ad
423 1.94 ad mutex_enter(&bufcache_lock);
424 1.33 fvdl for (i = 0; i < num; i++) {
425 1.94 ad if ((bp = incore(vp, ia[i].in_lbn)) == NULL)
426 1.94 ad continue;
427 1.94 ad if ((bp->b_cflags & BC_BUSY) != 0 ||
428 1.94 ad (bp->b_oflags & BO_DELWRI) == 0)
429 1.94 ad continue;
430 1.94 ad bp->b_cflags |= BC_BUSY | BC_VFLUSH;
431 1.94 ad mutex_exit(&bufcache_lock);
432 1.94 ad bawrite(bp);
433 1.94 ad mutex_enter(&bufcache_lock);
434 1.33 fvdl }
435 1.94 ad mutex_exit(&bufcache_lock);
436 1.33 fvdl }
437 1.33 fvdl
438 1.33 fvdl if (ap->a_flags & FSYNC_WAIT) {
439 1.119 rmind mutex_enter(vp->v_interlock);
440 1.94 ad while (vp->v_numoutput > 0)
441 1.119 rmind cv_wait(&vp->v_cv, vp->v_interlock);
442 1.119 rmind mutex_exit(vp->v_interlock);
443 1.33 fvdl }
444 1.33 fvdl
445 1.112 ad error = ffs_update(vp, NULL, NULL, UPDATE_CLOSE |
446 1.112 ad (((ap->a_flags & (FSYNC_WAIT | FSYNC_DATAONLY)) == FSYNC_WAIT)
447 1.112 ad ? UPDATE_WAIT : 0));
448 1.67 wrstuden
449 1.67 wrstuden if (error == 0 && ap->a_flags & FSYNC_CACHE) {
450 1.67 wrstuden int l = 0;
451 1.67 wrstuden VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE,
452 1.93 pooka curlwp->l_cred);
453 1.67 wrstuden }
454 1.67 wrstuden
455 1.84 hannken out:
456 1.67 wrstuden return error;
457 1.33 fvdl }
458 1.33 fvdl
459 1.20 fvdl /*
460 1.110 ad * Synch an open file. Called for VOP_FSYNC().
461 1.20 fvdl */
462 1.20 fvdl /* ARGSUSED */
463 1.94 ad int
464 1.94 ad ffs_full_fsync(struct vnode *vp, int flags)
465 1.20 fvdl {
466 1.118 hannken int error, i, uflags;
467 1.99 ad
468 1.118 hannken KASSERT(vp->v_tag == VT_UFS);
469 1.110 ad KASSERT(VTOI(vp) != NULL);
470 1.118 hannken KASSERT(vp->v_type != VCHR && vp->v_type != VBLK);
471 1.110 ad
472 1.118 hannken uflags = UPDATE_CLOSE | ((flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
473 1.24 fvdl
474 1.121 chs #ifdef WAPBL
475 1.121 chs struct mount *mp = vp->v_mount;
476 1.128 christos
477 1.121 chs if (mp && mp->mnt_wapbl) {
478 1.105 ad
479 1.121 chs /*
480 1.121 chs * Flush all dirty data associated with the vnode.
481 1.121 chs */
482 1.121 chs if (vp->v_type == VREG) {
483 1.121 chs int pflags = PGO_ALLPAGES | PGO_CLEANIT;
484 1.101 oster
485 1.121 chs if ((flags & FSYNC_LAZY))
486 1.121 chs pflags |= PGO_LAZY;
487 1.121 chs if ((flags & FSYNC_WAIT))
488 1.121 chs pflags |= PGO_SYNCIO;
489 1.130 ad rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
490 1.121 chs error = VOP_PUTPAGES(vp, 0, 0, pflags);
491 1.121 chs if (error)
492 1.121 chs return error;
493 1.121 chs }
494 1.100 simonb
495 1.110 ad /*
496 1.110 ad * Don't bother writing out metadata if the syncer is
497 1.110 ad * making the request. We will let the sync vnode
498 1.110 ad * write it out in a single burst through a call to
499 1.110 ad * VFS_SYNC().
500 1.110 ad */
501 1.110 ad if ((flags & (FSYNC_DATAONLY | FSYNC_LAZY)) != 0)
502 1.110 ad return 0;
503 1.100 simonb
504 1.110 ad if ((VTOI(vp)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE
505 1.109 ad | IN_MODIFY | IN_MODIFIED | IN_ACCESSED)) != 0) {
506 1.100 simonb error = UFS_WAPBL_BEGIN(mp);
507 1.100 simonb if (error)
508 1.100 simonb return error;
509 1.118 hannken error = ffs_update(vp, NULL, NULL, uflags);
510 1.100 simonb UFS_WAPBL_END(mp);
511 1.121 chs } else {
512 1.121 chs error = 0;
513 1.100 simonb }
514 1.110 ad if (error || (flags & FSYNC_NOLOG) != 0)
515 1.100 simonb return error;
516 1.106 ad
517 1.100 simonb /*
518 1.100 simonb * Don't flush the log if the vnode being flushed
519 1.100 simonb * contains no dirty buffers that could be in the log.
520 1.100 simonb */
521 1.109 ad if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
522 1.100 simonb error = wapbl_flush(mp->mnt_wapbl, 0);
523 1.100 simonb if (error)
524 1.100 simonb return error;
525 1.100 simonb }
526 1.100 simonb
527 1.109 ad if ((flags & FSYNC_WAIT) != 0) {
528 1.119 rmind mutex_enter(vp->v_interlock);
529 1.110 ad while (vp->v_numoutput != 0)
530 1.119 rmind cv_wait(&vp->v_cv, vp->v_interlock);
531 1.119 rmind mutex_exit(vp->v_interlock);
532 1.100 simonb }
533 1.100 simonb
534 1.100 simonb return error;
535 1.100 simonb }
536 1.100 simonb #endif /* WAPBL */
537 1.35 chs
538 1.121 chs error = vflushbuf(vp, flags);
539 1.118 hannken if (error == 0)
540 1.118 hannken error = ffs_update(vp, NULL, NULL, uflags);
541 1.109 ad if (error == 0 && (flags & FSYNC_CACHE) != 0) {
542 1.118 hannken i = 1;
543 1.110 ad (void)VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &i, FWRITE,
544 1.110 ad kauth_cred_get());
545 1.67 wrstuden }
546 1.67 wrstuden
547 1.67 wrstuden return error;
548 1.20 fvdl }
549 1.1 mycroft
550 1.1 mycroft /*
551 1.1 mycroft * Reclaim an inode so that it can be used for other purposes.
552 1.1 mycroft */
553 1.1 mycroft int
554 1.70 thorpej ffs_reclaim(void *v)
555 1.6 christos {
556 1.129 riastrad struct vop_reclaim_v2_args /* {
557 1.1 mycroft struct vnode *a_vp;
558 1.77 christos struct lwp *a_l;
559 1.6 christos } */ *ap = v;
560 1.26 augustss struct vnode *vp = ap->a_vp;
561 1.56 fvdl struct inode *ip = VTOI(vp);
562 1.84 hannken struct mount *mp = vp->v_mount;
563 1.56 fvdl struct ufsmount *ump = ip->i_ump;
564 1.94 ad void *data;
565 1.1 mycroft int error;
566 1.1 mycroft
567 1.129 riastrad VOP_UNLOCK(vp);
568 1.129 riastrad
569 1.115 hannken /*
570 1.115 hannken * The inode must be freed and updated before being removed
571 1.115 hannken * from its hash chain. Other threads trying to gain a hold
572 1.124 hannken * or lock on the inode will be stalled.
573 1.115 hannken */
574 1.115 hannken error = UFS_WAPBL_BEGIN(mp);
575 1.115 hannken if (error) {
576 1.115 hannken return error;
577 1.115 hannken }
578 1.116 hannken if (ip->i_nlink <= 0 && ip->i_omode != 0 &&
579 1.116 hannken (vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
580 1.115 hannken ffs_vfree(vp, ip->i_number, ip->i_omode);
581 1.115 hannken UFS_WAPBL_END(mp);
582 1.93 pooka if ((error = ufs_reclaim(vp)) != 0) {
583 1.1 mycroft return (error);
584 1.84 hannken }
585 1.57 fvdl if (ip->i_din.ffs1_din != NULL) {
586 1.57 fvdl if (ump->um_fstype == UFS1)
587 1.95 ad pool_cache_put(ffs_dinode1_cache, ip->i_din.ffs1_din);
588 1.57 fvdl else
589 1.95 ad pool_cache_put(ffs_dinode2_cache, ip->i_din.ffs2_din);
590 1.57 fvdl }
591 1.16 thorpej /*
592 1.94 ad * To interlock with ffs_sync().
593 1.94 ad */
594 1.94 ad genfs_node_destroy(vp);
595 1.119 rmind mutex_enter(vp->v_interlock);
596 1.94 ad data = vp->v_data;
597 1.94 ad vp->v_data = NULL;
598 1.119 rmind mutex_exit(vp->v_interlock);
599 1.94 ad
600 1.94 ad /*
601 1.16 thorpej * XXX MFS ends up here, too, to free an inode. Should we create
602 1.16 thorpej * XXX a separate pool for MFS inodes?
603 1.16 thorpej */
604 1.95 ad pool_cache_put(ffs_inode_cache, data);
605 1.1 mycroft return (0);
606 1.35 chs }
607 1.35 chs
608 1.35 chs /*
609 1.35 chs * Return the last logical file offset that should be written for this file
610 1.35 chs * if we're doing a write that ends at "size".
611 1.35 chs */
612 1.39 chs
613 1.39 chs void
614 1.83 christos ffs_gop_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
615 1.35 chs {
616 1.39 chs struct inode *ip = VTOI(vp);
617 1.35 chs struct fs *fs = ip->i_fs;
618 1.52 fvdl daddr_t olbn, nlbn;
619 1.55 perseant
620 1.123 dholland olbn = ffs_lblkno(fs, ip->i_size);
621 1.123 dholland nlbn = ffs_lblkno(fs, size);
622 1.122 dholland if (nlbn < UFS_NDADDR && olbn <= nlbn) {
623 1.123 dholland *eobp = ffs_fragroundup(fs, size);
624 1.35 chs } else {
625 1.123 dholland *eobp = ffs_blkroundup(fs, size);
626 1.35 chs }
627 1.1 mycroft }
628