Commit graph

35 commits

Author SHA1 Message Date
Ian Wienand 72cf389685 shm_lock: Handle ENOSPC better in AllocateSemaphore
When starting a container libpod/runtime_pod_linux.go:NewPod calls
libpod/lock/lock.go:AllocateLock ends up in here.  If you exceed
num_locks, in response to a "podman run ..." you will see:

 Error: error allocating lock for new container: no space left on device

As noted inline, this error is technically true as it is talking about
the SHM area, but for anyone who has not dug into the source (i.e. me,
before a few hours ago :) your initial thought is going to be that
your disk is full.  I spent quite a bit of time trying to diagnose
what disk, partition, overlay, etc. was filling up before I realised
this was actually due to leaking from failing containers.

This overrides this case to give a more explicit message that
hopefully puts people on the right track to fixing this faster.  You
will now see:

 $ ./bin/podman run --rm -it fedora bash
 Error: error allocating lock for new container: allocation failed; exceeded num_locks (20)

[NO NEW TESTS NEEDED] (just changes an existing error message)

Signed-off-by: Ian Wienand <iwienand@redhat.com>
2021-11-09 18:34:21 +11:00
Daniel J Walsh 1c4e6d8624
standardize logrus messages to upper case
Remove ERROR: Error stutter from logrus messages also.

[ NO TESTS NEEDED] This is just code cleanup.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-09-22 15:29:34 -04:00
Valentin Rothberg 5dded6fae7 bump go module to v3
We missed bumping the go module, so let's do it now :)

* Automated go code with github.com/sirkon/go-imports-rename
* Manually via `vgrep podman/v2` the rest

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-02-22 09:03:51 +01:00
Kir Kolyshkin 4878dff3e2 Remove excessive error wrapping
In case os.Open[File], os.Mkdir[All], ioutil.ReadFile and the like
fails, the error message already contains the file name and the
operation that fails, so there is no need to wrap the error with
something like "open %s failed".

While at it

 - replace a few places with os.Open, ioutil.ReadAll with
   ioutil.ReadFile.

 - replace errors.Wrapf with errors.Wrap for cases where there
   are no %-style arguments.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 15:30:37 -07:00
