| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | WSLCVolumes.h |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | Contains the definition for WSLCVolumes. |
| 12 | |
| 13 | --*/ |
| 14 | |
| 15 | #pragma once |
| 16 | |
| 17 | #include "IWSLCVolume.h" |
| 18 | #include "WSLCVolumeMetadata.h" |
| 19 | #include "DockerHTTPClient.h" |
| 20 | #include "DockerEventTracker.h" |
| 21 | #include <wslc_schema.h> |
| 22 | |
| 23 | namespace wsl::windows::service::wslc { |
| 24 | |
| 25 | class WSLCVirtualMachine; |
| 26 | |
| 27 | class WSLCVolumes |
| 28 | { |
| 29 | public: |
| 30 | NON_COPYABLE(WSLCVolumes); |
| 31 | NON_MOVABLE(WSLCVolumes); |
| 32 | |
| 33 | WSLCVolumes(DockerHTTPClient& dockerClient, WSLCVirtualMachine& virtualMachine, DockerEventTracker& eventTracker, const std::filesystem::path& storagePath); |
| 34 | ~WSLCVolumes() = default; |
| 35 | |
| 36 | WSLCVolumeInformation CreateVolume( |
| 37 | _In_opt_ LPCSTR Name, |
| 38 | _In_opt_ LPCSTR Driver, |
| 39 | _In_ std::map<std::string, std::string>&& DriverOpts, |
| 40 | _In_ std::map<std::string, std::string>&& Labels); |
| 41 | |
| 42 | void DeleteVolume(_In_ LPCSTR Name); |
| 43 | |
| 44 | std::vector<wsl::windows::common::wslc_schema::VolumeListEntry> ListVolumes(std::map<std::string, std::vector<std::string>>&& Filters) const; |
| 45 | |
| 46 | struct PruneVolumesResult |
| 47 | { |
| 48 | std::vector<std::string> Volumes; |
| 49 | std::uint64_t SpaceReclaimed{}; |
| 50 | }; |
| 51 | |
| 52 | PruneVolumesResult PruneVolumes(_In_ const std::map<std::string, std::vector<std::string>>& Filters); |
| 53 | |
| 54 | std::string InspectVolume(_In_ const std::string& Name) const; |
| 55 | |
| 56 | std::pair<HRESULT, std::string> GetVolumeStatus(_In_ const std::string& Name) const; |
| 57 | |
| 58 | private: |
| 59 | __requires_lock_held(m_lock) void OpenVolumeExclusiveLockHeld(const wsl::windows::common::docker_schema::Volume& vol); |
| 60 | __requires_lock_held(m_lock) void OpenVolumeExclusiveLockHeld(const std::string& volumeName); |
| 61 | __requires_lock_held(m_lock) void OnVolumeDeletedExclusiveLockHeld(const std::string& volumeName); |
| 62 | |
| 63 | void OnVolumeEvent(const std::string& volumeName, VolumeEvent event, std::int64_t eventTime); |
| 64 | |
| 65 | mutable wil::srwlock m_lock; |
| 66 | _Guarded_by_(m_lock) std::unordered_map<std::string, std::unique_ptr<IWSLCVolume>> m_volumes; |
| 67 | _Guarded_by_(m_lock) std::deque<std::pair<std::string, VolumeEvent>> m_expectedEvents; |
| 68 | |
| 69 | DockerHTTPClient& m_dockerClient; |
| 70 | WSLCVirtualMachine& m_virtualMachine; |
| 71 | std::filesystem::path m_storagePath; |
| 72 | DockerEventTracker::EventTrackingReference m_volumeEventTracking; |
| 73 | }; |
| 74 | |
| 75 | } // namespace wsl::windows::service::wslc |