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

@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

@Horiodino Horiodino force-pushed the issue-#3518 branch 2 times, most recently from d4972a3 to 590ae10 Compare June 27, 2025 10:23
@AkihiroSuda AkihiroSuda added this to the v1.1.2 milestone Jun 30, 2025
@Horiodino Horiodino force-pushed the issue-#3518 branch 3 times, most recently from 445ec48 to e743134 Compare July 1, 2025 07:36
AkihiroSuda
AkihiroSuda previously approved these changes Jul 1, 2025
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

} else {
err = imgutil.ResizeDisk(dataDisk, disk.Format, int(diskSize))
}
diskUtil := proxyimgutil.NewProxyImageUtil()
Copy link
Member

Choose a reason for hiding this comment

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

Can we improve the naming?

Currently, there are two issues:

  1. Duplication in proxyimgutil and NewProxyImageUtil.
  2. NewProxyImageUtil returns a diskUtil, not an imageUtil, which can be confusing for someone reading the code.
Suggested change
diskUtil := proxyimgutil.NewProxyImageUtil()
diskUtil := proxyimgutil.NewDiskUtil()

Copy link
Member

Choose a reason for hiding this comment

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

Confusing to have both “imgutil” and “diskutil”

Copy link
Member

Choose a reason for hiding this comment

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

Agree.

Copy link
Member

@alexandear alexandear left a comment

Choose a reason for hiding this comment

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

Let's merge this PR and improve in the next PRs.

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
3 participants