Lokesh Mandvekar 8a26134949 Delete prior /dev/shm/*
Currently, subsequent runs of `make localunit` fail and complain about
prior existing /dev/shm/libpod_test and /dev/shm/test1.

This commit deletes these files if existing already, prior to running
the tests.

Signed-off-by: Lokesh Mandvekar <lsm5@fedoraproject.org>
2020-08-28 09:26:33 -04:00
Daniel J Walsh a5e37ad280
Switch all references to github.com/containers/libpod -> podman
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-28 08:23:45 -04:00
Valentin Rothberg 8489dc4345 move go module to v2
With the advent of Podman 2.0.0 we crossed the magical barrier of go
modules.  While we were able to continue importing all packages inside
of the project, the project could not be vendored anymore from the
outside.

Move the go module to new major version and change all imports to
`github.com/containers/libpod/v2`.  The renaming of the imports
was done via `gomove` [1].

[1] https://github.com/KSubedi/gomove

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-06 15:50:12 +02:00
Valentin Rothberg 64a12898ad shm_lock_test: add nil check
Fixes: #6164
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-05-11 13:20:32 +02:00
Miloslav Trmač 8153ea358a Make libpod/lock/shm completely Linux-only
If the tests are not Linux-only, (go test ./...) still tries
to build and test the package.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-03-21 00:21:59 +01:00
Valentin Rothberg cf1f3191d2 make lint: include unit tests
Include the unit tests (i.e., _test.go files) for linting to make the
tests more robust and enforce the linters' coding styles etc.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-14 10:51:59 +01:00
Dmitry Smirnov 8d928d525f codespell: spelling corrections
Signed-off-by: Dmitry Smirnov <onlyjob@member.fsf.org>
2019-11-13 08:15:00 +11:00
baude fec1de6ef4 trivial cleanups from golang
the results of a code cleanup performed by the goland IDE.

Signed-off-by: baude <bbaude@redhat.com>
2019-07-03 15:41:33 -05:00
Giuseppe Scrivano 827ac0859f
lock: new lock type "file"
it is a wrapper around containers/storage file locking.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-07-02 16:41:10 +02:00
Giuseppe Scrivano 2341eaa6c1
lock: disable without cgo
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-07-02 16:41:04 +02:00
Sascha Grunert 4bfbc355de
Build cgo files with -Wall -Werror
To avoid unnecessary warnings and errors in the future I'd like to
propose building all cgo related sources with `-Wall -Werror`. This
commit fixes some warnings which came up in `shm_lock.c`, too.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2019-06-21 10:14:19 +02:00
Matthew Heon faae3a7065 When refreshing after a reboot, force lock allocation
After a reboot, when we refresh Podman's state, we retrieved the
lock from the fresh SHM instance, but we did not mark it as
allocated to prevent it being handed out to other containers and
pods.

Provide a method for marking locks as in-use, and use it when we
refresh Podman state after a reboot.

Fixes #2900

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-05-06 14:17:54 -04:00
Matthew Heon d2b77f8b33 Do not make renumber shut down the runtime
The original intent behind the requirement was to ensure that, if
two SHM lock structs were open at the same time, we should not
make such a runtime available to the user, and should clean it up
instead.

It turns out that we don't even need to open a second SHM lock
struct - if we get an error mapping the first one due to a lock
count mismatch, we can just delete it, and it cleans itself up
when it errors. So there's no reason not to return a valid
runtime.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-02-21 10:51:42 -05:00
Matthew Heon f9c548219b Recreate SHM locks when renumbering on count mismatch
When we're renumbering locks, we're destroying all existing
allocations anyways, so destroying the old lock struct is not a
particularly big deal. Existing long-lived libpod instances will
continue to use the old locks, but that will be solved in a
followon.

Also, solve an issue with returning error values in the C code.
There were a few places where we return ERRNO where it was not
set, so make them return actual error codes).

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-02-21 10:51:42 -05:00
Matthew Heon 7fdd20ae5a Add initial version of renumber backend
Renumber is a way of renumbering container locks after the number
of locks available has changed.

For now, renumber only works with containers.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-02-21 10:51:42 -05:00
baude 43c6da22b9 Add darwin support for remote-client
Add the ability to cross-compile podman remote for OSX.

Also, add image exists and tag to remote-client.

Signed-off-by: baude <bbaude@redhat.com>
2019-01-11 11:30:28 -06:00
Matthew Heon eba89259a5 Address lingering review comments from SHM locking PR
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-01-07 09:45:26 -05:00
Daniel J Walsh a76256834a
Rootless with shmlocks was not working.
This patch makes the path unigue to each UID.

Also cleans up some return code to return the path it is trying to lock.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-01-05 07:37:21 -05:00
Matthew Heon 625c7e18ef Update unit tests to use in-memory lock manager
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:51:09 -05:00
Matthew Heon 35361595f3 Remove runtime lockDir and add in-memory lock manager
Remove runtime's lockDir as it is no longer needed after the lock
rework.

Add a trivial in-memory lock manager for unit testing

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:51:09 -05:00
Matthew Heon d4b2f11601 Convert pods to SHM locks
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:51:09 -05:00
Matthew Heon a364b656ea Add lock manager to libpod runtime
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:51:09 -05:00
Matthew Heon e73484c176 Move to POSIX mutexes for SHM locks
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:51:09 -05:00
Matthew Heon f38fccb48c Disable lint on SHMLock struct
Golint wants to rename the struct. I think the name is fine. I
can disable golint. Golint will no longer complain about the
name.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:45:59 -05:00
Matthew Heon a21f21efa1 Refactor locks package to build on non-Linux
Move SHM specific code into a subpackage. Within the main locks
package, move the manager to be linux-only and add a non-Linux
unsupported build file.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:45:59 -05:00
Matthew Heon 3ed81051e8 Add an SHM-backed Lock Manager implementation
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:45:59 -05:00
Matthew Heon 185136cf0e Add interface for libpod multiprocess locks
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:45:59 -05:00
Matthew Heon 35cc71a9e8 Improve documentation and unit tests for SHM locks
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:45:59 -05:00
Matthew Heon 52d95f5072 Propogate error codes from SHM lock creation and open
Also add a few more unit tests

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:45:59 -05:00
Matthew Heon b489feff71 Add mutex invariant to SHM semaphores.
Check value of semaphores when incrementing to ensure we never go
beyond 1, preserving mutex invariants.

Also, add cleanup code to the lock tests, ensuring that we never
leave the locks in a bad state after a test. We aren't destroying
and recreating the SHM every time, so we have to be careful not
to leak state between test runs.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:45:59 -05:00
Matthew Heon 27cebb780b Initial skeleton of in-memory locks
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:45:59 -05:00