direct-io.hg

changeset 11485:ef3a08ab559f

Revert 11475:11645dda144c3c8365dd2a6a64cb5a7d7da01170
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Mon Sep 18 14:25:26 2006 +0100 (2006-09-18)
parents dc9fa4dcd19c
children d8bceca5f07d
files tools/libxc/xc_core.c tools/libxc/xenctrl.h
line diff
     1.1 --- a/tools/libxc/xc_core.c	Mon Sep 18 14:15:03 2006 +0100
     1.2 +++ b/tools/libxc/xc_core.c	Mon Sep 18 14:25:26 2006 +0100
     1.3 @@ -6,12 +6,6 @@
     1.4  #define DUMP_INCREMENT (4 * 1024)
     1.5  #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
     1.6  
     1.7 -/* Callback args for writing to a local dump file. */
     1.8 -struct dump_args {
     1.9 -    int     fd;
    1.10 -    int     incomp_fd;
    1.11 -};
    1.12 -
    1.13  static int
    1.14  copy_from_domain_page(int xc_handle,
    1.15                        uint32_t domid,
    1.16 @@ -33,7 +27,7 @@ xc_domain_dumpcore_via_callback(int xc_h
    1.17                                  void *args,
    1.18                                  dumpcore_rtn_t dump_rtn)
    1.19  {
    1.20 -    unsigned long n, nr_pages;
    1.21 +    unsigned long nr_pages;
    1.22      xen_pfn_t *page_array = NULL;
    1.23      xc_dominfo_t info;
    1.24      int i, nr_vcpus = 0;
    1.25 @@ -43,12 +37,6 @@ xc_domain_dumpcore_via_callback(int xc_h
    1.26      char dummy[PAGE_SIZE];
    1.27      int dummy_len;
    1.28      int sts;
    1.29 -    unsigned int cpy_err_cnt = 0;
    1.30 -    struct dump_args *da = args;
    1.31 -    int fd = da->fd;
    1.32 -    int incomp_fd = da->incomp_fd;
    1.33 -    char cpy_err_mesg[64];
    1.34 -    int mesg_bytes;
    1.35  
    1.36      if ( (dump_mem_start = malloc(DUMP_INCREMENT*PAGE_SIZE)) == NULL )
    1.37      {
    1.38 @@ -85,11 +73,11 @@ xc_domain_dumpcore_via_callback(int xc_h
    1.39                   (nr_pages * sizeof(xen_pfn_t)));
    1.40      header.xch_pages_offset = round_pgup(dummy_len);
    1.41  
    1.42 -    sts = dump_rtn(fd, (char *)&header, sizeof(struct xc_core_header));
    1.43 +    sts = dump_rtn(args, (char *)&header, sizeof(struct xc_core_header));
    1.44      if ( sts != 0 )
    1.45          goto error_out;
    1.46  
    1.47 -    sts = dump_rtn(fd, (char *)&ctxt, sizeof(ctxt[0]) * nr_vcpus);
    1.48 +    sts = dump_rtn(args, (char *)&ctxt, sizeof(ctxt[0]) * nr_vcpus);
    1.49      if ( sts != 0 )
    1.50          goto error_out;
    1.51  
    1.52 @@ -103,40 +91,28 @@ xc_domain_dumpcore_via_callback(int xc_h
    1.53          IPRINTF("Could not get the page frame list\n");
    1.54          goto error_out;
    1.55      }
    1.56 -    sts = dump_rtn(fd, (char *)page_array, nr_pages * sizeof(xen_pfn_t));
    1.57 +    sts = dump_rtn(args, (char *)page_array, nr_pages * sizeof(xen_pfn_t));
    1.58      if ( sts != 0 )
    1.59          goto error_out;
    1.60  
    1.61      /* Pad the output data to page alignment. */
    1.62      memset(dummy, 0, PAGE_SIZE);
    1.63 -    sts = dump_rtn(fd, dummy, header.xch_pages_offset - dummy_len);
    1.64 +    sts = dump_rtn(args, dummy, header.xch_pages_offset - dummy_len);
    1.65      if ( sts != 0 )
    1.66          goto error_out;
    1.67  
    1.68 -    for ( dump_mem = dump_mem_start, n = 0; n < nr_pages; n++ )
    1.69 +    for ( dump_mem = dump_mem_start, i = 0; i < nr_pages; i++ )
    1.70      {
    1.71 -        sts = copy_from_domain_page(xc_handle, domid, page_array[i], dump_mem);
    1.72 -        if( sts != 0 ){
    1.73 -            memset(dump_mem, 0, PAGE_SIZE);
    1.74 -            cpy_err_cnt++;
    1.75 -            memset(cpy_err_mesg, 0, sizeof(cpy_err_mesg));
    1.76 -            mesg_bytes = sprintf(cpy_err_mesg, "Cannot copy_from_domain_page (%lu)\n", n);
    1.77 -            dump_rtn(incomp_fd, (char *)cpy_err_mesg, mesg_bytes);
    1.78 -        }
    1.79 -
    1.80 +        copy_from_domain_page(xc_handle, domid, page_array[i], dump_mem);
    1.81          dump_mem += PAGE_SIZE;
    1.82 -        if ( ((n + 1) % DUMP_INCREMENT == 0) || ((n + 1) == nr_pages) )
    1.83 +        if ( ((i + 1) % DUMP_INCREMENT == 0) || ((i + 1) == nr_pages) )
    1.84          {
    1.85 -            sts = dump_rtn(fd, dump_mem_start, dump_mem - dump_mem_start);
    1.86 +            sts = dump_rtn(args, dump_mem_start, dump_mem - dump_mem_start);
    1.87              if ( sts != 0 )
    1.88                  goto error_out;
    1.89              dump_mem = dump_mem_start;
    1.90          }
    1.91      }
    1.92 -    if( cpy_err_cnt != 0 ){
    1.93 -        IPRINTF("Could not copy from domid=%d (%d)pages\n", domid, cpy_err_cnt);
    1.94 -        goto error_out;
    1.95 -    }
    1.96  
    1.97      free(dump_mem_start);
    1.98      free(page_array);
    1.99 @@ -148,14 +124,20 @@ xc_domain_dumpcore_via_callback(int xc_h
   1.100      return -1;
   1.101  }
   1.102  
   1.103 +/* Callback args for writing to a local dump file. */
   1.104 +struct dump_args {
   1.105 +    int     fd;
   1.106 +};
   1.107 +
   1.108  /* Callback routine for writing to a local dump file. */
   1.109 -static int local_file_dump(int fd, char *buffer, unsigned int length)
   1.110 +static int local_file_dump(void *args, char *buffer, unsigned int length)
   1.111  {
   1.112 +    struct dump_args *da = args;
   1.113      int bytes, offset;
   1.114  
   1.115      for ( offset = 0; offset < length; offset += bytes )
   1.116      {
   1.117 -        bytes = write(fd, &buffer[offset], length-offset);
   1.118 +        bytes = write(da->fd, &buffer[offset], length-offset);
   1.119          if ( bytes <= 0 )
   1.120          {
   1.121              PERROR("Failed to write buffer: %s", strerror(errno));
   1.122 @@ -172,7 +154,6 @@ xc_domain_dumpcore(int xc_handle,
   1.123                     const char *corename)
   1.124  {
   1.125      struct dump_args da;
   1.126 -    char *incomp_file;
   1.127      int sts;
   1.128  
   1.129      if ( (da.fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0 )
   1.130 @@ -181,28 +162,10 @@ xc_domain_dumpcore(int xc_handle,
   1.131          return -errno;
   1.132      }
   1.133  
   1.134 -    
   1.135 -    if ( (incomp_file = (char *)malloc(sizeof(corename) + 12)) == NULL )
   1.136 -    {
   1.137 -        PERROR("Could not allocate incomp_file");
   1.138 -        return -errno;
   1.139 -    }
   1.140 -
   1.141 -    sprintf(incomp_file, "%s-incomp.list", corename);
   1.142 -    if ( (da.incomp_fd = open(incomp_file, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0 )
   1.143 -    {
   1.144 -        PERROR("Could not open corefile %s: %s", incomp_file, strerror(errno));
   1.145 -        return -errno;
   1.146 -    }
   1.147 -
   1.148      sts = xc_domain_dumpcore_via_callback(
   1.149          xc_handle, domid, &da, &local_file_dump);
   1.150  
   1.151      close(da.fd);
   1.152 -    close(da.incomp_fd);
   1.153 -
   1.154 -    if( sts == 0)
   1.155 -        unlink(incomp_file);
   1.156  
   1.157      return sts;
   1.158  }
     2.1 --- a/tools/libxc/xenctrl.h	Mon Sep 18 14:15:03 2006 +0100
     2.2 +++ b/tools/libxc/xenctrl.h	Mon Sep 18 14:25:26 2006 +0100
     2.3 @@ -166,7 +166,7 @@ int xc_domain_dumpcore(int xc_handle,
     2.4   * and passes an opaque object for the use of the function and
     2.5   * created by the caller of xc_domain_dumpcore_via_callback.
     2.6   */
     2.7 -typedef int (dumpcore_rtn_t)(int fd, char *buffer, unsigned int length);
     2.8 +typedef int (dumpcore_rtn_t)(void *arg, char *buffer, unsigned int length);
     2.9  
    2.10  int xc_domain_dumpcore_via_callback(int xc_handle,
    2.11                                      uint32_t domid,