17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5da6c28aaSamw * Common Development and Distribution License (the "License"). 6da6c28aaSamw * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*0fbb751dSJohn Levon * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 267c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 307c478bd9Sstevel@tonic-gate * The Regents of the University of California 317c478bd9Sstevel@tonic-gate * All Rights Reserved 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 347c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 357c478bd9Sstevel@tonic-gate * contributors. 367c478bd9Sstevel@tonic-gate */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <sys/types.h> 407c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 417c478bd9Sstevel@tonic-gate #include <sys/param.h> 427c478bd9Sstevel@tonic-gate #include <sys/buf.h> 437c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 447c478bd9Sstevel@tonic-gate #include <sys/debug.h> 457c478bd9Sstevel@tonic-gate #include <sys/errno.h> 467c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 477c478bd9Sstevel@tonic-gate #include <sys/swap.h> 487c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 497c478bd9Sstevel@tonic-gate #include <sys/cred.h> 507c478bd9Sstevel@tonic-gate #include <sys/fs/snode.h> 517c478bd9Sstevel@tonic-gate #include <sys/thread.h> 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #include <fs/fs_subr.h> 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * This is the loadable module wrapper. 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate static vfsdef_t vfw = { 617c478bd9Sstevel@tonic-gate VFSDEF_VERSION, 627c478bd9Sstevel@tonic-gate "specfs", 637c478bd9Sstevel@tonic-gate specinit, 64*0fbb751dSJohn Levon VSW_ZMOUNT, 657c478bd9Sstevel@tonic-gate NULL 667c478bd9Sstevel@tonic-gate }; 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate extern struct mod_ops mod_fsops; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /* 717c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate static struct modlfs modlfs = { 747c478bd9Sstevel@tonic-gate &mod_fsops, "filesystem for specfs", &vfw 757c478bd9Sstevel@tonic-gate }; 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 787c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modlfs, NULL 797c478bd9Sstevel@tonic-gate }; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate int 827c478bd9Sstevel@tonic-gate _init(void) 837c478bd9Sstevel@tonic-gate { 847c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate int 887c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 897c478bd9Sstevel@tonic-gate { 907c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate /* 947c478bd9Sstevel@tonic-gate * N.B. 957c478bd9Sstevel@tonic-gate * No _fini routine. This module cannot be unloaded once loaded. 967c478bd9Sstevel@tonic-gate * The NO_UNLOAD_STUB in modstub.s must change if this module ever 97da6c28aaSamw * is modified to become unloadable. 987c478bd9Sstevel@tonic-gate */ 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate kmutex_t spec_syncbusy; /* initialized in specinit() */ 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate /* 1037c478bd9Sstevel@tonic-gate * Run though all the snodes and force write-back 1047c478bd9Sstevel@tonic-gate * of all dirty pages on the block devices. 1057c478bd9Sstevel@tonic-gate */ 1067c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1077c478bd9Sstevel@tonic-gate int 1087c478bd9Sstevel@tonic-gate spec_sync(struct vfs *vfsp, 1097c478bd9Sstevel@tonic-gate short flag, 1107c478bd9Sstevel@tonic-gate struct cred *cr) 1117c478bd9Sstevel@tonic-gate { 1127c478bd9Sstevel@tonic-gate struct snode *sync_list; 1137c478bd9Sstevel@tonic-gate register struct snode **spp, *sp, *spnext; 1147c478bd9Sstevel@tonic-gate register struct vnode *vp; 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate if (mutex_tryenter(&spec_syncbusy) == 0) 1177c478bd9Sstevel@tonic-gate return (0); 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate if (flag & SYNC_ATTR) { 1207c478bd9Sstevel@tonic-gate mutex_exit(&spec_syncbusy); 1217c478bd9Sstevel@tonic-gate return (0); 1227c478bd9Sstevel@tonic-gate } 1237c478bd9Sstevel@tonic-gate mutex_enter(&stable_lock); 1247c478bd9Sstevel@tonic-gate sync_list = NULL; 1257c478bd9Sstevel@tonic-gate /* 1267c478bd9Sstevel@tonic-gate * Find all the snodes that are dirty and add them to the sync_list 1277c478bd9Sstevel@tonic-gate */ 1287c478bd9Sstevel@tonic-gate for (spp = stable; spp < &stable[STABLESIZE]; spp++) { 1297c478bd9Sstevel@tonic-gate for (sp = *spp; sp != NULL; sp = sp->s_next) { 1307c478bd9Sstevel@tonic-gate vp = STOV(sp); 1317c478bd9Sstevel@tonic-gate /* 1327c478bd9Sstevel@tonic-gate * Don't bother sync'ing a vp if it's 1337c478bd9Sstevel@tonic-gate * part of a virtual swap device. 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate if (IS_SWAPVP(vp)) 1367c478bd9Sstevel@tonic-gate continue; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate if (vp->v_type == VBLK && vn_has_cached_data(vp)) { 1397c478bd9Sstevel@tonic-gate /* 1407c478bd9Sstevel@tonic-gate * Prevent vp from going away before we 1417c478bd9Sstevel@tonic-gate * we get a chance to do a VOP_PUTPAGE 1427c478bd9Sstevel@tonic-gate * via sync_list processing 1437c478bd9Sstevel@tonic-gate */ 1447c478bd9Sstevel@tonic-gate VN_HOLD(vp); 1457c478bd9Sstevel@tonic-gate sp->s_list = sync_list; 1467c478bd9Sstevel@tonic-gate sync_list = sp; 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate mutex_exit(&stable_lock); 1517c478bd9Sstevel@tonic-gate /* 1527c478bd9Sstevel@tonic-gate * Now write out all the snodes we marked asynchronously. 1537c478bd9Sstevel@tonic-gate */ 1547c478bd9Sstevel@tonic-gate for (sp = sync_list; sp != NULL; sp = spnext) { 1557c478bd9Sstevel@tonic-gate spnext = sp->s_list; 1567c478bd9Sstevel@tonic-gate vp = STOV(sp); 157da6c28aaSamw (void) VOP_PUTPAGE(vp, (offset_t)0, (uint_t)0, B_ASYNC, cr, 158da6c28aaSamw NULL); 1597c478bd9Sstevel@tonic-gate VN_RELE(vp); /* Release our hold on vnode */ 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate mutex_exit(&spec_syncbusy); 1627c478bd9Sstevel@tonic-gate return (0); 1637c478bd9Sstevel@tonic-gate } 164