-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Initial implementation for CreateContainer() #13791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1220fbe
0920c52
3d5fa8b
3a8a669
b8c5b8c
cff1cd2
29971ac
9c18826
cdf7c46
3b5c028
2a4f8d0
9dd34f2
292707e
0eda07f
e4822ba
987b1b7
a4ed4b2
ee948d5
08d5929
2c28e53
52aa7f8
9c5ed51
8d9e9cb
e786943
0760be6
70ac182
dcc0f5f
6d2831f
2c7c305
4acb3a4
61bca24
6fc68e8
912af10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| WSLAContainerLauncher.cpp | ||
|
|
||
| Abstract: | ||
|
|
||
| This file contains the implementation for WSLAContainerLauncher. | ||
|
|
||
| --*/ | ||
| #include "WSLAContainerLauncher.h" | ||
|
|
||
| using wsl::windows::common::ClientRunningWSLAProcess; | ||
| using wsl::windows::common::RunningWSLAContainer; | ||
| using wsl::windows::common::WSLAContainerLauncher; | ||
|
|
||
| RunningWSLAContainer::RunningWSLAContainer(wil::com_ptr<IWSLAContainer>&& Container, std::vector<WSLA_PROCESS_FD>&& fds) : | ||
| m_container(std::move(Container)), m_fds(std::move(fds)) | ||
| { | ||
| } | ||
|
|
||
| IWSLAContainer& RunningWSLAContainer::Get() | ||
| { | ||
| return *m_container; | ||
| } | ||
|
|
||
| WSLA_CONTAINER_STATE RunningWSLAContainer::State() | ||
| { | ||
| WSLA_CONTAINER_STATE state{}; | ||
| THROW_IF_FAILED(m_container->GetState(&state)); | ||
| return state; | ||
| } | ||
|
|
||
| ClientRunningWSLAProcess RunningWSLAContainer::GetInitProcess() | ||
| { | ||
| wil::com_ptr<IWSLAProcess> process; | ||
| THROW_IF_FAILED(m_container->GetInitProcess(&process)); | ||
|
|
||
| return ClientRunningWSLAProcess{std::move(process), std::move(m_fds)}; | ||
benhillis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| WSLAContainerLauncher::WSLAContainerLauncher( | ||
| const std::string& Image, | ||
OneBlue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const std::string& Name, | ||
| const std::string& EntryPoint, | ||
| const std::vector<std::string>& Arguments, | ||
| const std::vector<std::string>& Environment, | ||
| ProcessFlags Flags) : | ||
| WSLAProcessLauncher(EntryPoint, Arguments, Environment, Flags), m_image(Image), m_name(Name) | ||
| { | ||
| } | ||
|
|
||
| RunningWSLAContainer WSLAContainerLauncher::Launch(IWSLASession& Session) | ||
| { | ||
| WSLA_CONTAINER_OPTIONS options{}; | ||
| options.Image = m_image.c_str(); | ||
| options.Name = m_name.c_str(); | ||
| auto [processOptions, commandLinePtrs, environmentPtrs] = CreateProcessOptions(); | ||
| options.InitProcessOptions = processOptions; | ||
|
|
||
| if (m_executable.empty()) | ||
| { | ||
| options.InitProcessOptions.Executable = nullptr; | ||
| } | ||
|
|
||
| // TODO: Support volumes, ports, flags, shm size, container networking mode, etc. | ||
| wil::com_ptr<IWSLAContainer> container; | ||
| THROW_IF_FAILED(Session.CreateContainer(&options, &container)); | ||
|
|
||
| return RunningWSLAContainer{std::move(container), std::move(m_fds)}; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /*++ | ||
|
|
||
| Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| Module Name: | ||
|
|
||
| WSLAContainerLauncher.h | ||
|
|
||
| Abstract: | ||
|
|
||
| This file contains the definition for WSLAContainerLauncher. | ||
|
|
||
| --*/ | ||
|
|
||
| #pragma once | ||
| #include "WSLAProcessLauncher.h" | ||
|
|
||
| namespace wsl::windows::common { | ||
|
|
||
| class RunningWSLAContainer | ||
| { | ||
| public: | ||
| NON_COPYABLE(RunningWSLAContainer); | ||
| DEFAULT_MOVABLE(RunningWSLAContainer); | ||
| RunningWSLAContainer(wil::com_ptr<IWSLAContainer>&& Container, std::vector<WSLA_PROCESS_FD>&& fds); | ||
| IWSLAContainer& Get(); | ||
|
|
||
| WSLA_CONTAINER_STATE State(); | ||
| ClientRunningWSLAProcess GetInitProcess(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: It would be good to add a GetPid() either here or in ClientRunningWSLAProcess(). Otherwise, to get Container's entry process pid, we would be doing a RunningWSLAContainer->GetInitProcess()->Get()->GetPid(). Could do that in a followup PR, oc
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PID can be retrieved today RunningWSLAContainer.Get().GetPid(). We could add a convenience method to make it a bit easier though |
||
|
|
||
| private: | ||
| wil::com_ptr<IWSLAContainer> m_container; | ||
| std::vector<WSLA_PROCESS_FD> m_fds; | ||
| }; | ||
|
|
||
| class WSLAContainerLauncher : public WSLAProcessLauncher | ||
| { | ||
| public: | ||
| NON_COPYABLE(WSLAContainerLauncher); | ||
| NON_MOVABLE(WSLAContainerLauncher); | ||
|
|
||
| WSLAContainerLauncher( | ||
| const std::string& Image, | ||
| const std::string& Name, | ||
| const std::string& EntryPoint = "", | ||
| const std::vector<std::string>& Arguments = {}, | ||
| const std::vector<std::string>& Environment = {}, | ||
| ProcessFlags Flags = ProcessFlags::Stdout | ProcessFlags::Stderr); | ||
|
|
||
| void AddVolume(const std::string& HostPath, const std::string& ContainerPath, bool ReadOnly); | ||
| void AddPort(uint16_t WindowsPort, uint16_t ContainerPort, int Family); | ||
|
Comment on lines
+50
to
+51
|
||
|
|
||
| RunningWSLAContainer Launch(IWSLASession& Session); | ||
|
|
||
| private: | ||
| std::string m_image; | ||
| std::string m_name; | ||
| }; | ||
| } // namespace wsl::windows::common | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,7 +158,7 @@ ClientRunningWSLAProcess WSLAProcessLauncher::Launch(IWSLASession& Session) | |
| THROW_HR_MSG(hresult, "Failed to launch process: %hs (commandline: %hs). Errno = %i", m_executable.c_str(), commandLine.c_str(), error); | ||
| } | ||
|
|
||
| return process.value(); | ||
| return std::move(process.value()); | ||
|
||
| } | ||
|
|
||
| std::tuple<HRESULT, int, std::optional<ClientRunningWSLAProcess>> WSLAProcessLauncher::LaunchNoThrow(IWSLASession& Session) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,8 +29,10 @@ wil::unique_hfile wsl::core::filesystem::CreateFile( | |
|
|
||
| void wsl::core::filesystem::CreateVhd(_In_ LPCWSTR target, _In_ ULONGLONG maximumSize, _In_ PSID userSid, _In_ BOOL sparse, _In_ BOOL fixed) | ||
| { | ||
| WI_ASSERT(wsl::windows::common::string::IsPathComponentEqual( | ||
| std::filesystem::path{target}.extension().native(), windows::common::wslutil::c_vhdxFileExtension)); | ||
| THROW_HR_IF( | ||
| E_INVALIDARG, | ||
| !wsl::windows::common::string::IsPathComponentEqual( | ||
| std::filesystem::path{target}.extension().native(), windows::common::wslutil::c_vhdxFileExtension)); | ||
|
Comment on lines
+32
to
+35
|
||
|
|
||
| // Disable creation of sparse VHDs while data corruption is being debugged. | ||
| if (sparse) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition
DEFINED OFFICIAL_BUILDwas changed toOFFICIAL_BUILDwithout checking if it's defined first. IfOFFICIAL_BUILDis not defined, this will cause a CMake warning or error. The correct pattern should beif (NOT DEFINED OFFICIAL_BUILD OR NOT OFFICIAL_BUILD)or keep the originalif (NOT DEFINED OFFICIAL_BUILD ...)form.