engine.h 5.1 KB
Newer Older
O
overweight 已提交
1 2
/******************************************************************************
 * Copyright (c) Huawei Technologies Co., Ltd. 2018-2019. All rights reserved.
3 4 5 6
 * 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
O
overweight 已提交
7 8 9
 * 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.
10
 * See the Mulan PSL v2 for more details.
O
overweight 已提交
11 12 13 14
 * Author: tanyifeng
 * Create: 2018-11-08
 * Description: provide container engine definition
 ******************************************************************************/
L
LiuHao 已提交
15 16
#ifndef __ISULAD_ENGINE_H
#define __ISULAD_ENGINE_H
O
overweight 已提交
17 18 19 20 21

#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>

22 23
#include "runtime.h"

O
overweight 已提交
24 25 26 27
#ifdef __cplusplus
extern "C" {
#endif

28 29 30 31 32 33 34 35 36 37 38 39 40
struct engine_cgroup_resources {
    uint64_t blkio_weight;
    uint64_t cpu_shares;
    uint64_t cpu_period;
    uint64_t cpu_quota;
    char *cpuset_cpus;
    char *cpuset_mems;
    uint64_t memory_limit;
    uint64_t memory_swap;
    uint64_t memory_reservation;
    uint64_t kernel_memory_limit;
};

O
overweight 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
typedef struct _engine_start_request_t {
    const char *name;
    const char *lcrpath;

    const char *logpath;
    const char *loglevel;

    bool daemonize;
    bool tty;
    bool open_stdin;
    const char **console_fifos;
    uint32_t start_timeout;
    const char *container_pidfile;
    const char *exit_fifo;
} engine_start_request_t;

D
dogsheng 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
typedef struct _engine_exec_request_t {
    const char *name;
    const char *lcrpath;

    const char *logpath;
    const char *loglevel;

    const char **console_fifos;

    const char *user;

    const char **env;
    size_t env_len;
    const char **args;
    size_t args_len;

    int64_t timeout;
L
LiFeng 已提交
74 75

    const char *suffix;
76 77 78

    bool tty;
    bool open_stdin;
D
dogsheng 已提交
79 80
} engine_exec_request_t;

81
typedef bool (*engine_create_t)(const char *, const char *, void *);
O
overweight 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95

typedef bool (*engine_start_t)(const engine_start_request_t *request);

typedef bool (*engine_clean_t)(const char *name, const char *lcrpath, const char *logpath, const char *loglevel,
                               pid_t pid);

typedef bool (*engine_delete_t)(const char *name, const char *enginepath);

typedef bool (*engine_pause_t)(const char *name, const char *enginepath);

typedef bool (*engine_resume_t)(const char *name, const char *enginepath);

typedef bool (*engine_reset_t)(const char *name, const char *enginepath);

L
LiFeng 已提交
96 97 98 99
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);

O
overweight 已提交
100 101
typedef bool (*engine_update_t)(const char *name, const char *enginepath, const struct engine_cgroup_resources *cr);

D
dogsheng 已提交
102
typedef bool (*engine_exec_t)(const engine_exec_request_t *request, int *exit_code);
O
overweight 已提交
103 104

typedef int (*engine_get_container_status_t)(const char *name, const char *enginepath,
105
                                             struct runtime_container_status_info *status);
O
overweight 已提交
106

L
LiFeng 已提交
107
typedef int (*engine_get_container_resources_stats_t)(const char *name, const char *enginepath,
108
                                                      struct runtime_container_resources_stats_info *rs_stats);
O
overweight 已提交
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

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,
                                 char *err_fifo);

typedef int (*engine_log_init_t)(const char *name, const char *file, const char *priority, const char *prefix,
                                 int quiet, const char *enginepath);

typedef uint32_t (*engine_get_errno_t)();

typedef const char *(*engine_get_errmsg_t)();

typedef void (*engine_clear_errmsg_t)();

struct engine_operation {
    char *engine_type;
    engine_create_t engine_create_op;
    engine_start_t engine_start_op;
    engine_delete_t engine_delete_op;
    engine_pause_t engine_pause_op;
    engine_resume_t engine_resume_op;
    engine_reset_t engine_reset_op;
L
LiFeng 已提交
132 133
    engine_resize_t engine_resize_op;
    engine_exec_resize_t engine_exec_resize_op;
O
overweight 已提交
134 135 136
    engine_exec_t engine_exec_op;
    engine_console_t engine_console_op;
    engine_get_container_status_t engine_get_container_status_op;
L
LiFeng 已提交
137
    engine_get_container_resources_stats_t engine_get_container_resources_stats_op;
O
overweight 已提交
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    engine_get_container_pids_t engine_get_container_pids_op;
    engine_log_init_t engine_log_init_op;
    engine_update_t engine_update_op;
    engine_get_errmsg_t engine_get_errmsg_op;
    engine_clear_errmsg_t engine_clear_errmsg_op;
    engine_clean_t engine_clean_op;
};

extern int engines_global_init();

extern void engine_operation_free(struct engine_operation *eop);

extern int engines_discovery(const char *name);

extern struct engine_operation *engines_get_handler(const char *name);

#ifdef __cplusplus
}
#endif

#endif