[libvirt] [PATCH] Clear bandwidth settings for a shutoff domain using domiftune

2014-08-11 Thread Jianwei Hu
qemu: To clear bandwidth settings for a shutoff domain by using domiftune.

After applying this patch, we can use virsh domiftune command to clear inbound
or/and outbound setting for a shutoff domain.

for example:
virsh domiftune $domain $interface 0 0

Please refer to below virsh help message:

man virsh:

To clear inbound or outbound settings, use --inbound or --outbound respectfully 
with average value of zero.
---
 src/qemu/qemu_driver.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 82a82aa..7db2e9c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9983,11 +9983,17 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
 VIR_FREE(persistentNet-bandwidth-in);
 persistentNet-bandwidth-in = bandwidth-in;
 bandwidth-in = NULL;
+} else {
+VIR_FREE(persistentNet-bandwidth-in);
+persistentNet-bandwidth-in = 0;
 }
 if (bandwidth-out) {
 VIR_FREE(persistentNet-bandwidth-out);
 persistentNet-bandwidth-out = bandwidth-out;
 bandwidth-out = NULL;
+} else {
+VIR_FREE(persistentNet-bandwidth-out);
+persistentNet-bandwidth-out = 0;
 }
 }
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH RFC] LXC: add HOME environment variable

2014-08-11 Thread Daniel P. Berrange
On Tue, Aug 05, 2014 at 02:40:53AM +, chenhanx...@cn.fujitsu.com wrote:
 ping
 
  -Original Message-
  From: libvir-list-boun...@redhat.com [mailto:libvir-list-boun...@redhat.com]
  On Behalf Of Chen Hanxiao
  Sent: Friday, July 25, 2014 2:40 PM
  To: libvir-list@redhat.com
  Subject: [libvirt] [PATCH RFC] LXC: add HOME environment variable
  
  We lacked of HOME environment variable,
  set 'HOME=/' as default.
  
  Signed-off-by: Chen Hanxiao chenhanx...@cn.fujitsu.com
  ---
   src/lxc/lxc_container.c | 1 +
   1 file changed, 1 insertion(+)
  
  diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
  index 1cf2c8f..9df9c04 100644
  --- a/src/lxc/lxc_container.c
  +++ b/src/lxc/lxc_container.c
  @@ -236,6 +236,7 @@ static virCommandPtr
  lxcContainerBuildInitCmd(virDomainDefPtr vmDef,
   virCommandAddEnvString(cmd, PATH=/bin:/sbin);
   virCommandAddEnvString(cmd, TERM=linux);
   virCommandAddEnvString(cmd, container=lxc-libvirt);
  +virCommandAddEnvString(cmd, HOME=/);
   virCommandAddEnvPair(cmd, container_uuid, uuidstr);
   if (nttyPaths  1)
   virCommandAddEnvPair(cmd, container_ttys,
  virBufferCurrentContent(buf));

I'm curious what expects to have a $HOME env var set. I'd tend to view
the setting of $HOME to be something that the software in the container
should take care of.

Setting HOME=/ in libvirt isn't a problem, I'm just curious why we need
it.

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Include param.h in case of HAVE_BSD_CPU_AFFINITY

2014-08-11 Thread Michal Privoznik

On 10.08.2014 11:44, Guido Günther wrote:

This fixes compilation on kFreeBSD which otherwise fails like

   CC   util/libvirt_util_la-virprocess.lo
In file included from /usr/include/sys/cpuset.h:35:0,
  from util/virprocess.c:43:
/usr/include/sys/_cpuset.h:49:43: error: 'NBBY' undeclared here (not in
a function)
   long __bits[howmany(CPU_SETSIZE, _NCPUBITS)];
^
In file included from util/virprocess.c:43:0:
/usr/include/sys/cpuset.h:215:12: error: unknown type name 'cpusetid_t'
  int cpuset(cpusetid_t *);
 ^
/usr/include/sys/cpuset.h:216:30: error: expected ')' before 'id_t'
  int cpuset_setid(cpuwhich_t, id_t, cpusetid_t);
   ^
/usr/include/sys/cpuset.h:217:42: error: expected ')' before 'id_t'
  int cpuset_getid(cpulevel_t, cpuwhich_t, id_t, cpusetid_t *);
   ^
/usr/include/sys/cpuset.h:218:48: error: expected ')' before 'id_t'
  int cpuset_getaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, cpuset_t
*);
 ^
/usr/include/sys/cpuset.h:219:48: error: expected ')' before 'id_t'
  int cpuset_setaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, const
cpuset_t *);

And it's the correct usage as documented in

   http://www.freebsd.org/cgi/man.cgi?query=cpuset_setid
---
  src/util/virprocess.c | 1 +
  1 file changed, 1 insertion(+)

diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 9179d73..4d6c50d 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -40,6 +40,7 @@
  #endif

  #ifdef HAVE_BSD_CPU_AFFINITY
+# include sys/param.h
  # include sys/cpuset.h
  #endif




ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] qemu driver fails to load on Xen after be0782e1

2014-08-11 Thread Daniel P. Berrange
On Tue, Aug 05, 2014 at 11:16:53AM -0600, Jim Fehlig wrote:
 Jim Fehlig wrote:
  Until recently, the qemu driver has always succeeded in loading even on
  a system booted to Xen.  Commit be0782e1 broke this, hence libvirtd no
  longer loads
 
  xendom0 # /usr/sbin/libvirtd -l
  2014-08-04 22:27:31.586+: 35859: info : libvirt version: 1.2.8
  2014-08-04 22:27:31.586+: 35859: error :
  virFileGetDefaultHugepageSize:2958 : internal error: Unable to parse
  /proc/meminfo
  2014-08-04 22:27:31.586+: 35859: error : virStateInitialize:749 :
  Initialization of QEMU state driver failed: internal error: Unable to
  parse /proc/meminfo
  2014-08-04 22:27:31.586+: 35859: error : daemonRunStateInit:922 :
  Driver state initialization failed
 
  Problem is the Xen kernel does not provide any huge page info in
  /proc/meminfo
 
  xendom0 # cat /proc/meminfo | grep -i huge
  xendom0 #

 
 BTW, I think this would be the case for any kernel with
 CONFIG_HUGETLB_PAGE turned off.

Yes, we should be robust to this situation.

  Michal, short of always building with '--without-qemu' on a Xen system,
  is it possible to make detection of huge pages less fatal wrt loading
  the qemu driver?

 
 E.g. assume zero/default for entries not present?

If the dirs / files don't exist, we should just not report any huge
page info at all.

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Don't fail qemu driver intialization if we can't determine hugepage size

2014-08-11 Thread Michal Privoznik

On 10.08.2014 13:51, Guido Günther wrote:

Otherwise we fail like

   libvirt version: 1.2.7, package: 6 (root 2014-08-08-16:09:22 bogon)
   virAuditOpen:62 : Unable to initialize audit layer: Protocol not supported
   virFileGetDefaultHugepageSize:2958 : internal error: Unable to parse 
/proc/meminfo
   virStateInitialize:749 : Initialization of QEMU state driver failed: 
internal error: Unable to parse /proc/meminfo
   daemonRunStateInit:922 : Driver state initialization failed

if the data can't be determined.

Reference: http://bugs.debian.org/757609
---
  src/util/virfile.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index f9efc65..b6f5e3f 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -2953,8 +2953,9 @@ virFileGetDefaultHugepageSize(unsigned long long *size)
  goto cleanup;

  if (!(c = strstr(meminfo, HUGEPAGESIZE_STR))) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Unable to parse %s),
+virReportError(VIR_ERR_NO_SUPPORT,
+   _(%s not found in %s),
+   HUGEPAGESIZE_STR,
 PROC_MEMINFO);
  goto cleanup;
  }



This merely changes the error code and error message. But the 
initialization will fail anyway. Well, it would up till d26e81083. But 
the error message you suggests is more verbose and describes the origin 
of fault more accurately.


ACK

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] qemu driver fails to load on Xen after be0782e1

2014-08-11 Thread Michal Privoznik

On 11.08.2014 11:16, Daniel P. Berrange wrote:

On Tue, Aug 05, 2014 at 11:16:53AM -0600, Jim Fehlig wrote:

Jim Fehlig wrote:

Until recently, the qemu driver has always succeeded in loading even on
a system booted to Xen.  Commit be0782e1 broke this, hence libvirtd no
longer loads

xendom0 # /usr/sbin/libvirtd -l
2014-08-04 22:27:31.586+: 35859: info : libvirt version: 1.2.8
2014-08-04 22:27:31.586+: 35859: error :
virFileGetDefaultHugepageSize:2958 : internal error: Unable to parse
/proc/meminfo
2014-08-04 22:27:31.586+: 35859: error : virStateInitialize:749 :
Initialization of QEMU state driver failed: internal error: Unable to
parse /proc/meminfo
2014-08-04 22:27:31.586+: 35859: error : daemonRunStateInit:922 :
Driver state initialization failed

Problem is the Xen kernel does not provide any huge page info in
/proc/meminfo

xendom0 # cat /proc/meminfo | grep -i huge
xendom0 #



BTW, I think this would be the case for any kernel with
CONFIG_HUGETLB_PAGE turned off.


Yes, we should be robust to this situation.


And as of d26e810838fad we are fault tolerant.




Michal, short of always building with '--without-qemu' on a Xen system,
is it possible to make detection of huge pages less fatal wrt loading
the qemu driver?



E.g. assume zero/default for entries not present?


If the dirs / files don't exist, we should just not report any huge
page info at all.

Regards,
Daniel



Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [RFC] powerpc : Add support for VM in compat mode

2014-08-11 Thread Prerna Saxena

On Thursday 26 June 2014 03:41 PM, Prerna Saxena wrote:
 PowerISA allows processors to run VMs in binary compatibility (compat)
 mode supporting an older version of ISA. 
 Eg,in compatibility mode,  a POWER8 host can run a Power7 VM,conforming
 to PowerISA v2.06, while a POWER7 host can run a POWER6 VM, conforming
 to PowerISA v2.05.

 QEMU has recently added support to explicitly denote a VM running in
 compatibility mode through commit 6d9412ea. Now, a compat mode VM can
 be run by invoking this qemu commandline on a POWER8 host:
  -cpu host,compat=power7
 as against the older specification of -cpu power7.

 However, running in compatibility mode is not identical to running
 natively on an older processor. Hence the virtualization stack needs to
 explicitly provide for a compat-mode VM.

 This patch allows libvirt to extend the fallback semantics of cpu model to
 describe this new mode for PowerKVM guests.
 Additionally with the new scheme of things, qemu doesn't provide a way to 
 query
 for the supported compat models and models returned when querying with '-cpu 
 ?'
 are no longer valid. Hence removing the check cpuModelIsAllowed() for now.

 When a user wants to request a power7 vm to run in compatibility mode on
 a Power8 host, this can be described in XML as follows :
   cpu mode='custom' match='exact'
 model fallback='compat'power7/model 
   /cpu

 An alternative approach could be to leave the libvirt XML intact, and merely
 change the backend qemu command generation when the VM-requested cpu 
 does not match the host processor.

 Looking forward to suggestions on how this can best be implemented..

 Signed-off-by: Li Zhang zhlci...@linux.vnet.ibm.com
 Signed-off-by: Pradipta Kr. Banerjee bpra...@in.ibm.com
 Signed-off-by: Prerna Saxena pre...@linux.vnet.ibm.com

Ping !
Would folks have some feedback on the patch ?

Regards,

-- 
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Lifecycle events during reboot for KVM and Xen

2014-08-11 Thread Daniel P. Berrange
On Fri, Aug 08, 2014 at 10:54:53AM -0600, Jim Fehlig wrote:
 Thomas Bechtold wrote:
  Hi,
 
  during debugging a problem[1] of Openstack Nova I recognized the following:
 
  Doing a reboot (from inside of the VM with reboot command) on a kvm VM
  doesn't send any lifecycle events (events debugged with [2]).
  Doing the same thing with a xen VM leads to 2 events: First a
  VIR_DOMAIN_EVENT_STOPPED and then a VIR_DOMAIN_EVENT_STARTED event.

 
 Yep. Same can be said for new libxl Xen driver too.
 
  The problem here is that for the xen case it doesn't seem to be possible
  to recognize that a reboot is ongoing.
 
 Right. There is no VIR_DOMAIN_EVENT_REBOOTED event type.
 
   For that reason the OpenStack
  Nova component just forces the domain to stop after receiving the
  VIR_DOMAIN_EVENT_STOPPED event.

 
 Yikes!
 
  Is it expected that the 2 drivers send different events for the same
  action or a bug in qemu/xen/libvirt?

 
 You mentioned above that the qemu driver doesn't send *any* events when
 a reboot occurs within the VM. Looking at the code seems to confirm
 that. We could certainly change the Xen drivers to behave similarly, but
 I'd like to hear opinions from other libvirt devs. Options for resolving
 this include
 
 1. Remove emitting the events from Xen drivers

Possibily, though I'm not convinced this is actually possible.

 2. Add the events to qemu driver and fix nova
 3. Add VIR_DOMAIN_EVENT_REBOOTED, adapt drivers to use it, and fix nova

FYI, not having VIR_DOMAIN_EVENT_REBOOTED was an explicit decision since
it is not a lifecycle transition. We do have a separate event though
VIR_DOMAIN_EVENT_ID_REBOOOT to report on the case where the machine is
has a reset.

I think we probably need to make Nova robust to current behaviour.

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Lifecycle events during reboot for KVM and Xen

2014-08-11 Thread Daniel P. Berrange
On Thu, Aug 07, 2014 at 08:18:54AM +0200, Thomas Bechtold wrote:
 Hi,
 
 during debugging a problem[1] of Openstack Nova I recognized the following:
 
 Doing a reboot (from inside of the VM with reboot command) on a kvm VM
 doesn't send any lifecycle events (events debugged with [2]).
 Doing the same thing with a xen VM leads to 2 events: First a
 VIR_DOMAIN_EVENT_STOPPED and then a VIR_DOMAIN_EVENT_STARTED event.
 The problem here is that for the xen case it doesn't seem to be possible
 to recognize that a reboot is ongoing. For that reason the OpenStack
 Nova component just forces the domain to stop after receiving the
 VIR_DOMAIN_EVENT_STOPPED event.
 
 Is it expected that the 2 drivers send different events for the same
 action or a bug in qemu/xen/libvirt?

The lifecycle events reflect changes in the state of the machine hardware.
When a guest OS reboots in QEMU, the actual hardware does not do a running
- shutoff - running transition. Hence it is not appropriate to emit a
STOPPED/STARTED event in this case. I have a feeling that in Xen though,
the actual Xen domain is torn down  created again, though perhaps that is
actually different for PV vs HVM domains.

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH libvirt 1/6] conf: add MTP filesystem support to the parser

2014-08-11 Thread Daniel P. Berrange
On Thu, Aug 07, 2014 at 04:10:31PM +0200, Giuseppe Scrivano wrote:
 Signed-off-by: Giuseppe Scrivano gscri...@redhat.com
 ---
  src/conf/domain_conf.c | 34 +-
  src/conf/domain_conf.h |  1 +
  2 files changed, 26 insertions(+), 9 deletions(-)
 
 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
 index c25c74b..3bdf46a 100644
 --- a/src/conf/domain_conf.c
 +++ b/src/conf/domain_conf.c
 @@ -342,7 +342,8 @@ VIR_ENUM_IMPL(virDomainFS, VIR_DOMAIN_FS_TYPE_LAST,
file,
template,
ram,
 -  bind)
 +  bind,
 +  mtp)

I don't think this is the right way to represent it.

The 'type' attribute on filesystem represents where the backing store
for the filesystem comes from.

The distinction of 9p vs mtp reflects the type of guest device to expose
it as.

We shouldn't try to overload these two concepts in the same attribute.
We should instead try to add a device or model child element as we
have for some other device types.


Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Don't fail qemu driver intialization if we can't determine hugepage size

2014-08-11 Thread Guido Günther
On Mon, Aug 11, 2014 at 11:17:10AM +0200, Michal Privoznik wrote:
 On 10.08.2014 13:51, Guido Günther wrote:
 Otherwise we fail like
 
libvirt version: 1.2.7, package: 6 (root 2014-08-08-16:09:22 bogon)
virAuditOpen:62 : Unable to initialize audit layer: Protocol not supported
virFileGetDefaultHugepageSize:2958 : internal error: Unable to parse 
  /proc/meminfo
virStateInitialize:749 : Initialization of QEMU state driver failed: 
  internal error: Unable to parse /proc/meminfo
daemonRunStateInit:922 : Driver state initialization failed
 
 if the data can't be determined.
 
 Reference: http://bugs.debian.org/757609
 ---
   src/util/virfile.c | 5 +++--
   1 file changed, 3 insertions(+), 2 deletions(-)
 
 diff --git a/src/util/virfile.c b/src/util/virfile.c
 index f9efc65..b6f5e3f 100644
 --- a/src/util/virfile.c
 +++ b/src/util/virfile.c
 @@ -2953,8 +2953,9 @@ virFileGetDefaultHugepageSize(unsigned long long *size)
   goto cleanup;
 
   if (!(c = strstr(meminfo, HUGEPAGESIZE_STR))) {
 -virReportError(VIR_ERR_INTERNAL_ERROR,
 -   _(Unable to parse %s),
 +virReportError(VIR_ERR_NO_SUPPORT,
 +   _(%s not found in %s),
 +   HUGEPAGESIZE_STR,
  PROC_MEMINFO);
   goto cleanup;
   }
 
 
 This merely changes the error code and error message. But the initialization
 will fail anyway. Well, it would up till d26e81083. But the error message
 you suggests is more verbose and describes the origin of fault more
 accurately.

Initialization doesn't fail anymore with this since we have:

if (privileged 
virFileFindHugeTLBFS(cfg-hugetlbfs, cfg-nhugetlbfs)  0) {
/* This however is not implemented on all platforms. */
virErrorPtr err = virGetLastError();
if (err  err-code != VIR_ERR_NO_SUPPORT)
goto error;
}

in virQEMUDriverConfigNew so we only warn in this case. In case
someone has hugetlbfs_mount in qemu.conf we still fail hard which
is IMHO correct in this case.

 ACK

Thanks. I'll wait a bit more before pushding in case this isn't the
desired behviour!  
Cheers,
   -- Guido


 
 Michal
 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/1] numatune: Fix parsing of empty nodeset (0, ^0)

2014-08-11 Thread Erik Skultety
Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1121837
---
 src/conf/numatune_conf.c   | 18 +++--
 ...emuxml2argv-numatune-memory-invalid-nodeset.xml | 31 ++
 tests/qemuxml2argvtest.c   |  1 +
 3 files changed, 48 insertions(+), 2 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-numatune-memory-invalid-nodeset.xml

diff --git a/src/conf/numatune_conf.c b/src/conf/numatune_conf.c
index 48d1d04..9d7959a 100644
--- a/src/conf/numatune_conf.c
+++ b/src/conf/numatune_conf.c
@@ -182,6 +182,12 @@ virDomainNumatuneNodeParseXML(virDomainNumatunePtr 
*numatunePtr,
 if (virBitmapParse(tmp, 0, mem_node-nodeset,
VIR_DOMAIN_CPUMASK_LEN)  0)
 goto cleanup;
+
+if (virBitmapIsAllClear(mem_node-nodeset)) {
+virReportError(VIR_ERR_XML_ERROR, %s,
+   _(Numatune memory nodeset is empty));
+goto cleanup;
+}
 VIR_FREE(tmp);
 }
 
@@ -264,8 +270,16 @@ virDomainNumatuneParseXML(virDomainNumatunePtr 
*numatunePtr,
 VIR_FREE(tmp);
 
 tmp = virXMLPropString(node, nodeset);
-if (tmp  virBitmapParse(tmp, 0, nodeset, VIR_DOMAIN_CPUMASK_LEN)  0)
-goto cleanup;
+if (tmp) {
+if (virBitmapParse(tmp, 0, nodeset, VIR_DOMAIN_CPUMASK_LEN)  0)
+goto cleanup;
+
+if (virBitmapIsAllClear(nodeset)) {
+virReportError(VIR_ERR_XML_ERROR, %s,
+   _(Numatune memory nodeset is empty));
+goto cleanup;
+}
+}
 VIR_FREE(tmp);
 
 if (virDomainNumatuneSet(numatunePtr,
diff --git 
a/tests/qemuxml2argvdata/qemuxml2argv-numatune-memory-invalid-nodeset.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-numatune-memory-invalid-nodeset.xml
new file mode 100644
index 000..d2b41b4
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-numatune-memory-invalid-nodeset.xml
@@ -0,0 +1,31 @@
+domain type='qemu'
+  nameQEMUGuest1/name
+  uuidc7a5fdbd-edaf-9455-926a-d65c16db1809/uuid
+  memory unit='KiB'219136/memory
+  currentMemory unit='KiB'219136/currentMemory
+  vcpu placement='static' cpuset='0-1'2/vcpu
+  numatune
+memory mode=strict nodeset=0,^0/
+  /numatune
+  os
+type arch='i686' machine='pc'hvm/type
+boot dev='hd'/
+  /os
+  cpu
+topology sockets='2' cores='1' threads='1'/
+  /cpu
+  clock offset='utc'/
+  on_poweroffdestroy/on_poweroff
+  on_rebootrestart/on_reboot
+  on_crashdestroy/on_crash
+  devices
+emulator/usr/bin/qemu-kvm/emulator
+disk type='block' device='disk'
+  source dev='/dev/HostVG/QEMUGuest1'/
+  target dev='hda' bus='ide'/
+  address type='drive' controller='0' bus='0' target='0' unit='0'/
+/disk
+controller type='ide' index='0'/
+memballoon model='virtio'/
+  /devices
+/domain
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 1c121ff..62b969c 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1210,6 +1210,7 @@ mymain(void)
 DO_TEST(cputune-zero-shares, QEMU_CAPS_NAME);
 
 DO_TEST(numatune-memory, NONE);
+DO_TEST_PARSE_ERROR(numatune-memory-invalid-nodeset, NONE);
 DO_TEST(numatune-memnode, QEMU_CAPS_NUMA, QEMU_CAPS_OBJECT_MEMORY_RAM);
 DO_TEST_FAILURE(numatune-memnode, NONE);
 
-- 
1.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v1 3/3] qemu: Automatically create NVRAM store

2014-08-11 Thread Laszlo Ersek
On 08/08/14 14:05, Paolo Bonzini wrote:

 Il 08/08/2014 12:17, Michal Privoznik ha scritto:
 When using split UEFI image, it may come handy if libvirt manages per
 domain _VARS file automatically. While the _CODE file is RO and can
 be shared among multiple domains, you certainly don't want to do that
 on the _VARS file. This latter one needs to be per domain. So at the
 domain startup process, if it's determined that domain needs _VARS
 file it's copied from this master _VARS file. The location of the
 master file is configurable in qemu.conf and the default path can be
 compiled in via --with-qemu-nvram-file configure option.

 The only problem I see with this series is in this patch.

 The master _VARS file can be different for different machine types,
 for different architectures, and even for different _CODE files.

(I wasn't CC'd on the patch series, and I'm not a subscriber either, but
I now imported the set from the archive and hopefully can reply
in-thread.)

So, my suggestion was, for src/qemu/qemu.conf:

# Locations of master nvram files
#
# When a domain is configured to use UEFI instead of standard
# BIOS it may use a separate storage for UEFI variables. If
# that's the case libvirt creates the variable store per domain
# using this master file as image.
#
# Different firmware binaries can have different nvram templates;
# the following list specifies the mapping. Separate the
# nvram template from the firmware binary with a colon (:).
#
# nvram = [ /usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd ]

Michal then asked if we should maybe even say:

nvram = [ x86_64:/usr/share/OVMF/OVMF_CODE.fd:/usr/share/OVMF/OVMF_VARS.fd,
  i686:/usr/share/OVMF32/OVMF_CODE.fd:/usr/share/OVMF32/OVMF_VARS.fd ]

I don't think so. x86_64:/usr/share/OVMF/OVMF_CODE.fd does not carry
more information than just /usr/share/OVMF/OVMF_CODE.fd.

The firmware binary itself determines the valid architectures and the
nvram template; there's no additional degree of freedom in that
selection. That is, we do NOT have:

  (guest architecture, firmware binary) -- nvram template

instead we have:

firmware binary -- (
   { set of valid architectures / machtypes },
   nvram template
)

It is the user's responsibility to match architecture (machine type) and
firmware binary in the domain XML against each other.

- If they specify a firmware binary that is wrong for the architecture,
  the firmware simply won't run. (No different from trying to boot an OS
  that doesn't match the architecture.)

- If they specify the correct firmware binary, then it's *only* the
  firmware binary that libvirt needs to look at, in order to determine
  the nvram template.

Thanks,
Laszlo

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] Clear bandwidth settings for a shutoff domain using domiftune

2014-08-11 Thread Michal Privoznik

On 11.08.2014 08:41, Jianwei Hu wrote:

qemu: To clear bandwidth settings for a shutoff domain by using domiftune.

After applying this patch, we can use virsh domiftune command to clear inbound
or/and outbound setting for a shutoff domain.

for example:
virsh domiftune $domain $interface 0 0


Thanks for catching this.



Please refer to below virsh help message:

man virsh:

To clear inbound or outbound settings, use --inbound or --outbound respectfully 
with average value of zero.
---
  src/qemu/qemu_driver.c | 6 ++
  1 file changed, 6 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 82a82aa..7db2e9c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9983,11 +9983,17 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
  VIR_FREE(persistentNet-bandwidth-in);
  persistentNet-bandwidth-in = bandwidth-in;
  bandwidth-in = NULL;
+} else {
+VIR_FREE(persistentNet-bandwidth-in);
+persistentNet-bandwidth-in = 0;


We like NULL for pointer more than 0. Moreover, there's no need to 
explicitly set pointer freed to NULL as the VIR_FREE() macro does that 
already for you (in fact virFree() function does that, whatever).



  }
  if (bandwidth-out) {
  VIR_FREE(persistentNet-bandwidth-out);
  persistentNet-bandwidth-out = bandwidth-out;
  bandwidth-out = NULL;
+} else {
+VIR_FREE(persistentNet-bandwidth-out);
+persistentNet-bandwidth-out = 0;
  }
  }




But the fix isn't quite right. For instance:

virsh # domiftune dummy 52:54:00:89:3a:c2 --config
inbound.average: 10
inbound.peak   : 0
inbound.burst  : 0
outbound.average: 10
outbound.peak  : 0
outbound.burst : 0

virsh # domiftune dummy 52:54:00:89:3a:c2 --config 100

virsh # domiftune dummy 52:54:00:89:3a:c2 --config
inbound.average: 100
inbound.peak   : 0
inbound.burst  : 0
outbound.average: 0
outbound.peak  : 0
outbound.burst : 0

The bandwidth is cleared unconditionally. What we really need is:

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 82a82aa..2c3f179 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9983,11 +9983,15 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
 VIR_FREE(persistentNet-bandwidth-in);
 persistentNet-bandwidth-in = bandwidth-in;
 bandwidth-in = NULL;
+} else  if (inboundSpecified) {
+VIR_FREE(persistentNet-bandwidth-in);
 }
 if (bandwidth-out) {
 VIR_FREE(persistentNet-bandwidth-out);
 persistentNet-bandwidth-out = bandwidth-out;
 bandwidth-out = NULL;
+} else if (outboundSpecified) {
+VIR_FREE(persistentNet-bandwidth-out);
 }
 }

I'm fixing this patch though and pushing. ACK.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/1] qemu: min_guarantee: Parameter 'min_guarantee' not supported

2014-08-11 Thread Erik Skultety
The 'min_guarantee' is used by esx and vmx drivers, with qemu however,
libvirt should report error when starting a domain, because this
element is not used. Resolves
https://bugzilla.redhat.com/show_bug.cgi?id=1122455
---
 src/qemu/qemu_process.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 407da5e..22247fd 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3994,6 +3994,13 @@ int qemuProcessStart(virConnectPtr conn,
 flags  VIR_QEMU_PROCESS_START_COLD)  0)
 goto cleanup;
 
+if (vm-def-mem.min_guarantee) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
+   _(Parameter 'min_guarantee' 
+ not supported));
+goto cleanup;
+}
+
 if (VIR_ALLOC(priv-monConfig)  0)
 goto cleanup;
 
-- 
1.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 00/66] vbox: Rewrite vbox domain driver

2014-08-11 Thread Taowei
This series of patches rewrite the vbox's domain
driver. The driver is separated into two parts: the version
specified and the common part. The common driver use
vboxUniformedAPI to build a general driver for all vbox
versions. The vboxUniformedAPI take the responsiblity to
communicate with virtualbox. Since there are some incompatible
changes in virtualbox, vboxUniformedAPI should be aware of
these changes and provide a uniformed api for the upper layer.

The significant result of this patch is that we replace all
vir${vbox_version}Driver into one virCommonDriver. So, we will
have only one vbox driver implementation for all vbox versions
in libvirt.

PS: I have send part of my patches before:
https://www.redhat.com/archives/libvir-list/2014-July/msg00937.html
But I have to resend it beacuse I did some improvement on previous
patches:
*Remove the test case for vboxUniformedAPI, because it would raise
 break strict-aliasing rules warning in some distibutions
*Merged the flag fdWatchNeedInitialize into domainEventCallbacks,
 So, we use one flag to indicate whether vbox support callbacks
 as well as we need to initialize variables for it.

Taowei (66):
  vbox: Begin to rewrite, vboxConnectOpen
  vbox: Rewrite vboxConnectClose
  vbox: Rewrite vboxDomainSave
  vbox: Rewrite vboxConnectGetVersion
  vbox: Rewrite vboxConnectGetHostname
  vbox: Rewrite vboxConnectIsSecure
  vbox: Rewrite vboxConnectIsEncrypted
  vbox: Rewrite vboxConnectIsAlive
  vbox: Rewrite vboxConnectGetMaxVcpus
  vbox: Rewrite vboxConnectGetCapabilities
  vbox: Rewrite vboxConnectListDomains
  vbox: Rewrite vboxConnectNumOfDomains
  vbox: Rewrite vboxDomainLookupById
  vbox: Rewrite vboxDomainLookupByUUID
  vbox: Rewrite vboxDomainUndefineFlags
  vbox: Rewrite vboxDomainDefineXML
  vbox: Rewrite vboxDomainCreateWithFlags
  vbox: Rewrite vboxDomainCreate
  vbox: Rewrite vboxDomainCreateXML
  vbox: Rewrite vboxDomainLookupByName
  vbox: Rewrite vboxDomainIsActive
  vbox: Rewrite vboxDomainIsPersistent
  vbox: Rewrite vboxDomainIsUpdated
  vbox: Rewrite vboxDomainSuspend
  vbox: Rewrite vboxDomainResume
  vbox: Rewrite vboxDomainShutdownFlags
  vbox: Rewrite vboxDomainShutdown
  vbox: Rewrite vboxDomainReboot
  vbox: Rewrite vboxDomainDestroyFlags
  vbox: Rewrite vboxDomainDestroy
  vbox: Rewrite vboxDomainGetOSType
  vbox: Rewrite vboxDomainSetMemory
  vbox: Rewrite vboxDomainGetInfo
  vbox: Rewrite vboxDomainGetState
  vbox: Rewrite vboxDomainSetVcpusFlags
  vbox: Rewrite vboxDomainSetVcpus
  vbox: Rewrite vboxDomainGetVcpusFlags
  vbox: Rewrite vboxDomainGetMaxVcpus
  vbox: Add API for vboxDomainGetXMLDesc
  vbox: Rewrite vboxDomainGetXMLDesc
  vbox: Rewrite vboxConnectListDefinedDomains
  vbox: Rewrite vboxConnectNumOfDefinedDomains
  vbox: Rewrite vboxDomainUndefine
  vbox: Rewrite vboxDomainAttachDevice
  vbox: Rewrite vboxDomainAttachDeviceFlags
  vbox: Rewrite vboxDomainUpdateDeviceFlags
  vbox: Rewrite vboxDomainDetachDevice
  vbox: Rewrite vboxDomainDetachDeviceFlags
  vbox: Add API for vboxDomainSnapshotCreateXML
  vbox: Rewrite vboxDomainSnapshotCreateXML
  vbox: Rewrite vboxDomainSnapshotGetXMLDesc
  vbox: Rewrite vboxDomainSnapshotNum
  vbox: Rewrite vboxDomainSnapshotListNames
  vbox: Rewrite vboxSnapshotLookupByName
  vbox: Rewrite vboxDomainHasCurrentSnapshot
  vbox: Rewrite vboxDomainSnapshotGetParent
  vbox: Rewrite vboxDomainSnapshotCurrent
  vbox: Rewrite vboxDomainSnapshotIsCurrent
  vbox: Rewrite vboxDomainSnapshotHasMetadata
  vbox: Rewrite vboxDomainRevertToSnapshot
  vbox: Rewrite vboxDomainSnapshotDelete
  vbox: Rewrite vboxDomainScreenshot
  vbox: Rewrite vboxConnectListAllDomains
  vbox: Rewrite vboxNode functions
  vbox: Add registerDomainEvent
  vbox: Introducing vboxCommonDriver

 po/POTFILES.in|1 +
 src/Makefile.am   |5 +-
 src/vbox/README   |7 +-
 src/vbox/vbox_common.c| 7550 +
 src/vbox/vbox_common.h|  306 +
 src/vbox/vbox_driver.c|   40 +-
 src/vbox/vbox_install_api.h   |   26 +
 src/vbox/vbox_tmpl.c  |14557 +
 src/vbox/vbox_uniformed_api.h |  551 ++
 9 files changed, 13186 insertions(+), 9857 deletions(-)
 create mode 100644 src/vbox/vbox_common.c
 create mode 100644 src/vbox/vbox_common.h
 create mode 100644 src/vbox/vbox_install_api.h
 create mode 100644 src/vbox/vbox_uniformed_api.h

-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 03/66] vbox: Rewrite vboxDomainSave

2014-08-11 Thread Taowei
All vbox objects are child objects from the nsISupports in vbox's
C++ API version. Since the CAPI is generated from the C++ API, I
kept their relationship here, by the definitations below:

typedef struct nsISupports nsISupports;
typedef nsISupports IVirtualBox;
typedef nsISupports ISession;
and so on...

