xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Aurelien Chartier <aurelien.chartier@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Aurelien Chartier <aurelien.chartier@citrix.com>,
	konrad.wilk@oracle.com, ian.campbell@citrix.com,
	JBeulich@suse.com, david.vrabel@citrix.com
Subject: [PATCH V5 2/2] xenbus: delay xenbus frontend resume if xenstored is not running
Date: Tue, 28 May 2013 18:09:56 +0100	[thread overview]
Message-ID: <1369760996-23616-3-git-send-email-aurelien.chartier@citrix.com> (raw)
In-Reply-To: <1369760996-23616-1-git-send-email-aurelien.chartier@citrix.com>

If the xenbus frontend is located in a domain running xenstored, the device
resume is hanging because it is happening before the process resume. This
patch adds extra logic to the resume code to check if we are the domain
running xenstored and delay the resume if needed.

Signed-off-by: Aurelien Chartier <aurelien.chartier@citrix.com>

Changes in v2:
- Instead of bypassing the resume, process it in a workqueue
Changes in v3:
- Add a struct work in xenbus_device to avoid dynamic allocation
- Several small code fixes
Changes in v4:
- Use a dedicated workqueue
Changes in v5:
- Move create_workqueue error handling to xenbus_frontend_dev_resume
---
 drivers/xen/xenbus/xenbus_probe_frontend.c |   37 +++++++++++++++++++++++++++-
 include/xen/xenbus.h                       |    1 +
 2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/xen/xenbus/xenbus_probe_frontend.c b/drivers/xen/xenbus/xenbus_probe_frontend.c
index 3159a37..3374aee 100644
--- a/drivers/xen/xenbus/xenbus_probe_frontend.c
+++ b/drivers/xen/xenbus/xenbus_probe_frontend.c
@@ -29,6 +29,8 @@
 #include "xenbus_probe.h"
 
 
+static struct workqueue_struct *xenbus_frontend_wq;
+
 /* device/<type>/<id> => <type>-<id> */
 static int frontend_bus_id(char bus_id[XEN_BUS_ID_SIZE], const char *nodename)
 {
@@ -89,9 +91,40 @@ static void backend_changed(struct xenbus_watch *watch,
 	xenbus_otherend_changed(watch, vec, len, 1);
 }
 
+static void xenbus_frontend_delayed_resume(struct work_struct *w)
+{
+	struct xenbus_device *xdev = container_of(w, struct xenbus_device, work);
+
+	xenbus_dev_resume(&xdev->dev);
+}
+
+static int xenbus_frontend_dev_resume(struct device *dev)
+{
+	/* 
+	 * If xenstored is running in this domain, we cannot access the backend
+	 * state at the moment, so we need to defer xenbus_dev_resume
+	 */
+	if (xen_store_domain_type == XS_LOCAL) {
+		struct xenbus_device *xdev = to_xenbus_device(dev);
+
+		if (!xenbus_frontend_wq) {
+			pr_err("%s: no workqueue to process delayed resume\n",
+			       xdev->nodename);
+			return -EFAULT;
+		}
+
+		INIT_WORK(&xdev->work, xenbus_frontend_delayed_resume);
+		queue_work(xenbus_frontend_wq, &xdev->work);
+
+		return 0;
+	}
+
+	return xenbus_dev_resume(dev);
+}
+
 static const struct dev_pm_ops xenbus_pm_ops = {
 	.suspend	= xenbus_dev_suspend,
-	.resume		= xenbus_dev_resume,
+	.resume		= xenbus_frontend_dev_resume,
 	.freeze		= xenbus_dev_suspend,
 	.thaw		= xenbus_dev_cancel,
 	.restore	= xenbus_dev_resume,
@@ -440,6 +473,8 @@ static int __init xenbus_probe_frontend_init(void)
 
 	register_xenstore_notifier(&xenstore_notifier);
 
+	xenbus_frontend_wq = create_workqueue("xenbus_frontend");
+
 	return 0;
 }
 subsys_initcall(xenbus_probe_frontend_init);
diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h
index 0a7515c..569c07f 100644
--- a/include/xen/xenbus.h
+++ b/include/xen/xenbus.h
@@ -70,6 +70,7 @@ struct xenbus_device {
 	struct device dev;
 	enum xenbus_state state;
 	struct completion down;
+	struct work_struct work;
 };
 
 static inline struct xenbus_device *to_xenbus_device(struct device *dev)
-- 
1.7.10.4

  parent reply	other threads:[~2013-05-28 17:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-28 17:09 [PATCH V5 0/2] xenbus: Fix S3 frontend resume when xenstored is not running Aurelien Chartier
2013-05-28 17:09 ` [PATCH V5 1/2] xenbus: save xenstore local status for later use Aurelien Chartier
2013-05-28 17:09 ` Aurelien Chartier [this message]
2013-05-29  7:03   ` [PATCH V5 2/2] xenbus: delay xenbus frontend resume if xenstored is not running Jan Beulich
2013-05-29 15:44     ` Konrad Rzeszutek Wilk
2013-05-29 16:17       ` Aurelien Chartier

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=1369760996-23616-3-git-send-email-aurelien.chartier@citrix.com \
    --to=aurelien.chartier@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=david.vrabel@citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=konrad.wilk@oracle.com \
    --cc=xen-devel@lists.xensource.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).