no virsh managedsave option?


Recommended Posts

I think maybe pause does virsh suspend and hibernate does virsh dompmsuspend.  But what would be much more useful for me is virsh managedsave to actually pause the vm in a way that will last through an unraid reboot.  Am I misunderstanding the situation?  Is there some way to add this functionality to the unraid gui instead of just running it from command line?

Edited by uek2wooF
s/without/instead of/
Link to comment

Ok I found the related stuff in /usr/local/emhttp/plugins/dynamix.vm.manager/include/VMajax.php

 

This is for Pause:

 

case 'domain-pause':
        requireLibvirt();
        $arrResponse = $lv->domain_suspend($domName)
        ? ['success' => true, 'state' => $lv->domain_get_state($domName)]
        : ['error' => $lv->get_last_error()];
        break;

 

And this is for hibernate:

 

case 'domain-pmsuspend':
        requireLibvirt();
        // No support in libvirt-php to do a dompmsuspend, use virsh tool instead
        exec("virsh dompmsuspend ".escapeshellarg($uuid)." disk 2>&1", $arrOutput, $intReturnCode);
        $arrResponse = $intReturnCode==0
        ? ['success' => true, 'state' => $lv->domain_get_state($domName)]
        : ['error' => str_replace('error: ', '', implode('. ', $arrOutput))];
        break;

 

So it looks like I pretty much guessed right.  I am not sure I want to mess with libvirt-php so I think I will probably change Pause to something like this:

 

# nope.  no.  incorrect sorry

 

I don't know what all the error checking code there does exactly but I will just try it and see what happens.  I suppose to make it permanent through reboots I need to modify it with the User Scripts plugin each time.

 

Edited by uek2wooF
Link to comment

Ugh.  Right after posting that I realized libvirt-php might have domain_managedsave, and yes it does.  So this will be even easier, just

 

s/domain_suspend/domain_save/

 

in VMajax.php

Edited by uek2wooF
save not managedsave there, it calls a wrapper for the libvirt stuff
Link to comment

Another update, this is kind of embarrassing.  Anyway managedsave is not right.  I actually want virsh save and virsh restore.  Both take a file argument.  I don't see support for either one in libvirt.php though.  Apparently it is a bad idea to make that symlink for managedsave, not clear why but managedsave is "internal" to kvm.

 

The new plan was then to modify case 'domain-pmsuspend' (Pause in the menu) to use virsh save instead, and also modify 'domain-resume' to use virsh restore.  Since it is my box and i know the save dir will exist I will just have it save to /mnt/user/domain/save/$domName.save.  But the problem here is that after a virsh save, the vm looks "shut off", and not "paused", so the context menu to restore won't be there in the unraid gui.  I guess I could add some logic to look for a save file and provide the restore menu choice but this starts getting kind of complicated.

 

Link to comment
On 4/2/2021 at 6:47 PM, uek2wooF said:

ok this is really the end I hope.  bind mount is ok for managedsave apparently.  so I have a userscript with:

 




sed -i -e "s/domain_suspend/domain_save/" /usr/local/emhttp/plugins/dynamix.vm.manager/include/VMajax.php
mkdir -p /mnt/user/domains/save
mount --bind /mnt/user/domains/save /var/lib/libvirt/qemu/save

 

This is really interesting. So with this User Script, assuming it's run on each Array Start, it modifies the WebUI and is able to effectively hibernate the VM to /mnt/user/domains/save and restore from the same location. In other words, a VM can be paused, the server rebooted, after which the VM can still be resumed. 

Am I understanding correctly?

Edited by lnxd
Link to comment
On 4/7/2021 at 3:31 AM, lnxd said:

This is really interesting. So with this User Script, assuming it's run on each Array Start, it modifies the WebUI and is able to effectively hibernate the VM to /mnt/user/domains/save and restore from the same location. In other words, a VM can be paused, the server rebooted, after which the VM can still be resumed. 

Am I understanding correctly?

 

That was the plan and it seems to work.  It should be the default save since the others aren't really useful for much.

 

Sorry for the delayed response, I don't get email notifications for some reason.

  • Thanks 1
Link to comment
42 minutes ago, uek2wooF said:

That was the plan and it seems to work.  It should be the default save since the others aren't really useful for much.

 

Sorry for the delayed response, I don't get email notifications for some reason.

Honestly this is pretty cool and I'm going to use it myself, thank you 😁

Just as a warning to anyone who decides to use this it's definitely worth taking note of above:

On 4/2/2021 at 5:15 AM, bonienl said:

When people make their own modifications it makes support impossible.

 

This script also assumes your Default VM storage path is /mnt/user/domains/, if it's not, it will create a share called domains unless you update the references to this path.


Also note that VM Manager needs to be started before you run the script if you are using the default Libvirt storage location which is a disk image that gets mounted when you start VM Manager. Otherwise when it gets started /mnt/user/domains/save will be bound to a location that no longer exists, and you'll possibly either get errors when pausing a VM or the local location won't have any data saved in it. So if you accidentally run the script with VM Manager stopped, you need to need to run the script again after starting it, or specifically the line:

mount --bind /mnt/user/domains/save /var/lib/libvirt/qemu/save


Also to revert to the original option I'm pretty sure you can just restart; or make sure no VMs are paused and run:

sed -i -e "s/domain_save/domain_suspend/" /usr/local/emhttp/plugins/dynamix.vm.manager/include/VMajax.php

You can then safely delete /mnt/user/domains/save which will likely be empty. I'm not going to include the code for deletion here in case someone makes a typo and deletes the contents of their array. 

 

Also there is a possibility that this will get broken / possibly become slightly dangerous in a new release, to be clear this is tested as working on versions 6.8.3 - 6.9.2. If anyone is really interested in making the change permanent; it appears relatively un-breaking and straight-forward to implement so like @bonienl said, best to make a feature request. This mount option has the benefit of not wasting space in libvirt.img, so if someone makes a feature request definitely reference @uek2wooF's script, because it's awesome.
 

Edited by lnxd
  • Like 1
Link to comment

Save dir doesn't exist until you save, so there was nowhere to bind mount to at boot.  This is the correct userscript.

 

sed -i -e "s/domain_suspend/domain_save/" /usr/local/emhttp/plugins/dynamix.vm.manager/include/VMajax.php
mkdir -p /mnt/user/domains/save /var/lib/libvirt/qemu/save
mount --bind /mnt/user/domains/save /var/lib/libvirt/qemu/save

 

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.