Re: [libvirt] [PATCH 4/4] apparmor: allow to preserve /dev mountpoints into qemu namespaces

2018-08-13 Thread Christian Ehrhardt
On Mon, Aug 13, 2018 at 7:11 PM Jamie Strandboge 
wrote:

> On Mon, 2018-08-13 at 16:39 +0200, Christian Ehrhardt wrote:
> > Libvirt now tries to preserve all mounts under /dev in qemu
> > namespaces.
> > The old rules only listed a set of known paths but those are no more
> > enough.
> >
> > I found some due to containers like /dev/.lxc/* and such but also
> > /dev/console
> > and /dev/net/tun.
> >
> > Libvirt is correct to do so, but we can no more predict the names
> > properly, so
> > we modify the rule to allow a wildcard based pattern matching what
> > libvirt does.
> >
> > Signed-off-by: Christian Ehrhardt 
> > ---
> >  examples/apparmor/usr.sbin.libvirtd | 16 +---
> >  1 file changed, 5 insertions(+), 11 deletions(-)
> >
> > diff --git a/examples/apparmor/usr.sbin.libvirtd
> > b/examples/apparmor/usr.sbin.libvirtd
> > index 3ff43c32a2..b2e38fe0ad 100644
> > --- a/examples/apparmor/usr.sbin.libvirtd
> > +++ b/examples/apparmor/usr.sbin.libvirtd
> > @@ -33,17 +33,11 @@
> >mount options=(rw,rslave)  -> /,
> >mount options=(rw, nosuid) -> /{var/,}run/libvirt/qemu/*.dev/,
> >
> > -  mount options=(rw, move) /dev/   ->
> > /{var/,}run/libvirt/qemu/*.dev/,
> > -  mount options=(rw, move) /dev/hugepages/ ->
> > /{var/,}run/libvirt/qemu/*.hugepages/,
> > -  mount options=(rw, move) /dev/mqueue/->
> > /{var/,}run/libvirt/qemu/*.mqueue/,
> > -  mount options=(rw, move) /dev/pts/   ->
> > /{var/,}run/libvirt/qemu/*.pts/,
> > -  mount options=(rw, move) /dev/shm/   ->
> > /{var/,}run/libvirt/qemu/*.shm/,
> > -
> > -  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.dev/   ->
> > /dev/,
> > -  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.hugepages/ ->
> > /dev/hugepages/,
> > -  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.mqueue/->
> > /dev/mqueue/,
> > -  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.pts/   ->
> > /dev/pts/,
> > -  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.shm/   ->
> > /dev/shm/,
> > +  # libvirt provides any mounts under /dev to qemu namespaces
> > +  mount options=(rw, move) /dev/ -> /{var/,}run/libvirt/qemu/*.dev/,
> > +  mount options=(rw, move) /dev/**{/,} ->
> > /{var/,}run/libvirt/qemu/*{/,},
>
> What are you trying to convey with this rule? As written, the '{/,}' is
> redundant since '**' will match that.
>

I had issues on the other end, with different paths being accessed
with/without trailing slash
  /{var/,}run/libvirt/qemu/*{/,},
So I added the trailing "with or without slash" part.
You are right, on the other end due to the unpredictable path I already had
** which will cover the trailing slash.
I can do a V2 without the trailing part on the side that has the "**"
already


> > +  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.dev/ -> /dev/,
> > +  mount options=(rw, move) /{var/,}run/libvirt/qemu/*{/,} ->
> > /dev/**{/,},
>
> ditto
>
> --
> Jamie Strandboge | http://www.canonical.com



-- 
Christian Ehrhardt
Software Engineer, Ubuntu Server
Canonical Ltd
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] news: Add support for MBA (Memory Bandwidth Allocation)

2018-08-13 Thread bing . niu
From: Bing Niu 

Signed-off-by: Bing Niu 
---
 docs/news.xml | 9 +
 1 file changed, 9 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index 2f0c010..c6d03f5 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -44,6 +44,15 @@
   iscsiadm. It support basic pool operations: checkPool and 
refreshPool.
 
   
+  
+
+  Add support for MBA (Memory Bandwidth Allocation technology)
+
+
+  Domain vCPU threads can now have allocated some parts of host memory
+  bandwidth by using the memorytune element in 
cputune.
+
+  
 
 
   
-- 
2.7.4

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


Re: [libvirt] [PATCH v3 00/12] PCI passthrough support on s390

2018-08-13 Thread Yi Min Zhao



在 2018/8/13 下午2:59, Cornelia Huck 写道:

On Mon, 13 Aug 2018 12:46:16 +0800
Yi Min Zhao  wrote:


Is there any comment? I expect comments from all of you.

Well, I don't have any objections from my side, but you need the
libvirt folks' opinion on this.

Thanks for your response!




在 2018/8/7 下午5:10, Yi Min Zhao 写道:

Abstract

The PCI representation in QEMU has recently been extended for S390
allowing configuration of zPCI attributes like uid (user-defined
identifier) and fid (PCI function identifier).
The details can be found here:
https://lists.gnu.org/archive/html/qemu-devel/2016-06/msg07262.html

To support the new zPCI feature of the S390 platform, two new XML
attributes, @uid and @fid, are introduced for device addresses of type
'pci', i.e.:

  
  

  
  


uid and fid are optional attributes. If they are defined by the user,
unique values within the guest domain must be used. If they are not
specified and the architecture requires them, they are automatically
generated with non-conflicting values.

Current implementation is the most seamless one for the user as it
unites the address specific data of a PCI device on one XML element.
It could accommodate both specifying our special parameters (uid and fid)
and re-using standard statements (domain, bus, slot and function) for
PCI devices. User can still specify bus/slot/function for the virtualized
PCI devices in the XML.

Thus uid/fid act as an extension to the PCI address and are stored in
a new structure 'virZPCIDeviceAddress' which is a member of common PCI
Address structure. Additionally, two hashtables are used for assignment
and reservation of uid/fid.

In support of extending the PCI address, a new PCI address extension flag is
introduced. This extension flag allows is not only dedicated for the S390
platform but also other architectures needing certain extensions to PCI
address space.

Code Base
=
commit in master:
087de2f5a3: docs: formatdomain: fix spacing before parentheses

Change Log
==
v2->v3:
1. Revise code style.
2. Update test cases.
3. Introduce qemuDomainCollectPCIAddressExtension() to collect PCI
 extension addresses.
4. Introduce virDeviceInfoPCIAddressExtensionPresent() to check if zPCI
 address exists.
5. Optimize zPCI address check logic.
6. Optimize passed parameters of zPCI addr alloc/release/reserve functions.
7. Report enum range error in qemuDomainDeviceSupportZPCI().
8. Update commit messages.

v1->v2:
1. Separate test commit and merge testcases into corresponding commits that
 introduce the functionalities firstly.
2. Spare some checks for zpci device.
3. Add vsock and controller support.
4. Add uin32 type schema.
5. Rename zpciuid and zpcifid to zpci_uid and zpci_fid.
6. Always return multibus support on S390.

Yi Min Zhao (12):
conf: Add definitions for 'uid' and 'fid' PCI address attributes
qemu: Introduce zPCI capability
conf: Introduce a new PCI address extension flag
qemu: Enable PCI multi bus for S390 guests
qemu: Auto add pci-root for s390/s390x guests
conf: Introduce address caching for PCI extensions
conf: Introduce parser, formatter for uid and fid
conf: Allocate/release 'uid' and 'fid' in PCI address
qemu: Generate and use zPCI device in QEMU command line
qemu: Add hotpluging support for PCI devices on S390 guests
docs: Add 'uid' and 'fid' information
news: Update news for PCI address extension attributes

   docs/formatdomain.html.in  |   9 +-
   docs/news.xml  |  11 +
   docs/schemas/basictypes.rng|  23 ++
   docs/schemas/domaincommon.rng  |   1 +
   src/conf/device_conf.c |  78 +
   src/conf/device_conf.h |   8 +
   src/conf/domain_addr.c | 379 
+
   src/conf/domain_addr.h |  29 ++
   src/conf/domain_conf.c |   6 +
   src/libvirt_private.syms   |   4 +
   src/qemu/qemu_capabilities.c   |   6 +
   src/qemu/qemu_capabilities.h   |   1 +
   src/qemu/qemu_command.c| 114 +++
   src/qemu/qemu_command.h|   4 +
   src/qemu/qemu_domain.c |   1 +
   src/qemu/qemu_domain_address.c | 204 ++-
   src/qemu/qemu_hotplug.c| 155 -
   src/util/virpci.h  |  13 +
   tests/qemucapabilitiesdata/caps_2.10.0.s390x.xml   |   1 +
   tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml   |   1 +
   tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml   |   1 +
   tests/qemucapabilitiesdata/caps_2.7.0.s390x.xml|   1 +
   tests/qemucapabilitiesdata/caps_2.8.0.s390x.xml|   1 +
   

Re: [libvirt] [PATCH v2 RESEND 00/17] Introduce RDT memory bandwidth allocation support

2018-08-13 Thread bing.niu



On 2018年08月14日 02:33, John Ferlan wrote:



On 07/30/2018 11:54 PM, bing.niu wrote:



On 2018年07月31日 06:14, John Ferlan wrote:



On 07/29/2018 11:12 PM, bing@intel.com wrote:

From: Bing Niu 

This series is to introduce RDT memory bandwidth allocation support
by extending
current virresctrl implementation.


[]

Bing Niu (17):
    util: Rename some functions of virresctrl
    util: Refactor virResctrlGetInfo in virresctrl
    util: Refactor virResctrlAllocFormat of virresctrl
    util: Add MBA capability information query to resctrl
    util: Add MBA check to virResctrlInfoGetCache
    util: Add MBA allocation to virresctrl
    util: Add MBA schemata parse and format methods
    util: Add support to calculate MBA utilization
    util: Introduce virResctrlAllocForeachMemory
    util: Introduce virResctrlAllocSetMemoryBandwidth
    conf: Rename cachetune to resctrl
    conf: Factor out vcpus parsing part from virDomainCachetuneDefParse
    conf: Factor out vcpus overlapping from virDomainCachetuneDefParse
    conf: Factor out virDomainResctrlDef update from
  virDomainCachetuneDefParse
    conf: Add support for memorytune XML processing for resctrl MBA
    conf: Add return value check to virResctrlAllocForeachCache
    conf: Add memory bandwidth allocation capability of host

   docs/formatdomain.html.in  |  39 +-
   docs/schemas/capability.rng    |  33 ++
   docs/schemas/domaincommon.rng  |  17 +
   src/conf/capabilities.c    | 107 
   src/conf/capabilities.h    |  11 +
   src/conf/domain_conf.c | 428
---
   src/conf/domain_conf.h |  10 +-
   src/libvirt_private.syms   |   6 +-
   src/qemu/qemu_domain.c |   2 +-
   src/qemu/qemu_process.c    |  18 +-
   src/util/virresctrl.c  | 611
+++--
   src/util/virresctrl.h  |  55 +-
   .../memorytune-colliding-allocs.xml    |  30 +
   .../memorytune-colliding-cachetune.xml |  32 ++
   tests/genericxml2xmlindata/memorytune.xml  |  33 ++
   tests/genericxml2xmltest.c |   5 +
   .../linux-resctrl/resctrl/info/MB/bandwidth_gran   |   1 +
   .../linux-resctrl/resctrl/info/MB/min_bandwidth    |   1 +
   .../linux-resctrl/resctrl/info/MB/num_closids  |   1 +
   tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml   |   8 +
   tests/virresctrldata/resctrl.schemata  |   1 +
   21 files changed, 1280 insertions(+), 169 deletions(-)
   create mode 100644
tests/genericxml2xmlindata/memorytune-colliding-allocs.xml
   create mode 100644
tests/genericxml2xmlindata/memorytune-colliding-cachetune.xml
   create mode 100644 tests/genericxml2xmlindata/memorytune.xml
   create mode 100644
tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/bandwidth_gran
   create mode 100644
tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/min_bandwidth
   create mode 100644
tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/num_closids



Reviewed-by: John Ferlan 
(series)

I'll push once the tree is open for 4.7.0 commits unless someone else
chimes in with other major issues that need to be addressed.





Tree re-opened after I left for a week away from the virtual world...
Now that I'm back and digging out of email, figured I'd sync this series
up with current top and push.

Please post a followup docs/news.xml article describing the change.


Thanks for this. I will cook a patch for this. :)


Tks -

John



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

Re: [libvirt] [PATCH 4/4] cpu: split x86 map data into separate files

2018-08-13 Thread John Ferlan


On 08/01/2018 01:02 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé 
> ---
>  src/cpu/cpu_map.xml  | 2374 +-
>  src/cpu/cpu_map_x86_486.xml  |7 +
>  src/cpu/cpu_map_x86_Broadwell-IBRS.xml   |   61 +
>  src/cpu/cpu_map_x86_Broadwell-noTSX-IBRS.xml |   59 +
>  src/cpu/cpu_map_x86_Broadwell-noTSX.xml  |   58 +
>  src/cpu/cpu_map_x86_Broadwell.xml|   60 +
>  src/cpu/cpu_map_x86_Conroe.xml   |   33 +
>  src/cpu/cpu_map_x86_EPYC-IBRS.xml|   73 +
>  src/cpu/cpu_map_x86_EPYC.xml |   72 +
>  src/cpu/cpu_map_x86_Haswell-IBRS.xml |   57 +
>  src/cpu/cpu_map_x86_Haswell-noTSX-IBRS.xml   |   55 +
>  src/cpu/cpu_map_x86_Haswell-noTSX.xml|   54 +
>  src/cpu/cpu_map_x86_Haswell.xml  |   56 +
>  src/cpu/cpu_map_x86_IvyBridge-IBRS.xml   |   51 +
>  src/cpu/cpu_map_x86_IvyBridge.xml|   50 +
>  src/cpu/cpu_map_x86_Nehalem-IBRS.xml |   38 +
>  src/cpu/cpu_map_x86_Nehalem.xml  |   37 +
>  src/cpu/cpu_map_x86_Opteron_G1.xml   |   31 +
>  src/cpu/cpu_map_x86_Opteron_G2.xml   |   35 +
>  src/cpu/cpu_map_x86_Opteron_G3.xml   |   40 +
>  src/cpu/cpu_map_x86_Opteron_G4.xml   |   50 +
>  src/cpu/cpu_map_x86_Opteron_G5.xml   |   53 +
>  src/cpu/cpu_map_x86_Penryn.xml   |   35 +
>  src/cpu/cpu_map_x86_SandyBridge-IBRS.xml |   45 +
>  src/cpu/cpu_map_x86_SandyBridge.xml  |   44 +
>  src/cpu/cpu_map_x86_Skylake-Client-IBRS.xml  |   70 +
>  src/cpu/cpu_map_x86_Skylake-Client.xml   |   69 +
>  src/cpu/cpu_map_x86_Skylake-Server-IBRS.xml  |   77 +
>  src/cpu/cpu_map_x86_Skylake-Server.xml   |   76 +
>  src/cpu/cpu_map_x86_Westmere-IBRS.xml|   39 +
>  src/cpu/cpu_map_x86_Westmere.xml |   38 +
>  src/cpu/cpu_map_x86_athlon.xml   |   28 +
>  src/cpu/cpu_map_x86_core2duo.xml |   33 +
>  src/cpu/cpu_map_x86_coreduo.xml  |   29 +
>  src/cpu/cpu_map_x86_cpu64-rhel5.xml  |   29 +
>  src/cpu/cpu_map_x86_cpu64-rhel6.xml  |   31 +
>  src/cpu/cpu_map_x86_features.xml |  440 
>  src/cpu/cpu_map_x86_kvm32.xml|   26 +
>  src/cpu/cpu_map_x86_kvm64.xml|   30 +
>  src/cpu/cpu_map_x86_n270.xml |   30 +
>  src/cpu/cpu_map_x86_pentium.xml  |   13 +
>  src/cpu/cpu_map_x86_pentium2.xml |   22 +
>  src/cpu/cpu_map_x86_pentium3.xml |   23 +
>  src/cpu/cpu_map_x86_pentiumpro.xml   |   21 +
>  src/cpu/cpu_map_x86_phenom.xml   |   36 +
>  src/cpu/cpu_map_x86_qemu32.xml   |   22 +
>  src/cpu/cpu_map_x86_qemu64.xml   |   40 +
>  src/cpu/cpu_map_x86_vendors.xml  |4 +
>  48 files changed, 2427 insertions(+), 2327 deletions(-)
>  create mode 100644 src/cpu/cpu_map_x86_486.xml
>  create mode 100644 src/cpu/cpu_map_x86_Broadwell-IBRS.xml
>  create mode 100644 src/cpu/cpu_map_x86_Broadwell-noTSX-IBRS.xml
>  create mode 100644 src/cpu/cpu_map_x86_Broadwell-noTSX.xml
>  create mode 100644 src/cpu/cpu_map_x86_Broadwell.xml
>  create mode 100644 src/cpu/cpu_map_x86_Conroe.xml
>  create mode 100644 src/cpu/cpu_map_x86_EPYC-IBRS.xml
>  create mode 100644 src/cpu/cpu_map_x86_EPYC.xml
>  create mode 100644 src/cpu/cpu_map_x86_Haswell-IBRS.xml
>  create mode 100644 src/cpu/cpu_map_x86_Haswell-noTSX-IBRS.xml
>  create mode 100644 src/cpu/cpu_map_x86_Haswell-noTSX.xml
>  create mode 100644 src/cpu/cpu_map_x86_Haswell.xml
>  create mode 100644 src/cpu/cpu_map_x86_IvyBridge-IBRS.xml
>  create mode 100644 src/cpu/cpu_map_x86_IvyBridge.xml
>  create mode 100644 src/cpu/cpu_map_x86_Nehalem-IBRS.xml
>  create mode 100644 src/cpu/cpu_map_x86_Nehalem.xml
>  create mode 100644 src/cpu/cpu_map_x86_Opteron_G1.xml
>  create mode 100644 src/cpu/cpu_map_x86_Opteron_G2.xml
>  create mode 100644 src/cpu/cpu_map_x86_Opteron_G3.xml
>  create mode 100644 src/cpu/cpu_map_x86_Opteron_G4.xml
>  create mode 100644 src/cpu/cpu_map_x86_Opteron_G5.xml
>  create mode 100644 src/cpu/cpu_map_x86_Penryn.xml
>  create mode 100644 src/cpu/cpu_map_x86_SandyBridge-IBRS.xml
>  create mode 100644 src/cpu/cpu_map_x86_SandyBridge.xml
>  create mode 100644 src/cpu/cpu_map_x86_Skylake-Client-IBRS.xml
>  create mode 100644 src/cpu/cpu_map_x86_Skylake-Client.xml
>  create mode 100644 src/cpu/cpu_map_x86_Skylake-Server-IBRS.xml
>  create mode 100644 src/cpu/cpu_map_x86_Skylake-Server.xml
>  create mode 100644 src/cpu/cpu_map_x86_Westmere-IBRS.xml
>  create mode 100644 src/cpu/cpu_map_x86_Westmere.xml
>  create mode 100644 src/cpu/cpu_map_x86_athlon.xml
>  create mode 100644 src/cpu/cpu_map_x86_core2duo.xml
>  create mode 100644 src/cpu/cpu_map_x86_coreduo.xml
>  create mode 100644 src/cpu/cpu_map_x86_cpu64-rhel5.xml
>  create mode 100644 src/cpu/cpu_map_x86_cpu64-rhel6.xml
>  create mode 100644 src/cpu/cpu_map_x86_features.xml
>  

Re: [libvirt] [PATCH 3/4] cpu: split PPC64 map data into separate files

2018-08-13 Thread John Ferlan


On 08/01/2018 01:02 PM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé 
> ---
>  src/cpu/cpu_map.xml | 41 +
>  src/cpu/cpu_map_ppc64_POWER6.xml|  6 
>  src/cpu/cpu_map_ppc64_POWER7.xml|  7 +
>  src/cpu/cpu_map_ppc64_POWER8.xml|  8 +
>  src/cpu/cpu_map_ppc64_POWER9.xml|  6 
>  src/cpu/cpu_map_ppc64_POWERPC_e5500.xml |  6 
>  src/cpu/cpu_map_ppc64_POWERPC_e6500.xml |  6 
>  src/cpu/cpu_map_ppc64_vendors.xml   |  4 +++
>  8 files changed, 50 insertions(+), 34 deletions(-)
>  create mode 100644 src/cpu/cpu_map_ppc64_POWER6.xml
>  create mode 100644 src/cpu/cpu_map_ppc64_POWER7.xml
>  create mode 100644 src/cpu/cpu_map_ppc64_POWER8.xml
>  create mode 100644 src/cpu/cpu_map_ppc64_POWER9.xml
>  create mode 100644 src/cpu/cpu_map_ppc64_POWERPC_e5500.xml
>  create mode 100644 src/cpu/cpu_map_ppc64_POWERPC_e6500.xml
>  create mode 100644 src/cpu/cpu_map_ppc64_vendors.xml
> 

Reviewed-by: John Ferlan 

John

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

Re: [libvirt] [PATCH 1/4] cpu: allow include files for CPU definition

2018-08-13 Thread John Ferlan


On 08/01/2018 01:02 PM, Daniel P. Berrangé wrote:
> Allow for syntax
> 
> 
> 
> to reference other files in the CPU database directory
> 
> Signed-off-by: Daniel P. Berrangé 
> ---
>  libvirt.spec.in   |  2 +-
>  mingw-libvirt.spec.in |  4 +--
>  src/Makefile.am   |  2 +-
>  src/cpu/cpu_map.c | 84 +--
>  4 files changed, 86 insertions(+), 6 deletions(-)
> 

I'll assume you got the spec/makefile magic correct as it's not in my
wheelhouse!



> diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c
> index d263eb8cdd..9e090919ed 100644
> --- a/src/cpu/cpu_map.c
> +++ b/src/cpu/cpu_map.c
> @@ -70,6 +70,83 @@ static int load(xmlXPathContextPtr ctxt,
>  return ret;
>  }
>  

[...]

> +
> +
> +static int loadIncludes(xmlXPathContextPtr ctxt,
> +cpuMapLoadCallback callback,
> +void *data)

static int
loadIncludes(...)

for consistency

> +{
> +int ret = -1;

[...]

>  
>  int cpuMapLoad(const char *arch,
> cpuMapLoadCallback cb,
> @@ -88,7 +165,7 @@ int cpuMapLoad(const char *arch,
>  PKGDATADIR)))
>  return -1;
>  
> -VIR_DEBUG("Loading CPU map from %s", mapfile);
> +VIR_DEBUG("Loading '%s' CPU map from %s", arch, mapfile);

Considering the subsequent NULL check:

s/arch/NULLSTR(arch)/

or move the VIR_DEBUG after the check (IDC).

I'm not even sure why @mapfile filling is above the argument validation
checks, but that's a different issue and since more changes are about to
come, it's not that important ;-)...  As long there is either a NULLSTR
or moved message, that's fine.

Reviewed-by: John Ferlan 

John

[...]

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

Re: [libvirt] [PATCH 2/4] cpu: push more parsing logic into common code

2018-08-13 Thread John Ferlan


On 08/01/2018 01:02 PM, Daniel P. Berrangé wrote:
> The x86 and ppc impls both duplicate some logic when parsing CPU
> features. Change the callback signature so that this duplication can be
> pushed up a level to common code.
> 
> Signed-off-by: Daniel P. Berrangé 
> ---
>  src/cpu/cpu_map.c   | 106 +++-
>  src/cpu/cpu_map.h   |  22 ++---
>  src/cpu/cpu_ppc64.c | 112 ++---
>  src/cpu/cpu_x86.c   | 196 +---
>  4 files changed, 155 insertions(+), 281 deletions(-)
> 
> diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c
> index 9e090919ed..17ed53fda6 100644
> --- a/src/cpu/cpu_map.c
> +++ b/src/cpu/cpu_map.c
> @@ -35,31 +35,51 @@
>  
>  VIR_LOG_INIT("cpu.cpu_map");
>  
> -VIR_ENUM_IMPL(cpuMapElement, CPU_MAP_ELEMENT_LAST,
> -"vendor",
> -"feature",
> -"model")
> -
> -
> -static int load(xmlXPathContextPtr ctxt,
> -cpuMapElement element,
> -cpuMapLoadCallback callback,
> -void *data)
> +static int
> +loadData(const char *mapfile,
> + xmlXPathContextPtr ctxt,
> + const char *xpath,
> + cpuMapLoadCallback callback,
> + void *data)
>  {
>  int ret = -1;
>  xmlNodePtr ctxt_node;
>  xmlNodePtr *nodes = NULL;
>  int n;
> +size_t i;
> +int rv;
>  
>  ctxt_node = ctxt->node;
>  
> -n = virXPathNodeSet(cpuMapElementTypeToString(element), ctxt, );
> -if (n < 0)
> +n = virXPathNodeSet(xpath, ctxt, );
> +if (n < 0) {
> +virReportError(VIR_ERR_INTERNAL_ERROR,
> +   _("cannot find '%s' in CPU map '%s'"), xpath, 
> mapfile);
>  goto cleanup;
> +}
>  
> -if (n > 0 &&
> -callback(element, ctxt, nodes, n, data) < 0)
> +if (n > 0 && !callback) {
> +virReportError(VIR_ERR_INTERNAL_ERROR,
> +   _("Unexpected %s in CPU map '%s'"), xpath, mapfile);

How about "Unexpected element %s..."

to be fair it's a callback function isn't provided for a specific arch,
but adding that level of detail would be a bit more painful for the low
level of benefit at least.

>  goto cleanup;
> +}
> +

[...]

>  
>  int cpuMapLoad(const char *arch,
> -   cpuMapLoadCallback cb,
> +   cpuMapLoadCallback vendorCB,
> +   cpuMapLoadCallback featureCB,
> +   cpuMapLoadCallback modelCB,
> void *data)
>  {
>  xmlDocPtr xml = NULL;
> @@ -157,7 +183,6 @@ int cpuMapLoad(const char *arch,
>  virBuffer buf = VIR_BUFFER_INITIALIZER;
>  char *xpath = NULL;
>  int ret = -1;
> -int element;
>  char *mapfile;
>  
>  if (!(mapfile = virFileFindResource("cpu_map.xml",
> @@ -173,9 +198,15 @@ int cpuMapLoad(const char *arch,
>  goto cleanup;
>  }
>  
> -if (cb == NULL) {
> +if (vendorCB == NULL) {
> +virReportError(VIR_ERR_INTERNAL_ERROR,
> +   "%s", _("no vendor callback provided"));
> +goto cleanup;
> +}

To be fair, loadData does check "if (n > 0 && !callback)", so these
checks perhaps aren't necessary as if they were NULL we'd fail a bit
later on (if I'm reading things properly ;-)).

I suppose it doesn't matter if they stay or not until someone, some day
wonders why featureCB isn't checked.

> +
> +if (modelCB == NULL) {
>  virReportError(VIR_ERR_INTERNAL_ERROR,
> -   "%s", _("no callback provided"));
> +   "%s", _("no model callback provided"));
>  goto cleanup;
>  }
>  

[...]

> diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c
> index d562677fa3..75da5b77d8 100644
> --- a/src/cpu/cpu_ppc64.c
> +++ b/src/cpu/cpu_ppc64.c
> @@ -281,21 +281,19 @@ ppc64MapFree(struct ppc64_map *map)
>  VIR_FREE(map);
>  }
>  

[...]

>  ppc64ModelParse(xmlXPathContextPtr ctxt,
> -struct ppc64_map *map)
> +const char *name,
> +void *data)
>  {
> +struct ppc64_map *map = data;
>  struct ppc64_model *model;
>  xmlNodePtr *nodes = NULL;
>  char *vendor = NULL;
>  unsigned long pvr;
>  size_t i;
>  int n;
> +int ret = -1;
>  
>  if (VIR_ALLOC(model) < 0)
>  goto error;
>  
> -model->name = virXPathString("string(@name)", ctxt);
> -if (!model->name) {
> -virReportError(VIR_ERR_INTERNAL_ERROR,
> -   "%s", _("Missing CPU model name"));
> +if (VIR_STRDUP(model->name, name) < 0)
>  goto error;
> -}
>  
>  if (ppc64ModelFind(map, model->name)) {
>  virReportError(VIR_ERR_INTERNAL_ERROR,
> @@ -410,63 +387,22 @@ ppc64ModelParse(xmlXPathContextPtr ctxt,
>  model->data.pvr[i].mask = pvr;
>  }
>  
> +if (VIR_APPEND_ELEMENT(map->models, map->nmodels, model) < 0)
> +goto error;
> +

Since VIR_APPEND_ELEMENT would clear @model on success, we don't
necessarily need the error and cleanup labels. More 

Re: [libvirt] [PATCH 2/2] esx:Fix esxDomainGetMaxVcpus to return correct vcpus

2018-08-13 Thread Matthias Bolte
2018-08-10 5:56 GMT+02:00 Marcos Paulo de Souza :
> Before this change, esxDomainGetMaxVcpus returned -1, which in turn
> fails in libvirt. This commit reimplements esxDomainGetMaxVcpus instead
> of calling esxDomainGetVcpusFlags. The implementation checks for
> capability.maxSupportedVcpus, but as this one can be ommited in ESXi, we
> also check for capability.maxHostSupportedVcpus. With this change,
> virDomainSetVcpus, virDomainGetMaxVcpus and virDomainGetVcpusFlags and
> returning correct values.
>
> Signed-off-by: Marcos Paulo de Souza 
> ---
>  src/esx/esx_driver.c | 36 ++--
>  1 file changed, 34 insertions(+), 2 deletions(-)
>
> diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
> index d5e8a7b4eb..3169314fa4 100644
> --- a/src/esx/esx_driver.c
> +++ b/src/esx/esx_driver.c
> @@ -2581,8 +2581,40 @@ esxDomainGetVcpusFlags(virDomainPtr domain, unsigned 
> int flags)
>  static int
>  esxDomainGetMaxVcpus(virDomainPtr domain)
>  {
> -return esxDomainGetVcpusFlags(domain, (VIR_DOMAIN_AFFECT_LIVE |
> -   VIR_DOMAIN_VCPU_MAXIMUM));
> +esxPrivate *priv = domain->conn->privateData;
> +esxVI_String *propertyNameList = NULL;
> +esxVI_ObjectContent *hostSystem = NULL;
> +esxVI_Int *supportedVcpus = NULL;
> +esxVI_Int *hostVcpus = NULL;
> +
> +if (esxVI_EnsureSession(priv->primary) < 0)
> +return -1;
> +
> +priv->maxVcpus = -1;
> +
> +if (esxVI_String_AppendValueToList(,
> +   
> "capability.maxHostSupportedVcpus\0"
> +   "capability.maxSupportedVcpus"
> +  ) < 0 ||
> +esxVI_LookupHostSystemProperties(priv->primary, propertyNameList,
> +  ) < 0 ||
> +esxVI_GetInt(hostSystem, "capability.maxHostSupportedVcpus",
> +  , esxVI_Occurrence_RequiredItem) < 0 ||
> +esxVI_GetInt(hostSystem, "capability.maxSupportedVcpus",
> +  , esxVI_Occurrence_OptionalItem) < 0)
> +
> +goto cleanup;
> +
> +/* as maxSupportedVcpus is optional, check also for 
> maxHostSupportedVcpus */
> +priv->maxVcpus = supportedVcpus ? supportedVcpus->value : 
> hostVcpus->value;
> +
> + cleanup:
> +esxVI_String_Free();
> +esxVI_ObjectContent_Free();
> +esxVI_Int_Free();
> +esxVI_Int_Free();
> +
> +return priv->maxVcpus;
>  }

This is the wrong way to fix the situation. The correct way ist to
make esxDomainGetVcpusFlags handle the VIR_DOMAIN_VCPU_MAXIMUM flag
properly.

-- 
Matthias Bolte
http://photron.blogspot.com

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


Re: [libvirt] [PATCH 1/2] esx: Make esxDomainGetVcpusFlags return vcpus again

2018-08-13 Thread Matthias Bolte
2018-08-10 5:56 GMT+02:00 Marcos Paulo de Souza :
> Before this patch, esxDomainGetVcpusFlags was returning -1 since
> "maxSupportedVcpus" can be NULL in ESXi[1]. In order to make it work,
> replicate the same behavior than esxDomainGetInfo that used
> config.hardware.numCPU to return the correct number of vcpus of a VM.
>
> This patch, together with the next one, makes the calls
> virDomainSetVcpus, virDomainGetMaxVcpus and virDomainGetVcpusFlags to
> return successfull again.
>
> [1]:https://pubs.vmware.com/vi-sdk/visdk250/ReferenceGuide/vim.host.Capability.html
>
> Signed-off-by: Marcos Paulo de Souza 
> ---
>  src/esx/esx_driver.c | 36 +++-
>  1 file changed, 11 insertions(+), 25 deletions(-)


Before and after this commit the function did not properly handle the
VIR_DOMAIN_VCPU_MAXIMUM flag. If the flag is present then the function
should return the maximum vCPU Count. If the flag is absent then it
should return the current vCPU count.

-- 
Matthias Bolte
http://photron.blogspot.com

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


Re: [libvirt] [PATCH 0/1] bhyve: Make LPC slot number configurable

2018-08-13 Thread no-reply
Hi,

This series was run against 'syntax-check' test by patchew.org, which failed, 
please find the details below:

Type: series
Message-id: 20180810112233.44540-1-i...@conquex.com
Subject: [libvirt] [PATCH 0/1] bhyve: Make LPC slot number configurable

=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with
# HEAD pointing to a commit that has the patches applied on top of "base"
# branch
time bash -c './autogen.sh && make syntax-check'
=== TEST SCRIPT END ===

Updating bcb55ab053bc79561b55d0394490f4b64e0f2d01
Switched to a new branch 'test'
e0ac4cf637 bhyve: Make LPC slot number configurable

