Commit Graph

117 Commits

Author SHA1 Message Date
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
Giuseppe Scrivano a6fec757c8
store: keep graph lock during Mount
This solves a race condition where a mountpoint is created without the
home mount being present.

The cause is that another process could be calling the graph driver
cleanup as part of store.Shutdown() causing the unmount of the
driver home directory.

The unmount could happen between the time the rlstore is retrieved and
the actual mount, causing the driver mount to be done without a home
mount below it.

A third process then would re-create again the home mount, shadowing
the previous mount.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1757845

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-12-20 21:49:18 +01:00
Sascha Grunert 67ae39c0b3
Lazy initialize the layer store
The layer store gets memoized in any case so we can skip the initial
setup on store load.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2019-12-09 15:01:14 +01:00
Daniel J Walsh ff125a5657
Move storage options to driver specific entries
Storage options are really driver specific and it is when distributions set
defaults, they should not effect the user if he changes the default driver.

By moving the storage options to be driver specific, we can make sure all
drivers only document and support their options.

With this patch we will continue to support the global mountopt but the driver
specific version will override the global mountopt.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-10-11 16:26:42 -04:00
Giuseppe Scrivano 37930824fb
config: drop skip_mount_home
it was needed only with OSTree to allow hard links.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-05 20:27:46 +02:00
Giuseppe Scrivano 7a0d58dab5
storage: drop ostree deduplication
it was an attempt to use OSTree to deduplicate files, at the time we
already had a dependency on OSTree for system containers in
containers/image.  Since the feature never really took off, let's just
drop it.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-05 20:27:45 +02:00
Daniel J Walsh 45d208f3af
Merge pull request #436 from nalind/enobigdata
ImageBigData: distinguish between no-such-image and no-such-item
2019-09-27 07:47:11 +02:00
Nalin Dahyabhai 2a6b234dd4 ImageBigData: distinguish between no-such-image and no-such-item
When reporting an error from store.ImageBigData(), distinguish between
cases where we can't find the specified image, and where we found the
image, but it didn't have a matching requested item.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-09-25 10:41:49 -04:00
Nalin Dahyabhai b5a276ea64 ImageSize: don't get tripped up by images with no layers
Images don't have to have layers, so they don't have to have top layers,
and we shouldn't return an error when attempting to determine the size
of such an image.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-09-25 10:27:01 -04:00
Valentin Rothberg a427596d18 wrap ID or digest to ErrImageUnkown errors
Wrap the ID or the digest to ErrImageUnknown errors to avoid ambiguity
which image is unknown.  Consumers of the storage library may have
multiple subsequent calls to the storage API where it can be unclear
which image is unknown.  Wrapping the ID and digest attempts to avoid
this ambiguity.

Related-to:    github.com/containers/libpod/issues/2979
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-09-11 10:03:08 +02:00
Daniel J Walsh 976fe22092
Add storage options to IgnoreChownErrors
Modified patch of Kevin Pelzel.

Also changed ApplyDiff to take new ApplyDiffOpts Struct.

Signed-off-by: Kevin Pelzel <kevinpelzel22@gmail.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-07-26 06:05:27 -04:00
Nalin Dahyabhai 47335895e5 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
Nalin Dahyabhai fe3d4bcf9b drivers.Options: pass RunRoot in, too
Pass the library-level RunRoot in as part of the Config struct that we
pass to lower-level driver initialization functions.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-06-20 11:38:33 -04:00
Daniel J Walsh b69999d84c
Add function to parse out mount options from graphdriver
We have a bug in podman that uses the defaultGraphDriver options
for returning the MountOptions rather then the driver overrides
from the user.

This PR adds a new interface GetMountOptions which parses the callers
graphdriveroptions and return the mountoptions

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-06-07 10:18:39 -04:00
Nalin Dahyabhai 88afc63e89 CreateContainer: don't worry about mapping layers unless necessary
When creating a container, don't worry about whether or not the base
image's top layer has the right ID mappings in cases where the base
image doesn't have a top layer.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-05-07 16:21:04 -04:00
Daniel J Walsh ef42340c2e
Revert "Add MountTempFromSource and RemoveTemp interfaces"
This reverts commit e9695564db.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-05-02 11:54:55 -04:00
Daniel J Walsh e9695564db
Add MountTempFromSource and RemoveTemp interfaces
These interfaces can be used to setup a graphdriver mountpoint
of the source directory for use within a container.
The RemoveTemp interface umounts the mountpoint and then removes
all of the modified data in the graphdriver for this source directory.

The primary use case of these interfaces is for container engines that
want to mount a directory from the host system into the container. The
source dirctory then can be modified without actually changing the
directory on the host.

