[libvirt] [PATCH 09/23] qemu: process: Wire up firing of the VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD event

Peter Krempa posted 23 patches 8 years, 11 months ago
[libvirt] [PATCH 09/23] qemu: process: Wire up firing of the VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD event
Posted by Peter Krempa 8 years, 11 months ago
Bind it to qemus BLOCK_WRITE_THRESHOLD event. Look up the disk by
nodename and construct the string to return.
---
 src/qemu/qemu_process.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index b9c1847bb..d40deea10 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1441,6 +1441,45 @@ qemuProcessHandleAcpiOstInfo(qemuMonitorPtr mon ATTRIBUTE_UNUSED,


 static int
+qemuProcessHandleBlockThreshold(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
+                                virDomainObjPtr vm,
+                                const char *nodename,
+                                unsigned long long threshold,
+                                unsigned long long excess,
+                                void *opaque)
+{
+    virQEMUDriverPtr driver = opaque;
+    virObjectEventPtr event = NULL;
+    virDomainDiskDefPtr disk;
+    virStorageSourcePtr src;
+    unsigned int idx;
+    char *dev = NULL;
+    const char *path = NULL;
+
+    virObjectLock(vm);
+
+    VIR_DEBUG("BLOCK_WRITE_THRESHOLD event for block node '%s' in domain %p %s:"
+              "threshold '%llu' exceeded by '%llu'",
+              nodename, vm, vm->def->name, threshold, excess);
+
+    if ((disk = qemuDomainDiskLookupByNodename(vm->def, nodename, &src, &idx))) {
+        if (virStorageSourceIsLocalStorage(src))
+            path = src->path;
+
+        if ((dev = qemuDomainDiskBackingStoreGetName(disk, src, idx))) {
+            event = virDomainEventBlockThresholdNewFromObj(vm, dev, path,
+                                                           threshold, excess);
+        }
+    }
+
+    virObjectUnlock(vm);
+    qemuDomainEventQueue(driver, event);
+
+    return 0;
+}
+
+
+static int
 qemuProcessHandleNicRxFilterChanged(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
                                     virDomainObjPtr vm,
                                     const char *devAlias,
@@ -1636,6 +1675,7 @@ static qemuMonitorCallbacks monitorCallbacks = {
     .domainMigrationStatus = qemuProcessHandleMigrationStatus,
     .domainMigrationPass = qemuProcessHandleMigrationPass,
     .domainAcpiOstInfo = qemuProcessHandleAcpiOstInfo,
+    .domainBlockThreshold = qemuProcessHandleBlockThreshold,
 };

 static void
-- 
2.12.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 09/23] qemu: process: Wire up firing of the VIR_DOMAIN_EVENT_ID_BLOCK_THRESHOLD event
Posted by Eric Blake 8 years, 10 months ago
On 03/15/2017 11:37 AM, Peter Krempa wrote:
> Bind it to qemus BLOCK_WRITE_THRESHOLD event. Look up the disk by

s/qemus/qemu's/

> nodename and construct the string to return.
> ---
>  src/qemu/qemu_process.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 

>  static int
> +qemuProcessHandleBlockThreshold(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
> +                                virDomainObjPtr vm,
> +                                const char *nodename,
> +                                unsigned long long threshold,
> +                                unsigned long long excess,
> +                                void *opaque)
> +{
> +    virQEMUDriverPtr driver = opaque;
> +    virObjectEventPtr event = NULL;
> +    virDomainDiskDefPtr disk;
> +    virStorageSourcePtr src;
> +    unsigned int idx;
> +    char *dev = NULL;
> +    const char *path = NULL;
> +
> +    virObjectLock(vm);
> +
> +    VIR_DEBUG("BLOCK_WRITE_THRESHOLD event for block node '%s' in domain %p %s:"
> +              "threshold '%llu' exceeded by '%llu'",
> +              nodename, vm, vm->def->name, threshold, excess);
> +
> +    if ((disk = qemuDomainDiskLookupByNodename(vm->def, nodename, &src, &idx))) {
> +        if (virStorageSourceIsLocalStorage(src))
> +            path = src->path;
> +
> +        if ((dev = qemuDomainDiskBackingStoreGetName(disk, src, idx))) {
> +            event = virDomainEventBlockThresholdNewFromObj(vm, dev, path,
> +                                                           threshold, excess);
> +        }
> +    }
> +
> +    virObjectUnlock(vm);
> +    qemuDomainEventQueue(driver, event);
> +
> +    return 0;

Does this leak dev?

Okay, this looks like it fixes my concern on the earlier patch - you are
indeed mapping qemu's node name into a proper XML-related name for the
consumer of the event.

ACK once you fix any leaks.

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

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