Skip to content

Add configurable storage path for the default wslc session#40956

Open
benhillis wants to merge 7 commits into
masterfrom
user/benhill/wslc-default-session-storage-path
Open

Add configurable storage path for the default wslc session#40956
benhillis wants to merge 7 commits into
masterfrom
user/benhill/wslc-default-session-storage-path

Conversation

@benhillis

Copy link
Copy Markdown
Member

Summary

The default wslc CLI session always created its storage.vhdx under %LOCALAPPDATA%\wslc\sessions\<session>, which is a pain when the system drive is small. This adds a session.storagePath setting so users can redirect the default session's storage to another location (e.g. a larger data drive).

session:
  storagePath: D:\wslc

Resolves to D:\wslc\wslc\sessions\<session>\storage.vhdx, mirroring the existing layout. When the key is absent or set to default, behavior is unchanged (%LOCALAPPDATA%). Named (custom) sessions are unaffected, they already accept an explicit storage path.

Fixes #40953

Details

  • WSLCUserSettings.h / .cpp: new SessionStoragePath setting (session.storagePath), validated as a non-empty absolute path (relative/empty rejected, falls back to the default), plus a documented entry in the settings-file template.
  • WSLCSessionManager.cpp: SessionSettings::Default uses the configured base when set, otherwise %LOCALAPPDATA%. The downstream VHD plumbing was already path-driven, so no further wiring was needed.

Testing

  • New unit tests in WSLCCLISettingsUnitTests.cpp cover absent, absolute, default, and relative-rejected cases, plus the all-known-keys no-warning check.
  • Builds clean under /WX: common.lib, wslservice.exe, wslc.exe, wsltests.dll.
  • clang-format clean on all changed files.

Note: the validation only checks that the path is absolute; if the path is not writable by the user, session creation surfaces the underlying error at VHD-attach time (same as the existing custom-session path).

The default wslc CLI session always created its storage VHD under
%LOCALAPPDATA%\wslc\sessions, which is a problem when the system drive
is small. Add a `session.storagePath` setting (settings.yaml) that lets
users redirect the default session's storage to another location (e.g. a
larger data drive). The value must be an absolute path; relative/empty
values are rejected and fall back to %LOCALAPPDATA%. Named (custom)
sessions are unaffected since they already accept an explicit path.

Fixes #40953

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benhillis benhillis requested a review from a team as a code owner June 30, 2026 14:27
Copilot AI review requested due to automatic review settings June 30, 2026 14:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new session.storagePath user setting to allow redirecting the default wslc session’s storage location away from %LOCALAPPDATA%, while preserving the existing wslc\sessions\<session> layout under the configured base directory.

Changes:

  • Introduced session.storagePath in WSLCUserSettings (mapping + validation) and documented it in the settings template.
  • Updated default-session construction in WSLCSessionManager to use the configured storage base when present (otherwise %LOCALAPPDATA%).
  • Added unit tests covering absent/default/absolute/relative-invalid cases for the new setting.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/windows/wslc/WSLCCLISettingsUnitTests.cpp Adds unit tests for session.storagePath parsing/validation and updates the “all known keys” test input.
src/windows/service/exe/WSLCSessionManager.cpp Uses session.storagePath as the base for default session storage path resolution.
src/windows/common/WSLCUserSettings.h Adds the new setting enum entry and YAML path mapping for session.storagePath.
src/windows/common/WSLCUserSettings.cpp Documents session.storagePath in the settings template and validates it as a non-empty absolute path.

Comment thread src/windows/common/WSLCUserSettings.cpp Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dkbennett
dkbennett previously approved these changes Jun 30, 2026

@dkbennett dkbennett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Do we have any runtime validation for the storage path both existing and having correct permissions to be accessible to the user, or does that surface as a session error when we attempt to use it?

@OneBlue OneBlue left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to expose this as a configuration key ? One downside of doing this is that changing this path will essentially drop everything that the user has.

One alternative we considered was to tell users to symlink their storage folder instead. This has the benefit of explicitly requiring user action, and so the user can also move their storage while they're doing it

@benhillis

Copy link
Copy Markdown
Member Author

Do we want to expose this as a configuration key ? One downside of doing this is that changing this path will essentially drop everything that the user has.

One alternative we considered was to tell users to symlink their storage folder instead. This has the benefit of explicitly requiring user action, and so the user can also move their storage while they're doing it

Definitely one downside of this approach. I'm not a huge fan of the symlink approach. This one needs a little more UX thought but I think we really need to come up with a solution here.

OneBlue
OneBlue previously approved these changes Jun 30, 2026
Comment thread src/windows/common/WSLCUserSettings.cpp Outdated
@OneBlue

OneBlue commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Definitely one downside of this approach. I'm not a huge fan of the symlink approach. This one needs a little more UX thought but I think we really need to come up with a solution here.

I discussed this @dkbennett a bit and there's definitely downsides to both. I think this implementation is OK for now. If users modify the settings I think the storage being reset is a reasonable UX. We can refine later if needed

…session storage

Surfaces a one-time warning on default-session creation when session.storagePath is set and an existing session exists at the default %LOCALAPPDATA% location but not yet at the configured one, so users are not surprised by their previous session/containers/images not being migrated.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 30, 2026 20:47
@benhillis benhillis dismissed stale reviews from OneBlue and dkbennett via 9a2b4d3 June 30, 2026 20:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread src/windows/common/WSLCUserSettings.cpp Outdated
Ben Hillis and others added 2 commits June 30, 2026 14:26
Drop unneeded MultiByteToWide in the SessionStoragePath validator (std::filesystem::path constructs from std::string and is_absolute only inspects the root) and clarify the settings template to show the full per-session VHD path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
validate-localization.py enforces a canonical comment derived from auto-detected tokens; a manual {Locked=...} for a non-argument token (session.storagePath) diverges from the expected comment and fails CI. Use the canonical comment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 30, 2026 22:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread localization/strings/en-US/Resources.resw Outdated
Per PR review, the literal setting key should not be translated. Append a Locked token after the canonical comment so the validator canonical substring stays intact.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread src/windows/service/exe/WSLCSessionManager.cpp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Per PR feedback (dkbennett, benhillis), drop the default-vs-configured orphan detection. Warn once when creating a session VHD at a non-default storagePath, and document the orphan-on-change behavior in the settings template comment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make storage path for the default CLI session configurable

4 participants