So, when calling the API from nsISupports, we don't need to do
typecasting, and things work still work well.
---
 src/vbox/vbox_common.c|   95 
 src/vbox/vbox_common.h|   45 +-
 src/vbox/vbox_tmpl.c  |  342 +++--
 src/vbox/vbox_uniformed_api.h |   82 ++
 4 files changed, 477 insertions(+), 87 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 06f1524..28d8668 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -42,6 +42,9 @@
 
 VIR_LOG_INIT(vbox.vbox_common);
 
+#define RC_SUCCEEDED(rc) NS_SUCCEEDED(rc.resultCode)
+#define RC_FAILED(rc) NS_FAILED(rc.resultCode)
+
 #define VBOX_UTF16_FREE(arg)\
 do {\
 if (arg) {  \
@@ -69,6 +72,31 @@ VIR_LOG_INIT(vbox.vbox_common);
 #define VBOX_UTF16_TO_UTF8(arg1, arg2)  
gVBoxAPI.UPFN.Utf16ToUtf8(data-pFuncs, arg1, arg2)
 #define VBOX_UTF8_TO_UTF16(arg1, arg2)  
gVBoxAPI.UPFN.Utf8ToUtf16(data-pFuncs, arg1, arg2)
 
+#define VBOX_RELEASE(arg) \
+do {  \
+if (arg) {\
+gVBoxAPI.nsUISupports.Release((void *)arg);
\
+(arg) = NULL; \
+} \
+} while (0)
+
+#define VBOX_OBJECT_CHECK(conn, type, value) \
+vboxGlobalData *data = conn-privateData;\
+type ret = value;\
+if (!data-vboxObj) {\
+return ret;\
+}
+
+#define vboxIIDUnalloc(iid) 
gVBoxAPI.UIID.vboxIIDUnalloc(data, iid)
+#define vboxIIDToUUID(iid, uuid)
gVBoxAPI.UIID.vboxIIDToUUID(data, iid, uuid)
+#define vboxIIDFromUUID(iid, uuid)  
gVBoxAPI.UIID.vboxIIDFromUUID(data, iid, uuid)
+#define vboxIIDIsEqual(iid1, iid2)  
gVBoxAPI.UIID.vboxIIDIsEqual(data, iid1, iid2)
+#define DEBUGIID(msg, iid)  gVBoxAPI.UIID.DEBUGIID(msg, 
iid)
+#define vboxIIDFromArrayItem(iid, array, idx) \
+gVBoxAPI.UIID.vboxIIDFromArrayItem(data, iid, array, idx)
+
+#define VBOX_IID_INITIALIZE(iid)
gVBoxAPI.UIID.vboxIIDInitialize(iid)
+
 /* global vbox API, used for all common codes. */
 static vboxUniformedAPI gVBoxAPI;
 
@@ -103,6 +131,22 @@ int vboxRegisterUniformedAPI(uint32_t uVersion)
 return 0;
 }
 
+static int openSessionForMachine(vboxGlobalData *data, const unsigned char 
*dom_uuid, vboxIIDUnion *iid,
+ IMachine **machine, bool checkflag)
+{
+VBOX_IID_INITIALIZE(iid);
+vboxIIDFromUUID(iid, dom_uuid);
+if (!checkflag || gVBoxAPI.getMachineForSession) {
+/* Get machine for the call to VBOX_SESSION_OPEN_EXISTING */
+if (NS_FAILED(gVBoxAPI.UIVirtualBox.GetMachine(data-vboxObj, iid, 
machine))) {
+virReportError(VIR_ERR_NO_DOMAIN, %s,
+   _(no domain with matching uuid));
+return -1;
+}
+}
+return 0;
+}
+
 static virDomainDefParserConfig vboxDomainDefParserConfig = {
 .macPrefix = { 0x08, 0x00, 0x27 },
 };
@@ -300,3 +344,54 @@ int vboxConnectClose(virConnectPtr conn)
 
 return 0;
 }
+
+int
+vboxDomainSave(virDomainPtr dom, const char *path ATTRIBUTE_UNUSED)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IConsole *console= NULL;
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+IProgress *progress = NULL;
+resultCodeUnion resultCode;
+nsresult rc;
+
+/* VirtualBox currently doesn't support saving to a file
+ * at a location other then the machine folder and thus
+ * setting path to ATTRIBUTE_UNUSED for now, will change
+ * this behaviour once get the VirtualBox API in right
+ * shape to do this
+ */
+
+/* Open a Session for the machine */
+if (openSessionForMachine(data, dom-uuid, iid, machine, true)  0)
+goto cleanup;
+
+rc = gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+if (NS_FAILED(rc))
+goto cleanup;
+
+rc = gVBoxAPI.UISession.GetConsole(data-vboxSession, console);
+if (NS_FAILED(rc) || !console)
+goto freeSession;
+
+rc = gVBoxAPI.UIConsole.SaveState(console, progress);
+if (!progress)
+goto freeSession;
+
+gVBoxAPI.UIProgress.WaitForCompletion(progress, -1);
+gVBoxAPI.UIProgress.GetResultCode(progress, resultCode);
+

[libvirt] [PATCH 01/66] vbox: Begin to rewrite, vboxConnectOpen

2014-08-11 Thread Taowei
Introduce vbox_uniformed_api to deal with version conflicts. Use
vbox_install_api to register the currect vboxUniformedAPI with
vbox version.

vboxConnectOpen has been rewritten.
---
 po/POTFILES.in|1 +
 src/Makefile.am   |5 +-
 src/vbox/vbox_common.c|  291 +
 src/vbox/vbox_common.h|  130 +++
 src/vbox/vbox_driver.c|   14 +-
 src/vbox/vbox_install_api.h   |   26 +++
 src/vbox/vbox_tmpl.c  |  363 ++---
 src/vbox/vbox_uniformed_api.h |  153 +
 8 files changed, 735 insertions(+), 248 deletions(-)
 create mode 100644 src/vbox/vbox_common.c
 create mode 100644 src/vbox/vbox_common.h
 create mode 100644 src/vbox/vbox_install_api.h
 create mode 100644 src/vbox/vbox_uniformed_api.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index d10e892..3a6bbe8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -216,6 +216,7 @@ src/util/virxml.c
 src/vbox/vbox_MSCOMGlue.c
 src/vbox/vbox_XPCOMCGlue.c
 src/vbox/vbox_driver.c
+src/vbox/vbox_common.c
 src/vbox/vbox_snapshot_conf.c
 src/vbox/vbox_tmpl.c
 src/vmware/vmware_conf.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 982f63d..05e91e4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -675,7 +675,10 @@ VBOX_DRIVER_SOURCES =  
\
vbox/vbox_V4_2.c vbox/vbox_CAPI_v4_2.h  \
vbox/vbox_V4_2_20.c vbox/vbox_CAPI_v4_2_20.h\
vbox/vbox_V4_3.c vbox/vbox_CAPI_v4_3.h  \
-   vbox/vbox_V4_3_4.c vbox/vbox_CAPI_v4_3_4.h
+   vbox/vbox_V4_3_4.c vbox/vbox_CAPI_v4_3_4.h  \
+   vbox/vbox_common.c vbox/vbox_common.h   \
+   vbox/vbox_uniformed_api.h   \
+   vbox/vbox_install_api.h
 
 VBOX_DRIVER_EXTRA_DIST =   \
vbox/vbox_tmpl.c vbox/README\
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
new file mode 100644
index 000..65a249f
--- /dev/null
+++ b/src/vbox/vbox_common.c
@@ -0,0 +1,291 @@
+/*
+ * Copyright 2014, Taowei Luo (uaeda...@gmail.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * http://www.gnu.org/licenses/.
+ */
+
+#include config.h
+
+#include unistd.h
+
+#include internal.h
+#include datatypes.h
+#include domain_conf.h
+#include domain_event.h
+#include virlog.h
+#include viralloc.h
+#include nodeinfo.h
+
+#include vbox_common.h
+#include vbox_uniformed_api.h
+#include vbox_install_api.h
+
+/* Common codes for vbox driver. With the definitions in vbox_common.h,
+ * it treats vbox structs as a void*. Though vboxUniformedAPI
+ * it call vbox functions. This file is a high level implement about
+ * the vbox driver.
+ */
+
+#define VIR_FROM_THIS VIR_FROM_VBOX
+
+VIR_LOG_INIT(vbox.vbox_common);
+
+#define VBOX_UTF16_FREE(arg)\
+do {\
+if (arg) {  \
+gVBoxAPI.UPFN.Utf16Free(data-pFuncs, arg); \
+(arg) = NULL;   \
+}   \
+} while (0)
+
+#define VBOX_UTF8_FREE(arg) \
+do {\
+if (arg) {  \
+gVBoxAPI.UPFN.Utf8Free(data-pFuncs, arg);  \
+(arg) = NULL;   \
+}   \
+} while (0)
+
+#define VBOX_COM_UNALLOC_MEM(arg)   \
+do {\
+if (arg) {  \
+gVBoxAPI.UPFN.ComUnallocMem(data-pFuncs, arg); \
+(arg) = NULL;   \
+}   \
+} while (0)
+
+#define VBOX_UTF16_TO_UTF8(arg1, arg2)  

[libvirt] [PATCH 02/66] vbox: Rewrite vboxConnectClose

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   11 +++
 src/vbox/vbox_tmpl.c  |   29 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 12 insertions(+), 29 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 65a249f..06f1524 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -289,3 +289,14 @@ virDrvOpenStatus vboxConnectOpen(virConnectPtr conn,
 
 return VIR_DRV_OPEN_SUCCESS;
 }
+
+int vboxConnectClose(virConnectPtr conn)
+{
+vboxGlobalData *data = conn-privateData;
+VIR_DEBUG(%s: in vboxClose, conn-driver-name);
+
+vboxUninitialize(data);
+conn-privateData = NULL;
+
+return 0;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 6c13775..6315a64 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -834,35 +834,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static void vboxUninitialize(vboxGlobalData *data)
-{
-if (!data)
-return;
-
-if (data-pFuncs)
-data-pFuncs-pfnComUninitialize();
-
-virObjectUnref(data-caps);
-virObjectUnref(data-xmlopt);
-#if VBOX_API_VERSION == 2002000
-/* No domainEventCallbacks in 2.2.* version */
-#else  /* !(VBOX_API_VERSION == 2002000) */
-virObjectEventStateFree(data-domainEvents);
-#endif /* !(VBOX_API_VERSION == 2002000) */
-VIR_FREE(data);
-}
-
-static int vboxConnectClose(virConnectPtr conn)
-{
-vboxGlobalData *data = conn-privateData;
-VIR_DEBUG(%s: in vboxClose, conn-driver-name);
-
-vboxUninitialize(data);
-conn-privateData = NULL;
-
-return 0;
-}
-
 static int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version)
 {
 vboxGlobalData *data = conn-privateData;
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 80abcbb..f424047 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -137,6 +137,7 @@ typedef struct {
 virDrvOpenStatus vboxConnectOpen(virConnectPtr conn,
  virConnectAuthPtr auth,
  unsigned int flags);
+int vboxConnectClose(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 05/66] vbox: Rewrite vboxConnectGetHostname

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|5 +
 src/vbox/vbox_tmpl.c  |6 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index f4f0d6d..585e6b5 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -417,3 +417,8 @@ int vboxConnectGetVersion(virConnectPtr conn, unsigned long 
*version)
 
 return 0;
 }
+
+char *vboxConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+return virGetHostname();
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 60e6098..ad01524 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -914,12 +914,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static char *vboxConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
-{
-return virGetHostname();
-}
-
-
 static int vboxConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 /* Driver is using local, non-network based transport */
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 5bb2e65..f56fe7a 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -221,6 +221,7 @@ virDrvOpenStatus vboxConnectOpen(virConnectPtr conn,
 int vboxConnectClose(virConnectPtr conn);
 int vboxDomainSave(virDomainPtr dom, const char *path);
 int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version);
+char *vboxConnectGetHostname(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 04/66] vbox: Rewrite vboxConnectGetVersion

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   22 ++
 src/vbox/vbox_tmpl.c  |   13 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 28d8668..f4f0d6d 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -395,3 +395,25 @@ vboxDomainSave(virDomainPtr dom, const char *path 
ATTRIBUTE_UNUSED)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+static void vboxDriverLock(vboxGlobalData *data)
+{
+virMutexLock(data-lock);
+}
+
+static void vboxDriverUnlock(vboxGlobalData *data)
+{
+virMutexUnlock(data-lock);
+}
+
+int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version)
+{
+vboxGlobalData *data = conn-privateData;
+VIR_DEBUG(%s: in vboxGetVersion, conn-driver-name);
+
+vboxDriverLock(data);
+*version = data-version;
+vboxDriverUnlock(data);
+
+return 0;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 0e9b6c8..60e6098 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -914,19 +914,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version)
-{
-vboxGlobalData *data = conn-privateData;
-VIR_DEBUG(%s: in vboxGetVersion, conn-driver-name);
-
-vboxDriverLock(data);
-*version = data-version;
-vboxDriverUnlock(data);
-
-return 0;
-}
-
-
 static char *vboxConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 return virGetHostname();
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 8538754..5bb2e65 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -220,6 +220,7 @@ virDrvOpenStatus vboxConnectOpen(virConnectPtr conn,
  unsigned int flags);
 int vboxConnectClose(virConnectPtr conn);
 int vboxDomainSave(virDomainPtr dom, const char *path);
+int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 08/66] vbox: Rewrite vboxConnectIsAlive

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|5 +
 src/vbox/vbox_tmpl.c  |5 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 2a3ab1e..4a75b88 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -434,3 +434,8 @@ int vboxConnectIsEncrypted(virConnectPtr conn 
ATTRIBUTE_UNUSED)
 /* No encryption is needed, or used on the local transport*/
 return 0;
 }
+
+int vboxConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+return 1;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 690c614..857640c 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -914,11 +914,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
-{
-return 1;
-}
-
 static int
 vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED)
 {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 15cac24..434b8d7 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -224,6 +224,7 @@ int vboxConnectGetVersion(virConnectPtr conn, unsigned long 
*version);
 char *vboxConnectGetHostname(virConnectPtr conn);
 int vboxConnectIsSecure(virConnectPtr conn);
 int vboxConnectIsEncrypted(virConnectPtr conn);
+int vboxConnectIsAlive(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 06/66] vbox: Rewrite vboxConnectIsSecure

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|6 ++
 src/vbox/vbox_tmpl.c  |6 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 585e6b5..f40f14d 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -422,3 +422,9 @@ char *vboxConnectGetHostname(virConnectPtr conn 
ATTRIBUTE_UNUSED)
 {
 return virGetHostname();
 }
+
+int vboxConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+/* Driver is using local, non-network based transport */
+return 1;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index ad01524..75eff4c 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -914,12 +914,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
-{
-/* Driver is using local, non-network based transport */
-return 1;
-}
-
 static int vboxConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 /* No encryption is needed, or used on the local transport*/
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index f56fe7a..d688403 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -222,6 +222,7 @@ int vboxConnectClose(virConnectPtr conn);
 int vboxDomainSave(virDomainPtr dom, const char *path);
 int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version);
 char *vboxConnectGetHostname(virConnectPtr conn);
+int vboxConnectIsSecure(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 09/66] vbox: Rewrite vboxConnectGetMaxVcpus

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   24 +++
 src/vbox/vbox_common.h|1 +
 src/vbox/vbox_tmpl.c  |   42 ++---
 src/vbox/vbox_uniformed_api.h |8 
 4 files changed, 51 insertions(+), 24 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 4a75b88..cb73f97 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -439,3 +439,27 @@ int vboxConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 return 1;
 }
+
+int
+vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED)
+{
+VBOX_OBJECT_CHECK(conn, int, -1);
+PRUint32 maxCPUCount = 0;
+
+/* VirtualBox Supports only hvm and thus the type passed to it
+ * has no meaning, setting it to ATTRIBUTE_UNUSED
+ */
+ISystemProperties *systemProperties = NULL;
+
+gVBoxAPI.UIVirtualBox.GetSystemProperties(data-vboxObj, 
systemProperties);
+if (!systemProperties)
+goto cleanup;
+gVBoxAPI.UISystemProperties.GetMaxGuestCPUCount(systemProperties, 
maxCPUCount);
+
+if (maxCPUCount  0)
+ret = maxCPUCount;
+
+ cleanup:
+VBOX_RELEASE(systemProperties);
+return ret;
+}
diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h
index 800e7cc..c4147a1 100644
--- a/src/vbox/vbox_common.h
+++ b/src/vbox/vbox_common.h
@@ -167,5 +167,6 @@ typedef nsISupports ISession;
 typedef nsISupports IConsole;
 typedef nsISupports IProgress;
 typedef nsISupports IMachine;
+typedef nsISupports ISystemProperties;
 
 #endif /* VBOX_COMMON_H */
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 857640c..deb3067 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -914,30 +914,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int
-vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED)
-{
-VBOX_OBJECT_CHECK(conn, int, -1);
-PRUint32 maxCPUCount = 0;
-
-/* VirtualBox Supports only hvm and thus the type passed to it
- * has no meaning, setting it to ATTRIBUTE_UNUSED
- */
-ISystemProperties *systemProperties = NULL;
-
-data-vboxObj-vtbl-GetSystemProperties(data-vboxObj, systemProperties);
-if (systemProperties) {
-systemProperties-vtbl-GetMaxGuestCPUCount(systemProperties, 
maxCPUCount);
-VBOX_RELEASE(systemProperties);
-}
-
-if (maxCPUCount  0)
-ret = maxCPUCount;
-
-return ret;
-}
-
-
 static char *vboxConnectGetCapabilities(virConnectPtr conn) {
 VBOX_OBJECT_CHECK(conn, char *, NULL);
 
@@ -11346,6 +11322,12 @@ _virtualboxGetMachine(IVirtualBox *vboxObj, 
vboxIIDUnion *iidu, IMachine **machi
 
 #endif /* VBOX_API_VERSION = 400 */
 
+static nsresult
+_virtualboxGetSystemProperties(IVirtualBox *vboxObj, ISystemProperties 
**systemProperties)
+{
+return vboxObj-vtbl-GetSystemProperties(vboxObj, systemProperties);
+}
+
 #if VBOX_API_VERSION  400
 
 static nsresult
@@ -11404,6 +11386,12 @@ _progressGetResultCode(IProgress *progress, 
resultCodeUnion *resultCode)
 #endif /* VBOX_API_VERSION != 2002000 */
 }
 
+static nsresult
+_systemPropertiesGetMaxGuestCPUCount(ISystemProperties *systemProperties, 
PRUint32 *maxCPUCount)
+{
+return systemProperties-vtbl-GetMaxGuestCPUCount(systemProperties, 
maxCPUCount);
+}
+
 static vboxUniformedPFN _UPFN = {
 .Initialize = _pfnInitialize,
 .Uninitialize = _pfnUninitialize,
@@ -11431,6 +11419,7 @@ static vboxUniformednsISupports _nsUISupports = {
 static vboxUniformedIVirtualBox _UIVirtualBox = {
 .GetVersion = _virtualboxGetVersion,
 .GetMachine = _virtualboxGetMachine,
+.GetSystemProperties = _virtualboxGetSystemProperties,
 };
 
 static vboxUniformedISession _UISession = {
@@ -11448,6 +11437,10 @@ static vboxUniformedIProgress _UIProgress = {
 .GetResultCode = _progressGetResultCode,
 };
 
+static vboxUniformedISystemProperties _UISystemProperties = {
+.GetMaxGuestCPUCount = _systemPropertiesGetMaxGuestCPUCount,
+};
+
 void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
 {
 pVBoxAPI-APIVersion = VBOX_API_VERSION;
@@ -11461,6 +11454,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI 
*pVBoxAPI)
 pVBoxAPI-UISession = _UISession;
 pVBoxAPI-UIConsole = _UIConsole;
 pVBoxAPI-UIProgress = _UIProgress;
+pVBoxAPI-UISystemProperties = _UISystemProperties;
 
 #if VBOX_API_VERSION = 2002000 || VBOX_API_VERSION = 400
 pVBoxAPI-domainEventCallbacks = 0;
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 434b8d7..2cc0674 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -171,6 +171,7 @@ typedef struct {
 typedef struct {
 nsresult (*GetVersion)(IVirtualBox *vboxObj, PRUnichar **versionUtf16);
 nsresult (*GetMachine)(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IMachine 
**machine);
+nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, 

[libvirt] [PATCH 07/66] vbox: Rewrite vboxConnectIsEncrypted

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|6 ++
 src/vbox/vbox_tmpl.c  |6 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index f40f14d..2a3ab1e 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -428,3 +428,9 @@ int vboxConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
 /* Driver is using local, non-network based transport */
 return 1;
 }
+
+int vboxConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+/* No encryption is needed, or used on the local transport*/
+return 0;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 75eff4c..690c614 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -914,12 +914,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
-{
-/* No encryption is needed, or used on the local transport*/
-return 0;
-}
-
 static int vboxConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 return 1;
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index d688403..15cac24 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -223,6 +223,7 @@ int vboxDomainSave(virDomainPtr dom, const char *path);
 int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version);
 char *vboxConnectGetHostname(virConnectPtr conn);
 int vboxConnectIsSecure(virConnectPtr conn);
+int vboxConnectIsEncrypted(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 30/66] vbox: Rewrite vboxDomainDestroy

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|5 +
 src/vbox/vbox_tmpl.c  |6 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index aaebc44..f889384 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2598,3 +2598,8 @@ int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int 
flags)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainDestroy(virDomainPtr dom)
+{
+return vboxDomainDestroyFlags(dom, 0);
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index c3f14be..3c4cd35 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,12 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int
-vboxDomainDestroy(virDomainPtr dom)
-{
-return vboxDomainDestroyFlags(dom, 0);
-}
-
 static char *vboxDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) {
 /* Returning hvm always as suggested on list, cause
  * this functions seems to be badly named and it
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index b9c2068..935697f 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -428,6 +428,7 @@ int vboxDomainShutdownFlags(virDomainPtr dom, unsigned int 
flags);
 int vboxDomainShutdown(virDomainPtr dom);
 int vboxDomainReboot(virDomainPtr dom, unsigned int flags);
 int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int flags);
+int vboxDomainDestroy(virDomainPtr dom);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 17/66] vbox: Rewrite vboxDomainCreateWithFlags

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|  219 
 src/vbox/vbox_tmpl.c  |  274 +++--
 src/vbox/vbox_uniformed_api.h |8 ++
 3 files changed, 269 insertions(+), 232 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index f4e992d..16c8f44 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1936,3 +1936,222 @@ int vboxDomainUndefineFlags(virDomainPtr dom, unsigned 
int flags)
 
 return ret;
 }
+
+static int
+vboxStartMachine(virDomainPtr dom, int maxDomID, IMachine *machine, 
vboxIIDUnion *iid)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+int vrdpPresent  = 0;
+int sdlPresent   = 0;
+int guiPresent   = 0;
+char *guiDisplay = NULL;
+char *sdlDisplay = NULL;
+PRUnichar *keyTypeUtf16  = NULL;
+PRUnichar *valueTypeUtf16= NULL;
+char  *valueTypeUtf8 = NULL;
+PRUnichar *keyDislpayUtf16   = NULL;
+PRUnichar *valueDisplayUtf16 = NULL;
+char  *valueDisplayUtf8  = NULL;
+IProgress *progress  = NULL;
+PRUnichar *env   = NULL;
+PRUnichar *sessionType   = NULL;
+nsresult rc;
+
+VBOX_UTF8_TO_UTF16(FRONTEND/Type, keyTypeUtf16);
+gVBoxAPI.UIMachine.GetExtraData(machine, keyTypeUtf16, valueTypeUtf16);
+VBOX_UTF16_FREE(keyTypeUtf16);
+
+if (valueTypeUtf16) {
+VBOX_UTF16_TO_UTF8(valueTypeUtf16, valueTypeUtf8);
+VBOX_UTF16_FREE(valueTypeUtf16);
+
+if (STREQ(valueTypeUtf8, sdl) || STREQ(valueTypeUtf8, gui)) {
+
+VBOX_UTF8_TO_UTF16(FRONTEND/Display, keyDislpayUtf16);
+gVBoxAPI.UIMachine.GetExtraData(machine, keyDislpayUtf16,
+valueDisplayUtf16);
+VBOX_UTF16_FREE(keyDislpayUtf16);
+
+if (valueDisplayUtf16) {
+VBOX_UTF16_TO_UTF8(valueDisplayUtf16, valueDisplayUtf8);
+VBOX_UTF16_FREE(valueDisplayUtf16);
+
+if (strlen(valueDisplayUtf8) = 0)
+VBOX_UTF8_FREE(valueDisplayUtf8);
+}
+
+if (STREQ(valueTypeUtf8, sdl)) {
+sdlPresent = 1;
+if (VIR_STRDUP(sdlDisplay, valueDisplayUtf8)  0) {
+/* just don't go to cleanup yet as it is ok to have
+ * sdlDisplay as NULL and we check it below if it
+ * exist and then only use it there
+ */
+}
+}
+
+if (STREQ(valueTypeUtf8, gui)) {
+guiPresent = 1;
+if (VIR_STRDUP(guiDisplay, valueDisplayUtf8)  0) {
+/* just don't go to cleanup yet as it is ok to have
+ * guiDisplay as NULL and we check it below if it
+ * exist and then only use it there
+ */
+}
+}
+}
+
+if (STREQ(valueTypeUtf8, vrdp)) {
+vrdpPresent = 1;
+}
+
+if (!vrdpPresent  !sdlPresent  !guiPresent) {
+/* if nothing is selected it means either the machine xml
+ * file is really old or some values are missing so fallback
+ */
+guiPresent = 1;
+}
+
+VBOX_UTF8_FREE(valueTypeUtf8);
+
+} else {
+guiPresent = 1;
+}
+VBOX_UTF8_FREE(valueDisplayUtf8);
+
+if (guiPresent) {
+if (guiDisplay) {
+char *displayutf8;
+if (virAsprintf(displayutf8, DISPLAY=%s, guiDisplay) = 0) {
+VBOX_UTF8_TO_UTF16(displayutf8, env);
+VIR_FREE(displayutf8);
+}
+VIR_FREE(guiDisplay);
+}
+
+VBOX_UTF8_TO_UTF16(gui, sessionType);
+}
+
+if (sdlPresent) {
+if (sdlDisplay) {
+char *displayutf8;
+if (virAsprintf(displayutf8, DISPLAY=%s, sdlDisplay) = 0) {
+VBOX_UTF8_TO_UTF16(displayutf8, env);
+VIR_FREE(displayutf8);
+}
+VIR_FREE(sdlDisplay);
+}
+
+VBOX_UTF8_TO_UTF16(sdl, sessionType);
+}
+
+if (vrdpPresent) {
+VBOX_UTF8_TO_UTF16(vrdp, sessionType);
+}
+
+rc = gVBoxAPI.UIMachine.LaunchVMProcess(data, machine, iid,
+sessionType, env,
+progress);
+
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(OpenRemoteSession/LaunchVMProcess failed, domain 
can't be started));
+ret = -1;
+} else {
+PRBool completed = 0;
+resultCodeUnion resultCode;
+
+gVBoxAPI.UIProgress.WaitForCompletion(progress, -1);
+rc = gVBoxAPI.UIProgress.GetCompleted(progress, completed);
+if (NS_FAILED(rc)) {
+/* error */
+ret = -1;
+}
+

[libvirt] [PATCH 10/66] vbox: Rewrite vboxConnectGetCapabilities

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   11 +++
 src/vbox/vbox_tmpl.c  |   16 ++--
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index cb73f97..eaefe81 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -463,3 +463,14 @@ vboxConnectGetMaxVcpus(virConnectPtr conn, const char 
*type ATTRIBUTE_UNUSED)
 VBOX_RELEASE(systemProperties);
 return ret;
 }
+
+char *vboxConnectGetCapabilities(virConnectPtr conn)
+{
+VBOX_OBJECT_CHECK(conn, char *, NULL);
+
+vboxDriverLock(data);
+ret = virCapabilitiesFormatXML(data-caps);
+vboxDriverUnlock(data);
+
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index deb3067..7f9b4cc 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -256,6 +256,10 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr 
conn, const char *xml);
 static int vboxDomainCreate(virDomainPtr dom);
 static int vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags);
 
+#if VBOX_API_VERSION  2002000  VBOX_API_VERSION  400
+/* Since vboxConnectGetCapabilities has been rewriten,
+ * vboxDiverLock and Unlock only be used in 3.* */
+
 static void vboxDriverLock(vboxGlobalData *data)
 {
 virMutexLock(data-lock);
@@ -266,6 +270,8 @@ static void vboxDriverUnlock(vboxGlobalData *data)
 virMutexUnlock(data-lock);
 }
 
+#endif
+
 #if VBOX_API_VERSION == 2002000
 
 static void nsIDtoChar(unsigned char *uuid, const nsID *iid)
@@ -914,16 +920,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static char *vboxConnectGetCapabilities(virConnectPtr conn) {
-VBOX_OBJECT_CHECK(conn, char *, NULL);
-
-vboxDriverLock(data);
-ret = virCapabilitiesFormatXML(data-caps);
-vboxDriverUnlock(data);
-
-return ret;
-}
-
 static int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
 {
 VBOX_OBJECT_CHECK(conn, int, -1);
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 2cc0674..e49b881 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -233,6 +233,7 @@ int vboxConnectIsSecure(virConnectPtr conn);
 int vboxConnectIsEncrypted(virConnectPtr conn);
 int vboxConnectIsAlive(virConnectPtr conn);
 int vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type);
+char *vboxConnectGetCapabilities(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 27/66] vbox: Rewrite vboxDomainShutdown

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|5 +
 src/vbox/vbox_tmpl.c  |6 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 6371eb2..b15e8a3 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2504,3 +2504,8 @@ int vboxDomainShutdownFlags(virDomainPtr dom, unsigned 
int flags)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainShutdown(virDomainPtr dom)
+{
+return vboxDomainShutdownFlags(dom, 0);
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 3a25185..4c008c9 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,12 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainShutdown(virDomainPtr dom)
-{
-return vboxDomainShutdownFlags(dom, 0);
-}
-
-
 static int vboxDomainReboot(virDomainPtr dom, unsigned int flags)
 {
 VBOX_OBJECT_CHECK(dom-conn, int, -1);
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index bfd5339..bf53b27 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -423,6 +423,7 @@ int vboxDomainIsUpdated(virDomainPtr dom);
 int vboxDomainSuspend(virDomainPtr dom);
 int vboxDomainResume(virDomainPtr dom);
 int vboxDomainShutdownFlags(virDomainPtr dom, unsigned int flags);
+int vboxDomainShutdown(virDomainPtr dom);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 18/66] vbox: Rewrite vboxDomainCreate

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|5 +
 src/vbox/vbox_tmpl.c  |7 ---
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 16c8f44..4957655 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2155,3 +2155,8 @@ int vboxDomainCreateWithFlags(virDomainPtr dom, unsigned 
int flags)
  cleanup:
 return ret;
 }
+
+int vboxDomainCreate(virDomainPtr dom)
+{
+return vboxDomainCreateWithFlags(dom, 0);
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 177dc55..d9d0c3d 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -265,8 +265,6 @@ static vboxGlobalData *g_pVBoxGlobalData = NULL;
 
 #endif /* VBOX_API_VERSION = 400 */
 
-static int vboxDomainCreate(virDomainPtr dom);
-
 #if VBOX_API_VERSION  2002000  VBOX_API_VERSION  400
 /* Since vboxConnectGetCapabilities has been rewriten,
  * vboxDiverLock and Unlock only be used in 3.* */
@@ -3080,11 +3078,6 @@ static int vboxConnectNumOfDefinedDomains(virConnectPtr 
conn)
 return ret;
 }
 
-static int vboxDomainCreate(virDomainPtr dom)
-{
-return vboxDomainCreateWithFlags(dom, 0);
-}
-
 #if VBOX_API_VERSION  3001000
 
 static void
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index ff03749..e745bc7 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -406,6 +406,7 @@ virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
 virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml);
 int vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags);
 int vboxDomainCreateWithFlags(virDomainPtr dom, unsigned int flags);
+int vboxDomainCreate(virDomainPtr dom);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 19/66] vbox: Rewrite vboxDomainCreateXML

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   28 
 src/vbox/vbox_tmpl.c  |   28 
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 30 insertions(+), 28 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 4957655..9dc95a4 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2160,3 +2160,31 @@ int vboxDomainCreate(virDomainPtr dom)
 {
 return vboxDomainCreateWithFlags(dom, 0);
 }
+
+virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
+ unsigned int flags)
+{
+/* VirtualBox currently doesn't have support for running
+ * virtual machines without actually defining them and thus
+ * for time being just define new machine and start it.
+ *
+ * TODO: After the appropriate API's are added in VirtualBox
+ * change this behaviour to the expected one.
+ */
+
+virDomainPtr dom;
+
+virCheckFlags(0, NULL);
+
+dom = vboxDomainDefineXML(conn, xml);
+if (dom == NULL)
+return NULL;
+
+if (vboxDomainCreate(dom)  0) {
+vboxDomainUndefineFlags(dom, 0);
+virObjectUnref(dom);
+return NULL;
+}
+
+return dom;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index d9d0c3d..51fb7bd 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,34 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
-unsigned int flags)
-{
-/* VirtualBox currently doesn't have support for running
- * virtual machines without actually defining them and thus
- * for time being just define new machine and start it.
- *
- * TODO: After the appropriate API's are added in VirtualBox
- * change this behaviour to the expected one.
- */
-
-virDomainPtr dom;
-
-virCheckFlags(0, NULL);
-
-dom = vboxDomainDefineXML(conn, xml);
-if (dom == NULL)
-return NULL;
-
-if (vboxDomainCreate(dom)  0) {
-vboxDomainUndefineFlags(dom, 0);
-virObjectUnref(dom);
-return NULL;
-}
-
-return dom;
-}
-
 static virDomainPtr
 vboxDomainLookupByName(virConnectPtr conn, const char *name)
 {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index e745bc7..1c11caa 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -407,6 +407,8 @@ virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const 
char *xml);
 int vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags);
 int vboxDomainCreateWithFlags(virDomainPtr dom, unsigned int flags);
 int vboxDomainCreate(virDomainPtr dom);
+virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
+ unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 11/66] vbox: Rewrite vboxConnectListDomains

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   42 ++
 src/vbox/vbox_tmpl.c  |   80 +
 src/vbox/vbox_uniformed_api.h |   22 
 3 files changed, 105 insertions(+), 39 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index eaefe81..6de5757 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -97,6 +97,10 @@ if (!data-vboxObj) {\
 
 #define VBOX_IID_INITIALIZE(iid)
gVBoxAPI.UIID.vboxIIDInitialize(iid)
 
+#define ARRAY_GET_MACHINES \
+(gVBoxAPI.UArray.handleGetMachines(data-vboxObj))
+
+
 /* global vbox API, used for all common codes. */
 static vboxUniformedAPI gVBoxAPI;
 
@@ -474,3 +478,41 @@ char *vboxConnectGetCapabilities(virConnectPtr conn)
 
 return ret;
 }
+
+int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
+{
+VBOX_OBJECT_CHECK(conn, int, -1);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+PRUint32 state;
+nsresult rc;
+size_t i, j;
+
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of Domains, rc=%08x),
+   (unsigned)rc);
+goto cleanup;
+}
+
+ret = 0;
+for (i = 0, j = 0; (i  machines.count)  (j  nids); ++i) {
+IMachine *machine = machines.items[i];
+
+if (machine) {
+PRBool isAccessible = PR_FALSE;
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (isAccessible) {
+gVBoxAPI.UIMachine.GetState(machine, state);
+if (gVBoxAPI.machineStateChecker.Online(state)) {
+ret++;
+ids[j++] = i + 1;
+}
+}
+}
+}
+
+ cleanup:
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 7f9b4cc..e0033b9 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -920,45 +920,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
-{
-VBOX_OBJECT_CHECK(conn, int, -1);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-PRUint32 state;
-nsresult rc;
-size_t i, j;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get list of Domains, rc=%08x),
-   (unsigned)rc);
-goto cleanup;
-}
-
-ret = 0;
-for (i = 0, j = 0; (i  machines.count)  (j  nids); ++i) {
-IMachine *machine = machines.items[i];
-
-if (machine) {
-PRBool isAccessible = PR_FALSE;
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-if ((state = MachineState_FirstOnline) 
-(state = MachineState_LastOnline)) {
-ret++;
-ids[j++] = i + 1;
-}
-}
-}
-}
-
- cleanup:
-vboxArrayRelease(machines);
-return ret;
-}
-
 static int vboxConnectNumOfDomains(virConnectPtr conn)
 {
 VBOX_OBJECT_CHECK(conn, int, -1);
@@ -11289,6 +11250,11 @@ static void _DEBUGIID(const char *msg, vboxIIDUnion 
*iidu)
 
 #endif /* VBOX_API_VERSION != 2002000 */
 
+static void* _handleGetMachines(IVirtualBox *vboxObj)
+{
+return vboxObj-vtbl-GetMachines;
+}
+
 static nsresult _nsisupportsRelease(nsISupports *nsi)
 {
 return nsi-vtbl-Release(nsi);
@@ -11324,6 +11290,18 @@ _virtualboxGetSystemProperties(IVirtualBox *vboxObj, 
ISystemProperties **systemP
 return vboxObj-vtbl-GetSystemProperties(vboxObj, systemProperties);
 }
 
+static nsresult
+_machineGetAccessible(IMachine *machine, PRBool *isAccessible)
+{
+return machine-vtbl-GetAccessible(machine, isAccessible);
+}
+
+static nsresult
+_machineGetState(IMachine *machine, PRUint32 *state)
+{
+return machine-vtbl-GetState(machine, state);
+}
+
 #if VBOX_API_VERSION  400
 
 static nsresult
@@ -11388,6 +11366,12 @@ _systemPropertiesGetMaxGuestCPUCount(ISystemProperties 
*systemProperties, PRUint
 return systemProperties-vtbl-GetMaxGuestCPUCount(systemProperties, 
maxCPUCount);
 }
 
+static bool _machineStateOnline(PRUint32 state)
+{
+return ((state = MachineState_FirstOnline) 
+(state = MachineState_LastOnline));
+}
+
 static vboxUniformedPFN _UPFN = {
 .Initialize = _pfnInitialize,
 .Uninitialize = _pfnUninitialize,
@@ -11408,6 +11392,12 @@ static vboxUniformedIID _UIID = {
 .DEBUGIID = _DEBUGIID,
 };
 
+static vboxUniformedArray _UArray = {
+.vboxArrayGet = vboxArrayGet,
+.vboxArrayRelease = vboxArrayRelease,
+

[libvirt] [PATCH 33/66] vbox: Rewrite vboxDomainGetInfo

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   79 ++
 src/vbox/vbox_tmpl.c  |  106 ++---
 src/vbox/vbox_uniformed_api.h |5 ++
 3 files changed, 108 insertions(+), 82 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index b457c00..d661110 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2669,3 +2669,82 @@ int vboxDomainSetMemory(virDomainPtr dom, unsigned long 
memory)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+char *machineName= NULL;
+PRUnichar *machineNameUtf16 = NULL;
+nsresult rc;
+size_t i = 0;
+
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
+goto cleanup;
+}
+
+info-nrVirtCpu = 0;
+for (i = 0; i  machines.count; ++i) {
+IMachine *machine = machines.items[i];
+PRBool isAccessible = PR_FALSE;
+
+if (!machine)
+continue;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+continue;
+
+gVBoxAPI.UIMachine.GetName(machine, machineNameUtf16);
+VBOX_UTF16_TO_UTF8(machineNameUtf16, machineName);
+
+if (STREQ(dom-name, machineName)) {
+/* Get the Machine State (also match it with
+* virDomainState). Get the Machine memory and
+* for time being set max_balloon and cur_balloon to same
+* Also since there is no direct way of checking
+* the cputime required (one condition being the
+* VM is remote), return zero for cputime. Get the
+* number of CPU.
+*/
+PRUint32 CPUCount   = 0;
+PRUint32 memorySize = 0;
+PRUint32 state;
+PRUint32 maxMemorySize = 4 * 1024;
+ISystemProperties *systemProperties = NULL;
+
+gVBoxAPI.UIVirtualBox.GetSystemProperties(data-vboxObj, 
systemProperties);
+if (systemProperties) {
+gVBoxAPI.UISystemProperties.GetMaxGuestRAM(systemProperties, 
maxMemorySize);
+VBOX_RELEASE(systemProperties);
+systemProperties = NULL;
+}
+
+gVBoxAPI.UIMachine.GetCPUCount(machine, CPUCount);
+gVBoxAPI.UIMachine.GetMemorySize(machine, memorySize);
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+info-cpuTime = 0;
+info-nrVirtCpu = CPUCount;
+info-memory = memorySize * 1024;
+info-maxMem = maxMemorySize * 1024;
+info-state = gVBoxAPI.vboxConvertState(state);
+
+ret = 0;
+}
+
+VBOX_UTF8_FREE(machineName);
+VBOX_COM_UNALLOC_MEM(machineNameUtf16);
+if (info-nrVirtCpu)
+break;
+
+}
+
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+
+ cleanup:
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 2cb564e..3ae1864 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,7 +932,7 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static virDomainState vboxConvertState(enum MachineState state)
+static virDomainState _vboxConvertState(PRUint32 state)
 {
 switch (state) {
 case MachineState_Running:
@@ -954,86 +954,6 @@ static virDomainState vboxConvertState(enum MachineState 
state)
 }
 }
 
-static int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-char *machineName= NULL;
-PRUnichar *machineNameUtf16 = NULL;
-nsresult rc;
-size_t i = 0;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
-goto cleanup;
-}
-
-info-nrVirtCpu = 0;
-for (i = 0; i  machines.count; ++i) {
-IMachine *machine = machines.items[i];
-PRBool isAccessible = PR_FALSE;
-
-if (!machine)
-continue;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-
-machine-vtbl-GetName(machine, machineNameUtf16);
-VBOX_UTF16_TO_UTF8(machineNameUtf16, machineName);
-
-if (STREQ(dom-name, machineName)) {
-/* Get the Machine State (also match it with
-* virDomainState). Get the Machine memory and
-* for time being set max_balloon and cur_balloon to same
-

[libvirt] [PATCH 31/66] vbox: Rewrite vboxDomainGetOSType

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   12 
 src/vbox/vbox_tmpl.c  |   12 
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index f889384..102500a 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2603,3 +2603,15 @@ int vboxDomainDestroy(virDomainPtr dom)
 {
 return vboxDomainDestroyFlags(dom, 0);
 }
+
+char *vboxDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) {
+/* Returning hvm always as suggested on list, cause
+ * this functions seems to be badly named and it
+ * is supposed to pass the ABI name and not the domain
+ * operating system driver as I had imagined ;)
+ */
+char *osType;
+
+ignore_value(VIR_STRDUP(osType, hvm));
+return osType;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 3c4cd35..58f921a 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,18 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static char *vboxDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) {
-/* Returning hvm always as suggested on list, cause
- * this functions seems to be badly named and it
- * is supposed to pass the ABI name and not the domain
- * operating system driver as I had imagined ;)
- */
-char *osType;
-
-ignore_value(VIR_STRDUP(osType, hvm));
-return osType;
-}
-
 static int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory)
 {
 VBOX_OBJECT_CHECK(dom-conn, int, -1);
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 935697f..31a0e45 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -429,6 +429,7 @@ int vboxDomainShutdown(virDomainPtr dom);
 int vboxDomainReboot(virDomainPtr dom, unsigned int flags);
 int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int flags);
 int vboxDomainDestroy(virDomainPtr dom);
+char *vboxDomainGetOSType(virDomainPtr dom);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 20/66] vbox: Rewrite vboxDomainLookupByName

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   70 
 src/vbox/vbox_tmpl.c  |   71 -
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 72 insertions(+), 71 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 9dc95a4..fbb90ac 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -824,6 +824,76 @@ virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
 return ret;
 }
 
+virDomainPtr
+vboxDomainLookupByName(virConnectPtr conn, const char *name)
+{
+VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+vboxIIDUnion iid;
+char  *machineNameUtf8  = NULL;
+PRUnichar *machineNameUtf16 = NULL;
+unsigned char uuid[VIR_UUID_BUFLEN];
+size_t i;
+int matched = 0;
+nsresult rc;
+
+VBOX_IID_INITIALIZE(iid);
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
+return NULL;
+}
+
+for (i = 0; i  machines.count; ++i) {
+IMachine *machine = machines.items[i];
+PRBool isAccessible = PR_FALSE;
+
+if (!machine)
+continue;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+continue;
+
+gVBoxAPI.UIMachine.GetName(machine, machineNameUtf16);
+VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
+
+if (STREQ(name, machineNameUtf8)) {
+
+PRUint32 state;
+
+matched = 1;
+
+gVBoxAPI.UIMachine.GetId(machine, iid);
+vboxIIDToUUID(iid, uuid);
+vboxIIDUnalloc(iid);
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+/* get a new domain pointer from virGetDomain, if it fails
+ * then no need to assign the id, else assign the id, cause
+ * it is -1 by default. rest is taken care by virGetDomain
+ * itself, so need not worry.
+ */
+
+ret = virGetDomain(conn, machineNameUtf8, uuid);
+if (ret 
+gVBoxAPI.machineStateChecker.Online(state))
+ret-id = i + 1;
+}
+
+VBOX_UTF8_FREE(machineNameUtf8);
+VBOX_COM_UNALLOC_MEM(machineNameUtf16);
+if (matched == 1)
+break;
+}
+
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+
+return ret;
+}
+
 static void
 vboxSetBootDeviceOrder(virDomainDefPtr def, vboxGlobalData *data,
IMachine *machine)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 51fb7bd..7bb6896 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,77 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static virDomainPtr
-vboxDomainLookupByName(virConnectPtr conn, const char *name)
-{
-VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-vboxIID iid = VBOX_IID_INITIALIZER;
-char  *machineNameUtf8  = NULL;
-PRUnichar *machineNameUtf16 = NULL;
-unsigned char uuid[VIR_UUID_BUFLEN];
-size_t i;
-int matched = 0;
-nsresult rc;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
-return NULL;
-}
-
-for (i = 0; i  machines.count; ++i) {
-IMachine *machine = machines.items[i];
-PRBool isAccessible = PR_FALSE;
-
-if (!machine)
-continue;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-
-machine-vtbl-GetName(machine, machineNameUtf16);
-VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
-
-if (STREQ(name, machineNameUtf8)) {
-
-PRUint32 state;
-
-matched = 1;
-
-machine-vtbl-GetId(machine, iid.value);
-vboxIIDToUUID(iid, uuid);
-vboxIIDUnalloc(iid);
-
-machine-vtbl-GetState(machine, state);
-
-/* get a new domain pointer from virGetDomain, if it fails
- * then no need to assign the id, else assign the id, cause
- * it is -1 by default. rest is taken care by virGetDomain
- * itself, so need not worry.
- */
-
-ret = virGetDomain(conn, machineNameUtf8, uuid);
-if (ret 
-(state = MachineState_FirstOnline) 
-(state = MachineState_LastOnline))
-ret-id = i + 1;
-}
-
-VBOX_UTF8_FREE(machineNameUtf8);
-  

[libvirt] [PATCH 12/66] vbox: Rewrite vboxConnectNumOfDomains

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   35 +++
 src/vbox/vbox_tmpl.c  |   36 
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 6de5757..3023fe6 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -516,3 +516,38 @@ int vboxConnectListDomains(virConnectPtr conn, int *ids, 
int nids)
 gVBoxAPI.UArray.vboxArrayRelease(machines);
 return ret;
 }
+
+int vboxConnectNumOfDomains(virConnectPtr conn)
+{
+VBOX_OBJECT_CHECK(conn, int, -1);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+PRUint32 state;
+nsresult rc;
+size_t i;
+
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get number of Domains, rc=%08x), 
(unsigned)rc);
+goto cleanup;
+}
+
+ret = 0;
+for (i = 0; i  machines.count; ++i) {
+IMachine *machine = machines.items[i];
+
+if (machine) {
+PRBool isAccessible = PR_FALSE;
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (isAccessible) {
+gVBoxAPI.UIMachine.GetState(machine, state);
+if (gVBoxAPI.machineStateChecker.Online(state))
+ret++;
+}
+}
+}
+
+ cleanup:
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index e0033b9..83ea370 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -920,42 +920,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxConnectNumOfDomains(virConnectPtr conn)
-{
-VBOX_OBJECT_CHECK(conn, int, -1);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-PRUint32 state;
-nsresult rc;
-size_t i;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get number of Domains, rc=%08x), 
(unsigned)rc);
-goto cleanup;
-}
-
-ret = 0;
-for (i = 0; i  machines.count; ++i) {
-IMachine *machine = machines.items[i];
-
-if (machine) {
-PRBool isAccessible = PR_FALSE;
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-if ((state = MachineState_FirstOnline) 
-(state = MachineState_LastOnline))
-ret++;
-}
-}
-}
-
- cleanup:
-vboxArrayRelease(machines);
-return ret;
-}
-
 static virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
 unsigned int flags)
 {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index b72429b..0b95459 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -256,6 +256,7 @@ int vboxConnectIsAlive(virConnectPtr conn);
 int vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type);
 char *vboxConnectGetCapabilities(virConnectPtr conn);
 int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids);
+int vboxConnectNumOfDomains(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 38/66] vbox: Rewrite vboxDomainGetMaxVcpus

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|6 ++
 src/vbox/vbox_tmpl.c  |7 ---
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 120ad6c..24d2ddb 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2854,3 +2854,9 @@ int vboxDomainGetVcpusFlags(virDomainPtr dom, unsigned 
int flags)
 
 return ret;
 }
+
+int vboxDomainGetMaxVcpus(virDomainPtr dom)
+{
+return vboxDomainGetVcpusFlags(dom, (VIR_DOMAIN_AFFECT_LIVE |
+ VIR_DOMAIN_VCPU_MAXIMUM));
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 50e4653..8abb9a7 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -954,13 +954,6 @@ static virDomainState _vboxConvertState(PRUint32 state)
 }
 }
 
-static int
-vboxDomainGetMaxVcpus(virDomainPtr dom)
-{
-return vboxDomainGetVcpusFlags(dom, (VIR_DOMAIN_AFFECT_LIVE |
- VIR_DOMAIN_VCPU_MAXIMUM));
-}
-
 static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr 
def, IMachine *machine)
 {
 #if VBOX_API_VERSION  4003000
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 5bab8fa..f67c109 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -442,6 +442,7 @@ int vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned int 
nvcpus,
 unsigned int flags);
 int vboxDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus);
 int vboxDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags);
+int vboxDomainGetMaxVcpus(virDomainPtr dom);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 34/66] vbox: Rewrite vboxDomainGetState

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   27 +++
 src/vbox/vbox_tmpl.c  |   36 
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 29 insertions(+), 36 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index d661110..1a4a4f5 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2748,3 +2748,30 @@ int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr 
info)
  cleanup:
 return ret;
 }
+
+int vboxDomainGetState(virDomainPtr dom, int *state,
+   int *reason, unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxIIDUnion domiid;
+IMachine *machine = NULL;
+PRUint32 mstate;
+
+virCheckFlags(0, -1);
+
+if (openSessionForMachine(data, dom-uuid, domiid, machine, false)  0)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, mstate);
+
+*state = gVBoxAPI.vboxConvertState(mstate);
+
+if (reason)
+*reason = 0;
+
+ret = 0;
+
+ cleanup:
+vboxIIDUnalloc(domiid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 3ae1864..33aa66a 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -955,42 +955,6 @@ static virDomainState _vboxConvertState(PRUint32 state)
 }
 
 static int
-vboxDomainGetState(virDomainPtr dom,
-   int *state,
-   int *reason,
-   unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxIID domiid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-PRUint32 mstate = MachineState_Null;
-nsresult rc;
-
-virCheckFlags(0, -1);
-
-vboxIIDFromUUID(domiid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(domiid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-machine-vtbl-GetState(machine, mstate);
-
-*state = _vboxConvertState(mstate);
-
-if (reason)
-*reason = 0;
-
-ret = 0;
-
- cleanup:
-vboxIIDUnalloc(domiid);
-return ret;
-}
-
-static int
 vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
 unsigned int flags)
 {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 897e10c..0f6c8ea 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -436,6 +436,8 @@ int vboxDomainDestroy(virDomainPtr dom);
 char *vboxDomainGetOSType(virDomainPtr dom);
 int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory);
 int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info);
+int vboxDomainGetState(virDomainPtr dom, int *state,
+   int *reason, unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 13/66] vbox: Rewrite vboxDomainLookupById

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   73 
 src/vbox/vbox_tmpl.c  |   82 +++--
 src/vbox/vbox_uniformed_api.h |3 ++
 3 files changed, 90 insertions(+), 68 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 3023fe6..d901b7f 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -551,3 +551,76 @@ int vboxConnectNumOfDomains(virConnectPtr conn)
 gVBoxAPI.UArray.vboxArrayRelease(machines);
 return ret;
 }
+
+virDomainPtr vboxDomainLookupByID(virConnectPtr conn, int id)
+{
+VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+IMachine *machine;
+PRBool isAccessible = PR_FALSE;
+PRUnichar *machineNameUtf16 = NULL;
+char *machineNameUtf8  = NULL;
+vboxIIDUnion iid;
+unsigned char uuid[VIR_UUID_BUFLEN];
+PRUint32 state;
+nsresult rc;
+
+VBOX_IID_INITIALIZE(iid);
+/* Internal vbox IDs start from 0, the public libvirt ID
+ * starts from 1, so refuse id == 0, and adjust the rest*/
+if (id == 0) {
+virReportError(VIR_ERR_NO_DOMAIN,
+   _(no domain with matching id %d), id);
+return NULL;
+}
+id = id - 1;
+
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
+return NULL;
+}
+
+if (id = machines.count)
+goto cleanup;
+
+machine = machines.items[id];
+
+if (!machine)
+goto cleanup;
+
+isAccessible = PR_FALSE;
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+if (!gVBoxAPI.machineStateChecker.Online(state))
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetName(machine, machineNameUtf16);
+VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
+
+gVBoxAPI.UIMachine.GetId(machine, iid);
+vboxIIDToUUID(iid, uuid);
+vboxIIDUnalloc(iid);
+
+/* get a new domain pointer from virGetDomain, if it fails
+ * then no need to assign the id, else assign the id, cause
+ * it is -1 by default. rest is taken care by virGetDomain
+ * itself, so need not worry.
+ */
+
+ret = virGetDomain(conn, machineNameUtf8, uuid);
+if (ret)
+ret-id = id + 1;
+
+/* Cleanup all the XPCOM allocated stuff here */
+VBOX_UTF8_FREE(machineNameUtf8);
+VBOX_UTF16_FREE(machineNameUtf16);
+
+ cleanup:
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 83ea370..9018589 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -948,74 +948,6 @@ static virDomainPtr vboxDomainCreateXML(virConnectPtr 
conn, const char *xml,
 return dom;
 }
 
-static virDomainPtr vboxDomainLookupByID(virConnectPtr conn, int id)
-{
-VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-vboxIID iid = VBOX_IID_INITIALIZER;
-unsigned char uuid[VIR_UUID_BUFLEN];
-PRUint32 state;
-nsresult rc;
-
-/* Internal vbox IDs start from 0, the public libvirt ID
- * starts from 1, so refuse id == 0, and adjust the rest*/
-if (id == 0) {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), id);
-return NULL;
-}
-id = id - 1;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
-return NULL;
-}
-
-if (id  machines.count) {
-IMachine *machine = machines.items[id];
-
-if (machine) {
-PRBool isAccessible = PR_FALSE;
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-if ((state = MachineState_FirstOnline) 
-(state = MachineState_LastOnline)) {
-PRUnichar *machineNameUtf16 = NULL;
-char  *machineNameUtf8  = NULL;
-
-machine-vtbl-GetName(machine, machineNameUtf16);
-VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
-
-machine-vtbl-GetId(machine, iid.value);
-vboxIIDToUUID(iid, uuid);
-vboxIIDUnalloc(iid);
-
-/* get a new domain pointer from virGetDomain, if it fails
- * then no need to assign the id, else assign the id, cause
- * it is -1 by default. rest is taken care by virGetDomain
- * itself, so need not worry.
-   

[libvirt] [PATCH 23/66] vbox: Rewrite vboxDomainIsUpdated

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   19 +++
 src/vbox/vbox_tmpl.c  |   25 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index d29539d..01d0104 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2343,3 +2343,22 @@ int vboxDomainIsPersistent(virDomainPtr dom)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainIsUpdated(virDomainPtr dom)
+{
+/* VBox domains never have a persistent state that differs from
+ * current state.  However, we do want to check for existence.  */
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+ret = 0;
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 1bec175..669a89d 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,31 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainIsUpdated(virDomainPtr dom ATTRIBUTE_UNUSED)
-{
-/* VBox domains never have a persistent state that differs from
- * current state.  However, we do want to check for existence.  */
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxIID iid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-nsresult rc;
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-ret = 0;
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static int vboxDomainSuspend(virDomainPtr dom)
 {
 VBOX_OBJECT_CHECK(dom-conn, int, -1);
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 72b29e2..1568948 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -413,6 +413,7 @@ virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const 
char *xml,
  unsigned int flags);
 int vboxDomainIsActive(virDomainPtr dom);
 int vboxDomainIsPersistent(virDomainPtr dom);
+int vboxDomainIsUpdated(virDomainPtr dom);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 14/66] vbox: Rewrite vboxDomainLookupByUUID

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   73 +
 src/vbox/vbox_tmpl.c  |   73 -
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 75 insertions(+), 73 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index d901b7f..5d9a4f0 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -624,3 +624,76 @@ virDomainPtr vboxDomainLookupByID(virConnectPtr conn, int 
id)
 gVBoxAPI.UArray.vboxArrayRelease(machines);
 return ret;
 }
+
+virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
+const unsigned char *uuid)
+{
+VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+vboxIIDUnion iid;
+char  *machineNameUtf8  = NULL;
+PRUnichar *machineNameUtf16 = NULL;
+unsigned char iid_as_uuid[VIR_UUID_BUFLEN];
+size_t i;
+int matched = 0;
+nsresult rc;
+
+VBOX_IID_INITIALIZE(iid);
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
+return NULL;
+}
+
+for (i = 0; i  machines.count; ++i) {
+IMachine *machine = machines.items[i];
+PRBool isAccessible = PR_FALSE;
+
+if (!machine)
+continue;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+continue;
+
+rc = gVBoxAPI.UIMachine.GetId(machine, iid);
+if (NS_FAILED(rc))
+continue;
+vboxIIDToUUID(iid, iid_as_uuid);
+vboxIIDUnalloc(iid);
+
+if (memcmp(uuid, iid_as_uuid, VIR_UUID_BUFLEN) == 0) {
+
+PRUint32 state;
+
+matched = 1;
+
+gVBoxAPI.UIMachine.GetName(machine, machineNameUtf16);
+VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+/* get a new domain pointer from virGetDomain, if it fails
+ * then no need to assign the id, else assign the id, cause
+ * it is -1 by default. rest is taken care by virGetDomain
+ * itself, so need not worry.
+ */
+
+ret = virGetDomain(conn, machineNameUtf8, iid_as_uuid);
+if (ret 
+gVBoxAPI.machineStateChecker.Online(state))
+ret-id = i + 1;
+ }
+
+ if (matched == 1)
+ break;
+}
+
+/* Do the cleanup and take care you dont leak any memory */
+VBOX_UTF8_FREE(machineNameUtf8);
+VBOX_COM_UNALLOC_MEM(machineNameUtf16);
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 9018589..0f33605 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -949,79 +949,6 @@ static virDomainPtr vboxDomainCreateXML(virConnectPtr 
conn, const char *xml,
 }
 
 static virDomainPtr
-vboxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
-{
-VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-vboxIID iid = VBOX_IID_INITIALIZER;
-char  *machineNameUtf8  = NULL;
-PRUnichar *machineNameUtf16 = NULL;
-unsigned char iid_as_uuid[VIR_UUID_BUFLEN];
-size_t i;
-int matched = 0;
-nsresult rc;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
-return NULL;
-}
-
-for (i = 0; i  machines.count; ++i) {
-IMachine *machine = machines.items[i];
-PRBool isAccessible = PR_FALSE;
-
-if (!machine)
-continue;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-
-rc = machine-vtbl-GetId(machine, iid.value);
-if (NS_FAILED(rc))
-continue;
-vboxIIDToUUID(iid, iid_as_uuid);
-vboxIIDUnalloc(iid);
-
-if (memcmp(uuid, iid_as_uuid, VIR_UUID_BUFLEN) == 0) {
-
-PRUint32 state;
-
-matched = 1;
-
-machine-vtbl-GetName(machine, machineNameUtf16);
-VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
-
-machine-vtbl-GetState(machine, state);
-
-/* get a new domain pointer from virGetDomain, if it fails
- * then no need to assign the id, else assign the id, cause
- * it is -1 by default. rest is taken care by virGetDomain
- * itself, so need not worry.
- */
-
-ret = virGetDomain(conn, machineNameUtf8, iid_as_uuid);
-if 

[libvirt] [PATCH 26/66] vbox: Rewrite vboxDomainShutdownFlags

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   48 +
 src/vbox/vbox_tmpl.c  |   67 -
 src/vbox/vbox_uniformed_api.h |3 ++
 3 files changed, 64 insertions(+), 54 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 6b8a9e7..6371eb2 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2456,3 +2456,51 @@ int vboxDomainResume(virDomainPtr dom)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainShutdownFlags(virDomainPtr dom, unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+IConsole *console= NULL;
+PRUint32 state;
+PRBool isAccessible  = PR_FALSE;
+
+virCheckFlags(0, -1);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!machine)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.Paused(state)) {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(machine paused, so can't power it down));
+goto cleanup;
+} else if (gVBoxAPI.machineStateChecker.PoweredOff(state)) {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(machine already powered down));
+goto cleanup;
+}
+
+gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+gVBoxAPI.UISession.GetConsole(data-vboxSession, console);
+if (console) {
+gVBoxAPI.UIConsole.PowerButton(console);
+VBOX_RELEASE(console);
+ret = 0;
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 95c38d4..3a25185 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,60 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainShutdownFlags(virDomainPtr dom,
-   unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-IConsole *console= NULL;
-PRUint32 state   = MachineState_Null;
-PRBool isAccessible  = PR_FALSE;
-nsresult rc;
-
-virCheckFlags(0, -1);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), dom-id);
-goto cleanup;
-}
-
-if (!machine)
-goto cleanup;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-
-if (state == MachineState_Paused) {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(machine paused, so can't power it down));
-goto cleanup;
-} else if (state == MachineState_PoweredOff) {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(machine already powered down));
-goto cleanup;
-}
-
-VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
-data-vboxSession-vtbl-GetConsole(data-vboxSession, console);
-if (console) {
-console-vtbl-PowerButton(console);
-VBOX_RELEASE(console);
-ret = 0;
-}
-VBOX_SESSION_CLOSE();
-}
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static int vboxDomainShutdown(virDomainPtr dom)
 {
 return vboxDomainShutdownFlags(dom, 0);
@@ -9952,6 +9898,12 @@ _consoleResume(IConsole *console)
 }
 
 static nsresult
+_consolePowerButton(IConsole *console)
+{
+return console-vtbl-PowerButton(console);
+}
+
+static nsresult
 _progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
 {
 return progress-vtbl-WaitForCompletion(progress, timeout);
@@ -10389,6 +10341,11 @@ static bool _machineStatePaused(PRUint32 state)
 return state == MachineState_Paused;
 }
 
+static bool _machineStatePoweredOff(PRUint32 state)
+{
+return state == MachineState_PoweredOff;
+}
+
 static vboxUniformedPFN _UPFN = {
 .Initialize = _pfnInitialize,
 .Uninitialize = _pfnUninitialize,
@@ -10471,6 +10428,7 @@ static vboxUniformedIConsole _UIConsole = {
 .SaveState = _consoleSaveState,
 .Pause = _consolePause,
 .Resume = _consoleResume,
+.PowerButton = _consolePowerButton,
 };
 
 static vboxUniformedIProgress _UIProgress = {
@@ -10558,6 +10516,7 @@ static uniformedMachineStateChecker 
_machineStateChecker = {
 .NotStart = _machineStateNotStart,
 .Running = _machineStateRunning,
 .Paused = 

[libvirt] [PATCH 29/66] vbox: Rewrite vboxDomainDestroyFlags

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   45 +++
 src/vbox/vbox_tmpl.c  |   80 ++---
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 65 insertions(+), 62 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 0527fea..aaebc44 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2553,3 +2553,48 @@ int vboxDomainReboot(virDomainPtr dom, unsigned int 
flags)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+IConsole *console= NULL;
+PRUint32 state;
+PRBool isAccessible  = PR_FALSE;
+
+virCheckFlags(0, -1);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!machine)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.PoweredOff(state)) {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(machine already powered down));
+goto cleanup;
+}
+
+gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+gVBoxAPI.UISession.GetConsole(data-vboxSession, console);
+if (console) {
+gVBoxAPI.UIConsole.PowerDown(console);
+VBOX_RELEASE(console);
+dom-id = -1;
+ret = 0;
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index ef734c9..c3f14be 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -933,68 +933,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 }
 
 static int
-vboxDomainDestroyFlags(virDomainPtr dom,
-   unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-IConsole *console= NULL;
-PRUint32 state   = MachineState_Null;
-PRBool isAccessible  = PR_FALSE;
-nsresult rc;
-
-virCheckFlags(0, -1);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), dom-id);
-goto cleanup;
-}
-
-if (!machine)
-goto cleanup;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-
-if (state == MachineState_PoweredOff) {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(machine already powered down));
-goto cleanup;
-}
-
-VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
-data-vboxSession-vtbl-GetConsole(data-vboxSession, console);
-if (console) {
-
-#if VBOX_API_VERSION == 2002000
-console-vtbl-PowerDown(console);
-#else
-IProgress *progress = NULL;
-console-vtbl-PowerDown(console, progress);
-if (progress) {
-progress-vtbl-WaitForCompletion(progress, -1);
-VBOX_RELEASE(progress);
-}
-#endif
-VBOX_RELEASE(console);
-dom-id = -1;
-ret = 0;
-}
-VBOX_SESSION_CLOSE();
-}
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
-static int
 vboxDomainDestroy(virDomainPtr dom)
 {
 return vboxDomainDestroyFlags(dom, 0);
@@ -9849,6 +9787,23 @@ _consolePowerButton(IConsole *console)
 }
 
 static nsresult
