xref: /onnv-gate/usr/src/uts/common/fs/specfs/specvfsops.c (revision 12633:9f2cda0ed938)
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
55331Samw  * Common Development and Distribution License (the "License").
65331Samw  * 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*12633Sjohn.levon@sun.com  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
260Sstevel@tonic-gate /*	  All Rights Reserved  	*/
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
300Sstevel@tonic-gate  * The Regents of the University of California
310Sstevel@tonic-gate  * All Rights Reserved
320Sstevel@tonic-gate  *
330Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
340Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
350Sstevel@tonic-gate  * contributors.
360Sstevel@tonic-gate  */
370Sstevel@tonic-gate 
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #include <sys/types.h>
400Sstevel@tonic-gate #include <sys/t_lock.h>
410Sstevel@tonic-gate #include <sys/param.h>
420Sstevel@tonic-gate #include <sys/buf.h>
430Sstevel@tonic-gate #include <sys/cmn_err.h>
440Sstevel@tonic-gate #include <sys/debug.h>
450Sstevel@tonic-gate #include <sys/errno.h>
460Sstevel@tonic-gate #include <sys/vfs.h>
470Sstevel@tonic-gate #include <sys/swap.h>
480Sstevel@tonic-gate #include <sys/vnode.h>
490Sstevel@tonic-gate #include <sys/cred.h>
500Sstevel@tonic-gate #include <sys/fs/snode.h>
510Sstevel@tonic-gate #include <sys/thread.h>
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #include <fs/fs_subr.h>
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate  * This is the loadable module wrapper.
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate #include <sys/modctl.h>
590Sstevel@tonic-gate 
600Sstevel@tonic-gate static vfsdef_t vfw = {
610Sstevel@tonic-gate 	VFSDEF_VERSION,
620Sstevel@tonic-gate 	"specfs",
630Sstevel@tonic-gate 	specinit,
64*12633Sjohn.levon@sun.com 	VSW_ZMOUNT,
650Sstevel@tonic-gate 	NULL
660Sstevel@tonic-gate };
670Sstevel@tonic-gate 
680Sstevel@tonic-gate extern struct mod_ops mod_fsops;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate /*
710Sstevel@tonic-gate  * Module linkage information for the kernel.
720Sstevel@tonic-gate  */
730Sstevel@tonic-gate static struct modlfs modlfs = {
740Sstevel@tonic-gate 	&mod_fsops, "filesystem for specfs", &vfw
750Sstevel@tonic-gate };
760Sstevel@tonic-gate 
770Sstevel@tonic-gate static struct modlinkage modlinkage = {
780Sstevel@tonic-gate 	MODREV_1, (void *)&modlfs, NULL
790Sstevel@tonic-gate };
800Sstevel@tonic-gate 
810Sstevel@tonic-gate int
_init(void)820Sstevel@tonic-gate _init(void)
830Sstevel@tonic-gate {
840Sstevel@tonic-gate 	return (mod_install(&modlinkage));
850Sstevel@tonic-gate }
860Sstevel@tonic-gate 
870Sstevel@tonic-gate int
_info(struct modinfo * modinfop)880Sstevel@tonic-gate _info(struct modinfo *modinfop)
890Sstevel@tonic-gate {
900Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
910Sstevel@tonic-gate }
920Sstevel@tonic-gate 
930Sstevel@tonic-gate /*
940Sstevel@tonic-gate  * N.B.
950Sstevel@tonic-gate  * No _fini routine. This module cannot be unloaded once loaded.
960Sstevel@tonic-gate  * The NO_UNLOAD_STUB in modstub.s must change if this module ever
975331Samw  * is modified to become unloadable.
980Sstevel@tonic-gate  */
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate kmutex_t spec_syncbusy;		/* initialized in specinit() */
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate  * Run though all the snodes and force write-back
1040Sstevel@tonic-gate  * of all dirty pages on the block devices.
1050Sstevel@tonic-gate  */
1060Sstevel@tonic-gate /*ARGSUSED*/
1070Sstevel@tonic-gate int
spec_sync(struct vfs * vfsp,short flag,struct cred * cr)1080Sstevel@tonic-gate spec_sync(struct vfs *vfsp,
1090Sstevel@tonic-gate 	short	flag,
1100Sstevel@tonic-gate 	struct cred *cr)
1110Sstevel@tonic-gate {
1120Sstevel@tonic-gate 	struct snode *sync_list;
1130Sstevel@tonic-gate 	register struct snode **spp, *sp, *spnext;
1140Sstevel@tonic-gate 	register struct vnode *vp;
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate 	if (mutex_tryenter(&spec_syncbusy) == 0)
1170Sstevel@tonic-gate 		return (0);
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 	if (flag & SYNC_ATTR) {
1200Sstevel@tonic-gate 		mutex_exit(&spec_syncbusy);
1210Sstevel@tonic-gate 		return (0);
1220Sstevel@tonic-gate 	}
1230Sstevel@tonic-gate 	mutex_enter(&stable_lock);
1240Sstevel@tonic-gate 	sync_list = NULL;
1250Sstevel@tonic-gate 	/*
1260Sstevel@tonic-gate 	 * Find all the snodes that are dirty and add them to the sync_list
1270Sstevel@tonic-gate 	 */
1280Sstevel@tonic-gate 	for (spp = stable; spp < &stable[STABLESIZE]; spp++) {
1290Sstevel@tonic-gate 		for (sp = *spp; sp != NULL; sp = sp->s_next) {
1300Sstevel@tonic-gate 			vp = STOV(sp);
1310Sstevel@tonic-gate 			/*
1320Sstevel@tonic-gate 			 * Don't bother sync'ing a vp if it's
1330Sstevel@tonic-gate 			 * part of a virtual swap device.
1340Sstevel@tonic-gate 			 */
1350Sstevel@tonic-gate 			if (IS_SWAPVP(vp))
1360Sstevel@tonic-gate 				continue;
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 			if (vp->v_type == VBLK && vn_has_cached_data(vp)) {
1390Sstevel@tonic-gate 				/*
1400Sstevel@tonic-gate 				 * Prevent vp from going away before we
1410Sstevel@tonic-gate 				 * we get a chance to do a VOP_PUTPAGE
1420Sstevel@tonic-gate 				 * via sync_list processing
1430Sstevel@tonic-gate 				 */
1440Sstevel@tonic-gate 				VN_HOLD(vp);
1450Sstevel@tonic-gate 				sp->s_list = sync_list;
1460Sstevel@tonic-gate 				sync_list = sp;
1470Sstevel@tonic-gate 			}
1480Sstevel@tonic-gate 		}
1490Sstevel@tonic-gate 	}
1500Sstevel@tonic-gate 	mutex_exit(&stable_lock);
1510Sstevel@tonic-gate 	/*
1520Sstevel@tonic-gate 	 * Now write out all the snodes we marked asynchronously.
1530Sstevel@tonic-gate 	 */
1540Sstevel@tonic-gate 	for (sp = sync_list; sp != NULL; sp = spnext) {
1550Sstevel@tonic-gate 		spnext = sp->s_list;
1560Sstevel@tonic-gate 		vp = STOV(sp);
1575331Samw 		(void) VOP_PUTPAGE(vp, (offset_t)0, (uint_t)0, B_ASYNC, cr,
1585331Samw 		    NULL);
1590Sstevel@tonic-gate 		VN_RELE(vp);		/* Release our hold on vnode */
1600Sstevel@tonic-gate 	}
1610Sstevel@tonic-gate 	mutex_exit(&spec_syncbusy);
1620Sstevel@tonic-gate 	return (0);
1630Sstevel@tonic-gate }
164