ffs_vnops.c revision 1.16.2.3 1 1.16.2.3 chs /* $NetBSD: ffs_vnops.c,v 1.16.2.3 1999/02/25 03:58:29 chs Exp $ */
2 1.3 cgd
3 1.1 mycroft /*
4 1.1 mycroft * Copyright (c) 1982, 1986, 1989, 1993
5 1.1 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 mycroft *
7 1.1 mycroft * Redistribution and use in source and binary forms, with or without
8 1.1 mycroft * modification, are permitted provided that the following conditions
9 1.1 mycroft * are met:
10 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
11 1.1 mycroft * notice, this list of conditions and the following disclaimer.
12 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
14 1.1 mycroft * documentation and/or other materials provided with the distribution.
15 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
16 1.1 mycroft * must display the following acknowledgement:
17 1.1 mycroft * This product includes software developed by the University of
18 1.1 mycroft * California, Berkeley and its contributors.
19 1.1 mycroft * 4. Neither the name of the University nor the names of its contributors
20 1.1 mycroft * may be used to endorse or promote products derived from this software
21 1.1 mycroft * without specific prior written permission.
22 1.1 mycroft *
23 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 mycroft * SUCH DAMAGE.
34 1.1 mycroft *
35 1.12 fvdl * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
36 1.1 mycroft */
37 1.11 mrg
38 1.13 scottr #if defined(_KERNEL) && !defined(_LKM)
39 1.11 mrg #include "opt_uvm.h"
40 1.16.2.3 chs #include "opt_uvmhist.h"
41 1.13 scottr #endif
42 1.1 mycroft
43 1.1 mycroft #include <sys/param.h>
44 1.1 mycroft #include <sys/systm.h>
45 1.1 mycroft #include <sys/resourcevar.h>
46 1.1 mycroft #include <sys/kernel.h>
47 1.1 mycroft #include <sys/file.h>
48 1.1 mycroft #include <sys/stat.h>
49 1.1 mycroft #include <sys/buf.h>
50 1.1 mycroft #include <sys/proc.h>
51 1.1 mycroft #include <sys/conf.h>
52 1.1 mycroft #include <sys/mount.h>
53 1.1 mycroft #include <sys/vnode.h>
54 1.1 mycroft #include <sys/malloc.h>
55 1.16 thorpej #include <sys/pool.h>
56 1.6 christos #include <sys/signalvar.h>
57 1.1 mycroft
58 1.1 mycroft #include <vm/vm.h>
59 1.10 mrg
60 1.10 mrg #if defined(UVM)
61 1.10 mrg #include <uvm/uvm_extern.h>
62 1.10 mrg #endif
63 1.1 mycroft
64 1.8 mycroft #include <miscfs/fifofs/fifo.h>
65 1.8 mycroft #include <miscfs/genfs/genfs.h>
66 1.1 mycroft #include <miscfs/specfs/specdev.h>
67 1.1 mycroft
68 1.1 mycroft #include <ufs/ufs/quota.h>
69 1.1 mycroft #include <ufs/ufs/inode.h>
70 1.1 mycroft #include <ufs/ufs/dir.h>
71 1.1 mycroft #include <ufs/ufs/ufs_extern.h>
72 1.2 mycroft #include <ufs/ufs/ufsmount.h>
73 1.1 mycroft
74 1.1 mycroft #include <ufs/ffs/fs.h>
75 1.1 mycroft #include <ufs/ffs/ffs_extern.h>
76 1.1 mycroft
77 1.1 mycroft /* Global vfs data structures for ufs. */
78 1.6 christos int (**ffs_vnodeop_p) __P((void *));
79 1.1 mycroft struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
80 1.1 mycroft { &vop_default_desc, vn_default_error },
81 1.1 mycroft { &vop_lookup_desc, ufs_lookup }, /* lookup */
82 1.1 mycroft { &vop_create_desc, ufs_create }, /* create */
83 1.5 mycroft { &vop_whiteout_desc, ufs_whiteout }, /* whiteout */
84 1.1 mycroft { &vop_mknod_desc, ufs_mknod }, /* mknod */
85 1.1 mycroft { &vop_open_desc, ufs_open }, /* open */
86 1.1 mycroft { &vop_close_desc, ufs_close }, /* close */
87 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
88 1.1 mycroft { &vop_getattr_desc, ufs_getattr }, /* getattr */
89 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
90 1.1 mycroft { &vop_read_desc, ffs_read }, /* read */
91 1.1 mycroft { &vop_write_desc, ffs_write }, /* write */
92 1.4 mycroft { &vop_lease_desc, ufs_lease_check }, /* lease */
93 1.1 mycroft { &vop_ioctl_desc, ufs_ioctl }, /* ioctl */
94 1.9 mycroft { &vop_poll_desc, ufs_poll }, /* poll */
95 1.12 fvdl { &vop_revoke_desc, ufs_revoke }, /* revoke */
96 1.1 mycroft { &vop_mmap_desc, ufs_mmap }, /* mmap */
97 1.1 mycroft { &vop_fsync_desc, ffs_fsync }, /* fsync */
98 1.1 mycroft { &vop_seek_desc, ufs_seek }, /* seek */
99 1.1 mycroft { &vop_remove_desc, ufs_remove }, /* remove */
100 1.1 mycroft { &vop_link_desc, ufs_link }, /* link */
101 1.1 mycroft { &vop_rename_desc, ufs_rename }, /* rename */
102 1.1 mycroft { &vop_mkdir_desc, ufs_mkdir }, /* mkdir */
103 1.1 mycroft { &vop_rmdir_desc, ufs_rmdir }, /* rmdir */
104 1.1 mycroft { &vop_symlink_desc, ufs_symlink }, /* symlink */
105 1.1 mycroft { &vop_readdir_desc, ufs_readdir }, /* readdir */
106 1.1 mycroft { &vop_readlink_desc, ufs_readlink }, /* readlink */
107 1.1 mycroft { &vop_abortop_desc, ufs_abortop }, /* abortop */
108 1.1 mycroft { &vop_inactive_desc, ufs_inactive }, /* inactive */
109 1.1 mycroft { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
110 1.1 mycroft { &vop_lock_desc, ufs_lock }, /* lock */
111 1.1 mycroft { &vop_unlock_desc, ufs_unlock }, /* unlock */
112 1.1 mycroft { &vop_bmap_desc, ufs_bmap }, /* bmap */
113 1.1 mycroft { &vop_strategy_desc, ufs_strategy }, /* strategy */
114 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
115 1.1 mycroft { &vop_islocked_desc, ufs_islocked }, /* islocked */
116 1.1 mycroft { &vop_pathconf_desc, ufs_pathconf }, /* pathconf */
117 1.1 mycroft { &vop_advlock_desc, ufs_advlock }, /* advlock */
118 1.1 mycroft { &vop_blkatoff_desc, ffs_blkatoff }, /* blkatoff */
119 1.1 mycroft { &vop_valloc_desc, ffs_valloc }, /* valloc */
120 1.1 mycroft { &vop_reallocblks_desc, ffs_reallocblks }, /* reallocblks */
121 1.1 mycroft { &vop_vfree_desc, ffs_vfree }, /* vfree */
122 1.1 mycroft { &vop_truncate_desc, ffs_truncate }, /* truncate */
123 1.1 mycroft { &vop_update_desc, ffs_update }, /* update */
124 1.8 mycroft { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
125 1.16.2.1 chs #ifdef UBC
126 1.16.2.1 chs { &vop_getpages_desc, ffs_getpages }, /* getpages */
127 1.16.2.1 chs { &vop_putpages_desc, ffs_putpages }, /* putpages */
128 1.16.2.1 chs #endif
129 1.16.2.1 chs { NULL, NULL }
130 1.1 mycroft };
131 1.1 mycroft struct vnodeopv_desc ffs_vnodeop_opv_desc =
132 1.1 mycroft { &ffs_vnodeop_p, ffs_vnodeop_entries };
133 1.1 mycroft
134 1.6 christos int (**ffs_specop_p) __P((void *));
135 1.1 mycroft struct vnodeopv_entry_desc ffs_specop_entries[] = {
136 1.1 mycroft { &vop_default_desc, vn_default_error },
137 1.1 mycroft { &vop_lookup_desc, spec_lookup }, /* lookup */
138 1.1 mycroft { &vop_create_desc, spec_create }, /* create */
139 1.1 mycroft { &vop_mknod_desc, spec_mknod }, /* mknod */
140 1.1 mycroft { &vop_open_desc, spec_open }, /* open */
141 1.1 mycroft { &vop_close_desc, ufsspec_close }, /* close */
142 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
143 1.1 mycroft { &vop_getattr_desc, ufs_getattr }, /* getattr */
144 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
145 1.1 mycroft { &vop_read_desc, ufsspec_read }, /* read */
146 1.1 mycroft { &vop_write_desc, ufsspec_write }, /* write */
147 1.4 mycroft { &vop_lease_desc, spec_lease_check }, /* lease */
148 1.1 mycroft { &vop_ioctl_desc, spec_ioctl }, /* ioctl */
149 1.9 mycroft { &vop_poll_desc, spec_poll }, /* poll */
150 1.12 fvdl { &vop_revoke_desc, spec_revoke }, /* revoke */
151 1.1 mycroft { &vop_mmap_desc, spec_mmap }, /* mmap */
152 1.1 mycroft { &vop_fsync_desc, ffs_fsync }, /* fsync */
153 1.1 mycroft { &vop_seek_desc, spec_seek }, /* seek */
154 1.1 mycroft { &vop_remove_desc, spec_remove }, /* remove */
155 1.1 mycroft { &vop_link_desc, spec_link }, /* link */
156 1.1 mycroft { &vop_rename_desc, spec_rename }, /* rename */
157 1.1 mycroft { &vop_mkdir_desc, spec_mkdir }, /* mkdir */
158 1.1 mycroft { &vop_rmdir_desc, spec_rmdir }, /* rmdir */
159 1.1 mycroft { &vop_symlink_desc, spec_symlink }, /* symlink */
160 1.1 mycroft { &vop_readdir_desc, spec_readdir }, /* readdir */
161 1.1 mycroft { &vop_readlink_desc, spec_readlink }, /* readlink */
162 1.1 mycroft { &vop_abortop_desc, spec_abortop }, /* abortop */
163 1.1 mycroft { &vop_inactive_desc, ufs_inactive }, /* inactive */
164 1.1 mycroft { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
165 1.1 mycroft { &vop_lock_desc, ufs_lock }, /* lock */
166 1.1 mycroft { &vop_unlock_desc, ufs_unlock }, /* unlock */
167 1.1 mycroft { &vop_bmap_desc, spec_bmap }, /* bmap */
168 1.1 mycroft { &vop_strategy_desc, spec_strategy }, /* strategy */
169 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
170 1.1 mycroft { &vop_islocked_desc, ufs_islocked }, /* islocked */
171 1.1 mycroft { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
172 1.1 mycroft { &vop_advlock_desc, spec_advlock }, /* advlock */
173 1.1 mycroft { &vop_blkatoff_desc, spec_blkatoff }, /* blkatoff */
174 1.1 mycroft { &vop_valloc_desc, spec_valloc }, /* valloc */
175 1.1 mycroft { &vop_reallocblks_desc, spec_reallocblks }, /* reallocblks */
176 1.1 mycroft { &vop_vfree_desc, ffs_vfree }, /* vfree */
177 1.1 mycroft { &vop_truncate_desc, spec_truncate }, /* truncate */
178 1.1 mycroft { &vop_update_desc, ffs_update }, /* update */
179 1.8 mycroft { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
180 1.6 christos { (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
181 1.1 mycroft };
182 1.1 mycroft struct vnodeopv_desc ffs_specop_opv_desc =
183 1.1 mycroft { &ffs_specop_p, ffs_specop_entries };
184 1.1 mycroft
185 1.6 christos int (**ffs_fifoop_p) __P((void *));
186 1.1 mycroft struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
187 1.1 mycroft { &vop_default_desc, vn_default_error },
188 1.1 mycroft { &vop_lookup_desc, fifo_lookup }, /* lookup */
189 1.1 mycroft { &vop_create_desc, fifo_create }, /* create */
190 1.1 mycroft { &vop_mknod_desc, fifo_mknod }, /* mknod */
191 1.1 mycroft { &vop_open_desc, fifo_open }, /* open */
192 1.1 mycroft { &vop_close_desc, ufsfifo_close }, /* close */
193 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
194 1.1 mycroft { &vop_getattr_desc, ufs_getattr }, /* getattr */
195 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
196 1.1 mycroft { &vop_read_desc, ufsfifo_read }, /* read */
197 1.1 mycroft { &vop_write_desc, ufsfifo_write }, /* write */
198 1.4 mycroft { &vop_lease_desc, fifo_lease_check }, /* lease */
199 1.1 mycroft { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */
200 1.9 mycroft { &vop_poll_desc, fifo_poll }, /* poll */
201 1.12 fvdl { &vop_revoke_desc, fifo_revoke }, /* revoke */
202 1.1 mycroft { &vop_mmap_desc, fifo_mmap }, /* mmap */
203 1.1 mycroft { &vop_fsync_desc, ffs_fsync }, /* fsync */
204 1.1 mycroft { &vop_seek_desc, fifo_seek }, /* seek */
205 1.1 mycroft { &vop_remove_desc, fifo_remove }, /* remove */
206 1.1 mycroft { &vop_link_desc, fifo_link }, /* link */
207 1.1 mycroft { &vop_rename_desc, fifo_rename }, /* rename */
208 1.1 mycroft { &vop_mkdir_desc, fifo_mkdir }, /* mkdir */
209 1.1 mycroft { &vop_rmdir_desc, fifo_rmdir }, /* rmdir */
210 1.1 mycroft { &vop_symlink_desc, fifo_symlink }, /* symlink */
211 1.1 mycroft { &vop_readdir_desc, fifo_readdir }, /* readdir */
212 1.1 mycroft { &vop_readlink_desc, fifo_readlink }, /* readlink */
213 1.1 mycroft { &vop_abortop_desc, fifo_abortop }, /* abortop */
214 1.1 mycroft { &vop_inactive_desc, ufs_inactive }, /* inactive */
215 1.1 mycroft { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
216 1.1 mycroft { &vop_lock_desc, ufs_lock }, /* lock */
217 1.1 mycroft { &vop_unlock_desc, ufs_unlock }, /* unlock */
218 1.1 mycroft { &vop_bmap_desc, fifo_bmap }, /* bmap */
219 1.1 mycroft { &vop_strategy_desc, fifo_strategy }, /* strategy */
220 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
221 1.1 mycroft { &vop_islocked_desc, ufs_islocked }, /* islocked */
222 1.1 mycroft { &vop_pathconf_desc, fifo_pathconf }, /* pathconf */
223 1.1 mycroft { &vop_advlock_desc, fifo_advlock }, /* advlock */
224 1.1 mycroft { &vop_blkatoff_desc, fifo_blkatoff }, /* blkatoff */
225 1.1 mycroft { &vop_valloc_desc, fifo_valloc }, /* valloc */
226 1.1 mycroft { &vop_reallocblks_desc, fifo_reallocblks }, /* reallocblks */
227 1.1 mycroft { &vop_vfree_desc, ffs_vfree }, /* vfree */
228 1.1 mycroft { &vop_truncate_desc, fifo_truncate }, /* truncate */
229 1.1 mycroft { &vop_update_desc, ffs_update }, /* update */
230 1.8 mycroft { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
231 1.6 christos { (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
232 1.1 mycroft };
233 1.1 mycroft struct vnodeopv_desc ffs_fifoop_opv_desc =
234 1.1 mycroft { &ffs_fifoop_p, ffs_fifoop_entries };
235 1.1 mycroft
236 1.1 mycroft int doclusterread = 1;
237 1.1 mycroft int doclusterwrite = 1;
238 1.1 mycroft
239 1.1 mycroft #include <ufs/ufs/ufs_readwrite.c>
240 1.1 mycroft
241 1.1 mycroft /*
242 1.1 mycroft * Reclaim an inode so that it can be used for other purposes.
243 1.1 mycroft */
244 1.1 mycroft int
245 1.6 christos ffs_reclaim(v)
246 1.6 christos void *v;
247 1.6 christos {
248 1.1 mycroft struct vop_reclaim_args /* {
249 1.1 mycroft struct vnode *a_vp;
250 1.12 fvdl struct proc *a_p;
251 1.6 christos } */ *ap = v;
252 1.1 mycroft register struct vnode *vp = ap->a_vp;
253 1.1 mycroft int error;
254 1.1 mycroft
255 1.12 fvdl if ((error = ufs_reclaim(vp, ap->a_p)) != 0)
256 1.1 mycroft return (error);
257 1.16.2.1 chs
258 1.16 thorpej /*
259 1.16 thorpej * XXX MFS ends up here, too, to free an inode. Should we create
260 1.16 thorpej * XXX a separate pool for MFS inodes?
261 1.16 thorpej */
262 1.16 thorpej pool_put(&ffs_inode_pool, vp->v_data);
263 1.1 mycroft vp->v_data = NULL;
264 1.1 mycroft return (0);
265 1.1 mycroft }
266 1.16.2.1 chs
267 1.16.2.1 chs #ifdef UBC
268 1.16.2.1 chs #include <uvm/uvm.h>
269 1.16.2.1 chs
270 1.16.2.1 chs int
271 1.16.2.1 chs ffs_getpages(v)
272 1.16.2.1 chs void *v;
273 1.16.2.1 chs {
274 1.16.2.1 chs struct vop_getpages_args /* {
275 1.16.2.1 chs struct vnode *a_vp;
276 1.16.2.1 chs vaddr_t a_offset;
277 1.16.2.1 chs vm_page_t *a_m;
278 1.16.2.1 chs int *a_count;
279 1.16.2.1 chs int a_centeridx;
280 1.16.2.1 chs vm_prot_t a_access_type;
281 1.16.2.1 chs int a_advice;
282 1.16.2.1 chs int a_flags;
283 1.16.2.1 chs } */ *ap = v;
284 1.16.2.1 chs
285 1.16.2.3 chs int i, error, npages;
286 1.16.2.1 chs vm_page_t m;
287 1.16.2.1 chs vaddr_t kva;
288 1.16.2.1 chs struct buf tmpbuf, *bp;
289 1.16.2.1 chs struct vnode *vp = ap->a_vp;
290 1.16.2.1 chs struct uvm_object *uobj = &vp->v_uvm.u_obj;
291 1.16.2.1 chs struct inode *ip = VTOI(vp);
292 1.16.2.1 chs struct fs *fs = ip->i_fs;
293 1.16.2.1 chs UVMHIST_FUNC("ffs_getpages"); UVMHIST_CALLED(ubchist);
294 1.16.2.1 chs
295 1.16.2.3 chs #ifdef DIAGNOSTIC
296 1.16.2.3 chs if (ap->a_centeridx < 0 || ap->a_centeridx > *ap->a_count) {
297 1.16.2.3 chs panic("ffs_getpages: centeridx %d out of range",
298 1.16.2.3 chs ap->a_centeridx);
299 1.16.2.3 chs }
300 1.16.2.3 chs #endif
301 1.16.2.3 chs
302 1.16.2.1 chs if (ap->a_flags & PGO_LOCKED) {
303 1.16.2.3 chs uvn_findpages(uobj, ap->a_offset, ap->a_count, ap->a_m,
304 1.16.2.3 chs UFP_NOWAIT|UFP_NOALLOC);
305 1.16.2.3 chs
306 1.16.2.3 chs /* XXX PGO_ALLPAGES? */
307 1.16.2.3 chs return ap->a_m[ap->a_centeridx] == NULL ?
308 1.16.2.3 chs VM_PAGER_UNLOCK : VM_PAGER_OK;
309 1.16.2.1 chs }
310 1.16.2.1 chs
311 1.16.2.1 chs /* vnode is VOP_LOCKed, uobj is locked */
312 1.16.2.1 chs
313 1.16.2.3 chs /*
314 1.16.2.3 chs * XXX
315 1.16.2.3 chs * first see if center page already exists.
316 1.16.2.3 chs * this is needed because ubc_fault() doesn't
317 1.16.2.3 chs * do a PGO_LOCKED call first.
318 1.16.2.3 chs * if the page exists, return it.
319 1.16.2.3 chs */
320 1.16.2.1 chs
321 1.16.2.3 chs npages = 1;
322 1.16.2.3 chs uvn_findpages(uobj, ap->a_offset + (ap->a_centeridx << PAGE_SHIFT),
323 1.16.2.3 chs &npages, &ap->a_m[ap->a_centeridx], UFP_NOALLOC);
324 1.16.2.3 chs if (npages == 1) {
325 1.16.2.3 chs simple_unlock(&uobj->vmobjlock);
326 1.16.2.3 chs return VM_PAGER_OK;
327 1.16.2.1 chs }
328 1.16.2.1 chs
329 1.16.2.3 chs npages = 1;
330 1.16.2.3 chs uvn_findpages(uobj, ap->a_offset, &npages, ap->a_m, 0);
331 1.16.2.1 chs m = ap->a_m[ap->a_centeridx];
332 1.16.2.1 chs
333 1.16.2.1 chs simple_unlock(&uobj->vmobjlock);
334 1.16.2.1 chs
335 1.16.2.1 chs if ((m->flags & PG_FAKE) == 0) {
336 1.16.2.1 chs UVMHIST_LOG(ubchist, "page was valid",0,0,0,0);
337 1.16.2.3 chs return VM_PAGER_OK;
338 1.16.2.1 chs }
339 1.16.2.1 chs
340 1.16.2.1 chs bp = &tmpbuf;
341 1.16.2.1 chs bzero(bp, sizeof *bp);
342 1.16.2.1 chs
343 1.16.2.1 chs bp->b_lblkno = lblkno(fs, m->offset);
344 1.16.2.3 chs if (m->blkno == 0) {
345 1.16.2.3 chs error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL);
346 1.16.2.3 chs if (error) {
347 1.16.2.1 chs UVMHIST_LOG(ubchist, "VOP_BMAP error %d", error,0,0,0);
348 1.16.2.3 chs return (error);
349 1.16.2.3 chs }
350 1.16.2.1 chs UVMHIST_LOG(ubchist, "VOP_BMAP gave 0x%x", bp->b_blkno,0,0,0);
351 1.16.2.3 chs if (bp->b_blkno == (daddr_t)-1) {
352 1.16.2.3 chs
353 1.16.2.3 chs /*
354 1.16.2.3 chs * XXX pre-allocate blocks here someday?
355 1.16.2.3 chs * ... only for write accesses.
356 1.16.2.3 chs * for read accesses we can skip the block allocation
357 1.16.2.3 chs * if we can arrange to be called again
358 1.16.2.3 chs * when a subsequent write access occurs.
359 1.16.2.3 chs * needs support in uvm_fault().
360 1.16.2.3 chs */
361 1.16.2.3 chs uvm_pagezero(m);
362 1.16.2.3 chs m->flags &= ~(PG_FAKE);
363 1.16.2.3 chs pmap_clear_modify(PMAP_PGARG(m));
364 1.16.2.3 chs pmap_clear_reference(PMAP_PGARG(m));
365 1.16.2.3 chs return VM_PAGER_OK;
366 1.16.2.3 chs }
367 1.16.2.1 chs }
368 1.16.2.1 chs
369 1.16.2.1 chs /* adjust physical blkno for partial blocks */
370 1.16.2.1 chs bp->b_blkno += (m->offset - lblktosize(fs, bp->b_lblkno)) >> DEV_BSHIFT;
371 1.16.2.1 chs m->blkno = bp->b_blkno;
372 1.16.2.1 chs
373 1.16.2.3 chs UVMHIST_LOG(ubchist, "vp %p lblkno 0x%x blkno 0x%x",
374 1.16.2.3 chs vp, bp->b_lblkno, bp->b_blkno, 0);
375 1.16.2.3 chs
376 1.16.2.3 chs /*
377 1.16.2.3 chs * don't bother reading the pages if we're just going to
378 1.16.2.3 chs * overwrite them.
379 1.16.2.3 chs */
380 1.16.2.3 chs if (ap->a_flags & PGO_OVERWRITE) {
381 1.16.2.3 chs for (i = 0; i < *ap->a_count; i++) {
382 1.16.2.3 chs
383 1.16.2.3 chs /* XXX for now, zero the pages */
384 1.16.2.3 chs if (ap->a_m[i]->flags & PG_FAKE) {
385 1.16.2.3 chs uvm_pagezero(ap->a_m[i]);
386 1.16.2.3 chs ap->a_m[i]->flags &= ~(PG_FAKE);
387 1.16.2.3 chs }
388 1.16.2.3 chs }
389 1.16.2.3 chs return VM_PAGER_OK;
390 1.16.2.3 chs }
391 1.16.2.3 chs
392 1.16.2.3 chs kva = uvm_pagermapin(ap->a_m, *ap->a_count, NULL, M_WAITOK);
393 1.16.2.3 chs if (kva == 0) {
394 1.16.2.3 chs /* XXX unbusy pages */
395 1.16.2.3 chs return VM_PAGER_AGAIN;
396 1.16.2.3 chs }
397 1.16.2.3 chs
398 1.16.2.3 chs bp->b_bufsize = PAGE_SIZE;
399 1.16.2.3 chs bp->b_data = (void *)kva;
400 1.16.2.3 chs bp->b_bcount = bp->b_lblkno < 0 ? bp->b_bufsize :
401 1.16.2.3 chs min(bp->b_bufsize,
402 1.16.2.3 chs fragroundup(fs, vp->v_uvm.u_size - m->offset));
403 1.16.2.3 chs bp->b_vp = vp;
404 1.16.2.3 chs bp->b_flags = B_BUSY|B_READ;
405 1.16.2.3 chs
406 1.16.2.3 chs UVMHIST_LOG(ubchist, "bp %p vp %p blkno 0x%x", bp, vp, bp->b_lblkno, 0);
407 1.16.2.1 chs
408 1.16.2.1 chs VOP_STRATEGY(bp);
409 1.16.2.1 chs error = biowait(bp);
410 1.16.2.1 chs
411 1.16.2.1 chs UVMHIST_LOG(ubchist, "error %d", error,0,0,0);
412 1.16.2.1 chs
413 1.16.2.1 chs uvm_pagermapout(kva, *ap->a_count);
414 1.16.2.1 chs
415 1.16.2.1 chs if (error) {
416 1.16.2.1 chs simple_lock(&uobj->vmobjlock);
417 1.16.2.1 chs if (m->flags & PG_WANTED)
418 1.16.2.3 chs wakeup(m);
419 1.16.2.1 chs m->flags &= ~(PG_WANTED|PG_BUSY);
420 1.16.2.1 chs UVM_PAGE_OWN(m, NULL);
421 1.16.2.1 chs uvm_lock_pageq();
422 1.16.2.1 chs uvm_pagefree(m);
423 1.16.2.1 chs uvm_unlock_pageq();
424 1.16.2.1 chs simple_unlock(&uobj->vmobjlock);
425 1.16.2.1 chs } else {
426 1.16.2.3 chs m->flags &= ~(PG_FAKE);
427 1.16.2.1 chs pmap_clear_modify(PMAP_PGARG(m));
428 1.16.2.1 chs }
429 1.16.2.1 chs
430 1.16.2.3 chs return error ? VM_PAGER_ERROR : VM_PAGER_OK;
431 1.16.2.1 chs }
432 1.16.2.1 chs
433 1.16.2.1 chs /*
434 1.16.2.1 chs * Vnode op for VM putpages.
435 1.16.2.1 chs */
436 1.16.2.1 chs int
437 1.16.2.1 chs ffs_putpages(v)
438 1.16.2.1 chs void *v;
439 1.16.2.1 chs {
440 1.16.2.1 chs struct vop_putpages_args /* {
441 1.16.2.1 chs struct vnode *a_vp;
442 1.16.2.3 chs struct vm_page **a_m;
443 1.16.2.1 chs int a_count;
444 1.16.2.1 chs int a_sync;
445 1.16.2.1 chs int *a_rtvals;
446 1.16.2.1 chs } */ *ap = v;
447 1.16.2.1 chs
448 1.16.2.3 chs int s, error;
449 1.16.2.3 chs vaddr_t kva, offset;
450 1.16.2.3 chs struct vm_page *pg;
451 1.16.2.1 chs struct buf tmpbuf, *bp;
452 1.16.2.1 chs struct vnode *vp = ap->a_vp;
453 1.16.2.1 chs struct inode *ip = VTOI(vp);
454 1.16.2.1 chs struct fs *fs = ip->i_fs;
455 1.16.2.1 chs struct ucred *cred = curproc->p_ucred; /* XXX curproc */
456 1.16.2.1 chs UVMHIST_FUNC("ffs_putpages"); UVMHIST_CALLED(ubchist);
457 1.16.2.1 chs
458 1.16.2.3 chs pg = ap->a_m[0];
459 1.16.2.3 chs
460 1.16.2.3 chs #ifdef DIAGNOSTIC
461 1.16.2.3 chs if (ap->a_count > 1) {
462 1.16.2.3 chs int i;
463 1.16.2.3 chs
464 1.16.2.3 chs for (i = 1; i < ap->a_count; i++) {
465 1.16.2.3 chs if (ap->a_m[i]->blkno !=
466 1.16.2.3 chs pg->blkno + i * (PAGE_SIZE >> DEV_BSHIFT)) {
467 1.16.2.3 chs panic("ffs_putpages: pg %p %p not clusterable",
468 1.16.2.3 chs pg, ap->a_m[i]);
469 1.16.2.3 chs }
470 1.16.2.3 chs }
471 1.16.2.2 chs }
472 1.16.2.3 chs #endif
473 1.16.2.1 chs
474 1.16.2.1 chs kva = uvm_pagermapin(ap->a_m, ap->a_count, NULL, M_WAITOK);
475 1.16.2.2 chs if (kva == 0) {
476 1.16.2.3 chs return VM_PAGER_AGAIN;
477 1.16.2.1 chs }
478 1.16.2.1 chs
479 1.16.2.3 chs if (ap->a_sync) {
480 1.16.2.3 chs bp = &tmpbuf;
481 1.16.2.3 chs bzero(bp, sizeof *bp);
482 1.16.2.3 chs }
483 1.16.2.3 chs else {
484 1.16.2.3 chs struct uvm_aiobuf *abp = pool_get(uvm_aiobuf_pool, PR_WAITOK);
485 1.16.2.3 chs abp->aio.aiodone = uvm_aio_aiodone;
486 1.16.2.3 chs abp->aio.kva = kva;
487 1.16.2.3 chs abp->aio.npages = ap->a_count;
488 1.16.2.3 chs abp->aio.pd_ptr = abp;
489 1.16.2.3 chs bp = &abp->buf;
490 1.16.2.3 chs bzero(bp, sizeof *bp);
491 1.16.2.3 chs bp->b_flags = B_CALL|B_ASYNC;
492 1.16.2.3 chs bp->b_iodone = uvm_aio_biodone;
493 1.16.2.3 chs }
494 1.16.2.1 chs
495 1.16.2.3 chs offset = pg->offset;
496 1.16.2.3 chs bp->b_bufsize = ap->a_count << PAGE_SHIFT;
497 1.16.2.1 chs bp->b_data = (void *)kva;
498 1.16.2.3 chs bp->b_lblkno = lblkno(fs, offset);
499 1.16.2.3 chs bp->b_bcount = min(bp->b_bufsize,
500 1.16.2.3 chs fragroundup(fs, vp->v_uvm.u_size - offset));
501 1.16.2.3 chs bp->b_flags |= B_BUSY|B_WRITE;
502 1.16.2.1 chs bp->b_vp = vp;
503 1.16.2.1 chs
504 1.16.2.1 chs /*
505 1.16.2.1 chs * if the blkno wasn't set in the page, do a bmap to find it.
506 1.16.2.3 chs * this should only happen if the block is unallocated.
507 1.16.2.1 chs * we'll always want to set the page's blkno if it's allocated
508 1.16.2.1 chs * to help prevent memory deadlocks. we probably even want to
509 1.16.2.3 chs * allocate blocks in VOP_GETPAGES() for this same reason.
510 1.16.2.1 chs *
511 1.16.2.1 chs * once we switch to doing that, the page should always have a blkno.
512 1.16.2.1 chs * but for now, we'll handle allocating blocks here too.
513 1.16.2.3 chs *
514 1.16.2.3 chs * XXX this doesn't handle blocksizes smaller than PAGE_SIZE.
515 1.16.2.1 chs */
516 1.16.2.1 chs
517 1.16.2.3 chs bp->b_blkno = pg->blkno;
518 1.16.2.1 chs if (bp->b_blkno == 0) {
519 1.16.2.3 chs int bsize;
520 1.16.2.3 chs
521 1.16.2.3 chs #ifdef DEBUG
522 1.16.2.1 chs error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL);
523 1.16.2.1 chs if (error) {
524 1.16.2.3 chs goto out;
525 1.16.2.1 chs }
526 1.16.2.3 chs if (bp->b_blkno != (daddr_t)-1) {
527 1.16.2.3 chs panic("ffs_putpage: page %p has blkno 0, not %d\n",
528 1.16.2.3 chs pg, bp->b_blkno);
529 1.16.2.3 chs }
530 1.16.2.3 chs #endif
531 1.16.2.3 chs bsize = blksize(fs, ip, lblkno(fs, offset));
532 1.16.2.3 chs error = ffs_balloc(ip, bp->b_lblkno, bsize, cred, NULL,
533 1.16.2.3 chs &bp->b_blkno, 0, NULL);
534 1.16.2.1 chs if (error) {
535 1.16.2.3 chs UVMHIST_LOG(ubchist, "ffs_balloc -> %d", error, 0,0,0);
536 1.16.2.3 chs goto out;
537 1.16.2.1 chs }
538 1.16.2.1 chs
539 1.16.2.1 chs /* adjust physical blkno for partial blocks */
540 1.16.2.3 chs bp->b_blkno += ((offset - lblktosize(fs, bp->b_lblkno))
541 1.16.2.1 chs >> DEV_BSHIFT);
542 1.16.2.3 chs pg->blkno = bp->b_blkno;
543 1.16.2.1 chs }
544 1.16.2.1 chs
545 1.16.2.3 chs UVMHIST_LOG(ubchist, "pg %p vp %p lblkno 0x%x blkno 0x%x",
546 1.16.2.3 chs pg, vp, bp->b_lblkno, bp->b_blkno);
547 1.16.2.1 chs
548 1.16.2.3 chs s = splbio();
549 1.16.2.1 chs vp->v_numoutput++;
550 1.16.2.3 chs splx(s);
551 1.16.2.1 chs
552 1.16.2.1 chs VOP_STRATEGY(bp);
553 1.16.2.3 chs if (!ap->a_sync) {
554 1.16.2.3 chs return VM_PAGER_PEND;
555 1.16.2.3 chs }
556 1.16.2.1 chs
557 1.16.2.1 chs error = biowait(bp);
558 1.16.2.1 chs
559 1.16.2.3 chs out:
560 1.16.2.1 chs UVMHIST_LOG(ubchist, "error %d", error,0,0,0);
561 1.16.2.1 chs uvm_pagermapout(kva, ap->a_count);
562 1.16.2.1 chs
563 1.16.2.3 chs return error ? VM_PAGER_ERROR : VM_PAGER_OK;
564 1.16.2.1 chs }
565 1.16.2.1 chs #endif
566