mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
conf: Rename virDomainHasDiskMirror and detect block jobs properly
virDomainHasDiskMirror() currently detects only jobs that add the mirror elements. Since some operations like migration are interlocked by existing block jobs on the given domain the check needs to be instrumented to check regular jobs too. This patch renames virDomainHasDiskMirror to virDomainHasDiskBlockjob and adds an argument that allows to select that it returns true only for block copy jobs as those interlock making the domain persistent. Other two uses trigger on any block job type. Signed-off-by: Shanzhi Yu <shyu@redhat.com> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
c2a81eb7e1
commit
ffe3d3e886
@ -12277,15 +12277,30 @@ virDomainDiskRemoveByName(virDomainDefPtr def, const char *name)
|
||||
return virDomainDiskRemove(def, idx);
|
||||
}
|
||||
|
||||
/* Return true if VM has at least one disk involved in a current block
|
||||
* copy/commit job (that is, with a <mirror> element in the disk xml). */
|
||||
/**
|
||||
* virDomainHasBlockjob:
|
||||
* @vm: domain object
|
||||
* @copy_only: Reject only block copy job
|
||||
*
|
||||
* Return true if @vm has at least one disk involved in a current block
|
||||
* copy/commit/pull job. If @copy_only is true this returns true only if the
|
||||
* disk is involved in a block copy.
|
||||
* */
|
||||
bool
|
||||
virDomainHasDiskMirror(virDomainObjPtr vm)
|
||||
virDomainHasBlockjob(virDomainObjPtr vm,
|
||||
bool copy_only)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < vm->def->ndisks; i++)
|
||||
if (vm->def->disks[i]->mirror)
|
||||
for (i = 0; i < vm->def->ndisks; i++) {
|
||||
if (!copy_only &&
|
||||
vm->def->disks[i]->blockjob)
|
||||
return true;
|
||||
|
||||
if (vm->def->disks[i]->mirror &&
|
||||
vm->def->disks[i]->mirrorJob == VIR_DOMAIN_BLOCK_JOB_TYPE_COPY)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2660,7 +2660,8 @@ int virDomainDiskSourceParse(xmlNodePtr node,
|
||||
xmlXPathContextPtr ctxt,
|
||||
virStorageSourcePtr src);
|
||||
|
||||
bool virDomainHasDiskMirror(virDomainObjPtr vm);
|
||||
bool virDomainHasBlockjob(virDomainObjPtr vm,
|
||||
bool copy_only);
|
||||
|
||||
int virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net);
|
||||
virDomainNetDefPtr virDomainNetFind(virDomainDefPtr def, const char *device);
|
||||
|
@ -297,7 +297,7 @@ virDomainGraphicsTypeFromString;
|
||||
virDomainGraphicsTypeToString;
|
||||
virDomainGraphicsVNCSharePolicyTypeFromString;
|
||||
virDomainGraphicsVNCSharePolicyTypeToString;
|
||||
virDomainHasDiskMirror;
|
||||
virDomainHasBlockjob;
|
||||
virDomainHasNet;
|
||||
virDomainHostdevCapsTypeToString;
|
||||
virDomainHostdevDefAlloc;
|
||||
|
@ -7387,7 +7387,7 @@ static virDomainPtr qemuDomainDefineXMLFlags(virConnectPtr conn, const char *xml
|
||||
|
||||
virObjectRef(vm);
|
||||
def = NULL;
|
||||
if (virDomainHasDiskMirror(vm)) {
|
||||
if (virDomainHasBlockjob(vm, true)) {
|
||||
virReportError(VIR_ERR_BLOCK_COPY_ACTIVE, "%s",
|
||||
_("domain has active block job"));
|
||||
virDomainObjAssignDef(vm, NULL, false, NULL);
|
||||
@ -15237,8 +15237,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
|
||||
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainHasDiskMirror(vm)) {
|
||||
virReportError(VIR_ERR_BLOCK_COPY_ACTIVE, "%s",
|
||||
if (virDomainHasBlockjob(vm, false)) {
|
||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||
_("domain has active block job"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -1977,7 +1977,7 @@ qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
|
||||
|
||||
}
|
||||
|
||||
if (virDomainHasDiskMirror(vm)) {
|
||||
if (virDomainHasBlockjob(vm, false)) {
|
||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||
_("domain has an active block job"));
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user