Initial prune image support in wslc service#40132
Initial prune image support in wslc service#40132yao-msft wants to merge 13 commits intofeature/wsl-for-appsfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds initial “image prune” support to the WSLC session API by plumbing a new COM method through WSLCSession into the Docker Engine /images/prune endpoint, and validating the behavior with new Windows tests.
Changes:
- Adds
IWSLCSession::PruneImagesalong with new IDL types/options/results for image pruning. - Implements image prune in
WSLCSessionandDockerHTTPClient, including Docker schema support for prune responses. - Adds a new
ImagePrunetest and a small RAII helper for freeing prune results.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/WSLCTests.cpp | Adds ImagePrune test coverage for prune behavior and error paths. |
| src/windows/wslcsession/WSLCSession.h | Declares the new PruneImages COM method on WSLCSession. |
| src/windows/wslcsession/WSLCSession.cpp | Implements WSLCSession::PruneImages, including filter translation and result marshaling. |
| src/windows/wslcsession/DockerHTTPClient.h | Adds prune filter struct and PruneImages method declaration. |
| src/windows/wslcsession/DockerHTTPClient.cpp | Implements POST /images/prune request with Docker filters query param. |
| src/windows/service/inc/wslc.idl | Introduces prune-related structs/enums and adds PruneImages to IWSLCSession. |
| src/windows/inc/docker_schema.h | Adds PruneImageResult schema used to parse Docker prune responses. |
| src/windows/common/wslutil.h | Adds ImagePruneResult RAII wrapper for WSLCPruneImagesResults. |
Comments suppressed due to low confidence (1)
src/windows/service/inc/wslc.idl:660
- Adding a new method to the existing COM interface IWSLCSession changes the vtable layout for all subsequent methods (e.g., CreateContainer and later), which is a binary-breaking change for any existing clients built against the previous IDL. To preserve COM ABI compatibility, add a new interface (e.g., IWSLCSession2 with a new IID) that extends IWSLCSession, and implement/query that from the session object instead of inserting methods into IWSLCSession.
// Image management.
HRESULT PullImage([in] LPCSTR Image, [in, unique] LPCSTR RegistryAuthenticationInformation, [in, unique] IProgressCallback* ProgressCallback);
HRESULT BuildImage([in] const WSLCBuildImageOptions* Options, [in, unique] IProgressCallback* ProgressCallback, [in, unique, system_handle(sh_event)] HANDLE CancelEvent);
HRESULT LoadImage([in] WSLCHandle ImageHandle, [in, unique] IProgressCallback* ProgressCallback, [in] ULONGLONG ContentLength);
HRESULT ImportImage([in] WSLCHandle ImageHandle, [in] LPCSTR ImageName, [in, unique] IProgressCallback* ProgressCallback, [in] ULONGLONG ContentLength);
HRESULT SaveImage([in] WSLCHandle OutputHandle, [in] LPCSTR ImageNameOrID, [in, unique] IProgressCallback * ProgressCallback, [in, unique, system_handle(sh_event)] HANDLE CancelEvent);
HRESULT ListImages([in, unique] const WSLCListImageOptions* Options, [out, size_is(, *Count)] WSLCImageInformation** Images, [out] ULONG* Count);
HRESULT DeleteImage([in] const WSLCDeleteImageOptions* Options, [out, size_is(, *Count)] WSLCDeletedImageInformation** DeletedImages, [out] ULONG* Count);
HRESULT TagImage([in] const WSLCTagImageOptions* Options);
HRESULT InspectImage([in] LPCSTR ImageNameOrId, [out] LPSTR* Output);
HRESULT PruneImages([in, unique] const WSLCPruneImagesOptions* Options, [out] WSLCPruneImagesResults* Result);
// Container management.
HRESULT CreateContainer([in] const WSLCContainerOptions* Options, [out] IWSLCContainer** Container);
HRESULT OpenContainer([in, ref] LPCSTR Id, [out] IWSLCContainer** Container);
HRESULT ListContainers([out, size_is(, *Count)] WSLCContainerEntry** Containers,
[out] ULONG* Count,
[out, size_is(, *PortsCount)] WSLCContainerPortMapping** Ports,
[out] ULONG* PortsCount);
HRESULT PruneContainers([in, unique, size_is(FiltersCount)] WSLCContainerPruneFilter* Filters, [in] DWORD FiltersCount, [in] ULONGLONG Until, [out] WSLCPruneContainersResults* Result);
OneBlue
left a comment
There was a problem hiding this comment.
Change looks good, minor comments
| if (Options != nullptr) | ||
| { | ||
| RETURN_HR_IF(E_INVALIDARG, WI_IsFlagSet(Options->Flags, WSLCPruneImagesFlagsDanglingTrue) && WI_IsFlagSet(Options->Flags, WSLCPruneImagesFlagsDanglingFalse)); | ||
| RETURN_HR_IF(E_INVALIDARG, WI_IsAnyFlagSet(static_cast<WSLCPruneImagesFlags>(Options->Flags), ~WSLCPruneImagesFlagsValid)); |
There was a problem hiding this comment.
PruneImages validates dangling flags and unknown bits, but it doesn't validate the Labels pointer/count relationship. If Options->LabelsCount > 0 while Options->Labels is nullptr, the call currently succeeds and silently ignores the requested filters. Please add an argument check (similar to ListImages) to reject this case (e.g., return E_INVALIDARG when LabelsCount > 0 && Labels == nullptr).
| RETURN_HR_IF(E_INVALIDARG, WI_IsAnyFlagSet(static_cast<WSLCPruneImagesFlags>(Options->Flags), ~WSLCPruneImagesFlagsValid)); | |
| RETURN_HR_IF(E_INVALIDARG, WI_IsAnyFlagSet(static_cast<WSLCPruneImagesFlags>(Options->Flags), ~WSLCPruneImagesFlagsValid)); | |
| RETURN_HR_IF(E_INVALIDARG, Options->LabelsCount > 0 && Options->Labels == nullptr); |
Summary of the Pull Request
Initial prune image support in wslc service
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed
Added tests.