qemu: monitor: Add support for 'job-cancel' command

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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2018-08-16 11:48:41 +02:00
parent 190e66ea5d
commit 1d2e044302
5 changed files with 53 additions and 0 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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,

View File

@ -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);

View File

@ -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);