mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-26 14:03:49 +03:00
qemu: domainjob: Allow operations if cb is not set in job structure
We should allow resetting / freeing / restoring / parsing / formatting qemuDomainJobObj even if 'cb' attribute is not set. This is theoretical for now, but the attribute must not be always set in the future. It is sufficient to check if 'cb' exists before dereferencing it. This commit partially reverts af16e754cd4efc3ca1. Signed-off-by: Kristina Hanicova <khanicov@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
86dc94fbb6
commit
965f872f92
@ -239,8 +239,10 @@ qemuDomainObjResetAsyncJob(qemuDomainJobObj *job)
|
||||
job->abortJob = false;
|
||||
VIR_FREE(job->error);
|
||||
g_clear_pointer(&job->current, virDomainJobDataFree);
|
||||
job->cb->resetJobPrivate(job->privateData);
|
||||
job->apiFlags = 0;
|
||||
|
||||
if (job->cb)
|
||||
job->cb->resetJobPrivate(job->privateData);
|
||||
}
|
||||
|
||||
int
|
||||
@ -258,7 +260,8 @@ qemuDomainObjRestoreJob(virDomainObj *obj,
|
||||
job->privateData = g_steal_pointer(&priv->job.privateData);
|
||||
job->apiFlags = priv->job.apiFlags;
|
||||
|
||||
if (!(priv->job.privateData = priv->job.cb->allocJobPrivate()))
|
||||
if (priv->job.cb &&
|
||||
!(priv->job.privateData = priv->job.cb->allocJobPrivate()))
|
||||
return -1;
|
||||
job->cb = priv->job.cb;
|
||||
|
||||
@ -270,16 +273,15 @@ qemuDomainObjRestoreJob(virDomainObj *obj,
|
||||
void
|
||||
qemuDomainObjClearJob(qemuDomainJobObj *job)
|
||||
{
|
||||
if (!job->cb)
|
||||
return;
|
||||
|
||||
qemuDomainObjResetJob(job);
|
||||
qemuDomainObjResetAsyncJob(job);
|
||||
g_clear_pointer(&job->privateData, job->cb->freeJobPrivate);
|
||||
g_clear_pointer(&job->current, virDomainJobDataFree);
|
||||
g_clear_pointer(&job->completed, virDomainJobDataFree);
|
||||
virCondDestroy(&job->cond);
|
||||
virCondDestroy(&job->asyncCond);
|
||||
|
||||
if (job->cb)
|
||||
g_clear_pointer(&job->privateData, job->cb->freeJobPrivate);
|
||||
}
|
||||
|
||||
bool
|
||||
@ -1228,7 +1230,8 @@ qemuDomainObjPrivateXMLFormatJob(virBuffer *buf,
|
||||
if (priv->job.asyncJob != QEMU_ASYNC_JOB_NONE)
|
||||
virBufferAsprintf(&attrBuf, " flags='0x%lx'", priv->job.apiFlags);
|
||||
|
||||
if (priv->job.cb->formatJob(&childBuf, &priv->job, vm) < 0)
|
||||
if (priv->job.cb &&
|
||||
priv->job.cb->formatJob(&childBuf, &priv->job, vm) < 0)
|
||||
return -1;
|
||||
|
||||
virXMLFormatElement(buf, "job", &attrBuf, &childBuf);
|
||||
@ -1288,7 +1291,8 @@ qemuDomainObjPrivateXMLParseJob(virDomainObj *vm,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (priv->job.cb->parseJob(ctxt, job, vm) < 0)
|
||||
if (priv->job.cb &&
|
||||
priv->job.cb->parseJob(ctxt, job, vm) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user