*
* Finds a domain's net def, given the interface name or MAC address
*
- * Returns a pointer to the net def or NULL if not found.
+ * Returns a pointer to the net def or NULL if not found (error is reported).
*/
virDomainNetDefPtr
virDomainNetFind(virDomainDefPtr def, const char *device)
{
bool isMac = false;
- virDomainNetDefPtr net = NULL;
virMacAddr mac;
size_t i;
if (isMac) {
for (i = 0; i < def->nnets; i++) {
- if (virMacAddrCmp(&mac, &def->nets[i]->mac) == 0) {
- net = def->nets[i];
- break;
- }
+ if (virMacAddrCmp(&mac, &def->nets[i]->mac) == 0)
+ return def->nets[i];
}
} else { /* ifname */
- net = virDomainNetFindByName(def, device);
+ virDomainNetDefPtr net = NULL;
+
+ if ((net = virDomainNetFindByName(def, device)))
+ return net;
}
- return net;
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("'%s' is not a known interface"), device);
+ return NULL;
}
goto endjob;
}
- if (!(net = virDomainNetFindByName(vm->def, path))) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("'%s' is not a known interface"), path);
+ if (!(net = virDomainNetFindByName(vm->def, path)))
goto endjob;
- }
if (virNetDevTapInterfaceStats(path, stats,
!virDomainNetTypeSharesHostView(net)) < 0)
goto endjob;
}
- if (!(net = virDomainNetFindByName(vm->def, path))) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("Invalid path, '%s' is not a known interface"), path);
+ if (!(net = virDomainNetFindByName(vm->def, path)))
goto endjob;
- }
if (virNetDevTapInterfaceStats(path, stats,
!virDomainNetTypeSharesHostView(net)) < 0)
goto cleanup;
}
- if (!(net = virDomainNetFindByName(vm->def, path))) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("invalid path, '%s' is not a known interface"), path);
+ if (!(net = virDomainNetFindByName(vm->def, path)))
goto cleanup;
- }
if (virNetDevTapInterfaceStats(path, stats,
!virDomainNetTypeSharesHostView(net)) < 0)
goto cleanup;
}
- if (!(net = virDomainNetFindByName(vm->def, path))) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("invalid path, '%s' is not a known interface"), path);
+ if (!(net = virDomainNetFindByName(vm->def, path)))
goto cleanup;
- }
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
if (virNetDevOpenvswitchInterfaceStats(path, stats) < 0)
goto endjob;
if (def &&
- !(net = virDomainNetFind(vm->def, device))) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("Can't find device %s"), device);
+ !(net = virDomainNetFind(vm->def, device)))
goto endjob;
- }
if (persistentDef &&
- !(persistentNet = virDomainNetFind(persistentDef, device))) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("Can't find device %s"), device);
+ !(persistentNet = virDomainNetFind(persistentDef, device)))
goto endjob;
- }
if ((VIR_ALLOC(bandwidth) < 0) ||
(VIR_ALLOC(bandwidth->in) < 0) ||
goto cleanup;
}
- net = virDomainNetFind(def, device);
- if (!net) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("Can't find device %s"), device);
+ if (!(net = virDomainNetFind(def, device)))
goto cleanup;
- }
for (i = 0; i < *nparams && i < QEMU_NB_BANDWIDTH_PARAM; i++) {
switch (i) {
goto error;
}
- if (!(net = virDomainNetFindByName(privdom->def, path))) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("invalid path, '%s' is not a known interface"), path);
+ if (!(net = virDomainNetFindByName(privdom->def, path)))
goto error;
- }
if (gettimeofday(&tv, NULL) < 0) {
virReportSystemError(errno,
virDomainInterfaceStatsPtr stats)
{
virDomainDefPtr def = NULL;
+ virDomainNetDefPtr net = NULL;
int ret = -1;
if (!(def = xenGetDomainDefForDom(dom)))
if (virDomainInterfaceStatsEnsureACL(dom->conn, def) < 0)
goto cleanup;
- ret = xenHypervisorDomainInterfaceStats(def, path, stats);
+ if (!(net = virDomainNetFind(def, path)))
+ goto cleanup;
+
+ ret = xenHypervisorDomainInterfaceStats(def, net->ifname, stats);
cleanup:
virDomainDefFree(def);