=== OUTPUT BEGIN ===
Updating submodules...
Submodule 'gnulib' (https://git.savannah.gnu.org/git/gnulib.git/) registered 
for path '.gnulib'
Submodule 'keycodemapdb' (https://gitlab.com/keycodemap/keycodemapdb.git) 
registered for path 'src/keycodemapdb'
Cloning into '/var/tmp/patchew-tester-tmp-fryj5ja2/src/.gnulib'...
Cloning into '/var/tmp/patchew-tester-tmp-fryj5ja2/src/src/keycodemapdb'...
Submodule path '.gnulib': checked out '68df637b5f1b5c10370f6981d2a43a5cf74368df'
Submodule path 'src/keycodemapdb': checked out 
'16e5b0787687d8904dad2c026107409eb9bfcb95'
Running bootstrap...
./bootstrap: Bootstrapping from checked-out libvirt sources...
./bootstrap: consider installing git-merge-changelog from gnulib
./bootstrap: getting gnulib files...
running: libtoolize --install --copy
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/config.guess'
libtoolize: copying file 'build-aux/config.sub'
libtoolize: copying file 'build-aux/install-sh'
libtoolize: copying file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
./bootstrap: .gnulib/gnulib-tool--no-changelog   --aux-dir=build-aux   
--doc-base=doc   --lib=libgnu   --m4-base=m4/   --source-base=gnulib/lib/   
--tests-base=gnulib/tests   --local-dir=gnulib/local--lgpl=2 --with-tests 
--makefile-name=gnulib.mk --avoid=pt_chown --avoid=lock-tests   --libtool 
--import ...
Module list with included dependencies (indented):
absolute-header
  accept
accept-tests
alloca
alloca-opt
alloca-opt-tests
allocator
  areadlink
areadlink-tests
arpa_inet
arpa_inet-tests
assure
  autobuild
  base64
base64-tests
binary-io
binary-io-tests
  bind
bind-tests
  bitrotate
bitrotate-tests
btowc
btowc-tests
builtin-expect
  byteswap
byteswap-tests
  c-ctype
c-ctype-tests
  c-strcase
c-strcase-tests
  c-strcasestr
c-strcasestr-tests
  calloc-posix
  canonicalize-lgpl
canonicalize-lgpl-tests
careadlinkat
  chown
chown-tests
  clock-time
cloexec
cloexec-tests
  close
close-tests
  configmake
  connect
connect-tests
  count-leading-zeros
count-leading-zeros-tests
  count-one-bits
count-one-bits-tests
ctype
ctype-tests
  dirname-lgpl
dosname
double-slash-root
dup
dup-tests
dup2
dup2-tests
  environ
environ-tests
errno
errno-tests
error
  execinfo
exitfail
extensions
extern-inline
fatal-signal
  fclose
fclose-tests
  fcntl
  fcntl-h
fcntl-h-tests
fcntl-tests
fd-hook
  fdatasync
fdatasync-tests
fdopen
fdopen-tests
fflush
fflush-tests
  ffs
ffs-tests
  ffsl
ffsl-tests
fgetc-tests
filename
flexmember
float
float-tests
  fnmatch
fnmatch-tests
fpieee
fpucw
fpurge
fpurge-tests
fputc-tests
fread-tests
freading
freading-tests
fseek
fseek-tests
fseeko
fseeko-tests
fstat
fstat-tests
  fsync
fsync-tests
ftell
ftell-tests
ftello
ftello-tests
ftruncate
ftruncate-tests
  func
func-tests
fwrite-tests
  getaddrinfo
getaddrinfo-tests
  getcwd-lgpl
getcwd-lgpl-tests
getdelim
getdelim-tests
getdtablesize
getdtablesize-tests
getgroups
getgroups-tests
  gethostname
gethostname-tests
getline
getline-tests
  getopt-posix
getopt-posix-tests
getpagesize
  getpass
  getpeername
getpeername-tests
getprogname
getprogname-tests
  getsockname
getsockname-tests
getsockopt
getsockopt-tests
gettext-h
  gettimeofday
gettimeofday-tests
getugroups
  gitlog-to-changelog
  gnumakefile
grantpt
grantpt-tests
hard-locale
havelib
host-cpu-c-abi
hostent
  ignore-value
ignore-value-tests
include_next
inet_ntop
inet_ntop-tests
  inet_pton
inet_pton-tests
  intprops
intprops-tests
inttypes
inttypes-incomplete
inttypes-tests
  ioctl
ioctl-tests
  isatty
isatty-tests
isblank
isblank-tests

Re: [libvirt] [PATCH v3 02/11] util: netlink: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC

2018-08-13 Thread John Ferlan



On 08/13/2018 07:42 AM, Erik Skultety wrote:
> On Thu, Aug 09, 2018 at 09:42:10AM +0530, Sukrit Bhatnagar wrote:
>> Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in
>> src/util/viralloc.h, define a new wrapper around an existing
>> cleanup function which will be called when a variable declared
>> with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant
>> viralloc.h include, since that has moved from the source module into
>> the header.
>>
>> This commit also typedefs virNlMsg to struct nl_msg type for use
>> with the cleanup macros.
>>
>> When a variable of type virNlMsg * is declared using VIR_AUTOPTR,
>> the function nlmsg_free will be run automatically on it when it
>> goes out of scope.
>>
>> Signed-off-by: Sukrit Bhatnagar 
>> ---
>>  src/util/virnetlink.c | 1 -
>>  src/util/virnetlink.h | 5 +
>>  2 files changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
>> index 162efe6..ecf62c9 100644
>> --- a/src/util/virnetlink.c
>> +++ b/src/util/virnetlink.c
>> @@ -38,7 +38,6 @@
>>  #include "virnetlink.h"
>>  #include "virnetdev.h"
>>  #include "virlog.h"
>> -#include "viralloc.h"
>>  #include "virthread.h"
>>  #include "virmacaddr.h"
>>  #include "virerror.h"
>> diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h
>> index 2a9de0a..8ebeab8 100644
>> --- a/src/util/virnetlink.h
>> +++ b/src/util/virnetlink.h
>> @@ -22,6 +22,7 @@
>>
>>  # include "internal.h"
>>  # include "virmacaddr.h"
>> +# include "viralloc.h"
>>
>>  # if defined(__linux__) && defined(HAVE_LIBNL)
>>
>> @@ -44,6 +45,8 @@ struct nlmsghdr;
>>
>>  # endif /* __linux__ */
>>
>> +typedef struct nl_msg virNlMsg;
> 
> Since the name of the module is virNetlink, I'll rename this to virNetlinkMsg
> and tweak all the affected places across the whole series.
> 
> Reviewed-by: Erik Skultety 
> 
>> +
>>  int virNetlinkStartup(void);
>>  void virNetlinkShutdown(void);
>>
>> @@ -123,4 +126,6 @@ int 
>> virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB,
>>  int virNetlinkEventRemoveClient(int watch, const virMacAddr *macaddr,
>>  unsigned int protocol);
>>
>> +VIR_DEFINE_AUTOPTR_FUNC(virNlMsg, nlmsg_free)
>> +

The freebsd builds are not very happy, for example from...

https://ci.centos.org/view/libvirt/job/libvirt-master-build/systems=libvirt-freebsd-11/1675/

One gets:

...
  CC   util/libvirt_nss_la-viratomic.lo
In file included from ../../src/network/bridge_driver.c:63:
../../src/util/virnetlink.h:129:40: error: use of undeclared identifier
'nlmsg_free'
VIR_DEFINE_AUTOPTR_FUNC(virNetlinkMsg, nlmsg_free)
   ^
1 error generated.


John

>>  #endif /* __VIR_NETLINK_H__ */
>> --
>> 1.8.3.1
>>
>> --
>> libvir-list mailing list
>> libvir-list@redhat.com
>> https://www.redhat.com/mailman/listinfo/libvir-list
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
> 

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


Re: [libvirt] [PATCH 0/2] esx: Fix {g,s}et vcpus

2018-08-13 Thread no-reply
Hi,

This series was run against 'syntax-check' test by patchew.org, which failed, 
please find the details below:

Type: series
Message-id: 20180810035658.13555-1-marcos.souza@gmail.com
Subject: [libvirt] [PATCH 0/2] esx: Fix {g,s}et vcpus

=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with
# HEAD pointing to a commit that has the patches applied on top of "base"
# branch
time bash -c './autogen.sh && make syntax-check'
=== TEST SCRIPT END ===

Updating bcb55ab053bc79561b55d0394490f4b64e0f2d01
>From https://github.com/patchew-project/libvirt
   7995fecc25..d8826129fd  master -> master
Switched to a new branch 'test'
296fc25a8f esx:Fix esxDomainGetMaxVcpus to return correct vcpus
25939eab7b esx: Make esxDomainGetVcpusFlags return vcpus again

=== OUTPUT BEGIN ===
Updating submodules...
Submodule 'gnulib' (https://git.savannah.gnu.org/git/gnulib.git/) registered 
for path '.gnulib'
Submodule 'keycodemapdb' (https://gitlab.com/keycodemap/keycodemapdb.git) 
registered for path 'src/keycodemapdb'
Cloning into '/var/tmp/patchew-tester-tmp-75anuei6/src/.gnulib'...
Cloning into '/var/tmp/patchew-tester-tmp-75anuei6/src/src/keycodemapdb'...
Submodule path '.gnulib': checked out '68df637b5f1b5c10370f6981d2a43a5cf74368df'
Submodule path 'src/keycodemapdb': checked out 
'16e5b0787687d8904dad2c026107409eb9bfcb95'
Running bootstrap...
./bootstrap: Bootstrapping from checked-out libvirt sources...
./bootstrap: consider installing git-merge-changelog from gnulib
./bootstrap: getting gnulib files...
running: libtoolize --install --copy
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/config.guess'
libtoolize: copying file 'build-aux/config.sub'
libtoolize: copying file 'build-aux/install-sh'
libtoolize: copying file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
./bootstrap: .gnulib/gnulib-tool--no-changelog   --aux-dir=build-aux   
--doc-base=doc   --lib=libgnu   --m4-base=m4/   --source-base=gnulib/lib/   
--tests-base=gnulib/tests   --local-dir=gnulib/local--lgpl=2 --with-tests 
--makefile-name=gnulib.mk --avoid=pt_chown --avoid=lock-tests   --libtool 
--import ...
Module list with included dependencies (indented):
absolute-header
  accept
accept-tests
alloca
alloca-opt
alloca-opt-tests
allocator
  areadlink
areadlink-tests
arpa_inet
arpa_inet-tests
assure
  autobuild
  base64
base64-tests
binary-io
binary-io-tests
  bind
bind-tests
  bitrotate
bitrotate-tests
btowc
btowc-tests
builtin-expect
  byteswap
byteswap-tests
  c-ctype
c-ctype-tests
  c-strcase
c-strcase-tests
  c-strcasestr
c-strcasestr-tests
  calloc-posix
  canonicalize-lgpl
canonicalize-lgpl-tests
careadlinkat
  chown
chown-tests
  clock-time
cloexec
cloexec-tests
  close
close-tests
  configmake
  connect
connect-tests
  count-leading-zeros
count-leading-zeros-tests
  count-one-bits
count-one-bits-tests
ctype
ctype-tests
  dirname-lgpl
dosname
double-slash-root
dup
dup-tests
dup2
dup2-tests
  environ
environ-tests
errno
errno-tests
error
  execinfo
exitfail
extensions
extern-inline
fatal-signal
  fclose
fclose-tests
  fcntl
  fcntl-h
fcntl-h-tests
fcntl-tests
fd-hook
  fdatasync
fdatasync-tests
fdopen
fdopen-tests
fflush
fflush-tests
  ffs
ffs-tests
  ffsl
ffsl-tests
fgetc-tests
filename
flexmember
float
float-tests
  fnmatch
fnmatch-tests
fpieee
fpucw
fpurge
fpurge-tests
fputc-tests
fread-tests
freading
freading-tests
fseek
fseek-tests
fseeko
fseeko-tests
fstat
fstat-tests
  fsync
fsync-tests
ftell
ftell-tests
ftello
ftello-tests
ftruncate
ftruncate-tests
  func
func-tests
fwrite-tests
  getaddrinfo
getaddrinfo-tests
  getcwd-lgpl
getcwd-lgpl-tests
getdelim
getdelim-tests
getdtablesize
getdtablesize-tests
getgroups
getgroups-tests
  gethostname
gethostname-tests
getline
getline-tests
  getopt-posix
getopt-posix-tests
getpagesize
  getpass
  getpeername
getpeername-tests
getprogname
getprogname-tests
  getsockname
getsockname-tests
getsockopt
getsockopt-tests
gettext-h
  gettimeofday
gettimeofday-tests
getugroups
  gitlog-to-changelog
  gnumakefile
grantpt
grantpt-tests
hard-locale
havelib
host-cpu-c-abi
hostent
  ignore-value
ignore-value-tests
include_next
inet_ntop
inet_ntop-tests
  inet_pton
inet_pton-tests
  intprops
 

Re: [libvirt] [PATCH] esx: Fix build when libcurl debug is enabled

2018-08-13 Thread Michal Prívozník
On 08/10/2018 12:18 PM, Marcos Paulo de Souza wrote:
> On Mon, Aug 13, 2018 at 03:51:51PM +0200, Michal Prívozník wrote:
>> On 08/11/2018 04:39 PM, Marcos Paulo de Souza wrote:
>>> When building libvirt with libcurl debug enabled (with
>>> ESX_VI__CURL__ENABLE_DEBUG_OUTPUT set), the message bellow pops up:
>>>
>>> make[3]: Entering directory '/mnt/data/gitroot/libvirt/src'
>>>   CC   esx/libvirt_driver_esx_la-esx_vi.lo
>>> esx/esx_vi.c: In function 'esxVI_CURL_Debug':
>>> esx/esx_vi.c:191:5: error: enumeration value 'CURLINFO_SSL_DATA_IN' not 
>>> handled in switch [-Werror=switch-enum]
>>>  switch (type) {
>>>  ^~
>>> esx/esx_vi.c:191:5: error: enumeration value 'CURLINFO_SSL_DATA_OUT' not 
>>> handled in switch [-Werror=switch-enum]
>>> esx/esx_vi.c:191:5: error: enumeration value 'CURLINFO_END' not handled in 
>>> switch [-Werror=switch-enum]
>>>
>>> Our build requires at least libcurl 7.18.0, which is pretty stable since
>>> it was release in 2008. Fix this problem by handling the mentioned enums
>>> in the code.
>>>
>>> Signed-off-by: Marcos Paulo de Souza 
>>> ---
>>>  src/esx/esx_vi.c | 8 +++-
>>>  1 file changed, 7 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
>>> index a816c3a4f9..588670e137 100644
>>> --- a/src/esx/esx_vi.c
>>> +++ b/src/esx/esx_vi.c
>>> @@ -163,7 +163,7 @@ esxVI_CURL_WriteBuffer(char *data, size_t size, size_t 
>>> nmemb, void *userdata)
>>>  return 0;
>>>  }
>>>  
>>> -#define ESX_VI__CURL__ENABLE_DEBUG_OUTPUT 0
>>> +#define ESX_VI__CURL__ENABLE_DEBUG_OUTPUT 1
>>
>> The part below is fine. However, I'm not sure about this one ^^. This
>> turns curl debugging on by default. I'm not sure that is what we want.
> 
> You are right, this part was included by mistake. Would you want me to send a
> new version with this part removed?


No need. I've removed it just before pushing.

ACKed and pushed.

Michal

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

Re: [libvirt] [PATCH v2 RESEND 00/17] Introduce RDT memory bandwidth allocation support

2018-08-13 Thread John Ferlan


On 07/30/2018 11:54 PM, bing.niu wrote:
> 
> 
> On 2018年07月31日 06:14, John Ferlan wrote:
>>
>>
>> On 07/29/2018 11:12 PM, bing@intel.com wrote:
>>> From: Bing Niu 
>>>
>>> This series is to introduce RDT memory bandwidth allocation support
>>> by extending
>>> current virresctrl implementation.
> 
> []
>>> Bing Niu (17):
>>>    util: Rename some functions of virresctrl
>>>    util: Refactor virResctrlGetInfo in virresctrl
>>>    util: Refactor virResctrlAllocFormat of virresctrl
>>>    util: Add MBA capability information query to resctrl
>>>    util: Add MBA check to virResctrlInfoGetCache
>>>    util: Add MBA allocation to virresctrl
>>>    util: Add MBA schemata parse and format methods
>>>    util: Add support to calculate MBA utilization
>>>    util: Introduce virResctrlAllocForeachMemory
>>>    util: Introduce virResctrlAllocSetMemoryBandwidth
>>>    conf: Rename cachetune to resctrl
>>>    conf: Factor out vcpus parsing part from virDomainCachetuneDefParse
>>>    conf: Factor out vcpus overlapping from virDomainCachetuneDefParse
>>>    conf: Factor out virDomainResctrlDef update from
>>>  virDomainCachetuneDefParse
>>>    conf: Add support for memorytune XML processing for resctrl MBA
>>>    conf: Add return value check to virResctrlAllocForeachCache
>>>    conf: Add memory bandwidth allocation capability of host
>>>
>>>   docs/formatdomain.html.in  |  39 +-
>>>   docs/schemas/capability.rng    |  33 ++
>>>   docs/schemas/domaincommon.rng  |  17 +
>>>   src/conf/capabilities.c    | 107 
>>>   src/conf/capabilities.h    |  11 +
>>>   src/conf/domain_conf.c | 428
>>> ---
>>>   src/conf/domain_conf.h |  10 +-
>>>   src/libvirt_private.syms   |   6 +-
>>>   src/qemu/qemu_domain.c |   2 +-
>>>   src/qemu/qemu_process.c    |  18 +-
>>>   src/util/virresctrl.c  | 611
>>> +++--
>>>   src/util/virresctrl.h  |  55 +-
>>>   .../memorytune-colliding-allocs.xml    |  30 +
>>>   .../memorytune-colliding-cachetune.xml |  32 ++
>>>   tests/genericxml2xmlindata/memorytune.xml  |  33 ++
>>>   tests/genericxml2xmltest.c |   5 +
>>>   .../linux-resctrl/resctrl/info/MB/bandwidth_gran   |   1 +
>>>   .../linux-resctrl/resctrl/info/MB/min_bandwidth    |   1 +
>>>   .../linux-resctrl/resctrl/info/MB/num_closids  |   1 +
>>>   tests/vircaps2xmldata/vircaps-x86_64-resctrl.xml   |   8 +
>>>   tests/virresctrldata/resctrl.schemata  |   1 +
>>>   21 files changed, 1280 insertions(+), 169 deletions(-)
>>>   create mode 100644
>>> tests/genericxml2xmlindata/memorytune-colliding-allocs.xml
>>>   create mode 100644
>>> tests/genericxml2xmlindata/memorytune-colliding-cachetune.xml
>>>   create mode 100644 tests/genericxml2xmlindata/memorytune.xml
>>>   create mode 100644
>>> tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/bandwidth_gran
>>>   create mode 100644
>>> tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/min_bandwidth
>>>   create mode 100644
>>> tests/vircaps2xmldata/linux-resctrl/resctrl/info/MB/num_closids
>>>
>>
>> Reviewed-by: John Ferlan 
>> (series)
>>
>> I'll push once the tree is open for 4.7.0 commits unless someone else
>> chimes in with other major issues that need to be addressed.
>>
> 

Tree re-opened after I left for a week away from the virtual world...
Now that I'm back and digging out of email, figured I'd sync this series
up with current top and push.

Please post a followup docs/news.xml article describing the change.

Tks -

John

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

Re: [libvirt] [PATCH v3 00/11] use GNU C's cleanup attribute in src/util (batch III)

2018-08-13 Thread Erik Skultety
On Thu, Aug 09, 2018 at 09:42:08AM +0530, Sukrit Bhatnagar wrote:
> This third series of patches also modifies a few files in src/util
> to use VIR_AUTOFREE and VIR_AUTOPTR for automatic freeing of memory
> and get rid of some VIR_FREE macro invocations and *Free function
> calls.
>
> This is meant as a follow-up of the v1 series [1] of the same batch,
> and contains those patches which were not (completely) pushed upstream.

So I pushed all the patches except for 7 and 8 (technically I could have gone
with 8 too, but there were lots of merge conflicts, so I figured it would be
easier to send it along with 7 again rather than risk a mistake because of a
rebase).

Erik

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


Re: [libvirt] [PATCH] bhyve: fix process reconnect

2018-08-13 Thread no-reply
Hi,

This series was run against 'syntax-check' test by patchew.org, which failed, 
please find the details below:

Type: series
Message-id: 20180805155428.40866-1-bogorods...@gmail.com
Subject: [libvirt] [PATCH] bhyve: fix process reconnect

=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with
# HEAD pointing to a commit that has the patches applied on top of "base"
# branch
time bash -c './autogen.sh && make syntax-check'
=== TEST SCRIPT END ===

Updating bcb55ab053bc79561b55d0394490f4b64e0f2d01
>From https://github.com/patchew-project/libvirt
 * [new tag]   patchew/cover.1534173734.git.pkre...@redhat.com -> 
patchew/cover.1534173734.git.pkre...@redhat.com
 * [new tag]   
patchew/e4c0c13ab8e42fa3a2571fc6f5ce303dd8fa4363.1534157377.git.mpriv...@redhat.com
 -> 
patchew/e4c0c13ab8e42fa3a2571fc6f5ce303dd8fa4363.1534157377.git.mpriv...@redhat.com
Switched to a new branch 'test'
f034446009 bhyve: fix process reconnect

=== OUTPUT BEGIN ===
Updating submodules...
Submodule 'gnulib' (https://git.savannah.gnu.org/git/gnulib.git/) registered 
for path '.gnulib'
Submodule 'keycodemapdb' (https://gitlab.com/keycodemap/keycodemapdb.git) 
registered for path 'src/keycodemapdb'
Cloning into '/var/tmp/patchew-tester-tmp-4mu61k2o/src/.gnulib'...
Cloning into '/var/tmp/patchew-tester-tmp-4mu61k2o/src/src/keycodemapdb'...
Submodule path '.gnulib': checked out '68df637b5f1b5c10370f6981d2a43a5cf74368df'
Submodule path 'src/keycodemapdb': checked out 
'16e5b0787687d8904dad2c026107409eb9bfcb95'
Running bootstrap...
./bootstrap: Bootstrapping from checked-out libvirt sources...
./bootstrap: consider installing git-merge-changelog from gnulib
./bootstrap: getting gnulib files...
running: libtoolize --install --copy
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/config.guess'
libtoolize: copying file 'build-aux/config.sub'
libtoolize: copying file 'build-aux/install-sh'
libtoolize: copying file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
./bootstrap: .gnulib/gnulib-tool--no-changelog   --aux-dir=build-aux   
--doc-base=doc   --lib=libgnu   --m4-base=m4/   --source-base=gnulib/lib/   
--tests-base=gnulib/tests   --local-dir=gnulib/local--lgpl=2 --with-tests 
--makefile-name=gnulib.mk --avoid=pt_chown --avoid=lock-tests   --libtool 
--import ...
Module list with included dependencies (indented):
absolute-header
  accept
accept-tests
alloca
alloca-opt
alloca-opt-tests
allocator
  areadlink
areadlink-tests
arpa_inet
arpa_inet-tests
assure
  autobuild
  base64
base64-tests
binary-io
binary-io-tests
  bind
bind-tests
  bitrotate
bitrotate-tests
btowc
btowc-tests
builtin-expect
  byteswap
byteswap-tests
  c-ctype
c-ctype-tests
  c-strcase
c-strcase-tests
  c-strcasestr
c-strcasestr-tests
  calloc-posix
  canonicalize-lgpl
canonicalize-lgpl-tests
careadlinkat
  chown
chown-tests
  clock-time
cloexec
cloexec-tests
  close
close-tests
  configmake
  connect
connect-tests
  count-leading-zeros
count-leading-zeros-tests
  count-one-bits
count-one-bits-tests
ctype
ctype-tests
  dirname-lgpl
dosname
double-slash-root
dup
dup-tests
dup2
dup2-tests
  environ
environ-tests
errno
errno-tests
error
  execinfo
exitfail
extensions
extern-inline
fatal-signal
  fclose
fclose-tests
  fcntl
  fcntl-h
fcntl-h-tests
fcntl-tests
fd-hook
  fdatasync
fdatasync-tests
fdopen
fdopen-tests
fflush
fflush-tests
  ffs
ffs-tests
  ffsl
ffsl-tests
fgetc-tests
filename
flexmember
float
float-tests
  fnmatch
fnmatch-tests
fpieee
fpucw
fpurge
fpurge-tests
fputc-tests
fread-tests
freading
freading-tests
fseek
fseek-tests
fseeko
fseeko-tests
fstat
fstat-tests
  fsync
fsync-tests
ftell
ftell-tests
ftello
ftello-tests
ftruncate
ftruncate-tests
  func
func-tests
fwrite-tests
  getaddrinfo
getaddrinfo-tests
  getcwd-lgpl
getcwd-lgpl-tests
getdelim
getdelim-tests
getdtablesize
getdtablesize-tests
getgroups
getgroups-tests
  gethostname
gethostname-tests
getline
getline-tests
  getopt-posix
getopt-posix-tests
getpagesize
  getpass
  getpeername
getpeername-tests
getprogname
getprogname-tests
  getsockname
getsockname-tests
getsockopt
getsockopt-tests
gettext-h
  gettimeofday
gettimeofday-tests
getugroups
  gitlog-to-changelog
  gnumakefile
grantpt
grantpt-tests
  

Re: [libvirt] [PATCH 4/4] apparmor: allow to preserve /dev mountpoints into qemu namespaces

2018-08-13 Thread Jamie Strandboge
On Mon, 2018-08-13 at 16:39 +0200, Christian Ehrhardt wrote:
> Libvirt now tries to preserve all mounts under /dev in qemu
> namespaces.
> The old rules only listed a set of known paths but those are no more
> enough.
> 
> I found some due to containers like /dev/.lxc/* and such but also
> /dev/console
> and /dev/net/tun.
> 
> Libvirt is correct to do so, but we can no more predict the names
> properly, so
> we modify the rule to allow a wildcard based pattern matching what
> libvirt does.
> 
> Signed-off-by: Christian Ehrhardt 
> ---
>  examples/apparmor/usr.sbin.libvirtd | 16 +---
>  1 file changed, 5 insertions(+), 11 deletions(-)
> 
> diff --git a/examples/apparmor/usr.sbin.libvirtd
> b/examples/apparmor/usr.sbin.libvirtd
> index 3ff43c32a2..b2e38fe0ad 100644
> --- a/examples/apparmor/usr.sbin.libvirtd
> +++ b/examples/apparmor/usr.sbin.libvirtd
> @@ -33,17 +33,11 @@
>mount options=(rw,rslave)  -> /,
>mount options=(rw, nosuid) -> /{var/,}run/libvirt/qemu/*.dev/,
>  
> -  mount options=(rw, move) /dev/   ->
> /{var/,}run/libvirt/qemu/*.dev/,
> -  mount options=(rw, move) /dev/hugepages/ ->
> /{var/,}run/libvirt/qemu/*.hugepages/,
> -  mount options=(rw, move) /dev/mqueue/->
> /{var/,}run/libvirt/qemu/*.mqueue/,
> -  mount options=(rw, move) /dev/pts/   ->
> /{var/,}run/libvirt/qemu/*.pts/,
> -  mount options=(rw, move) /dev/shm/   ->
> /{var/,}run/libvirt/qemu/*.shm/,
> -
> -  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.dev/   ->
> /dev/,
> -  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.hugepages/ ->
> /dev/hugepages/,
> -  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.mqueue/->
> /dev/mqueue/,
> -  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.pts/   ->
> /dev/pts/,
> -  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.shm/   ->
> /dev/shm/,
> +  # libvirt provides any mounts under /dev to qemu namespaces
> +  mount options=(rw, move) /dev/ -> /{var/,}run/libvirt/qemu/*.dev/,
> +  mount options=(rw, move) /dev/**{/,} ->
> /{var/,}run/libvirt/qemu/*{/,},

What are you trying to convey with this rule? As written, the '{/,}' is
redundant since '**' will match that.

> +  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.dev/ -> /dev/,
> +  mount options=(rw, move) /{var/,}run/libvirt/qemu/*{/,} ->
> /dev/**{/,},

ditto

-- 
Jamie Strandboge | http://www.canonical.com

signature.asc
Description: This is a digitally signed message part
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 3/4] apparmor: allow expected /tmp access patterns

2018-08-13 Thread Jamie Strandboge
On Mon, 2018-08-13 at 16:39 +0200, Christian Ehrhardt wrote:
> Several cases were found needing /tmp, for example ceph will try to
> list /tmp
> and the samba feature of qemu will place things in /tmp/qemu-smb.*.
> This is sort of safe because:
>  - While /tmp could contain anything it is not recommended to put
> critical
>data there anyway
>  - We restrict general access to only dir listing and reading of
> files owned
>(intentionally not the full power of user-tmp abstraction)
>  - While it would be hard to predict the PID as part of the string
> for the
>qemu smb feature (this is not exposed through XML so virt-aa-
> helper
>can't help) it is guarded by the "owner" statement and a pretty
> clear
>qemu-smb infix in the path.
> 
> Signed-off-by: Christian Ehrhardt 
> ---
>  examples/apparmor/libvirt-qemu | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/examples/apparmor/libvirt-qemu
> b/examples/apparmor/libvirt-qemu
> index 5caf14e418..c4f231b328 100644
> --- a/examples/apparmor/libvirt-qemu
> +++ b/examples/apparmor/libvirt-qemu
> @@ -180,6 +180,16 @@
># for rbd
>/etc/ceph/ceph.conf r,
>  
> +  # various functions will need /tmp (e.g. ceph), allow the base dir
> and a
> +  # few known functions.
> +  # we want to avoid to give blanket read or even write to
> everything under /tmp
> +  # so users are expected to add site specific addons for more
> uncommon cases.
> +  # allow only dir listing and owner based file read
> +  /{,var/}tmp/ r,
> +  owner /{,var/}tmp/**/ r,
> +  # allow qemu smb feature specific path with write access
> +  owner /tmp/qemu-smb.*/{,**} rw,

The actual rule additions are a compromise between security and
usability. Personally I'd prefer they not be there and let admins add
them or allow distros to patch them. That said, the comments and commit
message don't seem quite right for what you are adding. Eg, you mention
ceph, but there is no ceph rule and the profile comment doesn't mention
ceph only needs to list dirs; the profile comments are formatted a bit
weird too.

You mention 'sort of safe', but because of the '/{,var/}tmp/ r,' rule,
you are allowing guests to enumerate all the /tmp/qemu-smb.*
directories and then there is a 'rw' rule for that path. While this is
an 'owner' match, in practice, VMs all run under the same uid so this
means a rogue vm would be allowed to access files in these directories.
That said, I don't know what qemu is setting up in there-- so maybe it
is designed in such a way that this doesn't matter.

I'd much rather not call this 'sort of safe' but instead call out the
problem, justify why the rule should be there and perhaps add a TODO
that once smb is supported in domain xml that this rule will be added
conditionally.

+0 for rule inclusion provided the comments and commit message are
addressed. +1 if it can be demonstrated that qemu is handling those
dirs safely wrt vm isolation.

-- 
Jamie Strandboge | http://www.canonical.com

signature.asc
Description: This is a digitally signed message part
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 2/4] apparmor: add mediation rules for unconfined guests

2018-08-13 Thread Jamie Strandboge
On Mon, 2018-08-13 at 16:39 +0200, Christian Ehrhardt wrote:
> If a guest runs unconfined , but libvirtd is
> confined then the peer for signal can only be detected as
> 'unconfined'. That triggers issues like:
>apparmor="DENIED" operation="signal"
>profile="/usr/sbin/libvirtd" pid=22395 comm="libvirtd"
>requested_mask="send" denied_mask="send" signal=term
> peer="unconfined"
> 
> To fix this add unconfined as an allowed peer for those operations.
> 
> I discussed with the apparmor folks, right now there is no better
> separation to be made in this case. But there might be further down
> the
> road with "policy namespaces with scope and view control + stacking"
> 
> This is more a use-case addition than a fix to the following two
> changes:
> - 3b1d19e6 AppArmor: add rules needed with additional mediation
> features
> - b482925c apparmor: support ptrace checks
> 
> Signed-off-by: Christian Ehrhardt 
> Acked-by: Jamie Strandboge 
> Acked-by: intrigeri 
> ---
>  examples/apparmor/usr.sbin.libvirtd | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/examples/apparmor/usr.sbin.libvirtd
> b/examples/apparmor/usr.sbin.libvirtd
> index dd37866c2a..3ff43c32a2 100644
> --- a/examples/apparmor/usr.sbin.libvirtd
> +++ b/examples/apparmor/usr.sbin.libvirtd
> @@ -74,6 +74,9 @@
># unconfined also required if guests run without security module
>unix (send, receive) type=stream addr=none
> peer=(label=unconfined),
>  
> +  # required if guests run unconfined seclabel type='none' but
> libvirtd is confined
> +  signal (read, send) peer=unconfined,

A tad unfortunate, but again, the libvirtd profile is meant to be super
strict. +1 to apply

-- 
Jamie Strandboge | http://www.canonical.com

signature.asc
Description: This is a digitally signed message part
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/4] apparmor: allow openGraphicsFD for virt manager >1.4

2018-08-13 Thread Jamie Strandboge
On Mon, 2018-08-13 at 16:39 +0200, Christian Ehrhardt wrote:
> virt-manager's UI connection will need socket access for
> openGraphicsFD
> to work - otherwise users will face a failed connection error when
> opening the UI view.
> 
> Depending on the exact versions of libvirt and qemu involved this
> needs
> either a rule from qemu to libvirt or vice versa.
> 
> Signed-off-by: Christian Ehrhardt 
> ---
>  examples/apparmor/libvirt-qemu  | 3 +++
>  examples/apparmor/usr.sbin.libvirtd | 5 +
>  2 files changed, 8 insertions(+)
> 
> diff --git a/examples/apparmor/libvirt-qemu
> b/examples/apparmor/libvirt-qemu
> index df5f512487..5caf14e418 100644
> --- a/examples/apparmor/libvirt-qemu
> +++ b/examples/apparmor/libvirt-qemu
> @@ -188,6 +188,9 @@
>@{PROC}/device-tree/** r,
>/sys/firmware/devicetree/** r,
>  
> +  # allow connect with openGraphicsFD to work
> +  unix (send, receive) type=stream addr=none
> peer=(label=/usr/sbin/libvirtd),

+1 to apply

> diff --git a/examples/apparmor/usr.sbin.libvirtd
> b/examples/apparmor/usr.sbin.libvirtd
> index 3102cab382..dd37866c2a 100644
> --- a/examples/apparmor/usr.sbin.libvirtd
> +++ b/examples/apparmor/usr.sbin.libvirtd
> @@ -69,6 +69,11 @@
>unix (send, receive) type=stream addr=none
> peer=(label=/usr/sbin/libvirtd//qemu_bridge_helper),
>signal (send) set=("term")
> peer=/usr/sbin/libvirtd//qemu_bridge_helper,
>  
> +  # allow connect with openGraphicsFD, direction reversed in newer
> versions
> +  unix (send, receive) type=stream addr=none peer=(label=libvirt-[0-
> 9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*),
> +  # unconfined also required if guests run without security module
> +  unix (send, receive) type=stream addr=none
> peer=(label=unconfined),

Makes sense. This libvirtd policy is meant to be super restrictive, so
+1 to apply.


-- 
Jamie Strandboge | http://www.canonical.com

signature.asc
Description: This is a digitally signed message part
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v3 04/11] util: netlink: use VIR_AUTOPTR for aggregate types

2018-08-13 Thread Sukrit Bhatnagar
On Mon, 13 Aug 2018 at 18:10, Erik Skultety  wrote:
>
> On Thu, Aug 09, 2018 at 09:42:12AM +0530, Sukrit Bhatnagar wrote:
> > By making use of GNU C's cleanup attribute handled by the
> > VIR_AUTOPTR macro for declaring aggregate pointer variables,
> > majority of the calls to *Free functions can be dropped, which
> > in turn leads to getting rid of most of our cleanup sections.
> >
> > Signed-off-by: Sukrit Bhatnagar 
> > ---
> >  src/util/virnetlink.c | 72 
> > ---
> >  1 file changed, 28 insertions(+), 44 deletions(-)
> >
> > diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
> > index fcdc09d..66e80e2 100644
> > --- a/src/util/virnetlink.c
> > +++ b/src/util/virnetlink.c
> > @@ -297,15 +297,16 @@ int virNetlinkCommand(struct nl_msg *nl_msg,
> >uint32_t src_pid, uint32_t dst_pid,
> >unsigned int protocol, unsigned int groups)
> >  {
> > -int ret = -1;
> >  struct sockaddr_nl nladdr = {
> >  .nl_family = AF_NETLINK,
> >  .nl_pid= dst_pid,
> >  .nl_groups = 0,
> >  };
> >  struct pollfd fds[1];
> > -VIR_AUTOPTR(virNetlinkHandle) nlhandle = NULL;
> >  int len = 0;
> > +VIR_AUTOPTR(virNetlinkHandle) nlhandle = NULL;
>
> unjustified code movement...
>
> > +
> > +*respbuflen = 0;
>
> unnecessary initialization..

We need *respbuflen to be 0 if -1 is returned. So if this initialization is
removed, we need to add `*respbuflen = 0;` in the cleanup section below.

> >  memset(fds, 0, sizeof(fds));
> >
> > @@ -324,15 +325,12 @@ int virNetlinkCommand(struct nl_msg *nl_msg,
> >  goto cleanup;
> >  }
> >
> > -ret = 0;
> >  *respbuflen = len;
> > - cleanup:
> > -if (ret < 0) {
> > -*resp = NULL;
> > -*respbuflen = 0;
> > -}
> > +return 0;
> >
> > -return ret;
> > + cleanup:
> > +*resp = NULL;
> > +return -1;
>
> I moved ^this hunk into the previous patch as I converted 1 more var into
> VIR_AUTOFREE.
>
> Reviewed-by: Erik Skultety 

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


[libvirt] [PATCHv2 41/62] qemu: monitor: Handle TRAY_MOVED event correctly with -blockdev

2018-08-13 Thread Peter Krempa
Add handling of the 'id' field in the event which corresponds to the
QDEV id of the device.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_monitor.c  |  3 ++-
 src/qemu/qemu_monitor.h  |  2 ++
 src/qemu/qemu_monitor_json.c | 11 ---
 src/qemu/qemu_process.c  |  3 ++-
 4 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 4dcbd69dce..cdfcbcea0b 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1460,13 +1460,14 @@ qemuMonitorEmitGraphics(qemuMonitorPtr mon,
 int
 qemuMonitorEmitTrayChange(qemuMonitorPtr mon,
   const char *devAlias,
+  const char *devid,
   int reason)
 {
 int ret = -1;
 VIR_DEBUG("mon=%p", mon);

 QEMU_MONITOR_CALLBACK(mon, ret, domainTrayChange, mon->vm,
-  devAlias, reason);
+  devAlias, devid, reason);

 return ret;
 }
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index f8f6969ddb..1c66459e69 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -181,6 +181,7 @@ typedef int 
(*qemuMonitorDomainBlockJobCallback)(qemuMonitorPtr mon,
 typedef int (*qemuMonitorDomainTrayChangeCallback)(qemuMonitorPtr mon,
virDomainObjPtr vm,
const char *devAlias,
+   const char *devid,
int reason,
void *opaque);
 typedef int (*qemuMonitorDomainPMWakeupCallback)(qemuMonitorPtr mon,
@@ -397,6 +398,7 @@ int qemuMonitorEmitGraphics(qemuMonitorPtr mon,
 const char *saslUsername);
 int qemuMonitorEmitTrayChange(qemuMonitorPtr mon,
   const char *devAlias,
+  const char *devid,
   int reason);
 int qemuMonitorEmitPMWakeup(qemuMonitorPtr mon);
 int qemuMonitorEmitPMSuspend(qemuMonitorPtr mon);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index de3fcd83d8..537cdfd19a 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1031,11 +1031,16 @@ static void
 qemuMonitorJSONHandleTrayChange(qemuMonitorPtr mon,
 virJSONValuePtr data)
 {
-const char *devAlias = NULL;
+const char *devAlias = virJSONValueObjectGetString(data, "device");
+const char *devid = virJSONValueObjectGetString(data, "id");
 bool trayOpened;
 int reason;

-if ((devAlias = virJSONValueObjectGetString(data, "device")) == NULL) {
+/* drive alias is always reported but empty for -blockdev */
+if (*devAlias == '\0')
+devAlias = NULL;
+
+if (!devAlias && !devid) {
 VIR_WARN("missing device in tray change event");
 return;
 }
@@ -1050,7 +1055,7 @@ qemuMonitorJSONHandleTrayChange(qemuMonitorPtr mon,
 else
 reason = VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE;

-qemuMonitorEmitTrayChange(mon, devAlias, reason);
+qemuMonitorEmitTrayChange(mon, devAlias, devid, reason);
 }

 static void
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index b713afa3a2..40e2589b37 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1061,6 +1061,7 @@ static int
 qemuProcessHandleTrayChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
 virDomainObjPtr vm,
 const char *devAlias,
+const char *devid,
 int reason,
 void *opaque)
 {
@@ -1070,7 +1071,7 @@ qemuProcessHandleTrayChange(qemuMonitorPtr mon 
ATTRIBUTE_UNUSED,
 virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);

 virObjectLock(vm);
-disk = qemuProcessFindDomainDiskByAliasOrQOM(vm, devAlias, NULL);
+disk = qemuProcessFindDomainDiskByAliasOrQOM(vm, devAlias, devid);

 if (disk) {
 event = virDomainEventTrayChangeNewFromObj(vm, disk->info.alias, 
reason);
-- 
2.16.2

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


[libvirt] [PATCHv2 61/62] qemu: driver: Prepare qemuDomainGetStatsBlock (bulk disk stats) for -blockdev

2018-08-13 Thread Peter Krempa
Add code paths which call into the new functions to gather the data on a
per-node-name basis and tweak the aliases used for extracting the data.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 54 +++---
 1 file changed, 38 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index dfb06bed80..059debb2f7 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20244,20 +20244,34 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr 
disk,
   bool visitBacking,
   virQEMUDriverPtr driver,
   virQEMUDriverConfigPtr cfg,
-  virDomainObjPtr dom)
+  virDomainObjPtr dom,
+  bool blockdev)

 {
 char *alias = NULL;
 virStorageSourcePtr n;
+const char *frontendalias;
+const char *backendalias;
+const char *backendstoragealias;
 int ret = -1;

 for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
-/* alias may be NULL if the VM is not running */
-if (disk->info.alias &&
-!(alias = qemuDomainStorageAlias(disk->info.alias, n->id)))
-goto cleanup;
+if (blockdev) {
+frontendalias = QEMU_DOMAIN_DISK_PRIVATE(disk)->backendQomName;
+backendalias = n->nodeformat;
+backendstoragealias = n->nodestorage;
+} else {
+/* alias may be NULL if the VM is not running */
+if (disk->info.alias &&
+!(alias = qemuDomainStorageAlias(disk->info.alias, n->id)))
+goto cleanup;
+
+qemuDomainGetStatsOneBlockRefreshNamed(n, alias, stats, nodestats);

-qemuDomainGetStatsOneBlockRefreshNamed(n, alias, stats, nodestats);
+frontendalias = alias;
+backendalias = alias;
+backendstoragealias = alias;
+}

 if (qemuDomainGetStatsBlockExportHeader(disk, n, *recordnr,
 records, nrecords) < 0)
@@ -20265,17 +20279,17 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr 
disk,

 /* The following stats make sense only for the frontend device */
 if (n == disk->src) {
-if (qemuDomainGetStatsBlockExportFrontend(alias, stats, *recordnr,
+if (qemuDomainGetStatsBlockExportFrontend(frontendalias, stats, 
*recordnr,
   records, nrecords) < 0)
 goto cleanup;
 }

 if (qemuDomainGetStatsOneBlock(driver, cfg, dom, records, nrecords,
-   alias, n, *recordnr,
+   backendalias, n, *recordnr,
stats) < 0)
 goto cleanup;

-if (qemuDomainGetStatsBlockExportBackendStorage(alias,
+if (qemuDomainGetStatsBlockExportBackendStorage(backendstoragealias,
 stats, *recordnr,
 records, nrecords) < 0)
 goto cleanup;
@@ -20310,19 +20324,26 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
 virJSONValuePtr nodedata = NULL;
 qemuDomainObjPrivatePtr priv = dom->privateData;
 virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
 bool fetchnodedata = virQEMUCapsGet(priv->qemuCaps,
-QEMU_CAPS_QUERY_NAMED_BLOCK_NODES);
+QEMU_CAPS_QUERY_NAMED_BLOCK_NODES) && 
!blockdev;
 int count_index = -1;
 size_t visited = 0;
 bool visitBacking = !!(privflags & QEMU_DOMAIN_STATS_BACKING);

 if (HAVE_JOB(privflags) && virDomainObjIsActive(dom)) {
 qemuDomainObjEnterMonitor(driver, dom);
-rc = qemuMonitorGetAllBlockStatsInfo(priv->mon, ,
- visitBacking);
-if (rc >= 0)
-ignore_value(qemuMonitorBlockStatsUpdateCapacity(priv->mon, stats,
- visitBacking));
+
+rc = qemuMonitorGetAllBlockStatsInfo(priv->mon, , visitBacking);
+
+if (blockdev) {
+if (rc >= 0)
+rc = qemuMonitorBlockStatsUpdateCapacityBlockdev(priv->mon, 
stats);
+} else {
+if (rc >= 0)
+ignore_value(qemuMonitorBlockStatsUpdateCapacity(priv->mon, 
stats,
+ 
visitBacking));
+}

 if (fetchnodedata)
 nodedata = qemuMonitorQueryNamedBlockNodes(priv->mon);
@@ -20348,7 +20369,8 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
 for (i = 0; i < dom->def->ndisks; i++) 

[libvirt] [PATCHv2 53/62] qemu: Extract exporting of the header for block stats

2018-08-13 Thread Peter Krempa
Split out the header so that the loop can be refactored later.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 38 --
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ac9c7faf2e..6ea86c8cbf 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20071,7 +20071,6 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
virDomainObjPtr dom,
virDomainStatsRecordPtr record,
int *maxparams,
-   const char *diskdst,
const char *entryname,
virStorageSourcePtr src,
size_t block_idx,
@@ -20080,14 +20079,6 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
 qemuBlockStats *entry;
 int ret = -1;

-QEMU_ADD_NAME_PARAM(record, maxparams, "block", "name", block_idx, 
diskdst);
-
-if (virStorageSourceIsLocalStorage(src) && src->path)
-QEMU_ADD_NAME_PARAM(record, maxparams, "block", "path",
-block_idx, src->path);
-if (src->id)
-QEMU_ADD_BLOCK_PARAM_UI(record, maxparams, block_idx, "backingIndex",
-src->id);

 /* the VM is offline so we have to go and load the stast from the disk by
  * ourselves */
@@ -20150,6 +20141,29 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
 }


+static int
+qemuDomainGetStatsBlockExportHeader(virDomainDiskDefPtr disk,
+virStorageSourcePtr src,
+size_t recordnr,
+virDomainStatsRecordPtr records,
+int *nrecords)
+{
+int ret = -1;
+
+QEMU_ADD_NAME_PARAM(records, nrecords, "block", "name", recordnr, 
disk->dst);
+
+if (virStorageSourceIsLocalStorage(src) && src->path)
+QEMU_ADD_NAME_PARAM(records, nrecords, "block", "path", recordnr, 
src->path);
+if (src->id)
+QEMU_ADD_BLOCK_PARAM_UI(records, nrecords, recordnr, "backingIndex",
+src->id);
+
+ret = 0;
+ cleanup:
+return ret;
+}
+
+
 static int
 qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr disk,
   virHashTablePtr stats,
@@ -20177,8 +20191,12 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr 
disk,

 qemuDomainGetStatsOneBlockRefreshNamed(src, alias, stats, nodestats);

+if (qemuDomainGetStatsBlockExportHeader(disk, src, *recordnr,
+records, nrecords) < 0)
+goto cleanup;
+
 if (qemuDomainGetStatsOneBlock(driver, cfg, dom, records, nrecords,
-   disk->dst, alias, src, *recordnr,
+   alias, src, *recordnr,
stats) < 0)
 goto cleanup;

-- 
2.16.2

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


[libvirt] [PATCHv2 59/62] qemu: Use QOM path with query-block when using -blockdev

2018-08-13 Thread Peter Krempa
Switch to using the QOM/qdev handles in all calls to
qemuMonitorGetBlockInfo when using -blockdev. The callers also need to
make sure to use the correct handle afterwards to extract the data.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c  | 9 -
 src/qemu/qemu_process.c | 7 ++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 55bb8f71fe..a97235614b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18724,6 +18724,7 @@ qemuDomainGetDiskErrors(virDomainPtr dom,
 virDomainObjPtr vm = NULL;
 qemuDomainObjPrivatePtr priv;
 virHashTablePtr table = NULL;
+bool blockdev = false;
 int ret = -1;
 size_t i;
 int n = 0;
@@ -18734,6 +18735,7 @@ qemuDomainGetDiskErrors(virDomainPtr dom,
 goto cleanup;

 priv = vm->privateData;
+blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);

 if (virDomainGetDiskErrorsEnsureACL(dom->conn, vm->def) < 0)
 goto cleanup;
@@ -18759,8 +18761,13 @@ qemuDomainGetDiskErrors(virDomainPtr dom,
 for (i = n = 0; i < vm->def->ndisks; i++) {
 struct qemuDomainDiskInfo *info;
 virDomainDiskDefPtr disk = vm->def->disks[i];
+qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+const char *entryname = disk->info.alias;
+
+if (blockdev)
+entryname = diskPriv->backendQomName;

-if ((info = virHashLookup(table, disk->info.alias)) &&
+if ((info = virHashLookup(table, entryname)) &&
 info->io_status != VIR_DOMAIN_DISK_ERROR_NONE) {
 if (n == nerrors)
 break;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 6e0b4b0027..15e7c951b6 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7589,6 +7589,7 @@ qemuProcessRefreshDisks(virQEMUDriverPtr driver,
 qemuDomainAsyncJob asyncJob)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
+bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
 virHashTablePtr table = NULL;
 int ret = -1;
 size_t i;
@@ -7606,8 +7607,12 @@ qemuProcessRefreshDisks(virQEMUDriverPtr driver,
 virDomainDiskDefPtr disk = vm->def->disks[i];
 qemuDomainDiskPrivatePtr diskpriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
 struct qemuDomainDiskInfo *info;
+const char *entryname = disk->info.alias;
+
+if (blockdev)
+entryname = diskpriv->backendQomName;

-if (!(info = virHashLookup(table, disk->info.alias)))
+if (!(info = virHashLookup(table, entryname)))
 continue;

 if (info->removable) {
-- 
2.16.2

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


[libvirt] [PATCHv2 57/62] qemu: Export stats relevant for the storage backend

2018-08-13 Thread Peter Krempa
Data relevant for the storage of a backing chain member will need to be
reported separately when switching to blockdev. Prepare a function that
extracts the appropriate data.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 28 +++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c09108b57e..55bb8f71fe 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20114,8 +20114,29 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
 }
 }

+ret = 0;
+ cleanup:
+return ret;
+}
+
+
+static int
+qemuDomainGetStatsBlockExportBackendStorage(const char *entryname,
+virHashTablePtr stats,
+size_t recordnr,
+virDomainStatsRecordPtr records,
+int *nrecords)
+{
+qemuBlockStats *entry;
+int ret = -1;
+
+if (!stats || !entryname || !(entry = virHashLookup(stats, entryname))) {
+ret = 0;
+goto cleanup;
+}
+
 if (entry->write_threshold)
-QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx, "threshold",
+QEMU_ADD_BLOCK_PARAM_ULL(records, nrecords, recordnr, "threshold",
  entry->write_threshold);

 ret = 0;
@@ -20221,6 +20242,11 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr 
disk,
stats) < 0)
 goto cleanup;

+if (qemuDomainGetStatsBlockExportBackendStorage(alias,
+stats, *recordnr,
+records, nrecords) < 0)
+goto cleanup;
+
 VIR_FREE(alias);
 (*recordnr)++;

-- 
2.16.2

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


[libvirt] [PATCHv2 60/62] qemu: driver: Allow using blockdev with qemuDomainBlocksStatsGather

2018-08-13 Thread Peter Krempa
Use the 'qdev' instead of the disk alias to lookup the stats and
transfer the capacity from the appropriate node name so that the
function works with -blockdev.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 48 +---
 1 file changed, 37 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a97235614b..dfb06bed80 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11063,11 +11063,13 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
 qemuBlockStatsPtr *retstats)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
-virDomainDiskDefPtr disk;
+bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
+virDomainDiskDefPtr disk = NULL;
 virHashTablePtr blockstats = NULL;
 qemuBlockStatsPtr stats;
 size_t i;
 int nstats;
+int rc = 0;
 const char *entryname = NULL;
 int ret = -1;

@@ -11077,23 +11079,30 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
 goto cleanup;
 }

-if (!disk->info.alias) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("missing disk device alias name for %s"), 
disk->dst);
-goto cleanup;
-}
+if (blockdev) {
+entryname = QEMU_DOMAIN_DISK_PRIVATE(disk)->backendQomName;
+} else {
+if (!disk->info.alias) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("missing disk device alias name for %s"), 
disk->dst);
+goto cleanup;
+}

-entryname = disk->info.alias;
+entryname = disk->info.alias;
+}
 }

 qemuDomainObjEnterMonitor(driver, vm);
 nstats = qemuMonitorGetAllBlockStatsInfo(priv->mon, , false);

-if (capacity && nstats >= 0 &&
-qemuMonitorBlockStatsUpdateCapacity(priv->mon, blockstats, false) < 0)
-nstats = -1;
+if (capacity && nstats >= 0) {
+if (blockdev)
+rc = qemuMonitorBlockStatsUpdateCapacityBlockdev(priv->mon, 
blockstats);
+else
+rc = qemuMonitorBlockStatsUpdateCapacity(priv->mon, blockstats, 
false);
+}

-if (qemuDomainObjExitMonitor(driver, vm) < 0 || nstats < 0)
+if (qemuDomainObjExitMonitor(driver, vm) < 0 || nstats < 0 || rc < 0)
 goto cleanup;

 if (VIR_ALLOC(*retstats) < 0)
@@ -11106,12 +5,29 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
 goto cleanup;
 }

+if (blockdev) {
+/* capacity are reported only per node-name so we need to transfer 
them */
+qemuBlockStatsPtr capstats;
+
+if (disk && disk->src &&
+(capstats = virHashLookup(blockstats, disk->src->nodeformat))) 
{
+(*retstats)->capacity = capstats->capacity;
+(*retstats)->physical = capstats->physical;
+(*retstats)->wr_highest_offset = capstats->wr_highest_offset;
+(*retstats)->wr_highest_offset_valid = 
capstats->wr_highest_offset_valid;
+(*retstats)->write_threshold = capstats->write_threshold;
+}
+}
+
 **retstats = *stats;
 } else {
 for (i = 0; i < vm->def->ndisks; i++) {
 disk = vm->def->disks[i];
 entryname = disk->info.alias;

+if (blockdev)
+entryname = QEMU_DOMAIN_DISK_PRIVATE(disk)->backendQomName;
+
 if (!entryname)
 continue;

-- 
2.16.2

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


[libvirt] [PATCHv2 52/62] qemu: Extract exporting of disk block statistics

2018-08-13 Thread Peter Krempa
Split out the code which converts the stats gathered in
qemuDomainGetStatsBlock into typed parameters so that it will look
less ugly when extending it.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 73 +-
 1 file changed, 49 insertions(+), 24 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 688746c36f..ac9c7faf2e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20150,6 +20150,51 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
 }


+static int
+qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr disk,
+  virHashTablePtr stats,
+  virHashTablePtr nodestats,
+  virDomainStatsRecordPtr records,
+  int *nrecords,
+  size_t *recordnr,
+  bool visitBacking,
+  virQEMUDriverPtr driver,
+  virQEMUDriverConfigPtr cfg,
+  virDomainObjPtr dom)
+
+{
+char *alias = NULL;
+virStorageSourcePtr src = disk->src;
+int ret = -1;
+
+while (virStorageSourceIsBacking(src) &&
+   (src == disk->src || visitBacking)) {
+
+/* alias may be NULL if the VM is not running */
+if (disk->info.alias &&
+!(alias = qemuDomainStorageAlias(disk->info.alias, src->id)))
+goto cleanup;
+
+qemuDomainGetStatsOneBlockRefreshNamed(src, alias, stats, nodestats);
+
+if (qemuDomainGetStatsOneBlock(driver, cfg, dom, records, nrecords,
+   disk->dst, alias, src, *recordnr,
+   stats) < 0)
+goto cleanup;
+
+VIR_FREE(alias);
+(*recordnr)++;
+src = src->backingStore;
+}
+
+ret = 0;
+
+ cleanup:
+VIR_FREE(alias);
+return ret;
+}
+
+
 static int
 qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
 virDomainObjPtr dom,
@@ -20170,7 +20215,6 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
 int count_index = -1;
 size_t visited = 0;
 bool visitBacking = !!(privflags & QEMU_DOMAIN_STATS_BACKING);
-char *alias = NULL;

 if (HAVE_JOB(privflags) && virDomainObjIsActive(dom)) {
 qemuDomainObjEnterMonitor(driver, dom);
@@ -20202,35 +20246,16 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
 QEMU_ADD_COUNT_PARAM(record, maxparams, "block", 0);

 for (i = 0; i < dom->def->ndisks; i++) {
-virDomainDiskDefPtr disk = dom->def->disks[i];
-virStorageSourcePtr src = disk->src;
-
-while (virStorageSourceIsBacking(src) &&
-   (src == disk->src || visitBacking)) {
-
-/* alias may be NULL if the VM is not running */
-if (disk->info.alias &&
-!(alias = qemuDomainStorageAlias(disk->info.alias, src->id)))
-goto cleanup;
-
-qemuDomainGetStatsOneBlockRefreshNamed(src, alias, stats, 
nodestats);
-
-if (qemuDomainGetStatsOneBlock(driver, cfg, dom, record, maxparams,
-   disk->dst, alias, src, visited,
-   stats) < 0)
-goto cleanup;
-
-VIR_FREE(alias);
-visited++;
-src = src->backingStore;
-}
+if (qemuDomainGetStatsBlockExportDisk(dom->def->disks[i], stats, 
nodestats,
+  record, maxparams, ,
+  visitBacking, driver, cfg, dom) 
< 0)
+goto cleanup;
 }

 record->params[count_index].value.ui = visited;
 ret = 0;

  cleanup:
-VIR_FREE(alias);
 virHashFree(stats);
 virHashFree(nodestats);
 virJSONValueFree(nodedata);
-- 
2.16.2

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


[libvirt] [PATCHv2 62/62] DO NOT APPLY: Enable QEMU_CAPS_BLOCKDEV if 'query-blockstats' works with -blockdev

2018-08-13 Thread Peter Krempa
'query-blockstats' did not report the 'qdev' field prior to fixing it so
that it works with our setup. Use that as a witness to enable -blockdev

Note that the blockjobs were NOT adapted yet so any blockjob will desync
the state of qemu. This patch needs to wait until blockjobs are fixed.
---
 src/qemu/qemu_capabilities.c   |   1 +
 tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml   |   1 +
 tests/qemuxml2argvdata/disk-aio.x86_64-latest.args |  19 ++-
 .../disk-backing-chains-noindex.x86_64-latest.args | 145 ++---
 .../qemuxml2argvdata/disk-cache.x86_64-latest.args |  50 ---
 .../disk-cdrom-network.x86_64-latest.args  |  32 +++--
 .../disk-cdrom-tray.x86_64-latest.args |  24 ++--
 .../qemuxml2argvdata/disk-cdrom.x86_64-latest.args |  17 ++-
 .../disk-copy_on_read.x86_64-latest.args   |  19 ++-
 .../disk-detect-zeroes.x86_64-latest.args  |  17 ++-
 .../disk-error-policy.x86_64-latest.args   |  30 +++--
 .../disk-floppy-q35-2_11.x86_64-latest.args|  14 +-
 .../disk-floppy-q35-2_9.x86_64-latest.args |  14 +-
 .../disk-floppy.x86_64-latest.args |  21 ++-
 .../disk-network-gluster.x86_64-latest.args|  32 +++--
 .../disk-network-iscsi.x86_64-latest.args  |  58 +
 .../disk-network-nbd.x86_64-latest.args|  41 --
 .../disk-network-rbd.x86_64-latest.args|  67 ++
 .../disk-network-sheepdog.x86_64-latest.args   |  16 ++-
 .../disk-network-source-auth.x86_64-latest.args|  30 +++--
 .../disk-network-tlsx509.x86_64-latest.args|  61 +
 .../disk-readonly-disk.x86_64-latest.args  |  14 +-
 .../disk-shared.x86_64-latest.args |  18 ++-
 ...isk-virtio-scsi-reservations.x86_64-latest.args |  20 ++-
 .../floppy-drive-fat.x86_64-latest.args|   7 +-
 25 files changed, 536 insertions(+), 232 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index f8c5967655..4de8b3a518 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1307,6 +1307,7 @@ static struct virQEMUCapsStringFlags 
virQEMUCapsQMPSchemaQueries[] = {
 { "blockdev-add/arg-type/+qcow2/encrypt/+luks/key-secret", 
QEMU_CAPS_QCOW2_LUKS },
 { "nbd-server-start/arg-type/tls-creds", QEMU_CAPS_NBD_TLS },
 { "screendump/arg-type/device", QEMU_CAPS_SCREENDUMP_DEVICE },
+{ "query-blockstats/ret-type/qdev", QEMU_CAPS_BLOCKDEV },
 };

 typedef struct _virQEMUCapsObjectTypeProps virQEMUCapsObjectTypeProps;
diff --git a/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml 
b/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml
index 9f4cdfc540..281163af3d 100644
--- a/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml
@@ -215,6 +215,7 @@
   
   
   
+  
   2012093
   0
   427343
diff --git a/tests/qemuxml2argvdata/disk-aio.x86_64-latest.args 
b/tests/qemuxml2argvdata/disk-aio.x86_64-latest.args
index 3894ed2502..ae82ba52bd 100644
--- a/tests/qemuxml2argvdata/disk-aio.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/disk-aio.x86_64-latest.args
@@ -24,13 +24,20 @@ file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
 -no-acpi \
 -boot strict=on \
 -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
--drive file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-ide0-0-0,\
-cache=none,aio=native \
--device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1,\
+-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1",\
+"aio":"native","node-name":"libvirt-2-storage","cache":{"direct":true,\
+"no-flush":false},"read-only":false,"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-2-format","read-only":false,\
+"cache":{"direct":true,"no-flush":false},"driver":"qcow2",\
+"file":"libvirt-2-storage"}' \
+-device 
ide-hd,bus=ide.0,unit=0,drive=libvirt-2-format,id=ide0-0-0,bootindex=1,\
 write-cache=on \
--drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-1-0,\
-readonly=on,aio=threads \
--device ide-cd,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0 \
+-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest2",\
+"aio":"threads","node-name":"libvirt-1-storage","read-only":true,\
+"discard":"unmap"}' \
+-blockdev '{"node-name":"libvirt-1-format","read-only":true,"driver":"raw",\
+"file":"libvirt-1-storage"}' \
+-device ide-cd,bus=ide.1,unit=0,drive=libvirt-1-format,id=ide0-1-0 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
 resourcecontrol=deny \
diff --git 
a/tests/qemuxml2argvdata/disk-backing-chains-noindex.x86_64-latest.args 
b/tests/qemuxml2argvdata/disk-backing-chains-noindex.x86_64-latest.args
index afe078adcc..11d805f3d8 100644
--- a/tests/qemuxml2argvdata/disk-backing-chains-noindex.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/disk-backing-chains-noindex.x86_64-latest.args
@@ -24,33 

[libvirt] [PATCHv2 51/62] qemu: monitor: Extract 'write-threshold' automatically for -blockdev

2018-08-13 Thread Peter Krempa
In cases when -blockdev is used we need to use 'query-named-block-nodes'
instead of 'query-block'. This means that we can extract the
write-threshold variable right away.

To keep compatibility with old VMs modify the code which was extracting
the value previously so that it updates the stats structure and a single
code path then can be used to extract the data.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c   | 57 ++--
 src/qemu/qemu_monitor.h  |  3 +++
 src/qemu/qemu_monitor_json.c | 16 ++---
 3 files changed, 50 insertions(+), 26 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 63ce68bd35..688746c36f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20029,29 +20029,39 @@ qemuDomainGetStatsOneBlockFallback(virQEMUDriverPtr 
driver,
 }


-static int
-qemuDomainGetStatsOneBlockNode(virDomainStatsRecordPtr record,
-   int *maxparams,
-   virStorageSourcePtr src,
-   size_t block_idx,
-   virHashTablePtr nodedata)
+/**
+ * qemuDomainGetStatsOneBlockRefreshNamed:
+ * @src: disk source structure
+ * @alias: disk alias
+ * @stats: hash table containing stats for all disks
+ * @nodedata: reply containin 'query-named-block-nodes' data
+ *
+ * Refresh disk block stats data (qemuBlockStatsPtr) which are present only
+ * in the reply of 'query-named-block-nodes' in cases when the data was 
gathered
+ * by using qem-block originally.
+ */
+static void
+qemuDomainGetStatsOneBlockRefreshNamed(virStorageSourcePtr src,
+   const char *alias,
+   virHashTablePtr stats,
+   virHashTablePtr nodedata)
 {
+qemuBlockStatsPtr entry;
+
 virJSONValuePtr data;
 unsigned long long tmp;
-int ret = -1;

-if (src->nodestorage &&
-(data = virHashLookup(nodedata, src->nodestorage))) {
-if (virJSONValueObjectGetNumberUlong(data, "write_threshold", ) == 
0 &&
-tmp > 0)
-QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx,
- "threshold", tmp);
-}
+if (!nodedata || !src->nodestorage)
+return;

-ret = 0;
+if (!(entry = virHashLookup(stats, alias)))
+return;

- cleanup:
-return ret;
+if (!(data = virHashLookup(nodedata, src->nodestorage)))
+return;
+
+if (virJSONValueObjectGetNumberUlong(data, "write_threshold", ) == 0)
+entry->write_threshold = tmp;
 }


@@ -20065,8 +20075,7 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
const char *entryname,
virStorageSourcePtr src,
size_t block_idx,
-   virHashTablePtr stats,
-   virHashTablePtr nodedata)
+   virHashTablePtr stats)
 {
 qemuBlockStats *entry;
 int ret = -1;
@@ -20131,9 +20140,9 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
 }
 }

