Merge upstream WSLA changes and restore session ID support

This commit is contained in:
Beena352 2025-12-05 10:26:40 -08:00
parent b46de5880d
commit 692faed78e
4 changed files with 8 additions and 17 deletions

View File

@ -8,7 +8,7 @@ Module Name:
Abstract: Abstract:
TODO Entry point for the wsladiag tool, performs WSL runtime initialization and parses --list/--help.
--*/ --*/

View File

@ -24,10 +24,7 @@ using wsl::windows::service::wsla::WSLAVirtualMachine;
WSLASession::WSLASession(ULONG id, const WSLA_SESSION_SETTINGS& Settings, WSLAUserSessionImpl& userSessionImpl) : WSLASession::WSLASession(ULONG id, const WSLA_SESSION_SETTINGS& Settings, WSLAUserSessionImpl& userSessionImpl) :
m_id(id), m_id(id), m_sessionSettings(Settings), m_userSession(&userSessionImpl), m_displayName(Settings.DisplayName)
m_sessionSettings(Settings),
m_userSession(&userSessionImpl),
m_displayName(Settings.DisplayName)
{ {
WSL_LOG("SessionCreated", TraceLoggingValue(m_displayName.c_str(), "DisplayName")); WSL_LOG("SessionCreated", TraceLoggingValue(m_displayName.c_str(), "DisplayName"));
@ -185,12 +182,6 @@ void WSLASession::ConfigureStorage(const WSLA_SESSION_SETTINGS& Settings)
deleteVhdOnFailure.release(); deleteVhdOnFailure.release();
} }
HRESULT WSLASession::GetDisplayName(LPWSTR* DisplayName)
{
RETURN_HR_IF_NULL(E_POINTER, DisplayName);
return wil::make_cotaskmem_string_nothrow(m_displayName.c_str(), DisplayName);
}
void WSLASession::CopyDisplayName(_Out_writes_z_(bufferLength) PWSTR buffer, size_t bufferLength) const void WSLASession::CopyDisplayName(_Out_writes_z_(bufferLength) PWSTR buffer, size_t bufferLength) const
{ {
THROW_HR_IF(E_BOUNDS, m_displayName.size() + 1 > bufferLength); THROW_HR_IF(E_BOUNDS, m_displayName.size() + 1 > bufferLength);

View File

@ -27,7 +27,7 @@ WSLAUserSessionImpl::~WSLAUserSessionImpl()
// In case there are still COM references on sessions, signal that the user session is terminating // In case there are still COM references on sessions, signal that the user session is terminating
// so the sessions are all in a 'terminated' state. // so the sessions are all in a 'terminated' state.
{ {
std::lock_guard lock(m_lock); std::lock_guard lock(m_wslaSessionsLock);
for (auto& e : m_sessions) for (auto& e : m_sessions)
{ {
@ -38,7 +38,7 @@ WSLAUserSessionImpl::~WSLAUserSessionImpl()
void WSLAUserSessionImpl::OnSessionTerminated(WSLASession* Session) void WSLAUserSessionImpl::OnSessionTerminated(WSLASession* Session)
{ {
std::lock_guard lock(m_lock); std::lock_guard lock(m_wslaSessionsLock);
WI_VERIFY(m_sessions.erase(Session) == 1); WI_VERIFY(m_sessions.erase(Session) == 1);
} }
@ -51,7 +51,7 @@ HRESULT WSLAUserSessionImpl::CreateSession(const WSLA_SESSION_SETTINGS* Settings
{ {
ULONG id = m_nextSessionId++; ULONG id = m_nextSessionId++;
auto session = wil::MakeOrThrow<WSLASession>(id, *Settings, *this); auto session = wil::MakeOrThrow<WSLASession>(id, *Settings, *this);
std::lock_guard lock(m_wslaSessionsLock); std::lock_guard lock(m_wslaSessionsLock);
auto it = m_sessions.emplace(session.Get()); auto it = m_sessions.emplace(session.Get());
@ -65,7 +65,7 @@ HRESULT WSLAUserSessionImpl::CreateSession(const WSLA_SESSION_SETTINGS* Settings
HRESULT WSLAUserSessionImpl::OpenSessionByName(LPCWSTR DisplayName, IWSLASession** Session) HRESULT WSLAUserSessionImpl::OpenSessionByName(LPCWSTR DisplayName, IWSLASession** Session)
{ {
std::lock_guard lock(m_lock); std::lock_guard lock(m_wslaSessionsLock);
// TODO: ACL check // TODO: ACL check
// TODO: Check for duplicate on session creation. // TODO: Check for duplicate on session creation.
@ -83,7 +83,7 @@ HRESULT WSLAUserSessionImpl::OpenSessionByName(LPCWSTR DisplayName, IWSLASession
HRESULT wsl::windows::service::wsla::WSLAUserSessionImpl::ListSessions(_Out_ WSLA_SESSION_INFORMATION** Sessions, _Out_ ULONG* SessionsCount) HRESULT wsl::windows::service::wsla::WSLAUserSessionImpl::ListSessions(_Out_ WSLA_SESSION_INFORMATION** Sessions, _Out_ ULONG* SessionsCount)
{ {
std::lock_guard lock(m_lock); std::lock_guard lock(m_wslaSessionsLock);
auto output = wil::make_unique_cotaskmem<WSLA_SESSION_INFORMATION[]>(m_sessions.size()); auto output = wil::make_unique_cotaskmem<WSLA_SESSION_INFORMATION[]>(m_sessions.size());
size_t index = 0; size_t index = 0;

View File

@ -43,7 +43,7 @@ private:
wil::unique_tokeninfo_ptr<TOKEN_USER> m_tokenInfo; wil::unique_tokeninfo_ptr<TOKEN_USER> m_tokenInfo;
std::atomic<ULONG> m_nextSessionId{1}; std::atomic<ULONG> m_nextSessionId{1};
std::recursive_mutex m_lock; std::recursive_mutex m_wslaSessionsLock;
// TODO-WSLA: Consider using a weak_ptr to easily destroy when the last client reference is released. // TODO-WSLA: Consider using a weak_ptr to easily destroy when the last client reference is released.
std::unordered_set<WSLASession*> m_sessions; std::unordered_set<WSLASession*> m_sessions;