[libvirt PATCH v2] Adds e1000e/vmxnet3 Vnet_hdr suuport

2020-08-08 Thread Patrick Magauran
Changes from Original:
Moved Comparison to qemuInterfaceIsVnetCompatModel in qemu_interface.c per the 
recommendation of Daniel Berrangé

-
Libvirt bases its decision about whether to apply the vnet_hdr flag to the tap 
interface on whether or not the selected model is VirtIO. Originally, VirtIO 
was the only model to support the vnet_hdr in QEMU; however, the e1000e & 
vmxnet3 adapters also support it(seemingly from introduction based on commits). 
This passes the whole packet to the host, reducing emulation overhead and 
improving performance.

Signed-off-by: Patrick Magauran 
---
 src/qemu/qemu_interface.c | 15 +++
 src/qemu/qemu_interface.h |  1 +
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c
index ffec992596..229bb299aa 100644
--- a/src/qemu/qemu_interface.c
+++ b/src/qemu/qemu_interface.c
@@ -230,6 +230,13 @@ qemuInterfaceStopDevices(virDomainDefPtr def)
 return 0;
 }
 
+bool qemuInterfaceIsVnetCompatModel(const virDomainNetDef *net)
+{
+return (virDomainNetIsVirtioModel(net) ||
+   net->model == VIR_DOMAIN_NET_MODEL_E1000E ||
+   net->model == VIR_DOMAIN_NET_MODEL_VMXNET3);
+}
+
 
 /**
  * qemuInterfaceDirectConnect:
@@ -255,7 +262,7 @@ qemuInterfaceDirectConnect(virDomainDefPtr def,
 virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
 unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP;
 
-if (virDomainNetIsVirtioModel(net))
+if (qemuInterfaceIsVnetCompatModel(net))
 macvlan_create_flags |= VIR_NETDEV_MACVLAN_VNET_HDR;
 
 if (virNetDevMacVLanCreateWithVPortProfile(net->ifname,
@@ -417,7 +424,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
 }
 }
 
-if (virDomainNetIsVirtioModel(net))
+if (qemuInterfaceIsVnetCompatModel(net))
 tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
 
 if (net->managed_tap == VIR_TRISTATE_BOOL_NO) {
@@ -436,7 +443,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def,
 if (virNetDevMacVLanTapOpen(net->ifname, tapfd, tapfdSize) < 0)
 goto cleanup;
 if (virNetDevMacVLanTapSetup(tapfd, tapfdSize,
- virDomainNetIsVirtioModel(net)) < 0) {
+ qemuInterfaceIsVnetCompatModel(net)) 
< 0) {
 goto cleanup;
 }
 } else {
@@ -559,7 +566,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def,
 template_ifname = true;
 }
 
-if (virDomainNetIsVirtioModel(net))
+if (qemuInterfaceIsVnetCompatModel(net))
 tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
 
 if (driver->privileged) {
diff --git a/src/qemu/qemu_interface.h b/src/qemu/qemu_interface.h
index 0464b903d7..9e3f61e8e0 100644
--- a/src/qemu/qemu_interface.h
+++ b/src/qemu/qemu_interface.h
@@ -58,3 +58,4 @@ int qemuInterfaceOpenVhostNet(virDomainDefPtr def,
 
 qemuSlirpPtr qemuInterfacePrepareSlirp(virQEMUDriverPtr driver,
virDomainNetDefPtr net);
+bool qemuInterfaceIsVnetCompatModel(const virDomainNetDef *net);
-- 
2.26.2



[PATCH] NVRAM: check NVRAM file size and recover from template

2020-08-08 Thread Hao Wang
From: Hao Wang 
Subject: [PATCH] NVRAM: check NVRAM file size and recover from template

A corrupted nvram file (e.g. caused by last unsuccessful creation due to
insufficient memory) can lead to boot or migration failure.
Check the size of the existed nvram file when qemuPrepareNVRAM, and re-create
if the existed one is unhealthy.

Signed-off-by: Hao Wang 
---
 src/qemu/qemu_process.c | 54 -
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 126fabf5ef..42060bb36c 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4376,6 +4376,48 @@ qemuProcessUpdateCPU(virQEMUDriverPtr driver,
 }


+static bool
+qemuIsNvramFileHealthy(virQEMUDriverConfigPtr cfg,
+   virDomainLoaderDefPtr loader)
+{
+const char *masterNvramPath;
+off_t nvramSize;
+off_t masterSize;
+
+masterNvramPath = loader->templt;
+if (!loader->templt) {
+size_t i;
+for (i = 0; i < cfg->nfirmwares; i++) {
+if (STREQ(cfg->firmwares[i]->name, loader->path)) {
+masterNvramPath = cfg->firmwares[i]->nvram;
+break;
+}
+}
+}
+
+if (!masterNvramPath) {
+VIR_WARN("no nvram template is found; assume the nvram file is 
healthy");
+return true;
+}
+
+if ((nvramSize = virFileLength(loader->nvram, -1)) < 0 ||
+(masterSize = virFileLength(masterNvramPath, -1)) < 0) {
+virReportSystemError(errno,
+ _("unable to get the size of '%s' or '%s'"),
+ loader->nvram, masterNvramPath);
+return false;
+}
+
+if (nvramSize != masterSize) {
+VIR_WARN("the size(%zd) of the nvram file is not equal to that of the 
template %s",
+ nvramSize, masterNvramPath);
+return false;
+}
+
+return true;
+}
+
+
 static int
 qemuPrepareNVRAM(virQEMUDriverConfigPtr cfg,
  virDomainObjPtr vm)
@@ -4388,9 +4430,19 @@ qemuPrepareNVRAM(virQEMUDriverConfigPtr cfg,
 const char *master_nvram_path;
 ssize_t r;

-if (!loader || !loader->nvram || virFileExists(loader->nvram))
+if (!loader || !loader->nvram)
 return 0;

+if (virFileExists(loader->nvram)) {
+if (qemuIsNvramFileHealthy(cfg, loader))
+return 0;
+
+ignore_value(virFileRemove(loader->nvram, -1, -1));
+VIR_WARN("the nvram file %s exists but may be corrupted! "
+ "Remove it and try to copy a new one from template.",
+ loader->nvram);
+}
+
 master_nvram_path = loader->templt;
 if (!loader->templt) {
 size_t i;
--
2.23.0



[PATCH] meson: fix some FreeBSD checks regressions

2020-08-08 Thread Roman Bogorodskiy
 * Add missing prerequisite headers for checking link_addr(3)
   in net/if_dl.h,
 * Add missing prerequisite headers for checking BRDGSFD, BRDGADD,
   BRDGDEL in net/if_bridgevar.h,
 * When checking for ifconfig(8), set not only IFCONFIG value,
   but also IFCONFIG_PATH as it's used in util/virnetdevip.c.

Signed-off-by: Roman Bogorodskiy 
---
 meson.build | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/meson.build b/meson.build
index 19b4795527..0913308bec 100644
--- a/meson.build
+++ b/meson.build
@@ -770,7 +770,7 @@ symbols = [
   [ 'linux/if_vlan.h', 'GET_VLAN_VID_CMD' ],
 
   # Check for BSD approach for setting MAC addr
-  [ 'net/if_dl.h', 'link_addr' ],
+  [ 'net/if_dl.h', 'link_addr', '#include \n#include 
' ],
 ]
 
 if host_machine.system() == 'linux'
@@ -791,15 +791,18 @@ if host_machine.system() == 'linux'
 endif
 
 foreach symbol : symbols
-  if cc.has_header_symbol(symbol[0], symbol[1], args: '-D_GNU_SOURCE')
+  if cc.has_header_symbol(symbol[0], symbol[1], args: '-D_GNU_SOURCE', prefix: 
symbol.get(2, ''))
 conf.set('HAVE_DECL_@0@'.format(symbol[1].to_upper()), 1)
   endif
 endforeach
 
 # Check for BSD approach for bridge management
-if (cc.has_header_symbol('net/if_bridgevar.h', 'BRDGSFD') and
-cc.has_header_symbol('net/if_bridgevar.h', 'BRDGADD') and
-cc.has_header_symbol('net/if_bridgevar.h', 'BRDGDEL'))
+brd_required_headers = '''#include 
+#include 
+#include '''
+if (cc.has_header_symbol('net/if_bridgevar.h', 'BRDGSFD', prefix: 
brd_required_headers) and
+cc.has_header_symbol('net/if_bridgevar.h', 'BRDGADD', prefix: 
brd_required_headers) and
+cc.has_header_symbol('net/if_bridgevar.h', 'BRDGDEL', prefix: 
brd_required_headers))
   conf.set('HAVE_BSD_BRIDGE_MGMT', 1)
 endif
 
@@ -900,6 +903,7 @@ foreach name : required_programs
   prog = find_program(name, required: true, dirs: libvirt_sbin_path)
   varname = name.underscorify()
   conf.set_quoted(varname.to_upper(), prog.path())
+  conf.set_quoted('@0@_PATH'.format(varname.to_upper()), prog.path())
   set_variable('@0@_prog'.format(varname), prog)
 endforeach
 
-- 
2.27.0



Re: [PATCH v3 4/6] bhyve: allow to specify host sound device

2020-08-08 Thread Roman Bogorodskiy
  Daniel P. Berrangé wrote:

> On Fri, Aug 07, 2020 at 07:09:33PM +0400, Roman Bogorodskiy wrote:
> > Allow to map sound playback and recording devices to host devices
> > using "" OSS audio backend.
> > 
> > Signed-off-by: Roman Bogorodskiy 
> > ---
> >  src/bhyve/bhyve_command.c | 26 ---
> >  src/conf/domain_conf.c| 13 ++
> >  src/conf/domain_conf.h|  4 +++
> >  src/libvirt_private.syms  |  1 +
> >  .../bhyvexml2argv-sound.args  |  2 +-
> >  .../bhyvexml2argvdata/bhyvexml2argv-sound.xml |  8 +-
> >  .../bhyvexml2xmlout-sound.xml |  5 
> >  7 files changed, 54 insertions(+), 5 deletions(-)
> > 
> > diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
> > index 1f42f71347..8e7907b882 100644
> > --- a/src/bhyve/bhyve_command.c
> > +++ b/src/bhyve/bhyve_command.c
> > @@ -478,9 +478,12 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
> >  static int
> >  bhyveBuildSoundArgStr(const virDomainDef *def G_GNUC_UNUSED,
> >virDomainSoundDefPtr sound,
> > +  virDomainAudioDefPtr audio,
> >bhyveConnPtr driver,
> >virCommandPtr cmd)
> >  {
> > +g_auto(virBuffer) params = VIR_BUFFER_INITIALIZER;
> > +
> >  if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_SOUND_HDA)) {
> >  /* Currently, bhyve only supports "hda" sound devices, so
> > if it's not supported, sound devices are not supported at all */
> > @@ -497,9 +500,24 @@ bhyveBuildSoundArgStr(const virDomainDef *def 
> > G_GNUC_UNUSED,
> >  }
> >  
> >  virCommandAddArg(cmd, "-s");
> > -virCommandAddArgFormat(cmd, "%d:%d,hda,play=/dev/dsp0",
> > +
> > +if (audio) {
> > +if (audio->type == VIR_DOMAIN_AUDIO_TYPE_OSS) {
> 
> Should use a switch() here and report enum range errors in the
> LAST/default case.
> 
> This will force us to fix bhyve when we add more audio types
> later to do proper error reporting.
> 
> > +if (audio->backend.oss.inputDev)
> > +virBufferAsprintf(¶ms, ",play=%s",
> > +  audio->backend.oss.inputDev);
> > +
> > +if (audio->backend.oss.outputDev)
> > +virBufferAsprintf(¶ms, ",rec=%s",
> > +  audio->backend.oss.outputDev);
> > +}
> > +}
> > +
> > +virCommandAddArgFormat(cmd, "%d:%d,hda%s",
> > sound->info.addr.pci.slot,
> > -   sound->info.addr.pci.function);
> > +   sound->info.addr.pci.function,
> > +   virBufferCurrentContent(¶ms));
> > +
> 
> What happens if you dont give an any play arg - does it just assume
> the default /dev/dsp0 ?

