Repository navigation
scripting: return the guest size of existing drives - #8192
Open
UTMapp-bot wants to merge 1 commit into
Open
UTMapp-bot wants to merge 1 commit into
UTMapp-bot wants to merge 1 commit into
Conversation
UTM.sdef declares `guest size` on the drive records that `get configuration` returns, and `update configuration` grows a QCOW2 drive to it, but the records never carried it. A script could not read a drive's capacity, nor check that a resize took effect (utmapp#8190). Read the size from the image as the guest sees it: the virtual size in a QCOW2 header, the file size of a raw image or of a removable drive's CD or floppy image, and the size DiskImageKit reports for an Apple drive (an ASIF image is sparse, so its file size is never used). The configuration property is read synchronously, so this does not go through qemu-img. A drive with no image, or whose size cannot be read, has no `guest size`. Every record from `get configuration` now carries the size, so applying one back sent it for every drive, and raw and removable drives refused it with driveNotResizable. A size equal to the drive's current one now changes nothing. When the same record replaces the drive's source, the size it carries is the replaced image's, so that size is ignored too instead of growing the new image. Resolves utmapp#8190 Assisted-by: Claude:claude-opus-5-5
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
UTM.sdefdeclaresguest sizeon the existing drive records thatget configurationreturns, andupdate configurationgrows a QCOW2 drive to it, but the records never carried it. A script could not read a drive's capacity or check that a resize took effect.Serializer (
Scripting/UTMScriptingConfigImpl.swift): drive records now carryguestSizein MiB, read from the image as the guest sees it:UTMAppleDiskImage.info(falling back to the file size, except for a sparse ASIF image).configurationis a synchronous property, so this does not go throughqemu-img. A drive with no image, or whose size cannot be read, has noguest size.Update path: every fetched record now carries the size, so applying one back unchanged sent it for every drive, and raw and removable drives threw
driveNotResizable. Two cases are now no-ops:guest sizeequal to the drive's current size;source, aguest sizeequal to the replaced image's size. Without this, the old size would grow the new image.A different size still grows a QCOW2 drive, or is refused for raw and removable drives as before.
UTM.sdef: the descriptions say when the property is missing. They also say that on Apple drives it is only set at creation, which is what the code already did.Not changed:
get configurationnow reads each drive image's first 32 bytes (or asks DiskImageKit, for Apple drives) on the main actor. The alternative was moving the "unchanged" check into the asyncvalidateDriveResizes. I didn't, because that would change whendriveNotResizableis raised for callers and tests that rely onupdateConfigurationthrowing it.Resolves #8190
Testing
Mac Studio (Apple Silicon), macOS 27.2.1, tested by AI (Claude).
Unit tests (
scripts/test_utm.sh -only-testing:UTMTests/UTMScriptingConfigImplTests): 22 tests, 0 failures. Three new tests:testDriveRecordsReturnTheirGuestSize_8190: QCOW2, ISO, empty removable, unreadable and corrupt-header drives.testAppleDriveRecordsReturnTheirGuestSize_8190.testUnchangedGuestSizeLeavesDrivesAlone_8190: the round trip with raw and removable drives, a source replaced together with the stale size and with the new image's size, and a real change still refused.With
UTMScriptingConfigImpl.swiftrestored tomainand the tests kept, all three fail:guestSizeis nil, and the round trip with a removable drive throwsdriveNotResizable. With only the serializer change, the round-trip test fails withdriveNotResizable.Tests/Static/run_all.sh: 0 problems.In the app, with AppleScript. For QEMU, the script created a stopped aarch64 VM with a 64 MiB internal QCOW2 drive and an empty removable drive. It then:
guest size;guest size:128to its record;The QCOW2 header was read independently. For the Apple backend, it created a VM with a 64 MiB drive, read the size, and applied the record back.
Before, on release UTM 5.0.9 (130):
After, on a Debug build of this branch:
Every test VM was deleted afterwards.