Преглед на файлове

Do not use qmemman when not present (installed) on particular VMM

Marek Marczykowski-Górecki преди 11 години
родител
ревизия
69d1ae645f
променени са 2 файла, в които са добавени 39 реда и са изтрити 25 реда
  1. 20 13
      core-modules/000QubesVm.py
  2. 19 12
      core-modules/01QubesDisposableVm.py

+ 20 - 13
core-modules/000QubesVm.py

@@ -44,7 +44,12 @@ from qubes.qubes import dry_run,vmm
 from qubes.qubes import register_qubes_vm_class
 from qubes.qubes import QubesVmCollection,QubesException,QubesHost,QubesVmLabels
 from qubes.qubes import defaults,system_path,vm_files,qubes_max_qid
-from qubes.qmemman_client import QMemmanClient
+qmemman_present = False
+try:
+    from qubes.qmemman_client import QMemmanClient
+    qmemman_present = True
+except ImportError:
+    pass
 
 import qubes.qubesutils
 
@@ -968,11 +973,11 @@ class QubesVm(object):
 
         self.qdb.write("/qubes-debug-mode", str(int(self.debug)))
 
-        # Fix permissions
         # TODO: Currently whole qmemman is quite Xen-specific, so stay with
         # xenstore for it until decided otherwise
-        vmm.xs.set_permissions('', '/local/domain/{0}/memory'.format(self.xid),
-                [{ 'dom': xid }])
+        if qmemman_present:
+            vmm.xs.set_permissions('', '/local/domain/{0}/memory'.format(self.xid),
+                    [{ 'dom': xid }])
 
         # fire hooks
         for hook in self.hooks_create_xenstore_entries:
@@ -1730,14 +1735,15 @@ class QubesVm(object):
 
         if mem_required is None:
             mem_required = int(self.memory) * 1024 * 1024
-        qmemman_client = QMemmanClient()
-        try:
-            got_memory = qmemman_client.request_memory(mem_required)
-        except IOError as e:
-            raise IOError("ERROR: Failed to connect to qmemman: %s" % str(e))
-        if not got_memory:
-            qmemman_client.close()
-            raise MemoryError ("ERROR: insufficient memory to start VM '%s'" % self.name)
+        if qmemman_present:
+            qmemman_client = QMemmanClient()
+            try:
+                got_memory = qmemman_client.request_memory(mem_required)
+            except IOError as e:
+                raise IOError("ERROR: Failed to connect to qmemman: %s" % str(e))
+            if not got_memory:
+                qmemman_client.close()
+                raise MemoryError ("ERROR: insufficient memory to start VM '%s'" % self.name)
 
         # Bind pci devices to pciback driver
         for pci in self.pcidevs:
@@ -1783,7 +1789,8 @@ class QubesVm(object):
 # constructing the domain after its main process exits
 # so we close() when we know the domain is up
 # the successful unpause is some indicator of it
-        qmemman_client.close()
+        if qmemman_present:
+            qmemman_client.close()
 
         if self._start_guid_first and start_guid and not preparing_dvm and os.path.exists('/var/run/shm.id'):
             self.start_guid(verbose=verbose, notify_function=notify_function, before_qrexec=True)

+ 19 - 12
core-modules/01QubesDisposableVm.py

@@ -29,7 +29,12 @@ import time
 from qubes.qubes import QubesVm,QubesVmLabel,register_qubes_vm_class
 from qubes.qubes import QubesDispVmLabels
 from qubes.qubes import dry_run,vmm
-from qubes.qmemman_client import QMemmanClient
+qmemman_present = False
+try:
+    from qubes.qmemman_client import QMemmanClient
+    qmemman_present = True
+except ImportError:
+    pass
 
 class QubesDisposableVm(QubesVm):
     """
@@ -130,16 +135,17 @@ class QubesDisposableVm(QubesVm):
         # refresh config file
         domain_config = self.create_config_file()
 
-        mem_required = int(self.memory) * 1024 * 1024
-        print >>sys.stderr, "time=%s, getting %d memory" % (str(time.time()), mem_required)
-        qmemman_client = QMemmanClient()
-        try:
-            got_memory = qmemman_client.request_memory(mem_required)
-        except IOError as e:
-            raise IOError("ERROR: Failed to connect to qmemman: %s" % str(e))
-        if not got_memory:
-            qmemman_client.close()
-            raise MemoryError ("ERROR: insufficient memory to start VM '%s'" % self.name)
+        if qmemman_present:
+            mem_required = int(self.memory) * 1024 * 1024
+            print >>sys.stderr, "time=%s, getting %d memory" % (str(time.time()), mem_required)
+            qmemman_client = QMemmanClient()
+            try:
+                got_memory = qmemman_client.request_memory(mem_required)
+            except IOError as e:
+                raise IOError("ERROR: Failed to connect to qmemman: %s" % str(e))
+            if not got_memory:
+                qmemman_client.close()
+                raise MemoryError ("ERROR: insufficient memory to start VM '%s'" % self.name)
 
         # dispvm cannot have PCI devices
         assert (len(self.pcidevs) == 0), "DispVM cannot have PCI devices"
@@ -175,7 +181,8 @@ class QubesDisposableVm(QubesVm):
 # constructing the domain after its main process exits
 # so we close() when we know the domain is up
 # the successful unpause is some indicator of it
-        qmemman_client.close()
+        if qmemman_present:
+            qmemman_client.close()
 
         if self._start_guid_first and kwargs.get('start_guid', True) and os.path.exists('/var/run/shm.id'):
             self.start_guid(verbose=verbose,