Commit Graph

10 Commits

Author SHA1 Message Date
Daniel J Walsh 33b3369a7f
Merge pull request #957 from saschagrunert/panic-fix
Fix runtime panic for opening lockfile if parent dir got removed
2021-07-09 06:39:19 -04:00
Sascha Grunert 16de6d32b4
Fix runtime panic for opening lockfile if parent dir got removed
If the lockfile directory gets removed but the container runtime is
still running with an open storage instance, then we can trigger a
runtime panic by:

1. Starting CRI-O
2. Removing the lockfile dir, e.g.:
   `sudo rm -rf /var/lib/containers/storage/overlay-images`
3. Running `crictl images`

```
panic: error opening "/var/lib/containers/storage/overlay-images/images.lock": no such file or directory

goroutine 93 [running]:
github.com/containers/storage/pkg/lockfile.(*lockfile).lock(0xc0006b83c0, 0x2000000)
        /go/src/github.com/cri-o/cri-o/vendor/github.com/containers/storage/pkg/lockfile/lockfile_unix.go:107 +0x388
github.com/containers/storage/pkg/lockfile.(*lockfile).RLock(0xc0006b83c0)
        /go/src/github.com/cri-o/cri-o/vendor/github.com/containers/storage/pkg/lockfile/lockfile_unix.go:146 +0x37
github.com/containers/storage.(*imageStore).RLock(0xc00006e420)
        /go/src/github.com/cri-o/cri-o/vendor/github.com/containers/storage/images.go:778 +0x33
github.com/containers/storage.(*store).Images(0xc0003f3b80, 0x0, 0x0, 0x0, 0x0, 0x0)
        /go/src/github.com/cri-o/cri-o/vendor/github.com/containers/storage/store.go:3089 +0x1dc
```

We now ensure the parent lockfile directory, but only if it does not
exist to not degrade the performance of c/stroage.

Unit tests around that case have been added as well.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2021-07-07 14:05:09 +02:00
Giuseppe Scrivano 10afc9279e
lockfile: merge Seek+Read/Write into Pread/Pwrite
drop a call to Seek and use the Pread and Pwrite syscalls instead that
already accept an offset.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-06-09 11:06:20 +02:00
Nalin Dahyabhai 58be038c06 pkg/lockfile: fix a race and an incorrect unit test
Fix a race where the state lock in a Unixy lockfile structure wasn't
being used to protect access to all of the structure's state fields.

Fix usage of sync/atomic in the corresponding unit tests to not mix
atomic adds and reads with non-atomic reads, something which the race
detector complained about.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-02-22 18:24:04 -05:00
Daniel J Walsh 44195fdb33
Make lock files world readable
This will make them easier to consule for additional stores

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-06-25 09:10:35 -04:00
Daniel J Walsh 533121f287
Lock files should be CLOEXEC
We are getting reports of SELinux failures on leaked file descriptors.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-06-25 06:06:59 -04:00
Giuseppe Scrivano c2d2788f52
lockfile: drop call to unix.Fsync
do not flush the modified metadata to disk each time the store is
modified.

It is not needed for other processes stat'ing the lock file to see the
updated mtime.

introduced with commit 9b0633295b

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-02 12:07:11 +01:00
Sascha Grunert fd72b45a3f
Enable golint linter and fix lints
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-01-28 15:59:15 +01:00
Matthew Heon fdd3af2db0 Do not discard errors when panicing on lockfile open
We're seeing some panics with Podman on Ubuntu 19 in this code,
and debugging without knowing what's going wrong is very
difficult.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-10-11 15:40:33 -04:00
Nalin Dahyabhai 2dfeb3edf7 Move lockfiles to their own package
Move the lockfile implementation into a subpackage so that we can use it
in the devicemapper driver.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-07-02 11:14:04 -04:00