提交 d7c4d869 编写于 作者: W WangFengTu 提交者: lifeng68

serial pulling image's layers

concurrent downloading only happen between different images
Signed-off-by: NWangFengTu <wangfengtu@huawei.com>
上级 b8770356
......@@ -1648,4 +1648,4 @@ char *util_int_to_string(long long int data)
}
return util_strdup_s(numstr);
}
\ No newline at end of file
}
......@@ -326,8 +326,8 @@ int http_request(const char *url, struct http_get_options *options, long *respon
/* set URL to get here */
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1L);
/* complete connection within 5 seconds */
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 5L);
/* complete connection within 15 seconds */
curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 15L);
/* provide a buffer to store errors in */
curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, errbuf);
curl_easy_setopt(curl_handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
......
......@@ -1048,20 +1048,11 @@ static void set_cached_layers_info(char *blob_digest, char *diffid, int result,
return;
}
static void *fetch_layer_in_thread(void *arg)
static int fetch_one_layer(thread_fetch_info *info)
{
thread_fetch_info *info = (thread_fetch_info *)arg;
int ret = 0;
char *diffid = NULL;
ret = pthread_detach(pthread_self());
if (ret != 0) {
ERROR("Set thread detach fail");
goto out;
}
prctl(PR_SET_NAME, "fetch_layer");
if (fetch_layer(info->desc, info->index) != 0) {
ERROR("fetch layer %d failed", info->index);
ret = -1;
......@@ -1088,14 +1079,13 @@ out:
free(diffid);
diffid = NULL;
return NULL;
return ret;
}
static int add_fetch_task(thread_fetch_info *info)
static int do_fetch(thread_fetch_info *info)
{
int ret = 0;
int cond_ret = 0;
pthread_t tid = 0;
bool cached_layers_added = true;
cached_layer *cache = NULL;
......@@ -1108,7 +1098,7 @@ static int add_fetch_task(thread_fetch_info *info)
if (cond_ret != 0) {
ERROR("condition wait failed, ret %d", cond_ret);
ret = -1;
goto out;
goto unlock_out;
}
}
}
......@@ -1117,27 +1107,35 @@ static int add_fetch_task(thread_fetch_info *info)
if (ret != 0) {
ERROR("add fetch info failed, ret %d", cond_ret);
ret = -1;
goto out;
goto unlock_out;
}
cached_layers_added = true;
// First request to download this blob.
if (cache == NULL) {
ret = pthread_create(&tid, NULL, fetch_layer_in_thread, info);
g_shared->count++;
}
mutex_unlock(&g_shared->mutex);
if (cache == NULL) {
ret = fetch_one_layer(info);
if (ret != 0) {
ERROR("failed to start thread to fetch layer %d", (int)info->index);
goto out;
}
g_shared->count++;
}
goto out;
unlock_out:
mutex_unlock(&g_shared->mutex);
out:
if (ret != 0 && cached_layers_added) {
mutex_lock(&g_shared->mutex);
del_cached_layer(info->blob_digest, info->file);
mutex_unlock(&g_shared->mutex);
}
mutex_unlock(&g_shared->mutex);
return ret;
}
......@@ -1233,7 +1231,7 @@ static int fetch_layers(pull_descriptor *desc)
infos[i].file = util_strdup_s(file);
infos[i].blob_digest = util_strdup_s(desc->layers[i].digest);
ret = add_fetch_task(&infos[i]);
ret = do_fetch(&infos[i]);
if (ret != 0) {
goto out;
}
......@@ -1347,7 +1345,7 @@ static int add_rootfs_and_history(pull_descriptor *desc, docker_image_config_v2
config->rootfs = util_common_calloc_s(sizeof(docker_image_rootfs));
config->history = util_common_calloc_s(sizeof(docker_image_history*)*desc->layers_len);
if (config->rootfs == NULL || config->history) {
if (config->rootfs == NULL || config->history == NULL) {
ERROR("out of memory");
return -1;
}
......
......@@ -268,9 +268,12 @@ static int parse_ping_header(pull_descriptor *desc, char *http_head)
version = get_header_value(message, "Docker-Distribution-Api-Version");
if (version == NULL) {
ERROR("Docker-Distribution-Api-Version not found in header, registry can not support registry API V2");
ret = -1;
goto out;
version = get_header_value(message, "Docker-Distribution-API-Version");
if (version == NULL) {
ERROR("Docker-Distribution-Api-Version not found in header, registry may can not support registry API V2");
ret = -1;
goto out;
}
}
if (!strings_contains_word(version, "registry/2.0")) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册