Commit Graph

30 Commits

Author SHA1 Message Date
Paul Holzinger ea1eeb523f
remove github.com/crc-org/crc/v2 dependency
There is one user in the code and one in the tests.
First the test is testing an external function that doesn't seem to make
a lot of sense.

Second when we pull the machine image and renmae doesn't work it would
mean it is on a different disk. That should never happen.
The oci pull is to
~/.local/share/containers/podman/machine/<provider>/cache/<sha>/...
and then it gets moved to
~/.local/share/containers/podman/machine/qemu/cache/<sha>.<extension>

These can under normal circumstances never be on different disk as it
would mean the pulled sha is known ahead of time and then that the blob
path is a mount point which is unrealistic and not something we have to
support.

It also removes three transitive dependencies.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-03-31 14:39:51 +02:00
Paul Holzinger e9fb805522
update golangci/golangci-lint to v1.63.4
Fix new issues found by usetesting, mainly we should use t.TempDir() in
test which makes the code better as this will be removed on test end
automatically so no need for defer or any error checking.
Also fix issues reported by exptostd, these mainly show where we can
switch the imports to the std maps/slices packages instead of the
golang.org/x/exp/... packages.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-01-07 15:48:53 +01:00
Paul Holzinger f630eebcfa
pkg/machine/compression: skip decompress bar for empty file
When the file is empty it is possible our code panics as bar.ProxyReader
returns nil when the bar is finished which is the case for 0 size as it
doesn't have to read anything from there. However as this happens on
different goroutines it is race and most of the time still works.

To fix this simply skip the progress bar setup for empty files.

While at it fix the deprecated argument in the tests.

Fixes #23281

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-07-18 13:23:00 +02:00
Mario Loriedo 82597144b6 Machine decompress.go refactoring follow-up
1. Added the xz decompression unit tests

2. Removed the xz implementation to use the one from c/images

3. Removed the specific macos gzip, zstd compressor and use
   the generic compressor but with SparseWriter if GOOS == darwin

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-03-13 00:58:50 +01:00
openshift-merge-bot[bot] 15e508a639
Merge pull request #21936 from l0rd/vmfile-peek
Don't read full VM File before decompressing
2024-03-07 16:40:09 +00:00
Miloslav Trmač 7bfe5e700f Fail on failures to close the file descriptors, and especially the SparseWriter
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-03-07 14:46:17 +01:00
Miloslav Trmač 5e0b7e54c0 Avoid reliance on fs.ErrClosed in SparseWriter users
Neither of the SparseWriter users actually _wants_ the underlying
WriteSeeker to be closed; so, don't.

That makes it clear where the responsibility for closing the file
lies, and allows us to remove the reliance on the destinations
reliably returning ErrClosed.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-03-07 14:46:12 +01:00
Mario Loriedo 724c5a06ba Don't read full VM File before decompressing
While working on #21592 we figured out that the
the full VM File was loaded in memory when detecting
the file format, but only a few bytes are needed.
This commit address that.

[NO NEW TESTS NEEDED]

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-03-07 10:11:11 +01:00
Mario Loriedo 8f02822c12 Remove xz unit tests as they are flaky
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-28 15:37:15 +01:00
Mario Loriedo 7b6d9a586e Fixup: avoid overriding io.Copy error
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-27 16:48:47 +01:00
Mario Loriedo 59704665ae Avoid overriding io.Copy error
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-27 16:16:44 +01:00
Mario Loriedo 24a33a538c Move code for sparse optimized copy to a dedicated method
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-27 15:59:56 +01:00
Mario Loriedo f099250beb Better file close and err handling
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-25 22:29:03 +01:00
Mario Loriedo ea4553d590 integrating changes from #21768
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-25 22:29:02 +01:00
Mario Loriedo fa99b9be93 renamed testfiles as testdata
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-25 22:29:02 +01:00
Mario Loriedo 0b3f3f0ef1 Use faster gzip reader
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-25 22:29:02 +01:00
Mario Loriedo 2245cf8dc4 Remove duplication and make consistent usage of the progress bar
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-25 22:29:02 +01:00
Mario Loriedo c42d3a74ed Add a comment to explain why we look at file name for zip files
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-25 22:29:02 +01:00
Mario Loriedo 95aa2c4e68 Use github.com/stretchr/testify assert in compression_test.go
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-25 22:29:02 +01:00
Mario Loriedo 88af8852db Refactor machine decompress.go
Added some tests to verify that files extractions works
with different compression format.

