1 .\" $NetBSD: fstrans.9,v 1.13 2009/04/12 19:00:56 joerg Exp $
3 .\" Copyright (c) 2007 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Juergen Hannken-Illjes.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
35 .Nm fstrans_setstate ,
36 .Nm fstrans_getstate ,
38 .Nm fstrans_start_nowait ,
40 .Nm fstrans_is_owner ,
42 .Nm fscow_disestablish ,
44 .Nd file system suspension helper subsystem
49 .Fn fstrans_setstate "struct mount *mp" "enum fstrans_state new_state"
50 .Ft "enum fstrans_state"
51 .Fn fstrans_getstate "struct mount *mp"
53 .Fn fstrans_start "struct mount *mp" "enum fstrans_lock_type lock_type"
55 .Fn fstrans_start_nowait "struct mount *mp" "enum fstrans_lock_type lock_type"
57 .Fn fstrans_done "struct mount *mp"
59 .Fn fstrans_is_owner "struct mount *mp"
61 .Fn fscow_establish "struct mount *mp" \
62 "int (*func)(void *, struct buf *, bool)" "void *cookie"
64 .Fn fscow_disestablish "struct mount *mp" \
65 "int (*func)(void *, struct buf *, bool)" "void *cookie"
67 .Fn fscow_run "struct buf *bp" "bool data_valid"
71 subsystem is a set of operations to assist file system suspension.
72 These operations must not be used outside of file systems.
74 File systems supporting this subsystem must set the flag
79 File systems are always in one of these states:
80 .Bl -tag -offset indent -width FSTRANS_SUSPENDING -compact
83 .It Dv FSTRANS_SUSPENDING
84 preparing a suspension.
85 .It Dv FSTRANS_SUSPENDED
88 This state is represented by
89 .Vt "enum fstrans_state" .
90 .Bl -tag -width compact
91 .It Fn fstrans_getstate "mp"
92 returns the current state of the file system
95 .It Fn fstrans_setstate "mp" "new_state"
96 changes the state of the file system
102 All file system operations use a
104 This lock is recursive.
105 A thread already owning a lock will always get another lock.
106 The lock has two variants:
107 .Bl -tag -offset indent -width FSTRANS_SHARED -compact
108 .It Dv FSTRANS_SHARED
109 this lock will be granted if the file system is in state
112 this lock will be granted if the file system is in state
115 .Dv FSTRANS_SUSPENDING .
116 It needs special care because operations using this variant will not block
117 while the file system prepares suspension.
119 The lock variant is represented by
120 .Vt "enum fstrans_lock_type" .
121 .Bl -tag -width compact
122 .It Fn fstrans_start "mp" "lock_type"
127 .It Fn fstrans_start_nowait "mp" "lock_type"
128 will not wait for a state change of the file system when attempting to
130 The thread may still sleep while attempting to acquire the lock.
131 .It Fn fstrans_done "mp"
132 releases a lock on the file system
134 .It Fn fstrans_is_owner "mp"
137 if this thread is currently suspending the file system
139 .It Fn fscow_establish "mp" "func" "cookie"
140 Establish a copy-on-write callback for the file system
143 will be called for every buffer written through this file system.
144 .It Fn fscow_disestablish "mp" "func" "cookie"
145 Disestablish a copy-on-write callback registered with
146 .Fn fscow_establish .
147 .It Fn fscow_run "bp" "data_valid"
148 Run all copy-on-write callbacks established for the file system this buffer
154 the buffer data has not yet been modified.
160 .Fn fstrans_start_nowait
161 return zero on success and an error value on failure.
163 The following is an example of a file system suspend operation.
166 xxx_suspendctl(struct mount *mp, int cmd)
171 case SUSPEND_SUSPEND:
172 error = fstrans_setstate(mp, FSTRANS_SUSPENDING);
176 /* Sync file system state to disk. */
178 return fstrans_setstate(mp, FSTRANS_SUSPENDED);
181 return fstrans_setstate(mp, FSTRANS_NORMAL);
189 This is an example of a file system operation.
194 struct vop_create_args *ap = v;
195 struct mount *mp = ap-\*[Gt]a_dvp-\*[Gt]v_mount;
198 if ((error = fstrans_start(mp, FSTRANS_SHARED)) != 0)
201 /* Actually create the node. */
212 The actual code implementing this subsystem can be found in the file
213 .Pa sys/kern/vfs_trans.c .
217 subsystem appeared in
222 subsystem was written by
223 .An J\(:urgen Hannken-Illjes
224 .Aq hannken@NetBSD.org .