From e8ad7f46602cd79f44d1c212c86c900859cb88c9 Mon Sep 17 00:00:00 2001
From: zhongtao <zhongtao17@huawei.com>
Date: Tue, 29 Aug 2023 09:38:53 +0000
Subject: [PATCH 125/145] !2153 fix codecheck * fix codecheck

---
 src/daemon/modules/image/embedded/load.c      |  2 +-
 src/daemon/modules/image/image.c              |  4 +-
 src/daemon/modules/image/oci/oci_login.h      |  2 -
 src/daemon/modules/image/oci/oci_logout.h     |  2 -
 .../oci/storage/image_store/image_store.c     |  1 -
 .../oci/storage/image_store/image_store.h     |  2 -
 .../graphdriver/devmapper/deviceset.c         |  9 ++-
 .../graphdriver/devmapper/deviceset.h         |  5 +-
 .../graphdriver/devmapper/driver_devmapper.h  | 16 ++---
 .../graphdriver/devmapper/wrapper_devmapper.h |  2 -
 .../storage/layer_store/graphdriver/driver.c  |  2 +-
 .../storage/layer_store/graphdriver/driver.h  | 59 ++++++++-----------
 .../graphdriver/overlay2/driver_overlay2.c    |  3 -
 .../graphdriver/overlay2/driver_overlay2.h    |  8 +--
 .../graphdriver/quota/project_quota.h         |  1 -
 .../oci/storage/layer_store/layer_store.c     |  1 -
 .../oci/storage/layer_store/layer_store.h     |  4 --
 .../overlay_remote_impl.c                     |  1 -
 .../remote_layer_support/remote_support.c     |  2 +-
 .../remote_layer_support/remote_support.h     |  2 +-
 .../oci/storage/rootfs_store/rootfs_store.h   |  4 --
 21 files changed, 46 insertions(+), 86 deletions(-)

diff --git a/src/daemon/modules/image/embedded/load.c b/src/daemon/modules/image/embedded/load.c
index dc2aeba2..92ac42ad 100644
--- a/src/daemon/modules/image/embedded/load.c
+++ b/src/daemon/modules/image/embedded/load.c
@@ -36,7 +36,7 @@ static char *replace_suffix_to_sgn(const char *file)
         ERROR("invalid NULL param");
         return NULL;
     }
