Every caller reports the error themselves. Might as well move it into the function and thus unify it. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/conf/domain_conf.c | 18 ++++++++++-------- src/libxl/libxl_driver.c | 5 +---- src/lxc/lxc_driver.c | 5 +---- src/openvz/openvz_driver.c | 5 +---- src/qemu/qemu_driver.c | 21 ++++----------------- src/test/test_driver.c | 5 +---- src/xen/xen_driver.c | 5 +---- 7 files changed, 19 insertions(+), 45 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 54be9028d..caffa896d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -26983,13 +26983,12 @@ virDomainGraphicsListenAppendSocket(virDomainGraphicsDefPtr def, * * 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; @@ -26998,16 +26997,19 @@ virDomainNetFind(virDomainDefPtr def, const char *device) 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; } diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 9db6f3503..08b0f0317 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -4979,11 +4979,8 @@ libxlDomainInterfaceStats(virDomainPtr dom, goto endjob; } - if (!(net = virDomainNetFind(vm->def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), device); + if (!(net = virDomainNetFind(vm->def, device))) goto endjob; - } if (virNetDevTapInterfaceStats(device, stats, !virDomainNetTypeSharesHostView(net)) < 0) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 4ab05a7ff..6cf499367 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2872,11 +2872,8 @@ lxcDomainInterfaceStats(virDomainPtr dom, goto endjob; } - if (!(net = virDomainNetFind(vm->def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), device); + if (!(net = virDomainNetFind(vm->def, device))) goto endjob; - } if (virNetDevTapInterfaceStats(device, stats, !virDomainNetTypeSharesHostView(net)) < 0) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 05ed2bcae..ffd64da04 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -2006,11 +2006,8 @@ openvzDomainInterfaceStats(virDomainPtr dom, goto cleanup; } - if (!(net = virDomainNetFind(vm->def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), device); + if (!(net = virDomainNetFind(vm->def, device))) goto cleanup; - } if (virNetDevTapInterfaceStats(device, stats, !virDomainNetTypeSharesHostView(net)) < 0) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f2cc0f0a5..7b79c0950 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11040,11 +11040,8 @@ qemuDomainInterfaceStats(virDomainPtr dom, goto cleanup; } - if (!(net = virDomainNetFind(vm->def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), device); + if (!(net = virDomainNetFind(vm->def, device))) goto cleanup; - } if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_VHOSTUSER) { if (virNetDevOpenvswitchInterfaceStats(device, stats) < 0) @@ -11114,18 +11111,12 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom, 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) || @@ -11291,12 +11282,8 @@ qemuDomainGetInterfaceParameters(virDomainPtr dom, 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) { diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 3e286635e..be9e8a7aa 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3181,11 +3181,8 @@ testDomainInterfaceStats(virDomainPtr domain, goto error; } - if (!(net = virDomainNetFind(privdom->def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), device); + if (!(net = virDomainNetFind(privdom->def, device))) goto error; - } if (gettimeofday(&tv, NULL) < 0) { virReportSystemError(errno, diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index 4235ca0ce..901b6ba4b 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -2122,11 +2122,8 @@ xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *device, if (virDomainInterfaceStatsEnsureACL(dom->conn, def) < 0) goto cleanup; - if (!(net = virDomainNetFind(def, device))) { - virReportError(VIR_ERR_INVALID_ARG, - _("'%s' is not a known interface"), device); + if (!(net = virDomainNetFind(def, device))) goto cleanup; - } ret = xenHypervisorDomainInterfaceStats(def, net->ifname, stats); -- 2.13.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list