netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Andrew J. Bennieston" <andrew.bennieston@citrix.com>
To: <xen-devel@lists.xenproject.org>, <davem@davemloft.net>
Cc: wei.liu2@citrix.com, ian.campbell@citrix.com,
	netdev@vger.kernel.org, paul.durrant@citrix.com,
	david.vrabel@citrix.com, zoltan.kiss@citrix.com,
	"Andrew J. Bennieston" <andrew.bennieston@citrix.com>
Subject: [PATCH V7 net-next 4/7] xen-netback: Correctly clean up after queue initialisation error.
Date: Tue, 29 Apr 2014 14:27:12 +0100	[thread overview]
Message-ID: <1398778035-26233-5-git-send-email-andrew.bennieston@citrix.com> (raw)
In-Reply-To: <1398778035-26233-1-git-send-email-andrew.bennieston@citrix.com>

From: "Andrew J. Bennieston" <andrew.bennieston@citrix.com>

Multiple queues were introduced in the previous patch, but if the
initialisation of a queue failed, earlier queues would not be cleaned
up. This patch adds cleanup logic for this scenario, making use of code
from the regular teardown sequence.

Signed-off-by: Andrew J. Bennieston <andrew.bennieston@citrix.com>
---
 drivers/net/xen-netback/common.h    |    1 +
 drivers/net/xen-netback/interface.c |   15 +++++++++++----
 drivers/net/xen-netback/xenbus.c    |   25 +++++++++++++++++++++++--
 3 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h
index 50efc29..16d6a05 100644
--- a/drivers/net/xen-netback/common.h
+++ b/drivers/net/xen-netback/common.h
@@ -237,6 +237,7 @@ struct xenvif *xenvif_alloc(struct device *parent,
 			    unsigned int handle);
 
 int xenvif_init_queue(struct xenvif_queue *queue);
+void xenvif_deinit_queue(struct xenvif_queue *queue);
 
 int xenvif_connect(struct xenvif_queue *queue, unsigned long tx_ring_ref,
 		   unsigned long rx_ring_ref, unsigned int tx_evtchn,
diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c
index 0eb6941..3ded8e5 100644
--- a/drivers/net/xen-netback/interface.c
+++ b/drivers/net/xen-netback/interface.c
@@ -733,6 +733,16 @@ void xenvif_disconnect(struct xenvif *vif)
 	}
 }
 
+/* Reverse the relevant parts of xenvif_init_queue().
+ * Used for queue teardown from xenvif_free(), and on the
+ * error handling paths in xenbus.c:connect().
+ */
+void xenvif_deinit_queue(struct xenvif_queue *queue)
+{
+	free_xenballooned_pages(MAX_PENDING_REQS, queue->mmap_pages);
+	netif_napi_del(&queue->napi);
+}
+
 void xenvif_free(struct xenvif *vif)
 {
 	struct xenvif_queue *queue = NULL;
@@ -756,11 +766,8 @@ void xenvif_free(struct xenvif *vif)
 
 	for (queue_index = 0; queue_index < num_queues; ++queue_index) {
 		queue = &vif->queues[queue_index];
-
 		xenvif_wait_unmap_timeout(queue, worst_case_skb_lifetime);
-		free_xenballooned_pages(MAX_PENDING_REQS, queue->mmap_pages);
-
-		netif_napi_del(&queue->napi);
+		xenvif_deinit_queue(queue);
 	}
 
 	/* Free the array of queues. The call below does not require
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index 9632e7a..96c63dc2 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -539,14 +539,33 @@ static void connect(struct backend_info *be)
 				be->vif->dev->name, queue->id);
 
 		err = xenvif_init_queue(queue);
-		if (err)
+		if (err) {
+			/* xenvif_init_queue() cleans up after itself on
+			 * failure, but we need to clean up any previously
+			 * initialised queues. Set num_queues to i so that
+			 * earlier queues can be destroyed using the regular
+			 * disconnect logic.
+			 */
+			rtnl_lock();
+			netif_set_real_num_tx_queues(be->vif->dev, queue_index);
+			rtnl_unlock();
 			goto err;
+		}
 
 		queue->remaining_credit = credit_bytes;
 
 		err = connect_rings(be, queue);
-		if (err)
+		if (err) {
+			/* connect_rings() cleans up after itself on failure,
+			 * but we need to clean up after xenvif_init_queue() here,
+			 * and also clean up any previously initialised queues.
+			 */
+			xenvif_deinit_queue(queue);
+			rtnl_lock();
+			netif_set_real_num_tx_queues(be->vif->dev, queue_index);
+			rtnl_unlock();
 			goto err;
+		}
 	}
 
 	xenvif_carrier_on(be->vif);
@@ -563,6 +582,8 @@ static void connect(struct backend_info *be)
 	return;
 
 err:
+	if (be->vif->dev->real_num_tx_queues > 0)
+		xenvif_disconnect(be->vif); /* Clean up existing queues */
 	vfree(be->vif->queues);
 	be->vif->queues = NULL;
 	rtnl_lock();
-- 
1.7.10.4

  parent reply	other threads:[~2014-04-29 13:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-29 13:27 [PATCH V7 net-next] xen-net{back, front}: Multiple transmit and receive queues Andrew J. Bennieston
2014-04-29 13:27 ` [PATCH V7 net-next 1/7] xen-netback: Move grant_copy_op array back into struct xenvif Andrew J. Bennieston
2014-04-30 14:50   ` Wei Liu
2014-04-29 13:27 ` [PATCH V7 net-next 2/7] xen-netback: Factor queue-specific data into queue struct Andrew J. Bennieston
2014-04-29 13:27 ` [PATCH V7 net-next 3/7] xen-netback: Add support for multiple queues Andrew J. Bennieston
2014-04-29 13:27 ` Andrew J. Bennieston [this message]
2014-04-30 14:49   ` [PATCH V7 net-next 4/7] xen-netback: Correctly clean up after queue initialisation error Wei Liu
2014-04-30 16:46     ` Andrew Bennieston
2014-04-29 13:27 ` [PATCH V7 net-next 5/7] xen-netfront: Factor queue-specific data into queue struct Andrew J. Bennieston
2014-04-30 14:51   ` Wei Liu
2014-04-30 14:59     ` [Xen-devel] " David Vrabel
2014-04-29 13:27 ` [PATCH V7 net-next 6/7] xen-netfront: Add support for multiple queues Andrew J. Bennieston
2014-04-30 14:51   ` Wei Liu
2014-04-29 13:27 ` [PATCH V7 net-next 7/7] xen-net{back, front}: Document multi-queue feature in netif.h Andrew J. Bennieston
2014-04-30 14:51   ` [PATCH V7 net-next 7/7] xen-net{back,front}: " Wei Liu
2014-04-30 16:47     ` Andrew Bennieston
2014-04-30 14:50 ` [PATCH V7 net-next] xen-net{back,front}: Multiple transmit and receive queues Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1398778035-26233-5-git-send-email-andrew.bennieston@citrix.com \
    --to=andrew.bennieston@citrix.com \
    --cc=davem@davemloft.net \
    --cc=david.vrabel@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=netdev@vger.kernel.org \
    --cc=paul.durrant@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    --cc=zoltan.kiss@citrix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).