| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | WSLCContainerMetadata.h |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | JSON schema for WSLC container metadata stored in Docker container labels. |
| 12 | This metadata allows WSLC to recover container state across service restarts. |
| 13 | |
| 14 | --*/ |
| 15 | |
| 16 | #pragma once |
| 17 | |
| 18 | #include "JsonUtils.h" |
| 19 | #include "wslc.h" |
| 20 | |
| 21 | namespace wsl::windows::service::wslc { |
| 22 | |
| 23 | // Label key used to store WSLC container metadata in Docker container labels. |
| 24 | constexpr auto WSLCContainerMetadataLabel = "com.microsoft.wsl.container.metadata"; |
| 25 | |
| 26 | struct WSLCPortMapping |
| 27 | { |
| 28 | uint16_t HostPort{}; |
| 29 | uint16_t VmPort{}; |
| 30 | uint16_t ContainerPort{}; |
| 31 | int Family{}; |
| 32 | int Protocol{}; |
| 33 | std::string BindingAddress; |
| 34 | |
| 35 | NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(WSLCPortMapping, HostPort, VmPort, ContainerPort, Family, Protocol, BindingAddress); |
| 36 | }; |
| 37 | |
| 38 | struct WSLCVolumeMount |
| 39 | { |
| 40 | std::wstring HostPath; |
| 41 | std::string ParentVMPath; |
| 42 | std::string ContainerPath; |
| 43 | bool ReadOnly{}; |
| 44 | |
| 45 | // Non-empty when the mount target is a single file rather than a directory. |
| 46 | std::wstring SourceFilename; |
| 47 | bool CreateSourceIfMissing{true}; |
| 48 | |
| 49 | // Runtime-only field. Not serialized to JSON. |
| 50 | bool Mounted{}; |
| 51 | |
| 52 | NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(WSLCVolumeMount, HostPath, ParentVMPath, ContainerPath, ReadOnly, SourceFilename, CreateSourceIfMissing); |
| 53 | }; |
| 54 | |
| 55 | struct WSLCContainerMetadataV1 |
| 56 | { |
| 57 | WSLCContainerFlags Flags{WSLCContainerFlagsNone}; |
| 58 | WSLCProcessFlags InitProcessFlags{WSLCProcessFlagsNone}; |
| 59 | std::vector<WSLCPortMapping> Ports; |
| 60 | std::vector<WSLCVolumeMount> Volumes; |
| 61 | |
| 62 | NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(WSLCContainerMetadataV1, Flags, InitProcessFlags, Ports, Volumes); |
| 63 | }; |
| 64 | |
| 65 | struct WSLCContainerMetadata |
| 66 | { |
| 67 | std::optional<WSLCContainerMetadataV1> V1; |
| 68 | NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(WSLCContainerMetadata, V1); |
| 69 | }; |
| 70 | |
| 71 | } // namespace wsl::windows::service::wslc |