From 201cba76675731f6c5bb43b54e5bd66a7aa85d5d Mon Sep 17 00:00:00 2001 From: Brano Zarnovican Date: Mon, 4 Feb 2013 13:39:44 +0100 Subject: [PATCH] BUGFIX: #1112483 - device size mismatch when LUN is reused if the iSCSI session cannot be closed (because there are other LUNs still in use), we will selectively remove only the SCSI device corresponding to the volume which is being disconnected. If the same LUN id will be reused later, next connect_volume() call will notice that the local device is missing and force --rescan. We need to clear 'connection_info' in block device mapping, when volume is disconnected but stays attached (typically on stop instance). Otherwise, the manager would call disconnect_volume twice. --- nova/compute/manager.py | 4 ++++ nova/rootwrap/compute.py | 1 + nova/virt/libvirt/volume.py | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/nova/compute/manager.py b/nova/compute/manager.py index ca51fc5..3eccb23 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -720,6 +720,8 @@ class ComputeManager(manager.SchedulerDependentManager): volume, connector) self.volume_api.detach(context, volume) + self.db.block_device_mapping_update( + context, bdm['id'], {'connection_info': None, }) except exception.DiskNotFound as exc: LOG.warn(_('Ignoring DiskNotFound: %s') % exc, instance=instance) @@ -1820,6 +1822,8 @@ class ComputeManager(manager.SchedulerDependentManager): volume = self.volume_api.get(context, volume_id) connector = self.driver.get_volume_connector(instance_ref) self.volume_api.terminate_connection(context, volume, connector) + self.db.block_device_mapping_update( + context, bdm['id'], {'connection_info': None, }) except exception.NotFound: pass diff --git a/nova/rootwrap/compute.py b/nova/rootwrap/compute.py index d28d3a0..b3a3cbc 100755 --- a/nova/rootwrap/compute.py +++ b/nova/rootwrap/compute.py @@ -74,6 +74,7 @@ filterlist = [ filters.CommandFilter("/bin/chmod", "root"), # nova/virt/disk/api.py: 'cp', os.path.join(fs... + # nova/virt/libvirt/volume.py: echo 1 | cp /dev/stdin /sys/block/.. filters.CommandFilter("/bin/cp", "root"), # nova/virt/libvirt/vif.py: 'ip', 'tuntap', 'add', dev, 'mode', 'tap' diff --git a/nova/virt/libvirt/volume.py b/nova/virt/libvirt/volume.py index 2edfa1b..ffd5379 100644 --- a/nova/virt/libvirt/volume.py +++ b/nova/virt/libvirt/volume.py @@ -208,3 +208,14 @@ class LibvirtISCSIVolumeDriver(LibvirtVolumeDriver): check_exit_code=[0, 255]) self._run_iscsiadm(iscsi_properties, ('--op', 'delete'), check_exit_code=[0, 255]) + else: + # can't close the session, at least delete the device for disconnected vol + if not 'target_lun' in iscsi_properties: + return + host_device = device_prefix+str(iscsi_properties['target_lun']) + device_shortname = os.path.basename(os.path.realpath(host_device)) + delete_ctl_file = '/sys/block/'+device_shortname+'/device/delete' + if os.path.exists(delete_ctl_file): + # echo 1 > /sys/block/sdX/device/delete + utils.execute('cp', '/dev/stdin', delete_ctl_file, + process_input='1', run_as_root=True) -- 1.8.1.4