Re: [libvirt] [question] We can create two network of one same linux bridge or local ethernet. It is a bug?

2013-12-02 Thread Sheldon

On 12/02/2013 10:48 PM, Laine Stump wrote:

On 12/02/2013 11:52 AM, Daniel P. Berrange wrote:

On Sat, Nov 30, 2013 at 07:30:03PM +0800, Sheldon wrote:

We can create two network of one same linux bridge or local ethernet:

This is not harmful.
But I wonder should this case is allowed?  Why?

It should probably be rejected as invalid.


In the end, these "unmanaged" (by libvirt) networks are just describing
where to connect the guests to, providing a persistent name for a
particular network connection so that the underlying network
implementation can change without needing to modify the guest config;
they aren't doing anything to change the configuration of the bridge
they point to, or any firewall rules or dhcp/dns server related to it.
So allowing multiple networks to point to the same bridge doesn't create
any bad situations, and I can actually think of a place where it would
be useful.

Let's say you have defined two networks, "engineering" and "sales" that
are currently connected to the same network due to limitations in your
physical network - simple enough, just define two networks that both
point to the same bridge device. Then one day you get around to setting
up a 2nd physical network and plugging your host into it - just change
the definition of one of the networks to the new bridge and restart the
guests (someday it would be nice if virNetworkUpdateFlags() could handle
changing the bridge device of a network without restarting it).

This same situation can't be handled with portgroups on a single
network, though.

Thank Laine for elaborating it.



virsh # net-list --all
Name State Autostart Persistent
--
br1 active yes yes
br2 active yes yes
default active yes yes

virsh # net-dumpxml br1

br1
d5410814-1bea-b10d-04b8-9fbd3a1cfc65




virsh # net-dumpxml br2

br2
99f20705-57cd-da31-f193-d13af4158792




virsh # net-list --all
Name State Autostart Persistent
--
br0 active yes yes
br1 active yes yes
default active yes yes

virsh # net-dumpxml br0

br0
a35c840a-9bdc-070d-43f5-8e834040aa42





virsh # net-dumpxml br1

br1
f1c87b80-2dfc-2a71-3fb6-56ef83daf29a





This case is also harmless, since bridge mode of macvtap allows multiple
connections to the same device. It is true, though, that when forward
mode='passthrough', there would be problems if two networks tried to use
the same physical device at the same time. However I think that the
proper solution to that problem isn't to disallow listing of the same
physdevs in multiple networks, but instead to keep a *global* (to
libvirt) in-use count for all physdevs. In this way, the same pool of
SRIOV VFs could be provided for multiple networks (e.g., a
mode='passthrough *and* a mode='hostdev' network) and those networks
could all safely share from that pool.

(An example of the usefulness of this would be the case where you had
some guests that required the extra bit of performance required by PCI
passthrough of a physical device, and some guests could get by okay with
macvtap in passthrough mode (and maybe still others could live with
macvtap in one of it's shared modes).




--
Sheldon Feng(冯少合)
IBM Linux Technology Center

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

[libvirt] [PATCHv2 3/3] qemu: command: Handle RBD storage pools

2013-12-02 Thread Adam Walters
This patch modifies the switch statement in qemuBuildVolumeString
to format and pass the needed argument to handle a volume from an
RBD storage pool properly. If the volume is a VIR_STORAGE_VOL_NETWORK
but is not from an RBD pool, I goto cleanup, just like the other
unimplemented volume types. Currently, the code only supports RBD
volumes, as I lack the facilities to test other network storage pools.
Once I have the ability to test those, I will revisit the possibility
of implementing additional types.
---
 src/qemu/qemu_command.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 763417f..4102568 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3825,6 +3825,17 @@ qemuBuildVolumeString(virConnectPtr conn,
 }
 break;
 case VIR_STORAGE_VOL_NETWORK:
+if (disk->srcpool->pooltype == VIR_STORAGE_POOL_RBD) {
+virBufferAddLit(opt, "file=");
+
+if (qemuBuildRBDString(conn, disk, opt) < 0)
+goto cleanup;
+
+virBufferAddChar(opt, ',');
+} else {
+goto cleanup;
+}
+break;
 case VIR_STORAGE_VOL_NETDIR:
 case VIR_STORAGE_VOL_LAST:
 /* Keep the compiler quiet, qemuTranslateDiskSourcePool already
-- 
1.8.4.2

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


[libvirt] [PATCHv2 0/3] Rebase of patch to add support for RBD storage pools

2013-12-02 Thread Adam Walters
This series of patches adds support for RBD storage pools to the latest version
of libvirt. Included in this is a simple structure to build additional network
storage pool support off of (really a couple of if/else blocks, so nothing 
fancy).

This code passes check, check-syntax, and the valgrind tests. Additionally, the
code is tested working in my environment. In fact, the machine I am sending this
email from is a VM being run under qemu+libvirt with backend storage being an 
RBD
storage pool using this code. Unfortunately, I only have the one RBD pool and
libvirt host, so the code could use additional testing.

If anyone finds any problems with my code, please let me know. I will fix them 
and
resubmit the patch as needed. Hopefully someone else out there finds this 
support
as useful as I do. While not many libvirt management clients utilize the storage
API today, it does look to be the better method to interact with storage, and 
thus
likely to be the best way to go in the future. I figure that additional storage
backend support may well help to get others using the API instead of duplicating
configuration options across every VM.

Adam Walters (3):
  qemu: config: Add qemuAddRBDPoolSourceHost helper function
  qemu: conf: Parse RBD storage pool from domain xml
  qemu: command: Handle RBD storage pools

 src/qemu/qemu_command.c | 11 +
 src/qemu/qemu_conf.c| 65 +
 2 files changed, 76 insertions(+)

-- 
1.8.4.2

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


[libvirt] [PATCHv2 1/3] qemu: config: Add qemuAddRBDPoolSourceHost helper function

2013-12-02 Thread Adam Walters
Add a function to grab the RBD hosts from a pool definition and add
them to the disk definition. This function allows the addition of
RBD storage pool functionality.
---
 src/qemu/qemu_conf.c | 39 +++
 1 file changed, 39 insertions(+)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 557ccc5..e2154c6 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1247,6 +1247,45 @@ cleanup:
 }
 
 static int
+qemuAddRBDPoolSourceHost(virDomainDiskDefPtr def,
+   virStoragePoolDefPtr pooldef)
+{
+int ret = -1;
+size_t i = 0;
+char **tokens = NULL;
+
+def->nhosts = pooldef->source.nhost;
+
+if (VIR_ALLOC_N(def->hosts, def->nhosts) < 0)
+goto cleanup;
+
+for (i = 0; i < def->nhosts; i++) {
+if (VIR_STRDUP(def->hosts[i].name, pooldef->source.hosts[i].name) < 0)
+goto cleanup;
+
+if (virAsprintf(&def->hosts[i].port, "%d",
+pooldef->source.hosts[i].port ?
+pooldef->source.hosts[i].port :
+6789) < 0)
+goto cleanup;
+
+/* Storage pools have not supported these 2 attributes yet,
+ * use the defaults.
+ */
+def->hosts[i].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
+def->hosts[i].socket = NULL;
+}
+
+def->protocol = VIR_DOMAIN_DISK_PROTOCOL_RBD;
+
+ret = 0;
+
+cleanup:
+virStringFreeList(tokens);
+return ret;
+}
+
+static int
 qemuTranslateDiskSourcePoolAuth(virDomainDiskDefPtr def,
 virStoragePoolDefPtr pooldef)
 {
-- 
1.8.4.2

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


[libvirt] [PATCHv2 2/3] qemu: conf: Parse RBD storage pool from domain xml

2013-12-02 Thread Adam Walters
Modify switch statement in qemuTranslateDiskSourcePool
to parse the storage pool definition for RBD pools
instead of throwing an error. I do throw errors for
any other usage case of VIR_STORAGE_VOL_NETWORK, as my
code does not cover their use cases currently. Once I
have the ability to test such usage cases, I will
revisit those possibilities.
---
 src/qemu/qemu_conf.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index e2154c6..024d40f 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1416,6 +1416,32 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,
 
 break;
 case VIR_STORAGE_VOL_NETWORK:
+if (!(poolxml = virStoragePoolGetXMLDesc(pool, 0)))
+goto cleanup;
+
+if (!(pooldef = virStoragePoolDefParseString(poolxml)))
+goto cleanup;
+
+def->srcpool->pooltype = pooldef->type;
+if (pooldef->type == VIR_STORAGE_POOL_RBD) {
+if (!def->srcpool->mode)
+def->srcpool->mode = VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT;
+
+if (qemuAddRBDPoolSourceHost(def, pooldef) < 0)
+goto cleanup;
+
+if (!(def->src = virStorageVolGetPath(vol)))
+goto cleanup;
+
+if (qemuTranslateDiskSourcePoolAuth(def, pooldef) < 0)
+goto cleanup;
+} else {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("Unsupported network volume type"));
+goto cleanup;
+}
+
+break;
 case VIR_STORAGE_VOL_NETDIR:
 case VIR_STORAGE_VOL_LAST:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-- 
1.8.4.2

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


[libvirt] [PATCH] qemuAgentDispose: Reset lastError

2013-12-02 Thread Wangyufei (James)
When an error occurred in qemuAgentIO, it will be saved in mon->lastError,
but it will not be freed at last.
So I add the following code to fix it.

==22219== 54 bytes in 1 blocks are definitely lost in loss record 982 of 1,379
==22219==at 0x4C26B9B: malloc (vg_replace_malloc.c:263)
==22219==by 0x8520521: strdup (in /lib64/libc-2.11.3.so)
==22219==by 0x52E99CB: virStrdup (virstring.c:554)
==22219==by 0x52B44C4: virCopyError (virerror.c:195)
==22219==by 0x52B5123: virCopyLastError (virerror.c:312)
==22219==by 0x10905877: qemuAgentIO (qemu_agent.c:660)
==22219==by 0x52B6122: virEventPollDispatchHandles (vireventpoll.c:501)
==22219==by 0x52B7AEA: virEventPollRunOnce (vireventpoll.c:647)
==22219==by 0x52B5C1B: virEventRunDefaultImpl (virevent.c:274)
==22219==by 0x54181FD: virNetServerRun (virnetserver.c:1112)
==22219==by 0x11EF4D: main (libvirtd.c:1513)

Signed-off-by: Zhou Yimin 
---
 src/qemu/qemu_agent.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 2cd0ccc..4a3820c 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -161,6 +161,7 @@ static void qemuAgentDispose(void *obj)
 (mon->cb->destroy)(mon, mon->vm);
 virCondDestroy(&mon->notify);
 VIR_FREE(mon->buffer);
+virResetError(&mon->lastError);
 }
 
 static int
-- 
1.7.3.1.msysgit.0

Best Regards,
-WangYufei



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


Re: [libvirt] [PATCH 1/4] Add USB Keyboard support in libvirt

2013-12-02 Thread Li Zhang

On 2013年12月03日 01:43, Nehal J Wani wrote:

+QEMU_CAPS_DEVICE_USB_KBD = 160, /*-device usb-kbd*/
+

Why this extra newline?

Thanks for your reviewing. :)

Let me remove the blank line in next version.




  QEMU_CAPS_LAST,   /* this must always be the last item */
  };
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 763417f..318f7a1 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5280,9 +5280,15 @@ qemuBuildUSBInputDevStr(virDomainDefPtr def,
  {
  virBuffer buf = VIR_BUFFER_INITIALIZER;

-virBufferAsprintf(&buf, "%s,id=%s",
-  dev->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ?
-  "usb-mouse" : "usb-tablet", dev->info.alias);
+if (dev->type == VIR_DOMAIN_INPUT_TYPE_MOUSE) {
+virBufferAsprintf(&buf, "usb-mouse,id=%s", dev->info.alias);
+} else if (dev->type == VIR_DOMAIN_INPUT_TYPE_TABLET) {
+virBufferAsprintf(&buf, "usb-tablet,id=%s", dev->info.alias);
+} else if (dev->type == VIR_DOMAIN_INPUT_TYPE_KBD) {
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_KBD))
+goto error;
+virBufferAsprintf(&buf, "usb-kbd,id=%s", dev->info.alias);
+}

I would've used switch(dev->type) instead of 'if else', to make it look simple.


OK, I will change it in next version.

Thanks.
--Li




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

Re: [libvirt] [PATCH 0/9] Add throttle blkio cgroup support for libvirt

2013-12-02 Thread hzguanqi...@corp.netease.com
On 2013-12-02 14:47 , Gao feng wrote:
Right now, libvirt only supports the cfq based blkio cgorup,
this means if the block devices doesn't use cfq scheduler, the
blkio cgroup will loss effect.

This patchset adds the throttle blkio cgroup support for libvirt,
intoduces four elements for domain configuration and extend the
virsh command blkiotune.

intoduces/introduces/s

This patchset is a new version of Guan Qiang's patchset
://www.redhat.com/archives/libvir-list/2013-October/msg01066.html

Change form Guan Qiang's patchset:
1, split to 8 patches, make logic more clear
2, change the type of read/write iops form unsigned long long to unsigned int,
   trying to set read/write iops to the value which bigger than max number of
   unsigned int will fail.
3, fix some logic shortage.

Gao feng (9):
  rename virDomainBlkioDeviceWeightParseXML to
virDomainBlkioDeviceParseXML
  rename virBlkioDeviceWeightArrayClear to virBlkioDeviceArrayClear
  rename virBlkioDeviceWeightPtr to virBlkioDevicePtr
  domain: introduce xml elements for throttle blkio cgroup
  blkio: Setting throttle blkio cgroup for domain
  qemu: allow to setup throttle blkio cgroup through virsh
  virsh: add virsh manual for setting throttle blkio cgroup
  lxc: allow to setup throttle blkio cgroup through virsh
  qemu: add new throttle blkio cgroup elements to the test xml

docs/schemas/domaincommon.rng  |  28 +-
include/libvirt/libvirt.h.in   |  45 ++
src/conf/domain_conf.c | 113 +++-
src/conf/domain_conf.h |  16 +-
src/libvirt_private.syms   |   5 +-
src/lxc/lxc_cgroup.c   |  12 +-
src/lxc/lxc_driver.c   | 649 -
src/qemu/qemu_cgroup.c |  13 +-
src/qemu/qemu_driver.c | 432 --
src/util/vircgroup.c   | 170 +-
src/util/vircgroup.h   |  18 +
.../qemuxml2argv-blkiotune-device.xml  |   8 +
tools/virsh-domain.c   |  64 ++
tools/virsh.pod|  36 +-
14 files changed, 1485 insertions(+), 124 deletions(-)

-- 
1.8.3.1

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


-- 
Best regards!
GuanQiang
10:46:48--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2 1/2] conf: add xml element devices/pvpanic

2013-12-02 Thread Hu Tao
On Mon, Dec 02, 2013 at 02:34:44PM -0700, Eric Blake wrote:
> On 12/01/2013 11:11 PM, Hu Tao wrote:
> > This patch adds a new xml element devices/pvpanic to support qemu device
> > pvpanic. It can be used to receive guest panic notification.
> > 
> > Signed-off-by: Hu Tao 
> > ---
> >  docs/formatdomain.html.in | 25 +
> >  src/conf/domain_conf.c| 68 
> > +++
> >  src/conf/domain_conf.h|  9 +++
> >  3 files changed, 102 insertions(+)
> 
> In addition to Peter's review:
> 
> when sending a series, it helps to include a 0/2 cover letter (git
> send-email --cover-letter).

OK, will include it in next version.

> 
> > 
> > diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> > index 1850a2b..0a72baa 100644
> > --- a/docs/formatdomain.html.in
> > +++ b/docs/formatdomain.html.in
> > @@ -5080,6 +5080,31 @@ qemu-kvm -net nic,model=? /dev/null
> >  
> >
> >  
> > +pvpanic device
> 
> pvpanic is a qemu term, but I could see the feasibility of other
> hypervisors having a paravirt device with a sole purpose of notifying
> the host about panics.  Do we want to come up with a more generic name?

I'd call it 'panic notification', but it doesn't sound like a device
name. Advise?

> 
> > +  
> > +
> > +  
> > +  ...
> > +
> > +  
> > +ioport
> > +
> > +  
> > +ioport used by pvpanic.
> 
> Probably worth documenting that 0x505 is the default port, and that most
> users don't need to specify the ioport.

OK.

> 
> 
> > +ioport = virXMLPropString(node, "ioport");
> > +if (!ioport) {
> > +pvpanic->ioport = -1;
> > +} else {
> > +if (virStrToLong_i(ioport, NULL, 0, &pvpanic->ioport) < 0) {
> > +virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> 
> VIR_ERR_INTERNAL_ERROR is probably the wrong type, since this is easily
> triggered by a user.  I know it's copy and paste from other code, but
> these days, VIR_ERR_XML_ERROR is preferred in new code reporting a parse
> error.
> 
> Should virDomainDeviceType be enhanced to include this device type?  And
> if so, you need to modify at least virDomainDeviceDefFree() to handle
> the new enum value.

OK.

> 
> > +static int virDomainPvpanicDefFormat(virBufferPtr buf,
> > + virDomainPvpanicDefPtr def)
> > +{
> > +if (def->ioport > 0) {
> 
> Isn't this an off-by-one if someone explicitly requests port 0 (since
> your parser initializes to -1 when left unspecified)?

port 0 means disable the device, so there is no need to add it when port
is 0. But if you'd prefer to let the device handle port itself, then
it's OK to add it in the case.

-- 
Regards,
Hu Tao

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


Re: [libvirt] [PATCH v2 2/2] qemu: add support for -device pvpanic

2013-12-02 Thread Hu Tao
On Mon, Dec 02, 2013 at 02:38:09PM -0700, Eric Blake wrote:
> On 12/01/2013 11:11 PM, Hu Tao wrote:
> > This patch will add -device pvpanic to qemu command line if user enables
> > pvpanic in domain xml and the qemu version supports pvpanic.
> > 
> > Signed-off-by: Hu Tao 
> > ---
> >  src/qemu/qemu_capabilities.c |  3 +++
> >  src/qemu/qemu_capabilities.h |  2 ++
> >  src/qemu/qemu_command.c  | 10 ++
> >  3 files changed, 15 insertions(+)
> > 
> 
> In addition to Peter's comments,
> 
> > +++ b/src/qemu/qemu_capabilities.h
> > @@ -199,6 +199,8 @@ enum virQEMUCapsFlags {
> >  QEMU_CAPS_DEVICE_ICH9_INTEL_HDA = 158, /* -device ich9-intel-hda */
> >  QEMU_CAPS_KVM_PIT_TICK_POLICY = 159, /* kvm-pit.lost_tick_policy */
> >  
> > +QEMU_CAPS_DEVICE_PVPANIC = 160, /* -device pvpanic */
> 
> Alignment looks odd here.

It aligns as most of the enums do. It doesn't look alike the above two
because their names are too long.

> 
> > +if (def->pvpanic &&
> > +virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PVPANIC)) {
> > +if (def->pvpanic->ioport > 0) {
> 
> Again, is port 0 a valid port (given that you initialized it to -1)?
> 
> I know we haven't been doing a good job of domxml-from-native, but in
> this particular case, can we also fix the command line parser to turn
> '-device pvpanic' into the appropriate pvpanic device allocation?

In the case of native->xml, I think we'd better to keep port 0 in xml.
I'll fix it.

> 
> > +} else
> 
> Style.  If you used {} for 'if', you must also use it for 'else' (I'm
> still not sure how to enforce it by syntax-check, but it's on my list of
> things that would be nice to have).

Thanks.

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


Re: [libvirt] [PATCH v2 2/2] qemu: add support for -device pvpanic

2013-12-02 Thread Hu Tao
On Mon, Dec 02, 2013 at 11:15:17AM +0100, Peter Krempa wrote:
> On 12/02/13 07:11, Hu Tao wrote:
> > This patch will add -device pvpanic to qemu command line if user enables
> > pvpanic in domain xml and the qemu version supports pvpanic.
> > 
> > Signed-off-by: Hu Tao 
> > ---
> >  src/qemu/qemu_capabilities.c |  3 +++
> >  src/qemu/qemu_capabilities.h |  2 ++
> >  src/qemu/qemu_command.c  | 10 ++
> >  3 files changed, 15 insertions(+)
> > 
> 
> ...
> 
> > diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> > index 763417f..6310bb2 100644
> > --- a/src/qemu/qemu_command.c
> > +++ b/src/qemu/qemu_command.c
> > @@ -9588,6 +9588,16 @@ qemuBuildCommandLine(virConnectPtr conn,
> >  goto error;
> >  }
> >  
> > +if (def->pvpanic &&
> > +virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PVPANIC)) {
> > +if (def->pvpanic->ioport > 0) {
> > +virCommandAddArg(cmd, "-device");
> > +virCommandAddArgFormat(cmd, "pvpanic,ioport=%d",
> > +   def->pvpanic->ioport);
> > +} else
> > +virCommandAddArgList(cmd, "-device", "pvpanic", NULL);
> 
> If pvpanic is requested, but not available in qemu, libvirt should error
> out instead of silently starting the VM without the device.
> 
> > +}
> > +
> >  if (mlock) {
> >  unsigned long long memKB;
> >  
> > 
> 
> Also as said in review of 1/2. You need to add tests for the new device.

Thanks.

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


Re: [libvirt] [PATCH v2 1/2] conf: add xml element devices/pvpanic

2013-12-02 Thread Hu Tao
On Mon, Dec 02, 2013 at 11:13:33AM +0100, Peter Krempa wrote:
> On 12/02/13 07:11, Hu Tao wrote:
> > This patch adds a new xml element devices/pvpanic to support qemu device
> > pvpanic. It can be used to receive guest panic notification.
> > 
> > Signed-off-by: Hu Tao 
> > ---
> >  docs/formatdomain.html.in | 25 +
> >  src/conf/domain_conf.c| 68 
> > +++
> >  src/conf/domain_conf.h|  9 +++
> >  3 files changed, 102 insertions(+)
> 
> A few issues I see at first glance:
> 
> 1) you didn't add ABI compatibility check for the pvpanic device
> 2) XML->XML tests are missing
> 3) RNG schemas for the new element are missing
> 4) XML->qemu commandline tests are missing (in 2/2)

Thanks, I'll add the missing parts in next version.

> 
> 
> > 
> > diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> > index 1850a2b..0a72baa 100644
> > --- a/docs/formatdomain.html.in
> > +++ b/docs/formatdomain.html.in
> > @@ -5080,6 +5080,31 @@ qemu-kvm -net nic,model=? /dev/null
> >  
> >
> >  
> > +pvpanic device
> > +
> > +  pvpanic device enables libvirt to receive panic notification from a 
> > QEMU
> > +  guest.
> > +  Since 1.3.0, QEMU and KVM only
> 
> 1.3.0? the since tag is supposed to contain a libvirt version. 1.3.0
> will not happen that soon. 1.2.1 is what you are looking for.

OK.

> 
> > +
> > +
> > +  Example: usage of pvpanic configuration
> > +
> > +
> > +  ...
> > +  
> > +
> > +  
> > +  ...
> > +
> > +  
> > +ioport
> > +
> > +  
> > +ioport used by pvpanic.
> > +  
> > +
> > +  
> > +
> >  Security label
> >  
> >  
> > diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> > index 140eb80..1b8f66f 100644
> > --- a/src/conf/domain_conf.c
> > +++ b/src/conf/domain_conf.c
> 
> ...
> 
> > @@ -15715,6 +15768,18 @@ virDomainWatchdogDefFormat(virBufferPtr buf,
> >  return 0;
> >  }
> >  
> > +static int virDomainPvpanicDefFormat(virBufferPtr buf,
> > + virDomainPvpanicDefPtr def)
> > +{
> > +if (def->ioport > 0) {
> > +virBufferAsprintf(buf, "\n",
> > +  def->ioport);
> > +} else {
> > +virBufferAsprintf(buf, "\n");
> 
> Would break syntax-check. For static strings use virBufferAddLit.

OK.

> 
> > +}
> > +
> > +return 0;
> > +}
> >  
> >  static int
> >  virDomainRNGDefFormat(virBufferPtr buf,
> 
> 


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


Re: [libvirt] [v3 01/32] Added domain start/stop/define/undefine event unit tests

2013-12-02 Thread Eric Blake
On 12/02/2013 09:39 AM, Cédric Bosdonnat wrote:
> These unit tests are aiming at providing some help during the domain
> events refactoring.
> ---
>  .gitignore  |   1 +
>  tests/Makefile.am   |   7 ++
>  tests/objecteventtest.c | 246 
> 
>  3 files changed, 254 insertions(+)
>  create mode 100644 tests/objecteventtest.c
> 

> +
> +struct lifecycleEventCounter {
> +int startEvents;
> +int stopEvents;
> +int defineEvents;
> +int undefineEvents;
> +};

Style: use a typedef here, so you don't have to repeat 'struct' below.

> +
> +static void lifecycleEventCounter_reset(struct lifecycleEventCounter* 
> counter)

Style: return type on separate line, '*' hugs the variable name, not the
type name.

static void
lifecycleEventCounter_reset(lifecycleEventCounter *counter)

> +static int domainLifecycleCb(virConnectPtr conn ATTRIBUTE_UNUSED,
> + virDomainPtr dom ATTRIBUTE_UNUSED,
> + int event,
> + int detail ATTRIBUTE_UNUSED,
> + void *opaque)
> +{
> +struct lifecycleEventCounter *counter = opaque;
> +
> +switch (event) {
> +case VIR_DOMAIN_EVENT_STARTED:
> +counter->startEvents++;
> +break;
> +case VIR_DOMAIN_EVENT_STOPPED:
> +counter->stopEvents++;
> +break;
> +case VIR_DOMAIN_EVENT_DEFINED:
> +counter->defineEvents++;
> +break;
> +case VIR_DOMAIN_EVENT_UNDEFINED:
> +counter->undefineEvents++;
> +break;
> +default:
> +/* Ignore other events */

Should we at least count the number of other events?

But overall looking very useful.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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

Re: [libvirt] [PATCHv3] qemu: Refactor qemuTranslateDiskSourcePool

2013-12-02 Thread Eric Blake
On 12/02/2013 08:19 AM, Peter Krempa wrote:
> Before this patch, the translation function still needs a second ugly
> helper function to actually format the command line for qemu. But if we
> do the right stuff in the translation function, we don't have to bother
> with the second function any more.
> 
> This patch removes the messy qemuBuildVolumeString function and changes
> qemuTranslateDiskSourcePool to set stuff up correctly so that the
> regular code paths meant for volumes can be used to format the command
> line correctly.
> 
> For this purpose a new helper "qemuDiskGetActualType()" is introduced to
> return the type of the volume in a pool.
> 
> As a part of the refactor the qemuTranslateDiskSourcePool function is
> fixed to do decisions based on the pool type instead of the volume type.
> This allows to separate pool-type-specific stuff more clearly and will
> ease addition of other pool types that will require certain other
> operations to get the correct pool source.
> 
> The previously fixed tests should make sure that we don't break stuff
> that was working before.
> ---
> 

> +virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> _("tray status 'open' is invalid for "
> - "block type disk"));
> + "block type %s"),
> +   disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME ? 
> _("volume") : _("disk"));

Translators generally prefer:

disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME ?
_("tray status 'open' is invalid for block type volume") :
_("tray status 'open' is invalid for block type disk")

because there may be gender differences between volume and disk that
require altering the rest of the sentence.

Looking good to me though; ACK.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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

Re: [libvirt] [PATCHv1.5 18/27] conf: Add functions to copy and free network disk source definitions

2013-12-02 Thread Eric Blake
On 11/27/2013 04:15 AM, Michal Privoznik wrote:
> On 26.11.2013 17:49, Peter Krempa wrote:
>> To simplify operations on virDomainDiskHostDef arrays we will need deep
>> copy and freeing functions. Add and properly export them.
>> ---

>> +if (VIR_STRDUP(dst->port, src->port) < 0)
>> +goto error;
>> +
>> +if (VIR_STRDUP(dst->socket, src->socket) < 0)
>> +goto error;
> 
> Could have been joined into one 'if' with or-ed VIR_STRDUP(). But this
> is just fine too.

Dan has been (successfully) convincing me that separate 'if' is better
for -O2 debugging, because then gdb is better able to show you which
line of code failed.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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

Re: [libvirt] [PATCHv1.5 17/27] snapshot: conf: Fix NULL dereference when element is empty

2013-12-02 Thread Eric Blake
On 11/27/2013 04:15 AM, Michal Privoznik wrote:
> On 26.11.2013 17:48, Peter Krempa wrote:
>> Consider the following valid snapshot XML as the  element is
>> allowed to be empty in the domainsnapshot.rng schema:
>>
>> $ cat snap.xml
>> 
>>   
>> 
>>   
>>   
>> 
>>   
>> 
>>
>> produces the following error:
>>
>> $ virsh snapshot-create domain snap.xml
>> error: internal error: unknown disk snapshot driver '(null)'
>>
>> The driver type is parsed as NULL from the XML as the attribute is not
>> present and then directly used to produce the error message.
>>
>> With this patch the attempt to parse the driver type is skipped if not
>> present to avoid changing the schema to forbid the empty driver element.
>> ---
>>  src/conf/snapshot_conf.c | 16 +---
>>  1 file changed, 9 insertions(+), 7 deletions(-)

Shouldn't we add this example somewhere in the tests/ subdirectory to
ensure we don't regress?

> 
> ACK and worth backporting on *-maint branches.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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] qemu: fix lastError memory leak

2013-12-02 Thread Eric Blake
On 12/02/2013 06:25 AM, Wangyufei (James) wrote:
> When an error occurred in qemuMonitorIO, it will be saved in mon->lastError,
> but the memory which mon->lastError.message, mon->lastError.str1,
> mon->lastError.str2 and mon->lastError.str3 will not be freed at last.
> The same bug happened in qemuAgentIO. So I add the following code to fix it.
> 

Do you have a valgrind trace of the leak?  It's not strictly required,
but having it would help prove that this is the right fix.

> Signed-off-by: Zhou Yimin 
> ---
>  src/qemu/qemu_agent.c   |2 ++
>  src/qemu/qemu_monitor.c |2 ++
>  2 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
> index 2cd0ccc..475b43e 100644
> --- a/src/qemu/qemu_agent.c
> +++ b/src/qemu/qemu_agent.c
> @@ -161,6 +161,8 @@ static void qemuAgentDispose(void *obj)
>  (mon->cb->destroy)(mon, mon->vm);
>  virCondDestroy(&mon->notify);
>  VIR_FREE(mon->buffer);
> +if (mon->lastError.code != VIR_ERR_OK)
> +virResetError(&mon->lastError);

Shouldn't we just reset mon->lastError unconditionally?

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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 python] Skip copying manually written python for C APIs which don't exist

2013-12-02 Thread Eric Blake
On 11/27/2013 04:14 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" 
> 
> If the libvirt-override-vir.py file has methods which call
> C APIs that don't exist in the version of libvirt built against
> we need to skip copying their code.
> 
> eg for 0.9.13 libvirt we should not copy the 'listAllDomains'
> method.
> 
> The way this works is that it breaks the override file into
> individual methods by looking for ' def '. It then collects
> the contents until the next method start, whereupon it looks
> for a libvirtmod.XX API call. It checks if the X part
> is present in the XML description we have, and if not, it
> discards the entire method.
> 
> Signed-off-by: Daniel P. Berrange 
> ---
>  generator.py | 42 +-
>  1 file changed, 41 insertions(+), 1 deletion(-)

I see this got committed prior to the release (good); but never reviewed...

My python is weak, so I only spotted something on the surface:


> +if offset != -1:
> +func = line[offset + 11:]
> +offset = func.find("(")
> +func = func[0:offset]
> +if func not in functions_skipped:
> +return True
> +return False
> +
> +for line in extra.readlines():
> +offset = line.find(" def ")
> +if offset != -1:
> +name = line[offset+5:]

Inconsistent spacing around '+'

Other than that, I assume it works, so belated ack :)

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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

Re: [libvirt] [libvirt-users] virsh detach typo

2013-12-02 Thread Eric Blake
On 12/02/2013 02:28 PM, Mauricio Tavares wrote:
> [root@vmhost vms]# virsh detach-disk puppet  vdb
> error: No found disk whose source path or target is vdb
> 
> [root@vmhost vms]# virsh --version
> 0.10.2
> [root@vmhost vms]#
> 
> This probably was solved already but if not, "No found disk" probably
> sounds better if it was "No disk found"

Sure.  I'm pushing this under the trivial rule:

From aaa7484097333c8194ee6323f5a479e8121cc18c Mon Sep 17 00:00:00 2001
From: Eric Blake 
Date: Mon, 2 Dec 2013 14:40:15 -0700
Subject: [PATCH] virsh: improve grammar in error message

Based on a suggestion from Mauricio Tavares.

* tools/virsh-domain.c (cmdDetachInterface, vshFindDisk): Improve
wording.

Signed-off-by: Eric Blake 
---
 tools/virsh-domain.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 1fe138c..8b80e1e 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -9802,7 +9802,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
 obj = xmlXPathEval(BAD_CAST buf, ctxt);
 if (obj == NULL || obj->type != XPATH_NODESET ||
 obj->nodesetval == NULL || obj->nodesetval->nodeNr == 0) {
-vshError(ctl, _("No found interface whose type is %s"), type);
+vshError(ctl, _("No interface found whose type is %s"), type);
 goto cleanup;
 }

@@ -9960,7 +9960,7 @@ vshFindDisk(const char *doc,
 }
 }

