[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 11/18] xen/netfront: use xenbus_setup_ring() and xenbus_teardown_ring()



Simplify netfront's ring creation and removal via xenbus_setup_ring()
and xenbus_teardown_ring().

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
 drivers/net/xen-netfront.c | 49 +++++++++-----------------------------
 1 file changed, 11 insertions(+), 38 deletions(-)

diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index af3d3de7d9fa..880b10d435d9 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -1921,8 +1921,7 @@ static int setup_netfront(struct xenbus_device *dev,
                        struct netfront_queue *queue, unsigned int 
feature_split_evtchn)
 {
        struct xen_netif_tx_sring *txs;
-       struct xen_netif_rx_sring *rxs = NULL;
-       grant_ref_t gref;
+       struct xen_netif_rx_sring *rxs;
        int err;
 
        queue->tx_ring_ref = INVALID_GRANT_REF;
@@ -1930,34 +1929,22 @@ static int setup_netfront(struct xenbus_device *dev,
        queue->rx.sring = NULL;
        queue->tx.sring = NULL;
 
-       txs = (struct xen_netif_tx_sring *)get_zeroed_page(GFP_NOIO | 
__GFP_HIGH);
-       if (!txs) {
-               err = -ENOMEM;
-               xenbus_dev_fatal(dev, err, "allocating tx ring page");
+       err = xenbus_setup_ring(dev, GFP_NOIO | __GFP_HIGH, (void **)&txs,
+                               1, &queue->tx_ring_ref);
+       if (err)
                goto fail;
-       }
+
        SHARED_RING_INIT(txs);
        FRONT_RING_INIT(&queue->tx, txs, XEN_PAGE_SIZE);
 
-       err = xenbus_grant_ring(dev, txs, 1, &gref);
-       if (err < 0)
+       err = xenbus_setup_ring(dev, GFP_NOIO | __GFP_HIGH, (void **)&rxs,
+                               1, &queue->rx_ring_ref);
+       if (err)
                goto fail;
-       queue->tx_ring_ref = gref;
 
-       rxs = (struct xen_netif_rx_sring *)get_zeroed_page(GFP_NOIO | 
__GFP_HIGH);
-       if (!rxs) {
-               err = -ENOMEM;
-               xenbus_dev_fatal(dev, err, "allocating rx ring page");
-               goto fail;
-       }
        SHARED_RING_INIT(rxs);
        FRONT_RING_INIT(&queue->rx, rxs, XEN_PAGE_SIZE);
 
-       err = xenbus_grant_ring(dev, rxs, 1, &gref);
-       if (err < 0)
-               goto fail;
-       queue->rx_ring_ref = gref;
-
        if (feature_split_evtchn)
                err = setup_netfront_split(queue);
        /* setup single event channel if
@@ -1972,24 +1959,10 @@ static int setup_netfront(struct xenbus_device *dev,
 
        return 0;
 
-       /* If we fail to setup netfront, it is safe to just revoke access to
-        * granted pages because backend is not accessing it at this point.
-        */
  fail:
-       if (queue->rx_ring_ref != INVALID_GRANT_REF) {
-               gnttab_end_foreign_access(queue->rx_ring_ref,
-                                         (unsigned long)rxs);
-               queue->rx_ring_ref = INVALID_GRANT_REF;
-       } else {
-               free_page((unsigned long)rxs);
-       }
-       if (queue->tx_ring_ref != INVALID_GRANT_REF) {
-               gnttab_end_foreign_access(queue->tx_ring_ref,
-                                         (unsigned long)txs);
-               queue->tx_ring_ref = INVALID_GRANT_REF;
-       } else {
-               free_page((unsigned long)txs);
-       }
+       xenbus_teardown_ring((void **)&queue->rx.sring, 1, &queue->rx_ring_ref);
+       xenbus_teardown_ring((void **)&queue->tx.sring, 1, &queue->tx_ring_ref);
+
        return err;
 }
 
-- 
2.34.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.