Skip to content

Commit 7202a5f

Browse files
committed
Fix GC hidden attribute in case of SIGTERM signal
The GC can be interrupted by a SIGTERM signal. If this is caught while modifying a volume's hidden flag, this can have bad consequences. For example in the situation below, the hidden flag of a volume has been changed but the cached value (self.hidden) in the python process still has the old value because of the 'util.CommandException' exception that was thrown. A VDI that normally should not be hidden is still hidden after executing `_undoInterruptedCoalesceLeaf` because the hidden value was not the correct one. Code: ``` def _setHidden(self, hidden=True): vhdutil.setHidden(self.path, hidden) # Exception! Next line is never executed. self.hidden = hidden ``` Trace: ``` Jun 5 09:15:50 r620-q6 SMGC: [563219] Removed vhd-parent from dce4b0fc(2.000G/170.336M?) Jun 5 09:15:50 r620-q6 SMGC: [563219] Removed vhd-blocks from dce4b0fc(2.000G/170.336M?) Jun 5 09:15:50 r620-q6 SM: [563219] ['/usr/bin/vhd-util', 'set', '--debug', '-n', '/var/run/sr-mount/f816795d-e7a9-43df-170c-23bc329607fc/OLD_dce4b0fc-6ad1-4750-857b-45d8d2758503.vhd', '-f', 'hidden', '-v', '1'] Jun 5 09:15:50 r620-q6 SM: [563219] GC: recieved SIGTERM Jun 5 09:15:50 r620-q6 SM: [563219] FAILED in util.pread: (rc -15) stdout: '', stderr: '' Jun 5 09:15:50 r620-q6 SMGC: [563219] *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* Jun 5 09:15:50 r620-q6 SMGC: [563219] *********************** Jun 5 09:15:50 r620-q6 SMGC: [563219] * E X C E P T I O N * Jun 5 09:15:50 r620-q6 SMGC: [563219] *********************** Jun 5 09:15:50 r620-q6 SMGC: [563219] _doCoalesceLeaf: EXCEPTION <class 'util.CommandException'>, Signalled 15 Jun 5 09:15:50 r620-q6 SMGC: [563219] File "/opt/xensource/sm/cleanup.py", line 2653, in _liveLeafCoalesce Jun 5 09:15:50 r620-q6 SMGC: [563219] self._doCoalesceLeaf(vdi) Jun 5 09:15:50 r620-q6 SMGC: [563219] File "/opt/xensource/sm/cleanup.py", line 2717, in _doCoalesceLeaf Jun 5 09:15:50 r620-q6 SMGC: [563219] vdi._setHidden(True) Jun 5 09:15:50 r620-q6 SMGC: [563219] File "/opt/xensource/sm/cleanup.py", line 1063, in _setHidden Jun 5 09:15:50 r620-q6 SMGC: [563219] vhdutil.setHidden(self.path, hidden) Jun 5 09:15:50 r620-q6 SMGC: [563219] File "/opt/xensource/sm/vhdutil.py", line 235, in setHidden Jun 5 09:15:50 r620-q6 SMGC: [563219] ret = ioretry(cmd) Jun 5 09:15:50 r620-q6 SMGC: [563219] File "/opt/xensource/sm/vhdutil.py", line 94, in ioretry Jun 5 09:15:50 r620-q6 SMGC: [563219] errlist=[errno.EIO, errno.EAGAIN]) Jun 5 09:15:50 r620-q6 SMGC: [563219] File "/opt/xensource/sm/util.py", line 347, in ioretry Jun 5 09:15:50 r620-q6 SMGC: [563219] return f() Jun 5 09:15:50 r620-q6 SMGC: [563219] File "/opt/xensource/sm/vhdutil.py", line 93, in <lambda> Jun 5 09:15:50 r620-q6 SMGC: [563219] return util.ioretry(lambda: util.pread2(cmd, text=text), Jun 5 09:15:50 r620-q6 SMGC: [563219] File "/opt/xensource/sm/util.py", line 255, in pread2 Jun 5 09:15:50 r620-q6 SMGC: [563219] return pread(cmdlist, quiet=quiet, text=text) Jun 5 09:15:50 r620-q6 SMGC: [563219] File "/opt/xensource/sm/util.py", line 217, in pread Jun 5 09:15:50 r620-q6 SMGC: [563219] raise CommandException(rc, str(cmdlist), stderr.strip()) Jun 5 09:15:50 r620-q6 SMGC: [563219] Jun 5 09:15:50 r620-q6 SMGC: [563219] *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~* Jun 5 09:15:50 r620-q6 SMGC: [563219] *** UNDO LEAF-COALESCE Jun 5 09:15:50 r620-q6 SMGC: [563219] Renaming parent back: dce4b0fc-6ad1-4750-857b-45d8d2758503 -> 056b6f93-66ff-460a-9354-157540b584a8 Jun 5 09:15:50 r620-q6 SMGC: [563219] Renaming /var/run/sr-mount/f816795d-e7a9-43df-170c-23bc329607fc/dce4b0fc-6ad1-4750-857b-45d8d2758503.vhd -> /var/run/sr-mount/f816795d-e7a9-43df-170c-23bc329607fc/056b6f93-66ff-460a-9354-157540b584a8.vhd Jun 5 09:15:50 r620-q6 SMGC: [563219] Renaming child back to dce4b0fc-6ad1-4750-857b-45d8d2758503 Jun 5 09:15:50 r620-q6 SMGC: [563219] Renaming /var/run/sr-mount/f816795d-e7a9-43df-170c-23bc329607fc/OLD_dce4b0fc-6ad1-4750-857b-45d8d2758503.vhd -> /var/run/sr-mount/f816795d-e7a9-43df-170c-23bc329607fc/dce4b0fc-6ad1-4750-857b-45d8d2758503.vhd Jun 5 09:15:50 r620-q6 SMGC: [563219] Updating the VDI record Jun 5 09:15:50 r620-q6 SMGC: [563219] Set vhd-parent = 056b6f93-66ff-460a-9354-157540b584a8 for dce4b0fc(2.000G/8.500K?) Jun 5 09:15:50 r620-q6 SMGC: [563219] Set vdi_type = vhd for dce4b0fc(2.000G/8.500K?) Jun 5 09:15:50 r620-q6 SM: [563219] ['/usr/bin/vhd-util', 'set', '--debug', '-n', '/var/run/sr-mount/f816795d-e7a9-43df-170c-23bc329607fc/056b6f93-66ff-460a-9354-157540b584a8.vhd', '-f', 'hidden', '-v', '1'] Jun 5 09:15:50 r620-q6 SM: [563219] pread SUCCESS Jun 5 09:15:50 r620-q6 SMGC: [563219] *** leaf-coalesce undo successful ``` Therefore, a VDI impacted by this problem remains hidden and can no longer be used correctly without manual intervention: ``` Jun 5 09:16:29 r620-q6 SM: [566174] lock: released /var/lock/sm/f816795d-e7a9-43df-170c-23bc329607fc/sr Jun 5 09:16:29 r620-q6 SM: [566174] ***** generic exception: vdi_clone: EXCEPTION <class 'xs_errors.SROSError'>, Failed to clone VDI [opterr=hidden VDI] Jun 5 09:16:29 r620-q6 SM: [566174] File "/opt/xensource/sm/SRCommand.py", line 113, in run Jun 5 09:16:29 r620-q6 SM: [566174] return self._run_locked(sr) Jun 5 09:16:29 r620-q6 SM: [566174] File "/opt/xensource/sm/SRCommand.py", line 163, in _run_locked Jun 5 09:16:29 r620-q6 SM: [566174] rv = self._run(sr, target) Jun 5 09:16:29 r620-q6 SM: [566174] File "/opt/xensource/sm/SRCommand.py", line 270, in _run Jun 5 09:16:29 r620-q6 SM: [566174] return target.clone(self.params['sr_uuid'], self.vdi_uuid) Jun 5 09:16:29 r620-q6 SM: [566174] File "/opt/xensource/sm/FileSR.py", line 704, in clone Jun 5 09:16:29 r620-q6 SM: [566174] return self._do_snapshot(sr_uuid, vdi_uuid, VDI.SNAPSHOT_DOUBLE) Jun 5 09:16:29 r620-q6 SM: [566174] File "/opt/xensource/sm/FileSR.py", line 754, in _do_snapshot Jun 5 09:16:29 r620-q6 SM: [566174] return self._snapshot(snapType, cbtlog, consistency_state) Jun 5 09:16:29 r620-q6 SM: [566174] File "/opt/xensource/sm/FileSR.py", line 797, in _snapshot Jun 5 09:16:29 r620-q6 SM: [566174] raise xs_errors.XenError('VDIClone', opterr='hidden VDI') Jun 5 09:16:29 r620-q6 SM: [566174] ``` Signed-off-by: Ronan Abhamon <[email protected]>
1 parent 31d1b02 commit 7202a5f

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

