ia64/xen-unstable

changeset 6703:5321e0858b0d

grant_table.c reindent.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Sep 08 17:29:02 2005 +0000 (2005-09-08)
parents e3fd0fa58364
children a27e28d38d52 3bde4219c681
files xen/common/grant_table.c
line diff
     1.1 --- a/xen/common/grant_table.c	Thu Sep 08 17:25:52 2005 +0000
     1.2 +++ b/xen/common/grant_table.c	Thu Sep 08 17:29:02 2005 +0000
     1.3 @@ -399,7 +399,7 @@ static int
     1.4      {
     1.5          int              i;
     1.6          grant_mapping_t *new_mt;
     1.7 -        grant_table_t   *lgt      = ld->grant_table;
     1.8 +        grant_table_t   *lgt = ld->grant_table;
     1.9  
    1.10          if ( (lgt->maptrack_limit << 1) > MAPTRACK_MAX_ENTRIES )
    1.11          {
    1.12 @@ -437,9 +437,8 @@ static int
    1.13              ref, dom, dev_hst_ro_flags);
    1.14  #endif
    1.15  
    1.16 -    if ( 0 <= ( rc = __gnttab_activate_grant_ref( ld, led, rd, ref,
    1.17 -                                                  dev_hst_ro_flags,
    1.18 -                                                  addr, &frame)))
    1.19 +    if ( (rc = __gnttab_activate_grant_ref(ld, led, rd, ref, dev_hst_ro_flags,
    1.20 +                                           addr, &frame)) >= 0 )
    1.21      {
    1.22          /*
    1.23           * Only make the maptrack live _after_ writing the pte, in case we 
    1.24 @@ -807,7 +806,8 @@ gnttab_donate(gnttab_donate_t *uop, unsi
    1.25      int i;
    1.26      int result = GNTST_okay;
    1.27  
    1.28 -    for (i = 0; i < count; i++) {
    1.29 +    for ( i = 0; i < count; i++ )
    1.30 +    {
    1.31          gnttab_donate_t *gop = &uop[i];
    1.32  #if GRANT_DEBUG
    1.33          printk("gnttab_donate: i=%d mfn=%lx domid=%d gref=%08x\n",
    1.34 @@ -881,30 +881,6 @@ gnttab_donate(gnttab_donate_t *uop, unsi
    1.35           * headroom.  Also, a domain mustn't have PGC_allocated
    1.36           * pages when it is dying.
    1.37           */
    1.38 -#ifdef GRANT_DEBUG
    1.39 -        if (unlikely(e->tot_pages >= e->max_pages)) {
    1.40 -            printk("gnttab_dontate: no headroom tot_pages=%d max_pages=%d\n",
    1.41 -                   e->tot_pages, e->max_pages);
    1.42 -            spin_unlock(&e->page_alloc_lock);
    1.43 -            put_domain(e);
    1.44 -            gop->status = result = GNTST_general_error;
    1.45 -            break;
    1.46 -        }
    1.47 -        if (unlikely(test_bit(DOMFLAGS_DYING, &e->domain_flags))) {
    1.48 -            printk("gnttab_donate: target domain is dying\n");
    1.49 -            spin_unlock(&e->page_alloc_lock);
    1.50 -            put_domain(e);
    1.51 -            gop->status = result = GNTST_general_error;
    1.52 -            break;
    1.53 -        }
    1.54 -        if (unlikely(!gnttab_prepare_for_transfer(e, d, gop->handle))) {
    1.55 -            printk("gnttab_donate: gnttab_prepare_for_transfer fails.\n");
    1.56 -            spin_unlock(&e->page_alloc_lock);
    1.57 -            put_domain(e);
    1.58 -            gop->status = result = GNTST_general_error;
    1.59 -            break;
    1.60 -        }
    1.61 -#else
    1.62          ASSERT(e->tot_pages <= e->max_pages);
    1.63          if (unlikely(test_bit(DOMFLAGS_DYING, &e->domain_flags)) ||
    1.64              unlikely(e->tot_pages == e->max_pages) ||
    1.65 @@ -914,11 +890,10 @@ gnttab_donate(gnttab_donate_t *uop, unsi
    1.66                     e->tot_pages, e->max_pages, gop->handle, e->d_flags);
    1.67              spin_unlock(&e->page_alloc_lock);
    1.68              put_domain(e);
    1.69 -            /* XXX SMH: better error return here would be useful */
    1.70              gop->status = result = GNTST_general_error;
    1.71              break;
    1.72          }
    1.73 -#endif
    1.74 +
    1.75          /* Okay, add the page to 'e'. */
    1.76          if (unlikely(e->tot_pages++ == 0)) {
    1.77              get_knownalive_domain(e);
    1.78 @@ -957,38 +932,38 @@ do_grant_table_op(
    1.79      
    1.80      rc = -EFAULT;
    1.81      switch ( cmd )
    1.82 -        {
    1.83 -        case GNTTABOP_map_grant_ref:
    1.84 -            if ( unlikely(!array_access_ok(
    1.85 -                              uop, count, sizeof(gnttab_map_grant_ref_t))) )
    1.86 -                goto out;
    1.87 -            rc = gnttab_map_grant_ref((gnttab_map_grant_ref_t *)uop, count);
    1.88 -            break;
    1.89 -        case GNTTABOP_unmap_grant_ref:
    1.90 -            if ( unlikely(!array_access_ok(
    1.91 -                              uop, count, sizeof(gnttab_unmap_grant_ref_t))) )
    1.92 -                goto out;
    1.93 -            rc = gnttab_unmap_grant_ref((gnttab_unmap_grant_ref_t *)uop, 
    1.94 -                                        count);
    1.95 -            break;
    1.96 -        case GNTTABOP_setup_table:
    1.97 -            rc = gnttab_setup_table((gnttab_setup_table_t *)uop, count);
    1.98 -            break;
    1.99 +    {
   1.100 +    case GNTTABOP_map_grant_ref:
   1.101 +        if ( unlikely(!array_access_ok(
   1.102 +            uop, count, sizeof(gnttab_map_grant_ref_t))) )
   1.103 +            goto out;
   1.104 +        rc = gnttab_map_grant_ref((gnttab_map_grant_ref_t *)uop, count);
   1.105 +        break;
   1.106 +    case GNTTABOP_unmap_grant_ref:
   1.107 +        if ( unlikely(!array_access_ok(
   1.108 +            uop, count, sizeof(gnttab_unmap_grant_ref_t))) )
   1.109 +            goto out;
   1.110 +        rc = gnttab_unmap_grant_ref(
   1.111 +            (gnttab_unmap_grant_ref_t *)uop, count);
   1.112 +        break;
   1.113 +    case GNTTABOP_setup_table:
   1.114 +        rc = gnttab_setup_table((gnttab_setup_table_t *)uop, count);
   1.115 +        break;
   1.116  #if GRANT_DEBUG
   1.117 -        case GNTTABOP_dump_table:
   1.118 -            rc = gnttab_dump_table((gnttab_dump_table_t *)uop);
   1.119 -            break;
   1.120 +    case GNTTABOP_dump_table:
   1.121 +        rc = gnttab_dump_table((gnttab_dump_table_t *)uop);
   1.122 +        break;
   1.123  #endif
   1.124 -        case GNTTABOP_donate:
   1.125 -            if (unlikely(!array_access_ok(uop, count, 
   1.126 -                                          sizeof(gnttab_donate_t))))
   1.127 -                goto out;
   1.128 -            rc = gnttab_donate(uop, count);
   1.129 -            break;
   1.130 -        default:
   1.131 -            rc = -ENOSYS;
   1.132 -            break;
   1.133 -        }
   1.134 +    case GNTTABOP_donate:
   1.135 +        if (unlikely(!array_access_ok(
   1.136 +            uop, count, sizeof(gnttab_donate_t))))
   1.137 +            goto out;
   1.138 +        rc = gnttab_donate(uop, count);
   1.139 +        break;
   1.140 +    default:
   1.141 +        rc = -ENOSYS;
   1.142 +        break;
   1.143 +    }
   1.144      
   1.145    out:
   1.146      UNLOCK_BIGLOCK(d);
   1.147 @@ -1021,17 +996,17 @@ gnttab_check_unmap(
   1.148      lgt = ld->grant_table;
   1.149      
   1.150  #if GRANT_DEBUG_VERBOSE
   1.151 -    if ( ld->domain_id != 0 ) {
   1.152 -            DPRINTK("Foreign unref rd(%d) ld(%d) frm(%lx) flgs(%x).\n",
   1.153 -                    rd->domain_id, ld->domain_id, frame, readonly);
   1.154 -      }
   1.155 +    if ( ld->domain_id != 0 )
   1.156 +        DPRINTK("Foreign unref rd(%d) ld(%d) frm(%lx) flgs(%x).\n",
   1.157 +                rd->domain_id, ld->domain_id, frame, readonly);
   1.158  #endif
   1.159      
   1.160      /* Fast exit if we're not mapping anything using grant tables */
   1.161      if ( lgt->map_count == 0 )
   1.162          return 0;
   1.163      
   1.164 -    if ( get_domain(rd) == 0 ) {
   1.165 +    if ( get_domain(rd) == 0 )
   1.166 +    {
   1.167          DPRINTK("gnttab_check_unmap: couldn't get_domain rd(%d)\n",
   1.168                  rd->domain_id);
   1.169          return 0;
   1.170 @@ -1268,8 +1243,11 @@ grant_table_create(
   1.171      for ( i = 0; i < NR_GRANT_FRAMES; i++ )
   1.172      {
   1.173          SHARE_PFN_WITH_DOMAIN(
   1.174 -            virt_to_page((char *)(t->shared)+(i*PAGE_SIZE)), d);
   1.175 -        set_pfn_from_mfn((virt_to_phys(t->shared) >> PAGE_SHIFT) + i, INVALID_M2P_ENTRY);
   1.176 +            virt_to_page((char *)t->shared + (i * PAGE_SIZE)),
   1.177 +            d);
   1.178 +        set_pfn_from_mfn(
   1.179 +            (virt_to_phys(t->shared) >> PAGE_SHIFT) + i,
   1.180 +            INVALID_M2P_ENTRY);
   1.181      }
   1.182  
   1.183      /* Okay, install the structure. */
   1.184 @@ -1306,57 +1284,53 @@ gnttab_release_dev_mappings(grant_table_
   1.185      {
   1.186          map = &gt->maptrack[handle];
   1.187  
   1.188 -        if ( map->ref_and_flags & GNTMAP_device_map )
   1.189 -        {
   1.190 -            dom = map->domid;
   1.191 -            ref = map->ref_and_flags >> MAPTRACK_REF_SHIFT;
   1.192 +        if ( !(map->ref_and_flags & GNTMAP_device_map) )
   1.193 +            continue;
   1.194  
   1.195 -            DPRINTK("Grant release (%hu) ref:(%hu) flags:(%x) dom:(%hu)\n",
   1.196 -                    handle, ref,
   1.197 -                    map->ref_and_flags & MAPTRACK_GNTMAP_MASK, dom);
   1.198 +        dom = map->domid;
   1.199 +        ref = map->ref_and_flags >> MAPTRACK_REF_SHIFT;
   1.200  
   1.201 -            if ( unlikely((rd = find_domain_by_id(dom)) == NULL) ||
   1.202 -                 unlikely(ld == rd) )
   1.203 +        DPRINTK("Grant release (%hu) ref:(%hu) flags:(%x) dom:(%hu)\n",
   1.204 +                handle, ref, map->ref_and_flags & MAPTRACK_GNTMAP_MASK, dom);
   1.205 +
   1.206 +        if ( unlikely((rd = find_domain_by_id(dom)) == NULL) ||
   1.207 +             unlikely(ld == rd) )
   1.208 +        {
   1.209 +            if ( rd != NULL )
   1.210 +                put_domain(rd);
   1.211 +            printk(KERN_WARNING "Grant release: No dom%d\n", dom);
   1.212 +            continue;
   1.213 +        }
   1.214 +
   1.215 +        act = &rd->grant_table->active[ref];
   1.216 +        sha = &rd->grant_table->shared[ref];
   1.217 +
   1.218 +        spin_lock(&rd->grant_table->lock);
   1.219 +
   1.220 +        if ( act->pin & (GNTPIN_devw_mask | GNTPIN_devr_mask) )
   1.221 +        {
   1.222 +            frame = act->frame;
   1.223 +
   1.224 +            if ( ( (act->pin & GNTPIN_hstw_mask) == 0 ) &&
   1.225 +                 ( (act->pin & GNTPIN_devw_mask) >  0 ) )
   1.226              {
   1.227 -                if ( rd != NULL )
   1.228 -                    put_domain(rd);
   1.229 -
   1.230 -                printk(KERN_WARNING "Grant release: No dom%d\n", dom);
   1.231 -                continue;
   1.232 +                clear_bit(_GTF_writing, &sha->flags);
   1.233 +                put_page_type(&frame_table[frame]);
   1.234              }
   1.235  
   1.236 -            act = &rd->grant_table->active[ref];
   1.237 -            sha = &rd->grant_table->shared[ref];
   1.238 -
   1.239 -            spin_lock(&rd->grant_table->lock);
   1.240 -
   1.241 -            if ( act->pin & (GNTPIN_devw_mask | GNTPIN_devr_mask) )
   1.242 +            map->ref_and_flags &= ~GNTMAP_device_map;
   1.243 +            act->pin &= ~(GNTPIN_devw_mask | GNTPIN_devr_mask);
   1.244 +            if ( act->pin == 0 )
   1.245              {
   1.246 -                frame = act->frame;
   1.247 -
   1.248 -                if ( ( (act->pin & GNTPIN_hstw_mask) == 0 ) &&
   1.249 -                     ( (act->pin & GNTPIN_devw_mask) >  0 ) )
   1.250 -                {
   1.251 -                    clear_bit(_GTF_writing, &sha->flags);
   1.252 -                    put_page_type(&frame_table[frame]);
   1.253 -                }
   1.254 +                clear_bit(_GTF_reading, &sha->flags);
   1.255 +                map->ref_and_flags = 0;
   1.256 +                put_page(&frame_table[frame]);
   1.257 +            }
   1.258 +        }
   1.259  
   1.260 -                act->pin &= ~(GNTPIN_devw_mask | GNTPIN_devr_mask);
   1.261 +        spin_unlock(&rd->grant_table->lock);
   1.262  
   1.263 -                if ( act->pin == 0 )
   1.264 -                {
   1.265 -                    clear_bit(_GTF_reading, &sha->flags);
   1.266 -                    map->ref_and_flags = 0;
   1.267 -                    put_page(&frame_table[frame]);
   1.268 -                }
   1.269 -                else
   1.270 -                    map->ref_and_flags &= ~GNTMAP_device_map;
   1.271 -            }
   1.272 -
   1.273 -            spin_unlock(&rd->grant_table->lock);
   1.274 -
   1.275 -            put_domain(rd);
   1.276 -        }
   1.277 +        put_domain(rd);
   1.278      }
   1.279  }
   1.280