direct-io.hg

changeset 6746:219d96d545fc

merge?
author cl349@firebug.cl.cam.ac.uk
date Mon Sep 12 20:00:41 2005 +0000 (2005-09-12)
parents cdaaaa027bf8 888094e5ac07
children d22091179975
files linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c tools/examples/Makefile tools/examples/block-enbd tools/examples/block-file tools/examples/xen-backend.agent tools/libxc/xc_linux_restore.c tools/libxc/xc_vmx_build.c tools/python/xen/xend/XendDomainInfo.py tools/vnet/Make.env tools/vnet/examples/vnet-insert tools/vnet/libxutil/mem_stream.c tools/vnet/libxutil/mem_stream.h tools/vnet/vnet-module/varp_util.c tools/vnet/vnet-module/varp_util.h xen/arch/x86/domain.c xen/arch/x86/vmx.c
line diff
     7.1 --- a/tools/libxc/xc_linux_restore.c	Mon Sep 12 19:59:40 2005 +0000
     7.2 +++ b/tools/libxc/xc_linux_restore.c	Mon Sep 12 20:00:41 2005 +0000
     7.3 @@ -42,18 +42,18 @@ read_exact(int fd, void *buf, size_t cou
     7.4      unsigned char *b = buf;
     7.5  
     7.6      while (r < count) {
     7.7 -	s = read(fd, &b[r], count - r);
     7.8 -	if (s <= 0)
     7.9 -	    break;
    7.10 -	r += s;
    7.11 +        s = read(fd, &b[r], count - r);
    7.12 +        if (s <= 0)
    7.13 +            break;
    7.14 +        r += s;
    7.15      }
    7.16  
    7.17      return r;
    7.18  }
    7.19  
    7.20  int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns,
    7.21 -		     unsigned int store_evtchn, unsigned long *store_mfn,
    7.22 -		     unsigned int console_evtchn, unsigned long *console_mfn)
    7.23 +                     unsigned int store_evtchn, unsigned long *store_mfn,
    7.24 +                     unsigned int console_evtchn, unsigned long *console_mfn)
    7.25  {
    7.26      dom0_op_t op;
    7.27      int rc = 1, i, n, k;
    7.28 @@ -91,6 +91,8 @@ int xc_linux_restore(int xc_handle, int 
    7.29      /* A temporary mapping of the guest's start_info page. */
    7.30      start_info_t *start_info;
    7.31  
    7.32 +    int pt_levels = 2; /* XXX auto-detect this */
    7.33 +
    7.34      char *region_base;
    7.35  
    7.36      xc_mmu_t *mmu = NULL;
    7.37 @@ -112,8 +114,8 @@ int xc_linux_restore(int xc_handle, int 
    7.38      }
    7.39  
    7.40      if (read_exact(io_fd, pfn_to_mfn_frame_list, PAGE_SIZE) != PAGE_SIZE) {
    7.41 -	ERR("read pfn_to_mfn_frame_list failed");
    7.42 -	goto out;
    7.43 +        ERR("read pfn_to_mfn_frame_list failed");
    7.44 +        goto out;
    7.45      }
    7.46  
    7.47      /* We want zeroed memory so use calloc rather than malloc. */
    7.48 @@ -289,10 +291,10 @@ int xc_linux_restore(int xc_handle, int 
    7.49                          if ( xpfn >= nr_pfns )
    7.50                          {
    7.51                              ERR("Frame number in type %lu page "
    7.52 -                                       "table is out of range. i=%d k=%d "
    7.53 -                                       "pfn=0x%lx nr_pfns=%lu", 
    7.54 -                                       region_pfn_type[i]>>28, i, 
    7.55 -                                       k, xpfn, nr_pfns);
    7.56 +                                "table is out of range. i=%d k=%d "
    7.57 +                                "pfn=0x%lx nr_pfns=%lu", 
    7.58 +                                region_pfn_type[i]>>28, i, 
    7.59 +                                k, xpfn, nr_pfns);
    7.60                              goto out;
    7.61                          }
    7.62  
    7.63 @@ -317,10 +319,10 @@ int xc_linux_restore(int xc_handle, int 
    7.64                          if ( xpfn >= nr_pfns )
    7.65                          {
    7.66                              ERR("Frame number in type %lu page"
    7.67 -                                       " table is out of range. i=%d k=%d "
    7.68 -                                       "pfn=%lu nr_pfns=%lu",
    7.69 -                                       region_pfn_type[i]>>28, i, k, 
    7.70 -                                       xpfn, nr_pfns);
    7.71 +                                " table is out of range. i=%d k=%d "
    7.72 +                                "pfn=%lu nr_pfns=%lu",
    7.73 +                                region_pfn_type[i]>>28, i, k, 
    7.74 +                                xpfn, nr_pfns);
    7.75                              goto out;
    7.76                          }
    7.77  
    7.78 @@ -334,8 +336,8 @@ int xc_linux_restore(int xc_handle, int 
    7.79  
    7.80              default:
    7.81                  ERR("Bogus page type %lx page table is "
    7.82 -                           "out of range. i=%d nr_pfns=%lu", 
    7.83 -                           region_pfn_type[i], i, nr_pfns);
    7.84 +                    "out of range. i=%d nr_pfns=%lu", 
    7.85 +                    region_pfn_type[i], i, nr_pfns);
    7.86                  goto out;
    7.87  
    7.88              } /* end of page type switch statement */
    7.89 @@ -362,8 +364,8 @@ int xc_linux_restore(int xc_handle, int 
    7.90              }
    7.91  
    7.92              if ( xc_add_mmu_update(xc_handle, mmu,
    7.93 -				   (mfn<<PAGE_SHIFT) | MMU_MACHPHYS_UPDATE,
    7.94 -				   pfn) )
    7.95 +                                   (mfn<<PAGE_SHIFT) | MMU_MACHPHYS_UPDATE,
    7.96 +                                   pfn) )
    7.97              {
    7.98                  printf("machpys mfn=%ld pfn=%ld\n",mfn,pfn);
    7.99                  goto out;
   7.100 @@ -377,6 +379,33 @@ int xc_linux_restore(int xc_handle, int 
   7.101  
   7.102      DPRINTF("Received all pages\n");
   7.103  
   7.104 +    if ( pt_levels == 3 )
   7.105 +    {
   7.106 +        /* Get all PGDs below 4GB. */
   7.107 +        for ( i = 0; i < nr_pfns; i++ )
   7.108 +        {
   7.109 +            if ( ((pfn_type[i] & LTABTYPE_MASK) == L3TAB) &&
   7.110 +                 (pfn_to_mfn_table[i] > 0xfffffUL) )
   7.111 +            {
   7.112 +                unsigned long new_mfn = xc_make_page_below_4G(
   7.113 +                    xc_handle, dom, pfn_to_mfn_table[i]);
   7.114 +                if ( new_mfn == 0 )
   7.115 +                {
   7.116 +                    fprintf(stderr, "Couldn't get a page below 4GB :-(\n");
   7.117 +                    goto out;
   7.118 +                }
   7.119 +                pfn_to_mfn_table[i] = new_mfn;
   7.120 +                if ( xc_add_mmu_update(
   7.121 +                    xc_handle, mmu, (new_mfn << PAGE_SHIFT) |
   7.122 +                    MMU_MACHPHYS_UPDATE, i) )
   7.123 +                {
   7.124 +                    fprintf(stderr, "Couldn't m2p on PAE root pgdir\n");
   7.125 +                    goto out;
   7.126 +                }
   7.127 +            }
   7.128 +        }
   7.129 +    }
   7.130 +
   7.131      if ( xc_finish_mmu_updates(xc_handle, mmu) )
   7.132          goto out;
   7.133  
   7.134 @@ -410,57 +439,57 @@ int xc_linux_restore(int xc_handle, int 
   7.135  
   7.136      /* Get the list of PFNs that are not in the psuedo-phys map */
   7.137      {
   7.138 -	unsigned int count;
   7.139 +        unsigned int count;
   7.140          unsigned long *pfntab;
   7.141 -	int rc;
   7.142 +        int rc;
   7.143  
   7.144 -	if ( read_exact(io_fd, &count, sizeof(count)) != sizeof(count) )
   7.145 -	{
   7.146 -	    ERR("Error when reading pfn count");
   7.147 -	    goto out;
   7.148 -	}
   7.149 +        if ( read_exact(io_fd, &count, sizeof(count)) != sizeof(count) )
   7.150 +        {
   7.151 +            ERR("Error when reading pfn count");
   7.152 +            goto out;
   7.153 +        }
   7.154  
   7.155 -	pfntab = malloc( sizeof(unsigned int) * count );
   7.156 -	if ( pfntab == NULL )
   7.157 -	{
   7.158 -	    ERR("Out of memory");
   7.159 -	    goto out;
   7.160 -	}
   7.161 +        pfntab = malloc( sizeof(unsigned int) * count );
   7.162 +        if ( pfntab == NULL )
   7.163 +        {
   7.164 +            ERR("Out of memory");
   7.165 +            goto out;
   7.166 +        }
   7.167  
   7.168 -	if ( read_exact(io_fd, pfntab, sizeof(unsigned int)*count) !=
   7.169 +        if ( read_exact(io_fd, pfntab, sizeof(unsigned int)*count) !=
   7.170               sizeof(unsigned int)*count )
   7.171 -	{
   7.172 -	    ERR("Error when reading pfntab");
   7.173 -	    goto out;
   7.174 -	}
   7.175 +        {
   7.176 +            ERR("Error when reading pfntab");
   7.177 +            goto out;
   7.178 +        }
   7.179  
   7.180 -	for ( i = 0; i < count; i++ )
   7.181 -	{
   7.182 -	    unsigned long pfn = pfntab[i];
   7.183 -	    pfntab[i]=pfn_to_mfn_table[pfn];
   7.184 -	    pfn_to_mfn_table[pfn] = 0x80000001;  // not in pmap
   7.185 -	}
   7.186 +        for ( i = 0; i < count; i++ )
   7.187 +        {
   7.188 +            unsigned long pfn = pfntab[i];
   7.189 +            pfntab[i]=pfn_to_mfn_table[pfn];
   7.190 +            pfn_to_mfn_table[pfn] = 0x80000001;  // not in pmap
   7.191 +        }
   7.192  
   7.193 -	if ( count > 0 )
   7.194 -	{
   7.195 +        if ( count > 0 )
   7.196 +        {
   7.197              struct xen_memory_reservation reservation = {
   7.198                  .extent_start = pfntab,
   7.199                  .nr_extents   = count,
   7.200                  .extent_order = 0,
   7.201                  .domid        = dom
   7.202              };
   7.203 -	    if ( (rc = xc_memory_op(xc_handle,
   7.204 +            if ( (rc = xc_memory_op(xc_handle,
   7.205                                      XENMEM_decrease_reservation,
   7.206                                      &reservation)) != count )
   7.207 -	    {
   7.208 -		ERR("Could not decrease reservation : %d",rc);
   7.209 -		goto out;
   7.210 -	    }
   7.211 -	    else
   7.212 -	    {
   7.213 -		printf("Decreased reservation by %d pages\n", count);
   7.214 -	    }
   7.215 -	}	
   7.216 +            {
   7.217 +                ERR("Could not decrease reservation : %d",rc);
   7.218 +                goto out;
   7.219 +            }
   7.220 +            else
   7.221 +            {
   7.222 +                printf("Decreased reservation by %d pages\n", count);
   7.223 +            }
   7.224 +        } 
   7.225      }
   7.226  
   7.227      if ( read_exact(io_fd, &ctxt,            sizeof(ctxt)) != sizeof(ctxt) ||
   7.228 @@ -484,10 +513,10 @@ int xc_linux_restore(int xc_handle, int 
   7.229      start_info->shared_info = shared_info_frame << PAGE_SHIFT;
   7.230      start_info->flags       = 0;
   7.231      *store_mfn = start_info->store_mfn   =
   7.232 -	pfn_to_mfn_table[start_info->store_mfn];
   7.233 +        pfn_to_mfn_table[start_info->store_mfn];
   7.234      start_info->store_evtchn = store_evtchn;
   7.235      *console_mfn = start_info->console_mfn   =
   7.236 -	pfn_to_mfn_table[start_info->console_mfn];
   7.237 +        pfn_to_mfn_table[start_info->console_mfn];
   7.238      start_info->console_evtchn = console_evtchn;
   7.239      munmap(start_info, PAGE_SIZE);
   7.240  
   7.241 @@ -522,7 +551,7 @@ int xc_linux_restore(int xc_handle, int 
   7.242  
   7.243      /* clear any pending events and the selector */
   7.244      memset(&(shared_info->evtchn_pending[0]), 0,
   7.245 -	   sizeof (shared_info->evtchn_pending));
   7.246 +           sizeof (shared_info->evtchn_pending));
   7.247      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
   7.248          shared_info->vcpu_data[i].evtchn_pending_sel = 0;
   7.249  
   7.250 @@ -548,7 +577,7 @@ int xc_linux_restore(int xc_handle, int 
   7.251      }
   7.252      
   7.253      if ( (live_pfn_to_mfn_table = 
   7.254 -	  xc_map_foreign_batch(xc_handle, dom, 
   7.255 +          xc_map_foreign_batch(xc_handle, dom, 
   7.256                                 PROT_WRITE,
   7.257                                 pfn_to_mfn_frame_list,
   7.258                                 (nr_pfns+1023)/1024 )) == 0 )
     8.1 --- a/tools/libxc/xc_vmx_build.c	Mon Sep 12 19:59:40 2005 +0000
     8.2 +++ b/tools/libxc/xc_vmx_build.c	Mon Sep 12 20:00:41 2005 +0000
     8.3 @@ -578,15 +578,6 @@ static int setup_guest(int xc_handle,
     8.4      sp->sp_global.eport = control_evtchn;
     8.5      munmap(sp, PAGE_SIZE);
     8.6  
     8.7 -    /*
     8.8 -     * Pin down l2tab addr as page dir page - causes hypervisor to provide
     8.9 -     * correct protection for the page
    8.10 -     */ 
    8.11 -#ifdef __i386__
    8.12 -    if ( pin_table(xc_handle, MMUEXT_PIN_L2_TABLE, l2tab>>PAGE_SHIFT, dom) )
    8.13 -        goto error_out;
    8.14 -#endif
    8.15 -
    8.16      /* Send the page update requests down to the hypervisor. */
    8.17      if ( xc_finish_mmu_updates(xc_handle, mmu) )
    8.18          goto error_out;
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/vnet/Make.env	Mon Sep 12 20:00:41 2005 +0000
    10.3 @@ -0,0 +1,20 @@
    10.4 +# -*- mode: Makefile; -*-
    10.5 +
    10.6 +export XEN_ROOT        = $(shell cd $(VNET_ROOT)/../.. && pwd)
    10.7 +export LINUX_SERIES   ?= 2.6
    10.8 +
    10.9 +DISTDIR               ?= $(XEN_ROOT)/dist
   10.10 +export DESTDIR        ?= $(DISTDIR)/install
   10.11 +
   10.12 +export VNET_MODULE_DIR = $(VNET_ROOT)/vnet-module
   10.13 +export VNETD_DIR       = $(VNET_ROOT)/vnetd
   10.14 +export LIBXUTIL_DIR    = $(VNET_ROOT)/libxutil
   10.15 +
   10.16 +export GC_DIR          = $(VNET_ROOT)/build/gc
   10.17 +export GC_INCLUDE      = $(GC_DIR)/include
   10.18 +export GC_LIB_DIR      = $(GC_DIR)/lib
   10.19 +export GC_LIB_A        = $(GC_LIB_DIR)/libgc.a
   10.20 +export GC_LIB_SO       = $(GC_LIB_DIR)/libgc.so
   10.21 +
   10.22 +#$(warning XEN_ROOT  = $(XEN_ROOT))
   10.23 +#$(warning DESTDIR   = $(DESTDIR))
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/tools/vnet/examples/vnet-insert	Mon Sep 12 20:00:41 2005 +0000
    11.3 @@ -0,0 +1,28 @@
    11.4 +#!/bin/bash
    11.5 +
    11.6 +# Insert the vnet module if it can be found and
    11.7 +# it's not already there.
    11.8 +vnet_insert () {
    11.9 +    local module="vnet_module"
   11.10 +    local mod_dir=/lib/modules/$(uname -r)
   11.11 +    local mod_obj=""
   11.12 +
   11.13 +    if lsmod | grep -q ${module} ; then
   11.14 +        echo "VNET: ${module} loaded"
   11.15 +        return
   11.16 +    fi
   11.17 +    local mods=$(find ${mod_dir} -name "${module}.*o")
   11.18 +    if [[ ${mods} ]] ; then
   11.19 +        for mod_obj in ${mods} ; do
   11.20 +            break
   11.21 +        done
   11.22 +    fi
   11.23 +    if [ -z "${mod_obj}" ] ; then
   11.24 +        echo "VNET: ${module} not found"
   11.25 +        exit 1
   11.26 +    fi
   11.27 +    echo "VNET: Loading ${module} from ${mod_obj}"
   11.28 +    insmod ${mod_obj} "$@"
   11.29 +}
   11.30 +
   11.31 +vnet_insert "$@"
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/tools/vnet/libxutil/mem_stream.c	Mon Sep 12 20:00:41 2005 +0000
    12.3 @@ -0,0 +1,319 @@
    12.4 +/*
    12.5 + * Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
    12.6 + *
    12.7 + * This library is free software; you can redistribute it and/or modify
    12.8 + * it under the terms of the GNU Lesser General Public License as published by
    12.9 + * the Free Software Foundation; either version 2.1 of the License, or
   12.10 + * (at your option) any later version.
   12.11 + *
   12.12 + * This library is distributed in the hope that it will be useful,
   12.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.15 + * GNU Lesser General Public License for more details.
   12.16 + *
   12.17 + * You should have received a copy of the GNU Lesser General Public License
   12.18 + * along with this library; if not, write to the Free Software
   12.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.20 + */
   12.21 +
   12.22 +/** @file
   12.23 + * IOStream subtype for input and output to memory.
   12.24 + * Usable from user or kernel code (with __KERNEL__ defined).
   12.25 + */
   12.26 +
   12.27 +#include "sys_string.h"
   12.28 +#include "mem_stream.h"
   12.29 +#include "allocate.h"
   12.30 +
   12.31 +/** Internal state for a memory stream.
   12.32 + *
   12.33 + * The memory stream buffer is treated as a circular buffer.
   12.34 + * The lo and hi markers indicate positions in the buffer, but
   12.35 + * are not reduced modulo the buffer size. This avoids the ambiguity
   12.36 + * between a full and empty buffer when using reduced values.
   12.37 + *
   12.38 + * If x is a marker, then buf + (x % buf_n) is the corresponding
   12.39 + * pointer into the buffer. When the buffer is empty, lo == hi,
   12.40 + * and the corresponding pointers are equal. When the buffer is
   12.41 + * full, hi == lo + buf_n, and the corresponding pointers
   12.42 + * are also equal.
   12.43 + *
   12.44 + * Data is written after the high pointer and read from the lo pointer.
   12.45 + * The value hi - lo is the number of bytes in the buffer.
   12.46 + */
   12.47 +typedef struct MemData {
   12.48 +    /** Data buffer. */
   12.49 +    char *buf;
   12.50 +    /** Low marker - start of readable area. */
   12.51 +    unsigned long lo;
   12.52 +    /** High marker - end of readable area, start of writeable area. */
   12.53 +    unsigned long hi;
   12.54 +    /** Size of the buffer. */
   12.55 +    unsigned int buf_n;
   12.56 +    /** Maximum size the buffer can grow to. */
   12.57 +    unsigned int buf_max;
   12.58 +    /** Error code. */
   12.59 +    int err;
   12.60 +} MemData;
   12.61 +
   12.62 +/** Get number of bytes available to read.
   12.63 + *
   12.64 + * @param data mem stream
   12.65 + * @return bytes
   12.66 + */
   12.67 +static inline int mem_len(struct MemData *data){
   12.68 +    return data->hi - data->lo;
   12.69 +}
   12.70 +
   12.71 +/** Get available space left in the buffer.
   12.72 + *
   12.73 + * @param data mem stream
   12.74 + * @return bytes
   12.75 + */
   12.76 +static inline int mem_room(struct MemData *data){
   12.77 +    return data->buf_n - mem_len(data);
   12.78 +}
   12.79 +
   12.80 +/** Get a pointer to the start of the data in the buffer.
   12.81 + *
   12.82 + * @param data mem stream
   12.83 + * @return lo pointer
   12.84 + */
   12.85 +static inline char * mem_lo(struct MemData *data){
   12.86 +    return data->buf + (data->lo % data->buf_n);
   12.87 +}
   12.88 +
   12.89 +/** Get a pointer to the end of the data in the buffer.
   12.90 + *
   12.91 + * @param data mem stream
   12.92 + * @return hi pointer
   12.93 + */
   12.94 +static inline char * mem_hi(struct MemData *data){
   12.95 +    return data->buf + (data->hi % data->buf_n);
   12.96 +}
   12.97 +
   12.98 +/** Get a pointer to the end of the buffer.
   12.99 + *
  12.100 + * @param data mem stream
  12.101 + * @return end pointer
  12.102 + */
  12.103 +static inline char * mem_end(struct MemData *data){
  12.104 +    return data->buf + data->buf_n;
  12.105 +}
  12.106 +
  12.107 +static int mem_error(IOStream *io);
  12.108 +static int mem_close(IOStream *io);
  12.109 +static void mem_free(IOStream *io);
  12.110 +static int mem_write(IOStream *io, const void *msg, size_t n);
  12.111 +static int mem_read(IOStream *io, void *buf, size_t n);
  12.112 +
  12.113 +/** Minimum delta used to increment the buffer. */
  12.114 +static int delta_min = 256;
  12.115 +
  12.116 +/** Methods for a memory stream. */
  12.117 +static IOMethods mem_methods = {
  12.118 +    read:  mem_read,
  12.119 +    write: mem_write,
  12.120 +    error: mem_error,
  12.121 +    close: mem_close,
  12.122 +    free:  mem_free,
  12.123 +};
  12.124 +
  12.125 +/** Get the memory stream state.
  12.126 + *
  12.127 + * @param io memory stream
  12.128 + * @return state
  12.129 + */
  12.130 +static inline MemData *get_mem_data(IOStream *io){
  12.131 +    return (MemData*)io->data;
  12.132 +}
  12.133 +
  12.134 +/** Get the number of bytes available to read.
  12.135 + *
  12.136 + * @param io memory stream
  12.137 + * @return number of bytes
  12.138 + */
  12.139 +int mem_stream_avail(IOStream *io){
  12.140 +    MemData *data = get_mem_data(io);
  12.141 +    return (data->err ? -data->err : mem_len(data));
  12.142 +}
  12.143 +
  12.144 +/** Copy bytes from a memory stream into a buffer.
  12.145 + *
  12.146 + * @param data mem stream
  12.147 + * @param buf buffer
  12.148 + * @param n number of bytes to copy
  12.149 + */
  12.150 +static void mem_get(MemData *data, char *buf, size_t n){
  12.151 +    char *start = mem_lo(data);
  12.152 +    char *end = mem_end(data);
  12.153 +    if (start + n < end) {
  12.154 +        memcpy(buf, start, n);
  12.155 +    } else {
  12.156 +        int k = end - start;
  12.157 +        memcpy(buf, start, k);
  12.158 +        memcpy(buf + k, data->buf, n - k);
  12.159 +    }
  12.160 +}
  12.161 +
  12.162 +/** Copy bytes from a buffer into a memory stream.
  12.163 + *
  12.164 + * @param data mem stream
  12.165 + * @param buf buffer
  12.166 + * @param n number of bytes to copy
  12.167 + */
  12.168 +static void mem_put(MemData *data, const char *buf, size_t n){
  12.169 +    char *start = mem_hi(data);
  12.170 +    char *end = mem_end(data);
  12.171 +    if(start + n < end){
  12.172 +        memcpy(start, buf, n);
  12.173 +    } else {
  12.174 +        int k = end - start;
  12.175 +        memcpy(start, buf, k);
  12.176 +        memcpy(data->buf, buf + k, n - k);
  12.177 +    }
  12.178 +}
  12.179 +
  12.180 +/** Expand the buffer used by a memory stream.
  12.181 + *
  12.182 + * @param data mem stream
  12.183 + * @param extra number of bytes to expand by
  12.184 + * @return 0 on success, negative error otherwise
  12.185 + */
  12.186 +static int mem_expand(MemData *data, size_t extra){
  12.187 +    int err = -ENOMEM;
  12.188 +    int delta = (extra < delta_min ? delta_min : extra);
  12.189 +    if(data->buf_max > 0){
  12.190 +        int delta_max = data->buf_max - data->buf_n;
  12.191 +        if(delta > delta_max){
  12.192 +            delta = extra;
  12.193 +            if(delta > delta_max) goto exit;
  12.194 +        }
  12.195 +    }
  12.196 +    int buf_n = data->buf_n + delta;
  12.197 +    char *buf = allocate(buf_n);
  12.198 +    if(!buf) goto exit;
  12.199 +    mem_get(data, buf, mem_len(data));
  12.200 +    data->hi = mem_len(data);
  12.201 +    data->lo = 0;
  12.202 +    deallocate(data->buf);
  12.203 +    data->buf = buf;
  12.204 +    data->buf_n = buf_n;
  12.205 +    err = 0;
  12.206 +  exit:
  12.207 +    if(err){
  12.208 +        data->err = -err;
  12.209 +    }
  12.210 +    return err;
  12.211 +}
  12.212 +
  12.213 +/** Write bytes from a buffer into a memory stream.
  12.214 + * The internal buffer is expanded as needed to hold the data,
  12.215 + * up to the stream maximum (if specified). If the buffer cannot
  12.216 + * be expanded -ENOMEM is returned.
  12.217 + *
  12.218 + * @param io mem stream
  12.219 + * @param buf buffer
  12.220 + * @param n number of bytes to write
  12.221 + * @return number of bytes written on success, negative error code otherwise
  12.222 + */
  12.223 +static int mem_write(IOStream *io, const void *msg, size_t n){
  12.224 +    MemData *data = get_mem_data(io);
  12.225 +    if(data->err) return -data->err;
  12.226 +    int room = mem_room(data);
  12.227 +    if(n > room){
  12.228 +        int err = mem_expand(data, n - room);
  12.229 +        if(err) return err;
  12.230 +    }
  12.231 +    mem_put(data, msg, n);
  12.232 +    data->hi += n;
  12.233 +    return n;
  12.234 +}
  12.235 +
  12.236 +/** Read bytes from a memory stream into a buffer.
  12.237 + *
  12.238 + * @param io mem stream
  12.239 + * @param buf buffer
  12.240 + * @param n maximum number of bytes to read
  12.241 + * @return number of bytes read on success, negative error code otherwise
  12.242 + */
  12.243 +static int mem_read(IOStream *io, void *buf, size_t n){
  12.244 +    MemData *data = get_mem_data(io);
  12.245 +    if(data->err) return -data->err;
  12.246 +    int k = mem_len(data);
  12.247 +    if(n > k){
  12.248 +        n = k;
  12.249 +    }
  12.250 +    mem_get(data, buf, n);
  12.251 +    data->lo += n;
  12.252 +    return n;
  12.253 +}
  12.254 +
  12.255 +/** Test if a memory stream has an error.
  12.256 + *
  12.257 + * @param io mem stream
  12.258 + * @return 0 if ok, error code otherwise
  12.259 + */
  12.260 +static int mem_error(IOStream *io){
  12.261 +    MemData *data = get_mem_data(io);
  12.262 +    return data->err;
  12.263 +}
  12.264 +
  12.265 +/** Close a memory stream.
  12.266 + *
  12.267 + * @param io mem stream
  12.268 + * @return 0
  12.269 + */
  12.270 +static int mem_close(IOStream *io){
  12.271 +    MemData *data = get_mem_data(io);
  12.272 +    if(!data->err){
  12.273 +        data->err = ENOTCONN;
  12.274 +    }
  12.275 +    return 0;
  12.276 +}
  12.277 +
  12.278 +/** Free a memory stream.
  12.279 + *
  12.280 + * @param io mem stream
  12.281 + */
  12.282 +static void mem_free(IOStream *io){
  12.283 +    MemData *data = get_mem_data(io);
  12.284 +    deallocate(data->buf);
  12.285 +    memzero(data, sizeof(*data));
  12.286 +    deallocate(data);
  12.287 +}
  12.288 +
  12.289 +/** Allocate and initialise a memory stream.
  12.290 + *
  12.291 + * @param buf_n initial buffer size (0 means default)
  12.292 + * @param buf_max maximum buffer size (0 means no max)
  12.293 + * @return new stream (free using IOStream_close)
  12.294 + */
  12.295 +IOStream *mem_stream_new_size(size_t buf_n, size_t buf_max){
  12.296 +    int err = -ENOMEM;
  12.297 +    MemData *data = ALLOCATE(MemData);
  12.298 +    if(!data) goto exit;
  12.299 +    IOStream *io = ALLOCATE(IOStream);
  12.300 +    if(!io) goto exit;
  12.301 +    if(buf_n <= delta_min){
  12.302 +        buf_n = delta_min;
  12.303 +    }
  12.304 +    if(buf_max > 0 && buf_max < buf_n){
  12.305 +        buf_max = buf_n;
  12.306 +    }
  12.307 +    data->buf = allocate(buf_n);
  12.308 +    if(!data->buf) goto exit;
  12.309 +    data->buf_n = buf_n;
  12.310 +    data->buf_max = buf_max;
  12.311 +    io->methods = &mem_methods;
  12.312 +    io->data = data;
  12.313 +    io->nofree = 0;
  12.314 +    err = 0;
  12.315 +  exit:
  12.316 +    if(err){
  12.317 +        deallocate(data);
  12.318 +        deallocate(io);
  12.319 +        io = NULL;
  12.320 +    }
  12.321 +    return io;
  12.322 +}
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/tools/vnet/libxutil/mem_stream.h	Mon Sep 12 20:00:41 2005 +0000
    13.3 @@ -0,0 +1,32 @@
    13.4 +/*
    13.5 + * Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
    13.6 + *
    13.7 + * This library is free software; you can redistribute it and/or modify
    13.8 + * it under the terms of the GNU Lesser General Public License as published by
    13.9 + * the Free Software Foundation; either version 2.1 of the License, or
   13.10 + * (at your option) any later version.
   13.11 + *
   13.12 + * This library is distributed in the hope that it will be useful,
   13.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.15 + * GNU Lesser General Public License for more details.
   13.16 + *
   13.17 + * You should have received a copy of the GNU Lesser General Public License
   13.18 + * along with this library; if not, write to the Free Software
   13.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   13.20 + */
   13.21 +
   13.22 +#ifndef _XUTIL_MEM_STREAM_H_
   13.23 +#define _XUTIL_MEM_STREAM_H_
   13.24 +
   13.25 +#include "iostream.h"
   13.26 +
   13.27 +extern IOStream *mem_stream_new_size(size_t buf_n, size_t buf_max);
   13.28 +
   13.29 +extern int mem_stream_avail(IOStream *io);
   13.30 +
   13.31 +static inline IOStream *mem_stream_new(void){
   13.32 +    return mem_stream_new_size(0, 0);
   13.33 +}
   13.34 +
   13.35 +#endif /* !_XUTIL_MEM_STREAM_H_ */
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/tools/vnet/vnet-module/varp_util.c	Mon Sep 12 20:00:41 2005 +0000
    14.3 @@ -0,0 +1,77 @@
    14.4 +/*
    14.5 + * Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
    14.6 + *
    14.7 + * This program is free software; you can redistribute it and/or modify
    14.8 + * it under the terms of the GNU General Public License as published by the 
    14.9 + * Free Software Foundation; either version 2 of the License, or (at your
   14.10 + * option) any later version.
   14.11 + * 
   14.12 + * This program is distributed in the hope that it will be useful, but
   14.13 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   14.14 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
   14.15 + * for more details.
   14.16 + *
   14.17 + * You should have received a copy of the GNU General Public License along
   14.18 + * with this program; if not, write to the Free software Foundation, Inc.,
   14.19 + * 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
   14.20 + *
   14.21 + */
   14.22 +
   14.23 +static int hex16(char *s, uint16_t *val)
   14.24 +{
   14.25 +    int err = -EINVAL;
   14.26 +    uint16_t v = 0;
   14.27 +    
   14.28 +    for( ; *s; s++){
   14.29 +        v <<= 4;
   14.30 +        if('0' <= *s && *s <= '9'){
   14.31 +            v |= *s - '0';
   14.32 +        } else if('A' <= *s && *s <= 'F'){
   14.33 +            v |= *s - 'A' + 10;
   14.34 +        } else if('a' <= *s && *s <= 'f'){
   14.35 +            v |= *s - 'a' + 10;
   14.36 +        } else {
   14.37 +            goto exit;
   14.38 +        }
   14.39 +    }
   14.40 +    err = 0;
   14.41 +  exit:
   14.42 +    *val = (err ? 0 : v);
   14.43 +    return err;
   14.44 +}
   14.45 +
   14.46 +int VnetId_aton(const char *s, VnetId *vnet){
   14.47 +    int err = -EINVAL;
   14.48 +    const char *p, *q;
   14.49 +    uint16_t v;
   14.50 +    char buf[5];
   14.51 +    int buf_n = sizeof(buf) - 1;
   14.52 +    int i, n;
   14.53 +    const int elts_n = 8;
   14.54 +
   14.55 +    q = s;
   14.56 +    p = strchr(q, ':');
   14.57 +    i = (p ? 0 : elts_n - 1);
   14.58 +    do {
   14.59 +        if(!p){
   14.60 +            if(i < elts_n - 1) goto exit;
   14.61 +            p = s + strlen(s);
   14.62 +        }
   14.63 +        n = p - q;
   14.64 +        if(n > buf_n) goto exit;
   14.65 +        memcpy(buf, q, n);
   14.66 +        buf[n] = '\0';
   14.67 +        err = hex16(buf, &v);
   14.68 +        if(err) goto exit;
   14.69 +        vnet->u.vnet16[i] = htons(v);
   14.70 +        q = p+1;
   14.71 +        p = strchr(q, ':');
   14.72 +        i++;
   14.73 +    } while(i < elts_n);
   14.74 +    err = 0;
   14.75 +  exit:
   14.76 +    if(err){
   14.77 +        *vnet = (VnetId){};
   14.78 +    }
   14.79 +    return err;
   14.80 +}
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/tools/vnet/vnet-module/varp_util.h	Mon Sep 12 20:00:41 2005 +0000
    15.3 @@ -0,0 +1,142 @@
    15.4 +/*
    15.5 + * Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
    15.6 + *
    15.7 + * This program is free software; you can redistribute it and/or modify
    15.8 + * it under the terms of the GNU General Public License as published by the 
    15.9 + * Free Software Foundation; either version 2 of the License, or (at your
   15.10 + * option) any later version.
   15.11 + * 
   15.12 + * This program is distributed in the hope that it will be useful, but
   15.13 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   15.14 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
   15.15 + * for more details.
   15.16 + *
   15.17 + * You should have received a copy of the GNU General Public License along
   15.18 + * with this program; if not, write to the Free software Foundation, Inc.,
   15.19 + * 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
   15.20 + *
   15.21 + */
   15.22 +#ifndef _VNET_VARP_UTIL_H
   15.23 +#define _VNET_VARP_UTIL_H
   15.24 +
   15.25 +#include "hash_table.h"
   15.26 +
   15.27 +/** Size of a string buffer to store a varp address. */
   15.28 +#define VARP_ADDR_BUF 56
   15.29 +
   15.30 +/** Size of a string buffer to store a vnet id. */
   15.31 +#define VNET_ID_BUF 56
   15.32 +
   15.33 +#ifndef NIPQUAD
   15.34 +#define NIPQUAD(addr) \
   15.35 +	((unsigned char *)&addr)[0], \
   15.36 +	((unsigned char *)&addr)[1], \
   15.37 +	((unsigned char *)&addr)[2], \
   15.38 +	((unsigned char *)&addr)[3]
   15.39 +#endif
   15.40 +
   15.41 +#ifndef NIP6
   15.42 +#define NIP6(addr) \
   15.43 +	ntohs((addr).s6_addr16[0]), \
   15.44 +	ntohs((addr).s6_addr16[1]), \
   15.45 +	ntohs((addr).s6_addr16[2]), \
   15.46 +	ntohs((addr).s6_addr16[3]), \
   15.47 +	ntohs((addr).s6_addr16[4]), \
   15.48 +	ntohs((addr).s6_addr16[5]), \
   15.49 +	ntohs((addr).s6_addr16[6]), \
   15.50 +	ntohs((addr).s6_addr16[7])
   15.51 +#endif
   15.52 +
   15.53 +
   15.54 +static inline const char *VarpAddr_ntoa(VarpAddr *addr, char buf[VARP_ADDR_BUF])
   15.55 +{
   15.56 +    switch(addr->family){
   15.57 +    default:
   15.58 +    case AF_INET:
   15.59 +        sprintf(buf, "%u.%u.%u.%u",
   15.60 +                NIPQUAD(addr->u.ip4));
   15.61 +        break;
   15.62 +    case AF_INET6:
   15.63 +        sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
   15.64 +                NIP6(addr->u.ip6));
   15.65 +        break;
   15.66 +    }
   15.67 +    return buf;
   15.68 +}
   15.69 +
   15.70 +static inline const char *VnetId_ntoa(VnetId *vnet, char buf[VNET_ID_BUF])
   15.71 +{
   15.72 +    sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
   15.73 +            ntohs(vnet->u.vnet16[0]), \
   15.74 +            ntohs(vnet->u.vnet16[1]), \
   15.75 +            ntohs(vnet->u.vnet16[2]), \
   15.76 +            ntohs(vnet->u.vnet16[3]), \
   15.77 +            ntohs(vnet->u.vnet16[4]), \
   15.78 +            ntohs(vnet->u.vnet16[5]), \
   15.79 +            ntohs(vnet->u.vnet16[6]), \
   15.80 +            ntohs(vnet->u.vnet16[7]));
   15.81 +    return buf;
   15.82 +}
   15.83 +
   15.84 +extern int VnetId_aton(const char *s, VnetId *vnet);
   15.85 +
   15.86 +/** Convert an unsigned in host order to a vnet id.
   15.87 + */
   15.88 +static inline struct VnetId toVnetId(uint32_t vnetid){
   15.89 +    struct VnetId vnet = {};
   15.90 +    vnet.u.vnet32[3] = htonl(vnetid);
   15.91 +    return vnet;
   15.92 +}
   15.93 +
   15.94 +static inline uint32_t VnetId_hash(uint32_t h, VnetId *vnet)
   15.95 +{
   15.96 +    h = hash_hul(h, vnet->u.vnet32[0]);
   15.97 +    h = hash_hul(h, vnet->u.vnet32[1]);
   15.98 +    h = hash_hul(h, vnet->u.vnet32[2]);
   15.99 +    h = hash_hul(h, vnet->u.vnet32[3]);
  15.100 +    return h;
  15.101 +}
  15.102 +
  15.103 +static inline int VnetId_eq(VnetId *vnet1, VnetId *vnet2)
  15.104 +{
  15.105 +    return memcmp(vnet1, vnet2, sizeof(VnetId)) == 0;
  15.106 +}
  15.107 +
  15.108 +static inline uint32_t VarpAddr_hash(uint32_t h, VarpAddr *addr)
  15.109 +{
  15.110 +    h = hash_hul(h, addr->family);
  15.111 +    if(addr->family == AF_INET6){
  15.112 +        h = hash_hul(h, addr->u.ip6.s6_addr32[0]);
  15.113 +        h = hash_hul(h, addr->u.ip6.s6_addr32[1]);
  15.114 +        h = hash_hul(h, addr->u.ip6.s6_addr32[2]);
  15.115 +        h = hash_hul(h, addr->u.ip6.s6_addr32[3]);
  15.116 +    } else {
  15.117 +        h = hash_hul(h, addr->u.ip4.s_addr);
  15.118 +    }
  15.119 +    return h;
  15.120 +}
  15.121 +
  15.122 +static inline int VarpAddr_eq(VarpAddr *addr1, VarpAddr*addr2)
  15.123 +{
  15.124 +    return memcmp(addr1, addr2, sizeof(VarpAddr)) == 0;
  15.125 +}
  15.126 +
  15.127 +static inline uint32_t Vmac_hash(uint32_t h, Vmac *vmac)
  15.128 +{
  15.129 +    h = hash_hul(h,
  15.130 +                 (vmac->mac[0] << 24) |
  15.131 +                 (vmac->mac[1] << 16) |
  15.132 +                 (vmac->mac[2] <<  8) |
  15.133 +                 (vmac->mac[3]      ));
  15.134 +    h = hash_hul(h, 
  15.135 +                 (vmac->mac[4] <<   8) |
  15.136 +                 (vmac->mac[5]       ));
  15.137 +    return h;
  15.138 +}
  15.139 +
  15.140 +static inline int Vmac_eq(Vmac *vmac1, Vmac *vmac2)
  15.141 +{
  15.142 +    return memcmp(vmac1, vmac2, sizeof(Vmac)) == 0;
  15.143 +}
  15.144 +
  15.145 +#endif /* _VNET_VARP_UTIL_H */
    16.1 --- a/xen/arch/x86/domain.c	Mon Sep 12 19:59:40 2005 +0000
    16.2 +++ b/xen/arch/x86/domain.c	Mon Sep 12 20:00:41 2005 +0000
    16.3 @@ -461,14 +461,11 @@ int arch_set_info_guest(
    16.4          if ( !get_page(&frame_table[phys_basetab>>PAGE_SHIFT], d) )
    16.5              return -EINVAL;
    16.6      }
    16.7 -    else
    16.8 +    else if ( !(c->flags & VGCF_VMX_GUEST) )
    16.9      {
   16.10 -#ifdef __x86_64__
   16.11 -        if ( !(c->flags & VGCF_VMX_GUEST) )
   16.12 -#endif
   16.13 -            if ( !get_page_and_type(&frame_table[phys_basetab>>PAGE_SHIFT], d, 
   16.14 -                                    PGT_base_page_table) )
   16.15 -                return -EINVAL;
   16.16 +        if ( !get_page_and_type(&frame_table[phys_basetab>>PAGE_SHIFT], d, 
   16.17 +                                PGT_base_page_table) )
   16.18 +            return -EINVAL;
   16.19      }
   16.20  
   16.21      if ( (rc = (int)set_gdt(v, c->gdt_frames, c->gdt_ents)) != 0 )
    17.1 --- a/xen/arch/x86/vmx.c	Mon Sep 12 19:59:40 2005 +0000
    17.2 +++ b/xen/arch/x86/vmx.c	Mon Sep 12 20:00:41 2005 +0000
    17.3 @@ -1082,11 +1082,6 @@ static int vmx_set_cr0(unsigned long val
    17.4              VMX_DBG_LOG(DBG_LEVEL_1, "enable PAE on cr4\n");
    17.5              __vmwrite(GUEST_CR4, crn | X86_CR4_PAE);
    17.6          }
    17.7 -#elif defined( __i386__)
    17.8 -        unsigned long old_base_mfn;
    17.9 -        old_base_mfn = pagetable_get_pfn(d->arch.guest_table);
   17.10 -        if (old_base_mfn)
   17.11 -            put_page(pfn_to_page(old_base_mfn));
   17.12  #endif
   17.13          /*
   17.14           * Now arch.guest_table points to machine physical.