1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
|
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
|