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 * tell caller whether the given program type represents a salvaging
18 * @param type program type enumeration
20 * @return whether program state is a salvager
21 * @retval 0 type is a non-salvaging program
22 * @retval 1 type is a salvaging program
25 VIsSalvager(ProgramType type)
35 /***************************************************/
36 /* demand attach fs state machine routines */
37 /***************************************************/
39 #ifdef AFS_DEMAND_ATTACH_FS
41 * tells caller whether or not the current state requires
42 * exclusive access without holding glock.
44 * @param state volume state enumeration
46 * @return whether volume state is a mutually exclusive state
47 * @retval 0 no, state is re-entrant
48 * @retval 1 yes, state is mutually exclusive
50 * @note DEMAND_ATTACH_FS only
53 VIsExclusiveState(VolState state)
56 case VOL_STATE_UPDATING:
57 case VOL_STATE_ATTACHING:
58 case VOL_STATE_GET_BITMAP:
59 case VOL_STATE_HDR_LOADING:
60 case VOL_STATE_HDR_ATTACHING:
61 case VOL_STATE_OFFLINING:
62 case VOL_STATE_DETACHING:
63 case VOL_STATE_SALVSYNC_REQ:
64 case VOL_STATE_VNODE_ALLOC:
65 case VOL_STATE_VNODE_GET:
66 case VOL_STATE_VNODE_CLOSE:
67 case VOL_STATE_VNODE_RELEASE:
74 * tell caller whether V_attachState is an error condition.
76 * @param state volume state enumeration
78 * @return whether volume state is in error state
79 * @retval 0 state is not an error state
80 * @retval 1 state is an error state
82 * @note DEMAND_ATTACH_FS only
85 VIsErrorState(VolState state)
89 case VOL_STATE_SALVAGING:
96 * tell caller whether V_attachState is an offline condition.
98 * @param state volume state enumeration
100 * @return whether volume state is in offline state
101 * @retval 0 state is not an offline state
102 * @retval 1 state is an offline state
104 * @note DEMAND_ATTACH_FS only
107 VIsOfflineState(VolState state)
110 case VOL_STATE_UNATTACHED:
111 case VOL_STATE_ERROR:
112 case VOL_STATE_SALVAGING:
119 * tell caller whether V_attachState is valid.
121 * @param state volume state enumeration
123 * @return whether volume state is a mutually exclusive state
124 * @retval 0 no, state is not valid
125 * @retval 1 yes, state is a valid enumeration member
127 * @note DEMAND_ATTACH_FS only
129 * @note do we really want to treat VOL_STATE_FREED as valid?
132 VIsValidState(VolState state)
135 (state < VOL_STATE_COUNT)) {
142 * increment volume-package internal refcount.
144 * @param vp volume object pointer
146 * @internal volume package internal use only
148 * @pre VOL_LOCK must be held
150 * @post volume waiters refcount is incremented
152 * @see VCancelReservation_r
154 * @note DEMAND_ATTACH_FS only
157 VCreateReservation_r(Volume * vp)
163 * wait for the volume to change states.
165 * @param vp volume object pointer
167 * @pre VOL_LOCK held; ref held on volume
169 * @post VOL_LOCK held; volume state has changed from previous value
171 * @note DEMAND_ATTACH_FS only
174 VWaitStateChange_r(Volume * vp)
176 VolState state_save = V_attachState(vp);
178 assert(vp->nWaiters || vp->nUsers);
180 VOL_CV_WAIT(&V_attachCV(vp));
181 } while (V_attachState(vp) == state_save);
182 assert(V_attachState(vp) != VOL_STATE_FREED);
186 * wait for blocking ops to end.
188 * @pre VOL_LOCK held; ref held on volume
190 * @post VOL_LOCK held; volume not in exclusive state
192 * @param vp volume object pointer
194 * @note DEMAND_ATTACH_FS only
197 VWaitExclusiveState_r(Volume * vp)
199 assert(vp->nWaiters || vp->nUsers);
200 while (VIsExclusiveState(V_attachState(vp))) {
201 VOL_CV_WAIT(&V_attachCV(vp));
203 assert(V_attachState(vp) != VOL_STATE_FREED);
207 * change state, and notify other threads,
208 * return previous state to caller.
210 * @param vp pointer to volume object
211 * @param new_state new volume state value
214 * @post volume state changed; stats updated
216 * @return previous volume state
218 * @note DEMAND_ATTACH_FS only
220 static_inline VolState
221 VChangeState_r(Volume * vp, VolState new_state)
223 VolState old_state = V_attachState(vp);
225 /* XXX profiling need to make sure these counters
226 * don't kill performance... */
227 VStats.state_levels[old_state]--;
228 VStats.state_levels[new_state]++;
230 V_attachState(vp) = new_state;
231 assert(pthread_cond_broadcast(&V_attachCV(vp)) == 0);
235 #endif /* AFS_DEMAND_ATTACH_FS */
237 #endif /* _AFS_VOL_VOLUME_INLINE_H */