Merge "Windows SMBFS: Fix image resize errors during volume creation"

This commit is contained in:
Jenkins
2015-06-05 22:57:00 +00:00
committed by Gerrit Code Review
4 changed files with 68 additions and 20 deletions

View File

@@ -30,6 +30,7 @@ from cinder import utils
from cinder.volume.drivers import smbfs
from cinder.volume.drivers.windows import remotefs
from cinder.volume.drivers.windows import vhdutils
from cinder.volume.drivers.windows import windows_utils
VERSION = '1.1.0'
@@ -57,6 +58,7 @@ class WindowsSmbfsDriver(smbfs.SmbfsDriver):
'cifs', root_helper=None, smbfs_mount_point_base=self.base,
smbfs_mount_options=opts)
self.vhdutils = vhdutils.VHDUtils()
self._windows_utils = windows_utils.WindowsUtils()
def do_setup(self, context):
self._check_os_platform()
@@ -218,8 +220,7 @@ class WindowsSmbfsDriver(smbfs.SmbfsDriver):
volume_path, volume_format,
self.configuration.volume_dd_blocksize)
self.vhdutils.resize_vhd(volume_path,
volume['size'] * units.Gi)
self._extend_vhd_if_needed(self.local_path(volume), volume['size'])
def _copy_volume_from_snapshot(self, snapshot, volume, volume_size):
"""Copy data from snapshot to destination volume."""
@@ -246,4 +247,14 @@ 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._extend_vhd_if_needed(volume_path, volume_size)
def _extend_vhd_if_needed(self, vhd_path, new_size_gb):
old_size_bytes = self.vhdutils.get_vhd_size(vhd_path)['VirtualSize']
new_size_bytes = new_size_gb * units.Gi
# This also ensures we're not attempting to shrink the image.
is_resize_needed = self._windows_utils.is_resize_needed(
vhd_path, new_size_bytes, old_size_bytes)
if is_resize_needed:
self.vhdutils.resize_vhd(vhd_path, new_size_bytes)