Revision ef2df7d3 lib/mcpu.py
b/lib/mcpu.py | ||
---|---|---|
36 | 36 |
from ganeti import rpc |
37 | 37 |
from ganeti import cmdlib |
38 | 38 |
from ganeti import locking |
39 |
from ganeti import utils |
|
39 | 40 |
|
40 | 41 |
|
41 | 42 |
class OpExecCbBase: |
... | ... | |
55 | 56 |
|
56 | 57 |
""" |
57 | 58 |
|
59 |
def ReportLocks(self, msg): |
|
60 |
"""Report lock operations. |
|
61 |
|
|
62 |
""" |
|
63 |
|
|
58 | 64 |
|
59 | 65 |
class Processor(object): |
60 | 66 |
"""Object which runs OpCodes""" |
... | ... | |
128 | 134 |
self.rpc = rpc.RpcRunner(context.cfg) |
129 | 135 |
self.hmclass = HooksMaster |
130 | 136 |
|
137 |
def _ReportLocks(self, level, names, shared, acquired): |
|
138 |
"""Reports lock operations. |
|
139 |
|
|
140 |
@type level: int |
|
141 |
@param level: Lock level |
|
142 |
@type names: list or string |
|
143 |
@param names: Lock names |
|
144 |
@type shared: bool |
|
145 |
@param shared: Whether the lock should be acquired in shared mode |
|
146 |
@type acquired: bool |
|
147 |
@param acquired: Whether the lock has already been acquired |
|
148 |
|
|
149 |
""" |
|
150 |
parts = [] |
|
151 |
|
|
152 |
# Build message |
|
153 |
if acquired: |
|
154 |
parts.append("acquired") |
|
155 |
else: |
|
156 |
parts.append("waiting") |
|
157 |
|
|
158 |
parts.append(locking.LEVEL_NAMES[level]) |
|
159 |
|
|
160 |
if names == locking.ALL_SET: |
|
161 |
parts.append("ALL") |
|
162 |
elif isinstance(names, basestring): |
|
163 |
parts.append(names) |
|
164 |
else: |
|
165 |
parts.append(",".join(names)) |
|
166 |
|
|
167 |
if shared: |
|
168 |
parts.append("shared") |
|
169 |
else: |
|
170 |
parts.append("exclusive") |
|
171 |
|
|
172 |
msg = "/".join(parts) |
|
173 |
|
|
174 |
logging.debug("LU locks %s", msg) |
|
175 |
|
|
176 |
if self._cbs: |
|
177 |
self._cbs.ReportLocks(msg) |
|
178 |
|
|
131 | 179 |
def _ExecLU(self, lu): |
132 | 180 |
"""Logical Unit execution sequence. |
133 | 181 |
|
... | ... | |
184 | 232 |
share = lu.share_locks[level] |
185 | 233 |
if acquiring_locks: |
186 | 234 |
needed_locks = lu.needed_locks[level] |
235 |
|
|
236 |
self._ReportLocks(level, needed_locks, share, False) |
|
187 | 237 |
lu.acquired_locks[level] = self.context.glm.acquire(level, |
188 | 238 |
needed_locks, |
189 | 239 |
shared=share) |
240 |
self._ReportLocks(level, needed_locks, share, True) |
|
241 |
|
|
190 | 242 |
else: # adding_locks |
191 | 243 |
add_locks = lu.add_locks[level] |
192 | 244 |
lu.remove_locks[level] = add_locks |
... | ... | |
234 | 286 |
# Acquire the Big Ganeti Lock exclusively if this LU requires it, and in a |
235 | 287 |
# shared fashion otherwise (to prevent concurrent run with an exclusive |
236 | 288 |
# LU. |
237 |
self.context.glm.acquire(locking.LEVEL_CLUSTER, [locking.BGL], |
|
238 |
shared=not lu_class.REQ_BGL) |
|
289 |
self._ReportLocks(locking.LEVEL_CLUSTER, [locking.BGL], |
|
290 |
not lu_class.REQ_BGL, False) |
|
291 |
try: |
|
292 |
self.context.glm.acquire(locking.LEVEL_CLUSTER, [locking.BGL], |
|
293 |
shared=not lu_class.REQ_BGL) |
|
294 |
finally: |
|
295 |
self._ReportLocks(locking.LEVEL_CLUSTER, [locking.BGL], |
|
296 |
not lu_class.REQ_BGL, True) |
|
239 | 297 |
try: |
240 | 298 |
self.exclusive_BGL = lu_class.REQ_BGL |
241 | 299 |
lu = lu_class(self, op, self.context, self.rpc) |
Also available in: Unified diff