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/src/windows/wslaservice/exe/WSLAVirtualMachine.cpp b/src/windows/wslaservice/exe/WSLAVirtualMachine.cpp index d5fc55747..373326936 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,23 @@ 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()) + auto getVhdDevicePath = [&](const std::variant& vhd) { + struct Visitor { - return GetVhdDevicePath(vhd.first.value()); - } - else - { - return vhd.second.value(); - } + 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);