ia64/xen-unstable

changeset 2222:79f922fe70cb

bitkeeper revision 1.1159.1.50 (411cafaaPlpV28_c19BEAsmasMfTcg)

Hacking to try to get migrate to localhost going.
author mjw@wray-m-3.hpl.hp.com
date Fri Aug 13 12:10:18 2004 +0000 (2004-08-13)
parents 7bac86571809
children 37ef3fbdde75
files tools/libxc/xc_linux_restore.c tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/SrvDomain.py tools/xfrd/xen_domain.c tools/xfrd/xen_domain.h tools/xfrd/xfrd.c
line diff
     1.1 --- a/tools/libxc/xc_linux_restore.c	Fri Aug 13 09:06:31 2004 +0000
     1.2 +++ b/tools/libxc/xc_linux_restore.c	Fri Aug 13 12:10:18 2004 +0000
     1.3 @@ -224,7 +224,7 @@ int xc_linux_restore(int xc_handle, XcIO
     1.4  
     1.5      /* XXX create domain on CPU=-1 so that in future it auto load ballances by default */
     1.6      if ( xc_domain_create( xc_handle,  nr_pfns * (PAGE_SIZE / 1024),
     1.7 -			   name, -1, &dom ) )
     1.8 +			   "", -1, &dom ) )
     1.9      {
    1.10  	xcio_error(ioctxt, "Could not create domain. pfns=%d, %dKB",
    1.11  		   nr_pfns,nr_pfns * (PAGE_SIZE / 1024));
     2.1 --- a/tools/python/xen/xend/XendDomain.py	Fri Aug 13 09:06:31 2004 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomain.py	Fri Aug 13 12:10:18 2004 +0000
     2.3 @@ -197,7 +197,11 @@ class XendDomain:
     2.4          """
     2.5          self.domain_by_id[info.id] = info
     2.6          self.domain_db[info.id] = info.sxpr()
     2.7 -        self.domain_by_name[info.name] = info
     2.8 +        for k, d in self.domain_by_name.items():
     2.9 +            if k != d.name:
    2.10 +                del self.domain_by_name[k]
    2.11 +        if info.name:
    2.12 +            self.domain_by_name[info.name] = info
    2.13          self.sync_domain(info.id)
    2.14          if notify: eserver.inject('xend.domain.created', [info.name, info.id])
    2.15  
    2.16 @@ -207,12 +211,13 @@ class XendDomain:
    2.17          @param id:     domain id
    2.18          @param notify: send a domain died event if true
    2.19          """
    2.20 +        for info in self.domain_by_name.values():
    2.21 +            if info.id == id:
    2.22 +                del self.domain_by_name[info.name]
    2.23          if id in self.domain_by_id:
    2.24              info = self.domain_by_id[id]
    2.25 +            del self.domain_by_id[id]
    2.26              if notify: eserver.inject('xend.domain.died', [info.name, info.id])
    2.27 -            if info.name in self.domain_by_name:
    2.28 -                del self.domain_by_name[info.name]
    2.29 -            del self.domain_by_id[id]
    2.30          if id in self.domain_db:
    2.31              del self.domain_db[id]
    2.32              self.db.delete(id)
    2.33 @@ -223,6 +228,10 @@ class XendDomain:
    2.34          """
    2.35          self.reap_cancel()
    2.36          domlist = xc.domain_getinfo()
    2.37 +        #for d in domlist:
    2.38 +        #    print 'reap> xen:  ', d['dom'], d
    2.39 +        #for d in self.domain_by_id.values():
    2.40 +        #    print 'reap> xend: ', d.id, d.info
    2.41          casualties = []
    2.42          for d in domlist:
    2.43              dead = 0
    2.44 @@ -240,9 +249,12 @@ class XendDomain:
    2.45                  log.debug('XendDomain>reap> shutdown id=%s reason=%s', id, reason)
    2.46                  if reason in ['suspend']:
    2.47                      dominfo = self.domain_by_id.get(id)
    2.48 -                    name = (dominfo and dominfo.name) or '??'
    2.49 -                    eserver.inject('xend.domain.suspended', [name, id])
    2.50 -                    continue
    2.51 +                    if dominfo.is_terminated():
    2.52 +                        log.debug('XendDomain>reap> Suspended domain died id=%s', id)
    2.53 +                    else:
    2.54 +                        name = (dominfo and dominfo.name) or '??'
    2.55 +                        eserver.inject('xend.domain.suspended', [name, id])
    2.56 +                        continue
    2.57                  if reason in ['poweroff', 'reboot']:
    2.58                      self.domain_restart_schedule(id, reason)
    2.59              destroyed += 1
    2.60 @@ -257,6 +269,10 @@ class XendDomain:
    2.61          """
    2.62          self.refresh_cancel()
    2.63          domlist = xc.domain_getinfo()
    2.64 +        #for d in domlist:
    2.65 +        #    print 'refresh> xen:  ', d['dom'], d
    2.66 +        #for d in self.domain_by_id.values():
    2.67 +        #    print 'refresh> xend: ', d.id, d.info
    2.68          # Index the domlist by id.
    2.69          # Add entries for any domains we don't know about.
    2.70          doms = {}
    2.71 @@ -344,6 +360,15 @@ class XendDomain:
    2.72          deferred.addCallback(cbok)
    2.73          return deferred
    2.74  
    2.75 +    def domain_setname(self, dom, name):
    2.76 +        """Set the name of a domain.
    2.77 +        For internal use only.
    2.78 +
    2.79 +        @param dom: domain id
    2.80 +        @param name: domain name
    2.81 +        """
    2.82 +        return xc.domain_setname(dom=dom, name=name)
    2.83 +
    2.84      def domain_restart(self, dominfo):
    2.85          """Restart a domain.
    2.86  
    2.87 @@ -358,22 +383,23 @@ class XendDomain:
    2.88          deferred.addCallback(cbok)
    2.89          return deferred        
    2.90  
    2.91 -    def domain_configure(self, id, config):
    2.92 +    def domain_configure(self, id, vmconfig):
    2.93          """Configure an existing domain. This is intended for internal
    2.94          use by domain restore and migrate.
    2.95  
    2.96 -        @param id:     domain id
    2.97 -        @param config: configuration
    2.98 +        @param id:       domain id
    2.99 +        @param vmconfig: vm configuration
   2.100          @return: deferred
   2.101          """
   2.102 -        print 'domain_configure>', id, config
   2.103 +        print 'domain_configure>', id, vmconfig
   2.104 +        config = sxp.child_value(vmconfig, 'config')
   2.105          dominfo = self.domain_lookup(id)
   2.106          print 'domain_configure>', 'dominfo=', dominfo
   2.107          for dinfo in self.domain_by_id.values():
   2.108 -            print 'domain', dinfo.id, dinfo.name
   2.109 -        log.debug('domain_configure> id=%s config=%s', id, str(config))
   2.110 +            print 'domain', 'id=', dinfo.id, 'name=', dinfo.name
   2.111 +        log.debug('domain_configure> id=%s config=%s', str(id), str(config))
   2.112          if dominfo.config:
   2.113 -            raise XendError("Domain already configured: " + dominfo.name)
   2.114 +            raise XendError("Domain already configured: " + dominfo.id)
   2.115          def cbok(dominfo):
   2.116              self._add_domain(dominfo)
   2.117              return dominfo
     3.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Aug 13 09:06:31 2004 +0000
     3.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Aug 13 12:10:18 2004 +0000
     3.3 @@ -475,6 +475,8 @@ class XendDomainInfo:
     3.4          if not dominfo:
     3.5              return
     3.6          print 'check_name>', 'dom=', dominfo.name, dominfo.dom, 'self=', name, self.dom
     3.7 +        if dominfo.is_terminated():
     3.8 +            return
     3.9          if not self.dom or (dominfo.dom != self.dom):
    3.10              raise VmError('vm name clash: ' + name)
    3.11          
    3.12 @@ -490,6 +492,8 @@ class XendDomainInfo:
    3.13          try:
    3.14              self.name = sxp.child_value(config, 'name')
    3.15              self.check_name(self.name)
    3.16 +            if self.restore and self.dom:
    3.17 +                xc.domain_setname(self.dom, self.name)
    3.18              self.memory = int(sxp.child_value(config, 'memory'))
    3.19              if self.memory is None:
    3.20                  raise VmError('missing memory size')
    3.21 @@ -629,6 +633,7 @@ class XendDomainInfo:
    3.22              if self.restart_pending():
    3.23                  self.console.deregisterChannel()
    3.24              else:
    3.25 +                log.debug('Closing console, domain %s', self.id)
    3.26                  self.console.close()
    3.27          chan = xend.getDomChannel(self.dom)
    3.28          if chan:
     4.1 --- a/tools/python/xen/xend/server/SrvDomain.py	Fri Aug 13 09:06:31 2004 +0000
     4.2 +++ b/tools/python/xen/xend/server/SrvDomain.py	Fri Aug 13 12:10:18 2004 +0000
     4.3 @@ -21,10 +21,14 @@ class SrvDomain(SrvDir):
     4.4          self.xconsole = XendConsole.instance()
     4.5  
     4.6      def op_configure(self, op, req):
     4.7 +        """Configure an existing domain.
     4.8 +        Configure is unusual in that it requires a domain id,
     4.9 +        not a domain name.
    4.10 +        """
    4.11          fn = FormFn(self.xd.domain_configure,
    4.12 -                    [['dom', 'str'],
    4.13 +                    [['dom', 'int'],
    4.14                       ['config', 'sxpr']])
    4.15 -        deferred = fn(req.args, {'dom': self.dom.name})
    4.16 +        deferred = fn(req.args, {'dom': self.dom.dom})
    4.17          deferred.addErrback(self._op_configure_err, req)
    4.18          return deferred
    4.19  
     5.1 --- a/tools/xfrd/xen_domain.c	Fri Aug 13 09:06:31 2004 +0000
     5.2 +++ b/tools/xfrd/xen_domain.c	Fri Aug 13 12:10:18 2004 +0000
     5.3 @@ -304,7 +304,6 @@ int xen_domain_configure(uint32_t dom, c
     5.4                              CURLFORM_COPYNAME,     "op",
     5.5                              CURLFORM_COPYCONTENTS, "configure",
     5.6                              CURLFORM_END);
     5.7 -
     5.8      if(formcode){
     5.9          eprintf("> Error adding op field.\n");
    5.10          err = -EINVAL;
    5.11 @@ -319,3 +318,41 @@ int xen_domain_configure(uint32_t dom, c
    5.12      dprintf("< err=%d\n", err);
    5.13      return err;
    5.14  }
    5.15 +
    5.16 +/** Get xend to unpause a domain.
    5.17 + *
    5.18 + * @param dom domain id
    5.19 + * @return 0 on success, error code otherwise
    5.20 + */
    5.21 +int xen_domain_unpause(uint32_t dom){
    5.22 +    int err = 0;
    5.23 +    CURL *curl = NULL;
    5.24 +    char url[128] = {};
    5.25 +    int url_n = sizeof(url);
    5.26 +    struct curl_httppost *form = NULL, *last = NULL;
    5.27 +    CURLFORMcode formcode = 0;
    5.28 +
    5.29 +    dprintf("> dom=%u\n", dom);
    5.30 +
    5.31 +    err = curlsetup(&curl, url, url_n, "http://localhost:%d/xend/domain/%u", XEND_PORT, dom);
    5.32 +    if(err) goto exit;
    5.33 +
    5.34 +    // Op field.
    5.35 +    formcode = curl_formadd(&form, &last,
    5.36 +                            CURLFORM_COPYNAME,     "op",
    5.37 +                            CURLFORM_COPYCONTENTS, "unpause",
    5.38 +                            CURLFORM_END);
    5.39 +    if(formcode){
    5.40 +        eprintf("> Error adding op field.\n");
    5.41 +        err = -EINVAL;
    5.42 +        goto exit;
    5.43 +    }
    5.44 +    // POST the form.
    5.45 +    curl_easy_setopt(curl, CURLOPT_HTTPPOST, form);
    5.46 +    err = curlresult(curl);
    5.47 +  exit:
    5.48 +    if(curl) curl_easy_cleanup(curl);
    5.49 +    if(form) curl_formfree(form);
    5.50 +    dprintf("< err=%d\n", err);
    5.51 +    return err;
    5.52 +}
     6.1 --- a/tools/xfrd/xen_domain.h	Fri Aug 13 09:06:31 2004 +0000
     6.2 +++ b/tools/xfrd/xen_domain.h	Fri Aug 13 12:10:18 2004 +0000
     6.3 @@ -12,4 +12,5 @@ extern int xen_domain_rcv(IOStream *io, 
     6.4  
     6.5  
     6.6  extern int xen_domain_configure(uint32_t dom, char *vmconfig, int vmconfig_n);
     6.7 +extern int xen_domain_unpause(uint32_t dom);
     6.8  #endif
     7.1 --- a/tools/xfrd/xfrd.c	Fri Aug 13 09:06:31 2004 +0000
     7.2 +++ b/tools/xfrd/xfrd.c	Fri Aug 13 12:10:18 2004 +0000
     7.3 @@ -605,13 +605,18 @@ int xfr_send_state(XfrState *state, Conn
     7.4      // Send xfr message and the domain state.
     7.5      err = xfr_send_xfr(peer, state->vmid);
     7.6      if(err) goto exit;
     7.7 +    dprintf(">*** Sending domain %u\n", state->vmid);
     7.8      err = xen_domain_snd(xend, peer->out,
     7.9                           state->vmid, state->vmconfig, state->vmconfig_n);
    7.10 +    dprintf(">*** Sent domain %u\n", state->vmid);
    7.11      if(err) goto exit;
    7.12      // Sending the domain suspends it, and there's no way back.
    7.13      // So destroy it now. If anything goes wrong now it's too late.
    7.14 +    dprintf(">*** Destroying domain %u\n", state->vmid);
    7.15      err = xfr_vm_destroy(xend, state->vmid);
    7.16      if(err) goto exit;
    7.17 +    err = xfr_error(peer, err);
    7.18 +    if(err) goto exit;
    7.19      IOStream_flush(peer->out);
    7.20      // Read the response from the peer.
    7.21      err = Conn_sxpr(peer, &sxpr);
    7.22 @@ -778,14 +783,21 @@ int xfr_save(Args *args, XfrState *state
    7.23  int xfr_recv(Args *args, XfrState *state, Conn *peer){
    7.24      int err = 0;
    7.25      time_t t0 = time(NULL), t1;
    7.26 +    Sxpr sxpr;
    7.27  
    7.28      dprintf(">\n");
    7.29      err = xen_domain_rcv(peer->in, &state->vmid_new, &state->vmconfig, &state->vmconfig_n);
    7.30      if(err) goto exit;
    7.31 -
    7.32 +    // Read from the peer. This is just so we wait before configuring.
    7.33 +    // When migrating to the same host the peer must destroy the domain
    7.34 +    // before we configure the new one.
    7.35 +    err = Conn_sxpr(peer, &sxpr);
    7.36 +    if(err) goto exit;
    7.37 +    sleep(2);
    7.38      err = xen_domain_configure(state->vmid_new, state->vmconfig, state->vmconfig_n);
    7.39      if(err) goto exit;
    7.40 -
    7.41 +    err = xen_domain_unpause(state->vmid_new);
    7.42 +    if(err) goto exit;
    7.43      // Report new domain id to peer.
    7.44      err = xfr_send_xfr_ok(peer, state->vmid_new);
    7.45      if(err) goto exit;