mirror of https://github.com/containers/podman.git
Add initial function batching API
Disabling locking/syncing in a batched operation not yet implemented Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #222 Approved by: rhatdan
This commit is contained in:
parent
9c5a42eb1f
commit
5599b64e72
|
@ -72,6 +72,11 @@ type Container struct {
|
||||||
|
|
||||||
state *containerRuntimeInfo
|
state *containerRuntimeInfo
|
||||||
|
|
||||||
|
// Locked indicates that a container has been locked as part of a
|
||||||
|
// Batch() operation
|
||||||
|
// Functions called on a locked container will not lock or sync
|
||||||
|
locked bool
|
||||||
|
|
||||||
valid bool
|
valid bool
|
||||||
lock storage.Locker
|
lock storage.Locker
|
||||||
runtime *Runtime
|
runtime *Runtime
|
||||||
|
@ -1266,3 +1271,38 @@ func (c *Container) copyHostFileToRundir(sourcePath string) (string, error) {
|
||||||
func (c *Container) StopTimeout() uint {
|
func (c *Container) StopTimeout() uint {
|
||||||
return c.config.StopTimeout
|
return c.config.StopTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Batch starts a batch operation on the given container
|
||||||
|
// All commands in the passed function will execute under the same lock and
|
||||||
|
// without syncronyzing state after each operation
|
||||||
|
// This will result in substantial performance benefits when running numerous
|
||||||
|
// commands on the same container
|
||||||
|
// Note that the container passed into the Batch function cannot be removed
|
||||||
|
// during batched operations. runtime.RemoveContainer can only be called outside
|
||||||
|
// of Batch
|
||||||
|
// Any error returned by the given batch function will be returned unmodified by
|
||||||
|
// Batch
|
||||||
|
func (c *Container) Batch(batchFunc func(*Container) error) error {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
|
if err := c.syncContainer(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
newCtr := new(Container)
|
||||||
|
newCtr.config = c.config
|
||||||
|
newCtr.state = c.state
|
||||||
|
newCtr.runtime = c.runtime
|
||||||
|
newCtr.valid = true
|
||||||
|
|
||||||
|
newCtr.locked = true
|
||||||
|
|
||||||
|
if err := batchFunc(newCtr); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
newCtr.locked = false
|
||||||
|
|
||||||
|
return c.save()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue