Skip to content

Commit 546233d

Browse files
benhillisBen Hillis
andauthored
cleanup: update GuestDeviceManager to not require passing in class IDs. (#14093)
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
1 parent a03462f commit 546233d

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

src/windows/common/GuestDeviceManager.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010

1111
inline const std::wstring c_defaultDeviceTag = L"default";
1212

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.
1414
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+
1518
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+
1621
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}
1723

1824
//
1925
// Provides synchronized access to guest device operations.

src/windows/common/VirtioNetworking.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ using wsl::core::VirtioNetworking;
1414
static constexpr auto c_loopbackDeviceName = TEXT(LX_INIT_LOOPBACK_DEVICE_NAME);
1515

1616
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) :
1818
m_guestDeviceManager(std::move(guestDeviceManager)),
1919
m_userToken(std::move(userToken)),
2020
m_gnsChannel(std::move(gnsChannel)),
21-
m_enableLocalhostRelay(enableLocalhostRelay),
22-
m_virtioNetworkClsid(classId)
21+
m_enableLocalhostRelay(enableLocalhostRelay)
2322
{
2423
}
2524

@@ -80,7 +79,7 @@ void VirtioNetworking::Initialize()
8079

8180
// Add virtio net adapter to guest
8281
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());
8483

8584
hns::HNSEndpoint endpointProperties;
8685
endpointProperties.ID = m_adapterId;
@@ -127,7 +126,7 @@ void VirtioNetworking::SetupLoopbackDevice()
127126
{
128127
m_localhostAdapterId = m_guestDeviceManager->AddGuestDevice(
129128
VIRTIO_NET_DEVICE_ID,
130-
m_virtioNetworkClsid,
129+
VIRTIO_NET_CLASS_ID,
131130
c_loopbackDeviceName,
132131
nullptr,
133132
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&
228227
}
229228

230229
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);
232231
if (server)
233232
{
234233
std::wstring portString = std::format(L"tag={};port_number={}", tag, addr.Ipv4.sin_port);

src/windows/common/VirtioNetworking.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace wsl::core {
1313
class VirtioNetworking : public INetworkingEngine
1414
{
1515
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);
1717
~VirtioNetworking();
1818

1919
// Note: This class cannot be moved because m_networkNotifyHandle captures a 'this' pointer.
@@ -51,7 +51,6 @@ class VirtioNetworking : public INetworkingEngine
5151
bool m_enableLocalhostRelay;
5252
GUID m_localhostAdapterId;
5353
GUID m_adapterId;
54-
GUID m_virtioNetworkClsid;
5554

5655
std::optional<ULONGLONG> m_interfaceLuid;
5756
ULONG m_networkMtu = 0;

src/windows/service/exe/WslCoreVm.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ using namespace std::string_literals;
4949
#define WSLG_SHARED_MEMORY_SIZE_MB 8192
5050
#define PAGE_SIZE 0x1000
5151

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-
5852
static constexpr size_t c_bootEntropy = 0x1000;
5953
static constexpr auto c_localDevicesKey = L"SOFTWARE\\Microsoft\\Terminal Server Client\\LocalDevices";
6054
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
583577
else if (m_vmConfig.NetworkingMode == NetworkingMode::VirtioProxy)
584578
{
585579
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);
587581
}
588582
else if (m_vmConfig.NetworkingMode == NetworkingMode::Bridged)
589583
{

0 commit comments

Comments
 (0)