vfs_trans.c revision 1.2.2.2 1 1.2.2.2 ad /* $NetBSD: vfs_trans.c,v 1.2.2.2 2007/02/01 08:48:41 ad Exp $ */
2 1.2.2.2 ad
3 1.2.2.2 ad /*-
4 1.2.2.2 ad * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 1.2.2.2 ad * All rights reserved.
6 1.2.2.2 ad *
7 1.2.2.2 ad * This code is derived from software contributed to The NetBSD Foundation
8 1.2.2.2 ad * by Juergen Hannken-Illjes.
9 1.2.2.2 ad *
10 1.2.2.2 ad * Redistribution and use in source and binary forms, with or without
11 1.2.2.2 ad * modification, are permitted provided that the following conditions
12 1.2.2.2 ad * are met:
13 1.2.2.2 ad * 1. Redistributions of source code must retain the above copyright
14 1.2.2.2 ad * notice, this list of conditions and the following disclaimer.
15 1.2.2.2 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.2.2 ad * notice, this list of conditions and the following disclaimer in the
17 1.2.2.2 ad * documentation and/or other materials provided with the distribution.
18 1.2.2.2 ad * 3. All advertising materials mentioning features or use of this software
19 1.2.2.2 ad * must display the following acknowledgement:
20 1.2.2.2 ad * This product includes software developed by the NetBSD
21 1.2.2.2 ad * Foundation, Inc. and its contributors.
22 1.2.2.2 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.2.2 ad * contributors may be used to endorse or promote products derived
24 1.2.2.2 ad * from this software without specific prior written permission.
25 1.2.2.2 ad *
26 1.2.2.2 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.2.2 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.2.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.2.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.2.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.2.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.2.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.2.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.2.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.2.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.2.2 ad * POSSIBILITY OF SUCH DAMAGE.
37 1.2.2.2 ad */
38 1.2.2.2 ad
39 1.2.2.2 ad #include <sys/cdefs.h>
40 1.2.2.2 ad __KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.2.2.2 2007/02/01 08:48:41 ad Exp $");
41 1.2.2.2 ad
42 1.2.2.2 ad /*
43 1.2.2.2 ad * File system transaction operations.
44 1.2.2.2 ad */
45 1.2.2.2 ad
46 1.2.2.2 ad #include "opt_ddb.h"
47 1.2.2.2 ad
48 1.2.2.2 ad #if defined(DDB)
49 1.2.2.2 ad #define _LWP_API_PRIVATE /* Need _lwp_getspecific_by_lwp() */
50 1.2.2.2 ad #endif
51 1.2.2.2 ad
52 1.2.2.2 ad #include <sys/param.h>
53 1.2.2.2 ad #include <sys/systm.h>
54 1.2.2.2 ad #include <sys/malloc.h>
55 1.2.2.2 ad #include <sys/mount.h>
56 1.2.2.2 ad #include <sys/vnode.h>
57 1.2.2.2 ad #define _FSTRANS_API_PRIVATE
58 1.2.2.2 ad #include <sys/fstrans.h>
59 1.2.2.2 ad
60 1.2.2.2 ad #include <miscfs/syncfs/syncfs.h>
61 1.2.2.2 ad
62 1.2.2.2 ad struct fstrans_lwp_info {
63 1.2.2.2 ad struct fstrans_lwp_info *fli_succ;
64 1.2.2.2 ad struct mount *fli_mount;
65 1.2.2.2 ad int fli_count;
66 1.2.2.2 ad enum fstrans_lock_type fli_lock_type;
67 1.2.2.2 ad };
68 1.2.2.2 ad struct fstrans_mount_info {
69 1.2.2.2 ad enum fstrans_state fmi_state;
70 1.2.2.2 ad struct lock fmi_shared_lock;
71 1.2.2.2 ad struct lock fmi_lazy_lock;
72 1.2.2.2 ad };
73 1.2.2.2 ad
74 1.2.2.2 ad static specificdata_key_t lwp_data_key;
75 1.2.2.2 ad static specificdata_key_t mount_data_key;
76 1.2.2.2 ad static struct lock vfs_suspend_lock = /* Serialize suspensions. */
77 1.2.2.2 ad LOCK_INITIALIZER(PUSER, "suspwt1", 0, 0);
78 1.2.2.2 ad
79 1.2.2.2 ad POOL_INIT(fstrans_pl, sizeof(struct fstrans_lwp_info), 0, 0, 0,
80 1.2.2.2 ad "fstrans", NULL);
81 1.2.2.2 ad
82 1.2.2.2 ad static void fstrans_lwp_dtor(void *);
83 1.2.2.2 ad static void fstrans_mount_dtor(void *);
84 1.2.2.2 ad static struct fstrans_mount_info *fstrans_mount_init(struct mount *);
85 1.2.2.2 ad
86 1.2.2.2 ad /*
87 1.2.2.2 ad * Initialize
88 1.2.2.2 ad */
89 1.2.2.2 ad void
90 1.2.2.2 ad fstrans_init(void)
91 1.2.2.2 ad {
92 1.2.2.2 ad int error;
93 1.2.2.2 ad
94 1.2.2.2 ad error = lwp_specific_key_create(&lwp_data_key, fstrans_lwp_dtor);
95 1.2.2.2 ad KASSERT(error == 0);
96 1.2.2.2 ad error = mount_specific_key_create(&mount_data_key, fstrans_mount_dtor);
97 1.2.2.2 ad KASSERT(error == 0);
98 1.2.2.2 ad }
99 1.2.2.2 ad
100 1.2.2.2 ad /*
101 1.2.2.2 ad * Deallocate lwp state
102 1.2.2.2 ad */
103 1.2.2.2 ad static void
104 1.2.2.2 ad fstrans_lwp_dtor(void *arg)
105 1.2.2.2 ad {
106 1.2.2.2 ad struct fstrans_lwp_info *fli, *fli_next;
107 1.2.2.2 ad
108 1.2.2.2 ad for (fli = arg; fli; fli = fli_next) {
109 1.2.2.2 ad KASSERT(fli->fli_mount == NULL);
110 1.2.2.2 ad KASSERT(fli->fli_count == 0);
111 1.2.2.2 ad fli_next = fli->fli_succ;
112 1.2.2.2 ad pool_put(&fstrans_pl, fli);
113 1.2.2.2 ad }
114 1.2.2.2 ad }
115 1.2.2.2 ad
116 1.2.2.2 ad /*
117 1.2.2.2 ad * Deallocate mount state
118 1.2.2.2 ad */
119 1.2.2.2 ad static void
120 1.2.2.2 ad fstrans_mount_dtor(void *arg)
121 1.2.2.2 ad {
122 1.2.2.2 ad struct fstrans_mount_info *fmi = arg;
123 1.2.2.2 ad
124 1.2.2.2 ad KASSERT(fmi->fmi_state == FSTRANS_NORMAL);
125 1.2.2.2 ad lockmgr(&fmi->fmi_lazy_lock, LK_DRAIN, NULL);
126 1.2.2.2 ad lockmgr(&fmi->fmi_shared_lock, LK_DRAIN, NULL);
127 1.2.2.2 ad free(fmi, M_MOUNT);
128 1.2.2.2 ad }
129 1.2.2.2 ad
130 1.2.2.2 ad /*
131 1.2.2.2 ad * Create mount info for this mount
132 1.2.2.2 ad */
133 1.2.2.2 ad static struct fstrans_mount_info *
134 1.2.2.2 ad fstrans_mount_init(struct mount *mp)
135 1.2.2.2 ad {
136 1.2.2.2 ad static struct lock lock = LOCK_INITIALIZER(PUSER, "ftminfo", 0, 0);
137 1.2.2.2 ad struct fstrans_mount_info *new;
138 1.2.2.2 ad
139 1.2.2.2 ad lockmgr(&lock, LK_EXCLUSIVE, NULL);
140 1.2.2.2 ad
141 1.2.2.2 ad if ((new = mount_getspecific(mp, mount_data_key)) != NULL) {
142 1.2.2.2 ad lockmgr(&lock, LK_RELEASE, NULL);
143 1.2.2.2 ad return new;
144 1.2.2.2 ad }
145 1.2.2.2 ad
146 1.2.2.2 ad new = malloc(sizeof(*new), M_MOUNT, M_WAITOK);
147 1.2.2.2 ad new->fmi_state = FSTRANS_NORMAL;
148 1.2.2.2 ad lockinit(&new->fmi_lazy_lock, PVFS, "suspfs", 0, 0);
149 1.2.2.2 ad lockinit(&new->fmi_shared_lock, PVFS, "suspfs", 0, 0);
150 1.2.2.2 ad
151 1.2.2.2 ad mount_setspecific(mp, mount_data_key, new);
152 1.2.2.2 ad
153 1.2.2.2 ad lockmgr(&lock, LK_RELEASE, NULL);
154 1.2.2.2 ad
155 1.2.2.2 ad return new;
156 1.2.2.2 ad }
157 1.2.2.2 ad
158 1.2.2.2 ad /*
159 1.2.2.2 ad * Start a transaction. If this thread already has a transaction on this
160 1.2.2.2 ad * file system increment the reference counter.
161 1.2.2.2 ad * A thread with an exclusive transaction lock may get a shared or lazy one.
162 1.2.2.2 ad * A thread with a shared or lazy transaction lock cannot upgrade to an
163 1.2.2.2 ad * exclusive one yet.
164 1.2.2.2 ad */
165 1.2.2.2 ad int
166 1.2.2.2 ad _fstrans_start(struct mount *mp, enum fstrans_lock_type lock_type, int wait)
167 1.2.2.2 ad {
168 1.2.2.2 ad int error, lkflags;
169 1.2.2.2 ad struct fstrans_lwp_info *fli, *new_fli;
170 1.2.2.2 ad struct fstrans_mount_info *fmi;
171 1.2.2.2 ad
172 1.2.2.2 ad ASSERT_SLEEPABLE(NULL, __func__);
173 1.2.2.2 ad
174 1.2.2.2 ad lkflags = (lock_type == FSTRANS_EXCL ? LK_EXCLUSIVE : LK_SHARED);
175 1.2.2.2 ad if (!wait)
176 1.2.2.2 ad lkflags |= LK_NOWAIT;
177 1.2.2.2 ad
178 1.2.2.2 ad if (mp == NULL || (mp->mnt_iflag & IMNT_HAS_TRANS) == 0)
179 1.2.2.2 ad return 0;
180 1.2.2.2 ad
181 1.2.2.2 ad new_fli = NULL;
182 1.2.2.2 ad for (fli = lwp_getspecific(lwp_data_key); fli; fli = fli->fli_succ) {
183 1.2.2.2 ad if (fli->fli_mount == NULL && new_fli == NULL)
184 1.2.2.2 ad new_fli = fli;
185 1.2.2.2 ad if (fli->fli_mount == mp) {
186 1.2.2.2 ad KASSERT(fli->fli_count > 0);
187 1.2.2.2 ad if (fli->fli_lock_type != FSTRANS_EXCL &&
188 1.2.2.2 ad lock_type == FSTRANS_EXCL)
189 1.2.2.2 ad panic("fstrans_start: cannot upgrade lock");
190 1.2.2.2 ad fli->fli_count += 1;
191 1.2.2.2 ad return 0;
192 1.2.2.2 ad }
193 1.2.2.2 ad }
194 1.2.2.2 ad
195 1.2.2.2 ad if (new_fli == NULL) {
196 1.2.2.2 ad new_fli = pool_get(&fstrans_pl, PR_WAITOK);
197 1.2.2.2 ad new_fli->fli_mount = NULL;
198 1.2.2.2 ad new_fli->fli_count = 0;
199 1.2.2.2 ad new_fli->fli_succ = lwp_getspecific(lwp_data_key);
200 1.2.2.2 ad lwp_setspecific(lwp_data_key, new_fli);
201 1.2.2.2 ad }
202 1.2.2.2 ad
203 1.2.2.2 ad KASSERT(new_fli->fli_mount == NULL);
204 1.2.2.2 ad KASSERT(new_fli->fli_count == 0);
205 1.2.2.2 ad
206 1.2.2.2 ad if ((fmi = mount_getspecific(mp, mount_data_key)) == NULL)
207 1.2.2.2 ad fmi = fstrans_mount_init(mp);
208 1.2.2.2 ad
209 1.2.2.2 ad if (lock_type == FSTRANS_LAZY)
210 1.2.2.2 ad error = lockmgr(&fmi->fmi_lazy_lock, lkflags, NULL);
211 1.2.2.2 ad else
212 1.2.2.2 ad error = lockmgr(&fmi->fmi_shared_lock, lkflags, NULL);
213 1.2.2.2 ad if (error)
214 1.2.2.2 ad return error;
215 1.2.2.2 ad
216 1.2.2.2 ad new_fli->fli_mount = mp;
217 1.2.2.2 ad new_fli->fli_count = 1;
218 1.2.2.2 ad new_fli->fli_lock_type = lock_type;
219 1.2.2.2 ad
220 1.2.2.2 ad return 0;
221 1.2.2.2 ad }
222 1.2.2.2 ad
223 1.2.2.2 ad /*
224 1.2.2.2 ad * Finish a transaction.
225 1.2.2.2 ad */
226 1.2.2.2 ad void
227 1.2.2.2 ad fstrans_done(struct mount *mp)
228 1.2.2.2 ad {
229 1.2.2.2 ad struct fstrans_lwp_info *fli;
230 1.2.2.2 ad struct fstrans_mount_info *fmi;
231 1.2.2.2 ad
232 1.2.2.2 ad if (mp == NULL || (mp->mnt_iflag & IMNT_HAS_TRANS) == 0)
233 1.2.2.2 ad return;
234 1.2.2.2 ad
235 1.2.2.2 ad for (fli = lwp_getspecific(lwp_data_key); fli; fli = fli->fli_succ) {
236 1.2.2.2 ad if (fli->fli_mount == mp) {
237 1.2.2.2 ad fli->fli_count -= 1;
238 1.2.2.2 ad if (fli->fli_count > 0)
239 1.2.2.2 ad return;
240 1.2.2.2 ad break;
241 1.2.2.2 ad }
242 1.2.2.2 ad }
243 1.2.2.2 ad
244 1.2.2.2 ad KASSERT(fli != NULL);
245 1.2.2.2 ad KASSERT(fli->fli_mount == mp);
246 1.2.2.2 ad KASSERT(fli->fli_count == 0);
247 1.2.2.2 ad fli->fli_mount = NULL;
248 1.2.2.2 ad fmi = mount_getspecific(mp, mount_data_key);
249 1.2.2.2 ad KASSERT(fmi != NULL);
250 1.2.2.2 ad if (fli->fli_lock_type == FSTRANS_LAZY)
251 1.2.2.2 ad lockmgr(&fmi->fmi_lazy_lock, LK_RELEASE, NULL);
252 1.2.2.2 ad else
253 1.2.2.2 ad lockmgr(&fmi->fmi_shared_lock, LK_RELEASE, NULL);
254 1.2.2.2 ad }
255 1.2.2.2 ad
256 1.2.2.2 ad /*
257 1.2.2.2 ad * Check if this thread has an exclusive lock.
258 1.2.2.2 ad */
259 1.2.2.2 ad int
260 1.2.2.2 ad fstrans_is_owner(struct mount *mp)
261 1.2.2.2 ad {
262 1.2.2.2 ad struct fstrans_lwp_info *fli;
263 1.2.2.2 ad
264 1.2.2.2 ad if (mp == NULL)
265 1.2.2.2 ad return 0;
266 1.2.2.2 ad if ((mp->mnt_iflag & IMNT_HAS_TRANS) == 0)
267 1.2.2.2 ad return 0;
268 1.2.2.2 ad
269 1.2.2.2 ad for (fli = lwp_getspecific(lwp_data_key); fli; fli = fli->fli_succ)
270 1.2.2.2 ad if (fli->fli_mount == mp)
271 1.2.2.2 ad break;
272 1.2.2.2 ad
273 1.2.2.2 ad if (fli == NULL)
274 1.2.2.2 ad return 0;
275 1.2.2.2 ad
276 1.2.2.2 ad KASSERT(fli->fli_mount == mp);
277 1.2.2.2 ad KASSERT(fli->fli_count > 0);
278 1.2.2.2 ad return (fli->fli_lock_type == FSTRANS_EXCL);
279 1.2.2.2 ad }
280 1.2.2.2 ad
281 1.2.2.2 ad /*
282 1.2.2.2 ad * Set new file system state.
283 1.2.2.2 ad */
284 1.2.2.2 ad int
285 1.2.2.2 ad fstrans_setstate(struct mount *mp, enum fstrans_state new_state)
286 1.2.2.2 ad {
287 1.2.2.2 ad int error;
288 1.2.2.2 ad struct fstrans_mount_info *fmi;
289 1.2.2.2 ad
290 1.2.2.2 ad if ((fmi = mount_getspecific(mp, mount_data_key)) == NULL)
291 1.2.2.2 ad fmi = fstrans_mount_init(mp);
292 1.2.2.2 ad
293 1.2.2.2 ad switch (new_state) {
294 1.2.2.2 ad case FSTRANS_SUSPENDING:
295 1.2.2.2 ad KASSERT(fmi->fmi_state == FSTRANS_NORMAL);
296 1.2.2.2 ad if ((error = fstrans_start(mp, FSTRANS_EXCL)) != 0)
297 1.2.2.2 ad return error;
298 1.2.2.2 ad fmi->fmi_state = FSTRANS_SUSPENDING;
299 1.2.2.2 ad break;
300 1.2.2.2 ad
301 1.2.2.2 ad case FSTRANS_SUSPENDED:
302 1.2.2.2 ad KASSERT(fmi->fmi_state == FSTRANS_NORMAL ||
303 1.2.2.2 ad fmi->fmi_state == FSTRANS_SUSPENDING);
304 1.2.2.2 ad KASSERT(fmi->fmi_state == FSTRANS_NORMAL ||
305 1.2.2.2 ad fstrans_is_owner(mp));
306 1.2.2.2 ad if (fmi->fmi_state == FSTRANS_NORMAL &&
307 1.2.2.2 ad (error = fstrans_start(mp, FSTRANS_EXCL)) != 0)
308 1.2.2.2 ad return error;
309 1.2.2.2 ad if ((error = lockmgr(&fmi->fmi_lazy_lock, LK_EXCLUSIVE, NULL))
310 1.2.2.2 ad != 0)
311 1.2.2.2 ad return error;
312 1.2.2.2 ad fmi->fmi_state = FSTRANS_SUSPENDED;
313 1.2.2.2 ad break;
314 1.2.2.2 ad
315 1.2.2.2 ad case FSTRANS_NORMAL:
316 1.2.2.2 ad KASSERT(fmi->fmi_state == FSTRANS_NORMAL ||
317 1.2.2.2 ad fstrans_is_owner(mp));
318 1.2.2.2 ad if (fmi->fmi_state == FSTRANS_SUSPENDED)
319 1.2.2.2 ad lockmgr(&fmi->fmi_lazy_lock, LK_RELEASE, NULL);
320 1.2.2.2 ad if (fmi->fmi_state == FSTRANS_SUSPENDING ||
321 1.2.2.2 ad fmi->fmi_state == FSTRANS_SUSPENDED) {
322 1.2.2.2 ad fmi->fmi_state = FSTRANS_NORMAL;
323 1.2.2.2 ad fstrans_done(mp);
324 1.2.2.2 ad }
325 1.2.2.2 ad break;
326 1.2.2.2 ad
327 1.2.2.2 ad default:
328 1.2.2.2 ad panic("%s: illegal state %d", __func__, new_state);
329 1.2.2.2 ad }
330 1.2.2.2 ad
331 1.2.2.2 ad return 0;
332 1.2.2.2 ad }
333 1.2.2.2 ad
334 1.2.2.2 ad /*
335 1.2.2.2 ad * Get current file system state
336 1.2.2.2 ad */
337 1.2.2.2 ad enum fstrans_state
338 1.2.2.2 ad fstrans_getstate(struct mount *mp)
339 1.2.2.2 ad {
340 1.2.2.2 ad struct fstrans_mount_info *fmi;
341 1.2.2.2 ad
342 1.2.2.2 ad if ((fmi = mount_getspecific(mp, mount_data_key)) == NULL)
343 1.2.2.2 ad return FSTRANS_NORMAL;
344 1.2.2.2 ad
345 1.2.2.2 ad return fmi->fmi_state;
346 1.2.2.2 ad }
347 1.2.2.2 ad
348 1.2.2.2 ad /*
349 1.2.2.2 ad * Request a filesystem to suspend all operations.
350 1.2.2.2 ad */
351 1.2.2.2 ad int
352 1.2.2.2 ad vfs_suspend(struct mount *mp, int nowait)
353 1.2.2.2 ad {
354 1.2.2.2 ad #ifndef NEWVNGATE
355 1.2.2.2 ad struct lwp *l = curlwp; /* XXX */
356 1.2.2.2 ad #endif /* NEWVNGATE */
357 1.2.2.2 ad int error, flags;
358 1.2.2.2 ad
359 1.2.2.2 ad flags = LK_EXCLUSIVE;
360 1.2.2.2 ad if (nowait)
361 1.2.2.2 ad flags |= LK_NOWAIT;
362 1.2.2.2 ad if (lockmgr(&vfs_suspend_lock, flags, NULL) != 0)
363 1.2.2.2 ad return EWOULDBLOCK;
364 1.2.2.2 ad
365 1.2.2.2 ad #ifdef NEWVNGATE
366 1.2.2.2 ad lockmgr(&syncer_lock, LK_EXCLUSIVE, NULL);
367 1.2.2.2 ad
368 1.2.2.2 ad if ((error = VFS_SUSPENDCTL(mp, SUSPEND_SUSPEND)) != 0) {
369 1.2.2.2 ad lockmgr(&syncer_lock, LK_RELEASE, NULL);
370 1.2.2.2 ad lockmgr(&vfs_suspend_lock, LK_RELEASE, NULL);
371 1.2.2.2 ad }
372 1.2.2.2 ad
373 1.2.2.2 ad return error;
374 1.2.2.2 ad #else /* NEWVNGATE */
375 1.2.2.2 ad KASSERT((mp->mnt_iflag &
376 1.2.2.2 ad (IMNT_SUSPEND|IMNT_SUSPENDLOW|IMNT_SUSPENDED)) == 0);
377 1.2.2.2 ad
378 1.2.2.2 ad mp->mnt_iflag |= IMNT_SUSPEND;
379 1.2.2.2 ad
380 1.2.2.2 ad simple_lock(&mp->mnt_slock);
381 1.2.2.2 ad if (mp->mnt_writeopcountupper > 0)
382 1.2.2.2 ad ltsleep(&mp->mnt_writeopcountupper, PUSER - 1, "suspwt",
383 1.2.2.2 ad 0, &mp->mnt_slock);
384 1.2.2.2 ad simple_unlock(&mp->mnt_slock);
385 1.2.2.2 ad
386 1.2.2.2 ad error = VFS_SYNC(mp, MNT_WAIT, l->l_proc->p_cred, l);
387 1.2.2.2 ad if (error) {
388 1.2.2.2 ad vfs_resume(mp);
389 1.2.2.2 ad return error;
390 1.2.2.2 ad }
391 1.2.2.2 ad mp->mnt_iflag |= IMNT_SUSPENDLOW;
392 1.2.2.2 ad
393 1.2.2.2 ad simple_lock(&mp->mnt_slock);
394 1.2.2.2 ad if (mp->mnt_writeopcountlower > 0)
395 1.2.2.2 ad ltsleep(&mp->mnt_writeopcountlower, PUSER - 1, "suspwt",
396 1.2.2.2 ad 0, &mp->mnt_slock);
397 1.2.2.2 ad mp->mnt_iflag |= IMNT_SUSPENDED;
398 1.2.2.2 ad simple_unlock(&mp->mnt_slock);
399 1.2.2.2 ad
400 1.2.2.2 ad return 0;
401 1.2.2.2 ad #endif /* NEWVNGATE */
402 1.2.2.2 ad }
403 1.2.2.2 ad
404 1.2.2.2 ad /*
405 1.2.2.2 ad * Request a filesystem to resume all operations.
406 1.2.2.2 ad */
407 1.2.2.2 ad void
408 1.2.2.2 ad vfs_resume(struct mount *mp)
409 1.2.2.2 ad {
410 1.2.2.2 ad
411 1.2.2.2 ad #ifdef NEWVNGATE
412 1.2.2.2 ad VFS_SUSPENDCTL(mp, SUSPEND_RESUME);
413 1.2.2.2 ad lockmgr(&syncer_lock, LK_RELEASE, NULL);
414 1.2.2.2 ad lockmgr(&vfs_suspend_lock, LK_RELEASE, NULL);
415 1.2.2.2 ad #else /* NEWVNGATE */
416 1.2.2.2 ad if ((mp->mnt_iflag & IMNT_SUSPEND) == 0)
417 1.2.2.2 ad return;
418 1.2.2.2 ad mp->mnt_iflag &= ~(IMNT_SUSPEND | IMNT_SUSPENDLOW | IMNT_SUSPENDED);
419 1.2.2.2 ad wakeup(&mp->mnt_flag);
420 1.2.2.2 ad
421 1.2.2.2 ad lockmgr(&vfs_suspend_lock, LK_RELEASE, NULL);
422 1.2.2.2 ad #endif /* NEWVNGATE */
423 1.2.2.2 ad }
424 1.2.2.2 ad
425 1.2.2.2 ad /*
426 1.2.2.2 ad * Default vfs_suspendctl routine for file systems that do not support it.
427 1.2.2.2 ad */
428 1.2.2.2 ad /*ARGSUSED*/
429 1.2.2.2 ad int
430 1.2.2.2 ad vfs_stdsuspendctl(struct mount *mp __unused, int mode __unused)
431 1.2.2.2 ad {
432 1.2.2.2 ad return EOPNOTSUPP;
433 1.2.2.2 ad }
434 1.2.2.2 ad
435 1.2.2.2 ad #if defined(DDB)
436 1.2.2.2 ad void fstrans_dump(int);
437 1.2.2.2 ad
438 1.2.2.2 ad static void
439 1.2.2.2 ad fstrans_print_lwp(struct proc *p, struct lwp *l, int verbose)
440 1.2.2.2 ad {
441 1.2.2.2 ad char prefix[9];
442 1.2.2.2 ad struct fstrans_lwp_info *fli;
443 1.2.2.2 ad
444 1.2.2.2 ad snprintf(prefix, sizeof(prefix), "%d.%d", p->p_pid, l->l_lid);
445 1.2.2.2 ad for (fli = _lwp_getspecific_by_lwp(l, lwp_data_key);
446 1.2.2.2 ad fli;
447 1.2.2.2 ad fli = fli->fli_succ) {
448 1.2.2.2 ad if (!verbose && fli->fli_count == 0)
449 1.2.2.2 ad continue;
450 1.2.2.2 ad printf("%-8s", prefix);
451 1.2.2.2 ad if (verbose)
452 1.2.2.2 ad printf(" @%p", fli);
453 1.2.2.2 ad if (fli->fli_mount != NULL)
454 1.2.2.2 ad printf(" (%s)", fli->fli_mount->mnt_stat.f_mntonname);
455 1.2.2.2 ad else
456 1.2.2.2 ad printf(" NULL");
457 1.2.2.2 ad switch (fli->fli_lock_type) {
458 1.2.2.2 ad case FSTRANS_LAZY:
459 1.2.2.2 ad printf(" lazy");
460 1.2.2.2 ad break;
461 1.2.2.2 ad case FSTRANS_SHARED:
462 1.2.2.2 ad printf(" shared");
463 1.2.2.2 ad break;
464 1.2.2.2 ad case FSTRANS_EXCL:
465 1.2.2.2 ad printf(" excl");
466 1.2.2.2 ad break;
467 1.2.2.2 ad default:
468 1.2.2.2 ad printf(" %#x", fli->fli_lock_type);
469 1.2.2.2 ad break;
470 1.2.2.2 ad }
471 1.2.2.2 ad printf(" %d\n", fli->fli_count);
472 1.2.2.2 ad prefix[0] = '\0';
473 1.2.2.2 ad }
474 1.2.2.2 ad }
475 1.2.2.2 ad
476 1.2.2.2 ad static void
477 1.2.2.2 ad fstrans_print_mount(struct mount *mp, int verbose)
478 1.2.2.2 ad {
479 1.2.2.2 ad struct fstrans_mount_info *fmi;
480 1.2.2.2 ad
481 1.2.2.2 ad fmi = mount_getspecific(mp, mount_data_key);
482 1.2.2.2 ad if (!verbose && (fmi == NULL || fmi->fmi_state == FSTRANS_NORMAL))
483 1.2.2.2 ad return;
484 1.2.2.2 ad
485 1.2.2.2 ad printf("%-16s ", mp->mnt_stat.f_mntonname);
486 1.2.2.2 ad if (fmi == NULL) {
487 1.2.2.2 ad printf("(null)\n");
488 1.2.2.2 ad return;
489 1.2.2.2 ad }
490 1.2.2.2 ad switch (fmi->fmi_state) {
491 1.2.2.2 ad case FSTRANS_NORMAL:
492 1.2.2.2 ad printf("state normal\n");
493 1.2.2.2 ad break;
494 1.2.2.2 ad case FSTRANS_SUSPENDING:
495 1.2.2.2 ad printf("state suspending\n");
496 1.2.2.2 ad break;
497 1.2.2.2 ad case FSTRANS_SUSPENDED:
498 1.2.2.2 ad printf("state suspended\n");
499 1.2.2.2 ad break;
500 1.2.2.2 ad default:
501 1.2.2.2 ad printf("state %#x\n", fmi->fmi_state);
502 1.2.2.2 ad break;
503 1.2.2.2 ad }
504 1.2.2.2 ad printf("%16s", "lock_lazy:");
505 1.2.2.2 ad lockmgr_printinfo(&fmi->fmi_lazy_lock);
506 1.2.2.2 ad printf("\n");
507 1.2.2.2 ad printf("%16s", "lock_shared:");
508 1.2.2.2 ad lockmgr_printinfo(&fmi->fmi_shared_lock);
509 1.2.2.2 ad printf("\n");
510 1.2.2.2 ad }
511 1.2.2.2 ad
512 1.2.2.2 ad void
513 1.2.2.2 ad fstrans_dump(int full)
514 1.2.2.2 ad {
515 1.2.2.2 ad const struct proclist_desc *pd;
516 1.2.2.2 ad struct proc *p;
517 1.2.2.2 ad struct lwp *l;
518 1.2.2.2 ad struct mount *mp;
519 1.2.2.2 ad
520 1.2.2.2 ad printf("Fstrans locks by lwp:\n");
521 1.2.2.2 ad for (pd = proclists; pd->pd_list != NULL; pd++)
522 1.2.2.2 ad LIST_FOREACH(p, pd->pd_list, p_list)
523 1.2.2.2 ad LIST_FOREACH(l, &p->p_lwps, l_sibling)
524 1.2.2.2 ad fstrans_print_lwp(p, l, full == 1);
525 1.2.2.2 ad
526 1.2.2.2 ad printf("Fstrans state by mount:\n");
527 1.2.2.2 ad CIRCLEQ_FOREACH(mp, &mountlist, mnt_list)
528 1.2.2.2 ad fstrans_print_mount(mp, full == 1);
529 1.2.2.2 ad }
530 1.2.2.2 ad #endif /* defined(DDB) */
531