direct-io.hg

changeset 2590:98bdf2c88015

bitkeeper revision 1.1159.1.201 (41600e1fkVMoQU0dVgk1h6vT502hEg)

Merge
author iap10@labyrinth.cl.cam.ac.uk
date Sun Oct 03 14:35:11 2004 +0000 (2004-10-03)
parents 80fce5fd8284 b661254cb10b
children a4fbb98f00cb
files tools/libxc/xc.h tools/libxc/xc_linux_restore.c tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendMigrate.py tools/python/xen/xend/server/SrvDomainDir.py tools/xfrd/xen_domain.c tools/xfrd/xen_domain.h tools/xfrd/xfrd.c
line diff
     1.1 --- a/tools/libxc/xc.h	Sat Oct 02 14:25:55 2004 +0000
     1.2 +++ b/tools/libxc/xc.h	Sun Oct 03 14:35:11 2004 +0000
     1.3 @@ -75,9 +75,10 @@ int xc_shadow_control(int xc_handle,
     1.4                        xc_shadow_control_stats_t *stats);
     1.5  
     1.6  
     1.7 -#define XCFLAGS_VERBOSE 1
     1.8 -#define XCFLAGS_LIVE    2
     1.9 -#define XCFLAGS_DEBUG   4
    1.10 +#define XCFLAGS_VERBOSE   1
    1.11 +#define XCFLAGS_LIVE      2
    1.12 +#define XCFLAGS_DEBUG     4
    1.13 +#define XCFLAGS_CONFIGURE 8
    1.14  
    1.15  struct XcIOContext;
    1.16  int xc_linux_save(int xc_handle, struct XcIOContext *ioctxt);
     2.1 --- a/tools/libxc/xc_linux_restore.c	Sat Oct 02 14:25:55 2004 +0000
     2.2 +++ b/tools/libxc/xc_linux_restore.c	Sun Oct 03 14:35:11 2004 +0000
     2.3 @@ -243,6 +243,15 @@ int xc_linux_restore(int xc_handle, XcIO
     2.4      }
     2.5      shared_info_frame = op.u.getdomaininfo.shared_info_frame;
     2.6  
     2.7 +    if(ioctxt->flags & XCFLAGS_CONFIGURE)
     2.8 +    {
     2.9 +        if(xcio_configure_domain(ioctxt))
    2.10 +        {
    2.11 +           xcio_error(ioctxt, "Configuring domain failed"); 
    2.12 +           goto out;
    2.13 +        }
    2.14 +    }
    2.15 +
    2.16      /* Build the pfn-to-mfn table. We choose MFN ordering returned by Xen. */
    2.17      if ( get_pfn_list(xc_handle, dom, pfn_to_mfn_table, nr_pfns) != nr_pfns )
    2.18      {
     3.1 --- a/tools/python/xen/xend/XendDomain.py	Sat Oct 02 14:25:55 2004 +0000
     3.2 +++ b/tools/python/xen/xend/XendDomain.py	Sun Oct 03 14:35:11 2004 +0000
     3.3 @@ -211,9 +211,9 @@ class XendDomain:
     3.4          @param id:     domain id
     3.5          @param notify: send a domain died event if true
     3.6          """
     3.7 -        for info in self.domain_by_name.values():
     3.8 +        for (k, info) in self.domain_by_name.items():
     3.9              if info.id == id:
    3.10 -                del self.domain_by_name[info.name]
    3.11 +                del self.domain_by_name[k]
    3.12          if id in self.domain_by_id:
    3.13              info = self.domain_by_id[id]
    3.14              del self.domain_by_id[id]
    3.15 @@ -408,11 +408,15 @@ class XendDomain:
    3.16          @return: deferred
    3.17          """
    3.18          
    3.19 -        def cbok(dominfo):
    3.20 -            self._add_domain(dominfo)
    3.21 -            return dominfo
    3.22 -        deferred = XendDomainInfo.vm_restore(src, progress=progress)
    3.23 -        deferred.addCallback(cbok)
    3.24 +        if 0:
    3.25 +            def cbok(dominfo):
    3.26 +                self._add_domain(dominfo)
    3.27 +                return dominfo
    3.28 +            deferred = XendDomainInfo.vm_restore(src, progress=progress)
    3.29 +            deferred.addCallback(cbok)
    3.30 +        else:
    3.31 +            xmigrate = XendMigrate.instance()
    3.32 +            deferred = xmigrate.restore_begin(src)
    3.33          return deferred
    3.34      
    3.35      def domain_get(self, id):
     4.1 --- a/tools/python/xen/xend/XendMigrate.py	Sat Oct 02 14:25:55 2004 +0000
     4.2 +++ b/tools/python/xen/xend/XendMigrate.py	Sun Oct 03 14:35:11 2004 +0000
     4.3 @@ -302,6 +302,19 @@ class XendMigrateInfo(XfrdInfo):
     4.4                        self.dst_port,
     4.5                        self.live ])
     4.6          
     4.7 +##     def xfr_vm_suspend(self, xfrd, val):
     4.8 +##         def cbok(val):
     4.9 +##             # Special case for localhost: destroy devices early.
    4.10 +##             if self.dst_host in ["localhost", "127.0.0.1"]:
    4.11 +##                 self.dominfo.restart_cancel()
    4.12 +##                 self.dominfo.cleanup()
    4.13 +##                 self.dominfo.destroy_console()
    4.14 +##             return val
    4.15 +            
    4.16 +##         d = XfrdInfo.xfr_vm_suspend(self, xfrd, val)
    4.17 +##         d.addCallback(cbok)
    4.18 +##         return d
    4.19 +    
    4.20      def xfr_migrate_ok(self, xfrd, val):
    4.21          dom = int(sxp.child0(val))
    4.22          self.state = 'ok'
    4.23 @@ -376,7 +389,35 @@ class XendSaveInfo(XfrdInfo):
    4.24                         [ self.dominfo.name, self.dominfo.id,
    4.25                           self.state, self.sxpr() ])
    4.26      
    4.27 +class XendRestoreInfo(XfrdInfo):
    4.28 +    """Representation of a restore in-progress and its interaction with xfrd.
    4.29 +    """
    4.30  
    4.31 +    def __init__(self, xid, file):
    4.32 +        XfrdInfo.__init__(self)
    4.33 +        self.xid = xid
    4.34 +        self.state = 'begin'
    4.35 +        self.file = file
    4.36 +
    4.37 +    def sxpr(self):
    4.38 +         sxpr = ['restore',
    4.39 +                 ['id', self.xid],
    4.40 +                 ['file', self.file] ]
    4.41 +         return sxpr
    4.42 +
    4.43 +    def request(self, xfrd):
    4.44 +        print '***request>', self.file
    4.45 +        log.info('restore BEGIN: ' + str(self.sxpr()))
    4.46 +        xfrd.request(['xfr.restore', self.file ])
    4.47 +        
    4.48 +    def xfr_restore_ok(self, xfrd, val):
    4.49 +        dom = int(sxp.child0(val))
    4.50 +        dominfo = self.xd.domain_get(dom)
    4.51 +        self.state = 'ok'
    4.52 +        if not self.deferred.called:
    4.53 +            self.deferred.callback(dominfo)
    4.54 +
    4.55 +         
    4.56  class XendMigrate:
    4.57      """External api for interaction with xfrd for migrate and save.
    4.58      Singleton.
    4.59 @@ -472,6 +513,12 @@ class XendMigrate:
    4.60          info = XendSaveInfo(xid, dominfo, file)
    4.61          return self.session_begin(info)
    4.62  
    4.63 +    def restore_begin(self, file):
    4.64 +        xid = self.nextid()
    4.65 +        info = XendRestoreInfo(xid, file)
    4.66 +        return self.session_begin(info)
    4.67 +        
    4.68 +
    4.69  def instance():
    4.70      global inst
    4.71      try:
     5.1 --- a/tools/python/xen/xend/server/SrvDomainDir.py	Sat Oct 02 14:25:55 2004 +0000
     5.2 +++ b/tools/python/xen/xend/server/SrvDomainDir.py	Sun Oct 03 14:35:11 2004 +0000
     5.3 @@ -45,7 +45,7 @@ class SrvDomainDir(SrvDir):
     5.4          errmsg = ''
     5.5          try:
     5.6              configstring = req.args.get('config')[0]
     5.7 -            print 'config:', configstring
     5.8 +            #print 'op_create>', 'config:', configstring
     5.9              pin = sxp.Parser()
    5.10              pin.input(configstring)
    5.11              pin.input_eof()
     6.1 --- a/tools/xfrd/xen_domain.c	Sat Oct 02 14:25:55 2004 +0000
     6.2 +++ b/tools/xfrd/xen_domain.c	Sun Oct 03 14:35:11 2004 +0000
     6.3 @@ -108,7 +108,10 @@ int xen_domain_snd(Conn *xend, IOStream 
     6.4  /** Receive domain state.
     6.5   * Create a new domain and store the received state into it.
     6.6   */
     6.7 -int xen_domain_rcv(IOStream *io, uint32_t *dom, char **vmconfig, int *vmconfig_n){
     6.8 +int xen_domain_rcv(IOStream *io,
     6.9 +                   uint32_t *dom,
    6.10 +                   char **vmconfig, int *vmconfig_n,
    6.11 +                   int *configured){
    6.12      int err = 0;
    6.13  #ifdef _XEN_XFR_STUB_
    6.14      char buf[1024];
    6.15 @@ -135,11 +138,15 @@ int xen_domain_rcv(IOStream *io, uint32_
    6.16      ioctxt->info = iostdout;
    6.17      ioctxt->err = iostderr;
    6.18      ioctxt->configure = domain_configure;
    6.19 +    if(!configured){
    6.20 +        ioctxt->flags |= XCFLAGS_CONFIGURE;
    6.21 +    }
    6.22  
    6.23      err = xc_linux_restore(xcinit(), ioctxt);
    6.24      *dom = ioctxt->domain;
    6.25      *vmconfig = ioctxt->vmconfig;
    6.26      *vmconfig_n = ioctxt->vmconfig_n;
    6.27 +    *configured = (ioctxt->flags & XCFLAGS_CONFIGURE);
    6.28  #endif   
    6.29      dprintf("< err=%d\n", err);
    6.30      return err;
     7.1 --- a/tools/xfrd/xen_domain.h	Sat Oct 02 14:25:55 2004 +0000
     7.2 +++ b/tools/xfrd/xen_domain.h	Sun Oct 03 14:35:11 2004 +0000
     7.3 @@ -11,7 +11,10 @@ extern int xen_domain_snd(Conn *xend, IO
     7.4                            uint32_t dom,
     7.5                            char *vmconfig, int vmconfig_n,
     7.6                            int live);
     7.7 -extern int xen_domain_rcv(IOStream *io, uint32_t *dom, char **vmconfig, int *vmconfig_n);
     7.8 +extern int xen_domain_rcv(IOStream *io,
     7.9 +                          uint32_t *dom,
    7.10 +                          char **vmconfig, int *vmconfig_n,
    7.11 +                          int *configured);
    7.12  
    7.13  
    7.14  extern int xen_domain_configure(uint32_t dom, char *vmconfig, int vmconfig_n);
     8.1 --- a/tools/xfrd/xfrd.c	Sat Oct 02 14:25:55 2004 +0000
     8.2 +++ b/tools/xfrd/xfrd.c	Sun Oct 03 14:35:11 2004 +0000
     8.3 @@ -99,6 +99,8 @@ Sxpr oxfr_hello;     // (xfr.hello <majo
     8.4  Sxpr oxfr_migrate;   // (xfr.migrate <vmid> <vmconfig> <host> <port> <live>)
     8.5  Sxpr oxfr_migrate_ok;// (xfr.migrate.ok <value>)
     8.6  Sxpr oxfr_progress;  // (xfr.progress <percent> <rate: kb/s>)
     8.7 +Sxpr oxfr_restore;   // (xfr.restore <file>)
     8.8 +Sxpr oxfr_restore_ok;// (xfr.restore.ok <vmid>)
     8.9  Sxpr oxfr_save;      // (xfr.save <vmid> <vmconfig> <file>)
    8.10  Sxpr oxfr_save_ok;   // (xfr.save.ok)
    8.11  Sxpr oxfr_vm_destroy;// (xfr.vm.destroy <vmid>)
    8.12 @@ -113,6 +115,8 @@ void xfr_init(void){
    8.13      oxfr_migrate        = intern("xfr.migrate");
    8.14      oxfr_migrate_ok     = intern("xfr.migrate.ok");
    8.15      oxfr_progress       = intern("xfr.progress");
    8.16 +    oxfr_restore        = intern("xfr.restore");
    8.17 +    oxfr_restore_ok     = intern("xfr.restore.ok");
    8.18      oxfr_save           = intern("xfr.save");
    8.19      oxfr_save_ok        = intern("xfr.save.ok");
    8.20      oxfr_vm_destroy     = intern("xfr.vm.destroy");
    8.21 @@ -540,6 +544,14 @@ int xfr_send_migrate_ok(Conn *conn, uint
    8.22      return (err < 0 ? err : 0);
    8.23  }
    8.24  
    8.25 +int xfr_send_restore_ok(Conn *conn, uint32_t vmid){
    8.26 +    int err = 0;
    8.27 +
    8.28 +    err = IOStream_print(conn->out, "(%s %d)",
    8.29 +                         atom_name(oxfr_restore_ok), vmid);
    8.30 +    return (err < 0 ? err : 0);
    8.31 +}
    8.32 +
    8.33  int xfr_send_save_ok(Conn *conn){
    8.34      int err = 0;
    8.35  
    8.36 @@ -777,6 +789,46 @@ int xfr_save(Args *args, XfrState *state
    8.37      return err;
    8.38  }
    8.39  
    8.40 +/** Restore a vm from file.
    8.41 + *
    8.42 + * @return 0 on success, error code otherwise
    8.43 + */
    8.44 +int xfr_restore(Args *args, XfrState *state, Conn *xend, char *file){
    8.45 +    int err = 0;
    8.46 +    IOStream *io = NULL;
    8.47 +    int configured=0;
    8.48 +
    8.49 +    dprintf("> file=%s\n", file);
    8.50 +    io = gzip_stream_fopen(file, "rb");
    8.51 +    if(!io){
    8.52 +        eprintf("> Failed to open %s\n", file);
    8.53 +        err = -EINVAL;
    8.54 +        goto exit;
    8.55 +    }
    8.56 +    err = xen_domain_rcv(io,
    8.57 +                         &state->vmid_new,
    8.58 +                         &state->vmconfig, &state->vmconfig_n,
    8.59 +                         &configured);
    8.60 +    if(err) goto exit;
    8.61 +    if(!configured){
    8.62 +        err = xen_domain_configure(state->vmid_new, state->vmconfig, state->vmconfig_n);
    8.63 +        if(err) goto exit;
    8.64 +    }
    8.65 +    err = xen_domain_unpause(state->vmid_new);
    8.66 +  exit:
    8.67 +    if(io){
    8.68 +        IOStream_close(io);
    8.69 +        IOStream_free(io);
    8.70 +    }
    8.71 +    if(err){
    8.72 +        xfr_error(xend, err);
    8.73 +    } else {
    8.74 +        xfr_send_restore_ok(xend, state->vmid_new);
    8.75 +    }
    8.76 +    dprintf("< err=%d\n", err);
    8.77 +    return err;
    8.78 +}
    8.79 +
    8.80  /** Accept the transfer of a vm from another node.
    8.81   *
    8.82   * @param peer connection
    8.83 @@ -787,17 +839,31 @@ int xfr_recv(Args *args, XfrState *state
    8.84      int err = 0;
    8.85      time_t t0 = time(NULL), t1;
    8.86      Sxpr sxpr;
    8.87 +    int configured=0;
    8.88  
    8.89 -    dprintf(">\n");
    8.90 -    err = xen_domain_rcv(peer->in, &state->vmid_new, &state->vmconfig, &state->vmconfig_n);
    8.91 +    dprintf("> peer=%s\n", inet_ntoa(peer->addr.sin_addr));
    8.92 +    // If receiving from localhost set configured so that that xen_domain_rcv()
    8.93 +    // does not attempt to configure the new domain. This is because the old
    8.94 +    // domain still exists and will make it fail.
    8.95 +    if(peer->addr.sin_addr.s_addr == htonl(INADDR_LOOPBACK)){
    8.96 +        dprintf("> Peer is localhost\n");
    8.97 +        configured = 1;
    8.98 +    }
    8.99 +    err = xen_domain_rcv(peer->in,
   8.100 +                         &state->vmid_new,
   8.101 +                         &state->vmconfig, &state->vmconfig_n,
   8.102 +                         &configured);
   8.103      if(err) goto exit;
   8.104      // Read from the peer. This is just so we wait before configuring.
   8.105      // When migrating to the same host the peer must destroy the domain
   8.106      // before we configure the new one.
   8.107      err = Conn_sxpr(peer, &sxpr);
   8.108      if(err) goto exit;
   8.109 -    err = xen_domain_configure(state->vmid_new, state->vmconfig, state->vmconfig_n);
   8.110 -    if(err) goto exit;
   8.111 +    if(!configured){
   8.112 +        dprintf("> Configuring...\n");
   8.113 +        err = xen_domain_configure(state->vmid_new, state->vmconfig, state->vmconfig_n);
   8.114 +        if(err) goto exit;
   8.115 +    }
   8.116      err = xen_domain_unpause(state->vmid_new);
   8.117      if(err) goto exit;
   8.118      // Report new domain id to peer.
   8.119 @@ -878,6 +944,17 @@ int xfrd_service(Args *args, int peersoc
   8.120          if(err) goto exit;
   8.121          err = xfr_save(args, state, conn, file);
   8.122  
   8.123 +    } else if(sxpr_elementp(sxpr, oxfr_restore)){
   8.124 +        // Restore message from xend.
   8.125 +        char *file;
   8.126 +        XfrState _state = {}, *state = &_state;
   8.127 +        int n = 0;
   8.128 +
   8.129 +        dprintf("> xfr.restore\n");
   8.130 +        err = stringof(sxpr_childN(sxpr, n++, ONONE), &file);
   8.131 +        if(err) goto exit;
   8.132 +        err = xfr_restore(args, state, conn, file);
   8.133 +
   8.134      } else if(sxpr_elementp(sxpr, oxfr_xfr)){
   8.135          // Xfr message from peer xfrd.
   8.136          XfrState _state = {}, *state = &_state;
   8.137 @@ -1144,9 +1221,11 @@ int main(int argc, char *argv[]){
   8.138      int long_index = 0;
   8.139      static const char * LOGFILE = "/var/log/xfrd.log";
   8.140  
   8.141 +#ifndef DEBUG
   8.142      freopen(LOGFILE, "w+", stdout);
   8.143      fclose(stderr);
   8.144      stderr = stdout;
   8.145 +#endif
   8.146      dprintf(">\n");
   8.147      set_defaults(args);
   8.148      while(1){