+_consolePowerDown(IConsole *console)
+{
+nsresult rc;
+#if VBOX_API_VERSION == 2002000
+rc = console-vtbl-PowerDown(console);
+#else
+IProgress *progress = NULL;
+rc = console-vtbl-PowerDown(console, progress);
+if (progress) {
+rc = progress-vtbl-WaitForCompletion(progress, -1);
+VBOX_RELEASE(progress);
+}
+#endif
+return rc;
+}
+
+static nsresult
 _consoleReset(IConsole *console)
 {
 return console-vtbl-Reset(console);
@@ -10380,6 +10335,7 @@ static vboxUniformedIConsole _UIConsole = {
 .Pause = _consolePause,
 .Resume = _consoleResume,
 .PowerButton = _consolePowerButton,
+.PowerDown = _consolePowerDown,
 .Reset = _consoleReset,
 };
 
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index d5c6fb4..b9c2068 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -240,6 +240,7 @@ typedef struct {
 nsresult (*Pause)(IConsole *console);
 nsresult (*Resume)(IConsole *console);
 nsresult (*PowerButton)(IConsole *console);
+nsresult (*PowerDown)(IConsole 

[libvirt] [PATCH 15/66] vbox: Rewrite vboxDomainUndefineFlags

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   70 
 src/vbox/vbox_tmpl.c  |  356 +
 src/vbox/vbox_uniformed_api.h |8 +
 3 files changed, 258 insertions(+), 176 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 5d9a4f0..efcda7a 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -27,6 +27,7 @@
 #include virlog.h
 #include viralloc.h
 #include nodeinfo.h
+#include virstring.h
 
 #include vbox_common.h
 #include vbox_uniformed_api.h
@@ -697,3 +698,72 @@ virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
 
 return ret;
 }
+
+static void
+detachDevices_common(vboxGlobalData *data, vboxIIDUnion *iidu)
+{
+/* Block for checking if HDD's are attched to VM.
+ * considering just IDE bus for now. Also skipped
+ * chanel=1 and device=0 (Secondary Master) as currenlty
+ * it is allocated to CD/DVD Drive by default.
+ *
+ * Only do this for VirtualBox 3.x and before. Since
+ * VirtualBox 4.0 the Unregister method can do this for use.
+ */
+IMachine *machine = NULL;
+PRUnichar *hddcnameUtf16 = NULL;
+nsresult rc;
+char *hddcname;
+
+if (!gVBoxAPI.detachDevicesExplicitly)
+VIR_WARN(This function may not work in current vbox version);
+
+ignore_value(VIR_STRDUP(hddcname, IDE));
+VBOX_UTF8_TO_UTF16(hddcname, hddcnameUtf16);
+VIR_FREE(hddcname);
+
+/* Open a Session for the machine */
+rc = gVBoxAPI.UISession.Open(data, iidu, machine);
+if (NS_SUCCEEDED(rc)) {
+rc = gVBoxAPI.UISession.GetMachine(data-vboxSession, machine);
+if (NS_SUCCEEDED(rc)  machine) {
+gVBoxAPI.detachDevices(data, machine, hddcnameUtf16);
+gVBoxAPI.UIMachine.SaveSettings(machine);
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+}
+VBOX_UTF16_FREE(hddcnameUtf16);
+}
+
+int vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+nsresult rc;
+
+gVBoxAPI.UIID.vboxIIDInitialize(iid);
+/* No managed save, so we explicitly reject
+ * VIR_DOMAIN_UNDEFINE_MANAGED_SAVE.  No snapshot metadata for
+ * VBox, so we can trivially ignore that flag.  */
+virCheckFlags(VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1);
+vboxIIDFromUUID(iid, dom-uuid);
+if (gVBoxAPI.detachDevicesExplicitly)
+detachDevices_common(data, iid);
+rc = gVBoxAPI.unregisterMachine(data, iid, machine);
+
+DEBUGIID(UUID of machine being undefined, iid);
+
+if (NS_SUCCEEDED(rc)) {
+gVBoxAPI.deleteConfig(machine);
+ret = 0;
+} else {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not delete the domain, rc=%08x), 
(unsigned)rc);
+}
+
+vboxIIDUnalloc(iid);
+VBOX_RELEASE(machine);
+
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 0f33605..86c02f1 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -254,7 +254,6 @@ static vboxGlobalData *g_pVBoxGlobalData = NULL;
 
 static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml);
 static int vboxDomainCreate(virDomainPtr dom);
-static int vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags);
 
 #if VBOX_API_VERSION  2002000  VBOX_API_VERSION  400
 /* Since vboxConnectGetCapabilities has been rewriten,
@@ -4784,181 +4783,6 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr 
conn, const char *xml)
 }
 
 static int
-vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-nsresult rc;
-#if VBOX_API_VERSION = 400
-vboxArray media = VBOX_ARRAY_INITIALIZER;
-#endif
-/* No managed save, so we explicitly reject
- * VIR_DOMAIN_UNDEFINE_MANAGED_SAVE.  No snapshot metadata for
- * VBox, so we can trivially ignore that flag.  */
-virCheckFlags(VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1);
-
-vboxIIDFromUUID(iid, dom-uuid);
-
-#if VBOX_API_VERSION  400
-/* Block for checking if HDD's are attched to VM.
- * considering just IDE bus for now. Also skipped
- * chanel=1 and device=0 (Secondary Master) as currenlty
- * it is allocated to CD/DVD Drive by default.
- *
- * Only do this for VirtualBox 3.x and before. Since
- * VirtualBox 4.0 the Unregister method can do this for use.
- */
-{
-PRUnichar *hddcnameUtf16 = NULL;
-
-char *hddcname;
-ignore_value(VIR_STRDUP(hddcname, IDE));
-VBOX_UTF8_TO_UTF16(hddcname, hddcnameUtf16);
-VIR_FREE(hddcname);
-
-/* Open a Session for the machine */
-rc = VBOX_SESSION_OPEN(iid.value, machine);
-if (NS_SUCCEEDED(rc)) {
-rc = data-vboxSession-vtbl-GetMachine(data-vboxSession, 
machine);
-if (NS_SUCCEEDED(rc)  

[libvirt] [PATCH 40/66] vbox: Rewrite vboxDomainGetXMLDesc

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c| 1076 ++-
 src/vbox/vbox_common.h|9 +
 src/vbox/vbox_tmpl.c  | 1261 +
 src/vbox/vbox_uniformed_api.h |1 +
 4 files changed, 1094 insertions(+), 1253 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 24d2ddb..fa9c0b0 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -109,7 +109,6 @@ if (!data-vboxObj) {\
 #define ARRAY_GET_MACHINES \
 (gVBoxAPI.UArray.handleGetMachines(data-vboxObj))
 
-
 /* global vbox API, used for all common codes. */
 static vboxUniformedAPI gVBoxAPI;
 
@@ -277,6 +276,66 @@ static bool vboxGetDeviceDetails(const char *deviceName,
 return true;
 }
 
+/**
+ * function to generate the name for medium,
+ * for e.g: hda, sda, etc
+ *
+ * @returns null terminated string with device name or NULL
+ *  for failures
+ * @param   connInput Connection Pointer
+ * @param   storageBus  Input storage bus type
+ * @param   deviceInst  Input device instance number
+ * @param   devicePort  Input port number
+ * @param   deviceSlot  Input slot number
+ * @param   aMaxPortPerInst Input array of max port per device instance
+ * @param   aMaxSlotPerPort Input array of max slot per device port
+ *
+ */
+static char *vboxGenerateMediumName(PRUint32  storageBus,
+PRInt32   deviceInst,
+PRInt32   devicePort,
+PRInt32   deviceSlot,
+PRUint32 *aMaxPortPerInst,
+PRUint32 *aMaxSlotPerPort)
+{
+const char *prefix = NULL;
+char *name  = NULL;
+int   total = 0;
+PRUint32 maxPortPerInst = 0;
+PRUint32 maxSlotPerPort = 0;
+
+if (!aMaxPortPerInst ||
+!aMaxSlotPerPort)
+return NULL;
+
+if ((storageBus  StorageBus_IDE) ||
+(storageBus  StorageBus_Floppy))
+return NULL;
+
+maxPortPerInst = aMaxPortPerInst[storageBus];
+maxSlotPerPort = aMaxSlotPerPort[storageBus];
+total =   (deviceInst * maxPortPerInst * maxSlotPerPort)
++ (devicePort * maxSlotPerPort)
++ deviceSlot;
+
+if (storageBus == StorageBus_IDE) {
+prefix = hd;
+} else if ((storageBus == StorageBus_SATA) ||
+   (storageBus == StorageBus_SCSI)) {
+prefix = sd;
+} else if (storageBus == StorageBus_Floppy) {
+prefix = fd;
+}
+
+name = virIndexToDiskName(total, prefix);
+
+VIR_DEBUG(name=%s, total=%d, storageBus=%u, deviceInst=%d, 
+  devicePort=%d deviceSlot=%d, maxPortPerInst=%u maxSlotPerPort=%u,
+  NULLSTR(name), total, storageBus, deviceInst, devicePort,
+  deviceSlot, maxPortPerInst, maxSlotPerPort);
+return name;
+}
+
 static virDomainDefParserConfig vboxDomainDefParserConfig = {
 .macPrefix = { 0x08, 0x00, 0x27 },
 };
@@ -2860,3 +2919,1018 @@ int vboxDomainGetMaxVcpus(virDomainPtr dom)
 return vboxDomainGetVcpusFlags(dom, (VIR_DOMAIN_AFFECT_LIVE |
  VIR_DOMAIN_VCPU_MAXIMUM));
 }
+
+static void
+vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr def, IMachine 
*machine)
+{
+IUSBCommon *USBCommon = NULL;
+PRBool enabled = PR_FALSE;
+vboxArray deviceFilters = VBOX_ARRAY_INITIALIZER;
+size_t i;
+PRUint32 USBFilterCount = 0;
+
+def-nhostdevs = 0;
+
+gVBoxAPI.UIMachine.GetUSBCommon(machine, USBCommon);
+if (!USBCommon)
+return;
+
+gVBoxAPI.UIUSBCommon.GetEnabled(USBCommon, enabled);
+if (!enabled)
+goto release_controller;
+
+gVBoxAPI.UArray.vboxArrayGet(deviceFilters, USBCommon,
+ 
gVBoxAPI.UArray.handleUSBGetDeviceFilters(USBCommon));
+
+if (deviceFilters.count = 0)
+goto release_filters;
+
+/* check if the filters are active and then only
+ * alloc mem and set def-nhostdevs
+ */
+
+for (i = 0; i  deviceFilters.count; i++) {
+PRBool active = PR_FALSE;
+IUSBDeviceFilter *deviceFilter = deviceFilters.items[i];
+
+gVBoxAPI.UIUSBDeviceFilter.GetActive(deviceFilter, active);
+if (active) {
+def-nhostdevs++;
+}
+}
+
+if (def-nhostdevs == 0)
+goto release_filters;
+
+/* Alloc mem needed for the filters now */
+if (VIR_ALLOC_N(def-hostdevs, def-nhostdevs)  0)
+goto release_filters;
+
+for (i = 0; i  def-nhostdevs; i++) {
+def-hostdevs[i] = virDomainHostdevDefAlloc();
+if (!def-hostdevs[i])
+goto release_hostdevs;
+}
+
+for (i = 0; i  deviceFilters.count; i++) {
+PRBool active  = PR_FALSE;
+IUSBDeviceFilter *deviceFilter = deviceFilters.items[i];
+PRUnichar *vendorIdUtf16   = NULL;
+char *vendorIdUtf8

[libvirt] [PATCH 43/66] vbox: Rewrite vboxDomainUndefine

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|5 +
 src/vbox/vbox_tmpl.c  |6 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index cd9fede..5b0706f 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2066,6 +2066,11 @@ int vboxDomainUndefineFlags(virDomainPtr dom, unsigned 
int flags)
 return ret;
 }
 
+int vboxDomainUndefine(virDomainPtr dom)
+{
+return vboxDomainUndefineFlags(dom, 0);
+}
+
 static int
 vboxStartMachine(virDomainPtr dom, int maxDomID, IMachine *machine, 
vboxIIDUnion *iid)
 {
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 239ee67..3651498 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1450,12 +1450,6 @@ _vboxAttachDrivesOld(virDomainDefPtr def 
ATTRIBUTE_UNUSED,
 
 #endif /* VBOX_API_VERSION = 400 */
 
-static int
-vboxDomainUndefine(virDomainPtr dom)
-{
-return vboxDomainUndefineFlags(dom, 0);
-}
-
 static int vboxDomainAttachDeviceImpl(virDomainPtr dom,
   const char *xml,
   int mediaChangeOnly ATTRIBUTE_UNUSED)
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index f57eaa9..9488999 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -493,6 +493,7 @@ virDomainPtr
 vboxDomainLookupByName(virConnectPtr conn, const char *name);
 virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml);
 int vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags);
+int vboxDomainUndefine(virDomainPtr dom);
 int vboxDomainCreateWithFlags(virDomainPtr dom, unsigned int flags);
 int vboxDomainCreate(virDomainPtr dom);
 virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 21/66] vbox: Rewrite vboxDomainIsActive

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   66 
 src/vbox/vbox_tmpl.c  |   67 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 67 insertions(+), 67 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index fbb90ac..89095f5 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2258,3 +2258,69 @@ virDomainPtr vboxDomainCreateXML(virConnectPtr conn, 
const char *xml,
 
 return dom;
 }
+
+int vboxDomainIsActive(virDomainPtr dom)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+vboxIIDUnion iid;
+char  *machineNameUtf8  = NULL;
+PRUnichar *machineNameUtf16 = NULL;
+unsigned char uuid[VIR_UUID_BUFLEN];
+size_t i;
+int matched = 0;
+nsresult rc;
+
+VBOX_IID_INITIALIZE(iid);
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
+return ret;
+}
+
+for (i = 0; i  machines.count; ++i) {
+IMachine *machine = machines.items[i];
+PRBool isAccessible = PR_FALSE;
+
+if (!machine)
+continue;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+continue;
+
+gVBoxAPI.UIMachine.GetId(machine, iid);
+if (NS_FAILED(rc))
+continue;
+vboxIIDToUUID(iid, uuid);
+vboxIIDUnalloc(iid);
+
+if (memcmp(dom-uuid, uuid, VIR_UUID_BUFLEN) == 0) {
+
+PRUint32 state;
+
+matched = 1;
+
+gVBoxAPI.UIMachine.GetName(machine, machineNameUtf16);
+VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.Online(state))
+ret = 1;
+else
+ret = 0;
+}
+
+if (matched == 1)
+break;
+}
+
+/* Do the cleanup and take care you dont leak any memory */
+VBOX_UTF8_FREE(machineNameUtf8);
+VBOX_COM_UNALLOC_MEM(machineNameUtf16);
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 7bb6896..2971af2 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,73 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainIsActive(virDomainPtr dom)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-vboxIID iid = VBOX_IID_INITIALIZER;
-char  *machineNameUtf8  = NULL;
-PRUnichar *machineNameUtf16 = NULL;
-unsigned char uuid[VIR_UUID_BUFLEN];
-size_t i;
-int matched = 0;
-nsresult rc;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
-return ret;
-}
-
-for (i = 0; i  machines.count; ++i) {
-IMachine *machine = machines.items[i];
-PRBool isAccessible = PR_FALSE;
-
-if (!machine)
-continue;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-
-rc = machine-vtbl-GetId(machine, iid.value);
-if (NS_FAILED(rc))
-continue;
-vboxIIDToUUID(iid, uuid);
-vboxIIDUnalloc(iid);
-
-if (memcmp(dom-uuid, uuid, VIR_UUID_BUFLEN) == 0) {
-
-PRUint32 state;
-
-matched = 1;
-
-machine-vtbl-GetName(machine, machineNameUtf16);
-VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
-
-machine-vtbl-GetState(machine, state);
-
-if ((state = MachineState_FirstOnline) 
-(state = MachineState_LastOnline))
-ret = 1;
-else
-ret = 0;
-}
-
-if (matched == 1)
-break;
-}
-}
-
-/* Do the cleanup and take care you dont leak any memory */
-VBOX_UTF8_FREE(machineNameUtf8);
-VBOX_COM_UNALLOC_MEM(machineNameUtf16);
-vboxArrayRelease(machines);
-
-return ret;
-}
-
-
 static int vboxDomainIsPersistent(virDomainPtr dom ATTRIBUTE_UNUSED)
 {
 /* All domains are persistent.  However, we do want to check for
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 41b2d90..6fc97ed 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -411,6 +411,7 @@ int vboxDomainCreateWithFlags(virDomainPtr dom, unsigned 
int flags);
 int 

[libvirt] [PATCH 37/66] vbox: Rewrite vboxDomainGetVcpusFlags

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   28 
 src/vbox/vbox_tmpl.c  |   29 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 1df946d..120ad6c 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2826,3 +2826,31 @@ int vboxDomainSetVcpus(virDomainPtr dom, unsigned int 
nvcpus)
 {
 return vboxDomainSetVcpusFlags(dom, nvcpus, VIR_DOMAIN_AFFECT_LIVE);
 }
+
+int vboxDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+ISystemProperties *systemProperties = NULL;
+PRUint32 maxCPUCount = 0;
+
+if (flags != (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_VCPU_MAXIMUM)) {
+virReportError(VIR_ERR_INVALID_ARG, _(unsupported flags: (0x%x)), 
flags);
+return -1;
+}
+
+/* Currently every domain supports the same number of max cpus
+ * as that supported by vbox and thus take it directly from
+ * the systemproperties.
+ */
+
+gVBoxAPI.UIVirtualBox.GetSystemProperties(data-vboxObj, 
systemProperties);
+if (systemProperties) {
+gVBoxAPI.UISystemProperties.GetMaxGuestCPUCount(systemProperties, 
maxCPUCount);
+VBOX_RELEASE(systemProperties);
+}
+
+if (maxCPUCount  0)
+ret = maxCPUCount;
+
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index db16092..50e4653 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -955,35 +955,6 @@ static virDomainState _vboxConvertState(PRUint32 state)
 }
 
 static int
-vboxDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-ISystemProperties *systemProperties = NULL;
-PRUint32 maxCPUCount = 0;
-
-if (flags != (VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_VCPU_MAXIMUM)) {
-virReportError(VIR_ERR_INVALID_ARG, _(unsupported flags: (0x%x)), 
flags);
-return -1;
-}
-
-/* Currently every domain supports the same number of max cpus
- * as that supported by vbox and thus take it directly from
- * the systemproperties.
- */
-
-data-vboxObj-vtbl-GetSystemProperties(data-vboxObj, systemProperties);
-if (systemProperties) {
-systemProperties-vtbl-GetMaxGuestCPUCount(systemProperties, 
maxCPUCount);
-VBOX_RELEASE(systemProperties);
-}
-
-if (maxCPUCount  0)
-ret = maxCPUCount;
-
-return ret;
-}
-
-static int
 vboxDomainGetMaxVcpus(virDomainPtr dom)
 {
 return vboxDomainGetVcpusFlags(dom, (VIR_DOMAIN_AFFECT_LIVE |
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index cb04501..5bab8fa 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -441,6 +441,7 @@ int vboxDomainGetState(virDomainPtr dom, int *state,
 int vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
 unsigned int flags);
 int vboxDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus);
+int vboxDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 45/66] vbox: Rewrite vboxDomainAttachDeviceFlags

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   14 ++
 src/vbox/vbox_tmpl.c  |   15 ---
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 84d82d7..f22cb5b 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -4155,3 +4155,17 @@ int vboxDomainAttachDevice(virDomainPtr dom, const char 
*xml)
 {
 return vboxDomainAttachDeviceImpl(dom, xml, 0);
 }
+
+int vboxDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
+unsigned int flags)
+{
+virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+if (flags  VIR_DOMAIN_AFFECT_CONFIG) {
+virReportError(VIR_ERR_OPERATION_INVALID, %s,
+   _(cannot modify the persistent configuration of a 
domain));
+return -1;
+}
+
+return vboxDomainAttachDeviceImpl(dom, xml, 0);
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index b80810d..5078f27 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1649,21 +1649,6 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom,
 return ret;
 }
 
-static int
-vboxDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
-unsigned int flags)
-{
-virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
-
-if (flags  VIR_DOMAIN_AFFECT_CONFIG) {
-virReportError(VIR_ERR_OPERATION_INVALID, %s,
-   _(cannot modify the persistent configuration of a 
domain));
-return -1;
-}
-
-return vboxDomainAttachDeviceImpl(dom, xml, 0);
-}
-
 static int vboxDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags)
 {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 1f82616..69090f3 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -525,6 +525,8 @@ int vboxConnectListDefinedDomains(virConnectPtr conn,
   char ** const names, int maxnames);
 int vboxConnectNumOfDefinedDomains(virConnectPtr conn);
 int vboxDomainAttachDevice(virDomainPtr dom, const char *xml);
+int vboxDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
+unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 36/66] vbox: Rewrite vboxDomainSetVcpus

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|5 +
 src/vbox/vbox_tmpl.c  |6 --
 src/vbox/vbox_uniformed_api.h |2 +-
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 4aadd01..1df946d 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2821,3 +2821,8 @@ int vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned 
int nvcpus,
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
+{
+return vboxDomainSetVcpusFlags(dom, nvcpus, VIR_DOMAIN_AFFECT_LIVE);
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index c8cc951..db16092 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -955,12 +955,6 @@ static virDomainState _vboxConvertState(PRUint32 state)
 }
 
 static int
-vboxDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
-{
-return vboxDomainSetVcpusFlags(dom, nvcpus, VIR_DOMAIN_AFFECT_LIVE);
-}
-
-static int
 vboxDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
 {
 VBOX_OBJECT_CHECK(dom-conn, int, -1);
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 84a8a37..cb04501 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -440,7 +440,7 @@ int vboxDomainGetState(virDomainPtr dom, int *state,
int *reason, unsigned int flags);
 int vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
 unsigned int flags);
-
+int vboxDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 41/66] vbox: Rewrite vboxConnectListDefinedDomains

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   59 +++
 src/vbox/vbox_tmpl.c  |   61 +
 src/vbox/vbox_uniformed_api.h |3 ++
 3 files changed, 69 insertions(+), 54 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index fa9c0b0..fcde620 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -3934,3 +3934,62 @@ char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned 
int flags)
 virDomainDefFree(def);
 return ret;
 }
+
+int vboxConnectListDefinedDomains(virConnectPtr conn,
+  char ** const names, int maxnames)
+{
+VBOX_OBJECT_CHECK(conn, int, -1);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+char *machineName= NULL;
+PRUnichar *machineNameUtf16 = NULL;
+PRUint32 state;
+nsresult rc;
+size_t i, j;
+
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj,
+  ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of Defined Domains, rc=%08x),
+   (unsigned)rc);
+goto cleanup;
+}
+
+memset(names, 0, sizeof(names[i]) * maxnames);
+
+ret = 0;
+for (i = 0, j = 0; (i  machines.count)  (j  maxnames); i++) {
+PRBool isAccessible = PR_FALSE;
+IMachine *machine = machines.items[i];
+
+if (!machine)
+continue;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+continue;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+if (!gVBoxAPI.machineStateChecker.Inactive(state))
+continue;
+
+gVBoxAPI.UIMachine.GetName(machine, machineNameUtf16);
+VBOX_UTF16_TO_UTF8(machineNameUtf16, machineName);
+if (VIR_STRDUP(names[j], machineName)  0) {
+VBOX_UTF16_FREE(machineNameUtf16);
+VBOX_UTF8_FREE(machineName);
+for (j = 0; j  maxnames; j++)
+VIR_FREE(names[j]);
+ret = -1;
+goto cleanup;
+}
+VBOX_UTF16_FREE(machineNameUtf16);
+VBOX_UTF8_FREE(machineName);
+j++;
+ret++;
+}
+
+ cleanup:
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index f017840..7479f23 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -966,60 +966,6 @@ static virDomainState _vboxConvertState(PRUint32 state)
 }
 }
 
-static int vboxConnectListDefinedDomains(virConnectPtr conn, char ** const 
names, int maxnames) {
-VBOX_OBJECT_CHECK(conn, int, -1);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-char *machineName= NULL;
-PRUnichar *machineNameUtf16 = NULL;
-PRUint32 state;
-nsresult rc;
-size_t i, j;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get list of Defined Domains, rc=%08x),
-   (unsigned)rc);
-goto cleanup;
-}
-
-memset(names, 0, sizeof(names[i]) * maxnames);
-
-ret = 0;
-for (i = 0, j = 0; (i  machines.count)  (j  maxnames); i++) {
-IMachine *machine = machines.items[i];
-
-if (machine) {
-PRBool isAccessible = PR_FALSE;
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-if ((state  MachineState_FirstOnline) ||
-(state  MachineState_LastOnline)) {
-machine-vtbl-GetName(machine, machineNameUtf16);
-VBOX_UTF16_TO_UTF8(machineNameUtf16, machineName);
-if (VIR_STRDUP(names[j], machineName)  0) {
-VBOX_UTF16_FREE(machineNameUtf16);
-VBOX_UTF8_FREE(machineName);
-for (j = 0; j  maxnames; j++)
-VIR_FREE(names[j]);
-ret = -1;
-goto cleanup;
-}
-VBOX_UTF16_FREE(machineNameUtf16);
-VBOX_UTF8_FREE(machineName);
-j++;
-ret++;
-}
-}
-}
-}
-
- cleanup:
-vboxArrayRelease(machines);
-return ret;
-}
-
 static int vboxConnectNumOfDefinedDomains(virConnectPtr conn)
 {
 VBOX_OBJECT_CHECK(conn, int, -1);
@@ -9368,6 +9314,12 @@ static bool _machineStateOnline(PRUint32 state)
 (state = MachineState_LastOnline));
 }
 
+static bool _machineStateInactive(PRUint32 state)
+{
+return ((state  MachineState_FirstOnline) 
+(state  MachineState_LastOnline));
+}
+
 static bool _machineStateNotStart(PRUint32 state)
 {

[libvirt] [PATCH 24/66] vbox: Rewrite vboxDomainSuspend

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   47 +
 src/vbox/vbox_tmpl.c  |   65 +
 src/vbox/vbox_uniformed_api.h |3 ++
 3 files changed, 63 insertions(+), 52 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 01d0104..d796be7 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2362,3 +2362,50 @@ int vboxDomainIsUpdated(virDomainPtr dom)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainSuspend(virDomainPtr dom)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+IConsole *console= NULL;
+PRBool isAccessible  = PR_FALSE;
+PRUint32 state;
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!machine)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.Running(state)) {
+/* set state pause */
+gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+gVBoxAPI.UISession.GetConsole(data-vboxSession, console);
+if (console) {
+gVBoxAPI.UIConsole.Pause(console);
+VBOX_RELEASE(console);
+ret = 0;
+} else {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(error while suspending the domain));
+goto cleanup;
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+} else {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(machine not in running state to suspend it));
+goto cleanup;
+}
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 669a89d..df7c290 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,58 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainSuspend(virDomainPtr dom)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-IConsole *console= NULL;
-PRBool isAccessible  = PR_FALSE;
-PRUint32 state;
-nsresult rc;
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), dom-id);
-goto cleanup;
-}
-
-if (!machine)
-goto cleanup;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-
-if (state == MachineState_Running) {
-/* set state pause */
-VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
-data-vboxSession-vtbl-GetConsole(data-vboxSession, console);
-if (console) {
-console-vtbl-Pause(console);
-VBOX_RELEASE(console);
-ret = 0;
-} else {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(error while suspending the domain));
-goto cleanup;
-}
-VBOX_SESSION_CLOSE();
-} else {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(machine not in running state to suspend it));
-goto cleanup;
-}
-}
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static int vboxDomainResume(virDomainPtr dom)
 {
 VBOX_OBJECT_CHECK(dom-conn, int, -1);
@@ -10045,6 +9993,12 @@ _consoleSaveState(IConsole *console, IProgress 
**progress)
 }
 
 static nsresult
+_consolePause(IConsole *console)
+{
+return console-vtbl-Pause(console);
+}
+
+static nsresult
 _progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
 {
 return progress-vtbl-WaitForCompletion(progress, timeout);
@@ -10472,6 +10426,11 @@ static bool _machineStateNotStart(PRUint32 state)
 (state == MachineState_Aborted));
 }
 
+static bool _machineStateRunning(PRUint32 state)
+{
+return state == MachineState_Running;
+}
+
 static vboxUniformedPFN _UPFN = {
 .Initialize = _pfnInitialize,
 .Uninitialize = _pfnUninitialize,
@@ -10552,6 +10511,7 @@ static vboxUniformedISession _UISession = {
 
 static vboxUniformedIConsole _UIConsole = {
 .SaveState = _consoleSaveState,
+.Pause = _consolePause,
 };
 
 static vboxUniformedIProgress _UIProgress = {
@@ -10637,6 +10597,7 @@ static vboxUniformedIMedium _UIMedium = {
 static uniformedMachineStateChecker _machineStateChecker = {
 .Online = _machineStateOnline,
 .NotStart = _machineStateNotStart,
+.Running = _machineStateRunning,
 };
 
 void 

[libvirt] [PATCH 22/66] vbox: Rewrite vboxDomainIsPersistent

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   19 +++
 src/vbox/vbox_tmpl.c  |   26 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 89095f5..d29539d 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2324,3 +2324,22 @@ int vboxDomainIsActive(virDomainPtr dom)
 
 return ret;
 }
+
+int vboxDomainIsPersistent(virDomainPtr dom)
+{
+/* All domains are persistent.  However, we do want to check for
+ * existence. */
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+ret = 1;
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 2971af2..1bec175 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,32 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainIsPersistent(virDomainPtr dom ATTRIBUTE_UNUSED)
-{
-/* All domains are persistent.  However, we do want to check for
- * existence. */
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxIID iid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-nsresult rc;
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-ret = 1;
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
-
 static int vboxDomainIsUpdated(virDomainPtr dom ATTRIBUTE_UNUSED)
 {
 /* VBox domains never have a persistent state that differs from
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 6fc97ed..72b29e2 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -412,6 +412,7 @@ int vboxDomainCreate(virDomainPtr dom);
 virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
  unsigned int flags);
 int vboxDomainIsActive(virDomainPtr dom);
+int vboxDomainIsPersistent(virDomainPtr dom);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 52/66] vbox: Rewrite vboxDomainSnapshotNum

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   40 +++
 src/vbox/vbox_tmpl.c  |   47 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 41 insertions(+), 47 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 36260de..074eab0 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6081,3 +6081,43 @@ char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr 
snapshot,
 vboxIIDUnalloc(domiid);
 return ret;
 }
+
+int vboxDomainSnapshotNum(virDomainPtr dom, unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+nsresult rc;
+PRUint32 snapshotCount;
+
+virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
+  VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+/* VBox snapshots do not require libvirt to maintain any metadata.  */
+if (flags  VIR_DOMAIN_SNAPSHOT_LIST_METADATA) {
+ret = 0;
+goto cleanup;
+}
+
+rc = gVBoxAPI.UIMachine.GetSnapshotCount(machine, snapshotCount);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not get snapshot count for domain %s),
+   dom-name);
+goto cleanup;
+}
+
+/* VBox has at most one root snapshot.  */
+if (snapshotCount  (flags  VIR_DOMAIN_SNAPSHOT_LIST_ROOTS))
+ret = 1;
+else
+ret = snapshotCount;
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 4b5f993..f384741 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1523,53 +1523,6 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
 }
 
 static int
-vboxDomainSnapshotNum(virDomainPtr dom,
-  unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxIID iid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-nsresult rc;
-PRUint32 snapshotCount;
-
-virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
-  VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-/* VBox snapshots do not require libvirt to maintain any metadata.  */
-if (flags  VIR_DOMAIN_SNAPSHOT_LIST_METADATA) {
-ret = 0;
-goto cleanup;
-}
-
-rc = machine-vtbl-GetSnapshotCount(machine, snapshotCount);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(could not get snapshot count for domain %s),
-   dom-name);
-goto cleanup;
-}
-
-/* VBox has at most one root snapshot.  */
-if (snapshotCount  (flags  VIR_DOMAIN_SNAPSHOT_LIST_ROOTS))
-ret = 1;
-else
-ret = snapshotCount;
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
-static int
 vboxDomainSnapshotListNames(virDomainPtr dom,
 char **names,
 int nameslen,
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 6b04b57..ba75d00 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -577,6 +577,7 @@ vboxDomainSnapshotCreateXML(virDomainPtr dom,
 unsigned int flags);
 char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
unsigned int flags);
+int vboxDomainSnapshotNum(virDomainPtr dom, unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 25/66] vbox: Rewrite vboxDomainResume

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   47 +
 src/vbox/vbox_tmpl.c  |   66 -
 src/vbox/vbox_uniformed_api.h |3 ++
 3 files changed, 63 insertions(+), 53 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index d796be7..6b8a9e7 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2409,3 +2409,50 @@ int vboxDomainSuspend(virDomainPtr dom)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainResume(virDomainPtr dom)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+IConsole *console= NULL;
+PRUint32 state;
+PRBool isAccessible = PR_FALSE;
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!machine)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.Paused(state)) {
+/* resume the machine here */
+gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+gVBoxAPI.UISession.GetConsole(data-vboxSession, console);
+if (console) {
+gVBoxAPI.UIConsole.Resume(console);
+VBOX_RELEASE(console);
+ret = 0;
+} else {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(error while resuming the domain));
+goto cleanup;
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+} else {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(machine not paused, so can't resume it));
+goto cleanup;
+}
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index df7c290..95c38d4 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,59 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainResume(virDomainPtr dom)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-IConsole *console= NULL;
-PRUint32 state   = MachineState_Null;
-nsresult rc;
-
-PRBool isAccessible = PR_FALSE;
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), dom-id);
-goto cleanup;
-}
-
-if (!machine)
-goto cleanup;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-
-if (state == MachineState_Paused) {
-/* resume the machine here */
-VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
-data-vboxSession-vtbl-GetConsole(data-vboxSession, console);
-if (console) {
-console-vtbl-Resume(console);
-VBOX_RELEASE(console);
-ret = 0;
-} else {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(error while resuming the domain));
-goto cleanup;
-}
-VBOX_SESSION_CLOSE();
-} else {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(machine not paused, so can't resume it));
-goto cleanup;
-}
-}
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static int vboxDomainShutdownFlags(virDomainPtr dom,
unsigned int flags)
 {
@@ -,6 +9946,12 @@ _consolePause(IConsole *console)
 }
 
 static nsresult
+_consoleResume(IConsole *console)
+{
+return console-vtbl-Resume(console);
+}
+
+static nsresult
 _progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
 {
 return progress-vtbl-WaitForCompletion(progress, timeout);
@@ -10431,6 +10384,11 @@ static bool _machineStateRunning(PRUint32 state)
 return state == MachineState_Running;
 }
 
