-
Notifications
You must be signed in to change notification settings - Fork 789
pkg/driver/vz: Support ASIF as diffdisk #4327
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
Merged
AkihiroSuda
merged 6 commits into
lima-vm:master
from
norio-nomura:vz-support-asif-as-diffdisk
Dec 1, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
28de241
pkg/driver/vz: Support ASIF as diffdisk
norio-nomura 3aa190e
vz: Support ASIF on creating diffdisk
norio-nomura 2806030
Add `vmType.vz.diskImageFormat` that accepts "raw" or "asif"
norio-nomura 70ed498
pkg/imgutil/nativeimgutil: Avoid resizing ASIF image
norio-nomura 1d0ac3f
pkg/imgutil: Consolidate `ConvertToRaw()` and `ConvertToASIF()` to `C…
norio-nomura cbe7241
Apply reviews
norio-nomura File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // SPDX-FileCopyrightText: Copyright The Lima Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package asifutil | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "strings" | ||
| ) | ||
|
|
||
| // NewAttachedASIF creates a new ASIF image file at the specified path with the given size | ||
| // and attaches it, returning the attached device path and an open file handle. | ||
| // The caller is responsible for detaching the ASIF image device when done. | ||
| func NewAttachedASIF(path string, size int64) (string, *os.File, error) { | ||
| createArgs := []string{"image", "create", "blank", "--fs", "none", "--format", "ASIF", "--size", fmt.Sprintf("%d", size), path} | ||
| if err := exec.CommandContext(context.Background(), "diskutil", createArgs...).Run(); err != nil { | ||
| return "", nil, fmt.Errorf("failed to create ASIF image %q: %w", path, err) | ||
| } | ||
| attachArgs := []string{"image", "attach", "--noMount", path} | ||
| out, err := exec.CommandContext(context.Background(), "diskutil", attachArgs...).Output() | ||
| if err != nil { | ||
| return "", nil, fmt.Errorf("failed to attach ASIF image %q: %w", path, err) | ||
| } | ||
| devicePath := strings.TrimSpace(string(out)) | ||
| f, err := os.OpenFile(devicePath, os.O_RDWR, 0o644) | ||
| if err != nil { | ||
| _ = DetachASIF(devicePath) | ||
| return "", nil, fmt.Errorf("failed to open ASIF device %q: %w", devicePath, err) | ||
| } | ||
| return devicePath, f, err | ||
| } | ||
|
|
||
| // DetachASIF detaches the ASIF image device at the specified path. | ||
| func DetachASIF(devicePath string) error { | ||
| if output, err := exec.CommandContext(context.Background(), "hdiutil", "detach", devicePath).CombinedOutput(); err != nil { | ||
| return fmt.Errorf("failed to detach ASIF image %q: %w: %s", devicePath, err, output) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // ResizeASIF resizes the ASIF image at the specified path to the given size. | ||
| func ResizeASIF(path string, size int64) error { | ||
| resizeArgs := []string{"image", "resize", "--size", fmt.Sprintf("%d", size), path} | ||
| if output, err := exec.CommandContext(context.Background(), "diskutil", resizeArgs...).CombinedOutput(); err != nil { | ||
| return fmt.Errorf("failed to resize ASIF image %q: %w: %s", path, err, output) | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //go:build !darwin | ||
|
|
||
| // SPDX-FileCopyrightText: Copyright The Lima Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package asifutil | ||
|
|
||
| import ( | ||
| "errors" | ||
| "os" | ||
| ) | ||
|
|
||
| var ErrASIFNotSupported = errors.New("ASIF is only supported on macOS") | ||
|
|
||
| func NewAttachedASIF(_ string, _ int64) (string, *os.File, error) { | ||
| return "", nil, ErrASIFNotSupported | ||
| } | ||
|
|
||
| func DetachASIF(_ string) error { | ||
| return ErrASIFNotSupported | ||
| } | ||
|
|
||
| func ResizeASIF(_ string, _ int64) error { | ||
| return ErrASIFNotSupported | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diskImageFormat is ignored for ISO mode