libvirt/src/conf
Eric Blake 0cd02bca6e event: don't allow mix of old- and new-style registration
Consider these two calls, in either order:

id1 = virConnectDomainEventRegisterAny(conn, NULL,
   VIR_DOMAIN_EVENT_ID_LIFECYCLE,
   VIR_DOMAIN_EVENT_CALLBACK(callback), NULL, NULL);
virConnectDomainEventRegister(conn, callback, NULL, NULL);

Right now, the second call fails, because under the hood, the
old-style function registration is tightly coupled to the
new style lifecycle eventID, and the two calls both try
to register the same global eventID callback representation.

We've alreay documented that users should avoid old-style
registration and deregistration, so anyone heeding the advice
won't run into this situation.  But it would be even nicer if
we pretend the two interfaces are completely separate, and
disallow any cross-linking.  That is, a call to old-style
deregister should never remove a new-style callback even if it
is the same function pointer, and a call to new-style callback
using only callbackIDs obtained legitimately should never
remove an old-style callback (of course, since our callback
IDs are sequential, and there is still coupling under the
hood, you can easily guess the callbackID of an old style
registration and use new-style deregistration to nuke it - but
that starts to be blatantly bad coding on your part rather
than a surprising result on what looks like reasonable
stand-alone API).

With this patch, you can now register a global lifecycle event
handler twice, by using both old and new APIs; if such an event
occurs, your callback will be entered twice.  But that is not a
problem in practice, since it is already possible to use the
new API to register both a global and per-domain event handler
using the same function, which will likewise fire your callback
twice for that domain.  Duplicates are still prevented when
using the same API with same parameters twice (old-style twice,
new-style global twice, or new-style per-domain with same domain
twice), and things are still bounded (it is not possible to
register a single function pointer more than N+2 times per event
id, where N is the number of domains available on the connection).
Besides, it has always been possible to register as many
separate function pointers on the same event id as desired,
through either old or new style API, where the bound there is
the physical limitation of writing a program with enough
distinct function pointers.

Adding another event registration in the testsuite is sufficient
to cover this, where the test fails without the rest of the patch.

* src/conf/object_event.c (_virObjectEventCallback): Add field.
(virObjectEventCallbackLookup): Add argument.
(virObjectEventCallbackListAddID, virObjectEventStateCallbackID):
Adjust callers.
* tests/objecteventtest.c (testDomainCreateXMLMixed): Enhance test.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-07 11:43:56 -07:00
..
capabilities.c maint: fix comma style issues: conf 2013-11-20 09:14:54 -07:00
capabilities.h maint: avoid further typedef accidents 2013-10-30 17:02:12 -06:00
cpu_conf.c conf: fix incorrect error log in virCPUDefIsEqual 2013-11-07 12:01:29 +01:00
cpu_conf.h maint: avoid 'const fooPtr' in cpu files 2013-10-14 13:11:20 -06:00
device_conf.c virutil: Move string related functions to virstring.c 2013-05-02 16:56:55 +02:00
device_conf.h Rename util.{c,h} to virutil.{c,h} 2012-12-21 11:19:49 +00:00
domain_audit.c Convert 'int i' to 'size_t i' in src/conf/ files 2013-07-10 17:40:13 +01:00
domain_audit.h Include pid namespace inode in LXC audit messages 2013-03-07 19:43:53 +00:00
domain_conf.c domain: don't try to interpret <driver> as virtio config for hostdev interfaces 2013-12-31 10:56:21 +02:00
domain_conf.h conf: add support for panic device 2013-12-12 21:17:26 -07:00
domain_event.c event: don't let old-style events clobber per-domain events 2014-01-07 09:12:10 -07:00
domain_event.h Associate a dispatch function with the event objects 2013-12-13 16:07:54 +00:00
domain_nwfilter.c Convert 'int i' to 'size_t i' in src/conf/ files 2013-07-10 17:40:13 +01:00
domain_nwfilter.h maint: fix up copyright notice inconsistencies 2012-09-20 16:30:55 -06:00
interface_conf.c maint: avoid 'const fooPtr' in conf 2013-10-14 14:34:38 -06:00
interface_conf.h Get rid of shadowed booleans 2013-10-22 15:50:47 +01:00
netdev_bandwidth_conf.c Adapt to VIR_ALLOC and virAsprintf in src/conf/* 2013-07-10 11:07:31 +02:00
netdev_bandwidth_conf.h Rename xml.{c,h} to virxml.{c,h} 2012-12-21 11:19:50 +00:00
netdev_vlan_conf.c maint: avoid 'const fooPtr' in conf 2013-10-14 14:34:38 -06:00
netdev_vlan_conf.h maint: avoid 'const fooPtr' in conf 2013-10-14 14:34:38 -06:00
netdev_vport_profile_conf.c Move virNetDevVPort enum impl into virnetdevvportprofile.c 2013-10-11 11:45:54 +01:00
netdev_vport_profile_conf.h Rename xml.{c,h} to virxml.{c,h} 2012-12-21 11:19:50 +00:00
network_conf.c maint: fix comma style issues: conf 2013-11-20 09:14:54 -07:00
network_conf.h maint: avoid 'const fooPtr' in conf 2013-10-14 14:34:38 -06:00
network_event.c event: fix doc typos, and doc more public methods 2014-01-03 10:45:54 -07:00
network_event.h Associate a dispatch function with the event objects 2013-12-13 16:07:54 +00:00
node_device_conf.c maint: avoid 'const fooPtr' in conf 2013-10-14 14:34:38 -06:00
node_device_conf.h util: use size_t instead of unsigned int for num_virtual_functions 2013-11-08 14:31:11 +02:00
nwfilter_conf.c Fix memory leak in virNWFilterDefParseXML() 2013-12-02 10:39:44 +08:00
nwfilter_conf.h maint: avoid 'const fooPtr' in nwfilter files 2013-10-14 13:13:18 -06:00
nwfilter_ipaddrmap.c Adapt to VIR_ALLOC and virAsprintf in src/conf/* 2013-07-10 11:07:31 +02:00
nwfilter_ipaddrmap.h maint: fix up copyright notice inconsistencies 2012-09-20 16:30:55 -06:00
nwfilter_params.c maint: avoid 'const fooPtr' in nwfilter files 2013-10-14 13:13:18 -06:00
nwfilter_params.h maint: avoid 'const fooPtr' in nwfilter files 2013-10-14 13:13:18 -06:00
object_event_private.h event: tighten scope of object_event 2014-01-07 09:12:11 -07:00
object_event.c event: don't allow mix of old- and new-style registration 2014-01-07 11:43:56 -07:00
object_event.h event: fix doc typos, and doc more public methods 2014-01-03 10:45:54 -07:00
secret_conf.c maint: avoid 'const fooPtr' in conf 2013-10-14 14:34:38 -06:00
secret_conf.h maint: avoid 'const fooPtr' in conf 2013-10-14 14:34:38 -06:00
snapshot_conf.c qemu: snapshot: Fix incorrect disk type for auto-generated disks 2013-12-06 10:45:49 +01:00
snapshot_conf.h snapshot: conf: Use common parsing and formatting functions for source 2013-12-02 14:28:20 +01:00
storage_conf.c storage: Add gluster pool filter and fix virsh pool listing 2013-12-19 11:01:50 +01:00
storage_conf.h maint: Kill usage of atoi() 2013-12-04 18:56:06 +01:00
storage_encryption_conf.c Convert 'int i' to 'size_t i' in src/conf/ files 2013-07-10 17:40:13 +01:00
storage_encryption_conf.h Rename util.{c,h} to virutil.{c,h} 2012-12-21 11:19:49 +00:00
virchrdev.c Adapt to VIR_ALLOC and virAsprintf in src/conf/* 2013-07-10 11:07:31 +02:00
virchrdev.h conf: Add unix socket support to virChrdevOpen 2013-01-04 18:07:11 -07:00