Containers will use these interfaces for sharing packaing cache directories
like /var/cache/dnf, to help speed up container builds.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-04-29 14:46:40 -04:00
Daniel J Walsh e3394b6beb
Fix handling of additional stores
When you build an image with a parent layer in read-only stores
and the new image in read/write stores, the first time you try
to create a container based on the image, it fails, since it
cannot find the image in the same store.

This patch looks not only in the same store, but all of the stores
available.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-04-19 04:36:07 -04:00
Valentin Rothberg 8017d7a735 add digest locks
Add a method to generate a lock file for a specific digest.  Such a
digest-specific lock file is needed to synchronize threads and processes
when copying blobs from a registry to the containers-storage.

Whenever a layer is about to get copied, the lock must be acquired which
indicates to other processes and threads that the layer/blob is already
being copied.

To avoid leaking file descriptors for long-living users of
containers/storage, such as CRI-O, open and close the file on demand
during Lock() and Unlock().  The internal reference counters allows to
determine if we are the first or last user.

Note: as deleting the lock files is subject to race conditions, we place
the lock files in a graph-specific directory in the runroot.  Since the
runroot is a tmpfs, the files will be cleanup during reboot.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-03-28 09:53:02 +01:00
Daniel J Walsh 877c68cba0
Move pkg/util default storage functions from libpod to containers/storage
In an effort to remove cross vendoring, trying to fix buildah from importing
from libpod.  I beleive these libraries make more sense in containers/storage
then in libpod.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-03-19 08:33:42 -04:00
Nalin Dahyabhai b41a2a8b83 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
Nalin Dahyabhai af52b699ef Switch to read-only locks in some places
In Store methods that don't expect to change state, use a read lock.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-02-26 14:19:53 -05:00
Nalin Dahyabhai 6d609d1042 GetStore(): resolve passed-in paths to absolute paths
Resolve passed-in locations to absolute paths at startup.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-02-18 11:23:05 -05:00
Valentin Rothberg 68d65106a0 enable parallel blob reads
Enable executing parallel `GetBlob()` executions in containers/image by
using reader-lock acquisitions in `ImageBigData()` and `Diff()`.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-02-15 15:00:37 +01:00
Valentin Rothberg d89252da40 avoid `defer x.Unlock()` pattern in loops
Deferring method calls on loop variables must be avoided by all means as
the calls will be invoked on the last item of the loop.

The intermediate fix used in this commit is to allocate a new variable
on the heap for each loop iteration.  An example transformation is:

FROM:
for _, x := range x_slice {
	x.Lock()
	defer x.Unlock()
}

TO:
for _, x_itr := range x_slice {
	x := x_itr
	x.Lock()
	defer x.Unlock()
}

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-02-15 09:49:44 +01:00
Nalin Dahyabhai 771658dbb8 Make use of overlay.override_kernel_check a warning instead of an error
When we removed all traces of override_kernel_check, we created a
situation where older configuration files would suddenly start causing
us to emit an error at startup.  Soften that to a warning, for now at
least.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-02-12 13:58:36 -05:00
Nalin Dahyabhai ccf8bef6fa Teach images to hold multiple manifests
Change how we compute digests for BigData items with names that start
with "manifest" so that we use the image library's manifest.Digest()
function, which knows how to preprocess schema1 manifests to get the
right value, instead of just trying to finesse it.

Track the digests of multiple manifest-named items for images.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-02-07 10:27:36 -05:00
Nalin Dahyabhai a74d0441db Don't ignore errors reloading layer/image/container lists
Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-02-05 10:19:46 -05:00
Urvashi Mohnani 74834ee9e0 Move structs for storage.conf to pkg/config
Need to access the storage structs in the machine-config
operator code for container runtime configuration but
with it being in store.go, it is pullng in way too many
dependencies. Moving it out to a separate package cuts down
the dependencies by a huge amount.

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
2019-02-03 21:21:32 -05:00
Daniel J Walsh 891018027e
Merge pull request #271 from nalind/template-layers
drivers: add CreateFromTemplate()
2019-01-18 10:56:56 -05:00
Nalin Dahyabhai c8dc9b79a8 Remove mapped layers first
When removing an image, remove the image's mapped top layers before the
image's "main" top layer, in case the graph driver is hiding a
dependency between the mapped layers and the "real" one (as it's allowed
to do).

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-01-17 14:30:04 -05:00
Nalin Dahyabhai c073b43547 Add a CreateFromTemplate() method to drivers, and use it for mapped layers
Add a CreateFromTemplate() method to graph drivers, and use it instead
of a driver-oblivious diff/put method when we want to create a copy of
an image's top layer that has the same parent and which differs from the
original only in its ID maps.

This lets drivers that can quickly make an independent layer based on
another layer do something smarter than we were doing with the
driver-oblivious method.  For some drivers, a native method is
dramatically faster.

Note that the driver needs to be able to do this while still exposing
just one notional layer (i.e., one link in the chain of layers for a
given container) to the higher levels of the APIs, so if the new layer
is actually a child of the template layer, that needs to remain a detail
that's private to the driver.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-01-17 14:28:40 -05:00
Nalin Dahyabhai bd6cac944a Remove the last traces of the "override_kernel_check" option
The logic that depended on override_kernel_check was changed to test for
the feature at runtime, so we don't need to be suggesting to people that
they need to set this option, or that the option is even a thing.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-01-16 16:59:39 -05:00
Daniel J Walsh 82e48f34ef
Expose path to default config file
We need to expose this file path in podman info
to make it easier for users to discover where
the configuration file is.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-01-03 16:51:25 -05:00
Nalin Dahyabhai 80e6aee4e2 imageTopLayerForMapping: report the right layer ID in error messages
If we fail to create an ID-mapped copy of an image's layer, report the
ID of the layer that we were attempting to create an ID-mapped copy of,
instead of attempting to log the ID of its parent, which might not
exist.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-12-06 13:50:38 -05:00
Daniel J Walsh 9d3838cd43
Merge pull request #226 from rhatdan/getmountopts
Allow the passing in and retrieval of mount options
2018-11-27 14:48:09 -05:00
Daniel J Walsh 01ab2352a3
Merge pull request #245 from rhatdan/deletecontainer
Should still delete container if layer does not exist.
2018-11-27 14:47:17 -05:00
Daniel J Walsh 93219f2b8c
Should still delete container if layer does not exist.
We have seen situations in buildah where a container is being
built and user hits ^c, then he ends up in a situation where
he can not delete container, since layer does not exist.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-11-27 10:14:32 -05:00
Šimon Lukašík ed97cd56f0 Refactor ParseIDMap, allow parsing multiple maps at once
I found that other projects, tend to parse multiple maps at once. So, we may
want to allow the base library to do so in order to decrease complexity in the
upper layers.

This is follow-up on previous refactoring in 7b209d36fd, I didn't got
it right on first try, sry.

Signed-off-by: Šimon Lukašík <isimluk@fedoraproject.org>
2018-11-26 20:11:49 +01:00
Daniel J Walsh ab6be50561
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
Miloslav Trmač 67d32d7678 Add missing parameters to errors.Wrapf
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-11-14 04:00:47 +01:00
Šimon Lukašík 7b209d36fd Refactor: Extract ParseIDMap func to idtools package
where it belongs.

I have noticed that this parsing gets spread across projects. Basically, the
very same method is present in libpod, buildah, and cri-o projects. We better
start re-using this code from single place or soon everyone has its own version.

Signed-off-by: Šimon Lukašík <slukasik@redhat.com>
2018-11-10 17:53:54 +01:00
Daniel J Walsh 24f0de4570
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
Daniel J Walsh b6ccc0acfa
Add MountOpts to stop adding fields to Get Interface
This patch adds a MountOpts field to the drivers so we can simplify
the interface to Get and allow additional options to be passed in the future.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-10-05 09:23:46 -04:00
Nalin Dahyabhai 3df3c9f9ae Hold the layer store lock while diffing
While generating a Diff, hold the lock on the layer store until after
we've completely finished building the diff.

There's an internal Mount/Unmount being done so that we can read the
layer's contents, and we don't update the mount counts properly if we're
not still holding the lock when the layer store's Unmount() method is
called, which doesn't happen until the ReadCloser that Diff() returns
gets closed.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-09-13 15:45:37 -04:00
Nalin Dahyabhai c8670efc15 Fix a lock inversion
In CreateContainer(), don't use ROLayerStores() to get a list of the
read-only layer stores after we've acquired the lock on the writeable
layer store.  ROLayerStores() acquires the graph lock, which we should
never try to acquire while we're holding the layer store lock.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-09-12 14:18:48 -04:00
Giuseppe Scrivano 1897396330
drivers: inform Mount of the mappings used by the container
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-07-26 06:12:42 +02:00
Giuseppe Scrivano 883ee15e4d
store: use the original image if the driver supports shifting
do not create a new image with different uid/gid if the driver has
support for shifting.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-07-26 06:12:40 +02:00
Giuseppe Scrivano 1e60d8a4c3
store: include layerID in the error message
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-07-26 06:12:39 +02:00
Daniel J Walsh 8b1a0f8d68
Add default mount options to pass to drivers
I believe we should be running container images mounted with nodev by default.
This would eliminate the disk of a device sneaking into the container without
being on the approved list.  This would give us the same or potentially additional
security over the device cgroup.

It would be nice if this could be passed in on an image by image basis.  So users
could also specify if they want nosuid images.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-07-18 10:20:27 -04:00