Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preparing for adding block status interface #39

Merged
merged 8 commits into from
Nov 3, 2024

Conversation

nirs
Copy link
Member

@nirs nirs commented Nov 2, 2024

These are various fixes, refactoring and test enhancements extracted from the block status work.

  • Fix typos in comments
  • Fix errors formatting when index >= len(table)
  • Add qemuimg.Create() helper (used in 6e3948d)
  • Add qemuio test package (used in 6e3948d)
  • Make qemu-img and qemu-io available for unit tests
  • Separate cluster metadata from reading
  • Cleanup getClusterMeta
  • Upgrade to go 1.22 (used in df84640)

Part-of #32

Signed-off-by: Nir Soffer <[email protected]>
When validating table index, if the index was too long, we formatted the
table using %d instead of the length. Testing show that this format the
entire table which is way too big to include in an error message.

Signed-off-by: Nir Soffer <[email protected]>
// Return stderr instead of the unhelpful default error (exited with status
// 1).
if _, ok := err.(*exec.ExitError); ok {
return out, errors.New(stderr.String())
Copy link
Member

@AkihiroSuda AkihiroSuda Nov 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fmt.Errorf("%w: stderr=%q", err, stderr)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the .String() - otherwise we get confusing output.

Without .String():

    qcow2reader_test.go:25: exit status 1: stderr={"qemu-img: unrecognized option '--no-such-arg'\nTry 'qemu-img --help' for more information\n" '\x00' '\x00'}

With .String()

    qcow2reader_test.go:25: exit status 1: stderr="qemu-img: unrecognized option '--no-such-arg'\nTry 'qemu-img --help' for more information\n"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in qemuimg and qemuio.

Extract qemuimg() helper for running qemu-img command and add a wrapper
for the qemu-img crate sub command.

Signed-off-by: Nir Soffer <[email protected]>
To qcow2 test images, we used raw image and converted to qcow2 format.
This does not work for creating qcow2 chain with some data in the
backing file and some data in the top image. qemu-io allows writing
data, zeros or discarding a byte range in an image of any format
supported by qemu.

This change add a tiny test package for running qemu-io. We provide 2
functions, wrapping usage of the write command with different flags:

- Write() - write a pattern to specified range
- Zero() - write zeros to specified range
- Discard() - discard specified range

With these functions we can test all kind of extents in both top layer
or the backing file:
- Allocated: false, Zero: true
- Allocated: true, Zero: false
- Allocated: true, Zero: true

Signed-off-by: Nir Soffer <[email protected]>
We want to use qemu-img and qemu-io to create and manipulate test
images.

Signed-off-by: Nir Soffer <[email protected]>
Extract a helper for getting cluster metadata from readAtAligned. The
helper will be reused for getting cluster status.

Signed-off-by: Nir Soffer <[email protected]>
Computing number of L2 entires for every cluster does not feel right
since this is a constant value per image. Computing it once after
reading the header.

Computing L1 index and L2 index use the cluster number. Make the
computation more clear by introducing a variable.

This change also speed up empty image processing by 10%, since we
actually have a tight loop over all image clusters.

Signed-off-by: Nir Soffer <[email protected]>
@AkihiroSuda
Copy link
Member

CI is failing

Probably golangci-lint has to be updated for Go 1.22

@nirs nirs mentioned this pull request Nov 3, 2024
@nirs
Copy link
Member Author

nirs commented Nov 3, 2024

CI is failing

Probably golangci-lint has to be updated for Go 1.22

On it

This allows using useful new packages such as slices package and other
fixes. This also matches lima requirement.

Updating also golanci-lint based on lima test workflow.

Signed-off-by: Nir Soffer <[email protected]>
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@AkihiroSuda AkihiroSuda merged commit 8255b8a into lima-vm:master Nov 3, 2024
2 checks passed
@nirs nirs deleted the block-status-preps branch November 3, 2024 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants