Samuel Thibault
2008-Feb-06 16:08 UTC
[Xen-devel] [PATCH] minios: Support net/block backend in domU
minios: Support net/block backend in domU Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com> diff -r 3c4ba66c097f extras/mini-os/blkfront.c --- a/extras/mini-os/blkfront.c Tue Feb 05 17:02:20 2008 +0000 +++ b/extras/mini-os/blkfront.c Wed Feb 06 16:05:11 2008 +0000 @@ -39,6 +39,8 @@ struct blk_buffer { }; struct blkfront_dev { + domid_t dom; + struct blkif_front_ring ring; grant_ref_t ring_ref; evtchn_port_t evtchn, local_port; @@ -95,6 +97,15 @@ struct blkfront_dev *init_blkfront(char dev = malloc(sizeof(*dev)); dev->nodename = strdup(nodename); + evtchn_alloc_unbound_t op; + op.dom = DOMID_SELF; + snprintf(path, sizeof(path), "%s/backend-id", nodename); + dev->dom = op.remote_dom = xenbus_read_integer(path); + HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op); + clear_evtchn(op.port); /* Without, handler gets invoked now! */ + dev->local_port = bind_evtchn(op.port, blkfront_handler, dev); + dev->evtchn=op.port; + s = (struct blkif_sring*) alloc_page(); memset(s,0,PAGE_SIZE); @@ -102,16 +113,7 @@ struct blkfront_dev *init_blkfront(char SHARED_RING_INIT(s); FRONT_RING_INIT(&dev->ring, s, PAGE_SIZE); - dev->ring_ref = gnttab_grant_access(0,virt_to_mfn(s),0); - - evtchn_alloc_unbound_t op; - op.dom = DOMID_SELF; - snprintf(path, sizeof(path), "%s/backend-id", nodename); - op.remote_dom = xenbus_read_integer(path); - HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op); - clear_evtchn(op.port); /* Without, handler gets invoked now! */ - dev->local_port = bind_evtchn(op.port, blkfront_handler, dev); - dev->evtchn=op.port; + dev->ring_ref = gnttab_grant_access(dev->dom,virt_to_mfn(s),0); // FIXME: proper frees on failures again: @@ -294,7 +296,7 @@ void blkfront_aio(struct blkfront_aiocb barrier(); } aiocbp->gref[j] = req->seg[j].gref - gnttab_grant_access(0, virtual_to_mfn(data), write); + gnttab_grant_access(dev->dom, virtual_to_mfn(data), write); req->seg[j].first_sect = 0; req->seg[j].last_sect = PAGE_SIZE / dev->sector_size - 1; } diff -r 3c4ba66c097f extras/mini-os/netfront.c --- a/extras/mini-os/netfront.c Tue Feb 05 17:02:20 2008 +0000 +++ b/extras/mini-os/netfront.c Wed Feb 06 16:05:11 2008 +0000 @@ -36,6 +36,8 @@ struct net_buffer { }; struct netfront_dev { + domid_t dom; + unsigned short tx_freelist[NET_TX_RING_SIZE]; struct semaphore tx_sem; @@ -163,7 +165,7 @@ moretodo: /* We are sure to have free gnttab entries since they got released above */ buf->gref = req->gref = - gnttab_grant_access(0,virt_to_mfn(page),0); + gnttab_grant_access(dev->dom,virt_to_mfn(page),0); req->id = id; } @@ -296,24 +298,10 @@ struct netfront_dev *init_netfront(char dev->rx_buffers[i].page = (char*)alloc_page(); } - txs = (struct netif_tx_sring*) alloc_page(); - rxs = (struct netif_rx_sring *) alloc_page(); - memset(txs,0,PAGE_SIZE); - memset(rxs,0,PAGE_SIZE); - - - SHARED_RING_INIT(txs); - SHARED_RING_INIT(rxs); - FRONT_RING_INIT(&dev->tx, txs, PAGE_SIZE); - FRONT_RING_INIT(&dev->rx, rxs, PAGE_SIZE); - - dev->tx_ring_ref = gnttab_grant_access(0,virt_to_mfn(txs),0); - dev->rx_ring_ref = gnttab_grant_access(0,virt_to_mfn(rxs),0); - evtchn_alloc_unbound_t op; op.dom = DOMID_SELF; snprintf(path, sizeof(path), "%s/backend-id", nodename); - op.remote_dom = xenbus_read_integer(path); + dev->dom = op.remote_dom = xenbus_read_integer(path); HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op); clear_evtchn(op.port); /* Without, handler gets invoked now! */ #ifdef HAVE_LIBC @@ -323,6 +311,20 @@ struct netfront_dev *init_netfront(char #endif dev->local_port = bind_evtchn(op.port, netfront_handler, dev); dev->evtchn=op.port; + + txs = (struct netif_tx_sring*) alloc_page(); + rxs = (struct netif_rx_sring *) alloc_page(); + memset(txs,0,PAGE_SIZE); + memset(rxs,0,PAGE_SIZE); + + + SHARED_RING_INIT(txs); + SHARED_RING_INIT(rxs); + FRONT_RING_INIT(&dev->tx, txs, PAGE_SIZE); + FRONT_RING_INIT(&dev->rx, rxs, PAGE_SIZE); + + dev->tx_ring_ref = gnttab_grant_access(dev->dom,virt_to_mfn(txs),0); + dev->rx_ring_ref = gnttab_grant_access(dev->dom,virt_to_mfn(rxs),0); dev->netif_rx = thenetif_rx; @@ -476,7 +478,7 @@ void init_rx_buffers(struct netfront_dev req = RING_GET_REQUEST(&dev->rx, requeue_idx); buf->gref = req->gref = - gnttab_grant_access(0,virt_to_mfn(buf->page),0); + gnttab_grant_access(dev->dom,virt_to_mfn(buf->page),0); req->id = requeue_idx; @@ -521,7 +523,7 @@ void netfront_xmit(struct netfront_dev * memcpy(page,data,len); buf->gref = - tx->gref = gnttab_grant_access(0,virt_to_mfn(page),0); + tx->gref = gnttab_grant_access(dev->dom,virt_to_mfn(page),1); tx->offset=0; tx->size = len; _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel