xref: /titanic_41/usr/src/uts/common/fs/specfs/specvfsops.c (revision b509e89b2befbaa42939abad9da1d7f5a8c6aaae)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 /*
30  * University Copyright- Copyright (c) 1982, 1986, 1988
31  * The Regents of the University of California
32  * All Rights Reserved
33  *
34  * University Acknowledgment- Portions of this document are derived from
35  * software developed by the University of California, Berkeley, and its
36  * contributors.
37  */
38 
39 
40 #pragma ident	"%Z%%M%	%I%	%E% SMI"
41 
42 #include <sys/types.h>
43 #include <sys/t_lock.h>
44 #include <sys/param.h>
45 #include <sys/buf.h>
46 #include <sys/cmn_err.h>
47 #include <sys/debug.h>
48 #include <sys/errno.h>
49 #include <sys/vfs.h>
50 #include <sys/swap.h>
51 #include <sys/vnode.h>
52 #include <sys/cred.h>
53 #include <sys/fs/snode.h>
54 #include <sys/thread.h>
55 
56 #include <fs/fs_subr.h>
57 
58 /*
59  * This is the loadable module wrapper.
60  */
61 #include <sys/modctl.h>
62 
63 static vfsdef_t vfw = {
64 	VFSDEF_VERSION,
65 	"specfs",
66 	specinit,
67 	0,
68 	NULL
69 };
70 
71 extern struct mod_ops mod_fsops;
72 
73 /*
74  * Module linkage information for the kernel.
75  */
76 static struct modlfs modlfs = {
77 	&mod_fsops, "filesystem for specfs", &vfw
78 };
79 
80 static struct modlinkage modlinkage = {
81 	MODREV_1, (void *)&modlfs, NULL
82 };
83 
84 int
85 _init(void)
86 {
87 	return (mod_install(&modlinkage));
88 }
89 
90 int
91 _info(struct modinfo *modinfop)
92 {
93 	return (mod_info(&modlinkage, modinfop));
94 }
95 
96 /*
97  * N.B.
98  * No _fini routine. This module cannot be unloaded once loaded.
99  * The NO_UNLOAD_STUB in modstub.s must change if this module ever
100  * is modified to become unloadable.
101  */
102 
103 kmutex_t spec_syncbusy;		/* initialized in specinit() */
104 
105 /*
106  * Run though all the snodes and force write-back
107  * of all dirty pages on the block devices.
108  */
109 /*ARGSUSED*/
110 int
111 spec_sync(struct vfs *vfsp,
112 	short	flag,
113 	struct cred *cr)
114 {
115 	struct snode *sync_list;
116 	register struct snode **spp, *sp, *spnext;
117 	register struct vnode *vp;
118 
119 	if (mutex_tryenter(&spec_syncbusy) == 0)
120 		return (0);
121 
122 	if (flag & SYNC_ATTR) {
123 		mutex_exit(&spec_syncbusy);
124 		return (0);
125 	}
126 	mutex_enter(&stable_lock);
127 	sync_list = NULL;
128 	/*
129 	 * Find all the snodes that are dirty and add them to the sync_list
130 	 */
131 	for (spp = stable; spp < &stable[STABLESIZE]; spp++) {
132 		for (sp = *spp; sp != NULL; sp = sp->s_next) {
133 			vp = STOV(sp);
134 			/*
135 			 * Don't bother sync'ing a vp if it's
136 			 * part of a virtual swap device.
137 			 */
138 			if (IS_SWAPVP(vp))
139 				continue;
140 
141 			if (vp->v_type == VBLK && vn_has_cached_data(vp)) {
142 				/*
143 				 * Prevent vp from going away before we
144 				 * we get a chance to do a VOP_PUTPAGE
145 				 * via sync_list processing
146 				 */
147 				VN_HOLD(vp);
148 				sp->s_list = sync_list;
149 				sync_list = sp;
150 			}
151 		}
152 	}
153 	mutex_exit(&stable_lock);
154 	/*
155 	 * Now write out all the snodes we marked asynchronously.
156 	 */
157 	for (sp = sync_list; sp != NULL; sp = spnext) {
158 		spnext = sp->s_list;
159 		vp = STOV(sp);
160 		(void) VOP_PUTPAGE(vp, (offset_t)0, (uint_t)0, B_ASYNC, cr,
161 		    NULL);
162 		VN_RELE(vp);		/* Release our hold on vnode */
163 	}
164 	mutex_exit(&spec_syncbusy);
165 	return (0);
166 }
167