ia64/xen-unstable
changeset 3436:6096356005ba
bitkeeper revision 1.1159.217.15 (41e67551cqukZiNFG0h_Hnw0bfuneA)
Merge maf46@ssh-relay1.cl.cam.ac.uk:/usr/groups/xeno/BK/xen-unstable.bk
into fleming.research:/scratch/fleming/mafetter/xen.work.combined
Merge maf46@ssh-relay1.cl.cam.ac.uk:/usr/groups/xeno/BK/xen-unstable.bk
into fleming.research:/scratch/fleming/mafetter/xen.work.combined
author | mafetter@fleming.research |
---|---|
date | Thu Jan 13 13:19:13 2005 +0000 (2005-01-13) |
parents | c5f713b422d1 0fd048d86eed |
children | 0002ff9aa407 |
files | tools/libxc/Makefile tools/libxc/xc.h tools/libxc/xc_domain.c tools/libxc/xc_linux_build.c tools/libxc/xc_linux_restore.c tools/libxc/xc_linux_save.c tools/libxc/xc_plan9_build.c tools/libxc/xc_private.c tools/libxc/xc_private.h tools/libxc/xc_vmx_build.c xen/common/dom0_ops.c |
line diff
1.1 --- a/tools/libxc/Makefile Thu Jan 13 11:57:02 2005 +0000 1.2 +++ b/tools/libxc/Makefile Thu Jan 13 13:19:13 2005 +0000 1.3 @@ -71,7 +71,7 @@ install: all 1.4 install -m0644 xc.h $(prefix)/usr/include 1.5 1.6 clean: 1.7 - rm -rf *.a *.so *.o *.rpm $(LIB) *~ $(DEPS) xen 1.8 + rm -rf *.a *.so *.o *.rpm $(LIB) *~ $(DEPS) xen TAGS 1.9 1.10 rpm: all 1.11 rm -rf staging 1.12 @@ -89,4 +89,8 @@ libxc.so.$(MAJOR): 1.13 libxc.so.$(MAJOR).$(MINOR): $(OBJS) 1.14 $(CC) -Wl,-soname -Wl,$(SONAME) -shared -o $@ $^ -L../libxutil -lxutil -lz 1.15 1.16 +.PHONY: TAGS clean install mk-symlinks rpm 1.17 +TAGS: 1.18 + etags -t $(SRCS) *.h 1.19 + 1.20 -include $(DEPS)
2.1 --- a/tools/libxc/xc.h Thu Jan 13 11:57:02 2005 +0000 2.2 +++ b/tools/libxc/xc.h Thu Jan 13 13:19:13 2005 +0000 2.3 @@ -62,13 +62,15 @@ int xc_domain_getinfo(int xc_handle, 2.4 xc_dominfo_t *info); 2.5 int xc_domain_getfullinfo(int xc_handle, 2.6 u32 domid, 2.7 + u32 vcpu, 2.8 xc_domaininfo_t *info, 2.9 full_execution_context_t *ctxt); 2.10 int xc_domain_setcpuweight(int xc_handle, 2.11 u32 domid, 2.12 float weight); 2.13 long long xc_domain_get_cpu_usage(int xc_handle, 2.14 - domid_t domid); 2.15 + domid_t domid, 2.16 + int vcpu); 2.17 2.18 2.19 typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
3.1 --- a/tools/libxc/xc_domain.c Thu Jan 13 11:57:02 2005 +0000 3.2 +++ b/tools/libxc/xc_domain.c Thu Jan 13 13:19:13 2005 +0000 3.3 @@ -88,6 +88,7 @@ int xc_domain_getinfo(int xc_handle, 3.4 { 3.5 op.cmd = DOM0_GETDOMAININFO; 3.6 op.u.getdomaininfo.domain = (domid_t)next_domid; 3.7 + op.u.getdomaininfo.exec_domain = 0; // FIX ME?!? 3.8 op.u.getdomaininfo.ctxt = NULL; /* no exec context info, thanks. */ 3.9 if ( do_dom0_op(xc_handle, &op) < 0 ) 3.10 break; 3.11 @@ -121,6 +122,7 @@ int xc_domain_getinfo(int xc_handle, 3.12 3.13 int xc_domain_getfullinfo(int xc_handle, 3.14 u32 domid, 3.15 + u32 vcpu, 3.16 xc_domaininfo_t *info, 3.17 full_execution_context_t *ctxt) 3.18 { 3.19 @@ -129,6 +131,7 @@ int xc_domain_getfullinfo(int xc_handle, 3.20 3.21 op.cmd = DOM0_GETDOMAININFO; 3.22 op.u.getdomaininfo.domain = (domid_t)domid; 3.23 + op.u.getdomaininfo.exec_domain = (u16)vcpu; 3.24 op.u.getdomaininfo.ctxt = ctxt; 3.25 3.26 rc = do_dom0_op(xc_handle, &op);
4.1 --- a/tools/libxc/xc_linux_build.c Thu Jan 13 11:57:02 2005 +0000 4.2 +++ b/tools/libxc/xc_linux_build.c Thu Jan 13 13:19:13 2005 +0000 4.3 @@ -41,52 +41,6 @@ loadelfsymtab( 4.4 char *elfbase, int xch, u32 dom, unsigned long *parray, 4.5 struct domain_setup_info *dsi); 4.6 4.7 -static long get_tot_pages(int xc_handle, u32 domid) 4.8 -{ 4.9 - dom0_op_t op; 4.10 - op.cmd = DOM0_GETDOMAININFO; 4.11 - op.u.getdomaininfo.domain = (domid_t)domid; 4.12 - op.u.getdomaininfo.ctxt = NULL; 4.13 - return (do_dom0_op(xc_handle, &op) < 0) ? 4.14 - -1 : op.u.getdomaininfo.tot_pages; 4.15 -} 4.16 - 4.17 -static int get_pfn_list(int xc_handle, 4.18 - u32 domid, 4.19 - unsigned long *pfn_buf, 4.20 - unsigned long max_pfns) 4.21 -{ 4.22 - dom0_op_t op; 4.23 - int ret; 4.24 - op.cmd = DOM0_GETMEMLIST; 4.25 - op.u.getmemlist.domain = (domid_t)domid; 4.26 - op.u.getmemlist.max_pfns = max_pfns; 4.27 - op.u.getmemlist.buffer = pfn_buf; 4.28 - 4.29 - if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 ) 4.30 - return -1; 4.31 - 4.32 - ret = do_dom0_op(xc_handle, &op); 4.33 - 4.34 - (void)munlock(pfn_buf, max_pfns * sizeof(unsigned long)); 4.35 - 4.36 - return (ret < 0) ? -1 : op.u.getmemlist.num_pfns; 4.37 -} 4.38 - 4.39 -static int copy_to_domain_page(int xc_handle, 4.40 - u32 domid, 4.41 - unsigned long dst_pfn, 4.42 - void *src_page) 4.43 -{ 4.44 - void *vaddr = xc_map_foreign_range( 4.45 - xc_handle, domid, PAGE_SIZE, PROT_WRITE, dst_pfn); 4.46 - if ( vaddr == NULL ) 4.47 - return -1; 4.48 - memcpy(vaddr, src_page, PAGE_SIZE); 4.49 - munmap(vaddr, PAGE_SIZE); 4.50 - return 0; 4.51 -} 4.52 - 4.53 static int setup_guestos(int xc_handle, 4.54 u32 dom, 4.55 char *image, unsigned long image_size, 4.56 @@ -206,7 +160,7 @@ static int setup_guestos(int xc_handle, 4.57 goto error_out; 4.58 } 4.59 4.60 - if ( get_pfn_list(xc_handle, dom, page_array, nr_pages) != nr_pages ) 4.61 + if ( xc_get_pfn_list(xc_handle, dom, page_array, nr_pages) != nr_pages ) 4.62 { 4.63 PERROR("Could not get the page frame list"); 4.64 goto error_out; 4.65 @@ -229,7 +183,7 @@ static int setup_guestos(int xc_handle, 4.66 PERROR("Error reading initrd image, could not"); 4.67 goto error_out; 4.68 } 4.69 - copy_to_domain_page(xc_handle, dom, 4.70 + xc_copy_to_domain_page(xc_handle, dom, 4.71 page_array[i>>PAGE_SHIFT], page); 4.72 } 4.73 } 4.74 @@ -364,69 +318,6 @@ static int setup_guestos(int xc_handle, 4.75 return -1; 4.76 } 4.77 4.78 -static unsigned long get_filesz(int fd) 4.79 -{ 4.80 - u16 sig; 4.81 - u32 _sz = 0; 4.82 - unsigned long sz; 4.83 - 4.84 - lseek(fd, 0, SEEK_SET); 4.85 - read(fd, &sig, sizeof(sig)); 4.86 - sz = lseek(fd, 0, SEEK_END); 4.87 - if ( sig == 0x8b1f ) /* GZIP signature? */ 4.88 - { 4.89 - lseek(fd, -4, SEEK_END); 4.90 - read(fd, &_sz, 4); 4.91 - sz = _sz; 4.92 - } 4.93 - lseek(fd, 0, SEEK_SET); 4.94 - 4.95 - return sz; 4.96 -} 4.97 - 4.98 -static char *read_kernel_image(const char *filename, unsigned long *size) 4.99 -{ 4.100 - int kernel_fd = -1; 4.101 - gzFile kernel_gfd = NULL; 4.102 - char *image = NULL; 4.103 - unsigned int bytes; 4.104 - 4.105 - if ( (kernel_fd = open(filename, O_RDONLY)) < 0 ) 4.106 - { 4.107 - PERROR("Could not open kernel image"); 4.108 - goto out; 4.109 - } 4.110 - 4.111 - *size = get_filesz(kernel_fd); 4.112 - 4.113 - if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL ) 4.114 - { 4.115 - PERROR("Could not allocate decompression state for state file"); 4.116 - goto out; 4.117 - } 4.118 - 4.119 - if ( (image = malloc(*size)) == NULL ) 4.120 - { 4.121 - PERROR("Could not allocate memory for kernel image"); 4.122 - goto out; 4.123 - } 4.124 - 4.125 - if ( (bytes = gzread(kernel_gfd, image, *size)) != *size ) 4.126 - { 4.127 - PERROR("Error reading kernel image, could not" 4.128 - " read the whole image (%d != %ld).", bytes, *size); 4.129 - free(image); 4.130 - image = NULL; 4.131 - } 4.132 - 4.133 - out: 4.134 - if ( kernel_gfd != NULL ) 4.135 - gzclose(kernel_gfd); 4.136 - else if ( kernel_fd >= 0 ) 4.137 - close(kernel_fd); 4.138 - return image; 4.139 -} 4.140 - 4.141 int xc_linux_build(int xc_handle, 4.142 u32 domid, 4.143 const char *image_name, 4.144 @@ -445,13 +336,13 @@ int xc_linux_build(int xc_handle, 4.145 unsigned long image_size, initrd_size=0; 4.146 unsigned long vstartinfo_start, vkern_entry; 4.147 4.148 - if ( (nr_pages = get_tot_pages(xc_handle, domid)) < 0 ) 4.149 + if ( (nr_pages = xc_get_tot_pages(xc_handle, domid)) < 0 ) 4.150 { 4.151 PERROR("Could not find total pages for domain"); 4.152 goto error_out; 4.153 } 4.154 4.155 - if ( (image = read_kernel_image(image_name, &image_size)) == NULL ) 4.156 + if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL ) 4.157 goto error_out; 4.158 4.159 if ( (ramdisk_name != NULL) && (strlen(ramdisk_name) != 0) ) 4.160 @@ -462,7 +353,7 @@ int xc_linux_build(int xc_handle, 4.161 goto error_out; 4.162 } 4.163 4.164 - initrd_size = get_filesz(initrd_fd); 4.165 + initrd_size = xc_get_filesz(initrd_fd); 4.166 4.167 if ( (initrd_gfd = gzdopen(initrd_fd, "rb")) == NULL ) 4.168 { 4.169 @@ -479,6 +370,7 @@ int xc_linux_build(int xc_handle, 4.170 4.171 op.cmd = DOM0_GETDOMAININFO; 4.172 op.u.getdomaininfo.domain = (domid_t)domid; 4.173 + op.u.getdomaininfo.exec_domain = 0; 4.174 op.u.getdomaininfo.ctxt = ctxt; 4.175 if ( (do_dom0_op(xc_handle, &op) < 0) || 4.176 ((u16)op.u.getdomaininfo.domain != domid) ) 4.177 @@ -747,27 +639,6 @@ loadelfimage( 4.178 return 0; 4.179 } 4.180 4.181 -static void 4.182 -map_memcpy( 4.183 - unsigned long dst, char *src, unsigned long size, 4.184 - int xch, u32 dom, unsigned long *parray, unsigned long vstart) 4.185 -{ 4.186 - char *va; 4.187 - unsigned long chunksz, done, pa; 4.188 - 4.189 - for ( done = 0; done < size; done += chunksz ) 4.190 - { 4.191 - pa = dst + done - vstart; 4.192 - va = xc_map_foreign_range( 4.193 - xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]); 4.194 - chunksz = size - done; 4.195 - if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) ) 4.196 - chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1)); 4.197 - memcpy(va + (pa & (PAGE_SIZE-1)), src + done, chunksz); 4.198 - munmap(va, PAGE_SIZE); 4.199 - } 4.200 -} 4.201 - 4.202 #define ELFROUND (ELFSIZE / 8) 4.203 4.204 static int 4.205 @@ -818,7 +689,7 @@ loadelfsymtab( 4.206 (shdr[h].sh_type == SHT_SYMTAB) ) 4.207 { 4.208 if ( parray != NULL ) 4.209 - map_memcpy(maxva, elfbase + shdr[h].sh_offset, shdr[h].sh_size, 4.210 + xc_map_memcpy(maxva, elfbase + shdr[h].sh_offset, shdr[h].sh_size, 4.211 xch, dom, parray, dsi->v_start); 4.212 4.213 /* Mangled to be based on ELF header location. */ 4.214 @@ -850,7 +721,7 @@ loadelfsymtab( 4.215 sym_ehdr->e_shstrndx = SHN_UNDEF; 4.216 4.217 /* Copy total length, crafted ELF header and section header table */ 4.218 - map_memcpy(symva, p, sizeof(int) + sizeof(Elf_Ehdr) + 4.219 + xc_map_memcpy(symva, p, sizeof(int) + sizeof(Elf_Ehdr) + 4.220 ehdr->e_shnum * sizeof(Elf_Shdr), xch, dom, parray, 4.221 dsi->v_start); 4.222 }
5.1 --- a/tools/libxc/xc_linux_restore.c Thu Jan 13 11:57:02 2005 +0000 5.2 +++ b/tools/libxc/xc_linux_restore.c Thu Jan 13 13:19:13 2005 +0000 5.3 @@ -19,31 +19,6 @@ 5.4 #define DPRINTF(_f, _a...) ((void)0) 5.5 #endif 5.6 5.7 -static int get_pfn_list(int xc_handle, 5.8 - u32 domain_id, 5.9 - unsigned long *pfn_buf, 5.10 - unsigned long max_pfns) 5.11 -{ 5.12 - dom0_op_t op; 5.13 - int ret; 5.14 - op.cmd = DOM0_GETMEMLIST; 5.15 - op.u.getmemlist.domain = (domid_t)domain_id; 5.16 - op.u.getmemlist.max_pfns = max_pfns; 5.17 - op.u.getmemlist.buffer = pfn_buf; 5.18 - 5.19 - if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 ) 5.20 - { 5.21 - PERROR("Could not lock pfn list buffer"); 5.22 - return -1; 5.23 - } 5.24 - 5.25 - ret = do_dom0_op(xc_handle, &op); 5.26 - 5.27 - (void)munlock(pfn_buf, max_pfns * sizeof(unsigned long)); 5.28 - 5.29 - return (ret < 0) ? -1 : op.u.getmemlist.num_pfns; 5.30 -} 5.31 - 5.32 /** Read the vmconfig string from the state input. 5.33 * It is stored as a 4-byte count 'n' followed by n bytes. 5.34 * The config data is stored in a new string in 'ioctxt->vmconfig', 5.35 @@ -202,6 +177,7 @@ int xc_linux_restore(int xc_handle, XcIO 5.36 /* Get the domain's shared-info frame. */ 5.37 op.cmd = DOM0_GETDOMAININFO; 5.38 op.u.getdomaininfo.domain = (domid_t)dom; 5.39 + op.u.getdomaininfo.exec_domain = 0; 5.40 op.u.getdomaininfo.ctxt = NULL; 5.41 if ( do_dom0_op(xc_handle, &op) < 0 ) 5.42 { 5.43 @@ -220,7 +196,7 @@ int xc_linux_restore(int xc_handle, XcIO 5.44 } 5.45 5.46 /* Build the pfn-to-mfn table. We choose MFN ordering returned by Xen. */ 5.47 - if ( get_pfn_list(xc_handle, dom, pfn_to_mfn_table, nr_pfns) != nr_pfns ) 5.48 + if ( xc_get_pfn_list(xc_handle, dom, pfn_to_mfn_table, nr_pfns) != nr_pfns ) 5.49 { 5.50 xcio_error(ioctxt, "Did not read correct number of frame " 5.51 "numbers for new dom");
6.1 --- a/tools/libxc/xc_linux_save.c Thu Jan 13 11:57:02 2005 +0000 6.2 +++ b/tools/libxc/xc_linux_save.c Thu Jan 13 13:19:13 2005 +0000 6.3 @@ -232,8 +232,8 @@ static int print_stats( int xc_handle, u 6.4 6.5 gettimeofday(&wall_now, NULL); 6.6 6.7 - d0_cpu_now = xc_domain_get_cpu_usage( xc_handle, 0 )/1000; 6.8 - d1_cpu_now = xc_domain_get_cpu_usage( xc_handle, domid )/1000; 6.9 + d0_cpu_now = xc_domain_get_cpu_usage( xc_handle, 0, /* FIXME */ 0 )/1000; 6.10 + d1_cpu_now = xc_domain_get_cpu_usage( xc_handle, domid, /* FIXME */ 0 )/1000; 6.11 6.12 if ( (d0_cpu_now == -1) || (d1_cpu_now == -1) ) 6.13 printf("ARRHHH!!\n"); 6.14 @@ -331,7 +331,7 @@ int suspend_and_state(int xc_handle, XcI 6.15 6.16 retry: 6.17 6.18 - if ( xc_domain_getfullinfo(xc_handle, ioctxt->domain, info, ctxt) ) 6.19 + if ( xc_domain_getfullinfo(xc_handle, ioctxt->domain, /* FIXME */ 0, info, ctxt) ) 6.20 { 6.21 xcio_error(ioctxt, "Could not get full domain info"); 6.22 return -1; 6.23 @@ -444,7 +444,7 @@ int xc_linux_save(int xc_handle, XcIOCon 6.24 return 1; 6.25 } 6.26 6.27 - if ( xc_domain_getfullinfo( xc_handle, domid, &info, &ctxt) ) 6.28 + if ( xc_domain_getfullinfo( xc_handle, domid, /* FIXME */ 0, &info, &ctxt) ) 6.29 { 6.30 xcio_error(ioctxt, "Could not get full domain info"); 6.31 goto out;
7.1 --- a/tools/libxc/xc_plan9_build.c Thu Jan 13 11:57:02 2005 +0000 7.2 +++ b/tools/libxc/xc_plan9_build.c Thu Jan 13 13:19:13 2005 +0000 7.3 @@ -132,52 +132,6 @@ static int 7.4 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED) 7.5 #define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER) 7.6 7.7 -static long 7.8 -get_tot_pages(int xc_handle, u32 domid) 7.9 -{ 7.10 - dom0_op_t op; 7.11 - op.cmd = DOM0_GETDOMAININFO; 7.12 - op.u.getdomaininfo.domain = (domid_t) domid; 7.13 - op.u.getdomaininfo.ctxt = NULL; 7.14 - return (do_dom0_op(xc_handle, &op) < 0) ? 7.15 - -1 : op.u.getdomaininfo.tot_pages; 7.16 -} 7.17 - 7.18 -static int 7.19 -get_pfn_list(int xc_handle, 7.20 - u32 domid, unsigned long *pfn_buf, unsigned long max_pfns) 7.21 -{ 7.22 - dom0_op_t op; 7.23 - int ret; 7.24 - op.cmd = DOM0_GETMEMLIST; 7.25 - op.u.getmemlist.domain = (domid_t) domid; 7.26 - op.u.getmemlist.max_pfns = max_pfns; 7.27 - op.u.getmemlist.buffer = pfn_buf; 7.28 - 7.29 - if (mlock(pfn_buf, max_pfns * sizeof (unsigned long)) != 0) 7.30 - return -1; 7.31 - 7.32 - ret = do_dom0_op(xc_handle, &op); 7.33 - 7.34 - (void) munlock(pfn_buf, max_pfns * sizeof (unsigned long)); 7.35 - 7.36 -#if 0 7.37 -#ifdef DEBUG 7.38 - DPRINTF(("Ret for get_pfn_list is %d\n", ret)); 7.39 - if (ret >= 0) { 7.40 - int i, j; 7.41 - for (i = 0; i < op.u.getmemlist.num_pfns; i += 16) { 7.42 - fprintf(stderr, "0x%x: ", i); 7.43 - for (j = 0; j < 16; j++) 7.44 - fprintf(stderr, "0x%lx ", pfn_buf[i + j]); 7.45 - fprintf(stderr, "\n"); 7.46 - } 7.47 - } 7.48 -#endif 7.49 -#endif 7.50 - return (ret < 0) ? -1 : op.u.getmemlist.num_pfns; 7.51 -} 7.52 - 7.53 static int 7.54 setup_guestos(int xc_handle, 7.55 u32 dom, 7.56 @@ -216,7 +170,7 @@ setup_guestos(int xc_handle, 7.57 goto error_out; 7.58 } 7.59 7.60 - if (get_pfn_list(xc_handle, dom, cpage_array, tot_pages) != tot_pages) { 7.61 + if (xc_get_pfn_list(xc_handle, dom, cpage_array, tot_pages) != tot_pages) { 7.62 PERROR("Could not get the page frame list"); 7.63 goto error_out; 7.64 } 7.65 @@ -487,11 +441,11 @@ xc_plan9_build(int xc_handle, 7.66 full_execution_context_t st_ctxt, *ctxt = &st_ctxt; 7.67 unsigned long virt_startinfo_addr; 7.68 7.69 - if ((tot_pages = get_tot_pages(xc_handle, domid)) < 0) { 7.70 + if ((tot_pages = xc_get_tot_pages(xc_handle, domid)) < 0) { 7.71 PERROR("Could not find total pages for domain"); 7.72 return 1; 7.73 } 7.74 - DPRINTF(("get_tot_pages returns %ld pages\n", tot_pages)); 7.75 + DPRINTF(("xc_get_tot_pages returns %ld pages\n", tot_pages)); 7.76 7.77 kernel_fd = open(image_name, O_RDONLY); 7.78 if (kernel_fd < 0) { 7.79 @@ -505,7 +459,7 @@ xc_plan9_build(int xc_handle, 7.80 return 1; 7.81 } 7.82 7.83 - DPRINTF(("get_tot_pages returns %ld pages\n", tot_pages)); 7.84 + DPRINTF(("xc_get_tot_pages returns %ld pages\n", tot_pages)); 7.85 if (mlock(&st_ctxt, sizeof (st_ctxt))) { 7.86 PERROR("Unable to mlock ctxt"); 7.87 return 1; 7.88 @@ -513,13 +467,14 @@ xc_plan9_build(int xc_handle, 7.89 7.90 op.cmd = DOM0_GETDOMAININFO; 7.91 op.u.getdomaininfo.domain = (domid_t) domid; 7.92 + op.u.getdomaininfo.exec_domain = 0; 7.93 op.u.getdomaininfo.ctxt = ctxt; 7.94 if ((do_dom0_op(xc_handle, &op) < 0) || 7.95 ((u32) op.u.getdomaininfo.domain != domid)) { 7.96 PERROR("Could not get info on domain"); 7.97 goto error_out; 7.98 } 7.99 - DPRINTF(("get_tot_pages returns %ld pages\n", tot_pages)); 7.100 + DPRINTF(("xc_get_tot_pages returns %ld pages\n", tot_pages)); 7.101 7.102 if (!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED) 7.103 || (op.u.getdomaininfo.ctxt->pt_base != 0)) { 7.104 @@ -527,7 +482,7 @@ xc_plan9_build(int xc_handle, 7.105 goto error_out; 7.106 } 7.107 7.108 - DPRINTF(("get_tot_pages returns %ld pages\n", tot_pages)); 7.109 + DPRINTF(("xc_get_tot_pages returns %ld pages\n", tot_pages)); 7.110 if (setup_guestos(xc_handle, domid, kernel_gfd, tot_pages, 7.111 &virt_startinfo_addr, 7.112 &load_addr, &st_ctxt, cmdline,
8.1 --- a/tools/libxc/xc_private.c Thu Jan 13 11:57:02 2005 +0000 8.2 +++ b/tools/libxc/xc_private.c Thu Jan 13 13:19:13 2005 +0000 8.3 @@ -4,6 +4,7 @@ 8.4 * Helper functions for the rest of the library. 8.5 */ 8.6 8.7 +#include <zlib.h> 8.8 #include "xc_private.h" 8.9 8.10 void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot, 8.11 @@ -159,12 +160,13 @@ int finish_mmu_updates(int xc_handle, mm 8.12 } 8.13 8.14 8.15 -long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid ) 8.16 +long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid, int vcpu ) 8.17 { 8.18 dom0_op_t op; 8.19 8.20 op.cmd = DOM0_GETDOMAININFO; 8.21 op.u.getdomaininfo.domain = (domid_t)domid; 8.22 + op.u.getdomaininfo.exec_domain = (u16)vcpu; 8.23 op.u.getdomaininfo.ctxt = NULL; 8.24 if ( (do_dom0_op(xc_handle, &op) < 0) || 8.25 ((u16)op.u.getdomaininfo.domain != domid) ) 8.26 @@ -201,5 +203,151 @@ unsigned long xc_get_m2p_start_mfn ( int 8.27 return mfn; 8.28 } 8.29 8.30 +int xc_get_pfn_list(int xc_handle, 8.31 + u32 domid, 8.32 + unsigned long *pfn_buf, 8.33 + unsigned long max_pfns) 8.34 +{ 8.35 + dom0_op_t op; 8.36 + int ret; 8.37 + op.cmd = DOM0_GETMEMLIST; 8.38 + op.u.getmemlist.domain = (domid_t)domid; 8.39 + op.u.getmemlist.max_pfns = max_pfns; 8.40 + op.u.getmemlist.buffer = pfn_buf; 8.41 8.42 8.43 + if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 ) 8.44 + { 8.45 + PERROR("Could not lock pfn list buffer"); 8.46 + return -1; 8.47 + } 8.48 + 8.49 + ret = do_dom0_op(xc_handle, &op); 8.50 + 8.51 + (void)munlock(pfn_buf, max_pfns * sizeof(unsigned long)); 8.52 + 8.53 +#if 0 8.54 +#ifdef DEBUG 8.55 + DPRINTF(("Ret for xc_get_pfn_list is %d\n", ret)); 8.56 + if (ret >= 0) { 8.57 + int i, j; 8.58 + for (i = 0; i < op.u.getmemlist.num_pfns; i += 16) { 8.59 + fprintf(stderr, "0x%x: ", i); 8.60 + for (j = 0; j < 16; j++) 8.61 + fprintf(stderr, "0x%lx ", pfn_buf[i + j]); 8.62 + fprintf(stderr, "\n"); 8.63 + } 8.64 + } 8.65 +#endif 8.66 +#endif 8.67 + 8.68 + return (ret < 0) ? -1 : op.u.getmemlist.num_pfns; 8.69 +} 8.70 + 8.71 +long xc_get_tot_pages(int xc_handle, u32 domid) 8.72 +{ 8.73 + dom0_op_t op; 8.74 + op.cmd = DOM0_GETDOMAININFO; 8.75 + op.u.getdomaininfo.domain = (domid_t)domid; 8.76 + op.u.getdomaininfo.exec_domain = 0; 8.77 + op.u.getdomaininfo.ctxt = NULL; 8.78 + return (do_dom0_op(xc_handle, &op) < 0) ? 8.79 + -1 : op.u.getdomaininfo.tot_pages; 8.80 +} 8.81 + 8.82 +int xc_copy_to_domain_page(int xc_handle, 8.83 + u32 domid, 8.84 + unsigned long dst_pfn, 8.85 + void *src_page) 8.86 +{ 8.87 + void *vaddr = xc_map_foreign_range( 8.88 + xc_handle, domid, PAGE_SIZE, PROT_WRITE, dst_pfn); 8.89 + if ( vaddr == NULL ) 8.90 + return -1; 8.91 + memcpy(vaddr, src_page, PAGE_SIZE); 8.92 + munmap(vaddr, PAGE_SIZE); 8.93 + return 0; 8.94 +} 8.95 + 8.96 +unsigned long xc_get_filesz(int fd) 8.97 +{ 8.98 + u16 sig; 8.99 + u32 _sz = 0; 8.100 + unsigned long sz; 8.101 + 8.102 + lseek(fd, 0, SEEK_SET); 8.103 + read(fd, &sig, sizeof(sig)); 8.104 + sz = lseek(fd, 0, SEEK_END); 8.105 + if ( sig == 0x8b1f ) /* GZIP signature? */ 8.106 + { 8.107 + lseek(fd, -4, SEEK_END); 8.108 + read(fd, &_sz, 4); 8.109 + sz = _sz; 8.110 + } 8.111 + lseek(fd, 0, SEEK_SET); 8.112 + 8.113 + return sz; 8.114 +} 8.115 + 8.116 +char *xc_read_kernel_image(const char *filename, unsigned long *size) 8.117 +{ 8.118 + int kernel_fd = -1; 8.119 + gzFile kernel_gfd = NULL; 8.120 + char *image = NULL; 8.121 + unsigned int bytes; 8.122 + 8.123 + if ( (kernel_fd = open(filename, O_RDONLY)) < 0 ) 8.124 + { 8.125 + PERROR("Could not open kernel image"); 8.126 + goto out; 8.127 + } 8.128 + 8.129 + *size = xc_get_filesz(kernel_fd); 8.130 + 8.131 + if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL ) 8.132 + { 8.133 + PERROR("Could not allocate decompression state for state file"); 8.134 + goto out; 8.135 + } 8.136 + 8.137 + if ( (image = malloc(*size)) == NULL ) 8.138 + { 8.139 + PERROR("Could not allocate memory for kernel image"); 8.140 + goto out; 8.141 + } 8.142 + 8.143 + if ( (bytes = gzread(kernel_gfd, image, *size)) != *size ) 8.144 + { 8.145 + PERROR("Error reading kernel image, could not" 8.146 + " read the whole image (%d != %ld).", bytes, *size); 8.147 + free(image); 8.148 + image = NULL; 8.149 + } 8.150 + 8.151 + out: 8.152 + if ( kernel_gfd != NULL ) 8.153 + gzclose(kernel_gfd); 8.154 + else if ( kernel_fd >= 0 ) 8.155 + close(kernel_fd); 8.156 + return image; 8.157 +} 8.158 + 8.159 +void xc_map_memcpy(unsigned long dst, char *src, unsigned long size, 8.160 + int xch, u32 dom, unsigned long *parray, 8.161 + unsigned long vstart) 8.162 +{ 8.163 + char *va; 8.164 + unsigned long chunksz, done, pa; 8.165 + 8.166 + for ( done = 0; done < size; done += chunksz ) 8.167 + { 8.168 + pa = dst + done - vstart; 8.169 + va = xc_map_foreign_range( 8.170 + xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]); 8.171 + chunksz = size - done; 8.172 + if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) ) 8.173 + chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1)); 8.174 + memcpy(va + (pa & (PAGE_SIZE-1)), src + done, chunksz); 8.175 + munmap(va, PAGE_SIZE); 8.176 + } 8.177 +}
9.1 --- a/tools/libxc/xc_private.h Thu Jan 13 11:57:02 2005 +0000 9.2 +++ b/tools/libxc/xc_private.h Thu Jan 13 13:19:13 2005 +0000 9.3 @@ -189,4 +189,17 @@ typedef struct mfn_mapper { 9.4 9.5 unsigned long xc_get_m2p_start_mfn ( int xc_handle ); 9.6 9.7 +long xc_get_tot_pages(int xc_handle, u32 domid); 9.8 + 9.9 +int xc_copy_to_domain_page(int xc_handle, u32 domid, 9.10 + unsigned long dst_pfn, void *src_page); 9.11 + 9.12 +unsigned long xc_get_filesz(int fd); 9.13 + 9.14 +char *xc_read_kernel_image(const char *filename, unsigned long *size); 9.15 + 9.16 +void xc_map_memcpy(unsigned long dst, char *src, unsigned long size, 9.17 + int xch, u32 dom, unsigned long *parray, 9.18 + unsigned long vstart); 9.19 + 9.20 #endif /* __XC_PRIVATE_H__ */
10.1 --- a/tools/libxc/xc_vmx_build.c Thu Jan 13 11:57:02 2005 +0000 10.2 +++ b/tools/libxc/xc_vmx_build.c Thu Jan 13 13:19:13 2005 +0000 10.3 @@ -46,53 +46,6 @@ loadelfsymtab( 10.4 char *elfbase, int xch, u32 dom, unsigned long *parray, 10.5 struct domain_setup_info *dsi); 10.6 10.7 -static long get_tot_pages(int xc_handle, u32 domid) 10.8 -{ 10.9 - dom0_op_t op; 10.10 - op.cmd = DOM0_GETDOMAININFO; 10.11 - op.u.getdomaininfo.domain = (domid_t)domid; 10.12 - op.u.getdomaininfo.ctxt = NULL; 10.13 - return (do_dom0_op(xc_handle, &op) < 0) ? 10.14 - -1 : op.u.getdomaininfo.tot_pages; 10.15 -} 10.16 - 10.17 -int xc_get_pfn_list(int xc_handle, 10.18 - u32 domid, 10.19 - unsigned long *pfn_buf, 10.20 - unsigned long max_pfns) 10.21 -{ 10.22 - dom0_op_t op; 10.23 - int ret; 10.24 - op.cmd = DOM0_GETMEMLIST; 10.25 - op.u.getmemlist.domain = (domid_t)domid; 10.26 - op.u.getmemlist.max_pfns = max_pfns; 10.27 - op.u.getmemlist.buffer = pfn_buf; 10.28 - 10.29 - 10.30 - if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 ) 10.31 - return -1; 10.32 - 10.33 - ret = do_dom0_op(xc_handle, &op); 10.34 - 10.35 - (void)munlock(pfn_buf, max_pfns * sizeof(unsigned long)); 10.36 - 10.37 - return (ret < 0) ? -1 : op.u.getmemlist.num_pfns; 10.38 -} 10.39 - 10.40 -static int copy_to_domain_page(int xc_handle, 10.41 - u32 domid, 10.42 - unsigned long dst_pfn, 10.43 - void *src_page) 10.44 -{ 10.45 - void *vaddr = xc_map_foreign_range( 10.46 - xc_handle, domid, PAGE_SIZE, PROT_WRITE, dst_pfn); 10.47 - if ( vaddr == NULL ) 10.48 - return -1; 10.49 - memcpy(vaddr, src_page, PAGE_SIZE); 10.50 - munmap(vaddr, PAGE_SIZE); 10.51 - return 0; 10.52 -} 10.53 - 10.54 static int setup_guestos(int xc_handle, 10.55 u32 dom, 10.56 char *image, unsigned long image_size, 10.57 @@ -225,7 +178,7 @@ static int setup_guestos(int xc_handle, 10.58 PERROR("Error reading initrd image, could not"); 10.59 goto error_out; 10.60 } 10.61 - copy_to_domain_page(xc_handle, dom, 10.62 + xc_copy_to_domain_page(xc_handle, dom, 10.63 page_array[i>>PAGE_SHIFT], page); 10.64 } 10.65 } 10.66 @@ -402,68 +355,6 @@ static int setup_guestos(int xc_handle, 10.67 return -1; 10.68 } 10.69 10.70 -static unsigned long get_filesz(int fd) 10.71 -{ 10.72 - u16 sig; 10.73 - u32 _sz = 0; 10.74 - unsigned long sz; 10.75 - 10.76 - lseek(fd, 0, SEEK_SET); 10.77 - read(fd, &sig, sizeof(sig)); 10.78 - sz = lseek(fd, 0, SEEK_END); 10.79 - if ( sig == 0x8b1f ) /* GZIP signature? */ 10.80 - { 10.81 - lseek(fd, -4, SEEK_END); 10.82 - read(fd, &_sz, 4); 10.83 - sz = _sz; 10.84 - } 10.85 - lseek(fd, 0, SEEK_SET); 10.86 - 10.87 - return sz; 10.88 -} 10.89 - 10.90 -static char *read_kernel_image(const char *filename, unsigned long *size) 10.91 -{ 10.92 - int kernel_fd = -1; 10.93 - gzFile kernel_gfd = NULL; 10.94 - char *image = NULL; 10.95 - unsigned int bytes; 10.96 - 10.97 - if ( (kernel_fd = open(filename, O_RDONLY)) < 0 ) 10.98 - { 10.99 - PERROR("Could not open kernel image"); 10.100 - goto out; 10.101 - } 10.102 - 10.103 - *size = get_filesz(kernel_fd); 10.104 - 10.105 - if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL ) 10.106 - { 10.107 - PERROR("Could not allocate decompression state for state file"); 10.108 - goto out; 10.109 - } 10.110 - 10.111 - if ( (image = malloc(*size)) == NULL ) 10.112 - { 10.113 - PERROR("Could not allocate memory for kernel image"); 10.114 - goto out; 10.115 - } 10.116 - 10.117 - if ( (bytes = gzread(kernel_gfd, image, *size)) != *size ) 10.118 - { 10.119 - PERROR("Error reading kernel image, could not" 10.120 - " read the whole image (%d != %ld).", bytes, *size); 10.121 - free(image); 10.122 - image = NULL; 10.123 - } 10.124 - 10.125 - out: 10.126 - if ( kernel_gfd != NULL ) 10.127 - gzclose(kernel_gfd); 10.128 - else if ( kernel_fd >= 0 ) 10.129 - close(kernel_fd); 10.130 - return image; 10.131 -} 10.132 10.133 #define VMX_FEATURE_FLAG 0x20 10.134 10.135 @@ -505,13 +396,13 @@ int xc_vmx_build(int xc_handle, 10.136 goto error_out; 10.137 } 10.138 10.139 - if ( (nr_pages = get_tot_pages(xc_handle, domid)) < 0 ) 10.140 + if ( (nr_pages = xc_get_tot_pages(xc_handle, domid)) < 0 ) 10.141 { 10.142 PERROR("Could not find total pages for domain"); 10.143 goto error_out; 10.144 } 10.145 10.146 - if ( (image = read_kernel_image(image_name, &image_size)) == NULL ) 10.147 + if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL ) 10.148 goto error_out; 10.149 10.150 if ( (ramdisk_name != NULL) && (strlen(ramdisk_name) != 0) ) 10.151 @@ -522,7 +413,7 @@ int xc_vmx_build(int xc_handle, 10.152 goto error_out; 10.153 } 10.154 10.155 - initrd_size = get_filesz(initrd_fd); 10.156 + initrd_size = xc_get_filesz(initrd_fd); 10.157 10.158 if ( (initrd_gfd = gzdopen(initrd_fd, "rb")) == NULL ) 10.159 { 10.160 @@ -539,6 +430,7 @@ int xc_vmx_build(int xc_handle, 10.161 10.162 op.cmd = DOM0_GETDOMAININFO; 10.163 op.u.getdomaininfo.domain = (domid_t)domid; 10.164 + op.u.getdomaininfo.exec_domain = 0; 10.165 op.u.getdomaininfo.ctxt = ctxt; 10.166 if ( (do_dom0_op(xc_handle, &op) < 0) || 10.167 ((u16)op.u.getdomaininfo.domain != domid) ) 10.168 @@ -746,26 +638,6 @@ loadelfimage( 10.169 return 0; 10.170 } 10.171 10.172 -static void 10.173 -map_memcpy( 10.174 - unsigned long dst, char *src, unsigned long size, 10.175 - int xch, u32 dom, unsigned long *parray, unsigned long vstart) 10.176 -{ 10.177 - char *va; 10.178 - unsigned long chunksz, done, pa; 10.179 - 10.180 - for ( done = 0; done < size; done += chunksz ) 10.181 - { 10.182 - pa = dst + done - vstart; 10.183 - va = xc_map_foreign_range( 10.184 - xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]); 10.185 - chunksz = size - done; 10.186 - if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) ) 10.187 - chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1)); 10.188 - memcpy(va + (pa & (PAGE_SIZE-1)), src + done, chunksz); 10.189 - munmap(va, PAGE_SIZE); 10.190 - } 10.191 -} 10.192 10.193 #define ELFROUND (ELFSIZE / 8) 10.194 10.195 @@ -817,7 +689,7 @@ loadelfsymtab( 10.196 (shdr[h].sh_type == SHT_SYMTAB) ) 10.197 { 10.198 if ( parray != NULL ) 10.199 - map_memcpy(maxva, elfbase + shdr[h].sh_offset, shdr[h].sh_size, 10.200 + xc_map_memcpy(maxva, elfbase + shdr[h].sh_offset, shdr[h].sh_size, 10.201 xch, dom, parray, dsi->v_start); 10.202 10.203 /* Mangled to be based on ELF header location. */ 10.204 @@ -849,7 +721,7 @@ loadelfsymtab( 10.205 sym_ehdr->e_shstrndx = SHN_UNDEF; 10.206 10.207 /* Copy total length, crafted ELF header and section header table */ 10.208 - map_memcpy(symva, p, sizeof(int) + sizeof(Elf_Ehdr) + 10.209 + xc_map_memcpy(symva, p, sizeof(int) + sizeof(Elf_Ehdr) + 10.210 ehdr->e_shnum * sizeof(Elf_Shdr), xch, dom, parray, 10.211 dsi->v_start); 10.212 }
11.1 --- a/xen/common/dom0_ops.c Thu Jan 13 11:57:02 2005 +0000 11.2 +++ b/xen/common/dom0_ops.c Thu Jan 13 13:19:13 2005 +0000 11.3 @@ -354,7 +354,14 @@ long do_dom0_op(dom0_op_t *u_dom0_op) 11.4 11.5 op->u.getdomaininfo.domain = d->id; 11.6 11.7 - ed = d->exec_domain[0]; // op->u.getdomaininfo.exec_domain]; 11.8 + if ( (op->u.getdomaininfo.exec_domain >= MAX_VIRT_CPUS) || 11.9 + !d->exec_domain[op->u.getdomaininfo.exec_domain] ) 11.10 + { 11.11 + ret = -EINVAL; 11.12 + break; 11.13 + } 11.14 + 11.15 + ed = d->exec_domain[op->u.getdomaininfo.exec_domain]; 11.16 11.17 op->u.getdomaininfo.flags = 11.18 (test_bit( DF_DYING, &d->d_flags) ? DOMFLAGS_DYING : 0) |