WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 3 of 3] linux-2.6.18: xen/pv-on-hvm kexec+kdump: rese

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 3 of 3] linux-2.6.18: xen/pv-on-hvm kexec+kdump: reset PV devices in kexec or crash kernel
From: Olaf Hering <olaf@xxxxxxxxx>
Date: Wed, 05 Oct 2011 16:10:56 +0200
Delivery-date: Wed, 05 Oct 2011 07:15:45 -0700
Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1317823869; l=7207; s=domk; d=aepfle.de; h=To:From:Date:References:In-Reply-To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:X-RZG-CLASS-ID: X-RZG-AUTH; bh=ZZBPuHWqIM6U7B1/hDYb9GaZ62I=; b=M9C4YsmlnAKvFe8RzrCpjkW88mVUs4dVRkz7Hh+NxUNG/dQx5kMDQuOAdkuz9RgGIbO LYkD+Y+NtJzPExwDy6lLWMEXhC2piIR5q/iEuqhC+KeuiQu4lIacZRsIs726CTM6+ZEEE SLg4vgaMcrr5+1udQxI4NXMGOqgxJWnkaLw=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1317823853@xxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1317823853@xxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.7.5
# HG changeset patch
# User Olaf Hering <olaf@xxxxxxxxx>
# Date 1314290085 -7200
# Node ID 6cbbaae4d5bed6834b5606a3b9d1a5a919d2db89
# Parent  94943cf143035aa7adbec2c39c45c16a5174e3c5
linux-2.6.18: xen/pv-on-hvm kexec+kdump: reset PV devices in kexec or crash 
kernel

commit 116df6f004af81925dcaa90d4a3b76da6b009427

After triggering a crash dump in a HVM guest, the PV backend drivers
will remain in Connected state. When the kdump kernel starts the PV
drivers will skip such devices. As a result, no root device is found and
the vmcore cant be saved.

A similar situation happens after a kexec boot, here the devices will be
in the Closed state.

With this change all frontend devices with state XenbusStateConnected or
XenbusStateClosed will be reset by changing the state file to Closing ->
Closed -> Initializing.  This will trigger a disconnect in the backend
drivers. Now the frontend drivers will find the backend drivers in state
Initwait and can connect.

v2:
  - add timeout when waiting for backend state change
  (based on feedback from Ian Campell)
  - extent printk message to include backend string
  - add comment to fall-through case in xenbus_reset_frontend

Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>