-vshError(NULL, _("No found disk whose source path or target is
%s"), path);
+vshError(NULL, _("No disk found whose source path or target is
%s"), path);

 cleanup:
 xmlXPathFreeObject(obj);
-- 
1.8.3.1



-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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 v2 2/2] qemu: add support for -device pvpanic

2013-12-02 Thread Eric Blake
On 12/01/2013 11:11 PM, Hu Tao wrote:
> This patch will add -device pvpanic to qemu command line if user enables
> pvpanic in domain xml and the qemu version supports pvpanic.
> 
> Signed-off-by: Hu Tao 
> ---
>  src/qemu/qemu_capabilities.c |  3 +++
>  src/qemu/qemu_capabilities.h |  2 ++
>  src/qemu/qemu_command.c  | 10 ++
>  3 files changed, 15 insertions(+)
> 

In addition to Peter's comments,

> +++ b/src/qemu/qemu_capabilities.h
> @@ -199,6 +199,8 @@ enum virQEMUCapsFlags {
>  QEMU_CAPS_DEVICE_ICH9_INTEL_HDA = 158, /* -device ich9-intel-hda */
>  QEMU_CAPS_KVM_PIT_TICK_POLICY = 159, /* kvm-pit.lost_tick_policy */
>  
> +QEMU_CAPS_DEVICE_PVPANIC = 160, /* -device pvpanic */

Alignment looks odd here.

> +if (def->pvpanic &&
> +virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PVPANIC)) {
> +if (def->pvpanic->ioport > 0) {

Again, is port 0 a valid port (given that you initialized it to -1)?

I know we haven't been doing a good job of domxml-from-native, but in
this particular case, can we also fix the command line parser to turn
'-device pvpanic' into the appropriate pvpanic device allocation?

> +} else

Style.  If you used {} for 'if', you must also use it for 'else' (I'm
still not sure how to enforce it by syntax-check, but it's on my list of
things that would be nice to have).

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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 v2 1/2] conf: add xml element devices/pvpanic

2013-12-02 Thread Eric Blake
On 12/01/2013 11:11 PM, Hu Tao wrote:
> This patch adds a new xml element devices/pvpanic to support qemu device
> pvpanic. It can be used to receive guest panic notification.
> 
> Signed-off-by: Hu Tao 
> ---
>  docs/formatdomain.html.in | 25 +
>  src/conf/domain_conf.c| 68 
> +++
>  src/conf/domain_conf.h|  9 +++
>  3 files changed, 102 insertions(+)

In addition to Peter's review:

when sending a series, it helps to include a 0/2 cover letter (git
send-email --cover-letter).

> 
> diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> index 1850a2b..0a72baa 100644
> --- a/docs/formatdomain.html.in
> +++ b/docs/formatdomain.html.in
> @@ -5080,6 +5080,31 @@ qemu-kvm -net nic,model=? /dev/null
>  
>
>  
> +pvpanic device

pvpanic is a qemu term, but I could see the feasibility of other
hypervisors having a paravirt device with a sole purpose of notifying
the host about panics.  Do we want to come up with a more generic name?

> +  
> +
> +  
> +  ...
> +
> +  
> +ioport
> +
> +  
> +ioport used by pvpanic.

Probably worth documenting that 0x505 is the default port, and that most
users don't need to specify the ioport.


> +ioport = virXMLPropString(node, "ioport");
> +if (!ioport) {
> +pvpanic->ioport = -1;
> +} else {
> +if (virStrToLong_i(ioport, NULL, 0, &pvpanic->ioport) < 0) {
> +virReportError(VIR_ERR_INTERNAL_ERROR, "%s",

VIR_ERR_INTERNAL_ERROR is probably the wrong type, since this is easily
triggered by a user.  I know it's copy and paste from other code, but
these days, VIR_ERR_XML_ERROR is preferred in new code reporting a parse
error.

Should virDomainDeviceType be enhanced to include this device type?  And
if so, you need to modify at least virDomainDeviceDefFree() to handle
the new enum value.

> +static int virDomainPvpanicDefFormat(virBufferPtr buf,
> + virDomainPvpanicDefPtr def)
> +{
> +if (def->ioport > 0) {

Isn't this an off-by-one if someone explicitly requests port 0 (since
your parser initializes to -1 when left unspecified)?

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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] qemu: add "-boot strict" to commandline whenever possible

2013-12-02 Thread Eric Blake
On 12/02/2013 05:41 AM, Laine Stump wrote:
> This resolves:
> 
>   https://bugzilla.redhat.com/show_bug.cgi?id=888635
> 
> (which was already closed as CANTFIX because the qemu "-boot strict"
> commandline option wasn't available at the time).
> 
> Problem: you couldn't have a domain that used PXE to boot, but also
> had an un-bootable disk device *even if that disk wasn't listed in the
> boot order*, because if PXE timed out (e.g. due to the bridge
> forwarding delay), the BIOS would move on to the next target, which
> would be the unbootable disk device (again - even though it wasn't
> given a boot order), and get stuck at a "BOOT DISK FAILURE, PRESS ANY
> KEY" message until a user intervened.
> 
> The solution available since sometime around QEMU 1.5, is to add
> "-boot strict=on" to *every* qemu command. When this is done, if any
> devices have a boot order specified, then QEMU will *only* attempt to
> boot from those devices that have an explicit boot order, ignoring the
> rest.
> ---
>  src/qemu/qemu_capabilities.c  | 3 +++
>  src/qemu/qemu_capabilities.h  | 1 +
>  src/qemu/qemu_command.c   | 6 ++
>  tests/qemucapabilitiesdata/caps_1.5.3-1.caps  | 1 +
>  tests/qemucapabilitiesdata/caps_1.6.0-1.caps  | 1 +
>  tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 +
>  tests/qemuxml2argvtest.c  | 4 
>  7 files changed, 17 insertions(+)

ACK.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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] Fix VMware support for Fusion 6 / Workstation 10

2013-12-02 Thread Doug Goldstein
On Mon, Dec 2, 2013 at 3:54 AM, Daniel P. Berrange  wrote:
> On Sat, Nov 30, 2013 at 07:51:10PM -0500, Brad Ackerman wrote:
>> This patch gets VMware Fusion 6 working, but the support for
>> ThinPrint needs work—I’m not sure what a good way would be to
>> represent that in libvirt; none of the existing virDomainChrType
>> values seem to be appropriate.
>
> Can you explain a bit what ThinPrint is ?
>
>
> BTW, it is preferrable to attach patches as text/plain rather
> than a binary mode, or have them inline. Best yet is to use
> git send-email to submit them since that trivally gets the
> formatted correct for you
>
> Regards,
> Daniel

>From everything I can tell they licensed a cloud printing tech that's
print first and select a printer later. So basically it allows you to
print from within your VM and queue it up on the host and then select
the printer from the host side. The advantage here is that you don't
have to pass through all the printers to the guest or have drivers
within the guest. They are expressing it as a type of serial device
within their configs. I believe VMware has an interface like
virtio-serial that they can generically plumb things over to the
guest.

Right now I'm skipping expressing the device in libvirt until I come
up with a better way to model it. Based on my description above do you
have any suggestions?

This patch also has a number of fixes that are independent tied
together. We'll also need some tests added for at least one of these
changes.

-- 
Doug Goldstein

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

Re: [libvirt] [PATCH] Added python binding for the new network events API

2013-12-02 Thread Eric Blake
On 11/29/2013 08:27 AM, Cédric Bosdonnat wrote:
> This patch was extracted from the network events feature patch to fit the
> new libvirt-python repository.

Thanks for remembering this.  In the future, if you will do a one-time:

 git config format.subjectprefix "python PATCH"

then it will be more obvious which repo your patch applies to.


> +
> +def networkEventDeregisterAny(self, callbackID):
> +"""Removes a Network Event Callback. De-registering for a
> +   network callback will disable delivery of this event type """

Trailing space inside the doc text looks odd

> +libvirt_virConnectNetworkEventLifecycleCallback(virConnectPtr conn 
> ATTRIBUTE_UNUSED,
> +   virNetworkPtr net,
> +   int event,
> +   void *opaque)
> +{
> +PyObject *pyobj_cbData = (PyObject*)opaque;
> +PyObject *pyobj_net;
> +PyObject *pyobj_ret;
> +PyObject *pyobj_conn;
> +PyObject *dictKey;
> +int ret = -1;
> +
> +LIBVIRT_ENSURE_THREAD_STATE;
> +
> +/* Create a python instance of this virNetworkPtr */
> +virNetworkRef(net);
> +pyobj_net = libvirt_virNetworkPtrWrap(net);
> +Py_INCREF(pyobj_cbData);
> +
> +dictKey = libvirt_constcharPtrWrap("conn");
> +pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);

Copy and paste, but can't dictKey be NULL if libvirt_constcharPtrWrap()
hit an OOM error, in which case PyDict_GetItem() will crash?


> +static PyObject *
> +libvirt_virConnectNetworkEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self,
> + PyObject * args)

Style: We put the * flush with the variable name, and usually place
attributes after rather than before:

(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)


-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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] Add docs about audit subsystem logging

2013-12-02 Thread Eric Blake
On 12/02/2013 11:58 AM, Eric Blake wrote:
> On 11/29/2013 09:23 AM, Daniel P. Berrange wrote:
>> From: "Daniel P. Berrange" 
>>
>> Adds a new page to the website "Deployment" section describing
>> what data is sent to the audit logs and how to configure libvirtd
>> audit settings.
>>
>> Signed-off-by: Daniel P. Berrange 
>> ---
>>  docs/auditlog.html.in | 321 
>> ++
>>  docs/sitemap.html.in  |   4 +
>>  2 files changed, 325 insertions(+)
>>  create mode 100644 docs/auditlog.html.in
> 
> Already in, but these nits need fixing:
> 
>> +
>> +
>> +  If there is a host network interace associated with the guest NIC then
> 
> s/interace/interface/
> 
> 
>> +  chardev
>> +  The path of the charecter device assigned to the guest, if 
>> resrc=hostdev
> 
> s/charecter/character/
> 

So I pushed them as a trivial fix.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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] Add docs about audit subsystem logging

2013-12-02 Thread Eric Blake
On 11/29/2013 09:23 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" 
> 
> Adds a new page to the website "Deployment" section describing
> what data is sent to the audit logs and how to configure libvirtd
> audit settings.
> 
> Signed-off-by: Daniel P. Berrange 
> ---
>  docs/auditlog.html.in | 321 
> ++
>  docs/sitemap.html.in  |   4 +
>  2 files changed, 325 insertions(+)
>  create mode 100644 docs/auditlog.html.in

Already in, but these nits need fixing:

> +
> +
> +  If there is a host network interace associated with the guest NIC then

s/interace/interface/


> +  chardev
> +  The path of the charecter device assigned to the guest, if 
> resrc=hostdev

s/charecter/character/

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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

Re: [libvirt] GlusterFS with libvirt

2013-12-02 Thread Eric Blake
On 11/28/2013 08:22 PM, Umar Draz wrote:
> HI Weiqing,

[Please don't top-post on technical lists]

> 
> Yes I want storage pool of glusterfs.
> 
> http://www.gluster.org/community/documentation/images/9/9d/QEMU_GlusterFS.pdf

Are you using libvirt 1.2.0 (released today)?  If so, a gluster storage
pool is one of today's brand new features - and testing is appreciated :)

>>>
>>> I tried the following, but its not working.
>>>
>>> qemu-img: Unknown protocol 'gluster://localhost/gv1/test.img'

That's from qemu-img rather than libvirt; are you sure you are using a
new-enough qemu, and that your build of qemu included libgfapi support?

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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

[libvirt] [PATCH] docs: fix typo in previous patch

2013-12-02 Thread Eric Blake
Avoid a nested comment compilation error.

* include/libvirt/libvirt.h.in: Fix typo.

Signed-off-by: Eric Blake 
---

Pushing as trivial/build-breaker, and sorry for the one-byte mistake.

 include/libvirt/libvirt.h.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 496986e..29d4dce 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -3587,7 +3587,7 @@ typedef enum {

 /**
  * virDomainEventCrashedDetailType:
-/*
+ *
  * Details on the cause of a 'crashed' lifecycle event
  */
 typedef enum {
-- 
1.8.3.1

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


Re: [libvirt] Internal error message from netcf when trying to start libvirtd

2013-12-02 Thread Daniel P. Berrange
On Mon, Dec 02, 2013 at 06:53:37PM +0100, Michal Privoznik wrote:
> On 02.12.2013 18:40, Daniel P. Berrange wrote:
> > On Mon, Dec 02, 2013 at 06:38:37PM +0100, Michal Privoznik wrote:
> >> On 02.12.2013 18:24, Daniel P. Berrange wrote:
> >>> On Mon, Dec 02, 2013 at 06:17:00PM +0100, Michal Privoznik wrote:
>  On 17.10.2013 14:40, Daniel P. Berrange wrote:
> > On Tue, Oct 15, 2013 at 06:03:27PM +0200, Christophe Fergeau wrote:
> >> Hey,
> >>
> >> Due to a configuration issue on my system, libvirtd is not starting on 
> >> my
> >> system (not complaining about this!):
> >> 2013-10-15 15:40:51.024+: 10222: info : libvirt version: 1.1.3
> >> 2013-10-15 15:40:51.024+: 10222: error : 
> >> virNetTLSContextCheckCertFile:117 : Cannot read CA certificate
> >> '/home/teuf/usr/etc/pki/CA/cacert.pem': No such file or directory
> >>
> >> However, before libvirtd exits, I get another error message from the 
> >> netcf
> >> code, which is unexpected this time:
> >> 2013-10-15 15:49:18.361+: 10222: error : netcfStateCleanup:105 :
> >> internal error: Attempt to close netcf state driver already closed
> >>
> >> This message comes from the call of virStateCleanup() at the end of 
> >> main()
> >> in libvirtd.c. virStateCleanup() should not be called before
> >> daemonStateInit() has been called in main.
> >> After this call, things get more ugly as daemonStateInit() calls
> >> virStateInitialize() from a thread, so there's probably a small window 
> >> for
> >> virStateInitialize() and virStateCleanup() running concurrently if an 
> >> error
> >> occurs between the call to daemonStateInit() and the call to
> >> virNetServerRun().
> >>
> >> I'm sending this email rather than a patch as I'm not sure what is the 
> >> best
> >> way to fix it. The easy way would be for virStateCleanup() to be a noop
> >> when virStateInitialize() hasn't been called (iow remove the error 
> >> message
> >> from netcfStateCleanup). However, this would leave this small race
> >> condition around (which is not that bad as it would only occurs in
> >> situations when the daemon fails to start). So another approach would 
> >> be to
> >> set a vir_state_initialized boolean once the thread has called
> >> ivrStateInitialize, and only call virStateCleanup() when it's set.
> >>
> >> Or maybe there's a 3rd way to fix this?
> >>
> >> Let me know if you have any guidance into the best way to fix this,
> >
> > Yeah, I've known about this issue for a while and its a bit horrible
> > to solve. I think we probably need to have a global mutex to serialize
> > the virStateInitialize, virStateReload and virStateCleanup calls so
> > that none of them can run in parallel.
> >
> > I'd have virGlobalInit create the mutex instance, since we know that
> > is run from thread safe context.
> >
> > Then make the virState* calls hold that mutex while executing.
> >
> > We don't want virStateCleanup to skip execution if virStateInitialize
> > has failed though - every callback in virStateCleanup should be written
> > to be safe if its corresponding init function hasn't run. Just the
> > mutex serialization ought to be sufficient I think.
> >
> >
> > Daniel
> >
> 
>  Sorry for bringing up a dead thread, but as you both may have noticed I
>  was trying to solve this too:
> 
>  https://www.redhat.com/archives/libvir-list/2013-November/msg01311.html
> 
>  And I don't think Dan, your approach is gonna work. I mean, the reason
>  for running virStateInitialize in thread is - it may take ages to
> >>>
> >>> Actually no, the reason for using a thread is that the initialization
> >>> code needs to have a working event loop - so you cannot run the
> >>> virStateInitialize code from the same thread that is running the
> >>> event loop.
> >>
> >> Okay, this might be the reason too.
> >>
> >>>
> >>> You're probably thinking of the QEMU VM autostart code, whicih spawns a
> >>> separate thread to auto-start QEMU VMs to avoid delaying use of the QEMU
> >>> driver while (slow) autostart takes place.
> >>>
> >>
> >> No. I am thinking of the stateAutostart member which is called from
> >> within virStateInitialize(). In case of qemu driver it's
> >> qemuStateAutoStart() what is called, which boils down to calling
> >> qemuProcessStart over each autostart domain without spawning a separate
> >> thread for it. The thread you have in mind is used for
> >> qemuProcessReconnect() not qemuProcessStart().
> >>
>  complete. Hence, serializing virState* will lead to main thread waiting
>  for the virStateInitialize to complete (which may not happen, i.e. in
>  case of deadlock somewhere in a driver).
> 
>  But I was thinking of rather refined locking. Turning each of
>  vir*DriverTa

Re: [libvirt] Internal error message from netcf when trying to start libvirtd

2013-12-02 Thread Michal Privoznik
On 02.12.2013 18:40, Daniel P. Berrange wrote:
> On Mon, Dec 02, 2013 at 06:38:37PM +0100, Michal Privoznik wrote:
>> On 02.12.2013 18:24, Daniel P. Berrange wrote:
>>> On Mon, Dec 02, 2013 at 06:17:00PM +0100, Michal Privoznik wrote:
 On 17.10.2013 14:40, Daniel P. Berrange wrote:
> On Tue, Oct 15, 2013 at 06:03:27PM +0200, Christophe Fergeau wrote:
>> Hey,
>>
>> Due to a configuration issue on my system, libvirtd is not starting on my
>> system (not complaining about this!):
>> 2013-10-15 15:40:51.024+: 10222: info : libvirt version: 1.1.3
>> 2013-10-15 15:40:51.024+: 10222: error : 
>> virNetTLSContextCheckCertFile:117 : Cannot read CA certificate
>> '/home/teuf/usr/etc/pki/CA/cacert.pem': No such file or directory
>>
>> However, before libvirtd exits, I get another error message from the 
>> netcf
>> code, which is unexpected this time:
>> 2013-10-15 15:49:18.361+: 10222: error : netcfStateCleanup:105 :
>> internal error: Attempt to close netcf state driver already closed
>>
>> This message comes from the call of virStateCleanup() at the end of 
>> main()
>> in libvirtd.c. virStateCleanup() should not be called before
>> daemonStateInit() has been called in main.
>> After this call, things get more ugly as daemonStateInit() calls
>> virStateInitialize() from a thread, so there's probably a small window 
>> for
>> virStateInitialize() and virStateCleanup() running concurrently if an 
>> error
>> occurs between the call to daemonStateInit() and the call to
>> virNetServerRun().
>>
>> I'm sending this email rather than a patch as I'm not sure what is the 
>> best
>> way to fix it. The easy way would be for virStateCleanup() to be a noop
>> when virStateInitialize() hasn't been called (iow remove the error 
>> message
>> from netcfStateCleanup). However, this would leave this small race
>> condition around (which is not that bad as it would only occurs in
>> situations when the daemon fails to start). So another approach would be 
>> to
>> set a vir_state_initialized boolean once the thread has called
>> ivrStateInitialize, and only call virStateCleanup() when it's set.
>>
>> Or maybe there's a 3rd way to fix this?
>>
>> Let me know if you have any guidance into the best way to fix this,
>
> Yeah, I've known about this issue for a while and its a bit horrible
> to solve. I think we probably need to have a global mutex to serialize
> the virStateInitialize, virStateReload and virStateCleanup calls so
> that none of them can run in parallel.
>
> I'd have virGlobalInit create the mutex instance, since we know that
> is run from thread safe context.
>
> Then make the virState* calls hold that mutex while executing.
>
> We don't want virStateCleanup to skip execution if virStateInitialize
> has failed though - every callback in virStateCleanup should be written
> to be safe if its corresponding init function hasn't run. Just the
> mutex serialization ought to be sufficient I think.
>
>
> Daniel
>

 Sorry for bringing up a dead thread, but as you both may have noticed I
 was trying to solve this too:

 https://www.redhat.com/archives/libvir-list/2013-November/msg01311.html

 And I don't think Dan, your approach is gonna work. I mean, the reason
 for running virStateInitialize in thread is - it may take ages to
>>>
>>> Actually no, the reason for using a thread is that the initialization
>>> code needs to have a working event loop - so you cannot run the
>>> virStateInitialize code from the same thread that is running the
>>> event loop.
>>
>> Okay, this might be the reason too.
>>
>>>
>>> You're probably thinking of the QEMU VM autostart code, whicih spawns a
>>> separate thread to auto-start QEMU VMs to avoid delaying use of the QEMU
>>> driver while (slow) autostart takes place.
>>>
>>
>> No. I am thinking of the stateAutostart member which is called from
>> within virStateInitialize(). In case of qemu driver it's
>> qemuStateAutoStart() what is called, which boils down to calling
>> qemuProcessStart over each autostart domain without spawning a separate
>> thread for it. The thread you have in mind is used for
>> qemuProcessReconnect() not qemuProcessStart().
>>
 complete. Hence, serializing virState* will lead to main thread waiting
 for the virStateInitialize to complete (which may not happen, i.e. in
 case of deadlock somewhere in a driver).

 But I was thinking of rather refined locking. Turning each of
 vir*DriverTab into virObjectLockable(). Then, each access would require
 object to lock itself. Moreover, the virStateCleanup would unregister
 the driver. Unfortunately, it could only unregister stateful drivers.
>>>
>>> This race condition scenario only hits us in two cases
>>>
>>>

Re: [libvirt] [PATCH 1/4] Add USB Keyboard support in libvirt

2013-12-02 Thread Nehal J Wani
> +QEMU_CAPS_DEVICE_USB_KBD = 160, /*-device usb-kbd*/
> +

Why this extra newline?

>
>  QEMU_CAPS_LAST,   /* this must always be the last item */
>  };
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 763417f..318f7a1 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -5280,9 +5280,15 @@ qemuBuildUSBInputDevStr(virDomainDefPtr def,
>  {
>  virBuffer buf = VIR_BUFFER_INITIALIZER;
>
> -virBufferAsprintf(&buf, "%s,id=%s",
> -  dev->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ?
> -  "usb-mouse" : "usb-tablet", dev->info.alias);
> +if (dev->type == VIR_DOMAIN_INPUT_TYPE_MOUSE) {
> +virBufferAsprintf(&buf, "usb-mouse,id=%s", dev->info.alias);
> +} else if (dev->type == VIR_DOMAIN_INPUT_TYPE_TABLET) {
> +virBufferAsprintf(&buf, "usb-tablet,id=%s", dev->info.alias);
> +} else if (dev->type == VIR_DOMAIN_INPUT_TYPE_KBD) {
> +if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_USB_KBD))
> +goto error;
> +virBufferAsprintf(&buf, "usb-kbd,id=%s", dev->info.alias);
> +}

I would've used switch(dev->type) instead of 'if else', to make it look simple.

-- 
Nehal J Wani

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


Re: [libvirt] Internal error message from netcf when trying to start libvirtd

2013-12-02 Thread Daniel P. Berrange
On Mon, Dec 02, 2013 at 06:38:37PM +0100, Michal Privoznik wrote:
> On 02.12.2013 18:24, Daniel P. Berrange wrote:
> > On Mon, Dec 02, 2013 at 06:17:00PM +0100, Michal Privoznik wrote:
> >> On 17.10.2013 14:40, Daniel P. Berrange wrote:
> >>> On Tue, Oct 15, 2013 at 06:03:27PM +0200, Christophe Fergeau wrote:
>  Hey,
> 
>  Due to a configuration issue on my system, libvirtd is not starting on my
>  system (not complaining about this!):
>  2013-10-15 15:40:51.024+: 10222: info : libvirt version: 1.1.3
>  2013-10-15 15:40:51.024+: 10222: error : 
>  virNetTLSContextCheckCertFile:117 : Cannot read CA certificate
>  '/home/teuf/usr/etc/pki/CA/cacert.pem': No such file or directory
> 
>  However, before libvirtd exits, I get another error message from the 
>  netcf
>  code, which is unexpected this time:
>  2013-10-15 15:49:18.361+: 10222: error : netcfStateCleanup:105 :
>  internal error: Attempt to close netcf state driver already closed
> 
>  This message comes from the call of virStateCleanup() at the end of 
>  main()
>  in libvirtd.c. virStateCleanup() should not be called before
>  daemonStateInit() has been called in main.
>  After this call, things get more ugly as daemonStateInit() calls
>  virStateInitialize() from a thread, so there's probably a small window 
>  for
>  virStateInitialize() and virStateCleanup() running concurrently if an 
>  error
>  occurs between the call to daemonStateInit() and the call to
>  virNetServerRun().
> 
>  I'm sending this email rather than a patch as I'm not sure what is the 
>  best
>  way to fix it. The easy way would be for virStateCleanup() to be a noop
>  when virStateInitialize() hasn't been called (iow remove the error 
>  message
>  from netcfStateCleanup). However, this would leave this small race
>  condition around (which is not that bad as it would only occurs in
>  situations when the daemon fails to start). So another approach would be 
>  to
>  set a vir_state_initialized boolean once the thread has called
>  ivrStateInitialize, and only call virStateCleanup() when it's set.
> 
>  Or maybe there's a 3rd way to fix this?
> 
>  Let me know if you have any guidance into the best way to fix this,
> >>>
> >>> Yeah, I've known about this issue for a while and its a bit horrible
> >>> to solve. I think we probably need to have a global mutex to serialize
> >>> the virStateInitialize, virStateReload and virStateCleanup calls so
> >>> that none of them can run in parallel.
> >>>
> >>> I'd have virGlobalInit create the mutex instance, since we know that
> >>> is run from thread safe context.
> >>>
> >>> Then make the virState* calls hold that mutex while executing.
> >>>
> >>> We don't want virStateCleanup to skip execution if virStateInitialize
> >>> has failed though - every callback in virStateCleanup should be written
> >>> to be safe if its corresponding init function hasn't run. Just the
> >>> mutex serialization ought to be sufficient I think.
> >>>
> >>>
> >>> Daniel
> >>>
> >>
> >> Sorry for bringing up a dead thread, but as you both may have noticed I
> >> was trying to solve this too:
> >>
> >> https://www.redhat.com/archives/libvir-list/2013-November/msg01311.html
> >>
> >> And I don't think Dan, your approach is gonna work. I mean, the reason
> >> for running virStateInitialize in thread is - it may take ages to
> > 
> > Actually no, the reason for using a thread is that the initialization
> > code needs to have a working event loop - so you cannot run the
> > virStateInitialize code from the same thread that is running the
> > event loop.
> 
> Okay, this might be the reason too.
> 
> > 
> > You're probably thinking of the QEMU VM autostart code, whicih spawns a
> > separate thread to auto-start QEMU VMs to avoid delaying use of the QEMU
> > driver while (slow) autostart takes place.
> > 
> 
> No. I am thinking of the stateAutostart member which is called from
> within virStateInitialize(). In case of qemu driver it's
> qemuStateAutoStart() what is called, which boils down to calling
> qemuProcessStart over each autostart domain without spawning a separate
> thread for it. The thread you have in mind is used for
> qemuProcessReconnect() not qemuProcessStart().
> 
> >> complete. Hence, serializing virState* will lead to main thread waiting
> >> for the virStateInitialize to complete (which may not happen, i.e. in
> >> case of deadlock somewhere in a driver).
> >>
> >> But I was thinking of rather refined locking. Turning each of
> >> vir*DriverTab into virObjectLockable(). Then, each access would require
> >> object to lock itself. Moreover, the virStateCleanup would unregister
> >> the driver. Unfortunately, it could only unregister stateful drivers.
> > 
> > This race condition scenario only hits us in two cases
> > 
> >  - libvirtd startup is being aborted due to some fa

Re: [libvirt] Internal error message from netcf when trying to start libvirtd

2013-12-02 Thread Michal Privoznik
On 02.12.2013 18:24, Daniel P. Berrange wrote:
> On Mon, Dec 02, 2013 at 06:17:00PM +0100, Michal Privoznik wrote:
>> On 17.10.2013 14:40, Daniel P. Berrange wrote:
>>> On Tue, Oct 15, 2013 at 06:03:27PM +0200, Christophe Fergeau wrote:
 Hey,

 Due to a configuration issue on my system, libvirtd is not starting on my
 system (not complaining about this!):
 2013-10-15 15:40:51.024+: 10222: info : libvirt version: 1.1.3
 2013-10-15 15:40:51.024+: 10222: error : 
 virNetTLSContextCheckCertFile:117 : Cannot read CA certificate
 '/home/teuf/usr/etc/pki/CA/cacert.pem': No such file or directory

 However, before libvirtd exits, I get another error message from the netcf
 code, which is unexpected this time:
 2013-10-15 15:49:18.361+: 10222: error : netcfStateCleanup:105 :
 internal error: Attempt to close netcf state driver already closed

 This message comes from the call of virStateCleanup() at the end of main()
 in libvirtd.c. virStateCleanup() should not be called before
 daemonStateInit() has been called in main.
 After this call, things get more ugly as daemonStateInit() calls
 virStateInitialize() from a thread, so there's probably a small window for
 virStateInitialize() and virStateCleanup() running concurrently if an error
 occurs between the call to daemonStateInit() and the call to
 virNetServerRun().

 I'm sending this email rather than a patch as I'm not sure what is the best
 way to fix it. The easy way would be for virStateCleanup() to be a noop
 when virStateInitialize() hasn't been called (iow remove the error message
 from netcfStateCleanup). However, this would leave this small race
 condition around (which is not that bad as it would only occurs in
 situations when the daemon fails to start). So another approach would be to
 set a vir_state_initialized boolean once the thread has called
 ivrStateInitialize, and only call virStateCleanup() when it's set.

 Or maybe there's a 3rd way to fix this?

 Let me know if you have any guidance into the best way to fix this,
>>>
>>> Yeah, I've known about this issue for a while and its a bit horrible
>>> to solve. I think we probably need to have a global mutex to serialize
>>> the virStateInitialize, virStateReload and virStateCleanup calls so
>>> that none of them can run in parallel.
>>>
>>> I'd have virGlobalInit create the mutex instance, since we know that
>>> is run from thread safe context.
>>>
>>> Then make the virState* calls hold that mutex while executing.
>>>
>>> We don't want virStateCleanup to skip execution if virStateInitialize
>>> has failed though - every callback in virStateCleanup should be written
>>> to be safe if its corresponding init function hasn't run. Just the
>>> mutex serialization ought to be sufficient I think.
>>>
>>>
>>> Daniel
>>>
>>
>> Sorry for bringing up a dead thread, but as you both may have noticed I
>> was trying to solve this too:
>>
>> https://www.redhat.com/archives/libvir-list/2013-November/msg01311.html
>>
>> And I don't think Dan, your approach is gonna work. I mean, the reason
>> for running virStateInitialize in thread is - it may take ages to
> 
> Actually no, the reason for using a thread is that the initialization
> code needs to have a working event loop - so you cannot run the
> virStateInitialize code from the same thread that is running the
> event loop.

Okay, this might be the reason too.

> 
> You're probably thinking of the QEMU VM autostart code, whicih spawns a
> separate thread to auto-start QEMU VMs to avoid delaying use of the QEMU
> driver while (slow) autostart takes place.
> 

No. I am thinking of the stateAutostart member which is called from
within virStateInitialize(). In case of qemu driver it's
qemuStateAutoStart() what is called, which boils down to calling
qemuProcessStart over each autostart domain without spawning a separate
thread for it. The thread you have in mind is used for
qemuProcessReconnect() not qemuProcessStart().

>> complete. Hence, serializing virState* will lead to main thread waiting
>> for the virStateInitialize to complete (which may not happen, i.e. in
>> case of deadlock somewhere in a driver).
>>
>> But I was thinking of rather refined locking. Turning each of
>> vir*DriverTab into virObjectLockable(). Then, each access would require
>> object to lock itself. Moreover, the virStateCleanup would unregister
>> the driver. Unfortunately, it could only unregister stateful drivers.
> 
> This race condition scenario only hits us in two cases
> 
>  - libvirtd startup is being aborted due to some failure
>while StateInit is still running
>  - libvirtd reload is triggered by SIGHUP causing StateReload
>to run

I can see the third scenario: the daemon exiting the event loop, i.e. as
a result of timeout or SIGINT. In this case you don't want to wait for
virStateInitialize() to finish, do you?

> 
> In both o

Re: [libvirt] Internal error message from netcf when trying to start libvirtd

2013-12-02 Thread Daniel P. Berrange
On Mon, Dec 02, 2013 at 06:17:00PM +0100, Michal Privoznik wrote:
> On 17.10.2013 14:40, Daniel P. Berrange wrote:
> > On Tue, Oct 15, 2013 at 06:03:27PM +0200, Christophe Fergeau wrote:
> >> Hey,
> >>
> >> Due to a configuration issue on my system, libvirtd is not starting on my
> >> system (not complaining about this!):
> >> 2013-10-15 15:40:51.024+: 10222: info : libvirt version: 1.1.3
> >> 2013-10-15 15:40:51.024+: 10222: error : 
> >> virNetTLSContextCheckCertFile:117 : Cannot read CA certificate
> >> '/home/teuf/usr/etc/pki/CA/cacert.pem': No such file or directory
> >>
> >> However, before libvirtd exits, I get another error message from the netcf
> >> code, which is unexpected this time:
> >> 2013-10-15 15:49:18.361+: 10222: error : netcfStateCleanup:105 :
> >> internal error: Attempt to close netcf state driver already closed
> >>
> >> This message comes from the call of virStateCleanup() at the end of main()
> >> in libvirtd.c. virStateCleanup() should not be called before
> >> daemonStateInit() has been called in main.
> >> After this call, things get more ugly as daemonStateInit() calls
> >> virStateInitialize() from a thread, so there's probably a small window for
> >> virStateInitialize() and virStateCleanup() running concurrently if an error
> >> occurs between the call to daemonStateInit() and the call to
> >> virNetServerRun().
> >>
> >> I'm sending this email rather than a patch as I'm not sure what is the best
> >> way to fix it. The easy way would be for virStateCleanup() to be a noop
> >> when virStateInitialize() hasn't been called (iow remove the error message
> >> from netcfStateCleanup). However, this would leave this small race
> >> condition around (which is not that bad as it would only occurs in
> >> situations when the daemon fails to start). So another approach would be to
> >> set a vir_state_initialized boolean once the thread has called
> >> ivrStateInitialize, and only call virStateCleanup() when it's set.
> >>
> >> Or maybe there's a 3rd way to fix this?
> >>
> >> Let me know if you have any guidance into the best way to fix this,
> > 
> > Yeah, I've known about this issue for a while and its a bit horrible
> > to solve. I think we probably need to have a global mutex to serialize
> > the virStateInitialize, virStateReload and virStateCleanup calls so
> > that none of them can run in parallel.
> > 
> > I'd have virGlobalInit create the mutex instance, since we know that
> > is run from thread safe context.
> > 
> > Then make the virState* calls hold that mutex while executing.
> > 
> > We don't want virStateCleanup to skip execution if virStateInitialize
> > has failed though - every callback in virStateCleanup should be written
> > to be safe if its corresponding init function hasn't run. Just the
> > mutex serialization ought to be sufficient I think.
> > 
> > 
> > Daniel
> > 
> 
> Sorry for bringing up a dead thread, but as you both may have noticed I
> was trying to solve this too:
> 
> https://www.redhat.com/archives/libvir-list/2013-November/msg01311.html
> 
> And I don't think Dan, your approach is gonna work. I mean, the reason
> for running virStateInitialize in thread is - it may take ages to

