Commit Graph

84 Commits

Author SHA1 Message Date
Miloslav Trmač 596f17c745 Use os.ReadFile instead of ioutil.ReadFile
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:30:43 +02:00
Sascha Grunert a41ae81840 Switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of the
deprecated github.com/pkg/errors package.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-07 13:22:46 +02:00
Aditya R 5b58ed404e store: add independent AddNames and RemoveNames for images,layers,containers
Adds AddNames and RemoveNames so operations which are invoked in parallel
manner can use it without destroying names from storage.

For instance

We are deleting names which were already written in store.
This creates faulty behavior when builds are invoked in parallel manner, as
this removes names for other builds.

To fix this behavior we must append to already written names and
override if needed. But this should be optional and not break public API

Following patch will be used by parallel operations at podman or buildah end, directly or indirectly.

Signed-off-by: Aditya R <arajan@redhat.com>
2022-03-01 01:33:35 +05:30
Giuseppe Scrivano 7d41427411 containers: detect overlapping mappings
when the container specifies some mappings to be applied, verify that
they are not overlapping and give a clearer error message.

Closes: https://github.com/containers/storage/issues/1127

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-02-08 09:57:34 +01:00
Giuseppe Scrivano f2deb04325 store: ReloadIfChanged propagates errors from Modified()
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-05-27 14:55:42 +02:00
Giuseppe Scrivano 8e3278d821 store: new method ROFileBasedStore.ReloadIfChanged()
add a new method to reload the store information from the hard disk if
has changed.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-05-13 09:05:42 +02:00
Nalin Dahyabhai 019495cec4 Use json-iterator instead of encoding/json
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2021-05-06 12:24:24 -04:00
Giuseppe Scrivano b12978ee1a store: support volatile containers
add a new class of containers that are not guaranteed to survive a
crash.  The advantage of such containers is that storage can be
optimized to skip some synchronizations with the underlying storage.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-02-11 10:13:27 +01:00
blade d4c9217c7b lost mountopts when read json from file
Signed-off-by: blade <blade.shen@ucloud.cn>
2020-04-29 01:34:19 +08:00
Nalin Dahyabhai 15c6baac88 locking: take read locks on read-only stores
Use RLock() to lock stores that we know are read-only, and panic in
Lock() if we know that we're not a read-write lock.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-07-02 11:14:03 -04:00
Valentin Rothberg 9e1b480ed7 lockfile: add RecursiveLock() API
Add a RecursiveLock() API to allow for recursive acquisitions of a
writer lock within the same process space.  This is yet another
requirement for the copy-detection mechanism in containers/image where
multiple goroutines can be pulling the same blob.  Having a recursive
lock avoids a complex synchronization mechanism as the commit order is
determinted by the corresponding index in the image.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-05-22 17:05:38 +02:00
Nalin Dahyabhai 4867edfac1 Drop our dependency on github.com/containers/image
Drop our dependency on the image library's manifest package by requiring
that callers pass its Digest() function to us as a callback.  This makes
our CLI test/diagnostic tool calculate digests of s1 manifests
incorrectly, but that's not something that we were testing.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-03-06 15:06:34 -05:00
Valentin Rothberg a1db08dcd3 lockfile: implement reader-writer locks
Implement reader-writer locks to allow allow multiple readers to hold
the lock in parallel.

* The locks are still based on fcntl(2).

* Changing the lock from a reader to a writer and vice versa will block
  on the syscall.

* A writer lock can be held only by one process.  To protect against
  concurrent accesses by gourtines within the same process space, use a
  writer mutex.

* Extend the Locker interface with the `RLock()` method to acquire a
  reader lock.  If the lock is set to be read-only, all calls to
  `Lock()` will be redirected to `RLock()`.  A reader lock is only
  released via fcntl(2) when all gourtines within the same process space
  have unlocked it.  This is done via an internal counter which is
  protected (among other things) by an internal state mutex.

* Panic on violations of the lock protocol, namely when calling
  `Unlock()` on an unlocked lock.  This helps detecting violations in
  the code but also protects the storage from corruption.  Doing this
  has revealed some bugs fixed in ealier commits.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-02-15 09:49:44 +01:00
Daniel J Walsh 87880e1bf8 Allow the passing in and retrieval of mount options
We want to allow tools like podman/buildah to override default storage
container mount options on a container by container basis.

For example if the default mount options for containers/storage include
nodev or nosuid, we want to allow podman to turn these off if the user
specifies --privileged.

We also might want to turn off certain user namespace flags that will cause
buildah and podman build to work slower when creating container images.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-11-19 19:14:21 -05:00
Daniel J Walsh c725dead10 Start to store SELinux labels in layer store
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-10-18 16:16:30 -04:00
Zac Medico c8ba057fc0 Add lock sanity checks to Save() methods
I have experienced "layer not known" corruption triggered by concurrent
buildah/skopeo processes, and hopefully lock sanity checks will help to
prevent this kind of problem.

Signed-off-by: Zac Medico <zmedico@gmail.com>
2018-08-24 20:31:47 -07:00
Marco Vedovati d5c5ca29f3 Improve duplicate name error message on container create
Signed-off-by: Marco Vedovati <mvedovati@suse.com>

