aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.cirrus.yml2
-rwxr-xr-xAPI.md4
-rw-r--r--CONTRIBUTING.md28
-rw-r--r--Makefile9
-rw-r--r--cmd/podman/common.go9
-rw-r--r--cmd/podman/create.go10
-rw-r--r--cmd/podman/varlink/io.podman.varlink2
-rw-r--r--docs/libpod.conf.5.md3
-rw-r--r--docs/podman-create.1.md8
-rw-r--r--docs/podman-run.1.md8
-rwxr-xr-xhack/install_catatonit.sh15
-rw-r--r--libpod.conf3
-rw-r--r--libpod/boltdb_state_internal.go14
-rw-r--r--libpod/common_test.go46
-rw-r--r--libpod/container.go5
-rw-r--r--libpod/container_easyjson.go12
-rw-r--r--libpod/container_graph_test.go160
-rw-r--r--libpod/container_internal.go12
-rw-r--r--libpod/lock/in_memory_locks.go91
-rw-r--r--libpod/lock/lock.go58
-rw-r--r--libpod/lock/shm/shm_lock.c452
-rw-r--r--libpod/lock/shm/shm_lock.go216
-rw-r--r--libpod/lock/shm/shm_lock.h46
-rw-r--r--libpod/lock/shm/shm_lock_test.go278
-rw-r--r--libpod/lock/shm_lock_manager_linux.go94
-rw-r--r--libpod/lock/shm_lock_manager_unsupported.go29
-rw-r--r--libpod/pod.go7
-rw-r--r--libpod/pod_easyjson.go12
-rw-r--r--libpod/pod_internal.go21
-rw-r--r--libpod/runtime.go95
-rw-r--r--libpod/runtime_ctr.go32
-rw-r--r--libpod/runtime_pod_linux.go15
-rw-r--r--libpod/runtime_volume_linux.go9
-rw-r--r--libpod/state_test.go908
-rw-r--r--libpod/volume.go10
-rw-r--r--pkg/spec/createconfig.go31
-rw-r--r--test/e2e/run_test.go12
-rw-r--r--vendor.conf10
-rw-r--r--vendor/github.com/containers/buildah/config.go3
-rw-r--r--vendor/github.com/containers/buildah/image.go4
-rw-r--r--vendor/github.com/containers/buildah/imagebuildah/build.go7
-rw-r--r--vendor/github.com/containers/buildah/imagebuildah/chroot_symlink.go5
-rw-r--r--vendor/github.com/containers/buildah/pkg/blobcache/blobcache.go8
-rw-r--r--vendor/github.com/containers/buildah/pkg/cli/common.go4
-rw-r--r--vendor/github.com/containers/buildah/run.go16
-rw-r--r--vendor/github.com/containers/buildah/unshare/unshare.c3
-rw-r--r--vendor/github.com/containers/buildah/util/util.go50
-rw-r--r--vendor/github.com/containers/buildah/vendor.conf14
-rw-r--r--vendor/github.com/containers/image/copy/copy.go145
-rw-r--r--vendor/github.com/containers/image/directory/directory_dest.go5
-rw-r--r--vendor/github.com/containers/image/directory/directory_src.go5
-rw-r--r--vendor/github.com/containers/image/docker/docker_client.go35
-rw-r--r--vendor/github.com/containers/image/docker/docker_image_dest.go5
-rw-r--r--vendor/github.com/containers/image/docker/docker_image_src.go5
-rw-r--r--vendor/github.com/containers/image/docker/tarfile/dest.go5
-rw-r--r--vendor/github.com/containers/image/docker/tarfile/src.go5
-rw-r--r--vendor/github.com/containers/image/oci/archive/oci_dest.go5
-rw-r--r--vendor/github.com/containers/image/oci/archive/oci_src.go5
-rw-r--r--vendor/github.com/containers/image/oci/layout/oci_dest.go5
-rw-r--r--vendor/github.com/containers/image/oci/layout/oci_src.go5
-rw-r--r--vendor/github.com/containers/image/openshift/openshift.go10
-rw-r--r--vendor/github.com/containers/image/ostree/ostree_dest.go9
-rw-r--r--vendor/github.com/containers/image/ostree/ostree_src.go9
-rw-r--r--vendor/github.com/containers/image/pkg/blobinfocache/default.go2
-rw-r--r--vendor/github.com/containers/image/pkg/compression/compression.go4
-rw-r--r--vendor/github.com/containers/image/pkg/sysregistriesv2/system_registries_v2.go35
-rw-r--r--vendor/github.com/containers/image/storage/storage_image.go28
-rw-r--r--vendor/github.com/containers/image/tarball/tarball_src.go10
-rw-r--r--vendor/github.com/containers/image/types/types.go4
-rw-r--r--vendor/github.com/containers/image/vendor.conf10
-rw-r--r--vendor/github.com/opencontainers/go-digest/LICENSE (renamed from vendor/github.com/opencontainers/go-digest/LICENSE.code)0
-rw-r--r--vendor/github.com/opencontainers/go-digest/README.md2
-rw-r--r--vendor/github.com/opencontainers/go-digest/algorithm.go40
-rw-r--r--vendor/github.com/opencontainers/go-digest/digest.go42
-rw-r--r--vendor/golang.org/x/sync/LICENSE27
-rw-r--r--vendor/golang.org/x/sync/PATENTS22
-rw-r--r--vendor/golang.org/x/sync/README.md18
-rw-r--r--vendor/golang.org/x/sync/semaphore/semaphore.go127
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/README.md11
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/format.go84
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/pb.go193
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/pb_appengine.go2
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/pb_nix.go8
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/pb_solaris.go6
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/pb_win.go4
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/pb_x.go118
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/pool.go62
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/pool_win.go16
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/pool_x.go13
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/runecount.go2
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/termios_nix.go7
-rw-r--r--vendor/gopkg.in/cheggaaa/pb.v1/termios_sysv.go13
92 files changed, 3087 insertions, 971 deletions
diff --git a/.cirrus.yml b/.cirrus.yml
index d1029d554..199c2a533 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -115,7 +115,7 @@ build_each_commit_task:
matrix:
image_name: "fedora-29-libpod-9afa57a9"
- timeout_in: 20m
+ timeout_in: 30m
script:
- $SCRIPT_BASE/setup_environment.sh
diff --git a/API.md b/API.md
index 51787496c..3722c2864 100755
--- a/API.md
+++ b/API.md
@@ -1169,6 +1169,10 @@ image [string](https://godoc.org/builtin#string)
image_id [string](https://godoc.org/builtin#string)
+init [bool](https://godoc.org/builtin#bool)
+
+init_path [string](https://godoc.org/builtin#string)
+
builtin_imgvolumes [[]string](#[]string)
id_mappings [IDMappingOptions](#IDMappingOptions)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 32ed94ad4..26e5473b2 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -226,3 +226,31 @@ and
tracking system.
[owners]: https://github.com/kubernetes/community/blob/master/contributors/guide/owners.md#owners
+
+
+### Bot Interactions
+
+The primary human-interface is through comments in pull-requests. Some of these are outlined
+below, along with their meaning and intended usage. Some of them require the comment
+author hold special privileges on the github repository. Others can be used by anyone.
+
+* ``/close``: Closes an issue or PR.
+
+* ``/approve``: Mark a PR as appropriate to the project, and as close to meeting
+ met all the contribution criteria above. Adds the *approved* label, marking
+ it as ready for review and possible future merging.
+
+* ``/lgtm``: A literal "Stamp of approval", signaling okay-to-merge. This causes
+ the bot to ad the *lgtm* label, then attempt a merge. In other words - Never,
+ ever, ever comment ``/lgtm``, unless a PR has actually, really, been fully
+ reviewed. The bot isn't too smart about these things, and could merge
+ unintentionally. Instead, just write ``LGTM``, or
+ spell it out.
+
+* ``[skip ci]``: Within the HEAD commit will cause Cirrus CI to ***NOT*** execute
+ tests on the PR. This is useful in basically two cases: 1) You're still working
+ and don't want to waste resources. 2) You haven't modified any code that would
+ be exercised by the tests. For example, documentation updates (outside of code).
+
+[The complete list may be found on the command-help page.](https://prow.k8s.io/command-help)
+However, not all commands are implemented for this repository. If in doubt, ask a maintainer.
diff --git a/Makefile b/Makefile
index c423d82f2..32f21227f 100644
--- a/Makefile
+++ b/Makefile
@@ -154,10 +154,10 @@ dbuild: libpodimage
${CONTAINER_RUNTIME} run --name=${LIBPOD_INSTANCE} --privileged -v ${PWD}:/go/src/${PROJECT} --rm ${LIBPOD_IMAGE} make all
test: libpodimage
- ${CONTAINER_RUNTIME} run -e STORAGE_OPTIONS="--storage-driver=vfs" -e TESTFLAGS -e CGROUP_MANAGER=cgroupfs -e TRAVIS -t --privileged --rm -v ${CURDIR}:/go/src/${PROJECT} ${LIBPOD_IMAGE} make clean all localunit localintegration
+ ${CONTAINER_RUNTIME} run -e STORAGE_OPTIONS="--storage-driver=vfs" -e TESTFLAGS -e CGROUP_MANAGER=cgroupfs -e TRAVIS -t --privileged --rm -v ${CURDIR}:/go/src/${PROJECT} ${LIBPOD_IMAGE} make clean all localunit install.catatonit localintegration
integration: libpodimage
- ${CONTAINER_RUNTIME} run -e STORAGE_OPTIONS="--storage-driver=vfs" -e TESTFLAGS -e CGROUP_MANAGER=cgroupfs -e TRAVIS -t --privileged --rm -v ${CURDIR}:/go/src/${PROJECT} ${LIBPOD_IMAGE} make clean all localintegration
+ ${CONTAINER_RUNTIME} run -e STORAGE_OPTIONS="--storage-driver=vfs" -e TESTFLAGS -e CGROUP_MANAGER=cgroupfs -e TRAVIS -t --privileged --rm -v ${CURDIR}:/go/src/${PROJECT} ${LIBPOD_IMAGE} make clean all install.catatonit localintegration
integration.fedora:
DIST=Fedora sh .papr_prepare.sh
@@ -201,7 +201,10 @@ vagrant-check:
binaries: varlink_generate easyjson_generate podman
-test-binaries: test/bin2img/bin2img test/copyimg/copyimg test/checkseccomp/checkseccomp test/goecho/goecho
+install.catatonit:
+ ./hack/install_catatonit.sh
+
+test-binaries: test/bin2img/bin2img test/copyimg/copyimg test/checkseccomp/checkseccomp test/goecho/goecho install.catatonit
MANPAGES_MD ?= $(wildcard docs/*.md pkg/*/docs/*.md)
MANPAGES ?= $(MANPAGES_MD:%.md=%)
diff --git a/cmd/podman/common.go b/cmd/podman/common.go
index 8404a29b8..0fc9a6acc 100644
--- a/cmd/podman/common.go
+++ b/cmd/podman/common.go
@@ -321,6 +321,15 @@ var createFlags = []cli.Flag{
Value: "bind",
},
cli.BoolFlag{
+ Name: "init",
+ Usage: "Run an init binary inside the container that forwards signals and reaps processes",
+ },
+ cli.StringFlag{
+ Name: "init-path",
+ // Do not use the Value field for setting the default value to determine user input (i.e., non-empty string)
+ Usage: fmt.Sprintf("Path to the container-init binary (default: %q)", libpod.DefaultInitPath),
+ },
+ cli.BoolFlag{
Name: "interactive, i",
Usage: "Keep STDIN open even if not attached",
},
diff --git a/cmd/podman/create.go b/cmd/podman/create.go
index dae429047..395a64b3b 100644
--- a/cmd/podman/create.go
+++ b/cmd/podman/create.go
@@ -809,6 +809,16 @@ func parseCreateOpts(ctx context.Context, c *cli.Context, runtime *libpod.Runtim
Syslog: c.GlobalBool("syslog"),
}
+ if c.Bool("init") {
+ initPath := c.String("init-path")
+ if initPath == "" {
+ initPath = runtime.GetConfig().InitPath
+ }
+ if err := config.AddContainerInitBinary(initPath); err != nil {
+ return nil, err
+ }
+ }
+
if config.Privileged {
config.LabelOpts = label.DisableSecOpt()
} else {
diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink
index c1b7c703a..4e8b69faf 100644
--- a/cmd/podman/varlink/io.podman.varlink
+++ b/cmd/podman/varlink/io.podman.varlink
@@ -211,6 +211,8 @@ type Create (
hostname: string,
image: string,
image_id: string,
+ init: bool,
+ init_path: string,
builtin_imgvolumes: []string,
id_mappings: IDMappingOptions,
image_volume_type: string,
diff --git a/docs/libpod.conf.5.md b/docs/libpod.conf.5.md
index d63baeb88..c02d247fb 100644
--- a/docs/libpod.conf.5.md
+++ b/docs/libpod.conf.5.md
@@ -24,6 +24,9 @@ libpod to manage containers.
**cgroup_manager**=""
Specify the CGroup Manager to use; valid values are "systemd" and "cgroupfs"
+**init_path**=""
+ Path to the container-init binary, which forwards signals and reaps processes within containers. Note that the container-init binary will only be used when the `--init` for podman-create and podman-run is set.
+
**hooks_dir**=["*path*", ...]
Each `*.json` file in the path configures a hook for Podman containers. For more details on the syntax of the JSON files and the semantics of hook injection, see `oci-hooks(5)`. Podman and libpod currently support both the 1.0.0 and 0.1.0 hook schemas, although the 0.1.0 schema is deprecated.
diff --git a/docs/podman-create.1.md b/docs/podman-create.1.md
index 97d6e77b1..3a75a4b00 100644
--- a/docs/podman-create.1.md
+++ b/docs/podman-create.1.md
@@ -276,6 +276,14 @@ tmpfs: The volume is mounted onto the container as a tmpfs, which allows the use
content that disappears when the container is stopped.
ignore: All volumes are just ignored and no action is taken.
+**--init**
+
+Run an init inside the container that forwards signals and reaps processes.
+
+**--init-path**=""
+
+Path to the container-init binary.
+
**-i**, **--interactive**=*true*|*false*
Keep STDIN open even if not attached. The default is *false*.
diff --git a/docs/podman-run.1.md b/docs/podman-run.1.md
index c0a466a9c..971b8829a 100644
--- a/docs/podman-run.1.md
+++ b/docs/podman-run.1.md
@@ -285,6 +285,14 @@ the container for the volumes.
content that disappears when the container is stopped.
- `ignore`: All volumes are just ignored and no action is taken.
+**--init**
+
+Run an init inside the container that forwards signals and reaps processes.
+
+**--init-path**=""
+
+Path to the container-init binary.
+
**-i**, **--interactive**=*true*|*false*
Keep STDIN open even if not attached. The default is *false*.
diff --git a/hack/install_catatonit.sh b/hack/install_catatonit.sh
new file mode 100755
index 000000000..e5532a200
--- /dev/null
+++ b/hack/install_catatonit.sh
@@ -0,0 +1,15 @@
+#!/bin/bash -e
+BASE_PATH="/usr/libexec/podman"
+CATATONIT_PATH="${BASE_PATH}/catatonit"
+CATATONIT_VERSION="v0.1.3"
+
+if [ -f $CATATONIT_PATH ]; then
+ echo "skipping ... catatonit is already installed"
+else
+ echo "downloading catatonit to $CATATONIT_PATH"
+ curl -o catatonit -L https://github.com/openSUSE/catatonit/releases/download/$CATATONIT_VERSION/catatonit.x86_64
+ chmod +x catatonit
+ install ${SELINUXOPT} -d -m 755 $BASE_PATH
+ install ${SELINUXOPT} -m 755 catatonit $CATATONIT_PATH
+ rm catatonit
+fi
diff --git a/libpod.conf b/libpod.conf
index d7469af68..cfdf83775 100644
--- a/libpod.conf
+++ b/libpod.conf
@@ -35,6 +35,9 @@ conmon_env_vars = [
# CGroup Manager - valid values are "systemd" and "cgroupfs"
cgroup_manager = "systemd"
+# Container init binary
+#init_path = "/usr/libexec/podman/catatonit"
+
# Directory for persistent libpod files (database, etc)
# By default, this will be configured relative to where containers/storage
# stores containers
diff --git a/libpod/boltdb_state_internal.go b/libpod/boltdb_state_internal.go
index 06f8dcb24..29a7184c9 100644
--- a/libpod/boltdb_state_internal.go
+++ b/libpod/boltdb_state_internal.go
@@ -3,7 +3,6 @@ package libpod
import (
"bytes"
"encoding/json"
- "path/filepath"
"runtime"
"strings"
@@ -288,10 +287,9 @@ func (s *BoltState) getContainerFromDB(id []byte, ctr *Container, ctrsBkt *bolt.
}
// Get the lock
- lockPath := filepath.Join(s.runtime.lockDir, string(id))
- lock, err := storage.GetLockfile(lockPath)
+ lock, err := s.runtime.lockManager.RetrieveLock(ctr.config.LockID)
if err != nil {
- return errors.Wrapf(err, "error retrieving lockfile for container %s", string(id))
+ return errors.Wrapf(err, "error retrieving lock for container %s", string(id))
}
ctr.lock = lock
@@ -324,10 +322,9 @@ func (s *BoltState) getPodFromDB(id []byte, pod *Pod, podBkt *bolt.Bucket) error
}
// Get the lock
- lockPath := filepath.Join(s.runtime.lockDir, string(id))
- lock, err := storage.GetLockfile(lockPath)
+ lock, err := s.runtime.lockManager.RetrieveLock(pod.config.LockID)
if err != nil {
- return errors.Wrapf(err, "error retrieving lockfile for pod %s", string(id))
+ return errors.Wrapf(err, "error retrieving lock for pod %s", string(id))
}
pod.lock = lock
@@ -353,8 +350,7 @@ func (s *BoltState) getVolumeFromDB(name []byte, volume *Volume, volBkt *bolt.Bu
}
// Get the lock
- lockPath := filepath.Join(s.runtime.lockDir, string(name))
- lock, err := storage.GetLockfile(lockPath)
+ lock, err := s.runtime.lockManager.RetrieveLock(volume.config.LockID)
if err != nil {
return errors.Wrapf(err, "error retrieving lockfile for volume %s", string(name))
}
diff --git a/libpod/common_test.go b/libpod/common_test.go
index 6c7434fd2..882468a3a 100644
--- a/libpod/common_test.go
+++ b/libpod/common_test.go
@@ -3,20 +3,19 @@ package libpod
import (
"encoding/json"
"net"
- "path/filepath"
"reflect"
"strings"
"testing"
"time"
- "github.com/containers/storage"
+ "github.com/containers/libpod/libpod/lock"
"github.com/cri-o/ocicni/pkg/ocicni"
"github.com/opencontainers/runtime-tools/generate"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
-func getTestContainer(id, name, locksDir string) (*Container, error) {
+func getTestContainer(id, name string, manager lock.Manager) (*Container, error) {
ctr := &Container{
config: &Config{
ID: id,
@@ -90,18 +89,18 @@ func getTestContainer(id, name, locksDir string) (*Container, error) {
ctr.config.Labels["test"] = "testing"
- // Must make lockfile or container will error on being retrieved from DB
- lockPath := filepath.Join(locksDir, id)
- lock, err := storage.GetLockfile(lockPath)
+ // Allocate a lock for the container
+ lock, err := manager.AllocateLock()
if err != nil {
return nil, err
}
ctr.lock = lock
+ ctr.config.LockID = lock.ID()
return ctr, nil
}
-func getTestPod(id, name, locksDir string) (*Pod, error) {
+func getTestPod(id, name string, manager lock.Manager) (*Pod, error) {
pod := &Pod{
config: &PodConfig{
ID: id,
@@ -115,38 +114,39 @@ func getTestPod(id, name, locksDir string) (*Pod, error) {
valid: true,
}
- lockPath := filepath.Join(locksDir, id)
- lock, err := storage.GetLockfile(lockPath)
+ // Allocate a lock for the pod
+ lock, err := manager.AllocateLock()
if err != nil {
return nil, err
}
pod.lock = lock
+ pod.config.LockID = lock.ID()
return pod, nil
}
-func getTestCtrN(n, lockPath string) (*Container, error) {
- return getTestContainer(strings.Repeat(n, 32), "test"+n, lockPath)
+func getTestCtrN(n string, manager lock.Manager) (*Container, error) {
+ return getTestContainer(strings.Repeat(n, 32), "test"+n, manager)
}
-func getTestCtr1(lockPath string) (*Container, error) {
- return getTestCtrN("1", lockPath)
+func getTestCtr1(manager lock.Manager) (*Container, error) {
+ return getTestCtrN("1", manager)
}
-func getTestCtr2(lockPath string) (*Container, error) {
- return getTestCtrN("2", lockPath)
+func getTestCtr2(manager lock.Manager) (*Container, error) {
+ return getTestCtrN("2", manager)
}
-func getTestPodN(n, lockPath string) (*Pod, error) {
- return getTestPod(strings.Repeat(n, 32), "test"+n, lockPath)
+func getTestPodN(n string, manager lock.Manager) (*Pod, error) {
+ return getTestPod(strings.Repeat(n, 32), "test"+n, manager)
}
-func getTestPod1(lockPath string) (*Pod, error) {
- return getTestPodN("1", lockPath)
+func getTestPod1(manager lock.Manager) (*Pod, error) {
+ return getTestPodN("1", manager)
}
-func getTestPod2(lockPath string) (*Pod, error) {
- return getTestPodN("2", lockPath)
+func getTestPod2(manager lock.Manager) (*Pod, error) {
+ return getTestPodN("2", manager)
}
// This horrible hack tests if containers are equal in a way that should handle
@@ -174,6 +174,8 @@ func testContainersEqual(t *testing.T, a, b *Container, allowedEmpty bool) {
assert.Equal(t, a.valid, b.valid)
+ assert.Equal(t, a.lock.ID(), b.lock.ID())
+
aConfigJSON, err := json.Marshal(a.config)
assert.NoError(t, err)
err = json.Unmarshal(aConfigJSON, aConfig)
@@ -223,6 +225,8 @@ func testPodsEqual(t *testing.T, a, b *Pod, allowedEmpty bool) {
assert.Equal(t, a.valid, b.valid)
+ assert.Equal(t, a.lock.ID(), b.lock.ID())
+
assert.EqualValues(t, a.config, b.config)
if allowedEmpty {
diff --git a/libpod/container.go b/libpod/container.go
index b4190344a..4e5088b32 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -9,6 +9,7 @@ import (
"github.com/containernetworking/cni/pkg/types"
cnitypes "github.com/containernetworking/cni/pkg/types/current"
+ "github.com/containers/libpod/libpod/lock"
"github.com/containers/libpod/pkg/namespaces"
"github.com/containers/storage"
"github.com/cri-o/ocicni/pkg/ocicni"
@@ -122,7 +123,7 @@ type Container struct {
batched bool
valid bool
- lock storage.Locker
+ lock lock.Locker
runtime *Runtime
rootlessSlirpSyncR *os.File
@@ -211,6 +212,8 @@ type Config struct {
Pod string `json:"pod,omitempty"`
// Namespace the container is in
Namespace string `json:"namespace,omitempty"`
+ // ID of this container's lock
+ LockID uint32 `json:"lockID"`
// TODO consider breaking these subsections up into smaller structs
diff --git a/libpod/container_easyjson.go b/libpod/container_easyjson.go
index 299a645e1..ae0972cf6 100644
--- a/libpod/container_easyjson.go
+++ b/libpod/container_easyjson.go
@@ -1275,6 +1275,8 @@ func easyjson1dbef17bDecodeGithubComContainersLibpodLibpod2(in *jlexer.Lexer, ou
out.Pod = string(in.String())
case "namespace":
out.Namespace = string(in.String())
+ case "lockID":
+ out.LockID = uint32(in.Uint32())
case "idMappingsOptions":
easyjson1dbef17bDecodeGithubComContainersLibpodVendorGithubComContainersStorage(in, &out.IDMappings)
case "rootfsImageID":
@@ -1778,6 +1780,16 @@ func easyjson1dbef17bEncodeGithubComContainersLibpodLibpod2(out *jwriter.Writer,
}
out.String(string(in.Namespace))
}
+ {
+ const prefix string = ",\"lockID\":"
+ if first {
+ first = false
+ out.RawString(prefix[1:])
+ } else {
+ out.RawString(prefix)
+ }
+ out.Uint32(uint32(in.LockID))
+ }
if true {
const prefix string = ",\"idMappingsOptions\":"
if first {
diff --git a/libpod/container_graph_test.go b/libpod/container_graph_test.go
index 25461f1f4..d1a52658d 100644
--- a/libpod/container_graph_test.go
+++ b/libpod/container_graph_test.go
@@ -1,10 +1,9 @@
package libpod
import (
- "io/ioutil"
- "os"
"testing"
+ "github.com/containers/libpod/libpod/lock"
"github.com/stretchr/testify/assert"
)
@@ -17,11 +16,12 @@ func TestBuildContainerGraphNoCtrsIsEmpty(t *testing.T) {
}
func TestBuildContainerGraphOneCtr(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
graph, err := buildContainerGraph([]*Container{ctr1})
@@ -39,13 +39,14 @@ func TestBuildContainerGraphOneCtr(t *testing.T) {
}
func TestBuildContainerGraphTwoCtrNoEdge(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
graph, err := buildContainerGraph([]*Container{ctr1, ctr2})
@@ -64,13 +65,14 @@ func TestBuildContainerGraphTwoCtrNoEdge(t *testing.T) {
}
func TestBuildContainerGraphTwoCtrOneEdge(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
ctr2.config.UserNsCtr = ctr1.config.ID
@@ -85,13 +87,14 @@ func TestBuildContainerGraphTwoCtrOneEdge(t *testing.T) {
}
func TestBuildContainerGraphTwoCtrCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
ctr2.config.UserNsCtr = ctr1.config.ID
ctr1.config.NetNsCtr = ctr2.config.ID
@@ -101,15 +104,16 @@ func TestBuildContainerGraphTwoCtrCycle(t *testing.T) {
}
func TestBuildContainerGraphThreeCtrNoEdges(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
graph, err := buildContainerGraph([]*Container{ctr1, ctr2, ctr3})
@@ -132,15 +136,16 @@ func TestBuildContainerGraphThreeCtrNoEdges(t *testing.T) {
}
func TestBuildContainerGraphThreeContainersTwoInCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
ctr1.config.UserNsCtr = ctr2.config.ID
ctr2.config.IPCNsCtr = ctr1.config.ID
@@ -150,15 +155,16 @@ func TestBuildContainerGraphThreeContainersTwoInCycle(t *testing.T) {
}
func TestBuildContainerGraphThreeContainersCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
ctr1.config.UserNsCtr = ctr2.config.ID
ctr2.config.IPCNsCtr = ctr3.config.ID
@@ -169,15 +175,16 @@ func TestBuildContainerGraphThreeContainersCycle(t *testing.T) {
}
func TestBuildContainerGraphThreeContainersNoCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
ctr1.config.UserNsCtr = ctr2.config.ID
ctr1.config.NetNsCtr = ctr3.config.ID
@@ -194,17 +201,18 @@ func TestBuildContainerGraphThreeContainersNoCycle(t *testing.T) {
}
func TestBuildContainerGraphFourContainersNoEdges(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
- ctr4, err := getTestCtrN("4", tmpDir)
+ ctr4, err := getTestCtrN("4", manager)
assert.NoError(t, err)
graph, err := buildContainerGraph([]*Container{ctr1, ctr2, ctr3, ctr4})
@@ -231,18 +239,20 @@ func TestBuildContainerGraphFourContainersNoEdges(t *testing.T) {
}
func TestBuildContainerGraphFourContainersTwoInCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
- ctr4, err := getTestCtrN("4", tmpDir)
+ ctr4, err := getTestCtrN("4", manager)
assert.NoError(t, err)
+
ctr1.config.IPCNsCtr = ctr2.config.ID
ctr2.config.UserNsCtr = ctr1.config.ID
@@ -251,18 +261,20 @@ func TestBuildContainerGraphFourContainersTwoInCycle(t *testing.T) {
}
func TestBuildContainerGraphFourContainersAllInCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
- ctr4, err := getTestCtrN("4", tmpDir)
+ ctr4, err := getTestCtrN("4", manager)
assert.NoError(t, err)
+
ctr1.config.IPCNsCtr = ctr2.config.ID
ctr2.config.UserNsCtr = ctr3.config.ID
ctr3.config.NetNsCtr = ctr4.config.ID
@@ -273,18 +285,20 @@ func TestBuildContainerGraphFourContainersAllInCycle(t *testing.T) {
}
func TestBuildContainerGraphFourContainersNoneInCycle(t *testing.T) {
- tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
- assert.NoError(t, err)
- defer os.RemoveAll(tmpDir)
+ manager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ t.Fatalf("Error setting up locks: %v", err)
+ }
- ctr1, err := getTestCtr1(tmpDir)
+ ctr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- ctr2, err := getTestCtr2(tmpDir)
+ ctr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- ctr3, err := getTestCtrN("3", tmpDir)
+ ctr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
- ctr4, err := getTestCtrN("4", tmpDir)
+ ctr4, err := getTestCtrN("4", manager)
assert.NoError(t, err)
+
ctr1.config.IPCNsCtr = ctr2.config.ID
ctr1.config.NetNsCtr = ctr3.config.ID
ctr2.config.UserNsCtr = ctr3.config.ID
diff --git a/libpod/container_internal.go b/libpod/container_internal.go
index 6c027f59a..cc4c36bc9 100644
--- a/libpod/container_internal.go
+++ b/libpod/container_internal.go
@@ -401,7 +401,10 @@ func resetState(state *containerState) error {
return nil
}
-// Refresh refreshes the container's state after a restart
+// Refresh refreshes the container's state after a restart.
+// Refresh cannot perform any operations that would lock another container.
+// We cannot guarantee any other container has a valid lock at the time it is
+// running.
func (c *Container) refresh() error {
// Don't need a full sync, but we do need to update from the database to
// pick up potentially-missing container state
@@ -447,6 +450,13 @@ func (c *Container) refresh() error {
c.state.DestinationRunDir = filepath.Join(c.state.UserNSRoot, "rundir")
}
+ // We need to pick up a new lock
+ lock, err := c.runtime.lockManager.RetrieveLock(c.config.LockID)
+ if err != nil {
+ return errors.Wrapf(err, "error acquiring lock for container %s", c.ID())
+ }
+ c.lock = lock
+
if err := c.save(); err != nil {
return errors.Wrapf(err, "error refreshing state for container %s", c.ID())
}
diff --git a/libpod/lock/in_memory_locks.go b/libpod/lock/in_memory_locks.go
new file mode 100644
index 000000000..db8f20e95
--- /dev/null
+++ b/libpod/lock/in_memory_locks.go
@@ -0,0 +1,91 @@
+package lock
+
+import (
+ "sync"
+
+ "github.com/pkg/errors"
+)
+
+// Mutex holds a single mutex and whether it has been allocated.
+type Mutex struct {
+ id uint32
+ lock sync.Mutex
+ allocated bool
+}
+
+// ID retrieves the ID of the mutex
+func (m *Mutex) ID() uint32 {
+ return m.id
+}
+
+// Lock locks the mutex
+func (m *Mutex) Lock() {
+ m.lock.Lock()
+}
+
+// Unlock unlocks the mutex
+func (m *Mutex) Unlock() {
+ m.lock.Unlock()
+}
+
+// Free deallocates the mutex to allow its reuse
+func (m *Mutex) Free() error {
+ m.allocated = false
+
+ return nil
+}
+
+// InMemoryManager is a lock manager that allocates and retrieves local-only
+// locks - that is, they are not multiprocess. This lock manager is intended
+// purely for unit and integration testing and should not be used in production
+// deployments.
+type InMemoryManager struct {
+ locks []*Mutex
+ numLocks uint32
+ localLock sync.Mutex
+}
+
+// NewInMemoryManager creates a new in-memory lock manager with the given number
+// of locks.
+func NewInMemoryManager(numLocks uint32) (Manager, error) {
+ if numLocks == 0 {
+ return nil, errors.Errorf("must provide a non-zero number of locks!")
+ }
+
+ manager := new(InMemoryManager)
+ manager.numLocks = numLocks
+ manager.locks = make([]*Mutex, numLocks)
+
+ var i uint32
+ for i = 0; i < numLocks; i++ {
+ lock := new(Mutex)
+ lock.id = i
+ manager.locks[i] = lock
+ }
+
+ return manager, nil
+}
+
+// AllocateLock allocates a lock from the manager.
+func (m *InMemoryManager) AllocateLock() (Locker, error) {
+ m.localLock.Lock()
+ defer m.localLock.Unlock()
+
+ for _, lock := range m.locks {
+ if !lock.allocated {
+ lock.allocated = true
+ return lock, nil
+ }
+ }
+
+ return nil, errors.Errorf("all locks have been allocated")
+}
+
+// RetrieveLock retrieves a lock from the manager.
+func (m *InMemoryManager) RetrieveLock(id uint32) (Locker, error) {
+ if id >= m.numLocks {
+ return nil, errors.Errorf("given lock ID %d is too large - this manager only supports lock indexes up to %d", id, m.numLocks-1)
+ }
+
+ return m.locks[id], nil
+}
diff --git a/libpod/lock/lock.go b/libpod/lock/lock.go
new file mode 100644
index 000000000..73c1fdcf7
--- /dev/null
+++ b/libpod/lock/lock.go
@@ -0,0 +1,58 @@
+package lock
+
+// Manager provides an interface for allocating multiprocess locks.
+// Locks returned by Manager MUST be multiprocess - allocating a lock in
+// process A and retrieving that lock's ID in process B must return handles for
+// the same lock, and locking the lock in A should exclude B from the lock until
+// it is unlocked in A.
+// All locks must be identified by a UUID (retrieved with Locker's ID() method).
+// All locks with a given UUID must refer to the same underlying lock, and it
+// must be possible to retrieve the lock given its UUID.
+// Each UUID should refer to a unique underlying lock.
+// Calls to AllocateLock() must return a unique, unallocated UUID.
+// AllocateLock() must fail once all available locks have been allocated.
+// Locks are returned to use by calls to Free(), and can subsequently be
+// reallocated.
+type Manager interface {
+ // AllocateLock returns an unallocated lock.
+ // It is guaranteed that the same lock will not be returned again by
+ // AllocateLock until the returned lock has Free() called on it.
+ // If all available locks are allocated, AllocateLock will return an
+ // error.
+ AllocateLock() (Locker, error)
+ // RetrieveLock retrieves a lock given its UUID.
+ // The underlying lock MUST be the same as another other lock with the
+ // same UUID.
+ RetrieveLock(id uint32) (Locker, error)
+}
+
+// Locker is similar to sync.Locker, but provides a method for freeing the lock
+// to allow its reuse.
+// All Locker implementations must maintain mutex semantics - the lock only
+// allows one caller in the critical section at a time.
+// All locks with the same ID must refer to the same underlying lock, even
+// if they are within multiple processes.
+type Locker interface {
+ // ID retrieves the lock's ID.
+ // ID is guaranteed to uniquely identify the lock within the
+ // Manager - that is, calling RetrieveLock with this ID will return
+ // another instance of the same lock.
+ ID() uint32
+ // Lock locks the lock.
+ // This call MUST block until it successfully acquires the lock or
+ // encounters a fatal error.
+ // All errors must be handled internally, as they are not returned. For
+ // the most part, panicking should be appropriate.
+ Lock()
+ // Unlock unlocks the lock.
+ // All errors must be handled internally, as they are not returned. For
+ // the most part, panicking should be appropriate.
+ // This includes unlocking locks which are already unlocked.
+ Unlock()
+ // Free deallocates the underlying lock, allowing its reuse by other
+ // pods and containers.
+ // The lock MUST still be usable after a Free() - some libpod instances
+ // may still retain Container structs with the old lock. This simply
+ // advises the manager that the lock may be reallocated.
+ Free() error
+}
diff --git a/libpod/lock/shm/shm_lock.c b/libpod/lock/shm/shm_lock.c
new file mode 100644
index 000000000..4af58d857
--- /dev/null
+++ b/libpod/lock/shm/shm_lock.c
@@ -0,0 +1,452 @@
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "shm_lock.h"
+
+// Compute the size of the SHM struct
+static size_t compute_shm_size(uint32_t num_bitmaps) {
+ return sizeof(shm_struct_t) + (num_bitmaps * sizeof(lock_group_t));
+}
+
+// Take the given mutex.
+// Handles exceptional conditions, including a mutex locked by a process that
+// died holding it.
+// Returns 0 on success, or positive errno on failure.
+static int take_mutex(pthread_mutex_t *mutex) {
+ int ret_code;
+
+ do {
+ ret_code = pthread_mutex_lock(mutex);
+ } while(ret_code == EAGAIN);
+
+ if (ret_code == EOWNERDEAD) {
+ // The previous owner of the mutex died while holding it
+ // Take it for ourselves
+ ret_code = pthread_mutex_consistent(mutex);
+ if (ret_code != 0) {
+ // Someone else may have gotten here first and marked the state consistent
+ // However, the mutex could also be invalid.
+ // Fail here instead of looping back to trying to lock the mutex.
+ return ret_code;
+ }
+ } else if (ret_code != 0) {
+ return ret_code;
+ }
+
+ return 0;
+}
+
+// Release the given mutex.
+// Returns 0 on success, or positive errno on failure.
+static int release_mutex(pthread_mutex_t *mutex) {
+ int ret_code;
+
+ do {
+ ret_code = pthread_mutex_unlock(mutex);
+ } while(ret_code == EAGAIN);
+
+ if (ret_code != 0) {
+ return ret_code;
+ }
+
+ return 0;
+}
+
+// Set up an SHM segment holding locks for libpod.
+// num_locks must not be 0.
+// Path is the path to the SHM segment. It must begin with a single / and
+// container no other / characters, and be at most 255 characters including
+// terminating NULL byte.
+// Returns a valid pointer on success or NULL on error.
+// If an error occurs, negative ERRNO values will be written to error_code.
+shm_struct_t *setup_lock_shm(char *path, uint32_t num_locks, int *error_code) {
+ int shm_fd, i, j, ret_code;
+ uint32_t num_bitmaps;
+ size_t shm_size;
+ shm_struct_t *shm;
+ pthread_mutexattr_t attr;
+
+ // If error_code doesn't point to anything, we can't reasonably return errors
+ // So fail immediately
+ if (error_code == NULL) {
+ return NULL;
+ }
+
+ // We need a nonzero number of locks
+ if (num_locks == 0) {
+ *error_code = -1 * EINVAL;
+ return NULL;
+ }
+
+ if (path == NULL) {
+ *error_code = -1 * EINVAL;
+ return NULL;
+ }
+
+ // Calculate the number of bitmaps required
+ num_bitmaps = num_locks / BITMAP_SIZE;
+ if (num_locks % BITMAP_SIZE != 0) {
+ // The actual number given is not an even multiple of our bitmap size
+ // So round up
+ num_bitmaps += 1;
+ }
+
+ // Calculate size of the shm segment
+ shm_size = compute_shm_size(num_bitmaps);
+
+ // Create a new SHM segment for us
+ shm_fd = shm_open(path, O_RDWR | O_CREAT | O_EXCL, 0600);
+ if (shm_fd < 0) {
+ *error_code = -1 * errno;
+ return NULL;
+ }
+
+ // Increase its size to what we need
+ ret_code = ftruncate(shm_fd, shm_size);
+ if (ret_code < 0) {
+ *error_code = -1 * errno;
+ goto CLEANUP_UNLINK;
+ }
+
+ // Map the shared memory in
+ shm = mmap(NULL, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
+ if (shm == MAP_FAILED) {
+ *error_code = -1 * errno;
+ goto CLEANUP_UNLINK;
+ }
+
+ // We have successfully mapped the memory, now initialize the region
+ shm->magic = MAGIC;
+ shm->unused = 0;
+ shm->num_locks = num_bitmaps * BITMAP_SIZE;
+ shm->num_bitmaps = num_bitmaps;
+
+ // Create an initializer for our pthread mutexes
+ ret_code = pthread_mutexattr_init(&attr);
+ if (ret_code != 0) {
+ *error_code = -1 * ret_code;
+ goto CLEANUP_UNMAP;
+ }
+
+ // Set mutexes to pshared - multiprocess-safe
+ ret_code = pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
+ if (ret_code != 0) {
+ *error_code = -1 * ret_code;
+ goto CLEANUP_FREEATTR;
+ }
+
+ // Set mutexes to robust - if a process dies while holding a mutex, we'll get
+ // a special error code on the next attempt to lock it.
+ // This should prevent panicing processes from leaving the state unusable.
+ ret_code = pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST);
+ if (ret_code != 0) {
+ *error_code = -1 * ret_code;
+ goto CLEANUP_FREEATTR;
+ }
+
+ // Initialize the mutex that protects the bitmaps using the mutex attributes
+ ret_code = pthread_mutex_init(&(shm->segment_lock), &attr);
+ if (ret_code != 0) {
+ *error_code = -1 * ret_code;
+ goto CLEANUP_FREEATTR;
+ }
+
+ // Initialize all bitmaps to 0 initially
+ // And initialize all semaphores they use
+ for (i = 0; i < num_bitmaps; i++) {
+ shm->locks[i].bitmap = 0;
+ for (j = 0; j < BITMAP_SIZE; j++) {
+ // Initialize each mutex
+ ret_code = pthread_mutex_init(&(shm->locks[i].locks[j]), &attr);
+ if (ret_code != 0) {
+ *error_code = -1 * ret_code;
+ goto CLEANUP_FREEATTR;
+ }
+ }
+ }
+
+ // Close the file descriptor, we're done with it
+ // Ignore errors, it's ok if we leak a single FD and this should only run once
+ close(shm_fd);
+
+ // Destroy the pthread initializer attribute.
+ // Again, ignore errors, this will only run once and we might leak a tiny bit
+ // of memory at worst.
+ pthread_mutexattr_destroy(&attr);
+
+ return shm;
+
+ // Cleanup after an error
+ CLEANUP_FREEATTR:
+ pthread_mutexattr_destroy(&attr);
+ CLEANUP_UNMAP:
+ munmap(shm, shm_size);
+ CLEANUP_UNLINK:
+ close(shm_fd);
+ shm_unlink(path);
+ return NULL;
+}
+
+// Open an existing SHM segment holding libpod locks.
+// num_locks is the number of locks that will be configured in the SHM segment.
+// num_locks cannot be 0.
+// Path is the path to the SHM segment. It must begin with a single / and
+// container no other / characters, and be at most 255 characters including
+// terminating NULL byte.
+// Returns a valid pointer on success or NULL on error.
+// If an error occurs, negative ERRNO values will be written to error_code.
+shm_struct_t *open_lock_shm(char *path, uint32_t num_locks, int *error_code) {
+ int shm_fd;
+ shm_struct_t *shm;
+ size_t shm_size;
+ uint32_t num_bitmaps;
+
+ if (error_code == NULL) {
+ return NULL;
+ }
+
+ // We need a nonzero number of locks
+ if (num_locks == 0) {
+ *error_code = -1 * EINVAL;
+ return NULL;
+ }
+
+ if (path == NULL) {
+ *error_code = -1 * EINVAL;
+ return NULL;
+ }
+
+ // Calculate the number of bitmaps required
+ num_bitmaps = num_locks / BITMAP_SIZE;
+ if (num_locks % BITMAP_SIZE != 0) {
+ num_bitmaps += 1;
+ }
+
+ // Calculate size of the shm segment
+ shm_size = compute_shm_size(num_bitmaps);
+
+ shm_fd = shm_open(path, O_RDWR, 0600);
+ if (shm_fd < 0) {
+ *error_code = -1 * errno;
+ return NULL;
+ }
+
+ // Map the shared memory in
+ shm = mmap(NULL, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
+ if (shm == MAP_FAILED) {
+ *error_code = -1 * errno;
+ }
+
+ // Ignore errors, it's ok if we leak a single FD since this only runs once
+ close(shm_fd);
+
+ // Check if we successfully mmap'd
+ if (shm == MAP_FAILED) {
+ return NULL;
+ }
+
+ // Need to check the SHM to see if it's actually our locks
+ if (shm->magic != MAGIC) {
+ *error_code = -1 * errno;
+ goto CLEANUP;
+ }
+ if (shm->num_locks != (num_bitmaps * BITMAP_SIZE)) {
+ *error_code = -1 * errno;
+ goto CLEANUP;
+ }
+
+ return shm;
+
+ CLEANUP:
+ munmap(shm, shm_size);
+ return NULL;
+}
+
+// Close an open SHM lock struct, unmapping the backing memory.
+// The given shm_struct_t will be rendered unusable as a result.
+// On success, 0 is returned. On failure, negative ERRNO values are returned.
+int32_t close_lock_shm(shm_struct_t *shm) {
+ int ret_code;
+ size_t shm_size;
+
+ // We can't unmap null...
+ if (shm == NULL) {
+ return -1 * EINVAL;
+ }
+
+ shm_size = compute_shm_size(shm->num_bitmaps);
+
+ ret_code = munmap(shm, shm_size);
+
+ if (ret_code != 0) {
+ return -1 * errno;
+ }
+
+ return 0;
+}
+
+// Allocate the first available semaphore
+// Returns a positive integer guaranteed to be less than UINT32_MAX on success,
+// or negative errno values on failure
+// On sucess, the returned integer is the number of the semaphore allocated
+int64_t allocate_semaphore(shm_struct_t *shm) {
+ int ret_code, i;
+ bitmap_t test_map;
+ int64_t sem_number, num_within_bitmap;
+
+ if (shm == NULL) {
+ return -1 * EINVAL;
+ }
+
+ // Lock the semaphore controlling access to our shared memory
+ ret_code = take_mutex(&(shm->segment_lock));
+ if (ret_code != 0) {
+ return -1 * ret_code;
+ }
+
+ // Loop through our bitmaps to search for one that is not full
+ for (i = 0; i < shm->num_bitmaps; i++) {
+ if (shm->locks[i].bitmap != 0xFFFFFFFF) {
+ test_map = 0x1;
+ num_within_bitmap = 0;
+ while (test_map != 0) {
+ if ((test_map & shm->locks[i].bitmap) == 0) {
+ // Compute the number of the semaphore we are allocating
+ sem_number = (BITMAP_SIZE * i) + num_within_bitmap;
+ // OR in the bitmap
+ shm->locks[i].bitmap = shm->locks[i].bitmap | test_map;
+
+ // Clear the mutex
+ ret_code = release_mutex(&(shm->segment_lock));
+ if (ret_code != 0) {
+ return -1 * ret_code;
+ }
+
+ // Return the semaphore we've allocated
+ return sem_number;
+ }
+ test_map = test_map << 1;
+ num_within_bitmap++;
+ }
+ // We should never fall through this loop
+ // TODO maybe an assert() here to panic if we do?
+ }
+ }
+
+ // Clear the mutex
+ ret_code = release_mutex(&(shm->segment_lock));
+ if (ret_code != 0) {
+ return -1 * ret_code;
+ }
+
+ // All bitmaps are full
+ // We have no available semaphores, report allocation failure
+ return -1 * ENOSPC;
+}
+
+// Deallocate a given semaphore
+// Returns 0 on success, negative ERRNO values on failure
+int32_t deallocate_semaphore(shm_struct_t *shm, uint32_t sem_index) {
+ bitmap_t test_map;
+ int bitmap_index, index_in_bitmap, ret_code, i;
+
+ if (shm == NULL) {
+ return -1 * EINVAL;
+ }
+
+ // Check if the lock index is valid
+ if (sem_index >= shm->num_locks) {
+ return -1 * EINVAL;
+ }
+
+ bitmap_index = sem_index / BITMAP_SIZE;
+ index_in_bitmap = sem_index % BITMAP_SIZE;
+
+ // This should never happen if the sem_index test above succeeded, but better
+ // safe than sorry
+ if (bitmap_index >= shm->num_bitmaps) {
+ return -1 * EFAULT;
+ }
+
+ test_map = 0x1 << index_in_bitmap;
+
+ // Lock the mutex controlling access to our shared memory
+ ret_code = take_mutex(&(shm->segment_lock));
+ if (ret_code != 0) {
+ return -1 * ret_code;
+ }
+
+ // Check if the semaphore is allocated
+ if ((test_map & shm->locks[bitmap_index].bitmap) == 0) {
+ ret_code = release_mutex(&(shm->segment_lock));
+ if (ret_code != 0) {
+ return -1 * ret_code;
+ }
+
+ return -1 * ENOENT;
+ }
+
+ // The semaphore is allocated, clear it
+ // Invert the bitmask we used to test to clear the bit
+ test_map = ~test_map;
+ shm->locks[bitmap_index].bitmap = shm->locks[bitmap_index].bitmap & test_map;
+
+ ret_code = release_mutex(&(shm->segment_lock));
+ if (ret_code != 0) {
+ return -1 * ret_code;
+ }
+
+ return 0;
+}
+
+// Lock a given semaphore
+// Does not check if the semaphore is allocated - this ensures that, even for
+// removed containers, we can still successfully lock to check status (and
+// subsequently realize they have been removed).
+// Returns 0 on success, -1 on failure
+int32_t lock_semaphore(shm_struct_t *shm, uint32_t sem_index) {
+ int bitmap_index, index_in_bitmap, ret_code;
+
+ if (shm == NULL) {
+ return -1 * EINVAL;
+ }
+
+ if (sem_index >= shm->num_locks) {
+ return -1 * EINVAL;
+ }
+
+ bitmap_index = sem_index / BITMAP_SIZE;
+ index_in_bitmap = sem_index % BITMAP_SIZE;
+
+ return -1 * take_mutex(&(shm->locks[bitmap_index].locks[index_in_bitmap]));
+}
+
+// Unlock a given semaphore
+// Does not check if the semaphore is allocated - this ensures that, even for
+// removed containers, we can still successfully lock to check status (and
+// subsequently realize they have been removed).
+// Returns 0 on success, -1 on failure
+int32_t unlock_semaphore(shm_struct_t *shm, uint32_t sem_index) {
+ int bitmap_index, index_in_bitmap, ret_code;
+
+ if (shm == NULL) {
+ return -1 * EINVAL;
+ }
+
+ if (sem_index >= shm->num_locks) {
+ return -1 * EINVAL;
+ }
+
+ bitmap_index = sem_index / BITMAP_SIZE;
+ index_in_bitmap = sem_index % BITMAP_SIZE;
+
+ return -1 * release_mutex(&(shm->locks[bitmap_index].locks[index_in_bitmap]));
+}
diff --git a/libpod/lock/shm/shm_lock.go b/libpod/lock/shm/shm_lock.go
new file mode 100644
index 000000000..3372a8c71
--- /dev/null
+++ b/libpod/lock/shm/shm_lock.go
@@ -0,0 +1,216 @@
+package shm
+
+// #cgo LDFLAGS: -lrt -lpthread
+// #include <stdlib.h>
+// #include "shm_lock.h"
+// const uint32_t bitmap_size_c = BITMAP_SIZE;
+import "C"
+
+import (
+ "runtime"
+ "syscall"
+ "unsafe"
+
+ "github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
+)
+
+var (
+ // BitmapSize is the size of the bitmap used when managing SHM locks.
+ // an SHM lock manager's max locks will be rounded up to a multiple of
+ // this number.
+ BitmapSize uint32 = uint32(C.bitmap_size_c)
+)
+
+// SHMLocks is a struct enabling POSIX semaphore locking in a shared memory
+// segment.
+type SHMLocks struct { // nolint
+ lockStruct *C.shm_struct_t
+ maxLocks uint32
+ valid bool
+}
+
+// CreateSHMLock sets up a shared-memory segment holding a given number of POSIX
+// semaphores, and returns a struct that can be used to operate on those locks.
+// numLocks must not be 0, and may be rounded up to a multiple of the bitmap
+// size used by the underlying implementation.
+func CreateSHMLock(path string, numLocks uint32) (*SHMLocks, error) {
+ if numLocks == 0 {
+ return nil, errors.Wrapf(syscall.EINVAL, "number of locks must greater than 0 0")
+ }
+
+ locks := new(SHMLocks)
+
+ cPath := C.CString(path)
+ defer C.free(unsafe.Pointer(cPath))
+
+ var errCode C.int
+ lockStruct := C.setup_lock_shm(cPath, C.uint32_t(numLocks), &errCode)
+ if lockStruct == nil {
+ // We got a null pointer, so something errored
+ return nil, syscall.Errno(-1 * errCode)
+ }
+
+ locks.lockStruct = lockStruct
+ locks.maxLocks = uint32(lockStruct.num_locks)
+ locks.valid = true
+
+ logrus.Debugf("Initialized SHM lock manager at path %s", path)
+
+ return locks, nil
+}
+
+// OpenSHMLock opens an existing shared-memory segment holding a given number of
+// POSIX semaphores. numLocks must match the number of locks the shared memory
+// segment was created with.
+func OpenSHMLock(path string, numLocks uint32) (*SHMLocks, error) {
+ if numLocks == 0 {
+ return nil, errors.Wrapf(syscall.EINVAL, "number of locks must greater than 0")
+ }
+
+ locks := new(SHMLocks)
+
+ cPath := C.CString(path)
+ defer C.free(unsafe.Pointer(cPath))
+
+ var errCode C.int
+ lockStruct := C.open_lock_shm(cPath, C.uint32_t(numLocks), &errCode)
+ if lockStruct == nil {
+ // We got a null pointer, so something errored
+ return nil, syscall.Errno(-1 * errCode)
+ }
+
+ locks.lockStruct = lockStruct
+ locks.maxLocks = numLocks
+ locks.valid = true
+
+ return locks, nil
+}
+
+// GetMaxLocks returns the maximum number of locks in the SHM
+func (locks *SHMLocks) GetMaxLocks() uint32 {
+ return locks.maxLocks
+}
+
+// Close closes an existing shared-memory segment.
+// The segment will be rendered unusable after closing.
+// WARNING: If you Close() while there are still locks locked, these locks may
+// fail to release, causing a program freeze.
+// Close() is only intended to be used while testing the locks.
+func (locks *SHMLocks) Close() error {
+ if !locks.valid {
+ return errors.Wrapf(syscall.EINVAL, "locks have already been closed")
+ }
+
+ locks.valid = false
+
+ retCode := C.close_lock_shm(locks.lockStruct)
+ if retCode < 0 {
+ // Negative errno returned
+ return syscall.Errno(-1 * retCode)
+ }
+
+ return nil
+}
+
+// AllocateSemaphore allocates a semaphore from a shared-memory segment for use
+// by a container or pod.
+// Returns the index of the semaphore that was allocated.
+// Allocations past the maximum number of locks given when the SHM segment was
+// created will result in an error, and no semaphore will be allocated.
+func (locks *SHMLocks) AllocateSemaphore() (uint32, error) {
+ if !locks.valid {
+ return 0, errors.Wrapf(syscall.EINVAL, "locks have already been closed")
+ }
+
+ // This returns a U64, so we have the full u32 range available for
+ // semaphore indexes, and can still return error codes.
+ retCode := C.allocate_semaphore(locks.lockStruct)
+ if retCode < 0 {
+ // Negative errno returned
+ return 0, syscall.Errno(-1 * retCode)
+ }
+
+ return uint32(retCode), nil
+}
+
+// DeallocateSemaphore frees a semaphore in a shared-memory segment so it can be
+// reallocated to another container or pod.
+// The given semaphore must be already allocated, or an error will be returned.
+func (locks *SHMLocks) DeallocateSemaphore(sem uint32) error {
+ if !locks.valid {
+ return errors.Wrapf(syscall.EINVAL, "locks have already been closed")
+ }
+
+ if sem > locks.maxLocks {
+ return errors.Wrapf(syscall.EINVAL, "given semaphore %d is higher than maximum locks count %d", sem, locks.maxLocks)
+ }
+
+ retCode := C.deallocate_semaphore(locks.lockStruct, C.uint32_t(sem))
+ if retCode < 0 {
+ // Negative errno returned
+ return syscall.Errno(-1 * retCode)
+ }
+
+ return nil
+}
+
+// LockSemaphore locks the given semaphore.
+// If the semaphore is already locked, LockSemaphore will block until the lock
+// can be acquired.
+// There is no requirement that the given semaphore be allocated.
+// This ensures that attempts to lock a container after it has been deleted,
+// but before the caller has queried the database to determine this, will
+// succeed.
+func (locks *SHMLocks) LockSemaphore(sem uint32) error {
+ if !locks.valid {
+ return errors.Wrapf(syscall.EINVAL, "locks have already been closed")
+ }
+
+ if sem > locks.maxLocks {
+ return errors.Wrapf(syscall.EINVAL, "given semaphore %d is higher than maximum locks count %d", sem, locks.maxLocks)
+ }
+
+ // For pthread mutexes, we have to guarantee lock and unlock happen in
+ // the same thread.
+ runtime.LockOSThread()
+
+ retCode := C.lock_semaphore(locks.lockStruct, C.uint32_t(sem))
+ if retCode < 0 {
+ // Negative errno returned
+ return syscall.Errno(-1 * retCode)
+ }
+
+ return nil
+}
+
+// UnlockSemaphore unlocks the given semaphore.
+// Unlocking a semaphore that is already unlocked with return EBUSY.
+// There is no requirement that the given semaphore be allocated.
+// This ensures that attempts to lock a container after it has been deleted,
+// but before the caller has queried the database to determine this, will
+// succeed.
+func (locks *SHMLocks) UnlockSemaphore(sem uint32) error {
+ if !locks.valid {
+ return errors.Wrapf(syscall.EINVAL, "locks have already been closed")
+ }
+
+ if sem > locks.maxLocks {
+ return errors.Wrapf(syscall.EINVAL, "given semaphore %d is higher than maximum locks count %d", sem, locks.maxLocks)
+ }
+
+ retCode := C.unlock_semaphore(locks.lockStruct, C.uint32_t(sem))
+ if retCode < 0 {
+ // Negative errno returned
+ return syscall.Errno(-1 * retCode)
+ }
+
+ // For pthread mutexes, we have to guarantee lock and unlock happen in
+ // the same thread.
+ // OK if we take multiple locks - UnlockOSThread() won't actually unlock
+ // until the number of calls equals the number of calls to
+ // LockOSThread()
+ runtime.UnlockOSThread()
+
+ return nil
+}
diff --git a/libpod/lock/shm/shm_lock.h b/libpod/lock/shm/shm_lock.h
new file mode 100644
index 000000000..8e7e23fb7
--- /dev/null
+++ b/libpod/lock/shm/shm_lock.h
@@ -0,0 +1,46 @@
+#ifndef shm_locks_h_
+#define shm_locks_h_
+
+#include <pthread.h>
+#include <stdint.h>
+
+// Magic number to ensure we open the right SHM segment
+#define MAGIC 0x87D1
+
+// Type for our bitmaps
+typedef uint32_t bitmap_t;
+
+// bitmap size
+#define BITMAP_SIZE (sizeof(bitmap_t) * 8)
+
+// Struct to hold a single bitmap and associated locks
+typedef struct lock_group {
+ bitmap_t bitmap;
+ pthread_mutex_t locks[BITMAP_SIZE];
+} lock_group_t;
+
+// Struct to hold our SHM locks.
+// Unused is required to be 0 in the current implementation. If we ever make
+// changes to this structure in the future, this will be repurposed as a version
+// field.
+typedef struct shm_struct {
+ uint16_t magic;
+ uint16_t unused;
+ pthread_mutex_t segment_lock;
+ uint32_t num_bitmaps;
+ uint32_t num_locks;
+ lock_group_t locks[];
+} shm_struct_t;
+
+static size_t compute_shm_size(uint32_t num_bitmaps);
+static int take_mutex(pthread_mutex_t *mutex);
+static int release_mutex(pthread_mutex_t *mutex);
+shm_struct_t *setup_lock_shm(char *path, uint32_t num_locks, int *error_code);
+shm_struct_t *open_lock_shm(char *path, uint32_t num_locks, int *error_code);
+int32_t close_lock_shm(shm_struct_t *shm);
+int64_t allocate_semaphore(shm_struct_t *shm);
+int32_t deallocate_semaphore(shm_struct_t *shm, uint32_t sem_index);
+int32_t lock_semaphore(shm_struct_t *shm, uint32_t sem_index);
+int32_t unlock_semaphore(shm_struct_t *shm, uint32_t sem_index);
+
+#endif
diff --git a/libpod/lock/shm/shm_lock_test.go b/libpod/lock/shm/shm_lock_test.go
new file mode 100644
index 000000000..0f3a96cca
--- /dev/null
+++ b/libpod/lock/shm/shm_lock_test.go
@@ -0,0 +1,278 @@
+package shm
+
+import (
+ "fmt"
+ "os"
+ "runtime"
+ "syscall"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+// All tests here are in the same process, which somewhat limits their utility
+// The big intent of this package it multiprocess locking, which is really hard
+// to test without actually having multiple processes...
+// We can at least verify that the locks work within the local process.
+
+var (
+ // 4 * BITMAP_SIZE to ensure we have to traverse bitmaps
+ numLocks = 4 * BitmapSize
+)
+
+const lockPath = "/libpod_test"
+
+// We need a test main to ensure that the SHM is created before the tests run
+func TestMain(m *testing.M) {
+ shmLock, err := CreateSHMLock(lockPath, numLocks)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Error creating SHM for tests: %v\n", err)
+ os.Exit(-1)
+ }
+
+ // Close the SHM - every subsequent test will reopen
+ if err := shmLock.Close(); err != nil {
+ fmt.Fprintf(os.Stderr, "Error closing SHM locks: %v\n", err)
+ os.Exit(-1)
+ }
+
+ exitCode := m.Run()
+
+ // We need to remove the SHM segment to clean up after ourselves
+ os.RemoveAll("/dev/shm/libpod_lock")
+
+ os.Exit(exitCode)
+}
+
+func runLockTest(t *testing.T, testFunc func(*testing.T, *SHMLocks)) {
+ locks, err := OpenSHMLock(lockPath, numLocks)
+ if err != nil {
+ t.Fatalf("Error opening locks: %v", err)
+ }
+ defer func() {
+ // Deallocate all locks
+ // Ignore ENOENT (lock is not allocated)
+ var i uint32
+ for i = 0; i < numLocks; i++ {
+ if err := locks.DeallocateSemaphore(i); err != nil && err != syscall.ENOENT {
+ t.Fatalf("Error deallocating semaphore %d: %v", i, err)
+ }
+ }
+
+ if err := locks.Close(); err != nil {
+ t.Fatalf("Error closing locks: %v", err)
+ }
+ }()
+
+ success := t.Run("locks", func(t *testing.T) {
+ testFunc(t, locks)
+ })
+ if !success {
+ t.Fail()
+ }
+}
+
+// Test that creating an SHM with a bad size rounds up to a good size
+func TestCreateNewSHMBadSizeRoundsUp(t *testing.T) {
+ // Odd number, not a power of 2, should never be a word size on a system
+ lock, err := CreateSHMLock("/test1", 7)
+ assert.NoError(t, err)
+
+ assert.Equal(t, lock.GetMaxLocks(), BitmapSize)
+
+ if err := lock.Close(); err != nil {
+ t.Fatalf("Error closing locks: %v", err)
+ }
+}
+
+// Test that creating an SHM with 0 size fails
+func TestCreateNewSHMZeroSize(t *testing.T) {
+ _, err := CreateSHMLock("/test2", 0)
+ assert.Error(t, err)
+}
+
+// Test that deallocating an unallocated lock errors
+func TestDeallocateUnallocatedLockErrors(t *testing.T) {
+ runLockTest(t, func(t *testing.T, locks *SHMLocks) {
+ err := locks.DeallocateSemaphore(0)
+ assert.Error(t, err)
+ })
+}
+
+// Test that unlocking an unlocked lock fails
+func TestUnlockingUnlockedLockFails(t *testing.T) {
+ runLockTest(t, func(t *testing.T, locks *SHMLocks) {
+ err := locks.UnlockSemaphore(0)
+ assert.Error(t, err)
+ })
+}
+
+// Test that locking and double-unlocking fails
+func TestDoubleUnlockFails(t *testing.T) {
+ runLockTest(t, func(t *testing.T, locks *SHMLocks) {
+ err := locks.LockSemaphore(0)
+ assert.NoError(t, err)
+
+ err = locks.UnlockSemaphore(0)
+ assert.NoError(t, err)
+
+ err = locks.UnlockSemaphore(0)
+ assert.Error(t, err)
+ })
+}
+
+// Test allocating - lock - unlock - deallocate cycle, single lock
+func TestLockLifecycleSingleLock(t *testing.T) {
+ runLockTest(t, func(t *testing.T, locks *SHMLocks) {
+ sem, err := locks.AllocateSemaphore()
+ require.NoError(t, err)
+
+ err = locks.LockSemaphore(sem)
+ assert.NoError(t, err)
+
+ err = locks.UnlockSemaphore(sem)
+ assert.NoError(t, err)
+
+ err = locks.DeallocateSemaphore(sem)
+ assert.NoError(t, err)
+ })
+}
+
+// Test allocate two locks returns different locks
+func TestAllocateTwoLocksGetsDifferentLocks(t *testing.T) {
+ runLockTest(t, func(t *testing.T, locks *SHMLocks) {
+ sem1, err := locks.AllocateSemaphore()
+ assert.NoError(t, err)
+
+ sem2, err := locks.AllocateSemaphore()
+ assert.NoError(t, err)
+
+ assert.NotEqual(t, sem1, sem2)
+ })
+}
+
+// Test allocate all locks successful and all are unique
+func TestAllocateAllLocksSucceeds(t *testing.T) {
+ runLockTest(t, func(t *testing.T, locks *SHMLocks) {
+ sems := make(map[uint32]bool)
+ var i uint32
+ for i = 0; i < numLocks; i++ {
+ sem, err := locks.AllocateSemaphore()
+ assert.NoError(t, err)
+
+ // Ensure the allocate semaphore is unique
+ _, ok := sems[sem]
+ assert.False(t, ok)
+
+ sems[sem] = true
+ }
+ })
+}
+
+// Test allocating more than the given max fails
+func TestAllocateTooManyLocksFails(t *testing.T) {
+ runLockTest(t, func(t *testing.T, locks *SHMLocks) {
+ // Allocate all locks
+ var i uint32
+ for i = 0; i < numLocks; i++ {
+ _, err := locks.AllocateSemaphore()
+ assert.NoError(t, err)
+ }
+
+ // Try and allocate one more
+ _, err := locks.AllocateSemaphore()
+ assert.Error(t, err)
+ })
+}
+
+// Test allocating max locks, deallocating one, and then allocating again succeeds
+func TestAllocateDeallocateCycle(t *testing.T) {
+ runLockTest(t, func(t *testing.T, locks *SHMLocks) {
+ // Allocate all locks
+ var i uint32
+ for i = 0; i < numLocks; i++ {
+ _, err := locks.AllocateSemaphore()
+ assert.NoError(t, err)
+ }
+
+ // Now loop through again, deallocating and reallocating.
+ // Each time we free 1 semaphore, allocate again, and make sure
+ // we get the same semaphore back.
+ var j uint32
+ for j = 0; j < numLocks; j++ {
+ err := locks.DeallocateSemaphore(j)
+ assert.NoError(t, err)
+
+ newSem, err := locks.AllocateSemaphore()
+ assert.NoError(t, err)
+ assert.Equal(t, j, newSem)
+ }
+ })
+}
+
+// Test that locks actually lock
+func TestLockSemaphoreActuallyLocks(t *testing.T) {
+ runLockTest(t, func(t *testing.T, locks *SHMLocks) {
+ // This entire test is very ugly - lots of sleeps to try and get
+ // things to occur in the right order.
+ // It also doesn't even exercise the multiprocess nature of the
+ // locks.
+
+ // Get the current time
+ startTime := time.Now()
+
+ // Start a goroutine to take the lock and then release it after
+ // a second.
+ go func() {
+ err := locks.LockSemaphore(0)
+ assert.NoError(t, err)
+
+ time.Sleep(1 * time.Second)
+
+ err = locks.UnlockSemaphore(0)
+ assert.NoError(t, err)
+ }()
+
+ // Sleep for a quarter of a second to give the goroutine time
+ // to kick off and grab the lock
+ time.Sleep(250 * time.Millisecond)
+
+ // Take the lock
+ err := locks.LockSemaphore(0)
+ assert.NoError(t, err)
+
+ // Get the current time
+ endTime := time.Now()
+
+ // Verify that at least 1 second has passed since start
+ duration := endTime.Sub(startTime)
+ assert.True(t, duration.Seconds() > 1.0)
+ })
+}
+
+// Test that locking and unlocking two semaphores succeeds
+// Ensures that runtime.LockOSThread() is doing its job
+func TestLockAndUnlockTwoSemaphore(t *testing.T) {
+ runLockTest(t, func(t *testing.T, locks *SHMLocks) {
+ err := locks.LockSemaphore(0)
+ assert.NoError(t, err)
+
+ err = locks.LockSemaphore(1)
+ assert.NoError(t, err)
+
+ err = locks.UnlockSemaphore(1)
+ assert.NoError(t, err)
+
+ // Now yield scheduling
+ // To try and get us on another OS thread
+ runtime.Gosched()
+
+ // And unlock the last semaphore
+ // If we are in a different OS thread, this should fail.
+ // However, runtime.UnlockOSThread() should guarantee we are not
+ err = locks.UnlockSemaphore(0)
+ assert.NoError(t, err)
+ })
+}
diff --git a/libpod/lock/shm_lock_manager_linux.go b/libpod/lock/shm_lock_manager_linux.go
new file mode 100644
index 000000000..3e8f4f3d2
--- /dev/null
+++ b/libpod/lock/shm_lock_manager_linux.go
@@ -0,0 +1,94 @@
+// +build linux
+
+package lock
+
+import (
+ "github.com/containers/libpod/libpod/lock/shm"
+)
+
+// SHMLockManager manages shared memory locks.
+type SHMLockManager struct {
+ locks *shm.SHMLocks
+}
+
+// NewSHMLockManager makes a new SHMLockManager with the given number of locks.
+// Due to the underlying implementation, the exact number of locks created may
+// be greater than the number given here.
+func NewSHMLockManager(path string, numLocks uint32) (Manager, error) {
+ locks, err := shm.CreateSHMLock(path, numLocks)
+ if err != nil {
+ return nil, err
+ }
+
+ manager := new(SHMLockManager)
+ manager.locks = locks
+
+ return manager, nil
+}
+
+// OpenSHMLockManager opens an existing SHMLockManager with the given number of
+// locks.
+func OpenSHMLockManager(path string, numLocks uint32) (Manager, error) {
+ locks, err := shm.OpenSHMLock(path, numLocks)
+ if err != nil {
+ return nil, err
+ }
+
+ manager := new(SHMLockManager)
+ manager.locks = locks
+
+ return manager, nil
+}
+
+// AllocateLock allocates a new lock from the manager.
+func (m *SHMLockManager) AllocateLock() (Locker, error) {
+ semIndex, err := m.locks.AllocateSemaphore()
+ if err != nil {
+ return nil, err
+ }
+
+ lock := new(SHMLock)
+ lock.lockID = semIndex
+ lock.manager = m
+
+ return lock, nil
+}
+
+// RetrieveLock retrieves a lock from the manager given its ID.
+func (m *SHMLockManager) RetrieveLock(id uint32) (Locker, error) {
+ lock := new(SHMLock)
+ lock.lockID = id
+ lock.manager = m
+
+ return lock, nil
+}
+
+// SHMLock is an individual shared memory lock.
+type SHMLock struct {
+ lockID uint32
+ manager *SHMLockManager
+}
+
+// ID returns the ID of the lock.
+func (l *SHMLock) ID() uint32 {
+ return l.lockID
+}
+
+// Lock acquires the lock.
+func (l *SHMLock) Lock() {
+ if err := l.manager.locks.LockSemaphore(l.lockID); err != nil {
+ panic(err.Error())
+ }
+}
+
+// Unlock releases the lock.
+func (l *SHMLock) Unlock() {
+ if err := l.manager.locks.UnlockSemaphore(l.lockID); err != nil {
+ panic(err.Error())
+ }
+}
+
+// Free releases the lock, allowing it to be reused.
+func (l *SHMLock) Free() error {
+ return l.manager.locks.DeallocateSemaphore(l.lockID)
+}
diff --git a/libpod/lock/shm_lock_manager_unsupported.go b/libpod/lock/shm_lock_manager_unsupported.go
new file mode 100644
index 000000000..a1340fcd1
--- /dev/null
+++ b/libpod/lock/shm_lock_manager_unsupported.go
@@ -0,0 +1,29 @@
+// +build !linux
+
+package lock
+
+import "fmt"
+
+// SHMLockManager is a shared memory lock manager.
+// It is not supported on non-Unix platforms.
+type SHMLockManager struct{}
+
+// NewSHMLockManager is not supported on this platform
+func NewSHMLockManager(numLocks uint32) (Manager, error) {
+ return nil, fmt.Errorf("not supported")
+}
+
+// OpenSHMLockManager is not supported on this platform
+func OpenSHMLockManager(numLocks uint32) (Manager, error) {
+ return nil, fmt.Errorf("not supported")
+}
+
+// AllocateLock is not supported on this platform
+func (m *SHMLockManager) AllocateLock() (Locker, error) {
+ return nil, fmt.Errorf("not supported")
+}
+
+// RetrieveLock is not supported on this platform
+func (m *SHMLockManager) RetrieveLock(id string) (Locker, error) {
+ return nil, fmt.Errorf("not supported")
+}
diff --git a/libpod/pod.go b/libpod/pod.go
index 07f41f5c6..4ce697402 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -3,7 +3,7 @@ package libpod
import (
"time"
- "github.com/containers/storage"
+ "github.com/containers/libpod/libpod/lock"
"github.com/cri-o/ocicni/pkg/ocicni"
"github.com/pkg/errors"
)
@@ -26,7 +26,7 @@ type Pod struct {
valid bool
runtime *Runtime
- lock storage.Locker
+ lock lock.Locker
}
// PodConfig represents a pod's static configuration
@@ -60,6 +60,9 @@ type PodConfig struct {
// Time pod was created
CreatedTime time.Time `json:"created"`
+
+ // ID of the pod's lock
+ LockID uint32 `json:"lockID"`
}
// podState represents a pod's state
diff --git a/libpod/pod_easyjson.go b/libpod/pod_easyjson.go
index 8ea9a5e72..71862dad0 100644
--- a/libpod/pod_easyjson.go
+++ b/libpod/pod_easyjson.go
@@ -501,6 +501,8 @@ func easyjsonBe091417DecodeGithubComContainersLibpodLibpod4(in *jlexer.Lexer, ou
if data := in.Raw(); in.Ok() {
in.AddError((out.CreatedTime).UnmarshalJSON(data))
}
+ case "lockID":
+ out.LockID = uint32(in.Uint32())
default:
in.SkipRecursive()
}
@@ -675,6 +677,16 @@ func easyjsonBe091417EncodeGithubComContainersLibpodLibpod4(out *jwriter.Writer,
}
out.Raw((in.CreatedTime).MarshalJSON())
}
+ {
+ const prefix string = ",\"lockID\":"
+ if first {
+ first = false
+ out.RawString(prefix[1:])
+ } else {
+ out.RawString(prefix)
+ }
+ out.Uint32(uint32(in.LockID))
+ }
out.RawByte('}')
}
diff --git a/libpod/pod_internal.go b/libpod/pod_internal.go
index 39a25c004..0f1f115e8 100644
--- a/libpod/pod_internal.go
+++ b/libpod/pod_internal.go
@@ -7,14 +7,13 @@ import (
"strings"
"time"
- "github.com/containers/storage"
"github.com/containers/storage/pkg/stringid"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
// Creates a new, empty pod
-func newPod(lockDir string, runtime *Runtime) (*Pod, error) {
+func newPod(runtime *Runtime) (*Pod, error) {
pod := new(Pod)
pod.config = new(PodConfig)
pod.config.ID = stringid.GenerateNonCryptoID()
@@ -24,15 +23,6 @@ func newPod(lockDir string, runtime *Runtime) (*Pod, error) {
pod.state = new(podState)
pod.runtime = runtime
- // Path our lock file will reside at
- lockPath := filepath.Join(lockDir, pod.config.ID)
- // Grab a lockfile at the given path
- lock, err := storage.GetLockfile(lockPath)
- if err != nil {
- return nil, errors.Wrapf(err, "error creating lockfile for new pod")
- }
- pod.lock = lock
-
return pod, nil
}
@@ -55,6 +45,8 @@ func (p *Pod) save() error {
}
// Refresh a pod's state after restart
+// This cannot lock any other pod, but may lock individual containers, as those
+// will have refreshed by the time pod refresh runs.
func (p *Pod) refresh() error {
// Need to to an update from the DB to pull potentially-missing state
if err := p.runtime.state.UpdatePod(p); err != nil {
@@ -65,6 +57,13 @@ func (p *Pod) refresh() error {
return ErrPodRemoved
}
+ // Retrieve the pod's lock
+ lock, err := p.runtime.lockManager.RetrieveLock(p.config.LockID)
+ if err != nil {
+ return errors.Wrapf(err, "error retrieving lock for pod %s", p.ID())
+ }
+ p.lock = lock
+
// We need to recreate the pod's cgroup
if p.config.UsePodCgroup {
switch p.runtime.config.CgroupManager {
diff --git a/libpod/runtime.go b/libpod/runtime.go
index 2dfebf565..fcc1c6d82 100644
--- a/libpod/runtime.go
+++ b/libpod/runtime.go
@@ -11,6 +11,7 @@ import (
is "github.com/containers/image/storage"
"github.com/containers/image/types"
"github.com/containers/libpod/libpod/image"
+ "github.com/containers/libpod/libpod/lock"
"github.com/containers/libpod/pkg/firewall"
sysreg "github.com/containers/libpod/pkg/registries"
"github.com/containers/libpod/pkg/rootless"
@@ -61,6 +62,14 @@ const (
DefaultInfraImage = "k8s.gcr.io/pause:3.1"
// DefaultInfraCommand to be run in an infra container
DefaultInfraCommand = "/pause"
+
+ // DefaultInitPath is the default path to the container-init binary
+ DefaultInitPath = "/usr/libexec/podman/catatonit"
+
+ // DefaultSHMLockPath is the default path for SHM locks
+ DefaultSHMLockPath = "/libpod_lock"
+ // DefaultRootlessSHMLockPath is the default path for rootless SHM locks
+ DefaultRootlessSHMLockPath = "/libpod_rootless_lock"
)
// A RuntimeOption is a functional option which alters the Runtime created by
@@ -75,7 +84,6 @@ type Runtime struct {
storageService *storageService
imageContext *types.SystemContext
ociRuntime *OCIRuntime
- lockDir string
netPlugin ocicni.CNIPlugin
ociRuntimePath string
conmonPath string
@@ -83,6 +91,7 @@ type Runtime struct {
lock sync.RWMutex
imageRuntime *image.Runtime
firewallBackend firewall.FirewallBackend
+ lockManager lock.Manager
configuredFrom *runtimeConfiguredFrom
}
@@ -122,6 +131,8 @@ type RuntimeConfig struct {
// CGroupManager is the CGroup Manager to use
// Valid values are "cgroupfs" and "systemd"
CgroupManager string `toml:"cgroup_manager"`
+ // InitPath is the path to the container-init binary.
+ InitPath string `toml:"init_path"`
// StaticDir is the path to a persistent directory to store container
// files
StaticDir string `toml:"static_dir"`
@@ -160,6 +171,7 @@ type RuntimeConfig struct {
// and all containers and pods will be visible.
// The default namespace is "".
Namespace string `toml:"namespace,omitempty"`
+
// InfraImage is the image a pod infra container will use to manage namespaces
InfraImage string `toml:"infra_image"`
// InfraCommand is the command run to start up a pod infra container
@@ -174,6 +186,10 @@ type RuntimeConfig struct {
EnablePortReservation bool `toml:"enable_port_reservation"`
// EnableLabeling indicates wether libpod will support container labeling
EnableLabeling bool `toml:"label"`
+
+ // NumLocks is the number of locks to make available for containers and
+ // pods.
+ NumLocks uint32 `toml:"num_locks,omitempty"`
}
// runtimeConfiguredFrom is a struct used during early runtime init to help
@@ -217,6 +233,7 @@ var (
ConmonEnvVars: []string{
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
},
+ InitPath: DefaultInitPath,
CgroupManager: SystemdCgroupsManager,
StaticDir: filepath.Join(storage.DefaultStoreOptions.GraphRoot, "libpod"),
TmpDir: "",
@@ -228,6 +245,7 @@ var (
InfraImage: DefaultInfraImage,
EnablePortReservation: true,
EnableLabeling: true,
+ NumLocks: 2048,
}
)
@@ -610,17 +628,6 @@ func makeRuntime(runtime *Runtime) (err error) {
}
runtime.ociRuntime = ociRuntime
- // Make a directory to hold container lockfiles
- lockDir := filepath.Join(runtime.config.TmpDir, "lock")
- if err := os.MkdirAll(lockDir, 0755); err != nil {
- // The directory is allowed to exist
- if !os.IsExist(err) {
- return errors.Wrapf(err, "error creating runtime lockfiles directory %s",
- lockDir)
- }
- }
- runtime.lockDir = lockDir
-
// Make the per-boot files directory if it does not exist
if err := os.MkdirAll(runtime.config.TmpDir, 0755); err != nil {
// The directory is allowed to exist
@@ -665,6 +672,7 @@ func makeRuntime(runtime *Runtime) (err error) {
// and use it to lock important operations
aliveLock.Lock()
locked := true
+ doRefresh := false
defer func() {
if locked {
aliveLock.Unlock()
@@ -677,22 +685,52 @@ func makeRuntime(runtime *Runtime) (err error) {
// empty state only creates a single file
// As such, it's not really a performance concern
if os.IsNotExist(err) {
- if os.Geteuid() != 0 {
- aliveLock.Unlock()
- locked = false
- if err2 := runtime.refreshRootless(); err2 != nil {
- return err2
- }
- } else {
- if err2 := runtime.refresh(runtimeAliveFile); err2 != nil {
- return err2
- }
- }
+ doRefresh = true
} else {
return errors.Wrapf(err, "error reading runtime status file %s", runtimeAliveFile)
}
}
+ // Set up the lock manager
+ var manager lock.Manager
+ lockPath := DefaultSHMLockPath
+ if rootless.IsRootless() {
+ lockPath = DefaultRootlessSHMLockPath
+ }
+ if doRefresh {
+ // If SHM locks already exist, delete them and reinitialize
+ if err := os.Remove(filepath.Join("/dev/shm", lockPath)); err != nil && !os.IsNotExist(err) {
+ return errors.Wrapf(err, "error deleting existing libpod SHM segment %s", lockPath)
+ }
+
+ manager, err = lock.NewSHMLockManager(lockPath, runtime.config.NumLocks)
+ if err != nil {
+ return errors.Wrapf(err, "error creating SHM locks for libpod")
+ }
+ } else {
+ manager, err = lock.OpenSHMLockManager(lockPath, runtime.config.NumLocks)
+ if err != nil {
+ return errors.Wrapf(err, "error opening libpod SHM locks")
+ }
+ }
+ runtime.lockManager = manager
+
+ // If we need to refresh the state, do it now - things are guaranteed to
+ // be set up by now.
+ if doRefresh {
+ if os.Geteuid() != 0 {
+ aliveLock.Unlock()
+ locked = false
+ if err2 := runtime.refreshRootless(); err2 != nil {
+ return err2
+ }
+ } else {
+ if err2 := runtime.refresh(runtimeAliveFile); err2 != nil {
+ return err2
+ }
+ }
+ }
+
// Mark the runtime as valid - ready to be used, cannot be modified
// further
runtime.valid = true
@@ -788,19 +826,22 @@ func (r *Runtime) refresh(alivePath string) error {
if err != nil {
return errors.Wrapf(err, "error retrieving all pods from state")
}
+ // No locks are taken during pod and container refresh.
+ // Furthermore, the pod and container refresh() functions are not
+ // allowed to take locks themselves.
+ // We cannot assume that any pod or container has a valid lock until
+ // after this function has returned.
+ // The runtime alive lock should suffice to provide mutual exclusion
+ // until this has run.
for _, ctr := range ctrs {
- ctr.lock.Lock()
if err := ctr.refresh(); err != nil {
logrus.Errorf("Error refreshing container %s: %v", ctr.ID(), err)
}
- ctr.lock.Unlock()
}
for _, pod := range pods {
- pod.lock.Lock()
if err := pod.refresh(); err != nil {
logrus.Errorf("Error refreshing pod %s: %v", pod.ID(), err)
}
- pod.lock.Unlock()
}
// Create a file indicating the runtime is alive and ready
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index a9095c6d1..e6f2c962f 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -9,7 +9,6 @@ import (
"time"
"github.com/containers/libpod/pkg/rootless"
- "github.com/containers/storage"
"github.com/containers/storage/pkg/stringid"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
@@ -61,15 +60,6 @@ func (r *Runtime) newContainer(ctx context.Context, rSpec *spec.Spec, options ..
ctr.state.BindMounts = make(map[string]string)
- // Path our lock file will reside at
- lockPath := filepath.Join(r.lockDir, ctr.config.ID)
- // Grab a lockfile at the given path
- lock, err := storage.GetLockfile(lockPath)
- if err != nil {
- return nil, errors.Wrapf(err, "error creating lockfile for new container")
- }
- ctr.lock = lock
-
ctr.config.StopTimeout = CtrRemoveTimeout
// Set namespace based on current runtime namespace
@@ -85,6 +75,19 @@ func (r *Runtime) newContainer(ctx context.Context, rSpec *spec.Spec, options ..
}
}
+ // Allocate a lock for the container
+ lock, err := r.lockManager.AllocateLock()
+ if err != nil {
+ return nil, errors.Wrapf(err, "error allocating lock for new container")
+ }
+ ctr.lock = lock
+ ctr.config.LockID = ctr.lock.ID()
+ logrus.Debugf("Allocated lock %d for container %s", ctr.lock.ID(), ctr.ID())
+
+ ctr.valid = true
+ ctr.state.State = ContainerStateConfigured
+ ctr.runtime = r
+
ctr.valid = true
ctr.state.State = ContainerStateConfigured
@@ -379,6 +382,15 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool)
}
}
+ // Deallocate the container's lock
+ if err := c.lock.Free(); err != nil {
+ if cleanupErr == nil {
+ cleanupErr = err
+ } else {
+ logrus.Errorf("free container lock: %v", err)
+ }
+ }
+
return cleanupErr
}
diff --git a/libpod/runtime_pod_linux.go b/libpod/runtime_pod_linux.go
index 3d6fad52f..c6d497c0c 100644
--- a/libpod/runtime_pod_linux.go
+++ b/libpod/runtime_pod_linux.go
@@ -23,7 +23,7 @@ func (r *Runtime) NewPod(ctx context.Context, options ...PodCreateOption) (*Pod,
return nil, ErrRuntimeStopped
}
- pod, err := newPod(r.lockDir, r)
+ pod, err := newPod(r)
if err != nil {
return nil, errors.Wrapf(err, "error creating pod")
}
@@ -48,6 +48,14 @@ func (r *Runtime) NewPod(ctx context.Context, options ...PodCreateOption) (*Pod,
pod.config.Name = name
}
+ // Allocate a lock for the pod
+ lock, err := r.lockManager.AllocateLock()
+ if err != nil {
+ return nil, errors.Wrapf(err, "error allocating lock for new pod")
+ }
+ pod.lock = lock
+ pod.config.LockID = pod.lock.ID()
+
pod.valid = true
// Check CGroup parent sanity, and set it if it was not set
@@ -239,6 +247,11 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
return err
}
}
+
+ // Free the container's lock
+ if err := ctr.lock.Free(); err != nil {
+ return err
+ }
}
// Remove containers from the state
diff --git a/libpod/runtime_volume_linux.go b/libpod/runtime_volume_linux.go
index 5cc0938f0..0727cfedf 100644
--- a/libpod/runtime_volume_linux.go
+++ b/libpod/runtime_volume_linux.go
@@ -8,7 +8,6 @@ import (
"path/filepath"
"strings"
- "github.com/containers/storage"
"github.com/containers/storage/pkg/stringid"
"github.com/opencontainers/selinux/go-selinux/label"
"github.com/pkg/errors"
@@ -68,14 +67,12 @@ func (r *Runtime) newVolume(ctx context.Context, options ...VolumeCreateOption)
}
volume.config.MountPoint = fullVolPath
- // Path our lock file will reside at
- lockPath := filepath.Join(r.lockDir, volume.config.Name)
- // Grab a lockfile at the given path
- lock, err := storage.GetLockfile(lockPath)
+ lock, err := r.lockManager.AllocateLock()
if err != nil {
- return nil, errors.Wrapf(err, "error creating lockfile for new volume")
+ return nil, errors.Wrapf(err, "error allocating lock for new volume")
}
volume.lock = lock
+ volume.config.LockID = volume.lock.ID()
volume.valid = true
diff --git a/libpod/state_test.go b/libpod/state_test.go
index 708ce7d4e..ee4201b1c 100644
--- a/libpod/state_test.go
+++ b/libpod/state_test.go
@@ -8,16 +8,17 @@ import (
"testing"
"time"
+ "github.com/containers/libpod/libpod/lock"
"github.com/containers/storage"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
-// Returns state, tmp directory containing all state files, locks directory
-// (subdirectory of tmp dir), and error
+// Returns state, tmp directory containing all state files, lock manager, and
+// error.
// Closing the state and removing the given tmp directory should be sufficient
-// to clean up
-type emptyStateFunc func() (State, string, string, error)
+// to clean up.
+type emptyStateFunc func() (State, string, lock.Manager, error)
const (
tmpDirPrefix = "libpod_state_test_"
@@ -31,10 +32,10 @@ var (
)
// Get an empty BoltDB state for use in tests
-func getEmptyBoltState() (s State, p string, p2 string, err error) {
+func getEmptyBoltState() (s State, p string, m lock.Manager, err error) {
tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
if err != nil {
- return nil, "", "", err
+ return nil, "", nil, err
}
defer func() {
if err != nil {
@@ -43,30 +44,30 @@ func getEmptyBoltState() (s State, p string, p2 string, err error) {
}()
dbPath := filepath.Join(tmpDir, "db.sql")
- lockDir := filepath.Join(tmpDir, "locks")
- if err := os.Mkdir(lockDir, 0755); err != nil {
- return nil, "", "", err
+ lockManager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ return nil, "", nil, err
}
runtime := new(Runtime)
runtime.config = new(RuntimeConfig)
runtime.config.StorageConfig = storage.StoreOptions{}
- runtime.lockDir = lockDir
+ runtime.lockManager = lockManager
state, err := NewBoltState(dbPath, runtime)
if err != nil {
- return nil, "", "", err
+ return nil, "", nil, err
}
- return state, tmpDir, lockDir, nil
+ return state, tmpDir, lockManager, nil
}
// Get an empty in-memory state for use in tests
-func getEmptyInMemoryState() (s State, p string, p2 string, err error) {
+func getEmptyInMemoryState() (s State, p string, m lock.Manager, err error) {
tmpDir, err := ioutil.TempDir("", tmpDirPrefix)
if err != nil {
- return nil, "", "", err
+ return nil, "", nil, err
}
defer func() {
if err != nil {
@@ -76,17 +77,20 @@ func getEmptyInMemoryState() (s State, p string, p2 string, err error) {
state, err := NewInMemoryState()
if err != nil {
- return nil, "", "", err
+ return nil, "", nil, err
+ }
+
+ lockManager, err := lock.NewInMemoryManager(16)
+ if err != nil {
+ return nil, "", nil, err
}
- // Don't need a separate locks dir as InMemoryState stores nothing on
- // disk
- return state, tmpDir, tmpDir, nil
+ return state, tmpDir, lockManager, nil
}
-func runForAllStates(t *testing.T, testFunc func(*testing.T, State, string)) {
+func runForAllStates(t *testing.T, testFunc func(*testing.T, State, lock.Manager)) {
for stateName, stateFunc := range testedStates {
- state, path, lockPath, err := stateFunc()
+ state, path, manager, err := stateFunc()
if err != nil {
t.Fatalf("Error initializing state %s: %v", stateName, err)
}
@@ -94,7 +98,7 @@ func runForAllStates(t *testing.T, testFunc func(*testing.T, State, string)) {
defer state.Close()
success := t.Run(stateName, func(t *testing.T) {
- testFunc(t, state, lockPath)
+ testFunc(t, state, manager)
})
if !success {
t.Fail()
@@ -103,8 +107,8 @@ func runForAllStates(t *testing.T, testFunc func(*testing.T, State, string)) {
}
func TestAddAndGetContainer(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -118,10 +122,10 @@ func TestAddAndGetContainer(t *testing.T) {
}
func TestAddAndGetContainerFromMultiple(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr1)
@@ -138,8 +142,8 @@ func TestAddAndGetContainerFromMultiple(t *testing.T) {
}
func TestGetContainerPodSameIDFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -151,17 +155,17 @@ func TestGetContainerPodSameIDFails(t *testing.T) {
}
func TestAddInvalidContainerFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
err := state.AddContainer(&Container{config: &Config{ID: "1234"}})
assert.Error(t, err)
})
}
func TestAddDuplicateCtrIDFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestContainer(testCtr1.ID(), "test2", lockPath)
+ testCtr2, err := getTestContainer(testCtr1.ID(), "test2", manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr1)
@@ -177,10 +181,10 @@ func TestAddDuplicateCtrIDFails(t *testing.T) {
}
func TestAddDuplicateCtrNameFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestContainer(strings.Repeat("2", 32), testCtr1.Name(), lockPath)
+ testCtr2, err := getTestContainer(strings.Repeat("2", 32), testCtr1.Name(), manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr1)
@@ -196,10 +200,10 @@ func TestAddDuplicateCtrNameFails(t *testing.T) {
}
func TestAddCtrPodDupIDFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestContainer(testPod.ID(), "testCtr", lockPath)
+ testCtr, err := getTestContainer(testPod.ID(), "testCtr", manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -215,10 +219,10 @@ func TestAddCtrPodDupIDFails(t *testing.T) {
}
func TestAddCtrPodDupNameFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestContainer(strings.Repeat("2", 32), testPod.Name(), lockPath)
+ testCtr, err := getTestContainer(strings.Repeat("2", 32), testPod.Name(), manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -234,11 +238,11 @@ func TestAddCtrPodDupNameFails(t *testing.T) {
}
func TestAddCtrInPodFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -256,16 +260,16 @@ func TestAddCtrInPodFails(t *testing.T) {
}
func TestAddCtrDepInPodFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.UserNsCtr = testCtr1.ID()
@@ -288,10 +292,10 @@ func TestAddCtrDepInPodFails(t *testing.T) {
}
func TestAddCtrDepInSameNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr2.config.UserNsCtr = testCtr1.config.ID
@@ -312,10 +316,10 @@ func TestAddCtrDepInSameNamespaceSucceeds(t *testing.T) {
}
func TestAddCtrDepInDifferentNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr2.config.UserNsCtr = testCtr1.config.ID
@@ -338,8 +342,8 @@ func TestAddCtrDepInDifferentNamespaceFails(t *testing.T) {
}
func TestAddCtrSameNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -357,8 +361,8 @@ func TestAddCtrSameNamespaceSucceeds(t *testing.T) {
}
func TestAddCtrDifferentNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -377,22 +381,22 @@ func TestAddCtrDifferentNamespaceFails(t *testing.T) {
}
func TestGetNonexistentContainerFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.Container("does not exist")
assert.Error(t, err)
})
}
func TestGetContainerWithEmptyIDFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.Container("")
assert.Error(t, err)
})
}
func TestGetContainerInDifferentNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test2"
@@ -408,8 +412,8 @@ func TestGetContainerInDifferentNamespaceFails(t *testing.T) {
}
func TestGetContainerInSameNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -427,8 +431,8 @@ func TestGetContainerInSameNamespaceSucceeds(t *testing.T) {
}
func TestGetContainerInNamespaceWhileNotInNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -444,22 +448,22 @@ func TestGetContainerInNamespaceWhileNotInNamespaceSucceeds(t *testing.T) {
}
func TestLookupContainerWithEmptyIDFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.LookupContainer("")
assert.Error(t, err)
})
}
func TestLookupNonexistentContainerFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.LookupContainer("does not exist")
assert.Error(t, err)
})
}
func TestLookupContainerByFullID(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -473,8 +477,8 @@ func TestLookupContainerByFullID(t *testing.T) {
}
func TestLookupContainerByUniquePartialID(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -488,10 +492,10 @@ func TestLookupContainerByUniquePartialID(t *testing.T) {
}
func TestLookupContainerByNonUniquePartialIDFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestContainer(strings.Repeat("0", 32), "test1", lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestContainer(strings.Repeat("0", 32), "test1", manager)
assert.NoError(t, err)
- testCtr2, err := getTestContainer(strings.Repeat("0", 31)+"1", "test2", lockPath)
+ testCtr2, err := getTestContainer(strings.Repeat("0", 31)+"1", "test2", manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr1)
@@ -506,8 +510,8 @@ func TestLookupContainerByNonUniquePartialIDFails(t *testing.T) {
}
func TestLookupContainerByName(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -521,8 +525,8 @@ func TestLookupContainerByName(t *testing.T) {
}
func TestLookupCtrByPodNameFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -534,8 +538,8 @@ func TestLookupCtrByPodNameFails(t *testing.T) {
}
func TestLookupCtrByPodIDFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -547,8 +551,8 @@ func TestLookupCtrByPodIDFails(t *testing.T) {
}
func TestLookupCtrInSameNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -566,8 +570,8 @@ func TestLookupCtrInSameNamespaceSucceeds(t *testing.T) {
}
func TestLookupCtrInDifferentNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -583,11 +587,11 @@ func TestLookupCtrInDifferentNamespaceFails(t *testing.T) {
}
func TestLookupContainerMatchInDifferentNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestContainer(strings.Repeat("0", 32), "test1", lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestContainer(strings.Repeat("0", 32), "test1", manager)
assert.NoError(t, err)
testCtr1.config.Namespace = "test2"
- testCtr2, err := getTestContainer(strings.Repeat("0", 31)+"1", "test2", lockPath)
+ testCtr2, err := getTestContainer(strings.Repeat("0", 31)+"1", "test2", manager)
assert.NoError(t, err)
testCtr2.config.Namespace = "test1"
@@ -607,14 +611,14 @@ func TestLookupContainerMatchInDifferentNamespaceSucceeds(t *testing.T) {
}
func TestHasContainerEmptyIDFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.HasContainer("")
assert.Error(t, err)
})
}
func TestHasContainerNoSuchContainerReturnsFalse(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
exists, err := state.HasContainer("does not exist")
assert.NoError(t, err)
assert.False(t, exists)
@@ -622,8 +626,8 @@ func TestHasContainerNoSuchContainerReturnsFalse(t *testing.T) {
}
func TestHasContainerFindsContainer(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -636,8 +640,8 @@ func TestHasContainerFindsContainer(t *testing.T) {
}
func TestHasContainerPodIDIsFalse(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -650,8 +654,8 @@ func TestHasContainerPodIDIsFalse(t *testing.T) {
}
func TestHasContainerSameNamespaceIsTrue(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -668,8 +672,8 @@ func TestHasContainerSameNamespaceIsTrue(t *testing.T) {
}
func TestHasContainerDifferentNamespaceIsFalse(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -686,8 +690,8 @@ func TestHasContainerDifferentNamespaceIsFalse(t *testing.T) {
}
func TestSaveAndUpdateContainer(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -711,8 +715,8 @@ func TestSaveAndUpdateContainer(t *testing.T) {
}
func TestSaveAndUpdateContainerSameNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -740,8 +744,8 @@ func TestSaveAndUpdateContainerSameNamespaceSucceeds(t *testing.T) {
}
func TestUpdateContainerNotInDatabaseReturnsError(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.UpdateContainer(testCtr)
@@ -751,15 +755,15 @@ func TestUpdateContainerNotInDatabaseReturnsError(t *testing.T) {
}
func TestUpdateInvalidContainerReturnsError(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
err := state.UpdateContainer(&Container{config: &Config{ID: "1234"}})
assert.Error(t, err)
})
}
func TestUpdateContainerNotInNamespaceReturnsError(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -775,15 +779,15 @@ func TestUpdateContainerNotInNamespaceReturnsError(t *testing.T) {
}
func TestSaveInvalidContainerReturnsError(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
err := state.SaveContainer(&Container{config: &Config{ID: "1234"}})
assert.Error(t, err)
})
}
func TestSaveContainerNotInStateReturnsError(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.SaveContainer(testCtr)
@@ -793,8 +797,8 @@ func TestSaveContainerNotInStateReturnsError(t *testing.T) {
}
func TestSaveContainerNotInNamespaceReturnsError(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -810,8 +814,8 @@ func TestSaveContainerNotInNamespaceReturnsError(t *testing.T) {
}
func TestRemoveContainer(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -831,8 +835,8 @@ func TestRemoveContainer(t *testing.T) {
}
func TestRemoveNonexistantContainerFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.RemoveContainer(testCtr)
@@ -842,8 +846,8 @@ func TestRemoveNonexistantContainerFails(t *testing.T) {
}
func TestRemoveContainerNotInNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -869,7 +873,7 @@ func TestRemoveContainerNotInNamespaceFails(t *testing.T) {
}
func TestGetAllContainersOnNewStateIsEmpty(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
ctrs, err := state.AllContainers()
assert.NoError(t, err)
assert.Equal(t, 0, len(ctrs))
@@ -877,8 +881,8 @@ func TestGetAllContainersOnNewStateIsEmpty(t *testing.T) {
}
func TestGetAllContainersWithOneContainer(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -893,10 +897,10 @@ func TestGetAllContainersWithOneContainer(t *testing.T) {
}
func TestGetAllContainersTwoContainers(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr1)
@@ -912,8 +916,8 @@ func TestGetAllContainersTwoContainers(t *testing.T) {
}
func TestGetAllContainersNoContainerInNamespace(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -930,13 +934,13 @@ func TestGetAllContainersNoContainerInNamespace(t *testing.T) {
}
func TestGetContainerOneContainerInNamespace(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr1.config.Namespace = "test1"
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr1)
@@ -956,15 +960,15 @@ func TestGetContainerOneContainerInNamespace(t *testing.T) {
}
func TestContainerInUseInvalidContainer(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.ContainerInUse(&Container{})
assert.Error(t, err)
})
}
func TestContainerInUseCtrNotInState(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
_, err = state.ContainerInUse(testCtr)
assert.Error(t, err)
@@ -972,8 +976,8 @@ func TestContainerInUseCtrNotInState(t *testing.T) {
}
func TestContainerInUseCtrNotInNamespace(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -989,10 +993,10 @@ func TestContainerInUseCtrNotInNamespace(t *testing.T) {
}
func TestContainerInUseOneContainer(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr2.config.UserNsCtr = testCtr1.config.ID
@@ -1011,12 +1015,12 @@ func TestContainerInUseOneContainer(t *testing.T) {
}
func TestContainerInUseTwoContainers(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- testCtr3, err := getTestCtrN("3", lockPath)
+ testCtr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.UserNsCtr = testCtr1.config.ID
@@ -1038,10 +1042,10 @@ func TestContainerInUseTwoContainers(t *testing.T) {
}
func TestContainerInUseOneContainerMultipleDependencies(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr2.config.UserNsCtr = testCtr1.config.ID
@@ -1061,10 +1065,10 @@ func TestContainerInUseOneContainerMultipleDependencies(t *testing.T) {
}
func TestContainerInUseGenericDependency(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr2.config.Dependencies = []string{testCtr1.config.ID}
@@ -1083,12 +1087,12 @@ func TestContainerInUseGenericDependency(t *testing.T) {
}
func TestContainerInUseMultipleGenericDependencies(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
- testCtr3, err := getTestCtrN("3", lockPath)
+ testCtr3, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr3.config.Dependencies = []string{testCtr1.config.ID, testCtr2.config.ID}
@@ -1115,10 +1119,10 @@ func TestContainerInUseMultipleGenericDependencies(t *testing.T) {
}
func TestContainerInUseGenericAndNamespaceDependencies(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr2.config.Dependencies = []string{testCtr1.config.ID}
@@ -1138,10 +1142,10 @@ func TestContainerInUseGenericAndNamespaceDependencies(t *testing.T) {
}
func TestCannotRemoveContainerWithDependency(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr2.config.UserNsCtr = testCtr1.config.ID
@@ -1162,10 +1166,10 @@ func TestCannotRemoveContainerWithDependency(t *testing.T) {
}
func TestCannotRemoveContainerWithGenericDependency(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr2.config.Dependencies = []string{testCtr1.config.ID}
@@ -1186,10 +1190,10 @@ func TestCannotRemoveContainerWithGenericDependency(t *testing.T) {
}
func TestCanRemoveContainerAfterDependencyRemoved(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr2.config.UserNsCtr = testCtr1.ID()
@@ -1213,10 +1217,10 @@ func TestCanRemoveContainerAfterDependencyRemoved(t *testing.T) {
}
func TestCanRemoveContainerAfterDependencyRemovedDuplicate(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr1, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr1, err := getTestCtr1(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtr2(lockPath)
+ testCtr2, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr2.config.UserNsCtr = testCtr1.ID()
@@ -1241,11 +1245,11 @@ func TestCanRemoveContainerAfterDependencyRemovedDuplicate(t *testing.T) {
}
func TestCannotUsePodAsDependency(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
- testPod, err := getTestPod2(lockPath)
+ testPod, err := getTestPod2(manager)
assert.NoError(t, err)
testCtr.config.UserNsCtr = testPod.ID()
@@ -1263,8 +1267,8 @@ func TestCannotUsePodAsDependency(t *testing.T) {
}
func TestCannotUseBadIDAsDependency(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.UserNsCtr = strings.Repeat("5", 32)
@@ -1279,8 +1283,8 @@ func TestCannotUseBadIDAsDependency(t *testing.T) {
}
func TestCannotUseBadIDAsGenericDependency(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
testCtr.config.Dependencies = []string{strings.Repeat("5", 32)}
@@ -1295,22 +1299,22 @@ func TestCannotUseBadIDAsGenericDependency(t *testing.T) {
}
func TestGetPodDoesNotExist(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.Pod("doesnotexist")
assert.Error(t, err)
})
}
func TestGetPodEmptyID(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.Pod("")
assert.Error(t, err)
})
}
func TestGetPodOnePod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -1324,11 +1328,11 @@ func TestGetPodOnePod(t *testing.T) {
}
func TestGetOnePodFromTwo(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod1, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod1, err := getTestPod1(manager)
assert.NoError(t, err)
- testPod2, err := getTestPod2(lockPath)
+ testPod2, err := getTestPod2(manager)
assert.NoError(t, err)
err = state.AddPod(testPod1)
@@ -1345,11 +1349,11 @@ func TestGetOnePodFromTwo(t *testing.T) {
}
func TestGetNotExistPodWithPods(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod1, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod1, err := getTestPod1(manager)
assert.NoError(t, err)
- testPod2, err := getTestPod2(lockPath)
+ testPod2, err := getTestPod2(manager)
assert.NoError(t, err)
err = state.AddPod(testPod1)
@@ -1364,8 +1368,8 @@ func TestGetNotExistPodWithPods(t *testing.T) {
}
func TestGetPodByCtrID(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -1377,8 +1381,8 @@ func TestGetPodByCtrID(t *testing.T) {
}
func TestGetPodInNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -1396,8 +1400,8 @@ func TestGetPodInNamespaceSucceeds(t *testing.T) {
}
func TestGetPodPodNotInNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -1413,22 +1417,22 @@ func TestGetPodPodNotInNamespaceFails(t *testing.T) {
}
func TestLookupPodEmptyID(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.LookupPod("")
assert.Error(t, err)
})
}
func TestLookupNotExistPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.LookupPod("doesnotexist")
assert.Error(t, err)
})
}
func TestLookupPodFullID(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -1442,8 +1446,8 @@ func TestLookupPodFullID(t *testing.T) {
}
func TestLookupPodUniquePartialID(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -1457,11 +1461,11 @@ func TestLookupPodUniquePartialID(t *testing.T) {
}
func TestLookupPodNonUniquePartialID(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod1, err := getTestPod(strings.Repeat("1", 32), "test1", lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod1, err := getTestPod(strings.Repeat("1", 32), "test1", manager)
assert.NoError(t, err)
- testPod2, err := getTestPod(strings.Repeat("1", 31)+"2", "test2", lockPath)
+ testPod2, err := getTestPod(strings.Repeat("1", 31)+"2", "test2", manager)
assert.NoError(t, err)
err = state.AddPod(testPod1)
@@ -1476,8 +1480,8 @@ func TestLookupPodNonUniquePartialID(t *testing.T) {
}
func TestLookupPodByName(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -1491,8 +1495,8 @@ func TestLookupPodByName(t *testing.T) {
}
func TestLookupPodByCtrID(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -1504,8 +1508,8 @@ func TestLookupPodByCtrID(t *testing.T) {
}
func TestLookupPodByCtrName(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -1517,8 +1521,8 @@ func TestLookupPodByCtrName(t *testing.T) {
}
func TestLookupPodInSameNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -1536,8 +1540,8 @@ func TestLookupPodInSameNamespaceSucceeds(t *testing.T) {
}
func TestLookupPodInDifferentNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -1553,13 +1557,13 @@ func TestLookupPodInDifferentNamespaceFails(t *testing.T) {
}
func TestLookupPodOneInDifferentNamespaceFindsRightPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod1, err := getTestPod(strings.Repeat("1", 32), "test1", lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod1, err := getTestPod(strings.Repeat("1", 32), "test1", manager)
assert.NoError(t, err)
testPod1.config.Namespace = "test1"
- testPod2, err := getTestPod(strings.Repeat("1", 31)+"2", "test2", lockPath)
+ testPod2, err := getTestPod(strings.Repeat("1", 31)+"2", "test2", manager)
assert.NoError(t, err)
testPod2.config.Namespace = "test2"
@@ -1580,14 +1584,14 @@ func TestLookupPodOneInDifferentNamespaceFindsRightPod(t *testing.T) {
}
func TestHasPodEmptyIDErrors(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.HasPod("")
assert.Error(t, err)
})
}
func TestHasPodNoSuchPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
exist, err := state.HasPod("notexist")
assert.NoError(t, err)
assert.False(t, exist)
@@ -1595,8 +1599,8 @@ func TestHasPodNoSuchPod(t *testing.T) {
}
func TestHasPodWrongIDFalse(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -1609,8 +1613,8 @@ func TestHasPodWrongIDFalse(t *testing.T) {
}
func TestHasPodRightIDTrue(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -1623,8 +1627,8 @@ func TestHasPodRightIDTrue(t *testing.T) {
}
func TestHasPodCtrIDFalse(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -1637,8 +1641,8 @@ func TestHasPodCtrIDFalse(t *testing.T) {
}
func TestHasPodSameNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -1655,8 +1659,8 @@ func TestHasPodSameNamespaceSucceeds(t *testing.T) {
}
func TestHasPodDifferentNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -1673,15 +1677,15 @@ func TestHasPodDifferentNamespaceFails(t *testing.T) {
}
func TestAddPodInvalidPodErrors(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
err := state.AddPod(&Pod{config: &PodConfig{}})
assert.Error(t, err)
})
}
func TestAddPodValidPodSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -1696,11 +1700,11 @@ func TestAddPodValidPodSucceeds(t *testing.T) {
}
func TestAddPodDuplicateIDFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod1, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod1, err := getTestPod1(manager)
assert.NoError(t, err)
- testPod2, err := getTestPod(testPod1.ID(), "testpod2", lockPath)
+ testPod2, err := getTestPod(testPod1.ID(), "testpod2", manager)
assert.NoError(t, err)
err = state.AddPod(testPod1)
@@ -1716,11 +1720,11 @@ func TestAddPodDuplicateIDFails(t *testing.T) {
}
func TestAddPodDuplicateNameFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod1, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod1, err := getTestPod1(manager)
assert.NoError(t, err)
- testPod2, err := getTestPod(strings.Repeat("2", 32), testPod1.Name(), lockPath)
+ testPod2, err := getTestPod(strings.Repeat("2", 32), testPod1.Name(), manager)
assert.NoError(t, err)
err = state.AddPod(testPod1)
@@ -1736,11 +1740,11 @@ func TestAddPodDuplicateNameFails(t *testing.T) {
}
func TestAddPodNonDuplicateSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod1, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod1, err := getTestPod1(manager)
assert.NoError(t, err)
- testPod2, err := getTestPod2(lockPath)
+ testPod2, err := getTestPod2(manager)
assert.NoError(t, err)
err = state.AddPod(testPod1)
@@ -1756,11 +1760,11 @@ func TestAddPodNonDuplicateSucceeds(t *testing.T) {
}
func TestAddPodCtrIDConflictFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
- testPod, err := getTestPod(testCtr.ID(), "testpod1", lockPath)
+ testPod, err := getTestPod(testCtr.ID(), "testpod1", manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -1776,11 +1780,11 @@ func TestAddPodCtrIDConflictFails(t *testing.T) {
}
func TestAddPodCtrNameConflictFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
- testPod, err := getTestPod(strings.Repeat("3", 32), testCtr.Name(), lockPath)
+ testPod, err := getTestPod(strings.Repeat("3", 32), testCtr.Name(), manager)
assert.NoError(t, err)
err = state.AddContainer(testCtr)
@@ -1796,8 +1800,8 @@ func TestAddPodCtrNameConflictFails(t *testing.T) {
}
func TestAddPodSameNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -1816,8 +1820,8 @@ func TestAddPodSameNamespaceSucceeds(t *testing.T) {
}
func TestAddPodDifferentNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -1836,15 +1840,15 @@ func TestAddPodDifferentNamespaceFails(t *testing.T) {
}
func TestRemovePodInvalidPodErrors(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
err := state.RemovePod(&Pod{config: &PodConfig{}})
assert.Error(t, err)
})
}
func TestRemovePodNotInStateFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.RemovePod(testPod)
@@ -1854,8 +1858,8 @@ func TestRemovePodNotInStateFails(t *testing.T) {
}
func TestRemovePodSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -1871,11 +1875,11 @@ func TestRemovePodSucceeds(t *testing.T) {
}
func TestRemovePodFromPods(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod1, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod1, err := getTestPod1(manager)
assert.NoError(t, err)
- testPod2, err := getTestPod2(lockPath)
+ testPod2, err := getTestPod2(manager)
assert.NoError(t, err)
err = state.AddPod(testPod1)
@@ -1896,11 +1900,11 @@ func TestRemovePodFromPods(t *testing.T) {
}
func TestRemovePodNotEmptyFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -1920,11 +1924,11 @@ func TestRemovePodNotEmptyFails(t *testing.T) {
}
func TestRemovePodAfterEmptySucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -1947,8 +1951,8 @@ func TestRemovePodAfterEmptySucceeds(t *testing.T) {
}
func TestRemovePodNotInNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -1970,7 +1974,7 @@ func TestRemovePodNotInNamespaceFails(t *testing.T) {
}
func TestAllPodsEmptyOnEmptyState(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
allPods, err := state.AllPods()
assert.NoError(t, err)
assert.Equal(t, 0, len(allPods))
@@ -1978,8 +1982,8 @@ func TestAllPodsEmptyOnEmptyState(t *testing.T) {
}
func TestAllPodsFindsPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -1994,14 +1998,14 @@ func TestAllPodsFindsPod(t *testing.T) {
}
func TestAllPodsMultiplePods(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod1, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod1, err := getTestPod1(manager)
assert.NoError(t, err)
- testPod2, err := getTestPod2(lockPath)
+ testPod2, err := getTestPod2(manager)
assert.NoError(t, err)
- testPod3, err := getTestPodN("3", lockPath)
+ testPod3, err := getTestPodN("3", manager)
assert.NoError(t, err)
allPods1, err := state.AllPods()
@@ -2032,8 +2036,8 @@ func TestAllPodsMultiplePods(t *testing.T) {
}
func TestAllPodsPodInDifferentNamespaces(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -2050,13 +2054,13 @@ func TestAllPodsPodInDifferentNamespaces(t *testing.T) {
}
func TestAllPodsOnePodInDifferentNamespace(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod1, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod1, err := getTestPod1(manager)
assert.NoError(t, err)
testPod1.config.Namespace = "test1"
- testPod2, err := getTestPod2(lockPath)
+ testPod2, err := getTestPod2(manager)
assert.NoError(t, err)
testPod2.config.Namespace = "test2"
@@ -2078,15 +2082,15 @@ func TestAllPodsOnePodInDifferentNamespace(t *testing.T) {
}
func TestPodHasContainerNoSuchPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.PodHasContainer(&Pod{config: &PodConfig{}}, strings.Repeat("0", 32))
assert.Error(t, err)
})
}
func TestPodHasContainerEmptyCtrID(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -2098,8 +2102,8 @@ func TestPodHasContainerEmptyCtrID(t *testing.T) {
}
func TestPodHasContainerNoSuchCtr(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -2112,11 +2116,11 @@ func TestPodHasContainerNoSuchCtr(t *testing.T) {
}
func TestPodHasContainerCtrNotInPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -2132,11 +2136,11 @@ func TestPodHasContainerCtrNotInPod(t *testing.T) {
}
func TestPodHasContainerSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -2154,8 +2158,8 @@ func TestPodHasContainerSucceeds(t *testing.T) {
}
func TestPodHasContainerPodNotInNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -2171,15 +2175,15 @@ func TestPodHasContainerPodNotInNamespaceFails(t *testing.T) {
}
func TestPodContainersByIDInvalidPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.PodContainersByID(&Pod{config: &PodConfig{}})
assert.Error(t, err)
})
}
func TestPodContainerdByIDPodNotInState(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
_, err = state.PodContainersByID(testPod)
@@ -2189,8 +2193,8 @@ func TestPodContainerdByIDPodNotInState(t *testing.T) {
}
func TestPodContainersByIDEmptyPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -2203,11 +2207,11 @@ func TestPodContainersByIDEmptyPod(t *testing.T) {
}
func TestPodContainersByIDOneContainer(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -2226,19 +2230,19 @@ func TestPodContainersByIDOneContainer(t *testing.T) {
}
func TestPodContainersByIDMultipleContainers(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
- testCtr3, err := getTestCtrN("4", lockPath)
+ testCtr3, err := getTestCtrN("4", manager)
assert.NoError(t, err)
testCtr3.config.Pod = testPod.ID()
@@ -2273,8 +2277,8 @@ func TestPodContainersByIDMultipleContainers(t *testing.T) {
}
func TestPodContainerByIDPodNotInNamespace(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -2290,15 +2294,15 @@ func TestPodContainerByIDPodNotInNamespace(t *testing.T) {
}
func TestPodContainersInvalidPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
_, err := state.PodContainers(&Pod{config: &PodConfig{}})
assert.Error(t, err)
})
}
func TestPodContainersPodNotInState(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
_, err = state.PodContainers(testPod)
@@ -2308,8 +2312,8 @@ func TestPodContainersPodNotInState(t *testing.T) {
}
func TestPodContainersEmptyPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -2322,11 +2326,11 @@ func TestPodContainersEmptyPod(t *testing.T) {
}
func TestPodContainersOneContainer(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -2346,19 +2350,19 @@ func TestPodContainersOneContainer(t *testing.T) {
}
func TestPodContainersMultipleContainers(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
- testCtr3, err := getTestCtrN("4", lockPath)
+ testCtr3, err := getTestCtrN("4", manager)
assert.NoError(t, err)
testCtr3.config.Pod = testPod.ID()
@@ -2393,8 +2397,8 @@ func TestPodContainersMultipleContainers(t *testing.T) {
}
func TestPodContainersPodNotInNamespace(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -2410,15 +2414,15 @@ func TestPodContainersPodNotInNamespace(t *testing.T) {
}
func TestRemovePodContainersInvalidPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
err := state.RemovePodContainers(&Pod{config: &PodConfig{}})
assert.Error(t, err)
})
}
func TestRemovePodContainersPodNotInState(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.RemovePodContainers(testPod)
@@ -2428,8 +2432,8 @@ func TestRemovePodContainersPodNotInState(t *testing.T) {
}
func TestRemovePodContainersNoContainers(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -2445,11 +2449,11 @@ func TestRemovePodContainersNoContainers(t *testing.T) {
}
func TestRemovePodContainersOneContainer(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -2469,15 +2473,15 @@ func TestRemovePodContainersOneContainer(t *testing.T) {
}
func TestRemovePodContainersPreservesCtrOutsidePod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -2503,15 +2507,15 @@ func TestRemovePodContainersPreservesCtrOutsidePod(t *testing.T) {
}
func TestRemovePodContainersTwoContainers(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
@@ -2534,15 +2538,15 @@ func TestRemovePodContainersTwoContainers(t *testing.T) {
}
func TestRemovePodContainerDependencyInPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
testCtr2.config.IPCNsCtr = testCtr1.ID()
@@ -2566,8 +2570,8 @@ func TestRemovePodContainerDependencyInPod(t *testing.T) {
}
func TestRemoveContainersNotInNamespace(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -2583,8 +2587,8 @@ func TestRemoveContainersNotInNamespace(t *testing.T) {
}
func TestAddContainerToPodInvalidPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.AddContainerToPod(&Pod{config: &PodConfig{}}, testCtr)
@@ -2593,8 +2597,8 @@ func TestAddContainerToPodInvalidPod(t *testing.T) {
}
func TestAddContainerToPodInvalidCtr(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -2610,11 +2614,11 @@ func TestAddContainerToPodInvalidCtr(t *testing.T) {
}
func TestAddContainerToPodPodNotInState(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -2625,11 +2629,11 @@ func TestAddContainerToPodPodNotInState(t *testing.T) {
}
func TestAddContainerToPodSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -2653,15 +2657,15 @@ func TestAddContainerToPodSucceeds(t *testing.T) {
}
func TestAddContainerToPodTwoContainers(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
@@ -2685,15 +2689,15 @@ func TestAddContainerToPodTwoContainers(t *testing.T) {
}
func TestAddContainerToPodWithAddContainer(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -2718,14 +2722,14 @@ func TestAddContainerToPodWithAddContainer(t *testing.T) {
}
func TestAddContainerToPodCtrIDConflict(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
- testCtr2, err := getTestContainer(testCtr1.ID(), "testCtr3", lockPath)
+ testCtr2, err := getTestContainer(testCtr1.ID(), "testCtr3", manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
@@ -2749,14 +2753,14 @@ func TestAddContainerToPodCtrIDConflict(t *testing.T) {
}
func TestAddContainerToPodCtrNameConflict(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
- testCtr2, err := getTestContainer(strings.Repeat("4", 32), testCtr1.Name(), lockPath)
+ testCtr2, err := getTestContainer(strings.Repeat("4", 32), testCtr1.Name(), manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
@@ -2780,11 +2784,11 @@ func TestAddContainerToPodCtrNameConflict(t *testing.T) {
}
func TestAddContainerToPodPodIDConflict(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestContainer(testPod.ID(), "testCtr", lockPath)
+ testCtr, err := getTestContainer(testPod.ID(), "testCtr", manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -2805,11 +2809,11 @@ func TestAddContainerToPodPodIDConflict(t *testing.T) {
}
func TestAddContainerToPodPodNameConflict(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestContainer(strings.Repeat("2", 32), testPod.Name(), lockPath)
+ testCtr, err := getTestContainer(strings.Repeat("2", 32), testPod.Name(), manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -2830,15 +2834,15 @@ func TestAddContainerToPodPodNameConflict(t *testing.T) {
}
func TestAddContainerToPodAddsDependencies(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
testCtr2.config.IPCNsCtr = testCtr1.ID()
@@ -2860,11 +2864,11 @@ func TestAddContainerToPodAddsDependencies(t *testing.T) {
}
func TestAddContainerToPodPodDependencyFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
testCtr.config.IPCNsCtr = testPod.ID()
@@ -2882,11 +2886,11 @@ func TestAddContainerToPodPodDependencyFails(t *testing.T) {
}
func TestAddContainerToPodBadDependencyFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
testCtr.config.IPCNsCtr = strings.Repeat("8", 32)
@@ -2904,14 +2908,14 @@ func TestAddContainerToPodBadDependencyFails(t *testing.T) {
}
func TestAddContainerToPodDependencyOutsidePodFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
testCtr2.config.IPCNsCtr = testCtr1.ID()
@@ -2940,17 +2944,17 @@ func TestAddContainerToPodDependencyOutsidePodFails(t *testing.T) {
}
func TestAddContainerToPodDependencyInSameNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
testCtr1.config.Namespace = "test1"
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
testCtr2.config.IPCNsCtr = testCtr1.ID()
@@ -2973,17 +2977,17 @@ func TestAddContainerToPodDependencyInSameNamespaceSucceeds(t *testing.T) {
}
func TestAddContainerToPodDependencyInSeparateNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
testCtr1.config.Namespace = "test1"
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
testCtr2.config.IPCNsCtr = testCtr1.ID()
@@ -3013,12 +3017,12 @@ func TestAddContainerToPodDependencyInSeparateNamespaceFails(t *testing.T) {
}
func TestAddContainerToPodSameNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
testCtr.config.Pod = testPod.ID()
@@ -3037,12 +3041,12 @@ func TestAddContainerToPodSameNamespaceSucceeds(t *testing.T) {
}
func TestAddContainerToPodDifferentNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test2"
testCtr.config.Pod = testPod.ID()
@@ -3060,11 +3064,11 @@ func TestAddContainerToPodDifferentNamespaceFails(t *testing.T) {
}
func TestAddContainerToPodNamespaceOnCtrFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
testCtr.config.Pod = testPod.ID()
@@ -3082,12 +3086,12 @@ func TestAddContainerToPodNamespaceOnCtrFails(t *testing.T) {
}
func TestAddContainerToPodNamespaceOnPodFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -3104,11 +3108,11 @@ func TestAddContainerToPodNamespaceOnPodFails(t *testing.T) {
}
func TestAddCtrToPodSameNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
- testPod, err := getTestPod2(lockPath)
+ testPod, err := getTestPod2(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -3131,11 +3135,11 @@ func TestAddCtrToPodSameNamespaceSucceeds(t *testing.T) {
}
func TestAddCtrToPodDifferentNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
- testPod, err := getTestPod2(lockPath)
+ testPod, err := getTestPod2(manager)
assert.NoError(t, err)
testCtr.config.Namespace = "test1"
@@ -3159,8 +3163,8 @@ func TestAddCtrToPodDifferentNamespaceFails(t *testing.T) {
}
func TestRemoveContainerFromPodBadPodFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testCtr, err := getTestCtr1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testCtr, err := getTestCtr1(manager)
assert.NoError(t, err)
err = state.RemoveContainerFromPod(&Pod{config: &PodConfig{}}, testCtr)
@@ -3169,11 +3173,11 @@ func TestRemoveContainerFromPodBadPodFails(t *testing.T) {
}
func TestRemoveContainerFromPodPodNotInStateFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -3185,11 +3189,11 @@ func TestRemoveContainerFromPodPodNotInStateFails(t *testing.T) {
}
func TestRemoveContainerFromPodCtrNotInStateFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -3204,11 +3208,11 @@ func TestRemoveContainerFromPodCtrNotInStateFails(t *testing.T) {
}
func TestRemoveContainerFromPodCtrNotInPodFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -3229,11 +3233,11 @@ func TestRemoveContainerFromPodCtrNotInPodFails(t *testing.T) {
}
func TestRemoveContainerFromPodSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -3257,15 +3261,15 @@ func TestRemoveContainerFromPodSucceeds(t *testing.T) {
}
func TestRemoveContainerFromPodWithDependencyFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
testCtr2.config.IPCNsCtr = testCtr1.ID()
@@ -3293,15 +3297,15 @@ func TestRemoveContainerFromPodWithDependencyFails(t *testing.T) {
}
func TestRemoveContainerFromPodWithDependencySucceedsAfterDepRemoved(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
- testCtr1, err := getTestCtr2(lockPath)
+ testCtr1, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr1.config.Pod = testPod.ID()
- testCtr2, err := getTestCtrN("3", lockPath)
+ testCtr2, err := getTestCtrN("3", manager)
assert.NoError(t, err)
testCtr2.config.Pod = testPod.ID()
testCtr2.config.IPCNsCtr = testCtr1.ID()
@@ -3332,13 +3336,13 @@ func TestRemoveContainerFromPodWithDependencySucceedsAfterDepRemoved(t *testing.
}
func TestRemoveContainerFromPodSameNamespaceSucceeds(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -3366,13 +3370,13 @@ func TestRemoveContainerFromPodSameNamespaceSucceeds(t *testing.T) {
}
func TestRemoveContainerFromPodDifferentNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
- testCtr, err := getTestCtr2(lockPath)
+ testCtr, err := getTestCtr2(manager)
assert.NoError(t, err)
testCtr.config.Pod = testPod.ID()
@@ -3402,15 +3406,15 @@ func TestRemoveContainerFromPodDifferentNamespaceFails(t *testing.T) {
}
func TestUpdatePodInvalidPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
err := state.UpdatePod(&Pod{config: &PodConfig{}})
assert.Error(t, err)
})
}
func TestUpdatePodPodNotInStateFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.UpdatePod(testPod)
@@ -3419,8 +3423,8 @@ func TestUpdatePodPodNotInStateFails(t *testing.T) {
}
func TestUpdatePodNotInNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -3436,15 +3440,15 @@ func TestUpdatePodNotInNamespaceFails(t *testing.T) {
}
func TestSavePodInvalidPod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
err := state.SavePod(&Pod{config: &PodConfig{}})
assert.Error(t, err)
})
}
func TestSavePodPodNotInStateFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.SavePod(testPod)
@@ -3453,8 +3457,8 @@ func TestSavePodPodNotInStateFails(t *testing.T) {
}
func TestSavePodNotInNamespaceFails(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
@@ -3470,8 +3474,8 @@ func TestSavePodNotInNamespaceFails(t *testing.T) {
}
func TestSaveAndUpdatePod(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
err = state.AddPod(testPod)
@@ -3495,8 +3499,8 @@ func TestSaveAndUpdatePod(t *testing.T) {
}
func TestSaveAndUpdatePodSameNamespace(t *testing.T) {
- runForAllStates(t, func(t *testing.T, state State, lockPath string) {
- testPod, err := getTestPod1(lockPath)
+ runForAllStates(t, func(t *testing.T, state State, manager lock.Manager) {
+ testPod, err := getTestPod1(manager)
assert.NoError(t, err)
testPod.config.Namespace = "test1"
diff --git a/libpod/volume.go b/libpod/volume.go
index b732e8aa7..026a3bf49 100644
--- a/libpod/volume.go
+++ b/libpod/volume.go
@@ -1,6 +1,6 @@
package libpod
-import "github.com/containers/storage"
+import "github.com/containers/libpod/libpod/lock"
// Volume is the type used to create named volumes
// TODO: all volumes should be created using this and the Volume API
@@ -9,13 +9,17 @@ type Volume struct {
valid bool
runtime *Runtime
- lock storage.Locker
+ lock lock.Locker
}
// VolumeConfig holds the volume's config information
//easyjson:json
type VolumeConfig struct {
- Name string `json:"name"`
+ // Name of the volume
+ Name string `json:"name"`
+ // ID of this volume's lock
+ LockID uint32 `json:"lockID"`
+
Labels map[string]string `json:"labels"`
MountPoint string `json:"mountPoint"`
Driver string `json:"driver"`
diff --git a/pkg/spec/createconfig.go b/pkg/spec/createconfig.go
index 25f8cd7a1..ffc98e307 100644
--- a/pkg/spec/createconfig.go
+++ b/pkg/spec/createconfig.go
@@ -2,6 +2,7 @@ package createconfig
import (
"encoding/json"
+ "fmt"
"net"
"os"
"strconv"
@@ -145,6 +146,36 @@ func (c *CreateConfig) CreateBlockIO() (*spec.LinuxBlockIO, error) {
return c.createBlockIO()
}
+// AddContainerInitBinary adds the init binary specified by path iff the
+// container will run in a private PID namespace that is not shared with the
+// host or another pre-existing container, where an init-like process is
+// already running.
+//
+// Note that AddContainerInitBinary prepends "/dev/init" "--" to the command
+// to execute the bind-mounted binary as PID 1.
+func (c *CreateConfig) AddContainerInitBinary(path string) error {
+ if path == "" {
+ return fmt.Errorf("please specify a path to the container-init binary")
+ }
+ if !c.PidMode.IsPrivate() {
+ return fmt.Errorf("cannot add init binary as PID 1 (PID namespace isn't private)")
+ }
+ if c.Systemd {
+ return fmt.Errorf("cannot use container-init binary with systemd")
+ }
+ if _, err := os.Stat(path); os.IsNotExist(err) {
+ return errors.Wrap(err, "container-init binary not found on the host")
+ }
+ c.Command = append([]string{"/dev/init", "--"}, c.Command...)
+ c.Mounts = append(c.Mounts, spec.Mount{
+ Destination: "/dev/init",
+ Type: "bind",
+ Source: path,
+ Options: []string{"bind", "ro"},
+ })
+ return nil
+}
+
func processOptions(options []string) []string {
var (
foundrw, foundro bool
diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go
index cf366b197..a0b16a254 100644
--- a/test/e2e/run_test.go
+++ b/test/e2e/run_test.go
@@ -87,6 +87,18 @@ var _ = Describe("Podman run", func() {
Expect(session.ExitCode()).To(Equal(0))
})
+ It("podman run a container with --init", func() {
+ session := podmanTest.Podman([]string{"run", "--init", ALPINE, "ls"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ })
+
+ It("podman run a container with --init and --init-path", func() {
+ session := podmanTest.Podman([]string{"run", "--init", "--init-path", "/usr/libexec/podman/catatonit", ALPINE, "ls"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ })
+
It("podman run seccomp test", func() {
jsonFile := filepath.Join(podmanTest.TempDir, "seccomp.json")
in := []byte(`{"defaultAction":"SCMP_ACT_ALLOW","syscalls":[{"name":"getcwd","action":"SCMP_ACT_ERRNO"}]}`)
diff --git a/vendor.conf b/vendor.conf
index fd4968870..c215f8294 100644
--- a/vendor.conf
+++ b/vendor.conf
@@ -11,8 +11,8 @@ github.com/containerd/cgroups 58556f5ad8448d99a6f7bea69ea4bdb7747cfeb0
github.com/containerd/continuity master
github.com/containernetworking/cni v0.7.0-alpha1
github.com/containernetworking/plugins 1562a1e60ed101aacc5e08ed9dbeba8e9f3d4ec1
-github.com/containers/image d53afe179b381fafb427e6b9cf9b1996a98c1067
-github.com/containers/storage c044256cbfbae8a18cfc76319e11fcf4f98843b9
+github.com/containers/image f0cbc16b444d729362c78244c715b45bf4019b71
+github.com/containers/storage v1.4
github.com/containers/psgo dc0bc9fac5b715034c4310ed4d795b3182360842
github.com/coreos/go-systemd v14
github.com/cri-o/ocicni 2d2983e40c242322a56c22a903785e7f83eb378c
@@ -46,7 +46,7 @@ github.com/kr/pty v1.0.0
github.com/mattn/go-runewidth v0.0.1
github.com/mistifyio/go-zfs v2.1.1
github.com/mtrmac/gpgme b2432428689ca58c2b8e8dea9449d3295cf96fc9
-github.com/opencontainers/go-digest v1.0.0-rc0
+github.com/opencontainers/go-digest c9281466c8b2f606084ac71339773efd177436e7
github.com/opencontainers/image-spec v1.0.0
github.com/opencontainers/runc bbb17efcb4c0ab986407812a31ba333a7450064c
github.com/opencontainers/runtime-spec d810dbc60d8c5aeeb3d054bd1132fab2121968ce
@@ -78,7 +78,7 @@ golang.org/x/text f72d8390a633d5dfb0cc84043294db9f6c935756
golang.org/x/time f51c12702a4d776e4c1fa9b0fabab841babae631
golang.org/x/sync master
google.golang.org/grpc v1.0.4 https://github.com/grpc/grpc-go
-gopkg.in/cheggaaa/pb.v1 v1.0.7
+gopkg.in/cheggaaa/pb.v1 v1.0.27
gopkg.in/inf.v0 v0.9.0
gopkg.in/mgo.v2 v2
gopkg.in/square/go-jose.v2 v2.1.3
@@ -92,7 +92,7 @@ k8s.io/kube-openapi 275e2ce91dec4c05a4094a7b1daee5560b555ac9 https://github.com/
k8s.io/utils 258e2a2fa64568210fbd6267cf1d8fd87c3cb86e https://github.com/kubernetes/utils
github.com/mrunalp/fileutils master
github.com/varlink/go master
-github.com/containers/buildah dd0f4f1b1eb49b841179049ac498e4b0f874b462
+github.com/containers/buildah bb710f39d01868e47224f35f48a128fbea6539c4
github.com/Nvveen/Gotty master
github.com/fsouza/go-dockerclient master
github.com/openshift/imagebuilder master
diff --git a/vendor/github.com/containers/buildah/config.go b/vendor/github.com/containers/buildah/config.go
index 3609694f6..114b8ca37 100644
--- a/vendor/github.com/containers/buildah/config.go
+++ b/vendor/github.com/containers/buildah/config.go
@@ -474,9 +474,6 @@ func (b *Builder) Hostname() string {
// Note: this setting is not present in the OCIv1 image format, so it is
// discarded when writing images using OCIv1 formats.
func (b *Builder) SetHostname(name string) {
- if name != "" && b.Format != Dockerv2ImageManifest {
- logrus.Errorf("HOSTNAME is not supported for OCI image format, hostname %s will be ignored. Must use `docker` format", name)
- }
b.Docker.Config.Hostname = name
}
diff --git a/vendor/github.com/containers/buildah/image.go b/vendor/github.com/containers/buildah/image.go
index 163d34269..47842db7d 100644
--- a/vendor/github.com/containers/buildah/image.go
+++ b/vendor/github.com/containers/buildah/image.go
@@ -557,6 +557,10 @@ func (i *containerImageSource) LayerInfosForCopy(ctx context.Context) ([]types.B
return nil, nil
}
+func (i *containerImageSource) HasThreadSafeGetBlob() bool {
+ return false
+}
+
func (i *containerImageSource) GetBlob(ctx context.Context, blob types.BlobInfo, cache types.BlobInfoCache) (reader io.ReadCloser, size int64, err error) {
if blob.Digest == i.configDigest {
logrus.Debugf("start reading config")
diff --git a/vendor/github.com/containers/buildah/imagebuildah/build.go b/vendor/github.com/containers/buildah/imagebuildah/build.go
index 2681bc198..d838260e7 100644
--- a/vendor/github.com/containers/buildah/imagebuildah/build.go
+++ b/vendor/github.com/containers/buildah/imagebuildah/build.go
@@ -1307,7 +1307,12 @@ func (b *Executor) Build(ctx context.Context, stages imagebuilder.Stages) (strin
var imageRef reference.Canonical
imageID := ""
- if !b.layers && !b.noCache {
+
+ // Check if we have a one line Dockerfile making layers irrelevant
+ // or the user told us to ignore layers.
+ ignoreLayers := (len(stages) < 2 && len(stages[0].Node.Children) < 2) || (!b.layers && !b.noCache)
+
+ if ignoreLayers {
imgID, ref, err := stageExecutor.Commit(ctx, stages[len(stages)-1].Builder, "")
if err != nil {
return "", nil, err
diff --git a/vendor/github.com/containers/buildah/imagebuildah/chroot_symlink.go b/vendor/github.com/containers/buildah/imagebuildah/chroot_symlink.go
index edb5837db..6feedf6a5 100644
--- a/vendor/github.com/containers/buildah/imagebuildah/chroot_symlink.go
+++ b/vendor/github.com/containers/buildah/imagebuildah/chroot_symlink.go
@@ -131,6 +131,11 @@ func resolveModifiedTime(rootdir, filename, historyTime string) (bool, error) {
func modTimeIsGreater(rootdir, path string, historyTime string) (bool, error) {
var timeIsGreater bool
+ // the Walk below doesn't work if rootdir and path are equal
+ if rootdir == path {
+ return false, nil
+ }
+
// Convert historyTime from string to time.Time for comparison
histTime, err := time.Parse(time.RFC3339Nano, historyTime)
if err != nil {
diff --git a/vendor/github.com/containers/buildah/pkg/blobcache/blobcache.go b/vendor/github.com/containers/buildah/pkg/blobcache/blobcache.go
index 63022f15d..ae55316b0 100644
--- a/vendor/github.com/containers/buildah/pkg/blobcache/blobcache.go
+++ b/vendor/github.com/containers/buildah/pkg/blobcache/blobcache.go
@@ -218,6 +218,10 @@ func (s *blobCacheSource) GetManifest(ctx context.Context, instanceDigest *diges
return s.source.GetManifest(ctx, instanceDigest)
}
+func (s *blobCacheSource) HasThreadSafeGetBlob() bool {
+ return false
+}
+
func (s *blobCacheSource) GetBlob(ctx context.Context, blobinfo types.BlobInfo, cache types.BlobInfoCache) (io.ReadCloser, int64, error) {
present, size, err := s.reference.HasBlob(blobinfo)
if err != nil {
@@ -398,6 +402,10 @@ func saveStream(wg *sync.WaitGroup, decompressReader io.ReadCloser, tempFile *os
}
}
+func (s *blobCacheDestination) HasThreadSafePutBlob() bool {
+ return false
+}
+
func (d *blobCacheDestination) PutBlob(ctx context.Context, stream io.Reader, inputInfo types.BlobInfo, cache types.BlobInfoCache, isConfig bool) (types.BlobInfo, error) {
var tempfile *os.File
var err error
diff --git a/vendor/github.com/containers/buildah/pkg/cli/common.go b/vendor/github.com/containers/buildah/pkg/cli/common.go
index e3a4fe62a..dc1b2bc69 100644
--- a/vendor/github.com/containers/buildah/pkg/cli/common.go
+++ b/vendor/github.com/containers/buildah/pkg/cli/common.go
@@ -148,6 +148,10 @@ var (
Name: "loglevel",
Usage: "adjust logging level (range from -2 to 3)",
},
+ cli.StringFlag{
+ Name: "platform",
+ Usage: "CLI compatibility: no action or effect",
+ },
cli.BoolTFlag{
Name: "pull",
Usage: "pull the image if not present",
diff --git a/vendor/github.com/containers/buildah/run.go b/vendor/github.com/containers/buildah/run.go
index 5d2cd6a32..a0627f489 100644
--- a/vendor/github.com/containers/buildah/run.go
+++ b/vendor/github.com/containers/buildah/run.go
@@ -26,6 +26,7 @@ import (
"github.com/containers/storage/pkg/idtools"
"github.com/containers/storage/pkg/ioutils"
"github.com/containers/storage/pkg/reexec"
+ "github.com/containers/storage/pkg/stringid"
units "github.com/docker/go-units"
digest "github.com/opencontainers/go-digest"
"github.com/opencontainers/runtime-spec/specs-go"
@@ -944,10 +945,25 @@ func (b *Builder) configureNamespaces(g *generate.Generator, options RunOptions)
g.SetHostname(options.Hostname)
} else if b.Hostname() != "" {
g.SetHostname(b.Hostname())
+ } else {
+ g.SetHostname(stringid.TruncateID(b.ContainerID))
}
} else {
g.SetHostname("")
}
+
+ found := false
+ spec := g.Spec()
+ for i := range spec.Process.Env {
+ if strings.HasPrefix(spec.Process.Env[i], "HOSTNAME=") {
+ found = true
+ break
+ }
+ }
+ if !found {
+ spec.Process.Env = append(spec.Process.Env, fmt.Sprintf("HOSTNAME=%s", spec.Hostname))
+ }
+
return configureNetwork, configureNetworks, nil
}
diff --git a/vendor/github.com/containers/buildah/unshare/unshare.c b/vendor/github.com/containers/buildah/unshare/unshare.c
index 6873e49c2..3865e414f 100644
--- a/vendor/github.com/containers/buildah/unshare/unshare.c
+++ b/vendor/github.com/containers/buildah/unshare/unshare.c
@@ -79,7 +79,8 @@ void _buildah_unshare(void)
pidfd = _buildah_unshare_parse_envint("_Buildah-pid-pipe");
if (pidfd != -1) {
snprintf(buf, sizeof(buf), "%llu", (unsigned long long) getpid());
- if (write(pidfd, buf, strlen(buf)) != strlen(buf)) {
+ size_t size = write(pidfd, buf, strlen(buf));
+ if (size != strlen(buf)) {
fprintf(stderr, "Error writing PID to pipe on fd %d: %m\n", pidfd);
_exit(1);
}
diff --git a/vendor/github.com/containers/buildah/util/util.go b/vendor/github.com/containers/buildah/util/util.go
index 427c8db28..f4cac522e 100644
--- a/vendor/github.com/containers/buildah/util/util.go
+++ b/vendor/github.com/containers/buildah/util/util.go
@@ -395,57 +395,11 @@ func GetSubIDMappings(user, group string) ([]specs.LinuxIDMapping, []specs.Linux
// ParseIDMappings parses mapping triples.
func ParseIDMappings(uidmap, gidmap []string) ([]idtools.IDMap, []idtools.IDMap, error) {
- nonDigitsToWhitespace := func(r rune) rune {
- if strings.IndexRune("0123456789", r) == -1 {
- return ' '
- } else {
- return r
- }
- }
- parseTriple := func(spec []string) (container, host, size uint32, err error) {
- cid, err := strconv.ParseUint(spec[0], 10, 32)
- if err != nil {
- return 0, 0, 0, fmt.Errorf("error parsing id map value %q: %v", spec[0], err)
- }
- hid, err := strconv.ParseUint(spec[1], 10, 32)
- if err != nil {
- return 0, 0, 0, fmt.Errorf("error parsing id map value %q: %v", spec[1], err)
- }
- sz, err := strconv.ParseUint(spec[2], 10, 32)
- if err != nil {
- return 0, 0, 0, fmt.Errorf("error parsing id map value %q: %v", spec[2], err)
- }
- return uint32(cid), uint32(hid), uint32(sz), nil
- }
- parseIDMap := func(mapSpec []string, mapSetting string) (idmap []idtools.IDMap, err error) {
- for _, idMapSpec := range mapSpec {
- idSpec := strings.Fields(strings.Map(nonDigitsToWhitespace, idMapSpec))
- if len(idSpec)%3 != 0 {
- return nil, errors.Errorf("error initializing ID mappings: %s setting is malformed", mapSetting)
- }
- for i := range idSpec {
- if i%3 != 0 {
- continue
- }
- cid, hid, size, err := parseTriple(idSpec[i : i+3])
- if err != nil {
- return nil, errors.Errorf("error initializing ID mappings: %s setting is malformed", mapSetting)
- }
- mapping := idtools.IDMap{
- ContainerID: int(cid),
- HostID: int(hid),
- Size: int(size),
- }
- idmap = append(idmap, mapping)
- }
- }
- return idmap, nil
- }
- uid, err := parseIDMap(uidmap, "userns-uid-map")
+ uid, err := idtools.ParseIDMap(uidmap, "userns-uid-map")
if err != nil {
return nil, nil, err
}
- gid, err := parseIDMap(gidmap, "userns-gid-map")
+ gid, err := idtools.ParseIDMap(gidmap, "userns-gid-map")
if err != nil {
return nil, nil, err
}
diff --git a/vendor/github.com/containers/buildah/vendor.conf b/vendor/github.com/containers/buildah/vendor.conf
index 61325114c..ee8192935 100644
--- a/vendor/github.com/containers/buildah/vendor.conf
+++ b/vendor/github.com/containers/buildah/vendor.conf
@@ -3,10 +3,10 @@ github.com/blang/semver master
github.com/BurntSushi/toml master
github.com/containerd/continuity master
github.com/containernetworking/cni v0.7.0-alpha1
-github.com/containers/image d53afe179b381fafb427e6b9cf9b1996a98c1067
+github.com/containers/image 0c6cc8e1420001ae39fa89d308b3b3bc5ee81c57
github.com/boltdb/bolt master
-github.com/containers/libpod fe4f09493f41f675d24c969d1b60d1a6a45ddb9e
-github.com/containers/storage db40f96d853dfced60c563e61fb66ba231ce7c8d
+github.com/containers/libpod c8eaf59d5f4bec249db8134c6a9fcfbcac792519
+github.com/containers/storage 60a692f7ce891feb91ce0eda87bd06bfd5651dff
github.com/docker/distribution 5f6282db7d65e6d72ad7c2cc66310724a57be716
github.com/docker/docker 86f080cff0914e9694068ed78d503701667c4c00
github.com/docker/docker-credential-helpers d68f9aeca33f5fd3f08eeae5e9d175edf4e731d1
@@ -32,7 +32,7 @@ github.com/mistifyio/go-zfs master
github.com/moby/moby f8806b18b4b92c5e1980f6e11c917fad201cd73c
github.com/mtrmac/gpgme master
github.com/Nvveen/Gotty master
-github.com/opencontainers/go-digest aa2ec055abd10d26d539eb630a92241b781ce4bc
+github.com/opencontainers/go-digest c9281466c8b2f606084ac71339773efd177436e7
github.com/opencontainers/image-spec v1.0.0
github.com/opencontainers/runc master
github.com/opencontainers/runtime-spec v1.0.0
@@ -55,10 +55,14 @@ github.com/xeipuuv/gojsonreference master
github.com/xeipuuv/gojsonschema master
golang.org/x/crypto master
golang.org/x/net master
+golang.org/x/sync 42b317875d0fa942474b76e1b46a6060d720ae6e
golang.org/x/sys master
golang.org/x/text master
-gopkg.in/cheggaaa/pb.v1 v1.0.13
+gopkg.in/cheggaaa/pb.v1 v1.0.27
gopkg.in/yaml.v2 cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b
k8s.io/apimachinery master
k8s.io/client-go master
k8s.io/kubernetes master
+github.com/klauspost/pgzip v1.2.1
+github.com/klauspost/compress v1.4.1
+github.com/klauspost/cpuid v1.2.0
diff --git a/vendor/github.com/containers/image/copy/copy.go b/vendor/github.com/containers/image/copy/copy.go
index 013080e8d..89c7e580f 100644
--- a/vendor/github.com/containers/image/copy/copy.go
+++ b/vendor/github.com/containers/image/copy/copy.go
@@ -2,7 +2,6 @@ package copy
import (
"bytes"
- "compress/gzip"
"context"
"fmt"
"io"
@@ -10,6 +9,7 @@ import (
"reflect"
"runtime"
"strings"
+ "sync"
"time"
"github.com/containers/image/image"
@@ -18,9 +18,11 @@ import (
"github.com/containers/image/signature"
"github.com/containers/image/transports"
"github.com/containers/image/types"
+ "github.com/klauspost/pgzip"
"github.com/opencontainers/go-digest"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
+ "golang.org/x/sync/semaphore"
pb "gopkg.in/cheggaaa/pb.v1"
)
@@ -32,6 +34,10 @@ type digestingReader struct {
validationSucceeded bool
}
+// maxParallelDownloads is used to limit the maxmimum number of parallel
+// downloads. Let's follow Firefox by limiting it to 6.
+var maxParallelDownloads = 6
+
// newDigestingReader returns an io.Reader implementation with contents of source, which will eventually return a non-EOF error
// or set validationSucceeded/validationFailed to true if the source stream does/does not match expectedDigest.
// (neither is set if EOF is never reached).
@@ -81,6 +87,7 @@ type copier struct {
progressInterval time.Duration
progress chan types.ProgressProperties
blobInfoCache types.BlobInfoCache
+ copyInParallel bool
}
// imageCopier tracks state specific to a single image (possibly an item of a manifest list)
@@ -145,12 +152,14 @@ func Image(ctx context.Context, policyContext *signature.PolicyContext, destRef,
}
}()
+ copyInParallel := dest.HasThreadSafePutBlob() && rawSource.HasThreadSafeGetBlob()
c := &copier{
dest: dest,
rawSource: rawSource,
reportWriter: reportWriter,
progressInterval: options.ProgressInterval,
progress: options.Progress,
+ copyInParallel: copyInParallel,
// FIXME? The cache is used for sources and destinations equally, but we only have a SourceCtx and DestinationCtx.
// For now, use DestinationCtx (because blob reuse changes the behavior of the destination side more); eventually
// we might want to add a separate CommonCtx — or would that be too confusing?
@@ -380,11 +389,26 @@ func (ic *imageCopier) updateEmbeddedDockerReference() error {
return nil
}
+// shortDigest returns the first 12 characters of the digest.
+func shortDigest(d digest.Digest) string {
+ return d.Encoded()[:12]
+}
+
+// createProgressBar creates a pb.ProgressBar.
+func createProgressBar(srcInfo types.BlobInfo, kind string, writer io.Writer) *pb.ProgressBar {
+ bar := pb.New(int(srcInfo.Size)).SetUnits(pb.U_BYTES)
+ bar.SetMaxWidth(80)
+ bar.ShowTimeLeft = false
+ bar.ShowPercent = false
+ bar.Prefix(fmt.Sprintf("Copying %s %s:", kind, shortDigest(srcInfo.Digest)))
+ bar.Output = writer
+ return bar
+}
+
// copyLayers copies layers from ic.src/ic.c.rawSource to dest, using and updating ic.manifestUpdates if necessary and ic.canModifyManifest.
func (ic *imageCopier) copyLayers(ctx context.Context) error {
srcInfos := ic.src.LayerInfos()
- destInfos := []types.BlobInfo{}
- diffIDs := []digest.Digest{}
+ numLayers := len(srcInfos)
updatedSrcInfos, err := ic.src.LayerInfosForCopy(ctx)
if err != nil {
return err
@@ -397,30 +421,83 @@ func (ic *imageCopier) copyLayers(ctx context.Context) error {
srcInfos = updatedSrcInfos
srcInfosUpdated = true
}
- for _, srcLayer := range srcInfos {
- var (
- destInfo types.BlobInfo
- diffID digest.Digest
- err error
- )
+
+ type copyLayerData struct {
+ destInfo types.BlobInfo
+ diffID digest.Digest
+ err error
+ }
+
+ // copyGroup is used to determine if all layers are copied
+ copyGroup := sync.WaitGroup{}
+ copyGroup.Add(numLayers)
+ // copySemaphore is used to limit the number of parallel downloads to
+ // avoid malicious images causing troubles and to be nice to servers.
+ var copySemaphore *semaphore.Weighted
+ if ic.c.copyInParallel {
+ copySemaphore = semaphore.NewWeighted(int64(maxParallelDownloads))
+ } else {
+ copySemaphore = semaphore.NewWeighted(int64(1))
+ }
+
+ data := make([]copyLayerData, numLayers)
+ copyLayerHelper := func(index int, srcLayer types.BlobInfo, bar *pb.ProgressBar) {
+ defer bar.Finish()
+ defer copySemaphore.Release(1)
+ defer copyGroup.Done()
+ cld := copyLayerData{}
if ic.c.dest.AcceptsForeignLayerURLs() && len(srcLayer.URLs) != 0 {
// DiffIDs are, currently, needed only when converting from schema1.
// In which case src.LayerInfos will not have URLs because schema1
// does not support them.
if ic.diffIDsAreNeeded {
- return errors.New("getting DiffID for foreign layers is unimplemented")
+ cld.err = errors.New("getting DiffID for foreign layers is unimplemented")
+ bar.Prefix(fmt.Sprintf("Skipping blob %s (DiffID foreign layer unimplemented):", shortDigest(srcLayer.Digest)))
+ bar.Finish()
+ } else {
+ cld.destInfo = srcLayer
+ logrus.Debugf("Skipping foreign layer %q copy to %s\n", cld.destInfo.Digest, ic.c.dest.Reference().Transport().Name())
+ bar.Prefix(fmt.Sprintf("Skipping blob %s (foreign layer):", shortDigest(srcLayer.Digest)))
+ bar.Add64(bar.Total)
+ bar.Finish()
}
- destInfo = srcLayer
- ic.c.Printf("Skipping foreign layer %q copy to %s\n", destInfo.Digest, ic.c.dest.Reference().Transport().Name())
} else {
- destInfo, diffID, err = ic.copyLayer(ctx, srcLayer)
- if err != nil {
- return err
- }
+ cld.destInfo, cld.diffID, cld.err = ic.copyLayer(ctx, srcLayer, bar)
}
- destInfos = append(destInfos, destInfo)
- diffIDs = append(diffIDs, diffID)
+ data[index] = cld
}
+
+ progressBars := make([]*pb.ProgressBar, numLayers)
+ for i, srcInfo := range srcInfos {
+ bar := createProgressBar(srcInfo, "blob", nil)
+ progressBars[i] = bar
+ }
+
+ progressPool := pb.NewPool(progressBars...)
+ progressPool.Output = ic.c.reportWriter
+ if err := progressPool.Start(); err != nil {
+ return errors.Wrapf(err, "error creating progress-bar pool")
+ }
+
+ for i, srcLayer := range srcInfos {
+ copySemaphore.Acquire(ctx, 1)
+ go copyLayerHelper(i, srcLayer, progressBars[i])
+ }
+
+ destInfos := make([]types.BlobInfo, numLayers)
+ diffIDs := make([]digest.Digest, numLayers)
+
+ copyGroup.Wait()
+ progressPool.Stop()
+
+ for i, cld := range data {
+ if cld.err != nil {
+ return cld.err
+ }
+ destInfos[i] = cld.destInfo
+ diffIDs[i] = cld.diffID
+ }
+
ic.manifestUpdates.InformationOnly.LayerInfos = destInfos
if ic.diffIDsAreNeeded {
ic.manifestUpdates.InformationOnly.LayerDiffIDs = diffIDs
@@ -487,12 +564,14 @@ func (ic *imageCopier) copyUpdatedConfigAndManifest(ctx context.Context) ([]byte
func (c *copier) copyConfig(ctx context.Context, src types.Image) error {
srcInfo := src.ConfigInfo()
if srcInfo.Digest != "" {
- c.Printf("Copying config %s\n", srcInfo.Digest)
configBlob, err := src.ConfigBlob(ctx)
if err != nil {
return errors.Wrapf(err, "Error reading config blob %s", srcInfo.Digest)
}
- destInfo, err := c.copyBlobFromStream(ctx, bytes.NewReader(configBlob), srcInfo, nil, false, true)
+ bar := createProgressBar(srcInfo, "config", c.reportWriter)
+ defer bar.Finish()
+ bar.Start()
+ destInfo, err := c.copyBlobFromStream(ctx, bytes.NewReader(configBlob), srcInfo, nil, false, true, bar)
if err != nil {
return err
}
@@ -512,7 +591,7 @@ type diffIDResult struct {
// copyLayer copies a layer with srcInfo (with known Digest and possibly known Size) in src to dest, perhaps compressing it if canCompress,
// and returns a complete blobInfo of the copied layer, and a value for LayerDiffIDs if diffIDIsNeeded
-func (ic *imageCopier) copyLayer(ctx context.Context, srcInfo types.BlobInfo) (types.BlobInfo, digest.Digest, error) {
+func (ic *imageCopier) copyLayer(ctx context.Context, srcInfo types.BlobInfo, bar *pb.ProgressBar) (types.BlobInfo, digest.Digest, error) {
cachedDiffID := ic.c.blobInfoCache.UncompressedDigest(srcInfo.Digest) // May be ""
diffIDIsNeeded := ic.diffIDsAreNeeded && cachedDiffID == ""
@@ -523,13 +602,14 @@ func (ic *imageCopier) copyLayer(ctx context.Context, srcInfo types.BlobInfo) (t
return types.BlobInfo{}, "", errors.Wrapf(err, "Error trying to reuse blob %s at destination", srcInfo.Digest)
}
if reused {
- ic.c.Printf("Skipping fetch of repeat blob %s\n", srcInfo.Digest)
+ bar.Prefix(fmt.Sprintf("Skipping blob %s (already present):", shortDigest(srcInfo.Digest)))
+ bar.Add64(bar.Total)
+ bar.Finish()
return blobInfo, cachedDiffID, nil
}
}
// Fallback: copy the layer, computing the diffID if we need to do so
- ic.c.Printf("Copying blob %s\n", srcInfo.Digest)
srcStream, srcBlobSize, err := ic.c.rawSource.GetBlob(ctx, srcInfo, ic.c.blobInfoCache)
if err != nil {
return types.BlobInfo{}, "", errors.Wrapf(err, "Error reading blob %s", srcInfo.Digest)
@@ -537,7 +617,7 @@ func (ic *imageCopier) copyLayer(ctx context.Context, srcInfo types.BlobInfo) (t
defer srcStream.Close()
blobInfo, diffIDChan, err := ic.copyLayerFromStream(ctx, srcStream, types.BlobInfo{Digest: srcInfo.Digest, Size: srcBlobSize},
- diffIDIsNeeded)
+ diffIDIsNeeded, bar)
if err != nil {
return types.BlobInfo{}, "", err
}
@@ -565,7 +645,7 @@ func (ic *imageCopier) copyLayer(ctx context.Context, srcInfo types.BlobInfo) (t
// perhaps compressing the stream if canCompress,
// and returns a complete blobInfo of the copied blob and perhaps a <-chan diffIDResult if diffIDIsNeeded, to be read by the caller.
func (ic *imageCopier) copyLayerFromStream(ctx context.Context, srcStream io.Reader, srcInfo types.BlobInfo,
- diffIDIsNeeded bool) (types.BlobInfo, <-chan diffIDResult, error) {
+ diffIDIsNeeded bool, bar *pb.ProgressBar) (types.BlobInfo, <-chan diffIDResult, error) {
var getDiffIDRecorder func(compression.DecompressorFunc) io.Writer // = nil
var diffIDChan chan diffIDResult
@@ -589,7 +669,7 @@ func (ic *imageCopier) copyLayerFromStream(ctx context.Context, srcStream io.Rea
return pipeWriter
}
}
- blobInfo, err := ic.c.copyBlobFromStream(ctx, srcStream, srcInfo, getDiffIDRecorder, ic.canModifyManifest, false) // Sets err to nil on success
+ blobInfo, err := ic.c.copyBlobFromStream(ctx, srcStream, srcInfo, getDiffIDRecorder, ic.canModifyManifest, false, bar) // Sets err to nil on success
return blobInfo, diffIDChan, err
// We need the defer … pipeWriter.CloseWithError() to happen HERE so that the caller can block on reading from diffIDChan
}
@@ -626,7 +706,7 @@ func computeDiffID(stream io.Reader, decompressor compression.DecompressorFunc)
// and returns a complete blobInfo of the copied blob.
func (c *copier) copyBlobFromStream(ctx context.Context, srcStream io.Reader, srcInfo types.BlobInfo,
getOriginalLayerCopyWriter func(decompressor compression.DecompressorFunc) io.Writer,
- canModifyBlob bool, isConfig bool) (types.BlobInfo, error) {
+ canModifyBlob bool, isConfig bool, bar *pb.ProgressBar) (types.BlobInfo, error) {
// The copying happens through a pipeline of connected io.Readers.
// === Input: srcStream
@@ -649,16 +729,7 @@ func (c *copier) copyBlobFromStream(ctx context.Context, srcStream io.Reader, sr
return types.BlobInfo{}, errors.Wrapf(err, "Error reading blob %s", srcInfo.Digest)
}
isCompressed := decompressor != nil
-
- // === Report progress using a pb.Reader.
- bar := pb.New(int(srcInfo.Size)).SetUnits(pb.U_BYTES)
- bar.Output = c.reportWriter
- bar.SetMaxWidth(80)
- bar.ShowTimeLeft = false
- bar.ShowPercent = false
- bar.Start()
destStream = bar.NewProxyReader(destStream)
- defer bar.Finish()
// === Send a copy of the original, uncompressed, stream, to a separate path if necessary.
var originalLayerReader io.Reader // DO NOT USE this other than to drain the input if no other consumer in the pipeline has done so.
@@ -761,7 +832,7 @@ func compressGoroutine(dest *io.PipeWriter, src io.Reader) {
dest.CloseWithError(err) // CloseWithError(nil) is equivalent to Close()
}()
- zipper := gzip.NewWriter(dest)
+ zipper := pgzip.NewWriter(dest)
defer zipper.Close()
_, err = io.Copy(zipper, src) // Sets err to nil, i.e. causes dest.Close()
diff --git a/vendor/github.com/containers/image/directory/directory_dest.go b/vendor/github.com/containers/image/directory/directory_dest.go
index d75c195b2..4b2ab022e 100644
--- a/vendor/github.com/containers/image/directory/directory_dest.go
+++ b/vendor/github.com/containers/image/directory/directory_dest.go
@@ -124,6 +124,11 @@ func (d *dirImageDestination) IgnoresEmbeddedDockerReference() bool {
return false // N/A, DockerReference() returns nil.
}
+// HasThreadSafePutBlob indicates whether PutBlob can be executed concurrently.
+func (d *dirImageDestination) HasThreadSafePutBlob() bool {
+ return false
+}
+
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
// inputInfo.Size is the expected length of stream, if known.
diff --git a/vendor/github.com/containers/image/directory/directory_src.go b/vendor/github.com/containers/image/directory/directory_src.go
index 3625def80..59b625397 100644
--- a/vendor/github.com/containers/image/directory/directory_src.go
+++ b/vendor/github.com/containers/image/directory/directory_src.go
@@ -48,6 +48,11 @@ func (s *dirImageSource) GetManifest(ctx context.Context, instanceDigest *digest
return m, manifest.GuessMIMEType(m), err
}
+// HasThreadSafeGetBlob indicates whether GetBlob can be executed concurrently.
+func (s *dirImageSource) HasThreadSafeGetBlob() bool {
+ return false
+}
+
// GetBlob returns a stream for the specified blob, and the blob’s size (or -1 if unknown).
// The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided.
// May update BlobInfoCache, preferably after it knows for certain that a blob truly exists at a specific location.
diff --git a/vendor/github.com/containers/image/docker/docker_client.go b/vendor/github.com/containers/image/docker/docker_client.go
index 7f55dbe7f..23d2ac70f 100644
--- a/vendor/github.com/containers/image/docker/docker_client.go
+++ b/vendor/github.com/containers/image/docker/docker_client.go
@@ -13,6 +13,7 @@ import (
"path/filepath"
"strconv"
"strings"
+ "sync"
"time"
"github.com/containers/image/docker/reference"
@@ -84,6 +85,7 @@ type dockerClient struct {
registry string
client *http.Client
insecureSkipTLSVerify bool
+
// The following members are not set by newDockerClient and must be set by callers if needed.
username string
password string
@@ -95,8 +97,13 @@ type dockerClient struct {
scheme string // Empty value also used to indicate detectProperties() has not yet succeeded.
challenges []challenge
supportsSignatures bool
- // Private state for setupRequestAuth
- tokenCache map[string]bearerToken
+
+ // Private state for setupRequestAuth (key: string, value: bearerToken)
+ tokenCache sync.Map
+ // detectPropertiesError caches the initial error.
+ detectPropertiesError error
+ // detectPropertiesOnce is used to execuute detectProperties() at most once in in makeRequest().
+ detectPropertiesOnce sync.Once
}
type authScope struct {
@@ -262,7 +269,6 @@ func newDockerClient(sys *types.SystemContext, registry, reference string) (*doc
registry: registry,
client: &http.Client{Transport: tr},
insecureSkipTLSVerify: skipVerify,
- tokenCache: map[string]bearerToken{},
}, nil
}
@@ -473,14 +479,18 @@ func (c *dockerClient) setupRequestAuth(req *http.Request) error {
cacheKey = fmt.Sprintf("%s:%s", c.extraScope.remoteName, c.extraScope.actions)
scopes = append(scopes, *c.extraScope)
}
- token, ok := c.tokenCache[cacheKey]
- if !ok || time.Now().After(token.expirationTime) {
+ var token bearerToken
+ t, inCache := c.tokenCache.Load(cacheKey)
+ if inCache {
+ token = t.(bearerToken)
+ }
+ if !inCache || time.Now().After(token.expirationTime) {
t, err := c.getBearerToken(req.Context(), challenge, scopes)
if err != nil {
return err
}
token = *t
- c.tokenCache[cacheKey] = token
+ c.tokenCache.Store(cacheKey, token)
}
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token.Token))
return nil
@@ -545,9 +555,9 @@ func (c *dockerClient) getBearerToken(ctx context.Context, challenge challenge,
return newBearerTokenFromJSONBlob(tokenBlob)
}
-// detectProperties detects various properties of the registry.
-// See the dockerClient documentation for members which are affected by this.
-func (c *dockerClient) detectProperties(ctx context.Context) error {
+// detectPropertiesHelper performs the work of detectProperties which executes
+// it at most once.
+func (c *dockerClient) detectPropertiesHelper(ctx context.Context) error {
if c.scheme != "" {
return nil
}
@@ -604,6 +614,13 @@ func (c *dockerClient) detectProperties(ctx context.Context) error {
return err
}
+// detectProperties detects various properties of the registry.
+// See the dockerClient documentation for members which are affected by this.
+func (c *dockerClient) detectProperties(ctx context.Context) error {
+ c.detectPropertiesOnce.Do(func() { c.detectPropertiesError = c.detectPropertiesHelper(ctx) })
+ return c.detectPropertiesError
+}
+
// getExtensionsSignatures returns signatures from the X-Registry-Supports-Signatures API extension,
// using the original data structures.
func (c *dockerClient) getExtensionsSignatures(ctx context.Context, ref dockerReference, manifestDigest digest.Digest) (*extensionSignatureList, error) {
diff --git a/vendor/github.com/containers/image/docker/docker_image_dest.go b/vendor/github.com/containers/image/docker/docker_image_dest.go
index 2f471f648..973d160d0 100644
--- a/vendor/github.com/containers/image/docker/docker_image_dest.go
+++ b/vendor/github.com/containers/image/docker/docker_image_dest.go
@@ -111,6 +111,11 @@ func (c *sizeCounter) Write(p []byte) (n int, err error) {
return len(p), nil
}
+// HasThreadSafePutBlob indicates whether PutBlob can be executed concurrently.
+func (d *dockerImageDestination) HasThreadSafePutBlob() bool {
+ return false
+}
+
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
// inputInfo.Size is the expected length of stream, if known.
diff --git a/vendor/github.com/containers/image/docker/docker_image_src.go b/vendor/github.com/containers/image/docker/docker_image_src.go
index fbed6297f..c88ff2f34 100644
--- a/vendor/github.com/containers/image/docker/docker_image_src.go
+++ b/vendor/github.com/containers/image/docker/docker_image_src.go
@@ -161,6 +161,11 @@ func getBlobSize(resp *http.Response) int64 {
return size
}
+// HasThreadSafeGetBlob indicates whether GetBlob can be executed concurrently.
+func (s *dockerImageSource) HasThreadSafeGetBlob() bool {
+ return true
+}
+
// GetBlob returns a stream for the specified blob, and the blob’s size (or -1 if unknown).
// The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided.
// May update BlobInfoCache, preferably after it knows for certain that a blob truly exists at a specific location.
diff --git a/vendor/github.com/containers/image/docker/tarfile/dest.go b/vendor/github.com/containers/image/docker/tarfile/dest.go
index ad8a48a03..5f30eddbc 100644
--- a/vendor/github.com/containers/image/docker/tarfile/dest.go
+++ b/vendor/github.com/containers/image/docker/tarfile/dest.go
@@ -82,6 +82,11 @@ func (d *Destination) IgnoresEmbeddedDockerReference() bool {
return false // N/A, we only accept schema2 images where EmbeddedDockerReferenceConflicts() is always false.
}
+// HasThreadSafePutBlob indicates whether PutBlob can be executed concurrently.
+func (d *Destination) HasThreadSafePutBlob() bool {
+ return false
+}
+
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
// inputInfo.Size is the expected length of stream, if known.
diff --git a/vendor/github.com/containers/image/docker/tarfile/src.go b/vendor/github.com/containers/image/docker/tarfile/src.go
index d94ed9783..889e5f8e8 100644
--- a/vendor/github.com/containers/image/docker/tarfile/src.go
+++ b/vendor/github.com/containers/image/docker/tarfile/src.go
@@ -397,6 +397,11 @@ func (r uncompressedReadCloser) Close() error {
return res
}
+// HasThreadSafeGetBlob indicates whether GetBlob can be executed concurrently.
+func (s *Source) HasThreadSafeGetBlob() bool {
+ return false
+}
+
// GetBlob returns a stream for the specified blob, and the blob’s size (or -1 if unknown).
// The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided.
// May update BlobInfoCache, preferably after it knows for certain that a blob truly exists at a specific location.
diff --git a/vendor/github.com/containers/image/oci/archive/oci_dest.go b/vendor/github.com/containers/image/oci/archive/oci_dest.go
index 3997ac2ee..9571c37e2 100644
--- a/vendor/github.com/containers/image/oci/archive/oci_dest.go
+++ b/vendor/github.com/containers/image/oci/archive/oci_dest.go
@@ -77,6 +77,11 @@ func (d *ociArchiveImageDestination) IgnoresEmbeddedDockerReference() bool {
return d.unpackedDest.IgnoresEmbeddedDockerReference()
}
+// HasThreadSafePutBlob indicates whether PutBlob can be executed concurrently.
+func (d *ociArchiveImageDestination) HasThreadSafePutBlob() bool {
+ return false
+}
+
// PutBlob writes contents of stream and returns data representing the result.
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
// inputInfo.Size is the expected length of stream, if known.
diff --git a/vendor/github.com/containers/image/oci/archive/oci_src.go b/vendor/github.com/containers/image/oci/archive/oci_src.go
index 084d818f7..ca74f950b 100644
--- a/vendor/github.com/containers/image/oci/archive/oci_src.go
+++ b/vendor/github.com/containers/image/oci/archive/oci_src.go
@@ -76,6 +76,11 @@ func (s *ociArchiveImageSource) GetManifest(ctx context.Context, instanceDigest
return s.unpackedSrc.GetManifest(ctx, instanceDigest)
}
+// HasThreadSafeGetBlob indicates whether GetBlob can be executed concurrently.
+func (s *ociArchiveImageSource) HasThreadSafeGetBlob() bool {
+ return false
+}
+
// GetBlob returns a stream for the specified blob, and the blob’s size (or -1 if unknown).
// The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided.
// May update BlobInfoCache, preferably after it knows for certain that a blob truly exists at a specific location.
diff --git a/vendor/github.com/containers/image/oci/layout/oci_dest.go b/vendor/github.com/containers/image/oci/layout/oci_dest.go
index b5a6e08f8..db102184d 100644
--- a/vendor/github.com/containers/image/oci/layout/oci_dest.go
+++ b/vendor/github.com/containers/image/oci/layout/oci_dest.go
@@ -107,6 +107,11 @@ func (d *ociImageDestination) IgnoresEmbeddedDockerReference() bool {
return false // N/A, DockerReference() returns nil.
}
+// HasThreadSafePutBlob indicates whether PutBlob can be executed concurrently.
+func (d *ociImageDestination) HasThreadSafePutBlob() bool {
+ return false
+}
+
// PutBlob writes contents of stream and returns data representing the result.
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
// inputInfo.Size is the expected length of stream, if known.
diff --git a/vendor/github.com/containers/image/oci/layout/oci_src.go b/vendor/github.com/containers/image/oci/layout/oci_src.go
index 086a7040d..cc536f69e 100644
--- a/vendor/github.com/containers/image/oci/layout/oci_src.go
+++ b/vendor/github.com/containers/image/oci/layout/oci_src.go
@@ -92,6 +92,11 @@ func (s *ociImageSource) GetManifest(ctx context.Context, instanceDigest *digest
return m, mimeType, nil
}
+// HasThreadSafeGetBlob indicates whether GetBlob can be executed concurrently.
+func (s *ociImageSource) HasThreadSafeGetBlob() bool {
+ return false
+}
+
// GetBlob returns a stream for the specified blob, and the blob’s size (or -1 if unknown).
// The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided.
// May update BlobInfoCache, preferably after it knows for certain that a blob truly exists at a specific location.
diff --git a/vendor/github.com/containers/image/openshift/openshift.go b/vendor/github.com/containers/image/openshift/openshift.go
index 0cce1e6c7..814c3eea1 100644
--- a/vendor/github.com/containers/image/openshift/openshift.go
+++ b/vendor/github.com/containers/image/openshift/openshift.go
@@ -211,6 +211,11 @@ func (s *openshiftImageSource) GetManifest(ctx context.Context, instanceDigest *
return s.docker.GetManifest(ctx, instanceDigest)
}
+// HasThreadSafeGetBlob indicates whether GetBlob can be executed concurrently.
+func (s *openshiftImageSource) HasThreadSafeGetBlob() bool {
+ return false
+}
+
// GetBlob returns a stream for the specified blob, and the blob’s size (or -1 if unknown).
// The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided.
// May update BlobInfoCache, preferably after it knows for certain that a blob truly exists at a specific location.
@@ -378,6 +383,11 @@ func (d *openshiftImageDestination) IgnoresEmbeddedDockerReference() bool {
return d.docker.IgnoresEmbeddedDockerReference()
}
+// HasThreadSafePutBlob indicates whether PutBlob can be executed concurrently.
+func (d *openshiftImageDestination) HasThreadSafePutBlob() bool {
+ return false
+}
+
// PutBlob writes contents of stream and returns data representing the result (with all data filled in).
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
// inputInfo.Size is the expected length of stream, if known.
diff --git a/vendor/github.com/containers/image/ostree/ostree_dest.go b/vendor/github.com/containers/image/ostree/ostree_dest.go
index 064898948..d69f4fa33 100644
--- a/vendor/github.com/containers/image/ostree/ostree_dest.go
+++ b/vendor/github.com/containers/image/ostree/ostree_dest.go
@@ -4,7 +4,6 @@ package ostree
import (
"bytes"
- "compress/gzip"
"context"
"encoding/base64"
"encoding/json"
@@ -24,6 +23,7 @@ import (
"github.com/containers/image/manifest"
"github.com/containers/image/types"
"github.com/containers/storage/pkg/archive"
+ "github.com/klauspost/pgzip"
"github.com/opencontainers/go-digest"
selinux "github.com/opencontainers/selinux/go-selinux"
"github.com/ostreedev/ostree-go/pkg/otbuiltin"
@@ -132,6 +132,11 @@ func (d *ostreeImageDestination) IgnoresEmbeddedDockerReference() bool {
return false // N/A, DockerReference() returns nil.
}
+// HasThreadSafePutBlob indicates whether PutBlob can be executed concurrently.
+func (d *ostreeImageDestination) HasThreadSafePutBlob() bool {
+ return false
+}
+
// PutBlob writes contents of stream and returns data representing the result.
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
// inputInfo.Size is the expected length of stream, if known.
@@ -249,7 +254,7 @@ func (d *ostreeImageDestination) ostreeCommit(repo *otbuiltin.Repo, branch strin
}
func generateTarSplitMetadata(output *bytes.Buffer, file string) (digest.Digest, int64, error) {
- mfz := gzip.NewWriter(output)
+ mfz := pgzip.NewWriter(output)
defer mfz.Close()
metaPacker := storage.NewJSONPacker(mfz)
diff --git a/vendor/github.com/containers/image/ostree/ostree_src.go b/vendor/github.com/containers/image/ostree/ostree_src.go
index e73cae198..df432c9f3 100644
--- a/vendor/github.com/containers/image/ostree/ostree_src.go
+++ b/vendor/github.com/containers/image/ostree/ostree_src.go
@@ -4,7 +4,6 @@ package ostree
import (
"bytes"
- "compress/gzip"
"context"
"encoding/base64"
"fmt"
@@ -17,6 +16,7 @@ import (
"github.com/containers/image/manifest"
"github.com/containers/image/types"
"github.com/containers/storage/pkg/ioutils"
+ "github.com/klauspost/pgzip"
"github.com/opencontainers/go-digest"
glib "github.com/ostreedev/ostree-go/pkg/glibobject"
"github.com/pkg/errors"
@@ -255,6 +255,11 @@ func (s *ostreeImageSource) readSingleFile(commit, path string) (io.ReadCloser,
return getter.Get(path)
}
+// HasThreadSafeGetBlob indicates whether GetBlob can be executed concurrently.
+func (s *ostreeImageSource) HasThreadSafeGetBlob() bool {
+ return false
+}
+
// GetBlob returns a stream for the specified blob, and the blob’s size (or -1 if unknown).
// The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided.
// May update BlobInfoCache, preferably after it knows for certain that a blob truly exists at a specific location.
@@ -304,7 +309,7 @@ func (s *ostreeImageSource) GetBlob(ctx context.Context, info types.BlobInfo, ca
}
mf := bytes.NewReader(tarsplit)
- mfz, err := gzip.NewReader(mf)
+ mfz, err := pgzip.NewReader(mf)
if err != nil {
return nil, 0, err
}
diff --git a/vendor/github.com/containers/image/pkg/blobinfocache/default.go b/vendor/github.com/containers/image/pkg/blobinfocache/default.go
index 6da9f2805..459ae5c06 100644
--- a/vendor/github.com/containers/image/pkg/blobinfocache/default.go
+++ b/vendor/github.com/containers/image/pkg/blobinfocache/default.go
@@ -54,7 +54,7 @@ func DefaultCache(sys *types.SystemContext) types.BlobInfoCache {
}
path := filepath.Join(dir, blobInfoCacheFilename)
if err := os.MkdirAll(dir, 0700); err != nil {
- logrus.Debugf("Error creating parent directories for %s, using a memory-only cache: %v", err)
+ logrus.Debugf("Error creating parent directories for %s, using a memory-only cache: %v", blobInfoCacheFilename, err)
return NewMemoryCache()
}
diff --git a/vendor/github.com/containers/image/pkg/compression/compression.go b/vendor/github.com/containers/image/pkg/compression/compression.go
index a39523e4f..aad2bfcf2 100644
--- a/vendor/github.com/containers/image/pkg/compression/compression.go
+++ b/vendor/github.com/containers/image/pkg/compression/compression.go
@@ -3,10 +3,10 @@ package compression
import (
"bytes"
"compress/bzip2"
- "compress/gzip"
"io"
"io/ioutil"
+ "github.com/klauspost/pgzip"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/ulikunitz/xz"
@@ -18,7 +18,7 @@ type DecompressorFunc func(io.Reader) (io.ReadCloser, error)
// GzipDecompressor is a DecompressorFunc for the gzip compression algorithm.
func GzipDecompressor(r io.Reader) (io.ReadCloser, error) {
- return gzip.NewReader(r)
+ return pgzip.NewReader(r)
}
// Bzip2Decompressor is a DecompressorFunc for the bzip2 compression algorithm.
diff --git a/vendor/github.com/containers/image/pkg/sysregistriesv2/system_registries_v2.go b/vendor/github.com/containers/image/pkg/sysregistriesv2/system_registries_v2.go
index afc7312d1..9e3e9cfe1 100644
--- a/vendor/github.com/containers/image/pkg/sysregistriesv2/system_registries_v2.go
+++ b/vendor/github.com/containers/image/pkg/sysregistriesv2/system_registries_v2.go
@@ -318,8 +318,37 @@ func FindUnqualifiedSearchRegistries(ctx *types.SystemContext) ([]Registry, erro
return unqualified, nil
}
-// FindRegistry returns the Registry with the longest prefix for ref. If no
-// Registry prefixes the image, nil is returned.
+// refMatchesPrefix returns true iff ref,
+// which is a registry, repository namespace, repository or image reference (as formatted by
+// reference.Domain(), reference.Named.Name() or reference.Reference.String()
+// — note that this requires the name to start with an explicit hostname!),
+// matches a Registry.Prefix value.
+// (This is split from the caller primarily to make testing easier.)
+func refMatchesPrefix(ref, prefix string) bool {
+ switch {
+ case len(ref) < len(prefix):
+ return false
+ case len(ref) == len(prefix):
+ return ref == prefix
+ case len(ref) > len(prefix):
+ if !strings.HasPrefix(ref, prefix) {
+ return false
+ }
+ c := ref[len(prefix)]
+ // This allows "example.com:5000" to match "example.com",
+ // which is unintended; that will get fixed eventually, DON'T RELY
+ // ON THE CURRENT BEHAVIOR.
+ return c == ':' || c == '/' || c == '@'
+ default:
+ panic("Internal error: impossible comparison outcome")
+ }
+}
+
+// FindRegistry returns the Registry with the longest prefix for ref,
+// which is a registry, repository namespace repository or image reference (as formatted by
+// reference.Domain(), reference.Named.Name() or reference.Reference.String()
+// — note that this requires the name to start with an explicit hostname!).
+// If no Registry prefixes the image, nil is returned.
func FindRegistry(ctx *types.SystemContext, ref string) (*Registry, error) {
registries, err := GetRegistries(ctx)
if err != nil {
@@ -329,7 +358,7 @@ func FindRegistry(ctx *types.SystemContext, ref string) (*Registry, error) {
reg := Registry{}
prefixLen := 0
for _, r := range registries {
- if strings.HasPrefix(ref, r.Prefix+"/") || ref == r.Prefix {
+ if refMatchesPrefix(ref, r.Prefix) {
length := len(r.Prefix)
if length > prefixLen {
reg = r
diff --git a/vendor/github.com/containers/image/storage/storage_image.go b/vendor/github.com/containers/image/storage/storage_image.go
index bd6813119..b53fbdf6e 100644
--- a/vendor/github.com/containers/image/storage/storage_image.go
+++ b/vendor/github.com/containers/image/storage/storage_image.go
@@ -11,6 +11,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
+ "sync"
"sync/atomic"
"github.com/containers/image/image"
@@ -47,6 +48,7 @@ type storageImageSource struct {
image *storage.Image
layerPosition map[digest.Digest]int // Where we are in reading a blob's layers
cachedManifest []byte // A cached copy of the manifest, if already known, or nil
+ getBlobMutex sync.Mutex // Mutex to sync state for parallel GetBlob executions
SignatureSizes []int `json:"signature-sizes,omitempty"` // List of sizes of each signature slice
}
@@ -56,6 +58,7 @@ type storageImageDestination struct {
nextTempFileID int32 // A counter that we use for computing filenames to assign to blobs
manifest []byte // Manifest contents, temporary
signatures []byte // Signature contents, temporary
+ putBlobMutex sync.Mutex // Mutex to sync state for parallel PutBlob executions
blobDiffIDs map[digest.Digest]digest.Digest // Mapping from layer blobsums to their corresponding DiffIDs
fileSizes map[digest.Digest]int64 // Mapping from layer blobsums to their sizes
filenames map[digest.Digest]string // Mapping from layer blobsums to names of files we used to hold them
@@ -91,15 +94,20 @@ func newImageSource(imageRef storageReference) (*storageImageSource, error) {
}
// Reference returns the image reference that we used to find this image.
-func (s storageImageSource) Reference() types.ImageReference {
+func (s *storageImageSource) Reference() types.ImageReference {
return s.imageRef
}
// Close cleans up any resources we tied up while reading the image.
-func (s storageImageSource) Close() error {
+func (s *storageImageSource) Close() error {
return nil
}
+// HasThreadSafeGetBlob indicates whether GetBlob can be executed concurrently.
+func (s *storageImageSource) HasThreadSafeGetBlob() bool {
+ return true
+}
+
// GetBlob returns a stream for the specified blob, and the blob’s size (or -1 if unknown).
// The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided.
// May update BlobInfoCache, preferably after it knows for certain that a blob truly exists at a specific location.
@@ -137,8 +145,10 @@ func (s *storageImageSource) getBlobAndLayerID(info types.BlobInfo) (rc io.ReadC
// Step through the list of matching layers. Tests may want to verify that if we have multiple layers
// which claim to have the same contents, that we actually do have multiple layers, otherwise we could
// just go ahead and use the first one every time.
+ s.getBlobMutex.Lock()
i := s.layerPosition[info.Digest]
s.layerPosition[info.Digest] = i + 1
+ s.getBlobMutex.Unlock()
if len(layers) > 0 {
layer = layers[i%len(layers)]
}
@@ -300,7 +310,7 @@ func newImageDestination(imageRef storageReference) (*storageImageDestination, e
// Reference returns the reference used to set up this destination. Note that this should directly correspond to user's intent,
// e.g. it should use the public hostname instead of the result of resolving CNAMEs or following redirects.
-func (s storageImageDestination) Reference() types.ImageReference {
+func (s *storageImageDestination) Reference() types.ImageReference {
return s.imageRef
}
@@ -309,7 +319,7 @@ func (s *storageImageDestination) Close() error {
return os.RemoveAll(s.directory)
}
-func (s storageImageDestination) DesiredLayerCompression() types.LayerCompression {
+func (s *storageImageDestination) DesiredLayerCompression() types.LayerCompression {
// We ultimately have to decompress layers to populate trees on disk,
// so callers shouldn't bother compressing them before handing them to
// us, if they're not already compressed.
@@ -320,6 +330,11 @@ func (s *storageImageDestination) computeNextBlobCacheFile() string {
return filepath.Join(s.directory, fmt.Sprintf("%d", atomic.AddInt32(&s.nextTempFileID, 1)))
}
+// HasThreadSafePutBlob indicates whether PutBlob can be executed concurrently.
+func (s *storageImageDestination) HasThreadSafePutBlob() bool {
+ return true
+}
+
// PutBlob writes contents of stream and returns data representing the result.
// inputInfo.Digest can be optionally provided if known; it is not mandatory for the implementation to verify it.
// inputInfo.Size is the expected length of stream, if known.
@@ -370,9 +385,11 @@ func (s *storageImageDestination) PutBlob(ctx context.Context, stream io.Reader,
return errorBlobInfo, ErrBlobSizeMismatch
}
// Record information about the blob.
+ s.putBlobMutex.Lock()
s.blobDiffIDs[hasher.Digest()] = diffID.Digest()
s.fileSizes[hasher.Digest()] = counter.Count
s.filenames[hasher.Digest()] = filename
+ s.putBlobMutex.Unlock()
blobDigest := blobinfo.Digest
if blobDigest.Validate() != nil {
blobDigest = hasher.Digest()
@@ -398,6 +415,9 @@ func (s *storageImageDestination) PutBlob(ctx context.Context, stream io.Reader,
// If the transport can not reuse the requested blob, TryReusingBlob returns (false, {}, nil); it returns a non-nil error only on an unexpected failure.
// May use and/or update cache.
func (s *storageImageDestination) TryReusingBlob(ctx context.Context, blobinfo types.BlobInfo, cache types.BlobInfoCache, canSubstitute bool) (bool, types.BlobInfo, error) {
+ // lock the entire method as it executes fairly quickly
+ s.putBlobMutex.Lock()
+ defer s.putBlobMutex.Unlock()
if blobinfo.Digest == "" {
return false, types.BlobInfo{}, errors.Errorf(`Can not check for a blob with unknown digest`)
}
diff --git a/vendor/github.com/containers/image/tarball/tarball_src.go b/vendor/github.com/containers/image/tarball/tarball_src.go
index ee963b8d8..76e3e755f 100644
--- a/vendor/github.com/containers/image/tarball/tarball_src.go
+++ b/vendor/github.com/containers/image/tarball/tarball_src.go
@@ -2,7 +2,6 @@ package tarball
import (
"bytes"
- "compress/gzip"
"context"
"encoding/json"
"fmt"
@@ -14,7 +13,7 @@ import (
"time"
"github.com/containers/image/types"
-
+ "github.com/klauspost/pgzip"
digest "github.com/opencontainers/go-digest"
imgspecs "github.com/opencontainers/image-spec/specs-go"
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
@@ -77,7 +76,7 @@ func (r *tarballReference) NewImageSource(ctx context.Context, sys *types.System
// Set up to digest the file after we maybe decompress it.
diffIDdigester := digest.Canonical.Digester()
- uncompressed, err := gzip.NewReader(reader)
+ uncompressed, err := pgzip.NewReader(reader)
if err == nil {
// It is compressed, so the diffID is the digest of the uncompressed version
reader = io.TeeReader(uncompressed, diffIDdigester.Hash())
@@ -207,6 +206,11 @@ func (is *tarballImageSource) Close() error {
return nil
}
+// HasThreadSafeGetBlob indicates whether GetBlob can be executed concurrently.
+func (is *tarballImageSource) HasThreadSafeGetBlob() bool {
+ return false
+}
+
// GetBlob returns a stream for the specified blob, and the blob’s size (or -1 if unknown).
// The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided.
// May update BlobInfoCache, preferably after it knows for certain that a blob truly exists at a specific location.
diff --git a/vendor/github.com/containers/image/types/types.go b/vendor/github.com/containers/image/types/types.go
index dda332776..9fdab2314 100644
--- a/vendor/github.com/containers/image/types/types.go
+++ b/vendor/github.com/containers/image/types/types.go
@@ -198,6 +198,8 @@ type ImageSource interface {
// The Digest field in BlobInfo is guaranteed to be provided, Size may be -1 and MediaType may be optionally provided.
// May update BlobInfoCache, preferably after it knows for certain that a blob truly exists at a specific location.
GetBlob(context.Context, BlobInfo, BlobInfoCache) (io.ReadCloser, int64, error)
+ // HasThreadSafeGetBlob indicates whether GetBlob can be executed concurrently.
+ HasThreadSafeGetBlob() bool
// GetSignatures returns the image's signatures. It may use a remote (= slow) service.
// If instanceDigest is not nil, it contains a digest of the specific manifest instance to retrieve signatures for
// (when the primary manifest is a manifest list); this never happens if the primary manifest is not a manifest list
@@ -264,6 +266,8 @@ type ImageDestination interface {
// to any other readers for download using the supplied digest.
// If stream.Read() at any time, ESPECIALLY at end of input, returns an error, PutBlob MUST 1) fail, and 2) delete any data stored so far.
PutBlob(ctx context.Context, stream io.Reader, inputInfo BlobInfo, cache BlobInfoCache, isConfig bool) (BlobInfo, error)
+ // HasThreadSafePutBlob indicates whether PutBlob can be executed concurrently.
+ HasThreadSafePutBlob() bool
// TryReusingBlob checks whether the transport already contains, or can efficiently reuse, a blob, and if so, applies it to the current destination
// (e.g. if the blob is a filesystem layer, this signifies that the changes it describes need to be applied again when composing a filesystem tree).
// info.Digest must not be empty.
diff --git a/vendor/github.com/containers/image/vendor.conf b/vendor/github.com/containers/image/vendor.conf
index 88537981a..bbbb1a458 100644
--- a/vendor/github.com/containers/image/vendor.conf
+++ b/vendor/github.com/containers/image/vendor.conf
@@ -16,7 +16,7 @@ github.com/imdario/mergo 50d4dbd4eb0e84778abe37cefef140271d96fade
github.com/mattn/go-runewidth 14207d285c6c197daabb5c9793d63e7af9ab2d50
github.com/mistifyio/go-zfs c0224de804d438efd11ea6e52ada8014537d6062
github.com/mtrmac/gpgme b2432428689ca58c2b8e8dea9449d3295cf96fc9
-github.com/opencontainers/go-digest aa2ec055abd10d26d539eb630a92241b781ce4bc
+github.com/opencontainers/go-digest c9281466c8b2f606084ac71339773efd177436e7
github.com/opencontainers/image-spec v1.0.0
github.com/opencontainers/runc 6b1d0e76f239ffb435445e5ae316d2676c07c6e3
github.com/pborman/uuid 1b00554d822231195d1babd97ff4a781231955c9
@@ -26,8 +26,9 @@ github.com/stretchr/testify 4d4bfba8f1d1027c4fdbe371823030df51419987
github.com/vbatts/tar-split v0.10.2
golang.org/x/crypto 453249f01cfeb54c3d549ddb75ff152ca243f9d8
golang.org/x/net 6b27048ae5e6ad1ef927e72e437531493de612fe
+golang.org/x/sync 42b317875d0fa942474b76e1b46a6060d720ae6e
golang.org/x/sys 43e60d72a8e2bd92ee98319ba9a384a0e9837c08
-gopkg.in/cheggaaa/pb.v1 d7e6ca3010b6f084d8056847f55d7f572f180678
+gopkg.in/cheggaaa/pb.v1 v1.0.27
gopkg.in/yaml.v2 a3f3340b5840cee44f372bddb5880fcbc419b46a
k8s.io/client-go bcde30fb7eaed76fd98a36b4120321b94995ffb6
github.com/xeipuuv/gojsonschema master
@@ -36,7 +37,7 @@ github.com/xeipuuv/gojsonpointer master
github.com/tchap/go-patricia v2.2.6
github.com/opencontainers/selinux 077c8b6d1c18456fb7c792bc0de52295a0d1900e
github.com/BurntSushi/toml b26d9c308763d68093482582cea63d69be07a0f0
-github.com/ostreedev/ostree-go aeb02c6b6aa2889db3ef62f7855650755befd460
+github.com/ostreedev/ostree-go 56f3a639dbc0f2f5051c6d52dade28a882ba78ce
github.com/gogo/protobuf fcdc5011193ff531a548e9b0301828d5a5b97fd8
github.com/pquerna/ffjson master
github.com/syndtr/gocapability master
@@ -44,3 +45,6 @@ github.com/Microsoft/go-winio ab35fc04b6365e8fcb18e6e9e41ea4a02b10b175
github.com/Microsoft/hcsshim eca7177590cdcbd25bbc5df27e3b693a54b53a6a
github.com/ulikunitz/xz v0.5.4
github.com/boltdb/bolt master
+github.com/klauspost/pgzip v1.2.1
+github.com/klauspost/compress v1.4.1
+github.com/klauspost/cpuid v1.2.0
diff --git a/vendor/github.com/opencontainers/go-digest/LICENSE.code b/vendor/github.com/opencontainers/go-digest/LICENSE
index 0ea3ff81e..0ea3ff81e 100644
--- a/vendor/github.com/opencontainers/go-digest/LICENSE.code
+++ b/vendor/github.com/opencontainers/go-digest/LICENSE
diff --git a/vendor/github.com/opencontainers/go-digest/README.md b/vendor/github.com/opencontainers/go-digest/README.md
index 0f5a04092..25aac3470 100644
--- a/vendor/github.com/opencontainers/go-digest/README.md
+++ b/vendor/github.com/opencontainers/go-digest/README.md
@@ -101,4 +101,4 @@ the various OCI projects).
# Copyright and license
-Copyright © 2016 Docker, Inc. All rights reserved, except as follows. Code is released under the [Apache 2.0 license](LICENSE.code). This `README.md` file and the [`CONTRIBUTING.md`](CONTRIBUTING.md) file are licensed under the Creative Commons Attribution 4.0 International License under the terms and conditions set forth in the file [`LICENSE.docs`](LICENSE.docs). You may obtain a duplicate copy of the same license, titled CC BY-SA 4.0, at http://creativecommons.org/licenses/by-sa/4.0/.
+Copyright © 2016 Docker, Inc. All rights reserved, except as follows. Code is released under the [Apache 2.0 license](LICENSE). This `README.md` file and the [`CONTRIBUTING.md`](CONTRIBUTING.md) file are licensed under the Creative Commons Attribution 4.0 International License under the terms and conditions set forth in the file [`LICENSE.docs`](LICENSE.docs). You may obtain a duplicate copy of the same license, titled CC BY-SA 4.0, at http://creativecommons.org/licenses/by-sa/4.0/.
diff --git a/vendor/github.com/opencontainers/go-digest/algorithm.go b/vendor/github.com/opencontainers/go-digest/algorithm.go
index bdff42d92..8813bd26f 100644
--- a/vendor/github.com/opencontainers/go-digest/algorithm.go
+++ b/vendor/github.com/opencontainers/go-digest/algorithm.go
@@ -19,6 +19,7 @@ import (
"fmt"
"hash"
"io"
+ "regexp"
)
// Algorithm identifies and implementation of a digester by an identifier.
@@ -28,9 +29,9 @@ type Algorithm string
// supported digest types
const (
- SHA256 Algorithm = "sha256" // sha256 with hex encoding
- SHA384 Algorithm = "sha384" // sha384 with hex encoding
- SHA512 Algorithm = "sha512" // sha512 with hex encoding
+ SHA256 Algorithm = "sha256" // sha256 with hex encoding (lower case only)
+ SHA384 Algorithm = "sha384" // sha384 with hex encoding (lower case only)
+ SHA512 Algorithm = "sha512" // sha512 with hex encoding (lower case only)
// Canonical is the primary digest algorithm used with the distribution
// project. Other digests may be used but this one is the primary storage
@@ -50,6 +51,14 @@ var (
SHA384: crypto.SHA384,
SHA512: crypto.SHA512,
}
+
+ // anchoredEncodedRegexps contains anchored regular expressions for hex-encoded digests.
+ // Note that /A-F/ disallowed.
+ anchoredEncodedRegexps = map[Algorithm]*regexp.Regexp{
+ SHA256: regexp.MustCompile(`^[a-f0-9]{64}$`),
+ SHA384: regexp.MustCompile(`^[a-f0-9]{96}$`),
+ SHA512: regexp.MustCompile(`^[a-f0-9]{128}$`),
+ }
)
// Available returns true if the digest type is available for use. If this
@@ -125,6 +134,14 @@ func (a Algorithm) Hash() hash.Hash {
return algorithms[a].New()
}
+// Encode encodes the raw bytes of a digest, typically from a hash.Hash, into
+// the encoded portion of the digest.
+func (a Algorithm) Encode(d []byte) string {
+ // TODO(stevvooe): Currently, all algorithms use a hex encoding. When we
+ // add support for back registration, we can modify this accordingly.
+ return fmt.Sprintf("%x", d)
+}
+
// FromReader returns the digest of the reader using the algorithm.
func (a Algorithm) FromReader(rd io.Reader) (Digest, error) {
digester := a.Digester()
@@ -156,3 +173,20 @@ func (a Algorithm) FromBytes(p []byte) Digest {
func (a Algorithm) FromString(s string) Digest {
return a.FromBytes([]byte(s))
}
+
+// Validate validates the encoded portion string
+func (a Algorithm) Validate(encoded string) error {
+ r, ok := anchoredEncodedRegexps[a]
+ if !ok {
+ return ErrDigestUnsupported
+ }
+ // Digests much always be hex-encoded, ensuring that their hex portion will
+ // always be size*2
+ if a.Size()*2 != len(encoded) {
+ return ErrDigestInvalidLength
+ }
+ if r.MatchString(encoded) {
+ return nil
+ }
+ return ErrDigestInvalidFormat
+}
diff --git a/vendor/github.com/opencontainers/go-digest/digest.go b/vendor/github.com/opencontainers/go-digest/digest.go
index 69e1d2b54..ad398cba2 100644
--- a/vendor/github.com/opencontainers/go-digest/digest.go
+++ b/vendor/github.com/opencontainers/go-digest/digest.go
@@ -45,16 +45,21 @@ func NewDigest(alg Algorithm, h hash.Hash) Digest {
// functions. This is also useful for rebuilding digests from binary
// serializations.
func NewDigestFromBytes(alg Algorithm, p []byte) Digest {
- return Digest(fmt.Sprintf("%s:%x", alg, p))
+ return NewDigestFromEncoded(alg, alg.Encode(p))
}
-// NewDigestFromHex returns a Digest from alg and a the hex encoded digest.
+// NewDigestFromHex is deprecated. Please use NewDigestFromEncoded.
func NewDigestFromHex(alg, hex string) Digest {
- return Digest(fmt.Sprintf("%s:%s", alg, hex))
+ return NewDigestFromEncoded(Algorithm(alg), hex)
+}
+
+// NewDigestFromEncoded returns a Digest from alg and the encoded digest.
+func NewDigestFromEncoded(alg Algorithm, encoded string) Digest {
+ return Digest(fmt.Sprintf("%s:%s", alg, encoded))
}
// DigestRegexp matches valid digest types.
-var DigestRegexp = regexp.MustCompile(`[a-zA-Z0-9-_+.]+:[a-fA-F0-9]+`)
+var DigestRegexp = regexp.MustCompile(`[a-z0-9]+(?:[.+_-][a-z0-9]+)*:[a-zA-Z0-9=_-]+`)
// DigestRegexpAnchored matches valid digest types, anchored to the start and end of the match.
var DigestRegexpAnchored = regexp.MustCompile(`^` + DigestRegexp.String() + `$`)
@@ -96,26 +101,18 @@ func FromString(s string) Digest {
// error if not.
func (d Digest) Validate() error {
s := string(d)
-
i := strings.Index(s, ":")
-
- // validate i then run through regexp
- if i < 0 || i+1 == len(s) || !DigestRegexpAnchored.MatchString(s) {
+ if i <= 0 || i+1 == len(s) {
return ErrDigestInvalidFormat
}
-
- algorithm := Algorithm(s[:i])
+ algorithm, encoded := Algorithm(s[:i]), s[i+1:]
if !algorithm.Available() {
+ if !DigestRegexpAnchored.MatchString(s) {
+ return ErrDigestInvalidFormat
+ }
return ErrDigestUnsupported
}
-
- // Digests much always be hex-encoded, ensuring that their hex portion will
- // always be size*2
- if algorithm.Size()*2 != len(s[i+1:]) {
- return ErrDigestInvalidLength
- }
-
- return nil
+ return algorithm.Validate(encoded)
}
// Algorithm returns the algorithm portion of the digest. This will panic if
@@ -133,12 +130,17 @@ func (d Digest) Verifier() Verifier {
}
}
-// Hex returns the hex digest portion of the digest. This will panic if the
+// Encoded returns the encoded portion of the digest. This will panic if the
// underlying digest is not in a valid format.
-func (d Digest) Hex() string {
+func (d Digest) Encoded() string {
return string(d[d.sepIndex()+1:])
}
+// Hex is deprecated. Please use Digest.Encoded.
+func (d Digest) Hex() string {
+ return d.Encoded()
+}
+
func (d Digest) String() string {
return string(d)
}
diff --git a/vendor/golang.org/x/sync/LICENSE b/vendor/golang.org/x/sync/LICENSE
new file mode 100644
index 000000000..6a66aea5e
--- /dev/null
+++ b/vendor/golang.org/x/sync/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2009 The Go Authors. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+ * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/golang.org/x/sync/PATENTS b/vendor/golang.org/x/sync/PATENTS
new file mode 100644
index 000000000..733099041
--- /dev/null
+++ b/vendor/golang.org/x/sync/PATENTS
@@ -0,0 +1,22 @@
+Additional IP Rights Grant (Patents)
+
+"This implementation" means the copyrightable works distributed by
+Google as part of the Go project.
+
+Google hereby grants to You a perpetual, worldwide, non-exclusive,
+no-charge, royalty-free, irrevocable (except as stated in this section)
+patent license to make, have made, use, offer to sell, sell, import,
+transfer and otherwise run, modify and propagate the contents of this
+implementation of Go, where such license applies only to those patent
+claims, both currently owned or controlled by Google and acquired in
+the future, licensable by Google that are necessarily infringed by this
+implementation of Go. This grant does not include claims that would be
+infringed only as a consequence of further modification of this
+implementation. If you or your agent or exclusive licensee institute or
+order or agree to the institution of patent litigation against any
+entity (including a cross-claim or counterclaim in a lawsuit) alleging
+that this implementation of Go or any code incorporated within this
+implementation of Go constitutes direct or contributory patent
+infringement, or inducement of patent infringement, then any patent
+rights granted to you under this License for this implementation of Go
+shall terminate as of the date such litigation is filed.
diff --git a/vendor/golang.org/x/sync/README.md b/vendor/golang.org/x/sync/README.md
new file mode 100644
index 000000000..1f8436cc9
--- /dev/null
+++ b/vendor/golang.org/x/sync/README.md
@@ -0,0 +1,18 @@
+# Go Sync
+
+This repository provides Go concurrency primitives in addition to the
+ones provided by the language and "sync" and "sync/atomic" packages.
+
+## Download/Install
+
+The easiest way to install is to run `go get -u golang.org/x/sync`. You can
+also manually git clone the repository to `$GOPATH/src/golang.org/x/sync`.
+
+## Report Issues / Send Patches
+
+This repository uses Gerrit for code changes. To learn how to submit changes to
+this repository, see https://golang.org/doc/contribute.html.
+
+The main issue tracker for the sync repository is located at
+https://github.com/golang/go/issues. Prefix your issue with "x/sync:" in the
+subject line, so it is easy to find.
diff --git a/vendor/golang.org/x/sync/semaphore/semaphore.go b/vendor/golang.org/x/sync/semaphore/semaphore.go
new file mode 100644
index 000000000..ac53e733e
--- /dev/null
+++ b/vendor/golang.org/x/sync/semaphore/semaphore.go
@@ -0,0 +1,127 @@
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package semaphore provides a weighted semaphore implementation.
+package semaphore // import "golang.org/x/sync/semaphore"
+
+import (
+ "container/list"
+ "context"
+ "sync"
+)
+
+type waiter struct {
+ n int64
+ ready chan<- struct{} // Closed when semaphore acquired.
+}
+
+// NewWeighted creates a new weighted semaphore with the given
+// maximum combined weight for concurrent access.
+func NewWeighted(n int64) *Weighted {
+ w := &Weighted{size: n}
+ return w
+}
+
+// Weighted provides a way to bound concurrent access to a resource.
+// The callers can request access with a given weight.
+type Weighted struct {
+ size int64
+ cur int64
+ mu sync.Mutex
+ waiters list.List
+}
+
+// Acquire acquires the semaphore with a weight of n, blocking until resources
+// are available or ctx is done. On success, returns nil. On failure, returns
+// ctx.Err() and leaves the semaphore unchanged.
+//
+// If ctx is already done, Acquire may still succeed without blocking.
+func (s *Weighted) Acquire(ctx context.Context, n int64) error {
+ s.mu.Lock()
+ if s.size-s.cur >= n && s.waiters.Len() == 0 {
+ s.cur += n
+ s.mu.Unlock()
+ return nil
+ }
+
+ if n > s.size {
+ // Don't make other Acquire calls block on one that's doomed to fail.
+ s.mu.Unlock()
+ <-ctx.Done()
+ return ctx.Err()
+ }
+
+ ready := make(chan struct{})
+ w := waiter{n: n, ready: ready}
+ elem := s.waiters.PushBack(w)
+ s.mu.Unlock()
+
+ select {
+ case <-ctx.Done():
+ err := ctx.Err()
+ s.mu.Lock()
+ select {
+ case <-ready:
+ // Acquired the semaphore after we were canceled. Rather than trying to
+ // fix up the queue, just pretend we didn't notice the cancelation.
+ err = nil
+ default:
+ s.waiters.Remove(elem)
+ }
+ s.mu.Unlock()
+ return err
+
+ case <-ready:
+ return nil
+ }
+}
+
+// TryAcquire acquires the semaphore with a weight of n without blocking.
+// On success, returns true. On failure, returns false and leaves the semaphore unchanged.
+func (s *Weighted) TryAcquire(n int64) bool {
+ s.mu.Lock()
+ success := s.size-s.cur >= n && s.waiters.Len() == 0
+ if success {
+ s.cur += n
+ }
+ s.mu.Unlock()
+ return success
+}
+
+// Release releases the semaphore with a weight of n.
+func (s *Weighted) Release(n int64) {
+ s.mu.Lock()
+ s.cur -= n
+ if s.cur < 0 {
+ s.mu.Unlock()
+ panic("semaphore: bad release")
+ }
+ for {
+ next := s.waiters.Front()
+ if next == nil {
+ break // No more waiters blocked.
+ }
+
+ w := next.Value.(waiter)
+ if s.size-s.cur < w.n {
+ // Not enough tokens for the next waiter. We could keep going (to try to
+ // find a waiter with a smaller request), but under load that could cause
+ // starvation for large requests; instead, we leave all remaining waiters
+ // blocked.
+ //
+ // Consider a semaphore used as a read-write lock, with N tokens, N
+ // readers, and one writer. Each reader can Acquire(1) to obtain a read
+ // lock. The writer can Acquire(N) to obtain a write lock, excluding all
+ // of the readers. If we allow the readers to jump ahead in the queue,
+ // the writer will starve — there is always one token available for every
+ // reader.
+ break
+ }
+
+ s.cur += w.n
+ s.waiters.Remove(next)
+ close(w.ready)
+ }
+ s.mu.Unlock()
+}
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/README.md b/vendor/gopkg.in/cheggaaa/pb.v1/README.md
index 31babb305..1295df70e 100644
--- a/vendor/gopkg.in/cheggaaa/pb.v1/README.md
+++ b/vendor/gopkg.in/cheggaaa/pb.v1/README.md
@@ -1,7 +1,8 @@
# Terminal progress bar for Go
-Simple progress bar for console programs.
-
+Simple progress bar for console programs.
+
+Please check the new version https://github.com/cheggaaa/pb/tree/v2 (currently, it's beta)
## Installation
@@ -170,7 +171,7 @@ The result will be as follows:
```
$ go run example/multiple.go
-First 141 / 1000 [===============>---------------------------------------] 14.10 % 44s
-Second 139 / 1000 [==============>---------------------------------------] 13.90 % 44s
-Third 152 / 1000 [================>--------------------------------------] 15.20 % 40s
+First 34 / 200 [=========>---------------------------------------------] 17.00% 00m08s
+Second 42 / 200 [===========>------------------------------------------] 21.00% 00m06s
+Third 36 / 200 [=========>---------------------------------------------] 18.00% 00m08s
```
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/format.go b/vendor/gopkg.in/cheggaaa/pb.v1/format.go
index d5aeff793..8bb8a7a1d 100644
--- a/vendor/gopkg.in/cheggaaa/pb.v1/format.go
+++ b/vendor/gopkg.in/cheggaaa/pb.v1/format.go
@@ -2,7 +2,6 @@ package pb
import (
"fmt"
- "strings"
"time"
)
@@ -11,12 +10,26 @@ type Units int
const (
// U_NO are default units, they represent a simple value and are not formatted at all.
U_NO Units = iota
- // U_BYTES units are formatted in a human readable way (b, Bb, Mb, ...)
+ // U_BYTES units are formatted in a human readable way (B, KiB, MiB, ...)
U_BYTES
+ // U_BYTES_DEC units are like U_BYTES, but base 10 (B, KB, MB, ...)
+ U_BYTES_DEC
// U_DURATION units are formatted in a human readable way (3h14m15s)
U_DURATION
)
+const (
+ KiB = 1024
+ MiB = 1048576
+ GiB = 1073741824
+ TiB = 1099511627776
+
+ KB = 1e3
+ MB = 1e6
+ GB = 1e9
+ TB = 1e12
+)
+
func Format(i int64) *formatter {
return &formatter{n: i}
}
@@ -28,11 +41,6 @@ type formatter struct {
perSec bool
}
-func (f *formatter) Value(n int64) *formatter {
- f.n = n
- return f
-}
-
func (f *formatter) To(unit Units) *formatter {
f.unit = unit
return f
@@ -52,13 +60,10 @@ func (f *formatter) String() (out string) {
switch f.unit {
case U_BYTES:
out = formatBytes(f.n)
+ case U_BYTES_DEC:
+ out = formatBytesDec(f.n)
case U_DURATION:
- d := time.Duration(f.n)
- if d > time.Hour*24 {
- out = fmt.Sprintf("%dd", d/24/time.Hour)
- d -= (d / time.Hour / 24) * (time.Hour * 24)
- }
- out = fmt.Sprintf("%s%v", out, d)
+ out = formatDuration(f.n)
default:
out = fmt.Sprintf(fmt.Sprintf("%%%dd", f.width), f.n)
}
@@ -68,20 +73,53 @@ func (f *formatter) String() (out string) {
return
}
-// Convert bytes to human readable string. Like a 2 MB, 64.2 KB, 52 B
+// Convert bytes to human readable string. Like 2 MiB, 64.2 KiB, 52 B
func formatBytes(i int64) (result string) {
switch {
- case i > (1024 * 1024 * 1024 * 1024):
- result = fmt.Sprintf("%.02f TB", float64(i)/1024/1024/1024/1024)
- case i > (1024 * 1024 * 1024):
- result = fmt.Sprintf("%.02f GB", float64(i)/1024/1024/1024)
- case i > (1024 * 1024):
- result = fmt.Sprintf("%.02f MB", float64(i)/1024/1024)
- case i > 1024:
- result = fmt.Sprintf("%.02f KB", float64(i)/1024)
+ case i >= TiB:
+ result = fmt.Sprintf("%.02f TiB", float64(i)/TiB)
+ case i >= GiB:
+ result = fmt.Sprintf("%.02f GiB", float64(i)/GiB)
+ case i >= MiB:
+ result = fmt.Sprintf("%.02f MiB", float64(i)/MiB)
+ case i >= KiB:
+ result = fmt.Sprintf("%.02f KiB", float64(i)/KiB)
default:
result = fmt.Sprintf("%d B", i)
}
- result = strings.Trim(result, " ")
+ return
+}
+
+// Convert bytes to base-10 human readable string. Like 2 MB, 64.2 KB, 52 B
+func formatBytesDec(i int64) (result string) {
+ switch {
+ case i >= TB:
+ result = fmt.Sprintf("%.02f TB", float64(i)/TB)
+ case i >= GB:
+ result = fmt.Sprintf("%.02f GB", float64(i)/GB)
+ case i >= MB:
+ result = fmt.Sprintf("%.02f MB", float64(i)/MB)
+ case i >= KB:
+ result = fmt.Sprintf("%.02f KB", float64(i)/KB)
+ default:
+ result = fmt.Sprintf("%d B", i)
+ }
+ return
+}
+
+func formatDuration(n int64) (result string) {
+ d := time.Duration(n)
+ if d > time.Hour*24 {
+ result = fmt.Sprintf("%dd", d/24/time.Hour)
+ d -= (d / time.Hour / 24) * (time.Hour * 24)
+ }
+ if d > time.Hour {
+ result = fmt.Sprintf("%s%dh", result, d/time.Hour)
+ d -= d / time.Hour * time.Hour
+ }
+ m := d / time.Minute
+ d -= m * time.Minute
+ s := d / time.Second
+ result = fmt.Sprintf("%s%02dm%02ds", result, m, s)
return
}
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/pb.go b/vendor/gopkg.in/cheggaaa/pb.v1/pb.go
index f1f15bff3..e03291b89 100644
--- a/vendor/gopkg.in/cheggaaa/pb.v1/pb.go
+++ b/vendor/gopkg.in/cheggaaa/pb.v1/pb.go
@@ -13,7 +13,7 @@ import (
)
// Current version
-const Version = "1.0.6"
+const Version = "1.0.27"
const (
// Default refresh rate - 200ms
@@ -37,18 +37,17 @@ func New(total int) *ProgressBar {
// Create new progress bar object using int64 as total
func New64(total int64) *ProgressBar {
pb := &ProgressBar{
- Total: total,
- RefreshRate: DEFAULT_REFRESH_RATE,
- ShowPercent: true,
- ShowCounters: true,
- ShowBar: true,
- ShowTimeLeft: true,
- ShowFinalTime: true,
- Units: U_NO,
- ManualUpdate: false,
- finish: make(chan struct{}),
- currentValue: -1,
- mu: new(sync.Mutex),
+ Total: total,
+ RefreshRate: DEFAULT_REFRESH_RATE,
+ ShowPercent: true,
+ ShowCounters: true,
+ ShowBar: true,
+ ShowTimeLeft: true,
+ ShowElapsedTime: false,
+ ShowFinalTime: true,
+ Units: U_NO,
+ ManualUpdate: false,
+ finish: make(chan struct{}),
}
return pb.Format(FORMAT)
}
@@ -67,13 +66,14 @@ func StartNew(total int) *ProgressBar {
type Callback func(out string)
type ProgressBar struct {
- current int64 // current must be first member of struct (https://code.google.com/p/go/issues/detail?id=5278)
+ current int64 // current must be first member of struct (https://code.google.com/p/go/issues/detail?id=5278)
+ previous int64
Total int64
RefreshRate time.Duration
ShowPercent, ShowCounters bool
ShowSpeed, ShowTimeLeft, ShowBar bool
- ShowFinalTime bool
+ ShowFinalTime, ShowElapsedTime bool
Output io.Writer
Callback Callback
NotPrint bool
@@ -91,13 +91,14 @@ type ProgressBar struct {
finish chan struct{}
isFinish bool
- startTime time.Time
- startValue int64
- currentValue int64
+ startTime time.Time
+ startValue int64
+
+ changeTime time.Time
prefix, postfix string
- mu *sync.Mutex
+ mu sync.Mutex
lastPrint string
BarStart string
@@ -112,8 +113,8 @@ type ProgressBar struct {
// Start print
func (pb *ProgressBar) Start() *ProgressBar {
pb.startTime = time.Now()
- pb.startValue = pb.current
- if pb.Total == 0 {
+ pb.startValue = atomic.LoadInt64(&pb.current)
+ if atomic.LoadInt64(&pb.Total) == 0 {
pb.ShowTimeLeft = false
pb.ShowPercent = false
pb.AutoStat = false
@@ -158,12 +159,16 @@ func (pb *ProgressBar) Add64(add int64) int64 {
// Set prefix string
func (pb *ProgressBar) Prefix(prefix string) *ProgressBar {
+ pb.mu.Lock()
+ defer pb.mu.Unlock()
pb.prefix = prefix
return pb
}
// Set postfix string
func (pb *ProgressBar) Postfix(postfix string) *ProgressBar {
+ pb.mu.Lock()
+ defer pb.mu.Unlock()
pb.postfix = postfix
return pb
}
@@ -173,7 +178,7 @@ func (pb *ProgressBar) Postfix(postfix string) *ProgressBar {
// Example: bar.Format("[\x00=\x00>\x00-\x00]") // \x00 is the delimiter
func (pb *ProgressBar) Format(format string) *ProgressBar {
var formatEntries []string
- if len(format) == 5 {
+ if utf8.RuneCountInString(format) == 5 {
formatEntries = strings.Split(format, "")
} else {
formatEntries = strings.Split(format, "\x00")
@@ -221,7 +226,9 @@ func (pb *ProgressBar) Finish() {
//Protect multiple calls
pb.finishOnce.Do(func() {
close(pb.finish)
- pb.write(atomic.LoadInt64(&pb.current))
+ pb.write(atomic.LoadInt64(&pb.Total), atomic.LoadInt64(&pb.current))
+ pb.mu.Lock()
+ defer pb.mu.Unlock()
switch {
case pb.Output != nil:
fmt.Fprintln(pb.Output)
@@ -232,6 +239,13 @@ func (pb *ProgressBar) Finish() {
})
}
+// IsFinished return boolean
+func (pb *ProgressBar) IsFinished() bool {
+ pb.mu.Lock()
+ defer pb.mu.Unlock()
+ return pb.isFinish
+}
+
// End print and write string 'str'
func (pb *ProgressBar) FinishPrint(str string) {
pb.Finish()
@@ -262,16 +276,18 @@ func (pb *ProgressBar) NewProxyReader(r io.Reader) *Reader {
return &Reader{r, pb}
}
-func (pb *ProgressBar) write(current int64) {
+func (pb *ProgressBar) write(total, current int64) {
+ pb.mu.Lock()
+ defer pb.mu.Unlock()
width := pb.GetWidth()
- var percentBox, countersBox, timeLeftBox, speedBox, barBox, end, out string
+ var percentBox, countersBox, timeLeftBox, timeSpentBox, speedBox, barBox, end, out string
// percents
if pb.ShowPercent {
var percent float64
- if pb.Total > 0 {
- percent = float64(current) / (float64(pb.Total) / float64(100))
+ if total > 0 {
+ percent = float64(current) / (float64(total) / float64(100))
} else {
percent = float64(current) / float64(100)
}
@@ -281,17 +297,24 @@ func (pb *ProgressBar) write(current int64) {
// counters
if pb.ShowCounters {
current := Format(current).To(pb.Units).Width(pb.UnitsWidth)
- if pb.Total > 0 {
- total := Format(pb.Total).To(pb.Units).Width(pb.UnitsWidth)
- countersBox = fmt.Sprintf(" %s / %s ", current, total)
+ if total > 0 {
+ totalS := Format(total).To(pb.Units).Width(pb.UnitsWidth)
+ countersBox = fmt.Sprintf(" %s / %s ", current, totalS)
} else {
countersBox = fmt.Sprintf(" %s / ? ", current)
}
}
// time left
- fromStart := time.Now().Sub(pb.startTime)
currentFromStart := current - pb.startValue
+ fromStart := time.Now().Sub(pb.startTime)
+ lastChangeTime := pb.changeTime
+ fromChange := lastChangeTime.Sub(pb.startTime)
+
+ if pb.ShowElapsedTime {
+ timeSpentBox = fmt.Sprintf(" %s ", (fromStart/time.Second)*time.Second)
+ }
+
select {
case <-pb.finish:
if pb.ShowFinalTime {
@@ -301,17 +324,20 @@ func (pb *ProgressBar) write(current int64) {
}
default:
if pb.ShowTimeLeft && currentFromStart > 0 {
- perEntry := fromStart / time.Duration(currentFromStart)
+ perEntry := fromChange / time.Duration(currentFromStart)
var left time.Duration
- if pb.Total > 0 {
- left = time.Duration(pb.Total-currentFromStart) * perEntry
+ if total > 0 {
+ left = time.Duration(total-currentFromStart) * perEntry
+ left -= time.Since(lastChangeTime)
left = (left / time.Second) * time.Second
} else {
left = time.Duration(currentFromStart) * perEntry
left = (left / time.Second) * time.Second
}
- timeLeft := Format(int64(left)).To(U_DURATION).String()
- timeLeftBox = fmt.Sprintf(" %s", timeLeft)
+ if left > 0 {
+ timeLeft := Format(int64(left)).To(U_DURATION).String()
+ timeLeftBox = fmt.Sprintf(" %s", timeLeft)
+ }
}
}
@@ -326,30 +352,38 @@ func (pb *ProgressBar) write(current int64) {
speedBox = " " + Format(int64(speed)).To(pb.Units).Width(pb.UnitsWidth).PerSec().String()
}
- barWidth := escapeAwareRuneCountInString(countersBox + pb.BarStart + pb.BarEnd + percentBox + timeLeftBox + speedBox + pb.prefix + pb.postfix)
+ barWidth := escapeAwareRuneCountInString(countersBox + pb.BarStart + pb.BarEnd + percentBox + timeSpentBox + timeLeftBox + speedBox + pb.prefix + pb.postfix)
// bar
if pb.ShowBar {
size := width - barWidth
if size > 0 {
- if pb.Total > 0 {
- curCount := int(math.Ceil((float64(current) / float64(pb.Total)) * float64(size)))
- emptCount := size - curCount
+ if total > 0 {
+ curSize := int(math.Ceil((float64(current) / float64(total)) * float64(size)))
+ emptySize := size - curSize
barBox = pb.BarStart
- if emptCount < 0 {
- emptCount = 0
+ if emptySize < 0 {
+ emptySize = 0
}
- if curCount > size {
- curCount = size
+ if curSize > size {
+ curSize = size
}
- if emptCount <= 0 {
- barBox += strings.Repeat(pb.Current, curCount)
- } else if curCount > 0 {
- barBox += strings.Repeat(pb.Current, curCount-1) + pb.CurrentN
+
+ cursorLen := escapeAwareRuneCountInString(pb.Current)
+ if emptySize <= 0 {
+ barBox += strings.Repeat(pb.Current, curSize/cursorLen)
+ } else if curSize > 0 {
+ cursorEndLen := escapeAwareRuneCountInString(pb.CurrentN)
+ cursorRepetitions := (curSize - cursorEndLen) / cursorLen
+ barBox += strings.Repeat(pb.Current, cursorRepetitions)
+ barBox += pb.CurrentN
}
- barBox += strings.Repeat(pb.Empty, emptCount) + pb.BarEnd
+
+ emptyLen := escapeAwareRuneCountInString(pb.Empty)
+ barBox += strings.Repeat(pb.Empty, emptySize/emptyLen)
+ barBox += pb.BarEnd
} else {
- barBox = pb.BarStart
pos := size - int(current)%int(size)
+ barBox = pb.BarStart
if pos-1 > 0 {
barBox += strings.Repeat(pb.Empty, pos-1)
}
@@ -363,17 +397,18 @@ func (pb *ProgressBar) write(current int64) {
}
// check len
- out = pb.prefix + countersBox + barBox + percentBox + speedBox + timeLeftBox + pb.postfix
- if escapeAwareRuneCountInString(out) < width {
- end = strings.Repeat(" ", width-utf8.RuneCountInString(out))
+ out = pb.prefix + timeSpentBox + countersBox + barBox + percentBox + speedBox + timeLeftBox + pb.postfix
+
+ if cl := escapeAwareRuneCountInString(out); cl < width {
+ end = strings.Repeat(" ", width-cl)
}
// and print!
- pb.mu.Lock()
pb.lastPrint = out + end
- pb.mu.Unlock()
+ isFinish := pb.isFinish
+
switch {
- case pb.isFinish:
+ case isFinish:
return
case pb.Output != nil:
fmt.Fprint(pb.Output, "\r"+out+end)
@@ -406,24 +441,55 @@ func (pb *ProgressBar) GetWidth() int {
// Write the current state of the progressbar
func (pb *ProgressBar) Update() {
c := atomic.LoadInt64(&pb.current)
- if pb.AlwaysUpdate || c != pb.currentValue {
- pb.write(c)
- pb.currentValue = c
+ p := atomic.LoadInt64(&pb.previous)
+ t := atomic.LoadInt64(&pb.Total)
+ if p != c {
+ pb.mu.Lock()
+ pb.changeTime = time.Now()
+ pb.mu.Unlock()
+ atomic.StoreInt64(&pb.previous, c)
}
+ pb.write(t, c)
if pb.AutoStat {
if c == 0 {
pb.startTime = time.Now()
pb.startValue = 0
- } else if c >= pb.Total && pb.isFinish != true {
+ } else if c >= t && pb.isFinish != true {
pb.Finish()
}
}
}
+// String return the last bar print
func (pb *ProgressBar) String() string {
+ pb.mu.Lock()
+ defer pb.mu.Unlock()
return pb.lastPrint
}
+// SetTotal atomically sets new total count
+func (pb *ProgressBar) SetTotal(total int) *ProgressBar {
+ return pb.SetTotal64(int64(total))
+}
+
+// SetTotal64 atomically sets new total count
+func (pb *ProgressBar) SetTotal64(total int64) *ProgressBar {
+ atomic.StoreInt64(&pb.Total, total)
+ return pb
+}
+
+// Reset bar and set new total count
+// Does effect only on finished bar
+func (pb *ProgressBar) Reset(total int) *ProgressBar {
+ pb.mu.Lock()
+ defer pb.mu.Unlock()
+ if pb.isFinish {
+ pb.SetTotal(total).Set(0)
+ atomic.StoreInt64(&pb.previous, 0)
+ }
+ return pb
+}
+
// Internal loop for refreshing the progressbar
func (pb *ProgressBar) refresher() {
for {
@@ -435,10 +501,3 @@ func (pb *ProgressBar) refresher() {
}
}
}
-
-type window struct {
- Row uint16
- Col uint16
- Xpixel uint16
- Ypixel uint16
-}
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/pb_appengine.go b/vendor/gopkg.in/cheggaaa/pb.v1/pb_appengine.go
index d85dbc3b2..17168f39a 100644
--- a/vendor/gopkg.in/cheggaaa/pb.v1/pb_appengine.go
+++ b/vendor/gopkg.in/cheggaaa/pb.v1/pb_appengine.go
@@ -1,4 +1,4 @@
-// +build appengine
+// +build appengine js
package pb
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/pb_nix.go b/vendor/gopkg.in/cheggaaa/pb.v1/pb_nix.go
deleted file mode 100644
index c06097b43..000000000
--- a/vendor/gopkg.in/cheggaaa/pb.v1/pb_nix.go
+++ /dev/null
@@ -1,8 +0,0 @@
-// +build linux darwin freebsd netbsd openbsd dragonfly
-// +build !appengine
-
-package pb
-
-import "syscall"
-
-const sysIoctl = syscall.SYS_IOCTL
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/pb_solaris.go b/vendor/gopkg.in/cheggaaa/pb.v1/pb_solaris.go
deleted file mode 100644
index b7d461e17..000000000
--- a/vendor/gopkg.in/cheggaaa/pb.v1/pb_solaris.go
+++ /dev/null
@@ -1,6 +0,0 @@
-// +build solaris
-// +build !appengine
-
-package pb
-
-const sysIoctl = 54
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/pb_win.go b/vendor/gopkg.in/cheggaaa/pb.v1/pb_win.go
index 72f682835..9595e8236 100644
--- a/vendor/gopkg.in/cheggaaa/pb.v1/pb_win.go
+++ b/vendor/gopkg.in/cheggaaa/pb.v1/pb_win.go
@@ -102,7 +102,7 @@ var echoLockMutex sync.Mutex
var oldState word
-func lockEcho() (quit chan int, err error) {
+func lockEcho() (shutdownCh chan struct{}, err error) {
echoLockMutex.Lock()
defer echoLockMutex.Unlock()
if echoLocked {
@@ -124,6 +124,8 @@ func lockEcho() (quit chan int, err error) {
err = fmt.Errorf("Can't set terminal settings: %v", e)
return
}
+
+ shutdownCh = make(chan struct{})
return
}
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/pb_x.go b/vendor/gopkg.in/cheggaaa/pb.v1/pb_x.go
index 12e6fe6e2..af4251760 100644
--- a/vendor/gopkg.in/cheggaaa/pb.v1/pb_x.go
+++ b/vendor/gopkg.in/cheggaaa/pb.v1/pb_x.go
@@ -1,5 +1,5 @@
// +build linux darwin freebsd netbsd openbsd solaris dragonfly
-// +build !appengine
+// +build !appengine !js
package pb
@@ -8,101 +8,109 @@ import (
"fmt"
"os"
"os/signal"
- "runtime"
"sync"
"syscall"
- "unsafe"
-)
-const (
- TIOCGWINSZ = 0x5413
- TIOCGWINSZ_OSX = 1074295912
+ "golang.org/x/sys/unix"
)
-var tty *os.File
-
var ErrPoolWasStarted = errors.New("Bar pool was started")
-var echoLocked bool
-var echoLockMutex sync.Mutex
+var (
+ echoLockMutex sync.Mutex
+ origTermStatePtr *unix.Termios
+ tty *os.File
+ istty bool
+)
func init() {
+ echoLockMutex.Lock()
+ defer echoLockMutex.Unlock()
+
var err error
tty, err = os.Open("/dev/tty")
+ istty = true
if err != nil {
tty = os.Stdin
+ istty = false
}
}
// terminalWidth returns width of the terminal.
func terminalWidth() (int, error) {
- w := new(window)
- tio := syscall.TIOCGWINSZ
- if runtime.GOOS == "darwin" {
- tio = TIOCGWINSZ_OSX
+ if !istty {
+ return 0, errors.New("Not Supported")
}
- res, _, err := syscall.Syscall(sysIoctl,
- tty.Fd(),
- uintptr(tio),
- uintptr(unsafe.Pointer(w)),
- )
- if int(res) == -1 {
+ echoLockMutex.Lock()
+ defer echoLockMutex.Unlock()
+
+ fd := int(tty.Fd())
+
+ ws, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ)
+ if err != nil {
return 0, err
}
- return int(w.Col), nil
-}
-var oldState syscall.Termios
+ return int(ws.Col), nil
+}
-func lockEcho() (quit chan int, err error) {
+func lockEcho() (shutdownCh chan struct{}, err error) {
echoLockMutex.Lock()
defer echoLockMutex.Unlock()
- if echoLocked {
- err = ErrPoolWasStarted
- return
- }
- echoLocked = true
+ if istty {
+ if origTermStatePtr != nil {
+ return shutdownCh, ErrPoolWasStarted
+ }
- fd := tty.Fd()
- if _, _, e := syscall.Syscall6(sysIoctl, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&oldState)), 0, 0, 0); e != 0 {
- err = fmt.Errorf("Can't get terminal settings: %v", e)
- return
- }
+ fd := int(tty.Fd())
+
+ origTermStatePtr, err = unix.IoctlGetTermios(fd, ioctlReadTermios)
+ if err != nil {
+ return nil, fmt.Errorf("Can't get terminal settings: %v", err)
+ }
+
+ oldTermios := *origTermStatePtr
+ newTermios := oldTermios
+ newTermios.Lflag &^= syscall.ECHO
+ newTermios.Lflag |= syscall.ICANON | syscall.ISIG
+ newTermios.Iflag |= syscall.ICRNL
+ if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, &newTermios); err != nil {
+ return nil, fmt.Errorf("Can't set terminal settings: %v", err)
+ }
- newState := oldState
- newState.Lflag &^= syscall.ECHO
- newState.Lflag |= syscall.ICANON | syscall.ISIG
- newState.Iflag |= syscall.ICRNL
- if _, _, e := syscall.Syscall6(sysIoctl, fd, ioctlWriteTermios, uintptr(unsafe.Pointer(&newState)), 0, 0, 0); e != 0 {
- err = fmt.Errorf("Can't set terminal settings: %v", e)
- return
}
- quit = make(chan int, 1)
- go catchTerminate(quit)
+ shutdownCh = make(chan struct{})
+ go catchTerminate(shutdownCh)
return
}
-func unlockEcho() (err error) {
+func unlockEcho() error {
echoLockMutex.Lock()
defer echoLockMutex.Unlock()
- if !echoLocked {
- return
- }
- echoLocked = false
- fd := tty.Fd()
- if _, _, e := syscall.Syscall6(sysIoctl, fd, ioctlWriteTermios, uintptr(unsafe.Pointer(&oldState)), 0, 0, 0); e != 0 {
- err = fmt.Errorf("Can't set terminal settings")
+ if istty {
+ if origTermStatePtr == nil {
+ return nil
+ }
+
+ fd := int(tty.Fd())
+
+ if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, origTermStatePtr); err != nil {
+ return fmt.Errorf("Can't set terminal settings: %v", err)
+ }
+
}
- return
+ origTermStatePtr = nil
+
+ return nil
}
// listen exit signals and restore terminal state
-func catchTerminate(quit chan int) {
+func catchTerminate(shutdownCh chan struct{}) {
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL)
defer signal.Stop(sig)
select {
- case <-quit:
+ case <-shutdownCh:
unlockEcho()
case <-sig:
unlockEcho()
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/pool.go b/vendor/gopkg.in/cheggaaa/pb.v1/pool.go
index 0b4a4afa8..392e7599c 100644
--- a/vendor/gopkg.in/cheggaaa/pb.v1/pool.go
+++ b/vendor/gopkg.in/cheggaaa/pb.v1/pool.go
@@ -3,6 +3,7 @@
package pb
import (
+ "io"
"sync"
"time"
)
@@ -11,22 +12,36 @@ import (
// You need call pool.Stop() after work
func StartPool(pbs ...*ProgressBar) (pool *Pool, err error) {
pool = new(Pool)
- if err = pool.start(); err != nil {
+ if err = pool.Start(); err != nil {
return
}
pool.Add(pbs...)
return
}
+// NewPool initialises a pool with progress bars, but
+// doesn't start it. You need to call Start manually
+func NewPool(pbs ...*ProgressBar) (pool *Pool) {
+ pool = new(Pool)
+ pool.Add(pbs...)
+ return
+}
+
type Pool struct {
- RefreshRate time.Duration
- bars []*ProgressBar
- quit chan int
- finishOnce sync.Once
+ Output io.Writer
+ RefreshRate time.Duration
+ bars []*ProgressBar
+ lastBarsCount int
+ shutdownCh chan struct{}
+ workerCh chan struct{}
+ m sync.Mutex
+ finishOnce sync.Once
}
// Add progress bars.
func (p *Pool) Add(pbs ...*ProgressBar) {
+ p.m.Lock()
+ defer p.m.Unlock()
for _, bar := range pbs {
bar.ManualUpdate = true
bar.NotPrint = true
@@ -35,30 +50,38 @@ func (p *Pool) Add(pbs ...*ProgressBar) {
}
}
-func (p *Pool) start() (err error) {
+func (p *Pool) Start() (err error) {
p.RefreshRate = DefaultRefreshRate
- quit, err := lockEcho()
+ p.shutdownCh, err = lockEcho()
if err != nil {
return
}
- p.quit = make(chan int)
- go p.writer(quit)
+ p.workerCh = make(chan struct{})
+ go p.writer()
return
}
-func (p *Pool) writer(finish chan int) {
+func (p *Pool) writer() {
var first = true
+ defer func() {
+ if first == false {
+ p.print(false)
+ } else {
+ p.print(true)
+ p.print(false)
+ }
+ close(p.workerCh)
+ }()
+
for {
select {
case <-time.After(p.RefreshRate):
if p.print(first) {
p.print(false)
- finish <- 1
return
}
first = false
- case <-p.quit:
- finish <- 1
+ case <-p.shutdownCh:
return
}
}
@@ -66,11 +89,16 @@ func (p *Pool) writer(finish chan int) {
// Restore terminal state and close pool
func (p *Pool) Stop() error {
- // Wait until one final refresh has passed.
- time.Sleep(p.RefreshRate)
-
p.finishOnce.Do(func() {
- close(p.quit)
+ if p.shutdownCh != nil {
+ close(p.shutdownCh)
+ }
})
+
+ // Wait for the worker to complete
+ select {
+ case <-p.workerCh:
+ }
+
return unlockEcho()
}
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/pool_win.go b/vendor/gopkg.in/cheggaaa/pb.v1/pool_win.go
index d7a5ace41..63598d378 100644
--- a/vendor/gopkg.in/cheggaaa/pb.v1/pool_win.go
+++ b/vendor/gopkg.in/cheggaaa/pb.v1/pool_win.go
@@ -8,13 +8,18 @@ import (
)
func (p *Pool) print(first bool) bool {
+ p.m.Lock()
+ defer p.m.Unlock()
var out string
if !first {
coords, err := getCursorPos()
if err != nil {
log.Panic(err)
}
- coords.Y -= int16(len(p.bars))
+ coords.Y -= int16(p.lastBarsCount)
+ if coords.Y < 0 {
+ coords.Y = 0
+ }
coords.X = 0
err = setCursorPos(coords)
@@ -24,12 +29,17 @@ func (p *Pool) print(first bool) bool {
}
isFinished := true
for _, bar := range p.bars {
- if !bar.isFinish {
+ if !bar.IsFinished() {
isFinished = false
}
bar.Update()
out += fmt.Sprintf("\r%s\n", bar.String())
}
- fmt.Print(out)
+ if p.Output != nil {
+ fmt.Fprint(p.Output, out)
+ } else {
+ fmt.Print(out)
+ }
+ p.lastBarsCount = len(p.bars)
return isFinished
}
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/pool_x.go b/vendor/gopkg.in/cheggaaa/pb.v1/pool_x.go
index d95b71d87..a8ae14d2f 100644
--- a/vendor/gopkg.in/cheggaaa/pb.v1/pool_x.go
+++ b/vendor/gopkg.in/cheggaaa/pb.v1/pool_x.go
@@ -5,18 +5,25 @@ package pb
import "fmt"
func (p *Pool) print(first bool) bool {
+ p.m.Lock()
+ defer p.m.Unlock()
var out string
if !first {
- out = fmt.Sprintf("\033[%dA", len(p.bars))
+ out = fmt.Sprintf("\033[%dA", p.lastBarsCount)
}
isFinished := true
for _, bar := range p.bars {
- if !bar.isFinish {
+ if !bar.IsFinished() {
isFinished = false
}
bar.Update()
out += fmt.Sprintf("\r%s\n", bar.String())
}
- fmt.Print(out)
+ if p.Output != nil {
+ fmt.Fprint(p.Output, out)
+ } else {
+ fmt.Print(out)
+ }
+ p.lastBarsCount = len(p.bars)
return isFinished
}
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/runecount.go b/vendor/gopkg.in/cheggaaa/pb.v1/runecount.go
index d52edd365..c617c55ec 100644
--- a/vendor/gopkg.in/cheggaaa/pb.v1/runecount.go
+++ b/vendor/gopkg.in/cheggaaa/pb.v1/runecount.go
@@ -11,7 +11,7 @@ var ctrlFinder = regexp.MustCompile("\x1b\x5b[0-9]+\x6d")
func escapeAwareRuneCountInString(s string) int {
n := runewidth.StringWidth(s)
for _, sm := range ctrlFinder.FindAllString(s, -1) {
- n -= len(sm)
+ n -= runewidth.StringWidth(sm)
}
return n
}
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/termios_nix.go b/vendor/gopkg.in/cheggaaa/pb.v1/termios_nix.go
deleted file mode 100644
index ebb3fe87c..000000000
--- a/vendor/gopkg.in/cheggaaa/pb.v1/termios_nix.go
+++ /dev/null
@@ -1,7 +0,0 @@
-// +build linux solaris
-// +build !appengine
-
-package pb
-
-const ioctlReadTermios = 0x5401 // syscall.TCGETS
-const ioctlWriteTermios = 0x5402 // syscall.TCSETS
diff --git a/vendor/gopkg.in/cheggaaa/pb.v1/termios_sysv.go b/vendor/gopkg.in/cheggaaa/pb.v1/termios_sysv.go
new file mode 100644
index 000000000..b10f61859
--- /dev/null
+++ b/vendor/gopkg.in/cheggaaa/pb.v1/termios_sysv.go
@@ -0,0 +1,13 @@
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build linux solaris
+// +build !appengine
+
+package pb
+
+import "golang.org/x/sys/unix"
+
+const ioctlReadTermios = unix.TCGETS
+const ioctlWriteTermios = unix.TCSETS