소스 검색

core: add methods to trigger ACPI S3 of VM

Those methods should be called during dom0 suspend/resume.
Marek Marczykowski-Górecki 10 년 전
부모
커밋
149971ae2e
3개의 변경된 파일49개의 추가작업 그리고 1개의 파일을 삭제
  1. 37 1
      core-modules/000QubesVm.py
  2. 3 0
      core-modules/006QubesDom0NetVm.py
  3. 9 0
      core-modules/01QubesHVm.py

+ 37 - 1
core-modules/000QubesVm.py

@@ -562,7 +562,10 @@ class QubesVm(object):
             elif dominfo['crashed']:
                 return "Crashed"
             elif dominfo['shutdown']:
-                return "Halting"
+                if dominfo['shutdown_reason'] == 2:
+                    return "Suspended"
+                else:
+                    return "Halting"
             elif dominfo['dying']:
                 return "Dying"
             else:
@@ -1532,6 +1535,39 @@ class QubesVm(object):
 
         subprocess.call (['/usr/sbin/xl', 'destroy', str(xid) if xid is not None else self.name])
 
+    def suspend(self):
+        if dry_run:
+            return
+
+        if not self.is_running() and not self.is_paused():
+            raise QubesException ("VM already stopped!")
+
+        xs_path = '/local/domain/%d/control/shutdown' % self.get_xid()
+        xs.write('', xs_path, 'suspend')
+        tries = 0
+        while self.get_power_state() != "Suspended":
+            tries += 1
+            if tries > 15:
+                # fallback to pause
+                print >>sys.stderr, "Failed to suspend domain %s, falling back to pause method" % self.name
+                self.pause()
+                break
+            time.sleep(0.2)
+
+    def resume(self):
+        if dry_run:
+            return
+
+        xc_info = self.get_xc_dominfo()
+        if not xc_info:
+            raise QubesException ("VM isn't started (cannot get xc_dominfo)!")
+
+        if xc_info['shutdown_reason'] == 2:
+            # suspended
+            xc.domain_resume(xc_info['domid'], 1)
+        else:
+            self.unpause()
+
     def pause(self):
         if dry_run:
             return

+ 3 - 0
core-modules/006QubesDom0NetVm.py

@@ -63,6 +63,9 @@ class QubesDom0NetVm(QubesNetVm):
     def start(self, **kwargs):
         raise QubesException ("Cannot start Dom0 fake domain!")
 
+    def suspend(self):
+        return
+
     def get_xl_dominfo(self):
         if dry_run:
             return

+ 9 - 0
core-modules/01QubesHVm.py

@@ -269,6 +269,15 @@ class QubesHVm(QubesVm):
 
                 self.wait_for_session(notify_function=kwargs.get('notify_function', None))
 
+    def suspend(self):
+        if dry_run:
+            return
+
+        if not self.is_running() and not self.is_paused():
+            raise QubesException ("VM not running!")
+
+        self.pause()
+
     def pause(self):
         if dry_run:
             return