It doesn't assume these defaults. When started this way, guest will have
a sound device, but playback (and likely recording) will not work
because the sound device will fail to open.

I'm not sure what's the purpose of things configured this way.

> Regards,
> Daniel
> -- 
> |: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o-https://fstop138.berrange.com :|
> |: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|
> 

Roman Bogorodskiy


signature.asc
Description: PGP signature


[PATCH] doCoreDump: fix return value not expect as result

2020-08-08 Thread Hao Wang
From: Hao Wang 
Subject: [PATCH] doCoreDump: fix return value not expect as result

In a case that qemuDumpToFd() return zero while VIR_CLOSE(fd) fails,
codes will go to "cleanup" with "ret=0", resulting in unexpected return
value. Fix that.

Signed-off-by: Hao Wang 
---
 src/qemu/qemu_driver.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 0f98243fe4..8dfb9a38bf 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3796,6 +3796,7 @@ doCoreDump(virQEMUDriverPtr driver,
 {
 int fd = -1;
 int ret = -1;
+int rc = -1;
 virFileWrapperFdPtr wrapperFd = NULL;
 int directFlag = 0;
 unsigned int flags = VIR_FILE_WRAPPER_NON_BLOCKING;
@@ -3843,8 +3844,8 @@ doCoreDump(virQEMUDriverPtr driver,
 if (STREQ(memory_dump_format, "elf"))
 memory_dump_format = NULL;

-ret = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP,
-   memory_dump_format);
+rc = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP,
+  memory_dump_format);
 } else {
 if (dumpformat != VIR_DOMAIN_CORE_DUMP_FORMAT_RAW) {
 virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
@@ -3856,11 +3857,11 @@ doCoreDump(virQEMUDriverPtr driver,
 if (!qemuMigrationSrcIsAllowed(driver, vm, false, 0))
 goto cleanup;

-ret = qemuMigrationSrcToFile(driver, vm, fd, compressor,
- QEMU_ASYNC_JOB_DUMP);
+rc = qemuMigrationSrcToFile(driver, vm, fd, compressor,
+QEMU_ASYNC_JOB_DUMP);
 }

-if (ret < 0)
+if (rc < 0)
 goto cleanup;

 if (VIR_CLOSE(fd) < 0) {
--
2.23.0