This belongs to the new job management API which can manage also
non-block based jobs. Since we'll need to be able to attempt to cancel
jobs which potentially were not started (during reconnect) the 'quiet'
flag allows to suppress errors reported.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
This version allows cancelling jobs quietly which is required for
weird-state cleanup during reconnect.
src/qemu/qemu_monitor.c | 13 +++++++++++++
src/qemu/qemu_monitor.h | 5 +++++
src/qemu/qemu_monitor_json.c | 28 ++++++++++++++++++++++++++++
src/qemu/qemu_monitor_json.h | 5 +++++
tests/qemumonitorjsontest.c | 2 ++
5 files changed, 53 insertions(+)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index d9196434ba..2b9a5426b8 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3475,6 +3475,19 @@ qemuMonitorJobDismiss(qemuMonitorPtr mon,
}
+int
+qemuMonitorJobCancel(qemuMonitorPtr mon,
+ const char *jobname,
+ bool quiet)
+{
+ VIR_DEBUG("jobname='%s' quiet=%d", jobname, quiet);
+
+ QEMU_CHECK_MONITOR(mon);
+
+ return qemuMonitorJSONJobCancel(mon, jobname, quiet);
+}
+
+
int
qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,
const char *drivealias,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 56c68683f5..bed15aea0f 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -991,6 +991,11 @@ int qemuMonitorJobDismiss(qemuMonitorPtr mon,
const char *jobname)
ATTRIBUTE_NONNULL(2);
+int qemuMonitorJobCancel(qemuMonitorPtr mon,
+ const char *jobname,
+ bool quiet)
+ ATTRIBUTE_NONNULL(2);
+
int qemuMonitorOpenGraphics(qemuMonitorPtr mon,
const char *protocol,
int fd,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 2ef2299a68..c318f1620b 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5088,6 +5088,34 @@ qemuMonitorJSONJobDismiss(qemuMonitorPtr mon,
}
+int
+qemuMonitorJSONJobCancel(qemuMonitorPtr mon,
+ const char *jobname,
+ bool quiet)
+{
+ VIR_AUTOPTR(virJSONValue) cmd = NULL;
+ VIR_AUTOPTR(virJSONValue) reply = NULL;
+
+ if (!(cmd = qemuMonitorJSONMakeCommand("job-cancel",
+ "s:id", jobname,
+ NULL)))
+ return -1;
+
+ if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+ return -1;
+
+ if (quiet) {
+ if (virJSONValueObjectHasKey(reply, "error") != 0)
+ return -1;
+ } else {
+ if (qemuMonitorJSONBlockJobError(cmd, reply, jobname) < 0)
+ return -1;
+ }
+
+ return 0;
+}
+
+
int qemuMonitorJSONOpenGraphics(qemuMonitorPtr mon,
const char *protocol,
const char *fdname,
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 1719509ec8..453c2e1af6 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -332,6 +332,11 @@ int qemuMonitorJSONJobDismiss(qemuMonitorPtr mon,
const char *jobname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+int qemuMonitorJSONJobCancel(qemuMonitorPtr mon,
+ const char *jobname,
+ bool quiet)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
int qemuMonitorJSONSetLink(qemuMonitorPtr mon,
const char *name,
virDomainNetInterfaceLinkState state);
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index e872f93490..88dc84a1f1 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1341,6 +1341,7 @@ GEN_TEST_FUNC(qemuMonitorJSONAddBitmap, "node",
"bitmap", true)
GEN_TEST_FUNC(qemuMonitorJSONEnableBitmap, "node", "bitmap")
GEN_TEST_FUNC(qemuMonitorJSONDeleteBitmap, "node", "bitmap")
GEN_TEST_FUNC(qemuMonitorJSONJobDismiss, "jobname")
+GEN_TEST_FUNC(qemuMonitorJSONJobCancel, "jobname", false)
static int
testQemuMonitorJSONqemuMonitorJSONNBDServerStart(const void *opaque)
@@ -3059,6 +3060,7 @@ mymain(void)
DO_TEST_GEN(qemuMonitorJSONEnableBitmap);
DO_TEST_GEN(qemuMonitorJSONDeleteBitmap);
DO_TEST_GEN(qemuMonitorJSONJobDismiss);
+ DO_TEST_GEN(qemuMonitorJSONJobCancel);
DO_TEST(qemuMonitorJSONGetBalloonInfo);
DO_TEST(qemuMonitorJSONGetBlockInfo);
DO_TEST(qemuMonitorJSONGetAllBlockStatsInfo);
--
2.21.0