direct-io.hg

view tools/libxc/xc_core.c @ 8500:dd5649730b32

Fix a couple of bogus dom0_op names:
setdomaininfo -> setvcpucontext
pincpudomain -> setvcpuaffinity

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Jan 06 12:53:19 2006 +0100 (2006-01-06)
parents fa0faada967b
children 316fafc6d743
line source
1 #include "xg_private.h"
2 #define ELFSIZE 32
3 #include "xc_elf.h"
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <zlib.h>
8 /* number of pages to write at a time */
9 #define DUMP_INCREMENT 4 * 1024
10 #define round_pgup(_p) (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
12 static int
13 copy_from_domain_page(int xc_handle,
14 uint32_t domid,
15 unsigned long *page_array,
16 unsigned long src_pfn,
17 void *dst_page)
18 {
19 void *vaddr = xc_map_foreign_range(
20 xc_handle, domid, PAGE_SIZE, PROT_READ, page_array[src_pfn]);
21 if ( vaddr == NULL )
22 return -1;
23 memcpy(dst_page, vaddr, PAGE_SIZE);
24 munmap(vaddr, PAGE_SIZE);
25 return 0;
26 }
28 int
29 xc_domain_dumpcore(int xc_handle,
30 uint32_t domid,
31 const char *corename)
32 {
33 unsigned long nr_pages;
34 unsigned long *page_array;
35 xc_dominfo_t info;
36 int i, nr_vcpus = 0, dump_fd;
37 char *dump_mem, *dump_mem_start = NULL;
38 struct xc_core_header header;
39 vcpu_guest_context_t ctxt[MAX_VIRT_CPUS];
42 if ((dump_fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0) {
43 PERROR("Could not open corefile %s: %s", corename, strerror(errno));
44 goto error_out;
45 }
47 if ((dump_mem_start = malloc(DUMP_INCREMENT*PAGE_SIZE)) == NULL) {
48 PERROR("Could not allocate dump_mem");
49 goto error_out;
50 }
52 if (xc_domain_getinfo(xc_handle, domid, 1, &info) != 1) {
53 PERROR("Could not get info for domain");
54 goto error_out;
55 }
57 for (i = 0; i < info.max_vcpu_id; i++)
58 if (xc_vcpu_getcontext(xc_handle, domid,
59 i, &ctxt[nr_vcpus]) == 0)
60 nr_vcpus++;
62 nr_pages = info.nr_pages;
64 header.xch_magic = 0xF00FEBED;
65 header.xch_nr_vcpus = nr_vcpus;
66 header.xch_nr_pages = nr_pages;
67 header.xch_ctxt_offset = sizeof(struct xc_core_header);
68 header.xch_index_offset = sizeof(struct xc_core_header) +
69 sizeof(vcpu_guest_context_t)*nr_vcpus;
70 header.xch_pages_offset = round_pgup(sizeof(struct xc_core_header) +
71 (sizeof(vcpu_guest_context_t) * nr_vcpus) +
72 (nr_pages * sizeof(unsigned long)));
74 write(dump_fd, &header, sizeof(struct xc_core_header));
75 write(dump_fd, &ctxt, sizeof(ctxt[0]) * nr_vcpus);
77 if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
78 printf("Could not allocate memory\n");
79 goto error_out;
80 }
81 if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) {
82 printf("Could not get the page frame list\n");
83 goto error_out;
84 }
85 write(dump_fd, page_array, nr_pages * sizeof(unsigned long));
86 lseek(dump_fd, header.xch_pages_offset, SEEK_SET);
87 for (dump_mem = dump_mem_start, i = 0; i < nr_pages; i++) {
88 copy_from_domain_page(xc_handle, domid, page_array, i, dump_mem);
89 dump_mem += PAGE_SIZE;
90 if (((i + 1) % DUMP_INCREMENT == 0) || (i + 1) == nr_pages) {
91 if (write(dump_fd, dump_mem_start, dump_mem - dump_mem_start) <
92 dump_mem - dump_mem_start) {
93 PERROR("Partial write, file system full?");
94 goto error_out;
95 }
96 dump_mem = dump_mem_start;
97 }
98 }
100 close(dump_fd);
101 free(dump_mem_start);
102 return 0;
103 error_out:
104 if (dump_fd != -1)
105 close(dump_fd);
106 free(dump_mem_start);
107 return -1;
108 }
110 /*
111 * Local variables:
112 * mode: C
113 * c-set-style: "BSD"
114 * c-basic-offset: 4
115 * tab-width: 4
116 * indent-tabs-mode: nil
117 * End:
118 */