Commit Graph

57 Commits

Author SHA1 Message Date
Nalin Dahyabhai 0f2bccfa56 Complete "pulling up" of images in updateNames()
When updateNames() copies an image's record from a read-only store into
the read-write store, copy the accompanying data as well.

Add fields for setting data items at creation-time to LayerOptions,
ImageOptions, and ContainerOptions to make this easier for us and our
consumers.

Replace the store-specific Create() (and the one CreateWithFlags() and
Put()) with private create() and put() methods, since they're not
intended for consumption outside of this package, and add Flags to the
options structures we pass into those methods.  In create() methods,
make copies of those passed-in options structures before modifying any
of their contents.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-03-31 10:36:30 -04:00
Nalin Dahyabhai 87b926f5f2 test helper: maxArgs = 0 is actually a meaningful value
We do have commands that don't take any arguments, and quietly ignoring
arguments when they get them is not a good idea.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-01-27 09:21:43 -05:00
Nalin Dahyabhai 6d91bc12f3 cmd: add a CLI wrapper for GarbageCollect
Add "gc" as an action for the CLI wrapper, for running the
GarbageCollect() method.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-01-26 16:09:00 -05:00
Alexander Larsson d6cb12d10f Add test for transient mode
If STORAGE_TRANSIENT is set to 1 then transient mode will be enabled
in the tests.

Also adds overlay-transient to the cirrus CI.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2022-11-14 16:36:30 +01:00
Miloslav Trmač d60159bc30 Add more error handling to cmd/containers-storage
Introduce an outputJSON helper to decrease repetition.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-14 17:17:54 +02:00
Miloslav Trmač ace9c41df3 Consolidate error reporting in cmd/containers-storage
Have the action handlers return an error value, and let
main() format that error, if any; this avoids duplicated
error formating code in the action handlers, dropping
89 lines.

This might change the error format in some cases (typically
%v vs. %+v).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-14 17:17:53 +02:00
Miloslav Trmač c497e66e9a Work around a paralleltest crash
> ERRO [runner] Panic: paralleltest: package "main" (isInitialPkg: true, needAnalyzeSource: true): runtime error: index out of range [0] with length 0: goroutine 5859 [running]:
> ...
> github.com/kunwardeep/paralleltest/pkg/paralleltest.isTestFunction(0x1b7d8c0?)
> 	github.com/kunwardeep/paralleltest@v1.0.6/pkg/paralleltest/paralleltest.go:252 +0x165

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-10-14 17:17:53 +02:00
Miloslav Trmač fbd5eff94d Simplify array concatenation
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:31:43 +02:00
Miloslav Trmač d80b48f97b Remove an unused assignment
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:31:42 +02:00
Miloslav Trmač b0c2fe5f20 Add missing error handling
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:31:41 +02:00
Miloslav Trmač be215b91d7 Fix JSON annotation
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:31:40 +02:00
Miloslav Trmač 7635db182b Use io.ReadAll instead of ioutil.ReadAll
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:30:46 +02:00
Giuseppe Scrivano cf998256f7
store: don't ignore empty mappings for top layer
do not pick the first available image if it was requested to not use
any mapping.

It causes a problem where an image is already present in the local
store with a mapping, then a container that doesn't specify any
mapping would end up to reuse that:

$ podman system reset -y
$ podman run --rm --uidmap 0:10000:1000 centos ls -ld /home
drwxr-xr-x. 2 root root 6 Nov  3  2020 /home

$ podman run --rm centos ls -ld /home
drwxr-xr-x. 2 10000 10000 6 Nov  3  2020 /home

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-10 17:43:02 +02:00
Giuseppe Scrivano 62b88ea445
containers-storage: add --volatile to container create
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-03-01 21:11:40 +01:00
Daniel J Walsh 120cc997d2
Move storageOpts structures into types subdir to shrink bindings.
Currently when we build podman bindings we are pulling in the entire
storage libraries, even though we only need a few structures and
functions.

Testing with the following program

```
package main

import (
	"fmt"
	"github.com/containers/storage/types"
)

func main() {
	fmt.Println(types.GetRootlessRuntimeDir(0))
}
```

Removing types above gives me compile size of the the program

du -s t.old t.new
9640	t.before
3232	t.after

Currently these functions are being vendored into
containers/common/pkg/config, which leads to large size in podman-remote
and podman bindings.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-02-26 05:34:09 -05:00
Giuseppe Scrivano 9cefbaec5f
containers-storage: support layer bigdata
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-02-02 11:39:03 +01:00
Daniel J Walsh 3fb27a360c
new interface for MountImage added
Interface added to mount image rootfs without any container.
image can be mounted only in ReadOnly mode.

Signed-off-by: Kunal Kushwaha <kunal.kushwaha@gmail.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-07 13:45:51 -04:00
yangfeiyu20102011 bb6c40aa2e
new interface Free for deleting Store object
New interface for deleting already-created Store object

When the store is not needed, it is neccessary to remove
it and release the memory

Signed-off-by: yangfeiyu <yangfeiyu20102011@163.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-06-29 13:01:33 -04:00
Valentin Rothberg c677b7d069 Move opts to internal/opts and fork docker filters
The dependency on docker's filter package prevents us from using newer
versions of docker/moby where the package's API has changed.  The filter
package is small enough to justify maintaining a small fork of it. Also,
since the opts package is only used for the `containers-storage` binary
and is not part of the actual storage library, move it to the ./internal
directory to make it clearer that this is an internal API.

