summaryrefslogtreecommitdiff
path: root/0145-cni-change-error-info.patch
blob: 7f4e256b2e8e6b932f646cef146834be6de01b95 (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
From 445642718fd3dd7867aad9fc8e6eb5b7dafadcb6 Mon Sep 17 00:00:00 2001
From: liuxu <liuxu156@huawei.com>
Date: Fri, 1 Nov 2024 12:56:38 +0800
Subject: [PATCH 145/156] cni:change error info

Signed-off-by: liuxu <liuxu156@huawei.com>
---
 .../modules/network/cni_operator/cni_operate.c     |  8 ++++----
 .../network/cni_operator/libcni/libcni_api.c       | 14 +++++++++++++-
 .../network/cni_operator/libcni/libcni_api.h       |  2 +-
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/daemon/modules/network/cni_operator/cni_operate.c b/src/daemon/modules/network/cni_operator/cni_operate.c
index 6db6db51..80a2642d 100644
--- a/src/daemon/modules/network/cni_operator/cni_operate.c
+++ b/src/daemon/modules/network/cni_operator/cni_operate.c
@@ -731,13 +731,13 @@ static int update_runtime_conf_cni_args_by_cached(cni_cached_info *info, struct
     return 0;
 }
 
-static int get_configs_from_cached(const char *network, struct runtime_conf *rc, char **conf_list)
+static int get_configs_from_cached(const char *network, const char *cni_version, struct runtime_conf *rc, char **conf_list)
 {
     int ret = 0;
     size_t i;
     cni_cached_info *info = NULL;
 
-    info = cni_get_network_list_cached_info(network, rc);
+    info = cni_get_network_list_cached_info(network, cni_version, rc);
     if (info == NULL) {
         return 0;
     }
@@ -857,7 +857,7 @@ int check_network_plane(const struct cni_manager *manager, const struct cni_netw
         goto out;
     }
 
-    ret = get_configs_from_cached(list->list->name, rc, NULL);
+    ret = get_configs_from_cached(list->list->name, list->list->cni_version, rc, NULL);
     if (ret != 0) {
         ERROR("Get cached info failed");
         ret = -1;
@@ -901,7 +901,7 @@ int detach_network_plane(const struct cni_manager *manager, const struct cni_net
         goto out;
     }
 
-    ret = get_configs_from_cached(list->list->name, rc, NULL);
+    ret = get_configs_from_cached(list->list->name, list->list->cni_version, rc, NULL);
     if (ret != 0) {
         ERROR("Get cached info failed");
         ret = -1;
diff --git a/src/daemon/modules/network/cni_operator/libcni/libcni_api.c b/src/daemon/modules/network/cni_operator/libcni/libcni_api.c
index 7ba983af..c55c8e9d 100644
--- a/src/daemon/modules/network/cni_operator/libcni/libcni_api.c
+++ b/src/daemon/modules/network/cni_operator/libcni/libcni_api.c
@@ -81,13 +81,25 @@ struct cni_opt_result *cni_get_network_list_cached_result(const struct cni_netwo
     return result;
 }
 
-cni_cached_info *cni_get_network_list_cached_info(const char *network, const struct runtime_conf *rc)
+cni_cached_info *cni_get_network_list_cached_info(const char *network, const char *cni_version, const struct runtime_conf *rc)
 {
+    bool greater = false;
     if (network == NULL) {
         ERROR("Empty network");
         return NULL;
     }
 
+    if (util_version_greater_than_or_equal_to(cni_version, SUPPORT_CACHE_AND_CHECK_VERSION, &greater) != 0) {
+        ERROR("Invalid cni version %s", cni_version);
+        return NULL;
+    }
+
+    // CACHE was added in CNI spec version 0.4.0 and higher
+    if (!greater) {
+        WARN("result version: %s is too old, do not save this cache", cni_version);
+        return NULL;
+    }
+
     return cni_cache_read(g_module_conf.cache_dir, network, rc);
 }
 
diff --git a/src/daemon/modules/network/cni_operator/libcni/libcni_api.h b/src/daemon/modules/network/cni_operator/libcni/libcni_api.h
index 2f10d6e9..bf16f168 100644
--- a/src/daemon/modules/network/cni_operator/libcni/libcni_api.h
+++ b/src/daemon/modules/network/cni_operator/libcni/libcni_api.h
@@ -75,7 +75,7 @@ bool cni_module_init(const char *cache_dir, const char * const *paths, size_t pa
 struct cni_opt_result *cni_get_network_list_cached_result(const struct cni_network_list_conf *list,
                                                           const struct runtime_conf *rc);
 
-cni_cached_info *cni_get_network_list_cached_info(const char *network, const struct runtime_conf *rc);
+cni_cached_info *cni_get_network_list_cached_info(const char *network, const char *cni_version, const struct runtime_conf *rc);
 
 int cni_add_network_list(const struct cni_network_list_conf *list, const struct runtime_conf *rc,
                          struct cni_opt_result **pret);
-- 
2.34.1