runtime_api.h 7.8 KB
Newer Older
D
dogsheng 已提交
1 2
/******************************************************************************
 * Copyright (c) Huawei Technologies Co., Ltd. 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
D
dogsheng 已提交
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.
D
dogsheng 已提交
11 12 13 14 15 16 17 18 19
 * Author: lifeng
 * Create: 2019-11-22
 * Description: provide runtime function definition
 ******************************************************************************/
#ifndef __RUNTIME_H
#define __RUNTIME_H

#include <stdint.h>
#include <stdbool.h>
20 21 22
#include "libisulad.h"
#include "isula_libutils/host_config.h"
#include "isula_libutils/oci_runtime_spec.h"
D
dogsheng 已提交
23 24 25 26 27 28 29

#ifdef __cplusplus
extern "C" {
#endif

#define RUNTIME_NOT_IMPLEMENT_RESET -2

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
typedef enum {
    RUNTIME_CONTAINER_STATUS_UNKNOWN = 0,
    RUNTIME_CONTAINER_STATUS_CREATED = 1,
    RUNTIME_CONTAINER_STATUS_STARTING = 2,
    RUNTIME_CONTAINER_STATUS_RUNNING = 3,
    RUNTIME_CONTAINER_STATUS_STOPPED = 4,
    RUNTIME_CONTAINER_STATUS_PAUSED = 5,
    RUNTIME_CONTAINER_STATUS_RESTARTING = 6,
    RUNTIME_CONTAINER_STATUS_MAX_STATE = 7
} Runtime_Container_Status;

struct runtime_container_status_info {
    bool has_pid;
    uint32_t pid;
    Runtime_Container_Status status;
};

struct runtime_container_resources_stats_info {
    uint64_t pids_current;
    /* CPU usage */
    uint64_t cpu_use_nanos;
    uint64_t cpu_system_use;
    /* BlkIO usage */
    uint64_t blkio_read;
    uint64_t blkio_write;
    /* Memory usage */
    uint64_t mem_used;
    uint64_t mem_limit;
    /* Kernel Memory usage */
    uint64_t kmem_used;
    uint64_t kmem_limit;
};

D
dogsheng 已提交
63 64 65 66 67 68 69 70 71
typedef struct _rt_create_params_t {
    const char *rootfs;
    const char *bundle;
    const char *state;
    void *oci_config_data;
    bool terminal;
    const char *stdin;
    const char *stdout;
    const char *stderr;
72
    const char *exit_fifo;
73 74
    bool tty;
    bool open_stdin;
D
dogsheng 已提交
75 76 77 78
} rt_create_params_t;

typedef struct _rt_start_params_t {
    const char *rootpath;
79
    const char *state;
D
dogsheng 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    bool tty;
    bool open_stdin;

    const char *logpath;
    const char *loglevel;

    const char **console_fifos;

    uint32_t start_timeout;

    const char *container_pidfile;
    const char *exit_fifo;
} rt_start_params_t;

typedef struct _rt_restart_params_t {
    const char *rootpath;
} rt_restart_params_t;

typedef struct _rt_clean_params_t {
    const char *rootpath;
    const char *statepath;
    const char *logpath;
    const char *loglevel;
    pid_t pid;
} rt_clean_params_t;

typedef struct _rt_rm_params_t {
    const char *rootpath;
} rt_rm_params_t;

typedef struct _rt_status_params_t {
    const char *rootpath;
112
    const char *state;
D
dogsheng 已提交
113 114
} rt_status_params_t;

L
LiFeng 已提交
115 116
typedef struct _rt_stats_params_t {
    const char *rootpath;
J
jingrui 已提交
117
    const char *state;
L
LiFeng 已提交
118 119
} rt_stats_params_t;

D
dogsheng 已提交
120 121
typedef struct _rt_exec_params_t {
    const char *rootpath;
122
    const char *state;
D
dogsheng 已提交
123 124 125 126
    const char *logpath;
    const char *loglevel;
    const char **console_fifos;
    int64_t timeout;
L
LiFeng 已提交
127
    const char *suffix;
128
    defs_process *spec;
129
    bool attach_stdin;
D
dogsheng 已提交
130 131 132 133
} rt_exec_params_t;

typedef struct _rt_pause_params_t {
    const char *rootpath;
134
    const char *state;
D
dogsheng 已提交
135 136 137 138
} rt_pause_params_t;

typedef struct _rt_resume_params_t {
    const char *rootpath;
139
    const char *state;
D
dogsheng 已提交
140 141
} rt_resume_params_t;

L
LiFeng 已提交
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
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;

D
dogsheng 已提交
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
struct rt_ops {
    /* detect whether runtime is of this runtime type */
    bool (*detect)(const char *runtime);

    /* runtime ops */
    int (*rt_create)(const char *name, const char *runtime, const rt_create_params_t *params);

    int (*rt_start)(const char *name, const char *runtime, const rt_start_params_t *params, container_pid_t *pid_info);

    int (*rt_restart)(const char *name, const char *runtime, const rt_restart_params_t *params);

    int (*rt_clean_resource)(const char *name, const char *runtime, const rt_clean_params_t *params);

    int (*rt_rm)(const char *name, const char *runtime, const rt_rm_params_t *params);

    int (*rt_status)(const char *name, const char *runtime, const rt_status_params_t *params,
192
                     struct runtime_container_status_info *status);
L
LiFeng 已提交
193 194

    int (*rt_resources_stats)(const char *name, const char *runtime, const rt_stats_params_t *params,
195
                              struct runtime_container_resources_stats_info *rs_stats);
D
dogsheng 已提交
196

197
    int (*rt_exec)(const char *name, const char *runtime, const rt_exec_params_t *params, int *exit_code);
D
dogsheng 已提交
198 199 200

    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);
L
LiFeng 已提交
201 202 203 204 205 206 207 208 209

    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);
D
dogsheng 已提交
210 211 212 213 214 215 216 217
};

int runtime_create(const char *name, const char *runtime, const rt_create_params_t *params);
int runtime_clean_resource(const char *name, const char *runtime, const rt_clean_params_t *params);
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_rm(const char *name, const char *runtime, const rt_rm_params_t *params);
int runtime_status(const char *name, const char *runtime, const rt_status_params_t *params,
218
                   struct runtime_container_status_info *status);
L
LiFeng 已提交
219
int runtime_resources_stats(const char *name, const char *runtime, const rt_stats_params_t *params,
220
                            struct runtime_container_resources_stats_info *rs_stats);
221
int runtime_exec(const char *name, const char *runtime, const rt_exec_params_t *params, int *exit_code);
D
dogsheng 已提交
222 223
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);
L
LiFeng 已提交
224 225 226
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);
D
dogsheng 已提交
227

L
LiFeng 已提交
228 229 230 231
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);
232 233

int runtime_init();
D
dogsheng 已提交
234 235 236 237 238
#ifdef __cplusplus
}
#endif

#endif