ext_image.c 4.2 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 15 16 17 18 19 20 21 22 23
 * Author: tanyifeng
 * Create: 2018-11-08
 * Description: provide image functions
 ******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <string.h>
#include <limits.h>
#include <sys/utsname.h>
#include <ctype.h>

H
haozi007 已提交
24
#include "isula_libutils/log.h"
O
overweight 已提交
25 26 27 28
#include "utils.h"
#include "ext_image.h"

#ifdef ENABLE_OCI_IMAGE
29
#include "storage.h"
D
dogsheng 已提交
30
#include "oci_common_operators.h"
O
overweight 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include "oci_config_merge.h"
#endif

bool ext_detect(const char *image_name)
{
    if (image_name == NULL) {
        return false;
    }

    if (image_name[0] != '/') {
        INFO("Rootfs should be absolutely path");
        return false;
    }

    return util_file_exists(image_name);
}
D
dogsheng 已提交
47
int ext_filesystem_usage(const im_container_fs_usage_request *request, imagetool_fs_info **fs_usage)
O
overweight 已提交
48 49 50 51
{
    return 0;
}

D
dogsheng 已提交
52
int ext_prepare_rf(const im_prepare_request *request, char **real_rootfs)
O
overweight 已提交
53 54 55
{
    int ret = 0;

D
dogsheng 已提交
56 57 58 59 60
    if (request == NULL) {
        ERROR("Invalid arguments");
        return -1;
    }

O
overweight 已提交
61
    if (real_rootfs != NULL) {
62
        if (request->rootfs != NULL) {
O
overweight 已提交
63
            char real_path[PATH_MAX] = { 0 };
64
            if (request->rootfs[0] != '/') {
O
overweight 已提交
65
                ERROR("Rootfs should be absolutely path");
L
LiuHao 已提交
66
                isulad_set_error_message("Rootfs should be absolutely path");
O
overweight 已提交
67 68
                return -1;
            }
69 70 71
            if (realpath(request->rootfs, real_path) == NULL) {
                ERROR("Failed to clean rootfs path '%s': %s", request->rootfs, strerror(errno));
                isulad_set_error_message("Failed to clean rootfs path '%s': %s", request->rootfs, strerror(errno));
O
overweight 已提交
72 73 74 75 76 77 78 79 80 81 82
                return -1;
            }
            *real_rootfs = util_strdup_s(real_path);
        } else {
            ERROR("Failed to get external rootfs");
            ret = -1;
        }
    }
    return ret;
}

D
dogsheng 已提交
83
int ext_mount_rf(const im_mount_request *request)
O
overweight 已提交
84 85 86 87
{
    return 0;
}

D
dogsheng 已提交
88
int ext_umount_rf(const im_umount_request *request)
O
overweight 已提交
89 90 91 92
{
    return 0;
}

93
int ext_delete_rf(const im_delete_rootfs_request *request)
O
overweight 已提交
94 95 96 97 98 99 100 101 102
{
    return 0;
}

char *ext_resolve_image_name(const char *image_name)
{
    return util_strdup_s(image_name);
}

103
int ext_merge_conf(const char *img_name, container_config *container_spec)
D
dogsheng 已提交
104
#ifdef ENABLE_OCI_IMAGE
O
overweight 已提交
105 106 107 108
{
    int ret = 0;

    // No config neeed merge if NULL.
109
    if (img_name == NULL) {
O
overweight 已提交
110 111 112 113
        ret = 0;
        goto out;
    }

114 115 116
    ret = oci_image_conf_merge_into_spec(img_name, container_spec);
    if (ret != 0) {
        ERROR("Failed to merge oci config for image: %s", img_name);
117 118 119
        ret = -1;
        goto out;
    }
O
overweight 已提交
120 121 122 123 124 125

out:
    return ret;
}
#else
{
126
    return 0;
O
overweight 已提交
127 128 129
}
#endif

130
int ext_get_user_conf(const char *basefs, host_config *hc, const char *userstr, defs_process_user *puser)
O
overweight 已提交
131 132 133 134 135 136 137 138
{
    if (basefs == NULL || puser == NULL) {
        ERROR("Empty basefs or puser");
        return -1;
    }
    return get_user(basefs, hc, userstr, puser);
}

D
dogsheng 已提交
139
int ext_list_images(const im_list_request *request, imagetool_images_list **list)
O
overweight 已提交
140 141 142 143 144 145 146 147 148 149 150 151 152
{
    int ret = 0;

    *list = util_common_calloc_s(sizeof(imagetool_images_list));
    if (*list == NULL) {
        ERROR("Memory out");
        ret = -1;
        goto out;
    }
out:
    return ret;
}

153
int ext_remove_image(const im_rmi_request *request)
O
overweight 已提交
154 155 156 157
{
    return 0;
}

D
dogsheng 已提交
158
int ext_inspect_image(const im_inspect_request *request, char **inspected_json)
O
overweight 已提交
159 160 161 162
{
    return 0;
}

D
dogsheng 已提交
163
int ext_load_image(const im_load_request *request)
O
overweight 已提交
164 165 166 167
{
    return 0;
}

D
dogsheng 已提交
168
int ext_login(const im_login_request *request)
O
overweight 已提交
169 170 171 172
{
    return 0;
}

D
dogsheng 已提交
173
int ext_logout(const im_logout_request *request)
O
overweight 已提交
174 175 176 177
{
    return 0;
}

178
int ext_init(const isulad_daemon_configs *args)
O
overweight 已提交
179 180 181
{
    return 0;
}