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

[win-pv-devel] [PATCH v2] Add optional log level settings



From: Owen Smith <owen.smith@xxxxxxxxxx>

Adds XenLogLevel and QemuLogLevel to xen.sys and ConsoleLogLevel
to xenbus.sys, which can be used to override the default log levels.
Each value is a REG_MULTI_SZ that contains an enumerated list of
log levels; TRACE, INFO, WARNING, ERROR, CRITICAL are defined.

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 include/xen.h       |  10 ++++-
 src/xen/driver.c    | 103 ++++++++++++++++++++++++++++++++++------------------
 src/xen/log.c       |  88 +++++++++++++++++++++++++++++++++++++++-----
 src/xenbus/driver.c |  37 +++++++++++++++++++
 src/xenbus/driver.h |   6 +++
 src/xenbus/fdo.c    |   5 +--
 6 files changed, 198 insertions(+), 51 deletions(-)

diff --git a/include/xen.h b/include/xen.h
index 470ccd4..05cf8ec 100644
--- a/include/xen.h
+++ b/include/xen.h
@@ -365,7 +365,7 @@ UnplugDecrementValue(
 // LOG
 
 typedef enum _LOG_LEVEL {
-    LOG_LEVEL_INVALID = 0,
+    LOG_LEVEL_NONE = 0,
     LOG_LEVEL_TRACE = 1 << DPFLTR_TRACE_LEVEL,
     LOG_LEVEL_INFO = 1 << DPFLTR_INFO_LEVEL,
     LOG_LEVEL_WARNING = 1 << DPFLTR_WARNING_LEVEL,
@@ -413,6 +413,14 @@ LogResume(
     VOID
     );
 
+XEN_API
+NTSTATUS
+LogReadLogLevel(
+    IN  HANDLE      Key,
+    IN  PCHAR       Name,
+    OUT PLOG_LEVEL  LogLevel
+    );
+
 typedef struct _LOG_DISPOSITION LOG_DISPOSITION, *PLOG_DISPOSITION;
 
 XEN_API
diff --git a/src/xen/driver.c b/src/xen/driver.c
index f83cb13..fa141f3 100644
--- a/src/xen/driver.c
+++ b/src/xen/driver.c
@@ -49,6 +49,13 @@
 #include "assert.h"
 #include "version.h"
 
+#define DEFAULT_XEN_LOG_LEVEL   (LOG_LEVEL_TRACE |      \
+                                 LOG_LEVEL_CRITICAL)
+#define DEFAULT_QEMU_LOG_LEVEL  (LOG_LEVEL_INFO |       \
+                                 LOG_LEVEL_WARNING |    \
+                                 LOG_LEVEL_ERROR |      \
+                                 LOG_LEVEL_CRITICAL)
+
 typedef struct _XEN_DRIVER {
     PLOG_DISPOSITION    TraceDisposition;
     PLOG_DISPOSITION    InfoDisposition;
@@ -160,6 +167,8 @@ DllInitialize(
 {
     HANDLE              ServiceKey;
     HANDLE              UnplugKey;
+    HANDLE              ParametersKey;
+    LOG_LEVEL           LogLevel;
     NTSTATUS            status;
 
     ExInitializeDriverRuntime(DrvRtPoolNxOptIn);
@@ -173,17 +182,40 @@ DllInitialize(
     if (!NT_SUCCESS(status))
         goto fail1;
 
-    status = LogAddDisposition(LOG_LEVEL_TRACE |
-                               LOG_LEVEL_CRITICAL,
+    status = RegistryInitialize(RegistryPath);
+    if (!NT_SUCCESS(status))
+        goto fail2;
+
+    status = RegistryCreateServiceKey(&ServiceKey);
+    if (!NT_SUCCESS(status))
+        goto fail3;
+
+    status = RegistryCreateSubKey(ServiceKey,
+                                "Parameters",
+                                REG_OPTION_NON_VOLATILE,
+                                &ParametersKey);
+    if (!NT_SUCCESS(status))
+        goto fail4;
+
+    status = LogReadLogLevel(ParametersKey,
+                             "XenLogLevel",
+                             &LogLevel);
+    if (!NT_SUCCESS(status))
+        LogLevel = DEFAULT_XEN_LOG_LEVEL;
+
+    status = LogAddDisposition(LogLevel,
                                DriverOutputBuffer,
                                (PVOID)XEN_PORT,
                                &Driver.TraceDisposition);
     ASSERT(NT_SUCCESS(status));
 
-    status = LogAddDisposition(LOG_LEVEL_INFO |
-                               LOG_LEVEL_WARNING |
-                               LOG_LEVEL_ERROR |
-                               LOG_LEVEL_CRITICAL,
+    status = LogReadLogLevel(ParametersKey,
+                             "QemuLogLevel",
+                             &LogLevel);
+    if (!NT_SUCCESS(status))
+        LogLevel = DEFAULT_QEMU_LOG_LEVEL;
+
+    status = LogAddDisposition(LogLevel,
                                DriverOutputBuffer,
                                (PVOID)QEMU_PORT,
                                &Driver.InfoDisposition);
@@ -201,50 +233,44 @@ DllInitialize(
     if (__DriverSafeMode())
         Info("SAFE MODE\n");
 
-    status = RegistryInitialize(RegistryPath);
-    if (!NT_SUCCESS(status))
-        goto fail2;
-
-    status = RegistryCreateServiceKey(&ServiceKey);
-    if (!NT_SUCCESS(status))
-        goto fail3;
-
     status = RegistryCreateSubKey(ServiceKey,
                                   "Unplug",
                                   REG_OPTION_NON_VOLATILE,
                                   &UnplugKey);
     if (!NT_SUCCESS(status))
-        goto fail4;
+        goto fail5;
 
     __DriverSetUnplugKey(UnplugKey);
 
     status = AcpiInitialize();
     if (!NT_SUCCESS(status))
-        goto fail5;
+        goto fail6;
 
     status = SystemInitialize();
     if (!NT_SUCCESS(status))
-        goto fail6;
+        goto fail7;
 
     status = HypercallInitialize();
     if (!NT_SUCCESS(status))
-        goto fail7;
+        goto fail8;
 
     status = BugCheckInitialize();
     if (!NT_SUCCESS(status))
-        goto fail8;
+        goto fail9;
 
     status = ModuleInitialize();
     if (!NT_SUCCESS(status))
-        goto fail9;
+        goto fail10;
 
     status = ProcessInitialize();
     if (!NT_SUCCESS(status))
-        goto fail10;
+        goto fail11;
 
     status = UnplugInitialize();
     if (!NT_SUCCESS(status))
-        goto fail11;
+        goto fail12;
+
+    RegistryCloseKey(ParametersKey);
 
     RegistryCloseKey(ServiceKey);
 
@@ -252,41 +278,52 @@ DllInitialize(
 
     return STATUS_SUCCESS;
 
+fail12:
+    Error("fail12\n");
+
+    ProcessTeardown();
+
 fail11:
     Error("fail11\n");
 
-    ProcessTeardown();
+    ModuleTeardown();
 
 fail10:
     Error("fail10\n");
 
-    ModuleTeardown();
+    BugCheckTeardown();
 
 fail9:
     Error("fail9\n");
 
-    BugCheckTeardown();
+    HypercallTeardown();
 
 fail8:
     Error("fail8\n");
 
-    HypercallTeardown();
+    SystemTeardown();
 
 fail7:
     Error("fail7\n");
 
-    SystemTeardown();
+    AcpiTeardown();
 
 fail6:
     Error("fail6\n");
 
-    AcpiTeardown();
+    RegistryCloseKey(UnplugKey);
+    __DriverSetUnplugKey(NULL);
 
 fail5:
     Error("fail5\n");
 
-    RegistryCloseKey(UnplugKey);
-    __DriverSetUnplugKey(NULL);
+    LogRemoveDisposition(Driver.InfoDisposition);
+    Driver.InfoDisposition = NULL;
+
+    LogRemoveDisposition(Driver.TraceDisposition);
+    Driver.TraceDisposition = NULL;
+
+    RegistryCloseKey(ParametersKey);
 
 fail4:
     Error("fail4\n");
@@ -301,12 +338,6 @@ fail3:
 fail2:
     Error("fail2\n");
 
-    LogRemoveDisposition(Driver.InfoDisposition);
-    Driver.InfoDisposition = NULL;
-
-    LogRemoveDisposition(Driver.TraceDisposition);
-    Driver.TraceDisposition = NULL;
-
     LogTeardown();
 
 fail1:
diff --git a/src/xen/log.c b/src/xen/log.c
index ff8b091..c10315e 100644
--- a/src/xen/log.c
+++ b/src/xen/log.c
@@ -560,9 +560,9 @@ LogAddDisposition(
     ULONG                   Index;
     NTSTATUS                status;
 
-    status = STATUS_INVALID_PARAMETER;
-    if (Mask == 0)
-        goto fail1;
+    *Disposition = NULL;
+    if (Mask == LOG_LEVEL_NONE)
+        goto ignore;
 
     AcquireHighLock(&Context->Lock, &Irql);
 
@@ -581,21 +581,19 @@ LogAddDisposition(
     }
 
     if (!NT_SUCCESS(status))
-        goto fail2;
+        goto fail1;
 
     ReleaseHighLock(&Context->Lock, Irql);
 
+ignore:
     return STATUS_SUCCESS;
 
-fail2:
-    Error("fail2\n");
-
-    *Disposition = NULL;
+fail1:
+    Error("fail1 (%08x)\n", status);
 
     ReleaseHighLock(&Context->Lock, Irql);
 
-fail1:
-    Error("fail1 (%08x)\n", status);
+    *Disposition = NULL;
 
     return status;
 }
@@ -609,6 +607,9 @@ LogRemoveDisposition(
     KIRQL                   Irql;
     ULONG                   Index;
 
+    if (Disposition == NULL)
+        return;
+
     AcquireHighLock(&Context->Lock, &Irql);
 
     for (Index = 0; Index < LOG_MAXIMUM_DISPOSITION; Index++) {
@@ -664,6 +665,73 @@ LogResume(
     (VOID) DbgSetDebugPrintCallback(LogDebugPrint, TRUE);
 }
 
+typedef struct _XEN_LOG_LEVEL_NAME {
+    const CHAR      *Name;
+    LOG_LEVEL       LogLevel;
+} XEN_LOG_LEVEL_NAME, *PXEN_LOG_LEVEL_NAME;
+
+static const XEN_LOG_LEVEL_NAME XenLogLevelNames[] = {
+    {   "TRACE",    LOG_LEVEL_TRACE     },
+    {   "INFO",     LOG_LEVEL_INFO      },
+    {   "WARNING",  LOG_LEVEL_WARNING   },
+    {   "ERROR",    LOG_LEVEL_ERROR,    },
+    {   "CRITICAL", LOG_LEVEL_CRITICAL  }
+};
+
+XEN_API
+NTSTATUS
+LogReadLogLevel(
+    IN  HANDLE      Key,
+    IN  PCHAR       Name,
+    OUT PLOG_LEVEL  LogLevel
+    )
+{
+    PANSI_STRING    Values;
+    ULONG           Type;
+    ULONG           Index;
+    NTSTATUS        status;
+
+    status = RegistryQuerySzValue(Key,
+                                  Name,
+                                  &Type,
+                                  &Values);
+    if (!NT_SUCCESS(status))
+        goto fail1;
+
+    status = STATUS_INVALID_PARAMETER;
+    if (Type != REG_MULTI_SZ)
+        goto fail2;
+
+    *LogLevel = LOG_LEVEL_NONE;
+    for (Index = 0; Values[Index].Buffer != NULL; ++Index) {
+        PANSI_STRING    Value = &Values[Index];
+        ULONG           Level;
+
+        for (Level = 0; Level < ARRAYSIZE(XenLogLevelNames); ++Level) {
+            if (_stricmp(XenLogLevelNames[Level].Name, Value->Buffer) == 0) {
+                *LogLevel |= XenLogLevelNames[Level].LogLevel;
+                break;
+            }
+        }
+    }
+
+    RegistryFreeSzValue(Values);
+
+    return STATUS_SUCCESS;
+
+fail2:
+    Error("fail2\n");
+
+    RegistryFreeSzValue(Values);
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    *LogLevel = LOG_LEVEL_NONE;
+
+    return status;
+}
+
 NTSTATUS
 LogInitialize(
     VOID
diff --git a/src/xenbus/driver.c b/src/xenbus/driver.c
index bbbda6c..5550d88 100644
--- a/src/xenbus/driver.c
+++ b/src/xenbus/driver.c
@@ -48,6 +48,7 @@
 typedef struct _XENBUS_DRIVER {
     PDRIVER_OBJECT      DriverObject;
     HANDLE              ParametersKey;
+    LOG_LEVEL           ConsoleLogLevel;
 
     MUTEX               Mutex;
     LIST_ENTRY          List;
@@ -57,6 +58,10 @@ typedef struct _XENBUS_DRIVER {
 static XENBUS_DRIVER    Driver;
 
 #define XENBUS_DRIVER_TAG   'VIRD'
+#define DEFAULT_CONSOLE_LOG_LEVEL   (LOG_LEVEL_INFO |       \
+                                     LOG_LEVEL_WARNING |    \
+                                     LOG_LEVEL_ERROR |      \
+                                     LOG_LEVEL_CRITICAL)
 
 static FORCEINLINE PVOID
 __DriverAllocate(
@@ -122,6 +127,30 @@ DriverGetParametersKey(
     return __DriverGetParametersKey();
 }
 
+static FORCEINLINE VOID
+__DriverSetConsoleLogLevel(
+    IN  LOG_LEVEL   LogLevel
+    )
+{
+    Driver.ConsoleLogLevel = LogLevel;
+}
+
+static FORCEINLINE LOG_LEVEL
+__DriverGetConsoleLogLevel(
+    VOID
+    )
+{
+    return Driver.ConsoleLogLevel;
+}
+
+LOG_LEVEL
+DriverGetConsoleLogLevel(
+    VOID
+    )
+{
+    return __DriverGetConsoleLogLevel();
+}
+
 #define MAXNAMELEN  128
 
 static FORCEINLINE VOID
@@ -680,6 +709,7 @@ DriverEntry(
     HANDLE              ServiceKey;
     HANDLE              ParametersKey;
     ULONG               Index;
+    LOG_LEVEL           LogLevel;
     NTSTATUS            status;
 
     ASSERT3P(__DriverGetDriverObject(), ==, NULL);
@@ -721,6 +751,13 @@ DriverEntry(
 
     __DriverSetParametersKey(ParametersKey);
 
+    status = LogReadLogLevel(ParametersKey,
+                             "ConsoleLogLevel",
+                             &LogLevel);
+    if (!NT_SUCCESS(status))
+        LogLevel = DEFAULT_CONSOLE_LOG_LEVEL;
+    __DriverSetConsoleLogLevel(LogLevel);
+
     RegistryCloseKey(ServiceKey);
 
     status = XenTouch(__MODULE__,
diff --git a/src/xenbus/driver.h b/src/xenbus/driver.h
index dd81e4c..21fb1f7 100644
--- a/src/xenbus/driver.h
+++ b/src/xenbus/driver.h
@@ -42,6 +42,12 @@ DriverGetParametersKey(
     VOID
     );
 
+#include <xen.h>
+extern LOG_LEVEL
+DriverGetConsoleLogLevel(
+    VOID
+    );
+
 extern VOID
 DriverRequestReboot(
     VOID
diff --git a/src/xenbus/fdo.c b/src/xenbus/fdo.c
index 0aeea3d..c5b5da1 100644
--- a/src/xenbus/fdo.c
+++ b/src/xenbus/fdo.c
@@ -2680,10 +2680,7 @@ __FdoD3ToD0(
                   Fdo->Channel,
                   FALSE);
 
-    status = LogAddDisposition(LOG_LEVEL_INFO |
-                               LOG_LEVEL_WARNING |
-                               LOG_LEVEL_ERROR |
-                               LOG_LEVEL_CRITICAL,
+    status = LogAddDisposition(DriverGetConsoleLogLevel(),
                                FdoOutputBuffer,
                                Fdo,
                                &Fdo->LogDisposition);
-- 
2.8.3


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel

 


Rackspace

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