提交 07a1f549 编写于 作者: G gaohuatao 提交者: lifeng68

add isula load image function

Signed-off-by: Ngaohuatao <gaohuatao@huawei.com>
(cherry picked from commit 02eadfad196475979e33fb410e7a70352a667eec)
Signed-off-by: Ngaohuatao <gaohuatao@huawei.com>
上级 3f6f6c85
......@@ -359,3 +359,36 @@ out:
return base_name;
}
char *oci_calc_diffid(const char *file)
{
int ret = 0;
char *diff_id = NULL;
bool gzip = false;
if (file == NULL) {
ERROR("Invalid NULL param");
return NULL;
}
ret = util_gzip_compressed(file, &gzip);
if (ret != 0) {
ERROR("Get layer file %s gzip attribute failed", file);
goto out;
}
if (gzip) {
diff_id = util_full_gzip_digest(file);
} else {
diff_id = util_full_file_digest(file);
}
if (diff_id == NULL) {
ERROR("calculate digest failed for file %s", file);
ret = -1;
}
out:
if (ret != 0) {
UTIL_FREE_AND_SET_NULL(diff_id);
}
return diff_id;
}
......@@ -30,6 +30,7 @@ extern "C" {
#define DEFAULT_TAG ":latest"
#define DEFAULT_HOSTNAME "docker.io/"
#define DEFAULT_REPO_PREFIX "library/"
#define MAX_ID_BUF_LEN 256
char *oci_get_host(const char *name);
char *oci_host_from_mirror(const char *mirror);
......@@ -40,6 +41,7 @@ int oci_split_image_name(const char *image_name, char **host, char **name, char
char *oci_full_image_name(const char *host, const char *name, const char *tag);
char *oci_strip_dockerio_prefix(const char *name);
char *make_big_data_base_name(const char *key);
char *oci_calc_diffid(const char *file);
#ifdef __cplusplus
}
......
......@@ -25,10 +25,10 @@
#include "registry.h"
#include "utils.h"
#include "storage.h"
#include "oci_load.h"
#define IMAGE_NOT_KNOWN_ERR "image not known"
static int storage_module_init_helper(const struct service_arguments *args)
{
int ret = 0;
......@@ -412,8 +412,7 @@ int oci_load_image(const im_load_request *request)
return -1;
}
// TODO call storage metadata load interface
//ret = isula_image_load(request->file, request->tag, &refs);
ret = oci_do_load(request);
if (ret != 0) {
ERROR("Failed to load image");
goto out;
......
此差异已折叠。
/******************************************************************************
* Copyright (c) Huawei Technologies Co., Ltd. 2019. 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: gaohuatao
* Create: 2020-05-14
* Description: isula load operator implement
*******************************************************************************/
#ifndef __IMAGE_OCI_LOAD_H
#define __IMAGE_OCI_LOAD_H
#include "image.h"
#include "image_manifest_items.h"
#include "oci_image_manifest.h"
#include "oci_image_spec.h"
#include "json_common.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
// uncompressed_digest
char *diff_id;
// compressed digest
char *compressed_digest;
char *chain_id;
char *fpath;
} load_layer_blob_t;
typedef struct {
load_layer_blob_t **layers;
size_t layers_len;
char **repo_tags;
size_t repo_tags_len;
char *config_fpath;
char *im_id;
char *im_digest;
char *manifest_fpath;
char *manifest_digest;
types_timestamp_t create_time;
oci_image_manifest *manifest;
} load_image_t;
int oci_do_load(const im_load_request *request);
#ifdef __cplusplus
}
#endif
#endif
......@@ -40,6 +40,7 @@
#include "isulad_config.h"
#include "storage.h"
#include "constants.h"
#include "utils_images.h"
#define MAX_LAYER_NUM 125
#define MANIFEST_BIG_DATA_KEY "manifest"
......@@ -428,7 +429,7 @@ out:
static char *calc_chain_id(char *parent_chain_id, char *diff_id)
{
int sret = 0;
char tmp_buffer[256] = {0};
char tmp_buffer[MAX_ID_BUF_LEN] = {0};
char *digest = NULL;
char *full_digest = NULL;
......@@ -526,43 +527,6 @@ static int set_cached_info_to_desc(thread_fetch_info *infos, size_t infos_len, p
return 0;
}
static char *calc_diffid(char *file)
{
int ret = 0;
char *diff_id = NULL;
bool gzip = false;
if (file == NULL) {
ERROR("Invalid NULL param");
return NULL;
}
ret = util_gzip_compressed(file, &gzip);
if (ret != 0) {
// consider it as gziped just like media type indicated if we cann't determined if it's gziped.
gzip = true;
}
if (gzip) {
diff_id = util_full_gzip_digest(file);
} else {
diff_id = util_full_file_digest(file);
}
if (diff_id == NULL) {
ERROR("calculate digest failed for file %s", file);
ret = -1;
goto out;
}
out:
if (ret != 0) {
free(diff_id);
diff_id = NULL;
}
return diff_id;
}
static char *without_sha256_prefix(char *digest)
{
if (digest == NULL) {
......@@ -1138,7 +1102,7 @@ static int fetch_one_layer(thread_fetch_info *info)
goto out;
}
diffid = calc_diffid(info->file);
diffid = oci_calc_diffid(info->file);
if (diffid == NULL) {
ERROR("calc diffid for layer %d failed", info->index);
ret = -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册