-if (qemuDomainGetStatsOneBlockNode(record, maxparams, src, block_idx,
-   nodedata) < 0)
-goto cleanup;
+if (entry->write_threshold)
+QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx, "threshold",
+ entry->write_threshold);

 ret = 0;
  cleanup:
@@ -20204,9 +20213,11 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
 !(alias = qemuDomainStorageAlias(disk->info.alias, src->id)))
 goto cleanup;

+qemuDomainGetStatsOneBlockRefreshNamed(src, alias, stats, 
nodestats);
+
 if (qemuDomainGetStatsOneBlock(driver, cfg, dom, record, maxparams,
disk->dst, alias, src, visited,
-   stats, nodestats) < 0)
+   stats) < 0)
 goto cleanup;

 VIR_FREE(alias);
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index f83a18f563..ae54b13a55 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -587,6 +587,9 @@ struct _qemuBlockStats {
  * if wr_highest_offset_valid is true */
 unsigned long long wr_highest_offset;
 bool wr_highest_offset_valid;
+
+/* write_threshold is valid only if it's non-zero, conforming to qemu 
semantics */
+unsigned long long write_threshold;
 };

 int qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 438864ac40..f98269b34a 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2492,7 +2492,8 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
 static int
 qemuMonitorJSONBlockStatsUpdateCapacityData(virJSONValuePtr 

[libvirt] [PATCHv2 54/62] qemu: Export stats relevant for the frontend separately

2018-08-13 Thread Peter Krempa
While we report the read and written byte stats for every single layer
of the backing chain, qemu in fact reports them only for the frontend.

Split out the relevant stats into a separate function so that we can
later fix this bug and stop reporting it for backing chain entries where
they don't make sense.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 54 ++
 1 file changed, 37 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6ea86c8cbf..479bf3adfe 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20096,23 +20096,6 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
 goto cleanup;
 }

-QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, block_idx,
-"rd.reqs", entry->rd_req);
-QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, block_idx,
-"rd.bytes", entry->rd_bytes);
-QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, block_idx,
-"rd.times", entry->rd_total_times);
-QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, block_idx,
-"wr.reqs", entry->wr_req);
-QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, block_idx,
-"wr.bytes", entry->wr_bytes);
-QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, block_idx,
-"wr.times", entry->wr_total_times);
-QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, block_idx,
-"fl.reqs", entry->flush_req);
-QEMU_ADD_BLOCK_PARAM_LL(record, maxparams, block_idx,
-"fl.times", entry->flush_total_times);
-
 QEMU_ADD_BLOCK_PARAM_ULL(record, maxparams, block_idx,
  "allocation", entry->wr_highest_offset);

@@ -20141,6 +20124,39 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
 }


+static int
+qemuDomainGetStatsBlockExportFrontend(const char *frontendname,
+  virHashTablePtr stats,
+  size_t recordnr,
+  virDomainStatsRecordPtr records,
+  int *nrecords)
+{
+qemuBlockStats *entry;
+int ret = -1;
+
+/* In case where qemu didn't provide the stats we stop here rather than
+ * trying to refresh the stats from the disk. Inability to provide stats is
+ * usually caused by blocked storage so this would make libvirtd hang */
+if (!stats || !frontendname || !(entry = virHashLookup(stats, 
frontendname))) {
+ret = 0;
+goto cleanup;
+}
+
+QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "rd.reqs", 
entry->rd_req);
+QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "rd.bytes", 
entry->rd_bytes);
+QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "rd.times", 
entry->rd_total_times);
+QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "wr.reqs", 
entry->wr_req);
+QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "wr.bytes", 
entry->wr_bytes);
+QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "wr.times", 
entry->wr_total_times);
+QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "fl.reqs", 
entry->flush_req);
+QEMU_ADD_BLOCK_PARAM_LL(records, nrecords, recordnr, "fl.times", 
entry->flush_total_times);
+
+ret = 0;
+ cleanup:
+return ret;
+}
+
+
 static int
 qemuDomainGetStatsBlockExportHeader(virDomainDiskDefPtr disk,
 virStorageSourcePtr src,
@@ -20195,6 +20211,10 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr 
disk,
 records, nrecords) < 0)
 goto cleanup;

+if (qemuDomainGetStatsBlockExportFrontend(alias, stats, *recordnr,
+  records, nrecords) < 0)
+goto cleanup;
+
 if (qemuDomainGetStatsOneBlock(driver, cfg, dom, records, nrecords,
alias, src, *recordnr,
stats) < 0)
-- 
2.16.2

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


[libvirt] [PATCHv2 47/62] qemu: Explicitly find disks for stats totals

2018-08-13 Thread Peter Krempa
Rather than totalling every entry from 'query-block' for stats provided
by qemuDomainBlocksStatsGather total only stats for known disks. This
will allow to return data for nodenames and qdevs in the same hash so
that we can use them with -blockdev.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 25 ++---
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f36d4dc37f..e18187b7bb 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11023,13 +11023,9 @@ qemuDomainBlockResize(virDomainPtr dom,


 static int
-qemuDomainBlockStatsGatherTotals(void *payload,
- const void *name ATTRIBUTE_UNUSED,
- void *opaque)
+qemuDomainBlockStatsGatherTotals(qemuBlockStatsPtr data,
+ qemuBlockStatsPtr total)
 {
-qemuBlockStatsPtr data = payload;
-qemuBlockStatsPtr total = opaque;
-
 #define QEMU_BLOCK_STAT_TOTAL(NAME) \
 if (data->NAME > 0) \
 total->NAME += data->NAME
@@ -11070,6 +11066,7 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
 virDomainDiskDefPtr disk;
 virHashTablePtr blockstats = NULL;
 qemuBlockStatsPtr stats;
+size_t i;
 int nstats;
 const char *entryname = NULL;
 int ret = -1;
@@ -1,7 +11108,21 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,

 **retstats = *stats;
 } else {
-virHashForEach(blockstats, qemuDomainBlockStatsGatherTotals, 
*retstats);
+for (i = 0; i < vm->def->ndisks; i++) {
+disk = vm->def->disks[i];
+entryname = disk->info.alias;
+
+if (!entryname)
+continue;
+
+if (!(stats = virHashLookup(blockstats, entryname))) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("cannot find statistics for device '%s'"), 
entryname);
+goto cleanup;
+}
+
+qemuDomainBlockStatsGatherTotals(stats, *retstats);
+}
 }

 ret = nstats;
-- 
2.16.2

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


[libvirt] [PATCHv2 49/62] qemu: monitor: Add APIs for refreshing disk capacity when using -blockdev

2018-08-13 Thread Peter Krempa
Disk image size data are not contained in the reply of query-blockstats
but need to be gathered from query-block. For use with -blockdev we
really need to call 'query-named-block-nodes' and process it to retrieve
the correct data.

This patch introduces qemuMonitorBlockStatsUpdateCapacityBlockdev which
updates the capacity data by nodename rather than device name.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_monitor.c  | 11 +++
 src/qemu/qemu_monitor.h  |  4 
 src/qemu/qemu_monitor_json.c | 46 
 src/qemu/qemu_monitor_json.h |  3 +++
 4 files changed, 64 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 0a29ad7502..f5dca42b38 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2311,6 +2311,17 @@ qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr mon,
 }


+int
+qemuMonitorBlockStatsUpdateCapacityBlockdev(qemuMonitorPtr mon,
+virHashTablePtr stats)
+{
+VIR_DEBUG("stats=%p", stats);
+
+QEMU_CHECK_MONITOR(mon);
+
+return qemuMonitorJSONBlockStatsUpdateCapacityBlockdev(mon, stats);
+}
+
 int
 qemuMonitorBlockResize(qemuMonitorPtr mon,
const char *device,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 649a925829..f83a18f563 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -599,6 +599,10 @@ int qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr mon,
 bool backingChain)
 ATTRIBUTE_NONNULL(2);

+int qemuMonitorBlockStatsUpdateCapacityBlockdev(qemuMonitorPtr mon,
+virHashTablePtr stats)
+ATTRIBUTE_NONNULL(2);
+
 int qemuMonitorBlockResize(qemuMonitorPtr mon,
const char *device,
const char *nodename,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 670147ddb6..438864ac40 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2593,6 +2593,52 @@ qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr 
mon,
 }


+static int
+qemuMonitorJSONBlockStatsUpdateCapacityBlockdevWorker(size_t pos 
ATTRIBUTE_UNUSED,
+  virJSONValuePtr val,
+  void *opaque)
+{
+virHashTablePtr stats = opaque;
+virJSONValuePtr image;
+const char *nodename;
+
+if (!(nodename = virJSONValueObjectGetString(val, "node-name")) ||
+!(image = virJSONValueObjectGetObject(val, "image"))) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("query-named-block-nodes entry was not in expected 
format"));
+return -1;
+}
+
+if (qemuMonitorJSONBlockStatsUpdateCapacityData(image, nodename, stats) < 
0)
+return -1;
+
+return 1; /* we don't want to steal the value from the JSON array */
+}
+
+
+int
+qemuMonitorJSONBlockStatsUpdateCapacityBlockdev(qemuMonitorPtr mon,
+virHashTablePtr stats)
+{
+virJSONValuePtr nodes;
+int ret = -1;
+
+if (!(nodes = qemuMonitorJSONQueryNamedBlockNodes(mon)))
+return -1;
+
+if (virJSONValueArrayForeachSteal(nodes,
+  
qemuMonitorJSONBlockStatsUpdateCapacityBlockdevWorker,
+  stats) < 0)
+goto cleanup;
+
+ret = 0;
+
+ cleanup:
+virJSONValueFree(nodes);
+return ret;
+}
+
+
 int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
const char *device,
const char *nodename,
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 3c5839db38..51214e3797 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -93,6 +93,9 @@ int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
 int qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr mon,
 virHashTablePtr stats,
 bool backingChain);
+int qemuMonitorJSONBlockStatsUpdateCapacityBlockdev(qemuMonitorPtr mon,
+virHashTablePtr stats);
+
 int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
const char *device,
const char *nodename,
-- 
2.16.2

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


[libvirt] [PATCHv2 46/62] qemu: driver: Don't copy disk alias in qemuDomainBlocksStatsGather

