[libvirt PATCH v3] hypervisor: Move interface mgmt methods to hypervisor

2023-10-19 Thread Praveen K Paladugu
Move guest interface management methods from qemu to hypervisor. These
methods will be shared by networking support in ch driver.

Signed-off-by: Praveen K Paladugu 
---
 po/POTFILES   |   1 +
 src/hypervisor/domain_interface.c | 368 ++
 src/hypervisor/domain_interface.h |  41 
 src/hypervisor/meson.build|   1 +
 src/libvirt_private.syms  |   8 +
 src/qemu/qemu_command.c   |   6 +-
 src/qemu/qemu_hotplug.c   |   5 +-
 src/qemu/qemu_interface.c | 339 +--
 src/qemu/qemu_interface.h |  11 -
 src/qemu/qemu_process.c   |   5 +-
 10 files changed, 434 insertions(+), 351 deletions(-)
 create mode 100644 src/hypervisor/domain_interface.c
 create mode 100644 src/hypervisor/domain_interface.h

diff --git a/po/POTFILES b/po/POTFILES
index 3a51aea5cb..023c041f61 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -92,6 +92,7 @@ src/hyperv/hyperv_util.c
 src/hyperv/hyperv_wmi.c
 src/hypervisor/domain_cgroup.c
 src/hypervisor/domain_driver.c
+src/hypervisor/domain_interface.c
 src/hypervisor/virhostdev.c
 src/interface/interface_backend_netcf.c
 src/interface/interface_backend_udev.c
diff --git a/src/hypervisor/domain_interface.c 
b/src/hypervisor/domain_interface.c
new file mode 100644
index 00..f726cb2bea
--- /dev/null
+++ b/src/hypervisor/domain_interface.c
@@ -0,0 +1,368 @@
+/*
+ * Copyright (C) 2015-2016 Red Hat, Inc.
+ * Copyright IBM Corp. 2014
+ *
+ * domain_interface.c: methods to manage guest/domain interfaces
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include "virconftypes.h"
+#include "virmacaddr.h"
+#include "virnetdevtap.h"
+#include "domain_audit.h"
+#include "domain_conf.h"
+#include "domain_interface.h"
+#include "domain_nwfilter.h"
+#include "viralloc.h"
+#include "virebtables.h"
+#include "virfile.h"
+#include "virlog.h"
+#include "virnetdevbridge.h"
+#include "network_conf.h"
+
+#define VIR_FROM_THIS VIR_FROM_INTERFACE
+
+VIR_LOG_INIT("interface.interface_connect");
+
+bool
+virDomainInterfaceIsVnetCompatModel(const virDomainNetDef *net)
+{
+return (virDomainNetIsVirtioModel(net) ||
+net->model == VIR_DOMAIN_NET_MODEL_E1000E ||
+net->model == VIR_DOMAIN_NET_MODEL_IGB ||
+net->model == VIR_DOMAIN_NET_MODEL_VMXNET3);
+}
+
+/* virDomainInterfaceEthernetConnect:
+ * @def: the definition of the VM
+ * @driver: qemu driver data
+ * @net: pointer to the VM's interface description
+ * @tapfd: array of file descriptor return value for the new device
+ * @tapfdsize: number of file descriptors in @tapfd
+ *
+ * Called *only* called if actualType is VIR_DOMAIN_NET_TYPE_ETHERNET
+ * (i.e. if the connection is made with a tap device)
+ */
+int
+virDomainInterfaceEthernetConnect(virDomainDef *def,
+virDomainNetDef *net,
+ebtablesContext *ebtables,
+bool macFilter,
+bool privileged,
+int *tapfd,
+size_t tapfdSize)
+{
+virMacAddr tapmac;
+int ret = -1;
+unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;
+bool template_ifname = false;
+const char *tunpath = "/dev/net/tun";
+const char *auditdev = tunpath;
+
+if (net->backend.tap) {
+tunpath = net->backend.tap;
+if (!privileged) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("cannot use custom tap device in session mode"));
+goto cleanup;
+}
+}
+
+if (virDomainInterfaceIsVnetCompatModel(net))
+tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
+
+if (net->managed_tap == VIR_TRISTATE_BOOL_NO) {
+if (!net->ifname) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("target dev must be supplied when managed='no'"));
+goto cleanup;
+}
+if (virNetDevExists(net->ifname) != 1) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("target managed='no' but specified dev doesn't 
exist"));
+goto cleanup;
+}
+
+tap_create_flags |= VIR_NETDEV_TAP_CREATE_ALLOW_EXISTING;

