Re: [libvirt] [PATCH 1/3] conf: Set rebootTimeout valid range to 0..0xffff

2019-10-15 Thread Michal Privoznik

On 10/15/19 7:23 AM, Han Han wrote:

Hi Michal,
Any more advice update?


Well, as I've said earlier, since we document that -1 is accepted value 
and it means that it suppresses automatic reboots we need a way to 
preserve this behaviour. For instance, what happens if you don't put 
reboot-timeout onto the cmd line at all? Does qemu use some default and 
reboot anyways? If it doesn't reboot then -1 should mean to not put 
reboot-timeout onto the cmd line. However, if it does reboot then we 
need to talk to qemu developers to provide us a way to suppress 
automatic reboots.


Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [virttools-planet PATCH] Add Fabiano Fidencio to Planet Virt-Tools

2019-10-15 Thread Fabiano Fidêncio
On Tue, Oct 15, 2019 at 10:13 AM Andrea Bolognani  wrote:
>
> On Tue, 2019-10-15 at 08:45 +0200, Fabiano Fidêncio wrote:
> > Add Fabiano Fidencio to Planet Virt-Tools
>
> s/Fidencio/Fidêncio/

This would break git publish. :-)

>
> > Signed-off-by: Fabiano Fidêncio 
> > ---
> >  updater/virt-tools/config.ini | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/updater/virt-tools/config.ini b/updater/virt-tools/config.ini
> > index 6b4b5ec..9375c82 100644
> > --- a/updater/virt-tools/config.ini
> > +++ b/updater/virt-tools/config.ini
> > @@ -194,3 +194,6 @@ name = Stefano Garzarella
> >  face = sgarzare.png
> >  facewidth = 89
> >  faceheight = 96
> > +
> > +[https://fidencio.org/tags/virt/index.xml]
> > +name = Fabiano Fidêncio
>
> Maybe publish at least one virt-related post before adding your feed
> to the Planet?

I just waiting for a review on the first part of a Libosinfo series.

Best Regards,
-- 
Fabiano Fidêncio

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [virttools-planet PATCH] Add Fabiano Fidencio to Planet Virt-Tools

2019-10-15 Thread Andrea Bolognani
On Tue, 2019-10-15 at 08:45 +0200, Fabiano Fidêncio wrote:
> Add Fabiano Fidencio to Planet Virt-Tools

s/Fidencio/Fidêncio/

> Signed-off-by: Fabiano Fidêncio 
> ---
>  updater/virt-tools/config.ini | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/updater/virt-tools/config.ini b/updater/virt-tools/config.ini
> index 6b4b5ec..9375c82 100644
> --- a/updater/virt-tools/config.ini
> +++ b/updater/virt-tools/config.ini
> @@ -194,3 +194,6 @@ name = Stefano Garzarella
>  face = sgarzare.png
>  facewidth = 89
>  faceheight = 96
> +
> +[https://fidencio.org/tags/virt/index.xml]
> +name = Fabiano Fidêncio

Maybe publish at least one virt-related post before adding your feed
to the Planet?

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [virttools-planet PATCH] Add Fabiano Fidencio to Planet Virt-Tools

2019-10-15 Thread Daniel P . Berrangé
On Tue, Oct 15, 2019 at 08:45:24AM +0200, Fabiano Fidêncio wrote:
> Signed-off-by: Fabiano Fidêncio 
> ---
>  updater/virt-tools/config.ini | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Daniel P. Berrangé 

and pushed to git


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 :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] qemu: fix EFI nvram removal on domain undefine

2019-10-15 Thread Pavel Mores
When undefining a UEFI domain its nvram file has to be properly handled as
well.  It's mandatory to use one of --nvram and --keep-nvram options when
'virsh undefine ' is issued for a UEFI domain.  To fix the bug as
reported, virsh should return an error message if neither option is used
and the nvram file should be removed when --nvram is given.

The cause of the problem is that when qemuDomainUndefineFlags() is invoked
on an inactive domain the path to its nvram file is empty.  This commit
aims to fix this by formatting and filling in the path in time for the
nvram removal code to run properly.

https://bugzilla.redhat.com/show_bug.cgi?id=1751596

Signed-off-by: Pavel Mores 
---
 src/qemu/qemu_domain.c | 12 +---
 src/qemu/qemu_domain.h |  4 
 src/qemu/qemu_driver.c | 20 +++-
 3 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 35067c851f..1a0367cc27 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -15441,16 +15441,22 @@ 
qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk)
 }
 
 
+int
+qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg,
+virDomainDefPtr def, char **path)
+{
+return virAsprintf(path, "%s/%s_VARS.fd", cfg->nvramDir, def->name);
+}
+
 int
 qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg,
 virDomainDefPtr def)
 {
 if (def->os.loader &&
 def->os.loader->type == VIR_DOMAIN_LOADER_TYPE_PFLASH &&
-def->os.loader->readonly == VIR_TRISTATE_SWITCH_ON &&
+def->os.loader->readonly == VIR_TRISTATE_BOOL_YES &&
 !def->os.loader->nvram) {
-return virAsprintf(&def->os.loader->nvram, "%s/%s_VARS.fd",
-   cfg->nvramDir, def->name);
+return qemuDomainNVRAMPathFormat(cfg, def, &def->os.loader->nvram);
 }
 
 return 0;
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 01a54d4265..07725c7cc4 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1207,6 +1207,10 @@ qemuDomainIsUsingNoShutdown(qemuDomainObjPrivatePtr 
priv);
 bool
 qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk);
 
+int
+qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg,
+virDomainDefPtr def, char **path);
+
 int
 qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg,
 virDomainDefPtr def);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index bc0ede2fb0..dcaadbdb52 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7828,6 +7828,8 @@ qemuDomainUndefineFlags(virDomainPtr dom,
 int nsnapshots;
 int ncheckpoints;
 virQEMUDriverConfigPtr cfg = NULL;
+char *nvram_path = NULL;
+bool need_deallocate_nvram_path = false;
 
 virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |
   VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA |
@@ -7905,14 +7907,20 @@ qemuDomainUndefineFlags(virDomainPtr dom,
 }
 }
 
-if (vm->def->os.loader &&
-vm->def->os.loader->nvram &&
-virFileExists(vm->def->os.loader->nvram)) {
+if (vm->def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) {
+qemuDomainNVRAMPathFormat(cfg, vm->def, &nvram_path);
+need_deallocate_nvram_path = true;
+} else {
+if (vm->def->os.loader)
+nvram_path = vm->def->os.loader->nvram;
+}
+
+if (nvram_path && virFileExists(nvram_path)) {
 if ((flags & VIR_DOMAIN_UNDEFINE_NVRAM)) {
-if (unlink(vm->def->os.loader->nvram) < 0) {
+if (unlink(nvram_path) < 0) {
 virReportSystemError(errno,
  _("failed to remove nvram: %s"),
- vm->def->os.loader->nvram);
+ nvram_path);
 goto endjob;
 }
 } else if (!(flags & VIR_DOMAIN_UNDEFINE_KEEP_NVRAM)) {
@@ -7948,6 +7956,8 @@ qemuDomainUndefineFlags(virDomainPtr dom,
 virDomainObjEndAPI(&vm);
 virObjectEventStateQueue(driver->domainEventState, event);
 virObjectUnref(cfg);
+if (need_deallocate_nvram_path)
+VIR_FREE(nvram_path);
 return ret;
 }
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 24/35] security: use G_GNUC_UNUSED

2019-10-15 Thread Michal Privoznik

On 10/14/19 3:15 PM, Ján Tomko wrote:

Use G_GNUC_UNUSED from GLib instead of ATTRIBUTE_UNUSED.

Signed-off-by: Ján Tomko 
---
  src/security/security_apparmor.c |  88 
  src/security/security_dac.c  | 114 ++--
  src/security/security_manager.c  |   6 +-
  src/security/security_nop.c  | 174 +++
  src/security/security_selinux.c  |  54 +-
  src/security/security_stack.c|   8 +-
  src/security/security_util.c |   6 +-
  src/security/virt-aa-helper.c|   4 +-
  8 files changed, 227 insertions(+), 227 deletions(-)


As you perhaps already know, this needs to be rebased. But the conflict 
resolution is trivial. Also, there's one new occurance in 
virSecuritySELinuxSetAllLabel() that needs updating and squashing into 
this patch.


Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 06/35] examples: use G_GNUC_UNUSED

2019-10-15 Thread Michal Privoznik

On 10/14/19 3:15 PM, Ján Tomko wrote:

Name the macro G_GNUC_UNUSED instead of ATTRIBUTE_UNUSED
to match the rest of libvirt code.

Signed-off-by: Ján Tomko 
---
  examples/c/misc/event-test.c | 140 +--
  1 file changed, 70 insertions(+), 70 deletions(-)

diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c
index fcf4492470..533b8da9bf 100644
--- a/examples/c/misc/event-test.c
+++ b/examples/c/misc/event-test.c
@@ -21,17 +21,17 @@
  # define verify(cond)
  #endif
  
-#ifndef ATTRIBUTE_UNUSED

-# define ATTRIBUTE_UNUSED __attribute__((__unused__))
+#ifndef G_GNUC_UNUSED
+# define G_GNUC_UNUSED __attribute__((__unused__))
  #endif


Now, that we no longer use ATTRIBUTE_UNUSED - a private macro, can't we 
just #include  here and drop this definition? This example is 
linked with glib anyways since it's linking with libvirt.so so we 
wouldn't be dragging in any dependency.


Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PULL 01/19] util/hbitmap: strict hbitmap_reset

2019-10-15 Thread Kevin Wolf
Am 14.10.2019 um 20:10 hat John Snow geschrieben:
> 
> 
> On 10/11/19 7:18 PM, John Snow wrote:
> > 
> > 
> > On 10/11/19 5:48 PM, Eric Blake wrote:
> >> On 10/11/19 4:25 PM, John Snow wrote:
> >>> From: Vladimir Sementsov-Ogievskiy 
> >>>
> >>> hbitmap_reset has an unobvious property: it rounds requested region up.
> >>> It may provoke bugs, like in recently fixed write-blocking mode of
> >>> mirror: user calls reset on unaligned region, not keeping in mind that
> >>> there are possible unrelated dirty bytes, covered by rounded-up region
> >>> and information of this unrelated "dirtiness" will be lost.
> >>>
> >>> Make hbitmap_reset strict: assert that arguments are aligned, allowing
> >>> only one exception when @start + @count == hb->orig_size. It's needed
> >>> to comfort users of hbitmap_next_dirty_area, which cares about
> >>> hb->orig_size.
> >>>
> >>> Signed-off-by: Vladimir Sementsov-Ogievskiy 
> >>> Reviewed-by: Max Reitz 
> >>> Message-Id: <20190806152611.280389-1-vsement...@virtuozzo.com>
> >>> [Maintainer edit: Max's suggestions from on-list. --js]
> >>> Signed-off-by: John Snow 
> >>> ---
> >>>   include/qemu/hbitmap.h | 5 +
> >>>   tests/test-hbitmap.c   | 2 +-
> >>>   util/hbitmap.c | 4 
> >>>   3 files changed, 10 insertions(+), 1 deletion(-)
> >>>
> >>
> >>> +++ b/util/hbitmap.c
> >>> @@ -476,6 +476,10 @@ void hbitmap_reset(HBitmap *hb, uint64_t start,
> >>> uint64_t count)
> >>>   /* Compute range in the last layer.  */
> >>>   uint64_t first;
> >>>   uint64_t last = start + count - 1;
> >>> +    uint64_t gran = 1ULL << hb->granularity;
> >>> +
> >>> +    assert(!(start & (gran - 1)));
> >>> +    assert(!(count & (gran - 1)) || (start + count == hb->orig_size));
> >>
> >> I know I'm replying a bit late (since this is now a pull request), but
> >> would it be worth using the dedicated macro:
> >>
> >> assert(QEMU_IS_ALIGNED(start, gran));
> >> assert(QEMU_IS_ALIGNED(count, gran) || start + count == hb->orig_size);
> >>
> >> instead of open-coding it?  (I would also drop the extra () around the
> >> right half of ||). If we want it, that would now be a followup patch.
> 
> I've noticed that seasoned C programmers hate extra parentheses a lot.
> I've noticed that I cannot remember operator precedence enough to ever
> feel like this is actually an improvement.
> 
> Something about a nice weighted tree of ((expr1) || (expr2)) feels
> soothing to my weary eyes. So, if it's not terribly important, I'd
> prefer to leave it as-is.

I don't mind the parentheses, but I do prefer QEMU_IS_ALIGNED() to the
open-coded version. Would that be a viable compromise?

Kevin

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 00/35] Use more of GLib's macros

2019-10-15 Thread Michal Privoznik

On 10/14/19 3:15 PM, Ján Tomko wrote:

We do not need to define MIN and MAX if we include glib.h
and it also provides some macros for __attribute__'s

Ján Tomko (35):
   util: remove MIN and MAX macros
   apibuild: ignore GLib macros too
   use G_GNUC_NORETURN instead of ATTRIBUTE_NORETURN
   use G_GNUC_NULL_TERMINATED instead of ATTRIBUTE_SENTINEL
   Use G_GNUC_WARN_UNUSED_RESULT instead of ATTRIBUTE_RETURN_CHECK
   examples: use G_GNUC_UNUSED
   access: use G_GNUC_UNUSED
   admin: use G_GNUC_UNUSED
   bhyve: use G_GNUC_UNUSED
   conf: use G_GNUC_UNUSED
   cpu: use G_GNUC_UNUSED
   esx: use G_GNUC_UNUSED
   libxl: use G_GNUC_UNUSED
   locking: use G_GNUC_UNUSED
   logging: use G_GNUC_UNUSED
   lxc: use G_GNUC_UNUSED
   network: use G_GNUC_UNUSED
   node_device: use G_GNUC_UNUSED
   nwfilter: use G_GNUC_UNUSED
   openvz: use G_GNUC_UNUSED
   qemu: use G_GNUC_UNUSED
   remote: use G_GNUC_UNUSED
   rpc: use G_GNUC_UNUSED
   security: use G_GNUC_UNUSED
   storage: use G_GNUC_UNUSED
   test: use G_GNUC_UNUSED
   tests: use G_GNUC_UNUSED
   tools: use G_GNUC_UNUSED
   util: use G_GNUC_UNUSED
   vbox: use G_GNUC_UNUSED
   vz: use G_GNUC_UNUSED
   Use G_GNUC_UNUSED everywhere
   syntax-check: check for G_GNUC_UNUSED instead of ATTRIBUTE_UNUSED
   gendispatch: generate G_GNUC_UNUSED instead of ATTRIBUTE_UNUSED
   internal: remove no longer used ATTRIBUTE macros

  build-aux/syntax-check.mk |  12 +-
  docs/apibuild.py  |   4 +-
  examples/c/misc/event-test.c  | 140 +++
  src/access/viraccessdrivernop.c   |  90 ++---
  src/access/viraccessdriverpolkit.c|   4 +-
  src/admin/admin_remote.c  |   4 +-
  src/admin/admin_server_dispatch.c |  62 +--
  src/bhyve/bhyve_command.c |   6 +-
  src/bhyve/bhyve_device.c  |   4 +-
  src/bhyve/bhyve_domain.c  |  26 +-
  src/bhyve/bhyve_driver.c  |  16 +-
  src/bhyve/bhyve_monitor.c |   2 +-
  src/bhyve/bhyve_parse_command.c   |   8 +-
  src/bhyve/bhyve_process.c |   2 +-
  src/conf/capabilities.c   |   6 +-
  src/conf/device_conf.h|   2 +-
  src/conf/domain_addr.c|  22 +-
  src/conf/domain_audit.c   |   2 +-
  src/conf/domain_capabilities.c|   2 +-
  src/conf/domain_conf.c|  30 +-
  src/conf/domain_conf.h|  38 +-
  src/conf/domain_event.c   |   2 +-
  src/conf/netdev_bandwidth_conf.h  |   2 +-
  src/conf/network_conf.c   |  80 ++--
  src/conf/node_device_conf.c   |  10 +-
  src/conf/nwfilter_conf.c  |  50 +--
  src/conf/nwfilter_params.c|   2 +-
  src/conf/object_event.c   |   2 +-
  src/conf/virchrdev.c  |  10 +-
  src/conf/virdomaincheckpointobjlist.c |   2 +-
  src/conf/virdomainmomentobjlist.c |   6 +-
  src/conf/virdomainobjlist.c   |  12 +-
  src/conf/virinterfaceobj.c|  10 +-
  src/conf/virnetworkobj.c  |  18 +-
  src/conf/virnetworkobj.h  |   2 +-
  src/conf/virnodedeviceobj.c   |  16 +-
  src/conf/virnwfilterbindingobjlist.c  |   4 +-
  src/conf/virsecretobj.c   |   8 +-
  src/conf/virstorageobj.c  |  22 +-
  src/cpu/cpu_arm.c |  14 +-
  src/cpu/cpu_ppc64.c   |  10 +-
  src/cpu/cpu_s390.c|   6 +-
  src/cpu/cpu_x86.c |   4 +-
  src/driver.h  |  18 +-
  src/esx/esx_driver.c  |  32 +-
  src/esx/esx_interface_driver.c|  10 +-
  src/esx/esx_network_driver.c  |  16 +-
  src/esx/esx_storage_backend_iscsi.c   |  16 +-
  src/esx/esx_storage_driver.c  |  16 +-
  src/esx/esx_vi.c  |  20 +-
  src/esx/esx_vi_types.c|   4 +-
  src/hyperv/hyperv_driver.c|  12 +-
  src/hyperv/hyperv_wmi.c   |   2 +-
  src/interface/interface_backend_netcf.c   |  16 +-
  src/interface/interface_backend_udev.c|  26 +-
  src/internal.h|  31 --
  src/libvirt.c |   8 +-
  src/libxl/libxl_conf.h|   2 +-
  src/libxl/libxl_domain.c  |  26 +-
  src/libxl/libxl_domain.h  |   4 +-
  src/libxl/libxl_driver.c  |  70 ++--
  src/libxl/libxl_logger.c  |  14 +-
  src/libxl/libxl_migration.c   |  12 +-
  src/locking/lock_daemon.c |  20 +-
  src/locking/lock_daemon_config.c  |   2 +-
  src/locking/lock_daemon_dispatch.c|  32 +-
  src/locking/lock_driver_lockd.c   |   8 +-
  src/locking/lock_driver_nop.c |  48 +--
  

Re: [libvirt] [PATCH 00/35] Use more of GLib's macros

2019-10-15 Thread Ján Tomko

On Tue, Oct 15, 2019 at 10:40:35AM +0200, Michal Privoznik wrote:

On 10/14/19 3:15 PM, Ján Tomko wrote:

We do not need to define MIN and MAX if we include glib.h
and it also provides some macros for __attribute__'s

Ján Tomko (35):
  util: remove MIN and MAX macros
  apibuild: ignore GLib macros too
  use G_GNUC_NORETURN instead of ATTRIBUTE_NORETURN
  use G_GNUC_NULL_TERMINATED instead of ATTRIBUTE_SENTINEL
  Use G_GNUC_WARN_UNUSED_RESULT instead of ATTRIBUTE_RETURN_CHECK
  examples: use G_GNUC_UNUSED
  access: use G_GNUC_UNUSED
  admin: use G_GNUC_UNUSED
  bhyve: use G_GNUC_UNUSED
  conf: use G_GNUC_UNUSED
  cpu: use G_GNUC_UNUSED
  esx: use G_GNUC_UNUSED
  libxl: use G_GNUC_UNUSED
  locking: use G_GNUC_UNUSED
  logging: use G_GNUC_UNUSED
  lxc: use G_GNUC_UNUSED
  network: use G_GNUC_UNUSED
  node_device: use G_GNUC_UNUSED
  nwfilter: use G_GNUC_UNUSED
  openvz: use G_GNUC_UNUSED
  qemu: use G_GNUC_UNUSED
  remote: use G_GNUC_UNUSED
  rpc: use G_GNUC_UNUSED
  security: use G_GNUC_UNUSED
  storage: use G_GNUC_UNUSED
  test: use G_GNUC_UNUSED
  tests: use G_GNUC_UNUSED
  tools: use G_GNUC_UNUSED
  util: use G_GNUC_UNUSED
  vbox: use G_GNUC_UNUSED
  vz: use G_GNUC_UNUSED
  Use G_GNUC_UNUSED everywhere
  syntax-check: check for G_GNUC_UNUSED instead of ATTRIBUTE_UNUSED
  gendispatch: generate G_GNUC_UNUSED instead of ATTRIBUTE_UNUSED
  internal: remove no longer used ATTRIBUTE macros



[...]


 370 files changed, 3672 insertions(+), 3710 deletions(-)



Reviewed-by: Michal Privoznik 

I've identified other macros of ours that might be worth converting too:

 ATTRIBUTE_FALLTHROUGH


G_GNUC_FALLTHROUGH was introduced in GLib 2.60 so not yet


 ATTRIBUTE_FMT_PRINTF


Right, I missed G_GNUC_PRINTF - thought there is only the G_GNUC_FORMAT
variant that only takes one argument


 ATTRIBUTE_FORMAT


We stopped using ATTRIBUTE_FORMAT in 2009:
commit 899ae0d2b52a560ac67104b4ba2f234bfada9df7


 ATTRIBUTE_NOINLINE


G_GNUC_NO_INLINE was introduced by GLib 2.58


 ATTRIBUTE_NONNULL


I did not find a GLib equivalent here. Also, we define it to nothing
unless compiling for static analysis.


 ATTRIBUTE_PACKED


No GLib equivalent either.


 ATTRIBUTE_RETURN_CHECK
 ATTRIBUTE_SENTINEL
 ATTRIBUTE_UNUSED


These were handled by this series.

Jano



Michal


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 06/35] examples: use G_GNUC_UNUSED

2019-10-15 Thread Ján Tomko

On Tue, Oct 15, 2019 at 10:40:47AM +0200, Michal Privoznik wrote:

On 10/14/19 3:15 PM, Ján Tomko wrote:

Name the macro G_GNUC_UNUSED instead of ATTRIBUTE_UNUSED
to match the rest of libvirt code.

Signed-off-by: Ján Tomko 
---
 examples/c/misc/event-test.c | 140 +--
 1 file changed, 70 insertions(+), 70 deletions(-)

diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c
index fcf4492470..533b8da9bf 100644
--- a/examples/c/misc/event-test.c
+++ b/examples/c/misc/event-test.c
@@ -21,17 +21,17 @@
 # define verify(cond)
 #endif
-#ifndef ATTRIBUTE_UNUSED
-# define ATTRIBUTE_UNUSED __attribute__((__unused__))
+#ifndef G_GNUC_UNUSED
+# define G_GNUC_UNUSED __attribute__((__unused__))
 #endif


Now, that we no longer use ATTRIBUTE_UNUSED - a private macro, can't 
we just #include  here and drop this definition? This example 
is linked with glib anyways since it's linking with libvirt.so so we 
wouldn't be dragging in any dependency.


Having libvirt.so and glib.so does not necessarily mean you need to have
the GLib headers installed.

The idea for examples is to use base C with no other dependencies than
libvirt, see e.g.:

commit acf522e85a9747457e6d81a6cae9eef1cf677ff0
   examples: Avoid gnulib, have standalone examples

or

commit 6933ebc497f5b432c0dc8c89450a2723c45371bd
   examples: Drop event-test.c dependency on gnulib 


Jano



Michal


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 00/35] Use more of GLib's macros

2019-10-15 Thread Andrea Bolognani
On Tue, 2019-10-15 at 10:53 +0200, Ján Tomko wrote:
> On Tue, Oct 15, 2019 at 10:40:35AM +0200, Michal Privoznik wrote:
> > I've identified other macros of ours that might be worth converting too:
> > 
> >  ATTRIBUTE_FALLTHROUGH
> 
> G_GNUC_FALLTHROUGH was introduced in GLib 2.60 so not yet
> 
> >  ATTRIBUTE_NOINLINE
> 
> G_GNUC_NO_INLINE was introduced by GLib 2.58

We should convert our code to use the GLib variant, and define it
ourself when it's not present; once our minimum required GLib version
has been increased appropriately, we can simply drop our definitions.

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] qemu: fix EFI nvram removal on domain undefine

2019-10-15 Thread Michal Privoznik

On 10/15/19 10:31 AM, Pavel Mores wrote:

When undefining a UEFI domain its nvram file has to be properly handled as
well.  It's mandatory to use one of --nvram and --keep-nvram options when
'virsh undefine ' is issued for a UEFI domain.  To fix the bug as
reported, virsh should return an error message if neither option is used
and the nvram file should be removed when --nvram is given.

The cause of the problem is that when qemuDomainUndefineFlags() is invoked
on an inactive domain the path to its nvram file is empty.  This commit
aims to fix this by formatting and filling in the path in time for the
nvram removal code to run properly.

https://bugzilla.redhat.com/show_bug.cgi?id=1751596

Signed-off-by: Pavel Mores 
---
  src/qemu/qemu_domain.c | 12 +---
  src/qemu/qemu_domain.h |  4 
  src/qemu/qemu_driver.c | 20 +++-
  3 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 35067c851f..1a0367cc27 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -15441,16 +15441,22 @@ 
qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk)
  }
  
  
+int

+qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg,
+virDomainDefPtr def, char **path)
+{
+return virAsprintf(path, "%s/%s_VARS.fd", cfg->nvramDir, def->name);
+}
+


We have two empty lines between functions in this file. And Also, one 
argument per line please.



  int
  qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg,
  virDomainDefPtr def)
  {
  if (def->os.loader &&
  def->os.loader->type == VIR_DOMAIN_LOADER_TYPE_PFLASH &&
-def->os.loader->readonly == VIR_TRISTATE_SWITCH_ON &&
+def->os.loader->readonly == VIR_TRISTATE_BOOL_YES &&
  !def->os.loader->nvram) {
-return virAsprintf(&def->os.loader->nvram, "%s/%s_VARS.fd",
-   cfg->nvramDir, def->name);
+return qemuDomainNVRAMPathFormat(cfg, def, &def->os.loader->nvram);
  }
  
  return 0;

diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 01a54d4265..07725c7cc4 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1207,6 +1207,10 @@ qemuDomainIsUsingNoShutdown(qemuDomainObjPrivatePtr 
priv);
  bool
  qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk);
  
+int

+qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg,
+virDomainDefPtr def, char **path);
+
  int
  qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg,
  virDomainDefPtr def);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index bc0ede2fb0..dcaadbdb52 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7828,6 +7828,8 @@ qemuDomainUndefineFlags(virDomainPtr dom,
  int nsnapshots;
  int ncheckpoints;
  virQEMUDriverConfigPtr cfg = NULL;
+char *nvram_path = NULL;
+bool need_deallocate_nvram_path = false;


While this works, I'd rather have @nvram_path autofreed, and ... [1]

  
  virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |

VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA |
@@ -7905,14 +7907,20 @@ qemuDomainUndefineFlags(virDomainPtr dom,
  }
  }
  
-if (vm->def->os.loader &&

-vm->def->os.loader->nvram &&
-virFileExists(vm->def->os.loader->nvram)) {
+if (vm->def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) {
+qemuDomainNVRAMPathFormat(cfg, vm->def, &nvram_path);


This needs a check for retval.


+need_deallocate_nvram_path = true;
+} else {
+if (vm->def->os.loader)
+nvram_path = vm->def->os.loader->nvram;


1: ... duplicate path here.


+}
+
+if (nvram_path && virFileExists(nvram_path)) {
  if ((flags & VIR_DOMAIN_UNDEFINE_NVRAM)) {
-if (unlink(vm->def->os.loader->nvram) < 0) {
+if (unlink(nvram_path) < 0) {
  virReportSystemError(errno,
   _("failed to remove nvram: %s"),
- vm->def->os.loader->nvram);
+ nvram_path);
  goto endjob;
  }
  } else if (!(flags & VIR_DOMAIN_UNDEFINE_KEEP_NVRAM)) {
@@ -7948,6 +7956,8 @@ qemuDomainUndefineFlags(virDomainPtr dom,
  virDomainObjEndAPI(&vm);
  virObjectEventStateQueue(driver->domainEventState, event);
  virObjectUnref(cfg);
+if (need_deallocate_nvram_path)
+VIR_FREE(nvram_path);
  return ret;
  }
  



Reviewed-by: Michal Privoznik  and pushed.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PULL 00/19] Bitmaps patches

2019-10-15 Thread Peter Maydell
On Fri, 11 Oct 2019 at 22:26, John Snow  wrote:
>
> The following changes since commit 98b2e3c9ab3abfe476a2b02f8f51813edb90e72d:
>
>   Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' 
> into staging (2019-10-08 16:08:35 +0100)
>
> are available in the Git repository at:
>
>   https://github.com/jnsnow/qemu.git tags/bitmaps-pull-request
>
> for you to fetch changes up to b97d9a1014b61dd0980e7f4a0c9ca1e3b0aaa761:
>
>   dirty-bitmaps: remove deprecated autoload parameter (2019-10-09 17:02:45 
> -0400)
>
> 
> Pull request
>
> 
>

Hi -- this has a conflict in block/backup.c -- could you fix up
and resend, please ?

thanks
-- PMM

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [virttools-planet PATCH] Add Fabiano Fidencio to Planet Virt-Tools

2019-10-15 Thread Ján Tomko

On Tue, Oct 15, 2019 at 10:20:12AM +0200, Fabiano Fidêncio wrote:

On Tue, Oct 15, 2019 at 10:13 AM Andrea Bolognani  wrote:


On Tue, 2019-10-15 at 08:45 +0200, Fabiano Fidêncio wrote:
> Add Fabiano Fidencio to Planet Virt-Tools

s/Fidencio/Fidêncio/


This would break git publish. :-)



Hopefully you filed a bug for it.

Jano



> Signed-off-by: Fabiano Fidêncio 
> ---
>  updater/virt-tools/config.ini | 3 +++
>  1 file changed, 3 insertions(+)
>


signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 1/8] syntax-check: mock-noinline: fix after G_GNUC attribute invocations

2019-10-15 Thread Ján Tomko
We started using G_GNUC macros instead of ATTRIBUTE for some attributes.
Adjust this syntax-check accordingly.

Signed-off-by: Ján Tomko 
---
 build-aux/mock-noinline.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build-aux/mock-noinline.pl b/build-aux/mock-noinline.pl
