direct-io.hg

changeset 3439:657d51f27c5b

bitkeeper revision 1.1159.1.532 (41e7bad3xQvdSTsIv4OVSCPYy_m2JA)

Merge tempest.cl.cam.ac.uk:/auto/groups/xeno-xenod/BK/xeno.bk
into tempest.cl.cam.ac.uk:/local/scratch/smh22/xen-unstable.bk
author smh22@tempest.cl.cam.ac.uk
date Fri Jan 14 12:28:03 2005 +0000 (2005-01-14)
parents 10e3000a78b4 0002ff9aa407
children cee684f223ee
files .rootkeys tools/examples/Makefile tools/examples/network-route tools/examples/vif-route tools/examples/xend-config.sxp 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 tools/python/xen/xm/create.py xen/common/dom0_ops.c xen/common/string.c xen/include/public/xen.h xen/include/xen/irq.h xen/include/xen/list.h
line diff
     1.1 --- a/.rootkeys	Thu Jan 13 10:05:14 2005 +0000
     1.2 +++ b/.rootkeys	Fri Jan 14 12:28:03 2005 +0000
     1.3 @@ -325,7 +325,9 @@ 405ff55dawQyCHFEnJ067ChPRoXBBA tools/exa
     1.4  40278d94cIUWl2eRgnwZtr4hTyWT1Q tools/examples/init.d/xendomains
     1.5  41dde8afTUuvdtFUlOx0ZRusKxyd8w tools/examples/mem-map.sxp
     1.6  40ee75a9xFz6S05sDKu-JCLqyVTkDA tools/examples/network
     1.7 +41e661e1giIEKbJ25qfiP-ke8u8hFA tools/examples/network-route
     1.8  40ee75a967sxgcRY4Q7zXoVUaJ4flA tools/examples/vif-bridge
     1.9 +41e661e1ooiRKlOfwumG6wwzc0PdhQ tools/examples/vif-route
    1.10  40ee75a93cqxHp6MiYXxxwR5j2_8QQ tools/examples/xend-config.sxp
    1.11  41dde8af6M2Pm1Rrv_f5jEFC_BIOIA tools/examples/xmexample.vmx
    1.12  41090ec8Pj_bkgCBpg2W7WfmNkumEA tools/examples/xmexample1
     2.1 --- a/tools/examples/Makefile	Thu Jan 13 10:05:14 2005 +0000
     2.2 +++ b/tools/examples/Makefile	Fri Jan 14 12:28:03 2005 +0000
     2.3 @@ -14,8 +14,8 @@ XEN_CONFIGS += bochsrc
     2.4  
     2.5  # Xen script dir and scripts to go there.
     2.6  XEN_SCRIPT_DIR = /etc/xen/scripts
     2.7 -XEN_SCRIPTS = network
     2.8 -XEN_SCRIPTS += vif-bridge
     2.9 +XEN_SCRIPTS = network vif-bridge
    2.10 +XEN_SCRIPTS += network-route vif-route
    2.11  XEN_SCRIPTS += block-file
    2.12  XEN_SCRIPTS += block-enbd
    2.13  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/examples/network-route	Fri Jan 14 12:28:03 2005 +0000
     3.3 @@ -0,0 +1,19 @@
     3.4 +#!/bin/sh
     3.5 +#============================================================================
     3.6 +# Default Xen network start/stop script.
     3.7 +# Xend calls a network script when it starts.
     3.8 +# The script name to use is defined in /etc/xen/xend-config.sxp
     3.9 +# in the network-script field.
    3.10 +#
    3.11 +# Usage:
    3.12 +#
    3.13 +# network-route (start|stop|status) {VAR=VAL}*
    3.14 +#
    3.15 +# Vars:
    3.16 +#
    3.17 +# netdev     The gateway interface (default eth0).
    3.18 +# antispoof  Whether to use iptables to prevent spoofing (default yes).
    3.19 +#
    3.20 +#============================================================================
    3.21 +
    3.22 +echo 1 >/proc/sys/net/ipv4/ip_forward
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/examples/vif-route	Fri Jan 14 12:28:03 2005 +0000
     4.3 @@ -0,0 +1,76 @@
     4.4 +#!/bin/sh
     4.5 +#============================================================================
     4.6 +# /etc/xen/vif-route
     4.7 +#
     4.8 +# Script for configuring a vif in routed mode.
     4.9 +# Xend calls a vif script when bringing a vif up or down.
    4.10 +# This script is the default - but it can be configured for each vif.
    4.11 +#
    4.12 +# Example invocation:
    4.13 +#
    4.14 +# vif-route up domain=VM1 vif=vif1.0 ip="128.232.38.45/28 10.10.10.55/24"
    4.15 +#
    4.16 +# Usage:
    4.17 +# vif-route (up|down) {VAR=VAL}*
    4.18 +#
    4.19 +# Vars:
    4.20 +#
    4.21 +# domain  name of the domain the interface is on (required).
    4.22 +# vif     vif interface name (required).
    4.23 +# mac     vif MAC address (required).
    4.24 +# ip      list of IP networks for the vif, space-separated (optional).
    4.25 +#============================================================================
    4.26 +
    4.27 +# Exit if anything goes wrong
    4.28 +set -e 
    4.29 +
    4.30 +echo "vif-route $*"
    4.31 +
    4.32 +# Operation name.
    4.33 +OP=$1
    4.34 +shift
    4.35 +
    4.36 +# Pull variables in args into environment
    4.37 +for arg ; do export "${arg}" ; done
    4.38 +
    4.39 +# Required parameters. Fail if not set.
    4.40 +domain=${domain:?}
    4.41 +vif=${vif:?}
    4.42 +mac=${mac:?}
    4.43 +
    4.44 +# Optional parameters. Set defaults.
    4.45 +ip=${ip:-''}   # default to null (do nothing)
    4.46 +
    4.47 +main_ip=`ifconfig eth0 | grep "inet addr:" | sed -e 's/.*inet addr:\(\w\w*\.\w\w*\.\w\w*\.\w\w*\).*/\1/'`
    4.48 +
    4.49 +# Are we going up or down?
    4.50 +case $OP in
    4.51 +    up)
    4.52 +        ifconfig ${vif} 169.254.1.0 netmask 255.255.255.255 up
    4.53 +        echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
    4.54 +        iptcmd='-A'
    4.55 +        ipcmd='a'
    4.56 +        ;;
    4.57 +    down)
    4.58 +        ifconfig ${vif} down
    4.59 +        iptcmd='-D'
    4.60 +        ipcmd='d'
    4.61 +        ;;
    4.62 +    *)
    4.63 +        echo 'Invalid command: ' $OP
    4.64 +        echo 'Valid commands are: up, down'
    4.65 +        exit 1
    4.66 +        ;;
    4.67 +esac
    4.68 +
    4.69 +if [ ${ip} ] ; then
    4.70 +
    4.71 +    # If we've been given a list of IP networks, allow pkts with these src addrs.
    4.72 +    for addr in ${ip} ; do
    4.73 +      ip r ${ipcmd} ${addr} dev ${vif} src ${main_ip}
    4.74 +#      iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -s ${addr} -j ACCEPT
    4.75 +    done 
    4.76 +
    4.77 +    # Always allow us to talk to a DHCP server anyhow.
    4.78 +#    iptables ${iptcmd} FORWARD -m physdev --physdev-in ${vif} -p udp --sport 68 --dport 67 -j ACCEPT
    4.79 +fi
     5.1 --- a/tools/examples/xend-config.sxp	Thu Jan 13 10:05:14 2005 +0000
     5.2 +++ b/tools/examples/xend-config.sxp	Fri Jan 14 12:28:03 2005 +0000
     5.3 @@ -8,12 +8,17 @@
     5.4  # Specifying the empty string '' allows all connections.
     5.5  (xend-address      '')
     5.6  
     5.7 +## Use the following if VIF traffic is routed.
     5.8 +# The script used to start/stop networking for xend.
     5.9 +#(network-script     network-route)
    5.10 +# The default script used to control virtual interfaces.
    5.11 +#(vif-script         vif-route)
    5.12 +
    5.13 +## Use the following if VIF traffic is bridged.
    5.14  # The script used to start/stop networking for xend.
    5.15  (network-script    network)
    5.16 -
    5.17  # The default bridge that virtual interfaces should be connected to.
    5.18  (vif-bridge        xen-br0)
    5.19 -
    5.20  # The default script used to control virtual interfaces.
    5.21  (vif-script        vif-bridge)
    5.22  
     6.1 --- a/tools/libxc/Makefile	Thu Jan 13 10:05:14 2005 +0000
     6.2 +++ b/tools/libxc/Makefile	Fri Jan 14 12:28:03 2005 +0000
     6.3 @@ -71,7 +71,7 @@ install: all
     6.4  	install -m0644 xc.h $(prefix)/usr/include
     6.5  
     6.6  clean:
     6.7 -	rm -rf *.a *.so *.o *.rpm $(LIB) *~ $(DEPS) xen
     6.8 +	rm -rf *.a *.so *.o *.rpm $(LIB) *~ $(DEPS) xen TAGS
     6.9  
    6.10  rpm: all
    6.11  	rm -rf staging
    6.12 @@ -89,4 +89,8 @@ libxc.so.$(MAJOR):
    6.13  libxc.so.$(MAJOR).$(MINOR): $(OBJS)
    6.14  	$(CC) -Wl,-soname -Wl,$(SONAME) -shared -o $@ $^ -L../libxutil -lxutil -lz
    6.15  
    6.16 +.PHONY: TAGS clean install mk-symlinks rpm
    6.17 +TAGS:
    6.18 +	etags -t $(SRCS) *.h
    6.19 +
    6.20  -include $(DEPS)
     7.1 --- a/tools/libxc/xc.h	Thu Jan 13 10:05:14 2005 +0000
     7.2 +++ b/tools/libxc/xc.h	Fri Jan 14 12:28:03 2005 +0000
     7.3 @@ -62,13 +62,15 @@ int xc_domain_getinfo(int xc_handle,
     7.4                        xc_dominfo_t *info);
     7.5  int xc_domain_getfullinfo(int xc_handle,
     7.6                            u32 domid,
     7.7 +                          u32 vcpu,
     7.8                            xc_domaininfo_t *info,
     7.9                            full_execution_context_t *ctxt);
    7.10  int xc_domain_setcpuweight(int xc_handle,
    7.11                             u32 domid,
    7.12                             float weight);
    7.13  long long xc_domain_get_cpu_usage(int xc_handle,
    7.14 -                                  domid_t domid);
    7.15 +                                  domid_t domid,
    7.16 +                                  int vcpu);
    7.17  
    7.18  
    7.19  typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
     8.1 --- a/tools/libxc/xc_domain.c	Thu Jan 13 10:05:14 2005 +0000
     8.2 +++ b/tools/libxc/xc_domain.c	Fri Jan 14 12:28:03 2005 +0000
     8.3 @@ -88,6 +88,7 @@ int xc_domain_getinfo(int xc_handle,
     8.4      {
     8.5          op.cmd = DOM0_GETDOMAININFO;
     8.6          op.u.getdomaininfo.domain = (domid_t)next_domid;
     8.7 +        op.u.getdomaininfo.exec_domain = 0; // FIX ME?!?
     8.8          op.u.getdomaininfo.ctxt = NULL; /* no exec context info, thanks. */
     8.9          if ( do_dom0_op(xc_handle, &op) < 0 )
    8.10              break;
    8.11 @@ -121,6 +122,7 @@ int xc_domain_getinfo(int xc_handle,
    8.12  
    8.13  int xc_domain_getfullinfo(int xc_handle,
    8.14                            u32 domid,
    8.15 +                          u32 vcpu,
    8.16                            xc_domaininfo_t *info,
    8.17                            full_execution_context_t *ctxt)
    8.18  {
    8.19 @@ -129,6 +131,7 @@ int xc_domain_getfullinfo(int xc_handle,
    8.20  
    8.21      op.cmd = DOM0_GETDOMAININFO;
    8.22      op.u.getdomaininfo.domain = (domid_t)domid;
    8.23 +    op.u.getdomaininfo.exec_domain = (u16)vcpu;
    8.24      op.u.getdomaininfo.ctxt = ctxt;
    8.25  
    8.26      rc = do_dom0_op(xc_handle, &op);
     9.1 --- a/tools/libxc/xc_linux_build.c	Thu Jan 13 10:05:14 2005 +0000
     9.2 +++ b/tools/libxc/xc_linux_build.c	Fri Jan 14 12:28:03 2005 +0000
     9.3 @@ -41,52 +41,6 @@ loadelfsymtab(
     9.4      char *elfbase, int xch, u32 dom, unsigned long *parray,
     9.5      struct domain_setup_info *dsi);
     9.6  
     9.7 -static long get_tot_pages(int xc_handle, u32 domid)
     9.8 -{
     9.9 -    dom0_op_t op;
    9.10 -    op.cmd = DOM0_GETDOMAININFO;
    9.11 -    op.u.getdomaininfo.domain = (domid_t)domid;
    9.12 -    op.u.getdomaininfo.ctxt = NULL;
    9.13 -    return (do_dom0_op(xc_handle, &op) < 0) ? 
    9.14 -        -1 : op.u.getdomaininfo.tot_pages;
    9.15 -}
    9.16 -
    9.17 -static int get_pfn_list(int xc_handle,
    9.18 -                        u32 domid, 
    9.19 -                        unsigned long *pfn_buf, 
    9.20 -                        unsigned long max_pfns)
    9.21 -{
    9.22 -    dom0_op_t op;
    9.23 -    int ret;
    9.24 -    op.cmd = DOM0_GETMEMLIST;
    9.25 -    op.u.getmemlist.domain   = (domid_t)domid;
    9.26 -    op.u.getmemlist.max_pfns = max_pfns;
    9.27 -    op.u.getmemlist.buffer   = pfn_buf;
    9.28 -
    9.29 -    if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 )
    9.30 -        return -1;
    9.31 -
    9.32 -    ret = do_dom0_op(xc_handle, &op);
    9.33 -
    9.34 -    (void)munlock(pfn_buf, max_pfns * sizeof(unsigned long));
    9.35 -
    9.36 -    return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
    9.37 -}
    9.38 -
    9.39 -static int copy_to_domain_page(int xc_handle,
    9.40 -                               u32 domid,
    9.41 -                               unsigned long dst_pfn, 
    9.42 -                               void *src_page)
    9.43 -{
    9.44 -    void *vaddr = xc_map_foreign_range(
    9.45 -        xc_handle, domid, PAGE_SIZE, PROT_WRITE, dst_pfn);
    9.46 -    if ( vaddr == NULL )
    9.47 -        return -1;
    9.48 -    memcpy(vaddr, src_page, PAGE_SIZE);
    9.49 -    munmap(vaddr, PAGE_SIZE);
    9.50 -    return 0;
    9.51 -}
    9.52 -
    9.53  static int setup_guestos(int xc_handle,
    9.54                           u32 dom,
    9.55                           char *image, unsigned long image_size,
    9.56 @@ -206,7 +160,7 @@ static int setup_guestos(int xc_handle,
    9.57          goto error_out;
    9.58      }
    9.59  
    9.60 -    if ( get_pfn_list(xc_handle, dom, page_array, nr_pages) != nr_pages )
    9.61 +    if ( xc_get_pfn_list(xc_handle, dom, page_array, nr_pages) != nr_pages )
    9.62      {
    9.63          PERROR("Could not get the page frame list");
    9.64          goto error_out;
    9.65 @@ -229,7 +183,7 @@ static int setup_guestos(int xc_handle,
    9.66                  PERROR("Error reading initrd image, could not");
    9.67                  goto error_out;
    9.68              }
    9.69 -            copy_to_domain_page(xc_handle, dom,
    9.70 +            xc_copy_to_domain_page(xc_handle, dom,
    9.71                                  page_array[i>>PAGE_SHIFT], page);
    9.72          }
    9.73      }
    9.74 @@ -364,69 +318,6 @@ static int setup_guestos(int xc_handle,
    9.75      return -1;
    9.76  }
    9.77  
    9.78 -static unsigned long get_filesz(int fd)
    9.79 -{
    9.80 -    u16 sig;
    9.81 -    u32 _sz = 0;
    9.82 -    unsigned long sz;
    9.83 -
    9.84 -    lseek(fd, 0, SEEK_SET);
    9.85 -    read(fd, &sig, sizeof(sig));
    9.86 -    sz = lseek(fd, 0, SEEK_END);
    9.87 -    if ( sig == 0x8b1f ) /* GZIP signature? */
    9.88 -    {
    9.89 -        lseek(fd, -4, SEEK_END);
    9.90 -        read(fd, &_sz, 4);
    9.91 -        sz = _sz;
    9.92 -    }
    9.93 -    lseek(fd, 0, SEEK_SET);
    9.94 -
    9.95 -    return sz;
    9.96 -}
    9.97 -
    9.98 -static char *read_kernel_image(const char *filename, unsigned long *size)
    9.99 -{
   9.100 -    int kernel_fd = -1;
   9.101 -    gzFile kernel_gfd = NULL;
   9.102 -    char *image = NULL;
   9.103 -    unsigned int bytes;
   9.104 -
   9.105 -    if ( (kernel_fd = open(filename, O_RDONLY)) < 0 )
   9.106 -    {
   9.107 -        PERROR("Could not open kernel image");
   9.108 -        goto out;
   9.109 -    }
   9.110 -
   9.111 -    *size = get_filesz(kernel_fd);
   9.112 -
   9.113 -    if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
   9.114 -    {
   9.115 -        PERROR("Could not allocate decompression state for state file");
   9.116 -        goto out;
   9.117 -    }
   9.118 -
   9.119 -    if ( (image = malloc(*size)) == NULL )
   9.120 -    {
   9.121 -        PERROR("Could not allocate memory for kernel image");
   9.122 -        goto out;
   9.123 -    }
   9.124 -
   9.125 -    if ( (bytes = gzread(kernel_gfd, image, *size)) != *size )
   9.126 -    {
   9.127 -        PERROR("Error reading kernel image, could not"
   9.128 -               " read the whole image (%d != %ld).", bytes, *size);
   9.129 -        free(image);
   9.130 -        image = NULL;
   9.131 -    }
   9.132 -
   9.133 - out:
   9.134 -    if ( kernel_gfd != NULL )
   9.135 -        gzclose(kernel_gfd);
   9.136 -    else if ( kernel_fd >= 0 )
   9.137 -        close(kernel_fd);
   9.138 -    return image;
   9.139 -}
   9.140 -
   9.141  int xc_linux_build(int xc_handle,
   9.142                     u32 domid,
   9.143                     const char *image_name,
   9.144 @@ -445,13 +336,13 @@ int xc_linux_build(int xc_handle,
   9.145      unsigned long image_size, initrd_size=0;
   9.146      unsigned long vstartinfo_start, vkern_entry;
   9.147  
   9.148 -    if ( (nr_pages = get_tot_pages(xc_handle, domid)) < 0 )
   9.149 +    if ( (nr_pages = xc_get_tot_pages(xc_handle, domid)) < 0 )
   9.150      {
   9.151          PERROR("Could not find total pages for domain");
   9.152          goto error_out;
   9.153      }
   9.154  
   9.155 -    if ( (image = read_kernel_image(image_name, &image_size)) == NULL )
   9.156 +    if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL )
   9.157          goto error_out;
   9.158  
   9.159      if ( (ramdisk_name != NULL) && (strlen(ramdisk_name) != 0) )
   9.160 @@ -462,7 +353,7 @@ int xc_linux_build(int xc_handle,
   9.161              goto error_out;
   9.162          }
   9.163  
   9.164 -        initrd_size = get_filesz(initrd_fd);
   9.165 +        initrd_size = xc_get_filesz(initrd_fd);
   9.166  
   9.167          if ( (initrd_gfd = gzdopen(initrd_fd, "rb")) == NULL )
   9.168          {
   9.169 @@ -479,6 +370,7 @@ int xc_linux_build(int xc_handle,
   9.170  
   9.171      op.cmd = DOM0_GETDOMAININFO;
   9.172      op.u.getdomaininfo.domain = (domid_t)domid;
   9.173 +    op.u.getdomaininfo.exec_domain = 0;
   9.174      op.u.getdomaininfo.ctxt = ctxt;
   9.175      if ( (do_dom0_op(xc_handle, &op) < 0) || 
   9.176           ((u16)op.u.getdomaininfo.domain != domid) )
   9.177 @@ -747,27 +639,6 @@ loadelfimage(
   9.178      return 0;
   9.179  }
   9.180  
   9.181 -static void
   9.182 -map_memcpy(
   9.183 -    unsigned long dst, char *src, unsigned long size,
   9.184 -    int xch, u32 dom, unsigned long *parray, unsigned long vstart)
   9.185 -{
   9.186 -    char *va;
   9.187 -    unsigned long chunksz, done, pa;
   9.188 -
   9.189 -    for ( done = 0; done < size; done += chunksz )
   9.190 -    {
   9.191 -        pa = dst + done - vstart;
   9.192 -        va = xc_map_foreign_range(
   9.193 -            xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]);
   9.194 -        chunksz = size - done;
   9.195 -        if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
   9.196 -            chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
   9.197 -        memcpy(va + (pa & (PAGE_SIZE-1)), src + done, chunksz);
   9.198 -        munmap(va, PAGE_SIZE);
   9.199 -    }
   9.200 -}
   9.201 -
   9.202  #define ELFROUND (ELFSIZE / 8)
   9.203  
   9.204  static int
   9.205 @@ -818,7 +689,7 @@ loadelfsymtab(
   9.206               (shdr[h].sh_type == SHT_SYMTAB) )
   9.207          {
   9.208              if ( parray != NULL )
   9.209 -                map_memcpy(maxva, elfbase + shdr[h].sh_offset, shdr[h].sh_size,
   9.210 +                xc_map_memcpy(maxva, elfbase + shdr[h].sh_offset, shdr[h].sh_size,
   9.211                             xch, dom, parray, dsi->v_start);
   9.212  
   9.213              /* Mangled to be based on ELF header location. */
   9.214 @@ -850,7 +721,7 @@ loadelfsymtab(
   9.215          sym_ehdr->e_shstrndx = SHN_UNDEF;
   9.216  
   9.217          /* Copy total length, crafted ELF header and section header table */
   9.218 -        map_memcpy(symva, p, sizeof(int) + sizeof(Elf_Ehdr) +
   9.219 +        xc_map_memcpy(symva, p, sizeof(int) + sizeof(Elf_Ehdr) +
   9.220                     ehdr->e_shnum * sizeof(Elf_Shdr), xch, dom, parray,
   9.221                     dsi->v_start);
   9.222      }
    10.1 --- a/tools/libxc/xc_linux_restore.c	Thu Jan 13 10:05:14 2005 +0000
    10.2 +++ b/tools/libxc/xc_linux_restore.c	Fri Jan 14 12:28:03 2005 +0000
    10.3 @@ -19,31 +19,6 @@
    10.4  #define DPRINTF(_f, _a...) ((void)0)
    10.5  #endif
    10.6  
    10.7 -static int get_pfn_list(int xc_handle,
    10.8 -                        u32 domain_id, 
    10.9 -                        unsigned long *pfn_buf, 
   10.10 -                        unsigned long max_pfns)
   10.11 -{
   10.12 -    dom0_op_t op;
   10.13 -    int ret;
   10.14 -    op.cmd = DOM0_GETMEMLIST;
   10.15 -    op.u.getmemlist.domain   = (domid_t)domain_id;
   10.16 -    op.u.getmemlist.max_pfns = max_pfns;
   10.17 -    op.u.getmemlist.buffer   = pfn_buf;
   10.18 -
   10.19 -    if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 )
   10.20 -    {
   10.21 -        PERROR("Could not lock pfn list buffer");
   10.22 -        return -1;
   10.23 -    }    
   10.24 -
   10.25 -    ret = do_dom0_op(xc_handle, &op);
   10.26 -
   10.27 -    (void)munlock(pfn_buf, max_pfns * sizeof(unsigned long));
   10.28 -
   10.29 -    return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
   10.30 -}
   10.31 -
   10.32  /** Read the vmconfig string from the state input.
   10.33   * It is stored as a 4-byte count 'n' followed by n bytes.
   10.34   * The config data is stored in a new string in 'ioctxt->vmconfig',
   10.35 @@ -202,6 +177,7 @@ int xc_linux_restore(int xc_handle, XcIO
   10.36      /* Get the domain's shared-info frame. */
   10.37      op.cmd = DOM0_GETDOMAININFO;
   10.38      op.u.getdomaininfo.domain = (domid_t)dom;
   10.39 +    op.u.getdomaininfo.exec_domain = 0;
   10.40      op.u.getdomaininfo.ctxt = NULL;
   10.41      if ( do_dom0_op(xc_handle, &op) < 0 )
   10.42      {
   10.43 @@ -220,7 +196,7 @@ int xc_linux_restore(int xc_handle, XcIO
   10.44      }
   10.45  
   10.46      /* Build the pfn-to-mfn table. We choose MFN ordering returned by Xen. */
   10.47 -    if ( get_pfn_list(xc_handle, dom, pfn_to_mfn_table, nr_pfns) != nr_pfns )
   10.48 +    if ( xc_get_pfn_list(xc_handle, dom, pfn_to_mfn_table, nr_pfns) != nr_pfns )
   10.49      {
   10.50          xcio_error(ioctxt, "Did not read correct number of frame "
   10.51                     "numbers for new dom");
    11.1 --- a/tools/libxc/xc_linux_save.c	Thu Jan 13 10:05:14 2005 +0000
    11.2 +++ b/tools/libxc/xc_linux_save.c	Fri Jan 14 12:28:03 2005 +0000
    11.3 @@ -232,8 +232,8 @@ static int print_stats( int xc_handle, u
    11.4  
    11.5      gettimeofday(&wall_now, NULL);
    11.6  
    11.7 -    d0_cpu_now = xc_domain_get_cpu_usage( xc_handle, 0 )/1000;
    11.8 -    d1_cpu_now = xc_domain_get_cpu_usage( xc_handle, domid )/1000;
    11.9 +    d0_cpu_now = xc_domain_get_cpu_usage( xc_handle, 0, /* FIXME */ 0 )/1000;
   11.10 +    d1_cpu_now = xc_domain_get_cpu_usage( xc_handle, domid, /* FIXME */ 0 )/1000;
   11.11  
   11.12      if ( (d0_cpu_now == -1) || (d1_cpu_now == -1) ) 
   11.13          printf("ARRHHH!!\n");
   11.14 @@ -331,7 +331,7 @@ int suspend_and_state(int xc_handle, XcI
   11.15  
   11.16  retry:
   11.17  
   11.18 -    if ( xc_domain_getfullinfo(xc_handle, ioctxt->domain, info, ctxt) )
   11.19 +    if ( xc_domain_getfullinfo(xc_handle, ioctxt->domain, /* FIXME */ 0, info, ctxt) )
   11.20      {
   11.21  	xcio_error(ioctxt, "Could not get full domain info");
   11.22  	return -1;
   11.23 @@ -444,7 +444,7 @@ int xc_linux_save(int xc_handle, XcIOCon
   11.24          return 1;
   11.25      }
   11.26  
   11.27 -    if ( xc_domain_getfullinfo( xc_handle, domid, &info, &ctxt) )
   11.28 +    if ( xc_domain_getfullinfo( xc_handle, domid, /* FIXME */ 0, &info, &ctxt) )
   11.29      {
   11.30          xcio_error(ioctxt, "Could not get full domain info");
   11.31          goto out;
    12.1 --- a/tools/libxc/xc_plan9_build.c	Thu Jan 13 10:05:14 2005 +0000
    12.2 +++ b/tools/libxc/xc_plan9_build.c	Fri Jan 14 12:28:03 2005 +0000
    12.3 @@ -132,52 +132,6 @@ static int
    12.4  #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
    12.5  #define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
    12.6  
    12.7 -static long
    12.8 -get_tot_pages(int xc_handle, u32 domid)
    12.9 -{
   12.10 -	dom0_op_t op;
   12.11 -	op.cmd = DOM0_GETDOMAININFO;
   12.12 -	op.u.getdomaininfo.domain = (domid_t) domid;
   12.13 -	op.u.getdomaininfo.ctxt = NULL;
   12.14 -	return (do_dom0_op(xc_handle, &op) < 0) ?
   12.15 -	    -1 : op.u.getdomaininfo.tot_pages;
   12.16 -}
   12.17 -
   12.18 -static int
   12.19 -get_pfn_list(int xc_handle,
   12.20 -	     u32 domid, unsigned long *pfn_buf, unsigned long max_pfns)
   12.21 -{
   12.22 -	dom0_op_t op;
   12.23 -	int ret;
   12.24 -	op.cmd = DOM0_GETMEMLIST;
   12.25 -	op.u.getmemlist.domain = (domid_t) domid;
   12.26 -	op.u.getmemlist.max_pfns = max_pfns;
   12.27 -	op.u.getmemlist.buffer = pfn_buf;
   12.28 -
   12.29 -	if (mlock(pfn_buf, max_pfns * sizeof (unsigned long)) != 0)
   12.30 -		return -1;
   12.31 -
   12.32 -	ret = do_dom0_op(xc_handle, &op);
   12.33 -
   12.34 -	(void) munlock(pfn_buf, max_pfns * sizeof (unsigned long));
   12.35 -
   12.36 -#if 0
   12.37 -#ifdef DEBUG
   12.38 -	DPRINTF(("Ret for get_pfn_list is %d\n", ret));
   12.39 -	if (ret >= 0) {
   12.40 -		int i, j;
   12.41 -		for (i = 0; i < op.u.getmemlist.num_pfns; i += 16) {
   12.42 -			fprintf(stderr, "0x%x: ", i);
   12.43 -			for (j = 0; j < 16; j++)
   12.44 -				fprintf(stderr, "0x%lx ", pfn_buf[i + j]);
   12.45 -			fprintf(stderr, "\n");
   12.46 -		}
   12.47 -	}
   12.48 -#endif
   12.49 -#endif
   12.50 -	return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
   12.51 -}
   12.52 -
   12.53  static int
   12.54  setup_guestos(int xc_handle,
   12.55  	      u32 dom,
   12.56 @@ -216,7 +170,7 @@ setup_guestos(int xc_handle,
   12.57  		goto error_out;
   12.58  	}
   12.59  
   12.60 -	if (get_pfn_list(xc_handle, dom, cpage_array, tot_pages) != tot_pages) {
   12.61 +	if (xc_get_pfn_list(xc_handle, dom, cpage_array, tot_pages) != tot_pages) {
   12.62  		PERROR("Could not get the page frame list");
   12.63  		goto error_out;
   12.64  	}
   12.65 @@ -487,11 +441,11 @@ xc_plan9_build(int xc_handle,
   12.66  	full_execution_context_t st_ctxt, *ctxt = &st_ctxt;
   12.67  	unsigned long virt_startinfo_addr;
   12.68  
   12.69 -	if ((tot_pages = get_tot_pages(xc_handle, domid)) < 0) {
   12.70 +	if ((tot_pages = xc_get_tot_pages(xc_handle, domid)) < 0) {
   12.71  		PERROR("Could not find total pages for domain");
   12.72  		return 1;
   12.73  	}
   12.74 -	DPRINTF(("get_tot_pages returns %ld pages\n", tot_pages));
   12.75 +	DPRINTF(("xc_get_tot_pages returns %ld pages\n", tot_pages));
   12.76  
   12.77  	kernel_fd = open(image_name, O_RDONLY);
   12.78  	if (kernel_fd < 0) {
   12.79 @@ -505,7 +459,7 @@ xc_plan9_build(int xc_handle,
   12.80  		return 1;
   12.81  	}
   12.82  
   12.83 -	DPRINTF(("get_tot_pages returns %ld pages\n", tot_pages));
   12.84 +	DPRINTF(("xc_get_tot_pages returns %ld pages\n", tot_pages));
   12.85  	if (mlock(&st_ctxt, sizeof (st_ctxt))) {
   12.86  		PERROR("Unable to mlock ctxt");
   12.87  		return 1;
   12.88 @@ -513,13 +467,14 @@ xc_plan9_build(int xc_handle,
   12.89  
   12.90  	op.cmd = DOM0_GETDOMAININFO;
   12.91  	op.u.getdomaininfo.domain = (domid_t) domid;
   12.92 +        op.u.getdomaininfo.exec_domain = 0;
   12.93  	op.u.getdomaininfo.ctxt = ctxt;
   12.94  	if ((do_dom0_op(xc_handle, &op) < 0) ||
   12.95  	    ((u32) op.u.getdomaininfo.domain != domid)) {
   12.96  		PERROR("Could not get info on domain");
   12.97  		goto error_out;
   12.98  	}
   12.99 -	DPRINTF(("get_tot_pages returns %ld pages\n", tot_pages));
  12.100 +	DPRINTF(("xc_get_tot_pages returns %ld pages\n", tot_pages));
  12.101  
  12.102  	if (!(op.u.getdomaininfo.flags & DOMFLAGS_PAUSED)
  12.103  	    || (op.u.getdomaininfo.ctxt->pt_base != 0)) {
  12.104 @@ -527,7 +482,7 @@ xc_plan9_build(int xc_handle,
  12.105  		goto error_out;
  12.106  	}
  12.107  
  12.108 -	DPRINTF(("get_tot_pages returns %ld pages\n", tot_pages));
  12.109 +	DPRINTF(("xc_get_tot_pages returns %ld pages\n", tot_pages));
  12.110  	if (setup_guestos(xc_handle, domid, kernel_gfd, tot_pages,
  12.111  			  &virt_startinfo_addr,
  12.112  			  &load_addr, &st_ctxt, cmdline,
    13.1 --- a/tools/libxc/xc_private.c	Thu Jan 13 10:05:14 2005 +0000
    13.2 +++ b/tools/libxc/xc_private.c	Fri Jan 14 12:28:03 2005 +0000
    13.3 @@ -4,6 +4,7 @@
    13.4   * Helper functions for the rest of the library.
    13.5   */
    13.6  
    13.7 +#include <zlib.h>
    13.8  #include "xc_private.h"
    13.9  
   13.10  void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
   13.11 @@ -159,12 +160,13 @@ int finish_mmu_updates(int xc_handle, mm
   13.12  }
   13.13  
   13.14  
   13.15 -long long  xc_domain_get_cpu_usage( int xc_handle, domid_t domid )
   13.16 +long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid, int vcpu )
   13.17  {
   13.18      dom0_op_t op;
   13.19  
   13.20      op.cmd = DOM0_GETDOMAININFO;
   13.21      op.u.getdomaininfo.domain = (domid_t)domid;
   13.22 +    op.u.getdomaininfo.exec_domain = (u16)vcpu;
   13.23      op.u.getdomaininfo.ctxt = NULL;
   13.24      if ( (do_dom0_op(xc_handle, &op) < 0) || 
   13.25           ((u16)op.u.getdomaininfo.domain != domid) )
   13.26 @@ -201,5 +203,151 @@ unsigned long xc_get_m2p_start_mfn ( int
   13.27      return mfn;
   13.28  }
   13.29  
   13.30 +int xc_get_pfn_list(int xc_handle,
   13.31 +		 u32 domid, 
   13.32 +		 unsigned long *pfn_buf, 
   13.33 +		 unsigned long max_pfns)
   13.34 +{
   13.35 +    dom0_op_t op;
   13.36 +    int ret;
   13.37 +    op.cmd = DOM0_GETMEMLIST;
   13.38 +    op.u.getmemlist.domain   = (domid_t)domid;
   13.39 +    op.u.getmemlist.max_pfns = max_pfns;
   13.40 +    op.u.getmemlist.buffer   = pfn_buf;
   13.41  
   13.42  
   13.43 +    if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 )
   13.44 +    {
   13.45 +        PERROR("Could not lock pfn list buffer");
   13.46 +        return -1;
   13.47 +    }    
   13.48 +
   13.49 +    ret = do_dom0_op(xc_handle, &op);
   13.50 +
   13.51 +    (void)munlock(pfn_buf, max_pfns * sizeof(unsigned long));
   13.52 +
   13.53 +#if 0
   13.54 +#ifdef DEBUG
   13.55 +	DPRINTF(("Ret for xc_get_pfn_list is %d\n", ret));
   13.56 +	if (ret >= 0) {
   13.57 +		int i, j;
   13.58 +		for (i = 0; i < op.u.getmemlist.num_pfns; i += 16) {
   13.59 +			fprintf(stderr, "0x%x: ", i);
   13.60 +			for (j = 0; j < 16; j++)
   13.61 +				fprintf(stderr, "0x%lx ", pfn_buf[i + j]);
   13.62 +			fprintf(stderr, "\n");
   13.63 +		}
   13.64 +	}
   13.65 +#endif
   13.66 +#endif
   13.67 +
   13.68 +    return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
   13.69 +}
   13.70 +
   13.71 +long xc_get_tot_pages(int xc_handle, u32 domid)
   13.72 +{
   13.73 +    dom0_op_t op;
   13.74 +    op.cmd = DOM0_GETDOMAININFO;
   13.75 +    op.u.getdomaininfo.domain = (domid_t)domid;
   13.76 +    op.u.getdomaininfo.exec_domain = 0;
   13.77 +    op.u.getdomaininfo.ctxt = NULL;
   13.78 +    return (do_dom0_op(xc_handle, &op) < 0) ? 
   13.79 +        -1 : op.u.getdomaininfo.tot_pages;
   13.80 +}
   13.81 +
   13.82 +int xc_copy_to_domain_page(int xc_handle,
   13.83 +                                   u32 domid,
   13.84 +                                   unsigned long dst_pfn, 
   13.85 +                                   void *src_page)
   13.86 +{
   13.87 +    void *vaddr = xc_map_foreign_range(
   13.88 +        xc_handle, domid, PAGE_SIZE, PROT_WRITE, dst_pfn);
   13.89 +    if ( vaddr == NULL )
   13.90 +        return -1;
   13.91 +    memcpy(vaddr, src_page, PAGE_SIZE);
   13.92 +    munmap(vaddr, PAGE_SIZE);
   13.93 +    return 0;
   13.94 +}
   13.95 +
   13.96 +unsigned long xc_get_filesz(int fd)
   13.97 +{
   13.98 +    u16 sig;
   13.99 +    u32 _sz = 0;
  13.100 +    unsigned long sz;
  13.101 +
  13.102 +    lseek(fd, 0, SEEK_SET);
  13.103 +    read(fd, &sig, sizeof(sig));
  13.104 +    sz = lseek(fd, 0, SEEK_END);
  13.105 +    if ( sig == 0x8b1f ) /* GZIP signature? */
  13.106 +    {
  13.107 +        lseek(fd, -4, SEEK_END);
  13.108 +        read(fd, &_sz, 4);
  13.109 +        sz = _sz;
  13.110 +    }
  13.111 +    lseek(fd, 0, SEEK_SET);
  13.112 +
  13.113 +    return sz;
  13.114 +}
  13.115 +
  13.116 +char *xc_read_kernel_image(const char *filename, unsigned long *size)
  13.117 +{
  13.118 +    int kernel_fd = -1;
  13.119 +    gzFile kernel_gfd = NULL;
  13.120 +    char *image = NULL;
  13.121 +    unsigned int bytes;
  13.122 +
  13.123 +    if ( (kernel_fd = open(filename, O_RDONLY)) < 0 )
  13.124 +    {
  13.125 +        PERROR("Could not open kernel image");
  13.126 +        goto out;
  13.127 +    }
  13.128 +
  13.129 +    *size = xc_get_filesz(kernel_fd);
  13.130 +
  13.131 +    if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
  13.132 +    {
  13.133 +        PERROR("Could not allocate decompression state for state file");
  13.134 +        goto out;
  13.135 +    }
  13.136 +
  13.137 +    if ( (image = malloc(*size)) == NULL )
  13.138 +    {
  13.139 +        PERROR("Could not allocate memory for kernel image");
  13.140 +        goto out;
  13.141 +    }
  13.142 +
  13.143 +    if ( (bytes = gzread(kernel_gfd, image, *size)) != *size )
  13.144 +    {
  13.145 +        PERROR("Error reading kernel image, could not"
  13.146 +               " read the whole image (%d != %ld).", bytes, *size);
  13.147 +        free(image);
  13.148 +        image = NULL;
  13.149 +    }
  13.150 +
  13.151 + out:
  13.152 +    if ( kernel_gfd != NULL )
  13.153 +        gzclose(kernel_gfd);
  13.154 +    else if ( kernel_fd >= 0 )
  13.155 +        close(kernel_fd);
  13.156 +    return image;
  13.157 +}
  13.158 +
  13.159 +void xc_map_memcpy(unsigned long dst, char *src, unsigned long size,
  13.160 +                   int xch, u32 dom, unsigned long *parray,
  13.161 +                   unsigned long vstart)
  13.162 +{
  13.163 +    char *va;
  13.164 +    unsigned long chunksz, done, pa;
  13.165 +
  13.166 +    for ( done = 0; done < size; done += chunksz )
  13.167 +    {
  13.168 +        pa = dst + done - vstart;
  13.169 +        va = xc_map_foreign_range(
  13.170 +            xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]);
  13.171 +        chunksz = size - done;
  13.172 +        if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
  13.173 +            chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
  13.174 +        memcpy(va + (pa & (PAGE_SIZE-1)), src + done, chunksz);
  13.175 +        munmap(va, PAGE_SIZE);
  13.176 +    }
  13.177 +}
    14.1 --- a/tools/libxc/xc_private.h	Thu Jan 13 10:05:14 2005 +0000
    14.2 +++ b/tools/libxc/xc_private.h	Fri Jan 14 12:28:03 2005 +0000
    14.3 @@ -189,4 +189,17 @@ typedef struct mfn_mapper {
    14.4  
    14.5  unsigned long xc_get_m2p_start_mfn ( int xc_handle );
    14.6  
    14.7 +long xc_get_tot_pages(int xc_handle, u32 domid);
    14.8 +
    14.9 +int xc_copy_to_domain_page(int xc_handle, u32 domid,
   14.10 +                            unsigned long dst_pfn, void *src_page);
   14.11 +
   14.12 +unsigned long xc_get_filesz(int fd);
   14.13 +
   14.14 +char *xc_read_kernel_image(const char *filename, unsigned long *size);
   14.15 +
   14.16 +void xc_map_memcpy(unsigned long dst, char *src, unsigned long size,
   14.17 +                   int xch, u32 dom, unsigned long *parray,
   14.18 +                   unsigned long vstart);
   14.19 +
   14.20  #endif /* __XC_PRIVATE_H__ */
    15.1 --- a/tools/libxc/xc_vmx_build.c	Thu Jan 13 10:05:14 2005 +0000
    15.2 +++ b/tools/libxc/xc_vmx_build.c	Fri Jan 14 12:28:03 2005 +0000
    15.3 @@ -46,53 +46,6 @@ loadelfsymtab(
    15.4      char *elfbase, int xch, u32 dom, unsigned long *parray,
    15.5      struct domain_setup_info *dsi);
    15.6  
    15.7 -static long get_tot_pages(int xc_handle, u32 domid)
    15.8 -{
    15.9 -    dom0_op_t op;
   15.10 -    op.cmd = DOM0_GETDOMAININFO;
   15.11 -    op.u.getdomaininfo.domain = (domid_t)domid;
   15.12 -    op.u.getdomaininfo.ctxt = NULL;
   15.13 -    return (do_dom0_op(xc_handle, &op) < 0) ? 
   15.14 -        -1 : op.u.getdomaininfo.tot_pages;
   15.15 -}
   15.16 -
   15.17 -int xc_get_pfn_list(int xc_handle,
   15.18 -		 u32 domid, 
   15.19 -		 unsigned long *pfn_buf, 
   15.20 -		 unsigned long max_pfns)
   15.21 -{
   15.22 -    dom0_op_t op;
   15.23 -    int ret;
   15.24 -    op.cmd = DOM0_GETMEMLIST;
   15.25 -    op.u.getmemlist.domain   = (domid_t)domid;
   15.26 -    op.u.getmemlist.max_pfns = max_pfns;
   15.27 -    op.u.getmemlist.buffer   = pfn_buf;
   15.28 -
   15.29 -
   15.30 -    if ( mlock(pfn_buf, max_pfns * sizeof(unsigned long)) != 0 )
   15.31 -        return -1;
   15.32 -
   15.33 -    ret = do_dom0_op(xc_handle, &op);
   15.34 -
   15.35 -    (void)munlock(pfn_buf, max_pfns * sizeof(unsigned long));
   15.36 -
   15.37 -    return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
   15.38 -}
   15.39 -
   15.40 -static int copy_to_domain_page(int xc_handle,
   15.41 -                               u32 domid,
   15.42 -                               unsigned long dst_pfn, 
   15.43 -                               void *src_page)
   15.44 -{
   15.45 -    void *vaddr = xc_map_foreign_range(
   15.46 -        xc_handle, domid, PAGE_SIZE, PROT_WRITE, dst_pfn);
   15.47 -    if ( vaddr == NULL )
   15.48 -        return -1;
   15.49 -    memcpy(vaddr, src_page, PAGE_SIZE);
   15.50 -    munmap(vaddr, PAGE_SIZE);
   15.51 -    return 0;
   15.52 -}
   15.53 -
   15.54  static int setup_guestos(int xc_handle,
   15.55                           u32 dom,
   15.56                           char *image, unsigned long image_size,
   15.57 @@ -225,7 +178,7 @@ static int setup_guestos(int xc_handle,
   15.58                  PERROR("Error reading initrd image, could not");
   15.59                  goto error_out;
   15.60              }
   15.61 -            copy_to_domain_page(xc_handle, dom,
   15.62 +            xc_copy_to_domain_page(xc_handle, dom,
   15.63                                  page_array[i>>PAGE_SHIFT], page);
   15.64          }
   15.65      }
   15.66 @@ -402,68 +355,6 @@ static int setup_guestos(int xc_handle,
   15.67      return -1;
   15.68  }
   15.69  
   15.70 -static unsigned long get_filesz(int fd)
   15.71 -{
   15.72 -    u16 sig;
   15.73 -    u32 _sz = 0;
   15.74 -    unsigned long sz;
   15.75 -
   15.76 -    lseek(fd, 0, SEEK_SET);
   15.77 -    read(fd, &sig, sizeof(sig));
   15.78 -    sz = lseek(fd, 0, SEEK_END);
   15.79 -    if ( sig == 0x8b1f ) /* GZIP signature? */
   15.80 -    {
   15.81 -        lseek(fd, -4, SEEK_END);
   15.82 -        read(fd, &_sz, 4);
   15.83 -        sz = _sz;
   15.84 -    }
   15.85 -    lseek(fd, 0, SEEK_SET);
   15.86 -
   15.87 -    return sz;
   15.88 -}
   15.89 -
   15.90 -static char *read_kernel_image(const char *filename, unsigned long *size)
   15.91 -{
   15.92 -    int kernel_fd = -1;
   15.93 -    gzFile kernel_gfd = NULL;
   15.94 -    char *image = NULL;
   15.95 -    unsigned int bytes;
   15.96 -
   15.97 -    if ( (kernel_fd = open(filename, O_RDONLY)) < 0 )
   15.98 -    {
   15.99 -        PERROR("Could not open kernel image");
  15.100 -        goto out;
  15.101 -    }
  15.102 -
  15.103 -    *size = get_filesz(kernel_fd);
  15.104 -
  15.105 -    if ( (kernel_gfd = gzdopen(kernel_fd, "rb")) == NULL )
  15.106 -    {
  15.107 -        PERROR("Could not allocate decompression state for state file");
  15.108 -        goto out;
  15.109 -    }
  15.110 -
  15.111 -    if ( (image = malloc(*size)) == NULL )
  15.112 -    {
  15.113 -        PERROR("Could not allocate memory for kernel image");
  15.114 -        goto out;
  15.115 -    }
  15.116 -
  15.117 -    if ( (bytes = gzread(kernel_gfd, image, *size)) != *size )
  15.118 -    {
  15.119 -        PERROR("Error reading kernel image, could not"
  15.120 -               " read the whole image (%d != %ld).", bytes, *size);
  15.121 -        free(image);
  15.122 -        image = NULL;
  15.123 -    }
  15.124 -
  15.125 - out:
  15.126 -    if ( kernel_gfd != NULL )
  15.127 -        gzclose(kernel_gfd);
  15.128 -    else if ( kernel_fd >= 0 )
  15.129 -        close(kernel_fd);
  15.130 -    return image;
  15.131 -}
  15.132  
  15.133  #define VMX_FEATURE_FLAG 0x20
  15.134  
  15.135 @@ -505,13 +396,13 @@ int xc_vmx_build(int xc_handle,
  15.136          goto error_out;
  15.137      }
  15.138      
  15.139 -    if ( (nr_pages = get_tot_pages(xc_handle, domid)) < 0 )
  15.140 +    if ( (nr_pages = xc_get_tot_pages(xc_handle, domid)) < 0 )
  15.141      {
  15.142          PERROR("Could not find total pages for domain");
  15.143          goto error_out;
  15.144      }
  15.145  
  15.146 -    if ( (image = read_kernel_image(image_name, &image_size)) == NULL )
  15.147 +    if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL )
  15.148          goto error_out;
  15.149  
  15.150      if ( (ramdisk_name != NULL) && (strlen(ramdisk_name) != 0) )
  15.151 @@ -522,7 +413,7 @@ int xc_vmx_build(int xc_handle,
  15.152              goto error_out;
  15.153          }
  15.154  
  15.155 -        initrd_size = get_filesz(initrd_fd);
  15.156 +        initrd_size = xc_get_filesz(initrd_fd);
  15.157  
  15.158          if ( (initrd_gfd = gzdopen(initrd_fd, "rb")) == NULL )
  15.159          {
  15.160 @@ -539,6 +430,7 @@ int xc_vmx_build(int xc_handle,
  15.161  
  15.162      op.cmd = DOM0_GETDOMAININFO;
  15.163      op.u.getdomaininfo.domain = (domid_t)domid;
  15.164 +    op.u.getdomaininfo.exec_domain = 0;
  15.165      op.u.getdomaininfo.ctxt = ctxt;
  15.166      if ( (do_dom0_op(xc_handle, &op) < 0) || 
  15.167           ((u16)op.u.getdomaininfo.domain != domid) )
  15.168 @@ -746,26 +638,6 @@ loadelfimage(
  15.169      return 0;
  15.170  }
  15.171  
  15.172 -static void
  15.173 -map_memcpy(
  15.174 -    unsigned long dst, char *src, unsigned long size,
  15.175 -    int xch, u32 dom, unsigned long *parray, unsigned long vstart)
  15.176 -{
  15.177 -    char *va;
  15.178 -    unsigned long chunksz, done, pa;
  15.179 -
  15.180 -    for ( done = 0; done < size; done += chunksz )
  15.181 -    {
  15.182 -        pa = dst + done - vstart;
  15.183 -        va = xc_map_foreign_range(
  15.184 -            xch, dom, PAGE_SIZE, PROT_WRITE, parray[pa>>PAGE_SHIFT]);
  15.185 -        chunksz = size - done;
  15.186 -        if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
  15.187 -            chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
  15.188 -        memcpy(va + (pa & (PAGE_SIZE-1)), src + done, chunksz);
  15.189 -        munmap(va, PAGE_SIZE);
  15.190 -    }
  15.191 -}
  15.192  
  15.193  #define ELFROUND (ELFSIZE / 8)
  15.194  
  15.195 @@ -817,7 +689,7 @@ loadelfsymtab(
  15.196               (shdr[h].sh_type == SHT_SYMTAB) )
  15.197          {
  15.198              if ( parray != NULL )
  15.199 -                map_memcpy(maxva, elfbase + shdr[h].sh_offset, shdr[h].sh_size,
  15.200 +                xc_map_memcpy(maxva, elfbase + shdr[h].sh_offset, shdr[h].sh_size,
  15.201                             xch, dom, parray, dsi->v_start);
  15.202  
  15.203              /* Mangled to be based on ELF header location. */
  15.204 @@ -849,7 +721,7 @@ loadelfsymtab(
  15.205          sym_ehdr->e_shstrndx = SHN_UNDEF;
  15.206  
  15.207          /* Copy total length, crafted ELF header and section header table */
  15.208 -        map_memcpy(symva, p, sizeof(int) + sizeof(Elf_Ehdr) +
  15.209 +        xc_map_memcpy(symva, p, sizeof(int) + sizeof(Elf_Ehdr) +
  15.210                     ehdr->e_shnum * sizeof(Elf_Shdr), xch, dom, parray,
  15.211                     dsi->v_start);
  15.212      }
    16.1 --- a/tools/python/xen/xm/create.py	Thu Jan 13 10:05:14 2005 +0000
    16.2 +++ b/tools/python/xen/xm/create.py	Fri Jan 14 12:28:03 2005 +0000
    16.3 @@ -295,14 +295,18 @@ def configure_vifs(config_devs, vals):
    16.4          if idx < len(vifs):
    16.5              d = vifs[idx]
    16.6              mac = d.get('mac')
    16.7 +            if not mac:
    16.8 +                mac = randomMAC()
    16.9              bridge = d.get('bridge')
   16.10              script = d.get('script')
   16.11              backend = d.get('backend')
   16.12 +            ip = d.get('ip')
   16.13          else:
   16.14              mac = randomMAC()
   16.15              bridge = None
   16.16              script = None
   16.17              backend = None
   16.18 +            ip = None
   16.19          config_vif = ['vif']
   16.20          config_vif.append(['mac', mac])
   16.21          if bridge:
   16.22 @@ -311,6 +315,8 @@ def configure_vifs(config_devs, vals):
   16.23              config_vif.append(['script', script])
   16.24          if backend:
   16.25              config_vif.append(['backend', backend])
   16.26 +        if ip:
   16.27 +            config_vif.append(['ip', ip])
   16.28          config_devs.append(['device', config_vif])
   16.29  
   16.30  def configure_vfr(config, vals):
   16.31 @@ -399,7 +405,7 @@ def preprocess_vifs(opts, vals):
   16.32              (k, v) = b.strip().split('=', 1)
   16.33              k = k.strip()
   16.34              v = v.strip()
   16.35 -            if k not in ['mac', 'bridge', 'script', 'backend']:
   16.36 +            if k not in ['mac', 'bridge', 'script', 'backend', 'ip']:
   16.37                  opts.err('Invalid vif specifier: ' + vif)
   16.38              d[k] = v
   16.39          vifs.append(d)
    17.1 --- a/xen/common/dom0_ops.c	Thu Jan 13 10:05:14 2005 +0000
    17.2 +++ b/xen/common/dom0_ops.c	Fri Jan 14 12:28:03 2005 +0000
    17.3 @@ -354,7 +354,14 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    17.4  
    17.5          op->u.getdomaininfo.domain = d->id;
    17.6  
    17.7 -        ed = d->exec_domain[0]; // op->u.getdomaininfo.exec_domain];
    17.8 +        if ( (op->u.getdomaininfo.exec_domain >= MAX_VIRT_CPUS) ||
    17.9 +             !d->exec_domain[op->u.getdomaininfo.exec_domain] )
   17.10 +        {
   17.11 +            ret = -EINVAL;
   17.12 +            break;
   17.13 +        }
   17.14 +        
   17.15 +        ed = d->exec_domain[op->u.getdomaininfo.exec_domain];
   17.16  
   17.17          op->u.getdomaininfo.flags =
   17.18              (test_bit( DF_DYING,      &d->d_flags)  ? DOMFLAGS_DYING    : 0) |
    18.1 --- a/xen/common/string.c	Thu Jan 13 10:05:14 2005 +0000
    18.2 +++ b/xen/common/string.c	Fri Jan 14 12:28:03 2005 +0000
    18.3 @@ -92,6 +92,32 @@ char * strncpy(char * dest,const char *s
    18.4  }
    18.5  #endif
    18.6  
    18.7 +#ifndef __HAVE_ARCH_STRLCPY
    18.8 +/**
    18.9 + * strlcpy - Copy a %NUL terminated string into a sized buffer
   18.10 + * @dest: Where to copy the string to
   18.11 + * @src: Where to copy the string from
   18.12 + * @size: size of destination buffer
   18.13 + *
   18.14 + * Compatible with *BSD: the result is always a valid
   18.15 + * NUL-terminated string that fits in the buffer (unless,
   18.16 + * of course, the buffer size is zero). It does not pad
   18.17 + * out the result like strncpy() does.
   18.18 + */
   18.19 +size_t strlcpy(char *dest, const char *src, size_t size)
   18.20 +{
   18.21 +	size_t ret = strlen(src);
   18.22 +
   18.23 +	if (size) {
   18.24 +		size_t len = (ret >= size) ? size-1 : ret;
   18.25 +		memcpy(dest, src, len);
   18.26 +		dest[len] = '\0';
   18.27 +	}
   18.28 +	return ret;
   18.29 +}
   18.30 +EXPORT_SYMBOL(strlcpy);
   18.31 +#endif
   18.32 +
   18.33  #ifndef __HAVE_ARCH_STRCAT
   18.34  /**
   18.35   * strcat - Append one %NUL-terminated string to another
   18.36 @@ -449,7 +475,6 @@ void * memmove(void * dest,const void *s
   18.37   * @ct: Another area of memory
   18.38   * @count: The size of the area.
   18.39   */
   18.40 -/*
   18.41  int memcmp(const void * cs,const void * ct,size_t count)
   18.42  {
   18.43  	const unsigned char *su1, *su2;
   18.44 @@ -460,7 +485,6 @@ int memcmp(const void * cs,const void * 
   18.45  			break;
   18.46  	return res;
   18.47  }
   18.48 -*/
   18.49  #endif
   18.50  
   18.51  #ifndef __HAVE_ARCH_MEMSCAN
    19.1 --- a/xen/include/public/xen.h	Thu Jan 13 10:05:14 2005 +0000
    19.2 +++ b/xen/include/public/xen.h	Fri Jan 14 12:28:03 2005 +0000
    19.3 @@ -18,6 +18,8 @@
    19.4  #include "arch-x86_32.h"
    19.5  #elif defined(__x86_64__)
    19.6  #include "arch-x86_64.h"
    19.7 +#elif defined(__ia64__)
    19.8 +#include "arch-ia64.h"
    19.9  #else
   19.10  #error "Unsupported architecture"
   19.11  #endif
    20.1 --- a/xen/include/xen/irq.h	Thu Jan 13 10:05:14 2005 +0000
    20.2 +++ b/xen/include/xen/irq.h	Fri Jan 14 12:28:03 2005 +0000
    20.3 @@ -21,6 +21,7 @@ struct irqaction
    20.4  #define IRQ_PENDING	4	/* IRQ pending - replay on enable */
    20.5  #define IRQ_REPLAY	8	/* IRQ has been replayed but not acked yet */
    20.6  #define IRQ_GUEST       16      /* IRQ is handled by guest OS(es) */
    20.7 +#define IRQ_PER_CPU     256     /* IRQ is per CPU */
    20.8  
    20.9  /*
   20.10   * Interrupt controller descriptor. This is all we need
    21.1 --- a/xen/include/xen/list.h	Thu Jan 13 10:05:14 2005 +0000
    21.2 +++ b/xen/include/xen/list.h	Fri Jan 14 12:28:03 2005 +0000
    21.3 @@ -162,3 +162,16 @@ static __inline__ void list_splice(struc
    21.4  		pos = n, n = pos->next)
    21.5  
    21.6  #endif
    21.7 +
    21.8 +/**
    21.9 + * list_for_each_entry	-	iterate over list of given type
   21.10 + * @pos:	the type * to use as a loop counter.
   21.11 + * @head:	the head for your list.
   21.12 + * @member:	the name of the list_struct within the struct.
   21.13 + */
   21.14 +#define list_for_each_entry(pos, head, member)				\
   21.15 +	for (pos = list_entry((head)->next, typeof(*pos), member),	\
   21.16 +		     prefetch(pos->member.next);			\
   21.17 +	     &pos->member != (head); 					\
   21.18 +	     pos = list_entry(pos->member.next, typeof(*pos), member),	\
   21.19 +		     prefetch(pos->member.next))