diff --git a/kata-containers.spec b/kata-containers.spec index 68aaac6010c1948b714745caf876868e6def428a..a3ed0eb3ffe69b35c38a12fddbc15657ca2a3ec0 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 +* Fri Jan 8 2021 LiangZhang - 1.11.1-9 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fixup that the getPids functions returns pid + * 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 0000000000000000000000000000000000000000..661608b220e9a3d294eb2cf08de1daaa5dbcfe7a --- /dev/null +++ b/runtime/patches/0065-runtime-fixup-that-the-getPids-function-returns-pid-.patch @@ -0,0 +1,83 @@ +From 899164391d2ca57f84716a5b2f34500883bc3690 Mon Sep 17 00:00:00 2001 +From: LiangZhang +Date: Mon, 11 Jan 2021 11:03:39 +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 +--- + virtcontainers/stratovirt.go | 31 ++++++++++++++++++++++++++-- + 1 file changed, 29 insertions(+), 2 deletions(-) + +diff --git a/virtcontainers/stratovirt.go b/virtcontainers/stratovirt.go +index 020135e..a8151de 100644 +--- a/virtcontainers/stratovirt.go ++++ b/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,27 @@ 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) ++ s.pid = p ++ } ++ ++ return pids + } + + func (s *stratovirt) fromGrpc(ctx context.Context, hypervisorConfig *HypervisorConfig, j []byte) error { +@@ -611,12 +633,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 aea067c172a67dfce3eefd3a89e674bf871504c2..462da994e348cbdc0d10b6ed8128e6066507c54a 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