Make the error message more informative by specifying the duplicate name
and the existing container ID.
2018-06-19 20:02:51 +02:00
Nalin Dahyabhai 2b889d5441 Only try to copy new layers/images/containers if we create them
When creating new Layers, Images, or Containers, only try to copy the
newly-created results if we actually created them.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-05-07 10:35:28 -04:00
Nalin Dahyabhai d52c43300a Support for per-container uid/gid mapping: upper
Add support to the Store objects for per-container UID/GID mapping.
* UID and GID maps can be specified when creating layers and containers.
* If mapping options are specified when creating a container, those
  options are used for creating the layer which we create for the
  container and recorded with the container for convenience.
* A layer defaults to using the ID mapping configured for its parent, or
  to the default which was used to initialize the Store object if it has
  no parent.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-04-03 10:34:32 -04:00
Nalin Dahyabhai d1034eef31 Always return deep-copied layer/image/container info
Always copy slices and maps in Layer, Image, and Container structures
before handing them back to callers so that, even if they modify them
directly, they won't accidentally mess with our in-memory copies of
those fields in the copies of the structures that we're using.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-03-07 17:07:38 -05:00
Nalin Dahyabhai 76abf73511 Track the digests of "big data" items
Teach image and container store types to also track the digests of "big
data" items that we have them store.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-10-02 17:50:00 -04:00
Daniel J Walsh 9587a70b21 Merge pull request #107 from nalind/preallocate-slices
Preallocate some slices that we build up
2017-09-30 07:07:48 -04:00
Nalin Dahyabhai 6b3dbfb5f7 Initialize Flags and BigDataSizes maps
When we read itms from disk, if maps in the structures are empty, they
won't be allocated as part of the decoding process.  When we
subsequently go to read or write something from such a map, make sure
it's been initialized.

Add some validation of names that we convert to file names, and of
digest values, so that we can be more precise about the error code we
return when there's a problem with the values.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-09-29 17:58:47 -04:00
Nalin Dahyabhai d2a9cbd86d Preallocate some slices that we build up
Take a guess at the final size of some slices that we build up item by
item, and try to allocate enough capacity for them before starting to
build them.  It's probably not a big speedup, though.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-09-29 15:00:59 -04:00
Nalin Dahyabhai 2801f2dfc1 Also dedupe layer/image/container names at create
We already deduplicated names in Store.SetNames(), but we weren't also
doing that when creating layers, images, and containers, or in the
individual store SetNames() methods.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-09-29 15:00:09 -04:00
Nalin Dahyabhai 428b5bd123 Create errors using "errors"
Use the standard library's "errors" package to create errors so that
backtraces in wrapped errors terminate at the point where the error was
first wrapped, and not at the line where we created the error, which
isn't as useful for troubleshooting.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-09-01 17:04:56 -04:00
Daniel J Walsh 12de881f2e Merge pull request #66 from runcom/memory-hungry-not
layers|containers: do not allocate slices at every delete
2017-06-19 11:50:32 -04:00
Antonio Murdaca 9986d86f67 layers|containers: do not allocate slices at every delete
When Delete:ing a layer or a container the code was always allocating a
new slice just to remove an element from the original slice.
Profiling cri-o with c/storage showed that doing it at every delete is
pretty expensive:

```
         .          .    309:   newContainers := []Container{}
         .          .    310:   for _, candidate := range r.containers
{
         .          .    311:           if candidate.ID != id {
  528.17kB   528.17kB    312:                   newContainers =
append(newContainers, candidate)
         .          .    313:           }
         .          .    314:   }

         .          .    552:           newLayers := []Layer{}
         .          .    553:           for _, candidate := range
r.layers {
         .          .    554:                   if candidate.ID != id {
    1.03MB     1.03MB    555:                           newLayers =
append(newLayers, candidate)
         .          .    556:                   }
         .          .    557:           }
         .          .    558:           r.layers = newLayers
```

This patch just filters out the element to remove from the original
slice w/o allocating a new slice. After this patch, no memory overhead
anymore is shown in the profiler.

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-06-19 17:08:40 +02:00
Nalin Dahyabhai d09403673d Track creation dates for layers/images/containers
Add a Created field to Layer, Image, and Container structures that we
intialize when creating one of them.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-06-16 10:12:55 -04:00
Dan Walsh 739546540d Add read-only locks
We need to be able to acquire locks on storage areas which aren't
mounted read-write, which return errors when we attempt to open a file
in the mode where we can take write locks on them.  This patch adds a
read-only lock type for use in those cases.

A given file can be opened for read-locking or write-locking, but not
both.  Our Locker interface gains an IsReadWrite() method to let callers
tell the difference.

Based on patches by Dan Walsh <dwalsh@redhat.com>
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-06-12 10:40:39 -04:00
Dan Walsh dad5692fb7 Uneccessary Touch functions.
We don't need these Touch calls, since the Save function will handle it.

Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2017-06-07 16:58:11 -04:00
Dan Walsh e898c5da40 Only touch when images, containers, layers save function called
Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2017-06-02 16:20:00 -04:00
Nalin Dahyabhai 829d6f3fc0 Fix consistency errors after adding/removing items
Fix consistency errors we'd hit after creating or deleting a layer,
image, or container, by replacing the slice of items in their respective
stores with a slice of pointers to items, so that pointers in name- and
ID-based indexes don't become invalid when the slice is resized.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-06-02 13:22:47 -04:00
Dan Walsh 35aabc6ad6 Move storage/storage go objects to storage.
There is no reason for the extra directory level.

Also fixup some go lint issues
Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2017-05-16 17:25:11 -04:00