Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ package/x64
tools/clang-format.exe
/linux-crashes
doc/site/
directory.build.targets
directory.build.targets
_codeql_detected_source_root
38 changes: 23 additions & 15 deletions src/windows/wslaservice/exe/WSLAVirtualMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Module Name:
#include "WSLAVirtualMachine.h"
#include <format>
#include <filesystem>
#include <variant>
#include "hcs_schema.h"
#include "VirtioNetworking.h"
#include "NatNetworking.h"
Expand Down Expand Up @@ -283,8 +284,8 @@ void WSLAVirtualMachine::Start()
#endif

// Initialize the boot VHDs.
std::pair<std::optional<ULONG>, std::optional<std::string>> rootVhd;
std::pair<std::optional<ULONG>, std::optional<std::string>> modulesVhd;
std::variant<ULONG, std::string> rootVhd;
std::variant<ULONG, std::string> modulesVhd;
hcs::Scsi scsiController{};
if (!FeatureEnabled(WslaFeatureFlagsPmemVhds))
{
Expand All @@ -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
{
Expand All @@ -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);
}

Expand Down Expand Up @@ -398,16 +399,23 @@ void WSLAVirtualMachine::Start()
ConfigureNetworking();

// Configure mounts.
auto getVhdDevicePath = [&](const std::pair<std::optional<ULONG>, std::optional<std::string>>& vhd) {
WI_ASSERT(vhd.first.has_value() ^ vhd.second.has_value());
if (vhd.first.has_value())
auto getVhdDevicePath = [&](const std::variant<ULONG, std::string>& 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);
Expand Down