Skip to content

Commit 127f50b

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 6deddfd commit 127f50b

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

libs/sm/cleanup.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ def __init__(self, sr, uuid, raw):
535535
self.sizeVirt = -1
536536
self._sizeVHD = -1
537537
self._sizeAllocated = -1
538-
self.hidden = False
538+
self._hidden = False
539539
self.parent = None
540540
self.children = []
541541
self._vdiRef = None
@@ -638,15 +638,15 @@ def isCoalesceable(self):
638638
return not self.scanError and \
639639
self.parent and \
640640
len(self.parent.children) == 1 and \
641-
self.hidden and \
641+
self.isHidden() and \
642642
len(self.children) > 0
643643

644644
def isLeafCoalesceable(self):
645645
"""A VDI is leaf-coalesceable if it has no siblings and is a leaf"""
646646
return not self.scanError and \
647647
self.parent and \
648648
len(self.parent.children) == 1 and \
649-
not self.hidden and \
649+
not self.isHidden() and \
650650
len(self.children) == 0
651651

652652
def canLiveCoalesce(self, speed):
@@ -674,7 +674,7 @@ def getAllPrunable(self):
674674
# some tapdisks could still be using the file.
675675
if self.sr.journaler.get(self.JRN_RELINK, self.uuid):
676676
return []
677-
if not self.scanError and self.hidden:
677+
if not self.scanError and self.isHidden():
678678
return [self]
679679
return []
680680

@@ -750,7 +750,7 @@ def delete(self):
750750

751751
def __str__(self):
752752
strHidden = ""
753-
if self.hidden:
753+
if self.isHidden():
754754
strHidden = "*"
755755
strSizeVirt = "?"
756756
if self.sizeVirt > 0:
@@ -1007,13 +1007,19 @@ def _setParent(self, parent):
10071007
Util.log("Failed to update %s with vhd-parent field %s" % \
10081008
(self.uuid, self.parentUuid))
10091009

1010+
def isHidden(self):
1011+
if self._hidden is None:
1012+
self._loadInfoHidden()
1013+
return self._hidden
1014+
10101015
def _loadInfoHidden(self):
10111016
hidden = vhdutil.getHidden(self.path)
1012-
self.hidden = (hidden != 0)
1017+
self._hidden = (hidden != 0)
10131018

10141019
def _setHidden(self, hidden=True):
1020+
self._hidden = None
10151021
vhdutil.setHidden(self.path, hidden)
1016-
self.hidden = hidden
1022+
self._hidden = hidden
10171023

10181024
def _increaseSizeVirt(self, size, atomic=True):
10191025
"""ensure the virtual size of 'self' is at least 'size'. Note that
@@ -1136,7 +1142,7 @@ def load(self, info=None):
11361142
self.sizeVirt = info.sizeVirt
11371143
self._sizeVHD = info.sizePhys
11381144
self._sizeAllocated = info.sizeAllocated
1139-
self.hidden = info.hidden
1145+
self._hidden = info.hidden
11401146
self.scanError = False
11411147
self.path = os.path.join(self.sr.path, "%s%s" % \
11421148
(self.uuid, vhdutil.FILE_EXTN_VHD))
@@ -1189,7 +1195,7 @@ def load(self, vdiInfo):
11891195
self.lvActive = vdiInfo.lvActive
11901196
self.lvOpen = vdiInfo.lvOpen
11911197
self.lvReadonly = vdiInfo.lvReadonly
1192-
self.hidden = vdiInfo.hidden
1198+
self._hidden = vdiInfo.hidden
11931199
self.parentUuid = vdiInfo.parentUuid
11941200
self.path = os.path.join(self.sr.path, self.fileName)
11951201

@@ -1314,14 +1320,19 @@ def _loadInfoSizeAllocated(self):
13141320

13151321
def _loadInfoHidden(self):
13161322
if self.raw:
1317-
self.hidden = self.sr.lvmCache.getHidden(self.fileName)
1323+
self._hidden = self.sr.lvmCache.getHidden(self.fileName)
13181324
else:
13191325
VDI._loadInfoHidden(self)
13201326

13211327
def _setHidden(self, hidden=True):
1328+
if self.raw:
1329+
self._hidden = None
1330+
self._hidden = None
1331+
if self.raw:
1332+
self._hidden = None
13221333
if self.raw:
13231334
self.sr.lvmCache.setHidden(self.fileName, hidden)
1324-
self.hidden = hidden
1335+
self._hidden = hidden
13251336
else:
13261337
VDI._setHidden(self, hidden)
13271338

@@ -1330,7 +1341,7 @@ def __str__(self):
13301341
if self.raw:
13311342
strType = "RAW"
13321343
strHidden = ""
1333-
if self.hidden:
1344+
if self.isHidden():
13341345
strHidden = "*"
13351346
strSizeVHD = ""
13361347
if self._sizeVHD > 0:
@@ -2612,9 +2623,9 @@ def _undoInterruptedCoalesceLeaf(self, childUuid, parentUuid):
26122623
child.setConfig(VDI.DB_VDI_TYPE, vhdutil.VDI_TYPE_VHD)
26132624
util.fistpoint.activate("LVHDRT_coaleaf_undo_after_rename2", self.uuid)
26142625

2615-
if child.hidden:
2626+
if child.isHidden():
26162627
child._setHidden(False)
2617-
if not parent.hidden:
2628+
if not parent.isHidden():
26182629
parent._setHidden(True)
26192630
self._updateSlavesOnUndoLeafCoalesce(parent, child)
26202631
util.fistpoint.activate("LVHDRT_coaleaf_undo_end", self.uuid)
@@ -2827,9 +2838,9 @@ def _undoInterruptedCoalesceLeaf(self, childUuid, parentUuid):
28272838
parent.deflate()
28282839
child.inflateFully()
28292840
util.fistpoint.activate("LVHDRT_coaleaf_undo_after_deflate", self.uuid)
2830-
if child.hidden:
2841+
if child.isHidden():
28312842
child._setHidden(False)
2832-
if not parent.hidden:
2843+
if not parent.isHidden():
28332844
parent._setHidden(True)
28342845
if not parent.lvReadonly:
28352846
self.lvmCache.setReadonly(parent.fileName, True)

0 commit comments

Comments
 (0)