Change vm.hvm into vm.virt_mode

Fixes QubesOS/qubes-issues#2912
This commit is contained in:
Marek Marczykowski-Górecki 2017-07-17 12:26:10 +02:00
parent 8cb831da29
commit 21940bef90
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
7 changed files with 44 additions and 23 deletions

View File

@ -2123,7 +2123,7 @@ class BackupRestore(object):
# allow kernel=None only for HVM, # allow kernel=None only for HVM,
# otherwise require valid kernel # otherwise require valid kernel
if not (vm_info.vm.property_is_default('kernel') if not (vm_info.vm.property_is_default('kernel')
or (not vm_info.vm.kernel and vm_info.vm.hvm) or (not vm_info.vm.kernel and vm_info.vm.virt_mode == 'hvm')
or vm_info.vm.kernel in installed_kernels): or vm_info.vm.kernel in installed_kernels):
if self.options.use_default_kernel: if self.options.use_default_kernel:
vm_info.vm.kernel = qubes.property.DEFAULT vm_info.vm.kernel = qubes.property.DEFAULT

View File

@ -190,7 +190,7 @@ class Core2Qubes(qubes.Qubes):
if value_is_default and value_is_default.lower() != \ if value_is_default and value_is_default.lower() != \
"true": "true":
kwargs[attr] = value kwargs[attr] = value
kwargs['hvm'] = "HVm" in vm_class_name kwargs['virt_mode'] = 'hvm' if "HVm" in vm_class_name else 'pv'
kwargs['provides_network'] = \ kwargs['provides_network'] = \
vm_class_name in ('QubesNetVm', 'QubesProxyVm') vm_class_name in ('QubesNetVm', 'QubesProxyVm')
if vm_class_name == 'QubesNetVm': if vm_class_name == 'QubesNetVm':

View File

