master
h 119 lines 2.98 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 WSLCVhdVolume.h
8
9 Abstract:
10
11 Internal implementation for a VHD-backed volume.
12
13 --*/
14
15 #pragma once
16
17 #include "IWSLCVolume.h"
18 #include "WSLCVolumeMetadata.h"
19 #include "wslc.h"
20 #include <filesystem>
21 #include <memory>
22 #include <string>
23
24 namespace wsl::windows::common::docker_schema {
25 struct Volume;
26 }
27
28 namespace wsl::windows::service::wslc {
29
30 class WSLCVirtualMachine;
31 class DockerHTTPClient;
32
33 class WSLCVhdVolumeImpl : public IWSLCVolume
34 {
35 public:
36 NON_COPYABLE(WSLCVhdVolumeImpl);
37 NON_MOVABLE(WSLCVhdVolumeImpl);
38
39 WSLCVhdVolumeImpl(
40 std::string&& Name,
41 std::filesystem::path&& HostPath,
42 ULONGLONG SizeBytes,
43 ULONG Lun,
44 std::string&& VirtualMachinePath,
45 std::string&& CreatedAt,
46 std::string&& Mountpoint,
47 std::map<std::string, std::string>&& DriverOpts,
48 std::map<std::string, std::string>&& Labels,
49 WSLCVirtualMachine& VirtualMachine,
50 DockerHTTPClient& DockerClient,
51 bool Attached = true,
52 std::pair<HRESULT, std::string> Status = {S_OK, {}});
53
54 ~WSLCVhdVolumeImpl();
55
56 static std::unique_ptr<WSLCVhdVolumeImpl> Create(
57 _In_opt_ LPCSTR Name,
58 _In_ std::map<std::string, std::string>&& DriverOpts,
59 _In_ std::map<std::string, std::string>&& Labels,
60 _In_ const std::filesystem::path& StoragePath,
61 _In_ WSLCVirtualMachine& VirtualMachine,
62 _In_ DockerHTTPClient& DockerClient);
63
64 static std::unique_ptr<WSLCVhdVolumeImpl> Open(
65 _In_ const wsl::windows::common::docker_schema::Volume& Volume, _In_ WSLCVirtualMachine& VirtualMachine, _In_ DockerHTTPClient& DockerClient);
66
67 // IWSLCVolume
68 const std::string& Name() const noexcept override
69 {
70 return m_name;
71 }
72 const char* Driver() const noexcept override
73 {
74 return WSLCVhdVolumeDriver;
75 }
76 const std::map<std::string, std::string>& Labels() const noexcept override
77 {
78 return m_labels;
79 }
80 const std::string& Mountpoint() const noexcept override
81 {
82 return m_mountpoint;
83 }
84
85 std::pair<HRESULT, std::string> Status() const override
86 {
87 return m_status;
88 }
89
90 void Delete() override;
91 std::string Inspect() const override;
92 WSLCVolumeInformation GetVolumeInformation() const override;
93
94 const std::string& VirtualMachinePath() const noexcept
95 {
96 return m_virtualMachinePath;
97 }
98
99 void OnDeleted() override;
100
101 private:
102 void Detach();
103 std::string m_name;
104 std::filesystem::path m_hostPath;
105 std::string m_virtualMachinePath;
106 std::string m_createdAt;
107 std::string m_mountpoint;
108 std::map<std::string, std::string> m_driverOpts;
109 std::map<std::string, std::string> m_labels;
110 ULONGLONG m_sizeBytes{};
111 ULONG m_lun{};
112 WSLCVirtualMachine& m_virtualMachine;
113 DockerHTTPClient& m_dockerClient;
114 bool m_attached;
115
116 std::pair<HRESULT, std::string> m_status;
117 };
118
119 } // namespace wsl::windows::service::wslc