From b8b96769bfc49e75d2eee3ae561e4e9ee7615473 Mon Sep 17 00:00:00 2001 From: Yoshiaki Tamura Date: Mon, 4 Jul 2011 13:53:17 +0900 Subject: Fix boot from volume failure for network block devices. This patch looks up the device_path and swithes between 'block' and 'network' when creating libvirt.xml. --- nova/virt/libvirt.xml.template | 6 +++++- nova/virt/libvirt/connection.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'nova') diff --git a/nova/virt/libvirt.xml.template b/nova/virt/libvirt.xml.template index e1a683da8..36d8c5aaa 100644 --- a/nova/virt/libvirt.xml.template +++ b/nova/virt/libvirt.xml.template @@ -82,9 +82,13 @@ #end if #for $vol in $volumes - + + #if $vol.type == 'network' + + #else + #end if #end for diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 0c6eaab84..3168bb9df 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -971,6 +971,7 @@ class LibvirtConnection(driver.ComputeDriver): return True return False + @exception.wrap_exception def _prepare_xml_info(self, instance, rescue=False, network_info=None, block_device_mapping=None): block_device_mapping = block_device_mapping or [] @@ -993,6 +994,16 @@ class LibvirtConnection(driver.ComputeDriver): for vol in block_device_mapping: vol['mount_device'] = _strip_dev(vol['mount_device']) + if vol['device_path'].startswith('/dev/'): + vol['type'] = 'block' + elif ':' in vol['device_path']: + (protocol, name) = vol['device_path'].split(':') + vol['type'] = 'network' + vol['protocol'] = protocol + vol['device_path'] = name + else: + raise exception.InvalidDevicePath(path=vol['device_path']) + ebs_root = self._volume_in_mapping(self.root_mount_device, block_device_mapping) if self._volume_in_mapping(self.local_mount_device, -- cgit From a2b07be9fb30321eb35ba7b76fac5588c8c06300 Mon Sep 17 00:00:00 2001 From: Yoshiaki Tamura Date: Wed, 20 Jul 2011 16:18:31 +0900 Subject: Refactor device type checking. Modify duplicated logics to use newly added _get_volume_device_info(). --- nova/virt/libvirt.xml.template | 2 +- nova/virt/libvirt/connection.py | 31 ++++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'nova') diff --git a/nova/virt/libvirt.xml.template b/nova/virt/libvirt.xml.template index 36d8c5aaa..ea62524cf 100644 --- a/nova/virt/libvirt.xml.template +++ b/nova/virt/libvirt.xml.template @@ -85,7 +85,7 @@ #if $vol.type == 'network' - + #else #end if diff --git a/nova/virt/libvirt/connection.py b/nova/virt/libvirt/connection.py index 3168bb9df..ae29b50c6 100644 --- a/nova/virt/libvirt/connection.py +++ b/nova/virt/libvirt/connection.py @@ -335,21 +335,20 @@ class LibvirtConnection(driver.ComputeDriver): def attach_volume(self, instance_name, device_path, mountpoint): virt_dom = self._lookup_by_name(instance_name) mount_device = mountpoint.rpartition("/")[2] - if device_path.startswith('/dev/'): + (type, protocol, name) = \ + self._get_volume_device_info(vol['device_path']) + if type == 'block': xml = """ """ % (device_path, mount_device) - elif ':' in device_path: - (protocol, name) = device_path.split(':') + elif type == 'network': xml = """ - """ % (protocol, - name, - mount_device) + """ % (protocol, name, mount_device) else: raise exception.InvalidDevicePath(path=device_path) @@ -972,6 +971,15 @@ class LibvirtConnection(driver.ComputeDriver): return False @exception.wrap_exception + def _get_volume_device_info(self, device_path): + if device_path.startswith('/dev/'): + return ('block', None, None) + elif ':' in device_path: + (protocol, name) = device_path.split(':') + return ('network', protocol, name) + else: + raise exception.InvalidDevicePath(path=device_path) + def _prepare_xml_info(self, instance, rescue=False, network_info=None, block_device_mapping=None): block_device_mapping = block_device_mapping or [] @@ -994,15 +1002,8 @@ class LibvirtConnection(driver.ComputeDriver): for vol in block_device_mapping: vol['mount_device'] = _strip_dev(vol['mount_device']) - if vol['device_path'].startswith('/dev/'): - vol['type'] = 'block' - elif ':' in vol['device_path']: - (protocol, name) = vol['device_path'].split(':') - vol['type'] = 'network' - vol['protocol'] = protocol - vol['device_path'] = name - else: - raise exception.InvalidDevicePath(path=vol['device_path']) + (vol['type'], vol['protocol'], vol['name']) = \ + self._get_volume_device_info(vol['device_path']) ebs_root = self._volume_in_mapping(self.root_mount_device, block_device_mapping) -- cgit