加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0048-CDI-interface-definition.patch 41.98 KB
一键复制 编辑 原始数据 按行查看 历史
liuxu 提交于 2024-04-20 10:00 . upgrade from upstream
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
From 040e39827049cd557987f505d1bd6c6e4f18b4b3 Mon Sep 17 00:00:00 2001
From: liuxu <liuxu156@huawei.com>
Date: Mon, 11 Mar 2024 17:48:11 +0800
Subject: [PATCH 48/69] CDI:interface definition
---
cmake/options.cmake | 11 +++
src/daemon/modules/CMakeLists.txt | 11 +++
src/daemon/modules/api/cdi_operate_api.h | 39 ++++++++++
src/daemon/modules/device/CMakeLists.txt | 23 ++++++
src/daemon/modules/device/cdi/CMakeLists.txt | 13 ++++
.../device/cdi/behavior/CMakeLists.txt | 13 ++++
.../device/cdi/behavior/cdi_container_edits.c | 49 ++++++++++++
.../device/cdi/behavior/cdi_container_edits.h | 39 ++++++++++
.../modules/device/cdi/behavior/cdi_device.c | 40 ++++++++++
.../modules/device/cdi/behavior/cdi_device.h | 46 ++++++++++++
.../modules/device/cdi/behavior/cdi_spec.c | 60 +++++++++++++++
.../modules/device/cdi/behavior/cdi_spec.h | 56 ++++++++++++++
.../device/cdi/behavior/cdi_spec_dirs.c | 29 +++++++
.../device/cdi/behavior/cdi_spec_dirs.h | 47 ++++++++++++
.../modules/device/cdi/behavior/cdi_version.c | 40 ++++++++++
.../modules/device/cdi/behavior/cdi_version.h | 34 +++++++++
.../device/cdi/behavior/parser/CMakeLists.txt | 3 +
.../device/cdi/behavior/parser/cdi_parser.c | 55 ++++++++++++++
.../device/cdi/behavior/parser/cdi_parser.h | 38 ++++++++++
.../modules/device/cdi/cdi_annotations.c | 31 ++++++++
.../modules/device/cdi/cdi_annotations.h | 32 ++++++++
src/daemon/modules/device/cdi/cdi_cache.c | 69 +++++++++++++++++
src/daemon/modules/device/cdi/cdi_cache.h | 75 +++++++++++++++++++
src/daemon/modules/device/cdi/cdi_registry.c | 25 +++++++
src/daemon/modules/device/cdi/cdi_registry.h | 36 +++++++++
src/daemon/modules/device/cdi_operate.c | 35 +++++++++
26 files changed, 949 insertions(+)
create mode 100644 src/daemon/modules/api/cdi_operate_api.h
create mode 100644 src/daemon/modules/device/CMakeLists.txt
create mode 100644 src/daemon/modules/device/cdi/CMakeLists.txt
create mode 100644 src/daemon/modules/device/cdi/behavior/CMakeLists.txt
create mode 100644 src/daemon/modules/device/cdi/behavior/cdi_container_edits.c
create mode 100644 src/daemon/modules/device/cdi/behavior/cdi_container_edits.h
create mode 100644 src/daemon/modules/device/cdi/behavior/cdi_device.c
create mode 100644 src/daemon/modules/device/cdi/behavior/cdi_device.h
create mode 100644 src/daemon/modules/device/cdi/behavior/cdi_spec.c
create mode 100644 src/daemon/modules/device/cdi/behavior/cdi_spec.h
create mode 100644 src/daemon/modules/device/cdi/behavior/cdi_spec_dirs.c
create mode 100644 src/daemon/modules/device/cdi/behavior/cdi_spec_dirs.h
create mode 100644 src/daemon/modules/device/cdi/behavior/cdi_version.c
create mode 100644 src/daemon/modules/device/cdi/behavior/cdi_version.h
create mode 100644 src/daemon/modules/device/cdi/behavior/parser/CMakeLists.txt
create mode 100644 src/daemon/modules/device/cdi/behavior/parser/cdi_parser.c
create mode 100644 src/daemon/modules/device/cdi/behavior/parser/cdi_parser.h
create mode 100644 src/daemon/modules/device/cdi/cdi_annotations.c
create mode 100644 src/daemon/modules/device/cdi/cdi_annotations.h
create mode 100644 src/daemon/modules/device/cdi/cdi_cache.c
create mode 100644 src/daemon/modules/device/cdi/cdi_cache.h
create mode 100644 src/daemon/modules/device/cdi/cdi_registry.c
create mode 100644 src/daemon/modules/device/cdi/cdi_registry.h
create mode 100644 src/daemon/modules/device/cdi_operate.c
diff --git a/cmake/options.cmake b/cmake/options.cmake
index b7a7c65d..c1eac472 100644
--- a/cmake/options.cmake
+++ b/cmake/options.cmake
@@ -40,6 +40,17 @@ if (ENABLE_CRI_API_V1 STREQUAL "ON")
message("${Green}-- Enable CRI API V1${ColourReset}")
endif()
+option(ENABLE_CDI "Enable CDI" OFF)
+if (ENABLE_CDI STREQUAL "ON")
+ if (ENABLE_CRI_API_V1)
+ add_definitions(-DENABLE_CDI)
+ set(ENABLE_CDI 1)
+ message("${Green}-- Enable CDI${ColourReset}")
+ else()
+ message("${Yellow}-- Can not enable CDI, CDI need enable CRI API V1 first ${ColourReset}")
+ endif()
+endif()
+
option(ENABLE_SANDBOXER "Enable sandbox API" ON)
if (ENABLE_SANDBOXER STREQUAL "ON")
add_definitions(-DENABLE_SANDBOXER)
diff --git a/src/daemon/modules/CMakeLists.txt b/src/daemon/modules/CMakeLists.txt
index a70c094f..ff2ea226 100644
--- a/src/daemon/modules/CMakeLists.txt
+++ b/src/daemon/modules/CMakeLists.txt
@@ -49,6 +49,16 @@ if (ENABLE_PLUGIN)
)
endif()
+if (ENABLE_CDI)
+ add_subdirectory(device)
+ list(APPEND local_modules_srcs
+ ${DEVICE_SRCS}
+ )
+ list(APPEND local_modules_incs
+ ${DEVICE_INCS}
+ )
+endif()
+
set(MODULES_SRCS
${local_modules_srcs}
PARENT_SCOPE
@@ -70,3 +80,4 @@ if(ENABLE_NETWORK)
)
endif()
+
diff --git a/src/daemon/modules/api/cdi_operate_api.h b/src/daemon/modules/api/cdi_operate_api.h
new file mode 100644
index 00000000..4f4c339e
--- /dev/null
+++ b/src/daemon/modules/api/cdi_operate_api.h
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi device manager function definition
+ ******************************************************************************/
+#ifndef CDI_OPERATE_API_H
+#define CDI_OPERATE_API_H
+
+#include <isula_libutils/oci_runtime_spec.h>
+#include <isula_libutils/json_common.h>
+
+#include "utils_array.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int cdi_operate_registry_init(char **specs_dirs, size_t specs_dirs_len);
+
+char *cdi_operate_refresh(void);
+
+string_array *cdi_operate_inject_devices(oci_runtime_spec *spec, string_array *devices, char **error);
+
+char *cdi_operate_parse_annotations(json_map_string_string *annotations, string_array **keys, string_array **devices);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/daemon/modules/device/CMakeLists.txt b/src/daemon/modules/device/CMakeLists.txt
new file mode 100644
index 00000000..e3468c0b
--- /dev/null
+++ b/src/daemon/modules/device/CMakeLists.txt
@@ -0,0 +1,23 @@
+# get current directory sources files
+aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} device_top_srcs)
+
+add_subdirectory(cdi)
+
+set(local_device_srcs
+ ${device_top_srcs}
+ ${CDI_SRCS}
+ )
+
+set(local_device_incs
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CDI_INCS}
+ )
+
+set(DEVICE_SRCS
+ ${local_device_srcs}
+ PARENT_SCOPE
+ )
+set(DEVICE_INCS
+ ${local_device_incs}
+ PARENT_SCOPE
+ )
\ No newline at end of file
diff --git a/src/daemon/modules/device/cdi/CMakeLists.txt b/src/daemon/modules/device/cdi/CMakeLists.txt
new file mode 100644
index 00000000..12d9b222
--- /dev/null
+++ b/src/daemon/modules/device/cdi/CMakeLists.txt
@@ -0,0 +1,13 @@
+aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} cdi_top_srcs)
+add_subdirectory(behavior)
+
+set(CDI_SRCS
+ ${cdi_top_srcs}
+ ${BEHAVIOR_SRCS}
+ PARENT_SCOPE
+ )
+set(CDI_INCS
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${BEHAVIOR_INCS}
+ PARENT_SCOPE
+ )
diff --git a/src/daemon/modules/device/cdi/behavior/CMakeLists.txt b/src/daemon/modules/device/cdi/behavior/CMakeLists.txt
new file mode 100644
index 00000000..39881a7b
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/CMakeLists.txt
@@ -0,0 +1,13 @@
+aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} behavior_top_srcs)
+add_subdirectory(parser)
+
+set(BEHAVIOR_SRCS
+ ${behavior_top_srcs}
+ ${PARSER_SRCS}
+ PARENT_SCOPE
+ )
+set(BEHAVIOR_INCS
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/parser/
+ PARENT_SCOPE
+ )
diff --git a/src/daemon/modules/device/cdi/behavior/cdi_container_edits.c b/src/daemon/modules/device/cdi/behavior/cdi_container_edits.c
new file mode 100644
index 00000000..ce7b16db
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/cdi_container_edits.c
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi container edits function
+ ******************************************************************************/
+#include "cdi_container_edits.h"
+
+// PRESTART_HOOK is the name of the OCI "prestart" hook.
+#define PRESTART_HOOK "prestart"
+// CREATE_RUNTIME_HOOK is the name of the OCI "createRuntime" hook.
+#define CREATE_RUNTIME_HOOK "createRuntime"
+// CREATE_CONTAINER_HOOK is the name of the OCI "createContainer" hook.
+#define CREATE_CONTAINER_HOOK "createContainer"
+// START_CONTAINER_HOOK is the name of the OCI "startContainer" hook.
+#define START_CONTAINER_HOOK "startContainer"
+// POSTSTART_HOOK is the name of the OCI "poststart" hook.
+#define POSTSTART_HOOK "poststart"
+// POSTSTOP_HOOK is the name of the OCI "poststop" hook.
+#define POSTSTOP_HOOK "poststop"
+
+char *cdi_container_edits_apply(cdi_container_edits *e, oci_runtime_spec *spec)
+{
+ return NULL;
+}
+
+char *cdi_container_edits_validate(cdi_container_edits *e)
+{
+ return NULL;
+}
+
+cdi_container_edits *cdi_container_edits_append(cdi_container_edits *e, cdi_container_edits *o)
+{
+ return NULL;
+}
+
+bool cdi_container_edits_is_empty(cdi_container_edits *e)
+{
+ return true;
+}
+
diff --git a/src/daemon/modules/device/cdi/behavior/cdi_container_edits.h b/src/daemon/modules/device/cdi/behavior/cdi_container_edits.h
new file mode 100644
index 00000000..7b16d2bc
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/cdi_container_edits.h
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi container edits function definition
+ ******************************************************************************/
+#ifndef CDI_CONTAINER_EDITS_H
+#define CDI_CONTAINER_EDITS_H
+
+#include <isula_libutils/cdi_container_edits.h>
+#include <isula_libutils/cdi_device_node.h>
+#include <isula_libutils/oci_runtime_spec.h>
+#include <isula_libutils/cdi_hook.h>
+#include <isula_libutils/cdi_mount.h>
+
+#include "utils_array.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+char *cdi_container_edits_apply(cdi_container_edits *e, oci_runtime_spec *spec);
+char *cdi_container_edits_validate(cdi_container_edits *e);
+cdi_container_edits *cdi_container_edits_append(cdi_container_edits *e, cdi_container_edits *o);
+bool cdi_container_edits_is_empty(cdi_container_edits *e);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/src/daemon/modules/device/cdi/behavior/cdi_device.c b/src/daemon/modules/device/cdi/behavior/cdi_device.c
new file mode 100644
index 00000000..9904e9ee
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/cdi_device.c
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi device function
+ ******************************************************************************/
+#include "cdi_device.h"
+
+void free_cdi_cache_device(struct cdi_cache_device *d)
+{
+ (void)d;
+}
+
+struct cdi_cache_device *cdi_device_new_device(struct cdi_cache_spec *spec, cdi_device *d, char **error)
+{
+ return NULL;
+}
+
+struct cdi_cache_spec *cdi_device_get_spec(struct cdi_cache_device *d)
+{
+ return NULL;
+}
+
+char *cdi_device_get_qualified_name(struct cdi_cache_device *d)
+{
+ return NULL;
+}
+
+cdi_container_edits *cdi_device_edits(struct cdi_cache_device *d)
+{
+ return NULL;
+}
diff --git a/src/daemon/modules/device/cdi/behavior/cdi_device.h b/src/daemon/modules/device/cdi/behavior/cdi_device.h
new file mode 100644
index 00000000..3f460152
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/cdi_device.h
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi device function definition
+ ******************************************************************************/
+#ifndef CDI_DEVICE_H
+#define CDI_DEVICE_H
+
+#include <stdbool.h>
+#include <isula_libutils/cdi_device.h>
+#include <isula_libutils/oci_runtime_spec.h>
+
+#include "cdi_container_edits.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct cdi_cache_spec;
+
+struct cdi_cache_device {
+ cdi_device *raw_device;
+ struct cdi_cache_spec *cache_spec;
+};
+
+void free_cdi_cache_device(struct cdi_cache_device *d);
+
+struct cdi_cache_device *cdi_device_new_device(struct cdi_cache_spec *spec, cdi_device *d, char **error);
+struct cdi_cache_spec *cdi_device_get_spec(struct cdi_cache_device *d);
+char *cdi_device_get_qualified_name(struct cdi_cache_device *d);
+cdi_container_edits *cdi_device_edits(struct cdi_cache_device *d);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/src/daemon/modules/device/cdi/behavior/cdi_spec.c b/src/daemon/modules/device/cdi/behavior/cdi_spec.c
new file mode 100644
index 00000000..38fc9e38
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/cdi_spec.c
@@ -0,0 +1,60 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi spec function
+ ******************************************************************************/
+#include "cdi_spec.h"
+
+void free_cdi_cache_spec(struct cdi_cache_spec *s)
+{
+ (void)s;
+}
+
+struct cdi_cache_spec *cdi_spec_read_spec(const char *path, int priority, char **error)
+{
+ return NULL;
+}
+
+struct cdi_cache_spec *cdi_spec_new_spec(cdi_spec *raw, const char *path, int priority, char **error)
+{
+ return NULL;
+}
+
+const char *cdi_spec_get_vendor(struct cdi_cache_spec *s)
+{
+ return NULL;
+}
+
+const char *cdi_spec_get_class(struct cdi_cache_spec *s)
+{
+ return NULL;
+}
+
+struct cdi_cache_device *cdi_spec_get_cache_device(struct cdi_cache_spec *s, const char *name)
+{
+ return NULL;
+}
+
+const char *cdi_spec_get_path(struct cdi_cache_spec *s)
+{
+ return NULL;
+}
+
+int cdi_spec_get_priority(struct cdi_cache_spec *s)
+{
+ return 0;
+}
+
+cdi_container_edits *cdi_spec_edits(struct cdi_cache_spec *s)
+{
+ return NULL;
+}
diff --git a/src/daemon/modules/device/cdi/behavior/cdi_spec.h b/src/daemon/modules/device/cdi/behavior/cdi_spec.h
new file mode 100644
index 00000000..bd4fc9d1
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/cdi_spec.h
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi spec function definition
+ ******************************************************************************/
+#ifndef CDI_SPEC_H
+#define CDI_SPEC_H
+
+#include <isula_libutils/cdi_spec.h>
+#include <isula_libutils/oci_runtime_spec.h>
+
+#include "map.h"
+#include "cdi_container_edits.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct cdi_cache_device;
+
+struct cdi_cache_spec {
+ cdi_spec *raw_spec;
+ char *vendor;
+ char *class;
+ char *path;
+ int priority;
+ map_t *devices; // MAP_STR_PTR devices[cdi_device.name] = cdi_cache_device*
+};
+
+#define CDI_DEFAULT_SPEC_EXT ".json"
+
+void free_cdi_cache_spec(struct cdi_cache_spec *s);
+
+struct cdi_cache_spec *cdi_spec_read_spec(const char *path, int priority, char **error);
+struct cdi_cache_spec *cdi_spec_new_spec(cdi_spec *raw, const char *path, int priority, char **error);
+const char *cdi_spec_get_vendor(struct cdi_cache_spec *s);
+const char *cdi_spec_get_class(struct cdi_cache_spec *s);
+struct cdi_cache_device *cdi_spec_get_cache_device(struct cdi_cache_spec *s, const char *name);
+const char *cdi_spec_get_path(struct cdi_cache_spec *s);
+int cdi_spec_get_priority(struct cdi_cache_spec *s);
+cdi_container_edits *cdi_spec_edits(struct cdi_cache_spec *s);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/src/daemon/modules/device/cdi/behavior/cdi_spec_dirs.c b/src/daemon/modules/device/cdi/behavior/cdi_spec_dirs.c
new file mode 100644
index 00000000..5df4c937
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/cdi_spec_dirs.c
@@ -0,0 +1,29 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi spec dirs function
+ ******************************************************************************/
+#include "cdi_spec_dirs.h"
+
+#define DEFAULT_SPEC_DIRS_LEN 2
+static char *default_spec_dirs_items[DEFAULT_SPEC_DIRS_LEN] = {CDI_DEFAULT_STATIC_DIR, CDI_DEFAULT_DYNAMIC_DIR};
+
+string_array g_default_spec_dirs = {
+ .items = default_spec_dirs_items,
+ .len = DEFAULT_SPEC_DIRS_LEN,
+ .cap = DEFAULT_SPEC_DIRS_LEN,
+};
+
+char *cdi_scan_spec_dirs(string_array *dirs, struct cdi_scan_fn_maps *scan_fn_maps, cdi_scan_spec_func scan_fn)
+{
+ return NULL;
+}
diff --git a/src/daemon/modules/device/cdi/behavior/cdi_spec_dirs.h b/src/daemon/modules/device/cdi/behavior/cdi_spec_dirs.h
new file mode 100644
index 00000000..bd00e318
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/cdi_spec_dirs.h
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi spec dirs function definition
+ ******************************************************************************/
+#ifndef CDI_SPEC_DIRS_H
+#define CDI_SPEC_DIRS_H
+
+#include "cdi_cache.h"
+#include "utils_array.h"
+#include "map.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define CDI_DEFAULT_STATIC_DIR "/etc/cdi"
+#define CDI_DEFAULT_DYNAMIC_DIR "/var/run/cdi"
+
+extern string_array g_default_spec_dirs;
+
+struct cdi_scan_fn_maps {
+ map_t *specs;
+ map_t *devices;
+ map_t *conflicts;
+ map_t *spec_errors;
+ string_array *result;
+};
+typedef char *(*cdi_scan_spec_func)(struct cdi_scan_fn_maps *scan_fn_maps, const char *path, int priority,
+ struct cdi_cache_spec *spec, char **error);
+
+char *cdi_scan_spec_dirs(string_array *dirs, struct cdi_scan_fn_maps *scan_fn_maps, cdi_scan_spec_func scan_fn);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/src/daemon/modules/device/cdi/behavior/cdi_version.c b/src/daemon/modules/device/cdi/behavior/cdi_version.c
new file mode 100644
index 00000000..3e87c111
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/cdi_version.c
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi version function
+ ******************************************************************************/
+#include "cdi_version.h"
+
+#define CDI_V_CURRENT_VERSION "v"##CDI_CURRENT_VERSION
+
+#define CDI_V010 "v0.1.0"
+#define CDI_V020 "v0.2.0"
+#define CDI_V030 "v0.3.0"
+#define CDI_V040 "v0.4.0"
+#define CDI_V050 "v0.5.0"
+#define CDI_V060 "v0.6.0"
+#define CDI_V_EARLIEST CDI_V030
+
+const char *cdi_minimum_required_version(cdi_spec *spec)
+{
+ return NULL;
+}
+
+bool cdi_is_greater_than_version(const char *v, const char *o)
+{
+ return true;
+}
+
+bool cdi_is_valid_version(const char *spec_version)
+{
+ return true;
+}
diff --git a/src/daemon/modules/device/cdi/behavior/cdi_version.h b/src/daemon/modules/device/cdi/behavior/cdi_version.h
new file mode 100644
index 00000000..99b7e692
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/cdi_version.h
@@ -0,0 +1,34 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi version function definition
+ ******************************************************************************/
+#ifndef CDI_VERSION_H
+#define CDI_VERSION_H
+
+#include <isula_libutils/cdi_spec.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define CDI_CURRENT_VERSION "0.6.0"
+
+const char *cdi_minimum_required_version(cdi_spec *spec);
+bool cdi_is_greater_than_version(const char *v, const char *o);
+bool cdi_is_valid_version(const char *spec_version);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/src/daemon/modules/device/cdi/behavior/parser/CMakeLists.txt b/src/daemon/modules/device/cdi/behavior/parser/CMakeLists.txt
new file mode 100644
index 00000000..9bf5f3f2
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/parser/CMakeLists.txt
@@ -0,0 +1,3 @@
+# get current directory sources files
+aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_cdi_parser_srcs)
+set(PARSER_SRCS ${local_cdi_parser_srcs} PARENT_SCOPE)
diff --git a/src/daemon/modules/device/cdi/behavior/parser/cdi_parser.c b/src/daemon/modules/device/cdi/behavior/parser/cdi_parser.c
new file mode 100644
index 00000000..45048f9a
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/parser/cdi_parser.c
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi parser linux function
+ ******************************************************************************/
+#include "cdi_parser.h"
+
+char *cdi_parser_qualified_name(const char *vendor, const char *class, const char *name)
+{
+ return NULL;
+}
+
+bool cdi_parser_is_qualified_name(const char *device)
+{
+ return true;
+}
+
+char *cdi_parser_parse_qualified_name(const char *device, char **vendor, char **class, char **name)
+{
+ return NULL;
+}
+
+int cdi_parser_parse_device(const char *device, char **vendor, char **class, char **name)
+{
+ return 0;
+}
+
+int cdi_parser_parse_qualifier(const char *kind, char **vendor, char **class)
+{
+ return 0;
+}
+
+char *cdi_parser_validate_vendor_name(const char *vendor)
+{
+ return NULL;
+}
+
+char *cdi_parser_validate_class_name(const char *class)
+{
+ return NULL;
+}
+
+char *cdi_parser_validate_device_name(const char *name)
+{
+ return NULL;
+}
diff --git a/src/daemon/modules/device/cdi/behavior/parser/cdi_parser.h b/src/daemon/modules/device/cdi/behavior/parser/cdi_parser.h
new file mode 100644
index 00000000..d9c057ea
--- /dev/null
+++ b/src/daemon/modules/device/cdi/behavior/parser/cdi_parser.h
@@ -0,0 +1,38 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi parser function definition
+ ******************************************************************************/
+#ifndef CDI_PARSER_H
+#define CDI_PARSER_H
+
+#include <stdbool.h>
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+char *cdi_parser_qualified_name(const char *vendor, const char *class, const char *name);
+bool cdi_parser_is_qualified_name(const char *device);
+char *cdi_parser_parse_qualified_name(const char *device, char **vendor, char **class, char **name);
+int cdi_parser_parse_device(const char *device, char **vendor, char **class, char **name);
+int cdi_parser_parse_qualifier(const char *kind, char **vendor, char **class);
+char *cdi_parser_validate_vendor_name(const char *vendor);
+char *cdi_parser_validate_class_name(const char *class);
+char *cdi_parser_validate_device_name(const char *name);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/src/daemon/modules/device/cdi/cdi_annotations.c b/src/daemon/modules/device/cdi/cdi_annotations.c
new file mode 100644
index 00000000..3cb9be84
--- /dev/null
+++ b/src/daemon/modules/device/cdi/cdi_annotations.c
@@ -0,0 +1,31 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi annotations function
+ ******************************************************************************/
+#include "cdi_annotations.h"
+
+#include <ctype.h>
+#include <isula_libutils/log.h>
+#include <isula_libutils/auto_cleanup.h>
+#include <isula_libutils/utils_string.h>
+
+#include "error.h"
+#include "utils.h"
+#include "cdi_parser.h"
+
+#define CDI_ANNOTATIONS_PREFIX "cdi.k8s.io/"
+
+char *cdi_parse_annotations(json_map_string_string *annotations, string_array **keys, string_array **devices)
+{
+ return NULL;
+}
diff --git a/src/daemon/modules/device/cdi/cdi_annotations.h b/src/daemon/modules/device/cdi/cdi_annotations.h
new file mode 100644
index 00000000..52355099
--- /dev/null
+++ b/src/daemon/modules/device/cdi/cdi_annotations.h
@@ -0,0 +1,32 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi annotations function definition
+ ******************************************************************************/
+#ifndef CDI_ANNOTATIONS_H
+#define CDI_ANNOTATIONS_H
+
+#include <isula_libutils/json_common.h>
+
+#include "utils_array.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+char *cdi_parse_annotations(json_map_string_string *annotations, string_array **keys, string_array **devices);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/src/daemon/modules/device/cdi/cdi_cache.c b/src/daemon/modules/device/cdi/cdi_cache.c
new file mode 100644
index 00000000..9c54acbf
--- /dev/null
+++ b/src/daemon/modules/device/cdi/cdi_cache.c
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi cache function
+ ******************************************************************************/
+#include "cdi_cache.h"
+
+void free_cdi_cache(struct cdi_cache *c)
+{
+ (void)c;
+}
+
+struct cdi_cache *cdi_new_cache(string_array *spec_dirs, char **error)
+{
+ return NULL;
+}
+
+static string_array *cdi_inject_devices(struct cdi_cache *c, oci_runtime_spec *oci_spec, string_array *devices, char **error)
+{
+ return NULL;
+}
+
+static char *cdi_configure(struct cdi_cache *c, string_array *spec_dirs)
+{
+ return NULL;
+}
+
+static char *cdi_refresh(struct cdi_cache *c)
+{
+ return NULL;
+}
+
+static map_t *cdi_get_errors(struct cdi_cache *c)
+{
+ return NULL;
+}
+
+static string_array *cdi_get_spec_directories(struct cdi_cache *c)
+{
+ return NULL;
+}
+
+static map_t *cdi_get_spec_dir_errors(struct cdi_cache *c)
+{
+ return NULL;
+}
+
+static struct cdi_cache_ops g_cdi_cache_ops = {
+ .inject_devices = cdi_inject_devices,
+ .configure = cdi_configure,
+ .refresh = cdi_refresh,
+ .get_errors = cdi_get_errors,
+ .get_spec_directories = cdi_get_spec_directories,
+ .get_spec_dir_errors = cdi_get_spec_dir_errors
+};
+
+struct cdi_cache_ops *cdi_get_cache_ops(void)
+{
+ return &g_cdi_cache_ops;
+}
\ No newline at end of file
diff --git a/src/daemon/modules/device/cdi/cdi_cache.h b/src/daemon/modules/device/cdi/cdi_cache.h
new file mode 100644
index 00000000..92fb64af
--- /dev/null
+++ b/src/daemon/modules/device/cdi/cdi_cache.h
@@ -0,0 +1,75 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi cache function definition
+ ******************************************************************************/
+#ifndef CDI_CACHE_H
+#define CDI_CACHE_H
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <isula_libutils/oci_runtime_spec.h>
+
+#include "utils_array.h"
+#include "map.h"
+#include "cdi_device.h"
+#include "cdi_spec.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct cdi_cache;
+
+struct cdi_cache_ops {
+ // injecting CDI devices into an OCI Spec.
+ // Resolver
+ string_array *(*inject_devices)(struct cdi_cache *c, oci_runtime_spec *spec, string_array *devices, char **error);
+
+ // refreshing the cache of CDI Specs and devices.
+ // Refresher
+ char *(*configure)(struct cdi_cache *c, string_array *spec_dirs);
+ char *(*refresh)(struct cdi_cache *c);
+ map_t *(*get_errors)(struct cdi_cache *c);
+ string_array *(*get_spec_directories)(struct cdi_cache *c);
+ map_t *(*get_spec_dir_errors)(struct cdi_cache *c);
+};
+
+struct cdi_watch {
+ int watcher_fd; // inotify fd
+ map_t *tracked; // MAP_STR_BOOL tracked[spec_dirs[i]] = bool
+ map_t *wd_dirs; // MAP_INT_STR wd_dirs[wd] = spec_dirs[i]
+};
+
+// Cache stores CDI Specs loaded from Spec directories.
+struct cdi_cache {
+ pthread_mutex_t mutex;
+ string_array *spec_dirs; // cdi-spec-dirs will scan for CDI Spec files
+ map_t *specs; // MAP_STR_PTR specs[vendor] = cdi_cache_spec**
+ map_t *devices; // MAP_STR_PTR devices[cdi_device.name] = cdi_cache_device*
+ map_t *errors; // MAP_STR_PTR errors[cdi_cache_spec.path] = string_array *errors
+ map_t *dir_errors; // MAP_STR_STR dir_errors[spec_dirs[i]] = error
+
+ bool auto_refresh;
+ struct cdi_watch *watch;
+};
+
+void free_cdi_cache(struct cdi_cache *c);
+
+struct cdi_cache *cdi_new_cache(string_array *spec_dirs, char **error);
+struct cdi_cache_ops *cdi_get_cache_ops(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/src/daemon/modules/device/cdi/cdi_registry.c b/src/daemon/modules/device/cdi/cdi_registry.c
new file mode 100644
index 00000000..68767a5f
--- /dev/null
+++ b/src/daemon/modules/device/cdi/cdi_registry.c
@@ -0,0 +1,25 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi registry function
+ ******************************************************************************/
+#include "cdi_registry.h"
+
+int cdi_registry_init(string_array *spec_dirs)
+{
+ return 0;
+}
+
+struct cdi_registry *cdi_get_registry(void)
+{
+ return NULL;
+}
diff --git a/src/daemon/modules/device/cdi/cdi_registry.h b/src/daemon/modules/device/cdi/cdi_registry.h
new file mode 100644
index 00000000..c27d37e3
--- /dev/null
+++ b/src/daemon/modules/device/cdi/cdi_registry.h
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi registry function definition
+ ******************************************************************************/
+#ifndef CDI_REGISTRY_H
+#define CDI_REGISTRY_H
+
+#include "cdi_cache.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct cdi_registry {
+ struct cdi_cache *cdi_cache;
+ struct cdi_cache_ops *ops;
+};
+
+int cdi_registry_init(string_array *spec_dirs);
+struct cdi_registry *cdi_get_registry(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/src/daemon/modules/device/cdi_operate.c b/src/daemon/modules/device/cdi_operate.c
new file mode 100644
index 00000000..c7aa77d8
--- /dev/null
+++ b/src/daemon/modules/device/cdi_operate.c
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * Copyright (c) Huawei Technologies Co., Ltd. 2024. 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:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
+ * PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ * Author: liuxu
+ * Create: 2024-03-06
+ * Description: provide cdi device manager function
+ ******************************************************************************/
+#include "cdi_operate_api.h"
+
+int cdi_operate_registry_init(char **specs_dirs, size_t specs_dirs_len)
+{
+ return 0;
+}
+
+char *cdi_operate_refresh(void)
+{
+ return NULL;
+}
+
+string_array *cdi_operate_inject_devices(oci_runtime_spec *spec, string_array *devices, char **error)
+{
+ return NULL;
+}
+
+char *cdi_operate_parse_annotations(json_map_string_string *annotations, string_array **keys, string_array **devices)
+{
+ return NULL;
+}
\ No newline at end of file
--
2.34.1
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化