From 32a08e4d6a18be743e936448f05f97113e80619c Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Wed, 13 Dec 2017 11:25:23 +0200 Subject: [PATCH] SMBFS: allow snapshot ro attach This change will allow snapshots created by the SMBFS driver to be attached in read-only mode. This will be used in order to backup in-use volumes. Note that writing to a snapshot would corrupt the differencing image chain. We'll need to locate snapshot backing files. The issue is that in some cases, in-place locks may prevent us from querying the top image from the chain. For this reason, we're going to store the backing file information in the DB using the snapshot object metadata field, at the same time preserving backwards compatibility. Fake volume/snapshot object usage throughout the smbfs driver unit tests had to be updated due to the object changes performed by it. Partial-Implements: bleuprint windows-smb-backup Change-Id: Ideaacbf9d160f400bef53825103b671127252789 --- cinder/tests/unit/windows/test_smbfs.py | 29 +++++++++++++++++++ cinder/volume/drivers/windows/smbfs.py | 19 ++++++++++++ ...mbfs-snapshot-attach-14742fe8f5864ac6.yaml | 6 ++++ 3 files changed, 54 insertions(+) create mode 100644 releasenotes/notes/smbfs-snapshot-attach-14742fe8f5864ac6.yaml diff --git a/cinder/tests/unit/windows/test_smbfs.py b/cinder/tests/unit/windows/test_smbfs.py index e49ff7eaec1..beaf3e872ae 100644 --- a/cinder/tests/unit/windows/test_smbfs.py +++ b/cinder/tests/unit/windows/test_smbfs.py @@ -177,6 +177,35 @@ class WindowsSmbFsTestCase(test.TestCase): self.assertEqual(expected, ret_val) + @mock.patch.object(smbfs.WindowsSmbfsDriver, '_get_snapshot_backing_file') + @mock.patch.object(smbfs.WindowsSmbfsDriver, 'get_volume_format') + @mock.patch.object(smbfs.WindowsSmbfsDriver, '_get_mount_point_base') + def test_initialize_connection_snapshot(self, mock_get_mount_base, + mock_get_volume_format, + mock_get_snap_by_backing_file): + self._smbfs_driver.shares = {self._FAKE_SHARE: self._FAKE_SHARE_OPTS} + mock_get_snap_by_backing_file.return_value = self._FAKE_VOLUME_NAME + mock_get_volume_format.return_value = 'vhdx' + mock_get_mount_base.return_value = self._FAKE_MNT_BASE + + exp_data = {'export': self._FAKE_SHARE, + 'format': 'vhdx', + 'name': self._FAKE_VOLUME_NAME, + 'options': self._FAKE_SHARE_OPTS, + 'access_mode': 'ro'} + expected = { + 'driver_volume_type': 'smbfs', + 'data': exp_data, + 'mount_point_base': self._FAKE_MNT_BASE} + ret_val = self._smbfs_driver.initialize_connection_snapshot( + self.snapshot, mock.sentinel.connector) + + self.assertEqual(expected, ret_val) + + mock_get_snap_by_backing_file.assert_called_once_with(self.snapshot) + mock_get_volume_format.assert_called_once_with(self.snapshot.volume) + mock_get_mount_base.assert_called_once_with() + def test_setup(self): self._test_setup(config=self._FAKE_SMBFS_CONFIG) diff --git a/cinder/volume/drivers/windows/smbfs.py b/cinder/volume/drivers/windows/smbfs.py index eab5801d461..3f240a0d89f 100644 --- a/cinder/volume/drivers/windows/smbfs.py +++ b/cinder/volume/drivers/windows/smbfs.py @@ -195,6 +195,25 @@ class WindowsSmbfsDriver(remotefs_drv.RevertToSnapshotMixin, 'mount_point_base': self._get_mount_point_base() } + @coordination.synchronized('{self.driver_prefix}-{snapshot.volume.id}') + def initialize_connection_snapshot(self, snapshot, connector): + backing_file = self._get_snapshot_backing_file(snapshot) + volume = snapshot.volume + fmt = self.get_volume_format(volume) + + data = {'export': volume.provider_location, + 'format': fmt, + 'name': backing_file, + 'access_mode': 'ro'} + + if volume.provider_location in self.shares: + data['options'] = self.shares[volume.provider_location] + return { + 'driver_volume_type': self.driver_volume_type, + 'data': data, + 'mount_point_base': self._get_mount_point_base() + } + def _check_os_platform(self): if sys.platform != 'win32': _msg = _("This system platform (%s) is not supported. This " diff --git a/releasenotes/notes/smbfs-snapshot-attach-14742fe8f5864ac6.yaml b/releasenotes/notes/smbfs-snapshot-attach-14742fe8f5864ac6.yaml new file mode 100644 index 00000000000..e3f1c3aa10a --- /dev/null +++ b/releasenotes/notes/smbfs-snapshot-attach-14742fe8f5864ac6.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The SMBFS driver now supports the 'snapshot attach' feature. Special care + must be taken when attaching snapshots though, as writing to a snapshot + will corrupt the differencing image chain.