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 Suspend To Disk Option to the VM control menu #1359

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DlpOne
Copy link

@DlpOne DlpOne commented Dec 21, 2023

The stop function can only pause the VM, which means that the VM continues to allocate resources and the status of the VM is lost when the Host is rebooted.

It would be useful to have a function that allows you to save the state of a VM to disk and resume it at a later point in time.
Libvirt offers the managedsave function for this purpose.

This patch adds this function to the control menu of the VM


Bildschirmfoto vom 2023-12-21 01-57-54

@garrett
Copy link
Member

garrett commented Jan 17, 2024

Thanks for this PR!

  1. Suspending to disk is similar in concept to pausing, so there should not be a divider between pausing and suspending to disk.
  2. Cockpit uses sentence capitalization, so it should be "Suspend to disk".

What should the menu look like when resuming? With both resuming, I'm assuming at least some of the other options aren't available (you can't unpause something that's suspended or send a non-maskable interrupt, for example). Right now, it just looks like a "shut off" VM.

Additionally:

  • Is "Resume" the correct word to use for both paused and suspended VMs?
  • Do we have a suspended state shown in the list and on details page? (There's a "Paused" state right now.) At the moment, it just shows as "Shut off" instead of "Suspended".
  • Why does pausing a VM still show suspend to disk as an option? Does it unpause and then suspend? Or does it suspend a paused VM so you have to resume twice (once from suspend, another from pausing)?
    image

@garrett garrett requested a review from jelly January 17, 2024 10:30
@DlpOne
Copy link
Author

DlpOne commented Jan 18, 2024

Thanks for the Response.

The difference between pause and managedsave are:

pause

  • Pausing stops the virtual machine (VM), but the VM domain continues to exist in libvirt, so the virtual memory resources of the VM are still allocated in Host Memory.
  • If the Host (hypervisor) is restarted, the VM's state is lost, and the VM cannot be resumed.

managedsave

  • managedsave stops the VM, the contents of the virtual memory are saved to the hard disk, the VM domain in libvirt is destroyed and the resources used are released.
  • The state of the VM can also be continued after a restart of the host (hypervisor)

After managedsave (Suspend to disk) the menu looks like the vm was "shut off", because in libvirt the vm Domain was destroyed. So Technically the vm is shutoff . To Resume the vm use normal start. Its the same behaviour as on a real PC after Suspend to Disk the PC is off, to continue use the power on button.

Save could be a better name for this functionality, instead of Suspend to disk.

Currently in the list and detail view the State is shut-off. Technically is the vm Domain destroyed in libvirt. I have to check if libvirt is able to represent the mangedsave state.

It is possible to Suspend to disk a paused vm because, mangedsave allows to save the state of an paused vm to disk. On resume (start) the state of an paused vm is still paused.

@DlpOne
Copy link
Author

DlpOne commented Jan 20, 2024

I made some changes based on the points mentioned. The name of the option has been changed from "Suspend to Disk" to "Save," as this should better reflect the functionality.

Save

To indicate that a saved image (managed save state) is present for the vm, I have added the tag "(Saved)" to the Shut Off status in both the list view and detail view. I chose not to use a separate status since the libvirt status of a vm with a saved image is "shut off," and there is no separate status for managed save.

However, there might be a better way to implement this in the code.

Save ListView
VM DetailView

In addition, I have implemented the option to remove an existing saved image. However, without a confirmation dialog. Perhaps it would be advisable to add one.

Unfortunately, libvirt does not provide an event for a deleted saved image, so I had to choose an approach that deviates from the behavior of other actions in code.

Bildschirmfoto vom 2024-01-20 18-07-40

Currently, it is not possible to filter based on the saved image tag. I am not sure if it makes sense to implement this function at the moment. The VMs are listed under "shut off" because that is the libvirt status.

FilterState

@martinpitt martinpitt marked this pull request as draft January 24, 2024 14:27
@DlpOne DlpOne marked this pull request as ready for review January 24, 2024 22:15
@garrett
Copy link
Member

garrett commented Jan 25, 2024

I do not like the word "Save" for this functionality. It sounds like it will save the VM as a file and download it, which is how "Save" is used in basically every other app (web-based or native).

"Suspend to disk" was clearer to me, at least.

The state should probably also be "Suspended". (It should probably still show up when filtering by the "shut off" state.)

How is "Remove save image" any different from "Delete"? If it's supposed to remove the suspended state, it's pretty much the same starting it back up and choosing "Force shut down", right?

@DlpOne
Copy link
Author

DlpOne commented Jan 25, 2024

I had considered that 'Suspend to Disk' might not be suitable because 'managedsave' also allows saving the content of paused vm, and the libvirt command is named 'managedsave.' However, I can change it to 'Suspend to disk' and the state to Suspended if you prefer.

Internally, 'Remove save image' uses the Libvirt 'ManagedSaveRemove' command, which simply deletes the saved image without starting the vm. In principle, this image is also deleted when the vm is started, making the behaviour comparable to turning on and immediately turning off the vm. The reason I implemented this function is to provide a solution in case of an error where the vm fails to start due to an issue with the save image.

@DlpOne DlpOne reopened this Nov 21, 2024
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.

2 participants