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
16 #define static_inline inline
18 #define static_inline static inline
22 /***************************************************/
23 /* demand attach fs state machine routines */
24 /***************************************************/
26 #ifdef AFS_DEMAND_ATTACH_FS
28 * tells caller whether or not the current state requires
29 * exclusive access without holding glock.
31 * @param state volume state enumeration
33 * @return whether volume state is a mutually exclusive state
34 * @retval 0 no, state is re-entrant
35 * @retval 1 yes, state is mutually exclusive
37 * @note DEMAND_ATTACH_FS only
39 * @note should VOL_STATE_SALVSYNC_REQ be treated as exclusive?
42 VIsExclusiveState(VolState state)
45 case VOL_STATE_UPDATING:
46 case VOL_STATE_ATTACHING:
47 case VOL_STATE_GET_BITMAP:
48 case VOL_STATE_HDR_LOADING:
49 case VOL_STATE_HDR_ATTACHING:
50 case VOL_STATE_OFFLINING:
51 case VOL_STATE_DETACHING:
52 case VOL_STATE_VNODE_ALLOC:
53 case VOL_STATE_VNODE_GET:
54 case VOL_STATE_VNODE_CLOSE:
55 case VOL_STATE_VNODE_RELEASE:
62 * tell caller whether V_attachState is an error condition.
64 * @param state volume state enumeration
66 * @return whether volume state is in error state
67 * @retval 0 state is not an error state
68 * @retval 1 state is an error state
70 * @note DEMAND_ATTACH_FS only
73 VIsErrorState(VolState state)
77 case VOL_STATE_SALVAGING:
84 * tell caller whether V_attachState is valid.
86 * @param state volume state enumeration
88 * @return whether volume state is a mutually exclusive state
89 * @retval 0 no, state is not valid
90 * @retval 1 yes, state is a valid enumeration member
92 * @note DEMAND_ATTACH_FS only
94 * @note do we really want to treat VOL_STATE_FREED as valid?
97 VIsValidState(VolState state)
100 (state < VOL_STATE_COUNT)) {
107 * increment volume-package internal refcount.
109 * @param vp volume object pointer
111 * @internal volume package internal use only
113 * @pre VOL_LOCK must be held
115 * @post volume waiters refcount is incremented
117 * @see VCancelReservation_r
119 * @note DEMAND_ATTACH_FS only
122 VCreateReservation_r(Volume * vp)
128 * wait for the volume to change states.
130 * @param vp volume object pointer
132 * @pre VOL_LOCK held; ref held on volume
134 * @post VOL_LOCK held; volume state has changed from previous value
136 * @note DEMAND_ATTACH_FS only
139 VWaitStateChange_r(Volume * vp)
141 VolState state_save = V_attachState(vp);
143 assert(vp->nWaiters || vp->nUsers);
145 VOL_CV_WAIT(&V_attachCV(vp));
146 } while (V_attachState(vp) == state_save);
147 assert(V_attachState(vp) != VOL_STATE_FREED);
151 * wait for blocking ops to end.
153 * @pre VOL_LOCK held; ref held on volume
155 * @post VOL_LOCK held; volume not in exclusive state
157 * @param vp volume object pointer
159 * @note DEMAND_ATTACH_FS only
162 VWaitExclusiveState_r(Volume * vp)
164 assert(vp->nWaiters || vp->nUsers);
165 while (VIsExclusiveState(V_attachState(vp))) {
166 VOL_CV_WAIT(&V_attachCV(vp));
168 assert(V_attachState(vp) != VOL_STATE_FREED);
172 * change state, and notify other threads,
173 * return previous state to caller.
175 * @param vp pointer to volume object
176 * @param new_state new volume state value
179 * @post volume state changed; stats updated
181 * @return previous volume state
183 * @note DEMAND_ATTACH_FS only
185 static_inline VolState
186 VChangeState_r(Volume * vp, VolState new_state)
188 VolState old_state = V_attachState(vp);
190 /* XXX profiling need to make sure these counters
191 * don't kill performance... */
192 VStats.state_levels[old_state]--;
193 VStats.state_levels[new_state]++;
195 V_attachState(vp) = new_state;
196 assert(pthread_cond_broadcast(&V_attachCV(vp)) == 0);
200 #endif /* AFS_DEMAND_ATTACH_FS */
202 #endif /* _AFS_VOL_VOLUME_INLINE_H */