+static bool _machineStatePaused(PRUint32 state)
+{
+return state == MachineState_Paused;
+}
+
 static vboxUniformedPFN _UPFN = {
 .Initialize = _pfnInitialize,
 .Uninitialize = _pfnUninitialize,
@@ -10512,6 +10470,7 @@ static vboxUniformedISession _UISession = {
 static vboxUniformedIConsole _UIConsole = {
 .SaveState = _consoleSaveState,
 .Pause = _consolePause,
+.Resume = _consoleResume,
 };
 
 static vboxUniformedIProgress _UIProgress = {
@@ -10598,6 +10557,7 @@ static uniformedMachineStateChecker 
_machineStateChecker = {
 .Online = _machineStateOnline,
 .NotStart = _machineStateNotStart,
 .Running = _machineStateRunning,
+

[libvirt] [PATCH 49/66] vbox: Add API for vboxDomainSnapshotCreateXML

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.h|1 +
 src/vbox/vbox_tmpl.c  |  171 -
 src/vbox/vbox_uniformed_api.h |   17 
 3 files changed, 187 insertions(+), 2 deletions(-)

diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h
index 434689b..a093481 100644
--- a/src/vbox/vbox_common.h
+++ b/src/vbox/vbox_common.h
@@ -269,5 +269,6 @@ typedef nsISupports IMedium;
 typedef nsISupports IMediumAttachment;
 typedef nsISupports IStorageController;
 typedef nsISupports ISharedFolder;
+typedef nsISupports ISnapshot;
 
 #endif /* VBOX_COMMON_H */
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index eeebd6f..2d5ea5c 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -665,7 +665,6 @@ _vboxIIDFromArrayItem(vboxGlobalData *data, vboxIIDUnion 
*iidu,
 vboxIIDFromArrayItem_v3_x(data, iidu-vboxIID_v3_x, array, idx);
 }
 
-
 # define vboxIIDUnalloc(iid) vboxIIDUnalloc_v3_x(data, iid)
 # define vboxIIDToUUID(iid, uuid) vboxIIDToUUID_v3_x(data, iid, uuid)
 # define vboxIIDFromUUID(iid, uuid) vboxIIDFromUUID_v3_x(data, iid, uuid)
@@ -676,7 +675,6 @@ _vboxIIDFromArrayItem(vboxGlobalData *data, vboxIIDUnion 
*iidu,
 
 #endif /* !(VBOX_API_VERSION == 2002000) */
 
-
 /**
  * function to generate the name for medium,
  * for e.g: hda, sda, etc
@@ -7785,6 +7783,18 @@ static void _DEBUGIID(const char *msg, vboxIIDUnion 
*iidu)
 
 #endif /* VBOX_API_VERSION != 2002000 */
 
+static void
+_vboxIIDToUtf8(vboxGlobalData *data ATTRIBUTE_UNUSED,
+   vboxIIDUnion *iidu ATTRIBUTE_UNUSED,
+   char **utf8 ATTRIBUTE_UNUSED)
+{
+#if VBOX_API_VERSION == 2002000
+vboxUnsupported();
+#else /* !(VBOX_API_VERSION == 2002000) */
+data-pFuncs-pfnUtf16ToUtf8(IID_MEMBER(value), utf8);
+#endif /* !(VBOX_API_VERSION == 2002000) */
+}
+
 static void* _handleGetMachines(IVirtualBox *vboxObj)
 {
 return vboxObj-vtbl-GetMachines;
@@ -7839,6 +7849,12 @@ _virtualboxGetMachine(IVirtualBox *vboxObj, vboxIIDUnion 
*iidu, IMachine **machi
 #endif /* VBOX_API_VERSION = 400 */
 
 static nsresult
+_virtualboxOpenMachine(IVirtualBox *vboxObj, PRUnichar *settingsFile, IMachine 
**machine)
+{
+return vboxObj-vtbl-OpenMachine(vboxObj, settingsFile, machine);
+}
+
+static nsresult
 _virtualboxGetSystemProperties(IVirtualBox *vboxObj, ISystemProperties 
**systemProperties)
 {
 return vboxObj-vtbl-GetSystemProperties(vboxObj, systemProperties);
@@ -7909,6 +7925,20 @@ _virtualboxCreateMachine(vboxGlobalData *data, 
virDomainDefPtr def, IMachine **m
 }
 
 static nsresult
+_virtualboxCreateHardDiskMedium(IVirtualBox *vboxObj ATTRIBUTE_UNUSED,
+PRUnichar *format ATTRIBUTE_UNUSED,
+PRUnichar *location ATTRIBUTE_UNUSED,
+IMedium **medium ATTRIBUTE_UNUSED)
+{
+#if VBOX_API_VERSION  3001000
+vboxUnsupported();
+return 0;
+#else /* VBOX_API_VERSION = 3001000 */
+return vboxObj-vtbl-CreateHardDisk(vboxObj, format, location, medium);
+#endif /* VBOX_API_VERSION = 3001000 */
+}
+
+static nsresult
 _virtualboxRegisterMachine(IVirtualBox *vboxObj, IMachine *machine)
 {
 return vboxObj-vtbl-RegisterMachine(vboxObj, machine);
@@ -8032,6 +8062,20 @@ _machineLaunchVMProcess(vboxGlobalData *data,
 }
 
 static nsresult
+_machineUnregister(IMachine *machine ATTRIBUTE_UNUSED,
+   PRUint32 cleanupMode ATTRIBUTE_UNUSED,
+   PRUint32 *aMediaSize ATTRIBUTE_UNUSED,
+   IMedium ***aMedia ATTRIBUTE_UNUSED)
+{
+#if VBOX_API_VERSION  400
+vboxUnsupported();
+return 0;
+#else /* VBOX_API_VERSION = 400 */
+return machine-vtbl-Unregister(machine, cleanupMode, aMediaSize, aMedia);
+#endif /* VBOX_API_VERSION = 400 */
+}
+
+static nsresult
 _machineGetAccessible(IMachine *machine, PRBool *isAccessible)
 {
 return machine-vtbl-GetAccessible(machine, isAccessible);
@@ -8117,6 +8161,18 @@ _machineGetUSBCommon(IMachine *machine, IUSBCommon 
**USBCommon)
 }
 
 static nsresult
+_machineGetCurrentSnapshot(IMachine *machine, ISnapshot **currentSnapshot)
+{
+return machine-vtbl-GetCurrentSnapshot(machine, currentSnapshot);
+}
+
+static nsresult
+_machineGetSettingsFilePath(IMachine *machine, PRUnichar **settingsFilePath)
+{
+return machine-vtbl-GetSettingsFilePath(machine, settingsFilePath);
+}
+
+static nsresult
 _machineGetCPUCount(IMachine *machine, PRUint32 *CPUCount)
 {
 return machine-vtbl-GetCPUCount(machine, CPUCount);
@@ -8356,6 +8412,13 @@ _consoleReset(IConsole *console)
 }
 
 static nsresult
+_consoleTakeSnapshot(IConsole *console, PRUnichar *name,
+ PRUnichar *description, IProgress **progress)
+{
+return console-vtbl-TakeSnapshot(console, name, description, progress);
+}
+
+static nsresult
 _progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
 {
 return progress-vtbl-WaitForCompletion(progress, timeout);
@@ -9011,10 +9074,74 @@ static nsresult 

[libvirt] [PATCH 32/66] vbox: Rewrite vboxDomainSetMemory

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   54 ++
 src/vbox/vbox_tmpl.c  |   57 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 55 insertions(+), 57 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 102500a..b457c00 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2615,3 +2615,57 @@ char *vboxDomainGetOSType(virDomainPtr dom 
ATTRIBUTE_UNUSED) {
 ignore_value(VIR_STRDUP(osType, hvm));
 return osType;
 }
+
+int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+PRUint32 state;
+PRBool isAccessible  = PR_FALSE;
+nsresult rc;
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!machine)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (!gVBoxAPI.machineStateChecker.PoweredOff(state)) {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(memory size can't be changed unless domain is 
powered down));
+goto cleanup;
+}
+
+rc = gVBoxAPI.UISession.Open(data, iid, machine);
+if (NS_FAILED(rc))
+goto cleanup;
+
+rc = gVBoxAPI.UISession.GetMachine(data-vboxSession, machine);
+if (NS_SUCCEEDED(rc)  machine) {
+
+rc = gVBoxAPI.UIMachine.SetMemorySize(machine,
+  VIR_DIV_UP(memory, 1024));
+if (NS_SUCCEEDED(rc)) {
+gVBoxAPI.UIMachine.SaveSettings(machine);
+ret = 0;
+} else {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not set the memory size of the 
+ domain to: %lu Kb, rc=%08x),
+   memory, (unsigned)rc);
+}
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 58f921a..2cb564e 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,63 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-PRUint32 state   = MachineState_Null;
-PRBool isAccessible  = PR_FALSE;
-nsresult rc;
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), dom-id);
-goto cleanup;
-}
-
-if (!machine)
-goto cleanup;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-
-if (state != MachineState_PoweredOff) {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(memory size can't be changed unless domain is 
powered down));
-goto cleanup;
-}
-
-rc = VBOX_SESSION_OPEN(iid.value, machine);
-if (NS_SUCCEEDED(rc)) {
-rc = data-vboxSession-vtbl-GetMachine(data-vboxSession, 
machine);
-if (NS_SUCCEEDED(rc)  machine) {
-
-rc = machine-vtbl-SetMemorySize(machine,
-  VIR_DIV_UP(memory, 1024));
-if (NS_SUCCEEDED(rc)) {
-machine-vtbl-SaveSettings(machine);
-ret = 0;
-} else {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(could not set the memory size of the 
- domain to: %lu Kb, rc=%08x),
-   memory, (unsigned)rc);
-}
-}
-VBOX_SESSION_CLOSE();
-}
-}
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static virDomainState vboxConvertState(enum MachineState state)
 {
 switch (state) {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 31a0e45..bc76904 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -430,6 +430,7 @@ int vboxDomainReboot(virDomainPtr dom, unsigned int flags);
 int vboxDomainDestroyFlags(virDomainPtr dom, unsigned int flags);
 int vboxDomainDestroy(virDomainPtr dom);
 char *vboxDomainGetOSType(virDomainPtr dom);
+int vboxDomainSetMemory(virDomainPtr dom, unsigned long memory);
 
 /* Version specified functions for installing 

[libvirt] [PATCH 53/66] vbox: Rewrite vboxDomainSnapshotListNames

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   79 
 src/vbox/vbox_tmpl.c  |   90 -
 src/vbox/vbox_uniformed_api.h |2 +
 3 files changed, 81 insertions(+), 90 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 074eab0..dc9018f 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6121,3 +6121,82 @@ int vboxDomainSnapshotNum(virDomainPtr dom, unsigned int 
flags)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainSnapshotListNames(virDomainPtr dom, char **names,
+int nameslen, unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+nsresult rc;
+ISnapshot **snapshots = NULL;
+int count = 0;
+size_t i;
+
+virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
+  VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (flags  VIR_DOMAIN_SNAPSHOT_LIST_METADATA) {
+ret = 0;
+goto cleanup;
+}
+
+if (flags  VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) {
+vboxIIDUnion empty;
+
+VBOX_IID_INITIALIZE(empty);
+if (VIR_ALLOC_N(snapshots, 1)  0)
+goto cleanup;
+rc = gVBoxAPI.UIMachine.FindSnapshot(machine, empty, snapshots);
+if (NS_FAILED(rc) || !snapshots[0]) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not get root snapshot for domain %s),
+   dom-name);
+goto cleanup;
+}
+count = 1;
+} else {
+if ((count = vboxDomainSnapshotGetAll(dom, machine, snapshots))  0)
+goto cleanup;
+}
+
+for (i = 0; i  nameslen; i++) {
+PRUnichar *nameUtf16;
+char *name;
+
+if (i = count)
+break;
+
+rc = gVBoxAPI.UISnapshot.GetName(snapshots[i], nameUtf16);
+if (NS_FAILED(rc) || !nameUtf16) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   %s, _(could not get snapshot name));
+goto cleanup;
+}
+VBOX_UTF16_TO_UTF8(nameUtf16, name);
+VBOX_UTF16_FREE(nameUtf16);
+if (VIR_STRDUP(names[i], name)  0) {
+VBOX_UTF8_FREE(name);
+goto cleanup;
+}
+VBOX_UTF8_FREE(name);
+}
+
+if (count = nameslen)
+ret = count;
+else
+ret = nameslen;
+
+ cleanup:
+if (count  0) {
+for (i = 0; i  count; i++)
+VBOX_RELEASE(snapshots[i]);
+}
+VIR_FREE(snapshots);
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index f384741..7b6f847 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1522,96 +1522,6 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
 return snapshot;
 }
 
-static int
-vboxDomainSnapshotListNames(virDomainPtr dom,
-char **names,
-int nameslen,
-unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxIID iid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-nsresult rc;
-ISnapshot **snapshots = NULL;
-int count = 0;
-size_t i;
-
-virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS |
-  VIR_DOMAIN_SNAPSHOT_LIST_METADATA, -1);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-if (flags  VIR_DOMAIN_SNAPSHOT_LIST_METADATA) {
-ret = 0;
-goto cleanup;
-}
-
-if (flags  VIR_DOMAIN_SNAPSHOT_LIST_ROOTS) {
-vboxIID empty = VBOX_IID_INITIALIZER;
-
-if (VIR_ALLOC_N(snapshots, 1)  0)
-goto cleanup;
-#if VBOX_API_VERSION  400
-rc = machine-vtbl-GetSnapshot(machine, empty.value, snapshots);
-#else /* VBOX_API_VERSION = 400 */
-rc = machine-vtbl-FindSnapshot(machine, empty.value, snapshots);
-#endif /* VBOX_API_VERSION = 400 */
-if (NS_FAILED(rc) || !snapshots[0]) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(could not get root snapshot for domain %s),
-   dom-name);
-goto cleanup;
-}
-count = 1;
-} else {
-if ((count = vboxDomainSnapshotGetAll(dom, machine, snapshots))  0)
-goto cleanup;
-}
-
-for (i = 0; i  nameslen; i++) {
-PRUnichar *nameUtf16;
-char *name;
-
-if (i = count)
-break;
-
-rc = snapshots[i]-vtbl-GetName(snapshots[i], nameUtf16);
-if (NS_FAILED(rc) || !nameUtf16) {
-

[libvirt] [PATCH 54/66] vbox: Rewrite vboxSnapshotLookupByName

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   26 ++
 src/vbox/vbox_tmpl.c  |   33 -
 src/vbox/vbox_uniformed_api.h |3 +++
 3 files changed, 29 insertions(+), 33 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index dc9018f..5178cda 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6200,3 +6200,29 @@ int vboxDomainSnapshotListNames(virDomainPtr dom, char 
**names,
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+virDomainSnapshotPtr
+vboxDomainSnapshotLookupByName(virDomainPtr dom, const char *name,
+   unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, virDomainSnapshotPtr, NULL);
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+ISnapshot *snapshot = NULL;
+
+virCheckFlags(0, NULL);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!(snapshot = vboxDomainSnapshotGet(data, dom, machine, name)))
+goto cleanup;
+
+ret = virGetDomainSnapshot(dom, name);
+
+ cleanup:
+VBOX_RELEASE(snapshot);
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 7b6f847..5aef7dd 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1522,39 +1522,6 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
 return snapshot;
 }
 
-static virDomainSnapshotPtr
-vboxDomainSnapshotLookupByName(virDomainPtr dom,
-   const char *name,
-   unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, virDomainSnapshotPtr, NULL);
-vboxIID iid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-ISnapshot *snapshot = NULL;
-nsresult rc;
-
-virCheckFlags(0, NULL);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-if (!(snapshot = vboxDomainSnapshotGet(data, dom, machine, name)))
-goto cleanup;
-
-ret = virGetDomainSnapshot(dom, name);
-
- cleanup:
-VBOX_RELEASE(snapshot);
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static int
 vboxDomainHasCurrentSnapshot(virDomainPtr dom,
  unsigned int flags)
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index f0cfb18..afbc351 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -580,6 +580,9 @@ char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr 
snapshot,
 int vboxDomainSnapshotNum(virDomainPtr dom, unsigned int flags);
 int vboxDomainSnapshotListNames(virDomainPtr dom, char **names,
 int nameslen, unsigned int flags);
+virDomainSnapshotPtr
+vboxDomainSnapshotLookupByName(virDomainPtr dom, const char *name,
+   unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 39/66] vbox: Add API for vboxDomainGetXMLDesc

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.h|2 +
 src/vbox/vbox_tmpl.c  |  718 +
 src/vbox/vbox_uniformed_api.h |   73 +
 3 files changed, 793 insertions(+)

diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h
index eedd755..c4e7ae5 100644
--- a/src/vbox/vbox_common.h
+++ b/src/vbox/vbox_common.h
@@ -257,6 +257,8 @@ typedef nsISupports IVRDxServer;
 typedef nsISupports IUSBCommon;
 typedef nsISupports IUSBDeviceFilter;
 typedef nsISupports IMedium;
+typedef nsISupports IMediumAttachment;
 typedef nsISupports IStorageController;
+typedef nsISupports ISharedFolder;
 
 #endif /* VBOX_COMMON_H */
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 8abb9a7..803b0cc 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -102,6 +102,10 @@ typedef IUSBController IUSBCommon;
 typedef IUSBDeviceFilters IUSBCommon;
 #endif /* VBOX_API_VERSION = 4003000 */
 
+#if VBOX_API_VERSION  3001000
+typedef IHardDiskAttachment IMediumAttachment;
+#endif /* VBOX_API_VERSION  3001000 */
+
 #include vbox_uniformed_api.h
 
 #define VIR_FROM_THIS   VIR_FROM_VBOX
@@ -8982,6 +8986,260 @@ _deleteConfig(IMachine *machine)
 
 #endif /* VBOX_API_VERSION = 400 */
 
+#if VBOX_API_VERSION  3001000
+
+static void
+_dumpIDEHDDsOld(virDomainDefPtr def,
+vboxGlobalData *data,
+IMachine *machine)
+{
+PRInt32   hddNum= 0;
+IHardDisk*hardDiskPM= NULL;
+IHardDisk*hardDiskPS= NULL;
+IHardDisk*hardDiskSS= NULL;
+const char   *hddBus= IDE;
+PRUnichar*hddBusUtf16   = NULL;
+
+/* dump IDE hdds if present */
+VBOX_UTF8_TO_UTF16(hddBus, hddBusUtf16);
+
+def-ndisks = 0;
+machine-vtbl-GetHardDisk(machine, hddBusUtf16, 0, 0,  hardDiskPM);
+if (hardDiskPM)
+def-ndisks++;
+
+machine-vtbl-GetHardDisk(machine, hddBusUtf16, 0, 1,  hardDiskPS);
+if (hardDiskPS)
+def-ndisks++;
+
+machine-vtbl-GetHardDisk(machine, hddBusUtf16, 1, 1,  hardDiskSS);
+if (hardDiskSS)
+def-ndisks++;
+
+VBOX_UTF16_FREE(hddBusUtf16);
+
+if ((def-ndisks  0)  (VIR_ALLOC_N(def-disks, def-ndisks) = 0)) {
+size_t i;
+for (i = 0; i  def-ndisks; i++) {
+if ((def-disks[i] = virDomainDiskDefNew())) {
+def-disks[i]-device = VIR_DOMAIN_DISK_DEVICE_DISK;
+def-disks[i]-bus = VIR_DOMAIN_DISK_BUS_IDE;
+virDomainDiskSetType(def-disks[i],
+ VIR_STORAGE_TYPE_FILE);
+}
+}
+}
+
+if (hardDiskPM) {
+PRUnichar *hddlocationUtf16 = NULL;
+char *hddlocation   = NULL;
+PRUint32 hddType= HardDiskType_Normal;
+
+hardDiskPM-vtbl-imedium.GetLocation((IMedium *)hardDiskPM, 
hddlocationUtf16);
+VBOX_UTF16_TO_UTF8(hddlocationUtf16, hddlocation);
+
+hardDiskPM-vtbl-GetType(hardDiskPM, hddType);
+
+if (hddType == HardDiskType_Immutable)
+def-disks[hddNum]-src-readonly = true;
+ignore_value(virDomainDiskSetSource(def-disks[hddNum],
+hddlocation));
+ignore_value(VIR_STRDUP(def-disks[hddNum]-dst, hda));
+hddNum++;
+
+VBOX_UTF8_FREE(hddlocation);
+VBOX_UTF16_FREE(hddlocationUtf16);
+VBOX_MEDIUM_RELEASE(hardDiskPM);
+}
+
+if (hardDiskPS) {
+PRUnichar *hddlocationUtf16 = NULL;
+char *hddlocation   = NULL;
+PRUint32 hddType= HardDiskType_Normal;
+
+hardDiskPS-vtbl-imedium.GetLocation((IMedium *)hardDiskPS, 
hddlocationUtf16);
+VBOX_UTF16_TO_UTF8(hddlocationUtf16, hddlocation);
+
+hardDiskPS-vtbl-GetType(hardDiskPS, hddType);
+
+if (hddType == HardDiskType_Immutable)
+def-disks[hddNum]-src-readonly = true;
+ignore_value(virDomainDiskSetSource(def-disks[hddNum],
+hddlocation));
+ignore_value(VIR_STRDUP(def-disks[hddNum]-dst, hdb));
+hddNum++;
+
+VBOX_UTF8_FREE(hddlocation);
+VBOX_UTF16_FREE(hddlocationUtf16);
+VBOX_MEDIUM_RELEASE(hardDiskPS);
+}
+
+if (hardDiskSS) {
+PRUnichar *hddlocationUtf16 = NULL;
+char *hddlocation   = NULL;
+PRUint32 hddType= HardDiskType_Normal;
+
+hardDiskSS-vtbl-imedium.GetLocation((IMedium *)hardDiskSS, 
hddlocationUtf16);
+VBOX_UTF16_TO_UTF8(hddlocationUtf16, hddlocation);
+
+hardDiskSS-vtbl-GetType(hardDiskSS, hddType);
+
+if (hddType == HardDiskType_Immutable)
+def-disks[hddNum]-src-readonly = true;
+ignore_value(virDomainDiskSetSource(def-disks[hddNum],
+hddlocation));
+ignore_value(VIR_STRDUP(def-disks[hddNum]-dst, hdd));
+hddNum++;

[libvirt] [PATCH 28/66] vbox: Rewrite vboxDomainReboot

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   44 
 src/vbox/vbox_tmpl.c  |   56 ++---
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 53 insertions(+), 49 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index b15e8a3..0527fea 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2509,3 +2509,47 @@ int vboxDomainShutdown(virDomainPtr dom)
 {
 return vboxDomainShutdownFlags(dom, 0);
 }
+
+int vboxDomainReboot(virDomainPtr dom, unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+IConsole *console= NULL;
+PRUint32 state;
+PRBool isAccessible  = PR_FALSE;
+
+virCheckFlags(0, -1);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!machine)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.Running(state)) {
+gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+gVBoxAPI.UISession.GetConsole(data-vboxSession, console);
+if (console) {
+gVBoxAPI.UIConsole.Reset(console);
+VBOX_RELEASE(console);
+ret = 0;
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+} else {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(machine not running, so can't reboot it));
+goto cleanup;
+}
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 4c008c9..ef734c9 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,55 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainReboot(virDomainPtr dom, unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-IConsole *console= NULL;
-PRUint32 state   = MachineState_Null;
-PRBool isAccessible  = PR_FALSE;
-nsresult rc;
-
-virCheckFlags(0, -1);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), dom-id);
-goto cleanup;
-}
-
-if (!machine)
-goto cleanup;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-
-if (state == MachineState_Running) {
-VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
-data-vboxSession-vtbl-GetConsole(data-vboxSession, console);
-if (console) {
-console-vtbl-Reset(console);
-VBOX_RELEASE(console);
-ret = 0;
-}
-VBOX_SESSION_CLOSE();
-} else {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(machine not running, so can't reboot it));
-goto cleanup;
-}
-}
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static int
 vboxDomainDestroyFlags(virDomainPtr dom,
unsigned int flags)
@@ -9898,6 +9849,12 @@ _consolePowerButton(IConsole *console)
 }
 
 static nsresult
+_consoleReset(IConsole *console)
+{
+return console-vtbl-Reset(console);
+}
+
+static nsresult
 _progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
 {
 return progress-vtbl-WaitForCompletion(progress, timeout);
@@ -10423,6 +10380,7 @@ static vboxUniformedIConsole _UIConsole = {
 .Pause = _consolePause,
 .Resume = _consoleResume,
 .PowerButton = _consolePowerButton,
+.Reset = _consoleReset,
 };
 
 static vboxUniformedIProgress _UIProgress = {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index bf53b27..d5c6fb4 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -240,6 +240,7 @@ typedef struct {
 nsresult (*Pause)(IConsole *console);
 nsresult (*Resume)(IConsole *console);
 nsresult (*PowerButton)(IConsole *console);
+nsresult (*Reset)(IConsole *console);
 } vboxUniformedIConsole;
 
 /* Functions for IProgress */
@@ -424,6 +425,7 @@ int vboxDomainSuspend(virDomainPtr dom);
 int vboxDomainResume(virDomainPtr dom);
 int vboxDomainShutdownFlags(virDomainPtr dom, unsigned int flags);
 int vboxDomainShutdown(virDomainPtr dom);
+int vboxDomainReboot(virDomainPtr dom, unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing 

[libvirt] [PATCH 58/66] vbox: Rewrite vboxDomainSnapshotIsCurrent

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   57 +
 src/vbox/vbox_tmpl.c  |   63 -
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 59 insertions(+), 63 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 32cbe60..f38305a 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6372,3 +6372,60 @@ vboxDomainSnapshotCurrent(virDomainPtr dom, unsigned int 
flags)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
+unsigned int flags)
+{
+virDomainPtr dom = snapshot-domain;
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+ISnapshot *snap = NULL;
+ISnapshot *current = NULL;
+PRUnichar *nameUtf16 = NULL;
+char *name = NULL;
+nsresult rc;
+
+virCheckFlags(0, -1);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot-name)))
+goto cleanup;
+
+rc = gVBoxAPI.UIMachine.GetCurrentSnapshot(machine, current);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(could not get current snapshot));
+goto cleanup;
+}
+if (!current) {
+ret = 0;
+goto cleanup;
+}
+
+rc = gVBoxAPI.UISnapshot.GetName(current, nameUtf16);
+if (NS_FAILED(rc) || !nameUtf16) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(could not get current snapshot name));
+goto cleanup;
+}
+
+VBOX_UTF16_TO_UTF8(nameUtf16, name);
+if (!name) {
+virReportOOMError();
+goto cleanup;
+}
+
+ret = STREQ(snapshot-name, name);
+
+ cleanup:
+VBOX_UTF8_FREE(name);
+VBOX_UTF16_FREE(nameUtf16);
+VBOX_RELEASE(snap);
+VBOX_RELEASE(current);
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 87200f1..fb3ed61 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1523,69 +1523,6 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
 }
 
 static int
-vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
-unsigned int flags)
-{
-virDomainPtr dom = snapshot-domain;
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxIID iid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-ISnapshot *snap = NULL;
-ISnapshot *current = NULL;
-PRUnichar *nameUtf16 = NULL;
-char *name = NULL;
-nsresult rc;
-
-virCheckFlags(0, -1);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot-name)))
-goto cleanup;
-
-rc = machine-vtbl-GetCurrentSnapshot(machine, current);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR, %s,
-   _(could not get current snapshot));
-goto cleanup;
-}
-if (!current) {
-ret = 0;
-goto cleanup;
-}
-
-rc = current-vtbl-GetName(current, nameUtf16);
-if (NS_FAILED(rc) || !nameUtf16) {
-virReportError(VIR_ERR_INTERNAL_ERROR, %s,
-   _(could not get current snapshot name));
-goto cleanup;
-}
-
-VBOX_UTF16_TO_UTF8(nameUtf16, name);
-if (!name) {
-virReportOOMError();
-goto cleanup;
-}
-
-ret = STREQ(snapshot-name, name);
-
- cleanup:
-VBOX_UTF8_FREE(name);
-VBOX_UTF16_FREE(nameUtf16);
-VBOX_RELEASE(snap);
-VBOX_RELEASE(current);
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
-static int
 vboxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
   unsigned int flags)
 {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index c320ac2..c761bda 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -589,6 +589,8 @@ vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
 unsigned int flags);
 virDomainSnapshotPtr
 vboxDomainSnapshotCurrent(virDomainPtr dom, unsigned int flags);
+int vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
+unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 51/66] vbox: Rewrite vboxDomainSnapshotGetXMLDesc

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|  712 ++
 src/vbox/vbox_tmpl.c  |  756 ++---
 src/vbox/vbox_uniformed_api.h |   22 +-
 3 files changed, 843 insertions(+), 647 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 8f3fe03..36260de 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -77,6 +77,8 @@ VIR_LOG_INIT(vbox.vbox_common);
 #define VBOX_UTF16_TO_UTF8(arg1, arg2)  
gVBoxAPI.UPFN.Utf16ToUtf8(data-pFuncs, arg1, arg2)
 #define VBOX_UTF8_TO_UTF16(arg1, arg2)  
gVBoxAPI.UPFN.Utf8ToUtf16(data-pFuncs, arg1, arg2)
 
+#define VBOX_ADDREF(arg)gVBoxAPI.nsUISupports.AddRef((void 
*)(arg))
+
 #define VBOX_RELEASE(arg) \
 do {  \
 if (arg) {\
@@ -5369,3 +5371,713 @@ vboxDomainSnapshotCreateXML(virDomainPtr dom,
 virDomainSnapshotDefFree(def);
 return ret;
 }
+
+static int
+vboxDomainSnapshotGetAll(virDomainPtr dom,
+ IMachine *machine,
+ ISnapshot ***snapshots)
+{
+vboxIIDUnion empty;
+ISnapshot **list = NULL;
+PRUint32 count;
+nsresult rc;
+unsigned int next;
+unsigned int top;
+
+VBOX_IID_INITIALIZE(empty);
+rc = gVBoxAPI.UIMachine.GetSnapshotCount(machine, count);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not get snapshot count for domain %s),
+   dom-name);
+goto error;
+}
+
+if (count == 0)
+goto out;
+
+if (VIR_ALLOC_N(list, count)  0)
+goto error;
+
+rc = gVBoxAPI.UIMachine.FindSnapshot(machine, empty, list);
+if (NS_FAILED(rc) || !list[0]) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not get root snapshot for domain %s),
+   dom-name);
+goto error;
+}
+
+/* BFS walk through snapshot tree */
+top = 1;
+for (next = 0; next  count; next++) {
+vboxArray children = VBOX_ARRAY_INITIALIZER;
+size_t i;
+
+if (!list[next]) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(unexpected number of snapshots  %u), count);
+goto error;
+}
+
+rc = gVBoxAPI.UArray.vboxArrayGet(children, list[next],
+  
gVBoxAPI.UArray.handleSnapshotGetChildren(list[next]));
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   %s, _(could not get children snapshots));
+goto error;
+}
+for (i = 0; i  children.count; i++) {
+ISnapshot *child = children.items[i];
+if (!child)
+continue;
+if (top == count) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(unexpected number of snapshots  %u), 
count);
+gVBoxAPI.UArray.vboxArrayRelease(children);
+goto error;
+}
+VBOX_ADDREF(child);
+list[top++] = child;
+}
+gVBoxAPI.UArray.vboxArrayRelease(children);
+}
+
+ out:
+*snapshots = list;
+return count;
+
+ error:
+if (list) {
+for (next = 0; next  count; next++)
+VBOX_RELEASE(list[next]);
+}
+VIR_FREE(list);
+
+return -1;
+}
+
+static ISnapshot *
+vboxDomainSnapshotGet(vboxGlobalData *data,
+  virDomainPtr dom,
+  IMachine *machine,
+  const char *name)
+{
+ISnapshot **snapshots = NULL;
+ISnapshot *snapshot = NULL;
+nsresult rc;
+int count = 0;
+size_t i;
+
+if ((count = vboxDomainSnapshotGetAll(dom, machine, snapshots))  0)
+goto cleanup;
+
+for (i = 0; i  count; i++) {
+PRUnichar *nameUtf16;
+char *nameUtf8;
+
+rc = gVBoxAPI.UISnapshot.GetName(snapshots[i], nameUtf16);
+if (NS_FAILED(rc) || !nameUtf16) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   %s, _(could not get snapshot name));
+goto cleanup;
+}
+VBOX_UTF16_TO_UTF8(nameUtf16, nameUtf8);
+VBOX_UTF16_FREE(nameUtf16);
+if (STREQ(name, nameUtf8))
+snapshot = snapshots[i];
+VBOX_UTF8_FREE(nameUtf8);
+
+if (snapshot)
+break;
+}
+
+if (!snapshot) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+   _(domain %s has no snapshots with name %s),
+   dom-name, name);
+goto cleanup;
+}
+
+ cleanup:
+if (count  0) {
+for (i = 0; i  count; i++) {
+if (snapshots[i] != snapshot)
+VBOX_RELEASE(snapshots[i]);
+}
+ 

[libvirt] [PATCH 56/66] vbox: Rewrite vboxDomainSnapshotGetParent

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   61 +
 src/vbox/vbox_tmpl.c  |   66 -
 src/vbox/vbox_uniformed_api.h |3 ++
 3 files changed, 64 insertions(+), 66 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index cb6ba78..04e6c2c 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6258,3 +6258,64 @@ int vboxDomainHasCurrentSnapshot(virDomainPtr dom,
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+virDomainSnapshotPtr
+vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
+unsigned int flags)
+{
+virDomainPtr dom = snapshot-domain;
+VBOX_OBJECT_CHECK(dom-conn, virDomainSnapshotPtr, NULL);
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+ISnapshot *snap = NULL;
+ISnapshot *parent = NULL;
+PRUnichar *nameUtf16 = NULL;
+char *name = NULL;
+nsresult rc;
+
+virCheckFlags(0, NULL);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot-name)))
+goto cleanup;
+
+rc = gVBoxAPI.UISnapshot.GetParent(snap, parent);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not get parent of snapshot %s),
+   snapshot-name);
+goto cleanup;
+}
+if (!parent) {
+virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
+   _(snapshot '%s' does not have a parent),
+   snapshot-name);
+goto cleanup;
+}
+
+rc = gVBoxAPI.UISnapshot.GetName(parent, nameUtf16);
+if (NS_FAILED(rc) || !nameUtf16) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not get name of parent of snapshot %s),
+   snapshot-name);
+goto cleanup;
+}
+VBOX_UTF16_TO_UTF8(nameUtf16, name);
+if (!name) {
+virReportOOMError();
+goto cleanup;
+}
+
+ret = virGetDomainSnapshot(dom, name);
+
+ cleanup:
+VBOX_UTF8_FREE(name);
+VBOX_UTF16_FREE(nameUtf16);
+VBOX_RELEASE(snap);
+VBOX_RELEASE(parent);
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 73b3fc3..d5df286 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1523,72 +1523,6 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
 }
 
 static virDomainSnapshotPtr
-vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
-unsigned int flags)
-{
-virDomainPtr dom = snapshot-domain;
-VBOX_OBJECT_CHECK(dom-conn, virDomainSnapshotPtr, NULL);
-vboxIID iid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-ISnapshot *snap = NULL;
-ISnapshot *parent = NULL;
-PRUnichar *nameUtf16 = NULL;
-char *name = NULL;
-nsresult rc;
-
-virCheckFlags(0, NULL);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot-name)))
-goto cleanup;
-
-rc = snap-vtbl-GetParent(snap, parent);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(could not get parent of snapshot %s),
-   snapshot-name);
-goto cleanup;
-}
-if (!parent) {
-virReportError(VIR_ERR_NO_DOMAIN_SNAPSHOT,
-   _(snapshot '%s' does not have a parent),
-   snapshot-name);
-goto cleanup;
-}
-
-rc = parent-vtbl-GetName(parent, nameUtf16);
-if (NS_FAILED(rc) || !nameUtf16) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(could not get name of parent of snapshot %s),
-   snapshot-name);
-goto cleanup;
-}
-VBOX_UTF16_TO_UTF8(nameUtf16, name);
-if (!name) {
-virReportOOMError();
-goto cleanup;
-}
-
-ret = virGetDomainSnapshot(dom, name);
-
- cleanup:
-VBOX_UTF8_FREE(name);
-VBOX_UTF16_FREE(nameUtf16);
-VBOX_RELEASE(snap);
-VBOX_RELEASE(parent);
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
-static virDomainSnapshotPtr
 vboxDomainSnapshotCurrent(virDomainPtr dom,
   unsigned int flags)
 {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index d91e970..978da5e 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -584,6 +584,9 @@ virDomainSnapshotPtr
 vboxDomainSnapshotLookupByName(virDomainPtr dom, const char *name,
unsigned int flags);
 int vboxDomainHasCurrentSnapshot(virDomainPtr dom, unsigned 

[libvirt] [PATCH 35/66] vbox: Rewrite vboxDomainSetVcpusFlags

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   46 ++
 src/vbox/vbox_tmpl.c  |   55 -
 src/vbox/vbox_uniformed_api.h |3 +++
 3 files changed, 49 insertions(+), 55 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 1a4a4f5..4aadd01 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2775,3 +2775,49 @@ int vboxDomainGetState(virDomainPtr dom, int *state,
 vboxIIDUnalloc(domiid);
 return ret;
 }
+
+int vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
+unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+PRUint32  CPUCount   = nvcpus;
+nsresult rc;
+
+if (flags != VIR_DOMAIN_AFFECT_LIVE) {
+virReportError(VIR_ERR_INVALID_ARG, _(unsupported flags: (0x%x)), 
flags);
+return -1;
+}
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, true)  0)
+return -1;
+
+rc = gVBoxAPI.UISession.Open(data, iid, machine);
+if (NS_SUCCEEDED(rc)) {
+gVBoxAPI.UISession.GetMachine(data-vboxSession, machine);
+if (machine) {
+rc = gVBoxAPI.UIMachine.SetCPUCount(machine, CPUCount);
+if (NS_SUCCEEDED(rc)) {
+gVBoxAPI.UIMachine.SaveSettings(machine);
+ret = 0;
+} else {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not set the number of cpus of the 
domain 
+ to: %u, rc=%08x),
+   CPUCount, (unsigned)rc);
+}
+VBOX_RELEASE(machine);
+} else {
+virReportError(VIR_ERR_NO_DOMAIN,
+   _(no domain with matching id %d), dom-id);
+}
+} else {
+virReportError(VIR_ERR_NO_DOMAIN,
+   _(can't open session to the domain with id %d), 
dom-id);
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 33aa66a..c8cc951 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -955,61 +955,6 @@ static virDomainState _vboxConvertState(PRUint32 state)
 }
 
 static int
-vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
-unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-PRUint32  CPUCount   = nvcpus;
-nsresult rc;
-
-if (flags != VIR_DOMAIN_AFFECT_LIVE) {
-virReportError(VIR_ERR_INVALID_ARG, _(unsupported flags: (0x%x)), 
flags);
-return -1;
-}
-
-vboxIIDFromUUID(iid, dom-uuid);
-#if VBOX_API_VERSION = 400
-/* Get machine for the call to VBOX_SESSION_OPEN */
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching uuid));
-return -1;
-}
-#endif
-
-rc = VBOX_SESSION_OPEN(iid.value, machine);
-if (NS_SUCCEEDED(rc)) {
-data-vboxSession-vtbl-GetMachine(data-vboxSession, machine);
-if (machine) {
-rc = machine-vtbl-SetCPUCount(machine, CPUCount);
-if (NS_SUCCEEDED(rc)) {
-machine-vtbl-SaveSettings(machine);
-ret = 0;
-} else {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(could not set the number of cpus of the 
domain 
- to: %u, rc=%08x),
-   CPUCount, (unsigned)rc);
-}
-VBOX_RELEASE(machine);
-} else {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), dom-id);
-}
-} else {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(can't open session to the domain with id %d), 
dom-id);
-}
-VBOX_SESSION_CLOSE();
-
-vboxIIDUnalloc(iid);
-return ret;
-}
-
-static int
 vboxDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
 {
 return vboxDomainSetVcpusFlags(dom, nvcpus, VIR_DOMAIN_AFFECT_LIVE);
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 0f6c8ea..84a8a37 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -438,6 +438,9 @@ int vboxDomainSetMemory(virDomainPtr dom, unsigned long 
memory);
 int vboxDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info);
 int vboxDomainGetState(virDomainPtr dom, int *state,
int *reason, unsigned int flags);
+int vboxDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
+unsigned int flags);
+
 
 /* Version specified functions for installing uniformed API */
 void 

[libvirt] [PATCH 59/66] vbox: Rewrite vboxDomainSnapshotHasMetadata

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   27 +++
 src/vbox/vbox_tmpl.c  |   34 --
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index f38305a..dcd8ab8 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6429,3 +6429,30 @@ int vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr 
snapshot,
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
+  unsigned int flags)
+{
+virDomainPtr dom = snapshot-domain;
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+ISnapshot *snap = NULL;
+
+virCheckFlags(0, -1);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+/* Check that snapshot exists.  If so, there is no metadata.  */
+if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot-name)))
+goto cleanup;
+
+ret = 0;
+
+ cleanup:
+VBOX_RELEASE(snap);
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index fb3ed61..6d80a26 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1522,40 +1522,6 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
 return snapshot;
 }
 
-static int
-vboxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
-  unsigned int flags)
-{
-virDomainPtr dom = snapshot-domain;
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxIID iid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-ISnapshot *snap = NULL;
-nsresult rc;
-
-virCheckFlags(0, -1);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-/* Check that snapshot exists.  If so, there is no metadata.  */
-if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot-name)))
-goto cleanup;
-
-ret = 0;
-
- cleanup:
-VBOX_RELEASE(snap);
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 #if VBOX_API_VERSION  3001000
 static int
 vboxDomainSnapshotRestore(virDomainPtr dom,
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index c761bda..ac8a6b7 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -591,6 +591,8 @@ virDomainSnapshotPtr
 vboxDomainSnapshotCurrent(virDomainPtr dom, unsigned int flags);
 int vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
 unsigned int flags);
+int vboxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot,
+unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 65/66] vbox: Add registerDomainEvent

2014-08-11 Thread Taowei
---
 src/vbox/vbox_tmpl.c  |   20 
 src/vbox/vbox_uniformed_api.h |1 +
 2 files changed, 21 insertions(+)

diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 72d4c4d..fbd0d08 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1492,6 +1492,16 @@ _vboxDomainSnapshotRestore(virDomainPtr dom,
 #if VBOX_API_VERSION = 2002000 || VBOX_API_VERSION = 400
 /* No Callback support for VirtualBox 2.2.* series */
 /* No Callback support for VirtualBox 4.* series */
+
+static void
+_registerDomainEvent(virDriverPtr driver)
+{
+driver-connectDomainEventRegister = NULL;
+driver-connectDomainEventDeregister = NULL;
+driver-connectDomainEventRegisterAny = NULL;
+driver-connectDomainEventDeregisterAny = NULL;
+}
+
 #else /* !(VBOX_API_VERSION == 2002000 || VBOX_API_VERSION = 400) */
 
 /* Functions needed for Callbacks */
@@ -2034,6 +2044,15 @@ vboxConnectDomainEventDeregisterAny(virConnectPtr conn,
 return ret;
 }
 
+static void
+_registerDomainEvent(virDriverPtr driver)
+{
+driver-connectDomainEventRegister = vboxConnectDomainEventRegister; /* 
0.7.0 */
+driver-connectDomainEventDeregister = vboxConnectDomainEventDeregister; 
/* 0.7.0 */
+driver-connectDomainEventRegisterAny = vboxConnectDomainEventRegisterAny; 
/* 0.8.0 */
+driver-connectDomainEventDeregisterAny = 
vboxConnectDomainEventDeregisterAny; /* 0.8.0 */
+}
+
 #endif /* !(VBOX_API_VERSION == 2002000 || VBOX_API_VERSION = 400) */
 
 /**
@@ -6381,6 +6400,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
 pVBoxAPI-attachFloppy = _attachFloppy;
 pVBoxAPI-detachFloppy = _detachFloppy;
 pVBoxAPI-snapshotRestore = _vboxDomainSnapshotRestore;
+pVBoxAPI-registerDomainEvent = _registerDomainEvent;
 pVBoxAPI-UPFN = _UPFN;
 pVBoxAPI-UIID = _UIID;
 pVBoxAPI-UArray = _UArray;
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index a868ac0..c0586c0 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -493,6 +493,7 @@ typedef struct {
 int (*attachFloppy)(vboxGlobalData *data, IMachine *machine, const char 
*src);
 int (*detachFloppy)(IMachine *machine);
 int (*snapshotRestore)(virDomainPtr dom, IMachine *machine, ISnapshot 
*snapshot);
+void (*registerDomainEvent)(virDriverPtr driver);
 vboxUniformedPFN UPFN;
 vboxUniformedIID UIID;
 vboxUniformedArray UArray;
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 42/66] vbox: Rewrite vboxConnectNumOfDefinedDomains

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   40 
 src/vbox/vbox_tmpl.c  |   38 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 41 insertions(+), 38 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index fcde620..cd9fede 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -3993,3 +3993,43 @@ int vboxConnectListDefinedDomains(virConnectPtr conn,
 gVBoxAPI.UArray.vboxArrayRelease(machines);
 return ret;
 }
+
+int vboxConnectNumOfDefinedDomains(virConnectPtr conn)
+{
+VBOX_OBJECT_CHECK(conn, int, -1);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+PRUint32 state;
+nsresult rc;
+size_t i;
+
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj,
+  ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get number of Defined Domains, rc=%08x),
+   (unsigned)rc);
+goto cleanup;
+}
+
+ret = 0;
+for (i = 0; i  machines.count; ++i) {
+PRBool isAccessible = PR_FALSE;
+IMachine *machine = machines.items[i];
+
+if (!machine)
+continue;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+continue;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+if (gVBoxAPI.machineStateChecker.Inactive(state)) {
+ret++;
+}
+}
+
+ cleanup:
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 7479f23..239ee67 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -966,44 +966,6 @@ static virDomainState _vboxConvertState(PRUint32 state)
 }
 }
 
-static int vboxConnectNumOfDefinedDomains(virConnectPtr conn)
-{
-VBOX_OBJECT_CHECK(conn, int, -1);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-PRUint32 state   = MachineState_Null;
-nsresult rc;
-size_t i;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get number of Defined Domains, rc=%08x),
-   (unsigned)rc);
-goto cleanup;
-}
-
-ret = 0;
-for (i = 0; i  machines.count; ++i) {
-IMachine *machine = machines.items[i];
-
-if (machine) {
-PRBool isAccessible = PR_FALSE;
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-if ((state  MachineState_FirstOnline) ||
-(state  MachineState_LastOnline)) {
-ret++;
-}
-}
-}
-}
-
- cleanup:
-vboxArrayRelease(machines);
-return ret;
-}
-
 #if VBOX_API_VERSION  3001000
 
 static void
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 7ff6b57..f57eaa9 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -520,6 +520,7 @@ int vboxDomainGetMaxVcpus(virDomainPtr dom);
 char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags);
 int vboxConnectListDefinedDomains(virConnectPtr conn,
   char ** const names, int maxnames);
+int vboxConnectNumOfDefinedDomains(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 61/66] vbox: Rewrite vboxDomainSnapshotDelete

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|  609 
 src/vbox/vbox_common.h|   13 +
 src/vbox/vbox_tmpl.c  |  778 +
 src/vbox/vbox_uniformed_api.h |4 +
 4 files changed, 637 insertions(+), 767 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index f5b07cf..505f1cd 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6524,3 +6524,612 @@ int vboxDomainRevertToSnapshot(virDomainSnapshotPtr 
snapshot,
 vboxIIDUnalloc(domiid);
 return ret;
 }
+
+static int
+vboxDomainSnapshotDeleteSingle(vboxGlobalData *data,
+   IConsole *console,
+   ISnapshot *snapshot)
+{
+IProgress *progress = NULL;
+vboxIIDUnion iid;
+int ret = -1;
+nsresult rc;
+resultCodeUnion result;
+
+VBOX_IID_INITIALIZE(iid);
+rc = gVBoxAPI.UISnapshot.GetId(snapshot, iid);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(could not get snapshot UUID));
+goto cleanup;
+}
+
+rc = gVBoxAPI.UIConsole.DeleteSnapshot(console, iid, progress);
+if (NS_FAILED(rc) || !progress) {
+if (rc == VBOX_E_INVALID_VM_STATE) {
+virReportError(VIR_ERR_OPERATION_INVALID, %s,
+   _(cannot delete domain snapshot for running 
domain));
+} else {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(could not delete snapshot));
+}
+goto cleanup;
+}
+
+gVBoxAPI.UIProgress.WaitForCompletion(progress, -1);
+gVBoxAPI.UIProgress.GetResultCode(progress, result);
+if (RC_FAILED(result)) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(could not delete snapshot));
+goto cleanup;
+}
+
+ret = 0;
+
+ cleanup:
+VBOX_RELEASE(progress);
+vboxIIDUnalloc(iid);
+return ret;
+}
+
+static int
+vboxDomainSnapshotDeleteTree(vboxGlobalData *data,
+ IConsole *console,
+ ISnapshot *snapshot)
+{
+vboxArray children = VBOX_ARRAY_INITIALIZER;
+int ret = -1;
+nsresult rc;
+size_t i;
+
+rc = gVBoxAPI.UArray.vboxArrayGet(children, snapshot,
+  gVBoxAPI.UArray.handleSnapshotGetChildren(snapshot));
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(could not get children snapshots));
+goto cleanup;
+}
+
+for (i = 0; i  children.count; i++) {
+if (vboxDomainSnapshotDeleteTree(data, console, children.items[i]))
+goto cleanup;
+}
+
+ret = vboxDomainSnapshotDeleteSingle(data, console, snapshot);
+
+ cleanup:
+gVBoxAPI.UArray.vboxArrayRelease(children);
+return ret;
+}
+
+static int
+vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot)
+{
+/*
+ * This function will remove the node in the vbox xml corresponding to the 
snapshot.
+ * It is usually called by vboxDomainSnapshotDelete() with the flag
+ * VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY.
+ * If you want to use it anywhere else, be careful, if the snapshot you 
want to delete
+ * has children, the result is not granted, they will probably will be 
deleted in the
+ * xml, but you may have a problem with hard drives.
+ *
+ * If the snapshot which is being deleted is the current one, we will set 
the current
+ * snapshot of the machine to the parent of this snapshot. Before writing 
the modified
+ * xml file, we undefine the machine from vbox. After writing the file, we 
redefine
+ * the machine with the new file.
+ */
+
+virDomainPtr dom = snapshot-domain;
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+virDomainSnapshotDefPtr def= NULL;
+char *defXml = NULL;
+vboxIIDUnion domiid;
+nsresult rc;
+IMachine *machine = NULL;
+PRUnichar *settingsFilePathUtf16 = NULL;
+char *settingsFilepath = NULL;
+virVBoxSnapshotConfMachinePtr snapshotMachineDesc = NULL;
+int isCurrent = -1;
+int it = 0;
+PRUnichar *machineNameUtf16 = NULL;
+char *machineName = NULL;
+char *nameTmpUse = NULL;
+char *machineLocationPath = NULL;
+PRUint32 aMediaSize = 0;
+IMedium **aMedia = NULL;
+
+VBOX_IID_INITIALIZE(domiid);
+if (!gVBoxAPI.vboxSnapshotRedefine)
+VIR_WARN(This function may not work in current version);
+
+defXml = vboxDomainSnapshotGetXMLDesc(snapshot, 0);
+if (!defXml) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(Unable to get XML Desc of snapshot));
+goto cleanup;
+}
+def = virDomainSnapshotDefParseString(defXml,
+  data-caps,
+  data-xmlopt,
+  -1,
+  

[libvirt] [PATCH 60/66] vbox: Rewrite vboxDomainRevertToSnapshot

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   68 +++
 src/vbox/vbox_tmpl.c  |   80 ++---
 src/vbox/vbox_uniformed_api.h |3 ++
 3 files changed, 74 insertions(+), 77 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index dcd8ab8..f5b07cf 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6456,3 +6456,71 @@ int vboxDomainSnapshotHasMetadata(virDomainSnapshotPtr 
snapshot,
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
+   unsigned int flags)
+{
+virDomainPtr dom = snapshot-domain;
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxIIDUnion domiid;
+IMachine *machine = NULL;
+ISnapshot *newSnapshot = NULL;
+ISnapshot *prevSnapshot = NULL;
+PRBool online = PR_FALSE;
+PRUint32 state;
+nsresult rc;
+
+virCheckFlags(0, -1);
+
+if (openSessionForMachine(data, dom-uuid, domiid, machine, false)  0)
+goto cleanup;
+
+newSnapshot = vboxDomainSnapshotGet(data, dom, machine, snapshot-name);
+if (!newSnapshot)
+goto cleanup;
+
+rc = gVBoxAPI.UISnapshot.GetOnline(newSnapshot, online);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not get online state of snapshot %s),
+   snapshot-name);
+goto cleanup;
+}
+
+rc = gVBoxAPI.UIMachine.GetCurrentSnapshot(machine, prevSnapshot);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not get current snapshot of domain %s),
+   dom-name);
+goto cleanup;
+}
+
+rc = gVBoxAPI.UIMachine.GetState(machine, state);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(could not get domain state));
+goto cleanup;
+}
+
+if (gVBoxAPI.machineStateChecker.Online(state)) {
+virReportError(VIR_ERR_OPERATION_INVALID, %s,
+   _(cannot revert snapshot of running domain));
+goto cleanup;
+}
+
+if (gVBoxAPI.snapshotRestore(dom, machine, newSnapshot))
+goto cleanup;
+
+if (online) {
+ret = vboxDomainCreate(dom);
+if (!ret)
+gVBoxAPI.snapshotRestore(dom, machine, prevSnapshot);
+} else
+ret = 0;
+
+ cleanup:
+VBOX_RELEASE(prevSnapshot);
+VBOX_RELEASE(newSnapshot);
+vboxIIDUnalloc(domiid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 6d80a26..adba028 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1524,7 +1524,7 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
 
 #if VBOX_API_VERSION  3001000
 static int
-vboxDomainSnapshotRestore(virDomainPtr dom,
+_vboxDomainSnapshotRestore(virDomainPtr dom,
   IMachine *machine,
   ISnapshot *snapshot)
 {
@@ -1554,7 +1554,7 @@ vboxDomainSnapshotRestore(virDomainPtr dom,
 }
 #else
 static int
-vboxDomainSnapshotRestore(virDomainPtr dom,
+_vboxDomainSnapshotRestore(virDomainPtr dom,
   IMachine *machine,
   ISnapshot *snapshot)
 {
@@ -1630,81 +1630,6 @@ vboxDomainSnapshotRestore(virDomainPtr dom,
 #endif
 
 static int
-vboxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
-   unsigned int flags)
-{
-virDomainPtr dom = snapshot-domain;
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxIID domiid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-ISnapshot *newSnapshot = NULL;
-ISnapshot *prevSnapshot = NULL;
-PRBool online = PR_FALSE;
-PRUint32 state;
-nsresult rc;
-
-virCheckFlags(0, -1);
-
-vboxIIDFromUUID(domiid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(domiid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-newSnapshot = vboxDomainSnapshotGet(data, dom, machine, snapshot-name);
-if (!newSnapshot)
-goto cleanup;
-
-rc = newSnapshot-vtbl-GetOnline(newSnapshot, online);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(could not get online state of snapshot %s),
-   snapshot-name);
-goto cleanup;
-}
-
-rc = machine-vtbl-GetCurrentSnapshot(machine, prevSnapshot);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(could not get current snapshot of domain %s),
-   dom-name);
-goto cleanup;
-}
-
-rc = machine-vtbl-GetState(machine, state);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR, %s,
-   _(could not get domain state));
-goto cleanup;
-}
-
-if (state = 

[libvirt] [PATCH 44/66] vbox: Rewrite vboxDomainAttachDevice

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|  117 ++
 src/vbox/vbox_tmpl.c  |  141 +++--
 src/vbox/vbox_uniformed_api.h |3 +
 3 files changed, 256 insertions(+), 5 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 5b0706f..84d82d7 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -4038,3 +4038,120 @@ int vboxConnectNumOfDefinedDomains(virConnectPtr conn)
 gVBoxAPI.UArray.vboxArrayRelease(machines);
 return ret;
 }
+
+static int vboxDomainAttachDeviceImpl(virDomainPtr dom,
+  const char *xml,
+  int mediaChangeOnly ATTRIBUTE_UNUSED)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+PRUint32 state;
+virDomainDefPtr def  = NULL;
+virDomainDeviceDefPtr dev  = NULL;
+nsresult rc;
+
+VBOX_IID_INITIALIZE(iid);
+if (VIR_ALLOC(def)  0)
+return ret;
+
+if (VIR_STRDUP(def-os.type, hvm)  0)
+goto cleanup;
+
+dev = virDomainDeviceDefParse(xml, def, data-caps, data-xmlopt,
+  VIR_DOMAIN_XML_INACTIVE);
+if (dev == NULL)
+goto cleanup;
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!machine)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.Running(state) ||
+gVBoxAPI.machineStateChecker.Paused(state)) {
+rc = gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+} else {
+rc = gVBoxAPI.UISession.Open(data, iid, machine);
+}
+
+if (NS_FAILED(rc))
+goto cleanup;
+
+rc = gVBoxAPI.UISession.GetMachine(data-vboxSession, machine);
+
+if (NS_SUCCEEDED(rc)  machine) {
+/* ret = -VIR_ERR_ARGUMENT_UNSUPPORTED means the current device don't 
support hotplug. */
+ret = -VIR_ERR_ARGUMENT_UNSUPPORTED;
+if (dev-type == VIR_DOMAIN_DEVICE_DISK) {
+if (gVBoxAPI.oldMediumInterface) {
+const char *src = virDomainDiskGetSource(dev-data.disk);
+int type = virDomainDiskGetType(dev-data.disk);
+
+if (dev-data.disk-device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
+if (type == VIR_STORAGE_TYPE_FILE  src) {
+ret = gVBoxAPI.attachDVD(data, machine, src);
+} else if (type == VIR_STORAGE_TYPE_BLOCK) {
+}
+} else if (dev-data.disk-device == 
VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
+if (type == VIR_STORAGE_TYPE_FILE  src) {
+ret = gVBoxAPI.attachFloppy(data, machine, src);
+} else if (type == VIR_STORAGE_TYPE_BLOCK) {
+}
+}
+}
+} else if (dev-type == VIR_DOMAIN_DEVICE_NET) {
+} else if (dev-type == VIR_DOMAIN_DEVICE_HOSTDEV) {
+if (dev-data.hostdev-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
+if (dev-data.hostdev-source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
+}
+}
+} else if (dev-type == VIR_DOMAIN_DEVICE_FS 
+   dev-data.fs-type == VIR_DOMAIN_FS_TYPE_MOUNT) {
+PRUnichar *nameUtf16;
+PRUnichar *hostPathUtf16;
+PRBool writable;
+
+VBOX_UTF8_TO_UTF16(dev-data.fs-dst, nameUtf16);
+VBOX_UTF8_TO_UTF16(dev-data.fs-src, hostPathUtf16);
+writable = !dev-data.fs-readonly;
+
+rc = gVBoxAPI.UIMachine.CreateSharedFolder(machine, nameUtf16, 
hostPathUtf16,
+   writable, PR_FALSE);
+
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not attach shared folder '%s', 
rc=%08x),
+   dev-data.fs-dst, (unsigned)rc);
+ret = -1;
+} else {
+ret = 0;
+}
+
+VBOX_UTF16_FREE(nameUtf16);
+VBOX_UTF16_FREE(hostPathUtf16);
+}
+gVBoxAPI.UIMachine.SaveSettings(machine);
+VBOX_RELEASE(machine);
+
+if (ret == -VIR_ERR_ARGUMENT_UNSUPPORTED) {
+virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, _(Unsupported device 
type %d), dev-type);
+ret = -1;
+}
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+
+ cleanup:
+vboxIIDUnalloc(iid);
+virDomainDefFree(def);
+virDomainDeviceDefFree(dev);
+return ret;
+}
+
+int vboxDomainAttachDevice(virDomainPtr dom, const char *xml)
+{
+return vboxDomainAttachDeviceImpl(dom, xml, 0);
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 3651498..b80810d 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1649,11 +1649,6 @@ static 

Re: [libvirt] [PATCH libvirt 1/6] conf: add MTP filesystem support to the parser

2014-08-11 Thread Giuseppe Scrivano
Daniel P. Berrange berra...@redhat.com writes:

 On Thu, Aug 07, 2014 at 04:10:31PM +0200, Giuseppe Scrivano wrote:
 Signed-off-by: Giuseppe Scrivano gscri...@redhat.com
 ---
  src/conf/domain_conf.c | 34 +-
  src/conf/domain_conf.h |  1 +
  2 files changed, 26 insertions(+), 9 deletions(-)
 
 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
 index c25c74b..3bdf46a 100644
 --- a/src/conf/domain_conf.c
 +++ b/src/conf/domain_conf.c
 @@ -342,7 +342,8 @@ VIR_ENUM_IMPL(virDomainFS, VIR_DOMAIN_FS_TYPE_LAST,
file,
template,
ram,
 -  bind)
 +  bind,
 +  mtp)

 I don't think this is the right way to represent it.

 The 'type' attribute on filesystem represents where the backing store
 for the filesystem comes from.

 The distinction of 9p vs mtp reflects the type of guest device to expose
 it as.

 We shouldn't try to overload these two concepts in the same attribute.
 We should instead try to add a device or model child element as we
 have for some other device types.

I see, thanks for the clarification.

Would you agree with something like this?

   filesystem type='mount'
  device name=mtp sharemtp/device
   ...