index 958e133885..db5420825f 100644
--- a/build-aux/mock-noinline.pl
+++ b/build-aux/mock-noinline.pl
@@ -40,7 +40,7 @@ sub scan_annotations {
 while () {
 if (/^\s*(\w+)\(/ || /^(?:\w+\*?\s+)+(?:\*\s*)?(\w+)\(/) {
 my $name = $1;
-if ($name !~ /ATTRIBUTE/) {
+if ($name !~ /(?:G_GNUC|ATTRIBUTE)/) {
 $func = $name;
 }
 } elsif (/^\s*$/) {
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 3/8] Use G_GNUC_NO_INLINE instead of ATTRIBUTE_NOINLINE

2019-10-15 Thread Ján Tomko
Define the macro for older GLib versions.

Signed-off-by: Ján Tomko 
---
 build-aux/mock-noinline.pl  |  2 +-
 build-aux/syntax-check.mk   |  2 +-
 src/internal.h  |  8 +---
 src/qemu/qemu_capspriv.h|  2 +-
 src/rpc/virnetsocket.h  |  4 ++--
 src/util/vircommand.h   |  2 +-
 src/util/virfile.h  | 16 
 src/util/virhashcode.h  |  2 +-
 src/util/virhostcpu.h   |  4 ++--
 src/util/virhostuptime.h|  2 +-
 src/util/virmacaddr.h   |  2 +-
 src/util/virnetdev.h| 10 +-
 src/util/virnetdevip.h  |  2 +-
 src/util/virnetdevmacvlan.h |  2 +-
 src/util/virnetdevopenvswitch.h |  2 +-
 src/util/virnetdevtap.h |  6 +++---
 src/util/virnuma.h  | 16 
 src/util/virprocess.h   |  4 ++--
 src/util/virrandom.h|  6 +++---
 src/util/virscsi.h  |  2 +-
 src/util/virscsivhost.h |  2 +-
 src/util/virtpm.h   |  2 +-
 src/util/virutil.h  | 12 ++--
 src/util/viruuid.h  |  2 +-
 24 files changed, 58 insertions(+), 56 deletions(-)

diff --git a/build-aux/mock-noinline.pl b/build-aux/mock-noinline.pl
index db5420825f..b005b8d95e 100644
--- a/build-aux/mock-noinline.pl
+++ b/build-aux/mock-noinline.pl
@@ -46,7 +46,7 @@ sub scan_annotations {
 } elsif (/^\s*$/) {
 $func = undef;
 }
-if (/ATTRIBUTE_NOINLINE/) {
+if (/G_GNUC_NO_INLINE/) {
 if (defined $func) {
 $noninlined{$func} = 1;
 }
diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk
index c0612a3319..c8ca6279a2 100644
--- a/build-aux/syntax-check.mk
+++ b/build-aux/syntax-check.mk
@@ -629,7 +629,7 @@ sc_avoid_g_gnuc_unused_in_header:
  $(_sc_search_regexp)
 
 sc_prohibit_attribute_macros:
-   @prohibit='ATTRIBUTE_(UNUSED|NORETURN|SENTINEL|RETURN_CHECK)' \
+   @prohibit='ATTRIBUTE_(UNUSED|NORETURN|SENTINEL|RETURN_CHECK|NOINLINE)' \
in_vc_files='\.[ch]$$' \
halt='use GLib macros: G_GNUC_ for most' \
  $(_sc_search_regexp)
diff --git a/src/internal.h b/src/internal.h
index 7737d9a209..e2e27342d7 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -94,13 +94,15 @@
 #define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array)))
 
 /**
- * ATTRIBUTE_NOINLINE:
+ * G_GNUC_NO_INLINE:
  *
  * Force compiler not to inline a method. Should be used if
  * the method need to be overridable by test mocks.
+ *
+ * TODO: Remove after upgrading to GLib >= 2.58
  */
-#ifndef ATTRIBUTE_NOINLINE
-# define ATTRIBUTE_NOINLINE __attribute__((__noinline__))
+#ifndef G_GNUC_NO_INLINE
+# define G_GNUC_NO_INLINE __attribute__((__noinline__))
 #endif
 
 /**
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
index 6b54e94fd3..e8fe48d8f0 100644
--- a/src/qemu/qemu_capspriv.h
+++ b/src/qemu/qemu_capspriv.h
@@ -83,7 +83,7 @@ virQEMUCapsGetCPUModelX86Data(virQEMUCapsPtr qemuCaps,
 
 virCPUDefPtr
 virQEMUCapsProbeHostCPU(virArch hostArch,
-virDomainCapsCPUModelsPtr models) ATTRIBUTE_NOINLINE;
+virDomainCapsCPUModelsPtr models) G_GNUC_NO_INLINE;
 
 void
 virQEMUCapsSetGICCapabilities(virQEMUCapsPtr qemuCaps,
diff --git a/src/rpc/virnetsocket.h b/src/rpc/virnetsocket.h
index 2f626cb08f..8d075464cb 100644
--- a/src/rpc/virnetsocket.h
+++ b/src/rpc/virnetsocket.h
@@ -136,10 +136,10 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
 gid_t *gid,
 pid_t *pid,
 unsigned long long *timestamp)
-ATTRIBUTE_NOINLINE;
+G_GNUC_NO_INLINE;
 int virNetSocketGetSELinuxContext(virNetSocketPtr sock,
   char **context)
-ATTRIBUTE_NOINLINE;
+G_GNUC_NO_INLINE;
 
 int virNetSocketSetBlocking(virNetSocketPtr sock,
 bool blocking);
diff --git a/src/util/vircommand.h b/src/util/vircommand.h
index 6bc1ef87b0..10961a328f 100644
--- a/src/util/vircommand.h
+++ b/src/util/vircommand.h
@@ -58,7 +58,7 @@ typedef enum {
 
 void virCommandPassFD(virCommandPtr cmd,
   int fd,
-  unsigned int flags) ATTRIBUTE_NOINLINE;
+  unsigned int flags) G_GNUC_NO_INLINE;
 
 int virCommandPassFDGetFDIndex(virCommandPtr cmd,
int fd);
diff --git a/src/util/virfile.h b/src/util/virfile.h
index a66e3569a3..555e6ebee7 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -114,9 +114,9 @@ int virFileWrapperFdClose(virFileWrapperFdPtr dfd);
 void virFileWrapperFdFree(virFileWrapperFdPtr dfd);
 
 int virFileLock(int fd, bool shared, off_t start, off_t len, bool waitForLock)
-ATTRIBUTE_NOINLINE;
+G_GNUC_NO_INLINE;
 int virFileUnlock(int fd, off_t start, off_t len)
-ATTRIBUTE_NOINLINE;
+G_GNUC_NO_INLINE;
 
 int virFileFlock(int fd, b

[libvirt] [PATCH 5/8] Document the ATTRIBUTE_FALLTHROUGH macro

2019-10-15 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/internal.h | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/src/internal.h b/src/internal.h
index 0825e63993..1f70123e47 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -135,6 +135,13 @@
 # endif
 #endif
 
+/**
+ *
+ * ATTRIBUTE_FALLTHROUGH
+ *
+ * silence the compiler warning when falling through a switch case
+ *
+ */
 #ifndef ATTRIBUTE_FALLTHROUGH
 # if __GNUC_PREREQ (7, 0)
 #  define ATTRIBUTE_FALLTHROUGH __attribute__((fallthrough))
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 6/8] Use G_GNUC_FALLTHROUGH instead of ATTRIBUTE_FALLTHROUGH

2019-10-15 Thread Ján Tomko
Also define the macro for building with GLib older than 2.60

Signed-off-by: Ján Tomko 
---
 build-aux/syntax-check.mk   |  2 +-
 src/conf/domain_conf.c  |  8 
 src/conf/network_conf.c |  2 +-
 src/conf/nwfilter_conf.c| 14 +++---
 src/cpu/cpu_ppc64.c |  2 +-
 src/internal.h  |  9 +
 src/libvirt-domain.c|  2 +-
 src/libxl/libxl_conf.c  |  2 +-
 src/lxc/lxc_container.c |  2 +-
 src/network/bridge_driver.c |  8 
 src/network/leaseshelper.c  |  4 ++--
 src/qemu/qemu_command.c |  4 ++--
 src/qemu/qemu_domain.c  |  6 +++---
 src/qemu/qemu_driver.c  |  4 ++--
 src/qemu/qemu_hotplug.c |  4 ++--
 src/qemu/qemu_migration.c   |  4 ++--
 src/qemu/qemu_process.c |  2 +-
 src/remote/remote_driver.c  |  2 +-
 src/util/virconf.c  |  2 +-
 src/util/virhashcode.c  |  6 +++---
 src/util/viriscsi.c |  2 +-
 src/util/virutil.c  | 10 +-
 tools/virsh-domain.c|  4 ++--
 tools/virsh-edit.c  |  2 +-
 tools/virsh.c   |  2 +-
 tools/virt-admin.c  |  2 +-
 26 files changed, 56 insertions(+), 55 deletions(-)

diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk
index cfcc339c95..63b9ce70f6 100644
--- a/build-aux/syntax-check.mk
+++ b/build-aux/syntax-check.mk
@@ -629,7 +629,7 @@ sc_avoid_g_gnuc_unused_in_header:
  $(_sc_search_regexp)
 
 sc_prohibit_attribute_macros:
-   
@prohibit='ATTRIBUTE_(UNUSED|NORETURN|SENTINEL|RETURN_CHECK|NOINLINE|FMT_PRINTF)'
 \
+   
@prohibit='ATTRIBUTE_(UNUSED|NORETURN|SENTINEL|RETURN_CHECK|NOINLINE|FMT_PRINTF|FALLTHROUGH)'
 \
in_vc_files='\.[ch]$$' \
halt='use GLib macros: G_GNUC_ for most' \
  $(_sc_search_regexp)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6bd2d4935d..c128d34ba2 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -17486,7 +17486,7 @@ virDomainChrEquals(virDomainChrDefPtr src,
 if (src->targetType != tgt->targetType)
 return false;
 
-ATTRIBUTE_FALLTHROUGH;
+G_GNUC_FALLTHROUGH;
 
 case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
 case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
@@ -20290,7 +20290,7 @@ virDomainDefParseXML(xmlDocPtr xml,
 def->apic_eoi = eoi;
 VIR_FREE(tmp);
 }
-ATTRIBUTE_FALLTHROUGH;
+G_GNUC_FALLTHROUGH;
 case VIR_DOMAIN_FEATURE_ACPI:
 case VIR_DOMAIN_FEATURE_PAE:
 case VIR_DOMAIN_FEATURE_VIRIDIAN:
@@ -31205,7 +31205,7 @@ virDomainNetResolveActualType(virDomainNetDefPtr iface)
 /* intentionally fall through to the direct case for
  * VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined
  */
-ATTRIBUTE_FALLTHROUGH;
+G_GNUC_FALLTHROUGH;
 
 case VIR_NETWORK_FORWARD_PRIVATE:
 case VIR_NETWORK_FORWARD_VEPA:
@@ -31471,7 +31471,7 @@ virDomainDiskTranslateSourcePool(virDomainDiskDefPtr 
def)
case VIR_STORAGE_SOURCE_POOL_MODE_DEFAULT:
case VIR_STORAGE_SOURCE_POOL_MODE_LAST:
def->src->srcpool->mode = VIR_STORAGE_SOURCE_POOL_MODE_HOST;
-   ATTRIBUTE_FALLTHROUGH;
+   G_GNUC_FALLTHROUGH;
case VIR_STORAGE_SOURCE_POOL_MODE_HOST:
def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK;
if (!(def->src->path = virStorageVolGetPath(vol)))
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 58a0e32dd7..75ec5ccc27 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1984,7 +1984,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt,
def->name);
 goto error;
 }
-ATTRIBUTE_FALLTHROUGH;
+G_GNUC_FALLTHROUGH;
 
 case VIR_NETWORK_FORWARD_BRIDGE:
 if (def->delay || stp || def->bridgeZone) {
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 6b7a606b64..aba12cd698 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -1863,7 +1863,7 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
 switch (datatype) {
 case DATATYPE_UINT8_HEX:
 base = 16;
-ATTRIBUTE_FALLTHROUGH;
+G_GNUC_FALLTHROUGH;
 case DATATYPE_UINT8:
 if (virStrToLong_ui(prop, NULL, base, &uint_val) 
>= 0) {
 if (uint_val <= 0xff) {
@@ -1880,7 +1880,7 @@ virNWFilterRuleDetailsParse(xmlNodePtr node,
 
 case DATATYPE_UINT16_HEX:
 base = 16;
-ATTRIBUTE_FALLTHROUGH;
+G_GNUC_FALLTHROUGH;
 case DATATYPE_UINT16:
 if (virStrToLong_ui(prop, NULL, base, &uint_val) 
>= 0) {
 if (uint_val <= 0x) {
@@ -1897,7 +189

[libvirt] [PATCH 0/8] Use even morer of GLib's macros (glib chronicles)

2019-10-15 Thread Ján Tomko
Ján Tomko (8):
  syntax-check: mock-noinline: fix after G_GNUC attribute invocations
  syntax-check: prohibit_attribute_macros: generalize error
  Use G_GNUC_NO_INLINE instead of ATTRIBUTE_NOINLINE
  Use G_GNUC_PRINTF instead of ATTRIBUTE_FMT_PRINTF
  Document the ATTRIBUTE_FALLTHROUGH macro
  Use G_GNUC_FALLTHROUGH instead of ATTRIBUTE_FALLTHROUGH
  examples: Use G_N_ELEMENTS instead of ARRAY_CARDINALITY
  Use G_N_ELEMENTS instead of ARRAY_CARDINALITY

 build-aux/mock-noinline.pl  |   4 +-
 build-aux/syntax-check.mk   |  10 ++-
 examples/c/misc/event-test.c|  26 +++
 src/access/viraccessmanager.c   |   2 +-
 src/conf/domain_capabilities.h  |   2 +-
 src/conf/domain_conf.c  |  10 +--
 src/conf/network_conf.c |   2 +-
 src/conf/nwfilter_conf.c|  14 ++--
 src/conf/storage_conf.c |   2 +-
 src/conf/virdomainsnapshotobjlist.c |   2 +-
 src/cpu/cpu.c   |   4 +-
 src/cpu/cpu_arm.c   |   2 +-
 src/cpu/cpu_ppc64.c |   6 +-
 src/cpu/cpu_s390.c  |   2 +-
 src/cpu/cpu_x86.c   |   8 +-
 src/esx/esx_vi.c|   4 +-
 src/internal.h  |  41 --
 src/libvirt-domain.c|   8 +-
 src/libvirt-host.c  |   2 +-
 src/libxl/libxl_capabilities.c  |   8 +-
 src/libxl/libxl_conf.c  |   2 +-
 src/libxl/libxl_driver.c|   2 +-
 src/libxl/libxl_logger.c|   2 +-
 src/libxl/libxl_migration.c |   4 +-
 src/libxl/xen_xl.c  |   2 +-
 src/locking/domain_lock.c   |   4 +-
 src/locking/lock_daemon.c   |   4 +-
 src/locking/sanlock_helper.c|   2 +-
 src/logging/log_daemon.c|   4 +-
 src/lxc/lxc_container.c |   8 +-
 src/lxc/lxc_controller.c|   2 +-
 src/lxc/lxc_monitor.c   |   2 +-
 src/network/bridge_driver.c |   8 +-
 src/network/leaseshelper.c  |   4 +-
 src/node_device/node_device_hal.c   |   4 +-
 src/node_device/node_device_udev.c  |   2 +-
 src/nwfilter/nwfilter_dhcpsnoop.c   |  10 +--
 src/nwfilter/nwfilter_learnipaddr.c |   2 +-
 src/phyp/phyp_driver.c  |   2 +-
 src/qemu/qemu_agent.c   |   2 +-
 src/qemu/qemu_capabilities.c| 112 ++--
 src/qemu/qemu_capspriv.h|   2 +-
 src/qemu/qemu_command.c |   6 +-
 src/qemu/qemu_conf.c|   2 +-
 src/qemu/qemu_domain.c  |   8 +-
 src/qemu/qemu_domain.h  |   4 +-
 src/qemu/qemu_driver.c  |   4 +-
 src/qemu/qemu_hotplug.c |   4 +-
 src/qemu/qemu_migration.c   |   8 +-
 src/qemu/qemu_migration_params.c|  12 +--
 src/qemu/qemu_monitor_json.c|   2 +-
 src/qemu/qemu_process.c |   2 +-
 src/qemu/qemu_qapi.c|   2 +-
 src/remote/remote_daemon.c  |   4 +-
 src/remote/remote_daemon_dispatch.c |  14 ++--
 src/remote/remote_driver.c  |   8 +-
 src/rpc/gendispatch.pl  |   2 +-
 src/rpc/virnetclient.c  |   8 +-
 src/rpc/virnetsocket.h  |   4 +-
 src/security/security_dac.c |   2 +-
 src/security/security_driver.c  |   2 +-
 src/security/security_selinux.c |   2 +-
 src/security/virt-aa-helper.c   |   6 +-
 src/test/test_driver.c  |   2 +-
 src/util/virarch.c  |   2 +-
 src/util/viraudit.c |   2 +-
 src/util/viraudit.h |   2 +-
 src/util/virbuffer.h|   4 +-
 src/util/vircgroupv1.c  |   6 +-
 src/util/vircgroupv2.c  |   4 +-
 src/util/vircommand.h   |   6 +-
 src/util/virconf.c  |   2 +-
 src/util/vircrypto.c|   2 +-
 src/util/virdbus.c  |   2 +-
 src/util/virenum.h  |   6 +-
 src/util/virerror.h |   8 +-
 src/util/virfile.h  |  28 +++
 src/util/virfirewall.c  |   2 +-
 src/util/virfirewall.h  |   2 +-
 src/util/virhashcode.c  |   6 +-
 src/util/virhashcode.h  |   2 +-
 src/util/virhostcpu.c   |   2 +-
 src/util/virhostcpu.h   |   4 +-
 src/util/virhostuptime.h|   2 +-
 src/util/viriptables.c  |   8 +-
 src/util/viriscsi.c |   2 +-
 src/util/virkeycode.c   |  26 +++
 src/util/virlog.c   |   6 +-
 src/util/virlog.h   |   4 +-
 src/util/virmacaddr.h   |   2 +-
 src/util/virnetdev.c|   4 +-
 src/util/virnetdev.h|  10 +--
 src/util/virnetdevip.h  |   2 +-
 src/util/virnetdevmacvlan.h |   2 +-
 src/util/virnetdevopenvswitch.h |   2 +-
 src/util/virnetdevtap.h |   6 +-
 src/util/virnetlink.c   |   2 +-
 src/util/virnuma.h  

[libvirt] [PATCH 2/8] syntax-check: prohibit_attribute_macros: generalize error

2019-10-15 Thread Ján Tomko
Instead of enumerating every single macro variant, just emit
a more generic error.

Signed-off-by: Ján Tomko 
---
 build-aux/syntax-check.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk
index c30d575e77..c0612a3319 100644
--- a/build-aux/syntax-check.mk
+++ b/build-aux/syntax-check.mk
@@ -631,7 +631,7 @@ sc_avoid_g_gnuc_unused_in_header:
 sc_prohibit_attribute_macros:
@prohibit='ATTRIBUTE_(UNUSED|NORETURN|SENTINEL|RETURN_CHECK)' \
in_vc_files='\.[ch]$$' \
-   halt='use GLib macros: 
G_GNUC_{UNUSED,NORETURN,NULL_TERMINATED,WARN_UNUSED_RESULT}' \
+   halt='use GLib macros: G_GNUC_ for most' \
  $(_sc_search_regexp)
 
 sc_prohibit_int_index:
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 4/8] Use G_GNUC_PRINTF instead of ATTRIBUTE_FMT_PRINTF

2019-10-15 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 build-aux/syntax-check.mk |  2 +-
 src/internal.h| 20 
 src/libxl/libxl_logger.c  |  2 +-
 src/qemu/qemu_domain.h|  4 ++--
 src/util/viraudit.h   |  2 +-
 src/util/virbuffer.h  |  4 ++--
 src/util/vircommand.h |  4 ++--
 src/util/virerror.h   |  8 
 src/util/virfile.h| 12 ++--
 src/util/virfirewall.h|  2 +-
 src/util/virlog.h |  4 ++--
 src/util/virstring.h  |  4 ++--
 src/util/virtypedparam.c  |  2 +-
 src/util/virtypedparam.h  | 14 +++---
 tests/eventtest.c |  2 +-
 tests/qemumonitortestutils.c  |  2 +-
 tools/virt-host-validate-common.h |  4 ++--
 tools/vsh.h   | 10 +-
 18 files changed, 41 insertions(+), 61 deletions(-)

diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk
index c8ca6279a2..cfcc339c95 100644
--- a/build-aux/syntax-check.mk
+++ b/build-aux/syntax-check.mk
@@ -629,7 +629,7 @@ sc_avoid_g_gnuc_unused_in_header:
  $(_sc_search_regexp)
 
 sc_prohibit_attribute_macros:
-   @prohibit='ATTRIBUTE_(UNUSED|NORETURN|SENTINEL|RETURN_CHECK|NOINLINE)' \
+   
@prohibit='ATTRIBUTE_(UNUSED|NORETURN|SENTINEL|RETURN_CHECK|NOINLINE|FMT_PRINTF)'
 \
in_vc_files='\.[ch]$$' \
halt='use GLib macros: G_GNUC_ for most' \
  $(_sc_search_regexp)
diff --git a/src/internal.h b/src/internal.h
index e2e27342d7..0825e63993 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -105,26 +105,6 @@
 # define G_GNUC_NO_INLINE __attribute__((__noinline__))
 #endif
 
-/**
- * ATTRIBUTE_FMT_PRINTF
- *
- * Macro used to check printf like functions, if compiling
- * with gcc.
- *
- * We use gnulib which guarantees we always have GNU style
- * printf format specifiers even on broken Win32 platforms
- * hence we have to force 'gnu_printf' for new GCC
- */
-#ifndef ATTRIBUTE_FMT_PRINTF
-# ifndef __clang__
-#  define ATTRIBUTE_FMT_PRINTF(fmtpos, argpos) \
-   __attribute__((__format__ (__gnu_printf__, fmtpos, argpos)))
-# else
-#  define ATTRIBUTE_FMT_PRINTF(fmtpos, argpos) \
-   __attribute__((__format__ (__printf__, fmtpos, argpos)))
-# endif
-#endif
-
 /**
  * ATTRIBUTE_PACKED
  *
diff --git a/src/libxl/libxl_logger.c b/src/libxl/libxl_logger.c
index b4a38ae865..87ad793fb5 100644
--- a/src/libxl/libxl_logger.c
+++ b/src/libxl/libxl_logger.c
@@ -54,7 +54,7 @@ libxlLoggerFileFree(void *payload, const void *key 
G_GNUC_UNUSED)
 file = NULL;
 }
 
-ATTRIBUTE_FMT_PRINTF(5, 0) static void
+G_GNUC_PRINTF(5, 0) static void
 libvirt_vmessage(xentoollog_logger *logger_in,
  xentoollog_level level,
  int errnoval,
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 9174631ad2..d703417862 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -739,7 +739,7 @@ qemuDomainLogContextPtr 
qemuDomainLogContextNew(virQEMUDriverPtr driver,
 virDomainObjPtr vm,
 qemuDomainLogContextMode mode);
 int qemuDomainLogContextWrite(qemuDomainLogContextPtr ctxt,
-  const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(2, 3);
+  const char *fmt, ...) G_GNUC_PRINTF(2, 3);
 ssize_t qemuDomainLogContextRead(qemuDomainLogContextPtr ctxt,
  char **msg);
 int qemuDomainLogContextGetWriteFD(qemuDomainLogContextPtr ctxt);
@@ -750,7 +750,7 @@ virLogManagerPtr 
qemuDomainLogContextGetManager(qemuDomainLogContextPtr ctxt);
 int qemuDomainLogAppendMessage(virQEMUDriverPtr driver,
virDomainObjPtr vm,
const char *fmt,
-   ...) ATTRIBUTE_FMT_PRINTF(3, 4);
+   ...) G_GNUC_PRINTF(3, 4);
 
 const char *qemuFindQemuImgBinary(virQEMUDriverPtr driver);
 
diff --git a/src/util/viraudit.h b/src/util/viraudit.h
index 51e152ad1e..a36cc77ca6 100644
--- a/src/util/viraudit.h
+++ b/src/util/viraudit.h
@@ -39,7 +39,7 @@ void virAuditSend(virLogSourcePtr source,
   const char *clienttty, const char *clientaddr,
   virAuditRecordType type, bool success,
   const char *fmt, ...)
-ATTRIBUTE_FMT_PRINTF(9, 10);
+G_GNUC_PRINTF(9, 10);
 
 char *virAuditEncode(const char *key, const char *value);
 
diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h
index 75e26c32ff..1c9748643e 100644
--- a/src/util/virbuffer.h
+++ b/src/util/virbuffer.h
@@ -73,9 +73,9 @@ void virBufferAdd(virBufferPtr buf, const char *str, int len);
 void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd);
 void virBufferAddChar(virBufferPtr buf, char c);
 void virBufferAsprintf(virBufferPtr buf, const char *format, ...)
-  ATTRIBUTE_FMT_PRINTF(2, 3);
+  G_GNUC_PRINTF(2, 3)

[libvirt] [PATCH 7/8] examples: Use G_N_ELEMENTS instead of ARRAY_CARDINALITY

2019-10-15 Thread Ján Tomko
We try to keep the example programs independent of libraries
other than libvirt.

Rename the locally defined ARRAY_CARDINALITY macro to G_N_ELEMENTS
which GLib provides, even though we don't actually include GLib.

Signed-off-by: Ján Tomko 
---
 examples/c/misc/event-test.c | 26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c
index 533b8da9bf..5db572175d 100644
--- a/examples/c/misc/event-test.c
+++ b/examples/c/misc/event-test.c
@@ -9,7 +9,7 @@
 #include 
 #include 
 
-#define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array)))
+#define G_N_ELEMENTS(Array) (sizeof(Array) / sizeof(*(Array)))
 #define STREQ(a, b) (strcmp(a, b) == 0)
 #define NULLSTR(s) ((s) ? (s) : "")
 
@@ -1135,10 +1135,10 @@ struct secretEventData secretEvents[] = {
 };
 
 /* make sure that the events are kept in sync */
-verify(ARRAY_CARDINALITY(domainEvents) == VIR_DOMAIN_EVENT_ID_LAST);
-verify(ARRAY_CARDINALITY(storagePoolEvents) == VIR_STORAGE_POOL_EVENT_ID_LAST);
-verify(ARRAY_CARDINALITY(nodeDeviceEvents) == VIR_NODE_DEVICE_EVENT_ID_LAST);
-verify(ARRAY_CARDINALITY(secretEvents) == VIR_SECRET_EVENT_ID_LAST);
+verify(G_N_ELEMENTS(domainEvents) == VIR_DOMAIN_EVENT_ID_LAST);
+verify(G_N_ELEMENTS(storagePoolEvents) == VIR_STORAGE_POOL_EVENT_ID_LAST);
+verify(G_N_ELEMENTS(nodeDeviceEvents) == VIR_NODE_DEVICE_EVENT_ID_LAST);
+verify(G_N_ELEMENTS(secretEvents) == VIR_SECRET_EVENT_ID_LAST);
 
 int
 main(int argc, char **argv)
@@ -1190,7 +1190,7 @@ main(int argc, char **argv)
  strdup("callback 1"), 
myFreeFunc);
 
 /* register common domain callbacks */
-for (i = 0; i < ARRAY_CARDINALITY(domainEvents); i++) {
+for (i = 0; i < G_N_ELEMENTS(domainEvents); i++) {
 struct domainEventData *event = domainEvents + i;
 
 event->id = virConnectDomainEventRegisterAny(dconn, NULL,
@@ -1212,7 +1212,7 @@ main(int argc, char **argv)
   strdup("net callback"), 
myFreeFunc);
 
 /* register common storage pool callbacks */
-for (i = 0; i < ARRAY_CARDINALITY(storagePoolEvents); i++) {
+for (i = 0; i < G_N_ELEMENTS(storagePoolEvents); i++) {
 struct storagePoolEventData *event = storagePoolEvents + i;
 
 event->id = virConnectStoragePoolEventRegisterAny(dconn, NULL,
@@ -1228,7 +1228,7 @@ main(int argc, char **argv)
 }
 
 /* register common node device callbacks */
-for (i = 0; i < ARRAY_CARDINALITY(nodeDeviceEvents); i++) {
+for (i = 0; i < G_N_ELEMENTS(nodeDeviceEvents); i++) {
 struct nodeDeviceEventData *event = nodeDeviceEvents + i;
 
 event->id = virConnectNodeDeviceEventRegisterAny(dconn, NULL,
@@ -1244,7 +1244,7 @@ main(int argc, char **argv)
 }
 
 /* register common secret callbacks */
-for (i = 0; i < ARRAY_CARDINALITY(secretEvents); i++) {
+for (i = 0; i < G_N_ELEMENTS(secretEvents); i++) {
 struct secretEventData *event = secretEvents + i;
 
 event->id = virConnectSecretEventRegisterAny(dconn, NULL,
@@ -1282,27 +1282,27 @@ main(int argc, char **argv)
 
 
 printf("Deregistering domain event callbacks\n");
-for (i = 0; i < ARRAY_CARDINALITY(domainEvents); i++) {
+for (i = 0; i < G_N_ELEMENTS(domainEvents); i++) {
 if (domainEvents[i].id > 0)
 virConnectDomainEventDeregisterAny(dconn, domainEvents[i].id);
 }
 
 
 printf("Deregistering storage pool event callbacks\n");
-for (i = 0; i < ARRAY_CARDINALITY(storagePoolEvents); i++) {
+for (i = 0; i < G_N_ELEMENTS(storagePoolEvents); i++) {
 if (storagePoolEvents[i].id > 0)
 virConnectStoragePoolEventDeregisterAny(dconn, 
storagePoolEvents[i].id);
 }
 
 
 printf("Deregistering node device event callbacks\n");
-for (i = 0; i < ARRAY_CARDINALITY(nodeDeviceEvents); i++) {
+for (i = 0; i < G_N_ELEMENTS(nodeDeviceEvents); i++) {
 if (nodeDeviceEvents[i].id > 0)
 virConnectNodeDeviceEventDeregisterAny(dconn, 
nodeDeviceEvents[i].id);
 }
 
 printf("Deregistering secret event callbacks\n");
-for (i = 0; i < ARRAY_CARDINALITY(secretEvents); i++) {
+for (i = 0; i < G_N_ELEMENTS(secretEvents); i++) {
 if (secretEvents[i].id > 0)
 virConnectSecretEventDeregisterAny(dconn, secretEvents[i].id);
 }
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [RFC 0/1] convert virStorageSource to GObject

2019-10-15 Thread Daniel Henrique Barboza
I was hoping to quickly re-send the qemu_driver cleanups I've
sent some time ago, now using Glib. I started by attempting to
change the first VIR_AUTOUNREF() call in qemu_driver.c to
g_autoptr(), which happens to be a virStorageSourcePtr type,
then I realized that it wasn't that simple.

Following up the instructions found on commit 16121a88a7, I started
the conversion. Then 'make check' started to fail because some
calls to virObjectRef/virObjectUnref were still remaining
in the code, messing up stuff related with mirrorChain in
qemu_blockjob.c. Turns out it was easier to burn through all the
instances and change them to use GLib.

This is being sent as RFC because x-I am aware that docs/hacking.html
mentions that we shouldn't mix up certain GLib macros with Libvirt
ones, thus I am uncertain of whether I have messed up or not.
'make check' works, did a few sanity checks with libvirtd as
well.

Hopefully this is somewhere near the mark. I intend to do such
convertions from time to time, based on the cleanups I wanted to
make in the qemu_driver file prior to the GLib introduction.


Daniel Henrique Barboza (1):
  util: convert virStorageSource class to use GObject

 src/conf/domain_conf.c| 13 ++---
 src/conf/snapshot_conf.c  |  3 +-
 src/qemu/qemu_blockjob.c  | 43 ++
 src/qemu/qemu_domain.c|  6 +-
 src/qemu/qemu_driver.c| 14 ++---
 src/qemu/qemu_hotplug.c   |  3 +-
 src/qemu/qemu_migration.c |  2 +-
 src/storage/storage_backend_gluster.c |  2 +-
 src/storage/storage_util.c|  4 +-
 src/util/virstoragefile.c | 84 +--
 src/util/virstoragefile.h |  9 ++-
 tests/qemublocktest.c |  6 +-
 tests/virstoragetest.c| 12 ++--
 13 files changed, 98 insertions(+), 103 deletions(-)

-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [RFC 1/1] util: convert virStorageSource class to use GObject

2019-10-15 Thread Daniel Henrique Barboza
Following up the directions provided in commit 16121a88a7, this
patch converts virStorageSource to use GObject.

All calls to virObjectRef were converted to g_object_ref. Calls to
virObjectUnref were changed to use either g_object_unref or
g_clear_object, depending on the context.

Signed-off-by: Daniel Henrique Barboza 
---
 src/conf/domain_conf.c| 13 ++---
 src/conf/snapshot_conf.c  |  3 +-
 src/qemu/qemu_blockjob.c  | 43 ++
 src/qemu/qemu_domain.c|  6 +-
 src/qemu/qemu_driver.c| 14 ++---
 src/qemu/qemu_hotplug.c   |  3 +-
 src/qemu/qemu_migration.c |  2 +-
 src/storage/storage_backend_gluster.c |  2 +-
 src/storage/storage_util.c|  4 +-
 src/util/virstoragefile.c | 84 +--
 src/util/virstoragefile.h |  9 ++-
 tests/qemublocktest.c |  6 +-
 tests/virstoragetest.c| 12 ++--
 13 files changed, 98 insertions(+), 103 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c1705a07b6..71888ebaf0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2097,10 +2097,10 @@ virDomainDiskDefFree(virDomainDiskDefPtr def)
 if (!def)
 return;
 
-virObjectUnref(def->src);
+g_clear_object(&def->src);
 VIR_FREE(def->serial);
 VIR_FREE(def->dst);
-virObjectUnref(def->mirror);
+g_clear_object(&def->mirror);
 VIR_FREE(def->wwn);
 VIR_FREE(def->driverName);
 VIR_FREE(def->vendor);
@@ -2312,7 +2312,7 @@ void virDomainFSDefFree(virDomainFSDefPtr def)
 if (!def)
 return;
 
-virObjectUnref(def->src);
+g_object_unref(def->src);
 VIR_FREE(def->dst);
 virDomainDeviceInfoClear(&def->info);
 VIR_FREE(def->virtio);
@@ -2896,8 +2896,7 @@ 
virDomainHostdevSubsysSCSIiSCSIClear(virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc
 if (!iscsisrc)
 return;
 
-virObjectUnref(iscsisrc->src);
-iscsisrc->src = NULL;
+g_clear_object(&iscsisrc->src);
 }
 
 
@@ -9276,7 +9275,7 @@ virDomainStorageSourceParseBase(const char *type,
 const char *format,
 const char *index)
 {
-VIR_AUTOUNREF(virStorageSourcePtr) src = NULL;
+g_autoptr(virStorageSource) src = NULL;
 virStorageSourcePtr ret = NULL;
 
 if (!(src = virStorageSourceNew()))
@@ -9402,7 +9401,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 {
 VIR_XPATH_NODE_AUTORESTORE(ctxt);
 xmlNodePtr source;
-VIR_AUTOUNREF(virStorageSourcePtr) backingStore = NULL;
+g_autoptr(virStorageSource) backingStore = NULL;
 VIR_AUTOFREE(char *) type = NULL;
 VIR_AUTOFREE(char *) format = NULL;
 VIR_AUTOFREE(char *) idx = NULL;
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index a77f521302..cb85d147b8 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -94,8 +94,7 @@ static void
 virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDefPtr disk)
 {
 VIR_FREE(disk->name);
-virObjectUnref(disk->src);
-disk->src = NULL;
+g_clear_object(&disk->src);
 }
 
 void
diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c
index c118f2c298..5bac0ec976 100644
--- a/src/qemu/qemu_blockjob.c
+++ b/src/qemu/qemu_blockjob.c
@@ -76,11 +76,11 @@ qemuBlockJobDataDispose(void *obj)
 {
 qemuBlockJobDataPtr job = obj;
 
-virObjectUnref(job->chain);
-virObjectUnref(job->mirrorChain);
+g_clear_object(&job->chain);
+g_clear_object(&job->mirrorChain);
 
 if (job->type == QEMU_BLOCKJOB_TYPE_CREATE)
-virObjectUnref(job->data.create.src);
+g_clear_object(&job->data.create.src);
 
 VIR_FREE(job->name);
 VIR_FREE(job->errmsg);
@@ -156,7 +156,7 @@ qemuBlockJobRegister(qemuBlockJobDataPtr job,
 
 if (disk) {
 job->disk = disk;
-job->chain = virObjectRef(disk->src);
+job->chain = g_object_ref(disk->src);
 QEMU_DOMAIN_DISK_PRIVATE(disk)->blockjob = virObjectRef(job);
 }
 
@@ -304,9 +304,9 @@ qemuBlockJobNewCreate(virDomainObjPtr vm,
 return NULL;
 
 if (virStorageSourceIsBacking(chain))
-job->chain = virObjectRef(chain);
+job->chain = g_object_ref(chain);
 
- job->data.create.src = virObjectRef(src);
+job->data.create.src = g_object_ref(src);
 
 if (qemuBlockJobRegister(job, vm, NULL, true) < 0)
 return NULL;
@@ -337,7 +337,7 @@ qemuBlockJobDiskNewCopy(virDomainObjPtr vm,
 if (!(job = qemuBlockJobDataNew(QEMU_BLOCKJOB_TYPE_COPY, jobname)))
 return NULL;
 
-job->mirrorChain = virObjectRef(mirror);
+job->mirrorChain = g_object_ref(mirror);
 
 if (shallow && !reuse)
 job->data.copy.shallownew = true;
@@ -595,7 +595,7 @@ qemuBlockJobRewriteConfigDiskSource(virDomainObjPtr vm,
 virStorageSourcePtr newsrc)
 {
 virDomainDiskDefPtr persistDisk = NULL;

Re: [libvirt] [PULL 01/19] util/hbitmap: strict hbitmap_reset

2019-10-15 Thread John Snow


On 10/15/19 4:44 AM, Kevin Wolf wrote:
> Am 14.10.2019 um 20:10 hat John Snow geschrieben:
>>
>>
>> On 10/11/19 7:18 PM, John Snow wrote:
>>>
>>>
>>> On 10/11/19 5:48 PM, Eric Blake wrote:
 On 10/11/19 4:25 PM, John Snow wrote:
> From: Vladimir Sementsov-Ogievskiy 
>
> hbitmap_reset has an unobvious property: it rounds requested region up.
> It may provoke bugs, like in recently fixed write-blocking mode of
> mirror: user calls reset on unaligned region, not keeping in mind that
> there are possible unrelated dirty bytes, covered by rounded-up region
> and information of this unrelated "dirtiness" will be lost.
>
> Make hbitmap_reset strict: assert that arguments are aligned, allowing
> only one exception when @start + @count == hb->orig_size. It's needed
> to comfort users of hbitmap_next_dirty_area, which cares about
> hb->orig_size.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy 
> Reviewed-by: Max Reitz 
> Message-Id: <20190806152611.280389-1-vsement...@virtuozzo.com>
> [Maintainer edit: Max's suggestions from on-list. --js]
> Signed-off-by: John Snow 
> ---
>   include/qemu/hbitmap.h | 5 +
>   tests/test-hbitmap.c   | 2 +-
>   util/hbitmap.c | 4 
>   3 files changed, 10 insertions(+), 1 deletion(-)
>

> +++ b/util/hbitmap.c
> @@ -476,6 +476,10 @@ void hbitmap_reset(HBitmap *hb, uint64_t start,
> uint64_t count)
>   /* Compute range in the last layer.  */
>   uint64_t first;
>   uint64_t last = start + count - 1;
> +    uint64_t gran = 1ULL << hb->granularity;
> +
> +    assert(!(start & (gran - 1)));
> +    assert(!(count & (gran - 1)) || (start + count == hb->orig_size));

 I know I'm replying a bit late (since this is now a pull request), but
 would it be worth using the dedicated macro:

 assert(QEMU_IS_ALIGNED(start, gran));
 assert(QEMU_IS_ALIGNED(count, gran) || start + count == hb->orig_size);

 instead of open-coding it?  (I would also drop the extra () around the
 right half of ||). If we want it, that would now be a followup patch.
>>
>> I've noticed that seasoned C programmers hate extra parentheses a lot.
>> I've noticed that I cannot remember operator precedence enough to ever
>> feel like this is actually an improvement.
>>
>> Something about a nice weighted tree of ((expr1) || (expr2)) feels
>> soothing to my weary eyes. So, if it's not terribly important, I'd
>> prefer to leave it as-is.
> 
> I don't mind the parentheses, but I do prefer QEMU_IS_ALIGNED() to the
> open-coded version. Would that be a viable compromise?
> 

Oh, I'm sorry! I did change that. I didn't mean to appear any more
stubborn than I actually am.

--js

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [RFC 0/1] convert virStorageSource to GObject

2019-10-15 Thread Daniel P . Berrangé
On Tue, Oct 15, 2019 at 09:42:45AM -0300, Daniel Henrique Barboza wrote:
> I was hoping to quickly re-send the qemu_driver cleanups I've
> sent some time ago, now using Glib. I started by attempting to
> change the first VIR_AUTOUNREF() call in qemu_driver.c to
> g_autoptr(), which happens to be a virStorageSourcePtr type,
> then I realized that it wasn't that simple.

It should be that simple with this commit:

  commit 667ff797e8eb8d82f30ab430216a8d2eef6b915a
  Author: Daniel P. Berrangé 
  Date:   Fri Oct 4 17:14:10 2019 +0100

src: add support for g_autoptr with virObject instances

we should be able to use g_autoptr for any virObject, without
having to lock-step convert to GObject.

What actual problem did you find ?

> Following up the instructions found on commit 16121a88a7, I started
> the conversion. Then 'make check' started to fail because some
> calls to virObjectRef/virObjectUnref were still remaining
> in the code, messing up stuff related with mirrorChain in
> qemu_blockjob.c. Turns out it was easier to burn through all the
> instances and change them to use GLib.

Yes, if you convert from virObject to GObject, you *must*
convert all virObjectRef/Unref calls at that time.

> This is being sent as RFC because x-I am aware that docs/hacking.html
> mentions that we shouldn't mix up certain GLib macros with Libvirt
> ones, thus I am uncertain of whether I have messed up or not.
> 'make check' works, did a few sanity checks with libvirtd as
> well.

Yes, the need to not mix  g_auto* with VIR_AUTO*, is why I did commit
667ff797e8eb8d82f30ab430216a8d2eef6b915a to let you use g_autoptr
with virObject, without first converting to GObject.

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 :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [RFC 0/1] convert virStorageSource to GObject

2019-10-15 Thread Peter Krempa
On Tue, Oct 15, 2019 at 09:42:45 -0300, Daniel Henrique Barboza wrote:
> I was hoping to quickly re-send the qemu_driver cleanups I've
> sent some time ago, now using Glib. I started by attempting to
> change the first VIR_AUTOUNREF() call in qemu_driver.c to
> g_autoptr(), which happens to be a virStorageSourcePtr type,
> then I realized that it wasn't that simple.
> 
> Following up the instructions found on commit 16121a88a7, I started
> the conversion. Then 'make check' started to fail because some
> calls to virObjectRef/virObjectUnref were still remaining
> in the code, messing up stuff related with mirrorChain in
> qemu_blockjob.c. Turns out it was easier to burn through all the
> instances and change them to use GLib.
> 
> This is being sent as RFC because x-I am aware that docs/hacking.html
> mentions that we shouldn't mix up certain GLib macros with Libvirt
> ones, thus I am uncertain of whether I have messed up or not.
> 'make check' works, did a few sanity checks with libvirtd as
> well.
> 
> Hopefully this is somewhere near the mark. I intend to do such
> convertions from time to time, based on the cleanups I wanted to
> make in the qemu_driver file prior to the GLib introduction.

I'd prefer if this kind of experiments is done on something simpler than
virStorageSource.

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] qemu: fix EFI nvram removal on domain undefine

2019-10-15 Thread Pavel Mores
On Tue, Oct 15, 2019 at 01:51:32PM +0200, Michal Privoznik wrote:
> On 10/15/19 10:31 AM, Pavel Mores wrote:
> > When undefining a UEFI domain its nvram file has to be properly handled as
> > well.  It's mandatory to use one of --nvram and --keep-nvram options when
> > 'virsh undefine ' is issued for a UEFI domain.  To fix the bug as
> > reported, virsh should return an error message if neither option is used
> > and the nvram file should be removed when --nvram is given.
> > 
> > The cause of the problem is that when qemuDomainUndefineFlags() is invoked
> > on an inactive domain the path to its nvram file is empty.  This commit
> > aims to fix this by formatting and filling in the path in time for the
> > nvram removal code to run properly.
> > 
> > https://bugzilla.redhat.com/show_bug.cgi?id=1751596
> > 
> > Signed-off-by: Pavel Mores 
> > ---
> >   src/qemu/qemu_domain.c | 12 +---
> >   src/qemu/qemu_domain.h |  4 
> >   src/qemu/qemu_driver.c | 20 +++-
> >   3 files changed, 28 insertions(+), 8 deletions(-)
> > 
> > diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> > index 35067c851f..1a0367cc27 100644
> > --- a/src/qemu/qemu_domain.c
> > +++ b/src/qemu/qemu_domain.c
> > @@ -15441,16 +15441,22 @@ 
> > qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk)
> >   }
> > +int
> > +qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg,
> > +virDomainDefPtr def, char **path)
> > +{
> > +return virAsprintf(path, "%s/%s_VARS.fd", cfg->nvramDir, def->name);
> > +}
> > +
> 
> We have two empty lines between functions in this file. And Also, one
> argument per line please.
> 
> >   int
> >   qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg,
> >   virDomainDefPtr def)
> >   {
> >   if (def->os.loader &&
> >   def->os.loader->type == VIR_DOMAIN_LOADER_TYPE_PFLASH &&
> > -def->os.loader->readonly == VIR_TRISTATE_SWITCH_ON &&
> > +def->os.loader->readonly == VIR_TRISTATE_BOOL_YES &&
> >   !def->os.loader->nvram) {
> > -return virAsprintf(&def->os.loader->nvram, "%s/%s_VARS.fd",
> > -   cfg->nvramDir, def->name);
> > +return qemuDomainNVRAMPathFormat(cfg, def, &def->os.loader->nvram);
> >   }
> >   return 0;
> > diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
> > index 01a54d4265..07725c7cc4 100644
> > --- a/src/qemu/qemu_domain.h
> > +++ b/src/qemu/qemu_domain.h
> > @@ -1207,6 +1207,10 @@ qemuDomainIsUsingNoShutdown(qemuDomainObjPrivatePtr 
> > priv);
> >   bool
> >   qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk);
> > +int
> > +qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg,
> > +virDomainDefPtr def, char **path);
> > +
> >   int
> >   qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg,
> >   virDomainDefPtr def);
> > diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> > index bc0ede2fb0..dcaadbdb52 100644
> > --- a/src/qemu/qemu_driver.c
> > +++ b/src/qemu/qemu_driver.c
> > @@ -7828,6 +7828,8 @@ qemuDomainUndefineFlags(virDomainPtr dom,
> >   int nsnapshots;
> >   int ncheckpoints;
> >   virQEMUDriverConfigPtr cfg = NULL;
> > +char *nvram_path = NULL;
> > +bool need_deallocate_nvram_path = false;
> 
> While this works, I'd rather have @nvram_path autofreed, and ... [1]
> 
> >   virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |
> > VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA |
> > @@ -7905,14 +7907,20 @@ qemuDomainUndefineFlags(virDomainPtr dom,
> >   }
> >   }
> > -if (vm->def->os.loader &&
> > -vm->def->os.loader->nvram &&
> > -virFileExists(vm->def->os.loader->nvram)) {
> > +if (vm->def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) {
> > +qemuDomainNVRAMPathFormat(cfg, vm->def, &nvram_path);
> 
> This needs a check for retval.
> 
> > +need_deallocate_nvram_path = true;
> > +} else {
> > +if (vm->def->os.loader)
> > +nvram_path = vm->def->os.loader->nvram;
> 
> 1: ... duplicate path here.
> 
> > +}
> > +
> > +if (nvram_path && virFileExists(nvram_path)) {
> >   if ((flags & VIR_DOMAIN_UNDEFINE_NVRAM)) {
> > -if (unlink(vm->def->os.loader->nvram) < 0) {
> > +if (unlink(nvram_path) < 0) {
> >   virReportSystemError(errno,
> >_("failed to remove nvram: %s"),
> > - vm->def->os.loader->nvram);
> > + nvram_path);
> >   goto endjob;
> >   }
> >   } else if (!(flags & VIR_DOMAIN_UNDEFINE_KEEP_NVRAM)) {
> > @@ -7948,6 +7956,8 @@ qemuDomainUndefineFlags(virDomainPtr dom,
> >   virDomainObjEndAPI(&vm);
> >   virObjectEventStateQueue(driver->domainEventState, event);
> >   virObjectUnref(cfg);
> > +   

[libvirt] [PATCH 2/2] tests: Add test case for empty 'network' cdrom

2019-10-15 Thread Peter Krempa
We don't allow such config in the schema but the code can handle that so
add a test case supporting it.

Signed-off-by: Peter Krempa 
---
 ...m-empty-network-invalid.x86_64-latest.args | 34 +++
 .../disk-cdrom-empty-network-invalid.xml  | 30 
 tests/qemuxml2argvtest.c  |  1 +
 ...om-empty-network-invalid.x86_64-latest.xml | 34 +++
 tests/qemuxml2xmltest.c   |  1 +
 5 files changed, 100 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/disk-cdrom-empty-network-invalid.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/disk-cdrom-empty-network-invalid.xml
 create mode 100644 
tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid.x86_64-latest.xml

diff --git 
a/tests/qemuxml2argvdata/disk-cdrom-empty-network-invalid.x86_64-latest.args 
b/tests/qemuxml2argvdata/disk-cdrom-empty-network-invalid.x86_64-latest.args
new file mode 100644
index 00..1e43047459
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-cdrom-empty-network-invalid.x86_64-latest.args
@@ -0,0 +1,34 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-i686 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
+-machine pc,accel=tcg,usb=off,dump-guest-core=off \
+-m 214 \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
+-drive if=none,id=drive-ide0-1-1,readonly=on \
+-device ide-cd,bus=ide.1,unit=1,drive=drive-ide0-1-1,id=ide0-1-1 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/disk-cdrom-empty-network-invalid.xml 
b/tests/qemuxml2argvdata/disk-cdrom-empty-network-invalid.xml
new file mode 100644
index 00..f593b33c91
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-cdrom-empty-network-invalid.xml
@@ -0,0 +1,30 @@
+
+  QEMUGuest1
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219100
+  219100
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu-system-i686
+
+  
+  
+  
+  
+
+
+
+
+
+
+
+  
+
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 834a289532..6b9da3b8ff 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1013,6 +1013,7 @@ mymain(void)
 DO_TEST("disk-cdrom", NONE);
 DO_TEST_CAPS_VER("disk-cdrom", "2.12.0");
 DO_TEST_CAPS_LATEST("disk-cdrom");
+DO_TEST_CAPS_LATEST("disk-cdrom-empty-network-invalid");
 DO_TEST_CAPS_LATEST("disk-cdrom-bus-other");
 DO_TEST("disk-iscsi", NONE);
 DO_TEST("disk-cdrom-network", QEMU_CAPS_KVM);
diff --git 
a/tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid.x86_64-latest.xml 
b/tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid.x86_64-latest.xml
new file mode 100644
index 00..f7772d832c
--- /dev/null
+++ 
b/tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid.x86_64-latest.xml
@@ -0,0 +1,34 @@
+
+  QEMUGuest1
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219100
+  219100
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu-system-i686
+
+  
+  
+  
+  
+
+
+  
+
+
+  
+
+
+
+
+
+  
+
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index b9364f942f..c3de13f64a 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -329,6 +329,7 @@ mymain(void)
 DO_TEST("qemu-ns-no-env", NONE);
 DO_TEST("disk-aio", NONE);
 DO_TEST("disk-cdrom", NONE);
+DO_TEST_CAPS_LATEST("disk-cdrom-empty-network-invalid");
 DO_TEST("disk-cdrom-bus-other", NONE);
 DO_TEST("disk-floppy", NONE);
 DO_TEST("disk-usb-device", NONE);
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 0/2] conf: Fix up empty 'network' cdroms

2019-10-15 Thread Peter Krempa
Peter Krempa (2):
  conf: Reset disk type if  element is completely missing
  tests: Add test case for empty 'network' cdrom

 src/conf/domain_conf.c|  4 +++
 ...m-empty-network-invalid.x86_64-latest.args | 34 +++
 .../disk-cdrom-empty-network-invalid.xml  | 30 
 tests/qemuxml2argvtest.c  |  1 +
 ...om-empty-network-invalid.x86_64-latest.xml | 34 +++
 tests/qemuxml2xmloutdata/disk-source-pool.xml |  2 +-
 tests/qemuxml2xmltest.c   |  1 +
 7 files changed, 105 insertions(+), 1 deletion(-)
 create mode 100644 
tests/qemuxml2argvdata/disk-cdrom-empty-network-invalid.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/disk-cdrom-empty-network-invalid.xml
 create mode 100644 
tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid.x86_64-latest.xml

-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/2] conf: Reset disk type if element is completely missing

2019-10-15 Thread Peter Krempa
The disk type is not part of source and thus it's parsed earlier. This
bypasses the checks when parsing a disk type='network' if it's
completely missing the source.

Since there are possible active users of this (it was reported as a
problem with openstack) fix it by resetting the disk type to '_FILE' for
an empty cdrom which is handled correctly.

Signed-off-by: Peter Krempa 
---
 src/conf/domain_conf.c| 4 
 tests/qemuxml2xmloutdata/disk-source-pool.xml | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c1705a07b6..399804dfbd 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10189,6 +10189,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 }
 }

+/* Reset def->src->type in case when 'source' was not present */
+if (!source)
+def->src->type = VIR_STORAGE_TYPE_FILE;
+
 /* Only CDROM and Floppy devices are allowed missing source path
  * to indicate no media present. LUN is for raw access CD-ROMs
  * that are not attached to a physical device presently */
diff --git a/tests/qemuxml2xmloutdata/disk-source-pool.xml 
b/tests/qemuxml2xmloutdata/disk-source-pool.xml
index 78e0449dfd..807d1099ed 100644
--- a/tests/qemuxml2xmloutdata/disk-source-pool.xml
+++ b/tests/qemuxml2xmloutdata/disk-source-pool.xml
@@ -25,7 +25,7 @@
   
   
 
-
+
   
   
   
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] qemu: fix EFI nvram removal on domain undefine

2019-10-15 Thread Michal Privoznik

On 10/15/19 3:15 PM, Pavel Mores wrote:

On Tue, Oct 15, 2019 at 01:51:32PM +0200, Michal Privoznik wrote:

On 10/15/19 10:31 AM, Pavel Mores wrote:

When undefining a UEFI domain its nvram file has to be properly handled as
well.  It's mandatory to use one of --nvram and --keep-nvram options when
'virsh undefine ' is issued for a UEFI domain.  To fix the bug as
reported, virsh should return an error message if neither option is used
and the nvram file should be removed when --nvram is given.

The cause of the problem is that when qemuDomainUndefineFlags() is invoked
on an inactive domain the path to its nvram file is empty.  This commit
aims to fix this by formatting and filling in the path in time for the
nvram removal code to run properly.

https://bugzilla.redhat.com/show_bug.cgi?id=1751596

Signed-off-by: Pavel Mores 
---
   src/qemu/qemu_domain.c | 12 +---
   src/qemu/qemu_domain.h |  4 
   src/qemu/qemu_driver.c | 20 +++-
   3 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 35067c851f..1a0367cc27 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -15441,16 +15441,22 @@ 
qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk)
   }
+int
+qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg,
+virDomainDefPtr def, char **path)
+{
+return virAsprintf(path, "%s/%s_VARS.fd", cfg->nvramDir, def->name);
+}
+


We have two empty lines between functions in this file. And Also, one
argument per line please.


   int
   qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg,
   virDomainDefPtr def)
   {
   if (def->os.loader &&
   def->os.loader->type == VIR_DOMAIN_LOADER_TYPE_PFLASH &&
-def->os.loader->readonly == VIR_TRISTATE_SWITCH_ON &&
+def->os.loader->readonly == VIR_TRISTATE_BOOL_YES &&
   !def->os.loader->nvram) {
-return virAsprintf(&def->os.loader->nvram, "%s/%s_VARS.fd",
-   cfg->nvramDir, def->name);
+return qemuDomainNVRAMPathFormat(cfg, def, &def->os.loader->nvram);
   }
   return 0;
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 01a54d4265..07725c7cc4 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -1207,6 +1207,10 @@ qemuDomainIsUsingNoShutdown(qemuDomainObjPrivatePtr 
priv);
   bool
   qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk);
+int
+qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg,
+virDomainDefPtr def, char **path);
+
   int
   qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg,
   virDomainDefPtr def);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index bc0ede2fb0..dcaadbdb52 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7828,6 +7828,8 @@ qemuDomainUndefineFlags(virDomainPtr dom,
   int nsnapshots;
   int ncheckpoints;
   virQEMUDriverConfigPtr cfg = NULL;
+char *nvram_path = NULL;
+bool need_deallocate_nvram_path = false;


While this works, I'd rather have @nvram_path autofreed, and ... [1]


   virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |
 VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA |
@@ -7905,14 +7907,20 @@ qemuDomainUndefineFlags(virDomainPtr dom,
   }
   }
-if (vm->def->os.loader &&
-vm->def->os.loader->nvram &&
-virFileExists(vm->def->os.loader->nvram)) {
+if (vm->def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) {
+qemuDomainNVRAMPathFormat(cfg, vm->def, &nvram_path);


This needs a check for retval.


+need_deallocate_nvram_path = true;
+} else {
+if (vm->def->os.loader)
+nvram_path = vm->def->os.loader->nvram;


1: ... duplicate path here.


+}
+
+if (nvram_path && virFileExists(nvram_path)) {
   if ((flags & VIR_DOMAIN_UNDEFINE_NVRAM)) {
-if (unlink(vm->def->os.loader->nvram) < 0) {
+if (unlink(nvram_path) < 0) {
   virReportSystemError(errno,
_("failed to remove nvram: %s"),
- vm->def->os.loader->nvram);
+ nvram_path);
   goto endjob;
   }
   } else if (!(flags & VIR_DOMAIN_UNDEFINE_KEEP_NVRAM)) {
@@ -7948,6 +7956,8 @@ qemuDomainUndefineFlags(virDomainPtr dom,
   virDomainObjEndAPI(&vm);
   virObjectEventStateQueue(driver->domainEventState, event);
   virObjectUnref(cfg);
+if (need_deallocate_nvram_path)
+VIR_FREE(nvram_path);
   return ret;
   }



Reviewed-by: Michal Privoznik  and pushed.


Cheers!  One question though - the pushed version duplicates the path as you
mention in [1] above, and if the strdup fails it does 'goto endjob'.  This
means that a failure in an avoidable string copy operation might make the

Re: [libvirt] [RFC 0/1] convert virStorageSource to GObject

2019-10-15 Thread Daniel Henrique Barboza



On 10/15/19 9:55 AM, Daniel P. Berrangé wrote:

On Tue, Oct 15, 2019 at 09:42:45AM -0300, Daniel Henrique Barboza wrote:

I was hoping to quickly re-send the qemu_driver cleanups I've
sent some time ago, now using Glib. I started by attempting to
change the first VIR_AUTOUNREF() call in qemu_driver.c to
g_autoptr(), which happens to be a virStorageSourcePtr type,
then I realized that it wasn't that simple.

It should be that simple with this commit:

   commit 667ff797e8eb8d82f30ab430216a8d2eef6b915a
   Author: Daniel P. Berrangé 
   Date:   Fri Oct 4 17:14:10 2019 +0100

 src: add support for g_autoptr with virObject instances

we should be able to use g_autoptr for any virObject, without
having to lock-step convert to GObject.

What actual problem did you find ?


I failed to notice this commit. Just tried it again and it worked.

What happened yesterday was that I attempted to do a simple
VIR_AUTOUNREF -> g_autopt replace, faced compile errors and then, since
I didn't notice this commit about, I assumed "I guess I need to convert
this guy to GObject".

In fact, the compile error happened because g_autoptr() does not operate
with a 'Ptr' type - something that I learned only during the conversion
process.

Well, hopefully this patch can serve as a baseline for a future 
conversion for
this object type. Guess I can go back safely to re-send the cleanup 
patches tha

 are already pending in the ML hehehe





Following up the instructions found on commit 16121a88a7, I started
the conversion. Then 'make check' started to fail because some
calls to virObjectRef/virObjectUnref were still remaining
in the code, messing up stuff related with mirrorChain in
qemu_blockjob.c. Turns out it was easier to burn through all the
instances and change them to use GLib.

Yes, if you convert from virObject to GObject, you *must*
convert all virObjectRef/Unref calls at that time.


This is being sent as RFC because x-I am aware that docs/hacking.html
mentions that we shouldn't mix up certain GLib macros with Libvirt
ones, thus I am uncertain of whether I have messed up or not.
'make check' works, did a few sanity checks with libvirtd as
well.

Yes, the need to not mix  g_auto* with VIR_AUTO*, is why I did commit
667ff797e8eb8d82f30ab430216a8d2eef6b915a to let you use g_autoptr
with virObject, without first converting to GObject.


What if there are other object types in the same function  using the VIR 
macros?

For example, inside qemu_driver.c: qemuDomainBlockCopyCommon:


    VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = 
virQEMUDriverGetConfig(driver);

    const char *format = NULL;
    bool mirror_reuse = !!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT);
    bool mirror_shallow = !!(flags & VIR_DOMAIN_BLOCK_COPY_SHALLOW);
    bool existing = mirror_reuse;
    qemuBlockJobDataPtr job = NULL;
    VIR_AUTOUNREF(virStorageSourcePtr) mirror = mirrorsrc;
    bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
    bool mirror_initialized = false;
    VIR_AUTOPTR(qemuBlockStorageSourceChainData) data = NULL;
    VIR_AUTOPTR(qemuBlockStorageSourceChainData) crdata = NULL;


Let's say that I change the virStorageSourcePtr up there to

   g_autoptr(virStorageSource) mirror = mirrorsrc;


As long as there are no VIR macros acting in the 'mirror' variable, is 
it to use g_autoptr

there even when everyone else is using VIR_AUTO* macros?




Thanks,

DHB




Regards,
Daniel


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 0/8] Use even morer of GLib's macros (glib chronicles)

2019-10-15 Thread Michal Privoznik

On 10/15/19 2:21 PM, Ján Tomko wrote:

Ján Tomko (8):

>

Reviewed-by: Michal Privoznik 

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 7/8] examples: Use G_N_ELEMENTS instead of ARRAY_CARDINALITY

2019-10-15 Thread Andrea Bolognani
On Tue, 2019-10-15 at 14:21 +0200, Ján Tomko wrote:
> We try to keep the example programs independent of libraries
> other than libvirt.
> 
> Rename the locally defined ARRAY_CARDINALITY macro to G_N_ELEMENTS
> which GLib provides, even though we don't actually include GLib.

[...]

> -#define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array)))
> +#define G_N_ELEMENTS(Array) (sizeof(Array) / sizeof(*(Array)))

In this case, and in this case only, I think we should leave the name
alone.

When we use GLib and simply provide our own implementation when using
a version that's too old, the GLib name is obviously accurate, but in
this specific case I think it's misleading and we should stick with
the current one.

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 0/2] conf: Fix up empty 'network' cdroms

2019-10-15 Thread Michal Privoznik

On 10/15/19 3:35 PM, Peter Krempa wrote:

Peter Krempa (2):
   conf: Reset disk type if  element is completely missing
   tests: Add test case for empty 'network' cdrom

  src/conf/domain_conf.c|  4 +++
  ...m-empty-network-invalid.x86_64-latest.args | 34 +++
  .../disk-cdrom-empty-network-invalid.xml  | 30 
  tests/qemuxml2argvtest.c  |  1 +
  ...om-empty-network-invalid.x86_64-latest.xml | 34 +++
  tests/qemuxml2xmloutdata/disk-source-pool.xml |  2 +-
  tests/qemuxml2xmltest.c   |  1 +
  7 files changed, 105 insertions(+), 1 deletion(-)
  create mode 100644 
tests/qemuxml2argvdata/disk-cdrom-empty-network-invalid.x86_64-latest.args
  create mode 100644 tests/qemuxml2argvdata/disk-cdrom-empty-network-invalid.xml
  create mode 100644 
tests/qemuxml2xmloutdata/disk-cdrom-empty-network-invalid.x86_64-latest.xml



I agree that this is not pretty, but I don't think there's a better way.

Reviewed-by: Michal Privoznik 

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] qemu: fix EFI nvram removal on domain undefine

2019-10-15 Thread Pavel Mores
On Tue, Oct 15, 2019 at 03:45:55PM +0200, Michal Privoznik wrote:
> On 10/15/19 3:15 PM, Pavel Mores wrote:
> > On Tue, Oct 15, 2019 at 01:51:32PM +0200, Michal Privoznik wrote:
> > > On 10/15/19 10:31 AM, Pavel Mores wrote:
> > > > When undefining a UEFI domain its nvram file has to be properly handled 
> > > > as
> > > > well.  It's mandatory to use one of --nvram and --keep-nvram options 
> > > > when
> > > > 'virsh undefine ' is issued for a UEFI domain.  To fix the bug 
> > > > as
> > > > reported, virsh should return an error message if neither option is used
> > > > and the nvram file should be removed when --nvram is given.
> > > > 
> > > > The cause of the problem is that when qemuDomainUndefineFlags() is 
> > > > invoked
> > > > on an inactive domain the path to its nvram file is empty.  This commit
> > > > aims to fix this by formatting and filling in the path in time for the
> > > > nvram removal code to run properly.
> > > > 
> > > > https://bugzilla.redhat.com/show_bug.cgi?id=1751596
> > > > 
> > > > Signed-off-by: Pavel Mores 
> > > > ---
> > > >src/qemu/qemu_domain.c | 12 +---
> > > >src/qemu/qemu_domain.h |  4 
> > > >src/qemu/qemu_driver.c | 20 +++-
> > > >3 files changed, 28 insertions(+), 8 deletions(-)
> > > > 
> > > > diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> > > > index 35067c851f..1a0367cc27 100644
> > > > --- a/src/qemu/qemu_domain.c
> > > > +++ b/src/qemu/qemu_domain.c
> > > > @@ -15441,16 +15441,22 @@ 
> > > > qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk)
> > > >}
> > > > +int
> > > > +qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg,
> > > > +virDomainDefPtr def, char **path)
> > > > +{
> > > > +return virAsprintf(path, "%s/%s_VARS.fd", cfg->nvramDir, 
> > > > def->name);
> > > > +}
> > > > +
> > > 
> > > We have two empty lines between functions in this file. And Also, one
> > > argument per line please.
> > > 
> > > >int
> > > >qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg,
> > > >virDomainDefPtr def)
> > > >{
> > > >if (def->os.loader &&
> > > >def->os.loader->type == VIR_DOMAIN_LOADER_TYPE_PFLASH &&
> > > > -def->os.loader->readonly == VIR_TRISTATE_SWITCH_ON &&
> > > > +def->os.loader->readonly == VIR_TRISTATE_BOOL_YES &&
> > > >!def->os.loader->nvram) {
> > > > -return virAsprintf(&def->os.loader->nvram, "%s/%s_VARS.fd",
> > > > -   cfg->nvramDir, def->name);
> > > > +return qemuDomainNVRAMPathFormat(cfg, def, 
> > > > &def->os.loader->nvram);
> > > >}
> > > >return 0;
> > > > diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
> > > > index 01a54d4265..07725c7cc4 100644
> > > > --- a/src/qemu/qemu_domain.h
> > > > +++ b/src/qemu/qemu_domain.h
> > > > @@ -1207,6 +1207,10 @@ 
> > > > qemuDomainIsUsingNoShutdown(qemuDomainObjPrivatePtr priv);
> > > >bool
> > > >qemuDomainDiskIsMissingLocalOptional(virDomainDiskDefPtr disk);
> > > > +int
> > > > +qemuDomainNVRAMPathFormat(virQEMUDriverConfigPtr cfg,
> > > > +virDomainDefPtr def, char **path);
> > > > +
> > > >int
> > > >qemuDomainNVRAMPathGenerate(virQEMUDriverConfigPtr cfg,
> > > >virDomainDefPtr def);
> > > > diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> > > > index bc0ede2fb0..dcaadbdb52 100644
> > > > --- a/src/qemu/qemu_driver.c
> > > > +++ b/src/qemu/qemu_driver.c
> > > > @@ -7828,6 +7828,8 @@ qemuDomainUndefineFlags(virDomainPtr dom,
> > > >int nsnapshots;
> > > >int ncheckpoints;
> > > >virQEMUDriverConfigPtr cfg = NULL;
> > > > +char *nvram_path = NULL;
> > > > +bool need_deallocate_nvram_path = false;
> > > 
> > > While this works, I'd rather have @nvram_path autofreed, and ... [1]
> > > 
> > > >virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE |
> > > >  VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA |
> > > > @@ -7905,14 +7907,20 @@ qemuDomainUndefineFlags(virDomainPtr dom,
> > > >}
> > > >}
> > > > -if (vm->def->os.loader &&
> > > > -vm->def->os.loader->nvram &&
> > > > -virFileExists(vm->def->os.loader->nvram)) {
> > > > +if (vm->def->os.firmware == VIR_DOMAIN_OS_DEF_FIRMWARE_EFI) {
> > > > +qemuDomainNVRAMPathFormat(cfg, vm->def, &nvram_path);
> > > 
> > > This needs a check for retval.
> > > 
> > > > +need_deallocate_nvram_path = true;
> > > > +} else {
> > > > +if (vm->def->os.loader)
> > > > +nvram_path = vm->def->os.loader->nvram;
> > > 
> > > 1: ... duplicate path here.
> > > 
> > > > +}
> > > > +
> > > > +if (nvram_path && virFileExists(nvram_path)) {
> > > >if ((flags & VIR_DOMAIN_UNDEFINE_NVRAM)) {
> > > > -if (unlink(vm->def->os.loader->nvram) < 0) {
> > > > +

Re: [libvirt] [PATCH 00/30] storagefile, security: qcow2 data_file support

2019-10-15 Thread Cole Robinson
On 10/15/19 12:29 AM, Han Han wrote:
> I find the issue cannot reproduced when `make clean` before build the
> source.
> It is not proper to build with an unclean source dir, right?
> 

I don't use 'make clean' in libvirt.git but in other projects I have hit
issues that required 'make clean', like in qemu if trying to run old
commits, often the build system gets confused. I dip in and out of
libvirt development though so maybe regular devs have hit similar issues

- Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 REBASE 00/12] hostdev: handle usb detach/attach on node

2019-10-15 Thread Nikolay Shirokovskiy
Diff to v2[1] version:
- add 'replug' attribute for hostdev element to allow replug semantics
- avoid accuiring domain lock in event loop thread on udev events as
  suggested by Peter
- nit picks after review by Daniel Henrique Barboza

* is used to mark patches that were 'Reviewed-by' by Daniel (sometimes
  with very minor changes to take into account new replug flag).

[1] https://www.redhat.com/archives/libvir-list/2019-September/msg00321.html

Nikolay Shirokovskiy (12):
  conf: add replug option for usb hostdev
  qemu: track hostdev delete intention
  qemu: support host usb device unplug
  qemu: support usb hostdev plugging back
  qemu: handle host usb device add/del udev events
  qemu: handle libvirtd restart after host usb device unplug
  qemu: handle race on device deletion and usb host device plugging
  qemu: hotplug: update device list on device deleted event
  qemu: handle host usb device plug/unplug when libvirtd is down
  qemu: don't mess with non mandatory hostdevs on reattaching
  qemu: handle detaching of unplugged hostdev
  conf: parse hostdev missing flag

 docs/formatdomain.html.in |  10 +-
 docs/schemas/domaincommon.rng |   5 +
 src/conf/domain_conf.c|  62 +++
 src/conf/domain_conf.h|  17 +
 src/qemu/Makefile.inc.am  |   2 +
 src/qemu/qemu_conf.h  |   3 +
 src/qemu/qemu_domain.c|   2 +
 src/qemu/qemu_domain.h|   2 +
 src/qemu/qemu_driver.c| 404 +-
 src/qemu/qemu_hotplug.c   | 104 -
 src/qemu/qemu_hotplug.h   |   3 +-
 src/qemu/qemu_process.c   |  60 +++
 src/util/virhostdev.c |   2 +
 tests/qemuhotplugtest.c   |   2 +-
 tests/qemuxml2argvdata/hostdev-usb-replug.xml |  36 ++
 .../qemuxml2xmloutdata/hostdev-usb-replug.xml |  40 ++
 tests/qemuxml2xmltest.c   |   1 +
 17 files changed, 733 insertions(+), 22 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/hostdev-usb-replug.xml
 create mode 100644 tests/qemuxml2xmloutdata/hostdev-usb-replug.xml

-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 REBASE 09/12] qemu: handle host usb device plug/unplug when libvirtd is down

2019-10-15 Thread Nikolay Shirokovskiy
Somebody can easily unplug usb device from host while libvirtd is being
stopped. Also usb device can be plugged or unplugged/plugged back and so
forth. Let's handle such cases.

Signed-off-by: Nikolay Shirokovskiy 
Reviewed-by: Daniel Henrique Barboza 
---
 src/qemu/qemu_process.c | 56 +
 1 file changed, 56 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 0afb7c79e4..82e10f4743 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3734,6 +3734,59 @@ qemuProcessUpdateDevices(virQEMUDriverPtr driver,
 return ret;
 }
 
+
+static int
+qemuProcessReattachUSBDevices(virQEMUDriverPtr driver,
+  virDomainObjPtr vm)
+{
+size_t i;
+
+for (i = 0; i < vm->def->nhostdevs; i++) {
+virDomainHostdevDefPtr hostdev = vm->def->hostdevs[i];
+virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
+
+if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB 
||
+!usbsrc->replug)
+continue;
+
+/* don't mess with devices that don't use stable host addressing
+ * with respect to unplug/plug to host
+ */
+if (!usbsrc->vendor || !usbsrc->product)
+continue;
+
+if (!usbsrc->bus && !usbsrc->device) {
+int num;
+
+if ((num = virUSBDeviceFindByVendor(usbsrc->vendor, 
usbsrc->product,
+NULL, false, NULL)) < 0)
+return -1;
+
+if (num > 0 &&
+qemuDomainAttachHostDevice(driver, vm, hostdev) < 0)
+return -1;
+} else {
+virUSBDevicePtr usb;
+
+if (virUSBDeviceFindByBus(usbsrc->bus, usbsrc->device,
+  NULL, false, &usb) < 0)
+return -1;
+
+if (!usb) {
+virDomainDeviceDef dev = { .type = VIR_DOMAIN_DEVICE_HOSTDEV };
+
+dev.data.hostdev = hostdev;
+if (qemuDomainDetachDeviceLive(vm, &dev, driver, true, true) < 
0)
+return -1;
+}
+virUSBDeviceFree(usb);
+}
+}
+
+return 0;
+}
+
+
 static int
 qemuDomainPerfRestart(virDomainObjPtr vm)
 {
@@ -8220,6 +8273,9 @@ qemuProcessReconnect(void *opaque)
 if (qemuProcessUpdateDevices(driver, obj) < 0)
 goto error;
 
+if (qemuProcessReattachUSBDevices(driver, obj) < 0)
+goto error;
+
 if (qemuRefreshPRManagerState(driver, obj) < 0)
 goto error;
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 REBASE 06/12] qemu: handle libvirtd restart after host usb device unplug

2019-10-15 Thread Nikolay Shirokovskiy
It is possible for libvirtd to go down before DEVICE_DELETED event is
delivered upon usb hostdev unplug and to receive the event after the
libvirtd is up. In order to handle this case we need to save
usb hostdev deleteAction in status file.

Signed-off-by: Nikolay Shirokovskiy 
Reviewed-by: Daniel Henrique Barboza 
---
 src/conf/domain_conf.c | 26 ++
 src/conf/domain_conf.h |  1 +
 src/qemu/qemu_driver.c | 20 ++--
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c99758d9f5..d185730023 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1244,6 +1244,13 @@ VIR_ENUM_IMPL(virDomainShmemModel,
   "ivshmem-doorbell",
 );
 
+VIR_ENUM_IMPL(virDomainHostdevDeleteAction,
+  VIR_DOMAIN_HOSTDEV_DELETE_ACTION_LAST,
+  "none",
+  "delete",
+  "unplug"
+);
+
 VIR_ENUM_IMPL(virDomainLaunchSecurity,
   VIR_DOMAIN_LAUNCH_SECURITY_LAST,
   "",
@@ -7588,6 +7595,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
 virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb;
 VIR_AUTOFREE(char *) startupPolicy = NULL;
 VIR_AUTOFREE(char *) autoAddress = NULL;
+VIR_AUTOFREE(char *) deleteAction = NULL;
 
 if ((startupPolicy = virXMLPropString(node, "startupPolicy"))) {
 def->startupPolicy =
@@ -7605,6 +7613,18 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
 usbsrc->autoAddress = true;
 }
 
+if ((deleteAction = virXMLPropString(node, "deleteAction"))) {
+def->deleteAction =
+virDomainHostdevDeleteActionTypeFromString(deleteAction);
+
+if (def->deleteAction <= 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("Unknown deleteAction '%s'"),
+   deleteAction);
+goto out;
+}
+}
+
 /* Product can validly be 0, so we need some extra help to determine
  * if it is uninitialized*/
 got_product = false;
@@ -25055,6 +25075,12 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
 
 if (def->missing && !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE))
 virBufferAddLit(buf, " missing='yes'");
+
+if (def->deleteAction && (flags & VIR_DOMAIN_DEF_FORMAT_STATUS)) {
+const char *deleteAction;
+deleteAction = 
virDomainHostdevDeleteActionTypeToString(def->deleteAction);
+virBufferAsprintf(buf, " deleteAction='%s'", deleteAction);
+}
 }
 
 if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 0a16413852..8055debe56 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -340,6 +340,7 @@ typedef enum {
 
 VIR_DOMAIN_HOSTDEV_DELETE_ACTION_LAST
 } virDomainHostdevDeleteActionType;
+VIR_ENUM_DECL(virDomainHostdevDeleteAction);
 
 
 /* basic device for direct passthrough */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1110e11c14..d7b44dab2c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5187,10 +5187,13 @@ processUSBAddedEvent(virQEMUDriverPtr driver,
 {
 virDomainHostdevDefPtr hostdev;
 virDomainHostdevSubsysUSBPtr usbsrc;
+virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
 size_t i;
 
-if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
+if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) {
+virObjectUnref(cfg);
 return;
+}
 
 if (!virDomainObjIsActive(vm)) {
 VIR_DEBUG("Domain is not running");
@@ -5218,8 +5221,13 @@ processUSBAddedEvent(virQEMUDriverPtr driver,
 if (qemuDomainAttachHostDevice(driver, vm, hostdev) < 0)
 goto cleanup;
 
+if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 
0)
+VIR_WARN("unable to save domain status after plugging device %s",
+ hostdev->info->alias);
+
  cleanup:
 qemuDomainObjEndJob(driver, vm);
+virObjectUnref(cfg);
 }
 
 
@@ -5231,9 +5239,12 @@ processUSBRemovedEvent(virQEMUDriverPtr driver,
 size_t i;
 virDomainHostdevDefPtr hostdev;
 virDomainDeviceDef dev = { .type = VIR_DOMAIN_DEVICE_HOSTDEV };
+virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
 
-if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
+if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) {
+virObjectUnref(cfg);
 return;
+}
 
 if (!virDomainObjIsActive(vm)) {
 VIR_DEBUG("Domain is not running");
@@ -5269,8 +5280,13 @@ processUSBRemovedEvent(virQEMUDriverPtr driver,
 if (qemuDomainDetachDeviceLive(vm, &dev, driver, true, true) < 0)
 goto cleanup;
 
+if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 
0)
+VIR_WARN("unable to save domain status after unplugging d

[libvirt] [PATCH v3 REBASE 10/12] qemu: don't mess with non mandatory hostdevs on reattaching

2019-10-15 Thread Nikolay Shirokovskiy
First I don't want to add code to handle dummy device that is used when
host usb device is not present at the moment of starting/migrating etc.
Second supporting non mandatory policies would require to handle races
when host usb device is plugged to host and libvirtd starts adding
device but if in the meanwhile host usb device it unplugged back then
current code will use dummy device which is not desired in this case.

Signed-off-by: Nikolay Shirokovskiy 
Reviewed-by: Daniel Henrique Barboza 
---
 src/qemu/qemu_driver.c  | 8 
 src/qemu/qemu_process.c | 4 
 2 files changed, 12 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e268e2fd1e..f3aae2ba1a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5252,6 +5252,10 @@ processUSBAddedEvent(virQEMUDriverPtr driver,
 if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
 continue;
 
+if (hostdev->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_OPTIONAL ||
+hostdev->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_REQUISITE)
+continue;
+
 usbsrc = &hostdev->source.subsys.u.usb;
 
 if (!usbsrc->replug)
@@ -5310,6 +5314,10 @@ processUSBRemovedEvent(virQEMUDriverPtr driver,
 if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
 continue;
 
+if (hostdev->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_OPTIONAL ||
+hostdev->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_REQUISITE)
+continue;
+
 usbsrc = &hostdev->source.subsys.u.usb;
 
 if (!usbsrc->replug)
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 82e10f4743..2ab3b6f0b9 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3755,6 +3755,10 @@ qemuProcessReattachUSBDevices(virQEMUDriverPtr driver,
 if (!usbsrc->vendor || !usbsrc->product)
 continue;
 
+if (hostdev->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_OPTIONAL ||
+hostdev->startupPolicy == VIR_DOMAIN_STARTUP_POLICY_REQUISITE)
+continue;
+
 if (!usbsrc->bus && !usbsrc->device) {
 int num;
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 REBASE 03/12] qemu: support host usb device unplug

2019-10-15 Thread Nikolay Shirokovskiy
Handle host usb device unplug in DEVICE_DELETED handle execution
path.

Signed-off-by: Nikolay Shirokovskiy 
Reviewed-by: Daniel Henrique Barboza 
---
 src/qemu/qemu_hotplug.c | 38 +++---
 1 file changed, 31 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 4f7858da71..0e161bfd5a 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4400,7 +4400,8 @@ qemuDomainRemoveUSBHostDevice(virQEMUDriverPtr driver,
   virDomainHostdevDefPtr hostdev)
 {
 qemuHostdevReAttachUSBDevices(driver, vm->def->name, &hostdev, 1);
-qemuDomainReleaseDeviceAddress(vm, hostdev->info);
+if (hostdev->deleteAction != VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG)
+qemuDomainReleaseDeviceAddress(vm, hostdev->info);
 }
 
 static void
@@ -4441,6 +4442,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
 VIR_AUTOFREE(char *) drivealias = NULL;
 VIR_AUTOFREE(char *) objAlias = NULL;
 bool is_vfio = false;
+bool unplug = hostdev->deleteAction == 
VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG;
 
 VIR_DEBUG("Removing host device %s from domain %p %s",
   hostdev->info->alias, vm, vm->def->name);
@@ -4488,16 +4490,24 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
 }
 }
 
-for (i = 0; i < vm->def->nhostdevs; i++) {
-if (vm->def->hostdevs[i] == hostdev) {
-virDomainHostdevRemove(vm->def, i);
-break;
+if (!unplug) {
+for (i = 0; i < vm->def->nhostdevs; i++) {
+if (vm->def->hostdevs[i] == hostdev) {
+virDomainHostdevRemove(vm->def, i);
+break;
+}
 }
 }
 
 virDomainAuditHostdev(vm, hostdev, "detach", true);
 
-if (!is_vfio &&
+/*
+ * In case of unplug the attempt to restore label will fail. But we don't
+ * need to restore the label! In case of separate mount namespace for the
+ * domain we remove device file later in this function. In case of global
+ * mount namespace the device file is deleted or being deleted by systemd.
+ */
+if (!is_vfio && !unplug &&
 qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0)
 VIR_WARN("Failed to restore host device labelling");
 
@@ -4531,7 +4541,13 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
 break;
 }
 
-virDomainHostdevDefFree(hostdev);
+if (unplug) {
+virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
+usbsrc->bus = 0;
+usbsrc->device = 0;
+} else {
+virDomainHostdevDefFree(hostdev);
+}
 
 if (net) {
 if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
@@ -4546,6 +4562,8 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
 virDomainNetDefFree(net);
 }
 
+hostdev->deleteAction = VIR_DOMAIN_HOSTDEV_DELETE_ACTION_NONE;
+
 return 0;
 }
 
@@ -4984,6 +5002,7 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver,
 virDomainDeviceInfoPtr info;
 virObjectEventPtr event;
 VIR_AUTOFREE(char *) alias = NULL;
+bool unplug;
 
 /*
  * save the alias to use when sending a DEVICE_REMOVED event after
@@ -5024,8 +5043,13 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver,
 return -1;
 break;
 case VIR_DOMAIN_DEVICE_HOSTDEV:
+unplug = dev->data.hostdev->deleteAction == 
VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG;
+
 if (qemuDomainRemoveHostDevice(driver, vm, dev->data.hostdev) < 0)
 return -1;
+
+if (unplug)
+return 0;
 break;
 case VIR_DOMAIN_DEVICE_RNG:
 if (qemuDomainRemoveRNGDevice(driver, vm, dev->data.rng) < 0)
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 REBASE 12/12] conf: parse hostdev missing flag

2019-10-15 Thread Nikolay Shirokovskiy
We want to keep this flag across libvirtd restarts.

Signed-off-by: Nikolay Shirokovskiy 
Reviewed-by: Daniel Henrique Barboza 
---
 src/conf/domain_conf.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d185730023..35006cac8c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7596,6 +7596,7 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
 VIR_AUTOFREE(char *) startupPolicy = NULL;
 VIR_AUTOFREE(char *) autoAddress = NULL;
 VIR_AUTOFREE(char *) deleteAction = NULL;
+VIR_AUTOFREE(char *) missing = NULL;
 
 if ((startupPolicy = virXMLPropString(node, "startupPolicy"))) {
 def->startupPolicy =
@@ -7625,6 +7626,11 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
 }
 }
 
+if ((missing = virXMLPropString(node, "missing"))) {
+if (STREQ(missing, "yes"))
+def->missing = true;
+}
+
 /* Product can validly be 0, so we need some extra help to determine
  * if it is uninitialized*/
 got_product = false;
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 REBASE 04/12] qemu: support usb hostdev plugging back

2019-10-15 Thread Nikolay Shirokovskiy
We are going to use qemuDomainAttachHostUSBDevice when
host usb device is plugged back to node.

Signed-off-by: Nikolay Shirokovskiy 
Reviewed-by: Daniel Henrique Barboza 
---
 src/qemu/qemu_hotplug.c | 29 -
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0e161bfd5a..920e0cb72b 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2478,8 +2478,18 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
 bool teardownlabel = false;
 bool teardowndevice = false;
 int ret = -1;
+bool replug = false;
+size_t i;
+
+for (i = 0; i < vm->def->nhostdevs; i++) {
+if (vm->def->hostdevs[i] == hostdev) {
+replug = true;
+break;
+}
+}
 
-if (virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0)
+if (!replug &&
+virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0)
 return -1;
 
 if (qemuHostdevPrepareUSBDevices(driver, vm->def->name, &hostdev, 1, 0) < 
0)
@@ -2504,7 +2514,7 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
 if (!(devstr = qemuBuildUSBHostdevDevStr(vm->def, hostdev, 
priv->qemuCaps)))
 goto cleanup;
 
-if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0)
+if (!replug && VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0)
 goto cleanup;
 
 qemuDomainObjEnterMonitor(driver, vm);
@@ -2517,7 +2527,8 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
 if (ret < 0)
 goto cleanup;
 
-vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
+if (!replug)
+vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
 
 ret = 0;
  cleanup:
@@ -2530,9 +2541,17 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
 if (teardowndevice &&
 qemuDomainNamespaceTeardownHostdev(vm, hostdev) < 0)
 VIR_WARN("Unable to remove host device from /dev");
-if (added)
+if (added) {
 qemuHostdevReAttachUSBDevices(driver, vm->def->name, &hostdev, 1);
-virDomainUSBAddressRelease(priv->usbaddrs, hostdev->info);
+
+if (replug) {
+virDomainHostdevSubsysUSBPtr usbsrc = 
&hostdev->source.subsys.u.usb;
+usbsrc->bus = 0;
+usbsrc->device = 0;
+}
+}
+if (!replug)
+virDomainUSBAddressRelease(priv->usbaddrs, hostdev->info);
 }
 return ret;
 }
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 REBASE 01/12] conf: add replug option for usb hostdev

2019-10-15 Thread Nikolay Shirokovskiy
If usb device attached to a domain is unplugged from host and
then plugged back then it will no longer be available in guest.
We are going to support this case so that device will be detached
from qemu on unplug and attached back on replug. As sometimes
this behaviour is not desirable and for backcompat too let's
add 'replug' option for usb hostdev.

Signed-off-by: Nikolay Shirokovskiy 
---
 docs/formatdomain.html.in | 10 -
 docs/schemas/domaincommon.rng |  5 +++
 src/conf/domain_conf.c| 30 ++
 src/conf/domain_conf.h|  2 +
 tests/qemuxml2argvdata/hostdev-usb-replug.xml | 36 +
 .../qemuxml2xmloutdata/hostdev-usb-replug.xml | 40 +++
 tests/qemuxml2xmltest.c   |  1 +
 7 files changed, 122 insertions(+), 2 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/hostdev-usb-replug.xml
 create mode 100644 tests/qemuxml2xmloutdata/hostdev-usb-replug.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 500f114f41..8e1c0bf6fa 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4688,7 +4688,7 @@
 
 ...
 
-  
+  
 
   
   
@@ -4787,7 +4787,13 @@
   usb
   USB devices are detached from the host on guest startup
 and reattached after the guest exits or the device is
-hot-unplugged.
+hot-unplugged. If optional replug
+(since 5.8.0) is "yes" then libvirt
+tracks USB device unplug/plug on host. On unplug the correspondent
+QEMU device will be be deleted but device stays in libvirt config.
+On plug the device will be added back to QEMU. This applies only
+for USB devices with product/vendor pair specified. Default value
+is "no".
   
   pci
   For PCI devices, when managed is "yes" it is
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index ead5a25068..caba7f4e24 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4658,6 +4658,11 @@
 
   usb
 
+
+  
+
+  
+
 
   
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6bd2d4935d..c99758d9f5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7702,6 +7702,13 @@ virDomainHostdevSubsysUSBDefParseXML(xmlNodePtr node,
 goto out;
 }
 
+if (usbsrc->replug && (!got_vendor || !got_product)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("replug is only possible if vendor/product "
+ "pair is specified"));
+goto out;
+}
+
 ret = 0;
  out:
 return ret;
@@ -8155,12 +8162,14 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 virDomainHostdevSubsysSCSIPtr scsisrc = &def->source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIVHostPtr scsihostsrc = 
&def->source.subsys.u.scsi_host;
 virDomainHostdevSubsysMediatedDevPtr mdevsrc = &def->source.subsys.u.mdev;
+virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb;
 VIR_AUTOFREE(char *) managed = NULL;
 VIR_AUTOFREE(char *) sgio = NULL;
 VIR_AUTOFREE(char *) rawio = NULL;
 VIR_AUTOFREE(char *) backendStr = NULL;
 VIR_AUTOFREE(char *) model = NULL;
 VIR_AUTOFREE(char *) display = NULL;
+VIR_AUTOFREE(char *) replug = NULL;
 
 /* @managed can be read from the xml document - it is always an
  * attribute of the toplevel element, no matter what type of
@@ -8176,6 +8185,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 rawio = virXMLPropString(node, "rawio");
 model = virXMLPropString(node, "model");
 display = virXMLPropString(node, "display");
+replug = virXMLPropString(node, "replug");
 
 /* @type is passed in from the caller rather than read from the
  * xml document, because it is specified in different places for
@@ -8242,6 +8252,20 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
 }
 }
 
+if (replug) {
+if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("replug is only supported for usb host device"));
+return -1;
+}
+
+if ((usbsrc->replug = virTristateBoolTypeFromString(replug)) <= 0) {
+virReportError(VIR_ERR_XML_ERROR,
+   _("unknown hostdev replug setting '%s'"), rawio);
+return -1;
+}
+}
+
 if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV &&
 def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST) {
 if (model) {
@@ -27220,6 +

[libvirt] [PATCH v3 REBASE 08/12] qemu: hotplug: update device list on device deleted event

2019-10-15 Thread Nikolay Shirokovskiy
I guess this is the missing piece for [1]. It did not hurt before (like
we didn't even see any errors/warns in logs) because in
qemuProcessUpdateDevices function virDomainDefFindDevice does not find
device deleted from libvirt config. But now in case of unpluggind usb
device from host we leave device in config and thus needlessly try to
call qemuDomainRemoveDevice second time.

[1] 0dfb8a1b9: qemu: Unplug devices that disappeared when libvirtd was down

Signed-off-by: Nikolay Shirokovskiy 
---
 src/qemu/qemu_driver.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 030fe8a6c4..e268e2fd1e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4646,6 +4646,9 @@ processDeviceDeletedEvent(virQEMUDriverPtr driver,
 if (STRPREFIX(devAlias, "vcpu")) {
 qemuDomainRemoveVcpuAlias(driver, vm, devAlias);
 } else {
+if (qemuDomainUpdateDeviceList(driver, vm, QEMU_ASYNC_JOB_NONE) < 0)
+goto cleanup;
+
 if (virDomainDefFindDevice(vm->def, devAlias, &dev, true) < 0)
 goto endjob;
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 REBASE 05/12] qemu: handle host usb device add/del udev events

2019-10-15 Thread Nikolay Shirokovskiy
Now when code handling attaching/detaching usb hostdev is appropriately
changed use it to handle host usb device udev add/del events.

As device adding/deleting needs acquiring job condition it is done in
thread pool rather in event loop thread itself where udev events are
delivered. However implementation in this patch is a bit different from
other places as we instead of finding right domain in event loop thread
and creating a single thread pool job create job for every vm. Such
a strategy allows us to avoid taking domain lock in event loop thread so
we have little chances to block event loop thread because some API
handler grabs domain lock for a significant amount of time.

Signed-off-by: Nikolay Shirokovskiy 
---
 src/qemu/Makefile.inc.am |   2 +
 src/qemu/qemu_conf.h |   3 +
 src/qemu/qemu_domain.c   |   2 +
 src/qemu/qemu_domain.h   |   2 +
 src/qemu/qemu_driver.c   | 324 ++-
 5 files changed, 332 insertions(+), 1 deletion(-)

diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am
index e66da76c0a..49b0202a11 100644
--- a/src/qemu/Makefile.inc.am
+++ b/src/qemu/Makefile.inc.am
@@ -98,6 +98,7 @@ libvirt_driver_qemu_impl_la_CFLAGS = \
-I$(srcdir)/conf \
-I$(srcdir)/secret \
$(AM_CFLAGS) \
+   $(UDEV_CFLAGS) \
$(NULL)
 libvirt_driver_qemu_impl_la_LDFLAGS = $(AM_LDFLAGS)
 libvirt_driver_qemu_impl_la_LIBADD = \
@@ -106,6 +107,7 @@ libvirt_driver_qemu_impl_la_LIBADD = \
$(LIBNL_LIBS) \
$(SELINUX_LIBS) \
$(LIBXML_LIBS) \
+   $(UDEV_LIBS) \
$(NULL)
 libvirt_driver_qemu_impl_la_SOURCES = $(QEMU_DRIVER_SOURCES)
 
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 7247199d3e..23c9b4d9fa 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -299,6 +299,9 @@ struct _virQEMUDriver {
 
 /* Immutable pointer, self-locking APIs */
 virHashAtomicPtr migrationErrors;
+
+struct udev_monitor *udev_monitor;
+int udev_watch;
 };
 
 virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index a6c95b7208..61c0c0e143 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -15335,6 +15335,8 @@ qemuProcessEventFree(struct qemuProcessEvent *event)
 case QEMU_PROCESS_EVENT_SERIAL_CHANGED:
 case QEMU_PROCESS_EVENT_BLOCK_JOB:
 case QEMU_PROCESS_EVENT_MONITOR_EOF:
+case QEMU_PROCESS_EVENT_USB_REMOVED:
+case QEMU_PROCESS_EVENT_USB_ADDED:
 VIR_FREE(event->data);
 break;
 case QEMU_PROCESS_EVENT_JOB_STATUS_CHANGE:
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 282ab2c3ec..3ba8b059ec 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -549,6 +549,8 @@ typedef enum {
 QEMU_PROCESS_EVENT_MONITOR_EOF,
 QEMU_PROCESS_EVENT_PR_DISCONNECT,
 QEMU_PROCESS_EVENT_RDMA_GID_STATUS_CHANGED,
+QEMU_PROCESS_EVENT_USB_REMOVED,
+QEMU_PROCESS_EVENT_USB_ADDED,
 
 QEMU_PROCESS_EVENT_LAST
 } qemuProcessEventType;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ca40879977..1110e11c14 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 
 
 #include "qemu_driver.h"
@@ -657,6 +658,221 @@ qemuDomainFindMaxID(virDomainObjPtr vm,
 }
 
 
+struct qemuUdevUSBRemoveData {
+unsigned int bus;
+unsigned int device;
+};
+
+struct qemuUdevUSBAddData {
+unsigned int vendor;
+unsigned int product;
+};
+
+struct qemuUdevUSBEventData {
+union {
+struct qemuUdevUSBRemoveData remove;
+struct qemuUdevUSBAddData add;
+} data;
+bool remove;
+};
+
+static int
+qemuUdevUSBHandleEvent(virDomainObjPtr vm, void *opaque)
+{
+struct qemuUdevUSBEventData *data = opaque;
+struct qemuProcessEvent *event = NULL;
+
+if (VIR_ALLOC(event) < 0)
+return 0;
+
+if (data->remove) {
+struct qemuUdevUSBRemoveData *rm_data;
+
+
+if (VIR_ALLOC(rm_data) < 0)
+goto cleanup;
+
+*rm_data = data->data.remove;
+event->data = rm_data;
+event->eventType = QEMU_PROCESS_EVENT_USB_REMOVED;
+} else {
+struct qemuUdevUSBAddData *add_data;
+
+if (VIR_ALLOC(add_data) < 0)
+goto cleanup;
+
+*add_data = data->data.add;
+event->data = add_data;
+event->eventType = QEMU_PROCESS_EVENT_USB_ADDED;
+}
+
+event->vm = virObjectRef(vm);
+
+if (virThreadPoolSendJob(qemu_driver->workerPool, 0, event) < 0) {
+virObjectUnref(vm);
+goto cleanup;
+}
+
+event = NULL;
+
+ cleanup:
+qemuProcessEventFree(event);
+
+return 0;
+}
+
+
+static void
+qemuUdevEventHandleCallback(int watch G_GNUC_UNUSED,
+int fd G_GNUC_UNUSED,
+int events G_GNUC_UNUSED,
+void *data G_GNUC_UNUSED)
+{
+struct qemuUdevUSBEventData event

[libvirt] [PATCH v3 REBASE 11/12] qemu: handle detaching of unplugged hostdev

2019-10-15 Thread Nikolay Shirokovskiy
If hostdev is unplugged we don't need to delete it's correspondent device
from qemu etc. Just remove it from config immediately.

Signed-off-by: Nikolay Shirokovskiy 
---
 src/qemu/qemu_hotplug.c | 16 +++-
 src/util/virhostdev.c   |  2 ++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 920e0cb72b..8ba0235dbc 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4462,6 +4462,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
 VIR_AUTOFREE(char *) objAlias = NULL;
 bool is_vfio = false;
 bool unplug = hostdev->deleteAction == 
VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG;
+bool unplugged = false;
 
 VIR_DEBUG("Removing host device %s from domain %p %s",
   hostdev->info->alias, vm, vm->def->name);
@@ -4520,13 +4521,17 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
 
 virDomainAuditHostdev(vm, hostdev, "detach", true);
 
+if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
+virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
+unplugged = !usbsrc->bus && !usbsrc->device;
+}
 /*
  * In case of unplug the attempt to restore label will fail. But we don't
  * need to restore the label! In case of separate mount namespace for the
  * domain we remove device file later in this function. In case of global
  * mount namespace the device file is deleted or being deleted by systemd.
  */
-if (!is_vfio && !unplug &&
+if (!is_vfio && !unplug && !unplugged &&
 qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0)
 VIR_WARN("Failed to restore host device labelling");
 
@@ -5832,6 +5837,15 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
 unplug) < 0) {
 return -1;
 }
+if (!unplug) {
+virDomainHostdevDefPtr hostdev = detach.data.hostdev;
+virDomainHostdevSubsysUSBPtr usbsrc = 
&hostdev->source.subsys.u.usb;
+
+if (hostdev->startupPolicy != VIR_DOMAIN_STARTUP_POLICY_OPTIONAL &&
+hostdev->startupPolicy != VIR_DOMAIN_STARTUP_POLICY_REQUISITE 
&&
+usbsrc->device == 0 && usbsrc->bus == 0)
+return qemuDomainRemoveDevice(driver, vm, &detach);
+}
 break;
 case VIR_DOMAIN_DEVICE_RNG:
 if (qemuDomainDetachPrepRNG(vm, match->data.rng,
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 41fcab7222..ed9bc09e14 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1793,6 +1793,8 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr mgr,
 continue;
 if (hostdev->missing)
 continue;
+if (!usbsrc->bus && !usbsrc->device)
+continue;
 
 if (!(usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL))) {
 VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 REBASE 02/12] qemu: track hostdev delete intention

2019-10-15 Thread Nikolay Shirokovskiy
So we are going to support replug of usb device on host. We need to
delete device from qemu when the device is unplugged on host and to add
device when the device is plugged back. As to deleting let's use
same code as when we detach device from domain. But we need to keep
the usb hostdev etc in libvirt config when handle DEVICE_DELETED event
from qemu. For this purpose let's save delete intention in device config.

Signed-off-by: Nikolay Shirokovskiy 
---
 src/conf/domain_conf.h  | 14 ++
 src/qemu/qemu_driver.c  |  4 ++--
 src/qemu/qemu_hotplug.c | 23 ---
 src/qemu/qemu_hotplug.h |  3 ++-
 tests/qemuhotplugtest.c |  2 +-
 5 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index da3eff242b..0a16413852 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -328,6 +328,19 @@ struct _virDomainHostdevCaps {
 } u;
 };
 
+typedef enum {
+VIR_DOMAIN_HOSTDEV_DELETE_ACTION_NONE = 0,
+/* delete associated device from libvirt config
+ * as intended by client API call */
+VIR_DOMAIN_HOSTDEV_DELETE_ACTION_DELETE,
+/* keep associated device in libvirt config as
+ * qemu device is deleted as a result of unplugging
+ * device from host */
+VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG,
+
+VIR_DOMAIN_HOSTDEV_DELETE_ACTION_LAST
+} virDomainHostdevDeleteActionType;
+
 
 /* basic device for direct passthrough */
 struct _virDomainHostdevDef {
@@ -345,6 +358,7 @@ struct _virDomainHostdevDef {
 bool missing;
 bool readonly;
 bool shareable;
+virDomainHostdevDeleteActionType deleteAction;
 union {
 virDomainHostdevSubsys subsys;
 virDomainHostdevCaps caps;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 681b26814b..ca40879977 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -9078,7 +9078,7 @@ qemuDomainDetachDeviceLiveAndConfig(virQEMUDriverPtr 
driver,
 if (flags & VIR_DOMAIN_AFFECT_LIVE) {
 int rc;
 
-if ((rc = qemuDomainDetachDeviceLive(vm, dev_copy, driver, false)) < 0)
+if ((rc = qemuDomainDetachDeviceLive(vm, dev_copy, driver, false, 
false)) < 0)
 goto cleanup;
 
 if (rc == 0 && qemuDomainUpdateDeviceList(driver, vm, 
QEMU_ASYNC_JOB_NONE) < 0)
@@ -9167,7 +9167,7 @@ qemuDomainDetachDeviceAliasLiveAndConfig(virQEMUDriverPtr 
driver,
 if (virDomainDefFindDevice(def, alias, &dev, true) < 0)
 goto cleanup;
 
-if ((rc = qemuDomainDetachDeviceLive(vm, &dev, driver, true)) < 0)
+if ((rc = qemuDomainDetachDeviceLive(vm, &dev, driver, true, false)) < 
0)
 goto cleanup;
 
 if (rc == 0 && qemuDomainUpdateDeviceList(driver, vm, 
QEMU_ASYNC_JOB_NONE) < 0)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 88984dff67..4f7858da71 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -5351,7 +5351,8 @@ qemuDomainDetachPrepController(virDomainObjPtr vm,
 static int
 qemuDomainDetachPrepHostdev(virDomainObjPtr vm,
 virDomainHostdevDefPtr match,
-virDomainHostdevDefPtr *detach)
+virDomainHostdevDefPtr *detach,
+bool unplug)
 {
 virDomainHostdevSubsysPtr subsys = &match->source.subsys;
 virDomainHostdevSubsysUSBPtr usbsrc = &subsys->u.usb;
@@ -5423,6 +5424,20 @@ qemuDomainDetachPrepHostdev(virDomainObjPtr vm,
 return -1;
 }
 
+/*
+ * Why having additional check in second branch? Suppose client
+ * asks for device detaching and we delete device from qemu
+ * but don't get DEVICE_DELETED event yet. Next USB is unplugged
+ * from host and we have this function called again. If we reset
+ * delete action to 'unplug' then device will be left in
+ * libvirt config after handling DEVICE_DELETED event while
+ * it should not as client asked to detach the device before.
+ */
+if (!unplug)
+hostdev->deleteAction = VIR_DOMAIN_HOSTDEV_DELETE_ACTION_DELETE;
+else if (hostdev->deleteAction != VIR_DOMAIN_HOSTDEV_DELETE_ACTION_DELETE)
+hostdev->deleteAction = VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG;
+
 return 0;
 }
 
@@ -5724,7 +5739,8 @@ int
 qemuDomainDetachDeviceLive(virDomainObjPtr vm,
virDomainDeviceDefPtr match,
virQEMUDriverPtr driver,
-   bool async)
+   bool async,
+   bool unplug)
 {
 virDomainDeviceDef detach = { .type = match->type };
 virDomainDeviceInfoPtr info = NULL;
@@ -5769,7 +5785,8 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
 break;
 case VIR_DOMAIN_DEVICE_HOSTDEV:
 if (qemuDomainDetachPrepHostdev(vm, match->data.hostdev,
-&detach.data.hostdev) < 0) {
+&detach.data

[libvirt] [PATCH v3 REBASE 07/12] qemu: handle race on device deletion and usb host device plugging

2019-10-15 Thread Nikolay Shirokovskiy
Imagine host usb device is unplugged from host and as a result we send
command to qemu to delete appropriate device. Then before qemu device is
deleted host usb device is plugged back. Currently code supposes there is
no remnant device in qemu and will try to add new device and the attempt
will fail.

Instead let's check the device is not yet deleted and postpone adding
qemu device to device_deleted event handler.

Signed-off-by: Nikolay Shirokovskiy 
Reviewed-by: Daniel Henrique Barboza 
---
 src/qemu/qemu_driver.c | 49 ++
 1 file changed, 49 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d7b44dab2c..030fe8a6c4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4586,6 +4586,44 @@ processGuestPanicEvent(virQEMUDriverPtr driver,
 }
 
 
+static int
+qemuCheckHostdevPlugged(virQEMUDriverPtr driver,
+virDomainObjPtr vm,
+const char *devAlias)
+{
+virDomainHostdevDefPtr hostdev;
+virDomainHostdevSubsysUSBPtr usbsrc;
+virDomainDeviceDef dev;
+int num;
+
+if (virDomainDefFindDevice(vm->def, devAlias, &dev, false) < 0)
+return 0;
+
+if (dev.type != VIR_DOMAIN_DEVICE_HOSTDEV)
+return 0;
+
+hostdev = dev.data.hostdev;
+if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
+return 0;
+
+usbsrc = &hostdev->source.subsys.u.usb;
+if (!usbsrc->vendor || !usbsrc->product)
+return 0;
+
+if ((num = virUSBDeviceFindByVendor(usbsrc->vendor, usbsrc->product,
+NULL, false, NULL)) < 0)
+return -1;
+
+if (num == 0)
+return 0;
+
+if (qemuDomainAttachHostDevice(driver, vm, hostdev) < 0)
+return -1;
+
+return 0;
+}
+
+
 static void
 processDeviceDeletedEvent(virQEMUDriverPtr driver,
   virDomainObjPtr vm,
@@ -4613,6 +4651,11 @@ processDeviceDeletedEvent(virQEMUDriverPtr driver,
 
 if (qemuDomainRemoveDevice(driver, vm, &dev) < 0)
 goto endjob;
+
+/* Fall thru and save status file even on error condition because
+ * device is removed successfully and changed configuration need
+ * to be saved in status file. */
+qemuCheckHostdevPlugged(driver, vm, devAlias);
 }
 
 if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 
0)
@@ -5218,6 +5261,12 @@ processUSBAddedEvent(virQEMUDriverPtr driver,
 if (i == vm->def->nhostdevs)
 goto cleanup;
 
+/* if device is not yet even deleted from qemu then handle plugging later.
+ * Or we failed handling host usb device unplugging, then another attempt 
of
+ * unplug/plug could help. */
+if (usbsrc->bus || usbsrc->device)
+goto cleanup;
+
 if (qemuDomainAttachHostDevice(driver, vm, hostdev) < 0)
 goto cleanup;
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/1] Add shrink flag to blockresize command

2019-10-15 Thread Cole Robinson
On 10/5/19 2:56 PM, martinsson.pat...@gmail.com wrote:
> From: patchon 
> 

You probably want to fix this to match your signed-off-by name.

> These commits simply adds the '--shrink' flag to the blockresize
> command to prevent accidental shrinking of a block device. This
> behaviour is already present on the vol-resize command and it
> makes sense to mimic that behaviour.
> 

I don't have an opinion on whether the feature should be added at the
API level, I will leave that to others. CCing pkrempa

But as implemented it seems problematic to add a flag that changes the
semantics of the API, essentially requiring a new flag to get the old
behavior. I see the argument that this is a data safety issue, but maybe
apps are depending on this already? I don't know enough about the usage
to guess either way

> Only implemented in the qemu-driver atm.
> 
> Signed-off-by: Patrik Martinsson 
> ---
>  src/qemu/qemu_driver.c | 15 ++-
>  tools/virsh-domain.c   |  7 +++
>  tools/virsh.pod|  9 -
>  3 files changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 95fe844c34..4e34eec796 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -11265,8 +11265,10 @@ qemuDomainBlockResize(virDomainPtr dom,
>  char *device = NULL;
>  const char *nodename = NULL;
>  virDomainDiskDefPtr disk = NULL;
> +virDomainBlockInfo info;
>  
> -virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1);
> +virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES |
> +  VIR_STORAGE_VOL_RESIZE_SHRINK, -1);
>  

We shouldn't mix and match flag prefix names. Each public API should be
coupled with its own set of flag names. So you would want to call this
VIR_DOMAIN_BLOCK_RESIZE_SHRINK, and add it to
include/libvirt/libvirt-domain.h and add it to documentation in
libvirt-domain.c

- Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 7/8] examples: Use G_N_ELEMENTS instead of ARRAY_CARDINALITY

2019-10-15 Thread Ján Tomko

On Tue, Oct 15, 2019 at 04:10:55PM +0200, Andrea Bolognani wrote:

On Tue, 2019-10-15 at 14:21 +0200, Ján Tomko wrote:

We try to keep the example programs independent of libraries
other than libvirt.

Rename the locally defined ARRAY_CARDINALITY macro to G_N_ELEMENTS
which GLib provides, even though we don't actually include GLib.


[...]


-#define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array)))
+#define G_N_ELEMENTS(Array) (sizeof(Array) / sizeof(*(Array)))


In this case, and in this case only, I think we should leave the name
alone.


This case being "the isolated event-test.c example" or "the
ARRAY_CARDINALITY macro in event-test.c"?

If it's the latter, I can add an exception to syntax-check instead.

Note that I also added a G_GNUC_UNUSED macro earlier, if the G_ prefix
is the issue. (The ATTRIBUTE_UNUSED spelling is used by multiple libs,
including libxml2)

Also, we open-code the 'verify' macro from gnulib.



When we use GLib and simply provide our own implementation when using
a version that's too old, the GLib name is obviously accurate, but in
this specific case I think it's misleading and we should stick with
the current one.



Alternatively, would a comment along the lines of:
/* define these macros to avoid pulling in glib */
make it less misleading?

The reason we included these macros here in the first place is that
we wanted to keep the code in sync with the rest of libvirt.

Jano



--
Andrea Bolognani / Red Hat / Virtualization



signature.asc
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 1/9] util: xml: use g_auto directly for VIR_XPATH_NODE_AUTORESTORE

2019-10-15 Thread Ján Tomko
Since commit 44e7f029159ed701b4a1739ac711507ee53790ed
util: rewrite auto cleanup macros to use glib's equivalent

VIR_AUTOCLEAN is just an alias for g_auto. Use the GLib macros
directly instead of our custom aliases.

Signed-off-by: Ján Tomko 
---
 src/util/virxml.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/util/virxml.h b/src/util/virxml.h
index c7def9ce61..8813e31f75 100644
--- a/src/util/virxml.h
+++ b/src/util/virxml.h
@@ -233,7 +233,7 @@ typedef virXPathContextNodeSave *virXPathContextNodeSavePtr;
 void
 virXPathContextNodeRestore(virXPathContextNodeSavePtr save);
 
-VIR_DEFINE_AUTOCLEAN_FUNC(virXPathContextNodeSave, virXPathContextNodeRestore);
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virXPathContextNodeSave, 
virXPathContextNodeRestore);
 
 /**
  * VIR_XPATH_NODE_AUTORESTORE:
@@ -243,8 +243,8 @@ VIR_DEFINE_AUTOCLEAN_FUNC(virXPathContextNodeSave, 
virXPathContextNodeRestore);
  * node pointer is reset to the original value when this macro was used.
  */
 #define VIR_XPATH_NODE_AUTORESTORE(_ctxt) \
-VIR_AUTOCLEAN(virXPathContextNodeSave) _ctxt ## CtxtSave = { .ctxt = 
_ctxt,\
- .node = 
_ctxt->node}; \
+g_auto(virXPathContextNodeSave) _ctxt ## CtxtSave = { .ctxt = _ctxt,\
+  .node = 
_ctxt->node}; \
 ignore_value(&_ctxt ## CtxtSave)
 
 VIR_DEFINE_AUTOPTR_FUNC(xmlDoc, xmlFreeDoc);
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 8/9] Delete virObjectAutoUnref

2019-10-15 Thread Ján Tomko
Signed-off-by: Ján Tomko 
---
 src/libvirt_private.syms |  1 -
 src/util/virobject.c | 14 --
 src/util/virobject.h | 15 ---
 3 files changed, 30 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7d62df8086..0da02bb8bd 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2636,7 +2636,6 @@ virClassForObjectRWLockable;
 virClassIsDerivedFrom;
 virClassName;
 virClassNew;
-virObjectAutoUnref;
 virObjectFreeCallback;
 virObjectFreeHashData;
 virObjectIsClass;
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 33feeb659a..c5363308d8 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -367,20 +367,6 @@ virObjectUnref(void *anyobj)
 }
 
 
-/**
- * virObjectAutoUnref:
- *
- * Helper used by VIR_AUTOUNREF
- */
-void
-virObjectAutoUnref(void *objptr)
-{
-virObjectPtr *obj = objptr;
-virObjectUnref(*obj);
-*obj = NULL;
-}
-
-
 /**
  * virObjectRef:
  * @anyobj: any instance of virObjectPtr
diff --git a/src/util/virobject.h b/src/util/virobject.h
index 773a009f5e..7cb3457021 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -109,21 +109,6 @@ virObjectNew(virClassPtr klass)
 bool
 virObjectUnref(void *obj);
 
-void
-virObjectAutoUnref(void *objptr);
-
-/**
- * VIR_AUTOUNREF:
- * @type: type of an virObject subclass to be unref'd automatically
- *
- * DEPRECATED: Use g_autoptr(type) instead
- *
- * Declares a variable of @type which will be automatically unref'd when
- * control goes out of the scope.
- */
-#define VIR_AUTOUNREF(type) \
-__attribute__((cleanup(virObjectAutoUnref))) type
-
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virObject, virObjectUnref);
 
 void *
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 2/9] virbuffer: use g_auto directly for virBuffer

2019-10-15 Thread Ján Tomko
Since commit 44e7f029159ed701b4a1739ac711507ee53790ed
util: rewrite auto cleanup macros to use glib's equivalent

VIR_AUTOCLEAN is just an alias for g_auto. Use the GLib macros
directly instead of our custom aliases.

Signed-off-by: Ján Tomko 
---
 src/conf/domain_conf.c   | 100 +-
 src/libxl/xen_common.c   |   2 +-
 src/qemu/qemu_command.c  | 136 +--
 src/qemu/qemu_domain.c   |  28 
 src/qemu/qemu_firmware.c |   2 +-
 src/qemu/qemu_monitor_json.c |   2 +-
 src/util/virbuffer.h |   2 +-
 src/util/virjson.c   |   2 +-
 tests/qemublocktest.c|   8 +--
 tests/qemumonitortestutils.c |   2 +-
 tests/virbuftest.c   |   6 +-
 tests/virstoragetest.c   |   2 +-
 tests/virsystemdtest.c   |   2 +-
 13 files changed, 147 insertions(+), 147 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 10d6bf0eea..16b939d511 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7095,8 +7095,8 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
   virDomainDeviceInfoPtr info,
   unsigned int flags)
 {
-VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
-VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
 int ret = -1;
 
 if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) && info->bootIndex) {
@@ -24139,7 +24139,7 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr buf,
  unsigned int flags,
  virDomainXMLOptionPtr xmlopt)
 {
-VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
 int ret = -1;
 
 if (!(flags & VIR_DOMAIN_DEF_FORMAT_STATUS) ||
@@ -24183,8 +24183,8 @@ virDomainDiskSourceFormat(virBufferPtr buf,
   unsigned int flags,
   virDomainXMLOptionPtr xmlopt)
 {
-VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
-VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
 
 virBufferSetChildIndent(&childBuf, buf);
 
@@ -24271,8 +24271,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
 virDomainXMLOptionPtr xmlopt,
 unsigned int flags)
 {
-VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
-VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
 bool inactive = flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE;
 virStorageSourcePtr backingStore = src->backingStore;
 
@@ -24435,8 +24435,8 @@ virDomainDiskDefFormatMirror(virBufferPtr buf,
  unsigned int flags,
  virDomainXMLOptionPtr xmlopt)
 {
-VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
-VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
 const char *formatStr = NULL;
 
 virBufferSetChildIndent(&childBuf, buf);
@@ -24488,7 +24488,7 @@ virDomainDiskDefFormatPrivateData(virBufferPtr buf,
   unsigned int flags,
   virDomainXMLOptionPtr xmlopt)
 {
-VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
 
 if (!(flags & VIR_DOMAIN_DEF_FORMAT_STATUS) ||
 !xmlopt ||
@@ -24637,7 +24637,7 @@ static int
 virDomainControllerDriverFormat(virBufferPtr buf,
 virDomainControllerDefPtr def)
 {
-VIR_AUTOCLEAN(virBuffer) driverBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) driverBuf = VIR_BUFFER_INITIALIZER;
 
 if (def->queues)
 virBufferAsprintf(&driverBuf, " queues='%u'", def->queues);
@@ -24670,8 +24670,8 @@ virDomainControllerDefFormat(virBufferPtr buf,
 const char *type = virDomainControllerTypeToString(def->type);
 const char *model = NULL;
 const char *modelName = NULL;
-VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
-VIR_AUTOCLEAN(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER;
 
 virBufferSetChildIndent(&childBuf, buf);
 
@@ -24839,7 +24839,7 @@ virDomainFSDefFormat(virBufferPtr buf,
 const char *fsdriver = virDomainFSDriverTypeToString(def->fsdriver);
 const char *wrpolicy = virDomainFSWrpolicyTypeToString(def->wrpolicy);
 const char *src = def->src-

[libvirt] [PATCH 4/9] Use G_DEFINE_AUTOPTR_CLEANUP_FUNC instead of VIR_DEFINE_AUTOPTR_FUNC

2019-10-15 Thread Ján Tomko
Since commit 44e7f029159ed701b4a1739ac711507ee53790ed
util: rewrite auto cleanup macros to use glib's equivalent

VIR_AUTOPTR aliases to g_autoptr. Replace all uses of VIR_DEFINE_AUTOPTR_FUNC
with G_DEFINE_AUTOPTR_CLEANUP_FUNC in preparation for replacing the
rest.

Signed-off-by: Ján Tomko 
---
 src/conf/domain_capabilities.h   | 2 +-
 src/conf/domain_conf.h   | 2 +-
 src/conf/secret_conf.h   | 2 +-
 src/conf/storage_conf.h  | 6 +++---
 src/conf/virnetworkportdef.h | 2 +-
 src/qemu/qemu_block.c| 2 +-
 src/qemu/qemu_block.h| 4 ++--
 src/qemu/qemu_dbus.h | 2 +-
 src/qemu/qemu_firmware.c | 6 +++---
 src/qemu/qemu_firmware.h | 2 +-
 src/qemu/qemu_migration_params.h | 2 +-
 src/qemu/qemu_monitor.h  | 2 +-
 src/qemu/qemu_slirp.h| 2 +-
 src/qemu/qemu_vhost_user.c   | 2 +-
 src/qemu/qemu_vhost_user.h   | 2 +-
 src/util/virauthconfig.h | 2 +-
 src/util/virbitmap.h | 2 +-
 src/util/vircommand.h| 2 +-
 src/util/virconf.h   | 2 +-
 src/util/virerror.h  | 2 +-
 src/util/virfile.h   | 2 +-
 src/util/virfirewall.h   | 2 +-
 src/util/virfirmware.h   | 2 +-
 src/util/virhash.h   | 2 +-
 src/util/virjson.h   | 2 +-
 src/util/virmacaddr.h| 2 +-
 src/util/virmdev.h   | 4 ++--
 src/util/virnetdev.c | 2 +-
 src/util/virnetdev.h | 2 +-
 src/util/virnetdevip.h   | 4 ++--
 src/util/virnetdevvlan.h | 2 +-
 src/util/virnetlink.c| 2 +-
 src/util/virnetlink.h| 2 +-
 src/util/virpci.h| 6 +++---
 src/util/virperf.h   | 2 +-
 src/util/virscsi.c   | 2 +-
 src/util/virscsi.h   | 2 +-
 src/util/virscsivhost.h  | 2 +-
 src/util/virsocketaddr.h | 2 +-
 src/util/virstoragefile.h| 2 +-
 src/util/virsystemd.h| 2 +-
 src/util/virtypedparam.h | 2 +-
 src/util/viruri.h| 2 +-
 src/util/virusb.h| 2 +-
 src/util/virxml.h| 4 ++--
 tests/qemumonitortestutils.h | 2 +-
 tools/virsh-util.h   | 2 +-
 47 files changed, 57 insertions(+), 57 deletions(-)

diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index 3a92194602..b5c322fd90 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -236,4 +236,4 @@ int virDomainCapsDeviceDefValidate(virDomainCapsPtr const 
caps,
 void
 virSEVCapabilitiesFree(virSEVCapability *capabilities);
 
-VIR_DEFINE_AUTOPTR_FUNC(virSEVCapability, virSEVCapabilitiesFree);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSEVCapability, virSEVCapabilitiesFree);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e2edca149a..edac6250e4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2913,7 +2913,7 @@ bool virDomainDefHasDeviceAddress(virDomainDefPtr def,
 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
 
 void virDomainDefFree(virDomainDefPtr vm);
-VIR_DEFINE_AUTOPTR_FUNC(virDomainDef, virDomainDefFree);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainDef, virDomainDefFree);
 
 virDomainChrSourceDefPtr
 virDomainChrSourceDefNew(virDomainXMLOptionPtr xmlopt);
diff --git a/src/conf/secret_conf.h b/src/conf/secret_conf.h
index 7cfcfc8a60..ac94751ef3 100644
--- a/src/conf/secret_conf.h
+++ b/src/conf/secret_conf.h
@@ -35,7 +35,7 @@ struct _virSecretDef {
 };
 
 void virSecretDefFree(virSecretDefPtr def);
-VIR_DEFINE_AUTOPTR_FUNC(virSecretDef, virSecretDefFree);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virSecretDef, virSecretDefFree);
 
 virSecretDefPtr virSecretDefParseString(const char *xml);
 virSecretDefPtr virSecretDefParseFile(const char *filename);
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 1f62803a9d..b172e82ccb 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -478,6 +478,6 @@ VIR_ENUM_DECL(virStoragePartedFs);
  VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_AUTOSTART  | \
  VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_POOL_TYPE)
 
-VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolSource, virStoragePoolSourceFree);
-VIR_DEFINE_AUTOPTR_FUNC(virStoragePoolDef, virStoragePoolDefFree);
-VIR_DEFINE_AUTOPTR_FUNC(virStorageVolDef, virStorageVolDefFree);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePoolSource, virStoragePoolSourceFree);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePoolDef, virStoragePoolDefFree);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageVolDef, virStorageVolDefFree);
diff --git a/src/conf/virnetworkportdef.h b/src/conf/virnetworkportdef.h
index 796e269fe0..f5ba337fc9 100644
--- a/src/conf/virnetworkportdef.h
+++ b/src/conf/virnetworkportdef.h
@@ -82,7 +82,7 @@ struct _virNetworkPortDef {
 
 void
 virNetworkPortDefFree(virNetworkPortDefPtr port);
-VIR_DEFINE_AUTOPTR_FUNC(virNetworkPortDef, virNetworkPortDefFree);
+G_DEFINE_AUTOPTR_CLEANUP

[libvirt] [PATCH 6/9] Define G_DEFINE_AUTOPTR_CLEANUP_FUNC for virDomainCheckpointDef

2019-10-15 Thread Ján Tomko
Allow g_autoptr to be used instead of VIR_AUTOUNREF.

Signed-off-by: Ján Tomko 
---
 src/conf/checkpoint_conf.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/conf/checkpoint_conf.h b/src/conf/checkpoint_conf.h
index 2be041ff56..982096abed 100644
--- a/src/conf/checkpoint_conf.h
+++ b/src/conf/checkpoint_conf.h
@@ -57,6 +57,7 @@ struct _virDomainCheckpointDef {
 virDomainCheckpointDiskDef *disks;
 };
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainCheckpointDef, virObjectUnref);
 
 typedef enum {
 VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE = 1 << 0,
-- 
2.19.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 9/9] Remove virautoclean.h

2019-10-15 Thread Ján Tomko
Now that we no longer use any of the macros from this file, remove it.

This also removes a typo.

Signed-off-by: Ján Tomko 
---
 src/conf/domain_capabilities.h   |  1 -
 src/conf/storage_conf.h  |  1 -
 src/qemu/qemu_firmware.h |  1 -
 src/qemu/qemu_migration_params.h |  1 -
 src/qemu/qemu_vhost_user.h   |  1 -
 src/util/Makefile.inc.am |  1 -
 src/util/virauthconfig.h |  1 -
 src/util/virautoclean.h  | 89 
 src/util/virbitmap.h |  1 -
 src/util/virbuffer.h |  1 -
 src/util/vircommand.h|  1 -
 src/util/virconf.h   |  1 -
 src/util/virerror.h  |  1 -
 src/util/virfile.h   |  1 -
 src/util/virfirewall.h   |  1 -
 src/util/virhash.h   |  2 -
 src/util/virjson.h   |  1 -
 src/util/virmacaddr.h|  1 -
 src/util/virmdev.h   |  1 -
 src/util/virnetdev.h |  1 -
 src/util/virnetdevip.h   |  1 -
 src/util/virnetdevvlan.h |  1 -
 src/util/virnetlink.h|  1 -
 src/util/virpci.h|  1 -
 src/util/virperf.h   |  1 -
 src/util/virscsi.h   |  1 -
 src/util/virscsivhost.h  |  1 -
 src/util/virsocketaddr.h |  1 -
 src/util/virstoragefile.h|  1 -
 src/util/virsystemd.h|  1 -
 src/util/virtypedparam.h |  1 -
 src/util/viruri.h|  1 -
 src/util/virusb.h|  1 -
 src/util/virxml.h|  1 -
 tests/qemumonitortestutils.h |  1 -
 35 files changed, 124 deletions(-)
 delete mode 100644 src/util/virautoclean.h

diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index b5c322fd90..a31458c653 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -22,7 +22,6 @@
 
 #include "internal.h"
 #include "domain_conf.h"
-#include "virautoclean.h"
 #include "virenum.h"
 
 typedef const char * (*virDomainCapsValToStr)(int value);
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index b172e82ccb..d2600efff0 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -29,7 +29,6 @@
 #include "device_conf.h"
 #include "object_event.h"
 #include "storage_adapter_conf.h"
-#include "virautoclean.h"
 #include "virenum.h"
 #include "virxml.h"
 
diff --git a/src/qemu/qemu_firmware.h b/src/qemu/qemu_firmware.h
index 10b8eb822b..4be65bc664 100644
--- a/src/qemu/qemu_firmware.h
+++ b/src/qemu/qemu_firmware.h
@@ -22,7 +22,6 @@
 
 #include "domain_conf.h"
 #include "qemu_conf.h"
-#include "virautoclean.h"
 #include "virarch.h"
 #include "virfirmware.h"
 
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index e8380e6fb1..9aea24725f 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -27,7 +27,6 @@
 #include "virxml.h"
 #include "qemu_monitor.h"
 #include "qemu_conf.h"
-#include "virautoclean.h"
 #include "virenum.h"
 
 typedef enum {
diff --git a/src/qemu/qemu_vhost_user.h b/src/qemu/qemu_vhost_user.h
index 6bb5f5807c..369ba00caa 100644
--- a/src/qemu/qemu_vhost_user.h
+++ b/src/qemu/qemu_vhost_user.h
@@ -22,7 +22,6 @@
 
 #include "domain_conf.h"
 #include "qemu_conf.h"
-#include "virautoclean.h"
 #include "virarch.h"
 
 typedef struct _qemuVhostUser qemuVhostUser;
diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
index 9747816fac..705b93c93c 100644
--- a/src/util/Makefile.inc.am
+++ b/src/util/Makefile.inc.am
@@ -17,7 +17,6 @@ UTIL_SOURCES = \
util/virauth.h \
util/virauthconfig.c \
util/virauthconfig.h \
-   util/virautoclean.h \
util/virbitmap.c \
util/virbitmap.h \
util/virbuffer.c \
diff --git a/src/util/virauthconfig.h b/src/util/virauthconfig.h
index 44bef7e2be..de28b1ff28 100644
--- a/src/util/virauthconfig.h
+++ b/src/util/virauthconfig.h
@@ -21,7 +21,6 @@
 #pragma once
 
 #include "internal.h"
-#include "virautoclean.h"
 
 typedef struct _virAuthConfig virAuthConfig;
 typedef virAuthConfig *virAuthConfigPtr;
diff --git a/src/util/virautoclean.h b/src/util/virautoclean.h
deleted file mode 100644
index 71312a2782..00
--- a/src/util/virautoclean.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * virautoclean.h: automatic scope-based memory clearing helper macros for
- * use in header files
- *
- * 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 G

[libvirt] [PATCH 7/9] Use g_autoptr instead of VIR_AUTOUNREF

2019-10-15 Thread Ján Tomko
Now that all the types using VIR_AUTOUNREF have a cleanup func defined
to virObjectUnref, use g_autoptr instead of VIR_AUTOUNREF.

Signed-off-by: Ján Tomko 
---
 src/conf/checkpoint_conf.c  |  2 +-
 src/conf/domain_conf.c  | 24 
 src/esx/esx_driver.c|  2 +-
 src/libxl/libxl_driver.c|  2 +-
 src/qemu/qemu_blockjob.c| 14 +++---
 src/qemu/qemu_checkpoint.c  | 10 +-
 src/qemu/qemu_command.c |  6 +++---
 src/qemu/qemu_conf.c| 10 +-
 src/qemu/qemu_domain.c  | 14 +++---
 src/qemu/qemu_driver.c  | 24 
 src/qemu/qemu_firmware.c|  2 +-
 src/qemu/qemu_hotplug.c | 24 
 src/qemu/qemu_migration.c   |  4 ++--
 src/qemu/qemu_process.c |  4 ++--
 src/qemu/qemu_slirp.c   |  4 ++--
 src/qemu/qemu_vhost_user_gpu.c  |  6 +++---
 src/storage/storage_backend_gluster.c   |  2 +-
 src/storage/storage_util.c  |  4 ++--
 src/test/test_driver.c  |  4 ++--
 src/util/virhostdev.c   | 18 +-
 src/util/virstoragefile.c   | 20 ++--
 src/vbox/vbox_common.c  |  4 ++--
 src/vz/vz_driver.c  |  2 +-
 tests/qemublocktest.c   |  6 +++---
 tests/qemudomaincheckpointxml2xmltest.c |  2 +-
 tests/qemudomainsnapshotxml2xmltest.c   |  2 +-
 tests/qemusecuritytest.c|  4 ++--
 tests/storagepoolcapstest.c |  6 +++---
 tests/virstoragetest.c  |  8 
 29 files changed, 117 insertions(+), 117 deletions(-)

diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c
index 376a627ee4..e7b204a4d2 100644
--- a/src/conf/checkpoint_conf.c
+++ b/src/conf/checkpoint_conf.c
@@ -134,7 +134,7 @@ virDomainCheckpointDefParse(xmlXPathContextPtr ctxt,
 int n;
 char *tmp;
 g_autofree xmlNodePtr *nodes = NULL;
-VIR_AUTOUNREF(virDomainCheckpointDefPtr) def = NULL;
+g_autoptr(virDomainCheckpointDef) def = NULL;
 
 if (!(def = virDomainCheckpointDefNew()))
 return NULL;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a0690e23f7..8616f820fc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1785,7 +1785,7 @@ static virDomainVcpuDefPtr
 virDomainVcpuDefNew(virDomainXMLOptionPtr xmlopt)
 {
 virDomainVcpuDefPtr ret = NULL;
-VIR_AUTOUNREF(virObjectPtr) priv = NULL;
+g_autoptr(virObject) priv = NULL;
 
 if (xmlopt && xmlopt->privateData.vcpuNew &&
 !(priv = xmlopt->privateData.vcpuNew()))
@@ -9276,7 +9276,7 @@ virDomainStorageSourceParseBase(const char *type,
 const char *format,
 const char *index)
 {
-VIR_AUTOUNREF(virStorageSourcePtr) src = NULL;
+g_autoptr(virStorageSource) src = NULL;
 virStorageSourcePtr ret = NULL;
 
 if (!(src = virStorageSourceNew()))
@@ -9402,7 +9402,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt,
 {
 VIR_XPATH_NODE_AUTORESTORE(ctxt);
 xmlNodePtr source;
-VIR_AUTOUNREF(virStorageSourcePtr) backingStore = NULL;
+g_autoptr(virStorageSource) backingStore = NULL;
 g_autofree char *type = NULL;
 g_autofree char *format = NULL;
 g_autofree char *idx = NULL;
@@ -19526,7 +19526,7 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
 int ret = -1;
 g_autoptr(virBitmap) vcpus = NULL;
 g_autofree xmlNodePtr *nodes = NULL;
-VIR_AUTOUNREF(virResctrlAllocPtr) alloc = NULL;
+g_autoptr(virResctrlAlloc) alloc = NULL;
 
 ctxt->node = node;
 
@@ -19724,7 +19724,7 @@ virDomainMemorytuneDefParse(virDomainDefPtr def,
 virDomainResctrlDefPtr resctrl = NULL;
 g_autoptr(virBitmap) vcpus = NULL;
 g_autofree xmlNodePtr *nodes = NULL;
-VIR_AUTOUNREF(virResctrlAllocPtr) alloc = NULL;
+g_autoptr(virResctrlAlloc) alloc = NULL;
 ssize_t i = 0;
 int n;
 
@@ -30936,9 +30936,9 @@ virDomainNetCreatePort(virConnectPtr conn,
unsigned int flags)
 {
 virErrorPtr save_err;
-VIR_AUTOUNREF(virNetworkPtr) net = NULL;
+g_autoptr(virNetwork) net = NULL;
 g_autoptr(virNetworkPortDef) portdef = NULL;
-VIR_AUTOUNREF(virNetworkPortPtr) port = NULL;
+g_autoptr(virNetworkPort) port = NULL;
 g_autofree char *portxml = NULL;
 
 if (!(net = virNetworkLookupByName(conn, iface->data.network.name)))
@@ -31156,8 +31156,8 @@ virDomainNetResolveActualType(virDomainNetDefPtr iface)
 virNetworkDefPtr def = NULL;
 int ret = -1;
 g_autofree char *xml = NULL;
-VIR_AUTOUNREF(virConnectPtr) conn = NULL;
-VIR_AUTOUNREF(virNetworkPtr) net = NULL;
+g_autoptr(virConnect) conn = NULL;
+g_autoptr(virNetwork) net = NULL;
 
 if (iface->type != VIR_D

[libvirt] [PATCH 0/9] More GLib macro usage (glib chronicles)

2019-10-15 Thread Ján Tomko
Ján Tomko (9):
  util: xml: use g_auto directly for VIR_XPATH_NODE_AUTORESTORE
  virbuffer: use g_auto directly for virBuffer
  Use g_autofree instead of VIR_AUTOFREE
  Use G_DEFINE_AUTOPTR_CLEANUP_FUNC instead of VIR_DEFINE_AUTOPTR_FUNC
  Use g_autoptr instead of VIR_AUTOPTR
  Define G_DEFINE_AUTOPTR_CLEANUP_FUNC for virDomainCheckpointDef
  Use g_autoptr instead of VIR_AUTOUNREF
  Delete virObjectAutoUnref
  Remove virautoclean.h

 src/bhyve/bhyve_conf.c |   2 +-
 src/conf/checkpoint_conf.c |  10 +-
 src/conf/checkpoint_conf.h |   1 +
 src/conf/domain_capabilities.h |   3 +-
 src/conf/domain_conf.c | 858 ++---
 src/conf/domain_conf.h |   2 +-
 src/conf/interface_conf.c  |   2 +-
 src/conf/network_conf.c|   6 +-
 src/conf/node_device_conf.c|   2 +-
 src/conf/nwfilter_conf.c   |   2 +-
 src/conf/secret_conf.c |   8 +-
 src/conf/secret_conf.h |   2 +-
 src/conf/snapshot_conf.c   |   4 +-
 src/conf/storage_conf.c|  60 +-
 src/conf/storage_conf.h|   7 +-
 src/conf/virnetworkobj.c   |  10 +-
 src/conf/virnetworkportdef.c   |  18 +-
 src/conf/virnetworkportdef.h   |   2 +-
 src/conf/virstorageobj.c   |   4 +-
 src/cpu/cpu_x86.c  |  12 +-
 src/driver.c   |   4 +-
 src/esx/esx_driver.c   |   2 +-
 src/esx/esx_storage_backend_vmfs.c |   4 +-
 src/interface/interface_backend_netcf.c|   2 +-
 src/interface/interface_backend_udev.c |   2 +-
 src/libvirt-admin.c|   4 +-
 src/libvirt.c  |   2 +-
 src/libvirt_private.syms   |   1 -
 src/libxl/libxl_conf.c |   2 +-
 src/libxl/libxl_driver.c   |   6 +-
 src/libxl/xen_common.c |  24 +-
 src/libxl/xen_xl.c |  14 +-
 src/libxl/xen_xm.c |  10 +-
 src/locking/lock_daemon.c  |   2 +-
 src/locking/lock_daemon_config.c   |   2 +-
 src/locking/lock_driver_lockd.c|   2 +-
 src/locking/lock_driver_sanlock.c  |   2 +-
 src/logging/log_daemon.c   |   2 +-
 src/logging/log_daemon_config.c|   2 +-
 src/lxc/lxc_conf.c |   2 +-
 src/lxc/lxc_native.c   |  18 +-
 src/network/bridge_driver.c|  12 +-
 src/node_device/node_device_hal.c  |   2 +-
 src/node_device/node_device_udev.c |   2 +-
 src/phyp/phyp_driver.c |   4 +-
 src/qemu/qemu_agent.c  |  16 +-
 src/qemu/qemu_block.c  | 126 +--
 src/qemu/qemu_block.h  |   4 +-
 src/qemu/qemu_blockjob.c   |  26 +-
 src/qemu/qemu_capabilities.c   |  12 +-
 src/qemu/qemu_checkpoint.c |  22 +-
 src/qemu/qemu_command.c| 336 
 src/qemu/qemu_conf.c   |  54 +-
 src/qemu/qemu_dbus.c   |   2 +-
 src/qemu/qemu_dbus.h   |   2 +-
 src/qemu/qemu_domain.c | 100 +--
 src/qemu/qemu_domain_address.c |   6 +-
 src/qemu/qemu_driver.c |  58 +-
 src/qemu/qemu_extdevice.c  |   4 +-
 src/qemu/qemu_firmware.c   |  46 +-
 src/qemu/qemu_firmware.h   |   3 +-
 src/qemu/qemu_hotplug.c| 154 ++--
 src/qemu/qemu_interface.c  |   2 +-
 src/qemu/qemu_interop_config.c |  18 +-
 src/qemu/qemu_migration.c  |   8 +-
 src/qemu/qemu_migration_params.h   |   3 +-
 src/qemu/qemu_monitor.c|   4 +-
 src/qemu/qemu_monitor.h|   2 +-
 src/qemu/qemu_monitor_json.c   |  72 +-
 src/qemu/qemu_process.c|  10 +-
 src/qemu/qemu_qapi.c   |   4 +-
 src/qemu/qemu_slirp.c  |  40 +-
 src/qemu/qemu_slirp.h  |   2 +-
 src/qemu/qemu_tpm.c|  10 +-
 src/qemu/qemu_vhost_user.c |  18 +-
 src/qemu/qemu_vhost_user.h |   3 +-
 src/qemu/qemu_vhost_user_gpu.c |  22 +-
 src/remote/remote_daemon.c |   2 +-
 src/remote/remote_daemon_config.c  |   4 +-
 src/remote/remote_daemon_dispatch.c|   8 +-
 src/remote/remote_driver.c |  42 +-
 src/secret/secret_driver.c |   4 +-
 src/security/security_selinux.c|   2 +-
 src/security/security_util.c   |  36 +-
 src/security/virt-aa-helper.c  |   2 +-
 src/storage/storage_backend.c

[libvirt] [PATCH v2 02/31] domcapstest: Add test case for QEMU 4.2.0 on s390x

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- new patch

 .../domaincapsschemadata/qemu_4.2.0.s390x.xml | 202 ++
 tests/domaincapstest.c|   4 +
 2 files changed, 206 insertions(+)
 create mode 100644 tests/domaincapsschemadata/qemu_4.2.0.s390x.xml

diff --git a/tests/domaincapsschemadata/qemu_4.2.0.s390x.xml 
b/tests/domaincapsschemadata/qemu_4.2.0.s390x.xml
new file mode 100644
index 00..1ca3b78251
--- /dev/null
+++ b/tests/domaincapsschemadata/qemu_4.2.0.s390x.xml
@@ -0,0 +1,202 @@
+
+  /usr/bin/qemu-system-s390x
+  kvm
+  s390-ccw-virtio-4.2
+  s390x
+  
+  
+  
+
+
+  /usr/share/AAVMF/AAVMF_CODE.fd
+  /usr/share/AAVMF/AAVMF32_CODE.fd
+  /usr/share/OVMF/OVMF_CODE.fd
+  
+rom
+pflash
+  
+  
+yes
+no
+  
+  
+no
+  
+
+  
+  
+
+
+  z13.2-base
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+
+
+  z800-base
+  z890.2-base
+  z9EC.2
+  z13.2
+  z990.5-base
+  z9BC-base
+  z890.2
+  z890
+  z9BC
+  z13
+  z196
+  z13s
+  z990.3
+  z13s-base
+  z9EC
+  gen15a
+  z14ZR1-base
+  z14.2-base
+  z900.3-base
+  z13.2-base
+  z196.2-base
+  zBC12-base
+  z9BC.2-base
+  z900.2-base
+  z9EC.3
+  zEC12
+  z900
+  z114-base
+  zEC12-base
+  z10EC.2
+  z10EC-base
+  z900.3
+  z14ZR1
+  z10BC
+  z10BC.2-base
+  z9BC.2
+  z990.2
+  z990
+  z14
+  gen15b-base
+  z990.4
+  max
+  z10EC.2-base
+  gen15a-base
+  z800
+  zEC12.2
+  z10EC
+  z990.2-base
+  z900-base
+  z10BC.2
+  z9EC-base
+  z9EC.3-base
+  z114
+  z890.3
+  z196-base
+  z9EC.2-base
+  z196.2
+  z990-base
+  z14.2
+  z900.2
+  z890-base
+  z10EC.3
+  z14-base
+  z990.4-base
+  z10EC.3-base
+  z10BC-base
+  z13-base
+  z990.3-base
+  zEC12.2-base
+  zBC12
+  z890.3-base
+  z990.5
+  gen15b
+  qemu
+
+  
+  
+
+  
+disk
+cdrom
+floppy
+lun
+  
+  
+fdc
+scsi
+virtio
+  
+  
+virtio
+virtio-transitional
+virtio-non-transitional
+  
+
+
+  
+sdl
+vnc
+  
+
+
+  
+virtio
+  
+
+
+  
+subsystem
+  
+  
+default
+mandatory
+requisite
+optional
+  
+  
+usb
+pci
+scsi
+  
+  
+  
+default
+vfio
+  
+
+
+  
+virtio
+virtio-transitional
+virtio-non-transitional
+  
+  
+random
+egd
+  
+
+  
+  
+
+
+
+
+  
+
diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index db14114cba..667311c2bd 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -468,6 +468,10 @@ mymain(void)
  "/usr/bin/qemu-system-aarch64", NULL,
  "aarch64", VIR_DOMAIN_VIRT_KVM);
 
+DO_TEST_QEMU("4.2.0", "caps_4.2.0",
+ "/usr/bin/qemu-system-s390x", NULL,
+ "s390x", VIR_DOMAIN_VIRT_KVM);
+
 virObjectUnref(cfg);
 
 virFileWrapperClearPrefixes();
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 05/31] qemu: Copy CPU models in virQEMUCapsGetCPUDefinitions

2019-10-15 Thread Jiri Denemark
Rather than returning a direct pointer the list stored in qemuCaps the
function now creates a new copy of the CPU models list.

The main purpose of this seemingly useless change is to update callers
to free the result returned by virQEMUCapsGetCPUDefinitions because the
internals of this function will change significantly in the following
patches.

Signed-off-by: Jiri Denemark 
Reviewed-by: Ján Tomko 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c | 23 ++-
 src/qemu/qemu_driver.c   |  2 +-
 src/qemu/qemu_process.c  |  7 +--
 tests/cputest.c  |  1 -
 4 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 14939fc91d..a40bf99aa3 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1891,10 +1891,17 @@ virDomainCapsCPUModelsPtr
 virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
  virDomainVirtType type)
 {
+virDomainCapsCPUModelsPtr cpuModels;
+
 if (type == VIR_DOMAIN_VIRT_KVM)
-return qemuCaps->kvmCPUModels;
+cpuModels = qemuCaps->kvmCPUModels;
 else
-return qemuCaps->tcgCPUModels;
+cpuModels = qemuCaps->tcgCPUModels;
+
+if (!cpuModels)
+return NULL;
+
+return virDomainCapsCPUModelsCopy(cpuModels);
 }
 
 
@@ -3125,6 +3132,7 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
virCPUDefPtr cpu,
bool migratable)
 {
+VIR_AUTOUNREF(virDomainCapsCPUModelsPtr) cpuModels = NULL;
 virCPUDataPtr data = NULL;
 int ret = -1;
 
@@ -3134,7 +3142,9 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
 if (!(data = virQEMUCapsGetCPUModelX86Data(qemuCaps, model, migratable)))
 goto cleanup;
 
-if (cpuDecode(cpu, data, virQEMUCapsGetCPUDefinitions(qemuCaps, type)) < 0)
+cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type);
+
+if (cpuDecode(cpu, data, cpuModels) < 0)
 goto cleanup;
 
 ret = 0;
@@ -3217,10 +3227,13 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
 if ((rc = virQEMUCapsInitCPUModel(qemuCaps, type, cpu, false)) < 0) {
 goto error;
 } else if (rc == 1) {
+VIR_AUTOUNREF(virDomainCapsCPUModelsPtr) cpuModels = NULL;
+
 VIR_DEBUG("No host CPU model info from QEMU; probing host CPU 
directly");
 
-hostCPU = virQEMUCapsProbeHostCPU(hostArch,
-  
virQEMUCapsGetCPUDefinitions(qemuCaps, type));
+cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type);
+hostCPU = virQEMUCapsProbeHostCPU(hostArch, cpuModels);
+
 if (!hostCPU ||
 virCPUDefCopyModelFilter(cpu, hostCPU, true,
  virQEMUCapsCPUFilterFeatures,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6ce6348593..15c69667a5 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13913,7 +13913,7 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn,
 virQEMUCapsPtr qemuCaps = NULL;
 virArch arch;
 virDomainVirtType virttype;
-virDomainCapsCPUModelsPtr cpuModels;
+VIR_AUTOUNREF(virDomainCapsCPUModelsPtr) cpuModels = NULL;
 bool migratable;
 virCPUDefPtr cpu = NULL;
 char *cpustr = NULL;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 9c50c4a1d8..58192612b0 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6122,6 +6122,8 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
 
 /* nothing to update for host-passthrough */
 if (def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH) {
+VIR_AUTOUNREF(virDomainCapsCPUModelsPtr) cpuModels = NULL;
+
 if (def->cpu->check == VIR_CPU_CHECK_PARTIAL &&
 virCPUCompare(caps->host.arch,
   virQEMUCapsGetHostModel(qemuCaps, def->virtType,
@@ -6134,8 +6136,9 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
  
VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE)) < 0)
 return -1;
 
-if (virCPUTranslate(def->os.arch, def->cpu,
-virQEMUCapsGetCPUDefinitions(qemuCaps, 
def->virtType)) < 0)
+cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType);
+
+if (virCPUTranslate(def->os.arch, def->cpu, cpuModels) < 0)
 return -1;
 
 def->cpu->fallback = VIR_CPU_FALLBACK_FORBID;
diff --git a/tests/cputest.c b/tests/cputest.c
index 7f47e3b601..3aa8fd7bf3 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -551,7 +551,6 @@ cpuTestGetCPUModels(const struct data *data,
 return -1;
 
 *models = virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM);
-virObjectRef(*models);
 
 virObjectUnref(qemuCaps);
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2 03/31] conf: Use VIR_AUTO* in virDomainCapsCPUModelsAdd

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
Reviewed-by: Ján Tomko 
---

Notes:
Version 2:
- no change

 src/conf/domain_capabilities.c | 15 +--
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index b0fdd15d6c..3224ec3f52 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -246,25 +246,20 @@ virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr 
cpuModels,
   virDomainCapsCPUUsable usable,
   char **blockers)
 {
-char *nameCopy = NULL;
-char **blockersCopy = NULL;
+VIR_AUTOFREE(char *) nameCopy = NULL;
+VIR_AUTOSTRINGLIST blockersCopy = NULL;
 
 if (VIR_STRNDUP(nameCopy, name, nameLen) < 0)
-goto error;
+return -1;
 
 if (virStringListCopy(&blockersCopy, (const char **)blockers) < 0)
-goto error;
+return -1;
 
 if (virDomainCapsCPUModelsAddSteal(cpuModels, &nameCopy,
usable, &blockersCopy) < 0)
-goto error;
+return -1;
 
 return 0;
-
- error:
-VIR_FREE(nameCopy);
-virStringListFree(blockersCopy);
-return -1;
 }
 
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2 01/31] tests: Add capabilities for QEMU 4.2.0 on s390x

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- new patch

 .../caps_4.2.0.s390x.replies  | 22414 
 .../qemucapabilitiesdata/caps_4.2.0.s390x.xml |  3345 +++
 2 files changed, 25759 insertions(+)
 create mode 100644 tests/qemucapabilitiesdata/caps_4.2.0.s390x.replies
 create mode 100644 tests/qemucapabilitiesdata/caps_4.2.0.s390x.xml

diff --git a/tests/qemucapabilitiesdata/caps_4.2.0.s390x.replies 
b/tests/qemucapabilitiesdata/caps_4.2.0.s390x.replies
new file mode 100644
index 00..68d70de415
--- /dev/null
+++ b/tests/qemucapabilitiesdata/caps_4.2.0.s390x.replies
@@ -0,0 +1,22414 @@
+{
+  "execute": "qmp_capabilities",
+  "id": "libvirt-1"
+}
+
+{
+  "return": {
+  },
+  "id": "libvirt-1"
+}
+
+{
+  "execute": "query-version",
+  "id": "libvirt-2"
+}
+
+{
+  "return": {
+"qemu": {
+  "micro": 50,
+  "minor": 1,
+  "major": 4
+},
+"package": "v4.1.0-1484-g3779d18011"
+  },
+  "id": "libvirt-2"
+}
...
diff --git a/tests/qemucapabilitiesdata/caps_4.2.0.s390x.xml 
b/tests/qemucapabilitiesdata/caps_4.2.0.s390x.xml
new file mode 100644
index 00..1c9a383816
--- /dev/null
+++ b/tests/qemucapabilitiesdata/caps_4.2.0.s390x.xml
@@ -0,0 +1,3345 @@
+
+  0
+  0
+  0
+  
...
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 12/31] build: Export virStringListCopy internal API

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/libvirt_private.syms | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7d62df8086..1af18b880b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -3077,6 +3077,7 @@ virStringIsEmpty;
 virStringIsPrintable;
 virStringListAdd;
 virStringListAutoFree;
+virStringListCopy;
 virStringListFree;
 virStringListFreeCount;
 virStringListGetFirstWithPrefix;
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 13/31] qemu: Add qemuMonitorCPUDefsCopy

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_monitor.c | 33 +
 src/qemu/qemu_monitor.h |  2 ++
 2 files changed, 35 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 87a9d06d45..8d86112f30 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3582,6 +3582,39 @@ qemuMonitorCPUDefsNew(size_t count)
 }
 
 
+int
+qemuMonitorCPUDefsCopy(qemuMonitorCPUDefsPtr *dst,
+   qemuMonitorCPUDefsPtr src)
+{
+VIR_AUTOPTR(qemuMonitorCPUDefs) defs = NULL;
+size_t i;
+
+if (!src) {
+*dst = NULL;
+return 0;
+}
+
+if (!(defs = qemuMonitorCPUDefsNew(src->ncpus)))
+return -1;
+
+defs->ncpus = src->ncpus;
+for (i = 0; i < src->ncpus; i++) {
+qemuMonitorCPUDefInfoPtr cpuDst = defs->cpus + i;
+qemuMonitorCPUDefInfoPtr cpuSrc = src->cpus + i;
+
+cpuDst->usable = cpuSrc->usable;
+
+if (VIR_STRDUP(cpuDst->name, cpuSrc->name) < 0 ||
+virStringListCopy(&cpuDst->blockers,
+  (const char **)cpuSrc->blockers) < 0)
+return -1;
+}
+
+VIR_STEAL_PTR(*dst, defs);
+return 0;
+}
+
+
 int
 qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon,
 qemuMonitorCPUModelExpansionType type,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index aa2a0e392a..4f355c760a 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -,6 +,8 @@ struct _qemuMonitorCPUDefs {
 int qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon,
  qemuMonitorCPUDefsPtr *cpuDefs);
 qemuMonitorCPUDefsPtr qemuMonitorCPUDefsNew(size_t count);
+int qemuMonitorCPUDefsCopy(qemuMonitorCPUDefsPtr *dst,
+   qemuMonitorCPUDefsPtr src);
 void qemuMonitorCPUDefsFree(qemuMonitorCPUDefsPtr defs);
 VIR_DEFINE_AUTOPTR_FUNC(qemuMonitorCPUDefs, qemuMonitorCPUDefsFree);
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 09/31] qemu: Change return type of virQEMUCapsFetchCPUDefinitions

2019-10-15 Thread Jiri Denemark
The function would return a valid virDomainCapsCPUModelsPtr with empty
CPU models list if query-cpu-definitions exists in QEMU, but returns
GenericError meaning it's not in fact implemented. This behaviour is a
bit strange especially after such virDomainCapsCPUModels structure is
stored in capabilities XML and parsed back, which will result in NULL
virDomainCapsCPUModelsPtr rather than a structure containing nothing.

Let's just keep virDomainCapsCPUModelsPtr NULL if the QMP command is not
implemented and change the return value to int so that callers can
easily check for failure or success.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- new patch

 src/qemu/qemu_capabilities.c | 34 +-
 src/qemu/qemu_capabilities.h |  5 +++--
 src/qemu/qemu_process.c  | 17 ++---
 3 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index b608eb1a43..6fa5e06edb 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2452,17 +2452,26 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCapsPtr qemuCaps,
 }
 
 
-virDomainCapsCPUModelsPtr
+int
 virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
-   virArch arch)
+   virArch arch,
+   virDomainCapsCPUModelsPtr *cpuModels)
 {
 virDomainCapsCPUModelsPtr models = NULL;
 qemuMonitorCPUDefInfoPtr *cpus = NULL;
 int ncpus = 0;
 size_t i;
+int ret = -1;
+
+*cpuModels = NULL;
 
 if ((ncpus = qemuMonitorGetCPUDefinitions(mon, &cpus)) < 0)
-return NULL;
+return -1;
+
+if (ncpus == 0) {
+ret = 0;
+goto cleanup;
+}
 
 /* QEMU 2.11 for Power renamed all CPU models to lower case, we need to
  * translate them back to libvirt's upper case model names. */
@@ -2471,7 +2480,7 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
 char **name;
 
 if (virCPUGetModels(arch, &libvirtModels) < 0)
-goto error;
+goto cleanup;
 
 for (name = libvirtModels; name && *name; name++) {
 for (i = 0; i < ncpus; i++) {
@@ -2480,13 +2489,13 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
 
 VIR_FREE(cpus[i]->name);
 if (VIR_STRDUP(cpus[i]->name, *name) < 0)
-goto error;
+goto cleanup;
 }
 }
 }
 
 if (!(models = virDomainCapsCPUModelsNew(ncpus)))
-goto error;
+goto cleanup;
 
 for (i = 0; i < ncpus; i++) {
 virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
@@ -2498,19 +2507,18 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
 
 if (virDomainCapsCPUModelsAddSteal(models, &cpus[i]->name, usable,
&cpus[i]->blockers) < 0)
-goto error;
+goto cleanup;
 }
 
+VIR_STEAL_PTR(*cpuModels, models);
+ret = 0;
+
  cleanup:
 for (i = 0; i < ncpus; i++)
 qemuMonitorCPUDefInfoFree(cpus[i]);
 VIR_FREE(cpus);
-return models;
-
- error:
 virObjectUnref(models);
-models = NULL;
-goto cleanup;
+return ret;
 }
 
 
@@ -2524,7 +2532,7 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
 if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_DEFINITIONS))
 return 0;
 
-if (!(models = virQEMUCapsFetchCPUDefinitions(mon, qemuCaps->arch)))
+if (virQEMUCapsFetchCPUDefinitions(mon, qemuCaps->arch, &models) < 0)
 return -1;
 
 if (tcg || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 67dccc522e..ba3fe3d2b6 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -573,8 +573,9 @@ virDomainCapsCPUModelsPtr 
virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
virDomainVirtType type,
const char 
**modelWhitelist,
const char 
**modelBlacklist);
-virDomainCapsCPUModelsPtr virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
- virArch arch);
+int virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
+   virArch arch,
+   virDomainCapsCPUModelsPtr *cpuModels);
 
 typedef enum {
 /* Host CPU definition reported in domain capabilities. */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f37acab9e4..93fe994f8e 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4353,27 +4353,30 @@ qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driver,
 }
 
 
-static virDomainCapsCPUModelsPtr
+static int
 qemuProcessFetchCPUDefinitions(virQEMUDriverPtr driver,
 

[libvirt] [PATCH v2 16/31] qemu: Rename virQEMUCaps{Get, Fetch}CPUDefinitions

2019-10-15 Thread Jiri Denemark
The functions return virDomainCapsCPUModelsPtr and thus they should be
called *CPUModels for consistency. Functions called *CPUDefinitions will
work on qemuMonitorCPUDefsPtr.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- new patch

 src/qemu/qemu_capabilities.c | 28 ++--
 src/qemu/qemu_capabilities.h | 14 +++---
 src/qemu/qemu_driver.c   |  2 +-
 src/qemu/qemu_process.c  |  4 ++--
 tests/cputest.c  |  2 +-
 5 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 87ac9bacdc..cdc3a2d4b0 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1923,10 +1923,10 @@ virQEMUCapsCPUDefsToModels(qemuMonitorCPUDefsPtr defs,
 
 
 virDomainCapsCPUModelsPtr
-virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
- virDomainVirtType type,
- const char **modelWhitelist,
- const char **modelBlacklist)
+virQEMUCapsGetCPUModels(virQEMUCapsPtr qemuCaps,
+virDomainVirtType type,
+const char **modelWhitelist,
+const char **modelBlacklist)
 {
 virDomainCapsCPUModelsPtr cpuModels;
 
@@ -2488,9 +2488,9 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCapsPtr qemuCaps,
 
 
 int
-virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
-   virArch arch,
-   virDomainCapsCPUModelsPtr *cpuModels)
+virQEMUCapsFetchCPUModels(qemuMonitorPtr mon,
+  virArch arch,
+  virDomainCapsCPUModelsPtr *cpuModels)
 {
 VIR_AUTOPTR(qemuMonitorCPUDefs) defs = NULL;
 size_t i;
@@ -2541,7 +2541,7 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
 if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_DEFINITIONS))
 return 0;
 
-if (virQEMUCapsFetchCPUDefinitions(mon, qemuCaps->arch, &models) < 0)
+if (virQEMUCapsFetchCPUModels(mon, qemuCaps->arch, &models) < 0)
 return -1;
 
 if (tcg || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM))
@@ -3164,7 +3164,7 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
 if (!(data = virQEMUCapsGetCPUModelX86Data(qemuCaps, model, migratable)))
 goto cleanup;
 
-cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type, NULL, NULL);
+cpuModels = virQEMUCapsGetCPUModels(qemuCaps, type, NULL, NULL);
 
 if (cpuDecode(cpu, data, cpuModels) < 0)
 goto cleanup;
@@ -3253,7 +3253,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
 
 VIR_DEBUG("No host CPU model info from QEMU; probing host CPU 
directly");
 
-cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type, NULL, NULL);
+cpuModels = virQEMUCapsGetCPUModels(qemuCaps, type, NULL, NULL);
 hostCPU = virQEMUCapsProbeHostCPU(hostArch, cpuModels);
 
 if (!hostCPU ||
@@ -5308,10 +5308,10 @@ virQEMUCapsFillDomainCPUCaps(virCapsPtr caps,
 VIR_AUTOSTRINGLIST models = NULL;
 
 if (virCPUGetModels(domCaps->arch, &models) >= 0) {
-domCaps->cpu.custom = virQEMUCapsGetCPUDefinitions(qemuCaps,
-   
domCaps->virttype,
-   (const char 
**)models,
-   blacklist);
+domCaps->cpu.custom = virQEMUCapsGetCPUModels(qemuCaps,
+  domCaps->virttype,
+  (const char 
**)models,
+  blacklist);
 } else {
 domCaps->cpu.custom = NULL;
 }
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index ba3fe3d2b6..923706c3bf 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -569,13 +569,13 @@ int virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
  const char **name,
  size_t count,
  virDomainCapsCPUUsable usable);
-virDomainCapsCPUModelsPtr virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
-   virDomainVirtType type,
-   const char 
**modelWhitelist,
-   const char 
**modelBlacklist);
-int virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
-   virArch arch,
-   virDomainCapsCPUModelsPtr *cpuModels);
+virDomainCapsCPUModelsPtr virQEMUCapsGetCPUModels(virQEMUCapsPtr qemuCaps,
+  virDomainVirtType type,
+  const cha

[libvirt] [PATCH v2 17/31] qemu: Split virQEMUCapsFetchCPUModels

2019-10-15 Thread Jiri Denemark
Most of the code moved to a new virQEMUCapsFetchCPUDefinitions function
and the existing virQEMUCapsFetchCPUModels just becomes a small wrapper
around virQEMUCapsFetchCPUDefinitions and virQEMUCapsCPUDefsToModels.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- new patch

 src/qemu/qemu_capabilities.c | 29 +++--
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index cdc3a2d4b0..436d65f578 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2487,15 +2487,15 @@ virQEMUCapsProbeQMPMachineProps(virQEMUCapsPtr qemuCaps,
 }
 
 
-int
-virQEMUCapsFetchCPUModels(qemuMonitorPtr mon,
-  virArch arch,
-  virDomainCapsCPUModelsPtr *cpuModels)
+static int
+virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
+   virArch arch,
+   qemuMonitorCPUDefsPtr *cpuDefs)
 {
 VIR_AUTOPTR(qemuMonitorCPUDefs) defs = NULL;
 size_t i;
 
-*cpuModels = NULL;
+*cpuDefs = NULL;
 
 if (qemuMonitorGetCPUDefinitions(mon, &defs) < 0)
 return -1;
@@ -2524,7 +2524,24 @@ virQEMUCapsFetchCPUModels(qemuMonitorPtr mon,
 }
 }
 
-if (!(*cpuModels = virQEMUCapsCPUDefsToModels(defs, NULL, NULL)))
+VIR_STEAL_PTR(*cpuDefs, defs);
+return 0;
+}
+
+
+int
+virQEMUCapsFetchCPUModels(qemuMonitorPtr mon,
+  virArch arch,
+  virDomainCapsCPUModelsPtr *cpuModels)
+{
+VIR_AUTOPTR(qemuMonitorCPUDefs) defs = NULL;
+
+*cpuModels = NULL;
+
+if (virQEMUCapsFetchCPUDefinitions(mon, arch, &defs) < 0)
+return -1;
+
+if (defs && !(*cpuModels = virQEMUCapsCPUDefsToModels(defs, NULL, NULL)))
 return -1;
 
 return 0;
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 18/31] qemu: Switch qemuCaps to use qemuMonitorCPUDefs

2019-10-15 Thread Jiri Denemark
We will need to keep some QEMU-specific data for each CPU model
supported by a QEMU binary. Instead of complicating the generic
virDomainCapsCPUModelsPtr, we can just directly store
qemuMonitorCPUDefsPtr returned by the capabilities probing code.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- adapted to changes made by the new patches

 src/qemu/qemu_capabilities.c | 109 +--
 1 file changed, 53 insertions(+), 56 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 436d65f578..a274cef120 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -607,8 +607,8 @@ struct _virQEMUCaps {
 virArch arch;
 
 virHashTablePtr domCapsCache;
-virDomainCapsCPUModelsPtr kvmCPUModels;
-virDomainCapsCPUModelsPtr tcgCPUModels;
+qemuMonitorCPUDefsPtr kvmCPUModels;
+qemuMonitorCPUDefsPtr tcgCPUModels;
 
 size_t nmachineTypes;
 struct virQEMUCapsMachineType *machineTypes;
@@ -1625,17 +1625,9 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr 
qemuCaps)
 
 ret->arch = qemuCaps->arch;
 
