Revision 066f16b0
b/lib/hypervisor/hv_kvm.py | ||
---|---|---|
761 | 761 |
|
762 | 762 |
_INFO_PCI_RE = re.compile(r'Bus.*device[ ]*(\d+).*') |
763 | 763 |
_INFO_PCI_CMD = "info pci" |
764 |
_FIND_PCI_DEVICE_RE = \ |
|
765 |
staticmethod( |
|
766 |
lambda pci, devid: re.compile(r'Bus.*device[ ]*%d,(.*\n){5,6}.*id "%s"' % |
|
767 |
(pci, devid), re.M)) |
|
768 |
|
|
764 | 769 |
_INFO_VERSION_RE = \ |
765 | 770 |
re.compile(r'^QEMU (\d+)\.(\d+)(\.(\d+))?.*monitor.*', re.M) |
766 | 771 |
_INFO_VERSION_CMD = "info version" |
... | ... | |
2071 | 2076 |
|
2072 | 2077 |
def _CallHotplugCommands(self, name, cmds): |
2073 | 2078 |
for c in cmds: |
2074 |
output = self._CallMonitorCommand(name, c) |
|
2075 |
# TODO: parse output and check if succeeded |
|
2076 |
for line in output.stdout.splitlines(): |
|
2077 |
logging.info("%s", line) |
|
2079 |
self._CallMonitorCommand(name, c) |
|
2078 | 2080 |
time.sleep(1) |
2079 | 2081 |
|
2082 |
def _VerifyHotplugCommand(self, instance_name, device, dev_type, |
|
2083 |
should_exist): |
|
2084 |
"""Checks if a previous hotplug command has succeeded. |
|
2085 |
|
|
2086 |
It issues info pci monitor command and checks depending on should_exist |
|
2087 |
value if an entry with PCI slot and device ID is found or not. |
|
2088 |
|
|
2089 |
@raise errors.HypervisorError: if result is not the expected one |
|
2090 |
|
|
2091 |
""" |
|
2092 |
output = self._CallMonitorCommand(instance_name, self._INFO_PCI_CMD) |
|
2093 |
kvm_devid = _GenerateDeviceKVMId(dev_type, device) |
|
2094 |
match = \ |
|
2095 |
self._FIND_PCI_DEVICE_RE(device.pci, kvm_devid).search(output.stdout) |
|
2096 |
if match and not should_exist: |
|
2097 |
msg = "Device %s should have been removed but is still there" % kvm_devid |
|
2098 |
raise errors.HypervisorError(msg) |
|
2099 |
|
|
2100 |
if not match and should_exist: |
|
2101 |
msg = "Device %s should have been added but is missing" % kvm_devid |
|
2102 |
raise errors.HypervisorError(msg) |
|
2103 |
|
|
2104 |
logging.info("Device %s has been correctly hot-plugged", kvm_devid) |
|
2105 |
|
|
2080 | 2106 |
def HotAddDevice(self, instance, dev_type, device, extra, seq): |
2081 | 2107 |
""" Helper method to hot-add a new device |
2082 | 2108 |
|
... | ... | |
2105 | 2131 |
utils.WriteFile(self._InstanceNICFile(instance.name, seq), data=tap) |
2106 | 2132 |
|
2107 | 2133 |
self._CallHotplugCommands(instance.name, cmds) |
2134 |
self._VerifyHotplugCommand(instance.name, device, dev_type, True) |
|
2108 | 2135 |
# update relevant entries in runtime file |
2109 | 2136 |
index = _DEVICE_RUNTIME_INDEX[dev_type] |
2110 | 2137 |
entry = _RUNTIME_ENTRY[dev_type](device, extra) |
... | ... | |
2130 | 2157 |
cmds += ["netdev_del %s" % kvm_devid] |
2131 | 2158 |
utils.RemoveFile(self._InstanceNICFile(instance.name, seq)) |
2132 | 2159 |
self._CallHotplugCommands(instance.name, cmds) |
2160 |
self._VerifyHotplugCommand(instance.name, kvm_device, dev_type, False) |
|
2133 | 2161 |
index = _DEVICE_RUNTIME_INDEX[dev_type] |
2134 | 2162 |
runtime[index].remove(entry) |
2135 | 2163 |
self._SaveKVMRuntime(instance, runtime) |
Also available in: Unified diff