Add volume listing and pruning functionality#40457
Draft
kvega005 wants to merge 14 commits intomicrosoft:masterfrom
Draft
Add volume listing and pruning functionality#40457kvega005 wants to merge 14 commits intomicrosoft:masterfrom
kvega005 wants to merge 14 commits intomicrosoft:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends WSLC volume management by adding filterable volume listing and implementing volume pruning via Docker’s /volumes/prune API, with corresponding plumbing through the session/service layers and new test coverage.
Changes:
- Added
WSLCListVolumesOptions+ flags and updatedListVolumesto support driver/name/label filters. - Implemented
PruneVolumesend-to-end (session → volumes layer → Docker HTTP client), returning deleted volume names and reclaimed space. - Added/updated Windows tests validating list filters, pruning behavior, and related label-filter handling.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| test/windows/WSLCTests.cpp | Adds helpers plus new tests for volume list filtering and pruning; updates label-filter expectations. |
| src/windows/wslcsession/WSLCVolumes.h | Updates ListVolumes signature and introduces PruneVolumesResult / PruneVolumes. |
| src/windows/wslcsession/WSLCVolumes.cpp | Implements filtering logic for listing and a new prune flow that syncs with Docker prune results. |
| src/windows/wslcsession/WSLCVhdVolume.h | Exposes volume labels through the IWSLCVolume interface. |
| src/windows/wslcsession/WSLCGuestVolume.h | Exposes volume labels through the IWSLCVolume interface. |
| src/windows/wslcsession/IWSLCVolume.h | Extends the volume interface with Labels() to support filtering. |
| src/windows/wslcsession/WSLCSession.h | Updates session COM method signatures for volume list/prune. |
| src/windows/wslcsession/WSLCSession.cpp | Wires options through ListVolumes and implements PruneVolumes COM method; tightens label validation. |
| src/windows/wslcsession/DockerHTTPClient.h | Adds prune-volumes filters struct and new PruneVolumes API. |
| src/windows/wslcsession/DockerHTTPClient.cpp | Extends prune filter JSON generation to support all; implements /volumes/prune request. |
| src/windows/wslc/services/VolumeService.cpp | Updates service-side listing call to pass the new optional options pointer. |
| src/windows/service/inc/wslc.idl | Adds list-volume options/flags and changes IWSLCSession method signatures for list/prune volumes. |
| src/windows/inc/docker_schema.h | Adds Docker schema model for volume prune response. |
Comment on lines
1547
to
1555
| for (ULONG i = 0; i < Options->LabelsCount; ++i) | ||
| { | ||
| const auto& filter = Options->Labels[i]; | ||
| RETURN_HR_IF_NULL(E_POINTER, filter.Key); | ||
| RETURN_HR_IF_NULL(E_POINTER, filter.Value); | ||
|
|
||
| std::string labelFilter = filter.Key; | ||
| if (filter.Value != nullptr) | ||
| if (filter.Value[0] != '\0') | ||
| { |
Comment on lines
1788
to
1799
| if (FiltersCount > 0) | ||
| { | ||
| THROW_HR_IF(E_POINTER, FiltersCount > 0 && Filters == nullptr); | ||
|
|
||
| for (DWORD i = 0; i < FiltersCount; ++i) | ||
| { | ||
| THROW_HR_IF_MSG(E_POINTER, Filters[i].Key == nullptr, "Filter key cannot be null (index %lu)", i); | ||
| THROW_HR_IF_MSG(E_POINTER, Filters[i].Value == nullptr, "Filter value cannot be null (index %lu)", i); | ||
| std::string labelFilter = Filters[i].Key; | ||
|
|
||
| if (Filters[i].Value != nullptr) | ||
| if (Filters[i].Value[0] != '\0') | ||
| { |
Comment on lines
+296
to
+302
| it->second->OnDeleted(); | ||
| } | ||
| CATCH_LOG_MSG("Failed to release host resources for pruned volume: %hs", name.c_str()); | ||
|
|
||
| m_volumes.erase(it); | ||
| m_expectedEvents.emplace_back(name, VolumeEvent::Destroy); | ||
| result.Deleted.push_back(name); |
Comment on lines
766
to
770
| // Volume management. | ||
| HRESULT CreateVolume([in] const WSLCVolumeOptions* Options, [out] WSLCVolumeInformation* VolumeInfo); | ||
| HRESULT DeleteVolume([in] LPCSTR Name); | ||
| HRESULT ListVolumes([out, size_is(, *Count)] WSLCVolumeInformation** Volumes, [out] ULONG* Count); | ||
| HRESULT ListVolumes([in, unique] const WSLCListVolumesOptions* Options, [out, size_is(, *Count)] WSLCVolumeInformation** Volumes, [out] ULONG* Count); | ||
| HRESULT InspectVolume([in] LPCSTR Name, [out] LPSTR* Output); |
Comment on lines
772
to
775
| HRESULT Authenticate([in] LPCSTR ServerAddress, [in] LPCSTR Username, [in] LPCSTR Password, [out] LPSTR* IdentityToken); | ||
| HRESULT PushImage([in] LPCSTR Image, [in] LPCSTR RegistryAuthenticationInformation, [in, unique] IProgressCallback* ProgressCallback); | ||
| HRESULT PruneVolumes([in, unique] const WSLCPruneVolumesOptions* Options, [out] WSLCPruneVolumesResults* Results); | ||
| HRESULT PruneVolumes([in, unique] const WSLCPruneVolumesOptions* Options, [out, size_is(, *VolumesCount)] WSLCVolumeName** Volumes, [out] ULONG* VolumesCount, [out] ULONGLONG* SpaceReclaimed); | ||
|
|
| CATCH_LOG_MSG("Failed to release host resources for pruned volume: %hs", name.c_str()); | ||
|
|
||
| m_volumes.erase(it); | ||
| m_expectedEvents.emplace_back(name, VolumeEvent::Destroy); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
WSLCListVolumesOptionsto include filtering options for volume listing, such as driver name, volume name, and labels.ListVolumesmethod to accept filtering options and return volumes based on specified criteria.PruneVolumesmethod inWSLCVolumesto prune unused volumes based on user-defined filters.PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed