Vzstorage: synchronize volume connect
We need to protect the mount procedure
against possible races between requests
for volumes located on single Vzstorage share.
Disconnect is a no-op in os-brick's remotefs connector,
hence doesn't need this.
Change-Id: I26c61a85b5daa264cbb04b4497d9b6ac16e3f3a1
Closes-Bug: #1718474
(cherry picked from commit ea20e87ad1
)
This commit is contained in:
parent
c88720628a
commit
950239707d
|
@ -67,7 +67,9 @@ class LibvirtVZStorageTestCase(test_volume.LibvirtVolumeBaseTestCase):
|
|||
self.disk_info,
|
||||
mock.sentinel.instance)
|
||||
|
||||
def test_libvirt_vzstorage_driver_connect(self):
|
||||
@mock.patch.object(vzstorage.utils, 'synchronized',
|
||||
return_value=lambda f: f)
|
||||
def test_libvirt_vzstorage_driver_connect(self, mock_synchronized):
|
||||
def brick_conn_vol(data):
|
||||
return {'path': 'vstorage://testcluster'}
|
||||
|
||||
|
@ -86,6 +88,7 @@ class LibvirtVZStorageTestCase(test_volume.LibvirtVolumeBaseTestCase):
|
|||
'-l /var/log/vstorage/testcluster/nova.log.gz '
|
||||
'-C /tmp/ssd-cache/testcluster',
|
||||
connection_info['data']['options'])
|
||||
mock_synchronized.assert_called_once_with('vz_share-testcluster')
|
||||
|
||||
def test_libvirt_vzstorage_driver_disconnect(self):
|
||||
drv = vzstorage.LibvirtVZStorageVolumeDriver(self.fake_host)
|
||||
|
|
|
@ -33,6 +33,7 @@ class LibvirtVZStorageVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver):
|
|||
"""Class implements libvirt part of volume driver for VzStorage."""
|
||||
|
||||
SHARE_FORMAT_REGEX = r'(?:(\S+):/)?([a-zA-Z0-9_-]+)(?::(\S+))?$'
|
||||
SHARE_LOCK_NAME = "vz_share-%s"
|
||||
|
||||
def __init__(self, connection):
|
||||
super(LibvirtVZStorageVolumeDriver, self).__init__(connection)
|
||||
|
@ -110,18 +111,22 @@ class LibvirtVZStorageVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver):
|
|||
|
||||
def connect_volume(self, connection_info, disk_info, instance):
|
||||
"""Attach the volume to instance_name."""
|
||||
|
||||
LOG.debug("Calling os-brick to mount vzstorage")
|
||||
vz_share = connection_info['data']['export']
|
||||
connection_info['data']['options'] = self._get_mount_opts(vz_share)
|
||||
device_info = self.connector.connect_volume(connection_info['data'])
|
||||
LOG.debug("Attached vzstorage volume %s", device_info)
|
||||
share_lock = self.SHARE_LOCK_NAME % vz_share
|
||||
|
||||
connection_info['data']['device_path'] = device_info['path']
|
||||
@utils.synchronized(share_lock)
|
||||
def _connect_volume(connection_info, disk_info, instance):
|
||||
LOG.debug("Calling os-brick to mount vzstorage")
|
||||
connection_info['data']['options'] = self._get_mount_opts(vz_share)
|
||||
device_info = self.connector.connect_volume(
|
||||
connection_info['data'])
|
||||
LOG.debug("Attached vzstorage volume %s", device_info)
|
||||
connection_info['data']['device_path'] = device_info['path']
|
||||
|
||||
return _connect_volume(connection_info, disk_info, instance)
|
||||
|
||||
def disconnect_volume(self, connection_info, disk_dev, instance):
|
||||
"""Detach the volume from instance_name."""
|
||||
|
||||
LOG.debug("calling os-brick to detach Vzstorage Volume")
|
||||
self.connector.disconnect_volume(connection_info['data'], None)
|
||||
LOG.debug("Disconnected Vzstorage Volume %s", disk_dev)
|
||||
|
|
Loading…
Reference in New Issue