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
|
From 16da66344854a75ce7a9d7908e0a75732eb147dc Mon Sep 17 00:00:00 2001
From: liuxu <liuxu156@huawei.com>
Date: Wed, 27 Nov 2024 15:11:57 +0800
Subject: [PATCH 01/11] sandbox: del shim_sandbox and change sandbox ops
Signed-off-by: liuxu <liuxu156@huawei.com>
---
src/daemon/sandbox/sandbox.cc | 28 ++
src/daemon/sandbox/sandbox.h | 15 +-
src/daemon/sandbox/sandbox_manager.cc | 9 +-
src/daemon/sandbox/sandbox_ops.cc | 363 +---------------
.../sandbox/sandboxer/sandboxer_sandbox.cc | 401 ++++++++++++++++++
.../sandbox/sandboxer/sandboxer_sandbox.h | 33 +-
src/daemon/sandbox/shim/shim_sandbox.cc | 65 ---
src/daemon/sandbox/shim/shim_sandbox.h | 49 ---
8 files changed, 469 insertions(+), 494 deletions(-)
delete mode 100644 src/daemon/sandbox/shim/shim_sandbox.cc
delete mode 100644 src/daemon/sandbox/shim/shim_sandbox.h
diff --git a/src/daemon/sandbox/sandbox.cc b/src/daemon/sandbox/sandbox.cc
index 3715e5e0..d105d71a 100644
--- a/src/daemon/sandbox/sandbox.cc
+++ b/src/daemon/sandbox/sandbox.cc
@@ -1118,4 +1118,32 @@ void Sandbox::FillSandboxMetadata(sandbox_metadata* metadata, Errors &error)
metadata->sandbox_config_json = util_strdup_s(jsonStr.c_str());
}
+
+void Sandbox::LoadSandboxTasks()
+{
+}
+
+auto Sandbox::PrepareContainer(const char *containerId, const char *baseFs,
+ const oci_runtime_spec *ociSpec,
+ const char *consoleFifos[]) -> int
+{
+ return 0;
+}
+
+auto Sandbox::PrepareExec(const char *containerId, const char *execId,
+ defs_process *processSpec, const char *consoleFifos[]) -> int
+{
+ return 0;
+}
+
+auto Sandbox::PurgeContainer(const char *containerId) -> int
+{
+ return 0;
+}
+
+auto Sandbox::PurgeExec(const char *containerId, const char *execId) -> int
+{
+ return 0;
+}
+
}
\ No newline at end of file
diff --git a/src/daemon/sandbox/sandbox.h b/src/daemon/sandbox/sandbox.h
index 415406ff..58d60ecb 100644
--- a/src/daemon/sandbox/sandbox.h
+++ b/src/daemon/sandbox/sandbox.h
@@ -141,13 +141,14 @@ public:
void Status(runtime::v1::PodSandboxStatus &status);
// for sandbox api update
- virtual void LoadSandboxTasks() = 0;
- virtual auto SaveSandboxTasks() -> bool = 0;
- virtual auto AddSandboxTasks(sandbox_task *task) -> bool = 0;
- virtual auto GetAnySandboxTasks() -> std::string = 0;
- virtual void DeleteSandboxTasks(const char *containerId) = 0;
- virtual auto AddSandboxTasksProcess(const char *containerId, sandbox_process *processes) -> bool = 0;
- virtual void DeleteSandboxTasksProcess(const char *containerId, const char *execId) = 0;
+ virtual void LoadSandboxTasks();
+ virtual auto PrepareContainer(const char *containerId, const char *baseFs,
+ const oci_runtime_spec *ociSpec,
+ const char *consoleFifos[]) -> int;
+ virtual auto PrepareExec(const char *containerId, const char *execId,
+ defs_process *processSpec, const char *consoleFifos[]) -> int;
+ virtual auto PurgeContainer(const char *containerId) -> int;
+ virtual auto PurgeExec(const char *containerId, const char *execId) -> int;
private:
auto SaveState(Errors &error) -> bool;
diff --git a/src/daemon/sandbox/sandbox_manager.cc b/src/daemon/sandbox/sandbox_manager.cc
index ba003d56..a7908a60 100644
--- a/src/daemon/sandbox/sandbox_manager.cc
+++ b/src/daemon/sandbox/sandbox_manager.cc
@@ -27,7 +27,6 @@
#ifdef ENABLE_SANDBOXER
#include "sandboxer_sandbox.h"
#endif
-#include "shim_sandbox.h"
#include "isulad_config.h"
#include "utils_verify.h"
#include "utils_file.h"
@@ -116,12 +115,12 @@ auto SandboxManager::CreateSandbox(const std::string &name, RuntimeInfo &info, s
#ifdef ENABLE_SANDBOXER
if (info.sandboxer == SHIM_CONTROLLER_NAME) {
- sandbox = std::make_shared<ShimSandbox>(id, m_rootdir, m_statedir, name, info, netMode, netNsPath, sandboxConfig, image);
+ sandbox = std::make_shared<Sandbox>(id, m_rootdir, m_statedir, name, info, netMode, netNsPath, sandboxConfig, image);
} else {
sandbox = std::make_shared<SandboxerSandbox>(id, m_rootdir, m_statedir, name, info, netMode, netNsPath, sandboxConfig, image);
}
#else
- sandbox = std::make_shared<ShimSandbox>(id, m_rootdir, m_statedir, name, info, netMode, netNsPath, sandboxConfig, image);
+ sandbox = std::make_shared<Sandbox>(id, m_rootdir, m_statedir, name, info, netMode, netNsPath, sandboxConfig, image);
#endif
if (sandbox == nullptr) {
ERROR("Failed to malloc for sandbox: %s", name.c_str());
@@ -485,12 +484,12 @@ auto SandboxManager::LoadSandbox(std::string &id) -> std::shared_ptr<Sandbox>
#ifdef ENABLE_SANDBOXER
if (IsShimSandbox(id, m_rootdir)) {
- sandbox = std::make_shared<ShimSandbox>(id, m_rootdir, m_statedir);
+ sandbox = std::make_shared<Sandbox>(id, m_rootdir, m_statedir);
} else {
sandbox = std::make_shared<SandboxerSandbox>(id, m_rootdir, m_statedir);
}
#else
- sandbox = std::make_shared<ShimSandbox>(id, m_rootdir, m_statedir);
+ sandbox = std::make_shared<Sandbox>(id, m_rootdir, m_statedir);
#endif
if (sandbox == nullptr) {
ERROR("Failed to malloc for sandboxes: %s", id.c_str());
diff --git a/src/daemon/sandbox/sandbox_ops.cc b/src/daemon/sandbox/sandbox_ops.cc
index f50a1033..ae881933 100644
--- a/src/daemon/sandbox/sandbox_ops.cc
+++ b/src/daemon/sandbox/sandbox_ops.cc
@@ -24,12 +24,6 @@
#include "sandbox.h"
#include "namespace.h"
#include "utils.h"
-#include "utils_timestamp.h"
-#include "utils_array.h"
-
-const std::string SANDBOX_EXTENSIONS_TASKS = "extensions.tasks";
-const std::string SANDBOX_TASKS_KEY = "tasks";
-const std::string SANDBOX_TASKS_TYPEURL = "github.com/containerd/containerd/Tasks";
static inline bool validate_sandbox_info(const container_sandbox_info *sandbox)
{
@@ -37,99 +31,6 @@ static inline bool validate_sandbox_info(const container_sandbox_info *sandbox)
sandbox->id != NULL);
}
-static int generate_ctrl_rootfs(sandbox_task *task,
- const container_config_v2_common_config *config)
-{
- size_t len = 1;
- if (nullptr == config->base_fs) {
- ERROR("Container %s has no base fs", config->id);
- return -1;
- }
-
- // TODO: rootfs's options left to be configured
- task->rootfs = (sandbox_mount **)util_smart_calloc_s(sizeof(sandbox_mount *), len);
- if (task->rootfs == nullptr) {
- ERROR("Out of memory.");
- return -1;
- }
- task->rootfs[0] = (sandbox_mount *)util_common_calloc_s(sizeof(sandbox_mount));
- if (task->rootfs[0] == nullptr) {
- ERROR("Out of memory.");
- return -1;
- }
- task->rootfs_len = len;
- task->rootfs[0]->type = util_strdup_s(MOUNT_TYPE_BIND);
- task->rootfs[0]->source = util_strdup_s(config->base_fs);
-
- return 0;
-}
-
-static int do_sandbox_update(std::shared_ptr<sandbox::Sandbox> &sandbox, sandbox_sandbox *apiSandbox)
-{
- Errors err;
- size_t fields_len = 1;
- __isula_auto_string_array_t string_array *fields = nullptr;
-
- fields = util_string_array_new(fields_len);
- if (fields == nullptr) {
- ERROR("Out of memory.");
- return -1;
- }
- if (util_append_string_array(fields, SANDBOX_EXTENSIONS_TASKS.c_str())) {
- ERROR("Out of memory.");
- return -1;
- }
-
- auto controller = sandbox::ControllerManager::GetInstance()->GetController(sandbox->GetSandboxer());
- if (nullptr == controller) {
- ERROR("Invalid sandboxer name: %s", sandbox->GetSandboxer().c_str());
- return -1;
- }
-
- if (!controller->Update(apiSandbox, fields, err)) {
- ERROR("Failed to update in container controller update: %s", err.GetCMessage());
- return -1;
- }
-
- return 0;
-}
-
-static oci_runtime_spec *clone_oci_runtime_spec(const oci_runtime_spec *oci_spec)
-{
- __isula_auto_free char *json_str = nullptr;
- __isula_auto_free parser_error err = nullptr;
- oci_runtime_spec *ret = nullptr;
-
- json_str = oci_runtime_spec_generate_json(oci_spec, nullptr, &err);
- if (json_str == nullptr) {
- ERROR("Failed to generate spec json: %s", err);
- return nullptr;
- }
- ret = oci_runtime_spec_parse_data(json_str, nullptr, &err);
- if (ret == nullptr) {
- ERROR("Failed to generate spec: %s", err);
- }
- return ret;
-}
-
-static defs_process *clone_defs_process(defs_process *process_spec)
-{
- __isula_auto_free char *json_str = nullptr;
- __isula_auto_free parser_error err = nullptr;
- defs_process *ret = nullptr;
-
- json_str = defs_process_generate_json(process_spec, nullptr, &err);
- if (json_str == nullptr) {
- ERROR("Failed to generate process spec json: %s", err);
- return nullptr;
- }
- ret = defs_process_parse_data(json_str, nullptr, &err);
- if (ret == nullptr) {
- ERROR("Failed to generate process spec: %s", err);
- }
- return ret;
-}
-
static std::shared_ptr<sandbox::Sandbox> get_prepare_sandbox(const container_config_v2_common_config *config)
{
if (nullptr == config || nullptr == config->id) {
@@ -151,126 +52,11 @@ static std::shared_ptr<sandbox::Sandbox> get_prepare_sandbox(const container_con
return sandbox;
}
-static sandbox_sandbox_runtime *init_sandbox_runtime(std::shared_ptr<sandbox::Sandbox> sandbox)
-{
- sandbox_sandbox_runtime *runtime = nullptr;
-
- auto runtime_wrapper = makeUniquePtrCStructWrapper<sandbox_sandbox_runtime>(free_sandbox_sandbox_runtime);
- if (runtime_wrapper == nullptr) {
- ERROR("Out of memory");
- return nullptr;
- }
- runtime = runtime_wrapper->get();
- runtime->name = util_strdup_s(sandbox->GetRuntime().c_str());
- // Just ignore options for now
-
- return runtime_wrapper->move();
-}
-
-static json_map_string_string *init_sandbox_labels(std::shared_ptr<sandbox::Sandbox> sandbox)
-{
- json_map_string_string *labels = nullptr;
-
- auto labels_wrapper = makeUniquePtrCStructWrapper<json_map_string_string>(free_json_map_string_string);
- if (labels_wrapper == nullptr) {
- ERROR("Out of memory");
- return nullptr;
- }
- labels = labels_wrapper->get();
- if (append_json_map_string_string(labels, "name", sandbox->GetName().c_str()) != 0) {
- ERROR("Out of memory");
- return nullptr;
- }
-
- return labels_wrapper->move();
-}
-
-static defs_map_string_object_any *init_sandbox_extensions(std::shared_ptr<sandbox::Sandbox> sandbox)
-{
- defs_map_string_object_any *extensions = nullptr;
- size_t len = 1;
- std::string task_json;
-
- auto extensions_wrapper = makeUniquePtrCStructWrapper<defs_map_string_object_any>(free_defs_map_string_object_any);
- if (extensions_wrapper == nullptr) {
- ERROR("Out of memory");
- return nullptr;
- }
- extensions = extensions_wrapper->get();
- extensions->keys = (char **)util_smart_calloc_s(sizeof(char *), len);
- if (extensions->keys == nullptr) {
- ERROR("Out of memory.");
- return nullptr;
- }
- extensions->len = len;
- extensions->values = (defs_map_string_object_any_element **)
- util_smart_calloc_s(sizeof(defs_map_string_object_any_element *), len);
- if (extensions->values == nullptr) {
- ERROR("Out of memory.");
- return nullptr;
- }
- extensions->values[0] = (defs_map_string_object_any_element *)
- util_common_calloc_s(sizeof(defs_map_string_object_any_element));
- if (extensions->values[0] == nullptr) {
- ERROR("Out of memory.");
- return nullptr;
- }
- extensions->values[0]->element = (defs_any *)util_common_calloc_s(sizeof(defs_any));
- if (extensions->values[0]->element == nullptr) {
- ERROR("Out of memory.");
- return nullptr;
- }
-
- extensions->keys[0] = util_strdup_s(SANDBOX_TASKS_KEY.c_str());
- task_json = sandbox->GetAnySandboxTasks();
- if (task_json.empty()) {
- ERROR("Failed to get any sandbox tasks");
- return nullptr;
- }
- DEBUG("Get any sandbox tasks %s", task_json.c_str());
- extensions->values[0]->element->type_url = util_strdup_s(SANDBOX_TASKS_TYPEURL.c_str());
- extensions->values[0]->element->value = reinterpret_cast<uint8_t *>(util_strdup_s(task_json.c_str()));
- extensions->values[0]->element->value_len = strlen(task_json.c_str());
-
- return extensions_wrapper->move();
-}
-
-static int init_api_sandbox(std::shared_ptr<sandbox::Sandbox> sandbox, sandbox_sandbox *apiSandbox)
-{
- apiSandbox->sandbox_id = util_strdup_s(sandbox->GetId().c_str());
- apiSandbox->runtime = init_sandbox_runtime(sandbox);
- if (apiSandbox->runtime == nullptr) {
- ERROR("Failed to init sandbox runtime");
- return -1;
- }
- // Just ignore spec
- apiSandbox->labels = init_sandbox_labels(sandbox);
- if (apiSandbox->labels == nullptr) {
- ERROR("Failed to init sandbox runtime");
- return -1;
- }
- apiSandbox->created_at = sandbox->GetCreatedAt();
- apiSandbox->updated_at = util_get_now_time_nanos();
- apiSandbox->extensions = init_sandbox_extensions(sandbox);
- if (apiSandbox->extensions == nullptr) {
- ERROR("Failed to init sandbox runtime");
- return -1;
- }
- apiSandbox->sandboxer = util_strdup_s(sandbox->GetSandboxer().c_str());
-
- return 0;
-}
int sandbox_prepare_container(const container_config_v2_common_config *config,
const oci_runtime_spec *oci_spec,
const char * console_fifos[], bool tty)
{
- sandbox_task *task = nullptr;
- sandbox_sandbox *apiSandbox = nullptr;
- int ret = -1;
-
- INFO("Prepare container for sandbox");
-
if (nullptr == console_fifos) {
ERROR("Invlaid parameter: console_fifos");
return -1;
@@ -282,67 +68,13 @@ int sandbox_prepare_container(const container_config_v2_common_config *config,
return -1;
}
- auto apiSandbox_wrapper = makeUniquePtrCStructWrapper<sandbox_sandbox>(free_sandbox_sandbox);
- if (apiSandbox_wrapper == nullptr) {
- ERROR("Out of memory");
- return -1;
- }
- apiSandbox = apiSandbox_wrapper->get();
- auto task_wrapper = makeUniquePtrCStructWrapper<sandbox_task>(free_sandbox_task);
- if (task_wrapper == nullptr) {
- ERROR("Out of memory");
- return -1;
- }
- task = task_wrapper->get();
-
- task->task_id = util_strdup_s(config->id);
- task->spec = clone_oci_runtime_spec(oci_spec);
- if (task->spec == nullptr) {
- ERROR("Out of memory.");
- return -1;
- }
- if (generate_ctrl_rootfs(task, config) != 0) {
- ERROR("Invalid rootfs");
- return -1;
- }
- task->stdin = util_strdup_s((nullptr == console_fifos[0]) ? "" : console_fifos[0]);
- task->stdout = util_strdup_s((nullptr == console_fifos[1]) ? "" : console_fifos[1]);
- task->stderr = util_strdup_s((nullptr == console_fifos[2]) ? "" : console_fifos[2]);
-
- if (!sandbox->AddSandboxTasks(task)) {
- ERROR("Failed to add sandbox %s task.", config->id);
- return -1;
- }
- task = task_wrapper->move();
- ret = init_api_sandbox(sandbox, apiSandbox);
- if (ret != 0) {
- ERROR("Failed to init %s api sandbox.", config->id);
- goto del_out;
- }
- ret = do_sandbox_update(sandbox, apiSandbox);
-
-del_out:
- if (ret != 0) {
- sandbox->DeleteSandboxTasks(config->id);
- }
- if (!sandbox->SaveSandboxTasks()) {
- ERROR("Failed to Save %s sandbox tasks.", config->id);
- ret = -1;
- }
-
- return ret;
+ return sandbox->PrepareContainer(config->id, config->base_fs, oci_spec, console_fifos);
}
int sandbox_prepare_exec(const container_config_v2_common_config *config,
const char *exec_id, defs_process *process_spec,
const char * console_fifos[], bool tty)
{
- sandbox_process *process = nullptr;
- sandbox_sandbox *apiSandbox = nullptr;
- int ret = -1;
-
- INFO("Prepare exec for container in sandbox");
-
if (nullptr == console_fifos) {
ERROR("Invlaid parameter: console_fifos");
return -1;
@@ -354,116 +86,29 @@ int sandbox_prepare_exec(const container_config_v2_common_config *config,
return -1;
}
- auto apiSandbox_wrapper = makeUniquePtrCStructWrapper<sandbox_sandbox>(free_sandbox_sandbox);
- if (apiSandbox_wrapper == nullptr) {
- ERROR("Out of memory");
- return -1;
- }
- apiSandbox = apiSandbox_wrapper->get();
- auto process_wrapper = makeUniquePtrCStructWrapper<sandbox_process>(free_sandbox_process);
- if (process_wrapper == nullptr) {
- ERROR("Out of memory");
- return -1;
- }
- process = process_wrapper->get();
-
- process->exec_id = util_strdup_s(exec_id);
- process->spec = clone_defs_process(process_spec);
- if (process->spec == nullptr) {
- ERROR("Out of memory.");
- return -1;
- }
- process->stdin = util_strdup_s((nullptr == console_fifos[0]) ? "" : console_fifos[0]);
- process->stdout = util_strdup_s((nullptr == console_fifos[1]) ? "" : console_fifos[1]);
- process->stderr = util_strdup_s((nullptr == console_fifos[2]) ? "" : console_fifos[2]);
-
- if (!sandbox->AddSandboxTasksProcess(config->id, process)) {
- ERROR("Failed to add sandbox %s process.", config->id);
- return -1;
- }
- process = process_wrapper->move();
- ret = init_api_sandbox(sandbox, apiSandbox);
- if (ret != 0) {
- ERROR("Failed to init %s api sandbox.", config->id);
- goto del_out;
- }
- ret = do_sandbox_update(sandbox, apiSandbox);
-
-del_out:
- if (ret != 0) {
- sandbox->DeleteSandboxTasksProcess(config->id, exec_id);
- }
- if (!sandbox->SaveSandboxTasks()) {
- ERROR("Failed to Save %s sandbox tasks.", config->id);
- ret = -1;
- }
-
- return ret;
+ return sandbox->PrepareExec(config->id, exec_id, process_spec, console_fifos);
}
int sandbox_purge_container(const container_config_v2_common_config *config)
{
- sandbox_sandbox *apiSandbox = nullptr;
-
- INFO("Purge container for sandbox");
-
auto sandbox = get_prepare_sandbox(config);
if (sandbox == nullptr) {
ERROR("Sandbox not found");
return -1;
}
- auto apiSandbox_wrapper = makeUniquePtrCStructWrapper<sandbox_sandbox>(free_sandbox_sandbox);
- if (apiSandbox_wrapper == nullptr) {
- ERROR("Out of memory");
- return -1;
- }
- apiSandbox = apiSandbox_wrapper->get();
-
- sandbox->DeleteSandboxTasks(config->id);
- if (!sandbox->SaveSandboxTasks()) {
- ERROR("Failed to Save %s sandbox tasks.", config->id);
- return -1;
- }
-
- if (init_api_sandbox(sandbox, apiSandbox) != 0) {
- ERROR("Failed to init %s api sandbox.", config->id);
- return -1;
- }
- return do_sandbox_update(sandbox, apiSandbox);
+ return sandbox->PurgeContainer(config->id);
}
int sandbox_purge_exec(const container_config_v2_common_config *config, const char *exec_id)
{
- sandbox_sandbox *apiSandbox = nullptr;
-
- INFO("Purge exec for container in sandbox");
-
auto sandbox = get_prepare_sandbox(config);
if (sandbox == nullptr) {
ERROR("Sandbox not found");
return -1;
}
- auto apiSandbox_wrapper = makeUniquePtrCStructWrapper<sandbox_sandbox>(free_sandbox_sandbox);
- if (apiSandbox_wrapper == nullptr) {
- ERROR("Out of memory");
- return -1;
- }
- apiSandbox = apiSandbox_wrapper->get();
-
- sandbox->DeleteSandboxTasksProcess(config->id, exec_id);
- if (!sandbox->SaveSandboxTasks()) {
- ERROR("Failed to Save %s sandbox tasks.", config->id);
- return -1;
- }
-
- if (init_api_sandbox(sandbox, apiSandbox) != 0) {
- ERROR("Failed to init %s api sandbox.", exec_id);
- return -1;
- }
-
- return do_sandbox_update(sandbox, apiSandbox);
+ return sandbox->PurgeExec(config->id, exec_id);
}
int sandbox_on_sandbox_exit(const char *sandbox_id, int exit_code)
diff --git a/src/daemon/sandbox/sandboxer/sandboxer_sandbox.cc b/src/daemon/sandbox/sandboxer/sandboxer_sandbox.cc
index 726b7b3a..b2e2fb32 100644
--- a/src/daemon/sandbox/sandboxer/sandboxer_sandbox.cc
+++ b/src/daemon/sandbox/sandboxer/sandboxer_sandbox.cc
@@ -23,13 +23,21 @@
#include <isula_libutils/log.h>
#include <isula_libutils/auto_cleanup.h>
+#include <isula_libutils/sandbox_sandbox.h>
+#include <isula_libutils/defs_process.h>
#include "utils_file.h"
#include "utils.h"
#include "cxxutils.h"
+#include "utils_timestamp.h"
+#include "utils_array.h"
namespace sandbox {
+const std::string SANDBOX_EXTENSIONS_TASKS = "extensions.tasks";
+const std::string SANDBOX_TASKS_KEY = "tasks";
+const std::string SANDBOX_TASKS_TYPEURL = "github.com/containerd/containerd/Tasks";
+
SandboxerSandbox::SandboxerSandbox(const std::string id, const std::string &rootdir, const std::string &statedir, const std::string name,
const RuntimeInfo info, std::string netMode, std::string netNsPath, const runtime::v1::PodSandboxConfig sandboxConfig,
const std::string image):Sandbox(id, rootdir, statedir, name, info, netMode,
@@ -251,4 +259,397 @@ void SandboxerSandbox::DeleteSandboxTasksProcess(const char *containerId, const
iter->second->DeleteSandboxTasksProcess(execId);
}
+static oci_runtime_spec *clone_oci_runtime_spec(const oci_runtime_spec *oci_spec)
+{
+ __isula_auto_free char *json_str = nullptr;
+ __isula_auto_free parser_error err = nullptr;
+ oci_runtime_spec *ret = nullptr;
+
+ json_str = oci_runtime_spec_generate_json(oci_spec, nullptr, &err);
+ if (json_str == nullptr) {
+ ERROR("Failed to generate spec json: %s", err);
+ return nullptr;
+ }
+ ret = oci_runtime_spec_parse_data(json_str, nullptr, &err);
+ if (ret == nullptr) {
+ ERROR("Failed to generate spec: %s", err);
+ }
+ return ret;
+}
+
+static defs_process *clone_defs_process(defs_process *process_spec)
+{
+ __isula_auto_free char *json_str = nullptr;
+ __isula_auto_free parser_error err = nullptr;
+ defs_process *ret = nullptr;
+
+ json_str = defs_process_generate_json(process_spec, nullptr, &err);
+ if (json_str == nullptr) {
+ ERROR("Failed to generate process spec json: %s", err);
+ return nullptr;
+ }
+ ret = defs_process_parse_data(json_str, nullptr, &err);
+ if (ret == nullptr) {
+ ERROR("Failed to generate process spec: %s", err);
+ }
+ return ret;
+}
+
+auto SandboxerSandbox::GenerateCtrlRootfs(sandbox_task *task, const char *baseFs) -> int
+{
+ size_t len = 1;
+ if (nullptr == baseFs) {
+ ERROR("Container %s has no base fs", task->task_id);
+ return -1;
+ }
+
+ // TODO: rootfs's options left to be configured
+ task->rootfs = (sandbox_mount **)util_smart_calloc_s(sizeof(sandbox_mount *), len);
+ if (task->rootfs == nullptr) {
+ ERROR("Out of memory.");
+ return -1;
+ }
+ task->rootfs[0] = (sandbox_mount *)util_common_calloc_s(sizeof(sandbox_mount));
+ if (task->rootfs[0] == nullptr) {
+ ERROR("Out of memory.");
+ return -1;
+ }
+ task->rootfs_len = len;
+ task->rootfs[0]->type = util_strdup_s(MOUNT_TYPE_BIND);
+ task->rootfs[0]->source = util_strdup_s(baseFs);
+
+ return 0;
+}
+
+auto SandboxerSandbox::InitSandboxRuntime() -> sandbox_sandbox_runtime *
+{
+ sandbox_sandbox_runtime *runtime = nullptr;
+
+ auto runtime_wrapper = makeUniquePtrCStructWrapper<sandbox_sandbox_runtime>(free_sandbox_sandbox_runtime);
+ if (runtime_wrapper == nullptr) {
+ ERROR("Out of memory");
+ return nullptr;
+ }
+ runtime = runtime_wrapper->get();
+ runtime->name = util_strdup_s(GetRuntime().c_str());
+ // Just ignore options for now
+
+ return runtime_wrapper->move();
+}
+
+auto SandboxerSandbox::InitSandboxLabels() -> json_map_string_string *
+{
+ json_map_string_string *labels = nullptr;
+
+ auto labels_wrapper = makeUniquePtrCStructWrapper<json_map_string_string>(free_json_map_string_string);
+ if (labels_wrapper == nullptr) {
+ ERROR("Out of memory");
+ return nullptr;
+ }
+ labels = labels_wrapper->get();
+ if (append_json_map_string_string(labels, "name", GetName().c_str()) != 0) {
+ ERROR("Out of memory");
+ return nullptr;
+ }
+
+ return labels_wrapper->move();
+}
+
+auto SandboxerSandbox::InitSandboxExtensions() -> defs_map_string_object_any *
+{
+ defs_map_string_object_any *extensions = nullptr;
+ size_t len = 1;
+ std::string task_json;
+
+ auto extensions_wrapper = makeUniquePtrCStructWrapper<defs_map_string_object_any>(free_defs_map_string_object_any);
+ if (extensions_wrapper == nullptr) {
+ ERROR("Out of memory");
+ return nullptr;
+ }
+ extensions = extensions_wrapper->get();
+
+ extensions->keys = (char **)util_smart_calloc_s(sizeof(char *), len);
+ if (extensions->keys == nullptr) {
+ ERROR("Out of memory.");
+ return nullptr;
+ }
+ extensions->values = (defs_map_string_object_any_element **)
+ util_smart_calloc_s(sizeof(defs_map_string_object_any_element *), len);
+ if (extensions->values == nullptr) {
+ ERROR("Out of memory.");
+ free(extensions->keys);
+ extensions->keys = nullptr;
+ return nullptr;
+ }
+ extensions->len = len;
+
+ extensions->values[0] = (defs_map_string_object_any_element *)
+ util_common_calloc_s(sizeof(defs_map_string_object_any_element));
+ if (extensions->values[0] == nullptr) {
+ ERROR("Out of memory.");
+ return nullptr;
+ }
+ extensions->values[0]->element = (defs_any *)util_common_calloc_s(sizeof(defs_any));
+ if (extensions->values[0]->element == nullptr) {
+ ERROR("Out of memory.");
+ return nullptr;
+ }
+
+ extensions->keys[0] = util_strdup_s(SANDBOX_TASKS_KEY.c_str());
+ task_json = GetAnySandboxTasks();
+ if (task_json.empty()) {
+ ERROR("Failed to get any sandbox tasks");
+ return nullptr;
+ }
+ DEBUG("Get any sandbox tasks %s", task_json.c_str());
+ extensions->values[0]->element->type_url = util_strdup_s(SANDBOX_TASKS_TYPEURL.c_str());
+ extensions->values[0]->element->value = reinterpret_cast<uint8_t *>(util_strdup_s(task_json.c_str()));
+ extensions->values[0]->element->value_len = strlen(task_json.c_str());
+
+ return extensions_wrapper->move();
+}
+
+auto SandboxerSandbox::InitApiSandbox(sandbox_sandbox *apiSandbox) -> int
+{
+ apiSandbox->sandbox_id = util_strdup_s(GetId().c_str());
+ apiSandbox->runtime = InitSandboxRuntime();
+ if (apiSandbox->runtime == nullptr) {
+ ERROR("Failed to init sandbox runtime");
+ return -1;
+ }
+ // Just ignore spec
+ apiSandbox->labels = InitSandboxLabels();
+ if (apiSandbox->labels == nullptr) {
+ ERROR("Failed to init sandbox runtime");
+ return -1;
+ }
+ apiSandbox->created_at = GetCreatedAt();
+ apiSandbox->updated_at = util_get_now_time_nanos();
+ apiSandbox->extensions = InitSandboxExtensions();
+ if (apiSandbox->extensions == nullptr) {
+ ERROR("Failed to init sandbox runtime");
+ return -1;
+ }
+ apiSandbox->sandboxer = util_strdup_s(GetSandboxer().c_str());
+
+ return 0;
+}
+
+auto SandboxerSandbox::DoSandboxUpdate(sandbox_sandbox *apiSandbox) -> int
+{
+ Errors err;
+ size_t fields_len = 1;
+ __isula_auto_string_array_t string_array *fields = nullptr;
+
+ fields = util_string_array_new(fields_len);
+ if (fields == nullptr) {
+ ERROR("Out of memory.");
+ return -1;
+ }
+ if (util_append_string_array(fields, SANDBOX_EXTENSIONS_TASKS.c_str())) {
+ ERROR("Out of memory.");
+ return -1;
+ }
+
+ auto controller = sandbox::ControllerManager::GetInstance()->GetController(GetSandboxer());
+ if (nullptr == controller) {
+ ERROR("Invalid sandboxer name: %s", GetSandboxer().c_str());
+ return -1;
+ }
+
+ if (!controller->Update(apiSandbox, fields, err)) {
+ ERROR("Failed to update in container controller update: %s", err.GetCMessage());
+ return -1;
+ }
+
+ return 0;
+}
+
+auto SandboxerSandbox::PrepareContainer(const char *containerId, const char *baseFs,
+ const oci_runtime_spec *ociSpec,
+ const char *consoleFifos[]) -> int
+{
+ sandbox_task *task = nullptr;
+ sandbox_sandbox *apiSandbox = nullptr;
+
+ INFO("Prepare container for sandbox");
+
+ if (nullptr == consoleFifos) {
+ ERROR("Invlaid parameter: consoleFifos");
+ return -1;
+ }
+
+ auto apiSandbox_wrapper = makeUniquePtrCStructWrapper<sandbox_sandbox>(free_sandbox_sandbox);
+ if (apiSandbox_wrapper == nullptr) {
+ ERROR("Out of memory");
+ return -1;
+ }
+ apiSandbox = apiSandbox_wrapper->get();
+ auto task_wrapper = makeUniquePtrCStructWrapper<sandbox_task>(free_sandbox_task);
+ if (task_wrapper == nullptr) {
+ ERROR("Out of memory");
+ return -1;
+ }
+ task = task_wrapper->get();
+
+ task->task_id = util_strdup_s(containerId);
+ task->spec = clone_oci_runtime_spec(ociSpec);
+ if (task->spec == nullptr) {
+ ERROR("Out of memory.");
+ return -1;
+ }
+ if (GenerateCtrlRootfs(task, baseFs) != 0) {
+ ERROR("Invalid rootfs");
+ return -1;
+ }
+ task->stdin = util_strdup_s((nullptr == consoleFifos[0]) ? "" : consoleFifos[0]);
+ task->stdout = util_strdup_s((nullptr == consoleFifos[1]) ? "" : consoleFifos[1]);
+ task->stderr = util_strdup_s((nullptr == consoleFifos[2]) ? "" : consoleFifos[2]);
+
+ if (!AddSandboxTasks(task)) {
+ ERROR("Failed to add sandbox %s task.", containerId);
+ return -1;
+ }
+ task = task_wrapper->move();
+ if (InitApiSandbox(apiSandbox) != 0) {
+ ERROR("Failed to init %s api sandbox.", containerId);
+ goto del_out;
+ }
+ if (DoSandboxUpdate(apiSandbox) != 0) {
+ ERROR("Failed to update %s api sandbox.", containerId);
+ goto del_out;
+ }
+ if (!SaveSandboxTasks()) {
+ ERROR("Failed to Save %s sandbox tasks.", containerId);
+ (void)PurgeContainer(containerId);
+ return -1;
+ }
+ return 0;
+
+del_out:
+ DeleteSandboxTasks(containerId);
+ return -1;
+}
+
+auto SandboxerSandbox::PrepareExec(const char *containerId, const char *execId,
+ defs_process *processSpec, const char *consoleFifos[]) -> int
+{
+ sandbox_process *process = nullptr;
+ sandbox_sandbox *apiSandbox = nullptr;
+
+ INFO("Prepare exec for container in sandbox");
+
+ if (nullptr == consoleFifos) {
+ ERROR("Invlaid parameter: consoleFifos");
+ return -1;
+ }
+
+ auto apiSandbox_wrapper = makeUniquePtrCStructWrapper<sandbox_sandbox>(free_sandbox_sandbox);
+ if (apiSandbox_wrapper == nullptr) {
+ ERROR("Out of memory");
+ return -1;
+ }
+ apiSandbox = apiSandbox_wrapper->get();
+ auto process_wrapper = makeUniquePtrCStructWrapper<sandbox_process>(free_sandbox_process);
+ if (process_wrapper == nullptr) {
+ ERROR("Out of memory");
+ return -1;
+ }
+ process = process_wrapper->get();
+
+ process->exec_id = util_strdup_s(execId);
+ process->spec = clone_defs_process(processSpec);
+ if (process->spec == nullptr) {
+ ERROR("Out of memory.");
+ return -1;
+ }
+ process->stdin = util_strdup_s((nullptr == consoleFifos[0]) ? "" : consoleFifos[0]);
+ process->stdout = util_strdup_s((nullptr == consoleFifos[1]) ? "" : consoleFifos[1]);
+ process->stderr = util_strdup_s((nullptr == consoleFifos[2]) ? "" : consoleFifos[2]);
+
+ if (!AddSandboxTasksProcess(containerId, process)) {
+ ERROR("Failed to add sandbox %s process.", containerId);
+ return -1;
+ }
+ process = process_wrapper->move();
+ if (InitApiSandbox(apiSandbox) != 0) {
+ ERROR("Failed to init %s api sandbox.", containerId);
+ goto del_out;
+ }
+ if (DoSandboxUpdate(apiSandbox) != 0) {
+ ERROR("Failed to init %s api sandbox.", containerId);
+ goto del_out;
+ }
+ if (!SaveSandboxTasks()) {
+ ERROR("Failed to Save %s sandbox tasks.", containerId);
+ (void)PurgeExec(containerId, execId);
+ return -1;
+ }
+ return 0;
+
+del_out:
+ DeleteSandboxTasksProcess(containerId, execId);
+ return -1;
+}
+
+auto SandboxerSandbox::PurgeContainer(const char *containerId) -> int
+{
+ sandbox_sandbox *apiSandbox = nullptr;
+
+ INFO("Purge container for sandbox");
+
+ auto apiSandbox_wrapper = makeUniquePtrCStructWrapper<sandbox_sandbox>(free_sandbox_sandbox);
+ if (apiSandbox_wrapper == nullptr) {
+ ERROR("Out of memory");
+ return -1;
+ }
+ apiSandbox = apiSandbox_wrapper->get();
+
+ DeleteSandboxTasks(containerId);
+
+ if (InitApiSandbox(apiSandbox) != 0) {
+ ERROR("Failed to init %s api sandbox.", containerId);
+ return -1;
+ }
+ if (DoSandboxUpdate(apiSandbox) != 0) {
+ ERROR("Failed to update %s api sandbox.", containerId);
+ return -1;
+ }
+ if (!SaveSandboxTasks()) {
+ ERROR("Failed to Save %s sandbox tasks.", containerId);
+ return -1;
+ }
+ return 0;
+}
+
+auto SandboxerSandbox::PurgeExec(const char *containerId, const char *execId) -> int
+{
+ sandbox_sandbox *apiSandbox = nullptr;
+
+ INFO("Purge exec for container in sandbox");
+
+ auto apiSandbox_wrapper = makeUniquePtrCStructWrapper<sandbox_sandbox>(free_sandbox_sandbox);
+ if (apiSandbox_wrapper == nullptr) {
+ ERROR("Out of memory");
+ return -1;
+ }
+ apiSandbox = apiSandbox_wrapper->get();
+
+ DeleteSandboxTasksProcess(containerId, execId);
+
+ if (InitApiSandbox(apiSandbox) != 0) {
+ ERROR("Failed to init %s api sandbox.", execId);
+ return -1;
+ }
+ if (DoSandboxUpdate(apiSandbox) != 0) {
+ ERROR("Failed to update %s api sandbox.", execId);
+ return -1;
+ }
+ if (!SaveSandboxTasks()) {
+ ERROR("Failed to Save %s sandbox tasks.", containerId);
+ return -1;
+ }
+ return 0;
+}
+
}
\ No newline at end of file
diff --git a/src/daemon/sandbox/sandboxer/sandboxer_sandbox.h b/src/daemon/sandbox/sandboxer/sandboxer_sandbox.h
index 552eb328..37a96cd6 100644
--- a/src/daemon/sandbox/sandboxer/sandboxer_sandbox.h
+++ b/src/daemon/sandbox/sandboxer/sandboxer_sandbox.h
@@ -33,24 +33,39 @@ public:
const runtime::v1::PodSandboxConfig sandboxConfig = runtime::v1::PodSandboxConfig::default_instance(),
const std::string image = "");
virtual ~SandboxerSandbox() = default;
-
- // for sandbox api update
- auto GetTasksJsonPath() -> std::string;
+
void LoadSandboxTasks() override;
- auto SaveSandboxTasks() -> bool override;
- auto AddSandboxTasks(sandbox_task *task) -> bool override;
- auto GetAnySandboxTasks() -> std::string override;
- void DeleteSandboxTasks(const char *containerId) override;
- auto AddSandboxTasksProcess(const char *containerId, sandbox_process *processes) -> bool override;
- void DeleteSandboxTasksProcess(const char *containerId, const char *execId) override;
+
+ auto PrepareContainer(const char *containerId, const char *baseFs,
+ const oci_runtime_spec *ociSpec,
+ const char *consoleFifos[]) -> int override;
+ auto PrepareExec(const char *containerId, const char *execId,
+ defs_process *processSpec, const char *consoleFifos[]) -> int override;
+ auto PurgeContainer(const char *containerId) -> int override;
+ auto PurgeExec(const char *containerId, const char *execId) -> int override;
private:
+ auto GetTasksJsonPath() -> std::string;
+ auto SaveSandboxTasks() -> bool;
+ auto AddSandboxTasks(sandbox_task *task) -> bool;
+ auto GetAnySandboxTasks() -> std::string;
+ void DeleteSandboxTasks(const char *containerId);
+ auto AddSandboxTasksProcess(const char *containerId, sandbox_process *processes) -> bool;
+ void DeleteSandboxTasksProcess(const char *containerId, const char *execId);
+
auto AddTaskById(const char *task_id, sandbox_task *task) -> bool;
auto ReadSandboxTasksJson() -> sandbox_tasks *;
auto WriteSandboxTasksJson(std::string &tasks_json) -> bool;
auto DeleteSandboxTasksJson() -> bool;
void AddSandboxTasksByArray(sandbox_tasks *tasksArray);
+ auto GenerateCtrlRootfs(sandbox_task *task, const char *baseFs) -> int;
+ auto InitSandboxRuntime() -> sandbox_sandbox_runtime *;
+ auto InitSandboxLabels() -> json_map_string_string *;
+ auto InitSandboxExtensions() -> defs_map_string_object_any *;
+ auto InitApiSandbox(sandbox_sandbox *apiSandbox) -> int;
+ auto DoSandboxUpdate(sandbox_sandbox *apiSandbox) -> int;
+
private:
// use m_tasksMutex to ensure the correctness of the tasks
RWMutex m_tasksMutex;
diff --git a/src/daemon/sandbox/shim/shim_sandbox.cc b/src/daemon/sandbox/shim/shim_sandbox.cc
deleted file mode 100644
index 2efb8d7c..00000000
--- a/src/daemon/sandbox/shim/shim_sandbox.cc
+++ /dev/null
@@ -1,65 +0,0 @@
-/******************************************************************************
- * 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-11-20
- * Description: provide sandboxer sandbox class definition
- *********************************************************************************/
-#include "shim_sandbox.h"
-
-#include <unistd.h>
-#include <string>
-
-#include <isula_libutils/log.h>
-#include <isula_libutils/auto_cleanup.h>
-
-
-namespace sandbox {
-
-ShimSandbox::ShimSandbox(const std::string id, const std::string &rootdir, const std::string &statedir, const std::string name,
- const RuntimeInfo info, std::string netMode, std::string netNsPath, const runtime::v1::PodSandboxConfig sandboxConfig,
- const std::string image):Sandbox(id, rootdir, statedir, name, info, netMode,
- netNsPath, sandboxConfig, image)
-{
-}
-
-void ShimSandbox::LoadSandboxTasks()
-{
-}
-
-auto ShimSandbox::SaveSandboxTasks() -> bool
-{
- return true;
-}
-
-auto ShimSandbox::AddSandboxTasks(sandbox_task *task) -> bool
-{
- return true;
-}
-
-auto ShimSandbox::GetAnySandboxTasks() -> std::string
-{
- return std::string("Nothing for shim.");
-}
-
-void ShimSandbox::DeleteSandboxTasks(const char *containerId)
-{
-}
-
-auto ShimSandbox::AddSandboxTasksProcess(const char *containerId, sandbox_process *processes) -> bool
-{
- return true;
-}
-
-void ShimSandbox::DeleteSandboxTasksProcess(const char *containerId, const char *execId)
-{
-}
-
-}
\ No newline at end of file
diff --git a/src/daemon/sandbox/shim/shim_sandbox.h b/src/daemon/sandbox/shim/shim_sandbox.h
deleted file mode 100644
index 82da0573..00000000
--- a/src/daemon/sandbox/shim/shim_sandbox.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/******************************************************************************
- * 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-11-20
- * Description: provide shim sandbox class definition
- *********************************************************************************/
-
-#ifndef DAEMON_SANDBOX_SHIM_SANDBOX_H
-#define DAEMON_SANDBOX_SHIM_SANDBOX_H
-
-#include <string>
-#include <mutex>
-#include <google/protobuf/map.h>
-
-#include "read_write_lock.h"
-#include "sandbox_task.h"
-#include "sandbox.h"
-
-namespace sandbox {
-
-class ShimSandbox : public Sandbox {
-public:
- ShimSandbox(const std::string id, const std::string &rootdir, const std::string &statedir, const std::string name = "",
- const RuntimeInfo info = {"", "", ""}, std::string netMode = DEFAULT_NETMODE, std::string netNsPath = "",
- const runtime::v1::PodSandboxConfig sandboxConfig = runtime::v1::PodSandboxConfig::default_instance(),
- const std::string image = "");
- virtual ~ShimSandbox() = default;
-
- // for sandbox api update
- void LoadSandboxTasks() override;
- auto SaveSandboxTasks() -> bool override;
- auto AddSandboxTasks(sandbox_task *task) -> bool override;
- auto GetAnySandboxTasks() -> std::string override;
- void DeleteSandboxTasks(const char *containerId) override;
- auto AddSandboxTasksProcess(const char *containerId, sandbox_process *processes) -> bool override;
- void DeleteSandboxTasksProcess(const char *containerId, const char *execId) override;
-};
-
-} // namespace sandbox
-
-#endif // DAEMON_SANDBOX_SHIM_SANDBOX_H
\ No newline at end of file
--
2.23.0
|