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

[PATCH 1/2] frontend: Cache 0x80/0x83 inquiry overrides


  • To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Date: Mon, 2 Nov 2026 12:57:49 +0100
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=vates.tech header.i="@vates.tech" header.h="From:Subject:Date:Message-ID:To:Cc:MIME-Version:Content-Type:Feedback-ID"
  • Cc: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
  • Delivery-date: Mon, 02 Nov 2026 11:58:02 +0000
  • Feedback-id: default:8631fc262581453bbf619ec5b2062170:Sweego
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

Storport uses the results of 0x80/0x83 VPD pages to identify an unique
storage unit. However, storage migration may cause the VDI UUID (and
thus the 0x80/0x83 inquiry values sent by sm) to change. If we pass on
the VPD change to Storport, then the disk will be considered as surprise
removed by Windows.

Instead, we must cache and use 0x80/0x83 overrides exactly once through
the entire lifetime of the frontend.

Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
 src/xenvbd/frontend.c | 115 +++++++++++++++++++++++++-----------------
 1 file changed, 70 insertions(+), 45 deletions(-)

diff --git a/src/xenvbd/frontend.c b/src/xenvbd/frontend.c
index 20207ba..038de09 100644
--- a/src/xenvbd/frontend.c
+++ b/src/xenvbd/frontend.c
@@ -75,6 +75,7 @@ struct _XENVBD_FRONTEND {
     XENVBD_DISKINFO             DiskInfo;
     XENVBD_PAGE                 Page80;
     XENVBD_PAGE                 Page83;
+    BOOLEAN                     InquiryInitialized;
     ULONG                       MaxQueues;
     ULONG                       NumQueues;
 
@@ -927,44 +928,85 @@ FrontendReadDiskInfo(
 }
 
 static FORCEINLINE VOID
-FrontendReadInquiryOverrides(
-    _Inout_ PXENVBD_FRONTEND    Frontend
+__FrontendFreePage(
+    _Inout_ PXENVBD_PAGE        Page
+    )
+{
+    if (Page->Data)
+        Base64Free(Page->Data);
+    Page->Data = NULL;
+    Page->Size = 0;
+}
+
+static FORCEINLINE BOOLEAN
+__FrontendPageEqual(
+    _In_ PXENVBD_PAGE           Page1,
+    _In_ PXENVBD_PAGE           Page2
+    )
+{
+    if (Page1->Size != Page2->Size)
+        return FALSE;
+    if (Page1->Size == 0)
+        return TRUE;
+    return RtlEqualMemory(Page1->Data, Page2->Data, Page1->Size);
+}
+
+static FORCEINLINE VOID
+__FrontendReadPage(
+    _In_ PXENVBD_FRONTEND       Frontend,
+    _In_ PCHAR                  Node,
+    _Out_ PXENVBD_PAGE          Page
     )
 {
     PCHAR                       Buffer;
     NTSTATUS                    status;
 
+    Page->Data = NULL;
+    Page->Size = 0;
+
     status = XENBUS_STORE(Read,
                           &Frontend->StoreInterface,
                           NULL,
                           Frontend->BackendPath,
-                          "sm-data/scsi/0x12/0x80",
+                          Node,
                           &Buffer);
-    if (NT_SUCCESS(status)) {
-        (VOID) Base64Decode(Buffer,
-                            &Frontend->Page80.Data,
-                            &Frontend->Page80.Size);
+    if (!NT_SUCCESS(status))
+        return;
 
-        XENBUS_STORE(Free,
-                     &Frontend->StoreInterface,
-                     Buffer);
-    }
+    (VOID) Base64Decode(Buffer,
+                        &Page->Data,
+                        &Page->Size);
 
-    status = XENBUS_STORE(Read,
-                          &Frontend->StoreInterface,
-                          NULL,
-                          Frontend->BackendPath,
-                          "sm-data/scsi/0x12/0x83",
-                          &Buffer);
-    if (NT_SUCCESS(status)) {
-        (VOID) Base64Decode(Buffer,
-                            &Frontend->Page83.Data,
-                            &Frontend->Page83.Size);
+    XENBUS_STORE(Free,
+                 &Frontend->StoreInterface,
+                 Buffer);
+}
 
-        XENBUS_STORE(Free,
-                     &Frontend->StoreInterface,
-                     Buffer);
+static FORCEINLINE VOID
+FrontendReadInquiryOverrides(
+    _Inout_ PXENVBD_FRONTEND    Frontend
+    )
+{
+    XENVBD_PAGE                 Page80;
+    XENVBD_PAGE                 Page83;
+
+    __FrontendReadPage(Frontend, "sm-data/scsi/0x12/0x80", &Page80);
+    __FrontendReadPage(Frontend, "sm-data/scsi/0x12/0x83", &Page83);
+
+    if (!Frontend->InquiryInitialized) {
+        Frontend->Page80 = Page80;
+        Frontend->Page83 = Page83;
+        Frontend->InquiryInitialized = TRUE;
+        return;
     }
+
+    if (!__FrontendPageEqual(&Frontend->Page80, &Page80) ||
+        !__FrontendPageEqual(&Frontend->Page83, &Page83))
+        Warning("Target[%d] : backend inquiry data has changed, using cached 
value\n",
+                Frontend->TargetId);
+
+    __FrontendFreePage(&Page80);
+    __FrontendFreePage(&Page83);
 }
 
 //=============================================================================
@@ -1287,17 +1329,6 @@ abort:
 fail7:
     Error("Fail7\n");
     RtlZeroMemory(&Frontend->Features, sizeof(XENVBD_FEATURES));
-
-    if (Frontend->Page80.Data)
-        Base64Free(Frontend->Page80.Data);
-    Frontend->Page80.Data = NULL;
-    Frontend->Page80.Size = 0;
-
-    if (Frontend->Page83.Data)
-        Base64Free(Frontend->Page83.Data);
-    Frontend->Page83.Data = NULL;
-    Frontend->Page83.Size = 0;
-
     RtlZeroMemory(&Frontend->DiskInfo, sizeof(XENVBD_DISKINFO));
 
 fail6:
@@ -1328,16 +1359,6 @@ FrontendDisconnect(
 
     Frontend->NumQueues = 0;
 
-    if (Frontend->Page80.Data)
-        Base64Free(Frontend->Page80.Data);
-    Frontend->Page80.Data = NULL;
-    Frontend->Page80.Size = 0;
-
-    if (Frontend->Page83.Data)
-        Base64Free(Frontend->Page83.Data);
-    Frontend->Page83.Data = NULL;
-    Frontend->Page83.Size = 0;
-
     RtlZeroMemory(&Frontend->Features, sizeof(XENVBD_FEATURES));
 }
 _IRQL_requires_(DISPATCH_LEVEL)
@@ -2000,6 +2021,10 @@ FrontendDestroy(
     RtlZeroMemory(&Frontend->DiskInfo, sizeof(XENVBD_DISKINFO));
     RtlZeroMemory(&Frontend->Caps, sizeof(XENVBD_CAPS));
 
+    __FrontendFreePage(&Frontend->Page83);
+    __FrontendFreePage(&Frontend->Page80);
+    Frontend->InquiryInitialized = FALSE;
+
     ASSERT3P(Frontend->BackendPath, ==, NULL);
     ASSERT3P(Frontend->BackendWatch, ==, NULL);
 
-- 
2.56.0.windows.4



--
Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

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