From 63092924ccddfabaaf6fd9ced8f033f8988d5298 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Mon, 13 Jun 2016 15:48:05 +0300 Subject: [PATCH] Windows SMBFS: fix VHD/x resize The os-win vhdutils resize method, by default, treats the requested size as the maximum VHD/x file size. Considering the size of the internal metadata, the virtual size of the image will be slightly smaller. Resizing an image may fail when the image size is close to the requested size, in which case the new calculated internal size may be smaller than the current image internal size. This fix consists in going back to the old behavior (pre os-win), ensuring that the new VHD/x internal size always matches the requested VHD/x size, regardless of the internal metadata overhead (which is really small anyway). Change-Id: Ib910ae388e210f33e4cfd87438e8e0ee17020d40 Closes-Bug: #1591988 --- cinder/tests/unit/windows/test_smbfs.py | 6 ++++-- cinder/volume/drivers/windows/smbfs.py | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cinder/tests/unit/windows/test_smbfs.py b/cinder/tests/unit/windows/test_smbfs.py index 910998058ce..bdf42175994 100644 --- a/cinder/tests/unit/windows/test_smbfs.py +++ b/cinder/tests/unit/windows/test_smbfs.py @@ -221,7 +221,8 @@ class WindowsSmbFsTestCase(test.TestCase): mock.sentinel.block_size) drv._vhdutils.resize_vhd.assert_called_once_with( self._FAKE_VOLUME_PATH, - self._FAKE_VOLUME['size'] * units.Gi) + self._FAKE_VOLUME['size'] * units.Gi, + is_file_max_size=False) def test_copy_volume_from_snapshot(self): drv = self._smbfs_driver @@ -251,7 +252,8 @@ class WindowsSmbFsTestCase(test.TestCase): mock.sentinel.new_volume_path) drv._vhdutils.resize_vhd.assert_called_once_with( mock.sentinel.new_volume_path, - self._FAKE_VOLUME['size'] * units.Gi) + self._FAKE_VOLUME['size'] * units.Gi, + is_file_max_size=False) def test_rebase_img(self): drv = self._smbfs_driver diff --git a/cinder/volume/drivers/windows/smbfs.py b/cinder/volume/drivers/windows/smbfs.py index f979792156e..e1f5698503c 100644 --- a/cinder/volume/drivers/windows/smbfs.py +++ b/cinder/volume/drivers/windows/smbfs.py @@ -152,7 +152,8 @@ class WindowsSmbfsDriver(smbfs.SmbfsDriver): backing_file_full_path) def _do_extend_volume(self, volume_path, size_gb, volume_name=None): - self._vhdutils.resize_vhd(volume_path, size_gb * units.Gi) + self._vhdutils.resize_vhd(volume_path, size_gb * units.Gi, + is_file_max_size=False) @remotefs_drv.locked_volume_id_operation def copy_volume_to_image(self, context, volume, image_service, image_meta): @@ -203,7 +204,8 @@ class WindowsSmbfsDriver(smbfs.SmbfsDriver): self.configuration.volume_dd_blocksize) self._vhdutils.resize_vhd(self.local_path(volume), - volume['size'] * units.Gi) + volume['size'] * units.Gi, + is_file_max_size=False) def _copy_volume_from_snapshot(self, snapshot, volume, volume_size): """Copy data from snapshot to destination volume.""" @@ -230,4 +232,5 @@ class WindowsSmbfsDriver(smbfs.SmbfsDriver): self._delete(volume_path) self._vhdutils.convert_vhd(snapshot_path, volume_path) - self._vhdutils.resize_vhd(volume_path, volume_size * units.Gi) + self._vhdutils.resize_vhd(volume_path, volume_size * units.Gi, + is_file_max_size=False)