Re: [PATCH libvirt v1 0/3] Ensure full early console access with libvirt

2023-10-19 Thread Marc Hartmayer
On Wed, Oct 11, 2023 at 10:05 AM +0200, "Marc Hartmayer" 
 wrote:
> On Thu, Sep 28, 2023 at 05:37 PM +0200, Marc Hartmayer 
>  wrote:
>> Currently, early console output may be lost, e.g. if starting a guest with
>> `virsh start --console` guest, which can make debugging of early failures 
>> very
>> difficult
>> (like zipl messages or disabled wait conditions happening early). This is
>> because QEMU may emit serial console output before the libvirt console client
>> starts to consume data from the pts. This can be prevented by starting the 
>> guest
>> in paused state, connect to the console and then resume the guest.
>>

>> Note: There is still a problem in QEMU itself, see QEMU patch series `[PATCH]
>> chardev/char-pty: Avoid losing bytes when the other side just (re-)connected`
>> [1]

This patch is now accepted upstream.

>>
>> Changelog:
>> RFCv1->v1:
>> + rebased on current master
>> + worked in comments from Daniel
>>
>> [1] https://lists.gnu.org/archive/html/qemu-devel/2023-08/msg02725.html
>>
>> Marc Hartmayer (3):
>>   virsh: add `console --resume` support
>>   Improve `virsh start --console` behavior
>>   Improve `virsh create --console` behavior
>>
>>  tools/virsh-console.c |  8 
>>  tools/virsh-console.h |  1 +
>>  tools/virsh-domain.c  | 94 ---
>>  3 files changed, 80 insertions(+), 23 deletions(-)
>>
>>
>> base-commit: dd403f8873cf8de7675b89ed757a4228af7bc05e
>> -- 
>> 2.34.1
>>
>
> Polite ping and adding Daniel to CC - sry I missed that in the
> beginning.
>
> -- 
> Kind regards / Beste Grüße
>Marc Hartmayer
>
> IBM Deutschland Research & Development GmbH
> Vorsitzender des Aufsichtsrats: Gregor Pillen
> Geschäftsführung: David Faller
> Sitz der Gesellschaft: Böblingen
> Registergericht: Amtsgericht Stuttgart, HRB 243294

Very friendly ping.

-- 
Kind regards / Beste Grüße
   Marc Hartmayer

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Gregor Pillen
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294



Re: [libvirt PATCH v2] hypervisor: Move interface mgmt methods to hypervisor

2023-10-19 Thread Praveen Paladugu
On Wed, Oct 18, 2023 at 03:36:47PM -0400, Laine Stump wrote:
> On 10/16/23 3:34 PM, Praveen K Paladugu wrote:
> >Move guest interface management methods from qemu to hypervisor. These
> >methods will be shared by networking support in ch driver.
> >
> >Signed-off-by: Praveen K Paladugu 
> >---
> >  po/POTFILES   |   1 +
> >  src/hypervisor/domain_interface.c | 280 ++
> >  src/hypervisor/domain_interface.h |  39 +
> >  src/hypervisor/meson.build|   1 +
> >  src/libvirt_private.syms  |   6 +
> >  src/qemu/qemu_command.c   |   7 +-
> >  src/qemu/qemu_hotplug.c   |   3 +-
> >  src/qemu/qemu_interface.c | 246 +-
> >  src/qemu/qemu_interface.h |   6 -
> >  src/qemu/qemu_process.c   |   3 +-
> >  10 files changed, 343 insertions(+), 249 deletions(-)
> >  create mode 100644 src/hypervisor/domain_interface.c
> >  create mode 100644 src/hypervisor/domain_interface.h
> >
> >diff --git a/po/POTFILES b/po/POTFILES
> >index 3a51aea5cb..023c041f61 100644
> >--- a/po/POTFILES
> >+++ b/po/POTFILES
> >@@ -92,6 +92,7 @@ src/hyperv/hyperv_util.c
> >  src/hyperv/hyperv_wmi.c
> >  src/hypervisor/domain_cgroup.c
> >  src/hypervisor/domain_driver.c
> >+src/hypervisor/domain_interface.c
> >  src/hypervisor/virhostdev.c
> >  src/interface/interface_backend_netcf.c
> >  src/interface/interface_backend_udev.c
> >diff --git a/src/hypervisor/domain_interface.c 
> >b/src/hypervisor/domain_interface.c
> >new file mode 100644
> >index 00..592c4253df
> >--- /dev/null
> >+++ b/src/hypervisor/domain_interface.c
> >@@ -0,0 +1,280 @@
> >+/*
> >+ * Copyright (C) 2015-2016 Red Hat, Inc.
> >+ * Copyright IBM Corp. 2014
> >+ *
> >+ * domain_interface.c: methods to manage guest/domain interfaces
> >+ *
> >+ * This library is free software; you can redistribute it and/or
> >+ * modify it under the terms of the GNU Lesser General Public
> >+ * License as published by the Free Software Foundation; either
> >+ * version 2.1 of the License, or (at your option) any later version.
> >+ *
> >+ * This library is distributed in the hope that it will be useful,
> >+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
> >+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> >+ * Lesser General Public License for more details.
> >+ *
> >+ * You should have received a copy of the GNU Lesser General Public
> >+ * License along with this library.  If not, see
> >+ * .
> >+ */
> >+
> >+#include 
> >+
> >+#include "virconftypes.h"
> >+#include "virmacaddr.h"
> >+#include "virnetdevtap.h"
> >+#include "domain_audit.h"
> >+#include "domain_conf.h"
> >+#include "domain_interface.h"
> >+#include "domain_nwfilter.h"
> >+#include "viralloc.h"
> >+#include "virebtables.h"
> >+#include "virfile.h"
> >+#include "virlog.h"
> >+#include "virnetdevbridge.h"
> >+#include "network_conf.h"
> >+
> >+#define VIR_FROM_THIS VIR_FROM_INTERFACE
> >+
> >+VIR_LOG_INIT("interface.interface_connect");
> >+
> >+bool
> >+virDomainInterfaceIsVnetCompatModel(const virDomainNetDef *net)
> >+{
> >+return (virDomainNetIsVirtioModel(net) ||
> >+net->model == VIR_DOMAIN_NET_MODEL_E1000E ||
> >+net->model == VIR_DOMAIN_NET_MODEL_IGB ||
> >+net->model == VIR_DOMAIN_NET_MODEL_VMXNET3);
> >+}
> >+
> >+/* virDomainInterfaceEthernetConnect:
> >+ * @def: the definition of the VM
> >+ * @driver: qemu driver data
> >+ * @net: pointer to the VM's interface description
> >+ * @tapfd: array of file descriptor return value for the new device
> >+ * @tapfdsize: number of file descriptors in @tapfd
> >+ *
> >+ * Called *only* called if actualType is VIR_DOMAIN_NET_TYPE_ETHERNET
> >+ * (i.e. if the connection is made with a tap device)
> >+ */
> >+int
> >+virDomainInterfaceEthernetConnect(virDomainDef *def,
> >+virDomainNetDef *net,
> >+ebtablesContext *ebtables,
> >+bool macFilter,
> >+bool privileged,
> >+int *tapfd,
> >+size_t tapfdSize)
> 
> This is all fine as far as it goes, but I was expecting that all of
> the functions at the same level (qemuInterface*Connect()) would be
> genericized and moved to the new file. I guess you're only planning
> to use the plain "ethernet" type of interface in the ch driver, but
> for QEMU to have some of the *Connect functions in one place and
> some in another makes the code more confusing; this is especially so
> since virDomainInterfaceStartDevice() has cases for these other
> interface types.

I started with enabling the "ethernet" mode, so I moved all the related
methods. I am planning to also enable "Bridge" and "NAT" modes too in follow
up patches. I did this to test the methods properly before I push.

> 
> I'm guessing

[PATCH] Send event on persistent config modification

2023-10-19 Thread Fima Shevrin
Currently, libvirt doesn't send events when devices are attached,
detached or updated. Thus, any services that listen to events are
unaware of the change to persistent config.

Signed-off-by: Fima Shevrin 
---
 src/qemu/qemu_driver.c | 25 -
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 43d96739d5..86da8da777 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7209,6 +7209,7 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObj *vm,
 unsigned int flags)
 {
 qemuDomainObjPrivate *priv = vm->privateData;
+virObjectEvent *event = NULL;
 g_autoptr(virDomainDef) vmdef = NULL;
 g_autoptr(virQEMUDriverConfig) cfg = NULL;
 g_autoptr(virDomainDeviceDef) devConf = NULL;
@@ -7292,6 +7293,12 @@ qemuDomainAttachDeviceLiveAndConfig(virDomainObj *vm,
 return -1;
 
 virDomainObjAssignDef(vm, &vmdef, false, NULL);
+
+/* Event sending if persistent config has changed */
+event = virDomainEventLifecycleNewFromObj(vm,
+  VIR_DOMAIN_EVENT_DEFINED,
+  
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
+virObjectEventStateQueue(driver->domainEventState, event);
 }
 
 return 0;
@@ -7348,6 +7355,7 @@ qemuDomainUpdateDeviceFlags(virDomainPtr dom,
 virQEMUDriver *driver = dom->conn->privateData;
 virDomainObj *vm = NULL;
 qemuDomainObjPrivate *priv;
+virObjectEvent *event = NULL;
 g_autoptr(virDomainDef) vmdef = NULL;
 g_autoptr(virDomainDeviceDef) dev_config = NULL;
 g_autoptr(virDomainDeviceDef) dev_live = NULL;
@@ -7419,8 +7427,16 @@ qemuDomainUpdateDeviceFlags(virDomainPtr dom,
 /* Finally, if no error until here, we can save config. */
 if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
 ret = virDomainDefSave(vmdef, driver->xmlopt, cfg->configDir);
-if (!ret)
+if (!ret) {
 virDomainObjAssignDef(vm, &vmdef, false, NULL);
+
+/* Event sending if persistent config has changed */
+event = virDomainEventLifecycleNewFromObj(vm,
+ VIR_DOMAIN_EVENT_DEFINED,
+ 
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
+
+virObjectEventStateQueue(driver->domainEventState, event);
+}
 }
 
  endjob:
@@ -7438,6 +7454,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver *driver,
 unsigned int flags)
 {
 qemuDomainObjPrivate *priv = vm->privateData;
+virObjectEvent *event = NULL;
 g_autoptr(virQEMUDriverConfig) cfg = NULL;
 g_autoptr(virDomainDeviceDef) dev_config = NULL;
 g_autoptr(virDomainDeviceDef) dev_live = NULL;
@@ -7495,6 +7512,12 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriver 
*driver,
 return -1;
 
 virDomainObjAssignDef(vm, &vmdef, false, NULL);
+
+/* Event sending if persistent config has changed */
+event = virDomainEventLifecycleNewFromObj(vm,
+  VIR_DOMAIN_EVENT_DEFINED,
+  
VIR_DOMAIN_EVENT_DEFINED_UPDATED);
+virObjectEventStateQueue(driver->domainEventState, event);
 }
 
 return 0;
-- 
2.39.3



Plans for 9.9.0 release (freeze on Thursday 26 Oct)

2023-10-19 Thread Jiri Denemark
We are getting close to 9.9.0 release of libvirt. To aim for the
release on Wednesday 01 Nov I suggest entering the freeze on Thursday
26 Oct and tagging RC2 on Monday 30 Oct.

I hope this works for everyone.

Jirka