Fixes: #450
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-10-29 13:12:13 +01: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
Nalin Dahyabhai 2bfb2b5b41 Add tests for the ReadOnly field
Check that layers and images in read-only stores are correctly marked as
such.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-05-21 11:54:50 -04:00
Nalin Dahyabhai 85c846a2bb tests: test layerless images
Test creation of images without layers, and containers based on them.

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
Giuseppe Scrivano 3dd479804f
storage: move the logic to detect rootless into utils.go
add a helper function that automatically detects the UID when running
in a user namespace..

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-04-05 15:11:57 +02: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 06025caa49 CLI helper: print backtraces with errors
Print backtrace information when displaying an error returned by our
API, to make troubleshooting tests a bit easier.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-02-26 14:19:15 -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
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
Š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
Š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 1538971882
Change Mounted to return the number of times mounted
podman unmount wants to know if the image is only mounted 1 time
and refuse to unmount if the container state expects it to be mounted.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-07-17 16:27:27 -04:00
Daniel J Walsh 1075a73cac
Modify storage to allow callers to determine if a mount point is mounted
Add force to umount to force the umount of a container image
Add an interface to indicate whether or not the layer is mounted
Add a boolean return from unmount to indicate when the layer is really unmounted

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-07-17 14:00:15 -04:00
Nalin Dahyabhai c16e8ec318 Add Store.ContainerSize()
Add a ContainerSize() method, which knows how to compute the sizes of
container, so that our callers don't need to all be updated when we make
changes to how we store them.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-05-30 17:16:53 -04:00
Nalin Dahyabhai ad6eeb6517 Add Store.ImageSize()
Add an ImageSize() method, which knows how to compute the sizes of
images, so that our callers don't need to all be updated when we make
changes to how we store them.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-05-30 17:16:53 -04:00
Nalin Dahyabhai 6cb6f31c03 Add mapped top layers to images
Allow images to have multiple top layers which should only differ by
which UID/GID mappings are used in them, to make creating multiple
containres which use the same mappings faster.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-05-30 13:46:08 -04:00
Nalin Dahyabhai b22d9f20d3 Exercise Copy[File]WithTar, optionally with Chown flags
Add integration tests to exercise CopyFileWithTar and CopyWithTar, both
with and without Chown flags.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-05-01 10:27:34 -04:00
Nalin Dahyabhai 13ae73afef CLI: fix JSON output for layer/container-parent-owners
Provide the information that was actually requested when we produce JSON
output for the layer-parent-owners and container-parent-owners commands.
Carried over from #156.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-04-10 14:39:47 -04:00
Nalin Dahyabhai aefafeeb85 Add LayerParentOwners()/ContainerParentOwners()
Add store methods for finding the list of UIDs and GIDs which probably
need to be mapped if a given layer or container's layer, which has to
have been mounted at least once in order for us to know where it goes,
is going to be used for a container that is run with the configured ID
mappings in a separate user namespace.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2018-04-03 10:34:32 -04:00
Nalin Dahyabhai b71d4c4197 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 1824cf917a Add explicitly-settable digest values for images
Add explicitly-settable digest values for images that are treated mostly
like the implicit digests that we track for manifests, for the sake of
v1 images which have manifests that need to be preprocessed before being
digested to produce an image's digest value.  We'll still have the
digest of the unprocessed manifest, but that shouldn't hurt.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-12-11 16:16:46 -05:00
Nalin Dahyabhai 2a564455fd Add a notion of image "digests" based on their "manifest" data
Add a "digest" of an image that is equal to the digest of its big data
item named "manifest", if it has one, that we can index and use for
locating images.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-11-16 11:52:25 -05:00
Nalin Dahyabhai d8c5c0a1f8 Make the CLI use either all defaults, or none
Make the CLI use all of the default settings if none of them are
overridden on the command line, or none of them, if any are overridden.
Any other behavior is hard to use in integration tests, and confusing.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-10-03 09:42:48 -04:00
Nalin Dahyabhai 240fe6016c Wrap new data retrieval APIs in the CLI tool
Add CLI wrappers for the store's
  ImageBigDataDigest
  ImageBigDataSize
  ContainerBigDataDigest
  ContainerBigDataSize
methods.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-10-02 17:50:01 -04:00
Nalin Dahyabhai 84922714d2 Merge pull request #108 from nalind/layerless-images
Stop rejecting creation of images with no layers
2017-09-29 16:16:54 -04:00
Daniel J Walsh 46acf2c518 Merge pull request #110 from nalind/dedupe-names
Be more thorough about deduplicating names
2017-09-29 16:00:40 -04:00
Nalin Dahyabhai d659609729 Clean up CLI display of settings
Change the labels we use when displaying our settings as part of a debug
log, and prepend that information to the "status" output.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-09-29 15:07:12 -04:00
Nalin Dahyabhai 2e93f81ed8 Fix weird formatting of CLI "create-*" output
Fix the weird formatting of the output from the various create commands
and the import-layer command.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2017-09-29 15:07:05 -04:00