Skip to content

scripting: return the guest size of existing drives - #8192

Open
UTMapp-bot wants to merge 1 commit into
utmapp:mainfrom
UTMapp-bot:fix/issue-8190-drive-guest-size
Open

UTMapp-bot wants to merge 1 commit into
utmapp:mainfrom
UTMapp-bot:fix/issue-8190-drive-guest-size

Conversation

@UTMapp-bot

Copy link
Copy Markdown
Collaborator

UTM.sdef declares guest size on the existing 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 or check that a resize took effect.

  • Serializer (Scripting/UTMScriptingConfigImpl.swift): drive records now carry guestSize in MiB, read from the image as the guest sees it:

    • a QCOW2 drive: the virtual size in its header;
    • a raw image, or a removable drive's CD/floppy image: the file size;
    • an Apple drive: the size from UTMAppleDiskImage.info (falling back to the file size, except for a sparse ASIF image).

    configuration is a synchronous property, so this does not go through qemu-img. A drive with no image, or whose size cannot be read, has no guest 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:

    • a guest size equal to the drive's current size;
    • in a record that also replaces the drive's source, a guest size equal 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 configuration now 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 async validateDriveResizes. I didn't, because that would change when driveNotResizable is raised for callers and tests that rely on updateConfiguration throwing 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.swift restored to main and the tests kept, all three fail: guestSize is nil, and the round trip with a removable drive throws driveNotResizable. With only the serializer change, the round-trip test fails with driveNotResizable. 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:

  1. read guest size;
  2. grew the fixed drive to 128 by adding guest size:128 to its record;
  3. put a 3 MiB ISO in the removable drive;
  4. applied the fetched record back unchanged;
  5. deleted the VM.

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):

created: fixed error -1728, removable error -1728
after grow to 128: fixed error -1728
removable with ISO: error -1728
plain get/update round trip ok: fixed error -1728, removable error -1728
qcow2 header virtual size: 128 MiB
apple created: error -1728
apple round trip ok: error -1728

After, on a Debug build of this branch:

created: fixed 64, removable error -1728   (empty removable drive: no guest size)
after grow to 128: fixed 128
removable with ISO: 3
plain get/update round trip ok: fixed 128, removable 3
qcow2 header virtual size: 128 MiB
apple created: 64
apple round trip ok: 64

Every test VM was deleted afterwards.

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
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.

fix(scripting): existing drive records omit guest size

2 participants