10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*5331Samw * Common Development and Distribution License (the "License"). 6*5331Samw * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*5331Samw * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 310Sstevel@tonic-gate * The Regents of the University of California 320Sstevel@tonic-gate * All Rights Reserved 330Sstevel@tonic-gate * 340Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 350Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 360Sstevel@tonic-gate * contributors. 370Sstevel@tonic-gate */ 380Sstevel@tonic-gate 390Sstevel@tonic-gate 400Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 410Sstevel@tonic-gate 420Sstevel@tonic-gate #include <sys/types.h> 430Sstevel@tonic-gate #include <sys/t_lock.h> 440Sstevel@tonic-gate #include <sys/param.h> 450Sstevel@tonic-gate #include <sys/buf.h> 460Sstevel@tonic-gate #include <sys/cmn_err.h> 470Sstevel@tonic-gate #include <sys/debug.h> 480Sstevel@tonic-gate #include <sys/errno.h> 490Sstevel@tonic-gate #include <sys/vfs.h> 500Sstevel@tonic-gate #include <sys/swap.h> 510Sstevel@tonic-gate #include <sys/vnode.h> 520Sstevel@tonic-gate #include <sys/cred.h> 530Sstevel@tonic-gate #include <sys/fs/snode.h> 540Sstevel@tonic-gate #include <sys/thread.h> 550Sstevel@tonic-gate 560Sstevel@tonic-gate #include <fs/fs_subr.h> 570Sstevel@tonic-gate 580Sstevel@tonic-gate /* 590Sstevel@tonic-gate * This is the loadable module wrapper. 600Sstevel@tonic-gate */ 610Sstevel@tonic-gate #include <sys/modctl.h> 620Sstevel@tonic-gate 630Sstevel@tonic-gate static vfsdef_t vfw = { 640Sstevel@tonic-gate VFSDEF_VERSION, 650Sstevel@tonic-gate "specfs", 660Sstevel@tonic-gate specinit, 670Sstevel@tonic-gate 0, 680Sstevel@tonic-gate NULL 690Sstevel@tonic-gate }; 700Sstevel@tonic-gate 710Sstevel@tonic-gate extern struct mod_ops mod_fsops; 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* 740Sstevel@tonic-gate * Module linkage information for the kernel. 750Sstevel@tonic-gate */ 760Sstevel@tonic-gate static struct modlfs modlfs = { 770Sstevel@tonic-gate &mod_fsops, "filesystem for specfs", &vfw 780Sstevel@tonic-gate }; 790Sstevel@tonic-gate 800Sstevel@tonic-gate static struct modlinkage modlinkage = { 810Sstevel@tonic-gate MODREV_1, (void *)&modlfs, NULL 820Sstevel@tonic-gate }; 830Sstevel@tonic-gate 840Sstevel@tonic-gate int 850Sstevel@tonic-gate _init(void) 860Sstevel@tonic-gate { 870Sstevel@tonic-gate return (mod_install(&modlinkage)); 880Sstevel@tonic-gate } 890Sstevel@tonic-gate 900Sstevel@tonic-gate int 910Sstevel@tonic-gate _info(struct modinfo *modinfop) 920Sstevel@tonic-gate { 930Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 940Sstevel@tonic-gate } 950Sstevel@tonic-gate 960Sstevel@tonic-gate /* 970Sstevel@tonic-gate * N.B. 980Sstevel@tonic-gate * No _fini routine. This module cannot be unloaded once loaded. 990Sstevel@tonic-gate * The NO_UNLOAD_STUB in modstub.s must change if this module ever 100*5331Samw * is modified to become unloadable. 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate kmutex_t spec_syncbusy; /* initialized in specinit() */ 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate /* 1060Sstevel@tonic-gate * Run though all the snodes and force write-back 1070Sstevel@tonic-gate * of all dirty pages on the block devices. 1080Sstevel@tonic-gate */ 1090Sstevel@tonic-gate /*ARGSUSED*/ 1100Sstevel@tonic-gate int 1110Sstevel@tonic-gate spec_sync(struct vfs *vfsp, 1120Sstevel@tonic-gate short flag, 1130Sstevel@tonic-gate struct cred *cr) 1140Sstevel@tonic-gate { 1150Sstevel@tonic-gate struct snode *sync_list; 1160Sstevel@tonic-gate register struct snode **spp, *sp, *spnext; 1170Sstevel@tonic-gate register struct vnode *vp; 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate if (mutex_tryenter(&spec_syncbusy) == 0) 1200Sstevel@tonic-gate return (0); 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate if (flag & SYNC_ATTR) { 1230Sstevel@tonic-gate mutex_exit(&spec_syncbusy); 1240Sstevel@tonic-gate return (0); 1250Sstevel@tonic-gate } 1260Sstevel@tonic-gate mutex_enter(&stable_lock); 1270Sstevel@tonic-gate sync_list = NULL; 1280Sstevel@tonic-gate /* 1290Sstevel@tonic-gate * Find all the snodes that are dirty and add them to the sync_list 1300Sstevel@tonic-gate */ 1310Sstevel@tonic-gate for (spp = stable; spp < &stable[STABLESIZE]; spp++) { 1320Sstevel@tonic-gate for (sp = *spp; sp != NULL; sp = sp->s_next) { 1330Sstevel@tonic-gate vp = STOV(sp); 1340Sstevel@tonic-gate /* 1350Sstevel@tonic-gate * Don't bother sync'ing a vp if it's 1360Sstevel@tonic-gate * part of a virtual swap device. 1370Sstevel@tonic-gate */ 1380Sstevel@tonic-gate if (IS_SWAPVP(vp)) 1390Sstevel@tonic-gate continue; 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate if (vp->v_type == VBLK && vn_has_cached_data(vp)) { 1420Sstevel@tonic-gate /* 1430Sstevel@tonic-gate * Prevent vp from going away before we 1440Sstevel@tonic-gate * we get a chance to do a VOP_PUTPAGE 1450Sstevel@tonic-gate * via sync_list processing 1460Sstevel@tonic-gate */ 1470Sstevel@tonic-gate VN_HOLD(vp); 1480Sstevel@tonic-gate sp->s_list = sync_list; 1490Sstevel@tonic-gate sync_list = sp; 1500Sstevel@tonic-gate } 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate } 1530Sstevel@tonic-gate mutex_exit(&stable_lock); 1540Sstevel@tonic-gate /* 1550Sstevel@tonic-gate * Now write out all the snodes we marked asynchronously. 1560Sstevel@tonic-gate */ 1570Sstevel@tonic-gate for (sp = sync_list; sp != NULL; sp = spnext) { 1580Sstevel@tonic-gate spnext = sp->s_list; 1590Sstevel@tonic-gate vp = STOV(sp); 160*5331Samw (void) VOP_PUTPAGE(vp, (offset_t)0, (uint_t)0, B_ASYNC, cr, 161*5331Samw NULL); 1620Sstevel@tonic-gate VN_RELE(vp); /* Release our hold on vnode */ 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate mutex_exit(&spec_syncbusy); 1650Sstevel@tonic-gate return (0); 1660Sstevel@tonic-gate } 167