Skip to content

defined a common interface for nativeimgutil & qemuimgutil #3650

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Horiodino
Copy link
Contributor

fixes : #3518

Define the common interface for qemuimgutil and nativeimgutil

@Horiodino Horiodino marked this pull request as draft June 21, 2025 16:57
@Horiodino Horiodino force-pushed the issue-#3518 branch 2 times, most recently from fe7a833 to 6bc9e97 Compare June 22, 2025 06:31
@Horiodino Horiodino marked this pull request as ready for review June 22, 2025 06:59
@alexandear alexandear requested a review from Copilot June 23, 2025 08:58
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors image utility handling by defining a common interface for both native and QEMU image utilities, allowing the code to use a unified API for disk image operations. Key changes include replacing direct calls to nativeimgutil and qemuimgutil with calls to the common imgutil package, introducing factory and proxy implementations, and updating tests and error handling accordingly.

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/vz/vm_darwin.go Replaced nativeimgutil with common imgutil for raw disk conversion.
pkg/vz/disk.go Updated disk creation and resizing to use the new imgutil interface.
pkg/qemu/qemu.go Refactored disk info retrieval and validation to use the proxy interface.
pkg/instance/start.go Updated disk conversion logic to use the common image utility.
pkg/imgutil/qemuimgutil/* Renamed helper functions to unexported versions and updated tests.
pkg/imgutil/nativeimgutil/* Adjusted naming of internal functions and updated tests accordingly.
pkg/imgutil/proxyimgutil/* Introduced proxy implementation to abstract native/qemu differences.
pkg/imgutil/factory.go Added a factory function to return the correct image util based on format.
cmd/limactl/disk.go Updated command-line disk actions to use the new unified API.
Comments suppressed due to low confidence (2)

pkg/qemu/qemu.go:95

  • [nitpick] If multiple image info calls occur within this function, consider caching the result of NewImageUtil to avoid redundant initialization overhead.
	_, infoProvider, err := imgutil.NewImageUtil("qcow2")

pkg/instance/start.go:429

  • [nitpick] If prepareDiffDisk is called frequently, consider caching the image util instance to reduce the cost of repetitive initialization.
	diskUtil, _, err := imgutil.NewImageUtil(format)

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.

Doesn't seem to follow #3518

func (p *ProxyImageDiskManager) CreateDisk(disk string, size int) error {
if err := p.qemu.CreateDisk(disk, size); err == nil {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

When qemu.CreateDisk returns an error other than exec.ErrNotFound, the error should be returned immediately without falling back to native.CreateDisk?

Copy link
Member

Choose a reason for hiding this comment

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

Same applies to other functions too

Copy link
Member

Choose a reason for hiding this comment

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

exitError.ExitCode() == 127

How does this happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok heres the explanation , see in go exec.Command("non existent command")
This results in exec.ErrNotFound because Go cannot find the command itself. It never even starts running because the binary doesn't exist.

exec.Command("sh", "-c", "non existent command"):
Here, sh exists, but the command inside the shell (nonexistentcommand) doesn't exist. So, the shell runs but exits with exit code 127, which means "command not found inside the shell."

exec.ErrNotFound for missing executables.

Exit code 127 when the executable runs but the command inside it is missing.

Copy link
Member

Choose a reason for hiding this comment

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

How is sh relevant here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used sh just as a common example to illustrate the behavior.

The 127 exit code is simply a valid, standardized way to indicate "command not found" it's a safe and predictable way to signal failure without causing unexpected behavior.

In this case, yeah the failure scenario I described doesn't really apply here. I included it more as an extra precaution.

@Horiodino Horiodino force-pushed the issue-#3518 branch 2 times, most recently from bebc163 to dabff97 Compare June 26, 2025 12:08
@AkihiroSuda
Copy link
Member

The commits can be squashed

Signed-off-by: Horiodino <holiodin@gmail.com>

refactor: remove old qemuimgutil and nativeimgutil packages

Signed-off-by: Horiodino <holiodin@gmail.com>

fixed golangci-lint errs

Signed-off-by: Horiodino <holiodin@gmail.com>

refactor: added  proxyimgutil for unified image utility interface

Signed-off-by: Horiodino <holiodin@gmail.com>

Only fall back to native if qemu-img is not found

Signed-off-by: Praful Khanduri <holiodin@gmail.com>
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.

Define the common interface for qemuimgutil and nativeimgutil
2 participants