!29 4.24: sync with upstream stable-2.0.0 at 4.24
Merge pull request !29 from lifeng_isula/424
This commit is contained in:
commit
bf45641ecf
@ -9,13 +9,7 @@ include(cmake/set_build_flags.cmake)
|
|||||||
|
|
||||||
#set(CMAKE_C_COMPILER "gcc" CACHE PATH "c compiler")
|
#set(CMAKE_C_COMPILER "gcc" CACHE PATH "c compiler")
|
||||||
|
|
||||||
# Get the latest abbreviated commit hash of the working branch
|
set(GIT_COMMIT_HASH "d03048c03e5f83d8de4e6f164f354a9cb8316362")
|
||||||
execute_process(
|
|
||||||
COMMAND git rev-parse HEAD
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
OUTPUT_VARIABLE GIT_COMMIT_HASH
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
message("-- commit id: " ${GIT_COMMIT_HASH})
|
message("-- commit id: " ${GIT_COMMIT_HASH})
|
||||||
add_definitions(-DISULAD_GIT_COMMIT="${GIT_COMMIT_HASH}")
|
add_definitions(-DISULAD_GIT_COMMIT="${GIT_COMMIT_HASH}")
|
||||||
|
|
||||||
|
|||||||
116
License/LICENSE
116
License/LICENSE
@ -1,22 +1,21 @@
|
|||||||
木兰宽松许可证, 第2版
|
木兰宽松许可证, 第1版
|
||||||
|
|
||||||
木兰宽松许可证, 第2版
|
木兰宽松许可证, 第1版
|
||||||
2020年1月 http://license.coscl.org.cn/MulanPSL2
|
2019年8月 http://license.coscl.org.cn/MulanPSL
|
||||||
|
|
||||||
|
您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第1版(“本许可证”)的如下条款的约束:
|
||||||
您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束:
|
|
||||||
|
|
||||||
0. 定义
|
0. 定义
|
||||||
|
|
||||||
“软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
|
“软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
|
||||||
|
|
||||||
“贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
|
|
||||||
|
|
||||||
“贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
|
“贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
|
||||||
|
|
||||||
“法人实体”是指提交贡献的机构及其“关联实体”。
|
“法人实体”是指提交贡献的机构及其“关联实体”。
|
||||||
|
|
||||||
“关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
|
“关联实体”是指,对“本许可证”下的一方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
|
||||||
|
|
||||||
|
“贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
|
||||||
|
|
||||||
1. 授予版权许可
|
1. 授予版权许可
|
||||||
|
|
||||||
@ -24,7 +23,7 @@
|
|||||||
|
|
||||||
2. 授予专利许可
|
2. 授予专利许可
|
||||||
|
|
||||||
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
|
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括仅因您或他人修改“贡献”或其他结合而将必然会侵犯到的专利权利要求。如您或您的“关联实体”直接或间接地(包括通过代理、专利被许可人或受让人),就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
|
||||||
|
|
||||||
3. 无商标许可
|
3. 无商标许可
|
||||||
|
|
||||||
@ -36,16 +35,13 @@
|
|||||||
|
|
||||||
5. 免责声明与责任限制
|
5. 免责声明与责任限制
|
||||||
|
|
||||||
“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
|
“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
|
||||||
|
|
||||||
6. 语言
|
条款结束。
|
||||||
“本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。
|
|
||||||
|
|
||||||
条款结束
|
如何将木兰宽松许可证,第1版,应用到您的软件
|
||||||
|
|
||||||
如何将木兰宽松许可证,第2版,应用到您的软件
|
如果您希望将木兰宽松许可证,第1版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步:
|
||||||
|
|
||||||
如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步:
|
|
||||||
|
|
||||||
1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
|
1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
|
||||||
|
|
||||||
@ -53,45 +49,47 @@
|
|||||||
|
|
||||||
3, 请将如下声明文本放入每个源文件的头部注释中。
|
3, 请将如下声明文本放入每个源文件的头部注释中。
|
||||||
|
|
||||||
Copyright (c) [Year] [name of copyright holder]
|
Copyright (c) [2019] [name of copyright holder]
|
||||||
[Software Name] is licensed under Mulan PSL v2.
|
[Software Name] is licensed under the Mulan PSL v1.
|
||||||
You can use this software according to the terms and conditions of the Mulan PSL v2.
|
You can use this software according to the terms and conditions of the Mulan PSL v1.
|
||||||
You may obtain a copy of Mulan PSL v2 at:
|
You may obtain a copy of Mulan PSL v1 at:
|
||||||
http://license.coscl.org.cn/MulanPSL2
|
http://license.coscl.org.cn/MulanPSL
|
||||||
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
See the Mulan PSL v2 for more details.
|
IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
PURPOSE.
|
||||||
|
See the Mulan PSL v1 for more details.
|
||||||
|
|
||||||
|
|
||||||
Mulan Permissive Software License,Version 2
|
Mulan Permissive Software License,Version 1
|
||||||
|
|
||||||
Mulan Permissive Software License,Version 2 (Mulan PSL v2)
|
Mulan Permissive Software License,Version 1 (Mulan PSL v1)
|
||||||
January 2020 http://license.coscl.org.cn/MulanPSL2
|
August 2019 http://license.coscl.org.cn/MulanPSL
|
||||||
|
|
||||||
|
Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v1 (this License) with following terms and conditions:
|
||||||
|
|
||||||
Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions:
|
|
||||||
|
|
||||||
0. Definition
|
0. Definition
|
||||||
|
|
||||||
Software means the program and related documents which are licensed under this License and comprise all Contribution(s).
|
Software means the program and related documents which are comprised of those Contribution and licensed under this License.
|
||||||
|
|
||||||
Contribution means the copyrightable work licensed by a particular Contributor under this License.
|
|
||||||
|
|
||||||
Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
|
Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
|
||||||
|
|
||||||
Legal Entity means the entity making a Contribution and all its Affiliates.
|
Legal Entity means the entity making a Contribution and all its Affiliates.
|
||||||
|
|
||||||
Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
|
Affiliates means entities that control, or are controlled by, or are under common control with a party to this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
|
||||||
|
|
||||||
|
Contribution means the copyrightable work licensed by a particular Contributor under this License.
|
||||||
|
|
||||||
1. Grant of Copyright License
|
1. Grant of Copyright License
|
||||||
|
|
||||||
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
|
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
|
||||||
|
|
||||||
2. Grant of Patent License
|
2. Grant of Patent License
|
||||||
|
|
||||||
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
|
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed, excluding of any patent claims solely be infringed by your or others’ modification or other combinations. If you or your Affiliates directly or indirectly (including through an agent, patent licensee or assignee), institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
|
||||||
|
|
||||||
3. No Trademark License
|
3. No Trademark License
|
||||||
|
|
||||||
No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4.
|
No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in section 4.
|
||||||
|
|
||||||
4. Distribution Restriction
|
4. Distribution Restriction
|
||||||
|
|
||||||
@ -99,29 +97,25 @@
|
|||||||
|
|
||||||
5. Disclaimer of Warranty and Limitation of Liability
|
5. Disclaimer of Warranty and Limitation of Liability
|
||||||
|
|
||||||
THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
The Software and Contribution in it are provided without warranties of any kind, either express or implied. In no event shall any Contributor or copyright holder be liable to you for any damages, including, but not limited to any direct, or indirect, special or consequential damages arising from your use or inability to use the Software or the Contribution in it, no matter how it’s caused or based on which legal theory, even if advised of the possibility of such damages.
|
||||||
|
|
||||||
6. Language
|
End of the Terms and Conditions
|
||||||
|
|
||||||
THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
|
How to apply the Mulan Permissive Software License,Version 1 (Mulan PSL v1) to your software
|
||||||
|
|
||||||
END OF THE TERMS AND CONDITIONS
|
To apply the Mulan PSL v1 to your work, for easy identification by recipients, you are suggested to complete following three steps:
|
||||||
|
|
||||||
How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software
|
i. Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
|
||||||
|
ii. Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package;
|
||||||
To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps:
|
iii. Attach the statement to the appropriate annotated syntax at the beginning of each source file.
|
||||||
|
|
||||||
i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
|
Copyright (c) [2019] [name of copyright holder]
|
||||||
|
[Software Name] is licensed under the Mulan PSL v1.
|
||||||
ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package;
|
You can use this software according to the terms and conditions of the Mulan PSL v1.
|
||||||
|
You may obtain a copy of Mulan PSL v1 at:
|
||||||
iii Attach the statement to the appropriate annotated syntax at the beginning of each source file.
|
http://license.coscl.org.cn/MulanPSL
|
||||||
|
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
Copyright (c) [Year] [name of copyright holder]
|
PURPOSE.
|
||||||
[Software Name] is licensed under Mulan PSL v2.
|
|
||||||
You can use this software according to the terms and conditions of the Mulan PSL v2.
|
See the Mulan PSL v1 for more details.
|
||||||
You may obtain a copy of Mulan PSL v2 at:
|
|
||||||
http://license.coscl.org.cn/MulanPSL2
|
|
||||||
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
||||||
See the Mulan PSL v2 for more details.
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
%global _version 2.0.0
|
%global _version 2.0.0
|
||||||
%global _release 20200321.032232.gitaec8336d
|
%global _release 20200406.224614.gitd03048c0
|
||||||
%global is_systemd 1
|
%global is_systemd 1
|
||||||
%global debug_package %{nil}
|
%global debug_package %{nil}
|
||||||
|
|
||||||
|
|||||||
@ -78,6 +78,9 @@ service ImageService {
|
|||||||
// get status of graphdriver
|
// get status of graphdriver
|
||||||
rpc GraphdriverStatus(GraphdriverStatusRequest) returns (GraphdriverStatusResponse) {}
|
rpc GraphdriverStatus(GraphdriverStatusRequest) returns (GraphdriverStatusResponse) {}
|
||||||
|
|
||||||
|
// get metadata of graphdriver
|
||||||
|
rpc GraphdriverMetadata(GraphdriverMetadataRequest) returns (GraphdriverMetadataResponse) {}
|
||||||
|
|
||||||
// login registry
|
// login registry
|
||||||
rpc Login(LoginRequest) returns (LoginResponse) {}
|
rpc Login(LoginRequest) returns (LoginResponse) {}
|
||||||
// logout registry
|
// logout registry
|
||||||
@ -85,6 +88,9 @@ service ImageService {
|
|||||||
|
|
||||||
// health check service
|
// health check service
|
||||||
rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse) {}
|
rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse) {}
|
||||||
|
|
||||||
|
// Add a tag to the image
|
||||||
|
rpc TagImage(TagImageRequest) returns (TagImageResponse) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
message HealthCheckRequest {}
|
message HealthCheckRequest {}
|
||||||
@ -146,6 +152,17 @@ message GraphdriverStatusResponse {
|
|||||||
uint32 cc = 3;
|
uint32 cc = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message GraphdriverMetadataRequest {
|
||||||
|
string name_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message GraphdriverMetadataResponse {
|
||||||
|
map<string,string> metadata = 1;
|
||||||
|
string name = 2;
|
||||||
|
string errmsg = 3;
|
||||||
|
uint32 cc = 4;
|
||||||
|
}
|
||||||
|
|
||||||
message ContainerFsUsageRequest {
|
message ContainerFsUsageRequest {
|
||||||
string name_id = 1;
|
string name_id = 1;
|
||||||
}
|
}
|
||||||
@ -412,6 +429,15 @@ message ListImagesRequest {
|
|||||||
bool check = 2;
|
bool check = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message HealthCheck {
|
||||||
|
repeated string test = 1;
|
||||||
|
int64 interval = 2;
|
||||||
|
int64 timeout = 3;
|
||||||
|
int64 start_period = 4;
|
||||||
|
int32 retries = 5;
|
||||||
|
bool exit_on_unhealthy = 6;
|
||||||
|
}
|
||||||
|
|
||||||
// Basic information about a container image.
|
// Basic information about a container image.
|
||||||
message Image {
|
message Image {
|
||||||
// ID of the image.
|
// ID of the image.
|
||||||
@ -438,6 +464,9 @@ message Image {
|
|||||||
|
|
||||||
// oci image spec
|
// oci image spec
|
||||||
ImageSpec spec = 9;
|
ImageSpec spec = 9;
|
||||||
|
|
||||||
|
// Health check
|
||||||
|
HealthCheck healthcheck = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ListImagesResponse {
|
message ListImagesResponse {
|
||||||
@ -557,3 +586,13 @@ message ImageFsInfoResponse {
|
|||||||
string errmsg = 2;
|
string errmsg = 2;
|
||||||
uint32 cc = 3;
|
uint32 cc = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message TagImageRequest {
|
||||||
|
ImageSpec srcName = 1;
|
||||||
|
ImageSpec destName = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message TagImageResponse {
|
||||||
|
string errmsg = 1;
|
||||||
|
uint32 cc = 2;
|
||||||
|
}
|
||||||
|
|||||||
@ -324,7 +324,8 @@ message RemoteExecRequest {
|
|||||||
}
|
}
|
||||||
message RemoteExecResponse {
|
message RemoteExecResponse {
|
||||||
bytes stdout = 1;
|
bytes stdout = 1;
|
||||||
bool finish = 2;
|
bytes stderr = 2;
|
||||||
|
bool finish = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message AttachRequest {
|
message AttachRequest {
|
||||||
|
|||||||
@ -70,6 +70,9 @@ service ImagesService {
|
|||||||
|
|
||||||
// Logout from a Docker registry
|
// Logout from a Docker registry
|
||||||
rpc Logout(LogoutRequest) returns (LogoutResponse);
|
rpc Logout(LogoutRequest) returns (LogoutResponse);
|
||||||
|
|
||||||
|
// Add a tag to the image
|
||||||
|
rpc Tag(TagImageRequest) returns (TagImageResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
message Image {
|
message Image {
|
||||||
@ -126,6 +129,16 @@ message DeleteImageResponse {
|
|||||||
string errmsg = 3;
|
string errmsg = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message TagImageRequest {
|
||||||
|
string src_name = 1;
|
||||||
|
string dest_name = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message TagImageResponse {
|
||||||
|
uint32 cc = 1;
|
||||||
|
string errmsg = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message LoadImageRequest {
|
message LoadImageRequest {
|
||||||
string file = 1;
|
string file = 1;
|
||||||
string type = 2;
|
string type = 2;
|
||||||
|
|||||||
123
src/cmd/isula/images/tag.c
Normal file
123
src/cmd/isula/images/tag.c
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||||
|
* iSulad licensed under the Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
* PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
* Author: wangfengtu
|
||||||
|
* Create: 2020-04-15
|
||||||
|
* Description: provide image tag functions
|
||||||
|
******************************************************************************/
|
||||||
|
#include "tag.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
#include "arguments.h"
|
||||||
|
#include "isula_connect.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
const char g_cmd_tag_desc[] = "Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE";
|
||||||
|
const char g_cmd_tag_usage[] = "tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]";
|
||||||
|
|
||||||
|
struct client_arguments g_cmd_tag_args = {};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add a tag to the image
|
||||||
|
*/
|
||||||
|
static int client_tag(const struct client_arguments *args)
|
||||||
|
{
|
||||||
|
isula_connect_ops *ops = NULL;
|
||||||
|
struct isula_tag_request request = { 0 };
|
||||||
|
struct isula_tag_response *response = NULL;
|
||||||
|
client_connect_config_t config = { 0 };
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
response = util_common_calloc_s(sizeof(struct isula_tag_response));
|
||||||
|
if (response == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
request.src_name = args->image_name;
|
||||||
|
request.dest_name = args->tag;
|
||||||
|
|
||||||
|
ops = get_connect_client_ops();
|
||||||
|
if (ops == NULL || !ops->image.tag) {
|
||||||
|
ERROR("Unimplemented ops");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
config = get_connect_config(args);
|
||||||
|
ret = ops->image.tag(&request, response, &config);
|
||||||
|
if (ret) {
|
||||||
|
client_print_error(response->cc, response->server_errono, response->errmsg);
|
||||||
|
if (response->server_errono) {
|
||||||
|
ret = ESERVERERROR;
|
||||||
|
}
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
out:
|
||||||
|
isula_tag_response_free(response);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cmd_tag_main(int argc, const char **argv)
|
||||||
|
{
|
||||||
|
struct log_config lconf = { 0 };
|
||||||
|
int exit_code = 1;
|
||||||
|
command_t cmd;
|
||||||
|
struct command_option options[] = {
|
||||||
|
LOG_OPTIONS(lconf),
|
||||||
|
COMMON_OPTIONS(g_cmd_tag_args),
|
||||||
|
};
|
||||||
|
|
||||||
|
set_default_command_log_config(argv[0], &lconf);
|
||||||
|
if (client_arguments_init(&g_cmd_tag_args)) {
|
||||||
|
COMMAND_ERROR("client arguments init failed");
|
||||||
|
exit(ECOMMON);
|
||||||
|
}
|
||||||
|
g_cmd_tag_args.progname = argv[0];
|
||||||
|
command_init(&cmd, options, sizeof(options) / sizeof(options[0]), argc, (const char **)argv, g_cmd_tag_desc,
|
||||||
|
g_cmd_tag_usage);
|
||||||
|
if (command_parse_args(&cmd, &g_cmd_tag_args.argc, &g_cmd_tag_args.argv)) {
|
||||||
|
exit(exit_code);
|
||||||
|
}
|
||||||
|
if (log_init(&lconf)) {
|
||||||
|
COMMAND_ERROR("RMI: log init failed");
|
||||||
|
exit(exit_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_cmd_tag_args.argc != 2) {
|
||||||
|
COMMAND_ERROR("\"tag\" requires exactly 2 arguments.");
|
||||||
|
exit(exit_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_cmd_tag_args.image_name = g_cmd_tag_args.argv[0];
|
||||||
|
g_cmd_tag_args.tag = g_cmd_tag_args.argv[1];
|
||||||
|
|
||||||
|
if (!util_valid_image_name(g_cmd_tag_args.image_name)) {
|
||||||
|
COMMAND_ERROR("%s is not a valid image name", g_cmd_tag_args.image_name);
|
||||||
|
exit(exit_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!util_valid_tag(g_cmd_tag_args.tag)) {
|
||||||
|
COMMAND_ERROR("%s is not a valid tag", g_cmd_tag_args.tag);
|
||||||
|
exit(exit_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = client_tag(&g_cmd_tag_args);
|
||||||
|
if (ret != 0) {
|
||||||
|
COMMAND_ERROR("Tag image \"%s\" to \"%s\" failed", g_cmd_tag_args.image_name, g_cmd_tag_args.tag);
|
||||||
|
exit(exit_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
34
src/cmd/isula/images/tag.h
Normal file
34
src/cmd/isula/images/tag.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||||
|
* iSulad licensed under the Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
* PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
* Author: wangfengtu
|
||||||
|
* Create: 2020-04-15
|
||||||
|
* Description: provide image tag definition
|
||||||
|
******************************************************************************/
|
||||||
|
#ifndef __CMD_TAG_IMAGE_H
|
||||||
|
#define __CMD_TAG_IMAGE_H
|
||||||
|
|
||||||
|
#include "arguments.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern const char g_cmd_tag_desc[];
|
||||||
|
extern const char g_cmd_tag_usage[];
|
||||||
|
extern struct client_arguments g_cmd_tag_args;
|
||||||
|
int cmd_tag_main(int argc, const char **argv);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __CMD_TAG_IMAGE_H */
|
||||||
|
|
||||||
@ -28,6 +28,7 @@
|
|||||||
#include "run.h"
|
#include "run.h"
|
||||||
#include "images.h"
|
#include "images.h"
|
||||||
#include "rmi.h"
|
#include "rmi.h"
|
||||||
|
#include "tag.h"
|
||||||
#include "wait.h"
|
#include "wait.h"
|
||||||
#include "restart.h"
|
#include "restart.h"
|
||||||
#include "pause.h"
|
#include "pause.h"
|
||||||
@ -190,6 +191,10 @@ struct command g_commands[] = {
|
|||||||
// `logout` sub-command
|
// `logout` sub-command
|
||||||
"logout", cmd_logout_main, g_cmd_logout_desc, NULL, &g_cmd_logout_args
|
"logout", cmd_logout_main, g_cmd_logout_desc, NULL, &g_cmd_logout_args
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// `tag` sub-command
|
||||||
|
"tag", cmd_tag_main, g_cmd_tag_desc, NULL, &g_cmd_tag_args
|
||||||
|
},
|
||||||
#endif
|
#endif
|
||||||
{ NULL, NULL, NULL, NULL, NULL } // End of the list
|
{ NULL, NULL, NULL, NULL, NULL } // End of the list
|
||||||
};
|
};
|
||||||
|
|||||||
@ -422,10 +422,8 @@ int cmd_exec_main(int argc, const char **argv)
|
|||||||
|
|
||||||
custom_cfg = &g_cmd_exec_args.custom_conf;
|
custom_cfg = &g_cmd_exec_args.custom_conf;
|
||||||
|
|
||||||
custom_cfg->tty = true;
|
|
||||||
custom_cfg->open_stdin = true;
|
|
||||||
custom_cfg->attach_stdout = true;
|
custom_cfg->attach_stdout = true;
|
||||||
custom_cfg->attach_stderr = false;
|
custom_cfg->attach_stderr = true;
|
||||||
custom_cfg->attach_stdin = custom_cfg->open_stdin;
|
custom_cfg->attach_stdin = custom_cfg->open_stdin;
|
||||||
|
|
||||||
if (g_cmd_exec_args.detach) {
|
if (g_cmd_exec_args.detach) {
|
||||||
|
|||||||
@ -1004,7 +1004,12 @@ out:
|
|||||||
if (stream_response.finish()) {
|
if (stream_response.finish()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::cout << stream_response.stdout() << std::flush;
|
if (!stream_response.stdout().empty()) {
|
||||||
|
std::cout << stream_response.stdout() << std::flush;
|
||||||
|
}
|
||||||
|
if (!stream_response.stderr().empty()) {
|
||||||
|
std::cerr << stream_response.stderr() << std::flush;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
write_task.stop();
|
write_task.stop();
|
||||||
stream->WritesDone();
|
stream->WritesDone();
|
||||||
|
|||||||
@ -167,6 +167,62 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ImageTag : public ClientBase<ImagesService, ImagesService::Stub, isula_tag_request, TagImageRequest,
|
||||||
|
isula_tag_response, TagImageResponse> {
|
||||||
|
public:
|
||||||
|
explicit ImageTag(void *args)
|
||||||
|
: ClientBase(args)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
~ImageTag() = default;
|
||||||
|
|
||||||
|
int request_to_grpc(const isula_tag_request *request, TagImageRequest *grequest) override
|
||||||
|
{
|
||||||
|
if (request == nullptr) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->src_name != nullptr) {
|
||||||
|
grequest->set_src_name(request->src_name);
|
||||||
|
}
|
||||||
|
if (request->dest_name != nullptr) {
|
||||||
|
grequest->set_dest_name(request->dest_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int response_from_grpc(TagImageResponse *gresponse, isula_tag_response *response) override
|
||||||
|
{
|
||||||
|
response->server_errono = (uint32_t)gresponse->cc();
|
||||||
|
|
||||||
|
if (!gresponse->errmsg().empty()) {
|
||||||
|
response->errmsg = util_strdup_s(gresponse->errmsg().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int check_parameter(const TagImageRequest &req) override
|
||||||
|
{
|
||||||
|
if (req.src_name().empty()) {
|
||||||
|
ERROR("Missing source image name in the request");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (req.dest_name().empty()) {
|
||||||
|
ERROR("Missing destition image name in the request");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status grpc_call(ClientContext *context, const TagImageRequest &req, TagImageResponse *reply) override
|
||||||
|
{
|
||||||
|
return stub_->Tag(context, req, reply);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class ImagesLoad : public ClientBase<ImagesService, ImagesService::Stub, isula_load_request, LoadImageRequest,
|
class ImagesLoad : public ClientBase<ImagesService, ImagesService::Stub, isula_load_request, LoadImageRequest,
|
||||||
isula_load_response, LoadImageResponse> {
|
isula_load_response, LoadImageResponse> {
|
||||||
public:
|
public:
|
||||||
@ -468,6 +524,7 @@ int grpc_images_client_ops_init(isula_connect_ops *ops)
|
|||||||
ops->image.inspect = container_func<isula_inspect_request, isula_inspect_response, ImageInspect>;
|
ops->image.inspect = container_func<isula_inspect_request, isula_inspect_response, ImageInspect>;
|
||||||
ops->image.login = container_func<isula_login_request, isula_login_response, Login>;
|
ops->image.login = container_func<isula_login_request, isula_login_response, Login>;
|
||||||
ops->image.logout = container_func<isula_logout_request, isula_logout_response, Logout>;
|
ops->image.logout = container_func<isula_logout_request, isula_logout_response, Logout>;
|
||||||
|
ops->image.tag = container_func<isula_tag_request, isula_tag_response, ImageTag>;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,6 +64,44 @@ int copy_image_digests_metadata(const isula::Image &gimage, struct image_metadat
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int copy_image_health_check_config(const isula::Image &gimage, struct image_metadata *metadata)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
defs_health_check *health_check = nullptr;
|
||||||
|
|
||||||
|
if (!gimage.has_healthcheck()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
health_check = (defs_health_check *)util_common_calloc_s(sizeof(defs_health_check));
|
||||||
|
if (health_check == nullptr) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
health_check->test = (char **)util_common_calloc_s(gimage.healthcheck().test_size() * sizeof(char *));
|
||||||
|
if (health_check->test == nullptr) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
for (int i {0}; i < gimage.healthcheck().test_size(); i++) {
|
||||||
|
health_check->test[i] = util_strdup_s(gimage.healthcheck().test(i).c_str());
|
||||||
|
}
|
||||||
|
health_check->test_len = gimage.healthcheck().test_size();
|
||||||
|
health_check->interval = (int64_t)gimage.healthcheck().interval();
|
||||||
|
health_check->timeout = (int64_t)gimage.healthcheck().timeout();
|
||||||
|
health_check->retries = (int)gimage.healthcheck().retries();
|
||||||
|
health_check->exit_on_unhealthy = gimage.healthcheck().exit_on_unhealthy();
|
||||||
|
|
||||||
|
metadata->health_check = health_check;
|
||||||
|
health_check = nullptr;
|
||||||
|
|
||||||
|
out:
|
||||||
|
free_defs_health_check(health_check);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int copy_image_metadata(const isula::Image &gimage, struct image_metadata **metadata)
|
int copy_image_metadata(const isula::Image &gimage, struct image_metadata **metadata)
|
||||||
{
|
{
|
||||||
struct image_metadata *tmp_data = (struct image_metadata *)util_common_calloc_s(sizeof(struct image_metadata));
|
struct image_metadata *tmp_data = (struct image_metadata *)util_common_calloc_s(sizeof(struct image_metadata));
|
||||||
@ -105,8 +143,14 @@ int copy_image_metadata(const isula::Image &gimage, struct image_metadata **meta
|
|||||||
if (gimage.has_spec() && !gimage.spec().image().empty()) {
|
if (gimage.has_spec() && !gimage.spec().image().empty()) {
|
||||||
tmp_data->oci_spec = util_strdup_s(gimage.spec().image().c_str());
|
tmp_data->oci_spec = util_strdup_s(gimage.spec().image().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (copy_image_health_check_config(gimage, tmp_data) != 0) {
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
|
||||||
*metadata = tmp_data;
|
*metadata = tmp_data;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_out:
|
err_out:
|
||||||
free_image_metadata(tmp_data);
|
free_image_metadata(tmp_data);
|
||||||
return -1;
|
return -1;
|
||||||
@ -633,6 +677,62 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ISulaTag : public ClientBase<isula::ImageService, isula::ImageService::Stub, isula_tag_request,
|
||||||
|
isula::TagImageRequest, isula_tag_response, isula::TagImageResponse> {
|
||||||
|
public:
|
||||||
|
explicit ISulaTag(void *args) : ClientBase(args)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
~ISulaTag() = default;
|
||||||
|
|
||||||
|
int request_to_grpc(const isula_tag_request *req, isula::TagImageRequest *grequest) override
|
||||||
|
{
|
||||||
|
if (req == nullptr) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (req->src_name == nullptr || req->src_name->image == nullptr ||
|
||||||
|
req->dest_name == nullptr || req->dest_name->image == nullptr) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
isula::ImageSpec *src_image = new (std::nothrow) isula::ImageSpec;
|
||||||
|
isula::ImageSpec *dest_image = new (std::nothrow) isula::ImageSpec;
|
||||||
|
if (src_image == nullptr || dest_image == nullptr) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
src_image->set_image(req->src_name->image);
|
||||||
|
dest_image->set_image(req->dest_name->image);
|
||||||
|
grequest->set_allocated_srcname(src_image);
|
||||||
|
grequest->set_allocated_destname(dest_image);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int response_from_grpc(isula::TagImageResponse *gresp, isula_tag_response *resp) override
|
||||||
|
{
|
||||||
|
if (!gresp->errmsg().empty()) {
|
||||||
|
resp->errmsg = util_strdup_s(gresp->errmsg().c_str());
|
||||||
|
}
|
||||||
|
resp->server_errono = gresp->cc();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int check_parameter(const isula::TagImageRequest &req) override
|
||||||
|
{
|
||||||
|
if (req.has_srcname() && !req.srcname().image().empty() &&
|
||||||
|
req.has_destname() && !req.destname().image().empty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ERROR("Image name is required.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status grpc_call(ClientContext *context, const isula::TagImageRequest &req,
|
||||||
|
isula::TagImageResponse *reply) override
|
||||||
|
{
|
||||||
|
return stub_->TagImage(context, req, reply);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class ISulaLoad : public ClientBase<isula::ImageService, isula::ImageService::Stub, isula_load_request,
|
class ISulaLoad : public ClientBase<isula::ImageService, isula::ImageService::Stub, isula_load_request,
|
||||||
isula::LoadImageRequest, isula_load_response, isula::LoadImageResponose> {
|
isula::LoadImageRequest, isula_load_response, isula::LoadImageResponose> {
|
||||||
public:
|
public:
|
||||||
@ -875,6 +975,63 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ISulaStorageMetadata : public
|
||||||
|
ClientBase<isula::ImageService, isula::ImageService::Stub, isula_storage_metadata_request,
|
||||||
|
isula::GraphdriverMetadataRequest, isula_storage_metadata_response, isula::GraphdriverMetadataResponse> {
|
||||||
|
public:
|
||||||
|
explicit ISulaStorageMetadata(void *args) : ClientBase(args)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
~ISulaStorageMetadata() = default;
|
||||||
|
|
||||||
|
int request_to_grpc(const isula_storage_metadata_request *req, isula::GraphdriverMetadataRequest *grequest) override
|
||||||
|
{
|
||||||
|
if (req == nullptr) {
|
||||||
|
isulad_set_error_message("unvalid export request");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (req->container_id != nullptr) {
|
||||||
|
grequest->set_name_id(req->container_id);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int response_from_grpc(isula::GraphdriverMetadataResponse *gresp, isula_storage_metadata_response *resp) override
|
||||||
|
{
|
||||||
|
int metadata_len = gresp->metadata_size();
|
||||||
|
if (metadata_len > 0) {
|
||||||
|
resp->metadata = (json_map_string_string *)util_common_calloc_s(sizeof(json_map_string_string));
|
||||||
|
if (resp->metadata == nullptr) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for (const auto &iter : gresp->metadata()) {
|
||||||
|
if (append_json_map_string_string(resp->metadata, iter.first.c_str(), iter.second.c_str()) != 0) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gresp->name().empty()) {
|
||||||
|
resp->name = util_strdup_s(gresp->name().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gresp->errmsg().empty()) {
|
||||||
|
resp->errmsg = util_strdup_s(gresp->errmsg().c_str());
|
||||||
|
}
|
||||||
|
resp->server_errono = gresp->cc();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status grpc_call(ClientContext *context, const isula::GraphdriverMetadataRequest &req,
|
||||||
|
isula::GraphdriverMetadataResponse *reply) override
|
||||||
|
{
|
||||||
|
return stub_->GraphdriverMetadata(context, req, reply);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class ISulaContainerFsUsage : public
|
class ISulaContainerFsUsage : public
|
||||||
ClientBase<isula::ImageService, isula::ImageService::Stub, isula_container_fs_usage_request,
|
ClientBase<isula::ImageService, isula::ImageService::Stub, isula_container_fs_usage_request,
|
||||||
isula::ContainerFsUsageRequest, isula_container_fs_usage_response, isula::ContainerFsUsageResponse> {
|
isula::ContainerFsUsageRequest, isula_container_fs_usage_response, isula::ContainerFsUsageResponse> {
|
||||||
@ -1040,6 +1197,7 @@ int grpc_isula_image_client_ops_init(isula_image_ops *ops)
|
|||||||
|
|
||||||
ops->pull = container_func<isula_pull_request, isula_pull_response, ISulaImagePull>;
|
ops->pull = container_func<isula_pull_request, isula_pull_response, ISulaImagePull>;
|
||||||
ops->rmi = container_func<isula_rmi_request, isula_rmi_response, ISulaRmi>;
|
ops->rmi = container_func<isula_rmi_request, isula_rmi_response, ISulaRmi>;
|
||||||
|
ops->tag = container_func<isula_tag_request, isula_tag_response, ISulaTag>;
|
||||||
ops->load = container_func<isula_load_request, isula_load_response, ISulaLoad>;
|
ops->load = container_func<isula_load_request, isula_load_response, ISulaLoad>;
|
||||||
ops->login = container_func<isula_login_request, isula_login_response, ISulaLogin>;
|
ops->login = container_func<isula_login_request, isula_login_response, ISulaLogin>;
|
||||||
ops->logout = container_func<isula_logout_request, isula_logout_response, ISulaLogout>;
|
ops->logout = container_func<isula_logout_request, isula_logout_response, ISulaLogout>;
|
||||||
@ -1060,6 +1218,8 @@ int grpc_isula_image_client_ops_init(isula_image_ops *ops)
|
|||||||
|
|
||||||
ops->storage_status = container_func<isula_storage_status_request, isula_storage_status_response,
|
ops->storage_status = container_func<isula_storage_status_request, isula_storage_status_response,
|
||||||
ISulaStorageStatus>;
|
ISulaStorageStatus>;
|
||||||
|
ops->storage_metadata = container_func<isula_storage_metadata_request, isula_storage_metadata_response,
|
||||||
|
ISulaStorageMetadata>;
|
||||||
|
|
||||||
ops->health_check = container_func<isula_health_check_request, isula_health_check_response, ISulaHealthCheck>;
|
ops->health_check = container_func<isula_health_check_request, isula_health_check_response, ISulaHealthCheck>;
|
||||||
|
|
||||||
|
|||||||
@ -119,6 +119,8 @@ typedef struct {
|
|||||||
struct isula_login_response *response, void *arg);
|
struct isula_login_response *response, void *arg);
|
||||||
int(*logout)(const struct isula_logout_request *request,
|
int(*logout)(const struct isula_logout_request *request,
|
||||||
struct isula_logout_response *response, void *arg);
|
struct isula_logout_response *response, void *arg);
|
||||||
|
int(*tag)(const struct isula_tag_request *request,
|
||||||
|
struct isula_tag_response *response, void *arg);
|
||||||
} image_ops;
|
} image_ops;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@ -224,6 +224,8 @@ void free_image_metadata(struct image_metadata *data)
|
|||||||
data->loaded = NULL;
|
data->loaded = NULL;
|
||||||
free(data->oci_spec);
|
free(data->oci_spec);
|
||||||
data->oci_spec = NULL;
|
data->oci_spec = NULL;
|
||||||
|
free_defs_health_check(data->health_check);
|
||||||
|
data->health_check = NULL;
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,6 +302,28 @@ void free_isula_rmi_response(struct isula_rmi_response *ptr)
|
|||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void free_isula_tag_request(struct isula_tag_request *ptr)
|
||||||
|
{
|
||||||
|
if (ptr == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free_image_spec(ptr->src_name);
|
||||||
|
ptr->src_name = NULL;
|
||||||
|
free_image_spec(ptr->dest_name);
|
||||||
|
ptr->dest_name = NULL;
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_isula_tag_response(struct isula_tag_response *ptr)
|
||||||
|
{
|
||||||
|
if (ptr == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free(ptr->errmsg);
|
||||||
|
ptr->errmsg = NULL;
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
void free_isula_load_request(struct isula_load_request *ptr)
|
void free_isula_load_request(struct isula_load_request *ptr)
|
||||||
{
|
{
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
@ -470,6 +494,20 @@ void free_isula_storage_status_response(struct isula_storage_status_response *pt
|
|||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void free_isula_storage_metadata_response(struct isula_storage_metadata_response *ptr)
|
||||||
|
{
|
||||||
|
if (ptr == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free_json_map_string_string(ptr->metadata);
|
||||||
|
ptr->metadata = NULL;
|
||||||
|
free(ptr->name);
|
||||||
|
ptr->name = NULL;
|
||||||
|
free(ptr->errmsg);
|
||||||
|
ptr->errmsg = NULL;
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
void free_isula_health_check_request(struct isula_health_check_request *ptr)
|
void free_isula_health_check_request(struct isula_health_check_request *ptr)
|
||||||
{
|
{
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "json_common.h"
|
#include "json_common.h"
|
||||||
|
#include "defs.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -116,6 +117,8 @@ struct image_metadata {
|
|||||||
char *loaded;
|
char *loaded;
|
||||||
|
|
||||||
char *oci_spec;
|
char *oci_spec;
|
||||||
|
|
||||||
|
defs_health_check *health_check;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct isula_status_request {
|
struct isula_status_request {
|
||||||
@ -157,6 +160,17 @@ struct isula_rmi_response {
|
|||||||
uint32_t server_errono;
|
uint32_t server_errono;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct isula_tag_request {
|
||||||
|
struct image_spec *src_name;
|
||||||
|
struct image_spec *dest_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct isula_tag_response {
|
||||||
|
char *errmsg;
|
||||||
|
uint32_t cc;
|
||||||
|
uint32_t server_errono;
|
||||||
|
};
|
||||||
|
|
||||||
struct isula_load_request {
|
struct isula_load_request {
|
||||||
char *file;
|
char *file;
|
||||||
char *tag;
|
char *tag;
|
||||||
@ -230,6 +244,19 @@ struct isula_storage_status_response {
|
|||||||
uint32_t server_errono;
|
uint32_t server_errono;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct isula_storage_metadata_request {
|
||||||
|
char *container_id;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct isula_storage_metadata_response {
|
||||||
|
json_map_string_string *metadata;
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
char *errmsg;
|
||||||
|
uint32_t cc;
|
||||||
|
uint32_t server_errono;
|
||||||
|
};
|
||||||
|
|
||||||
struct isula_container_fs_usage_request {
|
struct isula_container_fs_usage_request {
|
||||||
char *name_id;
|
char *name_id;
|
||||||
};
|
};
|
||||||
@ -283,6 +310,7 @@ typedef struct {
|
|||||||
|
|
||||||
int (*prepare)(const struct isula_prepare_request *req, struct isula_prepare_response *resp, void *arg);
|
int (*prepare)(const struct isula_prepare_request *req, struct isula_prepare_response *resp, void *arg);
|
||||||
int (*remove)(const struct isula_remove_request *req, struct isula_remove_response *resp, void *arg);
|
int (*remove)(const struct isula_remove_request *req, struct isula_remove_response *resp, void *arg);
|
||||||
|
int (*tag)(const struct isula_tag_request *req, struct isula_tag_response *resp, void *arg);
|
||||||
int (*mount)(const struct isula_mount_request *req, struct isula_mount_response *resp, void *arg);
|
int (*mount)(const struct isula_mount_request *req, struct isula_mount_response *resp, void *arg);
|
||||||
int (*umount)(const struct isula_umount_request *req, struct isula_umount_response *resp, void *arg);
|
int (*umount)(const struct isula_umount_request *req, struct isula_umount_response *resp, void *arg);
|
||||||
int (*containers_list)(const struct isula_containers_list_request *req, struct isula_containers_list_response *resp,
|
int (*containers_list)(const struct isula_containers_list_request *req, struct isula_containers_list_response *resp,
|
||||||
@ -297,6 +325,10 @@ typedef struct {
|
|||||||
int (*storage_status)(const struct isula_storage_status_request *req, struct isula_storage_status_response *resp,
|
int (*storage_status)(const struct isula_storage_status_request *req, struct isula_storage_status_response *resp,
|
||||||
void *arg);
|
void *arg);
|
||||||
|
|
||||||
|
int (*storage_metadata)(const struct isula_storage_metadata_request *req,
|
||||||
|
struct isula_storage_metadata_response *resp,
|
||||||
|
void *arg);
|
||||||
|
|
||||||
int (*health_check)(const struct isula_health_check_request *req,
|
int (*health_check)(const struct isula_health_check_request *req,
|
||||||
struct isula_health_check_response *resp, void *arg);
|
struct isula_health_check_response *resp, void *arg);
|
||||||
} isula_image_ops;
|
} isula_image_ops;
|
||||||
@ -316,6 +348,8 @@ void free_isula_prepare_request(struct isula_prepare_request *req);
|
|||||||
void free_isula_prepare_response(struct isula_prepare_response *resp);
|
void free_isula_prepare_response(struct isula_prepare_response *resp);
|
||||||
void free_isula_remove_request(struct isula_remove_request *req);
|
void free_isula_remove_request(struct isula_remove_request *req);
|
||||||
void free_isula_remove_response(struct isula_remove_response *resp);
|
void free_isula_remove_response(struct isula_remove_response *resp);
|
||||||
|
void free_isula_tag_request(struct isula_tag_request *req);
|
||||||
|
void free_isula_tag_response(struct isula_tag_response *resp);
|
||||||
void free_isula_mount_request(struct isula_mount_request *req);
|
void free_isula_mount_request(struct isula_mount_request *req);
|
||||||
void free_isula_mount_response(struct isula_mount_response *resp);
|
void free_isula_mount_response(struct isula_mount_response *resp);
|
||||||
void free_isula_umount_request(struct isula_umount_request *req);
|
void free_isula_umount_request(struct isula_umount_request *req);
|
||||||
@ -355,6 +389,8 @@ void free_isula_container_fs_usage_response(struct isula_container_fs_usage_resp
|
|||||||
void free_isula_storage_status_request(struct isula_storage_status_request *ptr);
|
void free_isula_storage_status_request(struct isula_storage_status_request *ptr);
|
||||||
void free_isula_storage_status_response(struct isula_storage_status_response *ptr);
|
void free_isula_storage_status_response(struct isula_storage_status_response *ptr);
|
||||||
|
|
||||||
|
void free_isula_storage_metadata_response(struct isula_storage_metadata_response *ptr);
|
||||||
|
|
||||||
void free_isula_health_check_request(struct isula_health_check_request *ptr);
|
void free_isula_health_check_request(struct isula_health_check_request *ptr);
|
||||||
void free_isula_health_check_response(struct isula_health_check_response *ptr);
|
void free_isula_health_check_response(struct isula_health_check_response *ptr);
|
||||||
|
|
||||||
|
|||||||
@ -427,6 +427,7 @@ static int unpack_container_info_for_list_response(container_list_response *cres
|
|||||||
util_strdup_s(cresponse->containers[i]->finishat) : util_strdup_s("-");
|
util_strdup_s(cresponse->containers[i]->finishat) : util_strdup_s("-");
|
||||||
summary_info[i]->exit_code = cresponse->containers[i]->exit_code;
|
summary_info[i]->exit_code = cresponse->containers[i]->exit_code;
|
||||||
summary_info[i]->restart_count = (unsigned int)cresponse->containers[i]->restartcount;
|
summary_info[i]->restart_count = (unsigned int)cresponse->containers[i]->restartcount;
|
||||||
|
summary_info[i]->created = cresponse->containers[i]->created;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -616,7 +616,7 @@ Status ContainerServiceImpl::Exec(ServerContext *context, const ExecRequest *req
|
|||||||
return Status::CANCELLED;
|
return Status::CANCELLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = cb->container.exec(container_req, &container_res, -1, nullptr);
|
ret = cb->container.exec(container_req, &container_res, -1, nullptr, nullptr);
|
||||||
tret = exec_response_to_grpc(container_res, reply);
|
tret = exec_response_to_grpc(container_res, reply);
|
||||||
|
|
||||||
free_container_exec_request(container_req);
|
free_container_exec_request(container_req);
|
||||||
@ -629,7 +629,7 @@ Status ContainerServiceImpl::Exec(ServerContext *context, const ExecRequest *req
|
|||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t WriteExecResponseToRemoteClient(void *context, const void *data, size_t len)
|
ssize_t WriteExecStdoutResponseToRemoteClient(void *context, const void *data, size_t len)
|
||||||
{
|
{
|
||||||
if (context == nullptr || data == nullptr || len == 0) {
|
if (context == nullptr || data == nullptr || len == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -644,11 +644,36 @@ ssize_t WriteExecResponseToRemoteClient(void *context, const void *data, size_t
|
|||||||
return (ssize_t)len;
|
return (ssize_t)len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t WriteExecStderrResponseToRemoteClient(void *context, const void *data, size_t len)
|
||||||
|
{
|
||||||
|
if (context == nullptr || data == nullptr || len == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
auto stream = static_cast<ServerReaderWriter<RemoteExecResponse, RemoteExecRequest> *>(context);
|
||||||
|
RemoteExecResponse response;
|
||||||
|
response.set_stderr((char *)data, len);
|
||||||
|
if (!stream->Write(response)) {
|
||||||
|
ERROR("Failed to write request to grpc client");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return (ssize_t)len;
|
||||||
|
}
|
||||||
|
|
||||||
class RemoteExecReceiveFromClientTask : public StoppableThread {
|
class RemoteExecReceiveFromClientTask : public StoppableThread {
|
||||||
public:
|
public:
|
||||||
|
RemoteExecReceiveFromClientTask() = default;
|
||||||
RemoteExecReceiveFromClientTask(ServerReaderWriter<RemoteExecResponse, RemoteExecRequest> *stream,
|
RemoteExecReceiveFromClientTask(ServerReaderWriter<RemoteExecResponse, RemoteExecRequest> *stream,
|
||||||
int read_pipe_fd) : m_stream(stream), m_read_pipe_fd(read_pipe_fd) {}
|
int read_pipe_fd) : m_stream(stream), m_read_pipe_fd(read_pipe_fd) {}
|
||||||
~RemoteExecReceiveFromClientTask() = default;
|
~RemoteExecReceiveFromClientTask() = default;
|
||||||
|
void SetStream(ServerReaderWriter<RemoteExecResponse, RemoteExecRequest> *stream)
|
||||||
|
{
|
||||||
|
m_stream = stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetReadPipeFd(int read_pipe_fd)
|
||||||
|
{
|
||||||
|
m_read_pipe_fd = read_pipe_fd;
|
||||||
|
}
|
||||||
|
|
||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
@ -688,44 +713,60 @@ Status ContainerServiceImpl::RemoteExec(ServerContext *context,
|
|||||||
return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback");
|
return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback");
|
||||||
}
|
}
|
||||||
|
|
||||||
int read_pipe_fd[2] = { -1, -1 };
|
|
||||||
if ((pipe2(read_pipe_fd, O_NONBLOCK | O_CLOEXEC)) < 0) {
|
|
||||||
ERROR("create read pipe(grpc server to lxc pipe) fail!");
|
|
||||||
return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback");
|
|
||||||
}
|
|
||||||
std::string errmsg;
|
std::string errmsg;
|
||||||
if (remote_exec_request_from_stream(context, &container_req, errmsg) != 0) {
|
if (remote_exec_request_from_stream(context, &container_req, errmsg) != 0) {
|
||||||
ERROR("Failed to transform grpc request!");
|
ERROR("Failed to transform grpc request!");
|
||||||
return Status(StatusCode::UNKNOWN, errmsg);
|
return Status(StatusCode::UNKNOWN, errmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteExecReceiveFromClientTask receive_task(stream, read_pipe_fd[1]);
|
int read_pipe_fd[2] = { -1, -1 };
|
||||||
std::thread command_writer([&]() {
|
RemoteExecReceiveFromClientTask receive_task;
|
||||||
receive_task.run();
|
std::thread command_writer;
|
||||||
});
|
if (container_req->attach_stdin) {
|
||||||
|
if ((pipe2(read_pipe_fd, O_NONBLOCK | O_CLOEXEC)) < 0) {
|
||||||
|
ERROR("create read pipe(grpc server to lxc pipe) fail!");
|
||||||
|
return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback");
|
||||||
|
}
|
||||||
|
|
||||||
struct io_write_wrapper stringWriter = { 0 };
|
receive_task.SetStream(stream);
|
||||||
stringWriter.context = (void *)stream;
|
receive_task.SetReadPipeFd(read_pipe_fd[1]);
|
||||||
stringWriter.write_func = WriteExecResponseToRemoteClient;
|
command_writer = std::thread([&]() {
|
||||||
stringWriter.close_func = nullptr;
|
receive_task.run();
|
||||||
(void)cb->container.exec(container_req, &container_res, read_pipe_fd[0], &stringWriter);
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
struct io_write_wrapper StdoutstringWriter = { 0 };
|
||||||
|
StdoutstringWriter.context = (void *)stream;
|
||||||
|
StdoutstringWriter.write_func = WriteExecStdoutResponseToRemoteClient;
|
||||||
|
StdoutstringWriter.close_func = nullptr;
|
||||||
|
struct io_write_wrapper StderrstringWriter = { 0 };
|
||||||
|
StderrstringWriter.context = (void *)stream;
|
||||||
|
StderrstringWriter.write_func = WriteExecStderrResponseToRemoteClient;
|
||||||
|
StderrstringWriter.close_func = nullptr;
|
||||||
|
(void)cb->container.exec(container_req, &container_res, read_pipe_fd[0], &StdoutstringWriter, &StderrstringWriter);
|
||||||
|
|
||||||
RemoteExecResponse finish_response;
|
RemoteExecResponse finish_response;
|
||||||
finish_response.set_finish(true);
|
finish_response.set_finish(true);
|
||||||
|
|
||||||
receive_task.stop();
|
if (container_req->attach_stdin) {
|
||||||
|
receive_task.stop();
|
||||||
|
}
|
||||||
|
|
||||||
if (!stream->Write(finish_response)) {
|
if (!stream->Write(finish_response)) {
|
||||||
ERROR("Failed to write finish request to grpc client");
|
ERROR("Failed to write finish request to grpc client");
|
||||||
return Status(StatusCode::INTERNAL, "Internal errors");
|
return Status(StatusCode::INTERNAL, "Internal errors");
|
||||||
}
|
}
|
||||||
|
|
||||||
command_writer.join();
|
if (container_req->attach_stdin) {
|
||||||
|
command_writer.join();
|
||||||
|
}
|
||||||
add_exec_trailing_metadata(context, container_res);
|
add_exec_trailing_metadata(context, container_res);
|
||||||
free_container_exec_request(container_req);
|
free_container_exec_request(container_req);
|
||||||
free_container_exec_response(container_res);
|
free_container_exec_response(container_res);
|
||||||
close(read_pipe_fd[0]);
|
if (read_pipe_fd[0] != -1) {
|
||||||
close(read_pipe_fd[1]);
|
close(read_pipe_fd[0]);
|
||||||
|
close(read_pipe_fd[1]);
|
||||||
|
}
|
||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -151,6 +151,27 @@ int ImagesServiceImpl::image_remove_request_from_grpc(const DeleteImageRequest *
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ImagesServiceImpl::image_tag_request_from_grpc(const TagImageRequest *grequest,
|
||||||
|
image_tag_image_request **request)
|
||||||
|
{
|
||||||
|
image_tag_image_request *tmpreq = (image_tag_image_request *)util_common_calloc_s(
|
||||||
|
sizeof(image_tag_image_request));
|
||||||
|
if (tmpreq == nullptr) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!grequest->src_name().empty()) {
|
||||||
|
tmpreq->src_name = util_strdup_s(grequest->src_name().c_str());
|
||||||
|
}
|
||||||
|
if (!grequest->dest_name().empty()) {
|
||||||
|
tmpreq->dest_name = util_strdup_s(grequest->dest_name().c_str());
|
||||||
|
}
|
||||||
|
*request = tmpreq;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int ImagesServiceImpl::image_load_request_from_grpc(
|
int ImagesServiceImpl::image_load_request_from_grpc(
|
||||||
const LoadImageRequest *grequest, image_load_image_request **request)
|
const LoadImageRequest *grequest, image_load_image_request **request)
|
||||||
{
|
{
|
||||||
@ -279,6 +300,39 @@ Status ImagesServiceImpl::Delete(ServerContext *context, const DeleteImageReques
|
|||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status ImagesServiceImpl::Tag(ServerContext *context, const TagImageRequest *request, TagImageResponse *reply)
|
||||||
|
{
|
||||||
|
auto status = GrpcServerTlsAuth::auth(context, "image_tag");
|
||||||
|
if (!status.ok()) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
service_callback_t *cb = get_service_callback();
|
||||||
|
if (cb == nullptr || cb->image.tag == nullptr) {
|
||||||
|
return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback");
|
||||||
|
}
|
||||||
|
|
||||||
|
image_tag_image_request *image_req = nullptr;
|
||||||
|
int tret = image_tag_request_from_grpc(request, &image_req);
|
||||||
|
if (tret != 0) {
|
||||||
|
ERROR("Failed to transform grpc request");
|
||||||
|
reply->set_cc(ISULAD_ERR_INPUT);
|
||||||
|
return Status::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
image_tag_image_response *image_res = nullptr;
|
||||||
|
int ret = cb->image.tag(image_req, &image_res);
|
||||||
|
tret = response_to_grpc(image_res, reply);
|
||||||
|
|
||||||
|
free_image_tag_image_request(image_req);
|
||||||
|
free_image_tag_image_response(image_res);
|
||||||
|
if (tret != 0) {
|
||||||
|
reply->set_errmsg(util_strdup_s(errno_to_error_message(ISULAD_ERR_INTERNAL)));
|
||||||
|
reply->set_cc(ISULAD_ERR_INPUT);
|
||||||
|
ERROR("Failed to translate response to grpc, operation is %s", ret ? "failed" : "success");
|
||||||
|
}
|
||||||
|
return Status::OK;
|
||||||
|
}
|
||||||
|
|
||||||
Status ImagesServiceImpl::Load(ServerContext *context, const LoadImageRequest *request, LoadImageResponse *reply)
|
Status ImagesServiceImpl::Load(ServerContext *context, const LoadImageRequest *request, LoadImageResponse *reply)
|
||||||
{
|
{
|
||||||
auto status = GrpcServerTlsAuth::auth(context, "image_load");
|
auto status = GrpcServerTlsAuth::auth(context, "image_load");
|
||||||
|
|||||||
@ -47,6 +47,8 @@ public:
|
|||||||
|
|
||||||
Status Delete(ServerContext *context, const DeleteImageRequest *request, DeleteImageResponse *reply) override;
|
Status Delete(ServerContext *context, const DeleteImageRequest *request, DeleteImageResponse *reply) override;
|
||||||
|
|
||||||
|
Status Tag(ServerContext *context, const TagImageRequest *request, TagImageResponse *reply) override;
|
||||||
|
|
||||||
Status Load(ServerContext *context, const LoadImageRequest *request, LoadImageResponse *reply) override;
|
Status Load(ServerContext *context, const LoadImageRequest *request, LoadImageResponse *reply) override;
|
||||||
|
|
||||||
Status Inspect(ServerContext *context, const InspectImageRequest *request, InspectImageResponse *reply) override;
|
Status Inspect(ServerContext *context, const InspectImageRequest *request, InspectImageResponse *reply) override;
|
||||||
@ -77,6 +79,8 @@ private:
|
|||||||
|
|
||||||
int image_remove_request_from_grpc(const DeleteImageRequest *grequest, image_delete_image_request **request);
|
int image_remove_request_from_grpc(const DeleteImageRequest *grequest, image_delete_image_request **request);
|
||||||
|
|
||||||
|
int image_tag_request_from_grpc(const TagImageRequest *grequest, image_tag_image_request **request);
|
||||||
|
|
||||||
int image_load_request_from_grpc(const LoadImageRequest *grequest, image_load_image_request **request);
|
int image_load_request_from_grpc(const LoadImageRequest *grequest, image_load_image_request **request);
|
||||||
|
|
||||||
int inspect_request_from_grpc(const InspectImageRequest *grequest, image_inspect_request **request);
|
int inspect_request_from_grpc(const InspectImageRequest *grequest, image_inspect_request **request);
|
||||||
|
|||||||
@ -945,7 +945,7 @@ static void rest_exec_cb(evhtp_request_t *req, void *arg)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)cb->container.exec(crequest, &cresponse, -1, NULL);
|
(void)cb->container.exec(crequest, &cresponse, -1, NULL, NULL);
|
||||||
|
|
||||||
evhtp_send_exec_repsponse(req, cresponse, RESTFUL_RES_OK);
|
evhtp_send_exec_repsponse(req, cresponse, RESTFUL_RES_OK);
|
||||||
out:
|
out:
|
||||||
|
|||||||
@ -408,6 +408,34 @@ bool util_valid_digest(const char *digest)
|
|||||||
return util_reg_match(patten, digest) == 0;
|
return util_reg_match(patten, digest) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool util_valid_tag(const char *tag)
|
||||||
|
{
|
||||||
|
char *patten = "^[a-f0-9]{64}$";
|
||||||
|
|
||||||
|
if (tag == NULL) {
|
||||||
|
ERROR("invalid NULL param");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(tag) >= strlen(SHA256_PREFIX) && !strncasecmp(tag, SHA256_PREFIX, strlen(SHA256_PREFIX))) {
|
||||||
|
ERROR("tag must not prefixed with \"sha256:\"");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cannot specify 64-byte hexadecimal strings
|
||||||
|
if (util_reg_match(patten, tag) == 0) {
|
||||||
|
ERROR("cannot specify 64-byte hexadecimal strings");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!util_valid_image_name(tag)) {
|
||||||
|
ERROR("Not a valid image name");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool util_valid_file(const char *path, uint32_t fmod)
|
bool util_valid_file(const char *path, uint32_t fmod)
|
||||||
{
|
{
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
|||||||
@ -56,6 +56,8 @@ bool util_valid_file(const char *path, uint32_t fmod);
|
|||||||
|
|
||||||
bool util_valid_digest(const char *digest);
|
bool util_valid_digest(const char *digest);
|
||||||
|
|
||||||
|
bool util_valid_tag(const char *tag);
|
||||||
|
|
||||||
bool util_valid_digest_file(const char *path, const char *digest);
|
bool util_valid_digest_file(const char *path, const char *digest);
|
||||||
|
|
||||||
bool util_valid_key_type(const char *key);
|
bool util_valid_key_type(const char *key);
|
||||||
|
|||||||
@ -89,8 +89,9 @@ static int engine_routine_log_init(const struct engine_operation *eop)
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
goto unlock_out;
|
goto unlock_out;
|
||||||
}
|
}
|
||||||
|
// log throught fifo, so we need disable stderr by quiet (set to 1)
|
||||||
ret = eop->engine_log_init_op(args->progname, engine_log_path, args->json_confs->log_level, eop->engine_type,
|
ret = eop->engine_log_init_op(args->progname, engine_log_path, args->json_confs->log_level, eop->engine_type,
|
||||||
args->quiet, NULL);
|
1, NULL);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto unlock_out;
|
goto unlock_out;
|
||||||
|
|||||||
@ -124,6 +124,9 @@ typedef struct _engine_exec_request_t {
|
|||||||
int64_t timeout;
|
int64_t timeout;
|
||||||
|
|
||||||
const char *suffix;
|
const char *suffix;
|
||||||
|
|
||||||
|
bool tty;
|
||||||
|
bool open_stdin;
|
||||||
} engine_exec_request_t;
|
} engine_exec_request_t;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -83,7 +83,7 @@ static int embedded_merge_env(const embedded_config *config, container_config *c
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < container_spec->env_len; j++) {
|
for (j = 0; j < container_spec->env_len; j++) {
|
||||||
custom_kv = util_string_split(container_spec->env[i], '=');
|
custom_kv = util_string_split(container_spec->env[j], '=');
|
||||||
if (custom_kv == NULL) {
|
if (custom_kv == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -112,8 +112,7 @@ out:
|
|||||||
static int merge_embedded_config(const embedded_manifest *manifest, container_config *container_spec)
|
static int merge_embedded_config(const embedded_manifest *manifest, container_config *container_spec)
|
||||||
{
|
{
|
||||||
if (manifest->config != NULL) {
|
if (manifest->config != NULL) {
|
||||||
if (manifest->config->workdir != NULL) {
|
if (container_spec->working_dir == NULL) {
|
||||||
free(container_spec->working_dir);
|
|
||||||
container_spec->working_dir = util_strdup_s(manifest->config->workdir);
|
container_spec->working_dir = util_strdup_s(manifest->config->workdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,8 +174,8 @@ static int embedded_append_mounts(char **volumes, size_t volumes_len, container_
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
size_t new_size = 0;
|
size_t new_size = 0;
|
||||||
size_t old_size = 0;
|
|
||||||
char **temp = NULL;
|
char **temp = NULL;
|
||||||
|
size_t temp_len = 0;
|
||||||
|
|
||||||
if (volumes == NULL || volumes_len == 0) {
|
if (volumes == NULL || volumes_len == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
@ -188,21 +187,29 @@ static int embedded_append_mounts(char **volumes, size_t volumes_len, container_
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
new_size = (container_spec->mounts_len + volumes_len) * sizeof(char *);
|
new_size = (container_spec->mounts_len + volumes_len) * sizeof(char *);
|
||||||
old_size = container_spec->mounts_len * sizeof(char *);
|
temp = util_common_calloc_s(new_size);
|
||||||
ret = mem_realloc((void **)&temp, new_size, container_spec->mounts, old_size);
|
if (temp == NULL) {
|
||||||
if (ret != 0) {
|
|
||||||
ERROR("Failed to realloc memory for mounts");
|
ERROR("Failed to realloc memory for mounts");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
container_spec->mounts = temp;
|
|
||||||
|
|
||||||
for (i = 0; i < volumes_len; i++) {
|
for (i = 0; i < volumes_len; i++) {
|
||||||
container_spec->mounts[container_spec->mounts_len] = util_strdup_s(volumes[i]);
|
temp[temp_len] = util_strdup_s(volumes[i]);
|
||||||
container_spec->mounts_len++;
|
temp_len++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < container_spec->mounts_len; i++) {
|
||||||
|
temp[temp_len] = util_strdup_s(container_spec->mounts[i]);
|
||||||
|
temp_len++;
|
||||||
|
free(container_spec->mounts[i]);
|
||||||
|
container_spec->mounts[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(container_spec->mounts);
|
||||||
|
container_spec->mounts = temp;
|
||||||
|
container_spec->mounts_len = temp_len;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -223,8 +230,7 @@ static int embedded_merge_mounts(const embedded_manifest *manifest, container_co
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = util_grow_array(&mounts, &cap, manifest->layers_len,
|
ret = util_grow_array(&mounts, &cap, manifest->layers_len, manifest->layers_len);
|
||||||
manifest->layers_len);
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ERROR("grow array failed");
|
ERROR("grow array failed");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
|||||||
16
src/image/external/ext_image.c
vendored
16
src/image/external/ext_image.c
vendored
@ -60,16 +60,16 @@ int ext_prepare_rf(const im_prepare_request *request, char **real_rootfs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (real_rootfs != NULL) {
|
if (real_rootfs != NULL) {
|
||||||
if (request->image_name != NULL) {
|
if (request->rootfs != NULL) {
|
||||||
char real_path[PATH_MAX] = { 0 };
|
char real_path[PATH_MAX] = { 0 };
|
||||||
if (request->image_name[0] != '/') {
|
if (request->rootfs[0] != '/') {
|
||||||
ERROR("Rootfs should be absolutely path");
|
ERROR("Rootfs should be absolutely path");
|
||||||
isulad_set_error_message("Rootfs should be absolutely path");
|
isulad_set_error_message("Rootfs should be absolutely path");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (realpath(request->image_name, real_path) == NULL) {
|
if (realpath(request->rootfs, real_path) == NULL) {
|
||||||
ERROR("Failed to clean rootfs path '%s': %s", request->image_name, strerror(errno));
|
ERROR("Failed to clean rootfs path '%s': %s", request->rootfs, strerror(errno));
|
||||||
isulad_set_error_message("Failed to clean rootfs path '%s': %s", request->image_name, strerror(errno));
|
isulad_set_error_message("Failed to clean rootfs path '%s': %s", request->rootfs, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*real_rootfs = util_strdup_s(real_path);
|
*real_rootfs = util_strdup_s(real_path);
|
||||||
@ -128,15 +128,15 @@ int ext_merge_conf(const host_config *host_spec, container_config *container_spe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// No config neeed merge if NULL.
|
// No config neeed merge if NULL.
|
||||||
if (request->ext_config_image == NULL) {
|
if (request->image_name == NULL) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get image's config and merge configs.
|
// Get image's config and merge configs.
|
||||||
resolved_name = oci_resolve_image_name(request->ext_config_image);
|
resolved_name = oci_resolve_image_name(request->image_name);
|
||||||
if (resolved_name == NULL) {
|
if (resolved_name == NULL) {
|
||||||
ERROR("Resolve external config image name failed, image name is %s", request->ext_config_image);
|
ERROR("Resolve external config image name failed, image name is %s", request->image_name);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,6 +62,7 @@ static const struct bim_ops g_embedded_ops = {
|
|||||||
.container_fs_usage = embedded_filesystem_usage,
|
.container_fs_usage = embedded_filesystem_usage,
|
||||||
.get_filesystem_info = NULL,
|
.get_filesystem_info = NULL,
|
||||||
.get_storage_status = NULL,
|
.get_storage_status = NULL,
|
||||||
|
.get_storage_metadata = NULL,
|
||||||
.image_status = NULL,
|
.image_status = NULL,
|
||||||
.load_image = embedded_load_image,
|
.load_image = embedded_load_image,
|
||||||
.pull_image = NULL,
|
.pull_image = NULL,
|
||||||
@ -70,6 +71,7 @@ static const struct bim_ops g_embedded_ops = {
|
|||||||
.logout = NULL,
|
.logout = NULL,
|
||||||
|
|
||||||
.health_check = NULL,
|
.health_check = NULL,
|
||||||
|
.tag_image = NULL,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -97,6 +99,7 @@ static const struct bim_ops g_isula_ops = {
|
|||||||
.container_fs_usage = isula_container_filesystem_usage,
|
.container_fs_usage = isula_container_filesystem_usage,
|
||||||
.get_filesystem_info = isula_get_filesystem_info,
|
.get_filesystem_info = isula_get_filesystem_info,
|
||||||
.get_storage_status = isula_get_storage_status,
|
.get_storage_status = isula_get_storage_status,
|
||||||
|
.get_storage_metadata = isula_get_storage_metadata,
|
||||||
.image_status = oci_status_image,
|
.image_status = oci_status_image,
|
||||||
.load_image = isual_load_image,
|
.load_image = isual_load_image,
|
||||||
.pull_image = isula_pull_rf,
|
.pull_image = isula_pull_rf,
|
||||||
@ -104,6 +107,7 @@ static const struct bim_ops g_isula_ops = {
|
|||||||
.logout = isula_logout,
|
.logout = isula_logout,
|
||||||
|
|
||||||
.health_check = isula_health_check,
|
.health_check = isula_health_check,
|
||||||
|
.tag_image = isula_tag,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -131,12 +135,14 @@ static const struct bim_ops g_ext_ops = {
|
|||||||
.image_status = NULL,
|
.image_status = NULL,
|
||||||
.get_filesystem_info = NULL,
|
.get_filesystem_info = NULL,
|
||||||
.get_storage_status = NULL,
|
.get_storage_status = NULL,
|
||||||
|
.get_storage_metadata = NULL,
|
||||||
.load_image = ext_load_image,
|
.load_image = ext_load_image,
|
||||||
.pull_image = NULL,
|
.pull_image = NULL,
|
||||||
.login = ext_login,
|
.login = ext_login,
|
||||||
.logout = ext_logout,
|
.logout = ext_logout,
|
||||||
|
|
||||||
.health_check = NULL,
|
.health_check = NULL,
|
||||||
|
.tag_image = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct bim_type g_bims[] = {
|
static const struct bim_type g_bims[] = {
|
||||||
@ -322,6 +328,36 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int im_get_storage_metadata(const char *image_type, char *id, im_storage_metadata_response **response)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
const struct bim_type *q = NULL;
|
||||||
|
|
||||||
|
if (image_type == NULL || response == NULL) {
|
||||||
|
ERROR("Image type or response is NULL");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
q = get_bim_by_type(image_type);
|
||||||
|
if (q == NULL) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
if (q->ops->get_storage_metadata == NULL) {
|
||||||
|
ERROR("Get storage metadata umimplements");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = q->ops->get_storage_metadata(id, response);
|
||||||
|
if (ret != 0) {
|
||||||
|
ERROR("Get storage metadata failed");
|
||||||
|
free_im_storage_metadata_response(*response);
|
||||||
|
*response = NULL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int im_get_filesystem_info(const char *image_type, im_fs_info_response **response)
|
int im_get_filesystem_info(const char *image_type, im_fs_info_response **response)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -501,8 +537,8 @@ void free_im_prepare_request(im_prepare_request *request)
|
|||||||
request->image_name = NULL;
|
request->image_name = NULL;
|
||||||
free(request->container_id);
|
free(request->container_id);
|
||||||
request->container_id = NULL;
|
request->container_id = NULL;
|
||||||
free(request->ext_config_image);
|
free(request->rootfs);
|
||||||
request->ext_config_image = NULL;
|
request->rootfs = NULL;
|
||||||
|
|
||||||
free_json_map_string_string(request->storage_opt);
|
free_json_map_string_string(request->storage_opt);
|
||||||
request->storage_opt = NULL;
|
request->storage_opt = NULL;
|
||||||
@ -673,8 +709,7 @@ bool im_config_image_exist(const char *image_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int im_merge_image_config(const char *id, const char *image_type, const char *image_name,
|
int im_merge_image_config(const char *id, const char *image_type, const char *image_name,
|
||||||
const char *ext_config_image,
|
const char *rootfs, host_config *host_spec, container_config *container_spec,
|
||||||
host_config *host_spec, container_config *container_spec,
|
|
||||||
char **real_rootfs)
|
char **real_rootfs)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -687,7 +722,7 @@ int im_merge_image_config(const char *id, const char *image_type, const char *im
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bim = bim_get(image_type, image_name, ext_config_image, id);
|
bim = bim_get(image_type, image_name, rootfs, id);
|
||||||
if (bim == NULL) {
|
if (bim == NULL) {
|
||||||
ERROR("Failed to init bim of image %s", image_name);
|
ERROR("Failed to init bim of image %s", image_name);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
@ -706,7 +741,7 @@ int im_merge_image_config(const char *id, const char *image_type, const char *im
|
|||||||
}
|
}
|
||||||
request->container_id = util_strdup_s(id);
|
request->container_id = util_strdup_s(id);
|
||||||
request->image_name = util_strdup_s(image_name);
|
request->image_name = util_strdup_s(image_name);
|
||||||
request->ext_config_image = util_strdup_s(ext_config_image);
|
request->rootfs = util_strdup_s(rootfs);
|
||||||
if (host_spec != NULL) {
|
if (host_spec != NULL) {
|
||||||
request->storage_opt = host_spec->storage_opt;
|
request->storage_opt = host_spec->storage_opt;
|
||||||
}
|
}
|
||||||
@ -716,7 +751,7 @@ int im_merge_image_config(const char *id, const char *image_type, const char *im
|
|||||||
ret = bim->ops->merge_conf(host_spec, container_spec, request, real_rootfs);
|
ret = bim->ops->merge_conf(host_spec, container_spec, request, real_rootfs);
|
||||||
request->storage_opt = NULL;
|
request->storage_opt = NULL;
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ERROR("Failed to merge image %s config, config image is %s", image_name, ext_config_image);
|
ERROR("Failed to merge image %s config", image_name);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -1394,6 +1429,68 @@ pack_response:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int im_tag_image(const im_tag_request *request, im_tag_response **response)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
char *src_name = NULL;
|
||||||
|
char *dest_name = NULL;
|
||||||
|
const struct bim_type *bim_type = NULL;
|
||||||
|
struct bim *bim = NULL;
|
||||||
|
|
||||||
|
if (request == NULL || response == NULL) {
|
||||||
|
ERROR("Invalid input arguments");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*response = util_common_calloc_s(sizeof(im_remove_response));
|
||||||
|
if (*response == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->src_name.image == NULL || request->dest_name.image == NULL) {
|
||||||
|
ERROR("remove image requires source image ref and dest image ref");
|
||||||
|
isulad_set_error_message("remove image requires source image ref and dest image ref");
|
||||||
|
goto pack_response;
|
||||||
|
}
|
||||||
|
|
||||||
|
src_name = util_strdup_s(request->src_name.image);
|
||||||
|
dest_name = util_strdup_s(request->dest_name.image);
|
||||||
|
|
||||||
|
bim_type = bim_query(src_name);
|
||||||
|
if (bim_type == NULL) {
|
||||||
|
ERROR("No such image:%s", src_name);
|
||||||
|
isulad_set_error_message("No such image:%s", src_name);
|
||||||
|
goto pack_response;
|
||||||
|
}
|
||||||
|
|
||||||
|
bim = bim_get(bim_type->image_type, src_name, NULL, NULL);
|
||||||
|
if (bim == NULL) {
|
||||||
|
ERROR("Failed to init bim for image %s", src_name);
|
||||||
|
goto pack_response;
|
||||||
|
}
|
||||||
|
if (bim->ops->tag_image == NULL) {
|
||||||
|
ERROR("Unimplements tag image in %s", bim->type);
|
||||||
|
goto pack_response;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = bim->ops->tag_image(request);
|
||||||
|
if (ret != 0) {
|
||||||
|
ERROR("Failed to tag image %s to %s", src_name, dest_name);
|
||||||
|
ret = -1;
|
||||||
|
goto pack_response;
|
||||||
|
}
|
||||||
|
|
||||||
|
pack_response:
|
||||||
|
if (g_isulad_errmsg != NULL) {
|
||||||
|
(*response)->errmsg = util_strdup_s(g_isulad_errmsg);
|
||||||
|
}
|
||||||
|
free(src_name);
|
||||||
|
free(dest_name);
|
||||||
|
bim_put(bim);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void free_im_remove_request(im_remove_request *ptr)
|
void free_im_remove_request(im_remove_request *ptr)
|
||||||
{
|
{
|
||||||
if (ptr == NULL) {
|
if (ptr == NULL) {
|
||||||
@ -1417,6 +1514,30 @@ void free_im_remove_response(im_remove_response *ptr)
|
|||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void free_im_tag_request(im_tag_request *ptr)
|
||||||
|
{
|
||||||
|
if (ptr == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free(ptr->src_name.image);
|
||||||
|
ptr->src_name.image = NULL;
|
||||||
|
free(ptr->dest_name.image);
|
||||||
|
ptr->dest_name.image = NULL;
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_im_tag_response(im_tag_response *ptr)
|
||||||
|
{
|
||||||
|
if (ptr == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(ptr->errmsg);
|
||||||
|
ptr->errmsg = NULL;
|
||||||
|
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
static int do_im_inspect_image(struct bim *bim, char **inspected_json)
|
static int do_im_inspect_image(struct bim *bim, char **inspected_json)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -1803,6 +1924,20 @@ void free_im_storage_status_response(im_storage_status_response *ptr)
|
|||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void free_im_storage_metadata_response(im_storage_metadata_response *ptr)
|
||||||
|
{
|
||||||
|
if (ptr == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free_json_map_string_string(ptr->metadata);
|
||||||
|
ptr->metadata = NULL;
|
||||||
|
free(ptr->name);
|
||||||
|
ptr->name = NULL;
|
||||||
|
free(ptr->errmsg);
|
||||||
|
ptr->errmsg = NULL;
|
||||||
|
free(ptr);
|
||||||
|
}
|
||||||
|
|
||||||
void im_sync_containers_isuladkit(void)
|
void im_sync_containers_isuladkit(void)
|
||||||
{
|
{
|
||||||
DEBUG("Sync containers...");
|
DEBUG("Sync containers...");
|
||||||
|
|||||||
@ -58,6 +58,12 @@ typedef struct {
|
|||||||
char *status;
|
char *status;
|
||||||
} im_storage_status_response;
|
} im_storage_status_response;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
json_map_string_string *metadata;
|
||||||
|
char *name;
|
||||||
|
char *errmsg;
|
||||||
|
} im_storage_metadata_response;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
imagetool_fs_info *fs_info;
|
imagetool_fs_info *fs_info;
|
||||||
char *errmsg;
|
char *errmsg;
|
||||||
@ -97,6 +103,15 @@ typedef struct {
|
|||||||
char *errmsg;
|
char *errmsg;
|
||||||
} im_remove_response;
|
} im_remove_response;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
image_spec src_name;
|
||||||
|
image_spec dest_name;
|
||||||
|
} im_tag_request;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *errmsg;
|
||||||
|
} im_tag_response;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
// Spec of the image.
|
// Spec of the image.
|
||||||
image_spec image;
|
image_spec image;
|
||||||
@ -181,7 +196,7 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
char *image_name;
|
char *image_name;
|
||||||
char *container_id;
|
char *container_id;
|
||||||
char *ext_config_image;
|
char *rootfs;
|
||||||
json_map_string_string *storage_opt;
|
json_map_string_string *storage_opt;
|
||||||
} im_prepare_request;
|
} im_prepare_request;
|
||||||
|
|
||||||
@ -238,6 +253,8 @@ struct bim_ops {
|
|||||||
|
|
||||||
int (*get_storage_status)(im_storage_status_response **response);
|
int (*get_storage_status)(im_storage_status_response **response);
|
||||||
|
|
||||||
|
int (*get_storage_metadata)(char *id, im_storage_metadata_response **response);
|
||||||
|
|
||||||
/* load image */
|
/* load image */
|
||||||
int (*load_image)(const im_load_request *request);
|
int (*load_image)(const im_load_request *request);
|
||||||
|
|
||||||
@ -252,6 +269,8 @@ struct bim_ops {
|
|||||||
|
|
||||||
/* health check */
|
/* health check */
|
||||||
int (*health_check)(void);
|
int (*health_check)(void);
|
||||||
|
/* Add a tag to the image */
|
||||||
|
int (*tag_image)(const im_tag_request *request);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bim {
|
struct bim {
|
||||||
@ -292,8 +311,7 @@ int im_umount_container_rootfs(const char *image_type, const char *image_name, c
|
|||||||
int im_remove_container_rootfs(const char *image_type, const char *container_id);
|
int im_remove_container_rootfs(const char *image_type, const char *container_id);
|
||||||
|
|
||||||
int im_merge_image_config(const char *id, const char *image_type, const char *image_name,
|
int im_merge_image_config(const char *id, const char *image_type, const char *image_name,
|
||||||
const char *ext_config_image,
|
const char *rootfs, host_config *host_spec, container_config *container_spec,
|
||||||
host_config *host_spec, container_config *container_spec,
|
|
||||||
char **real_rootfs);
|
char **real_rootfs);
|
||||||
|
|
||||||
int im_get_user_conf(const char *image_type, const char *basefs, host_config *hc, const char *userstr,
|
int im_get_user_conf(const char *image_type, const char *basefs, host_config *hc, const char *userstr,
|
||||||
@ -311,6 +329,12 @@ void free_im_remove_request(im_remove_request *ptr);
|
|||||||
|
|
||||||
void free_im_remove_response(im_remove_response *ptr);
|
void free_im_remove_response(im_remove_response *ptr);
|
||||||
|
|
||||||
|
int im_tag_image(const im_tag_request *request, im_tag_response **response);
|
||||||
|
|
||||||
|
void free_im_tag_request(im_tag_request *ptr);
|
||||||
|
|
||||||
|
void free_im_tag_response(im_tag_response *ptr);
|
||||||
|
|
||||||
int im_inspect_image(const im_inspect_request *request, im_inspect_response **response);
|
int im_inspect_image(const im_inspect_request *request, im_inspect_response **response);
|
||||||
|
|
||||||
void free_im_inspect_request(im_inspect_request *ptr);
|
void free_im_inspect_request(im_inspect_request *ptr);
|
||||||
@ -363,6 +387,10 @@ int im_get_storage_status(const char *image_type, im_storage_status_response **r
|
|||||||
|
|
||||||
void free_im_storage_status_response(im_storage_status_response *ptr);
|
void free_im_storage_status_response(im_storage_status_response *ptr);
|
||||||
|
|
||||||
|
int im_get_storage_metadata(const char *image_type, char *id, im_storage_metadata_response **response);
|
||||||
|
|
||||||
|
void free_im_storage_metadata_response(im_storage_metadata_response *ptr);
|
||||||
|
|
||||||
size_t im_get_image_count(const im_image_count_request *request);
|
size_t im_get_image_count(const im_image_count_request *request);
|
||||||
|
|
||||||
void free_im_image_count_request(im_image_count_request *ptr);
|
void free_im_image_count_request(im_image_count_request *ptr);
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
#include "isula_rootfs_mount.h"
|
#include "isula_rootfs_mount.h"
|
||||||
#include "isula_rootfs_umount.h"
|
#include "isula_rootfs_umount.h"
|
||||||
#include "isula_image_rmi.h"
|
#include "isula_image_rmi.h"
|
||||||
|
#include "isula_image_tag.h"
|
||||||
#include "isula_container_fs_usage.h"
|
#include "isula_container_fs_usage.h"
|
||||||
#include "isula_image_fs_info.h"
|
#include "isula_image_fs_info.h"
|
||||||
#include "isula_storage_status.h"
|
#include "isula_storage_status.h"
|
||||||
@ -36,6 +37,7 @@
|
|||||||
#include "isula_health_check.h"
|
#include "isula_health_check.h"
|
||||||
#include "isula_images_list.h"
|
#include "isula_images_list.h"
|
||||||
#include "isula_containers_list.h"
|
#include "isula_containers_list.h"
|
||||||
|
#include "isula_storage_metadata.h"
|
||||||
|
|
||||||
#include "containers_store.h"
|
#include "containers_store.h"
|
||||||
#include "oci_images_store.h"
|
#include "oci_images_store.h"
|
||||||
@ -263,6 +265,62 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int isula_tag(const im_tag_request *request)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
char *src_name = NULL;
|
||||||
|
char *dest_name = NULL;
|
||||||
|
oci_image_t *image_info = NULL;
|
||||||
|
char *errmsg = NULL;
|
||||||
|
|
||||||
|
if (request == NULL || request->src_name.image == NULL || request->dest_name.image == NULL) {
|
||||||
|
ERROR("Invalid input arguments");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
src_name = oci_resolve_image_name(request->src_name.image);
|
||||||
|
if (src_name == NULL) {
|
||||||
|
ret = -1;
|
||||||
|
ERROR("Failed to resolve source image name");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
dest_name = oci_normalize_image_name(request->dest_name.image);
|
||||||
|
if (src_name == NULL) {
|
||||||
|
ret = -1;
|
||||||
|
ERROR("Failed to resolve source image name");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
image_info = oci_images_store_get(src_name);
|
||||||
|
if (image_info == NULL) {
|
||||||
|
INFO("No such image exist %s", src_name);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
oci_image_lock(image_info);
|
||||||
|
|
||||||
|
ret = isula_image_tag(src_name, dest_name, &errmsg);
|
||||||
|
if (ret != 0) {
|
||||||
|
isulad_set_error_message("Failed to tag image with error: %s", errmsg);
|
||||||
|
ERROR("Failed to tag image '%s' to '%s' with error: %s", src_name, dest_name, errmsg);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = register_new_oci_image_into_memory(dest_name);
|
||||||
|
if (ret != 0) {
|
||||||
|
ERROR("Register image %s into store failed", dest_name);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
oci_image_unlock(image_info);
|
||||||
|
oci_image_unref(image_info);
|
||||||
|
free(src_name);
|
||||||
|
free(dest_name);
|
||||||
|
free(errmsg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int isula_container_filesystem_usage(const im_container_fs_usage_request *request, imagetool_fs_info **fs_usage)
|
int isula_container_filesystem_usage(const im_container_fs_usage_request *request, imagetool_fs_info **fs_usage)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -348,6 +406,35 @@ err_out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int isula_get_storage_metadata(char *id, im_storage_metadata_response **response)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (response == NULL || id == NULL) {
|
||||||
|
ERROR("Invalid input arguments");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
*response = (im_storage_metadata_response *)util_common_calloc_s(sizeof(im_storage_metadata_response));
|
||||||
|
if (*response == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = isula_do_storage_metadata(id, *response);
|
||||||
|
if (ret != 0) {
|
||||||
|
ERROR("Get get storage metadata failed");
|
||||||
|
ret = -1;
|
||||||
|
goto err_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
err_out:
|
||||||
|
free_im_storage_metadata_response(*response);
|
||||||
|
*response = NULL;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int isual_load_image(const im_load_request *request)
|
int isual_load_image(const im_load_request *request)
|
||||||
{
|
{
|
||||||
char **refs = NULL;
|
char **refs = NULL;
|
||||||
|
|||||||
@ -28,6 +28,7 @@ void isula_exit(void);
|
|||||||
|
|
||||||
int isula_pull_rf(const im_pull_request *request, im_pull_response **response);
|
int isula_pull_rf(const im_pull_request *request, im_pull_response **response);
|
||||||
int isula_rmi(const im_remove_request *request);
|
int isula_rmi(const im_remove_request *request);
|
||||||
|
int isula_tag(const im_tag_request *request);
|
||||||
int isula_get_filesystem_info(im_fs_info_response **response);
|
int isula_get_filesystem_info(im_fs_info_response **response);
|
||||||
int isual_load_image(const im_load_request *request);
|
int isual_load_image(const im_load_request *request);
|
||||||
|
|
||||||
@ -41,6 +42,7 @@ int isula_export_rf(const im_export_request *request);
|
|||||||
int isula_container_filesystem_usage(const im_container_fs_usage_request *request, imagetool_fs_info **fs_usage);
|
int isula_container_filesystem_usage(const im_container_fs_usage_request *request, imagetool_fs_info **fs_usage);
|
||||||
|
|
||||||
int isula_get_storage_status(im_storage_status_response **response);
|
int isula_get_storage_status(im_storage_status_response **response);
|
||||||
|
int isula_get_storage_metadata(char *id, im_storage_metadata_response **response);
|
||||||
|
|
||||||
int isula_login(const im_login_request *request);
|
int isula_login(const im_login_request *request);
|
||||||
int isula_logout(const im_logout_request *request);
|
int isula_logout(const im_logout_request *request);
|
||||||
|
|||||||
@ -97,6 +97,9 @@ static void pack_imagetool_image(struct image_metadata *data, imagetool_image **
|
|||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmp_img->healthcheck = data->health_check;
|
||||||
|
data->health_check = NULL;
|
||||||
|
|
||||||
free(err);
|
free(err);
|
||||||
*image = tmp_img;
|
*image = tmp_img;
|
||||||
return;
|
return;
|
||||||
|
|||||||
107
src/image/oci/isula_image_tag.c
Normal file
107
src/image/oci/isula_image_tag.c
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||||
|
* iSulad licensed under the Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
* PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
* Author: wangfengtu
|
||||||
|
* Create: 2020-04-15
|
||||||
|
* Description: isula image tag operator implement
|
||||||
|
*******************************************************************************/
|
||||||
|
#include "isula_image_tag.h"
|
||||||
|
|
||||||
|
#include "isula_image_connect.h"
|
||||||
|
#include "isula_helper.h"
|
||||||
|
#include "connect.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
static int generate_isula_tag_request(const char *src_name, const char *dest_name, struct isula_tag_request **ireq)
|
||||||
|
{
|
||||||
|
struct isula_tag_request *tmp_req = NULL;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if (src_name == NULL || dest_name == NULL || ireq == NULL) {
|
||||||
|
ERROR("Required image name");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
tmp_req = (struct isula_tag_request *)util_common_calloc_s(sizeof(struct isula_tag_request));
|
||||||
|
if (tmp_req == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp_req->src_name = (struct image_spec *)util_common_calloc_s(sizeof(struct image_spec));
|
||||||
|
if (tmp_req->src_name == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp_req->dest_name = (struct image_spec *)util_common_calloc_s(sizeof(struct image_spec));
|
||||||
|
if (tmp_req->dest_name == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp_req->src_name->image = util_strdup_s(src_name);
|
||||||
|
tmp_req->dest_name->image = util_strdup_s(dest_name);
|
||||||
|
|
||||||
|
out:
|
||||||
|
*ireq = tmp_req;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int isula_image_tag(const char *src_name, const char *dest_name, char **errmsg)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
struct isula_tag_request *ireq = NULL;
|
||||||
|
struct isula_tag_response *iresp = NULL;
|
||||||
|
client_connect_config_t conf = { 0 };
|
||||||
|
isula_image_ops *im_ops = NULL;
|
||||||
|
|
||||||
|
im_ops = get_isula_image_ops();
|
||||||
|
if (im_ops == NULL) {
|
||||||
|
ERROR("Don't init isula server grpc client");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (im_ops->tag == NULL) {
|
||||||
|
ERROR("Umimplement tag operator");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = generate_isula_tag_request(src_name, dest_name, &ireq);
|
||||||
|
if (ret != 0) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
iresp = (struct isula_tag_response *)util_common_calloc_s(sizeof(struct isula_tag_response));
|
||||||
|
if (iresp == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = get_isula_image_connect_config(&conf);
|
||||||
|
if (ret != 0) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
INFO("Send remove image GRPC request");
|
||||||
|
ret = im_ops->tag(ireq, iresp, &conf);
|
||||||
|
if (ret != 0) {
|
||||||
|
ERROR("Tag image %s to %s failed: %s", src_name, dest_name, iresp->errmsg);
|
||||||
|
}
|
||||||
|
*errmsg = iresp->errmsg;
|
||||||
|
iresp->errmsg = NULL;
|
||||||
|
|
||||||
|
out:
|
||||||
|
free_isula_tag_request(ireq);
|
||||||
|
free_isula_tag_response(iresp);
|
||||||
|
free_client_connect_config_value(&conf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
30
src/image/oci/isula_image_tag.h
Normal file
30
src/image/oci/isula_image_tag.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||||
|
* iSulad licensed under the Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
* PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
* Author: wangfengtu
|
||||||
|
* Create: 2020-04-15
|
||||||
|
* Description: isula image tag operator implement
|
||||||
|
*******************************************************************************/
|
||||||
|
#ifndef __IMAGE_ISULA_IMAGE_TAG_H
|
||||||
|
#define __IMAGE_ISULA_IMAGE_TAG_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int isula_image_tag(const char *src_name, const char *dest_name, char **errmsg);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -89,6 +89,9 @@ static int pack_imagetool_image(struct image_metadata *data, imagetool_image **i
|
|||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tmp_img->healthcheck = data->health_check;
|
||||||
|
data->health_check = NULL;
|
||||||
|
|
||||||
free(err);
|
free(err);
|
||||||
*image = tmp_img;
|
*image = tmp_img;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
78
src/image/oci/isula_storage_metadata.c
Normal file
78
src/image/oci/isula_storage_metadata.c
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||||
|
* iSulad licensed under the Mulan PSL v1.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v1.
|
||||||
|
* You may obtain a copy of Mulan PSL v1 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
* PURPOSE.
|
||||||
|
* See the Mulan PSL v1 for more details.
|
||||||
|
* Author: liuhao
|
||||||
|
* Create: 2020-03-24
|
||||||
|
* Description: isula storage metadata operator implement
|
||||||
|
*******************************************************************************/
|
||||||
|
#include "isula_storage_metadata.h"
|
||||||
|
|
||||||
|
#include "isula_image_connect.h"
|
||||||
|
#include "isula_helper.h"
|
||||||
|
#include "connect.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
int isula_do_storage_metadata(char *id, im_storage_metadata_response *resp)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int nret = -1;
|
||||||
|
struct isula_storage_metadata_request ireq;
|
||||||
|
struct isula_storage_metadata_response *iresp = NULL;
|
||||||
|
client_connect_config_t conf = { 0 };
|
||||||
|
isula_image_ops *im_ops = NULL;
|
||||||
|
|
||||||
|
if (resp == NULL || id == NULL) {
|
||||||
|
ERROR("Invalid arguments");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
im_ops = get_isula_image_ops();
|
||||||
|
if (im_ops == NULL) {
|
||||||
|
ERROR("Failed to init isula server grpc client");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (im_ops->storage_metadata == NULL) {
|
||||||
|
ERROR("Umimplement get storage metadata operator");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
iresp = util_common_calloc_s(sizeof(struct isula_storage_metadata_response));
|
||||||
|
if (iresp == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
nret = get_isula_image_connect_config(&conf);
|
||||||
|
if (nret != 0) {
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ireq.container_id = id;
|
||||||
|
nret = im_ops->storage_metadata(&ireq, iresp, &conf);
|
||||||
|
if (nret != 0) {
|
||||||
|
ERROR("Failed to get storage metadata with error: %s", iresp->errmsg);
|
||||||
|
isulad_set_error_message("Failed to get storage metadata with error: %s", iresp->errmsg);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
resp->metadata = iresp->metadata;
|
||||||
|
iresp->metadata = NULL;
|
||||||
|
resp->name = util_strdup_s(iresp->name);
|
||||||
|
resp->errmsg = util_strdup_s(iresp->errmsg);
|
||||||
|
|
||||||
|
out:
|
||||||
|
free_isula_storage_metadata_response(iresp);
|
||||||
|
free_client_connect_config_value(&conf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
30
src/image/oci/isula_storage_metadata.h
Normal file
30
src/image/oci/isula_storage_metadata.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
|
||||||
|
* iSulad licensed under the Mulan PSL v1.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v1.
|
||||||
|
* You may obtain a copy of Mulan PSL v1 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
* PURPOSE.
|
||||||
|
* See the Mulan PSL v1 for more details.
|
||||||
|
* Author: liuhao
|
||||||
|
* Create: 2020-03-23
|
||||||
|
* Description: isula storage metadata operator implement
|
||||||
|
*******************************************************************************/
|
||||||
|
#ifndef __IMAGE_ISULA_STORAGE_METADATA_H
|
||||||
|
#define __IMAGE_ISULA_STORAGE_METADATA_H
|
||||||
|
|
||||||
|
#include "image.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int isula_do_storage_metadata(char *id, im_storage_metadata_response *resp);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@ -27,11 +27,10 @@
|
|||||||
|
|
||||||
static void oci_image_merge_working_dir(const char *working_dir, container_config *container_spec)
|
static void oci_image_merge_working_dir(const char *working_dir, container_config *container_spec)
|
||||||
{
|
{
|
||||||
if (working_dir == NULL) {
|
if (container_spec->working_dir != NULL || working_dir == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(container_spec->working_dir);
|
|
||||||
container_spec->working_dir = util_strdup_s(working_dir);
|
container_spec->working_dir = util_strdup_s(working_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +73,7 @@ static int oci_image_merge_env(const oci_image_spec_config *config, container_co
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < container_spec->env_len; j++) {
|
for (j = 0; j < container_spec->env_len; j++) {
|
||||||
custom_kv = util_string_split(container_spec->env[i], '=');
|
custom_kv = util_string_split(container_spec->env[j], '=');
|
||||||
if (custom_kv == NULL) {
|
if (custom_kv == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,6 +90,40 @@
|
|||||||
"HostConfig":{
|
"HostConfig":{
|
||||||
"$ref": "../host-config.json"
|
"$ref": "../host-config.json"
|
||||||
},
|
},
|
||||||
|
"GraphDriver":{
|
||||||
|
"type":"object",
|
||||||
|
"properties":{
|
||||||
|
"Data": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"LowerDir":{
|
||||||
|
"type":"string"
|
||||||
|
},
|
||||||
|
"MergedDir":{
|
||||||
|
"type":"string"
|
||||||
|
},
|
||||||
|
"UpperDir":{
|
||||||
|
"type":"string"
|
||||||
|
},
|
||||||
|
"WorkDir":{
|
||||||
|
"type":"string"
|
||||||
|
},
|
||||||
|
"DeviceId":{
|
||||||
|
"type":"string"
|
||||||
|
},
|
||||||
|
"DeviceName":{
|
||||||
|
"type":"string"
|
||||||
|
},
|
||||||
|
"DeviceSize":{
|
||||||
|
"type":"string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"Mounts": {
|
"Mounts": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
|
|||||||
12
src/json/schema/schema/image/tag-image-request.json
Normal file
12
src/json/schema/schema/image/tag-image-request.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"src_name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"dest_name": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/json/schema/schema/image/tag-image-response.json
Normal file
12
src/json/schema/schema/image/tag-image-response.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"cc": {
|
||||||
|
"type": "uint32"
|
||||||
|
},
|
||||||
|
"errmsg": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1184,6 +1184,36 @@ void isula_rmi_response_free(struct isula_rmi_response *response)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* isula tag request free */
|
||||||
|
void isula_tag_request_free(struct isula_tag_request *request)
|
||||||
|
{
|
||||||
|
if (request == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(request->src_name);
|
||||||
|
request->src_name = NULL;
|
||||||
|
free(request->dest_name);
|
||||||
|
request->dest_name = NULL;
|
||||||
|
|
||||||
|
free(request);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* isula tag response free */
|
||||||
|
void isula_tag_response_free(struct isula_tag_response *response)
|
||||||
|
{
|
||||||
|
if (response == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(response->errmsg);
|
||||||
|
response->errmsg = NULL;
|
||||||
|
|
||||||
|
free(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* isula pull response free */
|
/* isula pull response free */
|
||||||
void isula_pull_request_free(struct isula_pull_request *request)
|
void isula_pull_request_free(struct isula_pull_request *request)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -609,6 +609,17 @@ struct isula_pull_request {
|
|||||||
char *image_name;
|
char *image_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct isula_tag_request {
|
||||||
|
char *src_name;
|
||||||
|
char *dest_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct isula_tag_response {
|
||||||
|
uint32_t cc;
|
||||||
|
uint32_t server_errono;
|
||||||
|
char *errmsg;
|
||||||
|
};
|
||||||
|
|
||||||
struct isula_pull_response {
|
struct isula_pull_response {
|
||||||
char *image_ref;
|
char *image_ref;
|
||||||
uint32_t cc;
|
uint32_t cc;
|
||||||
@ -812,6 +823,10 @@ void isula_rmi_request_free(struct isula_rmi_request *request);
|
|||||||
|
|
||||||
void isula_rmi_response_free(struct isula_rmi_response *response);
|
void isula_rmi_response_free(struct isula_rmi_response *response);
|
||||||
|
|
||||||
|
void isula_tag_request_free(struct isula_tag_request *request);
|
||||||
|
|
||||||
|
void isula_tag_response_free(struct isula_tag_response *response);
|
||||||
|
|
||||||
void isula_load_request_free(struct isula_load_request *request);
|
void isula_load_request_free(struct isula_load_request *request);
|
||||||
|
|
||||||
void isula_load_response_free(struct isula_load_response *response);
|
void isula_load_response_free(struct isula_load_response *response);
|
||||||
|
|||||||
@ -65,6 +65,8 @@
|
|||||||
#define PluginServicePostStop "/PluginService/PostStop"
|
#define PluginServicePostStop "/PluginService/PostStop"
|
||||||
#define PluginServicePostRemove "/PluginService/PostRemove"
|
#define PluginServicePostRemove "/PluginService/PostRemove"
|
||||||
|
|
||||||
|
static plugin_manager_t *g_plugin_manager;
|
||||||
|
|
||||||
static int pm_init_plugin(const plugin_t *plugin);
|
static int pm_init_plugin(const plugin_t *plugin);
|
||||||
|
|
||||||
static int plugin_event_pre_start_handle(const plugin_t *plugin, const char *cid);
|
static int plugin_event_pre_start_handle(const plugin_t *plugin, const char *cid);
|
||||||
|
|||||||
@ -78,8 +78,6 @@ typedef struct plugin_manager {
|
|||||||
map_t *eps; /* watch_event:plugins */
|
map_t *eps; /* watch_event:plugins */
|
||||||
} plugin_manager_t;
|
} plugin_manager_t;
|
||||||
|
|
||||||
plugin_manager_t *g_plugin_manager;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* init at isulad start, scan and init/sync all plugins
|
* init at isulad start, scan and init/sync all plugins
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -382,6 +382,11 @@ int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *par
|
|||||||
request.user = user;
|
request.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
request.open_stdin = params->attach_stdin;
|
||||||
|
if (params->spec != NULL) {
|
||||||
|
request.tty = params->spec->terminal;
|
||||||
|
}
|
||||||
|
|
||||||
if (!engine_ops->engine_exec_op(&request, exit_code)) {
|
if (!engine_ops->engine_exec_op(&request, exit_code)) {
|
||||||
const char *tmpmsg = NULL;
|
const char *tmpmsg = NULL;
|
||||||
if (engine_ops->engine_get_errmsg_op != NULL) {
|
if (engine_ops->engine_get_errmsg_op != NULL) {
|
||||||
|
|||||||
@ -93,6 +93,7 @@ typedef struct _rt_exec_params_t {
|
|||||||
int64_t timeout;
|
int64_t timeout;
|
||||||
const char *suffix;
|
const char *suffix;
|
||||||
defs_process *spec;
|
defs_process *spec;
|
||||||
|
bool attach_stdin;
|
||||||
} rt_exec_params_t;
|
} rt_exec_params_t;
|
||||||
|
|
||||||
typedef struct _rt_pause_params_t {
|
typedef struct _rt_pause_params_t {
|
||||||
|
|||||||
@ -60,6 +60,8 @@
|
|||||||
#include "host_info_response.h"
|
#include "host_info_response.h"
|
||||||
#include "image_delete_image_request.h"
|
#include "image_delete_image_request.h"
|
||||||
#include "image_delete_image_response.h"
|
#include "image_delete_image_response.h"
|
||||||
|
#include "image_tag_image_request.h"
|
||||||
|
#include "image_tag_image_response.h"
|
||||||
#include "image_load_image_request.h"
|
#include "image_load_image_request.h"
|
||||||
#include "image_load_image_response.h"
|
#include "image_load_image_response.h"
|
||||||
#include "image_inspect_request.h"
|
#include "image_inspect_request.h"
|
||||||
@ -111,7 +113,7 @@ typedef struct {
|
|||||||
int(*list)(const container_list_request *request, container_list_response **response);
|
int(*list)(const container_list_request *request, container_list_response **response);
|
||||||
|
|
||||||
int(*exec)(const container_exec_request *request, container_exec_response **response,
|
int(*exec)(const container_exec_request *request, container_exec_response **response,
|
||||||
int stdinfd, struct io_write_wrapper *stdout);
|
int stdinfd, struct io_write_wrapper *stdout, struct io_write_wrapper *stderr);
|
||||||
|
|
||||||
int(*attach)(const container_attach_request *request, container_attach_response **response,
|
int(*attach)(const container_attach_request *request, container_attach_response **response,
|
||||||
int stdinfd, struct io_write_wrapper *stdout, struct io_write_wrapper *stderr);
|
int stdinfd, struct io_write_wrapper *stdout, struct io_write_wrapper *stderr);
|
||||||
@ -157,6 +159,8 @@ typedef struct {
|
|||||||
int(*login)(const image_login_request *request, image_login_response **response);
|
int(*login)(const image_login_request *request, image_login_response **response);
|
||||||
|
|
||||||
int(*logout)(const image_logout_request *request, image_logout_response **response);
|
int(*logout)(const image_logout_request *request, image_logout_response **response);
|
||||||
|
|
||||||
|
int(*tag)(const image_tag_image_request *request, image_tag_image_response **response);
|
||||||
} service_image_callback_t;
|
} service_image_callback_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@ -1308,8 +1308,8 @@ void CRIRuntimeServiceImpl::ExecSyncFromGRPC(const std::string &containerID,
|
|||||||
error.SetError("Out of memory");
|
error.SetError("Out of memory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(*request)->tty = true;
|
(*request)->tty = false;
|
||||||
(*request)->attach_stdin = true;
|
(*request)->attach_stdin = false;
|
||||||
(*request)->attach_stdout = true;
|
(*request)->attach_stdout = true;
|
||||||
(*request)->attach_stderr = true;
|
(*request)->attach_stderr = true;
|
||||||
(*request)->timeout = timeout;
|
(*request)->timeout = timeout;
|
||||||
@ -1335,7 +1335,8 @@ void CRIRuntimeServiceImpl::ExecSync(const std::string &containerID,
|
|||||||
const google::protobuf::RepeatedPtrField<std::string> &cmd, int64_t timeout,
|
const google::protobuf::RepeatedPtrField<std::string> &cmd, int64_t timeout,
|
||||||
runtime::v1alpha2::ExecSyncResponse *reply, Errors &error)
|
runtime::v1alpha2::ExecSyncResponse *reply, Errors &error)
|
||||||
{
|
{
|
||||||
struct io_write_wrapper stringWriter = { 0 };
|
struct io_write_wrapper StdoutstringWriter = { 0 };
|
||||||
|
struct io_write_wrapper StderrstringWriter = { 0 };
|
||||||
|
|
||||||
if (m_cb == nullptr || m_cb->container.exec == nullptr) {
|
if (m_cb == nullptr || m_cb->container.exec == nullptr) {
|
||||||
error.SetError("Unimplemented callback");
|
error.SetError("Unimplemented callback");
|
||||||
@ -1361,9 +1362,12 @@ void CRIRuntimeServiceImpl::ExecSync(const std::string &containerID,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
stringWriter.context = (void *)reply->mutable_stdout();
|
StdoutstringWriter.context = (void *)reply->mutable_stdout();
|
||||||
stringWriter.write_func = WriteToString;
|
StdoutstringWriter.write_func = WriteToString;
|
||||||
if (m_cb->container.exec(request, &response, -1, &stringWriter)) {
|
|
||||||
|
StderrstringWriter.context = (void *)reply->mutable_stderr();
|
||||||
|
StderrstringWriter.write_func = WriteToString;
|
||||||
|
if (m_cb->container.exec(request, &response, -1, &StdoutstringWriter, &StderrstringWriter)) {
|
||||||
if (response != nullptr && response->errmsg != nullptr) {
|
if (response != nullptr && response->errmsg != nullptr) {
|
||||||
error.SetError(response->errmsg);
|
error.SetError(response->errmsg);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -256,8 +256,7 @@ static int umount_dev_tmpfs_for_system_container(const container_t *cont)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (umount(rootfs_dev_path) < 0 && errno != ENOENT) {
|
if (umount(rootfs_dev_path) < 0 && errno != ENOENT) {
|
||||||
ERROR("Failed to umount dev tmpfs: %s, error: %s", rootfs_dev_path, strerror(errno));
|
WARN("Failed to umount dev tmpfs: %s, error: %s", rootfs_dev_path, strerror(errno));
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -699,12 +698,12 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_env_to_target_file(const container_t *cont)
|
static int write_env_to_target_file(const container_t *cont, const oci_runtime_spec *oci_spec)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *env_path = NULL;
|
char *env_path = NULL;
|
||||||
|
|
||||||
if (cont->hostconfig->env_target_file == NULL || cont->common_config->config == NULL) {
|
if (cont->hostconfig->env_target_file == NULL || oci_spec->process == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
env_path = util_path_join(cont->common_config->base_fs, cont->hostconfig->env_target_file);
|
env_path = util_path_join(cont->common_config->base_fs, cont->hostconfig->env_target_file);
|
||||||
@ -713,8 +712,8 @@ static int write_env_to_target_file(const container_t *cont)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = write_env_content(env_path,
|
ret = write_env_content(env_path,
|
||||||
(const char **)cont->common_config->config->env,
|
(const char **)oci_spec->process->env,
|
||||||
cont->common_config->config->env_len);
|
oci_spec->process->env_len);
|
||||||
free(env_path);
|
free(env_path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -810,11 +809,6 @@ static int do_start_container(container_t *cont, const char *console_fifos[], bo
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write_env_to_target_file(cont) < 0) {
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reset_rm && !reset_restart_manager(cont, true)) {
|
if (reset_rm && !reset_restart_manager(cont, true)) {
|
||||||
ERROR("Failed to reset restart manager");
|
ERROR("Failed to reset restart manager");
|
||||||
isulad_set_error_message("Failed to reset restart manager");
|
isulad_set_error_message("Failed to reset restart manager");
|
||||||
@ -840,6 +834,11 @@ static int do_start_container(container_t *cont, const char *console_fifos[], bo
|
|||||||
goto close_exit_fd;
|
goto close_exit_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (write_env_to_target_file(cont, oci_spec) < 0) {
|
||||||
|
ret = -1;
|
||||||
|
goto close_exit_fd;
|
||||||
|
}
|
||||||
|
|
||||||
nret = im_mount_container_rootfs(cont->common_config->image_type, cont->common_config->image, id);
|
nret = im_mount_container_rootfs(cont->common_config->image_type, cont->common_config->image, id);
|
||||||
if (nret != 0) {
|
if (nret != 0) {
|
||||||
ERROR("Failed to mount rootfs for container %s", id);
|
ERROR("Failed to mount rootfs for container %s", id);
|
||||||
|
|||||||
@ -742,27 +742,21 @@ static int get_request_container_info(const container_create_request *request, c
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_request_image_info(const container_create_request *request, char **image_type,
|
static int get_request_image_info(const container_create_request *request, char **image_type, char **image_name)
|
||||||
const char **ext_config_image, const char **image_name)
|
|
||||||
{
|
{
|
||||||
*image_type = im_get_image_type(request->image, request->rootfs);
|
*image_type = im_get_image_type(request->image, request->rootfs);
|
||||||
if (*image_type == NULL) {
|
if (*image_type == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->rootfs != NULL) {
|
// Do not use none image because none image has no config.
|
||||||
*image_name = request->rootfs;
|
if (strcmp(request->image, "none") && strcmp(request->image, "none:latest")) {
|
||||||
// Do not use none image because none image has no config.
|
*image_name = util_strdup_s(request->image);
|
||||||
if (strcmp(request->image, "none") && strcmp(request->image, "none:latest")) {
|
|
||||||
*ext_config_image = request->image;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
*image_name = request->image;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if config image exist if provided.
|
// Check if config image exist if provided.
|
||||||
if (*ext_config_image != NULL) {
|
if (*image_name != NULL) {
|
||||||
if (!im_config_image_exist(*ext_config_image)) {
|
if (!im_config_image_exist(*image_name)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -775,7 +769,7 @@ static int preparate_runtime_environment(const container_create_request *request
|
|||||||
{
|
{
|
||||||
bool runtime_res = false;
|
bool runtime_res = false;
|
||||||
|
|
||||||
if (request->runtime) {
|
if (util_valid_str(request->runtime)) {
|
||||||
*runtime = get_runtime_from_request(request);
|
*runtime = get_runtime_from_request(request);
|
||||||
} else {
|
} else {
|
||||||
*runtime = conf_get_default_runtime();
|
*runtime = conf_get_default_runtime();
|
||||||
@ -787,6 +781,7 @@ static int preparate_runtime_environment(const container_create_request *request
|
|||||||
|
|
||||||
if (runtime_check(*runtime, &runtime_res) != 0) {
|
if (runtime_check(*runtime, &runtime_res) != 0) {
|
||||||
ERROR("Runtimes param check failed");
|
ERROR("Runtimes param check failed");
|
||||||
|
*cc = ISULAD_ERR_EXEC;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -794,6 +789,7 @@ static int preparate_runtime_environment(const container_create_request *request
|
|||||||
ERROR("Invalid runtime name:%s", *runtime);
|
ERROR("Invalid runtime name:%s", *runtime);
|
||||||
isulad_set_error_message("Invalid runtime name (%s).",
|
isulad_set_error_message("Invalid runtime name (%s).",
|
||||||
*runtime);
|
*runtime);
|
||||||
|
*cc = ISULAD_ERR_EXEC;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -845,8 +841,7 @@ int container_create_cb(const container_create_request *request,
|
|||||||
char *runtime = NULL;
|
char *runtime = NULL;
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
char *id = NULL;
|
char *id = NULL;
|
||||||
const char *image_name = NULL;
|
char *image_name = NULL;
|
||||||
const char *ext_config_image = NULL;
|
|
||||||
oci_runtime_spec *oci_spec = NULL;
|
oci_runtime_spec *oci_spec = NULL;
|
||||||
host_config *host_spec = NULL;
|
host_config *host_spec = NULL;
|
||||||
container_config *container_spec = NULL;
|
container_config *container_spec = NULL;
|
||||||
@ -864,7 +859,7 @@ int container_create_cb(const container_create_request *request,
|
|||||||
goto pack_response;
|
goto pack_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_request_image_info(request, &image_type, &ext_config_image, &image_name) != 0) {
|
if (get_request_image_info(request, &image_type, &image_name) != 0) {
|
||||||
cc = ISULAD_ERR_EXEC;
|
cc = ISULAD_ERR_EXEC;
|
||||||
goto clean_nameindex;
|
goto clean_nameindex;
|
||||||
}
|
}
|
||||||
@ -905,7 +900,7 @@ int container_create_cb(const container_create_request *request,
|
|||||||
goto clean_container_root_dir;
|
goto clean_container_root_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = im_merge_image_config(id, image_type, image_name, ext_config_image, host_spec,
|
ret = im_merge_image_config(id, image_type, image_name, request->rootfs, host_spec,
|
||||||
v2_spec->config, &real_rootfs);
|
v2_spec->config, &real_rootfs);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
ERROR("Can not merge container_spec with image config");
|
ERROR("Can not merge container_spec with image config");
|
||||||
@ -1006,6 +1001,7 @@ pack_response:
|
|||||||
free(runtime_root);
|
free(runtime_root);
|
||||||
free(real_rootfs);
|
free(real_rootfs);
|
||||||
free(image_type);
|
free(image_type);
|
||||||
|
free(image_name);
|
||||||
free(name);
|
free(name);
|
||||||
free(id);
|
free(id);
|
||||||
free_oci_runtime_spec(oci_spec);
|
free_oci_runtime_spec(oci_spec);
|
||||||
|
|||||||
@ -199,8 +199,10 @@ static int isulad_info_cb(const host_info_request *request, host_info_response *
|
|||||||
struct utsname u;
|
struct utsname u;
|
||||||
im_image_count_request *im_request = NULL;
|
im_image_count_request *im_request = NULL;
|
||||||
char *rootpath = NULL;
|
char *rootpath = NULL;
|
||||||
|
#ifdef ENABLE_OCI_IMAGE
|
||||||
char *graph_driver = NULL;
|
char *graph_driver = NULL;
|
||||||
struct graphdriver_status *driver_status = NULL;
|
struct graphdriver_status *driver_status = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
DAEMON_CLEAR_ERRMSG();
|
DAEMON_CLEAR_ERRMSG();
|
||||||
|
|
||||||
@ -334,8 +336,10 @@ pack_response:
|
|||||||
(*response)->cc = cc;
|
(*response)->cc = cc;
|
||||||
}
|
}
|
||||||
free(rootpath);
|
free(rootpath);
|
||||||
|
#ifdef ENABLE_OCI_IMAGE
|
||||||
free(graph_driver);
|
free(graph_driver);
|
||||||
free_graphdriver_status(driver_status);
|
free_graphdriver_status(driver_status);
|
||||||
|
#endif
|
||||||
free(huge_page_size);
|
free(huge_page_size);
|
||||||
free(operating_system);
|
free(operating_system);
|
||||||
free_im_image_count_request(im_request);
|
free_im_image_count_request(im_request);
|
||||||
@ -1339,6 +1343,17 @@ static int pack_inspect_data(const container_t *cont, container_inspect **out_in
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_OCI_IMAGE
|
||||||
|
if (!strcmp(cont->common_config->image_type, IMAGE_TYPE_OCI)) {
|
||||||
|
inspect->graph_driver = graphdriver_get_metadata(cont->common_config->id);
|
||||||
|
if (inspect->graph_driver == NULL) {
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
out:
|
out:
|
||||||
*out_inspect = inspect;
|
*out_inspect = inspect;
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@ -41,22 +41,37 @@ static int write_hostname_to_file(const char *rootfs, const char *hostname)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *file_path = NULL;
|
char *file_path = NULL;
|
||||||
|
char *tmp = NULL;
|
||||||
|
char sbuf[MAX_HOST_NAME_LEN] = { 0 };
|
||||||
|
|
||||||
|
if (hostname == NULL) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (realpath_in_scope(rootfs, "/etc/hostname", &file_path) < 0) {
|
if (realpath_in_scope(rootfs, "/etc/hostname", &file_path) < 0) {
|
||||||
SYSERROR("Failed to get real path '/etc/hostname' under rootfs '%s'", rootfs);
|
SYSERROR("Failed to get real path '/etc/hostname' under rootfs '%s'", rootfs);
|
||||||
isulad_set_error_message("Failed to get real path '/etc/hostname' under rootfs '%s'", rootfs);
|
isulad_set_error_message("Failed to get real path '/etc/hostname' under rootfs '%s'", rootfs);
|
||||||
goto error_out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (hostname != NULL) {
|
|
||||||
ret = util_write_file(file_path, hostname, strlen(hostname), NETWORK_MOUNT_FILE_MODE);
|
if (util_file_exists(file_path) && util_file2str(file_path, sbuf, sizeof(sbuf)) > 0) {
|
||||||
if (ret) {
|
tmp = util_strdup_s(sbuf);
|
||||||
SYSERROR("Failed to write %s", file_path);
|
(void)util_trim_newline(tmp);
|
||||||
isulad_set_error_message("Failed to write %s: %s", file_path, strerror(errno));
|
tmp = util_trim_space(tmp);
|
||||||
goto error_out;
|
if (strcmp("", tmp) != 0 && strcmp("localhost", tmp) != 0) {
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error_out:
|
ret = util_write_file(file_path, hostname, strlen(hostname), NETWORK_MOUNT_FILE_MODE);
|
||||||
|
if (ret) {
|
||||||
|
SYSERROR("Failed to write %s", file_path);
|
||||||
|
isulad_set_error_message("Failed to write %s: %s", file_path, strerror(errno));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
free(tmp);
|
||||||
free(file_path);
|
free(file_path);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -542,6 +542,7 @@ static int exec_container(container_t *cont, const char *runtime, char * const c
|
|||||||
params.suffix = request->suffix;
|
params.suffix = request->suffix;
|
||||||
params.state = cont->state_path;
|
params.state = cont->state_path;
|
||||||
params.spec = process_spec;
|
params.spec = process_spec;
|
||||||
|
params.attach_stdin = request->attach_stdin;
|
||||||
|
|
||||||
if (runtime_exec(cont->common_config->id, runtime, ¶ms, exit_code)) {
|
if (runtime_exec(cont->common_config->id, runtime, ¶ms, exit_code)) {
|
||||||
ERROR("Runtime exec container failed");
|
ERROR("Runtime exec container failed");
|
||||||
@ -607,8 +608,8 @@ static int container_exec_cb_check(const container_exec_request *request, contai
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int exec_prepare_console(container_t *cont, const container_exec_request *request, int stdinfd,
|
static int exec_prepare_console(container_t *cont, const container_exec_request *request, int stdinfd,
|
||||||
struct io_write_wrapper *stdout_handler, char **fifos,
|
struct io_write_wrapper *stdout_handler, struct io_write_wrapper *stderr_handler,
|
||||||
char **fifopath, int *sync_fd, pthread_t *thread_id)
|
char **fifos, char **fifopath, int *sync_fd, pthread_t *thread_id)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
const char *id = cont->common_config->id;
|
const char *id = cont->common_config->id;
|
||||||
@ -628,7 +629,7 @@ static int exec_prepare_console(container_t *cont, const container_exec_request
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (ready_copy_io_data(*sync_fd, false, request->stdin, request->stdout, request->stderr,
|
if (ready_copy_io_data(*sync_fd, false, request->stdin, request->stdout, request->stderr,
|
||||||
stdinfd, stdout_handler, NULL, (const char **)fifos, thread_id)) {
|
stdinfd, stdout_handler, stderr_handler, (const char **)fifos, thread_id)) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -729,7 +730,7 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int container_exec_cb(const container_exec_request *request, container_exec_response **response,
|
static int container_exec_cb(const container_exec_request *request, container_exec_response **response,
|
||||||
int stdinfd, struct io_write_wrapper *stdout_handler)
|
int stdinfd, struct io_write_wrapper *stdout_handler, struct io_write_wrapper *stderr_handler)
|
||||||
{
|
{
|
||||||
int exit_code = 0;
|
int exit_code = 0;
|
||||||
int sync_fd = -1;
|
int sync_fd = -1;
|
||||||
@ -801,7 +802,8 @@ static int container_exec_cb(const container_exec_request *request, container_ex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exec_prepare_console(cont, request, stdinfd, stdout_handler, fifos, &fifopath, &sync_fd, &thread_id)) {
|
if (exec_prepare_console(cont, request, stdinfd, stdout_handler, stderr_handler, fifos, &fifopath, &sync_fd,
|
||||||
|
&thread_id)) {
|
||||||
cc = ISULAD_ERR_EXEC;
|
cc = ISULAD_ERR_EXEC;
|
||||||
goto pack_response;
|
goto pack_response;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -516,7 +516,8 @@ void *health_check_run(void *arg)
|
|||||||
char **cmd_slice = NULL;
|
char **cmd_slice = NULL;
|
||||||
char output[REV_BUF_SIZE] = { 0 };
|
char output[REV_BUF_SIZE] = { 0 };
|
||||||
char timebuffer[TIME_STR_SIZE] = { 0 };
|
char timebuffer[TIME_STR_SIZE] = { 0 };
|
||||||
struct io_write_wrapper ctx = { 0 };
|
struct io_write_wrapper Stdoutctx = { 0 };
|
||||||
|
struct io_write_wrapper Stderrctx = { 0 };
|
||||||
container_t *cont = NULL;
|
container_t *cont = NULL;
|
||||||
service_callback_t *cb = NULL;
|
service_callback_t *cb = NULL;
|
||||||
container_exec_request *container_req = NULL;
|
container_exec_request *container_req = NULL;
|
||||||
@ -556,10 +557,12 @@ void *health_check_run(void *arg)
|
|||||||
ERROR("Out of memory");
|
ERROR("Out of memory");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
container_req->tty = false;
|
|
||||||
|
// Set tty to true, compatible with busybox
|
||||||
|
container_req->tty = true;
|
||||||
container_req->attach_stdin = false;
|
container_req->attach_stdin = false;
|
||||||
container_req->attach_stdout = true;
|
container_req->attach_stdout = true;
|
||||||
container_req->attach_stderr = false;
|
container_req->attach_stderr = true;
|
||||||
container_req->timeout = timeout_with_default(config->health_check->timeout, DEFAULT_PROBE_TIMEOUT) / Time_Second;
|
container_req->timeout = timeout_with_default(config->health_check->timeout, DEFAULT_PROBE_TIMEOUT) / Time_Second;
|
||||||
container_req->container_id = util_strdup_s(cont->common_config->id);
|
container_req->container_id = util_strdup_s(cont->common_config->id);
|
||||||
container_req->argv = cmd_slice;
|
container_req->argv = cmd_slice;
|
||||||
@ -575,10 +578,13 @@ void *health_check_run(void *arg)
|
|||||||
}
|
}
|
||||||
result->start = util_strdup_s(timebuffer);
|
result->start = util_strdup_s(timebuffer);
|
||||||
|
|
||||||
ctx.context = (void *)output;
|
Stdoutctx.context = (void *)output;
|
||||||
ctx.write_func = write_to_string;
|
Stdoutctx.write_func = write_to_string;
|
||||||
ctx.close_func = NULL;
|
Stdoutctx.close_func = NULL;
|
||||||
ret = cb->container.exec(container_req, &container_res, -1, &ctx);
|
Stderrctx.context = (void *)output;
|
||||||
|
Stderrctx.write_func = write_to_string;
|
||||||
|
Stderrctx.close_func = NULL;
|
||||||
|
ret = cb->container.exec(container_req, &container_res, -1, &Stdoutctx, &Stderrctx);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
health_check_exec_failed_handle(container_res, result);
|
health_check_exec_failed_handle(container_res, result);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -2311,12 +2311,31 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int destination_compare(const void *p1, const void *p2)
|
||||||
|
{
|
||||||
|
defs_mount *mount_1 = *(defs_mount **)p1;
|
||||||
|
defs_mount *mount_2 = *(defs_mount **)p2;
|
||||||
|
|
||||||
|
return strcmp(mount_1->destination, mount_2->destination);
|
||||||
|
}
|
||||||
|
|
||||||
int merge_conf_mounts(oci_runtime_spec *oci_spec, host_config *host_spec,
|
int merge_conf_mounts(oci_runtime_spec *oci_spec, host_config *host_spec,
|
||||||
container_config_v2_common_config *v2_spec)
|
container_config_v2_common_config *v2_spec)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
container_config *container_spec = v2_spec->config;
|
container_config *container_spec = v2_spec->config;
|
||||||
|
|
||||||
|
/* mounts to mount filesystem */
|
||||||
|
if (container_spec->mounts && container_spec->mounts_len) {
|
||||||
|
ret = merge_volumes(oci_spec, container_spec->mounts,
|
||||||
|
container_spec->mounts_len, v2_spec,
|
||||||
|
parse_mount);
|
||||||
|
if (ret) {
|
||||||
|
ERROR("Failed to merge mounts");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* volumes to mount */
|
/* volumes to mount */
|
||||||
if (host_spec->binds != NULL && host_spec->binds_len) {
|
if (host_spec->binds != NULL && host_spec->binds_len) {
|
||||||
ret = merge_volumes(oci_spec, host_spec->binds,
|
ret = merge_volumes(oci_spec, host_spec->binds,
|
||||||
@ -2336,17 +2355,6 @@ int merge_conf_mounts(oci_runtime_spec *oci_spec, host_config *host_spec,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mounts to mount filesystem */
|
|
||||||
if (container_spec->mounts && container_spec->mounts_len) {
|
|
||||||
ret = merge_volumes(oci_spec, container_spec->mounts,
|
|
||||||
container_spec->mounts_len, v2_spec,
|
|
||||||
parse_mount);
|
|
||||||
if (ret) {
|
|
||||||
ERROR("Failed to merge mounts");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (host_spec->shm_size == 0) {
|
if (host_spec->shm_size == 0) {
|
||||||
host_spec->shm_size = DEFAULT_SHM_SIZE;
|
host_spec->shm_size = DEFAULT_SHM_SIZE;
|
||||||
}
|
}
|
||||||
@ -2363,7 +2371,7 @@ int merge_conf_mounts(oci_runtime_spec *oci_spec, host_config *host_spec,
|
|||||||
add_shm_mount(oci_spec, v2_spec->shm_path);
|
add_shm_mount(oci_spec, v2_spec->shm_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (host_spec->shm_size > 0) {
|
if (!has_mount_shm(host_spec, v2_spec) && host_spec->shm_size > 0) {
|
||||||
ret = change_dev_shm_size(oci_spec, host_spec);
|
ret = change_dev_shm_size(oci_spec, host_spec);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
ERROR("Failed to set dev shm size");
|
ERROR("Failed to set dev shm size");
|
||||||
@ -2379,6 +2387,8 @@ int merge_conf_mounts(oci_runtime_spec *oci_spec, host_config *host_spec,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qsort(oci_spec->mounts, oci_spec->mounts_len, sizeof(oci_spec->mounts[0]), destination_compare);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,8 +27,8 @@
|
|||||||
#include "isulad_config.h"
|
#include "isulad_config.h"
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
|
||||||
/* overlay2 */
|
/* overlay/overlay2 */
|
||||||
|
#define DRIVER_OVERLAY_NAME "overlay"
|
||||||
#define DRIVER_OVERLAY2_NAME "overlay2"
|
#define DRIVER_OVERLAY2_NAME "overlay2"
|
||||||
static const struct graphdriver_ops g_overlay2_ops = {
|
static const struct graphdriver_ops g_overlay2_ops = {
|
||||||
.init = overlay2_init,
|
.init = overlay2_init,
|
||||||
@ -124,6 +124,77 @@ free_out:
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
container_inspect_graph_driver *graphdriver_get_metadata(char *id)
|
||||||
|
{
|
||||||
|
container_inspect_graph_driver *inspect_driver = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
im_storage_metadata_response *resp = NULL;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
ret = im_get_storage_metadata(IMAGE_TYPE_OCI, id, &resp);
|
||||||
|
if (ret != 0) {
|
||||||
|
goto free_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resp->name == NULL || resp->metadata == NULL) {
|
||||||
|
ERROR("Failed to get metadata or name");
|
||||||
|
ret = -1;
|
||||||
|
goto free_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
inspect_driver = util_common_calloc_s(sizeof(container_inspect_graph_driver));
|
||||||
|
if (inspect_driver == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto free_out;
|
||||||
|
}
|
||||||
|
inspect_driver->data = util_common_calloc_s(sizeof(container_inspect_graph_driver_data));
|
||||||
|
if (inspect_driver->data == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto free_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
inspect_driver->name = util_strdup_s(resp->name);
|
||||||
|
|
||||||
|
if (!strcmp(resp->name, DRIVER_OVERLAY_NAME) || !strcmp(resp->name, DRIVER_OVERLAY2_NAME)) {
|
||||||
|
for (i = 0; i < resp->metadata->len; i++) {
|
||||||
|
if (!strcmp(resp->metadata->keys[i], "LowerDir")) {
|
||||||
|
inspect_driver->data->lower_dir = util_strdup_s(resp->metadata->values[i]);
|
||||||
|
} else if (!strcmp(resp->metadata->keys[i], "MergedDir")) {
|
||||||
|
inspect_driver->data->merged_dir = util_strdup_s(resp->metadata->values[i]);
|
||||||
|
} else if (!strcmp(resp->metadata->keys[i], "UpperDir")) {
|
||||||
|
inspect_driver->data->upper_dir = util_strdup_s(resp->metadata->values[i]);
|
||||||
|
} else if (!strcmp(resp->metadata->keys[i], "WorkDir")) {
|
||||||
|
inspect_driver->data->work_dir = util_strdup_s(resp->metadata->values[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (!strcmp(resp->name, DRIVER_DEVMAPPER_NAME)) {
|
||||||
|
for (i = 0; i < resp->metadata->len; i++) {
|
||||||
|
if (!strcmp(resp->metadata->keys[i], "DeviceId")) {
|
||||||
|
inspect_driver->data->device_id = util_strdup_s(resp->metadata->values[i]);
|
||||||
|
} else if (!strcmp(resp->metadata->keys[i], "DeviceName")) {
|
||||||
|
inspect_driver->data->device_name = util_strdup_s(resp->metadata->values[i]);
|
||||||
|
} else if (!strcmp(resp->metadata->keys[i], "DeviceSize")) {
|
||||||
|
inspect_driver->data->device_size = util_strdup_s(resp->metadata->values[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ERROR("Unsupported driver %s", resp->name);
|
||||||
|
ret = -1;
|
||||||
|
goto free_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
free_out:
|
||||||
|
free_im_storage_metadata_response(resp);
|
||||||
|
if (ret != 0) {
|
||||||
|
free_container_inspect_graph_driver(inspect_driver);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return inspect_driver;
|
||||||
|
}
|
||||||
|
|
||||||
int update_graphdriver_status(struct graphdriver **driver)
|
int update_graphdriver_status(struct graphdriver **driver)
|
||||||
{
|
{
|
||||||
struct graphdriver_status *status = NULL;
|
struct graphdriver_status *status = NULL;
|
||||||
|
|||||||
@ -18,6 +18,7 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include "container_inspect.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -50,6 +51,8 @@ struct graphdriver *graphdriver_get(const char *name);
|
|||||||
|
|
||||||
struct graphdriver_status *graphdriver_get_status(void);
|
struct graphdriver_status *graphdriver_get_status(void);
|
||||||
|
|
||||||
|
container_inspect_graph_driver *graphdriver_get_metadata(char *id);
|
||||||
|
|
||||||
int update_graphdriver_status(struct graphdriver **driver);
|
int update_graphdriver_status(struct graphdriver **driver);
|
||||||
|
|
||||||
void graphdriver_umount_mntpoint(void);
|
void graphdriver_umount_mntpoint(void);
|
||||||
|
|||||||
@ -384,6 +384,111 @@ out:
|
|||||||
return (ret < 0) ? ECOMMON : ret;
|
return (ret < 0) ? ECOMMON : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* tag image */
|
||||||
|
static int tag_image(const char *src_name, const char *dest_name)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
im_tag_request *im_request = NULL;
|
||||||
|
im_tag_response *im_response = NULL;
|
||||||
|
|
||||||
|
if (src_name == NULL || dest_name == NULL) {
|
||||||
|
ERROR("invalid NULL param");
|
||||||
|
return EINVALIDARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
im_request = util_common_calloc_s(sizeof(im_tag_request));
|
||||||
|
if (im_request == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
im_request->src_name.image = util_strdup_s(src_name);
|
||||||
|
im_request->dest_name.image = util_strdup_s(dest_name);
|
||||||
|
|
||||||
|
ret = im_tag_image(im_request, &im_response);
|
||||||
|
if (ret != 0) {
|
||||||
|
if (im_response != NULL && im_response->errmsg != NULL) {
|
||||||
|
ERROR("Tag image %s to %s failed:%s", src_name, dest_name, im_response->errmsg);
|
||||||
|
isulad_try_set_error_message("Tag image %s to %s failed:%s", src_name, dest_name, im_response->errmsg);
|
||||||
|
} else {
|
||||||
|
ERROR("Tag image %s to %s failed", src_name, dest_name);
|
||||||
|
isulad_try_set_error_message("Tag image %s to %s failed");
|
||||||
|
}
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
free_im_tag_request(im_request);
|
||||||
|
free_im_tag_response(im_response);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* image tag cb */
|
||||||
|
static int image_tag_cb(const image_tag_image_request *request,
|
||||||
|
image_tag_image_response **response)
|
||||||
|
{
|
||||||
|
int ret = -1;
|
||||||
|
char *src_name = NULL;
|
||||||
|
char *dest_name = NULL;
|
||||||
|
uint32_t cc = ISULAD_SUCCESS;
|
||||||
|
|
||||||
|
DAEMON_CLEAR_ERRMSG();
|
||||||
|
|
||||||
|
if (request == NULL || request->src_name == NULL || response == NULL ||
|
||||||
|
request->dest_name == NULL) {
|
||||||
|
ERROR("Invalid input arguments");
|
||||||
|
return EINVALIDARGS;
|
||||||
|
}
|
||||||
|
|
||||||
|
src_name = request->src_name;
|
||||||
|
dest_name = request->dest_name;
|
||||||
|
|
||||||
|
*response = util_common_calloc_s(sizeof(image_delete_image_response));
|
||||||
|
if (*response == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
cc = ISULAD_ERR_MEMOUT;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!util_valid_image_name(src_name)) {
|
||||||
|
ERROR("Invalid image name %s", src_name);
|
||||||
|
cc = ISULAD_ERR_INPUT;
|
||||||
|
isulad_try_set_error_message("Invalid image name:%s", src_name);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!util_valid_image_name(dest_name)) {
|
||||||
|
ERROR("Invalid image name %s", dest_name);
|
||||||
|
cc = ISULAD_ERR_INPUT;
|
||||||
|
isulad_try_set_error_message("Invalid image name:%s", dest_name);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT("Image Event: {Object: %s, Type: Tagging}", src_name);
|
||||||
|
|
||||||
|
ret = tag_image(src_name, dest_name);
|
||||||
|
if (ret != 0) {
|
||||||
|
cc = ISULAD_ERR_EXEC;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT("Image Event: {Object: %s, Type: Tagged}", src_name);
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (*response != NULL) {
|
||||||
|
(*response)->cc = cc;
|
||||||
|
if (g_isulad_errmsg != NULL) {
|
||||||
|
(*response)->errmsg = util_strdup_s(g_isulad_errmsg);
|
||||||
|
DAEMON_CLEAR_ERRMSG();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (ret < 0) ? ECOMMON : ret;
|
||||||
|
}
|
||||||
|
|
||||||
static bool valid_repo_tags(char * const * const repo_tags, size_t repo_index)
|
static bool valid_repo_tags(char * const * const repo_tags, size_t repo_index)
|
||||||
{
|
{
|
||||||
if (repo_tags != NULL && repo_tags[repo_index] != NULL) {
|
if (repo_tags != NULL && repo_tags[repo_index] != NULL) {
|
||||||
@ -890,5 +995,6 @@ void image_callback_init(service_image_callback_t *cb)
|
|||||||
cb->inspect = image_inspect_cb;
|
cb->inspect = image_inspect_cb;
|
||||||
cb->login = login_cb;
|
cb->login = login_cb;
|
||||||
cb->logout = logout_cb;
|
cb->logout = logout_cb;
|
||||||
|
cb->tag = image_tag_cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -48,10 +48,11 @@ int AttachServe::Execute(struct lws *wsi, const std::string &token,
|
|||||||
}
|
}
|
||||||
struct io_write_wrapper stringWriter = { 0 };
|
struct io_write_wrapper stringWriter = { 0 };
|
||||||
stringWriter.context = (void *)wsi;
|
stringWriter.context = (void *)wsi;
|
||||||
stringWriter.write_func = WsWriteToClient;
|
stringWriter.write_func = WsWriteStdoutToClient;
|
||||||
stringWriter.close_func = closeWsConnect;
|
stringWriter.close_func = closeWsConnect;
|
||||||
container_req->attach_stderr = false;
|
container_req->attach_stderr = false;
|
||||||
int ret = cb->container.attach(container_req, &container_res, read_pipe_fd, &stringWriter, nullptr);
|
int ret = cb->container.attach(container_req, &container_res,
|
||||||
|
container_req->attach_stdin ? read_pipe_fd : -1, &stringWriter, nullptr);
|
||||||
free_container_attach_request(container_req);
|
free_container_attach_request(container_req);
|
||||||
free_container_attach_response(container_res);
|
free_container_attach_response(container_res);
|
||||||
|
|
||||||
|
|||||||
@ -45,10 +45,14 @@ int ExecServe::Execute(struct lws *wsi, const std::string &token,
|
|||||||
ERROR("Failed to transform grpc request!");
|
ERROR("Failed to transform grpc request!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
struct io_write_wrapper stringWriter = { 0 };
|
struct io_write_wrapper StdoutstringWriter = { 0 };
|
||||||
stringWriter.context = (void *)wsi;
|
StdoutstringWriter.context = (void *)wsi;
|
||||||
stringWriter.write_func = WsWriteToClient;
|
StdoutstringWriter.write_func = WsWriteStdoutToClient;
|
||||||
int ret = cb->container.exec(container_req, &container_res, read_pipe_fd, &stringWriter);
|
struct io_write_wrapper StderrstringWriter = { 0 };
|
||||||
|
StderrstringWriter.context = (void *)wsi;
|
||||||
|
StderrstringWriter.write_func = WsWriteStderrToClient;
|
||||||
|
int ret = cb->container.exec(container_req, &container_res,
|
||||||
|
container_req->attach_stdin ? read_pipe_fd : -1, &StdoutstringWriter, &StderrstringWriter);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
std::string message;
|
std::string message;
|
||||||
if (container_res != nullptr && container_res->errmsg != nullptr) {
|
if (container_res != nullptr && container_res->errmsg != nullptr) {
|
||||||
@ -56,11 +60,11 @@ int ExecServe::Execute(struct lws *wsi, const std::string &token,
|
|||||||
} else {
|
} else {
|
||||||
message = "Failed to call exec container callback. ";
|
message = "Failed to call exec container callback. ";
|
||||||
}
|
}
|
||||||
WsWriteToClient(wsi, message.c_str(), message.length());
|
WsWriteStdoutToClient(wsi, message.c_str(), message.length());
|
||||||
}
|
}
|
||||||
if (container_res != nullptr && container_res->exit_code != 0) {
|
if (container_res != nullptr && container_res->exit_code != 0) {
|
||||||
std::string exit_info = "Exit code :" + std::to_string((int)container_res->exit_code) + "\n";
|
std::string exit_info = "Exit code :" + std::to_string((int)container_res->exit_code) + "\n";
|
||||||
WsWriteToClient(wsi, exit_info.c_str(), exit_info.length());
|
WsWriteStdoutToClient(wsi, exit_info.c_str(), exit_info.length());
|
||||||
}
|
}
|
||||||
free_container_exec_request(container_req);
|
free_container_exec_request(container_req);
|
||||||
free_container_exec_response(container_res);
|
free_container_exec_response(container_res);
|
||||||
|
|||||||
@ -410,7 +410,7 @@ void WebsocketServer::Wait()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ssize_t WsWriteToClient(void *context, const void *data, size_t len)
|
ssize_t WsWriteStdoutToClient(void *context, const void *data, size_t len)
|
||||||
{
|
{
|
||||||
const int RETRIES = 10;
|
const int RETRIES = 10;
|
||||||
const int CHECK_PERIOD_SECOND = 1;
|
const int CHECK_PERIOD_SECOND = 1;
|
||||||
@ -456,6 +456,52 @@ ssize_t WsWriteToClient(void *context, const void *data, size_t len)
|
|||||||
return (ssize_t)len;
|
return (ssize_t)len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t WsWriteStderrToClient(void *context, const void *data, size_t len)
|
||||||
|
{
|
||||||
|
const int RETRIES = 10;
|
||||||
|
const int CHECK_PERIOD_SECOND = 1;
|
||||||
|
const int TRIGGER_PERIOD_MS = 100;
|
||||||
|
|
||||||
|
struct lws *wsi = static_cast<struct lws *>(context);
|
||||||
|
WebsocketServer *server = WebsocketServer::GetInstance();
|
||||||
|
server->LockAllWsSession();
|
||||||
|
auto it = server->GetWsisData().find(wsi);
|
||||||
|
if (it == server->GetWsisData().end()) {
|
||||||
|
ERROR("invalid session!");
|
||||||
|
server->UnlockAllWsSession();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
it->second.SetProcessingStatus(true);
|
||||||
|
server->UnlockAllWsSession();
|
||||||
|
server->SetLwsSendedFlag(wsi, false);
|
||||||
|
it->second.buf_mutex->lock();
|
||||||
|
auto &buf = it->second.buf;
|
||||||
|
// Determine if it is standard output channel or error channel?
|
||||||
|
(void)memset(buf, 0, LWS_PRE + MAX_MSG_BUFFER_SIZE + 1);
|
||||||
|
buf[LWS_PRE] = STDERRCHANNEL;
|
||||||
|
|
||||||
|
(void)memcpy(&buf[LWS_PRE + 1], (void *)data, len);
|
||||||
|
auto start = std::chrono::system_clock::now();
|
||||||
|
lws_callback_on_writable(wsi);
|
||||||
|
it->second.buf_mutex->unlock();
|
||||||
|
int count = 0;
|
||||||
|
while (!it->second.sended && count < RETRIES) {
|
||||||
|
auto end = std::chrono::system_clock::now();
|
||||||
|
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
||||||
|
double spend_time = static_cast<double>(duration.count()) * std::chrono::microseconds::period::num /
|
||||||
|
std::chrono::microseconds::period::den;
|
||||||
|
if (spend_time > CHECK_PERIOD_SECOND) {
|
||||||
|
lws_callback_on_writable(wsi);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(TRIGGER_PERIOD_MS));
|
||||||
|
start = std::chrono::system_clock::now();
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(TRIGGER_PERIOD_MS));
|
||||||
|
}
|
||||||
|
it->second.SetProcessingStatus(false);
|
||||||
|
return (ssize_t)len;
|
||||||
|
}
|
||||||
|
|
||||||
int closeWsConnect(void *context, char **err)
|
int closeWsConnect(void *context, char **err)
|
||||||
{
|
{
|
||||||
(void)err;
|
(void)err;
|
||||||
|
|||||||
@ -119,7 +119,8 @@ private:
|
|||||||
int m_listenPort;
|
int m_listenPort;
|
||||||
};
|
};
|
||||||
|
|
||||||
ssize_t WsWriteToClient(void *context, const void *data, size_t len);
|
ssize_t WsWriteStdoutToClient(void *context, const void *data, size_t len);
|
||||||
|
ssize_t WsWriteStderrToClient(void *context, const void *data, size_t len);
|
||||||
int closeWsConnect(void *context, char **err);
|
int closeWsConnect(void *context, char **err);
|
||||||
|
|
||||||
#endif /* __WEBSOCKET_SERVER_H_ */
|
#endif /* __WEBSOCKET_SERVER_H_ */
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
# ./update-version.bash
|
# ./update-version.bash
|
||||||
topDir=$(git rev-parse --show-toplevel)
|
topDir=$(git rev-parse --show-toplevel)
|
||||||
specfile="${topDir}/iSulad.spec"
|
specfile="${topDir}/iSulad.spec"
|
||||||
|
Cmakefile="${topDir}/CMakeLists.txt"
|
||||||
Version_CMakefile="${topDir}/cmake/options.cmake"
|
Version_CMakefile="${topDir}/cmake/options.cmake"
|
||||||
old_version=$(cat ${specfile} | grep "%global" | grep "_version" | awk {'print $3'})
|
old_version=$(cat ${specfile} | grep "%global" | grep "_version" | awk {'print $3'})
|
||||||
first_old_version=$(cat ${specfile} | grep "%global" | grep "_version" | awk {'print $3'} | awk -F "." {'print $1'})
|
first_old_version=$(cat ${specfile} | grep "%global" | grep "_version" | awk {'print $3'} | awk -F "." {'print $1'})
|
||||||
@ -49,6 +50,7 @@ commit_id=${commit_id_long:0:8}
|
|||||||
new_release=`date "+%Y%m%d"`.`date "+%H%M%S"`.git$commit_id
|
new_release=`date "+%Y%m%d"`.`date "+%H%M%S"`.git$commit_id
|
||||||
echo "The relase version has been modified, it is ${new_release}"
|
echo "The relase version has been modified, it is ${new_release}"
|
||||||
sed -i "s/set(ISULAD_VERSION \"${old_version}\")/set(ISULAD_VERSION \"${new_version}\")/g" ${Version_CMakefile}
|
sed -i "s/set(ISULAD_VERSION \"${old_version}\")/set(ISULAD_VERSION \"${new_version}\")/g" ${Version_CMakefile}
|
||||||
|
sed -i "s/^.*set(GIT_COMMIT_HASH.*$/set(GIT_COMMIT_HASH \"${commit_id_long}\")/g" ${Cmakefile}
|
||||||
sed -i "s/^\%global _version ${old_version}$/\%global _version ${new_version}/g" ${specfile}
|
sed -i "s/^\%global _version ${old_version}$/\%global _version ${new_version}/g" ${specfile}
|
||||||
sed -i "s/^\%global _release ${old_release}$/\%global _release ${new_release}/g" ${specfile}
|
sed -i "s/^\%global _release ${old_release}$/\%global _release ${new_release}/g" ${specfile}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user