Repository navigation
Put right a linked clone the app was stopped in the middle of - #164
Conversation
A linked clone moves the source's disk to the shared base before it makes the two overlays. If the app stops in between, the source VM points at a disk that isn't there, and its next Power on makes a blank one while the real data sits in the .base file. The clone now writes <base>.vmm-linking in the disks folder first, naming the source disk, the base and the new overlay, and removes it once the new VM's config is saved. To get that order, cloneVm takes the save as a callback instead of the IPC handler saving after it returns. At startup, recoverLinkedClones reads each marker. With the source disk missing it moves the base back. With the source overlay in place the clone is usable, so it makes the base read-only like a finished clone and removes the new overlay if no VM was saved with it. A marker it can't act on yet (base in use) stays for the next start.
Uses a fake qemu-img that never finishes, the way a quit leaves it, and checks what the next start puts right. The Still working question can now say a cut-off clone of either kind is undone at the next start.
A21-devs
left a comment
There was a problem hiding this comment.
Read the marker format, the save callback ordering and the recovery branches. The ordering is right: marker before the rename, removed only after saveConfig, and the in-process failure path keeps it when it can't move the disk back. One gap in how recovery decides the clone got far enough.
| } | ||
| tryRemove(m.target) // an overlay is only made after the source's, so this is a no-op | ||
| } else { | ||
| if (existsSync(m.base)) chmodSync(m.base, 0o444) |
There was a problem hiding this comment.
This branch takes "a file exists at diskPath" to mean the source overlay is good. But qemu-img create writes that file in place, so if the app (and with it the qemu-img child) is killed while it runs, diskPath can hold a zero-length or half-written qcow2. Recovery then keeps it, locks the base and drops the marker, and the source VM fails to boot with its real data sitting in the base, which is the same situation this PR is fixing, only rarer.
Cheapest way out is in cloneVm: create each overlay under a temporary name and renameSync it into place. A rename is atomic on the same volume, so a file at diskPath is then always a finished overlay. The overlay stores the base's path, not its own, so renaming it is safe.
|
Good catch, that was real. 1c2d9d0 creates each overlay as Two new tests make the fake qemu-img leave a half-written file and hang, once on the source overlay and once on the new one, and check the next start ends with only the original disk, or the source overlay plus the locked base. |
qemu-img create writes the overlay in place, so a quit while it runs can leave half a qcow2 at the source's disk path, which the startup recovery would take for a finished overlay and keep. Each overlay is now created as <file>.vmm-clone and renamed into place, and the recovery removes any temporary overlay a marker names.
A21-devs
left a comment
There was a problem hiding this comment.
Checked the follow-up against the first review. Fixed: overlay() creates <file>.vmm-clone and renames it into place, so existsSync(m.diskPath) in the recovery now really means a finished overlay. The startup order works out too: removeUnfinishedDisks runs first and takes any temporary overlay inside the disks folder, and the recovery's own tryRemove covers a source disk that lives elsewhere. The two hang tests leave a half-written file the way a killed qemu-img would, and both end with the right files. Nothing else open.
Closes #156
A linked clone renames the source's disk to
<name>.base-<id>.qcow2before it creates the two overlays. If the app stops in between (Quit anyway, a crash, power loss), the source VM's config points at a file that isn't there, and the next Power on creates a blank disk at that path.How
cloneVmwrites a small JSON marker in the disks folder,<base>.vmm-linking, naming the source disk, the base and the new overlay. The disks folder is used even when the source disk lives elsewhere, so startup only has to look in one place.cloneVmnow takes the save as a callback (the IPC handler passessaveConfig) instead of saving after it returns. The default just returns the config, so the integration tests' calls are unchanged.recoverLinkedClonesreads each marker:Testing
tests/clones.test.tswith a fake qemu-img whose overlay never finishes, the way a quit leaves it: cut off before the overlays (disk moved back), cut off before the config save (base made read-only, unsaved overlay removed), a finished clone (marker present during the save and gone after, recovery does nothing), and an unreadable marker / missing foldernpm run typecheck,npm test(199 pass),npm run test:qemu(216 pass, includes real linked clones that boot),npm run build.base-abc.qcow2and its marker: the log saysput right unfinished linked clones: moved ...Kali.base-abc.qcow2 back to ...Kali.qcow2, the disk is back with its contents, SMOKE OK