image.h 10.2 KB
Newer Older
O
overweight 已提交
1 2
/******************************************************************************
 * Copyright (c) Huawei Technologies Co., Ltd. 2017-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 15 16 17 18 19
 * Author: weiwei
 * Create: 2017-11-22
 * Description: provide image function definition
 ******************************************************************************/
#ifndef __IMAGE_H
#define __IMAGE_H

#include <stdint.h>

H
haozi007 已提交
20 21 22 23 24 25
#include "isula_libutils/oci_image_manifest.h"
#include "isula_libutils/oci_image_index.h"
#include "isula_libutils/oci_image_spec.h"
#include "isula_libutils/oci_runtime_spec.h"
#include "isula_libutils/host_config.h"
#include "isula_libutils/container_config.h"
L
LiuHao 已提交
26
#include "libisulad.h"
27
#include "isula_libutils/isulad_daemon_configs.h"
L
lifeng68 已提交
28
#include "isula_libutils/container_inspect.h"
H
haozi007 已提交
29 30 31
#include "isula_libutils/imagetool_images_list.h"
#include "isula_libutils/imagetool_fs_info.h"
#include "isula_libutils/imagetool_image_status.h"
O
overweight 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

#ifdef __cplusplus
extern "C" {
#endif

#define IMAGE_TYPE_OCI "oci"
#define IMAGE_TYPE_EMBEDDED "embedded"
#define IMAGE_TYPE_EXTERNAL "external"

typedef struct {
    char *image;
} image_spec;

typedef struct {
    image_spec image;
} image_filter;

D
dogsheng 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
typedef struct {
    imagetool_fs_info *fs_info;
    char *errmsg;
} im_fs_info_response;

typedef struct {
    // Spec of the image.
    image_spec image;
    // Verbose indicates whether to return extra information about the image.
    bool verbose;
} im_status_request;

typedef struct {
    imagetool_image_status *image_info;
    char *errmsg;
} im_status_response;

O
overweight 已提交
66 67 68
typedef struct {
    image_filter filter;
    bool check;
D
dogsheng 已提交
69
    struct filters_args *image_filters;
O
overweight 已提交
70 71 72 73 74 75 76 77 78 79 80 81
} im_list_request;

typedef struct {
    imagetool_images_list *images;
    char *errmsg;
} im_list_response;

typedef struct {
    // Spec of the image.
    image_spec image;

    bool force;
82
} im_rmi_request;
O
overweight 已提交
83 84 85 86 87

typedef struct {
    char *errmsg;
} im_remove_response;

W
WangFengTu 已提交
88 89 90 91 92 93 94 95 96
typedef struct {
    image_spec src_name;
    image_spec dest_name;
} im_tag_request;

typedef struct {
    char *errmsg;
} im_tag_response;

O
overweight 已提交
97 98 99 100 101 102 103 104 105 106
typedef struct {
    // Spec of the image.
    image_spec image;
} im_inspect_request;

typedef struct {
    char *im_inspect_json;
    char *errmsg;
} im_inspect_response;

W
WangFengTu 已提交
107 108 109 110 111 112 113 114 115 116
typedef struct {
    char *file;
    char *tag;
} im_import_request;

typedef struct {
    char *id;
    char *errmsg;
} im_import_response;

O
overweight 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
typedef struct {
    char *file;
    char *tag;
    char *type;
} im_load_request;

typedef struct {
    char *errmsg;
} im_load_response;

typedef struct {
    char *type;
    char *image;

    /* auth configs */
    char *username;
    char *password;
    char *auth;
    char *server_address;
    char *identity_token;
    char *registry_token;
} im_pull_request;

typedef struct {
    char *image_ref;
    char *errmsg;
} im_pull_response;

typedef struct {
    char *server;
    char *username;
    char *password;
    char *type;
} im_login_request;

typedef struct {
    char *errmsg;
} im_login_response;

typedef struct {
    char *server;
    char *type;
} im_logout_request;

typedef struct {
    char *errmsg;
} im_logout_response;

D
dogsheng 已提交
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
typedef struct {
    char *type;
} im_image_count_request;

typedef struct {
    char *type;
    char *file;
    char *name_id;
} im_export_request;

typedef struct {
    char *name_id;
    bool force;
} im_umount_request;

typedef struct {
    char *name_id;
} im_mount_request;

typedef struct {
    char *name_id;
186
} im_delete_rootfs_request;
D
dogsheng 已提交
187 188

typedef struct {
189
    char *image_type;
D
dogsheng 已提交
190 191
    char *image_name;
    char *container_id;
192
    char *rootfs; // only used for external image type
D
dogsheng 已提交
193 194 195 196 197 198
    json_map_string_string *storage_opt;
} im_prepare_request;

typedef struct {
    char *name_id;
} im_container_fs_usage_request;
O
overweight 已提交
199

200 201 202 203 204 205
struct graphdriver_status {
    char *driver_name;
    char *backing_fs;
    char *status;
};

O
overweight 已提交
206
struct bim_ops {
207
    int (*init)(const isulad_daemon_configs *args);
D
dogsheng 已提交
208 209
    void (*clean_resource)(void);

O
overweight 已提交
210 211 212
    /* detect whether image is of this bim type */
    bool (*detect)(const char *image_name);

D
dogsheng 已提交
213 214 215 216
    /* rootfs ops */
    int (*prepare_rf)(const im_prepare_request *request, char **real_rootfs);
    int (*mount_rf)(const im_mount_request *request);
    int (*umount_rf)(const im_umount_request *request);
217
    int (*delete_rf)(const im_delete_rootfs_request *request);
D
dogsheng 已提交
218
    int (*export_rf)(const im_export_request *request);
O
overweight 已提交
219 220
    char *(*resolve_image_name)(const char *image_name);

D
dogsheng 已提交
221
    /* merge image config ops */
222
    int (*merge_conf)(const char *img_name, container_config *container_spec);
O
overweight 已提交
223 224

    /* get user config ops */
L
lifeng68 已提交
225
    int (*get_user_conf)(const char *basefs, host_config *hc, const char *userstr, defs_process_user *puser);
O
overweight 已提交
226 227

    /* list images */
D
dogsheng 已提交
228 229 230 231
    int (*list_ims)(const im_list_request *request, imagetool_images_list **images);

    /* get count of images */
    size_t (*get_image_count)(void);
O
overweight 已提交
232 233

    /* remove image */
234
    int (*rm_image)(const im_rmi_request *request);
O
overweight 已提交
235 236

    /* inspect image */
D
dogsheng 已提交
237 238 239 240 241 242 243
    int (*inspect_image)(const im_inspect_request *request, char **inpected_json);

    int (*container_fs_usage)(const im_container_fs_usage_request *request, imagetool_fs_info **fs_usage);

    int (*image_status)(im_status_request *request, im_status_response **response);

    int (*get_filesystem_info)(im_fs_info_response **response);
O
overweight 已提交
244

W
WangFengTu 已提交
245 246 247
    /* import */
    int (*import)(const im_import_request *request, char **id);

O
overweight 已提交
248
    /* load image */
D
dogsheng 已提交
249
    int (*load_image)(const im_load_request *request);
O
overweight 已提交
250 251

    /* pull image */
252
    int (*pull_image)(const im_pull_request *request, im_pull_response *response);
O
overweight 已提交
253 254

    /* login */
D
dogsheng 已提交
255
    int (*login)(const im_login_request *request);
O
overweight 已提交
256 257

    /* logout */
D
dogsheng 已提交
258 259
    int (*logout)(const im_logout_request *request);

W
WangFengTu 已提交
260 261
    /* Add a tag to the image */
    int (*tag_image)(const im_tag_request *request);
O
overweight 已提交
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
};

struct bim {
    /* common arguments */
    const struct bim_ops *ops;
    const char *type;

    char *image_name;
    char *ext_config_image;
    char *container_id;
};

struct bim_type {
    const char *image_type;
    const struct bim_ops *ops;
};

279
int image_module_init(const isulad_daemon_configs *args);
O
overweight 已提交
280

D
dogsheng 已提交
281 282
void image_module_exit();

O
overweight 已提交
283 284
int im_get_container_filesystem_usage(const char *image_type, const char *id, imagetool_fs_info **fs_usage);

D
dogsheng 已提交
285 286 287 288 289 290 291 292
void free_im_container_fs_usage_request(im_container_fs_usage_request *request);

void free_im_prepare_request(im_prepare_request *request);

void free_im_mount_request(im_mount_request *request);

void free_im_umount_request(im_umount_request *request);

293 294 295
void free_im_delete_request(im_delete_rootfs_request *request);

int im_prepare_container_rootfs(const im_prepare_request *request, char **real_rootfs);
D
dogsheng 已提交
296

O
overweight 已提交
297 298
int im_mount_container_rootfs(const char *image_type, const char *image_name, const char *container_id);

D
dogsheng 已提交
299
int im_umount_container_rootfs(const char *image_type, const char *image_name, const char *container_id);
O
overweight 已提交
300 301 302

int im_remove_container_rootfs(const char *image_type, const char *container_id);

303
int im_merge_image_config(const char *image_type, const char *image_name, container_config *container_spec);
O
overweight 已提交
304 305

int im_get_user_conf(const char *image_type, const char *basefs, host_config *hc, const char *userstr,
306
                     defs_process_user *puser);
O
overweight 已提交
307

D
dogsheng 已提交
308
int im_list_images(const im_list_request *request, im_list_response **response);
O
overweight 已提交
309 310 311 312 313

void free_im_list_request(im_list_request *ptr);

void free_im_list_response(im_list_response *ptr);

314
int im_rm_image(const im_rmi_request *request, im_remove_response **response);
O
overweight 已提交
315

316
void free_im_remove_request(im_rmi_request *ptr);
O
overweight 已提交
317 318 319

void free_im_remove_response(im_remove_response *ptr);

W
WangFengTu 已提交
320 321 322 323 324 325
int im_tag_image(const im_tag_request *request, im_tag_response **response);

void free_im_tag_request(im_tag_request *ptr);

void free_im_tag_response(im_tag_response *ptr);

O
overweight 已提交
326 327 328 329 330 331
int im_inspect_image(const im_inspect_request *request, im_inspect_response **response);

void free_im_inspect_request(im_inspect_request *ptr);

void free_im_inspect_response(im_inspect_response *ptr);

W
WangFengTu 已提交
332 333 334 335 336 337
int im_import_image(const im_import_request *request, char **id);

void free_im_import_request(im_import_request *ptr);

void free_im_import_response(im_import_response *ptr);

D
dogsheng 已提交
338
int im_load_image(const im_load_request *request, im_load_response **response);
O
overweight 已提交
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353

void free_im_load_request(im_load_request *ptr);

void free_im_load_response(im_load_response *ptr);

int im_pull_image(const im_pull_request *request, im_pull_response **response);

void free_im_pull_request(im_pull_request *req);

void free_im_pull_response(im_pull_response *resp);

char *im_get_image_type(const char *image, const char *external_rootfs);

bool im_config_image_exist(const char *image_name);

D
dogsheng 已提交
354
int im_login(const im_login_request *request, im_login_response **response);
O
overweight 已提交
355 356 357 358 359

void free_im_login_request(im_login_request *ptr);

void free_im_login_response(im_login_response *ptr);

D
dogsheng 已提交
360
int im_logout(const im_logout_request *request, im_logout_response **response);
O
overweight 已提交
361 362 363 364 365

void free_im_logout_request(im_logout_request *ptr);

void free_im_logout_response(im_logout_response *ptr);

D
dogsheng 已提交
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
int im_image_status(im_status_request *request, im_status_response **response);

void free_im_status_request(im_status_request *req);

void free_im_status_response(im_status_response *resp);

int im_get_filesystem_info(const char *image_type, im_fs_info_response **response);

void free_im_fs_info_response(im_fs_info_response *ptr);

size_t im_get_image_count(const im_image_count_request *request);

void free_im_image_count_request(im_image_count_request *ptr);

int im_container_export(const im_export_request *request);

void free_im_export_request(im_export_request *ptr);

int im_resolv_image_name(const char *image_type, const char *image_name, char **resolved_name);

386 387 388 389 390 391
container_inspect_graph_driver *im_graphdriver_get_metadata(const char *id);

struct graphdriver_status *im_graphdriver_get_status(void);

void im_free_graphdriver_status(struct graphdriver_status *status);

392
bool im_oci_image_exist(const char *image_or_id);
393

O
overweight 已提交
394 395 396 397 398
#ifdef __cplusplus
}
#endif

#endif