[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH xenbus 4/4] The PV console may not always be available



From: Paul Durrant <pdurrant@xxxxxxxxxx>

In some Xen deployments the tool-stack may not allocate a PV console ring
and event channel to the guest, so XENBUS should deal with this situation
gracefully.

Signed-off-by: Paul Durrant <pdurrant@xxxxxxxxxx>
---
 src/xenbus/console.c | 42 ++++++++++++++++++++----------
 src/xenbus/fdo.c     | 62 +++++++++++++++++++++++++-------------------
 2 files changed, 64 insertions(+), 40 deletions(-)

diff --git a/src/xenbus/console.c b/src/xenbus/console.c
index 8573ea77a612..e638b3f4c84a 100644
--- a/src/xenbus/console.c
+++ b/src/xenbus/console.c
@@ -331,7 +331,7 @@ ConsoleDisable(
     Context->Channel = NULL;
 }
 
-static VOID
+static NTSTATUS
 ConsoleEnable(
     IN PXENBUS_CONSOLE_CONTEXT  Context
     )
@@ -340,8 +340,10 @@ ConsoleEnable(
     ULONG                       Port;
     NTSTATUS                    status;
 
+    /* In some Xen deployments the tool-stack may not set up the console */
     status = HvmGetParam(HVM_PARAM_CONSOLE_EVTCHN, &Value);
-    ASSERT(NT_SUCCESS(status));
+    if (!NT_SUCCESS(status))
+        goto fail1;
 
     Port = (ULONG)Value;
 
@@ -369,6 +371,13 @@ ConsoleEnable(
     // Trigger an initial poll
     if (KeInsertQueueDpc(&Context->Dpc, NULL, NULL))
         Context->Dpcs++;
+
+    return STATUS_SUCCESS;
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return status;
 }
 
 static
@@ -702,11 +711,13 @@ ConsoleAcquire(
     if (!NT_SUCCESS(status))
         goto fail4;
 
-    ConsoleEnable(Context);
+    status = ConsoleEnable(Context);
+    if (!NT_SUCCESS(status))
+        goto fail5;
 
     status = XENBUS_SUSPEND(Acquire, &Context->SuspendInterface);
     if (!NT_SUCCESS(status))
-        goto fail5;
+        goto fail6;
 
     status = XENBUS_SUSPEND(Register,
                             &Context->SuspendInterface,
@@ -715,11 +726,11 @@ ConsoleAcquire(
                             Context,
                             &Context->SuspendCallbackLate);
     if (!NT_SUCCESS(status))
-        goto fail6;
+        goto fail7;
 
     status = XENBUS_DEBUG(Acquire, &Context->DebugInterface);
     if (!NT_SUCCESS(status))
-        goto fail7;
+        goto fail8;
 
     status = XENBUS_DEBUG(Register,
                           &Context->DebugInterface,
@@ -728,7 +739,7 @@ ConsoleAcquire(
                           Context,
                           &Context->DebugCallback);
     if (!NT_SUCCESS(status))
-        goto fail8;
+        goto fail9;
 
     Trace("<====\n");
 
@@ -737,29 +748,32 @@ done:
 
     return STATUS_SUCCESS;
 
-fail8:
-    Error("fail8\n");
+fail9:
+    Error("fail9\n");
 
     XENBUS_DEBUG(Release, &Context->DebugInterface);
 
-fail7:
-    Error("fail7\n");
+fail8:
+    Error("fail8\n");
 
     XENBUS_SUSPEND(Deregister,
                    &Context->SuspendInterface,
                    Context->SuspendCallbackLate);
     Context->SuspendCallbackLate = NULL;
 
+fail7:
+    Error("fail7\n");
+
+    XENBUS_SUSPEND(Release, &Context->SuspendInterface);
+
 fail6:
     Error("fail6\n");
 
-    XENBUS_SUSPEND(Release, &Context->SuspendInterface);
+    ConsoleDisable(Context);
 
 fail5:
     Error("fail5\n");
 
-    ConsoleDisable(Context);
-
     XENBUS_EVTCHN(Release, &Context->EvtchnInterface);
 
 fail4:
diff --git a/src/xenbus/fdo.c b/src/xenbus/fdo.c
index ac86020765d5..e2b27021ce36 100644
--- a/src/xenbus/fdo.c
+++ b/src/xenbus/fdo.c
@@ -166,6 +166,7 @@ struct _XENBUS_FDO {
 
     PXENBUS_DEBUG_CALLBACK          DebugCallback;
     PXENBUS_SUSPEND_CALLBACK        SuspendCallbackLate;
+    BOOLEAN                         ConsoleAcquired;
     PLOG_DISPOSITION                LogDisposition;
 };
 
@@ -3057,11 +3058,13 @@ __FdoD3ToD0(
     if (!NT_SUCCESS(status))
         goto fail1;
 
-    status = LogAddDisposition(DriverGetConsoleLogLevel(),
-                               FdoOutputBuffer,
-                               Fdo,
-                               &Fdo->LogDisposition);
-    ASSERT(NT_SUCCESS(status));
+    if (Fdo->ConsoleAcquired) {
+        status = LogAddDisposition(DriverGetConsoleLogLevel(),
+                                   FdoOutputBuffer,
+                                   Fdo,
+                                   &Fdo->LogDisposition);
+        ASSERT(NT_SUCCESS(status));
+    }
 
     status = XENBUS_STORE(WatchAdd,
                           &Fdo->StoreInterface,
@@ -3137,8 +3140,10 @@ fail3:
 fail2:
     Error("fail2\n");
 
-    LogRemoveDisposition(Fdo->LogDisposition);
-    Fdo->LogDisposition = NULL;
+    if (Fdo->ConsoleAcquired) {
+        LogRemoveDisposition(Fdo->LogDisposition);
+        Fdo->LogDisposition = NULL;
+    }
 
     FdoVirqTeardown(Fdo);
 
@@ -3186,8 +3191,10 @@ __FdoD0ToD3(
                         Fdo->ScanWatch);
     Fdo->ScanWatch = NULL;
 
-    LogRemoveDisposition(Fdo->LogDisposition);
-    Fdo->LogDisposition = NULL;
+    if (Fdo->ConsoleAcquired) {
+        LogRemoveDisposition(Fdo->LogDisposition);
+        Fdo->LogDisposition = NULL;
+    }
 
     FdoVirqTeardown(Fdo);
 
@@ -3569,18 +3576,18 @@ FdoD3ToD0(
         goto fail6;
 
     status = XENBUS_CONSOLE(Acquire, &Fdo->ConsoleInterface);
-    if (!NT_SUCCESS(status))
-        goto fail7;
+    if (NT_SUCCESS(status))
+        Fdo->ConsoleAcquired = TRUE;
 
     if (Fdo->BalloonInterface.Interface.Context != NULL) {
         status = XENBUS_BALLOON(Acquire, &Fdo->BalloonInterface);
         if (!NT_SUCCESS(status))
-            goto fail8;
+            goto fail7;
     }
 
     status = __FdoD3ToD0(Fdo);
     if (!NT_SUCCESS(status))
-        goto fail9;
+        goto fail8;
 
     status = XENBUS_SUSPEND(Register,
                             &Fdo->SuspendInterface,
@@ -3589,7 +3596,7 @@ FdoD3ToD0(
                             Fdo,
                             &Fdo->SuspendCallbackLate);
     if (!NT_SUCCESS(status))
-        goto fail10;
+        goto fail9;
 
     status = XENBUS_DEBUG(Register,
                           &Fdo->DebugInterface,
@@ -3598,7 +3605,7 @@ FdoD3ToD0(
                           Fdo,
                           &Fdo->DebugCallback);
     if (!NT_SUCCESS(status))
-        goto fail11;
+        goto fail10;
 
     KeLowerIrql(Irql);
 
@@ -3629,33 +3636,33 @@ not_active:
 
     return STATUS_SUCCESS;
 
-fail11:
-    Error("fail11\n");
+fail10:
+    Error("fail10\n");
 
     XENBUS_SUSPEND(Deregister,
                    &Fdo->SuspendInterface,
                    Fdo->SuspendCallbackLate);
     Fdo->SuspendCallbackLate = NULL;
 
-fail10:
-    Error("fail10\n");
-
-    __FdoD0ToD3(Fdo);
-
 fail9:
     Error("fail9\n");
 
-    if (Fdo->BalloonInterface.Interface.Context != NULL)
-        XENBUS_BALLOON(Release, &Fdo->BalloonInterface);
+    __FdoD0ToD3(Fdo);
 
 fail8:
     Error("fail8\n");
 
-    XENBUS_CONSOLE(Release, &Fdo->ConsoleInterface);
+    if (Fdo->BalloonInterface.Interface.Context != NULL)
+        XENBUS_BALLOON(Release, &Fdo->BalloonInterface);
 
 fail7:
     Error("fail7\n");
 
+    if (Fdo->ConsoleAcquired) {
+        XENBUS_CONSOLE(Release, &Fdo->ConsoleInterface);
+        Fdo->ConsoleAcquired = FALSE;
+    }
+
     XENBUS_STORE(Release, &Fdo->StoreInterface);
 
 fail6:
@@ -3780,7 +3787,10 @@ FdoD0ToD3(
     if (Fdo->BalloonInterface.Interface.Context != NULL)
         XENBUS_BALLOON(Release, &Fdo->BalloonInterface);
 
-    XENBUS_CONSOLE(Release, &Fdo->ConsoleInterface);
+    if (Fdo->ConsoleAcquired) {
+        XENBUS_CONSOLE(Release, &Fdo->ConsoleInterface);
+        Fdo->ConsoleAcquired = FALSE;
+    }
 
     XENBUS_STORE(Release, &Fdo->StoreInterface);
 
-- 
2.17.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.