Actually no, the reason for using a thread is that the initialization
code needs to have a working event loop - so you cannot run the
virStateInitialize code from the same thread that is running the
event loop.

You're probably thinking of the QEMU VM autostart code, whicih spawns a
separate thread to auto-start QEMU VMs to avoid delaying use of the QEMU
driver while (slow) autostart takes place.

> complete. Hence, serializing virState* will lead to main thread waiting
> for the virStateInitialize to complete (which may not happen, i.e. in
> case of deadlock somewhere in a driver).
> 
> But I was thinking of rather refined locking. Turning each of
> vir*DriverTab into virObjectLockable(). Then, each access would require
> object to lock itself. Moreover, the virStateCleanup would unregister
> the driver. Unfortunately, it could only unregister stateful drivers.

This race condition scenario only hits us in two cases

 - libvirtd startup is being aborted due to some failure
   while StateInit is still running
 - libvirtd reload is triggered by SIGHUP causing StateReload
   to run

In both of those cases I think it is absolutely desirable that
virStateReload and virStateCleanup both block until virStateInitialize
completes.

The question of virStateInitialize deadlock has no bearing on this.
Any such problems are simply a bug that we must fix. So I don't see
why we shouldn't have a global mutex serializing the three
virState{Init,Reload,Cleanup} APIs.

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.gno

Re: [libvirt] Internal error message from netcf when trying to start libvirtd

2013-12-02 Thread Michal Privoznik
On 17.10.2013 14:40, Daniel P. Berrange wrote:
> On Tue, Oct 15, 2013 at 06:03:27PM +0200, Christophe Fergeau wrote:
>> Hey,
>>
>> Due to a configuration issue on my system, libvirtd is not starting on my
>> system (not complaining about this!):
>> 2013-10-15 15:40:51.024+: 10222: info : libvirt version: 1.1.3
>> 2013-10-15 15:40:51.024+: 10222: error : 
>> virNetTLSContextCheckCertFile:117 : Cannot read CA certificate
>> '/home/teuf/usr/etc/pki/CA/cacert.pem': No such file or directory
>>
>> However, before libvirtd exits, I get another error message from the netcf
>> code, which is unexpected this time:
>> 2013-10-15 15:49:18.361+: 10222: error : netcfStateCleanup:105 :
>> internal error: Attempt to close netcf state driver already closed
>>
>> This message comes from the call of virStateCleanup() at the end of main()
>> in libvirtd.c. virStateCleanup() should not be called before
>> daemonStateInit() has been called in main.
>> After this call, things get more ugly as daemonStateInit() calls
>> virStateInitialize() from a thread, so there's probably a small window for
>> virStateInitialize() and virStateCleanup() running concurrently if an error
>> occurs between the call to daemonStateInit() and the call to
>> virNetServerRun().
>>
>> I'm sending this email rather than a patch as I'm not sure what is the best
>> way to fix it. The easy way would be for virStateCleanup() to be a noop
>> when virStateInitialize() hasn't been called (iow remove the error message
>> from netcfStateCleanup). However, this would leave this small race
>> condition around (which is not that bad as it would only occurs in
>> situations when the daemon fails to start). So another approach would be to
>> set a vir_state_initialized boolean once the thread has called
>> ivrStateInitialize, and only call virStateCleanup() when it's set.
>>
>> Or maybe there's a 3rd way to fix this?
>>
>> Let me know if you have any guidance into the best way to fix this,
> 
> Yeah, I've known about this issue for a while and its a bit horrible
> to solve. I think we probably need to have a global mutex to serialize
> the virStateInitialize, virStateReload and virStateCleanup calls so
> that none of them can run in parallel.
> 
> I'd have virGlobalInit create the mutex instance, since we know that
> is run from thread safe context.
> 
> Then make the virState* calls hold that mutex while executing.
> 
> We don't want virStateCleanup to skip execution if virStateInitialize
> has failed though - every callback in virStateCleanup should be written
> to be safe if its corresponding init function hasn't run. Just the
> mutex serialization ought to be sufficient I think.
> 
> 
> Daniel
> 

Sorry for bringing up a dead thread, but as you both may have noticed I
was trying to solve this too:

https://www.redhat.com/archives/libvir-list/2013-November/msg01311.html

And I don't think Dan, your approach is gonna work. I mean, the reason
for running virStateInitialize in thread is - it may take ages to
complete. Hence, serializing virState* will lead to main thread waiting
for the virStateInitialize to complete (which may not happen, i.e. in
case of deadlock somewhere in a driver).

But I was thinking of rather refined locking. Turning each of
vir*DriverTab into virObjectLockable(). Then, each access would require
object to lock itself. Moreover, the virStateCleanup would unregister
the driver. Unfortunately, it could only unregister stateful drivers.

Michal

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


Re: [libvirt] [PATCH] Ensure to zero out the virDomainBlockJobInfo arg

2013-12-02 Thread Eric Blake
On 12/02/2013 09:57 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" 
> 
> The virDomainGetBlockJobInfo method did not zero out the
> virDomainBlockJobInfo pointer arg, so when block jobs were
> not active it would return garbage for the bandwidth/cur/end
> fields.
> 
> Signed-off-by: Daniel P. Berrange 
> ---
>  src/libvirt.c | 2 ++
>  1 file changed, 2 insertions(+)

ACK.

> 
> diff --git a/src/libvirt.c b/src/libvirt.c
> index eff44eb..a2df53d 100644
> --- a/src/libvirt.c
> +++ b/src/libvirt.c
> @@ -20850,6 +20850,8 @@ int virDomainGetBlockJobInfo(virDomainPtr dom, const 
> char *disk,
>  virCheckNonNullArgGoto(disk, error);
>  virCheckNonNullArgGoto(info, error);
>  
> +memset(info, 0, sizeof(*info));
> +
>  if (conn->driver->domainGetBlockJobInfo) {
>  int ret;
>  ret = conn->driver->domainGetBlockJobInfo(dom, disk, info, flags);
> 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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 v2] docs: fix typos in libvirt.h.in

2013-12-02 Thread Eric Blake
On 12/01/2013 07:56 PM, Daniel Veillard wrote:
> On Mon, Dec 02, 2013 at 10:36:16AM +0800, Chen Hanxiao wrote:
>> From: Chen Hanxiao 
>>
>> s/caused/causes
> 
>   ACK, applied and pushed :-)

Actually, see my comments on v1.  "cause" is better than "causes" here.

I'm pushing this:

