[PATCH v2] virnetdevveth: Do report error if creating veth fails

Michal Privoznik posted 1 patch 2 years, 4 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1f6dd125482986feaec0d1534422cc0c8a0910e3.1638452439.git.mprivozn@redhat.com
src/util/virnetdevveth.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
[PATCH v2] virnetdevveth: Do report error if creating veth fails
Posted by Michal Privoznik 2 years, 4 months ago
For some weird reason we are ignoring errors when creating veth
pair that netlink reports. This affects the LXC driver which
creates interfaces for container in
virLXCProcessSetupInterfaces(). If creating a veth pair fails, no
error is reported and the control jumps onto cleanup label where
some cryptic error message is reported instead (something about
inability to remove veth pair).

Let's report error that netlink returned - it's probably the most
accurate reason anyways.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/225
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---

v2 of:

https://listman.redhat.com/archives/libvir-list/2021-December/msg00016.html

diff to v1:
- Report error only if it wasn't already reported (error == 0)

 src/util/virnetdevveth.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c
index 7133af44a2..b580e105ac 100644
--- a/src/util/virnetdevveth.c
+++ b/src/util/virnetdevveth.c
@@ -38,10 +38,19 @@ VIR_LOG_INIT("util.netdevveth");
 static int
 virNetDevVethCreateInternal(const char *veth1, const char *veth2)
 {
-    int status;     /* Just ignore it */
+    int error = 0;
     virNetlinkNewLinkData data = { .veth_peer = veth2 };
 
-    return virNetlinkNewLink(veth1, "veth", &data, &status);
+    if (virNetlinkNewLink(veth1, "veth", &data, &error) < 0) {
+        if (error != 0) {
+            virReportSystemError(-error,
+                                 _("unable to create %s <-> %s veth pair"),
+                                 veth1, veth2);
+        }
+        return -1;
+    }
+
+    return 0;
 }
 
 static int
-- 
2.32.0

Re: [PATCH v2] virnetdevveth: Do report error if creating veth fails
Posted by Martin Kletzander 2 years, 4 months ago
On Thu, Dec 02, 2021 at 02:41:47PM +0100, Michal Privoznik wrote:
>For some weird reason we are ignoring errors when creating veth
>pair that netlink reports. This affects the LXC driver which
>creates interfaces for container in
>virLXCProcessSetupInterfaces(). If creating a veth pair fails, no
>error is reported and the control jumps onto cleanup label where
>some cryptic error message is reported instead (something about
>inability to remove veth pair).
>
>Let's report error that netlink returned - it's probably the most
>accurate reason anyways.
>
>Resolves: https://gitlab.com/libvirt/libvirt/-/issues/225
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>

>---
>
>v2 of:
>
>https://listman.redhat.com/archives/libvir-list/2021-December/msg00016.html
>
>diff to v1:
>- Report error only if it wasn't already reported (error == 0)
>
> src/util/virnetdevveth.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
>diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c
>index 7133af44a2..b580e105ac 100644
>--- a/src/util/virnetdevveth.c
>+++ b/src/util/virnetdevveth.c
>@@ -38,10 +38,19 @@ VIR_LOG_INIT("util.netdevveth");
> static int
> virNetDevVethCreateInternal(const char *veth1, const char *veth2)
> {
>-    int status;     /* Just ignore it */
>+    int error = 0;
>     virNetlinkNewLinkData data = { .veth_peer = veth2 };
>
>-    return virNetlinkNewLink(veth1, "veth", &data, &status);
>+    if (virNetlinkNewLink(veth1, "veth", &data, &error) < 0) {
>+        if (error != 0) {
>+            virReportSystemError(-error,
>+                                 _("unable to create %s <-> %s veth pair"),
>+                                 veth1, veth2);
>+        }
>+        return -1;
>+    }
>+
>+    return 0;
> }
>
> static int
>-- 
>2.32.0
>