Commit Graph

1428 Commits

Author SHA1 Message Date
Eric Blake
995b2ebab6 event: properly filter count of remaining events
On the surface, this sequence of API calls should succeed:

id1 = virConnectDomainEventRegisterAny(..., VIR_DOMAIN_EVENT_ID_LIFECYCLE,...);
id2 = virConnectDomainEventRegisterAny(..., VIR_DOMAIN_EVENT_ID_RTC_CHANGE,...);
virConnectDomainEventDeregisterAny(id1);
id1 = virConnectDomainEventRegisterAny(..., VIR_DOMAIN_EVENT_ID_LIFECYCLE,...);

And for test:///default, it does.  But for qemu:///system, it fails:
libvirt: XML-RPC error : internal error: domain event 0 already registered

Looking closer, the bug is caused by miscommunication between
the object event engine and the client side of the remote driver.
In our implementation, we set up a single server-side event per
eventID, then the client side replicates that one event to all
callbacks that have been registered client side.  To know when
to turn the server side eventID on or off, the client side must
track how many events for the same eventID have been registered.
But while our code was filtering by eventID on event registration,
it did not filter on event deregistration.  So the above API calls
resulted in the deregister returning 1 instead of 0, so no RPC
deregister was issued, and the final register detects on the
server side that the server is already handling eventID 0.

Unfortunately, since the problem is only observable on remote
connections, it's not possible to enhance objecteventtest to
expose the semantics using only public API entry points.

* src/conf/object_event.c (virObjectEventCallbackListCount): New
function.
(virObjectEventCallbackListAddID)
(virObjectEventCallbackListRemoveID)
(virObjectEventCallbackListMarkDeleteID): Use it.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-07 10:53:24 -07:00
Eric Blake
114aa0751e event: tighten scope of object_event
Tighten up scope after the previous patch avoided using
internals.  This will also make it easier to change
internal implementation without having to chase down quite
as many impacted callers or worrying about two files getting
implementations out of sync.

* src/conf/object_event_private.h
(virObjectEventCallbackListAddID, virObjectEventQueueClear)
(virObjectEventStateLock, virObjectEventStateUnlock)
(virObjectEventTimer): Drop prototype.
(_virObjectEventCallbackList, _virObjectEventState)
(_virObjectEventCallback): Move...
* src/conf/object_event.c: ...here.
(virObjectEventCallbackListAddID, virObjectEventQueueClear)
(virObjectEventStateLock, virObjectEventStateUnlock)
(virObjectEventTimer): Mark private.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-07 09:12:11 -07:00
Eric Blake
4221d64fcb event: don't let old-style events clobber per-domain events
Right now, the older virConnectDomainEventRegister (takes a
function pointer, returns 0 on success) and the newer
virConnectDomainEventRegisterID (takes an eventID, returns a
callbackID) share the underlying implementation (the older
API ends up consuming a callbackID for eventID 0 under the
hood).  We implemented that by a lot of copy and pasted
code between object_event.c and domain_event.c, according to
whether we are dealing with a function pointer or an eventID.
However, our copy and paste is not symmetric.  Consider this
sequence:

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

the first three calls would succeed, but the third call ended
up nuking the id1 callbackID (the per-domain new-style handler),
then the fourth call failed with an error about an unknown
callbackID, leaving us with the global handler (old-style) still
live and receiving events.  It required another old-style
deregister to clean up the mess.  Root cause was that
virDomainEventCallbackList{Remove,MarkDelete} were only
checking for function pointer match, rather than also checking
for whether the registration was global.

Rather than playing with the guts of object_event ourselves
in domain_event, it is nicer to add a mapping function for the
internal callback id, then share common code for event removal.
For now, the function-to-id mapping is used only internally;
I thought about whether a new public API to let a user learn
the callback would be useful, but decided exposing this to the
user is probably a disservice, since we already publicly
document that they should avoid the old style, and since this
patch already demonstrates that older libvirt versions have
weird behavior when mixing old and new styles.

And like all good bug fix patches, I enhanced the testsuite,
validating that the changes in tests/ expose the failure
without the rest of the patch.

* src/conf/object_event.c (virObjectEventCallbackLookup)
(virObjectEventStateCallbackID): New functions.
(virObjectEventCallbackLookup): Use helper function.
* src/conf/object_event_private.h (virObjectEventStateCallbackID):
Declare new function.
* src/conf/domain_event.c (virDomainEventStateRegister)
(virDomainEventStateDeregister): Let common code handle the
complexity.
(virDomainEventCallbackListRemove)
(virDomainEventCallbackListMarkDelete)
(virDomainEventCallbackListAdd): Drop unused functions.
* tests/objecteventtest.c (testDomainCreateXMLMixed): New test.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-07 09:12:10 -07:00
Eric Blake
94a26c7e88 event: use newer array management macros
We might as well take advantage of viralloc.h instead of open-coding
array management ourselves.  While at it, I simplified several
places that were doing repetitive pointer chasing to use an
intermediate variable for legibility (some other places remain,
but they will disapper in later refactoring patches).

* src/conf/object_event_private.h (_virObjectEventCallbackList):
Use size_t for count.
* src/conf/object_event.c (_virObjectEventQueue): Likewise.
(virObjectEventCallbackListRemoveID): Use VIR_DELETE_ELEMENT.
(virObjectEventQueuePush, virObjectEventCallbackListAddID): Use
VIR_APPEND_ELEMENT.
(virObjectEventCallbackListEventID)
(virObjectEventStateDispatchCallbacks): Simplify code.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-06 08:01:10 -07:00
Eric Blake
22e82aa596 event: use bool in more places
No need to use an int that only ever stores 0 and 1.

* src/conf/object_event_private.h (_virObjectEventCallback):
Change deleted to bool.
* src/conf/object_event.c (virObjectEventDispatchMatchCallback):
Switch return type to bool.
(virObjectEventCallbackListMarkDeleteID): Update client.
* src/conf/domain_event.c (virDomainEventCallbackListMarkDelete):
Likewise.
2014-01-06 07:58:08 -07:00
Eric Blake
344e1f5130 event: remove unneeded virObjectEventGetEventID
Any file with access to object_event_private.h also has access to
the internals of virObjectEvent, without needing an accessor
function.  Not to mention the accessor function was doing type
checks that would always succeed.

* src/conf/object_event_private.h (virObjectEventGetEventID): Drop.
* src/conf/object_event.c (virObjectEventGetEventID): Drop.
(virObjectEventDispatchMatchCallback): Simplify caller.
* src/conf/domain_event.c (virDomainEventDispatchDefaultFunc):
Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-03 10:55:42 -07:00
Eric Blake
6742fb0b10 event: fix doc typos, and doc more public methods
While working on events, I found a number of minor issues; I'm
hoisting these to the front rather than doing it piecemeal in
the patches where I first noticed bad or missing documentation.

* src/conf/object_event.c: Fix grammar, document all parameters
of public functions, wrap some long lines.
* src/conf/object_event.h: Likewise.
* src/conf/network_event.c: Likewise.
* src/conf/domain_event.c: Likewise (except for the large number
of event creation functions).
* src/libvirt_private.cyms (conf/object_event.h): Split...
(conf/network_event.h): ...to account for new file.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-01-03 10:45:54 -07:00
Laine Stump
3337a98a5e domain: don't try to interpret <driver> as virtio config for hostdev interfaces
This resolves:

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

The <driver> name attribute of an interface is interpreted in two
different ways depending on the <interface> type - if the interface is
type='hostdev', then the driver name describes which backend to use
for the hostdev device assignment (vfio or kvm), but if the interface
is any emulated type *and* the model type is "virtio", then the driver
name can be "vhost" or "qemu", telling which backend qemu should use
to communicate with the emulated device.

The problem comes when someone has defined a an interface like this
(which is accepted by the parser as long as no <driver name='xxx'/> is
specified):

    <interface type='hostdev'>
       ...
       <model type='virtio'/>
       ...
    </interface>

As libvirt storing this definition in the domain's status, the driver
name is automatically filled in with the backend that was
automatically decided by libvirt, so it stores this in the status:

    <interface type='hostdev'>
       ...
       <driver name='vfio'/>
       ...
       <model type='virtio'/>
       ...
    </interface>

This isn't noticed until the next time libvirtd is restarted - as it
is reading the status of all domains, it encounters the above
interface definition, logs an error:

  internal error: Unknown interface <driver name='vfio'> has been specified

and fails to reload the domain status, so the domain is marked as
inactive.

The solution is to stop the parser from interpreting <driver>
attributes as if the device was an emulated virtio device, when it is
actually a hostdev.

(Although the bug has existed since vfio support was added, it has
just recently become more apparent because libvirt previously didn't
automatically set the driver name for hostdev interfaces in the domain
status to vfio/kvm as it does since commit f094aa, first appearing in
v1.1.4.)
2013-12-31 10:56:21 +02:00
Laine Stump
8700b87800 qemu: re-add hostdev interfaces to hostdev array on libvirtd restart
This resolves:

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

