Skip to content

Commit 9a3e852

Browse files
committed
Try with sm-config entry
Signed-off-by: Damien Thenot <[email protected]>
1 parent 16e9a56 commit 9a3e852

File tree

2 files changed

+50
-38
lines changed

2 files changed

+50
-38
lines changed

drivers/blktap2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,9 @@ def _add_tag(self, vdi_uuid, writable):
15311531
self._session.xenapi.VDI.add_to_sm_config(vdi_ref, host_key,
15321532
attach_mode)
15331533
sm_config = self._session.xenapi.VDI.get_sm_config(vdi_ref)
1534-
if 'paused' in sm_config or 'relinking' in sm_config:
1534+
if "coalesceing" in sm_config:
1535+
time.sleep(2) #TODO: Is it needed to ensure that the abortTest of the coalesce see the key "activating"?
1536+
if 'paused' in sm_config or 'relinking' in sm_config or 'coalesceing' in sm_config:
15351537
util.SMlog("Found %s key, aborting" % (
15361538
'paused' if 'paused' in sm_config else 'relinking'))
15371539
self._session.xenapi.VDI.remove_from_sm_config(vdi_ref, host_key)

drivers/cleanup.py

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ class VDI(object):
527527
ONBOOT_RESET = "reset"
528528
DB_ALLOW_CACHING = "allow_caching"
529529

530+
DB_COALESCEING = "coalesceing"
531+
530532
CONFIG_TYPE = {
531533
DB_VDI_PARENT: XAPI.CONFIG_SM,
532534
DB_VDI_TYPE: XAPI.CONFIG_SM,
@@ -539,7 +541,8 @@ class VDI(object):
539541
DB_LEAFCLSC: XAPI.CONFIG_OTHER,
540542
DB_ONBOOT: XAPI.CONFIG_ON_BOOT,
541543
DB_ALLOW_CACHING: XAPI.CONFIG_ALLOW_CACHING,
542-
DB_GC_NO_SPACE: XAPI.CONFIG_SM
544+
DB_GC_NO_SPACE: XAPI.CONFIG_SM,
545+
DB_COALESCEING: XAPI.CONFIG_SM
543546
}
544547

545548
LIVE_LEAF_COALESCE_MAX_SIZE = 20 * 1024 * 1024 # bytes
@@ -838,7 +841,7 @@ def _call_plugin_coalesce(self, hostRef):
838841
self.sr.xapi.session.xenapi.host.call_plugin( \
839842
hostRef, XAPI.PLUGIN_ON_SLAVE, "commit_tapdisk", args)
840843

841-
def _doCoalesceOnHost(self, hostRef):
844+
def _doCoalesceOnHost(self, leaves: List["VDI"], hostRef: str):
842845
self.validate()
843846
self.parent.validate(True)
844847
self.parent._increaseSizeVirt(self.sizeVirt)
@@ -847,18 +850,15 @@ def _doCoalesceOnHost(self, hostRef):
847850
# Children and parent need to be RW for QCOW2 coalesce, otherwise tapdisk(libqcow) will crash trying to access them
848851

849852
def abortTest():
850-
file = self.sr._gc_running_file(self)
851853
try:
852-
with open(file, "r") as f:
853-
if not f.read():
854-
#TODO: Need to call commit cancel on the hostRef if we stop
855-
self._call_plug_cancel(hostRef)
856-
return True
857-
except OSError as e:
858-
if e.errno == errno.ENOENT:
859-
util.SMlog("File {} does not exist".format(file))
860-
else:
861-
util.SMlog("IOError: {}".format(e))
854+
for leaf in leaves:
855+
if leaf.getConfig(VDI.DB_VDI_ACTIVATING, default=False):
856+
isActivating = True
857+
break
858+
if isActivating:
859+
self._call_plug_cancel(hostRef)
860+
return True
861+
except Exception as e: #TODO: Correct exception here
862862
return True
863863
return False
864864

@@ -879,7 +879,7 @@ def _isOpenOnHosts(self) -> Optional[str]:
879879
return hostRef
880880
return None
881881