drivers/cleanup.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ def __init__(self, sr, uuid, raw):
561561
self.sizeVirt = -1
562562
self._sizeVHD = -1
563563
self._sizeAllocated = -1
564-
self.hidden = False
564+
self._hidden = False
565565
self.parent = None
566566
self.children = []
567567
self._vdiRef = None
@@ -664,15 +664,15 @@ def isCoalesceable(self):
664664
return not self.scanError and \
665665
self.parent and \
666666
len(self.parent.children) == 1 and \
667-
self.hidden and \
667+
self.isHidden() and \
668668
len(self.children) > 0
669669

670670
def isLeafCoalesceable(self):
671671
"""A VDI is leaf-coalesceable if it has no siblings and is a leaf"""
672672
return not self.scanError and \
673673
self.parent and \
674674
len(self.parent.children) == 1 and \
675-
not self.hidden and \
675+
not self.isHidden() and \
676676
len(self.children) == 0
677677

678678
def canLiveCoalesce(self, speed):
@@ -700,7 +700,7 @@ def getAllPrunable(self):
700700
# some tapdisks could still be using the file.
701701
if self.sr.journaler.get(self.JRN_RELINK, self.uuid):
702702
return []
703-
if not self.scanError and self.hidden:
703+
if not self.scanError and self.isHidden():
704704
return [self]
705705
return []
706706