If a domain has an <interface type='hostdev'> or an <interface
type='network'> where the network itself is a pool of hostdev devices,
then libvirt will internally keep that device on both the interface
list *and* the hostdev list for the domain. One of the places this
comes in handy is when a new device is being added and libvirt wants
to find a unique "alias" name for it - it just scans through the
hostdev array and makes sure it picks a name that doesn't match the
alias of any device in that array.

However, when libvirtd was restarted, if there was an <interface
type='network'> with the network being a hostdev pool, the device
would not be added to the reconstructed internal hostdev array, so its
alias would not be found during a scan of the hostdev array, thus
attempts to add a new hostdev (or <interface type='hostdev'> or
<interface type='network'>) would result in a message like this:

internal error: unable to execute QEMU command 'device_add':
                Duplicate ID 'hostdev0' for device

This patch simply fixes the existing code in the domain XML parser
that fixes up the hostdev array in the case of <interface
type='hostdev'> to do the same thing in the case of <interface
type='network'> with a hostdev network.

This bug has existed since the very first addition of hostdev networks
to libvirt (0.10.0).
2013-12-23 13:16:57 +02:00
John Ferlan
d53c57b806 PanicCheckABIStability: Need to check for existence
Commit id '4313fead' added a call to virDomainPanicCheckABIStability()
which did not check whether the panic device existed before making a call
to virDomainDeviceInfoCheckABIStability() which ended up segfaulting:

Thread 1 (Thread 0x7f5332837700 (LWP 10964)):
    (src=<optimized out>, dst=<optimized out>)
    at conf/domain_conf.c:13007
    (dst=<optimized out>, src=<optimized out>)
    at conf/domain_conf.c:13712
    (src=<optimized out>, dst=<optimized out>)
    at conf/domain_conf.c:14056
    (domain=domain@entry=0x7f53000057c0, vm=vm@entry=0x7f53000036d0,
     defptr=defptr@entry=0x7f5332836978, snap=snap@entry=0x7f5332836970,
     update_current=update_current@entry=0x7f5332836962, flags=flags@entry=1)
    at conf/snapshot_conf.c:1230
    (domain=0x7f53000057c0, xmlDesc=<optimized out>, flags=1)
    at qemu/qemu_driver.c:12719
    (domain=domain@entry=0x7f53000057c0, xmlDesc=0x7f53000081d0
     "<domainsnapshot>\n  <name>snap2</name>\n
     <description>new-desc</description>\n  <state>running</state>\n
     <parent>\n    <name>snap1</name>\n  </parent>\n
     <creationTime>1387487268</creationTime>\n  <memory s"..., flags=1)
    at libvirt.c:19695
...

(gdb) up 3
(gdb) print *other->def->dom
$2 = {virtType = 2, id = -1, ..
...
  rng = 0x0, panic = 0x0, namespaceData = 0x0,...
...
(gdb) print *def->dom
$3 = {virtType = 2, id = -1, ...
...
  rng = 0x0, panic = 0x0, namespaceData = 0x0,...
...
(gdb)

Also seen using following sequence:

virsh save $dom $file
virsh save-image-edit $file
  add (or remove) a <panic/> line
  <devices>
  ...
    <panic>
      <address type='isa' iobase='0x505'/>
    </panic>
  ...
  </devices>
2013-12-21 09:49:58 -05:00
Peter Krempa
b560946c19 storage: Add gluster pool filter and fix virsh pool listing
Recent addition of the gluster pool type omitted fixing the virsh and
virConnectListAllStoragePool filters. A typecast of the converting
function in virsh showed that also the sheepdog pool was omitted in the
command parser.

This patch adds gluster pool filtering support and fixes virsh to
properly convert all supported storage pool types. The added typecast
should avoid doing such mistakes in the future.
2013-12-19 11:01:50 +01:00
Daniel P. Berrange
ef19b3e3f5 Add debug output when registering event handlers
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-13 16:07:55 +00:00
Daniel P. Berrange
dbcc38da15 Remove the event namespace concept
The event namespace concept is mostly redundant information.
With the re-written dispatcher, the namespace is only used
for equality comparisons between event IDs. This can be solved
by just comparing virClassPtr instances instead.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-13 16:07:55 +00:00
Daniel P. Berrange
8a4820ab23 Associate a dispatch function with the event objects
Instead of having the object event code have to know about each
type of event and their dispatch functions, associate a dispatch
function with the object instance. The dispatch code can thus be
significantly simplified.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-13 16:07:54 +00:00
Daniel P. Berrange
5c17a37142 Introduce abstract virNetworkEvent class
Inject a virNetworkEvent class between virObjectEvent
and virNetworkEventLifecycle to mirror virDomainEvent.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-13 16:07:54 +00:00
Daniel P. Berrange
6e2545c07b Add 'detail' arg to network lifecycle event internals
While the public API & wire protocol included the 'detail'
arg for network lifecycle events, the internal event handling
code did not process it. This meant that if a future libvirtd
server starts sending non-0 'detail' args, the current libvirt
client will not process them.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-12-13 16:07:54 +00:00
Nehal J Wani
34d52b3471 Fix memory leak in virObjectEventCallbackListRemoveID()
While running objecteventtest, it was found that valgrind pointed out the
following memory leak:

==13464== 5 bytes in 1 blocks are definitely lost in loss record 7 of 134
==13464==    at 0x4A0887C: malloc (vg_replace_malloc.c:270)
==13464==    by 0x341F485E21: strdup (strdup.c:42)
==13464==    by 0x4CAE28F: virStrdup (virstring.c:554)
==13464==    by 0x4CF3CBE: virObjectEventCallbackListAddID (object_event.c:286)
==13464==    by 0x4CF49CA: virObjectEventStateRegisterID (object_event.c:729)
==13464==    by 0x4CF73FE: virDomainEventStateRegisterID (domain_event.c:1424)
==13464==    by 0x4D7358F: testConnectDomainEventRegisterAny (test_driver.c:6032)
==13464==    by 0x4D600C8: virConnectDomainEventRegisterAny (libvirt.c:19128)
==13464==    by 0x402409: testDomainStartStopEvent (objecteventtest.c:232)
==13464==    by 0x403451: virtTestRun (testutils.c:138)
==13464==    by 0x402012: mymain (objecteventtest.c:395)
==13464==    by 0x403AF2: virtTestMain (testutils.c:593)
==13464==
2013-12-13 16:23:21 +01:00
Hu Tao
4313feade4 conf: add support for panic device
panic device is a device that enables libvirt to receive notification
of guest panic event.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-12 21:17:26 -07:00
Hu Tao
f1a039ef57 conf: introduce generic ISA address
For example:
<address type='isa' iobase='0x505' irq='0x1'/>

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-12 21:11:21 -07:00
Gao feng
b9ce5d388f rename virBlkioDeviceWeightPtr to virBlkioDevicePtr
The throttle blkio cgroup will reuse this struct.

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
2013-12-12 12:29:59 +00:00
Gao feng
b4710669c3 rename virBlkioDeviceWeightArrayClear to virBlkioDeviceArrayClear
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
2013-12-12 12:29:54 +00:00
Gao feng
529739cc80 rename virDomainBlkioDeviceWeightParseXML to virDomainBlkioDeviceParseXML
virDomainBlkioDeviceWeightParseXML will be used to parse
the xml element read_bps, write_bps, read_iops, write_iops.

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
2013-12-12 12:29:50 +00:00
Cédric Bosdonnat
a5a484ddfc Added default case with error for object event dispatching
Hitting this should be pretty rare, but at least developers will know
that they are providing a weird event ID. Otherwise for namespace that
are added in the normal way, gcc will raise a warning about unhandled
case in the switch.
2013-12-11 13:35:08 +00:00
Cédric Bosdonnat
1b07406e9e Fixed indentation in src/conf/*_event* 2013-12-11 13:35:06 +00:00
Cédric Bosdonnat
9ff38c5428 Added Network events API and virNetworkEventLifecycle.
Define the public API for (de-)registering network events
and the callbacks for receiving lifecycle events. The lifecycle
event includes a 'detail' parameter to match the domain lifecycle
event data, but this is currently unused.

The network events related code goes into its own set of internal
files src/conf/network_event.[ch]
2013-12-11 13:10:41 +00:00
Cédric Bosdonnat
620103feaf Extracted common parts of domain_event.[ch] to object_event.[ch] 2013-12-10 13:12:35 +00:00
Cédric Bosdonnat
f88241608a Split the virObjectEvent and virDomainEvent* to separate them after 2013-12-10 13:07:07 +00:00
Cédric Bosdonnat
d397bf2f6d Renamed virDomainEventTimer to virObjectEventTimer 2013-12-10 13:07:02 +00:00
Cédric Bosdonnat
abb65994b7 Add object event namespaces for the event IDs
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.
2013-12-10 13:04:25 +00:00
Cédric Bosdonnat
67d91cb2bd Use virObjectEventPtr instead of virDomainEventPtr
The virDomainEvent class is kept as it indicates what meta informations
are valid for the children classes. This may be useful in the future.
2013-12-10 12:45:21 +00:00
Cédric Bosdonnat
d4d02b206a Create virDomainEventDeviceRemoved and remove the huge union
RIP virDomainEvent union. All data are now stored in each
virObjectEvent subclass.
2013-12-10 12:38:36 +00:00
Cédric Bosdonnat
d9c6ba31a5 Create virDomainEventBalloonChange to get rid of the huge union 2013-12-10 12:38:03 +00:00
Cédric Bosdonnat
8d53d6ab74 Create virDomainEventTrayChange to get rid of the huge union 2013-12-10 12:37:26 +00:00
Cédric Bosdonnat
bc7b304336 Create virDomainEventDiskChange to get rid of the huge union 2013-12-10 12:36:54 +00:00
Cédric Bosdonnat
0ac4c9edad Create virDomainEventBlockJob to get rid of the huge union 2013-12-10 12:35:12 +00:00
Cédric Bosdonnat
e6b83046b1 Create virDomainEventGraphics to get rid of the huge union 2013-12-10 12:34:52 +00:00
Cédric Bosdonnat
b223263850 Create virDomainEventIOError to get rid of the huge union 2013-12-10 12:33:24 +00:00
Cédric Bosdonnat
b044091540 Create virDomainEventWatchdog to get rid of the huge union 2013-12-10 12:31:55 +00:00
Cédric Bosdonnat
8a29ffcf9a Create virDomainEventRTCChange to get rid of the huge union 2013-12-10 12:30:55 +00:00
Cédric Bosdonnat
2c0008cc3e Renamed virDomainEventNewInternal to virDomainEventNew
This change may be confusing at first, but provides a much more
consistent naming scheme for the virObjectEvent children construction
functions.
2013-12-10 12:29:38 +00:00
Cédric Bosdonnat
6ffce0f698 Renamed virDomainEventNew* to virDomainEventLifecycleNew*
This aims at providing some consistency with other domain events
2013-12-10 12:27:37 +00:00
Cédric Bosdonnat
0d1d632d79 Create virDomainEventLifecycle to start removing the huge union 2013-12-10 12:25:26 +00:00
Cédric Bosdonnat
de463feb97 virObject-ified virDomainEvent
Added a parent class virObjectEvent for future event types
2013-12-10 12:05:06 +00:00
Cédric Bosdonnat
6893f37682 Created virObjectEventStateRegisterID
Keep virDomainEventStateRegisterID as a convenience wrapper around
this new function.
2013-12-10 11:38:30 +00:00
Cédric Bosdonnat
1ee803e590 Renamed virDomainEventCallbackList* to virObjectEventCallbackList*
Keep the legacy Domain lifecycle event functions as is.
2013-12-10 11:37:07 +00:00
Cédric Bosdonnat
146434efad Renamed virDomainEventState to virObjectEventState
Leave virDomainEventRegister and its Deregister brother as these are
legacy functions only for domain lifecycle events.
2013-12-10 11:35:34 +00:00
Cédric Bosdonnat
df328f9345 Renamed virDomainEventQueue to virObjectEventQueue
The event queue will be generalized to hold events related
to any object type.
2013-12-10 11:33:12 +00:00
Cédric Bosdonnat
9db86c87d7 Renamed virDomainMeta to virObjectMeta
The metadata struct will hold the unique identifiers for
any type of object, though not all fields will be used
for all types.
2013-12-10 11:31:02 +00:00
Cédric Bosdonnat
f95b1921a1 Rename virDomainEventCallback to virObjectEventCallback
The event callbacks will be generalized to handle events
for any object type.
2013-12-10 11:30:24 +00:00
Martin Kletzander
ea130e3bf6 conf: don't format memtune with unlimited values
When changing memtune limits to unlimited with AFFECT_CONFIG, the
values in virDomainDef are set to PARAM_UNLIMITED, which causes the
whole <memtune> to be formatted.  This can be changed in all drivers,
but it also makes sense to use the default (0) as another value for
"unlimited", since zero memory limit makes no sense.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2013-12-10 09:11:26 +01:00