lfs_vfsops.c revision 1.323 1 /* $NetBSD: lfs_vfsops.c,v 1.323 2015/05/31 15:44:31 hannken Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
5 * The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Konrad E. Schroder <perseant (at) hhhh.org>.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32 /*-
33 * Copyright (c) 1989, 1991, 1993, 1994
34 * The Regents of the University of California. All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
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.
47 *
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
58 * SUCH DAMAGE.
59 *
60 * @(#)lfs_vfsops.c 8.20 (Berkeley) 6/10/95
61 */
62
63 #include <sys/cdefs.h>
64 __KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.323 2015/05/31 15:44:31 hannken Exp $");
65
66 #if defined(_KERNEL_OPT)
67 #include "opt_lfs.h"
68 #include "opt_quota.h"
69 #endif
70
71 #include <sys/param.h>
72 #include <sys/systm.h>
73 #include <sys/namei.h>
74 #include <sys/proc.h>
75 #include <sys/kernel.h>
76 #include <sys/vnode.h>
77 #include <sys/mount.h>
78 #include <sys/kthread.h>
79 #include <sys/buf.h>
80 #include <sys/device.h>
81 #include <sys/mbuf.h>
82 #include <sys/file.h>
83 #include <sys/disklabel.h>
84 #include <sys/ioctl.h>
85 #include <sys/errno.h>
86 #include <sys/malloc.h>
87 #include <sys/pool.h>
88 #include <sys/socket.h>
89 #include <sys/syslog.h>
90 #include <uvm/uvm_extern.h>
91 #include <sys/sysctl.h>
92 #include <sys/conf.h>
93 #include <sys/kauth.h>
94 #include <sys/module.h>
95 #include <sys/syscallvar.h>
96 #include <sys/syscall.h>
97 #include <sys/syscallargs.h>
98
99 #include <miscfs/specfs/specdev.h>
100
101 #include <ufs/lfs/ulfs_quotacommon.h>
102 #include <ufs/lfs/ulfs_inode.h>
103 #include <ufs/lfs/ulfsmount.h>
104 #include <ufs/lfs/ulfs_extern.h>
105
106 #include <uvm/uvm.h>
107 #include <uvm/uvm_stat.h>
108 #include <uvm/uvm_pager.h>
109 #include <uvm/uvm_pdaemon.h>
110
111 #include <ufs/lfs/lfs.h>
112 #include <ufs/lfs/lfs_kernel.h>
113 #include <ufs/lfs/lfs_extern.h>
114
115 #include <miscfs/genfs/genfs.h>
116 #include <miscfs/genfs/genfs_node.h>
117
118 MODULE(MODULE_CLASS_VFS, lfs, NULL);
119
120 static int lfs_gop_write(struct vnode *, struct vm_page **, int, int);
121 static int lfs_mountfs(struct vnode *, struct mount *, struct lwp *);
122
123 static struct sysctllog *lfs_sysctl_log;
124
125 extern const struct vnodeopv_desc lfs_vnodeop_opv_desc;
126 extern const struct vnodeopv_desc lfs_specop_opv_desc;
127 extern const struct vnodeopv_desc lfs_fifoop_opv_desc;
128
129 pid_t lfs_writer_daemon = 0;
130 lwpid_t lfs_writer_lid = 0;
131 int lfs_do_flush = 0;
132 #ifdef LFS_KERNEL_RFW
133 int lfs_do_rfw = 0;
134 #endif
135
136 const struct vnodeopv_desc * const lfs_vnodeopv_descs[] = {
137 &lfs_vnodeop_opv_desc,
138 &lfs_specop_opv_desc,
139 &lfs_fifoop_opv_desc,
140 NULL,
141 };
142
143 struct vfsops lfs_vfsops = {
144 .vfs_name = MOUNT_LFS,
145 .vfs_min_mount_data = sizeof (struct ulfs_args),
146 .vfs_mount = lfs_mount,
147 .vfs_start = ulfs_start,
148 .vfs_unmount = lfs_unmount,
149 .vfs_root = ulfs_root,
150 .vfs_quotactl = ulfs_quotactl,
151 .vfs_statvfs = lfs_statvfs,
152 .vfs_sync = lfs_sync,
153 .vfs_vget = lfs_vget,
154 .vfs_fhtovp = lfs_fhtovp,
155 .vfs_vptofh = lfs_vptofh,
156 .vfs_init = lfs_init,
157 .vfs_reinit = lfs_reinit,
158 .vfs_done = lfs_done,
159 .vfs_mountroot = lfs_mountroot,
160 .vfs_snapshot = (void *)eopnotsupp,
161 .vfs_extattrctl = lfs_extattrctl,
162 .vfs_suspendctl = (void *)eopnotsupp,
163 .vfs_renamelock_enter = genfs_renamelock_enter,
164 .vfs_renamelock_exit = genfs_renamelock_exit,
165 .vfs_fsync = (void *)eopnotsupp,
166 .vfs_opv_descs = lfs_vnodeopv_descs
167 };
168
169 const struct genfs_ops lfs_genfsops = {
170 .gop_size = lfs_gop_size,
171 .gop_alloc = ulfs_gop_alloc,
172 .gop_write = lfs_gop_write,
173 .gop_markupdate = ulfs_gop_markupdate,
174 };
175
176 struct shortlong {
177 const char *sname;
178 const char *lname;
179 };
180
181 static int
182 sysctl_lfs_dostats(SYSCTLFN_ARGS)
183 {
184 extern struct lfs_stats lfs_stats;
185 extern int lfs_dostats;
186 int error;
187
188 error = sysctl_lookup(SYSCTLFN_CALL(rnode));
189 if (error || newp == NULL)
190 return (error);
191
192 if (lfs_dostats == 0)
193 memset(&lfs_stats, 0, sizeof(lfs_stats));
194
195 return (0);
196 }
197
198 static void
199 lfs_sysctl_setup(struct sysctllog **clog)
200 {
201 int i;
202 extern int lfs_writeindir, lfs_dostats, lfs_clean_vnhead,
203 lfs_fs_pagetrip, lfs_ignore_lazy_sync;
204 #ifdef DEBUG
205 extern int lfs_debug_log_subsys[DLOG_MAX];
206 struct shortlong dlog_names[DLOG_MAX] = { /* Must match lfs.h ! */
207 { "rollforward", "Debug roll-forward code" },
208 { "alloc", "Debug inode allocation and free list" },
209 { "avail", "Debug space-available-now accounting" },
210 { "flush", "Debug flush triggers" },
211 { "lockedlist", "Debug locked list accounting" },
212 { "vnode_verbose", "Verbose per-vnode-written debugging" },
213 { "vnode", "Debug vnode use during segment write" },
214 { "segment", "Debug segment writing" },
215 { "seguse", "Debug segment used-bytes accounting" },
216 { "cleaner", "Debug cleaning routines" },
217 { "mount", "Debug mount/unmount routines" },
218 { "pagecache", "Debug UBC interactions" },
219 { "dirop", "Debug directory-operation accounting" },
220 { "malloc", "Debug private malloc accounting" },
221 };
222 #endif /* DEBUG */
223 struct shortlong stat_names[] = { /* Must match lfs.h! */
224 { "segsused", "Number of new segments allocated" },
225 { "psegwrites", "Number of partial-segment writes" },
226 { "psyncwrites", "Number of synchronous partial-segment"
227 " writes" },
228 { "pcleanwrites", "Number of partial-segment writes by the"
229 " cleaner" },
230 { "blocktot", "Number of blocks written" },
231 { "cleanblocks", "Number of blocks written by the cleaner" },
232 { "ncheckpoints", "Number of checkpoints made" },
233 { "nwrites", "Number of whole writes" },
234 { "nsync_writes", "Number of synchronous writes" },
235 { "wait_exceeded", "Number of times writer waited for"
236 " cleaner" },
237 { "write_exceeded", "Number of times writer invoked flush" },
238 { "flush_invoked", "Number of times flush was invoked" },
239 { "vflush_invoked", "Number of time vflush was called" },
240 { "clean_inlocked", "Number of vnodes skipped for being dead" },
241 { "clean_vnlocked", "Number of vnodes skipped for vget failure" },
242 { "segs_reclaimed", "Number of segments reclaimed" },
243 };
244
245 sysctl_createv(clog, 0, NULL, NULL,
246 CTLFLAG_PERMANENT,
247 CTLTYPE_NODE, "lfs",
248 SYSCTL_DESCR("Log-structured file system"),
249 NULL, 0, NULL, 0,
250 CTL_VFS, 5, CTL_EOL);
251 /*
252 * XXX the "5" above could be dynamic, thereby eliminating one
253 * more instance of the "number to vfs" mapping problem, but
254 * "5" is the order as taken from sys/mount.h
255 */
256
257 sysctl_createv(clog, 0, NULL, NULL,
258 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
259 CTLTYPE_INT, "flushindir", NULL,
260 NULL, 0, &lfs_writeindir, 0,
261 CTL_VFS, 5, LFS_WRITEINDIR, CTL_EOL);
262 sysctl_createv(clog, 0, NULL, NULL,
263 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
264 CTLTYPE_INT, "clean_vnhead", NULL,
265 NULL, 0, &lfs_clean_vnhead, 0,
266 CTL_VFS, 5, LFS_CLEAN_VNHEAD, CTL_EOL);
267 sysctl_createv(clog, 0, NULL, NULL,
268 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
269 CTLTYPE_INT, "dostats",
270 SYSCTL_DESCR("Maintain statistics on LFS operations"),
271 sysctl_lfs_dostats, 0, &lfs_dostats, 0,
272 CTL_VFS, 5, LFS_DOSTATS, CTL_EOL);
273 sysctl_createv(clog, 0, NULL, NULL,
274 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
275 CTLTYPE_INT, "pagetrip",
276 SYSCTL_DESCR("How many dirty pages in fs triggers"
277 " a flush"),
278 NULL, 0, &lfs_fs_pagetrip, 0,
279 CTL_VFS, 5, LFS_FS_PAGETRIP, CTL_EOL);
280 sysctl_createv(clog, 0, NULL, NULL,
281 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
282 CTLTYPE_INT, "ignore_lazy_sync",
283 SYSCTL_DESCR("Lazy Sync is ignored entirely"),
284 NULL, 0, &lfs_ignore_lazy_sync, 0,
285 CTL_VFS, 5, LFS_IGNORE_LAZY_SYNC, CTL_EOL);
286 #ifdef LFS_KERNEL_RFW
287 sysctl_createv(clog, 0, NULL, NULL,
288 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
289 CTLTYPE_INT, "rfw",
290 SYSCTL_DESCR("Use in-kernel roll-forward on mount"),
291 NULL, 0, &lfs_do_rfw, 0,
292 CTL_VFS, 5, LFS_DO_RFW, CTL_EOL);
293 #endif
294
295 sysctl_createv(clog, 0, NULL, NULL,
296 CTLFLAG_PERMANENT,
297 CTLTYPE_NODE, "stats",
298 SYSCTL_DESCR("Debugging options"),
299 NULL, 0, NULL, 0,
300 CTL_VFS, 5, LFS_STATS, CTL_EOL);
301 for (i = 0; i < sizeof(struct lfs_stats) / sizeof(u_int); i++) {
302 sysctl_createv(clog, 0, NULL, NULL,
303 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
304 CTLTYPE_INT, stat_names[i].sname,
305 SYSCTL_DESCR(stat_names[i].lname),
306 NULL, 0, &(((u_int *)&lfs_stats.segsused)[i]),
307 0, CTL_VFS, 5, LFS_STATS, i, CTL_EOL);
308 }
309
310 #ifdef DEBUG
311 sysctl_createv(clog, 0, NULL, NULL,
312 CTLFLAG_PERMANENT,
313 CTLTYPE_NODE, "debug",
314 SYSCTL_DESCR("Debugging options"),
315 NULL, 0, NULL, 0,
316 CTL_VFS, 5, LFS_DEBUGLOG, CTL_EOL);
317 for (i = 0; i < DLOG_MAX; i++) {
318 sysctl_createv(clog, 0, NULL, NULL,
319 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
320 CTLTYPE_INT, dlog_names[i].sname,
321 SYSCTL_DESCR(dlog_names[i].lname),
322 NULL, 0, &(lfs_debug_log_subsys[i]), 0,
323 CTL_VFS, 5, LFS_DEBUGLOG, i, CTL_EOL);
324 }
325 #endif
326 }
327
328 /* old cleaner syscall interface. see VOP_FCNTL() */
329 static const struct syscall_package lfs_syscalls[] = {
330 { SYS_lfs_bmapv, 0, (sy_call_t *)sys_lfs_bmapv },
331 { SYS_lfs_markv, 0, (sy_call_t *)sys_lfs_markv },
332 { SYS_lfs_segclean, 0, (sy_call_t *)sys___lfs_segwait50 },
333 { 0, 0, NULL },
334 };
335
336 static int
337 lfs_modcmd(modcmd_t cmd, void *arg)
338 {
339 int error;
340
341 switch (cmd) {
342 case MODULE_CMD_INIT:
343 error = syscall_establish(NULL, lfs_syscalls);
344 if (error)
345 return error;
346 error = vfs_attach(&lfs_vfsops);
347 if (error != 0) {
348 syscall_disestablish(NULL, lfs_syscalls);
349 break;
350 }
351 lfs_sysctl_setup(&lfs_sysctl_log);
352 break;
353 case MODULE_CMD_FINI:
354 error = vfs_detach(&lfs_vfsops);
355 if (error != 0)
356 break;
357 syscall_disestablish(NULL, lfs_syscalls);
358 sysctl_teardown(&lfs_sysctl_log);
359 break;
360 default:
361 error = ENOTTY;
362 break;
363 }
364
365 return (error);
366 }
367
368 /*
369 * XXX Same structure as FFS inodes? Should we share a common pool?
370 */
371 struct pool lfs_inode_pool;
372 struct pool lfs_dinode_pool;
373 struct pool lfs_inoext_pool;
374 struct pool lfs_lbnentry_pool;
375
376 /*
377 * The writer daemon. UVM keeps track of how many dirty pages we are holding
378 * in lfs_subsys_pages; the daemon flushes the filesystem when this value
379 * crosses the (user-defined) threshhold LFS_MAX_PAGES.
380 */
381 static void
382 lfs_writerd(void *arg)
383 {
384 struct mount *mp, *nmp;
385 struct lfs *fs;
386 struct vfsops *vfs = NULL;
387 int fsflags;
388 int skipc;
389 int lfsc;
390 int wrote_something = 0;
391
392 mutex_enter(&lfs_lock);
393 lfs_writer_daemon = curproc->p_pid;
394 lfs_writer_lid = curlwp->l_lid;
395 mutex_exit(&lfs_lock);
396
397 /* Take an extra reference to the LFS vfsops. */
398 vfs = vfs_getopsbyname(MOUNT_LFS);
399
400 mutex_enter(&lfs_lock);
401 for (;;) {
402 KASSERT(mutex_owned(&lfs_lock));
403 if (wrote_something == 0)
404 mtsleep(&lfs_writer_daemon, PVM, "lfswriter", hz/10 + 1,
405 &lfs_lock);
406
407 KASSERT(mutex_owned(&lfs_lock));
408 wrote_something = 0;
409
410 /*
411 * If global state wants a flush, flush everything.
412 */
413 if (lfs_do_flush || locked_queue_count > LFS_MAX_BUFS ||
414 locked_queue_bytes > LFS_MAX_BYTES ||
415 lfs_subsys_pages > LFS_MAX_PAGES) {
416
417 if (lfs_do_flush) {
418 DLOG((DLOG_FLUSH, "lfs_writerd: lfs_do_flush\n"));
419 }
420 if (locked_queue_count > LFS_MAX_BUFS) {
421 DLOG((DLOG_FLUSH, "lfs_writerd: lqc = %d, max %d\n",
422 locked_queue_count, LFS_MAX_BUFS));
423 }
424 if (locked_queue_bytes > LFS_MAX_BYTES) {
425 DLOG((DLOG_FLUSH, "lfs_writerd: lqb = %ld, max %ld\n",
426 locked_queue_bytes, LFS_MAX_BYTES));
427 }
428 if (lfs_subsys_pages > LFS_MAX_PAGES) {
429 DLOG((DLOG_FLUSH, "lfs_writerd: lssp = %d, max %d\n",
430 lfs_subsys_pages, LFS_MAX_PAGES));
431 }
432
433 lfs_flush(NULL, SEGM_WRITERD, 0);
434 lfs_do_flush = 0;
435 KASSERT(mutex_owned(&lfs_lock));
436 continue;
437 }
438 KASSERT(mutex_owned(&lfs_lock));
439 mutex_exit(&lfs_lock);
440
441 /*
442 * Look through the list of LFSs to see if any of them
443 * have requested pageouts.
444 */
445 mutex_enter(&mountlist_lock);
446 lfsc = 0;
447 skipc = 0;
448 for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
449 if (vfs_busy(mp, &nmp)) {
450 ++skipc;
451 continue;
452 }
453 KASSERT(!mutex_owned(&lfs_lock));
454 if (strncmp(mp->mnt_stat.f_fstypename, MOUNT_LFS,
455 sizeof(mp->mnt_stat.f_fstypename)) == 0) {
456 ++lfsc;
457 fs = VFSTOULFS(mp)->um_lfs;
458 int32_t ooffset = 0;
459 fsflags = SEGM_SINGLE;
460
461 mutex_enter(&lfs_lock);
462 ooffset = fs->lfs_offset;
463
464 if (fs->lfs_nextseg < fs->lfs_curseg && fs->lfs_nowrap) {
465 /* Don't try to write if we're suspended */
466 mutex_exit(&lfs_lock);
467 vfs_unbusy(mp, false, &nmp);
468 continue;
469 }
470 if (LFS_STARVED_FOR_SEGS(fs)) {
471 mutex_exit(&lfs_lock);
472
473 DLOG((DLOG_FLUSH, "lfs_writerd: need cleaning before writing possible\n"));
474 lfs_wakeup_cleaner(fs);
475 vfs_unbusy(mp, false, &nmp);
476 continue;
477 }
478
479 if ((fs->lfs_dirvcount > LFS_MAX_FSDIROP(fs) ||
480 lfs_dirvcount > LFS_MAX_DIROP) &&
481 fs->lfs_dirops == 0) {
482 fsflags &= ~SEGM_SINGLE;
483 fsflags |= SEGM_CKP;
484 DLOG((DLOG_FLUSH, "lfs_writerd: checkpoint\n"));
485 lfs_flush_fs(fs, fsflags);
486 } else if (fs->lfs_pdflush) {
487 DLOG((DLOG_FLUSH, "lfs_writerd: pdflush set\n"));
488 lfs_flush_fs(fs, fsflags);
489 } else if (!TAILQ_EMPTY(&fs->lfs_pchainhd)) {
490 DLOG((DLOG_FLUSH, "lfs_writerd: pchain non-empty\n"));
491 mutex_exit(&lfs_lock);
492 lfs_writer_enter(fs, "wrdirop");
493 lfs_flush_pchain(fs);
494 lfs_writer_leave(fs);
495 mutex_enter(&lfs_lock);
496 }
497 if (fs->lfs_offset != ooffset)
498 ++wrote_something;
499 mutex_exit(&lfs_lock);
500 }
501 KASSERT(!mutex_owned(&lfs_lock));
502 vfs_unbusy(mp, false, &nmp);
503 }
504 if (lfsc + skipc == 0) {
505 mutex_enter(&lfs_lock);
506 lfs_writer_daemon = 0;
507 lfs_writer_lid = 0;
508 mutex_exit(&lfs_lock);
509 mutex_exit(&mountlist_lock);
510 break;
511 }
512 mutex_exit(&mountlist_lock);
513
514 mutex_enter(&lfs_lock);
515 }
516 KASSERT(!mutex_owned(&lfs_lock));
517 KASSERT(!mutex_owned(&mountlist_lock));
518
519 /* Give up our extra reference so the module can be unloaded. */
520 mutex_enter(&vfs_list_lock);
521 if (vfs != NULL)
522 vfs->vfs_refcount--;
523 mutex_exit(&vfs_list_lock);
524
525 /* Done! */
526 kthread_exit(0);
527 }
528
529 /*
530 * Initialize the filesystem, most work done by ulfs_init.
531 */
532 void
533 lfs_init(void)
534 {
535
536 malloc_type_attach(M_SEGMENT);
537 pool_init(&lfs_inode_pool, sizeof(struct inode), 0, 0, 0,
538 "lfsinopl", &pool_allocator_nointr, IPL_NONE);
539 pool_init(&lfs_dinode_pool, sizeof(struct ulfs1_dinode), 0, 0, 0,
540 "lfsdinopl", &pool_allocator_nointr, IPL_NONE);
541 pool_init(&lfs_inoext_pool, sizeof(struct lfs_inode_ext), 8, 0, 0,
542 "lfsinoextpl", &pool_allocator_nointr, IPL_NONE);
543 pool_init(&lfs_lbnentry_pool, sizeof(struct lbnentry), 0, 0, 0,
544 "lfslbnpool", &pool_allocator_nointr, IPL_NONE);
545 ulfs_init();
546
547 #ifdef DEBUG
548 memset(lfs_log, 0, sizeof(lfs_log));
549 #endif
550 mutex_init(&lfs_lock, MUTEX_DEFAULT, IPL_NONE);
551 cv_init(&locked_queue_cv, "lfsbuf");
552 cv_init(&lfs_writing_cv, "lfsflush");
553 }
554
555 void
556 lfs_reinit(void)
557 {
558 ulfs_reinit();
559 }
560
561 void
562 lfs_done(void)
563 {
564 ulfs_done();
565 mutex_destroy(&lfs_lock);
566 cv_destroy(&locked_queue_cv);
567 cv_destroy(&lfs_writing_cv);
568 pool_destroy(&lfs_inode_pool);
569 pool_destroy(&lfs_dinode_pool);
570 pool_destroy(&lfs_inoext_pool);
571 pool_destroy(&lfs_lbnentry_pool);
572 malloc_type_detach(M_SEGMENT);
573 }
574
575 /*
576 * Called by main() when ulfs is going to be mounted as root.
577 */
578 int
579 lfs_mountroot(void)
580 {
581 extern struct vnode *rootvp;
582 struct lfs *fs = NULL; /* LFS */
583 struct mount *mp;
584 struct lwp *l = curlwp;
585 struct ulfsmount *ump;
586 int error;
587
588 if (device_class(root_device) != DV_DISK)
589 return (ENODEV);
590
591 if (rootdev == NODEV)
592 return (ENODEV);
593 if ((error = vfs_rootmountalloc(MOUNT_LFS, "root_device", &mp))) {
594 vrele(rootvp);
595 return (error);
596 }
597 if ((error = lfs_mountfs(rootvp, mp, l))) {
598 vfs_unbusy(mp, false, NULL);
599 vfs_destroy(mp);
600 return (error);
601 }
602 mountlist_append(mp);
603 ump = VFSTOULFS(mp);
604 fs = ump->um_lfs;
605 memset(fs->lfs_fsmnt, 0, sizeof(fs->lfs_fsmnt));
606 (void)copystr(mp->mnt_stat.f_mntonname, fs->lfs_fsmnt, MNAMELEN - 1, 0);
607 (void)lfs_statvfs(mp, &mp->mnt_stat);
608 vfs_unbusy(mp, false, NULL);
609 setrootfstime((time_t)(VFSTOULFS(mp)->um_lfs->lfs_tstamp));
610 return (0);
611 }
612
613 /*
614 * VFS Operations.
615 *
616 * mount system call
617 */
618 int
619 lfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
620 {
621 struct lwp *l = curlwp;
622 struct vnode *devvp;
623 struct ulfs_args *args = data;
624 struct ulfsmount *ump = NULL;
625 struct lfs *fs = NULL; /* LFS */
626 int error = 0, update;
627 mode_t accessmode;
628
629 if (args == NULL)
630 return EINVAL;
631 if (*data_len < sizeof *args)
632 return EINVAL;
633
634 if (mp->mnt_flag & MNT_GETARGS) {
635 ump = VFSTOULFS(mp);
636 if (ump == NULL)
637 return EIO;
638 args->fspec = NULL;
639 *data_len = sizeof *args;
640 return 0;
641 }
642
643 update = mp->mnt_flag & MNT_UPDATE;
644
645 /* Check arguments */
646 if (args->fspec != NULL) {
647 /*
648 * Look up the name and verify that it's sane.
649 */
650 error = namei_simple_user(args->fspec,
651 NSM_FOLLOW_NOEMULROOT, &devvp);
652 if (error != 0)
653 return (error);
654
655 if (!update) {
656 /*
657 * Be sure this is a valid block device
658 */
659 if (devvp->v_type != VBLK)
660 error = ENOTBLK;
661 else if (bdevsw_lookup(devvp->v_rdev) == NULL)
662 error = ENXIO;
663 } else {
664 /*
665 * Be sure we're still naming the same device
666 * used for our initial mount
667 */
668 ump = VFSTOULFS(mp);
669 if (devvp != ump->um_devvp) {
670 if (devvp->v_rdev != ump->um_devvp->v_rdev)
671 error = EINVAL;
672 else {
673 vrele(devvp);
674 devvp = ump->um_devvp;
675 vref(devvp);
676 }
677 }
678 }
679 } else {
680 if (!update) {
681 /* New mounts must have a filename for the device */
682 return (EINVAL);
683 } else {
684 /* Use the extant mount */
685 ump = VFSTOULFS(mp);
686 devvp = ump->um_devvp;
687 vref(devvp);
688 }
689 }
690
691
692 /*
693 * If mount by non-root, then verify that user has necessary
694 * permissions on the device.
695 */
696 if (error == 0) {
697 accessmode = VREAD;
698 if (update ?
699 (mp->mnt_iflag & IMNT_WANTRDWR) != 0 :
700 (mp->mnt_flag & MNT_RDONLY) == 0)
701 accessmode |= VWRITE;
702 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
703 error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
704 KAUTH_REQ_SYSTEM_MOUNT_DEVICE, mp, devvp,
705 KAUTH_ARG(accessmode));
706 VOP_UNLOCK(devvp);
707 }
708
709 if (error) {
710 vrele(devvp);
711 return (error);
712 }
713
714 if (!update) {
715 int flags;
716
717 if (mp->mnt_flag & MNT_RDONLY)
718 flags = FREAD;
719 else
720 flags = FREAD|FWRITE;
721 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
722 error = VOP_OPEN(devvp, flags, FSCRED);
723 VOP_UNLOCK(devvp);
724 if (error)
725 goto fail;
726 error = lfs_mountfs(devvp, mp, l); /* LFS */
727 if (error) {
728 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
729 (void)VOP_CLOSE(devvp, flags, NOCRED);
730 VOP_UNLOCK(devvp);
731 goto fail;
732 }
733
734 ump = VFSTOULFS(mp);
735 fs = ump->um_lfs;
736 } else {
737 /*
738 * Update the mount.
739 */
740
741 /*
742 * The initial mount got a reference on this
743 * device, so drop the one obtained via
744 * namei(), above.
745 */
746 vrele(devvp);
747
748 ump = VFSTOULFS(mp);
749 fs = ump->um_lfs;
750
751 if (fs->lfs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
752 /*
753 * Changing from read/write to read-only.
754 * XXX: shouldn't we sync here? or does vfs do that?
755 */
756 #ifdef LFS_QUOTA2
757 /* XXX: quotas should remain on when readonly */
758 if (fs->lfs_use_quota2) {
759 error = lfsquota2_umount(mp, 0);
760 if (error) {
761 return error;
762 }
763 }
764 #endif
765 }
766
767 if (fs->lfs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR)) {
768 /*
769 * Changing from read-only to read/write.
770 * Note in the superblocks that we're writing.
771 */
772
773 /* XXX: quotas should have been on even if readonly */
774 if (fs->lfs_use_quota2) {
775 #ifdef LFS_QUOTA2
776 error = lfs_quota2_mount(mp);
777 #else
778 uprintf("%s: no kernel support for this "
779 "filesystem's quotas\n",
780 mp->mnt_stat.f_mntonname);
781 if (mp->mnt_flag & MNT_FORCE) {
782 uprintf("%s: mounting anyway; "
783 "fsck afterwards\n",
784 mp->mnt_stat.f_mntonname);
785 } else {
786 error = EINVAL;
787 }
788 #endif
789 if (error) {
790 return error;
791 }
792 }
793
794 fs->lfs_ronly = 0;
795 if (fs->lfs_pflags & LFS_PF_CLEAN) {
796 fs->lfs_pflags &= ~LFS_PF_CLEAN;
797 lfs_writesuper(fs, fs->lfs_sboffs[0]);
798 lfs_writesuper(fs, fs->lfs_sboffs[1]);
799 }
800 }
801 if (args->fspec == NULL)
802 return EINVAL;
803 }
804
805 error = set_statvfs_info(path, UIO_USERSPACE, args->fspec,
806 UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l);
807 if (error == 0)
808 (void)strncpy(fs->lfs_fsmnt, mp->mnt_stat.f_mntonname,
809 sizeof(fs->lfs_fsmnt));
810 return error;
811
812 fail:
813 vrele(devvp);
814 return (error);
815 }
816
817
818 /*
819 * Common code for mount and mountroot
820 * LFS specific
821 */
822 int
823 lfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l)
824 {
825 struct dlfs *tdfs, *dfs, *adfs;
826 struct lfs *fs;
827 struct ulfsmount *ump;
828 struct vnode *vp;
829 struct buf *bp, *abp;
830 dev_t dev;
831 int error, i, ronly, fsbsize;
832 kauth_cred_t cred;
833 CLEANERINFO *cip;
834 SEGUSE *sup;
835 daddr_t sb_addr;
836
837 cred = l ? l->l_cred : NOCRED;
838
839 /*
840 * Flush out any old buffers remaining from a previous use.
841 */
842 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
843 error = vinvalbuf(devvp, V_SAVE, cred, l, 0, 0);
844 VOP_UNLOCK(devvp);
845 if (error)
846 return (error);
847
848 ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
849
850 /* Don't free random space on error. */
851 bp = NULL;
852 abp = NULL;
853 ump = NULL;
854
855 sb_addr = LFS_LABELPAD / DEV_BSIZE;
856 while (1) {
857 /* Read in the superblock. */
858 error = bread(devvp, sb_addr, LFS_SBPAD, 0, &bp);
859 if (error)
860 goto out;
861 dfs = (struct dlfs *)bp->b_data;
862
863 /* Check the basics. */
864 if (dfs->dlfs_magic != LFS_MAGIC || dfs->dlfs_bsize > MAXBSIZE ||
865 dfs->dlfs_version > LFS_VERSION ||
866 dfs->dlfs_bsize < sizeof(struct dlfs)) {
867 DLOG((DLOG_MOUNT, "lfs_mountfs: primary superblock sanity failed\n"));
868 error = EINVAL; /* XXX needs translation */
869 goto out;
870 }
871 if (dfs->dlfs_inodefmt > LFS_MAXINODEFMT) {
872 DLOG((DLOG_MOUNT, "lfs_mountfs: unknown inode format %d\n",
873 dfs->dlfs_inodefmt));
874 error = EINVAL;
875 goto out;
876 }
877
878 if (dfs->dlfs_version == 1)
879 fsbsize = DEV_BSIZE;
880 else {
881 fsbsize = 1 << dfs->dlfs_ffshift;
882 /*
883 * Could be, if the frag size is large enough, that we
884 * don't have the "real" primary superblock. If that's
885 * the case, get the real one, and try again.
886 */
887 if (sb_addr != (dfs->dlfs_sboffs[0] << (dfs->dlfs_ffshift - DEV_BSHIFT))) {
888 DLOG((DLOG_MOUNT, "lfs_mountfs: sb daddr"
889 " 0x%llx is not right, trying 0x%llx\n",
890 (long long)sb_addr,
891 (long long)(dfs->dlfs_sboffs[0] << (dfs->dlfs_ffshift - DEV_BSHIFT))));
892 sb_addr = dfs->dlfs_sboffs[0] << (dfs->dlfs_ffshift - DEV_BSHIFT);
893 brelse(bp, 0);
894 continue;
895 }
896 }
897 break;
898 }
899
900 /*
901 * Check the second superblock to see which is newer; then mount
902 * using the older of the two. This is necessary to ensure that
903 * the filesystem is valid if it was not unmounted cleanly.
904 */
905
906 if (dfs->dlfs_sboffs[1] &&
907 dfs->dlfs_sboffs[1] - LFS_LABELPAD / fsbsize > LFS_SBPAD / fsbsize)
908 {
909 error = bread(devvp, dfs->dlfs_sboffs[1] * (fsbsize / DEV_BSIZE),
910 LFS_SBPAD, 0, &abp);
911 if (error)
912 goto out;
913 adfs = (struct dlfs *)abp->b_data;
914
915 if (dfs->dlfs_version == 1) {
916 /* 1s resolution comparison */
917 if (adfs->dlfs_tstamp < dfs->dlfs_tstamp)
918 tdfs = adfs;
919 else
920 tdfs = dfs;
921 } else {
922 /* monotonic infinite-resolution comparison */
923 if (adfs->dlfs_serial < dfs->dlfs_serial)
924 tdfs = adfs;
925 else
926 tdfs = dfs;
927 }
928
929 /* Check the basics. */
930 if (tdfs->dlfs_magic != LFS_MAGIC ||
931 tdfs->dlfs_bsize > MAXBSIZE ||
932 tdfs->dlfs_version > LFS_VERSION ||
933 tdfs->dlfs_bsize < sizeof(struct dlfs)) {
934 DLOG((DLOG_MOUNT, "lfs_mountfs: alt superblock"
935 " sanity failed\n"));
936 error = EINVAL; /* XXX needs translation */
937 goto out;
938 }
939 } else {
940 DLOG((DLOG_MOUNT, "lfs_mountfs: invalid alt superblock"
941 " daddr=0x%x\n", dfs->dlfs_sboffs[1]));
942 error = EINVAL;
943 goto out;
944 }
945
946 /* Allocate the mount structure, copy the superblock into it. */
947 fs = kmem_zalloc(sizeof(struct lfs), KM_SLEEP);
948 memcpy(&fs->lfs_dlfs, tdfs, sizeof(struct dlfs));
949
950 /* Compatibility */
951 if (fs->lfs_version < 2) {
952 fs->lfs_sumsize = LFS_V1_SUMMARY_SIZE;
953 fs->lfs_ibsize = fs->lfs_bsize;
954 fs->lfs_s0addr = fs->lfs_sboffs[0];
955 fs->lfs_tstamp = fs->lfs_otstamp;
956 fs->lfs_fsbtodb = 0;
957 }
958 if (fs->lfs_resvseg == 0)
959 fs->lfs_resvseg = MIN(fs->lfs_minfreeseg - 1, \
960 MAX(MIN_RESV_SEGS, fs->lfs_minfreeseg / 2 + 1));
961
962 /*
963 * If we aren't going to be able to write meaningfully to this
964 * filesystem, and were not mounted readonly, bomb out now.
965 */
966 if (lfs_fsbtob(fs, LFS_NRESERVE(fs)) > LFS_MAX_BYTES && !ronly) {
967 DLOG((DLOG_MOUNT, "lfs_mount: to mount this filesystem read/write,"
968 " we need BUFPAGES >= %lld\n",
969 (long long)((bufmem_hiwater / bufmem_lowater) *
970 LFS_INVERSE_MAX_BYTES(
971 lfs_fsbtob(fs, LFS_NRESERVE(fs))) >> PAGE_SHIFT)));
972 kmem_free(fs, sizeof(struct lfs));
973 error = EFBIG; /* XXX needs translation */
974 goto out;
975 }
976
977 /* Before rolling forward, lock so vget will sleep for other procs */
978 if (l != NULL) {
979 fs->lfs_flags = LFS_NOTYET;
980 fs->lfs_rfpid = l->l_proc->p_pid;
981 }
982
983 ump = kmem_zalloc(sizeof(*ump), KM_SLEEP);
984 ump->um_lfs = fs;
985 ump->um_fstype = ULFS1;
986 if (sizeof(struct lfs) < LFS_SBPAD) { /* XXX why? */
987 brelse(bp, BC_INVAL);
988 brelse(abp, BC_INVAL);
989 } else {
990 brelse(bp, 0);
991 brelse(abp, 0);
992 }
993 bp = NULL;
994 abp = NULL;
995
996
997 /* Set up the I/O information */
998 fs->lfs_devbsize = DEV_BSIZE;
999 fs->lfs_iocount = 0;
1000 fs->lfs_diropwait = 0;
1001 fs->lfs_activesb = 0;
1002 fs->lfs_uinodes = 0;
1003 fs->lfs_ravail = 0;
1004 fs->lfs_favail = 0;
1005 fs->lfs_sbactive = 0;
1006
1007 /* Set up the ifile and lock aflags */
1008 fs->lfs_doifile = 0;
1009 fs->lfs_writer = 0;
1010 fs->lfs_dirops = 0;
1011 fs->lfs_nadirop = 0;
1012 fs->lfs_seglock = 0;
1013 fs->lfs_pdflush = 0;
1014 fs->lfs_sleepers = 0;
1015 fs->lfs_pages = 0;
1016 rw_init(&fs->lfs_fraglock);
1017 rw_init(&fs->lfs_iflock);
1018 cv_init(&fs->lfs_stopcv, "lfsstop");
1019
1020 /* Set the file system readonly/modify bits. */
1021 fs->lfs_ronly = ronly;
1022 if (ronly == 0)
1023 fs->lfs_fmod = 1;
1024
1025 /* ulfs-level information */
1026 fs->um_flags = 0;
1027 fs->um_bptrtodb = fs->lfs_ffshift - DEV_BSHIFT;
1028 fs->um_seqinc = fs->lfs_frag;
1029 fs->um_nindir = fs->lfs_nindir;
1030 fs->um_lognindir = ffs(fs->lfs_nindir) - 1;
1031 fs->um_maxsymlinklen = fs->lfs_maxsymlinklen;
1032 fs->um_dirblksiz = LFS_DIRBLKSIZ;
1033 fs->um_maxfilesize = fs->lfs_maxfilesize;
1034
1035 /* quota stuff */
1036 /* XXX: these need to come from the on-disk superblock to be used */
1037 fs->lfs_use_quota2 = 0;
1038 fs->lfs_quota_magic = 0;
1039 fs->lfs_quota_flags = 0;
1040 fs->lfs_quotaino[0] = 0;
1041 fs->lfs_quotaino[1] = 0;
1042
1043 /* Initialize the mount structure. */
1044 dev = devvp->v_rdev;
1045 mp->mnt_data = ump;
1046 mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
1047 mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_LFS);
1048 mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
1049 mp->mnt_stat.f_namemax = LFS_MAXNAMLEN;
1050 mp->mnt_stat.f_iosize = fs->lfs_bsize;
1051 mp->mnt_flag |= MNT_LOCAL;
1052 mp->mnt_fs_bshift = fs->lfs_bshift;
1053 if (fs->um_maxsymlinklen > 0)
1054 mp->mnt_iflag |= IMNT_DTYPE;
1055
1056 ump->um_mountp = mp;
1057 ump->um_dev = dev;
1058 ump->um_devvp = devvp;
1059 for (i = 0; i < ULFS_MAXQUOTAS; i++)
1060 ump->um_quotas[i] = NULLVP;
1061 spec_node_setmountedfs(devvp, mp);
1062
1063 /* Set up reserved memory for pageout */
1064 lfs_setup_resblks(fs);
1065 /* Set up vdirop tailq */
1066 TAILQ_INIT(&fs->lfs_dchainhd);
1067 /* and paging tailq */
1068 TAILQ_INIT(&fs->lfs_pchainhd);
1069 /* and delayed segment accounting for truncation list */
1070 LIST_INIT(&fs->lfs_segdhd);
1071
1072 /*
1073 * We use the ifile vnode for almost every operation. Instead of
1074 * retrieving it from the hash table each time we retrieve it here,
1075 * artificially increment the reference count and keep a pointer
1076 * to it in the incore copy of the superblock.
1077 */
1078 if ((error = VFS_VGET(mp, LFS_IFILE_INUM, &vp)) != 0) {
1079 DLOG((DLOG_MOUNT, "lfs_mountfs: ifile vget failed, error=%d\n", error));
1080 goto out;
1081 }
1082 fs->lfs_ivnode = vp;
1083 vref(vp);
1084
1085 /* Set up inode bitmap and order free list */
1086 lfs_order_freelist(fs);
1087
1088 /* Set up segment usage flags for the autocleaner. */
1089 fs->lfs_nactive = 0;
1090 fs->lfs_suflags = (u_int32_t **)malloc(2 * sizeof(u_int32_t *),
1091 M_SEGMENT, M_WAITOK);
1092 fs->lfs_suflags[0] = (u_int32_t *)malloc(fs->lfs_nseg * sizeof(u_int32_t),
1093 M_SEGMENT, M_WAITOK);
1094 fs->lfs_suflags[1] = (u_int32_t *)malloc(fs->lfs_nseg * sizeof(u_int32_t),
1095 M_SEGMENT, M_WAITOK);
1096 memset(fs->lfs_suflags[1], 0, fs->lfs_nseg * sizeof(u_int32_t));
1097 for (i = 0; i < fs->lfs_nseg; i++) {
1098 int changed;
1099
1100 LFS_SEGENTRY(sup, fs, i, bp);
1101 changed = 0;
1102 if (!ronly) {
1103 if (sup->su_nbytes == 0 &&
1104 !(sup->su_flags & SEGUSE_EMPTY)) {
1105 sup->su_flags |= SEGUSE_EMPTY;
1106 ++changed;
1107 } else if (!(sup->su_nbytes == 0) &&
1108 (sup->su_flags & SEGUSE_EMPTY)) {
1109 sup->su_flags &= ~SEGUSE_EMPTY;
1110 ++changed;
1111 }
1112 if (sup->su_flags & (SEGUSE_ACTIVE|SEGUSE_INVAL)) {
1113 sup->su_flags &= ~(SEGUSE_ACTIVE|SEGUSE_INVAL);
1114 ++changed;
1115 }
1116 }
1117 fs->lfs_suflags[0][i] = sup->su_flags;
1118 if (changed)
1119 LFS_WRITESEGENTRY(sup, fs, i, bp);
1120 else
1121 brelse(bp, 0);
1122 }
1123
1124 /*
1125 * XXX: if the fs has quotas, quotas should be on even if
1126 * readonly. Otherwise you can't query the quota info!
1127 * However, that's not how the quota2 code got written and I
1128 * don't know if it'll behave itself if enabled while
1129 * readonly, so for now use the same enable logic as ffs.
1130 *
1131 * XXX: also, if you use the -f behavior allowed here (and
1132 * equivalently above for remount) it will corrupt the fs. It
1133 * ought not to allow that. It should allow mounting readonly
1134 * if there are quotas and the kernel doesn't have the quota
1135 * code, but only readonly.
1136 *
1137 * XXX: and if you use the -f behavior allowed here it will
1138 * likely crash at unmount time (or remount time) because we
1139 * think quotas are active.
1140 *
1141 * Although none of this applies until there's a way to set
1142 * lfs_use_quota2 and have quotas in the fs at all.
1143 */
1144 if (!ronly && fs->lfs_use_quota2) {
1145 #ifdef LFS_QUOTA2
1146 error = lfs_quota2_mount(mp);
1147 #else
1148 uprintf("%s: no kernel support for this filesystem's quotas\n",
1149 mp->mnt_stat.f_mntonname);
1150 if (mp->mnt_flag & MNT_FORCE) {
1151 uprintf("%s: mounting anyway; fsck afterwards\n",
1152 mp->mnt_stat.f_mntonname);
1153 } else {
1154 error = EINVAL;
1155 }
1156 #endif
1157 if (error) {
1158 /* XXX XXX must clean up the stuff immediately above */
1159 printf("lfs_mountfs: sorry, leaking some memory\n");
1160 goto out;
1161 }
1162 }
1163
1164 #ifdef LFS_EXTATTR
1165 /*
1166 * Initialize file-backed extended attributes for ULFS1 file
1167 * systems.
1168 *
1169 * XXX: why is this limited to ULFS1?
1170 */
1171 if (ump->um_fstype == ULFS1) {
1172 ulfs_extattr_uepm_init(&ump->um_extattr);
1173 }
1174 #endif
1175
1176 #ifdef LFS_KERNEL_RFW
1177 lfs_roll_forward(fs, mp, l);
1178 #endif
1179
1180 /* If writing, sb is not clean; record in case of immediate crash */
1181 if (!fs->lfs_ronly) {
1182 fs->lfs_pflags &= ~LFS_PF_CLEAN;
1183 lfs_writesuper(fs, fs->lfs_sboffs[0]);
1184 lfs_writesuper(fs, fs->lfs_sboffs[1]);
1185 }
1186
1187 /* Allow vget now that roll-forward is complete */
1188 fs->lfs_flags &= ~(LFS_NOTYET);
1189 wakeup(&fs->lfs_flags);
1190
1191 /*
1192 * Initialize the ifile cleaner info with information from
1193 * the superblock.
1194 */
1195 LFS_CLEANERINFO(cip, fs, bp);
1196 cip->clean = fs->lfs_nclean;
1197 cip->dirty = fs->lfs_nseg - fs->lfs_nclean;
1198 cip->avail = fs->lfs_avail;
1199 cip->bfree = fs->lfs_bfree;
1200 (void) LFS_BWRITE_LOG(bp); /* Ifile */
1201
1202 /*
1203 * Mark the current segment as ACTIVE, since we're going to
1204 * be writing to it.
1205 */
1206 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, fs->lfs_offset), bp);
1207 sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
1208 fs->lfs_nactive++;
1209 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, fs->lfs_offset), bp); /* Ifile */
1210
1211 /* Now that roll-forward is done, unlock the Ifile */
1212 vput(vp);
1213
1214 /* Start the pagedaemon-anticipating daemon */
1215 mutex_enter(&lfs_lock);
1216 if (lfs_writer_daemon == 0 && lfs_writer_lid == 0 &&
1217 kthread_create(PRI_BIO, 0, NULL,
1218 lfs_writerd, NULL, NULL, "lfs_writer") != 0)
1219 panic("fork lfs_writer");
1220 mutex_exit(&lfs_lock);
1221
1222 printf("WARNING: the log-structured file system is experimental\n"
1223 "WARNING: it may cause system crashes and/or corrupt data\n");
1224
1225 return (0);
1226
1227 out:
1228 if (bp)
1229 brelse(bp, 0);
1230 if (abp)
1231 brelse(abp, 0);
1232 if (ump) {
1233 kmem_free(ump->um_lfs, sizeof(struct lfs));
1234 kmem_free(ump, sizeof(*ump));
1235 mp->mnt_data = NULL;
1236 }
1237
1238 return (error);
1239 }
1240
1241 /*
1242 * unmount system call
1243 */
1244 int
1245 lfs_unmount(struct mount *mp, int mntflags)
1246 {
1247 struct lwp *l = curlwp;
1248 struct ulfsmount *ump;
1249 struct lfs *fs;
1250 int error, flags, ronly;
1251 vnode_t *vp;
1252
1253 flags = 0;
1254 if (mntflags & MNT_FORCE)
1255 flags |= FORCECLOSE;
1256
1257 ump = VFSTOULFS(mp);
1258 fs = ump->um_lfs;
1259
1260 /* Two checkpoints */
1261 lfs_segwrite(mp, SEGM_CKP | SEGM_SYNC);
1262 lfs_segwrite(mp, SEGM_CKP | SEGM_SYNC);
1263
1264 /* wake up the cleaner so it can die */
1265 /* XXX: shouldn't this be *after* the error cases below? */
1266 lfs_wakeup_cleaner(fs);
1267 mutex_enter(&lfs_lock);
1268 while (fs->lfs_sleepers)
1269 mtsleep(&fs->lfs_sleepers, PRIBIO + 1, "lfs_sleepers", 0,
1270 &lfs_lock);
1271 mutex_exit(&lfs_lock);
1272
1273 #ifdef LFS_EXTATTR
1274 if (ump->um_fstype == ULFS1) {
1275 if (ump->um_extattr.uepm_flags & ULFS_EXTATTR_UEPM_STARTED) {
1276 ulfs_extattr_stop(mp, curlwp);
1277 }
1278 if (ump->um_extattr.uepm_flags & ULFS_EXTATTR_UEPM_INITIALIZED) {
1279 ulfs_extattr_uepm_destroy(&ump->um_extattr);
1280 }
1281 }
1282 #endif
1283 #ifdef LFS_QUOTA
1284 if ((error = lfsquota1_umount(mp, flags)) != 0)
1285 return (error);
1286 #endif
1287 #ifdef LFS_QUOTA2
1288 if ((error = lfsquota2_umount(mp, flags)) != 0)
1289 return (error);
1290 #endif
1291 if ((error = vflush(mp, fs->lfs_ivnode, flags)) != 0)
1292 return (error);
1293 if ((error = VFS_SYNC(mp, 1, l->l_cred)) != 0)
1294 return (error);
1295 vp = fs->lfs_ivnode;
1296 mutex_enter(vp->v_interlock);
1297 if (LIST_FIRST(&vp->v_dirtyblkhd))
1298 panic("lfs_unmount: still dirty blocks on ifile vnode");
1299 mutex_exit(vp->v_interlock);
1300
1301 /* Explicitly write the superblock, to update serial and pflags */
1302 fs->lfs_pflags |= LFS_PF_CLEAN;
1303 lfs_writesuper(fs, fs->lfs_sboffs[0]);
1304 lfs_writesuper(fs, fs->lfs_sboffs[1]);
1305 mutex_enter(&lfs_lock);
1306 while (fs->lfs_iocount)
1307 mtsleep(&fs->lfs_iocount, PRIBIO + 1, "lfs_umount", 0,
1308 &lfs_lock);
1309 mutex_exit(&lfs_lock);
1310
1311 /* Finish with the Ifile, now that we're done with it */
1312 vgone(fs->lfs_ivnode);
1313
1314 ronly = !fs->lfs_ronly;
1315 if (ump->um_devvp->v_type != VBAD)
1316 spec_node_setmountedfs(ump->um_devvp, NULL);
1317 vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY);
1318 error = VOP_CLOSE(ump->um_devvp,
1319 ronly ? FREAD : FREAD|FWRITE, NOCRED);
1320 vput(ump->um_devvp);
1321
1322 /* Complain about page leakage */
1323 if (fs->lfs_pages > 0)
1324 printf("lfs_unmount: still claim %d pages (%d in subsystem)\n",
1325 fs->lfs_pages, lfs_subsys_pages);
1326
1327 /* Free per-mount data structures */
1328 free(fs->lfs_ino_bitmap, M_SEGMENT);
1329 free(fs->lfs_suflags[0], M_SEGMENT);
1330 free(fs->lfs_suflags[1], M_SEGMENT);
1331 free(fs->lfs_suflags, M_SEGMENT);
1332 lfs_free_resblks(fs);
1333 cv_destroy(&fs->lfs_stopcv);
1334 rw_destroy(&fs->lfs_fraglock);
1335 rw_destroy(&fs->lfs_iflock);
1336
1337 kmem_free(fs, sizeof(struct lfs));
1338 kmem_free(ump, sizeof(*ump));
1339
1340 mp->mnt_data = NULL;
1341 mp->mnt_flag &= ~MNT_LOCAL;
1342 return (error);
1343 }
1344
1345 /*
1346 * Get file system statistics.
1347 *
1348 * NB: We don't lock to access the superblock here, because it's not
1349 * really that important if we get it wrong.
1350 */
1351 int
1352 lfs_statvfs(struct mount *mp, struct statvfs *sbp)
1353 {
1354 struct lfs *fs;
1355 struct ulfsmount *ump;
1356
1357 ump = VFSTOULFS(mp);
1358 fs = ump->um_lfs;
1359 if (fs->lfs_magic != LFS_MAGIC)
1360 panic("lfs_statvfs: magic");
1361
1362 sbp->f_bsize = fs->lfs_bsize;
1363 sbp->f_frsize = fs->lfs_fsize;
1364 sbp->f_iosize = fs->lfs_bsize;
1365 sbp->f_blocks = LFS_EST_NONMETA(fs) - VTOI(fs->lfs_ivnode)->i_lfs_effnblks;
1366
1367 sbp->f_bfree = LFS_EST_BFREE(fs);
1368 KASSERT(sbp->f_bfree <= fs->lfs_dsize);
1369 #if 0
1370 if (sbp->f_bfree < 0)
1371 sbp->f_bfree = 0;
1372 #endif
1373
1374 sbp->f_bresvd = LFS_EST_RSVD(fs);
1375 if (sbp->f_bfree > sbp->f_bresvd)
1376 sbp->f_bavail = sbp->f_bfree - sbp->f_bresvd;
1377 else
1378 sbp->f_bavail = 0;
1379
1380 sbp->f_files = fs->lfs_bfree / lfs_btofsb(fs, fs->lfs_ibsize)
1381 * LFS_INOPB(fs);
1382 sbp->f_ffree = sbp->f_files - fs->lfs_nfiles;
1383 sbp->f_favail = sbp->f_ffree;
1384 sbp->f_fresvd = 0;
1385 copy_statvfs_info(sbp, mp);
1386 return (0);
1387 }
1388
1389 /*
1390 * Go through the disk queues to initiate sandbagged IO;
1391 * go through the inodes to write those that have been modified;
1392 * initiate the writing of the super block if it has been modified.
1393 *
1394 * Note: we are always called with the filesystem marked `MPBUSY'.
1395 */
1396 int
1397 lfs_sync(struct mount *mp, int waitfor, kauth_cred_t cred)
1398 {
1399 int error;
1400 struct lfs *fs;
1401
1402 fs = VFSTOULFS(mp)->um_lfs;
1403 if (fs->lfs_ronly)
1404 return 0;
1405
1406 /* Snapshots should not hose the syncer */
1407 /*
1408 * XXX Sync can block here anyway, since we don't have a very
1409 * XXX good idea of how much data is pending. If it's more
1410 * XXX than a segment and lfs_nextseg is close to the end of
1411 * XXX the log, we'll likely block.
1412 */
1413 mutex_enter(&lfs_lock);
1414 if (fs->lfs_nowrap && fs->lfs_nextseg < fs->lfs_curseg) {
1415 mutex_exit(&lfs_lock);
1416 return 0;
1417 }
1418 mutex_exit(&lfs_lock);
1419
1420 lfs_writer_enter(fs, "lfs_dirops");
1421
1422 /* All syncs must be checkpoints until roll-forward is implemented. */
1423 DLOG((DLOG_FLUSH, "lfs_sync at 0x%x\n", fs->lfs_offset));
1424 error = lfs_segwrite(mp, SEGM_CKP | (waitfor ? SEGM_SYNC : 0));
1425 lfs_writer_leave(fs);
1426 #ifdef LFS_QUOTA
1427 lfs_qsync(mp);
1428 #endif
1429 return (error);
1430 }
1431
1432 /*
1433 * Look up an LFS dinode number to find its incore vnode. If not already
1434 * in core, read it in from the specified device. Return the inode locked.
1435 * Detection and handling of mount points must be done by the calling routine.
1436 */
1437 int
1438 lfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
1439 {
1440 struct lfs *fs;
1441 struct ulfs1_dinode *dip;
1442 struct inode *ip;
1443 struct buf *bp;
1444 struct ifile *ifp;
1445 struct vnode *vp;
1446 struct ulfsmount *ump;
1447 daddr_t daddr;
1448 dev_t dev;
1449 int error, retries;
1450 struct timespec ts;
1451
1452 memset(&ts, 0, sizeof ts); /* XXX gcc */
1453
1454 ump = VFSTOULFS(mp);
1455 dev = ump->um_dev;
1456 fs = ump->um_lfs;
1457
1458 /*
1459 * If the filesystem is not completely mounted yet, suspend
1460 * any access requests (wait for roll-forward to complete).
1461 */
1462 mutex_enter(&lfs_lock);
1463 while ((fs->lfs_flags & LFS_NOTYET) && curproc->p_pid != fs->lfs_rfpid)
1464 mtsleep(&fs->lfs_flags, PRIBIO+1, "lfs_notyet", 0,
1465 &lfs_lock);
1466 mutex_exit(&lfs_lock);
1467
1468 retry:
1469 if ((*vpp = ulfs_ihashget(dev, ino, LK_EXCLUSIVE)) != NULL)
1470 return (0);
1471
1472 error = getnewvnode(VT_LFS, mp, lfs_vnodeop_p, NULL, &vp);
1473 if (error) {
1474 *vpp = NULL;
1475 return (error);
1476 }
1477
1478 mutex_enter(&ulfs_hashlock);
1479 if (ulfs_ihashget(dev, ino, 0) != NULL) {
1480 mutex_exit(&ulfs_hashlock);
1481 ungetnewvnode(vp);
1482 goto retry;
1483 }
1484
1485 /* Translate the inode number to a disk address. */
1486 if (ino == LFS_IFILE_INUM)
1487 daddr = fs->lfs_idaddr;
1488 else {
1489 /* XXX bounds-check this too */
1490 LFS_IENTRY(ifp, fs, ino, bp);
1491 daddr = ifp->if_daddr;
1492 if (fs->lfs_version > 1) {
1493 ts.tv_sec = ifp->if_atime_sec;
1494 ts.tv_nsec = ifp->if_atime_nsec;
1495 }
1496
1497 brelse(bp, 0);
1498 if (daddr == LFS_UNUSED_DADDR) {
1499 *vpp = NULLVP;
1500 mutex_exit(&ulfs_hashlock);
1501 ungetnewvnode(vp);
1502 return (ENOENT);
1503 }
1504 }
1505
1506 /* Allocate/init new vnode/inode. */
1507 lfs_vcreate(mp, ino, vp);
1508
1509 /*
1510 * Put it onto its hash chain and lock it so that other requests for
1511 * this inode will block if they arrive while we are sleeping waiting
1512 * for old data structures to be purged or for the contents of the
1513 * disk portion of this inode to be read.
1514 */
1515 ip = VTOI(vp);
1516 ulfs_ihashins(ip);
1517 mutex_exit(&ulfs_hashlock);
1518
1519 /*
1520 * XXX
1521 * This may not need to be here, logically it should go down with
1522 * the i_devvp initialization.
1523 * Ask Kirk.
1524 */
1525 ip->i_lfs = ump->um_lfs;
1526
1527 /* Read in the disk contents for the inode, copy into the inode. */
1528 retries = 0;
1529 again:
1530 error = bread(ump->um_devvp, LFS_FSBTODB(fs, daddr),
1531 (fs->lfs_version == 1 ? fs->lfs_bsize : fs->lfs_ibsize),
1532 0, &bp);
1533 if (error) {
1534 /*
1535 * The inode does not contain anything useful, so it would
1536 * be misleading to leave it on its hash chain. With mode
1537 * still zero, it will be unlinked and returned to the free
1538 * list by vput().
1539 */
1540 vput(vp);
1541 *vpp = NULL;
1542 return (error);
1543 }
1544
1545 dip = lfs_ifind(fs, ino, bp);
1546 if (dip == NULL) {
1547 /* Assume write has not completed yet; try again */
1548 brelse(bp, BC_INVAL);
1549 ++retries;
1550 if (retries > LFS_IFIND_RETRIES) {
1551 #ifdef DEBUG
1552 /* If the seglock is held look at the bpp to see
1553 what is there anyway */
1554 mutex_enter(&lfs_lock);
1555 if (fs->lfs_seglock > 0) {
1556 struct buf **bpp;
1557 struct ulfs1_dinode *dp;
1558 int i;
1559
1560 for (bpp = fs->lfs_sp->bpp;
1561 bpp != fs->lfs_sp->cbpp; ++bpp) {
1562 if ((*bpp)->b_vp == fs->lfs_ivnode &&
1563 bpp != fs->lfs_sp->bpp) {
1564 /* Inode block */
1565 printf("lfs_vget: block 0x%" PRIx64 ": ",
1566 (*bpp)->b_blkno);
1567 dp = (struct ulfs1_dinode *)(*bpp)->b_data;
1568 for (i = 0; i < LFS_INOPB(fs); i++)
1569 if (dp[i].di_inumber)
1570 printf("%d ", dp[i].di_inumber);
1571 printf("\n");
1572 }
1573 }
1574 }
1575 mutex_exit(&lfs_lock);
1576 #endif /* DEBUG */
1577 panic("lfs_vget: dinode not found");
1578 }
1579 mutex_enter(&lfs_lock);
1580 if (fs->lfs_iocount) {
1581 DLOG((DLOG_VNODE, "lfs_vget: dinode %d not found, retrying...\n", ino));
1582 (void)mtsleep(&fs->lfs_iocount, PRIBIO + 1,
1583 "lfs ifind", 1, &lfs_lock);
1584 } else
1585 retries = LFS_IFIND_RETRIES;
1586 mutex_exit(&lfs_lock);
1587 goto again;
1588 }
1589 *ip->i_din.ffs1_din = *dip;
1590 brelse(bp, 0);
1591
1592 if (fs->lfs_version > 1) {
1593 ip->i_ffs1_atime = ts.tv_sec;
1594 ip->i_ffs1_atimensec = ts.tv_nsec;
1595 }
1596
1597 lfs_vinit(mp, &vp);
1598
1599 *vpp = vp;
1600
1601 KASSERT(VOP_ISLOCKED(vp));
1602
1603 return (0);
1604 }
1605
1606 /*
1607 * File handle to vnode
1608 */
1609 int
1610 lfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
1611 {
1612 struct lfid lfh;
1613 struct buf *bp;
1614 IFILE *ifp;
1615 int32_t daddr;
1616 struct lfs *fs;
1617 vnode_t *vp;
1618
1619 if (fhp->fid_len != sizeof(struct lfid))
1620 return EINVAL;
1621
1622 memcpy(&lfh, fhp, sizeof(lfh));
1623 if (lfh.lfid_ino < LFS_IFILE_INUM)
1624 return ESTALE;
1625
1626 fs = VFSTOULFS(mp)->um_lfs;
1627 if (lfh.lfid_ident != fs->lfs_ident)
1628 return ESTALE;
1629
1630 if (lfh.lfid_ino >
1631 ((VTOI(fs->lfs_ivnode)->i_ffs1_size >> fs->lfs_bshift) -
1632 fs->lfs_cleansz - fs->lfs_segtabsz) * fs->lfs_ifpb)
1633 return ESTALE;
1634
1635 mutex_enter(&ulfs_ihash_lock);
1636 vp = ulfs_ihashlookup(VFSTOULFS(mp)->um_dev, lfh.lfid_ino);
1637 mutex_exit(&ulfs_ihash_lock);
1638 if (vp == NULL) {
1639 LFS_IENTRY(ifp, fs, lfh.lfid_ino, bp);
1640 daddr = ifp->if_daddr;
1641 brelse(bp, 0);
1642 if (daddr == LFS_UNUSED_DADDR)
1643 return ESTALE;
1644 }
1645
1646 return (ulfs_fhtovp(mp, &lfh.lfid_ufid, vpp));
1647 }
1648
1649 /*
1650 * Vnode pointer to File handle
1651 */
1652 /* ARGSUSED */
1653 int
1654 lfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
1655 {
1656 struct inode *ip;
1657 struct lfid lfh;
1658
1659 if (*fh_size < sizeof(struct lfid)) {
1660 *fh_size = sizeof(struct lfid);
1661 return E2BIG;
1662 }
1663 *fh_size = sizeof(struct lfid);
1664 ip = VTOI(vp);
1665 memset(&lfh, 0, sizeof(lfh));
1666 lfh.lfid_len = sizeof(struct lfid);
1667 lfh.lfid_ino = ip->i_number;
1668 lfh.lfid_gen = ip->i_gen;
1669 lfh.lfid_ident = ip->i_lfs->lfs_ident;
1670 memcpy(fhp, &lfh, sizeof(lfh));
1671 return (0);
1672 }
1673
1674 /*
1675 * ulfs_bmaparray callback function for writing.
1676 *
1677 * Since blocks will be written to the new segment anyway,
1678 * we don't care about current daddr of them.
1679 */
1680 static bool
1681 lfs_issequential_hole(const struct lfs *fs,
1682 daddr_t daddr0, daddr_t daddr1)
1683 {
1684 (void)fs; /* not used */
1685
1686 daddr0 = (daddr_t)((int32_t)daddr0); /* XXX ondisk32 */
1687 daddr1 = (daddr_t)((int32_t)daddr1); /* XXX ondisk32 */
1688
1689 KASSERT(daddr0 == UNWRITTEN ||
1690 (0 <= daddr0 && daddr0 <= LFS_MAX_DADDR));
1691 KASSERT(daddr1 == UNWRITTEN ||
1692 (0 <= daddr1 && daddr1 <= LFS_MAX_DADDR));
1693
1694 /* NOTE: all we want to know here is 'hole or not'. */
1695 /* NOTE: UNASSIGNED is converted to 0 by ulfs_bmaparray. */
1696
1697 /*
1698 * treat UNWRITTENs and all resident blocks as 'contiguous'
1699 */
1700 if (daddr0 != 0 && daddr1 != 0)
1701 return true;
1702
1703 /*
1704 * both are in hole?
1705 */
1706 if (daddr0 == 0 && daddr1 == 0)
1707 return true; /* all holes are 'contiguous' for us. */
1708
1709 return false;
1710 }
1711
1712 /*
1713 * lfs_gop_write functions exactly like genfs_gop_write, except that
1714 * (1) it requires the seglock to be held by its caller, and sp->fip
1715 * to be properly initialized (it will return without re-initializing
1716 * sp->fip, and without calling lfs_writeseg).
1717 * (2) it uses the remaining space in the segment, rather than VOP_BMAP,
1718 * to determine how large a block it can write at once (though it does
1719 * still use VOP_BMAP to find holes in the file);
1720 * (3) it calls lfs_gatherblock instead of VOP_STRATEGY on its blocks
1721 * (leaving lfs_writeseg to deal with the cluster blocks, so we might
1722 * now have clusters of clusters, ick.)
1723 */
1724 static int
1725 lfs_gop_write(struct vnode *vp, struct vm_page **pgs, int npages,
1726 int flags)
1727 {
1728 int i, error, run, haveeof = 0;
1729 int fs_bshift;
1730 vaddr_t kva;
1731 off_t eof, offset, startoffset = 0;
1732 size_t bytes, iobytes, skipbytes;
1733 bool async = (flags & PGO_SYNCIO) == 0;
1734 daddr_t lbn, blkno;
1735 struct vm_page *pg;
1736 struct buf *mbp, *bp;
1737 struct vnode *devvp = VTOI(vp)->i_devvp;
1738 struct inode *ip = VTOI(vp);
1739 struct lfs *fs = ip->i_lfs;
1740 struct segment *sp = fs->lfs_sp;
1741 UVMHIST_FUNC("lfs_gop_write"); UVMHIST_CALLED(ubchist);
1742 const char * failreason = NULL;
1743
1744 ASSERT_SEGLOCK(fs);
1745
1746 /* The Ifile lives in the buffer cache */
1747 KASSERT(vp != fs->lfs_ivnode);
1748
1749 /*
1750 * We don't want to fill the disk before the cleaner has a chance
1751 * to make room for us. If we're in danger of doing that, fail
1752 * with EAGAIN. The caller will have to notice this, unlock
1753 * so the cleaner can run, relock and try again.
1754 *
1755 * We must write everything, however, if our vnode is being
1756 * reclaimed.
1757 */
1758 mutex_enter(vp->v_interlock);
1759 if (LFS_STARVED_FOR_SEGS(fs) && vdead_check(vp, VDEAD_NOWAIT) == 0) {
1760 mutex_exit(vp->v_interlock);
1761 failreason = "Starved for segs and not flushing vp";
1762 goto tryagain;
1763 }
1764 mutex_exit(vp->v_interlock);
1765
1766 /*
1767 * Sometimes things slip past the filters in lfs_putpages,
1768 * and the pagedaemon tries to write pages---problem is
1769 * that the pagedaemon never acquires the segment lock.
1770 *
1771 * Alternatively, pages that were clean when we called
1772 * genfs_putpages may have become dirty in the meantime. In this
1773 * case the segment header is not properly set up for blocks
1774 * to be added to it.
1775 *
1776 * Unbusy and unclean the pages, and put them on the ACTIVE
1777 * queue under the hypothesis that they couldn't have got here
1778 * unless they were modified *quite* recently.
1779 *
1780 * XXXUBC that last statement is an oversimplification of course.
1781 */
1782 if (!LFS_SEGLOCK_HELD(fs)) {
1783 failreason = "Seglock not held";
1784 goto tryagain;
1785 }
1786 if (ip->i_lfs_iflags & LFSI_NO_GOP_WRITE) {
1787 failreason = "Inode with no_gop_write";
1788 goto tryagain;
1789 }
1790 if ((pgs[0]->offset & fs->lfs_bmask) != 0) {
1791 failreason = "Bad page offset";
1792 goto tryagain;
1793 }
1794
1795 UVMHIST_LOG(ubchist, "vp %p pgs %p npages %d flags 0x%x",
1796 vp, pgs, npages, flags);
1797
1798 GOP_SIZE(vp, vp->v_size, &eof, 0);
1799 haveeof = 1;
1800
1801 if (vp->v_type == VREG)
1802 fs_bshift = vp->v_mount->mnt_fs_bshift;
1803 else
1804 fs_bshift = DEV_BSHIFT;
1805 error = 0;
1806 pg = pgs[0];
1807 startoffset = pg->offset;
1808 KASSERT(eof >= 0);
1809
1810 if (startoffset >= eof) {
1811 failreason = "Offset beyond EOF";
1812 goto tryagain;
1813 } else
1814 bytes = MIN(npages << PAGE_SHIFT, eof - startoffset);
1815 skipbytes = 0;
1816
1817 KASSERT(bytes != 0);
1818
1819 /* Swap PG_DELWRI for PG_PAGEOUT */
1820 for (i = 0; i < npages; i++) {
1821 if (pgs[i]->flags & PG_DELWRI) {
1822 KASSERT(!(pgs[i]->flags & PG_PAGEOUT));
1823 pgs[i]->flags &= ~PG_DELWRI;
1824 pgs[i]->flags |= PG_PAGEOUT;
1825 uvm_pageout_start(1);
1826 mutex_enter(vp->v_interlock);
1827 mutex_enter(&uvm_pageqlock);
1828 uvm_pageunwire(pgs[i]);
1829 mutex_exit(&uvm_pageqlock);
1830 mutex_exit(vp->v_interlock);
1831 }
1832 }
1833
1834 /*
1835 * Check to make sure we're starting on a block boundary.
1836 * We'll check later to make sure we always write entire
1837 * blocks (or fragments).
1838 */
1839 if (startoffset & fs->lfs_bmask)
1840 printf("%" PRId64 " & %" PRId64 " = %" PRId64 "\n",
1841 startoffset, fs->lfs_bmask,
1842 startoffset & fs->lfs_bmask);
1843 KASSERT((startoffset & fs->lfs_bmask) == 0);
1844 if (bytes & fs->lfs_ffmask) {
1845 printf("lfs_gop_write: asked to write %ld bytes\n", (long)bytes);
1846 panic("lfs_gop_write: non-integer blocks");
1847 }
1848
1849 /*
1850 * We could deadlock here on pager_map with UVMPAGER_MAPIN_WAITOK.
1851 * If we would, write what we have and try again. If we don't
1852 * have anything to write, we'll have to sleep.
1853 */
1854 if ((kva = uvm_pagermapin(pgs, npages, UVMPAGER_MAPIN_WRITE |
1855 (((SEGSUM *)(sp->segsum))->ss_nfinfo < 1 ?
1856 UVMPAGER_MAPIN_WAITOK : 0))) == 0x0) {
1857 DLOG((DLOG_PAGE, "lfs_gop_write: forcing write\n"));
1858 #if 0
1859 " with nfinfo=%d at offset 0x%x\n",
1860 (int)((SEGSUM *)(sp->segsum))->ss_nfinfo,
1861 (unsigned)fs->lfs_offset));
1862 #endif
1863 lfs_updatemeta(sp);
1864 lfs_release_finfo(fs);
1865 (void) lfs_writeseg(fs, sp);
1866
1867 lfs_acquire_finfo(fs, ip->i_number, ip->i_gen);
1868
1869 /*
1870 * Having given up all of the pager_map we were holding,
1871 * we can now wait for aiodoned to reclaim it for us
1872 * without fear of deadlock.
1873 */
1874 kva = uvm_pagermapin(pgs, npages, UVMPAGER_MAPIN_WRITE |
1875 UVMPAGER_MAPIN_WAITOK);
1876 }
1877
1878 mbp = getiobuf(NULL, true);
1879 UVMHIST_LOG(ubchist, "vp %p mbp %p num now %d bytes 0x%x",
1880 vp, mbp, vp->v_numoutput, bytes);
1881 mbp->b_bufsize = npages << PAGE_SHIFT;
1882 mbp->b_data = (void *)kva;
1883 mbp->b_resid = mbp->b_bcount = bytes;
1884 mbp->b_cflags = BC_BUSY|BC_AGE;
1885 mbp->b_iodone = uvm_aio_biodone;
1886
1887 bp = NULL;
1888 for (offset = startoffset;
1889 bytes > 0;
1890 offset += iobytes, bytes -= iobytes) {
1891 lbn = offset >> fs_bshift;
1892 error = ulfs_bmaparray(vp, lbn, &blkno, NULL, NULL, &run,
1893 lfs_issequential_hole);
1894 if (error) {
1895 UVMHIST_LOG(ubchist, "ulfs_bmaparray() -> %d",
1896 error,0,0,0);
1897 skipbytes += bytes;
1898 bytes = 0;
1899 break;
1900 }
1901
1902 iobytes = MIN((((off_t)lbn + 1 + run) << fs_bshift) - offset,
1903 bytes);
1904 if (blkno == (daddr_t)-1) {
1905 skipbytes += iobytes;
1906 continue;
1907 }
1908
1909 /*
1910 * Discover how much we can really pack into this buffer.
1911 */
1912 /* If no room in the current segment, finish it up */
1913 if (sp->sum_bytes_left < sizeof(int32_t) ||
1914 sp->seg_bytes_left < (1 << fs->lfs_bshift)) {
1915 int vers;
1916
1917 lfs_updatemeta(sp);
1918 vers = sp->fip->fi_version;
1919 lfs_release_finfo(fs);
1920 (void) lfs_writeseg(fs, sp);
1921
1922 lfs_acquire_finfo(fs, ip->i_number, vers);
1923 }
1924 /* Check both for space in segment and space in segsum */
1925 iobytes = MIN(iobytes, (sp->seg_bytes_left >> fs_bshift)
1926 << fs_bshift);
1927 iobytes = MIN(iobytes, (sp->sum_bytes_left / sizeof(int32_t))
1928 << fs_bshift);
1929 KASSERT(iobytes > 0);
1930
1931 /* if it's really one i/o, don't make a second buf */
1932 if (offset == startoffset && iobytes == bytes) {
1933 bp = mbp;
1934 /*
1935 * All the LFS output is done by the segwriter. It
1936 * will increment numoutput by one for all the bufs it
1937 * recieves. However this buffer needs one extra to
1938 * account for aiodone.
1939 */
1940 mutex_enter(vp->v_interlock);
1941 vp->v_numoutput++;
1942 mutex_exit(vp->v_interlock);
1943 } else {
1944 bp = getiobuf(NULL, true);
1945 UVMHIST_LOG(ubchist, "vp %p bp %p num now %d",
1946 vp, bp, vp->v_numoutput, 0);
1947 nestiobuf_setup(mbp, bp, offset - pg->offset, iobytes);
1948 /*
1949 * LFS doesn't like async I/O here, dies with
1950 * an assert in lfs_bwrite(). Is that assert
1951 * valid? I retained non-async behaviour when
1952 * converted this to use nestiobuf --pooka
1953 */
1954 bp->b_flags &= ~B_ASYNC;
1955 }
1956
1957 /* XXX This is silly ... is this necessary? */
1958 mutex_enter(&bufcache_lock);
1959 mutex_enter(vp->v_interlock);
1960 bgetvp(vp, bp);
1961 mutex_exit(vp->v_interlock);
1962 mutex_exit(&bufcache_lock);
1963
1964 bp->b_lblkno = lfs_lblkno(fs, offset);
1965 bp->b_private = mbp;
1966 if (devvp->v_type == VBLK) {
1967 bp->b_dev = devvp->v_rdev;
1968 }
1969 VOP_BWRITE(bp->b_vp, bp);
1970 while (lfs_gatherblock(sp, bp, NULL))
1971 continue;
1972 }
1973
1974 nestiobuf_done(mbp, skipbytes, error);
1975 if (skipbytes) {
1976 UVMHIST_LOG(ubchist, "skipbytes %d", skipbytes, 0,0,0);
1977 }
1978 UVMHIST_LOG(ubchist, "returning 0", 0,0,0,0);
1979
1980 if (!async) {
1981 /* Start a segment write. */
1982 UVMHIST_LOG(ubchist, "flushing", 0,0,0,0);
1983 mutex_enter(&lfs_lock);
1984 lfs_flush(fs, 0, 1);
1985 mutex_exit(&lfs_lock);
1986 }
1987
1988 if ((sp->seg_flags & SEGM_SINGLE) && fs->lfs_curseg != fs->lfs_startseg)
1989 return EAGAIN;
1990
1991 return (0);
1992
1993 tryagain:
1994 /*
1995 * We can't write the pages, for whatever reason.
1996 * Clean up after ourselves, and make the caller try again.
1997 */
1998 mutex_enter(vp->v_interlock);
1999
2000 /* Tell why we're here, if we know */
2001 if (failreason != NULL) {
2002 DLOG((DLOG_PAGE, "lfs_gop_write: %s\n", failreason));
2003 }
2004 if (haveeof && startoffset >= eof) {
2005 DLOG((DLOG_PAGE, "lfs_gop_write: ino %d start 0x%" PRIx64
2006 " eof 0x%" PRIx64 " npages=%d\n", VTOI(vp)->i_number,
2007 pgs[0]->offset, eof, npages));
2008 }
2009
2010 mutex_enter(&uvm_pageqlock);
2011 for (i = 0; i < npages; i++) {
2012 pg = pgs[i];
2013
2014 if (pg->flags & PG_PAGEOUT)
2015 uvm_pageout_done(1);
2016 if (pg->flags & PG_DELWRI) {
2017 uvm_pageunwire(pg);
2018 }
2019 uvm_pageactivate(pg);
2020 pg->flags &= ~(PG_CLEAN|PG_DELWRI|PG_PAGEOUT|PG_RELEASED);
2021 DLOG((DLOG_PAGE, "pg[%d] = %p (vp %p off %" PRIx64 ")\n", i, pg,
2022 vp, pg->offset));
2023 DLOG((DLOG_PAGE, "pg[%d]->flags = %x\n", i, pg->flags));
2024 DLOG((DLOG_PAGE, "pg[%d]->pqflags = %x\n", i, pg->pqflags));
2025 DLOG((DLOG_PAGE, "pg[%d]->uanon = %p\n", i, pg->uanon));
2026 DLOG((DLOG_PAGE, "pg[%d]->uobject = %p\n", i, pg->uobject));
2027 DLOG((DLOG_PAGE, "pg[%d]->wire_count = %d\n", i,
2028 pg->wire_count));
2029 DLOG((DLOG_PAGE, "pg[%d]->loan_count = %d\n", i,
2030 pg->loan_count));
2031 }
2032 /* uvm_pageunbusy takes care of PG_BUSY, PG_WANTED */
2033 uvm_page_unbusy(pgs, npages);
2034 mutex_exit(&uvm_pageqlock);
2035 mutex_exit(vp->v_interlock);
2036 return EAGAIN;
2037 }
2038
2039 /*
2040 * finish vnode/inode initialization.
2041 * used by lfs_vget and lfs_fastvget.
2042 */
2043 void
2044 lfs_vinit(struct mount *mp, struct vnode **vpp)
2045 {
2046 struct vnode *vp = *vpp;
2047 struct inode *ip = VTOI(vp);
2048 struct ulfsmount *ump = VFSTOULFS(mp);
2049 struct lfs *fs = ump->um_lfs;
2050 int i;
2051
2052 ip->i_mode = ip->i_ffs1_mode;
2053 ip->i_nlink = ip->i_ffs1_nlink;
2054 ip->i_lfs_osize = ip->i_size = ip->i_ffs1_size;
2055 ip->i_flags = ip->i_ffs1_flags;
2056 ip->i_gen = ip->i_ffs1_gen;
2057 ip->i_uid = ip->i_ffs1_uid;
2058 ip->i_gid = ip->i_ffs1_gid;
2059
2060 ip->i_lfs_effnblks = ip->i_ffs1_blocks;
2061 ip->i_lfs_odnlink = ip->i_ffs1_nlink;
2062
2063 /*
2064 * Initialize the vnode from the inode, check for aliases. In all
2065 * cases re-init ip, the underlying vnode/inode may have changed.
2066 */
2067 ulfs_vinit(mp, lfs_specop_p, lfs_fifoop_p, &vp);
2068 ip = VTOI(vp);
2069
2070 memset(ip->i_lfs_fragsize, 0, ULFS_NDADDR * sizeof(*ip->i_lfs_fragsize));
2071 if (vp->v_type != VLNK || ip->i_size >= ip->i_lfs->um_maxsymlinklen) {
2072 #ifdef DEBUG
2073 for (i = (ip->i_size + fs->lfs_bsize - 1) >> fs->lfs_bshift;
2074 i < ULFS_NDADDR; i++) {
2075 if ((vp->v_type == VBLK || vp->v_type == VCHR) &&
2076 i == 0)
2077 continue;
2078 if (ip->i_ffs1_db[i] != 0) {
2079 lfs_dump_dinode(ip->i_din.ffs1_din);
2080 panic("inconsistent inode (direct)");
2081 }
2082 }
2083 for ( ; i < ULFS_NDADDR + ULFS_NIADDR; i++) {
2084 if (ip->i_ffs1_ib[i - ULFS_NDADDR] != 0) {
2085 lfs_dump_dinode(ip->i_din.ffs1_din);
2086 panic("inconsistent inode (indirect)");
2087 }
2088 }
2089 #endif /* DEBUG */
2090 for (i = 0; i < ULFS_NDADDR; i++)
2091 if (ip->i_ffs1_db[i] != 0)
2092 ip->i_lfs_fragsize[i] = lfs_blksize(fs, ip, i);
2093 }
2094
2095 #ifdef DIAGNOSTIC
2096 if (vp->v_type == VNON) {
2097 # ifdef DEBUG
2098 lfs_dump_dinode(ip->i_din.ffs1_din);
2099 # endif
2100 panic("lfs_vinit: ino %llu is type VNON! (ifmt=%o)\n",
2101 (unsigned long long)ip->i_number,
2102 (ip->i_mode & LFS_IFMT) >> 12);
2103 }
2104 #endif /* DIAGNOSTIC */
2105
2106 /*
2107 * Finish inode initialization now that aliasing has been resolved.
2108 */
2109
2110 ip->i_devvp = ump->um_devvp;
2111 vref(ip->i_devvp);
2112 #if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
2113 ulfsquota_init(ip);
2114 #endif
2115 genfs_node_init(vp, &lfs_genfsops);
2116 uvm_vnp_setsize(vp, ip->i_size);
2117
2118 /* Initialize hiblk from file size */
2119 ip->i_lfs_hiblk = lfs_lblkno(ip->i_lfs, ip->i_size + ip->i_lfs->lfs_bsize - 1) - 1;
2120
2121 *vpp = vp;
2122 }
2123
2124 /*
2125 * Resize the filesystem to contain the specified number of segments.
2126 */
2127 int
2128 lfs_resize_fs(struct lfs *fs, int newnsegs)
2129 {
2130 SEGUSE *sup;
2131 struct buf *bp, *obp;
2132 daddr_t olast, nlast, ilast, noff, start, end;
2133 struct vnode *ivp;
2134 struct inode *ip;
2135 int error, badnews, inc, oldnsegs;
2136 int sbbytes, csbbytes, gain, cgain;
2137 int i;
2138
2139 /* Only support v2 and up */
2140 if (fs->lfs_version < 2)
2141 return EOPNOTSUPP;
2142
2143 /* If we're doing nothing, do it fast */
2144 oldnsegs = fs->lfs_nseg;
2145 if (newnsegs == oldnsegs)
2146 return 0;
2147
2148 /* We always have to have two superblocks */
2149 if (newnsegs <= lfs_dtosn(fs, fs->lfs_sboffs[1]))
2150 return EFBIG;
2151
2152 ivp = fs->lfs_ivnode;
2153 ip = VTOI(ivp);
2154 error = 0;
2155
2156 /* Take the segment lock so no one else calls lfs_newseg() */
2157 lfs_seglock(fs, SEGM_PROT);
2158
2159 /*
2160 * Make sure the segments we're going to be losing, if any,
2161 * are in fact empty. We hold the seglock, so their status
2162 * cannot change underneath us. Count the superblocks we lose,
2163 * while we're at it.
2164 */
2165 sbbytes = csbbytes = 0;
2166 cgain = 0;
2167 for (i = newnsegs; i < oldnsegs; i++) {
2168 LFS_SEGENTRY(sup, fs, i, bp);
2169 badnews = sup->su_nbytes || !(sup->su_flags & SEGUSE_INVAL);
2170 if (sup->su_flags & SEGUSE_SUPERBLOCK)
2171 sbbytes += LFS_SBPAD;
2172 if (!(sup->su_flags & SEGUSE_DIRTY)) {
2173 ++cgain;
2174 if (sup->su_flags & SEGUSE_SUPERBLOCK)
2175 csbbytes += LFS_SBPAD;
2176 }
2177 brelse(bp, 0);
2178 if (badnews) {
2179 error = EBUSY;
2180 goto out;
2181 }
2182 }
2183
2184 /* Note old and new segment table endpoints, and old ifile size */
2185 olast = fs->lfs_cleansz + fs->lfs_segtabsz;
2186 nlast = howmany(newnsegs, fs->lfs_sepb) + fs->lfs_cleansz;
2187 ilast = ivp->v_size >> fs->lfs_bshift;
2188 noff = nlast - olast;
2189
2190 /*
2191 * Make sure no one can use the Ifile while we change it around.
2192 * Even after taking the iflock we need to make sure no one still
2193 * is holding Ifile buffers, so we get each one, to drain them.
2194 * (XXX this could be done better.)
2195 */
2196 rw_enter(&fs->lfs_iflock, RW_WRITER);
2197 for (i = 0; i < ilast; i++) {
2198 /* XXX what to do if bread fails? */
2199 bread(ivp, i, fs->lfs_bsize, 0, &bp);
2200 brelse(bp, 0);
2201 }
2202
2203 /* Allocate new Ifile blocks */
2204 for (i = ilast; i < ilast + noff; i++) {
2205 if (lfs_balloc(ivp, i * fs->lfs_bsize, fs->lfs_bsize, NOCRED, 0,
2206 &bp) != 0)
2207 panic("balloc extending ifile");
2208 memset(bp->b_data, 0, fs->lfs_bsize);
2209 VOP_BWRITE(bp->b_vp, bp);
2210 }
2211
2212 /* Register new ifile size */
2213 ip->i_size += noff * fs->lfs_bsize;
2214 ip->i_ffs1_size = ip->i_size;
2215 uvm_vnp_setsize(ivp, ip->i_size);
2216
2217 /* Copy the inode table to its new position */
2218 if (noff != 0) {
2219 if (noff < 0) {
2220 start = nlast;
2221 end = ilast + noff;
2222 inc = 1;
2223 } else {
2224 start = ilast + noff - 1;
2225 end = nlast - 1;
2226 inc = -1;
2227 }
2228 for (i = start; i != end; i += inc) {
2229 if (bread(ivp, i, fs->lfs_bsize,
2230 B_MODIFY, &bp) != 0)
2231 panic("resize: bread dst blk failed");
2232 if (bread(ivp, i - noff, fs->lfs_bsize,
2233 0, &obp))
2234 panic("resize: bread src blk failed");
2235 memcpy(bp->b_data, obp->b_data, fs->lfs_bsize);
2236 VOP_BWRITE(bp->b_vp, bp);
2237 brelse(obp, 0);
2238 }
2239 }
2240
2241 /* If we are expanding, write the new empty SEGUSE entries */
2242 if (newnsegs > oldnsegs) {
2243 for (i = oldnsegs; i < newnsegs; i++) {
2244 if ((error = bread(ivp, i / fs->lfs_sepb +
2245 fs->lfs_cleansz, fs->lfs_bsize,
2246 B_MODIFY, &bp)) != 0)
2247 panic("lfs: ifile read: %d", error);
2248 while ((i + 1) % fs->lfs_sepb && i < newnsegs) {
2249 sup = &((SEGUSE *)bp->b_data)[i % fs->lfs_sepb];
2250 memset(sup, 0, sizeof(*sup));
2251 i++;
2252 }
2253 VOP_BWRITE(bp->b_vp, bp);
2254 }
2255 }
2256
2257 /* Zero out unused superblock offsets */
2258 for (i = 2; i < LFS_MAXNUMSB; i++)
2259 if (lfs_dtosn(fs, fs->lfs_sboffs[i]) >= newnsegs)
2260 fs->lfs_sboffs[i] = 0x0;
2261
2262 /*
2263 * Correct superblock entries that depend on fs size.
2264 * The computations of these are as follows:
2265 *
2266 * size = lfs_segtod(fs, nseg)
2267 * dsize = lfs_segtod(fs, nseg - minfreeseg) - lfs_btofsb(#super * LFS_SBPAD)
2268 * bfree = dsize - lfs_btofsb(fs, bsize * nseg / 2) - blocks_actually_used
2269 * avail = lfs_segtod(fs, nclean) - lfs_btofsb(#clean_super * LFS_SBPAD)
2270 * + (lfs_segtod(fs, 1) - (offset - curseg))
2271 * - lfs_segtod(fs, minfreeseg - (minfreeseg / 2))
2272 *
2273 * XXX - we should probably adjust minfreeseg as well.
2274 */
2275 gain = (newnsegs - oldnsegs);
2276 fs->lfs_nseg = newnsegs;
2277 fs->lfs_segtabsz = nlast - fs->lfs_cleansz;
2278 fs->lfs_size += gain * lfs_btofsb(fs, fs->lfs_ssize);
2279 fs->lfs_dsize += gain * lfs_btofsb(fs, fs->lfs_ssize) - lfs_btofsb(fs, sbbytes);
2280 fs->lfs_bfree += gain * lfs_btofsb(fs, fs->lfs_ssize) - lfs_btofsb(fs, sbbytes)
2281 - gain * lfs_btofsb(fs, fs->lfs_bsize / 2);
2282 if (gain > 0) {
2283 fs->lfs_nclean += gain;
2284 fs->lfs_avail += gain * lfs_btofsb(fs, fs->lfs_ssize);
2285 } else {
2286 fs->lfs_nclean -= cgain;
2287 fs->lfs_avail -= cgain * lfs_btofsb(fs, fs->lfs_ssize) -
2288 lfs_btofsb(fs, csbbytes);
2289 }
2290
2291 /* Resize segment flag cache */
2292 fs->lfs_suflags[0] = realloc(fs->lfs_suflags[0],
2293 fs->lfs_nseg * sizeof(u_int32_t), M_SEGMENT, M_WAITOK);
2294 fs->lfs_suflags[1] = realloc(fs->lfs_suflags[1],
2295 fs->lfs_nseg * sizeof(u_int32_t), M_SEGMENT, M_WAITOK);
2296 for (i = oldnsegs; i < newnsegs; i++)
2297 fs->lfs_suflags[0][i] = fs->lfs_suflags[1][i] = 0x0;
2298
2299 /* Truncate Ifile if necessary */
2300 if (noff < 0)
2301 lfs_truncate(ivp, ivp->v_size + (noff << fs->lfs_bshift), 0,
2302 NOCRED);
2303
2304 /* Update cleaner info so the cleaner can die */
2305 /* XXX what to do if bread fails? */
2306 bread(ivp, 0, fs->lfs_bsize, B_MODIFY, &bp);
2307 ((CLEANERINFO *)bp->b_data)->clean = fs->lfs_nclean;
2308 ((CLEANERINFO *)bp->b_data)->dirty = fs->lfs_nseg - fs->lfs_nclean;
2309 VOP_BWRITE(bp->b_vp, bp);
2310
2311 /* Let Ifile accesses proceed */
2312 rw_exit(&fs->lfs_iflock);
2313
2314 out:
2315 lfs_segunlock(fs);
2316 return error;
2317 }
2318
2319 /*
2320 * Extended attribute dispatch
2321 */
2322 int
2323 lfs_extattrctl(struct mount *mp, int cmd, struct vnode *vp,
2324 int attrnamespace, const char *attrname)
2325 {
2326 #ifdef LFS_EXTATTR
2327 struct ulfsmount *ump;
2328
2329 ump = VFSTOULFS(mp);
2330 if (ump->um_fstype == ULFS1) {
2331 return ulfs_extattrctl(mp, cmd, vp, attrnamespace, attrname);
2332 }
2333 #endif
2334 return vfs_stdextattrctl(mp, cmd, vp, attrnamespace, attrname);
2335 }
2336