mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
virDomainNetFind: Report error if no device found
Every caller reports the error themselves. Might as well move it into the function and thus unify it. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
24796f2710
commit
e3909729d2
@ -26983,13 +26983,12 @@ virDomainGraphicsListenAppendSocket(virDomainGraphicsDefPtr def,
|
|||||||
*
|
*
|
||||||
* Finds a domain's net def, given the interface name or MAC address
|
* 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
|
virDomainNetDefPtr
|
||||||
virDomainNetFind(virDomainDefPtr def, const char *device)
|
virDomainNetFind(virDomainDefPtr def, const char *device)
|
||||||
{
|
{
|
||||||
bool isMac = false;
|
bool isMac = false;
|
||||||
virDomainNetDefPtr net = NULL;
|
|
||||||
virMacAddr mac;
|
virMacAddr mac;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -26998,16 +26997,19 @@ virDomainNetFind(virDomainDefPtr def, const char *device)
|
|||||||
|
|
||||||
if (isMac) {
|
if (isMac) {
|
||||||
for (i = 0; i < def->nnets; i++) {
|
for (i = 0; i < def->nnets; i++) {
|
||||||
if (virMacAddrCmp(&mac, &def->nets[i]->mac) == 0) {
|
if (virMacAddrCmp(&mac, &def->nets[i]->mac) == 0)
|
||||||
net = def->nets[i];
|
return def->nets[i];
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else { /* ifname */
|
} 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4979,11 +4979,8 @@ libxlDomainInterfaceStats(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(net = virDomainNetFindByName(vm->def, path))) {
|
if (!(net = virDomainNetFindByName(vm->def, path)))
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("'%s' is not a known interface"), path);
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
|
||||||
|
|
||||||
if (virNetDevTapInterfaceStats(path, stats,
|
if (virNetDevTapInterfaceStats(path, stats,
|
||||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||||
|
@ -2872,11 +2872,8 @@ lxcDomainInterfaceStats(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(net = virDomainNetFindByName(vm->def, path))) {
|
if (!(net = virDomainNetFindByName(vm->def, path)))
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("Invalid path, '%s' is not a known interface"), path);
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
|
||||||
|
|
||||||
if (virNetDevTapInterfaceStats(path, stats,
|
if (virNetDevTapInterfaceStats(path, stats,
|
||||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||||
|
@ -2006,11 +2006,8 @@ openvzDomainInterfaceStats(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(net = virDomainNetFindByName(vm->def, path))) {
|
if (!(net = virDomainNetFindByName(vm->def, path)))
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("invalid path, '%s' is not a known interface"), path);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (virNetDevTapInterfaceStats(path, stats,
|
if (virNetDevTapInterfaceStats(path, stats,
|
||||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||||
|
@ -11040,11 +11040,8 @@ qemuDomainInterfaceStats(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(net = virDomainNetFindByName(vm->def, path))) {
|
if (!(net = virDomainNetFindByName(vm->def, path)))
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("invalid path, '%s' is not a known interface"), path);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
|
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
|
||||||
if (virNetDevOpenvswitchInterfaceStats(path, stats) < 0)
|
if (virNetDevOpenvswitchInterfaceStats(path, stats) < 0)
|
||||||
@ -11114,18 +11111,12 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (def &&
|
if (def &&
|
||||||
!(net = virDomainNetFind(vm->def, device))) {
|
!(net = virDomainNetFind(vm->def, device)))
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("Can't find device %s"), device);
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
|
||||||
|
|
||||||
if (persistentDef &&
|
if (persistentDef &&
|
||||||
!(persistentNet = virDomainNetFind(persistentDef, device))) {
|
!(persistentNet = virDomainNetFind(persistentDef, device)))
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("Can't find device %s"), device);
|
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
|
||||||
|
|
||||||
if ((VIR_ALLOC(bandwidth) < 0) ||
|
if ((VIR_ALLOC(bandwidth) < 0) ||
|
||||||
(VIR_ALLOC(bandwidth->in) < 0) ||
|
(VIR_ALLOC(bandwidth->in) < 0) ||
|
||||||
@ -11291,12 +11282,8 @@ qemuDomainGetInterfaceParameters(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
net = virDomainNetFind(def, device);
|
if (!(net = virDomainNetFind(def, device)))
|
||||||
if (!net) {
|
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("Can't find device %s"), device);
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < *nparams && i < QEMU_NB_BANDWIDTH_PARAM; i++) {
|
for (i = 0; i < *nparams && i < QEMU_NB_BANDWIDTH_PARAM; i++) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
|
@ -3180,11 +3180,8 @@ static int testDomainInterfaceStats(virDomainPtr domain,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(net = virDomainNetFindByName(privdom->def, path))) {
|
if (!(net = virDomainNetFindByName(privdom->def, path)))
|
||||||
virReportError(VIR_ERR_INVALID_ARG,
|
|
||||||
_("invalid path, '%s' is not a known interface"), path);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
|
||||||
|
|
||||||
if (gettimeofday(&tv, NULL) < 0) {
|
if (gettimeofday(&tv, NULL) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
|
@ -2113,6 +2113,7 @@ xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *path,
|
|||||||
virDomainInterfaceStatsPtr stats)
|
virDomainInterfaceStatsPtr stats)
|
||||||
{
|
{
|
||||||
virDomainDefPtr def = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
|
virDomainNetDefPtr net = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!(def = xenGetDomainDefForDom(dom)))
|
if (!(def = xenGetDomainDefForDom(dom)))
|
||||||
@ -2121,7 +2122,10 @@ xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *path,
|
|||||||
if (virDomainInterfaceStatsEnsureACL(dom->conn, def) < 0)
|
if (virDomainInterfaceStatsEnsureACL(dom->conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = xenHypervisorDomainInterfaceStats(def, path, stats);
|
if (!(net = virDomainNetFind(def, path)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ret = xenHypervisorDomainInterfaceStats(def, net->ifname, stats);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainDefFree(def);
|
virDomainDefFree(def);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user