Skip to content

Instantly share code, notes, and snippets.

@WaltHP
Created March 4, 2015 22:25
Show Gist options
  • Save WaltHP/fc99545a013cf2ae98ab to your computer and use it in GitHub Desktop.
Save WaltHP/fc99545a013cf2ae98ab to your computer and use it in GitHub Desktop.
diff --git a/nova/storage/linuxscsi.py b/nova/storage/linuxscsi.py
index ed30462..bb7c265 100644
--- a/nova/storage/linuxscsi.py
+++ b/nova/storage/linuxscsi.py
@@ -150,3 +150,13 @@ def find_multipath_device(device):
"devices": devices}
return info
return None
+
+
+def flush_device_io(device):
+ """This is used to flush any remaining IO in the buffers."""
+ try:
+ LOG.debug("Flushing IO for device %s" % device)
+ utils.execute('blockdev', '--flushbufs', device,
+ run_as_root=True)
+ except processutils.ProcessExecutionError:
+ LOG.warn(_LW("Failed to flush IO buffers on device %s"), device)
diff --git a/nova/virt/libvirt/volume.py b/nova/virt/libvirt/volume.py
index 8688458..4d34d60 100644
--- a/nova/virt/libvirt/volume.py
+++ b/nova/virt/libvirt/volume.py
@@ -558,6 +558,9 @@ class LibvirtISCSIVolumeDriver(LibvirtBaseVolumeDriver):
if self.use_multipath and multipath_device:
return self._disconnect_volume_multipath_iscsi(iscsi_properties,
multipath_device)
+ else:
+ # remove the volume from the system.
+ self._delete_device(host_device)
# NOTE(vish): Only disconnect from the target if no luns from the
# target are in use.
@@ -571,14 +574,13 @@ class LibvirtISCSIVolumeDriver(LibvirtBaseVolumeDriver):
'/dev/disk/by-path/'))]
if not devices:
self._disconnect_from_iscsi_portal(iscsi_properties)
- elif host_device not in devices:
- # Delete device if LUN is not in use by another instance
- self._delete_device(host_device)
def _delete_device(self, device_path):
device_name = os.path.basename(os.path.realpath(device_path))
delete_control = '/sys/block/' + device_name + '/device/delete'
if os.path.exists(delete_control):
+ # Better flush an IO prior to removing it from the system
+ linuxscsi.flush_device_io(device_path)
# Copy '1' from stdin to the device delete control file
utils.execute('cp', '/dev/stdin', delete_control,
process_input='1', run_as_root=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment