Commit Graph

228 Commits

Author SHA1 Message Date
Nalin Dahyabhai cf83825fdf Support for per-container uid/gid mapping: lower
Expose reading and writing ID mapping in the archive and chrootarchive
packages, and in the driver interface.  Generally this means that
when computing or applying diffs, we need to have ID mappings passed in
that are specific to the layers we're using.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-04-03 10:34:32 -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
Daniel J Walsh e773ff82c2 Pass MountLabel down to diff drivers
Currently when we do a commmit, we are mounting the container without using
the mountlabel.  In certain situations we can leak mount points where the
image is already mounted with a label.  If you then attempt to commit the
image, the kernel will attempt to mount the image without a label.  The
kernel will reject this mount since SELinux does not allow the same image
to be mounted with different labels.

Passing down the label to the diff drivers, fixes this issue.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-02-06 13:42:25 -05: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
Daniel J Walsh 53be0202c5 Start using drivers.Options for passing date to graphdrivers
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2017-09-19 21:15:29 +00:00
Daniel J Walsh 36a340fd92 Update packages to match latest code in moby/pkg
Had to vendor in a new version of golang.org/x/net to build
Also had to make some changes to drivers to handle
archive.Reader -> io.Reader
archive.Archive -> io.ReadCloser

Also update .gitingore to ignore emacs files, containers-storage.*
and generated man pages.

Also no longer test travis against golang 1.7, cri-o, moby have also
done this.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2017-09-12 18:00:29 +00: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
Nalin Dahyabhai ff4becdefd Fix handling of DiffOptions.Compression in Diff()
Properly heed the DiffOptions.Compression value when generating a layer
diff between a layer and its parent, when there's no tarsplit data.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-07-10 11:41:34 -04:00
Nalin Dahyabhai 4b17fd7788 Correct a comment: compression is not encryption
Correct a reference to "encryption" in a comment that should instead be
referring to "compression".

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-07-07 17:19:49 -04:00
Nalin Dahyabhai b20bd6d0bd Cache the digests, sizes, and compression type
Cache the digests and sizes of a diff, both compressed and uncompressed,
along with the type of compression detected for it, that's supplied to
ApplyDiff() or Put() in the layer structure, and add methods to find a
list of layers that match one or the other digest.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-06-20 12:30:28 -04:00
Nalin Dahyabhai cb889f427d Remove some unused values
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-06-19 11:57:19 -04:00
Daniel J Walsh 0b147f3290 Merge pull request #65 from nalind/diffoptions
Make Diff() methods take an optional *DiffOptions
2017-06-19 11:50:54 -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 32710454cb Make Diff() methods take an optional *DiffOptions
Add an optional *DiffOptions parameter to Diff() methods (which can be
nil), to allow overriding of default behaviors.

At this time, that's just what type of compression is applied, if we
want something other than what was recorded when the diff was applied,
but we can add more later if needed.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-06-16 10:50:08 -04: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
Nalin Dahyabhai 06e44e4cf8 Add read-only layer/image/container stores
Implement read-only versions of layer and image store interfaces which
allocate read-only locks and which return errors whenever a write
function is called (which should only be possible after a type
assertion, since they're not part of the read-only interfaces).

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-06-12 16:31:19 -04:00
Nalin Dahyabhai 8e8d96e771 Split layer and image stores into RO and RW kinds
Split the LayerStore and ImageStore interfaces into read-only and
write-only subset interfaces, and make the proper stores into unions of
the read-only and write-only method sets.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-06-12 10:44:36 -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 ac022ae1d0 Remove parentlayers lookup.
We don't do anything with these variables, and they break additionalstores
Signed-off-by: Dan Walsh <dwalsh@redhat.com>
2017-05-16 17:44:36 -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