ffs_vnops.c revision 1.99.4.1 1 1.99.4.1 simonb /* $NetBSD: ffs_vnops.c,v 1.99.4.1 2008/06/10 14:51:23 simonb Exp $ */
2 1.99.4.1 simonb
3 1.99.4.1 simonb /*-
4 1.99.4.1 simonb * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.99.4.1 simonb * All rights reserved.
6 1.99.4.1 simonb *
7 1.99.4.1 simonb * This code is derived from software contributed to The NetBSD Foundation
8 1.99.4.1 simonb * by Wasabi Systems, Inc.
9 1.99.4.1 simonb *
10 1.99.4.1 simonb * Redistribution and use in source and binary forms, with or without
11 1.99.4.1 simonb * modification, are permitted provided that the following conditions
12 1.99.4.1 simonb * are met:
13 1.99.4.1 simonb * 1. Redistributions of source code must retain the above copyright
14 1.99.4.1 simonb * notice, this list of conditions and the following disclaimer.
15 1.99.4.1 simonb * 2. Redistributions in binary form must reproduce the above copyright
16 1.99.4.1 simonb * notice, this list of conditions and the following disclaimer in the
17 1.99.4.1 simonb * documentation and/or other materials provided with the distribution.
18 1.99.4.1 simonb * 3. All advertising materials mentioning features or use of this software
19 1.99.4.1 simonb * must display the following acknowledgement:
20 1.99.4.1 simonb * This product includes software developed by the NetBSD
21 1.99.4.1 simonb * Foundation, Inc. and its contributors.
22 1.99.4.1 simonb * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.99.4.1 simonb * contributors may be used to endorse or promote products derived
24 1.99.4.1 simonb * from this software without specific prior written permission.
25 1.99.4.1 simonb *
26 1.99.4.1 simonb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.99.4.1 simonb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.99.4.1 simonb * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.99.4.1 simonb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.99.4.1 simonb * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.99.4.1 simonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.99.4.1 simonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.99.4.1 simonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.99.4.1 simonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.99.4.1 simonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.99.4.1 simonb * POSSIBILITY OF SUCH DAMAGE.
37 1.99.4.1 simonb */
38 1.3 cgd
39 1.1 mycroft /*
40 1.1 mycroft * Copyright (c) 1982, 1986, 1989, 1993
41 1.1 mycroft * The Regents of the University of California. All rights reserved.
42 1.1 mycroft *
43 1.1 mycroft * Redistribution and use in source and binary forms, with or without
44 1.1 mycroft * modification, are permitted provided that the following conditions
45 1.1 mycroft * are met:
46 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
47 1.1 mycroft * notice, this list of conditions and the following disclaimer.
48 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
49 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
50 1.1 mycroft * documentation and/or other materials provided with the distribution.
51 1.60 agc * 3. Neither the name of the University nor the names of its contributors
52 1.1 mycroft * may be used to endorse or promote products derived from this software
53 1.1 mycroft * without specific prior written permission.
54 1.1 mycroft *
55 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 1.1 mycroft * SUCH DAMAGE.
66 1.1 mycroft *
67 1.12 fvdl * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
68 1.1 mycroft */
69 1.44 lukem
70 1.44 lukem #include <sys/cdefs.h>
71 1.99.4.1 simonb __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.99.4.1 2008/06/10 14:51:23 simonb Exp $");
72 1.99.4.1 simonb
73 1.99.4.1 simonb #if defined(_KERNEL_OPT)
74 1.99.4.1 simonb #include "opt_ffs.h"
75 1.99.4.1 simonb #include "opt_wapbl.h"
76 1.99.4.1 simonb #endif
77 1.11 mrg
78 1.1 mycroft #include <sys/param.h>
79 1.1 mycroft #include <sys/systm.h>
80 1.1 mycroft #include <sys/resourcevar.h>
81 1.1 mycroft #include <sys/kernel.h>
82 1.1 mycroft #include <sys/file.h>
83 1.1 mycroft #include <sys/stat.h>
84 1.1 mycroft #include <sys/buf.h>
85 1.50 jdolecek #include <sys/event.h>
86 1.1 mycroft #include <sys/proc.h>
87 1.1 mycroft #include <sys/mount.h>
88 1.1 mycroft #include <sys/vnode.h>
89 1.16 thorpej #include <sys/pool.h>
90 1.6 christos #include <sys/signalvar.h>
91 1.80 elad #include <sys/kauth.h>
92 1.99.4.1 simonb #include <sys/wapbl.h>
93 1.84 hannken #include <sys/fstrans.h>
94 1.1 mycroft
95 1.8 mycroft #include <miscfs/fifofs/fifo.h>
96 1.8 mycroft #include <miscfs/genfs/genfs.h>
97 1.1 mycroft #include <miscfs/specfs/specdev.h>
98 1.1 mycroft
99 1.1 mycroft #include <ufs/ufs/inode.h>
100 1.1 mycroft #include <ufs/ufs/dir.h>
101 1.1 mycroft #include <ufs/ufs/ufs_extern.h>
102 1.2 mycroft #include <ufs/ufs/ufsmount.h>
103 1.99.4.1 simonb #include <ufs/ufs/ufs_wapbl.h>
104 1.1 mycroft
105 1.1 mycroft #include <ufs/ffs/fs.h>
106 1.1 mycroft #include <ufs/ffs/ffs_extern.h>
107 1.1 mycroft
108 1.49 chs #include <uvm/uvm.h>
109 1.49 chs
110 1.1 mycroft /* Global vfs data structures for ufs. */
111 1.74 xtraeme int (**ffs_vnodeop_p)(void *);
112 1.37 jdolecek const struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
113 1.1 mycroft { &vop_default_desc, vn_default_error },
114 1.1 mycroft { &vop_lookup_desc, ufs_lookup }, /* lookup */
115 1.1 mycroft { &vop_create_desc, ufs_create }, /* create */
116 1.5 mycroft { &vop_whiteout_desc, ufs_whiteout }, /* whiteout */
117 1.1 mycroft { &vop_mknod_desc, ufs_mknod }, /* mknod */
118 1.1 mycroft { &vop_open_desc, ufs_open }, /* open */
119 1.1 mycroft { &vop_close_desc, ufs_close }, /* close */
120 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
121 1.1 mycroft { &vop_getattr_desc, ufs_getattr }, /* getattr */
122 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
123 1.1 mycroft { &vop_read_desc, ffs_read }, /* read */
124 1.1 mycroft { &vop_write_desc, ffs_write }, /* write */
125 1.1 mycroft { &vop_ioctl_desc, ufs_ioctl }, /* ioctl */
126 1.19 wrstuden { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
127 1.9 mycroft { &vop_poll_desc, ufs_poll }, /* poll */
128 1.50 jdolecek { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */
129 1.12 fvdl { &vop_revoke_desc, ufs_revoke }, /* revoke */
130 1.1 mycroft { &vop_mmap_desc, ufs_mmap }, /* mmap */
131 1.1 mycroft { &vop_fsync_desc, ffs_fsync }, /* fsync */
132 1.1 mycroft { &vop_seek_desc, ufs_seek }, /* seek */
133 1.1 mycroft { &vop_remove_desc, ufs_remove }, /* remove */
134 1.1 mycroft { &vop_link_desc, ufs_link }, /* link */
135 1.1 mycroft { &vop_rename_desc, ufs_rename }, /* rename */
136 1.1 mycroft { &vop_mkdir_desc, ufs_mkdir }, /* mkdir */
137 1.1 mycroft { &vop_rmdir_desc, ufs_rmdir }, /* rmdir */
138 1.1 mycroft { &vop_symlink_desc, ufs_symlink }, /* symlink */
139 1.1 mycroft { &vop_readdir_desc, ufs_readdir }, /* readdir */
140 1.1 mycroft { &vop_readlink_desc, ufs_readlink }, /* readlink */
141 1.1 mycroft { &vop_abortop_desc, ufs_abortop }, /* abortop */
142 1.1 mycroft { &vop_inactive_desc, ufs_inactive }, /* inactive */
143 1.1 mycroft { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
144 1.90 hannken { &vop_lock_desc, ffs_lock }, /* lock */
145 1.90 hannken { &vop_unlock_desc, ffs_unlock }, /* unlock */
146 1.1 mycroft { &vop_bmap_desc, ufs_bmap }, /* bmap */
147 1.1 mycroft { &vop_strategy_desc, ufs_strategy }, /* strategy */
148 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
149 1.90 hannken { &vop_islocked_desc, ffs_islocked }, /* islocked */
150 1.1 mycroft { &vop_pathconf_desc, ufs_pathconf }, /* pathconf */
151 1.1 mycroft { &vop_advlock_desc, ufs_advlock }, /* advlock */
152 1.8 mycroft { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
153 1.88 yamt { &vop_getpages_desc, genfs_getpages }, /* getpages */
154 1.75 yamt { &vop_putpages_desc, genfs_putpages }, /* putpages */
155 1.73 thorpej { &vop_openextattr_desc, ffs_openextattr }, /* openextattr */
156 1.73 thorpej { &vop_closeextattr_desc, ffs_closeextattr }, /* closeextattr */
157 1.73 thorpej { &vop_getextattr_desc, ffs_getextattr }, /* getextattr */
158 1.73 thorpej { &vop_setextattr_desc, ffs_setextattr }, /* setextattr */
159 1.73 thorpej { &vop_listextattr_desc, ffs_listextattr }, /* listextattr */
160 1.73 thorpej { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
161 1.35 chs { NULL, NULL }
162 1.1 mycroft };
163 1.37 jdolecek const struct vnodeopv_desc ffs_vnodeop_opv_desc =
164 1.1 mycroft { &ffs_vnodeop_p, ffs_vnodeop_entries };
165 1.1 mycroft
166 1.74 xtraeme int (**ffs_specop_p)(void *);
167 1.37 jdolecek const struct vnodeopv_entry_desc ffs_specop_entries[] = {
168 1.1 mycroft { &vop_default_desc, vn_default_error },
169 1.1 mycroft { &vop_lookup_desc, spec_lookup }, /* lookup */
170 1.1 mycroft { &vop_create_desc, spec_create }, /* create */
171 1.1 mycroft { &vop_mknod_desc, spec_mknod }, /* mknod */
172 1.1 mycroft { &vop_open_desc, spec_open }, /* open */
173 1.1 mycroft { &vop_close_desc, ufsspec_close }, /* close */
174 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
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.1 mycroft { &vop_ioctl_desc, spec_ioctl }, /* ioctl */
180 1.19 wrstuden { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
181 1.9 mycroft { &vop_poll_desc, spec_poll }, /* poll */
182 1.50 jdolecek { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */
183 1.12 fvdl { &vop_revoke_desc, spec_revoke }, /* revoke */
184 1.1 mycroft { &vop_mmap_desc, spec_mmap }, /* mmap */
185 1.1 mycroft { &vop_fsync_desc, ffs_fsync }, /* fsync */
186 1.1 mycroft { &vop_seek_desc, spec_seek }, /* seek */
187 1.1 mycroft { &vop_remove_desc, spec_remove }, /* remove */
188 1.1 mycroft { &vop_link_desc, spec_link }, /* link */
189 1.1 mycroft { &vop_rename_desc, spec_rename }, /* rename */
190 1.1 mycroft { &vop_mkdir_desc, spec_mkdir }, /* mkdir */
191 1.1 mycroft { &vop_rmdir_desc, spec_rmdir }, /* rmdir */
192 1.1 mycroft { &vop_symlink_desc, spec_symlink }, /* symlink */
193 1.1 mycroft { &vop_readdir_desc, spec_readdir }, /* readdir */
194 1.1 mycroft { &vop_readlink_desc, spec_readlink }, /* readlink */
195 1.1 mycroft { &vop_abortop_desc, spec_abortop }, /* abortop */
196 1.1 mycroft { &vop_inactive_desc, ufs_inactive }, /* inactive */
197 1.1 mycroft { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
198 1.90 hannken { &vop_lock_desc, ffs_lock }, /* lock */
199 1.90 hannken { &vop_unlock_desc, ffs_unlock }, /* unlock */
200 1.1 mycroft { &vop_bmap_desc, spec_bmap }, /* bmap */
201 1.1 mycroft { &vop_strategy_desc, spec_strategy }, /* strategy */
202 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
203 1.90 hannken { &vop_islocked_desc, ffs_islocked }, /* islocked */
204 1.1 mycroft { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
205 1.1 mycroft { &vop_advlock_desc, spec_advlock }, /* advlock */
206 1.8 mycroft { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
207 1.38 chs { &vop_getpages_desc, spec_getpages }, /* getpages */
208 1.38 chs { &vop_putpages_desc, spec_putpages }, /* putpages */
209 1.73 thorpej { &vop_openextattr_desc, ffs_openextattr }, /* openextattr */
210 1.73 thorpej { &vop_closeextattr_desc, ffs_closeextattr }, /* closeextattr */
211 1.73 thorpej { &vop_getextattr_desc, ffs_getextattr }, /* getextattr */
212 1.73 thorpej { &vop_setextattr_desc, ffs_setextattr }, /* setextattr */
213 1.73 thorpej { &vop_listextattr_desc, ffs_listextattr }, /* listextattr */
214 1.73 thorpej { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
215 1.35 chs { NULL, NULL }
216 1.1 mycroft };
217 1.37 jdolecek const struct vnodeopv_desc ffs_specop_opv_desc =
218 1.1 mycroft { &ffs_specop_p, ffs_specop_entries };
219 1.1 mycroft
220 1.74 xtraeme int (**ffs_fifoop_p)(void *);
221 1.37 jdolecek const struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
222 1.1 mycroft { &vop_default_desc, vn_default_error },
223 1.1 mycroft { &vop_lookup_desc, fifo_lookup }, /* lookup */
224 1.1 mycroft { &vop_create_desc, fifo_create }, /* create */
225 1.1 mycroft { &vop_mknod_desc, fifo_mknod }, /* mknod */
226 1.1 mycroft { &vop_open_desc, fifo_open }, /* open */
227 1.1 mycroft { &vop_close_desc, ufsfifo_close }, /* close */
228 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
229 1.1 mycroft { &vop_getattr_desc, ufs_getattr }, /* getattr */
230 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
231 1.1 mycroft { &vop_read_desc, ufsfifo_read }, /* read */
232 1.1 mycroft { &vop_write_desc, ufsfifo_write }, /* write */
233 1.1 mycroft { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */
234 1.19 wrstuden { &vop_fcntl_desc, ufs_fcntl }, /* fcntl */
235 1.9 mycroft { &vop_poll_desc, fifo_poll }, /* poll */
236 1.50 jdolecek { &vop_kqfilter_desc, fifo_kqfilter }, /* kqfilter */
237 1.12 fvdl { &vop_revoke_desc, fifo_revoke }, /* revoke */
238 1.1 mycroft { &vop_mmap_desc, fifo_mmap }, /* mmap */
239 1.1 mycroft { &vop_fsync_desc, ffs_fsync }, /* fsync */
240 1.1 mycroft { &vop_seek_desc, fifo_seek }, /* seek */
241 1.1 mycroft { &vop_remove_desc, fifo_remove }, /* remove */
242 1.1 mycroft { &vop_link_desc, fifo_link }, /* link */
243 1.1 mycroft { &vop_rename_desc, fifo_rename }, /* rename */
244 1.1 mycroft { &vop_mkdir_desc, fifo_mkdir }, /* mkdir */
245 1.1 mycroft { &vop_rmdir_desc, fifo_rmdir }, /* rmdir */
246 1.1 mycroft { &vop_symlink_desc, fifo_symlink }, /* symlink */
247 1.1 mycroft { &vop_readdir_desc, fifo_readdir }, /* readdir */
248 1.1 mycroft { &vop_readlink_desc, fifo_readlink }, /* readlink */
249 1.1 mycroft { &vop_abortop_desc, fifo_abortop }, /* abortop */
250 1.1 mycroft { &vop_inactive_desc, ufs_inactive }, /* inactive */
251 1.1 mycroft { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
252 1.90 hannken { &vop_lock_desc, ffs_lock }, /* lock */
253 1.90 hannken { &vop_unlock_desc, ffs_unlock }, /* unlock */
254 1.1 mycroft { &vop_bmap_desc, fifo_bmap }, /* bmap */
255 1.1 mycroft { &vop_strategy_desc, fifo_strategy }, /* strategy */
256 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
257 1.90 hannken { &vop_islocked_desc, ffs_islocked }, /* islocked */
258 1.1 mycroft { &vop_pathconf_desc, fifo_pathconf }, /* pathconf */
259 1.1 mycroft { &vop_advlock_desc, fifo_advlock }, /* advlock */
260 1.8 mycroft { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
261 1.40 sommerfe { &vop_putpages_desc, fifo_putpages }, /* putpages */
262 1.73 thorpej { &vop_openextattr_desc, ffs_openextattr }, /* openextattr */
263 1.73 thorpej { &vop_closeextattr_desc, ffs_closeextattr }, /* closeextattr */
264 1.73 thorpej { &vop_getextattr_desc, ffs_getextattr }, /* getextattr */
265 1.73 thorpej { &vop_setextattr_desc, ffs_setextattr }, /* setextattr */
266 1.73 thorpej { &vop_listextattr_desc, ffs_listextattr }, /* listextattr */
267 1.73 thorpej { &vop_deleteextattr_desc, ffs_deleteextattr }, /* deleteextattr */
268 1.35 chs { NULL, NULL }
269 1.1 mycroft };
270 1.37 jdolecek const struct vnodeopv_desc ffs_fifoop_opv_desc =
271 1.1 mycroft { &ffs_fifoop_p, ffs_fifoop_entries };
272 1.1 mycroft
273 1.1 mycroft #include <ufs/ufs/ufs_readwrite.c>
274 1.20 fvdl
275 1.33 fvdl int
276 1.70 thorpej ffs_fsync(void *v)
277 1.33 fvdl {
278 1.33 fvdl struct vop_fsync_args /* {
279 1.33 fvdl struct vnode *a_vp;
280 1.80 elad kauth_cred_t a_cred;
281 1.33 fvdl int a_flags;
282 1.46 chs off_t a_offlo;
283 1.46 chs off_t a_offhi;
284 1.77 christos struct lwp *a_l;
285 1.33 fvdl } */ *ap = v;
286 1.35 chs struct buf *bp;
287 1.94 ad int num, error, i;
288 1.33 fvdl struct indir ia[NIADDR + 1];
289 1.33 fvdl int bsize;
290 1.45 simonb daddr_t blk_high;
291 1.33 fvdl struct vnode *vp;
292 1.99.4.1 simonb #ifdef WAPBL
293 1.99.4.1 simonb struct mount *mp;
294 1.99.4.1 simonb #endif
295 1.33 fvdl
296 1.84 hannken vp = ap->a_vp;
297 1.84 hannken
298 1.87 hannken fstrans_start(vp->v_mount, FSTRANS_LAZY);
299 1.33 fvdl /*
300 1.33 fvdl * XXX no easy way to sync a range in a file with softdep.
301 1.33 fvdl */
302 1.84 hannken if ((ap->a_offlo == 0 && ap->a_offhi == 0) || DOINGSOFTDEP(vp) ||
303 1.84 hannken (vp->v_type != VREG)) {
304 1.94 ad error = ffs_full_fsync(vp, ap->a_flags);
305 1.84 hannken goto out;
306 1.84 hannken }
307 1.33 fvdl
308 1.84 hannken bsize = vp->v_mount->mnt_stat.f_iosize;
309 1.33 fvdl blk_high = ap->a_offhi / bsize;
310 1.33 fvdl if (ap->a_offhi % bsize != 0)
311 1.33 fvdl blk_high++;
312 1.33 fvdl
313 1.33 fvdl /*
314 1.35 chs * First, flush all pages in range.
315 1.33 fvdl */
316 1.35 chs
317 1.94 ad mutex_enter(&vp->v_interlock);
318 1.64 dbj error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
319 1.64 dbj round_page(ap->a_offhi), PGO_CLEANIT |
320 1.64 dbj ((ap->a_flags & FSYNC_WAIT) ? PGO_SYNCIO : 0));
321 1.64 dbj if (error) {
322 1.84 hannken goto out;
323 1.39 chs }
324 1.33 fvdl
325 1.99.4.1 simonb #ifdef WAPBL
326 1.99.4.1 simonb mp = wapbl_vptomp(vp);
327 1.99.4.1 simonb if (mp->mnt_wapbl) {
328 1.99.4.1 simonb if (ap->a_flags & FSYNC_DATAONLY) {
329 1.99.4.1 simonb fstrans_done(vp->v_mount);
330 1.99.4.1 simonb return 0;
331 1.99.4.1 simonb }
332 1.99.4.1 simonb error = 0;
333 1.99.4.1 simonb if (vp->v_tag == VT_UFS && VTOI(vp)->i_flag &
334 1.99.4.1 simonb (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY |
335 1.99.4.1 simonb IN_MODIFIED | IN_ACCESSED)) {
336 1.99.4.1 simonb error = UFS_WAPBL_BEGIN(mp);
337 1.99.4.1 simonb if (error) {
338 1.99.4.1 simonb fstrans_done(vp->v_mount);
339 1.99.4.1 simonb return error;
340 1.99.4.1 simonb }
341 1.99.4.1 simonb error = ffs_update(vp, NULL, NULL,
342 1.99.4.1 simonb (ap->a_flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
343 1.99.4.1 simonb UFS_WAPBL_END(mp);
344 1.99.4.1 simonb }
345 1.99.4.1 simonb if (error || (ap->a_flags & FSYNC_NOLOG)) {
346 1.99.4.1 simonb fstrans_done(vp->v_mount);
347 1.99.4.1 simonb return error;
348 1.99.4.1 simonb }
349 1.99.4.1 simonb error = wapbl_flush(mp->mnt_wapbl, 0);
350 1.99.4.1 simonb fstrans_done(vp->v_mount);
351 1.99.4.1 simonb return error;
352 1.99.4.1 simonb }
353 1.99.4.1 simonb #endif /* WAPBL */
354 1.99.4.1 simonb
355 1.33 fvdl /*
356 1.35 chs * Then, flush indirect blocks.
357 1.33 fvdl */
358 1.35 chs
359 1.61 kleink if (blk_high >= NDADDR) {
360 1.33 fvdl error = ufs_getlbns(vp, blk_high, ia, &num);
361 1.94 ad if (error)
362 1.84 hannken goto out;
363 1.94 ad
364 1.94 ad mutex_enter(&bufcache_lock);
365 1.33 fvdl for (i = 0; i < num; i++) {
366 1.94 ad if ((bp = incore(vp, ia[i].in_lbn)) == NULL)
367 1.94 ad continue;
368 1.94 ad if ((bp->b_cflags & BC_BUSY) != 0 ||
369 1.94 ad (bp->b_oflags & BO_DELWRI) == 0)
370 1.94 ad continue;
371 1.94 ad bp->b_cflags |= BC_BUSY | BC_VFLUSH;
372 1.94 ad mutex_exit(&bufcache_lock);
373 1.94 ad bawrite(bp);
374 1.94 ad mutex_enter(&bufcache_lock);
375 1.33 fvdl }
376 1.94 ad mutex_exit(&bufcache_lock);
377 1.33 fvdl }
378 1.33 fvdl
379 1.33 fvdl if (ap->a_flags & FSYNC_WAIT) {
380 1.94 ad mutex_enter(&vp->v_interlock);
381 1.94 ad while (vp->v_numoutput > 0)
382 1.94 ad cv_wait(&vp->v_cv, &vp->v_interlock);
383 1.94 ad mutex_exit(&vp->v_interlock);
384 1.33 fvdl }
385 1.33 fvdl
386 1.76 yamt error = ffs_update(vp, NULL, NULL,
387 1.66 thorpej ((ap->a_flags & (FSYNC_WAIT | FSYNC_DATAONLY)) == FSYNC_WAIT)
388 1.67 wrstuden ? UPDATE_WAIT : 0);
389 1.67 wrstuden
390 1.67 wrstuden if (error == 0 && ap->a_flags & FSYNC_CACHE) {
391 1.67 wrstuden int l = 0;
392 1.67 wrstuden VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE,
393 1.93 pooka curlwp->l_cred);
394 1.67 wrstuden }
395 1.67 wrstuden
396 1.84 hannken out:
397 1.84 hannken fstrans_done(vp->v_mount);
398 1.67 wrstuden return error;
399 1.33 fvdl }
400 1.33 fvdl
401 1.20 fvdl /*
402 1.20 fvdl * Synch an open file.
403 1.20 fvdl */
404 1.20 fvdl /* ARGSUSED */
405 1.94 ad int
406 1.94 ad ffs_full_fsync(struct vnode *vp, int flags)
407 1.20 fvdl {
408 1.20 fvdl struct buf *bp, *nbp;
409 1.94 ad int error, passes, skipmeta, inodedeps_only, waitfor;
410 1.99 ad struct mount *mp;
411 1.99 ad
412 1.99 ad error = 0;
413 1.24 fvdl
414 1.20 fvdl if (vp->v_type == VBLK &&
415 1.20 fvdl vp->v_specmountpoint != NULL &&
416 1.20 fvdl (vp->v_specmountpoint->mnt_flag & MNT_SOFTDEP))
417 1.20 fvdl softdep_fsync_mountdev(vp);
418 1.21 perseant
419 1.94 ad mutex_enter(&vp->v_interlock);
420 1.94 ad
421 1.94 ad inodedeps_only = DOINGSOFTDEP(vp) && (flags & FSYNC_RECLAIM)
422 1.89 pooka && UVM_OBJ_IS_CLEAN(&vp->v_uobj) && LIST_EMPTY(&vp->v_dirtyblkhd);
423 1.47 fvdl
424 1.35 chs /*
425 1.35 chs * Flush all dirty data associated with a vnode.
426 1.20 fvdl */
427 1.35 chs
428 1.99.4.1 simonb mp = NULL;
429 1.72 yamt if (vp->v_type == VREG || vp->v_type == VBLK) {
430 1.99 ad if ((flags & FSYNC_VFS) != 0)
431 1.99 ad mp = vp->v_specmountpoint;
432 1.99 ad else
433 1.99 ad mp = vp->v_mount;
434 1.46 chs error = VOP_PUTPAGES(vp, 0, 0, PGO_ALLPAGES | PGO_CLEANIT |
435 1.94 ad ((flags & FSYNC_WAIT) ? PGO_SYNCIO : 0) |
436 1.99 ad (fstrans_getstate(mp) == FSTRANS_SUSPENDING ?
437 1.84 hannken PGO_FREE : 0));
438 1.99 ad if (error)
439 1.39 chs return error;
440 1.94 ad } else
441 1.94 ad mutex_exit(&vp->v_interlock);
442 1.35 chs
443 1.99.4.1 simonb #ifdef WAPBL
444 1.99.4.1 simonb mp = wapbl_vptomp(vp); /* XXXXXX anti-kern/38057 hack */
445 1.99.4.1 simonb if (mp && mp->mnt_wapbl) {
446 1.99.4.1 simonb error = 0;
447 1.99.4.1 simonb if (flags & FSYNC_DATAONLY)
448 1.99.4.1 simonb return error;
449 1.99.4.1 simonb
450 1.99.4.1 simonb if (VTOI(vp)->i_flag &
451 1.99.4.1 simonb (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY |
452 1.99.4.1 simonb IN_MODIFIED | IN_ACCESSED)) {
453 1.99.4.1 simonb error = UFS_WAPBL_BEGIN(mp);
454 1.99.4.1 simonb if (error)
455 1.99.4.1 simonb return error;
456 1.99.4.1 simonb error = ffs_update(vp, NULL, NULL,
457 1.99.4.1 simonb (flags & FSYNC_WAIT) ? UPDATE_WAIT : 0);
458 1.99.4.1 simonb UFS_WAPBL_END(mp);
459 1.99.4.1 simonb }
460 1.99.4.1 simonb if (error || (flags & FSYNC_NOLOG))
461 1.99.4.1 simonb return error;
462 1.99.4.1 simonb /*
463 1.99.4.1 simonb * Don't flush the log if the vnode being flushed
464 1.99.4.1 simonb * contains no dirty buffers that could be in the log.
465 1.99.4.1 simonb */
466 1.99.4.1 simonb if (!((flags & FSYNC_RECLAIM) &&
467 1.99.4.1 simonb LIST_EMPTY(&vp->v_dirtyblkhd))) {
468 1.99.4.1 simonb error = wapbl_flush(mp->mnt_wapbl, 0);
469 1.99.4.1 simonb if (error)
470 1.99.4.1 simonb return error;
471 1.99.4.1 simonb }
472 1.99.4.1 simonb
473 1.99.4.1 simonb /*
474 1.99.4.1 simonb * XXX temporary workaround for "dirty bufs" panic in
475 1.99.4.1 simonb * vinvalbuf. need a full fix for the v_numoutput
476 1.99.4.1 simonb * waiters issues.
477 1.99.4.1 simonb */
478 1.99.4.1 simonb if (flags & FSYNC_WAIT) {
479 1.99.4.1 simonb mutex_enter(&vp->v_interlock);
480 1.99.4.1 simonb while (vp->v_numoutput)
481 1.99.4.1 simonb cv_wait(&vp->v_cv, &vp->v_interlock);
482 1.99.4.1 simonb mutex_exit(&vp->v_interlock);
483 1.99.4.1 simonb }
484 1.99.4.1 simonb
485 1.99.4.1 simonb return error;
486 1.99.4.1 simonb }
487 1.99.4.1 simonb #endif /* WAPBL */
488 1.99.4.1 simonb
489 1.20 fvdl passes = NIADDR + 1;
490 1.20 fvdl skipmeta = 0;
491 1.94 ad if (flags & FSYNC_WAIT)
492 1.20 fvdl skipmeta = 1;
493 1.35 chs
494 1.20 fvdl loop:
495 1.94 ad mutex_enter(&bufcache_lock);
496 1.94 ad LIST_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) {
497 1.94 ad bp->b_cflags &= ~BC_SCANNED;
498 1.94 ad }
499 1.29 mycroft for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
500 1.29 mycroft nbp = LIST_NEXT(bp, b_vnbufs);
501 1.94 ad if (bp->b_cflags & (BC_BUSY | BC_SCANNED))
502 1.20 fvdl continue;
503 1.94 ad if ((bp->b_oflags & BO_DELWRI) == 0)
504 1.20 fvdl panic("ffs_fsync: not dirty");
505 1.94 ad if (skipmeta && bp->b_lblkno < 0)
506 1.20 fvdl continue;
507 1.94 ad bp->b_cflags |= BC_BUSY | BC_VFLUSH | BC_SCANNED;
508 1.94 ad mutex_exit(&bufcache_lock);
509 1.20 fvdl /*
510 1.20 fvdl * On our final pass through, do all I/O synchronously
511 1.20 fvdl * so that we can find out if our flush is failing
512 1.20 fvdl * because of write errors.
513 1.20 fvdl */
514 1.94 ad if (passes > 0 || !(flags & FSYNC_WAIT))
515 1.20 fvdl (void) bawrite(bp);
516 1.20 fvdl else if ((error = bwrite(bp)) != 0)
517 1.20 fvdl return (error);
518 1.20 fvdl /*
519 1.94 ad * Since we unlocked during the I/O, we need
520 1.20 fvdl * to start from a known point.
521 1.20 fvdl */
522 1.94 ad mutex_enter(&bufcache_lock);
523 1.29 mycroft nbp = LIST_FIRST(&vp->v_dirtyblkhd);
524 1.20 fvdl }
525 1.94 ad mutex_exit(&bufcache_lock);
526 1.61 kleink if (skipmeta) {
527 1.20 fvdl skipmeta = 0;
528 1.20 fvdl goto loop;
529 1.20 fvdl }
530 1.94 ad
531 1.94 ad if (flags & FSYNC_WAIT) {
532 1.94 ad mutex_enter(&vp->v_interlock);
533 1.20 fvdl while (vp->v_numoutput) {
534 1.94 ad cv_wait(&vp->v_cv, &vp->v_interlock);
535 1.20 fvdl }
536 1.94 ad mutex_exit(&vp->v_interlock);
537 1.20 fvdl
538 1.69 perry /*
539 1.20 fvdl * Ensure that any filesystem metadata associated
540 1.20 fvdl * with the vnode has been written.
541 1.20 fvdl */
542 1.94 ad if ((error = softdep_sync_metadata(vp)) != 0)
543 1.20 fvdl return (error);
544 1.29 mycroft
545 1.29 mycroft if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
546 1.29 mycroft /*
547 1.29 mycroft * Block devices associated with filesystems may
548 1.29 mycroft * have new I/O requests posted for them even if
549 1.29 mycroft * the vnode is locked, so no amount of trying will
550 1.29 mycroft * get them clean. Thus we give block devices a
551 1.29 mycroft * good effort, then just give up. For all other file
552 1.29 mycroft * types, go around and try again until it is clean.
553 1.29 mycroft */
554 1.29 mycroft if (passes > 0) {
555 1.29 mycroft passes--;
556 1.29 mycroft goto loop;
557 1.29 mycroft }
558 1.20 fvdl #ifdef DIAGNOSTIC
559 1.29 mycroft if (vp->v_type != VBLK)
560 1.29 mycroft vprint("ffs_fsync: dirty", vp);
561 1.20 fvdl #endif
562 1.29 mycroft }
563 1.29 mycroft }
564 1.47 fvdl
565 1.47 fvdl if (inodedeps_only)
566 1.47 fvdl waitfor = 0;
567 1.47 fvdl else
568 1.94 ad waitfor = (flags & FSYNC_WAIT) ? UPDATE_WAIT : 0;
569 1.99 ad
570 1.99 ad if (vp->v_tag == VT_UFS)
571 1.99 ad error = ffs_update(vp, NULL, NULL, waitfor);
572 1.99 ad else {
573 1.99 ad KASSERT(vp->v_type == VBLK);
574 1.99 ad KASSERT((flags & FSYNC_VFS) != 0);
575 1.99 ad }
576 1.67 wrstuden
577 1.94 ad if (error == 0 && flags & FSYNC_CACHE) {
578 1.67 wrstuden int i = 0;
579 1.99 ad if ((flags & FSYNC_VFS) == 0)
580 1.99 ad vp = VTOI(vp)->i_devvp;
581 1.99 ad VOP_IOCTL(vp, DIOCCACHESYNC, &i, FWRITE, curlwp->l_cred);
582 1.67 wrstuden }
583 1.67 wrstuden
584 1.67 wrstuden return error;
585 1.20 fvdl }
586 1.1 mycroft
587 1.1 mycroft /*
588 1.1 mycroft * Reclaim an inode so that it can be used for other purposes.
589 1.1 mycroft */
590 1.1 mycroft int
591 1.70 thorpej ffs_reclaim(void *v)
592 1.6 christos {
593 1.1 mycroft struct vop_reclaim_args /* {
594 1.1 mycroft struct vnode *a_vp;
595 1.77 christos struct lwp *a_l;
596 1.6 christos } */ *ap = v;
597 1.26 augustss struct vnode *vp = ap->a_vp;
598 1.56 fvdl struct inode *ip = VTOI(vp);
599 1.84 hannken struct mount *mp = vp->v_mount;
600 1.56 fvdl struct ufsmount *ump = ip->i_ump;
601 1.94 ad void *data;
602 1.1 mycroft int error;
603 1.1 mycroft
604 1.87 hannken fstrans_start(mp, FSTRANS_LAZY);
605 1.93 pooka if ((error = ufs_reclaim(vp)) != 0) {
606 1.84 hannken fstrans_done(mp);
607 1.1 mycroft return (error);
608 1.84 hannken }
609 1.57 fvdl if (ip->i_din.ffs1_din != NULL) {
610 1.57 fvdl if (ump->um_fstype == UFS1)
611 1.95 ad pool_cache_put(ffs_dinode1_cache, ip->i_din.ffs1_din);
612 1.57 fvdl else
613 1.95 ad pool_cache_put(ffs_dinode2_cache, ip->i_din.ffs2_din);
614 1.57 fvdl }
615 1.16 thorpej /*
616 1.94 ad * To interlock with ffs_sync().
617 1.94 ad */
618 1.94 ad genfs_node_destroy(vp);
619 1.94 ad mutex_enter(&vp->v_interlock);
620 1.94 ad data = vp->v_data;
621 1.94 ad vp->v_data = NULL;
622 1.94 ad mutex_exit(&vp->v_interlock);
623 1.94 ad
624 1.94 ad /*
625 1.16 thorpej * XXX MFS ends up here, too, to free an inode. Should we create
626 1.16 thorpej * XXX a separate pool for MFS inodes?
627 1.16 thorpej */
628 1.95 ad pool_cache_put(ffs_inode_cache, data);
629 1.84 hannken fstrans_done(mp);
630 1.1 mycroft return (0);
631 1.35 chs }
632 1.35 chs
633 1.88 yamt #if 0
634 1.39 chs int
635 1.39 chs ffs_getpages(void *v)
636 1.39 chs {
637 1.39 chs struct vop_getpages_args /* {
638 1.39 chs struct vnode *a_vp;
639 1.39 chs voff_t a_offset;
640 1.39 chs struct vm_page **a_m;
641 1.39 chs int *a_count;
642 1.39 chs int a_centeridx;
643 1.39 chs vm_prot_t a_access_type;
644 1.39 chs int a_advice;
645 1.39 chs int a_flags;
646 1.39 chs } */ *ap = v;
647 1.39 chs struct vnode *vp = ap->a_vp;
648 1.39 chs struct inode *ip = VTOI(vp);
649 1.39 chs struct fs *fs = ip->i_fs;
650 1.39 chs
651 1.39 chs /*
652 1.39 chs * don't allow a softdep write to create pages for only part of a block.
653 1.39 chs * the dependency tracking requires that all pages be in memory for
654 1.39 chs * a block involved in a dependency.
655 1.39 chs */
656 1.39 chs
657 1.39 chs if (ap->a_flags & PGO_OVERWRITE &&
658 1.39 chs (blkoff(fs, ap->a_offset) != 0 ||
659 1.39 chs blkoff(fs, *ap->a_count << PAGE_SHIFT) != 0) &&
660 1.39 chs DOINGSOFTDEP(ap->a_vp)) {
661 1.39 chs if ((ap->a_flags & PGO_LOCKED) == 0) {
662 1.94 ad mutex_exit(&vp->v_interlock);
663 1.39 chs }
664 1.39 chs return EINVAL;
665 1.39 chs }
666 1.39 chs return genfs_getpages(v);
667 1.49 chs }
668 1.88 yamt #endif
669 1.49 chs
670 1.35 chs /*
671 1.35 chs * Return the last logical file offset that should be written for this file
672 1.35 chs * if we're doing a write that ends at "size".
673 1.35 chs */
674 1.39 chs
675 1.39 chs void
676 1.83 christos ffs_gop_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
677 1.35 chs {
678 1.39 chs struct inode *ip = VTOI(vp);
679 1.35 chs struct fs *fs = ip->i_fs;
680 1.52 fvdl daddr_t olbn, nlbn;
681 1.55 perseant
682 1.56 fvdl olbn = lblkno(fs, ip->i_size);
683 1.39 chs nlbn = lblkno(fs, size);
684 1.35 chs if (nlbn < NDADDR && olbn <= nlbn) {
685 1.39 chs *eobp = fragroundup(fs, size);
686 1.35 chs } else {
687 1.39 chs *eobp = blkroundup(fs, size);
688 1.35 chs }
689 1.1 mycroft }
690 1.73 thorpej
691 1.73 thorpej int
692 1.73 thorpej ffs_openextattr(void *v)
693 1.73 thorpej {
694 1.73 thorpej struct vop_openextattr_args /* {
695 1.73 thorpej struct vnode *a_vp;
696 1.80 elad kauth_cred_t a_cred;
697 1.73 thorpej struct proc *a_p;
698 1.73 thorpej } */ *ap = v;
699 1.73 thorpej struct inode *ip = VTOI(ap->a_vp);
700 1.73 thorpej struct fs *fs = ip->i_fs;
701 1.73 thorpej
702 1.73 thorpej /* Not supported for UFS1 file systems. */
703 1.73 thorpej if (fs->fs_magic == FS_UFS1_MAGIC)
704 1.73 thorpej return (EOPNOTSUPP);
705 1.73 thorpej
706 1.73 thorpej /* XXX Not implemented for UFS2 file systems. */
707 1.73 thorpej return (EOPNOTSUPP);
708 1.73 thorpej }
709 1.73 thorpej
710 1.73 thorpej int
711 1.73 thorpej ffs_closeextattr(void *v)
712 1.73 thorpej {
713 1.73 thorpej struct vop_closeextattr_args /* {
714 1.73 thorpej struct vnode *a_vp;
715 1.73 thorpej int a_commit;
716 1.80 elad kauth_cred_t a_cred;
717 1.73 thorpej struct proc *a_p;
718 1.73 thorpej } */ *ap = v;
719 1.73 thorpej struct inode *ip = VTOI(ap->a_vp);
720 1.73 thorpej struct fs *fs = ip->i_fs;
721 1.73 thorpej
722 1.73 thorpej /* Not supported for UFS1 file systems. */
723 1.73 thorpej if (fs->fs_magic == FS_UFS1_MAGIC)
724 1.73 thorpej return (EOPNOTSUPP);
725 1.73 thorpej
726 1.73 thorpej /* XXX Not implemented for UFS2 file systems. */
727 1.73 thorpej return (EOPNOTSUPP);
728 1.73 thorpej }
729 1.73 thorpej
730 1.73 thorpej int
731 1.73 thorpej ffs_getextattr(void *v)
732 1.73 thorpej {
733 1.73 thorpej struct vop_getextattr_args /* {
734 1.73 thorpej struct vnode *a_vp;
735 1.73 thorpej int a_attrnamespace;
736 1.73 thorpej const char *a_name;
737 1.73 thorpej struct uio *a_uio;
738 1.73 thorpej size_t *a_size;
739 1.80 elad kauth_cred_t a_cred;
740 1.73 thorpej struct proc *a_p;
741 1.73 thorpej } */ *ap = v;
742 1.84 hannken struct vnode *vp = ap->a_vp;
743 1.84 hannken struct inode *ip = VTOI(vp);
744 1.73 thorpej struct fs *fs = ip->i_fs;
745 1.73 thorpej
746 1.73 thorpej if (fs->fs_magic == FS_UFS1_MAGIC) {
747 1.73 thorpej #ifdef UFS_EXTATTR
748 1.84 hannken int error;
749 1.84 hannken
750 1.87 hannken fstrans_start(vp->v_mount, FSTRANS_SHARED);
751 1.84 hannken error = ufs_getextattr(ap);
752 1.84 hannken fstrans_done(vp->v_mount);
753 1.84 hannken return error;
754 1.73 thorpej #else
755 1.73 thorpej return (EOPNOTSUPP);
756 1.73 thorpej #endif
757 1.73 thorpej }
758 1.73 thorpej
759 1.73 thorpej /* XXX Not implemented for UFS2 file systems. */
760 1.73 thorpej return (EOPNOTSUPP);
761 1.73 thorpej }
762 1.73 thorpej
763 1.73 thorpej int
764 1.73 thorpej ffs_setextattr(void *v)
765 1.73 thorpej {
766 1.73 thorpej struct vop_setextattr_args /* {
767 1.73 thorpej struct vnode *a_vp;
768 1.73 thorpej int a_attrnamespace;
769 1.73 thorpej const char *a_name;
770 1.73 thorpej struct uio *a_uio;
771 1.80 elad kauth_cred_t a_cred;
772 1.73 thorpej struct proc *a_p;
773 1.73 thorpej } */ *ap = v;
774 1.84 hannken struct vnode *vp = ap->a_vp;
775 1.84 hannken struct inode *ip = VTOI(vp);
776 1.73 thorpej struct fs *fs = ip->i_fs;
777 1.73 thorpej
778 1.73 thorpej if (fs->fs_magic == FS_UFS1_MAGIC) {
779 1.73 thorpej #ifdef UFS_EXTATTR
780 1.84 hannken int error;
781 1.84 hannken
782 1.87 hannken fstrans_start(vp->v_mount, FSTRANS_SHARED);
783 1.84 hannken error = ufs_setextattr(ap);
784 1.84 hannken fstrans_done(vp->v_mount);
785 1.84 hannken return error;
786 1.73 thorpej #else
787 1.73 thorpej return (EOPNOTSUPP);
788 1.73 thorpej #endif
789 1.73 thorpej }
790 1.73 thorpej
791 1.73 thorpej /* XXX Not implemented for UFS2 file systems. */
792 1.73 thorpej return (EOPNOTSUPP);
793 1.73 thorpej }
794 1.73 thorpej
795 1.73 thorpej int
796 1.73 thorpej ffs_listextattr(void *v)
797 1.73 thorpej {
798 1.73 thorpej struct vop_listextattr_args /* {
799 1.73 thorpej struct vnode *a_vp;
800 1.73 thorpej int a_attrnamespace;
801 1.73 thorpej struct uio *a_uio;
802 1.73 thorpej size_t *a_size;
803 1.80 elad kauth_cred_t a_cred;
804 1.73 thorpej struct proc *a_p;
805 1.73 thorpej } */ *ap = v;
806 1.73 thorpej struct inode *ip = VTOI(ap->a_vp);
807 1.73 thorpej struct fs *fs = ip->i_fs;
808 1.73 thorpej
809 1.73 thorpej /* Not supported for UFS1 file systems. */
810 1.73 thorpej if (fs->fs_magic == FS_UFS1_MAGIC)
811 1.73 thorpej return (EOPNOTSUPP);
812 1.73 thorpej
813 1.73 thorpej /* XXX Not implemented for UFS2 file systems. */
814 1.73 thorpej return (EOPNOTSUPP);
815 1.73 thorpej }
816 1.73 thorpej
817 1.73 thorpej int
818 1.73 thorpej ffs_deleteextattr(void *v)
819 1.73 thorpej {
820 1.73 thorpej struct vop_deleteextattr_args /* {
821 1.73 thorpej struct vnode *a_vp;
822 1.73 thorpej int a_attrnamespace;
823 1.80 elad kauth_cred_t a_cred;
824 1.73 thorpej struct proc *a_p;
825 1.73 thorpej } */ *ap = v;
826 1.84 hannken struct vnode *vp = ap->a_vp;
827 1.84 hannken struct inode *ip = VTOI(vp);
828 1.73 thorpej struct fs *fs = ip->i_fs;
829 1.73 thorpej
830 1.73 thorpej if (fs->fs_magic == FS_UFS1_MAGIC) {
831 1.73 thorpej #ifdef UFS_EXTATTR
832 1.84 hannken int error;
833 1.84 hannken
834 1.87 hannken fstrans_start(vp->v_mount, FSTRANS_SHARED);
835 1.84 hannken error = ufs_deleteextattr(ap);
836 1.84 hannken fstrans_done(vp->v_mount);
837 1.84 hannken return error;
838 1.73 thorpej #else
839 1.73 thorpej return (EOPNOTSUPP);
840 1.73 thorpej #endif
841 1.73 thorpej }
842 1.73 thorpej
843 1.73 thorpej /* XXX Not implemented for UFS2 file systems. */
844 1.73 thorpej return (EOPNOTSUPP);
845 1.73 thorpej }
846 1.90 hannken
847 1.90 hannken /*
848 1.90 hannken * Lock the node.
849 1.90 hannken */
850 1.90 hannken int
851 1.90 hannken ffs_lock(void *v)
852 1.90 hannken {
853 1.90 hannken struct vop_lock_args /* {
854 1.90 hannken struct vnode *a_vp;
855 1.90 hannken int a_flags;
856 1.90 hannken } */ *ap = v;
857 1.90 hannken struct vnode *vp = ap->a_vp;
858 1.90 hannken struct mount *mp = vp->v_mount;
859 1.98 ad struct vnlock *lkp;
860 1.91 hannken int flags = ap->a_flags;
861 1.91 hannken int result;
862 1.90 hannken
863 1.98 ad if ((flags & LK_INTERLOCK) != 0) {
864 1.98 ad mutex_exit(&vp->v_interlock);
865 1.98 ad flags &= ~LK_INTERLOCK;
866 1.98 ad }
867 1.98 ad
868 1.90 hannken /*
869 1.90 hannken * Fake lock during file system suspension.
870 1.90 hannken */
871 1.90 hannken if ((vp->v_type == VREG || vp->v_type == VDIR) &&
872 1.90 hannken fstrans_is_owner(mp) &&
873 1.90 hannken fstrans_getstate(mp) == FSTRANS_SUSPENDING) {
874 1.90 hannken return 0;
875 1.90 hannken }
876 1.91 hannken
877 1.91 hannken for (;;) {
878 1.91 hannken lkp = vp->v_vnlock;
879 1.98 ad result = vlockmgr(lkp, flags);
880 1.91 hannken if (lkp == vp->v_vnlock || result != 0)
881 1.91 hannken return result;
882 1.91 hannken /*
883 1.91 hannken * Apparent success, except that the vnode mutated between
884 1.91 hannken * snapshot file vnode and regular file vnode while this
885 1.91 hannken * thread slept. The lock currently held is not the right
886 1.91 hannken * lock. Release it, and try to get the new lock.
887 1.91 hannken */
888 1.98 ad (void) vlockmgr(lkp, LK_RELEASE);
889 1.91 hannken }
890 1.90 hannken }
891 1.90 hannken
892 1.90 hannken /*
893 1.90 hannken * Unlock the node.
894 1.90 hannken */
895 1.90 hannken int
896 1.90 hannken ffs_unlock(void *v)
897 1.90 hannken {
898 1.90 hannken struct vop_unlock_args /* {
899 1.90 hannken struct vnode *a_vp;
900 1.90 hannken int a_flags;
901 1.90 hannken } */ *ap = v;
902 1.90 hannken struct vnode *vp = ap->a_vp;
903 1.90 hannken struct mount *mp = vp->v_mount;
904 1.90 hannken
905 1.98 ad KASSERT(ap->a_flags == 0);
906 1.98 ad
907 1.90 hannken /*
908 1.90 hannken * Fake unlock during file system suspension.
909 1.90 hannken */
910 1.90 hannken if ((vp->v_type == VREG || vp->v_type == VDIR) &&
911 1.90 hannken fstrans_is_owner(mp) &&
912 1.90 hannken fstrans_getstate(mp) == FSTRANS_SUSPENDING) {
913 1.90 hannken return 0;
914 1.90 hannken }
915 1.98 ad return (vlockmgr(vp->v_vnlock, LK_RELEASE));
916 1.90 hannken }
917 1.90 hannken
918 1.90 hannken /*
919 1.90 hannken * Return whether or not the node is locked.
920 1.90 hannken */
921 1.90 hannken int
922 1.90 hannken ffs_islocked(void *v)
923 1.90 hannken {
924 1.90 hannken struct vop_islocked_args /* {
925 1.90 hannken struct vnode *a_vp;
926 1.90 hannken } */ *ap = v;
927 1.90 hannken struct vnode *vp = ap->a_vp;
928 1.90 hannken
929 1.98 ad return (vlockstatus(vp->v_vnlock));
930 1.90 hannken }
931