-    if (sizeof(".sgn") > SIZE_MAX - strlen(file)) {
+    if (strlen(file) > SIZE_MAX - sizeof(".sgn")) {
         return NULL;
     }
     len = strlen(file) + sizeof(".sgn");
diff --git a/src/daemon/modules/image/image.c b/src/daemon/modules/image/image.c
index 4b0e2c07..e1b309b6 100644
--- a/src/daemon/modules/image/image.c
+++ b/src/daemon/modules/image/image.c
@@ -768,7 +768,9 @@ int im_merge_image_config(const char *image_type, const char *image_name, contai
     int ret = 0;
     struct bim *bim = NULL;
 
-    if (container_spec == NULL || image_name == NULL || image_type == NULL) {
+    // 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");
         ret = -1;
         goto out;
diff --git a/src/daemon/modules/image/oci/oci_login.h b/src/daemon/modules/image/oci/oci_login.h
index ab261ebd..acf6eeb6 100644
--- a/src/daemon/modules/image/oci/oci_login.h
+++ b/src/daemon/modules/image/oci/oci_login.h
@@ -15,8 +15,6 @@
 #ifndef DAEMON_MODULES_IMAGE_OCI_OCI_LOGIN_H
 #define DAEMON_MODULES_IMAGE_OCI_OCI_LOGIN_H
 
-#include <stdbool.h>
-
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/src/daemon/modules/image/oci/oci_logout.h b/src/daemon/modules/image/oci/oci_logout.h
index 81f0196c..c0a9bb8b 100644
--- a/src/daemon/modules/image/oci/oci_logout.h
+++ b/src/daemon/modules/image/oci/oci_logout.h
@@ -15,8 +15,6 @@
 #ifndef DAEMON_MODULES_IMAGE_OCI_OCI_LOGOUT_H
 #define DAEMON_MODULES_IMAGE_OCI_OCI_LOGOUT_H
 
-#include <stdbool.h>
-
 #ifdef __cplusplus
 extern "C" {
 #endif
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 6908ccc2..abd625f7 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
@@ -2122,7 +2122,6 @@ static int pack_repo_digest(char ***old_repo_digests, const char **image_tags, c
     }
 
     for (i = 0; i < util_array_len((const char **)*repo_digests); i++) {
-        bool value = true;
         if (!map_replace(digest_map, (void *)(*repo_digests)[i], &value)) {
             ERROR("Failed to insert pair to digest map: %s", (*repo_digests)[i]);
             ret = -1;
diff --git a/src/daemon/modules/image/oci/storage/image_store/image_store.h b/src/daemon/modules/image/oci/storage/image_store/image_store.h
index 019a2881..4544f84b 100644
--- a/src/daemon/modules/image/oci/storage/image_store/image_store.h
+++ b/src/daemon/modules/image/oci/storage/image_store/image_store.h
@@ -29,8 +29,6 @@
 #include "isula_libutils/imagetool_images_list.h"
 #include "isula_libutils/imagetool_image_summary.h"
 
-struct storage_module_init_options;
-
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
index 5f8d6c56..046dd333 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
@@ -106,7 +106,6 @@ static int handle_dm_min_free_space(char *val, struct device_set *devset)
 {
     long converted = 0;
     int ret = util_parse_percent_string(val, &converted);
-
     if (ret != 0 || converted >= 100) {
         ERROR("Invalid min free space: '%s': %s", val, strerror(-ret));
         isulad_set_error_message("Invalid min free space: '%s': %s", val, strerror(-ret));
@@ -292,7 +291,8 @@ static char *deviceset_meta_file(const struct device_set *devset)
     return file;
 }
 
-// get_dm_name return value format:container-253:0-409697-401641a00390ccd2b21eb464f5eb5a7b735c3731b717e7bffafe65971f4cb498
+// get_dm_name return value format:
+// container-253:0-409697-401641a00390ccd2b21eb464f5eb5a7b735c3731b717e7bffafe65971f4cb498
 static char *get_dm_name(const struct device_set *devset, const char *hash)
 {
     int nret = 0;
@@ -311,7 +311,8 @@ static char *get_dm_name(const struct device_set *devset, const char *hash)
     return util_strdup_s(buff);
 }
 
-// get_dev_name return value fromat:/dev/mapper/container-253:0-409697-401641a00390ccd2b21eb464f5eb5a7b735c3731b717e7bffafe65971f4cb498
+// get_dev_name return value fromat:
+// /dev/mapper/container-253:0-409697-401641a00390ccd2b21eb464f5eb5a7b735c3731b717e7bffafe65971f4cb498
 static char *get_dev_name(const char *name)
 {
     return util_string_append(name, DEVMAPPER_DECICE_DIRECTORY);
@@ -2350,7 +2351,6 @@ static int setup_base_image(struct device_set *devset)
     devmapper_device_info_t *device_info = NULL;
 
     device_info = lookup_device(devset, "base");
-
     // base image already exists. If it is initialized properly, do UUID
     // verification and return. Otherwise remove image and set it up
     // fresh.
@@ -2503,7 +2503,6 @@ static void cleanup_deleted_devices(struct graphdriver *driver)
         goto unlock_driver;
     }
 
-
     if (driver->devset->nr_deleted_devices == 0) {
         DEBUG("devmapper: no devices to delete");
         goto unlock_devset;
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.h b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.h
index ec985e40..d7f7d184 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.h
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.h
@@ -23,10 +23,7 @@
 
 #include "driver.h"
 #include "metadata_store.h"
-
-struct device_set;
-struct driver_mount_opts;
-struct graphdriver;
+#include "devices_constants.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.h b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.h
index 9ee020de..dca2d614 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.h
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.h
@@ -16,22 +16,18 @@
 #define DAEMON_MODULES_IMAGE_OCI_STORAGE_LAYER_STORE_GRAPHDRIVER_DEVMAPPER_DRIVER_DEVMAPPER_H
 
 #include <pthread.h>
-#include <isula_libutils/imagetool_fs_info.h>
-#include <isula_libutils/json_common.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
+#include <isula_libutils/imagetool_fs_info.h>
+#include <isula_libutils/json_common.h>
+#include <isula_libutils/image_devmapper_transaction.h>
+#include <isula_libutils/image_devmapper_deviceset_metadata.h>
 
 #include "driver.h"
 #include "map.h"
-#include "isula_libutils/image_devmapper_transaction.h"
-#include "isula_libutils/image_devmapper_deviceset_metadata.h"
-
-struct driver_create_opts;
-struct driver_mount_opts;
-struct graphdriver;
-struct graphdriver_status;
-struct io_read_wrapper;
+#include "image_api.h"
+#include "io_wrapper.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.h b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.h
index 01771a3b..4b2ae82b 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.h
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.h
@@ -24,8 +24,6 @@
 
 #include "driver.h"
 
-struct dm_task;
-
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
index 29223700..71cbbe1c 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.c
@@ -1,5 +1,5 @@
 /******************************************************************************
- * Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020. 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:
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.h b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.h
index acd847cc..2fcfa12b 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.h
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/driver.h
@@ -1,5 +1,5 @@
 /******************************************************************************
- * Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020. 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:
@@ -20,25 +20,42 @@
 #include <stddef.h>
 #include <pthread.h>
 #include <isula_libutils/imagetool_fs_info.h>
+#include <isula_libutils/container_inspect.h>
+#include <isula_libutils/json_common.h>
 
-#include "isula_libutils/container_inspect.h"
-#include "isula_libutils/json_common.h"
 #include "io_wrapper.h"
 #include "driver_overlay2_types.h"
 #include "devices_constants.h"
 #include "storage.h"
 #include "image_api.h"
-#include "isula_libutils/container_inspect.h"
-
-struct graphdriver_status;
-struct io_read_wrapper;
-struct storage_module_init_options;
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-struct graphdriver;
+struct graphdriver {
+    // common implement
+    const struct graphdriver_ops *ops;
+    const char *name;
+    const char *home;
+    char *backing_fs;
+    bool support_dtype;
+
+    bool support_quota;
+#ifdef ENABLE_REMOTE_LAYER_STORE
+    bool enable_remote_layer;
+#endif
+    struct pquota_control *quota_ctrl;
+
+    // options for overlay2
+    struct overlay_options *overlay_opts;
+
+    // options for device mapper
+    struct device_set *devset;
+
+    // lock to protect graphdriver between cleanup and other operations
+    pthread_rwlock_t rwlock;
+};
 
 struct driver_create_opts {
     char *mount_label;
@@ -81,30 +98,6 @@ struct graphdriver_ops {
     int (*get_layer_fs_info)(const char *id, const struct graphdriver *driver, imagetool_fs_info *fs_info);
 };
 
-struct graphdriver {
-    // common implement
-    const struct graphdriver_ops *ops;
-    const char *name;
-    const char *home;
-    char *backing_fs;
-    bool support_dtype;
-
-    bool support_quota;
-#ifdef ENABLE_REMOTE_LAYER_STORE
-    bool enable_remote_layer;
-#endif
-    struct pquota_control *quota_ctrl;
-
-    // options for overlay2
-    struct overlay_options *overlay_opts;
-
-    // options for device mapper
-    struct device_set *devset;
-
-    // lock to protect graphdriver between cleanup and other operations
-    pthread_rwlock_t rwlock;
-};
-
 int graphdriver_init(const struct storage_module_init_options *opts);
 
 int graphdriver_create_rw(const char *id, const char *parent, struct driver_create_opts *create_opts);
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 2a209626..469a2367 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
@@ -643,7 +643,6 @@ const static int check_lower_depth(const char *lowers_str)
 
     lowers_arr = util_string_split(lowers_str, ':');
     lowers_size = util_array_len((const char **)lowers_arr);
-
     if (lowers_size > OVERLAY_LAYER_MAX_DEPTH) {
         ERROR("Max depth exceeded %s", lowers_str);
         ret = -1;
@@ -1268,7 +1267,6 @@ static int append_rel_empty_path(const char *id, char ***rel_lowers)
     char *rel_path = NULL;
 
     rel_path = util_string_append("/empty", id);
-
     if (util_array_append(rel_lowers, rel_path) != 0) {
         SYSERROR("Can't append relative layer:%s", rel_path);
         ret = -1;
@@ -2166,7 +2164,6 @@ int overlay2_repair_lowers(const char *id, const char *parent, const struct grap
     lowers_str = read_layer_lower_file(layer_dir);
     lowers_arr = util_string_split(lowers_str, ':');
     lowers_size = util_array_len((const char **)lowers_arr);
-
     if (lowers_size != 0) {
         if (check_lower_valid(driver->home, lowers_arr[0]) == 0) {
             DEBUG("Try to repair layer %s, success check", id);
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.h b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.h
index 438c508e..444c0670 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.h
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/overlay2/driver_overlay2.h
@@ -22,12 +22,8 @@
 #include <stdint.h>
 
 #include "driver.h"
-
-struct driver_create_opts;
-struct driver_mount_opts;
-struct graphdriver;
-struct graphdriver_status;
-struct io_read_wrapper;
+#include "image_api.h"
+#include "io_wrapper.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/quota/project_quota.h b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/quota/project_quota.h
index 94230faa..6cda7456 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/quota/project_quota.h
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/quota/project_quota.h
@@ -33,7 +33,6 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <inttypes.h>
-#include <linux/magic.h>
 #include <linux/dqblk_xfs.h>
 #include <errno.h>
 #include <libgen.h>
diff --git a/src/daemon/modules/image/oci/storage/layer_store/layer_store.c b/src/daemon/modules/image/oci/storage/layer_store/layer_store.c
index 6db590e3..87df8160 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/layer_store.c
+++ b/src/daemon/modules/image/oci/storage/layer_store/layer_store.c
@@ -886,7 +886,6 @@ static int caculate_playload(struct archive *ar, char **result)
     bool empty = true;
 
     ctab = new_isula_crc_table(ISO_POLY);
-
     if (ctab == NULL) {
         return -1;
     }
diff --git a/src/daemon/modules/image/oci/storage/layer_store/layer_store.h b/src/daemon/modules/image/oci/storage/layer_store/layer_store.h
index 20287119..eba406d4 100644
--- a/src/daemon/modules/image/oci/storage/layer_store/layer_store.h
+++ b/src/daemon/modules/image/oci/storage/layer_store/layer_store.h
@@ -24,10 +24,6 @@
 #include "storage.h"
 #include "io_wrapper.h"
 
-struct io_read_wrapper;
-struct layer_list;
-struct storage_module_init_options;
-
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/src/daemon/modules/image/oci/storage/remote_layer_support/overlay_remote_impl.c b/src/daemon/modules/image/oci/storage/remote_layer_support/overlay_remote_impl.c
index 38d9b0ce..86e05ac2 100644
--- a/src/daemon/modules/image/oci/storage/remote_layer_support/overlay_remote_impl.c
+++ b/src/daemon/modules/image/oci/storage/remote_layer_support/overlay_remote_impl.c
@@ -185,7 +185,6 @@ static int remove_one_remote_overlay_layer(struct remote_overlay_data *data, con
     }
 
     link_id = (char *)map_search(overlay_id_link, (void *)overlay_id);
-
     if (link_id == NULL) {
         ERROR("Failed to find link id for overlay layer: %s", overlay_id);
         ret = -1;
diff --git a/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c b/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c
index b1ac2156..69022073 100644
--- a/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c
+++ b/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.c
@@ -1,5 +1,5 @@
 /******************************************************************************
- * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. 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:
diff --git a/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.h b/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.h
index 30e3ebb0..545cbe49 100644
--- a/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.h
+++ b/src/daemon/modules/image/oci/storage/remote_layer_support/remote_support.h
@@ -1,5 +1,5 @@
 /******************************************************************************
- * Copyright (c) Huawei Technologies Co., Ltd. 2020-2023. All rights reserved.
+ * Copyright (c) Huawei Technologies Co., Ltd. 2023. 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:
diff --git a/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.h b/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.h
index 63f3294b..d618c401 100644
--- a/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.h
+++ b/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.h
@@ -24,10 +24,6 @@
 #include "storage.h"
 #include "rootfs.h"
 
-struct rootfs_list;
-struct storage_module_init_options;
-struct storage_rootfs_options;
-
 #ifdef __cplusplus
 extern "C" {
 #endif
-- 
2.40.1