Regards,
Giuseppe

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 63/66] vbox: Rewrite vboxConnectListAllDomains

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|  157 +
 src/vbox/vbox_tmpl.c  |  156 
 src/vbox/vbox_uniformed_api.h |2 +
 3 files changed, 159 insertions(+), 156 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index d3735ac..14f627f 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -7263,3 +7263,160 @@ vboxDomainScreenshot(virDomainPtr dom,
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+#define MATCH(FLAG) (flags  (FLAG))
+int
+vboxConnectListAllDomains(virConnectPtr conn,
+  virDomainPtr **domains,
+  unsigned int flags)
+{
+VBOX_OBJECT_CHECK(conn, int, -1);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+char  *machineNameUtf8  = NULL;
+PRUnichar *machineNameUtf16 = NULL;
+unsigned char uuid[VIR_UUID_BUFLEN];
+vboxIIDUnion iid;
+PRUint32 state;
+nsresult rc;
+size_t i;
+virDomainPtr dom;
+virDomainPtr *doms = NULL;
+int count = 0;
+bool active;
+PRUint32 snapshotCount;
+
+virCheckFlags(VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL, -1);
+
+/* filter out flag options that will produce 0 results in vbox driver:
+ * - managed save: vbox guests don't have managed save images
+ * - autostart: vbox doesn't support autostarting guests
+ * - persistance: vbox doesn't support transient guests
+ */
+if ((MATCH(VIR_CONNECT_LIST_DOMAINS_TRANSIENT) 
+ !MATCH(VIR_CONNECT_LIST_DOMAINS_PERSISTENT)) ||
+(MATCH(VIR_CONNECT_LIST_DOMAINS_AUTOSTART) 
+ !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART)) ||
+(MATCH(VIR_CONNECT_LIST_DOMAINS_MANAGEDSAVE) 
+ !MATCH(VIR_CONNECT_LIST_DOMAINS_NO_MANAGEDSAVE))) {
+if (domains 
+VIR_ALLOC_N(*domains, 1)  0)
+goto cleanup;
+
+ret = 0;
+goto cleanup;
+}
+
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of domains, rc=%08x), 
(unsigned)rc);
+goto cleanup;
+}
+
+if (domains 
+VIR_ALLOC_N(doms, machines.count + 1)  0)
+goto cleanup;
+
+for (i = 0; i  machines.count; i++) {
+IMachine *machine = machines.items[i];
+
+if (!machine)
+continue;
+
+PRBool isAccessible = PR_FALSE;
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+
+if (!isAccessible)
+continue;
+
+  gVBoxAPI.UIMachine.GetState(machine, state);
+
+  if (gVBoxAPI.machineStateChecker.Online(state))
+  active = true;
+  else
+  active = false;
+
+  /* filter by active state */
+  if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE) 
+  !((MATCH(VIR_CONNECT_LIST_DOMAINS_ACTIVE)  active) ||
+(MATCH(VIR_CONNECT_LIST_DOMAINS_INACTIVE)  !active)))
+  continue;
+
+  /* filter by snapshot existence */
+  if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT)) {
+  rc = gVBoxAPI.UIMachine.GetSnapshotCount(machine, snapshotCount);
+  if (NS_FAILED(rc)) {
+  virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+ _(could not get snapshot count for listed 
domains));
+  goto cleanup;
+  }
+  if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT) 
+ snapshotCount  0) ||
+(MATCH(VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) 
+ snapshotCount == 0)))
+  continue;
+  }
+
+  /* filter by machine state */
+  if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE) 
+  !((MATCH(VIR_CONNECT_LIST_DOMAINS_RUNNING) 
+ gVBoxAPI.machineStateChecker.Running(state)) ||
+(MATCH(VIR_CONNECT_LIST_DOMAINS_PAUSED) 
+ gVBoxAPI.machineStateChecker.Paused(state)) ||
+(MATCH(VIR_CONNECT_LIST_DOMAINS_SHUTOFF) 
+ gVBoxAPI.machineStateChecker.PoweredOff(state)) ||
+(MATCH(VIR_CONNECT_LIST_DOMAINS_OTHER) 
+ (!gVBoxAPI.machineStateChecker.Running(state) 
+  !gVBoxAPI.machineStateChecker.Paused(state) 
+  !gVBoxAPI.machineStateChecker.PoweredOff(state)
+  continue;
+
+  /* just count the machines */
+  if (!doms) {
+  count++;
+  continue;
+  }
+
+  gVBoxAPI.UIMachine.GetName(machine, machineNameUtf16);
+  VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
+  gVBoxAPI.UIMachine.GetId(machine, iid);
+  vboxIIDToUUID(iid, uuid);
+  vboxIIDUnalloc(iid);
+
+  dom = virGetDomain(conn, machineNameUtf8, uuid);
+
+  VBOX_UTF8_FREE(machineNameUtf8);
+  VBOX_UTF16_FREE(machineNameUtf16);
+
+  if (!dom)
+  goto cleanup;
+
+  if (active)
+  dom-id = i + 1;
+
+  doms[count++] = dom;

[libvirt] [PATCH 46/66] vbox: Rewrite vboxDomainUpdateDeviceFlags

2014-08-11 Thread Taowei
Since vboxDomainAttachDeviceImple not used in vbox_tmpl.c, it has
been deleted.
---
 src/vbox/vbox_common.c|   16 +++
 src/vbox/vbox_tmpl.c  |  215 -
 src/vbox/vbox_uniformed_api.h |2 +
 3 files changed, 18 insertions(+), 215 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index f22cb5b..71c97a0 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -4169,3 +4169,19 @@ int vboxDomainAttachDeviceFlags(virDomainPtr dom, const 
char *xml,
 
 return vboxDomainAttachDeviceImpl(dom, xml, 0);
 }
+
+int vboxDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
+unsigned int flags)
+{
+virCheckFlags(VIR_DOMAIN_AFFECT_CURRENT |
+  VIR_DOMAIN_AFFECT_LIVE |
+  VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+if (flags  VIR_DOMAIN_AFFECT_CONFIG) {
+virReportError(VIR_ERR_OPERATION_INVALID, %s,
+   _(cannot modify the persistent configuration of a 
domain));
+return -1;
+}
+
+return vboxDomainAttachDeviceImpl(dom, xml, 1);
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 5078f27..dd93e2a 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1450,221 +1450,6 @@ _vboxAttachDrivesOld(virDomainDefPtr def 
ATTRIBUTE_UNUSED,
 
 #endif /* VBOX_API_VERSION = 400 */
 
-static int vboxDomainAttachDeviceImpl(virDomainPtr dom,
-  const char *xml,
-  int mediaChangeOnly ATTRIBUTE_UNUSED)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-PRUint32 state   = MachineState_Null;
-virDomainDefPtr def  = NULL;
-virDomainDeviceDefPtr dev  = NULL;
-nsresult rc;
-
-if (VIR_ALLOC(def)  0)
-return ret;
-
-if (VIR_STRDUP(def-os.type, hvm)  0)
-goto cleanup;
-
-dev = virDomainDeviceDefParse(xml, def, data-caps, data-xmlopt,
-  VIR_DOMAIN_XML_INACTIVE);
-if (dev == NULL)
-goto cleanup;
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching uuid));
-goto cleanup;
-}
-
-if (machine) {
-machine-vtbl-GetState(machine, state);
-
-if ((state == MachineState_Running) ||
-(state == MachineState_Paused)) {
-rc = VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
-} else {
-rc = VBOX_SESSION_OPEN(iid.value, machine);
-}
-if (NS_SUCCEEDED(rc)) {
-rc = data-vboxSession-vtbl-GetMachine(data-vboxSession, 
machine);
-if (NS_SUCCEEDED(rc)  machine) {
-if (dev-type == VIR_DOMAIN_DEVICE_DISK) {
-#if VBOX_API_VERSION  3001000
-const char *src = virDomainDiskGetSource(dev-data.disk);
-int type = virDomainDiskGetType(dev-data.disk);
-
-if (dev-data.disk-device == 
VIR_DOMAIN_DISK_DEVICE_CDROM) {
-if (type == VIR_STORAGE_TYPE_FILE  src) {
-IDVDDrive *dvdDrive = NULL;
-/* Currently CDROM/DVD Drive is always IDE
- * Secondary Master so neglecting the following
- * parameter dev-data.disk-bus
- */
-machine-vtbl-GetDVDDrive(machine, dvdDrive);
-if (dvdDrive) {
-IDVDImage *dvdImage  = NULL;
-PRUnichar *dvdfileUtf16  = NULL;
-vboxIID dvduuid = VBOX_IID_INITIALIZER;
-vboxIID dvdemptyuuid = VBOX_IID_INITIALIZER;
-
-VBOX_UTF8_TO_UTF16(src, dvdfileUtf16);
-
-
data-vboxObj-vtbl-FindDVDImage(data-vboxObj, dvdfileUtf16, dvdImage);
-if (!dvdImage) {
-
data-vboxObj-vtbl-OpenDVDImage(data-vboxObj, dvdfileUtf16, 
dvdemptyuuid.value, dvdImage);
-}
-if (dvdImage) {
-rc = 
dvdImage-vtbl-imedium.GetId((IMedium *)dvdImage, dvduuid.value);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(can't get the uuid 
of the file to 
- be attached to 
cdrom: %s, rc=%08x),
-   src, (unsigned)rc);
-} else {
- 

[libvirt] [PATCH 55/66] vbox: Rewrite vboxDomainHasCurrentSnapshot

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   32 
 src/vbox/vbox_tmpl.c  |   38 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 33 insertions(+), 38 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 5178cda..cb6ba78 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6226,3 +6226,35 @@ vboxDomainSnapshotLookupByName(virDomainPtr dom, const 
char *name,
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainHasCurrentSnapshot(virDomainPtr dom,
+ unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+ISnapshot *snapshot = NULL;
+nsresult rc;
+
+virCheckFlags(0, -1);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+rc = gVBoxAPI.UIMachine.GetCurrentSnapshot(machine, snapshot);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(could not get current snapshot));
+goto cleanup;
+}
+
+if (snapshot)
+ret = 1;
+else
+ret = 0;
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 5aef7dd..73b3fc3 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1522,44 +1522,6 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
 return snapshot;
 }
 
-static int
-vboxDomainHasCurrentSnapshot(virDomainPtr dom,
- unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxIID iid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-ISnapshot *snapshot = NULL;
-nsresult rc;
-
-virCheckFlags(0, -1);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-rc = machine-vtbl-GetCurrentSnapshot(machine, snapshot);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR, %s,
-   _(could not get current snapshot));
-goto cleanup;
-}
-
-if (snapshot)
-ret = 1;
-else
-ret = 0;
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static virDomainSnapshotPtr
 vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
 unsigned int flags)
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index afbc351..d91e970 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -583,6 +583,7 @@ int vboxDomainSnapshotListNames(virDomainPtr dom, char 
**names,
 virDomainSnapshotPtr
 vboxDomainSnapshotLookupByName(virDomainPtr dom, const char *name,
unsigned int flags);
+int vboxDomainHasCurrentSnapshot(virDomainPtr dom, unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 50/66] vbox: Rewrite vboxDomainSnapshotCreateXML

2014-08-11 Thread Taowei
The vboxDomainSnapshotCreateXML integrated the snapshot redefine
with this patch:
http://www.redhat.com/archives/libvir-list/2014-May/msg00589.html
This patch introduced vboxSnapshotRedefine in vboxUniformedAPI to
enable the features.

This patch replace all version specified APIs to the uniformed api,
then, moving the whole implementation to vbox_common.c. As there
is only API level changes, the behavior of the function doesn't
change.

Some old version's defects has brought to the new one. The already
known things are:
*goto cleanup in a loop without releasing the pointers in the
loop.
*When function failed after machine unregister, no roll back
to recovery it and the virtual machine would disappear.
---
 src/vbox/vbox_common.c| 1069 
 src/vbox/vbox_common.h|   18 +
 src/vbox/vbox_tmpl.c  | 1087 -
 src/vbox/vbox_uniformed_api.h |5 +
 4 files changed, 1092 insertions(+), 1087 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 4e0b990..8f3fe03 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -28,6 +28,10 @@
 #include viralloc.h
 #include nodeinfo.h
 #include virstring.h
+#include virfile.h
+#include virtime.h
+#include snapshot_conf.h
+#include vbox_snapshot_conf.h
 
 #include vbox_common.h
 #include vbox_uniformed_api.h
@@ -4300,3 +4304,1068 @@ int vboxDomainDetachDeviceFlags(virDomainPtr dom, 
const char *xml,
 
 return vboxDomainDetachDevice(dom, xml);
 }
+
+static int vboxCloseDisksRecursively(virDomainPtr dom, char *location)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+nsresult rc;
+size_t i = 0;
+PRUnichar *locationUtf = NULL;
+IMedium *medium = NULL;
+IMedium **children = NULL;
+PRUint32 childrenSize = 0;
+
+if (!gVBoxAPI.vboxSnapshotRedefine)
+VIR_WARN(This function may not work in current version);
+
+VBOX_UTF8_TO_UTF16(location, locationUtf);
+rc = gVBoxAPI.UIVirtualBox.OpenMedium(data-vboxObj,
+  locationUtf,
+  DeviceType_HardDisk,
+  AccessMode_ReadWrite,
+  medium);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Unable to open HardDisk, rc=%08x),
+   (unsigned)rc);
+goto cleanup;
+}
+rc = gVBoxAPI.UIMedium.GetChildren(medium, childrenSize, children);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s
+   , _(Unable to get disk children));
+goto cleanup;
+}
+for (i = 0; i  childrenSize; i++) {
+IMedium *childMedium = children[i];
+if (childMedium) {
+PRUnichar *childLocationUtf = NULL;
+char *childLocation = NULL;
+rc = gVBoxAPI.UIMedium.GetLocation(childMedium, childLocationUtf);
+VBOX_UTF16_TO_UTF8(childLocationUtf, childLocation);
+VBOX_UTF16_FREE(childLocationUtf);
+if (vboxCloseDisksRecursively(dom, childLocation)  0) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s
+   , _(Unable to close disk children));
+goto cleanup;
+}
+VIR_FREE(childLocation);
+}
+}
+rc = gVBoxAPI.UIMedium.Close(medium);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Unable to close HardDisk, rc=%08x),
+   (unsigned)rc);
+goto cleanup;
+}
+
+ret = 0;
+ cleanup:
+VBOX_UTF16_FREE(locationUtf);
+return ret;
+}
+
+static int
+vboxSnapshotRedefine(virDomainPtr dom,
+ virDomainSnapshotDefPtr def,
+ bool isCurrent)
+{
+/*
+ * If your snapshot has a parent,
+ * it will only be redefined if you have already
+ * redefined the parent.
+ *
+ * The general algorithm of this function is below :
+ * First of all, we are going to create our vboxSnapshotXmlMachinePtr 
struct from
+ * the machine settings path.
+ * Then, if the machine current snapshot xml file is saved in the machine 
location,
+ * it means that this snapshot was previously modified by us and has fake 
disks.
+ * Fake disks are added when the flag VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT 
was not set
+ * yet, in order to not corrupt read-only disks. The first thing to do is 
to remove those
+ * disks and restore the read-write disks, if any, in the 
vboxSnapshotXmlMachinePtr struct.
+ * We also delete the current snapshot xml file.
+ *
+ * After that, we are going to register the snapshot read-only disks that 
we want to redefine,
+ * if they are not in the media registry struct.
+ *
+ * The next step is to unregister the machine and close all disks.
+ 

[libvirt] [PATCH 57/66] vbox: Rewrite vboxDomainSnapshotCurrent

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   53 
 src/vbox/vbox_tmpl.c  |   59 -
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 55 insertions(+), 59 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 04e6c2c..32cbe60 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -6319,3 +6319,56 @@ vboxDomainSnapshotGetParent(virDomainSnapshotPtr 
snapshot,
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+virDomainSnapshotPtr
+vboxDomainSnapshotCurrent(virDomainPtr dom, unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, virDomainSnapshotPtr, NULL);
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+ISnapshot *snapshot = NULL;
+PRUnichar *nameUtf16 = NULL;
+char *name = NULL;
+nsresult rc;
+
+virCheckFlags(0, NULL);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+rc = gVBoxAPI.UIMachine.GetCurrentSnapshot(machine, snapshot);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(could not get current snapshot));
+goto cleanup;
+}
+
+if (!snapshot) {
+virReportError(VIR_ERR_OPERATION_INVALID, %s,
+   _(domain has no snapshots));
+goto cleanup;
+}
+
+rc = gVBoxAPI.UISnapshot.GetName(snapshot, nameUtf16);
+if (NS_FAILED(rc) || !nameUtf16) {
+virReportError(VIR_ERR_INTERNAL_ERROR, %s,
+   _(could not get current snapshot name));
+goto cleanup;
+}
+
+VBOX_UTF16_TO_UTF8(nameUtf16, name);
+if (!name) {
+virReportOOMError();
+goto cleanup;
+}
+
+ret = virGetDomainSnapshot(dom, name);
+
+ cleanup:
+VBOX_UTF8_FREE(name);
+VBOX_UTF16_FREE(nameUtf16);
+VBOX_RELEASE(snapshot);
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index d5df286..87200f1 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1522,65 +1522,6 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
 return snapshot;
 }
 
-static virDomainSnapshotPtr
-vboxDomainSnapshotCurrent(virDomainPtr dom,
-  unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, virDomainSnapshotPtr, NULL);
-vboxIID iid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-ISnapshot *snapshot = NULL;
-PRUnichar *nameUtf16 = NULL;
-char *name = NULL;
-nsresult rc;
-
-virCheckFlags(0, NULL);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-rc = machine-vtbl-GetCurrentSnapshot(machine, snapshot);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR, %s,
-   _(could not get current snapshot));
-goto cleanup;
-}
-
-if (!snapshot) {
-virReportError(VIR_ERR_OPERATION_INVALID, %s,
-   _(domain has no snapshots));
-goto cleanup;
-}
-
-rc = snapshot-vtbl-GetName(snapshot, nameUtf16);
-if (NS_FAILED(rc) || !nameUtf16) {
-virReportError(VIR_ERR_INTERNAL_ERROR, %s,
-   _(could not get current snapshot name));
-goto cleanup;
-}
-
-VBOX_UTF16_TO_UTF8(nameUtf16, name);
-if (!name) {
-virReportOOMError();
-goto cleanup;
-}
-
-ret = virGetDomainSnapshot(dom, name);
-
- cleanup:
-VBOX_UTF8_FREE(name);
-VBOX_UTF16_FREE(nameUtf16);
-VBOX_RELEASE(snapshot);
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static int
 vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot,
 unsigned int flags)
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 978da5e..c320ac2 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -587,6 +587,8 @@ int vboxDomainHasCurrentSnapshot(virDomainPtr dom, unsigned 
int flags);
 virDomainSnapshotPtr
 vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot,
 unsigned int flags);
+virDomainSnapshotPtr
+vboxDomainSnapshotCurrent(virDomainPtr dom, unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 62/66] vbox: Rewrite vboxDomainScreenshot

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|  130 
 src/vbox/vbox_common.h|1 +
 src/vbox/vbox_tmpl.c  |  190 -
 src/vbox/vbox_uniformed_api.h |   23 -
 4 files changed, 208 insertions(+), 136 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 505f1cd..d3735ac 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -19,6 +19,7 @@
 #include config.h
 
 #include unistd.h
+#include fcntl.h
 
 #include internal.h
 #include datatypes.h
@@ -32,6 +33,8 @@
 #include virtime.h
 #include snapshot_conf.h
 #include vbox_snapshot_conf.h
+#include fdstream.h
+#include configmake.h
 
 #include vbox_common.h
 #include vbox_uniformed_api.h
@@ -7133,3 +7136,130 @@ int vboxDomainSnapshotDelete(virDomainSnapshotPtr 
snapshot,
 gVBoxAPI.UISession.Close(data-vboxSession);
 return ret;
 }
+
+char *
+vboxDomainScreenshot(virDomainPtr dom,
+ virStreamPtr st,
+ unsigned int screen,
+ unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, char *, NULL);
+IConsole *console = NULL;
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+nsresult rc;
+char *tmp;
+int tmp_fd = -1;
+unsigned int max_screen;
+
+if (!gVBoxAPI.supportScreenshot) {
+virReportError(VIR_ERR_NO_SUPPORT, %s,
+   _(virDomainScreenshot don't support for current vbox 
version));
+return NULL;
+}
+
+virCheckFlags(0, NULL);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+return NULL;
+
+rc = gVBoxAPI.UIMachine.GetMonitorCount(machine, max_screen);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(unable to get monitor count));
+VBOX_RELEASE(machine);
+return NULL;
+}
+
+if (screen = max_screen) {
+virReportError(VIR_ERR_INVALID_ARG,
+   _(screen ID higher than monitor 
+ count (%d)), max_screen);
+VBOX_RELEASE(machine);
+return NULL;
+}
+
+if (virAsprintf(tmp, %s/cache/libvirt/vbox.screendump.XX, 
LOCALSTATEDIR)  0) {
+VBOX_RELEASE(machine);
+return NULL;
+}
+
+if ((tmp_fd = mkostemp(tmp, O_CLOEXEC)) == -1) {
+virReportSystemError(errno, _(mkostemp(\%s\) failed), tmp);
+VIR_FREE(tmp);
+VBOX_RELEASE(machine);
+return NULL;
+}
+
+
+rc = gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+if (NS_SUCCEEDED(rc)) {
+rc = gVBoxAPI.UISession.GetConsole(data-vboxSession, console);
+if (NS_SUCCEEDED(rc)  console) {
+IDisplay *display = NULL;
+
+gVBoxAPI.UIConsole.GetDisplay(console, display);
+
+if (display) {
+PRUint32 width, height, bitsPerPixel;
+PRUint32 screenDataSize;
+PRUint8 *screenData;
+PRInt32 xOrigin, yOrigin;
+
+rc = gVBoxAPI.UIDisplay.GetScreenResolution(display, screen,
+width, height,
+bitsPerPixel,
+xOrigin, 
yOrigin);
+
+if (NS_FAILED(rc) || !width || !height) {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(unable to get screen resolution));
+goto endjob;
+}
+
+rc = gVBoxAPI.UIDisplay.TakeScreenShotPNGToArray(display, 
screen,
+ width, height,
+ 
screenDataSize,
+ screenData);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(failed to take screenshot));
+goto endjob;
+}
+
+if (safewrite(tmp_fd, (char *) screenData,
+  screenDataSize)  0) {
+virReportSystemError(errno, _(unable to write data 
+  to '%s'), tmp);
+goto endjob;
+}
+
+if (VIR_CLOSE(tmp_fd)  0) {
+virReportSystemError(errno, _(unable to close %s), tmp);
+goto endjob;
+}
+
+if (VIR_STRDUP(ret, image/png)  0)
+goto endjob;
+
+if (virFDStreamOpenFile(st, tmp, 0, 0, O_RDONLY)  0) {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(unable to open stream));
+VIR_FREE(ret);
+}
+ 

[libvirt] [PATCH v2] Include param.h in case of HAVE_BSD_CPU_AFFINITY

2014-08-11 Thread Guido Günther
This fixes compilation on kFreeBSD which otherwise fails like

  CC   util/libvirt_util_la-virprocess.lo
In file included from /usr/include/sys/cpuset.h:35:0,
 from util/virprocess.c:43:
/usr/include/sys/_cpuset.h:49:43: error: 'NBBY' undeclared here (not in
a function)
  long __bits[howmany(CPU_SETSIZE, _NCPUBITS)];
   ^
In file included from util/virprocess.c:43:0:
/usr/include/sys/cpuset.h:215:12: error: unknown type name 'cpusetid_t'
 int cpuset(cpusetid_t *);
^
/usr/include/sys/cpuset.h:216:30: error: expected ')' before 'id_t'
 int cpuset_setid(cpuwhich_t, id_t, cpusetid_t);
  ^
/usr/include/sys/cpuset.h:217:42: error: expected ')' before 'id_t'
 int cpuset_getid(cpulevel_t, cpuwhich_t, id_t, cpusetid_t *);
  ^
/usr/include/sys/cpuset.h:218:48: error: expected ')' before 'id_t'
 int cpuset_getaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, cpuset_t
*);
^
/usr/include/sys/cpuset.h:219:48: error: expected ')' before 'id_t'
 int cpuset_setaffinity(cpulevel_t, cpuwhich_t, id_t, size_t, const
cpuset_t *);

And it's the correct usage as documented in

  http://www.freebsd.org/cgi/man.cgi?query=cpuset_setid

Also change the #ifdef HAVE_BSH_CPU_AFFINITY to #if for consistency.
---

The previous version inluded sys/param.h twice causing make
syntax-check to fail.
 -- Guido

 src/util/virprocess.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 9179d73..97cce4f 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -33,13 +33,16 @@
 #endif
 #include sched.h
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || HAVE_BSD_CPU_AFFINITY
 # include sys/param.h
+#endif
+
+#ifdef  __FreeBSD__
 # include sys/sysctl.h
 # include sys/user.h
 #endif
 
-#ifdef HAVE_BSD_CPU_AFFINITY
+#if HAVE_BSD_CPU_AFFINITY
 # include sys/cpuset.h
 #endif
 
-- 
2.0.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 66/66] vbox: Introducing vboxCommonDriver

2014-08-11 Thread Taowei
After this patch, we will have only one common domain driver.
So, the rewritten on domain driver is finished in this patch.
---
 src/vbox/README   |7 +-
 src/vbox/vbox_common.c|  257 +++--
 src/vbox/vbox_driver.c|   28 ++---
 src/vbox/vbox_tmpl.c  |   80 -
 src/vbox/vbox_uniformed_api.h |  103 -
 5 files changed, 186 insertions(+), 289 deletions(-)

diff --git a/src/vbox/README b/src/vbox/README
index 6e88ae6..0551db9 100644
--- a/src/vbox/README
+++ b/src/vbox/README
@@ -37,7 +37,12 @@ The file which has version dependent changes and includes 
the template
 file for given below for all of its functionality.
 
 vbox_tmpl.c
-The file where all the real driver implementation code exists.
+The file contains all version specified codes. It implements the
+vboxUniformedAPI for each vbox version.
+
+vbox_common.c
+The file implement the common driver, with the uniformed api which
+defined in vbox_uniformed_api.h and implemented in vbox_tmpl.c
 
 Now there would be a vbox_V*.c file (for eg: vbox_V2_2.c for V2.2) for
 each major virtualbox version which would do some preprocessor magic
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index c05fd6a..edd3eef 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -121,6 +121,9 @@ if (!data-vboxObj) {\
 /* global vbox API, used for all common codes. */
 static vboxUniformedAPI gVBoxAPI;
 
+/* update the virDriver according to the vboxUniformedAPI */
+static void updateDriver(void);
+
 int vboxRegisterUniformedAPI(uint32_t uVersion)
 {
 /* Install gVBoxAPI according to the vbox API version.
@@ -149,6 +152,7 @@ int vboxRegisterUniformedAPI(uint32_t uVersion)
 } else {
 return -1;
 }
+updateDriver();
 return 0;
 }
 
@@ -461,9 +465,10 @@ static void vboxUninitialize(vboxGlobalData *data)
 VIR_FREE(data);
 }
 
-virDrvOpenStatus vboxConnectOpen(virConnectPtr conn,
- virConnectAuthPtr auth ATTRIBUTE_UNUSED,
- unsigned int flags)
+static virDrvOpenStatus
+vboxConnectOpen(virConnectPtr conn,
+virConnectAuthPtr auth ATTRIBUTE_UNUSED,
+unsigned int flags)
 {
 vboxGlobalData *data = NULL;
 uid_t uid = geteuid();
@@ -532,7 +537,7 @@ virDrvOpenStatus vboxConnectOpen(virConnectPtr conn,
 return VIR_DRV_OPEN_SUCCESS;
 }
 
-int vboxConnectClose(virConnectPtr conn)
+static int vboxConnectClose(virConnectPtr conn)
 {
 vboxGlobalData *data = conn-privateData;
 VIR_DEBUG(%s: in vboxClose, conn-driver-name);
@@ -543,7 +548,7 @@ int vboxConnectClose(virConnectPtr conn)
 return 0;
 }
 
-int
+static int
 vboxDomainSave(virDomainPtr dom, const char *path ATTRIBUTE_UNUSED)
 {
 VBOX_OBJECT_CHECK(dom-conn, int, -1);
@@ -604,7 +609,7 @@ static void vboxDriverUnlock(vboxGlobalData *data)
 virMutexUnlock(data-lock);
 }
 
-int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version)
+static int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version)
 {
 vboxGlobalData *data = conn-privateData;
 VIR_DEBUG(%s: in vboxGetVersion, conn-driver-name);
@@ -616,29 +621,29 @@ int vboxConnectGetVersion(virConnectPtr conn, unsigned 
long *version)
 return 0;
 }
 
-char *vboxConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+static char *vboxConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 return virGetHostname();
 }
 
-int vboxConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
+static int vboxConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 /* Driver is using local, non-network based transport */
 return 1;
 }
 
-int vboxConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
+static int vboxConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 /* No encryption is needed, or used on the local transport*/
 return 0;
 }
 
-int vboxConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+static int vboxConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 return 1;
 }
 
-int
+static int
 vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED)
 {
 VBOX_OBJECT_CHECK(conn, int, -1);
@@ -662,7 +667,7 @@ vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type 
ATTRIBUTE_UNUSED)
 return ret;
 }
 
-char *vboxConnectGetCapabilities(virConnectPtr conn)
+static char *vboxConnectGetCapabilities(virConnectPtr conn)
 {
 VBOX_OBJECT_CHECK(conn, char *, NULL);
 
@@ -673,7 +678,7 @@ char *vboxConnectGetCapabilities(virConnectPtr conn)
 return ret;
 }
 
-int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
+static int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
 {
 VBOX_OBJECT_CHECK(conn, int, -1);
 vboxArray machines = VBOX_ARRAY_INITIALIZER;
@@ -711,7 +716,7 @@ int vboxConnectListDomains(virConnectPtr conn, int *ids, 
int nids)
 return ret;
 }
 
-int 

[libvirt] [PATCH 47/66] vbox: Rewrite vboxDomainDetachDevice

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|  101 +++
 src/vbox/vbox_tmpl.c  |  221 -
 src/vbox/vbox_uniformed_api.h |4 +
 3 files changed, 190 insertions(+), 136 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 71c97a0..f6ea357 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -4185,3 +4185,104 @@ int vboxDomainUpdateDeviceFlags(virDomainPtr dom, const 
char *xml,
 
 return vboxDomainAttachDeviceImpl(dom, xml, 1);
 }
+
+int vboxDomainDetachDevice(virDomainPtr dom, const char *xml)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+PRUint32 state;
+virDomainDefPtr def  = NULL;
+virDomainDeviceDefPtr dev  = NULL;
+nsresult rc;
+
+VBOX_IID_INITIALIZE(iid);
+if (VIR_ALLOC(def)  0)
+return ret;
+
+if (VIR_STRDUP(def-os.type, hvm)  0)
+goto cleanup;
+
+dev = virDomainDeviceDefParse(xml, def, data-caps, data-xmlopt,
+  VIR_DOMAIN_XML_INACTIVE);
+if (dev == NULL)
+goto cleanup;
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!machine)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.Running(state) ||
+gVBoxAPI.machineStateChecker.Paused(state)) {
+rc = gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+} else {
+rc = gVBoxAPI.UISession.Open(data, iid, machine);
+}
+
+if (NS_FAILED(rc))
+goto cleanup;
+
+rc = gVBoxAPI.UISession.GetMachine(data-vboxSession, machine);
+if (NS_SUCCEEDED(rc)  machine) {
+/* ret = -VIR_ERR_ARGUMENT_UNSUPPORTED means the current device don't 
support hotplug. */
+ret = -VIR_ERR_ARGUMENT_UNSUPPORTED;
+if (dev-type == VIR_DOMAIN_DEVICE_DISK) {
+if (gVBoxAPI.oldMediumInterface) {
+int type = virDomainDiskGetType(dev-data.disk);
+
+if (dev-data.disk-device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
+if (type == VIR_STORAGE_TYPE_FILE) {
+ret = gVBoxAPI.detachDVD(machine);
+} else if (type == VIR_STORAGE_TYPE_BLOCK) {
+}
+} else if (dev-data.disk-device == 
VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
+if (type == VIR_STORAGE_TYPE_FILE) {
+ret = gVBoxAPI.detachFloppy(machine);
+} else if (type == VIR_STORAGE_TYPE_BLOCK) {
+}
+}
+}
+} else if (dev-type == VIR_DOMAIN_DEVICE_NET) {
+} else if (dev-type == VIR_DOMAIN_DEVICE_HOSTDEV) {
+if (dev-data.hostdev-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
+if (dev-data.hostdev-source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
+}
+}
+} else if (dev-type == VIR_DOMAIN_DEVICE_FS 
+   dev-data.fs-type == VIR_DOMAIN_FS_TYPE_MOUNT) {
+PRUnichar *nameUtf16;
+
+VBOX_UTF8_TO_UTF16(dev-data.fs-dst, nameUtf16);
+
+rc = gVBoxAPI.UIMachine.RemoveSharedFolder(machine, nameUtf16);
+
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not detach shared folder '%s', 
rc=%08x),
+   dev-data.fs-dst, (unsigned)rc);
+} else {
+ret = 0;
+}
+
+VBOX_UTF16_FREE(nameUtf16);
+}
+gVBoxAPI.UIMachine.SaveSettings(machine);
+VBOX_RELEASE(machine);
+
+if (ret == -VIR_ERR_ARGUMENT_UNSUPPORTED) {
+virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, _(Unsupported device 
type %d), dev-type);
+ret = -1;
+}
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+
+ cleanup:
+vboxIIDUnalloc(iid);
+virDomainDefFree(def);
+virDomainDeviceDefFree(dev);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index dd93e2a..65f2d34 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1450,142 +1450,6 @@ _vboxAttachDrivesOld(virDomainDefPtr def 
ATTRIBUTE_UNUSED,
 
 #endif /* VBOX_API_VERSION = 400 */
 
-static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-PRUint32 state   = MachineState_Null;
-virDomainDefPtr def  = NULL;
-virDomainDeviceDefPtr dev  = NULL;
-nsresult rc;
-
-if (VIR_ALLOC(def)  0)
-return ret;
-
-if (VIR_STRDUP(def-os.type, hvm)  0)
-goto cleanup;
-
-dev = virDomainDeviceDefParse(xml, def, data-caps, data-xmlopt,
-  VIR_DOMAIN_XML_INACTIVE);
-if (dev == NULL)
-goto 

[libvirt] [PATCH 64/66] vbox: Rewrite vboxNode functions

2014-08-11 Thread Taowei
Four functions are rewrite in this patch, that is:
vboxNodeGetInfo
vboxNodeGetCellsFreeMemory
vboxNodeGetFreeMemory
vboxNodeGetFreePages
Since these functions has nothing to do with vbox,
it can be directly moved to vbox_common.c. So, I
merged these things into one patch.
---
 src/vbox/vbox_common.c|   39 ++
 src/vbox/vbox_tmpl.c  |   42 -
 src/vbox/vbox_uniformed_api.h |   13 +
 3 files changed, 52 insertions(+), 42 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 14f627f..c05fd6a 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -7420,3 +7420,42 @@ vboxConnectListAllDomains(virConnectPtr conn,
 return ret;
 }
 #undef MATCH
+
+int
+vboxNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED,
+virNodeInfoPtr nodeinfo)
+{
+return nodeGetInfo(nodeinfo);
+}
+
+int
+vboxNodeGetCellsFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED,
+   unsigned long long *freeMems,
+   int startCell,
+   int maxCells)
+{
+return nodeGetCellsFreeMemory(freeMems, startCell, maxCells);
+}
+
+unsigned long long
+vboxNodeGetFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+unsigned long long freeMem;
+if (nodeGetMemory(NULL, freeMem)  0)
+return 0;
+return freeMem;
+}
+
+int
+vboxNodeGetFreePages(virConnectPtr conn ATTRIBUTE_UNUSED,
+ unsigned int npages,
+ unsigned int *pages,
+ int startCell,
+ unsigned int cellCount,
+ unsigned long long *counts,
+ unsigned int flags)
+{
+virCheckFlags(0, -1);
+
+return nodeGetFreePages(npages, pages, startCell, cellCount, counts);
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 55ccbc7..72d4c4d 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -3732,48 +3732,6 @@ static char *vboxStorageVolGetPath(virStorageVolPtr vol) 
{
 return ret;
 }
 
-static int
-vboxNodeGetInfo(virConnectPtr conn ATTRIBUTE_UNUSED,
-virNodeInfoPtr nodeinfo)
-{
-return nodeGetInfo(nodeinfo);
-}
-
-
-static int
-vboxNodeGetCellsFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED,
-   unsigned long long *freeMems,
-   int startCell,
-   int maxCells)
-{
-return nodeGetCellsFreeMemory(freeMems, startCell, maxCells);
-}
-
-
-static unsigned long long
-vboxNodeGetFreeMemory(virConnectPtr conn ATTRIBUTE_UNUSED)
-{
-unsigned long long freeMem;
-if (nodeGetMemory(NULL, freeMem)  0)
-return 0;
-return freeMem;
-}
-
-
-static int
-vboxNodeGetFreePages(virConnectPtr conn ATTRIBUTE_UNUSED,
- unsigned int npages,
- unsigned int *pages,
- int startCell,
- unsigned int cellCount,
- unsigned long long *counts,
- unsigned int flags)
-{
-virCheckFlags(0, -1);
-
-return nodeGetFreePages(npages, pages, startCell, cellCount, counts);
-}
-
 static int _pfnInitialize(vboxGlobalData *data)
 {
 data-pFuncs = g_pfnGetFunctions(VBOX_XPCOMC_VERSION);
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index c105a07..a868ac0 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -623,6 +623,19 @@ char *vboxDomainScreenshot(virDomainPtr dom, virStreamPtr 
st,
unsigned int screen, unsigned int flags);
 int vboxConnectListAllDomains(virConnectPtr conn, virDomainPtr **domains,
   unsigned int flags);
+int vboxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo);
+int vboxNodeGetCellsFreeMemory(virConnectPtr conn,
+   unsigned long long *freeMems,
+   int startCell,
+   int maxCells);
+unsigned long long vboxNodeGetFreeMemory(virConnectPtr);
+int vboxNodeGetFreePages(virConnectPtr conn,
+ unsigned int npages,
+ unsigned int *pages,
+ int startCell,
+ unsigned int cellCount,
+ unsigned long long *counts,
+ unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 48/66] vbox: Rewrite vboxDomainDetachDeviceFlags

2014-08-11 Thread Taowei
---
 src/vbox/vbox_common.c|   14 ++
 src/vbox/vbox_tmpl.c  |   15 ---
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index f6ea357..4e0b990 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -4286,3 +4286,17 @@ int vboxDomainDetachDevice(virDomainPtr dom, const char 
*xml)
 virDomainDeviceDefFree(dev);
 return ret;
 }
+
+int vboxDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
+unsigned int flags)
+{
+virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+if (flags  VIR_DOMAIN_AFFECT_CONFIG) {
+virReportError(VIR_ERR_OPERATION_INVALID, %s,
+   _(cannot modify the persistent configuration of a 
domain));
+return -1;
+}
+
+return vboxDomainDetachDevice(dom, xml);
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 65f2d34..eeebd6f 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -1451,21 +1451,6 @@ _vboxAttachDrivesOld(virDomainDefPtr def 
ATTRIBUTE_UNUSED,
 #endif /* VBOX_API_VERSION = 400 */
 
 static int
-vboxDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
-unsigned int flags)
-{
-virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG, -1);
-
-if (flags  VIR_DOMAIN_AFFECT_CONFIG) {
-virReportError(VIR_ERR_OPERATION_INVALID, %s,
-   _(cannot modify the persistent configuration of a 
domain));
-return -1;
-}
-
-return vboxDomainDetachDevice(dom, xml);
-}
-
-static int
 vboxDomainSnapshotGetAll(virDomainPtr dom,
  IMachine *machine,
  ISnapshot ***snapshots)
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 357590c..48c2973 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -533,6 +533,8 @@ int vboxDomainAttachDeviceFlags(virDomainPtr dom, const 
char *xml,
 int vboxDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
 unsigned int flags);
 int vboxDomainDetachDevice(virDomainPtr dom, const char *xml);
+int vboxDomainDetachDeviceFlags(virDomainPtr dom, const char *xml,
+unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH libvirt 1/6] conf: add MTP filesystem support to the parser

2014-08-11 Thread Daniel P. Berrange
On Mon, Aug 11, 2014 at 12:15:41PM +0200, Giuseppe Scrivano wrote:
 Daniel P. Berrange berra...@redhat.com writes:
 
  On Thu, Aug 07, 2014 at 04:10:31PM +0200, Giuseppe Scrivano wrote:
  Signed-off-by: Giuseppe Scrivano gscri...@redhat.com
  ---
   src/conf/domain_conf.c | 34 +-
   src/conf/domain_conf.h |  1 +
   2 files changed, 26 insertions(+), 9 deletions(-)
  
  diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
  index c25c74b..3bdf46a 100644
  --- a/src/conf/domain_conf.c
  +++ b/src/conf/domain_conf.c
  @@ -342,7 +342,8 @@ VIR_ENUM_IMPL(virDomainFS, VIR_DOMAIN_FS_TYPE_LAST,
 file,
 template,
 ram,
  -  bind)
  +  bind,
  +  mtp)
 
  I don't think this is the right way to represent it.
 
  The 'type' attribute on filesystem represents where the backing store
  for the filesystem comes from.
 
  The distinction of 9p vs mtp reflects the type of guest device to expose
  it as.
 
  We shouldn't try to overload these two concepts in the same attribute.
  We should instead try to add a device or model child element as we
  have for some other device types.
 
 I see, thanks for the clarification.
 
 Would you agree with something like this?
 
