From 792f0e555cc5743213d5cf7b7899fdd8ce891c66 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Thu, 7 Jan 2021 15:43:15 +0800 Subject: [PATCH 1/2] runtime: add support for stratovirt of kata check cli Signed-off-by: LiangZhang --- kata-containers.spec | 8 +++- ...ort-for-stratovirt-of-kata-check-cli.patch | 38 +++++++++++++++++++ runtime/series.conf | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 runtime/patches/0064-runtime-add-support-for-stratovirt-of-kata-check-cli.patch diff --git a/kata-containers.spec b/kata-containers.spec index 2405ac4..4c96926 100644 --- a/kata-containers.spec +++ b/kata-containers.spec @@ -2,7 +2,7 @@ %global debug_package %{nil} %define VERSION v1.11.1 -%define RELEASE 7 +%define RELEASE 8 Name: kata-containers Version: %{VERSION} @@ -90,6 +90,12 @@ install -p -m 640 -D ./runtime/cli/config/configuration-qemu.toml %{buildroot}/u %changelog +* Thu Jan 7 2021 LiangZhang - 1.11.1-8 +- Type:feature +- ID:NA +- SUG:NA +- DESC:add suport for stratovirt of kata-check cli + * Tue Dec 22 2020 jiangpengfei - 1.11.1-7 - Type:enhancement - ID:NA diff --git a/runtime/patches/0064-runtime-add-support-for-stratovirt-of-kata-check-cli.patch b/runtime/patches/0064-runtime-add-support-for-stratovirt-of-kata-check-cli.patch new file mode 100644 index 0000000..d020b11 --- /dev/null +++ b/runtime/patches/0064-runtime-add-support-for-stratovirt-of-kata-check-cli.patch @@ -0,0 +1,38 @@ +From 5af764ee8aad86f57df64ad78b44611c47067cc9 Mon Sep 17 00:00:00 2001 +From: LiangZhang +Date: Tue, 15 Dec 2020 10:14:10 +0800 +Subject: [PATCH] runtime: add support for stratovirt of kata-check cli + +reason: The current version of kata-check lacks support of stratovirt + +Signed-off-by: LiangZhang +--- + cli/kata-check_amd64.go | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/cli/kata-check_amd64.go b/cli/kata-check_amd64.go +index 8376293..ae62746 100644 +--- a/cli/kata-check_amd64.go ++++ b/cli/kata-check_amd64.go +@@ -107,7 +107,7 @@ func setCPUtype(hypervisorType vc.HypervisorType) error { + fallthrough + case "clh": + fallthrough +- case "qemu": ++ case "qemu", "stratovirt": + archRequiredCPUFlags = map[string]string{ + cpuFlagVMX: "Virtualization support", + cpuFlagLM: "64Bit CPU", +@@ -286,6 +286,8 @@ func archHostCanCreateVMContainer(hypervisorType vc.HypervisorType) error { + switch hypervisorType { + case "qemu": + fallthrough ++ case "stratovirt": ++ fallthrough + case "clh": + fallthrough + case "firecracker": +-- +2.25.1 + + diff --git a/runtime/series.conf b/runtime/series.conf index 37b1b5f..aea067c 100644 --- a/runtime/series.conf +++ b/runtime/series.conf @@ -61,3 +61,4 @@ 0061-kata-runtime-retry-inserting-of-CNI-interface.patch 0062-kata-runtime-support-using-CNI-plugin-to-insert-muti.patch 0063-kata-runtime-fix-get-sandbox-cpu-resources-problem.patch +0064-runtime-add-support-for-stratovirt-of-kata-check-cli.patch -- Gitee From aa56e1c8d278ccdd1e301447202d0cf2d398aaa5 Mon Sep 17 00:00:00 2001 From: Ming Yang Date: Thu, 7 Jan 2021 19:34:55 +0800 Subject: [PATCH 2/2] runtime: fixup that the getPids function returns pid 0 Use pidfile to record the real pid of stratovirt, getPids then read the content of pidfile to get pid value. Signed-off-by: LiangZhang --- kata-containers.spec | 8 +- ...at-the-getPids-function-returns-pid-.patch | 82 +++++++++++++++++++ runtime/series.conf | 1 + 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 runtime/patches/0065-runtime-fixup-that-the-getPids-function-returns-pid-.patch diff --git a/kata-containers.spec b/kata-containers.spec index 4c96926..c77a613 100644 --- a/kata-containers.spec +++ b/kata-containers.spec @@ -2,7 +2,7 @@ %global debug_package %{nil} %define VERSION v1.11.1 -%define RELEASE 8 +%define RELEASE 9 Name: kata-containers Version: %{VERSION} @@ -90,6 +90,12 @@ install -p -m 640 -D ./runtime/cli/config/configuration-qemu.toml %{buildroot}/u %changelog +* Thu Jan 7 2021 LiangZhang - 1.11.1-8 - Type:feature - ID:NA diff --git a/runtime/patches/0065-runtime-fixup-that-the-getPids-function-returns-pid-.patch b/runtime/patches/0065-runtime-fixup-that-the-getPids-function-returns-pid-.patch new file mode 100644 index 0000000..08f22e5 --- /dev/null +++ b/runtime/patches/0065-runtime-fixup-that-the-getPids-function-returns-pid-.patch @@ -0,0 +1,82 @@ +From fde681b4fa01dd6a88824794fceb9b6733b6773d Mon Sep 17 00:00:00 2001 +From: root +Date: Thu, 7 Jan 2021 11:49:53 +0800 +Subject: [PATCH] runtime: fixup that the getPids function returns pid 0 + +Use pidfile to record the real pid of stratovirt, getPids then read the content of pidfile to get pid value. + +Signed-off-by: LiangZhang +--- + runtime/virtcontainers/stratovirt.go | 30 ++++++++++++++++++++++++++-- + 1 file changed, 28 insertions(+), 2 deletions(-) + +diff --git a/runtime/virtcontainers/stratovirt.go b/runtime/virtcontainers/stratovirt.go +index 020135e..e2fdd34 100644 +--- a/runtime/virtcontainers/stratovirt.go ++++ b/runtime/virtcontainers/stratovirt.go +@@ -3,6 +3,7 @@ package virtcontainers + import ( + "context" + "fmt" ++ "io/ioutil" + "os" + "os/exec" + "path/filepath" +@@ -148,6 +149,7 @@ func (s *stratovirt) startSandbox(timeout int) error { + params = append(params, "-smp", fmt.Sprintf("%d", s.config.NumVCPUs)) + params = append(params, "-m", fmt.Sprintf("%d", uint64(s.config.MemorySize)*1024*1024)) + params = append(params, "-chardev", fmt.Sprintf("id=charconsole0,path=%s", s.consolePath)) ++ params = append(params, "-pidfile", filepath.Join(s.store.RunVMStoragePath(), s.id, "pid")) + + // add devices to cmdline + for _, d := range s.devices { +@@ -587,7 +589,26 @@ func (s *stratovirt) cleanup() error { + } + + func (s *stratovirt) getPids() []int { +- return []int{s.pid} ++ var pids []int ++ if s.pid != 0 { ++ pids = append(pids, s.pid) ++ } else { ++ pid, err := ioutil.ReadFile(filepath.Join(s.store.RunVMStoragePath(), s.id, "pid")) ++ if err != nil { ++ s.Logger().WithError(err).Error("Read pid file failed.") ++ return []int{0} ++ } ++ ++ p, err := strconv.Atoi(strings.Trim(string(pid), "\n\t ")) ++ if err != nil { ++ s.Logger().WithError(err).Error("Get pid from pid file failed.") ++ return []int{0} ++ } ++ ++ pids = append(pids, p) ++ } ++ ++ return pids + } + + func (s *stratovirt) fromGrpc(ctx context.Context, hypervisorConfig *HypervisorConfig, j []byte) error { +@@ -611,12 +632,17 @@ func (s *stratovirt) generateSocket(id string, useVsock bool) (interface{}, erro + } + + func (s *stratovirt) save() (p persistapi.HypervisorState) { +- p.Pid = s.pid ++ pids := s.getPids() ++ p.Pid = pids[0] + p.Type = string(StratovirtHypervisor) + return + } + + func (s *stratovirt) load(p persistapi.HypervisorState) { + s.pid = p.Pid ++ if sandbox, err := globalSandboxList.lookupSandbox(s.id); err == nil { ++ s.sandbox = sandbox ++ } ++ + return + } +-- +2.27.0 + diff --git a/runtime/series.conf b/runtime/series.conf index aea067c..462da99 100644 --- a/runtime/series.conf +++ b/runtime/series.conf @@ -62,3 +62,4 @@ 0062-kata-runtime-support-using-CNI-plugin-to-insert-muti.patch 0063-kata-runtime-fix-get-sandbox-cpu-resources-problem.patch 0064-runtime-add-support-for-stratovirt-of-kata-check-cli.patch +0065-runtime-fixup-that-the-getPids-function-returns-pid-.patch -- Gitee