public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] reset support: make net driver alloc/cleanup in probe and remove
@ 2008-01-23 14:16 Rusty Russell
       [not found] ` <200801240116.26160.rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Rusty Russell @ 2008-01-23 14:16 UTC (permalink / raw)
  To: kvm-devel
  Cc: Dor Laor, Avi Kivity,
	virtualization-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

Since we want to reset the device to remove them, this is simpler
(device is reset for us on driver remove).

Signed-off-by: Rusty Russell <rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>
---
 drivers/net/virtio_net.c |   44 +++++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 19 deletions(-)

diff -r 7e5b3ff06f60 drivers/net/virtio_net.c
--- a/drivers/net/virtio_net.c	Wed Jan 23 22:53:14 2008 +1100
+++ b/drivers/net/virtio_net.c	Wed Jan 23 23:52:46 2008 +1100
@@ -300,12 +300,6 @@ static int virtnet_open(struct net_devic
 {
 	struct virtnet_info *vi = netdev_priv(dev);
 
-	try_fill_recv(vi);
-
-	/* If we didn't even get one input buffer, we're useless. */
-	if (vi->num == 0)
-		return -ENOMEM;
-
 	napi_enable(&vi->napi);
 
 	/* If all buffers were filled by other side before we napi_enabled, we
@@ -320,22 +314,9 @@ static int virtnet_close(struct net_devi
 static int virtnet_close(struct net_device *dev)
 {
 	struct virtnet_info *vi = netdev_priv(dev);
-	struct sk_buff *skb;
 
 	napi_disable(&vi->napi);
 
-	/* networking core has neutered skb_xmit_done/skb_recv_done, so don't
-	 * worry about races vs. get(). */
-	vi->rvq->vq_ops->shutdown(vi->rvq);
-	while ((skb = __skb_dequeue(&vi->recv)) != NULL) {
-		kfree_skb(skb);
-		vi->num--;
-	}
-	vi->svq->vq_ops->shutdown(vi->svq);
-	while ((skb = __skb_dequeue(&vi->send)) != NULL)
-		kfree_skb(skb);
-
-	BUG_ON(vi->num != 0);
 	return 0;
 }
 
@@ -403,10 +384,22 @@ static int virtnet_probe(struct virtio_d
 		pr_debug("virtio_net: registering device failed\n");
 		goto free_send;
 	}
+
+	/* Last of all, set up some receive buffers. */
+	try_fill_recv(vi);
+
+	/* If we didn't even get one input buffer, we're useless. */
+	if (vi->num == 0) {
+		err = -ENOMEM;
+		goto unregister;
+	}
+
 	pr_debug("virtnet: registered device %s\n", dev->name);
 	vdev->priv = vi;
 	return 0;
 
+unregister:
+	unregister_netdev(dev);
 free_send:
 	vdev->config->del_vq(vi->svq);
 free_recv:
@@ -419,6 +412,19 @@ static void virtnet_remove(struct virtio
 static void virtnet_remove(struct virtio_device *vdev)
 {
 	struct virtnet_info *vi = vdev->priv;
+	struct sk_buff *skb;
+
+	/* Free our skbs in send and recv queues, if any. */
+	vi->rvq->vq_ops->shutdown(vi->rvq);
+	while ((skb = __skb_dequeue(&vi->recv)) != NULL) {
+		kfree_skb(skb);
+		vi->num--;
+	}
+	vi->svq->vq_ops->shutdown(vi->svq);
+	while ((skb = __skb_dequeue(&vi->send)) != NULL)
+		kfree_skb(skb);
+
+	BUG_ON(vi->num != 0);
 
 	vdev->config->del_vq(vi->svq);
 	vdev->config->del_vq(vi->rvq);

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-01-29 17:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-23 14:16 [PATCH 1/2] reset support: make net driver alloc/cleanup in probe and remove Rusty Russell
     [not found] ` <200801240116.26160.rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>
2008-01-23 14:18   ` [PATCH 2/2] virtio reset support Rusty Russell
     [not found]     ` <200801240118.09032.rusty-8n+1lVoiYb80n/F98K4Iww@public.gmane.org>
2008-01-24 13:09       ` Dor Laor
     [not found]         ` <1201180147.7100.35.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-01-24 21:19           ` Rusty Russell
2008-01-27 13:22       ` Avi Kivity
     [not found]         ` <479C8599.60007-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2008-01-28 15:40           ` Anthony Liguori
     [not found]             ` <479DF787.2020100-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-01-28 15:48               ` Avi Kivity
     [not found]                 ` <479DF952.9040201-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2008-01-28 22:47                   ` Anthony Liguori
2008-01-29 17:27                     ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox