[PATCH 0/2] qemu_interface: Fix managed='no' case when creating an ethernet interface

*** BLURB HERE *** Michal Prívozník (2): virnetdevtap: Clarify virNetDevTapCreate() behavior wrt VIR_NETDEV_TAP_CREATE_ALLOW_EXISTING qemu_interface: Fix managed='no' case when creating an ethernet interface src/qemu/qemu_interface.c | 5 +++-- src/util/virnetdevtap.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) -- 2.39.1

The VIR_NETDEV_TAP_CREATE_ALLOW_EXISTING flag is documented as: /* The device is allowed to exist before creation */ VIR_NETDEV_TAP_CREATE_ALLOW_EXISTING = 1 << 4, and yet, the documentation to virNetDevTapCreate() documents its behavior when the flag is passed as: * VIR_NETDEV_TAP_CREATE_ALLOW_EXISTING * - The device creation fails if @ifname already exists Fortunately, the function is implemented so that it follows the expected behavior (i.e. the former flag documentation). Fix the function documentation then. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/util/virnetdevtap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index a4ead0ae93..2101d7847c 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -156,7 +156,7 @@ virNetDevTapGetRealDeviceName(char *ifname G_GNUC_UNUSED) * VIR_NETDEV_TAP_CREATE_PERSIST * - The device will persist after the file descriptor is closed * VIR_NETDEV_TAP_CREATE_ALLOW_EXISTING - * - The device creation fails if @ifname already exists + * - The device creation does not fail if @ifname already exists * * Creates a tap interface. The caller must use virNetDevTapDelete to * remove a persistent TAP device when it is no longer needed. In case -- 2.39.1

In a recent commit of v9.0.0-rc1~192 I've tried to forbid case where a TAP device already exists, but at the same time it's managed by Libvirt (<interface type='ethernet'> <target dev='tap0' managed='yes'/> </interface>). NB, if @managed attribute is missing then it's assumed to be managed by Libvirt. Anyway, I've mistakenly put setting of VIR_NETDEV_TAP_CREATE_ALLOW_EXISTING flag into managed='yes' branch instead of managed='no' branch in qemuInterfaceEthernetConnect(). Move the setting of the flag into the correct branch. Fixes: a2ae3d299cf9c5ada8aa42ec4271748eb479dc27 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_interface.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index b6895cedde..ed2c209167 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -443,6 +443,9 @@ qemuInterfaceEthernetConnect(virDomainDef *def, _("target managed='no' but specified dev doesn't exist")); goto cleanup; } + + tap_create_flags |= VIR_NETDEV_TAP_CREATE_ALLOW_EXISTING; + if (virNetDevMacVLanIsMacvtap(net->ifname)) { auditdev = net->ifname; if (virNetDevMacVLanTapOpen(net->ifname, tapfd, tapfdSize) < 0) @@ -461,8 +464,6 @@ qemuInterfaceEthernetConnect(virDomainDef *def, if (!net->ifname) template_ifname = true; - tap_create_flags |= VIR_NETDEV_TAP_CREATE_ALLOW_EXISTING; - if (virNetDevTapCreate(&net->ifname, tunpath, tapfd, tapfdSize, tap_create_flags) < 0) { goto cleanup; -- 2.39.1

On Mon, Jan 23, 2023 at 12:03:41PM +0100, Michal Privoznik wrote:
*** BLURB HERE ***
Michal Prívozník (2): virnetdevtap: Clarify virNetDevTapCreate() behavior wrt VIR_NETDEV_TAP_CREATE_ALLOW_EXISTING qemu_interface: Fix managed='no' case when creating an ethernet interface
Series: Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/qemu/qemu_interface.c | 5 +++-- src/util/virnetdevtap.c | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-)
-- 2.39.1
participants (2)
-
Martin Kletzander
-
Michal Privoznik