@@ -724,7 +724,7 @@ def getAllPrunable(self):
724724
# Normally we are not in this function when the delete action is
725725
# executed but in `_liveLeafCoalesce`.
726726

727-
if not self.scanError and not self.hidden and thisPrunable:
727+
if not self.scanError and not self.isHidden() and thisPrunable:
728728
vdiList.append(self)
729729
return vdiList
730730

@@ -795,7 +795,7 @@ def repair(self, parent) -> None:
795795
@override
796796
def __str__(self) -> str:
797797
strHidden = ""
798-
if self.hidden:
798+
if self.isHidden():
799799
strHidden = "*"
800800
strSizeVirt = "?"
801801
if self.sizeVirt > 0:
@@ -1055,13 +1055,19 @@ def _setParent(self, parent) -> None:
10551055
Util.log("Failed to update %s with vhd-parent field %s" % \
10561056
(self.uuid, self.parentUuid))
10571057

1058+
def isHidden(self) -> bool:
1059+
if self._hidden is None:
1060+
self._loadInfoHidden()
1061+
return self._hidden
1062+
10581063
def _loadInfoHidden(self) -> None:
10591064
hidden = vhdutil.getHidden(self.path)
1060-
self.hidden = (hidden != 0)
1065+
self._hidden = (hidden != 0)
10611066

10621067
def _setHidden(self, hidden=True) -> None:
1068+
self._hidden = None
10631069
vhdutil.setHidden(self.path, hidden)
1064-
self.hidden = hidden
1070+
self._hidden = hidden
10651071

