lfs_vnops.c revision 1.304.2.1 1 /* $NetBSD: lfs_vnops.c,v 1.304.2.1 2017/03/20 06:57:54 pgoyette Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant (at) hhhh.org>.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31 /*
32 * Copyright (c) 1986, 1989, 1991, 1993, 1995
33 * The Regents of the University of California. All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
46 *
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE.
58 *
59 * @(#)lfs_vnops.c 8.13 (Berkeley) 6/10/95
60 */
61
62 /* from NetBSD: ufs_vnops.c,v 1.232 2016/05/19 18:32:03 riastradh Exp */
63 /*-
64 * Copyright (c) 2008 The NetBSD Foundation, Inc.
65 * All rights reserved.
66 *
67 * This code is derived from software contributed to The NetBSD Foundation
68 * by Wasabi Systems, Inc.
69 *
70 * Redistribution and use in source and binary forms, with or without
71 * modification, are permitted provided that the following conditions
72 * are met:
73 * 1. Redistributions of source code must retain the above copyright
74 * notice, this list of conditions and the following disclaimer.
75 * 2. Redistributions in binary form must reproduce the above copyright
76 * notice, this list of conditions and the following disclaimer in the
77 * documentation and/or other materials provided with the distribution.
78 *
79 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
80 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
81 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
82 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
83 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
84 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
85 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
86 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
87 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
88 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
89 * POSSIBILITY OF SUCH DAMAGE.
90 */
91 /*
92 * Copyright (c) 1982, 1986, 1989, 1993, 1995
93 * The Regents of the University of California. All rights reserved.
94 * (c) UNIX System Laboratories, Inc.
95 * All or some portions of this file are derived from material licensed
96 * to the University of California by American Telephone and Telegraph
97 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
98 * the permission of UNIX System Laboratories, Inc.
99 *
100 * Redistribution and use in source and binary forms, with or without
101 * modification, are permitted provided that the following conditions
102 * are met:
103 * 1. Redistributions of source code must retain the above copyright
104 * notice, this list of conditions and the following disclaimer.
105 * 2. Redistributions in binary form must reproduce the above copyright
106 * notice, this list of conditions and the following disclaimer in the
107 * documentation and/or other materials provided with the distribution.
108 * 3. Neither the name of the University nor the names of its contributors
109 * may be used to endorse or promote products derived from this software
110 * without specific prior written permission.
111 *
112 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
113 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
114 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
115 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
116 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
117 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
118 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
119 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
120 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
121 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
122 * SUCH DAMAGE.
123 *
124 * @(#)ufs_vnops.c 8.28 (Berkeley) 7/31/95
125 */
126
127 #include <sys/cdefs.h>
128 __KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.304.2.1 2017/03/20 06:57:54 pgoyette Exp $");
129
130 #ifdef _KERNEL_OPT
131 #include "opt_compat_netbsd.h"
132 #include "opt_uvm_page_trkown.h"
133 #endif
134
135 #include <sys/param.h>
136 #include <sys/systm.h>
137 #include <sys/namei.h>
138 #include <sys/resourcevar.h>
139 #include <sys/kernel.h>
140 #include <sys/file.h>
141 #include <sys/stat.h>
142 #include <sys/buf.h>
143 #include <sys/proc.h>
144 #include <sys/mount.h>
145 #include <sys/vnode.h>
146 #include <sys/pool.h>
147 #include <sys/signalvar.h>
148 #include <sys/kauth.h>
149 #include <sys/syslog.h>
150 #include <sys/fstrans.h>
151
152 #include <miscfs/fifofs/fifo.h>
153 #include <miscfs/genfs/genfs.h>
154 #include <miscfs/specfs/specdev.h>
155
156 #include <ufs/lfs/ulfs_inode.h>
157 #include <ufs/lfs/ulfsmount.h>
158 #include <ufs/lfs/ulfs_bswap.h>
159 #include <ufs/lfs/ulfs_extern.h>
160
161 #include <uvm/uvm.h>
162 #include <uvm/uvm_pmap.h>
163 #include <uvm/uvm_stat.h>
164 #include <uvm/uvm_pager.h>
165
166 #include <ufs/lfs/lfs.h>
167 #include <ufs/lfs/lfs_accessors.h>
168 #include <ufs/lfs/lfs_kernel.h>
169 #include <ufs/lfs/lfs_extern.h>
170
171 extern pid_t lfs_writer_daemon;
172 int lfs_ignore_lazy_sync = 1;
173
174 static int lfs_openextattr(void *v);
175 static int lfs_closeextattr(void *v);
176 static int lfs_getextattr(void *v);
177 static int lfs_setextattr(void *v);
178 static int lfs_listextattr(void *v);
179 static int lfs_deleteextattr(void *v);
180
181 static int lfs_makeinode(struct vattr *vap, struct vnode *,
182 const struct ulfs_lookup_results *,
183 struct vnode **, struct componentname *);
184
185 /* Global vfs data structures for lfs. */
186 int (**lfs_vnodeop_p)(void *);
187 const struct vnodeopv_entry_desc lfs_vnodeop_entries[] = {
188 { &vop_default_desc, vn_default_error },
189 { &vop_lookup_desc, ulfs_lookup }, /* lookup */
190 { &vop_create_desc, lfs_create }, /* create */
191 { &vop_whiteout_desc, ulfs_whiteout }, /* whiteout */
192 { &vop_mknod_desc, lfs_mknod }, /* mknod */
193 { &vop_open_desc, ulfs_open }, /* open */
194 { &vop_close_desc, lfs_close }, /* close */
195 { &vop_access_desc, ulfs_access }, /* access */
196 { &vop_getattr_desc, lfs_getattr }, /* getattr */
197 { &vop_setattr_desc, lfs_setattr }, /* setattr */
198 { &vop_read_desc, lfs_read }, /* read */
199 { &vop_write_desc, lfs_write }, /* write */
200 { &vop_fallocate_desc, genfs_eopnotsupp }, /* fallocate */
201 { &vop_fdiscard_desc, genfs_eopnotsupp }, /* fdiscard */
202 { &vop_ioctl_desc, ulfs_ioctl }, /* ioctl */
203 { &vop_fcntl_desc, lfs_fcntl }, /* fcntl */
204 { &vop_poll_desc, ulfs_poll }, /* poll */
205 { &vop_kqfilter_desc, genfs_kqfilter }, /* kqfilter */
206 { &vop_revoke_desc, ulfs_revoke }, /* revoke */
207 { &vop_mmap_desc, lfs_mmap }, /* mmap */
208 { &vop_fsync_desc, lfs_fsync }, /* fsync */
209 { &vop_seek_desc, ulfs_seek }, /* seek */
210 { &vop_remove_desc, lfs_remove }, /* remove */
211 { &vop_link_desc, lfs_link }, /* link */
212 { &vop_rename_desc, lfs_rename }, /* rename */
213 { &vop_mkdir_desc, lfs_mkdir }, /* mkdir */
214 { &vop_rmdir_desc, lfs_rmdir }, /* rmdir */
215 { &vop_symlink_desc, lfs_symlink }, /* symlink */
216 { &vop_readdir_desc, ulfs_readdir }, /* readdir */
217 { &vop_readlink_desc, ulfs_readlink }, /* readlink */
218 { &vop_abortop_desc, ulfs_abortop }, /* abortop */
219 { &vop_inactive_desc, lfs_inactive }, /* inactive */
220 { &vop_reclaim_desc, lfs_reclaim }, /* reclaim */
221 { &vop_lock_desc, ulfs_lock }, /* lock */
222 { &vop_unlock_desc, ulfs_unlock }, /* unlock */
223 { &vop_bmap_desc, ulfs_bmap }, /* bmap */
224 { &vop_strategy_desc, lfs_strategy }, /* strategy */
225 { &vop_print_desc, ulfs_print }, /* print */
226 { &vop_islocked_desc, ulfs_islocked }, /* islocked */
227 { &vop_pathconf_desc, ulfs_pathconf }, /* pathconf */
228 { &vop_advlock_desc, ulfs_advlock }, /* advlock */
229 { &vop_bwrite_desc, lfs_bwrite }, /* bwrite */
230 { &vop_getpages_desc, lfs_getpages }, /* getpages */
231 { &vop_putpages_desc, lfs_putpages }, /* putpages */
232 { &vop_openextattr_desc, lfs_openextattr }, /* openextattr */
233 { &vop_closeextattr_desc, lfs_closeextattr }, /* closeextattr */
234 { &vop_getextattr_desc, lfs_getextattr }, /* getextattr */
235 { &vop_setextattr_desc, lfs_setextattr }, /* setextattr */
236 { &vop_listextattr_desc, lfs_listextattr }, /* listextattr */
237 { &vop_deleteextattr_desc, lfs_deleteextattr }, /* deleteextattr */
238 { NULL, NULL }
239 };
240 const struct vnodeopv_desc lfs_vnodeop_opv_desc =
241 { &lfs_vnodeop_p, lfs_vnodeop_entries };
242
243 int (**lfs_specop_p)(void *);
244 const struct vnodeopv_entry_desc lfs_specop_entries[] = {
245 { &vop_default_desc, vn_default_error },
246 { &vop_lookup_desc, spec_lookup }, /* lookup */
247 { &vop_create_desc, spec_create }, /* create */
248 { &vop_mknod_desc, spec_mknod }, /* mknod */
249 { &vop_open_desc, spec_open }, /* open */
250 { &vop_close_desc, lfsspec_close }, /* close */
251 { &vop_access_desc, ulfs_access }, /* access */
252 { &vop_getattr_desc, lfs_getattr }, /* getattr */
253 { &vop_setattr_desc, lfs_setattr }, /* setattr */
254 { &vop_read_desc, ulfsspec_read }, /* read */
255 { &vop_write_desc, ulfsspec_write }, /* write */
256 { &vop_fallocate_desc, spec_fallocate }, /* fallocate */
257 { &vop_fdiscard_desc, spec_fdiscard }, /* fdiscard */
258 { &vop_ioctl_desc, spec_ioctl }, /* ioctl */
259 { &vop_fcntl_desc, ulfs_fcntl }, /* fcntl */
260 { &vop_poll_desc, spec_poll }, /* poll */
261 { &vop_kqfilter_desc, spec_kqfilter }, /* kqfilter */
262 { &vop_revoke_desc, spec_revoke }, /* revoke */
263 { &vop_mmap_desc, spec_mmap }, /* mmap */
264 { &vop_fsync_desc, spec_fsync }, /* fsync */
265 { &vop_seek_desc, spec_seek }, /* seek */
266 { &vop_remove_desc, spec_remove }, /* remove */
267 { &vop_link_desc, spec_link }, /* link */
268 { &vop_rename_desc, spec_rename }, /* rename */
269 { &vop_mkdir_desc, spec_mkdir }, /* mkdir */
270 { &vop_rmdir_desc, spec_rmdir }, /* rmdir */
271 { &vop_symlink_desc, spec_symlink }, /* symlink */
272 { &vop_readdir_desc, spec_readdir }, /* readdir */
273 { &vop_readlink_desc, spec_readlink }, /* readlink */
274 { &vop_abortop_desc, spec_abortop }, /* abortop */
275 { &vop_inactive_desc, lfs_inactive }, /* inactive */
276 { &vop_reclaim_desc, lfs_reclaim }, /* reclaim */
277 { &vop_lock_desc, ulfs_lock }, /* lock */
278 { &vop_unlock_desc, ulfs_unlock }, /* unlock */
279 { &vop_bmap_desc, spec_bmap }, /* bmap */
280 { &vop_strategy_desc, spec_strategy }, /* strategy */
281 { &vop_print_desc, ulfs_print }, /* print */
282 { &vop_islocked_desc, ulfs_islocked }, /* islocked */
283 { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
284 { &vop_advlock_desc, spec_advlock }, /* advlock */
285 { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
286 { &vop_getpages_desc, spec_getpages }, /* getpages */
287 { &vop_putpages_desc, spec_putpages }, /* putpages */
288 { &vop_openextattr_desc, lfs_openextattr }, /* openextattr */
289 { &vop_closeextattr_desc, lfs_closeextattr }, /* closeextattr */
290 { &vop_getextattr_desc, lfs_getextattr }, /* getextattr */
291 { &vop_setextattr_desc, lfs_setextattr }, /* setextattr */
292 { &vop_listextattr_desc, lfs_listextattr }, /* listextattr */
293 { &vop_deleteextattr_desc, lfs_deleteextattr }, /* deleteextattr */
294 { NULL, NULL }
295 };
296 const struct vnodeopv_desc lfs_specop_opv_desc =
297 { &lfs_specop_p, lfs_specop_entries };
298
299 int (**lfs_fifoop_p)(void *);
300 const struct vnodeopv_entry_desc lfs_fifoop_entries[] = {
301 { &vop_default_desc, vn_default_error },
302 { &vop_lookup_desc, vn_fifo_bypass }, /* lookup */
303 { &vop_create_desc, vn_fifo_bypass }, /* create */
304 { &vop_mknod_desc, vn_fifo_bypass }, /* mknod */
305 { &vop_open_desc, vn_fifo_bypass }, /* open */
306 { &vop_close_desc, lfsfifo_close }, /* close */
307 { &vop_access_desc, ulfs_access }, /* access */
308 { &vop_getattr_desc, lfs_getattr }, /* getattr */
309 { &vop_setattr_desc, lfs_setattr }, /* setattr */
310 { &vop_read_desc, ulfsfifo_read }, /* read */
311 { &vop_write_desc, ulfsfifo_write }, /* write */
312 { &vop_fallocate_desc, vn_fifo_bypass }, /* fallocate */
313 { &vop_fdiscard_desc, vn_fifo_bypass }, /* fdiscard */
314 { &vop_ioctl_desc, vn_fifo_bypass }, /* ioctl */
315 { &vop_fcntl_desc, ulfs_fcntl }, /* fcntl */
316 { &vop_poll_desc, vn_fifo_bypass }, /* poll */
317 { &vop_kqfilter_desc, vn_fifo_bypass }, /* kqfilter */
318 { &vop_revoke_desc, vn_fifo_bypass }, /* revoke */
319 { &vop_mmap_desc, vn_fifo_bypass }, /* mmap */
320 { &vop_fsync_desc, vn_fifo_bypass }, /* fsync */
321 { &vop_seek_desc, vn_fifo_bypass }, /* seek */
322 { &vop_remove_desc, vn_fifo_bypass }, /* remove */
323 { &vop_link_desc, vn_fifo_bypass }, /* link */
324 { &vop_rename_desc, vn_fifo_bypass }, /* rename */
325 { &vop_mkdir_desc, vn_fifo_bypass }, /* mkdir */
326 { &vop_rmdir_desc, vn_fifo_bypass }, /* rmdir */
327 { &vop_symlink_desc, vn_fifo_bypass }, /* symlink */
328 { &vop_readdir_desc, vn_fifo_bypass }, /* readdir */
329 { &vop_readlink_desc, vn_fifo_bypass }, /* readlink */
330 { &vop_abortop_desc, vn_fifo_bypass }, /* abortop */
331 { &vop_inactive_desc, lfs_inactive }, /* inactive */
332 { &vop_reclaim_desc, lfs_reclaim }, /* reclaim */
333 { &vop_lock_desc, ulfs_lock }, /* lock */
334 { &vop_unlock_desc, ulfs_unlock }, /* unlock */
335 { &vop_bmap_desc, vn_fifo_bypass }, /* bmap */
336 { &vop_strategy_desc, vn_fifo_bypass }, /* strategy */
337 { &vop_print_desc, ulfs_print }, /* print */
338 { &vop_islocked_desc, ulfs_islocked }, /* islocked */
339 { &vop_pathconf_desc, vn_fifo_bypass }, /* pathconf */
340 { &vop_advlock_desc, vn_fifo_bypass }, /* advlock */
341 { &vop_bwrite_desc, lfs_bwrite }, /* bwrite */
342 { &vop_putpages_desc, vn_fifo_bypass }, /* putpages */
343 { &vop_openextattr_desc, lfs_openextattr }, /* openextattr */
344 { &vop_closeextattr_desc, lfs_closeextattr }, /* closeextattr */
345 { &vop_getextattr_desc, lfs_getextattr }, /* getextattr */
346 { &vop_setextattr_desc, lfs_setextattr }, /* setextattr */
347 { &vop_listextattr_desc, lfs_listextattr }, /* listextattr */
348 { &vop_deleteextattr_desc, lfs_deleteextattr }, /* deleteextattr */
349 { NULL, NULL }
350 };
351 const struct vnodeopv_desc lfs_fifoop_opv_desc =
352 { &lfs_fifoop_p, lfs_fifoop_entries };
353
354 #define LFS_READWRITE
355 #include <ufs/lfs/ulfs_readwrite.c>
356 #undef LFS_READWRITE
357
358 /*
359 * Allocate a new inode.
360 */
361 static int
362 lfs_makeinode(struct vattr *vap, struct vnode *dvp,
363 const struct ulfs_lookup_results *ulr,
364 struct vnode **vpp, struct componentname *cnp)
365 {
366 struct inode *ip;
367 struct vnode *tvp;
368 int error;
369
370 error = vcache_new(dvp->v_mount, dvp, vap, cnp->cn_cred, &tvp);
371 if (error)
372 return error;
373 error = vn_lock(tvp, LK_EXCLUSIVE);
374 if (error) {
375 vrele(tvp);
376 return error;
377 }
378 lfs_mark_vnode(tvp);
379 *vpp = tvp;
380 ip = VTOI(tvp);
381 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
382 ip->i_nlink = 1;
383 DIP_ASSIGN(ip, nlink, 1);
384
385 /* Authorize setting SGID if needed. */
386 if (ip->i_mode & ISGID) {
387 error = kauth_authorize_vnode(cnp->cn_cred, KAUTH_VNODE_WRITE_SECURITY,
388 tvp, NULL, genfs_can_chmod(tvp->v_type, cnp->cn_cred, ip->i_uid,
389 ip->i_gid, MAKEIMODE(vap->va_type, vap->va_mode)));
390 if (error) {
391 ip->i_mode &= ~ISGID;
392 DIP_ASSIGN(ip, mode, ip->i_mode);
393 }
394 }
395
396 if (cnp->cn_flags & ISWHITEOUT) {
397 ip->i_flags |= UF_OPAQUE;
398 DIP_ASSIGN(ip, flags, ip->i_flags);
399 }
400
401 /*
402 * Make sure inode goes to disk before directory entry.
403 */
404 if ((error = lfs_update(tvp, NULL, NULL, UPDATE_DIROP)) != 0)
405 goto bad;
406 error = ulfs_direnter(dvp, ulr, tvp,
407 cnp, ip->i_number, LFS_IFTODT(ip->i_mode), NULL);
408 if (error)
409 goto bad;
410 *vpp = tvp;
411 return (0);
412
413 bad:
414 /*
415 * Write error occurred trying to update the inode
416 * or the directory so must deallocate the inode.
417 */
418 ip->i_nlink = 0;
419 DIP_ASSIGN(ip, nlink, 0);
420 ip->i_flag |= IN_CHANGE;
421 /* If IN_ADIROP, account for it */
422 lfs_unmark_vnode(tvp);
423 vput(tvp);
424 return (error);
425 }
426
427 /*
428 * Synch an open file.
429 */
430 /* ARGSUSED */
431 int
432 lfs_fsync(void *v)
433 {
434 struct vop_fsync_args /* {
435 struct vnode *a_vp;
436 kauth_cred_t a_cred;
437 int a_flags;
438 off_t offlo;
439 off_t offhi;
440 } */ *ap = v;
441 struct vnode *vp = ap->a_vp;
442 int error, wait;
443 struct inode *ip = VTOI(vp);
444 struct lfs *fs = ip->i_lfs;
445
446 /* If we're mounted read-only, don't try to sync. */
447 if (fs->lfs_ronly)
448 return 0;
449
450 /* If a removed vnode is being cleaned, no need to sync here. */
451 if ((ap->a_flags & FSYNC_RECLAIM) != 0 && ip->i_mode == 0)
452 return 0;
453
454 /*
455 * Trickle sync simply adds this vnode to the pager list, as if
456 * the pagedaemon had requested a pageout.
457 */
458 if (ap->a_flags & FSYNC_LAZY) {
459 if (lfs_ignore_lazy_sync == 0) {
460 mutex_enter(&lfs_lock);
461 if (!(ip->i_flags & IN_PAGING)) {
462 ip->i_flags |= IN_PAGING;
463 TAILQ_INSERT_TAIL(&fs->lfs_pchainhd, ip,
464 i_lfs_pchain);
465 }
466 wakeup(&lfs_writer_daemon);
467 mutex_exit(&lfs_lock);
468 }
469 return 0;
470 }
471
472 /*
473 * If a vnode is bring cleaned, flush it out before we try to
474 * reuse it. This prevents the cleaner from writing files twice
475 * in the same partial segment, causing an accounting underflow.
476 */
477 if (ap->a_flags & FSYNC_RECLAIM && ip->i_flags & IN_CLEANING) {
478 lfs_vflush(vp);
479 }
480
481 wait = (ap->a_flags & FSYNC_WAIT);
482 do {
483 mutex_enter(vp->v_interlock);
484 error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
485 round_page(ap->a_offhi),
486 PGO_CLEANIT | (wait ? PGO_SYNCIO : 0));
487 if (error == EAGAIN) {
488 mutex_enter(&lfs_lock);
489 mtsleep(&fs->lfs_availsleep, PCATCH | PUSER,
490 "lfs_fsync", hz / 100 + 1, &lfs_lock);
491 mutex_exit(&lfs_lock);
492 }
493 } while (error == EAGAIN);
494 if (error)
495 return error;
496
497 if ((ap->a_flags & FSYNC_DATAONLY) == 0)
498 error = lfs_update(vp, NULL, NULL, wait ? UPDATE_WAIT : 0);
499
500 if (error == 0 && ap->a_flags & FSYNC_CACHE) {
501 int l = 0;
502 error = VOP_IOCTL(ip->i_devvp, DIOCCACHESYNC, &l, FWRITE,
503 curlwp->l_cred);
504 }
505 if (wait && !VPISEMPTY(vp))
506 LFS_SET_UINO(ip, IN_MODIFIED);
507
508 return error;
509 }
510
511 /*
512 * Take IN_ADIROP off, then call ulfs_inactive.
513 */
514 int
515 lfs_inactive(void *v)
516 {
517 struct vop_inactive_args /* {
518 struct vnode *a_vp;
519 } */ *ap = v;
520
521 lfs_unmark_vnode(ap->a_vp);
522
523 /*
524 * The Ifile is only ever inactivated on unmount.
525 * Streamline this process by not giving it more dirty blocks.
526 */
527 if (VTOI(ap->a_vp)->i_number == LFS_IFILE_INUM) {
528 mutex_enter(&lfs_lock);
529 LFS_CLR_UINO(VTOI(ap->a_vp), IN_ALLMOD);
530 mutex_exit(&lfs_lock);
531 VOP_UNLOCK(ap->a_vp);
532 return 0;
533 }
534
535 #ifdef DEBUG
536 /*
537 * This might happen on unmount.
538 * XXX If it happens at any other time, it should be a panic.
539 */
540 if (ap->a_vp->v_uflag & VU_DIROP) {
541 struct inode *ip = VTOI(ap->a_vp);
542 printf("lfs_inactive: inactivating VU_DIROP? ino = %llu\n",
543 (unsigned long long) ip->i_number);
544 }
545 #endif /* DIAGNOSTIC */
546
547 return ulfs_inactive(v);
548 }
549
550 int
551 lfs_set_dirop(struct vnode *dvp, struct vnode *vp)
552 {
553 struct lfs *fs;
554 int error;
555
556 KASSERT(VOP_ISLOCKED(dvp));
557 KASSERT(vp == NULL || VOP_ISLOCKED(vp));
558
559 fs = VTOI(dvp)->i_lfs;
560
561 ASSERT_NO_SEGLOCK(fs);
562 /*
563 * LFS_NRESERVE calculates direct and indirect blocks as well
564 * as an inode block; an overestimate in most cases.
565 */
566 if ((error = lfs_reserve(fs, dvp, vp, LFS_NRESERVE(fs))) != 0)
567 return (error);
568
569 restart:
570 mutex_enter(&lfs_lock);
571 if (fs->lfs_dirops == 0) {
572 mutex_exit(&lfs_lock);
573 lfs_check(dvp, LFS_UNUSED_LBN, 0);
574 mutex_enter(&lfs_lock);
575 }
576 while (fs->lfs_writer) {
577 error = mtsleep(&fs->lfs_dirops, (PRIBIO + 1) | PCATCH,
578 "lfs_sdirop", 0, &lfs_lock);
579 if (error == EINTR) {
580 mutex_exit(&lfs_lock);
581 goto unreserve;
582 }
583 }
584 if (lfs_dirvcount > LFS_MAX_DIROP && fs->lfs_dirops == 0) {
585 wakeup(&lfs_writer_daemon);
586 mutex_exit(&lfs_lock);
587 preempt();
588 goto restart;
589 }
590
591 if (lfs_dirvcount > LFS_MAX_DIROP) {
592 DLOG((DLOG_DIROP, "lfs_set_dirop: sleeping with dirops=%d, "
593 "dirvcount=%d\n", fs->lfs_dirops, lfs_dirvcount));
594 if ((error = mtsleep(&lfs_dirvcount,
595 PCATCH | PUSER | PNORELOCK, "lfs_maxdirop", 0,
596 &lfs_lock)) != 0) {
597 mutex_exit(&lfs_lock);
598 goto unreserve;
599 }
600 mutex_exit(&lfs_lock);
601 goto restart;
602 }
603
604 ++fs->lfs_dirops;
605 /* fs->lfs_doifile = 1; */ /* XXX why? --ks */
606 mutex_exit(&lfs_lock);
607
608 /* Hold a reference so SET_ENDOP will be happy */
609 vref(dvp);
610 if (vp) {
611 vref(vp);
612 MARK_VNODE(vp);
613 }
614
615 MARK_VNODE(dvp);
616 return 0;
617
618 unreserve:
619 lfs_reserve(fs, dvp, vp, -LFS_NRESERVE(fs));
620 return error;
621 }
622
623 /*
624 * Opposite of lfs_set_dirop... mostly. For now at least must call
625 * UNMARK_VNODE(dvp) explicitly first. (XXX: clean that up)
626 */
627 void
628 lfs_unset_dirop(struct lfs *fs, struct vnode *dvp, const char *str)
629 {
630 mutex_enter(&lfs_lock);
631 --fs->lfs_dirops;
632 if (!fs->lfs_dirops) {
633 if (fs->lfs_nadirop) {
634 panic("lfs_unset_dirop: %s: no dirops but "
635 " nadirop=%d", str,
636 fs->lfs_nadirop);
637 }
638 wakeup(&fs->lfs_writer);
639 mutex_exit(&lfs_lock);
640 lfs_check(dvp, LFS_UNUSED_LBN, 0);
641 } else {
642 mutex_exit(&lfs_lock);
643 }
644 lfs_reserve(fs, dvp, NULL, -LFS_NRESERVE(fs));
645 }
646
647 void
648 lfs_mark_vnode(struct vnode *vp)
649 {
650 struct inode *ip = VTOI(vp);
651 struct lfs *fs = ip->i_lfs;
652
653 mutex_enter(&lfs_lock);
654 if (!(ip->i_flag & IN_ADIROP)) {
655 if (!(vp->v_uflag & VU_DIROP)) {
656 mutex_exit(&lfs_lock);
657 vref(vp);
658 mutex_enter(&lfs_lock);
659 ++lfs_dirvcount;
660 ++fs->lfs_dirvcount;
661 TAILQ_INSERT_TAIL(&fs->lfs_dchainhd, ip, i_lfs_dchain);
662 vp->v_uflag |= VU_DIROP;
663 }
664 ++fs->lfs_nadirop;
665 ip->i_flag &= ~IN_CDIROP;
666 ip->i_flag |= IN_ADIROP;
667 } else
668 KASSERT(vp->v_uflag & VU_DIROP);
669 mutex_exit(&lfs_lock);
670 }
671
672 void
673 lfs_unmark_vnode(struct vnode *vp)
674 {
675 struct inode *ip = VTOI(vp);
676
677 mutex_enter(&lfs_lock);
678 if (ip && (ip->i_flag & IN_ADIROP)) {
679 KASSERT(vp->v_uflag & VU_DIROP);
680 --ip->i_lfs->lfs_nadirop;
681 ip->i_flag &= ~IN_ADIROP;
682 }
683 mutex_exit(&lfs_lock);
684 }
685
686 int
687 lfs_symlink(void *v)
688 {
689 struct vop_symlink_v3_args /* {
690 struct vnode *a_dvp;
691 struct vnode **a_vpp;
692 struct componentname *a_cnp;
693 struct vattr *a_vap;
694 char *a_target;
695 } */ *ap = v;
696 struct lfs *fs;
697 struct vnode *dvp, **vpp;
698 struct inode *ip;
699 struct ulfs_lookup_results *ulr;
700 ssize_t len; /* XXX should be size_t */
701 int error;
702
703 dvp = ap->a_dvp;
704 vpp = ap->a_vpp;
705
706 KASSERT(vpp != NULL);
707 KASSERT(*vpp == NULL);
708 KASSERT(ap->a_vap->va_type == VLNK);
709
710 /* XXX should handle this material another way */
711 ulr = &VTOI(ap->a_dvp)->i_crap;
712 ULFS_CHECK_CRAPCOUNTER(VTOI(ap->a_dvp));
713
714 fs = VFSTOULFS(dvp->v_mount)->um_lfs;
715 ASSERT_NO_SEGLOCK(fs);
716 if (fs->lfs_ronly) {
717 return EROFS;
718 }
719
720 error = lfs_set_dirop(dvp, NULL);
721 if (error)
722 return error;
723
724 fstrans_start(dvp->v_mount, FSTRANS_SHARED);
725 error = lfs_makeinode(ap->a_vap, dvp, ulr, vpp, ap->a_cnp);
726 if (error) {
727 goto out;
728 }
729
730 VN_KNOTE(ap->a_dvp, NOTE_WRITE);
731 ip = VTOI(*vpp);
732
733 /*
734 * This test is off by one. um_maxsymlinklen contains the
735 * number of bytes available, and we aren't storing a \0, so
736 * the test should properly be <=. However, it cannot be
737 * changed as this would break compatibility with existing fs
738 * images -- see the way ulfs_readlink() works.
739 */
740 len = strlen(ap->a_target);
741 if (len < ip->i_lfs->um_maxsymlinklen) {
742 memcpy((char *)SHORTLINK(ip), ap->a_target, len);
743 ip->i_size = len;
744 DIP_ASSIGN(ip, size, len);
745 uvm_vnp_setsize(*vpp, ip->i_size);
746 ip->i_flag |= IN_CHANGE | IN_UPDATE;
747 if ((*vpp)->v_mount->mnt_flag & MNT_RELATIME)
748 ip->i_flag |= IN_ACCESS;
749 } else {
750 error = ulfs_bufio(UIO_WRITE, *vpp, ap->a_target, len, (off_t)0,
751 IO_NODELOCKED | IO_JOURNALLOCKED, ap->a_cnp->cn_cred, NULL,
752 NULL);
753 }
754
755 VOP_UNLOCK(*vpp);
756 if (error)
757 vrele(*vpp);
758
759 out:
760 fstrans_done(dvp->v_mount);
761
762 UNMARK_VNODE(dvp);
763 /* XXX: is it even possible for the symlink to get MARK'd? */
764 UNMARK_VNODE(*vpp);
765 if (error) {
766 *vpp = NULL;
767 }
768 lfs_unset_dirop(fs, dvp, "symlink");
769
770 vrele(dvp);
771 return (error);
772 }
773
774 int
775 lfs_mknod(void *v)
776 {
777 struct vop_mknod_v3_args /* {
778 struct vnode *a_dvp;
779 struct vnode **a_vpp;
780 struct componentname *a_cnp;
781 struct vattr *a_vap;
782 } */ *ap = v;
783 struct lfs *fs;
784 struct vnode *dvp, **vpp;
785 struct vattr *vap;
786 struct inode *ip;
787 int error;
788 ino_t ino;
789 struct ulfs_lookup_results *ulr;
790
791 dvp = ap->a_dvp;
792 vpp = ap->a_vpp;
793 vap = ap->a_vap;
794
795 KASSERT(vpp != NULL);
796 KASSERT(*vpp == NULL);
797
798 /* XXX should handle this material another way */
799 ulr = &VTOI(dvp)->i_crap;
800 ULFS_CHECK_CRAPCOUNTER(VTOI(dvp));
801
802 fs = VFSTOULFS(dvp->v_mount)->um_lfs;
803 ASSERT_NO_SEGLOCK(fs);
804 if (fs->lfs_ronly) {
805 return EROFS;
806 }
807
808 error = lfs_set_dirop(dvp, NULL);
809 if (error)
810 return error;
811
812 fstrans_start(dvp->v_mount, FSTRANS_SHARED);
813 error = lfs_makeinode(vap, dvp, ulr, vpp, ap->a_cnp);
814
815 /* Either way we're done with the dirop at this point */
816 UNMARK_VNODE(dvp);
817 UNMARK_VNODE(*vpp);
818 lfs_unset_dirop(fs, dvp, "mknod");
819
820 if (error) {
821 fstrans_done(dvp->v_mount);
822 vrele(dvp);
823 *vpp = NULL;
824 return (error);
825 }
826
827 VN_KNOTE(dvp, NOTE_WRITE);
828 ip = VTOI(*vpp);
829 ino = ip->i_number;
830 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
831
832 /*
833 * Call fsync to write the vnode so that we don't have to deal with
834 * flushing it when it's marked VU_DIROP or reclaiming.
835 *
836 * XXX KS - If we can't flush we also can't call vgone(), so must
837 * return. But, that leaves this vnode in limbo, also not good.
838 * Can this ever happen (barring hardware failure)?
839 */
840 if ((error = VOP_FSYNC(*vpp, NOCRED, FSYNC_WAIT, 0, 0)) != 0) {
841 panic("lfs_mknod: couldn't fsync (ino %llu)",
842 (unsigned long long) ino);
843 /* return (error); */
844 }
845
846 fstrans_done(dvp->v_mount);
847 vrele(dvp);
848 KASSERT(error == 0);
849 VOP_UNLOCK(*vpp);
850 return (0);
851 }
852
853 /*
854 * Create a regular file
855 */
856 int
857 lfs_create(void *v)
858 {
859 struct vop_create_v3_args /* {
860 struct vnode *a_dvp;
861 struct vnode **a_vpp;
862 struct componentname *a_cnp;
863 struct vattr *a_vap;
864 } */ *ap = v;
865 struct lfs *fs;
866 struct vnode *dvp, **vpp;
867 struct vattr *vap;
868 struct ulfs_lookup_results *ulr;
869 int error;
870
871 dvp = ap->a_dvp;
872 vpp = ap->a_vpp;
873 vap = ap->a_vap;
874
875 KASSERT(vpp != NULL);
876 KASSERT(*vpp == NULL);
877
878 /* XXX should handle this material another way */
879 ulr = &VTOI(dvp)->i_crap;
880 ULFS_CHECK_CRAPCOUNTER(VTOI(dvp));
881
882 fs = VFSTOULFS(dvp->v_mount)->um_lfs;
883 ASSERT_NO_SEGLOCK(fs);
884 if (fs->lfs_ronly) {
885 return EROFS;
886 }
887
888 error = lfs_set_dirop(dvp, NULL);
889 if (error)
890 return error;
891
892 fstrans_start(dvp->v_mount, FSTRANS_SHARED);
893 error = lfs_makeinode(vap, dvp, ulr, vpp, ap->a_cnp);
894 if (error) {
895 fstrans_done(dvp->v_mount);
896 goto out;
897 }
898 fstrans_done(dvp->v_mount);
899 VN_KNOTE(dvp, NOTE_WRITE);
900 VOP_UNLOCK(*vpp);
901
902 out:
903
904 UNMARK_VNODE(dvp);
905 UNMARK_VNODE(*vpp);
906 if (error) {
907 *vpp = NULL;
908 }
909 lfs_unset_dirop(fs, dvp, "create");
910
911 vrele(dvp);
912 return (error);
913 }
914
915 int
916 lfs_mkdir(void *v)
917 {
918 struct vop_mkdir_v3_args /* {
919 struct vnode *a_dvp;
920 struct vnode **a_vpp;
921 struct componentname *a_cnp;
922 struct vattr *a_vap;
923 } */ *ap = v;
924 struct lfs *fs;
925 struct vnode *dvp, *tvp, **vpp;
926 struct inode *dp, *ip;
927 struct componentname *cnp;
928 struct vattr *vap;
929 struct ulfs_lookup_results *ulr;
930 struct buf *bp;
931 LFS_DIRHEADER *dirp;
932 int dirblksiz;
933 int error;
934
935 dvp = ap->a_dvp;
936 tvp = NULL;
937 vpp = ap->a_vpp;
938 cnp = ap->a_cnp;
939 vap = ap->a_vap;
940
941 dp = VTOI(dvp);
942 ip = NULL;
943
944 KASSERT(vap->va_type == VDIR);
945 KASSERT(vpp != NULL);
946 KASSERT(*vpp == NULL);
947
948 /* XXX should handle this material another way */
949 ulr = &dp->i_crap;
950 ULFS_CHECK_CRAPCOUNTER(dp);
951
952 fs = VFSTOULFS(dvp->v_mount)->um_lfs;
953 ASSERT_NO_SEGLOCK(fs);
954 if (fs->lfs_ronly) {
955 return EROFS;
956 }
957 dirblksiz = fs->um_dirblksiz;
958 /* XXX dholland 20150911 I believe this to be true, but... */
959 //KASSERT(dirblksiz == LFS_DIRBLKSIZ);
960
961 error = lfs_set_dirop(dvp, NULL);
962 if (error)
963 return error;
964
965 fstrans_start(dvp->v_mount, FSTRANS_SHARED);
966
967 if ((nlink_t)dp->i_nlink >= LINK_MAX) {
968 error = EMLINK;
969 goto out;
970 }
971
972 /*
973 * Must simulate part of lfs_makeinode here to acquire the inode,
974 * but not have it entered in the parent directory. The entry is
975 * made later after writing "." and ".." entries.
976 */
977 error = vcache_new(dvp->v_mount, dvp, vap, cnp->cn_cred, ap->a_vpp);
978 if (error)
979 goto out;
980
981 error = vn_lock(*ap->a_vpp, LK_EXCLUSIVE);
982 if (error) {
983 vrele(*ap->a_vpp);
984 *ap->a_vpp = NULL;
985 goto out;
986 }
987
988 tvp = *ap->a_vpp;
989 lfs_mark_vnode(tvp);
990 ip = VTOI(tvp);
991 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
992 ip->i_nlink = 2;
993 DIP_ASSIGN(ip, nlink, 2);
994 if (cnp->cn_flags & ISWHITEOUT) {
995 ip->i_flags |= UF_OPAQUE;
996 DIP_ASSIGN(ip, flags, ip->i_flags);
997 }
998
999 /*
1000 * Bump link count in parent directory to reflect work done below.
1001 */
1002 dp->i_nlink++;
1003 DIP_ASSIGN(dp, nlink, dp->i_nlink);
1004 dp->i_flag |= IN_CHANGE;
1005 if ((error = lfs_update(dvp, NULL, NULL, UPDATE_DIROP)) != 0)
1006 goto bad;
1007
1008 /*
1009 * Initialize directory with "." and "..". This used to use a
1010 * static template but that adds moving parts for very little
1011 * benefit.
1012 */
1013 if ((error = lfs_balloc(tvp, (off_t)0, dirblksiz, cnp->cn_cred,
1014 B_CLRBUF, &bp)) != 0)
1015 goto bad;
1016 ip->i_size = dirblksiz;
1017 DIP_ASSIGN(ip, size, dirblksiz);
1018 ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
1019 uvm_vnp_setsize(tvp, ip->i_size);
1020 dirp = bp->b_data;
1021
1022 /* . */
1023 lfs_dir_setino(fs, dirp, ip->i_number);
1024 lfs_dir_setreclen(fs, dirp, LFS_DIRECTSIZ(fs, 1));
1025 lfs_dir_settype(fs, dirp, LFS_DT_DIR);
1026 lfs_dir_setnamlen(fs, dirp, 1);
1027 lfs_copydirname(fs, lfs_dir_nameptr(fs, dirp), ".", 1,
1028 LFS_DIRECTSIZ(fs, 1));
1029 dirp = LFS_NEXTDIR(fs, dirp);
1030 /* .. */
1031 lfs_dir_setino(fs, dirp, dp->i_number);
1032 lfs_dir_setreclen(fs, dirp, dirblksiz - LFS_DIRECTSIZ(fs, 1));
1033 lfs_dir_settype(fs, dirp, LFS_DT_DIR);
1034 lfs_dir_setnamlen(fs, dirp, 2);
1035 lfs_copydirname(fs, lfs_dir_nameptr(fs, dirp), "..", 2,
1036 dirblksiz - LFS_DIRECTSIZ(fs, 1));
1037
1038 /*
1039 * Directory set up; now install its entry in the parent directory.
1040 */
1041 if ((error = VOP_BWRITE(bp->b_vp, bp)) != 0)
1042 goto bad;
1043 if ((error = lfs_update(tvp, NULL, NULL, UPDATE_DIROP)) != 0) {
1044 goto bad;
1045 }
1046 error = ulfs_direnter(dvp, ulr, tvp,
1047 cnp, ip->i_number, LFS_IFTODT(ip->i_mode), bp);
1048 bad:
1049 if (error == 0) {
1050 VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
1051 VOP_UNLOCK(tvp);
1052 } else {
1053 dp->i_nlink--;
1054 DIP_ASSIGN(dp, nlink, dp->i_nlink);
1055 dp->i_flag |= IN_CHANGE;
1056 /*
1057 * No need to do an explicit lfs_truncate here, vrele will
1058 * do this for us because we set the link count to 0.
1059 */
1060 ip->i_nlink = 0;
1061 DIP_ASSIGN(ip, nlink, 0);
1062 ip->i_flag |= IN_CHANGE;
1063 /* If IN_ADIROP, account for it */
1064 lfs_unmark_vnode(tvp);
1065 vput(tvp);
1066 }
1067
1068 out:
1069 fstrans_done(dvp->v_mount);
1070
1071 UNMARK_VNODE(dvp);
1072 UNMARK_VNODE(*vpp);
1073 if (error) {
1074 *vpp = NULL;
1075 }
1076 lfs_unset_dirop(fs, dvp, "mkdir");
1077
1078 vrele(dvp);
1079 return (error);
1080 }
1081
1082 int
1083 lfs_remove(void *v)
1084 {
1085 struct vop_remove_args /* {
1086 struct vnode *a_dvp;
1087 struct vnode *a_vp;
1088 struct componentname *a_cnp;
1089 } */ *ap = v;
1090 struct vnode *dvp, *vp;
1091 struct inode *ip;
1092 int error;
1093
1094 dvp = ap->a_dvp;
1095 vp = ap->a_vp;
1096 ip = VTOI(vp);
1097 if ((error = lfs_set_dirop(dvp, vp)) != 0) {
1098 if (dvp == vp)
1099 vrele(vp);
1100 else
1101 vput(vp);
1102 vput(dvp);
1103 return error;
1104 }
1105 error = ulfs_remove(ap);
1106 if (ip->i_nlink == 0)
1107 lfs_orphan(ip->i_lfs, ip->i_number);
1108
1109 UNMARK_VNODE(dvp);
1110 if (ap->a_vp) {
1111 UNMARK_VNODE(ap->a_vp);
1112 }
1113 lfs_unset_dirop(ip->i_lfs, dvp, "remove");
1114 vrele(dvp);
1115 if (ap->a_vp) {
1116 vrele(ap->a_vp);
1117 }
1118
1119 return (error);
1120 }
1121
1122 int
1123 lfs_rmdir(void *v)
1124 {
1125 struct vop_rmdir_args /* {
1126 struct vnodeop_desc *a_desc;
1127 struct vnode *a_dvp;
1128 struct vnode *a_vp;
1129 struct componentname *a_cnp;
1130 } */ *ap = v;
1131 struct vnode *vp;
1132 struct inode *ip;
1133 int error;
1134
1135 vp = ap->a_vp;
1136 ip = VTOI(vp);
1137 if ((error = lfs_set_dirop(ap->a_dvp, ap->a_vp)) != 0) {
1138 if (ap->a_dvp == vp)
1139 vrele(ap->a_dvp);
1140 else
1141 vput(ap->a_dvp);
1142 vput(vp);
1143 return error;
1144 }
1145 error = ulfs_rmdir(ap);
1146 if (ip->i_nlink == 0)
1147 lfs_orphan(ip->i_lfs, ip->i_number);
1148
1149 UNMARK_VNODE(ap->a_dvp);
1150 if (ap->a_vp) {
1151 UNMARK_VNODE(ap->a_vp);
1152 }
1153 lfs_unset_dirop(ip->i_lfs, ap->a_dvp, "rmdir");
1154 vrele(ap->a_dvp);
1155 if (ap->a_vp) {
1156 vrele(ap->a_vp);
1157 }
1158
1159 return (error);
1160 }
1161
1162 int
1163 lfs_link(void *v)
1164 {
1165 struct vop_link_v2_args /* {
1166 struct vnode *a_dvp;
1167 struct vnode *a_vp;
1168 struct componentname *a_cnp;
1169 } */ *ap = v;
1170 struct lfs *fs;
1171 struct vnode *dvp;
1172 int error;
1173
1174 dvp = ap->a_dvp;
1175
1176 fs = VFSTOULFS(dvp->v_mount)->um_lfs;
1177 ASSERT_NO_SEGLOCK(fs);
1178 if (fs->lfs_ronly) {
1179 return EROFS;
1180 }
1181
1182 error = lfs_set_dirop(dvp, NULL);
1183 if (error) {
1184 return error;
1185 }
1186
1187 error = ulfs_link(ap);
1188
1189 UNMARK_VNODE(dvp);
1190 lfs_unset_dirop(fs, dvp, "link");
1191 vrele(dvp);
1192
1193 return (error);
1194 }
1195
1196 /* XXX hack to avoid calling ITIMES in getattr */
1197 int
1198 lfs_getattr(void *v)
1199 {
1200 struct vop_getattr_args /* {
1201 struct vnode *a_vp;
1202 struct vattr *a_vap;
1203 kauth_cred_t a_cred;
1204 } */ *ap = v;
1205 struct vnode *vp = ap->a_vp;
1206 struct inode *ip = VTOI(vp);
1207 struct vattr *vap = ap->a_vap;
1208 struct lfs *fs = ip->i_lfs;
1209
1210 fstrans_start(vp->v_mount, FSTRANS_SHARED);
1211 /*
1212 * Copy from inode table
1213 */
1214 vap->va_fsid = ip->i_dev;
1215 vap->va_fileid = ip->i_number;
1216 vap->va_mode = ip->i_mode & ~LFS_IFMT;
1217 vap->va_nlink = ip->i_nlink;
1218 vap->va_uid = ip->i_uid;
1219 vap->va_gid = ip->i_gid;
1220 switch (vp->v_type) {
1221 case VBLK:
1222 case VCHR:
1223 vap->va_rdev = (dev_t)lfs_dino_getrdev(fs, ip->i_din);
1224 break;
1225 default:
1226 vap->va_rdev = NODEV;
1227 break;
1228 }
1229 vap->va_size = vp->v_size;
1230 vap->va_atime.tv_sec = lfs_dino_getatime(fs, ip->i_din);
1231 vap->va_atime.tv_nsec = lfs_dino_getatimensec(fs, ip->i_din);
1232 vap->va_mtime.tv_sec = lfs_dino_getmtime(fs, ip->i_din);
1233 vap->va_mtime.tv_nsec = lfs_dino_getmtimensec(fs, ip->i_din);
1234 vap->va_ctime.tv_sec = lfs_dino_getctime(fs, ip->i_din);
1235 vap->va_ctime.tv_nsec = lfs_dino_getctimensec(fs, ip->i_din);
1236 vap->va_flags = ip->i_flags;
1237 vap->va_gen = ip->i_gen;
1238 /* this doesn't belong here */
1239 if (vp->v_type == VBLK)
1240 vap->va_blocksize = BLKDEV_IOSIZE;
1241 else if (vp->v_type == VCHR)
1242 vap->va_blocksize = MAXBSIZE;
1243 else
1244 vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
1245 vap->va_bytes = lfs_fsbtob(fs, ip->i_lfs_effnblks);
1246 vap->va_type = vp->v_type;
1247 vap->va_filerev = ip->i_modrev;
1248 fstrans_done(vp->v_mount);
1249 return (0);
1250 }
1251
1252 /*
1253 * Check to make sure the inode blocks won't choke the buffer
1254 * cache, then call ulfs_setattr as usual.
1255 */
1256 int
1257 lfs_setattr(void *v)
1258 {
1259 struct vop_setattr_args /* {
1260 struct vnode *a_vp;
1261 struct vattr *a_vap;
1262 kauth_cred_t a_cred;
1263 } */ *ap = v;
1264 struct vnode *vp = ap->a_vp;
1265
1266 lfs_check(vp, LFS_UNUSED_LBN, 0);
1267 return ulfs_setattr(v);
1268 }
1269
1270 /*
1271 * Release the block we hold on lfs_newseg wrapping. Called on file close,
1272 * or explicitly from LFCNWRAPGO. Called with the interlock held.
1273 */
1274 static int
1275 lfs_wrapgo(struct lfs *fs, struct inode *ip, int waitfor)
1276 {
1277 if (fs->lfs_stoplwp != curlwp)
1278 return EBUSY;
1279
1280 fs->lfs_stoplwp = NULL;
1281 cv_signal(&fs->lfs_stopcv);
1282
1283 KASSERT(fs->lfs_nowrap > 0);
1284 if (fs->lfs_nowrap <= 0) {
1285 return 0;
1286 }
1287
1288 if (--fs->lfs_nowrap == 0) {
1289 log(LOG_NOTICE, "%s: re-enabled log wrap\n",
1290 lfs_sb_getfsmnt(fs));
1291 wakeup(&fs->lfs_wrappass);
1292 lfs_wakeup_cleaner(fs);
1293 }
1294 if (waitfor) {
1295 mtsleep(&fs->lfs_nextsegsleep, PCATCH | PUSER, "segment",
1296 0, &lfs_lock);
1297 }
1298
1299 return 0;
1300 }
1301
1302 /*
1303 * Close called.
1304 *
1305 * Update the times on the inode.
1306 */
1307 /* ARGSUSED */
1308 int
1309 lfs_close(void *v)
1310 {
1311 struct vop_close_args /* {
1312 struct vnode *a_vp;
1313 int a_fflag;
1314 kauth_cred_t a_cred;
1315 } */ *ap = v;
1316 struct vnode *vp = ap->a_vp;
1317 struct inode *ip = VTOI(vp);
1318 struct lfs *fs = ip->i_lfs;
1319
1320 if ((ip->i_number == ULFS_ROOTINO || ip->i_number == LFS_IFILE_INUM) &&
1321 fs->lfs_stoplwp == curlwp) {
1322 mutex_enter(&lfs_lock);
1323 log(LOG_NOTICE, "lfs_close: releasing log wrap control\n");
1324 lfs_wrapgo(fs, ip, 0);
1325 mutex_exit(&lfs_lock);
1326 }
1327
1328 if (vp == ip->i_lfs->lfs_ivnode &&
1329 vp->v_mount->mnt_iflag & IMNT_UNMOUNT)
1330 return 0;
1331
1332 fstrans_start(vp->v_mount, FSTRANS_SHARED);
1333 if (vp->v_usecount > 1 && vp != ip->i_lfs->lfs_ivnode) {
1334 LFS_ITIMES(ip, NULL, NULL, NULL);
1335 }
1336 fstrans_done(vp->v_mount);
1337 return (0);
1338 }
1339
1340 /*
1341 * Close wrapper for special devices.
1342 *
1343 * Update the times on the inode then do device close.
1344 */
1345 int
1346 lfsspec_close(void *v)
1347 {
1348 struct vop_close_args /* {
1349 struct vnode *a_vp;
1350 int a_fflag;
1351 kauth_cred_t a_cred;
1352 } */ *ap = v;
1353 struct vnode *vp;
1354 struct inode *ip;
1355
1356 vp = ap->a_vp;
1357 ip = VTOI(vp);
1358 if (vp->v_usecount > 1) {
1359 LFS_ITIMES(ip, NULL, NULL, NULL);
1360 }
1361 return (VOCALL (spec_vnodeop_p, VOFFSET(vop_close), ap));
1362 }
1363
1364 /*
1365 * Close wrapper for fifo's.
1366 *
1367 * Update the times on the inode then do device close.
1368 */
1369 int
1370 lfsfifo_close(void *v)
1371 {
1372 struct vop_close_args /* {
1373 struct vnode *a_vp;
1374 int a_fflag;
1375 kauth_cred_ a_cred;
1376 } */ *ap = v;
1377 struct vnode *vp;
1378 struct inode *ip;
1379
1380 vp = ap->a_vp;
1381 ip = VTOI(vp);
1382 if (ap->a_vp->v_usecount > 1) {
1383 LFS_ITIMES(ip, NULL, NULL, NULL);
1384 }
1385 return (VOCALL (fifo_vnodeop_p, VOFFSET(vop_close), ap));
1386 }
1387
1388 /*
1389 * Reclaim an inode so that it can be used for other purposes.
1390 */
1391
1392 int
1393 lfs_reclaim(void *v)
1394 {
1395 struct vop_reclaim_args /* {
1396 struct vnode *a_vp;
1397 } */ *ap = v;
1398 struct vnode *vp = ap->a_vp;
1399 struct inode *ip = VTOI(vp);
1400 struct lfs *fs = ip->i_lfs;
1401 int error;
1402
1403 /*
1404 * The inode must be freed and updated before being removed
1405 * from its hash chain. Other threads trying to gain a hold
1406 * or lock on the inode will be stalled.
1407 */
1408 if (ip->i_nlink <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
1409 lfs_vfree(vp, ip->i_number, ip->i_omode);
1410
1411 mutex_enter(&lfs_lock);
1412 LFS_CLR_UINO(ip, IN_ALLMOD);
1413 mutex_exit(&lfs_lock);
1414 if ((error = ulfs_reclaim(vp)))
1415 return (error);
1416
1417 /*
1418 * Take us off the paging and/or dirop queues if we were on them.
1419 * We shouldn't be on them.
1420 */
1421 mutex_enter(&lfs_lock);
1422 if (ip->i_flags & IN_PAGING) {
1423 log(LOG_WARNING, "%s: reclaimed vnode is IN_PAGING\n",
1424 lfs_sb_getfsmnt(fs));
1425 ip->i_flags &= ~IN_PAGING;
1426 TAILQ_REMOVE(&fs->lfs_pchainhd, ip, i_lfs_pchain);
1427 }
1428 if (vp->v_uflag & VU_DIROP) {
1429 panic("reclaimed vnode is VU_DIROP");
1430 vp->v_uflag &= ~VU_DIROP;
1431 TAILQ_REMOVE(&fs->lfs_dchainhd, ip, i_lfs_dchain);
1432 }
1433 mutex_exit(&lfs_lock);
1434
1435 pool_put(&lfs_dinode_pool, ip->i_din);
1436 lfs_deregister_all(vp);
1437 pool_put(&lfs_inoext_pool, ip->inode_ext.lfs);
1438 ip->inode_ext.lfs = NULL;
1439 genfs_node_destroy(vp);
1440 pool_put(&lfs_inode_pool, vp->v_data);
1441 vp->v_data = NULL;
1442 return (0);
1443 }
1444
1445 /*
1446 * Read a block from a storage device.
1447 *
1448 * Calculate the logical to physical mapping if not done already,
1449 * then call the device strategy routine.
1450 *
1451 * In order to avoid reading blocks that are in the process of being
1452 * written by the cleaner---and hence are not mutexed by the normal
1453 * buffer cache / page cache mechanisms---check for collisions before
1454 * reading.
1455 *
1456 * We inline ulfs_strategy to make sure that the VOP_BMAP occurs *before*
1457 * the active cleaner test.
1458 *
1459 * XXX This code assumes that lfs_markv makes synchronous checkpoints.
1460 */
1461 int
1462 lfs_strategy(void *v)
1463 {
1464 struct vop_strategy_args /* {
1465 struct vnode *a_vp;
1466 struct buf *a_bp;
1467 } */ *ap = v;
1468 struct buf *bp;
1469 struct lfs *fs;
1470 struct vnode *vp;
1471 struct inode *ip;
1472 daddr_t tbn;
1473 #define MAXLOOP 25
1474 int i, sn, error, slept, loopcount;
1475
1476 bp = ap->a_bp;
1477 vp = ap->a_vp;
1478 ip = VTOI(vp);
1479 fs = ip->i_lfs;
1480
1481 /* lfs uses its strategy routine only for read */
1482 KASSERT(bp->b_flags & B_READ);
1483
1484 if (vp->v_type == VBLK || vp->v_type == VCHR)
1485 panic("lfs_strategy: spec");
1486 KASSERT(bp->b_bcount != 0);
1487 if (bp->b_blkno == bp->b_lblkno) {
1488 error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno,
1489 NULL);
1490 if (error) {
1491 bp->b_error = error;
1492 bp->b_resid = bp->b_bcount;
1493 biodone(bp);
1494 return (error);
1495 }
1496 if ((long)bp->b_blkno == -1) /* no valid data */
1497 clrbuf(bp);
1498 }
1499 if ((long)bp->b_blkno < 0) { /* block is not on disk */
1500 bp->b_resid = bp->b_bcount;
1501 biodone(bp);
1502 return (0);
1503 }
1504
1505 slept = 1;
1506 loopcount = 0;
1507 mutex_enter(&lfs_lock);
1508 while (slept && fs->lfs_seglock) {
1509 mutex_exit(&lfs_lock);
1510 /*
1511 * Look through list of intervals.
1512 * There will only be intervals to look through
1513 * if the cleaner holds the seglock.
1514 * Since the cleaner is synchronous, we can trust
1515 * the list of intervals to be current.
1516 */
1517 tbn = LFS_DBTOFSB(fs, bp->b_blkno);
1518 sn = lfs_dtosn(fs, tbn);
1519 slept = 0;
1520 for (i = 0; i < fs->lfs_cleanind; i++) {
1521 if (sn == lfs_dtosn(fs, fs->lfs_cleanint[i]) &&
1522 tbn >= fs->lfs_cleanint[i]) {
1523 DLOG((DLOG_CLEAN,
1524 "lfs_strategy: ino %llu lbn %" PRId64
1525 " ind %d sn %d fsb %" PRIx64
1526 " given sn %d fsb %" PRIx64 "\n",
1527 (unsigned long long) ip->i_number,
1528 bp->b_lblkno, i,
1529 lfs_dtosn(fs, fs->lfs_cleanint[i]),
1530 fs->lfs_cleanint[i], sn, tbn));
1531 DLOG((DLOG_CLEAN,
1532 "lfs_strategy: sleeping on ino %llu lbn %"
1533 PRId64 "\n",
1534 (unsigned long long) ip->i_number,
1535 bp->b_lblkno));
1536 mutex_enter(&lfs_lock);
1537 if (LFS_SEGLOCK_HELD(fs) && fs->lfs_iocount) {
1538 /*
1539 * Cleaner can't wait for itself.
1540 * Instead, wait for the blocks
1541 * to be written to disk.
1542 * XXX we need pribio in the test
1543 * XXX here.
1544 */
1545 mtsleep(&fs->lfs_iocount,
1546 (PRIBIO + 1) | PNORELOCK,
1547 "clean2", hz/10 + 1,
1548 &lfs_lock);
1549 slept = 1;
1550 ++loopcount;
1551 break;
1552 } else if (fs->lfs_seglock) {
1553 mtsleep(&fs->lfs_seglock,
1554 (PRIBIO + 1) | PNORELOCK,
1555 "clean1", 0,
1556 &lfs_lock);
1557 slept = 1;
1558 break;
1559 }
1560 mutex_exit(&lfs_lock);
1561 }
1562 }
1563 mutex_enter(&lfs_lock);
1564 if (loopcount > MAXLOOP) {
1565 printf("lfs_strategy: breaking out of clean2 loop\n");
1566 break;
1567 }
1568 }
1569 mutex_exit(&lfs_lock);
1570
1571 vp = ip->i_devvp;
1572 return VOP_STRATEGY(vp, bp);
1573 }
1574
1575 /*
1576 * Inline lfs_segwrite/lfs_writevnodes, but just for dirops.
1577 * Technically this is a checkpoint (the on-disk state is valid)
1578 * even though we are leaving out all the file data.
1579 */
1580 int
1581 lfs_flush_dirops(struct lfs *fs)
1582 {
1583 struct inode *ip, *nip;
1584 struct vnode *vp;
1585 extern int lfs_dostats; /* XXX this does not belong here */
1586 struct segment *sp;
1587 SEGSUM *ssp;
1588 int flags = 0;
1589 int error = 0;
1590
1591 ASSERT_MAYBE_SEGLOCK(fs);
1592 KASSERT(fs->lfs_nadirop == 0);
1593
1594 if (fs->lfs_ronly)
1595 return EROFS;
1596
1597 mutex_enter(&lfs_lock);
1598 if (TAILQ_FIRST(&fs->lfs_dchainhd) == NULL) {
1599 mutex_exit(&lfs_lock);
1600 return 0;
1601 } else
1602 mutex_exit(&lfs_lock);
1603
1604 if (lfs_dostats)
1605 ++lfs_stats.flush_invoked;
1606
1607 lfs_imtime(fs);
1608 lfs_seglock(fs, flags);
1609 sp = fs->lfs_sp;
1610
1611 /*
1612 * lfs_writevnodes, optimized to get dirops out of the way.
1613 * Only write dirops, and don't flush files' pages, only
1614 * blocks from the directories.
1615 *
1616 * We don't need to vref these files because they are
1617 * dirops and so hold an extra reference until the
1618 * segunlock clears them of that status.
1619 *
1620 * We don't need to check for IN_ADIROP because we know that
1621 * no dirops are active.
1622 *
1623 */
1624 mutex_enter(&lfs_lock);
1625 for (ip = TAILQ_FIRST(&fs->lfs_dchainhd); ip != NULL; ip = nip) {
1626 nip = TAILQ_NEXT(ip, i_lfs_dchain);
1627 mutex_exit(&lfs_lock);
1628 vp = ITOV(ip);
1629 mutex_enter(vp->v_interlock);
1630
1631 KASSERT((ip->i_flag & IN_ADIROP) == 0);
1632 KASSERT(vp->v_uflag & VU_DIROP);
1633 KASSERT(vdead_check(vp, VDEAD_NOWAIT) == 0);
1634
1635 /*
1636 * All writes to directories come from dirops; all
1637 * writes to files' direct blocks go through the page
1638 * cache, which we're not touching. Reads to files
1639 * and/or directories will not be affected by writing
1640 * directory blocks inodes and file inodes. So we don't
1641 * really need to lock.
1642 */
1643 if (vdead_check(vp, VDEAD_NOWAIT) != 0) {
1644 mutex_exit(vp->v_interlock);
1645 mutex_enter(&lfs_lock);
1646 continue;
1647 }
1648 mutex_exit(vp->v_interlock);
1649 /* XXX see below
1650 * waslocked = VOP_ISLOCKED(vp);
1651 */
1652 if (vp->v_type != VREG &&
1653 ((ip->i_flag & IN_ALLMOD) || !VPISEMPTY(vp))) {
1654 error = lfs_writefile(fs, sp, vp);
1655 if (!VPISEMPTY(vp) && !WRITEINPROG(vp) &&
1656 !(ip->i_flag & IN_ALLMOD)) {
1657 mutex_enter(&lfs_lock);
1658 LFS_SET_UINO(ip, IN_MODIFIED);
1659 mutex_exit(&lfs_lock);
1660 }
1661 if (error && (sp->seg_flags & SEGM_SINGLE)) {
1662 mutex_enter(&lfs_lock);
1663 error = EAGAIN;
1664 break;
1665 }
1666 }
1667 KDASSERT(ip->i_number != LFS_IFILE_INUM);
1668 error = lfs_writeinode(fs, sp, ip);
1669 mutex_enter(&lfs_lock);
1670 if (error && (sp->seg_flags & SEGM_SINGLE)) {
1671 error = EAGAIN;
1672 break;
1673 }
1674
1675 /*
1676 * We might need to update these inodes again,
1677 * for example, if they have data blocks to write.
1678 * Make sure that after this flush, they are still
1679 * marked IN_MODIFIED so that we don't forget to
1680 * write them.
1681 */
1682 /* XXX only for non-directories? --KS */
1683 LFS_SET_UINO(ip, IN_MODIFIED);
1684 }
1685 mutex_exit(&lfs_lock);
1686 /* We've written all the dirops there are */
1687 ssp = (SEGSUM *)sp->segsum;
1688 lfs_ss_setflags(fs, ssp, lfs_ss_getflags(fs, ssp) & ~(SS_CONT));
1689 lfs_finalize_fs_seguse(fs);
1690 (void) lfs_writeseg(fs, sp);
1691 lfs_segunlock(fs);
1692
1693 return error;
1694 }
1695
1696 /*
1697 * Flush all vnodes for which the pagedaemon has requested pageouts.
1698 * Skip over any files that are marked VU_DIROP (since lfs_flush_dirop()
1699 * has just run, this would be an error). If we have to skip a vnode
1700 * for any reason, just skip it; if we have to wait for the cleaner,
1701 * abort. The writer daemon will call us again later.
1702 */
1703 int
1704 lfs_flush_pchain(struct lfs *fs)
1705 {
1706 struct inode *ip, *nip;
1707 struct vnode *vp;
1708 extern int lfs_dostats;
1709 struct segment *sp;
1710 int error, error2;
1711
1712 ASSERT_NO_SEGLOCK(fs);
1713
1714 if (fs->lfs_ronly)
1715 return EROFS;
1716
1717 mutex_enter(&lfs_lock);
1718 if (TAILQ_FIRST(&fs->lfs_pchainhd) == NULL) {
1719 mutex_exit(&lfs_lock);
1720 return 0;
1721 } else
1722 mutex_exit(&lfs_lock);
1723
1724 /* Get dirops out of the way */
1725 if ((error = lfs_flush_dirops(fs)) != 0)
1726 return error;
1727
1728 if (lfs_dostats)
1729 ++lfs_stats.flush_invoked;
1730
1731 /*
1732 * Inline lfs_segwrite/lfs_writevnodes, but just for pageouts.
1733 */
1734 lfs_imtime(fs);
1735 lfs_seglock(fs, 0);
1736 sp = fs->lfs_sp;
1737
1738 /*
1739 * lfs_writevnodes, optimized to clear pageout requests.
1740 * Only write non-dirop files that are in the pageout queue.
1741 * We're very conservative about what we write; we want to be
1742 * fast and async.
1743 */
1744 mutex_enter(&lfs_lock);
1745 top:
1746 for (ip = TAILQ_FIRST(&fs->lfs_pchainhd); ip != NULL; ip = nip) {
1747 struct mount *mp = ITOV(ip)->v_mount;
1748 ino_t ino = ip->i_number;
1749
1750 nip = TAILQ_NEXT(ip, i_lfs_pchain);
1751
1752 if (!(ip->i_flags & IN_PAGING))
1753 goto top;
1754
1755 mutex_exit(&lfs_lock);
1756 if (vcache_get(mp, &ino, sizeof(ino), &vp) != 0) {
1757 mutex_enter(&lfs_lock);
1758 continue;
1759 };
1760 if (vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT) != 0) {
1761 vrele(vp);
1762 mutex_enter(&lfs_lock);
1763 continue;
1764 }
1765 ip = VTOI(vp);
1766 mutex_enter(&lfs_lock);
1767 if ((vp->v_uflag & VU_DIROP) != 0 || vp->v_type != VREG ||
1768 !(ip->i_flags & IN_PAGING)) {
1769 mutex_exit(&lfs_lock);
1770 vput(vp);
1771 mutex_enter(&lfs_lock);
1772 goto top;
1773 }
1774 mutex_exit(&lfs_lock);
1775
1776 error = lfs_writefile(fs, sp, vp);
1777 if (!VPISEMPTY(vp) && !WRITEINPROG(vp) &&
1778 !(ip->i_flag & IN_ALLMOD)) {
1779 mutex_enter(&lfs_lock);
1780 LFS_SET_UINO(ip, IN_MODIFIED);
1781 mutex_exit(&lfs_lock);
1782 }
1783 KDASSERT(ip->i_number != LFS_IFILE_INUM);
1784 error2 = lfs_writeinode(fs, sp, ip);
1785
1786 VOP_UNLOCK(vp);
1787 vrele(vp);
1788
1789 if (error == EAGAIN || error2 == EAGAIN) {
1790 lfs_writeseg(fs, sp);
1791 mutex_enter(&lfs_lock);
1792 break;
1793 }
1794 mutex_enter(&lfs_lock);
1795 }
1796 mutex_exit(&lfs_lock);
1797 (void) lfs_writeseg(fs, sp);
1798 lfs_segunlock(fs);
1799
1800 return 0;
1801 }
1802
1803 /*
1804 * Conversion for compat.
1805 */
1806 static void
1807 block_info_from_70(BLOCK_INFO *bi, const BLOCK_INFO_70 *bi70)
1808 {
1809 bi->bi_inode = bi70->bi_inode;
1810 bi->bi_lbn = bi70->bi_lbn;
1811 bi->bi_daddr = bi70->bi_daddr;
1812 bi->bi_segcreate = bi70->bi_segcreate;
1813 bi->bi_version = bi70->bi_version;
1814 bi->bi_bp = bi70->bi_bp;
1815 bi->bi_size = bi70->bi_size;
1816 }
1817
1818 static void
1819 block_info_to_70(BLOCK_INFO_70 *bi70, const BLOCK_INFO *bi)
1820 {
1821 bi70->bi_inode = bi->bi_inode;
1822 bi70->bi_lbn = bi->bi_lbn;
1823 bi70->bi_daddr = bi->bi_daddr;
1824 bi70->bi_segcreate = bi->bi_segcreate;
1825 bi70->bi_version = bi->bi_version;
1826 bi70->bi_bp = bi->bi_bp;
1827 bi70->bi_size = bi->bi_size;
1828 }
1829
1830 /*
1831 * Provide a fcntl interface to sys_lfs_{segwait,bmapv,markv}.
1832 */
1833 int
1834 lfs_fcntl(void *v)
1835 {
1836 struct vop_fcntl_args /* {
1837 struct vnode *a_vp;
1838 u_int a_command;
1839 void * a_data;
1840 int a_fflag;
1841 kauth_cred_t a_cred;
1842 } */ *ap = v;
1843 struct timeval tv;
1844 struct timeval *tvp;
1845 BLOCK_INFO *blkiov;
1846 BLOCK_INFO_70 *blkiov70;
1847 CLEANERINFO *cip;
1848 SEGUSE *sup;
1849 int blkcnt, i, error;
1850 size_t fh_size;
1851 struct lfs_fcntl_markv blkvp;
1852 struct lfs_fcntl_markv_70 blkvp70;
1853 struct lwp *l;
1854 fsid_t *fsidp;
1855 struct lfs *fs;
1856 struct buf *bp;
1857 fhandle_t *fhp;
1858 daddr_t off;
1859 int oclean;
1860
1861 /* Only respect LFS fcntls on fs root or Ifile */
1862 if (VTOI(ap->a_vp)->i_number != ULFS_ROOTINO &&
1863 VTOI(ap->a_vp)->i_number != LFS_IFILE_INUM) {
1864 return ulfs_fcntl(v);
1865 }
1866
1867 /* Avoid locking a draining lock */
1868 if (ap->a_vp->v_mount->mnt_iflag & IMNT_UNMOUNT) {
1869 return ESHUTDOWN;
1870 }
1871
1872 /* LFS control and monitoring fcntls are available only to root */
1873 l = curlwp;
1874 if (((ap->a_command & 0xff00) >> 8) == 'L' &&
1875 (error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_LFS,
1876 KAUTH_REQ_SYSTEM_LFS_FCNTL, NULL, NULL, NULL)) != 0)
1877 return (error);
1878
1879 fs = VTOI(ap->a_vp)->i_lfs;
1880 fsidp = &ap->a_vp->v_mount->mnt_stat.f_fsidx;
1881
1882 error = 0;
1883 switch ((int)ap->a_command) {
1884 case LFCNSEGWAITALL_COMPAT_50:
1885 case LFCNSEGWAITALL_COMPAT:
1886 fsidp = NULL;
1887 /* FALLTHROUGH */
1888 case LFCNSEGWAIT_COMPAT_50:
1889 case LFCNSEGWAIT_COMPAT:
1890 {
1891 struct timeval50 *tvp50
1892 = (struct timeval50 *)ap->a_data;
1893 timeval50_to_timeval(tvp50, &tv);
1894 tvp = &tv;
1895 }
1896 goto segwait_common;
1897 case LFCNSEGWAITALL:
1898 fsidp = NULL;
1899 /* FALLTHROUGH */
1900 case LFCNSEGWAIT:
1901 tvp = (struct timeval *)ap->a_data;
1902 segwait_common:
1903 mutex_enter(&lfs_lock);
1904 ++fs->lfs_sleepers;
1905 mutex_exit(&lfs_lock);
1906
1907 error = lfs_segwait(fsidp, tvp);
1908
1909 mutex_enter(&lfs_lock);
1910 if (--fs->lfs_sleepers == 0)
1911 wakeup(&fs->lfs_sleepers);
1912 mutex_exit(&lfs_lock);
1913 return error;
1914
1915 case LFCNBMAPV_COMPAT_70:
1916 case LFCNMARKV_COMPAT_70:
1917 blkvp70 = *(struct lfs_fcntl_markv_70 *)ap->a_data;
1918
1919 blkcnt = blkvp70.blkcnt;
1920 if ((u_int) blkcnt > LFS_MARKV_MAXBLKCNT)
1921 return (EINVAL);
1922 blkiov = lfs_malloc(fs, blkcnt * sizeof(BLOCK_INFO), LFS_NB_BLKIOV);
1923 blkiov70 = lfs_malloc(fs, sizeof(BLOCK_INFO_70), LFS_NB_BLKIOV);
1924 for (i = 0; i < blkcnt; i++) {
1925 error = copyin(&blkvp70.blkiov[i], blkiov70,
1926 sizeof(*blkiov70));
1927 if (error) {
1928 lfs_free(fs, blkiov70, LFS_NB_BLKIOV);
1929 lfs_free(fs, blkiov, LFS_NB_BLKIOV);
1930 return error;
1931 }
1932 block_info_from_70(&blkiov[i], blkiov70);
1933 }
1934
1935 mutex_enter(&lfs_lock);
1936 ++fs->lfs_sleepers;
1937 mutex_exit(&lfs_lock);
1938 if (ap->a_command == LFCNBMAPV)
1939 error = lfs_bmapv(l, fsidp, blkiov, blkcnt);
1940 else /* LFCNMARKV */
1941 error = lfs_markv(l, fsidp, blkiov, blkcnt);
1942 if (error == 0) {
1943 for (i = 0; i < blkcnt; i++) {
1944 block_info_to_70(blkiov70, &blkiov[i]);
1945 error = copyout(blkiov70, &blkvp70.blkiov[i],
1946 sizeof(*blkiov70));
1947 if (error) {
1948 break;
1949 }
1950 }
1951 }
1952 mutex_enter(&lfs_lock);
1953 if (--fs->lfs_sleepers == 0)
1954 wakeup(&fs->lfs_sleepers);
1955 mutex_exit(&lfs_lock);
1956 lfs_free(fs, blkiov, LFS_NB_BLKIOV);
1957 return error;
1958
1959 case LFCNBMAPV:
1960 case LFCNMARKV:
1961 blkvp = *(struct lfs_fcntl_markv *)ap->a_data;
1962
1963 blkcnt = blkvp.blkcnt;
1964 if ((u_int) blkcnt > LFS_MARKV_MAXBLKCNT)
1965 return (EINVAL);
1966 blkiov = lfs_malloc(fs, blkcnt * sizeof(BLOCK_INFO), LFS_NB_BLKIOV);
1967 if ((error = copyin(blkvp.blkiov, blkiov,
1968 blkcnt * sizeof(BLOCK_INFO))) != 0) {
1969 lfs_free(fs, blkiov, LFS_NB_BLKIOV);
1970 return error;
1971 }
1972
1973 mutex_enter(&lfs_lock);
1974 ++fs->lfs_sleepers;
1975 mutex_exit(&lfs_lock);
1976 if (ap->a_command == LFCNBMAPV)
1977 error = lfs_bmapv(l, fsidp, blkiov, blkcnt);
1978 else /* LFCNMARKV */
1979 error = lfs_markv(l, fsidp, blkiov, blkcnt);
1980 if (error == 0)
1981 error = copyout(blkiov, blkvp.blkiov,
1982 blkcnt * sizeof(BLOCK_INFO));
1983 mutex_enter(&lfs_lock);
1984 if (--fs->lfs_sleepers == 0)
1985 wakeup(&fs->lfs_sleepers);
1986 mutex_exit(&lfs_lock);
1987 lfs_free(fs, blkiov, LFS_NB_BLKIOV);
1988 return error;
1989
1990 case LFCNRECLAIM:
1991 /*
1992 * Flush dirops and write Ifile, allowing empty segments
1993 * to be immediately reclaimed.
1994 */
1995 lfs_writer_enter(fs, "pndirop");
1996 off = lfs_sb_getoffset(fs);
1997 lfs_seglock(fs, SEGM_FORCE_CKP | SEGM_CKP);
1998 lfs_flush_dirops(fs);
1999 LFS_CLEANERINFO(cip, fs, bp);
2000 oclean = lfs_ci_getclean(fs, cip);
2001 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1);
2002 lfs_segwrite(ap->a_vp->v_mount, SEGM_FORCE_CKP);
2003 fs->lfs_sp->seg_flags |= SEGM_PROT;
2004 lfs_segunlock(fs);
2005 lfs_writer_leave(fs);
2006
2007 #ifdef DEBUG
2008 LFS_CLEANERINFO(cip, fs, bp);
2009 DLOG((DLOG_CLEAN, "lfs_fcntl: reclaim wrote %" PRId64
2010 " blocks, cleaned %" PRId32 " segments (activesb %d)\n",
2011 lfs_sb_getoffset(fs) - off,
2012 lfs_ci_getclean(fs, cip) - oclean,
2013 fs->lfs_activesb));
2014 LFS_SYNC_CLEANERINFO(cip, fs, bp, 0);
2015 #else
2016 __USE(oclean);
2017 __USE(off);
2018 #endif
2019
2020 return 0;
2021
2022 case LFCNIFILEFH_COMPAT:
2023 /* Return the filehandle of the Ifile */
2024 if ((error = kauth_authorize_system(l->l_cred,
2025 KAUTH_SYSTEM_FILEHANDLE, 0, NULL, NULL, NULL)) != 0)
2026 return (error);
2027 fhp = (struct fhandle *)ap->a_data;
2028 fhp->fh_fsid = *fsidp;
2029 fh_size = 16; /* former VFS_MAXFIDSIZ */
2030 return lfs_vptofh(fs->lfs_ivnode, &(fhp->fh_fid), &fh_size);
2031
2032 case LFCNIFILEFH_COMPAT2:
2033 case LFCNIFILEFH:
2034 /* Return the filehandle of the Ifile */
2035 fhp = (struct fhandle *)ap->a_data;
2036 fhp->fh_fsid = *fsidp;
2037 fh_size = sizeof(struct lfs_fhandle) -
2038 offsetof(fhandle_t, fh_fid);
2039 return lfs_vptofh(fs->lfs_ivnode, &(fhp->fh_fid), &fh_size);
2040
2041 case LFCNREWIND:
2042 /* Move lfs_offset to the lowest-numbered segment */
2043 return lfs_rewind(fs, *(int *)ap->a_data);
2044
2045 case LFCNINVAL:
2046 /* Mark a segment SEGUSE_INVAL */
2047 LFS_SEGENTRY(sup, fs, *(int *)ap->a_data, bp);
2048 if (sup->su_nbytes > 0) {
2049 brelse(bp, 0);
2050 lfs_unset_inval_all(fs);
2051 return EBUSY;
2052 }
2053 sup->su_flags |= SEGUSE_INVAL;
2054 VOP_BWRITE(bp->b_vp, bp);
2055 return 0;
2056
2057 case LFCNRESIZE:
2058 /* Resize the filesystem */
2059 return lfs_resize_fs(fs, *(int *)ap->a_data);
2060
2061 case LFCNWRAPSTOP:
2062 case LFCNWRAPSTOP_COMPAT:
2063 /*
2064 * Hold lfs_newseg at segment 0; if requested, sleep until
2065 * the filesystem wraps around. To support external agents
2066 * (dump, fsck-based regression test) that need to look at
2067 * a snapshot of the filesystem, without necessarily
2068 * requiring that all fs activity stops.
2069 */
2070 if (fs->lfs_stoplwp == curlwp)
2071 return EALREADY;
2072
2073 mutex_enter(&lfs_lock);
2074 while (fs->lfs_stoplwp != NULL)
2075 cv_wait(&fs->lfs_stopcv, &lfs_lock);
2076 fs->lfs_stoplwp = curlwp;
2077 if (fs->lfs_nowrap == 0)
2078 log(LOG_NOTICE, "%s: disabled log wrap\n",
2079 lfs_sb_getfsmnt(fs));
2080 ++fs->lfs_nowrap;
2081 if (*(int *)ap->a_data == 1
2082 || ap->a_command == LFCNWRAPSTOP_COMPAT) {
2083 log(LOG_NOTICE, "LFCNSTOPWRAP waiting for log wrap\n");
2084 error = mtsleep(&fs->lfs_nowrap, PCATCH | PUSER,
2085 "segwrap", 0, &lfs_lock);
2086 log(LOG_NOTICE, "LFCNSTOPWRAP done waiting\n");
2087 if (error) {
2088 lfs_wrapgo(fs, VTOI(ap->a_vp), 0);
2089 }
2090 }
2091 mutex_exit(&lfs_lock);
2092 return 0;
2093
2094 case LFCNWRAPGO:
2095 case LFCNWRAPGO_COMPAT:
2096 /*
2097 * Having done its work, the agent wakes up the writer.
2098 * If the argument is 1, it sleeps until a new segment
2099 * is selected.
2100 */
2101 mutex_enter(&lfs_lock);
2102 error = lfs_wrapgo(fs, VTOI(ap->a_vp),
2103 ap->a_command == LFCNWRAPGO_COMPAT ? 1 :
2104 *((int *)ap->a_data));
2105 mutex_exit(&lfs_lock);
2106 return error;
2107
2108 case LFCNWRAPPASS:
2109 if ((VTOI(ap->a_vp)->i_lfs_iflags & LFSI_WRAPWAIT))
2110 return EALREADY;
2111 mutex_enter(&lfs_lock);
2112 if (fs->lfs_stoplwp != curlwp) {
2113 mutex_exit(&lfs_lock);
2114 return EALREADY;
2115 }
2116 if (fs->lfs_nowrap == 0) {
2117 mutex_exit(&lfs_lock);
2118 return EBUSY;
2119 }
2120 fs->lfs_wrappass = 1;
2121 wakeup(&fs->lfs_wrappass);
2122 /* Wait for the log to wrap, if asked */
2123 if (*(int *)ap->a_data) {
2124 vref(ap->a_vp);
2125 VTOI(ap->a_vp)->i_lfs_iflags |= LFSI_WRAPWAIT;
2126 log(LOG_NOTICE, "LFCNPASS waiting for log wrap\n");
2127 error = mtsleep(&fs->lfs_nowrap, PCATCH | PUSER,
2128 "segwrap", 0, &lfs_lock);
2129 log(LOG_NOTICE, "LFCNPASS done waiting\n");
2130 VTOI(ap->a_vp)->i_lfs_iflags &= ~LFSI_WRAPWAIT;
2131 vrele(ap->a_vp);
2132 }
2133 mutex_exit(&lfs_lock);
2134 return error;
2135
2136 case LFCNWRAPSTATUS:
2137 mutex_enter(&lfs_lock);
2138 *(int *)ap->a_data = fs->lfs_wrapstatus;
2139 mutex_exit(&lfs_lock);
2140 return 0;
2141
2142 default:
2143 return ulfs_fcntl(v);
2144 }
2145 return 0;
2146 }
2147
2148 /*
2149 * Return the last logical file offset that should be written for this file
2150 * if we're doing a write that ends at "size". If writing, we need to know
2151 * about sizes on disk, i.e. fragments if there are any; if reading, we need
2152 * to know about entire blocks.
2153 */
2154 void
2155 lfs_gop_size(struct vnode *vp, off_t size, off_t *eobp, int flags)
2156 {
2157 struct inode *ip = VTOI(vp);
2158 struct lfs *fs = ip->i_lfs;
2159 daddr_t olbn, nlbn;
2160
2161 olbn = lfs_lblkno(fs, ip->i_size);
2162 nlbn = lfs_lblkno(fs, size);
2163 if (!(flags & GOP_SIZE_MEM) && nlbn < ULFS_NDADDR && olbn <= nlbn) {
2164 *eobp = lfs_fragroundup(fs, size);
2165 } else {
2166 *eobp = lfs_blkroundup(fs, size);
2167 }
2168 }
2169
2170 #ifdef DEBUG
2171 void lfs_dump_vop(void *);
2172
2173 void
2174 lfs_dump_vop(void *v)
2175 {
2176 struct vop_putpages_args /* {
2177 struct vnode *a_vp;
2178 voff_t a_offlo;
2179 voff_t a_offhi;
2180 int a_flags;
2181 } */ *ap = v;
2182
2183 struct inode *ip = VTOI(ap->a_vp);
2184 struct lfs *fs = ip->i_lfs;
2185
2186 #ifdef DDB
2187 vfs_vnode_print(ap->a_vp, 0, printf);
2188 #endif
2189 lfs_dump_dinode(fs, ip->i_din);
2190 }
2191 #endif
2192
2193 int
2194 lfs_mmap(void *v)
2195 {
2196 struct vop_mmap_args /* {
2197 const struct vnodeop_desc *a_desc;
2198 struct vnode *a_vp;
2199 vm_prot_t a_prot;
2200 kauth_cred_t a_cred;
2201 } */ *ap = v;
2202
2203 if (VTOI(ap->a_vp)->i_number == LFS_IFILE_INUM)
2204 return EOPNOTSUPP;
2205 return ulfs_mmap(v);
2206 }
2207
2208 static int
2209 lfs_openextattr(void *v)
2210 {
2211 struct vop_openextattr_args /* {
2212 struct vnode *a_vp;
2213 kauth_cred_t a_cred;
2214 struct proc *a_p;
2215 } */ *ap = v;
2216 struct inode *ip = VTOI(ap->a_vp);
2217 struct ulfsmount *ump = ip->i_ump;
2218 //struct lfs *fs = ip->i_lfs;
2219
2220 /* Not supported for ULFS1 file systems. */
2221 if (ump->um_fstype == ULFS1)
2222 return (EOPNOTSUPP);
2223
2224 /* XXX Not implemented for ULFS2 file systems. */
2225 return (EOPNOTSUPP);
2226 }
2227
2228 static int
2229 lfs_closeextattr(void *v)
2230 {
2231 struct vop_closeextattr_args /* {
2232 struct vnode *a_vp;
2233 int a_commit;
2234 kauth_cred_t a_cred;
2235 struct proc *a_p;
2236 } */ *ap = v;
2237 struct inode *ip = VTOI(ap->a_vp);
2238 struct ulfsmount *ump = ip->i_ump;
2239 //struct lfs *fs = ip->i_lfs;
2240
2241 /* Not supported for ULFS1 file systems. */
2242 if (ump->um_fstype == ULFS1)
2243 return (EOPNOTSUPP);
2244
2245 /* XXX Not implemented for ULFS2 file systems. */
2246 return (EOPNOTSUPP);
2247 }
2248
2249 static int
2250 lfs_getextattr(void *v)
2251 {
2252 struct vop_getextattr_args /* {
2253 struct vnode *a_vp;
2254 int a_attrnamespace;
2255 const char *a_name;
2256 struct uio *a_uio;
2257 size_t *a_size;
2258 kauth_cred_t a_cred;
2259 struct proc *a_p;
2260 } */ *ap = v;
2261 struct vnode *vp = ap->a_vp;
2262 struct inode *ip = VTOI(vp);
2263 struct ulfsmount *ump = ip->i_ump;
2264 //struct lfs *fs = ip->i_lfs;
2265 int error;
2266
2267 if (ump->um_fstype == ULFS1) {
2268 #ifdef LFS_EXTATTR
2269 fstrans_start(vp->v_mount, FSTRANS_SHARED);
2270 error = ulfs_getextattr(ap);
2271 fstrans_done(vp->v_mount);
2272 #else
2273 error = EOPNOTSUPP;
2274 #endif
2275 return error;
2276 }
2277
2278 /* XXX Not implemented for ULFS2 file systems. */
2279 return (EOPNOTSUPP);
2280 }
2281
2282 static int
2283 lfs_setextattr(void *v)
2284 {
2285 struct vop_setextattr_args /* {
2286 struct vnode *a_vp;
2287 int a_attrnamespace;
2288 const char *a_name;
2289 struct uio *a_uio;
2290 kauth_cred_t a_cred;
2291 struct proc *a_p;
2292 } */ *ap = v;
2293 struct vnode *vp = ap->a_vp;
2294 struct inode *ip = VTOI(vp);
2295 struct ulfsmount *ump = ip->i_ump;
2296 //struct lfs *fs = ip->i_lfs;
2297 int error;
2298
2299 if (ump->um_fstype == ULFS1) {
2300 #ifdef LFS_EXTATTR
2301 fstrans_start(vp->v_mount, FSTRANS_SHARED);
2302 error = ulfs_setextattr(ap);
2303 fstrans_done(vp->v_mount);
2304 #else
2305 error = EOPNOTSUPP;
2306 #endif
2307 return error;
2308 }
2309
2310 /* XXX Not implemented for ULFS2 file systems. */
2311 return (EOPNOTSUPP);
2312 }
2313
2314 static int
2315 lfs_listextattr(void *v)
2316 {
2317 struct vop_listextattr_args /* {
2318 struct vnode *a_vp;
2319 int a_attrnamespace;
2320 struct uio *a_uio;
2321 size_t *a_size;
2322 kauth_cred_t a_cred;
2323 struct proc *a_p;
2324 } */ *ap = v;
2325 struct vnode *vp = ap->a_vp;
2326 struct inode *ip = VTOI(vp);
2327 struct ulfsmount *ump = ip->i_ump;
2328 //struct lfs *fs = ip->i_lfs;
2329 int error;
2330
2331 if (ump->um_fstype == ULFS1) {
2332 #ifdef LFS_EXTATTR
2333 fstrans_start(vp->v_mount, FSTRANS_SHARED);
2334 error = ulfs_listextattr(ap);
2335 fstrans_done(vp->v_mount);
2336 #else
2337 error = EOPNOTSUPP;
2338 #endif
2339 return error;
2340 }
2341
2342 /* XXX Not implemented for ULFS2 file systems. */
2343 return (EOPNOTSUPP);
2344 }
2345
2346 static int
2347 lfs_deleteextattr(void *v)
2348 {
2349 struct vop_deleteextattr_args /* {
2350 struct vnode *a_vp;
2351 int a_attrnamespace;
2352 kauth_cred_t a_cred;
2353 struct proc *a_p;
2354 } */ *ap = v;
2355 struct vnode *vp = ap->a_vp;
2356 struct inode *ip = VTOI(vp);
2357 struct ulfsmount *ump = ip->i_ump;
2358 //struct fs *fs = ip->i_lfs;
2359 int error;
2360
2361 if (ump->um_fstype == ULFS1) {
2362 #ifdef LFS_EXTATTR
2363 fstrans_start(vp->v_mount, FSTRANS_SHARED);
2364 error = ulfs_deleteextattr(ap);
2365 fstrans_done(vp->v_mount);
2366 #else
2367 error = EOPNOTSUPP;
2368 #endif
2369 return error;
2370 }
2371
2372 /* XXX Not implemented for ULFS2 file systems. */
2373 return (EOPNOTSUPP);
2374 }
2375
2376