Skip to content

Implement SDK inspect and VHD management#14545

Open
JohnMcPMS wants to merge 10 commits intomicrosoft:feature/wsl-for-appsfrom
JohnMcPMS:sdk-autre
Open

Implement SDK inspect and VHD management#14545
JohnMcPMS wants to merge 10 commits intomicrosoft:feature/wsl-for-appsfrom
JohnMcPMS:sdk-autre

Conversation

@JohnMcPMS
Copy link
Copy Markdown
Member

@JohnMcPMS JohnMcPMS commented Mar 26, 2026

Summary of the Pull Request

Implements WslcInspectContainer and WslcCreateSessionVhd; adds WslcSetContainerSettingsNamedVolumes so that the VHDs are useful.

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

WslcInspectContainer is a straightforward pass-through.

WslcCreateSessionVhd WslcCreateSessionVhdVolume was also relatively straightforward, except it required adding a name to the existing VHD struct. Fixed VHDs cannot be requested via the runtime API currently, so attempting to use them is an error. If we never plan to allow them I can simply remove the option.

In order to actually use the created VHD, I had to add WslcSetContainerSettingsNamedVolumes so that they could be mounted in a container. This is basically a copy of the Windows <-> container volume setting with the Windows path replaced by the VHD name. And to enable removal, WslcDeleteSessionVhdVolume was added.

Validation Steps Performed

Tests added for inspect and VHD creation/use.

@JohnMcPMS JohnMcPMS requested a review from a team as a code owner March 26, 2026 18:54
Copilot AI review requested due to automatic review settings March 26, 2026 18:54
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR expands the WSLC SDK’s container/session storage capabilities by implementing container inspection, session VHD-backed volume creation, and support for mounting those named volumes into containers.

Changes:

  • Implement WslcInspectContainer by calling the underlying WSLA container Inspect() API and returning the JSON payload.
  • Implement WslcCreateSessionVhd to create VHD-backed named volumes via the underlying session volume APIs.
  • Add WslcSetContainerSettingsNamedVolumes to pass named session volumes through to container creation options, plus SDK tests covering inspect and VHD creation/mounting.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/windows/WslcSdkTests.cpp Adds SDK tests validating container inspect output and VHD-backed named volume creation + mounting.
src/windows/WslcSDK/wslcsdk.h Updates public SDK surface: struct size constants, new named-volume APIs/types, and WslcInspectContainer signature change.
src/windows/WslcSDK/wslcsdk.def Exports the new WslcSetContainerSettingsNamedVolumes API.
src/windows/WslcSDK/wslcsdk.cpp Implements WslcInspectContainer, WslcCreateSessionVhd, and named-volume handling during container creation.
src/windows/WslcSDK/WslcsdkPrivate.h Extends internal container options layout to carry named volume settings and updates size/alignment asserts.

Copilot AI review requested due to automatic review settings March 27, 2026 16:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 5 out of 5 changed files in this pull request and generated 6 comments.

Copilot AI review requested due to automatic review settings March 27, 2026 21:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 5 out of 5 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

src/windows/WslcSDK/wslcsdk.h:41

  • Bumping WSLC_SESSION_OPTIONS_SIZE / WSLC_CONTAINER_OPTIONS_SIZE changes the required size of the opaque settings structs. Any client binary built against the old header but running against the new DLL would pass smaller buffers, leading to out-of-bounds reads/writes when the DLL reinterprets the struct. If cross-version binary compatibility matters for this SDK, consider adding an explicit size/version field (or _Init functions that validate an incoming size) or versioning the DLL so mismatches are detectable.
// Session values
#define WSLC_SESSION_OPTIONS_SIZE 80
#define WSLC_SESSION_OPTIONS_ALIGNMENT 8

typedef struct WslcSessionSettings
{
    __declspec(align(WSLC_SESSION_OPTIONS_ALIGNMENT)) BYTE _opaque[WSLC_SESSION_OPTIONS_SIZE];
} WslcSessionSettings;

DECLARE_HANDLE(WslcSession);

// Container values
#define WSLC_CONTAINER_OPTIONS_SIZE 96
#define WSLC_CONTAINER_OPTIONS_ALIGNMENT 8

typedef struct WslcContainerSettings
{
    __declspec(align(WSLC_CONTAINER_OPTIONS_ALIGNMENT)) BYTE _opaque[WSLC_CONTAINER_OPTIONS_SIZE];
} WslcContainerSettings;

src/windows/WslcSDK/wslcsdk.cpp:447

  • WslcSetSessionSettingsVhd treats a null vhdRequirements pointer as “clear” by assigning an all-zero WslcVhdRequirements. That sets sizeInBytes=0, and WslcCreateSession then passes MaximumStorageSizeMb=0 to the runtime, which later attempts to create a 0-byte storage.vhdx (WSLCSession.cpp multiplies by _1MB). Consider making nullptr a no-op, or resetting to the same defaults as WslcInitSessionSettings (default size + dynamic type), rather than zeroing the requirements.
    if (vhdRequirements)
    {
        RETURN_HR_IF(E_INVALIDARG, vhdRequirements->sizeInBytes == 0);
        RETURN_HR_IF(E_NOTIMPL, vhdRequirements->type != WSLC_VHD_TYPE_DYNAMIC);

        internalType->vhdRequirements = *vhdRequirements;
    }
    else
    {
        internalType->vhdRequirements = {};
    }

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.

3 participants