10661072
def _increaseSizeVirt(self, size, atomic=True) -> None:
10671073
"""ensure the virtual size of 'self' is at least 'size'. Note that
@@ -1185,7 +1191,7 @@ def load(self, info=None) -> None:
11851191
self.sizeVirt = info.sizeVirt
11861192
self._sizeVHD = info.sizePhys
11871193
self._sizeAllocated = info.sizeAllocated
1188-
self.hidden = info.hidden
1194+
self._hidden = info.hidden
11891195
self.scanError = False
11901196
self.path = os.path.join(self.sr.path, "%s%s" % \
11911197
(self.uuid, vhdutil.FILE_EXTN_VHD))
@@ -1244,7 +1250,7 @@ def load(self, info=None) -> None:
12441250
self.lvActive = info.lvActive
12451251
self.lvOpen = info.lvOpen
12461252
self.lvReadonly = info.lvReadonly
1247-
self.hidden = info.hidden
1253+
self._hidden = info.hidden
12481254
self.parentUuid = info.parentUuid
12491255
self.path = os.path.join(self.sr.path, self.fileName)
12501256

@@ -1377,15 +1383,16 @@ def _loadInfoSizeAllocated(self):
13771383
@override
13781384
def _loadInfoHidden(self) -> None:
13791385
if self.raw:
1380-
self.hidden = self.sr.lvmCache.getHidden(self.fileName)
1386+
self._hidden = self.sr.lvmCache.getHidden(self.fileName)
13811387
else:
13821388
VDI._loadInfoHidden(self)
13831389

13841390
@override
13851391
def _setHidden(self, hidden=True) -> None:
13861392
if self.raw:
1393+
self._hidden = None
13871394
self.sr.lvmCache.setHidden(self.fileName, hidden)
1388-
self.hidden = hidden
1395+
self._hidden = hidden
13891396
else:
13901397
VDI._setHidden(self, hidden)
13911398

@@ -1395,7 +1402,7 @@ def __str__(self) -> str:
13951402
if self.raw:
13961403
strType = "RAW"
13971404
strHidden = ""
1398-
if self.hidden:
1405+
if self.isHidden():
13991406
strHidden = "*"
14001407
strSizeVHD = ""
14011408
if self._sizeVHD > 0:
@@ -1573,7 +1580,7 @@ def load(self, info=None) -> None:
15731580
self._sizeVHD = -1
15741581
self._sizeAllocated = -1
15751582
self.drbd_size = -1
1576-
self.hidden = info.hidden
1583+
self._hidden = info.hidden
15771584
self.scanError = False
15781585
self.vdi_type = vhdutil.VDI_TYPE_VHD
15791586

@@ -1747,10 +1754,11 @@ def _setHidden(self, hidden=True) -> None:
17471754
HIDDEN_TAG = 'hidden'
17481755

17491756
if self.raw:
1757+
self._hidden = None
17501758
self.sr._linstor.update_volume_metadata(self.uuid, {
17511759
HIDDEN_TAG: hidden
17521760
})
1753-
self.hidden = hidden
1761+
self._hidden = hidden
17541762
else:
17551763
VDI._setHidden(self, hidden)
17561764

@@ -3011,9 +3019,9 @@ def _undoInterruptedCoalesceLeaf(self, childUuid, parentUuid):
30113019
child.setConfig(VDI.DB_VDI_TYPE, vhdutil.VDI_TYPE_VHD)
30123020
util.fistpoint.activate("LVHDRT_coaleaf_undo_after_rename2", self.uuid)
30133021

3014-
if child.hidden:
3022+
if child.isHidden():
30153023
child._setHidden(False)
3016-
if not parent.hidden:
3024+
if not parent.isHidden():
30173025
parent._setHidden(True)
30183026
self._updateSlavesOnUndoLeafCoalesce(parent, child)
30193027
util.fistpoint.activate("LVHDRT_coaleaf_undo_end", self.uuid)
@@ -3245,9 +3253,9 @@ def _undoInterruptedCoalesceLeaf(self, childUuid, parentUuid):
32453253
parent.deflate()
32463254
child.inflateFully()
32473255
util.fistpoint.activate("LVHDRT_coaleaf_undo_after_deflate", self.uuid)
3248-
if child.hidden:
3256+
if child.isHidden():
32493257
child._setHidden(False)
3250-
if not parent.hidden:
3258+
if not parent.isHidden():
32513259
parent._setHidden(True)
32523260
if not parent.lvReadonly:
32533261
self.lvmCache.setReadonly(parent.fileName, True)
@@ -3601,9 +3609,9 @@ def _undoInterruptedCoalesceLeaf(self, childUuid, parentUuid):
36013609

36023610
# TODO: Maybe deflate here.
36033611

3604-
if child.hidden:
3612+
if child.isHidden():
36053613
child._setHidden(False)
3606-
if not parent.hidden:
3614+
if not parent.isHidden():
36073615
parent._setHidden(True)
36083616
self._updateSlavesOnUndoLeafCoalesce(parent, child)
36093617
Util.log('*** leaf-coalesce undo successful')

0 commit comments

Comments
 (0)