diff --git c/include/libvirt/libvirt.h.in i/include/libvirt/libvirt.h.in
index 6e480bb..df78783 100644
--- c/include/libvirt/libvirt.h.in
+++ i/include/libvirt/libvirt.h.in
@@ -3463,7 +3463,7 @@ typedef enum {
 /**
  * virDomainEventDefinedDetailType:
  *
- * Details on the causes of the 'defined' lifecycle event
+ * Details on the cause of a 'defined' lifecycle event
  */
 typedef enum {
 VIR_DOMAIN_EVENT_DEFINED_ADDED = 0, /* Newly created config file */
@@ -3477,7 +3477,7 @@ typedef enum {
 /**
  * virDomainEventUndefinedDetailType:
  *
- * Details on the causes of the 'undefined' lifecycle event
+ * Details on the cause of an 'undefined' lifecycle event
  */
 typedef enum {
 VIR_DOMAIN_EVENT_UNDEFINED_REMOVED = 0, /* Deleted the config file */
@@ -3490,7 +3490,7 @@ typedef enum {
 /**
  * virDomainEventStartedDetailType:
  *
- * Details on the causes of the 'started' lifecycle event
+ * Details on the cause of a 'started' lifecycle event
  */
 typedef enum {
 VIR_DOMAIN_EVENT_STARTED_BOOTED = 0,   /* Normal startup from boot */
@@ -3507,7 +3507,7 @@ typedef enum {
 /**
  * virDomainEventSuspendedDetailType:
  *
- * Details on the causes of the 'suspended' lifecycle event
+ * Details on the cause of a 'suspended' lifecycle event
  */
 typedef enum {
 VIR_DOMAIN_EVENT_SUSPENDED_PAUSED = 0,   /* Normal suspend due to
admin pause */
@@ -3526,7 +3526,7 @@ typedef enum {
 /**
  * virDomainEventResumedDetailType:
  *
- * Details on the causes of the 'resumed' lifecycle event
+ * Details on the cause of a 'resumed' lifecycle event
  */
 typedef enum {
 VIR_DOMAIN_EVENT_RESUMED_UNPAUSED = 0,   /* Normal resume due to
admin unpause */
@@ -3541,7 +3541,7 @@ typedef enum {
 /**
  * virDomainEventStoppedDetailType:
  *
- * Details on the causes of the 'stopped' lifecycle event
+ * Details on the cause of a 'stopped' lifecycle event
  */
 typedef enum {
 VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN = 0,  /* Normal shutdown */


-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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] docs: fix typos in libvirt.h.in

2013-12-02 Thread Eric Blake
On 11/28/2013 07:03 AM, Nehal J Wani wrote:
> On Thu, Nov 28, 2013 at 5:31 PM, Chen Hanxiao
>  wrote:
>> From: Chen Hanxiao 
>>

>>  /**
>>   * virDomainEventDefinedDetailType:
>>   *
>> - * Details on the caused of the 'defined' lifecycle event
>> + * Details on the cause of the 'defined' lifecycle event
>>   */
>> 1.8.2.1
>>
> 
> I am no English expert, but would like to ask, if a particular event
> can take place due to multiple reasons, shouldn't it be :
> "Details on the causes of the 'defined' lifecycle event"
> I think the original author made a typo by typing 'd' instead of 's'
> (very close on keyboard), i.e., s/caused/causes

Causes would make sense if you could have a plurality of causes
triggering a single event.  But we don't.  Each event has exactly one
cause.  The patch is correct as-is, so I'll apply it soon.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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

Re: [libvirt] RFC: virsh: add support for redirecting output to files in virsh shell

2013-12-02 Thread Eric Blake
On 11/30/2013 12:00 PM, Nehal J Wani wrote:
> Currently, for redirecting output (most of the times its the output of
> --dumpxml) we use:
> virsh $command > $file
> But such redirection is not possible in virsh shell. It would be great
> if libvirt supported this feature for those who love working in the
> 'virsh shell' (instead of typing 'virsh' before every command).
> 
> A simple approach would be to either add the redirection feature using
> '>' or having some option like -o or --outfile (it would be nice if it
> is available for each command, and not just restricted to --dumpxml
> ones)

Sure - sounds like a welcome addition.  Also useful would be supporting
'-' as a synonym for reading from stdin instead of a file name (as in
'virsh dumpxml | some modification script | virsh define -'; but also
usable from 'virsh' batch mode so that you can do 'define -' and then
just type your definition inline).

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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

[libvirt] [v3 29/32] Add network events unit tests

2013-12-02 Thread Cédric Bosdonnat
---
 tests/objecteventtest.c | 165 
 1 file changed, 165 insertions(+)

diff --git a/tests/objecteventtest.c b/tests/objecteventtest.c
index 031d677..9f0ff78 100644
--- a/tests/objecteventtest.c
+++ b/tests/objecteventtest.c
@@ -40,6 +40,18 @@ static const char domainDef[] =
 "  "
 "";
 
+static const char networkDef[] =
+"\n"
+"  test\n"
+"  \n"
+"  \n"
+"  \n"
+"\n"
+"  \n"
+"\n"
+"  \n"
+"\n";
+
 struct lifecycleEventCounter {
 int startEvents;
 int stopEvents;
@@ -57,6 +69,7 @@ static void lifecycleEventCounter_reset(struct 
lifecycleEventCounter* counter)
 
 struct objecteventTest {
 virConnectPtr conn;
+virNetworkPtr net;
 };
 
 
@@ -88,6 +101,25 @@ static int domainLifecycleCb(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 return 0;
 }
 
+static void
+networkLifecycleCb(virConnectPtr conn ATTRIBUTE_UNUSED,
+   virNetworkPtr net ATTRIBUTE_UNUSED,
+   int event,
+   void* opaque)
+{
+struct lifecycleEventCounter *counter = opaque;
+
+if (event == VIR_NETWORK_EVENT_STARTED)
+counter->startEvents++;
+else if (event == VIR_NETWORK_EVENT_STOPPED)
+counter->stopEvents++;
+else if (event == VIR_NETWORK_EVENT_DEFINED)
+counter->defineEvents++;
+else if (event == VIR_NETWORK_EVENT_UNDEFINED)
+counter->undefineEvents++;
+}
+
+
 static int
 testDomainCreateXML(const void *data)
 {
@@ -218,6 +250,124 @@ cleanup:
 }
 
 static int
+testNetworkCreateXML(const void *data)
+{
+const struct objecteventTest *test = data;
+struct lifecycleEventCounter counter;
+virNetworkPtr net;
+int id;
+int ret = 0;
+
+lifecycleEventCounter_reset(&counter);
+
+id = virConnectNetworkEventRegisterAny(test->conn, NULL,
+   VIR_NETWORK_EVENT_ID_LIFECYCLE,
+   VIR_NETWORK_EVENT_CALLBACK(&networkLifecycleCb),
+   &counter, NULL);
+net = virNetworkCreateXML(test->conn, networkDef);
+
+if (virEventRunDefaultImpl() < 0) {
+ret = -1;
+goto cleanup;
+}
+
+if (counter.startEvents != 1) {
+ret = -1;
+goto cleanup;
+}
+
+cleanup:
+virConnectNetworkEventDeregisterAny(test->conn, id);
+virNetworkDestroy(net);
+
+virNetworkFree(net);
+
+return ret;
+}
+
+static int
+testNetworkDefine(const void *data)
+{
+const struct objecteventTest *test = data;
+struct lifecycleEventCounter counter;
+virNetworkPtr net;
+int id;
+int ret = 0;
+
+lifecycleEventCounter_reset(&counter);
+
+id = virConnectNetworkEventRegisterAny(test->conn, NULL,
+   VIR_NETWORK_EVENT_ID_LIFECYCLE,
+   VIR_NETWORK_EVENT_CALLBACK(&networkLifecycleCb),
+   &counter, NULL);
+
+/* Make sure the define event is triggered */
+net = virNetworkDefineXML(test->conn, networkDef);
+
+if (virEventRunDefaultImpl() < 0) {
+ret = -1;
+goto cleanup;
+}
+
+if (counter.defineEvents != 1) {
+ret = -1;
+goto cleanup;
+}
+
+/* Make sure the undefine event is triggered */
+virNetworkUndefine(net);
+
+if (virEventRunDefaultImpl() < 0) {
+ret = -1;
+goto cleanup;
+}
+
+if (counter.undefineEvents != 1) {
+ret = -1;
+goto cleanup;
+}
+
+
+cleanup:
+virConnectNetworkEventDeregisterAny(test->conn, id);
+virNetworkFree(net);
+
+return ret;
+}
+
+static int
+testNetworkStartStopEvent(const void *data)
+{
+const struct objecteventTest *test = data;
+struct lifecycleEventCounter counter;
+int id;
+int ret = 0;
+
+lifecycleEventCounter_reset(&counter);
+
+id = virConnectNetworkEventRegisterAny(test->conn, test->net,
+   VIR_NETWORK_EVENT_ID_LIFECYCLE,
+   VIR_NETWORK_EVENT_CALLBACK(&networkLifecycleCb),
+   &counter, NULL);
+virNetworkCreate(test->net);
+virNetworkDestroy(test->net);
+
+if (virEventRunDefaultImpl() < 0) {
+ret = -1;
+goto cleanup;
+}
+
+if (counter.startEvents != 1 || counter.stopEvents != 1) {
+ret = -1;
+goto cleanup;
+}
+cleanup:
+virConnectNetworkEventDeregisterAny(test->conn, id);
+
+return ret;
+}
+
+static int
 mymain(void)
 {
 struct objecteventTest test;
@@ -238,6 +388,21 @@ mymain(void)
 if (virtTestRun("Domain start stop events", testDomainStartStopEvent, 
&test) < 0)
 ret = EXIT_FAILURE;
 
+/* Network event tests */
+/* Tests requiring the test network not to be set up*/
+if (virtTestRun("Network createXML start event ", testNetworkCreateXML, 
&test) < 0)
+ret = EXIT_FAILURE;
+if (virtTestRun("Network (un)define events", testNetworkDefine, &test) < 0)
+ret = EXIT_FAILURE;
+
+/* Define a test network */
+test.net = virNetwork

Re: [libvirt] Release of libvirt-python-1.2.0

2013-12-02 Thread Daniel P. Berrange
On Mon, Dec 02, 2013 at 02:28:00PM +0800, Daniel Veillard wrote:
>  So this is the first release fo the separated libvirt-python code base
> out of the main libvirt git. In this case the two release have been made
> in tandem to avoid disruptions, but there is no guarantee that the
> future releases of both project will be bound together (though I will
> try to sync those to minimize churn when possible !)
> 
>  Tarball and rpms are now available on the new location:
>ftp://libvirt.org/libvirt/python/

FYI I have also uploaded it to PyPI

   https://pypi.python.org/pypi/libvirt-python

So you can just do  'pip install libvirt-python' to install it.
Needs libvirt-devel RPM or equiv pkg installed first of course.

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


[libvirt] [v3 16/32] Created virDomainEventBlockJob

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 86 -
 src/conf/domain_event.h | 12 +++
 2 files changed, 62 insertions(+), 36 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index e145157..91bdbae 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -90,6 +90,7 @@ static virClassPtr virDomainEventRTCChangeClass;
 static virClassPtr virDomainEventWatchdogClass;
 static virClassPtr virDomainEventIOErrorClass;
 static virClassPtr virDomainEventGraphicsClass;
+static virClassPtr virDomainEventBlockJobClass;
 static void virObjectEventDispose(void *obj);
 static void virDomainEventDispose(void *obj);
 static void virDomainEventLifecycleDispose(void *obj);
@@ -97,6 +98,7 @@ static void virDomainEventRTCChangeDispose(void *obj);
 static void virDomainEventWatchdogDispose(void *obj);
 static void virDomainEventIOErrorDispose(void *obj);
 static void virDomainEventGraphicsDispose(void *obj);
+static void virDomainEventBlockJobDispose(void *obj);
 
 struct _virObjectEvent {
 virObject parent;
@@ -110,11 +112,6 @@ struct _virDomainEvent {
 
 union {
 struct {
-char *path;
-int type;
-int status;
-} blockJob;
-struct {
 char *oldSrcPath;
 char *newSrcPath;
 char *devAlias;
@@ -170,6 +167,16 @@ struct _virDomainEventIOError {
 typedef struct _virDomainEventIOError virDomainEventIOError;
 typedef virDomainEventIOError *virDomainEventIOErrorPtr;
 
+struct _virDomainEventBlockJob {
+virDomainEvent parent;
+
+char *path;
+int type;
+int status;
+};
+typedef struct _virDomainEventBlockJob virDomainEventBlockJob;
+typedef virDomainEventBlockJob *virDomainEventBlockJobPtr;
+
 struct _virDomainEventGraphics {
 virDomainEvent parent;
 
@@ -224,6 +231,12 @@ static int virObjectEventOnceInit(void)
  sizeof(virDomainEventGraphics),
  virDomainEventGraphicsDispose)))
 return -1;
+if (!(virDomainEventBlockJobClass = virClassNew(
+ virDomainEventClass,
+ "virDomainEventBlockJob",
+ sizeof(virDomainEventBlockJob),
+ virDomainEventBlockJobDispose)))
+return -1;
 return 0;
 }
 
@@ -256,10 +269,6 @@ static void virDomainEventDispose(void *obj)
 
 switch (virObjectEventGetEventID(event)) {
 
-case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
-VIR_FREE(event->data.blockJob.path);
-break;
-
 case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
 VIR_FREE(event->data.diskChange.oldSrcPath);
 VIR_FREE(event->data.diskChange.newSrcPath);
@@ -330,6 +339,14 @@ static void virDomainEventGraphicsDispose(void *obj)
 }
 }
 
+static void virDomainEventBlockJobDispose(void *obj)
+{
+virDomainEventBlockJobPtr event = obj;
+VIR_DEBUG("obj=%p", event);
+
+VIR_FREE(event->path);
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
@@ -1154,43 +1171,47 @@ virDomainEventPtr 
virDomainEventGraphicsNewFromObj(virDomainObjPtr obj,
 return (virDomainEventPtr)ev;
 }
 
-static virDomainEventPtr
-virDomainEventBlockJobNew(int id, const char *name, unsigned char *uuid,
-  const char *path, int type, int status)
+static
+virDomainEventPtr  virDomainEventBlockJobNew(int id,
+ const char *name,
+ unsigned char *uuid,
+ const char *path,
+ int type,
+ int status)
 {
-virDomainEventPtr ev;
+virDomainEventBlockJobPtr ev;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNew(virDomainEventClass,
+if (!(ev = virDomainEventNew(virDomainEventBlockJobClass,
  VIR_DOMAIN_EVENT_ID_BLOCK_JOB,
  id, name, uuid)))
 return NULL;
 
-if (VIR_STRDUP(ev->data.blockJob.path, path) < 0) {
+if (VIR_STRDUP(ev->path, path) < 0) {
 virObjectUnref(ev);
 return NULL;
 }
-ev->data.blockJob.type = type;
-ev->data.blockJob.status = status;
+ev->type = type;
+ev->status = status;
 
-return ev;
+return (virDomainEventPtr)ev;
 }
 
 virDomainEventPtr virDomainEventBlockJobNewFromObj(virDomainObjPtr obj,
-   const char *path,
-   int type,
-   int status)
+   const char *path,
+   int type,
+  

[libvirt] [v3 12/32] Create virDomainEventRTCChange to get rid of the huge union

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 53 +++--
 1 file changed, 38 insertions(+), 15 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 23d4965..ab38a3b 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -86,9 +86,11 @@ struct _virObjectEventCallback {
 static virClassPtr virObjectEventClass;
 static virClassPtr virDomainEventClass;
 static virClassPtr virDomainEventLifecycleClass;
+static virClassPtr virDomainEventRTCChangeClass;
 static void virObjectEventDispose(void *obj);
 static void virDomainEventDispose(void *obj);
 static void virDomainEventLifecycleDispose(void *obj);
+static void virDomainEventRTCChangeDispose(void *obj);
 
 struct _virObjectEvent {
 virObject parent;
@@ -102,9 +104,6 @@ struct _virDomainEvent {
 
 union {
 struct {
-long long offset;
-} rtcChange;
-struct {
 int action;
 } watchdog;
 struct {
@@ -154,6 +153,13 @@ struct _virDomainEventLifecycle {
 typedef struct _virDomainEventLifecycle virDomainEventLifecycle;
 typedef virDomainEventLifecycle *virDomainEventLifecyclePtr;
 
+struct _virDomainEventRTCChange {
+virDomainEvent parent;
+
+long long offset;
+};
+typedef struct _virDomainEventRTCChange virDomainEventRTCChange;
+typedef virDomainEventRTCChange *virDomainEventRTCChangePtr;
 
 static int virObjectEventOnceInit(void)
 {
@@ -173,6 +179,12 @@ static int virObjectEventOnceInit(void)
  sizeof(virDomainEventLifecycle),
  virDomainEventLifecycleDispose)))
 return -1;
+if (!(virDomainEventRTCChangeClass = virClassNew(
+ virDomainEventClass,
+ "virDomainEventRTCChange",
+ sizeof(virDomainEventRTCChange),
+ virDomainEventRTCChangeDispose)))
+return -1;
 return 0;
 }
 
@@ -259,6 +271,12 @@ static void virDomainEventLifecycleDispose(void *obj)
 VIR_DEBUG("obj=%p", event);
 }
 
+static void virDomainEventRTCChangeDispose(void *obj)
+{
+virDomainEventRTCChangePtr event = obj;
+VIR_DEBUG("obj=%p", event);
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
@@ -859,37 +877,37 @@ virDomainEventPtr 
virDomainEventRebootNewFromObj(virDomainObjPtr obj)
 virDomainEventPtr virDomainEventRTCChangeNewFromDom(virDomainPtr dom,
 long long offset)
 {
-virDomainEventPtr ev;
+virDomainEventRTCChangePtr ev;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNew(virDomainEventClass,
+if (!(ev = virDomainEventNew(virDomainEventRTCChangeClass,
  VIR_DOMAIN_EVENT_ID_RTC_CHANGE,
  dom->id, dom->name, dom->uuid)))
 return NULL;
 
-ev->data.rtcChange.offset = offset;
+ev->offset = offset;
 
-return ev;
+return (virDomainEventPtr)ev;
 }
 virDomainEventPtr virDomainEventRTCChangeNewFromObj(virDomainObjPtr obj,
 long long offset)
 {
-virDomainEventPtr ev;
+virDomainEventRTCChangePtr ev;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNew(virDomainEventClass,
+if (!(ev = virDomainEventNew(virDomainEventRTCChangeClass,
  VIR_DOMAIN_EVENT_ID_RTC_CHANGE,
  obj->def->id, obj->def->name,
  obj->def->uuid)))
 return NULL;
 
-ev->data.rtcChange.offset = offset;
+ev->offset = offset;
 
-return ev;
+return (virDomainEventPtr)ev;
 }
 
 virDomainEventPtr virDomainEventWatchdogNewFromDom(virDomainPtr dom,
@@ -1497,10 +1515,15 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
 goto cleanup;
 
 case VIR_DOMAIN_EVENT_ID_RTC_CHANGE:
-((virConnectDomainEventRTCChangeCallback)cb)(conn, dom,
- 
event->data.rtcChange.offset,
- cbopaque);
-goto cleanup;
+{
+virDomainEventRTCChangePtr rtcChangeEvent;
+
+rtcChangeEvent = (virDomainEventRTCChangePtr)event;
+((virConnectDomainEventRTCChangeCallback)cb)(conn, dom,
+ 
rtcChangeEvent->offset,
+ cbopaque);
+goto cleanup;
+}
 
 case VIR_DOMAIN_EVENT_ID_WATCHDOG:
 ((virConnectDomainEventWatchdogCallback)cb)(conn, dom,
-- 
1.8.4.4

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


Re: [libvirt] [PATCH] qemu: default to vfio for nodedev-detach

2013-12-02 Thread Eric Blake
On 11/29/2013 04:47 AM, Laine Stump wrote:
> This patch resolves:
> 
>   https://bugzilla.redhat.com/show_bug.cgi?id=1035188
> 
> Commit f094aaac48a6 changed the PCI device assignment in qemu domains
> to default to using VFIO rather than legacy KVM device assignment
> (when VFIO is available). It didn't change which driver was used by
> default for virNodeDeviceDetachFlags(), though, so that API (and the
> virsh nodedev-detach command) was still binding to the pci-stub
> driver, used by legacy KVM assignment, by default.
> 
> This patch publicizes (only within the qemu module, though, so no
> additions to the symbol exports are needed) the functions that check
> for presence of KVM and VFIO device assignment, then uses those
> functions to decide what to do when no driver is specified for
> virNodeDeviceDetachFlags(); if the vfio driver is loaded, the device
> will be bound to vfio-pci, or if legacy KVM assignment is supported on
> this system, the device will be bound to pci-stub; if neither method
> is avialable, the detach will fail.

s/avialable/available/

> ---
>  src/qemu/qemu_driver.c  | 19 ---
>  src/qemu/qemu_hostdev.c |  6 +++---
>  src/qemu/qemu_hostdev.h |  4 +++-
>  3 files changed, 22 insertions(+), 7 deletions(-)
> 

ACK.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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

[libvirt] [PATCH] Ensure to zero out the virDomainBlockJobInfo arg

2013-12-02 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

The virDomainGetBlockJobInfo method did not zero out the
virDomainBlockJobInfo pointer arg, so when block jobs were
not active it would return garbage for the bandwidth/cur/end
fields.

Signed-off-by: Daniel P. Berrange 
---
 src/libvirt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/libvirt.c b/src/libvirt.c
index eff44eb..a2df53d 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -20850,6 +20850,8 @@ int virDomainGetBlockJobInfo(virDomainPtr dom, const 
char *disk,
 virCheckNonNullArgGoto(disk, error);
 virCheckNonNullArgGoto(info, error);
 
+memset(info, 0, sizeof(*info));
+
 if (conn->driver->domainGetBlockJobInfo) {
 int ret;
 ret = conn->driver->domainGetBlockJobInfo(dom, disk, info, flags);
-- 
1.8.3.1

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


Re: [libvirt] [PATCH] Doc: Explicitly declaring that nodedev-destroy only works for vHBA

2013-12-02 Thread Eric Blake
On 11/22/2013 05:55 AM, Osier Yang wrote:
> Though trying to destroy a physical HBA doesn't make sense at all,
> it's still a bit misleading with saying "only works for HBA".
> 
> Signed-off-by: Osier Yang 
> ---
>  src/libvirt.c   | 5 +++--
>  tools/virsh.pod | 6 +++---
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 

ACK

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



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

[libvirt] [v3 28/32] test driver: implemented network events

2013-12-02 Thread Cédric Bosdonnat
---
 src/test/test_driver.c | 62 ++
 1 file changed, 62 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 4972e3d..66afdf7 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -45,6 +45,7 @@
 #include "interface_conf.h"
 #include "domain_conf.h"
 #include "domain_event.h"
+#include "network_event.h"
 #include "snapshot_conf.h"
 #include "fdstream.h"
 #include "storage_conf.h"
@@ -3529,6 +3530,7 @@ static virNetworkPtr testNetworkCreateXML(virConnectPtr 
conn, const char *xml) {
 virNetworkDefPtr def;
 virNetworkObjPtr net = NULL;
 virNetworkPtr ret = NULL;
+virObjectEventPtr event = NULL;
 
 testDriverLock(privconn);
 if ((def = virNetworkDefParseString(xml)) == NULL)
@@ -3539,10 +3541,15 @@ static virNetworkPtr testNetworkCreateXML(virConnectPtr 
conn, const char *xml) {
 def = NULL;
 net->active = 1;
 
+event = virNetworkEventLifecycleNew(net->def->name, net->def->uuid,
+VIR_NETWORK_EVENT_STARTED);
+
 ret = virGetNetwork(conn, net->def->name, net->def->uuid);
 
 cleanup:
 virNetworkDefFree(def);
+if (event)
+testObjectEventQueue(privconn, event);
 if (net)
 virNetworkObjUnlock(net);
 testDriverUnlock(privconn);
@@ -3556,6 +3563,7 @@ virNetworkPtr testNetworkDefineXML(virConnectPtr conn, 
const char *xml)
 virNetworkDefPtr def;
 virNetworkObjPtr net = NULL;
 virNetworkPtr ret = NULL;
+virObjectEventPtr event = NULL;
 
 testDriverLock(privconn);
 if ((def = virNetworkDefParseString(xml)) == NULL)
@@ -3566,10 +3574,15 @@ virNetworkPtr testNetworkDefineXML(virConnectPtr conn, 
const char *xml)
 def = NULL;
 net->persistent = 1;
 
+event = virNetworkEventLifecycleNew(net->def->name, net->def->uuid,
+VIR_NETWORK_EVENT_DEFINED);
+
 ret = virGetNetwork(conn, net->def->name, net->def->uuid);
 
 cleanup:
 virNetworkDefFree(def);
+if (event)
+testObjectEventQueue(privconn, event);
 if (net)
 virNetworkObjUnlock(net);
 testDriverUnlock(privconn);
@@ -3580,6 +3593,7 @@ static int testNetworkUndefine(virNetworkPtr network) {
 testConnPtr privconn = network->conn->privateData;
 virNetworkObjPtr privnet;
 int ret = -1;
+virObjectEventPtr event = NULL;
 
 testDriverLock(privconn);
 privnet = virNetworkFindByName(&privconn->networks,
@@ -3596,12 +3610,17 @@ static int testNetworkUndefine(virNetworkPtr network) {
 goto cleanup;
 }
 
+event = virNetworkEventLifecycleNew(network->name, network->uuid,
+VIR_NETWORK_EVENT_UNDEFINED);
+
 virNetworkRemoveInactive(&privconn->networks,
  privnet);
 privnet = NULL;
 ret = 0;
 
 cleanup:
+if (event)
+testObjectEventQueue(privconn, event);
 if (privnet)
 virNetworkObjUnlock(privnet);
 testDriverUnlock(privconn);
@@ -3660,6 +3679,7 @@ static int testNetworkCreate(virNetworkPtr network) {
 testConnPtr privconn = network->conn->privateData;
 virNetworkObjPtr privnet;
 int ret = -1;
+virObjectEventPtr event = NULL;
 
 testDriverLock(privconn);
 privnet = virNetworkFindByName(&privconn->networks,
@@ -3678,9 +3698,13 @@ static int testNetworkCreate(virNetworkPtr network) {
 }
 
 privnet->active = 1;
+event = virNetworkEventLifecycleNew(privnet->def->name, privnet->def->uuid,
+VIR_NETWORK_EVENT_STARTED);
 ret = 0;
 
 cleanup:
+if (event)
+testObjectEventQueue(privconn, event);
 if (privnet)
 virNetworkObjUnlock(privnet);
 return ret;
@@ -3690,6 +3714,7 @@ static int testNetworkDestroy(virNetworkPtr network) {
 testConnPtr privconn = network->conn->privateData;
 virNetworkObjPtr privnet;
 int ret = -1;
+virObjectEventPtr event = NULL;
 
 testDriverLock(privconn);
 privnet = virNetworkFindByName(&privconn->networks,
@@ -3701,6 +3726,8 @@ static int testNetworkDestroy(virNetworkPtr network) {
 }
 
 privnet->active = 0;
+event = virNetworkEventLifecycleNew(privnet->def->name, privnet->def->uuid,
+VIR_NETWORK_EVENT_STOPPED);
 if (!privnet->persistent) {
 virNetworkRemoveInactive(&privconn->networks,
  privnet);
@@ -3709,6 +3736,8 @@ static int testNetworkDestroy(virNetworkPtr network) {
 ret = 0;
 
 cleanup:
+if (event)
+testObjectEventQueue(privconn, event);
 if (privnet)
 virNetworkObjUnlock(privnet);
 testDriverUnlock(privconn);
@@ -6027,6 +6056,37 @@ testConnectDomainEventDeregisterAny(virConnectPtr conn,
 }
 
 
+static int
+testConnectNetworkEventRegisterAny(virConnectPtr conn,
+   virNetworkPtr net,
+   int eventID

[libvirt] [v3 27/32] test driver: renamed testDomainEventQueue into testObjectEventQueue

2013-12-02 Thread Cédric Bosdonnat
---
 src/test/test_driver.c | 40 
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 6d2a0e2..4972e3d 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -121,7 +121,7 @@ static const virNodeInfo defaultNodeInfo = {
 
 
 static int testConnectClose(virConnectPtr conn);
-static void testDomainEventQueue(testConnPtr driver,
+static void testObjectEventQueue(testConnPtr driver,
  virObjectEventPtr event);
 
 
@@ -1650,7 +1650,7 @@ cleanup:
 if (dom)
 virObjectUnlock(dom);
 if (event)
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 virDomainDefFree(def);
 testDriverUnlock(privconn);
 return ret;
@@ -1781,7 +1781,7 @@ cleanup:
 if (privdom)
 virObjectUnlock(privdom);
 if (event)
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 return ret;
 }
@@ -1821,7 +1821,7 @@ cleanup:
 virObjectUnlock(privdom);
 if (event) {
 testDriverLock(privconn);
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 }
 return ret;
@@ -1864,7 +1864,7 @@ cleanup:
 
 if (event) {
 testDriverLock(privconn);
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 }
 return ret;
@@ -1911,7 +1911,7 @@ cleanup:
 if (privdom)
 virObjectUnlock(privdom);
 if (event)
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 return ret;
 }
@@ -1987,7 +1987,7 @@ cleanup:
 if (privdom)
 virObjectUnlock(privdom);
 if (event)
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 return ret;
 }
@@ -2159,7 +2159,7 @@ cleanup:
 if (privdom)
 virObjectUnlock(privdom);
 if (event)
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 return ret;
 }
@@ -2265,7 +2265,7 @@ cleanup:
 if (dom)
 virObjectUnlock(dom);
 if (event)
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 return ret;
 }
@@ -2335,7 +2335,7 @@ cleanup:
 if (privdom)
 virObjectUnlock(privdom);
 if (event)
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 return ret;
 }
@@ -2819,7 +2819,7 @@ cleanup:
 if (dom)
 virObjectUnlock(dom);
 if (event)
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 return ret;
 }
@@ -2955,7 +2955,7 @@ cleanup:
 if (privdom)
 virObjectUnlock(privdom);
 if (event)
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 return ret;
 }
@@ -3030,7 +3030,7 @@ cleanup:
 if (privdom)
 virObjectUnlock(privdom);
 if (event)
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 return ret;
 }
@@ -6028,7 +6028,7 @@ testConnectDomainEventDeregisterAny(virConnectPtr conn,
 
 
 /* driver must be locked before calling */
-static void testDomainEventQueue(testConnPtr driver,
+static void testObjectEventQueue(testConnPtr driver,
  virObjectEventPtr event)
 {
 virObjectEventStateQueue(driver->domainEventState, event);
@@ -6191,7 +6191,7 @@ cleanup:
 virObjectUnlock(vm);
 if (event) {
 testDriverLock(privconn);
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 }
 
@@ -6743,7 +6743,7 @@ cleanup:
 }
 if (event) {
 testDriverLock(privconn);
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 testDriverUnlock(privconn);
 }
 virDomainSnapshotDefFree(def);
@@ -6989,7 +6989,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 VIR_DOMAIN_EVENT_STOPPED,
 VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT);
 if (event)
-testDomainEventQueue(privconn, event);
+testObjectEventQueue(privconn, event);
 goto load;
 }
 
@@ -7069,7 +7069,7 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 bool paused = (flags & VIR_DOMAIN_SNAPSHOT_REVERT

[libvirt] [v3 18/32] Created virDomainEventTrayChange

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 57 ++---
 1 file changed, 40 insertions(+), 17 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 49b87dd..47b183a 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -92,6 +92,7 @@ static virClassPtr virDomainEventIOErrorClass;
 static virClassPtr virDomainEventGraphicsClass;
 static virClassPtr virDomainEventBlockJobClass;
 static virClassPtr virDomainEventDiskChangeClass;
+static virClassPtr virDomainEventTrayChangeClass;
 
 static void virObjectEventDispose(void *obj);
 static void virDomainEventDispose(void *obj);
@@ -102,6 +103,7 @@ static void virDomainEventIOErrorDispose(void *obj);
 static void virDomainEventGraphicsDispose(void *obj);
 static void virDomainEventBlockJobDispose(void *obj);
 static void virDomainEventDiskChangeDispose(void *obj);
+static void virDomainEventTrayChangeDispose(void *obj);
 
 struct _virObjectEvent {
 virObject parent;
@@ -115,10 +117,6 @@ struct _virDomainEvent {
 
 union {
 struct {
-char *devAlias;
-int reason;
-} trayChange;
-struct {
 /* In unit of 1024 bytes */
 unsigned long long actual;
 } balloonChange;
@@ -197,6 +195,15 @@ struct _virDomainEventDiskChange {
 typedef struct _virDomainEventDiskChange virDomainEventDiskChange;
 typedef virDomainEventDiskChange *virDomainEventDiskChangePtr;
 
+struct _virDomainEventTrayChange {
+virDomainEvent parent;
+
+char *devAlias;
+int reason;
+};
+typedef struct _virDomainEventTrayChange virDomainEventTrayChange;
+typedef virDomainEventTrayChange *virDomainEventTrayChangePtr;
+
 
 static int virObjectEventOnceInit(void)
 {
@@ -252,6 +259,12 @@ static int virObjectEventOnceInit(void)
  sizeof(virDomainEventDiskChange),
  virDomainEventDiskChangeDispose)))
 return -1;
+if (!(virDomainEventTrayChangeClass = virClassNew(
+ virDomainEventClass,
+ "virDomainEventTrayChange",
+ sizeof(virDomainEventTrayChange),
+ virDomainEventTrayChangeDispose)))
+return -1;
 return 0;
 }
 
@@ -284,9 +297,6 @@ static void virDomainEventDispose(void *obj)
 
 switch (virObjectEventGetEventID(event)) {
 
-case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
-VIR_FREE(event->data.trayChange.devAlias);
-break;
 case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
 VIR_FREE(event->data.deviceRemoved.devAlias);
 break;
@@ -367,6 +377,14 @@ static void virDomainEventDiskChangeDispose(void *obj)
 VIR_FREE(event->devAlias);
 }
 
+static void virDomainEventTrayChangeDispose(void *obj)
+{
+virDomainEventTrayChangePtr event = obj;
+VIR_DEBUG("obj=%p", event);
+
+VIR_FREE(event->devAlias);
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
@@ -1330,22 +1348,22 @@ virDomainEventTrayChangeNew(int id, const char *name,
 const char *devAlias,
 int reason)
 {
-virDomainEventPtr ev;
+virDomainEventTrayChangePtr ev;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNew(virDomainEventClass,
+if (!(ev = virDomainEventNew(virDomainEventTrayChangeClass,
  VIR_DOMAIN_EVENT_ID_TRAY_CHANGE,
  id, name, uuid)))
 return NULL;
 
-if (VIR_STRDUP(ev->data.trayChange.devAlias, devAlias) < 0)
+if (VIR_STRDUP(ev->devAlias, devAlias) < 0)
 goto error;
 
-ev->data.trayChange.reason = reason;
+ev->reason = reason;
 
-return ev;
+return (virDomainEventPtr)ev;
 
 error:
 virObjectUnref(ev);
@@ -1703,11 +1721,16 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
 }
 
 case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
-((virConnectDomainEventTrayChangeCallback)cb)(conn, dom,
-  
event->data.trayChange.devAlias,
-  
event->data.trayChange.reason,
-  cbopaque);
-goto cleanup;
+{
+virDomainEventTrayChangePtr trayChangeEvent;
+
+trayChangeEvent = (virDomainEventTrayChangePtr)event;
+((virConnectDomainEventTrayChangeCallback)cb)(conn, dom,
+  
trayChangeEvent->devAlias,
+  
trayChangeEvent->reason,
+  cbopaque);
+goto cleanup;
+}
 
 case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
 ((virConnectDomainEventPMW

[libvirt] [v3 14/32] Created virDomainEventIOError

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 105 ++--
 1 file changed, 66 insertions(+), 39 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 63119b2..de3664f 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -88,11 +88,13 @@ static virClassPtr virDomainEventClass;
 static virClassPtr virDomainEventLifecycleClass;
 static virClassPtr virDomainEventRTCChangeClass;
 static virClassPtr virDomainEventWatchdogClass;
+static virClassPtr virDomainEventIOErrorClass;
 static void virObjectEventDispose(void *obj);
 static void virDomainEventDispose(void *obj);
 static void virDomainEventLifecycleDispose(void *obj);
 static void virDomainEventRTCChangeDispose(void *obj);
 static void virDomainEventWatchdogDispose(void *obj);
+static void virDomainEventIOErrorDispose(void *obj);
 
 struct _virObjectEvent {
 virObject parent;
@@ -106,12 +108,6 @@ struct _virDomainEvent {
 
 union {
 struct {
-char *srcPath;
-char *devAlias;
-int action;
-char *reason;
-} ioError;
-struct {
 int phase;
 virDomainEventGraphicsAddressPtr local;
 virDomainEventGraphicsAddressPtr remote;
@@ -168,6 +164,17 @@ struct _virDomainEventWatchdog {
 typedef struct _virDomainEventWatchdog virDomainEventWatchdog;
 typedef virDomainEventWatchdog *virDomainEventWatchdogPtr;
 
+struct _virDomainEventIOError {
+virDomainEvent parent;
+
+char *srcPath;
+char *devAlias;
+int action;
+char *reason;
+};
+typedef struct _virDomainEventIOError virDomainEventIOError;
+typedef virDomainEventIOError *virDomainEventIOErrorPtr;
+
 static int virObjectEventOnceInit(void)
 {
 if (!(virObjectEventClass = virClassNew(virClassForObject(),
@@ -198,6 +205,12 @@ static int virObjectEventOnceInit(void)
  sizeof(virDomainEventWatchdog),
  virDomainEventWatchdogDispose)))
 return -1;
+if (!(virDomainEventIOErrorClass = virClassNew(
+ virDomainEventClass,
+ "virDomainEventIOError",
+ sizeof(virDomainEventIOError),
+ virDomainEventIOErrorDispose)))
+return -1;
 return 0;
 }
 
@@ -229,12 +242,6 @@ static void virDomainEventDispose(void *obj)
 VIR_DEBUG("obj=%p", event);
 
 switch (virObjectEventGetEventID(event)) {
-case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON:
-case VIR_DOMAIN_EVENT_ID_IO_ERROR:
-VIR_FREE(event->data.ioError.srcPath);
-VIR_FREE(event->data.ioError.devAlias);
-VIR_FREE(event->data.ioError.reason);
-break;
 
 case VIR_DOMAIN_EVENT_ID_GRAPHICS:
 if (event->data.graphics.local) {
@@ -296,6 +303,16 @@ static void virDomainEventWatchdogDispose(void *obj)
 VIR_DEBUG("obj=%p", event);
 }
 
+static void virDomainEventIOErrorDispose(void *obj)
+{
+virDomainEventIOErrorPtr event = obj;
+VIR_DEBUG("obj=%p", event);
+
+VIR_FREE(event->srcPath);
+VIR_FREE(event->devAlias);
+VIR_FREE(event->reason);
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
@@ -970,24 +987,24 @@ static virDomainEventPtr 
virDomainEventIOErrorNewFromDomImpl(int event,
  int action,
  const char 
*reason)
 {
-virDomainEventPtr ev;
+virDomainEventIOErrorPtr ev;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNew(virDomainEventClass, event,
+if (!(ev = virDomainEventNew(virDomainEventIOErrorClass, event,
  dom->id, dom->name, dom->uuid)))
 return NULL;
 
-ev->data.ioError.action = action;
-if (VIR_STRDUP(ev->data.ioError.srcPath, srcPath) < 0 ||
-VIR_STRDUP(ev->data.ioError.devAlias, devAlias) < 0 ||
-VIR_STRDUP(ev->data.ioError.reason, reason) < 0) {
+ev->action = action;
+if (VIR_STRDUP(ev->srcPath, srcPath) < 0 ||
+VIR_STRDUP(ev->devAlias, devAlias) < 0 ||
+VIR_STRDUP(ev->reason, reason) < 0) {
 virObjectUnref(ev);
 ev = NULL;
 }
 
-return ev;
+return (virDomainEventPtr)ev;
 }
 
 static virDomainEventPtr virDomainEventIOErrorNewFromObjImpl(int event,
@@ -997,25 +1014,25 @@ static virDomainEventPtr 
virDomainEventIOErrorNewFromObjImpl(int event,
  int action,
  const char 
*reason)
 {
-virDomainEventPtr ev;
+virDomainEventIOErrorPtr ev;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNew(virDomainEventClass, event,
+if (!(e

[libvirt] [v3 24/32] Split the virObjectEvent and virDomainEvent* to separate them after

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 68 ++---
 1 file changed, 42 insertions(+), 26 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 2fc0870..b804f55 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -84,6 +84,8 @@ struct _virObjectEventCallback {
 
 
 static virClassPtr virObjectEventClass;
+static virClassPtr virClassForObjectEvent(void);
+
 static virClassPtr virDomainEventClass;
 static virClassPtr virDomainEventLifecycleClass;
 static virClassPtr virDomainEventRTCChangeClass;
@@ -227,7 +229,21 @@ static int virObjectEventOnceInit(void)
  sizeof(virObjectEvent),
  virObjectEventDispose)))
 return -1;
-if (!(virDomainEventClass = virClassNew(virObjectEventClass,
+return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virObjectEvent)
+
+virClassPtr virClassForObjectEvent(void)
+{
+if (virObjectEventInitialize() < 0)
+return NULL;
+return virObjectEventClass;
+}
+
+static int virDomainEventsOnceInit(void)
+{
+if (!(virDomainEventClass = virClassNew(virClassForObjectEvent(),
  "virDomainEvent",
  sizeof(virDomainEvent),
  virDomainEventDispose)))
@@ -295,13 +311,13 @@ static int virObjectEventOnceInit(void)
 return 0;
 }
 
-VIR_ONCE_GLOBAL_INIT(virObjectEvent)
+VIR_ONCE_GLOBAL_INIT(virDomainEvents)
 
 static int virObjectEventGetEventID(void *anyobj)
 {
 virObjectEventPtr obj = anyobj;
 
-if (!virObjectIsClass(obj, virObjectEventClass)) {
+if (!virObjectIsClass(obj, virClassForObjectEvent())) {
 VIR_WARN("Object %p (%s) is not a virObjectEvent instance",
  obj, obj ? virClassName(obj->parent.klass) : "(unknown)");
 return -1;
@@ -958,7 +974,7 @@ virObjectEventPtr virDomainEventLifecycleNew(int id, const 
char *name,
 {
 virDomainEventLifecyclePtr event;
 
-if (virObjectEventInitialize() < 0)
+if (virDomainEventsInitialize() < 0)
 return NULL;
 
 if (!(event = virDomainEventNew(virDomainEventLifecycleClass,
@@ -992,7 +1008,7 @@ virObjectEventPtr 
virDomainEventLifecycleNewFromDef(virDomainDefPtr def, int typ
 virObjectEventPtr virDomainEventRebootNew(int id, const char *name,
   const unsigned char *uuid)
 {
-if (virObjectEventInitialize() < 0)
+if (virDomainEventsInitialize() < 0)
 return NULL;
 
 return virDomainEventNew(virDomainEventClass,
@@ -1002,7 +1018,7 @@ virObjectEventPtr virDomainEventRebootNew(int id, const 
char *name,
 
 virObjectEventPtr virDomainEventRebootNewFromDom(virDomainPtr dom)
 {
-if (virObjectEventInitialize() < 0)
+if (virDomainEventsInitialize() < 0)
 return NULL;
 
 return virDomainEventNew(virDomainEventClass,
@@ -1012,7 +1028,7 @@ virObjectEventPtr 
virDomainEventRebootNewFromDom(virDomainPtr dom)
 
 virObjectEventPtr virDomainEventRebootNewFromObj(virDomainObjPtr obj)
 {
-if (virObjectEventInitialize() < 0)
+if (virDomainEventsInitialize() < 0)
 return NULL;
 
 return virDomainEventNew(virDomainEventClass,
@@ -1025,7 +1041,7 @@ virObjectEventPtr 
virDomainEventRTCChangeNewFromDom(virDomainPtr dom,
 {
 virDomainEventRTCChangePtr ev;
 
-if (virObjectEventInitialize() < 0)
+if (virDomainEventsInitialize() < 0)
 return NULL;
 
 if (!(ev = virDomainEventNew(virDomainEventRTCChangeClass,
@@ -1042,7 +1058,7 @@ virObjectEventPtr 
virDomainEventRTCChangeNewFromObj(virDomainObjPtr obj,
 {
 virDomainEventRTCChangePtr ev;
 
-if (virObjectEventInitialize() < 0)
+if (virDomainEventsInitialize() < 0)
 return NULL;
 
 if (!(ev = virDomainEventNew(virDomainEventRTCChangeClass,
@@ -1060,7 +1076,7 @@ virObjectEventPtr 
virDomainEventWatchdogNewFromDom(virDomainPtr dom, int action)
 {
 virDomainEventWatchdogPtr ev;
 
-if (virObjectEventInitialize() < 0)
+if (virDomainEventsInitialize() < 0)
 return NULL;
 
 if (!(ev = virDomainEventNew(virDomainEventWatchdogClass,
@@ -1076,7 +1092,7 @@ virObjectEventPtr 
virDomainEventWatchdogNewFromObj(virDomainObjPtr obj, int acti
 {
 virDomainEventWatchdogPtr ev;
 
-if (virObjectEventInitialize() < 0)
+if (virDomainEventsInitialize() < 0)
 return NULL;
 
 if (!(ev = virDomainEventNew(virDomainEventWatchdogClass,
@@ -1099,7 +1115,7 @@ static virObjectEventPtr 
virDomainEventIOErrorNewFromDomImpl(int event,
 {
 virDomainEventIOErrorPtr ev;
 
-if (virObjectEventInitialize() < 0)
+if (virDomainEventsInitialize() < 0)
 return NULL;
 
 if (!(ev = virDomainEventNew(virDomainEventIOErrorClass, event,
@@ -1126,7 +1142,7 @@ static virObjectEventPtr 
virDomainEventIOErrorNewFromObjImpl(int event,
 {
 virDomainEventIOErrorPtr ev;
 
-if (virObjectEventIn

[libvirt] [v3 11/32] Renamed virDomainEventNewInternal to virDomainEventNew

2013-12-02 Thread Cédric Bosdonnat
This change may be confusing at first, but provides a much more
consistent naming scheme for the virObjectEvent children construction
functions.
---
 src/conf/domain_event.c | 154 
 1 file changed, 77 insertions(+), 77 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index c2b2210..23d4965 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -757,11 +757,11 @@ static void *virObjectEventNew(virClassPtr klass,
 return event;
 }
 
-static void *virDomainEventNewInternal(virClassPtr klass,
-   int eventID,
-   int id,
-   const char *name,
-   const unsigned char *uuid)
+static void *virDomainEventNew(virClassPtr klass,
+   int eventID,
+   int id,
+   const char *name,
+   const unsigned char *uuid)
 {
 virDomainEventPtr event;
 
@@ -797,9 +797,9 @@ virDomainEventPtr virDomainEventLifecycleNew(int id, const 
char *name,
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(event = virDomainEventNewInternal(virDomainEventLifecycleClass,
-VIR_DOMAIN_EVENT_ID_LIFECYCLE,
-id, name, uuid)))
+if (!(event = virDomainEventNew(virDomainEventLifecycleClass,
+VIR_DOMAIN_EVENT_ID_LIFECYCLE,
+id, name, uuid)))
 return NULL;
 
 event->type = type;
@@ -831,9 +831,9 @@ virDomainEventPtr virDomainEventRebootNew(int id, const 
char *name,
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-return virDomainEventNewInternal(virDomainEventClass,
- VIR_DOMAIN_EVENT_ID_REBOOT,
- id, name, uuid);
+return virDomainEventNew(virDomainEventClass,
+ VIR_DOMAIN_EVENT_ID_REBOOT,
+ id, name, uuid);
 }
 
 virDomainEventPtr virDomainEventRebootNewFromDom(virDomainPtr dom)
@@ -841,9 +841,9 @@ virDomainEventPtr 
virDomainEventRebootNewFromDom(virDomainPtr dom)
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-return virDomainEventNewInternal(virDomainEventClass,
- VIR_DOMAIN_EVENT_ID_REBOOT,
- dom->id, dom->name, dom->uuid);
+return virDomainEventNew(virDomainEventClass,
+ VIR_DOMAIN_EVENT_ID_REBOOT,
+ dom->id, dom->name, dom->uuid);
 }
 
 virDomainEventPtr virDomainEventRebootNewFromObj(virDomainObjPtr obj)
@@ -851,9 +851,9 @@ virDomainEventPtr 
virDomainEventRebootNewFromObj(virDomainObjPtr obj)
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-return virDomainEventNewInternal(virDomainEventClass,
- VIR_DOMAIN_EVENT_ID_REBOOT,
- obj->def->id, obj->def->name, 
obj->def->uuid);
+return virDomainEventNew(virDomainEventClass,
+ VIR_DOMAIN_EVENT_ID_REBOOT,
+ obj->def->id, obj->def->name, obj->def->uuid);
 }
 
 virDomainEventPtr virDomainEventRTCChangeNewFromDom(virDomainPtr dom,
@@ -864,9 +864,9 @@ virDomainEventPtr 
virDomainEventRTCChangeNewFromDom(virDomainPtr dom,
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNewInternal(virDomainEventClass,
- VIR_DOMAIN_EVENT_ID_RTC_CHANGE,
- dom->id, dom->name, dom->uuid)))
+if (!(ev = virDomainEventNew(virDomainEventClass,
+ VIR_DOMAIN_EVENT_ID_RTC_CHANGE,
+ dom->id, dom->name, dom->uuid)))
 return NULL;
 
 ev->data.rtcChange.offset = offset;
@@ -881,10 +881,10 @@ virDomainEventPtr 
virDomainEventRTCChangeNewFromObj(virDomainObjPtr obj,
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNewInternal(virDomainEventClass,
- VIR_DOMAIN_EVENT_ID_RTC_CHANGE,
- obj->def->id, obj->def->name,
- obj->def->uuid)))
+if (!(ev = virDomainEventNew(virDomainEventClass,
+ VIR_DOMAIN_EVENT_ID_RTC_CHANGE,
+ obj->def->id, obj->def->name,
+ obj->def->uuid)))
 return NULL;
 
 ev->data.rtcChange.offset = offset;
@@ -900,9 +900,9 @@ virDomainEventPtr 
virDomainEventWatchdogNewFromDom(virDomainPtr dom,
 if (virObjectEventInitialize() < 0)
 return NULL;
 

[libvirt] [v3 31/32] Add network events to the remote driver

2013-12-02 Thread Cédric Bosdonnat
---
 daemon/libvirtd.h|   1 +
 daemon/remote.c  | 140 +++
 src/remote/remote_driver.c   | 127 +++
 src/remote/remote_protocol.x |  46 +-
 4 files changed, 313 insertions(+), 1 deletion(-)

diff --git a/daemon/libvirtd.h b/daemon/libvirtd.h
index d0afdc8..47f2589 100644
--- a/daemon/libvirtd.h
+++ b/daemon/libvirtd.h
@@ -50,6 +50,7 @@ struct daemonClientPrivate {
 virMutex lock;
 
 int domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LAST];
+int networkEventCallbackID[VIR_NETWORK_EVENT_ID_LAST];
 
 # if WITH_SASL
 virNetSASLSessionPtr sasl;
diff --git a/daemon/remote.c b/daemon/remote.c
index f060006..d14b0f3 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -49,6 +49,7 @@
 #include "qemu_protocol.h"
 #include "lxc_protocol.h"
 #include "virstring.h"
+#include "object_event.h"
 
 #define VIR_FROM_THIS VIR_FROM_RPC
 
@@ -653,6 +654,37 @@ static virConnectDomainEventGenericCallback 
domainEventCallbacks[] = {
 
 verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST);
 
+static int remoteRelayNetworkEventLifecycle(virConnectPtr conn 
ATTRIBUTE_UNUSED,
+   virNetworkPtr net,
+   int event,
+   void *opaque)
+{
+virNetServerClientPtr client = opaque;
+remote_network_event_lifecycle_msg data;
+
+if (!client)
+return -1;
+
+VIR_DEBUG("Relaying network lifecycle event %d", event);
+
+/* build return data */
+memset(&data, 0, sizeof(data));
+make_nonnull_network(&data.net, net);
+data.event = event;
+
+remoteDispatchObjectEventSend(client, remoteProgram,
+  REMOTE_PROC_NETWORK_EVENT_LIFECYCLE,
+  
(xdrproc_t)xdr_remote_network_event_lifecycle_msg, &data);
+
+return 0;
+}
+
+static virConnectNetworkEventGenericCallback networkEventCallbacks[] = {
+VIR_NETWORK_EVENT_CALLBACK(remoteRelayNetworkEventLifecycle),
+};
+
+verify(ARRAY_CARDINALITY(networkEventCallbacks) == VIR_NETWORK_EVENT_ID_LAST);
+
 /*
  * You must hold lock for at least the client
  * We don't free stuff here, merely disconnect the client's
@@ -680,6 +712,15 @@ void remoteClientFreeFunc(void *data)
 priv->domainEventCallbackID[i] = -1;
 }
 
+for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) {
+if (priv->networkEventCallbackID[i] != -1) {
+VIR_DEBUG("Deregistering to relay remote events %zu", i);
+virConnectNetworkEventDeregisterAny(priv->conn,
+
priv->networkEventCallbackID[i]);
+}
+priv->networkEventCallbackID[i] = -1;
+}
+
 virConnectClose(priv->conn);
 
 virIdentitySetCurrent(NULL);
@@ -716,6 +757,9 @@ void *remoteClientInitHook(virNetServerClientPtr client,
 for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++)
 priv->domainEventCallbackID[i] = -1;
 
+for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++)
+priv->networkEventCallbackID[i] = -1;
+
 virNetServerClientSetCloseHook(client, remoteClientCloseFunc);
 return priv;
 }
@@ -5216,6 +5260,102 @@ cleanup:
 }
 
 
+static int
+remoteDispatchConnectNetworkEventRegisterAny(virNetServerPtr server 
ATTRIBUTE_UNUSED,
+ virNetServerClientPtr client 
ATTRIBUTE_UNUSED,
+ virNetMessagePtr msg 
ATTRIBUTE_UNUSED,
+ virNetMessageErrorPtr rerr 
ATTRIBUTE_UNUSED,
+ 
remote_connect_network_event_register_any_args *args,
+ 
remote_connect_network_event_register_any_ret *ret ATTRIBUTE_UNUSED)
+{
+int callbackID;
+int rv = -1;
+struct daemonClientPrivate *priv =
+virNetServerClientGetPrivateData(client);
+
+if (!priv->conn) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+goto cleanup;
+}
+
+virMutexLock(&priv->lock);
+
+if ((args->eventID & 0xFF) >= VIR_NETWORK_EVENT_ID_LAST ||
+((args->eventID & 0xFF00) >> 8) != VIR_EVENT_NAMESPACE_NETWORK) {
+virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported event ID %d"), 
args->eventID);
+goto cleanup;
+}
+
+if (priv->networkEventCallbackID[args->eventID & 0xFF] != -1)  {
+virReportError(VIR_ERR_INTERNAL_ERROR, _("network event %d already 
registered"), args->eventID);
+goto cleanup;
+}
+
+if ((callbackID = virConnectNetworkEventRegisterAny(priv->conn,
+NULL,
+args->eventID,
+
networkEventCallbacks[args

[libvirt] [v3 19/32] Created virDomainEventBalloonChange

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 56 +++--
 1 file changed, 40 insertions(+), 16 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 47b183a..589ffea 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -93,6 +93,7 @@ static virClassPtr virDomainEventGraphicsClass;
 static virClassPtr virDomainEventBlockJobClass;
 static virClassPtr virDomainEventDiskChangeClass;
 static virClassPtr virDomainEventTrayChangeClass;
+static virClassPtr virDomainEventBalloonChangeClass;
 
 static void virObjectEventDispose(void *obj);
 static void virDomainEventDispose(void *obj);
@@ -104,6 +105,7 @@ static void virDomainEventGraphicsDispose(void *obj);
 static void virDomainEventBlockJobDispose(void *obj);
 static void virDomainEventDiskChangeDispose(void *obj);
 static void virDomainEventTrayChangeDispose(void *obj);
+static void virDomainEventBalloonChangeDispose(void *obj);
 
 struct _virObjectEvent {
 virObject parent;
@@ -117,10 +119,6 @@ struct _virDomainEvent {
 
 union {
 struct {
-/* In unit of 1024 bytes */
-unsigned long long actual;
-} balloonChange;
-struct {
 char *devAlias;
 } deviceRemoved;
 } data;
@@ -204,6 +202,15 @@ struct _virDomainEventTrayChange {
 typedef struct _virDomainEventTrayChange virDomainEventTrayChange;
 typedef virDomainEventTrayChange *virDomainEventTrayChangePtr;
 
+struct _virDomainEventBalloonChange {
+virDomainEvent parent;
+
+/* In unit of 1024 bytes */
+unsigned long long actual;
+};
+typedef struct _virDomainEventBalloonChange virDomainEventBalloonChange;
+typedef virDomainEventBalloonChange *virDomainEventBalloonChangePtr;
+
 
 static int virObjectEventOnceInit(void)
 {
@@ -265,6 +272,12 @@ static int virObjectEventOnceInit(void)
  sizeof(virDomainEventTrayChange),
  virDomainEventTrayChangeDispose)))
 return -1;
+if (!(virDomainEventBalloonChangeClass = virClassNew(
+ virDomainEventClass,
+ "virDomainEventBalloonChange",
+ 
sizeof(virDomainEventBalloonChange),
+ 
virDomainEventBalloonChangeDispose)))
+return -1;
 return 0;
 }
 
@@ -385,6 +398,12 @@ static void virDomainEventTrayChangeDispose(void *obj)
 VIR_FREE(event->devAlias);
 }
 
+static void virDomainEventBalloonChangeDispose(void *obj)
+{
+virDomainEventBalloonChangePtr event = obj;
+VIR_DEBUG("obj=%p", event);
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
@@ -1484,36 +1503,36 @@ virDomainEventPMSuspendDiskNewFromDom(virDomainPtr dom)
 virDomainEventPtr virDomainEventBalloonChangeNewFromDom(virDomainPtr dom,
 unsigned long long 
actual)
 {
-virDomainEventPtr ev;
+virDomainEventBalloonChangePtr ev;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNew(virDomainEventClass,
+if (!(ev = virDomainEventNew(virDomainEventBalloonChangeClass,
  VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE,
  dom->id, dom->name, dom->uuid)))
 return NULL;
 
-ev->data.balloonChange.actual = actual;
+ev->actual = actual;
 
-return ev;
+return (virDomainEventPtr)ev;
 }
 virDomainEventPtr virDomainEventBalloonChangeNewFromObj(virDomainObjPtr obj,
 unsigned long long 
actual)
 {
-virDomainEventPtr ev;
+virDomainEventBalloonChangePtr ev;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNew(virDomainEventClass,
+if (!(ev = virDomainEventNew(virDomainEventBalloonChangeClass,
  VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE,
  obj->def->id, obj->def->name, 
obj->def->uuid)))
 return NULL;
 
-ev->data.balloonChange.actual = actual;
+ev->actual = actual;
 
-return ev;
+return (virDomainEventPtr)ev;
 }
 
 static virDomainEventPtr
@@ -1741,10 +1760,15 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
 goto cleanup;
 
 case VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE:
-((virConnectDomainEventBalloonChangeCallback)cb)(conn, dom,
- 
event->data.balloonChange.actual,
- cbopaque);
-goto cleanup;
+{
+virDomainEventBalloonChangePtr balloonChangeEvent;
+
+balloonChangeEvent = (virDomainEventBalloonChangePtr)event;
+((virConnectDomainEventBalloonChangeCallback)cb)(conn, dom,
+  

[libvirt] [v3 32/32] Added network events to the bridged network driver

2013-12-02 Thread Cédric Bosdonnat
---
 src/network/bridge_driver.c  | 90 
 src/network/bridge_driver_platform.h |  3 ++
 2 files changed, 93 insertions(+)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 1e4cc70..1b5742d 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -70,6 +70,7 @@
 #include "virfile.h"
 #include "virstring.h"
 #include "viraccessapicheck.h"
+#include "network_event.h"
 
 #define VIR_FROM_THIS VIR_FROM_NETWORK
 
@@ -438,6 +439,8 @@ networkStateInitialize(bool privileged,
 networkReloadFirewallRules(driverState);
 networkRefreshDaemons(driverState);
 
+driverState->networkEventState = virObjectEventStateNew();
+
 networkDriverUnlock(driverState);
 
 #ifdef HAVE_FIREWALLD
@@ -532,6 +535,8 @@ networkStateCleanup(void) {
 
 networkDriverLock(driverState);
 
+virObjectEventStateFree(driverState->networkEventState);
+
 /* free inactive networks */
 virNetworkObjListFree(&driverState->networks);
 
@@ -2290,6 +2295,55 @@ cleanup:
 return ret;
 }
 
+static int
+networkConnectNetworkEventRegisterAny(virConnectPtr conn,
+  virNetworkPtr net,
+  int eventID,
+  virConnectNetworkEventGenericCallback 
callback,
+  void *opaque,
+  virFreeCallback freecb)
+{
+virNetworkDriverStatePtr driver = conn->networkPrivateData;
+int ret = -1;
+
+networkDriverLock(driver);
+
+if (virConnectNetworkEventRegisterAnyEnsureACL(conn) < 0)
+goto cleanup;
+
+if (virNetworkEventStateRegisterID(conn, driver->networkEventState,
+   net, eventID,
+   VIR_OBJECT_EVENT_CALLBACK(callback),
+   opaque, freecb, &ret) < 0)
+ret = -1;
+
+networkDriverUnlock(driver);
+
+cleanup:
+return ret;
+}
+
+static int
+networkConnectNetworkEventDeregisterAny(virConnectPtr conn,
+int callbackID)
+{
+virNetworkDriverStatePtr driver = conn->networkPrivateData;
+int ret = -1;
+
+if (virConnectNetworkEventDeregisterAnyEnsureACL(conn) < 0)
+goto cleanup;
+
+
+networkDriverLock(driver);
+ret = virObjectEventStateDeregisterID(conn,
+  driver->networkEventState,
+  callbackID);
+networkDriverUnlock(driver);
+
+cleanup:
+return ret;
+}
+
 static int networkIsActive(virNetworkPtr net)
 {
 virNetworkObjPtr obj;
@@ -2483,6 +2537,7 @@ static virNetworkPtr networkCreateXML(virConnectPtr conn, 
const char *xml) {
 virNetworkDefPtr def;
 virNetworkObjPtr network = NULL;
 virNetworkPtr ret = NULL;
+virObjectEventPtr event = NULL;
 
 networkDriverLock(driver);
 
@@ -2509,11 +2564,17 @@ static virNetworkPtr networkCreateXML(virConnectPtr 
conn, const char *xml) {
 goto cleanup;
 }
 
+event = virNetworkEventLifecycleNew(network->def->name,
+network->def->uuid,
+VIR_NETWORK_EVENT_STARTED);
+
 VIR_INFO("Creating network '%s'", network->def->name);
 ret = virGetNetwork(conn, network->def->name, network->def->uuid);
 
 cleanup:
 virNetworkDefFree(def);
+if (event)
+virObjectEventStateQueue(driver->networkEventState, event);
 if (network)
 virNetworkObjUnlock(network);
 networkDriverUnlock(driver);
@@ -2526,6 +2587,7 @@ static virNetworkPtr networkDefineXML(virConnectPtr conn, 
const char *xml) {
 bool freeDef = true;
 virNetworkObjPtr network = NULL;
 virNetworkPtr ret = NULL;
+virObjectEventPtr event = NULL;
 
 networkDriverLock(driver);
 
@@ -2565,10 +2627,15 @@ static virNetworkPtr networkDefineXML(virConnectPtr 
conn, const char *xml) {
 goto cleanup;
 }
 
+event = virNetworkEventLifecycleNew(def->name, def->uuid,
+VIR_NETWORK_EVENT_DEFINED);
+
 VIR_INFO("Defining network '%s'", def->name);
 ret = virGetNetwork(conn, def->name, def->uuid);
 
 cleanup:
+if (event)
+virObjectEventStateQueue(driver->networkEventState, event);
 if (freeDef)
virNetworkDefFree(def);
 if (network)
@@ -2583,6 +2650,7 @@ networkUndefine(virNetworkPtr net) {
 virNetworkObjPtr network;
 int ret = -1;
 bool active = false;
+virObjectEventPtr event = NULL;
 
 networkDriverLock(driver);
 
@@ -2610,6 +2678,10 @@ networkUndefine(virNetworkPtr net) {
 virNetworkDefFree(network->newDef);
 network->newDef = NULL;
 
+event = virNetworkEventLifecycleNew(network->def->name,
+network->def->uuid,
+VIR_NETWORK_EVENT_UNDEFINED);
+
 VIR_INFO("Un

[libvirt] [v3 01/32] Added domain start/stop/define/undefine event unit tests

2013-12-02 Thread Cédric Bosdonnat
These unit tests are aiming at providing some help during the domain
events refactoring.
---
 .gitignore  |   1 +
 tests/Makefile.am   |   7 ++
 tests/objecteventtest.c | 246 
 3 files changed, 254 insertions(+)
 create mode 100644 tests/objecteventtest.c

diff --git a/.gitignore b/.gitignore
index 8de0b26..fbb2c01 100644
--- a/.gitignore
+++ b/.gitignore
@@ -160,6 +160,7 @@
 /tests/networkxml2argvtest
 /tests/nodeinfotest
 /tests/nwfilterxml2xmltest
+/tests/objecteventtest
 /tests/object-locking
 /tests/object-locking-files.txt
 /tests/object-locking.cm[ix]
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0900448..568b7a0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -303,6 +303,8 @@ EXTRA_DIST +=   \
$(NULL)
 endif ! WITH_LIBVIRTD
 
+test_programs += objecteventtest
+
 if WITH_SECDRIVER_APPARMOR
 test_scripts += virt-aa-helper-test
 else ! WITH_SECDRIVER_APPARMOR
@@ -895,6 +897,11 @@ fdstreamtest_SOURCES = \
fdstreamtest.c testutils.h testutils.c
 fdstreamtest_LDADD = $(LDADDS)
 
+objecteventtest_SOURCES = \
+   objecteventtest.c \
+   testutils.c testutils.h
+objecteventtest_LDADD = $(LDADDS)
+
 if WITH_LINUX
 fchosttest_SOURCES = \
fchosttest.c testutils.h testutils.c
diff --git a/tests/objecteventtest.c b/tests/objecteventtest.c
new file mode 100644
index 000..031d677
--- /dev/null
+++ b/tests/objecteventtest.c
@@ -0,0 +1,246 @@
+/*
+ * Copyright (C) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
+ *
+ * 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
+ * .
+ *
+ * Author: Cedric Bosdonnat 
+ */
+
+#include 
+
+#include "testutils.h"
+
+#include "virerror.h"
+#include "virxml.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+
+static const char domainDef[] =
+""
+"  test-domain"
+"  77a6fc12-07b5-9415-8abb-a803613f2a40"
+"  8388608"
+"  2097152"
+"  2"
+"  "
+"hvm"
+"  "
+"";
+
+struct lifecycleEventCounter {
+int startEvents;
+int stopEvents;
+int defineEvents;
+int undefineEvents;
+};
+
+static void lifecycleEventCounter_reset(struct lifecycleEventCounter* counter)
+{
+counter->startEvents = 0;
+counter->stopEvents = 0;
+counter->defineEvents = 0;
+counter->undefineEvents = 0;
+}
+
+struct objecteventTest {
+virConnectPtr conn;
+};
+
+
+static int domainLifecycleCb(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom ATTRIBUTE_UNUSED,
+ int event,
+ int detail ATTRIBUTE_UNUSED,
+ void *opaque)
+{
+struct lifecycleEventCounter *counter = opaque;
+
+switch (event) {
+case VIR_DOMAIN_EVENT_STARTED:
+counter->startEvents++;
+break;
+case VIR_DOMAIN_EVENT_STOPPED:
+counter->stopEvents++;
+break;
+case VIR_DOMAIN_EVENT_DEFINED:
+counter->defineEvents++;
+break;
+case VIR_DOMAIN_EVENT_UNDEFINED:
+counter->undefineEvents++;
+break;
+default:
+/* Ignore other events */
+break;
+}
+return 0;
+}
+
+static int
+testDomainCreateXML(const void *data)
+{
+const struct objecteventTest *test = data;
+struct lifecycleEventCounter counter;
+int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
+virDomainPtr dom;
+int id;
+int ret = 0;
+
+lifecycleEventCounter_reset(&counter);
+
+id = virConnectDomainEventRegisterAny(test->conn, NULL, eventId,
+   VIR_DOMAIN_EVENT_CALLBACK(&domainLifecycleCb),
+   &counter, NULL);
+dom = virDomainCreateXML(test->conn, domainDef, 0);
+
+if (dom == NULL || virEventRunDefaultImpl() < 0) {
+ret = -1;
+goto cleanup;
+}
+
+if (counter.startEvents != 1) {
+ret = -1;
+goto cleanup;
+}
+
+cleanup:
+virConnectDomainEventDeregisterAny(test->conn, id);
+if (dom != NULL) {
+virDomainDestroy(dom);
+virDomainFree(dom);
+}
+
+return ret;
+}
+
+static int
+testDomainDefine(const void *data)
+{
+const struct objecteventTest *test = data;
+struct lifecycleEventCounter counter;
+int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
+virDomainPtr dom;
+int id;

[libvirt] [v3 26/32] Added Network events API and virNetworkEventLifecycle.

2013-12-02 Thread Cédric Bosdonnat
Put all network-events related code in src/conf/network_event.[ch]
---
 include/libvirt/libvirt.h.in |  77 ++
 src/Makefile.am  |   5 ++
 src/conf/network_event.c | 152 +++
 src/conf/network_event.h |  50 ++
 src/conf/object_event.c  |   6 ++
 src/conf/object_event.h  |   1 +
 src/driver.h |  14 
 src/libvirt.c| 125 +++
 src/libvirt_private.syms |   2 +
 src/libvirt_public.syms  |   7 ++
 10 files changed, 439 insertions(+)
 create mode 100644 src/conf/network_event.c
 create mode 100644 src/conf/network_event.h

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 5aad75c..5b38dd7 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -4972,6 +4972,83 @@ int virConnectDomainEventRegisterAny(virConnectPtr conn,
 int virConnectDomainEventDeregisterAny(virConnectPtr conn,
int callbackID);
 
+/**
+ * virNetworkEventLifecycleType:
+ *
+ * a virNetworkEventLifecycleType is emitted during network lifecycle events
+ */
+typedef enum {
+VIR_NETWORK_EVENT_DEFINED = 0,
+VIR_NETWORK_EVENT_UNDEFINED = 1,
+VIR_NETWORK_EVENT_STARTED = 2,
+VIR_NETWORK_EVENT_STOPPED = 3,
+
+#ifdef VIR_ENUM_SENTINELS
+VIR_NETWORK_EVENT_LAST
+#endif
+} virNetworkEventLifecycleType;
+
+/**
+ * virConnectNetworkEventLifecycleCallback:
+ * @conn: connection object
+ * @net: network on which the event occurred
+ * @event: The specific virNetworkEventLifeCycleType which occurred
+ * @opaque: application specified data
+ *
+ * This callback occurs when the network is started or stopped.
+ *
+ * The callback signature to use when registering for an event of type
+ * VIR_NETWORK_EVENT_ID_LIFECYCLE with virConnectNetworkEventRegisterAny()
+ */
+typedef void (*virConnectNetworkEventLifecycleCallback)(virConnectPtr conn,
+virNetworkPtr net,
+int event,
+void *opaque);
+
+/**
+ * VIR_NETWORK_EVENT_CALLBACK:
+ *
+ * Used to cast the event specific callback into the generic one
+ * for use for virNetworkEventRegister
+ */
+#define VIR_NETWORK_EVENT_CALLBACK(cb) 
((virConnectNetworkEventGenericCallback)(cb))
+
+typedef enum {
+VIR_NETWORK_EVENT_ID_LIFECYCLE = 0,   /* 
virConnectNetworkEventLifecycleCallback */
+
+#ifdef VIR_ENUM_SENTINELS
+VIR_NETWORK_EVENT_ID_LAST
+/*
+ * NB: this enum value will increase over time as new events are
+ * added to the libvirt API. It reflects the last event ID supported
+ * by this version of the libvirt API.
+ */
+#endif
+} virNetworkEventID;
+
+/*
+ * virConnectNetworkEventGenericCallback:
+ * @conn: the connection pointer
+ * @net: the network pointer
+ * @opaque: application specified data
+ *
+ * A generic network event callback handler. Specific events usually
+ * have a customization with extra parameters
+ */
+typedef void (*virConnectNetworkEventGenericCallback)(virConnectPtr conn,
+  virNetworkPtr net,
+  void *opaque);
+
+/* Use VIR_NETWORK_EVENT_CALLBACK() to cast the 'cb' parameter  */
+int virConnectNetworkEventRegisterAny(virConnectPtr conn,
+  virNetworkPtr net, /* Optional, to 
filter */
+  int eventID,
+  virConnectNetworkEventGenericCallback cb,
+  void *opaque,
+  virFreeCallback freecb);
+
+int virConnectNetworkEventDeregisterAny(virConnectPtr conn,
+int callbackID);
 
 /**
  * virNWFilter:
diff --git a/src/Makefile.am b/src/Makefile.am
index a3ea55c..57e163f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -248,6 +248,9 @@ OBJECT_EVENT_SOURCES =  
\
 DOMAIN_EVENT_SOURCES = \
conf/domain_event.c conf/domain_event.h
 
+NETWORK_EVENT_SOURCES =\
+   conf/network_event.c conf/network_event.h
+
 # Network driver generic impl APIs
 NETWORK_CONF_SOURCES = \
conf/network_conf.c conf/network_conf.h
@@ -298,6 +301,7 @@ CONF_SOURCES =  
\
$(DOMAIN_CONF_SOURCES)  \
$(OBJECT_EVENT_SOURCES) \
$(DOMAIN_EVENT_SOURCES) \
+   $(NETWORK_EVENT_SOURCES)\
$(NETWORK_CONF_SOURCES)  

[libvirt] [v3 05/32] Renamed virDomainEventState to virObjectEventState

2013-12-02 Thread Cédric Bosdonnat
Leave virDomainEventRegister and its Deregister brother as these are
legacy functions only for domain lifecycle events.
---
 cfg.mk  |   4 +-
 src/conf/domain_event.c | 100 
 src/conf/domain_event.h |  26 +--
 src/libvirt_private.syms|  10 ++--
 src/libxl/libxl_conf.h  |   2 +-
 src/libxl/libxl_driver.c|   8 ++--
 src/lxc/lxc_conf.h  |   2 +-
 src/lxc/lxc_driver.c|  22 -
 src/lxc/lxc_process.c   |   6 +--
 src/parallels/parallels_utils.h |   2 +-
 src/qemu/qemu_conf.h|   2 +-
 src/qemu/qemu_domain.c  |   2 +-
 src/qemu/qemu_driver.c  |   6 +--
 src/remote/remote_driver.c  |  14 +++---
 src/test/test_driver.c  |  10 ++--
 src/uml/uml_conf.h  |   2 +-
 src/uml/uml_driver.c|   8 ++--
 src/vbox/vbox_tmpl.c|  14 +++---
 src/xen/xen_driver.c|   8 ++--
 src/xen/xen_driver.h|   2 +-
 tests/qemuhotplugtest.c |   2 +-
 21 files changed, 126 insertions(+), 126 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index bd3dd48..c256164 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -126,8 +126,8 @@ useless_free_options =  \
   --name=virDomainDiskDefFree  \
   --name=virDomainEventCallbackListFree\
   --name=virDomainEventFree\
-  --name=virDomainEventQueueFree   \
-  --name=virDomainEventStateFree   \
+  --name=virObjectEventQueueFree   \
+  --name=virObjectEventStateFree   \
   --name=virDomainFSDefFree\
   --name=virDomainGraphicsDefFree  \
   --name=virDomainHostdevDefFree   \
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index ee19142..5389aef 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -54,7 +54,7 @@ struct _virObjectEventQueue {
 virDomainEventPtr *events;
 };
 
-struct _virDomainEventState {
+struct _virObjectEventState {
 /* The list of domain event callbacks */
 virDomainEventCallbackListPtr callbacks;
 /* The queue of object events */
@@ -579,25 +579,25 @@ virObjectEventQueueNew(void)
 }
 
 static void
-virDomainEventStateLock(virDomainEventStatePtr state)
+virObjectEventStateLock(virObjectEventStatePtr state)
 {
 virMutexLock(&state->lock);
 }
 
 static void
-virDomainEventStateUnlock(virDomainEventStatePtr state)
+virObjectEventStateUnlock(virObjectEventStatePtr state)
 {
 virMutexUnlock(&state->lock);
 }
 
 /**
- * virDomainEventStateFree:
- * @list: virDomainEventStatePtr to free
+ * virObjectEventStateFree:
+ * @list: virObjectEventStatePtr to free
  *
- * Free a virDomainEventStatePtr and its members, and unregister the timer.
+ * Free a virObjectEventStatePtr and its members, and unregister the timer.
  */
 void
-virDomainEventStateFree(virDomainEventStatePtr state)
+virObjectEventStateFree(virObjectEventStatePtr state)
 {
 if (!state)
 return;
@@ -613,23 +613,23 @@ virDomainEventStateFree(virDomainEventStatePtr state)
 }
 
 
-static void virDomainEventStateFlush(virDomainEventStatePtr state);
+static void virObjectEventStateFlush(virObjectEventStatePtr state);
 
 static void
 virDomainEventTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
 {
-virDomainEventStatePtr state = opaque;
+virObjectEventStatePtr state = opaque;
 
-virDomainEventStateFlush(state);
+virObjectEventStateFlush(state);
 }
 
 /**
- * virDomainEventStateNew:
+ * virObjectEventStateNew:
  */
-virDomainEventStatePtr
-virDomainEventStateNew(void)
+virObjectEventStatePtr
+virObjectEventStateNew(void)
 {
-virDomainEventStatePtr state = NULL;
+virObjectEventStatePtr state = NULL;
 
 if (VIR_ALLOC(state) < 0)
 goto error;
@@ -652,7 +652,7 @@ virDomainEventStateNew(void)
 return state;
 
 error:
-virDomainEventStateFree(state);
+virObjectEventStateFree(state);
 return NULL;
 }
 
@@ -1437,7 +1437,7 @@ virObjectEventQueueDispatch(virObjectEventQueuePtr queue,
 }
 
 void
-virDomainEventStateQueue(virDomainEventStatePtr state,
+virObjectEventStateQueue(virObjectEventStatePtr state,
  virDomainEventPtr event)
 {
 if (state->timer < 0) {
@@ -1445,7 +1445,7 @@ virDomainEventStateQueue(virDomainEventStatePtr state,
 return;
 }
 
-virDomainEventStateLock(state);
+virObjectEventStateLock(state);
 
 if (virObjectEventQueuePush(state->queue, event) < 0) {
 VIR_DEBUG("Error adding event to queue");
@@ -1454,32 +1454,32 @@ virDomainEventStateQueue(virDomainEventStatePtr state,
 
 if (state->queue->count == 1)
 virEventUpdateTimeout(state->timer, 0);
-virDomainEventStateUnlock(state);
+virObjectEventStateUnlock(state);
 }
 
 
 static void
-virDomainEventStateDispatchFunc(virConnectPtr conn,
+virObjectEventStateDispatchFunc(virConnectPtr conn,
   

[libvirt] [v3 23/32] Renamed virDomainEventTimer to virObjectEventTimer

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 8462754..2fc0870 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -853,7 +853,7 @@ virObjectEventStateFree(virObjectEventStatePtr state)
 static void virObjectEventStateFlush(virObjectEventStatePtr state);
 
 static void
-virDomainEventTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
+virObjectEventTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
 {
 virObjectEventStatePtr state = opaque;
 
@@ -1988,7 +1988,7 @@ virObjectEventStateRegisterID(virConnectPtr conn,
 if ((state->callbacks->count == 0) &&
 (state->timer == -1) &&
 (state->timer = virEventAddTimeout(-1,
-   virDomainEventTimer,
+   virObjectEventTimer,
state,
NULL)) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -2040,7 +2040,7 @@ virDomainEventStateRegister(virConnectPtr conn,
 if ((state->callbacks->count == 0) &&
 (state->timer == -1) &&
 (state->timer = virEventAddTimeout(-1,
-   virDomainEventTimer,
+   virObjectEventTimer,
state,
NULL)) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-- 
1.8.4.4

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


[libvirt] [v3 00/32] network events feature

2013-12-02 Thread Cédric Bosdonnat
Changes with v2:
 * This patch serie includes fixes for Daniel's comments.

 * The two commits adding the network events API have been merged into
   one to get rid of build problems between those two.

 * Otherwise one commit has been dropped to fix the void* returns of
   domain events creation functions

Cédric Bosdonnat (32):
  Added domain start/stop/define/undefine event unit tests
  Rename virDomainEventCallback to virObjectEventCallback
  Renamed virDomainMeta to virObjectMeta
  Renamed virDomainEventQueue to virObjectEventQueue
  Renamed virDomainEventState to virObjectEventState
  Renamed virDomainEventCallbackList* to virObjectEventCallbackList*
  Created virObjectEventStateRegisterID
  virObject-ified virDomainEvent
  Create virDomainEventLifecycle to start removing the huge union
  Renamed virDomainEventNew* to virDomainEventLifecycleNew*
  Renamed virDomainEventNewInternal to virDomainEventNew
  Create virDomainEventRTCChange to get rid of the huge union
  Created virDomainEventWatchdog to get rid of the huge union
  Created virDomainEventIOError
  Created virDomainEventGraphics
  Created virDomainEventBlockJob
  Create virDomainEventDiskChange
  Created virDomainEventTrayChange
  Created virDomainEventBalloonChange
  Created virDomainEventDeviceRemoved and removed the huge union
  Use virObjectEventPtr instead of virDomainEventPtr
  Add object event namespaces for the event IDs
  Renamed virDomainEventTimer to virObjectEventTimer
  Split the virObjectEvent and virDomainEvent* to separate them after
  Extracted common parts of domain_event.[ch] to object_event.[ch]
  Added Network events API and virNetworkEventLifecycle.
  test driver: renamed testDomainEventQueue into testObjectEventQueue
  test driver: implemented network events
  Add network events unit tests
  daemon/remote.c: renamed remoteDispatchDomainEventSend
  Add network events to the remote driver
  Added network events to the bridged network driver

 .gitignore   |1 +
 cfg.mk   |6 +-
 daemon/libvirtd.h|1 +
 daemon/remote.c  |  176 +++-
 include/libvirt/libvirt.h.in |   77 ++
 src/Makefile.am  |   11 +
 src/conf/domain_event.c  | 1904 ++
 src/conf/domain_event.h  |  169 ++-
 src/conf/network_event.c |  152 +++
 src/conf/network_event.h |   50 +
 src/conf/object_event.c  |  797 ++
 src/conf/object_event.h  |   98 ++
 src/conf/object_event_private.h  |  113 ++
 src/driver.h |   14 +
 src/libvirt.c|  125 +++
 src/libvirt_private.syms |   25 +-
 src/libvirt_public.syms  |7 +
 src/libxl/libxl_conf.h   |2 +-
 src/libxl/libxl_driver.c |   46 +-
 src/lxc/lxc_conf.h   |2 +-
 src/lxc/lxc_driver.c |   54 +-
 src/lxc/lxc_process.c|   20 +-
 src/network/bridge_driver.c  |   90 ++
 src/network/bridge_driver_platform.h |3 +
 src/parallels/parallels_utils.h  |2 +-
 src/qemu/qemu_conf.h |2 +-
 src/qemu/qemu_domain.c   |6 +-
 src/qemu/qemu_domain.h   |2 +-
 src/qemu/qemu_driver.c   |  116 +--
 src/qemu/qemu_hotplug.c  |   10 +-
 src/qemu/qemu_migration.c|   38 +-
 src/qemu/qemu_process.c  |   70 +-
 src/remote/remote_driver.c   |  179 +++-
 src/remote/remote_protocol.x |   46 +-
 src/test/test_driver.c   |  198 ++--
 src/uml/uml_conf.h   |2 +-
 src/uml/uml_driver.c |   44 +-
 src/vbox/vbox_tmpl.c |   22 +-
 src/xen/xen_driver.c |   10 +-
 src/xen/xen_driver.h |4 +-
 src/xen/xen_inotify.c|   10 +-
 src/xen/xs_internal.c|   20 +-
 tests/Makefile.am|7 +
 tests/objecteventtest.c  |  411 
 tests/qemuhotplugtest.c  |2 +-
 45 files changed, 3584 insertions(+), 1560 deletions(-)
 create mode 100644 src/conf/network_event.c
 create mode 100644 src/conf/network_event.h
 create mode 100644 src/conf/object_event.c
 create mode 100644 src/conf/object_event.h
 create mode 100644 src/conf/object_event_private.h
 create mode 100644 tests/objecteventtest.c

-- 
1.8.4.4

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

[libvirt] [v3 08/32] virObject-ified virDomainEvent

2013-12-02 Thread Cédric Bosdonnat
Added a parent class virObjectEvent for future event types
---
 cfg.mk   |   2 -
 src/conf/domain_event.c  | 619 +++
 src/conf/domain_event.h  |   5 +-
 src/libvirt_private.syms |   1 -
 src/qemu/qemu_driver.c   |   2 +-
 src/test/test_driver.c   |   4 +-
 6 files changed, 413 insertions(+), 220 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index c256164..198e084 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -125,7 +125,6 @@ useless_free_options =  \
   --name=virDomainDeviceDefFree\
   --name=virDomainDiskDefFree  \
   --name=virDomainEventCallbackListFree\
-  --name=virDomainEventFree\
   --name=virObjectEventQueueFree   \
   --name=virObjectEventStateFree   \
   --name=virDomainFSDefFree\
@@ -205,7 +204,6 @@ useless_free_options =  \
 # y virDomainDeviceDefFree
 # y virDomainDiskDefFree
 # y virDomainEventCallbackListFree
-# y virDomainEventFree
 # y virDomainEventQueueFree
 # y virDomainFSDefFree
 # n virDomainFree
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 99f0340..6b02022 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -81,8 +81,20 @@ struct _virObjectEventCallback {
 int deleted;
 };
 
-struct _virDomainEvent {
+
+
+static virClassPtr virObjectEventClass;
+static virClassPtr virDomainEventClass;
+static void virObjectEventDispose(void *obj);
+static void virDomainEventDispose(void *obj);
+
+struct _virObjectEvent {
+virObject parent;
 int eventID;
+};
+
+struct _virDomainEvent {
+virObjectEvent parent;
 
 virObjectMeta meta;
 
@@ -135,6 +147,98 @@ struct _virDomainEvent {
 } data;
 };
 
+static int virObjectEventOnceInit(void)
+{
+if (!(virObjectEventClass = virClassNew(virClassForObject(),
+ "virObjectEvent",
+ sizeof(virObjectEvent),
+ virObjectEventDispose)))
+return -1;
+if (!(virDomainEventClass = virClassNew(virObjectEventClass,
+ "virDomainEvent",
+ sizeof(virDomainEvent),
+ virDomainEventDispose)))
+return -1;
+return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virObjectEvent)
+
+static int virObjectEventGetEventID(void *anyobj)
+{
+virObjectEventPtr obj = anyobj;
+
+if (!virObjectIsClass(obj, virObjectEventClass)) {
+VIR_WARN("Object %p (%s) is not a virObjectEvent instance",
+ obj, obj ? virClassName(obj->parent.klass) : "(unknown)");
+return -1;
+}
+return obj->eventID;
+}
+
+static void virObjectEventDispose(void *obj)
+{
+virObjectEventPtr event = obj;
+
+VIR_DEBUG("obj=%p", event);
+}
+
+static void virDomainEventDispose(void *obj)
+{
+virDomainEventPtr event = obj;
+
+VIR_DEBUG("obj=%p", event);
+
+switch (virObjectEventGetEventID(event)) {
+case VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON:
+case VIR_DOMAIN_EVENT_ID_IO_ERROR:
+VIR_FREE(event->data.ioError.srcPath);
+VIR_FREE(event->data.ioError.devAlias);
+VIR_FREE(event->data.ioError.reason);
+break;
+
+case VIR_DOMAIN_EVENT_ID_GRAPHICS:
+if (event->data.graphics.local) {
+VIR_FREE(event->data.graphics.local->node);
+VIR_FREE(event->data.graphics.local->service);
+VIR_FREE(event->data.graphics.local);
+}
+if (event->data.graphics.remote) {
+VIR_FREE(event->data.graphics.remote->node);
+VIR_FREE(event->data.graphics.remote->service);
+VIR_FREE(event->data.graphics.remote);
+}
+VIR_FREE(event->data.graphics.authScheme);
+if (event->data.graphics.subject) {
+size_t i;
+for (i = 0; i < event->data.graphics.subject->nidentity; i++) {
+VIR_FREE(event->data.graphics.subject->identities[i].type);
+VIR_FREE(event->data.graphics.subject->identities[i].name);
+}
+VIR_FREE(event->data.graphics.subject);
+}
+break;
+
+case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
+VIR_FREE(event->data.blockJob.path);
+break;
+
+case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
+VIR_FREE(event->data.diskChange.oldSrcPath);
+VIR_FREE(event->data.diskChange.newSrcPath);
+VIR_FREE(event->data.diskChange.devAlias);
+break;
+case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
+VIR_FREE(event->data.trayChange.devAlias);
+break;
+case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
+VIR_FREE(event->data.deviceRemoved.devAlias);
+break;
+}
+
+VIR_FREE(event->meta.name);
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback 

[libvirt] [v3 07/32] Created virObjectEventStateRegisterID

2013-12-02 Thread Cédric Bosdonnat
Keep virDomainEventStateRegisterID as a convenience wrapper around
this new function.
---
 src/conf/domain_event.c  | 130 ++-
 src/conf/domain_event.h  |  25 +
 src/libvirt_private.syms |   1 +
 3 files changed, 110 insertions(+), 46 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 8442db5..99f0340 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -32,6 +32,8 @@
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
+#define VIR_OBJECT_EVENT_CALLBACK(cb) 
((virConnectObjectEventGenericCallback)(cb))
+
 struct _virObjectMeta {
 int id;
 char *name;
@@ -73,7 +75,7 @@ struct _virObjectEventCallback {
 int eventID;
 virConnectPtr conn;
 virObjectMetaPtr meta;
-virConnectDomainEventGenericCallback cb;
+virConnectObjectEventGenericCallback cb;
 void *opaque;
 virFreeCallback freecb;
 int deleted;
@@ -173,7 +175,7 @@ virDomainEventCallbackListRemove(virConnectPtr conn,
 int ret = 0;
 size_t i;
 for (i = 0; i < cbList->count; i++) {
-if (cbList->callbacks[i]->cb == VIR_DOMAIN_EVENT_CALLBACK(callback) &&
+if (cbList->callbacks[i]->cb == VIR_OBJECT_EVENT_CALLBACK(callback) &&
 cbList->callbacks[i]->eventID == VIR_DOMAIN_EVENT_ID_LIFECYCLE &&
 cbList->callbacks[i]->conn == conn) {
 virFreeCallback freecb = cbList->callbacks[i]->freecb;
@@ -266,7 +268,7 @@ virDomainEventCallbackListMarkDelete(virConnectPtr conn,
 int ret = 0;
 size_t i;
 for (i = 0; i < cbList->count; i++) {
-if (cbList->callbacks[i]->cb == VIR_DOMAIN_EVENT_CALLBACK(callback) &&
+if (cbList->callbacks[i]->cb == VIR_OBJECT_EVENT_CALLBACK(callback) &&
 cbList->callbacks[i]->eventID == VIR_DOMAIN_EVENT_ID_LIFECYCLE &&
 cbList->callbacks[i]->conn == conn) {
 cbList->callbacks[i]->deleted = 1;
@@ -360,7 +362,7 @@ virObjectEventCallbackListAddID(virConnectPtr conn,
 const char *name,
 int id,
 int eventID,
-virConnectDomainEventGenericCallback callback,
+virConnectObjectEventGenericCallback callback,
 void *opaque,
 virFreeCallback freecb,
 int *callbackID)
@@ -376,7 +378,7 @@ virObjectEventCallbackListAddID(virConnectPtr conn,
 
 /* check if we already have this callback on our list */
 for (i = 0; i < cbList->count; i++) {
-if (cbList->callbacks[i]->cb == VIR_DOMAIN_EVENT_CALLBACK(callback) &&
+if (cbList->callbacks[i]->cb == VIR_OBJECT_EVENT_CALLBACK(callback) &&
 cbList->callbacks[i]->eventID == eventID &&
 cbList->callbacks[i]->conn == conn &&
 ((uuid && cbList->callbacks[i]->meta &&
@@ -458,7 +460,7 @@ virDomainEventCallbackListAdd(virConnectPtr conn,
 {
 return virObjectEventCallbackListAddID(conn, cbList, NULL, NULL, 0,
VIR_DOMAIN_EVENT_ID_LIFECYCLE,
-   VIR_DOMAIN_EVENT_CALLBACK(callback),
+   VIR_OBJECT_EVENT_CALLBACK(callback),
opaque, freecb, NULL);
 }
 
@@ -1240,9 +1242,9 @@ virObjectEventQueuePush(virObjectEventQueuePtr evtQueue,
 }
 
 
-typedef void (*virDomainEventDispatchFunc)(virConnectPtr conn,
+typedef void (*virObjectEventDispatchFunc)(virConnectPtr conn,
virDomainEventPtr event,
-   
virConnectDomainEventGenericCallback cb,
+   
virConnectObjectEventGenericCallback cb,
void *cbopaque,
void *opaque);
 
@@ -1405,7 +1407,7 @@ static int 
virDomainEventDispatchMatchCallback(virDomainEventPtr event,
 static void
 virDomainEventDispatch(virDomainEventPtr event,
virObjectEventCallbackListPtr callbacks,
-   virDomainEventDispatchFunc dispatch,
+   virObjectEventDispatchFunc dispatch,
void *opaque)
 {
 size_t i;
@@ -1430,7 +1432,7 @@ virDomainEventDispatch(virDomainEventPtr event,
 static void
 virObjectEventQueueDispatch(virObjectEventQueuePtr queue,
 virObjectEventCallbackListPtr callbacks,
-virDomainEventDispatchFunc dispatch,
+virObjectEventDispatchFunc dispatch,
 void *opaque)
 {
 size_t i;
@@ -1468,7 +1470,7 @@ virObjectEventStateQueue(virObjectEventStatePtr state,
 static void
 virObjectEventStateDispatchFunc(virConnectPtr conn,
 virDomainEventPtr event,
- 

[libvirt] [v3 09/32] Create virDomainEventLifecycle to start removing the huge union

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 57 +++--
 1 file changed, 41 insertions(+), 16 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 6b02022..9a0c32b 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -85,8 +85,10 @@ struct _virObjectEventCallback {
 
 static virClassPtr virObjectEventClass;
 static virClassPtr virDomainEventClass;
+static virClassPtr virDomainEventLifecycleClass;
 static void virObjectEventDispose(void *obj);
 static void virDomainEventDispose(void *obj);
+static void virDomainEventLifecycleDispose(void *obj);
 
 struct _virObjectEvent {
 virObject parent;
@@ -100,10 +102,6 @@ struct _virDomainEvent {
 
 union {
 struct {
-int type;
-int detail;
-} lifecycle;
-struct {
 long long offset;
 } rtcChange;
 struct {
@@ -147,6 +145,16 @@ struct _virDomainEvent {
 } data;
 };
 
+struct _virDomainEventLifecycle {
+virDomainEvent parent;
+
+int type;
+int detail;
+};
+typedef struct _virDomainEventLifecycle virDomainEventLifecycle;
+typedef virDomainEventLifecycle *virDomainEventLifecyclePtr;
+
+
 static int virObjectEventOnceInit(void)
 {
 if (!(virObjectEventClass = virClassNew(virClassForObject(),
@@ -159,6 +167,12 @@ static int virObjectEventOnceInit(void)
  sizeof(virDomainEvent),
  virDomainEventDispose)))
 return -1;
+if (!(virDomainEventLifecycleClass = virClassNew(
+ virDomainEventClass,
+ "virDomainEventLifecycle",
+ sizeof(virDomainEventLifecycle),
+ virDomainEventLifecycleDispose)))
+return -1;
 return 0;
 }
 
@@ -239,6 +253,12 @@ static void virDomainEventDispose(void *obj)
 VIR_FREE(event->meta.name);
 }
 
+static void virDomainEventLifecycleDispose(void *obj)
+{
+virDomainEventLifecyclePtr event = obj;
+VIR_DEBUG("obj=%p", event);
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
@@ -772,20 +792,20 @@ virDomainEventPtr virDomainEventNew(int id, const char 
*name,
 const unsigned char *uuid,
 int type, int detail)
 {
-virDomainEventPtr event;
+virDomainEventLifecyclePtr event;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(event = virDomainEventNewInternal(virDomainEventClass,
-  VIR_DOMAIN_EVENT_ID_LIFECYCLE,
-  id, name, uuid)))
+if (!(event = virDomainEventNewInternal(virDomainEventLifecycleClass,
+VIR_DOMAIN_EVENT_ID_LIFECYCLE,
+id, name, uuid)))
 return NULL;
 
-event->data.lifecycle.type = type;
-event->data.lifecycle.detail = detail;
+event->type = type;
+event->detail = detail;
 
-return event;
+return (virDomainEventPtr)event;
 }
 
 virDomainEventPtr virDomainEventNewFromDom(virDomainPtr dom, int type, int 
detail)
@@ -1458,11 +1478,16 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
 
 switch ((virDomainEventID) eventID) {
 case VIR_DOMAIN_EVENT_ID_LIFECYCLE:
-((virConnectDomainEventCallback)cb)(conn, dom,
-event->data.lifecycle.type,
-event->data.lifecycle.detail,
-cbopaque);
-goto cleanup;
+{
+virDomainEventLifecyclePtr lifecycleEvent;
+
+lifecycleEvent = (virDomainEventLifecyclePtr)event;
+((virConnectDomainEventCallback)cb)(conn, dom,
+lifecycleEvent->type,
+lifecycleEvent->detail,
+cbopaque);
+goto cleanup;
+}
 
 case VIR_DOMAIN_EVENT_ID_REBOOT:
 (cb)(conn, dom,
-- 
1.8.4.4

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


[libvirt] [v3 30/32] daemon/remote.c: renamed remoteDispatchDomainEventSend

2013-12-02 Thread Cédric Bosdonnat
Renamed into remoteDispatchObjectEventSend as it will later be used for
both the domain and network events.
---
 daemon/remote.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index decaecc..f060006 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -108,7 +108,7 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr 
errors,
 
 /* Prototypes */
 static void
-remoteDispatchDomainEventSend(virNetServerClientPtr client,
+remoteDispatchObjectEventSend(virNetServerClientPtr client,
   virNetServerProgramPtr program,
   int procnr,
   xdrproc_t proc,
@@ -134,7 +134,7 @@ static int remoteRelayDomainEventLifecycle(virConnectPtr 
conn ATTRIBUTE_UNUSED,
 data.event = event;
 data.detail = detail;
 
-remoteDispatchDomainEventSend(client, remoteProgram,
+remoteDispatchObjectEventSend(client, remoteProgram,
   REMOTE_PROC_DOMAIN_EVENT_LIFECYCLE,
   
(xdrproc_t)xdr_remote_domain_event_lifecycle_msg, &data);
 
@@ -157,7 +157,7 @@ static int remoteRelayDomainEventReboot(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 memset(&data, 0, sizeof(data));
 make_nonnull_domain(&data.dom, dom);
 
-remoteDispatchDomainEventSend(client, remoteProgram,
+remoteDispatchObjectEventSend(client, remoteProgram,
   REMOTE_PROC_DOMAIN_EVENT_REBOOT,
   
(xdrproc_t)xdr_remote_domain_event_reboot_msg, &data);
 
@@ -183,7 +183,7 @@ static int remoteRelayDomainEventRTCChange(virConnectPtr 
conn ATTRIBUTE_UNUSED,
 make_nonnull_domain(&data.dom, dom);
 data.offset = offset;
 
-remoteDispatchDomainEventSend(client, remoteProgram,
+remoteDispatchObjectEventSend(client, remoteProgram,
   REMOTE_PROC_DOMAIN_EVENT_RTC_CHANGE,
   
(xdrproc_t)xdr_remote_domain_event_rtc_change_msg, &data);
 
@@ -209,7 +209,7 @@ static int remoteRelayDomainEventWatchdog(virConnectPtr 
conn ATTRIBUTE_UNUSED,
 make_nonnull_domain(&data.dom, dom);
 data.action = action;
 
-remoteDispatchDomainEventSend(client, remoteProgram,
+remoteDispatchObjectEventSend(client, remoteProgram,
   REMOTE_PROC_DOMAIN_EVENT_WATCHDOG,
   
(xdrproc_t)xdr_remote_domain_event_watchdog_msg, &data);
 
@@ -240,7 +240,7 @@ static int remoteRelayDomainEventIOError(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 make_nonnull_domain(&data.dom, dom);
 data.action = action;
 
-remoteDispatchDomainEventSend(client, remoteProgram,
+remoteDispatchObjectEventSend(client, remoteProgram,
   REMOTE_PROC_DOMAIN_EVENT_IO_ERROR,
   
(xdrproc_t)xdr_remote_domain_event_io_error_msg, &data);
 
@@ -279,7 +279,7 @@ static int 
remoteRelayDomainEventIOErrorReason(virConnectPtr conn ATTRIBUTE_UNUS
 
 make_nonnull_domain(&data.dom, dom);
 
-remoteDispatchDomainEventSend(client, remoteProgram,
+remoteDispatchObjectEventSend(client, remoteProgram,
   REMOTE_PROC_DOMAIN_EVENT_IO_ERROR_REASON,
   
(xdrproc_t)xdr_remote_domain_event_io_error_reason_msg, &data);
 
@@ -342,7 +342,7 @@ static int remoteRelayDomainEventGraphics(virConnectPtr 
conn ATTRIBUTE_UNUSED,
 }
 make_nonnull_domain(&data.dom, dom);
 
-remoteDispatchDomainEventSend(client, remoteProgram,
+remoteDispatchObjectEventSend(client, remoteProgram,
   REMOTE_PROC_DOMAIN_EVENT_GRAPHICS,
   
(xdrproc_t)xdr_remote_domain_event_graphics_msg, &data);
 
@@ -388,7 +388,7 @@ static int remoteRelayDomainEventBlockJob(virConnectPtr 
conn ATTRIBUTE_UNUSED,
 data.status = status;
 make_nonnull_domain(&data.dom, dom);
 
-remoteDispatchDomainEventSend(client, remoteProgram,
+remoteDispatchObjectEventSend(client, remoteProgram,
   REMOTE_PROC_DOMAIN_EVENT_BLOCK_JOB,
   
(xdrproc_t)xdr_remote_domain_event_block_job_msg, &data);
 
@@ -415,7 +415,7 @@ static int remoteRelayDomainEventControlError(virConnectPtr 
conn ATTRIBUTE_UNUSE
 memset(&data, 0, sizeof(data));
 make_nonnull_domain(&data.dom, dom);
 
-remoteDispatchDomainEventSend(client, remoteProgram,
+remoteDispatchObjectEventSend(client, remoteProgram,
   REMOTE_PROC_DOMAIN_EVENT_CONTROL_ERROR,
   
(xdrproc_t)xdr_remote_domain_event_control_error_msg, &data);
 
@@ -461,7 +461,7 @@ static int remoteRelayDomainEventDiskChange(virConnectPtr 
conn ATTRIBUTE_UNUSED,
 
 make_nonnull_domain(&data.dom, dom);
 
-remoteDispatchDomainEventSend(client, remoteProgram,
+

[libvirt] [v3 20/32] Created virDomainEventDeviceRemoved and removed the huge union

2013-12-02 Thread Cédric Bosdonnat
RIP virDomainEvent union. All data are now stored in each
virObjectEvent subclass.
---
 src/conf/domain_event.c | 77 +
 1 file changed, 45 insertions(+), 32 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 589ffea..9108207 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -94,6 +94,7 @@ static virClassPtr virDomainEventBlockJobClass;
 static virClassPtr virDomainEventDiskChangeClass;
 static virClassPtr virDomainEventTrayChangeClass;
 static virClassPtr virDomainEventBalloonChangeClass;
+static virClassPtr virDomainEventDeviceRemovedClass;
 
 static void virObjectEventDispose(void *obj);
 static void virDomainEventDispose(void *obj);
@@ -106,6 +107,7 @@ static void virDomainEventBlockJobDispose(void *obj);
 static void virDomainEventDiskChangeDispose(void *obj);
 static void virDomainEventTrayChangeDispose(void *obj);
 static void virDomainEventBalloonChangeDispose(void *obj);
+static void virDomainEventDeviceRemovedDispose(void *obj);
 
 struct _virObjectEvent {
 virObject parent;
@@ -116,12 +118,6 @@ struct _virDomainEvent {
 virObjectEvent parent;
 
 virObjectMeta meta;
-
-union {
-struct {
-char *devAlias;
-} deviceRemoved;
-} data;
 };
 
 struct _virDomainEventLifecycle {
@@ -211,6 +207,14 @@ struct _virDomainEventBalloonChange {
 typedef struct _virDomainEventBalloonChange virDomainEventBalloonChange;
 typedef virDomainEventBalloonChange *virDomainEventBalloonChangePtr;
 
+struct _virDomainEventDeviceRemoved {
+virDomainEvent parent;
+
+char *devAlias;
+};
+typedef struct _virDomainEventDeviceRemoved virDomainEventDeviceRemoved;
+typedef virDomainEventDeviceRemoved *virDomainEventDeviceRemovedPtr;
+
 
 static int virObjectEventOnceInit(void)
 {
@@ -278,6 +282,12 @@ static int virObjectEventOnceInit(void)
  
sizeof(virDomainEventBalloonChange),
  
virDomainEventBalloonChangeDispose)))
 return -1;
+if (!(virDomainEventDeviceRemovedClass = virClassNew(
+ virDomainEventClass,
+ "virDomainEventDeviceRemoved",
+ 
sizeof(virDomainEventDeviceRemoved),
+ 
virDomainEventDeviceRemovedDispose)))
+return -1;
 return 0;
 }
 
@@ -308,13 +318,6 @@ static void virDomainEventDispose(void *obj)
 
 VIR_DEBUG("obj=%p", event);
 
-switch (virObjectEventGetEventID(event)) {
-
-case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
-VIR_FREE(event->data.deviceRemoved.devAlias);
-break;
-}
-
 VIR_FREE(event->meta.name);
 }
 
@@ -404,6 +407,14 @@ static void virDomainEventBalloonChangeDispose(void *obj)
 VIR_DEBUG("obj=%p", event);
 }
 
+static void virDomainEventDeviceRemovedDispose(void *obj)
+{
+virDomainEventDeviceRemovedPtr event = obj;
+VIR_DEBUG("obj=%p", event);
+
+VIR_FREE(event->devAlias);
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
@@ -1535,43 +1546,40 @@ virDomainEventPtr 
virDomainEventBalloonChangeNewFromObj(virDomainObjPtr obj,
 return (virDomainEventPtr)ev;
 }
 
-static virDomainEventPtr
-virDomainEventDeviceRemovedNew(int id,
-   const char *name,
-   unsigned char *uuid,
-   const char *devAlias)
+static virDomainEventPtr virDomainEventDeviceRemovedNew(int id,
+const char *name,
+unsigned char *uuid,
+const char *devAlias)
 {
-virDomainEventPtr ev;
+virDomainEventDeviceRemovedPtr ev;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNew(virDomainEventClass,
+if (!(ev = virDomainEventNew(virDomainEventDeviceRemovedClass,
  VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED,
  id, name, uuid)))
 return NULL;
 
-if (VIR_STRDUP(ev->data.deviceRemoved.devAlias, devAlias) < 0)
+if (VIR_STRDUP(ev->devAlias, devAlias) < 0)
 goto error;
 
-return ev;
+return (virDomainEventPtr)ev;
 
 error:
 virObjectUnref(ev);
 return NULL;
 }
 
-virDomainEventPtr
-virDomainEventDeviceRemovedNewFromObj(virDomainObjPtr obj,
-  const char *devAlias)
+virDomainEventPtr virDomainEventDeviceRemovedNewFromObj(virDomainObjPtr obj,
+const char *devAlias)
 {
 return virDomainEventDeviceRemovedNew(obj->def->id, obj->def->name,
   obj->def->uuid, devAlias);
 }
 
-virDomainEventPtr
-virDomainEventDeviceRemovedNewFromDom(virDomainPtr dom,
-

[libvirt] [v3 15/32] Created virDomainEventGraphics

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 148 +++-
 src/conf/domain_event.h |  20 +++
 2 files changed, 95 insertions(+), 73 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index de3664f..e145157 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -89,12 +89,14 @@ static virClassPtr virDomainEventLifecycleClass;
 static virClassPtr virDomainEventRTCChangeClass;
 static virClassPtr virDomainEventWatchdogClass;
 static virClassPtr virDomainEventIOErrorClass;
+static virClassPtr virDomainEventGraphicsClass;
 static void virObjectEventDispose(void *obj);
 static void virDomainEventDispose(void *obj);
 static void virDomainEventLifecycleDispose(void *obj);
 static void virDomainEventRTCChangeDispose(void *obj);
 static void virDomainEventWatchdogDispose(void *obj);
 static void virDomainEventIOErrorDispose(void *obj);
+static void virDomainEventGraphicsDispose(void *obj);
 
 struct _virObjectEvent {
 virObject parent;
@@ -108,13 +110,6 @@ struct _virDomainEvent {
 
 union {
 struct {
-int phase;
-virDomainEventGraphicsAddressPtr local;
-virDomainEventGraphicsAddressPtr remote;
-char *authScheme;
-virDomainEventGraphicsSubjectPtr subject;
-} graphics;
-struct {
 char *path;
 int type;
 int status;
@@ -175,6 +170,18 @@ struct _virDomainEventIOError {
 typedef struct _virDomainEventIOError virDomainEventIOError;
 typedef virDomainEventIOError *virDomainEventIOErrorPtr;
 
+struct _virDomainEventGraphics {
+virDomainEvent parent;
+
+int phase;
+virDomainEventGraphicsAddressPtr local;
+virDomainEventGraphicsAddressPtr remote;
+char *authScheme;
+virDomainEventGraphicsSubjectPtr subject;
+};
+typedef struct _virDomainEventGraphics virDomainEventGraphics;
+typedef virDomainEventGraphics *virDomainEventGraphicsPtr;
+
 static int virObjectEventOnceInit(void)
 {
 if (!(virObjectEventClass = virClassNew(virClassForObject(),
@@ -211,6 +218,12 @@ static int virObjectEventOnceInit(void)
  sizeof(virDomainEventIOError),
  virDomainEventIOErrorDispose)))
 return -1;
+if (!(virDomainEventGraphicsClass = virClassNew(
+ virDomainEventClass,
+ "virDomainEventGraphics",
+ sizeof(virDomainEventGraphics),
+ virDomainEventGraphicsDispose)))
+return -1;
 return 0;
 }
 
@@ -243,28 +256,6 @@ static void virDomainEventDispose(void *obj)
 
 switch (virObjectEventGetEventID(event)) {
 
-case VIR_DOMAIN_EVENT_ID_GRAPHICS:
-if (event->data.graphics.local) {
-VIR_FREE(event->data.graphics.local->node);
-VIR_FREE(event->data.graphics.local->service);
-VIR_FREE(event->data.graphics.local);
-}
-if (event->data.graphics.remote) {
-VIR_FREE(event->data.graphics.remote->node);
-VIR_FREE(event->data.graphics.remote->service);
-VIR_FREE(event->data.graphics.remote);
-}
-VIR_FREE(event->data.graphics.authScheme);
-if (event->data.graphics.subject) {
-size_t i;
-for (i = 0; i < event->data.graphics.subject->nidentity; i++) {
-VIR_FREE(event->data.graphics.subject->identities[i].type);
-VIR_FREE(event->data.graphics.subject->identities[i].name);
-}
-VIR_FREE(event->data.graphics.subject);
-}
-break;
-
 case VIR_DOMAIN_EVENT_ID_BLOCK_JOB:
 VIR_FREE(event->data.blockJob.path);
 break;
@@ -313,6 +304,32 @@ static void virDomainEventIOErrorDispose(void *obj)
 VIR_FREE(event->reason);
 }
 
+static void virDomainEventGraphicsDispose(void *obj)
+{
+virDomainEventGraphicsPtr event = obj;
+VIR_DEBUG("obj=%p", event);
+
+if (event->local) {
+VIR_FREE(event->local->node);
+VIR_FREE(event->local->service);
+VIR_FREE(event->local);
+}
+if (event->remote) {
+VIR_FREE(event->remote->node);
+VIR_FREE(event->remote->service);
+VIR_FREE(event->remote);
+}
+VIR_FREE(event->authScheme);
+if (event->subject) {
+size_t i;
+for (i = 0; i < event->subject->nidentity; i++) {
+VIR_FREE(event->subject->identities[i].type);
+VIR_FREE(event->subject->identities[i].name);
+}
+VIR_FREE(event->subject);
+}
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
@@ -1079,62 +1096,62 @@ virDomainEventPtr 
virDomainEventIOErrorReasonNewFromObj(virDomainObjPtr obj,
 
 
 virDomainEventPtr virDomainEventGraphicsNewFromDom(virDomainPtr dom,
-

[libvirt] [v3 13/32] Created virDomainEventWatchdog to get rid of the huge union

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 60 +
 1 file changed, 41 insertions(+), 19 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index ab38a3b..63119b2 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -87,10 +87,12 @@ static virClassPtr virObjectEventClass;
 static virClassPtr virDomainEventClass;
 static virClassPtr virDomainEventLifecycleClass;
 static virClassPtr virDomainEventRTCChangeClass;
+static virClassPtr virDomainEventWatchdogClass;
 static void virObjectEventDispose(void *obj);
 static void virDomainEventDispose(void *obj);
 static void virDomainEventLifecycleDispose(void *obj);
 static void virDomainEventRTCChangeDispose(void *obj);
+static void virDomainEventWatchdogDispose(void *obj);
 
 struct _virObjectEvent {
 virObject parent;
@@ -104,9 +106,6 @@ struct _virDomainEvent {
 
 union {
 struct {
-int action;
-} watchdog;
-struct {
 char *srcPath;
 char *devAlias;
 int action;
@@ -161,6 +160,14 @@ struct _virDomainEventRTCChange {
 typedef struct _virDomainEventRTCChange virDomainEventRTCChange;
 typedef virDomainEventRTCChange *virDomainEventRTCChangePtr;
 
+struct _virDomainEventWatchdog {
+virDomainEvent parent;
+
+int action;
+};
+typedef struct _virDomainEventWatchdog virDomainEventWatchdog;
+typedef virDomainEventWatchdog *virDomainEventWatchdogPtr;
+
 static int virObjectEventOnceInit(void)
 {
 if (!(virObjectEventClass = virClassNew(virClassForObject(),
@@ -185,6 +192,12 @@ static int virObjectEventOnceInit(void)
  sizeof(virDomainEventRTCChange),
  virDomainEventRTCChangeDispose)))
 return -1;
+if (!(virDomainEventWatchdogClass = virClassNew(
+ virDomainEventClass,
+ "virDomainEventWatchdog",
+ sizeof(virDomainEventWatchdog),
+ virDomainEventWatchdogDispose)))
+return -1;
 return 0;
 }
 
@@ -277,6 +290,12 @@ static void virDomainEventRTCChangeDispose(void *obj)
 VIR_DEBUG("obj=%p", event);
 }
 
+static void virDomainEventWatchdogDispose(void *obj)
+{
+virDomainEventWatchdogPtr event = obj;
+VIR_DEBUG("obj=%p", event);
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
@@ -910,40 +929,38 @@ virDomainEventPtr 
virDomainEventRTCChangeNewFromObj(virDomainObjPtr obj,
 return (virDomainEventPtr)ev;
 }
 
-virDomainEventPtr virDomainEventWatchdogNewFromDom(virDomainPtr dom,
-   int action)
+virDomainEventPtr virDomainEventWatchdogNewFromDom(virDomainPtr dom, int 
action)
 {
-virDomainEventPtr ev;
+virDomainEventWatchdogPtr ev;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNew(virDomainEventClass,
+if (!(ev = virDomainEventNew(virDomainEventWatchdogClass,
  VIR_DOMAIN_EVENT_ID_WATCHDOG,
  dom->id, dom->name, dom->uuid)))
 return NULL;
 
-ev->data.watchdog.action = action;
+ev->action = action;
 
-return ev;
+return (virDomainEventPtr)ev;
 }
-virDomainEventPtr virDomainEventWatchdogNewFromObj(virDomainObjPtr obj,
-   int action)
+virDomainEventPtr virDomainEventWatchdogNewFromObj(virDomainObjPtr obj, int 
action)
 {
-virDomainEventPtr ev;
+virDomainEventWatchdogPtr ev;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNew(virDomainEventClass,
+if (!(ev = virDomainEventNew(virDomainEventWatchdogClass,
  VIR_DOMAIN_EVENT_ID_WATCHDOG,
  obj->def->id, obj->def->name,
  obj->def->uuid)))
 return NULL;
 
-ev->data.watchdog.action = action;
+ev->action = action;
 
-return ev;
+return (virDomainEventPtr)ev;
 }
 
 static virDomainEventPtr virDomainEventIOErrorNewFromDomImpl(int event,
@@ -1526,10 +1543,15 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
 }
 
 case VIR_DOMAIN_EVENT_ID_WATCHDOG:
-((virConnectDomainEventWatchdogCallback)cb)(conn, dom,
-
event->data.watchdog.action,
-cbopaque);
-goto cleanup;
+{
+virDomainEventWatchdogPtr watchdogEvent;
+
+watchdogEvent = (virDomainEventWatchdogPtr)event;
+((virConnectDomainEventWatchdogCallback)cb)(conn, dom,
+watchdogEvent->action,
+cbopa

[libvirt] [v3 06/32] Renamed virDomainEventCallbackList* to virObjectEventCallbackList*

2013-12-02 Thread Cédric Bosdonnat
Keep the legacy Domain lifecycle event functions as is.
---
 src/conf/domain_event.c | 94 -
 src/conf/domain_event.h |  3 --
 2 files changed, 53 insertions(+), 44 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 5389aef..8442db5 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -43,11 +43,13 @@ typedef virObjectMeta *virObjectMetaPtr;
 typedef struct _virObjectEventQueue virObjectEventQueue;
 typedef virObjectEventQueue *virObjectEventQueuePtr;
 
-struct _virDomainEventCallbackList {
+struct _virObjectEventCallbackList {
 unsigned int nextID;
 unsigned int count;
 virObjectEventCallbackPtr *callbacks;
 };
+typedef struct _virObjectEventCallbackList virObjectEventCallbackList;
+typedef virObjectEventCallbackList *virObjectEventCallbackListPtr;
 
 struct _virObjectEventQueue {
 unsigned int count;
@@ -56,7 +58,7 @@ struct _virObjectEventQueue {
 
 struct _virObjectEventState {
 /* The list of domain event callbacks */
-virDomainEventCallbackListPtr callbacks;
+virObjectEventCallbackListPtr callbacks;
 /* The queue of object events */
 virObjectEventQueuePtr queue;
 /* Timer for flushing events queue */
@@ -132,13 +134,13 @@ struct _virDomainEvent {
 };
 
 /**
- * virDomainEventCallbackListFree:
+ * virObjectEventCallbackListFree:
  * @list: event callback list head
  *
  * Free the memory in the domain event callback list
  */
 static void
-virDomainEventCallbackListFree(virDomainEventCallbackListPtr list)
+virObjectEventCallbackListFree(virObjectEventCallbackListPtr list)
 {
 size_t i;
 if (!list)
@@ -161,11 +163,11 @@ 
virDomainEventCallbackListFree(virDomainEventCallbackListPtr list)
  * @cbList: the list
  * @callback: the callback to remove
  *
- * Internal function to remove a callback from a virDomainEventCallbackListPtr
+ * Internal function to remove a callback from a virObjectEventCallbackListPtr
  */
 static int
 virDomainEventCallbackListRemove(virConnectPtr conn,
- virDomainEventCallbackListPtr cbList,
+ virObjectEventCallbackListPtr cbList,
  virConnectDomainEventCallback callback)
 {
 int ret = 0;
@@ -207,16 +209,16 @@ virDomainEventCallbackListRemove(virConnectPtr conn,
 
 
 /**
- * virDomainEventCallbackListRemoveID:
+ * virObjectEventCallbackListRemoveID:
  * @conn: pointer to the connection
  * @cbList: the list
  * @callback: the callback to remove
  *
- * Internal function to remove a callback from a virDomainEventCallbackListPtr
+ * Internal function to remove a callback from a virObjectEventCallbackListPtr
  */
 static int
-virDomainEventCallbackListRemoveID(virConnectPtr conn,
-   virDomainEventCallbackListPtr cbList,
+virObjectEventCallbackListRemoveID(virConnectPtr conn,
+   virObjectEventCallbackListPtr cbList,
int callbackID)
 {
 int ret = 0;
@@ -258,7 +260,7 @@ virDomainEventCallbackListRemoveID(virConnectPtr conn,
 
 static int
 virDomainEventCallbackListMarkDelete(virConnectPtr conn,
- virDomainEventCallbackListPtr cbList,
+ virObjectEventCallbackListPtr cbList,
  virConnectDomainEventCallback callback)
 {
 int ret = 0;
@@ -283,8 +285,8 @@ virDomainEventCallbackListMarkDelete(virConnectPtr conn,
 
 
 static int
-virDomainEventCallbackListMarkDeleteID(virConnectPtr conn,
-   virDomainEventCallbackListPtr cbList,
+virObjectEventCallbackListMarkDeleteID(virConnectPtr conn,
+   virObjectEventCallbackListPtr cbList,
int callbackID)
 {
 int ret = 0;
@@ -308,7 +310,7 @@ virDomainEventCallbackListMarkDeleteID(virConnectPtr conn,
 
 
 static int
-virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList)
+virObjectEventCallbackListPurgeMarked(virObjectEventCallbackListPtr cbList)
 {
 int old_count = cbList->count;
 int n;
@@ -338,20 +340,25 @@ 
virDomainEventCallbackListPurgeMarked(virDomainEventCallbackListPtr cbList)
 
 
 /**
- * virDomainEventCallbackListAddID:
+ * virObjectEventCallbackListAddID:
  * @conn: pointer to the connection
  * @cbList: the list
+ * @uuid: the uuid of the object to filter on
+ * @name: the name of the object to filter on
+ * @id: the ID of the object to filter on
  * @eventID: the event ID
  * @callback: the callback to add
  * @opaque: opaque data tio pass to callback
  * @callbackID: filled with callback ID
  *
- * Internal function to add a callback from a virDomainEventCallbackListPtr
+ * Internal function to add a callback from a virObjectEventCallbackListPtr
  */
 static int
-virDomainEventCallbackListAddID(virConnectPtr conn,
-   

[libvirt] [v3 03/32] Renamed virDomainMeta to virObjectMeta

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 46 +++---
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index fd68820..3bfe1e0 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -32,13 +32,13 @@
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
-struct _virDomainMeta {
+struct _virObjectMeta {
 int id;
 char *name;
 unsigned char uuid[VIR_UUID_BUFLEN];
 };
-typedef struct _virDomainMeta virDomainMeta;
-typedef virDomainMeta *virDomainMetaPtr;
+typedef struct _virObjectMeta virObjectMeta;
+typedef virObjectMeta *virObjectMetaPtr;
 
 struct _virDomainEventCallbackList {
 unsigned int nextID;
@@ -67,7 +67,7 @@ struct _virObjectEventCallback {
 int callbackID;
 int eventID;
 virConnectPtr conn;
-virDomainMetaPtr dom;
+virObjectMetaPtr meta;
 virConnectDomainEventGenericCallback cb;
 void *opaque;
 virFreeCallback freecb;
@@ -77,7 +77,7 @@ struct _virObjectEventCallback {
 struct _virDomainEvent {
 int eventID;
 
-virDomainMeta dom;
+virObjectMeta meta;
 
 union {
 struct {
@@ -369,10 +369,10 @@ virDomainEventCallbackListAddID(virConnectPtr conn,
 if (cbList->callbacks[i]->cb == VIR_DOMAIN_EVENT_CALLBACK(callback) &&
 cbList->callbacks[i]->eventID == eventID &&
 cbList->callbacks[i]->conn == conn &&
-((dom && cbList->callbacks[i]->dom &&
-  memcmp(cbList->callbacks[i]->dom->uuid,
+((dom && cbList->callbacks[i]->meta &&
+  memcmp(cbList->callbacks[i]->meta->uuid,
  dom->uuid, VIR_UUID_BUFLEN) == 0) ||
- (!dom && !cbList->callbacks[i]->dom))) {
+ (!dom && !cbList->callbacks[i]->meta))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("event callback already tracked"));
 return -1;
@@ -388,12 +388,12 @@ virDomainEventCallbackListAddID(virConnectPtr conn,
 event->freecb = freecb;
 
 if (dom) {
-if (VIR_ALLOC(event->dom) < 0)
+if (VIR_ALLOC(event->meta) < 0)
 goto error;
-if (VIR_STRDUP(event->dom->name, dom->name) < 0)
+if (VIR_STRDUP(event->meta->name, dom->name) < 0)
 goto error;
-memcpy(event->dom->uuid, dom->uuid, VIR_UUID_BUFLEN);
-event->dom->id = dom->id;
+memcpy(event->meta->uuid, dom->uuid, VIR_UUID_BUFLEN);
+event->meta->id = dom->id;
 }
 
 /* Make space on list */
@@ -421,9 +421,9 @@ virDomainEventCallbackListAddID(virConnectPtr conn,
 
 error:
 if (event) {
-if (event->dom)
-VIR_FREE(event->dom->name);
-VIR_FREE(event->dom);
+if (event->meta)
+VIR_FREE(event->meta->name);
+VIR_FREE(event->meta);
 }
 VIR_FREE(event);
 return -1;
@@ -526,7 +526,7 @@ void virDomainEventFree(virDomainEventPtr event)
 break;
 }
 
-VIR_FREE(event->dom.name);
+VIR_FREE(event->meta.name);
 VIR_FREE(event);
 }
 
@@ -664,12 +664,12 @@ static virDomainEventPtr virDomainEventNewInternal(int 
eventID,
 return NULL;
 
 event->eventID = eventID;
-if (VIR_STRDUP(event->dom.name, name) < 0) {
+if (VIR_STRDUP(event->meta.name, name) < 0) {
 VIR_FREE(event);
 return NULL;
 }
-event->dom.id = id;
-memcpy(event->dom.uuid, uuid, VIR_UUID_BUFLEN);
+event->meta.id = id;
+memcpy(event->meta.uuid, uuid, VIR_UUID_BUFLEN);
 
 return event;
 }
@@ -1244,10 +1244,10 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
   void *cbopaque,
   void *opaque ATTRIBUTE_UNUSED)
 {
-virDomainPtr dom = virGetDomain(conn, event->dom.name, event->dom.uuid);
+virDomainPtr dom = virGetDomain(conn, event->meta.name, event->meta.uuid);
 if (!dom)
 return;
-dom->id = event->dom.id;
+dom->id = event->meta.id;
 
 switch ((virDomainEventID) event->eventID) {
 case VIR_DOMAIN_EVENT_ID_LIFECYCLE:
@@ -1375,14 +1375,14 @@ static int 
virDomainEventDispatchMatchCallback(virDomainEventPtr event,
 if (cb->eventID != event->eventID)
 return 0;
 
-if (cb->dom) {
+if (cb->meta) {
 /* Deliberately ignoring 'id' for matching, since that
  * will cause problems when a domain switches between
  * running & shutoff states & ignoring 'name' since
  * Xen sometimes renames guests during migration, thus
  * leaving 'uuid' as the only truly reliable ID we can use*/
 
-if (memcmp(event->dom.uuid, cb->dom->uuid, VIR_UUID_BUFLEN) == 0)
+if (memcmp(event->meta.uuid, cb->meta->uuid, VIR_UUID_BUFLEN) == 0)
 return 1;
 
 return 0;
-- 
1.8.4.4

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


[libvirt] [v3 17/32] Create virDomainEventDiskChange

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 87 +++--
 1 file changed, 56 insertions(+), 31 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 91bdbae..49b87dd 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -91,6 +91,8 @@ static virClassPtr virDomainEventWatchdogClass;
 static virClassPtr virDomainEventIOErrorClass;
 static virClassPtr virDomainEventGraphicsClass;
 static virClassPtr virDomainEventBlockJobClass;
+static virClassPtr virDomainEventDiskChangeClass;
+
 static void virObjectEventDispose(void *obj);
 static void virDomainEventDispose(void *obj);
 static void virDomainEventLifecycleDispose(void *obj);
@@ -99,6 +101,7 @@ static void virDomainEventWatchdogDispose(void *obj);
 static void virDomainEventIOErrorDispose(void *obj);
 static void virDomainEventGraphicsDispose(void *obj);
 static void virDomainEventBlockJobDispose(void *obj);
+static void virDomainEventDiskChangeDispose(void *obj);
 
 struct _virObjectEvent {
 virObject parent;
@@ -112,12 +115,6 @@ struct _virDomainEvent {
 
 union {
 struct {
-char *oldSrcPath;
-char *newSrcPath;
-char *devAlias;
-int reason;
-} diskChange;
-struct {
 char *devAlias;
 int reason;
 } trayChange;
@@ -189,6 +186,18 @@ struct _virDomainEventGraphics {
 typedef struct _virDomainEventGraphics virDomainEventGraphics;
 typedef virDomainEventGraphics *virDomainEventGraphicsPtr;
 
+struct _virDomainEventDiskChange {
+virDomainEvent parent;
+
+char *oldSrcPath;
+char *newSrcPath;
+char *devAlias;
+int reason;
+};
+typedef struct _virDomainEventDiskChange virDomainEventDiskChange;
+typedef virDomainEventDiskChange *virDomainEventDiskChangePtr;
+
+
 static int virObjectEventOnceInit(void)
 {
 if (!(virObjectEventClass = virClassNew(virClassForObject(),
@@ -237,6 +246,12 @@ static int virObjectEventOnceInit(void)
  sizeof(virDomainEventBlockJob),
  virDomainEventBlockJobDispose)))
 return -1;
+if (!(virDomainEventDiskChangeClass = virClassNew(
+ virDomainEventClass,
+ "virDomainEventDiskChange",
+ sizeof(virDomainEventDiskChange),
+ virDomainEventDiskChangeDispose)))
+return -1;
 return 0;
 }
 
@@ -269,11 +284,6 @@ static void virDomainEventDispose(void *obj)
 
 switch (virObjectEventGetEventID(event)) {
 
-case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
-VIR_FREE(event->data.diskChange.oldSrcPath);
-VIR_FREE(event->data.diskChange.newSrcPath);
-VIR_FREE(event->data.diskChange.devAlias);
-break;
 case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
 VIR_FREE(event->data.trayChange.devAlias);
 break;
@@ -347,6 +357,16 @@ static void virDomainEventBlockJobDispose(void *obj)
 VIR_FREE(event->path);
 }
 
+static void virDomainEventDiskChangeDispose(void *obj)
+{
+virDomainEventDiskChangePtr event = obj;
+VIR_DEBUG("obj=%p", event);
+
+VIR_FREE(event->oldSrcPath);
+VIR_FREE(event->newSrcPath);
+VIR_FREE(event->devAlias);
+}
+
 /**
  * virObjectEventCallbackListFree:
  * @list: event callback list head
@@ -1247,35 +1267,35 @@ virDomainEventPtr 
virDomainEventControlErrorNewFromObj(virDomainObjPtr obj)
 return ev;
 }
 
-static virDomainEventPtr
-virDomainEventDiskChangeNew(int id, const char *name,
-unsigned char *uuid,
-const char *oldSrcPath,
-const char *newSrcPath,
-const char *devAlias, int reason)
+static
+virDomainEventPtr virDomainEventDiskChangeNew(int id, const char *name,
+  unsigned char *uuid,
+  const char *oldSrcPath,
+  const char *newSrcPath,
+  const char *devAlias, int reason)
 {
-virDomainEventPtr ev;
+virDomainEventDiskChangePtr ev;
 
 if (virObjectEventInitialize() < 0)
 return NULL;
 
-if (!(ev = virDomainEventNew(virDomainEventClass,
+if (!(ev = virDomainEventNew(virDomainEventDiskChangeClass,
  VIR_DOMAIN_EVENT_ID_DISK_CHANGE,
  id, name, uuid)))
 return NULL;
 
-if (VIR_STRDUP(ev->data.diskChange.devAlias, devAlias) < 0)
+if (VIR_STRDUP(ev->devAlias, devAlias) < 0)
 goto error;
 
-if (VIR_STRDUP(ev->data.diskChange.oldSrcPath, oldSrcPath) < 0)
+if (VIR_STRDUP(ev->oldSrcPath, oldSrcPath) < 0)
 goto error;
 
-if (VIR_STRDUP(ev->data.diskChange.newSrcPath, newSrcPath) < 0)
+ 

[libvirt] [v3 22/32] Add object event namespaces for the event IDs

2013-12-02 Thread Cédric Bosdonnat
Each unique event ID will thus be composed by 1 byte for the namespace
and 1 byte for a namespace-specific ID. The namespace for domain event
needs to be 0 for compatibility reasons.
---
 src/conf/domain_event.c | 10 --
 src/conf/domain_event.h |  8 
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 3c14cec..8462754 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -1910,11 +1910,17 @@ virObjectEventStateDispatchFunc(virConnectPtr conn,
 void *opaque)
 {
 virObjectEventStatePtr state = opaque;
+virEventNamespaceID namespace = (event->eventID & 0xFF00) >> 8;
 
 /* Drop the lock whle dispatching, for sake of re-entrancy */
 virObjectEventStateUnlock(state);
-virDomainEventDispatchDefaultFunc(conn, event,
-VIR_DOMAIN_EVENT_CALLBACK(cb), cbopaque, NULL);
+switch (namespace)
+{
+case VIR_EVENT_NAMESPACE_DOMAIN:
+virDomainEventDispatchDefaultFunc(conn, event,
+VIR_DOMAIN_EVENT_CALLBACK(cb), cbopaque, NULL);
+break;
+}
 virObjectEventStateLock(state);
 }
 
diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h
index 647b7e4..ec1b3d6 100644
--- a/src/conf/domain_event.h
+++ b/src/conf/domain_event.h
@@ -28,6 +28,14 @@
 
 # include "domain_conf.h"
 
+
+/** Event IDs are computed in the following way:
+virEventNamespaceID << 8 + vir*EventId
+  */
+typedef enum {
+VIR_EVENT_NAMESPACE_DOMAIN = 0, /* 0 to keep value of virDomainEventId 
unchanged */
+} virEventNamespaceID;
+
 typedef struct _virObjectEventCallback virObjectEventCallback;
 typedef virObjectEventCallback *virObjectEventCallbackPtr;
 
-- 
1.8.4.4

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


[libvirt] [v3 02/32] Rename virDomainEventCallback to virObjectEventCallback

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 8 
 src/conf/domain_event.h | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 19e3920..fd68820 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -43,7 +43,7 @@ typedef virDomainMeta *virDomainMetaPtr;
 struct _virDomainEventCallbackList {
 unsigned int nextID;
 unsigned int count;
-virDomainEventCallbackPtr *callbacks;
+virObjectEventCallbackPtr *callbacks;
 };
 
 struct _virDomainEventQueue {
@@ -63,7 +63,7 @@ struct _virDomainEventState {
 virMutex lock;
 };
 
-struct _virDomainEventCallback {
+struct _virObjectEventCallback {
 int callbackID;
 int eventID;
 virConnectPtr conn;
@@ -355,7 +355,7 @@ virDomainEventCallbackListAddID(virConnectPtr conn,
 virFreeCallback freecb,
 int *callbackID)
 {
-virDomainEventCallbackPtr event;
+virObjectEventCallbackPtr event;
 size_t i;
 int ret = 0;
 
@@ -1366,7 +1366,7 @@ cleanup:
 
 
 static int virDomainEventDispatchMatchCallback(virDomainEventPtr event,
-   virDomainEventCallbackPtr cb)
+   virObjectEventCallbackPtr cb)
 {
 if (!cb)
 return 0;
diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h
index f6b957d..07b14c4 100644
--- a/src/conf/domain_event.h
+++ b/src/conf/domain_event.h
@@ -28,8 +28,8 @@
 
 # include "domain_conf.h"
 
-typedef struct _virDomainEventCallback virDomainEventCallback;
-typedef virDomainEventCallback *virDomainEventCallbackPtr;
+typedef struct _virObjectEventCallback virObjectEventCallback;
+typedef virObjectEventCallback *virObjectEventCallbackPtr;
 
 typedef struct _virDomainEventCallbackList virDomainEventCallbackList;
 typedef virDomainEventCallbackList *virDomainEventCallbackListPtr;
-- 
1.8.4.4

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


[libvirt] [v3 04/32] Renamed virDomainEventQueue to virObjectEventQueue

2013-12-02 Thread Cédric Bosdonnat
---
 src/conf/domain_event.c | 49 ++---
 src/conf/domain_event.h |  3 ---
 2 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 3bfe1e0..ee19142 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -40,13 +40,16 @@ struct _virObjectMeta {
 typedef struct _virObjectMeta virObjectMeta;
 typedef virObjectMeta *virObjectMetaPtr;
 
+typedef struct _virObjectEventQueue virObjectEventQueue;
+typedef virObjectEventQueue *virObjectEventQueuePtr;
+
 struct _virDomainEventCallbackList {
 unsigned int nextID;
 unsigned int count;
 virObjectEventCallbackPtr *callbacks;
 };
 
-struct _virDomainEventQueue {
+struct _virObjectEventQueue {
 unsigned int count;
 virDomainEventPtr *events;
 };
@@ -54,8 +57,8 @@ struct _virDomainEventQueue {
 struct _virDomainEventState {
 /* The list of domain event callbacks */
 virDomainEventCallbackListPtr callbacks;
-/* The queue of domain events */
-virDomainEventQueuePtr queue;
+/* The queue of object events */
+virObjectEventQueuePtr queue;
 /* Timer for flushing events queue */
 int timer;
 /* Flag if we're in process of dispatching */
@@ -531,13 +534,13 @@ void virDomainEventFree(virDomainEventPtr event)
 }
 
 /**
- * virDomainEventQueueClear:
+ * virObjectEventQueueClear:
  * @queue: pointer to the queue
  *
  * Removes all elements from the queue
  */
 static void
-virDomainEventQueueClear(virDomainEventQueuePtr queue)
+virObjectEventQueueClear(virObjectEventQueuePtr queue)
 {
 size_t i;
 if (!queue)
@@ -551,25 +554,25 @@ virDomainEventQueueClear(virDomainEventQueuePtr queue)
 }
 
 /**
- * virDomainEventQueueFree:
+ * virObjectEventQueueFree:
  * @queue: pointer to the queue
  *
  * Free the memory in the queue. We process this like a list here
  */
 static void
-virDomainEventQueueFree(virDomainEventQueuePtr queue)
+virObjectEventQueueFree(virObjectEventQueuePtr queue)
 {
 if (!queue)
 return;
 
-virDomainEventQueueClear(queue);
+virObjectEventQueueClear(queue);
 VIR_FREE(queue);
 }
 
-static virDomainEventQueuePtr
-virDomainEventQueueNew(void)
+static virObjectEventQueuePtr
+virObjectEventQueueNew(void)
 {
-virDomainEventQueuePtr ret;
+virObjectEventQueuePtr ret;
 
 ignore_value(VIR_ALLOC(ret));
 return ret;
@@ -600,7 +603,7 @@ virDomainEventStateFree(virDomainEventStatePtr state)
 return;
 
 virDomainEventCallbackListFree(state->callbacks);
-virDomainEventQueueFree(state->queue);
+virObjectEventQueueFree(state->queue);
 
 if (state->timer != -1)
 virEventRemoveTimeout(state->timer);
@@ -641,7 +644,7 @@ virDomainEventStateNew(void)
 if (VIR_ALLOC(state->callbacks) < 0)
 goto error;
 
-if (!(state->queue = virDomainEventQueueNew()))
+if (!(state->queue = virObjectEventQueueNew()))
 goto error;
 
 state->timer = -1;
@@ -1203,16 +1206,16 @@ virDomainEventDeviceRemovedNewFromDom(virDomainPtr dom,
 }
 
 /**
- * virDomainEventQueuePush:
- * @evtQueue: the dom event queue
+ * virObjectEventQueuePush:
+ * @evtQueue: the object event queue
  * @event: the event to add
  *
- * Internal function to push to the back of a virDomainEventQueue
+ * Internal function to push to the back of a virObjectEventQueue
  *
  * Returns: 0 on success, -1 on failure
  */
 static int
-virDomainEventQueuePush(virDomainEventQueuePtr evtQueue,
+virObjectEventQueuePush(virObjectEventQueuePtr evtQueue,
 virDomainEventPtr event)
 {
 if (!evtQueue) {
@@ -1418,7 +1421,7 @@ virDomainEventDispatch(virDomainEventPtr event,
 
 
 static void
-virDomainEventQueueDispatch(virDomainEventQueuePtr queue,
+virObjectEventQueueDispatch(virObjectEventQueuePtr queue,
 virDomainEventCallbackListPtr callbacks,
 virDomainEventDispatchFunc dispatch,
 void *opaque)
@@ -1444,7 +1447,7 @@ virDomainEventStateQueue(virDomainEventStatePtr state,
 
 virDomainEventStateLock(state);
 
-if (virDomainEventQueuePush(state->queue, event) < 0) {
+if (virObjectEventQueuePush(state->queue, event) < 0) {
 VIR_DEBUG("Error adding event to queue");
 virDomainEventFree(event);
 }
@@ -1474,7 +1477,7 @@ virDomainEventStateDispatchFunc(virConnectPtr conn,
 static void
 virDomainEventStateFlush(virDomainEventStatePtr state)
 {
-virDomainEventQueue tempQueue;
+virObjectEventQueue tempQueue;
 
 virDomainEventStateLock(state);
 state->isDispatching = true;
@@ -1487,7 +1490,7 @@ virDomainEventStateFlush(virDomainEventStatePtr state)
 state->queue->events = NULL;
 virEventUpdateTimeout(state->timer, -1);
 
-virDomainEventQueueDispatch(&tempQueue,
+virObjectEventQueueDispatch(&tempQueue,
 state->callbacks,
 virDomainEventStateDispatchFu

[libvirt] clone "img" on iscsi storage

2013-12-02 Thread Jason
Hi:
   I need to clone a vm, the source is "vm1.img",i need to clone the "vm1.img" 
to a iscsi storage volume, it's said that i can't create volume on a iscsi. 
   I use  virStorageVolCreateXMLFrom to do this, can you do me a favor? thank 
you.
 the virt-manager can clone the "vm1.img" to overwrite the iscsi "lun",what can 
i do to do the same thing, i do not understand the python.--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCHv3] qemu: Refactor qemuTranslateDiskSourcePool

2013-12-02 Thread Peter Krempa
Before this patch, the translation function still needs a second ugly
helper function to actually format the command line for qemu. But if we
do the right stuff in the translation function, we don't have to bother
with the second function any more.

This patch removes the messy qemuBuildVolumeString function and changes
qemuTranslateDiskSourcePool to set stuff up correctly so that the
regular code paths meant for volumes can be used to format the command
line correctly.

For this purpose a new helper "qemuDiskGetActualType()" is introduced to
return the type of the volume in a pool.

As a part of the refactor the qemuTranslateDiskSourcePool function is
fixed to do decisions based on the pool type instead of the volume type.
This allows to separate pool-type-specific stuff more clearly and will
ease addition of other pool types that will require certain other
operations to get the correct pool source.

The previously fixed tests should make sure that we don't break stuff
that was working before.
---

Notes:
Version 3:
- fixed commit message typos
- the tray status error message now states if it's a disk or a volume
- returned startup policy checking

Version 2:
- Fixed accidental squash into the previous commit

 src/conf/domain_conf.h   |   1 +
 src/libvirt_private.syms |   1 +
 src/qemu/qemu_command.c  |  81 
 src/qemu/qemu_conf.c | 136 ++-
 src/qemu/qemu_conf.h |   2 +
 5 files changed, 112 insertions(+), 109 deletions(-)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 5afbfa7..4934911 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -686,6 +686,7 @@ struct _virDomainDiskSourcePoolDef {
 char *volume; /* volume name */
 int voltype; /* enum virStorageVolType, internal only */
 int pooltype; /* enum virStoragePoolType, internal only */
+int actualtype; /* enum virDomainDiskType, internal only */
 int mode; /* enum virDomainDiskSourcePoolMode */
 };
 typedef virDomainDiskSourcePoolDef *virDomainDiskSourcePoolDefPtr;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3a8cbe5..b2c7a8e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -696,6 +696,7 @@ virStoragePoolSourceFree;
 virStoragePoolSourceListFormat;
 virStoragePoolSourceListNewSource;
 virStoragePoolTypeFromString;
+virStoragePoolTypeToString;
 virStorageVolDefFindByKey;
 virStorageVolDefFindByName;
 virStorageVolDefFindByPath;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 763417f..d5c9c09 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3775,69 +3775,6 @@ qemuBuildNBDString(virConnectPtr conn, 
virDomainDiskDefPtr disk, virBufferPtr op
 return 0;
 }

-static int
-qemuBuildVolumeString(virConnectPtr conn,
-  virDomainDiskDefPtr disk,
-  virBufferPtr opt)
-{
-int ret = -1;
-
-switch ((virStorageVolType) disk->srcpool->voltype) {
-case VIR_STORAGE_VOL_DIR:
-if (!disk->readonly) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("cannot create virtual FAT disks in read-write 
mode"));
-goto cleanup;
-}
-if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
-virBufferEscape(opt, ',', ",", "file=fat:floppy:%s,", disk->src);
-else
-virBufferEscape(opt, ',', ",", "file=fat:%s,", disk->src);
-break;
-case VIR_STORAGE_VOL_BLOCK:
-if (disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN) {
-virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-   _("tray status 'open' is invalid for "
- "block type volume"));
-goto cleanup;
-}
-if (disk->srcpool->pooltype == VIR_STORAGE_POOL_ISCSI) {
-if (disk->srcpool->mode ==
-VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT) {
-if (qemuBuildISCSIString(conn, disk, opt) < 0)
-goto cleanup;
-virBufferAddChar(opt, ',');
-} else if (disk->srcpool->mode ==
-   VIR_DOMAIN_DISK_SOURCE_POOL_MODE_HOST) {
-virBufferEscape(opt, ',', ",", "file=%s,", disk->src);
-}
-} else {
-virBufferEscape(opt, ',', ",", "file=%s,", disk->src);
-}
-break;
-case VIR_STORAGE_VOL_FILE:
-if (disk->auth.username) {
-if (qemuBuildISCSIString(conn, disk, opt) < 0)
-goto cleanup;
-virBufferAddChar(opt, ',');
-} else {
-virBufferEscape(opt, ',', ",", "file=%s,", disk->src);
-}
-break;
-case VIR_STORAGE_VOL_NETWORK:
-case VIR_STORAGE_VOL_NETDIR:
-case VIR_STORAGE_VOL_LAST:
-/* Keep the compiler quiet, qemuTranslateDiskSourcePool already
- * reported the unsupported error.
-  

Re: [libvirt] [question] We can create two network of one same linux bridge or local ethernet. It is a bug?

2013-12-02 Thread Laine Stump
On 12/02/2013 11:52 AM, Daniel P. Berrange wrote:
> On Sat, Nov 30, 2013 at 07:30:03PM +0800, Sheldon wrote:
>>> We can create two network of one same linux bridge or local ethernet:
>> This is not harmful.
>> But I wonder should this case is allowed?  Why?
> It should probably be rejected as invalid.


In the end, these "unmanaged" (by libvirt) networks are just describing
where to connect the guests to, providing a persistent name for a
particular network connection so that the underlying network
implementation can change without needing to modify the guest config;
they aren't doing anything to change the configuration of the bridge
they point to, or any firewall rules or dhcp/dns server related to it.
So allowing multiple networks to point to the same bridge doesn't create
any bad situations, and I can actually think of a place where it would
be useful.

Let's say you have defined two networks, "engineering" and "sales" that
are currently connected to the same network due to limitations in your
physical network - simple enough, just define two networks that both
point to the same bridge device. Then one day you get around to setting
up a 2nd physical network and plugging your host into it - just change
the definition of one of the networks to the new bridge and restart the
guests (someday it would be nice if virNetworkUpdateFlags() could handle
changing the bridge device of a network without restarting it).

This same situation can't be handled with portgroups on a single
network, though.

>>> virsh # net-list --all
>>> Name State Autostart Persistent
>>> --
>>> br1 active yes yes
>>> br2 active yes yes
>>> default active yes yes
>>>
>>> virsh # net-dumpxml br1
>>> 
>>> br1
>>> d5410814-1bea-b10d-04b8-9fbd3a1cfc65
>>> 
>>> 
>>> 
>>>
>>> virsh # net-dumpxml br2
>>> 
>>> br2
>>> 99f20705-57cd-da31-f193-d13af4158792
>>> 
>>> 
>>> 
>>>
>>> virsh # net-list --all
>>> Name State Autostart Persistent
>>> --
>>> br0 active yes yes
>>> br1 active yes yes
>>> default active yes yes
>>>
>>> virsh # net-dumpxml br0
>>> 
>>> br0
>>> a35c840a-9bdc-070d-43f5-8e834040aa42
>>> 
>>> 
>>> 
>>> 
>>>
>>> virsh # net-dumpxml br1
>>> 
>>> br1
>>> f1c87b80-2dfc-2a71-3fb6-56ef83daf29a
>>> 
>>> 
>>> 
>>> 

This case is also harmless, since bridge mode of macvtap allows multiple
connections to the same device. It is true, though, that when forward
mode='passthrough', there would be problems if two networks tried to use
the same physical device at the same time. However I think that the
proper solution to that problem isn't to disallow listing of the same
physdevs in multiple networks, but instead to keep a *global* (to
libvirt) in-use count for all physdevs. In this way, the same pool of
SRIOV VFs could be provided for multiple networks (e.g., a
mode='passthrough *and* a mode='hostdev' network) and those networks
could all safely share from that pool.

(An example of the usefulness of this would be the case where you had
some guests that required the extra bit of performance required by PCI
passthrough of a physical device, and some guests could get by okay with
macvtap in passthrough mode (and maybe still others could live with
macvtap in one of it's shared modes).

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


Re: [libvirt] [PATCH v3] Pin guest to memory node on NUMA system

2013-12-02 Thread Martin Kletzander
On Tue, Nov 26, 2013 at 07:59:31PM +0530, Shivaprasad G Bhat wrote:
> Version 3:
> Addressed comments on V2.
> 
> Version 2:
> Fixed the string formatting errors in v1.
> 
> The patch contains the fix for defect 1009880 reported at redhat bugzilla.
> The root cause is, ever since the subcpusets(vcpu,emulator) were introduced, 
> the
> parent cpuset cannot be modified to remove the nodes that are in use by the
> subcpusets.
> The fix is to break the memory node modification into three steps as to assign
> new nodes into the parent first. Change the nodes in the child nodes. Then
> remove the old nodes on the parent node.
> 
> Signed-off-by: Shivaprasad G Bhat 
> ---
>  src/qemu/qemu_driver.c |  115 
> ++--
>  1 file changed, 110 insertions(+), 5 deletions(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 8a1eefd..4bc9d1d 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -8132,6 +8132,47 @@ cleanup:
>  }
>  
>  static int
> +qemuSetVcpuCpusetMems(virDomainObjPtr vm,
> +  char *nodeset_str)
> +{
> +size_t j = 0;
> +qemuDomainObjPrivatePtr priv = vm->privateData;
> +virCgroupPtr cgroup_vcpu = NULL;
> +
> +for (j = 0; j < priv->nvcpupids; j++) {
> +if (virCgroupNewVcpu(priv->cgroup, j, false, &cgroup_vcpu) < 0) {
> +return -1;
> +}
> +if (virCgroupSetCpusetMems(cgroup_vcpu, nodeset_str) < 0) {
> +virCgroupFree(&cgroup_vcpu);
> +return -1;
> +}
> +virCgroupFree(&cgroup_vcpu);
> +}
> +
> +return 0;
> +}
> +
> +static int
> +qemuSetEmulatorCpusetMems(virDomainObjPtr vm,
> +  char *nodeset_str)
> +{
> +qemuDomainObjPrivatePtr priv = vm->privateData;
> +virCgroupPtr cgroup_emulator = NULL;
> +
> +if (virCgroupNewEmulator(priv->cgroup, false, &cgroup_emulator) < 0) {
> +return -1;
> +}
> +if (virCgroupSetCpusetMems(cgroup_emulator, nodeset_str) < 0) {
> +virCgroupFree(&cgroup_emulator);
> +return -1;
> +}
> +virCgroupFree(&cgroup_emulator);
> +
> +return 0;
> +}
> +

I suggested to offload this to a different function just in case it is
used in more places than this one.  If it is not then it just adds
more code.

> +static int
>  qemuDomainSetNumaParameters(virDomainPtr dom,
>  virTypedParameterPtr params,
>  int nparams,
> @@ -8198,7 +8239,11 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
>  }
>  } else if (STREQ(param->field, VIR_DOMAIN_NUMA_NODESET)) {
>  virBitmapPtr nodeset = NULL;
> +virBitmapPtr old_nodeset = NULL;
> +virBitmapPtr temp_nodeset = NULL;
>  char *nodeset_str = NULL;
> +char *old_nodeset_str = NULL;
> +char *temp_nodeset_str = NULL;
>  
>  if (virBitmapParse(params[i].value.s,
> 0, &nodeset,
> @@ -8208,32 +8253,92 @@ qemuDomainSetNumaParameters(virDomainPtr dom,
>  }
>  
>  if (flags & VIR_DOMAIN_AFFECT_LIVE) {
> +size_t j;
> +
>  if (vm->def->numatune.memory.mode !=
>  VIR_DOMAIN_NUMATUNE_MEM_STRICT) {
>  virReportError(VIR_ERR_OPERATION_INVALID, "%s",
> _("change of nodeset for running domain "
>   "requires strict numa mode"));
> -virBitmapFree(nodeset);
>  ret = -1;
> -continue;
> +goto next;
>  }
>  
>  /* Ensure the cpuset string is formated before passing to 
> cgroup */
>  if (!(nodeset_str = virBitmapFormat(nodeset))) {
>  virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> _("Failed to format nodeset"));
> -virBitmapFree(nodeset);
>  ret = -1;
> -continue;
> +goto next;
> +}
> +
> +/*Get Exisitng nodeset values */
> +if (virCgroupGetCpusetMems(priv->cgroup, &old_nodeset_str) < 
> 0) {
> +ret = -1;
> +goto next;
> +}
> +if (virBitmapParse(old_nodeset_str, 0, &old_nodeset,
> +   VIR_DOMAIN_CPUMASK_LEN) < 0){
> +ret = -1;
> +goto next;
> +}
> +
> +/* Merge the existing and new nodeset values */
> +if ((temp_nodeset = virBitmapNewCopy(old_nodeset)) == NULL) {
> +ret = -1;
> +goto next;
> +}
> +
> +for (j = 0; j < caps->host.nnumaCell; j++) {
> +bool result;
> +  

Re: [libvirt] [PATCHv1.5 22/27] qemu: snapshot: Touch up error message

2013-12-02 Thread Peter Krempa
On 11/29/13 15:30, Laine Stump wrote:
> On 11/27/2013 01:14 PM, Michal Privoznik wrote:
>> On 26.11.2013 17:49, Peter Krempa wrote:
>>> ---
>>>  src/qemu/qemu_driver.c | 4 ++--
>>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
>>> index d2dbaf5..96bc87e 100644
>>> --- a/src/qemu/qemu_driver.c
>>> +++ b/src/qemu/qemu_driver.c
>>> @@ -11858,8 +11858,8 @@ qemuDomainSnapshotPrepare(virDomainObjPtr vm, 
>>> virDomainSnapshotDefPtr def,
>>>   * offline snapshots */
>>>  if (found_internal && external) {
>>>  virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
>>> -   _("mixing internal and external snapshots is not "
>>> - "supported yet"));
>>> +   _("mixing internal and external targets for a 
>>> snapshot "
>>> + "is not yet supported"));
>>>  goto cleanup;
>>>  }
>>>
>> I'm not a native speaker, but I remember being told in school that 'yet'
>> goes always at the end. So I'll leave this one for somebody else.
> 
> No, that usage is fine.

Thanks; Pushed.

Peter



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

Re: [libvirt] [PATCHv1.5 23/27] qemu: snapshot: Add functions similar to disk source pool translation

2013-12-02 Thread Peter Krempa
On 11/27/13 12:14, Michal Privoznik wrote:
> On 26.11.2013 17:49, Peter Krempa wrote:
>> To avoid future pain, add placeholder functions to get the actual
>> snapshot disk type.
>> ---
>>  src/qemu/qemu_conf.c | 23 +++
>>  src/qemu/qemu_conf.h |  6 ++
>>  2 files changed, 29 insertions(+)
>>

...

> 
> ACK

Thanks; Pushed.

Peter




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

Re: [libvirt] [PATCHv1.5 20/27] conf: Add helper do clear disk source authentication struct

2013-12-02 Thread Peter Krempa
On 11/27/13 12:15, Michal Privoznik wrote:
> On 26.11.2013 17:49, Peter Krempa wrote:
>> Add virDomainDiskAuthClear to help cleaning out the struct in other
>> places too.
>> ---
>>  src/conf/domain_conf.c   | 17 ++---
>>  src/conf/domain_conf.h   |  1 +
>>  src/libvirt_private.syms |  1 +
>>  3 files changed, 16 insertions(+), 3 deletions(-)
> 
> ACK

Thanks; Pushed.

Peter




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

Re: [libvirt] [PATCHv1.5 18/27] conf: Add functions to copy and free network disk source definitions

2013-12-02 Thread Peter Krempa
On 11/27/13 12:15, Michal Privoznik wrote:
> On 26.11.2013 17:49, Peter Krempa wrote:
>> To simplify operations on virDomainDiskHostDef arrays we will need deep
>> copy and freeing functions. Add and properly export them.
>> ---
>>  src/conf/domain_conf.c   | 55 
>> +---
>>  src/conf/domain_conf.h   |  3 +++
>>  src/libvirt_private.syms |  2 ++
>>  3 files changed, 57 insertions(+), 3 deletions(-)
>>
>>

...

> 
> ACK

Thanks; Pushed.

Peter




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

Re: [libvirt] [PATCHv1.5 17/27] snapshot: conf: Fix NULL dereference when element is empty

2013-12-02 Thread Peter Krempa
On 11/27/13 12:15, Michal Privoznik wrote:
> On 26.11.2013 17:48, Peter Krempa wrote:
>> Consider the following valid snapshot XML as the  element is
>> allowed to be empty in the domainsnapshot.rng schema:
>>
>> $ cat snap.xml
>> 
>>   
>> 
>>   
>>   
>> 
>>   
>> 
>>
>> produces the following error:
>>
>> $ virsh snapshot-create domain snap.xml
>> error: internal error: unknown disk snapshot driver '(null)'
>>
>> The driver type is parsed as NULL from the XML as the attribute is not
>> present and then directly used to produce the error message.
>>
>> With this patch the attempt to parse the driver type is skipped if not
>> present to avoid changing the schema to forbid the empty driver element.
>> ---
>>  src/conf/snapshot_conf.c | 16 +---
>>  1 file changed, 9 insertions(+), 7 deletions(-)
>>

...

>>
> 
> ACK and worth backporting on *-maint branches.

Thanks; Pushed. The backport won't be clean unless a few other patches
are backported, thus I will not do it until somebody will complain.

Peter





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

Re: [libvirt] [PATCHv1.5 16/27] snapshot: conf: Use common parsing and formatting functions for source

2013-12-02 Thread Peter Krempa
On 11/27/13 12:15, Michal Privoznik wrote:
> On 26.11.2013 17:48, Peter Krempa wrote:
>> Disk source elements for snapshots were using separate code from our
>> config parser. As snapshots can be stored on more than just regular
>> files, we will need the universal parser to allow us to expose a variety
>> of snapshot disk targets. This patch reuses the config parsers and
>> formatters to do the job.
>>
>> This initial support only changes the code without any visible XML
>> change.
>> ---
>>  src/conf/snapshot_conf.c | 70 
>> +---
>>  src/conf/snapshot_conf.h |  1 +
>>  2 files changed, 49 insertions(+), 22 deletions(-)
>>
>> diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
>> index 94a74d2..7258daa 100644
>> --- a/src/conf/snapshot_conf.c
>> +++ b/src/conf/snapshot_conf.c

...

>> @@ -584,6 +601,13 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
>>  if (disk->snapshot > 0)
>>  virBufferAsprintf(buf, " snapshot='%s'",
>>
>> virDomainSnapshotLocationTypeToString(disk->snapshot));
>> +
>> +if (type < 0)
>> +type = VIR_DOMAIN_DISK_TYPE_FILE;
>> +else
>> +virBufferAsprintf(buf, " type='%s'",
>> +  virDomainDiskTypeToString(type));
>> +
> 
> This is a very thin line between no XML change and outputting a new
> 'type' attribute into XML. Doesn't make much sense now, but I see this
> is to be changed in 25/27. Anyway, I think it would be better to save
> these small snippets up till then.

I got rid of the else section here until it will really be used.

> 
>>  if (!disk->file && disk->format == 0) {
>>  virBufferAddLit(buf, "/>\n");
>>  return;

...

>>
> 
> ACK to the rest.

Thanks; Pushed.

Peter





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

Re: [libvirt] [PATCHv1.5 15/27] conf: Export disk source formatter and parser

2013-12-02 Thread Peter Krempa
On 11/27/13 12:15, Michal Privoznik wrote:
> On 26.11.2013 17:48, Peter Krempa wrote:
>> This code will be reused in the snapshot disk definition parser.
>> ---
>>  src/conf/domain_conf.c |  4 ++--
>>  src/conf/domain_conf.h | 20 
>>  2 files changed, 22 insertions(+), 2 deletions(-)

...

> 
> ACK
> 
> Michal
> 

Thanks; Pushed.

Peter





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

Re: [libvirt] [PATCHv1.5 13/27] conf: Clean up virDomainDiskSourceDefFormatInternal

2013-12-02 Thread Peter Krempa
On 11/27/13 12:15, Michal Privoznik wrote:
> On 26.11.2013 17:48, Peter Krempa wrote:
>> Avoid if statements when used with virBufferEscapeString which
>> automaticaly omits the whole string. Also add some line breaks to
>> visualy separate the code.
>> ---
>>  src/conf/domain_conf.c | 48 
>>  1 file changed, 20 insertions(+), 28 deletions(-)
>>
> 
> ACK
> 
> Michal

Thanks; Pushed.

Peter




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

Re: [libvirt] [PATCHv1.5 14/27] conf: Split out seclabel formating code for disk source

2013-12-02 Thread Peter Krempa
On 11/27/13 12:15, Michal Privoznik wrote:
> On 26.11.2013 17:48, Peter Krempa wrote:
>> The code is common for all the various disk types. Split it out to a
>> common function.
>> ---
>>  src/conf/domain_conf.c | 62 
>> --
>>  1 file changed, 30 insertions(+), 32 deletions(-)
>>
> 
> ACK
> 
> Michal

Thanks; Pushed.

Peter





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

Re: [libvirt] [PATCHv1.5 12/27] conf: Support disk source formatting without needing a virDomainDiskDefPtr

2013-12-02 Thread Peter Krempa
On 11/27/13 12:15, Michal Privoznik wrote:
> On 26.11.2013 17:48, Peter Krempa wrote:
>> The  element formatting function was expecting a
>> virDomainDiskDefPtr to store the data. As snapshots are not using this
>> data structure to hold the data, we need to add an internal function
>> which splits out individual fields separately.
>> ---
>>  src/conf/domain_conf.c | 129 
>> ++---
>>  1 file changed, 78 insertions(+), 51 deletions(-)
> 
> ACK
> 
> Michal
> 

Thanks; Pushed.

Peter




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

[libvirt] [PATCH] qemu: fix lastError memory leak

2013-12-02 Thread Wangyufei (James)
When an error occurred in qemuMonitorIO, it will be saved in mon->lastError,
but the memory which mon->lastError.message, mon->lastError.str1,
mon->lastError.str2 and mon->lastError.str3 will not be freed at last.
The same bug happened in qemuAgentIO. So I add the following code to fix it.

Signed-off-by: Zhou Yimin 
---
 src/qemu/qemu_agent.c   |2 ++
 src/qemu/qemu_monitor.c |2 ++
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 2cd0ccc..475b43e 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -161,6 +161,8 @@ static void qemuAgentDispose(void *obj)
 (mon->cb->destroy)(mon, mon->vm);
 virCondDestroy(&mon->notify);
 VIR_FREE(mon->buffer);
+if (mon->lastError.code != VIR_ERR_OK)
+virResetError(&mon->lastError);
 }
 
 static int
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 1514715..df72c5d 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -263,6 +263,8 @@ static void qemuMonitorDispose(void *obj)
 virJSONValueFree(mon->options);
 VIR_FREE(mon->balloonpath);
 VIR_FORCE_CLOSE(mon->logfd);
+if (mon->lastError.code != VIR_ERR_OK)
+virResetError(&mon->lastError);
 }
 
 
-- 
1.7.3.1.msysgit.0

Best Regards,
-WangYufei


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


Re: [libvirt] [PATCH 22/34] Removed virDomainEventPtr in favor of virObjectEventPtr

2013-12-02 Thread Daniel P. Berrange
On Mon, Dec 02, 2013 at 01:50:58PM +0100, Cedric Bosdonnat wrote:
> On Fri, 2013-11-29 at 17:18 +, Daniel P. Berrange wrote:
> > On Fri, Nov 29, 2013 at 04:18:58PM +0100, Cédric Bosdonnat wrote:
> > > The virDomainEvent class wasn't defining anything special, thus it has
> > > been dropped.
> > 
> > 
> > > diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
> > > index 7694fcc..d4ecc23 100644
> > > --- a/src/conf/domain_event.c
> > > +++ b/src/conf/domain_event.c
> > 
> > > @@ -107,16 +105,11 @@ static void virDomainEventDeviceRemovedDispose(void 
> > > *obj);
> > >  struct _virObjectEvent {
> > >  virObject parent;
> > >  int eventID;
> > > -};
> > > -
> > > -struct _virDomainEvent {
> > > -virObjectEvent parent;
> > > -
> > >  virObjectMeta meta;
> > >  };
> > 
> > Ok, so you're merging virObjectMeta into the parent class. I understand why
> > you want to keep a single set of metadata for all object types. This does
> > mostly work. We should be aware of the fact that different objects have
> > a different set of valid attributes
> > 
> >  - virDomainPtr - id, name, uuid
> >  - virNetworkPtr - name, uuid
> >  - virStoragePoolPtr - name, uuid
> >  - virInterfacePtr - name
> >  - virSecretPtr - uuid
> >  - virNodeDevicePtr - name
> >  - virNWfilterPtr - name, uuid
> 
> In most of the cases, the uuid is used for the filtering... but that can
> be improved later for virInterfacePtr and virInterfacePtr.
> 
> > Even if we don't store any custom data in the virDomainEvent class its
> > existance does tell you information about the metadata attributes that
> > are valid for this class. Even if we don't use it right now, this feels
> > like a useful class representation to have available.
> 
> The problem is that virClassNew is failing to create a class that has no
> new attribute due to objectSize <= parent->objectSize. I'm tempted to
> replace the '<=' in that test by '<'. Any objection?

Actually that check has caught quite a few bugs in the past so would
rather not relax that. Just add a unused 'bool dummy' field to it.

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 09/34] Create virDomainEventLifecycle to start removing the huge union

2013-12-02 Thread Cedric Bosdonnat
On Fri, 2013-11-29 at 17:09 +, Daniel P. Berrange wrote:
> On Fri, Nov 29, 2013 at 04:18:45PM +0100, Cédric Bosdonnat wrote:
> >
> >  static virClassPtr virObjectEventClass;
> >  static virClassPtr virDomainEventClass;
> > +static virClassPtr virDomainEventLifecycleClass;
> >  static void virObjectEventDispose(void *obj);
> >  static void virDomainEventDispose(void *obj);
> > +static void virDomainEventLifecycleDispose(void *obj);
> >  
> >  struct _virObjectEvent {
> >  virObject parent;
> 
> > @@ -764,37 +786,37 @@ static void *virDomainEventNewInternal(virClassPtr 
> > klass,
> >  return event;
> >  }
> >  
> > -virDomainEventPtr virDomainEventNew(int id, const char *name,
> > +void *virDomainEventNew(int id, const char *name,
> >  const unsigned char *uuid,
> >  int type, int detail)
> >  {
> > -virDomainEventPtr event;
> > +virDomainEventLifecyclePtr event;
> >  
> >  if (virObjectEventInitialize() < 0)
> >  return NULL;
> >  
> > -if (!(event = virDomainEventNewInternal(virDomainEventClass,
> > -  VIR_DOMAIN_EVENT_ID_LIFECYCLE,
> > -  id, name, uuid)))
> > +if (!(event = virDomainEventNewInternal(virDomainEventLifecycleClass,
> > +VIR_DOMAIN_EVENT_ID_LIFECYCLE,
> > +id, name, uuid)))
> >  return NULL;
> >  
> > -event->data.lifecycle.type = type;
> > -event->data.lifecycle.detail = detail;
> > +event->type = type;
> > +event->detail = detail;
> >  
> >  return event;
> >  }
> >  
> > -virDomainEventPtr virDomainEventNewFromDom(virDomainPtr dom, int type, int 
> > detail)
> > +void *virDomainEventNewFromDom(virDomainPtr dom, int type, int detail)
> >  {
> >  return virDomainEventNew(dom->id, dom->name, dom->uuid, type, detail);
> >  }
> >  
> > -virDomainEventPtr virDomainEventNewFromObj(virDomainObjPtr obj, int type, 
> > int detail)
> > +void *virDomainEventNewFromObj(virDomainObjPtr obj, int type, int detail)
> >  {
> >  return virDomainEventNewFromDef(obj->def, type, detail);
> >  }
> >  
> > -virDomainEventPtr virDomainEventNewFromDef(virDomainDefPtr def, int type, 
> > int detail)
> > +void *virDomainEventNewFromDef(virDomainDefPtr def, int type, int detail)
> 
> I think I'd prefer these to return 'virObjectEventPtr' rather than void *, 
> since that's the shared base class of all these event types

OK, I just won't change that in this commit (and the other similar ones)
as it would break builds. I'll change that later when changing from
virDomainEventPtr to virObjectPtr.

--
Cedric

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

Re: [libvirt] [PATCH 22/34] Removed virDomainEventPtr in favor of virObjectEventPtr

2013-12-02 Thread Cedric Bosdonnat
On Fri, 2013-11-29 at 17:18 +, Daniel P. Berrange wrote:
> On Fri, Nov 29, 2013 at 04:18:58PM +0100, Cédric Bosdonnat wrote:
> > The virDomainEvent class wasn't defining anything special, thus it has
> > been dropped.
> 
> 
> > diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
> > index 7694fcc..d4ecc23 100644
> > --- a/src/conf/domain_event.c
> > +++ b/src/conf/domain_event.c
> 
> > @@ -107,16 +105,11 @@ static void virDomainEventDeviceRemovedDispose(void 
> > *obj);
> >  struct _virObjectEvent {
> >  virObject parent;
> >  int eventID;
> > -};
> > -
> > -struct _virDomainEvent {
> > -virObjectEvent parent;
> > -
> >  virObjectMeta meta;
> >  };
> 
> Ok, so you're merging virObjectMeta into the parent class. I understand why
> you want to keep a single set of metadata for all object types. This does
> mostly work. We should be aware of the fact that different objects have
> a different set of valid attributes
> 
>  - virDomainPtr - id, name, uuid
>  - virNetworkPtr - name, uuid
>  - virStoragePoolPtr - name, uuid
>  - virInterfacePtr - name
>  - virSecretPtr - uuid
>  - virNodeDevicePtr - name
>  - virNWfilterPtr - name, uuid

In most of the cases, the uuid is used for the filtering... but that can
be improved later for virInterfacePtr and virInterfacePtr.

> Even if we don't store any custom data in the virDomainEvent class its
> existance does tell you information about the metadata attributes that
> are valid for this class. Even if we don't use it right now, this feels
> like a useful class representation to have available.

The problem is that virClassNew is failing to create a class that has no
new attribute due to objectSize <= parent->objectSize. I'm tempted to
replace the '<=' in that test by '<'. Any objection?

--
Cedric

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

Re: [libvirt] [PATCH 3/3] vbox: handle several errors correctly in vboxHostDeviceGetXMLDesc

2013-12-02 Thread Ryota Ozaki
On Mon, Dec 2, 2013 at 12:03 PM, Daniel Veillard  wrote:
>   This patch also looks fine, but is more complex, I would rather
> postpone it after the 1.2.0 release,

Okay, not a problem :)

I will check the patch again and resend it later.

Thanks,
  ozaki-r

>
> Daniel
>
> On Sun, Dec 01, 2013 at 11:46:07PM +0900, Ryota Ozaki wrote:
>> In the original code, errors of Get{Vendor,Product}Id,
>> VBOX_UTF16_TO_UTF8, strtol were ignored.
>>
>> In order to handle the errors, the patch introduces
>> vboxGetVendorProductIds utility function because adding error
>> codes in the loop is difficult.
>>
>> Reported-by: Laine Stump 
>> Signed-off-by: Ryota Ozaki 
>> ---
>>  src/vbox/vbox_tmpl.c | 74 
>> 
>>  1 file changed, 51 insertions(+), 23 deletions(-)
>>
>> diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
>> index 9336514..27c21bd 100644
>> --- a/src/vbox/vbox_tmpl.c
>> +++ b/src/vbox/vbox_tmpl.c
>> @@ -2208,6 +2208,51 @@ vboxDomainGetMaxVcpus(virDomainPtr dom)
>>   VIR_DOMAIN_VCPU_MAXIMUM));
>>  }
>>
>> +static int vboxGetVendorProductIds(vboxGlobalData *data,
>> +   IUSBDeviceFilter *deviceFilter,
>> +   unsigned *vendorId,
>> +   unsigned *productId)
>> +{
>> +PRUnichar *idUtf16 = NULL;
>> +char *idUtf8 = NULL;
>> +char *endptr = NULL;
>> +unsigned vId = 0;
>> +unsigned pId = 0;
>> +int result = -1;
>> +
>> +if (deviceFilter->vtbl->GetVendorId(deviceFilter, &idUtf16) != 0)
>> +goto out;
>> +
>> +if (VBOX_UTF16_TO_UTF8(idUtf16, &idUtf8) < 0)
>> +goto release_utf16;
>> +
>> +if (virStrToLong_ui(idUtf8, &endptr, 16, &vId) < 0)
>> +goto release_utf8;
>> +
>> +VBOX_UTF8_FREE(idUtf8);
>> +VBOX_UTF16_FREE(idUtf16);
>> +
>> +if (deviceFilter->vtbl->GetProductId(deviceFilter, &idUtf16) != 0)
>> +goto out;
>> +
>> +if (VBOX_UTF16_TO_UTF8(idUtf16, &idUtf8) < 0)
>> +goto release_utf16;
>> +
>> +if (virStrToLong_ui(idUtf8, &endptr, 16, &pId) < 0)
>> +goto release_utf8;
>> +
>> +*vendorId = vId;
>> +*productId = pId;
>> +result = 0;
>> +
>> +release_utf8:
>> +VBOX_UTF8_FREE(idUtf8);
>> +release_utf16:
>> +VBOX_UTF16_FREE(idUtf16);
>> +out:
>> +return result;
>> +}
>> +
>>  static void vboxHostDeviceGetXMLDesc(vboxGlobalData *data, virDomainDefPtr 
>> def, IMachine *machine)
>>  {
>>  #if VBOX_API_VERSION < 4003
>> @@ -2278,13 +2323,7 @@ static void vboxHostDeviceGetXMLDesc(vboxGlobalData 
>> *data, virDomainDefPtr def,
>>  for (i = 0; i < deviceFilters.count; i++) {
>>  PRBool active  = PR_FALSE;
>>  IUSBDeviceFilter *deviceFilter = deviceFilters.items[i];
>> -PRUnichar *vendorIdUtf16   = NULL;
>> -char *vendorIdUtf8 = NULL;
>> -unsigned vendorId  = 0;
>> -PRUnichar *productIdUtf16  = NULL;
>> -char *productIdUtf8= NULL;
>> -unsigned productId = 0;
>> -char *endptr   = NULL;
>> +int res= 0;
>>
>>  deviceFilter->vtbl->GetActive(deviceFilter, &active);
>>  if (!active)
>> @@ -2295,23 +2334,12 @@ static void vboxHostDeviceGetXMLDesc(vboxGlobalData 
>> *data, virDomainDefPtr def,
>>  def->hostdevs[USBFilterCount]->source.subsys.type =
>>  VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB;
>>
>> -deviceFilter->vtbl->GetVendorId(deviceFilter, &vendorIdUtf16);
>> -deviceFilter->vtbl->GetProductId(deviceFilter, &productIdUtf16);
>> +res = vboxGetVendorProductIds(data, deviceFilter,
>> +  
>> &def->hostdevs[USBFilterCount]->source.subsys.u.usb.vendor,
>> +  
>> &def->hostdevs[USBFilterCount]->source.subsys.u.usb.product);
>>
>> -VBOX_UTF16_TO_UTF8(vendorIdUtf16, &vendorIdUtf8);
>> -VBOX_UTF16_TO_UTF8(productIdUtf16, &productIdUtf8);
>> -
>> -vendorId  = strtol(vendorIdUtf8, &endptr, 16);
>> -productId = strtol(productIdUtf8, &endptr, 16);
>> -
>> -def->hostdevs[USBFilterCount]->source.subsys.u.usb.vendor  = 
>> vendorId;
>> -def->hostdevs[USBFilterCount]->source.subsys.u.usb.product = 
>> productId;
>> -
>> -VBOX_UTF16_FREE(vendorIdUtf16);
>> -VBOX_UTF8_FREE(vendorIdUtf8);
>> -
>> -VBOX_UTF16_FREE(productIdUtf16);
>> -VBOX_UTF8_FREE(productIdUtf8);
>> +if (res < 0)
>> +goto release_hostdevs;
>>
>>  USBFilterCount++;
>>  }
>> --
>> 1.8.4
>>
>> --
>> libvir-list mailing list
>> libvir-list@redhat.com
>> https://www.redhat.com/mailman/listinfo/libvir-list
>
> --
> Daniel Veillard  | Open Source and Standards, Red Hat
> veill...@redhat.com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
> http

[libvirt] [PATCH] qemu: add "-boot strict" to commandline whenever possible

2013-12-02 Thread Laine Stump
This resolves:

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

(which was already closed as CANTFIX because the qemu "-boot strict"
commandline option wasn't available at the time).

Problem: you couldn't have a domain that used PXE to boot, but also
had an un-bootable disk device *even if that disk wasn't listed in the
boot order*, because if PXE timed out (e.g. due to the bridge
forwarding delay), the BIOS would move on to the next target, which
would be the unbootable disk device (again - even though it wasn't
given a boot order), and get stuck at a "BOOT DISK FAILURE, PRESS ANY
KEY" message until a user intervened.

The solution available since sometime around QEMU 1.5, is to add
"-boot strict=on" to *every* qemu command. When this is done, if any
devices have a boot order specified, then QEMU will *only* attempt to
boot from those devices that have an explicit boot order, ignoring the
rest.
---
 src/qemu/qemu_capabilities.c  | 3 +++
 src/qemu/qemu_capabilities.h  | 1 +
 src/qemu/qemu_command.c   | 6 ++
 tests/qemucapabilitiesdata/caps_1.5.3-1.caps  | 1 +
 tests/qemucapabilitiesdata/caps_1.6.0-1.caps  | 1 +
 tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 +
 tests/qemuxml2argvtest.c  | 4 
 7 files changed, 17 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 548b988..a68e555 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -243,6 +243,8 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
   "virtio-mmio",
   "ich9-intel-hda",
   "kvm-pit-lost-tick-policy",
+
+  "boot-strict", /* 160 */
 );
 
 struct _virQEMUCaps {
@@ -2279,6 +2281,7 @@ static struct virQEMUCapsCommandLineProps 
virQEMUCapsCommandLine[] = {
 { "machine", "mem-merge", QEMU_CAPS_MEM_MERGE },
 { "drive", "discard", QEMU_CAPS_DRIVE_DISCARD },
 { "realtime", "mlock", QEMU_CAPS_MLOCK },
+{ "boot-opts", "strict", QEMU_CAPS_BOOT_STRICT },
 };
 
 static int
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 02d47c6..aea64ea 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -198,6 +198,7 @@ enum virQEMUCapsFlags {
 QEMU_CAPS_DEVICE_VIRTIO_MMIO = 157, /* -device virtio-mmio */
 QEMU_CAPS_DEVICE_ICH9_INTEL_HDA = 158, /* -device ich9-intel-hda */
 QEMU_CAPS_KVM_PIT_TICK_POLICY = 159, /* kvm-pit.lost_tick_policy */
+QEMU_CAPS_BOOT_STRICT= 160, /* -boot strict */
 
 QEMU_CAPS_LAST,   /* this must always be the last item */
 };
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 763417f..84736d7 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8204,6 +8204,12 @@ qemuBuildCommandLine(virConnectPtr conn,
   def->os.bios.rt_delay);
 }
 
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BOOT_STRICT)) {
+if (boot_nparams++)
+virBufferAddChar(&boot_buf, ',');
+virBufferAddLit(&boot_buf, "strict=on");
+}
+
 if (boot_nparams > 0) {
 virCommandAddArg(cmd, "-boot");
 
diff --git a/tests/qemucapabilitiesdata/caps_1.5.3-1.caps 
b/tests/qemucapabilitiesdata/caps_1.5.3-1.caps
index 09cf657..2b00449 100644
--- a/tests/qemucapabilitiesdata/caps_1.5.3-1.caps
+++ b/tests/qemucapabilitiesdata/caps_1.5.3-1.caps
@@ -131,4 +131,5 @@
 
 
 
+
   
diff --git a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps 
b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps
index 33ee73b..7bce4aa 100644
--- a/tests/qemucapabilitiesdata/caps_1.6.0-1.caps
+++ b/tests/qemucapabilitiesdata/caps_1.6.0-1.caps
@@ -135,4 +135,5 @@
 
 
 
+
   
diff --git a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps 
b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps
index a66034a..bfaab9d 100644
--- a/tests/qemucapabilitiesdata/caps_1.6.50-1.caps
+++ b/tests/qemucapabilitiesdata/caps_1.6.50-1.caps
@@ -134,4 +134,5 @@
 
 
 
+
   
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index dad5973..631ece7 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -418,6 +418,10 @@ mymain(void)
 QEMU_CAPS_DEVICE, QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_BOOT,
 QEMU_CAPS_BOOTINDEX,
 QEMU_CAPS_VIRTIO_BLK_SCSI, QEMU_CAPS_VIRTIO_BLK_SG_IO);
+DO_TEST("boot-strict",
+QEMU_CAPS_DEVICE, QEMU_CAPS_DRIVE, QEMU_CAPS_DRIVE_BOOT,
+QEMU_CAPS_BOOTINDEX, QEMU_CAPS_BOOT_STRICT,
+QEMU_CAPS_VIRTIO_BLK_SCSI, QEMU_CAPS_VIRTIO_BLK_SG_IO);
 DO_TEST("bootloader", QEMU_CAPS_DOMID, QEMU_CAPS_KVM);
 
 DO_TEST("reboot-timeout-disabled", QEMU_CAPS_REBOOT_TIMEOUT);
-- 
1.8.4.2

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


Re: [libvirt] [PATCH] tests: Fix comment for fake storage pool driver

2013-12-02 Thread Peter Krempa
On 12/02/13 13:36, Peter Krempa wrote:
> Commit bae124e40ff2b9d4de75d44510619db2c08d548a was accidentaly pushed
> without review feedback worked in. Fix it up.
> ---
>  tests/qemuxml2argvtest.c | 9 -
>  1 file changed, 4 insertions(+), 5 deletions(-)

This patch was pushed under the trivial rule.

Peter




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

[libvirt] [PATCH] tests: Fix comment for fake storage pool driver

2013-12-02 Thread Peter Krempa
Commit bae124e40ff2b9d4de75d44510619db2c08d548a was accidentaly pushed
without review feedback worked in. Fix it up.
---
 tests/qemuxml2argvtest.c | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 17d4554..e9a32fb 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -227,17 +227,16 @@ fakeStoragePoolIsActive(virStoragePoolPtr pool)
 /* Test storage pool implementation
  *
  * These functions aid testing of storage pool related stuff when creating a
- * qemu command .
+ * qemu command line.
  *
  * There are a few "magic" values to pass to these functions:
  *
- * 1) "inactive" as
- * a pool name for pool lookup creates a inactive pool. All other names are
- * interpreted as file names for files of storagepooltest and are used as the
+ * 1) "inactive" as a pool name to create an inactive pool. All other names are
+ * interpreted as file names in storagepoolxml2xmlout/ and are used as the
  * definition for the pool. If the file doesn't exist the pool doesn't exist.
  *
  * 2) "nonexistent" returns an error while looking up a volume. Otherwise
- * pattern VOLUME_TYPE+VOLUME_PATH can be used to simulate a volume in an pool.
+ * pattern VOLUME_TYPE+VOLUME_PATH can be used to simulate a volume in a pool.
  * This creates a fake path for this volume. If the '+' sign is omitted, block
  * type is assumed.
  */
-- 
1.8.4.3

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


Re: [libvirt] [PATCHv2 3/4] qemuxml2argv: Add test for disk type='volume' with iSCSI pools

2013-12-02 Thread Peter Krempa
On 11/28/13 09:31, Osier Yang wrote:
> On 27/11/13 23:14, Peter Krempa wrote:
>> Tweak the existing file so that it can be tested for command line
>> corectness.
>> ---
>>   tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool-mode.args | 10
>> ++
>>   tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool-mode.xml  |  4
>> ++--
>>   tests/qemuxml2argvtest.c   |  2 ++
>>   3 files changed, 14 insertions(+), 2 deletions(-)
>>   create mode 100644
>> tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool-mode.args
>>

> 
> Okay, I see why you removed the "startupPolicy" now, it doesn't make sense
> for a pool with block type volume.
> 
> ACK

Pushed; Thanks.

Peter




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

Re: [libvirt] [PATCHv2 2/4] qemuxml2argv: Add test to verify correct usage of disk type="volume"

2013-12-02 Thread Peter Krempa
On 11/28/13 09:29, Osier Yang wrote:
> On 27/11/13 23:14, Peter Krempa wrote:
>> Tweak the existing file to test command line generator too.
>> ---
>>   tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool.args | 8 
>>   tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool.xml  | 2 +-
>>   tests/qemuxml2argvtest.c  | 2 ++
>>   3 files changed, 11 insertions(+), 1 deletion(-)
>>   create mode 100644
>> tests/qemuxml2argvdata/qemuxml2argv-disk-source-pool.args
>>
>>
> 
> Michal's ACK stands.

Pushed. Thanks.

Peter



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

Re: [libvirt] [PATCHv2 1/4] test: Implement fake storage pool driver in qemuxml2argv test

2013-12-02 Thread Peter Krempa
On 11/28/13 09:27, Osier Yang wrote:
> On 27/11/13 23:14, Peter Krempa wrote:
>> To support testing of "volume" disk backing, we need to implement a few
>> disk driver backend functions.
>>
>> The fake storage driver uses files in storagepoolxml2xmlout/POOLNAME.xml
>> as XML files for pool definitions and volume names are in format
>> "VOL_TYPE+VOL_PATH". By default type "block" is assumed (for iSCSI test
>> compatibility).
>>
>> The choice of this approach along with implemented functions was made so
>> that  can be tested in the xml2argv test.
>> ---
>>   tests/qemuxml2argvtest.c | 183
>> +++
>>   1 file changed, 183 insertions(+)
>>

...

> 
> Others look fine. ACK if you fix those comments.

I've fixed the comments and pushed this patch. Thanks.

Peter




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 v2 2/2] qemu: add support for -device pvpanic

2013-12-02 Thread Peter Krempa
On 12/02/13 07:11, Hu Tao wrote:
> This patch will add -device pvpanic to qemu command line if user enables
> pvpanic in domain xml and the qemu version supports pvpanic.
> 
> Signed-off-by: Hu Tao 
> ---
>  src/qemu/qemu_capabilities.c |  3 +++
>  src/qemu/qemu_capabilities.h |  2 ++
>  src/qemu/qemu_command.c  | 10 ++
>  3 files changed, 15 insertions(+)
> 

...

> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 763417f..6310bb2 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -9588,6 +9588,16 @@ qemuBuildCommandLine(virConnectPtr conn,
>  goto error;
>  }
>  
> +if (def->pvpanic &&
> +virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_PVPANIC)) {
> +if (def->pvpanic->ioport > 0) {
> +virCommandAddArg(cmd, "-device");
> +virCommandAddArgFormat(cmd, "pvpanic,ioport=%d",
> +   def->pvpanic->ioport);
> +} else
> +virCommandAddArgList(cmd, "-device", "pvpanic", NULL);

If pvpanic is requested, but not available in qemu, libvirt should error
out instead of silently starting the VM without the device.

> +}
> +
>  if (mlock) {
>  unsigned long long memKB;
>  
> 

Also as said in review of 1/2. You need to add tests for the new device.

Peter



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 v2 1/2] conf: add xml element devices/pvpanic

2013-12-02 Thread Peter Krempa
On 12/02/13 07:11, Hu Tao wrote:
> This patch adds a new xml element devices/pvpanic to support qemu device
> pvpanic. It can be used to receive guest panic notification.
> 
> Signed-off-by: Hu Tao 
> ---
>  docs/formatdomain.html.in | 25 +
>  src/conf/domain_conf.c| 68 
> +++
>  src/conf/domain_conf.h|  9 +++
>  3 files changed, 102 insertions(+)

A few issues I see at first glance:

1) you didn't add ABI compatibility check for the pvpanic device
2) XML->XML tests are missing
3) RNG schemas for the new element are missing
4) XML->qemu commandline tests are missing (in 2/2)


> 
> diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> index 1850a2b..0a72baa 100644
> --- a/docs/formatdomain.html.in
> +++ b/docs/formatdomain.html.in
> @@ -5080,6 +5080,31 @@ qemu-kvm -net nic,model=? /dev/null
>  
>
>  
> +pvpanic device
> +
> +  pvpanic device enables libvirt to receive panic notification from a 
> QEMU
> +  guest.
> +  Since 1.3.0, QEMU and KVM only

1.3.0? the since tag is supposed to contain a libvirt version. 1.3.0
will not happen that soon. 1.2.1 is what you are looking for.

> +
> +
> +  Example: usage of pvpanic configuration
> +
> +
> +  ...
> +  
> +
> +  
> +  ...
> +
> +  
> +ioport
> +
> +  
> +ioport used by pvpanic.
> +  
> +
> +  
> +
>  Security label
>  
>  
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 140eb80..1b8f66f 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c

...

> @@ -15715,6 +15768,18 @@ virDomainWatchdogDefFormat(virBufferPtr buf,
>  return 0;
>  }
>  
> +static int virDomainPvpanicDefFormat(virBufferPtr buf,
> + virDomainPvpanicDefPtr def)
> +{
> +if (def->ioport > 0) {
> +virBufferAsprintf(buf, "\n",
> +  def->ioport);
> +} else {
> +virBufferAsprintf(buf, "\n");

Would break syntax-check. For static strings use virBufferAddLit.

> +}
> +
> +return 0;
> +}
>  
>  static int
>  virDomainRNGDefFormat(virBufferPtr buf,




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

  1   2   >