mirror of
https://github.com/containers/podman.git
synced 2025-07-15 03:02:52 +08:00
Use a struct to pass options to Checkpoint()
For upcoming changes to the Checkpoint() functions this commit switches checkpoint options from a boolean to a struct, so that additional options can be passed easily to Checkpoint() without changing the function parameters all the time. Signed-off-by: Adrian Reber <areber@redhat.com>
This commit is contained in:

committed by
Adrian Reber

parent
ea928f2de6
commit
ff47a4c2d5
@ -50,7 +50,9 @@ func checkpointCmd(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
defer runtime.Shutdown(false)
|
defer runtime.Shutdown(false)
|
||||||
|
|
||||||
keep := c.Bool("keep")
|
options := libpod.ContainerCheckpointOptions{
|
||||||
|
Keep: c.Bool("keep"),
|
||||||
|
}
|
||||||
|
|
||||||
if err := checkAllAndLatest(c); err != nil {
|
if err := checkAllAndLatest(c); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -59,7 +61,7 @@ func checkpointCmd(c *cli.Context) error {
|
|||||||
containers, lastError := getAllOrLatestContainers(c, runtime, libpod.ContainerStateRunning, "running")
|
containers, lastError := getAllOrLatestContainers(c, runtime, libpod.ContainerStateRunning, "running")
|
||||||
|
|
||||||
for _, ctr := range containers {
|
for _, ctr := range containers {
|
||||||
if err = ctr.Checkpoint(context.TODO(), keep); err != nil {
|
if err = ctr.Checkpoint(context.TODO(), options); err != nil {
|
||||||
if lastError != nil {
|
if lastError != nil {
|
||||||
fmt.Fprintln(os.Stderr, lastError)
|
fmt.Fprintln(os.Stderr, lastError)
|
||||||
}
|
}
|
||||||
|
@ -830,8 +830,14 @@ func (c *Container) Refresh(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContainerCheckpointOptions is a struct used to pass the parameters
|
||||||
|
// for checkpointing to corresponding functions
|
||||||
|
type ContainerCheckpointOptions struct {
|
||||||
|
Keep bool
|
||||||
|
}
|
||||||
|
|
||||||
// Checkpoint checkpoints a container
|
// Checkpoint checkpoints a container
|
||||||
func (c *Container) Checkpoint(ctx context.Context, keep bool) error {
|
func (c *Container) Checkpoint(ctx context.Context, options ContainerCheckpointOptions) error {
|
||||||
logrus.Debugf("Trying to checkpoint container %s", c)
|
logrus.Debugf("Trying to checkpoint container %s", c)
|
||||||
if !c.batched {
|
if !c.batched {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
@ -842,7 +848,7 @@ func (c *Container) Checkpoint(ctx context.Context, keep bool) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.checkpoint(ctx, keep)
|
return c.checkpoint(ctx, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore restores a container
|
// Restore restores a container
|
||||||
|
@ -431,7 +431,7 @@ func (c *Container) addNamespaceContainer(g *generate.Generator, ns LinuxNS, ctr
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) checkpoint(ctx context.Context, keep bool) (err error) {
|
func (c *Container) checkpoint(ctx context.Context, options ContainerCheckpointOptions) (err error) {
|
||||||
|
|
||||||
if !criu.CheckForCriu() {
|
if !criu.CheckForCriu() {
|
||||||
return errors.Errorf("checkpointing a container requires at least CRIU %d", criu.MinCriuVersion)
|
return errors.Errorf("checkpointing a container requires at least CRIU %d", criu.MinCriuVersion)
|
||||||
@ -464,7 +464,7 @@ func (c *Container) checkpoint(ctx context.Context, keep bool) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !keep {
|
if !options.Keep {
|
||||||
// Remove log file
|
// Remove log file
|
||||||
os.Remove(filepath.Join(c.bundlePath(), "dump.log"))
|
os.Remove(filepath.Join(c.bundlePath(), "dump.log"))
|
||||||
// Remove statistic file
|
// Remove statistic file
|
||||||
|
Reference in New Issue
Block a user