|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 2/2] Use virtual-device as target ID
Per blkif.h, this is the only value that can be used as target ID.
There's no guarantee that the frontend path will equal the value found
in virtual-device.
Signed-off-by: Tu Dinh <ngoc-tu.dinh@xxxxxxxxxx>
---
src/xenvbd/adapter.c | 52 ++++++++++++++++++++++++++++++++++++++++++++
src/xenvbd/target.c | 7 +++---
src/xenvbd/target.h | 1 +
3 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/src/xenvbd/adapter.c b/src/xenvbd/adapter.c
index 5b787d1..4ff4e80 100644
--- a/src/xenvbd/adapter.c
+++ b/src/xenvbd/adapter.c
@@ -378,6 +378,50 @@ ignore:
return TRUE;
}
+static FORCEINLINE NTSTATUS
+__AdapterGetVirtualDevice(
+ _In_ PXENVBD_ADAPTER Adapter,
+ _In_ PSTR DeviceId,
+ _Out_ PULONG VirtualDevice
+ )
+{
+ PCHAR Buffer;
+ CHAR Path[MAXNAMELEN];
+ NTSTATUS status;
+
+ status = RtlStringCbPrintfA(Path,
+ sizeof(Path),
+ "device/vbd/%s",
+ DeviceId);
+ if (!NT_SUCCESS(status))
+ goto fail1;
+
+ status = XENBUS_STORE(Read,
+ &Adapter->StoreInterface,
+ NULL,
+ Path,
+ "virtual-device",
+ &Buffer);
+ if (!NT_SUCCESS(status))
+ goto fail2;
+
+ *VirtualDevice = strtoul(Buffer, NULL, 10);
+
+ XENBUS_STORE(Free,
+ &Adapter->StoreInterface,
+ Buffer);
+
+ return STATUS_SUCCESS;
+
+fail2:
+ Error("fail2\n");
+
+fail1:
+ Error("fail1 (%08x)\n", status);
+
+ return status;
+}
+
BOOLEAN
AdapterIsTargetEmulated(
_In_ PXENVBD_ADAPTER Adapter,
@@ -495,6 +539,7 @@ __AdapterEnumerate(
// add new targets
for (Index = 0; Devices[Index].Buffer != NULL; ++Index) {
+ ULONG VirtualDevice;
NTSTATUS status;
Device = &Devices[Index];
@@ -505,8 +550,15 @@ __AdapterEnumerate(
if (__AdapterHiddenTarget(Adapter, Device->Buffer))
continue;
+ status = __AdapterGetVirtualDevice(Adapter,
+ Device->Buffer,
+ &VirtualDevice);
+ if (!NT_SUCCESS(status))
+ continue;
+
status = TargetCreate(Adapter,
Device->Buffer,
+ VirtualDevice,
&Target);
if (status == STATUS_RETRY)
NeedReboot = TRUE;
diff --git a/src/xenvbd/target.c b/src/xenvbd/target.c
index cfbcb02..9b7c72b 100644
--- a/src/xenvbd/target.c
+++ b/src/xenvbd/target.c
@@ -1475,11 +1475,9 @@ TargetD0ToD3(
static FORCEINLINE ULONG
__ParseVbd(
- _In_ PSTR DeviceIdStr
+ _In_ ULONG DeviceId
)
{
- ULONG DeviceId = strtoul(DeviceIdStr, NULL, 10);
-
ASSERT3U((DeviceId & ~((1 << 29) - 1)), ==, 0);
if (DeviceId & (1 << 28))
@@ -1504,6 +1502,7 @@ NTSTATUS
TargetCreate(
_In_ PXENVBD_ADAPTER Adapter,
_In_ PSTR DeviceId,
+ _In_ ULONG VirtualDevice,
_Outptr_ PXENVBD_TARGET *_Target
)
{
@@ -1511,7 +1510,7 @@ TargetCreate(
PXENVBD_TARGET Target;
ULONG TargetId;
- TargetId = __ParseVbd(DeviceId);
+ TargetId = __ParseVbd(VirtualDevice);
if (TargetId >= XENVBD_MAX_TARGETS)
return STATUS_RETRY;
diff --git a/src/xenvbd/target.h b/src/xenvbd/target.h
index 05447ab..c560e91 100644
--- a/src/xenvbd/target.h
+++ b/src/xenvbd/target.h
@@ -45,6 +45,7 @@ extern NTSTATUS
TargetCreate(
_In_ PXENVBD_ADAPTER Adapter,
_In_ PSTR DeviceId,
+ _In_ ULONG VirtualDevice,
_Outptr_ PXENVBD_TARGET *_Target
);
--
2.56.0.windows.4
--
Ngoc Tu Dinh | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |