提交 ffe3d3e8 编写于 作者: S Shanzhi Yu 提交者: Peter Krempa

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: NShanzhi Yu <shyu@redhat.com>
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
上级 c2a81eb7
...@@ -12277,15 +12277,30 @@ virDomainDiskRemoveByName(virDomainDefPtr def, const char *name) ...@@ -12277,15 +12277,30 @@ virDomainDiskRemoveByName(virDomainDefPtr def, const char *name)
return virDomainDiskRemove(def, idx); 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 bool
virDomainHasDiskMirror(virDomainObjPtr vm) virDomainHasBlockjob(virDomainObjPtr vm,
bool copy_only)
{ {
size_t i; size_t i;
for (i = 0; i < vm->def->ndisks; i++) for (i = 0; i < vm->def->ndisks; i++) {
if (vm->def->disks[i]->mirror) 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 true;
}
return false; return false;
} }
......
...@@ -2660,7 +2660,8 @@ int virDomainDiskSourceParse(xmlNodePtr node, ...@@ -2660,7 +2660,8 @@ int virDomainDiskSourceParse(xmlNodePtr node,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
virStorageSourcePtr src); virStorageSourcePtr src);
bool virDomainHasDiskMirror(virDomainObjPtr vm); bool virDomainHasBlockjob(virDomainObjPtr vm,
bool copy_only);
int virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net); int virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net);
virDomainNetDefPtr virDomainNetFind(virDomainDefPtr def, const char *device); virDomainNetDefPtr virDomainNetFind(virDomainDefPtr def, const char *device);
......
...@@ -297,7 +297,7 @@ virDomainGraphicsTypeFromString; ...@@ -297,7 +297,7 @@ virDomainGraphicsTypeFromString;
virDomainGraphicsTypeToString; virDomainGraphicsTypeToString;
virDomainGraphicsVNCSharePolicyTypeFromString; virDomainGraphicsVNCSharePolicyTypeFromString;
virDomainGraphicsVNCSharePolicyTypeToString; virDomainGraphicsVNCSharePolicyTypeToString;
virDomainHasDiskMirror; virDomainHasBlockjob;
virDomainHasNet; virDomainHasNet;
virDomainHostdevCapsTypeToString; virDomainHostdevCapsTypeToString;
virDomainHostdevDefAlloc; virDomainHostdevDefAlloc;
......
...@@ -7387,7 +7387,7 @@ static virDomainPtr qemuDomainDefineXMLFlags(virConnectPtr conn, const char *xml ...@@ -7387,7 +7387,7 @@ static virDomainPtr qemuDomainDefineXMLFlags(virConnectPtr conn, const char *xml
virObjectRef(vm); virObjectRef(vm);
def = NULL; def = NULL;
if (virDomainHasDiskMirror(vm)) { if (virDomainHasBlockjob(vm, true)) {
virReportError(VIR_ERR_BLOCK_COPY_ACTIVE, "%s", virReportError(VIR_ERR_BLOCK_COPY_ACTIVE, "%s",
_("domain has active block job")); _("domain has active block job"));
virDomainObjAssignDef(vm, NULL, false, NULL); virDomainObjAssignDef(vm, NULL, false, NULL);
...@@ -15237,8 +15237,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, ...@@ -15237,8 +15237,8 @@ qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
if (!(caps = virQEMUDriverGetCapabilities(driver, false))) if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup; goto cleanup;
if (virDomainHasDiskMirror(vm)) { if (virDomainHasBlockjob(vm, false)) {
virReportError(VIR_ERR_BLOCK_COPY_ACTIVE, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("domain has active block job")); _("domain has active block job"));
goto cleanup; goto cleanup;
} }
......
...@@ -1977,7 +1977,7 @@ qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm, ...@@ -1977,7 +1977,7 @@ qemuMigrationIsAllowed(virQEMUDriverPtr driver, virDomainObjPtr vm,
} }
if (virDomainHasDiskMirror(vm)) { if (virDomainHasBlockjob(vm, false)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("domain has an active block job")); _("domain has an active block job"));
return false; return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册