ffs_vfsops.c revision 181345
1/*- 2 * Copyright (c) 1989, 1991, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 4. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)ffs_vfsops.c 8.31 (Berkeley) 5/20/95 30 */ 31 32#include <sys/cdefs.h> 33__FBSDID("$FreeBSD: head/sys/ufs/ffs/ffs_vfsops.c 181345 2008-08-06 14:47:19Z kib $"); 34 35#include "opt_mac.h" 36#include "opt_quota.h" 37#include "opt_ufs.h" 38#include "opt_ffs.h" 39 40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/namei.h> 43#include <sys/priv.h> 44#include <sys/proc.h> 45#include <sys/kernel.h> 46#include <sys/vnode.h> 47#include <sys/mount.h> 48#include <sys/bio.h> 49#include <sys/buf.h> 50#include <sys/conf.h> 51#include <sys/fcntl.h> 52#include <sys/malloc.h> 53#include <sys/mutex.h> 54 55#include <security/mac/mac_framework.h> 56 57#include <ufs/ufs/extattr.h> 58#include <ufs/ufs/gjournal.h> 59#include <ufs/ufs/quota.h> 60#include <ufs/ufs/ufsmount.h> 61#include <ufs/ufs/inode.h> 62#include <ufs/ufs/ufs_extern.h> 63 64#include <ufs/ffs/fs.h> 65#include <ufs/ffs/ffs_extern.h> 66 67#include <vm/vm.h> 68#include <vm/uma.h> 69#include <vm/vm_page.h> 70 71#include <geom/geom.h> 72#include <geom/geom_vfs.h> 73 74static uma_zone_t uma_inode, uma_ufs1, uma_ufs2; 75 76static int ffs_reload(struct mount *, struct thread *); 77static int ffs_mountfs(struct vnode *, struct mount *, struct thread *); 78static void ffs_oldfscompat_read(struct fs *, struct ufsmount *, 79 ufs2_daddr_t); 80static void ffs_oldfscompat_write(struct fs *, struct ufsmount *); 81static void ffs_ifree(struct ufsmount *ump, struct inode *ip); 82static vfs_init_t ffs_init; 83static vfs_uninit_t ffs_uninit; 84static vfs_extattrctl_t ffs_extattrctl; 85static vfs_cmount_t ffs_cmount; 86static vfs_unmount_t ffs_unmount; 87static vfs_mount_t ffs_mount; 88static vfs_statfs_t ffs_statfs; 89static vfs_fhtovp_t ffs_fhtovp; 90static vfs_sync_t ffs_sync; 91 92static struct vfsops ufs_vfsops = { 93 .vfs_extattrctl = ffs_extattrctl, 94 .vfs_fhtovp = ffs_fhtovp, 95 .vfs_init = ffs_init, 96 .vfs_mount = ffs_mount, 97 .vfs_cmount = ffs_cmount, 98 .vfs_quotactl = ufs_quotactl, 99 .vfs_root = ufs_root, 100 .vfs_statfs = ffs_statfs, 101 .vfs_sync = ffs_sync, 102 .vfs_uninit = ffs_uninit, 103 .vfs_unmount = ffs_unmount, 104 .vfs_vget = ffs_vget, 105}; 106 107VFS_SET(ufs_vfsops, ufs, 0); 108MODULE_VERSION(ufs, 1); 109 110static b_strategy_t ffs_geom_strategy; 111static b_write_t ffs_bufwrite; 112 113static struct buf_ops ffs_ops = { 114 .bop_name = "FFS", 115 .bop_write = ffs_bufwrite, 116 .bop_strategy = ffs_geom_strategy, 117 .bop_sync = bufsync, 118#ifdef NO_FFS_SNAPSHOT 119 .bop_bdflush = bufbdflush, 120#else 121 .bop_bdflush = ffs_bdflush, 122#endif 123}; 124 125static const char *ffs_opts[] = { "acls", "async", "noatime", "noclusterr", 126 "noclusterw", "noexec", "export", "force", "from", "multilabel", 127 "snapshot", "nosuid", "suiddir", "nosymfollow", "sync", 128 "union", NULL }; 129 130static int 131ffs_mount(struct mount *mp, struct thread *td) 132{ 133 struct vnode *devvp; 134 struct ufsmount *ump = 0; 135 struct fs *fs; 136 int error, flags; 137 u_int mntorflags, mntandnotflags; 138 mode_t accessmode; 139 struct nameidata ndp; 140 char *fspec; 141 142 if (vfs_filteropt(mp->mnt_optnew, ffs_opts)) 143 return (EINVAL); 144 if (uma_inode == NULL) { 145 uma_inode = uma_zcreate("FFS inode", 146 sizeof(struct inode), NULL, NULL, NULL, NULL, 147 UMA_ALIGN_PTR, 0); 148 uma_ufs1 = uma_zcreate("FFS1 dinode", 149 sizeof(struct ufs1_dinode), NULL, NULL, NULL, NULL, 150 UMA_ALIGN_PTR, 0); 151 uma_ufs2 = uma_zcreate("FFS2 dinode", 152 sizeof(struct ufs2_dinode), NULL, NULL, NULL, NULL, 153 UMA_ALIGN_PTR, 0); 154 } 155 156 fspec = vfs_getopts(mp->mnt_optnew, "from", &error); 157 if (error) 158 return (error); 159 160 mntorflags = 0; 161 mntandnotflags = 0; 162 if (vfs_getopt(mp->mnt_optnew, "acls", NULL, NULL) == 0) 163 mntorflags |= MNT_ACLS; 164 165 if (vfs_getopt(mp->mnt_optnew, "snapshot", NULL, NULL) == 0) { 166 mntorflags |= MNT_SNAPSHOT; 167 /* 168 * Once we have set the MNT_SNAPSHOT flag, do not 169 * persist "snapshot" in the options list. 170 */ 171 vfs_deleteopt(mp->mnt_optnew, "snapshot"); 172 if (mp->mnt_opt != NULL) 173 vfs_deleteopt(mp->mnt_opt, "snapshot"); 174 } 175 176 MNT_ILOCK(mp); 177 mp->mnt_flag = (mp->mnt_flag | mntorflags) & ~mntandnotflags; 178 MNT_IUNLOCK(mp); 179 /* 180 * If updating, check whether changing from read-only to 181 * read/write; if there is no device name, that's all we do. 182 */ 183 if (mp->mnt_flag & MNT_UPDATE) { 184 ump = VFSTOUFS(mp); 185 fs = ump->um_fs; 186 devvp = ump->um_devvp; 187 if (fs->fs_ronly == 0 && 188 vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0)) { 189 if ((error = vn_start_write(NULL, &mp, V_WAIT)) != 0) 190 return (error); 191 /* 192 * Flush any dirty data. 193 */ 194 if ((error = ffs_sync(mp, MNT_WAIT, td)) != 0) { 195 vn_finished_write(mp); 196 return (error); 197 } 198 /* 199 * Check for and optionally get rid of files open 200 * for writing. 201 */ 202 flags = WRITECLOSE; 203 if (mp->mnt_flag & MNT_FORCE) 204 flags |= FORCECLOSE; 205 if (mp->mnt_flag & MNT_SOFTDEP) { 206 error = softdep_flushfiles(mp, flags, td); 207 } else { 208 error = ffs_flushfiles(mp, flags, td); 209 } 210 if (error) { 211 vn_finished_write(mp); 212 return (error); 213 } 214 if (fs->fs_pendingblocks != 0 || 215 fs->fs_pendinginodes != 0) { 216 printf("%s: %s: blocks %jd files %d\n", 217 fs->fs_fsmnt, "update error", 218 (intmax_t)fs->fs_pendingblocks, 219 fs->fs_pendinginodes); 220 fs->fs_pendingblocks = 0; 221 fs->fs_pendinginodes = 0; 222 } 223 if ((fs->fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) == 0) 224 fs->fs_clean = 1; 225 if ((error = ffs_sbupdate(ump, MNT_WAIT, 0)) != 0) { 226 fs->fs_ronly = 0; 227 fs->fs_clean = 0; 228 vn_finished_write(mp); 229 return (error); 230 } 231 vn_finished_write(mp); 232 DROP_GIANT(); 233 g_topology_lock(); 234 g_access(ump->um_cp, 0, -1, 0); 235 g_topology_unlock(); 236 PICKUP_GIANT(); 237 fs->fs_ronly = 1; 238 MNT_ILOCK(mp); 239 mp->mnt_flag |= MNT_RDONLY; 240 MNT_IUNLOCK(mp); 241 } 242 if ((mp->mnt_flag & MNT_RELOAD) && 243 (error = ffs_reload(mp, td)) != 0) 244 return (error); 245 if (fs->fs_ronly && 246 !vfs_flagopt(mp->mnt_optnew, "ro", NULL, 0)) { 247 /* 248 * If upgrade to read-write by non-root, then verify 249 * that user has necessary permissions on the device. 250 */ 251 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); 252 error = VOP_ACCESS(devvp, VREAD | VWRITE, 253 td->td_ucred, td); 254 if (error) 255 error = priv_check(td, PRIV_VFS_MOUNT_PERM); 256 if (error) { 257 VOP_UNLOCK(devvp, 0); 258 return (error); 259 } 260 VOP_UNLOCK(devvp, 0); 261 fs->fs_flags &= ~FS_UNCLEAN; 262 if (fs->fs_clean == 0) { 263 fs->fs_flags |= FS_UNCLEAN; 264 if ((mp->mnt_flag & MNT_FORCE) || 265 ((fs->fs_flags & FS_NEEDSFSCK) == 0 && 266 (fs->fs_flags & FS_DOSOFTDEP))) { 267 printf("WARNING: %s was not %s\n", 268 fs->fs_fsmnt, "properly dismounted"); 269 } else { 270 printf( 271"WARNING: R/W mount of %s denied. Filesystem is not clean - run fsck\n", 272 fs->fs_fsmnt); 273 return (EPERM); 274 } 275 } 276 DROP_GIANT(); 277 g_topology_lock(); 278 /* 279 * If we're the root device, we may not have an E count 280 * yet, get it now. 281 */ 282 if (ump->um_cp->ace == 0) 283 error = g_access(ump->um_cp, 0, 1, 1); 284 else 285 error = g_access(ump->um_cp, 0, 1, 0); 286 g_topology_unlock(); 287 PICKUP_GIANT(); 288 if (error) 289 return (error); 290 if ((error = vn_start_write(NULL, &mp, V_WAIT)) != 0) 291 return (error); 292 fs->fs_ronly = 0; 293 MNT_ILOCK(mp); 294 mp->mnt_flag &= ~MNT_RDONLY; 295 MNT_IUNLOCK(mp); 296 fs->fs_clean = 0; 297 if ((error = ffs_sbupdate(ump, MNT_WAIT, 0)) != 0) { 298 vn_finished_write(mp); 299 return (error); 300 } 301 /* check to see if we need to start softdep */ 302 if ((fs->fs_flags & FS_DOSOFTDEP) && 303 (error = softdep_mount(devvp, mp, fs, td->td_ucred))){ 304 vn_finished_write(mp); 305 return (error); 306 } 307 if (fs->fs_snapinum[0] != 0) 308 ffs_snapshot_mount(mp); 309 vn_finished_write(mp); 310 } 311 /* 312 * Soft updates is incompatible with "async", 313 * so if we are doing softupdates stop the user 314 * from setting the async flag in an update. 315 * Softdep_mount() clears it in an initial mount 316 * or ro->rw remount. 317 */ 318 if (mp->mnt_flag & MNT_SOFTDEP) { 319 /* XXX: Reset too late ? */ 320 MNT_ILOCK(mp); 321 mp->mnt_flag &= ~MNT_ASYNC; 322 MNT_IUNLOCK(mp); 323 } 324 /* 325 * Keep MNT_ACLS flag if it is stored in superblock. 326 */ 327 if ((fs->fs_flags & FS_ACLS) != 0) { 328 /* XXX: Set too late ? */ 329 MNT_ILOCK(mp); 330 mp->mnt_flag |= MNT_ACLS; 331 MNT_IUNLOCK(mp); 332 } 333 334 /* 335 * If this is a snapshot request, take the snapshot. 336 */ 337 if (mp->mnt_flag & MNT_SNAPSHOT) 338 return (ffs_snapshot(mp, fspec)); 339 } 340 341 /* 342 * Not an update, or updating the name: look up the name 343 * and verify that it refers to a sensible disk device. 344 */ 345 NDINIT(&ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspec, td); 346 if ((error = namei(&ndp)) != 0) 347 return (error); 348 NDFREE(&ndp, NDF_ONLY_PNBUF); 349 devvp = ndp.ni_vp; 350 if (!vn_isdisk(devvp, &error)) { 351 vput(devvp); 352 return (error); 353 } 354 355 /* 356 * If mount by non-root, then verify that user has necessary 357 * permissions on the device. 358 */ 359 accessmode = VREAD; 360 if ((mp->mnt_flag & MNT_RDONLY) == 0) 361 accessmode |= VWRITE; 362 error = VOP_ACCESS(devvp, accessmode, td->td_ucred, td); 363 if (error) 364 error = priv_check(td, PRIV_VFS_MOUNT_PERM); 365 if (error) { 366 vput(devvp); 367 return (error); 368 } 369 370 if (mp->mnt_flag & MNT_UPDATE) { 371 /* 372 * Update only 373 * 374 * If it's not the same vnode, or at least the same device 375 * then it's not correct. 376 */ 377 378 if (devvp->v_rdev != ump->um_devvp->v_rdev) 379 error = EINVAL; /* needs translation */ 380 vput(devvp); 381 if (error) 382 return (error); 383 } else { 384 /* 385 * New mount 386 * 387 * We need the name for the mount point (also used for 388 * "last mounted on") copied in. If an error occurs, 389 * the mount point is discarded by the upper level code. 390 * Note that vfs_mount() populates f_mntonname for us. 391 */ 392 if ((error = ffs_mountfs(devvp, mp, td)) != 0) { 393 vrele(devvp); 394 return (error); 395 } 396 } 397 vfs_mountedfrom(mp, fspec); 398 return (0); 399} 400 401/* 402 * Compatibility with old mount system call. 403 */ 404 405static int 406ffs_cmount(struct mntarg *ma, void *data, int flags, struct thread *td) 407{ 408 struct ufs_args args; 409 int error; 410 411 if (data == NULL) 412 return (EINVAL); 413 error = copyin(data, &args, sizeof args); 414 if (error) 415 return (error); 416 417 ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN); 418 ma = mount_arg(ma, "export", &args.export, sizeof args.export); 419 error = kernel_mount(ma, flags); 420 421 return (error); 422} 423 424/* 425 * Reload all incore data for a filesystem (used after running fsck on 426 * the root filesystem and finding things to fix). The filesystem must 427 * be mounted read-only. 428 * 429 * Things to do to update the mount: 430 * 1) invalidate all cached meta-data. 431 * 2) re-read superblock from disk. 432 * 3) re-read summary information from disk. 433 * 4) invalidate all inactive vnodes. 434 * 5) invalidate all cached file data. 435 * 6) re-read inode data for all active vnodes. 436 */ 437static int 438ffs_reload(struct mount *mp, struct thread *td) 439{ 440 struct vnode *vp, *mvp, *devvp; 441 struct inode *ip; 442 void *space; 443 struct buf *bp; 444 struct fs *fs, *newfs; 445 struct ufsmount *ump; 446 ufs2_daddr_t sblockloc; 447 int i, blks, size, error; 448 int32_t *lp; 449 450 if ((mp->mnt_flag & MNT_RDONLY) == 0) 451 return (EINVAL); 452 ump = VFSTOUFS(mp); 453 /* 454 * Step 1: invalidate all cached meta-data. 455 */ 456 devvp = VFSTOUFS(mp)->um_devvp; 457 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); 458 if (vinvalbuf(devvp, 0, td, 0, 0) != 0) 459 panic("ffs_reload: dirty1"); 460 VOP_UNLOCK(devvp, 0); 461 462 /* 463 * Step 2: re-read superblock from disk. 464 */ 465 fs = VFSTOUFS(mp)->um_fs; 466 if ((error = bread(devvp, btodb(fs->fs_sblockloc), fs->fs_sbsize, 467 NOCRED, &bp)) != 0) 468 return (error); 469 newfs = (struct fs *)bp->b_data; 470 if ((newfs->fs_magic != FS_UFS1_MAGIC && 471 newfs->fs_magic != FS_UFS2_MAGIC) || 472 newfs->fs_bsize > MAXBSIZE || 473 newfs->fs_bsize < sizeof(struct fs)) { 474 brelse(bp); 475 return (EIO); /* XXX needs translation */ 476 } 477 /* 478 * Copy pointer fields back into superblock before copying in XXX 479 * new superblock. These should really be in the ufsmount. XXX 480 * Note that important parameters (eg fs_ncg) are unchanged. 481 */ 482 newfs->fs_csp = fs->fs_csp; 483 newfs->fs_maxcluster = fs->fs_maxcluster; 484 newfs->fs_contigdirs = fs->fs_contigdirs; 485 newfs->fs_active = fs->fs_active; 486 /* The file system is still read-only. */ 487 newfs->fs_ronly = 1; 488 sblockloc = fs->fs_sblockloc; 489 bcopy(newfs, fs, (u_int)fs->fs_sbsize); 490 brelse(bp); 491 mp->mnt_maxsymlinklen = fs->fs_maxsymlinklen; 492 ffs_oldfscompat_read(fs, VFSTOUFS(mp), sblockloc); 493 UFS_LOCK(ump); 494 if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) { 495 printf("%s: reload pending error: blocks %jd files %d\n", 496 fs->fs_fsmnt, (intmax_t)fs->fs_pendingblocks, 497 fs->fs_pendinginodes); 498 fs->fs_pendingblocks = 0; 499 fs->fs_pendinginodes = 0; 500 } 501 UFS_UNLOCK(ump); 502 503 /* 504 * Step 3: re-read summary information from disk. 505 */ 506 blks = howmany(fs->fs_cssize, fs->fs_fsize); 507 space = fs->fs_csp; 508 for (i = 0; i < blks; i += fs->fs_frag) { 509 size = fs->fs_bsize; 510 if (i + fs->fs_frag > blks) 511 size = (blks - i) * fs->fs_fsize; 512 error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), size, 513 NOCRED, &bp); 514 if (error) 515 return (error); 516 bcopy(bp->b_data, space, (u_int)size); 517 space = (char *)space + size; 518 brelse(bp); 519 } 520 /* 521 * We no longer know anything about clusters per cylinder group. 522 */ 523 if (fs->fs_contigsumsize > 0) { 524 lp = fs->fs_maxcluster; 525 for (i = 0; i < fs->fs_ncg; i++) 526 *lp++ = fs->fs_contigsumsize; 527 } 528 529loop: 530 MNT_ILOCK(mp); 531 MNT_VNODE_FOREACH(vp, mp, mvp) { 532 VI_LOCK(vp); 533 if (vp->v_iflag & VI_DOOMED) { 534 VI_UNLOCK(vp); 535 continue; 536 } 537 MNT_IUNLOCK(mp); 538 /* 539 * Step 4: invalidate all cached file data. 540 */ 541 if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, td)) { 542 MNT_VNODE_FOREACH_ABORT(mp, mvp); 543 goto loop; 544 } 545 if (vinvalbuf(vp, 0, td, 0, 0)) 546 panic("ffs_reload: dirty2"); 547 /* 548 * Step 5: re-read inode data for all active vnodes. 549 */ 550 ip = VTOI(vp); 551 error = 552 bread(devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)), 553 (int)fs->fs_bsize, NOCRED, &bp); 554 if (error) { 555 VOP_UNLOCK(vp, 0); 556 vrele(vp); 557 MNT_VNODE_FOREACH_ABORT(mp, mvp); 558 return (error); 559 } 560 ffs_load_inode(bp, ip, fs, ip->i_number); 561 ip->i_effnlink = ip->i_nlink; 562 brelse(bp); 563 VOP_UNLOCK(vp, 0); 564 vrele(vp); 565 MNT_ILOCK(mp); 566 } 567 MNT_IUNLOCK(mp); 568 return (0); 569} 570 571/* 572 * Possible superblock locations ordered from most to least likely. 573 */ 574static int sblock_try[] = SBLOCKSEARCH; 575 576/* 577 * Common code for mount and mountroot 578 */ 579static int 580ffs_mountfs(devvp, mp, td) 581 struct vnode *devvp; 582 struct mount *mp; 583 struct thread *td; 584{ 585 struct ufsmount *ump; 586 struct buf *bp; 587 struct fs *fs; 588 struct cdev *dev; 589 void *space; 590 ufs2_daddr_t sblockloc; 591 int error, i, blks, size, ronly; 592 int32_t *lp; 593 struct ucred *cred; 594 struct g_consumer *cp; 595 struct mount *nmp; 596 597 dev = devvp->v_rdev; 598 cred = td ? td->td_ucred : NOCRED; 599 600 ronly = (mp->mnt_flag & MNT_RDONLY) != 0; 601 DROP_GIANT(); 602 g_topology_lock(); 603 error = g_vfs_open(devvp, &cp, "ffs", ronly ? 0 : 1); 604 605 /* 606 * If we are a root mount, drop the E flag so fsck can do its magic. 607 * We will pick it up again when we remount R/W. 608 */ 609 if (error == 0 && ronly && (mp->mnt_flag & MNT_ROOTFS)) 610 error = g_access(cp, 0, 0, -1); 611 g_topology_unlock(); 612 PICKUP_GIANT(); 613 VOP_UNLOCK(devvp, 0); 614 if (error) 615 return (error); 616 if (devvp->v_rdev->si_iosize_max != 0) 617 mp->mnt_iosize_max = devvp->v_rdev->si_iosize_max; 618 if (mp->mnt_iosize_max > MAXPHYS) 619 mp->mnt_iosize_max = MAXPHYS; 620 621 devvp->v_bufobj.bo_private = cp; 622 devvp->v_bufobj.bo_ops = &ffs_ops; 623 624 bp = NULL; 625 ump = NULL; 626 fs = NULL; 627 sblockloc = 0; 628 /* 629 * Try reading the superblock in each of its possible locations. 630 */ 631 for (i = 0; sblock_try[i] != -1; i++) { 632 if ((SBLOCKSIZE % cp->provider->sectorsize) != 0) { 633 error = EINVAL; 634 vfs_mount_error(mp, 635 "Invalid sectorsize %d for superblock size %d", 636 cp->provider->sectorsize, SBLOCKSIZE); 637 goto out; 638 } 639 if ((error = bread(devvp, btodb(sblock_try[i]), SBLOCKSIZE, 640 cred, &bp)) != 0) 641 goto out; 642 fs = (struct fs *)bp->b_data; 643 sblockloc = sblock_try[i]; 644 if ((fs->fs_magic == FS_UFS1_MAGIC || 645 (fs->fs_magic == FS_UFS2_MAGIC && 646 (fs->fs_sblockloc == sblockloc || 647 (fs->fs_old_flags & FS_FLAGS_UPDATED) == 0))) && 648 fs->fs_bsize <= MAXBSIZE && 649 fs->fs_bsize >= sizeof(struct fs)) 650 break; 651 brelse(bp); 652 bp = NULL; 653 } 654 if (sblock_try[i] == -1) { 655 error = EINVAL; /* XXX needs translation */ 656 goto out; 657 } 658 fs->fs_fmod = 0; 659 fs->fs_flags &= ~FS_INDEXDIRS; /* no support for directory indicies */ 660 fs->fs_flags &= ~FS_UNCLEAN; 661 if (fs->fs_clean == 0) { 662 fs->fs_flags |= FS_UNCLEAN; 663 if (ronly || (mp->mnt_flag & MNT_FORCE) || 664 ((fs->fs_flags & FS_NEEDSFSCK) == 0 && 665 (fs->fs_flags & FS_DOSOFTDEP))) { 666 printf( 667"WARNING: %s was not properly dismounted\n", 668 fs->fs_fsmnt); 669 } else { 670 printf( 671"WARNING: R/W mount of %s denied. Filesystem is not clean - run fsck\n", 672 fs->fs_fsmnt); 673 error = EPERM; 674 goto out; 675 } 676 if ((fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) && 677 (mp->mnt_flag & MNT_FORCE)) { 678 printf("%s: lost blocks %jd files %d\n", fs->fs_fsmnt, 679 (intmax_t)fs->fs_pendingblocks, 680 fs->fs_pendinginodes); 681 fs->fs_pendingblocks = 0; 682 fs->fs_pendinginodes = 0; 683 } 684 } 685 if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) { 686 printf("%s: mount pending error: blocks %jd files %d\n", 687 fs->fs_fsmnt, (intmax_t)fs->fs_pendingblocks, 688 fs->fs_pendinginodes); 689 fs->fs_pendingblocks = 0; 690 fs->fs_pendinginodes = 0; 691 } 692 if ((fs->fs_flags & FS_GJOURNAL) != 0) { 693#ifdef UFS_GJOURNAL 694 /* 695 * Get journal provider name. 696 */ 697 size = 1024; 698 mp->mnt_gjprovider = malloc(size, M_UFSMNT, M_WAITOK); 699 if (g_io_getattr("GJOURNAL::provider", cp, &size, 700 mp->mnt_gjprovider) == 0) { 701 mp->mnt_gjprovider = realloc(mp->mnt_gjprovider, size, 702 M_UFSMNT, M_WAITOK); 703 MNT_ILOCK(mp); 704 mp->mnt_flag |= MNT_GJOURNAL; 705 MNT_IUNLOCK(mp); 706 } else { 707 printf( 708"WARNING: %s: GJOURNAL flag on fs but no gjournal provider below\n", 709 mp->mnt_stat.f_mntonname); 710 free(mp->mnt_gjprovider, M_UFSMNT); 711 mp->mnt_gjprovider = NULL; 712 } 713#else 714 printf( 715"WARNING: %s: GJOURNAL flag on fs but no UFS_GJOURNAL support\n", 716 mp->mnt_stat.f_mntonname); 717#endif 718 } else { 719 mp->mnt_gjprovider = NULL; 720 } 721 ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK | M_ZERO); 722 ump->um_cp = cp; 723 ump->um_bo = &devvp->v_bufobj; 724 ump->um_fs = malloc((u_long)fs->fs_sbsize, M_UFSMNT, M_WAITOK); 725 if (fs->fs_magic == FS_UFS1_MAGIC) { 726 ump->um_fstype = UFS1; 727 ump->um_balloc = ffs_balloc_ufs1; 728 } else { 729 ump->um_fstype = UFS2; 730 ump->um_balloc = ffs_balloc_ufs2; 731 } 732 ump->um_blkatoff = ffs_blkatoff; 733 ump->um_truncate = ffs_truncate; 734 ump->um_update = ffs_update; 735 ump->um_valloc = ffs_valloc; 736 ump->um_vfree = ffs_vfree; 737 ump->um_ifree = ffs_ifree; 738 mtx_init(UFS_MTX(ump), "FFS", "FFS Lock", MTX_DEF); 739 bcopy(bp->b_data, ump->um_fs, (u_int)fs->fs_sbsize); 740 if (fs->fs_sbsize < SBLOCKSIZE) 741 bp->b_flags |= B_INVAL | B_NOCACHE; 742 brelse(bp); 743 bp = NULL; 744 fs = ump->um_fs; 745 ffs_oldfscompat_read(fs, ump, sblockloc); 746 fs->fs_ronly = ronly; 747 size = fs->fs_cssize; 748 blks = howmany(size, fs->fs_fsize); 749 if (fs->fs_contigsumsize > 0) 750 size += fs->fs_ncg * sizeof(int32_t); 751 size += fs->fs_ncg * sizeof(u_int8_t); 752 space = malloc((u_long)size, M_UFSMNT, M_WAITOK); 753 fs->fs_csp = space; 754 for (i = 0; i < blks; i += fs->fs_frag) { 755 size = fs->fs_bsize; 756 if (i + fs->fs_frag > blks) 757 size = (blks - i) * fs->fs_fsize; 758 if ((error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), size, 759 cred, &bp)) != 0) { 760 free(fs->fs_csp, M_UFSMNT); 761 goto out; 762 } 763 bcopy(bp->b_data, space, (u_int)size); 764 space = (char *)space + size; 765 brelse(bp); 766 bp = NULL; 767 } 768 if (fs->fs_contigsumsize > 0) { 769 fs->fs_maxcluster = lp = space; 770 for (i = 0; i < fs->fs_ncg; i++) 771 *lp++ = fs->fs_contigsumsize; 772 space = lp; 773 } 774 size = fs->fs_ncg * sizeof(u_int8_t); 775 fs->fs_contigdirs = (u_int8_t *)space; 776 bzero(fs->fs_contigdirs, size); 777 fs->fs_active = NULL; 778 mp->mnt_data = ump; 779 mp->mnt_stat.f_fsid.val[0] = fs->fs_id[0]; 780 mp->mnt_stat.f_fsid.val[1] = fs->fs_id[1]; 781 nmp = NULL; 782 if (fs->fs_id[0] == 0 || fs->fs_id[1] == 0 || 783 (nmp = vfs_getvfs(&mp->mnt_stat.f_fsid))) { 784 if (nmp) 785 vfs_rel(nmp); 786 vfs_getnewfsid(mp); 787 } 788 mp->mnt_maxsymlinklen = fs->fs_maxsymlinklen; 789 MNT_ILOCK(mp); 790 mp->mnt_flag |= MNT_LOCAL; 791 MNT_IUNLOCK(mp); 792 if ((fs->fs_flags & FS_MULTILABEL) != 0) { 793#ifdef MAC 794 MNT_ILOCK(mp); 795 mp->mnt_flag |= MNT_MULTILABEL; 796 MNT_IUNLOCK(mp); 797#else 798 printf( 799"WARNING: %s: multilabel flag on fs but no MAC support\n", 800 mp->mnt_stat.f_mntonname); 801#endif 802 } 803 if ((fs->fs_flags & FS_ACLS) != 0) { 804#ifdef UFS_ACL 805 MNT_ILOCK(mp); 806 mp->mnt_flag |= MNT_ACLS; 807 MNT_IUNLOCK(mp); 808#else 809 printf( 810"WARNING: %s: ACLs flag on fs but no ACLs support\n", 811 mp->mnt_stat.f_mntonname); 812#endif 813 } 814 ump->um_mountp = mp; 815 ump->um_dev = dev; 816 ump->um_devvp = devvp; 817 ump->um_nindir = fs->fs_nindir; 818 ump->um_bptrtodb = fs->fs_fsbtodb; 819 ump->um_seqinc = fs->fs_frag; 820 for (i = 0; i < MAXQUOTAS; i++) 821 ump->um_quotas[i] = NULLVP; 822#ifdef UFS_EXTATTR 823 ufs_extattr_uepm_init(&ump->um_extattr); 824#endif 825 /* 826 * Set FS local "last mounted on" information (NULL pad) 827 */ 828 bzero(fs->fs_fsmnt, MAXMNTLEN); 829 strlcpy(fs->fs_fsmnt, mp->mnt_stat.f_mntonname, MAXMNTLEN); 830 831 if( mp->mnt_flag & MNT_ROOTFS) { 832 /* 833 * Root mount; update timestamp in mount structure. 834 * this will be used by the common root mount code 835 * to update the system clock. 836 */ 837 mp->mnt_time = fs->fs_time; 838 } 839 840 if (ronly == 0) { 841 if ((fs->fs_flags & FS_DOSOFTDEP) && 842 (error = softdep_mount(devvp, mp, fs, cred)) != 0) { 843 free(fs->fs_csp, M_UFSMNT); 844 goto out; 845 } 846 if (fs->fs_snapinum[0] != 0) 847 ffs_snapshot_mount(mp); 848 fs->fs_fmod = 1; 849 fs->fs_clean = 0; 850 (void) ffs_sbupdate(ump, MNT_WAIT, 0); 851 } 852 /* 853 * Initialize filesystem stat information in mount struct. 854 */ 855 MNT_ILOCK(mp); 856 mp->mnt_kern_flag |= MNTK_MPSAFE; 857 MNT_IUNLOCK(mp); 858#ifdef UFS_EXTATTR 859#ifdef UFS_EXTATTR_AUTOSTART 860 /* 861 * 862 * Auto-starting does the following: 863 * - check for /.attribute in the fs, and extattr_start if so 864 * - for each file in .attribute, enable that file with 865 * an attribute of the same name. 866 * Not clear how to report errors -- probably eat them. 867 * This would all happen while the filesystem was busy/not 868 * available, so would effectively be "atomic". 869 */ 870 mp->mnt_stat.f_iosize = fs->fs_bsize; 871 (void) ufs_extattr_autostart(mp, td); 872#endif /* !UFS_EXTATTR_AUTOSTART */ 873#endif /* !UFS_EXTATTR */ 874 return (0); 875out: 876 if (bp) 877 brelse(bp); 878 if (cp != NULL) { 879 DROP_GIANT(); 880 g_topology_lock(); 881 g_vfs_close(cp, td); 882 g_topology_unlock(); 883 PICKUP_GIANT(); 884 } 885 if (ump) { 886 mtx_destroy(UFS_MTX(ump)); 887 if (mp->mnt_gjprovider != NULL) { 888 free(mp->mnt_gjprovider, M_UFSMNT); 889 mp->mnt_gjprovider = NULL; 890 } 891 free(ump->um_fs, M_UFSMNT); 892 free(ump, M_UFSMNT); 893 mp->mnt_data = NULL; 894 } 895 return (error); 896} 897 898#include <sys/sysctl.h> 899static int bigcgs = 0; 900SYSCTL_INT(_debug, OID_AUTO, bigcgs, CTLFLAG_RW, &bigcgs, 0, ""); 901 902/* 903 * Sanity checks for loading old filesystem superblocks. 904 * See ffs_oldfscompat_write below for unwound actions. 905 * 906 * XXX - Parts get retired eventually. 907 * Unfortunately new bits get added. 908 */ 909static void 910ffs_oldfscompat_read(fs, ump, sblockloc) 911 struct fs *fs; 912 struct ufsmount *ump; 913 ufs2_daddr_t sblockloc; 914{ 915 off_t maxfilesize; 916 917 /* 918 * If not yet done, update fs_flags location and value of fs_sblockloc. 919 */ 920 if ((fs->fs_old_flags & FS_FLAGS_UPDATED) == 0) { 921 fs->fs_flags = fs->fs_old_flags; 922 fs->fs_old_flags |= FS_FLAGS_UPDATED; 923 fs->fs_sblockloc = sblockloc; 924 } 925 /* 926 * If not yet done, update UFS1 superblock with new wider fields. 927 */ 928 if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_maxbsize != fs->fs_bsize) { 929 fs->fs_maxbsize = fs->fs_bsize; 930 fs->fs_time = fs->fs_old_time; 931 fs->fs_size = fs->fs_old_size; 932 fs->fs_dsize = fs->fs_old_dsize; 933 fs->fs_csaddr = fs->fs_old_csaddr; 934 fs->fs_cstotal.cs_ndir = fs->fs_old_cstotal.cs_ndir; 935 fs->fs_cstotal.cs_nbfree = fs->fs_old_cstotal.cs_nbfree; 936 fs->fs_cstotal.cs_nifree = fs->fs_old_cstotal.cs_nifree; 937 fs->fs_cstotal.cs_nffree = fs->fs_old_cstotal.cs_nffree; 938 } 939 if (fs->fs_magic == FS_UFS1_MAGIC && 940 fs->fs_old_inodefmt < FS_44INODEFMT) { 941 fs->fs_maxfilesize = ((uint64_t)1 << 31) - 1; 942 fs->fs_qbmask = ~fs->fs_bmask; 943 fs->fs_qfmask = ~fs->fs_fmask; 944 } 945 if (fs->fs_magic == FS_UFS1_MAGIC) { 946 ump->um_savedmaxfilesize = fs->fs_maxfilesize; 947 maxfilesize = (uint64_t)0x80000000 * fs->fs_bsize - 1; 948 if (fs->fs_maxfilesize > maxfilesize) 949 fs->fs_maxfilesize = maxfilesize; 950 } 951 /* Compatibility for old filesystems */ 952 if (fs->fs_avgfilesize <= 0) 953 fs->fs_avgfilesize = AVFILESIZ; 954 if (fs->fs_avgfpdir <= 0) 955 fs->fs_avgfpdir = AFPDIR; 956 if (bigcgs) { 957 fs->fs_save_cgsize = fs->fs_cgsize; 958 fs->fs_cgsize = fs->fs_bsize; 959 } 960} 961 962/* 963 * Unwinding superblock updates for old filesystems. 964 * See ffs_oldfscompat_read above for details. 965 * 966 * XXX - Parts get retired eventually. 967 * Unfortunately new bits get added. 968 */ 969static void 970ffs_oldfscompat_write(fs, ump) 971 struct fs *fs; 972 struct ufsmount *ump; 973{ 974 975 /* 976 * Copy back UFS2 updated fields that UFS1 inspects. 977 */ 978 if (fs->fs_magic == FS_UFS1_MAGIC) { 979 fs->fs_old_time = fs->fs_time; 980 fs->fs_old_cstotal.cs_ndir = fs->fs_cstotal.cs_ndir; 981 fs->fs_old_cstotal.cs_nbfree = fs->fs_cstotal.cs_nbfree; 982 fs->fs_old_cstotal.cs_nifree = fs->fs_cstotal.cs_nifree; 983 fs->fs_old_cstotal.cs_nffree = fs->fs_cstotal.cs_nffree; 984 fs->fs_maxfilesize = ump->um_savedmaxfilesize; 985 } 986 if (bigcgs) { 987 fs->fs_cgsize = fs->fs_save_cgsize; 988 fs->fs_save_cgsize = 0; 989 } 990} 991 992/* 993 * unmount system call 994 */ 995static int 996ffs_unmount(mp, mntflags, td) 997 struct mount *mp; 998 int mntflags; 999 struct thread *td; 1000{ 1001 struct ufsmount *ump = VFSTOUFS(mp); 1002 struct fs *fs; 1003 int error, flags; 1004 1005 flags = 0; 1006 if (mntflags & MNT_FORCE) { 1007 flags |= FORCECLOSE; 1008 } 1009#ifdef UFS_EXTATTR 1010 if ((error = ufs_extattr_stop(mp, td))) { 1011 if (error != EOPNOTSUPP) 1012 printf("ffs_unmount: ufs_extattr_stop returned %d\n", 1013 error); 1014 } else { 1015 ufs_extattr_uepm_destroy(&ump->um_extattr); 1016 } 1017#endif 1018 if (mp->mnt_flag & MNT_SOFTDEP) { 1019 if ((error = softdep_flushfiles(mp, flags, td)) != 0) 1020 return (error); 1021 } else { 1022 if ((error = ffs_flushfiles(mp, flags, td)) != 0) 1023 return (error); 1024 } 1025 fs = ump->um_fs; 1026 UFS_LOCK(ump); 1027 if (fs->fs_pendingblocks != 0 || fs->fs_pendinginodes != 0) { 1028 printf("%s: unmount pending error: blocks %jd files %d\n", 1029 fs->fs_fsmnt, (intmax_t)fs->fs_pendingblocks, 1030 fs->fs_pendinginodes); 1031 fs->fs_pendingblocks = 0; 1032 fs->fs_pendinginodes = 0; 1033 } 1034 UFS_UNLOCK(ump); 1035 if (fs->fs_ronly == 0) { 1036 fs->fs_clean = fs->fs_flags & (FS_UNCLEAN|FS_NEEDSFSCK) ? 0 : 1; 1037 error = ffs_sbupdate(ump, MNT_WAIT, 0); 1038 if (error) { 1039 fs->fs_clean = 0; 1040 return (error); 1041 } 1042 } 1043 DROP_GIANT(); 1044 g_topology_lock(); 1045 g_vfs_close(ump->um_cp, td); 1046 g_topology_unlock(); 1047 PICKUP_GIANT(); 1048 vrele(ump->um_devvp); 1049 mtx_destroy(UFS_MTX(ump)); 1050 if (mp->mnt_gjprovider != NULL) { 1051 free(mp->mnt_gjprovider, M_UFSMNT); 1052 mp->mnt_gjprovider = NULL; 1053 } 1054 free(fs->fs_csp, M_UFSMNT); 1055 free(fs, M_UFSMNT); 1056 free(ump, M_UFSMNT); 1057 mp->mnt_data = NULL; 1058 MNT_ILOCK(mp); 1059 mp->mnt_flag &= ~MNT_LOCAL; 1060 MNT_IUNLOCK(mp); 1061 return (error); 1062} 1063 1064/* 1065 * Flush out all the files in a filesystem. 1066 */ 1067int 1068ffs_flushfiles(mp, flags, td) 1069 struct mount *mp; 1070 int flags; 1071 struct thread *td; 1072{ 1073 struct ufsmount *ump; 1074 int error; 1075 1076 ump = VFSTOUFS(mp); 1077#ifdef QUOTA 1078 if (mp->mnt_flag & MNT_QUOTA) { 1079 int i; 1080 error = vflush(mp, 0, SKIPSYSTEM|flags, td); 1081 if (error) 1082 return (error); 1083 for (i = 0; i < MAXQUOTAS; i++) { 1084 quotaoff(td, mp, i); 1085 } 1086 /* 1087 * Here we fall through to vflush again to ensure 1088 * that we have gotten rid of all the system vnodes. 1089 */ 1090 } 1091#endif 1092 ASSERT_VOP_LOCKED(ump->um_devvp, "ffs_flushfiles"); 1093 if (ump->um_devvp->v_vflag & VV_COPYONWRITE) { 1094 if ((error = vflush(mp, 0, SKIPSYSTEM | flags, td)) != 0) 1095 return (error); 1096 ffs_snapshot_unmount(mp); 1097 flags |= FORCECLOSE; 1098 /* 1099 * Here we fall through to vflush again to ensure 1100 * that we have gotten rid of all the system vnodes. 1101 */ 1102 } 1103 /* 1104 * Flush all the files. 1105 */ 1106 if ((error = vflush(mp, 0, flags, td)) != 0) 1107 return (error); 1108 /* 1109 * Flush filesystem metadata. 1110 */ 1111 vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY); 1112 error = VOP_FSYNC(ump->um_devvp, MNT_WAIT, td); 1113 VOP_UNLOCK(ump->um_devvp, 0); 1114 return (error); 1115} 1116 1117/* 1118 * Get filesystem statistics. 1119 */ 1120static int 1121ffs_statfs(mp, sbp, td) 1122 struct mount *mp; 1123 struct statfs *sbp; 1124 struct thread *td; 1125{ 1126 struct ufsmount *ump; 1127 struct fs *fs; 1128 1129 ump = VFSTOUFS(mp); 1130 fs = ump->um_fs; 1131 if (fs->fs_magic != FS_UFS1_MAGIC && fs->fs_magic != FS_UFS2_MAGIC) 1132 panic("ffs_statfs"); 1133 sbp->f_version = STATFS_VERSION; 1134 sbp->f_bsize = fs->fs_fsize; 1135 sbp->f_iosize = fs->fs_bsize; 1136 sbp->f_blocks = fs->fs_dsize; 1137 UFS_LOCK(ump); 1138 sbp->f_bfree = fs->fs_cstotal.cs_nbfree * fs->fs_frag + 1139 fs->fs_cstotal.cs_nffree + dbtofsb(fs, fs->fs_pendingblocks); 1140 sbp->f_bavail = freespace(fs, fs->fs_minfree) + 1141 dbtofsb(fs, fs->fs_pendingblocks); 1142 sbp->f_files = fs->fs_ncg * fs->fs_ipg - ROOTINO; 1143 sbp->f_ffree = fs->fs_cstotal.cs_nifree + fs->fs_pendinginodes; 1144 UFS_UNLOCK(ump); 1145 sbp->f_namemax = NAME_MAX; 1146 return (0); 1147} 1148 1149/* 1150 * Go through the disk queues to initiate sandbagged IO; 1151 * go through the inodes to write those that have been modified; 1152 * initiate the writing of the super block if it has been modified. 1153 * 1154 * Note: we are always called with the filesystem marked `MPBUSY'. 1155 */ 1156static int 1157ffs_sync(mp, waitfor, td) 1158 struct mount *mp; 1159 int waitfor; 1160 struct thread *td; 1161{ 1162 struct vnode *mvp, *vp, *devvp; 1163 struct inode *ip; 1164 struct ufsmount *ump = VFSTOUFS(mp); 1165 struct fs *fs; 1166 int error, count, wait, lockreq, allerror = 0; 1167 int suspend; 1168 int suspended; 1169 int secondary_writes; 1170 int secondary_accwrites; 1171 int softdep_deps; 1172 int softdep_accdeps; 1173 struct bufobj *bo; 1174 1175 fs = ump->um_fs; 1176 if (fs->fs_fmod != 0 && fs->fs_ronly != 0) { /* XXX */ 1177 printf("fs = %s\n", fs->fs_fsmnt); 1178 panic("ffs_sync: rofs mod"); 1179 } 1180 /* 1181 * Write back each (modified) inode. 1182 */ 1183 wait = 0; 1184 suspend = 0; 1185 suspended = 0; 1186 lockreq = LK_EXCLUSIVE | LK_NOWAIT; 1187 if (waitfor == MNT_SUSPEND) { 1188 suspend = 1; 1189 waitfor = MNT_WAIT; 1190 } 1191 if (waitfor == MNT_WAIT) { 1192 wait = 1; 1193 lockreq = LK_EXCLUSIVE; 1194 } 1195 lockreq |= LK_INTERLOCK | LK_SLEEPFAIL; 1196 MNT_ILOCK(mp); 1197loop: 1198 /* Grab snapshot of secondary write counts */ 1199 secondary_writes = mp->mnt_secondary_writes; 1200 secondary_accwrites = mp->mnt_secondary_accwrites; 1201 1202 /* Grab snapshot of softdep dependency counts */ 1203 MNT_IUNLOCK(mp); 1204 softdep_get_depcounts(mp, &softdep_deps, &softdep_accdeps); 1205 MNT_ILOCK(mp); 1206 1207 MNT_VNODE_FOREACH(vp, mp, mvp) { 1208 /* 1209 * Depend on the mntvnode_slock to keep things stable enough 1210 * for a quick test. Since there might be hundreds of 1211 * thousands of vnodes, we cannot afford even a subroutine 1212 * call unless there's a good chance that we have work to do. 1213 */ 1214 VI_LOCK(vp); 1215 if (vp->v_iflag & VI_DOOMED) { 1216 VI_UNLOCK(vp); 1217 continue; 1218 } 1219 ip = VTOI(vp); 1220 if (vp->v_type == VNON || ((ip->i_flag & 1221 (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) == 0 && 1222 vp->v_bufobj.bo_dirty.bv_cnt == 0)) { 1223 VI_UNLOCK(vp); 1224 continue; 1225 } 1226 MNT_IUNLOCK(mp); 1227 if ((error = vget(vp, lockreq, td)) != 0) { 1228 MNT_ILOCK(mp); 1229 if (error == ENOENT || error == ENOLCK) { 1230 MNT_VNODE_FOREACH_ABORT_ILOCKED(mp, mvp); 1231 goto loop; 1232 } 1233 continue; 1234 } 1235 if ((error = ffs_syncvnode(vp, waitfor)) != 0) 1236 allerror = error; 1237 vput(vp); 1238 MNT_ILOCK(mp); 1239 } 1240 MNT_IUNLOCK(mp); 1241 /* 1242 * Force stale filesystem control information to be flushed. 1243 */ 1244 if (waitfor == MNT_WAIT) { 1245 if ((error = softdep_flushworklist(ump->um_mountp, &count, td))) 1246 allerror = error; 1247 /* Flushed work items may create new vnodes to clean */ 1248 if (allerror == 0 && count) { 1249 MNT_ILOCK(mp); 1250 goto loop; 1251 } 1252 } 1253#ifdef QUOTA 1254 qsync(mp); 1255#endif 1256 devvp = ump->um_devvp; 1257 bo = &devvp->v_bufobj; 1258 BO_LOCK(bo); 1259 if (waitfor != MNT_LAZY && 1260 (bo->bo_numoutput > 0 || bo->bo_dirty.bv_cnt > 0)) { 1261 BO_UNLOCK(bo); 1262 vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); 1263 if ((error = VOP_FSYNC(devvp, waitfor, td)) != 0) 1264 allerror = error; 1265 VOP_UNLOCK(devvp, 0); 1266 if (allerror == 0 && waitfor == MNT_WAIT) { 1267 MNT_ILOCK(mp); 1268 goto loop; 1269 } 1270 } else if (suspend != 0) { 1271 if (softdep_check_suspend(mp, 1272 devvp, 1273 softdep_deps, 1274 softdep_accdeps, 1275 secondary_writes, 1276 secondary_accwrites) != 0) 1277 goto loop; /* More work needed */ 1278 mtx_assert(MNT_MTX(mp), MA_OWNED); 1279 mp->mnt_kern_flag |= MNTK_SUSPEND2 | MNTK_SUSPENDED; 1280 MNT_IUNLOCK(mp); 1281 suspended = 1; 1282 } else 1283 BO_UNLOCK(bo); 1284 /* 1285 * Write back modified superblock. 1286 */ 1287 if (fs->fs_fmod != 0 && 1288 (error = ffs_sbupdate(ump, waitfor, suspended)) != 0) 1289 allerror = error; 1290 return (allerror); 1291} 1292 1293int 1294ffs_vget(mp, ino, flags, vpp) 1295 struct mount *mp; 1296 ino_t ino; 1297 int flags; 1298 struct vnode **vpp; 1299{ 1300 struct fs *fs; 1301 struct inode *ip; 1302 struct ufsmount *ump; 1303 struct buf *bp; 1304 struct vnode *vp; 1305 struct cdev *dev; 1306 int error; 1307 1308 error = vfs_hash_get(mp, ino, flags, curthread, vpp, NULL, NULL); 1309 if (error || *vpp != NULL) 1310 return (error); 1311 1312 /* 1313 * We must promote to an exclusive lock for vnode creation. This 1314 * can happen if lookup is passed LOCKSHARED. 1315 */ 1316 if ((flags & LK_TYPE_MASK) == LK_SHARED) { 1317 flags &= ~LK_TYPE_MASK; 1318 flags |= LK_EXCLUSIVE; 1319 } 1320 1321 /* 1322 * We do not lock vnode creation as it is believed to be too 1323 * expensive for such rare case as simultaneous creation of vnode 1324 * for same ino by different processes. We just allow them to race 1325 * and check later to decide who wins. Let the race begin! 1326 */ 1327 1328 ump = VFSTOUFS(mp); 1329 dev = ump->um_dev; 1330 fs = ump->um_fs; 1331 1332 /* 1333 * If this MALLOC() is performed after the getnewvnode() 1334 * it might block, leaving a vnode with a NULL v_data to be 1335 * found by ffs_sync() if a sync happens to fire right then, 1336 * which will cause a panic because ffs_sync() blindly 1337 * dereferences vp->v_data (as well it should). 1338 */ 1339 ip = uma_zalloc(uma_inode, M_WAITOK | M_ZERO); 1340 1341 /* Allocate a new vnode/inode. */ 1342 if (fs->fs_magic == FS_UFS1_MAGIC) 1343 error = getnewvnode("ufs", mp, &ffs_vnodeops1, &vp); 1344 else 1345 error = getnewvnode("ufs", mp, &ffs_vnodeops2, &vp); 1346 if (error) { 1347 *vpp = NULL; 1348 uma_zfree(uma_inode, ip); 1349 return (error); 1350 } 1351 /* 1352 * FFS supports recursive and shared locking. 1353 */ 1354 VN_LOCK_AREC(vp); 1355 VN_LOCK_ASHARE(vp); 1356 vp->v_data = ip; 1357 vp->v_bufobj.bo_bsize = fs->fs_bsize; 1358 ip->i_vnode = vp; 1359 ip->i_ump = ump; 1360 ip->i_fs = fs; 1361 ip->i_dev = dev; 1362 ip->i_number = ino; 1363#ifdef QUOTA 1364 { 1365 int i; 1366 for (i = 0; i < MAXQUOTAS; i++) 1367 ip->i_dquot[i] = NODQUOT; 1368 } 1369#endif 1370 1371 lockmgr(vp->v_vnlock, LK_EXCLUSIVE, NULL); 1372 error = insmntque(vp, mp); 1373 if (error != 0) { 1374 uma_zfree(uma_inode, ip); 1375 *vpp = NULL; 1376 return (error); 1377 } 1378 error = vfs_hash_insert(vp, ino, flags, curthread, vpp, NULL, NULL); 1379 if (error || *vpp != NULL) 1380 return (error); 1381 1382 /* Read in the disk contents for the inode, copy into the inode. */ 1383 error = bread(ump->um_devvp, fsbtodb(fs, ino_to_fsba(fs, ino)), 1384 (int)fs->fs_bsize, NOCRED, &bp); 1385 if (error) { 1386 /* 1387 * The inode does not contain anything useful, so it would 1388 * be misleading to leave it on its hash chain. With mode 1389 * still zero, it will be unlinked and returned to the free 1390 * list by vput(). 1391 */ 1392 brelse(bp); 1393 vput(vp); 1394 *vpp = NULL; 1395 return (error); 1396 } 1397 if (ip->i_ump->um_fstype == UFS1) 1398 ip->i_din1 = uma_zalloc(uma_ufs1, M_WAITOK); 1399 else 1400 ip->i_din2 = uma_zalloc(uma_ufs2, M_WAITOK); 1401 ffs_load_inode(bp, ip, fs, ino); 1402 if (DOINGSOFTDEP(vp)) 1403 softdep_load_inodeblock(ip); 1404 else 1405 ip->i_effnlink = ip->i_nlink; 1406 bqrelse(bp); 1407 1408 /* 1409 * Initialize the vnode from the inode, check for aliases. 1410 * Note that the underlying vnode may have changed. 1411 */ 1412 if (ip->i_ump->um_fstype == UFS1) 1413 error = ufs_vinit(mp, &ffs_fifoops1, &vp); 1414 else 1415 error = ufs_vinit(mp, &ffs_fifoops2, &vp); 1416 if (error) { 1417 vput(vp); 1418 *vpp = NULL; 1419 return (error); 1420 } 1421 1422 /* 1423 * Finish inode initialization. 1424 */ 1425 1426 /* 1427 * Set up a generation number for this inode if it does not 1428 * already have one. This should only happen on old filesystems. 1429 */ 1430 if (ip->i_gen == 0) { 1431 ip->i_gen = arc4random() / 2 + 1; 1432 if ((vp->v_mount->mnt_flag & MNT_RDONLY) == 0) { 1433 ip->i_flag |= IN_MODIFIED; 1434 DIP_SET(ip, i_gen, ip->i_gen); 1435 } 1436 } 1437 /* 1438 * Ensure that uid and gid are correct. This is a temporary 1439 * fix until fsck has been changed to do the update. 1440 */ 1441 if (fs->fs_magic == FS_UFS1_MAGIC && /* XXX */ 1442 fs->fs_old_inodefmt < FS_44INODEFMT) { /* XXX */ 1443 ip->i_uid = ip->i_din1->di_ouid; /* XXX */ 1444 ip->i_gid = ip->i_din1->di_ogid; /* XXX */ 1445 } /* XXX */ 1446 1447#ifdef MAC 1448 if ((mp->mnt_flag & MNT_MULTILABEL) && ip->i_mode) { 1449 /* 1450 * If this vnode is already allocated, and we're running 1451 * multi-label, attempt to perform a label association 1452 * from the extended attributes on the inode. 1453 */ 1454 error = mac_vnode_associate_extattr(mp, vp); 1455 if (error) { 1456 /* ufs_inactive will release ip->i_devvp ref. */ 1457 vput(vp); 1458 *vpp = NULL; 1459 return (error); 1460 } 1461 } 1462#endif 1463 1464 *vpp = vp; 1465 return (0); 1466} 1467 1468/* 1469 * File handle to vnode 1470 * 1471 * Have to be really careful about stale file handles: 1472 * - check that the inode number is valid 1473 * - call ffs_vget() to get the locked inode 1474 * - check for an unallocated inode (i_mode == 0) 1475 * - check that the given client host has export rights and return 1476 * those rights via. exflagsp and credanonp 1477 */ 1478static int 1479ffs_fhtovp(mp, fhp, vpp) 1480 struct mount *mp; 1481 struct fid *fhp; 1482 struct vnode **vpp; 1483{ 1484 struct ufid *ufhp; 1485 struct fs *fs; 1486 1487 ufhp = (struct ufid *)fhp; 1488 fs = VFSTOUFS(mp)->um_fs; 1489 if (ufhp->ufid_ino < ROOTINO || 1490 ufhp->ufid_ino >= fs->fs_ncg * fs->fs_ipg) 1491 return (ESTALE); 1492 return (ufs_fhtovp(mp, ufhp, vpp)); 1493} 1494 1495/* 1496 * Initialize the filesystem. 1497 */ 1498static int 1499ffs_init(vfsp) 1500 struct vfsconf *vfsp; 1501{ 1502 1503 softdep_initialize(); 1504 return (ufs_init(vfsp)); 1505} 1506 1507/* 1508 * Undo the work of ffs_init(). 1509 */ 1510static int 1511ffs_uninit(vfsp) 1512 struct vfsconf *vfsp; 1513{ 1514 int ret; 1515 1516 ret = ufs_uninit(vfsp); 1517 softdep_uninitialize(); 1518 return (ret); 1519} 1520 1521/* 1522 * Write a superblock and associated information back to disk. 1523 */ 1524int 1525ffs_sbupdate(mp, waitfor, suspended) 1526 struct ufsmount *mp; 1527 int waitfor; 1528 int suspended; 1529{ 1530 struct fs *fs = mp->um_fs; 1531 struct buf *sbbp; 1532 struct buf *bp; 1533 int blks; 1534 void *space; 1535 int i, size, error, allerror = 0; 1536 1537 if (fs->fs_ronly == 1 && 1538 (mp->um_mountp->mnt_flag & (MNT_RDONLY | MNT_UPDATE)) != 1539 (MNT_RDONLY | MNT_UPDATE)) 1540 panic("ffs_sbupdate: write read-only filesystem"); 1541 /* 1542 * We use the superblock's buf to serialize calls to ffs_sbupdate(). 1543 */ 1544 sbbp = getblk(mp->um_devvp, btodb(fs->fs_sblockloc), (int)fs->fs_sbsize, 1545 0, 0, 0); 1546 /* 1547 * First write back the summary information. 1548 */ 1549 blks = howmany(fs->fs_cssize, fs->fs_fsize); 1550 space = fs->fs_csp; 1551 for (i = 0; i < blks; i += fs->fs_frag) { 1552 size = fs->fs_bsize; 1553 if (i + fs->fs_frag > blks) 1554 size = (blks - i) * fs->fs_fsize; 1555 bp = getblk(mp->um_devvp, fsbtodb(fs, fs->fs_csaddr + i), 1556 size, 0, 0, 0); 1557 bcopy(space, bp->b_data, (u_int)size); 1558 space = (char *)space + size; 1559 if (suspended) 1560 bp->b_flags |= B_VALIDSUSPWRT; 1561 if (waitfor != MNT_WAIT) 1562 bawrite(bp); 1563 else if ((error = bwrite(bp)) != 0) 1564 allerror = error; 1565 } 1566 /* 1567 * Now write back the superblock itself. If any errors occurred 1568 * up to this point, then fail so that the superblock avoids 1569 * being written out as clean. 1570 */ 1571 if (allerror) { 1572 brelse(sbbp); 1573 return (allerror); 1574 } 1575 bp = sbbp; 1576 if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_sblockloc != SBLOCK_UFS1 && 1577 (fs->fs_flags & FS_FLAGS_UPDATED) == 0) { 1578 printf("%s: correcting fs_sblockloc from %jd to %d\n", 1579 fs->fs_fsmnt, fs->fs_sblockloc, SBLOCK_UFS1); 1580 fs->fs_sblockloc = SBLOCK_UFS1; 1581 } 1582 if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_sblockloc != SBLOCK_UFS2 && 1583 (fs->fs_flags & FS_FLAGS_UPDATED) == 0) { 1584 printf("%s: correcting fs_sblockloc from %jd to %d\n", 1585 fs->fs_fsmnt, fs->fs_sblockloc, SBLOCK_UFS2); 1586 fs->fs_sblockloc = SBLOCK_UFS2; 1587 } 1588 fs->fs_fmod = 0; 1589 fs->fs_time = time_second; 1590 bcopy((caddr_t)fs, bp->b_data, (u_int)fs->fs_sbsize); 1591 ffs_oldfscompat_write((struct fs *)bp->b_data, mp); 1592 if (suspended) 1593 bp->b_flags |= B_VALIDSUSPWRT; 1594 if (waitfor != MNT_WAIT) 1595 bawrite(bp); 1596 else if ((error = bwrite(bp)) != 0) 1597 allerror = error; 1598 return (allerror); 1599} 1600 1601static int 1602ffs_extattrctl(struct mount *mp, int cmd, struct vnode *filename_vp, 1603 int attrnamespace, const char *attrname, struct thread *td) 1604{ 1605 1606#ifdef UFS_EXTATTR 1607 return (ufs_extattrctl(mp, cmd, filename_vp, attrnamespace, 1608 attrname, td)); 1609#else 1610 return (vfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace, 1611 attrname, td)); 1612#endif 1613} 1614 1615static void 1616ffs_ifree(struct ufsmount *ump, struct inode *ip) 1617{ 1618 1619 if (ump->um_fstype == UFS1 && ip->i_din1 != NULL) 1620 uma_zfree(uma_ufs1, ip->i_din1); 1621 else if (ip->i_din2 != NULL) 1622 uma_zfree(uma_ufs2, ip->i_din2); 1623 uma_zfree(uma_inode, ip); 1624} 1625 1626static int dobkgrdwrite = 1; 1627SYSCTL_INT(_debug, OID_AUTO, dobkgrdwrite, CTLFLAG_RW, &dobkgrdwrite, 0, 1628 "Do background writes (honoring the BV_BKGRDWRITE flag)?"); 1629 1630/* 1631 * Complete a background write started from bwrite. 1632 */ 1633static void 1634ffs_backgroundwritedone(struct buf *bp) 1635{ 1636 struct bufobj *bufobj; 1637 struct buf *origbp; 1638 1639 /* 1640 * Find the original buffer that we are writing. 1641 */ 1642 bufobj = bp->b_bufobj; 1643 BO_LOCK(bufobj); 1644 if ((origbp = gbincore(bp->b_bufobj, bp->b_lblkno)) == NULL) 1645 panic("backgroundwritedone: lost buffer"); 1646 /* Grab an extra reference to be dropped by the bufdone() below. */ 1647 bufobj_wrefl(bufobj); 1648 BO_UNLOCK(bufobj); 1649 /* 1650 * Process dependencies then return any unfinished ones. 1651 */ 1652 if (!LIST_EMPTY(&bp->b_dep)) 1653 buf_complete(bp); 1654#ifdef SOFTUPDATES 1655 if (!LIST_EMPTY(&bp->b_dep)) 1656 softdep_move_dependencies(bp, origbp); 1657#endif 1658 /* 1659 * This buffer is marked B_NOCACHE so when it is released 1660 * by biodone it will be tossed. 1661 */ 1662 bp->b_flags |= B_NOCACHE; 1663 bp->b_flags &= ~B_CACHE; 1664 bufdone(bp); 1665 BO_LOCK(bufobj); 1666 /* 1667 * Clear the BV_BKGRDINPROG flag in the original buffer 1668 * and awaken it if it is waiting for the write to complete. 1669 * If BV_BKGRDINPROG is not set in the original buffer it must 1670 * have been released and re-instantiated - which is not legal. 1671 */ 1672 KASSERT((origbp->b_vflags & BV_BKGRDINPROG), 1673 ("backgroundwritedone: lost buffer2")); 1674 origbp->b_vflags &= ~BV_BKGRDINPROG; 1675 if (origbp->b_vflags & BV_BKGRDWAIT) { 1676 origbp->b_vflags &= ~BV_BKGRDWAIT; 1677 wakeup(&origbp->b_xflags); 1678 } 1679 BO_UNLOCK(bufobj); 1680} 1681 1682 1683/* 1684 * Write, release buffer on completion. (Done by iodone 1685 * if async). Do not bother writing anything if the buffer 1686 * is invalid. 1687 * 1688 * Note that we set B_CACHE here, indicating that buffer is 1689 * fully valid and thus cacheable. This is true even of NFS 1690 * now so we set it generally. This could be set either here 1691 * or in biodone() since the I/O is synchronous. We put it 1692 * here. 1693 */ 1694static int 1695ffs_bufwrite(struct buf *bp) 1696{ 1697 int oldflags, s; 1698 struct buf *newbp; 1699 1700 CTR3(KTR_BUF, "bufwrite(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags); 1701 if (bp->b_flags & B_INVAL) { 1702 brelse(bp); 1703 return (0); 1704 } 1705 1706 oldflags = bp->b_flags; 1707 1708 if (!BUF_ISLOCKED(bp)) 1709 panic("bufwrite: buffer is not busy???"); 1710 s = splbio(); 1711 /* 1712 * If a background write is already in progress, delay 1713 * writing this block if it is asynchronous. Otherwise 1714 * wait for the background write to complete. 1715 */ 1716 BO_LOCK(bp->b_bufobj); 1717 if (bp->b_vflags & BV_BKGRDINPROG) { 1718 if (bp->b_flags & B_ASYNC) { 1719 BO_UNLOCK(bp->b_bufobj); 1720 splx(s); 1721 bdwrite(bp); 1722 return (0); 1723 } 1724 bp->b_vflags |= BV_BKGRDWAIT; 1725 msleep(&bp->b_xflags, BO_MTX(bp->b_bufobj), PRIBIO, "bwrbg", 0); 1726 if (bp->b_vflags & BV_BKGRDINPROG) 1727 panic("bufwrite: still writing"); 1728 } 1729 BO_UNLOCK(bp->b_bufobj); 1730 1731 /* Mark the buffer clean */ 1732 bundirty(bp); 1733 1734 /* 1735 * If this buffer is marked for background writing and we 1736 * do not have to wait for it, make a copy and write the 1737 * copy so as to leave this buffer ready for further use. 1738 * 1739 * This optimization eats a lot of memory. If we have a page 1740 * or buffer shortfall we can't do it. 1741 */ 1742 if (dobkgrdwrite && (bp->b_xflags & BX_BKGRDWRITE) && 1743 (bp->b_flags & B_ASYNC) && 1744 !vm_page_count_severe() && 1745 !buf_dirty_count_severe()) { 1746 KASSERT(bp->b_iodone == NULL, 1747 ("bufwrite: needs chained iodone (%p)", bp->b_iodone)); 1748 1749 /* get a new block */ 1750 newbp = geteblk(bp->b_bufsize); 1751 1752 /* 1753 * set it to be identical to the old block. We have to 1754 * set b_lblkno and BKGRDMARKER before calling bgetvp() 1755 * to avoid confusing the splay tree and gbincore(). 1756 */ 1757 memcpy(newbp->b_data, bp->b_data, bp->b_bufsize); 1758 newbp->b_lblkno = bp->b_lblkno; 1759 newbp->b_xflags |= BX_BKGRDMARKER; 1760 BO_LOCK(bp->b_bufobj); 1761 bp->b_vflags |= BV_BKGRDINPROG; 1762 bgetvp(bp->b_vp, newbp); 1763 BO_UNLOCK(bp->b_bufobj); 1764 newbp->b_bufobj = &bp->b_vp->v_bufobj; 1765 newbp->b_blkno = bp->b_blkno; 1766 newbp->b_offset = bp->b_offset; 1767 newbp->b_iodone = ffs_backgroundwritedone; 1768 newbp->b_flags |= B_ASYNC; 1769 newbp->b_flags &= ~B_INVAL; 1770 1771#ifdef SOFTUPDATES 1772 /* move over the dependencies */ 1773 if (!LIST_EMPTY(&bp->b_dep)) 1774 softdep_move_dependencies(bp, newbp); 1775#endif 1776 1777 /* 1778 * Initiate write on the copy, release the original to 1779 * the B_LOCKED queue so that it cannot go away until 1780 * the background write completes. If not locked it could go 1781 * away and then be reconstituted while it was being written. 1782 * If the reconstituted buffer were written, we could end up 1783 * with two background copies being written at the same time. 1784 */ 1785 bqrelse(bp); 1786 bp = newbp; 1787 } 1788 1789 /* Let the normal bufwrite do the rest for us */ 1790 return (bufwrite(bp)); 1791} 1792 1793 1794static void 1795ffs_geom_strategy(struct bufobj *bo, struct buf *bp) 1796{ 1797 struct vnode *vp; 1798 int error; 1799 struct buf *tbp; 1800 1801 vp = bo->__bo_vnode; 1802 if (bp->b_iocmd == BIO_WRITE) { 1803 if ((bp->b_flags & B_VALIDSUSPWRT) == 0 && 1804 bp->b_vp != NULL && bp->b_vp->v_mount != NULL && 1805 (bp->b_vp->v_mount->mnt_kern_flag & MNTK_SUSPENDED) != 0) 1806 panic("ffs_geom_strategy: bad I/O"); 1807 bp->b_flags &= ~B_VALIDSUSPWRT; 1808 if ((vp->v_vflag & VV_COPYONWRITE) && 1809 vp->v_rdev->si_snapdata != NULL) { 1810 if ((bp->b_flags & B_CLUSTER) != 0) { 1811 runningbufwakeup(bp); 1812 TAILQ_FOREACH(tbp, &bp->b_cluster.cluster_head, 1813 b_cluster.cluster_entry) { 1814 error = ffs_copyonwrite(vp, tbp); 1815 if (error != 0 && 1816 error != EOPNOTSUPP) { 1817 bp->b_error = error; 1818 bp->b_ioflags |= BIO_ERROR; 1819 bufdone(bp); 1820 return; 1821 } 1822 } 1823 bp->b_runningbufspace = bp->b_bufsize; 1824 atomic_add_int(&runningbufspace, 1825 bp->b_runningbufspace); 1826 } else { 1827 error = ffs_copyonwrite(vp, bp); 1828 if (error != 0 && error != EOPNOTSUPP) { 1829 bp->b_error = error; 1830 bp->b_ioflags |= BIO_ERROR; 1831 bufdone(bp); 1832 return; 1833 } 1834 } 1835 } 1836#ifdef SOFTUPDATES 1837 if ((bp->b_flags & B_CLUSTER) != 0) { 1838 TAILQ_FOREACH(tbp, &bp->b_cluster.cluster_head, 1839 b_cluster.cluster_entry) { 1840 if (!LIST_EMPTY(&tbp->b_dep)) 1841 buf_start(tbp); 1842 } 1843 } else { 1844 if (!LIST_EMPTY(&bp->b_dep)) 1845 buf_start(bp); 1846 } 1847 1848#endif 1849 } 1850 g_vfs_strategy(bo, bp); 1851} 1852