Skip to content

Add volume listing and pruning functionality#40457

Draft
kvega005 wants to merge 14 commits intomicrosoft:masterfrom
kvega005:VolumeListAndPrune
Draft

Add volume listing and pruning functionality#40457
kvega005 wants to merge 14 commits intomicrosoft:masterfrom
kvega005:VolumeListAndPrune

Conversation

@kvega005
Copy link
Copy Markdown
Contributor

@kvega005 kvega005 commented May 7, 2026

Summary of the Pull Request

  • Updated WSLCListVolumesOptions to include filtering options for volume listing, such as driver name, volume name, and labels.
  • Modified ListVolumes method to accept filtering options and return volumes based on specified criteria.
  • Implemented PruneVolumes method in WSLCVolumes to prune unused volumes based on user-defined filters.
  • Enhanced Docker HTTP client to support volume pruning requests.
  • Updated interfaces and implementations across various components to accommodate new volume management features.
  • Added tests to validate the new volume listing and pruning functionalities, ensuring correct behavior with various filters and conditions.

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

Validation Steps Performed

Copilot AI review requested due to automatic review settings May 7, 2026 23:42
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 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 updated ListVolumes to support driver/name/label filters.
  • Implemented PruneVolumes end-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 thread src/windows/service/inc/wslc.idl
Comment thread src/windows/wslcsession/WSLCSession.h
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 thread src/windows/wslcsession/WSLCVolumes.cpp Outdated
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 thread src/windows/wslcsession/WSLCVolumes.cpp
Copilot AI review requested due to automatic review settings May 8, 2026 00:20
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 13 out of 13 changed files in this pull request and generated 4 comments.

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);
Comment thread src/windows/wslcsession/IWSLCVolume.h
@kvega005 kvega005 marked this pull request as ready for review May 8, 2026 17:15
@kvega005 kvega005 requested a review from a team as a code owner May 8, 2026 17:15
@kvega005 kvega005 marked this pull request as draft May 8, 2026 18:29
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.

2 participants