-if (qemuCaps->kvmCPUModels) {
-ret->kvmCPUModels = virDomainCapsCPUModelsCopy(qemuCaps->kvmCPUModels);
-if (!ret->kvmCPUModels)
-goto error;
-}
-
-if (qemuCaps->tcgCPUModels) {
-ret->tcgCPUModels = virDomainCapsCPUModelsCopy(qemuCaps->tcgCPUModels);
-if (!ret->tcgCPUModels)
-goto error;
-}
+if (qemuMonitorCPUDefsCopy(&ret->kvmCPUModels, qemuCaps->kvmCPUModels) < 0 
||
+qemuMonitorCPUDefsCopy(&ret->tcgCPUModels, qemuCaps->tcgCPUModels) < 0)
+goto error;
 
 if (virQEMUCapsHostCPUDataCopy(&ret->kvmCPU, &qemuCaps->kvmCPU) < 0 ||
 virQEMUCapsHostCPUDataCopy(&ret->tcgCPU, &qemuCaps->tcgCPU) < 0)
@@ -1861,25 +1853,36 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
  virDomainCapsCPUUsable usable)
 {
 size_t i;
-virDomainCapsCPUModelsPtr cpus = NULL;
+size_t start;
+qemuMonitorCPUDefsPtr defs = NULL;
 
 if (type == VIR_DOMAIN_VIRT_KVM && qemuCaps->kvmCPUModels)
-cpus = qemuCaps->kvmCPUModels;
+defs = qemuCaps->kvmCPUModels;
 else if (type == VIR_DOMAIN_VIRT_QEMU && qemuCaps->tcgCPUModels)
-cpus = qemuCaps->tcgCPUModels;
+defs = qemuCaps->tcgCPUModels;
+
+if (defs) {
+start = defs->ncpus;
 
-if (!cpus) {
-if (!(cpus = virDomainCapsCPUModelsNew(count)))
+if (VIR_EXPAND_N(defs->cpus, defs->ncpus, count) < 0)
+return -1;
+} else {
+start = 0;
+
+if (!(defs = qemuMonitorCPUDefsNew(count)))
 return -1;
 
 if (type == VIR_DOMAIN_VIRT_KVM)
-qemuCaps->kvmCPUModels = cpus;
+qemuCaps->kvmCPUModels = defs;
 else
-qemuCaps->tcgCPUModels = cpus;
+qemuCaps->tcgCPUModels = defs;
 }
 
 for (i = 0; i < count; i++) {
-if (virDomainCapsCPUModelsAdd(cpus, name[i], usable, NULL) < 0)
+qemuMonitorCPUDefInfoPtr cpu = defs->cpus + start + i;
+
+cpu->usable = usable;
+if (VIR_STRDUP(cpu->name, name[i]) < 0)
 return -1;
 }
 
@@ -1928,20 +1931,17 @@ virQEMUCapsGetCPUModels(virQEMUCapsPtr qemuCaps,
 const char **modelWhitelist,
 const char **modelBlacklist)
 {
-virDomainCapsCPUModelsPtr cpuModels;
+qemuMonitorCPUDefsPtr defs;
 
 if (type == VIR_DOMAIN_VIRT_KVM)
-cpuModels = qemuCaps->kvmCPUModels;
+defs = qemuCaps->kvmCPUModels;
 else
-cpuModels = qemuCaps->tcgCPUModels;
+defs = qemuCaps->tcgCPUModels;
 
-if (!cpuModels)
+if (!defs)
 return NULL;
 
-if (modelWhitelist || modelBlacklist)
-return virDomainCapsCPUModelsFilter(cpuModels, modelWhitelist, 
modelBlacklist);
-
-return virDomainCapsCPUModelsCopy(cpuModels);
+return virQEMUCapsCPUDefsToModels(defs, modelWhitelist, modelBlacklist);
 }
 
 
@@ -2001,7 +2001,7 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
   virDomainVirtType type,
   virCPUMode mode)
 {
-virDomainCapsCPUModelsPtr cpus;
+qemuMonitorCPUDefsPtr cpus;
 
 switch (mode) {
 case VIR_CPU_MODE_HOST_PASSTHROUGH:
@@ -2017,7 +2017,7 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
 cpus = qemuCaps->kvmCPUModels;
 else
 cpus = qemuCaps->tcgCPUModels;
-return cpus && cpus->nmodels > 0;
+return cpus && cpus->ncpus > 0;
 
 case VIR_CPU_MODE_LAST:
 break;
@@ -2553,18 +2553,18 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr 
qemuCaps,
   qemuMonitorPtr mon,
   bool tcg)
 {
-virDomainCapsCPUModelsPtr models = NULL;
+qemuMonitorCPUDefsPtr defs = NULL;
 
 if (!virQEMUCapsGet(qemuCaps, QEMU_CAP

[libvirt] [PATCH v2 20/31] conf: Drop virDomainCapsCPUModelsAddSteal

2019-10-15 Thread Jiri Denemark
Both virDomainCapsCPUModelsAdd and virDomainCapsCPUModelsAddSteal are so
simple we can just squash the code in a single function.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/conf/domain_capabilities.c | 33 ++---
 src/conf/domain_capabilities.h |  4 
 src/libvirt_private.syms   |  1 -
 3 files changed, 10 insertions(+), 28 deletions(-)

diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index a13463a6e7..dadb2a1183 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -185,27 +185,6 @@ virDomainCapsCPUModelsCopy(virDomainCapsCPUModelsPtr old)
 }
 
 
-int
-virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr cpuModels,
-   char **name,
-   virDomainCapsCPUUsable usable,
-   char ***blockers)
-{
-if (VIR_RESIZE_N(cpuModels->models, cpuModels->nmodels_max,
- cpuModels->nmodels, 1) < 0)
-return -1;
-
-cpuModels->models[cpuModels->nmodels].usable = usable;
-VIR_STEAL_PTR(cpuModels->models[cpuModels->nmodels].name, *name);
-
-if (blockers)
-VIR_STEAL_PTR(cpuModels->models[cpuModels->nmodels].blockers, 
*blockers);
-
-cpuModels->nmodels++;
-return 0;
-}
-
-
 int
 virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr cpuModels,
   const char *name,
@@ -214,6 +193,7 @@ virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr 
cpuModels,
 {
 VIR_AUTOFREE(char *) nameCopy = NULL;
 VIR_AUTOSTRINGLIST blockersCopy = NULL;
+virDomainCapsCPUModelPtr cpu;
 
 if (VIR_STRDUP(nameCopy, name) < 0)
 return -1;
@@ -221,10 +201,17 @@ virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr 
cpuModels,
 if (virStringListCopy(&blockersCopy, (const char **)blockers) < 0)
 return -1;
 
-if (virDomainCapsCPUModelsAddSteal(cpuModels, &nameCopy,
-   usable, &blockersCopy) < 0)
+if (VIR_RESIZE_N(cpuModels->models, cpuModels->nmodels_max,
+ cpuModels->nmodels, 1) < 0)
 return -1;
 
+cpu = cpuModels->models + cpuModels->nmodels;
+cpuModels->nmodels++;
+
+cpu->usable = usable;
+VIR_STEAL_PTR(cpu->name, nameCopy);
+VIR_STEAL_PTR(cpu->blockers, blockersCopy);
+
 return 0;
 }
 
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index bdd0bd9253..8b220e3bf8 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -195,10 +195,6 @@ virDomainCapsPtr virDomainCapsNew(const char *path,
 
 virDomainCapsCPUModelsPtr virDomainCapsCPUModelsNew(size_t nmodels);
 virDomainCapsCPUModelsPtr virDomainCapsCPUModelsCopy(virDomainCapsCPUModelsPtr 
old);
-int virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr cpuModels,
-   char **name,
-   virDomainCapsCPUUsable usable,
-   char ***blockers);
 int virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr cpuModels,
   const char *name,
   virDomainCapsCPUUsable usable,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 641b1f93bd..b35934be1f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -191,7 +191,6 @@ virDomainAuditVcpu;
 
 # conf/domain_capabilities.h
 virDomainCapsCPUModelsAdd;
-virDomainCapsCPUModelsAddSteal;
 virDomainCapsCPUModelsCopy;
 virDomainCapsCPUModelsGet;
 virDomainCapsCPUModelsNew;
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 21/31] qemu: Store typename from query-cpu-definitions in qemuCaps

2019-10-15 Thread Jiri Denemark
We need to create a mapping between CPU model names and their
corresponding QOM types.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- ignore empty typename strings

 src/qemu/qemu_capabilities.c  |   3 +
 src/qemu/qemu_monitor.c   |   2 +
 src/qemu/qemu_monitor.h   |   1 +
 src/qemu/qemu_monitor_json.c  |   5 +
 .../caps_2.10.0.aarch64.xml   | 126 ++---
 .../caps_2.10.0.ppc64.xml | 512 -
 .../caps_2.10.0.s390x.xml | 264 -
 .../caps_2.10.0.x86_64.xml| 132 ++---
 .../caps_2.11.0.s390x.xml | 264 -
 .../caps_2.11.0.x86_64.xml| 136 ++---
 .../caps_2.12.0.aarch64.xml   | 136 ++---
 .../caps_2.12.0.ppc64.xml | 516 +-
 .../caps_2.12.0.s390x.xml | 264 -
 .../caps_2.12.0.x86_64.xml| 180 +++---
 .../qemucapabilitiesdata/caps_2.9.0.ppc64.xml | 512 -
 .../qemucapabilitiesdata/caps_2.9.0.s390x.xml | 256 -
 .../caps_2.9.0.x86_64.xml | 128 ++---
 .../qemucapabilitiesdata/caps_3.0.0.ppc64.xml | 516 +-
 .../qemucapabilitiesdata/caps_3.0.0.s390x.xml | 272 -
 .../caps_3.0.0.x86_64.xml | 184 +++
 .../qemucapabilitiesdata/caps_3.1.0.ppc64.xml | 516 +-
 .../caps_3.1.0.x86_64.xml | 196 +++
 .../caps_4.0.0.aarch64.xml| 148 ++---
 .../qemucapabilitiesdata/caps_4.0.0.ppc64.xml | 516 +-
 .../qemucapabilitiesdata/caps_4.0.0.s390x.xml | 284 +-
 .../caps_4.0.0.x86_64.xml | 196 +++
 .../caps_4.1.0.x86_64.xml | 400 +++---
 .../caps_4.2.0.aarch64.xml| 148 ++---
 .../qemucapabilitiesdata/caps_4.2.0.ppc64.xml | 516 +-
 .../qemucapabilitiesdata/caps_4.2.0.s390x.xml | 300 +-
 .../caps_4.2.0.x86_64.xml | 400 +++---
 31 files changed, 4020 insertions(+), 4009 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index a274cef120..2a32d575c9 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3548,6 +3548,8 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
 return -1;
 }
 
+cpu->type = virXMLPropString(nodes[i], "typename");
+
 node = ctxt->node;
 ctxt->node = nodes[i];
 nblockers = virXPathNodeSet("./blocker", ctxt, &blockerNodes);
@@ -4010,6 +4012,7 @@ virQEMUCapsFormatCPUModels(virQEMUCapsPtr qemuCaps,
 
 virBufferAsprintf(buf, "name);
+virBufferEscapeString(buf, " typename='%s'", cpu->type);
 if (cpu->usable) {
 virBufferAsprintf(buf, " usable='%s'",
   virDomainCapsCPUUsableTypeToString(cpu->usable));
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 8d86112f30..6056219674 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3559,6 +3559,7 @@ qemuMonitorCPUDefsFree(qemuMonitorCPUDefsPtr defs)
 for (i = 0; i < defs->ncpus; i++) {
 virStringListFree(defs->cpus[i].blockers);
 VIR_FREE(defs->cpus[i].name);
+VIR_FREE(defs->cpus[i].type);
 }
 
 VIR_FREE(defs->cpus);
@@ -3605,6 +3606,7 @@ qemuMonitorCPUDefsCopy(qemuMonitorCPUDefsPtr *dst,
 cpuDst->usable = cpuSrc->usable;
 
 if (VIR_STRDUP(cpuDst->name, cpuSrc->name) < 0 ||
+VIR_STRDUP(cpuDst->type, cpuSrc->type) < 0 ||
 virStringListCopy(&cpuDst->blockers,
   (const char **)cpuSrc->blockers) < 0)
 return -1;
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 4f355c760a..f2af1badd4 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1098,6 +1098,7 @@ typedef qemuMonitorCPUDefInfo *qemuMonitorCPUDefInfoPtr;
 struct _qemuMonitorCPUDefInfo {
 virTristateBool usable;
 char *name;
+char *type;
 char **blockers; /* NULL-terminated string list */
 };
 
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index de75c46dc1..bc30884223 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5571,6 +5571,11 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
 if (VIR_STRDUP(cpu->name, tmp) < 0)
 return -1;
 
+if ((tmp = virJSONValueObjectGetString(child, "typename")) &&
+*tmp &&
+VIR_STRDUP(cpu->type, tmp) < 0)
+return -1;
+
 if (virJSONValueObjectHasKey(child, "unavailable-features")) {
 virJSONValuePtr blockers;
 size_t j;
...
diff --git a/tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml 
b/tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml
index ab884239fe..1766

[libvirt] [PATCH v2 07/31] qemu: Use virQEMUCapsGetCPUDefinitions more

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
Reviewed-by: Ján Tomko 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c | 21 +++--
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e6a7ee4f14..b608eb1a43 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -5297,24 +5297,17 @@ virQEMUCapsFillDomainCPUCaps(virCapsPtr caps,
 
 if (virQEMUCapsIsCPUModeSupported(qemuCaps, caps, domCaps->virttype,
   VIR_CPU_MODE_CUSTOM)) {
-virDomainCapsCPUModelsPtr filtered = NULL;
-char **models = NULL;
 const char *blacklist[] = { "host", NULL };
+VIR_AUTOSTRINGLIST models = NULL;
 
 if (virCPUGetModels(domCaps->arch, &models) >= 0) {
-virDomainCapsCPUModelsPtr cpus;
-
-if (domCaps->virttype == VIR_DOMAIN_VIRT_KVM)
-cpus = qemuCaps->kvmCPUModels;
-else
-cpus = qemuCaps->tcgCPUModels;
-
-filtered = virDomainCapsCPUModelsFilter(cpus,
-(const char **)models,
-blacklist);
-virStringListFree(models);
+domCaps->cpu.custom = virQEMUCapsGetCPUDefinitions(qemuCaps,
+   
domCaps->virttype,
+   (const char 
**)models,
+   blacklist);
+} else {
+domCaps->cpu.custom = NULL;
 }
-domCaps->cpu.custom = filtered;
 }
 
 return 0;
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2 00/31] qemu: Store default CPU in domain XML

2019-10-15 Thread Jiri Denemark
When starting a domain without a CPU model specified in the domain XML,
QEMU will choose a default one. Which is fine unless the domain gets
migrated to another host because libvirt doesn't perform any CPU ABI
checks and the virtual CPU provided by QEMU on the destination host can
differ from the one on the source host.

With QEMU 4.2.0 we can probe for the default CPU model used by QEMU for
a particular machine type and store it in the domain XML. This way the
chosen CPU model is more visible to users and libvirt will make sure
the guest will see the exact same CPU after migration.

https://bugzilla.redhat.com/show_bug.cgi?id=1598151
https://bugzilla.redhat.com/show_bug.cgi?id=1598162

---

Some patches were too large so I decided to shorten them before sending
to the list. You can check the full version of this series with

git fetch https://gitlab.com/jirkade/libvirt cpu-default-type

Jiri Denemark (31):
  tests: Add capabilities for QEMU 4.2.0 on s390x
  domcapstest: Add test case for QEMU 4.2.0 on s390x
  conf: Use VIR_AUTO* in virDomainCapsCPUModelsAdd
  conf: Drop nameLen parameter from virDomainCapsCPUModelsAdd
  qemu: Copy CPU models in virQEMUCapsGetCPUDefinitions
  qemu: Filter models in virQEMUCapsGetCPUDefinitions
  qemu: Use virQEMUCapsGetCPUDefinitions more
  qemu: Use VIR_AUTOPTR in qemuMonitorJSONGetCPUDefinitions
  qemu: Change return type of virQEMUCapsFetchCPUDefinitions
  qemu: Introduce qemuMonitorCPUDefs struct
  qemu: Flatten qemuMonitorCPUDefs.cpus
  build: Export virStringListCopy internal API
  qemu: Add qemuMonitorCPUDefsCopy
  qemu: Use VIR_AUTOFREE in virQEMUCapsLoadCPUModels
  qemu: Introduce virQEMUCapsCPUDefsToModels
  qemu: Rename virQEMUCaps{Get,Fetch}CPUDefinitions
  qemu: Split virQEMUCapsFetchCPUModels
  qemu: Switch qemuCaps to use qemuMonitorCPUDefs
  conf: Drop unused virDomainCapsCPUModelsFilter
  conf: Drop virDomainCapsCPUModelsAddSteal
  qemu: Store typename from query-cpu-definitions in qemuCaps
  qemu: Probe for default CPU types
  qemu: Introduce virQEMUCapsGetMachineDefaultCPU
  qemu: Drop unused virQEMUCapsGetDefaultMachine
  qemu: Use VIR_AUTOUNREF in qemuDomainDefPostParse
  conf: Define VIR_AUTOPTR for virCPUDef
  qemuxml2*test: Add test cases for default CPU models on aarch64
  qemuxml2*test: Add test cases for default CPU models on ppc64
  qemuxml2*test: Add test cases for default CPU models on s390x
  qemuxml2*test: Add test cases for default CPU models on x86_64
  qemu: Store default CPU in domain XML

 src/conf/cpu_conf.h   | 1 +
 src/conf/domain_capabilities.c|86 +-
 src/conf/domain_capabilities.h| 8 -
 src/libvirt_private.syms  | 3 +-
 src/qemu/qemu_capabilities.c  |   358 +-
 src/qemu/qemu_capabilities.h  |15 +-
 src/qemu/qemu_domain.c|84 +-
 src/qemu/qemu_driver.c| 4 +-
 src/qemu/qemu_monitor.c   |74 +-
 src/qemu/qemu_monitor.h   |18 +-
 src/qemu/qemu_monitor_json.c  |82 +-
 src/qemu/qemu_monitor_json.h  | 2 +-
 src/qemu/qemu_process.c   |24 +-
 tests/cputest.c   | 7 +-
 .../domaincapsschemadata/qemu_4.2.0.s390x.xml |   202 +
 tests/domaincapstest.c| 4 +
 .../caps_2.10.0.aarch64.xml   |   126 +-
 .../caps_2.10.0.ppc64.xml |   512 +-
 .../caps_2.10.0.s390x.xml |   264 +-
 .../caps_2.10.0.x86_64.xml|   132 +-
 .../caps_2.11.0.s390x.xml |   264 +-
 .../caps_2.11.0.x86_64.xml|   136 +-
 .../caps_2.12.0.aarch64.xml   |   136 +-
 .../caps_2.12.0.ppc64.xml |   516 +-
 .../caps_2.12.0.s390x.xml |   264 +-
 .../caps_2.12.0.x86_64.xml|   180 +-
 .../qemucapabilitiesdata/caps_2.9.0.ppc64.xml |   512 +-
 .../qemucapabilitiesdata/caps_2.9.0.s390x.xml |   256 +-
 .../caps_2.9.0.x86_64.xml |   128 +-
 .../qemucapabilitiesdata/caps_3.0.0.ppc64.xml |   516 +-
 .../qemucapabilitiesdata/caps_3.0.0.s390x.xml |   272 +-
 .../caps_3.0.0.x86_64.xml |   184 +-
 .../qemucapabilitiesdata/caps_3.1.0.ppc64.xml |   516 +-
 .../caps_3.1.0.x86_64.xml |   196 +-
 .../caps_4.0.0.aarch64.xml|   148 +-
 .../qemucapabilitiesdata/caps_4.0.0.ppc64.xml |   516 +-
 .../qemucapabilitiesdata/caps_4.0.0.s390x.xml |   284 +-
 .../caps_4.0.0.x86_64.xml |   196 +-
 .../caps_4.1.0.x86_64.xml |   400 +-
 .../caps_4.2.0.aarch64.xml|   242 +-
 .../qemucapabilitiesdata/caps_4.2.0.ppc64.xml |   574 +-
 .../caps_4.2.0.s390x.replies  | 22414 
 .../qemucapabilitiesdata/caps_4.2.0.s390x.xml

[libvirt] [PATCH v2 25/31] qemu: Use VIR_AUTOUNREF in qemuDomainDefPostParse

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
Reviewed-by: Ján Tomko 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_domain.c | 28 
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c638077aa8..9dcba4ef38 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4617,55 +4617,51 @@ qemuDomainDefPostParse(virDomainDefPtr def,
void *parseOpaque)
 {
 virQEMUDriverPtr driver = opaque;
-virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
 /* Note that qemuCaps may be NULL when this function is called. This
  * function shall not fail in that case. It will be re-run on VM startup
  * with the capabilities populated. */
 virQEMUCapsPtr qemuCaps = parseOpaque;
-int ret = -1;
 
 if (def->os.bootloader || def->os.bootloaderArgs) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("bootloader is not supported by QEMU"));
-goto cleanup;
+return -1;
 }
 
 if (!def->os.machine) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing machine type"));
-goto cleanup;
+return -1;
 }
 
 if (qemuDomainNVRAMPathGenerate(cfg, def) < 0)
-goto cleanup;
+return -1;
 
 if (qemuDomainDefAddDefaultDevices(def, qemuCaps) < 0)
-goto cleanup;
+return -1;
 
 if (qemuCanonicalizeMachine(def, qemuCaps) < 0)
-goto cleanup;
+return -1;
 
 qemuDomainDefEnableDefaultFeatures(def, qemuCaps);
 
 if (qemuDomainRecheckInternalPaths(def, cfg, parseFlags) < 0)
-goto cleanup;
+return -1;
 
 if (qemuSecurityVerify(driver->securityManager, def) < 0)
-goto cleanup;
+return -1;
 
 if (qemuDomainDefVcpusPostParse(def) < 0)
-goto cleanup;
+return -1;
 
 if (qemuDomainDefCPUPostParse(def) < 0)
-goto cleanup;
+return -1;
 
 if (qemuDomainDefTsegPostParse(def, qemuCaps) < 0)
-goto cleanup;
+return -1;
 
-ret = 0;
- cleanup:
-virObjectUnref(cfg);
-return ret;
+return 0;
 }
 
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2 27/31] qemuxml2*test: Add test cases for default CPU models on aarch64

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- new patch

 ...fault-cpu-kvm-virt-4.2.aarch64-latest.args | 38 +++
 .../aarch64-default-cpu-kvm-virt-4.2.xml  | 20 ++
 ...fault-cpu-tcg-virt-4.2.aarch64-latest.args | 38 +++
 .../aarch64-default-cpu-tcg-virt-4.2.xml  | 20 ++
 tests/qemuxml2argvtest.c  |  3 ++
 ...efault-cpu-kvm-virt-4.2.aarch64-latest.xml | 38 +++
 ...efault-cpu-tcg-virt-4.2.aarch64-latest.xml | 38 +++
 tests/qemuxml2xmltest.c   |  3 ++
 8 files changed, 198 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/aarch64-default-cpu-kvm-virt-4.2.aarch64-latest.args
 create mode 100644 tests/qemuxml2argvdata/aarch64-default-cpu-kvm-virt-4.2.xml
 create mode 100644 
tests/qemuxml2argvdata/aarch64-default-cpu-tcg-virt-4.2.aarch64-latest.args
 create mode 100644 tests/qemuxml2argvdata/aarch64-default-cpu-tcg-virt-4.2.xml
 create mode 100644 
tests/qemuxml2xmloutdata/aarch64-default-cpu-kvm-virt-4.2.aarch64-latest.xml
 create mode 100644 
tests/qemuxml2xmloutdata/aarch64-default-cpu-tcg-virt-4.2.aarch64-latest.xml

diff --git 
a/tests/qemuxml2argvdata/aarch64-default-cpu-kvm-virt-4.2.aarch64-latest.args 
b/tests/qemuxml2argvdata/aarch64-default-cpu-kvm-virt-4.2.aarch64-latest.args
new file mode 100644
index 00..fe33d5410a
--- /dev/null
+++ 
b/tests/qemuxml2argvdata/aarch64-default-cpu-kvm-virt-4.2.aarch64-latest.args
@@ -0,0 +1,38 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-guest \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-guest/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-guest/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-guest/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-aarch64 \
+-name guest=guest,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-guest/master-key.aes \
+-machine virt-4.2,accel=kvm,usb=off,dump-guest-core=off,gic-version=3 \
+-m 4096 \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-device 
pcie-root-port,port=0x8,chassis=1,id=pci.1,bus=pcie.0,multifunction=on,\
+addr=0x1 \
+-device pcie-root-port,port=0x9,chassis=2,id=pci.2,bus=pcie.0,addr=0x1.0x1 \
+-drive file=/var/lib/libvirt/images/guest.qcow2,format=qcow2,if=none,\
+id=drive-virtio-disk0 \
+-device virtio-blk-pci,scsi=off,bus=pci.1,addr=0x0,drive=drive-virtio-disk0,\
+id=virtio-disk0,bootindex=1 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/aarch64-default-cpu-kvm-virt-4.2.xml 
b/tests/qemuxml2argvdata/aarch64-default-cpu-kvm-virt-4.2.xml
new file mode 100644
index 00..1267306ebf
--- /dev/null
+++ b/tests/qemuxml2argvdata/aarch64-default-cpu-kvm-virt-4.2.xml
@@ -0,0 +1,20 @@
+
+  guest
+  1ccfd97d-5eb4-478a-bbe6-88d254c16db7
+  4194304
+  4194304
+  1
+  
+hvm
+
+  
+  
+  
+/usr/bin/qemu-system-aarch64
+
+  
+  
+  
+
+  
+
diff --git 
a/tests/qemuxml2argvdata/aarch64-default-cpu-tcg-virt-4.2.aarch64-latest.args 
b/tests/qemuxml2argvdata/aarch64-default-cpu-tcg-virt-4.2.aarch64-latest.args
new file mode 100644
index 00..5ecbe1fdd6
--- /dev/null
+++ 
b/tests/qemuxml2argvdata/aarch64-default-cpu-tcg-virt-4.2.aarch64-latest.args
@@ -0,0 +1,38 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-guest \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-guest/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-guest/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-guest/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-aarch64 \
+-name guest=guest,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-guest/master-key.aes \
+-machine virt-4.2,accel=tcg,usb=off,dump-guest-core=off,gic-version=2 \
+-m 4096 \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-device 
pcie-root-port,port=0x8,chassis=1,id=pci.1,bus=pcie.0,multifunction=on,\
+addr=0x1 \
+-device pcie-root-port,port=0x9,chassis=2,id=pci.2,bus=pcie.0,addr=0x1.0x1 \
+-drive file=/var/lib/libvirt/images/guest.qcow2,format=qcow2,if=none,\
+id=drive-virtio-disk0 \
+-device virtio-blk-pci,scsi=off,bus=pci.1,addr=0x0,drive=drive-virtio-disk0,\
+id=virtio-disk0,bootindex=1 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
di

[libvirt] [PATCH v2 22/31] qemu: Probe for default CPU types

2019-10-15 Thread Jiri Denemark
QEMU 4.2.0 will report default CPU types used by each machine type and
we will want to start using it.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change except for updated test results

 src/qemu/qemu_capabilities.c  | 15 ++-
 src/qemu/qemu_monitor.c   |  1 +
 src/qemu/qemu_monitor.h   |  1 +
 src/qemu/qemu_monitor_json.c  | 12 +++
 .../caps_4.2.0.aarch64.xml| 94 +--
 .../qemucapabilitiesdata/caps_4.2.0.ppc64.xml | 58 ++--
 .../qemucapabilitiesdata/caps_4.2.0.s390x.xml | 28 +++---
 .../caps_4.2.0.x86_64.xml | 92 +-
 8 files changed, 163 insertions(+), 138 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 2a32d575c9..33cd3491b2 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -556,6 +556,7 @@ struct virQEMUCapsMachineType {
 unsigned int maxCpus;
 bool hotplugCpus;
 bool qemuDefault;
+char *defaultCPU;
 };
 
 typedef struct _virQEMUCapsHostCPUData virQEMUCapsHostCPUData;
@@ -1638,7 +1639,8 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
 ret->nmachineTypes = qemuCaps->nmachineTypes;
 for (i = 0; i < qemuCaps->nmachineTypes; i++) {
 if (VIR_STRDUP(ret->machineTypes[i].name, 
qemuCaps->machineTypes[i].name) < 0 ||
-VIR_STRDUP(ret->machineTypes[i].alias, 
qemuCaps->machineTypes[i].alias) < 0)
+VIR_STRDUP(ret->machineTypes[i].alias, 
qemuCaps->machineTypes[i].alias) < 0 ||
+VIR_STRDUP(ret->machineTypes[i].defaultCPU, 
qemuCaps->machineTypes[i].defaultCPU) < 0)
 goto error;
 ret->machineTypes[i].maxCpus = qemuCaps->machineTypes[i].maxCpus;
 ret->machineTypes[i].hotplugCpus = 
qemuCaps->machineTypes[i].hotplugCpus;
@@ -1673,6 +1675,7 @@ void virQEMUCapsDispose(void *obj)
 for (i = 0; i < qemuCaps->nmachineTypes; i++) {
 VIR_FREE(qemuCaps->machineTypes[i].name);
 VIR_FREE(qemuCaps->machineTypes[i].alias);
+VIR_FREE(qemuCaps->machineTypes[i].defaultCPU);
 }
 VIR_FREE(qemuCaps->machineTypes);
 
@@ -2406,7 +2409,8 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
 mach = &(qemuCaps->machineTypes[qemuCaps->nmachineTypes++]);
 
 if (VIR_STRDUP(mach->alias, machines[i]->alias) < 0 ||
-VIR_STRDUP(mach->name, machines[i]->name) < 0)
+VIR_STRDUP(mach->name, machines[i]->name) < 0 ||
+VIR_STRDUP(mach->defaultCPU, machines[i]->defaultCPU) < 0)
 goto cleanup;
 
 mach->maxCpus = machines[i]->maxCpus;
@@ -3843,6 +3847,8 @@ virQEMUCapsLoadCache(virArch hostArch,
 if (STREQ_NULLABLE(str, "yes"))
 qemuCaps->machineTypes[i].qemuDefault = true;
 VIR_FREE(str);
+
+qemuCaps->machineTypes[i].defaultCPU = virXMLPropString(nodes[i], 
"defaultCPU");
 }
 }
 VIR_FREE(nodes);