filesystem type='mount'
   device name=mtp sharemtp/device
...

What is the name=mtp share bit trying to reflect ?

It seems we're mostly biased towards model so I think we should aim
for  model type='mtp|9p'/

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH libvirt 1/6] conf: add MTP filesystem support to the parser

2014-08-11 Thread Giuseppe Scrivano
Daniel P. Berrange berra...@redhat.com writes:

 Would you agree with something like this?
 
filesystem type='mount'
   device name=mtp sharemtp/device
...

 What is the name=mtp share bit trying to reflect ?

 It seems we're mostly biased towards model so I think we should aim
 for  model type='mtp|9p'/

it is the name of the MTP share within the guest.  How will it look with
model?

Thanks,
Giuseppe

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH libvirt 1/6] conf: add MTP filesystem support to the parser

2014-08-11 Thread Daniel P. Berrange
On Mon, Aug 11, 2014 at 12:32:17PM +0200, Giuseppe Scrivano wrote:
 Daniel P. Berrange berra...@redhat.com writes:
 
  Would you agree with something like this?
  
 filesystem type='mount'
device name=mtp sharemtp/device
 ...
 
  What is the name=mtp share bit trying to reflect ?
 
  It seems we're mostly biased towards model so I think we should aim
  for  model type='mtp|9p'/
 
 it is the name of the MTP share within the guest.  How will it look with
 model?

For the name of the guest share we'll use  the existing target path=''
element. Yes 'path' is a misleading name - it doesn't have to be a path it
can be any string - this is what we do for 9p already.

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/1] numatune: Fix parsing of empty nodeset (0, ^0)

2014-08-11 Thread Ján Tomko
On 08/11/2014 12:03 PM, Erik Skultety wrote:
 Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1121837
 ---
  src/conf/numatune_conf.c   | 18 +++--
  ...emuxml2argv-numatune-memory-invalid-nodeset.xml | 31 
 ++
  tests/qemuxml2argvtest.c   |  1 +
  3 files changed, 48 insertions(+), 2 deletions(-)
  create mode 100644 
 tests/qemuxml2argvdata/qemuxml2argv-numatune-memory-invalid-nodeset.xml

We already reject a bitmap with no bits set specified by an empty string.
I think we should be consistent and reject all other representations of an
empty bitmap in virBitmapParse, fixing this for all callers.

Jan



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 3/4] vol-info: Check for NFS FS type

2014-08-11 Thread Ján Tomko
On 08/09/2014 12:28 AM, John Ferlan wrote:
 Testing seems to indicate that posix_fallocate() either doesn't work as
 expected on the target or using the target.path is incorrect...

 Before posix_fallocate
 stat st_blocks=0 st_blksize=1048576 st_size=10485760
 lseek end=10485760

 posix_fallocate of 10485760 bytes on /home/nfs_pool/target/test-vol1

 After posix_fallocate
 stat st_blocks=88 st_blksize=1048576 st_size=10485760
 lseek end=10485760


 Hmm... would going at the target be correct in this instance?  Same test
 but use the source path:

Using the source path would only work if the NFS export is on the localhost :)


 Before posix_fallocate
 stat st_blocks=0 st_blksize=4096 st_size=10485760
 lseek end=10485760

 posix_fallocate of 10485760 bytes on /home/nfs_pool/nfs-export/test-vol1

 After posix_fallocate
 stat st_blocks=20480 st_blksize=4096 st_size=10485760
 lseek end=10485760

 ...

 hmm 20480 * 512 = 10485760

 # df
 ...
 localhost:/home/nfs_pool/nfs-export 140979200 35521536  98273280  27%
 /home/nfs_pool/target
 #

 
 Well it's a tangled web that's being weaved...  The blksize of the
 target volume comes from the 'wsize' value in the mount:
 
 localhost:/home/nfs_pool/nfs-export on /home/nfs_pool/target type nfs4
 (rw,relatime,vers=4.0,rsize=1048576,wsize=1048576,...)
 
 Further testing shows if I change the wsize to 4096, then I get what I
 expect; however, starting at 8192 I'll get decreasingly smaller
 allocations. So this is a math problem.
 
 So going back to writing via posix_fallocate() to the
 /home/nfs_pool/target/test-vol the issue is the blksize of the
 source (nfs-export) is 4096 while the blksize of the target (target)
 is 1048576 (as a result of the nfs mount settings).  What seems to
 happen is the posix_fallocate() makes 11 writes - I assume because
 blksize*10  desired_size (10485760) (instead of =...).
 
 Thus 11 * 4096 = 45056 (bytes) / 1024 = 44 KiB which was displayed.
 
 Why all this happens I'm not sure.  Bug in posix_fallocate()? Bug in
 configuration?  I have to assume that when this code was first added NFS
 probably was still using smaller block sizes.

The code was introduced in 2013. Maybe it wasn't tested on NFS at all?
It looks like a posix_fallocate bug to me.

The other method we have (syscall(SYS_fallocate)) gives me EOPNOTSUPP -
Operation not supported on transport endpoint.

 Whether anyone has
 noticed or not beyond the virt-test which discovered the issue - I'm not
 sure.  In any case, does anyone have feedback/thoughts for next steps?
 I can put together something that avoids posix_fallocate() for the
 create-as and resize paths.
 

I think reporting an error when preallocate is requested for a NFS pool makes
sense, but that might be pretty annoying if something supplies the preallocate
flag by default.

Jan



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] conf: Format interface's driver more frequently

2014-08-11 Thread Michal Privoznik
There's this driver/ element under interface/ which can have
several attributes. However, the driver element is currently formated
only if the driver's name or txmode has been specified. This makes
only a little sense as we parse even partial driver/, for instance:

interface type='user'
  mac address='52:54:00:e5:48:58'/
  model type='virtio'/
  driver ioeventfd='on' event_idx='on' queues='5'/
/interface

But such XML would never get formatted back.

Signed-off-by: Michal Privoznik mpriv...@redhat.com
---
 src/conf/domain_conf.c |  4 +-
 .../qemuxml2argv-interface-driver.xml  | 51 ++
 tests/qemuxml2xmltest.c|  1 +
 3 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-interface-driver.xml

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c7016f3..934f6cb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16286,7 +16286,9 @@ virDomainNetDefFormat(virBufferPtr buf,
 virBufferEscapeString(buf, model type='%s'/\n,
   def-model);
 if (STREQ(def-model, virtio) 
-(def-driver.virtio.name || def-driver.virtio.txmode)) {
+(def-driver.virtio.name || def-driver.virtio.txmode ||
+ def-driver.virtio.ioeventfd || def-driver.virtio.event_idx ||
+ def-driver.virtio.queues)) {
 virBufferAddLit(buf, driver);
 if (def-driver.virtio.name) {
 virBufferAsprintf(buf,  name='%s',
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-interface-driver.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-interface-driver.xml
new file mode 100644
index 000..ec5ab61
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-interface-driver.xml
@@ -0,0 +1,51 @@
+domain type='qemu'
+  nametest/name
+  uuid15d091de-0181-456b-9554-e4382dc1f1ab/uuid
+  memory unit='KiB'1048576/memory
+  currentMemory unit='KiB'1048576/currentMemory
+  vcpu placement='static'1/vcpu
+  os
+type arch='x86_64' machine='pc-0.13'hvm/type
+boot dev='cdrom'/
+boot dev='hd'/
+bootmenu enable='yes'/
+  /os
+  clock offset='utc'/
+  on_poweroffdestroy/on_poweroff
+  on_rebootrestart/on_reboot
+  on_crashrestart/on_crash
+  devices
+emulator/usr/bin/qemu/emulator
+disk type='file' device='disk'
+  driver name='qemu' type='qcow2' event_idx='on'/
+  source file='/var/lib/libvirt/images/f14.img'/
+  target dev='vda' bus='virtio'/
+  address type='pci' domain='0x' bus='0x00' slot='0x04' 
function='0x0'/
+/disk
+disk type='file' device='cdrom'
+  driver name='qemu' type='raw'/
+  source file='/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso'/
+  target dev='hdc' bus='ide'/
+  readonly/
+  address type='drive' controller='0' bus='1' target='0' unit='0'/
+/disk
+controller type='usb' index='0'/
+controller type='virtio-serial' index='0'
+  address type='pci' domain='0x' bus='0x00' slot='0x06' 
function='0x0'/
+/controller
+controller type='ide' index='0'/
+controller type='pci' index='0' model='pci-root'/
+interface type='user'
+  mac address='52:54:00:e5:48:58'/
+  model type='virtio'/
+  driver ioeventfd='on' event_idx='on' queues='5'/
+/interface
+serial type='pty'
+  target port='0'/
+/serial
+console type='pty'
+  target type='serial' port='0'/
+/console
+memballoon model='virtio'/
+  /devices
+/domain
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 7d416d0..5941323 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -299,6 +299,7 @@ mymain(void)
 DO_TEST(lease);
 DO_TEST(event_idx);
 DO_TEST(vhost_queues);
+DO_TEST(interface-driver);
 DO_TEST(virtio-lun);
 
 DO_TEST(usb-redir);
-- 
1.8.5.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [python-PATCH] Fix libvirt_longlongWrap returning a very large value

2014-08-11 Thread Wang Rui
From: Zhou Yimin zhouyi...@huawei.com

If hypervisor is not Xen, the errs in struct _virDomainBlockStats will be -1.
But in KVM when we call domain.blockStats(), errs is 18446744073709551615.

To fix that, this patch has two changes:
1. Replace use of the PyLong_FromUnsignedLongLong with PyLong_FromLongLong
   in function libvirt_longlongWrap
2. If the paramemter of libvirt_longlongWrap is unsigned long long,
   use libvirt_ulonglongWrap instead because of above change.

After this patch, errs is -1 which is consistent with virDomainBlockStats api.

Signed-off-by: Zhou Yimin zhouyi...@huawei.com
Signed-off-by: Wang Rui moon.wang...@huawei.com
---
 libvirt-override.c | 18 +-
 typewrappers.c |  2 +-
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/libvirt-override.c b/libvirt-override.c
index ed5e9e4..b2271ae 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -1625,7 +1625,7 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
 PyTuple_SetItem(info, 1, item)  0)
 goto itemError;
 
-if ((item = libvirt_longlongWrap((long long)cpuinfo[i].cpuTime)) == 
NULL ||
+if ((item = libvirt_ulonglongWrap(cpuinfo[i].cpuTime)) == NULL ||
 PyTuple_SetItem(info, 2, item)  0)
 goto itemError;
 
@@ -2794,7 +2794,7 @@ libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED, 
PyObject *args) {
 PyList_SetItem(py_retval, 2, libvirt_ulongWrap(info.memory));
 PyList_SetItem(py_retval, 3, libvirt_intWrap((int) info.nrVirtCpu));
 PyList_SetItem(py_retval, 4,
-   libvirt_longlongWrap((unsigned long long) info.cpuTime));
+   libvirt_ulonglongWrap(info.cpuTime));
 return py_retval;
 }
 
@@ -2849,7 +2849,7 @@ libvirt_virDomainGetControlInfo(PyObject *self 
ATTRIBUTE_UNUSED, PyObject *args)
 py_retval = PyList_New(3);
 PyList_SetItem(py_retval, 0, libvirt_intWrap(info.state));
 PyList_SetItem(py_retval, 1, libvirt_intWrap(info.details));
-PyList_SetItem(py_retval, 2, libvirt_longlongWrap(info.stateTime));
+PyList_SetItem(py_retval, 2, libvirt_ulonglongWrap(info.stateTime));
 return py_retval;
 }
 
@@ -3354,7 +3354,7 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self 
ATTRIBUTE_UNUSED, PyObject *arg
 py_retval = PyList_New(c_retval);
 for (i = 0; i  c_retval; i++) {
 PyList_SetItem(py_retval, i,
-libvirt_longlongWrap((long long) freeMems[i]));
+libvirt_ulonglongWrap(freeMems[i]));
 }
 VIR_FREE(freeMems);
 return py_retval;
@@ -3794,11 +3794,11 @@ libvirt_virStoragePoolGetInfo(PyObject *self 
ATTRIBUTE_UNUSED, PyObject *args) {
 
 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.state));
 PyList_SetItem(py_retval, 1,
-   libvirt_longlongWrap((unsigned long long) info.capacity));
+   libvirt_ulonglongWrap(info.capacity));
 PyList_SetItem(py_retval, 2,
-   libvirt_longlongWrap((unsigned long long) info.allocation));
+   libvirt_ulonglongWrap(info.allocation));
 PyList_SetItem(py_retval, 3,
-   libvirt_longlongWrap((unsigned long long) info.available));
+   libvirt_ulonglongWrap(info.available));
 return py_retval;
 }
 
@@ -3825,9 +3825,9 @@ libvirt_virStorageVolGetInfo(PyObject *self 
ATTRIBUTE_UNUSED, PyObject *args) {
 return VIR_PY_NONE;
 PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.type));
 PyList_SetItem(py_retval, 1,
-   libvirt_longlongWrap((unsigned long long) info.capacity));
+   libvirt_ulonglongWrap(info.capacity));
 PyList_SetItem(py_retval, 2,
-   libvirt_longlongWrap((unsigned long long) info.allocation));
+   libvirt_ulonglongWrap(info.allocation));
 return py_retval;
 }
 
diff --git a/typewrappers.c b/typewrappers.c
index a5b562d..5399fb7 100644
--- a/typewrappers.c
+++ b/typewrappers.c
@@ -79,7 +79,7 @@ PyObject *
 libvirt_longlongWrap(long long val)
 {
 PyObject *ret;
-ret = PyLong_FromUnsignedLongLong((unsigned long long) val);
+ret = PyLong_FromLongLong(val);
 return ret;
 }
 
-- 
1.7.12.4


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] conf: Format interface's driver more frequently

2014-08-11 Thread Ján Tomko
On 08/11/2014 03:02 PM, Michal Privoznik wrote:
 There's this driver/ element under interface/ which can have
 several attributes. However, the driver element is currently formated
 only if the driver's name or txmode has been specified. This makes
 only a little sense as we parse even partial driver/, for instance:
 
 interface type='user'
   mac address='52:54:00:e5:48:58'/
   model type='virtio'/
   driver ioeventfd='on' event_idx='on' queues='5'/
 /interface
 
 But such XML would never get formatted back.
 
 Signed-off-by: Michal Privoznik mpriv...@redhat.com
 ---
  src/conf/domain_conf.c |  4 +-
  .../qemuxml2argv-interface-driver.xml  | 51 
 ++
  tests/qemuxml2xmltest.c|  1 +
  3 files changed, 55 insertions(+), 1 deletion(-)
  create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-interface-driver.xml

ACK

Jan



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCHv2] numatune: Fix parsing of empty nodeset (0,^0)

2014-08-11 Thread Erik Skultety
Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1121837
---

Notes:
Version 2:
- reject empty bitmaps while parsing instead of just rejecting nodesets

 src/util/virbitmap.c | 3 +++
 tests/qemuxml2argvtest.c | 1 +
 2 files changed, 4 insertions(+)

diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
index 27282df..b6bd074 100644
--- a/src/util/virbitmap.c
+++ b/src/util/virbitmap.c
@@ -378,6 +378,9 @@ virBitmapParse(const char *str,
 }
 }
 
+if (virBitmapIsAllClear(*bitmap))
+goto error;
+
 return virBitmapCountBits(*bitmap);
 
  error:
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 1c121ff..62b969c 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1210,6 +1210,7 @@ mymain(void)
 DO_TEST(cputune-zero-shares, QEMU_CAPS_NAME);
 
 DO_TEST(numatune-memory, NONE);
+DO_TEST_PARSE_ERROR(numatune-memory-invalid-nodeset, NONE);
 DO_TEST(numatune-memnode, QEMU_CAPS_NUMA, QEMU_CAPS_OBJECT_MEMORY_RAM);
 DO_TEST_FAILURE(numatune-memnode, NONE);
 
-- 
1.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] qemu: use guest-fsfreeze-freeze-list command if mountpoints to freeze specified

2014-08-11 Thread Michal Privoznik

On 08.08.2014 22:03, Tomoki Sekiyama wrote:

A command to freeze a part of mounted file systems is implemented in
upstream QEMU-guest-agent with a name of 'guest-fsfreeze-freeze-list'.
This fixes the name of the command used to partial fsfreeze in qemu driver
when 'mountpoints' option is specified to virDomainFSFreeze API.

Signed-off-by: Tomoki Sekiyama tomoki.sekiy...@hds.com
---
  src/qemu/qemu_agent.c |2 +-
  tests/qemuagenttest.c |2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 0421733..a10954a 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1336,7 +1336,7 @@ int qemuAgentFSFreeze(qemuAgentPtr mon, const char 
**mountpoints,
  if (!arg)
  return -1;

-cmd = qemuAgentMakeCommand(guest-fsfreeze-freeze,
+cmd = qemuAgentMakeCommand(guest-fsfreeze-freeze-list,
 a:mountpoints, arg, NULL);
  } else {
  cmd = qemuAgentMakeCommand(guest-fsfreeze-freeze, NULL);
diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c
index be207e8..bc649b4 100644
--- a/tests/qemuagenttest.c
+++ b/tests/qemuagenttest.c
@@ -45,7 +45,7 @@ testQemuAgentFSFreeze(const void *data)
  if (qemuMonitorTestAddAgentSyncResponse(test)  0)
  goto cleanup;

-if (qemuMonitorTestAddItem(test, guest-fsfreeze-freeze,
+if (qemuMonitorTestAddItem(test, guest-fsfreeze-freeze-list,
 { \return\ : 5 })  0)
  goto cleanup;


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list



ACKed  pushed.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 3/4] vol-info: Check for NFS FS type

2014-08-11 Thread John Ferlan
...snip...

 Why all this happens I'm not sure.  Bug in posix_fallocate()? Bug in
 configuration?  I have to assume that when this code was first added NFS
 probably was still using smaller block sizes.
 
 The code was introduced in 2013. Maybe it wasn't tested on NFS at all?
 It looks like a posix_fallocate bug to me.
 

Technically it was before that - the safezero function and it's
supporting cast were moved into virfile.c in 2013; however, they were in
[vir]util.c before that. It was first introduced in 2009 in commit id
'c29d0929' and beyond some minor changes/reword has stayed relatively
unchanged.

The one downside I see with it is that it's a build related either/or
setup. That is the HAVE_POSIX_FALLOCATE dictates the usage and
provides no fallback in the event that perhaps the result isn't expected
or if for some reason posix_fallocate fails.

Theoretically the safewrite option should/could be the fallback in the
event it's determined that the posix_fallocate() didn't generate the
right allocation size.

 The other method we have (syscall(SYS_fallocate)) gives me EOPNOTSUPP -
 Operation not supported on transport endpoint.
 

Right - I saw that too The resize code followed the safezero() code
at least with respect to the either/or with the HAVE_POSIX_FALLOCATE
build conditional. It was introduced in commit id 'aa2a4cff'.  It
assumes that the SYS_fallocate syscall is present and will work. It
is missing an option to safewrite() from current allocation to the new
end of the file (eg, a call to safezero passing the the current offset).

 Whether anyone has
 noticed or not beyond the virt-test which discovered the issue - I'm not
 sure.  In any case, does anyone have feedback/thoughts for next steps?
 I can put together something that avoids posix_fallocate() for the
 create-as and resize paths.

 
 I think reporting an error when preallocate is requested for a NFS pool makes
 sense, but that might be pretty annoying if something supplies the preallocate
 flag by default.
 

My comment was more geared towards my findings of the posix_fallocate()
introduction in 2009.

While I agree there's something flaky with posix_fallocate, I don't
think an error is necessarily the best path. Maybe better fall back
code - we could check the posix_fallocate() results (using stat)
perhaps VIR_WARN that something is wrong before falling back to the
mmap/safewrite options.

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [RFC PATCH 1/5] doc: schema: Add basic documentation for the ivshmem support

2014-08-11 Thread Levente Kurusa
(Imported thread from archives, hopefully I won't break threading. If I
did, I apologize.)

 On Aug 08 2014, Martin Kletzander wrote:
On Fri, Aug 08, 2014 at 02:07:56PM +0200, Maxime Leroy wrote:
On Fri, Aug 8, 2014 at 11:21 AM, Martin Kletzander mklet...@redhat.com 
wrote:
On Thu, Aug 07, 2014 at 05:34:35PM +0200, Maxime Leroy wrote:

On Thu, Aug 7, 2014 at 12:33 PM, Martin Kletzander mklet...@redhat.com
wrote:

On Tue, Aug 05, 2014 at 06:48:01PM +0200, Maxime Leroy wrote:

[...]

Note: the ivshmem server needs to be launched before
  creating the VM. It's not done by libvirt.


This is a good temporary workaround, but keep in mind that libvirt
works remotely as well and for remote machines libvirt should be able
to do everything for you to be able to run the machine if necessary.
So even if it might not start the server now, it should in the future.
That should be at least differentiable by some parameter (maybe you do
it somewhere in the code somehow, I haven't got into that).


The new version of ivshmem server has not been accepted yet in QEMU.
I think it's too early to have an option to launch an ivshmem server or
not.

I will prefer to focus on integrating these patches in libvirt first,
before adding a new feature to launch an ivhsmem server.

Are you ok with that ?


There was a suggestion of implementing the non-server variant first
and expand it to the variant with server afterwards.  That might be
the best solution because we'll have bit more time to see the
re-factoring differences in QEMU as well.  And we can concentrate on
other details.


I would prefer to have ivshmen server and non-server mode supported in
libvirt with these patches; because the XML format need to be designed
with both at the same time.

The new XML format supporting a start or not of ivshmem server could be:

shmem type='ivshmem'
 shm file='ivshmem0'
 server socket='/tmp/socket-ivshmem0'  start='yes'
 size unit='M'32/size
 msi vectors='32' ioeventfd='on'/
/shmem

Note: This new XML format can support different types of shmem.

After my holiday, I am going to check how to implement this feature.
What do you think about this XML format?


It's better, but I would like this:

shmem name='my_ivshmem_001'
 server socket='/tmp/ivsh-server' start='yes'/
 ...
/shmem

Keep in mind that libvirt should not allow having both the attribute
name and the server in the same shmem element. QEMU currently only
issues a warning, but I plan to change that, since it makes no sense to
continue when there are two possible sources for the SHMEM's file
descriptor.


That could be simplified into (in case of no server):

shmem name='my_ivshmem_001'/

Of course this will have a PCI address afterwards.

This design is generic enough that it doesn't mention ivshmem (so it
can be implemented differently in any hypervisor).

What's your opinion on that?

Any hints to develop this feature (i.e. starting ivshmen server in
libvirt) is welcomed.


With starting the server in libvirt we'll have to wait until it's in
qemu *and* we have to deal with how and when to stop the server (if we
are running it).

I assume I need to add a new file: src/util/virivshmemserver.c to add
a new function virIvshmemServerRun() and to use it in qemu_command.c.

How can I check whether an ivshmem-server application is installed or
not on the host ? Are there other equivalent behaviors into libvirt?


That should be checked by virFileIsExecutable() on a
IVSHMEM_SERVER_PATH that would be set by configure.ac (take a look at
EBTABLES_PATH in src/util/virfirewall.c for example).

I'll also see if I'll be able to get any info from the QEMU side about
what can we expect to happen with ivshmem in near future.

I plan to make a few mostly internal modifications on how it accesses
memory and how the registers are laid out in BAR1.

I don't really plan on changing the command line for now, one of my
minimal changes were changing 'use64=int' to 'use64=bool', however
MST didn't really like it claiming that it will break existing
scripts, so I postponed the patch until I finish off doing the more
serious internal stuff.

Watch out for patchdump with RFCs on qemu-devel in the next few days...

Thanks!
Levente Kurusa

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCHv3] numatune: Fix parsing of empty nodeset (0,^0)

2014-08-11 Thread Erik Skultety
Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1121837
---
 src/util/virbitmap.c   |  3 +++
 ...emuxml2argv-numatune-memory-invalid-nodeset.xml | 31 ++
 tests/qemuxml2argvtest.c   |  1 +
 3 files changed, 35 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/qemuxml2argv-numatune-memory-invalid-nodeset.xml

diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
index 27282df..b6bd074 100644
--- a/src/util/virbitmap.c
+++ b/src/util/virbitmap.c
@@ -378,6 +378,9 @@ virBitmapParse(const char *str,
 }
 }
 
+if (virBitmapIsAllClear(*bitmap))
+goto error;
+
 return virBitmapCountBits(*bitmap);
 
  error:
diff --git 
a/tests/qemuxml2argvdata/qemuxml2argv-numatune-memory-invalid-nodeset.xml 
b/tests/qemuxml2argvdata/qemuxml2argv-numatune-memory-invalid-nodeset.xml
new file mode 100644
index 000..079ca9d
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-numatune-memory-invalid-nodeset.xml
@@ -0,0 +1,31 @@
+domain type='qemu'
+  nameQEMUGuest1/name
+  uuidc7a5fdbd-edaf-9455-926a-d65c16db1809/uuid
+  memory unit='KiB'219136/memory
+  currentMemory unit='KiB'219136/currentMemory
+  vcpu placement='static' cpuset='0-1'2/vcpu
+  numatune
+memory mode=strict nodeset=0,^0/
+  /numatune
+  os
+type arch='i686' machine='pc'hvm/type
+boot dev='hd'/
+  /os
+  cpu
+topology sockets='2' cores='1' threads='1'/
+  /cpu
+  clock offset='utc'/
+  on_poweroffdestroy/on_poweroff
+  on_rebootrestart/on_reboot
+  on_crashdestroy/on_crash
+  devices
+emulator/usr/bin/qemu/emulator
+disk type='block' device='disk'
+  source dev='/dev/HostVG/QEMUGuest1'/
+  target dev='hda' bus='ide'/
+  address type='drive' controller='0' bus='0' target='0' unit='0'/
+/disk
+controller type='ide' index='0'/
+memballoon model='virtio'/
+  /devices
+/domain
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 1c121ff..62b969c 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1210,6 +1210,7 @@ mymain(void)
 DO_TEST(cputune-zero-shares, QEMU_CAPS_NAME);
 
 DO_TEST(numatune-memory, NONE);
+DO_TEST_PARSE_ERROR(numatune-memory-invalid-nodeset, NONE);
 DO_TEST(numatune-memnode, QEMU_CAPS_NUMA, QEMU_CAPS_OBJECT_MEMORY_RAM);
 DO_TEST_FAILURE(numatune-memnode, NONE);
 
-- 
1.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [RFC PATCH 0/5] ivshmem support

2014-08-11 Thread Levente Kurusa
On Aug 06 2014, Wang Rui wrote:
On 2014/8/6 0:48, Maxime Leroy wrote:
 The following patches are an implementation proposal
 for the ivshmem device support in libvirt.
 
 Any feedback is welcome.
 
 Note:
SELinux is not supported (need to be done for the next
patchset version)
 

Just some questiones:
Is there only one master at most on a host?

Right now, qemu does not have any restriction on the number of masters
on a host.

What will happen if two masters(in one VM or two VMS) on a host?

By default, all ivshmem devices are 'master' unless specified to be
'peer' on the command line. The only difference between 'master' and
'peer' is that 'peer' blocks migration.

My guess is that this mode-thing was a planned feature to solve
migration problems. According to my understanding the following was
meant to be:

The guests using the same SHM are virtually grouped together, having
one (and only one!) master guest, the rest being peer guests. On
migration the guest-group can only be migrated to the same host and all
together.

The master guest will copy over the SHM. Before this happens the ivshmem
devices are detached from the peer guests using PCI/ACPI hotplug. Once
the master finishes the copy, the guests are migrated and the peers are
reattached with a new fd pointing to the new shm object on the new host.

So, to answer your question: My guess is that you can have as much
master guests on the host, given that each master has a unique SHM.

Thanks!
Levente Kurusa

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [python-PATCH] Fix libvirt_longlongWrap returning a very large value

2014-08-11 Thread Michal Privoznik

On 11.08.2014 14:59, Wang Rui wrote:

From: Zhou Yimin zhouyi...@huawei.com

If hypervisor is not Xen, the errs in struct _virDomainBlockStats will be -1.
But in KVM when we call domain.blockStats(), errs is 18446744073709551615.

To fix that, this patch has two changes:
1. Replace use of the PyLong_FromUnsignedLongLong with PyLong_FromLongLong
in function libvirt_longlongWrap
2. If the paramemter of libvirt_longlongWrap is unsigned long long,
use libvirt_ulonglongWrap instead because of above change.

After this patch, errs is -1 which is consistent with virDomainBlockStats api.

Signed-off-by: Zhou Yimin zhouyi...@huawei.com
Signed-off-by: Wang Rui moon.wang...@huawei.com
---
  libvirt-override.c | 18 +-
  typewrappers.c |  2 +-
  2 files changed, 10 insertions(+), 10 deletions(-)


ACKed  pushed. Congratulations on your first libvirt-python commit!

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 libvirt 0/8] Add support for qemu usb-mtp device

2014-08-11 Thread Giuseppe Scrivano
This series adds support for qemu usb-mtp devices.

This new series addresses comments for v1:

https://www.redhat.com/archives/libvir-list/2014-August/msg00381.html

Now the XML looks like:

filesystem type='mount'
  source dir='/tmp/mtp_root'/
  model type='mtp'/
  target dir='mtp share'/
/filesystem

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1121781

Giuseppe Scrivano (8):
  conf: add model child element to filesystem
  conf, virDomainFSDefPtr: rename path argument to target
  qemu_command: fix block indentation
  qemu: add support for MTP filesystem
  docs: add documentation and schema for filesystem/model
  docs: relax filesystem/target dir element attribute to string
  conf: fix comment
  tests: add tests for filesystem model mtp

 docs/formatdomain.html.in  |  6 +++
 docs/schemas/domaincommon.rng  | 17 ++--
 src/conf/domain_conf.c | 29 -
 src/conf/domain_conf.h | 15 ++-
 src/qemu/qemu_command.c| 74 +++---
 tests/domainconfdata/getfilesystem.xml |  5 +++
 tests/domainconftest.c |  1 +
 7 files changed, 108 insertions(+), 39 deletions(-)

-- 
1.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 libvirt 1/8] conf: add model child element to filesystem

2014-08-11 Thread Giuseppe Scrivano
Signed-off-by: Giuseppe Scrivano gscri...@redhat.com
---
 src/conf/domain_conf.c | 25 +
 src/conf/domain_conf.h | 11 +++
 2 files changed, 36 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c7016f3..9252ffa 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -344,6 +344,11 @@ VIR_ENUM_IMPL(virDomainFS, VIR_DOMAIN_FS_TYPE_LAST,
   ram,
   bind)
 
+VIR_ENUM_IMPL(virDomainFSModel, VIR_DOMAIN_FS_MODEL_LAST,
+  default,
+  9p,
+  mtp)
+
 VIR_ENUM_IMPL(virDomainFSDriver, VIR_DOMAIN_FS_DRIVER_TYPE_LAST,
   default,
   path,
@@ -6458,6 +6463,7 @@ virDomainFSDefParseXML(xmlNodePtr node,
 virDomainFSDefPtr def;
 xmlNodePtr cur, save_node = ctxt-node;
 char *type = NULL;
+char *model = NULL;
 char *fsdriver = NULL;
 char *source = NULL;
 char *target = NULL;
@@ -6535,6 +6541,9 @@ virDomainFSDefParseXML(xmlNodePtr node,
 wrpolicy = virXMLPropString(cur, wrpolicy);
 if (!format)
 format = virXMLPropString(cur, format);
+} else if (!model 
+   xmlStrEqual(cur-name, BAD_CAST model)) {
+model = virXMLPropString(cur, type);
 }
 }
 cur = cur-next;
@@ -6556,6 +6565,14 @@ virDomainFSDefParseXML(xmlNodePtr node,
 }
 }
 
+if (model) {
+if ((def-model = virDomainFSModelTypeFromString(model)) = 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _(unknown model value '%s'), model);
+goto error;
+}
+}
+
 if (wrpolicy) {
 if ((def-wrpolicy = virDomainFSWrpolicyTypeFromString(wrpolicy)) = 
0) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -15795,6 +15812,14 @@ virDomainFSDefFormat(virBufferPtr buf,
 
 switch (def-type) {
 case VIR_DOMAIN_FS_TYPE_MOUNT:
+virBufferEscapeString(buf, source dir='%s'/\n,
+  def-src);
+if (def-model) {
+virBufferEscapeString(buf, model type='%s'/\n,
+  virDomainFSModelTypeToString(def-model));
+}
+break;
+
 case VIR_DOMAIN_FS_TYPE_BIND:
 virBufferEscapeString(buf, source dir='%s'/\n,
   def-src);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ff7d640..d7664e4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -764,6 +764,15 @@ typedef enum {
 VIR_DOMAIN_FS_TYPE_LAST
 } virDomainFSType;
 
+/* Filesystem model */
+typedef enum {
+VIR_DOMAIN_FS_MODEL_DEFAULT = 0,
+VIR_DOMAIN_FS_MODEL_9P,   /* 9P network filesystem */
+VIR_DOMAIN_FS_MODEL_MTP,   /* MTP usb filesystem */
+
+VIR_DOMAIN_FS_MODEL_LAST
+} virDomainFSModel;
+
 /* Filesystem driver type */
 typedef enum {
 VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT = 0,
@@ -808,6 +817,7 @@ struct _virDomainFSDef {
 virDomainDeviceInfo info;
 unsigned long long space_hard_limit; /* in bytes */
 unsigned long long space_soft_limit; /* in bytes */
+int model;
 };
 
 
@@ -2585,6 +2595,7 @@ VIR_ENUM_DECL(virDomainControllerModelPCI)
 VIR_ENUM_DECL(virDomainControllerModelSCSI)
 VIR_ENUM_DECL(virDomainControllerModelUSB)
 VIR_ENUM_DECL(virDomainFS)
+VIR_ENUM_DECL(virDomainFSModel)
 VIR_ENUM_DECL(virDomainFSDriver)
 VIR_ENUM_DECL(virDomainFSAccessMode)
 VIR_ENUM_DECL(virDomainFSWrpolicy)
-- 
1.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


  1   2   >