Browse Source

Change vm.hvm into vm.virt_mode

Fixes QubesOS/qubes-issues#2912
Marek Marczykowski-Górecki 6 years ago
parent
commit
21940bef90

+ 1 - 1
qubes/backup.py

@@ -2123,7 +2123,7 @@ class BackupRestore(object):
                 # allow kernel=None only for HVM,
                 # otherwise require valid 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):
                     if self.options.use_default_kernel:
                         vm_info.vm.kernel = qubes.property.DEFAULT

+ 1 - 1
qubes/core2migration.py

@@ -190,7 +190,7 @@ class Core2Qubes(qubes.Qubes):
                 if value_is_default and value_is_default.lower() != \
                         "true":
                     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'] = \
                 vm_class_name in ('QubesNetVm', 'QubesProxyVm')
             if vm_class_name == 'QubesNetVm':

+ 2 - 2
qubes/tests/integ/backup.py

@@ -122,7 +122,7 @@ class BackupTestsMixin(qubes.tests.SystemTestsMixin):
         self.log.debug("Creating %s" % vmname)
         testvm2 = self.app.add_new_vm(qubes.vm.standalonevm.StandaloneVM,
                                       name=vmname,
-                                      hvm=True,
+                                      virt_mode='hvm',
                                       label='red')
         testvm2.create_on_disk(pool=pool)
         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)
 
         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()
         self.fill_image(
             os.path.join(hvmtemplate.dir_path, '00file'),

+ 2 - 2
qubes/tests/integ/basic.py

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

+ 13 - 4
qubes/tests/vm/qubesvm.py

@@ -97,6 +97,19 @@ class TC_00_setters(qubes.tests.QubesTestCase):
 
     # 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):
     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', 123)
 
-    def test_150_hvm(self):
-        vm = self.get_vm()
-        self._test_generic_bool_property(vm, 'hvm', default=True)
-
     def test_160_memory(self):
         vm = self.get_vm()
         self.assertPropertyDefaultValue(vm, 'memory', 400)

+ 18 - 8
qubes/vm/qubesvm.py

@@ -102,6 +102,15 @@ def _setter_default_user(self, prop, value):
             'Username can contain only those characters: ' + allowed_chars)
     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):
     '''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,
         doc='UUID from libvirt.')
 
-    hvm = qubes.property('hvm',
-        type=bool, setter=qubes.property.bool,
-        default=True,
-        doc='''Use full virtualisation (HVM) for this qube,
-            instead of paravirtualisation (PV)''')
+    virt_mode = qubes.property('virt_mode',
+        type=str, setter=_setter_virt_mode,
+        default='hvm',
+        doc='''Virtualisation mode: full virtualisation ("hvm"),
+            or paravirtualisation ("pv")''')
 
     installed_by_rpm = qubes.property('installed_by_rpm',
         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,
         setter=_setter_positive_int,
         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.')
 
     maxmem = qubes.property('maxmem', type=int,
@@ -1117,7 +1127,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
             return
 
         if mem_required is None:
-            if self.hvm:
+            if self.virt_mode == 'hvm':
                 if self.stubdom_mem:
                     stubdom_mem = self.stubdom_mem
                 else:
@@ -1186,7 +1196,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
             qrexec_args.insert(0, "-q")
 
         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(
                 'Starting the qrexec daemon in background, because of features')
             qrexec_env['QREXEC_STARTUP_NOWAIT'] = '1'

+ 7 - 5
templates/libvirt/xen.xml

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