Skip to content
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

Add support for running VM as temporary snapshot #3067

Merged
merged 6 commits into from
May 8, 2022

Conversation

ktprograms
Copy link
Contributor

#2688

I tried adding the -snapshot option in the QEMU settings and it works, so I've changed the UI to use it.

The -snapshot option is enabled when you click the Play button while holding the command key on macOS, and in a long press context menu on iOS 14.

I can change the UI if this design isn't wanted.

Also I'm not sure how to change the UI on legacy (11 - 13) iOS.

@ktprograms ktprograms marked this pull request as draft August 30, 2021 08:32
Copy link
Contributor

@conath conath left a comment

Choose a reason for hiding this comment

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

Looks good overall! This could be a useful feature IMO.
Please take a look at my comments, esp. changing from the command key to option key. Thank you!

If you need help testing this, or with something else, let me know.

Platform/Shared/VMContextMenuModifier.swift Outdated Show resolved Hide resolved
Platform/Shared/VMDetailsView.swift Outdated Show resolved Hide resolved
Platform/Shared/VMDetailsView.swift Outdated Show resolved Hide resolved
Platform/Shared/VMRunButton.swift Outdated Show resolved Hide resolved
Platform/Shared/VMRunButton.swift Outdated Show resolved Hide resolved
Platform/Shared/VMRunButton.swift Outdated Show resolved Hide resolved
@ktprograms ktprograms marked this pull request as ready for review August 31, 2021 03:28
@ktprograms ktprograms requested a review from conath August 31, 2021 03:28
@ktprograms
Copy link
Contributor Author

BTW some of this code (the parts with custom modifiers) should probably be rewritten when Swift 5.5 is available with it's #if/#endif on modifiers.

@ktprograms
Copy link
Contributor Author

@conath I think I'll need some help adding the Run as Snapshot option for older iOS versions of the app.

I'm not sure how the UI should be implemented and where the code for it should be.

@ktprograms ktprograms force-pushed the command-temporary-snapshot branch from 28cbda4 to e2b8058 Compare September 4, 2021 06:14
Copy link
Contributor

@conath conath left a comment

Choose a reason for hiding this comment

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

Nice! @osy this looks like it will be a great addition.

@ThomasWaldmann
Copy link

Thanks for working on this! See also #2688.

As a remark: I find the terms / language for this option a bit unusual (but of course that began with the qemu option name) and not very intuitive / understandable.

Snapshot usually means something frozen, something one is keeping. But here (if I understood it correctly), it rather means to run the VM as a "disposable VM", so everything one changes while running it is disposed as soon as it is shutdown. Qubes OS calls this a "disposable VM".

But also if one considers the perspective of a non-admin, non-developer user: they likely would not associate "run as snapshot" with "disposable" or "temporary / throw away".

Also, hiding this behind an additional key to hold down is not very intuitive / discoverable - would anybody even find this without reading the docs (are there docs?)?

@utmapp utmapp deleted a comment from ktprograms Sep 10, 2021
@conath
Copy link
Contributor

conath commented Sep 10, 2021

Good point @ThomasWaldmann. There should definitely be some kind of explanation whenever this feature is activated, possibly an alert explaining what will happen, with the option to run normally and to not show it again. The running VM window should probably also gain an indicator that changes won't be saved.

I'm not sure on the wording either, "Run without saving changes" could be a more verbose and more obvious name (I can't think of a concise way of phrasing it). Though if someone is looking for the QEMU feature "snapshot" then they wouldn't find it.

In terms of UI, as ktprograms mentioned there is the context menu action so it's discoverable. Maybe a menu bar item could be added as well, if there isn't already one included with the PR. The menu bar has the advantage of being searchable from the Help menu.

@conath
Copy link
Contributor

conath commented Sep 28, 2021

Maybe this feature could have similar UX to a web browser's incognito window where the history is deleted when the browser window is closed. There could be a little ghost icon in the toolbar whenever a VM is running in this "snapshot" mode.