2018-08-13 Thread Peter Krempa
The string is not modified so it does not make sense to have a copy.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5dee701dc4..f36d4dc37f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11071,7 +11071,7 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
 virHashTablePtr blockstats = NULL;
 qemuBlockStatsPtr stats;
 int nstats;
-char *diskAlias = NULL;
+const char *entryname = NULL;
 int ret = -1;

 if (*path) {
@@ -11086,8 +11086,7 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
 goto cleanup;
 }

-if (VIR_STRDUP(diskAlias, disk->info.alias) < 0)
-goto cleanup;
+entryname = disk->info.alias;
 }

 qemuDomainObjEnterMonitor(driver, vm);
@@ -11103,10 +11102,10 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
 if (VIR_ALLOC(*retstats) < 0)
 goto cleanup;

-if (diskAlias) {
-if (!(stats = virHashLookup(blockstats, diskAlias))) {
+if (entryname) {
+if (!(stats = virHashLookup(blockstats, entryname))) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("cannot find statistics for device '%s'"), 
diskAlias);
+   _("cannot find statistics for device '%s'"), 
entryname);
 goto cleanup;
 }

@@ -8,7 +7,6 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver,
 ret = nstats;

  cleanup:
-VIR_FREE(diskAlias);
 virHashFree(blockstats);
 return ret;
 }
-- 
2.16.2

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


[libvirt] [PATCHv2 45/62] qemu: hotplug: Implement removable media change for -blockdev

2018-08-13 Thread Peter Krempa
Use the new APIs which allow to manipulate the tray and media separately
and also allow using a nodename to refer to a media to implement media
changing.

With the new approach we don't have to call eject twice as the media is
removed by calling qemuMonitorBlockdevMediumRemove.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_hotplug.c | 95 -
 1 file changed, 94 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 6fde7308f7..9e57bffa48 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -618,6 +618,95 @@ qemuHotplugDiskSourceRemove(qemuMonitorPtr mon,
 }


+/**
+ * qemuDomainChangeMediaBlockdev:
+ * @driver: qemu driver structure
+ * @vm: domain definition
+ * @disk: disk definition to change the source of
+ * @newsrc: new disk source to change to
+ * @force: force the change of media
+ *
+ * Change the media in an ejectable device to the one described by
+ * @newsrc. This function also removes the old source from the
+ * shared device table if appropriate. Note that newsrc is consumed
+ * on success and the old source is freed on success.
+ *
+ * Returns 0 on success, -1 on error and reports libvirt error
+ */
+static int
+qemuDomainChangeMediaBlockdev(virQEMUDriverPtr driver,
+  virDomainObjPtr vm,
+  virDomainDiskDefPtr disk,
+  virStorageSourcePtr newsrc,
+  bool force)
+{
+qemuDomainObjPrivatePtr priv = vm->privateData;
+qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+qemuHotplugDiskSourceDataPtr newbackend = NULL;
+qemuHotplugDiskSourceDataPtr oldbackend = NULL;
+virStorageSourcePtr oldsrc = disk->src;
+char *nodename = NULL;
+int rc;
+int ret = -1;
+
+if (!virStorageSourceIsEmpty(disk->src) &&
+!(oldbackend = qemuHotplugDiskSourceRemovePrepare(disk, 
priv->qemuCaps)))
+goto cleanup;
+
+disk->src = newsrc;
+if (!virStorageSourceIsEmpty(disk->src)) {
+if (!(newbackend = qemuHotplugDiskSourceAttachPrepare(disk,
+  priv->qemuCaps)))
+goto cleanup;
+
+if (qemuDomainDiskGetBackendAlias(disk, priv->qemuCaps, ) < 0)
+goto cleanup;
+}
+
+if (diskPriv->tray && disk->tray_status != VIR_DOMAIN_DISK_TRAY_OPEN) {
+qemuDomainObjEnterMonitor(driver, vm);
+rc = qemuMonitorBlockdevTrayOpen(priv->mon, diskPriv->backendQomName, 
force);
+if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
+goto cleanup;
+
+if (!force && qemuHotplugWaitForTrayEject(vm, disk) < 0)
+goto cleanup;
+}
+
+qemuDomainObjEnterMonitor(driver, vm);
+
+rc = qemuMonitorBlockdevMediumRemove(priv->mon, diskPriv->backendQomName);
+
+if (rc == 0 && oldbackend)
+qemuHotplugDiskSourceRemove(priv->mon, oldbackend);
+
+if (newbackend && nodename) {
+if (rc == 0)
+rc = qemuHotplugDiskSourceAttach(priv->mon, newbackend);
+
+if (rc == 0)
+rc = qemuMonitorBlockdevMediumInsert(priv->mon,
+ diskPriv->backendQomName,
+ nodename);
+}
+
+if (rc == 0)
+rc = qemuMonitorBlockdevTrayClose(priv->mon, diskPriv->backendQomName);
+
+if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
+goto cleanup;
+
+ret = 0;
+
+ cleanup:
+qemuHotplugDiskSourceDataFree(newbackend);
+qemuHotplugDiskSourceDataFree(oldbackend);
+/* caller handles correct exchange of sources */
+disk->src = oldsrc;
+return ret;
+}
+
+
 /**
  * qemuDomainChangeEjectableMedia:
  * @driver: qemu driver structure
@@ -640,6 +729,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
virStorageSourcePtr newsrc,
bool force)
 {
+qemuDomainObjPrivatePtr priv = vm->privateData;
 int ret = -1;
 int rc;

@@ -649,7 +739,10 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
 if (qemuHotplugAttachManagedPR(driver, vm, newsrc, QEMU_ASYNC_JOB_NONE) < 
0)
 goto cleanup;

-rc = qemuDomainChangeMediaLegacy(driver, vm, disk, newsrc, force);
+if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV))
+rc = qemuDomainChangeMediaBlockdev(driver, vm, disk, newsrc, force);
+else
+rc = qemuDomainChangeMediaLegacy(driver, vm, disk, newsrc, force);

 virDomainAuditDisk(vm, disk->src, newsrc, "update", rc >= 0);

-- 
2.16.2

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


[libvirt] [PATCHv2 58/62] qemu: monitor: Report data also for 'qdev' entry in qemuMonitorJSONGetBlockInfo

2018-08-13 Thread Peter Krempa
With -blockdev qemu will not report any useful "device" for the data
returned by 'query-block'. We need to start using the 'qdev' field to do
so in cases when "device" is empty or it does not match the entry name.

This patch adds data for the 'qdev' field into the returned data
structure.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_monitor_json.c | 69 +++-
 1 file changed, 55 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index f98269b34a..6f49de101f 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2209,6 +2209,38 @@ qemuMonitorJSONGetBlockDevDevice(virJSONValuePtr dev)
 }


+static int
+qemuMonitorJSONBlockInfoAdd(virHashTablePtr table,
+struct qemuDomainDiskInfo *info,
+const char *entryname)
+{
+struct qemuDomainDiskInfo *tmp = NULL;
+int ret = -1;
+
+if (VIR_ALLOC(tmp) < 0)
+goto cleanup;
+
+*tmp = *info;
+tmp->nodename = NULL;
+
+if (info->nodename &&
+VIR_STRDUP(tmp->nodename, info->nodename) < 0)
+goto cleanup;
+
+if (virHashAddEntry(table, entryname, tmp) < 0)
+goto cleanup;
+
+tmp = NULL;
+ret = 0;
+
+ cleanup:
+if (tmp)
+VIR_FREE(tmp->nodename);
+VIR_FREE(tmp);
+return ret;
+}
+
+
 int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
 virHashTablePtr table)
 {
@@ -2223,10 +2255,10 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
 for (i = 0; i < virJSONValueArraySize(devices); i++) {
 virJSONValuePtr dev;
 virJSONValuePtr image;
-struct qemuDomainDiskInfo *info;
+struct qemuDomainDiskInfo info = { false };
 const char *thisdev;
 const char *status;
-const char *nodename;
+const char *qdev;

 if (!(dev = qemuMonitorJSONGetBlockDev(devices, i)))
 goto cleanup;
@@ -2235,16 +2267,18 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
 goto cleanup;

 thisdev = qemuAliasDiskDriveSkipPrefix(thisdev);
+qdev = virJSONValueObjectGetString(dev, "qdev");

-if (VIR_ALLOC(info) < 0)
-goto cleanup;
+if (*thisdev == '\0')
+thisdev = NULL;

-if (virHashAddEntry(table, thisdev, info) < 0) {
-VIR_FREE(info);
+if (!qdev && !thisdev) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("query-block device entry was not in expected 
format"));
 goto cleanup;
 }

-if (virJSONValueObjectGetBoolean(dev, "removable", >removable) < 
0) {
+if (virJSONValueObjectGetBoolean(dev, "removable", ) < 
0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot read %s value"),
"removable");
@@ -2252,23 +2286,30 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
 }

 /* 'tray_open' is present only if the device has a tray */
-if (virJSONValueObjectGetBoolean(dev, "tray_open", >tray_open) 
== 0)
-info->tray = true;
+if (virJSONValueObjectGetBoolean(dev, "tray_open", _open) == 
0)
+info.tray = true;

 /* presence of 'inserted' notifies that a medium is in the device */
 if ((image = virJSONValueObjectGetObject(dev, "inserted"))) {
-if ((nodename = virJSONValueObjectGetString(image, "node-name")))
-ignore_value(VIR_STRDUP(info->nodename, nodename));
+info.nodename = (char *) virJSONValueObjectGetString(image, 
"node-name");
 } else {
-info->empty = true;
+info.empty = true;
 }

 /* Missing io-status indicates no error */
 if ((status = virJSONValueObjectGetString(dev, "io-status"))) {
-info->io_status = qemuMonitorBlockIOStatusToError(status);
-if (info->io_status < 0)
+info.io_status = qemuMonitorBlockIOStatusToError(status);
+if (info.io_status < 0)
 goto cleanup;
 }
+
+if (thisdev &&
+qemuMonitorJSONBlockInfoAdd(table, , thisdev) < 0)
+goto cleanup;
+
+if (qdev && STRNEQ_NULLABLE(thisdev, qdev) &&
+qemuMonitorJSONBlockInfoAdd(table, , qdev) < 0)
+goto cleanup;
 }

 ret = 0;
-- 
2.16.2

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


[libvirt] [PATCHv2 56/62] qemu: Report frontend stats only for the frontend entry

2018-08-13 Thread Peter Krempa
When reporting stats for the backing chain some of them make sense only
for the topmost entry as they are actually tied to the frontend device.
We unfortunately can't change that fact, but we can stop reporting all
zero stats for the backing chain members where they don't make any
sense.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e8e8bdbb14..c09108b57e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20209,9 +20209,12 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr 
disk,
 records, nrecords) < 0)
 goto cleanup;

-if (qemuDomainGetStatsBlockExportFrontend(alias, stats, *recordnr,
-  records, nrecords) < 0)
-goto cleanup;
+/* The following stats make sense only for the frontend device */
+if (n == disk->src) {
+if (qemuDomainGetStatsBlockExportFrontend(alias, stats, *recordnr,
+  records, nrecords) < 0)
+goto cleanup;
+}

 if (qemuDomainGetStatsOneBlock(driver, cfg, dom, records, nrecords,
alias, n, *recordnr,
-- 
2.16.2

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


[libvirt] [PATCHv2 42/62] qemu: monitor: Handle BLOCK_IO_ERROR event properly with -blockdev

2018-08-13 Thread Peter Krempa
Use the 'node-name' provided in the event if 'device' is empty to look
up the disk.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_monitor.c  |  3 ++-
 src/qemu/qemu_monitor.h  |  2 ++
 src/qemu/qemu_monitor_json.c |  5 -
 src/qemu/qemu_process.c  | 12 +++-
 4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index cdfcbcea0b..49dc478f5b 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1421,6 +1421,7 @@ qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action)
 int
 qemuMonitorEmitIOError(qemuMonitorPtr mon,
const char *diskAlias,
+   const char *nodename,
int action,
const char *reason)
 {
@@ -1428,7 +1429,7 @@ qemuMonitorEmitIOError(qemuMonitorPtr mon,
 VIR_DEBUG("mon=%p", mon);

 QEMU_MONITOR_CALLBACK(mon, ret, domainIOError, mon->vm,
-  diskAlias, action, reason);
+  diskAlias, nodename, action, reason);
 return ret;
 }

diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 1c66459e69..70854497b2 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -155,6 +155,7 @@ typedef int 
(*qemuMonitorDomainWatchdogCallback)(qemuMonitorPtr mon,
 typedef int (*qemuMonitorDomainIOErrorCallback)(qemuMonitorPtr mon,
 virDomainObjPtr vm,
 const char *diskAlias,
+const char *nodename,
 int action,
 const char *reason,
 void *opaque);
@@ -383,6 +384,7 @@ int qemuMonitorEmitRTCChange(qemuMonitorPtr mon, long long 
offset);
 int qemuMonitorEmitWatchdog(qemuMonitorPtr mon, int action);
 int qemuMonitorEmitIOError(qemuMonitorPtr mon,
const char *diskAlias,
+   const char *nodename,
int action,
const char *reason);
 int qemuMonitorEmitGraphics(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 537cdfd19a..2b168d96c2 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -765,6 +765,7 @@ static void
 qemuMonitorJSONHandleIOError(qemuMonitorPtr mon, virJSONValuePtr data)
 {
 const char *device;
+const char *nodename;
 const char *action;
 const char *reason = "";
 bool nospc = false;
@@ -782,6 +783,8 @@ qemuMonitorJSONHandleIOError(qemuMonitorPtr mon, 
virJSONValuePtr data)
 if ((device = virJSONValueObjectGetString(data, "device")) == NULL)
 VIR_WARN("missing device in disk io error event");

+nodename = virJSONValueObjectGetString(data, "node-name");
+
 if (virJSONValueObjectGetBoolean(data, "nospace", ) == 0 && nospc)
 reason = "enospc";

@@ -790,7 +793,7 @@ qemuMonitorJSONHandleIOError(qemuMonitorPtr mon, 
virJSONValuePtr data)
 actionID = VIR_DOMAIN_EVENT_IO_ERROR_NONE;
 }

-qemuMonitorEmitIOError(mon, device, actionID, reason);
+qemuMonitorEmitIOError(mon, device, nodename, actionID, reason);
 }


diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 40e2589b37..6e0b4b0027 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -855,6 +855,7 @@ static int
 qemuProcessHandleIOError(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
  virDomainObjPtr vm,
  const char *diskAlias,
+ const char *nodename,
  int action,
  const char *reason,
  void *opaque)
@@ -869,7 +870,16 @@ qemuProcessHandleIOError(qemuMonitorPtr mon 
ATTRIBUTE_UNUSED,
 virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);

 virObjectLock(vm);
-disk = qemuProcessFindDomainDiskByAliasOrQOM(vm, diskAlias, NULL);
+
+if (*diskAlias == '\0')
+diskAlias = NULL;
+
+if (diskAlias)
+disk = qemuProcessFindDomainDiskByAliasOrQOM(vm, diskAlias, NULL);
+else if (nodename)
+disk = qemuDomainDiskLookupByNodename(vm->def, nodename, NULL, NULL);
+else
+disk = NULL;

 if (disk) {
 srcPath = virDomainDiskGetSource(disk);
-- 
2.16.2

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


[libvirt] [PATCHv2 43/62] qemu: hotplug: Prepare for blockdev-add/blockdev-del with backing chains

2018-08-13 Thread Peter Krempa
Initialize data for the whole backing chain when plugging in or removing
disks when a machine supports -blockdev.

Similarly to startup we need to prepare the structures for the whole
backing chain and take care of the copy-on-read feature.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_hotplug.c | 77 +++--
 1 file changed, 62 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 32d0c3862e..6fde7308f7 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -380,6 +380,10 @@ qemuHotplugRemoveManagedPR(virQEMUDriverPtr driver,
 struct _qemuHotplugDiskSourceData {
 qemuBlockStorageSourceAttachDataPtr *backends;
 size_t nbackends;
+
+/* disk copy-on-read object */
+virJSONValuePtr corProps;
+char *corAlias;
 };
 typedef struct _qemuHotplugDiskSourceData qemuHotplugDiskSourceData;
 typedef qemuHotplugDiskSourceData *qemuHotplugDiskSourceDataPtr;
@@ -393,6 +397,9 @@ qemuHotplugDiskSourceDataFree(qemuHotplugDiskSourceDataPtr 
data)
 if (!data)
 return;

+virJSONValueFree(data->corProps);
+VIR_FREE(data->corAlias);
+
 for (i = 0; i < data->nbackends; i++)
 qemuBlockStorageSourceAttachDataFree(data->backends[i]);

@@ -461,25 +468,40 @@ 
qemuHotplugRemoveStorageSourcePrepareData(virStorageSourcePtr src,

 static qemuHotplugDiskSourceDataPtr
 qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
-   virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED)
+   virQEMUCapsPtr qemuCaps)
 {
+qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
 qemuBlockStorageSourceAttachDataPtr backend = NULL;
 qemuHotplugDiskSourceDataPtr data = NULL;
 qemuHotplugDiskSourceDataPtr ret = NULL;
 char *drivealias = NULL;
+virStorageSourcePtr n;

 if (VIR_ALLOC(data) < 0)
 return NULL;

-if (!(drivealias = qemuAliasDiskDriveFromDisk(disk)))
-goto cleanup;
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (VIR_STRDUP(data->corAlias, diskPriv->nodeCopyOnRead) < 0)
+goto cleanup;

-if (!(backend = qemuHotplugRemoveStorageSourcePrepareData(disk->src,
-  drivealias)))
-goto cleanup;
+for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) 
{
+if (!(backend = qemuHotplugRemoveStorageSourcePrepareData(n, 
NULL)))
+goto cleanup;

-if (VIR_APPEND_ELEMENT(data->backends, data->nbackends, backend) < 0)
-goto cleanup;
+if (VIR_APPEND_ELEMENT(data->backends, data->nbackends, backend) < 
0)
+goto cleanup;
+}
+} else {
+if (!(drivealias = qemuAliasDiskDriveFromDisk(disk)))
+goto cleanup;
+
+if (!(backend = qemuHotplugRemoveStorageSourcePrepareData(disk->src,
+  drivealias)))
+goto cleanup;
+
+if (VIR_APPEND_ELEMENT(data->backends, data->nbackends, backend) < 0)
+goto cleanup;
+}

 VIR_STEAL_PTR(ret, data);

@@ -502,21 +524,39 @@ static qemuHotplugDiskSourceDataPtr
 qemuHotplugDiskSourceAttachPrepare(virDomainDiskDefPtr disk,
virQEMUCapsPtr qemuCaps)
 {
-qemuBlockStorageSourceAttachDataPtr backend;
+qemuBlockStorageSourceAttachDataPtr backend = NULL;
 qemuHotplugDiskSourceDataPtr data;
 qemuHotplugDiskSourceDataPtr ret = NULL;
+virStorageSourcePtr n;

 if (VIR_ALLOC(data) < 0)
 return NULL;

-if (!(backend = qemuBuildStorageSourceAttachPrepareDrive(disk, qemuCaps)))
-goto cleanup;
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON &&
+!(data->corProps = qemuBlockStorageGetCopyOnReadProps(disk)))
+goto cleanup;

-if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, backend, 
qemuCaps) < 0)
-goto cleanup;
+for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) 
{
+if (!(backend = qemuBlockStorageSourceAttachPrepareBlockdev(n)))
+goto cleanup;

-if (VIR_APPEND_ELEMENT(data->backends, data->nbackends, backend) < 0)
-goto cleanup;
+if (qemuBuildStorageSourceAttachPrepareCommon(n, backend, 
qemuCaps) < 0)
+goto cleanup;
+
+if (VIR_APPEND_ELEMENT(data->backends, data->nbackends, backend) < 
0)
+goto cleanup;
+}
+} else {
+if (!(backend = qemuBuildStorageSourceAttachPrepareDrive(disk, 
qemuCaps)))
+goto cleanup;
+
+if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, backend, 
qemuCaps) < 0)
+goto cleanup;
+
+if (VIR_APPEND_ELEMENT(data->backends, data->nbackends, backend) < 0)
+goto 

[libvirt] [PATCHv2 44/62] qemu: monitor: Add APIs for cdrom tray handling for -blockdev

2018-08-13 Thread Peter Krempa
With blockdev we can use the full range of commands to manipulate the
tray and the medium separately. Implement monitor code for this.

Schema testing done in the qemumonitorjsontest allows us to verify that
we generate the commands correctly.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_monitor.c  |  51 +++
 src/qemu/qemu_monitor.h  |  14 ++
 src/qemu/qemu_monitor_json.c | 114 +++
 src/qemu/qemu_monitor_json.h |  18 +++
 tests/qemumonitorjsontest.c  |   8 +++
 5 files changed, 205 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 49dc478f5b..0a29ad7502 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -4336,6 +4336,57 @@ qemuMonitorBlockdevDel(qemuMonitorPtr mon,
 return qemuMonitorJSONBlockdevDel(mon, nodename);
 }

+int
+qemuMonitorBlockdevTrayOpen(qemuMonitorPtr mon,
+const char *id,
+bool force)
+{
+VIR_DEBUG("id=%s force=%d", id, force);
+
+QEMU_CHECK_MONITOR(mon);
+
+return qemuMonitorJSONBlockdevTrayOpen(mon, id, force);
+}
+
+
+int
+qemuMonitorBlockdevTrayClose(qemuMonitorPtr mon,
+ const char *id)
+{
+VIR_DEBUG("id=%s", id);
+
+QEMU_CHECK_MONITOR(mon);
+
+return qemuMonitorJSONBlockdevTrayClose(mon, id);
+}
+
+
+int
+qemuMonitorBlockdevMediumRemove(qemuMonitorPtr mon,
+const char *id)
+{
+VIR_DEBUG("id=%s", id);
+
+QEMU_CHECK_MONITOR(mon);
+
+return qemuMonitorJSONBlockdevMediumRemove(mon, id);
+}
+
+
+
+int
+qemuMonitorBlockdevMediumInsert(qemuMonitorPtr mon,
+const char *id,
+const char *nodename)
+{
+VIR_DEBUG("id=%s nodename=%s", id, nodename);
+
+QEMU_CHECK_MONITOR(mon);
+
+return qemuMonitorJSONBlockdevMediumInsert(mon, id, nodename);
+}
+
+
 char *
 qemuMonitorGetSEVMeasurement(qemuMonitorPtr mon)
 {
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 70854497b2..649a925829 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1155,6 +1155,20 @@ int qemuMonitorBlockdevAdd(qemuMonitorPtr mon,
 int qemuMonitorBlockdevDel(qemuMonitorPtr mon,
const char *nodename);

+int qemuMonitorBlockdevTrayOpen(qemuMonitorPtr mon,
+const char *id,
+bool force);
+
+int qemuMonitorBlockdevTrayClose(qemuMonitorPtr mon,
+ const char *id);
+
+int qemuMonitorBlockdevMediumRemove(qemuMonitorPtr mon,
+const char *id);
+
+int qemuMonitorBlockdevMediumInsert(qemuMonitorPtr mon,
+const char *id,
+const char *nodename);
+
 char *
 qemuMonitorGetSEVMeasurement(qemuMonitorPtr mon);

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 2b168d96c2..3351d405f3 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -8012,6 +8012,120 @@ qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon,
 return ret;
 }

+
+int
+qemuMonitorJSONBlockdevTrayOpen(qemuMonitorPtr mon,
+const char *id,
+bool force)
+{
+virJSONValuePtr cmd;
+virJSONValuePtr reply = NULL;
+int ret = -1;
+
+if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-open-tray",
+   "s:id", id,
+   "b:force", force, NULL)))
+return -1;
+
+if (qemuMonitorJSONCommand(mon, cmd, ) < 0)
+goto cleanup;
+
+if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+goto cleanup;
+
+ret = 0;
+
+ cleanup:
+virJSONValueFree(cmd);
+virJSONValueFree(reply);
+return ret;
+}
+
+
+int
+qemuMonitorJSONBlockdevTrayClose(qemuMonitorPtr mon,
+ const char *id)
+{
+virJSONValuePtr cmd;
+virJSONValuePtr reply = NULL;
+int ret = -1;
+
+if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-close-tray",
+   "s:id", id, NULL)))
+return -1;
+
+if (qemuMonitorJSONCommand(mon, cmd, ) < 0)
+goto cleanup;
+
+if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+goto cleanup;
+
+ret = 0;
+
+ cleanup:
+virJSONValueFree(cmd);
+virJSONValueFree(reply);
+return ret;
+}
+
+
+int
+qemuMonitorJSONBlockdevMediumRemove(qemuMonitorPtr mon,
+const char *id)
+{
+virJSONValuePtr cmd;
+virJSONValuePtr reply = NULL;
+int ret = -1;
+
+if (!(cmd = qemuMonitorJSONMakeCommand("blockdev-remove-medium",
+   "s:id", id, NULL)))
+return -1;
+
+if (qemuMonitorJSONCommand(mon, cmd, ) < 0)
+goto cleanup;
+
+if (qemuMonitorJSONCheckError(cmd, 

[libvirt] [PATCHv2 39/62] qemu: driver: Prepare qemuDomainBlockResize for blockdev

2018-08-13 Thread Peter Krempa
Use the nodename to resize the device rather than the drive alias.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 18 +++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fb09278112..f745a0392a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10945,6 +10945,7 @@ qemuDomainBlockResize(virDomainPtr dom,
 qemuDomainObjPrivatePtr priv;
 int ret = -1;
 char *device = NULL;
+const char *nodename = NULL;
 virDomainDiskDefPtr disk = NULL;

 virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1);
@@ -10987,11 +10988,22 @@ qemuDomainBlockResize(virDomainPtr dom,
 disk->src->format == VIR_STORAGE_FILE_QED)
 size = VIR_ROUND_UP(size, 512);

-if (!(device = qemuAliasDiskDriveFromDisk(disk)))
-goto endjob;
+if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (virStorageSourceIsEmpty(disk->src) || disk->src->readonly) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+   _("can't resize empty or readonly disk '%s'"),
+   disk->dst);
+goto endjob;
+}
+
+nodename = disk->src->nodeformat;
+} else {
+if (!(device = qemuAliasDiskDriveFromDisk(disk)))
+goto endjob;
+}

 qemuDomainObjEnterMonitor(driver, vm);
