iSulad: internal change
Signed-off-by: LiFeng <lifeng68@huawei.com>
This commit is contained in:
parent
99a92711bd
commit
e2728aa73e
@ -33,7 +33,7 @@ endif()
|
|||||||
|
|
||||||
option(VERSION "set lcrd version" ON)
|
option(VERSION "set lcrd version" ON)
|
||||||
if (VERSION STREQUAL "ON")
|
if (VERSION STREQUAL "ON")
|
||||||
set(LCRD_VERSION "1.1.4")
|
set(LCRD_VERSION "1.1.5")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(DEBUG "set lcrd gcc option" ON)
|
option(DEBUG "set lcrd gcc option" ON)
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
%global _version 1.1.4
|
%global _version 1.1.5
|
||||||
%global _release 20191226.061440.gitfa7769d5
|
%global _release 20200106.022952.git939935db
|
||||||
%global is_systemd 1
|
%global is_systemd 1
|
||||||
%global debug_package %{nil}
|
%global debug_package %{nil}
|
||||||
|
|
||||||
|
|||||||
@ -69,20 +69,18 @@ message Container {
|
|||||||
|
|
||||||
message Container_info {
|
message Container_info {
|
||||||
string id = 1;
|
string id = 1;
|
||||||
int32 pid = 2;
|
uint64 pids_current = 2;
|
||||||
ContainerStatus status = 3;
|
uint64 cpu_use_nanos = 3;
|
||||||
uint64 pids_current = 4;
|
uint64 cpu_use_user = 4;
|
||||||
uint64 cpu_use_nanos = 5;
|
uint64 cpu_use_kernel = 5;
|
||||||
uint64 cpu_use_user = 6;
|
uint64 cpu_system_use = 6;
|
||||||
uint64 cpu_use_kernel = 7;
|
uint32 online_cpus = 7;
|
||||||
uint64 cpu_system_use = 8;
|
uint64 blkio_read = 8;
|
||||||
uint32 online_cpus = 9;
|
uint64 blkio_write = 9;
|
||||||
uint64 blkio_read = 10;
|
uint64 mem_used = 10;
|
||||||
uint64 blkio_write = 11;
|
uint64 mem_limit = 11;
|
||||||
uint64 mem_used = 12;
|
uint64 kmem_used = 12;
|
||||||
uint64 mem_limit = 13;
|
uint64 kmem_limit = 13;
|
||||||
uint64 kmem_used = 14;
|
|
||||||
uint64 kmem_limit = 15;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message Event {
|
message Event {
|
||||||
@ -114,13 +112,13 @@ service ContainerService {
|
|||||||
rpc Info(InfoRequest) returns (InfoResponse);
|
rpc Info(InfoRequest) returns (InfoResponse);
|
||||||
rpc Update(UpdateRequest) returns (UpdateResponse);
|
rpc Update(UpdateRequest) returns (UpdateResponse);
|
||||||
rpc Attach(stream AttachRequest) returns (stream AttachResponse);
|
rpc Attach(stream AttachRequest) returns (stream AttachResponse);
|
||||||
rpc Container_conf(Container_conf_Request) returns (Container_conf_Response);
|
|
||||||
rpc Restart(RestartRequest) returns (RestartResponse);
|
rpc Restart(RestartRequest) returns (RestartResponse);
|
||||||
rpc Export(ExportRequest) returns (ExportResponse);
|
rpc Export(ExportRequest) returns (ExportResponse);
|
||||||
rpc CopyFromContainer(CopyFromContainerRequest) returns (stream CopyFromContainerResponse);
|
rpc CopyFromContainer(CopyFromContainerRequest) returns (stream CopyFromContainerResponse);
|
||||||
rpc CopyToContainer(stream CopyToContainerRequest) returns (stream CopyToContainerResponse);
|
rpc CopyToContainer(stream CopyToContainerRequest) returns (stream CopyToContainerResponse);
|
||||||
rpc Rename(RenameRequest) returns (RenameResponse);
|
rpc Rename(RenameRequest) returns (RenameResponse);
|
||||||
rpc Logs(LogsRequest) returns (stream LogsResponse);
|
rpc Logs(LogsRequest) returns (stream LogsResponse);
|
||||||
|
rpc Resize(ResizeRequest) returns (ResizeResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
message CreateRequest {
|
message CreateRequest {
|
||||||
@ -271,7 +269,6 @@ message ListResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
message StatsRequest {
|
message StatsRequest {
|
||||||
string runtime = 1;
|
|
||||||
repeated string containers = 2;
|
repeated string containers = 2;
|
||||||
bool all = 3;
|
bool all = 3;
|
||||||
}
|
}
|
||||||
@ -313,6 +310,7 @@ message ExecRequest {
|
|||||||
repeated string argv = 10;
|
repeated string argv = 10;
|
||||||
repeated string env = 11;
|
repeated string env = 11;
|
||||||
string user = 12;
|
string user = 12;
|
||||||
|
string suffix = 13;
|
||||||
}
|
}
|
||||||
message ExecResponse {
|
message ExecResponse {
|
||||||
int32 pid = 1;
|
int32 pid = 1;
|
||||||
@ -390,19 +388,6 @@ message UpdateResponse {
|
|||||||
uint32 cc = 2;
|
uint32 cc = 2;
|
||||||
string errmsg = 3;
|
string errmsg = 3;
|
||||||
}
|
}
|
||||||
message Container_conf_Request {
|
|
||||||
// ContainerID specifies the container in which to get config.
|
|
||||||
string container_id = 1;
|
|
||||||
string runtime = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message Container_conf_Response {
|
|
||||||
string container_logpath = 1;
|
|
||||||
string container_logsize = 2;
|
|
||||||
uint32 container_logrotate = 3;
|
|
||||||
uint32 cc = 4;
|
|
||||||
string errmsg = 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
message ExportRequest {
|
message ExportRequest {
|
||||||
string id = 1;
|
string id = 1;
|
||||||
@ -461,3 +446,16 @@ message LogsResponse {
|
|||||||
string time = 3;
|
string time = 3;
|
||||||
bytes attrs = 4;
|
bytes attrs = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message ResizeRequest {
|
||||||
|
string id = 1;
|
||||||
|
string suffix = 2;
|
||||||
|
uint32 height = 3;
|
||||||
|
uint32 width = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResizeResponse {
|
||||||
|
string id = 1;
|
||||||
|
uint32 cc = 2;
|
||||||
|
string errmsg = 3;
|
||||||
|
}
|
||||||
|
|||||||
@ -45,8 +45,6 @@
|
|||||||
#include "container_resume_response.h"
|
#include "container_resume_response.h"
|
||||||
#include "container_wait_request.h"
|
#include "container_wait_request.h"
|
||||||
#include "container_wait_response.h"
|
#include "container_wait_response.h"
|
||||||
#include "container_conf_request.h"
|
|
||||||
#include "container_conf_response.h"
|
|
||||||
|
|
||||||
#ifndef RestHttpHead
|
#ifndef RestHttpHead
|
||||||
#define RestHttpHead "http://localhost"
|
#define RestHttpHead "http://localhost"
|
||||||
@ -67,7 +65,6 @@
|
|||||||
#define ContainerServiceAttach "/ContainerService/Attach"
|
#define ContainerServiceAttach "/ContainerService/Attach"
|
||||||
#define ContainerServiceResume "/ContainerService/Resume"
|
#define ContainerServiceResume "/ContainerService/Resume"
|
||||||
#define ContainerServiceWait "/ContainerService/Wait"
|
#define ContainerServiceWait "/ContainerService/Wait"
|
||||||
#define ContainerServiceConf "/ContainerService/Container_conf"
|
|
||||||
|
|
||||||
/* "/ContainerService/Kill",
|
/* "/ContainerService/Kill",
|
||||||
"/ContainerService/Delete",
|
"/ContainerService/Delete",
|
||||||
|
|||||||
@ -286,6 +286,9 @@ struct client_arguments {
|
|||||||
char *type;
|
char *type;
|
||||||
char *tag;
|
char *tag;
|
||||||
|
|
||||||
|
// exec
|
||||||
|
char *exec_suffix;
|
||||||
|
|
||||||
// login/logout
|
// login/logout
|
||||||
char *username;
|
char *username;
|
||||||
char *password;
|
char *password;
|
||||||
|
|||||||
@ -1273,7 +1273,6 @@ int cmd_create_main(int argc, const char **argv)
|
|||||||
printf("%s\n", g_cmd_create_args.name);
|
printf("%s\n", g_cmd_create_args.name);
|
||||||
nret = EXIT_SUCCESS;
|
nret = EXIT_SUCCESS;
|
||||||
out:
|
out:
|
||||||
client_arguments_free(&g_cmd_create_args);
|
|
||||||
exit(nret);
|
exit(nret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,11 @@
|
|||||||
* Create: 2018-11-08
|
* Create: 2018-11-08
|
||||||
* Description: provide container run functions
|
* Description: provide container run functions
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <termios.h>
|
||||||
|
|
||||||
#include "run.h"
|
#include "run.h"
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
@ -127,6 +131,97 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int do_resize_run_console(const struct client_arguments *args, unsigned int height, unsigned int width)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
lcrc_connect_ops *ops = NULL;
|
||||||
|
struct lcrc_resize_request request = { 0 };
|
||||||
|
struct lcrc_resize_response *response = NULL;
|
||||||
|
client_connect_config_t config = { 0 };
|
||||||
|
|
||||||
|
ops = get_connect_client_ops();
|
||||||
|
if (ops == NULL || ops->container.resize == NULL) {
|
||||||
|
ERROR("Unimplemented ops");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
request.id = args->name;
|
||||||
|
request.height = height;
|
||||||
|
request.width = width;
|
||||||
|
|
||||||
|
response = util_common_calloc_s(sizeof(struct lcrc_resize_response));
|
||||||
|
if (response == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
config = get_connect_config(args);
|
||||||
|
ret = ops->container.resize(&request, response, &config);
|
||||||
|
if (ret != 0) {
|
||||||
|
ERROR("Failed to call resize");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
lcrc_resize_response_free(response);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *run_console_resize_thread(void *arg)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
const struct client_arguments *args = arg;
|
||||||
|
static struct winsize s_pre_wsz;
|
||||||
|
struct winsize wsz;
|
||||||
|
|
||||||
|
if (!isatty(STDIN_FILENO)) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = pthread_detach(pthread_self());
|
||||||
|
if (ret != 0) {
|
||||||
|
CRIT("Start: set thread detach fail");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
sleep(1); // check the windows size per 1s
|
||||||
|
ret = ioctl(STDIN_FILENO, TIOCGWINSZ, &wsz);
|
||||||
|
if (ret < 0) {
|
||||||
|
WARN("Failed to get window size");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (wsz.ws_row == s_pre_wsz.ws_row && wsz.ws_col == s_pre_wsz.ws_col) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ret = do_resize_run_console(args, wsz.ws_row, wsz.ws_col);
|
||||||
|
if (ret != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
s_pre_wsz.ws_row = wsz.ws_row;
|
||||||
|
s_pre_wsz.ws_col = wsz.ws_col;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int run_client_console_resize_thread(struct client_arguments *args)
|
||||||
|
{
|
||||||
|
int res = 0;
|
||||||
|
pthread_t a_thread;
|
||||||
|
|
||||||
|
res = pthread_create(&a_thread, NULL, run_console_resize_thread, (void *)(args));
|
||||||
|
if (res != 0) {
|
||||||
|
CRIT("Thread creation failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int cmd_run_main(int argc, const char **argv)
|
int cmd_run_main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -172,6 +267,10 @@ int cmd_run_main(int argc, const char **argv)
|
|||||||
printf("%s\n", g_cmd_run_args.name);
|
printf("%s\n", g_cmd_run_args.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_cmd_run_args.custom_conf.tty && isatty(STDIN_FILENO)) {
|
||||||
|
(void)run_client_console_resize_thread(&g_cmd_run_args);
|
||||||
|
}
|
||||||
|
|
||||||
if (strncmp(g_cmd_run_args.socket, "tcp://", strlen("tcp://")) == 0) {
|
if (strncmp(g_cmd_run_args.socket, "tcp://", strlen("tcp://")) == 0) {
|
||||||
ret = remote_cmd_start(&g_cmd_run_args, &exit_code);
|
ret = remote_cmd_start(&g_cmd_run_args, &exit_code);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
@ -187,7 +286,6 @@ int cmd_run_main(int argc, const char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
free_out:
|
free_out:
|
||||||
client_arguments_free(&g_cmd_run_args);
|
|
||||||
exit(ret);
|
exit(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -213,7 +213,6 @@ static int client_stats(const struct client_arguments *args)
|
|||||||
{
|
{
|
||||||
struct lcrc_stats_request request = { 0 };
|
struct lcrc_stats_request request = { 0 };
|
||||||
|
|
||||||
request.runtime = args->runtime;
|
|
||||||
request.all = args->showall;
|
request.all = args->showall;
|
||||||
request.containers = (char **)(args->argv);
|
request.containers = (char **)(args->argv);
|
||||||
request.containers_len = (size_t)(args->argc);
|
request.containers_len = (size_t)(args->argc);
|
||||||
|
|||||||
@ -18,8 +18,6 @@
|
|||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
#define STATUS_OPTIONS(cmdargs) \
|
#define STATUS_OPTIONS(cmdargs) \
|
||||||
{ CMD_OPT_TYPE_STRING, false, "runtime", 'R', &(cmdargs).runtime, \
|
|
||||||
"Runtime to use for containers(default: lcr)", NULL }, \
|
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "all", 'a', &(cmdargs).showall, \
|
{ CMD_OPT_TYPE_BOOL, false, "all", 'a', &(cmdargs).showall, \
|
||||||
"Show all containers (default shows just running)", NULL }, \
|
"Show all containers (default shows just running)", NULL }, \
|
||||||
{ CMD_OPT_TYPE_BOOL, false, "no-stream", 0, &(cmdargs).nostream, \
|
{ CMD_OPT_TYPE_BOOL, false, "no-stream", 0, &(cmdargs).nostream, \
|
||||||
|
|||||||
@ -18,6 +18,8 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <termios.h>
|
||||||
|
|
||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
@ -52,6 +54,7 @@ static int client_exec(const struct client_arguments *args, const struct command
|
|||||||
}
|
}
|
||||||
|
|
||||||
request.name = args->name;
|
request.name = args->name;
|
||||||
|
request.suffix = args->exec_suffix;
|
||||||
request.tty = args->custom_conf.tty;
|
request.tty = args->custom_conf.tty;
|
||||||
request.open_stdin = args->custom_conf.open_stdin;
|
request.open_stdin = args->custom_conf.open_stdin;
|
||||||
request.attach_stdin = args->custom_conf.attach_stdin;
|
request.attach_stdin = args->custom_conf.attach_stdin;
|
||||||
@ -248,6 +251,7 @@ static int remote_cmd_exec(const struct client_arguments *args, uint32_t *exit_c
|
|||||||
g_cmd_exec_args.name = util_strdup_s(inspect_data->id);
|
g_cmd_exec_args.name = util_strdup_s(inspect_data->id);
|
||||||
|
|
||||||
request.name = args->name;
|
request.name = args->name;
|
||||||
|
request.suffix = args->exec_suffix;
|
||||||
request.tty = args->custom_conf.tty;
|
request.tty = args->custom_conf.tty;
|
||||||
request.open_stdin = args->custom_conf.open_stdin;
|
request.open_stdin = args->custom_conf.open_stdin;
|
||||||
request.attach_stdin = args->custom_conf.attach_stdin;
|
request.attach_stdin = args->custom_conf.attach_stdin;
|
||||||
@ -313,6 +317,119 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *generate_exec_suffix()
|
||||||
|
{
|
||||||
|
char *exec_suffix = NULL;
|
||||||
|
|
||||||
|
exec_suffix = util_common_calloc_s(sizeof(char) * (CONTAINER_ID_MAX_LEN + 1));
|
||||||
|
if (exec_suffix == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (util_generate_random_str(exec_suffix, (size_t)CONTAINER_ID_MAX_LEN)) {
|
||||||
|
ERROR("Generate exec suffix failed");
|
||||||
|
free(exec_suffix);
|
||||||
|
exec_suffix = NULL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
return exec_suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int do_resize_exec_console(const struct client_arguments *args, unsigned int height, unsigned int width)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
lcrc_connect_ops *ops = NULL;
|
||||||
|
struct lcrc_resize_request request = { 0 };
|
||||||
|
struct lcrc_resize_response *response = NULL;
|
||||||
|
client_connect_config_t config = { 0 };
|
||||||
|
|
||||||
|
ops = get_connect_client_ops();
|
||||||
|
if (ops == NULL || ops->container.resize == NULL) {
|
||||||
|
ERROR("Unimplemented ops");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
request.id = args->name;
|
||||||
|
request.suffix = args->exec_suffix;
|
||||||
|
request.height = height;
|
||||||
|
request.width = width;
|
||||||
|
|
||||||
|
response = util_common_calloc_s(sizeof(struct lcrc_resize_response));
|
||||||
|
if (response == NULL) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
config = get_connect_config(args);
|
||||||
|
ret = ops->container.resize(&request, response, &config);
|
||||||
|
if (ret != 0) {
|
||||||
|
ERROR("Failed to call resize");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
lcrc_resize_response_free(response);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *exec_console_resize_thread(void *arg)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
const struct client_arguments *args = arg;
|
||||||
|
static struct winsize s_pre_wsz;
|
||||||
|
struct winsize wsz;
|
||||||
|
|
||||||
|
if (!isatty(STDIN_FILENO)) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = pthread_detach(pthread_self());
|
||||||
|
if (ret != 0) {
|
||||||
|
CRIT("Start: set thread detach fail");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
sleep(1); // check the windows size per 1s
|
||||||
|
ret = ioctl(STDIN_FILENO, TIOCGWINSZ, &wsz);
|
||||||
|
if (ret < 0) {
|
||||||
|
WARN("Failed to get window size");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (wsz.ws_row == s_pre_wsz.ws_row && wsz.ws_col == s_pre_wsz.ws_col) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ret = do_resize_exec_console(args, wsz.ws_row, wsz.ws_col);
|
||||||
|
if (ret != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
s_pre_wsz.ws_row = wsz.ws_row;
|
||||||
|
s_pre_wsz.ws_col = wsz.ws_col;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int exec_client_console_resize_thread(struct client_arguments *args)
|
||||||
|
{
|
||||||
|
int res = 0;
|
||||||
|
pthread_t a_thread;
|
||||||
|
|
||||||
|
res = pthread_create(&a_thread, NULL, exec_console_resize_thread, (void *)(args));
|
||||||
|
if (res != 0) {
|
||||||
|
CRIT("Thread creation failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int cmd_exec_main(int argc, const char **argv)
|
int cmd_exec_main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -339,6 +456,18 @@ int cmd_exec_main(int argc, const char **argv)
|
|||||||
custom_cfg->open_stdin = false;
|
custom_cfg->open_stdin = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_cmd_exec_args.exec_suffix = generate_exec_suffix();
|
||||||
|
if (g_cmd_exec_args.exec_suffix == NULL) {
|
||||||
|
ERROR("Failed to generate exec suffix");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (custom_cfg->tty && isatty(STDIN_FILENO) && (custom_cfg->attach_stdin || custom_cfg->attach_stdout ||
|
||||||
|
custom_cfg->attach_stderr)) {
|
||||||
|
(void)exec_client_console_resize_thread(&g_cmd_exec_args);
|
||||||
|
}
|
||||||
|
|
||||||
if (strncmp(g_cmd_exec_args.socket, "tcp://", strlen("tcp://")) == 0) {
|
if (strncmp(g_cmd_exec_args.socket, "tcp://", strlen("tcp://")) == 0) {
|
||||||
ret = remote_cmd_exec(&g_cmd_exec_args, &exit_code);
|
ret = remote_cmd_exec(&g_cmd_exec_args, &exit_code);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
|||||||
@ -636,6 +636,61 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ContainerResize : public ClientBase<ContainerService, ContainerService::Stub, lcrc_resize_request, ResizeRequest,
|
||||||
|
lcrc_resize_response, ResizeResponse> {
|
||||||
|
public:
|
||||||
|
explicit ContainerResize(void *args)
|
||||||
|
: ClientBase(args)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
~ContainerResize() = default;
|
||||||
|
|
||||||
|
int request_to_grpc(const lcrc_resize_request *request, ResizeRequest *grequest) override
|
||||||
|
{
|
||||||
|
if (request == nullptr) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->id != nullptr) {
|
||||||
|
grequest->set_id(request->id);
|
||||||
|
}
|
||||||
|
if (request->suffix != nullptr) {
|
||||||
|
grequest->set_suffix(request->suffix);
|
||||||
|
}
|
||||||
|
grequest->set_height(request->height);
|
||||||
|
|
||||||
|
grequest->set_width(request->width);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int response_from_grpc(ResizeResponse *gresponse, lcrc_resize_response *response) override
|
||||||
|
{
|
||||||
|
response->server_errono = gresponse->cc();
|
||||||
|
if (!gresponse->errmsg().empty()) {
|
||||||
|
response->errmsg = util_strdup_s(gresponse->errmsg().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int check_parameter(const ResizeRequest &req) override
|
||||||
|
{
|
||||||
|
if (req.id().empty()) {
|
||||||
|
ERROR("Missing container id in the request");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Status grpc_call(ClientContext *context, const ResizeRequest &req, ResizeResponse *reply) override
|
||||||
|
{
|
||||||
|
return stub_->Resize(context, req, reply);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class ContainerRestart : public ClientBase<ContainerService, ContainerService::Stub, lcrc_restart_request,
|
class ContainerRestart : public ClientBase<ContainerService, ContainerService::Stub, lcrc_restart_request,
|
||||||
RestartRequest, lcrc_restart_response, RestartResponse> {
|
RestartRequest, lcrc_restart_response, RestartResponse> {
|
||||||
public:
|
public:
|
||||||
@ -752,6 +807,9 @@ public:
|
|||||||
if (request->name != nullptr) {
|
if (request->name != nullptr) {
|
||||||
grequest->set_container_id(request->name);
|
grequest->set_container_id(request->name);
|
||||||
}
|
}
|
||||||
|
if (request->suffix != nullptr) {
|
||||||
|
grequest->set_suffix(request->suffix);
|
||||||
|
}
|
||||||
grequest->set_tty(request->tty);
|
grequest->set_tty(request->tty);
|
||||||
grequest->set_open_stdin(request->open_stdin);
|
grequest->set_open_stdin(request->open_stdin);
|
||||||
grequest->set_attach_stdin(request->attach_stdin);
|
grequest->set_attach_stdin(request->attach_stdin);
|
||||||
@ -876,6 +934,7 @@ public:
|
|||||||
exec.argv_len = (size_t)request->argc;
|
exec.argv_len = (size_t)request->argc;
|
||||||
exec.env = request->env;
|
exec.env = request->env;
|
||||||
exec.env_len = request->env_len;
|
exec.env_len = request->env_len;
|
||||||
|
exec.suffix = request->suffix;
|
||||||
json = container_exec_request_generate_json(&exec, &ctx, &err);
|
json = container_exec_request_generate_json(&exec, &ctx, &err);
|
||||||
if (json == nullptr) {
|
if (json == nullptr) {
|
||||||
format_errorf(&response->errmsg, "Can not generate json: %s", err);
|
format_errorf(&response->errmsg, "Can not generate json: %s", err);
|
||||||
@ -1589,61 +1648,6 @@ cleanup:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ContainerConf : public ClientBase<ContainerService, ContainerService::Stub, lcrc_container_conf_request,
|
|
||||||
Container_conf_Request, lcrc_container_conf_response, Container_conf_Response> {
|
|
||||||
public:
|
|
||||||
explicit ContainerConf(void *args)
|
|
||||||
: ClientBase(args)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
~ContainerConf() = default;
|
|
||||||
|
|
||||||
int request_to_grpc(const lcrc_container_conf_request *request, Container_conf_Request *grequest) override
|
|
||||||
{
|
|
||||||
if (request == nullptr) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request->name != nullptr) {
|
|
||||||
grequest->set_container_id(request->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int response_from_grpc(Container_conf_Response *gresponse, lcrc_container_conf_response *response) override
|
|
||||||
{
|
|
||||||
response->server_errono = gresponse->cc();
|
|
||||||
if (!gresponse->errmsg().empty()) {
|
|
||||||
response->errmsg = util_strdup_s(gresponse->errmsg().c_str());
|
|
||||||
}
|
|
||||||
if (!gresponse->container_logpath().empty()) {
|
|
||||||
response->container_logpath = util_strdup_s(gresponse->container_logpath().c_str());
|
|
||||||
}
|
|
||||||
response->container_logrotate = gresponse->container_logrotate();
|
|
||||||
if (!gresponse->container_logsize().empty()) {
|
|
||||||
response->container_logsize = util_strdup_s(gresponse->container_logsize().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int check_parameter(const Container_conf_Request &req) override
|
|
||||||
{
|
|
||||||
if (req.container_id().empty()) {
|
|
||||||
ERROR("Missing container name in the request");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Status grpc_call(ClientContext *context, const Container_conf_Request &req, Container_conf_Response *reply) override
|
|
||||||
{
|
|
||||||
return stub_->Container_conf(context, req, reply);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class ContainerStats : public ClientBase<ContainerService, ContainerService::Stub, lcrc_stats_request, StatsRequest,
|
class ContainerStats : public ClientBase<ContainerService, ContainerService::Stub, lcrc_stats_request, StatsRequest,
|
||||||
lcrc_stats_response, StatsResponse> {
|
lcrc_stats_response, StatsResponse> {
|
||||||
public:
|
public:
|
||||||
@ -1659,10 +1663,6 @@ public:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->runtime != nullptr) {
|
|
||||||
grequest->set_runtime(request->runtime);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; request->containers != nullptr && i < request->containers_len; i++) {
|
for (size_t i = 0; request->containers != nullptr && i < request->containers_len; i++) {
|
||||||
grequest->add_containers(request->containers[i]);
|
grequest->add_containers(request->containers[i]);
|
||||||
}
|
}
|
||||||
@ -1686,9 +1686,6 @@ public:
|
|||||||
if (!gresponse->containers(i).id().empty()) {
|
if (!gresponse->containers(i).id().empty()) {
|
||||||
response->container_stats[i].id = util_strdup_s(gresponse->containers(i).id().c_str());
|
response->container_stats[i].id = util_strdup_s(gresponse->containers(i).id().c_str());
|
||||||
}
|
}
|
||||||
response->container_stats[i].has_pid = (int)gresponse->containers(i).pid() != -1;
|
|
||||||
response->container_stats[i].pid = (uint32_t)gresponse->containers(i).pid();
|
|
||||||
response->container_stats[i].status = (Container_Status)((int)gresponse->containers(i).status());
|
|
||||||
response->container_stats[i].pids_current = gresponse->containers(i).pids_current();
|
response->container_stats[i].pids_current = gresponse->containers(i).pids_current();
|
||||||
response->container_stats[i].cpu_use_nanos = gresponse->containers(i).cpu_use_nanos();
|
response->container_stats[i].cpu_use_nanos = gresponse->containers(i).cpu_use_nanos();
|
||||||
response->container_stats[i].cpu_system_use = gresponse->containers(i).cpu_system_use();
|
response->container_stats[i].cpu_system_use = gresponse->containers(i).cpu_system_use();
|
||||||
@ -1712,11 +1709,6 @@ public:
|
|||||||
|
|
||||||
int check_parameter(const StatsRequest &req) override
|
int check_parameter(const StatsRequest &req) override
|
||||||
{
|
{
|
||||||
if (req.runtime().empty()) {
|
|
||||||
ERROR("Missing runtime in the request");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2213,7 +2205,6 @@ int grpc_containers_client_ops_init(lcrc_connect_ops *ops)
|
|||||||
ops->container.pause = container_func<lcrc_pause_request, lcrc_pause_response, ContainerPause>;
|
ops->container.pause = container_func<lcrc_pause_request, lcrc_pause_response, ContainerPause>;
|
||||||
ops->container.resume = container_func<lcrc_resume_request, lcrc_resume_response, ContainerResume>;
|
ops->container.resume = container_func<lcrc_resume_request, lcrc_resume_response, ContainerResume>;
|
||||||
ops->container.update = container_func<lcrc_update_request, lcrc_update_response, ContainerUpdate>;
|
ops->container.update = container_func<lcrc_update_request, lcrc_update_response, ContainerUpdate>;
|
||||||
ops->container.conf = container_func<lcrc_container_conf_request, lcrc_container_conf_response, ContainerConf>;
|
|
||||||
ops->container.kill = container_func<lcrc_kill_request, lcrc_kill_response, ContainerKill>;
|
ops->container.kill = container_func<lcrc_kill_request, lcrc_kill_response, ContainerKill>;
|
||||||
ops->container.stats = container_func<lcrc_stats_request, lcrc_stats_response, ContainerStats>;
|
ops->container.stats = container_func<lcrc_stats_request, lcrc_stats_response, ContainerStats>;
|
||||||
ops->container.wait = container_func<lcrc_wait_request, lcrc_wait_response, ContainerWait>;
|
ops->container.wait = container_func<lcrc_wait_request, lcrc_wait_response, ContainerWait>;
|
||||||
@ -2226,6 +2217,7 @@ int grpc_containers_client_ops_init(lcrc_connect_ops *ops)
|
|||||||
container_func<lcrc_copy_to_container_request, lcrc_copy_to_container_response, CopyToContainer>;
|
container_func<lcrc_copy_to_container_request, lcrc_copy_to_container_response, CopyToContainer>;
|
||||||
ops->container.top = container_func<lcrc_top_request, lcrc_top_response, ContainerTop>;
|
ops->container.top = container_func<lcrc_top_request, lcrc_top_response, ContainerTop>;
|
||||||
ops->container.rename = container_func<lcrc_rename_request, lcrc_rename_response, ContainerRename>;
|
ops->container.rename = container_func<lcrc_rename_request, lcrc_rename_response, ContainerRename>;
|
||||||
|
ops->container.resize = container_func<lcrc_resize_request, lcrc_resize_response, ContainerResize>;
|
||||||
ops->container.logs = container_func<lcrc_logs_request, lcrc_logs_response, ContainerLogs>;
|
ops->container.logs = container_func<lcrc_logs_request, lcrc_logs_response, ContainerLogs>;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@ -83,9 +83,6 @@ typedef struct {
|
|||||||
int(*update)(const struct lcrc_update_request *request,
|
int(*update)(const struct lcrc_update_request *request,
|
||||||
struct lcrc_update_response *response, void *arg);
|
struct lcrc_update_response *response, void *arg);
|
||||||
|
|
||||||
int(*conf)(const struct lcrc_container_conf_request *request,
|
|
||||||
struct lcrc_container_conf_response *response, void *arg);
|
|
||||||
|
|
||||||
int(*attach)(const struct lcrc_attach_request *request,
|
int(*attach)(const struct lcrc_attach_request *request,
|
||||||
struct lcrc_attach_response *response, void *arg);
|
struct lcrc_attach_response *response, void *arg);
|
||||||
|
|
||||||
@ -98,7 +95,8 @@ typedef struct {
|
|||||||
struct lcrc_top_response *response, void *arg);
|
struct lcrc_top_response *response, void *arg);
|
||||||
int(*rename)(const struct lcrc_rename_request *request,
|
int(*rename)(const struct lcrc_rename_request *request,
|
||||||
struct lcrc_rename_response *response, void *arg);
|
struct lcrc_rename_response *response, void *arg);
|
||||||
|
int(*resize)(const struct lcrc_resize_request *request,
|
||||||
|
struct lcrc_resize_response *response, void *arg);
|
||||||
int(*logs)(const struct lcrc_logs_request *request, struct lcrc_logs_response *response, void *arg);
|
int(*logs)(const struct lcrc_logs_request *request, struct lcrc_logs_response *response, void *arg);
|
||||||
} container_ops;
|
} container_ops;
|
||||||
|
|
||||||
|
|||||||
@ -271,37 +271,6 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* container conf request to rest */
|
|
||||||
static int container_conf_request_to_rest(const struct lcrc_container_conf_request *lconf_request, char **body,
|
|
||||||
size_t *body_len)
|
|
||||||
{
|
|
||||||
container_conf_request *crequest = NULL;
|
|
||||||
struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 };
|
|
||||||
parser_error err = NULL;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
crequest = util_common_calloc_s(sizeof(container_conf_request));
|
|
||||||
if (crequest == NULL) {
|
|
||||||
ERROR("Out of memory");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lconf_request->name != NULL) {
|
|
||||||
crequest->container_id = util_strdup_s(lconf_request->name);
|
|
||||||
}
|
|
||||||
*body = container_conf_request_generate_json(crequest, &ctx, &err);
|
|
||||||
if (*body == NULL) {
|
|
||||||
ERROR("Failed to generate conf request json:%s", err);
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
*body_len = strlen(*body) + 1;
|
|
||||||
out:
|
|
||||||
free(err);
|
|
||||||
free_container_conf_request(crequest);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* wait request to rest */
|
/* wait request to rest */
|
||||||
static int wait_request_to_rest(const struct lcrc_wait_request *lw_request, char **body, size_t *body_len)
|
static int wait_request_to_rest(const struct lcrc_wait_request *lw_request, char **body, size_t *body_len)
|
||||||
{
|
{
|
||||||
@ -568,47 +537,6 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* unpack container conf response */
|
|
||||||
static int unpack_container_conf_response(const struct parsed_http_message *message, void *arg)
|
|
||||||
{
|
|
||||||
struct lcrc_container_conf_response *response = arg;
|
|
||||||
container_conf_response *cresponse = NULL;
|
|
||||||
parser_error err = NULL;
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
ret = check_status_code(message->status_code);
|
|
||||||
if (ret != 0) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
cresponse = container_conf_response_parse_data(message->body, NULL, &err);
|
|
||||||
if (cresponse == NULL) {
|
|
||||||
ERROR("Invalid create response:%s", err);
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
response->server_errono = cresponse->cc;
|
|
||||||
if (cresponse->errmsg != NULL) {
|
|
||||||
response->errmsg = util_strdup_s(cresponse->errmsg);
|
|
||||||
}
|
|
||||||
if (cresponse->container_logpath != NULL) {
|
|
||||||
response->container_logpath = util_strdup_s(cresponse->container_logpath);
|
|
||||||
}
|
|
||||||
response->container_logrotate = cresponse->container_logrotate;
|
|
||||||
if (cresponse->container_logsize != NULL) {
|
|
||||||
response->container_logsize = util_strdup_s(cresponse->container_logsize);
|
|
||||||
}
|
|
||||||
ret = (cresponse->cc == LCRD_SUCCESS) ? 0 : -1;
|
|
||||||
if (message->status_code == EVHTP_RES_SERVERR) {
|
|
||||||
ret = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
free(err);
|
|
||||||
free_container_conf_response(cresponse);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* unpack wait response */
|
/* unpack wait response */
|
||||||
static int unpack_wait_response(const struct parsed_http_message *message, void *arg)
|
static int unpack_wait_response(const struct parsed_http_message *message, void *arg)
|
||||||
{
|
{
|
||||||
@ -811,39 +739,6 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* rest container conf */
|
|
||||||
static int rest_container_conf(const struct lcrc_container_conf_request *lc_request,
|
|
||||||
struct lcrc_container_conf_response *lc_response, void *arg)
|
|
||||||
{
|
|
||||||
char *body = NULL;
|
|
||||||
int ret = 0;
|
|
||||||
size_t len = 0;
|
|
||||||
client_connect_config_t *connect_config = (client_connect_config_t *)arg;
|
|
||||||
const char *socketname = (const char *)(connect_config->socket);
|
|
||||||
Buffer *c_output = NULL;
|
|
||||||
|
|
||||||
ret = container_conf_request_to_rest(lc_request, &body, &len);
|
|
||||||
if (ret != 0) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
ret = rest_send_requst(socketname, RestHttpHead ContainerServiceConf, body, len, &c_output);
|
|
||||||
if (ret != 0) {
|
|
||||||
lc_response->errmsg = util_strdup_s(errno_to_error_message(LCRD_ERR_CONNECT));
|
|
||||||
lc_response->cc = LCRD_ERR_EXEC;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
ret = get_response(c_output, unpack_container_conf_response, (void *)lc_response);
|
|
||||||
if (ret != 0) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
out:
|
|
||||||
if (c_output != NULL) {
|
|
||||||
buffer_free(c_output);
|
|
||||||
}
|
|
||||||
put_body(body);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* rest container wait */
|
/* rest container wait */
|
||||||
static int rest_container_wait(const struct lcrc_wait_request *lw_request,
|
static int rest_container_wait(const struct lcrc_wait_request *lw_request,
|
||||||
struct lcrc_wait_response *lw_response, void *arg)
|
struct lcrc_wait_response *lw_response, void *arg)
|
||||||
@ -1871,7 +1766,6 @@ int rest_containers_client_ops_init(lcrc_connect_ops *ops)
|
|||||||
ops->container.attach = &rest_container_attach;
|
ops->container.attach = &rest_container_attach;
|
||||||
ops->container.resume = &rest_container_resume;
|
ops->container.resume = &rest_container_resume;
|
||||||
ops->container.update = &rest_container_update;
|
ops->container.update = &rest_container_update;
|
||||||
ops->container.conf = &rest_container_conf;
|
|
||||||
ops->container.kill = &rest_container_kill;
|
ops->container.kill = &rest_container_kill;
|
||||||
ops->container.version = &rest_container_version;
|
ops->container.version = &rest_container_version;
|
||||||
ops->container.wait = &rest_container_wait;
|
ops->container.wait = &rest_container_wait;
|
||||||
|
|||||||
@ -1041,39 +1041,6 @@ Status ContainerServiceImpl::Export(ServerContext *context, const ExportRequest
|
|||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status ContainerServiceImpl::Container_conf(ServerContext *context, const Container_conf_Request *request,
|
|
||||||
Container_conf_Response *reply)
|
|
||||||
{
|
|
||||||
int ret, tret;
|
|
||||||
service_callback_t *cb = nullptr;
|
|
||||||
struct lcrd_container_conf_request *lcrdreq = nullptr;
|
|
||||||
struct lcrd_container_conf_response *lcrdres = nullptr;
|
|
||||||
|
|
||||||
cb = get_service_callback();
|
|
||||||
if (cb == nullptr || cb->container.conf == nullptr) {
|
|
||||||
return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback");
|
|
||||||
}
|
|
||||||
|
|
||||||
tret = container_conf_request_from_grpc(request, &lcrdreq);
|
|
||||||
if (tret != 0) {
|
|
||||||
ERROR("Failed to transform grpc request");
|
|
||||||
reply->set_cc(LCRD_ERR_INPUT);
|
|
||||||
return Status::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = cb->container.conf(lcrdreq, &lcrdres);
|
|
||||||
tret = container_conf_response_to_grpc(lcrdres, reply);
|
|
||||||
|
|
||||||
lcrd_container_conf_request_free(lcrdreq);
|
|
||||||
lcrd_container_conf_response_free(lcrdres);
|
|
||||||
if (tret != 0) {
|
|
||||||
reply->set_errmsg(errno_to_error_message(LCRD_ERR_INTERNAL));
|
|
||||||
reply->set_cc(LCRD_ERR_INTERNAL);
|
|
||||||
ERROR("Failed to translate response to grpc, operation is %s", ret ? "failed" : "success");
|
|
||||||
}
|
|
||||||
return Status::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
Status ContainerServiceImpl::Rename(ServerContext *context, const RenameRequest *request,
|
Status ContainerServiceImpl::Rename(ServerContext *context, const RenameRequest *request,
|
||||||
RenameResponse *reply)
|
RenameResponse *reply)
|
||||||
{
|
{
|
||||||
@ -1112,6 +1079,44 @@ Status ContainerServiceImpl::Rename(ServerContext *context, const RenameRequest
|
|||||||
return Status::OK;
|
return Status::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status ContainerServiceImpl::Resize(ServerContext *context, const ResizeRequest *request,
|
||||||
|
ResizeResponse *reply)
|
||||||
|
{
|
||||||
|
int ret, tret;
|
||||||
|
service_callback_t *cb = nullptr;
|
||||||
|
struct lcrd_container_resize_request *lcrdreq = nullptr;
|
||||||
|
struct lcrd_container_resize_response *lcrdres = nullptr;
|
||||||
|
|
||||||
|
auto status = GrpcServerTlsAuth::auth(context, "container_resize");
|
||||||
|
if (!status.ok()) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
cb = get_service_callback();
|
||||||
|
if (cb == nullptr || cb->container.resize == nullptr) {
|
||||||
|
return Status(StatusCode::UNIMPLEMENTED, "Unimplemented callback");
|
||||||
|
}
|
||||||
|
|
||||||
|
tret = container_resize_request_from_grpc(request, &lcrdreq);
|
||||||
|
if (tret != 0) {
|
||||||
|
ERROR("Failed to transform grpc request");
|
||||||
|
reply->set_cc(LCRD_ERR_INPUT);
|
||||||
|
return Status::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = cb->container.resize(lcrdreq, &lcrdres);
|
||||||
|
tret = container_resize_response_to_grpc(lcrdres, reply);
|
||||||
|
|
||||||
|
lcrd_container_resize_request_free(lcrdreq);
|
||||||
|
lcrd_container_resize_response_free(lcrdres);
|
||||||
|
if (tret != 0) {
|
||||||
|
reply->set_errmsg(errno_to_error_message(LCRD_ERR_INTERNAL));
|
||||||
|
reply->set_cc(LCRD_ERR_INTERNAL);
|
||||||
|
ERROR("Failed to translate response to grpc, operation is %s", ret ? "failed" : "success");
|
||||||
|
}
|
||||||
|
return Status::OK;
|
||||||
|
}
|
||||||
|
|
||||||
Status ContainerServiceImpl::Update(ServerContext *context, const UpdateRequest *request, UpdateResponse *reply)
|
Status ContainerServiceImpl::Update(ServerContext *context, const UpdateRequest *request, UpdateResponse *reply)
|
||||||
{
|
{
|
||||||
int ret, tret;
|
int ret, tret;
|
||||||
|
|||||||
@ -75,11 +75,10 @@ public:
|
|||||||
|
|
||||||
Status Resume(ServerContext *context, const ResumeRequest *request, ResumeResponse *reply) override;
|
Status Resume(ServerContext *context, const ResumeRequest *request, ResumeResponse *reply) override;
|
||||||
|
|
||||||
Status Container_conf(ServerContext *context, const Container_conf_Request *request,
|
|
||||||
Container_conf_Response *reply) override;
|
|
||||||
|
|
||||||
Status Rename(ServerContext *context, const RenameRequest *request, RenameResponse *reply) override;
|
Status Rename(ServerContext *context, const RenameRequest *request, RenameResponse *reply) override;
|
||||||
|
|
||||||
|
Status Resize(ServerContext *context, const ResizeRequest *request, ResizeResponse *reply) override;
|
||||||
|
|
||||||
Status Update(ServerContext *context, const UpdateRequest *request, UpdateResponse *reply) override;
|
Status Update(ServerContext *context, const UpdateRequest *request, UpdateResponse *reply) override;
|
||||||
|
|
||||||
|
|
||||||
@ -165,18 +164,18 @@ private:
|
|||||||
|
|
||||||
int resume_request_from_grpc(const ResumeRequest *grequest, container_resume_request **request);
|
int resume_request_from_grpc(const ResumeRequest *grequest, container_resume_request **request);
|
||||||
|
|
||||||
int container_conf_request_from_grpc(const Container_conf_Request *grequest,
|
|
||||||
struct lcrd_container_conf_request **request);
|
|
||||||
|
|
||||||
int container_conf_response_to_grpc(const struct lcrd_container_conf_response *response,
|
|
||||||
Container_conf_Response *gresponse);
|
|
||||||
|
|
||||||
int container_rename_request_from_grpc(const RenameRequest *grequest,
|
int container_rename_request_from_grpc(const RenameRequest *grequest,
|
||||||
struct lcrd_container_rename_request **request);
|
struct lcrd_container_rename_request **request);
|
||||||
|
|
||||||
int container_rename_response_to_grpc(const struct lcrd_container_rename_response *response,
|
int container_rename_response_to_grpc(const struct lcrd_container_rename_response *response,
|
||||||
RenameResponse *gresponse);
|
RenameResponse *gresponse);
|
||||||
|
|
||||||
|
int container_resize_request_from_grpc(const ResizeRequest *grequest,
|
||||||
|
struct lcrd_container_resize_request **request);
|
||||||
|
|
||||||
|
int container_resize_response_to_grpc(const struct lcrd_container_resize_response *response,
|
||||||
|
ResizeResponse *gresponse);
|
||||||
|
|
||||||
int update_request_from_grpc(const UpdateRequest *grequest, container_update_request **request);
|
int update_request_from_grpc(const UpdateRequest *grequest, container_update_request **request);
|
||||||
|
|
||||||
int update_response_to_grpc(const container_update_response *response, UpdateResponse *gresponse);
|
int update_response_to_grpc(const container_update_response *response, UpdateResponse *gresponse);
|
||||||
|
|||||||
@ -352,6 +352,10 @@ int ContainerServiceImpl::exec_request_from_grpc(const ExecRequest *grequest, co
|
|||||||
tmpreq->container_id = util_strdup_s(grequest->container_id().c_str());
|
tmpreq->container_id = util_strdup_s(grequest->container_id().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!grequest->suffix().empty()) {
|
||||||
|
tmpreq->suffix = util_strdup_s(grequest->suffix().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
tmpreq->tty = grequest->tty();
|
tmpreq->tty = grequest->tty();
|
||||||
tmpreq->attach_stdin = grequest->attach_stdin();
|
tmpreq->attach_stdin = grequest->attach_stdin();
|
||||||
tmpreq->attach_stdout = grequest->attach_stdout();
|
tmpreq->attach_stdout = grequest->attach_stdout();
|
||||||
@ -607,46 +611,6 @@ int ContainerServiceImpl::resume_request_from_grpc(const ResumeRequest *grequest
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ContainerServiceImpl::container_conf_request_from_grpc(const Container_conf_Request *grequest,
|
|
||||||
struct lcrd_container_conf_request **request)
|
|
||||||
{
|
|
||||||
struct lcrd_container_conf_request *tmpreq = (struct lcrd_container_conf_request *)util_common_calloc_s(
|
|
||||||
sizeof(struct lcrd_container_conf_request));
|
|
||||||
if (tmpreq == nullptr) {
|
|
||||||
ERROR("Out of memory");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!grequest->container_id().empty()) {
|
|
||||||
tmpreq->name = util_strdup_s(grequest->container_id().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
*request = tmpreq;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ContainerServiceImpl::container_conf_response_to_grpc(const struct lcrd_container_conf_response *response,
|
|
||||||
Container_conf_Response *gresponse)
|
|
||||||
{
|
|
||||||
if (response == nullptr) {
|
|
||||||
gresponse->set_cc(LCRD_ERR_MEMOUT);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
gresponse->set_cc(response->cc);
|
|
||||||
if (response->errmsg != nullptr) {
|
|
||||||
gresponse->set_errmsg(response->errmsg);
|
|
||||||
}
|
|
||||||
if (response->container_logpath != nullptr) {
|
|
||||||
gresponse->set_container_logpath(response->container_logpath);
|
|
||||||
}
|
|
||||||
gresponse->set_container_logrotate(response->container_logrotate);
|
|
||||||
if (response->container_logsize != nullptr) {
|
|
||||||
gresponse->set_container_logsize(response->container_logsize);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ContainerServiceImpl::container_rename_request_from_grpc(const RenameRequest *grequest,
|
int ContainerServiceImpl::container_rename_request_from_grpc(const RenameRequest *grequest,
|
||||||
struct lcrd_container_rename_request **request)
|
struct lcrd_container_rename_request **request)
|
||||||
{
|
{
|
||||||
@ -688,6 +652,50 @@ int ContainerServiceImpl::container_rename_response_to_grpc(const struct lcrd_co
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ContainerServiceImpl::container_resize_request_from_grpc(const ResizeRequest *grequest,
|
||||||
|
struct lcrd_container_resize_request **request)
|
||||||
|
{
|
||||||
|
struct lcrd_container_resize_request *tmpreq = (struct lcrd_container_resize_request *)util_common_calloc_s(
|
||||||
|
sizeof(struct lcrd_container_resize_request));
|
||||||
|
if (tmpreq == nullptr) {
|
||||||
|
ERROR("Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!grequest->id().empty()) {
|
||||||
|
tmpreq->id = util_strdup_s(grequest->id().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!grequest->suffix().empty()) {
|
||||||
|
tmpreq->suffix = util_strdup_s(grequest->suffix().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpreq->height = grequest->height();
|
||||||
|
|
||||||
|
tmpreq->width = grequest->width();
|
||||||
|
|
||||||
|
*request = tmpreq;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ContainerServiceImpl::container_resize_response_to_grpc(const struct lcrd_container_resize_response *response,
|
||||||
|
ResizeResponse *gresponse)
|
||||||
|
{
|
||||||
|
if (response == nullptr) {
|
||||||
|
gresponse->set_cc(LCRD_ERR_MEMOUT);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
gresponse->set_cc(response->cc);
|
||||||
|
if (response->errmsg != nullptr) {
|
||||||
|
gresponse->set_errmsg(response->errmsg);
|
||||||
|
}
|
||||||
|
if (response->id != nullptr) {
|
||||||
|
gresponse->set_id(response->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int ContainerServiceImpl::update_request_from_grpc(const UpdateRequest *grequest, container_update_request **request)
|
int ContainerServiceImpl::update_request_from_grpc(const UpdateRequest *grequest, container_update_request **request)
|
||||||
{
|
{
|
||||||
@ -735,10 +743,6 @@ int ContainerServiceImpl::stats_request_from_grpc(const StatsRequest *grequest,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!grequest->runtime().empty()) {
|
|
||||||
tmpreq->runtime = util_strdup_s(grequest->runtime().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (grequest->containers_size() > 0) {
|
if (grequest->containers_size() > 0) {
|
||||||
tmpreq->containers = (char **)util_common_calloc_s(grequest->containers_size() * sizeof(char *));
|
tmpreq->containers = (char **)util_common_calloc_s(grequest->containers_size() * sizeof(char *));
|
||||||
if (tmpreq->containers == nullptr) {
|
if (tmpreq->containers == nullptr) {
|
||||||
@ -771,12 +775,6 @@ int ContainerServiceImpl::stats_response_to_grpc(const container_stats_response
|
|||||||
if (response->container_stats[i]->id != nullptr) {
|
if (response->container_stats[i]->id != nullptr) {
|
||||||
stats->set_id(response->container_stats[i]->id);
|
stats->set_id(response->container_stats[i]->id);
|
||||||
}
|
}
|
||||||
if (response->container_stats[i]->has_pid) {
|
|
||||||
stats->set_pid(response->container_stats[i]->pid);
|
|
||||||
} else {
|
|
||||||
stats->set_pid(-1);
|
|
||||||
}
|
|
||||||
stats->set_status((ContainerStatus)response->container_stats[i]->status);
|
|
||||||
stats->set_pids_current(response->container_stats[i]->pids_current);
|
stats->set_pids_current(response->container_stats[i]->pids_current);
|
||||||
stats->set_cpu_use_nanos(response->container_stats[i]->cpu_use_nanos);
|
stats->set_cpu_use_nanos(response->container_stats[i]->cpu_use_nanos);
|
||||||
stats->set_cpu_system_use(response->container_stats[i]->cpu_system_use);
|
stats->set_cpu_system_use(response->container_stats[i]->cpu_system_use);
|
||||||
|
|||||||
@ -150,20 +150,6 @@ static int list_request_check(void *req)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* container conf response check */
|
|
||||||
static int container_conf_request_check(void *req)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
struct lcrd_container_conf_request *req_conf = (struct lcrd_container_conf_request *)req;
|
|
||||||
if (req_conf->name == NULL) {
|
|
||||||
DEBUG("container name error");
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
/* create request check */
|
/* create request check */
|
||||||
static int create_request_check(void *req)
|
static int create_request_check(void *req)
|
||||||
{
|
{
|
||||||
@ -297,11 +283,6 @@ static struct rest_handle_st g_rest_handle[] = {
|
|||||||
.request_parse_data = (void *)container_wait_request_parse_data,
|
.request_parse_data = (void *)container_wait_request_parse_data,
|
||||||
.request_check = wait_request_check,
|
.request_check = wait_request_check,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
.name = ContainerServiceConf,
|
|
||||||
.request_parse_data = (void *)container_conf_request_parse_data,
|
|
||||||
.request_check = container_conf_request_check,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
.name = ContainerServiceInspect,
|
.name = ContainerServiceInspect,
|
||||||
.request_parse_data = (void *)container_inspect_request_parse_data,
|
.request_parse_data = (void *)container_inspect_request_parse_data,
|
||||||
@ -411,50 +392,6 @@ out:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* evhtp send container conf repsponse */
|
|
||||||
static void evhtp_send_container_conf_repsponse(evhtp_request_t *req, container_conf_response *response, int rescode)
|
|
||||||
{
|
|
||||||
parser_error err = NULL;
|
|
||||||
struct parser_context ctx = { OPT_GEN_SIMPLIFY, 0 };
|
|
||||||
char *responsedata = NULL;
|
|
||||||
|
|
||||||
responsedata = container_conf_response_generate_json(response, &ctx, &err);
|
|
||||||
if (responsedata == NULL) {
|
|
||||||
ERROR("Failed to generate container_conf request json:%s", err);
|
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
evhtp_send_response(req, responsedata, rescode);
|
|
||||||
|
|
||||||
out:
|
|
||||||
free(err);
|
|
||||||
free(responsedata);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* container conf response to rest */
|
|
||||||
static int container_conf_response_to_rest(container_conf_response *cresponse,
|
|
||||||
struct lcrd_container_conf_response *response)
|
|
||||||
{
|
|
||||||
if (response == NULL) {
|
|
||||||
cresponse->cc = LCRD_ERR_MEMOUT;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
cresponse->cc = response->cc;
|
|
||||||
if (response->errmsg) {
|
|
||||||
cresponse->errmsg = util_strdup_s(response->errmsg);
|
|
||||||
}
|
|
||||||
if (response->container_logpath) {
|
|
||||||
cresponse->container_logpath = util_strdup_s(response->container_logpath);
|
|
||||||
}
|
|
||||||
cresponse->container_logrotate = response->container_logrotate;
|
|
||||||
if (response->container_logsize) {
|
|
||||||
cresponse->container_logsize = util_strdup_s(response->container_logsize);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* evhtp send wait repsponse */
|
/* evhtp send wait repsponse */
|
||||||
static void evhtp_send_wait_repsponse(evhtp_request_t *req, container_wait_response *response, int rescode)
|
static void evhtp_send_wait_repsponse(evhtp_request_t *req, container_wait_response *response, int rescode)
|
||||||
{
|
{
|
||||||
@ -547,58 +484,6 @@ out:
|
|||||||
free_container_start_response(cresponse);
|
free_container_start_response(cresponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* rest container conf cb */
|
|
||||||
static void rest_container_conf_cb(evhtp_request_t *req, void *arg)
|
|
||||||
{
|
|
||||||
int ret, tret;
|
|
||||||
service_callback_t *cb = NULL;
|
|
||||||
struct lcrd_container_conf_request *lcrdreq = NULL;
|
|
||||||
struct lcrd_container_conf_response *lcrdres = NULL;
|
|
||||||
container_conf_response *cresponse = NULL;
|
|
||||||
|
|
||||||
// only deal with POST request
|
|
||||||
if (evhtp_request_get_method(req) != htp_method_POST) {
|
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cb = get_service_callback();
|
|
||||||
if (cb == NULL || cb->container.conf == NULL) {
|
|
||||||
ERROR("Unimplemented callback");
|
|
||||||
evhtp_send_reply(req, EVHTP_RES_NOTIMPL);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cresponse = util_common_calloc_s(sizeof(container_conf_response));
|
|
||||||
if (cresponse == NULL) {
|
|
||||||
evhtp_send_reply(req, EVHTP_RES_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tret = action_request_from_rest(req, (void **)&lcrdreq, ContainerServiceConf);
|
|
||||||
if (tret < 0) {
|
|
||||||
ERROR("Bad request");
|
|
||||||
cresponse->cc = LCRD_ERR_EXEC;
|
|
||||||
evhtp_send_container_conf_repsponse(req, cresponse, EVHTP_RES_SERVERR);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = cb->container.conf(lcrdreq, &lcrdres);
|
|
||||||
|
|
||||||
tret = container_conf_response_to_rest(cresponse, lcrdres);
|
|
||||||
if (tret) {
|
|
||||||
ERROR("Failed to translate response to rest,operation is %s", ret ? "failed" : "success");
|
|
||||||
cresponse->cc = LCRD_ERR_EXEC;
|
|
||||||
if (cresponse->errmsg == NULL) {
|
|
||||||
cresponse->errmsg = util_strdup_s(errno_to_error_message(LCRD_ERR_INTERNAL));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
evhtp_send_container_conf_repsponse(req, cresponse, EVHTP_RES_OK);
|
|
||||||
out:
|
|
||||||
lcrd_container_conf_request_free(lcrdreq);
|
|
||||||
lcrd_container_conf_response_free(lcrdres);
|
|
||||||
free_container_conf_response(cresponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* rest wait cb */
|
/* rest wait cb */
|
||||||
static void rest_wait_cb(evhtp_request_t *req, void *arg)
|
static void rest_wait_cb(evhtp_request_t *req, void *arg)
|
||||||
{
|
{
|
||||||
@ -1213,11 +1098,6 @@ int rest_register_containers_handler(evhtp_t *htp)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evhtp_set_cb(htp, ContainerServiceConf, rest_container_conf_cb, NULL) == NULL) {
|
|
||||||
ERROR("Failed to register container_conf callback");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (evhtp_set_cb(htp, ContainerServiceWait, rest_wait_cb, NULL) == NULL) {
|
if (evhtp_set_cb(htp, ContainerServiceWait, rest_wait_cb, NULL) == NULL) {
|
||||||
ERROR("Failed to register wait callback");
|
ERROR("Failed to register wait callback");
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@ -1424,4 +1424,54 @@ void usleep_nointerupt(unsigned long usec)
|
|||||||
request = remain;
|
request = remain;
|
||||||
} while (ret == -1 && errno == EINTR);
|
} while (ret == -1 && errno == EINTR);
|
||||||
}
|
}
|
||||||
|
int util_generate_random_str(char *id, size_t len)
|
||||||
|
{
|
||||||
|
int fd = -1;
|
||||||
|
int num = 0;
|
||||||
|
size_t i;
|
||||||
|
const int m = 256;
|
||||||
|
|
||||||
|
len = len / 2;
|
||||||
|
fd = open("/dev/urandom", O_RDONLY);
|
||||||
|
if (fd == -1) {
|
||||||
|
ERROR("Failed to open /dev/urandom");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
int nret;
|
||||||
|
if (read(fd, &num, sizeof(int)) < 0) {
|
||||||
|
ERROR("Failed to read urandom value");
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
unsigned char rs = (unsigned char)(num % m);
|
||||||
|
nret = snprintf((id + i * 2), ((len - i) * 2 + 1), "%02x", (unsigned int)rs);
|
||||||
|
if (nret < 0 || (size_t)nret >= ((len - i) * 2 + 1)) {
|
||||||
|
ERROR("Failed to snprintf random string");
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
id[i * 2] = '\0';
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_array_elem(char **array, size_t total, size_t *pos, const char *elem)
|
||||||
|
{
|
||||||
|
if (*pos + 1 >= total - 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
array[*pos] = util_strdup_s(elem);
|
||||||
|
*pos += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_array_kv(char **array, size_t total, size_t *pos, const char *k, const char *v)
|
||||||
|
{
|
||||||
|
if (k == NULL || v == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
add_array_elem(array, total, pos, k);
|
||||||
|
add_array_elem(array, total, pos, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -57,6 +57,8 @@ extern "C" {
|
|||||||
|
|
||||||
#define ECOMMON 1
|
#define ECOMMON 1
|
||||||
|
|
||||||
|
#define PARAM_NUM 100
|
||||||
|
|
||||||
/* image error start */
|
/* image error start */
|
||||||
#define EIMAGEBUSY 2
|
#define EIMAGEBUSY 2
|
||||||
#define ENAMECONFLICT 3
|
#define ENAMECONFLICT 3
|
||||||
@ -90,6 +92,8 @@ extern "C" {
|
|||||||
/* container id max length */
|
/* container id max length */
|
||||||
#define CONTAINER_ID_MAX_LEN 64
|
#define CONTAINER_ID_MAX_LEN 64
|
||||||
|
|
||||||
|
#define CONTAINER_EXEC_ID_MAX_LEN 64
|
||||||
|
|
||||||
#define LIST_SIZE_MAX 1000LL
|
#define LIST_SIZE_MAX 1000LL
|
||||||
#define LIST_DEVICE_SIZE_MAX 10000LL
|
#define LIST_DEVICE_SIZE_MAX 10000LL
|
||||||
#define LIST_ENV_SIZE_MAX 200000LL
|
#define LIST_ENV_SIZE_MAX 200000LL
|
||||||
@ -418,6 +422,12 @@ bool util_check_signal_valid(int sig);
|
|||||||
|
|
||||||
void usleep_nointerupt(unsigned long usec);
|
void usleep_nointerupt(unsigned long usec);
|
||||||
|
|
||||||
|
int util_generate_random_str(char *id, size_t len);
|
||||||
|
|
||||||
|
void add_array_elem(char **array, size_t total, size_t *pos, const char *elem);
|
||||||
|
|
||||||
|
void add_array_kv(char **array, size_t total, size_t *pos, const char *k, const char *v);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -95,15 +95,15 @@ int util_wildcard_to_regex(const char *wildcard, char **regex)
|
|||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
size_t regex_size;
|
size_t regex_size;
|
||||||
char escapes[] = { '$', '^', '[', ']', '(', ')', '{', '|', '+', '\\', '.', '<', '>', '}' };
|
char escapes[] = { '$', '^', '[', ']', '(', ')', '{', '|', '+', '\\', '.', '<', '>', '}' };
|
||||||
if (wildcard == NULL) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (wildcard == NULL || regex == NULL) {
|
||||||
|
ERROR("Invalid output parameter");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (get_regex_size_from_wildcard(wildcard, escapes, sizeof(escapes) / sizeof(char), ®ex_size) != 0) {
|
if (get_regex_size_from_wildcard(wildcard, escapes, sizeof(escapes) / sizeof(char), ®ex_size) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
*regex = (char *)util_common_calloc_s(regex_size);
|
||||||
*regex = malloc(regex_size);
|
|
||||||
if (*regex == NULL) {
|
if (*regex == NULL) {
|
||||||
ERROR("Out of memory");
|
ERROR("Out of memory");
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@ -622,3 +622,14 @@ cleanup:
|
|||||||
return bret;
|
return bret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool util_valid_exec_suffix(const char *suffix)
|
||||||
|
{
|
||||||
|
char *patten = "^[a-f0-9]{64}$";
|
||||||
|
|
||||||
|
if (suffix == NULL) {
|
||||||
|
ERROR("invalid NULL param");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return util_reg_match(patten, suffix) == 0;
|
||||||
|
}
|
||||||
|
|||||||
@ -96,6 +96,8 @@ bool util_valid_runtime_name(const char *name);
|
|||||||
|
|
||||||
bool util_valid_short_sha256_id(const char *id);
|
bool util_valid_short_sha256_id(const char *id);
|
||||||
|
|
||||||
|
bool util_valid_exec_suffix(const char *suffix);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -23,12 +23,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct engine_console_config {
|
|
||||||
char *log_path;
|
|
||||||
unsigned int log_rotate;
|
|
||||||
char *log_file_size;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct engine_cgroup_resources {
|
struct engine_cgroup_resources {
|
||||||
uint64_t blkio_weight;
|
uint64_t blkio_weight;
|
||||||
uint64_t cpu_shares;
|
uint64_t cpu_shares;
|
||||||
@ -66,11 +60,13 @@ struct engine_container_summary_info {
|
|||||||
char *finishat;
|
char *finishat;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct engine_container_info {
|
struct engine_container_status_info {
|
||||||
char *id;
|
|
||||||
bool has_pid;
|
bool has_pid;
|
||||||
uint32_t pid;
|
uint32_t pid;
|
||||||
Engine_Container_Status status;
|
Engine_Container_Status status;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct engine_container_resources_stats_info {
|
||||||
uint64_t pids_current;
|
uint64_t pids_current;
|
||||||
/* CPU usage */
|
/* CPU usage */
|
||||||
uint64_t cpu_use_nanos;
|
uint64_t cpu_use_nanos;
|
||||||
@ -131,6 +127,8 @@ typedef struct _engine_exec_request_t {
|
|||||||
size_t args_len;
|
size_t args_len;
|
||||||
|
|
||||||
int64_t timeout;
|
int64_t timeout;
|
||||||
|
|
||||||
|
const char *suffix;
|
||||||
} engine_exec_request_t;
|
} engine_exec_request_t;
|
||||||
|
|
||||||
|
|
||||||
@ -149,33 +147,25 @@ typedef bool (*engine_resume_t)(const char *name, const char *enginepath);
|
|||||||
|
|
||||||
typedef bool (*engine_reset_t)(const char *name, const char *enginepath);
|
typedef bool (*engine_reset_t)(const char *name, const char *enginepath);
|
||||||
|
|
||||||
|
typedef bool (*engine_resize_t)(const char *name, const char *lcrpath, unsigned int height, unsigned int width);
|
||||||
|
typedef bool (*engine_exec_resize_t)(const char *name, const char *lcrpath, const char *suffix, unsigned int height,
|
||||||
|
unsigned int width);
|
||||||
|
|
||||||
typedef bool (*engine_update_t)(const char *name, const char *enginepath, const struct engine_cgroup_resources *cr);
|
typedef bool (*engine_update_t)(const char *name, const char *enginepath, const struct engine_cgroup_resources *cr);
|
||||||
|
|
||||||
typedef bool (*engine_exec_t)(const engine_exec_request_t *request, int *exit_code);
|
typedef bool (*engine_exec_t)(const engine_exec_request_t *request, int *exit_code);
|
||||||
|
|
||||||
typedef int (*engine_get_all_containers_info_t)(const char *enginepath, struct engine_container_summary_info **cons);
|
|
||||||
|
|
||||||
typedef struct engine_container_summary_info *(*engine_get_container_info_t)(const char *name, const char *enginepath);
|
|
||||||
|
|
||||||
typedef void (*engine_free_container_info_t)(struct engine_container_summary_info *info);
|
|
||||||
|
|
||||||
typedef void (*engine_free_all_containers_info_t)(struct engine_container_summary_info *info, int num);
|
|
||||||
|
|
||||||
typedef int (*engine_get_container_status_t)(const char *name, const char *enginepath,
|
typedef int (*engine_get_container_status_t)(const char *name, const char *enginepath,
|
||||||
struct engine_container_info *status);
|
struct engine_container_status_info *status);
|
||||||
|
|
||||||
typedef void (*engine_free_container_status_t)(struct engine_container_info *container);
|
typedef int (*engine_get_container_resources_stats_t)(const char *name, const char *enginepath,
|
||||||
|
struct engine_container_resources_stats_info *rs_stats);
|
||||||
|
|
||||||
typedef bool (*engine_get_container_pids_t)(const char *name, const char *rootpath, pid_t **pids, size_t *pids_len);
|
typedef bool (*engine_get_container_pids_t)(const char *name, const char *rootpath, pid_t **pids, size_t *pids_len);
|
||||||
|
|
||||||
typedef bool (*engine_console_t)(const char *name, const char *enginepath, char *in_fifo, char *out_fifo,
|
typedef bool (*engine_console_t)(const char *name, const char *enginepath, char *in_fifo, char *out_fifo,
|
||||||
char *err_fifo);
|
char *err_fifo);
|
||||||
|
|
||||||
typedef bool (*engine_get_console_config_t)(const char *name, const char *enginepath,
|
|
||||||
struct engine_console_config *config);
|
|
||||||
|
|
||||||
typedef void (*engine_free_console_config_t)(struct engine_console_config *config);
|
|
||||||
|
|
||||||
typedef int (*engine_log_init_t)(const char *name, const char *file, const char *priority, const char *prefix,
|
typedef int (*engine_log_init_t)(const char *name, const char *file, const char *priority, const char *prefix,
|
||||||
int quiet, const char *enginepath);
|
int quiet, const char *enginepath);
|
||||||
|
|
||||||
@ -193,17 +183,15 @@ struct engine_operation {
|
|||||||
engine_pause_t engine_pause_op;
|
engine_pause_t engine_pause_op;
|
||||||
engine_resume_t engine_resume_op;
|
engine_resume_t engine_resume_op;
|
||||||
engine_reset_t engine_reset_op;
|
engine_reset_t engine_reset_op;
|
||||||
|
engine_resize_t engine_resize_op;
|
||||||
|
engine_exec_resize_t engine_exec_resize_op;
|
||||||
engine_exec_t engine_exec_op;
|
engine_exec_t engine_exec_op;
|
||||||
engine_console_t engine_console_op;
|
engine_console_t engine_console_op;
|
||||||
engine_get_container_status_t engine_get_container_status_op;
|
engine_get_container_status_t engine_get_container_status_op;
|
||||||
engine_free_container_status_t engine_free_container_status_op;
|
engine_get_container_resources_stats_t engine_get_container_resources_stats_op;
|
||||||
engine_get_all_containers_info_t engine_get_all_containers_info_op;
|
|
||||||
engine_free_all_containers_info_t engine_free_all_containers_info_op;
|
|
||||||
engine_get_container_pids_t engine_get_container_pids_op;
|
engine_get_container_pids_t engine_get_container_pids_op;
|
||||||
engine_log_init_t engine_log_init_op;
|
engine_log_init_t engine_log_init_op;
|
||||||
engine_update_t engine_update_op;
|
engine_update_t engine_update_op;
|
||||||
engine_get_console_config_t engine_get_console_config_op;
|
|
||||||
engine_free_console_config_t engine_free_console_config_op;
|
|
||||||
engine_get_errmsg_t engine_get_errmsg_op;
|
engine_get_errmsg_t engine_get_errmsg_op;
|
||||||
engine_clear_errmsg_t engine_clear_errmsg_op;
|
engine_clear_errmsg_t engine_clear_errmsg_op;
|
||||||
engine_clean_t engine_clean_op;
|
engine_clean_t engine_clean_op;
|
||||||
|
|||||||
@ -27,23 +27,15 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "lcrd_config.h"
|
#include "lcrd_config.h"
|
||||||
|
|
||||||
typedef int(*lcr_list_all_containers_t)(const char *lcrpath, struct lcr_container_info **info_arr);
|
|
||||||
typedef void(*lcr_containers_info_free_t)(struct lcr_container_info **info_arr, size_t size);
|
|
||||||
typedef bool(*lcr_state_op_t)(const char *name, const char *lcrpath, struct lcr_container_state *lcs);
|
typedef bool(*lcr_state_op_t)(const char *name, const char *lcrpath, struct lcr_container_state *lcs);
|
||||||
typedef void(*lcr_container_state_free_t)(struct lcr_container_state *lcs);
|
typedef void(*lcr_container_state_free_t)(struct lcr_container_state *lcs);
|
||||||
typedef bool(*lcr_update_op_t)(const char *name, const char *lcrpath, struct lcr_cgroup_resources *cr);
|
typedef bool(*lcr_update_op_t)(const char *name, const char *lcrpath, struct lcr_cgroup_resources *cr);
|
||||||
typedef bool(*lcr_get_console_config_op_t)(const char *name, const char *lcrpath, struct lcr_console_config *config);
|
|
||||||
typedef void(*lcr_free_console_config_op_t)(struct lcr_console_config *config);
|
|
||||||
typedef bool(*lcr_start_op_t)(struct lcr_start_request *request);
|
typedef bool(*lcr_start_op_t)(struct lcr_start_request *request);
|
||||||
typedef bool(*lcr_exec_op_t)(const struct lcr_exec_request *request, int *exit_code);
|
typedef bool(*lcr_exec_op_t)(const struct lcr_exec_request *request, int *exit_code);
|
||||||
|
|
||||||
static lcr_list_all_containers_t g_lcr_list_all_containers_op = NULL;
|
|
||||||
static lcr_containers_info_free_t g_lcr_containers_info_free_op = NULL;
|
|
||||||
static lcr_state_op_t g_lcr_state_op = NULL;
|
static lcr_state_op_t g_lcr_state_op = NULL;
|
||||||
static lcr_container_state_free_t g_lcr_container_state_free_op = NULL;
|
static lcr_container_state_free_t g_lcr_container_state_free_op = NULL;
|
||||||
static lcr_update_op_t g_lcr_update_op = NULL;
|
static lcr_update_op_t g_lcr_update_op = NULL;
|
||||||
static lcr_get_console_config_op_t g_lcr_get_console_config_op = NULL;
|
|
||||||
static lcr_free_console_config_op_t g_lcr_free_console_config_op = NULL;
|
|
||||||
static lcr_start_op_t g_lcr_start_op = NULL;
|
static lcr_start_op_t g_lcr_start_op = NULL;
|
||||||
static lcr_exec_op_t g_lcr_exec_op = NULL;
|
static lcr_exec_op_t g_lcr_exec_op = NULL;
|
||||||
/*
|
/*
|
||||||
@ -120,199 +112,21 @@ static bool lcr_exec_container(const engine_exec_request_t *request, int *exit_c
|
|||||||
return g_lcr_exec_op(lcr_request, exit_code);
|
return g_lcr_exec_op(lcr_request, exit_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free console config */
|
|
||||||
void free_console_config(struct engine_console_config *config)
|
|
||||||
{
|
|
||||||
if (config == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
free(config->log_path);
|
|
||||||
config->log_path = NULL;
|
|
||||||
|
|
||||||
free(config->log_file_size);
|
|
||||||
config->log_file_size = NULL;
|
|
||||||
|
|
||||||
config->log_rotate = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get console config */
|
|
||||||
bool get_console_config(const char *name, const char *lcrpath, struct engine_console_config *config)
|
|
||||||
{
|
|
||||||
struct lcr_console_config lcr_config;
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
if (name == NULL || config == NULL) {
|
|
||||||
ERROR("Invalid arguments");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void)memset(&lcr_config, 0, sizeof(struct lcr_console_config));
|
|
||||||
|
|
||||||
if (g_lcr_get_console_config_op != NULL) {
|
|
||||||
ret = g_lcr_get_console_config_op(name, lcrpath, &lcr_config);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret) {
|
|
||||||
if (lcr_config.log_path) {
|
|
||||||
config->log_path = util_strdup_s(lcr_config.log_path);
|
|
||||||
} else {
|
|
||||||
config->log_path = NULL;
|
|
||||||
}
|
|
||||||
config->log_rotate = lcr_config.log_rotate;
|
|
||||||
if (lcr_config.log_file_size) {
|
|
||||||
config->log_file_size = util_strdup_s(lcr_config.log_file_size);
|
|
||||||
} else {
|
|
||||||
config->log_file_size = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_lcr_free_console_config_op != NULL) {
|
|
||||||
g_lcr_free_console_config_op(&lcr_config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Get the containers info by liblcr
|
|
||||||
*/
|
|
||||||
static void get_containers_info(int num, const struct lcr_container_info *info_arr,
|
|
||||||
struct engine_container_summary_info *info)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
const struct lcr_container_info *in = NULL;
|
|
||||||
char *name = NULL;
|
|
||||||
|
|
||||||
for (i = 0, in = info_arr; i < num; i++, in++) {
|
|
||||||
name = in->name;
|
|
||||||
if (name == NULL) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
info[i].id = util_strdup_s(name);
|
|
||||||
info[i].has_pid = (-1 == in->init) ? false : true;
|
|
||||||
info[i].pid = (uint32_t)in->init;
|
|
||||||
info[i].status = lcrsta2sta(in->state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the state of container from 'lcr_container_state'
|
* Get the state of container from 'lcr_container_state'
|
||||||
*/
|
*/
|
||||||
static void copy_container_status(const struct lcr_container_state *lcs, struct engine_container_info *status)
|
static void copy_container_status(const struct lcr_container_state *lcs, struct engine_container_status_info *status)
|
||||||
{
|
{
|
||||||
const char *defvalue = "-";
|
(void)memset(status, 0, sizeof(struct engine_container_status_info));
|
||||||
const char *name = NULL;
|
|
||||||
|
|
||||||
(void)memset(status, 0, sizeof(struct engine_container_info));
|
|
||||||
|
|
||||||
name = lcs->name ? lcs->name : defvalue;
|
|
||||||
status->id = util_strdup_s(name);
|
|
||||||
|
|
||||||
status->has_pid = (-1 == lcs->init) ? false : true;
|
status->has_pid = (-1 == lcs->init) ? false : true;
|
||||||
status->pid = (uint32_t)lcs->init;
|
status->pid = (uint32_t)lcs->init;
|
||||||
|
|
||||||
status->status = lcrsta2sta(lcs->state);
|
status->status = lcrsta2sta(lcs->state);
|
||||||
|
|
||||||
status->pids_current = lcs->pids_current;
|
|
||||||
|
|
||||||
status->cpu_use_nanos = lcs->cpu_use_nanos;
|
|
||||||
|
|
||||||
status->blkio_read = lcs->io_service_bytes.read;
|
|
||||||
status->blkio_write = lcs->io_service_bytes.write;
|
|
||||||
|
|
||||||
status->mem_used = lcs->mem_used;
|
|
||||||
status->mem_limit = lcs->mem_limit;
|
|
||||||
status->kmem_used = lcs->kmem_used;
|
|
||||||
status->kmem_limit = lcs->kmem_limit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Alloc Memory for containerArray and container
|
|
||||||
*/
|
|
||||||
static int service_list_alloc(int num, struct engine_container_summary_info **cons)
|
|
||||||
{
|
|
||||||
if (num <= 0 || cons == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((size_t)num > SIZE_MAX / sizeof(struct engine_container_summary_info)) {
|
|
||||||
ERROR("Too many engine container summaries!");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
*cons = util_common_calloc_s((size_t)num * sizeof(struct engine_container_summary_info));
|
|
||||||
if ((*cons) == NULL) {
|
|
||||||
ERROR("Out of memory");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Free the container** containerArray
|
|
||||||
*/
|
|
||||||
static void free_all_containers_info(struct engine_container_summary_info *info, int num)
|
|
||||||
{
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
if (num <= 0 || info == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (i = 0; i < num; i++) {
|
|
||||||
free(info[i].id);
|
|
||||||
info[i].id = NULL;
|
|
||||||
free(info[i].command);
|
|
||||||
info[i].command = NULL;
|
|
||||||
free(info[i].image);
|
|
||||||
info[i].image = NULL;
|
|
||||||
free(info[i].finishat);
|
|
||||||
info[i].finishat = NULL;
|
|
||||||
free(info[i].startat);
|
|
||||||
info[i].startat = NULL;
|
|
||||||
}
|
|
||||||
free(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get all containers info */
|
|
||||||
static int get_all_containers_info(const char *enginepath, struct engine_container_summary_info **cons)
|
|
||||||
{
|
|
||||||
struct lcr_container_info *info_arr = NULL;
|
|
||||||
int num = 0;
|
|
||||||
|
|
||||||
if (cons == NULL) {
|
|
||||||
ERROR("Invalid argument");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_lcr_list_all_containers_op == NULL || g_lcr_containers_info_free_op == NULL) {
|
|
||||||
ERROR("Not supported op");
|
|
||||||
num = -1;
|
|
||||||
goto free_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
num = g_lcr_list_all_containers_op(enginepath, &info_arr);
|
|
||||||
if (num <= 0) {
|
|
||||||
num = 0; /* set to 0 if non were found */
|
|
||||||
goto free_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (service_list_alloc(num, cons)) {
|
|
||||||
g_lcr_containers_info_free_op(&info_arr, (size_t)num);
|
|
||||||
ERROR("service list alloc failed");
|
|
||||||
num = -1;
|
|
||||||
goto free_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
get_containers_info(num, info_arr, *cons);
|
|
||||||
g_lcr_containers_info_free_op(&info_arr, (size_t)num);
|
|
||||||
|
|
||||||
free_out:
|
|
||||||
return num;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get container status */
|
/* get container status */
|
||||||
static int get_container_status(const char *name, const char *enginepath, struct engine_container_info *status)
|
static int get_container_status(const char *name, const char *enginepath, struct engine_container_status_info *status)
|
||||||
{
|
{
|
||||||
struct lcr_container_state lcs = { 0 };
|
struct lcr_container_state lcs = { 0 };
|
||||||
|
|
||||||
@ -331,22 +145,43 @@ static int get_container_status(const char *name, const char *enginepath, struct
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free container status */
|
static void copy_container_resources_stats(const struct lcr_container_state *lcs,
|
||||||
static void free_container_status(struct engine_container_info *status)
|
struct engine_container_resources_stats_info *rs_stats)
|
||||||
{
|
{
|
||||||
if (status == NULL) {
|
(void)memset(rs_stats, 0, sizeof(struct engine_container_resources_stats_info));
|
||||||
return;
|
rs_stats->pids_current = lcs->pids_current;
|
||||||
}
|
|
||||||
|
|
||||||
free(status->id);
|
rs_stats->cpu_use_nanos = lcs->cpu_use_nanos;
|
||||||
status->id = NULL;
|
|
||||||
|
rs_stats->blkio_read = lcs->io_service_bytes.read;
|
||||||
|
rs_stats->blkio_write = lcs->io_service_bytes.write;
|
||||||
|
|
||||||
|
rs_stats->mem_used = lcs->mem_used;
|
||||||
|
rs_stats->mem_limit = lcs->mem_limit;
|
||||||
|
rs_stats->kmem_used = lcs->kmem_used;
|
||||||
|
rs_stats->kmem_limit = lcs->kmem_limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CHECK_ERROR(P) do { \
|
/* get container cgroup resources */
|
||||||
if (dlerror() != NULL) { \
|
static int lcr_get_container_resources_stats(const char *name, const char *enginepath,
|
||||||
goto badcleanup; \
|
struct engine_container_resources_stats_info *rs_stats)
|
||||||
} \
|
{
|
||||||
} while (0)
|
struct lcr_container_state lcs = { 0 };
|
||||||
|
|
||||||
|
if (g_lcr_state_op == NULL || g_lcr_container_state_free_op == NULL) {
|
||||||
|
ERROR("Not supported op");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_lcr_state_op(name, enginepath, &lcs)) {
|
||||||
|
DEBUG("Failed to state for container '%s'", name);
|
||||||
|
g_lcr_container_state_free_op(&lcs);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
copy_container_resources_stats(&lcs, rs_stats);
|
||||||
|
g_lcr_container_state_free_op(&lcs);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static bool load_lcr_exec_ops(void *lcr_handler, struct engine_operation *eop)
|
static bool load_lcr_exec_ops(void *lcr_handler, struct engine_operation *eop)
|
||||||
{
|
{
|
||||||
@ -386,6 +221,14 @@ static bool load_lcr_exec_ops(void *lcr_handler, struct engine_operation *eop)
|
|||||||
if (dlerror() != NULL) {
|
if (dlerror() != NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
eop->engine_resize_op = dlsym(lcr_handler, "lcr_resize");
|
||||||
|
if (dlerror() != NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
eop->engine_exec_resize_op = dlsym(lcr_handler, "lcr_exec_resize");
|
||||||
|
if (dlerror() != NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,22 +246,6 @@ static bool load_lcr_info_ops(void *lcr_handler, struct engine_operation *eop)
|
|||||||
if (dlerror() != NULL) {
|
if (dlerror() != NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
g_lcr_get_console_config_op = dlsym(lcr_handler, "lcr_get_console_config");
|
|
||||||
if (dlerror() != NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
g_lcr_free_console_config_op = dlsym(lcr_handler, "lcr_free_console_config");
|
|
||||||
if (dlerror() != NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
g_lcr_list_all_containers_op = dlsym(lcr_handler, "lcr_list_all_containers");
|
|
||||||
if (dlerror() != NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
g_lcr_containers_info_free_op = dlsym(lcr_handler, "lcr_containers_info_free");
|
|
||||||
if (dlerror() != NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
g_lcr_state_op = dlsym(lcr_handler, "lcr_state");
|
g_lcr_state_op = dlsym(lcr_handler, "lcr_state");
|
||||||
if (dlerror() != NULL) {
|
if (dlerror() != NULL) {
|
||||||
return false;
|
return false;
|
||||||
@ -464,16 +291,11 @@ struct engine_operation *lcr_engine_init()
|
|||||||
ERROR("Load lcr info operations failed");
|
ERROR("Load lcr info operations failed");
|
||||||
goto badcleanup;
|
goto badcleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
eop->engine_get_all_containers_info_op = get_all_containers_info;
|
|
||||||
eop->engine_free_all_containers_info_op = free_all_containers_info;
|
|
||||||
eop->engine_get_container_status_op = get_container_status;
|
eop->engine_get_container_status_op = get_container_status;
|
||||||
eop->engine_free_container_status_op = free_container_status;
|
eop->engine_get_container_resources_stats_op = lcr_get_container_resources_stats;
|
||||||
eop->engine_update_op = lcr_update_container;
|
eop->engine_update_op = lcr_update_container;
|
||||||
eop->engine_start_op = lcr_start_container;
|
eop->engine_start_op = lcr_start_container;
|
||||||
eop->engine_exec_op = lcr_exec_container;
|
eop->engine_exec_op = lcr_exec_container;
|
||||||
eop->engine_get_console_config_op = get_console_config;
|
|
||||||
eop->engine_free_console_config_op = free_console_config;
|
|
||||||
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
|||||||
@ -21,8 +21,6 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define PARAM_NUM 100
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
GB_OPTION_GRAPH_ROOT = 0,
|
GB_OPTION_GRAPH_ROOT = 0,
|
||||||
GB_OPTION_RUN_ROOT,
|
GB_OPTION_RUN_ROOT,
|
||||||
@ -37,25 +35,6 @@ enum {
|
|||||||
GB_OPTION_MAX, // should not be used
|
GB_OPTION_MAX, // should not be used
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static inline void add_array_elem(char **array, size_t total, size_t *pos, const char *elem)
|
|
||||||
{
|
|
||||||
if (*pos + 1 >= total - 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
array[*pos] = util_strdup_s(elem);
|
|
||||||
*pos += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void add_array_kv(char **array, size_t total, size_t *pos, const char *k, const char *v)
|
|
||||||
{
|
|
||||||
if (k == NULL || v == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
add_array_elem(array, total, pos, k);
|
|
||||||
add_array_elem(array, total, pos, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
int pack_global_options(const char * const *options, char *params[], size_t *count, bool ignore_storage_opt_size);
|
int pack_global_options(const char * const *options, char *params[], size_t *count, bool ignore_storage_opt_size);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@ -61,11 +61,15 @@ void isula_exit(void)
|
|||||||
|
|
||||||
static int start_isula_image_server(void)
|
static int start_isula_image_server(void)
|
||||||
{
|
{
|
||||||
struct server_monitor_conf sm_conf = {0};
|
#define MIN_OPT_TIMEOUT 15
|
||||||
|
struct server_monitor_conf sm_conf = { 0 };
|
||||||
struct timespec ts = { 0 };
|
struct timespec ts = { 0 };
|
||||||
sem_t wait_monitor_sem;
|
sem_t wait_monitor_sem;
|
||||||
|
unsigned int im_opt_timeout = conf_get_im_opt_timeout();
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
im_opt_timeout = im_opt_timeout >= MIN_OPT_TIMEOUT ? im_opt_timeout : MIN_OPT_TIMEOUT;
|
||||||
|
|
||||||
// check whether isula_kit is running by systemd
|
// check whether isula_kit is running by systemd
|
||||||
if (util_file_exists(ISULA_IMAGE_SERVER_DEFAULT_SOCK)) {
|
if (util_file_exists(ISULA_IMAGE_SERVER_DEFAULT_SOCK)) {
|
||||||
if (!conf_update_im_server_sock_addr(ISULA_IMAGE_SERVER_DEFAULT_SOCK)) {
|
if (!conf_update_im_server_sock_addr(ISULA_IMAGE_SERVER_DEFAULT_SOCK)) {
|
||||||
@ -93,7 +97,7 @@ static int start_isula_image_server(void)
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
ts.tv_sec += 15; // set deadline 15s
|
ts.tv_sec += (time_t)im_opt_timeout; // set deadline
|
||||||
|
|
||||||
ret = sem_timedwait(&wait_monitor_sem, &ts);
|
ret = sem_timedwait(&wait_monitor_sem, &ts);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
|
|||||||
@ -245,10 +245,42 @@ static void *heartbeat_for_isulad_kit(void *arg)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned long get_timeout_secs(bool retry)
|
||||||
|
{
|
||||||
|
unsigned long result = RETRY_COUNT_MAX;
|
||||||
|
|
||||||
|
if (retry) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = conf_get_im_opt_timeout();
|
||||||
|
if (result < RETRY_COUNT_MAX) {
|
||||||
|
result = RETRY_COUNT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_timeout(unsigned long max_second, unsigned long retry_cnt)
|
||||||
|
{
|
||||||
|
unsigned long total = retry_cnt;
|
||||||
|
|
||||||
|
if (total >= ULONG_MAX / (total + 1)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
total = total * (total + 1) / 2;
|
||||||
|
// time unit is second, retry time is 0.1s
|
||||||
|
if (total >= max_second * 10) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static int isula_image_server_load_first_check(const struct server_monitor_conf *conf, bool retry)
|
static int isula_image_server_load_first_check(const struct server_monitor_conf *conf, bool retry)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
unsigned long retry_cnt = 1;
|
unsigned long retry_cnt = 0;
|
||||||
|
unsigned long opt_timeout = get_timeout_secs(retry);
|
||||||
|
|
||||||
/* parent: check server is running */
|
/* parent: check server is running */
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -257,13 +289,13 @@ static int isula_image_server_load_first_check(const struct server_monitor_conf
|
|||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
retry_cnt++;
|
if (is_timeout(opt_timeout, retry_cnt)) {
|
||||||
if (retry_cnt > RETRY_COUNT_MAX) {
|
|
||||||
// don't post sem to main thread
|
// don't post sem to main thread
|
||||||
ERROR("First load image server failed");
|
ERROR("First load image server failed");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
retry_cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 1. If health check success, send a mutex to main thread and make it run again;
|
/* 1. If health check success, send a mutex to main thread and make it run again;
|
||||||
|
|||||||
@ -5,6 +5,9 @@
|
|||||||
"container_id": {
|
"container_id": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"suffix": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"tty": {
|
"tty": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -648,6 +648,9 @@ void lcrc_exec_request_free(struct lcrc_exec_request *request)
|
|||||||
free(request->name);
|
free(request->name);
|
||||||
request->name = NULL;
|
request->name = NULL;
|
||||||
|
|
||||||
|
free(request->suffix);
|
||||||
|
request->suffix = NULL;
|
||||||
|
|
||||||
free(request->stdout);
|
free(request->stdout);
|
||||||
request->stdout = NULL;
|
request->stdout = NULL;
|
||||||
|
|
||||||
@ -778,38 +781,6 @@ void lcrc_resume_response_free(struct lcrc_resume_response *response)
|
|||||||
free(response);
|
free(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* lcrc container conf request free */
|
|
||||||
void lcrc_container_conf_request_free(struct lcrc_container_conf_request *req)
|
|
||||||
{
|
|
||||||
if (req == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(req->name);
|
|
||||||
req->name = NULL;
|
|
||||||
|
|
||||||
free(req);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* lcrc container conf response free */
|
|
||||||
void lcrc_container_conf_response_free(struct lcrc_container_conf_response *resp)
|
|
||||||
{
|
|
||||||
if (resp == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(resp->errmsg);
|
|
||||||
resp->errmsg = NULL;
|
|
||||||
|
|
||||||
free(resp->container_logpath);
|
|
||||||
resp->container_logpath = NULL;
|
|
||||||
|
|
||||||
free(resp->container_logsize);
|
|
||||||
resp->container_logsize = NULL;
|
|
||||||
|
|
||||||
free(resp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* lcrc kill request free */
|
/* lcrc kill request free */
|
||||||
void lcrc_kill_request_free(struct lcrc_kill_request *request)
|
void lcrc_kill_request_free(struct lcrc_kill_request *request)
|
||||||
{
|
{
|
||||||
@ -882,12 +853,20 @@ void lcrc_update_response_free(struct lcrc_update_response *response)
|
|||||||
/* lcrc stats request free */
|
/* lcrc stats request free */
|
||||||
void lcrc_stats_request_free(struct lcrc_stats_request *request)
|
void lcrc_stats_request_free(struct lcrc_stats_request *request)
|
||||||
{
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
if (request == NULL) {
|
if (request == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(request->runtime);
|
for (i = 0; i < request->containers_len; i++) {
|
||||||
request->runtime = NULL;
|
free(request->containers[i]);
|
||||||
|
request->containers[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(request->containers);
|
||||||
|
request->containers = NULL;
|
||||||
|
|
||||||
free(request);
|
free(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -902,8 +881,8 @@ void lcrc_stats_response_free(struct lcrc_stats_response *response)
|
|||||||
response->errmsg = NULL;
|
response->errmsg = NULL;
|
||||||
|
|
||||||
if (response->container_stats != NULL && response->container_num) {
|
if (response->container_stats != NULL && response->container_num) {
|
||||||
int i;
|
size_t i;
|
||||||
for (i = 0; i < (int)response->container_num; i++) {
|
for (i = 0; i < response->container_num; i++) {
|
||||||
free(response->container_stats[i].id);
|
free(response->container_stats[i].id);
|
||||||
response->container_stats[i].id = NULL;
|
response->container_stats[i].id = NULL;
|
||||||
}
|
}
|
||||||
@ -1348,6 +1327,36 @@ void lcrc_rename_response_free(struct lcrc_rename_response *response)
|
|||||||
free(response);
|
free(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* lcrc resize request free */
|
||||||
|
void lcrc_resize_request_free(struct lcrc_resize_request *request)
|
||||||
|
{
|
||||||
|
if (request == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(request->id);
|
||||||
|
request->id = NULL;
|
||||||
|
|
||||||
|
free(request->suffix);
|
||||||
|
request->suffix = NULL;
|
||||||
|
|
||||||
|
free(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* lcrc resize response free */
|
||||||
|
void lcrc_resize_response_free(struct lcrc_resize_response *response)
|
||||||
|
{
|
||||||
|
if (response == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(response->errmsg);
|
||||||
|
response->errmsg = NULL;
|
||||||
|
|
||||||
|
free(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* lcrc logs request free */
|
/* lcrc logs request free */
|
||||||
void lcrc_logs_request_free(struct lcrc_logs_request *request)
|
void lcrc_logs_request_free(struct lcrc_logs_request *request)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -296,9 +296,6 @@ struct lcrc_resume_response {
|
|||||||
|
|
||||||
struct lcrc_container_info {
|
struct lcrc_container_info {
|
||||||
char *id;
|
char *id;
|
||||||
bool has_pid;
|
|
||||||
uint32_t pid;
|
|
||||||
Container_Status status;
|
|
||||||
uint64_t pids_current;
|
uint64_t pids_current;
|
||||||
// CPU usage
|
// CPU usage
|
||||||
uint64_t cpu_use_nanos;
|
uint64_t cpu_use_nanos;
|
||||||
@ -359,7 +356,6 @@ struct lcrc_list_response {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct lcrc_stats_request {
|
struct lcrc_stats_request {
|
||||||
char *runtime;
|
|
||||||
char **containers;
|
char **containers;
|
||||||
size_t containers_len;
|
size_t containers_len;
|
||||||
bool all;
|
bool all;
|
||||||
@ -449,6 +445,7 @@ struct lcrc_wait_response {
|
|||||||
|
|
||||||
struct lcrc_exec_request {
|
struct lcrc_exec_request {
|
||||||
char *name;
|
char *name;
|
||||||
|
char *suffix;
|
||||||
bool tty;
|
bool tty;
|
||||||
bool open_stdin;
|
bool open_stdin;
|
||||||
bool attach_stdin;
|
bool attach_stdin;
|
||||||
@ -542,19 +539,6 @@ struct lcrc_info_response {
|
|||||||
char *errmsg;
|
char *errmsg;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lcrc_container_conf_request {
|
|
||||||
char *name;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct lcrc_container_conf_response {
|
|
||||||
uint32_t cc;
|
|
||||||
uint32_t server_errono;
|
|
||||||
char *container_logpath;
|
|
||||||
uint32_t container_logrotate;
|
|
||||||
char *container_logsize;
|
|
||||||
char *errmsg;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct lcrc_update_config {
|
typedef struct lcrc_update_config {
|
||||||
char *restart_policy;
|
char *restart_policy;
|
||||||
container_cgroup_resources_t *cr;
|
container_cgroup_resources_t *cr;
|
||||||
@ -688,6 +672,19 @@ struct lcrc_rename_response {
|
|||||||
char *errmsg;
|
char *errmsg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct lcrc_resize_request {
|
||||||
|
char *id;
|
||||||
|
char *suffix;
|
||||||
|
uint32_t height;
|
||||||
|
uint32_t width;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct lcrc_resize_response {
|
||||||
|
uint32_t cc;
|
||||||
|
uint32_t server_errono;
|
||||||
|
char *errmsg;
|
||||||
|
};
|
||||||
|
|
||||||
Container_Status lcrcstastr2sta(const char *state);
|
Container_Status lcrcstastr2sta(const char *state);
|
||||||
|
|
||||||
struct lcrc_filters *lcrc_filters_parse_args(const char **array, size_t len);
|
struct lcrc_filters *lcrc_filters_parse_args(const char **array, size_t len);
|
||||||
@ -758,10 +755,6 @@ void lcrc_resume_request_free(struct lcrc_resume_request *request);
|
|||||||
|
|
||||||
void lcrc_resume_response_free(struct lcrc_resume_response *response);
|
void lcrc_resume_response_free(struct lcrc_resume_response *response);
|
||||||
|
|
||||||
void lcrc_container_conf_request_free(struct lcrc_container_conf_request *req);
|
|
||||||
|
|
||||||
void lcrc_container_conf_response_free(struct lcrc_container_conf_response *resp);
|
|
||||||
|
|
||||||
void lcrc_kill_request_free(struct lcrc_kill_request *request);
|
void lcrc_kill_request_free(struct lcrc_kill_request *request);
|
||||||
|
|
||||||
void lcrc_kill_response_free(struct lcrc_kill_response *response);
|
void lcrc_kill_response_free(struct lcrc_kill_response *response);
|
||||||
@ -833,6 +826,10 @@ void lcrc_rename_request_free(struct lcrc_rename_request *request);
|
|||||||
|
|
||||||
void lcrc_rename_response_free(struct lcrc_rename_response *response);
|
void lcrc_rename_response_free(struct lcrc_rename_response *response);
|
||||||
|
|
||||||
|
void lcrc_resize_request_free(struct lcrc_resize_request *request);
|
||||||
|
|
||||||
|
void lcrc_resize_response_free(struct lcrc_resize_response *response);
|
||||||
|
|
||||||
void lcrc_logs_request_free(struct lcrc_logs_request *request);
|
void lcrc_logs_request_free(struct lcrc_logs_request *request);
|
||||||
void lcrc_logs_response_free(struct lcrc_logs_response *response);
|
void lcrc_logs_response_free(struct lcrc_logs_response *response);
|
||||||
|
|
||||||
|
|||||||
@ -26,36 +26,6 @@
|
|||||||
// record the errno
|
// record the errno
|
||||||
__thread char *g_lcrd_errmsg = NULL;
|
__thread char *g_lcrd_errmsg = NULL;
|
||||||
|
|
||||||
/* lcrd container conf request free */
|
|
||||||
void lcrd_container_conf_request_free(struct lcrd_container_conf_request *request)
|
|
||||||
{
|
|
||||||
if (request == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
free(request->name);
|
|
||||||
request->name = NULL;
|
|
||||||
|
|
||||||
free(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* lcrd container conf response free */
|
|
||||||
void lcrd_container_conf_response_free(struct lcrd_container_conf_response *response)
|
|
||||||
{
|
|
||||||
if (response == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
free(response->errmsg);
|
|
||||||
response->errmsg = NULL;
|
|
||||||
|
|
||||||
free(response->container_logpath);
|
|
||||||
response->container_logpath = NULL;
|
|
||||||
|
|
||||||
free(response->container_logsize);
|
|
||||||
response->container_logsize = NULL;
|
|
||||||
|
|
||||||
free(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* lcrd events request free */
|
/* lcrd events request free */
|
||||||
void lcrd_events_request_free(struct lcrd_events_request *request)
|
void lcrd_events_request_free(struct lcrd_events_request *request)
|
||||||
{
|
{
|
||||||
@ -193,6 +163,38 @@ void lcrd_container_rename_response_free(struct lcrd_container_rename_response *
|
|||||||
free(response);
|
free(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* lcrd container rename request free */
|
||||||
|
void lcrd_container_resize_request_free(struct lcrd_container_resize_request *request)
|
||||||
|
{
|
||||||
|
if (request == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(request->id);
|
||||||
|
request->id = NULL;
|
||||||
|
|
||||||
|
free(request->suffix);
|
||||||
|
request->suffix = NULL;
|
||||||
|
|
||||||
|
free(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* lcrd container rename response free */
|
||||||
|
void lcrd_container_resize_response_free(struct lcrd_container_resize_response *response)
|
||||||
|
{
|
||||||
|
if (response == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(response->id);
|
||||||
|
response->id = NULL;
|
||||||
|
free(response->errmsg);
|
||||||
|
response->errmsg = NULL;
|
||||||
|
|
||||||
|
free(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void lcrd_logs_request_free(struct lcrd_logs_request *request)
|
void lcrd_logs_request_free(struct lcrd_logs_request *request)
|
||||||
{
|
{
|
||||||
if (request == NULL) {
|
if (request == NULL) {
|
||||||
|
|||||||
@ -243,19 +243,6 @@ struct lcrd_health_check_response {
|
|||||||
char *errmsg;
|
char *errmsg;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct lcrd_container_conf_request {
|
|
||||||
char *name;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct lcrd_container_conf_response {
|
|
||||||
uint32_t cc;
|
|
||||||
uint32_t server_errono;
|
|
||||||
char *container_logpath;
|
|
||||||
uint32_t container_logrotate;
|
|
||||||
char *container_logsize;
|
|
||||||
char *errmsg;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct lcrd_container_rename_request {
|
struct lcrd_container_rename_request {
|
||||||
char *old_name;
|
char *old_name;
|
||||||
char *new_name;
|
char *new_name;
|
||||||
@ -267,6 +254,19 @@ struct lcrd_container_rename_response {
|
|||||||
char *errmsg;
|
char *errmsg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct lcrd_container_resize_request {
|
||||||
|
char *id;
|
||||||
|
char *suffix;
|
||||||
|
uint32_t height;
|
||||||
|
uint32_t width;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct lcrd_container_resize_response {
|
||||||
|
char *id;
|
||||||
|
uint32_t cc;
|
||||||
|
char *errmsg;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
struct lcrd_image_info {
|
struct lcrd_image_info {
|
||||||
char *imageref;
|
char *imageref;
|
||||||
@ -295,10 +295,6 @@ struct container_log_config {
|
|||||||
};
|
};
|
||||||
void container_log_config_free(struct container_log_config *conf);
|
void container_log_config_free(struct container_log_config *conf);
|
||||||
|
|
||||||
void lcrd_container_conf_request_free(struct lcrd_container_conf_request *request);
|
|
||||||
|
|
||||||
void lcrd_container_conf_response_free(struct lcrd_container_conf_response *response);
|
|
||||||
|
|
||||||
void lcrd_events_request_free(struct lcrd_events_request *request);
|
void lcrd_events_request_free(struct lcrd_events_request *request);
|
||||||
|
|
||||||
void lcrd_copy_from_container_request_free(struct lcrd_copy_from_container_request *request);
|
void lcrd_copy_from_container_request_free(struct lcrd_copy_from_container_request *request);
|
||||||
@ -315,6 +311,10 @@ void lcrd_container_rename_request_free(struct lcrd_container_rename_request *re
|
|||||||
|
|
||||||
void lcrd_container_rename_response_free(struct lcrd_container_rename_response *response);
|
void lcrd_container_rename_response_free(struct lcrd_container_rename_response *response);
|
||||||
|
|
||||||
|
void lcrd_container_resize_request_free(struct lcrd_container_resize_request *request);
|
||||||
|
|
||||||
|
void lcrd_container_resize_response_free(struct lcrd_container_resize_response *response);
|
||||||
|
|
||||||
void lcrd_logs_request_free(struct lcrd_logs_request *request);
|
void lcrd_logs_request_free(struct lcrd_logs_request *request);
|
||||||
void lcrd_logs_response_free(struct lcrd_logs_response *response);
|
void lcrd_logs_response_free(struct lcrd_logs_response *response);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@ -62,12 +62,14 @@ int rt_lcr_create(const char *name, const char *runtime, const rt_create_params_
|
|||||||
lcrd_set_error_message("Create container error: %s",
|
lcrd_set_error_message("Create container error: %s",
|
||||||
(tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
|
(tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
|
||||||
: DEF_ERR_RUNTIME_STR);
|
: DEF_ERR_RUNTIME_STR);
|
||||||
engine_ops->engine_clear_errmsg_op();
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
if (engine_ops != NULL) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
}
|
||||||
free(runtime_root);
|
free(runtime_root);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -138,7 +140,6 @@ int rt_lcr_start(const char *name, const char *runtime, const rt_start_params_t
|
|||||||
: DEF_ERR_RUNTIME_STR);
|
: DEF_ERR_RUNTIME_STR);
|
||||||
ERROR("Start container error: %s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
|
ERROR("Start container error: %s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
|
||||||
: DEF_ERR_RUNTIME_STR);
|
: DEF_ERR_RUNTIME_STR);
|
||||||
engine_ops->engine_clear_errmsg_op();
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -149,6 +150,9 @@ int rt_lcr_start(const char *name, const char *runtime, const rt_start_params_t
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
|
if (engine_ops != NULL) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,38 +251,8 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rt_lcr_get_console_config(const char *name, const char *runtime, const rt_get_console_conf_params_t *params)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
struct engine_operation *engine_ops = NULL;
|
|
||||||
|
|
||||||
engine_ops = engines_get_handler(runtime);
|
|
||||||
if (engine_ops == NULL || (engine_ops->engine_get_console_config_op) == NULL) {
|
|
||||||
ERROR("Failed to get engine get_console_config operation");
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!engine_ops->engine_get_console_config_op(name, params->rootpath, params->config)) {
|
|
||||||
ERROR("Failed to get console config");
|
|
||||||
const char *tmpmsg = NULL;
|
|
||||||
tmpmsg = engine_ops->engine_get_errmsg_op();
|
|
||||||
lcrd_set_error_message("Get console config error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
|
|
||||||
tmpmsg : DEF_ERR_RUNTIME_STR);
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
out:
|
|
||||||
if (engine_ops != NULL) {
|
|
||||||
engine_ops->engine_clear_errmsg_op();
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_t *params,
|
int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_t *params,
|
||||||
struct engine_container_info *status)
|
struct engine_container_status_info *status)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int nret = 0;
|
int nret = 0;
|
||||||
@ -299,9 +273,39 @@ int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
if (engine_ops != NULL) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int rt_lcr_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params,
|
||||||
|
struct engine_container_resources_stats_info *rs_stats)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int nret = 0;
|
||||||
|
struct engine_operation *engine_ops = NULL;
|
||||||
|
|
||||||
|
engine_ops = engines_get_handler(runtime);
|
||||||
|
if (engine_ops == NULL || engine_ops->engine_get_container_resources_stats_op == NULL) {
|
||||||
|
ERROR("Failed to get engine stats operations");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
nret = engine_ops->engine_get_container_resources_stats_op(name, params->rootpath, rs_stats);
|
||||||
|
if (nret != 0) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (engine_ops != NULL) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *params, int *exit_code)
|
int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *params, int *exit_code)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -326,6 +330,7 @@ int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *par
|
|||||||
request.console_fifos = params->console_fifos;
|
request.console_fifos = params->console_fifos;
|
||||||
request.timeout = params->timeout;
|
request.timeout = params->timeout;
|
||||||
request.user = params->user;
|
request.user = params->user;
|
||||||
|
request.suffix = params->suffix;
|
||||||
|
|
||||||
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;
|
||||||
@ -339,6 +344,9 @@ int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *par
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
if (engine_ops != NULL) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,11 +368,13 @@ int rt_lcr_pause(const char *name, const char *runtime, const rt_pause_params_t
|
|||||||
tmpmsg = engine_ops->engine_get_errmsg_op();
|
tmpmsg = engine_ops->engine_get_errmsg_op();
|
||||||
lcrd_set_error_message("Pause container error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
|
lcrd_set_error_message("Pause container error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
|
||||||
tmpmsg : DEF_ERR_RUNTIME_STR);
|
tmpmsg : DEF_ERR_RUNTIME_STR);
|
||||||
engine_ops->engine_clear_errmsg_op();
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
|
if (engine_ops != NULL) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,11 +397,177 @@ int rt_lcr_resume(const char *name, const char *runtime, const rt_resume_params_
|
|||||||
lcrd_set_error_message("Resume container error;%s",
|
lcrd_set_error_message("Resume container error;%s",
|
||||||
(tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
|
(tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
|
||||||
: DEF_ERR_RUNTIME_STR);
|
: DEF_ERR_RUNTIME_STR);
|
||||||
|
|
||||||
engine_ops->engine_clear_errmsg_op();
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
|
if (engine_ops != NULL) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rt_lcr_attach(const char *name, const char *runtime, const rt_attach_params_t *params)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
struct engine_operation *engine_ops = NULL;
|
||||||
|
|
||||||
|
engine_ops = engines_get_handler(runtime);
|
||||||
|
if (engine_ops == NULL || engine_ops->engine_console_op == NULL) {
|
||||||
|
DEBUG("Failed to get engine attach operations");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!engine_ops->engine_console_op(name, params->rootpath, (char *)params->stdin, (char *)params->stdout,
|
||||||
|
(char *)params->stderr)) {
|
||||||
|
ERROR("attach failed");
|
||||||
|
const char *tmpmsg = NULL;
|
||||||
|
tmpmsg = engine_ops->engine_get_errmsg_op();
|
||||||
|
lcrd_set_error_message("Attach container error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
|
||||||
|
tmpmsg : DEF_ERR_RUNTIME_STR);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
out:
|
||||||
|
if (engine_ops != NULL) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void to_engine_resources(const host_config *hostconfig, struct engine_cgroup_resources *cr)
|
||||||
|
{
|
||||||
|
if (hostconfig == NULL || cr == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cr->blkio_weight = hostconfig->blkio_weight;
|
||||||
|
cr->cpu_shares = (uint64_t)hostconfig->cpu_shares;
|
||||||
|
cr->cpu_period = (uint64_t)hostconfig->cpu_period;
|
||||||
|
cr->cpu_quota = (uint64_t)hostconfig->cpu_quota;
|
||||||
|
cr->cpuset_cpus = hostconfig->cpuset_cpus;
|
||||||
|
cr->cpuset_mems = hostconfig->cpuset_mems;
|
||||||
|
cr->memory_limit = (uint64_t)hostconfig->memory;
|
||||||
|
cr->memory_swap = (uint64_t)hostconfig->memory_swap;
|
||||||
|
cr->memory_reservation = (uint64_t)hostconfig->memory_reservation;
|
||||||
|
cr->kernel_memory_limit = (uint64_t)hostconfig->kernel_memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rt_lcr_update(const char *id, const char *runtime, const rt_update_params_t *params)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
struct engine_operation *engine_ops = NULL;
|
||||||
|
struct engine_cgroup_resources cr = { 0 };
|
||||||
|
|
||||||
|
engine_ops = engines_get_handler(runtime);
|
||||||
|
if (engine_ops == NULL || engine_ops->engine_update_op == NULL) {
|
||||||
|
DEBUG("Failed to get engine update operations");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
to_engine_resources(params->hostconfig, &cr);
|
||||||
|
|
||||||
|
if (!engine_ops->engine_update_op(id, params->rootpath, &cr)) {
|
||||||
|
DEBUG("Update container %s failed", id);
|
||||||
|
const char *tmpmsg = NULL;
|
||||||
|
tmpmsg = engine_ops->engine_get_errmsg_op();
|
||||||
|
lcrd_set_error_message("Cannot update container %s: %s", id, (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
|
||||||
|
tmpmsg : DEF_ERR_RUNTIME_STR);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
out:
|
||||||
|
if (engine_ops != NULL) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rt_lcr_listpids(const char *name, const char *runtime, const rt_listpids_params_t *params, rt_listpids_out_t *out)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
struct engine_operation *engine_ops = NULL;
|
||||||
|
|
||||||
|
engine_ops = engines_get_handler(runtime);
|
||||||
|
if (engine_ops == NULL || engine_ops->engine_get_container_pids_op == NULL) {
|
||||||
|
DEBUG("Failed to get engine top operations");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!engine_ops->engine_get_container_pids_op(name, params->rootpath, &(out->pids), &(out->pids_len))) {
|
||||||
|
DEBUG("Top container %s failed", name);
|
||||||
|
const char *tmpmsg = NULL;
|
||||||
|
tmpmsg = engine_ops->engine_get_errmsg_op();
|
||||||
|
lcrd_set_error_message("Runtime top container error: %s",
|
||||||
|
(tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg : DEF_ERR_RUNTIME_STR);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
out:
|
||||||
|
if (engine_ops != NULL) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rt_lcr_resize(const char *id, const char *runtime, const rt_resize_params_t *params)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
struct engine_operation *engine_ops = NULL;
|
||||||
|
|
||||||
|
engine_ops = engines_get_handler(runtime);
|
||||||
|
if (engine_ops == NULL || engine_ops->engine_resize_op == NULL) {
|
||||||
|
DEBUG("Failed to get engine resume operations");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!engine_ops->engine_resize_op(id, params->rootpath, params->height, params->width)) {
|
||||||
|
DEBUG("resize container %s failed", id);
|
||||||
|
const char *tmpmsg = NULL;
|
||||||
|
tmpmsg = engine_ops->engine_get_errmsg_op();
|
||||||
|
lcrd_set_error_message("Resize container error;%s",
|
||||||
|
(tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
|
||||||
|
: DEF_ERR_RUNTIME_STR);
|
||||||
|
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
out:
|
||||||
|
if (engine_ops != NULL) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int rt_lcr_exec_resize(const char *id, const char *runtime, const rt_exec_resize_params_t *params)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
struct engine_operation *engine_ops = NULL;
|
||||||
|
|
||||||
|
engine_ops = engines_get_handler(runtime);
|
||||||
|
if (engine_ops == NULL || engine_ops->engine_resize_op == NULL) {
|
||||||
|
DEBUG("Failed to get engine resume operations");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!engine_ops->engine_exec_resize_op(id, params->rootpath, params->suffix, params->height, params->width)) {
|
||||||
|
DEBUG("exec resize container %s failed", id);
|
||||||
|
const char *tmpmsg = NULL;
|
||||||
|
tmpmsg = engine_ops->engine_get_errmsg_op();
|
||||||
|
lcrd_set_error_message("Resize container error;%s",
|
||||||
|
(tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg
|
||||||
|
: DEF_ERR_RUNTIME_STR);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
out:
|
||||||
|
if (engine_ops != NULL) {
|
||||||
|
engine_ops->engine_clear_errmsg_op();
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,13 +28,21 @@ int rt_lcr_start(const char *name, const char *runtime, const rt_start_params_t
|
|||||||
int rt_lcr_restart(const char *name, const char *runtime, const rt_restart_params_t *params);
|
int rt_lcr_restart(const char *name, const char *runtime, const rt_restart_params_t *params);
|
||||||
int rt_lcr_clean_resource(const char *name, const char *runtime, const rt_clean_params_t *params);
|
int rt_lcr_clean_resource(const char *name, const char *runtime, const rt_clean_params_t *params);
|
||||||
int rt_lcr_rm(const char *name, const char *runtime, const rt_rm_params_t *params);
|
int rt_lcr_rm(const char *name, const char *runtime, const rt_rm_params_t *params);
|
||||||
int rt_lcr_get_console_config(const char *name, const char *runtime, const rt_get_console_conf_params_t *params);
|
|
||||||
int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_t *params,
|
int rt_lcr_status(const char *name, const char *runtime, const rt_status_params_t *params,
|
||||||
struct engine_container_info *status);
|
struct engine_container_status_info *status);
|
||||||
int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *params, int *exit_code);
|
int rt_lcr_exec(const char *id, const char *runtime, const rt_exec_params_t *params, int *exit_code);
|
||||||
int rt_lcr_pause(const char *name, const char *runtime, const rt_pause_params_t *params);
|
int rt_lcr_pause(const char *name, const char *runtime, const rt_pause_params_t *params);
|
||||||
int rt_lcr_resume(const char *name, const char *runtime, const rt_resume_params_t *params);
|
int rt_lcr_resume(const char *name, const char *runtime, const rt_resume_params_t *params);
|
||||||
|
|
||||||
|
int rt_lcr_attach(const char *name, const char *runtime, const rt_attach_params_t *params);
|
||||||
|
|
||||||
|
int rt_lcr_update(const char *id, const char *runtime, const rt_update_params_t *params);
|
||||||
|
|
||||||
|
int rt_lcr_listpids(const char *name, const char *runtime, const rt_listpids_params_t *params, rt_listpids_out_t *out);
|
||||||
|
int rt_lcr_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params,
|
||||||
|
struct engine_container_resources_stats_info *rs_stats);
|
||||||
|
int rt_lcr_resize(const char *id, const char *runtime, const rt_resize_params_t *params);
|
||||||
|
int rt_lcr_exec_resize(const char *id, const char *runtime, const rt_exec_resize_params_t *params);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -33,11 +33,16 @@ static const struct rt_ops g_lcr_rt_ops = {
|
|||||||
.rt_restart = rt_lcr_restart,
|
.rt_restart = rt_lcr_restart,
|
||||||
.rt_clean_resource = rt_lcr_clean_resource,
|
.rt_clean_resource = rt_lcr_clean_resource,
|
||||||
.rt_rm = rt_lcr_rm,
|
.rt_rm = rt_lcr_rm,
|
||||||
.rt_get_console_config = rt_lcr_get_console_config,
|
|
||||||
.rt_status = rt_lcr_status,
|
.rt_status = rt_lcr_status,
|
||||||
.rt_exec = rt_lcr_exec,
|
.rt_exec = rt_lcr_exec,
|
||||||
.rt_pause = rt_lcr_pause,
|
.rt_pause = rt_lcr_pause,
|
||||||
.rt_resume = rt_lcr_resume,
|
.rt_resume = rt_lcr_resume,
|
||||||
|
.rt_attach = rt_lcr_attach,
|
||||||
|
.rt_update = rt_lcr_update,
|
||||||
|
.rt_listpids = rt_lcr_listpids,
|
||||||
|
.rt_resources_stats = rt_lcr_resources_stats,
|
||||||
|
.rt_resize = rt_lcr_resize,
|
||||||
|
.rt_exec_resize = rt_lcr_exec_resize,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct rt_ops *g_rt_ops[] = {
|
static const struct rt_ops *g_rt_ops[] = {
|
||||||
@ -184,38 +189,14 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int runtime_get_console_config(const char *name, const char *runtime, const rt_get_console_conf_params_t *params)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
const struct rt_ops *ops = NULL;
|
|
||||||
|
|
||||||
if (name == NULL || runtime == NULL) {
|
|
||||||
ERROR("Invalide arguments for runtime get console config");
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ops = rt_ops_query(runtime);
|
|
||||||
if (ops == NULL) {
|
|
||||||
ERROR("Failed to get runtime ops");
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = ops->rt_get_console_config(name, runtime, params);
|
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int runtime_status(const char *name, const char *runtime, const rt_status_params_t *params,
|
int runtime_status(const char *name, const char *runtime, const rt_status_params_t *params,
|
||||||
struct engine_container_info *status)
|
struct engine_container_status_info *status)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
const struct rt_ops *ops = NULL;
|
const struct rt_ops *ops = NULL;
|
||||||
|
|
||||||
if (name == NULL || runtime == NULL || status == NULL) {
|
if (name == NULL || runtime == NULL || status == NULL) {
|
||||||
ERROR("Invalide arguments for runtime start");
|
ERROR("Invalide arguments for runtime status");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -233,6 +214,31 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int runtime_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params,
|
||||||
|
struct engine_container_resources_stats_info *rs_stats)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
const struct rt_ops *ops = NULL;
|
||||||
|
|
||||||
|
if (name == NULL || runtime == NULL || rs_stats == NULL) {
|
||||||
|
ERROR("Invalide arguments for runtime stats");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ops = rt_ops_query(runtime);
|
||||||
|
if (ops == NULL) {
|
||||||
|
ERROR("Failed to get runtime ops");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ops->rt_resources_stats(name, runtime, params, rs_stats);
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int runtime_exec(const char *name, const char *runtime, const rt_exec_params_t *params,
|
int runtime_exec(const char *name, const char *runtime, const rt_exec_params_t *params,
|
||||||
int *exit_code)
|
int *exit_code)
|
||||||
{
|
{
|
||||||
@ -305,3 +311,134 @@ int runtime_resume(const char *name, const char *runtime, const rt_resume_params
|
|||||||
out:
|
out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int runtime_attach(const char *name, const char *runtime, const rt_attach_params_t *params)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
const struct rt_ops *ops = NULL;
|
||||||
|
|
||||||
|
if (name == NULL || runtime == NULL || params == NULL) {
|
||||||
|
ERROR("Invalide arguments for runtime attach");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ops = rt_ops_query(runtime);
|
||||||
|
if (ops == NULL) {
|
||||||
|
ERROR("Failed to get runtime ops");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ops->rt_attach(name, runtime, params);
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int runtime_update(const char *name, const char *runtime, const rt_update_params_t *params)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
const struct rt_ops *ops = NULL;
|
||||||
|
|
||||||
|
if (name == NULL || runtime == NULL || params == NULL) {
|
||||||
|
ERROR("Invalide arguments for runtime update");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ops = rt_ops_query(runtime);
|
||||||
|
if (ops == NULL) {
|
||||||
|
ERROR("Failed to get runtime ops");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ops->rt_update(name, runtime, params);
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void free_rt_listpids_out_t(rt_listpids_out_t *out)
|
||||||
|
{
|
||||||
|
if (out == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(out->pids);
|
||||||
|
out->pids = NULL;
|
||||||
|
free(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
int runtime_listpids(const char *name, const char *runtime, const rt_listpids_params_t *params, rt_listpids_out_t *out)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
const struct rt_ops *ops = NULL;
|
||||||
|
|
||||||
|
if (name == NULL || runtime == NULL || params == NULL || out == NULL) {
|
||||||
|
ERROR("Invalide arguments for runtime listpids");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ops = rt_ops_query(runtime);
|
||||||
|
if (ops == NULL) {
|
||||||
|
ERROR("Failed to get runtime ops");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ops->rt_listpids(name, runtime, params, out);
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int runtime_resize(const char *name, const char *runtime, const rt_resize_params_t *params)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
const struct rt_ops *ops = NULL;
|
||||||
|
|
||||||
|
if (name == NULL || runtime == NULL || params == NULL) {
|
||||||
|
ERROR("Invalide arguments for runtime resize");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ops = rt_ops_query(runtime);
|
||||||
|
if (ops == NULL) {
|
||||||
|
ERROR("Failed to get runtime ops");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ops->rt_resize(name, runtime, params);
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int runtime_exec_resize(const char *name, const char *runtime, const rt_exec_resize_params_t *params)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
const struct rt_ops *ops = NULL;
|
||||||
|
|
||||||
|
if (name == NULL || runtime == NULL || params == NULL) {
|
||||||
|
ERROR("Invalide arguments for runtime exec resize");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ops = rt_ops_query(runtime);
|
||||||
|
if (ops == NULL) {
|
||||||
|
ERROR("Failed to get runtime ops");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = ops->rt_exec_resize(name, runtime, params);
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|||||||
@ -73,15 +73,14 @@ typedef struct _rt_rm_params_t {
|
|||||||
const char *rootpath;
|
const char *rootpath;
|
||||||
} rt_rm_params_t;
|
} rt_rm_params_t;
|
||||||
|
|
||||||
typedef struct _rt_get_console_conf_params_t {
|
|
||||||
const char *rootpath;
|
|
||||||
struct engine_console_config *config;
|
|
||||||
} rt_get_console_conf_params_t;
|
|
||||||
|
|
||||||
typedef struct _rt_status_params_t {
|
typedef struct _rt_status_params_t {
|
||||||
const char *rootpath;
|
const char *rootpath;
|
||||||
} rt_status_params_t;
|
} rt_status_params_t;
|
||||||
|
|
||||||
|
typedef struct _rt_stats_params_t {
|
||||||
|
const char *rootpath;
|
||||||
|
} rt_stats_params_t;
|
||||||
|
|
||||||
typedef struct _rt_exec_params_t {
|
typedef struct _rt_exec_params_t {
|
||||||
const char *rootpath;
|
const char *rootpath;
|
||||||
const char *logpath;
|
const char *logpath;
|
||||||
@ -93,6 +92,7 @@ typedef struct _rt_exec_params_t {
|
|||||||
size_t args_len;
|
size_t args_len;
|
||||||
const char * const *envs;
|
const char * const *envs;
|
||||||
size_t envs_len;
|
size_t envs_len;
|
||||||
|
const char *suffix;
|
||||||
} rt_exec_params_t;
|
} rt_exec_params_t;
|
||||||
|
|
||||||
typedef struct _rt_pause_params_t {
|
typedef struct _rt_pause_params_t {
|
||||||
@ -103,6 +103,40 @@ typedef struct _rt_resume_params_t {
|
|||||||
const char *rootpath;
|
const char *rootpath;
|
||||||
} rt_resume_params_t;
|
} rt_resume_params_t;
|
||||||
|
|
||||||
|
typedef struct _rt_attach_params_t {
|
||||||
|
const char *rootpath;
|
||||||
|
const char *stdin;
|
||||||
|
const char *stdout;
|
||||||
|
const char *stderr;
|
||||||
|
} rt_attach_params_t;
|
||||||
|
|
||||||
|
typedef struct _rt_update_params_t {
|
||||||
|
const char *rootpath;
|
||||||
|
const host_config *hostconfig;
|
||||||
|
} rt_update_params_t;
|
||||||
|
|
||||||
|
typedef struct _rt_listpids_params_t {
|
||||||
|
const char *rootpath;
|
||||||
|
} rt_listpids_params_t;
|
||||||
|
|
||||||
|
typedef struct _rt_listpids_out_t {
|
||||||
|
pid_t *pids;
|
||||||
|
size_t pids_len;
|
||||||
|
} rt_listpids_out_t;
|
||||||
|
|
||||||
|
typedef struct _rt_resize_params_t {
|
||||||
|
const char *rootpath;
|
||||||
|
unsigned int height;
|
||||||
|
unsigned int width;
|
||||||
|
} rt_resize_params_t;
|
||||||
|
|
||||||
|
typedef struct _rt_exec_resize_params_t {
|
||||||
|
const char *rootpath;
|
||||||
|
const char *suffix;
|
||||||
|
unsigned int height;
|
||||||
|
unsigned int width;
|
||||||
|
} rt_exec_resize_params_t;
|
||||||
|
|
||||||
struct rt_ops {
|
struct rt_ops {
|
||||||
/* detect whether runtime is of this runtime type */
|
/* detect whether runtime is of this runtime type */
|
||||||
bool (*detect)(const char *runtime);
|
bool (*detect)(const char *runtime);
|
||||||
@ -118,16 +152,26 @@ struct rt_ops {
|
|||||||
|
|
||||||
int (*rt_rm)(const char *name, const char *runtime, const rt_rm_params_t *params);
|
int (*rt_rm)(const char *name, const char *runtime, const rt_rm_params_t *params);
|
||||||
|
|
||||||
int (*rt_get_console_config)(const char *name, const char *runtime, const rt_get_console_conf_params_t *params);
|
|
||||||
|
|
||||||
int (*rt_status)(const char *name, const char *runtime, const rt_status_params_t *params,
|
int (*rt_status)(const char *name, const char *runtime, const rt_status_params_t *params,
|
||||||
struct engine_container_info *status);
|
struct engine_container_status_info *status);
|
||||||
|
|
||||||
|
int (*rt_resources_stats)(const char *name, const char *runtime, const rt_stats_params_t *params,
|
||||||
|
struct engine_container_resources_stats_info *rs_stats);
|
||||||
|
|
||||||
int (*rt_exec)(const char *name, const char *runtime, const rt_exec_params_t *params,
|
int (*rt_exec)(const char *name, const char *runtime, const rt_exec_params_t *params,
|
||||||
int *exit_code);
|
int *exit_code);
|
||||||
|
|
||||||
int (*rt_pause)(const char *name, const char *runtime, const rt_pause_params_t *params);
|
int (*rt_pause)(const char *name, const char *runtime, const rt_pause_params_t *params);
|
||||||
int (*rt_resume)(const char *name, const char *runtime, const rt_resume_params_t *params);
|
int (*rt_resume)(const char *name, const char *runtime, const rt_resume_params_t *params);
|
||||||
|
|
||||||
|
int (*rt_attach)(const char *name, const char *runtime, const rt_attach_params_t *params);
|
||||||
|
|
||||||
|
int (*rt_update)(const char *name, const char *runtime, const rt_update_params_t *params);
|
||||||
|
|
||||||
|
int (*rt_listpids)(const char *name, const char *runtime, const rt_listpids_params_t *params,
|
||||||
|
rt_listpids_out_t *out);
|
||||||
|
int (*rt_resize)(const char *name, const char *runtime, const rt_resize_params_t *params);
|
||||||
|
int (*rt_exec_resize)(const char *name, const char *runtime, const rt_exec_resize_params_t *params);
|
||||||
};
|
};
|
||||||
|
|
||||||
int runtime_create(const char *name, const char *runtime, const rt_create_params_t *params);
|
int runtime_create(const char *name, const char *runtime, const rt_create_params_t *params);
|
||||||
@ -135,14 +179,22 @@ int runtime_clean_resource(const char *name, const char *runtime, const rt_clean
|
|||||||
int runtime_start(const char *name, const char *runtime, const rt_start_params_t *params, container_pid_t *pid_info);
|
int runtime_start(const char *name, const char *runtime, const rt_start_params_t *params, container_pid_t *pid_info);
|
||||||
int runtime_restart(const char *name, const char *runtime, const rt_restart_params_t *params);
|
int runtime_restart(const char *name, const char *runtime, const rt_restart_params_t *params);
|
||||||
int runtime_rm(const char *name, const char *runtime, const rt_rm_params_t *params);
|
int runtime_rm(const char *name, const char *runtime, const rt_rm_params_t *params);
|
||||||
int runtime_get_console_config(const char *name, const char *runtime, const rt_get_console_conf_params_t *params);
|
|
||||||
int runtime_status(const char *name, const char *runtime, const rt_status_params_t *params,
|
int runtime_status(const char *name, const char *runtime, const rt_status_params_t *params,
|
||||||
struct engine_container_info *status);
|
struct engine_container_status_info *status);
|
||||||
|
int runtime_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params,
|
||||||
|
struct engine_container_resources_stats_info *rs_stats);
|
||||||
int runtime_exec(const char *name, const char *runtime, const rt_exec_params_t *params,
|
int runtime_exec(const char *name, const char *runtime, const rt_exec_params_t *params,
|
||||||
int *exit_code);
|
int *exit_code);
|
||||||
int runtime_pause(const char *name, const char *runtime, const rt_pause_params_t *params);
|
int runtime_pause(const char *name, const char *runtime, const rt_pause_params_t *params);
|
||||||
int runtime_resume(const char *name, const char *runtime, const rt_resume_params_t *params);
|
int runtime_resume(const char *name, const char *runtime, const rt_resume_params_t *params);
|
||||||
|
int runtime_attach(const char *name, const char *runtime, const rt_attach_params_t *params);
|
||||||
|
|
||||||
|
int runtime_update(const char *name, const char *runtime, const rt_update_params_t *params);
|
||||||
|
|
||||||
|
int runtime_listpids(const char *name, const char *runtime, const rt_listpids_params_t *params, rt_listpids_out_t *out);
|
||||||
|
void free_rt_listpids_out_t(rt_listpids_out_t *out);
|
||||||
|
int runtime_resize(const char *name, const char *runtime, const rt_resize_params_t *params);
|
||||||
|
int runtime_exec_resize(const char *name, const char *runtime, const rt_exec_resize_params_t *params);
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -123,8 +123,6 @@ typedef struct {
|
|||||||
|
|
||||||
int(*inspect)(const container_inspect_request *request, container_inspect_response **response);
|
int(*inspect)(const container_inspect_request *request, container_inspect_response **response);
|
||||||
|
|
||||||
int(*conf)(const struct lcrd_container_conf_request *request, struct lcrd_container_conf_response **response);
|
|
||||||
|
|
||||||
int(*wait)(const container_wait_request *request, container_wait_response **response);
|
int(*wait)(const container_wait_request *request, container_wait_response **response);
|
||||||
|
|
||||||
int(*events)(const struct lcrd_events_request *request, const stream_func_wrapper *stream);
|
int(*events)(const struct lcrd_events_request *request, const stream_func_wrapper *stream);
|
||||||
@ -140,6 +138,8 @@ typedef struct {
|
|||||||
|
|
||||||
int(*logs)(const struct lcrd_logs_request *request,
|
int(*logs)(const struct lcrd_logs_request *request,
|
||||||
stream_func_wrapper *stream, struct lcrd_logs_response **response);
|
stream_func_wrapper *stream, struct lcrd_logs_response **response);
|
||||||
|
|
||||||
|
int(*resize)(const struct lcrd_container_resize_request *request, struct lcrd_container_resize_response **response);
|
||||||
} service_container_callback_t;
|
} service_container_callback_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@ -811,14 +811,74 @@ cleanup:
|
|||||||
free_container_list_response(response);
|
free_container_list_response(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CRIRuntimeServiceImpl::PackContainerStatsAttributes(
|
||||||
|
const char *id,
|
||||||
|
std::unique_ptr<runtime::v1alpha2::ContainerStats> &container,
|
||||||
|
Errors &error)
|
||||||
|
{
|
||||||
|
if (id == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
container->mutable_attributes()->set_id(id);
|
||||||
|
auto status = ContainerStatus(std::string(id), error);
|
||||||
|
if (status->has_metadata()) {
|
||||||
|
std::unique_ptr<runtime::v1alpha2::ContainerMetadata> metadata(
|
||||||
|
new (std::nothrow) runtime::v1alpha2::ContainerMetadata(status->metadata()));
|
||||||
|
if (metadata == nullptr) {
|
||||||
|
error.SetError("Out of memory");
|
||||||
|
ERROR("Out of memory");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
container->mutable_attributes()->set_allocated_metadata(metadata.release());
|
||||||
|
}
|
||||||
|
if (status->labels_size() > 0) {
|
||||||
|
auto labels = container->mutable_attributes()->mutable_labels();
|
||||||
|
*labels = status->labels();
|
||||||
|
}
|
||||||
|
if (status->annotations_size() > 0) {
|
||||||
|
auto annotations = container->mutable_attributes()->mutable_annotations();
|
||||||
|
*annotations = status->annotations();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CRIRuntimeServiceImpl::PackContainerStatsFilesystemUsage(
|
||||||
|
const char *id, const char *image_type,
|
||||||
|
std::unique_ptr<runtime::v1alpha2::ContainerStats> &container,
|
||||||
|
Errors &error)
|
||||||
|
{
|
||||||
|
if (id == nullptr || image_type == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
imagetool_fs_info *fs_usage { nullptr };
|
||||||
|
if (im_get_container_filesystem_usage(image_type, id, &fs_usage) != 0) {
|
||||||
|
ERROR("Failed to get container filesystem usage");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs_usage == nullptr) {
|
||||||
|
container->mutable_writable_layer()->mutable_used_bytes()->set_value(0);
|
||||||
|
container->mutable_writable_layer()->mutable_inodes_used()->set_value(0);
|
||||||
|
} else {
|
||||||
|
if (fs_usage->image_filesystems[0]->used_bytes->value) {
|
||||||
|
container->mutable_writable_layer()->mutable_used_bytes()->set_value(
|
||||||
|
fs_usage->image_filesystems[0]->used_bytes->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs_usage->image_filesystems[0]->inodes_used->value) {
|
||||||
|
container->mutable_writable_layer()->mutable_inodes_used()->set_value(
|
||||||
|
fs_usage->image_filesystems[0]->inodes_used->value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free_imagetool_fs_info(fs_usage);
|
||||||
|
}
|
||||||
|
|
||||||
void CRIRuntimeServiceImpl::ContainerStatsToGRPC(
|
void CRIRuntimeServiceImpl::ContainerStatsToGRPC(
|
||||||
container_stats_response *response,
|
container_stats_response *response,
|
||||||
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *containerstats, Errors &error)
|
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *containerstats, Errors &error)
|
||||||
{
|
{
|
||||||
int ret {};
|
|
||||||
|
|
||||||
for (size_t i {}; i < response->container_stats_len; i++) {
|
for (size_t i {}; i < response->container_stats_len; i++) {
|
||||||
imagetool_fs_info *fs_usage { nullptr };
|
|
||||||
using ContainerStatsPtr = std::unique_ptr<runtime::v1alpha2::ContainerStats>;
|
using ContainerStatsPtr = std::unique_ptr<runtime::v1alpha2::ContainerStats>;
|
||||||
ContainerStatsPtr container(new (std::nothrow) runtime::v1alpha2::ContainerStats);
|
ContainerStatsPtr container(new (std::nothrow) runtime::v1alpha2::ContainerStats);
|
||||||
if (container == nullptr) {
|
if (container == nullptr) {
|
||||||
@ -826,14 +886,12 @@ void CRIRuntimeServiceImpl::ContainerStatsToGRPC(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response->container_stats[i]->id != nullptr && response->container_stats[i]->image_type != nullptr) {
|
PackContainerStatsAttributes(response->container_stats[i]->id, container, error);
|
||||||
container->mutable_attributes()->set_id(response->container_stats[i]->id);
|
if (error.NotEmpty()) {
|
||||||
ret = im_get_container_filesystem_usage(response->container_stats[i]->image_type,
|
return;
|
||||||
response->container_stats[i]->id, &fs_usage);
|
|
||||||
if (ret != 0) {
|
|
||||||
ERROR("Failed to get container filesystem usage");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
PackContainerStatsFilesystemUsage(response->container_stats[i]->id,
|
||||||
|
response->container_stats[i]->image_type, container, error);
|
||||||
|
|
||||||
if (response->container_stats[i]->mem_used) {
|
if (response->container_stats[i]->mem_used) {
|
||||||
container->mutable_memory()->mutable_working_set_bytes()->set_value(response->container_stats[i]->mem_used);
|
container->mutable_memory()->mutable_working_set_bytes()->set_value(response->container_stats[i]->mem_used);
|
||||||
@ -845,23 +903,7 @@ void CRIRuntimeServiceImpl::ContainerStatsToGRPC(
|
|||||||
container->mutable_cpu()->set_timestamp((int64_t)(response->container_stats[i]->cpu_system_use));
|
container->mutable_cpu()->set_timestamp((int64_t)(response->container_stats[i]->cpu_system_use));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs_usage == nullptr) {
|
|
||||||
container->mutable_writable_layer()->mutable_used_bytes()->set_value(0);
|
|
||||||
container->mutable_writable_layer()->mutable_inodes_used()->set_value(0);
|
|
||||||
}
|
|
||||||
if (fs_usage != nullptr) {
|
|
||||||
if (fs_usage->image_filesystems[0]->used_bytes->value) {
|
|
||||||
container->mutable_writable_layer()->mutable_used_bytes()->set_value(
|
|
||||||
fs_usage->image_filesystems[0]->used_bytes->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fs_usage->image_filesystems[0]->inodes_used->value) {
|
|
||||||
container->mutable_writable_layer()->mutable_inodes_used()->set_value(
|
|
||||||
fs_usage->image_filesystems[0]->inodes_used->value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
containerstats->push_back(move(container));
|
containerstats->push_back(move(container));
|
||||||
free_imagetool_fs_info(fs_usage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -143,6 +143,13 @@ private:
|
|||||||
void ListContainersToGRPC(container_list_response *response,
|
void ListContainersToGRPC(container_list_response *response,
|
||||||
std::vector<std::unique_ptr<runtime::v1alpha2::Container>> *pods, Errors &error);
|
std::vector<std::unique_ptr<runtime::v1alpha2::Container>> *pods, Errors &error);
|
||||||
|
|
||||||
|
void PackContainerStatsAttributes(const char *id, std::unique_ptr<runtime::v1alpha2::ContainerStats> &container,
|
||||||
|
Errors &error);
|
||||||
|
|
||||||
|
void PackContainerStatsFilesystemUsage(const char *id, const char *image_type,
|
||||||
|
std::unique_ptr<runtime::v1alpha2::ContainerStats> &container,
|
||||||
|
Errors &error);
|
||||||
|
|
||||||
void ContainerStatsToGRPC(container_stats_response *response,
|
void ContainerStatsToGRPC(container_stats_response *response,
|
||||||
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *pods, Errors &error);
|
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *pods, Errors &error);
|
||||||
|
|
||||||
|
|||||||
@ -174,9 +174,10 @@ static void ModifyHostNetworkOptionForSandbox(const runtime::v1alpha2::Namespace
|
|||||||
static void ModifyContainerNamespaceOptions(const runtime::v1alpha2::NamespaceOption &nsOpts,
|
static void ModifyContainerNamespaceOptions(const runtime::v1alpha2::NamespaceOption &nsOpts,
|
||||||
const std::string &podSandboxID, host_config *hostConfig, Errors &error)
|
const std::string &podSandboxID, host_config *hostConfig, Errors &error)
|
||||||
{
|
{
|
||||||
|
std::string sandboxNSMode = "container:" + podSandboxID;
|
||||||
if (nsOpts.pid() == runtime::v1alpha2::NamespaceMode::POD) {
|
if (nsOpts.pid() == runtime::v1alpha2::NamespaceMode::POD) {
|
||||||
free(hostConfig->pid_mode);
|
free(hostConfig->pid_mode);
|
||||||
hostConfig->pid_mode = util_strdup_s("");
|
hostConfig->pid_mode = util_strdup_s(sandboxNSMode.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set common Namespace options */
|
/* set common Namespace options */
|
||||||
|
|||||||
@ -212,39 +212,6 @@ error_out:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int generateID(char *id, size_t len)
|
|
||||||
{
|
|
||||||
int fd = -1;
|
|
||||||
int num = 0;
|
|
||||||
size_t i;
|
|
||||||
const int m = 256;
|
|
||||||
|
|
||||||
len = len / 2;
|
|
||||||
fd = open("/dev/urandom", O_RDONLY);
|
|
||||||
if (fd == -1) {
|
|
||||||
ERROR("Failed to open /dev/urandom");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
int nret;
|
|
||||||
if (read(fd, &num, sizeof(int)) < 0) {
|
|
||||||
ERROR("Failed to read urandom value");
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
unsigned char rs = (unsigned char)(num % m);
|
|
||||||
nret = snprintf((id + i * 2), ((len - i) * 2 + 1), "%02x", (unsigned int)rs);
|
|
||||||
if (nret >= ((len - i) * 2 + 1) || nret < 0) {
|
|
||||||
close(fd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
id[i * 2] = '\0';
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static oci_runtime_spec *merge_config(const char *id, const char *image_type, const char *image_name,
|
static oci_runtime_spec *merge_config(const char *id, const char *image_type, const char *image_name,
|
||||||
const char *ext_config_image, host_config *host_spec,
|
const char *ext_config_image, host_config *host_spec,
|
||||||
container_custom_config *custom_spec,
|
container_custom_config *custom_spec,
|
||||||
@ -311,7 +278,7 @@ static char *try_generate_id()
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < max_time; i++) {
|
for (i = 0; i < max_time; i++) {
|
||||||
if (generateID(id, (size_t)CONTAINER_ID_MAX_LEN)) {
|
if (util_generate_random_str(id, (size_t)CONTAINER_ID_MAX_LEN)) {
|
||||||
ERROR("Generate id failed");
|
ERROR("Generate id failed");
|
||||||
goto err_out;
|
goto err_out;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -213,7 +213,8 @@ static int copy_map_labels(const container_config *config, map_t **map_labels)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static container_info *get_container_stats(const container_t *cont, const struct engine_container_info *einfo,
|
static container_info *get_container_stats(const container_t *cont,
|
||||||
|
const struct engine_container_resources_stats_info *einfo,
|
||||||
const struct stats_context *ctx)
|
const struct stats_context *ctx)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -229,9 +230,6 @@ static container_info *get_container_stats(const container_t *cont, const struct
|
|||||||
}
|
}
|
||||||
|
|
||||||
info->id = util_strdup_s(cont->common_config->id);
|
info->id = util_strdup_s(cont->common_config->id);
|
||||||
info->has_pid = einfo->has_pid;
|
|
||||||
info->pid = (int32_t)einfo->pid;
|
|
||||||
info->status = (int)einfo->status;
|
|
||||||
info->pids_current = einfo->pids_current;
|
info->pids_current = einfo->pids_current;
|
||||||
info->cpu_use_nanos = einfo->cpu_use_nanos;
|
info->cpu_use_nanos = einfo->cpu_use_nanos;
|
||||||
info->blkio_read = einfo->blkio_read;
|
info->blkio_read = einfo->blkio_read;
|
||||||
@ -395,29 +393,12 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_containers_stats(const char *runtime, char **idsarray, size_t ids_len, const struct stats_context *ctx,
|
static int get_containers_stats(char **idsarray, size_t ids_len, const struct stats_context *ctx,
|
||||||
bool check_exists, container_info ***info, size_t *info_len)
|
bool check_exists, container_info ***info, size_t *info_len)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int nret;
|
int nret;
|
||||||
size_t i;
|
size_t i;
|
||||||
char *engine_path = NULL;
|
|
||||||
struct engine_operation *engine_ops = NULL;
|
|
||||||
|
|
||||||
engine_ops = engines_get_handler(runtime);
|
|
||||||
if (engine_ops == NULL || engine_ops->engine_get_container_status_op == NULL ||
|
|
||||||
engine_ops->engine_free_container_status_op == NULL) {
|
|
||||||
ERROR("Failed to get engine stats operations");
|
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
engine_path = conf_get_routine_rootdir(runtime);
|
|
||||||
if (engine_path == NULL) {
|
|
||||||
ERROR("Get engine path failed");
|
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
nret = service_stats_make_memory(info, ids_len);
|
nret = service_stats_make_memory(info, ids_len);
|
||||||
if (nret != 0) {
|
if (nret != 0) {
|
||||||
@ -426,7 +407,7 @@ static int get_containers_stats(const char *runtime, char **idsarray, size_t ids
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < ids_len; i++) {
|
for (i = 0; i < ids_len; i++) {
|
||||||
struct engine_container_info einfo = { 0 };
|
struct engine_container_resources_stats_info einfo = { 0 };
|
||||||
container_t *cont = NULL;
|
container_t *cont = NULL;
|
||||||
|
|
||||||
cont = containers_store_get(idsarray[i]);
|
cont = containers_store_get(idsarray[i]);
|
||||||
@ -440,9 +421,11 @@ static int get_containers_stats(const char *runtime, char **idsarray, size_t ids
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (is_running(cont->state)) {
|
if (is_running(cont->state)) {
|
||||||
nret = engine_ops->engine_get_container_status_op(cont->common_config->id, engine_path, &einfo);
|
rt_stats_params_t params = { 0 };
|
||||||
|
params.rootpath = cont->root_path;
|
||||||
|
|
||||||
|
nret = runtime_resources_stats(cont->common_config->id, cont->runtime, ¶ms, &einfo);
|
||||||
if (nret != 0) {
|
if (nret != 0) {
|
||||||
engine_ops->engine_clear_errmsg_op();
|
|
||||||
container_unref(cont);
|
container_unref(cont);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -455,14 +438,12 @@ static int get_containers_stats(const char *runtime, char **idsarray, size_t ids
|
|||||||
|
|
||||||
(*info)[*info_len] = get_container_stats(cont, &einfo, ctx);
|
(*info)[*info_len] = get_container_stats(cont, &einfo, ctx);
|
||||||
container_unref(cont);
|
container_unref(cont);
|
||||||
engine_ops->engine_free_container_status_op(&einfo);
|
|
||||||
if ((*info)[*info_len] == NULL) {
|
if ((*info)[*info_len] == NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
(*info_len)++;
|
(*info_len)++;
|
||||||
}
|
}
|
||||||
cleanup:
|
cleanup:
|
||||||
free(engine_path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,12 +471,6 @@ static int container_stats_cb(const container_stats_request *request,
|
|||||||
goto pack_response;
|
goto pack_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request->runtime == NULL) {
|
|
||||||
ERROR("Receive NULL Request runtime");
|
|
||||||
cc = LCRD_ERR_INPUT;
|
|
||||||
goto pack_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx = fold_stats_filter(request);
|
ctx = fold_stats_filter(request);
|
||||||
if (ctx == NULL) {
|
if (ctx == NULL) {
|
||||||
cc = LCRD_ERR_EXEC;
|
cc = LCRD_ERR_EXEC;
|
||||||
@ -510,7 +485,7 @@ static int container_stats_cb(const container_stats_request *request,
|
|||||||
goto pack_response;
|
goto pack_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_containers_stats(request->runtime, idsarray, ids_len, ctx, check_exists, &info, &info_len)) {
|
if (get_containers_stats(idsarray, ids_len, ctx, check_exists, &info, &info_len)) {
|
||||||
cc = LCRD_ERR_EXEC;
|
cc = LCRD_ERR_EXEC;
|
||||||
goto pack_response;
|
goto pack_response;
|
||||||
}
|
}
|
||||||
@ -553,6 +528,7 @@ static int resume_container(container_t *cont)
|
|||||||
}
|
}
|
||||||
|
|
||||||
state_reset_paused(cont->state);
|
state_reset_paused(cont->state);
|
||||||
|
|
||||||
update_health_monitor(cont->common_config->id);
|
update_health_monitor(cont->common_config->id);
|
||||||
|
|
||||||
if (container_to_disk(cont)) {
|
if (container_to_disk(cont)) {
|
||||||
@ -739,6 +715,7 @@ static int pause_container(container_t *cont)
|
|||||||
}
|
}
|
||||||
|
|
||||||
state_set_paused(cont->state);
|
state_set_paused(cont->state);
|
||||||
|
|
||||||
update_health_monitor(cont->common_config->id);
|
update_health_monitor(cont->common_config->id);
|
||||||
|
|
||||||
if (container_to_disk(cont)) {
|
if (container_to_disk(cont)) {
|
||||||
@ -840,24 +817,6 @@ pack_response:
|
|||||||
return (cc == LCRD_SUCCESS) ? 0 : -1;
|
return (cc == LCRD_SUCCESS) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void to_engine_resources(const host_config *hostconfig, struct engine_cgroup_resources *cr)
|
|
||||||
{
|
|
||||||
if (hostconfig == NULL || cr == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
cr->blkio_weight = hostconfig->blkio_weight;
|
|
||||||
cr->cpu_shares = (uint64_t)hostconfig->cpu_shares;
|
|
||||||
cr->cpu_period = (uint64_t)hostconfig->cpu_period;
|
|
||||||
cr->cpu_quota = (uint64_t)hostconfig->cpu_quota;
|
|
||||||
cr->cpuset_cpus = hostconfig->cpuset_cpus;
|
|
||||||
cr->cpuset_mems = hostconfig->cpuset_mems;
|
|
||||||
cr->memory_limit = (uint64_t)hostconfig->memory;
|
|
||||||
cr->memory_swap = (uint64_t)hostconfig->memory_swap;
|
|
||||||
cr->memory_reservation = (uint64_t)hostconfig->memory_reservation;
|
|
||||||
cr->kernel_memory_limit = (uint64_t)hostconfig->kernel_memory;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void host_config_restore_unlocking(container_t *cont, host_config *backup_hostconfig)
|
static void host_config_restore_unlocking(container_t *cont, host_config *backup_hostconfig)
|
||||||
{
|
{
|
||||||
free_host_config(cont->hostconfig);
|
free_host_config(cont->hostconfig);
|
||||||
@ -1034,32 +993,6 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int runtime_update(const char *id, const char *runtime, const char *rootpath, struct engine_cgroup_resources *cr)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
struct engine_operation *engine_ops = NULL;
|
|
||||||
|
|
||||||
engine_ops = engines_get_handler(runtime);
|
|
||||||
if (engine_ops == NULL || engine_ops->engine_update_op == NULL) {
|
|
||||||
DEBUG("Failed to get engine update operations");
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!engine_ops->engine_update_op(id, rootpath, cr)) {
|
|
||||||
DEBUG("Update container %s failed", id);
|
|
||||||
const char *tmpmsg = NULL;
|
|
||||||
tmpmsg = engine_ops->engine_get_errmsg_op();
|
|
||||||
lcrd_set_error_message("Cannot update container %s: %s", id, (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
|
|
||||||
tmpmsg : DEF_ERR_RUNTIME_STR);
|
|
||||||
engine_ops->engine_clear_errmsg_op();
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int do_update_resources(const container_update_request *request, container_t *cont)
|
static int do_update_resources(const container_update_request *request, container_t *cont)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -1067,7 +1000,7 @@ static int do_update_resources(const container_update_request *request, containe
|
|||||||
parser_error err = NULL;
|
parser_error err = NULL;
|
||||||
host_config *hostconfig = NULL;
|
host_config *hostconfig = NULL;
|
||||||
host_config *backup_hostconfig = NULL;
|
host_config *backup_hostconfig = NULL;
|
||||||
struct engine_cgroup_resources cr = { 0 };
|
rt_update_params_t params = { 0 };
|
||||||
|
|
||||||
if (request->host_config == NULL) {
|
if (request->host_config == NULL) {
|
||||||
DEBUG("receive NULL host config");
|
DEBUG("receive NULL host config");
|
||||||
@ -1111,10 +1044,10 @@ static int do_update_resources(const container_update_request *request, containe
|
|||||||
container_update_restart_manager(cont, hostconfig->restart_policy);
|
container_update_restart_manager(cont, hostconfig->restart_policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
to_engine_resources(hostconfig, &cr);
|
params.rootpath = cont->root_path;
|
||||||
if (runtime_update(id, cont->runtime, cont->root_path, &cr)) {
|
params.hostconfig = hostconfig;
|
||||||
|
if (runtime_update(id, cont->runtime, ¶ms)) {
|
||||||
ERROR("Update container %s failed", id);
|
ERROR("Update container %s failed", id);
|
||||||
host_config_restore_unlocking(cont, backup_hostconfig);
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto unlock_out;
|
goto unlock_out;
|
||||||
}
|
}
|
||||||
@ -1291,6 +1224,179 @@ pack_response:
|
|||||||
return (cc == LCRD_SUCCESS) ? 0 : -1;
|
return (cc == LCRD_SUCCESS) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int runtime_resize_helper(const char *id, const char *runtime, const char *rootpath, unsigned int height,
|
||||||
|
unsigned int width)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
rt_resize_params_t params = { 0 };
|
||||||
|
|
||||||
|
params.rootpath = rootpath;
|
||||||
|
params.height = height;
|
||||||
|
params.width = width;
|
||||||
|
|
||||||
|
ret = runtime_resize(id, runtime, ¶ms);
|
||||||
|
if (ret != 0) {
|
||||||
|
ERROR("Failed to resize container %s", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int runtime_exec_resize_helper(const char *id, const char *runtime, const char *rootpath, const char *suffix,
|
||||||
|
unsigned int height,
|
||||||
|
unsigned int width)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
rt_exec_resize_params_t params = { 0 };
|
||||||
|
|
||||||
|
params.rootpath = rootpath;
|
||||||
|
params.suffix = suffix;
|
||||||
|
params.height = height;
|
||||||
|
params.width = width;
|
||||||
|
|
||||||
|
ret = runtime_exec_resize(id, runtime, ¶ms);
|
||||||
|
if (ret != 0) {
|
||||||
|
ERROR("Failed to resize container %s", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int resize_container(container_t *cont, const char *suffix, unsigned int height, unsigned int width)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
const char *id = cont->common_config->id;
|
||||||
|
|
||||||
|
container_lock(cont);
|
||||||
|
|
||||||
|
if (!is_running(cont->state)) {
|
||||||
|
ERROR("Container %s is not running", id);
|
||||||
|
lcrd_set_error_message("Container %s is not running", id);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (suffix != NULL) {
|
||||||
|
DEBUG("Failed to resize container:%s suffix:%s", id, suffix);
|
||||||
|
if (runtime_exec_resize_helper(id, cont->runtime, cont->root_path, suffix, height, width)) {
|
||||||
|
ERROR("Failed to resize container:%s", id);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (runtime_resize_helper(id, cont->runtime, cont->root_path, height, width)) {
|
||||||
|
ERROR("Failed to resize container:%s", id);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
container_unlock(cont);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pack_resize_response(struct lcrd_container_resize_response *response, uint32_t cc, const char *id)
|
||||||
|
{
|
||||||
|
if (response == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
response->cc = cc;
|
||||||
|
if (id != NULL) {
|
||||||
|
response->id = util_strdup_s(id);
|
||||||
|
}
|
||||||
|
if (g_lcrd_errmsg != NULL) {
|
||||||
|
response->errmsg = util_strdup_s(g_lcrd_errmsg);
|
||||||
|
DAEMON_CLEAR_ERRMSG();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int resize_request_check(const struct lcrd_container_resize_request *request)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
char *name = request->id;
|
||||||
|
if (name == NULL) {
|
||||||
|
ERROR("Resume: receive NULL id");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!util_valid_container_id_or_name(name)) {
|
||||||
|
ERROR("Invalid container name %s", name);
|
||||||
|
lcrd_set_error_message("Invalid container name %s", name);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->suffix != NULL && !util_valid_exec_suffix(request->suffix)) {
|
||||||
|
ERROR("Invalid suffix name %s", name);
|
||||||
|
lcrd_set_error_message("Invalid suffix name %s", name);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int container_resize_cb(const struct lcrd_container_resize_request *request,
|
||||||
|
struct lcrd_container_resize_response **response)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
uint32_t cc = LCRD_SUCCESS;
|
||||||
|
char *name = NULL;
|
||||||
|
char *id = NULL;
|
||||||
|
container_t *cont = NULL;
|
||||||
|
|
||||||
|
DAEMON_CLEAR_ERRMSG();
|
||||||
|
if (request == NULL || response == NULL) {
|
||||||
|
ERROR("Invalid NULL input");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
*response = util_common_calloc_s(sizeof(struct lcrd_container_resize_response));
|
||||||
|
if (*response == NULL) {
|
||||||
|
ERROR("Resume: Out of memory");
|
||||||
|
cc = LCRD_ERR_MEMOUT;
|
||||||
|
goto pack_response;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resize_request_check(request) != 0) {
|
||||||
|
cc = LCRD_ERR_INPUT;
|
||||||
|
goto pack_response;
|
||||||
|
}
|
||||||
|
|
||||||
|
name = request->id;
|
||||||
|
|
||||||
|
cont = containers_store_get(name);
|
||||||
|
if (cont == NULL) {
|
||||||
|
ERROR("No such container:%s", name);
|
||||||
|
lcrd_set_error_message("No such container:%s", name);
|
||||||
|
cc = LCRD_ERR_EXEC;
|
||||||
|
goto pack_response;
|
||||||
|
}
|
||||||
|
|
||||||
|
id = cont->common_config->id;
|
||||||
|
set_log_prefix(id);
|
||||||
|
EVENT("Event: {Object: %s, Type: Resizing}", id);
|
||||||
|
|
||||||
|
ret = resize_container(cont, request->suffix, request->height, request->width);
|
||||||
|
if (ret != 0) {
|
||||||
|
cc = LCRD_ERR_EXEC;
|
||||||
|
container_state_set_error(cont->state, (const char *)g_lcrd_errmsg);
|
||||||
|
goto pack_response;
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT("Event: {Object: %s, Type: Resized}", id);
|
||||||
|
|
||||||
|
pack_response:
|
||||||
|
pack_resize_response(*response, cc, id);
|
||||||
|
container_unref(cont);
|
||||||
|
free_log_prefix();
|
||||||
|
return (cc == LCRD_SUCCESS) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
void container_extend_callback_init(service_container_callback_t *cb)
|
void container_extend_callback_init(service_container_callback_t *cb)
|
||||||
{
|
{
|
||||||
cb->update = container_update_cb;
|
cb->update = container_update_cb;
|
||||||
@ -1299,5 +1405,6 @@ void container_extend_callback_init(service_container_callback_t *cb)
|
|||||||
cb->stats = container_stats_cb;
|
cb->stats = container_stats_cb;
|
||||||
cb->events = container_events_cb;
|
cb->events = container_events_cb;
|
||||||
cb->export_rootfs = container_export_cb;
|
cb->export_rootfs = container_export_cb;
|
||||||
|
cb->resize = container_resize_cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -456,7 +456,6 @@ out:
|
|||||||
|
|
||||||
static inline void add_ps_array_elem(char **array, size_t *pos, const char *elem)
|
static inline void add_ps_array_elem(char **array, size_t *pos, const char *elem)
|
||||||
{
|
{
|
||||||
#define PARAM_NUM 100
|
|
||||||
if (*pos + 1 >= (PARAM_NUM - 1)) {
|
if (*pos + 1 >= (PARAM_NUM - 1)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -537,26 +536,48 @@ static int get_pids(const char *name, const char *runtime, const char *rootpath,
|
|||||||
char **pid_args)
|
char **pid_args)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct engine_operation *engine_ops = NULL;
|
size_t i = 0;
|
||||||
|
rt_listpids_params_t params = { 0 };
|
||||||
|
rt_listpids_out_t *out = NULL;
|
||||||
|
|
||||||
engine_ops = engines_get_handler(runtime);
|
out = util_common_calloc_s(sizeof(rt_listpids_out_t));
|
||||||
if (engine_ops == NULL || engine_ops->engine_get_container_pids_op == NULL) {
|
if (out == NULL) {
|
||||||
DEBUG("Failed to get engine top operations");
|
ERROR("Memeory out");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!engine_ops->engine_get_container_pids_op(name, rootpath, pids, pids_len)) {
|
params.rootpath = rootpath;
|
||||||
DEBUG("Top container %s failed", name);
|
|
||||||
const char *tmpmsg = NULL;
|
|
||||||
tmpmsg = engine_ops->engine_get_errmsg_op();
|
|
||||||
lcrd_set_error_message("Runtime top container error: %s",
|
|
||||||
(tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ? tmpmsg : DEF_ERR_RUNTIME_STR);
|
|
||||||
|
|
||||||
|
if (runtime_listpids(name, runtime, ¶ms, out) != 0) {
|
||||||
|
ERROR("runtime failed to list pids");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (out->pids_len > SIZE_MAX / sizeof(pid_t)) {
|
||||||
|
ERROR("list too many pids");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out->pids_len != 0) {
|
||||||
|
pid_t *tmp = NULL;
|
||||||
|
tmp = util_common_calloc_s(sizeof(pid_t) * out->pids_len);
|
||||||
|
if (tmp == NULL) {
|
||||||
|
ERROR("Memory out");
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
for (i = 0; i < out->pids_len; i++) {
|
||||||
|
tmp[i] = out->pids[i];
|
||||||
|
}
|
||||||
|
*pids = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
*pids_len = out->pids_len;
|
||||||
|
|
||||||
*pid_args = ps_pids_arg(*pids, *pids_len);
|
*pid_args = ps_pids_arg(*pids, *pids_len);
|
||||||
if (*pid_args == NULL) {
|
if (*pid_args == NULL) {
|
||||||
ERROR("failed to get pid_args");
|
ERROR("failed to get pid_args");
|
||||||
@ -564,9 +585,7 @@ static int get_pids(const char *name, const char *runtime, const char *rootpath,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
if (engine_ops != NULL) {
|
free_rt_listpids_out_t(out);
|
||||||
engine_ops->engine_clear_errmsg_op();
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1467,113 +1486,6 @@ pack_response:
|
|||||||
return (cc == LCRD_SUCCESS) ? 0 : -1;
|
return (cc == LCRD_SUCCESS) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int container_conf_request_check(const struct lcrd_container_conf_request *h)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (h->name == NULL) {
|
|
||||||
ERROR("Receive NULL container name");
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!util_valid_container_id_or_name(h->name)) {
|
|
||||||
ERROR("Invalid container name %s", h->name);
|
|
||||||
lcrd_set_error_message("Invalid container name %s", h->name);
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void pack_container_conf_response(struct lcrd_container_conf_response *response, uint32_t cc,
|
|
||||||
const struct engine_console_config *config)
|
|
||||||
{
|
|
||||||
if (response == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
response->cc = cc;
|
|
||||||
if (g_lcrd_errmsg != NULL) {
|
|
||||||
response->errmsg = util_strdup_s(g_lcrd_errmsg);
|
|
||||||
DAEMON_CLEAR_ERRMSG();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config->log_path != NULL) {
|
|
||||||
response->container_logpath = util_strdup_s(config->log_path);
|
|
||||||
}
|
|
||||||
response->container_logrotate = (uint32_t)config->log_rotate;
|
|
||||||
if (config->log_file_size != NULL) {
|
|
||||||
response->container_logsize = util_strdup_s(config->log_file_size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int container_conf_cb(const struct lcrd_container_conf_request *request,
|
|
||||||
struct lcrd_container_conf_response **response)
|
|
||||||
{
|
|
||||||
char *id = NULL;
|
|
||||||
uint32_t cc = LCRD_SUCCESS;
|
|
||||||
struct engine_operation *engine_ops = NULL;
|
|
||||||
struct engine_console_config config = { 0 };
|
|
||||||
container_t *cont = NULL;
|
|
||||||
rt_get_console_conf_params_t params = { 0 };
|
|
||||||
|
|
||||||
DAEMON_CLEAR_ERRMSG();
|
|
||||||
if (request == NULL || response == NULL) {
|
|
||||||
ERROR("Invalid NULL input");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*response = util_common_calloc_s(sizeof(struct lcrd_container_conf_response));
|
|
||||||
if (*response == NULL) {
|
|
||||||
ERROR("Out of memory");
|
|
||||||
cc = LCRD_ERR_MEMOUT;
|
|
||||||
goto pack_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (container_conf_request_check(request) != 0) {
|
|
||||||
cc = LCRD_ERR_INPUT;
|
|
||||||
goto pack_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
cont = containers_store_get(request->name);
|
|
||||||
if (cont == NULL) {
|
|
||||||
ERROR("No such container:%s", request->name);
|
|
||||||
lcrd_set_error_message("No such container:%s", request->name);
|
|
||||||
cc = LCRD_ERR_EXEC;
|
|
||||||
goto pack_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
engine_ops = engines_get_handler(cont->runtime);
|
|
||||||
if (engine_ops == NULL || engine_ops->engine_free_console_config_op == NULL) {
|
|
||||||
ERROR("Failed to get engine free_console_config operation");
|
|
||||||
cc = LCRD_ERR_EXEC;
|
|
||||||
goto pack_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
id = cont->common_config->id;
|
|
||||||
set_log_prefix(id);
|
|
||||||
|
|
||||||
params.rootpath = cont->root_path;
|
|
||||||
params.config = &config;
|
|
||||||
|
|
||||||
if (runtime_get_console_config(id, cont->runtime, ¶ms) != 0) {
|
|
||||||
cc = LCRD_ERR_EXEC;
|
|
||||||
goto pack_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
pack_response:
|
|
||||||
pack_container_conf_response(*response, cc, &config);
|
|
||||||
container_unref(cont);
|
|
||||||
if (engine_ops != NULL && engine_ops->engine_free_console_config_op != NULL) {
|
|
||||||
engine_ops->engine_free_console_config_op(&config);
|
|
||||||
}
|
|
||||||
|
|
||||||
free_log_prefix();
|
|
||||||
return (cc == LCRD_SUCCESS) ? 0 : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int rename_request_check(const struct lcrd_container_rename_request *request)
|
static int rename_request_check(const struct lcrd_container_rename_request *request)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -1745,7 +1657,6 @@ void container_information_callback_init(service_container_callback_t *cb)
|
|||||||
cb->inspect = container_inspect_cb;
|
cb->inspect = container_inspect_cb;
|
||||||
cb->list = container_list_cb;
|
cb->list = container_list_cb;
|
||||||
cb->wait = container_wait_cb;
|
cb->wait = container_wait_cb;
|
||||||
cb->conf = container_conf_cb;
|
|
||||||
cb->top = container_top_cb;
|
cb->top = container_top_cb;
|
||||||
cb->rename = container_rename_cb;
|
cb->rename = container_rename_cb;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -250,7 +250,7 @@ out:
|
|||||||
|
|
||||||
static int exec_container(container_t *cont, const char *runtime, char * const console_fifos[], const char *user,
|
static int exec_container(container_t *cont, const char *runtime, char * const console_fifos[], const char *user,
|
||||||
size_t argc, const char **argv, size_t env_len, const char **env,
|
size_t argc, const char **argv, size_t env_len, const char **env,
|
||||||
int64_t timeout, int *exit_code)
|
int64_t timeout, const char *suffix, int *exit_code)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *engine_log_path = NULL;
|
char *engine_log_path = NULL;
|
||||||
@ -287,6 +287,7 @@ static int exec_container(container_t *cont, const char *runtime, char * const c
|
|||||||
params.args_len = argc;
|
params.args_len = argc;
|
||||||
params.envs = (const char * const *)env;
|
params.envs = (const char * const *)env;
|
||||||
params.envs_len = env_len;
|
params.envs_len = env_len;
|
||||||
|
params.suffix = suffix;
|
||||||
|
|
||||||
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");
|
||||||
@ -332,6 +333,13 @@ static int container_exec_cb_check(const container_exec_request *request, contai
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (request->suffix != NULL && !util_valid_exec_suffix(request->suffix)) {
|
||||||
|
ERROR("Invalid exec suffix %s", request->suffix);
|
||||||
|
lcrd_set_error_message("Invalid exec suffix %s", request->suffix);
|
||||||
|
*cc = LCRD_ERR_EXEC;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
*cont = containers_store_get(container_name);
|
*cont = containers_store_get(container_name);
|
||||||
if (*cont == NULL) {
|
if (*cont == NULL) {
|
||||||
ERROR("No such container:%s", container_name);
|
ERROR("No such container:%s", container_name);
|
||||||
@ -564,7 +572,7 @@ static int container_exec_cb(const container_exec_request *request, container_ex
|
|||||||
|
|
||||||
if (exec_container(cont, cont->runtime, (char * const *)fifos, user, request->argv_len,
|
if (exec_container(cont, cont->runtime, (char * const *)fifos, user, request->argv_len,
|
||||||
(const char **)request->argv, request->env_len,
|
(const char **)request->argv, request->env_len,
|
||||||
(const char **)request->env, request->timeout, &exit_code)) {
|
(const char **)request->env, request->timeout, request->suffix, &exit_code)) {
|
||||||
cc = LCRD_ERR_EXEC;
|
cc = LCRD_ERR_EXEC;
|
||||||
goto pack_response;
|
goto pack_response;
|
||||||
}
|
}
|
||||||
@ -698,7 +706,7 @@ static int container_attach_cb(const container_attach_request *request, containe
|
|||||||
char *fifopath = NULL;
|
char *fifopath = NULL;
|
||||||
pthread_t tid = 0;
|
pthread_t tid = 0;
|
||||||
container_t *cont = NULL;
|
container_t *cont = NULL;
|
||||||
struct engine_operation *engine_ops = NULL;
|
rt_attach_params_t params = { 0 };
|
||||||
|
|
||||||
DAEMON_CLEAR_ERRMSG();
|
DAEMON_CLEAR_ERRMSG();
|
||||||
if (request == NULL || response == NULL) {
|
if (request == NULL || response == NULL) {
|
||||||
@ -725,21 +733,14 @@ static int container_attach_cb(const container_attach_request *request, containe
|
|||||||
goto pack_response;
|
goto pack_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
engine_ops = engines_get_handler(cont->runtime);
|
params.rootpath = cont->root_path;
|
||||||
if (engine_ops == NULL || engine_ops->engine_console_op == NULL) {
|
params.stdin = fifos[0];
|
||||||
DEBUG("Failed to get engine attach operations");
|
params.stdout = fifos[1];
|
||||||
cc = LCRD_ERR_EXEC;
|
params.stderr = fifos[2];
|
||||||
goto pack_response;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!engine_ops->engine_console_op(id, cont->root_path, fifos[0], fifos[1], fifos[2])) {
|
if (runtime_attach(cont->common_config->id, cont->runtime, ¶ms)) {
|
||||||
ERROR("attach failed");
|
ERROR("Runtime attach container failed");
|
||||||
cc = LCRD_ERR_EXEC;
|
cc = LCRD_ERR_EXEC;
|
||||||
const char *tmpmsg = NULL;
|
|
||||||
tmpmsg = engine_ops->engine_get_errmsg_op();
|
|
||||||
lcrd_set_error_message("Attach container error;%s", (tmpmsg && strcmp(tmpmsg, DEF_SUCCESS_STR)) ?
|
|
||||||
tmpmsg : DEF_ERR_RUNTIME_STR);
|
|
||||||
engine_ops->engine_clear_errmsg_op();
|
|
||||||
goto pack_response;
|
goto pack_response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1796,6 +1797,20 @@ static int handle_rotate(int fd, int wd, const char *path)
|
|||||||
return watch_fd;
|
return watch_fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cleanup_handler(void *arg)
|
||||||
|
{
|
||||||
|
int *fds = (int *)arg;
|
||||||
|
|
||||||
|
if (fds[0] < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fds[1] >= 0 && inotify_rm_watch(fds[0], fds[1]) < 0) {
|
||||||
|
SYSERROR("Rm watch failed");
|
||||||
|
}
|
||||||
|
close(fds[0]);
|
||||||
|
}
|
||||||
|
|
||||||
static int hanlde_events(int fd, const struct follow_args *farg)
|
static int hanlde_events(int fd, const struct follow_args *farg)
|
||||||
{
|
{
|
||||||
int write_cnt, rename_cnt;
|
int write_cnt, rename_cnt;
|
||||||
@ -1805,17 +1820,21 @@ static int hanlde_events(int fd, const struct follow_args *farg)
|
|||||||
ssize_t len = 0;
|
ssize_t len = 0;
|
||||||
struct inotify_event *c_event = NULL;
|
struct inotify_event *c_event = NULL;
|
||||||
char buf[MAXLINE] __attribute__((aligned(__alignof__(struct inotify_event)))) = { 0 };
|
char buf[MAXLINE] __attribute__((aligned(__alignof__(struct inotify_event)))) = { 0 };
|
||||||
|
int clean_fds[2] = { fd, -1 };
|
||||||
|
|
||||||
struct last_log_file_position last_pos = {
|
struct last_log_file_position last_pos = {
|
||||||
.file_index = farg->last_file_index,
|
.file_index = farg->last_file_index,
|
||||||
.pos = farg->last_file_pos,
|
.pos = farg->last_file_pos,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pthread_cleanup_push(cleanup_handler, clean_fds);
|
||||||
|
|
||||||
watch_fd = inotify_add_watch(fd, farg->path, IN_MODIFY | IN_DELETE | IN_MOVED_FROM | IN_MOVE_SELF);
|
watch_fd = inotify_add_watch(fd, farg->path, IN_MODIFY | IN_DELETE | IN_MOVED_FROM | IN_MOVE_SELF);
|
||||||
if (watch_fd < 0) {
|
if (watch_fd < 0) {
|
||||||
SYSERROR("Add watch %s failed", farg->path);
|
SYSERROR("Add watch %s failed", farg->path);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
clean_fds[1] = watch_fd;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) {
|
if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) {
|
||||||
@ -1866,9 +1885,7 @@ static int hanlde_events(int fd, const struct follow_args *farg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (inotify_rm_watch(fd, watch_fd) < 0) {
|
pthread_cleanup_pop(1);
|
||||||
SYSERROR("Rm watch failed");
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1881,7 +1898,7 @@ static void *follow_thread_func(void *arg)
|
|||||||
|
|
||||||
INFO("Get args, path: %s, last pos: %ld, last file: %d", farg->path, farg->last_file_pos, farg->last_file_index);
|
INFO("Get args, path: %s, last pos: %ld, last file: %d", farg->path, farg->last_file_pos, farg->last_file_index);
|
||||||
|
|
||||||
inotify_fd = inotify_init();
|
inotify_fd = inotify_init1(IN_CLOEXEC);
|
||||||
if (inotify_fd < 0) {
|
if (inotify_fd < 0) {
|
||||||
SYSERROR("Init inotify failed");
|
SYSERROR("Init inotify failed");
|
||||||
goto set_flag;
|
goto set_flag;
|
||||||
@ -1891,7 +1908,6 @@ static void *follow_thread_func(void *arg)
|
|||||||
ERROR("Handle inotify event failed");
|
ERROR("Handle inotify event failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
close(inotify_fd);
|
|
||||||
set_flag:
|
set_flag:
|
||||||
*(farg->finish) = true;
|
*(farg->finish) = true;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|||||||
@ -1255,46 +1255,6 @@ unlock:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static container_pid_t *parse_container_pid(const char *S)
|
|
||||||
{
|
|
||||||
int num;
|
|
||||||
container_pid_t *P = NULL;
|
|
||||||
|
|
||||||
if (S == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
P = util_common_calloc_s(sizeof(container_pid_t));
|
|
||||||
if (P == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
num = sscanf(S, "%d %Lu %d %Lu", &P->pid, &P->start_time, &P->ppid, &P->pstart_time);
|
|
||||||
if (num != 4) { // args num to read is 4
|
|
||||||
ERROR("Call sscanf error: %s", errno ? strerror(errno) : "");
|
|
||||||
free(P);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return P;
|
|
||||||
}
|
|
||||||
|
|
||||||
container_pid_t *container_read_pidfile(const char *pidfile)
|
|
||||||
{
|
|
||||||
if (pidfile == NULL) {
|
|
||||||
ERROR("Invalid input arguments");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
char sbuf[1024] = { 0 }; /* bufs for stat */
|
|
||||||
|
|
||||||
if ((util_file2str(pidfile, sbuf, sizeof(sbuf))) == -1) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parse_container_pid(sbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *container_get_env_nolock(const container_t *cont, const char *key)
|
char *container_get_env_nolock(const container_t *cont, const char *key)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
@ -1340,3 +1300,38 @@ char *container_get_env_nolock(const container_t *cont, const char *key)
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int container_read_proc(uint32_t pid, container_pid_t *pid_info)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
proc_t *proc = NULL;
|
||||||
|
proc_t *p_proc = NULL;
|
||||||
|
|
||||||
|
if (pid == 0) {
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
proc = util_get_process_proc_info((pid_t)pid);
|
||||||
|
if (proc == NULL) {
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_proc = util_get_process_proc_info((pid_t)proc->ppid);
|
||||||
|
if (p_proc == NULL) {
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_info->pid = proc->pid;
|
||||||
|
pid_info->start_time = proc->start_time;
|
||||||
|
pid_info->ppid = proc->ppid;
|
||||||
|
pid_info->pstart_time = p_proc->start_time;
|
||||||
|
|
||||||
|
out:
|
||||||
|
free(proc);
|
||||||
|
free(p_proc);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -106,11 +106,11 @@ int container_wait_stop_locking(container_t *cont, int timeout);
|
|||||||
void container_wait_rm_cond_broadcast(container_t *cont);
|
void container_wait_rm_cond_broadcast(container_t *cont);
|
||||||
int container_wait_rm_locking(container_t *cont, int timeout);
|
int container_wait_rm_locking(container_t *cont, int timeout);
|
||||||
|
|
||||||
container_pid_t *container_read_pidfile(const char *pidfile);
|
|
||||||
|
|
||||||
int save_host_config(const char *id, const char *rootpath, const char *hostconfigstr);
|
int save_host_config(const char *id, const char *rootpath, const char *hostconfigstr);
|
||||||
int save_config_v2_json(const char *id, const char *rootpath, const char *v2configstr);
|
int save_config_v2_json(const char *id, const char *rootpath, const char *v2configstr);
|
||||||
|
|
||||||
|
int container_read_proc(uint32_t pid, container_pid_t *pid_info);
|
||||||
|
|
||||||
#if defined(__cplusplus) || defined(c_plusplus)
|
#if defined(__cplusplus) || defined(c_plusplus)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -28,6 +28,7 @@
|
|||||||
#include "container_unix.h"
|
#include "container_unix.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "image.h"
|
#include "image.h"
|
||||||
|
#include "runtime.h"
|
||||||
|
|
||||||
#ifdef ENABLE_OCI_IMAGE
|
#ifdef ENABLE_OCI_IMAGE
|
||||||
#include "oci_images_store.h"
|
#include "oci_images_store.h"
|
||||||
@ -36,15 +37,17 @@
|
|||||||
#include "execution.h"
|
#include "execution.h"
|
||||||
|
|
||||||
/* restore supervisor */
|
/* restore supervisor */
|
||||||
static int restore_supervisor(const char *id, const char *runtime, const char *statepath)
|
static int restore_supervisor(const container_t *cont)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int nret = 0;
|
int nret = 0;
|
||||||
int exit_fifo_fd = -1;
|
int exit_fifo_fd = -1;
|
||||||
char container_state[PATH_MAX] = { 0 };
|
char container_state[PATH_MAX] = { 0 };
|
||||||
char pidfile[PATH_MAX] = { 0 };
|
|
||||||
char *exit_fifo = NULL;
|
char *exit_fifo = NULL;
|
||||||
container_pid_t *pid_info = NULL;
|
char *id = cont->common_config->id;
|
||||||
|
char *statepath = cont->state_path;
|
||||||
|
char *runtime = cont->runtime;
|
||||||
|
container_pid_t pid_info = { 0 };
|
||||||
|
|
||||||
nret = snprintf(container_state, sizeof(container_state), "%s/%s", statepath, id);
|
nret = snprintf(container_state, sizeof(container_state), "%s/%s", statepath, id);
|
||||||
if (nret < 0 || (size_t)nret >= sizeof(container_state)) {
|
if (nret < 0 || (size_t)nret >= sizeof(container_state)) {
|
||||||
@ -67,23 +70,12 @@ static int restore_supervisor(const char *id, const char *runtime, const char *s
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
nret = snprintf(pidfile, sizeof(pidfile), "%s/pid.file", container_state);
|
pid_info.pid = cont->state->state->pid;
|
||||||
if (nret < 0 || (size_t)nret >= sizeof(pidfile)) {
|
pid_info.ppid = cont->state->state->p_pid;
|
||||||
close(exit_fifo_fd);
|
pid_info.start_time = cont->state->state->start_time;
|
||||||
ERROR("Failed to sprintf pidfile");
|
pid_info.pstart_time = cont->state->state->p_start_time;
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_info = container_read_pidfile(pidfile);
|
if (supervisor_add_exit_monitor(exit_fifo_fd, &pid_info, id, runtime)) {
|
||||||
if (pid_info == NULL) {
|
|
||||||
close(exit_fifo_fd);
|
|
||||||
ERROR("Failed to get started container's pid info");
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (supervisor_add_exit_monitor(exit_fifo_fd, pid_info, id, runtime)) {
|
|
||||||
ERROR("Failed to add exit monitor to supervisor");
|
ERROR("Failed to add exit monitor to supervisor");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
@ -91,115 +83,31 @@ static int restore_supervisor(const char *id, const char *runtime, const char *s
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
free(exit_fifo);
|
free(exit_fifo);
|
||||||
free(pid_info);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static container_pid_t *container_read_proc(uint32_t pid)
|
|
||||||
{
|
|
||||||
container_pid_t *pid_info = NULL;
|
|
||||||
proc_t *proc_info = NULL;
|
|
||||||
|
|
||||||
if (pid == 0) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
proc_info = util_get_process_proc_info((pid_t)pid);
|
|
||||||
if (proc_info == NULL) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_info = util_common_calloc_s(sizeof(container_pid_t));
|
|
||||||
if (pid_info == NULL) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_info->pid = proc_info->pid;
|
|
||||||
pid_info->start_time = proc_info->start_time;
|
|
||||||
|
|
||||||
out:
|
|
||||||
free(proc_info);
|
|
||||||
return pid_info;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* post stopped container to gc */
|
/* post stopped container to gc */
|
||||||
static int post_stopped_container_to_gc(const char *id, const char *runtime, const char *statepath, uint32_t pid)
|
static int post_stopped_container_to_gc(const char *id, const char *runtime, const char *statepath, uint32_t pid)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int nret = 0;
|
container_pid_t pid_info = { 0 };
|
||||||
char container_state[PATH_MAX] = { 0 };
|
|
||||||
char pidfile[PATH_MAX] = { 0 };
|
|
||||||
container_pid_t *pid_info = NULL;
|
|
||||||
|
|
||||||
nret = snprintf(container_state, sizeof(container_state), "%s/%s", statepath, id);
|
(void)container_read_proc(pid, &pid_info);
|
||||||
if (nret < 0 || (size_t)nret >= sizeof(container_state)) {
|
|
||||||
ERROR("Failed to sprintf container state %s/%s", statepath, id);
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
nret = snprintf(pidfile, sizeof(pidfile), "%s/pid.file", container_state);
|
if (gc_add_container(id, runtime, &pid_info)) {
|
||||||
if (nret < 0 || (size_t)nret >= sizeof(pidfile)) {
|
|
||||||
ERROR("Failed to sprintf pidfile");
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_info = container_read_pidfile(pidfile);
|
|
||||||
if (pid_info == NULL) {
|
|
||||||
WARN("Failed to get started container's pid info, try to read proc filesystem");
|
|
||||||
pid_info = container_read_proc(pid);
|
|
||||||
if (pid_info == NULL) {
|
|
||||||
ERROR("Failed to get started container's pid info");
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gc_add_container(id, runtime, pid_info)) {
|
|
||||||
ERROR("Failed to post container %s to garbage collector", id);
|
ERROR("Failed to post container %s to garbage collector", id);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(pid_info);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static container_pid_t *load_running_container_pid_info(const container_t *cont)
|
|
||||||
{
|
|
||||||
int nret = 0;
|
|
||||||
const char *id = cont->common_config->id;
|
|
||||||
char pidfile[PATH_MAX] = { 0 };
|
|
||||||
char container_state[PATH_MAX] = { 0 };
|
|
||||||
container_pid_t *pid_info = NULL;
|
|
||||||
|
|
||||||
nret = snprintf(container_state, sizeof(container_state), "%s/%s", cont->state_path, id);
|
|
||||||
if (nret < 0 || (size_t)nret >= sizeof(container_state)) {
|
|
||||||
ERROR("Failed to sprintf container_state for container %s", id);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
nret = snprintf(pidfile, sizeof(pidfile), "%s/pid.file", container_state);
|
|
||||||
if (nret < 0 || (size_t)nret >= sizeof(pidfile)) {
|
|
||||||
ERROR("Failed to sprintf pidfile");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_info = container_read_pidfile(pidfile);
|
|
||||||
if (pid_info == NULL) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
return pid_info;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef ENABLE_OCI_IMAGE
|
#ifdef ENABLE_OCI_IMAGE
|
||||||
static void post_nonexist_image_containers(const container_t *cont, Container_Status status,
|
static void post_nonexist_image_containers(const container_t *cont, Container_Status status,
|
||||||
const struct engine_container_summary_info *info)
|
const struct engine_container_status_info *info)
|
||||||
{
|
{
|
||||||
int nret;
|
int nret;
|
||||||
const char *id = cont->common_config->id;
|
const char *id = cont->common_config->id;
|
||||||
@ -267,50 +175,31 @@ out:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void try_to_set_container_running(Container_Status status, const container_t *cont,
|
static bool is_same_process(const container_t *cont, const container_pid_t *pid_info)
|
||||||
const container_pid_t *pid_info)
|
|
||||||
{
|
{
|
||||||
int pid = 0;
|
if (pid_info->pid == cont->state->state->pid &&
|
||||||
|
pid_info->ppid == cont->state->state->p_pid &&
|
||||||
pid = state_get_pid(cont->state);
|
pid_info->start_time == cont->state->state->start_time &&
|
||||||
if (status != CONTAINER_STATUS_RUNNING || pid != pid_info->pid) {
|
pid_info->pstart_time == cont->state->state->p_start_time) {
|
||||||
state_set_running(cont->state, pid_info, true);
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void try_to_set_paused_container_pid(Container_Status status, const container_t *cont,
|
static void try_to_set_paused_container_pid(Container_Status status, const container_t *cont,
|
||||||
const container_pid_t *pid_info)
|
const container_pid_t *pid_info)
|
||||||
{
|
{
|
||||||
int pid = 0;
|
if (status != CONTAINER_STATUS_RUNNING || !is_same_process(cont, pid_info)) {
|
||||||
|
|
||||||
pid = state_get_pid(cont->state);
|
|
||||||
if (status != CONTAINER_STATUS_RUNNING || pid != pid_info->pid) {
|
|
||||||
state_set_running(cont->state, pid_info, false);
|
state_set_running(cont->state, pid_info, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int restore_check_id_valid(const char *id, const struct engine_container_summary_info *info,
|
static void try_to_set_container_running(Container_Status status, container_t *cont,
|
||||||
size_t container_num)
|
const container_pid_t *pid_info)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
if (status != CONTAINER_STATUS_RUNNING || !is_same_process(cont, pid_info)) {
|
||||||
|
state_set_running(cont->state, pid_info, true);
|
||||||
if (id == NULL) {
|
|
||||||
ERROR("Cannot get container id from config v2");
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < container_num; i++) {
|
|
||||||
if (strcmp(id, info[i].id) == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i >= container_num) {
|
|
||||||
ERROR("Container %s is not in runtime container array", id);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (int)i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int restore_stopped_container(Container_Status status, const container_t *cont, bool *need_save)
|
static int restore_stopped_container(Container_Status status, const container_t *cont, bool *need_save)
|
||||||
@ -333,16 +222,19 @@ static int restore_stopped_container(Container_Status status, const container_t
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int restore_running_container(Container_Status status, container_t *cont,
|
static int restore_running_container(Container_Status status, container_t *cont,
|
||||||
const struct engine_container_summary_info *info)
|
const struct engine_container_status_info *info)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
int nret = 0;
|
||||||
const char *id = cont->common_config->id;
|
const char *id = cont->common_config->id;
|
||||||
container_pid_t *pid_info = NULL;
|
container_pid_t pid_info = { 0 };
|
||||||
|
|
||||||
pid_info = load_running_container_pid_info(cont);
|
nret = container_read_proc(info->pid, &pid_info);
|
||||||
if (pid_info == NULL) {
|
if (nret == 0) {
|
||||||
ERROR("Failed to restore container:%s due to unable to read container pid info", id);
|
try_to_set_container_running(status, cont, &pid_info);
|
||||||
int nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, info->pid);
|
} else {
|
||||||
|
ERROR("Failed to restore container:%s due to unable to read container pid information", id);
|
||||||
|
nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, 0);
|
||||||
if (nret != 0) {
|
if (nret != 0) {
|
||||||
ERROR("Failed to post container %s to garbage"
|
ERROR("Failed to post container %s to garbage"
|
||||||
"collector, that may lost some resources"
|
"collector, that may lost some resources"
|
||||||
@ -350,29 +242,30 @@ static int restore_running_container(Container_Status status, container_t *cont,
|
|||||||
}
|
}
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
|
||||||
try_to_set_container_running(status, cont, pid_info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
container_reset_manually_stopped(cont);
|
container_reset_manually_stopped(cont);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(pid_info);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int restore_paused_container(Container_Status status, container_t *cont,
|
static int restore_paused_container(Container_Status status, container_t *cont,
|
||||||
const struct engine_container_summary_info *info)
|
const struct engine_container_status_info *info)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
int nret = 0;
|
||||||
const char *id = cont->common_config->id;
|
const char *id = cont->common_config->id;
|
||||||
container_pid_t *pid_info = NULL;
|
container_pid_t pid_info = { 0 };
|
||||||
|
|
||||||
state_set_paused(cont->state);
|
state_set_paused(cont->state);
|
||||||
|
|
||||||
pid_info = load_running_container_pid_info(cont);
|
nret = container_read_proc(info->pid, &pid_info);
|
||||||
if (pid_info == NULL) {
|
if (nret == 0) {
|
||||||
ERROR("Failed to restore container:%s due to unable to read container pid info", id);
|
try_to_set_paused_container_pid(status, cont, &pid_info);
|
||||||
int nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, info->pid);
|
} else {
|
||||||
|
ERROR("Failed to restore container:%s due to unable to read container pid information", id);
|
||||||
|
nret = post_stopped_container_to_gc(id, cont->runtime, cont->state_path, 0);
|
||||||
if (nret != 0) {
|
if (nret != 0) {
|
||||||
ERROR("Failed to post container %s to garbage"
|
ERROR("Failed to post container %s to garbage"
|
||||||
"collector, that may lost some resources"
|
"collector, that may lost some resources"
|
||||||
@ -380,27 +273,31 @@ static int restore_paused_container(Container_Status status, container_t *cont,
|
|||||||
}
|
}
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
} else {
|
|
||||||
try_to_set_paused_container_pid(status, cont, pid_info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
container_reset_manually_stopped(cont);
|
container_reset_manually_stopped(cont);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(pid_info);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* restore state */
|
/* restore state */
|
||||||
static int restore_state(container_t *cont, const struct engine_container_summary_info *info, size_t container_num)
|
static int restore_state(container_t *cont)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int c_index = 0;
|
int nret = 0;
|
||||||
bool need_save = false;
|
bool need_save = false;
|
||||||
const char *id = cont->common_config->id;
|
const char *id = cont->common_config->id;
|
||||||
|
const char *runtime = cont->runtime;
|
||||||
|
rt_status_params_t params = { 0 };
|
||||||
|
struct engine_container_status_info real_status = { 0 };
|
||||||
Container_Status status = CONTAINER_STATUS_UNKNOWN;
|
Container_Status status = CONTAINER_STATUS_UNKNOWN;
|
||||||
|
|
||||||
c_index = restore_check_id_valid(id, info, container_num);
|
params.rootpath = cont->root_path;
|
||||||
if (c_index < 0) {
|
|
||||||
|
nret = runtime_status(id, runtime, ¶ms, &real_status);
|
||||||
|
if (nret != 0) {
|
||||||
|
ERROR("Failed to restore container %s, due to can not load container status", id);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -411,29 +308,31 @@ static int restore_state(container_t *cont, const struct engine_container_summar
|
|||||||
#ifdef ENABLE_OCI_IMAGE
|
#ifdef ENABLE_OCI_IMAGE
|
||||||
if (check_container_image_exist(cont) != 0) {
|
if (check_container_image_exist(cont) != 0) {
|
||||||
ERROR("Failed to restore container:%s due to image not exist", id);
|
ERROR("Failed to restore container:%s due to image not exist", id);
|
||||||
post_nonexist_image_containers(cont, status, &info[c_index]);
|
post_nonexist_image_containers(cont, status, &real_status);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (info[c_index].status == ENGINE_CONTAINER_STATUS_STOPPED) {
|
if (real_status.status == ENGINE_CONTAINER_STATUS_STOPPED) {
|
||||||
ret = restore_stopped_container(status, cont, &need_save);
|
ret = restore_stopped_container(status, cont, &need_save);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else if (info[c_index].status == ENGINE_CONTAINER_STATUS_RUNNING) {
|
} else if (real_status.status == ENGINE_CONTAINER_STATUS_RUNNING) {
|
||||||
ret = restore_running_container(status, cont, &info[c_index]);
|
ret = restore_running_container(status, cont, &real_status);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else if (info[c_index].status == ENGINE_CONTAINER_STATUS_PAUSED) {
|
} else if (real_status.status == ENGINE_CONTAINER_STATUS_PAUSED) {
|
||||||
ret = restore_paused_container(status, cont, &info[c_index]);
|
ret = restore_paused_container(status, cont, &real_status);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ERROR("Container %s get invalid status %d", id, info[c_index].status);
|
ERROR("Container %s get invalid status %d", id, real_status.status);
|
||||||
|
ret = -1;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_removal_in_progress(cont->state)) {
|
if (is_removal_in_progress(cont->state)) {
|
||||||
@ -538,7 +437,7 @@ static void handle_restored_container()
|
|||||||
id = cont->common_config->id;
|
id = cont->common_config->id;
|
||||||
|
|
||||||
if (is_running(cont->state)) {
|
if (is_running(cont->state)) {
|
||||||
if (restore_supervisor(id, cont->runtime, cont->state_path)) {
|
if (restore_supervisor(cont)) {
|
||||||
ERROR("Failed to restore %s supervisor", id);
|
ERROR("Failed to restore %s supervisor", id);
|
||||||
}
|
}
|
||||||
init_health_monitor(id);
|
init_health_monitor(id);
|
||||||
@ -563,8 +462,7 @@ static void handle_restored_container()
|
|||||||
|
|
||||||
/* scan dir to add store */
|
/* scan dir to add store */
|
||||||
static void scan_dir_to_add_store(const char *runtime, const char *rootpath, const char *statepath,
|
static void scan_dir_to_add_store(const char *runtime, const char *rootpath, const char *statepath,
|
||||||
const size_t subdir_num, const char **subdir, const size_t container_num,
|
const size_t subdir_num, const char **subdir)
|
||||||
const struct engine_container_summary_info *info)
|
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
container_t *cont = NULL;
|
container_t *cont = NULL;
|
||||||
@ -579,7 +477,7 @@ static void scan_dir_to_add_store(const char *runtime, const char *rootpath, con
|
|||||||
goto error_load;
|
goto error_load;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (restore_state(cont, info, container_num)) {
|
if (restore_state(cont)) {
|
||||||
WARN("Failed to restore container %s state", subdir[i]);
|
WARN("Failed to restore container %s state", subdir[i]);
|
||||||
goto error_load;
|
goto error_load;
|
||||||
}
|
}
|
||||||
@ -609,83 +507,14 @@ error_load:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* query all containers info */
|
|
||||||
static int query_all_containers_info(const char *runtime, struct engine_container_summary_info **container_summary,
|
|
||||||
size_t *container_num)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
int container_nums = 0;
|
|
||||||
char *engine_path = NULL;
|
|
||||||
struct engine_operation *engine_ops = NULL;
|
|
||||||
|
|
||||||
if (runtime == NULL || container_summary == NULL || container_num == NULL) {
|
|
||||||
ERROR("invalid NULL param");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
engine_ops = engines_get_handler(runtime);
|
|
||||||
if (engine_ops == NULL || engine_ops->engine_get_all_containers_info_op == NULL) {
|
|
||||||
ERROR("Failed to get list op of engine %s", runtime);
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
engine_path = conf_get_routine_rootdir(runtime);
|
|
||||||
if (engine_path == NULL) {
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
container_nums = engine_ops->engine_get_all_containers_info_op(engine_path, container_summary);
|
|
||||||
if (container_nums < 0) {
|
|
||||||
ERROR("Engine %s get all containers info failed", runtime);
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
*container_num = (size_t)container_nums;
|
|
||||||
|
|
||||||
out:
|
|
||||||
free(engine_path);
|
|
||||||
if (engine_ops != NULL) {
|
|
||||||
engine_ops->engine_clear_errmsg_op();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* all containers info free */
|
|
||||||
static void all_containers_info_free(const char *runtime, struct engine_container_summary_info *container_summary,
|
|
||||||
size_t container_num)
|
|
||||||
{
|
|
||||||
struct engine_operation *engine_ops = NULL;
|
|
||||||
|
|
||||||
if (container_summary == NULL || runtime == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
engine_ops = engines_get_handler(runtime);
|
|
||||||
if (engine_ops == NULL || engine_ops->engine_free_all_containers_info_op == NULL) {
|
|
||||||
ERROR("Failed to get free op of engine %s", runtime);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
engine_ops->engine_free_all_containers_info_op(container_summary, (int)container_num);
|
|
||||||
|
|
||||||
if (engine_ops->engine_clear_errmsg_op != NULL) {
|
|
||||||
engine_ops->engine_clear_errmsg_op();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* restore container by runtime */
|
/* restore container by runtime */
|
||||||
static int restore_container_by_runtime(const char *runtime)
|
static int restore_container_by_runtime(const char *runtime)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *rootpath = NULL;
|
char *rootpath = NULL;
|
||||||
char *statepath = NULL;
|
char *statepath = NULL;
|
||||||
size_t container_num = 0;
|
|
||||||
size_t subdir_num = 0;
|
size_t subdir_num = 0;
|
||||||
char **subdir = NULL;
|
char **subdir = NULL;
|
||||||
struct engine_container_summary_info *info = NULL;
|
|
||||||
|
|
||||||
rootpath = conf_get_routine_rootdir(runtime);
|
rootpath = conf_get_routine_rootdir(runtime);
|
||||||
if (rootpath == NULL) {
|
if (rootpath == NULL) {
|
||||||
@ -712,17 +541,9 @@ static int restore_container_by_runtime(const char *runtime)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = query_all_containers_info(runtime, &info, &container_num);
|
scan_dir_to_add_store(runtime, rootpath, statepath, subdir_num, (const char **)subdir);
|
||||||
if (ret < 0) {
|
|
||||||
ERROR("query all containers info failed");
|
|
||||||
ret = -1;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
scan_dir_to_add_store(runtime, rootpath, statepath, subdir_num, (const char **)subdir, container_num, info);
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
all_containers_info_free(runtime, info, container_num);
|
|
||||||
free(rootpath);
|
free(rootpath);
|
||||||
free(statepath);
|
free(statepath);
|
||||||
util_free_array(subdir);
|
util_free_array(subdir);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user