@ktprograms
Copy link
Contributor Author

When using the Qemu Monitor, it's possible to commit changes to disk even if it was started as -snapshot. Does UTM have access to the Qemu Monitor?

Copy link
Contributor

@osy osy left a comment

Choose a reason for hiding this comment

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

Change not storing into UTMConfiguration and also address previous comments about visibility to users. Maybe to make things easier, we remove the Cmd+Click option? I don't think this will be a feature that will be widely used and therefore it seems weird to assign a hot key to it when other features do not have such assignment.

@@ -38,6 +38,8 @@
const NSString *const kUTMConfigIconCustomKey = @"IconCustom";
const NSString *const kUTMConfigNotesKey = @"Notes";

const NSString *const kUTMConfigSnapshotKey = @"RunAsSnapshot";
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't add temporary (per launch) settings to UTMConfiguration. Check out UTMViewState and how we save things like displayScale.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I'm reading on and I take back this suggestion. Read the next comment.

@@ -645,6 +645,10 @@ - (void)argsFromConfiguration {
// fix windows time issues
[self pushArgv:@"-rtc"];
[self pushArgv:@"base=localtime"];

if (self.configuration.runAsSnapshot) {
Copy link
Contributor

Choose a reason for hiding this comment

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

So actually, it may make more sense to add a new @ property to UTMQemuSystem for runAsSnapshot and to UTMVirtualMachine where the property in UTMVirtualMachine is called isNextRunAsSnapshot, which the set handler will set UTMQemuSystem's property.

Copy link
Contributor Author

@ktprograms ktprograms Oct 8, 2021

Choose a reason for hiding this comment

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

So where would the property in UTMVirtualMachine be set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And what would the UI to enable it be like?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean in UTMVirtualMachine we add @property (nonatomic) BOOL isNextRunAsSnapshot; and then for - (void)setIsNextRunAsSnapshot it will propagate to UTMQemuSystem which has its own property as well. Then from the UI you set UTMVirtualMachine's property. Additionally, in start it should un-set isNextRunAsSnapshot.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the context menu UI is good enough. I would remove the hot key.

Choose a reason for hiding this comment

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

Agreed; this also makes it consistent with other VM systems. On some UIs though, there's the start button > with a drop-down button on press-and-hold that lets you select between Run, Run Snapshot, Run Shadow Copy.
Of course, the issue there is that then you get into shadow copy management, where you need the ability somewhere to manage/delete shadow copies.

As for UI labeling, Snapshot is definitely problematic, especially when most popular VMs use the term the way QEMU refers to shadow copies. Even the QEMU documentation has to differentiate between -snapshot and VM Snapshots: https://qemu.readthedocs.io/en/latest/system/images.html

On the plus side, that documentation now has a clear explanation of what VM snapshotting and -snapshot do, which might be useful to incorporate into UTM documentation as well. Of course, with no access to the monitor, there's currently no way to manage VM snapshots on UTM?

Mark me down as someone who would love the ability to use -snapshot, plus the ability to optionally merge the snapshot into the image at the end of the session. I do lots of demonstration sessions on various OSes, and would love the ability to automatically discard changes unless I explicitly choose to merge them. A dialog when closing the VM stating "This session has unsaved changes. Would you like to save them?" with UTM handling the response by doing nothing if the answer is No, or sending "-a s" to the serial console if the answer is Yes.

Copy link
Contributor

Choose a reason for hiding this comment

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

@adespoton I plan to merge the PR as-is but your suggestions are good. Feel free to open a new issue with the suggestions once it's merged.

@ktprograms ktprograms force-pushed the command-temporary-snapshot branch from e2b8058 to 42fb253 Compare March 14, 2022 02:50
@ktprograms
Copy link
Contributor Author

ktprograms commented Mar 14, 2022

@osy Did your requested changes (completely rewrote it against current master)

@osy osy merged commit b855cfe into utmapp:master May 8, 2022
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.

5 participants