9119d9
From 1285973505b7c917737cc9bf4eaca08a0617395b Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <1285973505b7c917737cc9bf4eaca08a0617395b@dist-git>
9119d9
From: Pavel Hrdina <phrdina@redhat.com>
9119d9
Date: Fri, 26 Sep 2014 12:44:01 +0200
9119d9
Subject: [PATCH] blkdeviotune: trigger tunable event for blkdeviotune updates
9119d9
9119d9
Use the universal tunable event to report changes to user. All
9119d9
blkdeviotune values are prefixed with "blkdeviotune".
9119d9
9119d9
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
9119d9
(cherry picked from commit 18fc3199c2d45256ae1dd80d855cef9f1ec65118)
9119d9
9119d9
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1115898
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 include/libvirt/libvirt.h.in | 56 ++++++++++++++++++++++++++++++++++++++++++++
9119d9
 src/qemu/qemu_driver.c       | 47 +++++++++++++++++++++++++++++++++++++
9119d9
 2 files changed, 103 insertions(+)
9119d9
9119d9
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
9119d9
index b78f110..026df48 100644
9119d9
--- a/include/libvirt/libvirt.h.in
9119d9
+++ b/include/libvirt/libvirt.h.in
9119d9
@@ -5226,6 +5226,61 @@ typedef void (*virConnectDomainEventDeviceRemovedCallback)(virConnectPtr conn,
9119d9
  */
9119d9
 #define VIR_DOMAIN_EVENT_CPUTUNE_EMULATOR_QUOTA "cputune.emulator_quota"
9119d9
 
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_BLKDEVIOTUNE_DISK:
9119d9
+ *
9119d9
+ * Macro represents the name of guest disk for which the values are updated,
9119d9
+ * as VIR_TYPED_PARAM_STRING.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_BLKDEVIOTUNE_DISK "blkdeviotune.disk"
9119d9
+
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_BLKDEVIOTUNE_TOTAL_BYTES_SEC:
9119d9
+ *
9119d9
+ * Marco represents the total throughput limit in bytes per second,
9119d9
+ * as VIR_TYPED_PARAM_ULLONG.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_BLKDEVIOTUNE_TOTAL_BYTES_SEC "blkdeviotune.total_bytes_sec"
9119d9
+
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_BLKDEVIOTUNE_READ_BYTES_SEC:
9119d9
+ *
9119d9
+ * Marco represents the read throughput limit in bytes per second,
9119d9
+ * as VIR_TYPED_PARAM_ULLONG.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_BLKDEVIOTUNE_READ_BYTES_SEC "blkdeviotune.read_bytes_sec"
9119d9
+
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_BLKDEVIOTUNE_WRITE_BYTES_SEC:
9119d9
+ *
9119d9
+ * Macro represents the write throughput limit in bytes per second,
9119d9
+ * as VIR_TYPED_PARAM_ULLONG.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_BLKDEVIOTUNE_WRITE_BYTES_SEC "blkdeviotune.write_bytes_sec"
9119d9
+
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_BLKDEVIOTUNE_TOTAL_IOPS_SEC:
9119d9
+ *
9119d9
+ * Macro represents the total I/O operations per second,
9119d9
+ * as VIR_TYPED_PARAM_ULLONG.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_BLKDEVIOTUNE_TOTAL_IOPS_SEC "blkdeviotune.total_iops_sec"
9119d9
+
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_BLKDEVIOTUNE_READ_IOPS_SEC:
9119d9
+ *
9119d9
+ * Macro represents the read I/O operations per second,
9119d9
+ * as VIR_TYPED_PARAM_ULLONG.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_BLKDEVIOTUNE_READ_IOPS_SEC "blkdeviotune.read_iops_sec"
9119d9
+
9119d9
+/**
9119d9
+ * VIR_DOMAIN_EVENT_BLKDEVIOTUNE_WRITE_IOPS_SEC:
9119d9
+ *
9119d9
+ * Macro represents the write I/O operations per second,
9119d9
+ * as VIR_TYPED_PARAM_ULLONG.
9119d9
+ */
9119d9
+#define VIR_DOMAIN_EVENT_BLKDEVIOTUNE_WRITE_IOPS_SEC "blkdeviotune.write_iops_sec"
9119d9
 
9119d9
 /**
9119d9
  * virConnectDomainEventTunableCallback:
9119d9
@@ -5241,6 +5296,7 @@ typedef void (*virConnectDomainEventDeviceRemovedCallback)(virConnectPtr conn,
9119d9
  *
9119d9
  * Currently supported name spaces:
9119d9
  *  "cputune.*"
9119d9
+ *  "blkdeviotune.*"
9119d9
  *
9119d9
  * The callback signature to use when registering for an event of type
9119d9
  * VIR_DOMAIN_EVENT_ID_TUNABLE with virConnectDomainEventRegisterAny()
9119d9
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
9119d9
index 663c98d..843101c 100644
9119d9
--- a/src/qemu/qemu_driver.c
9119d9
+++ b/src/qemu/qemu_driver.c
9119d9
@@ -16059,6 +16059,10 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
9119d9
     bool set_iops = false;
9119d9
     virQEMUDriverConfigPtr cfg = NULL;
9119d9
     virCapsPtr caps = NULL;
9119d9
+    virObjectEventPtr event = NULL;
9119d9
+    virTypedParameterPtr eventParams = NULL;
9119d9
+    int eventNparams = 0;
9119d9
+    int eventMaxparams = 0;
9119d9
 
9119d9
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
9119d9
                   VIR_DOMAIN_AFFECT_CONFIG, -1);
9119d9
@@ -16100,6 +16104,10 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
9119d9
                                         &persistentDef) < 0)
9119d9
         goto endjob;
9119d9
 
9119d9
+    if (virTypedParamsAddString(&eventParams, &eventNparams, &eventMaxparams,
9119d9
+                                VIR_DOMAIN_EVENT_BLKDEVIOTUNE_DISK, disk) < 0)
9119d9
+        goto endjob;
9119d9
+
9119d9
     for (i = 0; i < nparams; i++) {
9119d9
         virTypedParameterPtr param = &params[i];
9119d9
 
9119d9
@@ -16113,26 +16121,56 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
9119d9
         if (STREQ(param->field, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC)) {
9119d9
             info.total_bytes_sec = param->value.ul;
9119d9
             set_bytes = true;
9119d9
+            if (virTypedParamsAddULLong(&eventParams, &eventNparams,
9119d9
+                                        &eventMaxparams,
9119d9
+                                        VIR_DOMAIN_EVENT_BLKDEVIOTUNE_TOTAL_BYTES_SEC,
9119d9
+                                        param->value.ul) < 0)
9119d9
+                goto endjob;
9119d9
         } else if (STREQ(param->field,
9119d9
                          VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC)) {
9119d9
             info.read_bytes_sec = param->value.ul;
9119d9
             set_bytes = true;
9119d9
+            if (virTypedParamsAddULLong(&eventParams, &eventNparams,
9119d9
+                                        &eventMaxparams,
9119d9
+                                        VIR_DOMAIN_EVENT_BLKDEVIOTUNE_READ_BYTES_SEC,
9119d9
+                                        param->value.ul) < 0)
9119d9
+                goto endjob;
9119d9
         } else if (STREQ(param->field,
9119d9
                          VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC)) {
9119d9
             info.write_bytes_sec = param->value.ul;
9119d9
             set_bytes = true;
9119d9
+            if (virTypedParamsAddULLong(&eventParams, &eventNparams,
9119d9
+                                        &eventMaxparams,
9119d9
+                                        VIR_DOMAIN_EVENT_BLKDEVIOTUNE_WRITE_BYTES_SEC,
9119d9
+                                        param->value.ul) < 0)
9119d9
+                goto endjob;
9119d9
         } else if (STREQ(param->field,
9119d9
                          VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC)) {
9119d9
             info.total_iops_sec = param->value.ul;
9119d9
             set_iops = true;
9119d9
+            if (virTypedParamsAddULLong(&eventParams, &eventNparams,
9119d9
+                                        &eventMaxparams,
9119d9
+                                        VIR_DOMAIN_EVENT_BLKDEVIOTUNE_TOTAL_IOPS_SEC,
9119d9
+                                        param->value.ul) < 0)
9119d9
+                goto endjob;
9119d9
         } else if (STREQ(param->field,
9119d9
                          VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC)) {
9119d9
             info.read_iops_sec = param->value.ul;
9119d9
             set_iops = true;
9119d9
+            if (virTypedParamsAddULLong(&eventParams, &eventNparams,
9119d9
+                                        &eventMaxparams,
9119d9
+                                        VIR_DOMAIN_EVENT_BLKDEVIOTUNE_READ_IOPS_SEC,
9119d9
+                                        param->value.ul) < 0)
9119d9
+                goto endjob;
9119d9
         } else if (STREQ(param->field,
9119d9
                          VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC)) {
9119d9
             info.write_iops_sec = param->value.ul;
9119d9
             set_iops = true;
9119d9
+            if (virTypedParamsAddULLong(&eventParams, &eventNparams,
9119d9
+                                        &eventMaxparams,
9119d9
+                                        VIR_DOMAIN_EVENT_BLKDEVIOTUNE_WRITE_IOPS_SEC,
9119d9
+                                        param->value.ul) < 0)
9119d9
+                goto endjob;
9119d9
         }
9119d9
     }
9119d9
 
9119d9
@@ -16197,6 +16235,13 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
9119d9
                            _("Saving live XML config failed"));
9119d9
             goto endjob;
9119d9
         }
9119d9
+
9119d9
+        if (eventNparams) {
9119d9
+            event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
9119d9
+            eventNparams = 0;
9119d9
+            if (event)
9119d9
+                qemuDomainEventQueue(driver, event);
9119d9
+        }
9119d9
     }
9119d9
 
9119d9
     if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
9119d9
@@ -16229,6 +16274,8 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
9119d9
     VIR_FREE(device);
9119d9
     if (vm)
9119d9
         virObjectUnlock(vm);
9119d9
+    if (eventNparams)
9119d9
+        virTypedParamsFree(eventParams, eventNparams);
9119d9
     virObjectUnref(caps);
9119d9
     virObjectUnref(cfg);
9119d9
     return ret;
9119d9
-- 
9119d9
2.1.1
9119d9