On 01/06/2014 05:27 PM, Eric Blake wrote: > 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. > > * src/conf/object_event.c (_virObjectEventCallback): Add field. > (virObjectEventCallbackLookup): Add argument. > (virObjectEventCallbackListAddID, virObjectEventStateCallbackID): > Adjust callers. > > Signed-off-by: Eric Blake <eblake@xxxxxxxxxx> > --- > src/conf/object_event.c | 21 ++++++++++++++++----- > 1 file changed, 16 insertions(+), 5 deletions(-) > ACK the pair (10 & 11) John It's a tangled web you weave... -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list