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 static __inline
17 #elif defined(AFS_AIX_ENV)
18 #define static_inline static
20 #define static_inline static inline
24 /***************************************************/
25 /* demand attach fs state machine routines */
26 /***************************************************/
28 #ifdef AFS_DEMAND_ATTACH_FS
30 * tells caller whether or not the current state requires
31 * exclusive access without holding glock.
33 * @param state volume state enumeration
35 * @return whether volume state is a mutually exclusive state
36 * @retval 0 no, state is re-entrant
37 * @retval 1 yes, state is mutually exclusive
39 * @note DEMAND_ATTACH_FS only
41 * @note should VOL_STATE_SALVSYNC_REQ be treated as exclusive?
44 VIsExclusiveState(VolState state)
47 case VOL_STATE_UPDATING:
48 case VOL_STATE_ATTACHING:
49 case VOL_STATE_GET_BITMAP:
50 case VOL_STATE_HDR_LOADING:
51 case VOL_STATE_HDR_ATTACHING:
52 case VOL_STATE_OFFLINING:
53 case VOL_STATE_DETACHING:
54 case VOL_STATE_VNODE_ALLOC:
55 case VOL_STATE_VNODE_GET:
56 case VOL_STATE_VNODE_CLOSE:
57 case VOL_STATE_VNODE_RELEASE:
64 * tell caller whether V_attachState is an error condition.
66 * @param state volume state enumeration
68 * @return whether volume state is in error state
69 * @retval 0 state is not an error state
70 * @retval 1 state is an error state
72 * @note DEMAND_ATTACH_FS only
75 VIsErrorState(VolState state)
79 case VOL_STATE_SALVAGING:
86 * tell caller whether V_attachState is valid.
88 * @param state volume state enumeration
90 * @return whether volume state is a mutually exclusive state
91 * @retval 0 no, state is not valid
92 * @retval 1 yes, state is a valid enumeration member
94 * @note DEMAND_ATTACH_FS only
96 * @note do we really want to treat VOL_STATE_FREED as valid?
99 VIsValidState(VolState state)
102 (state < VOL_STATE_COUNT)) {
109 * increment volume-package internal refcount.
111 * @param vp volume object pointer
113 * @internal volume package internal use only
115 * @pre VOL_LOCK must be held
117 * @post volume waiters refcount is incremented
119 * @see VCancelReservation_r
121 * @note DEMAND_ATTACH_FS only
124 VCreateReservation_r(Volume * vp)
130 * wait for the volume to change states.
132 * @param vp volume object pointer
134 * @pre VOL_LOCK held; ref held on volume
136 * @post VOL_LOCK held; volume state has changed from previous value
138 * @note DEMAND_ATTACH_FS only
141 VWaitStateChange_r(Volume * vp)
143 VolState state_save = V_attachState(vp);
145 assert(vp->nWaiters || vp->nUsers);
147 VOL_CV_WAIT(&V_attachCV(vp));
148 } while (V_attachState(vp) == state_save);
149 assert(V_attachState(vp) != VOL_STATE_FREED);
153 * wait for blocking ops to end.
155 * @pre VOL_LOCK held; ref held on volume
157 * @post VOL_LOCK held; volume not in exclusive state
159 * @param vp volume object pointer
161 * @note DEMAND_ATTACH_FS only
164 VWaitExclusiveState_r(Volume * vp)
166 assert(vp->nWaiters || vp->nUsers);
167 while (VIsExclusiveState(V_attachState(vp))) {
168 VOL_CV_WAIT(&V_attachCV(vp));
170 assert(V_attachState(vp) != VOL_STATE_FREED);
174 * change state, and notify other threads,
175 * return previous state to caller.
177 * @param vp pointer to volume object
178 * @param new_state new volume state value
181 * @post volume state changed; stats updated
183 * @return previous volume state
185 * @note DEMAND_ATTACH_FS only
187 static_inline VolState
188 VChangeState_r(Volume * vp, VolState new_state)
190 VolState old_state = V_attachState(vp);
192 /* XXX profiling need to make sure these counters
193 * don't kill performance... */
194 VStats.state_levels[old_state]--;
195 VStats.state_levels[new_state]++;
197 V_attachState(vp) = new_state;
198 assert(pthread_cond_broadcast(&V_attachCV(vp)) == 0);
202 #endif /* AFS_DEMAND_ATTACH_FS */
204 #endif /* _AFS_VOL_VOLUME_INLINE_H */