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)
36 /***************************************************/
37 /* demand attach fs state machine routines */
38 /***************************************************/
40 #ifdef AFS_DEMAND_ATTACH_FS
42 * tells caller whether or not the current state requires
43 * exclusive access without holding glock.
45 * @param state volume state enumeration
47 * @return whether volume state is a mutually exclusive state
48 * @retval 0 no, state is re-entrant
49 * @retval 1 yes, state is mutually exclusive
51 * @note DEMAND_ATTACH_FS only
54 VIsExclusiveState(VolState state)
57 case VOL_STATE_UPDATING:
58 case VOL_STATE_ATTACHING:
59 case VOL_STATE_GET_BITMAP:
60 case VOL_STATE_HDR_LOADING:
61 case VOL_STATE_HDR_ATTACHING:
62 case VOL_STATE_OFFLINING:
63 case VOL_STATE_DETACHING:
64 case VOL_STATE_SALVSYNC_REQ:
65 case VOL_STATE_VNODE_ALLOC:
66 case VOL_STATE_VNODE_GET:
67 case VOL_STATE_VNODE_CLOSE:
68 case VOL_STATE_VNODE_RELEASE:
69 case VOL_STATE_VLRU_ADD:
77 * tell caller whether V_attachState is an error condition.
79 * @param state volume state enumeration
81 * @return whether volume state is in error state
82 * @retval 0 state is not an error state
83 * @retval 1 state is an error state
85 * @note DEMAND_ATTACH_FS only
88 VIsErrorState(VolState state)
92 case VOL_STATE_SALVAGING:
100 * tell caller whether V_attachState is an offline condition.
102 * @param state volume state enumeration
104 * @return whether volume state is in offline state
105 * @retval 0 state is not an offline state
106 * @retval 1 state is an offline state
108 * @note DEMAND_ATTACH_FS only
111 VIsOfflineState(VolState state)
114 case VOL_STATE_UNATTACHED:
115 case VOL_STATE_ERROR:
116 case VOL_STATE_SALVAGING:
124 * tell caller whether V_attachState is valid.
126 * @param state volume state enumeration
128 * @return whether volume state is a mutually exclusive state
129 * @retval 0 no, state is not valid
130 * @retval 1 yes, state is a valid enumeration member
132 * @note DEMAND_ATTACH_FS only
134 * @note do we really want to treat VOL_STATE_FREED as valid?
137 VIsValidState(VolState state)
140 (state < VOL_STATE_COUNT)) {
147 * increment volume-package internal refcount.
149 * @param vp volume object pointer
151 * @internal volume package internal use only
153 * @pre VOL_LOCK must be held
155 * @post volume waiters refcount is incremented
157 * @see VCancelReservation_r
159 * @note DEMAND_ATTACH_FS only
162 VCreateReservation_r(Volume * vp)
168 * wait for the volume to change states.
170 * @param vp volume object pointer
172 * @pre VOL_LOCK held; ref held on volume
174 * @post VOL_LOCK held; volume state has changed from previous value
176 * @note DEMAND_ATTACH_FS only
179 VWaitStateChange_r(Volume * vp)
181 VolState state_save = V_attachState(vp);
183 assert(vp->nWaiters || vp->nUsers);
185 VOL_CV_WAIT(&V_attachCV(vp));
186 } while (V_attachState(vp) == state_save);
187 assert(V_attachState(vp) != VOL_STATE_FREED);
191 * wait for blocking ops to end.
193 * @pre VOL_LOCK held; ref held on volume
195 * @post VOL_LOCK held; volume not in exclusive state
197 * @param vp volume object pointer
199 * @note DEMAND_ATTACH_FS only
202 VWaitExclusiveState_r(Volume * vp)
204 assert(vp->nWaiters || vp->nUsers);
205 while (VIsExclusiveState(V_attachState(vp))) {
206 VOL_CV_WAIT(&V_attachCV(vp));
208 assert(V_attachState(vp) != VOL_STATE_FREED);
212 * change state, and notify other threads,
213 * return previous state to caller.
215 * @param vp pointer to volume object
216 * @param new_state new volume state value
219 * @post volume state changed; stats updated
221 * @return previous volume state
223 * @note DEMAND_ATTACH_FS only
225 static_inline VolState
226 VChangeState_r(Volume * vp, VolState new_state)
228 VolState old_state = V_attachState(vp);
230 /* XXX profiling need to make sure these counters
231 * don't kill performance... */
232 VStats.state_levels[old_state]--;
233 VStats.state_levels[new_state]++;
235 V_attachState(vp) = new_state;
236 assert(pthread_cond_broadcast(&V_attachCV(vp)) == 0);
240 #endif /* AFS_DEMAND_ATTACH_FS */
242 #endif /* _AFS_VOL_VOLUME_INLINE_H */