diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-01-12 15:34:38 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-01-14 12:27:33 +0000 |
commit | 5599b64e727ccfa0e2ce992689846c59bb51e4ad (patch) | |
tree | 63adffa3c61a79c57414c2261715cb0dd307dca0 | |
parent | 9c5a42eb1fcff8b99cc99ce307f51567efec9b61 (diff) | |
download | podman-5599b64e727ccfa0e2ce992689846c59bb51e4ad.tar.gz podman-5599b64e727ccfa0e2ce992689846c59bb51e4ad.tar.bz2 podman-5599b64e727ccfa0e2ce992689846c59bb51e4ad.zip |
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
-rw-r--r-- | libpod/container.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/libpod/container.go b/libpod/container.go index dfd77938d..a34394792 100644 --- a/libpod/container.go +++ b/libpod/container.go @@ -72,6 +72,11 @@ type Container struct { 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 lock storage.Locker runtime *Runtime @@ -1266,3 +1271,38 @@ func (c *Container) copyHostFileToRundir(sourcePath string) (string, error) { func (c *Container) StopTimeout() uint { 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() +} |