mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-16 00:16:52 +00:00
virtcontainers: add method to get hypervisor PID
hypervisor PID can be used to move the whole process and its threads into a new cgroup. Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
136b188fd4
commit
a1c85902f6
@ -702,3 +702,7 @@ func (fc *firecracker) getThreadIDs() (*threadIDs, error) {
|
||||
func (fc *firecracker) cleanup() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fc *firecracker) pid() int {
|
||||
return fc.info.PID
|
||||
}
|
||||
|
@ -609,4 +609,5 @@ type hypervisor interface {
|
||||
hypervisorConfig() HypervisorConfig
|
||||
getThreadIDs() (*threadIDs, error)
|
||||
cleanup() error
|
||||
pid() int
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
)
|
||||
|
||||
type mockHypervisor struct {
|
||||
mockPid int
|
||||
}
|
||||
|
||||
func (m *mockHypervisor) capabilities() types.Capabilities {
|
||||
@ -100,3 +101,7 @@ func (m *mockHypervisor) getThreadIDs() (*threadIDs, error) {
|
||||
func (m *mockHypervisor) cleanup() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockHypervisor) pid() int {
|
||||
return m.mockPid
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ package virtcontainers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -500,6 +501,8 @@ func (q *qemu) createSandbox(ctx context.Context, id string, hypervisorConfig *H
|
||||
return err
|
||||
}
|
||||
|
||||
pidFile := q.pidFile()
|
||||
|
||||
qemuConfig := govmmQemu.Config{
|
||||
Name: fmt.Sprintf("sandbox-%s", q.id),
|
||||
UUID: q.state.UUID,
|
||||
@ -518,6 +521,7 @@ func (q *qemu) createSandbox(ctx context.Context, id string, hypervisorConfig *H
|
||||
VGA: "none",
|
||||
GlobalParam: "kvm-pit.lost_tick_policy=discard",
|
||||
Bios: firmwarePath,
|
||||
PidFile: pidFile,
|
||||
}
|
||||
|
||||
if ioThread != nil {
|
||||
@ -1567,3 +1571,23 @@ func (q *qemu) cleanup() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *qemu) pidFile() string {
|
||||
return filepath.Join(store.RunVMStoragePath, q.id, "pid")
|
||||
}
|
||||
|
||||
func (q *qemu) pid() int {
|
||||
data, err := ioutil.ReadFile(q.pidFile())
|
||||
if err != nil {
|
||||
q.Logger().WithError(err).Error("Could not read qemu pid file")
|
||||
return 0
|
||||
}
|
||||
|
||||
pid, err := strconv.Atoi(strings.Trim(string(data), "\n\t "))
|
||||
if err != nil {
|
||||
q.Logger().WithError(err).Error("Could not convert string to int")
|
||||
return 0
|
||||
}
|
||||
|
||||
return pid
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user