-if (qemuMonitorBlockResize(priv->mon, device, NULL, size) < 0) {
+if (qemuMonitorBlockResize(priv->mon, device, nodename, size) < 0) {
 ignore_value(qemuDomainObjExitMonitor(driver, vm));
 goto endjob;
 }
-- 
2.16.2

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


[libvirt] [PATCHv2 50/62] qemu: driver: Don't pass 'virDomainDiskDefPtr' to qemuDomainGetStatsOneBlock

2018-08-13 Thread Peter Krempa
Allow reuse of qemuDomainGetStatsOneBlock to work with nodenames by
removing the code that looks up the stats data to the caller.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 24 +++-
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e18187b7bb..63ce68bd35 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20061,7 +20061,8 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
virDomainObjPtr dom,
virDomainStatsRecordPtr record,
int *maxparams,
-   virDomainDiskDefPtr disk,
+   const char *diskdst,
+   const char *entryname,
virStorageSourcePtr src,
size_t block_idx,
virHashTablePtr stats,
@@ -20069,13 +20070,9 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
 {
 qemuBlockStats *entry;
 int ret = -1;
-char *alias = NULL;

-if (disk->info.alias)
-alias = qemuDomainStorageAlias(disk->info.alias, src->id);
+QEMU_ADD_NAME_PARAM(record, maxparams, "block", "name", block_idx, 
diskdst);

-QEMU_ADD_NAME_PARAM(record, maxparams, "block", "name", block_idx,
-disk->dst);
 if (virStorageSourceIsLocalStorage(src) && src->path)
 QEMU_ADD_NAME_PARAM(record, maxparams, "block", "path",
 block_idx, src->path);
@@ -20094,7 +20091,7 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
 /* In case where qemu didn't provide the stats we stop here rather than
  * trying to refresh the stats from the disk. Inability to provide stats is
  * usually caused by blocked storage so this would make libvirtd hang */
-if (!stats || !alias || !(entry = virHashLookup(stats, alias))) {
+if (!stats || !entryname || !(entry = virHashLookup(stats, entryname))) {
 ret = 0;
 goto cleanup;
 }
@@ -20140,7 +20137,6 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,

 ret = 0;
  cleanup:
-VIR_FREE(alias);
 return ret;
 }

@@ -20165,6 +20161,7 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
 int count_index = -1;
 size_t visited = 0;
 bool visitBacking = !!(privflags & QEMU_DOMAIN_STATS_BACKING);
+char *alias = NULL;

 if (HAVE_JOB(privflags) && virDomainObjIsActive(dom)) {
 qemuDomainObjEnterMonitor(driver, dom);
@@ -20201,10 +20198,18 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,

 while (virStorageSourceIsBacking(src) &&
(src == disk->src || visitBacking)) {
+
+/* alias may be NULL if the VM is not running */
+if (disk->info.alias &&
+!(alias = qemuDomainStorageAlias(disk->info.alias, src->id)))
+goto cleanup;
+
 if (qemuDomainGetStatsOneBlock(driver, cfg, dom, record, maxparams,
-   disk, src, visited,
+   disk->dst, alias, src, visited,
stats, nodestats) < 0)
 goto cleanup;
+
+VIR_FREE(alias);
 visited++;
 src = src->backingStore;
 }
@@ -20214,6 +20219,7 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
 ret = 0;

  cleanup:
+VIR_FREE(alias);
 virHashFree(stats);
 virHashFree(nodestats);
 virJSONValueFree(nodedata);
-- 
2.16.2

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


[libvirt] [PATCHv2 33/62] qemu: block: Add generator for the 'copy-on-read' blockdev driver

2018-08-13 Thread Peter Krempa
The copy on read functionality is done using a separate layer in the
backing chain. Add function to generate properties for it.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_block.c | 22 ++
 src/qemu/qemu_block.h |  2 ++
 2 files changed, 24 insertions(+)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index ccdd334367..5321dda316 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -1745,3 +1745,25 @@ qemuBlockSnapshotAddLegacy(virJSONValuePtr actions,
 VIR_FREE(source);
 return ret;
 }
+
+
+/**
+ * qemuBlockStorageGetCopyOnReadProps:
+ * @disk: disk with copy-on-read enabled
+ *
+ * Creates blockdev properties for a disk copy-on-read layer.
+ */
+virJSONValuePtr
+qemuBlockStorageGetCopyOnReadProps(virDomainDiskDefPtr disk)
+{
+qemuDomainDiskPrivatePtr priv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+virJSONValuePtr ret = NULL;
+
+ignore_value(virJSONValueObjectCreate(,
+  "s:driver", "copy-on-read",
+  "s:node-name", priv->nodeCopyOnRead,
+  "s:file", disk->src->nodeformat,
+  NULL));
+
+return ret;
+}
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index fd8984e60b..62ed5027cb 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -67,6 +67,8 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src);
 virJSONValuePtr
 qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src);

+virJSONValuePtr
+qemuBlockStorageGetCopyOnReadProps(virDomainDiskDefPtr disk);

 typedef struct qemuBlockStorageSourceAttachData 
qemuBlockStorageSourceAttachData;
 typedef qemuBlockStorageSourceAttachData *qemuBlockStorageSourceAttachDataPtr;
-- 
2.16.2

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


[libvirt] [PATCHv2 30/62] qemu: command: Setup floppy drives via -device for blockdev

2018-08-13 Thread Peter Krempa
To allow referring to the drives via the QOM id we need to setup the
floppy drives with a proper ID. This means that -device should be used
for them.

There are the following quirks:
- FDC needs to be instantiated prior to any floppy device
- floppy drive specified via -device does not support 'bootindex'
(hacked around by passing bootindexA=1 to the FDC)

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c | 42 +++---
 1 file changed, 31 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a3fadc505d..72fdffa92a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2060,6 +2060,10 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
 goto error;
 break;

+case VIR_DOMAIN_DISK_BUS_FDC:
+virBufferAsprintf(, "floppy,unit=%d", disk->info.addr.drive.unit);
+break;
+
 default:
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("unsupported disk bus '%s' with device setup"), bus);
@@ -2181,17 +2185,20 @@ 
qemuBuildFloppyCommandLineControllerOptions(virCommandPtr cmd,
 else
 driveLetter = 'A';

-if (qemuDomainDiskGetBackendAlias(disk, qemuCaps, ) < 0)
-goto cleanup;
-
-if (backendAlias &&
-virAsprintf(, "drive%c=%s", driveLetter, backendAlias) 
< 0)
-goto cleanup;
-
 if (bootindex &&
 virAsprintf(, "bootindex%c=%u", driveLetter, 
bootindex) < 0)
 goto cleanup;

+/* with -blockdev we setup the floppy device and it's backend with 
-device */
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (qemuDomainDiskGetBackendAlias(disk, qemuCaps, ) < 
0)
+goto cleanup;
+
+if (backendAlias &&
+virAsprintf(, "drive%c=%s", driveLetter, 
backendAlias) < 0)
+goto cleanup;
+}
+
 if (!explicitfdc) {
 if (backendStr) {
 virCommandAddArg(cmd, "-global");
@@ -2303,7 +2310,8 @@ qemuBuildDiskCommandLine(virCommandPtr cmd,
 return -1;

 if (!qemuDiskBusNeedsDriveArg(disk->bus)) {
-if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC) {
+if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC ||
+virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
 virCommandAddArg(cmd, "-device");

 if (!(optstr = qemuBuildDiskDeviceStr(def, disk, bootindex,
@@ -2327,6 +2335,7 @@ qemuBuildDisksCommandLine(virCommandPtr cmd,
 unsigned int bootCD = 0;
 unsigned int bootFloppy = 0;
 unsigned int bootDisk = 0;
+bool blockdev = virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV);

 for (i = 0; i < def->os.nBootDevs; i++) {
 switch (def->os.bootDevs[i]) {
@@ -2342,6 +2351,12 @@ qemuBuildDisksCommandLine(virCommandPtr cmd,
 }
 }

+/* If we want to express the floppy drives via -device, the controller 
needs
+ * to be instantiated prior to that */
+if (blockdev &&
+qemuBuildFloppyCommandLineControllerOptions(cmd, def, qemuCaps, 
bootFloppy) < 0)
+return -1;
+
 for (i = 0; i < def->ndisks; i++) {
 virDomainDiskDefPtr disk = def->disks[i];
 unsigned int bootindex = 0;
@@ -2362,12 +2377,17 @@ qemuBuildDisksCommandLine(virCommandPtr cmd,
 }
 }

-if (qemuBuildDiskCommandLine(cmd, def, disk, qemuCaps,
- bootindex) < 0)
+/* The floppy device itself does not support the bootindex property
+ * so we need to set it up for the controller */
+if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
+bootindex = 0;
+
+if (qemuBuildDiskCommandLine(cmd, def, disk, qemuCaps, bootindex) < 0)
 return -1;
 }

-if (qemuBuildFloppyCommandLineControllerOptions(cmd, def, qemuCaps, 
bootFloppy) < 0)
+if (!blockdev &&
+qemuBuildFloppyCommandLineControllerOptions(cmd, def, qemuCaps, 
bootFloppy) < 0)
 return -1;

 return 0;
-- 
2.16.2

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


[libvirt] [PATCHv2 40/62] qemu: process: Add lookup via QOM id to qemuProcessFindDomainDiskByAlias

2018-08-13 Thread Peter Krempa
Allow looking up also via QOM id and rename the function accordingly.
Also add documentation of the specifics.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c  |  2 +-
 src/qemu/qemu_process.c | 42 +++---
 src/qemu/qemu_process.h |  5 +++--
 3 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f745a0392a..5dee701dc4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4727,7 +4727,7 @@ processBlockJobEvent(virQEMUDriverPtr driver,
 goto endjob;
 }

-if ((disk = qemuProcessFindDomainDiskByAlias(vm, diskAlias)))
+if ((disk = qemuProcessFindDomainDiskByAliasOrQOM(vm, diskAlias, NULL)))
 qemuBlockJobEventProcess(driver, vm, disk, QEMU_ASYNC_JOB_NONE, type, 
status);

  endjob:
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 3495733041..b713afa3a2 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -350,28 +350,48 @@ qemuProcessHandleMonitorError(qemuMonitorPtr mon 
ATTRIBUTE_UNUSED,
 }


+/**
+ * qemuProcessFindDomainDiskByAliasOrQOM:
+ * @vm: domain object to search for the disk
+ * @alias: -drive or -device alias of the disk
+ * @qomid: QOM tree device name
+ *
+ * Looks up a disk in the domain definition of @vm which either matches the
+ * -drive or -device alias used for the backend and frontend respectively or 
the
+ *  QOM name. If @alias is empty it's treated as NULL as it's a mandatory field
+ *  in some cases.
+ *
+ *  Returns a disk from @vm or NULL if it could not be found.
+ */
 virDomainDiskDefPtr
-qemuProcessFindDomainDiskByAlias(virDomainObjPtr vm,
- const char *alias)
+qemuProcessFindDomainDiskByAliasOrQOM(virDomainObjPtr vm,
+  const char *alias,
+  const char *qomid)
 {
 size_t i;

-alias = qemuAliasDiskDriveSkipPrefix(alias);
+if (*alias == '\0')
+alias = NULL;
+
+if (alias)
+alias = qemuAliasDiskDriveSkipPrefix(alias);

 for (i = 0; i < vm->def->ndisks; i++) {
-virDomainDiskDefPtr disk;
+virDomainDiskDefPtr disk = vm->def->disks[i];
+qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);

-disk = vm->def->disks[i];
-if (disk->info.alias != NULL && STREQ(disk->info.alias, alias))
+if ((disk->info.alias && STREQ_NULLABLE(disk->info.alias, alias)) ||
+(diskPriv->backendQomName && 
STREQ_NULLABLE(diskPriv->backendQomName, qomid)))
 return disk;
 }

 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("no disk found with alias %s"),
-   alias);
+   _("no disk found with alias '%s' or id '%s'"),
+   NULLSTR(alias), NULLSTR(qomid));
 return NULL;
 }

+
 static int
 qemuProcessHandleReset(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virDomainObjPtr vm,
@@ -849,7 +869,7 @@ qemuProcessHandleIOError(qemuMonitorPtr mon 
ATTRIBUTE_UNUSED,
 virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);

 virObjectLock(vm);
-disk = qemuProcessFindDomainDiskByAlias(vm, diskAlias);
+disk = qemuProcessFindDomainDiskByAliasOrQOM(vm, diskAlias, NULL);

 if (disk) {
 srcPath = virDomainDiskGetSource(disk);
@@ -912,7 +932,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon 
ATTRIBUTE_UNUSED,
 VIR_DEBUG("Block job for device %s (domain: %p,%s) type %d status %d",
   diskAlias, vm, vm->def->name, type, status);

-if (!(disk = qemuProcessFindDomainDiskByAlias(vm, diskAlias)))
+if (!(disk = qemuProcessFindDomainDiskByAliasOrQOM(vm, diskAlias, NULL)))
 goto error;
 diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);

@@ -1050,7 +1070,7 @@ qemuProcessHandleTrayChange(qemuMonitorPtr mon 
ATTRIBUTE_UNUSED,
 virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);

 virObjectLock(vm);
-disk = qemuProcessFindDomainDiskByAlias(vm, devAlias);
+disk = qemuProcessFindDomainDiskByAliasOrQOM(vm, devAlias, NULL);

 if (disk) {
 event = virDomainEventTrayChangeNewFromObj(vm, disk->info.alias, 
reason);
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 07ce3a9915..c2f7c2b5d2 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -187,8 +187,9 @@ bool qemuProcessAutoDestroyActive(virQEMUDriverPtr driver,
 int qemuProcessSetSchedParams(int id, pid_t pid, size_t nsp,
   virDomainThreadSchedParamPtr sp);

-virDomainDiskDefPtr qemuProcessFindDomainDiskByAlias(virDomainObjPtr vm,
- const char *alias);
+virDomainDiskDefPtr qemuProcessFindDomainDiskByAliasOrQOM(virDomainObjPtr vm,
+  const char *alias,
+  const char *qomid);

 int 

[libvirt] [PATCHv2 55/62] qemu: Refactor control flow in qemuDomainGetStatsBlockExportDisk

2018-08-13 Thread Peter Krempa
Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 479bf3adfe..e8e8bdbb14 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20194,20 +20194,18 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr 
disk,

 {
 char *alias = NULL;
-virStorageSourcePtr src = disk->src;
+virStorageSourcePtr n;
 int ret = -1;

-while (virStorageSourceIsBacking(src) &&
-   (src == disk->src || visitBacking)) {
-
+for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
 /* alias may be NULL if the VM is not running */
 if (disk->info.alias &&
-!(alias = qemuDomainStorageAlias(disk->info.alias, src->id)))
+!(alias = qemuDomainStorageAlias(disk->info.alias, n->id)))
 goto cleanup;

-qemuDomainGetStatsOneBlockRefreshNamed(src, alias, stats, nodestats);
+qemuDomainGetStatsOneBlockRefreshNamed(n, alias, stats, nodestats);

-if (qemuDomainGetStatsBlockExportHeader(disk, src, *recordnr,
+if (qemuDomainGetStatsBlockExportHeader(disk, n, *recordnr,
 records, nrecords) < 0)
 goto cleanup;

@@ -20216,13 +20214,15 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr 
disk,
 goto cleanup;

 if (qemuDomainGetStatsOneBlock(driver, cfg, dom, records, nrecords,
-   alias, src, *recordnr,
+   alias, n, *recordnr,
stats) < 0)
 goto cleanup;

 VIR_FREE(alias);
 (*recordnr)++;
-src = src->backingStore;
+
+if (!visitBacking)
+break;
 }

 ret = 0;
-- 
2.16.2

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


[libvirt] [PATCHv2 32/62] qemu: proces: assign node names for user defined backing chains

2018-08-13 Thread Peter Krempa
Prepare the full backing chain by instantiating authentication and TLS
transport secrets and other necessary objects so that we can add the
full backing chain explicitly to qemu. This also includes allocation of
nodenames for the individual backing chain members.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_domain.c | 77 --
 1 file changed, 75 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e0dd3c0b15..fc2a3d9f60 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -137,6 +137,14 @@ static virClassPtr qemuDomainSaveCookieClass;
 static void qemuDomainLogContextDispose(void *obj);
 static void qemuDomainSaveCookieDispose(void *obj);

+
+static int
+qemuDomainPrepareStorageSourceBlockdev(virDomainDiskDefPtr disk,
+   virStorageSourcePtr src,
+   qemuDomainObjPrivatePtr priv,
+   virQEMUDriverConfigPtr cfg);
+
+
 static int
 qemuDomainOnceInit(void)
 {
@@ -8653,6 +8661,10 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,

 if (qemuDomainPrepareDiskSourceData(disk, n, cfg, priv->qemuCaps) < 0)
 goto cleanup;
+
+if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
+qemuDomainPrepareStorageSourceBlockdev(disk, n, priv, cfg) < 0)
+goto cleanup;
 }

 ret = 0;
@@ -13103,6 +13115,62 @@ qemuDomainPrepareDiskSourceLegacy(virDomainDiskDefPtr 
disk,
 }


+static int
+qemuDomainPrepareStorageSourceBlockdev(virDomainDiskDefPtr disk,
+   virStorageSourcePtr src,
+   qemuDomainObjPrivatePtr priv,
+   virQEMUDriverConfigPtr cfg)
+{
+src->id = qemuDomainStorageIdNew(priv);
+
+if (virAsprintf(>nodestorage, "libvirt-%u-storage", src->id) < 0 ||
+virAsprintf(>nodeformat, "libvirt-%u-format", src->id) < 0)
+return -1;
+
+if (qemuDomainValidateStorageSource(src, priv->qemuCaps) < 0)
+return -1;
+
+if (qemuDomainPrepareDiskSourceData(disk, src, cfg, priv->qemuCaps) < 0)
+return -1;
+
+if (qemuDomainSecretStorageSourcePrepare(priv, src,
+ src->nodestorage,
+ src->nodeformat) < 0)
+return -1;
+
+if (qemuDomainPrepareStorageSourcePR(disk->src, priv, src->nodestorage) < 
0)
+return -1;
+
+if (qemuDomainPrepareStorageSourceTLS(disk->src, cfg, src->nodestorage,
+  priv->qemuCaps) < 0)
+return -1;
+
+return 0;
+}
+
+
+static int
+qemuDomainPrepareDiskSourceBlockdev(virDomainDiskDefPtr disk,
+qemuDomainObjPrivatePtr priv,
+virQEMUDriverConfigPtr cfg)
+{
+qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+virStorageSourcePtr n;
+
+if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON &&
+!diskPriv->nodeCopyOnRead &&
+virAsprintf(>nodeCopyOnRead, "libvirt-CoR-%s", disk->dst) < 
0)
+return -1;
+
+for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
+if (qemuDomainPrepareStorageSourceBlockdev(disk, n, priv, cfg) < 0)
+return -1;
+}
+
+return 0;
+}
+
+
 int
 qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk,
 qemuDomainObjPrivatePtr priv,
@@ -13110,8 +13178,13 @@ qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk,
 {
 qemuDomainPrepareDiskCachemode(disk);

-if (qemuDomainPrepareDiskSourceLegacy(disk, priv, cfg) < 0)
-return -1;
+if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (qemuDomainPrepareDiskSourceBlockdev(disk, priv, cfg) < 0)
+return -1;
+} else {
+if (qemuDomainPrepareDiskSourceLegacy(disk, priv, cfg) < 0)
+return -1;
+}

 return 0;
 }
-- 
2.16.2

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


[libvirt] [PATCHv2 48/62] qemu: monitor: Retrieve blockstats also by qdev and node-names

2018-08-13 Thread Peter Krempa
For use with -blockdev we need to be able to retrieve the stats by
'qdev' for the frontend device stats since 'device' will be empty. Note
that for non-blockdev case qdev and 'device' with 'drive-' skipped would
be the same.

Additionally so that we can report the highest written offset we need to
also be able to access them by node-name for backing chain purposes.

In cases when 'device' is empty it does not make sense to gather them.

Allow arranging the stats simultaneously in all the above dimensions.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_monitor_json.c | 55 
 1 file changed, 50 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 3351d405f3..670147ddb6 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2332,6 +2332,28 @@ qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr dev,
 }


+static int
+qemuMonitorJSONAddOneBlockStatsInfo(qemuBlockStatsPtr bstats,
+const char *name,
+virHashTablePtr stats)
+{
+qemuBlockStatsPtr copy = NULL;
+
+if (VIR_ALLOC(copy) < 0)
+return -1;
+
+if (bstats)
+*copy = *bstats;
+
+if (virHashAddEntry(stats, name, copy) < 0) {
+VIR_FREE(copy);
+return -1;
+}
+
+return 0;
+}
+
+
 static int
 qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,
 const char *dev_name,
@@ -2342,18 +2364,38 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,
 qemuBlockStatsPtr bstats = NULL;
 int ret = -1;
 int nstats = 0;
-char *entry_name = qemuDomainStorageAlias(dev_name, depth);
+const char *qdevname = NULL;
+const char *nodename = NULL;
+char *devicename = NULL;
 virJSONValuePtr backing;

-if (!entry_name)
+if (dev_name &&
+!(devicename = qemuDomainStorageAlias(dev_name, depth)))
 goto cleanup;

+qdevname = virJSONValueObjectGetString(dev, "qdev");
+nodename = virJSONValueObjectGetString(dev, "node-name");
+
+if (!devicename && !qdevname && !nodename) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("blockstats device entry was not in expected 
format"));
+goto cleanup;
+}
+
 if (!(bstats = qemuMonitorJSONBlockStatsCollectData(dev, )))
 goto cleanup;

-if (virHashAddEntry(hash, entry_name, bstats) < 0)
+if (devicename &&
+qemuMonitorJSONAddOneBlockStatsInfo(bstats, devicename, hash) < 0)
+goto cleanup;
+
+if (qdevname && STRNEQ_NULLABLE(qdevname, devicename) &&
+qemuMonitorJSONAddOneBlockStatsInfo(bstats, qdevname, hash) < 0)
+goto cleanup;
+
+if (nodename &&
+qemuMonitorJSONAddOneBlockStatsInfo(bstats, nodename, hash) < 0)
 goto cleanup;
-bstats = NULL;

 if (backingChain &&
 (backing = virJSONValueObjectGetObject(dev, "backing")) &&
@@ -2364,7 +2406,7 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,
 ret = nstats;
  cleanup:
 VIR_FREE(bstats);
-VIR_FREE(entry_name);
+VIR_FREE(devicename);
 return ret;
 }

@@ -2426,6 +2468,9 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
 goto cleanup;
 }

+if (*dev_name == '\0')
+dev_name = NULL;
+
 rc = qemuMonitorJSONGetOneBlockStatsInfo(dev, dev_name, 0, hash,
  backingChain);

-- 
2.16.2

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


[libvirt] [PATCHv2 23/62] conf: domain: Format out user provided backing chains in XML

2018-08-13 Thread Peter Krempa
If a user configures the backing chain in the XML we should not ignore
it. We already do parse it but don't format it out. As a
safety-precaution don't attempt to format detected chain into the
inactive XML.

Signed-off-by: Peter Krempa 
---
 src/conf/domain_conf.c |  8 ++-
 .../disk-backing-chains-inactive.xml   | 35 ++
 .../disk-backing-chains-index-active.xml   | 80 ++
 .../disk-backing-chains-index-inactive.xml | 80 ++
 .../disk-backing-chains-noindex-active.xml | 80 ++
 .../disk-backing-chains-noindex-inactive.xml   | 80 ++
 tests/qemuxml2xmloutdata/disk-mirror-inactive.xml  |  4 ++
 .../disk-mirror-old-inactive.xml   |  4 ++
 8 files changed, 369 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f0d44bb75d..93d745bb74 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -23797,10 +23797,15 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
 unsigned int flags)
 {
 const char *format;
+bool inactive = flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE;

 if (!backingStore)
 return 0;

+/* don't write detected backing chain members to inactive xml */
+if (inactive && backingStore->detected)
+return 0;
+
 if (backingStore->type == VIR_STORAGE_TYPE_NONE) {
 virBufferAddLit(buf, "\n");
 return 0;
@@ -24066,8 +24071,7 @@ virDomainDiskDefFormat(virBufferPtr buf,

 /* Don't format backingStore to inactive XMLs until the code for
  * persistent storage of backing chains is ready. */
-if (!(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE) &&
-virDomainDiskBackingStoreFormat(buf, def->src->backingStore,
+if (virDomainDiskBackingStoreFormat(buf, def->src->backingStore,
 xmlopt, flags) < 0)
 return -1;

diff --git a/tests/qemuxml2xmloutdata/disk-backing-chains-inactive.xml 
b/tests/qemuxml2xmloutdata/disk-backing-chains-inactive.xml
index a9db12ba4d..c1af58ff6f 100644
--- a/tests/qemuxml2xmloutdata/disk-backing-chains-inactive.xml
+++ b/tests/qemuxml2xmloutdata/disk-backing-chains-inactive.xml
@@ -19,6 +19,10 @@
   
 
   
+  
+
+
+  
   
   
 
@@ -27,6 +31,31 @@
   
 
   
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+  
+
+  
+
+  
   
   
 
@@ -35,6 +64,7 @@
   
 
   
+  
   
   
 
@@ -48,6 +78,11 @@
 
 
   
+  
+
+
+
+  
   
   
 
diff --git a/tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml 
b/tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml
index db70ae2b53..724afa4e83 100644
--- a/tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml
+++ b/tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml
@@ -19,6 +19,10 @@
   
 
   
+  
+
+
+  
   
   
 
@@ -27,6 +31,31 @@
   
 
   
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+  
+
+  
+
+  
   
   
 
@@ -35,6 +64,7 @@
   
 
   
+  
   
   
 
@@ -48,6 +78,11 @@
 
 
   
+  
+
+
+
+  
   
   
 
@@ -60,6 +95,51 @@
 
   
   
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+
+
+  
+
+  
+
+  
+
+  
+
+  
+
+  
   
   
 
diff --git 

[libvirt] [PATCHv2 29/62] qemu: alias: Generate QDEV name of the block backend for disks

2018-08-13 Thread Peter Krempa
When we stop using -drive qemu stops reporting it in some of the monitor
commands. To allow referring the disk frontends and the corresponding
block backends we need to know these names. Unfortunately different
buses require different names.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_alias.c   | 86 +++--
 src/qemu/qemu_alias.h   |  3 +-
 src/qemu/qemu_hotplug.c |  2 +-
 3 files changed, 65 insertions(+), 26 deletions(-)

diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 80d9b6cf46..e66a8a5c1d 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -175,44 +175,82 @@ qemuAssignDeviceControllerAlias(virDomainDefPtr domainDef,
 }


-/* Our custom -drive naming scheme used with id= */
 int
 qemuAssignDeviceDiskAlias(virDomainDefPtr def,
-  virDomainDiskDefPtr disk)
+  virDomainDiskDefPtr disk,
+  virQEMUCapsPtr qemuCaps)
 {
+qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
 const char *prefix = virDomainDiskBusTypeToString(disk->bus);
 int controllerModel = -1;

 if (disk->info.alias)
 return 0;

-if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
-if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
-controllerModel = qemuDomainFindSCSIControllerModel(def,
->info);
-if (controllerModel < 0)
+if (!disk->info.alias) {
+if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
+if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
+controllerModel = qemuDomainFindSCSIControllerModel(def,
+
>info);
+if (controllerModel < 0)
+return -1;
+}
+
+if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI ||
+controllerModel == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
+if (virAsprintf(>info.alias, "%s%d-%d-%d", prefix,
+disk->info.addr.drive.controller,
+disk->info.addr.drive.bus,
+disk->info.addr.drive.unit) < 0)
+return -1;
+} else {
+if (virAsprintf(>info.alias, "%s%d-%d-%d-%d", prefix,
+disk->info.addr.drive.controller,
+disk->info.addr.drive.bus,
+disk->info.addr.drive.target,
+disk->info.addr.drive.unit) < 0)
+return -1;
+}
+} else {
+int idx = virDiskNameToIndex(disk->dst);
+if (virAsprintf(>info.alias, "%s-disk%d", prefix, idx) < 0)
 return -1;
 }
+}

-if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI ||
-controllerModel == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
-if (virAsprintf(>info.alias, "%s%d-%d-%d", prefix,
-disk->info.addr.drive.controller,
-disk->info.addr.drive.bus,
-disk->info.addr.drive.unit) < 0)
+/* For -blockdev we need to know the QDEV ids of the block backend of the
+ * disk. The QDEV id used by qemu is based on the alias so we generate them
+ * here. */
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+switch ((virDomainDiskBus) disk->bus) {
+case VIR_DOMAIN_DISK_BUS_FDC:
+case VIR_DOMAIN_DISK_BUS_IDE:
+case VIR_DOMAIN_DISK_BUS_SATA:
+case VIR_DOMAIN_DISK_BUS_SCSI:
+if (VIR_STRDUP(diskPriv->backendQomName, disk->info.alias) < 0)
 return -1;
-} else {
-if (virAsprintf(>info.alias, "%s%d-%d-%d-%d", prefix,
-disk->info.addr.drive.controller,
-disk->info.addr.drive.bus,
-disk->info.addr.drive.target,
-disk->info.addr.drive.unit) < 0)
+break;
+
+case VIR_DOMAIN_DISK_BUS_VIRTIO:
+if (virAsprintf(>backendQomName,
+"/machine/peripheral/%s/virtio-backend",
+disk->info.alias) < 0)
 return -1;
+break;
+
+case VIR_DOMAIN_DISK_BUS_USB:
+if (virAsprintf(>backendQomName,
+"/machine/peripheral/%s/%s.0/legacy[0]",
+disk->info.alias, disk->info.alias) < 0)
+return -1;
+break;
+
+case VIR_DOMAIN_DISK_BUS_XEN:
+case VIR_DOMAIN_DISK_BUS_UML:
+case VIR_DOMAIN_DISK_BUS_SD:
+case VIR_DOMAIN_DISK_BUS_LAST:
+break;
 }
-} else {
-int idx = virDiskNameToIndex(disk->dst);
-if 

[libvirt] [PATCHv2 37/62] qemu: process: Setup disk io throttling for -blockdev

2018-08-13 Thread Peter Krempa
The proper way to do this would be to use the 'throttle' driver but
unfortunately it can't change the 'throttle_group' so we can't provide
feature parity. This hack uses the block_set_io_throttle command to do
so until we can properly replace it.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_process.c | 50 +
 1 file changed, 50 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 0bf8245173..3495733041 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6230,6 +6230,53 @@ qemuProcessGenID(virDomainObjPtr vm,
 }


+/**
+ * qemuProcessSetupDiskThrottlingBlockdev:
+ *
+ * Sets up disk trottling for -blockdev via block_set_io_throttle monitor
+ * command. This hack should be replaced by proper use of the 'throttle'
+ * blockdev driver in qemu once it will support changing of the throttle group.
+ */
+static int
+qemuProcessSetupDiskThrottlingBlockdev(virQEMUDriverPtr driver,
+   virDomainObjPtr vm,
+   qemuDomainAsyncJob asyncJob)
+{
+qemuDomainObjPrivatePtr priv = vm->privateData;
+size_t i;
+int ret = -1;
+
+if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV))
+return 0;
+
+VIR_DEBUG("Setting up disk throttling for -blockdev via 
block_set_io_throttle");
+
+if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
+return -1;
+
+for (i = 0; i < vm->def->ndisks; i++) {
+virDomainDiskDefPtr disk = vm->def->disks[i];
+qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+
+if (!qemuDiskConfigBlkdeviotuneEnabled(disk))
+continue;
+
+if (qemuMonitorSetBlockIoThrottle(qemuDomainGetMonitor(vm), NULL,
+  diskPriv->backendQomName,
+  >blkdeviotune,
+  true, true, true) < 0)
+goto cleanup;
+}
+
+ret = 0;
+
+ cleanup:
+if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ret = -1;
+return ret;
+}
+
+
 /**
  * qemuProcessLaunch:
  *
@@ -6548,6 +6595,9 @@ qemuProcessLaunch(virConnectPtr conn,
 if (qemuProcessSetupBalloon(driver, vm, asyncJob) < 0)
 goto cleanup;

+if (qemuProcessSetupDiskThrottlingBlockdev(driver, vm, asyncJob) < 0)
+goto cleanup;
+
 /* Since CPUs were not started yet, the balloon could not return the memory
  * to the host and thus cur_balloon needs to be updated so that GetXMLdesc
  * and friends return the correct size in case they can't grab the job */
-- 
2.16.2

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


[libvirt] [PATCHv2 22/62] qemu: process: Don't detect nodenames when we support -blockdev

2018-08-13 Thread Peter Krempa
We'll specify them ourselves so it's pointless to attempt to redetect
them.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_process.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d9acb4bd68..ff4d992ff1 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7804,7 +7804,8 @@ qemuProcessReconnect(void *opaque)
 if (qemuProcessRefreshDisks(driver, obj, QEMU_ASYNC_JOB_NONE) < 0)
 goto error;

-if (qemuBlockNodeNamesDetect(driver, obj, QEMU_ASYNC_JOB_NONE) < 0)
+if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
+qemuBlockNodeNamesDetect(driver, obj, QEMU_ASYNC_JOB_NONE) < 0)
 goto error;

 if (qemuRefreshVirtioChannelState(driver, obj, QEMU_ASYNC_JOB_NONE) < 0)
-- 
2.16.2

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


[libvirt] [PATCHv2 21/62] qemu: domain: Don't redetect backing chain when using -blockdev

2018-08-13 Thread Peter Krempa
We need to load the backing chain from the XML when using -blockdev.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_process.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 38e88404aa..d9acb4bd68 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6024,8 +6024,10 @@ qemuProcessPrepareHostStorage(virQEMUDriverPtr driver,
   virDomainObjPtr vm,
   unsigned int flags)
 {
+qemuDomainObjPrivatePtr priv = vm->privateData;
 size_t i;
 bool cold_boot = flags & VIR_QEMU_PROCESS_START_COLD;
+bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);

 for (i = vm->def->ndisks; i > 0; i--) {
 size_t idx = i - 1;
@@ -6034,7 +6036,9 @@ qemuProcessPrepareHostStorage(virQEMUDriverPtr driver,
 if (virStorageSourceIsEmpty(disk->src))
 continue;

-virStorageSourceBackingStoreClear(disk->src);
+/* backing chain needs to be redetected if we aren't using blockdev */
+if (!blockdev)
+virStorageSourceBackingStoreClear(disk->src);

 if (qemuDomainDetermineDiskChain(driver, vm, disk, true) >= 0)
 continue;
@@ -7710,7 +7714,8 @@ qemuProcessReconnect(void *opaque)
 goto error;

 /* backing chains need to be refreshed only if they could change */
-if (priv->reconnectBlockjobs != VIR_TRISTATE_BOOL_NO) {
+if (priv->reconnectBlockjobs != VIR_TRISTATE_BOOL_NO &&
+!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
 /* This should be the only place that calls
  * qemuDomainDetermineDiskChain with @report_broken == false
  * to guarantee best-effort domain reconnect */
-- 
2.16.2

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


[libvirt] [PATCHv2 34/62] qemu: domain: Prepare qemuDomainDiskGetBackendAlias for -blockdev

2018-08-13 Thread Peter Krempa
Pass in the node name as the backend alias when -blockdev is used. As
copy-on-read is expressed by a separate -blockdev backing chain member
we need to decide which node name to use here.

For empty cdroms when using -blockdev there is no backend at all so NULL
is returned.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_domain.c | 21 +++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index fc2a3d9f60..7ce4487b05 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8691,12 +8691,29 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver,
  */
 int
 qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk,
-  virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED,
+  virQEMUCapsPtr qemuCaps,
   char **backendAlias)
 {
+qemuDomainDiskPrivatePtr priv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+const char *nodename = NULL;
 *backendAlias = NULL;

-if (!(*backendAlias = qemuAliasDiskDriveFromDisk(disk)))
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (!(*backendAlias = qemuAliasDiskDriveFromDisk(disk)))
+return -1;
+
+return 0;
+}
+
+if (virStorageSourceIsEmpty(disk->src))
+return 0;
+
+if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON)
+nodename = priv->nodeCopyOnRead;
+else
+nodename = disk->src->nodeformat;
+
+if (VIR_STRDUP(*backendAlias, nodename) < 0)
 return -1;

 return 0;
-- 
2.16.2

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


[libvirt] [PATCHv2 38/62] qemu: driver: Use QOM backend name for disk IO throttling APIs

2018-08-13 Thread Peter Krempa
With -blockdev the drive alias can't be used any more so we need to
switch to the QOM name.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 30 --
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7b9c19087e..fb09278112 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18202,7 +18202,8 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
 virDomainDefPtr def = NULL;
 virDomainDefPtr persistentDef = NULL;
 virDomainBlockIoTuneInfo info;
-char *device = NULL;
+char *drivealias = NULL;
+const char *qdevid = NULL;
 int ret = -1;
 size_t i;
 virDomainDiskDefPtr conf_disk = NULL;
@@ -18427,8 +18428,12 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
 if (!(disk = qemuDomainDiskByName(def, path)))
 goto endjob;

-if (!(device = qemuAliasDiskDriveFromDisk(disk)))
-goto endjob;
+if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+qdevid = QEMU_DOMAIN_DISK_PRIVATE(disk)->backendQomName;
+} else {
+if (!(drivealias = qemuAliasDiskDriveFromDisk(disk)))
+goto endjob;
+}

 if (qemuDomainSetBlockIoTuneDefaults(, >blkdeviotune,
  set_fields) < 0)
@@ -18474,7 +18479,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
   * via the JSON error code from the block_set_io_throttle call */

 qemuDomainObjEnterMonitor(driver, vm);
-ret = qemuMonitorSetBlockIoThrottle(priv->mon, device, NULL,
+ret = qemuMonitorSetBlockIoThrottle(priv->mon, drivealias, qdevid,
 , supportMaxOptions,
 set_fields & 
QEMU_BLOCK_IOTUNE_SET_GROUP_NAME,
 supportMaxLengthOptions);
@@ -18524,7 +18529,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,

  cleanup:
 VIR_FREE(info.group_name);
-VIR_FREE(device);
+VIR_FREE(drivealias);
 virDomainObjEndAPI();
 if (eventNparams)
 virTypedParamsFree(eventParams, eventNparams);
@@ -18546,7 +18551,8 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
 virDomainDefPtr def = NULL;
 virDomainDefPtr persistentDef = NULL;
 virDomainBlockIoTuneInfo reply = {0};
-char *device = NULL;
+char *drivealias = NULL;
+const char *qdevid = NULL;
 int ret = -1;
 int maxparams;

@@ -18600,10 +18606,14 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
 if (!(disk = qemuDomainDiskByName(def, path)))
 goto endjob;

-if (!(device = qemuAliasDiskDriveFromDisk(disk)))
-goto endjob;
+if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+qdevid = QEMU_DOMAIN_DISK_PRIVATE(disk)->backendQomName;
+} else {
+if (!(drivealias = qemuAliasDiskDriveFromDisk(disk)))
+goto endjob;
+}
 qemuDomainObjEnterMonitor(driver, vm);
-ret = qemuMonitorGetBlockIoThrottle(priv->mon, device, NULL, );
+ret = qemuMonitorGetBlockIoThrottle(priv->mon, drivealias, qdevid, 
);
 if (qemuDomainObjExitMonitor(driver, vm) < 0)
 goto endjob;
 if (ret < 0)
@@ -18678,7 +18688,7 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,

  cleanup:
 VIR_FREE(reply.group_name);
-VIR_FREE(device);
+VIR_FREE(drivealias);
 virDomainObjEndAPI();
 return ret;
 }
-- 
2.16.2

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


[libvirt] [PATCHv2 31/62] qemu: domain: Add field for storing node name for copy-on-read

2018-08-13 Thread Peter Krempa
The copy-on-read feature is expressed by adding a new node layer in
qemu when using -blockdev. Since we will keep these per-disk (as opposed
to per storage source) we need to store the appropriate node names in
the disk definition.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_domain.c| 11 +++
 src/qemu/qemu_domain.h|  1 +
 tests/qemustatusxml2xmldata/modern-in.xml |  3 +++
 3 files changed, 15 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3058ceca79..e0dd3c0b15 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1066,6 +1066,7 @@ qemuDomainDiskPrivateDispose(void *obj)
 VIR_FREE(priv->blockJobError);
 virStorageSourceFree(priv->migrSource);
 VIR_FREE(priv->backendQomName);
+VIR_FREE(priv->nodeCopyOnRead);
 }

 static virClassPtr qemuDomainStorageSourcePrivateClass;
@@ -2131,6 +2132,7 @@ qemuDomainDiskPrivateParse(xmlXPathContextPtr ctxt,
 qemuDomainDiskPrivatePtr priv = QEMU_DOMAIN_DISK_PRIVATE(disk);

 priv->backendQomName = virXPathString("string(./qom/@backend)", ctxt);
+priv->nodeCopyOnRead = 
virXPathString("string(./nodenames/nodename[@type='copyOnRead']/@name)", ctxt);

 return 0;
 }
@@ -2144,6 +2146,15 @@ qemuDomainDiskPrivateFormat(virDomainDiskDefPtr disk,

 virBufferEscapeString(buf, "\n", priv->backendQomName);

+if (priv->nodeCopyOnRead) {
+virBufferAddLit(buf, "\n");
+virBufferAdjustIndent(buf, 2);
+virBufferEscapeString(buf, "\n",
+  priv->nodeCopyOnRead);
+virBufferAdjustIndent(buf, -2);
+virBufferAddLit(buf, "\n");
+}
+
 return 0;
 }

diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 7d0b304727..d3147cb69a 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -398,6 +398,7 @@ struct _qemuDomainDiskPrivate {
 bool removable; /* device media can be removed/changed */

 char *backendQomName; /* QOM path to the eligible block backend */
+char *nodeCopyOnRead; /* nodename of the disk-wide copy-on-read blockdev 
layer */
 };

 # define QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src) \
diff --git a/tests/qemustatusxml2xmldata/modern-in.xml 
b/tests/qemustatusxml2xmldata/modern-in.xml
index 21d4faca66..612090786a 100644
--- a/tests/qemustatusxml2xmldata/modern-in.xml
+++ b/tests/qemustatusxml2xmldata/modern-in.xml
@@ -333,6 +333,9 @@
 
 
   
+  
+
+  
 
   
   
-- 
2.16.2

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


[libvirt] [PATCHv2 36/62] qemu: command: Add helper to check if disk throttling is enabled

2018-08-13 Thread Peter Krempa
Add a helper which will use a collection of other helpers to determine
whether a disk requires throttling to be enabled.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c | 10 ++
 src/qemu/qemu_command.h |  3 +++
 2 files changed, 13 insertions(+)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 4a3dda28fe..613e4742af 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1031,6 +1031,16 @@ 
qemuDiskConfigBlkdeviotuneHasMaxLength(virDomainDiskDefPtr disk)
 }


