ia64/xen-unstable

changeset 11479:11645dda144c

In this patch, the xc_domain_dumpcore_via_callback() in xc_core.c of
libxc is modified. Previously, the xc_domain_dumpcore_via_callback()
did not respond to error when copy_from_domain_page() failed.
In other words, the dump core remained silent even if mapping the domain
memory failed and its page could not be copied. When this happened,
erroneous data had been dumped to the file without the user realizing it.
Now, it has been modified so that if copy_from_domain_page fails,
this fact is recorded in the logfile and make imcoplerte-list.
However even in such cases, the dumping will continue as before.

Signed-off-by: Ken Hironaka <hironaka.ken@soft.fujitsu.com>
Signed-off-by: Akio Takebe <takebe_akio@jp.fujitsu.com>
author root@procyon
date Thu Sep 14 08:19:41 2006 +0100 (2006-09-14)
parents 30c659b655f1
children 65b33e64b642
files tools/libxc/xc_core.c tools/libxc/xenctrl.h
line diff
     1.1 --- a/tools/libxc/xc_core.c	Thu Sep 14 08:19:39 2006 +0100
     1.2 +++ b/tools/libxc/xc_core.c	Thu Sep 14 08:19:41 2006 +0100
     1.3 @@ -6,6 +6,12 @@
     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 @@ -27,7 +33,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 nr_pages;
    1.21 +    unsigned long n, 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 @@ -37,6 +43,12 @@ 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 @@ -73,11 +85,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(args, (char *)&header, sizeof(struct xc_core_header));
    1.43 +    sts = dump_rtn(fd, (char *)&header, sizeof(struct xc_core_header));
    1.44      if ( sts != 0 )
    1.45          goto error_out;
    1.46  
    1.47 -    sts = dump_rtn(args, (char *)&ctxt, sizeof(ctxt[0]) * nr_vcpus);
    1.48 +    sts = dump_rtn(fd, (char *)&ctxt, sizeof(ctxt[0]) * nr_vcpus);
    1.49      if ( sts != 0 )
    1.50          goto error_out;
    1.51  
    1.52 @@ -91,28 +103,40 @@ 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(args, (char *)page_array, nr_pages * sizeof(xen_pfn_t));
    1.57 +    sts = dump_rtn(fd, (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(args, dummy, header.xch_pages_offset - dummy_len);
    1.64 +    sts = dump_rtn(fd, 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, i = 0; i < nr_pages; i++ )
    1.69 +    for ( dump_mem = dump_mem_start, n = 0; n < nr_pages; n++ )
    1.70      {
    1.71 -        copy_from_domain_page(xc_handle, domid, page_array[i], dump_mem);
    1.72 +        sts = copy_from_domain_page(xc_handle, domid, page_array[i], dump_mem);
    1.73 +        if( sts != 0 ){
    1.74 +            memset(dump_mem, 0, PAGE_SIZE);
    1.75 +            cpy_err_cnt++;
    1.76 +            memset(cpy_err_mesg, 0, sizeof(cpy_err_mesg));
    1.77 +            mesg_bytes = sprintf(cpy_err_mesg, "Cannot copy_from_domain_page (%lu)\n", n);
    1.78 +            dump_rtn(incomp_fd, (char *)cpy_err_mesg, mesg_bytes);
    1.79 +        }
    1.80 +
    1.81          dump_mem += PAGE_SIZE;
    1.82 -        if ( ((i + 1) % DUMP_INCREMENT == 0) || ((i + 1) == nr_pages) )
    1.83 +        if ( ((n + 1) % DUMP_INCREMENT == 0) || ((n + 1) == nr_pages) )
    1.84          {
    1.85 -            sts = dump_rtn(args, dump_mem_start, dump_mem - dump_mem_start);
    1.86 +            sts = dump_rtn(fd, 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 @@ -124,20 +148,14 @@ 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(void *args, char *buffer, unsigned int length)
   1.110 +static int local_file_dump(int fd, 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(da->fd, &buffer[offset], length-offset);
   1.118 +        bytes = write(fd, &buffer[offset], length-offset);
   1.119          if ( bytes <= 0 )
   1.120          {
   1.121              PERROR("Failed to write buffer: %s", strerror(errno));
   1.122 @@ -154,6 +172,7 @@ 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 @@ -162,10 +181,28 @@ 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	Thu Sep 14 08:19:39 2006 +0100
     2.2 +++ b/tools/libxc/xenctrl.h	Thu Sep 14 08:19:41 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)(void *arg, char *buffer, unsigned int length);
     2.8 +typedef int (dumpcore_rtn_t)(int fd, char *buffer, unsigned int length);
     2.9  
    2.10  int xc_domain_dumpcore_via_callback(int xc_handle,
    2.11                                      uint32_t domid,