ia64/xen-unstable

changeset 16994:c9844192c965

minios: Support net/block backend in domU

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Feb 07 09:15:59 2008 +0000 (2008-02-07)
parents b280ee89dcdc
children 0672d5b11262
files extras/mini-os/blkfront.c extras/mini-os/netfront.c
line diff
     1.1 --- a/extras/mini-os/blkfront.c	Wed Feb 06 18:31:02 2008 +0000
     1.2 +++ b/extras/mini-os/blkfront.c	Thu Feb 07 09:15:59 2008 +0000
     1.3 @@ -35,6 +35,8 @@ struct blk_buffer {
     1.4  };
     1.5  
     1.6  struct blkfront_dev {
     1.7 +    domid_t dom;
     1.8 +
     1.9      struct blkif_front_ring ring;
    1.10      grant_ref_t ring_ref;
    1.11      evtchn_port_t evtchn, local_port;
    1.12 @@ -81,6 +83,15 @@ struct blkfront_dev *init_blkfront(char 
    1.13      dev = malloc(sizeof(*dev));
    1.14      dev->nodename = strdup(nodename);
    1.15  
    1.16 +    evtchn_alloc_unbound_t op;
    1.17 +    op.dom = DOMID_SELF;
    1.18 +    snprintf(path, sizeof(path), "%s/backend-id", nodename);
    1.19 +    dev->dom = op.remote_dom = xenbus_read_integer(path); 
    1.20 +    HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
    1.21 +    clear_evtchn(op.port);        /* Without, handler gets invoked now! */
    1.22 +    dev->local_port = bind_evtchn(op.port, blkfront_handler, dev);
    1.23 +    dev->evtchn=op.port;
    1.24 +
    1.25      s = (struct blkif_sring*) alloc_page();
    1.26      memset(s,0,PAGE_SIZE);
    1.27  
    1.28 @@ -88,16 +99,7 @@ struct blkfront_dev *init_blkfront(char 
    1.29      SHARED_RING_INIT(s);
    1.30      FRONT_RING_INIT(&dev->ring, s, PAGE_SIZE);
    1.31  
    1.32 -    dev->ring_ref = gnttab_grant_access(0,virt_to_mfn(s),0);
    1.33 -
    1.34 -    evtchn_alloc_unbound_t op;
    1.35 -    op.dom = DOMID_SELF;
    1.36 -    snprintf(path, sizeof(path), "%s/backend-id", nodename);
    1.37 -    op.remote_dom = xenbus_read_integer(path); 
    1.38 -    HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
    1.39 -    clear_evtchn(op.port);        /* Without, handler gets invoked now! */
    1.40 -    dev->local_port = bind_evtchn(op.port, blkfront_handler, dev);
    1.41 -    dev->evtchn=op.port;
    1.42 +    dev->ring_ref = gnttab_grant_access(dev->dom,virt_to_mfn(s),0);
    1.43  
    1.44      // FIXME: proper frees on failures
    1.45  again:
    1.46 @@ -280,7 +282,7 @@ void blkfront_aio(struct blkfront_aiocb 
    1.47              barrier();
    1.48          }
    1.49  	aiocbp->gref[j] = req->seg[j].gref =
    1.50 -            gnttab_grant_access(0, virtual_to_mfn(data), write);
    1.51 +            gnttab_grant_access(dev->dom, virtual_to_mfn(data), write);
    1.52  	req->seg[j].first_sect = 0;
    1.53  	req->seg[j].last_sect = PAGE_SIZE / dev->sector_size - 1;
    1.54      }
     2.1 --- a/extras/mini-os/netfront.c	Wed Feb 06 18:31:02 2008 +0000
     2.2 +++ b/extras/mini-os/netfront.c	Thu Feb 07 09:15:59 2008 +0000
     2.3 @@ -33,6 +33,8 @@ struct net_buffer {
     2.4  };
     2.5  
     2.6  struct netfront_dev {
     2.7 +    domid_t dom;
     2.8 +
     2.9      unsigned short tx_freelist[NET_TX_RING_SIZE];
    2.10      struct semaphore tx_sem;
    2.11  
    2.12 @@ -141,7 +143,7 @@ moretodo:
    2.13  
    2.14          /* We are sure to have free gnttab entries since they got released above */
    2.15          buf->gref = req->gref = 
    2.16 -            gnttab_grant_access(0,virt_to_mfn(page),0);
    2.17 +            gnttab_grant_access(dev->dom,virt_to_mfn(page),0);
    2.18  
    2.19          req->id = id;
    2.20      }
    2.21 @@ -258,6 +260,15 @@ struct netfront_dev *init_netfront(char 
    2.22          dev->rx_buffers[i].page = (char*)alloc_page();
    2.23      }
    2.24  
    2.25 +    evtchn_alloc_unbound_t op;
    2.26 +    op.dom = DOMID_SELF;
    2.27 +    snprintf(path, sizeof(path), "%s/backend-id", nodename);
    2.28 +    dev->dom = op.remote_dom = xenbus_read_integer(path);
    2.29 +    HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
    2.30 +    clear_evtchn(op.port);        /* Without, handler gets invoked now! */
    2.31 +    dev->local_port = bind_evtchn(op.port, netfront_handler, dev);
    2.32 +    dev->evtchn=op.port;
    2.33 +
    2.34      txs = (struct netif_tx_sring*) alloc_page();
    2.35      rxs = (struct netif_rx_sring *) alloc_page();
    2.36      memset(txs,0,PAGE_SIZE);
    2.37 @@ -269,17 +280,8 @@ struct netfront_dev *init_netfront(char 
    2.38      FRONT_RING_INIT(&dev->tx, txs, PAGE_SIZE);
    2.39      FRONT_RING_INIT(&dev->rx, rxs, PAGE_SIZE);
    2.40  
    2.41 -    dev->tx_ring_ref = gnttab_grant_access(0,virt_to_mfn(txs),0);
    2.42 -    dev->rx_ring_ref = gnttab_grant_access(0,virt_to_mfn(rxs),0);
    2.43 -
    2.44 -    evtchn_alloc_unbound_t op;
    2.45 -    op.dom = DOMID_SELF;
    2.46 -    snprintf(path, sizeof(path), "%s/backend-id", nodename);
    2.47 -    op.remote_dom = xenbus_read_integer(path);
    2.48 -    HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
    2.49 -    clear_evtchn(op.port);        /* Without, handler gets invoked now! */
    2.50 -    dev->local_port = bind_evtchn(op.port, netfront_handler, dev);
    2.51 -    dev->evtchn=op.port;
    2.52 +    dev->tx_ring_ref = gnttab_grant_access(dev->dom,virt_to_mfn(txs),0);
    2.53 +    dev->rx_ring_ref = gnttab_grant_access(dev->dom,virt_to_mfn(rxs),0);
    2.54  
    2.55      dev->netif_rx = thenetif_rx;
    2.56  
    2.57 @@ -416,7 +418,7 @@ void init_rx_buffers(struct netfront_dev
    2.58          req = RING_GET_REQUEST(&dev->rx, requeue_idx);
    2.59  
    2.60          buf->gref = req->gref = 
    2.61 -            gnttab_grant_access(0,virt_to_mfn(buf->page),0);
    2.62 +            gnttab_grant_access(dev->dom,virt_to_mfn(buf->page),0);
    2.63  
    2.64          req->id = requeue_idx;
    2.65  
    2.66 @@ -461,7 +463,7 @@ void netfront_xmit(struct netfront_dev *
    2.67      memcpy(page,data,len);
    2.68  
    2.69      buf->gref = 
    2.70 -        tx->gref = gnttab_grant_access(0,virt_to_mfn(page),0);
    2.71 +        tx->gref = gnttab_grant_access(dev->dom,virt_to_mfn(page),1);
    2.72  
    2.73      tx->offset=0;
    2.74      tx->size = len;