882-
def _doCoalesce(self) -> None:
882+
def _doCoalesce(self, leaves=None) -> None:
883883
"""Coalesce self onto parent. Only perform the actual coalescing of
884884
an image, but not the subsequent relinking. We'll do that as the next step,
885885
after reloading the entire SR in case things have changed while we
@@ -888,7 +888,7 @@ def _doCoalesce(self) -> None:
888888
self.parent.validate(True)
889889
self.parent._increaseSizeVirt(self.sizeVirt)
890890
self.sr._updateSlavesOnResize(self.parent)
891-
self._coalesceCowImage(0)
891+
self._coalesceCowImage(0, leaves=leaves)
892892
self.parent.validate(True)
893893
#self._verifyContents(0)
894894
self.parent.updateBlockInfo()
@@ -992,20 +992,19 @@ def _vdi_is_raw(self, vdi_path):
992992
uuid = self.extractUuid(vdi_path)
993993
return self.sr.vdis[uuid].vdi_type == VdiType.RAW
994994

995-
def _coalesceCowImage(self, timeOut):
995+
def _coalesceCowImage(self, timeOut, leaves: List["VDI"] = None):
996996
Util.log(" Running COW coalesce on %s" % self)
997997
def abortTest():
998998
if self.cowutil.isCoalesceableOnRemote():
999-
file = self.sr._gc_running_file(self)
1000999
try:
1001-
with open(file, "r") as f:
1002-
if not f.read():
1000+
if leaves is not None:
1001+
for leaf in leaves:
1002+
if leaf.getConfig(VDI.DB_VDI_ACTIVATING, default=False):
1003+
isActivating = True
1004+
break
1005+
if isActivating:
10031006
return True
1004-
except OSError as e:
1005-
if e.errno == errno.ENOENT:
1006-
util.SMlog("File {} does not exist".format(file))
1007-
else:
1008-
util.SMlog("IOError: {}".format(e))
1007+
except Exception as e: #TODO: Correct exception here
10091008
return True
10101009
return IPCFlag(self.sr.uuid).test(FLAG_TYPE_ABORT)
10111010

@@ -1490,7 +1489,7 @@ def _setChainRo(self, was_ro: List[str]) -> None:
14901489
self.sr.lvmCache.setReadonly(lvName, True)
14911490

14921491
@override
1493-
def _doCoalesce(self) -> None:
1492+
def _doCoalesce(self, leaves=None) -> None:
14941493
"""LVMVDI parents must first be activated, inflated, and made writable"""
14951494
try:
14961495
self._activateChain()
@@ -1794,7 +1793,7 @@ def _setParent(self, parent) -> None:
17941793
(self.uuid, self.parentUuid))
17951794

17961795
@override
1797-
def _doCoalesce(self) -> None:
1796+
def _doCoalesce(self, leaves=None) -> None:
17981797
try:
17991798
self._activateChain()
18001799
self.parent.validate()
@@ -2448,11 +2447,18 @@ def cleanupJournals(self, dryRun=False):
24482447
def cleanupCache(self, maxAge=-1) -> int:
24492448
return 0
24502449

2451-
def _hasLeavesAttachedOn(self, vdi: VDI):
2452-
leaves = vdi.getAllLeaves()
2450+
def _hasLeavesAttachedOn(self, leaves: List[VDI]):
24532451
leaves_vdi = [leaf.uuid for leaf in leaves]
24542452
return util.get_hosts_attached_on(self.xapi.session, leaves_vdi)
24552453

2454+
def _put_coalesce_flag_on_leaves(self, leaves: List[VDI]):
2455+
for leaf in leaves:
2456+
leaf.setConfig(VDI.DB_COALESCEING, "true")
2457+
2458+
def _remove_coalesce_flag_on_leaves(self, leaves: List[VDI]):
2459+
for leaf in leaves:
2460+
leaf.delConfig(VDI.DB_COALESCEING)
2461+
24562462
def _gc_running_file(self, vdi):
24572463
run_file = "gc_running_{}".format(vdi.uuid)
24582464
return os.path.join(NON_PERSISTENT_DIR, str(self.uuid), run_file)
@@ -2470,14 +2476,16 @@ def _coalesce(self, vdi: VDI):
24702476
# don't expect the rest of the process to take long
24712477

24722478
#TODO: Create `gc_running` in `/run/nonpersistent/sm/<sr uuid>/`
2473-
if os.path.exists(self._gc_running_file(vdi)):
2474-
util.SMlog("gc_running already exist for {}. Ignoring...".format(self.uuid))
2479+
# if os.path.exists(self._gc_running_file(vdi)):
2480+
# util.SMlog("gc_running already exist for {}. Ignoring...".format(self.uuid))
24752481

2476-
with open(self._gc_running_file(vdi), "w") as f:
2477-
f.write("1")
2482+
# with open(self._gc_running_file(vdi), "w") as f:
2483+
# f.write("1")
24782484

24792485
self.journaler.create(vdi.JRN_COALESCE, vdi.uuid, "1")
2480-
host_refs = self._hasLeavesAttachedOn(vdi)
2486+
leaves = vdi.getAllLeaves()
2487+
self._put_coalesce_flag_on_leaves(leaves)
2488+
host_refs = self._hasLeavesAttachedOn(leaves)
24812489
#TODO: this check of multiple host_refs should be done earlier in `is_coalesceable` to avoid stopping this late every time
24822490
if len(host_refs) > 1:
24832491
util.SMlog("Not coalesceable, chain activated more than once")
@@ -2486,12 +2494,13 @@ def _coalesce(self, vdi: VDI):
24862494
try:
24872495
if host_refs and vdi.cowutil.isCoalesceableOnRemote:
24882496
#Leaf opened on another host, we need to call online coalesce
2489-
vdi._doCoalesceOnHost(host_refs[0])
2497+
vdi._doCoalesceOnHost(leaves, host_refs[0])
24902498
skipRelink = True
24912499
else:
2492-
vdi._doCoalesce()
2500+
vdi._doCoalesce(leaves=leaves)
24932501
except:
2494-
os.unlink(self._gc_running_file(vdi))
2502+
self._remove_coalesce_flag_on_leaves(leaves)
2503+
# os.unlink(self._gc_running_file(vdi))
24952504
raise
24962505
"""
24972506
vdi._doCoalesce will call vdi._coalesceCowImage (after doing other things).
@@ -2520,7 +2529,8 @@ def _coalesce(self, vdi: VDI):
25202529
vdi.parent._reloadChildren(vdi)
25212530
self.journaler.remove(vdi.JRN_RELINK, vdi.uuid)
25222531

2523-
os.unlink(self._gc_running_file(vdi))
2532+
# os.unlink(self._gc_running_file(vdi))
2533+
self._remove_coalesce_flag_on_leaves(leaves)
25242534
self.deleteVDI(vdi)
25252535

25262536
class CoalesceTracker:

0 commit comments

Comments
 (0)