qemu: monitor: Add support for 'write-blocking' copy mode for blockdev-mirror

Forces the data to be written synchronously to both the original and the
mirrored images which ensures that the job will reach synchronized
phase.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-11-30 20:22:46 +01:00
parent 701c8c2467
commit 7d773a77ff
7 changed files with 22 additions and 10 deletions

View File

@ -15149,7 +15149,8 @@ qemuDomainBlockCopyCommon(virDomainObj *vm,
ret = qemuMonitorBlockdevMirror(priv->mon, job->name, true,
qemuDomainDiskGetTopNodename(disk),
mirror->nodeformat, bandwidth,
granularity, buf_size, mirror_shallow);
granularity, buf_size, mirror_shallow,
false);
} else {
/* qemuMonitorDriveMirror needs to honor the REUSE_EXT flag as specified
* by the user */

View File

@ -959,7 +959,8 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriver *driver,
if (mon_ret == 0)
mon_ret = qemuMonitorBlockdevMirror(qemuDomainGetMonitor(vm), jobname, persistjob,
sourcename, copysrc->nodeformat,
mirror_speed, 0, 0, mirror_shallow);
mirror_speed, 0, 0, mirror_shallow,
false);
if (mon_ret != 0)
qemuBlockStorageSourceAttachRollback(qemuDomainGetMonitor(vm), data);

View File

@ -3058,17 +3058,19 @@ qemuMonitorBlockdevMirror(qemuMonitor *mon,
unsigned long long bandwidth,
unsigned int granularity,
unsigned long long buf_size,
bool shallow)
bool shallow,
bool syncWrite)
{
VIR_DEBUG("jobname=%s, persistjob=%d, device=%s, target=%s, bandwidth=%lld, "
"granularity=%#x, buf_size=%lld, shallow=%d",
"granularity=%#x, buf_size=%lld, shallow=%d syncWrite=%d",
NULLSTR(jobname), persistjob, device, target, bandwidth, granularity,
buf_size, shallow);
buf_size, shallow, syncWrite);
QEMU_CHECK_MONITOR(mon);
return qemuMonitorJSONBlockdevMirror(mon, jobname, persistjob, device, target,
bandwidth, granularity, buf_size, shallow);
bandwidth, granularity, buf_size, shallow,
syncWrite);
}

View File

@ -1079,7 +1079,8 @@ int qemuMonitorBlockdevMirror(qemuMonitor *mon,
unsigned long long bandwidth,
unsigned int granularity,
unsigned long long buf_size,
bool shallow)
bool shallow,
bool syncWrite)
ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5);
int qemuMonitorDrivePivot(qemuMonitor *mon,
const char *jobname)

View File

@ -4305,17 +4305,22 @@ qemuMonitorJSONBlockdevMirror(qemuMonitor *mon,
unsigned long long speed,
unsigned int granularity,
unsigned long long buf_size,
bool shallow)
bool shallow,
bool syncWrite)
{
g_autoptr(virJSONValue) cmd = NULL;
g_autoptr(virJSONValue) reply = NULL;
virTristateBool autofinalize = VIR_TRISTATE_BOOL_ABSENT;
virTristateBool autodismiss = VIR_TRISTATE_BOOL_ABSENT;
const char *syncmode = "full";
const char *copymode = NULL;
if (shallow)
syncmode = "top";
if (syncWrite)
copymode = "write-blocking";
if (persistjob) {
autofinalize = VIR_TRISTATE_BOOL_YES;
autodismiss = VIR_TRISTATE_BOOL_NO;
@ -4329,6 +4334,7 @@ qemuMonitorJSONBlockdevMirror(qemuMonitor *mon,
"z:granularity", granularity,
"P:buf-size", buf_size,
"s:sync", syncmode,
"S:copy-mode", copymode,
"T:auto-finalize", autofinalize,
"T:auto-dismiss", autodismiss,
NULL);

View File

@ -266,7 +266,8 @@ int qemuMonitorJSONBlockdevMirror(qemuMonitor *mon,
unsigned long long speed,
unsigned int granularity,
unsigned long long buf_size,
bool shallow)
bool shallow,
bool syncWrite)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5);
int qemuMonitorJSONDrivePivot(qemuMonitor *mon,
const char *jobname)

View File

@ -1175,7 +1175,7 @@ GEN_TEST_FUNC(qemuMonitorJSONGraphicsRelocate, VIR_DOMAIN_GRAPHICS_TYPE_SPICE,
GEN_TEST_FUNC(qemuMonitorJSONRemoveNetdev, "net0")
GEN_TEST_FUNC(qemuMonitorJSONDelDevice, "ide0")
GEN_TEST_FUNC(qemuMonitorJSONDriveMirror, "vdb", "/foo/bar", "formatstr", 1024, 1234, 31234, true, true)
GEN_TEST_FUNC(qemuMonitorJSONBlockdevMirror, "jobname", true, "vdb", "targetnode", 1024, 1234, 31234, true)
GEN_TEST_FUNC(qemuMonitorJSONBlockdevMirror, "jobname", true, "vdb", "targetnode", 1024, 1234, 31234, true, true)
GEN_TEST_FUNC(qemuMonitorJSONBlockStream, "vdb", "jobname", true, "/foo/bar1", "backingnode", "backingfilename", 1024)
GEN_TEST_FUNC(qemuMonitorJSONBlockCommit, "vdb", "jobname", true, "/foo/bar1", "topnode", "/foo/bar2", "basenode", "backingfilename", 1024)
GEN_TEST_FUNC(qemuMonitorJSONDrivePivot, "vdb")