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 valid.
78 * @param state volume state enumeration
80 * @return whether volume state is a mutually exclusive state
81 * @retval 0 no, state is not valid
82 * @retval 1 yes, state is a valid enumeration member
84 * @note DEMAND_ATTACH_FS only
86 * @note do we really want to treat VOL_STATE_FREED as valid?
89 VIsValidState(VolState state)
92 (state < VOL_STATE_COUNT)) {
99 * increment volume-package internal refcount.
101 * @param vp volume object pointer
103 * @internal volume package internal use only
105 * @pre VOL_LOCK must be held
107 * @post volume waiters refcount is incremented
109 * @see VCancelReservation_r
111 * @note DEMAND_ATTACH_FS only
114 VCreateReservation_r(Volume * vp)
120 * wait for the volume to change states.
122 * @param vp volume object pointer
124 * @pre VOL_LOCK held; ref held on volume
126 * @post VOL_LOCK held; volume state has changed from previous value
128 * @note DEMAND_ATTACH_FS only
131 VWaitStateChange_r(Volume * vp)
133 VolState state_save = V_attachState(vp);
135 assert(vp->nWaiters || vp->nUsers);
137 VOL_CV_WAIT(&V_attachCV(vp));
138 } while (V_attachState(vp) == state_save);
139 assert(V_attachState(vp) != VOL_STATE_FREED);
143 * wait for blocking ops to end.
145 * @pre VOL_LOCK held; ref held on volume
147 * @post VOL_LOCK held; volume not in exclusive state
149 * @param vp volume object pointer
151 * @note DEMAND_ATTACH_FS only
154 VWaitExclusiveState_r(Volume * vp)
156 assert(vp->nWaiters || vp->nUsers);
157 while (VIsExclusiveState(V_attachState(vp))) {
158 VOL_CV_WAIT(&V_attachCV(vp));
160 assert(V_attachState(vp) != VOL_STATE_FREED);
164 * change state, and notify other threads,
165 * return previous state to caller.
167 * @param vp pointer to volume object
168 * @param new_state new volume state value
171 * @post volume state changed; stats updated
173 * @return previous volume state
175 * @note DEMAND_ATTACH_FS only
177 static_inline VolState
178 VChangeState_r(Volume * vp, VolState new_state)
180 VolState old_state = V_attachState(vp);
182 /* XXX profiling need to make sure these counters
183 * don't kill performance... */
184 VStats.state_levels[old_state]--;
185 VStats.state_levels[new_state]++;
187 V_attachState(vp) = new_state;
188 assert(pthread_cond_broadcast(&V_attachCV(vp)) == 0);
192 #endif /* AFS_DEMAND_ATTACH_FS */
194 #endif /* _AFS_VOL_VOLUME_INLINE_H */