Change in vdsm[master]: xen: hook: let oVirt run VMs on Xen hosts

danken at redhat.com danken at redhat.com
Wed Jun 4 11:43:12 UTC 2014


Dan Kenigsberg has uploaded a new change for review.

Change subject: xen: hook: let oVirt run VMs on Xen hosts
......................................................................

xen: hook: let oVirt run VMs on Xen hosts

With this hook installed (and previous hacks applied) it is possible to
start oVirt VMs as Xen domU HVM guests.

Note that this hook has undergone very limited testing: migration was
not attempted, as well as no shared storage.

The hook is known to be limited, as it does not support qcow images, or
spice; no emulated devices, no hotplugging nor virtio. It is expected to
serve as a proof of concept and as a basis to further experimentation by
other parties.

Change-Id: Iaabda72bebde98d2884fe9fcfe87d266e2dcdde0
Signed-off-by: Dan Kenigsberg <danken at redhat.com>
---
M configure.ac
M debian/Makefile.am
A debian/vdsm-hook-xen.docs
A debian/vdsm-hook-xen.install
M vdsm.spec.in
M vdsm_hooks/Makefile.am
A vdsm_hooks/xen/Makefile.am
A vdsm_hooks/xen/after_get_caps.py
A vdsm_hooks/xen/before_vm_start.py
A vdsm_hooks/xen/empty.test.xml
10 files changed, 343 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/53/28353/1

diff --git a/configure.ac b/configure.ac
index 5e7f333..0d5bcaf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -310,6 +310,7 @@
 	vdsm_hooks/vmdisk/Makefile
 	vdsm_hooks/vmfex/Makefile
 	vdsm_hooks/vmfex_dev/Makefile
+	vdsm_hooks/xen/Makefile
 	vdsm_reg/Makefile
 ])
 
diff --git a/debian/Makefile.am b/debian/Makefile.am
index 00b0d33..b65dd70 100644
--- a/debian/Makefile.am
+++ b/debian/Makefile.am
@@ -87,6 +87,8 @@
     vdsm-hook-vmfex.install \
     vdsm-hook-vmfex-dev.docs \
     vdsm-hook-vmfex-dev.install \
+    vdsm-hook-xen.docs \
+    vdsm-hook-xen.install \
     vdsm.install \
     vdsm.postinst \
     vdsm.postrm \
diff --git a/debian/vdsm-hook-xen.docs b/debian/vdsm-hook-xen.docs
new file mode 100644
index 0000000..5ecd9c6
--- /dev/null
+++ b/debian/vdsm-hook-xen.docs
@@ -0,0 +1 @@
+COPYING
diff --git a/debian/vdsm-hook-xen.install b/debian/vdsm-hook-xen.install
new file mode 100644
index 0000000..917f772
--- /dev/null
+++ b/debian/vdsm-hook-xen.install
@@ -0,0 +1,2 @@
+usr/libexec/vdsm/hooks/before_device_create/70_xen
+usr/libexec/vdsm/hooks/after_get_caps/70_xen
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 35617ab..46d3d71 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -600,6 +600,16 @@
 %description hook-vmdisk
 Hook adds additional disk image for a VM (raw or qcow2)
 
+%package hook-xen
+Summary:        Rum an oVirt VM as a Xen domU
+BuildArch:      noarch
+Requires:       %{name}
+
+%description hook-xen
+VDSM hook that allow oVirt to run its VMs as Xen domU.
+Install this hook on a Xen dom0 with HVM support, and add the host to Engine.
+
+
 %if 0%{?with_gluster}
 %package gluster
 Summary:        Gluster Plugin for VDSM
@@ -1385,7 +1395,13 @@
 %{_libexecdir}/%{vdsm_name}/hooks/before_device_create/50_vmfex
 %{_libexecdir}/%{vdsm_name}/hooks/before_device_migrate_destination/50_vmfex
 %{_libexecdir}/%{vdsm_name}/hooks/before_nic_hotplug/50_vmfex
-%endif
+
+%files hook-xen
+%defattr(-, root, root, -)
+%{_libexecdir}/%{vdsm_name}/hooks/before_vm_start/70_xen
+%{_libexecdir}/%{vdsm_name}/hooks/after_get_caps/70_xen
+
+%endif  # with_hooks
 
 %files debug-plugin
 %defattr(-, root, root, -)
diff --git a/vdsm_hooks/Makefile.am b/vdsm_hooks/Makefile.am
index 5e4d731..ef5a22a 100644
--- a/vdsm_hooks/Makefile.am
+++ b/vdsm_hooks/Makefile.am
@@ -48,6 +48,7 @@
 	vmdisk \
 	vmfex \
 	vmfex_dev \
+	xen \
 	$(NULL)
 endif
 
diff --git a/vdsm_hooks/xen/Makefile.am b/vdsm_hooks/xen/Makefile.am
new file mode 100644
index 0000000..c6c76ca
--- /dev/null
+++ b/vdsm_hooks/xen/Makefile.am
@@ -0,0 +1,42 @@
+#
+# Copyright 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+include $(top_srcdir)/build-aux/Makefile.subs
+
+CLEANFILES = \
+	config.log
+
+EXTRA_DIST = \
+	after_get_caps.py \
+	before_vm_start.py \
+	empty.test.xml \
+	$(NULL)
+
+install-data-local:
+	$(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/before_vm_start
+	$(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/after_get_caps
+	$(INSTALL_SCRIPT) $(srcdir)/before_vm_start.py \
+		$(DESTDIR)$(vdsmhooksdir)/before_vm_start/70_xen
+	$(INSTALL_SCRIPT) $(srcdir)/after_get_caps.py \
+		$(DESTDIR)$(vdsmhooksdir)/after_get_caps/70_xen
+
+uninstall-local:
+	$(RM) $(DESTDIR)$(vdsmhooksdir)/before_vm_start/70_xen
+	$(RM) $(DESTDIR)$(vdsmhooksdir)/after_get_caps/70_xen
diff --git a/vdsm_hooks/xen/after_get_caps.py b/vdsm_hooks/xen/after_get_caps.py
new file mode 100755
index 0000000..82f6ccb
--- /dev/null
+++ b/vdsm_hooks/xen/after_get_caps.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+#
+# Copyright 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+import sys
+import traceback
+
+import hooking
+
+
+def fake_caps(capsdict):
+    """Report kvmEnable, even though it is not, so the Engine knows that
+    virualization is available on this host"""
+    capsdict['kvmEnabled'] = 'True'
+    flags = set(capsdict['cpuFlags'].split(','))
+
+    # vmx is not exposed to dom0, yet Engine expects to see it
+    flags.add('vmx')
+
+    capsdict['cpuFlags'] += ','.join(flags)
+
+    return capsdict
+
+
+def test():
+    from pprint import pprint
+    pprint(fake_caps({}))
+
+
+def main():
+    hooking.write_json(fake_caps(hooking.read_json()))
+
+
+if __name__ == '__main__':
+    if '--test' in sys.argv:
+        test()
+    else:
+        try:
+            main()
+        except:
+            hooking.exit_hook('[unexpected error]: %s\n'
+                              % traceback.format_exc())
diff --git a/vdsm_hooks/xen/before_vm_start.py b/vdsm_hooks/xen/before_vm_start.py
new file mode 100755
index 0000000..17bea92
--- /dev/null
+++ b/vdsm_hooks/xen/before_vm_start.py
@@ -0,0 +1,135 @@
+#!/usr/bin/python
+#
+# Copyright 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from xml.dom import minidom
+import sys
+import traceback
+
+
+def drop_address(d):
+    addresses = d.getElementsByTagName('address')
+    if addresses:
+        d.removeChild(addresses[0])
+
+
+def drop_driver(d):
+    drivers = d.getElementsByTagName('driver')
+    if drivers:
+        d.removeChild(drivers[0])
+
+
+def xenify(domxml):
+    """Make a Vdsm-generate domxml runnable on a Xen host"""
+
+    # it's not kvm
+    domxml.getElementsByTagName('domain')[0].attributes['type'].value = 'xen'
+
+    # no vCPU hotplugging
+    vcpu = domxml.getElementsByTagName("vcpu")[0]
+    while vcpu.firstChild:
+        vcpu.removeChild(vcpu.firstChild)
+    vcpu.appendChild(domxml.createTextNode('1'))
+
+    devices = domxml.getElementsByTagName("devices")[0]
+    d = devices.firstChild
+    while d:
+        n = d.nextSibling
+        if d.nodeType == d.TEXT_NODE:
+            pass  # skip whitespace
+
+        elif d.tagName == 'channel':
+            # no support for virtio channels.
+            devices.removeChild(d)
+
+        elif d.tagName == 'graphics' and d.attributes['type'].value == 'spice':
+            raise Exception('spice not supported, try vnc')
+
+        elif d.tagName == 'memballoon':
+            # no virtio balloon
+            devices.removeChild(d)
+
+        elif d.tagName == 'controller':
+            # no controllers
+            devices.removeChild(d)
+
+        elif d.tagName == 'video':
+            # use xen video device
+            drop_address(d)
+            d.getElementsByTagName('model')[0].attributes['type'].value = 'xen'
+
+        elif d.tagName == 'interface':
+            # xen interfaces are not pci devices
+            drop_address(d)
+            d.removeChild(d.getElementsByTagName('model')[0])
+            drop_driver(d)
+
+        elif d.tagName == 'disk' and d.attributes['device'].value == 'cdrom':
+            # bug: cdrom existence makes disk non-bootable
+            # bug: empty cdrom path is handled badly by libvirt
+            devices.removeChild(d)
+
+        elif d.tagName == 'disk':
+            # xen disks are not pci devices
+            drop_address(d)
+
+            target = d.getElementsByTagName('target')[0]
+            target.attributes['bus'].value = 'xen'
+            target.attributes['dev'].value = (
+                'xvd' + target.attributes['dev'].value[2:])
+
+            driver = d.getElementsByTagName('driver')[0]
+            # most probably, enospace and co are missing, too.
+            if driver.attributes['type'].value != 'raw':
+                raise Exception(
+                    'I have no idea how to specify qcow to xen, '
+                    'please use raw')
+            d.removeChild(driver)
+
+        else:
+            pass
+        d = n
+
+    domxml.getElementsByTagName("features")[0].appendChild(
+        domxml.createElement('pae'))
+
+    return domxml
+
+
+def test():
+    domxml = minidom.parseString(sys.stdin.read())
+    print xenify(domxml).toxml(encoding='UTF-8')
+
+
+def main():
+    domxml = hooking.read_domxml()
+    hooking.write_domxml(xenify(domxml))
+
+
+if __name__ == '__main__':
+    if '--test' in sys.argv:
+        test()
+    else:
+        import hooking
+        try:
+                main()
+        except:
+            hooking.exit_hook('[unexpected error]: %s\n'
+                              % traceback.format_exc())
diff --git a/vdsm_hooks/xen/empty.test.xml b/vdsm_hooks/xen/empty.test.xml
new file mode 100644
index 0000000..710e5b9
--- /dev/null
+++ b/vdsm_hooks/xen/empty.test.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="utf-8"?><domain type="kvm">
+
+    <!-- This is a domxml of a typical, yet extremely simple, oVirt VM.
+         It is supplied here to ease tests of the xenify script. -->
+
+	<name>empty</name>
+	<uuid>a6b0e0af-7f6d-4a18-95d6-f34477be340d</uuid>
+	<memory>20480</memory>
+	<currentMemory>20480</currentMemory>
+	<vcpu current="1">160</vcpu>
+	<memtune>
+		<min_guarantee>102400</min_guarantee>
+	</memtune>
+	<devices>
+		<channel type="unix">
+			<target name="com.redhat.rhevm.vdsm" type="virtio"/>
+			<source mode="bind" path="/var/lib/libvirt/qemu/channels/a6b0e0af-7f6d-4a18-95d6-f34477be340d.com.redhat.rhevm.vdsm"/>
+		</channel>
+		<channel type="unix">
+			<target name="org.qemu.guest_agent.0" type="virtio"/>
+			<source mode="bind" path="/var/lib/libvirt/qemu/channels/a6b0e0af-7f6d-4a18-95d6-f34477be340d.org.qemu.guest_agent.0"/>
+		</channel>
+		<input bus="ps2" type="mouse"/>
+		<channel type="spicevmc">
+			<target name="com.redhat.spice.0" type="virtio"/>
+		</channel>
+		<graphics autoport="yes" keymap="en-us" listen="0" type="vnc">
+		</graphics>
+		<memballoon model="virtio"/>
+		<controller index="0" model="virtio-scsi" type="scsi">
+			<address bus="0x00" domain="0x0000" function="0x0" slot="0x04" type="pci"/>
+		</controller>
+		<video>
+			<address bus="0x00" domain="0x0000" function="0x0" slot="0x02" type="pci"/>
+			<model type="vga"/>
+		</video>
+		<interface type="bridge">
+			<address bus="0x00" domain="0x0000" function="0x0" slot="0x03" type="pci"/>
+			<mac address="00:1a:4a:bd:c4:10"/>
+			<model type="virtio"/>
+			<source bridge="ovirtmgmt"/>
+			<filterref filter="vdsm-no-mac-spoofing"/>
+			<link state="up"/>
+			<driver queues="3"/>
+		</interface>
+		<disk device="cdrom" snapshot="no" type="file">
+			<address bus="1" controller="0" target="0" type="drive" unit="0"/>
+			<source file="" startupPolicy="optional"/>
+			<target bus="ide" dev="hdc"/>
+			<readonly/>
+			<serial/>
+		</disk>
+		<disk device="disk" snapshot="no" type="file">
+			<address bus="0x00" domain="0x0000" function="0x0" slot="0x06" type="pci"/>
+			<source file="/rhev/data-center/mnt/_var_lib_images/51dcf56a-371b-43f6-824e-1f2364d17a19/images/1ebbf8d0-853c-4c56-ad80-213afddbede1/79e8fb9c-39e8-48e6-b111-06d186e910d3"/>
+			<target bus="virtio" dev="vda"/>
+			<serial>1ebbf8d0-853c-4c56-ad80-213afddbede1</serial>
+			<driver cache="none" error_policy="stop" io="threads" name="qemu" type="raw"/>
+		</disk>
+	</devices>
+	<os>
+		<type arch="x86_64" machine="rhel6.5.0">hvm</type>
+		<smbios mode="sysinfo"/>
+	</os>
+	<sysinfo type="smbios">
+		<system>
+			<entry name="manufacturer">oVirt</entry>
+			<entry name="product">oVirt Node</entry>
+			<entry name="version">6-5.el6.centos.11.2</entry>
+			<entry name="serial">AEF32683-69FA-4EFB-AE8F-3555B2C1F6E5</entry>
+			<entry name="uuid">a6b0e0af-7f6d-4a18-95d6-f34477be340d</entry>
+		</system>
+	</sysinfo>
+	<clock adjustment="0" offset="variable">
+		<timer name="rtc" tickpolicy="catchup"/>
+		<timer name="pit" tickpolicy="delay"/>
+		<timer name="hpet" present="no"/>
+	</clock>
+	<features>
+		<acpi/>
+	</features>
+
+</domain>


-- 
To view, visit http://gerrit.ovirt.org/28353
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaabda72bebde98d2884fe9fcfe87d266e2dcdde0
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Dan Kenigsberg <danken at redhat.com>


More information about the vdsm-patches mailing list