mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Remove main package dependency on criurpc
Commit 7f64fb47 made the main package, and runc/libcontainer's CriuOpts
depend on criu/rpc. This is not good; among the other things, it makes
it complicated to make c/r optional.
Let's switch CriuOpts.ManageCgroupsMode to a string (yes, it's an APIt
breaking change) and move the cgroup mode string parsing to
libcontainer.
While at it, let's better document ManageCgroupsMode.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
+62
-44
@@ -295,6 +295,11 @@ func (c *Container) Checkpoint(criuOpts *CriuOpts) error {
|
||||
return errors.New("invalid directory to save checkpoint")
|
||||
}
|
||||
|
||||
cgMode, err := criuCgMode(criuOpts.ManageCgroupsMode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Since a container can be C/R'ed multiple times,
|
||||
// the checkpoint directory may already exist.
|
||||
if err := os.Mkdir(criuOpts.ImagesDirectory, 0o700); err != nil && !os.IsExist(err) {
|
||||
@@ -309,22 +314,23 @@ func (c *Container) Checkpoint(criuOpts *CriuOpts) error {
|
||||
defer imageDir.Close()
|
||||
|
||||
rpcOpts := criurpc.CriuOpts{
|
||||
ImagesDirFd: proto.Int32(int32(imageDir.Fd())),
|
||||
LogLevel: proto.Int32(4),
|
||||
LogFile: proto.String(logFile),
|
||||
Root: proto.String(c.config.Rootfs),
|
||||
ManageCgroups: proto.Bool(true),
|
||||
NotifyScripts: proto.Bool(true),
|
||||
Pid: proto.Int32(int32(c.initProcess.pid())),
|
||||
ShellJob: proto.Bool(criuOpts.ShellJob),
|
||||
LeaveRunning: proto.Bool(criuOpts.LeaveRunning),
|
||||
TcpEstablished: proto.Bool(criuOpts.TcpEstablished),
|
||||
ExtUnixSk: proto.Bool(criuOpts.ExternalUnixConnections),
|
||||
FileLocks: proto.Bool(criuOpts.FileLocks),
|
||||
EmptyNs: proto.Uint32(criuOpts.EmptyNs),
|
||||
OrphanPtsMaster: proto.Bool(true),
|
||||
AutoDedup: proto.Bool(criuOpts.AutoDedup),
|
||||
LazyPages: proto.Bool(criuOpts.LazyPages),
|
||||
ImagesDirFd: proto.Int32(int32(imageDir.Fd())),
|
||||
LogLevel: proto.Int32(4),
|
||||
LogFile: proto.String(logFile),
|
||||
Root: proto.String(c.config.Rootfs),
|
||||
ManageCgroups: proto.Bool(true), // Obsoleted by ManageCgroupsMode.
|
||||
ManageCgroupsMode: &cgMode,
|
||||
NotifyScripts: proto.Bool(true),
|
||||
Pid: proto.Int32(int32(c.initProcess.pid())),
|
||||
ShellJob: proto.Bool(criuOpts.ShellJob),
|
||||
LeaveRunning: proto.Bool(criuOpts.LeaveRunning),
|
||||
TcpEstablished: proto.Bool(criuOpts.TcpEstablished),
|
||||
ExtUnixSk: proto.Bool(criuOpts.ExternalUnixConnections),
|
||||
FileLocks: proto.Bool(criuOpts.FileLocks),
|
||||
EmptyNs: proto.Uint32(criuOpts.EmptyNs),
|
||||
OrphanPtsMaster: proto.Bool(true),
|
||||
AutoDedup: proto.Bool(criuOpts.AutoDedup),
|
||||
LazyPages: proto.Bool(criuOpts.LazyPages),
|
||||
}
|
||||
|
||||
// if criuOpts.WorkDirectory is not set, criu default is used.
|
||||
@@ -381,12 +387,6 @@ func (c *Container) Checkpoint(criuOpts *CriuOpts) error {
|
||||
rpcOpts.TrackMem = proto.Bool(true)
|
||||
}
|
||||
|
||||
// append optional manage cgroups mode
|
||||
if criuOpts.ManageCgroupsMode != 0 {
|
||||
mode := criuOpts.ManageCgroupsMode
|
||||
rpcOpts.ManageCgroupsMode = &mode
|
||||
}
|
||||
|
||||
var t criurpc.CriuReqType
|
||||
if criuOpts.PreDump {
|
||||
feat := criurpc.CriuFeatures{
|
||||
@@ -634,6 +634,12 @@ func (c *Container) Restore(process *Process, criuOpts *CriuOpts) error {
|
||||
if criuOpts.ImagesDirectory == "" {
|
||||
return errors.New("invalid directory to restore checkpoint")
|
||||
}
|
||||
|
||||
cgMode, err := criuCgMode(criuOpts.ManageCgroupsMode)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logDir := criuOpts.ImagesDirectory
|
||||
imageDir, err := os.Open(criuOpts.ImagesDirectory)
|
||||
if err != nil {
|
||||
@@ -663,22 +669,23 @@ func (c *Container) Restore(process *Process, criuOpts *CriuOpts) error {
|
||||
req := &criurpc.CriuReq{
|
||||
Type: &t,
|
||||
Opts: &criurpc.CriuOpts{
|
||||
ImagesDirFd: proto.Int32(int32(imageDir.Fd())),
|
||||
EvasiveDevices: proto.Bool(true),
|
||||
LogLevel: proto.Int32(4),
|
||||
LogFile: proto.String(logFile),
|
||||
RstSibling: proto.Bool(true),
|
||||
Root: proto.String(root),
|
||||
ManageCgroups: proto.Bool(true),
|
||||
NotifyScripts: proto.Bool(true),
|
||||
ShellJob: proto.Bool(criuOpts.ShellJob),
|
||||
ExtUnixSk: proto.Bool(criuOpts.ExternalUnixConnections),
|
||||
TcpEstablished: proto.Bool(criuOpts.TcpEstablished),
|
||||
FileLocks: proto.Bool(criuOpts.FileLocks),
|
||||
EmptyNs: proto.Uint32(criuOpts.EmptyNs),
|
||||
OrphanPtsMaster: proto.Bool(true),
|
||||
AutoDedup: proto.Bool(criuOpts.AutoDedup),
|
||||
LazyPages: proto.Bool(criuOpts.LazyPages),
|
||||
ImagesDirFd: proto.Int32(int32(imageDir.Fd())),
|
||||
EvasiveDevices: proto.Bool(true),
|
||||
LogLevel: proto.Int32(4),
|
||||
LogFile: proto.String(logFile),
|
||||
RstSibling: proto.Bool(true),
|
||||
Root: proto.String(root),
|
||||
ManageCgroups: proto.Bool(true), // Obsoleted by ManageCgroupsMode.
|
||||
ManageCgroupsMode: &cgMode,
|
||||
NotifyScripts: proto.Bool(true),
|
||||
ShellJob: proto.Bool(criuOpts.ShellJob),
|
||||
ExtUnixSk: proto.Bool(criuOpts.ExternalUnixConnections),
|
||||
TcpEstablished: proto.Bool(criuOpts.TcpEstablished),
|
||||
FileLocks: proto.Bool(criuOpts.FileLocks),
|
||||
EmptyNs: proto.Uint32(criuOpts.EmptyNs),
|
||||
OrphanPtsMaster: proto.Bool(true),
|
||||
AutoDedup: proto.Bool(criuOpts.AutoDedup),
|
||||
LazyPages: proto.Bool(criuOpts.LazyPages),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -757,12 +764,6 @@ func (c *Container) Restore(process *Process, criuOpts *CriuOpts) error {
|
||||
c.restoreNetwork(req, criuOpts)
|
||||
}
|
||||
|
||||
// append optional manage cgroups mode
|
||||
if criuOpts.ManageCgroupsMode != 0 {
|
||||
mode := criuOpts.ManageCgroupsMode
|
||||
req.Opts.ManageCgroupsMode = &mode
|
||||
}
|
||||
|
||||
var (
|
||||
fds []string
|
||||
fdJSON []byte
|
||||
@@ -1184,3 +1185,20 @@ func (c *Container) criuNotifications(resp *criurpc.CriuResp, process *Process,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func criuCgMode(mode string) (criurpc.CriuCgMode, error) {
|
||||
switch mode {
|
||||
case "":
|
||||
return criurpc.CriuCgMode_DEFAULT, nil
|
||||
case "soft":
|
||||
return criurpc.CriuCgMode_SOFT, nil
|
||||
case "full":
|
||||
return criurpc.CriuCgMode_FULL, nil
|
||||
case "strict":
|
||||
return criurpc.CriuCgMode_STRICT, nil
|
||||
case "ignore":
|
||||
return criurpc.CriuCgMode_IGNORE, nil
|
||||
default:
|
||||
return 0, errors.New("invalid manage-cgroups-mode value")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user