129 |
129 |
given LU and its opcodes.
|
130 |
130 |
|
131 |
131 |
"""
|
|
132 |
adding_locks = level in lu.add_locks
|
|
133 |
acquiring_locks = level in lu.needed_locks
|
132 |
134 |
if level not in locking.LEVELS:
|
133 |
135 |
result = self._ExecLU(lu)
|
134 |
|
elif level in lu.needed_locks:
|
135 |
|
# This gives a chance to LUs to make last-minute changes after acquiring
|
136 |
|
# locks at any preceding level.
|
|
136 |
elif adding_locks and acquiring_locks:
|
|
137 |
# We could both acquire and add locks at the same level, but for now we
|
|
138 |
# don't need this, so we'll avoid the complicated code needed.
|
|
139 |
raise NotImplementedError(
|
|
140 |
"Can't declare locks to acquire when adding others")
|
|
141 |
elif adding_locks or acquiring_locks:
|
137 |
142 |
lu.DeclareLocks(level)
|
138 |
|
needed_locks = lu.needed_locks[level]
|
139 |
143 |
share = lu.share_locks[level]
|
140 |
|
# This is always safe to do, as we can't acquire more/less locks than
|
141 |
|
# what was requested.
|
142 |
|
lu.acquired_locks[level] = self.context.glm.acquire(level,
|
143 |
|
needed_locks,
|
144 |
|
shared=share)
|
|
144 |
if acquiring_locks:
|
|
145 |
needed_locks = lu.needed_locks[level]
|
|
146 |
lu.acquired_locks[level] = self.context.glm.acquire(level,
|
|
147 |
needed_locks,
|
|
148 |
shared=share)
|
|
149 |
else: # adding_locks
|
|
150 |
add_locks = lu.add_locks[level]
|
|
151 |
lu.remove_locks[level] = add_locks
|
|
152 |
try:
|
|
153 |
self.context.glm.add(level, add_locks, acquired=1, shared=share)
|
|
154 |
except errors.LockError:
|
|
155 |
raise errors.OpPrereqError(
|
|
156 |
"Coudn't add locks (%s), probably because of a race condition"
|
|
157 |
" with another job, who added them first" % add_locks)
|
145 |
158 |
try:
|
146 |
|
result = self._LockAndExecLU(lu, level + 1)
|
|
159 |
try:
|
|
160 |
if adding_locks:
|
|
161 |
lu.acquired_locks[level] = add_locks
|
|
162 |
result = self._LockAndExecLU(lu, level + 1)
|
|
163 |
finally:
|
|
164 |
if level in lu.remove_locks:
|
|
165 |
self.context.glm.remove(level, lu.remove_locks[level])
|
147 |
166 |
finally:
|
148 |
167 |
if self.context.glm.is_owned(level):
|
149 |
168 |
self.context.glm.release(level)
|