提交 de229b28 编写于 作者: L lifeng68

refact: add modules api directory

Signed-off-by: Nlifeng68 <lifeng68@huawei.com>
上级 de7e6125
......@@ -91,7 +91,7 @@ install(FILES src/utils/cutils/error.h
DESTINATION include/isulad)
install(FILES src/daemon/modules/runtime/engines/engine.h
DESTINATION include/isulad)
install(FILES src/daemon/modules/image/image.h
install(FILES src/daemon/modules/api/image_api.h
DESTINATION include/isulad)
# install config files
......
......@@ -79,7 +79,7 @@ install -m 0644 ../src/client/connect/isula_connect.h %{buildroot}/%{_includedi
install -m 0644 ../src/utils/cutils/utils_timestamp.h %{buildroot}/%{_includedir}/isulad/utils_timestamp.h
install -m 0644 ../src/utils/cutils/error.h %{buildroot}/%{_includedir}/isulad/error.h
install -m 0644 ../src/daemon/modules/runtime/engines/engine.h %{buildroot}/%{_includedir}/isulad/engine.h
install -m 0644 ../src/daemon/modules/image/image.h %{buildroot}/%{_includedir}/isulad/image.h
install -m 0644 ../src/daemon/modules/api/image_api.h %{buildroot}/%{_includedir}/isulad/image_api.h
install -d $RPM_BUILD_ROOT/%{_sysconfdir}/isulad
install -m 0640 ../src/contrib/config/daemon.json %{buildroot}/%{_sysconfdir}/isulad/daemon.json
......
......@@ -44,17 +44,18 @@
#include "isula_libutils/log.h"
#include "utils.h"
#include "isulad_config.h"
#include "image.h"
#include "image_api.h"
#include "sysinfo.h"
#include "verify.h"
#include "service_common.h"
#include "callback.h"
#include "log_gather.h"
#include "containers_store.h"
#include "container_api.h"
#include "service_container.h"
#include "plugin.h"
#include "selinux_label.h"
#include "http.h"
#include "runtime.h"
#ifdef GRPC_CONNECTOR
#include "clibcni/api.h"
......
......@@ -24,7 +24,7 @@
#include "cxxutils.h"
#include "stoppable_thread.h"
#include "grpc_server_tls_auth.h"
#include "containers_store.h"
#include "container_api.h"
#include "isula_libutils/logger_json_file.h"
void protobuf_timestamp_to_grpc(const types_timestamp_t *timestamp, Timestamp *gtimestamp)
......@@ -139,7 +139,7 @@ bool grpc_copy_to_container_read_function(void *reader, void *data)
{
struct isulad_copy_to_container_data *copy = (struct isulad_copy_to_container_data *)data;
ServerReaderWriter<CopyToContainerResponse, CopyToContainerRequest> *stream =
(ServerReaderWriter<CopyToContainerResponse, CopyToContainerRequest> *)reader;
(ServerReaderWriter<CopyToContainerResponse, CopyToContainerRequest> *)reader;
CopyToContainerRequest gcopy;
if (!stream->Read(&gcopy)) {
return false;
......@@ -663,8 +663,8 @@ class RemoteExecReceiveFromClientTask : public StoppableThread {
public:
RemoteExecReceiveFromClientTask() = default;
RemoteExecReceiveFromClientTask(ServerReaderWriter<RemoteExecResponse, RemoteExecRequest> *stream, int read_pipe_fd)
: m_stream(stream)
, m_read_pipe_fd(read_pipe_fd)
: m_stream(stream)
, m_read_pipe_fd(read_pipe_fd)
{
}
~RemoteExecReceiveFromClientTask() = default;
......@@ -733,9 +733,7 @@ Status ContainerServiceImpl::RemoteExec(ServerContext *context,
receive_task.SetStream(stream);
receive_task.SetReadPipeFd(read_pipe_fd[1]);
command_writer = std::thread([&]() {
receive_task.run();
});
command_writer = std::thread([&]() { receive_task.run(); });
}
struct io_write_wrapper StdoutstringWriter = { 0 };
......
......@@ -30,7 +30,7 @@
#include "path.h"
#include "naming.h"
#include "isula_libutils/parse_common.h"
#include "image.h"
#include "image_api.h"
#include "cri_runtime_service.h"
#include "request_cache.h"
......@@ -142,11 +142,10 @@ void CRIRuntimeServiceImpl::GetContainerTimeStamps(container_inspect *inspect, i
}
container_config *CRIRuntimeServiceImpl::GenerateCreateContainerCustomConfig(
const std::string &realPodSandboxID, const runtime::v1alpha2::ContainerConfig &containerConfig,
const runtime::v1alpha2::PodSandboxConfig &podSandboxConfig, Errors &error)
const std::string &realPodSandboxID, const runtime::v1alpha2::ContainerConfig &containerConfig,
const runtime::v1alpha2::PodSandboxConfig &podSandboxConfig, Errors &error)
{
container_config *custom_config =
(container_config *)util_common_calloc_s(sizeof(container_config));
container_config *custom_config = (container_config *)util_common_calloc_s(sizeof(container_config));
if (custom_config == nullptr) {
error.SetError("Out of memory");
goto cleanup;
......@@ -212,7 +211,7 @@ cleanup:
}
int CRIRuntimeServiceImpl::PackCreateContainerHostConfigDevices(
const runtime::v1alpha2::ContainerConfig &containerConfig, host_config *hostconfig, Errors &error)
const runtime::v1alpha2::ContainerConfig &containerConfig, host_config *hostconfig, Errors &error)
{
int ret { 0 };
......@@ -232,7 +231,7 @@ int CRIRuntimeServiceImpl::PackCreateContainerHostConfigDevices(
}
for (int i = 0; i < containerConfig.devices_size(); i++) {
hostconfig->devices[i] =
(host_config_devices_element *)util_common_calloc_s(sizeof(host_config_devices_element));
(host_config_devices_element *)util_common_calloc_s(sizeof(host_config_devices_element));
if (hostconfig->devices[i] == nullptr) {
ret = -1;
goto out;
......@@ -247,7 +246,7 @@ out:
}
int CRIRuntimeServiceImpl::PackCreateContainerHostConfigSecurityContext(
const runtime::v1alpha2::ContainerConfig &containerConfig, host_config *hostconfig, Errors &error)
const runtime::v1alpha2::ContainerConfig &containerConfig, host_config *hostconfig, Errors &error)
{
if (!containerConfig.linux().has_security_context()) {
return 0;
......@@ -256,8 +255,7 @@ int CRIRuntimeServiceImpl::PackCreateContainerHostConfigSecurityContext(
// New version '=' , old version ':', iSulad cri is based on v18.09, so iSulad cri use new version separator
const char securityOptSep { '=' };
std::vector<std::string> securityOpts = CRIHelpers::GetSecurityOpts(
containerConfig.linux().security_context().seccomp_profile_path(),
securityOptSep, error);
containerConfig.linux().security_context().seccomp_profile_path(), securityOptSep, error);
if (error.NotEmpty()) {
error.Errorf("failed to generate security options for container %s", containerConfig.metadata().name().c_str());
return -1;
......@@ -284,8 +282,9 @@ int CRIRuntimeServiceImpl::PackCreateContainerHostConfigSecurityContext(
return 0;
}
host_config *CRIRuntimeServiceImpl::GenerateCreateContainerHostConfig(
const runtime::v1alpha2::ContainerConfig &containerConfig, Errors &error)
host_config *
CRIRuntimeServiceImpl::GenerateCreateContainerHostConfig(const runtime::v1alpha2::ContainerConfig &containerConfig,
Errors &error)
{
host_config *hostconfig = (host_config *)util_common_calloc_s(sizeof(host_config));
if (hostconfig == nullptr) {
......@@ -323,9 +322,11 @@ cleanup:
return nullptr;
}
container_create_request *CRIRuntimeServiceImpl::GenerateCreateContainerRequest(
const std::string &realPodSandboxID, const runtime::v1alpha2::ContainerConfig &containerConfig,
const runtime::v1alpha2::PodSandboxConfig &podSandboxConfig, const std::string &podSandboxRuntime, Errors &error)
container_create_request *
CRIRuntimeServiceImpl::GenerateCreateContainerRequest(const std::string &realPodSandboxID,
const runtime::v1alpha2::ContainerConfig &containerConfig,
const runtime::v1alpha2::PodSandboxConfig &podSandboxConfig,
const std::string &podSandboxRuntime, Errors &error)
{
struct parser_context ctx {
OPT_GEN_SIMPLIFY, 0
......@@ -417,7 +418,8 @@ std::string CRIRuntimeServiceImpl::CreateContainer(const std::string &podSandbox
podSandboxRuntime = GetContainerOrSandboxRuntime(realPodSandboxID, error);
request = GenerateCreateContainerRequest(realPodSandboxID, containerConfig, podSandboxConfig, podSandboxRuntime, error);
request = GenerateCreateContainerRequest(realPodSandboxID, containerConfig, podSandboxConfig, podSandboxRuntime,
error);
if (error.NotEmpty()) {
error.SetError("Failed to generate create container request");
goto cleanup;
......@@ -508,8 +510,8 @@ void CRIRuntimeServiceImpl::GetContainerLogPath(const std::string &containerID,
if (info->config != nullptr && info->config->labels) {
for (size_t i = 0; i < info->config->labels->len; i++) {
if (strcmp(info->config->labels->keys[i],
CRIHelpers::Constants::CONTAINER_LOGPATH_LABEL_KEY.c_str()) == 0 &&
if (strcmp(info->config->labels->keys[i], CRIHelpers::Constants::CONTAINER_LOGPATH_LABEL_KEY.c_str()) ==
0 &&
strcmp(info->config->labels->values[i], "") != 0) {
*path = util_strdup_s(info->config->labels->values[i]);
break;
......@@ -687,7 +689,7 @@ void CRIRuntimeServiceImpl::RemoveContainer(const std::string &containerID, Erro
container_delete_response *response { nullptr };
container_delete_request *request =
(container_delete_request *)util_common_calloc_s(sizeof(container_delete_request));
(container_delete_request *)util_common_calloc_s(sizeof(container_delete_request));
if (request == nullptr) {
error.SetError("Out of memory");
goto cleanup;
......@@ -764,7 +766,7 @@ void CRIRuntimeServiceImpl::ListContainersToGRPC(container_list_response *respon
}
runtime::v1alpha2::ContainerState state =
CRIHelpers::ContainerStatusToRuntime(Container_Status(response->containers[i]->status));
CRIHelpers::ContainerStatusToRuntime(Container_Status(response->containers[i]->status));
container->set_state(state);
pods->push_back(move(container));
......@@ -856,10 +858,9 @@ cleanup:
free_container_list_response(response);
}
void CRIRuntimeServiceImpl::PackContainerStatsAttributes(
const char *id,
std::unique_ptr<runtime::v1alpha2::ContainerStats> &container,
Errors &error)
void CRIRuntimeServiceImpl::PackContainerStatsAttributes(const char *id,
std::unique_ptr<runtime::v1alpha2::ContainerStats> &container,
Errors &error)
{
if (id == nullptr) {
return;
......@@ -873,7 +874,7 @@ void CRIRuntimeServiceImpl::PackContainerStatsAttributes(
if (status->has_metadata()) {
std::unique_ptr<runtime::v1alpha2::ContainerMetadata> metadata(
new (std::nothrow) runtime::v1alpha2::ContainerMetadata(status->metadata()));
new (std::nothrow) runtime::v1alpha2::ContainerMetadata(status->metadata()));
if (metadata == nullptr) {
error.SetError("Out of memory");
ERROR("Out of memory");
......@@ -903,21 +904,20 @@ static void SetFsUsage(const imagetool_fs_info *fs_usage, std::unique_ptr<runtim
container->mutable_writable_layer()->mutable_used_bytes()->set_value(0);
} else {
container->mutable_writable_layer()->mutable_used_bytes()->set_value(
fs_usage->image_filesystems[0]->used_bytes->value);
fs_usage->image_filesystems[0]->used_bytes->value);
}
if (fs_usage->image_filesystems[0]->inodes_used == nullptr) {
container->mutable_writable_layer()->mutable_inodes_used()->set_value(0);
} else {
container->mutable_writable_layer()->mutable_inodes_used()->set_value(
fs_usage->image_filesystems[0]->inodes_used->value);
fs_usage->image_filesystems[0]->inodes_used->value);
}
}
void CRIRuntimeServiceImpl::PackContainerStatsFilesystemUsage(
const char *id, const char *image_type,
std::unique_ptr<runtime::v1alpha2::ContainerStats> &container,
Errors &error)
const char *id, const char *image_type, std::unique_ptr<runtime::v1alpha2::ContainerStats> &container,
Errors &error)
{
if (id == nullptr || image_type == nullptr) {
return;
......@@ -933,8 +933,8 @@ void CRIRuntimeServiceImpl::PackContainerStatsFilesystemUsage(
}
void CRIRuntimeServiceImpl::ContainerStatsToGRPC(
container_stats_response *response,
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *containerstats, Errors &error)
container_stats_response *response,
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *containerstats, Errors &error)
{
if (response == nullptr) {
return;
......@@ -952,8 +952,8 @@ void CRIRuntimeServiceImpl::ContainerStatsToGRPC(
if (error.NotEmpty()) {
return;
}
PackContainerStatsFilesystemUsage(response->container_stats[i]->id,
response->container_stats[i]->image_type, container, error);
PackContainerStatsFilesystemUsage(response->container_stats[i]->id, response->container_stats[i]->image_type,
container, error);
if (response->container_stats[i]->mem_used) {
container->mutable_memory()->mutable_working_set_bytes()->set_value(response->container_stats[i]->mem_used);
......@@ -961,7 +961,7 @@ void CRIRuntimeServiceImpl::ContainerStatsToGRPC(
if (response->container_stats[i]->cpu_use_nanos) {
container->mutable_cpu()->mutable_usage_core_nano_seconds()->set_value(
response->container_stats[i]->cpu_use_nanos);
response->container_stats[i]->cpu_use_nanos);
container->mutable_cpu()->set_timestamp((int64_t)(response->container_stats[i]->cpu_system_use));
}
......@@ -1007,8 +1007,8 @@ int CRIRuntimeServiceImpl::PackContainerStatsFilter(const runtime::v1alpha2::Con
}
void CRIRuntimeServiceImpl::ListContainerStats(
const runtime::v1alpha2::ContainerStatsFilter *filter,
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *containerstats, Errors &error)
const runtime::v1alpha2::ContainerStatsFilter *filter,
std::vector<std::unique_ptr<runtime::v1alpha2::ContainerStats>> *containerstats, Errors &error)
{
if (m_cb == nullptr || m_cb->container.stats == nullptr) {
error.SetError("Unimplemented callback");
......@@ -1187,8 +1187,8 @@ void CRIRuntimeServiceImpl::ContainerStatusToGRPC(container_inspect *inspect,
ConvertMountsToStatus(inspect, contStatus);
}
std::unique_ptr<runtime::v1alpha2::ContainerStatus> CRIRuntimeServiceImpl::ContainerStatus(
const std::string &containerID, Errors &error)
std::unique_ptr<runtime::v1alpha2::ContainerStatus>
CRIRuntimeServiceImpl::ContainerStatus(const std::string &containerID, Errors &error)
{
if (containerID.empty()) {
error.SetError("Empty pod sandbox id");
......@@ -1533,7 +1533,7 @@ container_inspect *CRIRuntimeServiceImpl::InspectContainer(const std::string &co
}
container_inspect_request *req =
(container_inspect_request *)util_common_calloc_s(sizeof(container_inspect_request));
(container_inspect_request *)util_common_calloc_s(sizeof(container_inspect_request));
if (req == nullptr) {
err.SetError("Out of memory");
goto cleanup;
......
......@@ -26,9 +26,10 @@
#include "isula_libutils/docker_seccomp.h"
#include "isula_libutils/cri_pod_network.h"
#include "checkpoint_handler.h"
#include "image.h"
#include "image_api.h"
namespace CRIHelpers {
namespace CRIHelpers
{
class Constants {
public:
static const std::string DEFAULT_RUNTIME_NAME;
......
......@@ -20,7 +20,7 @@
#include <vector>
#include <memory>
#include "cri_services.h"
#include "image.h"
#include "image_api.h"
class CRIImageServiceImpl : public cri::ImageManagerService {
public:
......@@ -51,8 +51,7 @@ private:
void list_images_to_grpc(im_list_response *response, std::vector<std::unique_ptr<runtime::v1alpha2::Image>> *images,
Errors &error);
int status_request_from_grpc(const runtime::v1alpha2::ImageSpec *image, im_status_request **request,
Errors &error);
int status_request_from_grpc(const runtime::v1alpha2::ImageSpec *image, im_status_request **request, Errors &error);
std::unique_ptr<runtime::v1alpha2::Image> status_image_to_grpc(im_status_response *response, Errors &error);
......
......@@ -33,11 +33,11 @@
#include "io_wrapper.h"
#include "isulad_config.h"
#include "config.h"
#include "image.h"
#include "image_api.h"
#include "execution.h"
#include "verify.h"
#include "isula_libutils/container_inspect.h"
#include "containers_store.h"
#include "container_api.h"
#include "execution_extend.h"
#include "execution_information.h"
#include "execution_stream.h"
......
......@@ -34,11 +34,11 @@
#include "config.h"
#include "specs.h"
#include "verify.h"
#include "containers_store.h"
#include "container_api.h"
#include "execution_network.h"
#include "runtime.h"
#include "plugin.h"
#include "image.h"
#include "image_api.h"
#include "utils.h"
#include "error.h"
#include "constants.h"
......@@ -695,7 +695,7 @@ static host_config_host_channel *dup_host_channel(const host_config_host_channel
dup_channel->path_on_host = channel->path_on_host != NULL ? util_strdup_s(channel->path_on_host) : NULL;
dup_channel->path_in_container = channel->path_in_container != NULL ? util_strdup_s(channel->path_in_container) :
NULL;
NULL;
dup_channel->permissions = channel->permissions != NULL ? util_strdup_s(channel->permissions) : NULL;
dup_channel->size = channel->size;
......
......@@ -32,10 +32,10 @@
#include "io_wrapper.h"
#include "isulad_config.h"
#include "config.h"
#include "image.h"
#include "image_api.h"
#include "verify.h"
#include "isula_libutils/container_inspect.h"
#include "containers_store.h"
#include "container_api.h"
#include "service_container.h"
#include "sysinfo.h"
#include "specs.h"
......@@ -964,7 +964,7 @@ static int update_host_config_check(container_t *cont, host_config *hostconfig)
if (is_removal_in_progress(cont->state) || is_dead(cont->state)) {
ERROR("Container is marked for removal and cannot be \"update\".");
isulad_set_error_message(
"Cannot update container %s: Container is marked for removal and cannot be \"update\".", id);
"Cannot update container %s: Container is marked for removal and cannot be \"update\".", id);
ret = -1;
goto out;
}
......
......@@ -30,14 +30,13 @@
#include "io_wrapper.h"
#include "isulad_config.h"
#include "config.h"
#include "image.h"
#include "image_api.h"
#include "execution.h"
#include "isula_libutils/container_inspect.h"
#include "containers_store.h"
#include "container_api.h"
#include "execution_information.h"
#include "sysinfo.h"
#include "container_state.h"
#include "runtime.h"
#include "list.h"
#include "utils.h"
......@@ -933,7 +932,7 @@ static int dup_health_check_config(const container_config *src, container_inspec
dest->health_check->start_period = timeout_with_default(src->healthcheck->start_period, DEFAULT_START_PERIOD);
dest->health_check->timeout = timeout_with_default(src->healthcheck->timeout, DEFAULT_PROBE_TIMEOUT);
dest->health_check->retries = src->healthcheck->retries != 0 ? src->healthcheck->retries :
DEFAULT_PROBE_RETRIES;
DEFAULT_PROBE_RETRIES;
dest->health_check->exit_on_unhealthy = src->healthcheck->exit_on_unhealthy;
}
......@@ -1142,9 +1141,9 @@ static int pack_inspect_container_state(const container_t *cont, container_inspe
inspect->state->exit_code = cont_state->exit_code;
inspect->state->started_at = cont_state->started_at ? util_strdup_s(cont_state->started_at) :
util_strdup_s(defaultContainerTime);
util_strdup_s(defaultContainerTime);
inspect->state->finished_at = cont_state->finished_at ? util_strdup_s(cont_state->finished_at) :
util_strdup_s(defaultContainerTime);
util_strdup_s(defaultContainerTime);
inspect->state->error = cont->state->state->error ? util_strdup_s(cont->state->state->error) : NULL;
inspect->restart_count = cont->common_config->restart_count;
......
......@@ -32,7 +32,7 @@
#include "utils.h"
#include "isulad_config.h"
#include "config.h"
#include "containers_store.h"
#include "container_api.h"
#include "namespace.h"
#include "path.h"
#include "selinux_label.h"
......@@ -429,9 +429,7 @@ static bool is_need_add(const char *dns_search, const json_map_string_bool *dns_
return need_to_add;
}
static int generate_new_search(const host_config *host_spec,
json_map_string_bool *dns_search_map,
char **content,
static int generate_new_search(const host_config *host_spec, json_map_string_bool *dns_search_map, char **content,
bool search)
{
char *tmp = NULL;
......@@ -464,9 +462,7 @@ static int generate_new_search(const host_config *host_spec,
return 0;
}
static int generate_new_options(const host_config *host_spec,
json_map_string_bool *dns_options_map,
char **content,
static int generate_new_options(const host_config *host_spec, json_map_string_bool *dns_options_map, char **content,
bool options)
{
char *tmp = NULL;
......@@ -532,8 +528,8 @@ error_out:
return ret;
}
static int resolve_handle_content(const char *pline, const host_config *host_spec,
char **content, json_map_string_bool *dns_map, bool *search, bool *options)
static int resolve_handle_content(const char *pline, const host_config *host_spec, char **content,
json_map_string_bool *dns_map, bool *search, bool *options)
{
int ret = 0;
char *tmp = NULL;
......@@ -688,10 +684,7 @@ static int chown_network(const char *user_remap, const char *rootfs, const char
}
if (chown(file_path, host_uid, host_gid) != 0) {
SYSERROR("Failed to chown network file '%s' to %u:%u", filename, host_uid, host_gid);
isulad_set_error_message("Failed to chown network file '%s' to %u:%u: %s",
filename,
host_uid,
host_gid,
isulad_set_error_message("Failed to chown network file '%s' to %u:%u: %s", filename, host_uid, host_gid,
strerror(errno));
ret = -1;
goto out;
......@@ -706,7 +699,7 @@ static int merge_network_for_universal_container(const host_config *host_spec, c
{
int ret = 0;
int nret = 0;
char root_path[PATH_MAX] = {0x00};
char root_path[PATH_MAX] = { 0x00 };
if (runtime_root == NULL || id == NULL) {
ERROR("empty runtime root or id");
......@@ -758,8 +751,8 @@ static int merge_network_for_syscontainer(const host_config *host_spec, const ch
return 0;
}
int merge_network(const host_config *host_spec, const char *rootfs, const char *runtime_root,
const char *id, const char *hostname)
int merge_network(const host_config *host_spec, const char *rootfs, const char *runtime_root, const char *id,
const char *hostname)
{
int ret = 0;
......@@ -883,7 +876,6 @@ static int create_default_hostname(const char *id, const char *rootpath, bool sh
goto out;
}
if (util_write_file(file_path, hostname_content, strlen(hostname_content), NETWORK_MOUNT_FILE_MODE) != 0) {
ERROR("Failed to create default hostname");
ret = -1;
......@@ -924,7 +916,7 @@ static int write_default_hosts(const char *file_path, const char *hostname)
}
ret = snprintf(content, content_len, "%s%s%s\n", default_config, loop_ip, hostname);
if (ret < 0 || (size_t)ret >= content_len) {
if (ret < 0 || (size_t)ret >= content_len) {
ERROR("Failed to generate default hosts");
ret = -1;
goto out_free;
......@@ -941,7 +933,6 @@ out_free:
return ret;
}
static int create_default_hosts(const char *id, const char *rootpath, bool share_host,
container_config_v2_common_config *v2_spec)
{
......@@ -975,7 +966,8 @@ out:
static int write_default_resolve(const char *file_path)
{
const char *default_ipv4_dns = "\nnameserver 8.8.8.8\nnameserver 8.8.4.4\n";;
const char *default_ipv4_dns = "\nnameserver 8.8.8.8\nnameserver 8.8.4.4\n";
;
return util_write_file(file_path, default_ipv4_dns, strlen(default_ipv4_dns), NETWORK_MOUNT_FILE_MODE);
}
......@@ -1010,8 +1002,6 @@ out:
return ret;
}
int init_container_network_confs(const char *id, const char *rootpath, const host_config *hc,
container_config_v2_common_config *v2_spec)
{
......@@ -1044,5 +1034,3 @@ int init_container_network_confs(const char *id, const char *rootpath, const hos
out:
return ret;
}
......@@ -33,12 +33,11 @@
#include "io_wrapper.h"
#include "isulad_config.h"
#include "config.h"
#include "image.h"
#include "image_api.h"
#include "path.h"
#include "isulad_tar.h"
#include "isula_libutils/container_inspect.h"
#include "containers_store.h"
#include "container_state.h"
#include "container_api.h"
#include "error.h"
#include "isula_libutils/logger_json_file.h"
#include "constants.h"
......@@ -302,8 +301,7 @@ err_out:
return NULL;
}
static int exec_container(container_t *cont, const char *runtime, char * const console_fifos[],
defs_process_user *puser,
static int exec_container(container_t *cont, const char *runtime, char *const console_fifos[], defs_process_user *puser,
const container_exec_request *request, int *exit_code)
{
int ret = 0;
......@@ -601,7 +599,7 @@ static int container_exec_cb(const container_exec_request *request, container_ex
goto pack_response;
}
(void)isulad_monitor_send_container_event(id, EXEC_START, -1, 0, exec_command, NULL);
if (exec_container(cont, cont->runtime, (char * const *)fifos, puser, request, &exit_code)) {
if (exec_container(cont, cont->runtime, (char *const *)fifos, puser, request, &exit_code)) {
cc = ISULAD_ERR_EXEC;
goto pack_response;
}
......
......@@ -33,12 +33,11 @@
#include "console.h"
#include "isulad_config.h"
#include "config.h"
#include "image.h"
#include "image_api.h"
#include "path.h"
#include "isulad_tar.h"
#include "isula_libutils/container_inspect.h"
#include "containers_store.h"
#include "container_state.h"
#include "container_api.h"
#include "error.h"
#include "isula_libutils/logger_json_file.h"
#include "constants.h"
......
......@@ -17,7 +17,7 @@
#include <unistd.h>
#include "isula_libutils/log.h"
#include "containers_store.h"
#include "container_api.h"
#include "isula_libutils/timestamp.h"
#include "list.h"
#include "filters.h"
......
......@@ -29,7 +29,7 @@
#include "error.h"
#include "libisulad.h"
#include "isula_libutils/log.h"
#include "image.h"
#include "image_api.h"
#include "isulad_config.h"
#include "mediatype.h"
#include "filters.h"
......@@ -529,7 +529,7 @@ out:
return (ret < 0) ? ECOMMON : ret;
}
static bool valid_repo_tags(char * const * const repo_tags, size_t repo_index)
static bool valid_repo_tags(char *const *const repo_tags, size_t repo_index)
{
if (repo_tags != NULL && repo_tags[repo_index] != NULL) {
return true;
......
......@@ -10,6 +10,7 @@ add_subdirectory(log)
add_subdirectory(events)
add_subdirectory(events_sender)
add_subdirectory(service)
add_subdirectory(api)
set(local_modules_srcs
${modules_top_srcs}
......@@ -35,6 +36,7 @@ set(local_modules_incs
${EVENTS_INCS}
${EVENTS_SENDER_INCS}
${SERVICE_INCS}
${MODULES_API_INCS}
)
set(MODULES_SRCS
......
# get current directory sources files
set(MODULES_API_SRCS
${CMAKE_CURRENT_SOURCE_DIR}
PARENT_SCOPE
)
set(MODULES_API_INCS
${CMAKE_CURRENT_SOURCE_DIR}
PARENT_SCOPE
)
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
* iSulad licensed under the Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
* PURPOSE.
* See the Mulan PSL v2 for more details.
* Author: lifeng
* Create: 2020-06-22
* Description: provide container api definition
******************************************************************************/
#ifndef __ISULAD_CONTAINER_API_H__
#define __ISULAD_CONTAINER_API_H__
#include <pthread.h>
#include "libisulad.h"
#include "util_atomic.h"
#include "isula_libutils/container_config_v2.h"
#include "isula_libutils/host_config.h"
#include "isula_libutils/oci_runtime_spec.h"
#include "linked_list.h"
#include "map.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
#define MAX_OUTPUT_LEN 4096
#define DEFAULT_PROBE_INTERVAL (30 * Time_Second)
#define DEFAULT_PROBE_TIMEOUT (30 * Time_Second)
#define DEFAULT_START_PERIOD (0 * Time_Second)
#define DEFAULT_PROBE_RETRIES 3
#define MAX_LOG_ENTRIES 5
#define EXIT_STATUS_HEALTHY 0
#define NO_HEALTH_CHECK "none"
#define HEALTH_STARTING "starting"
#define HEALTHY "healthy"
#define UNHEALTHY "unhealthy"
typedef enum { MONITOR_IDLE = 0, MONITOR_INTERVAL = 1, MONITOR_STOP = 2 } health_check_monitor_status_t;
typedef struct health_check_manager {
pthread_mutex_t mutex;
bool init_mutex;
health_check_monitor_status_t monitor_status;
} health_check_manager_t;
typedef struct _container_state_t_ {
pthread_mutex_t mutex;
container_config_v2_state *state;
} container_state_t;
typedef struct _restart_manager_t {
pthread_mutex_t mutex;
bool init_mutex;
pthread_cond_t wait_cancel_con;
bool init_wait_cancel_con;
uint64_t refcnt;
host_config_restart_policy *policy;
int failure_count;
int64_t timeout;
bool active;
bool canceled;
} restart_manager_t;
typedef struct _container_events_handler_t {
pthread_mutex_t mutex;
bool init_mutex;
struct linked_list events_list;
bool has_handler;
} container_events_handler_t;
typedef struct _container_t_ {
pthread_mutex_t mutex;
bool init_mutex;
pthread_cond_t wait_stop_con;
bool init_wait_stop_con;
pthread_cond_t wait_rm_con;
bool init_wait_rm_con;
uint64_t refcnt;
char *runtime;
char *root_path;
char *state_path;
char *image_id;
container_config_v2_common_config *common_config;
container_state_t *state;
host_config *hostconfig;
restart_manager_t *rm;
container_events_handler_t *handler;
health_check_manager_t *health_check;
/* log configs of container */
char *log_driver;
char *log_path;
int log_rotate;
int64_t log_maxsize;
} container_t;
int containers_store_init(void);
bool containers_store_add(const char *id, container_t *cont);
container_t *containers_store_get(const char *id_or_name);
container_t *containers_store_get_by_prefix(const char *prefix);
bool containers_store_remove(const char *id);
int containers_store_list(container_t ***out, size_t *size);
char **containers_store_list_ids(void);
/* name indexs */
int name_index_init(void);
bool name_index_remove(const char *name);
char *name_index_get(const char *name);
bool name_index_add(const char *name, const char *id);
map_t *name_index_get_all(void);
bool name_index_rename(const char *new_name, const char *old_name, const char *id);
void container_refinc(container_t *cont);
void container_unref(container_t *cont);
container_t *container_new(const char *runtime, const char *rootpath, const char *statepath, const char *image_id,
host_config **hostconfig, container_config_v2_common_config **common_config);
container_t *container_load(const char *runtime, const char *rootpath, const char *statepath, const char *id);
int container_to_disk(const container_t *cont);
int container_to_disk_locking(container_t *cont);
void container_lock(container_t *cont);
int container_timedlock(container_t *cont, int timeout);
void container_unlock(container_t *cont);
char *container_get_env_nolock(const container_t *cont, const char *key);
int v2_spec_merge_contaner_spec(container_config_v2_common_config *v2_spec);
char *container_get_command(const container_t *cont);
char *container_get_image(const container_t *cont);
int container_exit_on_next(container_t *cont);
bool reset_restart_manager(container_t *cont, bool reset_count);
void container_update_restart_manager(container_t *cont, const host_config_restart_policy *policy);
void container_wait_stop_cond_broadcast(container_t *cont);
int container_wait_stop(container_t *cont, int timeout);
int container_wait_stop_locking(container_t *cont, int timeout);
void container_wait_rm_cond_broadcast(container_t *cont);
int container_wait_rm_locking(container_t *cont, int timeout);
bool has_mount_for(container_t *cont, const char *mpath);
container_config_v2_state *state_get_info(container_state_t *s);
void update_start_and_finish_time(container_state_t *s, const char *finish_at);
void state_set_starting(container_state_t *s);
void state_reset_starting(container_state_t *s);
void state_set_running(container_state_t *s, const container_pid_t *pid_info, bool initial);
void state_set_stopped(container_state_t *s, int exit_code);
void state_set_restarting(container_state_t *s, int exit_code);
void state_set_paused(container_state_t *s);
void state_reset_paused(container_state_t *s);
void state_set_dead(container_state_t *s);
// state_set_removal_in_progress sets the container state as being removed.
// It returns true if the container was already in that state
bool state_set_removal_in_progress(container_state_t *s);
void state_reset_removal_in_progress(container_state_t *s);
const char *state_to_string(Container_Status cs);
Container_Status state_judge_status(const container_config_v2_state *state);
Container_Status state_get_status(container_state_t *s);
bool is_running(container_state_t *s);
bool is_restarting(container_state_t *s);
bool is_removal_in_progress(container_state_t *s);
bool is_paused(container_state_t *s);
uint32_t state_get_exitcode(container_state_t *s);
int state_get_pid(container_state_t *s);
bool is_dead(container_state_t *s);
void container_state_set_error(container_state_t *s, const char *err);
char *state_get_started_at(container_state_t *s);
bool is_valid_state_string(const char *state);
int dup_health_check_status(defs_health **dst, const defs_health *src);
void update_health_monitor(const char *container_id);
int64_t timeout_with_default(int64_t configured_value, int64_t default_value);
extern int supervisor_add_exit_monitor(int fd, const container_pid_t *pid_info, const char *name, const char *runtime);
extern char *exit_fifo_create(const char *cont_state_path);
extern int exit_fifo_open(const char *cont_exit_fifo);
void init_health_monitor(const char *id);
void stop_health_checks(const char *container_id);
bool container_in_gc_progress(const char *id);
int container_module_init(char **msg);
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#endif /* __ISULAD_CONTAINER_API_H__ */
......@@ -26,9 +26,11 @@
#include "isulad_config.h"
#include "container_events_handler.h"
#include "utils.h"
#include "containers_store.h"
#include "container_api.h"
#include "service_container.h"
#include "plugin.h"
#include "restartmanager.h"
#include "health_check.h"
/* events handler lock */
static void events_handler_lock(container_events_handler_t *handler)
......@@ -57,7 +59,7 @@ void container_events_handler_free(container_events_handler_t *handler)
return;
}
linked_list_for_each_safe(it, &(handler->events_list), next) {
linked_list_for_each_safe (it, &(handler->events_list), next) {
event = (struct isulad_events_format *)it->elem;
linked_list_del(it);
isulad_events_format_free(event);
......
......@@ -20,13 +20,7 @@
#include "linked_list.h"
#include "libisulad.h"
typedef struct _container_events_handler_t {
pthread_mutex_t mutex;
bool init_mutex;
struct linked_list events_list;
bool has_handler;
} container_events_handler_t;
#include "container_api.h"
container_events_handler_t *container_events_handler_new();
......
......@@ -24,8 +24,9 @@
#include "isula_libutils/log.h"
#include "utils.h"
#include "service_container.h"
#include "containers_store.h"
#include "container_api.h"
#include "runtime.h"
#include "restartmanager.h"
static containers_gc_t g_gc_containers;
......@@ -141,7 +142,7 @@ static int gc_containers_to_disk()
ERROR("Out of memory");
return -1;
}
linked_list_for_each_safe(it, &g_gc_containers.containers_list, next) {
linked_list_for_each_safe (it, &g_gc_containers.containers_list, next) {
conts[i] = (container_garbage_config_gc_containers_element *)it->elem;
i++;
}
......@@ -167,7 +168,7 @@ bool gc_is_gc_progress(const char *id)
gc_containers_lock();
linked_list_for_each_safe(it, &g_gc_containers.containers_list, next) {
linked_list_for_each_safe (it, &g_gc_containers.containers_list, next) {
cont = (container_garbage_config_gc_containers_element *)it->elem;
if (strcmp(id, cont->id) == 0) {
ret = true;
......@@ -522,7 +523,7 @@ static void *gchandler(void *arg)
do_gc_container(it);
wait_continue:
wait_continue:
usleep_nointerupt(100 * 1000); /* wait 100 millisecond to check next gc container */
}
error:
......@@ -573,3 +574,12 @@ int start_gchandler()
out:
return ret;
}
bool container_in_gc_progress(const char *id)
{
if (id == NULL) {
return false;
}
return gc_is_gc_progress(id);
}
\ No newline at end of file
......@@ -16,81 +16,20 @@
#define __ISULAD_CONTAINER_STATE_H__
#include <pthread.h>
#include "libisulad.h"
#include "isula_libutils/container_config_v2.h"
#include "runtime.h"
#include "container_api.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
typedef struct _container_state_t_ {
pthread_mutex_t mutex;
container_config_v2_state *state;
} container_state_t;
container_state_t *container_state_new(void);
void container_state_free(container_state_t *state);
container_config_v2_state *state_get_info(container_state_t *s);
void container_state_lock(container_state_t *state);
void container_state_unlock(container_state_t *state);
void update_start_and_finish_time(container_state_t *s, const char *finish_at);
void state_set_starting(container_state_t *s);
void state_reset_starting(container_state_t *s);
void state_set_running(container_state_t *s, const container_pid_t *pid_info, bool initial);
void state_set_stopped(container_state_t *s, int exit_code);
void state_set_restarting(container_state_t *s, int exit_code);
void state_set_paused(container_state_t *s);
void state_reset_paused(container_state_t *s);
void state_set_dead(container_state_t *s);
// state_set_removal_in_progress sets the container state as being removed.
// It returns true if the container was already in that state
bool state_set_removal_in_progress(container_state_t *s);
void state_reset_removal_in_progress(container_state_t *s);
const char *state_to_string(Container_Status cs);
Container_Status state_judge_status(const container_config_v2_state *state);
Container_Status state_get_status(container_state_t *s);
bool is_running(container_state_t *s);
bool is_restarting(container_state_t *s);
bool is_removal_in_progress(container_state_t *s);
bool is_paused(container_state_t *s);
uint32_t state_get_exitcode(container_state_t *s);
int state_get_pid(container_state_t *s);
bool is_dead(container_state_t *s);
void container_state_set_error(container_state_t *s, const char *err);
char *state_get_started_at(container_state_t *s);
bool is_valid_state_string(const char *state);
int dup_health_check_status(defs_health **dst, const defs_health *src);
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
......
......@@ -20,7 +20,14 @@
#include "constants.h"
#include "container_unix.h"
#include "isula_libutils/log.h"
#include "container_state.h"
#include "restartmanager.h"
#include "utils.h"
#include "container_events_handler.h"
#include "health_check.h"
#include "containers_gc.h"
#include "supervisor.h"
#include "restore.h"
static int parse_container_log_configs(container_t *cont);
......@@ -403,27 +410,6 @@ out:
return ret;
}
/* container make basic v2 spec info */
int v2_spec_make_basic_info(const char *id, const char *name, const char *image_name, const char *image_type,
container_config_v2_common_config *v2_spec)
{
char timebuffer[TIME_STR_SIZE] = { 0 };
if (v2_spec == NULL) {
return -1;
}
v2_spec->id = id ? util_strdup_s(id) : NULL;
v2_spec->name = name ? util_strdup_s(name) : NULL;
v2_spec->image = image_name ? util_strdup_s(image_name) : util_strdup_s("none");
v2_spec->image_type = image_type ? util_strdup_s(image_type) : NULL;
(void)get_now_time_buffer(timebuffer, sizeof(timebuffer));
free(v2_spec->created);
v2_spec->created = util_strdup_s(timebuffer);
return 0;
}
/* container merge basic v2 spec info */
int v2_spec_merge_contaner_spec(container_config_v2_common_config *v2_spec)
{
......@@ -1098,3 +1084,31 @@ bool has_mount_for(container_t *cont, const char *mpath)
return false;
}
int container_module_init(char **msg)
{
int ret = 0;
if (new_gchandler()) {
*msg = "Create garbage handler thread failed";
ret = -1;
goto out;
}
if (new_supervisor()) {
*msg = "Create supervisor thread failed";
ret = -1;
goto out;
}
containers_restore();
if (start_gchandler()) {
*msg = "Failed to start garbage collecotor handler";
ret = -1;
goto out;
}
out:
return ret;
}
\ No newline at end of file
......@@ -17,98 +17,19 @@
#include <pthread.h>
#include "libisulad.h"
#include "util_atomic.h"
#include "isula_libutils/container_config_v2.h"
#include "isula_libutils/host_config.h"
#include "container_state.h"
#include "isula_libutils/oci_runtime_spec.h"
#include "restartmanager.h"
#include "container_events_handler.h"
#include "health_check.h"
#include "container_api.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
typedef struct _container_t_ {
pthread_mutex_t mutex;
bool init_mutex;
pthread_cond_t wait_stop_con;
bool init_wait_stop_con;
pthread_cond_t wait_rm_con;
bool init_wait_rm_con;
uint64_t refcnt;
char *runtime;
char *root_path;
char *state_path;
char *image_id;
container_config_v2_common_config *common_config;
container_state_t *state;
host_config *hostconfig;
restart_manager_t *rm;
container_events_handler_t *handler;
health_check_manager_t *health_check;
/* log configs of container */
char *log_driver;
char *log_path;
int log_rotate;
int64_t log_maxsize;
} container_t;
void container_refinc(container_t *cont);
void container_unref(container_t *cont);
container_t *container_new(const char *runtime, const char *rootpath, const char *statepath, const char *image_id,
host_config **hostconfig, container_config_v2_common_config **common_config);
container_t *container_load(const char *runtime, const char *rootpath, const char *statepath, const char *id);
int container_to_disk(const container_t *cont);
int container_to_disk_locking(container_t *cont);
void container_lock(container_t *cont);
int container_timedlock(container_t *cont, int timeout);
void container_unlock(container_t *cont);
char *container_get_env_nolock(const container_t *cont, const char *key);
int v2_spec_make_basic_info(const char *id, const char *name, const char *image_name, const char *image_type,
container_config_v2_common_config *v2_spec);
int v2_spec_merge_contaner_spec(container_config_v2_common_config *v2_spec);
char *container_get_command(const container_t *cont);
char *container_get_image(const container_t *cont);
int container_exit_on_next(container_t *cont);
restart_manager_t *get_restart_manager(container_t *cont);
bool reset_restart_manager(container_t *cont, bool reset_count);
void container_update_restart_manager(container_t *cont, const host_config_restart_policy *policy);
void container_reset_manually_stopped(container_t *cont);
void container_wait_stop_cond_broadcast(container_t *cont);
int container_wait_stop(container_t *cont, int timeout);
int container_wait_stop_locking(container_t *cont, int timeout);
void container_wait_rm_cond_broadcast(container_t *cont);
int container_wait_rm_locking(container_t *cont, int timeout);
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);
bool has_mount_for(container_t *cont, const char *mpath);
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
......
......@@ -15,12 +15,12 @@
#include <stdlib.h>
#include <pthread.h>
#include "containers_store.h"
#include "container_api.h"
#include "isula_libutils/log.h"
#include "utils.h"
typedef struct memory_store_t {
map_t *map; // map string container_t
map_t *map; // map string container_t
pthread_rwlock_t rwlock;
} memory_store;
......@@ -264,8 +264,7 @@ int containers_store_list(container_t ***out, size_t *size)
goto unlock;
}
for (i = 0; map_itor_valid(itor) &&
i < *size; map_itor_next(itor), i++) {
for (i = 0; map_itor_valid(itor) && i < *size; map_itor_next(itor), i++) {
conts[i] = map_itor_value(itor);
container_refinc(conts[i]);
}
......@@ -435,7 +434,6 @@ unlock_out:
return ret;
}
/* name index get */
char *name_index_get(const char *name)
{
......@@ -521,7 +519,6 @@ out:
return map_id_name;
}
/* name index init */
int name_index_init(void)
{
......@@ -530,5 +527,4 @@ int name_index_init(void)
return -1;
}
return 0;
}
}
\ No newline at end of file
......@@ -15,43 +15,14 @@
#ifndef __ISULAD_MEMORY_STORE_H__
#define __ISULAD_MEMORY_STORE_H__
#include "container_unix.h"
#include "map.h"
#include "container_api.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
int containers_store_init(void);
bool containers_store_add(const char *id, container_t *cont);
container_t *containers_store_get(const char *id_or_name);
container_t *containers_store_get_by_prefix(const char *prefix);
bool containers_store_remove(const char *id);
int containers_store_list(container_t ***out, size_t *size);
char **containers_store_list_ids(void);
/* name indexs */
int name_index_init(void);
bool name_index_remove(const char *name);
char *name_index_get(const char *name);
bool name_index_add(const char *name, const char *id);
map_t *name_index_get_all(void);
bool name_index_rename(const char *new_name, const char *old_name, const char *id);
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#endif /* __ISULAD_MEMORY_STORE_H__ */
......@@ -29,8 +29,8 @@
#include "service_container.h"
#include "isula_libutils/container_exec_request.h"
#include "isula_libutils/container_exec_response.h"
#include "containers_store.h"
#include "log_gather.h"
#include "container_state.h"
/* container state lock */
static void container_health_check_lock(health_check_manager_t *health)
......@@ -278,7 +278,7 @@ static int shift_and_store_log_result(defs_health *health, const defs_health_log
health->log[i]->end = util_strdup_s(health->log[i + 1]->end);
health->log[i]->exit_code = health->log[i + 1]->exit_code;
health->log[i]->output = health->log[i + 1]->output != NULL ? util_strdup_s(health->log[i + 1]->output) :
NULL;
NULL;
} else {
health->log[i]->start = util_strdup_s(result->start);
health->log[i]->end = util_strdup_s(result->end);
......@@ -358,7 +358,7 @@ static int handle_unhealthy_case(container_t *cont, const defs_health_log_elemen
if (strcmp(health_status, HEALTH_STARTING) == 0) {
int64_t start_period =
timeout_with_default(cont->common_config->config->healthcheck->start_period, DEFAULT_START_PERIOD);
timeout_with_default(cont->common_config->config->healthcheck->start_period, DEFAULT_START_PERIOD);
int64_t first, last;
if (to_unix_nanos_from_str(cont->state->state->started_at, &first)) {
ERROR("Parse container started time failed: %s", cont->state->state->started_at);
......
......@@ -16,40 +16,16 @@
#define __ISULAD_HEALTH_CHECK_H_
#include "utils_timestamp.h"
#include "container_api.h"
#include "isula_libutils/container_config_v2.h"
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_OUTPUT_LEN 4096
#define DEFAULT_PROBE_INTERVAL (30 * Time_Second)
#define DEFAULT_PROBE_TIMEOUT (30 * Time_Second)
#define DEFAULT_START_PERIOD (0 * Time_Second)
#define DEFAULT_PROBE_RETRIES 3
#define MAX_LOG_ENTRIES 5
#define EXIT_STATUS_HEALTHY 0
#define NO_HEALTH_CHECK "none"
#define HEALTH_STARTING "starting"
#define HEALTHY "healthy"
#define UNHEALTHY "unhealthy"
typedef enum { CMD, CMD_SHELL, HEALTH_NONE, HEALTH_UNKNOWN } health_probe_t;
typedef enum { MONITOR_IDLE = 0, MONITOR_INTERVAL = 1, MONITOR_STOP = 2 } health_check_monitor_status_t;
typedef struct health_check_manager {
pthread_mutex_t mutex;
bool init_mutex;
health_check_monitor_status_t monitor_status;
} health_check_manager_t;
void init_health_monitor(const char *id);
void stop_health_checks(const char *container_id);
void update_health_monitor(const char *container_id);
void health_check_manager_free(health_check_manager_t *health_check);
int64_t timeout_with_default(int64_t configured_value, int64_t default_value);
#ifdef __cplusplus
}
......
......@@ -12,6 +12,7 @@
* Create: 2017-11-22
* Description: provide container restart manager functions
******************************************************************************/
#include "restartmanager.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
......@@ -24,9 +25,7 @@
#include "error.h"
#include "isula_libutils/log.h"
#include "isulad_config.h"
#include "restartmanager.h"
#include "utils.h"
#include "containers_store.h"
#include "service_container.h"
#define backoffMultipulier 2U
......
......@@ -18,24 +18,7 @@
#include <stdint.h>
#include <pthread.h>
#include "isula_libutils/host_config.h"
struct restart_policy {
char *name;
uint64_t max_retry_count;
};
typedef struct _restart_manager_t {
pthread_mutex_t mutex;
bool init_mutex;
pthread_cond_t wait_cancel_con;
bool init_wait_cancel_con;
uint64_t refcnt;
host_config_restart_policy *policy;
int failure_count;
int64_t timeout;
bool active;
bool canceled;
} restart_manager_t;
#include "container_api.h"
void restart_policy_free(host_config_restart_policy *policy);
......
......@@ -22,14 +22,16 @@
#include "isulad_config.h"
#include "isula_libutils/log.h"
#include "restore.h"
#include "containers_store.h"
#include "container_api.h"
#include "supervisor.h"
#include "containers_gc.h"
#include "container_unix.h"
#include "error.h"
#include "image.h"
#include "image_api.h"
#include "runtime.h"
#include "service_container.h"
#include "restartmanager.h"
#include "health_check.h"
/* restore supervisor */
static int restore_supervisor(const container_t *cont)
......@@ -492,7 +494,7 @@ static void scan_dir_to_add_store(const char *runtime, const char *rootpath, con
}
continue;
error_load:
error_load:
if (remove_invalid_container(cont, runtime, rootpath, statepath, subdir[i])) {
ERROR("Failed to delete subdir:%s", subdir[i]);
}
......
......@@ -18,16 +18,8 @@
#include <semaphore.h>
#include "container_unix.h"
extern char *exit_fifo_create(const char *cont_state_path);
extern char *exit_fifo_name(const char *cont_state_path);
extern int exit_fifo_open(const char *cont_exit_fifo);
extern int supervisor_add_exit_monitor(int fd, const container_pid_t *pid_info, const char *name,
const char *runtime);
extern int new_supervisor();
#endif
......@@ -31,8 +31,9 @@
#include "monitord.h"
#include "isulad_config.h"
#include "libisulad.h"
#include "containers_store.h"
#include "container_api.h"
#include "event_type.h"
#include "container_events_handler.h"
static struct context_lists g_context_lists;
......@@ -127,7 +128,7 @@ static container_events_type_t lcrsta2Evetype(int value)
return et;
}
static const char * const g_isulad_event_strtype[] = {
static const char *const g_isulad_event_strtype[] = {
"exit", "die", "starting", "running", "stopping", "aborting", "freezing", "frozen",
"thawed", "oom", "create", "start", "restart", "stop", "exec_create", "exec_start",
"exec_die", "attach", "kill", "top", "reanme", "archive-path", "extract-to-dir", "update",
......@@ -144,7 +145,7 @@ static const char *isulad_event_sta2str(container_events_type_t sta)
return g_isulad_event_strtype[sta];
}
static const char * const g_isulad_image_event_strtype[] = { "load", "remove", "pull", "login", "logout" };
static const char *const g_isulad_image_event_strtype[] = { "load", "remove", "pull", "login", "logout" };
static const char *isulad_image_event_sta2str(image_events_type_t sta)
{
......@@ -621,7 +622,7 @@ static int do_subscribe(const char *name, const types_timestamp_t *since, const
return -1;
}
linked_list_for_each_safe(it, &g_events_buffer.event_list, next) {
linked_list_for_each_safe (it, &g_events_buffer.event_list, next) {
c_event = (struct isulad_events_format *)it->elem;
if (check_since_time(since, c_event) != 0) {
......@@ -702,7 +703,7 @@ static void events_forward(struct isulad_events_format *r)
return;
}
linked_list_for_each_safe(it, &g_context_lists.context_list, next) {
linked_list_for_each_safe (it, &g_context_lists.context_list, next) {
context_info = (struct context_elem *)it->elem;
name = context_info->name;
......@@ -729,7 +730,7 @@ static void events_forward(struct isulad_events_format *r)
continue;
delete_and_continue:
delete_and_continue:
linked_list_del(it);
sem_post(&context_info->context_sem);
continue;
......@@ -770,7 +771,7 @@ static void *event_should_exit(void *arg)
continue;
}
linked_list_for_each_safe(it, &g_context_lists.context_list, next) {
linked_list_for_each_safe (it, &g_context_lists.context_list, next) {
context_info = (struct context_elem *)it->elem;
if (context_info->stream.is_cancelled(context_info->stream.context)) {
......
......@@ -74,7 +74,7 @@ add_library(${LIB_ISULAD_IMG} ${LIBTYPE}
target_include_directories(${LIB_ISULAD_IMG} PUBLIC
${local_image_incs}
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/src/daemon/modules/api
${CMAKE_SOURCE_DIR}/src/utils/sha256
${CMAKE_SOURCE_DIR}/src/http
${CMAKE_SOURCE_DIR}/src/utils/tar
......
......@@ -16,7 +16,7 @@
#define __EMBEDDED_IMAGE_H
#include <stdint.h>
#include "image.h"
#include "image_api.h"
bool embedded_detect(const char *image_name);
......
......@@ -26,7 +26,7 @@
#include "isula_libutils/embedded_manifest.h"
#include "db_all.h"
#include "path.h"
#include "image.h"
#include "image_api.h"
#include "sha256.h"
/* lim init */
......@@ -199,7 +199,7 @@ static bool validate_layer_path_in_host_real(size_t layer_index, char *path_in_h
ERROR("invalid path in host %s, real path is %s, layer %ld", path_in_host, real_path, layer_index);
if (fmod == (uint32_t)S_IFREG) {
isulad_try_set_error_message(
"Invalid content in manifest: layer(except first layer) is not a regular file");
"Invalid content in manifest: layer(except first layer) is not a regular file");
} else if ((int)fmod == S_IFDIR) {
isulad_try_set_error_message("Invalid content in manifest: layer(except first layer) is not a directory");
} else if ((int)fmod == S_IFBLK) {
......@@ -286,8 +286,8 @@ static bool validate_layer_media_type(size_t layer_index, char *media_type, uint
}
isulad_try_set_error_message(
"Invalid content in manifest: layer's media type must be"
" application/squashfs.image.rootfs.diff.img or application/bind.image.rootfs.diff.dir");
"Invalid content in manifest: layer's media type must be"
" application/squashfs.image.rootfs.diff.img or application/bind.image.rootfs.diff.dir");
ERROR("invalid layer media type %s", media_type);
return false;
}
......@@ -393,7 +393,7 @@ static bool validate_image_name(char *image_name)
if (strcmp(image_name, "none") == 0 || strcmp(image_name, "none:latest") == 0) {
ERROR("image name %s must not be none or none:latest", image_name);
isulad_try_set_error_message(
"Image name 'none' or 'none:latest' in manifest is reserved, please use other name");
"Image name 'none' or 'none:latest' in manifest is reserved, please use other name");
return false;
}
......
......@@ -21,7 +21,7 @@
#include "lim.h"
#include "limits.h"
#include "isula_libutils/log.h"
#include "image.h"
#include "image_api.h"
#define RAW_DIGEST_LEN 64
......@@ -196,4 +196,3 @@ int embedded_load_image(const im_load_request *request)
return load_image(request->file);
}
......@@ -16,7 +16,7 @@
#define __EXT_IMAGE_H
#include <stdint.h>
#include "image.h"
#include "image_api.h"
bool ext_detect(const char *image_name);
int ext_filesystem_usage(const im_container_fs_usage_request *request, imagetool_fs_info **fs_usage);
......
......@@ -21,7 +21,7 @@
#include <sys/utsname.h>
#include <ctype.h>
#include "image.h"
#include "image_api.h"
#include "libisulad.h"
#include "isula_libutils/log.h"
#include "utils.h"
......@@ -138,8 +138,8 @@ static const struct bim_ops g_ext_ops = {
static const struct bim_type g_bims[] = {
#ifdef ENABLE_OCI_IMAGE
{
.image_type = IMAGE_TYPE_OCI,
.ops = &g_oci_ops,
.image_type = IMAGE_TYPE_OCI,
.ops = &g_oci_ops,
},
#endif
{ .image_type = IMAGE_TYPE_EXTERNAL, .ops = &g_ext_ops },
......@@ -807,7 +807,7 @@ void free_im_list_response(im_list_response *ptr)
free(ptr);
}
static bool check_im_pull_args(const im_pull_request *req, im_pull_response * const *resp)
static bool check_im_pull_args(const im_pull_request *req, im_pull_response *const *resp)
{
if (req == NULL || resp == NULL) {
ERROR("Request or response is NULL");
......
......@@ -16,7 +16,7 @@
#define __OCI_COMMON_OPERATORS_H
#include <stdint.h>
#include "image.h"
#include "image_api.h"
#include "isula_libutils/imagetool_image.h"
#include "isula_libutils/oci_image_spec.h"
......
......@@ -15,7 +15,7 @@
#ifndef __IMAGE_OCI_IMAGE_H
#define __IMAGE_OCI_IMAGE_H
#include "image.h"
#include "image_api.h"
#include "isula_libutils/oci_image_spec.h"
#include "oci_common_operators.h"
......
......@@ -15,7 +15,7 @@
#ifndef __IMAGE_OCI_LOAD_H
#define __IMAGE_OCI_LOAD_H
#include "image.h"
#include "image_api.h"
#include "isula_libutils/image_manifest_items.h"
#include "isula_libutils/oci_image_manifest.h"
#include "isula_libutils/oci_image_spec.h"
......
......@@ -15,7 +15,7 @@
#ifndef __IMAGE_OCI_PULL_H
#define __IMAGE_OCI_PULL_H
#include "image.h"
#include "image_api.h"
#ifdef __cplusplus
extern "C" {
......
......@@ -24,7 +24,7 @@
#include "driver_overlay2_types.h"
#include "devices_constants.h"
#include "storage.h"
#include "image.h"
#include "image_api.h"
#include "isula_libutils/container_inspect.h"
#ifdef __cplusplus
......
......@@ -31,7 +31,7 @@
#include "specs.h"
#include "specs_extend.h"
#include "rest_common.h"
#include "containers_store.h"
#include "container_api.h"
#include "constants.h"
#include "isula_libutils/plugin_activate_plugin_request.h"
......
......@@ -21,19 +21,17 @@
#include "isula_libutils/log.h"
#include "utils.h"
#include "supervisor.h"
#include "mainloop.h"
#include "libisulad.h"
#include "event_sender.h"
#include "containers_gc.h"
#include "image.h"
#include "image_api.h"
#include "specs.h"
#include "isulad_config.h"
#include "verify.h"
#include "plugin.h"
#include "containers_store.h"
#include "container_api.h"
#include "namespace.h"
#include "restore.h"
#include "runtime.h"
int set_container_to_removal(const container_t *cont)
{
......@@ -350,7 +348,7 @@ static int mount_host_channel(const host_config_host_channel *host_channel, cons
return 0;
}
int nret =
snprintf(properties, sizeof(properties), "mode=1777,size=%llu", (long long unsigned int)host_channel->size);
snprintf(properties, sizeof(properties), "mode=1777,size=%llu", (long long unsigned int)host_channel->size);
if (nret < 0 || (size_t)nret >= sizeof(properties)) {
ERROR("Failed to generate mount properties");
return -1;
......@@ -1323,40 +1321,3 @@ void umount_host_channel(const host_config_host_channel *host_channel)
ERROR("Failed to delete host path: %s", host_channel->path_on_host);
}
}
bool container_in_gc_progress(const char *id)
{
if (id == NULL) {
return false;
}
return gc_is_gc_progress(id);
}
int container_module_init(char **msg)
{
int ret = 0;
if (new_gchandler()) {
*msg = "Create garbage handler thread failed";
ret = -1;
goto out;
}
if (new_supervisor()) {
*msg = "Create supervisor thread failed";
ret = -1;
goto out;
}
containers_restore();
if (start_gchandler()) {
*msg = "Failed to start garbage collecotor handler";
ret = -1;
goto out;
}
out:
return ret;
}
......@@ -40,8 +40,6 @@ int set_container_to_removal(const container_t *cont);
int delete_container(container_t *cont, bool force);
bool container_in_gc_progress(const char *id);
int container_module_init(char **msg);
#ifdef __cplusplus
......
......@@ -20,9 +20,9 @@
#include <sys/mount.h>
#include "isula_libutils/log.h"
#include "image.h"
#include "image_api.h"
#include "utils.h"
#include "containers_store.h"
#include "container_api.h"
#include "event_sender.h"
static bool check_image_in_used(const char *image_ref)
......@@ -54,7 +54,7 @@ static bool check_image_in_used(const char *image_ref)
in_used = true;
goto unref_continue;
}
unref_continue:
unref_continue:
container_unref(conts[i]);
continue;
}
......
......@@ -20,7 +20,7 @@
#include "isula_libutils/log.h"
#include "utils.h"
#include "namespace.h"
#include "containers_store.h"
#include "container_api.h"
static char *parse_share_namespace_with_prefix(const char *type, const char *path)
{
......
......@@ -34,7 +34,7 @@
#include "verify.h"
#include "isulad_config.h"
#include "selinux_label.h"
#include "image.h"
#include "image_api.h"
/* verify hook timeout */
static int verify_hook_timeout(int t)
......@@ -136,16 +136,14 @@ static int verify_mem_limit_swap(const sysinfo_t *sysinfo, int64_t limit, int64_
if (limit > 0 && !(sysinfo->cgmeminfo.limit)) {
ERROR("Your kernel does not support memory limit capabilities. Limitation discarded.");
isulad_set_error_message(
"Your kernel does not support memory limit capabilities. Limitation discarded.");
isulad_set_error_message("Your kernel does not support memory limit capabilities. Limitation discarded.");
ret = -1;
goto out;
}
if (limit > 0 && swap != 0 && !(sysinfo->cgmeminfo.swap)) {
ERROR("Your kernel does not support swap limit capabilities, memory limited without swap.");
isulad_set_error_message(
"Your kernel does not support swap limit capabilities, memory limited without swap.");
isulad_set_error_message("Your kernel does not support swap limit capabilities, memory limited without swap.");
ret = -1;
goto out;
}
......@@ -181,7 +179,7 @@ static int verify_memory_swappiness(const sysinfo_t *sysinfo, uint64_t swapiness
if ((int64_t)swapiness != -1 && !(sysinfo->cgmeminfo.swappiness)) {
ERROR("Your kernel does not support memory swappiness capabilities, memory swappiness discarded.");
isulad_set_error_message(
"Your kernel does not support memory swappiness capabilities, memory swappiness discarded.");
"Your kernel does not support memory swappiness capabilities, memory swappiness discarded.");
ret = -1;
goto out;
}
......@@ -252,7 +250,8 @@ static int verify_memory_kernel(const sysinfo_t *sysinfo, int64_t kernel)
if (kernel > 0 && !(sysinfo->cgmeminfo.kernel)) {
ERROR("Your kernel does not support kernel memory limit capabilities. Limitation discarded.");
isulad_set_error_message("Your kernel does not support kernel memory limit capabilities. Limitation discarded.");
isulad_set_error_message(
"Your kernel does not support kernel memory limit capabilities. Limitation discarded.");
ret = -1;
goto out;
}
......@@ -300,7 +299,6 @@ static int verify_files_limit(const sysinfo_t *sysinfo, int64_t files_limit)
return ret;
}
/* verify oom control */
static int verify_oom_control(const sysinfo_t *sysinfo, bool oomdisable)
{
......@@ -400,8 +398,7 @@ static int verify_cpu_shares(const sysinfo_t *sysinfo, int64_t cpu_shares)
if (cpu_shares > 0 && !(sysinfo->cgcpuinfo.cpu_shares)) {
ERROR("Your kernel does not support cgroup cpu shares. Shares discarded.");
isulad_set_error_message(
"Your kernel does not support cgroup cpu shares. Shares discarded.");
isulad_set_error_message("Your kernel does not support cgroup cpu shares. Shares discarded.");
ret = -1;
}
......@@ -619,8 +616,7 @@ static bool is_cpuset_list_available(const char *provided, const char *available
goto out;
}
if (parse_unit_list(provided, parsed_provided) < 0 ||
parse_unit_list(available, parsed_available) < 0) {
if (parse_unit_list(provided, parsed_provided) < 0 || parse_unit_list(available, parsed_available) < 0) {
goto out;
}
for (i = 0; i < cpu_num; i++) {
......@@ -692,10 +688,10 @@ static int verify_resources_cpuset(const sysinfo_t *sysinfo, const char *cpus, c
mems_available = is_cpuset_mems_available(sysinfo, mems);
if (!mems_available) {
ERROR("Requested memory nodes are not available - requested %s, available: %s.",
mems, sysinfo->cpusetinfo.mems);
isulad_set_error_message("Requested memory nodes are not available - requested %s, available: %s.",
mems, sysinfo->cpusetinfo.mems);
ERROR("Requested memory nodes are not available - requested %s, available: %s.", mems,
sysinfo->cpusetinfo.mems);
isulad_set_error_message("Requested memory nodes are not available - requested %s, available: %s.", mems,
sysinfo->cpusetinfo.mems);
ret = -1;
goto out;
}
......@@ -952,8 +948,8 @@ static bool check_hugetlbs_repeated(size_t newlen, const char *pagesize,
for (j = 0; j < newlen; j++) {
if (newtlb[j] != NULL && newtlb[j]->page_size != NULL && !strcmp(newtlb[j]->page_size, pagesize)) {
WARN("hugetlb-limit setting of %s is repeated, former setting %lu will be replaced with %lu",
pagesize, newtlb[j]->limit, hugetlb->limit);
WARN("hugetlb-limit setting of %s is repeated, former setting %lu will be replaced with %lu", pagesize,
newtlb[j]->limit, hugetlb->limit);
newtlb[j]->limit = hugetlb->limit;
repeated = true;
goto out;
......@@ -964,8 +960,7 @@ out:
return repeated;
}
static void free_hugetlbs_array(defs_resources_hugepage_limits_element **hugetlb,
size_t hugetlb_len)
static void free_hugetlbs_array(defs_resources_hugepage_limits_element **hugetlb, size_t hugetlb_len)
{
size_t i;
......@@ -983,8 +978,7 @@ static void free_hugetlbs_array(defs_resources_hugepage_limits_element **hugetlb
}
/* verify resources hugetlbs */
static int verify_resources_hugetlbs(const sysinfo_t *sysinfo,
defs_resources_hugepage_limits_element ***hugetlb,
static int verify_resources_hugetlbs(const sysinfo_t *sysinfo, defs_resources_hugepage_limits_element ***hugetlb,
size_t *hugetlb_len)
{
int ret = 0;
......@@ -994,8 +988,7 @@ static int verify_resources_hugetlbs(const sysinfo_t *sysinfo,
if (!sysinfo->hugetlbinfo.hugetlblimit) {
ERROR("Your kernel does not support hugetlb limit. --hugetlb-limit discarded.");
isulad_set_error_message(
"Your kernel does not support hugetlb limit. --hugetlb-limit discarded.");
isulad_set_error_message("Your kernel does not support hugetlb limit. --hugetlb-limit discarded.");
ret = -1;
goto out;
}
......@@ -1153,9 +1146,7 @@ static bool verify_oci_linux_sysctl(const oci_runtime_config_linux *l)
}
}
if (!check_sysctl_valid(l->sysctl->keys[i])) {
isulad_set_error_message("Sysctl %s=%s is not whitelist",
l->sysctl->keys[i],
l->sysctl->values[i]);
isulad_set_error_message("Sysctl %s=%s is not whitelist", l->sysctl->keys[i], l->sysctl->values[i]);
return false;
}
}
......@@ -1270,7 +1261,7 @@ static int get_source_mount(const char *src, char **srcpath, char **optional)
mountinfo_t **minfos = NULL;
mountinfo_t *info = NULL;
int ret = 0;
char real_path[PATH_MAX + 1] = {0};
char real_path[PATH_MAX + 1] = { 0 };
char *dirc = NULL;
char *dname = NULL;
......@@ -1463,8 +1454,7 @@ static int verify_custom_mount(defs_mount **mounts, size_t len)
continue;
}
if (!util_file_exists(iter->source) &&
util_mkdir_p(iter->source, CONFIG_DIRECTORY_MODE)) {
if (!util_file_exists(iter->source) && util_mkdir_p(iter->source, CONFIG_DIRECTORY_MODE)) {
ERROR("Failed to create directory '%s': %s", iter->source, strerror(errno));
isulad_try_set_error_message("Failed to create directory '%s': %s", iter->source, strerror(errno));
ret = -1;
......@@ -1989,8 +1979,7 @@ int verify_container_settings_start(const oci_runtime_spec *oci_spec)
ret = -1;
goto out;
}
if (relabel_mounts_if_needed(oci_spec->mounts, oci_spec->mounts_len,
oci_spec->linux->mount_label) != 0) {
if (relabel_mounts_if_needed(oci_spec->mounts, oci_spec->mounts_len, oci_spec->linux->mount_label) != 0) {
ERROR("Failed to relabel mount");
ret = -1;
goto out;
......@@ -2042,5 +2031,3 @@ int verify_health_check_parameter(const container_config *container_spec)
out:
return ret;
}
......@@ -31,6 +31,6 @@ public:
MOCK_METHOD1(IsRemovalInProgress, bool(container_state_t *s));
};
void MockContainerState_SetMock(MockContainerState* mock);
void MockContainerState_SetMock(MockContainerState *mock);
#endif
......@@ -17,7 +17,7 @@
#define CONTAINERS_STORE_MOCK_H_
#include <gmock/gmock.h>
#include "containers_store.h"
#include "container_api.h"
class MockContainersStore {
public:
......@@ -33,10 +33,10 @@ public:
MOCK_METHOD1(NameIndexRemove, bool(const char *name));
MOCK_METHOD1(NameIndexGet, char *(const char *name));
MOCK_METHOD2(NameIndexAdd, bool(const char *name, const char *id));
MOCK_METHOD0(NameIndexGetAll, map_t * (void));
MOCK_METHOD0(NameIndexGetAll, map_t *(void));
MOCK_METHOD3(NameIndexRename, bool(const char *new_name, const char *old_name, const char *id));
};
void MockContainersStore_SetMock(MockContainersStore* mock);
void MockContainersStore_SetMock(MockContainersStore *mock);
#endif // CONTAINERS_STORE_MOCK_H_
\ No newline at end of file
#endif // CONTAINERS_STORE_MOCK_H_
\ No newline at end of file
......@@ -17,7 +17,7 @@
#define IMAGE_MOCK_H_
#include <gmock/gmock.h>
#include "image.h"
#include "image_api.h"
class MockImage {
public:
......@@ -26,6 +26,6 @@ public:
MOCK_METHOD1(FreeImExportRequest, void(im_export_request *ptr));
};
void MockImage_SetMock(MockImage* mock);
void MockImage_SetMock(MockImage *mock);
#endif // IMAGE_MOCK_H_
#endif // IMAGE_MOCK_H_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册