xen-vtx-unstable
changeset 6389:fdfd511768a3
Break the building/save/restore code out into a separate library libxenguest.
Also update the tools accordingly.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
Also update the tools accordingly.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
line diff
1.1 --- a/tools/libxc/Makefile Wed Aug 24 23:07:29 2005 +0000 1.2 +++ b/tools/libxc/Makefile Thu Aug 25 00:51:20 2005 +0000 1.3 @@ -12,28 +12,32 @@ CC = gcc 1.4 XEN_ROOT = ../.. 1.5 include $(XEN_ROOT)/tools/Rules.mk 1.6 1.7 -SRCS := 1.8 -SRCS += xc_sedf.c 1.9 -SRCS += xc_bvtsched.c 1.10 -SRCS += xc_core.c 1.11 -SRCS += xc_domain.c 1.12 -SRCS += xc_evtchn.c 1.13 -SRCS += xc_gnttab.c 1.14 -SRCS += xc_load_bin.c 1.15 -SRCS += xc_load_elf.c 1.16 -SRCS += xc_linux_build.c 1.17 -SRCS += xc_misc.c 1.18 -SRCS += xc_physdev.c 1.19 -SRCS += xc_private.c 1.20 +SRCS := 1.21 +BUILD_SRCS := 1.22 +SRCS += xc_bvtsched.c 1.23 +SRCS += xc_core.c 1.24 +SRCS += xc_domain.c 1.25 +SRCS += xc_evtchn.c 1.26 +SRCS += xc_gnttab.c 1.27 +SRCS += xc_misc.c 1.28 +SRCS += xc_physdev.c 1.29 +SRCS += xc_private.c 1.30 +SRCS += xc_sedf.c 1.31 + 1.32 ifeq ($(XEN_TARGET_ARCH),ia64) 1.33 -SRCS += xc_ia64_stubs.c 1.34 +BUILD_SRCS += xc_ia64_stubs.c 1.35 else 1.36 -SRCS += xc_load_aout9.c 1.37 -SRCS += xc_linux_restore.c 1.38 -SRCS += xc_linux_save.c 1.39 -SRCS += xc_vmx_build.c 1.40 -SRCS += xc_ptrace.c 1.41 -SRCS += xc_ptrace_core.c 1.42 +SRCS += xc_ptrace.c 1.43 +SRCS += xc_ptrace_core.c 1.44 + 1.45 +BUILD_SRCS := xc_load_aout9.c 1.46 +BUILD_SRCS += xc_load_bin.c 1.47 +BUILD_SRCS += xc_load_elf.c 1.48 +BUILD_SRCS += xc_linux_build.c 1.49 +BUILD_SRCS += xc_linux_restore.c 1.50 +BUILD_SRCS += xc_linux_save.c 1.51 +BUILD_SRCS += xc_vmx_build.c 1.52 +BUILD_SRCS += xg_private.c 1.53 endif 1.54 1.55 CFLAGS += -Wall 1.56 @@ -43,13 +47,20 @@ CFLAGS += -fno-strict-aliasing 1.57 CFLAGS += $(INCLUDES) -I. 1.58 # Get gcc to generate the dependencies for us. 1.59 CFLAGS += -Wp,-MD,.$(@F).d 1.60 +LDFLAGS += -L. 1.61 DEPS = .*.d 1.62 1.63 LIB_OBJS := $(patsubst %.c,%.o,$(SRCS)) 1.64 PIC_OBJS := $(patsubst %.c,%.opic,$(SRCS)) 1.65 1.66 -LIB := libxenctrl.a libxenctrl-pic.a 1.67 -LIB += libxenctrl.so libxenctrl.so.$(MAJOR) libxenctrl.so.$(MAJOR).$(MINOR) 1.68 +LIB_BUILD_OBJS := $(patsubst %.c,%.o,$(BUILD_SRCS)) 1.69 +PIC_BUILD_OBJS := $(patsubst %.c,%.opic,$(BUILD_SRCS)) 1.70 + 1.71 +LIB := libxenctrl.a 1.72 +LIB += libxenctrl.so libxenctrl.so.$(MAJOR) libxenctrl.so.$(MAJOR).$(MINOR) 1.73 + 1.74 +LIB += libxenguest.a 1.75 +LIB += libxenguest.so libxenguest.so.$(MAJOR) libxenguest.so.$(MAJOR).$(MINOR) 1.76 1.77 all: build 1.78 build: check-for-zlib mk-symlinks 1.79 @@ -83,6 +94,11 @@ install: build 1.80 ln -sf libxenctrl.so.$(MAJOR) $(DESTDIR)/usr/$(LIBDIR)/libxenctrl.so 1.81 $(INSTALL_DATA) xenctrl.h $(DESTDIR)/usr/include/xen 1.82 1.83 + $(INSTALL_PROG) libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR) 1.84 + $(INSTALL_DATA) libxenguest.a $(DESTDIR)/usr/$(LIBDIR) 1.85 + ln -sf libxenguest.so.$(MAJOR).$(MINOR) $(DESTDIR)/usr/$(LIBDIR)/libxenguest.so.$(MAJOR) 1.86 + ln -sf libxenguest.so.$(MAJOR) $(DESTDIR)/usr/$(LIBDIR)/libxenguest.so 1.87 + 1.88 .PHONY: TAGS clean rpm install all 1.89 1.90 TAGS: 1.91 @@ -100,18 +116,30 @@ rpm: build 1.92 mv staging/i386/*.rpm . 1.93 rm -rf staging 1.94 1.95 +# libxenctrl 1.96 + 1.97 libxenctrl.a: $(LIB_OBJS) 1.98 $(AR) rc $@ $^ 1.99 1.100 -libxenctrl-pic.a: $(PIC_OBJS) 1.101 - $(AR) rc $@ $^ 1.102 - 1.103 libxenctrl.so: libxenctrl.so.$(MAJOR) 1.104 ln -sf $< $@ 1.105 libxenctrl.so.$(MAJOR): libxenctrl.so.$(MAJOR).$(MINOR) 1.106 ln -sf $< $@ 1.107 1.108 libxenctrl.so.$(MAJOR).$(MINOR): $(PIC_OBJS) 1.109 - $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenctrl.so.$(MAJOR) -shared -o $@ $^ -lz 1.110 + $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenctrl.so.$(MAJOR) -shared -o $@ $^ 1.111 + 1.112 +# libxenguest 1.113 + 1.114 +libxenguest.a: $(LIB_BUILD_OBJS) 1.115 + $(AR) rc $@ $^ 1.116 + 1.117 +libxenguest.so: libxenguest.so.$(MAJOR) 1.118 + ln -sf $< $@ 1.119 +libxenguest.so.$(MAJOR): libxenguest.so.$(MAJOR).$(MINOR) 1.120 + ln -sf $< $@ 1.121 + 1.122 +libxenguest.so.$(MAJOR).$(MINOR): $(PIC_BUILD_OBJS) 1.123 + $(CC) $(CFLAGS) $(LDFLAGS) -Wl,-soname -Wl,libxenguest.so.$(MAJOR) -shared -o $@ $^ -lz -lxenctrl 1.124 1.125 -include $(DEPS)
2.1 --- a/tools/libxc/xc_core.c Wed Aug 24 23:07:29 2005 +0000 2.2 +++ b/tools/libxc/xc_core.c Thu Aug 25 00:51:20 2005 +0000 2.3 @@ -1,4 +1,4 @@ 2.4 -#include "xc_private.h" 2.5 +#include "xg_private.h" 2.6 #define ELFSIZE 32 2.7 #include "xc_elf.h" 2.8 #include <stdlib.h>
3.1 --- a/tools/libxc/xc_domain.c Wed Aug 24 23:07:29 2005 +0000 3.2 +++ b/tools/libxc/xc_domain.c Thu Aug 25 00:51:20 2005 +0000 3.3 @@ -266,7 +266,7 @@ int xc_domain_memory_increase_reservatio 3.4 int err; 3.5 unsigned int npages = mem_kb / (PAGE_SIZE/1024); 3.6 3.7 - err = do_dom_mem_op(xc_handle, MEMOP_increase_reservation, NULL, 3.8 + err = xc_dom_mem_op(xc_handle, MEMOP_increase_reservation, NULL, 3.9 npages, 0, domid); 3.10 if (err == npages) 3.11 return 0;
4.1 --- a/tools/libxc/xc_linux_build.c Wed Aug 24 23:07:29 2005 +0000 4.2 +++ b/tools/libxc/xc_linux_build.c Thu Aug 25 00:51:20 2005 +0000 4.3 @@ -2,7 +2,8 @@ 4.4 * xc_linux_build.c 4.5 */ 4.6 4.7 -#include "xc_private.h" 4.8 +#include "xg_private.h" 4.9 +#include <xenctrl.h> 4.10 4.11 #if defined(__i386__) 4.12 #define ELFSIZE 32 4.13 @@ -340,7 +341,7 @@ static int setup_guest(int xc_handle, 4.14 unsigned long count, i; 4.15 start_info_t *start_info; 4.16 shared_info_t *shared_info; 4.17 - mmu_t *mmu = NULL; 4.18 + xc_mmu_t *mmu = NULL; 4.19 int rc; 4.20 4.21 unsigned long nr_pt_pages; 4.22 @@ -490,7 +491,7 @@ static int setup_guest(int xc_handle, 4.23 } 4.24 } 4.25 4.26 - if ( (mmu = init_mmu_updates(xc_handle, dom)) == NULL ) 4.27 + if ( (mmu = xc_init_mmu_updates(xc_handle, dom)) == NULL ) 4.28 goto error_out; 4.29 4.30 /* setup page tables */ 4.31 @@ -520,9 +521,9 @@ static int setup_guest(int xc_handle, 4.32 page_array[physmap_pfn++]); 4.33 for ( count = 0; count < nr_pages; count++ ) 4.34 { 4.35 - if ( add_mmu_update(xc_handle, mmu, 4.36 - (page_array[count] << PAGE_SHIFT) | 4.37 - MMU_MACHPHYS_UPDATE, count) ) 4.38 + if ( xc_add_mmu_update(xc_handle, mmu, 4.39 + (page_array[count] << PAGE_SHIFT) | 4.40 + MMU_MACHPHYS_UPDATE, count) ) 4.41 { 4.42 munmap(physmap, PAGE_SIZE); 4.43 goto error_out; 4.44 @@ -602,7 +603,7 @@ static int setup_guest(int xc_handle, 4.45 munmap(shared_info, PAGE_SIZE); 4.46 4.47 /* Send the page update requests down to the hypervisor. */ 4.48 - if ( finish_mmu_updates(xc_handle, mmu) ) 4.49 + if ( xc_finish_mmu_updates(xc_handle, mmu) ) 4.50 goto error_out; 4.51 4.52 free(mmu); 4.53 @@ -676,7 +677,7 @@ int xc_linux_build(int xc_handle, 4.54 4.55 op.cmd = DOM0_GETDOMAININFO; 4.56 op.u.getdomaininfo.domain = (domid_t)domid; 4.57 - if ( (do_dom0_op(xc_handle, &op) < 0) || 4.58 + if ( (xc_dom0_op(xc_handle, &op) < 0) || 4.59 ((u16)op.u.getdomaininfo.domain != domid) ) 4.60 { 4.61 PERROR("Could not get info on domain"); 4.62 @@ -793,7 +794,7 @@ int xc_linux_build(int xc_handle, 4.63 launch_op.u.setdomaininfo.ctxt = ctxt; 4.64 4.65 launch_op.cmd = DOM0_SETDOMAININFO; 4.66 - rc = do_dom0_op(xc_handle, &launch_op); 4.67 + rc = xc_dom0_op(xc_handle, &launch_op); 4.68 4.69 return rc; 4.70
5.1 --- a/tools/libxc/xc_linux_restore.c Wed Aug 24 23:07:29 2005 +0000 5.2 +++ b/tools/libxc/xc_linux_restore.c Thu Aug 25 00:51:20 2005 +0000 5.3 @@ -6,7 +6,12 @@ 5.4 * Copyright (c) 2003, K A Fraser. 5.5 */ 5.6 5.7 -#include "xc_private.h" 5.8 +#include <stdlib.h> 5.9 +#include <unistd.h> 5.10 + 5.11 +#include "xg_private.h" 5.12 +#include <xenctrl.h> 5.13 + 5.14 #include <xen/linux/suspend.h> 5.15 5.16 #define MAX_BATCH_SIZE 1024 5.17 @@ -89,7 +94,7 @@ int xc_linux_restore(int xc_handle, int 5.18 5.19 char *region_base; 5.20 5.21 - mmu_t *mmu = NULL; 5.22 + xc_mmu_t *mmu = NULL; 5.23 5.24 /* used by debug verify code */ 5.25 unsigned long buf[PAGE_SIZE/sizeof(unsigned long)]; 5.26 @@ -132,7 +137,7 @@ int xc_linux_restore(int xc_handle, int 5.27 /* Get the domain's shared-info frame. */ 5.28 op.cmd = DOM0_GETDOMAININFO; 5.29 op.u.getdomaininfo.domain = (domid_t)dom; 5.30 - if (do_dom0_op(xc_handle, &op) < 0) { 5.31 + if (xc_dom0_op(xc_handle, &op) < 0) { 5.32 ERR("Could not get information on new domain"); 5.33 goto out; 5.34 } 5.35 @@ -158,7 +163,7 @@ int xc_linux_restore(int xc_handle, int 5.36 goto out; 5.37 } 5.38 5.39 - mmu = init_mmu_updates(xc_handle, dom); 5.40 + mmu = xc_init_mmu_updates(xc_handle, dom); 5.41 if (mmu == NULL) { 5.42 ERR("Could not initialise for MMU updates"); 5.43 goto out; 5.44 @@ -355,8 +360,9 @@ int xc_linux_restore(int xc_handle, int 5.45 } 5.46 } 5.47 5.48 - if ( add_mmu_update(xc_handle, mmu, 5.49 - (mfn<<PAGE_SHIFT) | MMU_MACHPHYS_UPDATE, pfn) ) 5.50 + if ( xc_add_mmu_update(xc_handle, mmu, 5.51 + (mfn<<PAGE_SHIFT) | MMU_MACHPHYS_UPDATE, 5.52 + pfn) ) 5.53 { 5.54 printf("machpys mfn=%ld pfn=%ld\n",mfn,pfn); 5.55 goto out; 5.56 @@ -370,7 +376,7 @@ int xc_linux_restore(int xc_handle, int 5.57 5.58 DPRINTF("Received all pages\n"); 5.59 5.60 - if ( finish_mmu_updates(xc_handle, mmu) ) 5.61 + if ( xc_finish_mmu_updates(xc_handle, mmu) ) 5.62 goto out; 5.63 5.64 /* 5.65 @@ -388,14 +394,14 @@ int xc_linux_restore(int xc_handle, int 5.66 pin[nr_pins].mfn = pfn_to_mfn_table[i]; 5.67 if ( ++nr_pins == MAX_PIN_BATCH ) 5.68 { 5.69 - if ( do_mmuext_op(xc_handle, pin, nr_pins, dom) < 0 ) 5.70 + if ( xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0 ) 5.71 goto out; 5.72 nr_pins = 0; 5.73 } 5.74 } 5.75 5.76 if ( (nr_pins != 0) && 5.77 - (do_mmuext_op(xc_handle, pin, nr_pins, dom) < 0) ) 5.78 + (xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0) ) 5.79 goto out; 5.80 5.81 DPRINTF("\b\b\b\b100%%\n"); 5.82 @@ -435,7 +441,7 @@ int xc_linux_restore(int xc_handle, int 5.83 5.84 if ( count > 0 ) 5.85 { 5.86 - if ( (rc = do_dom_mem_op( xc_handle, 5.87 + if ( (rc = xc_dom_mem_op( xc_handle, 5.88 MEMOP_decrease_reservation, 5.89 pfntab, count, 0, dom )) <0 ) 5.90 { 5.91 @@ -586,7 +592,7 @@ int xc_linux_restore(int xc_handle, int 5.92 op.u.setdomaininfo.domain = (domid_t)dom; 5.93 op.u.setdomaininfo.vcpu = 0; 5.94 op.u.setdomaininfo.ctxt = &ctxt; 5.95 - rc = do_dom0_op(xc_handle, &op); 5.96 + rc = xc_dom0_op(xc_handle, &op); 5.97 5.98 if ( rc != 0 ) 5.99 { 5.100 @@ -597,7 +603,7 @@ int xc_linux_restore(int xc_handle, int 5.101 DPRINTF("Domain ready to be unpaused\n"); 5.102 op.cmd = DOM0_UNPAUSEDOMAIN; 5.103 op.u.unpausedomain.domain = (domid_t)dom; 5.104 - rc = do_dom0_op(xc_handle, &op); 5.105 + rc = xc_dom0_op(xc_handle, &op); 5.106 if (rc == 0) { 5.107 /* Success: print the domain id. */ 5.108 DPRINTF("DOM=%u\n", dom);
6.1 --- a/tools/libxc/xc_linux_save.c Wed Aug 24 23:07:29 2005 +0000 6.2 +++ b/tools/libxc/xc_linux_save.c Thu Aug 25 00:51:20 2005 +0000 6.3 @@ -7,11 +7,15 @@ 6.4 */ 6.5 6.6 #include <inttypes.h> 6.7 +#include <time.h> 6.8 +#include <stdlib.h> 6.9 +#include <unistd.h> 6.10 #include <sys/time.h> 6.11 -#include "xc_private.h" 6.12 + 6.13 +#include "xg_private.h" 6.14 + 6.15 #include <xen/linux/suspend.h> 6.16 #include <xen/io/domain_controller.h> 6.17 -#include <time.h> 6.18 6.19 #define BATCH_SIZE 1024 /* 1024 pages (4MB) at a time */ 6.20 6.21 @@ -772,7 +776,7 @@ int xc_linux_save(int xc_handle, int io_ 6.22 goto out; 6.23 } 6.24 6.25 - if ( get_pfn_type_batch(xc_handle, dom, batch, pfn_type) ){ 6.26 + if ( xc_get_pfn_type_batch(xc_handle, dom, batch, pfn_type) ){ 6.27 ERR("get_pfn_type_batch failed"); 6.28 goto out; 6.29 }
7.1 --- a/tools/libxc/xc_load_aout9.c Wed Aug 24 23:07:29 2005 +0000 7.2 +++ b/tools/libxc/xc_load_aout9.c Thu Aug 25 00:51:20 2005 +0000 7.3 @@ -1,5 +1,5 @@ 7.4 7.5 -#include "xc_private.h" 7.6 +#include "xg_private.h" 7.7 #include "xc_aout9.h" 7.8 7.9 #if defined(__i386__)
8.1 --- a/tools/libxc/xc_load_bin.c Wed Aug 24 23:07:29 2005 +0000 8.2 +++ b/tools/libxc/xc_load_bin.c Thu Aug 25 00:51:20 2005 +0000 8.3 @@ -66,7 +66,7 @@ 8.4 * Free Software Foundation, Inc. 8.5 */ 8.6 8.7 -#include "xc_private.h" 8.8 +#include "xg_private.h" 8.9 #include <stdlib.h> 8.10 8.11 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
9.1 --- a/tools/libxc/xc_load_elf.c Wed Aug 24 23:07:29 2005 +0000 9.2 +++ b/tools/libxc/xc_load_elf.c Thu Aug 25 00:51:20 2005 +0000 9.3 @@ -2,7 +2,7 @@ 9.4 * xc_elf_load.c 9.5 */ 9.6 9.7 -#include "xc_private.h" 9.8 +#include "xg_private.h" 9.9 9.10 #if defined(__i386__) 9.11 #define ELFSIZE 32
10.1 --- a/tools/libxc/xc_private.c Wed Aug 24 23:07:29 2005 +0000 10.2 +++ b/tools/libxc/xc_private.c Thu Aug 25 00:51:20 2005 +0000 10.3 @@ -64,8 +64,8 @@ void *xc_map_foreign_range(int xc_handle 10.4 /*******************/ 10.5 10.6 /* NB: arr must be mlock'ed */ 10.7 -int get_pfn_type_batch(int xc_handle, 10.8 - u32 dom, int num, unsigned long *arr) 10.9 +int xc_get_pfn_type_batch(int xc_handle, 10.10 + u32 dom, int num, unsigned long *arr) 10.11 { 10.12 dom0_op_t op; 10.13 op.cmd = DOM0_GETPAGEFRAMEINFO2; 10.14 @@ -92,25 +92,40 @@ unsigned int get_pfn_type(int xc_handle, 10.15 return op.u.getpageframeinfo.type; 10.16 } 10.17 10.18 - 10.19 - 10.20 -/*******************/ 10.21 +int xc_mmuext_op( 10.22 + int xc_handle, 10.23 + struct mmuext_op *op, 10.24 + unsigned int nr_ops, 10.25 + domid_t dom) 10.26 +{ 10.27 + privcmd_hypercall_t hypercall; 10.28 + long ret = -EINVAL; 10.29 10.30 -int pin_table( 10.31 - int xc_handle, unsigned int type, unsigned long mfn, domid_t dom) 10.32 -{ 10.33 - struct mmuext_op op; 10.34 + hypercall.op = __HYPERVISOR_mmuext_op; 10.35 + hypercall.arg[0] = (unsigned long)op; 10.36 + hypercall.arg[1] = (unsigned long)nr_ops; 10.37 + hypercall.arg[2] = (unsigned long)0; 10.38 + hypercall.arg[3] = (unsigned long)dom; 10.39 10.40 - op.cmd = type; 10.41 - op.mfn = mfn; 10.42 + if ( mlock(op, nr_ops*sizeof(*op)) != 0 ) 10.43 + { 10.44 + PERROR("Could not lock memory for Xen hypercall"); 10.45 + goto out1; 10.46 + } 10.47 10.48 - if ( do_mmuext_op(xc_handle, &op, 1, dom) < 0 ) 10.49 - return 1; 10.50 + if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 ) 10.51 + { 10.52 + fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to" 10.53 + " rebuild the user-space tool set?\n",ret,errno); 10.54 + } 10.55 10.56 - return 0; 10.57 -} 10.58 + safe_munlock(op, nr_ops*sizeof(*op)); 10.59 10.60 -static int flush_mmu_updates(int xc_handle, mmu_t *mmu) 10.61 + out1: 10.62 + return ret; 10.63 +} 10.64 + 10.65 +static int flush_mmu_updates(int xc_handle, xc_mmu_t *mmu) 10.66 { 10.67 int err = 0; 10.68 privcmd_hypercall_t hypercall; 10.69 @@ -145,9 +160,9 @@ static int flush_mmu_updates(int xc_hand 10.70 return err; 10.71 } 10.72 10.73 -mmu_t *init_mmu_updates(int xc_handle, domid_t dom) 10.74 +xc_mmu_t *xc_init_mmu_updates(int xc_handle, domid_t dom) 10.75 { 10.76 - mmu_t *mmu = malloc(sizeof(mmu_t)); 10.77 + xc_mmu_t *mmu = malloc(sizeof(xc_mmu_t)); 10.78 if ( mmu == NULL ) 10.79 return mmu; 10.80 mmu->idx = 0; 10.81 @@ -155,8 +170,8 @@ mmu_t *init_mmu_updates(int xc_handle, d 10.82 return mmu; 10.83 } 10.84 10.85 -int add_mmu_update(int xc_handle, mmu_t *mmu, 10.86 - unsigned long ptr, unsigned long val) 10.87 +int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu, 10.88 + unsigned long ptr, unsigned long val) 10.89 { 10.90 mmu->updates[mmu->idx].ptr = ptr; 10.91 mmu->updates[mmu->idx].val = val; 10.92 @@ -167,11 +182,48 @@ int add_mmu_update(int xc_handle, mmu_t 10.93 return 0; 10.94 } 10.95 10.96 -int finish_mmu_updates(int xc_handle, mmu_t *mmu) 10.97 +int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu) 10.98 { 10.99 return flush_mmu_updates(xc_handle, mmu); 10.100 } 10.101 10.102 +int xc_dom_mem_op(int xc_handle, 10.103 + unsigned int memop, 10.104 + unsigned int *extent_list, 10.105 + unsigned int nr_extents, 10.106 + unsigned int extent_order, 10.107 + domid_t domid) 10.108 +{ 10.109 + privcmd_hypercall_t hypercall; 10.110 + long ret = -EINVAL; 10.111 + 10.112 + hypercall.op = __HYPERVISOR_dom_mem_op; 10.113 + hypercall.arg[0] = (unsigned long)memop; 10.114 + hypercall.arg[1] = (unsigned long)extent_list; 10.115 + hypercall.arg[2] = (unsigned long)nr_extents; 10.116 + hypercall.arg[3] = (unsigned long)extent_order; 10.117 + hypercall.arg[4] = (unsigned long)domid; 10.118 + 10.119 + if ( (extent_list != NULL) && 10.120 + (mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0) ) 10.121 + { 10.122 + PERROR("Could not lock memory for Xen hypercall"); 10.123 + goto out1; 10.124 + } 10.125 + 10.126 + if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 ) 10.127 + { 10.128 + fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to" 10.129 + " rebuild the user-space tool set?\n",ret,errno); 10.130 + } 10.131 + 10.132 + if ( extent_list != NULL ) 10.133 + safe_munlock(extent_list, nr_extents*sizeof(unsigned long)); 10.134 + 10.135 + out1: 10.136 + return ret; 10.137 +} 10.138 + 10.139 10.140 long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid, int vcpu ) 10.141 { 10.142 @@ -190,19 +242,6 @@ long long xc_domain_get_cpu_usage( int x 10.143 } 10.144 10.145 10.146 -/* This is shared between save and restore, and may generally be useful. */ 10.147 -unsigned long csum_page (void * page) 10.148 -{ 10.149 - int i; 10.150 - unsigned long *p = page; 10.151 - unsigned long long sum=0; 10.152 - 10.153 - for ( i = 0; i < (PAGE_SIZE/sizeof(unsigned long)); i++ ) 10.154 - sum += p[i]; 10.155 - 10.156 - return sum ^ (sum>>32); 10.157 -} 10.158 - 10.159 unsigned long xc_get_m2p_start_mfn ( int xc_handle ) 10.160 { 10.161 unsigned long mfn; 10.162 @@ -332,53 +371,6 @@ unsigned long xc_get_filesz(int fd) 10.163 return sz; 10.164 } 10.165 10.166 -char *xc_read_kernel_image(const char *filename, unsigned long *size) 10.167 -{ 10.168 - int kernel_fd = -1; 10.169 - gzFile kernel_gfd = NULL; 10.170 - char *image = NULL; 10.171 - unsigned int bytes; 10.172 - 10.173 - if ( (kernel_fd = open(filename, O_RDONLY)) < 0 ) 10.174 - { 10.175 - PERROR("Could not open kernel image"); 10.176 - goto out; 10.177 - } 10.178 - 10.179 - if ( (*size = xc_get_filesz(kernel_fd)) == 0 ) 10.180 - { 10.181 - PERROR("Could not read kernel image"); 10.182 - goto out; 10.183 - } 10.184 - 10.185 - if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL ) 10.186 - { 10.187 - PERROR("Could not allocate decompression state for state file"); 10.188 - goto out; 10.189 - } 10.190 - 10.191 - if ( (image = malloc(*size)) == NULL ) 10.192 - { 10.193 - PERROR("Could not allocate memory for kernel image"); 10.194 - goto out; 10.195 - } 10.196 - 10.197 - if ( (bytes = gzread(kernel_gfd, image, *size)) != *size ) 10.198 - { 10.199 - PERROR("Error reading kernel image, could not" 10.200 - " read the whole image (%d != %ld).", bytes, *size); 10.201 - free(image); 10.202 - image = NULL; 10.203 - } 10.204 - 10.205 - out: 10.206 - if ( kernel_gfd != NULL ) 10.207 - gzclose(kernel_gfd); 10.208 - else if ( kernel_fd >= 0 ) 10.209 - close(kernel_fd); 10.210 - return image; 10.211 -} 10.212 - 10.213 void xc_map_memcpy(unsigned long dst, char *src, unsigned long size, 10.214 int xch, u32 dom, unsigned long *parray, 10.215 unsigned long vstart)
11.1 --- a/tools/libxc/xc_private.h Wed Aug 24 23:07:29 2005 +0000 11.2 +++ b/tools/libxc/xc_private.h Thu Aug 25 00:51:20 2005 +0000 11.3 @@ -1,124 +1,26 @@ 11.4 11.5 -#ifndef __XC_PRIVATE_H__ 11.6 -#define __XC_PRIVATE_H__ 11.7 +#ifndef XC_PRIVATE_H 11.8 +#define XC_PRIVATE_H 11.9 11.10 #include <unistd.h> 11.11 #include <stdio.h> 11.12 #include <errno.h> 11.13 #include <fcntl.h> 11.14 +#include <string.h> 11.15 #include <sys/mman.h> 11.16 #include <sys/types.h> 11.17 #include <sys/stat.h> 11.18 #include <stdlib.h> 11.19 #include <sys/ioctl.h> 11.20 -#include <errno.h> 11.21 -#include <string.h> 11.22 11.23 #include "xenctrl.h" 11.24 11.25 #include <xen/linux/privcmd.h> 11.26 11.27 -#define _PAGE_PRESENT 0x001 11.28 -#define _PAGE_RW 0x002 11.29 -#define _PAGE_USER 0x004 11.30 -#define _PAGE_PWT 0x008 11.31 -#define _PAGE_PCD 0x010 11.32 -#define _PAGE_ACCESSED 0x020 11.33 -#define _PAGE_DIRTY 0x040 11.34 -#define _PAGE_PAT 0x080 11.35 -#define _PAGE_PSE 0x080 11.36 -#define _PAGE_GLOBAL 0x100 11.37 - 11.38 -#if defined(__i386__) 11.39 -#define L1_PAGETABLE_SHIFT 12 11.40 -#define L2_PAGETABLE_SHIFT 22 11.41 -#define L1_PAGETABLE_SHIFT_PAE 12 11.42 -#define L2_PAGETABLE_SHIFT_PAE 21 11.43 -#define L3_PAGETABLE_SHIFT_PAE 30 11.44 -#elif defined(__x86_64__) 11.45 -#define L1_PAGETABLE_SHIFT 12 11.46 -#define L2_PAGETABLE_SHIFT 21 11.47 -#define L3_PAGETABLE_SHIFT 30 11.48 -#define L4_PAGETABLE_SHIFT 39 11.49 -#endif 11.50 - 11.51 -#if defined(__i386__) 11.52 -#define ENTRIES_PER_L1_PAGETABLE 1024 11.53 -#define ENTRIES_PER_L2_PAGETABLE 1024 11.54 -#define L1_PAGETABLE_ENTRIES_PAE 512 11.55 -#define L2_PAGETABLE_ENTRIES_PAE 512 11.56 -#define L3_PAGETABLE_ENTRIES_PAE 4 11.57 -#elif defined(__x86_64__) 11.58 -#define L1_PAGETABLE_ENTRIES 512 11.59 -#define L2_PAGETABLE_ENTRIES 512 11.60 -#define L3_PAGETABLE_ENTRIES 512 11.61 -#define L4_PAGETABLE_ENTRIES 512 11.62 -#endif 11.63 - 11.64 #define PAGE_SHIFT XC_PAGE_SHIFT 11.65 #define PAGE_SIZE (1UL << PAGE_SHIFT) 11.66 #define PAGE_MASK (~(PAGE_SIZE-1)) 11.67 11.68 -typedef u32 l1_pgentry_32_t; 11.69 -typedef u32 l2_pgentry_32_t; 11.70 -typedef u64 l1_pgentry_64_t; 11.71 -typedef u64 l2_pgentry_64_t; 11.72 -typedef u64 l3_pgentry_64_t; 11.73 -typedef unsigned long l1_pgentry_t; 11.74 -typedef unsigned long l2_pgentry_t; 11.75 -#if defined(__x86_64__) 11.76 -typedef unsigned long l3_pgentry_t; 11.77 -typedef unsigned long l4_pgentry_t; 11.78 -#endif 11.79 - 11.80 -#if defined(__i386__) 11.81 -#define l1_table_offset(_a) \ 11.82 - (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1)) 11.83 -#define l2_table_offset(_a) \ 11.84 - ((_a) >> L2_PAGETABLE_SHIFT) 11.85 -#define l1_table_offset_pae(_a) \ 11.86 - (((_a) >> L1_PAGETABLE_SHIFT_PAE) & (L1_PAGETABLE_ENTRIES_PAE - 1)) 11.87 -#define l2_table_offset_pae(_a) \ 11.88 - (((_a) >> L2_PAGETABLE_SHIFT_PAE) & (L2_PAGETABLE_ENTRIES_PAE - 1)) 11.89 -#define l3_table_offset_pae(_a) \ 11.90 - (((_a) >> L3_PAGETABLE_SHIFT_PAE) & (L3_PAGETABLE_ENTRIES_PAE - 1)) 11.91 -#elif defined(__x86_64__) 11.92 -#define l1_table_offset(_a) \ 11.93 - (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1)) 11.94 -#define l2_table_offset(_a) \ 11.95 - (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1)) 11.96 -#define l3_table_offset(_a) \ 11.97 - (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1)) 11.98 -#define l4_table_offset(_a) \ 11.99 - (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1)) 11.100 -#endif 11.101 - 11.102 -struct domain_setup_info 11.103 -{ 11.104 - unsigned long v_start; 11.105 - unsigned long v_end; 11.106 - unsigned long v_kernstart; 11.107 - unsigned long v_kernend; 11.108 - unsigned long v_kernentry; 11.109 - 11.110 - unsigned int load_symtab; 11.111 - unsigned int pae_kernel; 11.112 - unsigned long symtab_addr; 11.113 - unsigned long symtab_len; 11.114 -}; 11.115 - 11.116 -typedef int (*parseimagefunc)(char *image, unsigned long image_size, 11.117 - struct domain_setup_info *dsi); 11.118 -typedef int (*loadimagefunc)(char *image, unsigned long image_size, int xch, 11.119 - u32 dom, unsigned long *parray, 11.120 - struct domain_setup_info *dsi); 11.121 - 11.122 -struct load_funcs 11.123 -{ 11.124 - parseimagefunc parseimage; 11.125 - loadimagefunc loadimage; 11.126 -}; 11.127 - 11.128 #define ERROR(_m, _a...) \ 11.129 do { \ 11.130 int __saved_errno = errno; \ 11.131 @@ -186,97 +88,6 @@ static inline int do_dom0_op(int xc_hand 11.132 return ret; 11.133 } 11.134 11.135 -static inline int do_dom_mem_op(int xc_handle, 11.136 - unsigned int memop, 11.137 - unsigned int *extent_list, 11.138 - unsigned int nr_extents, 11.139 - unsigned int extent_order, 11.140 - domid_t domid) 11.141 -{ 11.142 - privcmd_hypercall_t hypercall; 11.143 - long ret = -EINVAL; 11.144 - 11.145 - hypercall.op = __HYPERVISOR_dom_mem_op; 11.146 - hypercall.arg[0] = (unsigned long)memop; 11.147 - hypercall.arg[1] = (unsigned long)extent_list; 11.148 - hypercall.arg[2] = (unsigned long)nr_extents; 11.149 - hypercall.arg[3] = (unsigned long)extent_order; 11.150 - hypercall.arg[4] = (unsigned long)domid; 11.151 - 11.152 - if ( (extent_list != NULL) && 11.153 - (mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0) ) 11.154 - { 11.155 - PERROR("Could not lock memory for Xen hypercall"); 11.156 - goto out1; 11.157 - } 11.158 - 11.159 - if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 ) 11.160 - { 11.161 - fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to" 11.162 - " rebuild the user-space tool set?\n",ret,errno); 11.163 - } 11.164 - 11.165 - if ( extent_list != NULL ) 11.166 - safe_munlock(extent_list, nr_extents*sizeof(unsigned long)); 11.167 - 11.168 - out1: 11.169 - return ret; 11.170 -} 11.171 - 11.172 -static inline int do_mmuext_op( 11.173 - int xc_handle, 11.174 - struct mmuext_op *op, 11.175 - unsigned int nr_ops, 11.176 - domid_t dom) 11.177 -{ 11.178 - privcmd_hypercall_t hypercall; 11.179 - long ret = -EINVAL; 11.180 - 11.181 - hypercall.op = __HYPERVISOR_mmuext_op; 11.182 - hypercall.arg[0] = (unsigned long)op; 11.183 - hypercall.arg[1] = (unsigned long)nr_ops; 11.184 - hypercall.arg[2] = (unsigned long)0; 11.185 - hypercall.arg[3] = (unsigned long)dom; 11.186 - 11.187 - if ( mlock(op, nr_ops*sizeof(*op)) != 0 ) 11.188 - { 11.189 - PERROR("Could not lock memory for Xen hypercall"); 11.190 - goto out1; 11.191 - } 11.192 - 11.193 - if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 ) 11.194 - { 11.195 - fprintf(stderr, "Dom_mem operation failed (rc=%ld errno=%d)-- need to" 11.196 - " rebuild the user-space tool set?\n",ret,errno); 11.197 - } 11.198 - 11.199 - safe_munlock(op, nr_ops*sizeof(*op)); 11.200 - 11.201 - out1: 11.202 - return ret; 11.203 -} 11.204 - 11.205 - 11.206 -/* 11.207 - * PFN mapping. 11.208 - */ 11.209 -int get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr); 11.210 -unsigned long csum_page (void * page); 11.211 - 11.212 -/* 11.213 - * MMU updates. 11.214 - */ 11.215 -#define MAX_MMU_UPDATES 1024 11.216 -typedef struct { 11.217 - mmu_update_t updates[MAX_MMU_UPDATES]; 11.218 - int idx; 11.219 - domid_t subject; 11.220 -} mmu_t; 11.221 -mmu_t *init_mmu_updates(int xc_handle, domid_t dom); 11.222 -int add_mmu_update(int xc_handle, mmu_t *mmu, 11.223 - unsigned long ptr, unsigned long val); 11.224 -int finish_mmu_updates(int xc_handle, mmu_t *mmu); 11.225 - 11.226 11.227 /* 11.228 * ioctl-based mfn mapping interface 11.229 @@ -296,38 +107,4 @@ typedef struct privcmd_mmap { 11.230 } privcmd_mmap_t; 11.231 */ 11.232 11.233 -#define mfn_mapper_queue_size 128 11.234 - 11.235 -typedef struct mfn_mapper { 11.236 - int xc_handle; 11.237 - int size; 11.238 - int prot; 11.239 - int error; 11.240 - int max_queue_size; 11.241 - void * addr; 11.242 - privcmd_mmap_t ioctl; 11.243 - 11.244 -} mfn_mapper_t; 11.245 - 11.246 -unsigned long xc_get_m2p_start_mfn (int xc_handle); 11.247 - 11.248 -int xc_copy_to_domain_page(int xc_handle, u32 domid, 11.249 - unsigned long dst_pfn, void *src_page); 11.250 - 11.251 -unsigned long xc_get_filesz(int fd); 11.252 - 11.253 -char *xc_read_kernel_image(const char *filename, unsigned long *size); 11.254 - 11.255 -void xc_map_memcpy(unsigned long dst, char *src, unsigned long size, 11.256 - int xch, u32 dom, unsigned long *parray, 11.257 - unsigned long vstart); 11.258 - 11.259 -int pin_table(int xc_handle, unsigned int type, unsigned long mfn, 11.260 - domid_t dom); 11.261 - 11.262 -/* image loading */ 11.263 -int probe_elf(char *image, unsigned long image_size, struct load_funcs *funcs); 11.264 -int probe_bin(char *image, unsigned long image_size, struct load_funcs *funcs); 11.265 -int probe_aout9(char *image, unsigned long image_size, struct load_funcs *funcs); 11.266 - 11.267 #endif /* __XC_PRIVATE_H__ */
12.1 --- a/tools/libxc/xc_vmx_build.c Wed Aug 24 23:07:29 2005 +0000 12.2 +++ b/tools/libxc/xc_vmx_build.c Thu Aug 25 00:51:20 2005 +0000 12.3 @@ -3,7 +3,7 @@ 12.4 */ 12.5 12.6 #include <stddef.h> 12.7 -#include "xc_private.h" 12.8 +#include "xg_private.h" 12.9 #define ELFSIZE 32 12.10 #include "xc_elf.h" 12.11 #include <stdlib.h> 12.12 @@ -243,7 +243,7 @@ static int setup_guest(int xc_handle, 12.13 shared_info_t *shared_info; 12.14 struct linux_boot_params * boot_paramsp; 12.15 __u16 * boot_gdtp; 12.16 - mmu_t *mmu = NULL; 12.17 + xc_mmu_t *mmu = NULL; 12.18 int rc; 12.19 12.20 unsigned long nr_pt_pages; 12.21 @@ -358,7 +358,7 @@ static int setup_guest(int xc_handle, 12.22 } 12.23 } 12.24 12.25 - if ( (mmu = init_mmu_updates(xc_handle, dom)) == NULL ) 12.26 + if ( (mmu = xc_init_mmu_updates(xc_handle, dom)) == NULL ) 12.27 goto error_out; 12.28 12.29 #ifdef __i386__ 12.30 @@ -459,9 +459,9 @@ static int setup_guest(int xc_handle, 12.31 /* Write the machine->phys table entries. */ 12.32 for ( count = 0; count < nr_pages; count++ ) 12.33 { 12.34 - if ( add_mmu_update(xc_handle, mmu, 12.35 - (page_array[count] << PAGE_SHIFT) | 12.36 - MMU_MACHPHYS_UPDATE, count) ) 12.37 + if ( xc_add_mmu_update(xc_handle, mmu, 12.38 + (page_array[count] << PAGE_SHIFT) | 12.39 + MMU_MACHPHYS_UPDATE, count) ) 12.40 goto error_out; 12.41 } 12.42 12.43 @@ -587,7 +587,7 @@ static int setup_guest(int xc_handle, 12.44 #endif 12.45 12.46 /* Send the page update requests down to the hypervisor. */ 12.47 - if ( finish_mmu_updates(xc_handle, mmu) ) 12.48 + if ( xc_finish_mmu_updates(xc_handle, mmu) ) 12.49 goto error_out; 12.50 12.51 free(mmu); 12.52 @@ -708,7 +708,7 @@ int xc_vmx_build(int xc_handle, 12.53 12.54 op.cmd = DOM0_GETDOMAININFO; 12.55 op.u.getdomaininfo.domain = (domid_t)domid; 12.56 - if ( (do_dom0_op(xc_handle, &op) < 0) || 12.57 + if ( (xc_dom0_op(xc_handle, &op) < 0) || 12.58 ((u16)op.u.getdomaininfo.domain != domid) ) 12.59 { 12.60 PERROR("Could not get info on domain"); 12.61 @@ -789,7 +789,7 @@ int xc_vmx_build(int xc_handle, 12.62 launch_op.u.setdomaininfo.ctxt = ctxt; 12.63 12.64 launch_op.cmd = DOM0_SETDOMAININFO; 12.65 - rc = do_dom0_op(xc_handle, &launch_op); 12.66 + rc = xc_dom0_op(xc_handle, &launch_op); 12.67 12.68 return rc; 12.69
13.1 --- a/tools/libxc/xenctrl.h Wed Aug 24 23:07:29 2005 +0000 13.2 +++ b/tools/libxc/xenctrl.h Thu Aug 25 00:51:20 2005 +0000 13.3 @@ -6,8 +6,8 @@ 13.4 * Copyright (c) 2003-2004, K A Fraser. 13.5 */ 13.6 13.7 -#ifndef __XC_H__ 13.8 -#define __XC_H__ 13.9 +#ifndef XENCTRL_H 13.10 +#define XENCTRL_H 13.11 13.12 #include <stdint.h> 13.13 13.14 @@ -254,63 +254,6 @@ int xc_shadow_control(int xc_handle, 13.15 unsigned long pages, 13.16 xc_shadow_control_stats_t *stats); 13.17 13.18 - 13.19 -#define XCFLAGS_VERBOSE 1 13.20 -#define XCFLAGS_LIVE 2 13.21 -#define XCFLAGS_DEBUG 4 13.22 -#define XCFLAGS_CONFIGURE 8 13.23 - 13.24 -struct XcIOContext; 13.25 - 13.26 -/** 13.27 - * This function will save a domain running Linux. 13.28 - * 13.29 - * @parm xc_handle a handle to an open hypervisor interface 13.30 - * @parm fd the file descriptor to save a domain to 13.31 - * @parm dom the id of the domain 13.32 - * @return 0 on success, -1 on failure 13.33 - */ 13.34 -int xc_linux_save(int xc_handle, int fd, u32 dom); 13.35 - 13.36 -/** 13.37 - * This function will restore a saved domain running Linux. 13.38 - * 13.39 - * @parm xc_handle a handle to an open hypervisor interface 13.40 - * @parm fd the file descriptor to restore a domain from 13.41 - * @parm dom the id of the domain 13.42 - * @parm nr_pfns the number of pages 13.43 - * @parm store_evtchn the store event channel for this domain to use 13.44 - * @parm store_mfn returned with the mfn of the store page 13.45 - * @return 0 on success, -1 on failure 13.46 - */ 13.47 -int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns, 13.48 - unsigned int store_evtchn, unsigned long *store_mfn); 13.49 - 13.50 -int xc_linux_build(int xc_handle, 13.51 - u32 domid, 13.52 - const char *image_name, 13.53 - const char *ramdisk_name, 13.54 - const char *cmdline, 13.55 - unsigned int control_evtchn, 13.56 - unsigned long flags, 13.57 - unsigned int vcpus, 13.58 - unsigned int store_evtchn, 13.59 - unsigned long *store_mfn); 13.60 - 13.61 -struct mem_map; 13.62 -int xc_vmx_build(int xc_handle, 13.63 - u32 domid, 13.64 - int memsize, 13.65 - const char *image_name, 13.66 - struct mem_map *memmap, 13.67 - const char *ramdisk_name, 13.68 - const char *cmdline, 13.69 - unsigned int control_evtchn, 13.70 - unsigned long flags, 13.71 - unsigned int vcpus, 13.72 - unsigned int store_evtchn, 13.73 - unsigned long *store_mfn); 13.74 - 13.75 int xc_bvtsched_global_set(int xc_handle, 13.76 unsigned long ctx_allow); 13.77 13.78 @@ -484,6 +427,16 @@ int xc_get_pfn_list(int xc_handle, u32 d 13.79 int xc_ia64_get_pfn_list(int xc_handle, u32 domid, unsigned long *pfn_buf, 13.80 unsigned int start_page, unsigned int nr_pages); 13.81 13.82 +int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops, 13.83 + domid_t dom); 13.84 + 13.85 +int xc_dom_mem_op(int xc_handle, unsigned int memop, unsigned int *extent_list, 13.86 + unsigned int nr_extents, unsigned int extent_order, 13.87 + domid_t domid); 13.88 + 13.89 +int xc_get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr); 13.90 + 13.91 + 13.92 /*\ 13.93 * GRANT TABLE FUNCTIONS 13.94 \*/ 13.95 @@ -555,4 +508,19 @@ int xc_dom0_op(int xc_handle, dom0_op_t 13.96 */ 13.97 long xc_init_store(int xc_handle, int remote_port); 13.98 13.99 -#endif /* __XC_H__ */ 13.100 +/* 13.101 + * MMU updates. 13.102 + */ 13.103 +#define MAX_MMU_UPDATES 1024 13.104 +struct xc_mmu { 13.105 + mmu_update_t updates[MAX_MMU_UPDATES]; 13.106 + int idx; 13.107 + domid_t subject; 13.108 +}; 13.109 +typedef struct xc_mmu xc_mmu_t; 13.110 +xc_mmu_t *xc_init_mmu_updates(int xc_handle, domid_t dom); 13.111 +int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu, 13.112 + unsigned long ptr, unsigned long val); 13.113 +int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu); 13.114 + 13.115 +#endif
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/tools/libxc/xenguest.h Thu Aug 25 00:51:20 2005 +0000 14.3 @@ -0,0 +1,66 @@ 14.4 +/****************************************************************************** 14.5 + * xenguest.h 14.6 + * 14.7 + * A library for guest domain management in Xen. 14.8 + * 14.9 + * Copyright (c) 2003-2004, K A Fraser. 14.10 + */ 14.11 + 14.12 +#ifndef XENBUILD_H 14.13 +#define XENBUILD_H 14.14 + 14.15 +#define XCFLAGS_VERBOSE 1 14.16 +#define XCFLAGS_LIVE 2 14.17 +#define XCFLAGS_DEBUG 4 14.18 +#define XCFLAGS_CONFIGURE 8 14.19 + 14.20 +/** 14.21 + * This function will save a domain running Linux. 14.22 + * 14.23 + * @parm xc_handle a handle to an open hypervisor interface 14.24 + * @parm fd the file descriptor to save a domain to 14.25 + * @parm dom the id of the domain 14.26 + * @return 0 on success, -1 on failure 14.27 + */ 14.28 +int xc_linux_save(int xc_handle, int fd, uint32_t dom); 14.29 + 14.30 +/** 14.31 + * This function will restore a saved domain running Linux. 14.32 + * 14.33 + * @parm xc_handle a handle to an open hypervisor interface 14.34 + * @parm fd the file descriptor to restore a domain from 14.35 + * @parm dom the id of the domain 14.36 + * @parm nr_pfns the number of pages 14.37 + * @parm store_evtchn the store event channel for this domain to use 14.38 + * @parm store_mfn returned with the mfn of the store page 14.39 + * @return 0 on success, -1 on failure 14.40 + */ 14.41 +int xc_linux_restore(int xc_handle, int io_fd, uint32_t dom, unsigned long nr_pfns, 14.42 + unsigned int store_evtchn, unsigned long *store_mfn); 14.43 + 14.44 +int xc_linux_build(int xc_handle, 14.45 + uint32_t domid, 14.46 + const char *image_name, 14.47 + const char *ramdisk_name, 14.48 + const char *cmdline, 14.49 + unsigned int control_evtchn, 14.50 + unsigned long flags, 14.51 + unsigned int vcpus, 14.52 + unsigned int store_evtchn, 14.53 + unsigned long *store_mfn); 14.54 + 14.55 +struct mem_map; 14.56 +int xc_vmx_build(int xc_handle, 14.57 + uint32_t domid, 14.58 + int memsize, 14.59 + const char *image_name, 14.60 + struct mem_map *memmap, 14.61 + const char *ramdisk_name, 14.62 + const char *cmdline, 14.63 + unsigned int control_evtchn, 14.64 + unsigned long flags, 14.65 + unsigned int vcpus, 14.66 + unsigned int store_evtchn, 14.67 + unsigned long *store_mfn); 14.68 + 14.69 +#endif
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/tools/libxc/xg_private.c Thu Aug 25 00:51:20 2005 +0000 15.3 @@ -0,0 +1,86 @@ 15.4 +/****************************************************************************** 15.5 + * xg_private.c 15.6 + * 15.7 + * Helper functions for the rest of the library. 15.8 + */ 15.9 + 15.10 +#include <stdlib.h> 15.11 +#include <zlib.h> 15.12 + 15.13 +#include "xg_private.h" 15.14 + 15.15 +char *xc_read_kernel_image(const char *filename, unsigned long *size) 15.16 +{ 15.17 + int kernel_fd = -1; 15.18 + gzFile kernel_gfd = NULL; 15.19 + char *image = NULL; 15.20 + unsigned int bytes; 15.21 + 15.22 + if ( (kernel_fd = open(filename, O_RDONLY)) < 0 ) 15.23 + { 15.24 + PERROR("Could not open kernel image"); 15.25 + goto out; 15.26 + } 15.27 + 15.28 + if ( (*size = xc_get_filesz(kernel_fd)) == 0 ) 15.29 + { 15.30 + PERROR("Could not read kernel image"); 15.31 + goto out; 15.32 + } 15.33 + 15.34 + if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL ) 15.35 + { 15.36 + PERROR("Could not allocate decompression state for state file"); 15.37 + goto out; 15.38 + } 15.39 + 15.40 + if ( (image = malloc(*size)) == NULL ) 15.41 + { 15.42 + PERROR("Could not allocate memory for kernel image"); 15.43 + goto out; 15.44 + } 15.45 + 15.46 + if ( (bytes = gzread(kernel_gfd, image, *size)) != *size ) 15.47 + { 15.48 + PERROR("Error reading kernel image, could not" 15.49 + " read the whole image (%d != %ld).", bytes, *size); 15.50 + free(image); 15.51 + image = NULL; 15.52 + } 15.53 + 15.54 + out: 15.55 + if ( kernel_gfd != NULL ) 15.56 + gzclose(kernel_gfd); 15.57 + else if ( kernel_fd >= 0 ) 15.58 + close(kernel_fd); 15.59 + return image; 15.60 +} 15.61 + 15.62 +/*******************/ 15.63 + 15.64 +int pin_table( 15.65 + int xc_handle, unsigned int type, unsigned long mfn, domid_t dom) 15.66 +{ 15.67 + struct mmuext_op op; 15.68 + 15.69 + op.cmd = type; 15.70 + op.mfn = mfn; 15.71 + 15.72 + if ( xc_mmuext_op(xc_handle, &op, 1, dom) < 0 ) 15.73 + return 1; 15.74 + 15.75 + return 0; 15.76 +} 15.77 + 15.78 +/* This is shared between save and restore, and may generally be useful. */ 15.79 +unsigned long csum_page (void * page) 15.80 +{ 15.81 + int i; 15.82 + unsigned long *p = page; 15.83 + unsigned long long sum=0; 15.84 + 15.85 + for ( i = 0; i < (PAGE_SIZE/sizeof(unsigned long)); i++ ) 15.86 + sum += p[i]; 15.87 + 15.88 + return sum ^ (sum>>32); 15.89 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/tools/libxc/xg_private.h Thu Aug 25 00:51:20 2005 +0000 16.3 @@ -0,0 +1,170 @@ 16.4 +#ifndef XG_PRIVATE_H 16.5 +#define XG_PRIVATE_H 16.6 + 16.7 +#include <errno.h> 16.8 +#include <fcntl.h> 16.9 +#include <stdio.h> 16.10 +#include <string.h> 16.11 +#include <sys/mman.h> 16.12 +#include <sys/types.h> 16.13 +#include <sys/stat.h> 16.14 + 16.15 +#include "xenctrl.h" 16.16 + 16.17 +#include <xen/linux/privcmd.h> 16.18 + 16.19 +char *xc_read_kernel_image(const char *filename, unsigned long *size); 16.20 +unsigned long csum_page (void * page); 16.21 + 16.22 +#define _PAGE_PRESENT 0x001 16.23 +#define _PAGE_RW 0x002 16.24 +#define _PAGE_USER 0x004 16.25 +#define _PAGE_PWT 0x008 16.26 +#define _PAGE_PCD 0x010 16.27 +#define _PAGE_ACCESSED 0x020 16.28 +#define _PAGE_DIRTY 0x040 16.29 +#define _PAGE_PAT 0x080 16.30 +#define _PAGE_PSE 0x080 16.31 +#define _PAGE_GLOBAL 0x100 16.32 + 16.33 +#if defined(__i386__) 16.34 +#define L1_PAGETABLE_SHIFT 12 16.35 +#define L2_PAGETABLE_SHIFT 22 16.36 +#define L1_PAGETABLE_SHIFT_PAE 12 16.37 +#define L2_PAGETABLE_SHIFT_PAE 21 16.38 +#define L3_PAGETABLE_SHIFT_PAE 30 16.39 +#elif defined(__x86_64__) 16.40 +#define L1_PAGETABLE_SHIFT 12 16.41 +#define L2_PAGETABLE_SHIFT 21 16.42 +#define L3_PAGETABLE_SHIFT 30 16.43 +#define L4_PAGETABLE_SHIFT 39 16.44 +#endif 16.45 + 16.46 +#if defined(__i386__) 16.47 +#define ENTRIES_PER_L1_PAGETABLE 1024 16.48 +#define ENTRIES_PER_L2_PAGETABLE 1024 16.49 +#define L1_PAGETABLE_ENTRIES_PAE 512 16.50 +#define L2_PAGETABLE_ENTRIES_PAE 512 16.51 +#define L3_PAGETABLE_ENTRIES_PAE 4 16.52 +#elif defined(__x86_64__) 16.53 +#define L1_PAGETABLE_ENTRIES 512 16.54 +#define L2_PAGETABLE_ENTRIES 512 16.55 +#define L3_PAGETABLE_ENTRIES 512 16.56 +#define L4_PAGETABLE_ENTRIES 512 16.57 +#endif 16.58 + 16.59 +#define PAGE_SHIFT XC_PAGE_SHIFT 16.60 +#define PAGE_SIZE (1UL << PAGE_SHIFT) 16.61 +#define PAGE_MASK (~(PAGE_SIZE-1)) 16.62 + 16.63 +typedef u32 l1_pgentry_32_t; 16.64 +typedef u32 l2_pgentry_32_t; 16.65 +typedef u64 l1_pgentry_64_t; 16.66 +typedef u64 l2_pgentry_64_t; 16.67 +typedef u64 l3_pgentry_64_t; 16.68 +typedef unsigned long l1_pgentry_t; 16.69 +typedef unsigned long l2_pgentry_t; 16.70 +#if defined(__x86_64__) 16.71 +typedef unsigned long l3_pgentry_t; 16.72 +typedef unsigned long l4_pgentry_t; 16.73 +#endif 16.74 + 16.75 +#if defined(__i386__) 16.76 +#define l1_table_offset(_a) \ 16.77 + (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1)) 16.78 +#define l2_table_offset(_a) \ 16.79 + ((_a) >> L2_PAGETABLE_SHIFT) 16.80 +#define l1_table_offset_pae(_a) \ 16.81 + (((_a) >> L1_PAGETABLE_SHIFT_PAE) & (L1_PAGETABLE_ENTRIES_PAE - 1)) 16.82 +#define l2_table_offset_pae(_a) \ 16.83 + (((_a) >> L2_PAGETABLE_SHIFT_PAE) & (L2_PAGETABLE_ENTRIES_PAE - 1)) 16.84 +#define l3_table_offset_pae(_a) \ 16.85 + (((_a) >> L3_PAGETABLE_SHIFT_PAE) & (L3_PAGETABLE_ENTRIES_PAE - 1)) 16.86 +#elif defined(__x86_64__) 16.87 +#define l1_table_offset(_a) \ 16.88 + (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1)) 16.89 +#define l2_table_offset(_a) \ 16.90 + (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1)) 16.91 +#define l3_table_offset(_a) \ 16.92 + (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1)) 16.93 +#define l4_table_offset(_a) \ 16.94 + (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1)) 16.95 +#endif 16.96 + 16.97 +#define ERROR(_m, _a...) \ 16.98 +do { \ 16.99 + int __saved_errno = errno; \ 16.100 + fprintf(stderr, "ERROR: " _m "\n" , ## _a ); \ 16.101 + errno = __saved_errno; \ 16.102 +} while (0) 16.103 + 16.104 + 16.105 +#define PERROR(_m, _a...) \ 16.106 +do { \ 16.107 + int __saved_errno = errno; \ 16.108 + fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \ 16.109 + __saved_errno, strerror(__saved_errno)); \ 16.110 + errno = __saved_errno; \ 16.111 +} while (0) 16.112 + 16.113 + 16.114 +struct domain_setup_info 16.115 +{ 16.116 + unsigned long v_start; 16.117 + unsigned long v_end; 16.118 + unsigned long v_kernstart; 16.119 + unsigned long v_kernend; 16.120 + unsigned long v_kernentry; 16.121 + 16.122 + unsigned int load_symtab; 16.123 + unsigned int pae_kernel; 16.124 + unsigned long symtab_addr; 16.125 + unsigned long symtab_len; 16.126 +}; 16.127 + 16.128 +typedef int (*parseimagefunc)(char *image, unsigned long image_size, 16.129 + struct domain_setup_info *dsi); 16.130 +typedef int (*loadimagefunc)(char *image, unsigned long image_size, int xch, 16.131 + u32 dom, unsigned long *parray, 16.132 + struct domain_setup_info *dsi); 16.133 + 16.134 +struct load_funcs 16.135 +{ 16.136 + parseimagefunc parseimage; 16.137 + loadimagefunc loadimage; 16.138 +}; 16.139 + 16.140 +#define mfn_mapper_queue_size 128 16.141 + 16.142 +typedef struct mfn_mapper { 16.143 + int xc_handle; 16.144 + int size; 16.145 + int prot; 16.146 + int error; 16.147 + int max_queue_size; 16.148 + void * addr; 16.149 + privcmd_mmap_t ioctl; 16.150 + 16.151 +} mfn_mapper_t; 16.152 + 16.153 +unsigned long xc_get_m2p_start_mfn (int xc_handle); 16.154 + 16.155 +int xc_copy_to_domain_page(int xc_handle, u32 domid, 16.156 + unsigned long dst_pfn, void *src_page); 16.157 + 16.158 +unsigned long xc_get_filesz(int fd); 16.159 + 16.160 +void xc_map_memcpy(unsigned long dst, char *src, unsigned long size, 16.161 + int xch, u32 dom, unsigned long *parray, 16.162 + unsigned long vstart); 16.163 + 16.164 +int pin_table(int xc_handle, unsigned int type, unsigned long mfn, 16.165 + domid_t dom); 16.166 + 16.167 +/* image loading */ 16.168 +int probe_elf(char *image, unsigned long image_size, struct load_funcs *funcs); 16.169 +int probe_bin(char *image, unsigned long image_size, struct load_funcs *funcs); 16.170 +int probe_aout9(char *image, unsigned long image_size, struct load_funcs *funcs); 16.171 + 16.172 +#endif 16.173 +
17.1 --- a/tools/python/setup.py Wed Aug 24 23:07:29 2005 +0000 17.2 +++ b/tools/python/setup.py Thu Aug 25 00:51:20 2005 +0000 17.3 @@ -17,7 +17,7 @@ library_dirs = [ XEN_ROOT + "/tools/libx 17.4 XEN_ROOT + "/tools/xenstore", 17.5 ] 17.6 17.7 -libraries = [ "xenctrl", "xenstore" ] 17.8 +libraries = [ "xenctrl", "xenguest", "xenstore" ] 17.9 17.10 xc = Extension("xc", 17.11 extra_compile_args = extra_compile_args,
18.1 --- a/tools/python/xen/lowlevel/xc/xc.c Wed Aug 24 23:07:29 2005 +0000 18.2 +++ b/tools/python/xen/lowlevel/xc/xc.c Thu Aug 25 00:51:20 2005 +0000 18.3 @@ -6,6 +6,7 @@ 18.4 18.5 #include <Python.h> 18.6 #include <xenctrl.h> 18.7 +#include <xenguest.h> 18.8 #include <zlib.h> 18.9 #include <fcntl.h> 18.10 #include <netinet/in.h>
19.1 --- a/tools/xcutils/Makefile Wed Aug 24 23:07:29 2005 +0000 19.2 +++ b/tools/xcutils/Makefile Thu Aug 25 00:51:20 2005 +0000 19.3 @@ -30,7 +30,7 @@ PROG_DEP = .*.d 19.4 19.5 PROGRAMS = xc_restore xc_save 19.6 19.7 -LDLIBS = -L$(XEN_LIBXC) -lxenctrl 19.8 +LDLIBS = -L$(XEN_LIBXC) -lxenguest -lxenctrl 19.9 19.10 .PHONY: all 19.11 all: build
20.1 --- a/tools/xcutils/xc_restore.c Wed Aug 24 23:07:29 2005 +0000 20.2 +++ b/tools/xcutils/xc_restore.c Thu Aug 25 00:51:20 2005 +0000 20.3 @@ -7,11 +7,12 @@ 20.4 * 20.5 */ 20.6 20.7 +#include <err.h> 20.8 #include <stdlib.h> 20.9 +#include <stdint.h> 20.10 #include <stdio.h> 20.11 -#include <err.h> 20.12 20.13 -#include <xenctrl.h> 20.14 +#include <xenguest.h> 20.15 20.16 int 20.17 main(int argc, char **argv)
21.1 --- a/tools/xcutils/xc_save.c Wed Aug 24 23:07:29 2005 +0000 21.2 +++ b/tools/xcutils/xc_save.c Thu Aug 25 00:51:20 2005 +0000 21.3 @@ -7,11 +7,12 @@ 21.4 * 21.5 */ 21.6 21.7 +#include <err.h> 21.8 #include <stdlib.h> 21.9 +#include <stdint.h> 21.10 #include <stdio.h> 21.11 -#include <err.h> 21.12 21.13 -#include <xenctrl.h> 21.14 +#include <xenguest.h> 21.15 21.16 int 21.17 main(int argc, char **argv)