LaunchVMProcess emergencystop API clarification?

Discussion about using the VirtualBox API, Tutorials, Samples.

LaunchVMProcess emergencystop API clarification?

Postby rousseauhk » 13. May 2013, 10:18

If I run

Code: Select all   Expand viewCollapse view
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   Expand viewCollapse view
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
rousseauhk
 
Posts: 45
Joined: 8. Apr 2013, 09:16
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Ubuntu Server

Re: LaunchVMProcess emergencystop API clarification?

Postby noteirak » 13. May 2013, 16:32

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://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: LaunchVMProcess emergencystop API clarification?

Postby noteirak » 13. May 2013, 21:26

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://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: LaunchVMProcess emergencystop API clarification?

Postby rousseauhk » 14. May 2013, 12:02

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
rousseauhk
 
Posts: 45
Joined: 8. Apr 2013, 09:16
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Ubuntu Server

Re: LaunchVMProcess emergencystop API clarification?

Postby noteirak » 14. May 2013, 13:58

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://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7

Re: LaunchVMProcess emergencystop API clarification?

Postby rousseauhk » 14. May 2013, 17:20

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   Expand viewCollapse view
; 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
rousseauhk
 
Posts: 45
Joined: 8. Apr 2013, 09:16
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Ubuntu Server

Re: LaunchVMProcess emergencystop API clarification?

Postby noteirak » 14. May 2013, 20:55

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://kamax.io/hbox/
Manage your VirtualBox infrastructure the free way!
noteirak
Site Moderator
 
Posts: 5198
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7


Return to The VirtualBox API

Who is online

Users browsing this forum: No registered users and 0 guests