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
This commit is contained in:
Lucian Petrut 2017-12-13 11:25:23 +02:00
parent 8aa2f5a5b6
commit 32a08e4d6a
3 changed files with 54 additions and 0 deletions

View File

@ -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)

View File

@ -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 "

View File

@ -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.