From f8479e5cbc27c88f4fcf9a781d7cd5d6b7a9ff74 Mon Sep 17 00:00:00 2001 From: Adrian Vladu Date: Mon, 18 Oct 2021 15:20:10 +0300 Subject: [PATCH] Continue execution on volume extension failure When a small amount of disk space remains to be extended, the 'Virtual Disk Service' can fail with VDS_E_EXTENT_SIZE_LESS_THAN_MIN error code. This happens on environments where a volume has already been extended and there is a small amount of bytes that somehow remain residual after the initial extension. Change-Id: I072ed568ef1f2790e95851b45afb8ffcc0acce0e --- .../windows/storage/vds_storage_manager.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/cloudbaseinit/utils/windows/storage/vds_storage_manager.py b/cloudbaseinit/utils/windows/storage/vds_storage_manager.py index d9e8636e..6fe18361 100644 --- a/cloudbaseinit/utils/windows/storage/vds_storage_manager.py +++ b/cloudbaseinit/utils/windows/storage/vds_storage_manager.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import comtypes import ctypes import re @@ -22,6 +23,8 @@ from cloudbaseinit.utils.windows import vds LOG = oslo_logging.getLogger(__name__) +VDS_E_EXTENT_SIZE_LESS_THAN_MIN = -2147212237 + ole32 = ctypes.windll.ole32 ole32.CoTaskMemFree.restype = None ole32.CoTaskMemFree.argtypes = [ctypes.c_void_p] @@ -89,10 +92,19 @@ class VDSStorageManager(base.BaseStorageManager): LOG.info('Extending volume "%s" with %s bytes' % (volume_name, extend_size)) - input_disks_ar = (vds.VDS_INPUT_DISK * - len(input_disks))(*input_disks) - extend_job = volume.Extend(input_disks_ar, len(input_disks)) - extend_job.Wait() + try: + input_disks_ar = (vds.VDS_INPUT_DISK * + len(input_disks))(*input_disks) + extend_job = volume.Extend(input_disks_ar, len(input_disks)) + extend_job.Wait() + except comtypes.COMError as ex: + if ex.hresult == VDS_E_EXTENT_SIZE_LESS_THAN_MIN: + LOG.debug( + 'Volume extension failed because of a ' + 'Windows disk management bug issue where the ' + 'estimated extend size is less than the minimum.') + else: + raise def _get_volume_extents_to_resize(self, pack, volume_id): volume_extents = []