ia64/xen-unstable

changeset 14971:3c352bbc894d

Merge.
author Steven Smith <ssmith@xensource.com>
date Fri Apr 27 13:31:09 2007 +0100 (2007-04-27)
parents 491bed0350f1 499e50c3115f
children 2c90965d0810
files tools/firmware/hvmloader/smbios.h tools/xm-test/tests/network-attach/network_utils.py xen/common/compat/acm_ops.c
line diff
     1.1 --- a/docs/man/xm.pod.1	Fri Apr 27 13:25:58 2007 +0100
     1.2 +++ b/docs/man/xm.pod.1	Fri Apr 27 13:31:09 2007 +0100
     1.3 @@ -555,29 +555,29 @@ B<EXAMPLES>
     1.4  I<normal EDF (20ms/5ms):>
     1.5  
     1.6      xm sched-sedf <dom-id> 20000000 5000000 0 0 0
     1.7 -  
     1.8 +
     1.9  I<best-effort domains (i.e. non-realtime):>
    1.10  
    1.11      xm sched-sedf <dom-id> 20000000 0 0 1 0
    1.12     1.13 +
    1.14  I<normal EDF (20ms/5ms) + share of extra-time:>
    1.15     1.16 +
    1.17      xm sched-sedf <dom-id> 20000000 5000000 0 1 0
    1.18  
    1.19  I<4 domains with weights 2:3:4:2>
    1.20  
    1.21      xm sched-sedf <d1> 0 0 0 0 2
    1.22 -    xm sched-sedf <d2> 0 0 0 0 3
    1.23 -    xm sched-sedf <d3> 0 0 0 0 4
    1.24 -    xm sched-sedf <d4> 0 0 0 0 2
    1.25 +    xm sched-sedf <d2> 0 0 0 0 3
    1.26 +    xm sched-sedf <d3> 0 0 0 0 4
    1.27 +    xm sched-sedf <d4> 0 0 0 0 2
    1.28    
    1.29  I<1 fully-specified (10ms/3ms) domain, 3 other domains share available
    1.30  rest in 2:7:3 ratio:>
    1.31  
    1.32 -    xm sched-sedf <d1> 10000000 3000000 0 0 0   
    1.33 -    xm sched-sedf <d2> 0 0 0 0 2   
    1.34 +    xm sched-sedf <d1> 10000000 3000000 0 0 0
    1.35 +    xm sched-sedf <d2> 0 0 0 0 2
    1.36      xm sched-sedf <d3> 0 0 0 0 7
    1.37 -    xm sched-sedf <d4> 0 0 0 0 3
    1.38 +    xm sched-sedf <d4> 0 0 0 0 3
    1.39  
    1.40  =back
    1.41  
     2.1 --- a/tools/blktap/drivers/block-qcow.c	Fri Apr 27 13:25:58 2007 +0100
     2.2 +++ b/tools/blktap/drivers/block-qcow.c	Fri Apr 27 13:31:09 2007 +0100
     2.3 @@ -55,7 +55,6 @@
     2.4  
     2.5  /******AIO DEFINES******/
     2.6  #define REQUEST_ASYNC_FD 1
     2.7 -#define MAX_AIO_REQS (MAX_REQUESTS * MAX_SEGMENTS_PER_REQ)
     2.8  
     2.9  struct pending_aio {
    2.10          td_callback_t cb;
    2.11 @@ -146,19 +145,38 @@ struct tdqcow_state {
    2.12  	AES_KEY aes_encrypt_key;       /*AES key*/
    2.13  	AES_KEY aes_decrypt_key;       /*AES key*/
    2.14          /* libaio state */
    2.15 -        io_context_t       aio_ctx;
    2.16 -        struct iocb        iocb_list  [MAX_AIO_REQS];
    2.17 -        struct iocb       *iocb_free  [MAX_AIO_REQS];
    2.18 -        struct pending_aio pending_aio[MAX_AIO_REQS];
    2.19 -        int                iocb_free_count;
    2.20 -        struct iocb       *iocb_queue[MAX_AIO_REQS];
    2.21 -        int                iocb_queued;
    2.22 -        int                poll_fd;      /* NB: we require aio_poll support */
    2.23 -        struct io_event    aio_events[MAX_AIO_REQS];
    2.24 +        io_context_t        aio_ctx;
    2.25 +        int                 max_aio_reqs;
    2.26 +        struct iocb        *iocb_list;
    2.27 +        struct iocb       **iocb_free;
    2.28 +        struct pending_aio *pending_aio;
    2.29 +        int                 iocb_free_count;
    2.30 +        struct iocb       **iocb_queue;
    2.31 +        int                 iocb_queued;
    2.32 +        int                 poll_fd;      /* NB: we require aio_poll support */
    2.33 +        struct io_event    *aio_events;
    2.34  };
    2.35  
    2.36  static int decompress_cluster(struct tdqcow_state *s, uint64_t cluster_offset);
    2.37  
    2.38 +static void free_aio_state(struct disk_driver *dd)
    2.39 +{
    2.40 +        struct tdqcow_state *s = (struct tdqcow_state *)dd->private;
    2.41 +
    2.42 +        if (s->sector_lock)
    2.43 +                free(s->sector_lock);
    2.44 +        if (s->iocb_list)
    2.45 +                free(s->iocb_list);
    2.46 +        if (s->pending_aio)
    2.47 +                free(s->pending_aio);
    2.48 +        if (s->aio_events)
    2.49 +                free(s->aio_events);
    2.50 +        if (s->iocb_free)
    2.51 +                free(s->iocb_free);
    2.52 +        if (s->iocb_queue)
    2.53 +                free(s->iocb_queue);
    2.54 +}
    2.55 +
    2.56  static int init_aio_state(struct disk_driver *dd)
    2.57  {
    2.58          int i;
    2.59 @@ -166,6 +184,12 @@ static int init_aio_state(struct disk_dr
    2.60  	struct tdqcow_state  *s = (struct tdqcow_state *)dd->private;
    2.61          long     ioidx;
    2.62  
    2.63 +        s->iocb_list = NULL;
    2.64 +        s->pending_aio = NULL;
    2.65 +        s->aio_events = NULL;
    2.66 +        s->iocb_free = NULL;
    2.67 +        s->iocb_queue = NULL;
    2.68 +
    2.69          /*Initialize Locking bitmap*/
    2.70  	s->sector_lock = calloc(1, bs->size);
    2.71  	
    2.72 @@ -174,13 +198,26 @@ static int init_aio_state(struct disk_dr
    2.73  		goto fail;
    2.74  	}
    2.75  
    2.76 +        /* A segment (i.e. a page) can span multiple clusters */
    2.77 +        s->max_aio_reqs = (getpagesize() / s->cluster_size) + 1;
    2.78 +
    2.79          /* Initialize AIO */
    2.80 -        s->iocb_free_count = MAX_AIO_REQS;
    2.81 +        s->iocb_free_count = s->max_aio_reqs;
    2.82          s->iocb_queued     = 0;
    2.83  
    2.84 +        if (!(s->iocb_list = malloc(sizeof(struct iocb) * s->max_aio_reqs)) ||
    2.85 +            !(s->pending_aio = malloc(sizeof(struct pending_aio) * s->max_aio_reqs)) ||
    2.86 +            !(s->aio_events = malloc(sizeof(struct io_event) * s->max_aio_reqs)) ||
    2.87 +            !(s->iocb_free = malloc(sizeof(struct iocb *) * s->max_aio_reqs)) ||
    2.88 +            !(s->iocb_queue = malloc(sizeof(struct iocb *) * s->max_aio_reqs))) {
    2.89 +                DPRINTF("Failed to allocate AIO structs (max_aio_reqs = %d)\n",
    2.90 +                        s->max_aio_reqs);
    2.91 +                goto fail;
    2.92 +        }
    2.93 +
    2.94          /*Signal kernel to create Poll FD for Asyc completion events*/
    2.95          s->aio_ctx = (io_context_t) REQUEST_ASYNC_FD;   
    2.96 -        s->poll_fd = io_setup(MAX_AIO_REQS, &s->aio_ctx);
    2.97 +        s->poll_fd = io_setup(s->max_aio_reqs, &s->aio_ctx);
    2.98  
    2.99  	if (s->poll_fd < 0) {
   2.100                  if (s->poll_fd == -EAGAIN) {
   2.101 @@ -198,7 +235,7 @@ static int init_aio_state(struct disk_dr
   2.102  		goto fail;
   2.103  	}
   2.104  
   2.105 -        for (i=0;i<MAX_AIO_REQS;i++)
   2.106 +        for (i=0;i<s->max_aio_reqs;i++)
   2.107                  s->iocb_free[i] = &s->iocb_list[i];
   2.108  
   2.109          DPRINTF("AIO state initialised\n");
   2.110 @@ -946,6 +983,7 @@ int tdqcow_open (struct disk_driver *dd,
   2.111   end_xenhdr:
   2.112  	if (init_aio_state(dd)!=0) {
   2.113  		DPRINTF("Unable to initialise AIO state\n");
   2.114 +                free_aio_state(dd);
   2.115  		goto fail;
   2.116  	}
   2.117  	init_fds(dd);
   2.118 @@ -962,6 +1000,7 @@ int tdqcow_open (struct disk_driver *dd,
   2.119  	
   2.120  fail:
   2.121  	DPRINTF("QCOW Open failed\n");
   2.122 +	free_aio_state(dd);
   2.123  	free(s->l1_table);
   2.124  	free(s->l2_cache);
   2.125  	free(s->cluster_cache);
   2.126 @@ -1145,7 +1184,7 @@ int tdqcow_do_callbacks(struct disk_driv
   2.127          if (sid > MAX_IOFD) return 1;
   2.128  	
   2.129  	/* Non-blocking test for completed io. */
   2.130 -        ret = io_getevents(prv->aio_ctx, 0, MAX_AIO_REQS, prv->aio_events,
   2.131 +        ret = io_getevents(prv->aio_ctx, 0, prv->max_aio_reqs, prv->aio_events,
   2.132                             NULL);
   2.133  
   2.134          for (ep = prv->aio_events, i = ret; i-- > 0; ep++) {
     3.1 --- a/tools/firmware/hvmloader/acpi/acpi2_0.h	Fri Apr 27 13:25:58 2007 +0100
     3.2 +++ b/tools/firmware/hvmloader/acpi/acpi2_0.h	Fri Apr 27 13:31:09 2007 +0100
     3.3 @@ -394,8 +394,6 @@ struct acpi_20_madt_intsrcovr {
     3.4  
     3.5  #pragma pack ()
     3.6  
     3.7 -#define ACPI_PHYSICAL_ADDRESS 0xEA000
     3.8 -
     3.9  int acpi_build_tables(uint8_t *);
    3.10  
    3.11  #endif /* _ACPI_2_0_H_ */
     4.1 --- a/tools/firmware/hvmloader/config.h	Fri Apr 27 13:25:58 2007 +0100
     4.2 +++ b/tools/firmware/hvmloader/config.h	Fri Apr 27 13:31:09 2007 +0100
     4.3 @@ -17,5 +17,14 @@
     4.4  #define ROMBIOS_MAXOFFSET      0x0000FFFF
     4.5  #define ROMBIOS_END            (ROMBIOS_BEGIN + ROMBIOS_SIZE)
     4.6  
     4.7 +/* Memory map. */
     4.8 +#define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
     4.9 +#define VGABIOS_PHYSICAL_ADDRESS      0x000C0000
    4.10 +#define ETHERBOOT_PHYSICAL_ADDRESS    0x000C8000
    4.11 +#define VMXASSIST_PHYSICAL_ADDRESS    0x000D0000
    4.12 +#define SMBIOS_PHYSICAL_ADDRESS       0x000E9000
    4.13 +#define SMBIOS_MAXIMUM_SIZE           0x00001000
    4.14 +#define ACPI_PHYSICAL_ADDRESS         0x000EA000
    4.15 +#define ROMBIOS_PHYSICAL_ADDRESS      0x000F0000
    4.16  
    4.17  #endif /* __HVMLOADER_CONFIG_H__ */
     5.1 --- a/tools/firmware/hvmloader/hvmloader.c	Fri Apr 27 13:25:58 2007 +0100
     5.2 +++ b/tools/firmware/hvmloader/hvmloader.c	Fri Apr 27 13:31:09 2007 +0100
     5.3 @@ -19,24 +19,17 @@
     5.4   * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
     5.5   * Place - Suite 330, Boston, MA 02111-1307 USA.
     5.6   */
     5.7 +
     5.8  #include "roms.h"
     5.9 -#include "acpi/acpi2_0.h"  /* for ACPI_PHYSICAL_ADDRESS */
    5.10 +#include "acpi/acpi2_0.h"
    5.11  #include "hypercall.h"
    5.12  #include "util.h"
    5.13 -#include "smbios.h"
    5.14  #include "config.h"
    5.15  #include "apic_regs.h"
    5.16  #include "pci_regs.h"
    5.17  #include <xen/version.h>
    5.18  #include <xen/hvm/params.h>
    5.19  
    5.20 -/* memory map */
    5.21 -#define HYPERCALL_PHYSICAL_ADDRESS    0x00080000
    5.22 -#define VGABIOS_PHYSICAL_ADDRESS      0x000C0000
    5.23 -#define ETHERBOOT_PHYSICAL_ADDRESS    0x000C8000
    5.24 -#define VMXASSIST_PHYSICAL_ADDRESS    0x000D0000
    5.25 -#define ROMBIOS_PHYSICAL_ADDRESS      0x000F0000
    5.26 -
    5.27  asm(
    5.28      "    .text                       \n"
    5.29      "    .globl _start               \n"
    5.30 @@ -103,7 +96,8 @@ asm(
    5.31      "stack_top:                      \n"
    5.32      );
    5.33  
    5.34 -extern void create_mp_tables(void);
    5.35 +void create_mp_tables(void);
    5.36 +int hvm_write_smbios_tables(void);
    5.37  
    5.38  static int
    5.39  cirrus_check(void)
    5.40 @@ -351,17 +345,20 @@ static void cmos_write_memory_size(void)
    5.41  
    5.42  int main(void)
    5.43  {
    5.44 -    int acpi_sz;
    5.45 +    int acpi_sz = 0, vgabios_sz = 0, etherboot_sz = 0, rombios_sz, smbios_sz;
    5.46  
    5.47      printf("HVM Loader\n");
    5.48  
    5.49      init_hypercalls();
    5.50  
    5.51      printf("Writing SMBIOS tables ...\n");
    5.52 -    hvm_write_smbios_tables();
    5.53 +    smbios_sz = hvm_write_smbios_tables();
    5.54  
    5.55      printf("Loading ROMBIOS ...\n");
    5.56 -    memcpy((void *)ROMBIOS_PHYSICAL_ADDRESS, rombios, sizeof(rombios));
    5.57 +    rombios_sz = sizeof(rombios);
    5.58 +    if ( rombios_sz > 0x10000 )
    5.59 +        rombios_sz = 0x10000;
    5.60 +    memcpy((void *)ROMBIOS_PHYSICAL_ADDRESS, rombios, rombios_sz);
    5.61      highbios_setup();
    5.62  
    5.63      apic_setup();
    5.64 @@ -375,12 +372,14 @@ int main(void)
    5.65          printf("Loading Cirrus VGABIOS ...\n");
    5.66          memcpy((void *)VGABIOS_PHYSICAL_ADDRESS,
    5.67                 vgabios_cirrusvga, sizeof(vgabios_cirrusvga));
    5.68 +        vgabios_sz = sizeof(vgabios_cirrusvga);
    5.69      }
    5.70      else
    5.71      {
    5.72          printf("Loading Standard VGABIOS ...\n");
    5.73          memcpy((void *)VGABIOS_PHYSICAL_ADDRESS,
    5.74                 vgabios_stdvga, sizeof(vgabios_stdvga));
    5.75 +        vgabios_sz = sizeof(vgabios_stdvga);
    5.76      }
    5.77  
    5.78      if ( must_load_nic() )
    5.79 @@ -388,9 +387,10 @@ int main(void)
    5.80          printf("Loading ETHERBOOT ...\n");
    5.81          memcpy((void *)ETHERBOOT_PHYSICAL_ADDRESS,
    5.82                 etherboot, sizeof(etherboot));
    5.83 +        etherboot_sz = sizeof(etherboot);
    5.84      }
    5.85  
    5.86 -    if ( get_acpi_enabled() != 0 )
    5.87 +    if ( get_acpi_enabled() )
    5.88      {
    5.89          printf("Loading ACPI ...\n");
    5.90          acpi_sz = acpi_build_tables((uint8_t *)ACPI_PHYSICAL_ADDRESS);
    5.91 @@ -399,6 +399,32 @@ int main(void)
    5.92  
    5.93      cmos_write_memory_size();
    5.94  
    5.95 +    printf("BIOS map:\n");
    5.96 +    if ( vgabios_sz )
    5.97 +        printf(" %05x-%05x: VGA BIOS\n",
    5.98 +               VGABIOS_PHYSICAL_ADDRESS,
    5.99 +               VGABIOS_PHYSICAL_ADDRESS + vgabios_sz - 1);
   5.100 +    if ( etherboot_sz )
   5.101 +        printf(" %05x-%05x: Etherboot ROM\n",
   5.102 +               ETHERBOOT_PHYSICAL_ADDRESS,
   5.103 +               ETHERBOOT_PHYSICAL_ADDRESS + etherboot_sz - 1);
   5.104 +    if ( !check_amd() )
   5.105 +        printf(" %05x-%05x: VMXAssist\n",
   5.106 +               VMXASSIST_PHYSICAL_ADDRESS,
   5.107 +               VMXASSIST_PHYSICAL_ADDRESS + sizeof(vmxassist) - 1);
   5.108 +    if ( smbios_sz )
   5.109 +        printf(" %05x-%05x: SMBIOS tables\n",
   5.110 +               SMBIOS_PHYSICAL_ADDRESS,
   5.111 +               SMBIOS_PHYSICAL_ADDRESS + smbios_sz - 1);
   5.112 +    if ( acpi_sz )
   5.113 +        printf(" %05x-%05x: ACPI tables\n",
   5.114 +               ACPI_PHYSICAL_ADDRESS,
   5.115 +               ACPI_PHYSICAL_ADDRESS + acpi_sz - 1);
   5.116 +    if ( rombios_sz )
   5.117 +        printf(" %05x-%05x: Main BIOS\n",
   5.118 +               ROMBIOS_PHYSICAL_ADDRESS,
   5.119 +               ROMBIOS_PHYSICAL_ADDRESS + rombios_sz - 1);
   5.120 +
   5.121      if ( !check_amd() )
   5.122      {
   5.123          printf("Loading VMXAssist ...\n");
     6.1 --- a/tools/firmware/hvmloader/hypercall.h	Fri Apr 27 13:25:58 2007 +0100
     6.2 +++ b/tools/firmware/hvmloader/hypercall.h	Fri Apr 27 13:31:09 2007 +0100
     6.3 @@ -31,17 +31,18 @@
     6.4  #ifndef __HVMLOADER_HYPERCALL_H__
     6.5  #define __HVMLOADER_HYPERCALL_H__
     6.6  
     6.7 +#include <stdint.h>
     6.8  #include <xen/xen.h>
     6.9 +#include "config.h"
    6.10 +
    6.11 +#define __STR(...) #__VA_ARGS__
    6.12 +#define STR(...) __STR(__VA_ARGS__)
    6.13  
    6.14  /*
    6.15   * NB. Hypercall address needs to be relative to a linkage symbol for
    6.16   * some version of ld to relocate the relative calls properly.
    6.17 - * Keep this in sync with HYPERCALL_PHYSICAL_ADDRESS in hvmloader.c!
    6.18   */
    6.19 -#define hypercall_pa "_start - 0x80000"
    6.20 -
    6.21 -#define __STR(x) #x
    6.22 -#define STR(x) __STR(x)
    6.23 +#define hypercall_pa "_start - " STR(HYPERCALL_PHYSICAL_ADDRESS)
    6.24  
    6.25  #define _hypercall0(type, name)						\
    6.26  ({									\
     7.1 --- a/tools/firmware/hvmloader/smbios.c	Fri Apr 27 13:25:58 2007 +0100
     7.2 +++ b/tools/firmware/hvmloader/smbios.c	Fri Apr 27 13:31:09 2007 +0100
     7.3 @@ -22,12 +22,11 @@
     7.4  
     7.5  #include <stdint.h>
     7.6  #include <xen/version.h>
     7.7 -#include "smbios.h"
     7.8  #include "smbios_types.h"
     7.9  #include "util.h"
    7.10  #include "hypercall.h"
    7.11  
    7.12 -static size_t
    7.13 +static int
    7.14  write_smbios_tables(void *start,
    7.15                      uint32_t vcpus, uint64_t memsize,
    7.16                      uint8_t uuid[16], char *xen_version,
    7.17 @@ -82,7 +81,7 @@ get_cpu_manufacturer(char *buf, int len)
    7.18          strncpy(buf, "unknown", len);
    7.19  }
    7.20  
    7.21 -static size_t
    7.22 +static int
    7.23  write_smbios_tables(void *start,
    7.24                      uint32_t vcpus, uint64_t memsize,
    7.25                      uint8_t uuid[16], char *xen_version,
    7.26 @@ -125,7 +124,7 @@ write_smbios_tables(void *start,
    7.27          SMBIOS_PHYSICAL_ADDRESS + sizeof(struct smbios_entry_point),
    7.28          nr_structs);
    7.29  
    7.30 -    return (size_t)((char *)p - (char *)start);
    7.31 +    return ((char *)p - (char *)start);
    7.32  }
    7.33  
    7.34  /* Calculate how much pseudo-physical memory (in MB) is allocated to us. */
    7.35 @@ -156,7 +155,7 @@ get_memsize(void)
    7.36      return (memsize + (1 << 20) - 1) >> 20;
    7.37  }
    7.38  
    7.39 -void
    7.40 +int
    7.41  hvm_write_smbios_tables(void)
    7.42  {
    7.43      uint8_t uuid[16]; /* ** This will break if xen_domain_handle_t is
    7.44 @@ -221,16 +220,17 @@ hvm_write_smbios_tables(void)
    7.45                                get_vcpu_nr(), get_memsize(),
    7.46                                uuid, xen_version_str,
    7.47                                xen_major_version, xen_minor_version);
    7.48 -    if ( len > SMBIOS_SIZE_LIMIT )
    7.49 +    if ( len > SMBIOS_MAXIMUM_SIZE )
    7.50          goto error_out;
    7.51      /* Okay, not too large: copy out of scratch to final location. */
    7.52      memcpy((void *)SMBIOS_PHYSICAL_ADDRESS, (void *)0xC0000, len);
    7.53  
    7.54 -    return;
    7.55 +    return len;
    7.56  
    7.57   error_out:
    7.58      printf("Could not write SMBIOS tables, error in hvmloader.c:"
    7.59             "hvm_write_smbios_tables()\n");
    7.60 +    return 0;
    7.61  }
    7.62  
    7.63  
     8.1 --- a/tools/firmware/hvmloader/smbios.h	Fri Apr 27 13:25:58 2007 +0100
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,38 +0,0 @@
     8.4 -/*
     8.5 - * smbios.h - interface for Xen HVM SMBIOS generation
     8.6 - *
     8.7 - * This program is free software; you can redistribute it and/or modify
     8.8 - * it under the terms of the GNU General Public License as published by
     8.9 - * the Free Software Foundation; either version 2 of the License, or
    8.10 - * (at your option) any later version.
    8.11 - *
    8.12 - * This program is distributed in the hope that it will be useful,
    8.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.15 - * GNU General Public License for more details.
    8.16 - *
    8.17 - * You should have received a copy of the GNU General Public License
    8.18 - * along with this program; if not, write to the Free Software
    8.19 - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    8.20 - *
    8.21 - * Copyright (C) IBM Corporation, 2006
    8.22 - *
    8.23 - * Authors: Andrew D. Ball <aball@us.ibm.com>
    8.24 - */
    8.25 -
    8.26 -#ifndef SMBIOS_H
    8.27 -#define SMBIOS_H
    8.28 -
    8.29 -#include <stdint.h>
    8.30 -#include <stdlib.h>
    8.31 -
    8.32 -/* These constants must agree with the ACPI e820 memory map as defined
    8.33 -   in tools/libxc/xc_hvm_build.c and the address the ROMBIOS pulls the
    8.34 -   SMBIOS entry point from in the smbios_init subroutine.
    8.35 - */
    8.36 -#define SMBIOS_PHYSICAL_ADDRESS 0x9f000
    8.37 -#define SMBIOS_SIZE_LIMIT 0x800
    8.38 -
    8.39 -void hvm_write_smbios_tables(void);
    8.40 -
    8.41 -#endif /* SMBIOS_H */
     9.1 --- a/tools/firmware/hvmloader/util.c	Fri Apr 27 13:25:58 2007 +0100
     9.2 +++ b/tools/firmware/hvmloader/util.c	Fri Apr 27 13:31:09 2007 +0100
     9.3 @@ -18,7 +18,6 @@
     9.4   * Place - Suite 330, Boston, MA 02111-1307 USA.
     9.5   */
     9.6  
     9.7 -#include "acpi/acpi2_0.h"  /* for ACPI_PHYSICAL_ADDRESS */
     9.8  #include "util.h"
     9.9  #include "config.h"
    9.10  #include <stdint.h>
    10.1 --- a/tools/firmware/hvmloader/util.h	Fri Apr 27 13:25:58 2007 +0100
    10.2 +++ b/tools/firmware/hvmloader/util.h	Fri Apr 27 13:31:09 2007 +0100
    10.3 @@ -2,6 +2,7 @@
    10.4  #define __HVMLOADER_UTIL_H__
    10.5  
    10.6  #include <stdarg.h>
    10.7 +#include <stdint.h>
    10.8  
    10.9  #undef offsetof
   10.10  #define offsetof(t, m) ((unsigned long)&((t *)0)->m)
    11.1 --- a/tools/firmware/rombios/rombios.c	Fri Apr 27 13:25:58 2007 +0100
    11.2 +++ b/tools/firmware/rombios/rombios.c	Fri Apr 27 13:31:09 2007 +0100
    11.3 @@ -26,6 +26,8 @@
    11.4  
    11.5  // ROM BIOS for use with Bochs/Plex x86 emulation environment
    11.6  
    11.7 +#include "../hvmloader/config.h"
    11.8 +
    11.9  #define HVMASSIST
   11.10  #undef HVMTEST
   11.11  
   11.12 @@ -9409,9 +9411,9 @@ rom_scan_increment:
   11.13  
   11.14  #ifdef HVMASSIST
   11.15  
   11.16 -; Copy the SMBIOS entry point over from 0x9f000, where hvmloader left it.
   11.17 +; Copy the SMBIOS entry point from where hvmloader left it.
   11.18  ; The entry point must be somewhere in 0xf0000-0xfffff on a 16-byte boundary,
   11.19 -; but the tables themeselves can be elsewhere.
   11.20 +; but the tables themselves can be elsewhere.
   11.21  smbios_init:
   11.22    push ax
   11.23    push cx
   11.24 @@ -9424,9 +9426,9 @@ smbios_init:
   11.25    mov ax, #0xf000
   11.26    mov es, ax      ; destination segment is 0xf0000
   11.27    mov di, #smbios_entry_point ; destination offset
   11.28 -  mov ax, #0x9f00
   11.29 -  mov ds, ax      ; source segment is 0x9f000
   11.30 -  mov si, #0x0000 ; source offset is 0
   11.31 +  mov ax, #(SMBIOS_PHYSICAL_ADDRESS>>4)
   11.32 +  mov ds, ax
   11.33 +  mov si, #(SMBIOS_PHYSICAL_ADDRESS&15)
   11.34    cld
   11.35    rep
   11.36      movsb
    12.1 --- a/tools/ioemu/hw/pc.c	Fri Apr 27 13:25:58 2007 +0100
    12.2 +++ b/tools/ioemu/hw/pc.c	Fri Apr 27 13:31:09 2007 +0100
    12.3 @@ -922,12 +922,13 @@ static void pc_init1(uint64_t ram_size, 
    12.4  #endif
    12.5  #else
    12.6      if (pci_enabled) {
    12.7 -        void *scsi;
    12.8 -
    12.9 -        scsi = lsi_scsi_init(pci_bus, -1);
   12.10 +        void *scsi = NULL;
   12.11          for (i = 0; i < MAX_SCSI_DISKS ; i++) {
   12.12 -            if (bs_table[i + MAX_DISKS]) 
   12.13 -                lsi_scsi_attach(scsi, bs_table[i + MAX_DISKS], -1);
   12.14 +            if (!bs_table[i + MAX_DISKS])
   12.15 +                continue;
   12.16 +            if (!scsi)
   12.17 +                scsi = lsi_scsi_init(pci_bus, -1);
   12.18 +            lsi_scsi_attach(scsi, bs_table[i + MAX_DISKS], -1);
   12.19          }
   12.20      }
   12.21  #endif /* !CONFIG_DM */
    13.1 --- a/tools/libxc/xc_core_x86.c	Fri Apr 27 13:25:58 2007 +0100
    13.2 +++ b/tools/libxc/xc_core_x86.c	Fri Apr 27 13:31:09 2007 +0100
    13.3 @@ -21,9 +21,9 @@
    13.4  #include "xg_private.h"
    13.5  #include "xc_core.h"
    13.6  
    13.7 -static int max_gpfn(int xc_handle, domid_t domid)
    13.8 +static int nr_gpfns(int xc_handle, domid_t domid)
    13.9  {
   13.10 -    return xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &domid);
   13.11 +    return xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &domid) + 1;
   13.12  }
   13.13  
   13.14  int
   13.15 @@ -38,7 +38,7 @@ xc_core_arch_memory_map_get(int xc_handl
   13.16                              xc_core_memory_map_t **mapp,
   13.17                              unsigned int *nr_entries)
   13.18  {
   13.19 -    unsigned long p2m_size = max_gpfn(xc_handle, info->domid);
   13.20 +    unsigned long p2m_size = nr_gpfns(xc_handle, info->domid);
   13.21      xc_core_memory_map_t *map;
   13.22  
   13.23      map = malloc(sizeof(*map));
   13.24 @@ -65,7 +65,7 @@ xc_core_arch_map_p2m(int xc_handle, xc_d
   13.25      xen_pfn_t *live_p2m_frame_list_list = NULL;
   13.26      xen_pfn_t *live_p2m_frame_list = NULL;
   13.27      uint32_t dom = info->domid;
   13.28 -    unsigned long p2m_size = max_gpfn(xc_handle, info->domid);
   13.29 +    unsigned long p2m_size = nr_gpfns(xc_handle, info->domid);
   13.30      int ret = -1;
   13.31      int err;
   13.32  
    14.1 --- a/tools/libxc/xc_dom_core.c	Fri Apr 27 13:25:58 2007 +0100
    14.2 +++ b/tools/libxc/xc_dom_core.c	Fri Apr 27 13:31:09 2007 +0100
    14.3 @@ -209,13 +209,13 @@ size_t xc_dom_check_gzip(void *blob, siz
    14.4      unsigned char *gzlen;
    14.5      size_t unziplen;
    14.6  
    14.7 -    if (strncmp(blob, "\037\213", 2))
    14.8 +    if ( strncmp(blob, "\037\213", 2) )
    14.9          /* not gzipped */
   14.10          return 0;
   14.11  
   14.12      gzlen = blob + ziplen - 4;
   14.13      unziplen = gzlen[3] << 24 | gzlen[2] << 16 | gzlen[1] << 8 | gzlen[0];
   14.14 -    if ( (unziplen < ziplen) || (unziplen > (ziplen * 8)) )
   14.15 +    if ( (unziplen < 0) || (unziplen > (1024*1024*1024)) ) /* 1GB limit */
   14.16      {
   14.17          xc_dom_printf
   14.18              ("%s: size (zip %zd, unzip %zd) looks insane, skip gunzip\n",
    15.1 --- a/tools/libxc/xc_domain_save.c	Fri Apr 27 13:25:58 2007 +0100
    15.2 +++ b/tools/libxc/xc_domain_save.c	Fri Apr 27 13:31:09 2007 +0100
    15.3 @@ -870,7 +870,7 @@ int xc_domain_save(int xc_handle, int io
    15.4      }
    15.5  
    15.6      /* Get the size of the P2M table */
    15.7 -    p2m_size = xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &dom);
    15.8 +    p2m_size = xc_memory_op(xc_handle, XENMEM_maximum_gpfn, &dom) + 1;
    15.9  
   15.10      /* Domain is still running at this point */
   15.11      if ( live )
    16.1 --- a/tools/libxc/xc_hvm_build.c	Fri Apr 27 13:25:58 2007 +0100
    16.2 +++ b/tools/libxc/xc_hvm_build.c	Fri Apr 27 13:31:09 2007 +0100
    16.3 @@ -47,20 +47,15 @@ static void build_e820map(void *e820_pag
    16.4          mem_size = HVM_BELOW_4G_RAM_END;
    16.5      }
    16.6  
    16.7 -    /* 0x0-0x9F000: Ordinary RAM. */
    16.8 +    /* 0x0-0x9FC00: Ordinary RAM. */
    16.9      e820entry[nr_map].addr = 0x0;
   16.10 -    e820entry[nr_map].size = 0x9F000;
   16.11 +    e820entry[nr_map].size = 0x9FC00;
   16.12      e820entry[nr_map].type = E820_RAM;
   16.13      nr_map++;
   16.14  
   16.15 -    /*
   16.16 -     * 0x9F000-0x9F800: SMBIOS tables.
   16.17 -     * 0x9FC00-0xA0000: Extended BIOS Data Area (EBDA).
   16.18 -     * TODO: SMBIOS tables should be moved higher (>=0xE0000).
   16.19 -     *       They are unusually low in our memory map: could cause problems?
   16.20 -     */
   16.21 -    e820entry[nr_map].addr = 0x9F000;
   16.22 -    e820entry[nr_map].size = 0x1000;
   16.23 +    /* 0x9FC00-0xA0000: Extended BIOS Data Area (EBDA). */
   16.24 +    e820entry[nr_map].addr = 0x9FC00;
   16.25 +    e820entry[nr_map].size = 0x400;
   16.26      e820entry[nr_map].type = E820_RESERVED;
   16.27      nr_map++;
   16.28  
    17.1 --- a/tools/python/xen/xend/XendAPI.py	Fri Apr 27 13:25:58 2007 +0100
    17.2 +++ b/tools/python/xen/xend/XendAPI.py	Fri Apr 27 13:31:09 2007 +0100
    17.3 @@ -27,7 +27,7 @@ import time
    17.4  import xmlrpclib
    17.5  
    17.6  import XendDomain, XendDomainInfo, XendNode, XendDmesg
    17.7 -import XendLogging, XendTaskManager
    17.8 +import XendLogging, XendTaskManager, XendAPIStore
    17.9  
   17.10  from XendAPIVersion import *
   17.11  from XendAuthSessions import instance as auth_manager
   17.12 @@ -38,8 +38,8 @@ from XendNetwork import XendNetwork
   17.13  from XendTask import XendTask
   17.14  from XendPIFMetrics import XendPIFMetrics
   17.15  from XendVMMetrics import XendVMMetrics
   17.16 -
   17.17 -import XendPBD
   17.18 +from XendPIF import XendPIF
   17.19 +from XendPBD import XendPBD
   17.20  
   17.21  from XendAPIConstants import *
   17.22  from xen.util.xmlrpclib2 import stringify
   17.23 @@ -237,6 +237,8 @@ def catch_typeerror(func):
   17.24                      finally:
   17.25                          del tb
   17.26              raise
   17.27 +        except XendAPIError, exn:
   17.28 +            return xen_api_error(exn.get_api_error())
   17.29  
   17.30      return f
   17.31  
   17.32 @@ -307,26 +309,6 @@ def valid_vm(func):
   17.33             _check_ref(XendDomain.instance().is_valid_vm,
   17.34                        'VM', func, *args, **kwargs)
   17.35  
   17.36 -def valid_vm_metrics(func):
   17.37 -    """Decorator to verify if vm_metrics_ref is valid before calling method.
   17.38 -
   17.39 -    @param func: function with params: (self, session, vm_metrics_ref, ...)
   17.40 -    @rtype: callable object
   17.41 -    """    
   17.42 -    return lambda *args, **kwargs: \
   17.43 -           _check_ref(XendVMMetrics.is_valid_vm_metrics,
   17.44 -                      'VM_metrics', func, *args, **kwargs)
   17.45 -
   17.46 -def valid_network(func):
   17.47 -    """Decorator to verify if network_ref is valid before calling method.
   17.48 -
   17.49 -    @param func: function with params: (self, session, network_ref, ...)
   17.50 -    @rtype: callable object
   17.51 -    """    
   17.52 -    return lambda *args, **kwargs: \
   17.53 -           _check_ref(XendNode.instance().is_valid_network,
   17.54 -                      'network', func, *args, **kwargs)
   17.55 -
   17.56  def valid_vbd(func):
   17.57      """Decorator to verify if vbd_ref is valid before calling method.
   17.58  
   17.59 @@ -409,39 +391,6 @@ def valid_sr(func):
   17.60             _check_ref(lambda r: XendNode.instance().is_valid_sr,
   17.61                        'SR', func, *args, **kwargs)
   17.62  
   17.63 -def valid_pbd(func):
   17.64 -    """Decorator to verify if pbd_ref is valid before calling
   17.65 -    method.
   17.66 -
   17.67 -    @param func: function with params: (self, session, pbd_ref)
   17.68 -    @rtype: callable object
   17.69 -    """
   17.70 -    return lambda *args, **kwargs: \
   17.71 -           _check_ref(lambda r: r in XendPBD.get_all_refs(),
   17.72 -                      'PBD', func, *args, **kwargs)
   17.73 -
   17.74 -def valid_pif(func):
   17.75 -    """Decorator to verify if pif_ref is valid before calling
   17.76 -    method.
   17.77 -
   17.78 -    @param func: function with params: (self, session, pif_ref)
   17.79 -    @rtype: callable object
   17.80 -    """
   17.81 -    return lambda *args, **kwargs: \
   17.82 -           _check_ref(lambda r: r in XendNode.instance().pifs,
   17.83 -                      'PIF', func, *args, **kwargs)
   17.84 -
   17.85 -def valid_pif_metrics(func):
   17.86 -    """Decorator to verify if pif_metrics_ref is valid before calling
   17.87 -    method.
   17.88 -
   17.89 -    @param func: function with params: (self, session, pif_metrics_ref)
   17.90 -    @rtype: callable object
   17.91 -    """
   17.92 -    return lambda *args, **kwargs: \
   17.93 -           _check_ref(lambda r: r in XendNode.instance().pif_metrics,
   17.94 -                      'PIF_metrics', func, *args, **kwargs)
   17.95 -
   17.96  def valid_task(func):
   17.97      """Decorator to verify if task_ref is valid before calling
   17.98      method.
   17.99 @@ -464,6 +413,20 @@ def valid_debug(func):
  17.100             _check_ref(lambda r: r in XendAPI._debug,
  17.101                        'debug', func, *args, **kwargs)
  17.102  
  17.103 +
  17.104 +def valid_object(class_name):
  17.105 +    """Decorator to verify if object is valid before calling
  17.106 +    method.
  17.107 +
  17.108 +    @param func: function with params: (self, session, pif_ref)
  17.109 +    @rtype: callable object
  17.110 +    """
  17.111 +    return lambda func: \
  17.112 +           lambda *args, **kwargs: \
  17.113 +           _check_ref(lambda r: \
  17.114 +                          XendAPIStore.get(r, class_name) is not None,
  17.115 +                      'PIF', func, *args, **kwargs)
  17.116 +
  17.117  # -----------------------------
  17.118  # Bridge to Legacy XM API calls
  17.119  # -----------------------------
  17.120 @@ -494,9 +457,7 @@ classes = {
  17.121      'host'         : valid_host,
  17.122      'host_cpu'     : valid_host_cpu,
  17.123      'host_metrics' : valid_host_metrics,
  17.124 -    'network'      : valid_network,
  17.125      'VM'           : valid_vm,
  17.126 -    'VM_metrics'   : valid_vm_metrics,
  17.127      'VBD'          : valid_vbd,
  17.128      'VBD_metrics'  : valid_vbd_metrics,
  17.129      'VIF'          : valid_vif,
  17.130 @@ -505,21 +466,23 @@ classes = {
  17.131      'VTPM'         : valid_vtpm,
  17.132      'console'      : valid_console,
  17.133      'SR'           : valid_sr,
  17.134 -    'PBD'          : valid_pbd,
  17.135 -    'PIF'          : valid_pif,
  17.136 -    'PIF_metrics'  : valid_pif_metrics,
  17.137      'task'         : valid_task,
  17.138      'debug'        : valid_debug,
  17.139 +    'network'      : valid_object("network"),
  17.140 +    'PIF'          : valid_object("PIF"),
  17.141 +    'VM_metrics'   : valid_object("VM_metrics"),
  17.142 +    'PBD'          : valid_object("PBD"),
  17.143 +    'PIF_metrics'  : valid_object("PIF_metrics")
  17.144  }
  17.145  
  17.146  autoplug_classes = {
  17.147      'network'     : XendNetwork,
  17.148 +    'PIF'         : XendPIF,
  17.149      'VM_metrics'  : XendVMMetrics,
  17.150 -    'PBD'         : XendPBD.XendPBD,
  17.151 +    'PBD'         : XendPBD,
  17.152      'PIF_metrics' : XendPIFMetrics,
  17.153  }
  17.154  
  17.155 -
  17.156  class XendAPI(object):
  17.157      """Implementation of the Xen-API in Xend. Expects to be
  17.158      used via XMLRPCServer.
  17.159 @@ -570,7 +533,9 @@ class XendAPI(object):
  17.160          #    all get_by_uuid() methods.
  17.161          
  17.162          for api_cls in classes.keys():
  17.163 -            if api_cls == 'session':
  17.164 +            # We'll let the autoplug classes implement these functions
  17.165 +            # themselves - its much cleaner to do it in the base class
  17.166 +            if api_cls == 'session' or api_cls in autoplug_classes.keys():
  17.167                  continue
  17.168              
  17.169              get_by_uuid = '%s_get_by_uuid' % api_cls
  17.170 @@ -599,34 +564,48 @@ class XendAPI(object):
  17.171          # --------------------
  17.172          # These have all of their methods grabbed out from the implementation
  17.173          # class, and wrapped up to be compatible with the Xen-API.
  17.174 +
  17.175 +        def getter(ref, type):
  17.176 +            return XendAPIStore.get(ref, type)
  17.177          
  17.178          for api_cls, impl_cls in autoplug_classes.items():
  17.179 -            def doit(n):
  17.180 -                getter = getattr(cls, '_%s_get' % api_cls)
  17.181 +            def doit(n):           
  17.182                  dot_n = '%s.%s' % (api_cls, n)
  17.183                  full_n = '%s_%s' % (api_cls, n)
  17.184                  if not hasattr(cls, full_n):
  17.185                      f = getattr(impl_cls, n)
  17.186                      argcounts[dot_n] = f.func_code.co_argcount + 1
  17.187 -                    setattr(cls, full_n,
  17.188 +                    g = lambda api_cls: \
  17.189 +                    setattr(cls, full_n, \
  17.190                              lambda s, session, ref, *args: \
  17.191                                 xen_api_success( \
  17.192 -                                   f(getter(s, session, ref), *args)))
  17.193 +                                   f(getter(ref, api_cls), *args)))
  17.194 +                    g(api_cls) # Force api_cls to be captured
  17.195 +                    
  17.196 +            def doit_func(n):           
  17.197 +                dot_n = '%s.%s' % (api_cls, n)
  17.198 +                full_n = '%s_%s' % (api_cls, n)
  17.199 +                if not hasattr(cls, full_n):
  17.200 +                    f = getattr(impl_cls, n)
  17.201 +                    argcounts[dot_n] = f.func_code.co_argcount
  17.202 +                    setattr(cls, full_n, \
  17.203 +                            lambda s, session, *args: \
  17.204 +                               xen_api_success( \
  17.205 +                                   f(*args)))
  17.206  
  17.207 -            ro_attrs = getattr(cls, '%s_attr_ro' % api_cls, [])
  17.208 -            rw_attrs = getattr(cls, '%s_attr_rw' % api_cls, [])
  17.209 -            methods  = getattr(cls, '%s_methods' % api_cls, [])
  17.210 -            funcs    = getattr(cls, '%s_funcs'   % api_cls, [])
  17.211 +            ro_attrs = impl_cls.getAttrRO()
  17.212 +            rw_attrs = impl_cls.getAttrRW()
  17.213 +            methods  = impl_cls.getMethods()
  17.214 +            funcs    = impl_cls.getFuncs()
  17.215              
  17.216              for attr_name in ro_attrs + rw_attrs:
  17.217                  doit('get_%s' % attr_name)
  17.218 -            for attr_name in rw_attrs + cls.Base_attr_rw:
  17.219 +            for attr_name in rw_attrs:
  17.220                  doit('set_%s' % attr_name)
  17.221 -            for method_name, return_type in methods + cls.Base_methods:
  17.222 -                doit('%s' % method_name)
  17.223 -            for func_name, return_type in funcs + cls.Base_funcs:
  17.224 -                doit('%s' % func_name)
  17.225 -
  17.226 +            for method in methods:
  17.227 +                doit('%s' % method)
  17.228 +            for func in funcs:
  17.229 +                doit_func('%s' % func)
  17.230  
  17.231          def wrap_method(name, new_f):
  17.232              try:
  17.233 @@ -692,31 +671,42 @@ class XendAPI(object):
  17.234                  except AttributeError:
  17.235                      log.warn("API call: %s not found" % n)
  17.236  
  17.237 -
  17.238 -            ro_attrs = getattr(cls, '%s_attr_ro' % api_cls, [])
  17.239 -            rw_attrs = getattr(cls, '%s_attr_rw' % api_cls, [])
  17.240 -            methods  = getattr(cls, '%s_methods' % api_cls, [])
  17.241 -            funcs    = getattr(cls, '%s_funcs'   % api_cls, [])
  17.242 +            if api_cls in autoplug_classes.keys():
  17.243 +                impl_cls = autoplug_classes[api_cls]
  17.244 +                ro_attrs = impl_cls.getAttrRO()
  17.245 +                rw_attrs = impl_cls.getAttrRW()
  17.246 +                methods  = map(lambda x: (x, ""), impl_cls.getMethods())
  17.247 +                funcs    = map(lambda x: (x, ""), impl_cls.getFuncs())
  17.248 +            else:
  17.249 +                ro_attrs = getattr(cls, '%s_attr_ro' % api_cls, []) \
  17.250 +                           + cls.Base_attr_ro
  17.251 +                rw_attrs = getattr(cls, '%s_attr_rw' % api_cls, []) \
  17.252 +                           + cls.Base_attr_rw
  17.253 +                methods  = getattr(cls, '%s_methods' % api_cls, []) \
  17.254 +                           + cls.Base_methods
  17.255 +                funcs    = getattr(cls, '%s_funcs'   % api_cls, []) \
  17.256 +                           + cls.Base_funcs
  17.257  
  17.258              # wrap validators around readable class attributes
  17.259 -            for attr_name in ro_attrs + rw_attrs + cls.Base_attr_ro:
  17.260 +            for attr_name in ro_attrs + rw_attrs:
  17.261                  doit('%s.get_%s' % (api_cls, attr_name), True,
  17.262                       async_support = False)
  17.263  
  17.264              # wrap validators around writable class attrributes
  17.265 -            for attr_name in rw_attrs + cls.Base_attr_rw:
  17.266 +            for attr_name in rw_attrs:
  17.267                  doit('%s.set_%s' % (api_cls, attr_name), True,
  17.268                       async_support = False)
  17.269                  setter_event_wrapper(api_cls, attr_name)
  17.270  
  17.271              # wrap validators around methods
  17.272 -            for method_name, return_type in methods + cls.Base_methods:
  17.273 +            for method_name, return_type in methods:
  17.274                  doit('%s.%s' % (api_cls, method_name), True,
  17.275                       async_support = True)
  17.276  
  17.277              # wrap validators around class functions
  17.278 -            for func_name, return_type in funcs + cls.Base_funcs:
  17.279 -                doit('%s.%s' % (api_cls, func_name), False, async_support = True,
  17.280 +            for func_name, return_type in funcs:
  17.281 +                doit('%s.%s' % (api_cls, func_name), False,
  17.282 +                     async_support = True,
  17.283                       return_type = return_type)
  17.284  
  17.285              ctor_event_wrapper(api_cls)
  17.286 @@ -952,7 +942,7 @@ class XendAPI(object):
  17.287      def host_get_resident_VMs(self, session, host_ref):
  17.288          return xen_api_success(XendDomain.instance().get_domain_refs())
  17.289      def host_get_PBDs(self, _, ref):
  17.290 -        return xen_api_success(XendPBD.get_all_refs())
  17.291 +        return xen_api_success(XendPBD.get_all())
  17.292      def host_get_PIFs(self, session, ref):
  17.293          return xen_api_success(XendNode.instance().get_PIF_refs())
  17.294      def host_get_host_CPUs(self, session, host_ref):
  17.295 @@ -1131,130 +1121,6 @@ class XendAPI(object):
  17.296          node = XendNode.instance()
  17.297          return node.xc.physinfo()['free_memory'] * 1024
  17.298  
  17.299 -
  17.300 -    # Xen API: Class network
  17.301 -    # ----------------------------------------------------------------
  17.302 -
  17.303 -    network_attr_ro = ['VIFs', 'PIFs']
  17.304 -    network_attr_rw = ['name_label',
  17.305 -                       'name_description',
  17.306 -                       'other_config']
  17.307 -    network_methods = [('add_to_other_config', None),
  17.308 -                       ('remove_from_other_config', None),
  17.309 -                       ('destroy', None)]
  17.310 -    network_funcs = [('create', None)]
  17.311 -    
  17.312 -    def _network_get(self, _, ref):
  17.313 -        return XendNode.instance().get_network(ref)
  17.314 -
  17.315 -    def network_get_all(self, _):
  17.316 -        return xen_api_success(XendNode.instance().get_network_refs())
  17.317 -
  17.318 -    def network_create(self, _, record):
  17.319 -        return xen_api_success(XendNode.instance().network_create(record))
  17.320 -
  17.321 -    def network_destroy(self, _, ref):
  17.322 -        return xen_api_success(XendNode.instance().network_destroy(ref))
  17.323 -
  17.324 -
  17.325 -    # Xen API: Class PIF
  17.326 -    # ----------------------------------------------------------------
  17.327 -
  17.328 -    PIF_attr_ro = ['network',
  17.329 -                   'host',
  17.330 -                   'metrics']
  17.331 -    PIF_attr_rw = ['device',
  17.332 -                   'MAC',
  17.333 -                   'MTU',
  17.334 -                   'VLAN']
  17.335 -
  17.336 -    PIF_attr_inst = PIF_attr_rw
  17.337 -
  17.338 -    PIF_methods = [('create_VLAN', 'int'), ('destroy', None)]
  17.339 -
  17.340 -    def _get_PIF(self, ref):
  17.341 -        return XendNode.instance().pifs[ref]
  17.342 -
  17.343 -    def PIF_destroy(self, _, ref):
  17.344 -        try:
  17.345 -            return xen_api_success(XendNode.instance().PIF_destroy(ref))
  17.346 -        except PIFIsPhysical, exn:
  17.347 -            return xen_api_error(['PIF_IS_PHYSICAL', ref])
  17.348 -
  17.349 -    # object methods
  17.350 -    def PIF_get_record(self, _, ref):
  17.351 -        return xen_api_success(self._get_PIF(ref).get_record())
  17.352 -
  17.353 -    def PIF_get_all(self, _):
  17.354 -        return xen_api_success(XendNode.instance().pifs.keys())
  17.355 -
  17.356 -    def PIF_get_metrics(self, _, ref):
  17.357 -        return xen_api_success(self._get_PIF(ref).metrics.uuid)
  17.358 -
  17.359 -    def PIF_get_device(self, _, ref):
  17.360 -        return xen_api_success(self._get_PIF(ref).device)
  17.361 -
  17.362 -    def PIF_get_network(self, _, ref):
  17.363 -        return xen_api_success(self._get_PIF(ref).network.uuid)
  17.364 -
  17.365 -    def PIF_get_host(self, _, ref):
  17.366 -        return xen_api_success(self._get_PIF(ref).host.uuid)
  17.367 -
  17.368 -    def PIF_get_MAC(self, _, ref):
  17.369 -        return xen_api_success(self._get_PIF(ref).mac)
  17.370 -
  17.371 -    def PIF_get_MTU(self, _, ref):
  17.372 -        return xen_api_success(self._get_PIF(ref).mtu)
  17.373 -
  17.374 -    def PIF_get_VLAN(self, _, ref):
  17.375 -        return xen_api_success(self._get_PIF(ref).vlan)
  17.376 -
  17.377 -    def PIF_set_device(self, _, ref, device):
  17.378 -        return xen_api_success(self._get_PIF(ref).set_device(device))
  17.379 -
  17.380 -    def PIF_set_MAC(self, _, ref, mac):
  17.381 -        return xen_api_success(self._get_PIF(ref).set_mac(mac))
  17.382 -
  17.383 -    def PIF_set_MTU(self, _, ref, mtu):
  17.384 -        return xen_api_success(self._get_PIF(ref).set_mtu(mtu))
  17.385 -
  17.386 -    def PIF_create_VLAN(self, _, ref, network, vlan):
  17.387 -        try:
  17.388 -            vlan = int(vlan)
  17.389 -        except:
  17.390 -            return xen_api_error(['VLAN_TAG_INVALID', vlan])
  17.391 -
  17.392 -        try:
  17.393 -            node = XendNode.instance()
  17.394 -            
  17.395 -            if _is_valid_ref(network, node.is_valid_network):
  17.396 -                return xen_api_success(
  17.397 -                    node.PIF_create_VLAN(ref, network, vlan))
  17.398 -            else:
  17.399 -                return xen_api_error(['HANDLE_INVALID', 'network', network])
  17.400 -        except NetworkAlreadyConnected, exn:
  17.401 -            return xen_api_error(['NETWORK_ALREADY_CONNECTED',
  17.402 -                                  network, exn.pif_uuid])
  17.403 -        except VLANTagInvalid:
  17.404 -            return xen_api_error(['VLAN_TAG_INVALID', vlan])
  17.405 -
  17.406 -
  17.407 -    # Xen API: Class PIF_metrics
  17.408 -    # ----------------------------------------------------------------
  17.409 -
  17.410 -    PIF_metrics_attr_ro = ['io_read_kbs',
  17.411 -                           'io_write_kbs',
  17.412 -                           'last_updated']
  17.413 -    PIF_metrics_attr_rw = []
  17.414 -    PIF_metrics_methods = []
  17.415 -
  17.416 -    def PIF_metrics_get_all(self, _):
  17.417 -        return xen_api_success(XendNode.instance().pif_metrics.keys())
  17.418 -
  17.419 -    def _PIF_metrics_get(self, _, ref):
  17.420 -        return XendNode.instance().pif_metrics[ref]
  17.421 -
  17.422 -
  17.423      # Xen API: Class VM
  17.424      # ----------------------------------------------------------------        
  17.425  
  17.426 @@ -1865,28 +1731,6 @@ class XendAPI(object):
  17.427          return xen_api_success_void()
  17.428  
  17.429  
  17.430 -    # Xen API: Class VM_metrics
  17.431 -    # ----------------------------------------------------------------
  17.432 -
  17.433 -    VM_metrics_attr_ro = ['memory_actual',
  17.434 -                          'VCPUs_number',
  17.435 -                          'VCPUs_utilisation',
  17.436 -                          'VCPUs_CPU',
  17.437 -                          'VCPUs_flags',
  17.438 -                          'VCPUs_params',
  17.439 -                          'state',
  17.440 -                          'start_time',
  17.441 -                          'last_updated']
  17.442 -    VM_metrics_attr_rw = []
  17.443 -    VM_metrics_methods = []
  17.444 -
  17.445 -    def _VM_metrics_get(self, _, ref):
  17.446 -        return XendVMMetrics.get_by_uuid(ref)
  17.447 -
  17.448 -    def VM_metrics_get_all(self, _):
  17.449 -        return xen_api_success(XendVMMetrics.get_all())
  17.450 -
  17.451 -
  17.452      # Xen API: Class VBD
  17.453      # ----------------------------------------------------------------
  17.454  
  17.455 @@ -2570,33 +2414,6 @@ class XendAPI(object):
  17.456          return xen_api_success_void()
  17.457  
  17.458  
  17.459 -    # Xen API: Class PBD
  17.460 -    # ----------------------------------------------------------------
  17.461 -
  17.462 -    PBD_attr_ro = ['host',
  17.463 -                   'SR',
  17.464 -                   'device_config',
  17.465 -                   'currently_attached']
  17.466 -    PBD_attr_rw = []
  17.467 -    PBD_methods = [('destroy', None)]
  17.468 -    PBD_funcs   = [('create', None)]
  17.469 -
  17.470 -    def PBD_get_all(self, _):
  17.471 -        return xen_api_success(XendPBD.get_all_refs())
  17.472 -
  17.473 -    def _PBD_get(self, _, ref):
  17.474 -        return XendPBD.get(ref)
  17.475 -
  17.476 -    def PBD_create(self, _, record):
  17.477 -        if 'uuid' in record:
  17.478 -            return xen_api_error(['VALUE_NOT_SUPPORTED',
  17.479 -                                  'uuid', record['uuid'],
  17.480 -                                  'You may not specify a UUID on creation'])
  17.481 -        new_uuid = XendPBD.XendPBD(record).get_uuid()
  17.482 -        XendNode.instance().save()
  17.483 -        return xen_api_success(new_uuid)
  17.484 -
  17.485 -
  17.486      # Xen API: Class event
  17.487      # ----------------------------------------------------------------
  17.488  
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tools/python/xen/xend/XendAPIStore.py	Fri Apr 27 13:31:09 2007 +0100
    18.3 @@ -0,0 +1,59 @@
    18.4 +#============================================================================
    18.5 +# This library is free software; you can redistribute it and/or
    18.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
    18.7 +# License as published by the Free Software Foundation.
    18.8 +#
    18.9 +# This library is distributed in the hope that it will be useful,
   18.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   18.12 +# Lesser General Public License for more details.
   18.13 +#
   18.14 +# You should have received a copy of the GNU Lesser General Public
   18.15 +# License along with this library; if not, write to the Free Software
   18.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18.17 +#============================================================================
   18.18 +# Copyright (C) 2007 Tom Wilkie <tom.wilkie@gmail.com>
   18.19 +#============================================================================
   18.20 +"""
   18.21 +This is a place to put instances of XenAPI objects,
   18.22 +instead of just holding them in arbitrary places.
   18.23 +
   18.24 +All objects which subclass XendBase should use this
   18.25 +mechanism.
   18.26 +
   18.27 +You must register both the uuid and type, and get objects
   18.28 +by type, to ensure safety
   18.29 +"""
   18.30 +
   18.31 +__classes = {}
   18.32 +
   18.33 +def register(uuid, type, inst):
   18.34 +    __classes[(uuid, type)] = inst
   18.35 +    return inst
   18.36 +
   18.37 +def deregister(uuid, type):
   18.38 +    old = get(uuid, type)
   18.39 +    del __classes[(uuid, type)]
   18.40 +    return old
   18.41 +
   18.42 +def get(uuid, type):
   18.43 +    """
   18.44 +    Get the instances by uuid and type
   18.45 +    """
   18.46 +    return __classes.get((uuid, type), None)
   18.47 +
   18.48 +def get_all(all_type):
   18.49 +    """
   18.50 +    Get all instances by type
   18.51 +    """
   18.52 +    return [inst
   18.53 +            for ((uuid, t), inst) in __classes.items()
   18.54 +            if t == all_type]        
   18.55 +
   18.56 +def get_all_uuid(all_type):
   18.57 +    """
   18.58 +    Get all uuids by type
   18.59 +    """
   18.60 +    return [uuid
   18.61 +            for (uuid, t) in __classes.keys()
   18.62 +            if t == all_type]
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/tools/python/xen/xend/XendBase.py	Fri Apr 27 13:31:09 2007 +0100
    19.3 @@ -0,0 +1,126 @@
    19.4 +#!/usr/bin/python
    19.5 +#============================================================================
    19.6 +# This library is free software; you can redistribute it and/or
    19.7 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
    19.8 +# License as published by the Free Software Foundation.
    19.9 +#
   19.10 +# This library is distributed in the hope that it will be useful,
   19.11 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.12 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   19.13 +# Lesser General Public License for more details.
   19.14 +#
   19.15 +# You should have received a copy of the GNU Lesser General Public
   19.16 +# License along with this library; if not, write to the Free Software
   19.17 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19.18 +#============================================================================
   19.19 +# Copyright (C) 2007 Tom Wilkie <tom.wilkie@gmail.com>
   19.20 +#============================================================================
   19.21 +"""
   19.22 +Base class for all XenAPI classes
   19.23 +"""
   19.24 +
   19.25 +from xen.xend.XendError import *
   19.26 +from xen.xend import XendAPIStore
   19.27 +
   19.28 +class XendBase:
   19.29 +    #
   19.30 +    # These functions describe the object, and what is exposed via the API
   19.31 +    #
   19.32 +    def getClass(self):
   19.33 +        return "Base"
   19.34 +    
   19.35 +    def getAttrRO(self):
   19.36 +        return ['uuid']
   19.37 +
   19.38 +    def getAttrRW(self):
   19.39 +        return []
   19.40 +
   19.41 +    def getAttrInst(self):
   19.42 +        return []
   19.43 +
   19.44 +    def getMethods(self):
   19.45 +        return ["get_record"]
   19.46 +
   19.47 +    def getFuncs(self):
   19.48 +        return ["get_all", "get_by_uuid", "get_all_records"]
   19.49 +
   19.50 +    getClass    = classmethod(getClass)
   19.51 +    getAttrRO   = classmethod(getAttrRO)
   19.52 +    getAttrRW   = classmethod(getAttrRW)
   19.53 +    getAttrInst = classmethod(getAttrInst)
   19.54 +    getMethods  = classmethod(getMethods)
   19.55 +    getFuncs    = classmethod(getFuncs)
   19.56 +    
   19.57 +    def __init__(self, uuid, record):
   19.58 +        self.__uuid = uuid
   19.59 +        
   19.60 +        # First check this class implements all the correct methods:
   19.61 +        for attr_ro in self.getAttrRO() + self.getAttrRW():
   19.62 +            if not hasattr(self, "get_%s" % attr_ro):
   19.63 +                raise ImplementationError(self.getClass(),
   19.64 +                                          "get_%s" % attr_ro)
   19.65 +
   19.66 +        for attr_rw in self.getAttrRW():
   19.67 +            if not hasattr(self, "set_%s" % attr_rw):
   19.68 +                raise ImplementationError(self.getClass(),
   19.69 +                                          "set_%s" % attr_rw)
   19.70 +
   19.71 +        for method in self.getMethods():
   19.72 +            if not hasattr(self, method):
   19.73 +                raise ImplementationError(self.getClass(),
   19.74 +                                          method)
   19.75 +
   19.76 +        for func in self.getFuncs():
   19.77 +            if not hasattr(self.__class__, func):
   19.78 +                raise ImplementationError(self.getClass(),
   19.79 +                                          func)
   19.80 +
   19.81 +        # Next check that the class is being created with the correct
   19.82 +        # parameters
   19.83 +        if not isinstance(record, dict):
   19.84 +            raise CreateUnspecifiedAttributeError(
   19.85 +                    "record" , self.getClass())
   19.86 +        
   19.87 +        for attr_inst in self.getAttrInst():
   19.88 +            if attr_inst not in record:
   19.89 +                raise CreateUnspecifiedAttributeError(
   19.90 +                    attr_inst, self.getClass())
   19.91 +            setattr(self, attr_inst, record[attr_inst])
   19.92 +
   19.93 +        # Finally register it
   19.94 +        XendAPIStore.register(uuid, self.getClass(), self)
   19.95 +
   19.96 +    def destroy(self):
   19.97 +        XendAPIStore.deregister(self.get_uuid(), self.getClass())
   19.98 +
   19.99 +    def get_uuid(self):
  19.100 +        return self.__uuid
  19.101 +
  19.102 +    def get_record(self):
  19.103 +        keys = self.getAttrRO() + self.getAttrRW()
  19.104 +        return dict([(key, getattr(self, "get_%s" % key)())
  19.105 +                     for key in keys])
  19.106 +
  19.107 +    #
  19.108 +    # Class methods
  19.109 +    #
  19.110 +
  19.111 +    def get_all(cls):
  19.112 +        return XendAPIStore.get_all_uuid(cls.getClass())
  19.113 +
  19.114 +    def get_by_uuid(cls, uuid):
  19.115 +        # Sanity check the uuid is one of us
  19.116 +        me = XendAPIStore.get(uuid, cls.getClass())
  19.117 +        if me is not None and me.getClass() == cls.getClass():
  19.118 +            # In OSS, ref == uuid
  19.119 +            return uuid
  19.120 +        else:
  19.121 +            raise "Big Error.. TODO!"
  19.122 +
  19.123 +    def get_all_records(cls):
  19.124 +        return [inst.get_record()
  19.125 +                for inst in XendAPIStore.get_all(cls.getClass())]
  19.126 +
  19.127 +    get_all = classmethod(get_all)
  19.128 +    get_by_uuid = classmethod(get_by_uuid)
  19.129 +    get_all_records = classmethod(get_all_records)
    20.1 --- a/tools/python/xen/xend/XendConfig.py	Fri Apr 27 13:25:58 2007 +0100
    20.2 +++ b/tools/python/xen/xend/XendConfig.py	Fri Apr 27 13:31:09 2007 +0100
    20.3 @@ -22,6 +22,7 @@ import types
    20.4  
    20.5  from xen.xend import sxp
    20.6  from xen.xend import uuid
    20.7 +from xen.xend import XendAPIStore
    20.8  from xen.xend.XendError import VmError
    20.9  from xen.xend.XendDevices import XendDevices
   20.10  from xen.xend.PrettyPrint import prettyprintstring
   20.11 @@ -341,7 +342,7 @@ class XendConfig(dict):
   20.12      # try and 'fix it up' but acutually fix the cause ;-)
   20.13      #
   20.14      def _memory_sanity_check(self):
   20.15 -        log.debug("_memory_sanity_check memory_static_min: %s, "
   20.16 +        log.trace("_memory_sanity_check memory_static_min: %s, "
   20.17                        "memory_static_max: %i, "
   20.18                        "memory_dynamic_min: %i, " 
   20.19                        "memory_dynamic_max: %i",
   20.20 @@ -1049,6 +1050,10 @@ class XendConfig(dict):
   20.21                      dev_info['type'] = cfg_xenapi.get('type')
   20.22                  if cfg_xenapi.get('name'):
   20.23                      dev_info['name'] = cfg_xenapi.get('name')
   20.24 +                if cfg_xenapi.get('network'):
   20.25 +                    network = XendAPIStore.get(
   20.26 +                        cfg_xenapi.get('network'), 'network')
   20.27 +                    dev_info['bridge'] = network.get_name_label()
   20.28                  
   20.29                  dev_uuid = cfg_xenapi.get('uuid', None)
   20.30                  if not dev_uuid:
    21.1 --- a/tools/python/xen/xend/XendDomain.py	Fri Apr 27 13:25:58 2007 +0100
    21.2 +++ b/tools/python/xen/xend/XendDomain.py	Fri Apr 27 13:31:09 2007 +0100
    21.3 @@ -293,10 +293,12 @@ class XendDomain:
    21.4                                  width = 78)
    21.5                  finally:
    21.6                      f.close()
    21.7 +                    
    21.8                  try:
    21.9 -                    os.rename(fn, self._managed_config_path(dom_uuid))
   21.10 +                    shutil.move(fn, self._managed_config_path(dom_uuid))
   21.11                  except:
   21.12 -                    log.exception("Renaming %s" % fn)
   21.13 +                    log.exception("Renaming %s to %s", fn,
   21.14 +                                  self._managed_config_path(dom_uuid))
   21.15                      os.remove(fn)
   21.16              except:
   21.17                  log.exception("Error occurred saving configuration file " +
    22.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Fri Apr 27 13:25:58 2007 +0100
    22.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Apr 27 13:31:09 2007 +0100
    22.3 @@ -1820,7 +1820,7 @@ class XendDomainInfo:
    22.4                      log.info("Unmounting %s from %s." %
    22.5                               (fn, BOOTLOADER_LOOPBACK_DEVICE))
    22.6  
    22.7 -                    dom0.destroyDevice('tap', '/dev/xvdp')
    22.8 +                    dom0.destroyDevice('tap', BOOTLOADER_LOOPBACK_DEVICE)
    22.9  
   22.10              if blcfg is None:
   22.11                  msg = "Had a bootloader specified, but can't find disk"
   22.12 @@ -2246,9 +2246,18 @@ class XendDomainInfo:
   22.13  
   22.14              if not config.has_key('network'):
   22.15                  try:
   22.16 +                    bridge = config.get('bridge', None)
   22.17 +                    if bridge is None:
   22.18 +                        from xen.util import Brctl
   22.19 +                        if_to_br = dict([(i,b)
   22.20 +                            for (b,ifs) in Brctl.get_state().items()
   22.21 +                                for i in ifs])
   22.22 +                        vifname = "vif%s.%s" % (self.getDomid(),
   22.23 +                                                config.get('id'))
   22.24 +                        bridge = if_to_br.get(vifname, None)
   22.25                      config['network'] = \
   22.26                          XendNode.instance().bridge_to_network(
   22.27 -                        config.get('bridge')).uuid
   22.28 +                        config.get('bridge')).get_uuid()
   22.29                  except Exception:
   22.30                      log.exception('bridge_to_network')
   22.31                      # Ignore this for now -- it may happen if the device
    23.1 --- a/tools/python/xen/xend/XendError.py	Fri Apr 27 13:25:58 2007 +0100
    23.2 +++ b/tools/python/xen/xend/XendError.py	Fri Apr 27 13:31:09 2007 +0100
    23.3 @@ -48,10 +48,6 @@ class PIFIsPhysical(XendError):
    23.4      def __init__(self):
    23.5          XendError.__init__(self, 'PIF is physical')
    23.6  
    23.7 -class VLANTagInvalid(XendError):
    23.8 -    def __init__(self):
    23.9 -        XendError.__init__(self, 'VLAN tag invalid')
   23.10 -
   23.11  class VmError(XendError):
   23.12      """Vm construction error."""
   23.13      pass
   23.14 @@ -62,7 +58,123 @@ class HVMRequired(VmError):
   23.15                             'HVM guest support is unavailable: is VT/AMD-V '
   23.16                             'supported by your CPU and enabled in your BIOS?')
   23.17  
   23.18 +class XendAPIError(XendError):
   23.19 +    """Extend this class for all error thrown by
   23.20 +    autoplugged classes"""
   23.21 +    def __init__(self):
   23.22 +        XendError.__init__(self, 'XendAPI Error: You should never see this'
   23.23 +                           ' message; this class need to be overidden')
   23.24  
   23.25 +    def get_api_error(self):
   23.26 +        return ['INTERNAL_ERROR', 'You should never see this message; '
   23.27 +                'this method needs to be overidden']
   23.28 +
   23.29 +class CreateUnspecifiedAttributeError(XendAPIError):
   23.30 +    def __init__(self, attr_name, class_name):
   23.31 +        XendAPIError.__init__(self)
   23.32 +        self.attr_name = attr_name
   23.33 +        self.class_name = class_name
   23.34 +
   23.35 +    def get_api_error(self):
   23.36 +        return ['CREATE_UNSPECIFIED_ATTRIBUTE', self.attr_name,
   23.37 +                self.class_name]
   23.38 +
   23.39 +    def __str__(self):
   23.40 +        return "CREATE_UNSPECIFIED_ATTRIBUTE: %s, %s" % (self.attr_name,
   23.41 +                 self.class_name)
   23.42 +
   23.43 +class UnmanagedNetworkError(XendAPIError):
   23.44 +    def __init__(self, attr_name):
   23.45 +        XendAPIError.__init__(self)
   23.46 +        self.attr_name = attr_name
   23.47 +
   23.48 +    def get_api_error(self):
   23.49 +        return ['UNMANAGED_NETWORK_ERROR', self.attr_name]
   23.50 +
   23.51 +    def __str__(self):
   23.52 +        return "UNMANAGED_NETWORK_ERROR: %s" % self.attr_name
   23.53 +
   23.54 +class UniqueNameError(XendAPIError):
   23.55 +    def __init__(self, name, class_name):
   23.56 +        XendAPIError.__init__(self)
   23.57 +        self.name = name
   23.58 +        self.class_name = class_name
   23.59 +        
   23.60 +    def get_api_error(self):
   23.61 +        return ['UNIQUE_NAME_ERROR', self.name, self.class_name]        
   23.62 +
   23.63 +    def __str__(self):
   23.64 +        return 'UNIQUE_NAME_ERROR: %s, %s' % (self.name, self.class_name)
   23.65 +
   23.66 +class InvalidDeviceError(XendAPIError):
   23.67 +    def __init__(self, dev):
   23.68 +        XendAPIError.__init__(self)
   23.69 +        self.dev = dev
   23.70 +        
   23.71 +    def get_api_error(self):
   23.72 +        return ['INVALID_DEVICE_ERROR', self.dev]        
   23.73 +
   23.74 +    def __str__(self):
   23.75 +        return 'INVALID_DEVICE_ERROR: %s' % self.dev
   23.76 +    
   23.77 +class DeviceExistsError(XendAPIError):
   23.78 +    def __init__(self, dev):
   23.79 +        XendAPIError.__init__(self)
   23.80 +        self.dev = dev
   23.81 +        
   23.82 +    def get_api_error(self):
   23.83 +        return ['DEVICE_EXISTS_ERROR', self.dev]        
   23.84 +
   23.85 +    def __str__(self):
   23.86 +        return 'DEVICE_EXISTS_ERROR: %s' % self.dev
   23.87 +
   23.88 +class InvalidHandleError(XendAPIError):
   23.89 +    def __init__(self, klass, handle):
   23.90 +        XendAPIError.__init__(self)
   23.91 +        self.klass = klass
   23.92 +        self.handle = handle
   23.93 +        
   23.94 +    def get_api_error(self):
   23.95 +        return ['HANDLE_INVALID', self.klass, self.handle]        
   23.96 +
   23.97 +    def __str__(self):
   23.98 +        return 'HANDLE_INVALID: %s %s' % (self.klass, self.handle)
   23.99 +
  23.100 +class ImplementationError(XendAPIError):
  23.101 +    def __init__(self, klass, func):
  23.102 +        XendAPIError.__init__(self)
  23.103 +        self.klass = klass
  23.104 +        self.func = func
  23.105 +
  23.106 +    def get_api_error(self):
  23.107 +        return ['IMPLEMENTATION_ERROR', self.klass, self.func]        
  23.108 +
  23.109 +    def __str__(self):
  23.110 +        return 'IMPLEMENTATION_ERROR: %s %s' % (self.klass, self.func)
  23.111 +
  23.112 +class VLANTagInvalid(XendAPIError):
  23.113 +    def __init__(self, vlan):
  23.114 +        XendAPIError.__init__(self)
  23.115 +        self.vlan = vlan
  23.116 +
  23.117 +    def get_api_error(self):
  23.118 +        return ['VLAN_TAG_INVALID', self.vlan]
  23.119 +
  23.120 +    def __str__(self):
  23.121 +        return 'VLAN_TAG_INVALID: %s' % self.vlan
  23.122 +
  23.123 +class NetworkError(XendAPIError):
  23.124 +    def __init__(self, error, network):
  23.125 +        XendAPIError.__init__(self)
  23.126 +        self.network = network
  23.127 +        self.error = error
  23.128 +
  23.129 +    def get_api_error(self):
  23.130 +        return ['NETWORK_ERROR', self.error, self.network]
  23.131 +
  23.132 +    def __str__(self):
  23.133 +        return 'NETWORK_ERROR: %s %s' % (self.error, self.network)
  23.134 +    
  23.135  XEND_ERROR_AUTHENTICATION_FAILED = ('ELUSER', 'Authentication Failed')
  23.136  XEND_ERROR_SESSION_INVALID       = ('EPERMDENIED', 'Session Invalid')
  23.137  XEND_ERROR_DOMAIN_INVALID        = ('EINVALIDDOMAIN', 'Domain Invalid')
    24.1 --- a/tools/python/xen/xend/XendNetwork.py	Fri Apr 27 13:25:58 2007 +0100
    24.2 +++ b/tools/python/xen/xend/XendNetwork.py	Fri Apr 27 13:31:09 2007 +0100
    24.3 @@ -24,15 +24,139 @@ import socket
    24.4  import XendDomain
    24.5  import XendNode
    24.6  from XendLogging import log
    24.7 +from xen.xend import uuid as genuuid
    24.8 +from xen.xend.XendBase import XendBase
    24.9 +from xen.xend.XendError import *
   24.10 +from xen.util import Brctl
   24.11 +from xen.xend import XendAPIStore
   24.12  
   24.13  IP_ROUTE_RE = r'^default via ([\d\.]+) dev (\w+)'
   24.14  
   24.15 -class XendNetwork:
   24.16 -    def __init__(self, uuid, record):
   24.17 -        self.uuid = uuid
   24.18 -        self.name_label = record.get('name_label', '')
   24.19 -        self.name_description = record.get('name_description', '')
   24.20 -        self.other_config = record.get('other_config', {})
   24.21 +def bridge_exists(name):
   24.22 +    return name in Brctl.get_state().keys()
   24.23 +
   24.24 +class XendNetwork(XendBase):
   24.25 +    """We're going to assert that the name_label of this
   24.26 +    network is just the name of the bridge"""
   24.27 +
   24.28 +    def getClass(self):
   24.29 +        return "network"
   24.30 +
   24.31 +    def getAttrRW(self):
   24.32 +        attrRW = ['name_label',
   24.33 +                  'name_description',
   24.34 +                  'other_config',
   24.35 +                  'default_gateway',
   24.36 +                  'default_netmask']
   24.37 +        return XendBase.getAttrRW() + attrRW
   24.38 +
   24.39 +    def getAttrRO(self):
   24.40 +        attrRO =  ['VIFs',
   24.41 +                   'PIFs']
   24.42 +        return XendBase.getAttrRO() + attrRO
   24.43 +
   24.44 +    def getAttrInst(self):
   24.45 +        return XendBase.getAttrInst() + self.getAttrRW()
   24.46 +
   24.47 +    def getMethods(self):
   24.48 +        methods = ['add_to_other_config',
   24.49 +                   'remove_from_other_config',
   24.50 +                   'destroy']
   24.51 +        return XendBase.getMethods() + methods
   24.52 +
   24.53 +    def getFuncs(self):
   24.54 +        funcs = ['create']
   24.55 +        return XendBase.getFuncs() + funcs
   24.56 +
   24.57 +    getClass    = classmethod(getClass)
   24.58 +    getAttrRO   = classmethod(getAttrRO)
   24.59 +    getAttrRW   = classmethod(getAttrRW)
   24.60 +    getAttrInst = classmethod(getAttrInst)
   24.61 +    getMethods  = classmethod(getMethods)
   24.62 +    getFuncs    = classmethod(getFuncs)
   24.63 +
   24.64 +    def create_phy(self, name):
   24.65 +        """
   24.66 +        Called when a new bridge is found on xend start
   24.67 +        """
   24.68 +        # Create new uuids
   24.69 +        uuid = genuuid.createString()
   24.70 +
   24.71 +        # Create instance
   24.72 +        record = {
   24.73 +                'name_label':       name,
   24.74 +                'name_description': '',
   24.75 +                'other_config':     {},
   24.76 +                'default_gateway':  '',
   24.77 +                'default_netmask':  ''
   24.78 +            }
   24.79 +        network = XendNetwork(record, uuid)
   24.80 +
   24.81 +        return uuid
   24.82 +        
   24.83 +    def recreate(self, record, uuid):
   24.84 +        """
   24.85 +        Called on xend start / restart, or machine
   24.86 +        restart, when read from saved config.
   24.87 +        Needs to check network exists, create it otherwise
   24.88 +        """
   24.89 +
   24.90 +        # Create instance (do this first, to check record)
   24.91 +        network = XendNetwork(record, uuid)
   24.92 +
   24.93 +        # Create network if it doesn't already exist
   24.94 +        if not bridge_exists(network.name_label):
   24.95 +            Brctl.bridge_create(network.name_label)
   24.96 +
   24.97 +        return uuid
   24.98 +
   24.99 +    def create(self, record):
  24.100 +        """
  24.101 +        Called from API, to create a new network
  24.102 +        """
  24.103 +        # Create new uuids
  24.104 +        uuid = genuuid.createString()
  24.105 +
  24.106 +        # Create instance (do this first, to check record)
  24.107 +        network = XendNetwork(record, uuid)
  24.108 +
  24.109 +        # Check network doesn't already exist
  24.110 +        name_label = network.name_label
  24.111 +        if bridge_exists(name_label):
  24.112 +            del network
  24.113 +            raise UniqueNameError(name_label, "network")
  24.114 +
  24.115 +        # Create the bridge
  24.116 +        Brctl.bridge_create(network.name_label)
  24.117 +
  24.118 +        XendNode.instance().save_networks()
  24.119 +
  24.120 +        return uuid
  24.121 +
  24.122 +    create_phy  = classmethod(create_phy)
  24.123 +    recreate    = classmethod(recreate)
  24.124 +    create      = classmethod(create)
  24.125 +        
  24.126 +    def __init__(self, record, uuid):       
  24.127 +        XendBase.__init__(self, uuid, record)
  24.128 +        
  24.129 +    #
  24.130 +    # XenAPI Mehtods
  24.131 +    #
  24.132 +
  24.133 +    def destroy(self):
  24.134 +        # check no VIFs or PIFs attached
  24.135 +        if len(self.get_VIFs()) > 0:
  24.136 +            raise NetworkError("Cannot destroy network with VIFs attached",
  24.137 +                               self.get_name_label())
  24.138 +
  24.139 +        if len(self.get_PIFs()) > 0:
  24.140 +            raise NetworkError("Cannot destroy network with PIFs attached",
  24.141 +                               self.get_name_label())        
  24.142 +        
  24.143 +        XendBase.destroy(self)
  24.144 +        Brctl.bridge_del(self.get_name_label())
  24.145 +        XendNode.instance().save_networks()
  24.146  
  24.147      def get_name_label(self):
  24.148          return self.name_label
  24.149 @@ -41,9 +165,8 @@ class XendNetwork:
  24.150          return self.name_description
  24.151  
  24.152      def set_name_label(self, new_name):
  24.153 -        self.name_label = new_name
  24.154 -        XendNode.instance().save_networks()
  24.155 -
  24.156 +        pass
  24.157 +        
  24.158      def set_name_description(self, new_desc):
  24.159          self.name_description = new_desc
  24.160          XendNode.instance().save_networks()
  24.161 @@ -55,13 +178,14 @@ class XendNetwork:
  24.162              vifs = vm.get_vifs()
  24.163              for vif in vifs:
  24.164                  vif_cfg = vm.get_dev_xenapi_config('vif', vif)
  24.165 -                if vif_cfg.get('network') == self.uuid:
  24.166 +                if vif_cfg.get('network') == self.get_uuid():
  24.167                      result.append(vif)
  24.168          return result
  24.169  
  24.170      def get_PIFs(self):
  24.171 -        return [x.uuid for x in XendNode.instance().pifs.values()
  24.172 -                if x.network == self]
  24.173 +        pifs = XendAPIStore.get_all("PIF")
  24.174 +        return [pif.get_uuid() for pif in pifs
  24.175 +                if pif.get_network() == self.get_uuid()]
  24.176  
  24.177      def get_other_config(self):
  24.178          return self.other_config
  24.179 @@ -79,17 +203,16 @@ class XendNetwork:
  24.180              del self.other_config[key]
  24.181          XendNode.instance().save_networks()
  24.182  
  24.183 -    def get_record(self):
  24.184 -        return self.get_record_internal(True)
  24.185 +    def get_default_gateway(self):
  24.186 +        return self.default_gateway
  24.187 +
  24.188 +    def set_default_gateway(self, gateway):
  24.189 +        self.default_gateway = gateway
  24.190 +        XendNode.instance().save_networks()
  24.191  
  24.192 -    def get_record_internal(self, transient):
  24.193 -        result = {
  24.194 -            'uuid': self.uuid,
  24.195 -            'name_label': self.name_label,
  24.196 -            'name_description': self.name_description,
  24.197 -            'other_config' : self.other_config,
  24.198 -        }
  24.199 -        if transient:
  24.200 -            result['VIFs'] = self.get_VIFs()
  24.201 -            result['PIFs'] = self.get_PIFs()
  24.202 -        return result
  24.203 +    def get_default_netmask(self):
  24.204 +        return self.default_netmask
  24.205 +
  24.206 +    def set_default_netmask(self, netmask):
  24.207 +        self.default_netmask = netmask
  24.208 +        XendNode.instance().save_networks()
    25.1 --- a/tools/python/xen/xend/XendNode.py	Fri Apr 27 13:25:58 2007 +0100
    25.2 +++ b/tools/python/xen/xend/XendNode.py	Fri Apr 27 13:31:09 2007 +0100
    25.3 @@ -21,9 +21,10 @@ import socket
    25.4  import xen.lowlevel.xc
    25.5  
    25.6  from xen.util import Brctl
    25.7 +from xen.xend import XendAPIStore
    25.8  
    25.9  import uuid, arch
   25.10 -import XendPBD
   25.11 +from XendPBD import XendPBD
   25.12  from XendError import *
   25.13  from XendOptions import instance as xendoptions
   25.14  from XendQCoWStorageRepo import XendQCoWStorageRepo
   25.15 @@ -34,7 +35,7 @@ from XendPIFMetrics import XendPIFMetric
   25.16  from XendNetwork import *
   25.17  from XendStateStore import XendStateStore
   25.18  from XendMonitor import XendMonitor
   25.19 -
   25.20 +     
   25.21  class XendNode:
   25.22      """XendNode - Represents a Domain 0 Host."""
   25.23      
   25.24 @@ -133,70 +134,78 @@ class XendNode:
   25.25                        'features' : cpu_features,
   25.26                      })
   25.27  
   25.28 -        self.pifs = {}
   25.29 -        self.pif_metrics = {}
   25.30 -        self.networks = {}
   25.31          self.srs = {}
   25.32 -        
   25.33 -        # initialise networks
   25.34 +
   25.35 +        # Initialise networks
   25.36 +        # First configure ones off disk
   25.37          saved_networks = self.state_store.load_state('network')
   25.38          if saved_networks:
   25.39              for net_uuid, network in saved_networks.items():
   25.40 -                self.network_create(network, False, net_uuid)
   25.41 -        else:
   25.42 -            bridges = Brctl.get_state().keys()
   25.43 -            for bridge in bridges:
   25.44 -                self.network_create({'name_label' : bridge }, False)
   25.45 +                try:
   25.46 +                    XendNetwork.recreate(network, net_uuid)
   25.47 +                except CreateUnspecifiedAttributeError:
   25.48 +                    log.warn("Error recreating network %s", net_uuid)
   25.49                  
   25.50 -        # Get a mapping from interface to bridge
   25.51 +        # Next discover any existing bridges and check
   25.52 +        # they are not already configured
   25.53 +        bridges = Brctl.get_state().keys()
   25.54 +        configured_bridges = [XendAPIStore.get(
   25.55 +                                  network_uuid, "network")
   25.56 +                                      .get_name_label()
   25.57 +                              for network_uuid in XendNetwork.get_all()]
   25.58 +        unconfigured_bridges = [bridge
   25.59 +                                for bridge in bridges
   25.60 +                                if bridge not in configured_bridges]
   25.61 +        for unconfigured_bridge in unconfigured_bridges:
   25.62 +            XendNetwork.create_phy(unconfigured_bridge)
   25.63  
   25.64 -        if_to_br = dict([(i,b)
   25.65 -                         for (b,ifs) in Brctl.get_state().items()
   25.66 -                         for i in ifs])
   25.67 -
   25.68 -        # initialise PIFs
   25.69 +        # Initialise PIFs
   25.70 +        # First configure ones off disk
   25.71          saved_pifs = self.state_store.load_state('pif')
   25.72          if saved_pifs:
   25.73              for pif_uuid, pif in saved_pifs.items():
   25.74 -                if pif.get('network') in self.networks:
   25.75 -                    network = self.networks[pif['network']]
   25.76 -                    try:
   25.77 -                        if 'device' not in pif and 'name' in pif:
   25.78 -                            # Compatibility hack, can go pretty soon.
   25.79 -                            pif['device'] = pif['name']
   25.80 -                        if 'metrics' not in pif:
   25.81 -                            # Compatibility hack, can go pretty soon.
   25.82 -                            pif['metrics'] = uuid.createString()
   25.83 -
   25.84 -                        try:
   25.85 -                            pif['VLAN'] = int(pif.get('VLAN', -1))
   25.86 -                        except (ValueError, TypeError):
   25.87 -                            pif['VLAN'] = -1
   25.88 +                try:
   25.89 +                    XendPIF.recreate(pif, pif_uuid)
   25.90 +                except CreateUnspecifiedAttributeError:
   25.91 +                    log.warn("Error recreating PIF %s", pif_uuid)
   25.92 +        
   25.93 +        # Next discover any existing PIFs and check
   25.94 +        # they are not already configured
   25.95 +        configured_pifs = [XendAPIStore.get(
   25.96 +                               pif_uuid, "PIF")
   25.97 +                                   .get_interface_name()
   25.98 +                           for pif_uuid in XendPIF.get_all()]
   25.99 +        unconfigured_pifs = [(name, mtu, mac)
  25.100 +                             for name, mtu, mac in linux_get_phy_ifaces()
  25.101 +                             if name not in configured_pifs]
  25.102  
  25.103 -                        self._PIF_create(pif['device'], pif['MTU'],
  25.104 -                                         pif['VLAN'],
  25.105 -                                         pif['MAC'], network, False, pif_uuid,
  25.106 -                                         pif['metrics'])
  25.107 -                    except NetworkAlreadyConnected, exn:
  25.108 -                        log.error('Cannot load saved PIF %s, as network %s ' +
  25.109 -                                  'is already connected to PIF %s',
  25.110 -                                  pif_uuid, pif['network'], exn.pif_uuid)
  25.111 -        else:
  25.112 -            for name, mtu, mac in linux_get_phy_ifaces():
  25.113 -                bridge_name = if_to_br.get(name, None)
  25.114 -                if bridge_name is not None:
  25.115 -                    networks = [network for
  25.116 -                                network in self.networks.values()
  25.117 -                                if network.get_name_label() == bridge_name]
  25.118 -                    if len(networks) > 0:
  25.119 -                        network = networks[0]
  25.120 -                        self._PIF_create(name, mtu, -1, mac, network, False)
  25.121 +        # Get a mapping from interface to bridge          
  25.122 +        if_to_br = dict([(i,b)
  25.123 +                         for (b,ifs) in Brctl.get_state().items()
  25.124 +                             for i in ifs])
  25.125  
  25.126 +        for name, mtu, mac in unconfigured_pifs:
  25.127 +            # Check PIF is on bridge
  25.128 +            # if not, ignore
  25.129 +            bridge_name = if_to_br.get(name, None)
  25.130 +            if bridge_name is not None:
  25.131 +                # Translate bridge name to network uuid
  25.132 +                for network_uuid in XendNetwork.get_all():
  25.133 +                    network = XendAPIStore.get(
  25.134 +                        network_uuid, 'network')
  25.135 +                    if network.get_name_label() == bridge_name:
  25.136 +                        XendPIF.create_phy(network_uuid, name,
  25.137 +                                           mtu, mac)
  25.138 +                        break
  25.139 +                else:
  25.140 +                    log.debug("Cannot find network for bridge %s "
  25.141 +                              "when configuring PIF %s",
  25.142 +                              (bridge_name, name))     
  25.143 +        
  25.144          # initialise storage
  25.145          saved_srs = self.state_store.load_state('sr')
  25.146          if saved_srs:
  25.147              for sr_uuid, sr_cfg in saved_srs.items():
  25.148 -                log.error("SAved SRS %s %s", sr_uuid, sr_cfg['type'])
  25.149                  if sr_cfg['type'] == 'qcow_file':
  25.150                      self.srs[sr_uuid] = XendQCoWStorageRepo(sr_uuid)
  25.151                  elif sr_cfg['type'] == 'local':
  25.152 @@ -214,69 +223,50 @@ class XendNode:
  25.153          saved_pbds = self.state_store.load_state('pbd')
  25.154          if saved_pbds:
  25.155              for pbd_uuid, pbd_cfg in saved_pbds.items():
  25.156 -                pbd_cfg['uuid'] = pbd_uuid
  25.157 -                XendPBD.XendPBD(pbd_cfg)
  25.158 -
  25.159 +                try:
  25.160 +                    XendPBD.recreate(pbd_uuid, pbd_cfg)
  25.161 +                except CreateUnspecifiedAttributeError:
  25.162 +                    log.warn("Error recreating PBD %s", pbd_uuid) 
  25.163  
  25.164 -    def network_create(self, record, persist = True, net_uuid = None):
  25.165 -        if net_uuid is None:
  25.166 -            net_uuid = uuid.createString()
  25.167 -        self.networks[net_uuid] = XendNetwork(net_uuid, record)
  25.168 -        if persist:
  25.169 -            self.save_networks()
  25.170 -        return net_uuid
  25.171 -
  25.172 -
  25.173 -    def network_destroy(self, net_uuid):
  25.174 -        del self.networks[net_uuid]
  25.175 -        self.save_networks()
  25.176 -
  25.177 -
  25.178 -    def get_PIF_refs(self):
  25.179 -        return self.pifs.keys()
  25.180 +##    def network_destroy(self, net_uuid):
  25.181 + ##       del self.networks[net_uuid]
  25.182 +  ##      self.save_networks()
  25.183  
  25.184  
  25.185 -    def _PIF_create(self, name, mtu, vlan, mac, network, persist = True,
  25.186 -                    pif_uuid = None, metrics_uuid = None):
  25.187 -        for pif in self.pifs.values():
  25.188 -            if pif.network == network:
  25.189 -                raise NetworkAlreadyConnected(pif.uuid)
  25.190 +##    def get_PIF_refs(self):
  25.191 +##       return self.pifs[:]
  25.192  
  25.193 -        if pif_uuid is None:
  25.194 -            pif_uuid = uuid.createString()
  25.195 -        if metrics_uuid is None:
  25.196 -            metrics_uuid = uuid.createString()
  25.197 +##   def _PIF_create(self, name, mtu, vlan, mac, network, persist = True,
  25.198 +##                     pif_uuid = None, metrics_uuid = None):
  25.199 +##         for pif in self.pifs.values():
  25.200 +##             if pif.network == network:
  25.201 +##                 raise NetworkAlreadyConnected(pif.uuid)
  25.202  
  25.203 -        metrics = XendPIFMetrics(metrics_uuid)
  25.204 -        pif = XendPIF(pif_uuid, metrics, name, mtu, vlan, mac, network, self)
  25.205 -        metrics.set_PIF(pif)
  25.206 -
  25.207 -        self.pif_metrics[metrics_uuid] = metrics
  25.208 -        self.pifs[pif_uuid] = pif
  25.209 +##         if pif_uuid is None:
  25.210 +##             pif_uuid = uuid.createString()
  25.211 +##         if metrics_uuid is None:
  25.212 +##             metrics_uuid = uuid.createString()
  25.213  
  25.214 -        if persist:
  25.215 -            self.save_PIFs()
  25.216 -            self.refreshBridges()
  25.217 -        return pif_uuid
  25.218 +##         metrics = XendPIFMetrics(metrics_uuid)
  25.219 +##         pif = XendPIF(pif_uuid, metrics, name, mtu, vlan, mac, network, self)
  25.220 +##         metrics.set_PIF(pif)
  25.221  
  25.222 +##         self.pif_metrics[metrics_uuid] = metrics
  25.223 +##         self.pifs[pif_uuid] = pif
  25.224  
  25.225 -    def PIF_create_VLAN(self, pif_uuid, network_uuid, vlan):
  25.226 -        if vlan < 0 or vlan >= 4096:
  25.227 -            raise VLANTagInvalid()
  25.228 -            
  25.229 -        pif = self.pifs[pif_uuid]
  25.230 -        network = self.networks[network_uuid]
  25.231 -        return self._PIF_create(pif.device, pif.mtu, vlan, pif.mac, network)
  25.232 -
  25.233 +##         if persist:
  25.234 +##             self.save_PIFs()
  25.235 +##             self.refreshBridges()
  25.236 +##         return pif_uuid
  25.237  
  25.238 -    def PIF_destroy(self, pif_uuid):
  25.239 -        pif = self.pifs[pif_uuid]
  25.240 +##     def PIF_destroy(self, pif_uuid):
  25.241 +##         pif = self.pifs[pif_uuid]
  25.242  
  25.243 -        if pif.vlan == -1:
  25.244 -            raise PIFIsPhysical()
  25.245 +##         if pif.vlan == -1:
  25.246 +##             raise PIFIsPhysical()
  25.247  
  25.248 -        del self.pifs[pif_uuid]
  25.249 -        self.save_PIFs()
  25.250 +##         del self.pifs[pif_uuid]
  25.251 +##         self.save_PIFs()
  25.252  
  25.253  
  25.254      def save(self):
  25.255 @@ -284,7 +274,7 @@ class XendNode:
  25.256          host_record = {self.uuid: {'name_label':self.name,
  25.257                                     'name_description':self.desc,
  25.258                                     'metrics_uuid': self.host_metrics_uuid,
  25.259 -                                   'other_config': repr(self.other_config)}}
  25.260 +                                   'other_config': self.other_config}}
  25.261          self.state_store.save_state('host',host_record)
  25.262          self.state_store.save_state('cpu', self.cpus)
  25.263          self.save_PIFs()
  25.264 @@ -293,18 +283,21 @@ class XendNode:
  25.265          self.save_SRs()
  25.266  
  25.267      def save_PIFs(self):
  25.268 -        pif_records = dict([(k, v.get_record())
  25.269 -                            for k, v in self.pifs.items()])
  25.270 +        pif_records = dict([(pif_uuid, XendAPIStore.get(
  25.271 +                                 pif_uuid, "PIF").get_record())
  25.272 +                            for pif_uuid in XendPIF.get_all()])
  25.273          self.state_store.save_state('pif', pif_records)
  25.274  
  25.275      def save_networks(self):
  25.276 -        net_records = dict([(k, v.get_record_internal(False))
  25.277 -                            for k, v in self.networks.items()])
  25.278 +        net_records = dict([(network_uuid, XendAPIStore.get(
  25.279 +                                 network_uuid, "network").get_record())
  25.280 +                            for network_uuid in XendNetwork.get_all()])
  25.281          self.state_store.save_state('network', net_records)
  25.282  
  25.283      def save_PBDs(self):
  25.284 -        pbd_records = dict([(v.get_uuid(), v.get_record())
  25.285 -                            for v in XendPBD.get_all()])
  25.286 +        pbd_records = dict([(pbd_uuid, XendAPIStore.get(
  25.287 +                                 pbd_uuid, "PBD").get_record())
  25.288 +                            for pbd_uuid in XendPBD.get_all()])
  25.289          self.state_store.save_state('pbd', pbd_records)
  25.290  
  25.291      def save_SRs(self):
  25.292 @@ -331,9 +324,6 @@ class XendNode:
  25.293      def is_valid_cpu(self, cpu_ref):
  25.294          return (cpu_ref in self.cpus)
  25.295  
  25.296 -    def is_valid_network(self, network_ref):
  25.297 -        return (network_ref in self.networks)
  25.298 -
  25.299      def is_valid_sr(self, sr_ref):
  25.300          return (sr_ref in self.srs)
  25.301  
  25.302 @@ -495,12 +485,6 @@ class XendNode:
  25.303      # Network Functions
  25.304      #
  25.305      
  25.306 -    def get_network_refs(self):
  25.307 -        return self.networks.keys()
  25.308 -
  25.309 -    def get_network(self, network_ref):
  25.310 -        return self.networks[network_ref]
  25.311 -
  25.312      def bridge_to_network(self, bridge):
  25.313          """
  25.314          Determine which network a particular bridge is attached to.
  25.315 @@ -518,13 +502,12 @@ class XendNode:
  25.316                  raise Exception(
  25.317                      'Could not find default bridge, and none was specified')
  25.318  
  25.319 -        bridges = Brctl.get_state()
  25.320 -        if bridge not in bridges:
  25.321 -            raise Exception('Bridge %s is not up' % bridge)
  25.322 -        for pif in self.pifs.values():
  25.323 -            if pif.interface_name() in bridges[bridge]:
  25.324 -                return pif.network
  25.325 -        raise Exception('Bridge %s is not connected to a network' % bridge)
  25.326 +        for network_uuid in XendNetwork.get_all():
  25.327 +            network = XendAPIStore.get(network_uuid, "network")
  25.328 +            if network.get_name_label() == bridge:
  25.329 +                return network
  25.330 +        else:
  25.331 +            raise Exception('Cannot find network for bridge %s' % bridge)
  25.332  
  25.333      #
  25.334      # Debug keys.
  25.335 @@ -642,12 +625,6 @@ class XendNode:
  25.336      def info_dict(self):
  25.337          return dict(self.info())
  25.338  
  25.339 -
  25.340 -    def refreshBridges(self):
  25.341 -        for pif in self.pifs.values():
  25.342 -            pif.refresh(Brctl.get_state())
  25.343 -
  25.344 -
  25.345  def parse_proc_cpuinfo():
  25.346      cpuinfo = {}
  25.347      f = file('/proc/cpuinfo', 'r')
    26.1 --- a/tools/python/xen/xend/XendPBD.py	Fri Apr 27 13:25:58 2007 +0100
    26.2 +++ b/tools/python/xen/xend/XendPBD.py	Fri Apr 27 13:31:09 2007 +0100
    26.3 @@ -18,62 +18,82 @@
    26.4  
    26.5  import uuid
    26.6  from XendLogging import log
    26.7 -
    26.8 +from xen.xend.XendBase import XendBase
    26.9 +from xen.xend import XendAPIStore
   26.10  
   26.11 -attr_inst = ['uuid',
   26.12 -             'host',
   26.13 -             'SR',
   26.14 -             'device_config']
   26.15 -attr_ro = attr_inst + ['currently_attached']
   26.16 -
   26.17 +class XendPBD(XendBase):
   26.18 +    """Physical block devices."""
   26.19  
   26.20 -_all = {}
   26.21 -
   26.22 +    def getClass(self):
   26.23 +        return "PBD"
   26.24 +    
   26.25 +    def getAttrRO(self):
   26.26 +        attrRO = ['host',
   26.27 +                  'SR',
   26.28 +                  'device_config',
   26.29 +                  'currently_attached']
   26.30 +        return XendBase.getAttrRO() + attrRO
   26.31  
   26.32 -def get(ref):
   26.33 -    return _all[ref]
   26.34 -
   26.35 +    def getAttrRW(self):
   26.36 +        attrRW = []
   26.37 +        return XendBase.getAttrRW() + attrRW
   26.38  
   26.39 -def get_all():
   26.40 -    return _all.values()
   26.41 +    def getAttrInst(self):
   26.42 +        return ['uuid',
   26.43 +                'host',
   26.44 +                'SR',
   26.45 +                'device_config']
   26.46  
   26.47 +    def getMethods(self):
   26.48 +        methods = ['destroy']
   26.49 +        return XendBase.getMethods() + methods
   26.50  
   26.51 -def get_all_refs():
   26.52 -    return _all.keys()
   26.53 -
   26.54 +    def getFuncs(self):
   26.55 +        funcs = ['create',
   26.56 +                 'get_by_SR']
   26.57 +        return XendBase.getFuncs() + funcs
   26.58  
   26.59 -def get_by_SR(sr_ref):
   26.60 -    return [k for (k, v) in _all.items() if v.get_SR() == sr_ref]
   26.61 +    getClass    = classmethod(getClass)
   26.62 +    getAttrRO   = classmethod(getAttrRO)
   26.63 +    getAttrRW   = classmethod(getAttrRW)
   26.64 +    getAttrInst = classmethod(getAttrInst)
   26.65 +    getMethods  = classmethod(getMethods)
   26.66 +    getFuncs    = classmethod(getFuncs)
   26.67  
   26.68 -
   26.69 -class XendPBD:
   26.70 -    """Physical block devices."""
   26.71 +    def recreate(uuid, record):
   26.72 +        pbd = XendPBD(uuid, record)
   26.73 +        return uuid
   26.74      
   26.75 -    def __init__(self, record):
   26.76 -        if 'uuid' not in record:
   26.77 -            record['uuid'] = uuid.createString()
   26.78 +    def create(cls, record):
   26.79 +        uuid = genuuid.createString()
   26.80 +        pbd = XendPBD(uuid, record)
   26.81 +        return uuid       
   26.82 +
   26.83 +    create = classmethod(create)
   26.84 +    
   26.85 +    def __init__(self, uuid, record):
   26.86 +        XendBase.__init__(self, uuid, record)
   26.87 +        this.currently_attached = True
   26.88  
   26.89 -        import XendAPI
   26.90 -        for v in attr_inst:
   26.91 -            setattr(self, v, record[v])
   26.92 -        self.currently_attached = True
   26.93 -        _all[record['uuid']] = self
   26.94 +    def get_host(self):
   26.95 +        return this.host
   26.96 +    
   26.97 +    def get_SR(self):
   26.98 +        return this.SR
   26.99  
  26.100 +    def get_device_config(self):
  26.101 +        return this.device_config
  26.102 +
  26.103 +    def get_currently_attached(self):
  26.104 +        return this.currently_attached
  26.105  
  26.106      def destroy(self):
  26.107 -        if self.uuid in _all:
  26.108 -            del _all[self.uuid]
  26.109 -
  26.110 +        pass
  26.111 +    
  26.112 +    def get_by_SR(cls, sr_ref):
  26.113 +        pbds = XendAPIStore.get_all("PBD")
  26.114 +        return [pbd.get_uuid()
  26.115 +                for pbd in pbds
  26.116 +                if pbd.get_SR() == sr_ref]
  26.117  
  26.118 -    def get_record(self):
  26.119 -        import XendAPI
  26.120 -        result = {}
  26.121 -        for v in attr_ro:
  26.122 -            result[v] = getattr(self, v)
  26.123 -        return result
  26.124 -
  26.125 -
  26.126 -for v in attr_ro:
  26.127 -    def f(v_):
  26.128 -        setattr(XendPBD, 'get_' + v_, lambda s: getattr(s, v_))
  26.129 -    f(v)
  26.130 +    get_by_SR = classmethod(get_by_SR)
    27.1 --- a/tools/python/xen/xend/XendPIF.py	Fri Apr 27 13:25:58 2007 +0100
    27.2 +++ b/tools/python/xen/xend/XendPIF.py	Fri Apr 27 13:31:09 2007 +0100
    27.3 @@ -19,12 +19,15 @@ import commands
    27.4  import logging
    27.5  import os
    27.6  import re
    27.7 -
    27.8 +from xen.xend import uuid as genuuid
    27.9 +from xen.xend import XendAPIStore
   27.10 +from xen.xend.XendBase import XendBase
   27.11 +from xen.xend.XendPIFMetrics import XendPIFMetrics
   27.12 +from xen.xend.XendError import *
   27.13  
   27.14  log = logging.getLogger("xend.XendPIF")
   27.15  log.setLevel(logging.TRACE)
   27.16  
   27.17 -
   27.18  MAC_RE = re.compile(':'.join(['[0-9a-f]{2}'] * 6))
   27.19  IP_IFACE_RE = re.compile(r'^\d+: (\w+):.*mtu (\d+) .* link/\w+ ([0-9a-f:]+)')
   27.20  
   27.21 @@ -87,106 +90,279 @@ def linux_set_mtu(iface, mtu):
   27.22      except ValueError:
   27.23          return False
   27.24  
   27.25 -class XendPIF:
   27.26 +def _create_VLAN(dev, vlan):
   27.27 +    rc, _ = commands.getstatusoutput('vconfig add %s %d' %
   27.28 +                                     (dev, vlan))
   27.29 +    if rc != 0:
   27.30 +        return False
   27.31 +
   27.32 +    rc, _ = commands.getstatusoutput('ifconfig %s.%d up' %
   27.33 +                                     (dev, vlan))
   27.34 +    return rc == 0
   27.35 +
   27.36 +def _destroy_VLAN(dev, vlan):
   27.37 +    rc, _ = commands.getstatusoutput('ifconfig %s.%d down' %
   27.38 +                                     (dev, vlan))
   27.39 +    if rc != 0:
   27.40 +        return False
   27.41 +                                     
   27.42 +    rc, _ = commands.getstatusoutput('vconfig rem %s.%d' %
   27.43 +                                     (dev, vlan))
   27.44 +    return rc == 0
   27.45 +
   27.46 +class XendPIF(XendBase):
   27.47      """Representation of a Physical Network Interface."""
   27.48 +
   27.49 +    def getClass(self):
   27.50 +        return "PIF"
   27.51 +
   27.52 +    def getAttrRO(self):
   27.53 +        attrRO = ['network',
   27.54 +                  'host',
   27.55 +                  'metrics',
   27.56 +                  'device',
   27.57 +                  'VLAN']
   27.58 +        return XendBase.getAttrRO() + attrRO
   27.59 +    
   27.60 +    def getAttrRW(self):
   27.61 +        attrRW = ['MAC',
   27.62 +                  'MTU']
   27.63 +        return XendBase.getAttrRW() + attrRW
   27.64 +
   27.65 +    def getAttrInst(self):
   27.66 +        attrInst = ['network',
   27.67 +                    'device',
   27.68 +                    'MAC',
   27.69 +                    'MTU',
   27.70 +                    'VLAN']
   27.71 +        return attrInst
   27.72 +
   27.73 +    def getMethods(self):
   27.74 +        methods = ['plug',
   27.75 +                   'unplug',
   27.76 +                   'destroy']
   27.77 +        return XendBase.getMethods() + methods
   27.78 +
   27.79 +    def getFuncs(self):
   27.80 +        funcs = ['create_VLAN']
   27.81 +        return XendBase.getFuncs() + funcs
   27.82 +
   27.83 +    getClass    = classmethod(getClass)
   27.84 +    getAttrRO   = classmethod(getAttrRO)
   27.85 +    getAttrRW   = classmethod(getAttrRW)
   27.86 +    getAttrInst = classmethod(getAttrInst)
   27.87 +    getMethods  = classmethod(getMethods)
   27.88 +    getFuncs    = classmethod(getFuncs)
   27.89      
   27.90 -    def __init__(self, uuid, metrics, device, mtu, vlan, mac, network,
   27.91 -                 host):
   27.92 -        self.uuid = uuid
   27.93 -        self.metrics = metrics
   27.94 -        self.device = device
   27.95 -        self.mac = mac
   27.96 -        self.mtu = mtu
   27.97 -        self.vlan = vlan
   27.98 -        self.network = network
   27.99 -        self.host = host
  27.100 +    def create_phy(self, network_uuid, device,
  27.101 +                   MAC, MTU):
  27.102 +        """
  27.103 +        Called when a new physical PIF is found
  27.104 +        Could be a VLAN...
  27.105 +        """
  27.106 +        # Create new uuids
  27.107 +        pif_uuid = genuuid.createString()
  27.108 +        metrics_uuid = genuuid.createString()
  27.109 +
  27.110 +        # Create instances
  27.111 +        metrics = XendPIFMetrics(metrics_uuid, pif_uuid)
  27.112 +
  27.113 +        # Is this a VLAN?
  27.114 +        VLANdot = device.split(".")
  27.115 +        VLANcolon = device.split(":")
  27.116 +
  27.117 +        if len(VLANdot) > 1:
  27.118 +            VLAN = VLANdot[1]
  27.119 +            device = VLANdot[0]
  27.120 +        elif len(VLANcolon) > 1:
  27.121 +            VLAN = VLANcolon[1]
  27.122 +            device = VLANcolon[0] 
  27.123 +        else:
  27.124 +            VLAN = -1
  27.125 +            
  27.126 +        record = {
  27.127 +            'network': network_uuid,
  27.128 +            'device':  device,
  27.129 +            'MAC':     MAC,
  27.130 +            'MTU':     MTU,
  27.131 +            'VLAN':    VLAN
  27.132 +            }
  27.133 +        pif = XendPIF(record, pif_uuid, metrics_uuid)
  27.134 +
  27.135 +        return pif_uuid
  27.136 +
  27.137 +    def recreate(self, record, uuid):
  27.138 +        """Called on xend start / restart"""        
  27.139 +        pif_uuid = uuid
  27.140 +        metrics_uuid = record['metrics']
  27.141 +
  27.142 +        # Create instances
  27.143 +        metrics = XendPIFMetrics(metrics_uuid, pif_uuid)
  27.144 +        pif = XendPIF(record, pif_uuid, metrics_uuid)
  27.145 +
  27.146 +        # If physical PIF, check exists
  27.147 +        # If VLAN, create if not exist
  27.148 +        ifs = [dev for dev, _1, _2 in linux_get_phy_ifaces()]
  27.149 +        if pif.get_VLAN() == -1:
  27.150 +            if pif.get_device() not in ifs:
  27.151 +                pif.destroy()
  27.152 +                metrics.destroy()
  27.153 +                return None
  27.154 +        else:
  27.155 +            if pif.get_interface_name() not in ifs:
  27.156 +                _create_VLAN(pif.get_device(), pif.get_VLAN())
  27.157 +                pif.plug()
  27.158 +
  27.159 +        return pif_uuid
  27.160 +
  27.161 +    def create_VLAN(self, device, network_uuid, host_ref, vlan):
  27.162 +        """Exposed via API - create a new VLAN from existing VIF"""
  27.163 +        
  27.164 +        ifs = [name for name, _, _ in linux_get_phy_ifaces()]
  27.165  
  27.166 -    def set_device(self, new_device):
  27.167 -        self.device = new_device
  27.168 +        vlan = int(vlan)
  27.169 +
  27.170 +        # Check VLAN tag is valid
  27.171 +        if vlan < 0 or vlan >= 4096:
  27.172 +            raise VLANTagInvalid(vlan)
  27.173 +        
  27.174 +        # Check device exists
  27.175 +        if device not in ifs:
  27.176 +            raise InvalidDeviceError(device)
  27.177 +
  27.178 +        # Check VLAN doesn't already exist
  27.179 +        if "%s.%d" % (device, vlan) in ifs:
  27.180 +            raise DeviceExistsError("%s.%d" % (device, vlan))
  27.181 +
  27.182 +        # Check network ref is valid
  27.183 +        from XendNetwork import XendNetwork
  27.184 +        if network_uuid not in XendNetwork.get_all():
  27.185 +            raise InvalidHandleError("Network", network_uuid)
  27.186 +
  27.187 +        # Check host_ref is this host
  27.188 +        import XendNode
  27.189 +        if host_ref != XendNode.instance().get_uuid():
  27.190 +            raise InvalidHandleError("Host", host_ref)
  27.191 +
  27.192 +        # Create the VLAN
  27.193 +        _create_VLAN(device, vlan)
  27.194 +
  27.195 +        # Create new uuids
  27.196 +        pif_uuid = genuuid.createString()
  27.197 +        metrics_uuid = genuuid.createString()
  27.198 +
  27.199 +        # Create the record
  27.200 +        record = {
  27.201 +            "device":  device,
  27.202 +            "MAC":     '',
  27.203 +            "MTU":     '',
  27.204 +            "network": network_uuid,
  27.205 +            "VLAN":    vlan
  27.206 +            }
  27.207 +
  27.208 +        # Create instances
  27.209 +        metrics = XendPIFMetrics(metrics_uuid, pif_uuid)
  27.210 +        pif = XendPIF(record, pif_uuid, metrics_uuid)
  27.211 +
  27.212 +        # Not sure if they should be created plugged or not...
  27.213 +        pif.plug()
  27.214 +
  27.215 +        XendNode.instance().save_PIFs()
  27.216 +        return pif_uuid
  27.217 +
  27.218 +    create_phy  = classmethod(create_phy)
  27.219 +    recreate    = classmethod(recreate)
  27.220 +    create_VLAN = classmethod(create_VLAN)
  27.221 +    
  27.222 +    def __init__(self, record, uuid, metrics_uuid):
  27.223 +        XendBase.__init__(self, uuid, record)
  27.224 +        self.metrics = metrics_uuid
  27.225 +
  27.226 +    def plug(self):
  27.227 +        """Plug the PIF into the network"""
  27.228 +        network = XendAPIStore.get(self.network,
  27.229 +                                   "network")
  27.230 +        bridge_name = network.get_name_label()
  27.231  
  27.232 -    def set_mac(self, new_mac):
  27.233 -        success = linux_set_mac(new_mac)
  27.234 +        from xen.util import Brctl
  27.235 +        Brctl.vif_bridge_add({
  27.236 +            "bridge": bridge_name,
  27.237 +            "vif":    self.get_interface_name()
  27.238 +            })
  27.239 +
  27.240 +    def unplug(self):
  27.241 +        """Unplug the PIF from the network"""
  27.242 +        network = XendAPIStore.get(self.network,
  27.243 +                                   "network")
  27.244 +        bridge_name = network.get_name_label()
  27.245 +
  27.246 +        from xen.util import Brctl
  27.247 +        Brctl.vif_bridge_rem({
  27.248 +            "bridge": bridge_name,
  27.249 +            "vif":    self.get_interface_name()
  27.250 +            })
  27.251 +
  27.252 +    def destroy(self):
  27.253 +        # Figure out if this is a physical device
  27.254 +        if self.get_interface_name() == \
  27.255 +           self.get_device():
  27.256 +            raise PIFIsPhysical(self.get_uuid())
  27.257 +
  27.258 +        self.unplug()
  27.259 +
  27.260 +        if _destroy_VLAN(self.get_device(), self.get_VLAN()):
  27.261 +            XendBase.destroy(self)
  27.262 +            import XendNode
  27.263 +            XendNode.instance().save_PIFs()
  27.264 +        else:
  27.265 +            raise NetworkError("Unable to delete VLAN", self.get_uuid())
  27.266 +
  27.267 +    def get_interface_name(self):
  27.268 +        if self.get_VLAN() == -1:
  27.269 +            return self.get_device()
  27.270 +        else:
  27.271 +            return "%s.%d" % (self.get_device(), self.get_VLAN())
  27.272 +        
  27.273 +    def get_device(self):
  27.274 +        """
  27.275 +        This is the base interface.
  27.276 +        For phy if (VLAN == -1) this is same as
  27.277 +        if name.
  27.278 +        For VLANs, this it the bit before the period
  27.279 +        """
  27.280 +        return self.device
  27.281 +
  27.282 +    def get_network(self):
  27.283 +        return self.network
  27.284 +
  27.285 +    def get_host(self):
  27.286 +        from xen.xend import XendNode
  27.287 +        return XendNode.instance().get_uuid()
  27.288 +
  27.289 +    def get_metrics(self):
  27.290 +        return self.metrics
  27.291 +
  27.292 +    def get_MAC(self):
  27.293 +        return self.MAC
  27.294 +
  27.295 +    def set_MAC(self, new_mac):
  27.296 +        success = linux_set_mac(self.device, new_mac)
  27.297          if success:
  27.298 -            self.mac = new_mac
  27.299 -        return success
  27.300 -
  27.301 -    def set_mtu(self, new_mtu):
  27.302 -        success = linux_set_mtu(new_mtu)
  27.303 -        if success:
  27.304 -            self.mtu = new_mtu
  27.305 +            self.MAC = new_mac
  27.306 +            import XendNode
  27.307 +            XendNode.instance().save_PIFs()
  27.308          return success
  27.309  
  27.310 -    def get_record(self):
  27.311 -        return {'uuid': self.uuid,
  27.312 -                'device': self.device,
  27.313 -                'MAC': self.mac,
  27.314 -                'MTU': self.mtu,
  27.315 -                'VLAN': self.vlan,
  27.316 -                'host': self.host.uuid,
  27.317 -                'network': self.network.uuid,
  27.318 -                'metrics': self.metrics.uuid}
  27.319 -
  27.320 -    def refresh(self, bridges):
  27.321 -        ifname = self.interface_name()
  27.322 -        rc, _ = _cmd('ip link show %s', ifname)
  27.323 -        if rc != 0:
  27.324 -            # Interface does not exist.  If it's a physical interface, then
  27.325 -            # there's nothing we can do -- this should have been set up with
  27.326 -            # the network script.  Otherwise, we can use vconfig to derive
  27.327 -            # a subinterface.
  27.328 -            if self.vlan == -1:
  27.329 -                return
  27.330 -            
  27.331 -            rc, _ = _cmd('vconfig add %s %d', self.device, self.vlan)
  27.332 -            if rc != 0:
  27.333 -                log.error('Could not refresh VLAN for interface %s', ifname)
  27.334 -                return
  27.335 -            
  27.336 -            log.info('Created network interface %s', ifname)
  27.337 -
  27.338 -        for brname, nics in bridges.items():
  27.339 -            if ifname in nics:
  27.340 -                log.debug('%s is already attached to %s', ifname, brname)
  27.341 -                return
  27.342 +    def get_MTU(self):
  27.343 +        return self.MTU
  27.344  
  27.345 -        # The interface is not attached to a bridge.  Create one, and attach
  27.346 -        # the interface to it.
  27.347 -        brname = _new_bridge_name(bridges)
  27.348 -        rc, _ = _cmd('brctl addbr %s', brname)
  27.349 -        if rc != 0:
  27.350 -            log.error('Could not create bridge %s for interface %s', brname,
  27.351 -                      ifname)
  27.352 -            return
  27.353 -        log.info('Created network bridge %s', brname)
  27.354 -        
  27.355 -        rc, _ = _cmd('brctl addif %s %s', brname, ifname)
  27.356 -        if rc != 0:
  27.357 -            log.error('Could not add %s to %s', ifname, brname)
  27.358 -            return
  27.359 -        log.info('Added network interface %s to bridge %s', ifname, brname)
  27.360 -
  27.361 +    def set_MTU(self, new_mtu):
  27.362 +        success = linux_set_mtu(self.device, new_mtu)
  27.363 +        if success:
  27.364 +            self.MTU = new_mtu
  27.365 +            import XendNode
  27.366 +            XendNode.instance().save_PIFs()
  27.367 +        return success
  27.368  
  27.369 -    def interface_name(self):
  27.370 -        if self.vlan != -1:
  27.371 -            return '%s.%d' % (self.device, self.vlan)
  27.372 -        else:
  27.373 -            return self.device
  27.374 -
  27.375 -
  27.376 -def _cmd(cmd, *args):
  27.377 -    if len(args) > 0:
  27.378 -        cmd = cmd % args
  27.379 -    rc, output = commands.getstatusoutput(cmd)
  27.380 -    if rc != 0:
  27.381 -        log.debug('%s failed with code %d' % (cmd, rc))
  27.382 -    log.trace('%s: %s' % (cmd, output))
  27.383 -    return rc, output
  27.384 -
  27.385 -
  27.386 -def _new_bridge_name(bridges):
  27.387 -    n = 0
  27.388 -    while True:
  27.389 -        brname = 'xenbr%d' % n
  27.390 -        if brname not in bridges:
  27.391 -            return brname
  27.392 -        n += 1
  27.393 +    def get_VLAN(self):
  27.394 +        return self.VLAN
    28.1 --- a/tools/python/xen/xend/XendPIFMetrics.py	Fri Apr 27 13:25:58 2007 +0100
    28.2 +++ b/tools/python/xen/xend/XendPIFMetrics.py	Fri Apr 27 13:31:09 2007 +0100
    28.3 @@ -15,15 +15,30 @@
    28.4  # Copyright (c) 2006-2007 Xensource Inc.
    28.5  #============================================================================
    28.6  
    28.7 +from XendBase import XendBase
    28.8  
    28.9 -class XendPIFMetrics:
   28.10 +class XendPIFMetrics(XendBase):
   28.11      """PIF Metrics."""
   28.12 +
   28.13 +    def getClass(self):
   28.14 +        return "PIF_metrics"
   28.15      
   28.16 -    def __init__(self, uuid):
   28.17 -        self.uuid = uuid
   28.18 +    def getAttrRO(self):
   28.19 +        attrRO =  ['io_read_kbs',
   28.20 +                   'io_write_kbs',
   28.21 +                   'last_updated',
   28.22 +                   'pif']
   28.23 +        return XendBase.getAttrRO() + attrRO
   28.24  
   28.25 -    def set_PIF(self, pif):
   28.26 -        self.pif = pif
   28.27 +    getClass    = classmethod(getClass)
   28.28 +    getAttrRO   = classmethod(getAttrRO)
   28.29 +
   28.30 +    def __init__(self, uuid, pif_uuid):
   28.31 +        XendBase.__init__(self, uuid, {})
   28.32 +        self.pif_uuid = pif_uuid
   28.33 +
   28.34 +    def get_pif(self):
   28.35 +        return self.pif_uuid
   28.36  
   28.37      def get_io_read_kbs(self):
   28.38          return self._get_stat(0)
   28.39 @@ -33,19 +48,12 @@ class XendPIFMetrics:
   28.40  
   28.41      def _get_stat(self, n):
   28.42          from xen.xend.XendNode import instance as xennode
   28.43 -        pifname = self.pif.device
   28.44 -        pifs_util = xennode().monitor.get_pifs_util()
   28.45 -        if pifname in pifs_util:
   28.46 -            return pifs_util[pifname][n]
   28.47 +        #pifname = self.pif.device
   28.48 +        #pifs_util = xennode().monitor.get_pifs_util()
   28.49 +        #if pifname in pifs_util:
   28.50 +        #    return pifs_util[pifname][n]
   28.51          return 0.0
   28.52  
   28.53      def get_last_updated(self):
   28.54          import xen.xend.XendAPI as XendAPI
   28.55          return XendAPI.now()
   28.56 -
   28.57 -    def get_record(self):
   28.58 -        return {'uuid'         : self.uuid,
   28.59 -                'io_read_kbs'  : self.get_io_read_kbs(),
   28.60 -                'io_write_kbs' : self.get_io_write_kbs(),
   28.61 -                'last_updated' : self.get_last_updated(),
   28.62 -                }
    29.1 --- a/tools/python/xen/xend/XendQCoWStorageRepo.py	Fri Apr 27 13:25:58 2007 +0100
    29.2 +++ b/tools/python/xen/xend/XendQCoWStorageRepo.py	Fri Apr 27 13:31:09 2007 +0100
    29.3 @@ -30,7 +30,7 @@ import struct
    29.4  
    29.5  from xen.util import mkdir
    29.6  import uuid
    29.7 -import XendPBD
    29.8 +from XendPBD import XendPBD
    29.9  from XendError import XendError
   29.10  from XendVDI import *
   29.11  from XendTask import XendTask
    30.1 --- a/tools/python/xen/xend/XendStateStore.py	Fri Apr 27 13:25:58 2007 +0100
    30.2 +++ b/tools/python/xen/xend/XendStateStore.py	Fri Apr 27 13:31:09 2007 +0100
    30.3 @@ -57,10 +57,12 @@ class XendStateStore:
    30.4  
    30.5      <hosts>
    30.6         <host uuid='49c01812-3c28-1ad4-a59d-2a3f81b13ec2'>
    30.7 -           <name type='string'>norwich</name>
    30.8 -           <description type='string'>Test Xen Host</description>
    30.9 -           <cpu uuid='6fc2d1ed-7eb0-4c9d-8006-3657d5483ae0' />
   30.10 -           <cpu uuid='669df3b8-62be-4e61-800b-bbe8ee63a760' />
   30.11 +          <name type='string'>norwich</name>
   30.12 +          <description type='string'>Test Xen Host</description>
   30.13 +          <cpu type='dict'>
   30.14 +             <item uuid='6fc2d1ed-7eb0-4c9d-8006-3657d5483ae0' />
   30.15 +             <item uuid='669df3b8-62be-4e61-800b-bbe8ee63a760' />
   30.16 +          </cpu>
   30.17         </host>
   30.18      </hosts>
   30.19  
   30.20 @@ -121,18 +123,20 @@ class XendStateStore:
   30.21                  if val_elem.firstChild:
   30.22                      val_text = val_elem.firstChild.nodeValue.strip()
   30.23                  
   30.24 -                if val_type == '' and val_uuid != '':
   30.25 -                    # this is a reference
   30.26 -                    if val_name not in cls_dict:
   30.27 -                        cls_dict[val_name] = {}
   30.28 -                    cls_dict[val_name][val_uuid] = None
   30.29 -                elif val_type == '':
   30.30 -                    # dictionary
   30.31 -                    k = val_elem.getAttribute('key').encode('utf8')
   30.32 -                    v = val_elem.getAttribute('value').encode('utf8')
   30.33 -                    if val_name not in cls_dict:
   30.34 -                        cls_dict[val_name] = {}
   30.35 -                    cls_dict[val_name][k] = v
   30.36 +                if val_type == 'list':
   30.37 +                    cls_dict[val_name] = []
   30.38 +                    for item in val_elem.childNodes:
   30.39 +                        if item.nodeType != Node.ELEMENT_NODE:
   30.40 +                            continue # skip non element nodes
   30.41 +                        cls_dict[val_name].append(item.getAttribute('uuid'))
   30.42 +                elif val_type == 'dict':
   30.43 +                    cls_dict[val_name] = {}
   30.44 +                    for item in val_elem.childNodes:
   30.45 +                        if item.nodeType != Node.ELEMENT_NODE:
   30.46 +                            continue # skip non element nodes
   30.47 +                        k = item.getAttribute('key').encode('utf8')
   30.48 +                        v = item.getAttribute('value').encode('utf8')
   30.49 +                        cls_dict[val_name][k] = v
   30.50                  elif val_type == 'string':
   30.51                      cls_dict[val_name] = val_text.encode('utf8')
   30.52                  elif val_type == 'float':
   30.53 @@ -158,8 +162,7 @@ class XendStateStore:
   30.54          @param state: a Xen API struct of the state of the class.
   30.55          @type  state: dict
   30.56          @rtype: None
   30.57 -        """
   30.58 -        
   30.59 +        """        
   30.60          xml_path = self._xml_file(cls)
   30.61  
   30.62          doc = minidom.getDOMImplementation().createDocument(None,
   30.63 @@ -191,7 +194,7 @@ class XendStateStore:
   30.64                      store_val = str(int(val))
   30.65                      store_type = 'bool'
   30.66  
   30.67 -                if store_type != None:
   30.68 +                if store_type is not None:
   30.69                      val_node = doc.createElement(key)
   30.70                      val_node.setAttribute('type', store_type)
   30.71                      node.appendChild(val_node)
   30.72 @@ -202,19 +205,25 @@ class XendStateStore:
   30.73  
   30.74                  # deal with dicts and lists
   30.75                  if type(val) == dict:
   30.76 -                    for val_uuid in val.keys():
   30.77 -                        val_node = doc.createElement(key)
   30.78 +                    val_node = doc.createElement(key)
   30.79 +                    val_node.setAttribute('type', 'dict')
   30.80 +                    for val_item in val.keys():
   30.81 +                        tmp = doc.createElement("item")
   30.82                          if key in ['other_config', 'device_config']:
   30.83 -                            val_node.setAttribute('key', str(val_uuid))
   30.84 -                            val_node.setAttribute('value', str(val[val_uuid]))
   30.85 +                            tmp.setAttribute('key', str(val_item))
   30.86 +                            tmp.setAttribute('value', str(val[val_item]))
   30.87                          else:
   30.88 -                            val_node.setAttribute('uuid', val_uuid)
   30.89 -                        node.appendChild(val_node)
   30.90 +                            tmp.setAttribute('uuid', val_uuid)
   30.91 +                        val_node.appendChild(tmp)
   30.92 +                    node.appendChild(val_node)
   30.93                  elif type(val) in (list, tuple):
   30.94 +                    val_node = doc.createElement(key)
   30.95 +                    val_node.setAttribute('type', 'list')
   30.96                      for val_uuid in val:
   30.97 -                        val_node = doc.createElement(key)
   30.98 -                        val_node.setAttribute('uuid', val_uuid)
   30.99 -                        node.appendChild(val_node)
  30.100 +                        tmp = doc.createElement("item")
  30.101 +                        tmp.setAttribute('uuid', val_uuid)
  30.102 +                        val_node.appendChild(tmp)
  30.103 +                    node.appendChild(val_node)
  30.104  
  30.105          open(xml_path, 'w').write(doc.toprettyxml())
  30.106          
    31.1 --- a/tools/python/xen/xend/XendStorageRepository.py	Fri Apr 27 13:25:58 2007 +0100
    31.2 +++ b/tools/python/xen/xend/XendStorageRepository.py	Fri Apr 27 13:31:09 2007 +0100
    31.3 @@ -24,7 +24,7 @@ import sys
    31.4  
    31.5  from XendError import XendError
    31.6  from XendVDI import *
    31.7 -import XendPBD
    31.8 +from XendPBD import XendPBD
    31.9  
   31.10  XEND_STORAGE_NO_MAXIMUM = sys.maxint
   31.11  
    32.1 --- a/tools/python/xen/xend/XendVMMetrics.py	Fri Apr 27 13:25:58 2007 +0100
    32.2 +++ b/tools/python/xen/xend/XendVMMetrics.py	Fri Apr 27 13:31:09 2007 +0100
    32.3 @@ -17,38 +17,36 @@
    32.4  #============================================================================
    32.5  
    32.6  from xen.xend.XendLogging import log
    32.7 +from xen.xend.XendBase import XendBase
    32.8  import xen.lowlevel.xc
    32.9  
   32.10  xc = xen.lowlevel.xc.xc()
   32.11  
   32.12 -instances = {}
   32.13 -
   32.14 -class XendVMMetrics:
   32.15 +class XendVMMetrics(XendBase):
   32.16      """VM Metrics."""
   32.17  
   32.18 -    def get_by_uuid(_, uuid):
   32.19 -        return instances[uuid]
   32.20 -
   32.21 -    get_by_uuid = classmethod(get_by_uuid)
   32.22 -
   32.23 -    def is_valid_vm_metrics(_, uuid):
   32.24 -        return uuid in instances
   32.25 -
   32.26 -    is_valid_vm_metrics = classmethod(is_valid_vm_metrics)
   32.27 +    def getClass(self):
   32.28 +        return "VM_metrics"
   32.29 +    
   32.30 +    def getAttrRO(self):
   32.31 +        attrRO = ['memory_actual',
   32.32 +                  'VCPUs_number',
   32.33 +                  'VCPUs_utilisation',
   32.34 +                  'VCPUs_CPU',
   32.35 +                  'VCPUs_flags',
   32.36 +                  'VCPUs_params',
   32.37 +                  'state',
   32.38 +                  'start_time',
   32.39 +                  'last_updated']
   32.40 +        return XendBase.getAttrRO() + attrRO
   32.41  
   32.42 -    def get_all(_):
   32.43 -        return instances.keys()
   32.44 +    getClass    = classmethod(getClass)
   32.45 +    getAttrRO   = classmethod(getAttrRO)
   32.46  
   32.47 -    get_all = classmethod(get_all)
   32.48 -   
   32.49      def __init__(self, uuid, xend_domain_instance):
   32.50 -        self.uuid = uuid
   32.51 +        XendBase.__init__(self, uuid, {})
   32.52          self.xend_domain_instance = xend_domain_instance
   32.53 -        instances[uuid] = self
   32.54 -
   32.55 -    def get_uuid(self):
   32.56 -        return self.uuid
   32.57 -
   32.58 +        
   32.59      def get_memory_actual(self):
   32.60          domInfo = self.xend_domain_instance.getDomInfo()
   32.61          if domInfo:
   32.62 @@ -145,16 +143,3 @@ class XendVMMetrics:
   32.63      def get_last_updated(self):
   32.64          import xen.xend.XendAPI as XendAPI
   32.65          return XendAPI.now()
   32.66 -    
   32.67 -    def get_record(self):
   32.68 -        return { 'uuid'              : self.uuid,
   32.69 -                 'memory_actual'     : self.get_memory_actual(),
   32.70 -                 'VCPUs_number'      : self.get_VCPUs_number(),
   32.71 -                 'VCPUs_utilisation' : self.get_VCPUs_utilisation(),
   32.72 -                 'VCPUs_CPU'         : self.get_VCPUs_CPU(),
   32.73 -                 'VCPUs_flags'       : self.get_VCPUs_flags(),
   32.74 -                 'VCPUs_params'      : self.get_VCPUs_params(),
   32.75 -                 'start_time'        : self.get_start_time(),
   32.76 -                 'state'             : self.get_state(),
   32.77 -                 'last_updated'      : self.get_last_updated(),
   32.78 -               }
    33.1 --- a/tools/python/xen/xend/server/SrvServer.py	Fri Apr 27 13:25:58 2007 +0100
    33.2 +++ b/tools/python/xen/xend/server/SrvServer.py	Fri Apr 27 13:31:09 2007 +0100
    33.3 @@ -109,8 +109,6 @@ class XendServers:
    33.4          signal.signal(signal.SIGHUP, self.reloadConfig)
    33.5  
    33.6          while True:
    33.7 -            XendNode.instance().refreshBridges()
    33.8 -
    33.9              threads = []
   33.10              for server in self.servers:
   33.11                  if server.ready:
    34.1 --- a/tools/python/xen/xm/create.dtd	Fri Apr 27 13:25:58 2007 +0100
    34.2 +++ b/tools/python/xen/xm/create.dtd	Fri Apr 27 13:31:09 2007 +0100
    34.3 @@ -27,7 +27,8 @@
    34.4                              | crashdump )">
    34.5  
    34.6  <!ELEMENT xm (vm*, 
    34.7 -              vdi*)> 
    34.8 +              vdi*,
    34.9 +              network*)> 
   34.10  
   34.11  <!ELEMENT version (#PCDATA)>
   34.12   
   34.13 @@ -98,6 +99,12 @@
   34.14                   sharable        CDATA #REQUIRED
   34.15                   read_only       CDATA #REQUIRED>
   34.16  
   34.17 +<!ELEMENT network (name,
   34.18 +                  other_config*)>
   34.19 +<!ATTLIST network %NAMEID;
   34.20 +                  default_gateway CDATA #REQUIRED
   34.21 +                  default_netmask CDATA #REQUIRED>
   34.22 +
   34.23  <!ELEMENT name   (label, 
   34.24                    description)> 
   34.25  
    35.1 --- a/tools/python/xen/xm/main.py	Fri Apr 27 13:25:58 2007 +0100
    35.2 +++ b/tools/python/xen/xm/main.py	Fri Apr 27 13:31:09 2007 +0100
    35.3 @@ -510,6 +510,10 @@ def xenapi_unsupported():
    35.4      if serverType == SERVER_XEN_API:
    35.5          raise XenAPIUnsupportedException, "This function is not supported by Xen-API"
    35.6  
    35.7 +def xenapi_only():
    35.8 +    if serverType != SERVER_XEN_API:
    35.9 +        raise XenAPIUnsupportedException, "This function is only supported by Xen-API"
   35.10 +
   35.11  def map2sxp(m):
   35.12      return [[k, m[k]] for k in m.keys()]
   35.13  
   35.14 @@ -2070,8 +2074,14 @@ def xm_network_attach(args):
   35.15              record[keys[-1]] = val
   35.16  
   35.17          def get_net_from_bridge(bridge):
   35.18 -            raise "Not supported just yet"
   35.19 -         
   35.20 +            # In OSS, we just assert network.name_label == bridge name
   35.21 +            networks = dict([(record['name_label'], record['uuid'])
   35.22 +                             for record in server.xenapi.network
   35.23 +                             .get_all_records()])
   35.24 +            if bridge not in networks.keys():
   35.25 +                raise "Unknown bridge name!"
   35.26 +            return networks[bridge]
   35.27 +
   35.28          vif_conv = {
   35.29              'type':
   35.30                  lambda x: None,
   35.31 @@ -2102,7 +2112,6 @@ def xm_network_attach(args):
   35.32              else:
   35.33                  vif_conv[vif_param[0]](vif_param[1])
   35.34  
   35.35 -        print str(vif_record)
   35.36          server.xenapi.VIF.create(vif_record)
   35.37      else:
   35.38          for a in args[1:]:
   35.39 @@ -2222,6 +2231,93 @@ def xm_vnet_delete(args):
   35.40      vnet = args[0]
   35.41      server.xend_vnet_delete(vnet)
   35.42  
   35.43 +def xm_network_new(args):
   35.44 +    xenapi_only()
   35.45 +    arg_check(args, "network-new", 1)
   35.46 +    network = args[0]
   35.47 +
   35.48 +    record = {
   35.49 +        "name_label":       network,
   35.50 +        "name_description": "",
   35.51 +        "other_config":     {},
   35.52 +        "default_gateway":  "",
   35.53 +        "default_netmask":  ""
   35.54 +        }
   35.55 +    
   35.56 +    server.xenapi.network.create(record)
   35.57 +    
   35.58 +def xm_network_del(args):
   35.59 +    xenapi_only()
   35.60 +    arg_check(args, "network-del", 1)
   35.61 +    network = args[0]
   35.62 +
   35.63 +    networks = dict([(record['name_label'], record['uuid'])
   35.64 +                     for record in
   35.65 +                     server.xenapi.network.get_all_records()])
   35.66 +
   35.67 +    if network not in networks.keys():
   35.68 +        raise ValueError("'%s' is not a valid network name" % network)
   35.69 +    
   35.70 +    server.xenapi.network.destroy(networks[network])
   35.71 +
   35.72 +def uuid_dict_trans(records):
   35.73 +    return dict([(record['uuid'], record)
   35.74 +                 for record in records])
   35.75 +
   35.76 +def xm_network_show(args):
   35.77 +    xenapi_only()
   35.78 +    arg_check(args, "network-show", 0)
   35.79 +
   35.80 +    networks = server.xenapi.network.get_all_records()
   35.81 +    pifs     = uuid_dict_trans(
   35.82 +        server.xenapi.PIF.get_all_records())
   35.83 +    vifs     = uuid_dict_trans(
   35.84 +        server.xenapi.VIF.get_all_records())
   35.85 +
   35.86 +    print '%-20s %-40s %-10s' % \
   35.87 +          ('Name', 'VIFs', 'PIFs')
   35.88 +    
   35.89 +    format2 = "%(name_label)-20s %(vif)-40s %(pif)-10s"
   35.90 +
   35.91 +    for network in networks:
   35.92 +        for i in range(max(len(network['PIFs']),
   35.93 +                           len(network['VIFs']), 1)):
   35.94 +            if i < len(network['PIFs']):
   35.95 +                pif_uuid = network['PIFs'][i]
   35.96 +            else:
   35.97 +                pif_uuid = None
   35.98 +                
   35.99 +            if i < len(network['VIFs']):
  35.100 +                vif_uuid = network['VIFs'][i]
  35.101 +            else:
  35.102 +                vif_uuid = None
  35.103 +                
  35.104 +            pif = pifs.get(pif_uuid, {'device':''}) 
  35.105 +            vif = vifs.get(vif_uuid, None)
  35.106 +
  35.107 +            if vif:
  35.108 +                dom_name = server.xenapi.VM.get_name_label(vif['VM'])
  35.109 +                vif = "%s.%s" % (dom_name, vif['device'])
  35.110 +            else:
  35.111 +                vif = '' 
  35.112 +
  35.113 +            if pif:
  35.114 +                if int(pif['VLAN']) > -1:
  35.115 +                    pif = '%s.%s' % (pif['device'], pif['VLAN'])
  35.116 +                else:
  35.117 +                    pif = pif['device']
  35.118 +            else:
  35.119 +                pif = ''
  35.120 +
  35.121 +            if i == 0:
  35.122 +                r = {'name_label':network['name_label'],
  35.123 +                     'vif':vif, 'pif':pif}
  35.124 +            else:
  35.125 +                r = {'name_label':'', 'vif':vif, 'pif':pif}
  35.126 +
  35.127 +            print format2 % r
  35.128 +
  35.129 +            
  35.130  commands = {
  35.131      "shell": xm_shell,
  35.132      "event-monitor": xm_event_monitor,
  35.133 @@ -2271,10 +2367,14 @@ commands = {
  35.134      "block-detach": xm_block_detach,
  35.135      "block-list": xm_block_list,
  35.136      "block-configure": xm_block_configure,
  35.137 -    # network
  35.138 +    # network (AKA vifs)
  35.139      "network-attach": xm_network_attach,
  35.140      "network-detach": xm_network_detach,
  35.141      "network-list": xm_network_list,
  35.142 +    # network (as in XenAPI)
  35.143 +    "network-new": xm_network_new,
  35.144 +    "network-del": xm_network_del,
  35.145 +    "network-show": xm_network_show,
  35.146      # vnet
  35.147      "vnet-list": xm_vnet_list,
  35.148      "vnet-create": xm_vnet_create,
    36.1 --- a/tools/python/xen/xm/messages/en/xen-xm.po	Fri Apr 27 13:25:58 2007 +0100
    36.2 +++ b/tools/python/xen/xm/messages/en/xen-xm.po	Fri Apr 27 13:31:09 2007 +0100
    36.3 @@ -67,3 +67,27 @@ msgstr "HVM guest support is unavailable
    36.4  
    36.5  msgid "SESSION_NOT_REGISTERED"
    36.6  msgstr "This session is not registered to receive events.  You must call event.register before event.next.  (Session handle is %(1)s.)"
    36.7 +
    36.8 +msgid "CREATE_UNSPECIFIED_ATTRIBUTE"
    36.9 +msgstr "You need to specify %s when creating a new %s"
   36.10 + 
   36.11 +msgid "UNMANAGED_NETWORK_ERROR"
   36.12 +msgstr "Cannot change %s on an unmanaged network"
   36.13 + 
   36.14 +msgid "UNIQUE_NAME_ERROR"
   36.15 +msgstr "Name %s for class %s is not unique"
   36.16 +
   36.17 +msgid "INVALID_DEVICE_ERROR"
   36.18 +msgstr "Invalid device %s"
   36.19 +
   36.20 +msgid "DEVICE_EXISTS_ERROR"
   36.21 +msgstr "Device already exists %s"
   36.22 +
   36.23 +msgid "IMPLEMENTATION_ERROR"
   36.24 +msgstr "Class %s does not implement %s"
   36.25 +
   36.26 +msgid "VLAN_TAG_INVALID"
   36.27 +msgstr "VLAN tag invalid %s"
   36.28 +
   36.29 +msgid "NETWORK_ERROR"
   36.30 +msgstr "Network Error: %s - %s"
   36.31 \ No newline at end of file
    37.1 --- a/tools/python/xen/xm/xenapi_create.py	Fri Apr 27 13:25:58 2007 +0100
    37.2 +++ b/tools/python/xen/xm/xenapi_create.py	Fri Apr 27 13:31:09 2007 +0100
    37.3 @@ -93,10 +93,13 @@ class xenapi_create:
    37.4  
    37.5          vdis = document.getElementsByTagName("vdi")
    37.6          vdi_refs_dict = self.create_vdis(vdis)
    37.7 +
    37.8 +        networks = document.getElementsByTagName("network")
    37.9 +        network_refs_dict = self.create_networks(networks)
   37.10          
   37.11          try:    
   37.12              vms = document.getElementsByTagName("vm")
   37.13 -            return self.create_vms(vms, vdi_refs_dict)
   37.14 +            return self.create_vms(vms, vdi_refs_dict, network_refs_dict)
   37.15          except Exception, exn:
   37.16              try_quietly(self.cleanup_vdis(vdi_refs_dict))
   37.17              raise exn
   37.18 @@ -223,11 +226,33 @@ class xenapi_create:
   37.19          
   37.20          return (key, value)
   37.21  
   37.22 -    def create_vms(self, vms, vdis):
   37.23 +    def create_networks(self, networks):
   37.24 +        log(DEBUG, "create_networks")
   37.25 +        return dict(map(self.create_network, networks))
   37.26 +
   37.27 +    def create_network(self, network):
   37.28 +        log(DEBUG, "create_network")
   37.29 +
   37.30 +        network_record = {
   37.31 +            "name_label":       get_name_label(network),
   37.32 +            "name_description": get_name_description(network),
   37.33 +            "other_config":
   37.34 +                get_child_nodes_as_dict(network, "other_config",
   37.35 +                                        "key", "value"),
   37.36 +            "default_netmask":  network.attributes["default_netmask"].value,
   37.37 +            "default_gateway":  network.attributes["default_gateway"].value
   37.38 +            }
   37.39 +
   37.40 +        key = network.attributes["name"].value
   37.41 +        value = server.xenapi.network.create(network_record)
   37.42 +
   37.43 +        return (key, value)
   37.44 +        
   37.45 +    def create_vms(self, vms, vdis, networks):
   37.46          log(DEBUG, "create_vms")
   37.47 -        return map(lambda vm: self.create_vm(vm, vdis), vms)
   37.48 +        return map(lambda vm: self.create_vm(vm, vdis, networks), vms)
   37.49  
   37.50 -    def create_vm(self, vm, vdis):
   37.51 +    def create_vm(self, vm, vdis, networks):
   37.52          log(DEBUG, "create_vm")
   37.53  
   37.54          vm_record = {
   37.55 @@ -321,7 +346,7 @@ class xenapi_create:
   37.56  
   37.57              vifs = vm.getElementsByTagName("vif")
   37.58  
   37.59 -            self.create_vifs(vm_ref, vifs)
   37.60 +            self.create_vifs(vm_ref, vifs, networks)
   37.61  
   37.62              # Now create consoles
   37.63  
   37.64 @@ -363,31 +388,35 @@ class xenapi_create:
   37.65  
   37.66          return server.xenapi.VBD.create(vbd_record)
   37.67  
   37.68 -    def create_vifs(self, vm_ref, vifs):
   37.69 +    def create_vifs(self, vm_ref, vifs, networks):
   37.70          log(DEBUG, "create_vifs")
   37.71 -        return map(lambda vif: self.create_vif(vm_ref, vif), vifs)
   37.72 +        return map(lambda vif: self.create_vif(vm_ref, vif, networks), vifs)
   37.73  
   37.74 -    def create_vif(self, vm_ref, vif):
   37.75 +    def create_vif(self, vm_ref, vif, networks):
   37.76          log(DEBUG, "create_vif")
   37.77  
   37.78 -        if "network" in vif.attributes.keys():
   37.79 -            networks = [network_ref
   37.80 -                for network_ref in server.xenapi.network.get_all()
   37.81 -                if server.xenapi.network.get_name_label(network_ref)
   37.82 -                       == vif.attributes["network"].value]
   37.83 -            if len(networks) > 0:
   37.84 -                network = networks[0]
   37.85 +        if 'network' in vif.attributes.keys():
   37.86 +            network_name = vif.attributes['network'].value
   37.87 +
   37.88 +            if network_name in networks.keys():
   37.89 +                network_uuid = networks[network_name]
   37.90              else:
   37.91 -                raise OptionError("Network %s doesn't exist"
   37.92 +                networks = dict([(record['name_label'], record['uuid'])
   37.93 +                                 for record in
   37.94 +                                 server.xenapi.network.get_all_records()])
   37.95 +                if network_name in networks.keys():
   37.96 +                    network_uuid = networks[network_name]
   37.97 +                else:
   37.98 +                    raise OptionError("Network %s doesn't exist"
   37.99                                    % vif.attributes["network"].value)
  37.100          else:
  37.101 -            network = self._get_network_ref()
  37.102 +            network_uuid = self._get_network_ref()
  37.103  
  37.104          vif_record = {
  37.105              "device":
  37.106                  vif.attributes["device"].value,
  37.107              "network":
  37.108 -                network,
  37.109 +                network_uuid,
  37.110              "VM":
  37.111                  vm_ref,
  37.112              "MAC":
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/tools/xm-test/lib/XmTestLib/network_utils.py	Fri Apr 27 13:31:09 2007 +0100
    38.3 @@ -0,0 +1,60 @@
    38.4 +#!/usr/bin/python
    38.5 +
    38.6 +# Copyright (C) International Business Machines Corp., 2005
    38.7 +# Author: Murillo F. Bernardes <mfb@br.ibm.com>
    38.8 +
    38.9 +from XmTestLib import *
   38.10 +
   38.11 +def count_eth(console):
   38.12 +    try:
   38.13 +        run = console.runCmd("ifconfig -a | grep eth")
   38.14 +    except ConsoleError, e:
   38.15 +        FAIL(str(e))
   38.16 +    return len(run['output'].splitlines())
   38.17 +
   38.18 +def get_state(domain_name, number):
   38.19 +    s, o = traceCommand("xm network-list %s | awk '/^%d/ {print $5}'" %
   38.20 +                        (domain_name, number))
   38.21 +    print o
   38.22 +    
   38.23 +    if s != 0:
   38.24 +        FAIL("network-list failed")
   38.25 +    if o == "":
   38.26 +        return 0
   38.27 +    else:
   38.28 +        return int(o)
   38.29 +
   38.30 +def network_attach(domain_name, console, bridge=None):
   38.31 +    eths_before = count_eth(console)
   38.32 +    if bridge:
   38.33 +        status, output = traceCommand("xm network-attach %s bridge=%s"
   38.34 +                                      % (domain_name, bridge))
   38.35 +    else:
   38.36 +        status, output = traceCommand("xm network-attach %s" % domain_name)
   38.37 +    if status != 0:
   38.38 +        return -1, "xm network-attach returned invalid %i != 0" % status
   38.39 +
   38.40 +    eths_after = count_eth(console)
   38.41 +    if (eths_after != (eths_before+1)):
   38.42 +        return -2, "Network device is not actually connected to domU"
   38.43 +
   38.44 +    return 0, None 
   38.45 +
   38.46 +def network_detach(domain_name, console, num=0):
   38.47 +    eths_before = count_eth(console)
   38.48 +    status, output = traceCommand("xm network-detach %s %d" % (domain_name, num))
   38.49 +    if status != 0:
   38.50 +        return -1, "xm network-detach returned invalid %i != 0" % status
   38.51 +
   38.52 +    for i in range(10):
   38.53 +        if get_state(domain_name, num) == 0:
   38.54 +            break
   38.55 +        time.sleep(1)
   38.56 +    else:
   38.57 +        FAIL("network-detach failed: device did not disappear")
   38.58 +
   38.59 +    eths_after = count_eth(console)
   38.60 +    if eths_after != (eths_before-1):
   38.61 +        return -2, "Network device was not actually disconnected from domU"
   38.62 +
   38.63 +    return 0, None
    39.1 --- a/tools/xm-test/tests/network-attach/01_network_attach_pos.py	Fri Apr 27 13:25:58 2007 +0100
    39.2 +++ b/tools/xm-test/tests/network-attach/01_network_attach_pos.py	Fri Apr 27 13:31:09 2007 +0100
    39.3 @@ -6,7 +6,7 @@
    39.4  import sys
    39.5  
    39.6  from XmTestLib import *
    39.7 -from network_utils import *
    39.8 +from XmTestLib.network_utils import *
    39.9  
   39.10  if ENABLE_HVM_SUPPORT:
   39.11      SKIP("Network-attach not supported for HVM domains")
    40.1 --- a/tools/xm-test/tests/network-attach/02_network_attach_detach_pos.py	Fri Apr 27 13:25:58 2007 +0100
    40.2 +++ b/tools/xm-test/tests/network-attach/02_network_attach_detach_pos.py	Fri Apr 27 13:31:09 2007 +0100
    40.3 @@ -8,7 +8,7 @@ import re
    40.4  import time
    40.5  
    40.6  from XmTestLib import *
    40.7 -from network_utils import *
    40.8 +from XmTestLib.network_utils import *
    40.9  
   40.10  if ENABLE_HVM_SUPPORT:
   40.11      SKIP("Network-attach not supported for HVM domains")
    41.1 --- a/tools/xm-test/tests/network-attach/03_network_attach_detach_multiple_pos.py	Fri Apr 27 13:25:58 2007 +0100
    41.2 +++ b/tools/xm-test/tests/network-attach/03_network_attach_detach_multiple_pos.py	Fri Apr 27 13:31:09 2007 +0100
    41.3 @@ -8,7 +8,7 @@ import re
    41.4  import time
    41.5  
    41.6  from XmTestLib import *
    41.7 -from network_utils import *
    41.8 +from XmTestLib.network_utils import *
    41.9  
   41.10  if ENABLE_HVM_SUPPORT:
   41.11      SKIP("Network-attach not supported for HVM domains")
    42.1 --- a/tools/xm-test/tests/network-attach/network_utils.py	Fri Apr 27 13:25:58 2007 +0100
    42.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.3 @@ -1,56 +0,0 @@
    42.4 -#!/usr/bin/python
    42.5 -
    42.6 -# Copyright (C) International Business Machines Corp., 2005
    42.7 -# Author: Murillo F. Bernardes <mfb@br.ibm.com>
    42.8 -
    42.9 -from XmTestLib import *
   42.10 -
   42.11 -def count_eth(console):
   42.12 -    try:
   42.13 -        run = console.runCmd("ifconfig -a | grep eth")
   42.14 -    except ConsoleError, e:
   42.15 -        FAIL(str(e))
   42.16 -    return len(run['output'].splitlines())
   42.17 -
   42.18 -def get_state(domain_name, number):
   42.19 -    s, o = traceCommand("xm network-list %s | awk '/^%d/ {print $5}'" %
   42.20 -                        (domain_name, number))
   42.21 -    print o
   42.22 -    
   42.23 -    if s != 0:
   42.24 -        FAIL("network-list failed")
   42.25 -    if o == "":
   42.26 -        return 0
   42.27 -    else:
   42.28 -        return int(o)
   42.29 -
   42.30 -def network_attach(domain_name, console):
   42.31 -    eths_before = count_eth(console)
   42.32 -    status, output = traceCommand("xm network-attach %s" % domain_name)
   42.33 -    if status != 0:
   42.34 -        return -1, "xm network-attach returned invalid %i != 0" % status
   42.35 -
   42.36 -    eths_after = count_eth(console)
   42.37 -    if (eths_after != (eths_before+1)):
   42.38 -        return -2, "Network device is not actually connected to domU"
   42.39 -
   42.40 -    return 0, None 
   42.41 -
   42.42 -def network_detach(domain_name, console, num=0):
   42.43 -    eths_before = count_eth(console)
   42.44 -    status, output = traceCommand("xm network-detach %s %d" % (domain_name, num))
   42.45 -    if status != 0:
   42.46 -        return -1, "xm network-detach returned invalid %i != 0" % status
   42.47 -
   42.48 -    for i in range(10):
   42.49 -        if get_state(domain_name, num) == 0:
   42.50 -            break
   42.51 -        time.sleep(1)
   42.52 -    else:
   42.53 -        FAIL("network-detach failed: device did not disappear")
   42.54 -
   42.55 -    eths_after = count_eth(console)
   42.56 -    if eths_after != (eths_before-1):
   42.57 -        return -2, "Network device was not actually disconnected from domU"
   42.58 -
   42.59 -    return 0, None
    43.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.2 +++ b/tools/xm-test/tests/xapi/03_xapi-network_pos.py	Fri Apr 27 13:31:09 2007 +0100
    43.3 @@ -0,0 +1,71 @@
    43.4 +#!/usr/bin/python
    43.5 +
    43.6 +# Try and create two VMs and a private network betwene the two
    43.7 +
    43.8 +import sys
    43.9 +
   43.10 +from XmTestLib import *
   43.11 +from XmTestLib.network_utils import *
   43.12 +
   43.13 +# Create two domains (default XmTestDomain, with our ramdisk)
   43.14 +try:
   43.15 +    domain1 = XmTestDomain()
   43.16 +    console1 = domain1.start()
   43.17 +    domain2 = XmTestDomain()
   43.18 +    console2 = domain2.start()
   43.19 +except DomainError, e:
   43.20 +    if verbose:
   43.21 +        print "Failed to create test domain because:"
   43.22 +        print e.extra
   43.23 +    FAIL(str(e))
   43.24 +
   43.25 +# Create a network
   43.26 +
   43.27 +status, ouptut = traceCommand("xm network-new xapi-network")
   43.28 +if status:
   43.29 +    FAIL(output)
   43.30 +
   43.31 +# Attach two domains to it
   43.32 +status, msg = network_attach(domain1.getName(),
   43.33 +                             console1, bridge='xapi-network')
   43.34 +if status:
   43.35 +    FAIL(msg)
   43.36 +
   43.37 +status, msg = network_attach(domain2.getName(),
   43.38 +                             console2, bridge='xapi-network')
   43.39 +if status:
   43.40 +    FAIL(msg)
   43.41 +
   43.42 +# Configure IP addresses on two domains
   43.43 +try:
   43.44 +    # Run 'ls'
   43.45 +    run = console1.runCmd("ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up")
   43.46 +    run = console2.runCmd("ifconfig eth0 192.168.0.2 netmask 255.255.255.0 up")
   43.47 +except ConsoleError, e:
   43.48 +    saveLog(console.getHistory())
   43.49 +    FAIL(str(e))
   43.50 +
   43.51 +# Now ping...
   43.52 +try:
   43.53 +    run = console1.runCmd("ping -c 4 192.168.0.2")
   43.54 +    if run['return'] > 0:
   43.55 +        FAIL("Could not ping other host")
   43.56 +    run = console2.runCmd("ping -c 4 192.168.0.1")
   43.57 +    if run['return'] > 0:
   43.58 +        FAIL("Could not pint other host")
   43.59 +except ConsoleError, e:
   43.60 +    saveLog(console.getHistory())
   43.61 +    FAIL(str(e))
   43.62 +
   43.63 +status, msg = network_detach(domain1.getName(), console1)
   43.64 +status, msg = network_detach(domain2.getName(), console2)
   43.65 +
   43.66 +# Clean up
   43.67 +domain1.closeConsole()
   43.68 +domain1.stop()
   43.69 +domain2.closeConsole()
   43.70 +domain2.stop()
   43.71 +
   43.72 +status, ouptut = traceCommand("xm network-del xapi-network")
   43.73 +if status:
   43.74 +    FAIL(output)
    44.1 --- a/tools/xm-test/tests/xapi/Makefile.am	Fri Apr 27 13:25:58 2007 +0100
    44.2 +++ b/tools/xm-test/tests/xapi/Makefile.am	Fri Apr 27 13:31:09 2007 +0100
    44.3 @@ -1,7 +1,8 @@
    44.4  SUBDIRS =
    44.5  
    44.6  TESTS = 01_xapi-vm_basic.test \
    44.7 -	02_xapi-vbd_basic.test
    44.8 +	02_xapi-vbd_basic.test \
    44.9 +	03_xapi-network_pos.test
   44.10  
   44.11  XFAIL_TESTS =
   44.12  
    45.1 --- a/xen/acm/acm_policy.c	Fri Apr 27 13:25:58 2007 +0100
    45.2 +++ b/xen/acm/acm_policy.c	Fri Apr 27 13:31:09 2007 +0100
    45.3 @@ -46,7 +46,7 @@ static ssidref_t oldssid_to_newssid(cons
    45.4  
    45.5  
    45.6  int
    45.7 -acm_set_policy(XEN_GUEST_HANDLE(void) buf, u32 buf_size)
    45.8 +acm_set_policy(XEN_GUEST_HANDLE_64(void) buf, u32 buf_size)
    45.9  {
   45.10      u8 *policy_buffer = NULL;
   45.11      int ret = -EFAULT;
   45.12 @@ -213,7 +213,7 @@ do_acm_set_policy(void *buf, u32 buf_siz
   45.13  }
   45.14  
   45.15  int
   45.16 -acm_get_policy(XEN_GUEST_HANDLE(void) buf, u32 buf_size)
   45.17 +acm_get_policy(XEN_GUEST_HANDLE_64(void) buf, u32 buf_size)
   45.18  { 
   45.19      u8 *policy_buffer;
   45.20      int ret;
   45.21 @@ -278,7 +278,7 @@ acm_get_policy(XEN_GUEST_HANDLE(void) bu
   45.22  }
   45.23  
   45.24  int
   45.25 -acm_dump_statistics(XEN_GUEST_HANDLE(void) buf, u16 buf_size)
   45.26 +acm_dump_statistics(XEN_GUEST_HANDLE_64(void) buf, u16 buf_size)
   45.27  { 
   45.28      /* send stats to user space */
   45.29      u8 *stats_buffer;
   45.30 @@ -324,7 +324,7 @@ acm_dump_statistics(XEN_GUEST_HANDLE(voi
   45.31  
   45.32  
   45.33  int
   45.34 -acm_get_ssid(ssidref_t ssidref, XEN_GUEST_HANDLE(void) buf, u16 buf_size)
   45.35 +acm_get_ssid(ssidref_t ssidref, XEN_GUEST_HANDLE_64(void) buf, u16 buf_size)
   45.36  {
   45.37      /* send stats to user space */
   45.38      u8 *ssid_buffer;
    46.1 --- a/xen/arch/x86/domain.c	Fri Apr 27 13:25:58 2007 +0100
    46.2 +++ b/xen/arch/x86/domain.c	Fri Apr 27 13:31:09 2007 +0100
    46.3 @@ -237,7 +237,8 @@ static int setup_compat_l4(struct vcpu *
    46.4      l4tab[l4_table_offset(LINEAR_PT_VIRT_START)] =
    46.5          l4e_from_page(pg, __PAGE_HYPERVISOR);
    46.6      l4tab[l4_table_offset(PERDOMAIN_VIRT_START)] =
    46.7 -        l4e_from_paddr(__pa(v->domain->arch.mm_perdomain_l3), __PAGE_HYPERVISOR);
    46.8 +        l4e_from_paddr(__pa(v->domain->arch.mm_perdomain_l3),
    46.9 +                       __PAGE_HYPERVISOR);
   46.10      v->arch.guest_table = pagetable_from_page(pg);
   46.11      v->arch.guest_table_user = v->arch.guest_table;
   46.12  
   46.13 @@ -259,7 +260,7 @@ static void release_compat_l4(struct vcp
   46.14  
   46.15  static inline int may_switch_mode(struct domain *d)
   46.16  {
   46.17 -    return (d->tot_pages == 0);
   46.18 +    return (!is_hvm_domain(d) && (d->tot_pages == 0));
   46.19  }
   46.20  
   46.21  int switch_native(struct domain *d)
   46.22 @@ -371,15 +372,12 @@ int vcpu_initialise(struct vcpu *v)
   46.23      v->arch.perdomain_ptes =
   46.24          d->arch.mm_perdomain_pt + (v->vcpu_id << GDT_LDT_VCPU_SHIFT);
   46.25  
   46.26 -    if ( IS_COMPAT(d) && (rc = setup_compat_l4(v)) != 0 )
   46.27 -        return rc;
   46.28 -
   46.29 -    return 0;
   46.30 +    return (pv_32on64_vcpu(v) ? setup_compat_l4(v) : 0);
   46.31  }
   46.32  
   46.33  void vcpu_destroy(struct vcpu *v)
   46.34  {
   46.35 -    if ( IS_COMPAT(v->domain) )
   46.36 +    if ( pv_32on64_vcpu(v) )
   46.37          release_compat_l4(v);
   46.38  }
   46.39  
   46.40 @@ -491,7 +489,7 @@ void arch_domain_destroy(struct domain *
   46.41      free_domheap_page(virt_to_page(d->arch.mm_perdomain_l3));
   46.42  #endif
   46.43  
   46.44 -    if ( IS_COMPAT(d) )
   46.45 +    if ( pv_32on64_domain(d) )
   46.46          release_arg_xlat_area(d);
   46.47  
   46.48      free_xenheap_page(d->shared_info);
   46.49 @@ -508,7 +506,7 @@ int arch_set_info_guest(
   46.50  
   46.51      /* The context is a compat-mode one if the target domain is compat-mode;
   46.52       * we expect the tools to DTRT even in compat-mode callers. */
   46.53 -    compat = IS_COMPAT(d);
   46.54 +    compat = pv_32on64_domain(d);
   46.55  
   46.56  #ifdef CONFIG_COMPAT
   46.57  #define c(fld) (compat ? (c.cmp->fld) : (c.nat->fld))
   46.58 @@ -1268,7 +1266,7 @@ unsigned long hypercall_create_continuat
   46.59          else
   46.60  #endif
   46.61          {
   46.62 -            if ( supervisor_mode_kernel || is_hvm_vcpu(current) )
   46.63 +            if ( supervisor_mode_kernel )
   46.64                  regs->eip &= ~31; /* re-execute entire hypercall entry stub */
   46.65  
   46.66              for ( i = 0; *p != '\0'; i++ )
   46.67 @@ -1449,14 +1447,11 @@ static void vcpu_destroy_pagetables(stru
   46.68      struct domain *d = v->domain;
   46.69      unsigned long pfn;
   46.70  
   46.71 -#ifdef CONFIG_COMPAT
   46.72 -    if ( IS_COMPAT(d) )
   46.73 +#ifdef __x86_64__
   46.74 +    if ( pv_32on64_vcpu(v) )
   46.75      {
   46.76 -        if ( is_hvm_vcpu(v) )
   46.77 -            pfn = pagetable_get_pfn(v->arch.guest_table);
   46.78 -        else
   46.79 -            pfn = l4e_get_pfn(*(l4_pgentry_t *)
   46.80 -                              __va(pagetable_get_paddr(v->arch.guest_table)));
   46.81 +        pfn = l4e_get_pfn(*(l4_pgentry_t *)
   46.82 +                          __va(pagetable_get_paddr(v->arch.guest_table)));
   46.83  
   46.84          if ( pfn != 0 )
   46.85          {
   46.86 @@ -1466,12 +1461,9 @@ static void vcpu_destroy_pagetables(stru
   46.87                  put_page_and_type(mfn_to_page(pfn));
   46.88          }
   46.89  
   46.90 -        if ( is_hvm_vcpu(v) )
   46.91 -            v->arch.guest_table = pagetable_null();
   46.92 -        else
   46.93 -            l4e_write(
   46.94 -                (l4_pgentry_t *) __va(pagetable_get_paddr(v->arch.guest_table)),
   46.95 -                l4e_empty());
   46.96 +        l4e_write(
   46.97 +            (l4_pgentry_t *)__va(pagetable_get_paddr(v->arch.guest_table)),
   46.98 +            l4e_empty());
   46.99  
  46.100          v->arch.cr3 = 0;
  46.101          return;
    47.1 --- a/xen/arch/x86/hvm/vmx/intr.c	Fri Apr 27 13:25:58 2007 +0100
    47.2 +++ b/xen/arch/x86/hvm/vmx/intr.c	Fri Apr 27 13:31:09 2007 +0100
    47.3 @@ -72,6 +72,9 @@ static void update_tpr_threshold(struct 
    47.4  {
    47.5      int max_irr, tpr;
    47.6  
    47.7 +    if ( !cpu_has_vmx_tpr_shadow )
    47.8 +        return;
    47.9 +
   47.10      if ( !vlapic_enabled(vlapic) || 
   47.11           ((max_irr = vlapic_find_highest_irr(vlapic)) == -1) )
   47.12      {
    48.1 --- a/xen/arch/x86/hvm/vmx/vmcs.c	Fri Apr 27 13:25:58 2007 +0100
    48.2 +++ b/xen/arch/x86/hvm/vmx/vmcs.c	Fri Apr 27 13:31:09 2007 +0100
    48.3 @@ -38,16 +38,16 @@
    48.4  #include <asm/shadow.h>
    48.5  
    48.6  /* Dynamic (run-time adjusted) execution control flags. */
    48.7 -u32 vmx_pin_based_exec_control;
    48.8 -u32 vmx_cpu_based_exec_control;
    48.9 -u32 vmx_vmexit_control;
   48.10 -u32 vmx_vmentry_control;
   48.11 +u32 vmx_pin_based_exec_control __read_mostly;
   48.12 +u32 vmx_cpu_based_exec_control __read_mostly;
   48.13 +u32 vmx_vmexit_control __read_mostly;
   48.14 +u32 vmx_vmentry_control __read_mostly;
   48.15  
   48.16 -static u32 vmcs_revision_id;
   48.17 +static u32 vmcs_revision_id __read_mostly;
   48.18  
   48.19 -static u32 adjust_vmx_controls(u32 ctl_min, u32 ctl_max, u32 msr)
   48.20 +static u32 adjust_vmx_controls(u32 ctl_min, u32 ctl_opt, u32 msr)
   48.21  {
   48.22 -    u32 vmx_msr_low, vmx_msr_high, ctl = ctl_max;
   48.23 +    u32 vmx_msr_low, vmx_msr_high, ctl = ctl_min | ctl_opt;
   48.24  
   48.25      rdmsr(msr, vmx_msr_low, vmx_msr_high);
   48.26  
   48.27 @@ -56,46 +56,55 @@ static u32 adjust_vmx_controls(u32 ctl_m
   48.28  
   48.29      /* Ensure minimum (required) set of control bits are supported. */
   48.30      BUG_ON(ctl_min & ~ctl);
   48.31 -    BUG_ON(ctl_min & ~ctl_max);
   48.32  
   48.33      return ctl;
   48.34  }
   48.35  
   48.36  void vmx_init_vmcs_config(void)
   48.37  {
   48.38 -    u32 vmx_msr_low, vmx_msr_high, min, max;
   48.39 +    u32 vmx_msr_low, vmx_msr_high, min, opt;
   48.40      u32 _vmx_pin_based_exec_control;
   48.41      u32 _vmx_cpu_based_exec_control;
   48.42      u32 _vmx_vmexit_control;
   48.43      u32 _vmx_vmentry_control;
   48.44  
   48.45 -    min = max = PIN_BASED_EXT_INTR_MASK | PIN_BASED_NMI_EXITING;
   48.46 +    min = PIN_BASED_EXT_INTR_MASK | PIN_BASED_NMI_EXITING;
   48.47 +    opt = 0;
   48.48      _vmx_pin_based_exec_control = adjust_vmx_controls(
   48.49 -        min, max, MSR_IA32_VMX_PINBASED_CTLS_MSR);
   48.50 +        min, opt, MSR_IA32_VMX_PINBASED_CTLS_MSR);
   48.51  
   48.52 -    min = max = (CPU_BASED_HLT_EXITING |
   48.53 -                 CPU_BASED_INVDPG_EXITING |
   48.54 -                 CPU_BASED_MWAIT_EXITING |
   48.55 -                 CPU_BASED_MOV_DR_EXITING |
   48.56 -                 CPU_BASED_ACTIVATE_IO_BITMAP |
   48.57 -                 CPU_BASED_USE_TSC_OFFSETING);
   48.58 +    min = (CPU_BASED_HLT_EXITING |
   48.59 +           CPU_BASED_INVDPG_EXITING |
   48.60 +           CPU_BASED_MWAIT_EXITING |
   48.61 +           CPU_BASED_MOV_DR_EXITING |
   48.62 +           CPU_BASED_ACTIVATE_IO_BITMAP |
   48.63 +           CPU_BASED_USE_TSC_OFFSETING);
   48.64 +    opt = CPU_BASED_ACTIVATE_MSR_BITMAP;
   48.65 +#ifdef __x86_64__
   48.66 +    opt |= CPU_BASED_TPR_SHADOW;
   48.67 +#endif
   48.68 +    _vmx_cpu_based_exec_control = adjust_vmx_controls(
   48.69 +        min, opt, MSR_IA32_VMX_PROCBASED_CTLS_MSR);
   48.70  #ifdef __x86_64__
   48.71 -    min = max |= CPU_BASED_CR8_LOAD_EXITING | CPU_BASED_CR8_STORE_EXITING;
   48.72 +    if ( !(_vmx_cpu_based_exec_control & CPU_BASED_TPR_SHADOW) )
   48.73 +    {
   48.74 +        min |= CPU_BASED_CR8_LOAD_EXITING | CPU_BASED_CR8_STORE_EXITING;
   48.75 +        _vmx_cpu_based_exec_control = adjust_vmx_controls(
   48.76 +            min, opt, MSR_IA32_VMX_PROCBASED_CTLS_MSR);
   48.77 +    }
   48.78  #endif
   48.79 -    max |= CPU_BASED_ACTIVATE_MSR_BITMAP;
   48.80 -    _vmx_cpu_based_exec_control = adjust_vmx_controls(
   48.81 -        min, max, MSR_IA32_VMX_PROCBASED_CTLS_MSR);
   48.82  
   48.83 -    min = max = VM_EXIT_ACK_INTR_ON_EXIT;
   48.84 +    min = VM_EXIT_ACK_INTR_ON_EXIT;
   48.85 +    opt = 0;
   48.86  #ifdef __x86_64__
   48.87 -    min = max |= VM_EXIT_IA32E_MODE;
   48.88 +    min |= VM_EXIT_IA32E_MODE;
   48.89  #endif
   48.90      _vmx_vmexit_control = adjust_vmx_controls(
   48.91 -        min, max, MSR_IA32_VMX_EXIT_CTLS_MSR);
   48.92 +        min, opt, MSR_IA32_VMX_EXIT_CTLS_MSR);
   48.93  
   48.94 -    min = max = 0;
   48.95 +    min = opt = 0;
   48.96      _vmx_vmentry_control = adjust_vmx_controls(
   48.97 -        min, max, MSR_IA32_VMX_ENTRY_CTLS_MSR);
   48.98 +        min, opt, MSR_IA32_VMX_ENTRY_CTLS_MSR);
   48.99  
  48.100      rdmsr(MSR_IA32_VMX_BASIC_MSR, vmx_msr_low, vmx_msr_high);
  48.101  
  48.102 @@ -414,13 +423,12 @@ static void construct_vmcs(struct vcpu *
  48.103  
  48.104  #ifdef __x86_64__ 
  48.105      /* VLAPIC TPR optimisation. */
  48.106 -    v->arch.hvm_vcpu.u.vmx.exec_control |= CPU_BASED_TPR_SHADOW;
  48.107 -    v->arch.hvm_vcpu.u.vmx.exec_control &=
  48.108 -        ~(CPU_BASED_CR8_STORE_EXITING | CPU_BASED_CR8_LOAD_EXITING);
  48.109 -    __vmwrite(CPU_BASED_VM_EXEC_CONTROL, v->arch.hvm_vcpu.u.vmx.exec_control);
  48.110 -    __vmwrite(VIRTUAL_APIC_PAGE_ADDR,
  48.111 -              page_to_maddr(vcpu_vlapic(v)->regs_page));
  48.112 -    __vmwrite(TPR_THRESHOLD, 0);
  48.113 +    if ( cpu_has_vmx_tpr_shadow )
  48.114 +    {
  48.115 +        __vmwrite(VIRTUAL_APIC_PAGE_ADDR,
  48.116 +                  page_to_maddr(vcpu_vlapic(v)->regs_page));
  48.117 +        __vmwrite(TPR_THRESHOLD, 0);
  48.118 +    }
  48.119  #endif
  48.120  
  48.121      __vmwrite(GUEST_LDTR_SELECTOR, 0);
    49.1 --- a/xen/arch/x86/mm.c	Fri Apr 27 13:25:58 2007 +0100
    49.2 +++ b/xen/arch/x86/mm.c	Fri Apr 27 13:31:09 2007 +0100
    49.3 @@ -249,7 +249,10 @@ int memory_is_conventional_ram(paddr_t p
    49.4  
    49.5  unsigned long domain_get_maximum_gpfn(struct domain *d)
    49.6  {
    49.7 -    return is_hvm_domain(d) ? d->arch.p2m.max_mapped_pfn : arch_get_max_pfn(d);
    49.8 +    if ( is_hvm_domain(d) )
    49.9 +        return d->arch.p2m.max_mapped_pfn;
   49.10 +    /* NB. PV guests specify nr_pfns rather than max_pfn so we adjust here. */
   49.11 +    return arch_get_max_pfn(d) - 1;
   49.12  }
   49.13  
   49.14  void share_xen_page_with_guest(
    50.1 --- a/xen/arch/x86/mm/shadow/common.c	Fri Apr 27 13:25:58 2007 +0100
    50.2 +++ b/xen/arch/x86/mm/shadow/common.c	Fri Apr 27 13:31:09 2007 +0100
    50.3 @@ -1577,9 +1577,7 @@ void sh_destroy_shadow(struct vcpu *v, m
    50.4             t == SH_type_fl1_pae_shadow ||  
    50.5             t == SH_type_fl1_64_shadow  || 
    50.6             t == SH_type_monitor_table  || 
    50.7 -#ifdef CONFIG_COMPAT
    50.8 -           (IS_COMPAT(v->domain) && t == SH_type_l4_64_shadow) ||
    50.9 -#endif
   50.10 +           (pv_32on64_vcpu(v) && t == SH_type_l4_64_shadow) ||
   50.11             (page_get_owner(mfn_to_page(_mfn(sp->backpointer))) 
   50.12              == v->domain)); 
   50.13  
   50.14 @@ -1622,7 +1620,7 @@ void sh_destroy_shadow(struct vcpu *v, m
   50.15          SHADOW_INTERNAL_NAME(sh_destroy_l1_shadow, 4, 4)(v, smfn);
   50.16          break;
   50.17      case SH_type_l2h_64_shadow:
   50.18 -        ASSERT( IS_COMPAT(v->domain) );
   50.19 +        ASSERT(pv_32on64_vcpu(v));
   50.20          /* Fall through... */
   50.21      case SH_type_l2_64_shadow:
   50.22          SHADOW_INTERNAL_NAME(sh_destroy_l2_shadow, 4, 4)(v, smfn);
   50.23 @@ -2668,8 +2666,7 @@ sh_alloc_log_dirty_bitmap(struct domain 
   50.24  {
   50.25      ASSERT(d->arch.paging.shadow.dirty_bitmap == NULL);
   50.26      d->arch.paging.shadow.dirty_bitmap_size =
   50.27 -        (domain_get_maximum_gpfn(d) + (BITS_PER_LONG - 1)) &
   50.28 -        ~(BITS_PER_LONG - 1);
   50.29 +        (domain_get_maximum_gpfn(d) + BITS_PER_LONG) & ~(BITS_PER_LONG - 1);
   50.30      d->arch.paging.shadow.dirty_bitmap =
   50.31          xmalloc_array(unsigned long,
   50.32                        d->arch.paging.shadow.dirty_bitmap_size / BITS_PER_LONG);
   50.33 @@ -2717,7 +2714,10 @@ static int shadow_log_dirty_enable(struc
   50.34      }
   50.35  
   50.36  #if (SHADOW_OPTIMIZATIONS & SHOPT_LINUX_L3_TOPLEVEL)
   50.37 -    if ( IS_COMPAT(d) )
   50.38 +    /* 32bit PV guests on 64bit xen behave like older 64bit linux: they
   50.39 +     * change an l4e instead of cr3 to switch tables.  Give them the
   50.40 +     * same optimization */
   50.41 +    if ( pv_32on64_domain(d) )
   50.42          d->arch.paging.shadow.opt_flags = SHOPT_LINUX_L3_TOPLEVEL;
   50.43  #endif
   50.44  
    51.1 --- a/xen/arch/x86/mm/shadow/multi.c	Fri Apr 27 13:25:58 2007 +0100
    51.2 +++ b/xen/arch/x86/mm/shadow/multi.c	Fri Apr 27 13:31:09 2007 +0100
    51.3 @@ -134,9 +134,8 @@ set_shadow_status(struct vcpu *v, mfn_t 
    51.4                     d->domain_id, v->vcpu_id, mfn_x(gmfn),
    51.5                     shadow_type, mfn_x(smfn));
    51.6  
    51.7 -#ifdef CONFIG_COMPAT
    51.8 -    if ( !IS_COMPAT(d) || shadow_type != SH_type_l4_64_shadow )
    51.9 -#endif
   51.10 +    /* 32-on-64 PV guests don't own their l4 pages so can't get_page them */
   51.11 +    if ( !pv_32on64_vcpu(v) || shadow_type != SH_type_l4_64_shadow )
   51.12      {
   51.13          res = get_page(mfn_to_page(gmfn), d);
   51.14          ASSERT(res == 1);
   51.15 @@ -162,9 +161,8 @@ delete_shadow_status(struct vcpu *v, mfn
   51.16                     v->domain->domain_id, v->vcpu_id,
   51.17                     mfn_x(gmfn), shadow_type, mfn_x(smfn));
   51.18      shadow_hash_delete(v, mfn_x(gmfn), shadow_type, smfn);
   51.19 -#ifdef CONFIG_COMPAT
   51.20 -    if ( !IS_COMPAT(v->domain) || shadow_type != SH_type_l4_64_shadow )
   51.21 -#endif
   51.22 +    /* 32-on-64 PV guests don't own their l4 pages; see set_shadow_status */
   51.23 +    if ( !pv_32on64_vcpu(v) || shadow_type != SH_type_l4_64_shadow )
   51.24          put_page(mfn_to_page(gmfn));
   51.25  }
   51.26  
   51.27 @@ -746,7 +744,8 @@ static always_inline void
   51.28      // PV guests in 64-bit mode use two different page tables for user vs
   51.29      // supervisor permissions, making the guest's _PAGE_USER bit irrelevant.
   51.30      // It is always shadowed as present...
   51.31 -    if ( (GUEST_PAGING_LEVELS == 4) && !IS_COMPAT(d) && !is_hvm_domain(d) )
   51.32 +    if ( (GUEST_PAGING_LEVELS == 4) && !pv_32on64_domain(d) 
   51.33 +         && !is_hvm_domain(d) )
   51.34      {
   51.35          sflags |= _PAGE_USER;
   51.36      }
   51.37 @@ -1300,7 +1299,7 @@ do {                                    
   51.38      for ( _i = 0; _i < SHADOW_L2_PAGETABLE_ENTRIES; _i++ )                  \
   51.39      {                                                                       \
   51.40          if ( (!(_xen))                                                      \
   51.41 -             || !IS_COMPAT(_dom)                                            \
   51.42 +             || !pv_32on64_domain(_dom)                                     \
   51.43               || mfn_to_shadow_page(_sl2mfn)->type != SH_type_l2h_64_shadow  \
   51.44               || (_i < COMPAT_L2_PAGETABLE_FIRST_XEN_SLOT(_dom)) )           \
   51.45          {                                                                   \
   51.46 @@ -1411,7 +1410,7 @@ void sh_install_xen_entries_in_l4(struct
   51.47                                  __PAGE_HYPERVISOR);
   51.48      }
   51.49  
   51.50 -    if ( IS_COMPAT(v->domain) )
   51.51 +    if ( pv_32on64_domain(v->domain) )
   51.52      {
   51.53          /* install compat arg xlat entry */
   51.54          sl4e[shadow_l4_table_offset(COMPAT_ARG_XLAT_VIRT_BASE)] =
   51.55 @@ -1437,7 +1436,7 @@ static void sh_install_xen_entries_in_l2
   51.56      int i;
   51.57  #else
   51.58  
   51.59 -    if ( !pv_32bit_guest(v) )
   51.60 +    if ( !pv_32on64_vcpu(v) )
   51.61          return;
   51.62  #endif
   51.63  
   51.64 @@ -1622,9 +1621,6 @@ sh_make_shadow(struct vcpu *v, mfn_t gmf
   51.65  #endif
   51.66  #if CONFIG_PAGING_LEVELS >= 3 && GUEST_PAGING_LEVELS >= 3
   51.67          case SH_type_l2h_shadow:
   51.68 -#ifdef CONFIG_COMPAT
   51.69 -            ASSERT( IS_COMPAT(v->domain) );
   51.70 -#endif
   51.71              sh_install_xen_entries_in_l2h(v, smfn); break;
   51.72  #endif
   51.73  #if CONFIG_PAGING_LEVELS == 2 && GUEST_PAGING_LEVELS == 2
   51.74 @@ -1685,7 +1681,7 @@ sh_make_monitor_table(struct vcpu *v)
   51.75              l4e = sh_map_domain_page(m4mfn);
   51.76              l4e[0] = l4e_from_pfn(mfn_x(m3mfn), __PAGE_HYPERVISOR);
   51.77              sh_unmap_domain_page(l4e);
   51.78 -            if ( pv_32bit_guest(v) )
   51.79 +            if ( pv_32on64_vcpu(v) )
   51.80              {
   51.81                  // Install a monitor l2 table in slot 3 of the l3 table.
   51.82                  // This is used for all Xen entries.
   51.83 @@ -1840,13 +1836,12 @@ static shadow_l2e_t * shadow_get_and_cre
   51.84          shadow_l3e_t new_sl3e;
   51.85          unsigned int t = SH_type_l2_shadow;
   51.86  
   51.87 -#ifdef CONFIG_COMPAT
   51.88          /* Tag compat L2 containing hypervisor (m2p) mappings */
   51.89 -        if ( IS_COMPAT(v->domain) &&
   51.90 +        if ( pv_32on64_domain(v->domain) &&
   51.91               guest_l4_table_offset(gw->va) == 0 &&
   51.92               guest_l3_table_offset(gw->va) == 3 )
   51.93              t = SH_type_l2h_shadow;
   51.94 -#endif
   51.95 +
   51.96          /* No l2 shadow installed: find and install it. */
   51.97          *sl2mfn = get_shadow_status(v, gw->l2mfn, t);
   51.98          if ( !mfn_valid(*sl2mfn) ) 
   51.99 @@ -2111,7 +2106,7 @@ void sh_destroy_monitor_table(struct vcp
  51.100          l4_pgentry_t *l4e = sh_map_domain_page(mmfn);
  51.101          ASSERT(l4e_get_flags(l4e[0]) & _PAGE_PRESENT);
  51.102          m3mfn = _mfn(l4e_get_pfn(l4e[0]));
  51.103 -        if ( pv_32bit_guest(v) )
  51.104 +        if ( pv_32on64_vcpu(v) )
  51.105          {
  51.106              /* Need to destroy the l2 monitor page in slot 3 too */
  51.107              l3_pgentry_t *l3e = sh_map_domain_page(m3mfn);
  51.108 @@ -3474,7 +3469,7 @@ sh_update_cr3(struct vcpu *v, int do_loc
  51.109                     (unsigned long)pagetable_get_pfn(v->arch.guest_table));
  51.110  
  51.111  #if GUEST_PAGING_LEVELS == 4
  51.112 -    if ( !(v->arch.flags & TF_kernel_mode) && !IS_COMPAT(v->domain) )
  51.113 +    if ( !(v->arch.flags & TF_kernel_mode) && !pv_32on64_vcpu(v) )
  51.114          gmfn = pagetable_get_mfn(v->arch.guest_table_user);
  51.115      else
  51.116  #endif
  51.117 @@ -4285,7 +4280,7 @@ int sh_audit_l3_table(struct vcpu *v, mf
  51.118              mfn = shadow_l3e_get_mfn(*sl3e);
  51.119              gmfn = get_shadow_status(v, audit_gfn_to_mfn(v, gfn, gl3mfn), 
  51.120                                       ((GUEST_PAGING_LEVELS == 3 ||
  51.121 -                                       IS_COMPAT(v->domain))
  51.122 +                                       pv_32on64_vcpu(v))
  51.123                                        && !shadow_mode_external(v->domain)
  51.124                                        && (guest_index(gl3e) % 4) == 3)
  51.125                                       ? SH_type_l2h_shadow
    52.1 --- a/xen/arch/x86/x86_32/entry.S	Fri Apr 27 13:25:58 2007 +0100
    52.2 +++ b/xen/arch/x86/x86_32/entry.S	Fri Apr 27 13:31:09 2007 +0100
    52.3 @@ -75,6 +75,7 @@
    52.4  
    52.5          ALIGN
    52.6  restore_all_guest:
    52.7 +        ASSERT_INTERRUPTS_DISABLED
    52.8          testl $X86_EFLAGS_VM,UREGS_eflags(%esp)
    52.9          jnz  restore_all_vm86
   52.10  #ifdef CONFIG_X86_SUPERVISOR_MODE_KERNEL
   52.11 @@ -129,10 +130,10 @@ failsafe_callback:
   52.12          movl  %eax,TRAPBOUNCE_eip(%edx)
   52.13          movl  VCPU_failsafe_sel(%ebx),%eax
   52.14          movw  %ax,TRAPBOUNCE_cs(%edx)
   52.15 -        movw  $TBF_FAILSAFE,TRAPBOUNCE_flags(%edx)
   52.16 +        movb  $TBF_FAILSAFE,TRAPBOUNCE_flags(%edx)
   52.17          bt    $_VGCF_failsafe_disables_events,VCPU_guest_context_flags(%ebx)
   52.18          jnc   1f
   52.19 -        orw   $TBF_INTERRUPT,TRAPBOUNCE_flags(%edx)
   52.20 +        orb   $TBF_INTERRUPT,TRAPBOUNCE_flags(%edx)
   52.21  1:      call  create_bounce_frame
   52.22          xorl  %eax,%eax
   52.23          movl  %eax,UREGS_ds(%esp)
   52.24 @@ -247,7 +248,7 @@ test_guest_events:
   52.25          movl %eax,TRAPBOUNCE_eip(%edx)
   52.26          movl VCPU_event_sel(%ebx),%eax
   52.27          movw %ax,TRAPBOUNCE_cs(%edx)
   52.28 -        movw $TBF_INTERRUPT,TRAPBOUNCE_flags(%edx)
   52.29 +        movb $TBF_INTERRUPT,TRAPBOUNCE_flags(%edx)
   52.30          call create_bounce_frame
   52.31          jmp  test_all_events
   52.32  
   52.33 @@ -270,7 +271,7 @@ process_nmi:
   52.34          leal VCPU_trap_bounce(%ebx),%edx
   52.35          movl %eax,TRAPBOUNCE_eip(%edx)
   52.36          movw $FLAT_KERNEL_CS,TRAPBOUNCE_cs(%edx)
   52.37 -        movw $TBF_INTERRUPT,TRAPBOUNCE_flags(%edx)
   52.38 +        movb $TBF_INTERRUPT,TRAPBOUNCE_flags(%edx)
   52.39          call create_bounce_frame
   52.40          jmp  test_all_events
   52.41  
   52.42 @@ -383,7 +384,6 @@ 2:      testl $X86_EFLAGS_VM,UREGS_eflag
   52.43          movl %eax,UREGS_cs+4(%esp)
   52.44          movl TRAPBOUNCE_eip(%edx),%eax
   52.45          movl %eax,UREGS_eip+4(%esp)
   52.46 -        movb $0,TRAPBOUNCE_flags(%edx)
   52.47          ret
   52.48  .section __ex_table,"a"
   52.49          .long  .Lft6,domain_crash_synchronous ,  .Lft7,domain_crash_synchronous
   52.50 @@ -441,6 +441,7 @@ 1:      xorl  %eax,%eax
   52.51          testb $TBF_EXCEPTION,TRAPBOUNCE_flags(%edx)
   52.52          jz    test_all_events
   52.53          call  create_bounce_frame
   52.54 +        movb  $0,TRAPBOUNCE_flags(%edx)
   52.55          jmp   test_all_events
   52.56  
   52.57  exception_with_ints_disabled:
    53.1 --- a/xen/arch/x86/x86_64/compat/entry.S	Fri Apr 27 13:25:58 2007 +0100
    53.2 +++ b/xen/arch/x86/x86_64/compat/entry.S	Fri Apr 27 13:31:09 2007 +0100
    53.3 @@ -101,8 +101,8 @@ compat_test_guest_events:
    53.4          movl  VCPU_event_addr(%rbx),%eax
    53.5          movl  %eax,TRAPBOUNCE_eip(%rdx)
    53.6          movl  VCPU_event_sel(%rbx),%eax
    53.7 -        movl  %eax,TRAPBOUNCE_cs(%rdx)
    53.8 -        movw  $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
    53.9 +        movw  %ax,TRAPBOUNCE_cs(%rdx)
   53.10 +        movb  $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   53.11          call  compat_create_bounce_frame
   53.12          jmp   compat_test_all_events
   53.13  
   53.14 @@ -126,8 +126,8 @@ compat_process_nmi:
   53.15          sti
   53.16          leaq  VCPU_trap_bounce(%rbx),%rdx
   53.17          movl  %eax,TRAPBOUNCE_eip(%rdx)
   53.18 -        movl  $FLAT_COMPAT_KERNEL_CS,TRAPBOUNCE_cs(%rdx)
   53.19 -        movw  $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   53.20 +        movw  $FLAT_COMPAT_KERNEL_CS,TRAPBOUNCE_cs(%rdx)
   53.21 +        movb  $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   53.22          call  compat_create_bounce_frame
   53.23          jmp   compat_test_all_events
   53.24  
   53.25 @@ -164,13 +164,12 @@ compat_failsafe_callback:
   53.26          movl  VCPU_failsafe_addr(%rbx),%eax
   53.27          movl  %eax,TRAPBOUNCE_eip(%rdx)
   53.28          movl  VCPU_failsafe_sel(%rbx),%eax
   53.29 -        movl  %eax,TRAPBOUNCE_cs(%rdx)
   53.30 -        movw  $TBF_FAILSAFE,TRAPBOUNCE_flags(%rdx)
   53.31 +        movw  %ax,TRAPBOUNCE_cs(%rdx)
   53.32 +        movb  $TBF_FAILSAFE,TRAPBOUNCE_flags(%rdx)
   53.33          btq   $_VGCF_failsafe_disables_events,VCPU_guest_context_flags(%rbx)
   53.34          jnc   1f
   53.35 -        orw   $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   53.36 -1:
   53.37 -        call  compat_create_bounce_frame
   53.38 +        orb   $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   53.39 +1:      call  compat_create_bounce_frame
   53.40          jmp   compat_test_all_events
   53.41  .previous
   53.42  .section __pre_ex_table,"a"
   53.43 @@ -185,6 +184,7 @@ ENTRY(compat_post_handle_exception)
   53.44          testb $TBF_EXCEPTION,TRAPBOUNCE_flags(%rdx)
   53.45          jz    compat_test_all_events
   53.46          call  compat_create_bounce_frame
   53.47 +        movb  $0,TRAPBOUNCE_flags(%rdx)
   53.48          jmp   compat_test_all_events
   53.49  
   53.50  ENTRY(compat_int80_direct_trap)
   53.51 @@ -194,7 +194,7 @@ ENTRY(compat_int80_direct_trap)
   53.52  /* CREATE A BASIC EXCEPTION FRAME ON GUEST OS (RING-1) STACK:            */
   53.53  /*   {[ERRCODE,] EIP, CS, EFLAGS, [ESP, SS]}                             */
   53.54  /* %rdx: trap_bounce, %rbx: struct vcpu                                  */
   53.55 -/* On return only %rbx is guaranteed non-clobbered.                      */
   53.56 +/* On return only %rbx and %rdx are guaranteed non-clobbered.            */
   53.57  compat_create_bounce_frame:
   53.58          ASSERT_INTERRUPTS_ENABLED
   53.59          mov   %fs,%edi
   53.60 @@ -253,7 +253,6 @@ 1:
   53.61  2:
   53.62          /* Rewrite our stack frame and return to guest-OS mode. */
   53.63          /* IA32 Ref. Vol. 3: TF, VM, RF and NT flags are cleared on trap. */
   53.64 -        movl  $TRAP_syscall,UREGS_entry_vector+8(%rsp)
   53.65          andl  $~(X86_EFLAGS_VM|X86_EFLAGS_RF|\
   53.66                   X86_EFLAGS_NT|X86_EFLAGS_TF),UREGS_eflags+8(%rsp)
   53.67          mov   %fs,UREGS_ss+8(%rsp)
   53.68 @@ -266,7 +265,6 @@ 2:
   53.69          movl  %eax,UREGS_cs+8(%rsp)
   53.70          movl  TRAPBOUNCE_eip(%rdx),%eax
   53.71          movl  %eax,UREGS_rip+8(%rsp)
   53.72 -        movb  $0,TRAPBOUNCE_flags(%rdx)
   53.73          ret
   53.74  .section .fixup,"ax"
   53.75  .Lfx13:
   53.76 @@ -333,7 +331,7 @@ ENTRY(compat_hypercall_table)
   53.77          .quad compat_vcpu_op
   53.78          .quad compat_ni_hypercall       /* 25 */
   53.79          .quad compat_mmuext_op
   53.80 -        .quad compat_acm_op
   53.81 +        .quad do_acm_op
   53.82          .quad compat_nmi_op
   53.83          .quad compat_sched_op
   53.84          .quad compat_callback_op        /* 30 */
   53.85 @@ -376,7 +374,7 @@ ENTRY(compat_hypercall_args_table)
   53.86          .byte 3 /* compat_vcpu_op           */
   53.87          .byte 0 /* compat_ni_hypercall      */  /* 25 */
   53.88          .byte 4 /* compat_mmuext_op         */
   53.89 -        .byte 1 /* compat_acm_op            */
   53.90 +        .byte 1 /* do_acm_op                */
   53.91          .byte 2 /* compat_nmi_op            */
   53.92          .byte 2 /* compat_sched_op          */
   53.93          .byte 2 /* compat_callback_op       */  /* 30 */
    54.1 --- a/xen/arch/x86/x86_64/entry.S	Fri Apr 27 13:25:58 2007 +0100
    54.2 +++ b/xen/arch/x86/x86_64/entry.S	Fri Apr 27 13:31:09 2007 +0100
    54.3 @@ -29,10 +29,10 @@ switch_to_kernel:
    54.4          leaq  VCPU_trap_bounce(%rbx),%rdx
    54.5          movq  VCPU_syscall_addr(%rbx),%rax
    54.6          movq  %rax,TRAPBOUNCE_eip(%rdx)
    54.7 -        movw  $0,TRAPBOUNCE_flags(%rdx)
    54.8 +        movb  $0,TRAPBOUNCE_flags(%rdx)
    54.9          bt    $_VGCF_syscall_disables_events,VCPU_guest_context_flags(%rbx)
   54.10          jnc   1f
   54.11 -        orw   $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   54.12 +        movb  $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   54.13  1:      call  create_bounce_frame
   54.14          jmp   test_all_events
   54.15  
   54.16 @@ -80,10 +80,10 @@ failsafe_callback:
   54.17          leaq  VCPU_trap_bounce(%rbx),%rdx
   54.18          movq  VCPU_failsafe_addr(%rbx),%rax
   54.19          movq  %rax,TRAPBOUNCE_eip(%rdx)
   54.20 -        movw  $TBF_FAILSAFE,TRAPBOUNCE_flags(%rdx)
   54.21 +        movb  $TBF_FAILSAFE,TRAPBOUNCE_flags(%rdx)
   54.22          bt    $_VGCF_failsafe_disables_events,VCPU_guest_context_flags(%rbx)
   54.23          jnc   1f
   54.24 -        orw   $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   54.25 +        orb   $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   54.26  1:      call  create_bounce_frame
   54.27          jmp   test_all_events
   54.28  .previous
   54.29 @@ -191,7 +191,7 @@ test_guest_events:
   54.30          leaq  VCPU_trap_bounce(%rbx),%rdx
   54.31          movq  VCPU_event_addr(%rbx),%rax
   54.32          movq  %rax,TRAPBOUNCE_eip(%rdx)
   54.33 -        movw  $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   54.34 +        movb  $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   54.35          call  create_bounce_frame
   54.36          jmp   test_all_events
   54.37  
   54.38 @@ -215,7 +215,7 @@ process_nmi:
   54.39          sti
   54.40          leaq VCPU_trap_bounce(%rbx),%rdx
   54.41          movq %rax,TRAPBOUNCE_eip(%rdx)
   54.42 -        movw $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   54.43 +        movb $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   54.44          call create_bounce_frame
   54.45          jmp  test_all_events
   54.46  
   54.47 @@ -231,7 +231,7 @@ ENTRY(int80_direct_trap)
   54.48  
   54.49          /* Check that the callback is non-null. */
   54.50          leaq  VCPU_int80_bounce(%rbx),%rdx
   54.51 -        cmp   $0,TRAPBOUNCE_flags(%rdx)
   54.52 +        cmpb  $0,TRAPBOUNCE_flags(%rdx)
   54.53          jz    int80_slow_path
   54.54  
   54.55          movq  VCPU_domain(%rbx),%rax
   54.56 @@ -249,13 +249,13 @@ int80_slow_path:
   54.57          movl  $((0x80 << 3) | 0x2),UREGS_error_code(%rsp)
   54.58          movl  $TRAP_gp_fault,UREGS_entry_vector(%rsp)
   54.59          /* A GPF wouldn't have incremented the instruction pointer. */
   54.60 -        sub   $2,UREGS_rip(%rsp)
   54.61 +        subq  $2,UREGS_rip(%rsp)
   54.62          jmp   handle_exception_saved
   54.63  
   54.64  /* CREATE A BASIC EXCEPTION FRAME ON GUEST OS STACK:                     */
   54.65  /*   { RCX, R11, [DS-GS,] [CR2,] [ERRCODE,] RIP, CS, RFLAGS, RSP, SS }   */
   54.66 -/* %rdx: trap_bounce, %rbx: struct vcpu                           */
   54.67 -/* On return only %rbx is guaranteed non-clobbered.                      */
   54.68 +/* %rdx: trap_bounce, %rbx: struct vcpu                                  */
   54.69 +/* On return only %rbx and %rdx are guaranteed non-clobbered.            */
   54.70  create_bounce_frame:
   54.71          ASSERT_INTERRUPTS_ENABLED
   54.72          testb $TF_kernel_mode,VCPU_thread_flags(%rbx)
   54.73 @@ -336,7 +336,6 @@ 2:      subq  $16,%rsi
   54.74          testq %rax,%rax
   54.75          jz    domain_crash_synchronous
   54.76          movq  %rax,UREGS_rip+8(%rsp)
   54.77 -        movb  $0,TRAPBOUNCE_flags(%rdx)
   54.78          ret
   54.79  .section __ex_table,"a"
   54.80          .quad  .Lft2,domain_crash_synchronous ,  .Lft3,domain_crash_synchronous
   54.81 @@ -401,6 +400,7 @@ 1:      movq  %rsp,%rdi
   54.82          testb $TBF_EXCEPTION,TRAPBOUNCE_flags(%rdx)
   54.83          jz    test_all_events
   54.84          call  create_bounce_frame
   54.85 +        movb  $0,TRAPBOUNCE_flags(%rdx)
   54.86          jmp   test_all_events
   54.87  
   54.88  /* No special register assumptions. */
    55.1 --- a/xen/arch/x86/x86_64/traps.c	Fri Apr 27 13:25:58 2007 +0100
    55.2 +++ b/xen/arch/x86/x86_64/traps.c	Fri Apr 27 13:31:09 2007 +0100
    55.3 @@ -357,9 +357,6 @@ void init_int80_direct_trap(struct vcpu 
    55.4      struct trap_info *ti = &v->arch.guest_context.trap_ctxt[0x80];
    55.5      struct trap_bounce *tb = &v->arch.int80_bounce;
    55.6  
    55.7 -    if ( !guest_gate_selector_okay(v->domain, ti->cs) )
    55.8 -         return;
    55.9 -
   55.10      tb->flags = TBF_EXCEPTION;
   55.11      tb->cs    = ti->cs;
   55.12      tb->eip   = ti->address;
    56.1 --- a/xen/common/Makefile	Fri Apr 27 13:25:58 2007 +0100
    56.2 +++ b/xen/common/Makefile	Fri Apr 27 13:31:09 2007 +0100
    56.3 @@ -43,7 +43,6 @@ version.o: $(BASEDIR)/include/xen/compil
    56.4  
    56.5  ifeq ($(CONFIG_COMPAT),y)
    56.6  # extra dependencies
    56.7 -acm_ops.o: compat/acm_ops.c
    56.8  grant_table.o: compat/grant_table.c
    56.9  kexec.o: compat/kexec.c
   56.10  schedule.o: compat/schedule.c
    57.1 --- a/xen/common/acm_ops.c	Fri Apr 27 13:25:58 2007 +0100
    57.2 +++ b/xen/common/acm_ops.c	Fri Apr 27 13:31:09 2007 +0100
    57.3 @@ -12,10 +12,8 @@
    57.4   * License.
    57.5   *
    57.6   * Process acm command requests from guest OS.
    57.7 - *
    57.8   */
    57.9  
   57.10 -#ifndef COMPAT
   57.11  #include <xen/config.h>
   57.12  #include <xen/types.h>
   57.13  #include <xen/lib.h>
   57.14 @@ -29,38 +27,25 @@
   57.15  #include <xen/guest_access.h>
   57.16  #include <acm/acm_hooks.h>
   57.17  
   57.18 -typedef long ret_t;
   57.19 -
   57.20 -#endif /* !COMPAT */
   57.21 -
   57.22  #ifndef ACM_SECURITY
   57.23  
   57.24 -
   57.25  long do_acm_op(int cmd, XEN_GUEST_HANDLE(void) arg)
   57.26  {
   57.27      return -ENOSYS;
   57.28  }
   57.29  
   57.30 -
   57.31  #else
   57.32  
   57.33 -
   57.34 -#ifndef COMPAT
   57.35  int acm_authorize_acm_ops(struct domain *d)
   57.36  {
   57.37 -    /* currently, policy management functions are restricted to privileged domains */
   57.38 -    if (!IS_PRIV(d))
   57.39 -        return -EPERM;
   57.40 -    return 0;
   57.41 +    return (IS_PRIV(d) ? 0 : -EPERM);
   57.42  }
   57.43 -#endif
   57.44  
   57.45 -
   57.46 -ret_t do_acm_op(int cmd, XEN_GUEST_HANDLE(void) arg)
   57.47 +long do_acm_op(int cmd, XEN_GUEST_HANDLE(void) arg)
   57.48  {
   57.49 -    ret_t rc = -EFAULT;
   57.50 +    long rc = -EFAULT;
   57.51  
   57.52 -    if (acm_authorize_acm_ops(current->domain))
   57.53 +    if ( acm_authorize_acm_ops(current->domain) )
   57.54          return -EPERM;
   57.55  
   57.56      switch ( cmd )
   57.57 @@ -226,11 +211,9 @@ ret_t do_acm_op(int cmd, XEN_GUEST_HANDL
   57.58  
   57.59          rc = acm_change_policy(&chgpolicy);
   57.60  
   57.61 -        if (rc == 0) {
   57.62 -            if (copy_to_guest(arg, &chgpolicy, 1) != 0) {
   57.63 +        if (rc == 0)
   57.64 +            if (copy_to_guest(arg, &chgpolicy, 1) != 0)
   57.65                  rc = -EFAULT;
   57.66 -            }
   57.67 -        }
   57.68          break;
   57.69      }
   57.70  
   57.71 @@ -244,11 +227,9 @@ ret_t do_acm_op(int cmd, XEN_GUEST_HANDL
   57.72  
   57.73          rc = acm_relabel_domains(&relabeldoms);
   57.74  
   57.75 -        if (rc == 0) {
   57.76 -            if (copy_to_guest(arg, &relabeldoms, 1) != 0) {
   57.77 +        if (rc == 0)
   57.78 +            if (copy_to_guest(arg, &relabeldoms, 1) != 0)
   57.79                  rc = -EFAULT;
   57.80 -            }
   57.81 -        }
   57.82          break;
   57.83      }
   57.84  
   57.85 @@ -260,11 +241,7 @@ ret_t do_acm_op(int cmd, XEN_GUEST_HANDL
   57.86      return rc;
   57.87  }
   57.88  
   57.89 -#endif
   57.90 -
   57.91 -#if defined(CONFIG_COMPAT) && !defined(COMPAT)
   57.92 -#include "compat/acm_ops.c"
   57.93 -#endif
   57.94 +#endif /* defined(ACM_SECURITY) */
   57.95  
   57.96  /*
   57.97   * Local variables:
    58.1 --- a/xen/common/compat/acm_ops.c	Fri Apr 27 13:25:58 2007 +0100
    58.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    58.3 @@ -1,47 +0,0 @@
    58.4 -/******************************************************************************
    58.5 - * compat/acm_ops.c
    58.6 - */
    58.7 -
    58.8 -#include <compat/acm.h>
    58.9 -#include <compat/acm_ops.h>
   58.10 -
   58.11 -#define COMPAT
   58.12 -#define ret_t int
   58.13 -
   58.14 -#define do_acm_op compat_acm_op
   58.15 -
   58.16 -static inline XEN_GUEST_HANDLE(void) acm_xlat_handle(COMPAT_HANDLE(void) cmp)
   58.17 -{
   58.18 -    XEN_GUEST_HANDLE(void) nat;
   58.19 -
   58.20 -    guest_from_compat_handle(nat, cmp);
   58.21 -    return nat;
   58.22 -}
   58.23 -
   58.24 -#define acm_setpolicy compat_acm_setpolicy
   58.25 -#define acm_set_policy(h, sz) acm_set_policy(acm_xlat_handle(h), sz)
   58.26 -
   58.27 -#define acm_getpolicy compat_acm_getpolicy
   58.28 -#define acm_get_policy(h, sz) acm_get_policy(acm_xlat_handle(h), sz)
   58.29 -
   58.30 -#define acm_dumpstats compat_acm_dumpstats
   58.31 -#define acm_dump_statistics(h, sz) acm_dump_statistics(acm_xlat_handle(h), sz)
   58.32 -
   58.33 -#define acm_getssid compat_acm_getssid
   58.34 -#define acm_get_ssid(r, h, sz) acm_get_ssid(r, acm_xlat_handle(h), sz)
   58.35 -
   58.36 -#define xen_acm_getdecision acm_getdecision
   58.37 -CHECK_acm_getdecision;
   58.38 -#undef xen_acm_getdecision
   58.39 -
   58.40 -#include "../acm_ops.c"
   58.41 -
   58.42 -/*
   58.43 - * Local variables:
   58.44 - * mode: C
   58.45 - * c-set-style: "BSD"
   58.46 - * c-basic-offset: 4
   58.47 - * tab-width: 4
   58.48 - * indent-tabs-mode: nil
   58.49 - * End:
   58.50 - */
    59.1 --- a/xen/include/Makefile	Fri Apr 27 13:25:58 2007 +0100
    59.2 +++ b/xen/include/Makefile	Fri Apr 27 13:31:09 2007 +0100
    59.3 @@ -3,8 +3,6 @@ ifneq ($(CONFIG_COMPAT),)
    59.4  compat-arch-$(CONFIG_X86) := x86_32
    59.5  
    59.6  headers-y := \
    59.7 -    compat/acm.h \
    59.8 -    compat/acm_ops.h \
    59.9      compat/callback.h \
   59.10      compat/elfnote.h \
   59.11      compat/event_channel.h \
    60.1 --- a/xen/include/acm/acm_core.h	Fri Apr 27 13:25:58 2007 +0100
    60.2 +++ b/xen/include/acm/acm_core.h	Fri Apr 27 13:31:09 2007 +0100
    60.3 @@ -155,13 +155,13 @@ int acm_init_domain_ssid(domid_t id, ssi
    60.4  int acm_init_domain_ssid_new(struct domain *, ssidref_t ssidref);
    60.5  void acm_free_domain_ssid(struct acm_ssid_domain *ssid);
    60.6  int acm_init_binary_policy(u32 policy_code);
    60.7 -int acm_set_policy(XEN_GUEST_HANDLE(void) buf, u32 buf_size);
    60.8 +int acm_set_policy(XEN_GUEST_HANDLE_64(void) buf, u32 buf_size);
    60.9  int do_acm_set_policy(void *buf, u32 buf_size, int is_bootpolicy,
   60.10                        struct acm_sized_buffer *, struct acm_sized_buffer *,
   60.11                        struct acm_sized_buffer *);
   60.12 -int acm_get_policy(XEN_GUEST_HANDLE(void) buf, u32 buf_size);
   60.13 -int acm_dump_statistics(XEN_GUEST_HANDLE(void) buf, u16 buf_size);
   60.14 -int acm_get_ssid(ssidref_t ssidref, XEN_GUEST_HANDLE(void) buf, u16 buf_size);
   60.15 +int acm_get_policy(XEN_GUEST_HANDLE_64(void) buf, u32 buf_size);
   60.16 +int acm_dump_statistics(XEN_GUEST_HANDLE_64(void) buf, u16 buf_size);
   60.17 +int acm_get_ssid(ssidref_t ssidref, XEN_GUEST_HANDLE_64(void) buf, u16 buf_size);
   60.18  int acm_get_decision(ssidref_t ssidref1, ssidref_t ssidref2, u32 hook);
   60.19  int acm_set_policy_reference(u8 * buf, u32 buf_size);
   60.20  int acm_dump_policy_reference(u8 *buf, u32 buf_size);
    61.1 --- a/xen/include/asm-x86/domain.h	Fri Apr 27 13:25:58 2007 +0100
    61.2 +++ b/xen/include/asm-x86/domain.h	Fri Apr 27 13:31:09 2007 +0100
    61.3 @@ -7,11 +7,24 @@
    61.4  #include <asm/hvm/domain.h>
    61.5  #include <asm/e820.h>
    61.6  
    61.7 +#ifdef __x86_64__
    61.8 +#define pv_32bit_vcpu(v)    (!is_hvm_vcpu(v) && IS_COMPAT((v)->domain))
    61.9 +#define pv_32bit_domain(d)  (!is_hvm_domain(d) && IS_COMPAT(d))
   61.10 +#define pv_32on64_vcpu(v)   (pv_32bit_vcpu(v))
   61.11 +#define pv_32on64_domain(d) (pv_32bit_domain(d))
   61.12 +#else
   61.13 +#define pv_32bit_vcpu(v)    (!is_hvm_vcpu(v))
   61.14 +#define pv_32bit_domain(d)  (!is_hvm_domain(d))
   61.15 +#define pv_32on64_vcpu(v)   (0)
   61.16 +#define pv_32on64_domain(d) (0)
   61.17 +#endif
   61.18 +
   61.19 +
   61.20  struct trap_bounce {
   61.21 -    unsigned long  error_code;
   61.22 -    unsigned short flags; /* TBF_ */
   61.23 -    unsigned short cs;
   61.24 -    unsigned long  eip;
   61.25 +    uint32_t      error_code;
   61.26 +    uint8_t       flags; /* TBF_ */
   61.27 +    uint16_t      cs;
   61.28 +    unsigned long eip;
   61.29  };
   61.30  
   61.31  #define MAPHASH_ENTRIES 8
    62.1 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h	Fri Apr 27 13:25:58 2007 +0100
    62.2 +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h	Fri Apr 27 13:31:09 2007 +0100
    62.3 @@ -119,6 +119,8 @@ extern u32 vmx_vmexit_control;
    62.4  #define VM_ENTRY_DEACT_DUAL_MONITOR     0x00000800
    62.5  extern u32 vmx_vmentry_control;
    62.6  
    62.7 +#define cpu_has_vmx_tpr_shadow \
    62.8 +    (vmx_cpu_based_exec_control & CPU_BASED_TPR_SHADOW)
    62.9  #define cpu_has_vmx_msr_bitmap \
   62.10      (vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_MSR_BITMAP)
   62.11  extern char *vmx_msr_bitmap;
    63.1 --- a/xen/include/asm-x86/shadow.h	Fri Apr 27 13:25:58 2007 +0100
    63.2 +++ b/xen/include/asm-x86/shadow.h	Fri Apr 27 13:31:09 2007 +0100
    63.3 @@ -48,16 +48,6 @@
    63.4   * not yet supported */
    63.5  #define shadow_mode_trap_reads(_d) ({ (void)(_d); 0; })
    63.6  
    63.7 -/*
    63.8 - * 32on64 support
    63.9 - */
   63.10 -#ifdef __x86_64__
   63.11 -#define pv_32bit_guest(_v) (!is_hvm_vcpu(_v) && IS_COMPAT((_v)->domain))
   63.12 -#else
   63.13 -#define pv_32bit_guest(_v) (!is_hvm_vcpu(_v))
   63.14 -#endif
   63.15 -
   63.16 -
   63.17  /*****************************************************************************
   63.18   * Entry points into the shadow code */
   63.19  
    64.1 --- a/xen/include/public/hvm/save.h	Fri Apr 27 13:25:58 2007 +0100
    64.2 +++ b/xen/include/public/hvm/save.h	Fri Apr 27 13:31:09 2007 +0100
    64.3 @@ -32,7 +32,8 @@
    64.4  /*
    64.5   * Structures in this header *must* have the same layout in 32bit 
    64.6   * and 64bit environments: this means that all fields must be explicitly 
    64.7 - * sized types and aligned to their sizes.
    64.8 + * sized types and aligned to their sizes, and the structs must be 
    64.9 + * a multiple of eight bytes long.
   64.10   *
   64.11   * Only the state necessary for saving and restoring (i.e. fields 
   64.12   * that are analogous to actual hardware state) should go in this file. 
   64.13 @@ -77,6 +78,7 @@ struct hvm_save_header {
   64.14      uint32_t version;           /* File format version */
   64.15      uint64_t changeset;         /* Version of Xen that saved this file */
   64.16      uint32_t cpuid;             /* CPUID[0x01][%eax] on the saving machine */
   64.17 +    uint32_t pad0;
   64.18  };
   64.19  
   64.20  DECLARE_HVM_SAVE_TYPE(HEADER, 1, struct hvm_save_header);
   64.21 @@ -340,6 +342,7 @@ struct hvm_hw_pci_link {
   64.22       * The router provides a programmable mapping from each link to a GSI.
   64.23       */
   64.24      uint8_t route[4];
   64.25 +    uint8_t pad0[4];
   64.26  };
   64.27  
   64.28  DECLARE_HVM_SAVE_TYPE(PCI_LINK, 9, struct hvm_hw_pci_link);
   64.29 @@ -364,6 +367,7 @@ struct hvm_hw_pit {
   64.30          uint8_t gate; /* timer start */
   64.31      } channels[3];  /* 3 x 16 bytes */
   64.32      uint32_t speaker_data_on;
   64.33 +    uint32_t pad0;
   64.34  };
   64.35  
   64.36  DECLARE_HVM_SAVE_TYPE(PIT, 10, struct hvm_hw_pit);
   64.37 @@ -379,6 +383,7 @@ struct hvm_hw_rtc {
   64.38      uint8_t cmos_data[RTC_CMOS_SIZE];
   64.39      /* Index register for 2-part operations */
   64.40      uint8_t cmos_index;
   64.41 +    uint8_t pad0;
   64.42  };
   64.43  
   64.44  DECLARE_HVM_SAVE_TYPE(RTC, 11, struct hvm_hw_rtc);
    65.1 --- a/xen/include/xlat.lst	Fri Apr 27 13:25:58 2007 +0100
    65.2 +++ b/xen/include/xlat.lst	Fri Apr 27 13:31:09 2007 +0100
    65.3 @@ -9,7 +9,6 @@
    65.4  !	cpu_user_regs			arch-x86/xen-@arch@.h
    65.5  !	trap_info			arch-x86/xen.h
    65.6  !	vcpu_guest_context		arch-x86/xen.h
    65.7 -?	acm_getdecision			acm_ops.h
    65.8  ?	evtchn_alloc_unbound		event_channel.h
    65.9  ?	evtchn_bind_interdomain		event_channel.h
   65.10  ?	evtchn_bind_ipi			event_channel.h