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

[XENVBD PATCH 2/2] Use UNPLUG v3



Use UnplugBootEmulated to detect whether the boot disk should remain emulated
to avoid openning an absolute registry path.
Use UnplugReboot to request a reboot from xenbus_monitor. Also removes the
RequestKey property from the INF file, as its no longer needed.
Bumps binding in INF file to match revision exposed by xenbus that implements
UNPLUG v3 (0x0900000B)

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxx>
---
 include/unplug_interface.h | 40 +++++++++++++++++++-
 src/xenvbd.inf             |  8 ++--
 src/xenvbd/adapter.c       | 35 ++++++++++++------
 src/xenvbd/adapter.h       |  5 +++
 src/xenvbd/driver.c        | 76 --------------------------------------
 src/xenvbd/driver.h        |  6 ---
 6 files changed, 69 insertions(+), 101 deletions(-)

diff --git a/include/unplug_interface.h b/include/unplug_interface.h
index e99b406..1dc9f51 100644
--- a/include/unplug_interface.h
+++ b/include/unplug_interface.h
@@ -99,6 +99,28 @@ typedef BOOLEAN
     IN  XENBUS_UNPLUG_DEVICE_TYPE   Type
     );
 
+/*! \typedef XENBUS_UNPLUG_BOOT_EMULATED
+    \brief Should the boot disk be emulated
+
+    \param Interface The interface header
+*/
+typedef BOOLEAN
+(*XENBUS_UNPLUG_BOOT_EMULATED)(
+    IN  PINTERFACE                  Interface
+    );
+
+/*! \typedef XENBUS_UNPLUG_REBOOT
+    \brief Request a reboot to complete setup
+
+    \param Interface The interface header
+    \param Module The module name requesting a reboot
+*/
+typedef VOID
+(*XENBUS_UNPLUG_REBOOT)(
+    IN  PINTERFACE                  Interface,
+    IN  PCHAR                       Module
+    );
+
 // {73db6517-3d06-4937-989f-199b7501e229}
 DEFINE_GUID(GUID_XENBUS_UNPLUG_INTERFACE,
 0x73db6517, 0x3d06, 0x4937, 0x98, 0x9f, 0x19, 0x9b, 0x75, 0x01, 0xe2, 0x29);
@@ -126,7 +148,21 @@ struct _XENBUS_UNPLUG_INTERFACE_V2 {
     XENBUS_UNPLUG_IS_REQUESTED  UnplugIsRequested;
 };
 
