1 /* $NetBSD: ffs_vnops.c,v 1.125 2014/07/25 08:20:53 dholland Exp $ */
4 * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Wasabi Systems, Inc, and by Andrew Doran.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
33 * Copyright (c) 1982, 1986, 1989, 1993
34 * The Regents of the University of California. All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: ffs_vnops.c,v 1.125 2014/07/25 08:20:53 dholland Exp $");
66 #if defined(_KERNEL_OPT)
68 #include "opt_wapbl.h"
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/resourcevar.h>
74 #include <sys/kernel.h>
78 #include <sys/event.h>
80 #include <sys/mount.h>
81 #include <sys/vnode.h>
83 #include <sys/signalvar.h>
84 #include <sys/kauth.h>
85 #include <sys/wapbl.h>
86 #include <sys/fstrans.h>
88 #include <miscfs/fifofs/fifo.h>
89 #include <miscfs/genfs/genfs.h>
90 #include <miscfs/specfs/specdev.h>
92 #include <ufs/ufs/inode.h>
93 #include <ufs/ufs/dir.h>
94 #include <ufs/ufs/ufs_extern.h>
95 #include <ufs/ufs/ufsmount.h>
96 #include <ufs/ufs/ufs_wapbl.h>
98 #include <ufs/ffs/fs.h>
99 #include <ufs/ffs/ffs_extern.h>
103 /* Global vfs data structures for ufs. */
104 int (**ffs_vnodeop_p
)(void *);
105 const struct vnodeopv_entry_desc ffs_vnodeop_entries
[] = {
106 { &vop_default_desc
, vn_default_error
},
107 { &vop_lookup_desc
, ufs_lookup
}, /* lookup */
108 { &vop_create_desc
, ufs_create
}, /* create */
109 { &vop_whiteout_desc
, ufs_whiteout
}, /* whiteout */
110 { &vop_mknod_desc
, ufs_mknod
}, /* mknod */
111 { &vop_open_desc
, ufs_open
}, /* open */
112 { &vop_close_desc
, ufs_close
}, /* close */
113 { &vop_access_desc
, ufs_access
}, /* access */
114 { &vop_getattr_desc
, ufs_getattr
}, /* getattr */
115 { &vop_setattr_desc
, ufs_setattr
}, /* setattr */
116 { &vop_read_desc
, ffs_read
}, /* read */
117 { &vop_write_desc
, ffs_write
}, /* write */
118 { &vop_fallocate_desc
, genfs_eopnotsupp
}, /* fallocate */
119 { &vop_fdiscard_desc
, genfs_eopnotsupp
}, /* fdiscard */
120 { &vop_ioctl_desc
, ufs_ioctl
}, /* ioctl */
121 { &vop_fcntl_desc
, ufs_fcntl
}, /* fcntl */
122 { &vop_poll_desc
, ufs_poll
}, /* poll */
123 { &vop_kqfilter_desc
, genfs_kqfilter
}, /* kqfilter */
124 { &vop_revoke_desc
, ufs_revoke
}, /* revoke */
125 { &vop_mmap_desc
, ufs_mmap
}, /* mmap */
126 { &vop_fsync_desc
, ffs_fsync
}, /* fsync */
127 { &vop_seek_desc
, ufs_seek
}, /* seek */
128 { &vop_remove_desc
, ufs_remove
}, /* remove */
129 { &vop_link_desc
, ufs_link
}, /* link */
130 { &vop_rename_desc
, ufs_rename
}, /* rename */
131 { &vop_mkdir_desc
, ufs_mkdir
}, /* mkdir */
132 { &vop_rmdir_desc
, ufs_rmdir
}, /* rmdir */
133 { &vop_symlink_desc
, ufs_symlink
}, /* symlink */
134 { &vop_readdir_desc
, ufs_readdir
}, /* readdir */
135 { &vop_readlink_desc
, ufs_readlink
}, /* readlink */
136 { &vop_abortop_desc
, ufs_abortop
}, /* abortop */
137 { &vop_inactive_desc
, ufs_inactive
}, /* inactive */
138 { &vop_reclaim_desc
, ffs_reclaim
}, /* reclaim */
139 { &vop_lock_desc
, ufs_lock
}, /* lock */
140 { &vop_unlock_desc
, ufs_unlock
}, /* unlock */
141 { &vop_bmap_desc
, ufs_bmap
}, /* bmap */
142 { &vop_strategy_desc
, ufs_strategy
}, /* strategy */
143 { &vop_print_desc
, ufs_print
}, /* print */
144 { &vop_islocked_desc
, ufs_islocked
}, /* islocked */
145 { &vop_pathconf_desc
, ufs_pathconf
}, /* pathconf */
146 { &vop_advlock_desc
, ufs_advlock
}, /* advlock */
147 { &vop_bwrite_desc
, vn_bwrite
}, /* bwrite */
148 { &vop_getpages_desc
, genfs_getpages
}, /* getpages */
149 { &vop_putpages_desc
, genfs_putpages
}, /* putpages */
150 { &vop_openextattr_desc
, ffs_openextattr
}, /* openextattr */
151 { &vop_closeextattr_desc
, ffs_closeextattr
}, /* closeextattr */
152 { &vop_getextattr_desc
, ffs_getextattr
}, /* getextattr */
153 { &vop_setextattr_desc
, ffs_setextattr
}, /* setextattr */
154 { &vop_listextattr_desc
, ffs_listextattr
}, /* listextattr */
155 { &vop_deleteextattr_desc
, ffs_deleteextattr
}, /* deleteextattr */
158 const struct vnodeopv_desc ffs_vnodeop_opv_desc
=
159 { &ffs_vnodeop_p
, ffs_vnodeop_entries
};
161 int (**ffs_specop_p
)(void *);
162 const struct vnodeopv_entry_desc ffs_specop_entries
[] = {
163 { &vop_default_desc
, vn_default_error
},
164 { &vop_lookup_desc
, spec_lookup
}, /* lookup */
165 { &vop_create_desc
, spec_create
}, /* create */
166 { &vop_mknod_desc
, spec_mknod
}, /* mknod */
167 { &vop_open_desc
, spec_open
}, /* open */
168 { &vop_close_desc
, ufsspec_close
}, /* close */
169 { &vop_access_desc
, ufs_access
}, /* access */
170 { &vop_getattr_desc
, ufs_getattr
}, /* getattr */
171 { &vop_setattr_desc
, ufs_setattr
}, /* setattr */
172 { &vop_read_desc
, ufsspec_read
}, /* read */
173 { &vop_write_desc
, ufsspec_write
}, /* write */
174 { &vop_fallocate_desc
, spec_fallocate
}, /* fallocate */
175 { &vop_fdiscard_desc
, spec_fdiscard
}, /* fdiscard */
176 { &vop_ioctl_desc
, spec_ioctl
}, /* ioctl */
177 { &vop_fcntl_desc
, ufs_fcntl
}, /* fcntl */
178 { &vop_poll_desc
, spec_poll
}, /* poll */
179 { &vop_kqfilter_desc
, spec_kqfilter
}, /* kqfilter */
180 { &vop_revoke_desc
, spec_revoke
}, /* revoke */
181 { &vop_mmap_desc
, spec_mmap
}, /* mmap */
182 { &vop_fsync_desc
, ffs_spec_fsync
}, /* fsync */
183 { &vop_seek_desc
, spec_seek
}, /* seek */
184 { &vop_remove_desc
, spec_remove
}, /* remove */
185 { &vop_link_desc
, spec_link
}, /* link */
186 { &vop_rename_desc
, spec_rename
}, /* rename */
187 { &vop_mkdir_desc
, spec_mkdir
}, /* mkdir */
188 { &vop_rmdir_desc
, spec_rmdir
}, /* rmdir */
189 { &vop_symlink_desc
, spec_symlink
}, /* symlink */
190 { &vop_readdir_desc
, spec_readdir
}, /* readdir */
191 { &vop_readlink_desc
, spec_readlink
}, /* readlink */
192 { &vop_abortop_desc
, spec_abortop
}, /* abortop */
193 { &vop_inactive_desc
, ufs_inactive
}, /* inactive */
194 { &vop_reclaim_desc
, ffs_reclaim
}, /* reclaim */
195 { &vop_lock_desc
, ufs_lock
}, /* lock */
196 { &vop_unlock_desc
, ufs_unlock
}, /* unlock */
197 { &vop_bmap_desc
, spec_bmap
}, /* bmap */
198 { &vop_strategy_desc
, spec_strategy
}, /* strategy */
199 { &vop_print_desc
, ufs_print
}, /* print */
200 { &vop_islocked_desc
, ufs_islocked
}, /* islocked */
201 { &vop_pathconf_desc
, spec_pathconf
}, /* pathconf */
202 { &vop_advlock_desc
, spec_advlock
}, /* advlock */
203 { &vop_bwrite_desc
, vn_bwrite
}, /* bwrite */
204 { &vop_getpages_desc
, spec_getpages
}, /* getpages */
205 { &vop_putpages_desc
, spec_putpages
}, /* putpages */
206 { &vop_openextattr_desc
, ffs_openextattr
}, /* openextattr */
207 { &vop_closeextattr_desc
, ffs_closeextattr
}, /* closeextattr */
208 { &vop_getextattr_desc
, ffs_getextattr
}, /* getextattr */
209 { &vop_setextattr_desc
, ffs_setextattr
}, /* setextattr */
210 { &vop_listextattr_desc
, ffs_listextattr
}, /* listextattr */
211 { &vop_deleteextattr_desc
, ffs_deleteextattr
}, /* deleteextattr */
214 const struct vnodeopv_desc ffs_specop_opv_desc
=
215 { &ffs_specop_p
, ffs_specop_entries
};
217 int (**ffs_fifoop_p
)(void *);
218 const struct vnodeopv_entry_desc ffs_fifoop_entries
[] = {
219 { &vop_default_desc
, vn_default_error
},
220 { &vop_lookup_desc
, vn_fifo_bypass
}, /* lookup */
221 { &vop_create_desc
, vn_fifo_bypass
}, /* create */
222 { &vop_mknod_desc
, vn_fifo_bypass
}, /* mknod */
223 { &vop_open_desc
, vn_fifo_bypass
}, /* open */
224 { &vop_close_desc
, ufsfifo_close
}, /* close */
225 { &vop_access_desc
, ufs_access
}, /* access */
226 { &vop_getattr_desc
, ufs_getattr
}, /* getattr */
227 { &vop_setattr_desc
, ufs_setattr
}, /* setattr */
228 { &vop_read_desc
, ufsfifo_read
}, /* read */
229 { &vop_write_desc
, ufsfifo_write
}, /* write */
230 { &vop_fallocate_desc
, vn_fifo_bypass
}, /* fallocate */
231 { &vop_fdiscard_desc
, vn_fifo_bypass
}, /* fdiscard */
232 { &vop_ioctl_desc
, vn_fifo_bypass
}, /* ioctl */
233 { &vop_fcntl_desc
, ufs_fcntl
}, /* fcntl */
234 { &vop_poll_desc
, vn_fifo_bypass
}, /* poll */
235 { &vop_kqfilter_desc
, vn_fifo_bypass
}, /* kqfilter */
236 { &vop_revoke_desc
, vn_fifo_bypass
}, /* revoke */
237 { &vop_mmap_desc
, vn_fifo_bypass
}, /* mmap */
238 { &vop_fsync_desc
, ffs_fsync
}, /* fsync */
239 { &vop_seek_desc
, vn_fifo_bypass
}, /* seek */
240 { &vop_remove_desc
, vn_fifo_bypass
}, /* remove */
241 { &vop_link_desc
, vn_fifo_bypass
}, /* link */
242 { &vop_rename_desc
, vn_fifo_bypass
}, /* rename */
243 { &vop_mkdir_desc
, vn_fifo_bypass
}, /* mkdir */
244 { &vop_rmdir_desc
, vn_fifo_bypass
}, /* rmdir */
245 { &vop_symlink_desc
, vn_fifo_bypass
}, /* symlink */
246 { &vop_readdir_desc
, vn_fifo_bypass
}, /* readdir */
247 { &vop_readlink_desc
, vn_fifo_bypass
}, /* readlink */
248 { &vop_abortop_desc
, vn_fifo_bypass
}, /* abortop */
249 { &vop_inactive_desc
, ufs_inactive
}, /* inactive */
250 { &vop_reclaim_desc
, ffs_reclaim
}, /* reclaim */
251 { &vop_lock_desc
, ufs_lock
}, /* lock */
252 { &vop_unlock_desc
, ufs_unlock
}, /* unlock */
253 { &vop_bmap_desc
, vn_fifo_bypass
}, /* bmap */
254 { &vop_strategy_desc
, vn_fifo_bypass
}, /* strategy */
255 { &vop_print_desc
, ufs_print
}, /* print */
256 { &vop_islocked_desc
, ufs_islocked
}, /* islocked */
257 { &vop_pathconf_desc
, vn_fifo_bypass
}, /* pathconf */
258 { &vop_advlock_desc
, vn_fifo_bypass
}, /* advlock */
259 { &vop_bwrite_desc
, vn_bwrite
}, /* bwrite */
260 { &vop_putpages_desc
, vn_fifo_bypass
}, /* putpages */
261 { &vop_openextattr_desc
, ffs_openextattr
}, /* openextattr */
262 { &vop_closeextattr_desc
, ffs_closeextattr
}, /* closeextattr */
263 { &vop_getextattr_desc
, ffs_getextattr
}, /* getextattr */
264 { &vop_setextattr_desc
, ffs_setextattr
}, /* setextattr */
265 { &vop_listextattr_desc
, ffs_listextattr
}, /* listextattr */
266 { &vop_deleteextattr_desc
, ffs_deleteextattr
}, /* deleteextattr */
269 const struct vnodeopv_desc ffs_fifoop_opv_desc
=
270 { &ffs_fifoop_p
, ffs_fifoop_entries
};
272 #include <ufs/ufs/ufs_readwrite.c>
275 ffs_spec_fsync(void *v
)
277 struct vop_fsync_args
/* {
285 int error
, flags
, uflags
;
290 uflags
= UPDATE_CLOSE
| ((flags
& FSYNC_WAIT
) ? UPDATE_WAIT
: 0);
294 fstrans_start(mp
, FSTRANS_LAZY
);
296 error
= spec_fsync(v
);
301 if (mp
&& mp
->mnt_wapbl
) {
303 * Don't bother writing out metadata if the syncer is
304 * making the request. We will let the sync vnode
305 * write it out in a single burst through a call to
308 if ((flags
& (FSYNC_DATAONLY
| FSYNC_LAZY
)) != 0)
310 if ((VTOI(vp
)->i_flag
& (IN_ACCESS
| IN_CHANGE
| IN_UPDATE
311 | IN_MODIFY
| IN_MODIFIED
| IN_ACCESSED
)) != 0) {
312 error
= UFS_WAPBL_BEGIN(mp
);
315 error
= ffs_update(vp
, NULL
, NULL
, uflags
);
322 error
= ffs_update(vp
, NULL
, NULL
, uflags
);
332 struct vop_fsync_args
/* {
342 struct indir ia
[UFS_NIADDR
+ 1];
351 fstrans_start(mp
, FSTRANS_LAZY
);
352 if ((ap
->a_offlo
== 0 && ap
->a_offhi
== 0) || (vp
->v_type
!= VREG
)) {
353 error
= ffs_full_fsync(vp
, ap
->a_flags
);
357 bsize
= mp
->mnt_stat
.f_iosize
;
358 blk_high
= ap
->a_offhi
/ bsize
;
359 if (ap
->a_offhi
% bsize
!= 0)
363 * First, flush all pages in range.
366 mutex_enter(vp
->v_interlock
);
367 error
= VOP_PUTPAGES(vp
, trunc_page(ap
->a_offlo
),
368 round_page(ap
->a_offhi
), PGO_CLEANIT
|
369 ((ap
->a_flags
& FSYNC_WAIT
) ? PGO_SYNCIO
: 0));
375 KASSERT(vp
->v_type
== VREG
);
378 * Don't bother writing out metadata if the syncer is
379 * making the request. We will let the sync vnode
380 * write it out in a single burst through a call to
383 if ((ap
->a_flags
& (FSYNC_DATAONLY
| FSYNC_LAZY
)) != 0) {
388 if (vp
->v_tag
== VT_UFS
&& VTOI(vp
)->i_flag
&
389 (IN_ACCESS
| IN_CHANGE
| IN_UPDATE
| IN_MODIFY
|
390 IN_MODIFIED
| IN_ACCESSED
)) {
391 error
= UFS_WAPBL_BEGIN(mp
);
396 error
= ffs_update(vp
, NULL
, NULL
, UPDATE_CLOSE
|
397 ((ap
->a_flags
& FSYNC_WAIT
) ? UPDATE_WAIT
: 0));
400 if (error
|| (ap
->a_flags
& FSYNC_NOLOG
) != 0) {
404 error
= wapbl_flush(mp
->mnt_wapbl
, 0);
411 * Then, flush indirect blocks.
414 if (blk_high
>= UFS_NDADDR
) {
415 error
= ufs_getlbns(vp
, blk_high
, ia
, &num
);
419 mutex_enter(&bufcache_lock
);
420 for (i
= 0; i
< num
; i
++) {
421 if ((bp
= incore(vp
, ia
[i
].in_lbn
)) == NULL
)
423 if ((bp
->b_cflags
& BC_BUSY
) != 0 ||
424 (bp
->b_oflags
& BO_DELWRI
) == 0)
426 bp
->b_cflags
|= BC_BUSY
| BC_VFLUSH
;
427 mutex_exit(&bufcache_lock
);
429 mutex_enter(&bufcache_lock
);
431 mutex_exit(&bufcache_lock
);
434 if (ap
->a_flags
& FSYNC_WAIT
) {
435 mutex_enter(vp
->v_interlock
);
436 while (vp
->v_numoutput
> 0)
437 cv_wait(&vp
->v_cv
, vp
->v_interlock
);
438 mutex_exit(vp
->v_interlock
);
441 error
= ffs_update(vp
, NULL
, NULL
, UPDATE_CLOSE
|
442 (((ap
->a_flags
& (FSYNC_WAIT
| FSYNC_DATAONLY
)) == FSYNC_WAIT
)
445 if (error
== 0 && ap
->a_flags
& FSYNC_CACHE
) {
447 VOP_IOCTL(VTOI(vp
)->i_devvp
, DIOCCACHESYNC
, &l
, FWRITE
,
457 * Synch an open file. Called for VOP_FSYNC().
461 ffs_full_fsync(struct vnode
*vp
, int flags
)
463 int error
, i
, uflags
;
465 KASSERT(vp
->v_tag
== VT_UFS
);
466 KASSERT(VTOI(vp
) != NULL
);
467 KASSERT(vp
->v_type
!= VCHR
&& vp
->v_type
!= VBLK
);
469 uflags
= UPDATE_CLOSE
| ((flags
& FSYNC_WAIT
) ? UPDATE_WAIT
: 0);
472 struct mount
*mp
= vp
->v_mount
;
473 if (mp
&& mp
->mnt_wapbl
) {
476 * Flush all dirty data associated with the vnode.
478 if (vp
->v_type
== VREG
) {
479 int pflags
= PGO_ALLPAGES
| PGO_CLEANIT
;
481 if ((flags
& FSYNC_LAZY
))
483 if ((flags
& FSYNC_WAIT
))
484 pflags
|= PGO_SYNCIO
;
485 if (fstrans_getstate(mp
) == FSTRANS_SUSPENDING
)
487 mutex_enter(vp
->v_interlock
);
488 error
= VOP_PUTPAGES(vp
, 0, 0, pflags
);
494 * Don't bother writing out metadata if the syncer is
495 * making the request. We will let the sync vnode
496 * write it out in a single burst through a call to
499 if ((flags
& (FSYNC_DATAONLY
| FSYNC_LAZY
)) != 0)
502 if ((VTOI(vp
)->i_flag
& (IN_ACCESS
| IN_CHANGE
| IN_UPDATE
503 | IN_MODIFY
| IN_MODIFIED
| IN_ACCESSED
)) != 0) {
504 error
= UFS_WAPBL_BEGIN(mp
);
507 error
= ffs_update(vp
, NULL
, NULL
, uflags
);
512 if (error
|| (flags
& FSYNC_NOLOG
) != 0)
516 * Don't flush the log if the vnode being flushed
517 * contains no dirty buffers that could be in the log.
519 if (!LIST_EMPTY(&vp
->v_dirtyblkhd
)) {
520 error
= wapbl_flush(mp
->mnt_wapbl
, 0);
525 if ((flags
& FSYNC_WAIT
) != 0) {
526 mutex_enter(vp
->v_interlock
);
527 while (vp
->v_numoutput
!= 0)
528 cv_wait(&vp
->v_cv
, vp
->v_interlock
);
529 mutex_exit(vp
->v_interlock
);
536 error
= vflushbuf(vp
, flags
);
538 error
= ffs_update(vp
, NULL
, NULL
, uflags
);
539 if (error
== 0 && (flags
& FSYNC_CACHE
) != 0) {
541 (void)VOP_IOCTL(VTOI(vp
)->i_devvp
, DIOCCACHESYNC
, &i
, FWRITE
,
549 * Reclaim an inode so that it can be used for other purposes.
554 struct vop_reclaim_args
/* {
558 struct vnode
*vp
= ap
->a_vp
;
559 struct inode
*ip
= VTOI(vp
);
560 struct mount
*mp
= vp
->v_mount
;
561 struct ufsmount
*ump
= ip
->i_ump
;
565 fstrans_start(mp
, FSTRANS_LAZY
);
567 * The inode must be freed and updated before being removed
568 * from its hash chain. Other threads trying to gain a hold
569 * or lock on the inode will be stalled.
571 error
= UFS_WAPBL_BEGIN(mp
);
576 if (ip
->i_nlink
<= 0 && ip
->i_omode
!= 0 &&
577 (vp
->v_mount
->mnt_flag
& MNT_RDONLY
) == 0)
578 ffs_vfree(vp
, ip
->i_number
, ip
->i_omode
);
580 if ((error
= ufs_reclaim(vp
)) != 0) {
584 if (ip
->i_din
.ffs1_din
!= NULL
) {
585 if (ump
->um_fstype
== UFS1
)
586 pool_cache_put(ffs_dinode1_cache
, ip
->i_din
.ffs1_din
);
588 pool_cache_put(ffs_dinode2_cache
, ip
->i_din
.ffs2_din
);
591 * To interlock with ffs_sync().
593 genfs_node_destroy(vp
);
594 mutex_enter(vp
->v_interlock
);
597 mutex_exit(vp
->v_interlock
);
600 * XXX MFS ends up here, too, to free an inode. Should we create
601 * XXX a separate pool for MFS inodes?
603 pool_cache_put(ffs_inode_cache
, data
);
609 * Return the last logical file offset that should be written for this file
610 * if we're doing a write that ends at "size".
614 ffs_gop_size(struct vnode
*vp
, off_t size
, off_t
*eobp
, int flags
)
616 struct inode
*ip
= VTOI(vp
);
617 struct fs
*fs
= ip
->i_fs
;
620 olbn
= ffs_lblkno(fs
, ip
->i_size
);
621 nlbn
= ffs_lblkno(fs
, size
);
622 if (nlbn
< UFS_NDADDR
&& olbn
<= nlbn
) {
623 *eobp
= ffs_fragroundup(fs
, size
);
625 *eobp
= ffs_blkroundup(fs
, size
);
630 ffs_openextattr(void *v
)
632 struct vop_openextattr_args
/* {
637 struct inode
*ip
= VTOI(ap
->a_vp
);
638 struct fs
*fs
= ip
->i_fs
;
640 /* Not supported for UFS1 file systems. */
641 if (fs
->fs_magic
== FS_UFS1_MAGIC
)
644 /* XXX Not implemented for UFS2 file systems. */
649 ffs_closeextattr(void *v
)
651 struct vop_closeextattr_args
/* {
657 struct inode
*ip
= VTOI(ap
->a_vp
);
658 struct fs
*fs
= ip
->i_fs
;
660 /* Not supported for UFS1 file systems. */
661 if (fs
->fs_magic
== FS_UFS1_MAGIC
)
664 /* XXX Not implemented for UFS2 file systems. */
669 ffs_getextattr(void *v
)
671 struct vop_getextattr_args
/* {
680 struct vnode
*vp
= ap
->a_vp
;
681 struct inode
*ip
= VTOI(vp
);
682 struct fs
*fs
= ip
->i_fs
;
684 if (fs
->fs_magic
== FS_UFS1_MAGIC
) {
688 fstrans_start(vp
->v_mount
, FSTRANS_SHARED
);
689 error
= ufs_getextattr(ap
);
690 fstrans_done(vp
->v_mount
);
697 /* XXX Not implemented for UFS2 file systems. */
702 ffs_setextattr(void *v
)
704 struct vop_setextattr_args
/* {
712 struct vnode
*vp
= ap
->a_vp
;
713 struct inode
*ip
= VTOI(vp
);
714 struct fs
*fs
= ip
->i_fs
;
716 if (fs
->fs_magic
== FS_UFS1_MAGIC
) {
720 fstrans_start(vp
->v_mount
, FSTRANS_SHARED
);
721 error
= ufs_setextattr(ap
);
722 fstrans_done(vp
->v_mount
);
729 /* XXX Not implemented for UFS2 file systems. */
734 ffs_listextattr(void *v
)
736 struct vop_listextattr_args
/* {
744 struct inode
*ip
= VTOI(ap
->a_vp
);
745 struct fs
*fs
= ip
->i_fs
;
747 if (fs
->fs_magic
== FS_UFS1_MAGIC
) {
749 struct vnode
*vp
= ap
->a_vp
;
752 fstrans_start(vp
->v_mount
, FSTRANS_SHARED
);
753 error
= ufs_listextattr(ap
);
754 fstrans_done(vp
->v_mount
);
761 /* XXX Not implemented for UFS2 file systems. */
766 ffs_deleteextattr(void *v
)
768 struct vop_deleteextattr_args
/* {
774 struct vnode
*vp
= ap
->a_vp
;
775 struct inode
*ip
= VTOI(vp
);
776 struct fs
*fs
= ip
->i_fs
;
778 if (fs
->fs_magic
== FS_UFS1_MAGIC
) {
782 fstrans_start(vp
->v_mount
, FSTRANS_SHARED
);
783 error
= ufs_deleteextattr(ap
);
784 fstrans_done(vp
->v_mount
);
791 /* XXX Not implemented for UFS2 file systems. */