From 38724a88abe918ced7248b6b9efcd6154f701187 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 31 Dec 2025 18:55:37 +0000 Subject: [PATCH 1/5] Initial plan From 2fc7d11ab78d92a382e0965ef68dd45524b01cb5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 31 Dec 2025 18:59:47 +0000 Subject: [PATCH 2/5] Refactor to use std::variant instead of std::pair with optionals Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com> --- .../wslaservice/exe/WSLAVirtualMachine.cpp | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/windows/wslaservice/exe/WSLAVirtualMachine.cpp b/src/windows/wslaservice/exe/WSLAVirtualMachine.cpp index d5fc55747..50e4c69e8 100644 --- a/src/windows/wslaservice/exe/WSLAVirtualMachine.cpp +++ b/src/windows/wslaservice/exe/WSLAVirtualMachine.cpp @@ -15,6 +15,7 @@ Module Name: #include "WSLAVirtualMachine.h" #include #include +#include #include "hcs_schema.h" #include "VirtioNetworking.h" #include "NatNetworking.h" @@ -283,8 +284,8 @@ void WSLAVirtualMachine::Start() #endif // Initialize the boot VHDs. - std::pair, std::optional> rootVhd; - std::pair, std::optional> modulesVhd; + std::variant rootVhd; + std::variant modulesVhd; hcs::Scsi scsiController{}; if (!FeatureEnabled(WslaFeatureFlagsPmemVhds)) { @@ -306,8 +307,8 @@ void WSLAVirtualMachine::Start() return lun; }; - rootVhd.first = attachScsiDisk(m_settings.RootVhd.c_str()); - modulesVhd.first = attachScsiDisk(kernelModulesPath.c_str()); + rootVhd = attachScsiDisk(m_settings.RootVhd.c_str()); + modulesVhd = attachScsiDisk(kernelModulesPath.c_str()); } else { @@ -326,8 +327,8 @@ void WSLAVirtualMachine::Start() return std::format("/dev/pmem{}", deviceId); }; - rootVhd.second = attachPmemDisk(m_settings.RootVhd.c_str()); - modulesVhd.second = attachPmemDisk(kernelModulesPath.c_str()); + rootVhd = attachPmemDisk(m_settings.RootVhd.c_str()); + modulesVhd = attachPmemDisk(kernelModulesPath.c_str()); vmSettings.Devices.VirtualPMem = std::move(pmemController); } @@ -398,16 +399,20 @@ void WSLAVirtualMachine::Start() ConfigureNetworking(); // Configure mounts. - auto getVhdDevicePath = [&](const std::pair, std::optional>& vhd) { - WI_ASSERT(vhd.first.has_value() ^ vhd.second.has_value()); - if (vhd.first.has_value()) - { - return GetVhdDevicePath(vhd.first.value()); - } - else - { - return vhd.second.value(); - } + auto getVhdDevicePath = [&](const std::variant& vhd) { + return std::visit( + [&](auto&& arg) -> std::string { + using T = std::decay_t; + if constexpr (std::is_same_v) + { + return GetVhdDevicePath(arg); + } + else if constexpr (std::is_same_v) + { + return arg; + } + }, + vhd); }; Mount(m_initChannel, getVhdDevicePath(rootVhd).c_str(), "/mnt", m_settings.RootVhdType.c_str(), "ro", WSLAMountFlagsChroot | WSLAMountFlagsWriteableOverlayFs); From 7d56134f89c732905153a9b50b22182504d9e831 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 31 Dec 2025 19:01:08 +0000 Subject: [PATCH 3/5] Use overload set visitor for improved readability Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com> --- .../wslaservice/exe/WSLAVirtualMachine.cpp | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/windows/wslaservice/exe/WSLAVirtualMachine.cpp b/src/windows/wslaservice/exe/WSLAVirtualMachine.cpp index 50e4c69e8..373326936 100644 --- a/src/windows/wslaservice/exe/WSLAVirtualMachine.cpp +++ b/src/windows/wslaservice/exe/WSLAVirtualMachine.cpp @@ -400,19 +400,22 @@ void WSLAVirtualMachine::Start() // Configure mounts. auto getVhdDevicePath = [&](const std::variant& vhd) { - return std::visit( - [&](auto&& arg) -> std::string { - using T = std::decay_t; - if constexpr (std::is_same_v) - { - return GetVhdDevicePath(arg); - } - else if constexpr (std::is_same_v) - { - return arg; - } - }, - vhd); + struct Visitor + { + WSLAVirtualMachine* vm; + + std::string operator()(ULONG lun) const + { + return vm->GetVhdDevicePath(lun); + } + + std::string operator()(const std::string& path) const + { + return path; + } + }; + + return std::visit(Visitor{this}, vhd); }; Mount(m_initChannel, getVhdDevicePath(rootVhd).c_str(), "/mnt", m_settings.RootVhdType.c_str(), "ro", WSLAMountFlagsChroot | WSLAMountFlagsWriteableOverlayFs); From 04f1f781755ad3a7179ffc46862eda12aeb6caa6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 31 Dec 2025 19:02:13 +0000 Subject: [PATCH 4/5] Final code review completed Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com> --- _codeql_detected_source_root | 1 + 1 file changed, 1 insertion(+) create mode 120000 _codeql_detected_source_root diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root new file mode 120000 index 000000000..945c9b46d --- /dev/null +++ b/_codeql_detected_source_root @@ -0,0 +1 @@ +. \ No newline at end of file From 17f6e78fcf1179cdafad9f8bc649f42b47f260ce Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 31 Dec 2025 19:03:22 +0000 Subject: [PATCH 5/5] Remove CodeQL artifact and update gitignore Co-authored-by: benhillis <17727402+benhillis@users.noreply.github.com> --- .gitignore | 3 ++- _codeql_detected_source_root | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 120000 _codeql_detected_source_root diff --git a/.gitignore b/.gitignore index c2361092a..ad5b2ee10 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,5 @@ package/x64 tools/clang-format.exe /linux-crashes doc/site/ -directory.build.targets \ No newline at end of file +directory.build.targets +_codeql_detected_source_root \ No newline at end of file diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root deleted file mode 120000 index 945c9b46d..000000000 --- a/_codeql_detected_source_root +++ /dev/null @@ -1 +0,0 @@ -. \ No newline at end of file