ia64/xen-unstable

changeset 5154:6e81b0f58356

bitkeeper revision 1.1550.1.3 (4294b356XJn1FHEVZ-2JlKpBDmqmpA)

xc_linux_restore.c:
Make read from network work.
Make error messages more specific.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Wed May 25 17:18:14 2005 +0000 (2005-05-25)
parents be7e052ce7e8
children 10992a804a2a
files tools/libxc/xc_linux_restore.c
line diff
     1.1 --- a/tools/libxc/xc_linux_restore.c	Wed May 25 16:04:01 2005 +0000
     1.2 +++ b/tools/libxc/xc_linux_restore.c	Wed May 25 17:18:14 2005 +0000
     1.3 @@ -32,6 +32,22 @@
     1.4  #define PPRINTF(_f, _a...)
     1.5  #endif
     1.6  
     1.7 +ssize_t
     1.8 +read_exact(int fd, void *buf, size_t count)
     1.9 +{
    1.10 +    int r = 0, s;
    1.11 +    unsigned char *b = buf;
    1.12 +
    1.13 +    while (r < count) {
    1.14 +	s = read(fd, &b[r], count - r);
    1.15 +	if (s <= 0)
    1.16 +	    break;
    1.17 +	r += s;
    1.18 +    }
    1.19 +
    1.20 +    return r;
    1.21 +}
    1.22 +
    1.23  int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns)
    1.24  {
    1.25      dom0_op_t op;
    1.26 @@ -90,7 +106,7 @@ int xc_linux_restore(int xc_handle, int 
    1.27          return 1;
    1.28      }
    1.29  
    1.30 -    if (read(io_fd, pfn_to_mfn_frame_list, PAGE_SIZE) != PAGE_SIZE) {
    1.31 +    if (read_exact(io_fd, pfn_to_mfn_frame_list, PAGE_SIZE) != PAGE_SIZE) {
    1.32  	ERR("read pfn_to_mfn_frame_list failed");
    1.33  	goto out;
    1.34      }
    1.35 @@ -168,9 +184,9 @@ int xc_linux_restore(int xc_handle, int 
    1.36              prev_pc = this_pc;
    1.37          }
    1.38  
    1.39 -        if ( read(io_fd, &j, sizeof(int)) != sizeof(int) )
    1.40 +        if ( read_exact(io_fd, &j, sizeof(int)) != sizeof(int) )
    1.41          {
    1.42 -            ERR("Error when reading from state file");
    1.43 +            ERR("Error when reading batch size");
    1.44              goto out;
    1.45          }
    1.46  
    1.47 @@ -192,9 +208,9 @@ int xc_linux_restore(int xc_handle, int 
    1.48              goto out;
    1.49          }
    1.50   
    1.51 -        if ( read(io_fd, region_pfn_type, j*sizeof(unsigned long)) !=
    1.52 +        if ( read_exact(io_fd, region_pfn_type, j*sizeof(unsigned long)) !=
    1.53               j*sizeof(unsigned long) ) {
    1.54 -            ERR("Error when reading from state file");
    1.55 +            ERR("Error when reading region pfn types");
    1.56              goto out;
    1.57          }
    1.58  
    1.59 @@ -245,9 +261,9 @@ int xc_linux_restore(int xc_handle, int 
    1.60              else
    1.61                  ppage = (unsigned long*) (region_base + i*PAGE_SIZE);
    1.62  
    1.63 -            if ( read(io_fd, ppage, PAGE_SIZE) != PAGE_SIZE )
    1.64 +            if ( read_exact(io_fd, ppage, PAGE_SIZE) != PAGE_SIZE )
    1.65              {
    1.66 -                ERR("Error when reading from state file");
    1.67 +                ERR("Error when reading pagetable page");
    1.68                  goto out;
    1.69              }
    1.70  
    1.71 @@ -389,9 +405,9 @@ int xc_linux_restore(int xc_handle, int 
    1.72  	unsigned int count, *pfntab;
    1.73  	int rc;
    1.74  
    1.75 -	if ( read(io_fd, &count, sizeof(count)) != sizeof(count) )
    1.76 +	if ( read_exact(io_fd, &count, sizeof(count)) != sizeof(count) )
    1.77  	{
    1.78 -	    ERR("Error when reading from state file");
    1.79 +	    ERR("Error when reading pfn count");
    1.80  	    goto out;
    1.81  	}
    1.82  
    1.83 @@ -402,10 +418,10 @@ int xc_linux_restore(int xc_handle, int 
    1.84  	    goto out;
    1.85  	}
    1.86  
    1.87 -	if ( read(io_fd, pfntab, sizeof(unsigned int)*count) !=
    1.88 +	if ( read_exact(io_fd, pfntab, sizeof(unsigned int)*count) !=
    1.89               sizeof(unsigned int)*count )
    1.90  	{
    1.91 -	    ERR("Error when reading pfntab from state file");
    1.92 +	    ERR("Error when reading pfntab");
    1.93  	    goto out;
    1.94  	}
    1.95  
    1.96 @@ -432,10 +448,10 @@ int xc_linux_restore(int xc_handle, int 
    1.97  	}	
    1.98      }
    1.99  
   1.100 -    if ( read(io_fd, &ctxt,            sizeof(ctxt)) != sizeof(ctxt) ||
   1.101 -         read(io_fd, shared_info_page, PAGE_SIZE) != PAGE_SIZE )
   1.102 +    if ( read_exact(io_fd, &ctxt,            sizeof(ctxt)) != sizeof(ctxt) ||
   1.103 +         read_exact(io_fd, shared_info_page, PAGE_SIZE) != PAGE_SIZE )
   1.104      {
   1.105 -        ERR("Error when reading from state file");
   1.106 +        ERR("Error when reading ctxt or shared info page");
   1.107          goto out;
   1.108      }
   1.109