Commit 46e20d43 authored by Juergen Gross's avatar Juergen Gross

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: default avatarJuergen Gross <jgross@suse.com>
Reviewed-by: default avatarBoris Ostrovsky <boris.ostrovsky@oracle.com>
Signed-off-by: default avatarJuergen Gross <jgross@suse.com>
parent 47cbd598
...@@ -1921,8 +1921,7 @@ static int setup_netfront(struct xenbus_device *dev, ...@@ -1921,8 +1921,7 @@ static int setup_netfront(struct xenbus_device *dev,
struct netfront_queue *queue, unsigned int feature_split_evtchn) struct netfront_queue *queue, unsigned int feature_split_evtchn)
{ {
struct xen_netif_tx_sring *txs; struct xen_netif_tx_sring *txs;
struct xen_netif_rx_sring *rxs = NULL; struct xen_netif_rx_sring *rxs;
grant_ref_t gref;
int err; int err;
queue->tx_ring_ref = INVALID_GRANT_REF; queue->tx_ring_ref = INVALID_GRANT_REF;
...@@ -1930,33 +1929,19 @@ static int setup_netfront(struct xenbus_device *dev, ...@@ -1930,33 +1929,19 @@ static int setup_netfront(struct xenbus_device *dev,
queue->rx.sring = NULL; queue->rx.sring = NULL;
queue->tx.sring = NULL; queue->tx.sring = NULL;
txs = (struct xen_netif_tx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH); err = xenbus_setup_ring(dev, GFP_NOIO | __GFP_HIGH, (void **)&txs,
if (!txs) { 1, &queue->tx_ring_ref);
err = -ENOMEM; if (err)
xenbus_dev_fatal(dev, err, "allocating tx ring page");
goto fail; goto fail;
}
SHARED_RING_INIT(txs);
FRONT_RING_INIT(&queue->tx, txs, XEN_PAGE_SIZE);
err = xenbus_grant_ring(dev, txs, 1, &gref); XEN_FRONT_RING_INIT(&queue->tx, txs, XEN_PAGE_SIZE);
if (err < 0)
goto fail;
queue->tx_ring_ref = gref;
rxs = (struct xen_netif_rx_sring *)get_zeroed_page(GFP_NOIO | __GFP_HIGH); err = xenbus_setup_ring(dev, GFP_NOIO | __GFP_HIGH, (void **)&rxs,
if (!rxs) { 1, &queue->rx_ring_ref);
err = -ENOMEM; if (err)
xenbus_dev_fatal(dev, err, "allocating rx ring page");
goto fail; goto fail;
}
SHARED_RING_INIT(rxs);
FRONT_RING_INIT(&queue->rx, rxs, XEN_PAGE_SIZE);
err = xenbus_grant_ring(dev, rxs, 1, &gref); XEN_FRONT_RING_INIT(&queue->rx, rxs, XEN_PAGE_SIZE);
if (err < 0)
goto fail;
queue->rx_ring_ref = gref;
if (feature_split_evtchn) if (feature_split_evtchn)
err = setup_netfront_split(queue); err = setup_netfront_split(queue);
...@@ -1972,24 +1957,10 @@ static int setup_netfront(struct xenbus_device *dev, ...@@ -1972,24 +1957,10 @@ static int setup_netfront(struct xenbus_device *dev,
return 0; 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: fail:
if (queue->rx_ring_ref != INVALID_GRANT_REF) { xenbus_teardown_ring((void **)&queue->rx.sring, 1, &queue->rx_ring_ref);
gnttab_end_foreign_access(queue->rx_ring_ref, xenbus_teardown_ring((void **)&queue->tx.sring, 1, &queue->tx_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);
}
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment