mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
qemu: Switch context for job related private XML parsing
Having to repeat "./job[1]/" XPath prefix for every single element or attribute we want to parse is suboptimal. And even more so once we further extract code from qemuDomainObjPrivateXMLParseJob into separate functions. Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
This commit is contained in:
parent
0a3a96b5c3
commit
6c2e34e1a7
@ -2332,12 +2332,18 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
|
|||||||
xmlXPathContextPtr ctxt)
|
xmlXPathContextPtr ctxt)
|
||||||
{
|
{
|
||||||
xmlNodePtr *nodes = NULL;
|
xmlNodePtr *nodes = NULL;
|
||||||
|
xmlNodePtr savedNode = ctxt->node;
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
int n;
|
int n;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if ((tmp = virXPathString("string(./job[1]/@type)", ctxt))) {
|
if (!(ctxt->node = virXPathNode("./job[1]", ctxt))) {
|
||||||
|
ret = 0;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((tmp = virXPathString("string(@type)", ctxt))) {
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
if ((type = qemuDomainJobTypeFromString(tmp)) < 0) {
|
if ((type = qemuDomainJobTypeFromString(tmp)) < 0) {
|
||||||
@ -2349,7 +2355,7 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
|
|||||||
priv->job.active = type;
|
priv->job.active = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((tmp = virXPathString("string(./job[1]/@async)", ctxt))) {
|
if ((tmp = virXPathString("string(@async)", ctxt))) {
|
||||||
int async;
|
int async;
|
||||||
|
|
||||||
if ((async = qemuDomainAsyncJobTypeFromString(tmp)) < 0) {
|
if ((async = qemuDomainAsyncJobTypeFromString(tmp)) < 0) {
|
||||||
@ -2360,7 +2366,7 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
|
|||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
priv->job.asyncJob = async;
|
priv->job.asyncJob = async;
|
||||||
|
|
||||||
if ((tmp = virXPathString("string(./job[1]/@phase)", ctxt))) {
|
if ((tmp = virXPathString("string(@phase)", ctxt))) {
|
||||||
priv->job.phase = qemuDomainAsyncJobPhaseFromString(async, tmp);
|
priv->job.phase = qemuDomainAsyncJobPhaseFromString(async, tmp);
|
||||||
if (priv->job.phase < 0) {
|
if (priv->job.phase < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -2371,7 +2377,7 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((n = virXPathNodeSet("./job[1]/disk[@migrating='yes']", ctxt, &nodes)) < 0)
|
if ((n = virXPathNodeSet("./disk[@migrating='yes']", ctxt, &nodes)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
@ -2394,6 +2400,7 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
ctxt->node = savedNode;
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user