Created a decompressor interface with 2 main methods:
  reader(): returns an io.Reader for the specific compression algorithm
  copy(): extracts the compressed file into the file provided as param

Created 5 decompressor types:
- gzip: extract gzip files
- xz: extract xz files
- zip: extract zip files
- generic: extract any other file using github.com/containers/image/v5/pkg/compression
- uncompressed: only do a copy of the file

Minor fix to the progress bar instances: added a call to bar.Abort(false)
that happens before Progress.Wait() to avoid that it hangs when a bar is
not set as completed although extraction is done.

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-25 22:29:02 +01:00
Miloslav Trmač 5d303ca267 Reformulate sparseWriter to deal with starting/ending zeroes explicitly
... instead of using a multi-variable state machine.

The net effect of this code is exactly the same as the previous implementation,
except:
- the operation after Write() returns an error might differ
- If the file ends with zeroes, we don't Seek(-1), and
  we don't create a hole at all if it is too small, preferring
  to save a syscall.

But this formulation is hopefully easier to prove correct.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-02-23 02:09:39 +01:00
Miloslav Trmač c5434bf711 Expand sparseWriter tests
- Add more test cases
- Test that we create the expected (large) holes;
  don't enforce anything for the <zerosThresholt ones.

O)nly changes test code, should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-02-23 02:09:39 +01:00
Brent Baude a31e8d2a23 zstd now default compression for podman machine
given that we are moving to building our own machine images, we have
decided to use zstd compression as it is superior in speed to the
alternatives.  as such, this pr adds zstd to our machine code; and also
has to account for dealing with sparseness on darwin; which the default
zstd golang library does not.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-02-20 14:26:41 -06:00
Giuseppe Scrivano 0b861350c2
machine: add sparse file writer
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-02-20 15:57:24 +01:00
Jason T. Greene 487219d809 Complete WSL implementation, refactor a few areas
Also addresses a number of issues:
- StopHostNetworking isn't plumbed, win-sshproxy leaks on hyperv
- Wait api and print output doesn't work properly on Windows
- API forwarding doesn't work on WSL
- Terminal corruption with after start/stop on Windows
- Gvproxy is forcefully killed vs gracefully quit
- Switching rootful/rootless does not update /var/run/docker.sock on the guest
- File already closed error on init
- HyperV backend is publishing Unix sockets when it should be named pipes
- User-mode networking doesn't always work
- Stop state outside of lock boundaries
- WSL blocks parallel machined (should be supported)

[NO NEW TESTS NEEDED]

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
2024-02-11 12:58:11 -06:00
Mario Loriedo 7ecc414678 Vendor crc CopySparse
Added the module github.com/crc-org/crc/ as a dependency.

Updated `decompress.go` and `copy_test.go` in compression
so that `CopySparse` from crc-org/crc/v2/pkg/os is used instead
of the local version in `copy.go`.

Deleted `copy.go` that is not used anymore.

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-02-09 19:33:56 +01:00
Matt Heon 72f1617fac Bump Go module to v5
Moving from Go module v4 to v5 prepares us for public releases.

Move done using gomove [1] as with the v3 and v4 moves.

[1] https://github.com/KSubedi/gomove

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-02-08 09:35:39 -05:00
Brent Baude f23b144c60 Podman Machine AppleHV CI fixes
This PR contains several fixes that allow the applehv podman tests run
to completion.

Signed-off-by: Brent Baude <baude@redhat.com>
2024-02-07 09:19:16 -06:00
Brent Baude d5eb8f3b71 AppleHV - make gz ops sparse
gz by definition is not able to preserve the sparse nature of files.  using some code from the crc project and gluing it together with our decompression code, we can re-create the sparseness of a file.  one downside is the operation is a little bit slower, but i think the gains from the sparse file are well worth it in IO alone.

there are a number of todo's in this PR that would be ripe for quick hitting fixes.

[NO NEW TESTS NEEDED]

Signed-off-by: Brent Baude <baude@redhat.com>
2024-02-07 09:19:09 -06:00
Brent Baude a45ba06d02 Refactor key machine objects
In #20538, I was asked to consider refactoring the new OCI pull code
from within the generic machine directory.  This is something I had
tried when originally coding it but it became apparent that a much
larger refactor to prevent circular deps was needed.  Because I did not
want to pollute the initial PR with that refactor, I asked for the PR to
merge first.  This is the refactor that needed to be done.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-11-07 08:30:44 -06:00