+bool
+qemuDiskConfigBlkdeviotuneEnabled(virDomainDiskDefPtr disk)
+{
+return !!disk->blkdeviotune.group_name ||
+   qemuDiskConfigBlkdeviotuneHasBasic(disk) ||
+   qemuDiskConfigBlkdeviotuneHasMax(disk) ||
+   qemuDiskConfigBlkdeviotuneHasMaxLength(disk);
+}
+
+
 /**
  * qemuCheckDiskConfigBlkdeviotune:
  * @disk: disk configuration
diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h
index 283bf3120d..13c5508ae8 100644
--- a/src/qemu/qemu_command.h
+++ b/src/qemu/qemu_command.h
@@ -180,6 +180,9 @@ int qemuGetDriveSourceString(virStorageSourcePtr src,
  qemuDomainSecretInfoPtr secinfo,
  char **source);

+bool
+qemuDiskConfigBlkdeviotuneEnabled(virDomainDiskDefPtr disk);
+
 int qemuCheckDiskConfig(virDomainDiskDefPtr disk,
 virQEMUCapsPtr qemuCaps);

-- 
2.16.2

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


[libvirt] [PATCHv2 26/62] conf: Allow formatting and parsing of 'index' for disk source image

2018-08-13 Thread Peter Krempa
Similarly to backing store indexes which will become stable eventually
we need also to be able to format and store in the status XML for later
use the index for the top level of the backing chain.

Add XML formatter, parser, schema and docs.

Signed-off-by: Peter Krempa 
---
 docs/formatdomain.html.in   |  7 ++-
 docs/schemas/domaincommon.rng   | 19 +++
 src/conf/domain_conf.c  | 21 +
 .../qemuxml2argvdata/disk-backing-chains-index.xml  | 12 ++--
 .../disk-backing-chains-index-active.xml| 12 ++--
 5 files changed, 54 insertions(+), 17 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 34664f7903..231e74e6b8 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2962,6 +2962,11 @@
 is only valid when the specified storage volume is of 'file' or
 'block' type).
 
+The source element may also have the index
+attribute with same semantics the 
+index attribute of backingStore
+
+
 The source element may contain the following sub elements:
 

@@ -3170,7 +3175,7 @@
 by the backing store, see disk type attribute above for more
 details and possible values.
   
-  index
+  index
   
 This attribute is only valid in output (and ignored on input) and
 it can be used to refer to a specific part of the disk chain when
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 1a786968cc..e98f71536f 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1528,6 +1528,14 @@
 
   

+  
+
+  
+
+  
+
+  
+
   
 
   
@@ -1551,6 +1559,7 @@
 
   
 
+
 
   
 
@@ -1575,6 +1584,7 @@
 
   
 
+
 
   
 
@@ -1600,6 +1610,7 @@
 
   
 
+
 
   
 
@@ -1653,6 +1664,7 @@
 
   rbd
 
+
 
   
 
@@ -1692,6 +1704,7 @@
 iscsi
   
   
+  
   
   
 
@@ -1714,6 +1727,7 @@
 
   
   
+  
   
   
 
@@ -1732,6 +1746,7 @@
 
   
   
+  
   
   
 
@@ -1752,6 +1767,7 @@
   
 
   
+  
   
   
 
@@ -1765,6 +1781,7 @@
 gluster
   
   
+  
   
 
   
@@ -1782,6 +1799,7 @@
 
   
   
+  
   
 
   
@@ -1826,6 +1844,7 @@
 
   
 
+
 
   
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c10e0a9eca..72602fb48c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9805,6 +9805,13 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,

 startupPolicy = virXMLPropString(cur, "startupPolicy");

+if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) &&
+(tmp = virXMLPropString(cur, "index")) &&
+virStrToLong_uip(tmp, NULL, 10, >src->id) < 0) {
+virReportError(VIR_ERR_XML_ERROR, _("invalid disk index 
'%s'"), tmp);
+goto error;
+}
+VIR_FREE(tmp);
 } else if (!target &&
virXMLNodeNameEqual(cur, "target")) {
 target = virXMLPropString(cur, "dev");
@@ -23776,6 +23783,7 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
   int policy,
   unsigned int flags,
   bool skipSeclabels,
+  bool attrIndex,
   virDomainXMLOptionPtr xmlopt)
 {
 virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
@@ -23792,6 +23800,9 @@ virDomainDiskSourceFormatInternal(virBufferPtr buf,
 virBufferEscapeString(, " startupPolicy='%s'",
   virDomainStartupPolicyTypeToString(policy));

+if (attrIndex && src->id != 0)
+virBufferAsprintf(, " index='%u'", src->id);
+
 if (virDomainDiskSourceFormatPrivateData(, src, flags, xmlopt) < 
0)
 goto cleanup;

@@ -23814,7 +23825,8 @@ virDomainDiskSourceFormat(virBufferPtr buf,
   unsigned int flags,
   virDomainXMLOptionPtr xmlopt)
 {
-return virDomainDiskSourceFormatInternal(buf, src, policy, flags, false, 
xmlopt);
+return virDomainDiskSourceFormatInternal(buf, src, policy, flags, false,
+ false, xmlopt);
 }


@@ -23856,7 +23868,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,

 virBufferAsprintf(buf, "\n", format);
 /* 

[libvirt] [PATCHv2 35/62] qemu: command: format disk source commandline for -blockdev

2018-08-13 Thread Peter Krempa
Format the backing chain onto the commandline using the 'json' syntax
with -blockdev.

The command line formatter needs only minor tweaks to add the new
entries but we now need to initialize the strucutres that are used for
every layer of the backing chain.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_command.c | 82 -
 1 file changed, 75 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 72fdffa92a..4a3dda28fe 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2261,6 +2261,8 @@ static int
 qemuBuildBlockStorageSourceAttachDataCommandline(virCommandPtr cmd,
  
qemuBlockStorageSourceAttachDataPtr data)
 {
+char *tmp;
+
 if (qemuBuildObjectCommandline(cmd, data->prmgrProps) < 0 ||
 qemuBuildObjectCommandline(cmd, data->authsecretProps) < 0 ||
 qemuBuildObjectCommandline(cmd, data->encryptsecretProps) < 0 ||
@@ -2270,6 +2272,22 @@ 
qemuBuildBlockStorageSourceAttachDataCommandline(virCommandPtr cmd,
 if (data->driveCmd)
 virCommandAddArgList(cmd, "-drive", data->driveCmd, NULL);

+if (data->storageProps) {
+if (!(tmp = virJSONValueToString(data->storageProps, false)))
+return -1;
+
+virCommandAddArgList(cmd, "-blockdev", tmp, NULL);
+VIR_FREE(tmp);
+}
+
+if (data->formatProps) {
+if (!(tmp = virJSONValueToString(data->formatProps, false)))
+return -1;
+
+virCommandAddArgList(cmd, "-blockdev", tmp, NULL);
+VIR_FREE(tmp);
+}
+
 return 0;
 }

@@ -2279,20 +2297,70 @@ qemuBuildDiskSourceCommandLine(virCommandPtr cmd,
virDomainDiskDefPtr disk,
virQEMUCapsPtr qemuCaps)
 {
-qemuBlockStorageSourceAttachDataPtr data = NULL;
+qemuBlockStorageSourceAttachDataPtr *data = NULL;
+size_t ndata = 0;
+qemuBlockStorageSourceAttachDataPtr tmp = NULL;
+virJSONValuePtr copyOnReadProps = NULL;
+virStorageSourcePtr n;
+char *str = NULL;
+size_t i;
 int ret = -1;

-if (!(data = qemuBuildStorageSourceAttachPrepareDrive(disk, qemuCaps)))
-return -1;
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+if (virStorageSourceIsEmpty(disk->src)) {
+ret = 0;
+goto cleanup;
+}

-if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, data, qemuCaps) < 
0 ||
-qemuBuildBlockStorageSourceAttachDataCommandline(cmd, data) < 0)
-goto cleanup;
+for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) 
{
+if (!(tmp = qemuBlockStorageSourceAttachPrepareBlockdev(n)))
+goto cleanup;
+
+if (qemuBuildStorageSourceAttachPrepareCommon(n, tmp, qemuCaps) < 
0)
+goto cleanup;
+
+if (VIR_APPEND_ELEMENT(data, ndata, tmp) < 0)
+goto cleanup;
+}
+
+if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON &&
+!(copyOnReadProps = qemuBlockStorageGetCopyOnReadProps(disk)))
+goto cleanup;
+} else {
+if (!(tmp = qemuBuildStorageSourceAttachPrepareDrive(disk, qemuCaps)))
+goto cleanup;
+
+if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, tmp,
+  qemuCaps) < 0)
+goto cleanup;
+
+if (VIR_APPEND_ELEMENT(data, ndata, tmp) < 0)
+goto cleanup;
+}
+
+for (i = ndata; i > 0; i--) {
+if (qemuBuildBlockStorageSourceAttachDataCommandline(cmd,
+ data[i - 1]) < 0)
+goto cleanup;
+}
+
+if (copyOnReadProps) {
+if (!(str = virJSONValueToString(copyOnReadProps, false)))
+goto cleanup;
+
+virCommandAddArgList(cmd, "-blockdev", str, NULL);
+VIR_FREE(str);
+}

 ret = 0;

  cleanup:
-qemuBlockStorageSourceAttachDataFree(data);
+for (i = 0; i < ndata; i++)
+qemuBlockStorageSourceAttachDataFree(data[i]);
+VIR_FREE(data);
+qemuBlockStorageSourceAttachDataFree(tmp);
+virJSONValueFree(copyOnReadProps);
+VIR_FREE(str);
 return ret;
 }

-- 
2.16.2

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


[libvirt] [PATCHv2 17/62] qemu: hotplug: Don't generate alias when detaching disk

2018-08-13 Thread Peter Krempa
It should be impossible to lack an alias in the domain definition. Other
disk types don't generate it so remove it here as well.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_hotplug.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 87bc63e5e1..53ee01bc54 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4915,11 +4915,6 @@ qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver,
 goto cleanup;
 }

-if (!detach->info.alias) {
-if (qemuAssignDeviceDiskAlias(vm->def, detach) < 0)
-goto cleanup;
-}
-
 if (!async)
 qemuDomainMarkDeviceForRemoval(vm, >info);

-- 
2.16.2

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


[libvirt] [PATCHv2 28/62] qemu: Add field to store QDEV path of a disk in private data

2018-08-13 Thread Peter Krempa
When using -blockdev you need to use the qdev path to refer to the disk
fronends. Add means for storing the path and getting it after restart.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_domain.c| 27 +++
 src/qemu/qemu_domain.h|  2 ++
 tests/qemustatusxml2xmldata/modern-in.xml |  3 +++
 3 files changed, 32 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 032ad80baa..3058ceca79 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1065,6 +1065,7 @@ qemuDomainDiskPrivateDispose(void *obj)

 VIR_FREE(priv->blockJobError);
 virStorageSourceFree(priv->migrSource);
+VIR_FREE(priv->backendQomName);
 }

 static virClassPtr qemuDomainStorageSourcePrivateClass;
@@ -2123,6 +2124,30 @@ qemuStorageSourcePrivateDataFormat(virStorageSourcePtr 
src,
 }


+static int
+qemuDomainDiskPrivateParse(xmlXPathContextPtr ctxt,
+   virDomainDiskDefPtr disk)
+{
+qemuDomainDiskPrivatePtr priv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+
+priv->backendQomName = virXPathString("string(./qom/@backend)", ctxt);
+
+return 0;
+}
+
+
+static int
+qemuDomainDiskPrivateFormat(virDomainDiskDefPtr disk,
+virBufferPtr buf)
+{
+qemuDomainDiskPrivatePtr priv = QEMU_DOMAIN_DISK_PRIVATE(disk);
+
+virBufferEscapeString(buf, "\n", priv->backendQomName);
+
+return 0;
+}
+
+
 static void
 qemuDomainObjPrivateXMLFormatVcpus(virBufferPtr buf,
virDomainDefPtr def)
@@ -2973,6 +2998,8 @@ virDomainXMLPrivateDataCallbacks 
virQEMUDriverPrivateDataCallbacks = {
 .alloc = qemuDomainObjPrivateAlloc,
 .free = qemuDomainObjPrivateFree,
 .diskNew = qemuDomainDiskPrivateNew,
+.diskParse = qemuDomainDiskPrivateParse,
+.diskFormat = qemuDomainDiskPrivateFormat,
 .vcpuNew = qemuDomainVcpuPrivateNew,
 .chrSourceNew = qemuDomainChrSourcePrivateNew,
 .vsockNew = qemuDomainVsockPrivateNew,
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 5dcbdfbbe1..7d0b304727 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -396,6 +396,8 @@ struct _qemuDomainDiskPrivate {
 /* information about the device */
 bool tray; /* device has tray */
 bool removable; /* device media can be removed/changed */
+
+char *backendQomName; /* QOM path to the eligible block backend */
 };

 # define QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src) \
diff --git a/tests/qemustatusxml2xmldata/modern-in.xml 
b/tests/qemustatusxml2xmldata/modern-in.xml
index 4fb5f326c2..21d4faca66 100644
--- a/tests/qemustatusxml2xmldata/modern-in.xml
+++ b/tests/qemustatusxml2xmldata/modern-in.xml
@@ -331,6 +331,9 @@
 
 
 
+
+  
+
   
   
 
-- 
2.16.2

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


[libvirt] [PATCHv2 19/62] qemu: caps: Add capability for using the blockdev infrastructure

2018-08-13 Thread Peter Krempa
The capability currently is not enabled so that we can add individual
bits first.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_capabilities.c | 1 +
 src/qemu/qemu_capabilities.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index e6e199b2c6..f8c5967655 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -507,6 +507,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,

   /* 315 */
   "vfio-pci.display",
+  "blockdev",
 );


diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 26813a908c..ece5771cc2 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -491,6 +491,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for 
syntax-check */

 /* 315 */
 QEMU_CAPS_VFIO_PCI_DISPLAY, /* -device vfio-pci.display */
+QEMU_CAPS_BLOCKDEV, /* -blockdev and blockdev-add are supported */

 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
-- 
2.16.2

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


[libvirt] [PATCHv2 25/62] conf: Implement private data formatting and parsing for disks

2018-08-13 Thread Peter Krempa
Allow storing of private data in the status XML for disks.

Signed-off-by: Peter Krempa 
---
 src/conf/domain_conf.c | 60 ++
 src/conf/domain_conf.h |  7 ++
 2 files changed, 67 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 93d745bb74..c10e0a9eca 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9676,6 +9676,30 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def,
 }


+static int
+virDomainDiskDefParsePrivateData(xmlXPathContextPtr ctxt,
+ virDomainDiskDefPtr disk,
+ virDomainXMLOptionPtr xmlopt)
+{
+xmlNodePtr save_node = ctxt->node;
+int ret = 0;
+
+if (!xmlopt ||
+!xmlopt->privateData.diskParse)
+return 0;
+
+if (!(ctxt->node = virXPathNode("./privateData", ctxt)))
+goto cleanup;
+
+if (xmlopt->privateData.diskParse(ctxt, disk) < 0)
+ret = -1;
+
+ cleanup:
+ctxt->node = save_node;
+return ret;
+}
+
+
 #define VENDOR_LEN  8
 #define PRODUCT_LEN 16

@@ -10091,6 +10115,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
 goto error;
 }

+if (flags & VIR_DOMAIN_DEF_PARSE_STATUS &&
+virDomainDiskDefParsePrivateData(ctxt, def, xmlopt) < 0)
+goto error;
+
 if (virDomainDiskDefParseValidate(def, vmSeclabels, nvmSeclabels) < 0)
 goto error;

@@ -24006,6 +24034,35 @@ virDomainDiskDefFormatMirror(virBufferPtr buf,
 }


+static int
+virDomainDiskDefFormatPrivateData(virBufferPtr buf,
+  virDomainDiskDefPtr disk,
+  unsigned int flags,
+  virDomainXMLOptionPtr xmlopt)
+{
+virBuffer childBuf = VIR_BUFFER_INITIALIZER;
+
+if (!(flags & VIR_DOMAIN_DEF_FORMAT_STATUS) ||
+!xmlopt ||
+!xmlopt->privateData.diskFormat)
+return 0;
+
+virBufferSetChildIndent(, buf);
+
+if (xmlopt->privateData.diskFormat(disk, ) < 0)
+goto error;
+
+if (virXMLFormatElement(buf, "privateData", NULL, ) < 0)
+goto error;
+
+return 0;
+
+ error:
+virBufferFreeAndReset();
+return -1;
+}
+
+
 static int
 virDomainDiskDefFormat(virBufferPtr buf,
virDomainDiskDefPtr def,
@@ -24119,6 +24176,9 @@ virDomainDiskDefFormat(virBufferPtr buf,
 virDomainDeviceInfoFormat(buf, >info,
   flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT);

+if (virDomainDiskDefFormatPrivateData(buf, def, flags, xmlopt) < 0)
+return -1;
+
 virBufferAdjustIndent(buf, -2);
 virBufferAddLit(buf, "\n");
 return 0;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c1dfa37fdf..50d2ead607 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2735,6 +2735,11 @@ typedef int 
(*virDomainXMLPrivateDataParseFunc)(xmlXPathContextPtr,

 typedef void *(*virDomainXMLPrivateDataGetParseOpaqueFunc)(virDomainObjPtr vm);

+typedef int (*virDomainXMLPrivateDataDiskParseFunc)(xmlXPathContextPtr ctxt,
+virDomainDiskDefPtr disk);
+typedef int (*virDomainXMLPrivateDataDiskFormatFunc)(virDomainDiskDefPtr disk,
+ virBufferPtr buf);
+
 typedef int 
(*virDomainXMLPrivateDataStorageSourceParseFunc)(xmlXPathContextPtr ctxt,
  
virStorageSourcePtr src);
 typedef int 
(*virDomainXMLPrivateDataStorageSourceFormatFunc)(virStorageSourcePtr src,
@@ -2749,6 +2754,8 @@ struct _virDomainXMLPrivateDataCallbacks {
 /* note that private data for devices are not copied when using
  * virDomainDefCopy and similar functions */
 virDomainXMLPrivateDataNewFuncdiskNew;
+virDomainXMLPrivateDataDiskParseFunc diskParse;
+virDomainXMLPrivateDataDiskFormatFunc diskFormat;
 virDomainXMLPrivateDataNewFuncvcpuNew;
 virDomainXMLPrivateDataNewFuncchrSourceNew;
 virDomainXMLPrivateDataNewFuncvsockNew;
-- 
2.16.2

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


[libvirt] [PATCHv2 13/62] qemu: monitor: Add 'nodename' argument for 'block_resize'

2018-08-13 Thread Peter Krempa
Allow referring to individual node name to rezise.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c   |  2 +-
 src/qemu/qemu_monitor.c  | 12 ++--
 src/qemu/qemu_monitor.h  |  3 ++-
 src/qemu/qemu_monitor_json.c |  4 +++-
 src/qemu/qemu_monitor_json.h |  3 ++-
 tests/qemumonitorjsontest.c  |  2 +-
 6 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d11e990443..7456db6468 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10991,7 +10991,7 @@ qemuDomainBlockResize(virDomainPtr dom,
 goto endjob;

 qemuDomainObjEnterMonitor(driver, vm);
-if (qemuMonitorBlockResize(priv->mon, device, size) < 0) {
+if (qemuMonitorBlockResize(priv->mon, device, NULL, size) < 0) {
 ignore_value(qemuDomainObjExitMonitor(driver, vm));
 goto endjob;
 }
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 758942ffcb..4dcbd69dce 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2312,13 +2312,21 @@ qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr mon,
 int
 qemuMonitorBlockResize(qemuMonitorPtr mon,
const char *device,
+   const char *nodename,
unsigned long long size)
 {
-VIR_DEBUG("device=%s size=%llu", device, size);
+VIR_DEBUG("device=%s nodename=%s size=%llu",
+  NULLSTR(device), NULLSTR(nodename), size);

 QEMU_CHECK_MONITOR(mon);

-return qemuMonitorJSONBlockResize(mon, device, size);
+if ((!device && !nodename) || (device && nodename)) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("exactly one of 'device' and 'nodename' need to be 
specified"));
+return -1;
+}
+
+return qemuMonitorJSONBlockResize(mon, device, nodename, size);
 }


diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 60418422e9..f8f6969ddb 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -596,7 +596,8 @@ int qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr mon,
 ATTRIBUTE_NONNULL(2);

 int qemuMonitorBlockResize(qemuMonitorPtr mon,
-   const char *dev_name,
+   const char *device,
+   const char *nodename,
unsigned long long size);
 int qemuMonitorSetVNCPassword(qemuMonitorPtr mon,
   const char *password);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index e43447dc53..de3fcd83d8 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2542,6 +2542,7 @@ qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr 
mon,

 int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
const char *device,
+   const char *nodename,
unsigned long long size)
 {
 int ret = -1;
@@ -2549,7 +2550,8 @@ int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
 virJSONValuePtr reply = NULL;

 cmd = qemuMonitorJSONMakeCommand("block_resize",
- "s:device", device,
+ "S:device", device,
+ "S:node-name", nodename,
  "U:size", size,
  NULL);
 if (!cmd)
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 4d75e04183..19aebef5fb 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -94,7 +94,8 @@ int qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr 
mon,
 virHashTablePtr stats,
 bool backingChain);
 int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
-   const char *devce,
+   const char *device,
+   const char *nodename,
unsigned long long size);

 int qemuMonitorJSONSetVNCPassword(qemuMonitorPtr mon,
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 35d24cfb22..3da4d3076a 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1320,7 +1320,7 @@ cleanup: \
 }

 GEN_TEST_FUNC(qemuMonitorJSONSetLink, "vnet0", 
VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DOWN)
-GEN_TEST_FUNC(qemuMonitorJSONBlockResize, "vda", 123456)
+GEN_TEST_FUNC(qemuMonitorJSONBlockResize, "vda", "asdf", 123456)
 GEN_TEST_FUNC(qemuMonitorJSONSetVNCPassword, "secret_password")
 GEN_TEST_FUNC(qemuMonitorJSONSetPassword, "spice", "secret_password", 
"disconnect")
 GEN_TEST_FUNC(qemuMonitorJSONExpirePassword, "spice", "123456")
-- 
2.16.2

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


[libvirt] [PATCHv2 27/62] qemu: Use proper backingIndex when reporting stats for backing chain

2018-08-13 Thread Peter Krempa
Use the index stored in virStorageSource struct rather than
recalculating it. Currently we'd report proper numbers but that will
change with blockdev.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 13 +
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7456db6468..7b9c19087e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20033,7 +20033,6 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
virDomainDiskDefPtr disk,
virStorageSourcePtr src,
size_t block_idx,
-   unsigned int backing_idx,
virHashTablePtr stats,
virHashTablePtr nodedata)
 {
@@ -20042,16 +20041,16 @@ qemuDomainGetStatsOneBlock(virQEMUDriverPtr driver,
 char *alias = NULL;

 if (disk->info.alias)
-alias = qemuDomainStorageAlias(disk->info.alias, backing_idx);
+alias = qemuDomainStorageAlias(disk->info.alias, src->id);

 QEMU_ADD_NAME_PARAM(record, maxparams, "block", "name", block_idx,
 disk->dst);
 if (virStorageSourceIsLocalStorage(src) && src->path)
 QEMU_ADD_NAME_PARAM(record, maxparams, "block", "path",
 block_idx, src->path);
-if (backing_idx)
+if (src->id)
 QEMU_ADD_BLOCK_PARAM_UI(record, maxparams, block_idx, "backingIndex",
-backing_idx);
+src->id);

 /* the VM is offline so we have to go and load the stast from the disk by
  * ourselves */
@@ -20168,16 +20167,14 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
 for (i = 0; i < dom->def->ndisks; i++) {
 virDomainDiskDefPtr disk = dom->def->disks[i];
 virStorageSourcePtr src = disk->src;
-unsigned int backing_idx = 0;

 while (virStorageSourceIsBacking(src) &&
-   (backing_idx == 0 || visitBacking)) {
+   (src == disk->src || visitBacking)) {
 if (qemuDomainGetStatsOneBlock(driver, cfg, dom, record, maxparams,
-   disk, src, visited, backing_idx,
+   disk, src, visited,
stats, nodestats) < 0)
 goto cleanup;
 visited++;
-backing_idx++;
 src = src->backingStore;
 }
 }
-- 
2.16.2

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


[libvirt] [PATCHv2 24/62] qemu: domain: Add infrastructure to generate block node names

2018-08-13 Thread Peter Krempa
Node names for block objects in qemu need to be unique for an instance
of the qemu process. Add a counter to generate objects sequentially and
store it in the status XML so that we can restore it.

The helpers added allow to create new node names and reset the counter
after the VM process terminates.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_domain.c  | 38 ++
 src/qemu/qemu_domain.h  |  6 ++
 src/qemu/qemu_process.c |  3 +++
 3 files changed, 47 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e5f055f203..032ad80baa 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2438,6 +2438,9 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf,

 qemuDomainObjPrivateXMLFormatPR(buf, priv);

+if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV))
+virBufferAsprintf(buf, "\n", 
priv->nodenameindex);
+
 if (qemuDomainObjPrivateXMLFormatBlockjobs(buf, vm) < 0)
 return -1;

@@ -2933,6 +2936,14 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
 if (qemuDomainObjPrivateXMLParseBlockjobs(priv, ctxt) < 0)
 goto error;

+qemuDomainStorageIdReset(priv);
+if (virXPathULongLong("string(./nodename/@next)", ctxt,
+  >nodenameindex) == -2) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("failed to parse node name index"));
+goto error;
+}
+
 return 0;

  error:
@@ -13179,3 +13190,30 @@ 
qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv)

 return ret;
 }
+
+
+/**
+ * qemuDomainStorageIdNew:
+ * @priv: qemu VM private data object.
+ *
+ * Generate a new unique id for a storage object. Useful for node name 
generation.
+ */
+unsigned int
+qemuDomainStorageIdNew(qemuDomainObjPrivatePtr priv)
+{
+return ++priv->nodenameindex;
+}
+
+
+/**
+ * qemuDomainStorageIdReset:
+ * @priv: qemu VM private data object.
+ *
+ * Resets the data for the node name generator. The node names need to be 
unique
+ * for a single instance, so can be reset on VM shutdown.
+ */
+void
+qemuDomainStorageIdReset(qemuDomainObjPrivatePtr priv)
+{
+priv->nodenameindex = 0;
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 7b79d77257..5dcbdfbbe1 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -363,6 +363,9 @@ struct _qemuDomainObjPrivate {

 /* true if qemu-pr-helper process is running for the domain */
 bool prDaemonRunning;
+
+/* counter for generating node names for qemu disks */
+unsigned long long nodenameindex;
 };

 # define QEMU_DOMAIN_PRIVATE(vm) \
@@ -1063,4 +1066,7 @@ qemuDomainDiskCachemodeFlags(int cachemode,

 char * qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivatePtr priv);

+unsigned int qemuDomainStorageIdNew(qemuDomainObjPrivatePtr priv);
+void qemuDomainStorageIdReset(qemuDomainObjPrivatePtr priv);
+
 #endif /* __QEMU_DOMAIN_H__ */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index ff4d992ff1..0bf8245173 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7154,6 +7154,9 @@ void qemuProcessStop(virQEMUDriverPtr driver,
 /* clear all private data entries which are no longer needed */
 qemuDomainObjPrivateDataClear(priv);

+/* reset node name allocator */
+qemuDomainStorageIdReset(priv);
+
 /* The "release" hook cleans up additional resources */
 if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
 char *xml = qemuDomainDefFormatXML(driver, vm->def, 0);
-- 
2.16.2

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


[libvirt] [PATCHv2 09/62] qemu: hotplug: Prepare disk source in qemuDomainAttachDeviceDiskLive

2018-08-13 Thread Peter Krempa
Move the preparation steps from qemuDomainAttachDiskGeneric up into
qemuDomainAttachDeviceDiskLive so that also media changing can use the
prepared file.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_hotplug.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index c46f27f4b4..87bc63e5e1 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -641,7 +641,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
 qemuDomainObjPrivatePtr priv = vm->privateData;
 qemuHotplugDiskSourceDataPtr diskdata = NULL;
 char *devstr = NULL;
-virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);

 if (qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, false) < 0)
 goto cleanup;
@@ -649,9 +648,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
 if (qemuAssignDeviceDiskAlias(vm->def, disk) < 0)
 goto error;

-if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0)
-goto error;
-
 if (!(diskdata = qemuHotplugDiskSourceAttachPrepare(disk, priv->qemuCaps)))
 goto error;

@@ -686,7 +682,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
 qemuHotplugDiskSourceDataFree(diskdata);
 qemuDomainSecretDiskDestroy(disk);
 VIR_FREE(devstr);
-virObjectUnref(cfg);
 return ret;

  exit_monitor:
