mirror of
https://github.com/microsoft/WSL.git
synced 2025-12-10 00:44:55 -06:00
more refactoring
This commit is contained in:
parent
bfc921c52d
commit
e2109c1f4f
@ -11,21 +11,15 @@ GuestDeviceManager::GuestDeviceManager(_In_ const std::wstring& machineId, _In_
|
||||
|
||||
_Requires_lock_not_held_(m_lock)
|
||||
GUID GuestDeviceManager::AddGuestDevice(
|
||||
_In_ const GUID& DeviceId, _In_ const GUID& ImplementationClsid, _In_ PCWSTR AccessName, _In_ PCWSTR Path, _In_ UINT32 Flags, _In_ HANDLE UserToken)
|
||||
_In_ const GUID& DeviceId, _In_ const GUID& ImplementationClsid, _In_ PCWSTR AccessName, _In_opt_ PCWSTR Options, _In_ PCWSTR Path, _In_ UINT32 Flags, _In_ HANDLE UserToken)
|
||||
{
|
||||
auto guestDeviceLock = m_lock.lock_exclusive();
|
||||
return AddHdvShareWithOptions(DeviceId, ImplementationClsid, AccessName, {}, Path, Flags, UserToken);
|
||||
return AddHdvShareWithOptions(DeviceId, ImplementationClsid, AccessName, Options, Path, Flags, UserToken);
|
||||
}
|
||||
|
||||
_Requires_lock_held_(m_lock)
|
||||
GUID GuestDeviceManager::AddHdvShareWithOptions(
|
||||
_In_ const GUID& DeviceId,
|
||||
_In_ const GUID& ImplementationClsid,
|
||||
_In_ std::wstring_view AccessName,
|
||||
_In_ std::wstring_view Options,
|
||||
_In_ std::wstring_view Path,
|
||||
_In_ UINT32 Flags,
|
||||
_In_ HANDLE UserToken)
|
||||
_In_ const GUID& DeviceId, _In_ const GUID& ImplementationClsid, _In_ PCWSTR AccessName, _In_opt_ PCWSTR Options, _In_ PCWSTR Path, _In_ UINT32 Flags, _In_ HANDLE UserToken)
|
||||
{
|
||||
wil::com_ptr<IPlan9FileSystem> server;
|
||||
|
||||
@ -33,7 +27,7 @@ GUID GuestDeviceManager::AddHdvShareWithOptions(
|
||||
// "name;key1=value1;key2=value2"
|
||||
// The AddSharePath implementation is responsible for separating them out and interpreting them.
|
||||
std::wstring nameWithOptions{AccessName};
|
||||
if (!Options.empty())
|
||||
if (ARGUMENT_PRESENT(Options))
|
||||
{
|
||||
nameWithOptions += L";";
|
||||
nameWithOptions += Options;
|
||||
@ -46,16 +40,14 @@ GUID GuestDeviceManager::AddHdvShareWithOptions(
|
||||
if (!server)
|
||||
{
|
||||
server = wil::CoCreateInstance<IPlan9FileSystem>(ImplementationClsid, (CLSCTX_LOCAL_SERVER | CLSCTX_ENABLE_CLOAKING | CLSCTX_ENABLE_AAA));
|
||||
AddRemoteFileSystem(ImplementationClsid, std::wstring(c_defaultDeviceTag).c_str(), server);
|
||||
AddRemoteFileSystem(ImplementationClsid, c_defaultDeviceTag.c_str(), server);
|
||||
}
|
||||
|
||||
const std::wstring SharePath(Path);
|
||||
THROW_IF_FAILED(server->AddSharePath(nameWithOptions.c_str(), SharePath.c_str(), Flags));
|
||||
THROW_IF_FAILED(server->AddSharePath(nameWithOptions.c_str(), Path, Flags));
|
||||
}
|
||||
|
||||
// This requires more privileges than the user may have, so impersonation is disabled.
|
||||
const std::wstring VirtioTag(AccessName);
|
||||
return AddNewDevice(DeviceId, server, VirtioTag.c_str());
|
||||
return AddNewDevice(DeviceId, server, AccessName);
|
||||
}
|
||||
|
||||
GUID GuestDeviceManager::AddNewDevice(_In_ const GUID& deviceId, _In_ const wil::com_ptr<IPlan9FileSystem>& server, _In_ PCWSTR tag)
|
||||
|
||||
@ -14,7 +14,7 @@ DEFINE_GUID(VIRTIO_VIRTIOFS_DEVICE_ID, 0x872270E1, 0xA899, 0x4AF6, 0xB4, 0x54, 0
|
||||
// {ABB755FC-1B86-4255-83E2-E5787ABCF6C2}
|
||||
DEFINE_GUID(VIRTIO_PMEM_CLASS_ID, 0xABB755FC, 0x1B86, 0x4255, 0x83, 0xe2, 0xe5, 0x78, 0x7a, 0xbc, 0xf6, 0xc2);
|
||||
|
||||
inline constexpr std::wstring_view c_defaultDeviceTag = L"default";
|
||||
inline const std::wstring c_defaultDeviceTag = L"default";
|
||||
|
||||
//
|
||||
// Provides synchronized access to guest device operations.
|
||||
@ -25,15 +25,12 @@ public:
|
||||
GuestDeviceManager(_In_ const std::wstring& machineId, _In_ const GUID& runtimeId);
|
||||
|
||||
_Requires_lock_not_held_(m_lock)
|
||||
GUID AddGuestDevice(_In_ const GUID& DeviceId, _In_ const GUID& ImplementationClsid, _In_ PCWSTR AccessName, _In_ PCWSTR Path, _In_ UINT32 Flags, _In_ HANDLE UserToken);
|
||||
|
||||
_Requires_lock_held_(m_lock)
|
||||
GUID AddHdvShareWithOptions(
|
||||
GUID AddGuestDevice(
|
||||
_In_ const GUID& DeviceId,
|
||||
_In_ const GUID& ImplementationClsid,
|
||||
_In_ std::wstring_view AccessName,
|
||||
_In_ std::wstring_view Options,
|
||||
_In_ std::wstring_view Path,
|
||||
_In_ PCWSTR AccessName,
|
||||
_In_opt_ PCWSTR Options,
|
||||
_In_ PCWSTR Path,
|
||||
_In_ UINT32 Flags,
|
||||
_In_ HANDLE UserToken);
|
||||
|
||||
@ -43,6 +40,21 @@ public:
|
||||
|
||||
void AddSharedMemoryDevice(_In_ const GUID& ImplementationClsid, _In_ PCWSTR Tag, _In_ PCWSTR Path, _In_ UINT32 SizeMb, _In_ HANDLE UserToken);
|
||||
|
||||
wil::com_ptr<IPlan9FileSystem> GetRemoteFileSystem(_In_ REFCLSID clsid, _In_ std::wstring_view tag);
|
||||
|
||||
void Shutdown();
|
||||
|
||||
private:
|
||||
_Requires_lock_held_(m_lock)
|
||||
GUID AddHdvShareWithOptions(
|
||||
_In_ const GUID& DeviceId,
|
||||
_In_ const GUID& ImplementationClsid,
|
||||
_In_ PCWSTR AccessName,
|
||||
_In_opt_ PCWSTR Options,
|
||||
_In_ PCWSTR Path,
|
||||
_In_ UINT32 Flags,
|
||||
_In_ HANDLE UserToken);
|
||||
|
||||
struct DirectoryObjectLifetime
|
||||
{
|
||||
std::wstring Path;
|
||||
@ -53,11 +65,6 @@ public:
|
||||
|
||||
DirectoryObjectLifetime CreateSectionObjectRoot(_In_ std::wstring_view RelativeRootPath, _In_ HANDLE UserToken) const;
|
||||
|
||||
wil::com_ptr<IPlan9FileSystem> GetRemoteFileSystem(_In_ REFCLSID clsid, _In_ std::wstring_view tag);
|
||||
|
||||
void Shutdown();
|
||||
|
||||
private:
|
||||
wil::srwlock m_lock;
|
||||
std::wstring m_machineId;
|
||||
wil::com_ptr<DeviceHostProxy> m_deviceHostSupport;
|
||||
|
||||
@ -72,7 +72,7 @@ try
|
||||
|
||||
// Add virtio net adapter to guest
|
||||
m_adapterId = m_guestDeviceManager->AddGuestDevice(
|
||||
c_virtioNetworkDeviceId, c_virtioNetworkClsid, L"eth0", device_options.str().c_str(), 0, m_userToken.get());
|
||||
c_virtioNetworkDeviceId, c_virtioNetworkClsid, L"eth0", nullptr, device_options.str().c_str(), 0, m_userToken.get());
|
||||
|
||||
hns::HNSEndpoint endpointProperties;
|
||||
endpointProperties.ID = m_adapterId;
|
||||
@ -122,6 +122,7 @@ void VirtioNetworking::SetupLoopbackDevice()
|
||||
c_virtioNetworkDeviceId,
|
||||
c_virtioNetworkClsid,
|
||||
c_loopbackDeviceName,
|
||||
nullptr,
|
||||
L"client_ip=127.0.0.1;client_mac=00:11:22:33:44:55",
|
||||
0,
|
||||
m_userToken.get());
|
||||
|
||||
@ -2063,7 +2063,7 @@ WslCoreVm::MountFileAsPersistentMemory(_In_ PCWSTR FilePath, _In_ bool ReadOnly)
|
||||
// (in which case there's no need to remove the device).
|
||||
{
|
||||
(void)m_guestDeviceManager->AddGuestDevice(
|
||||
VIRTIO_PMEM_DEVICE_ID, VIRTIO_PMEM_CLASS_ID, L"", FilePath, static_cast<UINT32>(flags), m_userToken.get());
|
||||
VIRTIO_PMEM_DEVICE_ID, VIRTIO_PMEM_CLASS_ID, L"", nullptr, FilePath, static_cast<UINT32>(flags), m_userToken.get());
|
||||
}
|
||||
|
||||
// Wait for the pmem device to appear in the VM at /dev/pmemX. Guess the value of X given the
|
||||
@ -2144,8 +2144,14 @@ std::wstring WslCoreVm::AddVirtioFsShare(_In_ bool Admin, _In_ PCWSTR Path, _In_
|
||||
tag += std::to_wstring(m_virtioFsShares.size());
|
||||
WI_ASSERT(!FindVirtioFsShare(tag.c_str(), Admin));
|
||||
|
||||
(void)m_guestDeviceManager->AddHdvShareWithOptions(
|
||||
VIRTIO_VIRTIOFS_DEVICE_ID, Admin ? c_virtiofsAdminClassId : c_virtiofsClassId, tag, key.OptionsString(), sharePath, VIRTIO_FS_FLAGS_TYPE_FILES, UserToken);
|
||||
(void)m_guestDeviceManager->AddGuestDevice(
|
||||
VIRTIO_VIRTIOFS_DEVICE_ID,
|
||||
Admin ? c_virtiofsAdminClassId : c_virtiofsClassId,
|
||||
tag.c_str(),
|
||||
key.OptionsString().c_str(),
|
||||
sharePath.c_str(),
|
||||
VIRTIO_FS_FLAGS_TYPE_FILES,
|
||||
UserToken);
|
||||
|
||||
m_virtioFsShares.emplace(std::move(key), tag);
|
||||
created = true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user