ia64/xen-unstable

changeset 1651:bb0cd2c046b0

bitkeeper revision 1.1041.1.5 (40e3c0467qvzGCG5_k0ERlfXYvvLXg)

Merge xenbk@gandalf:/var/bk/xeno-unstable.bk
into wray-m-3.hpl.hp.com:/home/mjw/repos-bk/xeno-unstable.bk
author mjw@wray-m-3.hpl.hp.com
date Thu Jul 01 07:41:58 2004 +0000 (2004-07-01)
parents 351141a3792f 19a9925664d8
children b4bc38d3acd4
files tools/libxc/xc_linux_build.c tools/libxc/xc_linux_restore.c tools/libxc/xc_netbsd_build.c tools/libxc/xc_private.c tools/libxc/xc_private.h tools/python/xen/lowlevel/xu/xu.c tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/channel.py
line diff
     1.1 --- a/tools/libxc/xc_linux_build.c	Thu Jul 01 07:41:45 2004 +0000
     1.2 +++ b/tools/libxc/xc_linux_build.c	Thu Jul 01 07:41:58 2004 +0000
     1.3 @@ -18,7 +18,7 @@ static int readelfimage_base_and_size(ch
     1.4                                        unsigned long *pkernstart,
     1.5                                        unsigned long *pkernend,
     1.6                                        unsigned long *pkernentry);
     1.7 -static int loadelfimage(char *elfbase, int pmh, unsigned long *parray,
     1.8 +static int loadelfimage(char *elfbase, void *pmh, unsigned long *parray,
     1.9                          unsigned long vstart);
    1.10  
    1.11  static long get_tot_pages(int xc_handle, u32 domid)
    1.12 @@ -53,7 +53,7 @@ static int get_pfn_list(int xc_handle,
    1.13      return (ret < 0) ? -1 : op.u.getmemlist.num_pfns;
    1.14  }
    1.15  
    1.16 -static int copy_to_domain_page(int pm_handle,
    1.17 +static int copy_to_domain_page(void *pm_handle,
    1.18                                 unsigned long dst_pfn, 
    1.19                                 void *src_page)
    1.20  {
    1.21 @@ -86,7 +86,8 @@ static int setup_guestos(int xc_handle,
    1.22      extended_start_info_t *start_info;
    1.23      shared_info_t *shared_info;
    1.24      mmu_t *mmu = NULL;
    1.25 -    int pm_handle=-1, rc;
    1.26 +    void  *pm_handle=NULL;
    1.27 +    int rc;
    1.28  
    1.29      unsigned long nr_pt_pages;
    1.30      unsigned long ppt_alloc;
    1.31 @@ -165,7 +166,7 @@ static int setup_guestos(int xc_handle,
    1.32             v_start, v_end);
    1.33      printf(" ENTRY ADDRESS: %08lx\n", vkern_entry);
    1.34  
    1.35 -    if ( (pm_handle = init_pfn_mapper((domid_t)dom)) < 0 )
    1.36 +    if ( (pm_handle = init_pfn_mapper((domid_t)dom)) == NULL )
    1.37          goto error_out;
    1.38  
    1.39      if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL )
    1.40 @@ -307,7 +308,7 @@ static int setup_guestos(int xc_handle,
    1.41   error_out:
    1.42      if ( mmu != NULL )
    1.43          free(mmu);
    1.44 -    if ( pm_handle >= 0 )
    1.45 +    if ( pm_handle != NULL )
    1.46          (void)close_pfn_mapper(pm_handle);
    1.47      if ( page_array != NULL )
    1.48          free(page_array);
    1.49 @@ -629,7 +630,7 @@ static int readelfimage_base_and_size(ch
    1.50      return 0;
    1.51  }
    1.52  
    1.53 -static int loadelfimage(char *elfbase, int pmh, unsigned long *parray,
    1.54 +static int loadelfimage(char *elfbase, void *pmh, unsigned long *parray,
    1.55                          unsigned long vstart)
    1.56  {
    1.57      Elf_Ehdr *ehdr = (Elf_Ehdr *)elfbase;
    1.58 @@ -649,11 +650,11 @@ static int loadelfimage(char *elfbase, i
    1.59          {
    1.60              pa = (phdr->p_vaddr + done) - vstart;
    1.61              va = map_pfn_writeable(pmh, parray[pa>>PAGE_SHIFT]);
    1.62 -            va += pa & (PAGE_SIZE-1);
    1.63              chunksz = phdr->p_filesz - done;
    1.64              if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
    1.65                  chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
    1.66 -            memcpy(va, elfbase + phdr->p_offset + done, chunksz);
    1.67 +            memcpy(va + (pa & (PAGE_SIZE-1)),
    1.68 +                   elfbase + phdr->p_offset + done, chunksz);
    1.69              unmap_pfn(pmh, va);
    1.70          }
    1.71  
    1.72 @@ -661,11 +662,10 @@ static int loadelfimage(char *elfbase, i
    1.73          {
    1.74              pa = (phdr->p_vaddr + done) - vstart;
    1.75              va = map_pfn_writeable(pmh, parray[pa>>PAGE_SHIFT]);
    1.76 -            va += pa & (PAGE_SIZE-1);
    1.77              chunksz = phdr->p_memsz - done;
    1.78              if ( chunksz > (PAGE_SIZE - (pa & (PAGE_SIZE-1))) )
    1.79                  chunksz = PAGE_SIZE - (pa & (PAGE_SIZE-1));
    1.80 -            memset(va, 0, chunksz);
    1.81 +            memset(va + (pa & (PAGE_SIZE-1)), 0, chunksz);
    1.82              unmap_pfn(pmh, va);            
    1.83          }
    1.84      }
     2.1 --- a/tools/libxc/xc_linux_restore.c	Thu Jul 01 07:41:45 2004 +0000
     2.2 +++ b/tools/libxc/xc_linux_restore.c	Thu Jul 01 07:41:58 2004 +0000
     2.3 @@ -19,7 +19,6 @@
     2.4  #define DPRINTF(_f, _a...) ((void)0)
     2.5  #endif
     2.6  
     2.7 -
     2.8  static int get_pfn_list(int xc_handle,
     2.9                          u32 domain_id, 
    2.10                          unsigned long *pfn_buf, 
    2.11 @@ -53,23 +52,28 @@ static int get_pfn_list(int xc_handle,
    2.12   * @param ioctxt i/o context
    2.13   * @return 0 on success, non-zero on error.
    2.14   */
    2.15 -static int read_vmconfig(XcIOContext *ioctxt){
    2.16 +static int read_vmconfig(XcIOContext *ioctxt)
    2.17 +{
    2.18      int err = -1;
    2.19 -    if(xcio_read(ioctxt, &ioctxt->vmconfig_n, sizeof(ioctxt->vmconfig_n))){
    2.20 +
    2.21 +    if ( xcio_read(ioctxt, &ioctxt->vmconfig_n, sizeof(ioctxt->vmconfig_n)) )
    2.22          goto exit;
    2.23 -    }
    2.24 +
    2.25      ioctxt->vmconfig = malloc(ioctxt->vmconfig_n + 1);
    2.26 -    if(!ioctxt->vmconfig) goto exit;
    2.27 -    if(xcio_read(ioctxt, ioctxt->vmconfig, ioctxt->vmconfig_n)){
    2.28 +    if ( ioctxt->vmconfig == NULL ) 
    2.29          goto exit;
    2.30 -    }
    2.31 +
    2.32 +    if ( xcio_read(ioctxt, ioctxt->vmconfig, ioctxt->vmconfig_n) )
    2.33 +        goto exit;
    2.34 +
    2.35      ioctxt->vmconfig[ioctxt->vmconfig_n] = '\0';
    2.36      err = 0;
    2.37 +
    2.38    exit:
    2.39 -    if(err){
    2.40 -        if(ioctxt->vmconfig){
    2.41 +    if ( err )
    2.42 +    {
    2.43 +        if ( ioctxt->vmconfig != NULL )
    2.44              free(ioctxt->vmconfig);
    2.45 -        }
    2.46          ioctxt->vmconfig = NULL;
    2.47          ioctxt->vmconfig_n = 0;
    2.48      }
    2.49 @@ -126,12 +130,13 @@ int xc_linux_restore(int xc_handle, XcIO
    2.50  
    2.51      mmu_t *mmu = NULL;
    2.52  
    2.53 -    int pm_handle = -1;
    2.54 +    void *pm_handle = NULL;
    2.55  
    2.56      /* used by debug verify code */
    2.57      unsigned long buf[PAGE_SIZE/sizeof(unsigned long)];
    2.58  
    2.59 -    if ( mlock(&ctxt, sizeof(ctxt) ) ) {   
    2.60 +    if ( mlock(&ctxt, sizeof(ctxt) ) )
    2.61 +    {
    2.62          /* needed for when we do the build dom0 op, 
    2.63             but might as well do early */
    2.64          PERROR("Unable to mlock ctxt");
    2.65 @@ -140,24 +145,28 @@ int xc_linux_restore(int xc_handle, XcIO
    2.66  
    2.67      /* Start writing out the saved-domain record. */
    2.68      if ( xcio_read(ioctxt, signature, 16) ||
    2.69 -         (memcmp(signature, "LinuxGuestRecord", 16) != 0) ) {
    2.70 +         (memcmp(signature, "LinuxGuestRecord", 16) != 0) )
    2.71 +    {
    2.72          xcio_error(ioctxt, "Unrecognised state format -- no signature found");
    2.73          goto out;
    2.74      }
    2.75  
    2.76      if ( xcio_read(ioctxt, name,                  sizeof(name)) ||
    2.77           xcio_read(ioctxt, &nr_pfns,              sizeof(unsigned long)) ||
    2.78 -         xcio_read(ioctxt, pfn_to_mfn_frame_list, PAGE_SIZE) ) {
    2.79 +         xcio_read(ioctxt, pfn_to_mfn_frame_list, PAGE_SIZE) )
    2.80 +    {
    2.81          xcio_error(ioctxt, "Error reading header");
    2.82          goto out;
    2.83      }
    2.84  
    2.85 -    if(read_vmconfig(ioctxt)){
    2.86 +    if ( read_vmconfig(ioctxt) )
    2.87 +    {
    2.88          xcio_error(ioctxt, "Error writing vmconfig");
    2.89          goto out;
    2.90      }
    2.91  
    2.92 -    for ( i = 0; i < MAX_DOMAIN_NAME; i++ ) {
    2.93 +    for ( i = 0; i < MAX_DOMAIN_NAME; i++ ) 
    2.94 +    {
    2.95          if ( name[i] == '\0' ) break;
    2.96          if ( name[i] & 0x80 )
    2.97          {
    2.98 @@ -167,7 +176,8 @@ int xc_linux_restore(int xc_handle, XcIO
    2.99      }
   2.100      name[MAX_DOMAIN_NAME-1] = '\0';
   2.101  
   2.102 -    if ( nr_pfns > 1024*1024 ) {
   2.103 +    if ( nr_pfns > 1024*1024 )
   2.104 +    {
   2.105          xcio_error(ioctxt, "Invalid state file -- pfn count out of range");
   2.106          goto out;
   2.107      }
   2.108 @@ -177,19 +187,23 @@ int xc_linux_restore(int xc_handle, XcIO
   2.109      pfn_type         = calloc(1, 4 * nr_pfns);    
   2.110      region_mfn       = calloc(1, 4 * MAX_BATCH_SIZE);    
   2.111  
   2.112 -    if ( (pfn_to_mfn_table == NULL) || (pfn_type == NULL) || 
   2.113 -         (region_mfn == NULL) ) {
   2.114 +    if ( (pfn_to_mfn_table == NULL) ||
   2.115 +         (pfn_type == NULL) || 
   2.116 +         (region_mfn == NULL) ) 
   2.117 +    {
   2.118          errno = ENOMEM;
   2.119          goto out;
   2.120      }
   2.121      
   2.122 -    if ( mlock(region_mfn, 4 * MAX_BATCH_SIZE ) ) {
   2.123 +    if ( mlock(region_mfn, 4 * MAX_BATCH_SIZE ) )
   2.124 +    {
   2.125          xcio_error(ioctxt, "Could not mlock region_mfn");
   2.126          goto out;
   2.127      }
   2.128  
   2.129      /* Set the domain's name to that from the restore file */
   2.130 -    if ( xc_domain_setname( xc_handle, dom, name ) ) {
   2.131 +    if ( xc_domain_setname( xc_handle, dom, name ) )
   2.132 +    {
   2.133          xcio_error(ioctxt, "Could not set domain name");
   2.134          goto out;
   2.135      }
   2.136 @@ -208,24 +222,26 @@ int xc_linux_restore(int xc_handle, XcIO
   2.137      op.cmd = DOM0_GETDOMAININFO;
   2.138      op.u.getdomaininfo.domain = (domid_t)dom;
   2.139      op.u.getdomaininfo.ctxt = NULL;
   2.140 -    if ( do_dom0_op(xc_handle, &op) < 0 ) {
   2.141 +    if ( do_dom0_op(xc_handle, &op) < 0 )
   2.142 +    {
   2.143          xcio_error(ioctxt, "Could not get information on new domain");
   2.144          goto out;
   2.145      }
   2.146      shared_info_frame = op.u.getdomaininfo.shared_info_frame;
   2.147  
   2.148 -    if ( (pm_handle = init_pfn_mapper((domid_t)dom)) < 0 )
   2.149 +    if ( (pm_handle = init_pfn_mapper((domid_t)dom)) == NULL )
   2.150          goto out;
   2.151  
   2.152 -
   2.153 -
   2.154      /* Build the pfn-to-mfn table. We choose MFN ordering returned by Xen. */
   2.155 -    if ( get_pfn_list(xc_handle, dom, pfn_to_mfn_table, nr_pfns) != nr_pfns ) {
   2.156 -        xcio_error(ioctxt, "Did not read correct number of frame numbers for new dom");
   2.157 +    if ( get_pfn_list(xc_handle, dom, pfn_to_mfn_table, nr_pfns) != nr_pfns )
   2.158 +    {
   2.159 +        xcio_error(ioctxt, "Did not read correct number of frame "
   2.160 +                   "numbers for new dom");
   2.161          goto out;
   2.162      }
   2.163  
   2.164 -    if ( (mmu = init_mmu_updates(xc_handle, dom)) == NULL ) {
   2.165 +    if ( (mmu = init_mmu_updates(xc_handle, dom)) == NULL )
   2.166 +    {
   2.167          xcio_error(ioctxt, "Could not initialise for MMU updates");
   2.168          goto out;
   2.169      }
   2.170 @@ -238,33 +254,39 @@ int xc_linux_restore(int xc_handle, XcIO
   2.171       */
   2.172      prev_pc = 0;
   2.173  
   2.174 -    n=0;
   2.175 -    while(1) {
   2.176 +    n = 0;
   2.177 +    while ( 1 )
   2.178 +    {
   2.179          int j;
   2.180          unsigned long region_pfn_type[MAX_BATCH_SIZE];
   2.181  
   2.182          this_pc = (n * 100) / nr_pfns;
   2.183 -        if ( (this_pc - prev_pc) >= 5 ) {
   2.184 +        if ( (this_pc - prev_pc) >= 5 )
   2.185 +        {
   2.186              xcio_info(ioctxt, "\b\b\b\b%3d%%", this_pc);
   2.187              prev_pc = this_pc;
   2.188          }
   2.189  
   2.190 -        if ( xcio_read(ioctxt, &j, sizeof(int)) ) {
   2.191 +        if ( xcio_read(ioctxt, &j, sizeof(int)) )
   2.192 +        {
   2.193              xcio_error(ioctxt, "Error when reading from state file");
   2.194              goto out;
   2.195          }
   2.196  
   2.197          DPRINTF("batch %d\n",j);
   2.198   
   2.199 -        if ( j == -1 ) {
   2.200 +        if ( j == -1 )
   2.201 +        {
   2.202              verify = 1;
   2.203              printf("Entering page verify mode\n");
   2.204              continue;
   2.205          }
   2.206  
   2.207 -        if ( j == 0 ) break;  /* our work here is done */
   2.208 +        if ( j == 0 )
   2.209 +            break;  /* our work here is done */
   2.210  
   2.211 -        if( j > MAX_BATCH_SIZE ) {
   2.212 +        if ( j > MAX_BATCH_SIZE )
   2.213 +        {
   2.214              xcio_error(ioctxt, "Max batch size exceeded. Giving up.");
   2.215              goto out;
   2.216          }
   2.217 @@ -274,10 +296,14 @@ int xc_linux_restore(int xc_handle, XcIO
   2.218              goto out;
   2.219          }
   2.220  
   2.221 -        for(i=0; i<j; i++) {
   2.222 -            if ( (region_pfn_type[i] & LTAB_MASK) == XTAB) {
   2.223 +        for ( i = 0; i < j; i++ )
   2.224 +        {
   2.225 +            if ( (region_pfn_type[i] & LTAB_MASK) == XTAB)
   2.226 +            {
   2.227                  region_mfn[i] = 0; /* we know map will fail, but don't care */
   2.228 -            } else {  
   2.229 +            }
   2.230 +            else
   2.231 +            {  
   2.232                  pfn = region_pfn_type[i] & ~LTAB_MASK;
   2.233                  region_mfn[i] = pfn_to_mfn_table[pfn];
   2.234              }          
   2.235 @@ -286,19 +312,22 @@ int xc_linux_restore(int xc_handle, XcIO
   2.236          if ( (region_base = mfn_mapper_map_batch( xc_handle, dom, 
   2.237                                                    PROT_WRITE,
   2.238                                                    region_mfn,
   2.239 -                                                  j )) == 0) {
   2.240 +                                                  j )) == 0 )
   2.241 +        {
   2.242              xcio_error(ioctxt, "map batch failed");
   2.243              goto out;
   2.244          }
   2.245  
   2.246 -        for(i=0;i<j;i++) {
   2.247 +        for ( i = 0; i < j; i++ )
   2.248 +        {
   2.249              unsigned long *ppage;
   2.250  
   2.251              pfn = region_pfn_type[i] & ~LTAB_MASK;
   2.252  
   2.253              if ( (region_pfn_type[i] & LTAB_MASK) == XTAB) continue;
   2.254  
   2.255 -            if (pfn>nr_pfns) {
   2.256 +            if (pfn>nr_pfns)
   2.257 +            {
   2.258                  xcio_error(ioctxt, "pfn out of range");
   2.259                  goto out;
   2.260              }
   2.261 @@ -309,32 +338,36 @@ int xc_linux_restore(int xc_handle, XcIO
   2.262  
   2.263              mfn = pfn_to_mfn_table[pfn];
   2.264  
   2.265 -            if ( verify ) {
   2.266 +            if ( verify )
   2.267                  ppage = (unsigned long*) buf;  /* debug case */
   2.268 -            } else {
   2.269 +            else
   2.270                  ppage = (unsigned long*) (region_base + i*PAGE_SIZE);
   2.271 -            }
   2.272  
   2.273 -            if ( xcio_read(ioctxt, ppage, PAGE_SIZE) ) {
   2.274 +            if ( xcio_read(ioctxt, ppage, PAGE_SIZE) )
   2.275 +            {
   2.276                  xcio_error(ioctxt, "Error when reading from state file");
   2.277                  goto out;
   2.278              }
   2.279  
   2.280 -            switch( region_pfn_type[i] ) {
   2.281 +            switch( region_pfn_type[i] )
   2.282 +            {
   2.283              case 0:
   2.284                  break;
   2.285  
   2.286              case L1TAB:
   2.287              {
   2.288 -                for ( k = 0; k < 1024; k++ ) {
   2.289 -                    if ( ppage[k] & _PAGE_PRESENT ) {
   2.290 +                for ( k = 0; k < 1024; k++ ) 
   2.291 +                {
   2.292 +                    if ( ppage[k] & _PAGE_PRESENT ) 
   2.293 +                    {
   2.294                          xpfn = ppage[k] >> PAGE_SHIFT;
   2.295 -
   2.296 -                        if ( xpfn >= nr_pfns ) {
   2.297 -                            xcio_error(ioctxt, "Frame number in type %lu page table is "
   2.298 -                                  "out of range. i=%d k=%d pfn=0x%lx "
   2.299 -                                  "nr_pfns=%lu", region_pfn_type[i]>>28, i, 
   2.300 -                                  k, xpfn, nr_pfns);
   2.301 +                        if ( xpfn >= nr_pfns )
   2.302 +                        {
   2.303 +                            xcio_error(ioctxt, "Frame number in type %lu page "
   2.304 +                                       "table is out of range. i=%d k=%d "
   2.305 +                                       "pfn=0x%lx nr_pfns=%lu", 
   2.306 +                                       region_pfn_type[i]>>28, i, 
   2.307 +                                       k, xpfn, nr_pfns);
   2.308                              goto out;
   2.309                          }
   2.310  
   2.311 @@ -350,15 +383,19 @@ int xc_linux_restore(int xc_handle, XcIO
   2.312              {
   2.313                  for ( k = 0; 
   2.314                        k < (HYPERVISOR_VIRT_START>>L2_PAGETABLE_SHIFT); 
   2.315 -                      k++ ) {
   2.316 -                    if ( ppage[k] & _PAGE_PRESENT ) {
   2.317 +                      k++ )
   2.318 +                {
   2.319 +                    if ( ppage[k] & _PAGE_PRESENT )
   2.320 +                    {
   2.321                          xpfn = ppage[k] >> PAGE_SHIFT;
   2.322  
   2.323 -                        if ( xpfn >= nr_pfns ) {
   2.324 -                            xcio_error(ioctxt, "Frame number in type %lu page table is "
   2.325 -                                  "out of range. i=%d k=%d pfn=%lu nr_pfns=%lu",
   2.326 -                                  region_pfn_type[i]>>28, i, k, xpfn, nr_pfns);
   2.327 -
   2.328 +                        if ( xpfn >= nr_pfns )
   2.329 +                        {
   2.330 +                            xcio_error(ioctxt, "Frame number in type %lu page"
   2.331 +                                       " table is out of range. i=%d k=%d "
   2.332 +                                       "pfn=%lu nr_pfns=%lu",
   2.333 +                                       region_pfn_type[i]>>28, i, k, 
   2.334 +                                       xpfn, nr_pfns);
   2.335                              goto out;
   2.336                          }
   2.337  
   2.338 @@ -371,21 +408,25 @@ int xc_linux_restore(int xc_handle, XcIO
   2.339              break;
   2.340  
   2.341              default:
   2.342 -                xcio_error(ioctxt, "Bogus page type %lx page table is out of range."
   2.343 -                      " i=%d nr_pfns=%lu", region_pfn_type[i], i, nr_pfns);
   2.344 +                xcio_error(ioctxt, "Bogus page type %lx page table is "
   2.345 +                           "out of range. i=%d nr_pfns=%lu", 
   2.346 +                           region_pfn_type[i], i, nr_pfns);
   2.347                  goto out;
   2.348  
   2.349              } /* end of page type switch statement */
   2.350  
   2.351 -            if ( verify ) {
   2.352 +            if ( verify )
   2.353 +            {
   2.354                  int res = memcmp(buf, (region_base + i*PAGE_SIZE), PAGE_SIZE );
   2.355 -                if (res) {
   2.356 +                if ( res )
   2.357 +                {
   2.358                      int v;
   2.359                      printf("************** pfn=%lx type=%lx gotcs=%08lx "
   2.360                             "actualcs=%08lx\n", pfn, pfn_type[pfn], 
   2.361                             csum_page(region_base + i*PAGE_SIZE), 
   2.362                             csum_page(buf));
   2.363 -                    for ( v = 0; v < 4; v++ ) {
   2.364 +                    for ( v = 0; v < 4; v++ )
   2.365 +                    {
   2.366                          unsigned long *p = (unsigned long *)
   2.367                              (region_base + i*PAGE_SIZE);
   2.368                          if ( buf[v] != p[v] )
   2.369 @@ -396,7 +437,8 @@ int xc_linux_restore(int xc_handle, XcIO
   2.370              }
   2.371  
   2.372              if ( add_mmu_update(xc_handle, mmu,
   2.373 -                                (mfn<<PAGE_SHIFT) | MMU_MACHPHYS_UPDATE, pfn) ) {
   2.374 +                                (mfn<<PAGE_SHIFT) | MMU_MACHPHYS_UPDATE, pfn) )
   2.375 +            {
   2.376                  printf("machpys mfn=%ld pfn=%ld\n",mfn,pfn);
   2.377                  goto out;
   2.378              }
   2.379 @@ -407,16 +449,16 @@ int xc_linux_restore(int xc_handle, XcIO
   2.380          n+=j; /* crude stats */
   2.381      }
   2.382  
   2.383 -    printf("Received all pages\n");
   2.384 -
   2.385      DPRINTF("Received all pages\n");
   2.386  
   2.387      /*
   2.388       * Pin page tables. Do this after writing to them as otherwise Xen
   2.389       * will barf when doing the type-checking.
   2.390       */
   2.391 -    for ( i = 0; i < nr_pfns; i++ ) {
   2.392 -        if ( pfn_type[i] == L1TAB ) {
   2.393 +    for ( i = 0; i < nr_pfns; i++ )
   2.394 +    {
   2.395 +        if ( pfn_type[i] == L1TAB )
   2.396 +        {
   2.397              if ( add_mmu_update(xc_handle, mmu,
   2.398                                  (pfn_to_mfn_table[i]<<PAGE_SHIFT) | 
   2.399                                  MMU_EXTENDED_COMMAND,
   2.400 @@ -425,11 +467,14 @@ int xc_linux_restore(int xc_handle, XcIO
   2.401                         (unsigned long)i, pfn_to_mfn_table[i]);
   2.402                  goto out;
   2.403              }
   2.404 -        } else if ( pfn_type[i] == L2TAB ) {
   2.405 +        }
   2.406 +        else if ( pfn_type[i] == L2TAB )
   2.407 +        {
   2.408              if ( add_mmu_update(xc_handle, mmu,
   2.409                                  (pfn_to_mfn_table[i]<<PAGE_SHIFT) | 
   2.410                                  MMU_EXTENDED_COMMAND,
   2.411 -                                MMUEXT_PIN_L2_TABLE) ) {
   2.412 +                                MMUEXT_PIN_L2_TABLE) )
   2.413 +            {
   2.414                  printf("ERR pin L2 pfn=%lx mfn=%lx\n",
   2.415                         (unsigned long)i, pfn_to_mfn_table[i]);
   2.416                  goto out;
   2.417 @@ -442,8 +487,9 @@ int xc_linux_restore(int xc_handle, XcIO
   2.418      xcio_info(ioctxt, "\b\b\b\b100%%\nMemory reloaded.\n");
   2.419  
   2.420  
   2.421 -    if ( xcio_read(ioctxt, &ctxt,                 sizeof(ctxt)) ||
   2.422 -         xcio_read(ioctxt, shared_info,           PAGE_SIZE) ) {
   2.423 +    if ( xcio_read(ioctxt, &ctxt,       sizeof(ctxt)) ||
   2.424 +         xcio_read(ioctxt, shared_info, PAGE_SIZE) )
   2.425 +    {
   2.426          xcio_error(ioctxt, "Error when reading from state file");
   2.427          goto out;
   2.428      }
   2.429 @@ -463,13 +509,16 @@ int xc_linux_restore(int xc_handle, XcIO
   2.430      unmap_pfn(pm_handle, p_srec);
   2.431  
   2.432      /* Uncanonicalise each GDT frame number. */
   2.433 -    if ( ctxt.gdt_ents > 8192 ) {
   2.434 +    if ( ctxt.gdt_ents > 8192 )
   2.435 +    {
   2.436          xcio_error(ioctxt, "GDT entry count out of range");
   2.437          goto out;
   2.438      }
   2.439 -    for ( i = 0; i < ctxt.gdt_ents; i += 512 ) {
   2.440 +    for ( i = 0; i < ctxt.gdt_ents; i += 512 )
   2.441 +    {
   2.442          pfn = ctxt.gdt_frames[i];
   2.443 -        if ( (pfn >= nr_pfns) || (pfn_type[pfn] != NOTAB) ) {
   2.444 +        if ( (pfn >= nr_pfns) || (pfn_type[pfn] != NOTAB) )
   2.445 +        {
   2.446              xcio_error(ioctxt, "GDT frame number is bad");
   2.447              goto out;
   2.448          }
   2.449 @@ -478,7 +527,8 @@ int xc_linux_restore(int xc_handle, XcIO
   2.450  
   2.451      /* Uncanonicalise the page table base pointer. */
   2.452      pfn = ctxt.pt_base >> PAGE_SHIFT;
   2.453 -    if ( (pfn >= nr_pfns) || (pfn_type[pfn] != L2TAB) ) {
   2.454 +    if ( (pfn >= nr_pfns) || (pfn_type[pfn] != L2TAB) )
   2.455 +    {
   2.456          printf("PT base is bad. pfn=%lu nr=%lu type=%08lx %08lx\n",
   2.457                 pfn, nr_pfns, pfn_type[pfn], (unsigned long)L2TAB);
   2.458          xcio_error(ioctxt, "PT base is bad.");
   2.459 @@ -499,11 +549,13 @@ int xc_linux_restore(int xc_handle, XcIO
   2.460  
   2.461  
   2.462      /* Uncanonicalise the pfn-to-mfn table frame-number list. */
   2.463 -    for ( i = 0; i < (nr_pfns+1023)/1024; i++ ) {
   2.464 +    for ( i = 0; i < (nr_pfns+1023)/1024; i++ )
   2.465 +    {
   2.466          unsigned long pfn, mfn;
   2.467  
   2.468          pfn = pfn_to_mfn_frame_list[i];
   2.469 -        if ( (pfn >= nr_pfns) || (pfn_type[pfn] != NOTAB) ) {
   2.470 +        if ( (pfn >= nr_pfns) || (pfn_type[pfn] != NOTAB) )
   2.471 +        {
   2.472              xcio_error(ioctxt, "PFN-to-MFN frame number is bad");
   2.473              goto out;
   2.474          }
   2.475 @@ -515,15 +567,16 @@ int xc_linux_restore(int xc_handle, XcIO
   2.476            mfn_mapper_map_batch(xc_handle, dom, 
   2.477                                 PROT_WRITE,
   2.478                                 pfn_to_mfn_frame_list,
   2.479 -                               (nr_pfns+1023)/1024 )) == 0 ) {
   2.480 +                               (nr_pfns+1023)/1024 )) == 0 )
   2.481 +    {
   2.482          xcio_error(ioctxt, "Couldn't map pfn_to_mfn table");
   2.483          goto out;
   2.484      }
   2.485  
   2.486 -    memcpy( live_pfn_to_mfn_table, pfn_to_mfn_table, 
   2.487 -            nr_pfns*sizeof(unsigned long) );
   2.488 +    memcpy(live_pfn_to_mfn_table, pfn_to_mfn_table, 
   2.489 +           nr_pfns*sizeof(unsigned long) );
   2.490  
   2.491 -    munmap( live_pfn_to_mfn_table, ((nr_pfns+1023)/1024)*PAGE_SIZE );
   2.492 +    munmap(live_pfn_to_mfn_table, ((nr_pfns+1023)/1024)*PAGE_SIZE);
   2.493  
   2.494      /*
   2.495       * Safety checking of saved context:
   2.496 @@ -538,20 +591,18 @@ int xc_linux_restore(int xc_handle, XcIO
   2.497       *  9. debugregs are checked by Xen.
   2.498       *  10. callback code selectors need checking.
   2.499       */
   2.500 -    for ( i = 0; i < 256; i++ ) {
   2.501 +    for ( i = 0; i < 256; i++ )
   2.502 +    {
   2.503          ctxt.trap_ctxt[i].vector = i;
   2.504          if ( (ctxt.trap_ctxt[i].cs & 3) == 0 )
   2.505              ctxt.trap_ctxt[i].cs = FLAT_GUESTOS_CS;
   2.506      }
   2.507 -    if ( (ctxt.guestos_ss & 3) == 0 ){
   2.508 +    if ( (ctxt.guestos_ss & 3) == 0 )
   2.509          ctxt.guestos_ss = FLAT_GUESTOS_DS;
   2.510 -    }
   2.511 -    if ( (ctxt.event_callback_cs & 3) == 0 ){
   2.512 +    if ( (ctxt.event_callback_cs & 3) == 0 )
   2.513          ctxt.event_callback_cs = FLAT_GUESTOS_CS;
   2.514 -    }
   2.515 -    if ( (ctxt.failsafe_callback_cs & 3) == 0 ){
   2.516 +    if ( (ctxt.failsafe_callback_cs & 3) == 0 )
   2.517          ctxt.failsafe_callback_cs = FLAT_GUESTOS_CS;
   2.518 -    }
   2.519      if ( ((ctxt.ldt_base & (PAGE_SIZE - 1)) != 0) ||
   2.520           (ctxt.ldt_ents > 8192) ||
   2.521           (ctxt.ldt_base > HYPERVISOR_VIRT_START) ||
   2.522 @@ -568,7 +619,8 @@ int xc_linux_restore(int xc_handle, XcIO
   2.523  
   2.524      /* don't start the domain as we have console etc to set up */
   2.525    
   2.526 -    if( rc == 0 ) {
   2.527 +    if ( rc == 0 )
   2.528 +    {
   2.529          /* Success: print the domain id. */
   2.530          xcio_info(ioctxt, "DOM=%lu\n", dom);
   2.531          return 0;
   2.532 @@ -576,25 +628,20 @@ int xc_linux_restore(int xc_handle, XcIO
   2.533  
   2.534  
   2.535   out:
   2.536 -    if ( (rc != 0) && (dom != 0) ){
   2.537 +    if ( (rc != 0) && (dom != 0) )
   2.538          xc_domain_destroy(xc_handle, dom);
   2.539 -    }
   2.540 -    if ( mmu != NULL ){
   2.541 +    if ( mmu != NULL )
   2.542          free(mmu);
   2.543 -    }
   2.544 -    if ( pm_handle >= 0 ){
   2.545 +    if ( pm_handle != NULL )
   2.546          (void)close_pfn_mapper(pm_handle);
   2.547 -    }
   2.548 -    if ( pfn_to_mfn_table != NULL ){
   2.549 +    if ( pfn_to_mfn_table != NULL )
   2.550          free(pfn_to_mfn_table);
   2.551 -    }
   2.552 -    if ( pfn_type != NULL ){
   2.553 +    if ( pfn_type != NULL )
   2.554          free(pfn_type);
   2.555 -    }
   2.556  
   2.557 -    if ( rc == 0 ){
   2.558 +    if ( rc == 0 )
   2.559          ioctxt->domain = dom;
   2.560 -    }
   2.561 +
   2.562      DPRINTF("Restore exit with rc=%d\n",rc);
   2.563      return rc;
   2.564  }
     3.1 --- a/tools/libxc/xc_netbsd_build.c	Thu Jul 01 07:41:45 2004 +0000
     3.2 +++ b/tools/libxc/xc_netbsd_build.c	Thu Jul 01 07:41:58 2004 +0000
     3.3 @@ -13,7 +13,7 @@
     3.4  #define DPRINTF(x)
     3.5  #endif
     3.6  
     3.7 -static int loadelfimage(gzFile, int, unsigned long *, unsigned long,
     3.8 +static int loadelfimage(gzFile, void *, unsigned long *, unsigned long,
     3.9                          unsigned long *, unsigned long *,
    3.10                          unsigned long *, unsigned long *);
    3.11  
    3.12 @@ -77,9 +77,10 @@ static int setup_guestos(int xc_handle,
    3.13      shared_info_t *shared_info;
    3.14      unsigned long ksize;
    3.15      mmu_t *mmu = NULL;
    3.16 -    int pm_handle, i;
    3.17 +    void  *pm_handle = NULL;
    3.18 +    int i;
    3.19  
    3.20 -    if ( (pm_handle = init_pfn_mapper((domid_t)dom)) < 0 )
    3.21 +    if ( (pm_handle = init_pfn_mapper((domid_t)dom)) == NULL )
    3.22          goto error_out;
    3.23  
    3.24      if ( (page_array = malloc(tot_pages * sizeof(unsigned long))) == NULL )
    3.25 @@ -201,7 +202,7 @@ static int setup_guestos(int xc_handle,
    3.26   error_out:
    3.27      if ( mmu != NULL )
    3.28          free(mmu);
    3.29 -    if ( pm_handle >= 0 )
    3.30 +    if ( pm_handle != NULL )
    3.31          (void)close_pfn_mapper(pm_handle);
    3.32      if ( page_array == NULL )
    3.33          free(page_array);
    3.34 @@ -412,7 +413,7 @@ myseek(gzFile gfd, off_t offset, int whe
    3.35  #define IS_BSS(p) (p.p_filesz < p.p_memsz)
    3.36  
    3.37  static int
    3.38 -loadelfimage(gzFile kernel_gfd, int pm_handle, unsigned long *page_array,
    3.39 +loadelfimage(gzFile kernel_gfd, void *pm_handle, unsigned long *page_array,
    3.40               unsigned long tot_pages, unsigned long *virt_load_addr,
    3.41               unsigned long *ksize, unsigned long *symtab_addr,
    3.42               unsigned long *symtab_len)
     4.1 --- a/tools/libxc/xc_private.c	Thu Jul 01 07:41:45 2004 +0000
     4.2 +++ b/tools/libxc/xc_private.c	Thu Jul 01 07:41:58 2004 +0000
     4.3 @@ -6,51 +6,140 @@
     4.4  
     4.5  #include "xc_private.h"
     4.6  
     4.7 -int init_pfn_mapper(domid_t domid)
     4.8 +#define MAX_EXTENTS 8
     4.9 +typedef struct {
    4.10 +    int fd;
    4.11 +    struct {
    4.12 +        void         *base; 
    4.13 +        unsigned long length;
    4.14 +    } extent[MAX_EXTENTS];
    4.15 +} mapper_desc_t;
    4.16 +
    4.17 +void *init_pfn_mapper(domid_t domid)
    4.18  {
    4.19 -    int fd = open("/dev/mem", O_RDWR);
    4.20 -    if ( fd >= 0 )
    4.21 -        (void)ioctl(fd, _IO('M', 1), (unsigned long)domid);
    4.22 -    return fd;
    4.23 +    int            fd = open("/dev/mem", O_RDWR);
    4.24 +    mapper_desc_t *desc;
    4.25 +
    4.26 +    if ( fd < 0 )
    4.27 +        return NULL;
    4.28 +
    4.29 +    if ( (desc = malloc(sizeof(*desc))) == NULL )
    4.30 +    {
    4.31 +        close(fd);
    4.32 +        return NULL;
    4.33 +    }
    4.34 +
    4.35 +    (void)ioctl(fd, _IO('M', 1), (unsigned long)domid);
    4.36 +
    4.37 +    memset(desc, 0, sizeof(*desc));
    4.38 +    desc->fd = fd;
    4.39 +
    4.40 +    return desc;
    4.41  }
    4.42  
    4.43 -int close_pfn_mapper(int pm_handle)
    4.44 +int close_pfn_mapper(void *pm_handle)
    4.45  {
    4.46 -    return close(pm_handle);
    4.47 +    mapper_desc_t *desc = pm_handle;
    4.48 +    int            i;
    4.49 +
    4.50 +    for ( i = 0; i < MAX_EXTENTS; i++ )
    4.51 +    {
    4.52 +        if ( desc->extent[i].base != NULL )
    4.53 +            (void)munmap(desc->extent[i].base, desc->extent[i].length);
    4.54 +    }
    4.55 +
    4.56 +    close(desc->fd);
    4.57 +    free(desc);
    4.58 +
    4.59 +    return 0;
    4.60  }
    4.61  
    4.62 -void *map_pfn_writeable(int pm_handle, unsigned long pfn)
    4.63 +static int get_free_offset(mapper_desc_t *desc)
    4.64  {
    4.65 -    void *vaddr = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE,
    4.66 -                       MAP_SHARED, pm_handle, pfn << PAGE_SHIFT);
    4.67 +    int i;
    4.68 +
    4.69 +    for ( i = 0; i < MAX_EXTENTS; i++ )
    4.70 +    {
    4.71 +        if ( desc->extent[i].base == NULL )
    4.72 +            break;
    4.73 +    }
    4.74 +
    4.75 +    if ( i == MAX_EXTENTS )
    4.76 +    {
    4.77 +        fprintf(stderr, "Extent overflow in map_pfn_*()!\n");
    4.78 +        fflush(stderr);
    4.79 +        *(int*)0=0; /* XXX */
    4.80 +    }
    4.81 +
    4.82 +    return i;
    4.83 +}
    4.84 +
    4.85 +void *map_pfn_writeable(void *pm_handle, unsigned long pfn)
    4.86 +{
    4.87 +    mapper_desc_t *desc = pm_handle;
    4.88 +    void          *vaddr;
    4.89 +    int            off;
    4.90 +
    4.91 +    vaddr = mmap(NULL, PAGE_SIZE, PROT_READ|PROT_WRITE,
    4.92 +                 MAP_SHARED, desc->fd, pfn << PAGE_SHIFT);
    4.93      if ( vaddr == MAP_FAILED )
    4.94          return NULL;
    4.95 +
    4.96 +    off = get_free_offset(desc);
    4.97 +    desc->extent[off].base   = vaddr;
    4.98 +    desc->extent[off].length = PAGE_SIZE;
    4.99 +
   4.100      return vaddr;
   4.101  }
   4.102  
   4.103 -void *map_pfn_readonly(int pm_handle, unsigned long pfn)
   4.104 +void *map_pfn_readonly(void *pm_handle, unsigned long pfn)
   4.105  {
   4.106 -    void *vaddr = mmap(NULL, PAGE_SIZE, PROT_READ,
   4.107 -                       MAP_SHARED, pm_handle, pfn << PAGE_SHIFT);
   4.108 +    mapper_desc_t *desc = pm_handle;
   4.109 +    void          *vaddr;
   4.110 +    int            off;
   4.111 +
   4.112 +    vaddr = mmap(NULL, PAGE_SIZE, PROT_READ,
   4.113 +                 MAP_SHARED, desc->fd, pfn << PAGE_SHIFT);
   4.114      if ( vaddr == MAP_FAILED )
   4.115          return NULL;
   4.116 +
   4.117 +    off = get_free_offset(desc);
   4.118 +    desc->extent[off].base   = vaddr;
   4.119 +    desc->extent[off].length = PAGE_SIZE;
   4.120 +
   4.121      return vaddr;
   4.122  }
   4.123  
   4.124 -void unmap_pfn(int pm_handle, void *vaddr)
   4.125 +void unmap_pfn(void *pm_handle, void *vaddr)
   4.126  {
   4.127 -    (void)munmap(vaddr, PAGE_SIZE);
   4.128 +    mapper_desc_t *desc = pm_handle;
   4.129 +    int            i;
   4.130 +    unsigned long  len = 0;
   4.131 +
   4.132 +    for ( i = 0; i < MAX_EXTENTS; i++ )
   4.133 +    {
   4.134 +        if ( desc->extent[i].base == vaddr )
   4.135 +        {
   4.136 +            desc->extent[i].base = NULL;
   4.137 +            len = desc->extent[i].length;
   4.138 +        }
   4.139 +    }
   4.140 +
   4.141 +    if ( len == 0 )
   4.142 +        *(int*)0 = 0; /* XXX */
   4.143 +
   4.144 +    (void)munmap(vaddr, len);
   4.145  }
   4.146  
   4.147  /*******************/
   4.148  
   4.149 -void * mfn_mapper_map_batch(int xc_handle, domid_t dom, int prot,
   4.150 -                            unsigned long *arr, int num )
   4.151 +void *mfn_mapper_map_batch(int xc_handle, domid_t dom, int prot,
   4.152 +                           unsigned long *arr, int num )
   4.153  {
   4.154      privcmd_mmapbatch_t ioctlx; 
   4.155      void *addr;
   4.156 -    addr = mmap( NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0 );
   4.157 -    if (addr)
   4.158 +    addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
   4.159 +    if ( addr != NULL )
   4.160      {
   4.161          ioctlx.num=num;
   4.162          ioctlx.dom=dom;
   4.163 @@ -69,15 +158,15 @@ void * mfn_mapper_map_batch(int xc_handl
   4.164  
   4.165  /*******************/
   4.166  
   4.167 -void * mfn_mapper_map_single(int xc_handle, domid_t dom,
   4.168 -                             int size, int prot,
   4.169 -                             unsigned long mfn )
   4.170 +void *mfn_mapper_map_single(int xc_handle, domid_t dom,
   4.171 +                            int size, int prot,
   4.172 +                            unsigned long mfn )
   4.173  {
   4.174      privcmd_mmap_t ioctlx; 
   4.175      privcmd_mmap_entry_t entry; 
   4.176      void *addr;
   4.177 -    addr = mmap( NULL, size, prot, MAP_SHARED, xc_handle, 0 );
   4.178 -    if (addr)
   4.179 +    addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
   4.180 +    if ( addr != NULL )
   4.181      {
   4.182          ioctlx.num=1;
   4.183          ioctlx.dom=dom;
   4.184 @@ -85,7 +174,7 @@ void * mfn_mapper_map_single(int xc_hand
   4.185          entry.va=(unsigned long) addr;
   4.186          entry.mfn=mfn;
   4.187          entry.npages=(size+PAGE_SIZE-1)>>PAGE_SHIFT;
   4.188 -        if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx ) <0 )
   4.189 +        if ( ioctl( xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx ) < 0 )
   4.190          {
   4.191              munmap(addr, size);
   4.192              return 0;
     5.1 --- a/tools/libxc/xc_private.h	Thu Jul 01 07:41:45 2004 +0000
     5.2 +++ b/tools/libxc/xc_private.h	Thu Jul 01 07:41:58 2004 +0000
     5.3 @@ -131,11 +131,11 @@ static inline int do_multicall_op(int xc
     5.4  /*
     5.5   * PFN mapping.
     5.6   */
     5.7 -int init_pfn_mapper(domid_t domid);
     5.8 -int close_pfn_mapper(int pm_handle);
     5.9 -void *map_pfn_writeable(int pm_handle, unsigned long pfn);
    5.10 -void *map_pfn_readonly(int pm_handle, unsigned long pfn);
    5.11 -void unmap_pfn(int pm_handle, void *vaddr);
    5.12 +void *init_pfn_mapper(domid_t domid);
    5.13 +int close_pfn_mapper(void *pm_handle);
    5.14 +void *map_pfn_writeable(void *pm_handle, unsigned long pfn);
    5.15 +void *map_pfn_readonly(void *pm_handle, unsigned long pfn);
    5.16 +void unmap_pfn(void *pm_handle, void *vaddr);
    5.17  int get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr);
    5.18  unsigned long csum_page (void * page);
    5.19  
     6.1 --- a/tools/python/xen/lowlevel/xu/xu.c	Thu Jul 01 07:41:45 2004 +0000
     6.2 +++ b/tools/python/xen/lowlevel/xu/xu.c	Thu Jul 01 07:41:58 2004 +0000
     6.3 @@ -38,9 +38,6 @@
     6.4  #define EVTCHN_DEV_NAME  "/dev/xen/evtchn"
     6.5  #define EVTCHN_DEV_MAJOR 10
     6.6  #define EVTCHN_DEV_MINOR 200
     6.7 -#define PORT_NORMAL     0x0000   /* A standard event notification.      */ 
     6.8 -#define PORT_EXCEPTION  0x8000   /* An exceptional notification.        */
     6.9 -#define PORTIDX_MASK    0x7fff   /* Strip subtype to obtain port index. */
    6.10  /* /dev/xen/evtchn ioctls: */
    6.11  /* EVTCHN_RESET: Clear and reinit the event buffer. Clear error condition. */
    6.12  #define EVTCHN_RESET  _IO('E', 1)
    6.13 @@ -81,7 +78,7 @@ static PyObject *xu_notifier_read(PyObje
    6.14      }
    6.15      
    6.16      if ( bytes == sizeof(v) )
    6.17 -        return Py_BuildValue("(i,i)", v&PORTIDX_MASK, v&~PORTIDX_MASK);
    6.18 +        return PyInt_FromLong(v);
    6.19  
    6.20   none:
    6.21      Py_INCREF(Py_None);
    6.22 @@ -145,7 +142,7 @@ static PyMethodDef xu_notifier_methods[]
    6.23      { "read",
    6.24        (PyCFunction)xu_notifier_read,
    6.25        METH_VARARGS,
    6.26 -      "Read a (@port, @type) pair.\n" },
    6.27 +      "Read a @port with pending notifications.\n" },
    6.28  
    6.29      { "unmask", 
    6.30        (PyCFunction)xu_notifier_unmask,
    6.31 @@ -199,10 +196,6 @@ static PyObject *xu_notifier_new(PyObjec
    6.32  
    6.33  static PyObject *xu_notifier_getattr(PyObject *obj, char *name)
    6.34  {
    6.35 -    if ( strcmp(name, "EXCEPTION") == 0 )
    6.36 -        return PyInt_FromLong(PORT_EXCEPTION);
    6.37 -    if ( strcmp(name, "NORMAL") == 0 )
    6.38 -        return PyInt_FromLong(PORT_NORMAL);
    6.39      return Py_FindMethod(xu_notifier_methods, obj, name);
    6.40  }
    6.41  
    6.42 @@ -686,43 +679,6 @@ typedef struct xu_port_object {
    6.43  
    6.44  static PyObject *port_error;
    6.45  
    6.46 -static int xup_connect(xu_port_object *xup, domid_t dom,
    6.47 -                       int local_port, int remote_port){
    6.48 -    // From our prespective rx = producer, tx = consumer.
    6.49 -    int err = 0;
    6.50 -    printf("%s> dom=%u %d:%d\n", __FUNCTION__, (unsigned int)dom, 
    6.51 -           local_port, remote_port);
    6.52 -
    6.53 -    // Consumer = tx.
    6.54 -    //xup->interface->tx_resp_prod = 0;
    6.55 -    //xup->interface->tx_req_prod = 0;
    6.56 -    xup->tx_resp_prod = xup->interface->tx_resp_prod;
    6.57 -    xup->tx_req_cons = xup->interface->tx_resp_prod;
    6.58 -    printf("%s> tx: %u %u : %u %u\n", __FUNCTION__,
    6.59 -           (unsigned int)xup->interface->tx_resp_prod,
    6.60 -           (unsigned int)xup->tx_resp_prod,
    6.61 -           (unsigned int)xup->tx_req_cons,
    6.62 -           (unsigned int)xup->interface->tx_req_prod);
    6.63 -
    6.64 -    // Producer = rx.
    6.65 -    //xup->interface->rx_req_prod  = 0;
    6.66 -    //xup->interface->rx_resp_prod = 0;
    6.67 -    xup->rx_req_prod  = xup->interface->rx_req_prod;
    6.68 -    xup->rx_resp_cons = xup->interface->rx_resp_prod;
    6.69 -    printf("%s> rx: %u %u : %u %u\n", __FUNCTION__,
    6.70 -           (unsigned int)xup->rx_resp_cons,
    6.71 -           (unsigned int)xup->interface->rx_resp_prod,
    6.72 -           (unsigned int)xup->interface->rx_req_prod,
    6.73 -           (unsigned int)xup->rx_req_prod);
    6.74 -
    6.75 -    xup->remote_dom   = dom;
    6.76 -    xup->local_port   = local_port;
    6.77 -    xup->remote_port  = remote_port;
    6.78 -
    6.79 -    printf("%s< err=%d\n", __FUNCTION__, err);
    6.80 -    return err;
    6.81 -}
    6.82 -
    6.83  static PyObject *xu_port_notify(PyObject *self, PyObject *args)
    6.84  {
    6.85      xu_port_object *xup = (xu_port_object *)self;
    6.86 @@ -913,6 +869,86 @@ static PyObject *xu_port_space_to_write_
    6.87      return PyInt_FromLong(1);
    6.88  }
    6.89  
    6.90 +static int __xu_port_connect(xu_port_object *xup)
    6.91 +{
    6.92 +    xc_dominfo_t info;
    6.93 +
    6.94 +    if ( xup->mem_fd != -1 )
    6.95 +        return 0;
    6.96 +
    6.97 +    if ( (xup->mem_fd = open("/dev/mem", O_RDWR)) == -1 )
    6.98 +    {
    6.99 +        PyErr_SetString(port_error, "Could not open '/dev/mem'");
   6.100 +        return -1;
   6.101 +    }
   6.102 +
   6.103 +    /* Set the General-Purpose Subject whose page frame will be mapped. */
   6.104 +    (void)ioctl(xup->mem_fd, _IO('M', 1), (unsigned long)xup->remote_dom);
   6.105 +
   6.106 +    if ( (xc_domain_getinfo(xup->xc_handle, xup->remote_dom, 1, &info) != 1) ||
   6.107 +         (info.domid != xup->remote_dom) )
   6.108 +    {
   6.109 +        PyErr_SetString(port_error, "Failed to obtain domain status");
   6.110 +        (void)close(xup->mem_fd);
   6.111 +        xup->mem_fd = -1;
   6.112 +        return -1;
   6.113 +    }
   6.114 +
   6.115 +    xup->interface = 
   6.116 +        map_control_interface(xup->mem_fd, info.shared_info_frame);
   6.117 +    if ( xup->interface == NULL )
   6.118 +    {
   6.119 +        PyErr_SetString(port_error, "Failed to map domain control interface");
   6.120 +        (void)close(xup->mem_fd);
   6.121 +        xup->mem_fd = -1;
   6.122 +        return -1;
   6.123 +    }
   6.124 +
   6.125 +    /* Synchronise ring indexes. */
   6.126 +    xup->tx_resp_prod = xup->interface->tx_resp_prod;
   6.127 +    xup->tx_req_cons  = xup->interface->tx_resp_prod;
   6.128 +    xup->rx_req_prod  = xup->interface->rx_req_prod;
   6.129 +    xup->rx_resp_cons = xup->interface->rx_resp_prod;
   6.130 +
   6.131 +    return 0;
   6.132 +}
   6.133 +
   6.134 +static void __xu_port_disconnect(xu_port_object *xup)
   6.135 +{
   6.136 +    if ( xup->mem_fd == -1 )
   6.137 +        return;
   6.138 +    unmap_control_interface(xup->mem_fd, xup->interface);
   6.139 +    (void)close(xup->mem_fd);
   6.140 +    xup->mem_fd = -1;
   6.141 +}
   6.142 +
   6.143 +static PyObject *xu_port_connect(PyObject *self, PyObject *args)
   6.144 +{
   6.145 +    xu_port_object *xup = (xu_port_object *)self;
   6.146 +
   6.147 +    if ( !PyArg_ParseTuple(args, "") )
   6.148 +        return NULL;
   6.149 +
   6.150 +    if ( __xu_port_connect(xup) != 0 )
   6.151 +        return NULL;
   6.152 +
   6.153 +    Py_INCREF(Py_None);
   6.154 +    return Py_None;
   6.155 +}
   6.156 +
   6.157 +static PyObject *xu_port_disconnect(PyObject *self, PyObject *args)
   6.158 +{
   6.159 +    xu_port_object *xup = (xu_port_object *)self;
   6.160 +
   6.161 +    if ( !PyArg_ParseTuple(args, "") )
   6.162 +        return NULL;
   6.163 +
   6.164 +    __xu_port_disconnect(xup);
   6.165 +
   6.166 +    Py_INCREF(Py_None);
   6.167 +    return Py_None;
   6.168 +}
   6.169 +
   6.170  static PyMethodDef xu_port_methods[] = {
   6.171      { "notify",
   6.172        (PyCFunction)xu_port_notify,
   6.173 @@ -959,6 +995,16 @@ static PyMethodDef xu_port_methods[] = {
   6.174        METH_VARARGS,
   6.175        "Returns TRUE if there is space to write a response message.\n" },
   6.176  
   6.177 +    { "connect",
   6.178 +      (PyCFunction)xu_port_connect,
   6.179 +      METH_VARARGS,
   6.180 +      "Synchronously connect to remote domain.\n" },
   6.181 +
   6.182 +    { "disconnect",
   6.183 +      (PyCFunction)xu_port_disconnect,
   6.184 +      METH_VARARGS,
   6.185 +      "Synchronously disconnect from remote domain.\n" },
   6.186 +
   6.187      { NULL, NULL, 0, NULL }
   6.188  };
   6.189  
   6.190 @@ -969,26 +1015,19 @@ static PyObject *xu_port_new(PyObject *s
   6.191      xu_port_object *xup;
   6.192      u32 dom;
   6.193      int port1, port2;
   6.194 -    xc_dominfo_t info;
   6.195  
   6.196      if ( !PyArg_ParseTuple(args, "i", &dom) )
   6.197          return NULL;
   6.198  
   6.199      xup = PyObject_New(xu_port_object, &xu_port_type);
   6.200  
   6.201 -    if ( (xup->mem_fd = open("/dev/mem", O_RDWR)) == -1 )
   6.202 -    {
   6.203 -        PyErr_SetString(port_error, "Could not open '/dev/mem'");
   6.204 -        goto fail1;
   6.205 -    }
   6.206 -
   6.207 -    /* Set the General-Purpose Subject whose page frame will be mapped. */
   6.208 -    (void)ioctl(xup->mem_fd, _IO('M', 1), (unsigned long)dom);
   6.209 +    xup->remote_dom = dom;
   6.210 +    xup->mem_fd     = -1; /* currently disconnected */
   6.211  
   6.212      if ( (xup->xc_handle = xc_interface_open()) == -1 )
   6.213      {
   6.214          PyErr_SetString(port_error, "Could not open Xen control interface");
   6.215 -        goto fail2;
   6.216 +        goto fail1;
   6.217      }
   6.218  
   6.219      if ( dom == 0 )
   6.220 @@ -1002,7 +1041,7 @@ static PyObject *xu_port_new(PyObject *s
   6.221          if ( port1 < 0 )
   6.222          {
   6.223              PyErr_SetString(port_error, "Could not open channel to DOM0");
   6.224 -            goto fail3;
   6.225 +            goto fail2;
   6.226          }
   6.227      }
   6.228      else if ( xc_evtchn_bind_interdomain(xup->xc_handle, 
   6.229 @@ -1010,34 +1049,22 @@ static PyObject *xu_port_new(PyObject *s
   6.230                                           &port1, &port2) != 0 )
   6.231      {
   6.232          PyErr_SetString(port_error, "Could not open channel to domain");
   6.233 -        goto fail3;
   6.234 -    }
   6.235 -
   6.236 -    if ( (xc_domain_getinfo(xup->xc_handle, dom, 1, &info) != 1) ||
   6.237 -         (info.domid != dom) )
   6.238 -    {
   6.239 -        PyErr_SetString(port_error, "Failed to obtain domain status");
   6.240 -        goto fail4;
   6.241 +        goto fail2;
   6.242      }
   6.243  
   6.244 -    xup->interface = 
   6.245 -        map_control_interface(xup->mem_fd, info.shared_info_frame);
   6.246 -    if ( xup->interface == NULL )
   6.247 -    {
   6.248 -        PyErr_SetString(port_error, "Failed to map domain control interface");
   6.249 -        goto fail4;
   6.250 -    }
   6.251 +    xup->local_port  = port1;
   6.252 +    xup->remote_port = port2;
   6.253 +
   6.254 +    if ( __xu_port_connect(xup) != 0 )
   6.255 +        goto fail3;
   6.256  
   6.257 -    xup_connect(xup, dom, port1, port2);
   6.258      return (PyObject *)xup;
   6.259 -
   6.260      
   6.261 - fail4:
   6.262 -    (void)xc_evtchn_close(xup->xc_handle, DOMID_SELF, port1);
   6.263   fail3:
   6.264 -    (void)xc_interface_close(xup->xc_handle);
   6.265 +    if ( dom != 0 )
   6.266 +        (void)xc_evtchn_close(xup->xc_handle, DOMID_SELF, port1);
   6.267   fail2:
   6.268 -    (void)close(xup->mem_fd);
   6.269 +    (void)xc_interface_close(xup->xc_handle);
   6.270   fail1:
   6.271      PyObject_Del((PyObject *)xup);
   6.272      return NULL;        
   6.273 @@ -1058,11 +1085,10 @@ static PyObject *xu_port_getattr(PyObjec
   6.274  static void xu_port_dealloc(PyObject *self)
   6.275  {
   6.276      xu_port_object *xup = (xu_port_object *)self;
   6.277 -    unmap_control_interface(xup->mem_fd, xup->interface);
   6.278 +    __xu_port_disconnect(xup);
   6.279      if ( xup->remote_dom != 0 )
   6.280          (void)xc_evtchn_close(xup->xc_handle, DOMID_SELF, xup->local_port);
   6.281      (void)xc_interface_close(xup->xc_handle);
   6.282 -    (void)close(xup->mem_fd);
   6.283      PyObject_Del(self);
   6.284  }
   6.285  
     7.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Thu Jul 01 07:41:45 2004 +0000
     7.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Thu Jul 01 07:41:58 2004 +0000
     7.3 @@ -170,13 +170,10 @@ class NotifierProtocol(protocol.Protocol
     7.4      def __init__(self, channelFactory):
     7.5          self.channelFactory = channelFactory
     7.6  
     7.7 -    def notificationReceived(self, idx, type):
     7.8 -        #print 'NotifierProtocol>notificationReceived>', idx, type
     7.9 +    def notificationReceived(self, idx):
    7.10          channel = self.channelFactory.getChannel(idx)
    7.11 -        if not channel:
    7.12 -            return
    7.13 -        #print 'NotifierProtocol>notificationReceived> channel', channel
    7.14 -        channel.notificationReceived(type)
    7.15 +        if channel:
    7.16 +            channel.notificationReceived()
    7.17  
    7.18      def connectionLost(self, reason=None):
    7.19          pass
    7.20 @@ -252,9 +249,8 @@ class NotifierPort(abstract.FileDescript
    7.21              notification = self.notifier.read()
    7.22              if not notification:
    7.23                  break
    7.24 -            (idx, type) = notification
    7.25 -            self.protocol.notificationReceived(idx, type)
    7.26 -            self.notifier.unmask(idx)
    7.27 +            self.protocol.notificationReceived(notification)
    7.28 +            self.notifier.unmask(notification)
    7.29              count += 1
    7.30          #print 'NotifierPort>doRead<'
    7.31  
     8.1 --- a/tools/python/xen/xend/server/channel.py	Thu Jul 01 07:41:45 2004 +0000
     8.2 +++ b/tools/python/xen/xend/server/channel.py	Thu Jul 01 07:41:58 2004 +0000
     8.3 @@ -107,22 +107,14 @@ class BaseChannel:
     8.4          """
     8.5          return self.idx
     8.6  
     8.7 -    def notificationReceived(self, type):
     8.8 +    def notificationReceived(self):
     8.9          """Called when a notification is received.
    8.10          Closes the channel on error, otherwise calls
    8.11          handleNotification(type), which should be defined
    8.12          in a subclass.
    8.13          """
    8.14 -        #print 'notificationReceived> type=', type, self
    8.15 -        if self.closed: return
    8.16 -        if type == self.factory.notifier.EXCEPTION:
    8.17 -            print 'notificationReceived> EXCEPTION'
    8.18 -            info = xc.evtchn_status(self.idx)
    8.19 -            if info['status'] == 'unbound':
    8.20 -                print 'notificationReceived> EXCEPTION closing...'
    8.21 -                self.close()
    8.22 -                return
    8.23 -        self.handleNotification(type)
    8.24 +        if not self.closed:
    8.25 +            self.handleNotification(type)
    8.26  
    8.27      def close(self):
    8.28          """Close the channel. Calls channelClosed() on the factory.