2 * Copyright 2005-2008, Sine Nomine Associates and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #ifndef _AFS_VOL_VOLUME_INLINE_H
11 #define _AFS_VOL_VOLUME_INLINE_H 1
15 /***************************************************/
16 /* demand attach fs state machine routines */
17 /***************************************************/
19 #ifdef AFS_DEMAND_ATTACH_FS
21 * tells caller whether or not the current state requires
22 * exclusive access without holding glock.
24 * @param state volume state enumeration
26 * @return whether volume state is a mutually exclusive state
27 * @retval 0 no, state is re-entrant
28 * @retval 1 yes, state is mutually exclusive
30 * @note DEMAND_ATTACH_FS only
33 VIsExclusiveState(VolState state)
36 case VOL_STATE_UPDATING:
37 case VOL_STATE_ATTACHING:
38 case VOL_STATE_GET_BITMAP:
39 case VOL_STATE_HDR_LOADING:
40 case VOL_STATE_HDR_ATTACHING:
41 case VOL_STATE_OFFLINING:
42 case VOL_STATE_DETACHING:
43 case VOL_STATE_SALVSYNC_REQ:
44 case VOL_STATE_VNODE_ALLOC:
45 case VOL_STATE_VNODE_GET:
46 case VOL_STATE_VNODE_CLOSE:
47 case VOL_STATE_VNODE_RELEASE:
54 * tell caller whether V_attachState is an error condition.
56 * @param state volume state enumeration
58 * @return whether volume state is in error state
59 * @retval 0 state is not an error state
60 * @retval 1 state is an error state
62 * @note DEMAND_ATTACH_FS only
65 VIsErrorState(VolState state)
69 case VOL_STATE_SALVAGING:
76 * tell caller whether V_attachState is an offline condition.
78 * @param state volume state enumeration
80 * @return whether volume state is in offline state
81 * @retval 0 state is not an offline state
82 * @retval 1 state is an offline state
84 * @note DEMAND_ATTACH_FS only
87 VIsOfflineState(VolState state)
90 case VOL_STATE_UNATTACHED:
92 case VOL_STATE_SALVAGING:
99 * tell caller whether V_attachState is valid.
101 * @param state volume state enumeration
103 * @return whether volume state is a mutually exclusive state
104 * @retval 0 no, state is not valid
105 * @retval 1 yes, state is a valid enumeration member
107 * @note DEMAND_ATTACH_FS only
109 * @note do we really want to treat VOL_STATE_FREED as valid?
112 VIsValidState(VolState state)
115 (state < VOL_STATE_COUNT)) {
122 * increment volume-package internal refcount.
124 * @param vp volume object pointer
126 * @internal volume package internal use only
128 * @pre VOL_LOCK must be held
130 * @post volume waiters refcount is incremented
132 * @see VCancelReservation_r
134 * @note DEMAND_ATTACH_FS only
137 VCreateReservation_r(Volume * vp)
143 * wait for the volume to change states.
145 * @param vp volume object pointer
147 * @pre VOL_LOCK held; ref held on volume
149 * @post VOL_LOCK held; volume state has changed from previous value
151 * @note DEMAND_ATTACH_FS only
154 VWaitStateChange_r(Volume * vp)
156 VolState state_save = V_attachState(vp);
158 assert(vp->nWaiters || vp->nUsers);
160 VOL_CV_WAIT(&V_attachCV(vp));
161 } while (V_attachState(vp) == state_save);
162 assert(V_attachState(vp) != VOL_STATE_FREED);
166 * wait for blocking ops to end.
168 * @pre VOL_LOCK held; ref held on volume
170 * @post VOL_LOCK held; volume not in exclusive state
172 * @param vp volume object pointer
174 * @note DEMAND_ATTACH_FS only
177 VWaitExclusiveState_r(Volume * vp)
179 assert(vp->nWaiters || vp->nUsers);
180 while (VIsExclusiveState(V_attachState(vp))) {
181 VOL_CV_WAIT(&V_attachCV(vp));
183 assert(V_attachState(vp) != VOL_STATE_FREED);
187 * change state, and notify other threads,
188 * return previous state to caller.
190 * @param vp pointer to volume object
191 * @param new_state new volume state value
194 * @post volume state changed; stats updated
196 * @return previous volume state
198 * @note DEMAND_ATTACH_FS only
200 static_inline VolState
201 VChangeState_r(Volume * vp, VolState new_state)
203 VolState old_state = V_attachState(vp);
205 /* XXX profiling need to make sure these counters
206 * don't kill performance... */
207 VStats.state_levels[old_state]--;
208 VStats.state_levels[new_state]++;
210 V_attachState(vp) = new_state;
211 assert(pthread_cond_broadcast(&V_attachCV(vp)) == 0);
215 #endif /* AFS_DEMAND_ATTACH_FS */
217 #endif /* _AFS_VOL_VOLUME_INLINE_H */