Use more of VIR_XPATH_NODE_AUTORESTORE

This is convenience macro, use it more. This commit was generated
using the following spatch:

  @@
  symbol node;
  identifier old;
  identifier ctxt;
  type xmlNodePtr;
  @@
  - xmlNodePtr old;
  + VIR_XPATH_NODE_AUTORESTORE(ctxt);
    ...
  - old = ctxt->node;
    ... when != old
  - ctxt->node = old;

  @@
  symbol node;
  identifier old;
  identifier ctxt;
  type xmlNodePtr;
  @@
  - xmlNodePtr old = ctxt->node;
  + VIR_XPATH_NODE_AUTORESTORE(ctxt);
    ... when != old
  - ctxt->node = old;

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2020-06-02 22:06:41 +02:00
parent 52351030a4
commit d3a7479c0b
18 changed files with 51 additions and 137 deletions

View File

@ -326,7 +326,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
{ {
virCPUDefPtr def = NULL; virCPUDefPtr def = NULL;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
xmlNodePtr oldnode = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
int n; int n;
size_t i; size_t i;
char *cpuMode; char *cpuMode;
@ -662,7 +662,6 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
cleanup: cleanup:
ctxt->node = oldnode;
VIR_FREE(fallback); VIR_FREE(fallback);
VIR_FREE(vendor_id); VIR_FREE(vendor_id);
VIR_FREE(nodes); VIR_FREE(nodes);

View File

@ -13265,16 +13265,14 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
/* Check for an optional seclabel override in <source/>. */ /* Check for an optional seclabel override in <source/>. */
if (chr_def) { if (chr_def) {
xmlNodePtr saved_node = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
ctxt->node = cur; ctxt->node = cur;
if (virSecurityDeviceLabelDefParseXML(&def->seclabels, if (virSecurityDeviceLabelDefParseXML(&def->seclabels,
&def->nseclabels, &def->nseclabels,
ctxt, ctxt,
flags) < 0) { flags) < 0) {
ctxt->node = saved_node;
goto error; goto error;
} }
ctxt->node = saved_node;
} }
} else if (virXMLNodeNameEqual(cur, "log")) { } else if (virXMLNodeNameEqual(cur, "log")) {
if (logParsed) { if (logParsed) {
@ -22181,11 +22179,10 @@ virDomainDefParseXML(xmlDocPtr xml,
} }
if ((node = virXPathNode("./sysinfo[1]", ctxt)) != NULL) { if ((node = virXPathNode("./sysinfo[1]", ctxt)) != NULL) {
xmlNodePtr oldnode = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
ctxt->node = node; ctxt->node = node;
def->sysinfo = virSysinfoParseXML(node, ctxt, def->sysinfo = virSysinfoParseXML(node, ctxt,
def->uuid, uuid_generated); def->uuid, uuid_generated);
ctxt->node = oldnode;
if (def->sysinfo == NULL) if (def->sysinfo == NULL)
goto error; goto error;

View File

@ -262,12 +262,11 @@ static int
virInterfaceDefParseDhcp(virInterfaceProtocolDefPtr def, virInterfaceDefParseDhcp(virInterfaceProtocolDefPtr def,
xmlNodePtr dhcp, xmlXPathContextPtr ctxt) xmlNodePtr dhcp, xmlXPathContextPtr ctxt)
{ {
xmlNodePtr save; VIR_XPATH_NODE_AUTORESTORE(ctxt);
char *tmp; char *tmp;
int ret = 0; int ret = 0;
def->dhcp = 1; def->dhcp = 1;
save = ctxt->node;
ctxt->node = dhcp; ctxt->node = dhcp;
def->peerdns = -1; def->peerdns = -1;
/* Not much to do in the current version */ /* Not much to do in the current version */
@ -284,7 +283,6 @@ virInterfaceDefParseDhcp(virInterfaceProtocolDefPtr def,
VIR_FREE(tmp); VIR_FREE(tmp);
} }
ctxt->node = save;
return ret; return ret;
} }
@ -426,13 +424,11 @@ static int
virInterfaceDefParseIfAdressing(virInterfaceDefPtr def, virInterfaceDefParseIfAdressing(virInterfaceDefPtr def,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
xmlNodePtr save; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr *protoNodes = NULL; xmlNodePtr *protoNodes = NULL;
int nProtoNodes, pp, ret = -1; int nProtoNodes, pp, ret = -1;
char *tmp; char *tmp;
save = ctxt->node;
nProtoNodes = virXPathNodeSet("./protocol", ctxt, &protoNodes); nProtoNodes = virXPathNodeSet("./protocol", ctxt, &protoNodes);
if (nProtoNodes < 0) if (nProtoNodes < 0)
goto error; goto error;
@ -487,7 +483,6 @@ virInterfaceDefParseIfAdressing(virInterfaceDefPtr def,
error: error:
VIR_FREE(protoNodes); VIR_FREE(protoNodes);
ctxt->node = save;
return ret; return ret;
} }
@ -558,7 +553,7 @@ virInterfaceDefParseBondItfs(virInterfaceDefPtr def,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
xmlNodePtr *interfaces = NULL; xmlNodePtr *interfaces = NULL;
xmlNodePtr bond = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
virInterfaceDefPtr itf; virInterfaceDefPtr itf;
int nbItf; int nbItf;
size_t i; size_t i;
@ -591,7 +586,6 @@ virInterfaceDefParseBondItfs(virInterfaceDefPtr def,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(interfaces); VIR_FREE(interfaces);
ctxt->node = bond;
return ret; return ret;
} }
@ -698,7 +692,7 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt,
virInterfaceDefPtr def; virInterfaceDefPtr def;
int type; int type;
char *tmp; char *tmp;
xmlNodePtr cur = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr lnk; xmlNodePtr lnk;
@ -804,11 +798,9 @@ virInterfaceDefParseXML(xmlXPathContextPtr ctxt,
} }
ctxt->node = cur;
return def; return def;
error: error:
ctxt->node = cur;
virInterfaceDefFree(def); virInterfaceDefFree(def);
return NULL; return NULL;
} }

View File

@ -33,7 +33,7 @@ int
virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr def) virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr def)
{ {
int ret = -1; int ret = -1;
xmlNodePtr save = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
char *trunk = NULL; char *trunk = NULL;
char *nativeMode = NULL; char *nativeMode = NULL;
xmlNodePtr *tagNodes = NULL; xmlNodePtr *tagNodes = NULL;
@ -128,7 +128,6 @@ virNetDevVlanParse(xmlNodePtr node, xmlXPathContextPtr ctxt, virNetDevVlanPtr de
ret = 0; ret = 0;
cleanup: cleanup:
ctxt->node = save;
VIR_FREE(tagNodes); VIR_FREE(tagNodes);
VIR_FREE(trunk); VIR_FREE(trunk);
VIR_FREE(nativeMode); VIR_FREE(nativeMode);

View File

@ -800,7 +800,7 @@ virNetworkDNSSrvDefParseXML(const char *networkName,
bool partialOkay) bool partialOkay)
{ {
int ret; int ret;
xmlNodePtr save_ctxt = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
ctxt->node = node; ctxt->node = node;
@ -895,12 +895,10 @@ virNetworkDNSSrvDefParseXML(const char *networkName,
goto error; goto error;
} }
ctxt->node = save_ctxt;
return 0; return 0;
error: error:
virNetworkDNSSrvDefClear(def); virNetworkDNSSrvDefClear(def);
ctxt->node = save_ctxt;
return -1; return -1;
} }
@ -961,7 +959,7 @@ virNetworkDNSDefParseXML(const char *networkName,
int nhosts, nsrvs, ntxts, nfwds; int nhosts, nsrvs, ntxts, nfwds;
size_t i; size_t i;
int ret = -1; int ret = -1;
xmlNodePtr save = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
ctxt->node = node; ctxt->node = node;
@ -1100,7 +1098,6 @@ virNetworkDNSDefParseXML(const char *networkName,
VIR_FREE(hostNodes); VIR_FREE(hostNodes);
VIR_FREE(srvNodes); VIR_FREE(srvNodes);
VIR_FREE(txtNodes); VIR_FREE(txtNodes);
ctxt->node = save;
return ret; return ret;
} }
@ -1116,7 +1113,7 @@ virNetworkIPDefParseXML(const char *networkName,
* On failure clear it out, but don't free it. * On failure clear it out, but don't free it.
*/ */
xmlNodePtr save; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr dhcp; xmlNodePtr dhcp;
char *address = NULL, *netmask = NULL; char *address = NULL, *netmask = NULL;
unsigned long prefix = 0; unsigned long prefix = 0;
@ -1124,7 +1121,6 @@ virNetworkIPDefParseXML(const char *networkName,
int result = -1; int result = -1;
char *localPtr = NULL; char *localPtr = NULL;
save = ctxt->node;
ctxt->node = node; ctxt->node = node;
/* grab raw data from XML */ /* grab raw data from XML */
@ -1256,7 +1252,6 @@ virNetworkIPDefParseXML(const char *networkName,
VIR_FREE(netmask); VIR_FREE(netmask);
VIR_FREE(localPtr); VIR_FREE(localPtr);
ctxt->node = save;
return result; return result;
} }
@ -1291,7 +1286,7 @@ virNetworkPortGroupParseXML(virPortGroupDefPtr def,
* On failure clear it out, but don't free it. * On failure clear it out, but don't free it.
*/ */
xmlNodePtr save; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr virtPortNode; xmlNodePtr virtPortNode;
xmlNodePtr vlanNode; xmlNodePtr vlanNode;
xmlNodePtr bandwidth_node; xmlNodePtr bandwidth_node;
@ -1300,7 +1295,6 @@ virNetworkPortGroupParseXML(virPortGroupDefPtr def,
int result = -1; int result = -1;
save = ctxt->node;
ctxt->node = node; ctxt->node = node;
/* grab raw data from XML */ /* grab raw data from XML */
@ -1348,7 +1342,6 @@ virNetworkPortGroupParseXML(virPortGroupDefPtr def,
VIR_FREE(isDefault); VIR_FREE(isDefault);
VIR_FREE(trustGuestRxFilters); VIR_FREE(trustGuestRxFilters);
ctxt->node = save;
return result; return result;
} }
@ -1365,7 +1358,7 @@ virNetworkForwardNatDefParseXML(const char *networkName,
int nNatAddrs, nNatPorts; int nNatAddrs, nNatPorts;
char *addrStart = NULL; char *addrStart = NULL;
char *addrEnd = NULL; char *addrEnd = NULL;
xmlNodePtr save = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
ctxt->node = node; ctxt->node = node;
@ -1477,7 +1470,6 @@ virNetworkForwardNatDefParseXML(const char *networkName,
VIR_FREE(addrEnd); VIR_FREE(addrEnd);
VIR_FREE(natAddrNodes); VIR_FREE(natAddrNodes);
VIR_FREE(natPortNodes); VIR_FREE(natPortNodes);
ctxt->node = save;
return ret; return ret;
} }
@ -1499,7 +1491,7 @@ virNetworkForwardDefParseXML(const char *networkName,
char *forwardManaged = NULL; char *forwardManaged = NULL;
char *forwardDriverName = NULL; char *forwardDriverName = NULL;
char *type = NULL; char *type = NULL;
xmlNodePtr save = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
ctxt->node = node; ctxt->node = node;
@ -1726,7 +1718,6 @@ virNetworkForwardDefParseXML(const char *networkName,
VIR_FREE(forwardIfNodes); VIR_FREE(forwardIfNodes);
VIR_FREE(forwardAddrNodes); VIR_FREE(forwardAddrNodes);
VIR_FREE(forwardNatNodes); VIR_FREE(forwardNatNodes);
ctxt->node = save;
return ret; return ret;
} }
@ -1747,7 +1738,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr forwardNode = NULL; xmlNodePtr forwardNode = NULL;
char *ipv6nogwStr = NULL; char *ipv6nogwStr = NULL;
char *trustGuestRxFilters = NULL; char *trustGuestRxFilters = NULL;
xmlNodePtr save = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr bandwidthNode = NULL; xmlNodePtr bandwidthNode = NULL;
xmlNodePtr vlanNode; xmlNodePtr vlanNode;
xmlNodePtr metadataNode = NULL; xmlNodePtr metadataNode = NULL;
@ -2164,7 +2155,6 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
goto error; goto error;
} }
ctxt->node = save;
return def; return def;
error: error:
@ -2176,7 +2166,6 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
VIR_FREE(portGroupNodes); VIR_FREE(portGroupNodes);
VIR_FREE(ipv6nogwStr); VIR_FREE(ipv6nogwStr);
VIR_FREE(trustGuestRxFilters); VIR_FREE(trustGuestRxFilters);
ctxt->node = save;
return NULL; return NULL;
} }

View File

@ -228,7 +228,7 @@ virNetDevIPRouteParseXML(const char *errorDetail,
*/ */
virNetDevIPRoutePtr def = NULL; virNetDevIPRoutePtr def = NULL;
xmlNodePtr save; VIR_XPATH_NODE_AUTORESTORE(ctxt);
char *family = NULL; char *family = NULL;
char *address = NULL, *netmask = NULL; char *address = NULL, *netmask = NULL;
char *gateway = NULL; char *gateway = NULL;
@ -237,7 +237,6 @@ virNetDevIPRouteParseXML(const char *errorDetail,
bool hasPrefix = false; bool hasPrefix = false;
bool hasMetric = false; bool hasMetric = false;
save = ctxt->node;
ctxt->node = node; ctxt->node = node;
/* grab raw data from XML */ /* grab raw data from XML */
@ -278,7 +277,6 @@ virNetDevIPRouteParseXML(const char *errorDetail,
hasMetric); hasMetric);
cleanup: cleanup:
ctxt->node = save;
VIR_FREE(family); VIR_FREE(family);
VIR_FREE(address); VIR_FREE(address);
VIR_FREE(netmask); VIR_FREE(netmask);

View File

@ -703,11 +703,10 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapDRMPtr drm) virNodeDevCapDRMPtr drm)
{ {
xmlNodePtr orignode; VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1, val; int ret = -1, val;
char *type = NULL; char *type = NULL;
orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
type = virXPathString("string(./type[1])", ctxt); type = virXPathString("string(./type[1])", ctxt);
@ -723,7 +722,6 @@ virNodeDevCapDRMParseXML(xmlXPathContextPtr ctxt,
out: out:
VIR_FREE(type); VIR_FREE(type);
ctxt->node = orignode;
return ret; return ret;
} }
@ -734,11 +732,10 @@ virNodeDevCapCCWParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapCCWPtr ccw_dev) virNodeDevCapCCWPtr ccw_dev)
{ {
xmlNodePtr orignode; VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1; int ret = -1;
char *cssid = NULL, *ssid = NULL, *devno = NULL; char *cssid = NULL, *ssid = NULL, *devno = NULL;
orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
if (!(cssid = virXPathString("string(./cssid[1])", ctxt))) { if (!(cssid = virXPathString("string(./cssid[1])", ctxt))) {
@ -783,7 +780,6 @@ virNodeDevCapCCWParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
out: out:
ctxt->node = orignode;
VIR_FREE(cssid); VIR_FREE(cssid);
VIR_FREE(ssid); VIR_FREE(ssid);
VIR_FREE(devno); VIR_FREE(devno);
@ -797,12 +793,12 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapStoragePtr storage) virNodeDevCapStoragePtr storage)
{ {
xmlNodePtr orignode, *nodes = NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr *nodes = NULL;
size_t i; size_t i;
int n, ret = -1; int n, ret = -1;
unsigned long long val; unsigned long long val;
orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
storage->block = virXPathString("string(./block[1])", ctxt); storage->block = virXPathString("string(./block[1])", ctxt);
@ -851,7 +847,6 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
if (virNodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def, if (virNodeDevCapsDefParseULongLong("number(./media_size[1])", ctxt, &val, def,
_("no removable media size supplied for '%s'"), _("no removable media size supplied for '%s'"),
_("invalid removable media size supplied for '%s'")) < 0) { _("invalid removable media size supplied for '%s'")) < 0) {
ctxt->node = orignode2;
VIR_FREE(type); VIR_FREE(type);
goto out; goto out;
} }
@ -881,7 +876,6 @@ virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
out: out:
VIR_FREE(nodes); VIR_FREE(nodes);
ctxt->node = orignode;
return ret; return ret;
} }
@ -892,10 +886,9 @@ virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapSCSIPtr scsi) virNodeDevCapSCSIPtr scsi)
{ {
xmlNodePtr orignode; VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1; int ret = -1;
orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./host[1])", ctxt,
@ -926,7 +919,6 @@ virNodeDevCapSCSIParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
out: out:
ctxt->node = orignode;
return ret; return ret;
} }
@ -937,12 +929,12 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapSCSITargetPtr scsi_target) virNodeDevCapSCSITargetPtr scsi_target)
{ {
xmlNodePtr orignode, *nodes = NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr *nodes = NULL;
int ret = -1, n = 0; int ret = -1, n = 0;
size_t i; size_t i;
char *type = NULL; char *type = NULL;
orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
scsi_target->name = virXPathString("string(./target[1])", ctxt); scsi_target->name = virXPathString("string(./target[1])", ctxt);
@ -967,11 +959,8 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt,
} }
if (STREQ(type, "fc_remote_port")) { if (STREQ(type, "fc_remote_port")) {
xmlNodePtr orignode2;
scsi_target->flags |= VIR_NODE_DEV_CAP_FLAG_FC_RPORT; scsi_target->flags |= VIR_NODE_DEV_CAP_FLAG_FC_RPORT;
orignode2 = ctxt->node;
ctxt->node = nodes[i]; ctxt->node = nodes[i];
if (virNodeDevCapsDefParseString("string(./rport[1])", if (virNodeDevCapsDefParseString("string(./rport[1])",
@ -989,8 +978,6 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt,
def->name); def->name);
goto out; goto out;
} }
ctxt->node = orignode2;
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown SCSI target capability type '%s' for '%s'"), _("unknown SCSI target capability type '%s' for '%s'"),
@ -1004,7 +991,6 @@ virNodeDevCapSCSITargetParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
out: out:
ctxt->node = orignode;
VIR_FREE(type); VIR_FREE(type);
VIR_FREE(nodes); VIR_FREE(nodes);
return ret; return ret;
@ -1019,12 +1005,12 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
int create, int create,
const char *virt_type) const char *virt_type)
{ {
xmlNodePtr orignode, *nodes = NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr *nodes = NULL;
int ret = -1, n = 0; int ret = -1, n = 0;
size_t i; size_t i;
char *type = NULL; char *type = NULL;
orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
if (create == EXISTING_DEVICE) { if (create == EXISTING_DEVICE) {
@ -1061,12 +1047,8 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS; scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS;
} else if (STREQ(type, "fc_host")) { } else if (STREQ(type, "fc_host")) {
xmlNodePtr orignode2;
scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST; scsi_host->flags |= VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST;
orignode2 = ctxt->node;
ctxt->node = nodes[i]; ctxt->node = nodes[i];
if (virNodeDevCapsDefParseString("string(./wwnn[1])", if (virNodeDevCapsDefParseString("string(./wwnn[1])",
@ -1098,8 +1080,6 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
&scsi_host->fabric_wwn) < 0) &scsi_host->fabric_wwn) < 0)
VIR_DEBUG("No fabric_wwn defined for '%s'", def->name); VIR_DEBUG("No fabric_wwn defined for '%s'", def->name);
ctxt->node = orignode2;
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown SCSI host capability type '%s' for '%s'"), _("unknown SCSI host capability type '%s' for '%s'"),
@ -1114,7 +1094,6 @@ virNodeDevCapSCSIHostParseXML(xmlXPathContextPtr ctxt,
out: out:
VIR_FREE(type); VIR_FREE(type);
ctxt->node = orignode;
VIR_FREE(nodes); VIR_FREE(nodes);
return ret; return ret;
} }
@ -1126,13 +1105,13 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapNetPtr net) virNodeDevCapNetPtr net)
{ {
xmlNodePtr orignode, lnk; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr lnk;
size_t i = -1; size_t i = -1;
int ret = -1, n = -1; int ret = -1, n = -1;
char *tmp = NULL; char *tmp = NULL;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
net->ifname = virXPathString("string(./interface[1])", ctxt); net->ifname = virXPathString("string(./interface[1])", ctxt);
@ -1192,7 +1171,6 @@ virNodeDevCapNetParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
out: out:
ctxt->node = orignode;
VIR_FREE(nodes); VIR_FREE(nodes);
VIR_FREE(tmp); VIR_FREE(tmp);
return ret; return ret;
@ -1205,10 +1183,9 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapUSBIfPtr usb_if) virNodeDevCapUSBIfPtr usb_if)
{ {
xmlNodePtr orignode; VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1; int ret = -1;
orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
if (virNodeDevCapsDefParseULong("number(./number[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./number[1])", ctxt,
@ -1239,7 +1216,6 @@ virNodeDevCapUSBInterfaceParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
out: out:
ctxt->node = orignode;
return ret; return ret;
} }
@ -1274,10 +1250,9 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapUSBDevPtr usb_dev) virNodeDevCapUSBDevPtr usb_dev)
{ {
xmlNodePtr orignode; VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1; int ret = -1;
orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt, if (virNodeDevCapsDefParseULong("number(./bus[1])", ctxt,
@ -1309,7 +1284,6 @@ virNodeDevCapUSBDevParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
out: out:
ctxt->node = orignode;
return ret; return ret;
} }
@ -1319,7 +1293,7 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr iommuGroupNode, xmlNodePtr iommuGroupNode,
virNodeDevCapPCIDevPtr pci_dev) virNodeDevCapPCIDevPtr pci_dev)
{ {
xmlNodePtr origNode = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr *addrNodes = NULL; xmlNodePtr *addrNodes = NULL;
char *numberStr = NULL; char *numberStr = NULL;
int nAddrNodes, ret = -1; int nAddrNodes, ret = -1;
@ -1363,7 +1337,6 @@ virNodeDevCapPCIDevIommuGroupParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
cleanup: cleanup:
ctxt->node = origNode;
VIR_FREE(numberStr); VIR_FREE(numberStr);
VIR_FREE(addrNodes); VIR_FREE(addrNodes);
VIR_FREE(pciAddr); VIR_FREE(pciAddr);
@ -1376,7 +1349,7 @@ virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr linkNode, xmlNodePtr linkNode,
virPCIELinkPtr lnk) virPCIELinkPtr lnk)
{ {
xmlNodePtr origNode = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1, speed; int ret = -1, speed;
char *speedStr = NULL, *portStr = NULL; char *speedStr = NULL, *portStr = NULL;
@ -1413,7 +1386,6 @@ virPCIEDeviceInfoLinkParseXML(xmlXPathContextPtr ctxt,
cleanup: cleanup:
VIR_FREE(portStr); VIR_FREE(portStr);
VIR_FREE(speedStr); VIR_FREE(speedStr);
ctxt->node = origNode;
return ret; return ret;
} }
@ -1423,7 +1395,8 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr pciExpressNode, xmlNodePtr pciExpressNode,
virPCIEDeviceInfoPtr pci_express) virPCIEDeviceInfoPtr pci_express)
{ {
xmlNodePtr lnk, origNode = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr lnk;
int ret = -1; int ret = -1;
ctxt->node = pciExpressNode; ctxt->node = pciExpressNode;
@ -1448,7 +1421,6 @@ virPCIEDeviceInfoParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
cleanup: cleanup:
ctxt->node = origNode;
return ret; return ret;
} }
@ -1595,7 +1567,7 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
virNodeDevCapPCIDevPtr pci_dev) virNodeDevCapPCIDevPtr pci_dev)
{ {
char *type = virXMLPropString(node, "type"); char *type = virXMLPropString(node, "type");
xmlNodePtr orignode = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1; int ret = -1;
ctxt->node = node; ctxt->node = node;
@ -1624,7 +1596,6 @@ virNodeDevPCICapabilityParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(type); VIR_FREE(type);
ctxt->node = orignode;
return ret; return ret;
} }
@ -1635,7 +1606,9 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapPCIDevPtr pci_dev) virNodeDevCapPCIDevPtr pci_dev)
{ {
xmlNodePtr orignode, iommuGroupNode, pciExpress; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr iommuGroupNode;
xmlNodePtr pciExpress;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
int n = 0; int n = 0;
int ret = -1; int ret = -1;
@ -1643,7 +1616,6 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt,
char *tmp = NULL; char *tmp = NULL;
size_t i = 0; size_t i = 0;
orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
if ((tmp = virXPathString("string(./class[1])", ctxt))) { if ((tmp = virXPathString("string(./class[1])", ctxt))) {
@ -1737,7 +1709,6 @@ virNodeDevCapPCIDevParseXML(xmlXPathContextPtr ctxt,
VIR_FREE(nodes); VIR_FREE(nodes);
VIR_FREE(tmp); VIR_FREE(tmp);
virPCIEDeviceInfoFree(pci_express); virPCIEDeviceInfoFree(pci_express);
ctxt->node = orignode;
return ret; return ret;
} }
@ -1750,11 +1721,10 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt,
{ {
virNodeDevCapSystemHardwarePtr hardware = &syscap->hardware; virNodeDevCapSystemHardwarePtr hardware = &syscap->hardware;
virNodeDevCapSystemFirmwarePtr firmware = &syscap->firmware; virNodeDevCapSystemFirmwarePtr firmware = &syscap->firmware;
xmlNodePtr orignode; VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1; int ret = -1;
char *tmp; char *tmp;
orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
syscap->product_name = virXPathString("string(./product[1])", ctxt); syscap->product_name = virXPathString("string(./product[1])", ctxt);
@ -1784,7 +1754,6 @@ virNodeDevCapSystemParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
out: out:
ctxt->node = orignode;
return ret; return ret;
} }
@ -1795,10 +1764,9 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt,
xmlNodePtr node, xmlNodePtr node,
virNodeDevCapMdevPtr mdev) virNodeDevCapMdevPtr mdev)
{ {
xmlNodePtr orignode; VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1; int ret = -1;
orignode = ctxt->node;
ctxt->node = node; ctxt->node = node;
if (!(mdev->type = virXPathString("string(./type[1]/@id)", ctxt))) { if (!(mdev->type = virXPathString("string(./type[1]/@id)", ctxt))) {
@ -1817,7 +1785,6 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
out: out:
ctxt->node = orignode;
return ret; return ret;
} }

View File

@ -846,7 +846,7 @@ virDomainNumaDefCPUParseXML(virDomainNumaPtr def,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
xmlNodePtr oldNode = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
char *tmp = NULL; char *tmp = NULL;
int n; int n;
size_t i, j; size_t i, j;
@ -963,7 +963,6 @@ virDomainNumaDefCPUParseXML(virDomainNumaPtr def,
ret = 0; ret = 0;
cleanup: cleanup:
ctxt->node = oldNode;
VIR_FREE(nodes); VIR_FREE(nodes);
VIR_FREE(tmp); VIR_FREE(tmp);
return ret; return ret;

View File

@ -144,7 +144,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
char *type = NULL; char *type = NULL;
char *driver = NULL; char *driver = NULL;
xmlNodePtr cur; xmlNodePtr cur;
xmlNodePtr saved = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
ctxt->node = node; ctxt->node = node;
@ -205,7 +205,6 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
ret = 0; ret = 0;
cleanup: cleanup:
ctxt->node = saved;
VIR_FREE(driver); VIR_FREE(driver);
VIR_FREE(snapshot); VIR_FREE(snapshot);

View File

@ -178,7 +178,7 @@ virStorageAdapterParseXML(virStorageAdapterPtr adapter,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
int ret = -1; int ret = -1;
xmlNodePtr relnode = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
char *adapter_type = NULL; char *adapter_type = NULL;
ctxt->node = node; ctxt->node = node;
@ -208,7 +208,6 @@ virStorageAdapterParseXML(virStorageAdapterPtr adapter,
ret = 0; ret = 0;
cleanup: cleanup:
ctxt->node = relnode;
VIR_FREE(adapter_type); VIR_FREE(adapter_type);
return ret; return ret;
} }

View File

@ -727,7 +727,7 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
{ {
long long val; long long val;
int ret = -1; int ret = -1;
xmlNodePtr relnode; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr node; xmlNodePtr node;
g_autofree char *mode = NULL; g_autofree char *mode = NULL;
@ -741,7 +741,6 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
return 0; return 0;
} }
relnode = ctxt->node;
ctxt->node = node; ctxt->node = node;
if ((mode = virXPathString("string(./mode)", ctxt))) { if ((mode = virXPathString("string(./mode)", ctxt))) {
@ -791,7 +790,6 @@ virStorageDefParsePerms(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
error: error:
ctxt->node = relnode;
return ret; return ret;
} }

View File

@ -57,7 +57,7 @@ virSaveCookieParse(xmlXPathContextPtr ctxt,
virObjectPtr *obj, virObjectPtr *obj,
virSaveCookieCallbacksPtr saveCookie) virSaveCookieCallbacksPtr saveCookie)
{ {
xmlNodePtr node = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
int ret = -1; int ret = -1;
*obj = NULL; *obj = NULL;
@ -70,7 +70,6 @@ virSaveCookieParse(xmlXPathContextPtr ctxt,
ret = virSaveCookieParseNode(ctxt, obj, saveCookie); ret = virSaveCookieParseNode(ctxt, obj, saveCookie);
cleanup: cleanup:
ctxt->node = node;
return ret; return ret;
} }

View File

@ -40,14 +40,12 @@ loadData(const char *mapfile,
void *data) void *data)
{ {
int ret = -1; int ret = -1;
xmlNodePtr ctxt_node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
int n; int n;
size_t i; size_t i;
int rv; int rv;
ctxt_node = ctxt->node;
if ((n = virXPathNodeSet(element, ctxt, &nodes)) < 0) if ((n = virXPathNodeSet(element, ctxt, &nodes)) < 0)
goto cleanup; goto cleanup;
@ -58,7 +56,6 @@ loadData(const char *mapfile,
} }
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
xmlNodePtr old = ctxt->node;
char *name = virXMLPropString(nodes[i], "name"); char *name = virXMLPropString(nodes[i], "name");
if (!name) { if (!name) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
@ -68,7 +65,6 @@ loadData(const char *mapfile,
VIR_DEBUG("Load %s name %s", element, name); VIR_DEBUG("Load %s name %s", element, name);
ctxt->node = nodes[i]; ctxt->node = nodes[i];
rv = callback(ctxt, name, data); rv = callback(ctxt, name, data);
ctxt->node = old;
VIR_FREE(name); VIR_FREE(name);
if (rv < 0) if (rv < 0)
goto cleanup; goto cleanup;
@ -77,7 +73,6 @@ loadData(const char *mapfile,
ret = 0; ret = 0;
cleanup: cleanup:
ctxt->node = ctxt_node;
VIR_FREE(nodes); VIR_FREE(nodes);
return ret; return ret;
@ -135,13 +130,11 @@ loadIncludes(xmlXPathContextPtr ctxt,
void *data) void *data)
{ {
int ret = -1; int ret = -1;
xmlNodePtr ctxt_node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
int n; int n;
size_t i; size_t i;
ctxt_node = ctxt->node;
n = virXPathNodeSet("include", ctxt, &nodes); n = virXPathNodeSet("include", ctxt, &nodes);
if (n < 0) if (n < 0)
goto cleanup; goto cleanup;
@ -164,7 +157,6 @@ loadIncludes(xmlXPathContextPtr ctxt,
ret = 0; ret = 0;
cleanup: cleanup:
ctxt->node = ctxt_node;
VIR_FREE(nodes); VIR_FREE(nodes);
return ret; return ret;

View File

@ -1486,7 +1486,7 @@ x86ModelParseSignatures(virCPUx86ModelPtr model,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
g_autofree xmlNodePtr *nodes = NULL; g_autofree xmlNodePtr *nodes = NULL;
xmlNodePtr root = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
size_t i; size_t i;
int n; int n;
@ -1527,7 +1527,6 @@ x86ModelParseSignatures(virCPUx86ModelPtr model,
return -1; return -1;
} }
ctxt->node = root;
return 0; return 0;
} }

View File

@ -207,12 +207,11 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt,
lxcDomainDefPtr lxcDef = g_new0(lxcDomainDef, 1); lxcDomainDefPtr lxcDef = g_new0(lxcDomainDef, 1);
g_autofree xmlNodePtr *nodes = NULL; g_autofree xmlNodePtr *nodes = NULL;
bool uses_lxc_ns = false; bool uses_lxc_ns = false;
xmlNodePtr node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
int feature; int feature;
int n; int n;
size_t i; size_t i;
node = ctxt->node;
if ((n = virXPathNodeSet("./lxc:namespace/*", ctxt, &nodes)) < 0) if ((n = virXPathNodeSet("./lxc:namespace/*", ctxt, &nodes)) < 0)
goto error; goto error;
uses_lxc_ns |= n > 0; uses_lxc_ns |= n > 0;
@ -249,7 +248,6 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt,
goto error; goto error;
} }
} }
ctxt->node = node;
if (uses_lxc_ns) if (uses_lxc_ns)
*data = lxcDef; *data = lxcDef;
else else

View File

@ -143,7 +143,7 @@ static virStorageEncryptionSecretPtr
virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt, virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
xmlNodePtr node) xmlNodePtr node)
{ {
xmlNodePtr old_node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
virStorageEncryptionSecretPtr ret; virStorageEncryptionSecretPtr ret;
char *type_str = NULL; char *type_str = NULL;
char *uuidstr = NULL; char *uuidstr = NULL;
@ -152,7 +152,6 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
if (VIR_ALLOC(ret) < 0) if (VIR_ALLOC(ret) < 0)
return NULL; return NULL;
old_node = ctxt->node;
ctxt->node = node; ctxt->node = node;
if (!(type_str = virXPathString("string(./@type)", ctxt))) { if (!(type_str = virXPathString("string(./@type)", ctxt))) {
@ -173,7 +172,6 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
VIR_FREE(type_str); VIR_FREE(type_str);
ctxt->node = old_node;
return ret; return ret;
cleanup: cleanup:
@ -181,7 +179,6 @@ virStorageEncryptionSecretParse(xmlXPathContextPtr ctxt,
virStorageEncryptionSecretFree(ret); virStorageEncryptionSecretFree(ret);
VIR_FREE(uuidstr); VIR_FREE(uuidstr);
VIR_FREE(usagestr); VIR_FREE(usagestr);
ctxt->node = old_node;
return NULL; return NULL;
} }
@ -244,7 +241,7 @@ virStorageEncryptionPtr
virStorageEncryptionParseNode(xmlNodePtr node, virStorageEncryptionParseNode(xmlNodePtr node,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
xmlNodePtr saveNode = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
virStorageEncryptionPtr encdef = NULL; virStorageEncryptionPtr encdef = NULL;
virStorageEncryptionPtr ret = NULL; virStorageEncryptionPtr ret = NULL;
@ -313,7 +310,6 @@ virStorageEncryptionParseNode(xmlNodePtr node,
VIR_FREE(format_str); VIR_FREE(format_str);
VIR_FREE(nodes); VIR_FREE(nodes);
virStorageEncryptionFree(encdef); virStorageEncryptionFree(encdef);
ctxt->node = saveNode;
return ret; return ret;
} }

View File

@ -1781,7 +1781,7 @@ virStorageAuthDefPtr
virStorageAuthDefParse(xmlNodePtr node, virStorageAuthDefParse(xmlNodePtr node,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
xmlNodePtr saveNode = ctxt->node; VIR_XPATH_NODE_AUTORESTORE(ctxt);
virStorageAuthDefPtr ret = NULL; virStorageAuthDefPtr ret = NULL;
xmlNodePtr secretnode = NULL; xmlNodePtr secretnode = NULL;
g_autoptr(virStorageAuthDef) authdef = NULL; g_autoptr(virStorageAuthDef) authdef = NULL;
@ -1832,7 +1832,6 @@ virStorageAuthDefParse(xmlNodePtr node,
ret = g_steal_pointer(&authdef); ret = g_steal_pointer(&authdef);
cleanup: cleanup:
ctxt->node = saveNode;
return ret; return ret;
} }

View File

@ -6818,7 +6818,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
xmlDocPtr xml = NULL; xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL; xmlXPathContextPtr ctxt = NULL;
xmlNodePtr *nodes = NULL; xmlNodePtr *nodes = NULL;
xmlNodePtr old;
int nnodes; int nnodes;
size_t i; size_t i;
unsigned int curvcpus = 0; unsigned int curvcpus = 0;
@ -6853,8 +6852,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
goto cleanup; goto cleanup;
} }
old = ctxt->node;
for (i = 0; i < nnodes; i++) { for (i = 0; i < nnodes; i++) {
ctxt->node = nodes[i]; ctxt->node = nodes[i];
@ -6868,8 +6865,6 @@ virshDomainGetVcpuBitmap(vshControl *ctl,
VIR_FREE(online); VIR_FREE(online);
} }
ctxt->node = old;
if (virBitmapCountBits(ret) != curvcpus) { if (virBitmapCountBits(ret) != curvcpus) {
vshError(ctl, "%s", _("Failed to retrieve vcpu state bitmap")); vshError(ctl, "%s", _("Failed to retrieve vcpu state bitmap"));
virBitmapFree(ret); virBitmapFree(ret);