summaryrefslogtreecommitdiff
path: root/0027-improve-code-of-pull-progress.patch
blob: 86b4ecac7847092e7e193978ee2e0f1801263ea8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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
112
113
114
115
116
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
From 78304f7ad584517e02125c928e976f34aaf859f8 Mon Sep 17 00:00:00 2001
From: haozi007 <liuhao27@huawei.com>
Date: Wed, 22 Nov 2023 15:00:43 +0800
Subject: [PATCH 27/64] improve code of pull progress

Signed-off-by: haozi007 <liuhao27@huawei.com>
---
 src/client/connect/CMakeLists.txt             |   7 +-
 src/client/connect/grpc/grpc_images_client.cc |  48 ++----
 .../connect/grpc/grpc_volumes_client.cc       |   1 -
 src/daemon/common/events_format.h             |   2 +
 .../v1/v1_cri_image_manager_service_impl.cc   |   2 -
 .../v1alpha/cri_image_manager_service_impl.cc |   2 -
 src/daemon/executor/image_cb/image_cb.c       |   2 +
 src/daemon/modules/api/event_type.h           |   4 +-
 src/daemon/modules/events/collector.c         |   4 +-
 src/daemon/modules/image/image.c              |   2 +-
 src/daemon/modules/image/oci/oci_pull.c       | 146 ++++++++++--------
 src/daemon/modules/image/oci/progress.c       |  28 +++-
 src/daemon/modules/image/oci/progress.h       |   6 +-
 .../modules/image/oci/registry/http_request.c |  28 +---
 .../oci/storage/image_store/image_store.c     |   2 +-
 .../graphdriver/overlay2/driver_overlay2.c    |   2 +-
 .../modules/image/oci/storage/storage.c       |   5 +-
 17 files changed, 137 insertions(+), 154 deletions(-)

diff --git a/src/client/connect/CMakeLists.txt b/src/client/connect/CMakeLists.txt
index 00ba2f68..d4ce6c9c 100644
--- a/src/client/connect/CMakeLists.txt
+++ b/src/client/connect/CMakeLists.txt
@@ -12,10 +12,7 @@ if (GRPC_CONNECTOR)
     aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/containers CONNECT_API_CONTAINERS)
     aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/images CONNECT_API_IMAGES)
     aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/volumes CONNECT_API_VOLUMES)
-    # TODO: current isula pull use CRI pullImage API, we should remove this dependence
-    aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/cri CONNECT_API_CRI)
-    aux_source_directory(${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1alpha CONNECT_API_CRI_ALPHAS)
-    set(CONNECT_API ${CONNECT_API_VOLUMES} ${CONNECT_API_CONTAINERS} ${CONNECT_API_IMAGES} ${CONNECT_API_CRI_ALPHAS} ${CONNECT_API_CRI})
+    set(CONNECT_API ${CONNECT_API_VOLUMES} ${CONNECT_API_CONTAINERS} ${CONNECT_API_IMAGES})
     list(APPEND local_client_connect_srcs ${CONNECT_API})
 
     list(APPEND local_client_connect_incs ${CMAKE_CURRENT_SOURCE_DIR}/grpc)
@@ -23,8 +20,6 @@ if (GRPC_CONNECTOR)
         ${CMAKE_BINARY_DIR}/grpc/src/api/services/volumes
         ${CMAKE_BINARY_DIR}/grpc/src/api/services/containers
         ${CMAKE_BINARY_DIR}/grpc/src/api/services/images
-        ${CMAKE_BINARY_DIR}/grpc/src/api/services/cri
-        ${CMAKE_BINARY_DIR}/grpc/src/api/services/cri/v1alpha
         )
 
     if(ENABLE_NATIVE_NETWORK)
diff --git a/src/client/connect/grpc/grpc_images_client.cc b/src/client/connect/grpc/grpc_images_client.cc
index 7a283e8c..7fd36cc1 100644
--- a/src/client/connect/grpc/grpc_images_client.cc
+++ b/src/client/connect/grpc/grpc_images_client.cc
@@ -390,50 +390,20 @@ public:
         return 0;
     }
 
-    auto run(const struct isula_pull_request *request, struct isula_pull_response *response) -> int override
-    {
-        ClientContext context;
-        PullImageRequest grequest;
-
-#ifdef ENABLE_GRPC_REMOTE_CONNECT
-#ifdef OPENSSL_VERIFY
-        // Set common name from cert.perm
-        char common_name_value[ClientBaseConstants::COMMON_NAME_LEN] = { 0 };
-        int ret = get_common_name_from_tls_cert(m_certFile.c_str(), common_name_value,
-                                                ClientBaseConstants::COMMON_NAME_LEN);
-        if (ret != 0) {
-            ERROR("Failed to get common name in: %s", m_certFile.c_str());
-            return -1;
-        }
-        context.AddMetadata("username", std::string(common_name_value, strlen(common_name_value)));
-        context.AddMetadata("tls_mode", m_tlsMode);
-#endif
-#endif
-        if (request_to_grpc(request, &grequest) != 0) {
-            ERROR("Failed to transform pull request to grpc");
-            response->server_errono = ISULAD_ERR_INPUT;
-            return -1;
-        }
-
-        auto reader = stub_->PullImage(&context, grequest);
+    auto grpc_call(ClientContext *context, const PullImageRequest &req, PullImageResponse *reply) -> Status override
+    {
+        auto reader = stub_->PullImage(context, req);
 
-        PullImageResponse gresponse;
-        if (grequest.is_progress_visible()) {
-            while (reader->Read(&gresponse)) {
-                output_progress(gresponse);
+        if (req.is_progress_visible()) {
+            while (reader->Read(reply)) {
+                output_progress(*reply);
             }
         } else {
-            reader->Read(&gresponse);
+            reader->Read(reply);
             WARN("The terminal may not support ANSI Escape code. Display is skipped");
         }
-        Status status = reader->Finish();
-        if (!status.ok()) {
-            ERROR("Error code: %d: %s", status.error_code(), status.error_message().c_str());
-            unpackStatus(status, response);
-            return -1;
-        }
-        response->image_ref = util_strdup_s(gresponse.image_ref().c_str());
-        return 0;
+
+        return reader->Finish();
     }
 
 private:
diff --git a/src/client/connect/grpc/grpc_volumes_client.cc b/src/client/connect/grpc/grpc_volumes_client.cc
index 32b83a9e..5fe8ed5e 100644
--- a/src/client/connect/grpc/grpc_volumes_client.cc
+++ b/src/client/connect/grpc/grpc_volumes_client.cc
@@ -16,7 +16,6 @@
 
 #include <string>
 
-#include "api.grpc.pb.h"
 #include "client_base.h"
 #include "volumes.grpc.pb.h"
 #include "utils.h"
diff --git a/src/daemon/common/events_format.h b/src/daemon/common/events_format.h
index 7e97b2c5..6b8fcfd5 100644
--- a/src/daemon/common/events_format.h
+++ b/src/daemon/common/events_format.h
@@ -64,6 +64,8 @@ typedef enum {
     EVENTS_TYPE_IMAGE_PULL,
     EVENTS_TYPE_IMAGE_LOGIN,
     EVENTS_TYPE_IMAGE_LOGOUT,
+    EVENTS_TYPE_IMAGE_IMPORT,
+    EVENTS_TYPE_IMAGE_TAG,
     EVENTS_TYPE_IMAGE_MAX_STATE
 } image_events_type_t;
 
diff --git a/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc b/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc
index b9cbf24c..066eed5e 100644
--- a/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc
+++ b/src/daemon/entry/cri/v1/v1_cri_image_manager_service_impl.cc
@@ -25,7 +25,6 @@
 
 #include "v1_cri_helpers.h"
 #include "err_msg.h"
-#include "events_sender_api.h"
 #include "isula_libutils/log.h"
 #include "service_image_api.h"
 #include "utils.h"
@@ -277,7 +276,6 @@ auto ImageManagerServiceImpl::PullImage(const runtime::v1::ImageSpec &image,
     if (response->image_ref != nullptr) {
         out_str = response->image_ref;
     }
-    (void)isulad_monitor_send_image_event(request->image, IM_PULL);
 
 cleanup:
     DAEMON_CLEAR_ERRMSG();
diff --git a/src/daemon/entry/cri/v1alpha/cri_image_manager_service_impl.cc b/src/daemon/entry/cri/v1alpha/cri_image_manager_service_impl.cc
index 0b36f007..9015df26 100644
--- a/src/daemon/entry/cri/v1alpha/cri_image_manager_service_impl.cc
+++ b/src/daemon/entry/cri/v1alpha/cri_image_manager_service_impl.cc
@@ -25,7 +25,6 @@
 
 #include "cri_helpers.h"
 #include "err_msg.h"
-#include "events_sender_api.h"
 #include "isula_libutils/log.h"
 #include "service_image_api.h"
 #include "utils.h"
@@ -277,7 +276,6 @@ auto ImageManagerServiceImpl::PullImage(const runtime::v1alpha2::ImageSpec &imag
     if (response->image_ref != nullptr) {
         out_str = response->image_ref;
     }
-    (void)isulad_monitor_send_image_event(request->image, IM_PULL);
 
 cleanup:
     DAEMON_CLEAR_ERRMSG();
diff --git a/src/daemon/executor/image_cb/image_cb.c b/src/daemon/executor/image_cb/image_cb.c
index 317cb0a8..60899f2b 100644
--- a/src/daemon/executor/image_cb/image_cb.c
+++ b/src/daemon/executor/image_cb/image_cb.c
@@ -519,6 +519,7 @@ static int image_tag_cb(const image_tag_image_request *request, image_tag_image_
     }
 
     EVENT("Image Event: {Object: %s, Type: Tagged}", request->src_name);
+    (void)isulad_monitor_send_image_event(request->src_name, IM_TAG);
 
 out:
     if (*response != NULL) {
@@ -997,6 +998,7 @@ static int image_pull_cb(const image_pull_image_request *request, stream_func_wr
     }
 
     EVENT("Image Event: {Object: %s, Type: Pulled}", request->image_name);
+    (void)isulad_monitor_send_image_event(request->image_name, IM_PULL);
 
 out:
     (*response)->cc = cc;
diff --git a/src/daemon/modules/api/event_type.h b/src/daemon/modules/api/event_type.h
index c3c7951b..4f2aaf28 100644
--- a/src/daemon/modules/api/event_type.h
+++ b/src/daemon/modules/api/event_type.h
@@ -54,7 +54,9 @@ typedef enum {
     MAX_STATE,
 } runtime_state_t;
 
-typedef enum { IM_LOAD, IM_REMOVE, IM_PULL, IM_LOGIN, IM_LOGOUT, IM_IMPORT } image_state_t;
+// relate to g_isulad_image_event_strtype and image_events_type_t
+// we should keep them consistent
+typedef enum { IM_LOAD, IM_REMOVE, IM_PULL, IM_LOGIN, IM_LOGOUT, IM_IMPORT, IM_TAG } image_state_t;
 
 typedef enum { CONTAINER_EVENT, IMAGE_EVENT } msg_event_type_t;
 typedef enum { MONITORD_MSG_STATE, MONITORD_MSG_PRIORITY, MONITORD_MSG_EXIT_CODE } msg_type_t;
diff --git a/src/daemon/modules/events/collector.c b/src/daemon/modules/events/collector.c
index b82ede81..36aa9299 100644
--- a/src/daemon/modules/events/collector.c
+++ b/src/daemon/modules/events/collector.c
@@ -157,11 +157,11 @@ static const char *isulad_event_sta2str(container_events_type_t sta)
     return g_isulad_event_strtype[sta];
 }
 
-static const char * const g_isulad_image_event_strtype[] = { "load", "remove", "pull", "login", "logout" };
+static const char * const g_isulad_image_event_strtype[] = { "load", "remove", "pull", "login", "logout", "import", "tag" };
 
 static const char *isulad_image_event_sta2str(image_events_type_t sta)
 {
-    if (sta > EVENTS_TYPE_IMAGE_LOGOUT) {
+    if (sta >= EVENTS_TYPE_IMAGE_MAX_STATE) {
         return NULL;
     }
 
diff --git a/src/daemon/modules/image/image.c b/src/daemon/modules/image/image.c
index 8d7e2c1a..4a1950fe 100644
--- a/src/daemon/modules/image/image.c
+++ b/src/daemon/modules/image/image.c
@@ -784,7 +784,7 @@ int im_merge_image_config(const char *image_type, const char *image_name, contai
     int ret = 0;
     struct bim *bim = NULL;
 
-    // there is no need to judge the image name as empty, 
+    // there is no need to judge the image name as empty,
     // because the image name of external type allows it to be empty.
     if (container_spec == NULL || image_type == NULL) {
         ERROR("Invalid input arguments");
diff --git a/src/daemon/modules/image/oci/oci_pull.c b/src/daemon/modules/image/oci/oci_pull.c
index 2706af91..9ad875a5 100644
--- a/src/daemon/modules/image/oci/oci_pull.c
+++ b/src/daemon/modules/image/oci/oci_pull.c
@@ -75,7 +75,8 @@ out:
     return ret;
 }
 
-static void update_option_insecure_registry(registry_pull_options *options, char **insecure_registries, const char *host)
+static void update_option_insecure_registry(registry_pull_options *options, char **insecure_registries,
+                                            const char *host)
 {
     char **registry = NULL;
 
@@ -188,83 +189,95 @@ typedef struct status_arg {
     stream_func_wrapper *stream;
 } status_arg;
 
+static int do_get_progress_from_store(progress_status_map *status_store, image_progress *result)
+{
+    int i = 0;
+    size_t progress_size = progress_status_map_size(status_store);
+
+    result->progresses = util_smart_calloc_s(sizeof(image_progress_progresses_element *), progress_size);
+    if (result->progresses == NULL) {
+        ERROR("Out of memory");
+        return -1;
+    }
+
+    if (!progress_status_map_lock(status_store)) {
+        WARN("Cannot itorate progress status map for locking failed");
+        // ignore lock error, retry lock after delay.
+        return 0;
+    }
+
+    map_itor *itor = map_itor_new(status_store->map);
+    for (i = 0; map_itor_valid(itor) && i < progress_size; map_itor_next(itor), i++) {
+        void *id = map_itor_key(itor);
+        const progress *value = (progress *)map_itor_value(itor);
+        const int ID_LEN = 12; // The last 12 charactos of image digest.
+
+        result->progresses[i] = util_common_calloc_s(sizeof(image_progress_progresses_element));
+        if (result->progresses[i] == NULL) {
+            // ignore error, return got progress data
+            WARN("Out of memory");
+            break;
+        }
+        result->progresses[i]->id = util_strdup_s((char *)id + strlen((char *)id) - ID_LEN);
+        result->progresses[i]->total = value->dltotal;
+        result->progresses[i]->current = value->dlnow;
+        result->progresses_len++;
+    }
+    map_itor_free(itor);
+    progress_status_map_unlock(status_store);
+
+    return 0;
+}
+
 void *get_progress_status(void *arg)
 {
     status_arg *status = (status_arg *)arg;
-    const int delay = 100; // Sleep for 100 milliseconds
-    bool write_ok = false;
+
+    prctl(PR_SET_NAME, "PullProgress");
 
     if (status == NULL || status->status_store == NULL || status->stream == NULL) {
         ERROR("Get progress status condition error");
         return NULL;
     }
 
-    for (;;) {
-        int i = 0;
-        
-        usleep(delay * 1000);  // Sleep for 100 milliseconds
+    while (!status->should_terminal || status->image != NULL) {
+        bool write_ok = false;
+        image_progress *iprogresses = NULL;
 
-        if (status->should_terminal && status->image == NULL) {
+        // Step 1: delay 100ms, wait progress update
+        util_usleep_nointerupt(100 * 1000);
+
+        // Step 2: check client whether is canceled?
+        if (status->stream->is_cancelled(status->stream->context)) {
+            WARN("pull stream is cancelled");
             break;
         }
-        
-        image_progress *progresses;
-        size_t progress_size = progress_status_map_size(status->status_store);
 
-        progresses = util_common_calloc_s(sizeof(image_progress));
-        if (progresses == NULL) {
-            ERROR("Out of memory. Skip progress show.");
-            break;   
+        iprogresses = util_common_calloc_s(sizeof(image_progress));
+        if (iprogresses == NULL) {
+            ERROR("Out of memory");
+            break;
         }
-
-        progresses->progresses = util_smart_calloc_s(sizeof(image_progress_progresses_element *), progress_size);
-        if (progresses->progresses == NULL) {
-            ERROR("Out of memory. Skip progress show.");
-            goto roundend;
+        // Step 3: get progress of pull from progress status store
+        if (do_get_progress_from_store(status->status_store, iprogresses) != 0) {
+            free_image_progress(iprogresses);
+            break;
         }
+
+        // Step 4: check main thread whether is finished, and setted pulled image info
         if (status->image != NULL) {
-            progresses->image = util_strdup_s(status->image_name);
+            iprogresses->image = util_strdup_s(status->image_name);
             status->image = NULL;
         }
 
-        if (!progress_status_map_lock(status->status_store)) {
-            ERROR("Cannot itorate progress status map for locking failed");
-            goto roundend;
-        }
-        map_itor *itor = map_itor_new(status->status_store->map); 
-        for (i = 0; map_itor_valid(itor) && i < progress_size; map_itor_next(itor), i++) {
-            void *id = map_itor_key(itor);
-            const progress *value = (progress *)map_itor_value(itor);
-            const int ID_LEN = 12; // The last 12 charactos of image digest.
-
-            progresses->progresses[i] = util_common_calloc_s(sizeof(image_progress_progresses_element));
-            if (progresses->progresses[i] == NULL) {
-                WARN("Out of memory. Skip progress show.");
-                map_itor_free(itor);
-                progress_status_map_unlock(status->status_store);
-                goto roundend;
-            }
-            progresses->progresses[i]->id = util_strdup_s((char *)id + strlen((char *)id) - ID_LEN);
-            progresses->progresses[i]->total = value->dltotal;
-            progresses->progresses[i]->current = value->dlnow;
-            progresses->progresses_len++;
+        // Step 5: send got progress of pull to client
+        write_ok = status->stream->write_func(status->stream->writer, iprogresses);
+        if (!write_ok) {
+            WARN("Send progress data to client failed, just ignore and retry it");
         }
-        map_itor_free(itor);
-        progress_status_map_unlock(status->status_store);
-    
-        /* send to client */
-        write_ok = status->stream->write_func(status->stream->writer, progresses);
-        if (write_ok) {
-            goto roundend;
-        } 
-        if (status->stream->is_cancelled(status->stream->context)) {
-            ERROR("pull stream is cancelled");
-            goto roundend;
-        }    
-        ERROR("Send progress data to client failed");
-roundend:
-        free_image_progress(progresses);
+        free_image_progress(iprogresses);
     }
+
     return NULL;
 }
 
@@ -286,7 +299,7 @@ int oci_do_pull_image(const im_pull_request *request, stream_func_wrapper *strea
     if (request->is_progress_visible && stream != NULL) {
         progress_status_store = progress_status_map_new();
         if (progress_status_store == NULL) {
-            ERROR("Out of memory and will not show the pull progress");
+            ERROR("Out of memory");
             isulad_set_error_message("Failed to pull image %s with error: out of memory", request->image);
             ret = -1;
             goto out;
@@ -321,21 +334,28 @@ int oci_do_pull_image(const im_pull_request *request, stream_func_wrapper *strea
     arg.image = image;
     arg.image_name = dest_image_name;
     if (!request->is_progress_visible && stream != NULL) {
-        image_progress *progresses;
+        image_progress *progresses = NULL;
+        bool nret = false;
 
         progresses = util_common_calloc_s(sizeof(image_progress));
         if (progresses == NULL) {
-            ERROR("Out of memory. Skip progress show.");
-            goto out;   
+            ERROR("Out of memory");
+            isulad_set_error_message("Failed to pull image %s with error: out of memory", request->image);
+            ret = -1;
+            goto out;
         }
         progresses->image = util_strdup_s(dest_image_name);
-        if (stream->write_func(stream->writer, progresses)) {
+        nret = stream->write_func(stream->writer, progresses);
+        free_image_progress(progresses);
+        if (!nret) {
             ERROR("Send progress data to client failed");
+            isulad_set_error_message("Failed to pull image %s with error: send progress data to client failed", request->image);
+            ret = -1;
             goto out;
         }
     }
     response->image_ref = util_strdup_s(image->id);
-    
+
 out:
     arg.should_terminal = true;
     if (tid != 0 && pthread_join(tid, NULL) != 0) {
diff --git a/src/daemon/modules/image/oci/progress.c b/src/daemon/modules/image/oci/progress.c
index 110f22c0..7d0c10a4 100644
--- a/src/daemon/modules/image/oci/progress.c
+++ b/src/daemon/modules/image/oci/progress.c
@@ -34,15 +34,16 @@ size_t progress_status_map_size(progress_status_map *progress_status_map)
     }
     ret = map_size(progress_status_map->map);
     progress_status_map_unlock(progress_status_map);
-    
+
     return ret;
 }
 
-bool progress_status_map_insert(progress_status_map *progress_status_map, char *key, progress *value)
+bool progress_status_map_udpate(progress_status_map *progress_status_map, char *key, int64_t current, int64_t total)
 {
     bool ret = false;
+    progress *pval = NULL;
 
-    if (progress_status_map == NULL || key == NULL || value == NULL) {
+    if (progress_status_map == NULL || key == NULL) {
         ERROR("Invalid parameter");
         return false;
     }
@@ -51,9 +52,26 @@ bool progress_status_map_insert(progress_status_map *progress_status_map, char *
         ERROR("Cannot replace the progress status map item for locking failed");
         return false;
     }
-    ret = map_insert(progress_status_map->map, key, value);
-    progress_status_map_unlock(progress_status_map);
 
+    // If the item exists, only replace the value.
+    pval = map_search(progress_status_map->map, key);
+    if (pval != NULL) {
+        pval->dlnow = current;
+        pval->dltotal = total;
+        progress_status_map_unlock(progress_status_map);
+        return true;
+    }
+    pval = util_common_calloc_s(sizeof(progress));
+    if (pval == NULL) {
+        ERROR("Out of memory");
+        progress_status_map_unlock(progress_status_map);
+        return false;
+    }
+    pval->dlnow = current;
+    pval->dltotal = total;
+
+    ret = map_insert(progress_status_map->map, key, pval);
+    progress_status_map_unlock(progress_status_map);
     return ret;
 }
 
diff --git a/src/daemon/modules/image/oci/progress.h b/src/daemon/modules/image/oci/progress.h
index 496a32f3..dcc8e144 100644
--- a/src/daemon/modules/image/oci/progress.h
+++ b/src/daemon/modules/image/oci/progress.h
@@ -29,11 +29,11 @@ typedef struct progress_status_map {
 } progress_status_map;
 
 typedef struct progress {
-   int64_t dlnow;
-   int64_t dltotal; 
+    int64_t dlnow;
+    int64_t dltotal;
 } progress;
 
-bool progress_status_map_insert(progress_status_map *progress_status_map, char *key, progress *value);
+bool progress_status_map_udpate(progress_status_map *progress_status_map, char *key, int64_t current, int64_t total);
 
 progress_status_map *progress_status_map_new();
 
diff --git a/src/daemon/modules/image/oci/registry/http_request.c b/src/daemon/modules/image/oci/registry/http_request.c
index 748c9a9b..450fbc41 100644
--- a/src/daemon/modules/image/oci/registry/http_request.c
+++ b/src/daemon/modules/image/oci/registry/http_request.c
@@ -692,44 +692,22 @@ out:
 static int xfer_inner(void *p, int64_t dltotal, int64_t dlnow, int64_t ultotal, int64_t ulnow)
 {
     progress_arg *arg = (progress_arg *)p;
-    progress *progress_value = NULL;
 
     if (arg == NULL || arg->map_store == NULL) {
         ERROR("Wrong progress arg");
         return -1;
     }
+
     // When fetch_manifest_list, there's no digest. It's not a layer pulling progress and skip it.
     if (arg->digest == NULL) {
         return 0;
     }
 
-    if (!progress_status_map_lock(arg->map_store)) {
-        ERROR("Cannot update progress status map for locking failed");
+    if (!progress_status_map_udpate(arg->map_store, arg->digest, dlnow, dltotal)) {
+        ERROR("Failed to update pull progress");
         return -1;
     }
 
-    // If the item exists, only replace the value.
-    progress_value = map_search(arg->map_store->map, arg->digest);
-    if (progress_value != NULL) {
-        progress_value->dlnow = dlnow;
-        progress_value->dltotal = dltotal;
-        progress_status_map_unlock(arg->map_store);
-
-        return 0;
-    }
-    progress_status_map_unlock(arg->map_store);
-
-    progress_value = util_common_calloc_s(sizeof(progress));
-    if (progress_value == NULL) {
-        ERROR("Out of memory");
-        return -1;
-    }
-
-    progress_value->dlnow = dlnow;
-    progress_value->dltotal = dltotal;
-
-    progress_status_map_insert(arg->map_store, arg->digest, progress_value);
-
     return 0;
 }
 
diff --git a/src/daemon/modules/image/oci/storage/image_store/image_store.c b/src/daemon/modules/image/oci/storage/image_store/image_store.c
index f49f4707..58baa47a 100644
--- a/src/daemon/modules/image/oci/storage/image_store/image_store.c
+++ b/src/daemon/modules/image/oci/storage/image_store/image_store.c
@@ -2824,7 +2824,7 @@ static int implicit_digest(map_t *digests, image_t *img)
 
     // Find whether the manifest in big_data_digests exists, if not, return 0 directly
     if (!get_index_by_key((const char **)img->simage->big_data_digests->keys, img->simage->big_data_digests->len,
-                         IMAGE_DIGEST_BIG_DATA_KEY, &index)) {
+                          IMAGE_DIGEST_BIG_DATA_KEY, &index)) {
         return 0;
     }
 
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
index 7517dd43..3bc433ae 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.c
@@ -1930,7 +1930,7 @@ int overlay2_apply_diff(const char *id, const struct graphdriver *driver, const
         goto out;
     }
 
-    ret = archive_unpack(content, layer_diff, &options, root_dir ,&err);
+    ret = archive_unpack(content, layer_diff, &options, root_dir, &err);
     if (ret != 0) {
         ERROR("Failed to unpack to %s: %s", layer_diff, err);
         ret = -1;
diff --git a/src/daemon/modules/image/oci/storage/storage.c b/src/daemon/modules/image/oci/storage/storage.c
index 2e53dbac..0d1a846a 100644
--- a/src/daemon/modules/image/oci/storage/storage.c
+++ b/src/daemon/modules/image/oci/storage/storage.c
@@ -215,7 +215,7 @@ int storage_inc_hold_refs(const char *layer_id)
 int storage_dec_hold_refs(const char *layer_id)
 {
     int ret = 0;
-    
+
     if (layer_id == NULL) {
         ERROR("Empty layer id");
         return -1;
@@ -550,7 +550,8 @@ char *storage_img_get_image_id(const char *img_name)
     return image_store_lookup(img_name);
 }
 
-static bool is_top_layer_of_other_image(const char *img_id, const imagetool_images_list *all_images, const char *layer_id)
+static bool is_top_layer_of_other_image(const char *img_id, const imagetool_images_list *all_images,
+                                        const char *layer_id)
 {
     size_t i = 0;
 
-- 
2.42.0