Commit Graph

36 Commits

Author SHA1 Message Date
Giuseppe Scrivano 65b0c4b592 chunked: release zstd on termination 2022-01-07 21:28:16 +01:00
Giuseppe Scrivano 9d808fd79e chunked: reuse cache
try to reuse an existing cache object, instead of creating it for
every layer.

Set a time limit on how long it can be reused so to clean up stale
references.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-07 21:28:16 +01:00
Giuseppe Scrivano f19256c6aa chunked: move copy logic to storage_linux.go
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-07 21:28:16 +01:00
Giuseppe Scrivano 1c67dafd91 chunked: chunk deduplication
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-07 21:28:15 +01:00
Giuseppe Scrivano efdb305775 chunked: move cache to separate file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-24 13:28:25 +01:00
Giuseppe Scrivano 10ed9d2168 chunked: move discard call to outer scope
it solves a problem where the discard could be performed before the
compression handler was closed (through a deferred call).

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-24 13:28:25 +01:00
Giuseppe Scrivano 1f91974b86 chunked: support copy from uncompressed stream
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-24 13:28:25 +01:00
Giuseppe Scrivano fdb414ede4 chunked: add infra to dedup from partial file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-24 13:28:25 +01:00
Giuseppe Scrivano b3f7520616 chunked: allow streaming to the same file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-24 13:28:25 +01:00
Giuseppe Scrivano 7c509b750e chunked: rename types
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-23 14:11:16 +01:00
Giuseppe Scrivano b717e225f4 chunked: drop argument mode
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-23 14:11:16 +01:00
Giuseppe Scrivano 1da7a3c179 chunked: move check to helper function
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-23 14:11:16 +01:00
Daniel J Walsh 83aa81d4a6 Merge pull request #1077 from giuseppe/ignore-security-selinux
archive: ignore the security.selinux xattr
2021-11-29 10:59:56 -05:00
Giuseppe Scrivano 7f147b05f5 chunked: ignore security.selinux
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-26 11:00:59 +01:00
Giuseppe Scrivano 1b8c0c7582 chunked: add fallback for openat2
add a fallback mechanism when openat2 is not supported by the
underlying kernel.

If a call to openat2 fails with ENOSYS, then fallback to a user space
lookup.  Generally the user space lookup is not safe, since symlinks
lookups are vulnerable to TOCTOU attacks, but in this case where the
rootfs is being created, there are no other processes modifying it
thus such lookups can be considered safe.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-26 09:29:55 +01:00
Giuseppe Scrivano 74b13e5e8d chunked: refactor common code in a function
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-25 14:49:35 +01:00
Giuseppe Scrivano 3c97403d7c chunked: wrap the correct underlying error
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-25 14:49:08 +01:00
Giuseppe Scrivano 53b286a81b chunked: fix setting attributes for symlinks
when dealing with symlink, open the parent directory and use the
symlink basename to set its attributes.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-23 21:13:23 +01:00
Giuseppe Scrivano f8d4421709 chunked: create missing parent directories
when creating a new file, handle the case where any of the parent
directories are missing and create them automatically if needed.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-23 21:13:22 +01:00
Giuseppe Scrivano 3e75bcacec chunked: improve error messages
add more context to the error messages generated while unpacking the
image.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-23 21:13:22 +01:00
Giuseppe Scrivano 5d127f2bb6 pkg/chunked, pkg/idtools: adjust error message
since we now support reading additional IDs with libsubid, clarify
that the /etc/subuid and /etc/subgid files are honored only when
shadow-utils is configured to use them.

[NO TESTS NEEDED]

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-08 13:12:45 +01:00
Giuseppe Scrivano 3c9b03d71b chunked: fix another occurrence of linkat
Using unix.AT_EMPTY_PATH requires CAP_DAC_READ_SEARCH.  Use an
equivalent variant that uses /proc/self/fd that can be used with
rootless.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-03 10:32:55 +01:00
Giuseppe Scrivano 8b3751e3ca chunked: implement OSTree deduplication
if the option ostree_repos is set:

    [storage.options]
    pull_options = {enable_partial_images = "true", ostree_repos = "/foo:/bar"}

then attempt to deduplicate from the specified list of OSTree repositories.

In order to be usable, an OSTree repository must be configured to track
the checksum for its files payload (payload link), that is disabled by
default:

ostree config --repo=/path/to/repo set core.payload-link-threshold N

Where N is the minimum size for files to be tracked by their payload
and must be a nonzero value.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-24 10:56:46 +02:00
Giuseppe Scrivano 65ce6e014c chunked: fix linkat for rootless
Using unix.AT_EMPTY_PATH requires CAP_DAC_READ_SEARCH.  Use an
equivalent variant that uses /proc/self/fd that can be used with
rootless.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-06 10:37:16 +02:00
Giuseppe Scrivano c157afaa27 chunked: restrict dedup with hard links
before deduplicating with hard links make sure the two files share the
same UID, GID, file mode and extended attributes.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-06 10:37:15 +02:00
Giuseppe Scrivano e0a2befc58 chunked: cache all the files with the same digest
this is a preparation change for the next commit.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-03 13:03:03 +02:00
Giuseppe Scrivano 84f6c8f693 chunked: do not store the digest if it is empty
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-03 12:26:19 +02:00
Giuseppe Scrivano db11cbef4f chunked: estargz support
in addition to zstd:chunked, add support for the estargz format.

estargz is maintained at github.com/containerd/stargz-snapshotter

Images using estargz can be used on old clients and registries that
have no support for the zstd compression algorithm.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-25 16:16:20 +02:00
Giuseppe Scrivano d739302b1d chunked: remove unused args
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-18 09:25:50 +02:00
Giuseppe Scrivano b7bee72745 chunked: fix fd leak on error
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-18 08:17:40 +02:00
Giuseppe Scrivano a6224472dd chunked: remove unused argument missingDirsMode
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-18 08:17:39 +02:00
Giuseppe Scrivano a39418e977 chunked: add new pull option use_hard_links
if the option use_hard_links is set:

[storage.options]
pull_options = {use_hard_links = "true"}

then attempt to deduplicate files using hard links first.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-18 08:17:39 +02:00
Giuseppe Scrivano e5b1bbd274 chunked: allow to disable partial images feature
enable partial pulls only when it is explicitely configured in the
storage.conf file:

[storage.options]

pull_options = {enable_partial_images = "true"}

This is to prevent the experimental feature to leak into CRI-O.

The default value will change in future once the feature is stable.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-17 09:32:36 +02:00
Miloslav Trmač 41e2fb4e9b Split pkg/chunked.ZstdCompressor into a separate subpackage
containers/image/pkg/compression depends on that function, so it's
highly undesirable for it to drag in all of containers/storage.

So, move it into a separate subpackage, along with its exclusive
dependency tree.

Code that is called both from the new pkg/chunked/compressor
and the original pkg/chunked has been moved into pkg/chunked/internal ,
so that we don't expose any new public API. That move was made
purely mechanically without any concern for conceptual consistency,
to minimize the size of the dependency (and not to spend time on
that until the concept is proven to be useful).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-07-23 21:43:52 +02:00
Giuseppe Scrivano ef96e9287e chunked: fix the path used for layers dedup
`source` is the path to the layer that already contains the file that
is looked up.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-07-01 00:02:06 +02:00
Giuseppe Scrivano b723ae9831 chunked: fix build on other platforms
fix package build on !linux platforms

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-05-25 14:42:28 +02:00