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/65] 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