diff -r 94943cf14303 -r 6cbbaae4d5be drivers/xen/xenbus/xenbus_probe.c
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -859,72 +859,100 @@ void unregister_xenstore_notifier(struct
 EXPORT_SYMBOL_GPL(unregister_xenstore_notifier);
 #endif
 
-#ifdef CONFIG_CRASH_DUMP
-static DECLARE_WAIT_QUEUE_HEAD(be_state_wq);
-static int be_state;
+#ifndef CONFIG_XEN
+static DECLARE_WAIT_QUEUE_HEAD(backend_state_wq);
+static int backend_state;
 
-static void xenbus_reset_state_changed(struct xenbus_watch *w, const char **v, 
unsigned int l)
+static void xenbus_reset_backend_state_changed(struct xenbus_watch *w,
+                                       const char **v, unsigned int l)
 {
-       if (xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i", &be_state) != 1)
-               be_state = XenbusStateUnknown;
-       printk(KERN_INFO "XENBUS: %s %s\n", v[XS_WATCH_PATH], 
xenbus_strstate(be_state));
-       wake_up(&be_state_wq);
+       if (xenbus_scanf(XBT_NIL, v[XS_WATCH_PATH], "", "%i", &backend_state) 
!= 1)
+               backend_state = XenbusStateUnknown;
+       printk(KERN_DEBUG "XENBUS: backend %s %s\n",
+                       v[XS_WATCH_PATH], xenbus_strstate(backend_state));
+       wake_up(&backend_state_wq);
 }
 
-static int xenbus_reset_check_final(int *st)
+static void xenbus_reset_wait_for_backend(char *be, int expected)
 {
-       return *st == XenbusStateInitialising || *st == XenbusStateInitWait;
+       long timeout;
+       timeout = wait_event_interruptible_timeout(backend_state_wq,
+                       backend_state == expected, 5 * HZ);
+       if (timeout <= 0)
+               printk(KERN_INFO "XENBUS: backend %s timed out.\n", be);
 }
 
-static void xenbus_reset_frontend_state(char *backend, char *frontend)
+/*
+ * Reset frontend if it is in Connected or Closed state.
+ * Wait for backend to catch up.
+ * State Connected happens during kdump, Closed after kexec.
+ */
+static void xenbus_reset_frontend(char *fe, char *be, int be_state)
 {
-       struct xenbus_watch watch;
+       struct xenbus_watch be_watch;
 
-       memset(&watch, 0, sizeof(watch));
-       watch.node = kasprintf(GFP_NOIO | __GFP_HIGH, "%s/state", backend);
-       if (!watch.node)
+       printk(KERN_DEBUG "XENBUS: backend %s %s\n",
+                       be, xenbus_strstate(be_state));
+
+       memset(&be_watch, 0, sizeof(be_watch));
+       be_watch.node = kasprintf(GFP_NOIO | __GFP_HIGH, "%s/state", be);
+       if (!be_watch.node)
                return;
 
-       watch.callback = xenbus_reset_state_changed;
-       be_state = XenbusStateUnknown;
+       be_watch.callback = xenbus_reset_backend_state_changed;
+       backend_state = XenbusStateUnknown;
 
-       printk(KERN_INFO "XENBUS: triggering reconnect on %s\n", backend);
-       register_xenbus_watch(&watch);
+       printk(KERN_INFO "XENBUS: triggering reconnect on %s\n", be);
+       register_xenbus_watch(&be_watch);
 
-       xenbus_printf(XBT_NIL, frontend, "state", "%d", XenbusStateClosing);
-       wait_event_interruptible(be_state_wq, be_state == XenbusStateClosing);
+       /* fall through to forward backend to state XenbusStateInitialising */
+       switch (be_state) {
+       case XenbusStateConnected:
+               xenbus_printf(XBT_NIL, fe, "state", "%d", XenbusStateClosing);
+               xenbus_reset_wait_for_backend(be, XenbusStateClosing);
 
-       xenbus_printf(XBT_NIL, frontend, "state", "%d", XenbusStateClosed);
-       wait_event_interruptible(be_state_wq, be_state == XenbusStateClosed);
+       case XenbusStateClosing:
+               xenbus_printf(XBT_NIL, fe, "state", "%d", XenbusStateClosed);
+               xenbus_reset_wait_for_backend(be, XenbusStateClosed);
 
-       xenbus_printf(XBT_NIL, frontend, "state", "%d", 
XenbusStateInitialising);
-       wait_event_interruptible(be_state_wq, 
xenbus_reset_check_final(&be_state));
+       case XenbusStateClosed:
+               xenbus_printf(XBT_NIL, fe, "state", "%d", 
XenbusStateInitialising);
+               xenbus_reset_wait_for_backend(be, XenbusStateInitWait);
+       }
 
-       unregister_xenbus_watch(&watch);
-       printk(KERN_INFO "XENBUS: reconnect done on %s\n", backend);
-       kfree(watch.node);
+       unregister_xenbus_watch(&be_watch);
+       printk(KERN_INFO "XENBUS: reconnect done on %s\n", be);
+       kfree(be_watch.node);
 }
 
-static void xenbus_reset_check_state(char *class, char *dev)
+static void xenbus_check_frontend(char *class, char *dev)
 {
-       int state, err;
+       int be_state, fe_state, err;
        char *backend, *frontend;
 
        frontend = kasprintf(GFP_NOIO | __GFP_HIGH, "device/%s/%s", class, dev);
        if (!frontend)
                return;
 
-       err = xenbus_scanf(XBT_NIL, frontend, "state", "%i", &state);
-       /* frontend connected? */
-       if (err == 1 && state == XenbusStateConnected) {
+       err = xenbus_scanf(XBT_NIL, frontend, "state", "%i", &fe_state);
+       if (err != 1)
+               goto out;
+
+       switch (fe_state) {
+       case XenbusStateConnected:
+       case XenbusStateClosed:
+               printk(KERN_DEBUG "XENBUS: frontend %s %s\n",
+                               frontend, xenbus_strstate(fe_state));
                backend = xenbus_read(XBT_NIL, frontend, "backend", NULL);
                if (!backend || IS_ERR(backend))
                        goto out;
-               err = xenbus_scanf(XBT_NIL, backend, "state", "%i", &state);
-               /* backend connected? */
-               if (err == 1 && state == XenbusStateConnected)
-                       xenbus_reset_frontend_state(backend, frontend);
+               err = xenbus_scanf(XBT_NIL, backend, "state", "%i", &be_state);
+               if (err == 1)
+                       xenbus_reset_frontend(frontend, backend, be_state);
                kfree(backend);
+               break;
+       default:
+               break;
        }
 out:
        kfree(frontend);
@@ -945,7 +973,7 @@ static void xenbus_reset_state(void)
                if (IS_ERR(dev))
                        continue;
                for (j = 0; j < dev_n; j++)
-                       xenbus_reset_check_state(devclass[i], dev[j]);
+                       xenbus_check_frontend(devclass[i], dev[j]);
                kfree(dev);
        }
        kfree(devclass);
@@ -956,11 +984,11 @@ void xenbus_probe(void *unused)
 {
        BUG_ON(!is_xenstored_ready());
 
-#ifdef CONFIG_CRASH_DUMP
-       /* reset devices in XenbusStateConnected state */
-       if (!is_initial_xendomain() && reset_devices)
-               xenbus_reset_state();
+#ifndef CONFIG_XEN
+       /* reset devices in Connected or Closed state */
+       xenbus_reset_state();
 #endif
+
        /* Enumerate devices in xenstore and watch for changes. */
        xenbus_probe_devices(&xenbus_frontend);
        register_xenbus_watch(&fe_watch);

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel