-
Notifications
You must be signed in to change notification settings - Fork 736
feature/hyperv-api-backend: HCS/HCN/virtdisk API wrapper implementation #4079
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 25 commits
0fabed9
7232028
fd2800d
51eeeb8
c02a402
4e31987
feb1b26
f27fb00
1d88683
83c7209
4258184
a064155
de8aaac
04e1da1
00d345c
1deb854
abb1b62
aed777f
69c9700
525d6ba
3497b6c
2597a3f
6ecb885
b705973
f473102
c02b482
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,57 @@ | ||
| # Copyright (C) Canonical, Ltd. | ||
| # | ||
| # This program is free software: you can redistribute it and/or modify | ||
| # it under the terms of the GNU General Public License version 3 as | ||
| # published by the Free Software Foundation. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| # | ||
|
|
||
| if(WIN32) | ||
|
|
||
| include(CheckCXXSourceRuns) | ||
|
|
||
| macro(check_pragma_lib LIB_NAME HEADER_NAME OUT_VAR) | ||
| check_cxx_source_runs(" | ||
| #pragma comment(lib, \"${LIB_NAME}\") | ||
| #define WIN32_LEAN_AND_MEAN | ||
| #include <windows.h> | ||
| #include <${HEADER_NAME}> | ||
| int main(void){ return 0; } | ||
| " ${OUT_VAR}) | ||
| endmacro() | ||
|
|
||
| check_pragma_lib("computecore.lib" "computecore.h" HAS_COMPUTECORE) | ||
| check_pragma_lib("computenetwork.lib" "computenetwork.h" HAS_COMPUTENETWORK) | ||
| check_pragma_lib("virtdisk.lib" "virtdisk.h" HAS_VIRTDISK) | ||
|
|
||
| if(NOT (HAS_COMPUTECORE AND HAS_COMPUTENETWORK AND HAS_VIRTDISK)) | ||
| message(FATAL_ERROR | ||
| "[hyperv_api] One or more required libraries are missing:\n" | ||
| " HAS_COMPUTECORE_LIB=${HAS_COMPUTECORE_LIB}\n" | ||
| " HAS_COMPUTENETWORK_LIB=${HAS_COMPUTENETWORK_LIB}\n" | ||
| " HAS_VIRTDISK_LIB=${HAS_VIRTDISK_LIB}\n" | ||
| ) | ||
| endif() | ||
|
|
||
| add_library(hyperv_api_backend STATIC | ||
| hyperv_api_common.cpp | ||
| hcn/hyperv_hcn_api_wrapper.cpp | ||
| hcs/hyperv_hcs_api_wrapper.cpp | ||
| virtdisk/virtdisk_api_wrapper.cpp | ||
| ) | ||
|
|
||
| target_link_libraries(hyperv_api_backend PRIVATE | ||
| fmt::fmt-header-only | ||
| utils | ||
| computecore.lib | ||
| computenetwork.lib | ||
| virtdisk.lib | ||
| ) | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,88 @@ | ||||||
| /* | ||||||
| * Copyright (C) Canonical, Ltd. | ||||||
| * | ||||||
| * This program is free software; you can redistribute it and/or modify | ||||||
| * it under the terms of the GNU General Public License as published by | ||||||
| * the Free Software Foundation; version 3. | ||||||
| * | ||||||
| * This program is distributed in the hope that it will be useful, | ||||||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||
| * GNU General Public License for more details. | ||||||
| * | ||||||
| * You should have received a copy of the GNU General Public License | ||||||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||
| * | ||||||
| */ | ||||||
|
|
||||||
| #ifndef MULTIPASS_HYPERV_API_HCN_API_TABLE | ||||||
| #define MULTIPASS_HYPERV_API_HCN_API_TABLE | ||||||
Sploder12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| // clang-format off | ||||||
| // (xmkg): clang-format is messing with the include order. | ||||||
| #include <windows.h> | ||||||
| #include <computenetwork.h> | ||||||
| #include <objbase.h> // for CoTaskMemFree | ||||||
| // clang-format on | ||||||
|
|
||||||
| #include <fmt/format.h> | ||||||
| #include <functional> | ||||||
|
|
||||||
| namespace multipass::hyperv::hcn | ||||||
| { | ||||||
|
|
||||||
| /** | ||||||
| * API function table for the Host Compute Network API | ||||||
| */ | ||||||
| struct HCNAPITable | ||||||
| { | ||||||
| // @ref https://learn.microsoft.com/en-us/virtualization/api/hcn/reference/hcncreatenetwork | ||||||
| std::function<decltype(HcnCreateNetwork)> CreateNetwork = &HcnCreateNetwork; | ||||||
| // @ref https://learn.microsoft.com/en-us/virtualization/api/hcn/reference/hcnopennetwork | ||||||
| std::function<decltype(HcnOpenNetwork)> OpenNetwork = &HcnOpenNetwork; | ||||||
| // @ref https://learn.microsoft.com/en-us/virtualization/api/hcn/reference/hcndeletenetwork | ||||||
| std::function<decltype(HcnDeleteNetwork)> DeleteNetwork = &HcnDeleteNetwork; | ||||||
| // @ref https://learn.microsoft.com/en-us/virtualization/api/hcn/reference/hcnclosenetwork | ||||||
| std::function<decltype(HcnCloseNetwork)> CloseNetwork = &HcnCloseNetwork; | ||||||
| // @ref https://learn.microsoft.com/en-us/virtualization/api/hcn/reference/hcncreateendpoint | ||||||
| std::function<decltype(HcnCreateEndpoint)> CreateEndpoint = &HcnCreateEndpoint; | ||||||
| // @ref https://learn.microsoft.com/en-us/virtualization/api/hcn/reference/hcnopenendpoint | ||||||
| std::function<decltype(HcnOpenEndpoint)> OpenEndpoint = &HcnOpenEndpoint; | ||||||
| // @ref https://learn.microsoft.com/en-us/virtualization/api/hcn/reference/hcndeleteendpoint | ||||||
| std::function<decltype(HcnDeleteEndpoint)> DeleteEndpoint = &HcnDeleteEndpoint; | ||||||
| // @ref https://learn.microsoft.com/en-us/virtualization/api/hcn/reference/hcndeleteendpoint | ||||||
|
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.
Suggested change
|
||||||
| std::function<decltype(HcnCloseEndpoint)> CloseEndpoint = &HcnCloseEndpoint; | ||||||
| // @ref https://learn.microsoft.com/en-us/windows/win32/api/combaseapi/nf-combaseapi-cotaskmemfree | ||||||
| std::function<decltype(::CoTaskMemFree)> CoTaskMemFree = &::CoTaskMemFree; | ||||||
| }; | ||||||
|
|
||||||
| } // namespace multipass::hyperv::hcn | ||||||
|
|
||||||
| /** | ||||||
| * Formatter type specialization for HCNAPITable | ||||||
| */ | ||||||
| template <typename Char> | ||||||
| struct fmt::formatter<multipass::hyperv::hcn::HCNAPITable, Char> | ||||||
| { | ||||||
| constexpr auto parse(basic_format_parse_context<Char>& ctx) | ||||||
| { | ||||||
| return ctx.begin(); | ||||||
| } | ||||||
|
|
||||||
| template <typename FormatContext> | ||||||
| auto format(const multipass::hyperv::hcn::HCNAPITable& api, FormatContext& ctx) const | ||||||
| { | ||||||
| return format_to(ctx.out(), | ||||||
| "CreateNetwork: ({}) | OpenNetwork: ({}) | DeleteNetwork: ({}) | CreateEndpoint: ({}) | " | ||||||
| "OpenEndpoint: ({}) | DeleteEndpoint: ({}) | CoTaskMemFree: ({})", | ||||||
| static_cast<bool>(api.CreateNetwork), | ||||||
| static_cast<bool>(api.OpenNetwork), | ||||||
| static_cast<bool>(api.DeleteNetwork), | ||||||
| static_cast<bool>(api.CreateEndpoint), | ||||||
| static_cast<bool>(api.OpenEndpoint), | ||||||
| static_cast<bool>(api.DeleteEndpoint), | ||||||
| static_cast<bool>(api.CoTaskMemFree)); | ||||||
|
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. Missing 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. Sharp eyes :) I'll add them. 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. To avoid rebasing, I'll make the changes in the succeeding PR. |
||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| #endif // MULTIPASS_HYPERV_API_HCN_API_TABLE | ||||||
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.
Is this necessary if we are already selecting linked libraries by platform in src/platform/CMakeLists.txt?