提交 e67e8c54 编写于 作者: P Peter Krempa

qemu: blockjob: Introduce "broken" block job type

To better track jobs we couldn't parse let's introduce a new job type
which will clarify semantics internally in few places.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NCole Robinson <crobinso@redhat.com>
上级 2624c6d2
...@@ -66,7 +66,8 @@ VIR_ENUM_IMPL(qemuBlockjob, ...@@ -66,7 +66,8 @@ VIR_ENUM_IMPL(qemuBlockjob,
"commit", "commit",
"active-commit", "active-commit",
"", "",
"create"); "create",
"broken");
static virClassPtr qemuBlockJobDataClass; static virClassPtr qemuBlockJobDataClass;
...@@ -128,6 +129,23 @@ qemuBlockJobDataNew(qemuBlockJobType type, ...@@ -128,6 +129,23 @@ qemuBlockJobDataNew(qemuBlockJobType type,
} }
/**
* qemuBlockJobMarkBroken:
* @job: job to mark as broken
*
* In case when we are unable to parse the block job data from the XML
* successfully we'll need to mark the job as broken and then attempt to abort
* it. This function marks the job as broken.
*/
static void
qemuBlockJobMarkBroken(qemuBlockJobDataPtr job)
{
qemuBlockJobDataDisposeJobdata(job);
job->brokentype = job->type;
job->type = QEMU_BLOCKJOB_TYPE_BROKEN;
}
/** /**
* qemuBlockJobRegister: * qemuBlockJobRegister:
* @job: job to register * @job: job to register
...@@ -461,6 +479,9 @@ qemuBlockJobRefreshJobs(virQEMUDriverPtr driver, ...@@ -461,6 +479,9 @@ qemuBlockJobRefreshJobs(virQEMUDriverPtr driver,
* in qemu and just forget about it in libvirt because there's not much * in qemu and just forget about it in libvirt because there's not much
* we coud do besides killing the VM */ * we coud do besides killing the VM */
if (job->invalidData) { if (job->invalidData) {
qemuBlockJobMarkBroken(job);
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
rc = qemuMonitorJobCancel(priv->mon, job->name, true); rc = qemuMonitorJobCancel(priv->mon, job->name, true);
...@@ -1255,6 +1276,8 @@ qemuBlockJobEventProcessConcludedTransition(qemuBlockJobDataPtr job, ...@@ -1255,6 +1276,8 @@ qemuBlockJobEventProcessConcludedTransition(qemuBlockJobDataPtr job,
qemuBlockJobProcessEventConcludedCopyAbort(driver, vm, job, asyncJob); qemuBlockJobProcessEventConcludedCopyAbort(driver, vm, job, asyncJob);
break; break;
case QEMU_BLOCKJOB_TYPE_BROKEN:
case QEMU_BLOCKJOB_TYPE_NONE: case QEMU_BLOCKJOB_TYPE_NONE:
case QEMU_BLOCKJOB_TYPE_INTERNAL: case QEMU_BLOCKJOB_TYPE_INTERNAL:
case QEMU_BLOCKJOB_TYPE_LAST: case QEMU_BLOCKJOB_TYPE_LAST:
......
...@@ -63,6 +63,7 @@ typedef enum { ...@@ -63,6 +63,7 @@ typedef enum {
/* Additional enum values local to qemu */ /* Additional enum values local to qemu */
QEMU_BLOCKJOB_TYPE_INTERNAL, QEMU_BLOCKJOB_TYPE_INTERNAL,
QEMU_BLOCKJOB_TYPE_CREATE, QEMU_BLOCKJOB_TYPE_CREATE,
QEMU_BLOCKJOB_TYPE_BROKEN,
QEMU_BLOCKJOB_TYPE_LAST QEMU_BLOCKJOB_TYPE_LAST
} qemuBlockJobType; } qemuBlockJobType;
verify((int)QEMU_BLOCKJOB_TYPE_INTERNAL == VIR_DOMAIN_BLOCK_JOB_TYPE_LAST); verify((int)QEMU_BLOCKJOB_TYPE_INTERNAL == VIR_DOMAIN_BLOCK_JOB_TYPE_LAST);
...@@ -131,6 +132,8 @@ struct _qemuBlockJobData { ...@@ -131,6 +132,8 @@ struct _qemuBlockJobData {
int newstate; /* qemuBlockjobState, subset of events emitted by qemu */ int newstate; /* qemuBlockjobState, subset of events emitted by qemu */
int brokentype; /* the previous type of a broken blockjob qemuBlockJobType */
bool invalidData; /* the job data (except name) is not valid */ bool invalidData; /* the job data (except name) is not valid */
bool reconnected; /* internal field for tracking whether job is live after reconnect to qemu */ bool reconnected; /* internal field for tracking whether job is live after reconnect to qemu */
}; };
......
...@@ -2475,6 +2475,8 @@ qemuDomainObjPrivateXMLFormatBlockjobIterator(void *payload, ...@@ -2475,6 +2475,8 @@ qemuDomainObjPrivateXMLFormatBlockjobIterator(void *payload,
virBufferEscapeString(&attrBuf, " type='%s'", qemuBlockjobTypeToString(job->type)); virBufferEscapeString(&attrBuf, " type='%s'", qemuBlockjobTypeToString(job->type));
virBufferEscapeString(&attrBuf, " state='%s'", state); virBufferEscapeString(&attrBuf, " state='%s'", state);
virBufferEscapeString(&attrBuf, " newstate='%s'", newstate); virBufferEscapeString(&attrBuf, " newstate='%s'", newstate);
if (job->brokentype != QEMU_BLOCKJOB_TYPE_NONE)
virBufferEscapeString(&attrBuf, " brokentype='%s'", qemuBlockjobTypeToString(job->brokentype));
virBufferEscapeString(&childBuf, "<errmsg>%s</errmsg>", job->errmsg); virBufferEscapeString(&childBuf, "<errmsg>%s</errmsg>", job->errmsg);
if (job->disk) { if (job->disk) {
...@@ -2536,6 +2538,8 @@ qemuDomainObjPrivateXMLFormatBlockjobIterator(void *payload, ...@@ -2536,6 +2538,8 @@ qemuDomainObjPrivateXMLFormatBlockjobIterator(void *payload,
virBufferAddLit(&attrBuf, " shallownew='yes'"); virBufferAddLit(&attrBuf, " shallownew='yes'");
break; break;
case QEMU_BLOCKJOB_TYPE_BROKEN:
case QEMU_BLOCKJOB_TYPE_NONE: case QEMU_BLOCKJOB_TYPE_NONE:
case QEMU_BLOCKJOB_TYPE_INTERNAL: case QEMU_BLOCKJOB_TYPE_INTERNAL:
case QEMU_BLOCKJOB_TYPE_LAST: case QEMU_BLOCKJOB_TYPE_LAST:
...@@ -3100,6 +3104,8 @@ qemuDomainObjPrivateXMLParseBlockjobDataSpecific(qemuBlockJobDataPtr job, ...@@ -3100,6 +3104,8 @@ qemuDomainObjPrivateXMLParseBlockjobDataSpecific(qemuBlockJobDataPtr job,
} }
break; break;
case QEMU_BLOCKJOB_TYPE_BROKEN:
case QEMU_BLOCKJOB_TYPE_NONE: case QEMU_BLOCKJOB_TYPE_NONE:
case QEMU_BLOCKJOB_TYPE_INTERNAL: case QEMU_BLOCKJOB_TYPE_INTERNAL:
case QEMU_BLOCKJOB_TYPE_LAST: case QEMU_BLOCKJOB_TYPE_LAST:
...@@ -3125,6 +3131,7 @@ qemuDomainObjPrivateXMLParseBlockjobData(virDomainObjPtr vm, ...@@ -3125,6 +3131,7 @@ qemuDomainObjPrivateXMLParseBlockjobData(virDomainObjPtr vm,
g_autoptr(qemuBlockJobData) job = NULL; g_autoptr(qemuBlockJobData) job = NULL;
g_autofree char *name = NULL; g_autofree char *name = NULL;
g_autofree char *typestr = NULL; g_autofree char *typestr = NULL;
g_autofree char *brokentypestr = NULL;
int type; int type;
g_autofree char *statestr = NULL; g_autofree char *statestr = NULL;
int state = QEMU_BLOCKJOB_STATE_FAILED; int state = QEMU_BLOCKJOB_STATE_FAILED;
...@@ -3146,13 +3153,17 @@ qemuDomainObjPrivateXMLParseBlockjobData(virDomainObjPtr vm, ...@@ -3146,13 +3153,17 @@ qemuDomainObjPrivateXMLParseBlockjobData(virDomainObjPtr vm,
* clean it up */ * clean it up */
if (!(typestr = virXPathString("string(./@type)", ctxt)) || if (!(typestr = virXPathString("string(./@type)", ctxt)) ||
(type = qemuBlockjobTypeFromString(typestr)) < 0) { (type = qemuBlockjobTypeFromString(typestr)) < 0) {
type = QEMU_BLOCKJOB_TYPE_NONE; type = QEMU_BLOCKJOB_TYPE_BROKEN;
invalidData = true; invalidData = true;
} }
if (!(job = qemuBlockJobDataNew(type, name))) if (!(job = qemuBlockJobDataNew(type, name)))
return -1; return -1;
if ((brokentypestr = virXPathString("string(./@brokentype)", ctxt)) &&
(job->brokentype = qemuBlockjobTypeFromString(brokentypestr)) < 0)
job->brokentype = QEMU_BLOCKJOB_TYPE_NONE;
if (!(statestr = virXPathString("string(./@state)", ctxt)) || if (!(statestr = virXPathString("string(./@state)", ctxt)) ||
(state = qemuBlockjobStateTypeFromString(statestr)) < 0) (state = qemuBlockjobStateTypeFromString(statestr)) < 0)
invalidData = true; invalidData = true;
......
...@@ -17418,6 +17418,7 @@ qemuDomainBlockPivot(virQEMUDriverPtr driver, ...@@ -17418,6 +17418,7 @@ qemuDomainBlockPivot(virQEMUDriverPtr driver,
case QEMU_BLOCKJOB_TYPE_COMMIT: case QEMU_BLOCKJOB_TYPE_COMMIT:
case QEMU_BLOCKJOB_TYPE_INTERNAL: case QEMU_BLOCKJOB_TYPE_INTERNAL:
case QEMU_BLOCKJOB_TYPE_CREATE: case QEMU_BLOCKJOB_TYPE_CREATE:
case QEMU_BLOCKJOB_TYPE_BROKEN:
virReportError(VIR_ERR_OPERATION_INVALID, virReportError(VIR_ERR_OPERATION_INVALID,
_("job type '%s' does not support pivot"), _("job type '%s' does not support pivot"),
qemuBlockjobTypeToString(job->type)); qemuBlockjobTypeToString(job->type));
......
...@@ -300,6 +300,7 @@ ...@@ -300,6 +300,7 @@
</source> </source>
</src> </src>
</blockjob> </blockjob>
<blockjob name='broken-test' type='broken' state='ready' brokentype='commit'/>
<blockjob name='test-orphan-job0' type='copy' state='ready'> <blockjob name='test-orphan-job0' type='copy' state='ready'>
<chains> <chains>
<disk type='file' format='qcow2'> <disk type='file' format='qcow2'>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册