Discussion:
[vbox-dev] Change setting with java Main API
Federica Renzi
2014-05-29 08:12:32 UTC
Permalink
Hi everyone,
I'm trying to change some VM setting during the execution of virtualbox. I
read in SDK documentation that it's possible only locking the machine and
saving its state, otherwise no change will be performed.

I tried to achieve it using java api (com-xpcom glue) and custumize
TestVBox.java, but I fall into these errors:

- if I write
m.lockMachine(sess, LockType.fromValue(2)); // lock write
The function "lockMachine" returned an error condition: "The machine
'NAME' is already locked for a session (or being unlocked)" (0x80bb0007)

- if I write
sess.unlockMachine();
The function "unlockMachine" returned an error condition: "The session
is not locked (session state: Unlocked)" (0x8000ffff)

- if I write directly (without any lock command)
m.saveSettings();
The function "saveSettings" returned an error condition: "The machine is
not mutable (state is Running)" (0x80bb0002)


How could I solve it?

Thanks
--
Federica Renzi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.virtualbox.org/pipermail/vbox-dev/attachments/20140529/4f0582ae/attachment.html
Maxime Dor
2014-05-29 20:07:02 UTC
Permalink
Use LockType.Shared instead - some other process must already be using the
VM (is it running?)
Post by Federica Renzi
Hi everyone,
I'm trying to change some VM setting during the execution of virtualbox. I
read in SDK documentation that it's possible only locking the machine and
saving its state, otherwise no change will be performed.
I tried to achieve it using java api (com-xpcom glue) and custumize
- if I write
m.lockMachine(sess, LockType.fromValue(2)); // lock write
The function "lockMachine" returned an error condition: "The machine
'NAME' is already locked for a session (or being unlocked)" (0x80bb0007)
- if I write
sess.unlockMachine();
The function "unlockMachine" returned an error condition: "The session
is not locked (session state: Unlocked)" (0x8000ffff)
- if I write directly (without any lock command)
m.saveSettings();
The function "saveSettings" returned an error condition: "The machine
is not mutable (state is Running)" (0x80bb0002)
How could I solve it?
Thanks
--
Federica Renzi
_______________________________________________
vbox-dev mailing list
vbox-dev at virtualbox.org
https://www.virtualbox.org/mailman/listinfo/vbox-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.virtualbox.org/pipermail/vbox-dev/attachments/20140529/73cf9804/attachment.html
Federica Renzi
2014-05-30 07:07:11 UTC
Permalink
thanks for your response!
Well...I tried to use LockType.Shared but It doesn't let me to save setting
( The function "saveSettings" returned an error condition: "The machine is
not mutable (state is Running)")

Yes, The machine is running under my control (in theory), because I started
it up using java Main Api.
I really would like to change some setting while it is running but I don't
understand if it's possible.
Post by Maxime Dor
Use LockType.Shared instead - some other process must already be using the
VM (is it running?)
Post by Federica Renzi
Hi everyone,
I'm trying to change some VM setting during the execution of virtualbox.
I read in SDK documentation that it's possible only locking the machine and
saving its state, otherwise no change will be performed.
I tried to achieve it using java api (com-xpcom glue) and custumize
- if I write
m.lockMachine(sess, LockType.fromValue(2)); // lock write
The function "lockMachine" returned an error condition: "The machine
'NAME' is already locked for a session (or being unlocked)" (0x80bb0007)
- if I write
sess.unlockMachine();
The function "unlockMachine" returned an error condition: "The
session is not locked (session state: Unlocked)" (0x8000ffff)
- if I write directly (without any lock command)
m.saveSettings();
The function "saveSettings" returned an error condition: "The machine
is not mutable (state is Running)" (0x80bb0002)
How could I solve it?
Thanks
--
Federica Renzi
_______________________________________________
vbox-dev mailing list
vbox-dev at virtualbox.org
https://www.virtualbox.org/mailman/listinfo/vbox-dev
--
Federica Renzi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.virtualbox.org/pipermail/vbox-dev/attachments/20140530/4dda3a6d/attachment.html
Federica Renzi
2014-05-30 09:59:36 UTC
Permalink
Errata corrige: I use launchVMProcess() method to start up the machine with
a frontend, so It will be that frontend the lock owner on machine, isn't it?

Let me see if I completely understood:
The only way to change setting (and make them effective) during runtime is
to have write lock on my machine and I can't do it starting up the machine
using an existing frontend...right?
If it is correct, I will have to write my own frontend...

Sorry for these questions but I'm newbie and VirtualBox is...huge!:-)
Post by Federica Renzi
thanks for your response!
Well...I tried to use LockType.Shared but It doesn't let me to save
setting ( The function "saveSettings" returned an error condition: "The
machine is not mutable (state is Running)")
Yes, The machine is running under my control (in theory), because I
started it up using java Main Api.
I really would like to change some setting while it is running but I don't
understand if it's possible.
Use LockType.Shared instead - some other process must already be using the
Post by Maxime Dor
VM (is it running?)
Post by Federica Renzi
Hi everyone,
I'm trying to change some VM setting during the execution of virtualbox.
I read in SDK documentation that it's possible only locking the machine and
saving its state, otherwise no change will be performed.
I tried to achieve it using java api (com-xpcom glue) and custumize
- if I write
m.lockMachine(sess, LockType.fromValue(2)); // lock write
The function "lockMachine" returned an error condition: "The machine
'NAME' is already locked for a session (or being unlocked)" (0x80bb0007)
- if I write
sess.unlockMachine();
The function "unlockMachine" returned an error condition: "The
session is not locked (session state: Unlocked)" (0x8000ffff)
- if I write directly (without any lock command)
m.saveSettings();
The function "saveSettings" returned an error condition: "The
machine is not mutable (state is Running)" (0x80bb0002)
How could I solve it?
Thanks
--
Federica Renzi
_______________________________________________
vbox-dev mailing list
vbox-dev at virtualbox.org
https://www.virtualbox.org/mailman/listinfo/vbox-dev
--
Federica Renzi
--
Federica Renzi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.virtualbox.org/pipermail/vbox-dev/attachments/20140530/04d00414/attachment-0001.html
Maxime Dor
2014-05-30 12:24:39 UTC
Permalink
You are correct, lunchVMPRocess() starts a front-end, so the Write lock
(which is exclusive) is not owned by you, but by the process of the front
end.
Some settings can be changed during runtime, and you only need a Shared
Lock for those (network interface attachment per exemple). Last time I
asked the devs, there was no exhaustive list of the settings that can be
changed with Shared lock. So you need to rely on the existing behaviour of
the Virtualbox Manager to know.

Be aware that a bug exist that allow you to still save all the settings
with the Java API (at least) : https://www.virtualbox.org/ticket/12164 - so
you can't just try & see which settings fails, they will all succeed.
Writing your own front-end will not help because the limitation of changing
the settings at runtime is because some are simply not taken into account
until you start the VM, like the amount of CPU or the amount of RAM. Even
if you wrote your own front-end and changed the values, they wouldn't be
taken into account before a poweroff & poweron of the VM.
I would not recommend writting your own front-end since you can use the
Shared lock to save settings.
Post by Federica Renzi
Errata corrige: I use launchVMProcess() method to start up the machine
with a frontend, so It will be that frontend the lock owner on machine,
isn't it?
The only way to change setting (and make them effective) during runtime is
to have write lock on my machine and I can't do it starting up the machine
using an existing frontend...right?
If it is correct, I will have to write my own frontend...
Sorry for these questions but I'm newbie and VirtualBox is...huge!:-)
thanks for your response!
Post by Federica Renzi
Well...I tried to use LockType.Shared but It doesn't let me to save
setting ( The function "saveSettings" returned an error condition: "The
machine is not mutable (state is Running)")
Yes, The machine is running under my control (in theory), because I
started it up using java Main Api.
I really would like to change some setting while it is running but I
don't understand if it's possible.
Use LockType.Shared instead - some other process must already be using
the VM (is it running?)
Post by Federica Renzi
Hi everyone,
I'm trying to change some VM setting during the execution of
virtualbox. I read in SDK documentation that it's possible only locking the
machine and saving its state, otherwise no change will be performed.
I tried to achieve it using java api (com-xpcom glue) and custumize
- if I write
m.lockMachine(sess, LockType.fromValue(2)); // lock write
The function "lockMachine" returned an error condition: "The
machine 'NAME' is already locked for a session (or being unlocked)"
(0x80bb0007)
- if I write
sess.unlockMachine();
The function "unlockMachine" returned an error condition: "The
session is not locked (session state: Unlocked)" (0x8000ffff)
- if I write directly (without any lock command)
m.saveSettings();
The function "saveSettings" returned an error condition: "The
machine is not mutable (state is Running)" (0x80bb0002)
How could I solve it?
Thanks
--
Federica Renzi
_______________________________________________
vbox-dev mailing list
vbox-dev at virtualbox.org
https://www.virtualbox.org/mailman/listinfo/vbox-dev
--
Federica Renzi
--
Federica Renzi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.virtualbox.org/pipermail/vbox-dev/attachments/20140530/aeed8dec/attachment.html
Klaus Espenlaub
2014-06-10 13:00:42 UTC
Permalink
Post by Maxime Dor
You are correct, lunchVMPRocess() starts a front-end, so the Write lock
(which is exclusive) is not owned by you, but by the process of the
front end.
Technically the VM process holds a VM lock, which is slightly different
than a Write lock. When something holds a Write lock then no one should
be able to get a Shared lock (which probably isn't true, the session
locking logic is still quirky).
Post by Maxime Dor
Some settings can be changed during runtime, and you only need a Shared
Lock for those (network interface attachment per exemple). Last time I
asked the devs, there was no exhaustive list of the settings that can be
changed with Shared lock. So you need to rely on the existing behaviour
of the Virtualbox Manager to know.
Actually you can always try (and VBoxManage in most cases doesn't check
either) to change some setting at VM run time, worst case you'll get the
error message about "not mutable". We try our best to allow changing
everything at run time, but it's not possible for everything. It must be
possible to make the change immediately visible to the VM.
Post by Maxime Dor
Be aware that a bug exist that allow you to still save all the settings
with the Java API (at least) : https://www.virtualbox.org/ticket/12164 -
so you can't just try & see which settings fails, they will all succeed.
Writing your own front-end will not help because the limitation of
changing the settings at runtime is because some are simply not taken
into account until you start the VM, like the amount of CPU or the
amount of RAM. Even if you wrote your own front-end and changed the
values, they wouldn't be taken into account before a poweroff & poweron
of the VM.
Updated that bug - don't yet know what's going wrong, but I have this
feeling that it has something to do with reusing the session object for
launching a VM and changing its settings. Shouldn't be the case as you
unlock it, but those are famous last words :)
Post by Maxime Dor
I would not recommend writting your own front-end since you can use the
Shared lock to save settings.
Yes, there's no need to hack up a new VM front end simply to allow
changing settings at run time. This can be done by a normal API client.

Klaus
Post by Maxime Dor
On 30 May 2014 11:59, Federica Renzi <renzi.fede at gmail.com
Errata corrige: I use launchVMProcess() method to start up the
machine with a frontend, so It will be that frontend the lock owner
on machine, isn't it?
The only way to change setting (and make them effective) during
runtime is to have write lock on my machine and I can't do it
starting up the machine using an existing frontend...right?
If it is correct, I will have to write my own frontend...
Sorry for these questions but I'm newbie and VirtualBox is...huge!:-)
2014-05-30 9:07 GMT+02:00 Federica Renzi <renzi.fede at gmail.com
thanks for your response!
Well...I tried to use LockType.Shared but It doesn't let me to
save setting ( The function "saveSettings" returned an error
condition: "The machine is not mutable (state is Running)")
Yes, The machine is running under my control (in theory),
because I started it up using java Main Api.
I really would like to change some setting while it is running
but I don't understand if it's possible.
2014-05-29 22:07 GMT+02:00 Maxime Dor <maxime.dor at altherian.org
Use LockType.Shared instead - some other process must
already be using the VM (is it running?)
On 29 May 2014 10:12, Federica Renzi <renzi.fede at gmail.com
Hi everyone,
I'm trying to change some VM setting during the
execution of virtualbox. I read in SDK documentation
that it's possible only locking the machine and saving
its state, otherwise no change will be performed.
I tried to achieve it using java api (com-xpcom glue)
* if I write
m.lockMachine(sess, LockType.fromValue(2)); // lock
write
The function "lockMachine" returned an error
condition: "The machine 'NAME' is already locked for
a session (or being unlocked)" (0x80bb0007)
* if I write
sess.unlockMachine();
The function "unlockMachine" returned an error
condition: "The session is not locked (session
state: Unlocked)" (0x8000ffff)
* if I write directly (without any lock command)
m.saveSettings();
The function "saveSettings" returned an error
condition: "The machine is not mutable (state is
Running)" (0x80bb0002)
How could I solve it?
Thanks
--
Federica Renzi
_______________________________________________
vbox-dev mailing list
vbox-dev at virtualbox.org <mailto:vbox-dev at virtualbox.org>
https://www.virtualbox.org/mailman/listinfo/vbox-dev
--
Federica Renzi
--
Federica Renzi
Loading...