]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/mini-os.git/commitdiff
minios: Support net/block backend in domU
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 7 Feb 2008 09:15:59 +0000 (09:15 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 7 Feb 2008 09:15:59 +0000 (09:15 +0000)
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
blkfront.c
netfront.c

index 0c77d6d1e4c8badd762889fca152c40bab318309..f07900580b5689ee6cf2234dad3f589149aa412c 100644 (file)
@@ -35,6 +35,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;
@@ -81,24 +83,24 @@ struct blkfront_dev *init_blkfront(char *nodename, uint64_t *sectors, unsigned *
     dev = malloc(sizeof(*dev));
     dev->nodename = strdup(nodename);
 
-    s = (struct blkif_sring*) alloc_page();
-    memset(s,0,PAGE_SIZE);
-
-
-    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); 
+    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);
+
+
+    SHARED_RING_INIT(s);
+    FRONT_RING_INIT(&dev->ring, s, PAGE_SIZE);
+
+    dev->ring_ref = gnttab_grant_access(dev->dom,virt_to_mfn(s),0);
+
     // FIXME: proper frees on failures
 again:
     err = xenbus_transaction_start(&xbt);
@@ -280,7 +282,7 @@ void blkfront_aio(struct blkfront_aiocb *aiocbp, int write)
             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;
     }
index a0a3708fbc4a0c819e9764a7d6b3214c5c981a6e..e3c56c10c4a8668b67ced27be6195a1eee608ed3 100644 (file)
@@ -33,6 +33,8 @@ struct net_buffer {
 };
 
 struct netfront_dev {
+    domid_t dom;
+
     unsigned short tx_freelist[NET_TX_RING_SIZE];
     struct semaphore tx_sem;
 
@@ -141,7 +143,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;
     }
@@ -258,6 +260,15 @@ struct netfront_dev *init_netfront(char *nodename, void (*thenetif_rx)(unsigned
         dev->rx_buffers[i].page = (char*)alloc_page();
     }
 
+    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, 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);
@@ -269,17 +280,8 @@ struct netfront_dev *init_netfront(char *nodename, void (*thenetif_rx)(unsigned
     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);
-    HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
-    clear_evtchn(op.port);        /* Without, handler gets invoked now! */
-    dev->local_port = bind_evtchn(op.port, netfront_handler, dev);
-    dev->evtchn=op.port;
+    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;
 
@@ -416,7 +418,7 @@ void init_rx_buffers(struct netfront_dev *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;
 
@@ -461,7 +463,7 @@ void netfront_xmit(struct netfront_dev *dev, unsigned char* data,int len)
     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;