@ -122,7 +122,7 @@ class BackupTestsMixin(qubes.tests.SystemTestsMixin):
self.log.debug("Creating %s" % vmname) self.log.debug("Creating %s" % vmname)
testvm2 = self.app.add_new_vm(qubes.vm.standalonevm.StandaloneVM, testvm2 = self.app.add_new_vm(qubes.vm.standalonevm.StandaloneVM,
name=vmname, name=vmname,
hvm=True, virt_mode='hvm',
label='red') label='red')
testvm2.create_on_disk(pool=pool) testvm2.create_on_disk(pool=pool)
self.fill_image(testvm2.storage.export('root'), 1024 * 1024 * 1024, \ self.fill_image(testvm2.storage.export('root'), 1024 * 1024 * 1024, \
@ -322,7 +322,7 @@ class TC_00_Backup(BackupTestsMixin, qubes.tests.QubesTestCase):
self.log.debug("Creating %s" % vmname) self.log.debug("Creating %s" % vmname)
hvmtemplate = self.app.add_new_vm( hvmtemplate = self.app.add_new_vm(
qubes.vm.templatevm.TemplateVM, name=vmname, hvm=True, label='red') qubes.vm.templatevm.TemplateVM, name=vmname, virt_mode='hvm', label='red')
hvmtemplate.create_on_disk() hvmtemplate.create_on_disk()
self.fill_image( self.fill_image(
os.path.join(hvmtemplate.dir_path, '00file'), os.path.join(hvmtemplate.dir_path, '00file'),

View File

@ -212,7 +212,7 @@ class TC_02_QvmPrefs(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
qubes.vm.appvm.AppVM, qubes.vm.appvm.AppVM,
name=self.make_vm_name("hvm"), name=self.make_vm_name("hvm"),
label='red') label='red')
self.testvm.hvm = True self.testvm.virt_mode = 'hvm'
self.loop.run_until_complete(self.testvm.create_on_disk()) self.loop.run_until_complete(self.testvm.create_on_disk())
self.app.save() self.app.save()
@ -326,7 +326,7 @@ class TC_03_QvmRevertTemplateChanges(qubes.tests.SystemTestsMixin,
qubes.vm.templatevm.TemplateVM, qubes.vm.templatevm.TemplateVM,
name=self.make_vm_name("hvm"), name=self.make_vm_name("hvm"),
label='red', label='red',
hvm=True virt_mode='hvm',
) )
self.loop.run_until_complete(self.test_template.create_on_disk()) self.loop.run_until_complete(self.test_template.create_on_disk())
self.app.save() self.app.save()

View File

@ -97,6 +97,19 @@ class TC_00_setters(qubes.tests.QubesTestCase):
# there is no check for self.app.get_label() # there is no check for self.app.get_label()
def test_040_setter_virt_mode(self):
self.assertEqual(
qubes.vm.qubesvm._setter_virt_mode(self.vm, self.prop, 'hvm'),
'hvm')
self.assertEqual(
qubes.vm.qubesvm._setter_virt_mode(self.vm, self.prop, 'HVM'),
'hvm')
self.assertEqual(
qubes.vm.qubesvm._setter_virt_mode(self.vm, self.prop, 'PV'),
'pv')
with self.assertRaises(ValueError):
qubes.vm.qubesvm._setter_virt_mode(self.vm, self.prop, 'True')
class QubesVMTestsMixin(object): class QubesVMTestsMixin(object):
property_no_default = object() property_no_default = object()
@ -230,10 +243,6 @@ class TC_90_QubesVM(QubesVMTestsMixin, qubes.tests.QubesTestCase):
self.assertPropertyInvalidValue(vm, 'label', 'invalid') self.assertPropertyInvalidValue(vm, 'label', 'invalid')
self.assertPropertyInvalidValue(vm, 'label', 123) self.assertPropertyInvalidValue(vm, 'label', 123)
def test_150_hvm(self):
vm = self.get_vm()
self._test_generic_bool_property(vm, 'hvm', default=True)
def test_160_memory(self): def test_160_memory(self):
vm = self.get_vm() vm = self.get_vm()
self.assertPropertyDefaultValue(vm, 'memory', 400) self.assertPropertyDefaultValue(vm, 'memory', 400)

View File

@ -102,6 +102,15 @@ def _setter_default_user(self, prop, value):
'Username can contain only those characters: ' + allowed_chars) 'Username can contain only those characters: ' + allowed_chars)
return value return value
def _setter_virt_mode(self, prop, value):
value = str(value)
value = value.lower()
if value not in ('hvm', 'pv'):
raise qubes.exc.QubesPropertyValueError(self, prop, value,
'Invalid virtualization mode, supported values: hvm, pv')
return value
class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
'''Base functionality of Qubes VM shared between all VMs. '''Base functionality of Qubes VM shared between all VMs.
@ -373,11 +382,11 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
clone=False, clone=False,
doc='UUID from libvirt.') doc='UUID from libvirt.')
hvm = qubes.property('hvm', virt_mode = qubes.property('virt_mode',
type=bool, setter=qubes.property.bool, type=str, setter=_setter_virt_mode,
default=True, default='hvm',
doc='''Use full virtualisation (HVM) for this qube, doc='''Virtualisation mode: full virtualisation ("hvm"),
instead of paravirtualisation (PV)''') or paravirtualisation ("pv")''')
installed_by_rpm = qubes.property('installed_by_rpm', installed_by_rpm = qubes.property('installed_by_rpm',
type=bool, setter=qubes.property.bool, type=bool, setter=qubes.property.bool,
@ -388,7 +397,8 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
memory = qubes.property('memory', type=int, memory = qubes.property('memory', type=int,
setter=_setter_positive_int, setter=_setter_positive_int,
default=(lambda self: default=(lambda self:
qubes.config.defaults['hvm_memory' if self.hvm else 'memory']), qubes.config.defaults[
'hvm_memory' if self.virt_mode == 'hvm' else 'memory']),
doc='Memory currently available for this VM.') doc='Memory currently available for this VM.')
maxmem = qubes.property('maxmem', type=int, maxmem = qubes.property('maxmem', type=int,
@ -1117,7 +1127,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
return return
if mem_required is None: if mem_required is None:
if self.hvm: if self.virt_mode == 'hvm':
if self.stubdom_mem: if self.stubdom_mem:
stubdom_mem = self.stubdom_mem stubdom_mem = self.stubdom_mem
else: else:
@ -1186,7 +1196,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
qrexec_args.insert(0, "-q") qrexec_args.insert(0, "-q")
qrexec_env = os.environ.copy() qrexec_env = os.environ.copy()
if not self.features.check_with_template('qrexec', not self.hvm): if not self.features.check_with_template('qrexec', False):
self.log.debug( self.log.debug(
'Starting the qrexec daemon in background, because of features') 'Starting the qrexec daemon in background, because of features')
qrexec_env['QREXEC_STARTUP_NOWAIT'] = '1' qrexec_env['QREXEC_STARTUP_NOWAIT'] = '1'

View File

@ -2,7 +2,7 @@
{% block basic %} {% block basic %}
<name>{{ vm.name }}</name> <name>{{ vm.name }}</name>
<uuid>{{ vm.uuid }}</uuid> <uuid>{{ vm.uuid }}</uuid>
{% if vm.hvm and vm.devices['pci'].persistent() | list %} {% if vm.virt_mode == 'hvm' and vm.devices['pci'].persistent() | list %}
<memory unit="MiB">{{ vm.memory }}</memory> <memory unit="MiB">{{ vm.memory }}</memory>
{% else %} {% else %}
<memory unit="MiB">{{ vm.maxmem }}</memory> <memory unit="MiB">{{ vm.maxmem }}</memory>
@ -11,6 +11,7 @@
<vcpu placement="static">{{ vm.vcpus }}</vcpu> <vcpu placement="static">{{ vm.vcpus }}</vcpu>
{% endblock %} {% endblock %}
{% block cpu %} {% block cpu %}
{% if vm.virt_mode == 'hvm' %}
<cpu mode='host-passthrough'> <cpu mode='host-passthrough'>
<!-- disable nested HVM --> <!-- disable nested HVM -->
<feature name='vmx' policy='disable'/> <feature name='vmx' policy='disable'/>
@ -18,10 +19,11 @@
<!-- disable SMAP inside VM, because of Linux bug --> <!-- disable SMAP inside VM, because of Linux bug -->
<feature name='smap' policy='disable'/> <feature name='smap' policy='disable'/>
</cpu> </cpu>
{% endif %}
{% endblock %} {% endblock %}
<os> <os>
{% block os %} {% block os %}
{% if vm.hvm %} {% if vm.virt_mode == 'hvm' %}
<type arch="x86_64" machine="xenfv">hvm</type> <type arch="x86_64" machine="xenfv">hvm</type>
<loader>hvmloader</loader> <loader>hvmloader</loader>
<boot dev="cdrom" /> <boot dev="cdrom" />
@ -38,7 +40,7 @@
<features> <features>
{% block features %} {% block features %}
{% if vm.hvm %} {% if vm.virt_mode == 'hvm' %}
<pae/> <pae/>
<acpi/> <acpi/>
<apic/> <apic/>
@ -55,7 +57,7 @@
</features> </features>
{% block clock %} {% block clock %}
{% if vm.hvm %} {% if vm.virt_mode == 'hvm' %}
{% set timezone = vm.features.check_with_template('timezone', 'localtime').lower() %} {% set timezone = vm.features.check_with_template('timezone', 'localtime').lower() %}
{% if timezone == 'localtime' %} {% if timezone == 'localtime' %}
<clock offset="variable" adjustment="0" basis="localtime" /> <clock offset="variable" adjustment="0" basis="localtime" />
@ -133,7 +135,7 @@
{% include 'libvirt/devices/pci.xml' %} {% include 'libvirt/devices/pci.xml' %}
{% endfor %} {% endfor %}
{% if vm.hvm %} {% if vm.virt_mode == 'hvm' %}
<emulator <emulator
{% if vm.features.check_with_template('linux-stubdom', True) %} {% if vm.features.check_with_template('linux-stubdom', True) %}
type="stubdom-linux" type="stubdom-linux"