LaunchVMProcess emergencystop API clarification?

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
rousseauhk
Posts: 45
Joined: 8. Apr 2013, 09:16
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Ubuntu Server
Contact:

LaunchVMProcess emergencystop API clarification?

Post by rousseauhk »

If I run

Code: Select all

machine.LaunchVMProcess(null, "emergencystop", null);
I sometimes get an error:

"The machine [blah] is not locked by a session"

However if I try to establish a lock before i call it:

Code: Select all

machine.LockMachine(session, LockType.LockType_VM);
I often get the contrary error (something like) "Session locked by another user".

What is the correct usage of the emergencystop command? From the documentation it reads like it shouldnt need a lock, because the whole purpose is to terminate a machine that is in use/locked by another user. Am I missing something?

thx
Steve
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: LaunchVMProcess emergencystop API clarification?

Post by noteirak »

I am not sure how it should behave - never used that specific of it.
I'll give it a try later tonight and see what happens. Or a dev comes by and answers your question directly :)
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: LaunchVMProcess emergencystop API clarification?

Post by noteirak »

I won't have the time tonight, but I was wondering : is there any particular reason you're using that specific method instead of using the regular powerDown()?
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
rousseauhk
Posts: 45
Joined: 8. Apr 2013, 09:16
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Ubuntu Server
Contact:

Re: LaunchVMProcess emergencystop API clarification?

Post by rousseauhk »

I run a cleanup process under a separate account that deletes old VMs. Since the VM could still have a lock open by another user, this seemed the most fool-proof way. The current method seems to work, but sometime generates those exceptions in the locking code (and if I dont lock, it sometimes generates exceptions in the emergencystop code).

thx
Steve
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: LaunchVMProcess emergencystop API clarification?

Post by noteirak »

Just to make it clear, if you use the "emergencystop", does the VM ALWAYS stop, and sometimes you get an exception?
If that's the case, then I believe it would only be part of the API race with session and object destruction. I had a chat about this with Klaus in the dev mailing list but about powerOff().
Basically, if the VM always stops, and you sometimes get an exception aswell, then it's working as expected and your code has to deal with it.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
rousseauhk
Posts: 45
Joined: 8. Apr 2013, 09:16
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Ubuntu Server
Contact:

Re: LaunchVMProcess emergencystop API clarification?

Post by rousseauhk »

While LaunchVMProess doesnt always seem to work by itself, the following code does (or at least I havent yet found a case where it fails)..

Code: Select all

; psuedo-code
try
{
lockMachine();
}
catch (Exception) { //ignore}

try
{
LanchVMProcess("EmergencyStop"};
}
catch (Exception) { //ignore}

try
{
unlockMachine();
}
catch (Exception) { //ignore }
Basically this seems to covers two cases:

1) LaunchVMProcess either requires a lock in which case try{lockMachine()} always seems to work. Or
2) LaunchVMProcess doesnt require a lock, in which case try{lockMachine()} fails, but LaunchVMProcess still works OK.

thx
Steve
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: LaunchVMProcess emergencystop API clarification?

Post by noteirak »

For the unlock(), you do require to be ready to catch exception yes, that's by design - see my discussion about it with Klaus, one of the devs.
So I would assume your code is in track with what would be expected but if you want a final confirmation, I would take this to the dev mailing list.

Side note : be sure that you don't simply catch Exception but check if the exception error message/code fits your specific issue, and rethrow it if it doesn't.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
Post Reply