@@ -4116,6 +4122,11 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps)
   qemuCaps->machineTypes[i].maxCpus);
 if (qemuCaps->machineTypes[i].qemuDefault)
 virBufferAddLit(&buf, " default='yes'");
+
+if (qemuCaps->machineTypes[i].defaultCPU)
+virBufferEscapeString(&buf, " defaultCPU='%s'",
+  qemuCaps->machineTypes[i].defaultCPU);
+
 virBufferAddLit(&buf, "/>\n");
 }
 
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 6056219674..6f2d759a78 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3532,6 +3532,7 @@ qemuMonitorMachineInfoFree(qemuMonitorMachineInfoPtr 
machine)
 return;
 VIR_FREE(machine->name);
 VIR_FREE(machine->alias);
+VIR_FREE(machine->defaultCPU);
 VIR_FREE(machine);
 }
 
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index f2af1badd4..c099321ad1 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1085,6 +1085,7 @@ struct _qemuMonitorMachineInfo {
 char *alias;
 unsigned int maxCpus;
 bool hotplugCpus;
+char *defaultCPU;
 };
 
 int qemuMonitorGetMachines(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index bc30884223..1309b6a781 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5504,6 +5504,18 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon,
 
 ignore_value(virJSONValueObjectGetBoolean(child, "hotpluggable-cpus",
   &info->hotplugCpus));
+
+if (virJSONValueObjectHasKey(child, "default-cpu-type")) {
+if (!(tmp = virJSONValueObjectGetString(child, 
"default-cpu-type"))) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("query-machines reply has malformed "
+ "'default-cpu

[libvirt] [PATCH v2 08/31] qemu: Use VIR_AUTOPTR in qemuMonitorJSONGetCPUDefinitions

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
Reviewed-by: Ján Tomko 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_monitor_json.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index d3447dd2f3..418bdcec92 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5527,8 +5527,8 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
  qemuMonitorCPUDefInfoPtr **cpus)
 {
 int ret = -1;
-virJSONValuePtr cmd;
-virJSONValuePtr reply = NULL;
+VIR_AUTOPTR(virJSONValue) cmd = NULL;
+VIR_AUTOPTR(virJSONValue) reply = NULL;
 virJSONValuePtr data;
 qemuMonitorCPUDefInfoPtr *cpulist = NULL;
 size_t n = 0;
@@ -5630,8 +5630,6 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
 qemuMonitorCPUDefInfoFree(cpulist[i]);
 VIR_FREE(cpulist);
 }
-virJSONValueFree(cmd);
-virJSONValueFree(reply);
 return ret;
 }
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2 19/31] conf: Drop unused virDomainCapsCPUModelsFilter

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/conf/domain_capabilities.c | 33 -
 src/conf/domain_capabilities.h |  3 ---
 src/libvirt_private.syms   |  1 -
 3 files changed, 37 deletions(-)

diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index ab8ebb650d..a13463a6e7 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -185,39 +185,6 @@ virDomainCapsCPUModelsCopy(virDomainCapsCPUModelsPtr old)
 }
 
 
-virDomainCapsCPUModelsPtr
-virDomainCapsCPUModelsFilter(virDomainCapsCPUModelsPtr old,
- const char **models,
- const char **blacklist)
-{
-virDomainCapsCPUModelsPtr cpuModels;
-size_t i;
-
-if (!(cpuModels = virDomainCapsCPUModelsNew(0)))
-return NULL;
-
-for (i = 0; i < old->nmodels; i++) {
-if (models && !virStringListHasString(models, old->models[i].name))
-continue;
-
-if (blacklist && virStringListHasString(blacklist, 
old->models[i].name))
-continue;
-
-if (virDomainCapsCPUModelsAdd(cpuModels,
-  old->models[i].name,
-  old->models[i].usable,
-  old->models[i].blockers) < 0)
-goto error;
-}
-
-return cpuModels;
-
- error:
-virObjectUnref(cpuModels);
-return NULL;
-}
-
-
 int
 virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr cpuModels,
char **name,
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index e3bd8d423e..bdd0bd9253 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -195,9 +195,6 @@ virDomainCapsPtr virDomainCapsNew(const char *path,
 
 virDomainCapsCPUModelsPtr virDomainCapsCPUModelsNew(size_t nmodels);
 virDomainCapsCPUModelsPtr virDomainCapsCPUModelsCopy(virDomainCapsCPUModelsPtr 
old);
-virDomainCapsCPUModelsPtr 
virDomainCapsCPUModelsFilter(virDomainCapsCPUModelsPtr old,
-   const char **models,
-   const char **blacklist);
 int virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr cpuModels,
char **name,
virDomainCapsCPUUsable usable,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1af18b880b..641b1f93bd 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -193,7 +193,6 @@ virDomainAuditVcpu;
 virDomainCapsCPUModelsAdd;
 virDomainCapsCPUModelsAddSteal;
 virDomainCapsCPUModelsCopy;
-virDomainCapsCPUModelsFilter;
 virDomainCapsCPUModelsGet;
 virDomainCapsCPUModelsNew;
 virDomainCapsCPUUsableTypeFromString;
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 28/31] qemuxml2*test: Add test cases for default CPU models on ppc64

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- new patch

 ...ault-cpu-kvm-pseries-2.7.ppc64-latest.args | 38 
 .../ppc64-default-cpu-kvm-pseries-2.7.xml | 22 +
 ...ault-cpu-kvm-pseries-3.1.ppc64-latest.args | 38 
 .../ppc64-default-cpu-kvm-pseries-3.1.xml | 22 +
 ...ault-cpu-kvm-pseries-4.2.ppc64-latest.args | 38 
 .../ppc64-default-cpu-kvm-pseries-4.2.xml | 22 +
 ...ault-cpu-tcg-pseries-2.7.ppc64-latest.args | 38 
 .../ppc64-default-cpu-tcg-pseries-2.7.xml | 22 +
 ...ault-cpu-tcg-pseries-3.1.ppc64-latest.args | 38 
 .../ppc64-default-cpu-tcg-pseries-3.1.xml | 22 +
 ...ault-cpu-tcg-pseries-4.2.ppc64-latest.args | 38 
 .../ppc64-default-cpu-tcg-pseries-4.2.xml | 22 +
 tests/qemuxml2argvtest.c  |  6 +++
 ...fault-cpu-kvm-pseries-2.7.ppc64-latest.xml | 45 +++
 ...fault-cpu-kvm-pseries-3.1.ppc64-latest.xml | 45 +++
 ...fault-cpu-kvm-pseries-4.2.ppc64-latest.xml | 45 +++
 ...fault-cpu-tcg-pseries-2.7.ppc64-latest.xml | 45 +++
 ...fault-cpu-tcg-pseries-3.1.ppc64-latest.xml | 45 +++
 ...fault-cpu-tcg-pseries-4.2.ppc64-latest.xml | 45 +++
 tests/qemuxml2xmltest.c   |  6 +++
 20 files changed, 642 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-2.7.ppc64-latest.args
 create mode 100644 tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-2.7.xml
 create mode 100644 
tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-3.1.ppc64-latest.args
 create mode 100644 tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-3.1.xml
 create mode 100644 
tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-4.2.ppc64-latest.args
 create mode 100644 tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-4.2.xml
 create mode 100644 
tests/qemuxml2argvdata/ppc64-default-cpu-tcg-pseries-2.7.ppc64-latest.args
 create mode 100644 tests/qemuxml2argvdata/ppc64-default-cpu-tcg-pseries-2.7.xml
 create mode 100644 
tests/qemuxml2argvdata/ppc64-default-cpu-tcg-pseries-3.1.ppc64-latest.args
 create mode 100644 tests/qemuxml2argvdata/ppc64-default-cpu-tcg-pseries-3.1.xml
 create mode 100644 
tests/qemuxml2argvdata/ppc64-default-cpu-tcg-pseries-4.2.ppc64-latest.args
 create mode 100644 tests/qemuxml2argvdata/ppc64-default-cpu-tcg-pseries-4.2.xml
 create mode 100644 
tests/qemuxml2xmloutdata/ppc64-default-cpu-kvm-pseries-2.7.ppc64-latest.xml
 create mode 100644 
tests/qemuxml2xmloutdata/ppc64-default-cpu-kvm-pseries-3.1.ppc64-latest.xml
 create mode 100644 
tests/qemuxml2xmloutdata/ppc64-default-cpu-kvm-pseries-4.2.ppc64-latest.xml
 create mode 100644 
tests/qemuxml2xmloutdata/ppc64-default-cpu-tcg-pseries-2.7.ppc64-latest.xml
 create mode 100644 
tests/qemuxml2xmloutdata/ppc64-default-cpu-tcg-pseries-3.1.ppc64-latest.xml
 create mode 100644 
tests/qemuxml2xmloutdata/ppc64-default-cpu-tcg-pseries-4.2.ppc64-latest.xml

diff --git 
a/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-2.7.ppc64-latest.args 
b/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-2.7.ppc64-latest.args
new file mode 100644
index 00..d264659d49
--- /dev/null
+++ b/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-2.7.ppc64-latest.args
@@ -0,0 +1,38 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-guest \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-guest/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-guest/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-guest/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-ppc64 \
+-name guest=guest,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-guest/master-key.aes \
+-machine pseries-2.7,accel=kvm,usb=off,dump-guest-core=off \
+-m 4096 \
+-overcommit mem-lock=off \
+-smp 4,sockets=4,cores=1,threads=1 \
+-uuid 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot strict=on \
+-device pci-ohci,id=usb,bus=pci.0,addr=0x1 \
+-drive file=/var/lib/libvirt/images/guest.qcow2,format=qcow2,if=none,\
+id=drive-virtio-disk0 \
+-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x2,drive=drive-virtio-disk0,\
+id=virtio-disk0,bootindex=1 \
+-chardev pty,id=charserial0 \
+-device spapr-vty,chardev=charserial0,id=serial0,reg=0x3000 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-2.7.xml 
b/tests/qemuxml2argvdata/ppc64-default-cpu-kvm-pseries-2.7.xml
new file mode 100644
index 00..9aac1815c4
--- /dev/null
+++ b/tests/qemuxml2argvdata/ppc64-d

[libvirt] [PATCH v2 11/31] qemu: Flatten qemuMonitorCPUDefs.cpus

2019-10-15 Thread Jiri Denemark
Let's store qemuMonitorCPUDefInfo directly in the array of CPUs in
qemuMonitorCPUDefs rather then using an array of pointers.

Signed-off-by: Jiri Denemark 
Reviewed-by: Ján Tomko 
---

Notes:
Version 2:
- trivial rebase

 src/qemu/qemu_capabilities.c | 14 +++---
 src/qemu/qemu_monitor.c  |  5 ++---
 src/qemu/qemu_monitor.h  |  2 +-
 src/qemu/qemu_monitor_json.c |  7 +--
 tests/qemumonitorjsontest.c  |  8 
 5 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 59af3ab6d3..442445aad9 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2483,11 +2483,11 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
 
 for (name = libvirtModels; name && *name; name++) {
 for (i = 0; i < defs->ncpus; i++) {
-if (STRCASENEQ(defs->cpus[i]->name, *name))
+if (STRCASENEQ(defs->cpus[i].name, *name))
 continue;
 
-VIR_FREE(defs->cpus[i]->name);
-if (VIR_STRDUP(defs->cpus[i]->name, *name) < 0)
+VIR_FREE(defs->cpus[i].name);
+if (VIR_STRDUP(defs->cpus[i].name, *name) < 0)
 goto cleanup;
 }
 }
@@ -2499,13 +2499,13 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
 for (i = 0; i < defs->ncpus; i++) {
 virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
 
-if (defs->cpus[i]->usable == VIR_TRISTATE_BOOL_YES)
+if (defs->cpus[i].usable == VIR_TRISTATE_BOOL_YES)
 usable = VIR_DOMCAPS_CPU_USABLE_YES;
-else if (defs->cpus[i]->usable == VIR_TRISTATE_BOOL_NO)
+else if (defs->cpus[i].usable == VIR_TRISTATE_BOOL_NO)
 usable = VIR_DOMCAPS_CPU_USABLE_NO;
 
-if (virDomainCapsCPUModelsAddSteal(models, &defs->cpus[i]->name, 
usable,
-   &defs->cpus[i]->blockers) < 0)
+if (virDomainCapsCPUModelsAddSteal(models, &defs->cpus[i].name, usable,
+   &defs->cpus[i].blockers) < 0)
 goto cleanup;
 }
 
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index d17387d27f..87a9d06d45 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3557,9 +3557,8 @@ qemuMonitorCPUDefsFree(qemuMonitorCPUDefsPtr defs)
 return;
 
 for (i = 0; i < defs->ncpus; i++) {
-virStringListFree(defs->cpus[i]->blockers);
-VIR_FREE(defs->cpus[i]->name);
-VIR_FREE(defs->cpus[i]);
+virStringListFree(defs->cpus[i].blockers);
+VIR_FREE(defs->cpus[i].name);
 }
 
 VIR_FREE(defs->cpus);
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 359bbfca7f..aa2a0e392a 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1105,7 +1105,7 @@ typedef struct _qemuMonitorCPUDefs qemuMonitorCPUDefs;
 typedef qemuMonitorCPUDefs *qemuMonitorCPUDefsPtr;
 struct _qemuMonitorCPUDefs {
 size_t ncpus;
-qemuMonitorCPUDefInfoPtr *cpus;
+qemuMonitorCPUDefInfoPtr cpus;
 };
 
 int qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 664f1b225e..de75c46dc1 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5560,12 +5560,7 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon,
 for (i = 0; i < defs->ncpus; i++) {
 virJSONValuePtr child = virJSONValueArrayGet(data, i);
 const char *tmp;
-qemuMonitorCPUDefInfoPtr cpu;
-
-if (VIR_ALLOC(cpu) < 0)
-return -1;
-
-defs->cpus[i] = cpu;
+qemuMonitorCPUDefInfoPtr cpu = defs->cpus + i;
 
 if (!(tmp = virJSONValueObjectGetString(child, "name"))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 7b8f63b11e..18ccf271f5 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -463,16 +463,16 @@ testQemuMonitorJSONGetCPUDefinitions(const void *opaque)
 
 #define CHECK_FULL(i, wantname, Usable) \
 do { \
-if (STRNEQ(defs->cpus[i]->name, (wantname))) { \
+if (STRNEQ(defs->cpus[i].name, (wantname))) { \
 virReportError(VIR_ERR_INTERNAL_ERROR, \
"name %s is not %s", \
-   defs->cpus[i]->name, (wantname)); \
+   defs->cpus[i].name, (wantname)); \
 return -1; \
 } \
-if (defs->cpus[i]->usable != (Usable)) { \
+if (defs->cpus[i].usable != (Usable)) { \
 virReportError(VIR_ERR_INTERNAL_ERROR, \
"%s: expecting usable flag %d, got %d", \
-   defs->cpus[i]->name, Usable, 
defs->cpus[i]->usable); \
+   defs->cpus[i].name, Usable, defs->cpus[i].usable); \

[libvirt] [PATCH v2 06/31] qemu: Filter models in virQEMUCapsGetCPUDefinitions

2019-10-15 Thread Jiri Denemark
Some callers of virQEMUCapsGetCPUDefinitions will need to filter the
returned list of CPU models. Let's add the filtering parameters directly
to virQEMUCapsGetCPUDefinitions to avoid copying the CPU models list
twice.

Signed-off-by: Jiri Denemark 
Reviewed-by: Ján Tomko 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c | 11 ---
 src/qemu/qemu_capabilities.h |  4 +++-
 src/qemu/qemu_driver.c   |  2 +-
 src/qemu/qemu_process.c  |  2 +-
 tests/cputest.c  |  2 +-
 5 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index a40bf99aa3..e6a7ee4f14 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1889,7 +1889,9 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
 
 virDomainCapsCPUModelsPtr
 virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
- virDomainVirtType type)
+ virDomainVirtType type,
+ const char **modelWhitelist,
+ const char **modelBlacklist)
 {
 virDomainCapsCPUModelsPtr cpuModels;
 
@@ -1901,6 +1903,9 @@ virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
 if (!cpuModels)
 return NULL;
 
+if (modelWhitelist || modelBlacklist)
+return virDomainCapsCPUModelsFilter(cpuModels, modelWhitelist, 
modelBlacklist);
+
 return virDomainCapsCPUModelsCopy(cpuModels);
 }
 
@@ -3142,7 +3147,7 @@ virQEMUCapsInitCPUModelX86(virQEMUCapsPtr qemuCaps,
 if (!(data = virQEMUCapsGetCPUModelX86Data(qemuCaps, model, migratable)))
 goto cleanup;
 
-cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type);
+cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type, NULL, NULL);
 
 if (cpuDecode(cpu, data, cpuModels) < 0)
 goto cleanup;
@@ -3231,7 +3236,7 @@ virQEMUCapsInitHostCPUModel(virQEMUCapsPtr qemuCaps,
 
 VIR_DEBUG("No host CPU model info from QEMU; probing host CPU 
directly");
 
-cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type);
+cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, type, NULL, NULL);
 hostCPU = virQEMUCapsProbeHostCPU(hostArch, cpuModels);
 
 if (!hostCPU ||
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 10f0ce2654..67dccc522e 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -570,7 +570,9 @@ int virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
  size_t count,
  virDomainCapsCPUUsable usable);
 virDomainCapsCPUModelsPtr virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
-   virDomainVirtType type);
+   virDomainVirtType type,
+   const char 
**modelWhitelist,
+   const char 
**modelBlacklist);
 virDomainCapsCPUModelsPtr virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
  virArch arch);
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 15c69667a5..802f07fe92 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13939,7 +13939,7 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn,
 if (!qemuCaps)
 goto cleanup;
 
-if (!(cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, virttype)) ||
+if (!(cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, virttype, NULL, 
NULL)) ||
 cpuModels->nmodels == 0) {
 virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("QEMU '%s' does not support any CPU models for "
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 58192612b0..f37acab9e4 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6136,7 +6136,7 @@ qemuProcessUpdateGuestCPU(virDomainDefPtr def,
  
VIR_QEMU_CAPS_HOST_CPU_MIGRATABLE)) < 0)
 return -1;
 
-cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType);
+cpuModels = virQEMUCapsGetCPUDefinitions(qemuCaps, def->virtType, 
NULL, NULL);
 
 if (virCPUTranslate(def->os.arch, def->cpu, cpuModels) < 0)
 return -1;
diff --git a/tests/cputest.c b/tests/cputest.c
index 3aa8fd7bf3..4428d451cf 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -550,7 +550,7 @@ cpuTestGetCPUModels(const struct data *data,
 if (!(qemuCaps = cpuTestMakeQEMUCaps(data)))
 return -1;
 
-*models = virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM);
+*models = virQEMUCapsGetCPUDefinitions(qemuCaps, VIR_DOMAIN_VIRT_KVM, 
NULL, NULL);
 
 virObjectUnref(qemuCaps);
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listin

[libvirt] [PATCH v2 10/31] qemu: Introduce qemuMonitorCPUDefs struct

2019-10-15 Thread Jiri Denemark
It is a container for a CPU models list (qemuMonitorCPUDefInfo) and a
number of elements in this list.

Signed-off-by: Jiri Denemark 
Reviewed-by: Ján Tomko 
---

Notes:
Version 2:
- v1 reviewed by Ján Tomko, but the patch had to be changed because
  of the previous patch

 src/qemu/qemu_capabilities.c | 30 +--
 src/qemu/qemu_monitor.c  | 39 +++--
 src/qemu/qemu_monitor.h  | 14 +++--
 src/qemu/qemu_monitor_json.c | 56 ++--
 src/qemu/qemu_monitor_json.h |  2 +-
 tests/qemumonitorjsontest.c  | 38 +---
 6 files changed, 93 insertions(+), 86 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 6fa5e06edb..59af3ab6d3 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2457,18 +2457,17 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
virArch arch,
virDomainCapsCPUModelsPtr *cpuModels)
 {
+VIR_AUTOPTR(qemuMonitorCPUDefs) defs = NULL;
 virDomainCapsCPUModelsPtr models = NULL;
-qemuMonitorCPUDefInfoPtr *cpus = NULL;
-int ncpus = 0;
 size_t i;
 int ret = -1;
 
 *cpuModels = NULL;
 
-if ((ncpus = qemuMonitorGetCPUDefinitions(mon, &cpus)) < 0)
+if (qemuMonitorGetCPUDefinitions(mon, &defs) < 0)
 return -1;
 
-if (ncpus == 0) {
+if (!defs) {
 ret = 0;
 goto cleanup;
 }
@@ -2483,30 +2482,30 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
 goto cleanup;
 
 for (name = libvirtModels; name && *name; name++) {
-for (i = 0; i < ncpus; i++) {
-if (STRCASENEQ(cpus[i]->name, *name))
+for (i = 0; i < defs->ncpus; i++) {
+if (STRCASENEQ(defs->cpus[i]->name, *name))
 continue;
 
-VIR_FREE(cpus[i]->name);
-if (VIR_STRDUP(cpus[i]->name, *name) < 0)
+VIR_FREE(defs->cpus[i]->name);
+if (VIR_STRDUP(defs->cpus[i]->name, *name) < 0)
 goto cleanup;
 }
 }
 }
 
-if (!(models = virDomainCapsCPUModelsNew(ncpus)))
+if (!(models = virDomainCapsCPUModelsNew(defs->ncpus)))
 goto cleanup;
 
-for (i = 0; i < ncpus; i++) {
+for (i = 0; i < defs->ncpus; i++) {
 virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
 
-if (cpus[i]->usable == VIR_TRISTATE_BOOL_YES)
+if (defs->cpus[i]->usable == VIR_TRISTATE_BOOL_YES)
 usable = VIR_DOMCAPS_CPU_USABLE_YES;
-else if (cpus[i]->usable == VIR_TRISTATE_BOOL_NO)
+else if (defs->cpus[i]->usable == VIR_TRISTATE_BOOL_NO)
 usable = VIR_DOMCAPS_CPU_USABLE_NO;
 
-if (virDomainCapsCPUModelsAddSteal(models, &cpus[i]->name, usable,
-   &cpus[i]->blockers) < 0)
+if (virDomainCapsCPUModelsAddSteal(models, &defs->cpus[i]->name, 
usable,
+   &defs->cpus[i]->blockers) < 0)
 goto cleanup;
 }
 
@@ -2514,9 +2513,6 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
 ret = 0;
 
  cleanup:
-for (i = 0; i < ncpus; i++)
-qemuMonitorCPUDefInfoFree(cpus[i]);
-VIR_FREE(cpus);
 virObjectUnref(models);
 return ret;
 }
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 49f9159315..d17387d27f 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3538,25 +3538,48 @@ qemuMonitorMachineInfoFree(qemuMonitorMachineInfoPtr 
machine)
 
 int
 qemuMonitorGetCPUDefinitions(qemuMonitorPtr mon,
- qemuMonitorCPUDefInfoPtr **cpus)
+ qemuMonitorCPUDefsPtr *cpuDefs)
 {
-VIR_DEBUG("cpus=%p", cpus);
+VIR_DEBUG("cpuDefs=%p", cpuDefs);
 
 QEMU_CHECK_MONITOR(mon);
 
-return qemuMonitorJSONGetCPUDefinitions(mon, cpus);
+return qemuMonitorJSONGetCPUDefinitions(mon, cpuDefs);
 }
 
 
 void
-qemuMonitorCPUDefInfoFree(qemuMonitorCPUDefInfoPtr cpu)
+qemuMonitorCPUDefsFree(qemuMonitorCPUDefsPtr defs)
 {
-if (!cpu)
+size_t i;
+
+if (!defs)
 return;
 
-virStringListFree(cpu->blockers);
-VIR_FREE(cpu->name);
-VIR_FREE(cpu);
+for (i = 0; i < defs->ncpus; i++) {
+virStringListFree(defs->cpus[i]->blockers);
+VIR_FREE(defs->cpus[i]->name);
+VIR_FREE(defs->cpus[i]);
+}
+
+VIR_FREE(defs->cpus);
+VIR_FREE(defs);
+}
+
+
+qemuMonitorCPUDefsPtr
+qemuMonitorCPUDefsNew(size_t count)
+{
+VIR_AUTOPTR(qemuMonitorCPUDefs) defs = NULL;
+
+if (VIR_ALLOC(defs) < 0)
+return NULL;
+
+if (count > 0 && VIR_ALLOC_N(defs->cpus, count) < 0)
+return NULL;
+
+defs->ncpus = count;
+VIR_RETURN_PTR(defs);
 }
 
 
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 536ba7893b..359bbfca7f 100644
--- a/src/qemu/qemu_

[libvirt] [PATCH v2 15/31] qemu: Introduce virQEMUCapsCPUDefsToModels

2019-10-15 Thread Jiri Denemark
The function translates qemuMonitorCPUDefsPtr (used by QEMU caps probing
code) into virDomainCapsCPUModelsPtr used by domain capabilities.

Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- trivial rebase

 src/qemu/qemu_capabilities.c | 71 +---
 1 file changed, 42 insertions(+), 29 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e38ad03ab5..87ac9bacdc 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1887,6 +1887,41 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
 }
 
 
+static virDomainCapsCPUModelsPtr
+virQEMUCapsCPUDefsToModels(qemuMonitorCPUDefsPtr defs,
+   const char **modelWhitelist,
+   const char **modelBlacklist)
+{
+VIR_AUTOUNREF(virDomainCapsCPUModelsPtr) cpuModels = NULL;
+size_t i;
+
+if (!(cpuModels = virDomainCapsCPUModelsNew(defs->ncpus)))
+return NULL;
+
+for (i = 0; i < defs->ncpus; i++) {
+qemuMonitorCPUDefInfoPtr cpu = defs->cpus + i;
+virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
+
+if (modelWhitelist && !virStringListHasString(modelWhitelist, 
cpu->name))
+continue;
+
+if (modelBlacklist && virStringListHasString(modelBlacklist, 
cpu->name))
+continue;
+
+if (cpu->usable == VIR_TRISTATE_BOOL_YES)
+usable = VIR_DOMCAPS_CPU_USABLE_YES;
+else if (cpu->usable == VIR_TRISTATE_BOOL_NO)
+usable = VIR_DOMCAPS_CPU_USABLE_NO;
+
+if (virDomainCapsCPUModelsAdd(cpuModels, cpu->name,
+  usable, cpu->blockers) < 0)
+return NULL;
+}
+
+VIR_RETURN_PTR(cpuModels);
+}
+
+
 virDomainCapsCPUModelsPtr
 virQEMUCapsGetCPUDefinitions(virQEMUCapsPtr qemuCaps,
  virDomainVirtType type,
@@ -2458,19 +2493,15 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
virDomainCapsCPUModelsPtr *cpuModels)
 {
 VIR_AUTOPTR(qemuMonitorCPUDefs) defs = NULL;
-virDomainCapsCPUModelsPtr models = NULL;
 size_t i;
-int ret = -1;
 
 *cpuModels = NULL;
 
 if (qemuMonitorGetCPUDefinitions(mon, &defs) < 0)
 return -1;
 
-if (!defs) {
-ret = 0;
-goto cleanup;
-}
+if (!defs)
+return 0;
 
 /* QEMU 2.11 for Power renamed all CPU models to lower case, we need to
  * translate them back to libvirt's upper case model names. */
@@ -2479,7 +2510,7 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
 char **name;
 
 if (virCPUGetModels(arch, &libvirtModels) < 0)
-goto cleanup;
+return -1;
 
 for (name = libvirtModels; name && *name; name++) {
 for (i = 0; i < defs->ncpus; i++) {
@@ -2488,33 +2519,15 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon,
 
 VIR_FREE(defs->cpus[i].name);
 if (VIR_STRDUP(defs->cpus[i].name, *name) < 0)
-goto cleanup;
+return -1;
 }
 }
 }
 
-if (!(models = virDomainCapsCPUModelsNew(defs->ncpus)))
-goto cleanup;
-
-for (i = 0; i < defs->ncpus; i++) {
-virDomainCapsCPUUsable usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
-
-if (defs->cpus[i].usable == VIR_TRISTATE_BOOL_YES)
-usable = VIR_DOMCAPS_CPU_USABLE_YES;
-else if (defs->cpus[i].usable == VIR_TRISTATE_BOOL_NO)
-usable = VIR_DOMCAPS_CPU_USABLE_NO;
-
-if (virDomainCapsCPUModelsAddSteal(models, &defs->cpus[i].name, usable,
-   &defs->cpus[i].blockers) < 0)
-goto cleanup;
-}
-
-VIR_STEAL_PTR(*cpuModels, models);
-ret = 0;
+if (!(*cpuModels = virQEMUCapsCPUDefsToModels(defs, NULL, NULL)))
+return -1;
 
- cleanup:
-virObjectUnref(models);
-return ret;
+return 0;
 }
 
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 04/31] conf: Drop nameLen parameter from virDomainCapsCPUModelsAdd

2019-10-15 Thread Jiri Denemark
All callers use nameLen == -1 anyway.

Signed-off-by: Jiri Denemark 
Reviewed-by: Ján Tomko 
---

Notes:
Version 2:
- no change

 src/conf/domain_capabilities.c | 7 +++
 src/conf/domain_capabilities.h | 1 -
 src/qemu/qemu_capabilities.c   | 2 +-
 tests/cputest.c| 4 ++--
 4 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index 3224ec3f52..ab8ebb650d 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -171,7 +171,7 @@ virDomainCapsCPUModelsCopy(virDomainCapsCPUModelsPtr old)
 
 for (i = 0; i < old->nmodels; i++) {
 if (virDomainCapsCPUModelsAdd(cpuModels,
-  old->models[i].name, -1,
+  old->models[i].name,
   old->models[i].usable,
   old->models[i].blockers) < 0)
 goto error;
@@ -204,7 +204,7 @@ virDomainCapsCPUModelsFilter(virDomainCapsCPUModelsPtr old,
 continue;
 
 if (virDomainCapsCPUModelsAdd(cpuModels,
-  old->models[i].name, -1,
+  old->models[i].name,
   old->models[i].usable,
   old->models[i].blockers) < 0)
 goto error;
@@ -242,14 +242,13 @@ virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr 
cpuModels,
 int
 virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr cpuModels,
   const char *name,
-  ssize_t nameLen,
   virDomainCapsCPUUsable usable,
   char **blockers)
 {
 VIR_AUTOFREE(char *) nameCopy = NULL;
 VIR_AUTOSTRINGLIST blockersCopy = NULL;
 
-if (VIR_STRNDUP(nameCopy, name, nameLen) < 0)
+if (VIR_STRDUP(nameCopy, name) < 0)
 return -1;
 
 if (virStringListCopy(&blockersCopy, (const char **)blockers) < 0)
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index 3a92194602..e3bd8d423e 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -204,7 +204,6 @@ int 
virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr cpuModels,
char ***blockers);
 int virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr cpuModels,
   const char *name,
-  ssize_t nameLen,
   virDomainCapsCPUUsable usable,
   char **blockers);
 virDomainCapsCPUModelPtr
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index efd71d69c5..14939fc91d 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1879,7 +1879,7 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
 }
 
 for (i = 0; i < count; i++) {
-if (virDomainCapsCPUModelsAdd(cpus, name[i], -1, usable, NULL) < 0)
+if (virDomainCapsCPUModelsAdd(cpus, name[i], usable, NULL) < 0)
 return -1;
 }
 
diff --git a/tests/cputest.c b/tests/cputest.c
index e3937c6fd6..7f47e3b601 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -863,7 +863,7 @@ cpuTestUpdateLive(const void *arg)
 usable = hvModel->usable;
 }
 
-if (virDomainCapsCPUModelsAdd(models, expected->model, -1,
+if (virDomainCapsCPUModelsAdd(models, expected->model,
   usable, blockers) < 0)
 goto cleanup;
 
@@ -973,7 +973,7 @@ cpuTestInitModels(const char **list)
 return NULL;
 
 for (model = list; *model; model++) {
-if (virDomainCapsCPUModelsAdd(cpus, *model, -1,
+if (virDomainCapsCPUModelsAdd(cpus, *model,
   VIR_DOMCAPS_CPU_USABLE_UNKNOWN, NULL) < 
0)
 goto error;
 }
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2 14/31] qemu: Use VIR_AUTOFREE in virQEMUCapsLoadCPUModels

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
Reviewed-by: Ján Tomko 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c | 58 +++-
 1 file changed, 24 insertions(+), 34 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 442445aad9..e38ad03ab5 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3474,15 +3474,10 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
  virDomainVirtType type)
 {
 virDomainCapsCPUModelsPtr cpus = NULL;
-xmlNodePtr *nodes = NULL;
-char *str = NULL;
+VIR_AUTOFREE(xmlNodePtr *) nodes = NULL;
 size_t i;
 int n;
-int ret = -1;
 xmlNodePtr node;
-xmlNodePtr *blockerNodes = NULL;
-char **blockers = NULL;
-int nblockers;
 
 if (type == VIR_DOMAIN_VIRT_KVM)
 n = virXPathNodeSet("./cpu[@type='kvm']", ctxt, &nodes);
@@ -3492,16 +3487,14 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
 if (n < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to parse qemu capabilities cpus"));
-goto cleanup;
+return -1;
 }
 
-if (n == 0) {
-ret = 0;
-goto cleanup;
-}
+if (n == 0)
+return 0;
 
 if (!(cpus = virDomainCapsCPUModelsNew(n)))
-goto cleanup;
+return -1;
 
 if (type == VIR_DOMAIN_VIRT_KVM)
 qemuCaps->kvmCPUModels = cpus;
@@ -3510,19 +3503,24 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
 
 for (i = 0; i < n; i++) {
 int usable = VIR_DOMCAPS_CPU_USABLE_UNKNOWN;
-
-if ((str = virXMLPropString(nodes[i], "usable")) &&
-(usable = virDomainCapsCPUUsableTypeFromString(str)) < 0) {
+VIR_AUTOFREE(char *) strUsable = NULL;
+VIR_AUTOFREE(char *) name = NULL;
+VIR_AUTOFREE(xmlNodePtr *) blockerNodes = NULL;
+VIR_AUTOSTRINGLIST blockers = NULL;
+int nblockers;
+
+if ((strUsable = virXMLPropString(nodes[i], "usable")) &&
+(usable = virDomainCapsCPUUsableTypeFromString(strUsable)) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("unknown value '%s' in attribute 'usable'"), str);
-goto cleanup;
+   _("unknown value '%s' in attribute 'usable'"),
+   strUsable);
+return -1;
 }
-VIR_FREE(str);
 
-if (!(str = virXMLPropString(nodes[i], "name"))) {
+if (!(name = virXMLPropString(nodes[i], "name"))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing cpu name in QEMU capabilities cache"));
-goto cleanup;
+return -1;
 }
 
 node = ctxt->node;
@@ -3533,38 +3531,30 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
 if (nblockers < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to parse CPU blockers in QEMU 
capabilities"));
-goto cleanup;
+return -1;
 }
 
 if (nblockers > 0) {
 size_t j;
 
 if (VIR_ALLOC_N(blockers, nblockers + 1) < 0)
-goto cleanup;
+return -1;
 
 for (j = 0; j < nblockers; j++) {
 if (!(blockers[j] = virXMLPropString(blockerNodes[j], 
"name"))) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing blocker name in QEMU "
  "capabilities cache"));
-goto cleanup;
+return -1;
 }
 }
-VIR_FREE(blockerNodes);
 }
 
-if (virDomainCapsCPUModelsAddSteal(cpus, &str, usable, &blockers) < 0)
-goto cleanup;
+if (virDomainCapsCPUModelsAddSteal(cpus, &name, usable, &blockers) < 0)
+return -1;
 }
 
-ret = 0;
-
- cleanup:
-VIR_FREE(nodes);
-VIR_FREE(str);
-VIR_FREE(blockerNodes);
-virStringListFree(blockers);
-return ret;
+return 0;
 }
 
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2 24/31] qemu: Drop unused virQEMUCapsGetDefaultMachine

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/qemu/qemu_capabilities.c | 12 
 src/qemu/qemu_capabilities.h |  1 -
 2 files changed, 13 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index dd7ea9ae86..bd54c1751c 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2133,18 +2133,6 @@ const char 
*virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
 return name;
 }
 
-const char *
-virQEMUCapsGetDefaultMachine(virQEMUCapsPtr qemuCaps)
-{
-size_t i;
-
-for (i = 0; i < qemuCaps->nmachineTypes; i++) {
-if (qemuCaps->machineTypes[i].qemuDefault)
-return qemuCaps->machineTypes[i].name;
-}
-
-return NULL;
-}
 
 int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
  const char *name)
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index f5133d083d..feb6a9ecd0 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -602,7 +602,6 @@ bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
virCPUMode mode);
 const char *virQEMUCapsGetCanonicalMachine(virQEMUCapsPtr qemuCaps,
const char *name);
-const char *virQEMUCapsGetDefaultMachine(virQEMUCapsPtr qemuCaps);
 int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
  const char *name);
 bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 23/31] qemu: Introduce virQEMUCapsGetMachineDefaultCPU

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- fix crash with CPUs without type

 src/qemu/qemu_capabilities.c | 36 
 src/qemu/qemu_capabilities.h |  3 +++
 2 files changed, 39 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 33cd3491b2..dd7ea9ae86 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2179,6 +2179,42 @@ bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr 
qemuCaps,
 }
 
 
+const char *
+virQEMUCapsGetMachineDefaultCPU(virQEMUCapsPtr qemuCaps,
+const char *name,
+virDomainVirtType type)
+{
+qemuMonitorCPUDefsPtr defs;
+const char *cpuType = NULL;
+size_t i;
+
+if (type == VIR_DOMAIN_VIRT_KVM)
+defs = qemuCaps->kvmCPUModels;
+else
+defs = qemuCaps->tcgCPUModels;
+
+if (!name || !defs)
+return NULL;
+
+for (i = 0; i < qemuCaps->nmachineTypes; i++) {
+if (STREQ(qemuCaps->machineTypes[i].name, name)) {
+cpuType = qemuCaps->machineTypes[i].defaultCPU;
+break;
+}
+}
+
+if (!cpuType)
+return NULL;
+
+for (i = 0; i < defs->ncpus; i++) {
+if (STREQ_NULLABLE(defs->cpus[i].type, cpuType))
+return defs->cpus[i].name;
+}
+
+return NULL;
+}
+
+
 /**
  * virQEMUCapsSetGICCapabilities:
  * @qemuCaps: QEMU capabilities
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 923706c3bf..f5133d083d 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -607,6 +607,9 @@ int virQEMUCapsGetMachineMaxCpus(virQEMUCapsPtr qemuCaps,
  const char *name);
 bool virQEMUCapsGetMachineHotplugCpus(virQEMUCapsPtr qemuCaps,
   const char *name);
+const char *virQEMUCapsGetMachineDefaultCPU(virQEMUCapsPtr qemuCaps,
+const char *name,
+virDomainVirtType type);
 int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
size_t *nmachines,
virCapsGuestMachinePtr **machines);
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 26/31] conf: Define VIR_AUTOPTR for virCPUDef

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- no change

 src/conf/cpu_conf.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 30904fab95..230e75f077 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -151,6 +151,7 @@ virCPUDefFreeModel(virCPUDefPtr def);
 
 void
 virCPUDefFree(virCPUDefPtr def);
+VIR_DEFINE_AUTOPTR_FUNC(virCPUDef, virCPUDefFree);
 
 int ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
 virCPUDefCopyModel(virCPUDefPtr dst,
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 29/31] qemuxml2*test: Add test cases for default CPU models on s390x

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- new patch

 ...t-cpu-kvm-ccw-virtio-4.2.s390x-latest.args | 31 +++
 .../s390-default-cpu-kvm-ccw-virtio-4.2.xml   | 16 ++
 ...t-cpu-tcg-ccw-virtio-4.2.s390x-latest.args | 31 +++
 .../s390-default-cpu-tcg-ccw-virtio-4.2.xml   | 16 ++
 tests/qemuxml2argvtest.c  |  2 ++
 ...lt-cpu-kvm-ccw-virtio-4.2.s390x-latest.xml | 23 ++
 ...lt-cpu-tcg-ccw-virtio-4.2.s390x-latest.xml | 23 ++
 tests/qemuxml2xmltest.c   |  2 ++
 8 files changed, 144 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.args
 create mode 100644 
tests/qemuxml2argvdata/s390-default-cpu-kvm-ccw-virtio-4.2.xml
 create mode 100644 
tests/qemuxml2argvdata/s390-default-cpu-tcg-ccw-virtio-4.2.s390x-latest.args
 create mode 100644 
tests/qemuxml2argvdata/s390-default-cpu-tcg-ccw-virtio-4.2.xml
 create mode 100644 
tests/qemuxml2xmloutdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.xml
 create mode 100644 
tests/qemuxml2xmloutdata/s390-default-cpu-tcg-ccw-virtio-4.2.s390x-latest.xml

diff --git 
a/tests/qemuxml2argvdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.args 
b/tests/qemuxml2argvdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.args
new file mode 100644
index 00..d45a87e6ec
--- /dev/null
+++ 
b/tests/qemuxml2argvdata/s390-default-cpu-kvm-ccw-virtio-4.2.s390x-latest.args
@@ -0,0 +1,31 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-test \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-test/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-test/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-test/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-s390x \
+-name guest=test,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-test/master-key.aes \
+-machine s390-ccw-virtio-4.2,accel=kvm,usb=off,dump-guest-core=off \
+-m 256 \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 9aa4b45c-b9dd-45ef-91fe-862b27b4231f \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot strict=on \
+-device virtio-balloon-ccw,id=balloon0,devno=fe.0. \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/s390-default-cpu-kvm-ccw-virtio-4.2.xml 
b/tests/qemuxml2argvdata/s390-default-cpu-kvm-ccw-virtio-4.2.xml
new file mode 100644
index 00..405b53db7d
--- /dev/null
+++ b/tests/qemuxml2argvdata/s390-default-cpu-kvm-ccw-virtio-4.2.xml
@@ -0,0 +1,16 @@
+
+  test
+  9aa4b45c-b9dd-45ef-91fe-862b27b4231f
+  262144
+  262144
+  
+hvm
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu-system-s390x
+  
+
diff --git 
a/tests/qemuxml2argvdata/s390-default-cpu-tcg-ccw-virtio-4.2.s390x-latest.args 
b/tests/qemuxml2argvdata/s390-default-cpu-tcg-ccw-virtio-4.2.s390x-latest.args
new file mode 100644
index 00..3d31148613
--- /dev/null
+++ 
b/tests/qemuxml2argvdata/s390-default-cpu-tcg-ccw-virtio-4.2.s390x-latest.args
@@ -0,0 +1,31 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-test \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-test/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-test/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-test/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-s390x \
+-name guest=test,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-test/master-key.aes \
+-machine s390-ccw-virtio-4.2,accel=tcg,usb=off,dump-guest-core=off \
+-m 256 \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 9aa4b45c-b9dd-45ef-91fe-862b27b4231f \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot strict=on \
+-device virtio-balloon-ccw,id=balloon0,devno=fe.0. \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/s390-default-cpu-tcg-ccw-virtio-4.2.xml 
b/tests/qemuxml2argvdata/s390-default-cpu-tcg-ccw-virtio-4.2.xml
new file mode 100644
index 00..c6c92bb08a
--- /dev/null
+++ b/tests/qemuxml2argvdata/s390-default-cpu-tcg-ccw-virtio-4.2.xml
@@ -0,0 +1,16 @@
+
+  test
+  9aa4b45c-b9dd-45ef-91fe-862b27b4231f
+  262144
+  262144
+  
+hvm
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu-system-s390x
+  
+
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 7fb84fc950..e19f30ff15 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -3042,6 +3042,8 @@ mymain(void)
 DO_TEST_CAPS_ARCH_LATEST("ppc64-def

[libvirt] [PATCH v2 30/31] qemuxml2*test: Add test cases for default CPU models on x86_64

2019-10-15 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---

Notes:
Version 2:
- new patch

 ...-default-cpu-kvm-pc-4.2.x86_64-latest.args | 36 +++
 .../x86_64-default-cpu-kvm-pc-4.2.xml | 24 
 ...default-cpu-kvm-q35-4.2.x86_64-latest.args | 41 +
 .../x86_64-default-cpu-kvm-q35-4.2.xml| 24 
 ...-default-cpu-tcg-pc-4.2.x86_64-latest.args | 36 +++
 .../x86_64-default-cpu-tcg-pc-4.2.xml | 24 
 ...default-cpu-tcg-q35-4.2.x86_64-latest.args | 41 +
 .../x86_64-default-cpu-tcg-q35-4.2.xml| 24 
 tests/qemuxml2argvtest.c  |  4 ++
 ...4-default-cpu-kvm-pc-4.2.x86_64-latest.xml | 37 
 ...-default-cpu-kvm-q35-4.2.x86_64-latest.xml | 60 +++
 ...4-default-cpu-tcg-pc-4.2.x86_64-latest.xml | 37 
 ...-default-cpu-tcg-q35-4.2.x86_64-latest.xml | 60 +++
 tests/qemuxml2xmltest.c   |  4 ++
 14 files changed, 452 insertions(+)
 create mode 100644 
tests/qemuxml2argvdata/x86_64-default-cpu-kvm-pc-4.2.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/x86_64-default-cpu-kvm-pc-4.2.xml
 create mode 100644 
tests/qemuxml2argvdata/x86_64-default-cpu-kvm-q35-4.2.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/x86_64-default-cpu-kvm-q35-4.2.xml
 create mode 100644 
tests/qemuxml2argvdata/x86_64-default-cpu-tcg-pc-4.2.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/x86_64-default-cpu-tcg-pc-4.2.xml
 create mode 100644 
tests/qemuxml2argvdata/x86_64-default-cpu-tcg-q35-4.2.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/x86_64-default-cpu-tcg-q35-4.2.xml
 create mode 100644 
tests/qemuxml2xmloutdata/x86_64-default-cpu-kvm-pc-4.2.x86_64-latest.xml
 create mode 100644 
tests/qemuxml2xmloutdata/x86_64-default-cpu-kvm-q35-4.2.x86_64-latest.xml
 create mode 100644 
tests/qemuxml2xmloutdata/x86_64-default-cpu-tcg-pc-4.2.x86_64-latest.xml
 create mode 100644 
tests/qemuxml2xmloutdata/x86_64-default-cpu-tcg-q35-4.2.x86_64-latest.xml

diff --git 
a/tests/qemuxml2argvdata/x86_64-default-cpu-kvm-pc-4.2.x86_64-latest.args 
b/tests/qemuxml2argvdata/x86_64-default-cpu-kvm-pc-4.2.x86_64-latest.args
new file mode 100644
index 00..c7bef11f22
--- /dev/null
+++ b/tests/qemuxml2argvdata/x86_64-default-cpu-kvm-pc-4.2.x86_64-latest.args
@@ -0,0 +1,36 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-guest \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-guest/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-guest/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-guest/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-x86_64 \
+-name guest=guest,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-guest/master-key.aes \
+-machine pc-i440fx-4.2,accel=kvm,usb=off,dump-guest-core=off \
+-m 4096 \
+-overcommit mem-lock=off \
+-smp 4,sockets=4,cores=1,threads=1 \
+-uuid 1ccfd97d-5eb4-478a-bbe6-88d254c16db7 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-boot strict=on \
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
+-drive file=/var/lib/libvirt/images/guest.qcow2,format=qcow2,if=none,\
+id=drive-virtio-disk0 \
+-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x2,drive=drive-virtio-disk0,\
+id=virtio-disk0,bootindex=1 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/x86_64-default-cpu-kvm-pc-4.2.xml 
b/tests/qemuxml2argvdata/x86_64-default-cpu-kvm-pc-4.2.xml
new file mode 100644
index 00..ce432ef52f
--- /dev/null
+++ b/tests/qemuxml2argvdata/x86_64-default-cpu-kvm-pc-4.2.xml
@@ -0,0 +1,24 @@
+
+  guest
+  1ccfd97d-5eb4-478a-bbe6-88d254c16db7
+  4194304
+  4194304
+  4
+  
+hvm
+
+  
+  
+
+
+  
+  
+  
+/usr/bin/qemu-system-x86_64
+
+  
+  
+  
+
+  
+
diff --git 
a/tests/qemuxml2argvdata/x86_64-default-cpu-kvm-q35-4.2.x86_64-latest.args 
b/tests/qemuxml2argvdata/x86_64-default-cpu-kvm-q35-4.2.x86_64-latest.args
new file mode 100644
index 00..c65d29fc32
--- /dev/null
+++ b/tests/qemuxml2argvdata/x86_64-default-cpu-kvm-q35-4.2.x86_64-latest.args
@@ -0,0 +1,41 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-guest \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-guest/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-guest/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-guest/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-x86_64 \
+-name guest=guest,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-guest/master-key.aes \
+-machine pc-q35-4.2,accel=kvm,usb=off,dump-guest-core=off \
+-m 4096 \
+-overcommit mem-lock=off \
+-smp 4,sockets=4,core

[libvirt] [PATCH v2 31/31] qemu: Store default CPU in domain XML

2019-10-15 Thread Jiri Denemark
When starting a domain without a CPU model specified in the domain XML,
QEMU will choose a default one. Which is fine unless the domain gets
migrated to another host because libvirt doesn't perform any CPU ABI
checks and the virtual CPU provided by QEMU on the destination host can
differ from the one on the source host.

With QEMU 4.2.0 we can probe for the default CPU model used by QEMU for
a particular machine type and store it in the domain XML. This way the
chosen CPU model is more visible to users and libvirt will make sure
the guest will see the exact same CPU after migration.

Architecture specific notes
- aarch64: We only set the default CPU for TCG domains as KVM requires
  -cpu host to work.

- ppc64: (to be checked with QEMU developers) Default CPU data reported
  by QEMU is unusable for KVM. QEMU would effectively use -cpu host by
  default and it even rewrites typename of the current host CPU model to
  host-powerpc64-cpu. The default CPU type reported by query-machines is
  still power*-powerpc64-cpu, which may not even exist due to the
  changed typename. For example, on a Power8 host, power8 CPU model is
  of host-powerpc64-cpu type (according to query-cpu-definitions), while
  the default CPU type name for pseries-3.1 machine type is reported as
  power8_v2.0-powerpc64-cpu. What's even worse, pseries-4.2 says the
  default CPU type is power9_v2.0-powerpc64-cpu, which cannot be started
  on older host at all. So again, we only set the default CPU for TCG
  domains.

- s390x: (to be checked with QEMU developers) The default CPU is said to
  be "qemu", which works fine for TCG domains, but it doesn't work on
  KVM because QEMU complains that some features requested in the CPU
  model are not available.

- x86_64: The default CPU model (qemu64) is not runnable on any host
  with KVM, but in contrast to s390x QEMU just disables unavailable
  features and starts happily.

https://bugzilla.redhat.com/show_bug.cgi?id=1598151
https://bugzilla.redhat.com/show_bug.cgi?id=1598162
---

Notes:
This patch should not be merged yet as we need to confirm what to do
on s390x and ppc64 architectures.

Version 2:
- new test cases

 src/qemu/qemu_domain.c| 56 +++
 ...fault-cpu-tcg-virt-4.2.aarch64-latest.args |  1 +
 .../disk-cache.x86_64-latest.args |  1 +
 .../disk-cdrom-network.x86_64-latest.args |  1 +
 .../disk-cdrom-tray.x86_64-latest.args|  1 +
 .../disk-copy_on_read.x86_64-latest.args  |  1 +
 .../disk-detect-zeroes.x86_64-latest.args |  1 +
 .../disk-floppy-q35-2_11.x86_64-latest.args   |  1 +
 .../disk-floppy-q35-2_9.x86_64-latest.args|  1 +
 .../os-firmware-bios.x86_64-latest.args   |  1 +
 ...os-firmware-efi-secboot.x86_64-latest.args |  1 +
 .../os-firmware-efi.x86_64-latest.args|  1 +
 ...ault-cpu-tcg-pseries-2.7.ppc64-latest.args |  1 +
 ...ault-cpu-tcg-pseries-3.1.ppc64-latest.args |  1 +
 ...ault-cpu-tcg-pseries-4.2.ppc64-latest.args |  1 +
 ...t-cpu-tcg-ccw-virtio-4.2.s390x-latest.args |  1 +
 .../tpm-emulator-tpm2-enc.x86_64-latest.args  |  1 +
 .../tpm-emulator-tpm2.x86_64-latest.args  |  1 +
 .../tpm-emulator.x86_64-latest.args   |  1 +
 .../tseg-explicit-size.x86_64-latest.args |  1 +
 .../vhost-vsock-auto.x86_64-latest.args   |  1 +
 .../vhost-vsock.x86_64-latest.args|  1 +
 ...-default-cpu-kvm-pc-4.2.x86_64-latest.args |  1 +
 ...default-cpu-kvm-q35-4.2.x86_64-latest.args |  1 +
 ...-default-cpu-tcg-pc-4.2.x86_64-latest.args |  1 +
 ...default-cpu-tcg-q35-4.2.x86_64-latest.args |  1 +
 ...efault-cpu-tcg-virt-4.2.aarch64-latest.xml |  3 +
 .../os-firmware-bios.x86_64-latest.xml|  3 +
 .../os-firmware-efi-secboot.x86_64-latest.xml |  3 +
 .../os-firmware-efi.x86_64-latest.xml |  3 +
 ...fault-cpu-tcg-pseries-2.7.ppc64-latest.xml |  3 +
 ...fault-cpu-tcg-pseries-3.1.ppc64-latest.xml |  3 +
 ...fault-cpu-tcg-pseries-4.2.ppc64-latest.xml |  3 +
 ...lt-cpu-tcg-ccw-virtio-4.2.s390x-latest.xml |  3 +
 .../tpm-emulator-tpm2-enc.x86_64-latest.xml   |  3 +
 .../tpm-emulator-tpm2.x86_64-latest.xml   |  3 +
 .../tpm-emulator.x86_64-latest.xml|  3 +
 .../tpm-passthrough-crb.x86_64-latest.xml |  3 +
 .../tpm-passthrough.x86_64-latest.xml |  3 +
 ...4-default-cpu-kvm-pc-4.2.x86_64-latest.xml |  3 +
 ...-default-cpu-kvm-q35-4.2.x86_64-latest.xml |  3 +
 ...4-default-cpu-tcg-pc-4.2.x86_64-latest.xml |  3 +
 ...-default-cpu-tcg-q35-4.2.x86_64-latest.xml |  3 +
 43 files changed, 132 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 9dcba4ef38..438f003186 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4470,6 +4470,59 @@ qemuDomainDefVcpusPostParse(virDomainDefPtr def)
 }
 
 
+static int
+qemuDomainDefSetDefaultCPU(virDomainDefPtr def,
+   virQEMUCapsPtr qemuCaps)
+{
+VIR_AUTOPTR(virCPUDef) newCPU = NULL;
+virCPUDefPtr cpu = def->cpu;
+con

[libvirt] [PATCH] qemu: caps: Use unique key for domCaps caching

2019-10-15 Thread Cole Robinson
When searching qemuCaps->domCapsCache for existing domCaps data,
we check for a matching pair of arch+virttype+machine+emulator. However
for the hash table key we only use the machine string. So if the
cache already contains:

  x86_64 + kvm + pc + /usr/bin/qemu-kvm

But a new VM is defined with

  x86_64 + qemu + pc + /usr/bin/qemu-kvm

We correctly fail to find matching cached domCaps, but then attempt
to use a colliding key with virHashAddEntry

Fix this by building a hash key from the 4 values, not just machine

Signed-off-by: Cole Robinson 
---
qemu_domain.c validation should be affected, but it is covered up
by another bug, fixed here:
https://www.redhat.com/archives/libvir-list/2019-October/msg00708.html

 src/qemu/qemu_conf.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 08cd784054..64ac8cbdd3 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1396,6 +1396,8 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr 
driver,
 domCaps = virHashSearch(domCapsCache,
 virQEMUDriverSearchDomcaps, &data, NULL);
 if (!domCaps) {
+VIR_AUTOFREE(char *) key = NULL;
+
 /* hash miss, build new domcaps */
 if (!(domCaps = virDomainCapsNew(data.path, data.machine,
  data.arch, data.virttype)))
@@ -1406,7 +1408,14 @@ virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr 
driver,
   cfg->firmwares, cfg->nfirmwares) < 0)
 return NULL;
 
-if (virHashAddEntry(domCapsCache, machine, domCaps) < 0)
+if (virAsprintf(&key, "%d:%d:%s:%s",
+data.arch,
+data.virttype,
+NULLSTR(data.machine),
+NULLSTR(data.path)) < 0)
+return NULL;
+
+if (virHashAddEntry(domCapsCache, key, domCaps) < 0)
 return NULL;
 }
 
-- 
2.23.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2 2/6] qemu: use VIR_AUTOUNREF in qemuDomainDeviceDefValidate()

2019-10-15 Thread Cole Robinson
On 10/11/19 5:27 PM, Jonathon Jongsma wrote:
> This allows us to simplify the function and avoid jumping to 'cleanup'.
> 
> Signed-off-by: Jonathon Jongsma 
> ---
>  src/qemu/qemu_domain.c | 13 +
>  1 file changed, 5 insertions(+), 8 deletions(-)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index dc7568fe18..516ae7e444 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -7197,8 +7197,8 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef 
> *dev,
>  {
>  int ret = 0;
>  virQEMUDriverPtr driver = opaque;
> -virQEMUCapsPtr qemuCaps = NULL;
> -virDomainCapsPtr domCaps = NULL;
> +VIR_AUTOUNREF(virQEMUCapsPtr) qemuCaps = NULL;
> +VIR_AUTOUNREF(virDomainCapsPtr) domCaps = NULL;
>  
>  if (!(qemuCaps = virQEMUCapsCacheLookup(driver->qemuCapsCache,
>  def->emulator)))
> @@ -7208,13 +7208,13 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef 
> *dev,
> def->os.machine,
> def->os.arch,
> def->virtType)))
> -goto cleanup;
> +return -1;
> 

This patch actually uncovers a bug in the domcaps caching,
qemumemlocktest is failing. I sent a fix now and CCd you. Previously
even when this function failed, we would return 0; So this patch has a
side effect besides the cleanup.

I think you should move patch #3 before this and have it contain all the
bug fixing here. Then do the VIR_AUTOFREE cleanup on top, which should
be a no-op. Without cleaning up the function, the bug fixing will look a
bit weird:

if (!(qemuCaps = virQEMUBlah())) {
ret = -1;
goto cleanup;
}

That's due to this function being a little funky because it's using
'ret' as both the function return code, and to capture the return value
of functions we are calling. Elsewhere in libvirt we will use a separate
'int rc' to capture return values. Then the code is more like:

int ret = -1;
int rc;

if (foo() < 0)
goto cleanup;

if ((rc = bar()) < 0) {
ret = rc;
goto cleanup;
}

switch()...

ret = rc;
 cleanup:
return ret;


But after the VIR_AUTOFREE cleanup that distinction probably doesn't
matter, so if the bug fix is a bit ugly than IMO that's fine because the
VIR_AUTOFREE conversion will clean it up anyways

But, did you run the test suite on this series? There are the errors I
hit here, but there's also tons of qemuxml2xml breakage with caused by
the video validation move. Please make sure you run 'make check' and
'make syntax-check' on every commit in a series before sending. I'll
reply to the other patches with more info.

Thanks,
Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2 4/6] qemu: consolidate video validation

2019-10-15 Thread Cole Robinson
On 10/11/19 5:27 PM, Jonathon Jongsma wrote:
> Move video validation logic from qemuProcessStartValidateVideo() to
> qemuDomainDeviceDefValidateVideo() (which is in fact called from the
> aforementioned function).
> 

As mentioned in the other response, this patch adds a lot of test suite
breakage. By moving more validation from process start time to XML parse
time, it exposes that many test suite test cases do not have the full
list of capabilities specified that it would need to actually boot the
XML under test.

Most of the example failures are in qemuxml2xml test. Run
VIR_TEST_DEBUG=1 ./tests/qemuxml2xmltest to see each failure and the
associated error message. Most of these cases will just be adding the
associated CIRRUS or VGA qemuCaps to the list in qemuxml2xmltest.c. You
can also look at the same test case in qemuxml2argvtest.c and copy the
caps list from there.

Also this patch should be broken up even more IMO. Some ideas:

* Add a qemuDomainDeviceDefValidateVideoModel from the existing code
qemu_domain.c code, which should be a no-op
* Extend it to handle the vhostuser validation
* Move the video->accel validation to qemuDomainDeviceDefValidateVideo.
it may need to grow an extra check for backend != vhostuser because we
will be de-nesting it
* Move the remaining model validation to
qemuDomainDeviceDefValidateVideoModel

Some of that will also help split up the test suite breakage, rather
than requiring you to adjust them all at once in one patch.

Thanks,
Cole

> Signed-off-by: Jonathon Jongsma 
> ---
>  src/qemu/qemu_domain.c  | 172 +---
>  src/qemu/qemu_process.c |  62 ---
>  2 files changed, 107 insertions(+), 127 deletions(-)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index bc455e7da3..def90a0f7d 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -5706,83 +5706,125 @@ qemuDomainDeviceDefValidateHostdev(const 
> virDomainHostdevDef *hostdev,
>  
>  
>  static int
> -qemuDomainDeviceDefValidateVideo(const virDomainVideoDef *video)
> +qemuDomainDeviceDefValidateVideo(const virDomainVideoDef *video,
> + virQEMUCapsPtr qemuCaps)
>  {
> -switch ((virDomainVideoType) video->type) {
> -case VIR_DOMAIN_VIDEO_TYPE_NONE:
> -return 0;
> -case VIR_DOMAIN_VIDEO_TYPE_XEN:
> -case VIR_DOMAIN_VIDEO_TYPE_VBOX:
> -case VIR_DOMAIN_VIDEO_TYPE_PARALLELS:
> -case VIR_DOMAIN_VIDEO_TYPE_GOP:
> -case VIR_DOMAIN_VIDEO_TYPE_DEFAULT:
> -virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> -   _("video type '%s' is not supported with QEMU"),
> -   virDomainVideoTypeToString(video->type));
> -return -1;
> -case VIR_DOMAIN_VIDEO_TYPE_VGA:
> -case VIR_DOMAIN_VIDEO_TYPE_CIRRUS:
> -case VIR_DOMAIN_VIDEO_TYPE_VMVGA:
> -case VIR_DOMAIN_VIDEO_TYPE_QXL:
> -case VIR_DOMAIN_VIDEO_TYPE_VIRTIO:
> -case VIR_DOMAIN_VIDEO_TYPE_BOCHS:
> -case VIR_DOMAIN_VIDEO_TYPE_RAMFB:
> -case VIR_DOMAIN_VIDEO_TYPE_LAST:
> -break;
> -}
> -
> -if (!video->primary &&
> -video->type != VIR_DOMAIN_VIDEO_TYPE_QXL &&
> -video->type != VIR_DOMAIN_VIDEO_TYPE_VIRTIO) {
> -virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> -   _("video type '%s' is only valid as primary "
> - "video device"),
> -   virDomainVideoTypeToString(video->type));
> -return -1;
> -}
> -
> -if (video->accel && video->accel->accel2d == VIR_TRISTATE_SWITCH_ON) {
> -virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> -   _("qemu does not support the accel2d setting"));
> -return -1;
> -}
> -
> -if (video->type == VIR_DOMAIN_VIDEO_TYPE_QXL) {
> -if (video->vram > (UINT_MAX / 1024)) {
> -virReportError(VIR_ERR_OVERFLOW,
> -   _("value for 'vram' must be less than '%u'"),
> -   UINT_MAX / 1024);
> +if (video->backend == VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER) {
> +if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO &&
> +!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VHOST_USER_GPU)) {
> +virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> +   _("this QEMU does not support 'vhost-user' video 
> device"));
> +return -1;
> +}
> +} else {
> +switch ((virDomainVideoType) video->type) {
> +case VIR_DOMAIN_VIDEO_TYPE_NONE:
> +return 0;
> +case VIR_DOMAIN_VIDEO_TYPE_XEN:
> +case VIR_DOMAIN_VIDEO_TYPE_VBOX:
> +case VIR_DOMAIN_VIDEO_TYPE_PARALLELS:
> +case VIR_DOMAIN_VIDEO_TYPE_GOP:
> +case VIR_DOMAIN_VIDEO_TYPE_DEFAULT:
> +virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> +   _("video type '%s' is not supported with 
> QEMU"),
> +

Re: [libvirt] [PATCH 00/30] storagefile, security: qcow2 data_file support

2019-10-15 Thread Cole Robinson
On 10/15/19 3:56 AM, Han Han wrote:
> Hello Cole, one issue is found:
> The qcow2 data file XTTRs is not cleaned on external snapshot when
> -blockdev is not enabled
> 
> Versions:
> libvirt v5.8.0-134-g9d03e9adf1
> qemu-kvm-4.1.0-13.module+el8.1.0+4313+ef76ec61.x86_64
> 
> Steps:
> 1. Convert a OS image to qcow2&qcow2 data file:
> # qemu-img convert -O qcow2 -o
> data_file=/var/lib/libvirt/images/pc-data.raw,data_file_raw=on
> /var/lib/libvirt/images/pc.qcow2 /var/lib/libvirt/images/pc-data.qcow2
> 
> 2. Build and start libvirt source, start libvirt daemon:
> # make clean && CC=/usr/lib64/ccache/cc ./autogen.sh&&./configure
> --without-libssh --build=x86_64-redhat-linux-gnu
> --host=x86_64-redhat-linux-gnu --program-prefix=
> --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr
> --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc
> --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64
> --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib
> --mandir=/usr/share/man --infodir=/usr/share/info --with-qemu
> --without-openvz --without-lxc --without-vbox --without-libxl
> --with-sasl --with-polkit --with-libvirtd --without-phyp --with-esx
> --without-hyperv --without-vmware --without-xenapi --without-vz
> --without-bhyve --with-interface --with-network --with-storage-fs
> --with-storage-lvm --with-storage-iscsi --with-storage-iscsi-direct
> --with-storage-scsi --with-storage-disk --with-storage-mpath
> --with-storage-rbd --without-storage-sheepdog --with-storage-gluster
> --without-storage-zfs --without-storage-vstorage --with-numactl
> --with-numad --with-capng --without-fuse --with-netcf --with-selinux
> --with-selinux-mount=/sys/fs/selinux --without-apparmor --without-hal
> --with-udev --with-yajl --with-sanlock --with-libpcap --with-macvtap
> --with-audit --with-dtrace --with-driver-modules --with-firewalld
> --with-firewalld-zone --without-wireshark-dissector --without-pm-utils
> --with-nss-plugin '--with-packager=Unknown, 2019-08-19-12:13:01,
> lab.rhel8.me ' --with-packager-version=1.el8
> --with-qemu-user=qemu --with-qemu-group=qemu
> --with-tls-priority=@LIBVIRT,SYSTEM --enable-werror
> --enable-expensive-tests --with-init-script=systemd
> --without-login-shell && make -j8
> # LD_PRELOAD="$(find src -name '*.so.*'|tr '\n' ' ')" src/.libs/virtlogd
> # LD_PRELOAD="$(find src -name '*.so.*'|tr '\n' ' ')" LIBVIRT_DEBUG=3
> LIBVIRT_LOG_FILTERS="1:util 1:qemu 1:security"
> LIBVIRT_LOG_OUTPUTS="1:file:/tmp/libvirt_daemon.log" src/.libs/libvirtd
> 
> 3. Define and start an VM with the qcow2&qcow2 data file. Note that the
> -blockdev is not enabled
> # virsh define pc-data.xml
> # virsh start pc-data
> 
> 4. Create snapshot and check the data file XATTRs:
> # virsh snapshot-create-as pc-data s1 --no-metadata --disk-only
> # getfattr -m - -d /var/lib/libvirt/images/pc-data.raw
> getfattr: Removing leading '/' from absolute path names
> # file: var/lib/libvirt/images/pc-data.raw
> security.selinux="unconfined_u:object_r:svirt_image_t:s0:c775,c1011"
> trusted.libvirt.security.dac="+107:+107"
> trusted.libvirt.security.ref_dac="1"
> trusted.libvirt.security.ref_selinux="1"
> trusted.libvirt.security.selinux="unconfined_u:object_r:svirt_image_t:s0:c284,c367"
> trusted.libvirt.security.timestamp_dac="1563328069"
> trusted.libvirt.security.timestamp_selinux="1563328069"
> 
> Shutdown the VM. The XATTRs of data file is not changed.
> It is not expected. The XTTRs should not contain *.libvirt.*
> 
> Issue is not reproduced with -blockdev enabled:
> 
> ...
>   
>     
>     
>   
> 
> 
> See the libvirt daemon log and vm xml in attachment.

Nice catch! I will need to dig into this to figure out where the issue
is. Can you put this info into an upstream bug report in
product=Virtualization Tools  and I will get to it when I can

Thanks,
Cole

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [RFC 0/1] convert virStorageSource to GObject

2019-10-15 Thread Daniel P . Berrangé
On Tue, Oct 15, 2019 at 10:51:39AM -0300, Daniel Henrique Barboza wrote:
> 
> 
> On 10/15/19 9:55 AM, Daniel P. Berrangé wrote:
> > On Tue, Oct 15, 2019 at 09:42:45AM -0300, Daniel Henrique Barboza wrote:
> > > I was hoping to quickly re-send the qemu_driver cleanups I've
> > > sent some time ago, now using Glib. I started by attempting to
> > > change the first VIR_AUTOUNREF() call in qemu_driver.c to
> > > g_autoptr(), which happens to be a virStorageSourcePtr type,
> > > then I realized that it wasn't that simple.
> > It should be that simple with this commit:
> > 
> >commit 667ff797e8eb8d82f30ab430216a8d2eef6b915a
> >Author: Daniel P. Berrangé 
> >Date:   Fri Oct 4 17:14:10 2019 +0100
> > 
> >  src: add support for g_autoptr with virObject instances
> > 
> > we should be able to use g_autoptr for any virObject, without
> > having to lock-step convert to GObject.
> > 
> > What actual problem did you find ?
> 
> I failed to notice this commit. Just tried it again and it worked.
> 
> What happened yesterday was that I attempted to do a simple
> VIR_AUTOUNREF -> g_autopt replace, faced compile errors and then, since
> I didn't notice this commit about, I assumed "I guess I need to convert
> this guy to GObject".
> 
> In fact, the compile error happened because g_autoptr() does not operate
> with a 'Ptr' type - something that I learned only during the conversion
> process.

Yeah, you need to drop the 'Ptr' suffix in the type name when
converting to g_autoptr, as it adds the pointer itself.


> > > This is being sent as RFC because x-I am aware that docs/hacking.html
> > > mentions that we shouldn't mix up certain GLib macros with Libvirt
> > > ones, thus I am uncertain of whether I have messed up or not.
> > > 'make check' works, did a few sanity checks with libvirtd as
> > > well.
> > Yes, the need to not mix  g_auto* with VIR_AUTO*, is why I did commit
> > 667ff797e8eb8d82f30ab430216a8d2eef6b915a to let you use g_autoptr
> > with virObject, without first converting to GObject.
> 
> What if there are other object types in the same function  using the VIR
> macros?
> For example, inside qemu_driver.c: qemuDomainBlockCopyCommon:
> 
> 
>     VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg =
> virQEMUDriverGetConfig(driver);
>     const char *format = NULL;
>     bool mirror_reuse = !!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT);
>     bool mirror_shallow = !!(flags & VIR_DOMAIN_BLOCK_COPY_SHALLOW);
>     bool existing = mirror_reuse;
>     qemuBlockJobDataPtr job = NULL;
>     VIR_AUTOUNREF(virStorageSourcePtr) mirror = mirrorsrc;
>     bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
>     bool mirror_initialized = false;
>     VIR_AUTOPTR(qemuBlockStorageSourceChainData) data = NULL;
>     VIR_AUTOPTR(qemuBlockStorageSourceChainData) crdata = NULL;
> 
> 
> Let's say that I change the virStorageSourcePtr up there to
> 
>    g_autoptr(virStorageSource) mirror = mirrorsrc;
> 
> 
> As long as there are no VIR macros acting in the 'mirror' variable, is it to
> use g_autoptr
> there even when everyone else is using VIR_AUTO* macros?

You should change all variables in the method at the same time.
Both the VIR_AUTOUNEF calls here can use g_autoptr, as can the
two VIR_AUTOPTR calls.

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 :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 7/8] examples: Use G_N_ELEMENTS instead of ARRAY_CARDINALITY

2019-10-15 Thread Daniel P . Berrangé
On Tue, Oct 15, 2019 at 04:10:55PM +0200, Andrea Bolognani wrote:
> On Tue, 2019-10-15 at 14:21 +0200, Ján Tomko wrote:
> > We try to keep the example programs independent of libraries
> > other than libvirt.
> > 
> > Rename the locally defined ARRAY_CARDINALITY macro to G_N_ELEMENTS
> > which GLib provides, even though we don't actually include GLib.
> 
> [...]
> 
> > -#define ARRAY_CARDINALITY(Array) (sizeof(Array) / sizeof(*(Array)))
> > +#define G_N_ELEMENTS(Array) (sizeof(Array) / sizeof(*(Array)))
> 
> In this case, and in this case only, I think we should leave the name
> alone.
> 
> When we use GLib and simply provide our own implementation when using
> a version that's too old, the GLib name is obviously accurate, but in
> this specific case I think it's misleading and we should stick with
> the current one.

We do have the option to have our example programs use GLib instead
of plain C. If people are using libvirt from plain C, I'm inclined
to suggest they'd be wise to use GLib for the same reasons that it
is beneficial for libvirt to use GLib.

If they're not using GLib, they likely have enough C knowledge to
figure out what they must do from our examples anyway.

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 :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

  1   2   >