[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [RFC PATCH 11/12] qemu: implement qemuDomainSetBlockThreshold



Add code to call the appropriate monitor command and code to lookup the
given disk backing chain member.
---
 src/qemu/qemu_driver.c       | 64 ++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor.c      | 13 +++++++++
 src/qemu/qemu_monitor.h      |  5 ++++
 src/qemu/qemu_monitor_json.c | 31 +++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  6 +++++
 5 files changed, 119 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6e1e3d408..279a0033d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20283,6 +20283,69 @@ qemuDomainSetVcpu(virDomainPtr dom,
 }


+static int
+qemuDomainSetBlockThreshold(virDomainPtr dom,
+                            const char *dev,
+                            unsigned long long threshold,
+                            unsigned int flags)
+{
+    virQEMUDriverPtr driver = dom->conn->privateData;
+    qemuDomainObjPrivatePtr priv;
+    virDomainObjPtr vm = NULL;
+    virStorageSourcePtr src;
+    char *nodename = NULL;
+    int rc;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    if (!(vm = qemuDomObjFromDomain(dom)))
+        goto cleanup;
+
+     priv = vm->privateData;
+
+    if (virDomainSetBlockThresholdEnsureACL(dom->conn, vm->def) < 0)
+        goto cleanup;
+
+    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
+        goto cleanup;
+
+    if (!virDomainObjIsActive(vm)) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("domain is not running"));
+        goto endjob;
+    }
+
+    if (!(src = qemuDomainGetStorageSourceByDevstr(dev, vm->def)))
+        goto endjob;
+
+    if (!src->nodeName) {
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+                       _("threshold currently can't be set for block device '%s'"),
+                       dev);
+        goto endjob;
+    }
+
+    if (VIR_STRDUP(nodename, src->nodeName) < 0)
+        goto endjob;
+
+    qemuDomainObjEnterMonitor(driver, vm);
+    rc = qemuMonitorSetBlockThreshold(priv->mon, nodename, threshold);
+    if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
+        goto endjob;
+
+    ret = 0;
+
+ endjob:
+    qemuDomainObjEndJob(driver, vm);
+
+ cleanup:
+    VIR_FREE(nodename);
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
+
 static virHypervisorDriver qemuHypervisorDriver = {
     .name = QEMU_DRIVER_NAME,
     .connectOpen = qemuConnectOpen, /* 0.2.0 */
@@ -20497,6 +20560,7 @@ static virHypervisorDriver qemuHypervisorDriver = {
     .domainGetGuestVcpus = qemuDomainGetGuestVcpus, /* 2.0.0 */
     .domainSetGuestVcpus = qemuDomainSetGuestVcpus, /* 2.0.0 */
     .domainSetVcpu = qemuDomainSetVcpu, /* 3.1.0 */
+    .domainSetBlockThreshold = qemuDomainSetBlockThreshold /* 3.1.0 */
 };


diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index a8e113f94..7caced7fe 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4150,3 +4150,16 @@ qemuMonitorQueryQMPSchema(qemuMonitorPtr mon)

     return qemuMonitorJSONQueryQMPSchema(mon);
 }
+
+
+int
+qemuMonitorSetBlockThreshold(qemuMonitorPtr mon,
+                             const char *nodename,
+                             unsigned long long threshold)
+{
+    VIR_DEBUG("mon=%p, node='%s', threshold=%llu", mon, nodename, threshold);
+
+    QEMU_CHECK_MONITOR_JSON(mon);
+
+    return qemuMonitorJSONSetBlockThreshold(mon, nodename, threshold);
+}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index a866685e9..ef5c2fdc8 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1047,4 +1047,9 @@ int qemuMonitorGetRTCTime(qemuMonitorPtr mon,

 virHashTablePtr qemuMonitorQueryQMPSchema(qemuMonitorPtr mon);

+int qemuMonitorSetBlockThreshold(qemuMonitorPtr mon,
+                                 const char *nodename,
+                                 unsigned long long threshold);
+
+
 #endif /* QEMU_MONITOR_H */
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index b69d870d3..4b8103195 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -7434,3 +7434,34 @@ qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)

     return ret;
 }
+
+
+int
+qemuMonitorJSONSetBlockThreshold(qemuMonitorPtr mon,
+                                 const char *nodename,
+                                 unsigned long long threshold)
+{
+    virJSONValuePtr cmd;
+    virJSONValuePtr reply = NULL;
+    int ret = -1;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("block-set-write-threshold",
+                                           "s:node-name", nodename,
+                                           "U:write-threshold", threshold,
+                                           NULL)))
+        return -1;
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        goto cleanup;
+
+    if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+
+    return ret;
+}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 79688c82f..0459356b4 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -511,4 +511,10 @@ int qemuMonitorJSONGetHotpluggableCPUs(qemuMonitorPtr mon,

 virHashTablePtr qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon)
     ATTRIBUTE_NONNULL(1);
+
+int qemuMonitorJSONSetBlockThreshold(qemuMonitorPtr mon,
+                                     const char *nodename,
+                                     unsigned long long threshold)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
 #endif /* QEMU_MONITOR_JSON_H */
-- 
2.11.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]