ia64/xen-unstable

changeset 2156:9fe59cdcbfdd

bitkeeper revision 1.1159.13.3 (4118a2b8Vq29DYYv3u6Iy7NHB25wRw)

Make the suspend callback for migrate/save wait until the domain
is suspended.
author mjw@wray-m-3.hpl.hp.com
date Tue Aug 10 10:26:00 2004 +0000 (2004-08-10)
parents 31a33f49cc2c
children 3ba188e96131 c7f623950d2d
files tools/python/xen/xend/XendMigrate.py
line diff
     1.1 --- a/tools/python/xen/xend/XendMigrate.py	Tue Aug 10 10:15:57 2004 +0000
     1.2 +++ b/tools/python/xen/xend/XendMigrate.py	Tue Aug 10 10:26:00 2004 +0000
     1.3 @@ -107,6 +107,15 @@ class XfrdInfo:
     1.4              self.deferred.errback(err)
     1.5  
     1.6      def dispatch(self, xfrd, val):
     1.7 +        
     1.8 +        def cbok(v):
     1.9 +            if v is None: return
    1.10 +            sxp.show(v, out=xfrd.transport)
    1.11 +
    1.12 +        def cberr(err):
    1.13 +            v = ['xfr.err', errno.EINVAL]
    1.14 +            sxp.show(v, out=xfrd.transport)
    1.15 +
    1.16          op = sxp.name(val)
    1.17          op = op.replace('.', '_')
    1.18          if op.startswith('xfr_'):
    1.19 @@ -114,8 +123,11 @@ class XfrdInfo:
    1.20          else:
    1.21              fn = self.unknown
    1.22          val = fn(xfrd, val)
    1.23 -        if val is not None:
    1.24 -            sxp.show(val, out=xfrd.transport)
    1.25 +        if isinstance(val, defer.Deferred):
    1.26 +            val.addCallback(cbok)
    1.27 +            val.addErrback(cberr)
    1.28 +        else:
    1.29 +            cbok(val)
    1.30  
    1.31      def unknown(self, xfrd, val):
    1.32          print 'unknown>', val
    1.33 @@ -164,11 +176,40 @@ class XfrdInfo:
    1.34          return ['xfr.err', val]
    1.35  
    1.36      def xfr_vm_suspend(self, xfrd, val):
    1.37 +        """Suspend a domain. Suspending takes time, so we return
    1.38 +        a Deferred that is called when the suspend completes.
    1.39 +        """
    1.40          print 'xfr_vm_suspend>', val
    1.41          try:
    1.42              vmid = sxp.child0(val)
    1.43 +            d = defer.Deferred()
    1.44 +            # Subscribe to 'suspended' events so we can tell when the
    1.45 +            # suspend completes. Subscribe to 'died' events so we can tell if
    1.46 +            # the domain died.
    1.47 +            def onSuspended(e, v):
    1.48 +                print 'onSuspended>', e, v
    1.49 +                if v[1] != vmid: return
    1.50 +                subscribe(on=0)
    1.51 +                d.callback(v)
    1.52 +                
    1.53 +            def onDied(e, v):
    1.54 +                print 'onDied>', e, v
    1.55 +                if v[1] != vmid: return
    1.56 +                subscribe(on=0)
    1.57 +                d.errback(XendError('Domain died'))
    1.58 +                
    1.59 +            def subscribe(on=1):
    1.60 +                if on:
    1.61 +                    action = eserver.subscribe
    1.62 +                else:
    1.63 +                    action = eserver.unsubscribe
    1.64 +                action('xend.domain.suspended', onSuspended)
    1.65 +                action('xend.domain.died', onDied)
    1.66 +
    1.67 +            subscribe()
    1.68              val = self.xd.domain_shutdown(vmid, reason='suspend')
    1.69              self.suspended[vmid] = 1
    1.70 +            return d
    1.71          except:
    1.72              val = errno.EINVAL
    1.73          return ['xfr.err', val]
    1.74 @@ -216,8 +257,6 @@ class XendMigrateInfo(XfrdInfo):
    1.75          if not vmconfig:
    1.76              xfrd.loseConnection()
    1.77              return
    1.78 -        self.xd.domain_pause(self.src_dom)
    1.79 -        self.paused[self.src_dom] = 1
    1.80          xfrd.request(['xfr.migrate',
    1.81                        self.src_dom,
    1.82                        vmconfig,
    1.83 @@ -266,14 +305,11 @@ class XendSaveInfo(XfrdInfo):
    1.84          if not vmconfig:
    1.85              xfrd.loseConnection()
    1.86              return
    1.87 -        self.xd.domain_pause(self.src_dom)
    1.88 -        self.paused[self.src_dom] = 1
    1.89          xfrd.request(['xfr.save', self.src_dom, vmconfig, self.file ])
    1.90          
    1.91      def xfr_save_ok(self, xfrd, val):
    1.92 -        dom = int(sxp.child0(val))
    1.93          self.state = 'ok'
    1.94 -        self.xd_domain_destroy(self.src_dom)
    1.95 +        self.xd.domain_destroy(self.src_dom)
    1.96          if not self.deferred.called:
    1.97              self.deferred.callback(self)
    1.98