cleanup: update GuestDeviceManager to not require passing in class IDs. (#14093)
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
Ben Hillis committed
Jan 22, 2026 at 11:18 UTC
546233d5312b6863b23373e0e43f615d4a882236
4 files changed
+14
-16
src/windows/common/GuestDeviceManager.h
+7
-1
@@ -10,10 +10,16 @@
10
11
inline const std::wstring c_defaultDeviceTag = L"default";
12
13
-// These device types are implemented by the external wsldevicehost vdev.
13
+// These device types and class IDs are implemented by the external wsldevicehost vdev.
14
DEFINE_GUID(VIRTIO_FS_DEVICE_ID, 0x872270E1, 0xA899, 0x4AF6, 0xB4, 0x54, 0x71, 0x93, 0x63, 0x44, 0x35, 0xAD); // {872270E1-A899-4AF6-B454-7193634435AD}
15
+DEFINE_GUID(VIRTIO_FS_ADMIN_CLASS_ID, 0x7E6AD219, 0xD1B3, 0x42D5, 0xB8, 0xEE, 0xD9, 0x63, 0x24, 0xE6, 0x4F, 0xF6); // {7E6AD219-D1B3-42D5-B8EE-D96324E64FF6}
16
+DEFINE_GUID(VIRTIO_FS_CLASS_ID, 0x60285AE6, 0xAAF3, 0x4456, 0xB4, 0x44, 0xA6, 0xC2, 0xD0, 0xDE, 0xDA, 0x38); // {60285AE6-AAF3-4456-B444-A6C2D0DEDA38}
17
+
18
DEFINE_GUID(VIRTIO_NET_DEVICE_ID, 0xF07010D0, 0x0EA9, 0x447F, 0x88, 0xEF, 0xBD, 0x95, 0x2A, 0x4D, 0x2F, 0x14); // {F07010D0-0EA9-447F-88EF-BD952A4D2F14}
19
+DEFINE_GUID(VIRTIO_NET_CLASS_ID, 0x16479D2E, 0xF0C3, 0x4DBA, 0xBF, 0x7A, 0x04, 0xFF, 0xF0, 0x89, 0x2B, 0x07); // {16479D2E-F0C3-4DBA-BF7A-04FFF0892B07}
20
+
21
DEFINE_GUID(VIRTIO_PMEM_DEVICE_ID, 0xEDBB24BB, 0x5E19, 0x40F4, 0x8A, 0x0F, 0x82, 0x24, 0x31, 0x30, 0x64, 0xFD); // {EDBB24BB-5E19-40F4-8A0F-8224313064FD}
22
+DEFINE_GUID(VIRTIO_PMEM_CLASS_ID, 0xABB755FC, 0x1B86, 0x4255, 0x83, 0xE2, 0xE5, 0x78, 0x7A, 0xBC, 0xF6, 0xC2); // {ABB755FC-1B86-4255-83E2-E5787ABCF6C2}
23
24
//
25
// Provides synchronized access to guest device operations.
src/windows/common/VirtioNetworking.cpp
+5
-6
@@ -14,12 +14,11 @@ using wsl::core::VirtioNetworking;
14
static constexpr auto c_loopbackDeviceName = TEXT(LX_INIT_LOOPBACK_DEVICE_NAME);
15
16
VirtioNetworking::VirtioNetworking(
17
- GnsChannel&& gnsChannel, bool enableLocalhostRelay, std::shared_ptr<GuestDeviceManager> guestDeviceManager, GUID classId, wil::shared_handle userToken) :
17
+ GnsChannel&& gnsChannel, bool enableLocalhostRelay, std::shared_ptr<GuestDeviceManager> guestDeviceManager, wil::shared_handle userToken) :
18
m_guestDeviceManager(std::move(guestDeviceManager)),
19
m_userToken(std::move(userToken)),
20
m_gnsChannel(std::move(gnsChannel)),
21
- m_enableLocalhostRelay(enableLocalhostRelay),
22
- m_virtioNetworkClsid(classId)
21
+ m_enableLocalhostRelay(enableLocalhostRelay)
22
{
23
}
24
@@ -80,7 +79,7 @@ void VirtioNetworking::Initialize()
79
80
// Add virtio net adapter to guest
81
m_adapterId = m_guestDeviceManager->AddGuestDevice(
83
- VIRTIO_NET_DEVICE_ID, m_virtioNetworkClsid, L"eth0", nullptr, device_options.str().c_str(), 0, m_userToken.get());
82
+ VIRTIO_NET_DEVICE_ID, VIRTIO_NET_CLASS_ID, L"eth0", nullptr, device_options.str().c_str(), 0, m_userToken.get());
83
84
hns::HNSEndpoint endpointProperties;
85
endpointProperties.ID = m_adapterId;
@@ -127,7 +126,7 @@ void VirtioNetworking::SetupLoopbackDevice()
126
{
127
m_localhostAdapterId = m_guestDeviceManager->AddGuestDevice(
128
VIRTIO_NET_DEVICE_ID,
130
- m_virtioNetworkClsid,
129
+ VIRTIO_NET_CLASS_ID,
130
c_loopbackDeviceName,
131
nullptr,
132
L"client_ip=127.0.0.1;client_mac=00:11:22:33:44:55",
@@ -228,7 +227,7 @@ int VirtioNetworking::ModifyOpenPorts(_In_ PCWSTR tag, _In_ const SOCKADDR_INET&
227
}
228
229
auto lock = m_lock.lock_exclusive();
231
- const auto server = m_guestDeviceManager->GetRemoteFileSystem(m_virtioNetworkClsid, c_defaultDeviceTag);
230
+ const auto server = m_guestDeviceManager->GetRemoteFileSystem(VIRTIO_NET_CLASS_ID, c_defaultDeviceTag);
231
if (server)
232
{
233
std::wstring portString = std::format(L"tag={};port_number={}", tag, addr.Ipv4.sin_port);
src/windows/common/VirtioNetworking.h
+1
-2
@@ -13,7 +13,7 @@ namespace wsl::core {
13
class VirtioNetworking : public INetworkingEngine
14
{
15
public:
16
- VirtioNetworking(GnsChannel&& gnsChannel, bool enableLocalhostRelay, std::shared_ptr<GuestDeviceManager> guestDeviceManager, GUID classId, wil::shared_handle userToken);
16
+ VirtioNetworking(GnsChannel&& gnsChannel, bool enableLocalhostRelay, std::shared_ptr<GuestDeviceManager> guestDeviceManager, wil::shared_handle userToken);
17
~VirtioNetworking();
18
19
// Note: This class cannot be moved because m_networkNotifyHandle captures a 'this' pointer.
@@ -51,7 +51,6 @@ private:
51
bool m_enableLocalhostRelay;
52
GUID m_localhostAdapterId;
53
GUID m_adapterId;
54
- GUID m_virtioNetworkClsid;
54
55
std::optional<ULONGLONG> m_interfaceLuid;
56
ULONG m_networkMtu = 0;
src/windows/service/exe/WslCoreVm.cpp
+1
-7
@@ -49,12 +49,6 @@ using namespace std::string_literals;
49
#define WSLG_SHARED_MEMORY_SIZE_MB 8192
50
#define PAGE_SIZE 0x1000
51
52
-// WSL-specific virtio device class IDs.
53
-DEFINE_GUID(VIRTIO_FS_ADMIN_CLASS_ID, 0x7E6AD219, 0xD1B3, 0x42D5, 0xB8, 0xEE, 0xD9, 0x63, 0x24, 0xE6, 0x4F, 0xF6); // {7E6AD219-D1B3-42D5-B8EE-D96324E64FF6}
54
-DEFINE_GUID(VIRTIO_FS_CLASS_ID, 0x60285AE6, 0xAAF3, 0x4456, 0xB4, 0x44, 0xA6, 0xC2, 0xD0, 0xDE, 0xDA, 0x38); // {60285AE6-AAF3-4456-B444-A6C2D0DEDA38}
55
-DEFINE_GUID(VIRTIO_NET_CLASS_ID, 0x16479D2E, 0xF0C3, 0x4DBA, 0xBF, 0x7A, 0x04, 0xFF, 0xF0, 0x89, 0x2B, 0x07); // {16479D2E-F0C3-4DBA-BF7A-04FFF0892B07}
56
-DEFINE_GUID(VIRTIO_PMEM_CLASS_ID, 0xABB755FC, 0x1B86, 0x4255, 0x83, 0xE2, 0xE5, 0x78, 0x7A, 0xBC, 0xF6, 0xC2); // {ABB755FC-1B86-4255-83E2-E5787ABCF6C2}
57
-
52
static constexpr size_t c_bootEntropy = 0x1000;
53
static constexpr auto c_localDevicesKey = L"SOFTWARE\\Microsoft\\Terminal Server Client\\LocalDevices";
54
static constexpr std::pair<uint32_t, uint32_t> c_schemaVersionNickel{2, 7};
@@ -583,7 +577,7 @@ void WslCoreVm::Initialize(const GUID& VmId, const wil::shared_handle& UserToken
577
else if (m_vmConfig.NetworkingMode == NetworkingMode::VirtioProxy)
578
{
579
m_networkingEngine = std::make_unique<wsl::core::VirtioNetworking>(
586
- std::move(gnsChannel), m_vmConfig.EnableLocalhostRelay, m_guestDeviceManager, VIRTIO_NET_CLASS_ID, m_userToken);
580
+ std::move(gnsChannel), m_vmConfig.EnableLocalhostRelay, m_guestDeviceManager, m_userToken);
581
}
582
else if (m_vmConfig.NetworkingMode == NetworkingMode::Bridged)
583
{