-typedef struct _XENBUS_UNPLUG_INTERFACE_V2 XENBUS_UNPLUG_INTERFACE, 
*PXENBUS_UNPLUG_INTERFACE;
+/*! \struct _XENBUS_UNPLUG_INTERFACE_V3
+    \brief UNPLUG interface version 3
+    \ingroup interfaces
+*/
+struct _XENBUS_UNPLUG_INTERFACE_V3 {
+    INTERFACE                   Interface;
+    XENBUS_UNPLUG_ACQUIRE       UnplugAcquire;
+    XENBUS_UNPLUG_RELEASE       UnplugRelease;
+    XENBUS_UNPLUG_REQUEST       UnplugRequest;
+    XENBUS_UNPLUG_IS_REQUESTED  UnplugIsRequested;
+    XENBUS_UNPLUG_BOOT_EMULATED UnplugBootEmulated;
+    XENBUS_UNPLUG_REBOOT        UnplugReboot;
+};
+
+typedef struct _XENBUS_UNPLUG_INTERFACE_V3 XENBUS_UNPLUG_INTERFACE, 
*PXENBUS_UNPLUG_INTERFACE;
 
 /*! \def XENBUS_UNPLUG
     \brief Macro at assist in method invocation
@@ -137,6 +173,6 @@ typedef struct _XENBUS_UNPLUG_INTERFACE_V2 
XENBUS_UNPLUG_INTERFACE, *PXENBUS_UNP
 #endif  // _WINDLL
 
 #define XENBUS_UNPLUG_INTERFACE_VERSION_MIN  1
-#define XENBUS_UNPLUG_INTERFACE_VERSION_MAX  2
+#define XENBUS_UNPLUG_INTERFACE_VERSION_MAX  3
 
 #endif  // _XENBUS_UNPLUG_INTERFACE_H
diff --git a/src/xenvbd.inf b/src/xenvbd.inf
index 8bb7998..dfde613 100644
--- a/src/xenvbd.inf
+++ b/src/xenvbd.inf
@@ -54,9 +54,9 @@ xendisk.sys=0,,
 %Vendor%=Inst,NT@INF_ARCH@
 
 [Inst.NT@INF_ARCH@]
-%XenVbdName%=XenVbd_Inst,XENBUS\VEN_@VENDOR_PREFIX@@VENDOR_DEVICE_ID@&DEV_VBD&REV_0900000A
-%XenVbdName%=XenVbd_Inst,XENBUS\VEN_@VENDOR_PREFIX@0001&DEV_VBD&REV_0900000A
-%XenVbdName%=XenVbd_Inst,XENBUS\VEN_@VENDOR_PREFIX@0002&DEV_VBD&REV_0900000A
+%XenVbdName%=XenVbd_Inst,XENBUS\VEN_@VENDOR_PREFIX@@VENDOR_DEVICE_ID@&DEV_VBD&REV_0900000B
+%XenVbdName%=XenVbd_Inst,XENBUS\VEN_@VENDOR_PREFIX@0001&DEV_VBD&REV_0900000B
+%XenVbdName%=XenVbd_Inst,XENBUS\VEN_@VENDOR_PREFIX@0002&DEV_VBD&REV_0900000B
 
 [XenVbd_Inst] 
 CopyFiles=XenVbd_Copyfiles
@@ -101,7 +101,6 @@ AddReg=XenVbd_Parameters, XenVbd_Unplug, XenVbd_Extras
 HKR,"Parameters",,0x00000010
 HKR,"Parameters","BusType",0x00010001,0x00000001 
 HKR,"Parameters\PnpInterface","5",0x00010001,0x00000001 
-HKR,"Parameters","RequestKey",0x00000000,%RequestKey%
 HKR,"Parameters","max-ring-page-order",0x00010001,0x00000001
 HKR,"Parameters","multi-queue-max-queues",0x00010001,0x00000002
 
@@ -120,7 +119,6 @@ Vendor = "@VENDOR_NAME@"
 DiskDesc = "@PRODUCT_NAME@ PV Storage Host Adapter Package" 
 XenVbdName= "@PRODUCT_NAME@ PV Storage Host Adapter"
 XenDiskName= "@PRODUCT_NAME@ PV Storage Filter"
-RequestKey="SYSTEM\CurrentControlSet\Services\xenbus_monitor\Request"
 UnplugKey="SYSTEM\CurrentControlSet\Services\XEN\Unplug"
 PnpKey="SYSTEM\CurrentControlSet\Control\Pnp"
 PartMgrKey="SYSTEM\CurrentControlSet\Services\PartMgr\Parameters"
diff --git a/src/xenvbd/adapter.c b/src/xenvbd/adapter.c
index 7092086..0f9500c 100644
--- a/src/xenvbd/adapter.c
+++ b/src/xenvbd/adapter.c
@@ -418,6 +418,24 @@ AdapterBootEmulated(
     return Adapter->BootEmulated;
 }
 
+VOID
+AdapterRequestReboot(
+    IN  PXENVBD_ADAPTER Adapter
+    )
+{
+    NTSTATUS            status;
+
+    status = XENBUS_UNPLUG(Acquire, &Adapter->UnplugInterface);
+    if (!NT_SUCCESS(status))
+        return;
+
+    XENBUS_UNPLUG(Reboot,
+                  &Adapter->UnplugInterface,
+                  __MODULE__);
+
+    XENBUS_UNPLUG(Release, &Adapter->UnplugInterface);
+}
+
 static FORCEINLINE VOID
 __AdapterEnumerate(
     IN  PXENVBD_ADAPTER Adapter,
@@ -508,7 +526,7 @@ __AdapterEnumerate(
     if (NeedInvalidate)
         AdapterTargetListChanged(Adapter);
     if (NeedReboot)
-        DriverRequestReboot();
+        AdapterRequestReboot(Adapter);
 }
 
 static DECLSPEC_NOINLINE NTSTATUS
@@ -1190,25 +1208,18 @@ __AdapterSetBootEmulated(
     IN  PXENVBD_ADAPTER Adapter
     )
 {
-    CHAR                Key[] = "XEN:BOOT_EMULATED=";
-    PANSI_STRING        Option;
-    PCHAR               Value;
     NTSTATUS            status;
 
     Adapter->BootEmulated = FALSE;
 
-    status = RegistryQuerySystemStartOption(Key, &Option);
+    status = XENBUS_UNPLUG(Acquire, &Adapter->UnplugInterface);
     if (!NT_SUCCESS(status))
         return;
 
-    Value = Option->Buffer + sizeof (Key) - 1;
+    Adapter->BootEmulated = XENBUS_UNPLUG(BootEmulated,
+                                          &Adapter->UnplugInterface);
 
-    if (strcmp(Value, "TRUE") == 0)
-        Adapter->BootEmulated = TRUE;
-    else if (strcmp(Value, "FALSE") != 0)
-        Warning("UNRECOGNIZED VALUE OF %s: %s\n", Key, Value);
-
-    RegistryFreeSzValue(Option);
+    XENBUS_UNPLUG(Release, &Adapter->UnplugInterface);
 }
 
 __drv_requiresIRQL(PASSIVE_LEVEL)
diff --git a/src/xenvbd/adapter.h b/src/xenvbd/adapter.h
index e6684ba..7b8b952 100644
--- a/src/xenvbd/adapter.h
+++ b/src/xenvbd/adapter.h
@@ -73,6 +73,11 @@ AdapterBootEmulated(
     IN  PXENVBD_ADAPTER Adapter
     );
 
+extern VOID
+AdapterRequestReboot(
+    IN  PXENVBD_ADAPTER Adapter
+    );
+
 extern VOID
 AdapterCompleteSrb(
     IN  PXENVBD_ADAPTER Adapter,
diff --git a/src/xenvbd/driver.c b/src/xenvbd/driver.c
index ba0ad33..676246e 100644
--- a/src/xenvbd/driver.c
+++ b/src/xenvbd/driver.c
@@ -111,82 +111,6 @@ DriverDispatchPower(
     return Driver.StorPortDispatchPower(DeviceObject, Irp);
 }
 
-#define MAXNAMELEN  256
-
-__drv_requiresIRQL(PASSIVE_LEVEL)
-VOID
-DriverRequestReboot(
-    VOID
-    )
-{
-    PANSI_STRING    Ansi;
-    CHAR            RequestKeyName[MAXNAMELEN];
-    HANDLE          RequestKey;
-    HANDLE          SubKey;
-    NTSTATUS        status;
-
-    ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
-
-    status = RegistryQuerySzValue(Driver.ParametersKey,
-                                  "RequestKey",
-                                  NULL,
-                                  &Ansi);
-    if (!NT_SUCCESS(status))
-        goto fail1;
-
-    status = RtlStringCbPrintfA(RequestKeyName,
-                                MAXNAMELEN,
-                                "\\Registry\\Machine\\%Z",
-                                &Ansi[0]);
-    ASSERT(NT_SUCCESS(status));
-
-    status = RegistryCreateSubKey(NULL,
-                                  RequestKeyName,
-                                  REG_OPTION_NON_VOLATILE,
-                                  &RequestKey);
-    if (!NT_SUCCESS(status))
-        goto fail2;
-
-    status = RegistryCreateSubKey(RequestKey,
-                                  __MODULE__,
-                                  REG_OPTION_VOLATILE,
-                                  &SubKey);
-    if (!NT_SUCCESS(status))
-        goto fail3;
-
-    status = RegistryUpdateDwordValue(SubKey,
-                                      "Reboot",
-                                      1);
-    if (!NT_SUCCESS(status))
-        goto fail4;
-
-    RegistryCloseKey(SubKey);
-
-    RegistryCloseKey(RequestKey);
-
-    RegistryFreeSzValue(Ansi);
-
-    return;
-
-fail4:
-    Error("fail4\n");
-
-    RegistryCloseKey(SubKey);
-
-fail3:
-    Error("fail3\n");
-
-    RegistryCloseKey(RequestKey);
-
-fail2:
-    Error("fail2\n");
-
-    RegistryFreeSzValue(Ansi);
-
-fail1:
-    Error("fail1 (%08x)\n", status);
-}
-
 __drv_dispatchType(IRP_MJ_PNP)
 DRIVER_DISPATCH             DispatchPnp;
 
diff --git a/src/xenvbd/driver.h b/src/xenvbd/driver.h
index cd3c97f..5c5df45 100644
--- a/src/xenvbd/driver.h
+++ b/src/xenvbd/driver.h
@@ -62,12 +62,6 @@ DriverDispatchPower(
     IN  PIRP            Irp
     );
 
-__drv_requiresIRQL(PASSIVE_LEVEL)
-extern VOID
-DriverRequestReboot(
-    VOID
-    );
-
 // Registry overrides for driver features
 typedef enum _XENVBD_FEATURE {
     FeatureRemovable = 0,
-- 
2.44.0.windows.1




 


Rackspace

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