@@ -927,6 +922,8 @@ qemuDomainAttachDeviceDiskLive(virQEMUDriverPtr driver,
bool forceMediaChange)
 {
 size_t i;
+virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+qemuDomainObjPrivatePtr priv = vm->privateData;
 virDomainDiskDefPtr disk = dev->data.disk;
 virDomainDiskDefPtr orig_disk = NULL;
 int ret = -1;
@@ -943,6 +940,9 @@ qemuDomainAttachDeviceDiskLive(virQEMUDriverPtr driver,
 if (qemuDomainDetermineDiskChain(driver, vm, disk, true) < 0)
 goto cleanup;

+if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0)
+goto cleanup;
+
 switch ((virDomainDiskDevice) disk->device)  {
 case VIR_DOMAIN_DISK_DEVICE_CDROM:
 case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
@@ -1013,6 +1013,7 @@ qemuDomainAttachDeviceDiskLive(virQEMUDriverPtr driver,
  cleanup:
 if (ret != 0)
 ignore_value(qemuRemoveSharedDevice(driver, dev, vm->def->name));
+virObjectUnref(cfg);
 return ret;
 }

-- 
2.16.2

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


[libvirt] [PATCHv2 06/62] tests: qemucapabilities: Update capability data for qemu 3.0.0

2018-08-13 Thread Peter Krempa
The diff contains changes from the change of the JSON library
reformatting as well as dropping of the preconfig state and adding of
the 'qdev' field to output of 'query-blockstats'.

Signed-off-by: Peter Krempa 
---
 .../qemucapabilitiesdata/caps_3.0.0.x86_64.replies | 591 +++--
 tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml   |   8 +-
 2 files changed, 88 insertions(+), 511 deletions(-)

diff --git a/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.replies 
b/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.replies
index b2f8377248..714fac5a6f 100644
--- a/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.replies
+++ b/tests/qemucapabilitiesdata/caps_3.0.0.x86_64.replies
@@ -4,8 +4,7 @@
 }

 {
-  "return": {
-  },
+  "return": {},
   "id": "libvirt-1"
 }

@@ -17,11 +16,11 @@
 {
   "return": {
 "qemu": {
-  "micro": 90,
+  "micro": 93,
   "minor": 12,
   "major": 2
 },
-"package": "v3.0.0-rc0-31-g633e824037"
+"package": "v3.0.0-rc3-17-g09b94ac0f2"
   },
   "id": "libvirt-2"
 }
@@ -175,7 +174,7 @@
   "name": "system_wakeup"
 },
 {
-  "name": "exit-preconfig"
+  "name": "x-exit-preconfig"
 },
 {
   "name": "cont"
@@ -5346,40 +5345,35 @@
 {
   "name": "max",
   "typename": "max-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": false
 },
 {
   "name": "host",
   "typename": "host-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": false
 },
 {
   "name": "base",
   "typename": "base-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": true,
   "migration-safe": true
 },
 {
   "name": "qemu64",
   "typename": "qemu64-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
 {
   "name": "qemu32",
   "typename": "qemu32-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
@@ -5400,64 +5394,56 @@
 {
   "name": "pentium3",
   "typename": "pentium3-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
 {
   "name": "pentium2",
   "typename": "pentium2-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
 {
   "name": "pentium",
   "typename": "pentium-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
 {
   "name": "n270",
   "typename": "n270-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
 {
   "name": "kvm64",
   "typename": "kvm64-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
 {
   "name": "kvm32",
   "typename": "kvm32-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
 {
   "name": "coreduo",
   "typename": "coreduo-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
 {
   "name": "core2duo",
   "typename": "core2duo-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
@@ -5475,16 +5461,14 @@
 {
   "name": "Westmere-IBRS",
   "typename": "Westmere-IBRS-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
 {
   "name": "Westmere",
   "typename": "Westmere-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
@@ -5525,40 +5509,35 @@
 {
   "name": "Skylake-Client-IBRS",
   "typename": "Skylake-Client-IBRS-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
 {
   "name": "Skylake-Client",
   "typename": "Skylake-Client-x86_64-cpu",
-  "unavailable-features": [
-  ],
+  "unavailable-features": [],
   "static": false,
   "migration-safe": true
 },
 {
   "name": "SandyBridge-IBRS",
   

[libvirt] [PATCHv2 08/62] qemu: hotplug: consolidate media change code paths

2018-08-13 Thread Peter Krempa
Use qemuDomainAttachDeviceDiskLive to change the media in
qemuDomainChangeDiskLive as the former function already does all the
necessary steps to prepare the new medium.

This also allows us to turn qemuDomainChangeEjectableMedia static.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c  | 18 ++
 src/qemu/qemu_hotplug.c | 18 +++---
 src/qemu/qemu_hotplug.h |  9 ++---
 tests/qemuhotplugtest.c |  2 +-
 4 files changed, 20 insertions(+), 27 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4fc1e358fa..15ec92bf10 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7599,7 +7599,7 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm,
 switch ((virDomainDeviceType)dev->type) {
 case VIR_DOMAIN_DEVICE_DISK:
 qemuDomainObjCheckDiskTaint(driver, vm, dev->data.disk, NULL);
-ret = qemuDomainAttachDeviceDiskLive(driver, vm, dev);
+ret = qemuDomainAttachDeviceDiskLive(driver, vm, dev, false);
 if (!ret) {
 alias = dev->data.disk->info.alias;
 dev->data.disk = NULL;
@@ -7850,12 +7850,6 @@ qemuDomainChangeDiskLive(virDomainObjPtr vm,
 virDomainDeviceDef oldDev = { .type = dev->type };
 int ret = -1;

-if (virDomainDiskTranslateSourcePool(disk) < 0)
-goto cleanup;
-
-if (qemuDomainDetermineDiskChain(driver, vm, disk, true) < 0)
-goto cleanup;
-
 if (!(orig_disk = virDomainDiskFindByBusAndDst(vm->def,
disk->bus, disk->dst))) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -7884,16 +7878,8 @@ qemuDomainChangeDiskLive(virDomainObjPtr vm,
 goto cleanup;
 }

-/* Add the new disk src into shared disk hash table */
-if (qemuAddSharedDevice(driver, dev, vm->def->name) < 0)
-goto cleanup;
-
-if (qemuDomainChangeEjectableMedia(driver, vm, orig_disk,
-   dev->data.disk->src, force) < 0) {
-ignore_value(qemuRemoveSharedDisk(driver, dev->data.disk,
-  vm->def->name));
+if (qemuDomainAttachDeviceDiskLive(driver, vm, dev, force) < 0)
 goto cleanup;
-}

 dev->data.disk->src = NULL;
 }
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 5b52fe9edc..c46f27f4b4 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -586,7 +586,7 @@ qemuHotplugDiskSourceRemove(qemuMonitorPtr mon,
  *
  * Returns 0 on success, -1 on error and reports libvirt error
  */
-int
+static int
 qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainDiskDefPtr disk,
@@ -909,10 +909,22 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr 
driver,
 }


+/**
+ * qemuDomainAttachDeviceDiskLive:
+ * @driver: qemu driver struct
+ * @vm: domain object
+ * @dev: device to attach (expected type is DISK)
+ * @forceMediaChange: Forcibly open the drive if changing media
+ *
+ * Attach a new disk or in case of cdroms/floppies change the media in the 
drive.
+ * This function handles all the necessary steps to attach a new storage source
+ * to the VM. If @forceMediaChange is true the drive is opened forcibly.
+ */
 int
 qemuDomainAttachDeviceDiskLive(virQEMUDriverPtr driver,
virDomainObjPtr vm,
-   virDomainDeviceDefPtr dev)
+   virDomainDeviceDefPtr dev,
+   bool forceMediaChange)
 {
 size_t i;
 virDomainDiskDefPtr disk = dev->data.disk;
@@ -946,7 +958,7 @@ qemuDomainAttachDeviceDiskLive(virQEMUDriverPtr driver,
 }

 if (qemuDomainChangeEjectableMedia(driver, vm, orig_disk,
-   disk->src, false) < 0)
+   disk->src, forceMediaChange) < 0)
 goto cleanup;

 disk->src = NULL;
diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index 0297e42a98..c085c45082 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -28,12 +28,6 @@
 # include "qemu_domain.h"
 # include "domain_conf.h"

-int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
-   virDomainObjPtr vm,
-   virDomainDiskDefPtr disk,
-   virStorageSourcePtr newsrc,
-   bool force);
-
 void qemuDomainDelTLSObjects(virQEMUDriverPtr driver,
  virDomainObjPtr vm,
  qemuDomainAsyncJob asyncJob,
@@ -60,7 +54,8 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
  virDomainControllerDefPtr controller);
 int qemuDomainAttachDeviceDiskLive(virQEMUDriverPtr driver,
  

[libvirt] [PATCHv2 14/62] tests: qemu: Drop disk from hostdev-mdev tests

2018-08-13 Thread Peter Krempa
The disk is not necessary to test the mdevs.

Signed-off-by: Peter Krempa 
---
 tests/qemuxml2argvdata/hostdev-mdev-display-missing-graphics.xml| 6 --
 .../hostdev-mdev-display-spice-egl-headless.x86_64-latest.args  | 2 --
 tests/qemuxml2argvdata/hostdev-mdev-display-spice-egl-headless.xml  | 6 --
 .../hostdev-mdev-display-spice-opengl.x86_64-latest.args| 2 --
 tests/qemuxml2argvdata/hostdev-mdev-display-spice-opengl.xml| 6 --
 .../hostdev-mdev-display-vnc-egl-headless.x86_64-latest.args| 2 --
 tests/qemuxml2argvdata/hostdev-mdev-display-vnc-egl-headless.xml| 6 --
 tests/qemuxml2argvdata/hostdev-mdev-display-vnc.x86_64-latest.args  | 2 --
 tests/qemuxml2argvdata/hostdev-mdev-display-vnc.xml | 6 --
 tests/qemuxml2argvdata/hostdev-mdev-display.xml | 6 --
 tests/qemuxml2argvdata/hostdev-mdev-invalid-target-address.xml  | 5 -
 tests/qemuxml2argvdata/hostdev-mdev-precreated.args | 3 ---
 tests/qemuxml2argvdata/hostdev-mdev-precreated.xml  | 6 --
 tests/qemuxml2argvdata/hostdev-mdev-src-address-invalid.xml | 6 --
 tests/qemuxml2xmloutdata/hostdev-mdev-display.xml   | 6 --
 tests/qemuxml2xmloutdata/hostdev-mdev-precreated.xml| 6 --
 16 files changed, 76 deletions(-)

diff --git a/tests/qemuxml2argvdata/hostdev-mdev-display-missing-graphics.xml 
b/tests/qemuxml2argvdata/hostdev-mdev-display-missing-graphics.xml
index ea559a6444..55b60ba133 100644
--- a/tests/qemuxml2argvdata/hostdev-mdev-display-missing-graphics.xml
+++ b/tests/qemuxml2argvdata/hostdev-mdev-display-missing-graphics.xml
@@ -14,12 +14,6 @@
   destroy
   
 /usr/bin/qemu-system-i686
-
-  
-  
-  
-  
-
 
 
 
diff --git 
a/tests/qemuxml2argvdata/hostdev-mdev-display-spice-egl-headless.x86_64-latest.args
 
b/tests/qemuxml2argvdata/hostdev-mdev-display-spice-egl-headless.x86_64-latest.args
index 0ac90c81d2..b84869264e 100644
--- 
a/tests/qemuxml2argvdata/hostdev-mdev-display-spice-egl-headless.x86_64-latest.args
+++ 
b/tests/qemuxml2argvdata/hostdev-mdev-display-spice-egl-headless.x86_64-latest.args
@@ -23,8 +23,6 @@ file=/tmp/lib/domain--1-QEMUGuest2/master-key.aes \
 -no-acpi \
 -boot strict=on \
 -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
--drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-0-0 \
--device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
 -spice port=0,seamless-migration=on \
 -display egl-headless \
 -device qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,\
diff --git a/tests/qemuxml2argvdata/hostdev-mdev-display-spice-egl-headless.xml 
b/tests/qemuxml2argvdata/hostdev-mdev-display-spice-egl-headless.xml
index c8f10c2f3a..3a686ad2bf 100644
--- a/tests/qemuxml2argvdata/hostdev-mdev-display-spice-egl-headless.xml
+++ b/tests/qemuxml2argvdata/hostdev-mdev-display-spice-egl-headless.xml
@@ -14,12 +14,6 @@
   destroy
   
 /usr/bin/qemu-system-i686
-
-  
-  
-  
-  
-
 
 
 
diff --git 
a/tests/qemuxml2argvdata/hostdev-mdev-display-spice-opengl.x86_64-latest.args 
b/tests/qemuxml2argvdata/hostdev-mdev-display-spice-opengl.x86_64-latest.args
index 1fd9fdaa16..80c56abfb9 100644
--- 
a/tests/qemuxml2argvdata/hostdev-mdev-display-spice-opengl.x86_64-latest.args
+++ 
b/tests/qemuxml2argvdata/hostdev-mdev-display-spice-opengl.x86_64-latest.args
@@ -23,8 +23,6 @@ file=/tmp/lib/domain--1-QEMUGuest2/master-key.aes \
 -no-acpi \
 -boot strict=on \
 -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
--drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-0-0 \
--device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
 -spice port=0,gl=on,rendernode=/dev/dri/foo,seamless-migration=on \
 -device qxl-vga,id=video0,ram_size=67108864,vram_size=67108864,\
 vram64_size_mb=0,vgamem_mb=16,max_outputs=1,bus=pci.0,addr=0x2 \
diff --git a/tests/qemuxml2argvdata/hostdev-mdev-display-spice-opengl.xml 
b/tests/qemuxml2argvdata/hostdev-mdev-display-spice-opengl.xml
index 18c9817608..a632e58a41 100644
--- a/tests/qemuxml2argvdata/hostdev-mdev-display-spice-opengl.xml
+++ b/tests/qemuxml2argvdata/hostdev-mdev-display-spice-opengl.xml
@@ -14,12 +14,6 @@
   destroy
   
 /usr/bin/qemu-system-i686
-
-  
-  
-  
-  
-
 
 
 
diff --git 
a/tests/qemuxml2argvdata/hostdev-mdev-display-vnc-egl-headless.x86_64-latest.args
 
b/tests/qemuxml2argvdata/hostdev-mdev-display-vnc-egl-headless.x86_64-latest.args
index cdf545d0e0..91708d7663 100644
--- 
a/tests/qemuxml2argvdata/hostdev-mdev-display-vnc-egl-headless.x86_64-latest.args
+++ 
b/tests/qemuxml2argvdata/hostdev-mdev-display-vnc-egl-headless.x86_64-latest.args
@@ -23,8 +23,6 @@ file=/tmp/lib/domain--1-QEMUGuest2/master-key.aes \
 -no-acpi \
 -boot strict=on \
 -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
--drive 

[libvirt] [PATCHv2 20/62] qemu: process: clear QEMU_CAPS_BLOCKDEV for VMs with SD card

2018-08-13 Thread Peter Krempa
SD cards are currently passed by using -drive only which would not be
compatible with using -blockdev fully.

Clear QEMU_CAPS_BLOCKDEV if the VM has such devices.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_process.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index c1a8dfda29..38e88404aa 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5882,6 +5882,15 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,

 qemuProcessPrepareAllowReboot(vm);

+/* clear the 'blockdev' capability for VMs which have disks that need
+ * -drive or which have floppies where we can't reliably get the QOM path 
*/
+for (i = 0; i < vm->def->ndisks; i++) {
+if (qemuDiskBusNeedsDriveArg(vm->def->disks[i]->bus)) {
+virQEMUCapsClear(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
+break;
+}
+}
+
 /*
  * Normally PCI addresses are assigned in the virDomainCreate
  * or virDomainDefine methods. We might still need to assign
-- 
2.16.2

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


[libvirt] [PATCHv2 05/62] qemu: monitor: Remove useless 'locked' property from struct qemuDomainDiskInfo

2018-08-13 Thread Peter Krempa
We don't use it for anything useful so it does not make much sense to
extract it.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_domain.h   | 1 -
 src/qemu/qemu_monitor_json.c | 7 ---
 tests/qemumonitorjsontest.c  | 1 -
 3 files changed, 9 deletions(-)

diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index bff293fc0a..7b79d77257 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -438,7 +438,6 @@ struct _qemuDomainVcpuPrivate {

 struct qemuDomainDiskInfo {
 bool removable;
-bool locked;
 bool tray;
 bool tray_open;
 bool empty;
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 0695ec8d2c..2389ebb9aa 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2243,13 +2243,6 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
 goto cleanup;
 }

-if (virJSONValueObjectGetBoolean(dev, "locked", >locked) < 0) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _("cannot read %s value"),
-   "locked");
-goto cleanup;
-}
-
 /* 'tray_open' is present only if the device has a tray */
 if (virJSONValueObjectGetBoolean(dev, "tray_open", >tray_open) 
== 0)
 info->tray = true;
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 3a0490bd26..955892b1f6 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1647,7 +1647,6 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockInfo(const void 
*data)
 if (VIR_ALLOC(info) < 0)
 goto cleanup;

-info->locked = true;
 info->removable = true;
 info->tray = true;

-- 
2.16.2

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


[libvirt] [PATCHv2 10/62] qemu: monitor: Reuse qemuMonitorJSONQueryBlock in qemuMonitorJSONBlockIoThrottleInfo

2018-08-13 Thread Peter Krempa
The wrapper executes the command and does error detection so there's no
need to open-code all of those things.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_monitor_json.c | 37 +
 1 file changed, 5 insertions(+), 32 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index e20851eeb2..48439ccae1 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -4817,21 +4817,14 @@ int qemuMonitorJSONOpenGraphics(qemuMonitorPtr mon,
 goto cleanup; \
 }
 static int
-qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr result,
+qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr io_throttle,
const char *device,
virDomainBlockIoTuneInfoPtr reply)
 {
-virJSONValuePtr io_throttle;
 int ret = -1;
 size_t i;
 bool found = false;

-if (!(io_throttle = virJSONValueObjectGetArray(result, "return"))) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _(" block_io_throttle reply was missing device list"));
-goto cleanup;
-}
-
 for (i = 0; i < virJSONValueArraySize(io_throttle); i++) {
 virJSONValuePtr temp_dev = virJSONValueArrayGet(io_throttle, i);
 virJSONValuePtr inserted;
@@ -5001,33 +4994,13 @@ int qemuMonitorJSONGetBlockIoThrottle(qemuMonitorPtr 
mon,
   virDomainBlockIoTuneInfoPtr reply)
 {
 int ret = -1;
-virJSONValuePtr cmd = NULL;
-virJSONValuePtr result = NULL;
+virJSONValuePtr devices = NULL;

-cmd = qemuMonitorJSONMakeCommand("query-block", NULL);
-if (!cmd)
+if (!(devices = qemuMonitorJSONQueryBlock(mon)))
 return -1;

-if (qemuMonitorJSONCommand(mon, cmd, ) < 0)
-goto cleanup;
-
-if (virJSONValueObjectHasKey(result, "error")) {
-if (qemuMonitorJSONHasError(result, "DeviceNotActive"))
-virReportError(VIR_ERR_OPERATION_INVALID,
-   _("No active operation on device: %s"), device);
-else if (qemuMonitorJSONHasError(result, "NotSupported"))
-virReportError(VIR_ERR_OPERATION_INVALID,
-   _("Operation is not supported for device: %s"), 
device);
-else
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Unexpected error"));
-goto cleanup;
-}
-
-ret = qemuMonitorJSONBlockIoThrottleInfo(result, device, reply);
- cleanup:
-virJSONValueFree(cmd);
-virJSONValueFree(result);
+ret = qemuMonitorJSONBlockIoThrottleInfo(devices, device, reply);
+virJSONValueFree(devices);
 return ret;
 }

-- 
2.16.2

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


[libvirt] [PATCHv2 15/62] tests: qemuxml2argv: Fork CAPS_LATEST test cases for 'blockdev'

2018-08-13 Thread Peter Krempa
The blockdev support will change existing approach to add disks to VMs
so all tests using the DO_TEST_CAPS_LATEST approach which have any disks
need to be forked so that the changes can be applied.

Signed-off-by: Peter Krempa 
---
 tests/qemuxml2argvdata/disk-aio.x86_64-2.12.0.args | 37 +
 .../qemuxml2argvdata/disk-cache.x86_64-2.12.0.args | 50 +
 .../disk-cdrom-network.x86_64-2.12.0.args  | 41 ++
 .../disk-cdrom-tray.x86_64-2.12.0.args | 39 ++
 .../qemuxml2argvdata/disk-cdrom.x86_64-2.12.0.args | 35 
 .../disk-copy_on_read.x86_64-2.12.0.args   | 41 ++
 .../disk-detect-zeroes.x86_64-2.12.0.args  | 37 +
 .../disk-error-policy.x86_64-2.12.0.args   | 41 ++
 .../disk-floppy-q35-2_11.x86_64-2.12.0.args| 35 
 .../disk-floppy-q35-2_9.x86_64-2.12.0.args | 35 
 .../disk-floppy.x86_64-2.12.0.args | 35 
 .../disk-network-gluster.x86_64-2.12.0.args| 44 +++
 .../disk-network-iscsi.x86_64-2.12.0.args  | 63 ++
 .../disk-network-nbd.x86_64-2.12.0.args| 46 
 .../disk-network-rbd.x86_64-2.12.0.args| 61 +
 .../disk-network-sheepdog.x86_64-2.12.0.args   | 35 
 .../disk-network-source-auth.x86_64-2.12.0.args| 47 
 .../disk-network-tlsx509.x86_64-2.12.0.args| 59 
 .../disk-readonly-disk.x86_64-2.12.0.args  | 34 
 .../disk-shared.x86_64-2.12.0.args | 37 +
 ...isk-virtio-scsi-reservations.x86_64-2.12.0.args | 43 +++
 .../floppy-drive-fat.x86_64-2.12.0.args| 33 
 tests/qemuxml2argvtest.c   | 22 
 23 files changed, 950 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/disk-aio.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-cache.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-cdrom-network.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-cdrom-tray.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-cdrom.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-copy_on_read.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-detect-zeroes.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-error-policy.x86_64-2.12.0.args
 create mode 100644 
tests/qemuxml2argvdata/disk-floppy-q35-2_11.x86_64-2.12.0.args
 create mode 100644 
tests/qemuxml2argvdata/disk-floppy-q35-2_9.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-floppy.x86_64-2.12.0.args
 create mode 100644 
tests/qemuxml2argvdata/disk-network-gluster.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-network-iscsi.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-network-nbd.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-network-rbd.x86_64-2.12.0.args
 create mode 100644 
tests/qemuxml2argvdata/disk-network-sheepdog.x86_64-2.12.0.args
 create mode 100644 
tests/qemuxml2argvdata/disk-network-source-auth.x86_64-2.12.0.args
 create mode 100644 
tests/qemuxml2argvdata/disk-network-tlsx509.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-readonly-disk.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/disk-shared.x86_64-2.12.0.args
 create mode 100644 
tests/qemuxml2argvdata/disk-virtio-scsi-reservations.x86_64-2.12.0.args
 create mode 100644 tests/qemuxml2argvdata/floppy-drive-fat.x86_64-2.12.0.args

diff --git a/tests/qemuxml2argvdata/disk-aio.x86_64-2.12.0.args 
b/tests/qemuxml2argvdata/disk-aio.x86_64-2.12.0.args
new file mode 100644
index 00..1dfade0882
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-aio.x86_64-2.12.0.args
@@ -0,0 +1,37 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+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-i440fx-2.12,accel=tcg,usb=off,dump-guest-core=off \
+-m 214 \
+-realtime mlock=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 file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-ide0-0-0,\
+cache=none,aio=native \
+-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1,\
+write-cache=on \
+-drive file=/dev/HostVG/QEMUGuest2,format=raw,if=none,id=drive-ide0-1-0,\
+readonly=on,aio=threads \
+-device 

[libvirt] [PATCHv2 11/62] qemu: monitor: Allow using 'id' instead of 'device' for 'block_set_io_throttle'

2018-08-13 Thread Peter Krempa
The 'device' argument matches only the legacy drive alias. For blockdev
we need to set the throttling for a QOM id and thus we'll need to use
the 'id' field.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c   |  2 +-
 src/qemu/qemu_monitor.c  |  8 +---
 src/qemu/qemu_monitor.h  |  3 ++-
 src/qemu/qemu_monitor_json.c | 14 ++
 src/qemu/qemu_monitor_json.h |  3 ++-
 tests/qemumonitorjsontest.c  |  2 +-
 6 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 15ec92bf10..36ec0a2346 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18474,7 +18474,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
   * via the JSON error code from the block_set_io_throttle call */

 qemuDomainObjEnterMonitor(driver, vm);
-ret = qemuMonitorSetBlockIoThrottle(priv->mon, device,
+ret = qemuMonitorSetBlockIoThrottle(priv->mon, device, NULL,
 , supportMaxOptions,
 set_fields & 
QEMU_BLOCK_IOTUNE_SET_GROUP_NAME,
 supportMaxLengthOptions);
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 4f0bbc147d..2902c3b246 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3444,17 +3444,19 @@ qemuMonitorGetBlockJobInfo(qemuMonitorPtr mon,

 int
 qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,
-  const char *device,
+  const char *drivealias,
+  const char *qomid,
   virDomainBlockIoTuneInfoPtr info,
   bool supportMaxOptions,
   bool supportGroupNameOption,
   bool supportMaxLengthOptions)
 {
-VIR_DEBUG("device=%p, info=%p", device, info);
+VIR_DEBUG("drivealias=%s, qomid=%s, info=%p",
+  NULLSTR(drivealias), NULLSTR(qomid), info);

 QEMU_CHECK_MONITOR(mon);

-return qemuMonitorJSONSetBlockIoThrottle(mon, device, info,
+return qemuMonitorJSONSetBlockIoThrottle(mon, drivealias, qomid, info,
  supportMaxOptions,
  supportGroupNameOption,
  supportMaxLengthOptions);
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index b8e3ca2ce1..16fc75819f 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -932,7 +932,8 @@ int qemuMonitorOpenGraphics(qemuMonitorPtr mon,
 bool skipauth);

 int qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,
-  const char *device,
+  const char *drivealias,
+  const char *qomid,
   virDomainBlockIoTuneInfoPtr info,
   bool supportMaxOptions,
   bool supportGroupNameOption,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 48439ccae1..3a1dfb8563 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -4897,7 +4897,8 @@ qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr 
io_throttle,
 #undef GET_THROTTLE_STATS_OPTIONAL

 int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr mon,
-  const char *device,
+  const char *drivealias,
+  const char *qomid,
   virDomainBlockIoTuneInfoPtr info,
   bool supportMaxOptions,
   bool supportGroupNameOption,
@@ -4907,12 +4908,17 @@ int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr 
mon,
 virJSONValuePtr cmd = NULL;
 virJSONValuePtr result = NULL;
 virJSONValuePtr args = NULL;
+const char *errdev = drivealias;
+
+if (!errdev)
+errdev = qomid;

 if (!(cmd = qemuMonitorJSONMakeCommand("block_set_io_throttle", NULL)))
 return -1;

 if (virJSONValueObjectCreate(,
- "s:device", device,
+ "S:device", drivealias,
+ "S:id", qomid,
  "U:bps", info->total_bytes_sec,
  "U:bps_rd", info->read_bytes_sec,
  "U:bps_wr", info->write_bytes_sec,
@@ -4967,10 +4973,10 @@ int qemuMonitorJSONSetBlockIoThrottle(qemuMonitorPtr 
mon,
 if (virJSONValueObjectHasKey(result, "error")) {
 if (qemuMonitorJSONHasError(result, "DeviceNotActive")) {
 virReportError(VIR_ERR_OPERATION_INVALID,
-   _("No active operation on device: %s"), device);
+   

[libvirt] [PATCHv2 16/62] tests: qemu: Add test data for backing chains and indexes

2018-08-13 Thread Peter Krempa
Add test data for nested backing chains with/without indexes (used in
status XMLs) which will excercise blockdev and the related work.

Signed-off-by: Peter Krempa 
---
 .../disk-backing-chains-index.x86_64-2.12.0.args   |   1 +
 .../disk-backing-chains-index.x86_64-latest.args   |   1 +
 .../qemuxml2argvdata/disk-backing-chains-index.xml | 145 +
 .../disk-backing-chains-noindex.x86_64-2.12.0.args |  58 +
 .../disk-backing-chains-noindex.x86_64-latest.args |  58 +
 .../disk-backing-chains-noindex.xml| 145 +
 tests/qemuxml2argvtest.c   |   4 +
 .../disk-backing-chains-index-active.xml   |  76 +++
 .../disk-backing-chains-index-inactive.xml |  76 +++
 .../disk-backing-chains-noindex-active.xml |  76 +++
 .../disk-backing-chains-noindex-inactive.xml   |  76 +++
 tests/qemuxml2xmltest.c|   2 +
 12 files changed, 718 insertions(+)
 create mode 12 
tests/qemuxml2argvdata/disk-backing-chains-index.x86_64-2.12.0.args
 create mode 12 
tests/qemuxml2argvdata/disk-backing-chains-index.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/disk-backing-chains-index.xml
 create mode 100644 
tests/qemuxml2argvdata/disk-backing-chains-noindex.x86_64-2.12.0.args
 create mode 100644 
tests/qemuxml2argvdata/disk-backing-chains-noindex.x86_64-latest.args
 create mode 100644 tests/qemuxml2argvdata/disk-backing-chains-noindex.xml
 create mode 100644 
tests/qemuxml2xmloutdata/disk-backing-chains-index-active.xml
 create mode 100644 
tests/qemuxml2xmloutdata/disk-backing-chains-index-inactive.xml
 create mode 100644 
tests/qemuxml2xmloutdata/disk-backing-chains-noindex-active.xml
 create mode 100644 
tests/qemuxml2xmloutdata/disk-backing-chains-noindex-inactive.xml

diff --git 
a/tests/qemuxml2argvdata/disk-backing-chains-index.x86_64-2.12.0.args 
b/tests/qemuxml2argvdata/disk-backing-chains-index.x86_64-2.12.0.args
new file mode 12
index 00..3f4cd9040d
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-backing-chains-index.x86_64-2.12.0.args
@@ -0,0 +1 @@
+disk-backing-chains-noindex.x86_64-2.12.0.args
\ No newline at end of file
diff --git 
a/tests/qemuxml2argvdata/disk-backing-chains-index.x86_64-latest.args 
b/tests/qemuxml2argvdata/disk-backing-chains-index.x86_64-latest.args
new file mode 12
index 00..549eb65512
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-backing-chains-index.x86_64-latest.args
@@ -0,0 +1 @@
+disk-backing-chains-noindex.x86_64-latest.args
\ No newline at end of file
diff --git a/tests/qemuxml2argvdata/disk-backing-chains-index.xml 
b/tests/qemuxml2argvdata/disk-backing-chains-index.xml
new file mode 100644
index 00..95b8a64cf8
--- /dev/null
+++ b/tests/qemuxml2argvdata/disk-backing-chains-index.xml
@@ -0,0 +1,145 @@
+
+  QEMUGuest1
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219136
+  219136
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu-system-i686
+
+  
+  
+
+  
+  
+
+
+  
+  
+
+
+  
+  
+
+  
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+  
+
+
+
+  
+  
+  
+
+  
+
+  
+
+  
+  
+
+
+  
+  
+  
+
+  
+  
+
+
+  
+  
+
+  
+  
+
+
+
+  
+  
+
+
+
+  
+  
+
+
+  
+  
+  
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+
+
+  
+
+  
+
+  
+
+  
+
+  
+
+  
+  
+
+
+
+
+  
+
diff --git 
a/tests/qemuxml2argvdata/disk-backing-chains-noindex.x86_64-2.12.0.args 
b/tests/qemuxml2argvdata/disk-backing-chains-noindex.x86_64-2.12.0.args
new file mode 100644
index 00..dea109b13a
--- /dev/null
+++ 

[libvirt] [PATCHv2 18/62] util: virqemu: Simplify debugging if building QOM object with missing args

2018-08-13 Thread Peter Krempa
Print the values so it's simpler to debug.

Signed-off-by: Peter Krempa 
---
 src/util/virqemu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/util/virqemu.c b/src/util/virqemu.c
index bc788538af..13ad7410b4 100644
--- a/src/util/virqemu.c
+++ b/src/util/virqemu.c
@@ -235,8 +235,9 @@ virQEMUBuildObjectCommandlineFromJSONInternal(virBufferPtr 
buf,
   virJSONValuePtr props)
 {
 if (!type || !alias) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("missing 'type' or 'alias' field of QOM 'object'"));
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("missing 'type'(%s) or 'alias'(%s) field of QOM 
'object'"),
+   NULLSTR(type), NULLSTR(alias));
 return -1;
 }

-- 
2.16.2

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


[libvirt] [PATCHv2 02/62] tests: qemumonitorjson: Simplify debugging of 'blockInfo' test

2018-08-13 Thread Peter Krempa
Print the differences in case when the expected data does not match.

Signed-off-by: Peter Krempa 
---
 tests/qemumonitorjsontest.c | 19 ++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index e9b2632655..3a0490bd26 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1585,12 +1585,29 @@ testQemuMonitorJSONqemuMonitorJSONGetVirtType(const 
void *data)
 return ret;
 }

+
+static void
+testQemuMonitorJSONGetBlockInfoPrint(const struct qemuDomainDiskInfo *d)
+{
+VIR_TEST_VERBOSE("removable: %d, tray: %d, tray_open: %d, empty: %d, "
+ "io_status: %d, nodename: '%s'\n",
+ d->removable, d->tray, d->tray_open, d->empty,
+ d->io_status, NULLSTR(d->nodename));
+}
+
+
 static int
 testHashEqualQemuDomainDiskInfo(const void *value1, const void *value2)
 {
 const struct qemuDomainDiskInfo *info1 = value1, *info2 = value2;
+int ret;
+
+if ((ret = memcmp(info1, info2, sizeof(*info1))) != 0) {
+testQemuMonitorJSONGetBlockInfoPrint(info1);
+testQemuMonitorJSONGetBlockInfoPrint(info2);
+}

-return memcmp(info1, info2, sizeof(*info1));
+return ret;
 }

 static int
-- 
2.16.2

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


[libvirt] [PATCHv2 07/62] Revert "qemu: monitor: Add the 'query-nodes' argument for query-blockstats"

2018-08-13 Thread Peter Krempa
Turns out that 'query-nodes' is not what we want and the
'query-blockstats' command was in fact buggy. Revert the new field since
it's not needed.

This reverts commit 50edca1331298bfcb2622e8fe588d493aff9ab68.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_block.c| 2 +-
 src/qemu/qemu_monitor.c  | 8 ++--
 src/qemu/qemu_monitor.h  | 3 +--
 src/qemu/qemu_monitor_json.c | 9 +++--
 src/qemu/qemu_monitor_json.h | 3 +--
 5 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index be120b30f0..ccdd334367 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -358,7 +358,7 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver,
 return -1;

 data = qemuMonitorQueryNamedBlockNodes(qemuDomainGetMonitor(vm));
-blockstats = qemuMonitorQueryBlockstats(qemuDomainGetMonitor(vm), false);
+blockstats = qemuMonitorQueryBlockstats(qemuDomainGetMonitor(vm));

 if (qemuDomainObjExitMonitor(driver, vm) < 0 || !data || !blockstats)
 goto cleanup;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 6e0644221b..4f0bbc147d 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2243,19 +2243,15 @@ qemuMonitorGetBlockInfo(qemuMonitorPtr mon)
 /**
  * qemuMonitorQueryBlockstats:
  * @mon: monitor object
- * @nodenames: include backing chain nodes with explicitly specified name
  *
  * Returns data from a call to 'query-blockstats'.
  */
 virJSONValuePtr
-qemuMonitorQueryBlockstats(qemuMonitorPtr mon,
-   bool nodenames)
+qemuMonitorQueryBlockstats(qemuMonitorPtr mon)
 {
 QEMU_CHECK_MONITOR_NULL(mon);

-VIR_DEBUG("nodenames: %d", nodenames);
-
-return qemuMonitorJSONQueryBlockstats(mon, nodenames);
+return qemuMonitorJSONQueryBlockstats(mon);
 }


diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 2fa8d5b51d..b8e3ca2ce1 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -563,8 +563,7 @@ int qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
 int qemuMonitorBlockIOStatusToError(const char *status);
 virHashTablePtr qemuMonitorGetBlockInfo(qemuMonitorPtr mon);

-virJSONValuePtr qemuMonitorQueryBlockstats(qemuMonitorPtr mon,
-   bool nodenames);
+virJSONValuePtr qemuMonitorQueryBlockstats(qemuMonitorPtr mon);

 typedef struct _qemuBlockStats qemuBlockStats;
 typedef qemuBlockStats *qemuBlockStatsPtr;
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 2389ebb9aa..e20851eeb2 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2362,16 +2362,13 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,


 virJSONValuePtr
-qemuMonitorJSONQueryBlockstats(qemuMonitorPtr mon,
-   bool nodenames)
+qemuMonitorJSONQueryBlockstats(qemuMonitorPtr mon)
 {
 virJSONValuePtr cmd;
 virJSONValuePtr reply = NULL;
 virJSONValuePtr ret = NULL;

-if (!(cmd = qemuMonitorJSONMakeCommand("query-blockstats",
-   "B:query-nodes", nodenames,
-   NULL)))
+if (!(cmd = qemuMonitorJSONMakeCommand("query-blockstats", NULL)))
 return NULL;

 if (qemuMonitorJSONCommand(mon, cmd, ) < 0)
@@ -2400,7 +2397,7 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
 size_t i;
 virJSONValuePtr devices;

-if (!(devices = qemuMonitorJSONQueryBlockstats(mon, false)))
+if (!(devices = qemuMonitorJSONQueryBlockstats(mon)))
 return -1;

 for (i = 0; i < virJSONValueArraySize(devices); i++) {
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 2408ab0c5b..0458d81c0d 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -86,8 +86,7 @@ int qemuMonitorJSONSetMemoryStatsPeriod(qemuMonitorPtr mon,
 int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
 virHashTablePtr table);

-virJSONValuePtr qemuMonitorJSONQueryBlockstats(qemuMonitorPtr mon,
-   bool nodenames);
+virJSONValuePtr qemuMonitorJSONQueryBlockstats(qemuMonitorPtr mon);
 int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
 virHashTablePtr hash,
 bool backingChain);
-- 
2.16.2

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


[libvirt] [PATCHv2 01/62] qemu: process: Fix alias for disk-tray-moved event

2018-08-13 Thread Peter Krempa
Currently we'd report the alias of the drive which is backing the cdrom
rather than the device itself:

 $ virsh event ds tray-change --loop
 event 'tray-change' for domain ds disk drive-ide0-0-1: opened
 event 'tray-change' for domain ds disk drive-ide0-0-1: closed

Report the disk device alias as we document in the API docs.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_process.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index c4e33723d1..c1a8dfda29 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1053,9 +1053,7 @@ qemuProcessHandleTrayChange(qemuMonitorPtr mon 
ATTRIBUTE_UNUSED,
 disk = qemuProcessFindDomainDiskByAlias(vm, devAlias);

 if (disk) {
-event = virDomainEventTrayChangeNewFromObj(vm,
-   devAlias,
-   reason);
+event = virDomainEventTrayChangeNewFromObj(vm, disk->info.alias, 
reason);
 /* Update disk tray status */
 if (reason == VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN)
 disk->tray_status = VIR_DOMAIN_DISK_TRAY_OPEN;
-- 
2.16.2

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


[libvirt] [PATCHv2 03/62] qemu: Improve errors in qemuDomainBlockResize

2018-08-13 Thread Peter Krempa
Remove the pointless "empty path" check and use a better error message
if the disk was not found.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d4a2379e48..4fc1e358fa 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10963,12 +10963,6 @@ qemuDomainBlockResize(virDomainPtr dom,

 virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1);

-if (path[0] == '\0') {
-virReportError(VIR_ERR_INVALID_ARG,
-   "%s", _("empty path"));
-return -1;
-}
-
 /* We prefer operating on bytes.  */
 if ((flags & VIR_DOMAIN_BLOCK_RESIZE_BYTES) == 0) {
 if (size > ULLONG_MAX / 1024) {
@@ -10996,7 +10990,7 @@ qemuDomainBlockResize(virDomainPtr dom,

 if (!(disk = virDomainDiskByName(vm->def, path, false))) {
 virReportError(VIR_ERR_INVALID_ARG,
-   _("invalid path: %s"), path);
+   _("disk '%s' was not found in the domain config"), 
path);
 goto endjob;
 }

-- 
2.16.2

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


[libvirt] [PATCHv2 12/62] qemu: monitor: Allow using 'qdev' instead of 'device' for getting disk throttling

2018-08-13 Thread Peter Krempa
The 'device' field reported by 'query-block' is empty when -blockdev is
used. Add an argument which will allow matching disk by using the qdev
id so we can use this code with -blockdev.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_driver.c   |  2 +-
 src/qemu/qemu_monitor.c  |  8 +---
 src/qemu/qemu_monitor.h  |  3 ++-
 src/qemu/qemu_monitor_json.c | 21 ++---
 src/qemu/qemu_monitor_json.h |  3 ++-
 tests/qemumonitorjsontest.c  |  2 +-
 6 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 36ec0a2346..d11e990443 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -18603,7 +18603,7 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
 if (!(device = qemuAliasDiskDriveFromDisk(disk)))
 goto endjob;
 qemuDomainObjEnterMonitor(driver, vm);
-ret = qemuMonitorGetBlockIoThrottle(priv->mon, device, );
+ret = qemuMonitorGetBlockIoThrottle(priv->mon, device, NULL, );
 if (qemuDomainObjExitMonitor(driver, vm) < 0)
 goto endjob;
 if (ret < 0)
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 2902c3b246..758942ffcb 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3465,14 +3465,16 @@ qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,

 int
 qemuMonitorGetBlockIoThrottle(qemuMonitorPtr mon,
-  const char *device,
+  const char *drivealias,
+  const char *qdevid,
   virDomainBlockIoTuneInfoPtr reply)
 {
-VIR_DEBUG("device=%p, reply=%p", device, reply);
+VIR_DEBUG("drivealias=%s, qdevid=%s, reply=%p",
+  NULLSTR(drivealias), NULLSTR(qdevid), reply);

 QEMU_CHECK_MONITOR(mon);

-return qemuMonitorJSONGetBlockIoThrottle(mon, device, reply);
+return qemuMonitorJSONGetBlockIoThrottle(mon, drivealias, qdevid, reply);
 }


diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 16fc75819f..60418422e9 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -940,7 +940,8 @@ int qemuMonitorSetBlockIoThrottle(qemuMonitorPtr mon,
   bool supportMaxLengthOptions);

 int qemuMonitorGetBlockIoThrottle(qemuMonitorPtr mon,
-  const char *device,
+  const char *drivealias,
+  const char *qdevid,
   virDomainBlockIoTuneInfoPtr reply);

 int qemuMonitorSystemWakeup(qemuMonitorPtr mon);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 3a1dfb8563..e43447dc53 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -4818,7 +4818,8 @@ int qemuMonitorJSONOpenGraphics(qemuMonitorPtr mon,
 }
 static int
 qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr io_throttle,
-   const char *device,
+   const char *drivealias,
+   const char *qdevid,
virDomainBlockIoTuneInfoPtr reply)
 {
 int ret = -1;
@@ -4828,7 +4829,8 @@ qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr 
io_throttle,
 for (i = 0; i < virJSONValueArraySize(io_throttle); i++) {
 virJSONValuePtr temp_dev = virJSONValueArrayGet(io_throttle, i);
 virJSONValuePtr inserted;
-const char *current_dev;
+const char *current_drive;
+const char *current_qdev;

 if (!temp_dev || virJSONValueGetType(temp_dev) != 
VIR_JSON_TYPE_OBJECT) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -4837,14 +4839,18 @@ qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr 
io_throttle,
 goto cleanup;
 }

-if (!(current_dev = virJSONValueObjectGetString(temp_dev, "device"))) {
+current_qdev = virJSONValueObjectGetString(temp_dev, "qdev");
+current_drive = virJSONValueObjectGetString(temp_dev, "device");
+
+if (!current_drive && !current_qdev) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("block_io_throttle device entry "
  "was not in expected format"));
 goto cleanup;
 }

-if (STRNEQ(current_dev, device))
+if ((drivealias && STRNEQ(current_drive, drivealias)) ||
+(qdevid && STRNEQ(current_qdev, qdevid)))
 continue;

 found = true;
@@ -4885,7 +4891,7 @@ qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr 
io_throttle,
 if (!found) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot find throttling info for device '%s'"),
-   device);
+   drivealias ? drivealias : qdevid);
 goto cleanup;
 }
 ret = 0;
@@ -4996,7 +5002,8 @@ int 

[libvirt] [PATCHv2 04/62] qemu: monitor: Remove unsupported function check for 'block_resize'

2018-08-13 Thread Peter Krempa
QEMU supports 'block_resize' since 0.14 so we don't need to do explicit
checking. Additionally the caller did not use the different value at
all.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_monitor_json.c | 7 ---
 1 file changed, 7 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 2921f110a9..0695ec8d2c 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2550,8 +2550,6 @@ qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr 
mon,
 }


-/* Return 0 on success, -1 on failure, or -2 if not supported.  Size
- * is in bytes.  */
 int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
const char *device,
unsigned long long size)
@@ -2570,11 +2568,6 @@ int qemuMonitorJSONBlockResize(qemuMonitorPtr mon,
 if (qemuMonitorJSONCommand(mon, cmd, ) < 0)
 goto cleanup;

-if (qemuMonitorJSONHasError(reply, "CommandNotFound")) {
-ret = -2;
-goto cleanup;
-}
-
 if (qemuMonitorJSONCheckError(cmd, reply) < 0)
 goto cleanup;

-- 
2.16.2

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


[libvirt] [PATCHv2 00/62] qemu: Add support for -blockdev

2018-08-13 Thread Peter Krempa
In this version everything except blockjobs should work properly.

Similarly to the previous posting, the block job support is not part of
this posting yet so blockjobs will not work.

Changes to v1:
- Added support for floppies via -device so they work with blockdev
- fixed return value from the new media changing API
- fixed handling of the TRAY_MOVED and BLOCK_IO_ERROR events
- fixed two compilation problems with nitpicky compilers
- refactored/fixed setup of backing chain for disk media change
- fixed two regressions when filling stats hash tables without -blockdev
- fixed alias reported in the TRAY_MOVED event to the users
- added helper to retrieve a disk definition from a VM by alias or QOM path

Note that the bump of the capability data needs to be fixed since
jansson support was reverted.

For the quirks of specifying floppies via -device please refer to commit

30/62 qemu: command: Setup floppy drives via -device for blockdev

Peter Krempa (62):
  qemu: process: Fix alias for disk-tray-moved event
  tests: qemumonitorjson: Simplify debugging of 'blockInfo' test
  qemu: Improve errors in qemuDomainBlockResize
  qemu: monitor: Remove unsupported function check for 'block_resize'
  qemu: monitor: Remove useless 'locked' property from struct
qemuDomainDiskInfo
  tests: qemucapabilities: Update capability data for qemu 3.0.0
  Revert "qemu: monitor: Add the 'query-nodes' argument for
query-blockstats"
  qemu: hotplug: consolidate media change code paths
  qemu: hotplug: Prepare disk source in qemuDomainAttachDeviceDiskLive
  qemu: monitor: Reuse qemuMonitorJSONQueryBlock in
qemuMonitorJSONBlockIoThrottleInfo
  qemu: monitor: Allow using 'id' instead of 'device' for
'block_set_io_throttle'
  qemu: monitor: Allow using 'qdev' instead of 'device' for getting disk
throttling
  qemu: monitor: Add 'nodename' argument for 'block_resize'
  tests: qemu: Drop disk from hostdev-mdev tests
  tests: qemuxml2argv: Fork CAPS_LATEST test cases for 'blockdev'
  tests: qemu: Add test data for backing chains and indexes
  qemu: hotplug: Don't generate alias when detaching disk
  util: virqemu: Simplify debugging if building QOM object with missing
args
  qemu: caps: Add capability for using the blockdev infrastructure
  qemu: process: clear QEMU_CAPS_BLOCKDEV for VMs with SD card
  qemu: domain: Don't redetect backing chain when using -blockdev
  qemu: process: Don't detect nodenames when we support -blockdev
  conf: domain: Format out user provided backing chains in XML
  qemu: domain: Add infrastructure to generate block node names
  conf: Implement private data formatting and parsing for disks
  conf: Allow formatting and parsing of 'index' for disk source image
  qemu: Use proper backingIndex when reporting stats for backing chain
  qemu: Add field to store QDEV path of a disk in private data
  qemu: alias: Generate QDEV name of the block backend for disks
  qemu: command: Setup floppy drives via -device for blockdev
  qemu: domain: Add field for storing node name for copy-on-read
  qemu: proces: assign node names for user defined backing chains
  qemu: block: Add generator for the 'copy-on-read' blockdev driver
  qemu: domain: Prepare qemuDomainDiskGetBackendAlias for -blockdev
  qemu: command: format disk source commandline for -blockdev
  qemu: command: Add helper to check if disk throttling is enabled
  qemu: process: Setup disk io throttling for -blockdev
  qemu: driver: Use QOM backend name for disk IO throttling APIs
  qemu: driver: Prepare qemuDomainBlockResize for blockdev
  qemu: process: Add lookup via QOM id to
qemuProcessFindDomainDiskByAlias
  qemu: monitor: Handle TRAY_MOVED event correctly with -blockdev
  qemu: monitor: Handle BLOCK_IO_ERROR event properly with -blockdev
  qemu: hotplug: Prepare for blockdev-add/blockdev-del with backing
chains
  qemu: monitor: Add APIs for cdrom tray handling for -blockdev
  qemu: hotplug: Implement removable media change for -blockdev
  qemu: driver: Don't copy disk alias in qemuDomainBlocksStatsGather
  qemu: Explicitly find disks for stats totals
  qemu: monitor: Retrieve blockstats also by qdev and node-names
  qemu: monitor: Add APIs for refreshing disk capacity when using
-blockdev
  qemu: driver: Don't pass 'virDomainDiskDefPtr' to
qemuDomainGetStatsOneBlock
  qemu: monitor: Extract 'write-threshold' automatically for -blockdev
  qemu: Extract exporting of disk block statistics
  qemu: Extract exporting of the header for block stats
  qemu: Export stats relevant for the frontend separately
  qemu: Refactor control flow in qemuDomainGetStatsBlockExportDisk
  qemu: Report frontend stats only for the frontend entry
  qemu: Export stats relevant for the storage backend
  qemu: monitor: Report data also for 'qdev' entry in
qemuMonitorJSONGetBlockInfo
  qemu: Use QOM path with query-block when using -blockdev
  qemu: driver: Allow using blockdev with qemuDomainBlocksStatsGather
  qemu: driver: Prepare 

[libvirt] [PATCH v2 1/3] conf: rename structs used by Export function

2018-08-13 Thread Anya Harter
name structs to be the name of the Export function followed by Data
also tweak definitions to follow standard struct definition pattern

ex. for virInterfaceObjListExport, the struct is defined as follows:

typedef struct _virInterfaceObjListExportData 
virInterfaceObjListExportData;
typedef virInterfaceObjListExportData *virInterfaceObjListExportDataPtr;
struct _virInterfaceObjListExportData {...};

Signed-off-by: Anya Harter 
---
 src/conf/virinterfaceobj.c  |  8 +---
 src/conf/virnetworkobj.c|  8 +---
 src/conf/virnodedeviceobj.c |  8 +---
 src/conf/virsecretobj.c |  8 +---
 src/conf/virstorageobj.c| 16 ++--
 5 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index b0c4ca15a1..0fe0042920 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -260,7 +260,9 @@ virInterfaceObjMatch(virInterfaceObjPtr obj,
 #undef MATCH
 
 
-struct virInterfaceObjListData {
+typedef struct _virInterfaceObjListExportData virInterfaceObjListExportData;
+typedef virInterfaceObjListExportData *virInterfaceObjListExportDataPtr;
+struct _virInterfaceObjListExportData {
 virConnectPtr conn;
 virInterfacePtr *ifaces;
 virInterfaceObjListFilter filter;
@@ -274,7 +276,7 @@ virInterfaceObjListPopulate(void *payload,
 const void *name ATTRIBUTE_UNUSED,
 void *opaque)
 {
-struct virInterfaceObjListData *data = opaque;
+virInterfaceObjListExportDataPtr data = opaque;
 virInterfaceObjPtr obj = payload;
 virInterfacePtr iface = NULL;
 
@@ -316,7 +318,7 @@ virInterfaceObjListExport(virConnectPtr conn,
   unsigned int flags)
 {
 int ret = -1;
-struct virInterfaceObjListData data = {
+virInterfaceObjListExportData data = {
 .conn = conn, .ifaces = NULL, .filter = filter, .flags = flags,
 .nifaces = 0, .error = false };
 
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index e00c8a7f6c..f69ee0c2fa 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -1304,7 +1304,9 @@ virNetworkMatch(virNetworkObjPtr obj,
 #undef MATCH
 
 
-struct virNetworkObjListData {
+typedef struct _virNetworkObjListExportData virNetworkObjListExportData;
+typedef virNetworkObjListExportData *virNetworkObjListExportDataPtr;
+struct _virNetworkObjListExportData {
 virConnectPtr conn;
 virNetworkPtr *nets;
 virNetworkObjListFilter filter;
@@ -1318,7 +1320,7 @@ virNetworkObjListPopulate(void *payload,
   const void *name ATTRIBUTE_UNUSED,
   void *opaque)
 {
-struct virNetworkObjListData *data = opaque;
+virNetworkObjListExportDataPtr data = opaque;
 virNetworkObjPtr obj = payload;
 virNetworkPtr net = NULL;
 
@@ -1360,7 +1362,7 @@ virNetworkObjListExport(virConnectPtr conn,
 unsigned int flags)
 {
 int ret = -1;
-struct virNetworkObjListData data = {
+virNetworkObjListExportData data = {
 .conn = conn, .nets = NULL, .filter = filter, .flags = flags,
 .nnets = 0, .error = false };
 
diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index 6c04caf6ab..2c660a080a 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -838,7 +838,9 @@ virNodeDeviceMatch(virNodeDeviceObjPtr obj,
 #undef MATCH
 
 
-struct virNodeDeviceObjListExportData {
+typedef struct _virNodeDeviceObjListExportData virNodeDeviceObjListExportData;
+typedef virNodeDeviceObjListExportData *virNodeDeviceObjListExportDataPtr;
+struct _virNodeDeviceObjListExportData {
 virConnectPtr conn;
 virNodeDeviceObjListFilter filter;
 unsigned int flags;
@@ -854,7 +856,7 @@ virNodeDeviceObjListExportCallback(void *payload,
 {
 virNodeDeviceObjPtr obj = payload;
 virNodeDeviceDefPtr def;
-struct virNodeDeviceObjListExportData *data = opaque;
+virNodeDeviceObjListExportDataPtr data = opaque;
 virNodeDevicePtr device = NULL;
 
 if (data->error)
@@ -890,7 +892,7 @@ virNodeDeviceObjListExport(virConnectPtr conn,
virNodeDeviceObjListFilter filter,
unsigned int flags)
 {
-struct virNodeDeviceObjListExportData data = {
+virNodeDeviceObjListExportData data = {
 .conn = conn, .filter = filter, .flags = flags,
 .devices = NULL, .ndevices = 0, .error = false };
 
diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index 48ce3c8141..c80cf364c6 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -526,7 +526,9 @@ virSecretObjMatchFlags(virSecretObjPtr obj,
 #undef MATCH
 
 
-struct virSecretObjListData {
+typedef struct _virSecretObjListExportData virSecretObjListExportData;
+typedef virSecretObjListExportData *virSecretObjListExportDataPtr;
+struct _virSecretObjListExportData {
 virConnectPtr conn;
  

[libvirt] [PATCH v2 2/3] conf: rename Export Callback functions

2018-08-13 Thread Anya Harter
name functions to be the name of the export function followed by Callback

ex. for virInterfaceObjListExport, the callback function is named
virInterfaceObjListExportCallback

Signed-off-by: Anya Harter 
---
 src/conf/virinterfaceobj.c |  8 
 src/conf/virnetworkobj.c   |  8 
 src/conf/virstorageobj.c   | 16 
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index 0fe0042920..028d699b32 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -272,9 +272,9 @@ struct _virInterfaceObjListExportData {
 };
 
 static int
-virInterfaceObjListPopulate(void *payload,
-const void *name ATTRIBUTE_UNUSED,
-void *opaque)
+virInterfaceObjListExportCallback(void *payload,
+  const void *name ATTRIBUTE_UNUSED,
+  void *opaque)
 {
 virInterfaceObjListExportDataPtr data = opaque;
 virInterfaceObjPtr obj = payload;
@@ -327,7 +327,7 @@ virInterfaceObjListExport(virConnectPtr conn,
   virHashSize(ifaceobjs->objsName) + 1) < 0)
 goto cleanup;
 
-virHashForEach(ifaceobjs->objsName, virInterfaceObjListPopulate, );
+virHashForEach(ifaceobjs->objsName, virInterfaceObjListExportCallback, 
);
 
 if (data.error)
 goto cleanup;
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index f69ee0c2fa..69465d7f44 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -1316,9 +1316,9 @@ struct _virNetworkObjListExportData {
 };
 
 static int
-virNetworkObjListPopulate(void *payload,
-  const void *name ATTRIBUTE_UNUSED,
-  void *opaque)
+virNetworkObjListExportCallback(void *payload,
+const void *name ATTRIBUTE_UNUSED,
+void *opaque)
 {
 virNetworkObjListExportDataPtr data = opaque;
 virNetworkObjPtr obj = payload;
@@ -1370,7 +1370,7 @@ virNetworkObjListExport(virConnectPtr conn,
 if (nets && VIR_ALLOC_N(data.nets, virHashSize(netobjs->objs) + 1) < 0)
 goto cleanup;
 
-virHashForEach(netobjs->objs, virNetworkObjListPopulate, );
+virHashForEach(netobjs->objs, virNetworkObjListExportCallback, );
 
 if (data.error)
 goto cleanup;
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 0964088fda..02ed491b6f 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -972,9 +972,9 @@ struct _virStoragePoolObjVolumeListExportData {
 };
 
 static int
-virStoragePoolObjVolumeListExportCb(void *payload,
-const void *name ATTRIBUTE_UNUSED,
-void *opaque)
+virStoragePoolObjVolumeListExportCallback(void *payload,
+  const void *name ATTRIBUTE_UNUSED,
+  void *opaque)
 {
 virStorageVolObjPtr volobj = payload;
 virStoragePoolObjVolumeListExportDataPtr data = opaque;
@@ -1031,7 +1031,7 @@ virStoragePoolObjVolumeListExport(virConnectPtr conn,
 return -1;
 }
 
-virHashForEach(volumes->objsName, virStoragePoolObjVolumeListExportCb, 
);
+virHashForEach(volumes->objsName, 
virStoragePoolObjVolumeListExportCallback, );
 virObjectRWUnlock(volumes);
 
 if (data.error)
@@ -1987,9 +1987,9 @@ struct _virStoragePoolObjListExportData {
 
 
 static int
-virStoragePoolObjListExportCb(void *payload,
-  const void *name ATTRIBUTE_UNUSED,
-  void *opaque)
+virStoragePoolObjListExportCallback(void *payload,
+const void *name ATTRIBUTE_UNUSED,
+void *opaque)
 {
 virStoragePoolObjPtr obj = payload;
 virStoragePoolObjListExportDataPtr data = opaque;
@@ -2039,7 +2039,7 @@ virStoragePoolObjListExport(virConnectPtr conn,
 if (pools && VIR_ALLOC_N(data.pools, virHashSize(poolobjs->objs) + 1) < 0)
 goto error;
 
-virHashForEach(poolobjs->objs, virStoragePoolObjListExportCb, );
+virHashForEach(poolobjs->objs, virStoragePoolObjListExportCallback, );
 virObjectRWUnlock(poolobjs);
 
 if (data.error)
-- 
2.17.1

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


[libvirt] [PATCH v2 0/3] conf: standardize naming

2018-08-13 Thread Anya Harter
on vir*ObjListExport call stack

Anya Harter (3):
  conf: rename structs used by Export function
  conf: rename Export Callback functions
  conf: rename Match functions

 src/conf/virinterfaceobj.c  | 16 +---
 src/conf/virnetworkobj.c| 24 ---
 src/conf/virnodedeviceobj.c | 14 --
 src/conf/virsecretobj.c | 14 --
 src/conf/virstorageobj.c| 38 -
 5 files changed, 59 insertions(+), 47 deletions(-)

-- 
2.17.1

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


[libvirt] [PATCH v2 3/3] conf: rename Match functions

2018-08-13 Thread Anya Harter
name match functions to be the vir prefix and interface name followed by 
ObjMatch

ex. for virNetworkObjListExport, the match function is named
virNetworkObjMatch

Signed-off-by: Anya Harter 
---
 src/conf/virnetworkobj.c| 8 
 src/conf/virnodedeviceobj.c | 6 +++---
 src/conf/virsecretobj.c | 6 +++---
 src/conf/virstorageobj.c| 6 +++---
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index 69465d7f44..75a48601fa 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -1272,8 +1272,8 @@ virNetworkObjUpdate(virNetworkObjPtr obj,
 
 #define MATCH(FLAG) (flags & (FLAG))
 static bool
-virNetworkMatch(virNetworkObjPtr obj,
-unsigned int flags)
+virNetworkObjMatch(virNetworkObjPtr obj,
+   unsigned int flags)
 {
 /* filter by active state */
 if (MATCH(VIR_CONNECT_LIST_NETWORKS_FILTERS_ACTIVE) &&
@@ -1333,7 +1333,7 @@ virNetworkObjListExportCallback(void *payload,
 !data->filter(data->conn, obj->def))
 goto cleanup;
 
-if (!virNetworkMatch(obj, data->flags))
+if (!virNetworkObjMatch(obj, data->flags))
 goto cleanup;
 
 if (!data->nets) {
@@ -1549,7 +1549,7 @@ virNetworkObjListPruneHelper(const void *payload,
 int want = 0;
 
 virObjectLock(obj);
-want = virNetworkMatch(obj, data->flags);
+want = virNetworkObjMatch(obj, data->flags);
 virObjectUnlock(obj);
 return want;
 }
diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c
index 2c660a080a..c8ad1314b5 100644
--- a/src/conf/virnodedeviceobj.c
+++ b/src/conf/virnodedeviceobj.c
@@ -804,8 +804,8 @@ virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr devs,
 #define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)) && 
\
  virNodeDeviceObjHasCap(obj, VIR_NODE_DEV_CAP_ ## FLAG))
 static bool
-virNodeDeviceMatch(virNodeDeviceObjPtr obj,
-   unsigned int flags)
+virNodeDeviceObjMatch(virNodeDeviceObjPtr obj,
+  unsigned int flags)
 {
 /* Refresh the capabilities first, e.g. due to a driver change */
 if (!obj->skipUpdateCaps &&
@@ -866,7 +866,7 @@ virNodeDeviceObjListExportCallback(void *payload,
 def = obj->def;
 
 if ((!data->filter || data->filter(data->conn, def)) &&
-virNodeDeviceMatch(obj, data->flags)) {
+virNodeDeviceObjMatch(obj, data->flags)) {
 if (data->devices) {
 if (!(device = virGetNodeDevice(data->conn, def->name)) ||
 VIR_STRDUP(device->parentName, def->parent) < 0) {
diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index c80cf364c6..2ff2998c15 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -500,8 +500,8 @@ virSecretObjListNumOfSecrets(virSecretObjListPtr secrets,
 
 #define MATCH(FLAG) (flags & (FLAG))
 static bool
-virSecretObjMatchFlags(virSecretObjPtr obj,
-   unsigned int flags)
+virSecretObjMatch(virSecretObjPtr obj,
+  unsigned int flags)
 {
 virSecretDefPtr def = obj->def;
 
@@ -556,7 +556,7 @@ virSecretObjListExportCallback(void *payload,
 if (data->filter && !data->filter(data->conn, def))
 goto cleanup;
 
-if (!virSecretObjMatchFlags(obj, data->flags))
+if (!virSecretObjMatch(obj, data->flags))
 goto cleanup;
 
 if (!data->secrets) {
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 02ed491b6f..b44ce99dd5 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1908,8 +1908,8 @@ virStoragePoolObjSourceFindDuplicate(virConnectPtr conn,
 
 #define MATCH(FLAG) (flags & (FLAG))
 static bool
-virStoragePoolMatch(virStoragePoolObjPtr obj,
-unsigned int flags)
+virStoragePoolObjMatch(virStoragePoolObjPtr obj,
+   unsigned int flags)
 {
 /* filter by active state */
 if (MATCH(VIR_CONNECT_LIST_STORAGE_POOLS_FILTERS_ACTIVE) &&
@@ -2003,7 +2003,7 @@ virStoragePoolObjListExportCallback(void *payload,
 if (data->filter && !data->filter(data->conn, obj->def))
 goto cleanup;
 
-if (!virStoragePoolMatch(obj, data->flags))
+if (!virStoragePoolObjMatch(obj, data->flags))
 goto cleanup;
 
 if (data->pools) {
-- 
2.17.1

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


Re: [libvirt] [PATCH 0/1] bhyve: Make LPC slot number configurable

2018-08-13 Thread Roman Bogorodskiy
  Ivan Mishonov wrote:

> On 08/13/2018 11:00 AM, Daniel P. Berrangé wrote:
> 
> > On Sun, Aug 12, 2018 at 08:22:08PM +0400, Roman Bogorodskiy wrote:
> >>Ivan Mishonov wrote:
> >>
> >>> Yes, that makes sense. I'll try to find some time next week to redo my
> >>> code and send another patch. Since my time for working on libvirt is
> >>> very limited can you confirm that the LPC configuration should look like
> >>> this:
> >>>
> >>>      
> >>>      
> >>>      
> >> This looks reasonable to me. However, it adds some corner cases we need to
> >> handle:
> >>
> >> 1. I'm wondering if we should still default to 31 if this entry is not 
> >> specified?
> >> We can generate this entry when post-processing XML, but I'm not sure
> >> what's the best way to handle upgrades for the existing domains...
> > It depends if the BHyve driver is at a point where you consider stable
> > upgrades important or not. It could be valid for you to just change the
> > default to 31 if you think its better and upgrade stability is not
> > required yet.

My general view on upgrades is that it's best-effort based at this point. In 
this
specific case, I hope it won't affect many users as we can't run guests
that a picky about LPC, and other guests should be fine with the changed
LPC slot... Though I'll test if my existing guests will handle that
fine.

I guess when bhyve supports migrations (there are some WIP patches for
that), we'll have less flexibility in moving devices/slots around...

> I decided to check what vm-bhyve does. 
> https://github.com/churchers/vm-bhyve/blob/master/lib/vm-run#L367. They 
> seem to always place LPC at slot 31 so I guess it's safe to move it
> >
> >> 2. According to bhyve(8) manual page, lpc is only supported on bus 0, so
> >> need to add 'isa-bridge' specific validation to check that.
> > If its only supported in 1 address, then arguably you don't need to add
> > this at all - just fix the historically mistaken use of 31 in the code
> > and leave it out of XML.
> Yes, we might not need that option at all

Good, so let's stick to the simpler approach for now, and we can always
make things configurable if there's a demand for that.

> > Regards,
> > Daniel
> 

Roman Bogorodskiy


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

Re: [libvirt] [PATCH] rpm: simplify applying of patches

2018-08-13 Thread no-reply
Hi,

This series was run against 'syntax-check' test by patchew.org, which failed, 
please find the details below:

Type: series
Message-id: 20180803093532.16922-1-berra...@redhat.com
Subject: [libvirt] [PATCH] rpm: simplify applying of patches

=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with
# HEAD pointing to a commit that has the patches applied on top of "base"
# branch
time bash -c './autogen.sh && make syntax-check'
=== TEST SCRIPT END ===

Updating bcb55ab053bc79561b55d0394490f4b64e0f2d01
Switched to a new branch 'test'
fatal: Not a valid branch point: '9eae8398edde9446ecc99f4f393bea94652fb6a2'.
Traceback (most recent call last):
  File "patchew-tester/src/patchew-cli", line 523, in test_one
cwd=clone, stdout=logf, stderr=logf)
  File "/usr/lib64/python3.6/subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['git', 'branch', 'base', 
'9eae8398edde9446ecc99f4f393bea94652fb6a2']' returned non-zero exit status 128.


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

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


Re: [libvirt] [PATCH] qemu_migration: Avoid writing to freed memory

2018-08-13 Thread no-reply
Hi,

This series was run against 'syntax-check' test by patchew.org, which failed, 
please find the details below:

Type: series
Message-id: 
7824152ee221199b352c0753db3eefaa5ec9dbb7.1533222453.git.jdene...@redhat.com
Subject: [libvirt] [PATCH] qemu_migration: Avoid writing to freed memory

=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with
# HEAD pointing to a commit that has the patches applied on top of "base"
# branch
time bash -c './autogen.sh && make syntax-check'
=== TEST SCRIPT END ===

Updating bcb55ab053bc79561b55d0394490f4b64e0f2d01
>From https://github.com/patchew-project/libvirt
 t [tag update]patchew/20180803093532.16922-1-berra...@redhat.com 
-> patchew/20180803093532.16922-1-berra...@redhat.com
 t [tag update]
patchew/7824152ee221199b352c0753db3eefaa5ec9dbb7.1533222453.git.jdene...@redhat.com
 -> 
patchew/7824152ee221199b352c0753db3eefaa5ec9dbb7.1533222453.git.jdene...@redhat.com
Switched to a new branch 'test'
fatal: Not a valid branch point: '9eae8398edde9446ecc99f4f393bea94652fb6a2'.
Traceback (most recent call last):
  File "patchew-tester/src/patchew-cli", line 523, in test_one
cwd=clone, stdout=logf, stderr=logf)
  File "/usr/lib64/python3.6/subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['git', 'branch', 'base', 
'9eae8398edde9446ecc99f4f393bea94652fb6a2']' returned non-zero exit status 128.


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

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


Re: [libvirt] [PATCH] spec: Use %make_install

2018-08-13 Thread no-reply
Hi,

This series was run against 'syntax-check' test by patchew.org, which failed, 
please find the details below:

Type: series
Message-id: 
c690de2ccd5777f163f030bcaf13ec4e69881933.1533051128.git.crobi...@redhat.com
Subject: [libvirt] [PATCH] spec: Use %make_install

=== TEST SCRIPT BEGIN ===
#!/bin/bash
# Testing script will be invoked under the git checkout with
# HEAD pointing to a commit that has the patches applied on top of "base"
# branch
time bash -c './autogen.sh && make syntax-check'
=== TEST SCRIPT END ===

Updating bcb55ab053bc79561b55d0394490f4b64e0f2d01
>From https://github.com/patchew-project/libvirt
 t [tag update]
patchew/c690de2ccd5777f163f030bcaf13ec4e69881933.1533051128.git.crobi...@redhat.com
 -> 
patchew/c690de2ccd5777f163f030bcaf13ec4e69881933.1533051128.git.crobi...@redhat.com
Switched to a new branch 'test'
fatal: Not a valid branch point: '9eae8398edde9446ecc99f4f393bea94652fb6a2'.
Traceback (most recent call last):
  File "patchew-tester/src/patchew-cli", line 523, in test_one
cwd=clone, stdout=logf, stderr=logf)
  File "/usr/lib64/python3.6/subprocess.py", line 291, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['git', 'branch', 'base', 
'9eae8398edde9446ecc99f4f393bea94652fb6a2']' returned non-zero exit status 128.


---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to patchew-de...@redhat.com

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


Re: [libvirt] [PATCH] esx: Fix build when libcurl debug is enabled

2018-08-13 Thread Marcos Paulo de Souza
On Mon, Aug 13, 2018 at 03:51:51PM +0200, Michal Prívozník wrote:
> On 08/11/2018 04:39 PM, Marcos Paulo de Souza wrote:
> > When building libvirt with libcurl debug enabled (with
> > ESX_VI__CURL__ENABLE_DEBUG_OUTPUT set), the message bellow pops up:
> > 
> > make[3]: Entering directory '/mnt/data/gitroot/libvirt/src'
> >   CC   esx/libvirt_driver_esx_la-esx_vi.lo
> > esx/esx_vi.c: In function 'esxVI_CURL_Debug':
> > esx/esx_vi.c:191:5: error: enumeration value 'CURLINFO_SSL_DATA_IN' not 
> > handled in switch [-Werror=switch-enum]
> >  switch (type) {
> >  ^~
> > esx/esx_vi.c:191:5: error: enumeration value 'CURLINFO_SSL_DATA_OUT' not 
> > handled in switch [-Werror=switch-enum]
> > esx/esx_vi.c:191:5: error: enumeration value 'CURLINFO_END' not handled in 
> > switch [-Werror=switch-enum]
> > 
> > Our build requires at least libcurl 7.18.0, which is pretty stable since
> > it was release in 2008. Fix this problem by handling the mentioned enums
> > in the code.
> > 
> > Signed-off-by: Marcos Paulo de Souza 
> > ---
> >  src/esx/esx_vi.c | 8 +++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
> > index a816c3a4f9..588670e137 100644
> > --- a/src/esx/esx_vi.c
> > +++ b/src/esx/esx_vi.c
> > @@ -163,7 +163,7 @@ esxVI_CURL_WriteBuffer(char *data, size_t size, size_t 
> > nmemb, void *userdata)
> >  return 0;
> >  }
> >  
> > -#define ESX_VI__CURL__ENABLE_DEBUG_OUTPUT 0
> > +#define ESX_VI__CURL__ENABLE_DEBUG_OUTPUT 1
> 
> The part below is fine. However, I'm not sure about this one ^^. This
> turns curl debugging on by default. I'm not sure that is what we want.

You are right, this part was included by mistake. Would you want me to send a
new version with this part removed?

> 
> >  
> >  #if ESX_VI__CURL__ENABLE_DEBUG_OUTPUT
> >  static int
> > @@ -205,13 +205,19 @@ esxVI_CURL_Debug(CURL *curl ATTRIBUTE_UNUSED, 
> > curl_infotype type,
> >  break;
> >  
> >case CURLINFO_DATA_IN:
> > +  case CURLINFO_SSL_DATA_IN:
> >  VIR_DEBUG("CURLINFO_DATA_IN %s", buffer);
> >  break;
> >  
> >case CURLINFO_DATA_OUT:
> > +  case CURLINFO_SSL_DATA_OUT:
> >  VIR_DEBUG("CURLINFO_DATA_OUT %s", buffer);
> >  break;
> >  
> > +  case CURLINFO_END:
> > +VIR_DEBUG("CURLINFO_END %s", buffer);
> > +break;
> > +
> >default:
> >  VIR_DEBUG("unknown");
> >  break;
> > 
> 
> 
> Michal

-- 
Thanks,
Marcos

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


Re: [libvirt] [PATCH 0/3] conf: qemu: support new Hyper-V enlightenments

2018-08-13 Thread Roman Kagan
On Thu, Aug 09, 2018 at 03:14:18PM +0200, Vitaly Kuznetsov wrote:
> Several new Hyper-V enlightenments were recently added to Qemu:
> - hv-frequencies
> - hv-reenlightenment
> - hv-tlbflush
> 
> Support these in libvirt.
> 
> Vitaly Kuznetsov (3):
>   conf: qemu: add support for Hyper-V frequency MSRs
>   conf: qemu: add support for Hyper-V reenlightenment notifications
>   conf: qemu: add support for Hyper-V PV TLB flush
> 
>  docs/formatdomain.html.in   | 21 +
>  docs/schemas/domaincommon.rng   | 15 +++
>  src/conf/domain_conf.c  | 14 +-
>  src/conf/domain_conf.h  |  3 +++
>  src/cpu/cpu_x86.c   |  9 +
>  src/cpu/cpu_x86_data.h  |  3 +++
>  src/qemu/qemu_command.c |  3 +++
>  src/qemu/qemu_parse_command.c   |  3 +++
>  src/qemu/qemu_process.c |  3 +++
>  tests/qemuxml2argvdata/hyperv-off.xml   |  3 +++
>  tests/qemuxml2argvdata/hyperv.args  |  3 ++-
>  tests/qemuxml2argvdata/hyperv.xml   |  3 +++
>  tests/qemuxml2xmloutdata/hyperv-off.xml |  3 +++
>  tests/qemuxml2xmloutdata/hyperv.xml |  3 +++
>  14 files changed, 87 insertions(+), 2 deletions(-)

Bringing this to the attention of our libvirt guru...

Roman.

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


[libvirt] [PATCH 0/4] Extend apparmor rules for libvirt 4.6

2018-08-13 Thread Christian Ehrhardt
Hi,
this is a summary of things I had to touch recently when working on 4.6.
The first two patches are re-submissions and modifications of last
year which were never totally challenged, but also not pushed yet (I had
no permissions yet back then).

The first was lost in a discussion about virt-aa-helper, whicih eventually
turned out to be clear that it could not help in that case.
  - https://www.redhat.com/archives/libvir-list/2017-February/msg01598.html
  - https://www.redhat.com/archives/libvir-list/2017-March/msg00052.html

The second even got a few Acks, but neither made it into upstream yet.
Parts of it where introduced already, in
  7edcbd02 apparmor: allow libvirt to send term signal to unconfined
  b482925c apparmor: support ptrace checks
But there are still signals blocked with those rules, so I resubmit the
remaining bit. Also I added the Acks to the resubmission.

The third change came in recently via various bug reports which I finally
wanted to adress - e.g. for ceph lib or smb. If we later on spot more
cases that have predictable safe paths under /tmp we can add those.

Finally the forth change was triggered by me testing libvirt 4.6 in
various conditions. Some of them were in containers, and the new libvirt
behavior to carry more mount points into the qemu namespace triggers the
need to rewrite the existing mount-moving rules that we added last year.

Christian Ehrhardt (4):
  apparmor: allow openGraphicsFD for virt manager >1.4
  apparmor: add mediation rules for unconfined guests
  apparmor: allow expected /tmp access patterns
  apparmor: allow to preserve /dev mountpoints into qemu namespaces

 examples/apparmor/libvirt-qemu  | 13 +
 examples/apparmor/usr.sbin.libvirtd | 24 +---
 2 files changed, 26 insertions(+), 11 deletions(-)

-- 
2.17.1

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


[libvirt] [PATCH 2/4] apparmor: add mediation rules for unconfined guests

2018-08-13 Thread Christian Ehrhardt
If a guest runs unconfined , but libvirtd is
confined then the peer for signal can only be detected as
'unconfined'. That triggers issues like:
   apparmor="DENIED" operation="signal"
   profile="/usr/sbin/libvirtd" pid=22395 comm="libvirtd"
   requested_mask="send" denied_mask="send" signal=term peer="unconfined"

To fix this add unconfined as an allowed peer for those operations.

I discussed with the apparmor folks, right now there is no better
separation to be made in this case. But there might be further down the
road with "policy namespaces with scope and view control + stacking"

This is more a use-case addition than a fix to the following two changes:
- 3b1d19e6 AppArmor: add rules needed with additional mediation features
- b482925c apparmor: support ptrace checks

Signed-off-by: Christian Ehrhardt 
Acked-by: Jamie Strandboge 
Acked-by: intrigeri 
---
 examples/apparmor/usr.sbin.libvirtd | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/examples/apparmor/usr.sbin.libvirtd 
b/examples/apparmor/usr.sbin.libvirtd
index dd37866c2a..3ff43c32a2 100644
--- a/examples/apparmor/usr.sbin.libvirtd
+++ b/examples/apparmor/usr.sbin.libvirtd
@@ -74,6 +74,9 @@
   # unconfined also required if guests run without security module
   unix (send, receive) type=stream addr=none peer=(label=unconfined),
 
+  # required if guests run unconfined seclabel type='none' but libvirtd is 
confined
+  signal (read, send) peer=unconfined,
+
   # Very lenient profile for libvirtd since we want to first focus on confining
   # the guests. Guests will have a very restricted profile.
   / r,
-- 
2.17.1

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


[libvirt] [PATCH 4/4] apparmor: allow to preserve /dev mountpoints into qemu namespaces

2018-08-13 Thread Christian Ehrhardt
Libvirt now tries to preserve all mounts under /dev in qemu namespaces.
The old rules only listed a set of known paths but those are no more enough.

I found some due to containers like /dev/.lxc/* and such but also /dev/console
and /dev/net/tun.

Libvirt is correct to do so, but we can no more predict the names properly, so
we modify the rule to allow a wildcard based pattern matching what libvirt does.

Signed-off-by: Christian Ehrhardt 
---
 examples/apparmor/usr.sbin.libvirtd | 16 +---
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/examples/apparmor/usr.sbin.libvirtd 
b/examples/apparmor/usr.sbin.libvirtd
index 3ff43c32a2..b2e38fe0ad 100644
--- a/examples/apparmor/usr.sbin.libvirtd
+++ b/examples/apparmor/usr.sbin.libvirtd
@@ -33,17 +33,11 @@
   mount options=(rw,rslave)  -> /,
   mount options=(rw, nosuid) -> /{var/,}run/libvirt/qemu/*.dev/,
 
-  mount options=(rw, move) /dev/   -> /{var/,}run/libvirt/qemu/*.dev/,
-  mount options=(rw, move) /dev/hugepages/ -> 
/{var/,}run/libvirt/qemu/*.hugepages/,
-  mount options=(rw, move) /dev/mqueue/-> 
/{var/,}run/libvirt/qemu/*.mqueue/,
-  mount options=(rw, move) /dev/pts/   -> /{var/,}run/libvirt/qemu/*.pts/,
-  mount options=(rw, move) /dev/shm/   -> /{var/,}run/libvirt/qemu/*.shm/,
-
-  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.dev/   -> /dev/,
-  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.hugepages/ -> 
/dev/hugepages/,
-  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.mqueue/-> 
/dev/mqueue/,
-  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.pts/   -> /dev/pts/,
-  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.shm/   -> /dev/shm/,
+  # libvirt provides any mounts under /dev to qemu namespaces
+  mount options=(rw, move) /dev/ -> /{var/,}run/libvirt/qemu/*.dev/,
+  mount options=(rw, move) /dev/**{/,} -> /{var/,}run/libvirt/qemu/*{/,},
+  mount options=(rw, move) /{var/,}run/libvirt/qemu/*.dev/ -> /dev/,
+  mount options=(rw, move) /{var/,}run/libvirt/qemu/*{/,} -> /dev/**{/,},
 
   network inet stream,
   network inet dgram,
-- 
2.17.1

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


[libvirt] [PATCH 1/4] apparmor: allow openGraphicsFD for virt manager >1.4

2018-08-13 Thread Christian Ehrhardt
virt-manager's UI connection will need socket access for openGraphicsFD
to work - otherwise users will face a failed connection error when
opening the UI view.

Depending on the exact versions of libvirt and qemu involved this needs
either a rule from qemu to libvirt or vice versa.

Signed-off-by: Christian Ehrhardt 
---
 examples/apparmor/libvirt-qemu  | 3 +++
 examples/apparmor/usr.sbin.libvirtd | 5 +
 2 files changed, 8 insertions(+)

diff --git a/examples/apparmor/libvirt-qemu b/examples/apparmor/libvirt-qemu
index df5f512487..5caf14e418 100644
--- a/examples/apparmor/libvirt-qemu
+++ b/examples/apparmor/libvirt-qemu
@@ -188,6 +188,9 @@
   @{PROC}/device-tree/** r,
   /sys/firmware/devicetree/** r,
 
+  # allow connect with openGraphicsFD to work
+  unix (send, receive) type=stream addr=none peer=(label=/usr/sbin/libvirtd),
+
   # for gathering information about available host resources
   /sys/devices/system/cpu/ r,
   /sys/devices/system/node/ r,
diff --git a/examples/apparmor/usr.sbin.libvirtd 
b/examples/apparmor/usr.sbin.libvirtd
index 3102cab382..dd37866c2a 100644
--- a/examples/apparmor/usr.sbin.libvirtd
+++ b/examples/apparmor/usr.sbin.libvirtd
@@ -69,6 +69,11 @@
   unix (send, receive) type=stream addr=none 
peer=(label=/usr/sbin/libvirtd//qemu_bridge_helper),
   signal (send) set=("term") peer=/usr/sbin/libvirtd//qemu_bridge_helper,
 
+  # allow connect with openGraphicsFD, direction reversed in newer versions
+  unix (send, receive) type=stream addr=none 
peer=(label=libvirt-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*-[0-9a-f]*),
+  # unconfined also required if guests run without security module
+  unix (send, receive) type=stream addr=none peer=(label=unconfined),
+
   # Very lenient profile for libvirtd since we want to first focus on confining
   # the guests. Guests will have a very restricted profile.
   / r,
-- 
2.17.1

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


[libvirt] [PATCH 3/4] apparmor: allow expected /tmp access patterns

2018-08-13 Thread Christian Ehrhardt
Several cases were found needing /tmp, for example ceph will try to list /tmp
and the samba feature of qemu will place things in /tmp/qemu-smb.*.
This is sort of safe because:
 - While /tmp could contain anything it is not recommended to put critical
   data there anyway
 - We restrict general access to only dir listing and reading of files owned
   (intentionally not the full power of user-tmp abstraction)
 - While it would be hard to predict the PID as part of the string for the
   qemu smb feature (this is not exposed through XML so virt-aa-helper
   can't help) it is guarded by the "owner" statement and a pretty clear
   qemu-smb infix in the path.

Signed-off-by: Christian Ehrhardt 
---
 examples/apparmor/libvirt-qemu | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/examples/apparmor/libvirt-qemu b/examples/apparmor/libvirt-qemu
index 5caf14e418..c4f231b328 100644
--- a/examples/apparmor/libvirt-qemu
+++ b/examples/apparmor/libvirt-qemu
@@ -180,6 +180,16 @@
   # for rbd
   /etc/ceph/ceph.conf r,
 
+  # various functions will need /tmp (e.g. ceph), allow the base dir and a
+  # few known functions.
+  # we want to avoid to give blanket read or even write to everything under 
/tmp
+  # so users are expected to add site specific addons for more uncommon cases.
+  # allow only dir listing and owner based file read
+  /{,var/}tmp/ r,
+  owner /{,var/}tmp/**/ r,
+  # allow qemu smb feature specific path with write access
+  owner /tmp/qemu-smb.*/{,**} rw,
+
   # for file-posix getting limits since 9103f1ce
   /sys/devices/**/block/*/queue/max_segments r,
 
-- 
2.17.1

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


  1   2   >