From b718903b5f9afd535612f2723574bb23c8749e4a Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Tue, 4 Jul 2017 23:59:58 +0300 Subject: [PATCH] vm: Log changes in drive extension info Each time drives' capacity, allocation, or physical change, log a debug log with the new values. This log will allow easy debugging when lower level component misbehave. Here is an example log when starting a VM: 2017-08-02 02:54:24,468+0300 DEBUG (periodic/0) [virt.vm] (vmId='f33a7fbc-3dab-448c-bb41-204eccee70ba') Extension info for drive sda volume 13b40805-a43b-4c0e-9a0b-0c03a2e4ecbb: BlockInfo(capacity=8589934592L, allocation=0L, physical=1073741824L) (vm:1057) The allocation value is 0, since qemu did not write anything yet to this drive. Once qemu write to the drive, we get the correct allocation: 2017-08-02 02:54:38,473+0300 DEBUG (periodic/1) [virt.vm] (vmId='f33a7fbc-3dab-448c-bb41-204eccee70ba') Extension info for drive sda volume 13b40805-a43b-4c0e-9a0b-0c03a2e4ecbb: BlockInfo(capacity=8589934592L, allocation=2490368L, physical=1073741824L) (vm:1057) Change-Id: I68701bcb1b83295f346139b2aed64b9221a4ee44 Bug-Url: https://bugzilla.redhat.com/1461536 Signed-off-by: Nir Soffer --- lib/vdsm/virt/vm.py | 9 ++++++++- lib/vdsm/virt/vmdevices/storage.py | 12 +++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/vdsm/virt/vm.py b/lib/vdsm/virt/vm.py index a380e8dc13..dbbe843fee 100644 --- a/lib/vdsm/virt/vm.py +++ b/lib/vdsm/virt/vm.py @@ -1111,7 +1111,14 @@ def _getExtendInfo(self, drive): replica["volumeID"]) physical = volsize.apparentsize - return capacity, alloc, physical + blockinfo = vmdevices.storage.BlockInfo(capacity, alloc, physical) + + if blockinfo != drive.blockinfo: + drive.blockinfo = blockinfo + self.log.debug("Extension info for drive %s volume %s: %s", + drive.name, drive.volumeID, blockinfo) + + return blockinfo def _shouldExtendVolume(self, drive, volumeID, capacity, alloc, physical): nextPhysSize = drive.getNextVolumeSize(physical, capacity) diff --git a/lib/vdsm/virt/vmdevices/storage.py b/lib/vdsm/virt/vmdevices/storage.py index da5d0e3ab5..0cee5b64b1 100644 --- a/lib/vdsm/virt/vmdevices/storage.py +++ b/lib/vdsm/virt/vmdevices/storage.py @@ -94,6 +94,13 @@ def __init__(self, path, index): ['uuid', 'path', 'allocation', 'index']) +BlockInfo = collections.namedtuple("BlockInfo", [ + "capacity", # guest virtual size + "allocation", # host allocated size (highest allocated offset) + "physical" # host physical size (lv size, file size) +]) + + class Drive(core.Base): __slots__ = ('iface', '_path', 'readonly', 'bootOrder', 'domainID', 'poolID', 'imageID', 'UUID', 'volumeID', 'format', @@ -102,7 +109,7 @@ class Drive(core.Base): 'volumeChain', 'baseVolumeID', 'serial', 'reqsize', 'cache', 'extSharedState', 'drv', 'sgio', 'GUID', 'diskReplicate', '_diskType', 'hosts', 'protocol', 'auth', 'discard', - 'vm_custom') + 'vm_custom', 'blockinfo') VOLWM_CHUNK_SIZE = (config.getint('irs', 'volume_utilization_chunk_mb') * constants.MEGAB) VOLWM_FREE_PCT = 100 - config.getint('irs', 'volume_utilization_percent') @@ -217,6 +224,9 @@ def __init__(self, log, **kwargs): self.cache = config.get('vars', 'qemu_drive_cache') self.discard = kwargs.get('discard', False) + # Used for chunked drives or drives replicating to chunked replica. + self.blockinfo = None + self._customize() self._setExtSharedState()