[libvirt] [PATCH] docs: Update the format of the generate metadata example

2018-04-04 Thread John Ferlan
Initially, update the UUID field to have the proper format, but
then also changed the type, id, and name fields.

Signed-off-by: John Ferlan 
---

 While beginning to think more about the vmgenid RFC and creating a 
 element under the , I noted that the existing name and uuid fields
 were a bit out of date. 

 docs/formatdomain.html.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 82e7d7ce66..984563379e 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -31,9 +31,9 @@
 General metadata
 
 
-domain type='xen' id='3'
-  namefv0/name
-  uuid4dea22b31d52d8f32516782e98ab3fa0/uuid
+domain type='kvm' id='1'
+  nameMyFirstGuest/name
+  uuid4dea22b3-1d52-d8f3-2516-782e98ab3fa0/uuid
   titleA short description - title - of the domain/title
   descriptionSome human readable description/description
   metadata
-- 
2.13.6

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


Re: [libvirt] [PATCH 7/7] remote: use a separate connection for storage APIs

2018-04-04 Thread John Ferlan


On 03/28/2018 11:18 AM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé 
> ---
>  src/remote/remote_daemon.h  |  1 +
>  src/remote/remote_daemon_dispatch.c | 17 ++---
>  src/rpc/gendispatch.pl  |  6 ++
>  3 files changed, 17 insertions(+), 7 deletions(-)
> 

FWIW: Once this was applied, I looked through the
remote_daemon_dispatch_stubs.h and remote_daemon_dispatch.c for
priv->conn and various priv->*Conn and with my suggested adjustments
they seem to all be correct. It got monotonous after a bit though :-).

> diff --git a/src/remote/remote_daemon.h b/src/remote/remote_daemon.h
> index 2b757d9cd6..2834da04a9 100644
> --- a/src/remote/remote_daemon.h
> +++ b/src/remote/remote_daemon.h
> @@ -79,6 +79,7 @@ struct daemonClientPrivate {
>  virConnectPtr nodedevConn;
>  virConnectPtr nwfilterConn;
>  virConnectPtr secretConn;
> +virConnectPtr storageConn;
>  
>  daemonClientStreamPtr streams;
>  };
> diff --git a/src/remote/remote_daemon_dispatch.c 
> b/src/remote/remote_daemon_dispatch.c
> index 1a30d73049..10d9d73ff0 100644
> --- a/src/remote/remote_daemon_dispatch.c
> +++ b/src/remote/remote_daemon_dispatch.c

Forgot remoteClientFreePrivateCallbacks here...

> @@ -1750,6 +1750,8 @@ void remoteClientFree(void *data)
>  virConnectClose(priv->nwfilterConn);
>  if (priv->secretConn)
>  virConnectClose(priv->secretConn);
> +if (priv->storageConn)
> +virConnectClose(priv->storageConn);
>  
>  VIR_FREE(priv);
>  }

[...]

> diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
> index 58de379c8a..656f66f1b5 100755
> --- a/src/rpc/gendispatch.pl
> +++ b/src/rpc/gendispatch.pl
> @@ -140,6 +140,9 @@ sub get_conn_arg {
>  if ($type =~ /remote_nonnull_secret/) {
>  return "priv->secretConn";
>  }
> +if ($type =~ /remote_nonnull_storage/) {
> +return "priv->storageConn";
> +}
>  }
>  
>  # This is for the few virConnect APIs that
> @@ -159,6 +162,9 @@ sub get_conn_arg {
>  }
>  if ($proc =~ /Connect.*Secret/) {
>  return "priv->secretConn";
> +} 

git am and syntax-check told me:

s/} /}/

(there's a trailing space).

w/ adjustments,

Reviewed-by: John Ferlan 

John

> +if ($proc =~ /Connect.*Storage/) {
> +return "priv->storageConn";
>  }
>  
>  return "priv->conn";
> 

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

Re: [libvirt] [PATCH 6/7] remote: use a separate connection for secret APIs

2018-04-04 Thread John Ferlan


On 03/28/2018 11:18 AM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé 
> ---
>  src/remote/remote_daemon.h  |  1 +
>  src/remote/remote_daemon_dispatch.c | 19 +++
>  src/rpc/gendispatch.pl  |  6 ++
>  3 files changed, 18 insertions(+), 8 deletions(-)
> 

Reviewed-by: John Ferlan 

John

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

Re: [libvirt] [PATCH 5/7] remote: use a separate connection for nwfilter APIs

2018-04-04 Thread John Ferlan


On 03/28/2018 11:18 AM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé 
> ---
>  src/remote/remote_daemon.h  | 1 +
>  src/remote/remote_daemon_dispatch.c | 3 +++
>  src/rpc/gendispatch.pl  | 6 ++
>  3 files changed, 10 insertions(+)
> 

[...]

> diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
> index 0e7567fbde..d8ab8b17dd 100755
> --- a/src/rpc/gendispatch.pl
> +++ b/src/rpc/gendispatch.pl
> @@ -134,6 +134,9 @@ sub get_conn_arg {
>  if ($type =~ /remote_nonnull_node_device/) {
>  return "priv->nodedevConn";
>  }
> +if ($type =~ /remote_nonnull_nwfilter/) {
> +return "priv->nwfilterConn";
> +}
>  }
>  
>  # This is for the few virConnect APIs that
> @@ -148,6 +151,9 @@ sub get_conn_arg {
>  if ($proc =~ /Node.*Device/) {
>  return "priv->nodedevConn";
>  }
> +if ($proc =~ /Connect.*NWFilter/) {
> +return "priv->nodedevConn";

s/nodedev/nwfilter

w/ the adjustment...

Reviewed-by: John Ferlan 

John
> +}
>  
>  return "priv->conn";
>  }
> 

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

Re: [libvirt] [PATCH 4/7] remote: use a separate connection for nodedev APIs

2018-04-04 Thread John Ferlan


On 03/28/2018 11:18 AM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé 
> ---
>  src/remote/remote_daemon.h  |  1 +
>  src/remote/remote_daemon_dispatch.c | 19 +++
>  src/rpc/gendispatch.pl  |  6 ++
>  3 files changed, 18 insertions(+), 8 deletions(-)
> 

[...]

> diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
> index 5bab13bb7b..0e7567fbde 100755
> --- a/src/rpc/gendispatch.pl
> +++ b/src/rpc/gendispatch.pl
> @@ -131,6 +131,9 @@ sub get_conn_arg {
>  if ($type =~ /remote_nonnull_network/) {
>  return "priv->networkConn";
>  }
> +if ($type =~ /remote_nonnull_node_device/) {
> +return "priv->nodedevConn";
> +}
>  }
>  
>  # This is for the few virConnect APIs that
> @@ -142,6 +145,9 @@ sub get_conn_arg {
>  if ($proc =~ /Connect.*Network/) {
>  return "priv->networkConn";
>  }
> +if ($proc =~ /Node.*Device/) {

Originally I thought this should be NodeDevice; however, I see you're
picking up the NumOfDevices and ListDevices by this syntax.

Hopefully some day there isn't a *NodeGet*Device* entry for those Node,
but not NodeDevice API's... That'd be a bugger to find.

Reviewed-by: John Ferlan 

John

> +return "priv->nodedevConn";
> +}
>  
>  return "priv->conn";
>  }
> 

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

Re: [libvirt] [PATCH 1/7] rpc: refactor way connection object is generated for remote dispatch

2018-04-04 Thread John Ferlan


On 03/28/2018 11:18 AM, Daniel P. Berrangé wrote:
> Calling a push_privconn method to directly push the connection object
> name into the arg list is inconvenient. Refactor so that we acquire
> the connection variable name upfront, and push it to the arg list
> separately. This allows various hardcoded usage of "priv->conn" to
> be parameterized.
> 
> Signed-off-by: Daniel P. Berrangé 
> ---
>  src/rpc/gendispatch.pl | 48 ++--
>  1 file changed, 22 insertions(+), 26 deletions(-)
> 
> diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
> index fb15cc4849..e11921f3d9 100755
> --- a/src/rpc/gendispatch.pl
> +++ b/src/rpc/gendispatch.pl

[...]

> @@ -1002,7 +998,7 @@ elsif ($mode eq "server") {
>  if ($structprefix eq "admin") {
>  print "if (!priv->dmn) {\n";
>  } else {
> -print "if (!priv->conn) {\n";
> +print "if (!$conn) {\n";
>  }

Shouldn't this just be "if (!$conn) {\n" for both halves of the if else?

w/ slight adjustment,

Reviewed-by: John Ferlan 

John

>  
>  print "virReportError(VIR_ERR_INTERNAL_ERROR, \"%s\", 
> _(\"connection not open\"));\n";
> @@ -1034,7 +1030,7 @@ elsif ($mode eq "server") {
>  }
>  
[...]

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

Re: [libvirt] [PATCH 3/7] remote: use a separate connection for network APIs

2018-04-04 Thread John Ferlan


On 03/28/2018 11:18 AM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé 
> ---
>  src/remote/remote_daemon.h  |  1 +
>  src/remote/remote_daemon_dispatch.c | 19 +++
>  src/rpc/gendispatch.pl  |  6 ++
>  3 files changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/src/remote/remote_daemon.h b/src/remote/remote_daemon.h
> index 31f433c15d..60be78fe0b 100644
> --- a/src/remote/remote_daemon.h
> +++ b/src/remote/remote_daemon.h
> @@ -75,6 +75,7 @@ struct daemonClientPrivate {
>   */
>  virConnectPtr conn;
>  virConnectPtr interfaceConn;
> +virConnectPtr networkConn;
>  
>  daemonClientStreamPtr streams;
>  };
> diff --git a/src/remote/remote_daemon_dispatch.c 
> b/src/remote/remote_daemon_dispatch.c
> index 7971646c28..d0bc474850 100644
> --- a/src/remote/remote_daemon_dispatch.c
> +++ b/src/remote/remote_daemon_dispatch.c
> @@ -1699,7 +1699,7 @@ remoteClientFreePrivateCallbacks(struct 
> daemonClientPrivate *priv)

Trying to forward think - will there ever come a day when priv->conn ==
NULL, but priv->*Conn != NULL?  The caller is gated on priv->conn...

IOW: Do we need to separate this one out a bit now

If not, then consider this

Reviewed-by: John Ferlan 

If so, then probably need to see adjustment...

John

>  DEREG_CB(priv->conn, priv->domainEventCallbacks,
>   priv->ndomainEventCallbacks,
>   virConnectDomainEventDeregisterAny, "domain");
> -DEREG_CB(priv->conn, priv->networkEventCallbacks,
> +DEREG_CB(priv->networkConn, priv->networkEventCallbacks,
>   priv->nnetworkEventCallbacks,
>   virConnectNetworkEventDeregisterAny, "network");
>  DEREG_CB(priv->conn, priv->storageEventCallbacks,
[...]

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

Re: [libvirt] [PATCH 2/7] remote: use a separate connection for interface APIs

2018-04-04 Thread John Ferlan


On 03/28/2018 11:18 AM, Daniel P. Berrangé wrote:
> Signed-off-by: Daniel P. Berrangé 
> ---
>  src/remote/remote_daemon.h  |  1 +
>  src/remote/remote_daemon_dispatch.c |  4 
>  src/rpc/gendispatch.pl  | 25 -
>  3 files changed, 29 insertions(+), 1 deletion(-)
> 

Reviewed-by: John Ferlan 

John

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

[libvirt] [PATCH v3 1/2] util: Add helper APIs to get/verify VF Representor name

2018-04-04 Thread Jai Singh Rana
Switchdev VF representor interface name on host is queried based on
Bus:Device:Function information of pci SR-IOV device in Domain's
'hostdev' structure and subsequently verifying the required net sysfs
directory and file entries of VF representor according to switchdev
model.
---
v3 includes changes based on v2's[1] feedback and suggestions. Fixes
warnings reported by syntax-check.
[1] https://www.redhat.com/archives/libvir-list/2018-February/msg00562.html

 po/POTFILES.in  |   1 +
 src/libvirt_private.syms|   7 +
 src/util/Makefile.inc.am|   2 +
 src/util/virhostdev.c   |   2 +-
 src/util/virhostdev.h   |   8 +
 src/util/virnetdevhostdev.c | 374 
 src/util/virnetdevhostdev.h |  35 +
 7 files changed, 428 insertions(+), 1 deletion(-)
 create mode 100644 src/util/virnetdevhostdev.c
 create mode 100644 src/util/virnetdevhostdev.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index d84859a4e..8cd6b86e8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -234,6 +234,7 @@ src/util/virmdev.c
 src/util/virnetdev.c
 src/util/virnetdevbandwidth.c
 src/util/virnetdevbridge.c
+src/util/virnetdevhostdev.c
 src/util/virnetdevip.c
 src/util/virnetdevmacvlan.c
 src/util/virnetdevmidonet.c
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f6897915c..fad235206 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1923,6 +1923,7 @@ virHostCPUStatsAssign;
 virHostdevFindUSBDevice;
 virHostdevIsSCSIDevice;
 virHostdevManagerGetDefault;
+virHostdevNetDevice;
 virHostdevPCINodeDeviceDetach;
 virHostdevPCINodeDeviceReAttach;
 virHostdevPCINodeDeviceReset;
@@ -2306,6 +2307,12 @@ virNetDevBridgeSetSTPDelay;
 virNetDevBridgeSetVlanFiltering;
 
 
+# util/virnetdevhostdev.h
+virNetdevHostdevCheckVFRIfName;
+virNetdevHostdevGetVFRIfName;
+virNetdevHostdevVFRIfStats;
+
+
 # util/virnetdevip.h
 virNetDevIPAddrAdd;
 virNetDevIPAddrDel;
diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
index a3c3b711f..31fe11c68 100644
--- a/src/util/Makefile.inc.am
+++ b/src/util/Makefile.inc.am
@@ -104,6 +104,8 @@ UTIL_SOURCES = \
util/virnetdevbandwidth.h \
util/virnetdevbridge.c \
util/virnetdevbridge.h \
+   util/virnetdevhostdev.c \
+   util/virnetdevhostdev.h \
util/virnetdevip.c \
util/virnetdevip.h \
util/virnetdevmacvlan.c \
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index a12224c58..4f7b46a04 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -306,7 +306,7 @@ virHostdevIsVirtualFunction(virDomainHostdevDefPtr hostdev)
 }
 
 
-static int
+int
 virHostdevNetDevice(virDomainHostdevDefPtr hostdev,
 int pfNetDevIdx,
 char **linkdev,
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 54e1c66be..735220add 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -60,6 +60,14 @@ struct _virHostdevManager {
 };
 
 virHostdevManagerPtr virHostdevManagerGetDefault(void);
+
+int
+virHostdevNetDevice(virDomainHostdevDefPtr hostdev,
+int pfNetDevIdx,
+char **linkdev,
+int *vf)
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
+
 int
 virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr,
 const char *drv_name,
diff --git a/src/util/virnetdevhostdev.c b/src/util/virnetdevhostdev.c
new file mode 100644
index 0..19f95bfdd
--- /dev/null
+++ b/src/util/virnetdevhostdev.c
@@ -0,0 +1,374 @@
+/*
+ * virnetdevhostdev.c: utilities to get/verify Switchdev VF Representor
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "virhostdev.h"
+#include "virnetdev.h"
+#include "virnetdevhostdev.h"
+#include "viralloc.h"
+#include "virstring.h"
+#include "virfile.h"
+#include "virerror.h"
+#include "virlog.h"
+#include "c-ctype.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+VIR_LOG_INIT("util.netdevhostdev");
+
+#ifndef IFNAMSIZ
+#define IFNAMSIZ 16
+#endif
+
+#define IFSWITCHIDSIZ 20
+
+#ifdef __linux__
+/**
+ * virNetdevHostdevNetSysfsPath
+ *
+ * @pf_name: netdev name of the physical function (PF)
+ * @vf: virtual function (VF) number for the device of interest
+ * @vf_ifname: name of the VF 

Re: [libvirt] [ovirt-devel] [kubevirt-dev] Re: [virt-tools-list] Project for profiles and defaults for libvirt domains

2018-04-04 Thread Yaniv Lavi
Hi,
I'd like to go one step back and discuss why we should try to do this on
the high level.

For the last 5-10 years of KVM development, we are pragmatically providing
the Linux host level APIs via project specific host agents/integration code
(Nova agent, oVirt host agent, virt-manager).
In recent time we see new projects that have similar requirements (Cockpit,
different automation tool, KubeVirt), this means that all of the Linux virt
stack consumers are reinventing the wheel and using very different paths to
consume the partial solutions that are provided today.

The use of the Linux virt stack is well defined by the existing projects
scope and it makes a lot of sense to try to provide the common patterns via
the virt stack directly as a host level API that different client or
management consume.
The main goal is to improve the developer experience for virtualization
management applications with an API set that is useful to the entire set of
tools (OSP, oVirt, KubeVirt, Cockpit and so on).

The Linux virt developer community currently is not able to provide best
practices and optimizations from single node knowledge. This means that all
of that smarts is locked to the specific project integration in the good
case or not provided at all and the projects as a whole lose from that.
When testing the Linux virt stack itself and since each project has
different usage pattern, we lose the ability to test abilities on the lower
level making the entire stack less stable and complete for new features.

This also limits the different projects ability to contribute back to the
Linux stack based on their user and market experience for others in open
source to gain.

I understand this shift is technically challenging for existing projects,
but I do see value in doing this even for new implementation like Cockpit
and KubeVirt.
I also believe that the end result could be appealing enough to cause
project like OSP, virt-manager and oVirt to consider to reduce the existing
capabilities of their host side integrations/agents to shims on the host
level and reuse the common/better-tested pattern as clients that was
developed against the experience of the different projects.

I call us all to collaborate and try to converge on a solution that will
help all in the long term in the value you get from the common base.


Thanks,

YANIV LAVI

SENIOR TECHNICAL PRODUCT MANAGER

Red Hat Israel Ltd. 

34 Jerusalem Road, Building A, 1st floor

Ra'anana, Israel 4350109

yl...@redhat.comT: +972-9-7692306/8272306 F: +972-9-7692223IM: ylavi
  TRIED. TESTED. TRUSTED. 
@redhatnews    Red Hat
   Red Hat



On Thu, Mar 22, 2018 at 7:18 PM, Daniel P. Berrangé 
wrote:

> On Thu, Mar 22, 2018 at 03:54:01PM +0100, Martin Kletzander wrote:
> > >
> > > > One more thing could be automatically figuring out best values based
> on
> > > > libosinfo-provided data.
> > > >
> > > > 2) Policies
> > > >
> > > > Lot of the time there are parts of the domain definition that need
> to be
> > > > added, but nobody really cares about them.  Sometimes it's enough to
> > > > have few templates, another time you might want to have a policy
> > > > per-scenario and want to combine them in various ways.  For example
> with
> > > > the data provided by point 1).
> > > >
> > > > For example if you want PCI-Express, you need the q35 machine type,
> but
> > > > you don't really want to care about the machine type.  Or you want to
> > > > use SPICE, but you don't want to care about adding QXL.
> > > >
> > > > What if some of these policies could be specified once (using some
> DSL
> > > > for example), and used by virtuned to merge them in a unified and
> > > > predictable way?
> > > >
> > > > 3) Abstracting the XML
> > > >
> > > > This is probably just usable for stateless apps, but it might happen
> > > > that some apps don't really want to care about the XML at all.  They
> > > > just want an abstract view of the domain, possibly add/remove a
> device
> > > > and that's it.  We could do that as well.  I can't really tell how
> much
> > > > of a demand there is for it, though.
> > >
> > > It is safe to say that applications do not want to touch XML at all.
> > > Any non-trivial application has created an abstraction around XML,
> > > so that they have an API to express what they want, rather than
> > > manipulating of strings to format/parse XML.
> > >
> >
> > Sure, this was just meant to be a question as to whether it's worth
> > pursuing or not.  You make a good point on why it is not (at least for
> > existing apps).
> >
> > However, since this was optional, the way this would look without the
> > XML abstraction is that both input and output would be valid domain
> > definitions, ultimately resulting in something similar to virt-xml with
> > the added 

Re: [libvirt] [ovirt-devel] [kubevirt-dev] Re: [virt-tools-list] Project for profiles and defaults for libvirt domains

2018-04-04 Thread Yaniv Lavi
[resending to include KubeVirt devs ]

YANIV LAVI

SENIOR TECHNICAL PRODUCT MANAGER

Red Hat Israel Ltd. 

34 Jerusalem Road, Building A, 1st floor

Ra'anana, Israel 4350109

yl...@redhat.comT: +972-9-7692306/8272306 F: +972-9-7692223IM: ylavi
  TRIED. TESTED. TRUSTED. 
@redhatnews    Red Hat
   Red Hat



On Wed, Apr 4, 2018 at 7:07 PM, Yaniv Lavi  wrote:

> Hi,
> I'd like to go one step back and discuss why we should try to do this on
> the high level.
>
> For the last 5-10 years of KVM development, we are pragmatically providing
> the Linux host level APIs via project specific host agents/integration code
> (Nova agent, oVirt host agent, virt-manager).
> In recent time we see new projects that have similar requirements
> (Cockpit, different automation tool, KubeVirt), this means that all of the
> Linux virt stack consumers are reinventing the wheel and using very
> different paths to consume the partial solutions that are provided today.
>
> The use of the Linux virt stack is well defined by the existing projects
> scope and it makes a lot of sense to try to provide the common patterns via
> the virt stack directly as a host level API that different client or
> management consume.
> The main goal is to improve the developer experience for virtualization
> management applications with an API set that is useful to the entire set of
> tools (OSP, oVirt, KubeVirt, Cockpit and so on).
>
> The Linux virt developer community currently is not able to provide best
> practices and optimizations from single node knowledge. This means that all
> of that smarts is locked to the specific project integration in the good
> case or not provided at all and the projects as a whole lose from that.
> When testing the Linux virt stack itself and since each project has
> different usage pattern, we lose the ability to test abilities on the lower
> level making the entire stack less stable and complete for new features.
>
> This also limits the different projects ability to contribute back to the
> Linux stack based on their user and market experience for others in open
> source to gain.
>
> I understand this shift is technically challenging for existing projects,
> but I do see value in doing this even for new implementation like Cockpit
> and KubeVirt.
> I also believe that the end result could be appealing enough to cause
> project like OSP, virt-manager and oVirt to consider to reduce the existing
> capabilities of their host side integrations/agents to shims on the host
> level and reuse the common/better-tested pattern as clients that was
> developed against the experience of the different projects.
>
> I call us all to collaborate and try to converge on a solution that will
> help all in the long term in the value you get from the common base.
>
>
> Thanks,
>
> YANIV LAVI
>
> SENIOR TECHNICAL PRODUCT MANAGER
>
> Red Hat Israel Ltd. 
>
> 34 Jerusalem Road, Building A, 1st floor
>
> Ra'anana, Israel 4350109
>
> yl...@redhat.comT: +972-9-7692306/8272306 F: +972-9-7692223IM: 
> ylavi
>   TRIED. TESTED. TRUSTED. 
> @redhatnews    Red Hat 
>    Red Hat 
> 
>
>
> On Thu, Mar 22, 2018 at 7:18 PM, Daniel P. Berrangé 
> wrote:
>
>> On Thu, Mar 22, 2018 at 03:54:01PM +0100, Martin Kletzander wrote:
>> > >
>> > > > One more thing could be automatically figuring out best values
>> based on
>> > > > libosinfo-provided data.
>> > > >
>> > > > 2) Policies
>> > > >
>> > > > Lot of the time there are parts of the domain definition that need
>> to be
>> > > > added, but nobody really cares about them.  Sometimes it's enough to
>> > > > have few templates, another time you might want to have a policy
>> > > > per-scenario and want to combine them in various ways.  For example
>> with
>> > > > the data provided by point 1).
>> > > >
>> > > > For example if you want PCI-Express, you need the q35 machine type,
>> but
>> > > > you don't really want to care about the machine type.  Or you want
>> to
>> > > > use SPICE, but you don't want to care about adding QXL.
>> > > >
>> > > > What if some of these policies could be specified once (using some
>> DSL
>> > > > for example), and used by virtuned to merge them in a unified and
>> > > > predictable way?
>> > > >
>> > > > 3) Abstracting the XML
>> > > >
>> > > > This is probably just usable for stateless apps, but it might happen
>> > > > that some apps don't really want to care about the XML at all.  They
>> > > > just want an abstract view of the domain, possibly add/remove a
>> device
>> > > > and that's it.  We could do that as well.  I can't really tell how
>> much
>> > 

[libvirt] [PATCH v3 2/2] qemu: conf: Network stats support for VF Representors

2018-04-04 Thread Jai Singh Rana
In case of pci SR-IOV device with interface_type as 'hostdev', return
network stats if it has a VF Representor interface on host for
pci SR-IOV device according to switchdev model.
---
v3 includes changes based on v2's[1] feedback and suggestions. Includes
fix for hostdev to net mapping in a given domain.
[1] https://www.redhat.com/archives/libvir-list/2018-February/msg00563.html

 docs/news.xml  |  9 +
 src/conf/domain_conf.c | 15 +++
 src/qemu/qemu_driver.c | 33 +
 3 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/docs/news.xml b/docs/news.xml
index 87f52e83e..04c18495f 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -47,6 +47,15 @@
   supported. In fact, kernel has been supporting this since 4.10.
 
   
+  
+
+  qemu: Support interface network stats for VF Representors
+
+
+  Interface network stats are supported now for SR-IOV device(hostdev)
+  if this interface has VF representor on host in switchdev mode.
+
+  
 
 
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ef16431aa..50813701c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -56,6 +56,7 @@
 #include "virsecret.h"
 #include "virstring.h"
 #include "virnetdev.h"
+#include "virnetdevhostdev.h"
 #include "virnetdevmacvlan.h"
 #include "virhostdev.h"
 #include "virmdev.h"
@@ -28264,12 +28265,26 @@ virDomainNetFindByName(virDomainDefPtr def,
const char *ifname)
 {
 size_t i;
+size_t j;
 
 for (i = 0; i < def->nnets; i++) {
 if (STREQ_NULLABLE(ifname, def->nets[i]->ifname))
 return def->nets[i];
 }
 
+/* Give a try to hostdev */
+for (i = 0; i < def->nhostdevs; i++) {
+if (virNetdevHostdevCheckVFRIfName(def->hostdevs[i], ifname)) {
+for (j = 0; j < def->nnets; j++) {
+if (def->nets[j]->type != VIR_DOMAIN_NET_TYPE_HOSTDEV)
+continue;
+if (memcmp(def->hostdevs[i], >nets[j]->data.hostdev,
+   sizeof(virDomainHostdevDef)) == 0)
+return def->nets[j];
+}
+}
+}
+
 return NULL;
 }
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5c31dfdd5..f2f9d290b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -66,6 +66,7 @@
 #include "virbuffer.h"
 #include "virhostcpu.h"
 #include "virhostmem.h"
+#include "virnetdevhostdev.h"
 #include "virnetdevtap.h"
 #include "virnetdevopenvswitch.h"
 #include "capabilities.h"
@@ -11156,6 +11157,11 @@ qemuDomainInterfaceStats(virDomainPtr dom,
 if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
 if (virNetDevOpenvswitchInterfaceStats(net->ifname, stats) < 0)
 goto cleanup;
+} else if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+if (virNetdevHostdevVFRIfStats(device, stats,
+   !virDomainNetTypeSharesHostView(net))
+   < 0)
+goto cleanup;
 } else {
 if (virNetDevTapInterfaceStats(net->ifname, stats,
!virDomainNetTypeSharesHostView(net)) < 
0)
@@ -19818,6 +19824,7 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver 
ATTRIBUTE_UNUSED,
 {
 size_t i;
 struct _virDomainInterfaceStats tmp;
+char *vf_ifname = NULL;
 int ret = -1;
 
 if (!virDomainObjIsActive(dom))
@@ -19830,21 +19837,39 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver 
ATTRIBUTE_UNUSED,
 virDomainNetDefPtr net = dom->def->nets[i];
 virDomainNetType actualType;
 
-if (!net->ifname)
+actualType = virDomainNetGetActualType(net);
+
+if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+vf_ifname = virNetdevHostdevGetVFRIfName(dom->def->hostdevs[i]);
+if (!vf_ifname)
+continue;
+}
+else if (!net->ifname)
 continue;
 
 memset(, 0, sizeof(tmp));
 
-actualType = virDomainNetGetActualType(net);
 
-QEMU_ADD_NAME_PARAM(record, maxparams,
-"net", "name", i, net->ifname);
+if (actualType != VIR_DOMAIN_NET_TYPE_HOSTDEV)
+QEMU_ADD_NAME_PARAM(record, maxparams,
+"net", "name", i, net->ifname);
+else
+QEMU_ADD_NAME_PARAM(record, maxparams,
+"net", "name", i, vf_ifname);
 
 if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
 if (virNetDevOpenvswitchInterfaceStats(net->ifname, ) < 0) {
 virResetLastError();
 continue;
 }
+} else if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+if (virNetdevHostdevVFRIfStats(vf_ifname, ,
+ 

[libvirt] [PATCH v3 0/2] Support network stats for VF representor interface

2018-04-04 Thread Jai Singh Rana
With availability of switchdev model in linux, it is possible to capture
stats for SR-IOV device with interface_type as 'hostdev' provided device
supports VF represontor in switchdev mode[1] on host.

These stats are supported by adding helper APIs for getting/verifying VF
representor name based on PCI Bus:Device:Function information in domains
'hostdev' structure and querying required net sysfs directory and file
entries on host according to switchdev model. These helper APIs are then
used in qemu/conf to get the interface stats for VF representor on host
of pci SR-IOV device.

[1]  https://www.kernel.org/doc/Documentation/networking/switchdev.txt
V2   https://www.redhat.com/archives/libvir-list/2018-February/msg00561.html

Jai Singh Rana (2):
  util: Add helper APIs to get/verify VF Representor name
  qemu: conf: Network stats support for VF Representors

 docs/news.xml   |   9 ++
 po/POTFILES.in  |   1 +
 src/conf/domain_conf.c  |  15 ++
 src/libvirt_private.syms|   7 +
 src/qemu/qemu_driver.c  |  33 +++-
 src/util/Makefile.inc.am|   2 +
 src/util/virhostdev.c   |   2 +-
 src/util/virhostdev.h   |   8 +
 src/util/virnetdevhostdev.c | 374 
 src/util/virnetdevhostdev.h |  35 +
 10 files changed, 481 insertions(+), 5 deletions(-)
 create mode 100644 src/util/virnetdevhostdev.c
 create mode 100644 src/util/virnetdevhostdev.h

-- 
2.13.6

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


Re: [libvirt] [dbus PATCH v2 5/5] Implement NetworkLookupByName method for Connect interface

2018-04-04 Thread Pavel Hrdina
On Wed, Apr 04, 2018 at 02:26:13PM +0200, Katerina Koukiou wrote:
> Signed-off-by: Katerina Koukiou 
> ---
>  data/org.libvirt.Connect.xml |  6 ++
>  src/connect.c| 29 +
>  test/test_connect.py | 11 +++
>  3 files changed, 46 insertions(+)
> 
> diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
> index ac06875..2901ba5 100644
> --- a/data/org.libvirt.Connect.xml
> +++ b/data/org.libvirt.Connect.xml
> @@ -56,5 +56,11 @@
>
>
>  
> +
> +   +value="See 
> https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByName"/>
> +  
> +  
> +

Same as for the ListNetworks method, keep all methods together.

>
>  
> diff --git a/src/connect.c b/src/connect.c
> index 13fdd20..a17e15c 100644
> --- a/src/connect.c
> +++ b/src/connect.c
> @@ -320,6 +320,34 @@ virtDBusConnectListNetworks(GVariant *inArgs,
>  *outArgs = g_variant_new_tuple(, 1);
>  }
>  
> +static void
> +virtDBusNetworkLookupByName(GVariant *inArgs,
> +GUnixFDList *inFDs G_GNUC_UNUSED,
> +const gchar *objectPath G_GNUC_UNUSED,
> +gpointer userData,
> +GVariant **outArgs,
> +GUnixFDList **outFDs G_GNUC_UNUSED,
> +GError **error)
> +{
> +virtDBusConnect *connect = userData;
> +g_autoptr(virNetwork) network = NULL;
> +g_autofree gchar *path = NULL;
> +const gchar *name;
> +
> +g_variant_get(inArgs, "(s)", );
> +
> +if (!virtDBusConnectOpen(connect, NULL))
> +return;

We should pass error here instead of NULL and I've noticed that the
remaining LookupBy* function have the same issue, that should be fixed
in a followup patch.

With the issue fixed

Reviewed-by: Pavel Hrdina 


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

Re: [libvirt] [dbus PATCH v2 4/5] Implement Name property for Network interface

2018-04-04 Thread Pavel Hrdina
On Wed, Apr 04, 2018 at 02:26:12PM +0200, Katerina Koukiou wrote:
> This commit also introduces the virtDBusNetworkGetVirNetwork
> static function which is needed for the virtDBusNetworkGetName.
> 
> Signed-off-by: Katerina Koukiou 
> ---
>  data/org.libvirt.Network.xml |  4 
>  src/network.c| 43 +++
>  test/Makefile.am |  3 ++-
>  test/libvirttest.py  | 12 
>  test/test_network.py | 19 +++
>  5 files changed, 80 insertions(+), 1 deletion(-)
>  create mode 100755 test/test_network.py

Reviewed-by: Pavel Hrdina 


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

Re: [libvirt] [dbus PATCH v2 3/5] Implement virtDBusUtilVirNetworkFromBusPath helper function.

2018-04-04 Thread Pavel Hrdina
On Wed, Apr 04, 2018 at 02:26:11PM +0200, Katerina Koukiou wrote:
> Signed-off-by: Katerina Koukiou 
> ---
>  src/util.c | 13 +
>  src/util.h |  5 +
>  2 files changed, 18 insertions(+)

This can be squashed into the first patch.  You are introducing support
for new object and this is a generic helper for that object.

Pavel


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

Re: [libvirt] [dbus PATCH v2 2/5] Implement ListNetworks method for Connect interface

2018-04-04 Thread Pavel Hrdina
On Wed, Apr 04, 2018 at 02:26:10PM +0200, Katerina Koukiou wrote:
> Signed-off-by: Katerina Koukiou 
> ---
>  data/org.libvirt.Connect.xml |  6 ++
>  src/connect.c| 41 +
>  2 files changed, 47 insertions(+)
> 
> diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
> index 1695100..ac06875 100644
> --- a/data/org.libvirt.Connect.xml
> +++ b/data/org.libvirt.Connect.xml
> @@ -50,5 +50,11 @@
>
>
>  
> +
> +   +value="See 
> https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListAllNetworks"/>
> +  
> +  
> +

We should keep the methods together.

One more note, but that is for different patch series, I was thinking
about having all the properties, methods and signals sorted in
alphabetic order.

>
>  
> diff --git a/src/connect.c b/src/connect.c
> index 7b3f834..13fdd20 100644
> --- a/src/connect.c
> +++ b/src/connect.c
> @@ -280,6 +280,46 @@ virtDBusDomainLookupByUUID(GVariant *inArgs,
>  *outArgs = g_variant_new("(o)", path);
>  }
>  
> +static void
> +virtDBusConnectListNetworks(GVariant *inArgs,
> +GUnixFDList *inFDs G_GNUC_UNUSED,
> +const gchar *objectPath G_GNUC_UNUSED,
> +gpointer userData,
> +GVariant **outArgs,
> +GUnixFDList **outFDs G_GNUC_UNUSED,
> +GError **error)
> +{
> +virtDBusConnect *connect = userData;
> +g_autoptr(virNetworkPtr) networks = NULL;
> +guint flags;
> +GVariantBuilder builder;
> +GVariant *gnetworks;
> +
> +g_variant_get(inArgs, "(u)", );
> +
> +if (!virtDBusConnectOpen(connect, error))
> +return;
> +
> +if (virConnectListAllNetworks(connect->connection, , flags) < 0)
> +return virtDBusUtilSetLastVirtError(error);
> +
> +if (!*networks)
> +return;
> +
> +g_variant_builder_init(, G_VARIANT_TYPE("ao"));
> +
> +for (gint i = 0; networks[i]; i++) {
> +g_autofree gchar *path = NULL;
> +path = virtDBusUtilBusPathForVirNetwork(networks[i],
> +connect->networkPath);
> +
> +g_variant_builder_add(, "o", path);
> +}
> +
> +gnetworks = g_variant_builder_end();
> +*outArgs = g_variant_new_tuple(, 1);
> +}
> +
>  static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
>  { "Version", virtDBusConnectGetVersion, NULL },
>  { 0 }
> @@ -292,6 +332,7 @@ static virtDBusGDBusMethodTable 
> virtDBusConnectMethodTable[] = {
>  { "DomainLookupByID", virtDBusDomainLookupByID },
>  { "DomainLookupByName", virtDBusDomainLookupByName },
>  { "DomainLookupByUUID", virtDBusDomainLookupByUUID },
> +{ "ListNetworks", virtDBusConnectListNetworks },
>  { 0 }
>  };

Test is missing, similar to the test_list_domains test.

Pavel


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

Re: [libvirt] [PATCH v3 2/3] qemu_cgroup: Handle device mapper targets properly

2018-04-04 Thread Peter Krempa
On Tue, Apr 03, 2018 at 11:03:26 +0200, Michal Privoznik wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=1557769
> 
> Problem with device mapper targets is that there can be several
> other devices 'hidden' behind them. For instance, /dev/dm-1 can
> consist of /dev/sda, /dev/sdb and /dev/sdc. Therefore, when
> setting up devices CGroup and namespaces we have to take this
> into account.
> 
> Signed-off-by: Michal Privoznik 
> ---
>  libvirt.spec.in|  2 ++
>  src/qemu/qemu_cgroup.c | 69 
> +++---
>  2 files changed, 62 insertions(+), 9 deletions(-)

[...]

> @@ -71,12 +75,35 @@ qemuSetupImagePathCgroup(virDomainObjPtr vm,
>  VIR_DEBUG("Allow path %s, perms: %s",
>path, virCgroupGetDevicePermsString(perms));
>  
> -ret = virCgroupAllowDevicePath(priv->cgroup, path, perms, true);
> +rv = virCgroupAllowDevicePath(priv->cgroup, path, perms, true);

So this returns 1 if 'path' is not a char or block device ...

>  
>  virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path,
>   virCgroupGetDevicePermsString(perms),
> - ret);
> + rv);
> +if (rv < 0)
> +goto cleanup;
>  
> +if (virDevMapperGetTargets(path, ) < 0 &&
> +errno != ENOSYS && errno != EBADF) {
> +virReportSystemError(errno,

So in that case this is definitely not necessary and should be skipped.



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

Re: [libvirt] [PATCH v3 3/3] news: Document device mapper fix

2018-04-04 Thread Peter Krempa
On Tue, Apr 03, 2018 at 11:03:27 +0200, Michal Privoznik wrote:
> Signed-off-by: Michal Privoznik 
> ---
>  docs/news.xml | 10 ++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/docs/news.xml b/docs/news.xml
> index 87f52e83ef..065b60b6eb 100644
> --- a/docs/news.xml
> +++ b/docs/news.xml
> @@ -49,6 +49,16 @@
>
>  
>  
> +  
> +
> +  Improve handling of device mapper targets
> +
> +
> +  When starting a domain with a disk backed by a
> +  device-mapper volume libvirt also needs to allow the
> +  storage backing the device mapper in cgroups.

Again, some background for this would be welcome.

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


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

Re: [libvirt] [PATCH v3 2/3] qemu_cgroup: Handle device mapper targets properly

2018-04-04 Thread Peter Krempa
On Tue, Apr 03, 2018 at 11:03:26 +0200, Michal Privoznik wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=1557769

This BZ is private. Please don't use links which can't be viewed by the
public.

> 
> Problem with device mapper targets is that there can be several
> other devices 'hidden' behind them. For instance, /dev/dm-1 can
> consist of /dev/sda, /dev/sdb and /dev/sdc. Therefore, when
> setting up devices CGroup and namespaces we have to take this
> into account.

Also I'd appreciate if you could justify this here. Mention that the
kernel was fixed and this was supposed to be happening from the
beggining.

> Signed-off-by: Michal Privoznik 
> ---
>  libvirt.spec.in|  2 ++
>  src/qemu/qemu_cgroup.c | 69 
> +++---
>  2 files changed, 62 insertions(+), 9 deletions(-)

[...]

> diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
> index b604edb31c..42502e1b03 100644
> --- a/src/qemu/qemu_cgroup.c
> +++ b/src/qemu/qemu_cgroup.c

[...]

> @@ -71,12 +75,35 @@ qemuSetupImagePathCgroup(virDomainObjPtr vm,
>  VIR_DEBUG("Allow path %s, perms: %s",
>path, virCgroupGetDevicePermsString(perms));
>  
> -ret = virCgroupAllowDevicePath(priv->cgroup, path, perms, true);
> +rv = virCgroupAllowDevicePath(priv->cgroup, path, perms, true);
>  
>  virDomainAuditCgroupPath(vm, priv->cgroup, "allow", path,
>   virCgroupGetDevicePermsString(perms),
> - ret);
> + rv);
> +if (rv < 0)
> +goto cleanup;
>  
> +if (virDevMapperGetTargets(path, ) < 0 &&
> +errno != ENOSYS && errno != EBADF) {
> +virReportSystemError(errno,
> + _("Unable to get devmapper targets for %s"),
> + path);
> +goto cleanup;
> +}
> +
> +for (i = 0; targetPaths && targetPaths[i]; i++) {
> +rv = virCgroupAllowDevicePath(priv->cgroup, targetPaths[i], perms, 
> false);
> +
> +virDomainAuditCgroupPath(vm, priv->cgroup, "allow", targetPaths[i],
> + virCgroupGetDevicePermsString(perms),
> + rv);
> +if (rv < 0)
> +goto cleanup;
> +}
> +
> +ret = 0;
> + cleanup:
> +virStringListFree(targetPaths);
>  return ret;
>  }

This looks okay. I did not check that the 'errnos' returned by
libdevmapper are sane given your checks though.

[...]

> @@ -126,11 +154,34 @@ qemuTeardownImageCgroup(virDomainObjPtr vm,
>  
>  VIR_DEBUG("Deny path %s", src->path);
>  
> -ret = virCgroupDenyDevicePath(priv->cgroup, src->path, perms, true);
> +rv = virCgroupDenyDevicePath(priv->cgroup, src->path, perms, true);
>  
>  virDomainAuditCgroupPath(vm, priv->cgroup, "deny", src->path,
> - virCgroupGetDevicePermsString(perms), ret);
> + virCgroupGetDevicePermsString(perms), rv);
> +if (rv < 0)
> +goto cleanup;
>  
> +if (virDevMapperGetTargets(src->path, ) < 0 &&
> +errno != ENOSYS && errno != EBADF) {
> +virReportSystemError(errno,
> + _("Unable to get devmapper targets for %s"),
> + src->path);
> +goto cleanup;
> +}
> +
> +for (i = 0; targetPaths && targetPaths[i]; i++) {
> +rv = virCgroupDenyDevicePath(priv->cgroup, targetPaths[i], perms, 
> false);

This isn't a good idea. If a backing device of a device mapper volume is
shared between two disks, this would rip it out of cgroups even if it
would be still used. I think a simple reproducer for this should be if
you use two LVs in the same VG for backing two disks and hot-unplug one
of them.


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

Re: [libvirt] [PATCH v3 1/3] util: Introduce virDevMapperGetTargets

2018-04-04 Thread Peter Krempa
On Tue, Apr 03, 2018 at 11:03:25 +0200, Michal Privoznik wrote:
> This helper fetches dependencies for given device mapper target.
> 
> At the same time, we need to provide a dummy log function because
> by default libdevmapper prints out error messages to stderr which
> we need to suppress.
> 
> Signed-off-by: Michal Privoznik 
> ---
>  src/libvirt_private.syms |   4 +
>  src/util/Makefile.inc.am |   2 +
>  src/util/virdevmapper.c  | 200 
> +++
>  src/util/virdevmapper.h  |  31 
>  4 files changed, 237 insertions(+)
>  create mode 100644 src/util/virdevmapper.c
>  create mode 100644 src/util/virdevmapper.h

[...]

> diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
> new file mode 100644
> index 00..9491848f48
> --- /dev/null
> +++ b/src/util/virdevmapper.c
> @@ -0,0 +1,200 @@
> +/*
> + * virdevmapper.c: Functions for handling devmapper

device mapper

> + *
> + * Copyright (C) 2018 Red Hat, Inc.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library.  If not, see
> + * .
> + *
> + * Authors:
> + * Michal Privoznik 
> + */
> +
> +#include 

[...]

> +static int
> +virDevMapperGetTargetsImpl(const char *path,
> +   char ***devPaths_ret,
> +   unsigned int ttl)
> +{
> +struct dm_task *dmt = NULL;
> +struct dm_deps *deps;
> +struct dm_info info;
> +char **devPaths = NULL;
> +char **recursiveDevPaths = NULL;
> +size_t i;
> +int ret = -1;
> +
> +*devPaths_ret = NULL;
> +
> +if (virDevMapperInitialize() < 0)
> +return ret;
> +
> +if (!ttl) {

if (ttl == 0)

> +errno = ELOOP;
> +return ret;
> +}
> +
> +if (!(dmt = dm_task_create(DM_DEVICE_DEPS)))
> +return ret;
> +
> +if (!dm_task_set_name(dmt, path)) {
> +if (errno == ENOENT) {
> +/* It's okay, @path is not managed by devmapper =>
> + * not a devmapper device. */
> +ret = 0;
> +}
> +goto cleanup;
> +}
> +
> +dm_task_no_open_count(dmt);
> +
> +if (!dm_task_run(dmt))
> +goto cleanup;
> +
> +if (!dm_task_get_info(dmt, ))
> +goto cleanup;
> +
> +if (!info.exists) {
> +ret = 0;
> +goto cleanup;
> +}
> +
> +if (!(deps = dm_task_get_deps(dmt)))
> +goto cleanup;
> +
> +if (VIR_ALLOC_N_QUIET(devPaths, deps->count + 1) < 0)
> +goto cleanup;
> +
> +for (i = 0; i < deps->count; i++) {
> +if (virAsprintfQuiet([i], "/dev/block/%u:%u",
> + major(deps->device[i]),
> + minor(deps->device[i])) < 0)
> +goto cleanup;
> +}
> +
> +recursiveDevPaths = NULL;
> +for (i = 0; i < deps->count; i++) {
> +char **tmpPaths;
> +
> +if (virDevMapperGetTargetsImpl(devPaths[i], , ttl - 1) < 0)
> +goto cleanup;
> +
> +if (tmpPaths &&
> +virStringListMerge(, ) < 0) {

So these report libvirt errors, but don't mess them up. And only in case
of OOM, so this is fine.

> +virStringListFree(tmpPaths);
> +goto cleanup;
> +}
> +}
> +
> +if (virStringListMerge(, ) < 0)
> +goto cleanup;
> +
> +VIR_STEAL_PTR(*devPaths_ret, devPaths);
> +ret = 0;
> + cleanup:
> +virStringListFree(recursiveDevPaths);
> +virStringListFree(devPaths);
> +dm_task_destroy(dmt);
> +return ret;
> +}
> +
> +
> +/**
> + * virDevMapperGetTargets:
> + * @path: devmapper target
> + * @devPaths: returned string list of devices
> + *
> + * For given @path figure out its targets, and store them in
> + * @devPaths array. Note, @devPaths is a string list so it's NULL
> + * terminated.
> + *
> + * If @path is not a devmapper device, @devPaths is set to NULL and
> + * success is returned.
> + *
> + * If @path consists of yet another devmapper targets these are
> + * consulted recursively.
> + *
> + * If we don't have permissions to talk to kernel, -1 is returned
> + * and errno is set to EBADF.
> + *
> + * Returns 0 on success,
> + *-1 otherwise (with errno set, no libvirt error is
> + *reported)
> + */
> +int
> +virDevMapperGetTargets(const char *path,
> +   char ***devPaths)
> +{
> +

[libvirt] [PATCH 66/68] qemu: Store API flags for async jobs in status XML

2018-04-04 Thread Jiri Denemark
This will help us decide what to do when libvirtd is restarted while an
async job is running.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_domain.c|   8 +
 .../migration-out-nbd-out.xml | 450 +-
 2 files changed, 457 insertions(+), 1 deletion(-)
 mode change 12 => 100644 
tests/qemustatusxml2xmldata/migration-out-nbd-out.xml

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2a15eb273b..704f395c24 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2087,6 +2087,9 @@ qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
   priv->job.phase));
 }
 
+if (priv->job.asyncJob != QEMU_ASYNC_JOB_NONE)
+virBufferAsprintf(, " flags='0x%lx'", priv->job.apiFlags);
+
 if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT) {
 size_t i;
 virDomainDiskDefPtr disk;
@@ -2382,6 +2385,11 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
 }
 }
 
+if (virXPathULongHex("string(@flags)", ctxt, >job.apiFlags) == -2) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid job flags"));
+goto cleanup;
+}
+
 if ((n = virXPathNodeSet("./disk[@migrating='yes']", ctxt, )) < 0)
 goto cleanup;
 
diff --git a/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml 
b/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml
deleted file mode 12
index a4830f04a8..00
--- a/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml
+++ /dev/null
@@ -1 +0,0 @@
-migration-out-nbd-in.xml
\ No newline at end of file
diff --git a/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml 
b/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml
new file mode 100644
index 00..05da1f81c6
--- /dev/null
+++ b/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml
@@ -0,0 +1,449 @@
+
+  
+  
+  
+
+
+  
+  
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  
+  
+
+
+  
+  
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  
+  
+  
+  
+  
+  
+  
+  
+upstream
+dcf47dbd-46d1-4d5b-b442-262a806a333a
+1024000
+1024000
+
+  
+
+8
+
+  
+
+
+  /machine
+
+
+  hvm
+  
+
+
+  
+  
+  
+
+
+  
+
+
+  
+
+
+  
+  
+  
+
+destroy
+restart
+restart
+
+  
+  
+
+
+  /usr/bin/qemu-system-x86_64
+  
+
+
+
+  
+  
+
+  base.qcow2
+
+  
+  
+
+
+
+
+  
+  
+
+
+
+
+
+
+
+
+  
+  
+
+
+  
+  
+
+
+
+  
+  
+
+
+
+  
+  
+
+
+
+  
+  
+
+  
+  
+
+
+  
+  
+
+
+  
+  
+
+
+  
+  
+
+  
+  
+
+
+
+  
+
+
+
+
+
+  
+  
+
+
+  
+
+
+  
+  
+
+
+
+  
+  
+
+
+
+
+  
+  
+
+
+
+  
+  
+
+
+  
+  
+
+  
+  
+
+  
+  
+
+
+  
+  
+
+
+  
+  
+   

[libvirt] [PATCH 67/68] qemu: Don't delete TLS objects unless TLS migration was requested

2018-04-04 Thread Jiri Denemark
Trying to delete the non-existent TLS objects results in ugly error
messages in the log, which could easily confuse users. Let's avoid this
confusion by not trying to delete the objects if we were not asked to
enable TLS migration and thus we didn't created the objects anyway.

This patch restores the behavior to the state before "qemu: Reset all
migration parameters".

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c| 12 ++--
 src/qemu/qemu_migration_params.c | 18 --
 src/qemu/qemu_migration_params.h |  3 ++-
 src/qemu/qemu_process.c  |  6 --
 4 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 808a6c147e..c7dcbf0788 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1771,7 +1771,7 @@ qemuMigrationSrcCleanup(virDomainObjPtr vm,
  " domain was successfully started on destination or not",
  vm->def->name);
 qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
- priv->job.migParams);
+ priv->job.migParams, priv->job.apiFlags);
 /* clear the job and let higher levels decide what to do */
 qemuDomainObjDiscardAsyncJob(driver, vm);
 break;
@@ -2496,7 +2496,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 
  stopjob:
 qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
- priv->job.migParams);
+ priv->job.migParams, priv->job.apiFlags);
 
 if (stopProcess) {
 unsigned int stopFlags = VIR_QEMU_PROCESS_STOP_MIGRATED;
@@ -2866,7 +2866,7 @@ qemuMigrationSrcConfirmPhase(virQEMUDriverPtr driver,
 }
 
 qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
- priv->job.migParams);
+ priv->job.migParams, priv->job.apiFlags);
 
 if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, 
driver->caps) < 0)
 VIR_WARN("Failed to save status on vm %s", vm->def->name);
@@ -4490,7 +4490,7 @@ qemuMigrationSrcPerformJob(virQEMUDriverPtr driver,
  */
 if (!v3proto && ret < 0)
 qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
- priv->job.migParams);
+ priv->job.migParams, priv->job.apiFlags);
 
 if (qemuMigrationSrcRestoreDomainState(driver, vm)) {
 event = virDomainEventLifecycleNewFromObj(vm,
@@ -4579,7 +4579,7 @@ qemuMigrationSrcPerformPhase(virQEMUDriverPtr driver,
  endjob:
 if (ret < 0) {
 qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
- priv->job.migParams);
+ priv->job.migParams, priv->job.apiFlags);
 qemuMigrationJobFinish(driver, vm);
 } else {
 qemuMigrationJobContinue(vm);
@@ -5035,7 +5035,7 @@ qemuMigrationDstFinish(virQEMUDriverPtr driver,
 }
 
 qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
- priv->job.migParams);
+ priv->job.migParams, priv->job.apiFlags);
 
 qemuMigrationJobFinish(driver, vm);
 if (!virDomainObjIsActive(vm))
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 6634fae4f6..a9c0d90f00 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -803,6 +803,7 @@ qemuMigrationParamsDisableTLS(virDomainObjPtr vm,
  * @driver: pointer to qemu driver
  * @vm: domain object
  * @asyncJob: migration job to join
+ * @apiFlags: API flags used to start the migration
  *
  * Deconstruct all the setup possibly done for TLS - delete the TLS and
  * security objects, free the secinfo, and reset the migration params to "".
@@ -811,13 +812,16 @@ static void
 qemuMigrationParamsResetTLS(virQEMUDriverPtr driver,
 virDomainObjPtr vm,
 int asyncJob,
-qemuMigrationParamsPtr origParams)
+qemuMigrationParamsPtr origParams,
+unsigned long apiFlags)
 {
 char *tlsAlias = NULL;
 char *secAlias = NULL;
 
-/* If QEMU does not support TLS migration we didn't set the aliases. */
-if (!origParams->params[QEMU_MIGRATION_PARAM_TLS_CREDS].set)
+/* There's nothing to do if QEMU does not support TLS migration or we were
+ * not asked to enable it. */
+if (!origParams->params[QEMU_MIGRATION_PARAM_TLS_CREDS].set ||
+!(apiFlags & VIR_MIGRATE_TLS))
 return;
 
 /* NB: If either or both fail to allocate memory we can still proceed
@@ -966,11 +970,13 @@ void
 qemuMigrationParamsReset(virQEMUDriverPtr driver,
  virDomainObjPtr vm,
  

[libvirt] [PATCH 46/68] qemu: Drop qemuMigrationCompression structure

2018-04-04 Thread Jiri Denemark
By merging qemuMigrationAnyCompressionParse into
qemuMigrationParamsSetCompression we can drop the useless intermediate
qemuMigrationCompression structure and parse compression related typed
parameters and flags directly into qemuMigrationParams.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c   |  63 ++-
 src/qemu/qemu_migration_params.c | 181 +--
 src/qemu/qemu_migration_params.h |  26 +
 3 files changed, 85 insertions(+), 185 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5e79e90609..8e880280ec 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12126,7 +12126,6 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 virQEMUDriverPtr driver = dconn->privateData;
 virDomainDefPtr def = NULL;
 char *origname = NULL;
-qemuMigrationCompressionPtr compression = NULL;
 qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
@@ -12138,11 +12137,8 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 goto cleanup;
 }
 
-if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
-goto cleanup;
-
 if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
-   QEMU_MIGRATION_DESTINATION, 
compression)))
+   
QEMU_MIGRATION_DESTINATION)))
 goto cleanup;
 
 if (virLockManagerPluginUsesState(driver->lockManager)) {
@@ -12163,7 +12159,6 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 st, , origname, migParams, flags);
 
  cleanup:
-VIR_FREE(compression);
 qemuMigrationParamsFree(migParams);
 VIR_FREE(origname);
 virDomainDefFree(def);
@@ -12188,7 +12183,6 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
 virQEMUDriverPtr driver = dconn->privateData;
 virDomainDefPtr def = NULL;
 char *origname = NULL;
-qemuMigrationCompressionPtr compression = NULL;
 qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
@@ -12204,11 +12198,8 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
 goto cleanup;
 }
 
-if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
-goto cleanup;
-
 if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
-   QEMU_MIGRATION_DESTINATION, 
compression)))
+   
QEMU_MIGRATION_DESTINATION)))
 goto cleanup;
 
 if (virLockManagerPluginUsesState(driver->lockManager)) {
@@ -12236,7 +12227,6 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
 
  cleanup:
 qemuMigrationParamsFree(migParams);
-VIR_FREE(compression);
 VIR_FREE(origname);
 virDomainDefFree(def);
 return ret;
@@ -12257,7 +12247,6 @@ qemuDomainMigratePerform(virDomainPtr dom,
 virDomainObjPtr vm;
 int ret = -1;
 const char *dconnuri = NULL;
-qemuMigrationCompressionPtr compression = NULL;
 qemuMigrationParamsPtr migParams = NULL;
 
 virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -12269,11 +12258,8 @@ qemuDomainMigratePerform(virDomainPtr dom,
 goto cleanup;
 }
 
-if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
-goto cleanup;
-
 if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
-   QEMU_MIGRATION_SOURCE, 
compression)))
+   QEMU_MIGRATION_SOURCE)))
 goto cleanup;
 
 if (!(vm = qemuDomObjFromDomain(dom)))
@@ -12303,7 +12289,6 @@ qemuDomainMigratePerform(virDomainPtr dom,
 
  cleanup:
 qemuMigrationParamsFree(migParams);
-VIR_FREE(compression);
 return ret;
 }
 
@@ -12447,7 +12432,6 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
 virQEMUDriverPtr driver = dconn->privateData;
 virDomainDefPtr def = NULL;
 char *origname = NULL;
-qemuMigrationCompressionPtr compression = NULL;
 qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
@@ -12463,11 +12447,8 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
 goto cleanup;
 }
 
-if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
-goto cleanup;
-
 if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
-   QEMU_MIGRATION_DESTINATION, 
compression)))
+   
QEMU_MIGRATION_DESTINATION)))
 goto cleanup;
 
 if (!(def = qemuMigrationAnyPrepareDef(driver, dom_xml, dname, )))
@@ -12485,7 +12466,6 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
 
  cleanup:
 qemuMigrationParamsFree(migParams);
-VIR_FREE(compression);
 VIR_FREE(origname);
 virDomainDefFree(def);
 return ret;
@@ -12513,7 +12493,6 @@ 

[libvirt] [PATCH 65/68] qemu: Drop priv->job.postcopyEnabled bool

2018-04-04 Thread Jiri Denemark
We store the flags passed to the API which started the migration. Let's
use them instead of a separate bool to check if post-copy migration was
requested.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_domain.c| 1 -
 src/qemu/qemu_domain.h| 1 -
 src/qemu/qemu_driver.c| 2 +-
 src/qemu/qemu_migration.c | 4 
 4 files changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index d82c9aad23..2a15eb273b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -332,7 +332,6 @@ qemuDomainObjResetAsyncJob(qemuDomainObjPrivatePtr priv)
 job->abortJob = false;
 job->spiceMigration = false;
 job->spiceMigrated = false;
-job->postcopyEnabled = false;
 job->dumpCompleted = false;
 VIR_FREE(job->error);
 VIR_FREE(job->current);
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 8d608da121..91385da2a9 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -176,7 +176,6 @@ struct _qemuDomainJobObj {
 bool spiceMigration;/* we asked for spice migration and we
  * should wait for it to finish */
 bool spiceMigrated; /* spice migration completed */
-bool postcopyEnabled;   /* post-copy migration was enabled */
 char *error;/* job event completion error */
 bool dumpCompleted; /* dump completed */
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 04eb0b6929..b871dab581 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13840,7 +13840,7 @@ qemuDomainMigrateStartPostCopy(virDomainPtr dom,
 goto endjob;
 }
 
-if (!priv->job.postcopyEnabled) {
+if (!(priv->job.apiFlags & VIR_MIGRATE_POSTCOPY)) {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("switching to post-copy requires migration to be "
  "started with VIR_MIGRATE_POSTCOPY flag"));
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 3ce180dd39..808a6c147e 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2403,8 +2403,6 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
  migParams) < 0)
 goto stopjob;
 
-priv->job.postcopyEnabled = flags & VIR_MIGRATE_POSTCOPY;
-
 if (mig->nbd &&
 flags & (VIR_MIGRATE_NON_SHARED_DISK | VIR_MIGRATE_NON_SHARED_INC) &&
 virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NBD_SERVER)) {
@@ -3340,8 +3338,6 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
  migParams) < 0)
 goto error;
 
-priv->job.postcopyEnabled = flags & VIR_MIGRATE_POSTCOPY;
-
 if (migrate_flags & (QEMU_MONITOR_MIGRATE_NON_SHARED_DISK |
  QEMU_MONITOR_MIGRATE_NON_SHARED_INC)) {
 if (mig->nbd) {
-- 
2.17.0

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


[libvirt] [PATCH 61/68] qemumigparamstest: Add test data for TLS parameters

2018-04-04 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 tests/qemumigparamsdata/tls-enabled.json   | 11 +++
 tests/qemumigparamsdata/tls-enabled.reply  | 14 ++
 tests/qemumigparamsdata/tls-enabled.xml| 13 +
 tests/qemumigparamsdata/tls-hostname.json  | 11 +++
 tests/qemumigparamsdata/tls-hostname.reply | 14 ++
 tests/qemumigparamsdata/tls-hostname.xml   | 13 +
 tests/qemumigparamsdata/tls.json   | 11 +++
 tests/qemumigparamsdata/tls.reply  | 14 ++
 tests/qemumigparamsdata/tls.xml| 13 +
 tests/qemumigparamstest.c  |  3 +++
 10 files changed, 117 insertions(+)
 create mode 100644 tests/qemumigparamsdata/tls-enabled.json
 create mode 100644 tests/qemumigparamsdata/tls-enabled.reply
 create mode 100644 tests/qemumigparamsdata/tls-enabled.xml
 create mode 100644 tests/qemumigparamsdata/tls-hostname.json
 create mode 100644 tests/qemumigparamsdata/tls-hostname.reply
 create mode 100644 tests/qemumigparamsdata/tls-hostname.xml
 create mode 100644 tests/qemumigparamsdata/tls.json
 create mode 100644 tests/qemumigparamsdata/tls.reply
 create mode 100644 tests/qemumigparamsdata/tls.xml

diff --git a/tests/qemumigparamsdata/tls-enabled.json 
b/tests/qemumigparamsdata/tls-enabled.json
new file mode 100644
index 00..d42684a9de
--- /dev/null
+++ b/tests/qemumigparamsdata/tls-enabled.json
@@ -0,0 +1,11 @@
+{
+  "compress-level": 1,
+  "compress-threads": 8,
+  "decompress-threads": 2,
+  "cpu-throttle-initial": 20,
+  "cpu-throttle-increment": 10,
+  "tls-creds": "objlibvirt_migrate_tls0",
+  "tls-hostname": "",
+  "max-bandwidth": 33554432,
+  "downtime-limit": 300
+}
diff --git a/tests/qemumigparamsdata/tls-enabled.reply 
b/tests/qemumigparamsdata/tls-enabled.reply
new file mode 100644
index 00..001241b075
--- /dev/null
+++ b/tests/qemumigparamsdata/tls-enabled.reply
@@ -0,0 +1,14 @@
+{
+  "id": "libvirt-1",
+  "return": {
+"decompress-threads": 2,
+"cpu-throttle-increment": 10,
+"compress-threads": 8,
+"tls-hostname": "",
+"compress-level": 1,
+"cpu-throttle-initial": 20,
+"tls-creds": "objlibvirt_migrate_tls0",
+"max-bandwidth": 33554432,
+"downtime-limit": 300
+  }
+}
diff --git a/tests/qemumigparamsdata/tls-enabled.xml 
b/tests/qemumigparamsdata/tls-enabled.xml
new file mode 100644
index 00..3e60c4dec3
--- /dev/null
+++ b/tests/qemumigparamsdata/tls-enabled.xml
@@ -0,0 +1,13 @@
+
+  
+
+
+
+
+
+
+
+
+
+  
+
diff --git a/tests/qemumigparamsdata/tls-hostname.json 
b/tests/qemumigparamsdata/tls-hostname.json
new file mode 100644
index 00..abbd9f124b
--- /dev/null
+++ b/tests/qemumigparamsdata/tls-hostname.json
@@ -0,0 +1,11 @@
+{
+  "compress-level": 1,
+  "compress-threads": 8,
+  "decompress-threads": 2,
+  "cpu-throttle-initial": 20,
+  "cpu-throttle-increment": 10,
+  "tls-creds": "objlibvirt_migrate_tls0",
+  "tls-hostname": "f27-1.virt",
+  "max-bandwidth": 33554432,
+  "downtime-limit": 300
+}
diff --git a/tests/qemumigparamsdata/tls-hostname.reply 
b/tests/qemumigparamsdata/tls-hostname.reply
new file mode 100644
index 00..74f069f780
--- /dev/null
+++ b/tests/qemumigparamsdata/tls-hostname.reply
@@ -0,0 +1,14 @@
+{
+  "id": "libvirt-1",
+  "return": {
+"decompress-threads": 2,
+"cpu-throttle-increment": 10,
+"compress-threads": 8,
+"tls-hostname": "f27-1.virt",
+"compress-level": 1,
+"cpu-throttle-initial": 20,
+"tls-creds": "objlibvirt_migrate_tls0",
+"max-bandwidth": 33554432,
+"downtime-limit": 300
+  }
+}
diff --git a/tests/qemumigparamsdata/tls-hostname.xml 
b/tests/qemumigparamsdata/tls-hostname.xml
new file mode 100644
index 00..4310e789a0
--- /dev/null
+++ b/tests/qemumigparamsdata/tls-hostname.xml
@@ -0,0 +1,13 @@
+
+  
+
+
+
+
+
+
+
+
+
+  
+
diff --git a/tests/qemumigparamsdata/tls.json b/tests/qemumigparamsdata/tls.json
new file mode 100644
index 00..02e90c60ea
--- /dev/null
+++ b/tests/qemumigparamsdata/tls.json
@@ -0,0 +1,11 @@
+{
+  "compress-level": 1,
+  "compress-threads": 8,
+  "decompress-threads": 2,
+  "cpu-throttle-initial": 20,
+  "cpu-throttle-increment": 10,
+  "tls-creds": "",
+  "tls-hostname": "",
+  "max-bandwidth": 33554432,
+  "downtime-limit": 300
+}
diff --git a/tests/qemumigparamsdata/tls.reply 
b/tests/qemumigparamsdata/tls.reply
new file mode 100644
index 00..591eca6926
--- /dev/null
+++ b/tests/qemumigparamsdata/tls.reply
@@ -0,0 +1,14 @@
+{
+  "id": "libvirt-1",
+  "return": {
+"decompress-threads": 2,
+"cpu-throttle-increment": 10,
+"compress-threads": 8,
+"tls-hostname": "",
+"compress-level": 1,
+"cpu-throttle-initial": 20,
+"tls-creds": "",
+"max-bandwidth": 33554432,
+"downtime-limit": 300
+  }
+}
diff --git a/tests/qemumigparamsdata/tls.xml b/tests/qemumigparamsdata/tls.xml
new file 

[libvirt] [PATCH 50/68] util: Introduce virJSONValueObjectStealObject

2018-04-04 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 src/libvirt_private.syms | 1 +
 src/util/virjson.c   | 8 
 src/util/virjson.h   | 2 ++
 3 files changed, 11 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f6897915ce..9d98ee54df 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2093,6 +2093,7 @@ virJSONValueObjectIsNull;
 virJSONValueObjectKeysNumber;
 virJSONValueObjectRemoveKey;
 virJSONValueObjectStealArray;
+virJSONValueObjectStealObject;
 virJSONValueToString;
 
 
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 3ddefc34ca..dfe00d9280 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -1400,6 +1400,14 @@ virJSONValueObjectStealArray(virJSONValuePtr object, 
const char *key)
 }
 
 
+virJSONValuePtr
+virJSONValueObjectStealObject(virJSONValuePtr object,
+  const char *key)
+{
+return virJSONValueObjectStealByType(object, key, VIR_JSON_TYPE_OBJECT);
+}
+
+
 int
 virJSONValueObjectIsNull(virJSONValuePtr object,
  const char *key)
diff --git a/src/util/virjson.h b/src/util/virjson.h
index f7283dcf97..0f098892b4 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -112,6 +112,8 @@ virJSONValuePtr virJSONValueObjectGetArray(virJSONValuePtr 
object,
const char *key);
 virJSONValuePtr virJSONValueObjectStealArray(virJSONValuePtr object,
  const char *key);
+virJSONValuePtr virJSONValueObjectStealObject(virJSONValuePtr object,
+  const char *key);
 
 const char *virJSONValueObjectGetString(virJSONValuePtr object, const char 
*key);
 const char *virJSONValueObjectGetStringOrNumber(virJSONValuePtr object, const 
char *key);
-- 
2.17.0

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


[libvirt] [PATCH 57/68] qemu: Properly reset migration params when libvirtd restarts

2018-04-04 Thread Jiri Denemark
To be able to restore all migration parameters when libvirtd is
restarting during an active migration job, we need to store the original
values of all parameters (stored in priv->job.migParams) in the status
XML.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_domain.c   |   7 ++
 src/qemu/qemu_migration_params.c | 145 +++
 src/qemu/qemu_migration_params.h |  10 +++
 3 files changed, 162 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 55b88e35e0..cef08343ea 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -32,6 +32,7 @@
 #include "qemu_parse_command.h"
 #include "qemu_capabilities.h"
 #include "qemu_migration.h"
+#include "qemu_migration_params.h"
 #include "qemu_security.h"
 #include "viralloc.h"
 #include "virlog.h"
@@ -2099,6 +2100,9 @@ qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
 }
 }
 
+if (priv->job.migParams)
+qemuMigrationParamsFormat(, priv->job.migParams);
+
 return virXMLFormatElement(buf, "job", , );
 }
 
@@ -2398,6 +2402,9 @@ qemuDomainObjPrivateXMLParseJob(virDomainObjPtr vm,
 }
 VIR_FREE(nodes);
 
+if (qemuMigrationParamsParse(ctxt, >job.migParams) < 0)
+goto cleanup;
+
 ret = 0;
 
  cleanup:
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 6f3555bc63..dd2a91cac3 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -985,3 +985,148 @@ qemuMigrationParamsReset(virQEMUDriverPtr driver,
 virFreeError(err);
 }
 }
+
+
+void
+qemuMigrationParamsFormat(virBufferPtr buf,
+  qemuMigrationParamsPtr migParams)
+{
+qemuMigrationParamValuePtr pv;
+size_t i;
+
+virBufferAddLit(buf, "\n");
+virBufferAdjustIndent(buf, 2);
+
+for (i = 0; i < QEMU_MIGRATION_PARAM_LAST; i++) {
+pv = >params[i];
+
+if (!pv->set)
+continue;
+
+virBufferAsprintf(buf, "value.i);
+break;
+
+case QEMU_MIGRATION_PARAM_TYPE_ULL:
+virBufferAsprintf(buf, "value='%llu'", pv->value.ull);
+break;
+
+case QEMU_MIGRATION_PARAM_TYPE_BOOL:
+virBufferAsprintf(buf, "value='%s'", pv->value.b ? "yes" : "no");
+break;
+
+case QEMU_MIGRATION_PARAM_TYPE_STRING:
+virBufferEscapeString(buf, "value='%s'", pv->value.s);
+break;
+}
+
+virBufferAddLit(buf, "/>\n");
+}
+
+virBufferAdjustIndent(buf, -2);
+virBufferAddLit(buf, "\n");
+}
+
+
+int
+qemuMigrationParamsParse(xmlXPathContextPtr ctxt,
+ qemuMigrationParamsPtr *migParams)
+{
+qemuMigrationParamsPtr params = NULL;
+qemuMigrationParamValuePtr pv;
+xmlNodePtr *nodes = NULL;
+char *name = NULL;
+char *value = NULL;
+int param;
+size_t i;
+int rc;
+int n;
+int ret = -1;
+
+*migParams = NULL;
+
+if ((rc = virXPathBoolean("boolean(./migParams)", ctxt)) < 0)
+goto cleanup;
+
+if (rc == 0) {
+ret = 0;
+goto cleanup;
+}
+
+if ((n = virXPathNodeSet("./migParams[1]/param", ctxt, )) < 0)
+return -1;
+
+if (!(params = qemuMigrationParamsNew()))
+goto cleanup;
+
+for (i = 0; i < n; i++) {
+if (!(name = virXMLPropString(nodes[i], "name"))) {
+virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+   _("missing migration parameter name"));
+goto cleanup;
+}
+
+if ((param = qemuMigrationParamTypeFromString(name)) < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("unknown migration parameter '%s'"), name);
+goto cleanup;
+}
+pv = >params[param];
+
+if (!(value = virXMLPropString(nodes[i], "value"))) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("missing value for migration parameter '%s'"),
+   name);
+goto cleanup;
+}
+
+rc = 0;
+switch (qemuMigrationParamTypes[param]) {
+case QEMU_MIGRATION_PARAM_TYPE_INT:
+rc = virStrToLong_i(value, NULL, 10, >value.i);
+break;
+
+case QEMU_MIGRATION_PARAM_TYPE_ULL:
+rc = virStrToLong_ullp(value, NULL, 10, >value.ull);
+break;
+
+case QEMU_MIGRATION_PARAM_TYPE_BOOL:
+if (STREQ(value, "yes"))
+pv->value.b = true;
+else if (STREQ(value, "no"))
+pv->value.b = false;
+else
+rc = -1;
+break;
+
+case QEMU_MIGRATION_PARAM_TYPE_STRING:
+VIR_STEAL_PTR(pv->value.s, value);
+break;
+}
+
+if (rc < 0) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("invalid value '%s' for migration parameter 
'%s'"),
+   

[libvirt] [PATCH 58/68] qemu: Export qemuMigrationParams{To, From}JSON for tests

2018-04-04 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 src/qemu/Makefile.inc.am |  1 +
 src/qemu/qemu_migration_params.c |  5 +++--
 src/qemu/qemu_migration_paramspriv.h | 31 
 3 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 src/qemu/qemu_migration_paramspriv.h

diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am
index 25706ba4bc..63e7c878d1 100644
--- a/src/qemu/Makefile.inc.am
+++ b/src/qemu/Makefile.inc.am
@@ -35,6 +35,7 @@ QEMU_DRIVER_SOURCES = \
qemu/qemu_migration_cookie.h \
 qemu/qemu_migration_params.c \
 qemu/qemu_migration_params.h \
+qemu/qemu_migration_paramspriv.h \
qemu/qemu_monitor.c \
qemu/qemu_monitor.h \
qemu/qemu_monitor_text.c \
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index dd2a91cac3..6634fae4f6 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -30,6 +30,7 @@
 #include "qemu_hotplug.h"
 #include "qemu_migration.h"
 #include "qemu_migration_params.h"
+#include "qemu_migration_paramspriv.h"
 #include "qemu_monitor.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
@@ -508,7 +509,7 @@ qemuMigrationParamsDump(qemuMigrationParamsPtr migParams,
 }
 
 
-static qemuMigrationParamsPtr
+qemuMigrationParamsPtr
 qemuMigrationParamsFromJSON(virJSONValuePtr params)
 {
 qemuMigrationParamsPtr migParams;
@@ -561,7 +562,7 @@ qemuMigrationParamsFromJSON(virJSONValuePtr params)
 }
 
 
-static virJSONValuePtr
+virJSONValuePtr
 qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams)
 {
 virJSONValuePtr params = NULL;
diff --git a/src/qemu/qemu_migration_paramspriv.h 
b/src/qemu/qemu_migration_paramspriv.h
new file mode 100644
index 00..350973b6f9
--- /dev/null
+++ b/src/qemu/qemu_migration_paramspriv.h
@@ -0,0 +1,31 @@
+/*
+ * qemu_migration_paramspriv.h: private declarations for migration parameters
+ *
+ * Copyright (C) 2006-2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ *
+ */
+
+#ifndef __QEMU_MIGRATION_PARAMSPRIV_H__
+# define __QEMU_MIGRATION_PARAMSPRIV_H__
+
+virJSONValuePtr
+qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams);
+
+qemuMigrationParamsPtr
+qemuMigrationParamsFromJSON(virJSONValuePtr params);
+
+#endif /* __QEMU_MIGRATION_PARAMSPRIV_H__ */
-- 
2.17.0

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


[libvirt] [PATCH 62/68] qemu: Store API flags for async jobs in qemuDomainJobObj

2018-04-04 Thread Jiri Denemark
When an async job is running, we sometimes need to know how it was
started to distinguish between several types of the job, e.g., post-copy
vs. normal migration. So far we added a specific bool item to
qemuDomainJobObj for such cases, which doesn't scale very well and
storing such bools in status XML would be painful so we didn't do it.

A better approach is to store the flags passed to the API which started
the async job, which can be easily stored in status XML.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_domain.c| 10 --
 src/qemu/qemu_domain.h|  4 +++-
 src/qemu/qemu_driver.c| 31 +++
 src/qemu/qemu_migration.c | 20 +---
 src/qemu/qemu_process.c   |  5 +++--
 src/qemu/qemu_process.h   |  3 ++-
 6 files changed, 48 insertions(+), 25 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index cef08343ea..3f3a49f064 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -339,6 +339,7 @@ qemuDomainObjResetAsyncJob(qemuDomainObjPrivatePtr priv)
 VIR_FREE(job->current);
 qemuMigrationParamsFree(job->migParams);
 job->migParams = NULL;
+job->apiFlags = 0;
 }
 
 void
@@ -354,6 +355,7 @@ qemuDomainObjRestoreJob(virDomainObjPtr obj,
 job->asyncOwner = priv->job.asyncOwner;
 job->phase = priv->job.phase;
 VIR_STEAL_PTR(job->migParams, priv->job.migParams);
+job->apiFlags = priv->job.apiFlags;
 
 qemuDomainObjResetJob(priv);
 qemuDomainObjResetAsyncJob(priv);
@@ -5788,7 +5790,8 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
 asyncDuration = now - priv->job.asyncStarted;
 
 VIR_WARN("Cannot start job (%s, %s) for domain %s; "
- "current job is (%s, %s) owned by (%llu %s, %llu %s) "
+ "current job is (%s, %s) "
+ "owned by (%llu %s, %llu %s (flags=0x%lx)) "
  "for (%llus, %llus)",
  qemuDomainJobTypeToString(job),
  qemuDomainAsyncJobTypeToString(asyncJob),
@@ -5797,6 +5800,7 @@ qemuDomainObjBeginJobInternal(virQEMUDriverPtr driver,
  qemuDomainAsyncJobTypeToString(priv->job.asyncJob),
  priv->job.owner, NULLSTR(priv->job.ownerAPI),
  priv->job.asyncOwner, NULLSTR(priv->job.asyncOwnerAPI),
+ priv->job.apiFlags,
  duration / 1000, asyncDuration / 1000);
 
 if (nested || qemuDomainNestedJobAllowed(priv, job))
@@ -5860,7 +5864,8 @@ int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
 int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
virDomainObjPtr obj,
qemuDomainAsyncJob asyncJob,
-   virDomainJobOperation operation)
+   virDomainJobOperation operation,
+   unsigned long apiFlags)
 {
 qemuDomainObjPrivatePtr priv;
 
@@ -5870,6 +5875,7 @@ int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
 
 priv = obj->privateData;
 priv->job.current->operation = operation;
+priv->job.apiFlags = apiFlags;
 return 0;
 }
 
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 2bb3e0a788..2146ff00a9 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -182,6 +182,7 @@ struct _qemuDomainJobObj {
 bool dumpCompleted; /* dump completed */
 
 qemuMigrationParamsPtr migParams;
+unsigned long apiFlags; /* flags passed to the API which started the async 
job */
 };
 
 typedef void (*qemuDomainCleanupCallback)(virQEMUDriverPtr driver,
@@ -493,7 +494,8 @@ int qemuDomainObjBeginJob(virQEMUDriverPtr driver,
 int qemuDomainObjBeginAsyncJob(virQEMUDriverPtr driver,
virDomainObjPtr obj,
qemuDomainAsyncJob asyncJob,
-   virDomainJobOperation operation)
+   virDomainJobOperation operation,
+   unsigned long apiFlags)
 ATTRIBUTE_RETURN_CHECK;
 int qemuDomainObjBeginNestedJob(virQEMUDriverPtr driver,
 virDomainObjPtr obj,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 93dec7c2ce..e15eb49a5c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -267,7 +267,7 @@ qemuAutostartDomain(virDomainObjPtr vm,
 if (vm->autostart &&
 !virDomainObjIsActive(vm)) {
 if (qemuProcessBeginJob(driver, vm,
-VIR_DOMAIN_JOB_OPERATION_START) < 0) {
+VIR_DOMAIN_JOB_OPERATION_START, flags) < 0) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to start job on VM '%s': %s"),
vm->def->name, virGetLastErrorMessage());
@@ -1779,7 +1779,8 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr 
conn,
 virObjectRef(vm);
 def = NULL;
 
-if 

[libvirt] [PATCH 17/68] qemu: Drop qemuMigrationParamsCheckTLSCreds

2018-04-04 Thread Jiri Denemark
The function checks whether QEMU supports TLS migration and stores the
original value of tls-creds parameter to priv->migTLSAlias. This is no
longer needed because we already have the original value stored in
priv->migParams.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_domain.c   |  2 --
 src/qemu/qemu_domain.h   |  4 ---
 src/qemu/qemu_migration.c|  8 ++---
 src/qemu/qemu_migration_params.c | 62 ++--
 src/qemu/qemu_migration_params.h |  4 +--
 5 files changed, 6 insertions(+), 74 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 7528ec9dc8..55b88e35e0 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1905,8 +1905,6 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr 
priv)
 virDomainUSBAddressSetFree(priv->usbaddrs);
 priv->usbaddrs = NULL;
 
-/* clean up migration data */
-VIR_FREE(priv->migTLSAlias);
 virCPUDefFree(priv->origCPU);
 priv->origCPU = NULL;
 
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 2c474ae4a4..2bb3e0a788 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -330,10 +330,6 @@ struct _qemuDomainObjPrivate {
 /* private XML). */
 qemuDomainSecretInfoPtr migSecinfo;
 
-/* Used when fetching/storing the current 'tls-creds' migration setting */
-/* (not to be saved in our private XML). */
-char *migTLSAlias;
-
 /* CPU def used to start the domain when it differs from the one actually
  * provided by QEMU. */
 virCPUDefPtr origCPU;
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 072a5c95ae..8cd5426ed9 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2465,9 +2465,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 goto stopjob;
 
 } else {
-if (qemuMigrationParamsSetEmptyTLS(driver, vm,
-   QEMU_ASYNC_JOB_MIGRATION_IN,
-   migParams) < 0)
+if (qemuMigrationParamsSetEmptyTLS(vm, migParams) < 0)
 goto stopjob;
 }
 
@@ -3429,9 +3427,7 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 goto error;
 }
 } else {
-if (qemuMigrationParamsSetEmptyTLS(driver, vm,
-   QEMU_ASYNC_JOB_MIGRATION_OUT,
-   migParams) < 0)
+if (qemuMigrationParamsSetEmptyTLS(vm, migParams) < 0)
 goto error;
 }
 
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index bee7d9796f..fd4fc6c6a8 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -133,52 +133,6 @@ qemuMigrationParamsSet(virQEMUDriverPtr driver,
 }
 
 
-/* qemuMigrationParamsCheckTLSCreds
- * @driver: pointer to qemu driver
- * @vm: domain object
- * @asyncJob: migration job to join
- *
- * Query the migration parameters looking for the 'tls-creds' parameter.
- * If found, then we can support setting or clearing the parameters and thus
- * can support TLS for migration.
- *
- * Returns 0 if we were able to successfully fetch the params and
- * additionally if the tls-creds parameter exists, saves it in the
- * private domain structure. Returns -1 on failure.
- */
-static int
-qemuMigrationParamsCheckTLSCreds(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- int asyncJob)
-{
-int ret = -1;
-qemuDomainObjPrivatePtr priv = vm->privateData;
-qemuMigrationParamsPtr migParams = NULL;
-
-if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
-return -1;
-
-if (!(migParams = qemuMigrationParamsNew()))
-goto cleanup;
-
-if (qemuMonitorGetMigrationParams(priv->mon, >params) < 0)
-goto cleanup;
-
-/* NB: Could steal NULL pointer too! Let caller decide what to do. */
-VIR_STEAL_PTR(priv->migTLSAlias, migParams->params.tlsCreds);
-
-ret = 0;
-
- cleanup:
-if (qemuDomainObjExitMonitor(driver, vm) < 0)
-ret = -1;
-
-qemuMigrationParamsFree(migParams);
-
-return ret;
-}
-
-
 /* qemuMigrationParamsAddTLSObjects
  * @driver: pointer to qemu driver
  * @vm: domain object
@@ -213,10 +167,7 @@ qemuMigrationParamsAddTLSObjects(virQEMUDriverPtr driver,
 goto error;
 }
 
-if (qemuMigrationParamsCheckTLSCreds(driver, vm, asyncJob) < 0)
-goto error;
-
-if (!priv->migTLSAlias) {
+if ((!priv->job.migParams->params.tlsCreds)) {
 virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("TLS migration is not supported with this "
  "QEMU binary"));
@@ -260,9 +211,7 @@ qemuMigrationParamsAddTLSObjects(virQEMUDriverPtr driver,
 
 
 /* qemuMigrationParamsSetEmptyTLS
- * @driver: pointer to qemu driver
  * @vm: domain object
- * @asyncJob: migration job to join
  * 

[libvirt] [PATCH 40/68] qemu: Generalize macro for getting VIR_MIGRATE_* typed params

2018-04-04 Thread Jiri Denemark
So far it's used only for CPU throttling parameters which are all ints,
but we'll soon want to use it for more parameters with different types.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 9d2ac6bee5..2caf4dd1c9 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -112,6 +112,17 @@ qemuMigrationParamsFree(qemuMigrationParamsPtr migParams)
 }
 
 
+#define GET(API, PARAM, VAR) \
+do { \
+int rc; \
+if ((rc = API(params, nparams, VIR_MIGRATE_PARAM_ ## PARAM, \
+  >params.VAR)) < 0) \
+goto error; \
+ \
+if (rc == 1) \
+migParams->params.VAR ## _set = true; \
+} while (0)
+
 qemuMigrationParamsPtr
 qemuMigrationParamsFromFlags(virTypedParameterPtr params,
  int nparams,
@@ -132,27 +143,13 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
 }
 }
 
-#define GET(PARAM, VAR) \
-do { \
-int rc; \
-if ((rc = virTypedParamsGetInt(params, nparams, \
-   VIR_MIGRATE_PARAM_ ## PARAM, \
-   >params.VAR)) < 0) \
-goto error; \
- \
-if (rc == 1) \
-migParams->params.VAR ## _set = true; \
-} while (0)
-
 if (params) {
 if (party == QEMU_MIGRATION_SOURCE) {
-GET(AUTO_CONVERGE_INITIAL, cpuThrottleInitial);
-GET(AUTO_CONVERGE_INCREMENT, cpuThrottleIncrement);
+GET(virTypedParamsGetInt, AUTO_CONVERGE_INITIAL, 
cpuThrottleInitial);
+GET(virTypedParamsGetInt, AUTO_CONVERGE_INCREMENT, 
cpuThrottleIncrement);
 }
 }
 
-#undef GET
-
 if ((migParams->params.cpuThrottleInitial_set ||
  migParams->params.cpuThrottleIncrement_set) &&
 !(flags & VIR_MIGRATE_AUTO_CONVERGE)) {
@@ -168,6 +165,8 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
 return NULL;
 }
 
+#undef GET
+
 
 /**
  * qemuMigrationParamsApply
-- 
2.17.0

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


[libvirt] [PATCH 27/68] qemu: Drop unused qemuMonitorSetMigrationCapability

2018-04-04 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_monitor.c  | 14 --
 src/qemu/qemu_monitor.h  |  3 --
 src/qemu/qemu_monitor_json.c | 53 
 src/qemu/qemu_monitor_json.h |  3 --
 4 files changed, 73 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 7ea72af788..09f21ba77d 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3977,20 +3977,6 @@ qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
 }
 
 
-int
-qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
-  qemuMonitorMigrationCaps capability,
-  bool state)
-{
-VIR_DEBUG("capability=%s, state=%d",
-  qemuMonitorMigrationCapsTypeToString(capability), state);
-
-QEMU_CHECK_MONITOR_JSON(mon);
-
-return qemuMonitorJSONSetMigrationCapability(mon, capability, state);
-}
-
-
 int
 qemuMonitorSetMigrationCapabilities(qemuMonitorPtr mon,
 virBitmapPtr caps,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 870aae5cbd..c95b3a2ef4 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -760,9 +760,6 @@ VIR_ENUM_DECL(qemuMonitorMigrationCaps);
 
 int qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
 char ***capabilities);
-int qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
-  qemuMonitorMigrationCaps capability,
-  bool state);
 int qemuMonitorSetMigrationCapabilities(qemuMonitorPtr mon,
 virBitmapPtr caps,
 virBitmapPtr states);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 7ab73657a0..c6cb71addf 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6198,59 +6198,6 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr 
mon,
 }
 
 
-int
-qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon,
-  qemuMonitorMigrationCaps capability,
-  bool state)
-{
-int ret = -1;
-
-virJSONValuePtr cmd = NULL;
-virJSONValuePtr reply = NULL;
-virJSONValuePtr cap = NULL;
-virJSONValuePtr caps;
-
-if (!(caps = virJSONValueNewArray()))
-goto cleanup;
-
-if (!(cap = virJSONValueNewObject()))
-goto cleanup;
-
-if (virJSONValueObjectAppendString(
-cap, "capability",
-qemuMonitorMigrationCapsTypeToString(capability)) < 0)
-goto cleanup;
-
-if (virJSONValueObjectAppendBoolean(cap, "state", state) < 0)
-goto cleanup;
-
-if (virJSONValueArrayAppend(caps, cap) < 0)
-goto cleanup;
-
-cap = NULL;
-
-cmd = qemuMonitorJSONMakeCommand("migrate-set-capabilities",
- "a:capabilities", ,
- NULL);
-if (!cmd)
-goto cleanup;
-
-if (qemuMonitorJSONCommand(mon, cmd, ) < 0)
-goto cleanup;
-
-if (qemuMonitorJSONCheckError(cmd, reply) < 0)
-goto cleanup;
-
-ret = 0;
- cleanup:
-virJSONValueFree(caps);
-virJSONValueFree(cap);
-virJSONValueFree(cmd);
-virJSONValueFree(reply);
-return ret;
-}
-
-
 int
 qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
 virBitmapPtr caps,
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 76e6738f44..a73e98815c 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -145,9 +145,6 @@ int qemuMonitorJSONGetMigrationStats(qemuMonitorPtr mon,
 
 int qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon,
 char ***capabilities);
-int qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon,
-  qemuMonitorMigrationCaps capability,
-  bool state);
 int qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
 virBitmapPtr caps,
 virBitmapPtr states);
-- 
2.17.0

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


[libvirt] [PATCH 47/68] qemu: Introduce qemuMigrationParamsFetch

2018-04-04 Thread Jiri Denemark
Let's separate the code which queries QEMU for migration parameters from
qemuMigrationParamsCheck into a dedicated function.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 56 +++-
 src/qemu/qemu_migration_params.h |  6 
 2 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index f3cfb41952..642e4f314c 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -517,6 +517,39 @@ qemuMigrationParamsResetTLS(virQEMUDriverPtr driver,
 }
 
 
+int
+qemuMigrationParamsFetch(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ int asyncJob,
+ qemuMigrationParamsPtr *migParams)
+{
+qemuDomainObjPrivatePtr priv = vm->privateData;
+qemuMigrationParamsPtr params = NULL;
+int ret = -1;
+int rc;
+
+*migParams = NULL;
+
+if (!(params = qemuMigrationParamsNew()))
+return -1;
+
+if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
+goto cleanup;
+
+rc = qemuMonitorGetMigrationParams(priv->mon, >params);
+
+if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
+goto cleanup;
+
+VIR_STEAL_PTR(*migParams, params);
+ret = 0;
+
+ cleanup:
+qemuMigrationParamsFree(params);
+return ret;
+}
+
+
 /**
  * qemuMigrationParamsCheck:
  *
@@ -532,11 +565,9 @@ qemuMigrationParamsCheck(virQEMUDriverPtr driver,
  qemuMigrationParamsPtr migParams)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
-qemuMigrationParamsPtr origParams = NULL;
 qemuMonitorMigrationCaps cap;
 qemuMigrationParty party;
 size_t i;
-int ret = -1;
 
 if (asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT)
 party = QEMU_MIGRATION_SOURCE;
@@ -564,31 +595,12 @@ qemuMigrationParamsCheck(virQEMUDriverPtr driver,
 }
 }
 
-if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
-return -1;
-
-if (!(origParams = qemuMigrationParamsNew()))
-goto cleanup;
-
 /*
  * We want to disable all migration capabilities after migration, no need
  * to ask QEMU for their current settings.
  */
 
-if (qemuMonitorGetMigrationParams(priv->mon, >params) < 0)
-goto cleanup;
-
-ret = 0;
-
- cleanup:
-if (qemuDomainObjExitMonitor(driver, vm) < 0)
-ret = -1;
-
-if (ret == 0)
-VIR_STEAL_PTR(priv->job.migParams, origParams);
-qemuMigrationParamsFree(origParams);
-
-return ret;
+return qemuMigrationParamsFetch(driver, vm, asyncJob, 
>job.migParams);
 }
 
 
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 91863e0991..cabf4cebe6 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -73,6 +73,12 @@ int
 qemuMigrationParamsDisableTLS(virDomainObjPtr vm,
   qemuMigrationParamsPtr migParams);
 
+int
+qemuMigrationParamsFetch(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ int asyncJob,
+ qemuMigrationParamsPtr *migParams);
+
 int
 qemuMigrationParamsCheck(virQEMUDriverPtr driver,
  virDomainObjPtr vm,
-- 
2.17.0

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


[libvirt] [PATCH 28/68] qemu: Add support for xbzrle-cache-size migration parameter

2018-04-04 Thread Jiri Denemark
Originally QEMU provided query-migrate-cache-size and
migrate-set-cache-size QMP commands for querying/setting XBZRLE cache
size. In version 2.11 QEMU added support for XBZRLE cache size to the
general migration paramaters commands.

This patch adds support for this parameter to libvirt to make sure it is
properly restored to its original value after a failed or aborted
migration.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_monitor.c  | 5 +++--
 src/qemu/qemu_monitor.h  | 3 +++
 src/qemu/qemu_monitor_json.c | 2 ++
 tests/qemumonitorjsontest.c  | 4 +++-
 4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 09f21ba77d..18b54e2da8 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2639,7 +2639,7 @@ qemuMonitorSetMigrationParams(qemuMonitorPtr mon,
   "decompressThreads=%d:%d cpuThrottleInitial=%d:%d "
   "cpuThrottleIncrement=%d:%d tlsCreds=%s tlsHostname=%s "
   "maxBandwidth=%d:%llu downtimeLimit=%d:%llu "
-  "blockIncremental=%d:%d",
+  "blockIncremental=%d:%d xbzrleCacheSize=%d:%llu",
   params->compressLevel_set, params->compressLevel,
   params->compressThreads_set, params->compressThreads,
   params->decompressThreads_set, params->decompressThreads,
@@ -2648,7 +2648,8 @@ qemuMonitorSetMigrationParams(qemuMonitorPtr mon,
   NULLSTR(params->tlsCreds), NULLSTR(params->tlsHostname),
   params->maxBandwidth_set, params->maxBandwidth,
   params->downtimeLimit_set, params->downtimeLimit,
-  params->blockIncremental_set, params->blockIncremental);
+  params->blockIncremental_set, params->blockIncremental,
+  params->xbzrleCacheSize_set, params->xbzrleCacheSize);
 
 QEMU_CHECK_MONITOR_JSON(mon);
 
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index c95b3a2ef4..2bb4dbc667 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -673,6 +673,9 @@ struct _qemuMonitorMigrationParams {
 
 bool blockIncremental_set;
 bool blockIncremental;
+
+bool xbzrleCacheSize_set;
+unsigned long long xbzrleCacheSize;
 };
 
 int qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index c6cb71addf..acc126629e 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2833,6 +2833,7 @@ qemuMonitorJSONGetMigrationParams(qemuMonitorPtr mon,
 PARSE_ULONG(maxBandwidth, "max-bandwidth");
 PARSE_ULONG(downtimeLimit, "downtime-limit");
 PARSE_BOOL(blockIncremental, "block-incremental");
+PARSE_ULONG(xbzrleCacheSize, "xbzrle-cache-size");
 
 #undef PARSE_SET
 #undef PARSE_INT
@@ -2898,6 +2899,7 @@ qemuMonitorJSONSetMigrationParams(qemuMonitorPtr mon,
 APPEND_ULONG(maxBandwidth, "max-bandwidth");
 APPEND_ULONG(downtimeLimit, "downtime-limit");
 APPEND_BOOL(blockIncremental, "block-incremental");
+APPEND_ULONG(xbzrleCacheSize, "xbzrle-cache-size");
 
 #undef APPEND
 #undef APPEND_INT
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 1cad383596..8a5b0be64b 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1810,7 +1810,8 @@ 
testQemuMonitorJSONqemuMonitorJSONGetMigrationParams(const void *data)
"\"tls-hostname\": \"\","
"\"max-bandwidth\": 1234567890,"
"\"downtime-limit\": 500,"
-   "\"block-incremental\": true"
+   "\"block-incremental\": true,"
+   "\"xbzrle-cache-size\": 67108864"
"}"
"}") < 0) {
 goto cleanup;
@@ -1867,6 +1868,7 @@ 
testQemuMonitorJSONqemuMonitorJSONGetMigrationParams(const void *data)
 CHECK_ULONG(maxBandwidth, "max-bandwidth", 1234567890ULL);
 CHECK_ULONG(downtimeLimit, "downtime-limit", 500ULL);
 CHECK_BOOL(blockIncremental, "block-incremental", true);
+CHECK_ULONG(xbzrleCacheSize, "xbzrle-cache-size", 67108864ULL);
 
 #undef CHECK_NUM
 #undef CHECK_INT
-- 
2.17.0

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


[libvirt] [PATCH 34/68] qemu: Use qemuMigrationParamsFromFlags everywhere

2018-04-04 Thread Jiri Denemark
Every migration entry point in qemu_driver is supposed to call
qemuMigrationParamsFromFlags to transform flags and parameters into
qemuMigrationParams structure and pass the result to qemuMigration*
APIs.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c| 64 +++
 src/qemu/qemu_migration.c | 23 ++
 src/qemu/qemu_migration.h |  2 ++
 3 files changed, 62 insertions(+), 27 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d8a641f77d..5271e01d92 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12126,6 +12126,7 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 virQEMUDriverPtr driver = dconn->privateData;
 virDomainDefPtr def = NULL;
 char *origname = NULL;
+qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
 virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -12136,6 +12137,10 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 goto cleanup;
 }
 
+if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
+   
QEMU_MIGRATION_DESTINATION)))
+goto cleanup;
+
 if (virLockManagerPluginUsesState(driver->lockManager)) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("Cannot use migrate v2 protocol with lock manager 
%s"),
@@ -12151,9 +12156,10 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 
 ret = qemuMigrationDstPrepareTunnel(driver, dconn,
 NULL, 0, NULL, NULL, /* No cookies in 
v2 */
-st, , origname, flags);
+st, , origname, migParams, flags);
 
  cleanup:
+qemuMigrationParamsFree(migParams);
 VIR_FREE(origname);
 virDomainDefFree(def);
 return ret;
@@ -12178,6 +12184,7 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
 virDomainDefPtr def = NULL;
 char *origname = NULL;
 qemuMigrationCompressionPtr compression = NULL;
+qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
 virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -12195,6 +12202,10 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
 if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
 goto cleanup;
 
+if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
+   
QEMU_MIGRATION_DESTINATION)))
+goto cleanup;
+
 if (virLockManagerPluginUsesState(driver->lockManager)) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_("Cannot use migrate v2 protocol with lock manager 
%s"),
@@ -12216,9 +12227,10 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
 NULL, 0, NULL, NULL, /* No cookies */
 uri_in, uri_out,
 , origname, NULL, 0, NULL, 0,
-compression, flags);
+compression, migParams, flags);
 
  cleanup:
+qemuMigrationParamsFree(migParams);
 VIR_FREE(compression);
 VIR_FREE(origname);
 virDomainDefFree(def);
@@ -12252,10 +12264,11 @@ qemuDomainMigratePerform(virDomainPtr dom,
 goto cleanup;
 }
 
-if (!(migParams = qemuMigrationParamsNew()))
+if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
 goto cleanup;
 
-if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
+if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
+   QEMU_MIGRATION_SOURCE)))
 goto cleanup;
 
 if (!(vm = qemuDomObjFromDomain(dom)))
@@ -12430,6 +12443,7 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
 virDomainDefPtr def = NULL;
 char *origname = NULL;
 qemuMigrationCompressionPtr compression = NULL;
+qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
 virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -12447,6 +12461,10 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
 if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
 goto cleanup;
 
+if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
+   
QEMU_MIGRATION_DESTINATION)))
+goto cleanup;
+
 if (!(def = qemuMigrationAnyPrepareDef(driver, dom_xml, dname, )))
 goto cleanup;
 
@@ -12458,9 +12476,10 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
 cookieout, cookieoutlen,
 uri_in, uri_out,
 , origname, NULL, 0, NULL, 0,
-compression, flags);
+compression, migParams, flags);
 
  cleanup:
+

[libvirt] [PATCH 21/68] qemu: Hide cfg inside qemuMigrationParamsEnableTLS

2018-04-04 Thread Jiri Denemark
There's no real reason for qemuMigrationParamsEnableTLS to require the
callers to pass a valid virQEMUDriverConfigPtr, it can just call
virQEMUDriverGetConfig.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c| 10 ++
 src/qemu/qemu_migration_params.c | 12 
 src/qemu/qemu_migration_params.h |  1 -
 3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index fe2fae8fba..d07a12cdec 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2231,7 +2231,6 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 {
 virDomainObjPtr vm = NULL;
 virObjectEventPtr event = NULL;
-virQEMUDriverConfigPtr cfg = NULL;
 int ret = -1;
 int dataFD[2] = { -1, -1 };
 qemuDomainObjPrivatePtr priv = NULL;
@@ -2454,8 +2453,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 /* Migrations using TLS need to add the "tls-creds-x509" object and
  * set the migration TLS parameters */
 if (flags & VIR_MIGRATE_TLS) {
-cfg = virQEMUDriverGetConfig(driver);
-if (qemuMigrationParamsEnableTLS(driver, vm, cfg, true,
+if (qemuMigrationParamsEnableTLS(driver, vm, true,
  QEMU_ASYNC_JOB_MIGRATION_IN,
  , , NULL,
  migParams) < 0)
@@ -2552,7 +2550,6 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
  cleanup:
 VIR_FREE(tlsAlias);
 VIR_FREE(secAlias);
-virObjectUnref(cfg);
 qemuProcessIncomingDefFree(incoming);
 VIR_FREE(xmlout);
 VIR_FORCE_CLOSE(dataFD[0]);
@@ -,7 +3330,6 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 {
 int ret = -1;
 unsigned int migrate_flags = QEMU_MONITOR_MIGRATE_BACKGROUND;
-virQEMUDriverConfigPtr cfg = NULL;
 qemuDomainObjPrivatePtr priv = vm->privateData;
 qemuMigrationCookiePtr mig = NULL;
 char *tlsAlias = NULL;
@@ -3413,8 +3409,7 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 spec->destType == MIGRATION_DEST_FD)
 hostname = spec->dest.host.name;
 
-cfg = virQEMUDriverGetConfig(driver);
-if (qemuMigrationParamsEnableTLS(driver, vm, cfg, false,
+if (qemuMigrationParamsEnableTLS(driver, vm, false,
  QEMU_ASYNC_JOB_MIGRATION_OUT,
  , , hostname,
  migParams) < 0)
@@ -3652,7 +3647,6 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
  cleanup:
 VIR_FREE(tlsAlias);
 VIR_FREE(secAlias);
-virObjectUnref(cfg);
 VIR_FORCE_CLOSE(fd);
 virDomainDefFree(persistDef);
 qemuMigrationCookieFree(mig);
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 812c35e13e..7b5a7c108f 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -136,7 +136,6 @@ qemuMigrationParamsSet(virQEMUDriverPtr driver,
 /* qemuMigrationParamsEnableTLS
  * @driver: pointer to qemu driver
  * @vm: domain object
- * @cfg: configuration pointer
  * @tlsListen: server or client
  * @asyncJob: Migration job to join
  * @tlsAlias: alias to be generated for TLS object
@@ -153,7 +152,6 @@ qemuMigrationParamsSet(virQEMUDriverPtr driver,
 int
 qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
  virDomainObjPtr vm,
- virQEMUDriverConfigPtr cfg,
  bool tlsListen,
  int asyncJob,
  char **tlsAlias,
@@ -164,6 +162,8 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
 qemuDomainObjPrivatePtr priv = vm->privateData;
 virJSONValuePtr tlsProps = NULL;
 virJSONValuePtr secProps = NULL;
+virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+int ret = -1;
 
 if (!cfg->migrateTLSx509certdir) {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -206,12 +206,16 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
 VIR_STRDUP(migParams->params.tlsHostname, hostname ? hostname : "") < 
0)
 goto error;
 
-return 0;
+ret = 0;
+
+ cleanup:
+virObjectUnref(cfg);
+return ret;
 
  error:
 virJSONValueFree(tlsProps);
 virJSONValueFree(secProps);
-return -1;
+goto cleanup;
 }
 
 
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 2955bf7436..45834e5b48 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -74,7 +74,6 @@ qemuMigrationParamsSet(virQEMUDriverPtr driver,
 int
 qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
  virDomainObjPtr vm,
- virQEMUDriverConfigPtr cfg,
  bool tlsListen,
  int asyncJob,
  

[libvirt] [PATCH 39/68] qemu: Call qemuMigrationAnyCompressionParse only from driver

2018-04-04 Thread Jiri Denemark
Propagate the calls up the stack to the point where
qemuMigrationParamsFromFlags is called. The end goal achieved in the
following few patches is to merge compression parameters into the
general migration parameters code.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c| 21 ++---
 src/qemu/qemu_migration.c | 25 +++--
 src/qemu/qemu_migration.h |  1 +
 3 files changed, 26 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5271e01d92..85755257aa 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12126,6 +12126,7 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 virQEMUDriverPtr driver = dconn->privateData;
 virDomainDefPtr def = NULL;
 char *origname = NULL;
+qemuMigrationCompressionPtr compression = NULL;
 qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
@@ -12137,6 +12138,9 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 goto cleanup;
 }
 
+if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
+goto cleanup;
+
 if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,

QEMU_MIGRATION_DESTINATION)))
 goto cleanup;
@@ -12156,9 +12160,10 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 
 ret = qemuMigrationDstPrepareTunnel(driver, dconn,
 NULL, 0, NULL, NULL, /* No cookies in 
v2 */
-st, , origname, migParams, flags);
+st, , origname, compression, 
migParams, flags);
 
  cleanup:
+VIR_FREE(compression);
 qemuMigrationParamsFree(migParams);
 VIR_FREE(origname);
 virDomainDefFree(def);
@@ -12597,6 +12602,7 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
 virQEMUDriverPtr driver = dconn->privateData;
 virDomainDefPtr def = NULL;
 char *origname = NULL;
+qemuMigrationCompressionPtr compression = NULL;
 qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
@@ -12608,6 +12614,9 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
 goto cleanup;
 }
 
+if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
+goto cleanup;
+
 if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,

QEMU_MIGRATION_DESTINATION)))
 goto cleanup;
@@ -12621,9 +12630,10 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
 ret = qemuMigrationDstPrepareTunnel(driver, dconn,
 cookiein, cookieinlen,
 cookieout, cookieoutlen,
-st, , origname, migParams, flags);
+st, , origname, compression, 
migParams, flags);
 
  cleanup:
+VIR_FREE(compression);
 qemuMigrationParamsFree(migParams);
 VIR_FREE(origname);
 virDomainDefFree(def);
@@ -12646,6 +12656,7 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr 
dconn,
 const char *dom_xml = NULL;
 const char *dname = NULL;
 char *origname = NULL;
+qemuMigrationCompressionPtr compression = NULL;
 qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
@@ -12667,6 +12678,9 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr 
dconn,
 goto cleanup;
 }
 
+if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
+goto cleanup;
+
 if (!(migParams = qemuMigrationParamsFromFlags(params, nparams, flags,

QEMU_MIGRATION_DESTINATION)))
 goto cleanup;
@@ -12680,9 +12694,10 @@ qemuDomainMigratePrepareTunnel3Params(virConnectPtr 
dconn,
 ret = qemuMigrationDstPrepareTunnel(driver, dconn,
 cookiein, cookieinlen,
 cookieout, cookieoutlen,
-st, , origname, migParams, flags);
+st, , origname, compression, 
migParams, flags);
 
  cleanup:
+VIR_FREE(compression);
 qemuMigrationParamsFree(migParams);
 VIR_FREE(origname);
 virDomainDefFree(def);
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 1c614f8c0d..fa220d6ce4 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2534,12 +2534,10 @@ qemuMigrationDstPrepareTunnel(virQEMUDriverPtr driver,
   virStreamPtr st,
   virDomainDefPtr *def,
   const char *origname,
+  qemuMigrationCompressionPtr compression,
   qemuMigrationParamsPtr migParams,
   unsigned long flags)
 {
-qemuMigrationCompressionPtr 

[libvirt] [PATCH 42/68] qemu: Move qemuMigrationParamsSetCompression

2018-04-04 Thread Jiri Denemark
The API will soon be called from qemuMigrationParamsFromFlags. Let's
move it to avoid the need to add a forward declaration.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 59 
 1 file changed, 30 insertions(+), 29 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index b70229a156..dfa534bfd9 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -123,6 +123,36 @@ qemuMigrationParamsFree(qemuMigrationParamsPtr migParams)
 migParams->params.VAR ## _set = true; \
 } while (0)
 
+
+int
+qemuMigrationParamsSetCompression(virDomainObjPtr vm ATTRIBUTE_UNUSED,
+  qemuMigrationCompressionPtr compression,
+  qemuMigrationParamsPtr migParams)
+{
+if (compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE))
+ignore_value(virBitmapSetBit(migParams->caps,
+ QEMU_MONITOR_MIGRATION_CAPS_XBZRLE));
+
+if (compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_MT))
+ignore_value(virBitmapSetBit(migParams->caps,
+ QEMU_MONITOR_MIGRATION_CAPS_COMPRESS));
+
+migParams->params.compressLevel_set = compression->level_set;
+migParams->params.compressLevel = compression->level;
+
+migParams->params.compressThreads_set = compression->threads_set;
+migParams->params.compressThreads = compression->threads;
+
+migParams->params.decompressThreads_set = compression->dthreads_set;
+migParams->params.decompressThreads = compression->dthreads;
+
+migParams->params.xbzrleCacheSize_set = compression->xbzrle_cache_set;
+migParams->params.xbzrleCacheSize = compression->xbzrle_cache;
+
+return 0;
+}
+
+
 qemuMigrationParamsPtr
 qemuMigrationParamsFromFlags(virTypedParameterPtr params,
  int nparams,
@@ -339,35 +369,6 @@ qemuMigrationParamsDisableTLS(virDomainObjPtr vm,
 }
 
 
-int
-qemuMigrationParamsSetCompression(virDomainObjPtr vm ATTRIBUTE_UNUSED,
-  qemuMigrationCompressionPtr compression,
-  qemuMigrationParamsPtr migParams)
-{
-if (compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE))
-ignore_value(virBitmapSetBit(migParams->caps,
- QEMU_MONITOR_MIGRATION_CAPS_XBZRLE));
-
-if (compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_MT))
-ignore_value(virBitmapSetBit(migParams->caps,
- QEMU_MONITOR_MIGRATION_CAPS_COMPRESS));
-
-migParams->params.compressLevel_set = compression->level_set;
-migParams->params.compressLevel = compression->level;
-
-migParams->params.compressThreads_set = compression->threads_set;
-migParams->params.compressThreads = compression->threads;
-
-migParams->params.decompressThreads_set = compression->dthreads_set;
-migParams->params.decompressThreads = compression->dthreads;
-
-migParams->params.xbzrleCacheSize_set = compression->xbzrle_cache_set;
-migParams->params.xbzrleCacheSize = compression->xbzrle_cache;
-
-return 0;
-}
-
-
 /* qemuMigrationParamsResetTLS
  * @driver: pointer to qemu driver
  * @vm: domain object
-- 
2.17.0

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


Re: [libvirt] [dbus PATCH v2 1/5] Introduce Network Interface

2018-04-04 Thread Pavel Hrdina
On Wed, Apr 04, 2018 at 02:26:09PM +0200, Katerina Koukiou wrote:
> Signed-off-by: Katerina Koukiou 
> ---
>  data/Makefile.am |  3 ++-
>  data/org.libvirt.Network.xml |  7 +
>  src/Makefile.am  |  3 ++-
>  src/connect.c|  5 
>  src/connect.h|  1 +
>  src/network.c| 64 
> 
>  src/network.h|  9 +++
>  src/util.c   | 20 ++
>  src/util.h   | 10 +++
>  9 files changed, 120 insertions(+), 2 deletions(-)
>  create mode 100644 data/org.libvirt.Network.xml
>  create mode 100644 src/network.c
>  create mode 100644 src/network.h
> 
> diff --git a/data/Makefile.am b/data/Makefile.am
> index dd60713..61702df 100644
> --- a/data/Makefile.am
> +++ b/data/Makefile.am
> @@ -20,7 +20,8 @@ polkit_DATA = $(polkit_files:.rules.in=.rules)
>  
>  interfaces_files = \
>   org.libvirt.Connect.xml \
> - org.libvirt.Domain.xml
> + org.libvirt.Domain.xml \
> + org.libvirt.Network.xml
>  interfacesdir = $(DBUS_INTERFACES_DIR)
>  interfaces_DATA = $(interfaces_files)
>  
> diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml
> new file mode 100644
> index 000..2b7c4f7
> --- /dev/null
> +++ b/data/org.libvirt.Network.xml
> @@ -0,0 +1,7 @@
> + 1.0//EN"
> +"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd;>
> +
> +
> +  
> +  
> +
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 7248561..158398a 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -8,7 +8,8 @@ DAEMON_SOURCES = \
>   util.c util.h \
>   domain.c domain.h \
>   events.c events.h \
> - gdbus.c gdbus.h
> + gdbus.c gdbus.h \
> + network.c network.h
>  
>  EXTRA_DIST = \
>   $(DAEMON_SOURCES)
> diff --git a/src/connect.c b/src/connect.c
> index 2350736..7b3f834 100644
> --- a/src/connect.c
> +++ b/src/connect.c
> @@ -1,6 +1,7 @@
>  #include "connect.h"
>  #include "domain.h"
>  #include "events.h"
> +#include "network.h"
>  #include "util.h"
>  
>  #include 
> @@ -345,6 +346,10 @@ virtDBusConnectNew(virtDBusConnect **connectp,
>  if (error && *error)
>  return;
>  
> +virtDBusNetworkRegister(connect, error);
> +if (error && *error)
> +return;
> +
>  *connectp = connect;
>  connect = NULL;
>  }
> diff --git a/src/connect.h b/src/connect.h
> index 9572857..7ed84b8 100644
> --- a/src/connect.h
> +++ b/src/connect.h
> @@ -13,6 +13,7 @@ struct virtDBusConnect {
>  const gchar *uri;
>  const gchar *connectPath;
>  gchar *domainPath;
> +gchar *networkPath;
>  virConnectPtr connection;
>  GMutex lock;
>  
> diff --git a/src/network.c b/src/network.c
> new file mode 100644
> index 000..0d0e992
> --- /dev/null
> +++ b/src/network.c
> @@ -0,0 +1,64 @@
> +#include "network.h"
> +#include "util.h"
> +
> +#include 
> +
> +static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = {
> +{ 0 }
> +};
> +
> +static virtDBusGDBusMethodTable virtDBusNetworkMethodTable[] = {
> +{ 0 }
> +};
> +
> +static gchar **
> +virtDBusNetworkEnumerate(gpointer userData)
> +{
> +virtDBusConnect *connect = userData;
> +g_autoptr(virNetworkPtr) networks = NULL;
> +gint num = 0;
> +gchar **ret = NULL;
> +
> +if (!virtDBusConnectOpen(connect, NULL))
> +return NULL;
> +
> +num = virConnectListAllNetworks(connect->connection, , 0);
> +if (num < 0)
> +return NULL;
> +
> +if (num == 0)
> +return NULL;
> +
> +ret = g_new0(gchar *, num + 1);
> +
> +for (gint i = 0; i < num; i++) {
> +ret[i] = virtDBusUtilBusPathForVirNetwork(networks[i],
> +  connect->networkPath);
> +}
> +
> +return ret;
> +}
> +
> +static GDBusInterfaceInfo *interfaceInfo = NULL;
> +
> +void
> +virtDBusNetworkRegister(virtDBusConnect *connect,
> +   GError **error)

Indentation is off here.

With the virtDBusConnectFree addition

Reviewed-by: Pavel Hrdina 


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

[libvirt] [PATCH 19/68] qemu: Rename qemuMigrationParamsAddTLSObjects

2018-04-04 Thread Jiri Denemark
The new name is qemuMigrationParamsEnableTLS.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c| 12 ++--
 src/qemu/qemu_migration_params.c | 18 +-
 src/qemu/qemu_migration_params.h | 16 
 3 files changed, 23 insertions(+), 23 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index f007f7e05a..254239b18b 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2455,9 +2455,9 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
  * set the migration TLS parameters */
 if (flags & VIR_MIGRATE_TLS) {
 cfg = virQEMUDriverGetConfig(driver);
-if (qemuMigrationParamsAddTLSObjects(driver, vm, cfg, true,
- QEMU_ASYNC_JOB_MIGRATION_IN,
- , , migParams) 
< 0)
+if (qemuMigrationParamsEnableTLS(driver, vm, cfg, true,
+ QEMU_ASYNC_JOB_MIGRATION_IN,
+ , , migParams) < 0)
 goto stopjob;
 
 /* Force reset of 'tls-hostname', it's a source only parameter */
@@ -3410,9 +3410,9 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 
 if (flags & VIR_MIGRATE_TLS) {
 cfg = virQEMUDriverGetConfig(driver);
-if (qemuMigrationParamsAddTLSObjects(driver, vm, cfg, false,
- QEMU_ASYNC_JOB_MIGRATION_OUT,
- , , migParams) 
< 0)
+if (qemuMigrationParamsEnableTLS(driver, vm, cfg, false,
+ QEMU_ASYNC_JOB_MIGRATION_OUT,
+ , , migParams) < 0)
 goto error;
 
 /* We need to add tls-hostname whenever QEMU itself does not
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 26f3f29d16..a03239e2a2 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -133,7 +133,7 @@ qemuMigrationParamsSet(virQEMUDriverPtr driver,
 }
 
 
-/* qemuMigrationParamsAddTLSObjects
+/* qemuMigrationParamsEnableTLS
  * @driver: pointer to qemu driver
  * @vm: domain object
  * @cfg: configuration pointer
@@ -148,14 +148,14 @@ qemuMigrationParamsSet(virQEMUDriverPtr driver,
  * Returns 0 on success, -1 on failure
  */
 int
-qemuMigrationParamsAddTLSObjects(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virQEMUDriverConfigPtr cfg,
- bool tlsListen,
- int asyncJob,
- char **tlsAlias,
- char **secAlias,
- qemuMigrationParamsPtr migParams)
+qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virQEMUDriverConfigPtr cfg,
+ bool tlsListen,
+ int asyncJob,
+ char **tlsAlias,
+ char **secAlias,
+ qemuMigrationParamsPtr migParams)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
 virJSONValuePtr tlsProps = NULL;
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 281c2ae687..8aa6136508 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -72,14 +72,14 @@ qemuMigrationParamsSet(virQEMUDriverPtr driver,
qemuMigrationParamsPtr migParams);
 
 int
-qemuMigrationParamsAddTLSObjects(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- virQEMUDriverConfigPtr cfg,
- bool tlsListen,
- int asyncJob,
- char **tlsAlias,
- char **secAlias,
- qemuMigrationParamsPtr migParams);
+qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virQEMUDriverConfigPtr cfg,
+ bool tlsListen,
+ int asyncJob,
+ char **tlsAlias,
+ char **secAlias,
+ qemuMigrationParamsPtr migParams);
 
 int
 qemuMigrationParamsDisableTLS(virDomainObjPtr vm,
-- 
2.17.0

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


[libvirt] [PATCH 07/68] qemu: Allocate struct for migration parameters

2018-04-04 Thread Jiri Denemark
It will get a bit more complicated soon and storing it on a stack with
{0} initializer will no longer work. We need a proper constructor.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c   | 20 +++--
 src/qemu/qemu_migration.c| 28 ++-
 src/qemu/qemu_migration_params.c | 38 +++-
 src/qemu/qemu_migration_params.h |  3 +++
 4 files changed, 61 insertions(+), 28 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index bf6c0d0826..c157ff9bb0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12241,7 +12241,7 @@ qemuDomainMigratePerform(virDomainPtr dom,
 int ret = -1;
 const char *dconnuri = NULL;
 qemuMigrationCompressionPtr compression = NULL;
-qemuMonitorMigrationParams migParams = { 0 };
+qemuMonitorMigrationParamsPtr migParams = NULL;
 
 virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
 
@@ -12252,6 +12252,9 @@ qemuDomainMigratePerform(virDomainPtr dom,
 goto cleanup;
 }
 
+if (!(migParams = qemuMigrationParamsNew()))
+goto cleanup;
+
 if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
 goto cleanup;
 
@@ -12276,12 +12279,12 @@ qemuDomainMigratePerform(virDomainPtr dom,
  */
 ret = qemuMigrationSrcPerform(driver, dom->conn, vm, NULL,
   NULL, dconnuri, uri, NULL, NULL, 0, NULL, 0,
-  compression, , cookie, cookielen,
+  compression, migParams, cookie, cookielen,
   NULL, NULL, /* No output cookies in v2 */
   flags, dname, resource, false);
 
  cleanup:
-qemuMigrationParamsClear();
+qemuMigrationParamsFree(migParams);
 VIR_FREE(compression);
 return ret;
 }
@@ -12666,13 +12669,16 @@ qemuDomainMigratePerform3(virDomainPtr dom,
 virQEMUDriverPtr driver = dom->conn->privateData;
 virDomainObjPtr vm;
 qemuMigrationCompressionPtr compression = NULL;
-qemuMonitorMigrationParams migParams = { 0 };
+qemuMonitorMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
 virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
 
+if (!(migParams = qemuMigrationParamsNew()))
+goto cleanup;
+
 if (!(compression = qemuMigrationAnyCompressionParse(NULL, 0, flags)))
-return -1;
+goto cleanup;
 
 if (!(vm = qemuDomObjFromDomain(dom)))
 goto cleanup;
@@ -12684,13 +12690,13 @@ qemuDomainMigratePerform3(virDomainPtr dom,
 
 ret = qemuMigrationSrcPerform(driver, dom->conn, vm, xmlin, NULL,
   dconnuri, uri, NULL, NULL, 0, NULL, 0,
-  compression, ,
+  compression, migParams,
   cookiein, cookieinlen,
   cookieout, cookieoutlen,
   flags, dname, resource, true);
 
  cleanup:
-qemuMigrationParamsClear();
+qemuMigrationParamsFree(migParams);
 VIR_FREE(compression);
 return ret;
 }
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 4bdaa67ea1..ffdf0ba2e5 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2254,7 +2254,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 int rv;
 char *tlsAlias = NULL;
 char *secAlias = NULL;
-qemuMonitorMigrationParams migParams = { 0 };
+qemuMonitorMigrationParamsPtr migParams = NULL;
 
 virNWFilterReadLockFilterUpdates();
 
@@ -2304,6 +2304,9 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 if (!qemuMigrationSrcIsAllowedHostdev(*def))
 goto cleanup;
 
+if (!(migParams = qemuMigrationParamsNew()))
+goto cleanup;
+
 /* Let migration hook filter domain XML */
 if (virHookPresent(VIR_HOOK_DRIVER_QEMU)) {
 char *xml;
@@ -2448,7 +2451,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 }
 
 if (qemuMigrationParamsSetCompression(driver, vm, 
QEMU_ASYNC_JOB_MIGRATION_IN,
-  compression, ) < 0)
+  compression, migParams) < 0)
 goto stopjob;
 
 /* Migrations using TLS need to add the "tls-creds-x509" object and
@@ -2461,17 +2464,17 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 
 if (qemuMigrationParamsAddTLSObjects(driver, vm, cfg, true,
  QEMU_ASYNC_JOB_MIGRATION_IN,
- , , ) 
< 0)
+ , , migParams) 
< 0)
 goto stopjob;
 
 /* Force reset of 'tls-hostname', it's a source only parameter */
-if (VIR_STRDUP(migParams.tlsHostname, "") < 0)
+if (VIR_STRDUP(migParams->tlsHostname, "") < 0)
 goto stopjob;
 
 } else {
 if 

[libvirt] [PATCH 06/68] qemu: Make qemuMigrationParamsFree follow common pattern

2018-04-04 Thread Jiri Denemark
Our *Free functions usually do not take a double pointer and the caller
has to make sure it doesn't use the stale pointer after the *Free
function returns.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c   |  2 +-
 src/qemu/qemu_migration_params.c | 10 +-
 src/qemu/qemu_migration_params.h |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 519bd767c1..bf6c0d0826 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12781,7 +12781,7 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
   flags, dname, bandwidth, true);
  cleanup:
 VIR_FREE(compression);
-qemuMigrationParamsFree();
+qemuMigrationParamsFree(migParams);
 VIR_FREE(migrate_disks);
 return ret;
 }
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 69fbeaefa9..867fe82b92 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -50,13 +50,13 @@ qemuMigrationParamsClear(qemuMonitorMigrationParamsPtr 
migParams)
 
 
 void
-qemuMigrationParamsFree(qemuMonitorMigrationParamsPtr *migParams)
+qemuMigrationParamsFree(qemuMonitorMigrationParamsPtr migParams)
 {
-if (!*migParams)
+if (!migParams)
 return;
 
-qemuMigrationParamsClear(*migParams);
-VIR_FREE(*migParams);
+qemuMigrationParamsClear(migParams);
+VIR_FREE(migParams);
 }
 
 
@@ -101,7 +101,7 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
 return migParams;
 
  error:
-qemuMigrationParamsFree();
+qemuMigrationParamsFree(migParams);
 return NULL;
 }
 
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 33b3c27e51..d3e7fe9d7a 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -37,7 +37,7 @@ void
 qemuMigrationParamsClear(qemuMonitorMigrationParamsPtr migParams);
 
 void
-qemuMigrationParamsFree(qemuMonitorMigrationParamsPtr *migParams);
+qemuMigrationParamsFree(qemuMonitorMigrationParamsPtr migParams);
 
 int
 qemuMigrationParamsSet(virQEMUDriverPtr driver,
-- 
2.17.0

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


[libvirt] [PATCH 23/68] qemu: Hide internals of qemuMigrationParams struct

2018-04-04 Thread Jiri Denemark
All users of migration parameters are supposed to use APIs provided by
qemu_migration_params.c without having to worry about the internals.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 5 +
 src/qemu/qemu_migration_params.h | 3 ---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 733df86687..42c7c6a3ec 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -30,6 +30,7 @@
 #include "qemu_hotplug.h"
 #include "qemu_migration.h"
 #include "qemu_migration_params.h"
+#include "qemu_monitor.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -37,6 +38,10 @@ VIR_LOG_INIT("qemu.qemu_migration_params");
 
 #define QEMU_MIGRATION_TLS_ALIAS_BASE "libvirt_migrate"
 
+struct _qemuMigrationParams {
+qemuMonitorMigrationParams params;
+};
+
 
 qemuMigrationParamsPtr
 qemuMigrationParamsNew(void)
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index e06aaa74eb..0f7cb55878 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -49,9 +49,6 @@ struct _qemuMigrationCompression {
 
 typedef struct _qemuMigrationParams qemuMigrationParams;
 typedef qemuMigrationParams *qemuMigrationParamsPtr;
-struct _qemuMigrationParams {
-qemuMonitorMigrationParams params;
-};
 
 
 qemuMigrationParamsPtr
-- 
2.17.0

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


[libvirt] [PATCH 10/68] qemu: Introduce qemuMigrationParams struct

2018-04-04 Thread Jiri Denemark
Currently migration parameters are stored in a structure which mimics
the QEMU migration parameters handled by query-migrate-parameters and
migrate-set-parameters. The new structure will become a libvirt's
abstraction on top of QEMU migration parameters, capabilities, and
related stuff.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c   |  6 ++--
 src/qemu/qemu_migration.c| 26 +++---
 src/qemu/qemu_migration.h|  2 +-
 src/qemu/qemu_migration_params.c | 62 
 src/qemu/qemu_migration_params.h | 21 +++
 5 files changed, 62 insertions(+), 55 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c157ff9bb0..6e6fc130c5 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12241,7 +12241,7 @@ qemuDomainMigratePerform(virDomainPtr dom,
 int ret = -1;
 const char *dconnuri = NULL;
 qemuMigrationCompressionPtr compression = NULL;
-qemuMonitorMigrationParamsPtr migParams = NULL;
+qemuMigrationParamsPtr migParams = NULL;
 
 virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
 
@@ -12669,7 +12669,7 @@ qemuDomainMigratePerform3(virDomainPtr dom,
 virQEMUDriverPtr driver = dom->conn->privateData;
 virDomainObjPtr vm;
 qemuMigrationCompressionPtr compression = NULL;
-qemuMonitorMigrationParamsPtr migParams = NULL;
+qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
 virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
@@ -12725,7 +12725,7 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
 unsigned long long bandwidth = 0;
 int nbdPort = 0;
 qemuMigrationCompressionPtr compression = NULL;
-qemuMonitorMigrationParamsPtr migParams = NULL;
+qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
 virCheckFlags(QEMU_MIGRATION_FLAGS, -1);
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index ffdf0ba2e5..a6f8e66891 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2254,7 +2254,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 int rv;
 char *tlsAlias = NULL;
 char *secAlias = NULL;
-qemuMonitorMigrationParamsPtr migParams = NULL;
+qemuMigrationParamsPtr migParams = NULL;
 
 virNWFilterReadLockFilterUpdates();
 
@@ -2468,7 +2468,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 goto stopjob;
 
 /* Force reset of 'tls-hostname', it's a source only parameter */
-if (VIR_STRDUP(migParams->tlsHostname, "") < 0)
+if (VIR_STRDUP(migParams->params.tlsHostname, "") < 0)
 goto stopjob;
 
 } else {
@@ -3340,7 +3340,7 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 size_t nmigrate_disks,
 const char **migrate_disks,
 qemuMigrationCompressionPtr compression,
-qemuMonitorMigrationParamsPtr migParams)
+qemuMigrationParamsPtr migParams)
 {
 int ret = -1;
 unsigned int migrate_flags = QEMU_MONITOR_MIGRATE_BACKGROUND;
@@ -3429,11 +3429,11 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
  * connect directly to the destination. */
 if (spec->destType == MIGRATION_DEST_CONNECT_HOST ||
 spec->destType == MIGRATION_DEST_FD) {
-if (VIR_STRDUP(migParams->tlsHostname, spec->dest.host.name) < 0)
+if (VIR_STRDUP(migParams->params.tlsHostname, 
spec->dest.host.name) < 0)
 goto error;
 } else {
 /* Be sure there's nothing from a previous migration */
-if (VIR_STRDUP(migParams->tlsHostname, "") < 0)
+if (VIR_STRDUP(migParams->params.tlsHostname, "") < 0)
 goto error;
 }
 } else {
@@ -3736,7 +3736,7 @@ qemuMigrationSrcPerformNative(virQEMUDriverPtr driver,
   size_t nmigrate_disks,
   const char **migrate_disks,
   qemuMigrationCompressionPtr compression,
-  qemuMonitorMigrationParamsPtr migParams)
+  qemuMigrationParamsPtr migParams)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
 virURIPtr uribits = NULL;
@@ -3815,7 +3815,7 @@ qemuMigrationSrcPerformTunnel(virQEMUDriverPtr driver,
   size_t nmigrate_disks,
   const char **migrate_disks,
   qemuMigrationCompressionPtr compression,
-  qemuMonitorMigrationParamsPtr migParams)
+  qemuMigrationParamsPtr migParams)
 {
 int ret = -1;
 qemuMigrationSpec spec;
@@ -3887,7 +3887,7 @@ qemuMigrationSrcPerformPeer2Peer2(virQEMUDriverPtr driver,
 virStreamPtr st = NULL;
 unsigned long destflags;
 qemuMigrationCompressionPtr compression = NULL;
-qemuMonitorMigrationParamsPtr migParams = NULL;
+qemuMigrationParamsPtr 

[libvirt] [PATCH 22/68] qemu: Rename qemuMigrationParamsSet

2018-04-04 Thread Jiri Denemark
The new name is qemuMigrationParamsApply and it will soon become the
only API which will send all requested migration parameters and
capabilities to QEMU. All other qemuMigrationParams* APIs will just
operate on the qemuMigrationParams structure.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c|  8 
 src/qemu/qemu_migration_params.c | 21 -
 src/qemu/qemu_migration_params.h |  8 
 3 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index d07a12cdec..3e775ea56b 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2479,8 +2479,8 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
 goto stopjob;
 
-if (qemuMigrationParamsSet(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
-   migParams) < 0)
+if (qemuMigrationParamsApply(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
+ migParams) < 0)
 goto stopjob;
 
 if (mig->nbd &&
@@ -3474,8 +3474,8 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
true, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
 goto error;
 
-if (qemuMigrationParamsSet(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
-   migParams) < 0)
+if (qemuMigrationParamsApply(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
+ migParams) < 0)
 goto error;
 
 if (qemuDomainObjEnterMonitorAsync(driver, vm,
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 7b5a7c108f..733df86687 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -108,11 +108,22 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
 }
 
 
+/**
+ * qemuMigrationParamsApply
+ * @driver: qemu driver
+ * @vm: domain object
+ * @asyncJob: migration job
+ * @migParams: migration parameters to send to QEMU
+ *
+ * Send all parameters stored in @migParams to QEMU.
+ *
+ * Returns 0 on success, -1 on failure.
+ */
 int
-qemuMigrationParamsSet(virQEMUDriverPtr driver,
-   virDomainObjPtr vm,
-   int asyncJob,
-   qemuMigrationParamsPtr migParams)
+qemuMigrationParamsApply(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ int asyncJob,
+ qemuMigrationParamsPtr migParams)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
 int ret = -1;
@@ -391,7 +402,7 @@ qemuMigrationParamsReset(virQEMUDriverPtr driver,
 goto cleanup;
 
 if (origParams) {
-if (qemuMigrationParamsSet(driver, vm, asyncJob, origParams) < 0)
+if (qemuMigrationParamsApply(driver, vm, asyncJob, origParams) < 0)
 goto cleanup;
 qemuMigrationParamsResetTLS(driver, vm, asyncJob, origParams);
 }
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 45834e5b48..e06aaa74eb 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -66,10 +66,10 @@ void
 qemuMigrationParamsFree(qemuMigrationParamsPtr migParams);
 
 int
-qemuMigrationParamsSet(virQEMUDriverPtr driver,
-   virDomainObjPtr vm,
-   int asyncJob,
-   qemuMigrationParamsPtr migParams);
+qemuMigrationParamsApply(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ int asyncJob,
+ qemuMigrationParamsPtr migParams);
 
 int
 qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
-- 
2.17.0

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


[libvirt] [PATCH 05/68] qemu: Reindent qemuMigrationParamsSetEmptyTLS

2018-04-04 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 72ecafd057..69fbeaefa9 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -299,17 +299,17 @@ qemuMigrationParamsSetEmptyTLS(virQEMUDriverPtr driver,
int asyncJob,
qemuMonitorMigrationParamsPtr migParams)
 {
-   qemuDomainObjPrivatePtr priv = vm->privateData;
+qemuDomainObjPrivatePtr priv = vm->privateData;
 
-   if (qemuMigrationParamsCheckTLSCreds(driver, vm, asyncJob) < 0)
-   return -1;
+if (qemuMigrationParamsCheckTLSCreds(driver, vm, asyncJob) < 0)
+return -1;
 
-   if (!priv->migTLSAlias)
-   return 0;
+if (!priv->migTLSAlias)
+return 0;
 
-   if (VIR_STRDUP(migParams->tlsCreds, "") < 0 ||
-   VIR_STRDUP(migParams->tlsHostname, "") < 0)
-   return -1;
+if (VIR_STRDUP(migParams->tlsCreds, "") < 0 ||
+VIR_STRDUP(migParams->tlsHostname, "") < 0)
+return -1;
 
 return 0;
 }
-- 
2.17.0

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


[libvirt] [PATCHv3 6/6] qemu: refresh vcpu halted state only via query-cpus-fast

2018-04-04 Thread Viktor Mihajlovski
In order to not affect running VMs, refreshing the halted state
is only performed if QEMU supports the query-cpus-fast QAPI.

Signed-off-by: Viktor Mihajlovski 
Reviewed-by: Boris Fiuczynski 
Reviewed-by: Marc Hartmayer 
---
 src/qemu/qemu_domain.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 662937b..0331af7 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -9124,8 +9124,13 @@ qemuDomainRefreshVcpuHalted(virQEMUDriverPtr driver,
 return 0;
 
 /* The halted state is interresting only on s390(x). On other platforms
- * the data would be stale at the time when it would be used. */
-if (!ARCH_IS_S390(vm->def->os.arch))
+ * the data would be stale at the time when it would be used.
+ * Calling qemuMonitorGetCpuHalted() can adversely affect the running
+ * VM's performance unless QEMU supports query-cpus-fast.
+ */
+if (!ARCH_IS_S390(vm->def->os.arch) ||
+!virQEMUCapsGet(QEMU_DOMAIN_PRIVATE(vm)->qemuCaps,
+QEMU_CAPS_QUERY_CPUS_FAST))
 return 0;
 
 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
-- 
1.9.1

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


[libvirt] [PATCHv3 5/6] tests: add testcase for s390 query-cpus-fast

2018-04-04 Thread Viktor Mihajlovski
The s390 testcase verifies that the s390-specific cpu-state
field is correctly mapped to the halted property.

Signed-off-by: Viktor Mihajlovski 
---
 .../qemumonitorjson-cpuinfo-s390-fast-cpus.json| 25 ++
 .../qemumonitorjson-cpuinfo-s390-fast-hotplug.json | 21 ++
 .../qemumonitorjson-cpuinfo-s390-fast.data | 19 
 tests/qemumonitorjsontest.c|  2 ++
 4 files changed, 67 insertions(+)
 create mode 100644 
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast-cpus.json
 create mode 100644 
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast-hotplug.json
 create mode 100644 
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast.data

diff --git 
a/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast-cpus.json 
b/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast-cpus.json
new file mode 100644
index 000..ef9c975
--- /dev/null
+++ b/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast-cpus.json
@@ -0,0 +1,25 @@
+{
+  "return": [
+{
+  "arch": "s390",
+  "cpu-index": 0,
+  "props": {
+ "core-id": 0
+  },
+  "qom-path": "/machine/unattached/device[0]",
+  "thread-id": 89504,
+  "cpu-state": "operating"
+},
+{
+  "arch": "s390",
+  "cpu-index": 1,
+  "props": {
+ "core-id": 1
+  },
+  "qom-path": "/machine/unattached/device[1]",
+  "thread-id": 89505,
+  "cpu-state": "stopped"
+}
+  ],
+  "id": "libvirt-42"
+}
diff --git 
a/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast-hotplug.json 
b/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast-hotplug.json
new file mode 100644
index 000..8016b5b
--- /dev/null
+++ b/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast-hotplug.json
@@ -0,0 +1,21 @@
+{
+  "return": [
+{
+  "props": {
+"core-id": 1
+  },
+  "vcpus-count": 1,
+  "qom-path": "/machine/unattached/device[1]",
+  "type": "host-s390x-cpu"
+},
+{
+  "props": {
+"core-id": 0
+  },
+  "vcpus-count": 1,
+  "qom-path": "/machine/unattached/device[0]",
+  "type": "host-s390x-cpu"
+}
+  ],
+  "id": "libvirt-41"
+}
diff --git a/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast.data 
b/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast.data
new file mode 100644
index 000..9fc7041
--- /dev/null
+++ b/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast.data
@@ -0,0 +1,19 @@
+[vcpu libvirt-id='0']
+online=yes
+hotpluggable=no
+thread-id='89504'
+enable-id='1'
+query-cpus-id='0'
+type='host-s390x-cpu'
+qom_path='/machine/unattached/device[0]'
+topology: core='0' vcpus='1'
+[vcpu libvirt-id='1']
+online=yes
+hotpluggable=no
+thread-id='89505'
+enable-id='2'
+query-cpus-id='1'
+type='host-s390x-cpu'
+qom_path='/machine/unattached/device[1]'
+topology: core='1' vcpus='1'
+halted
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 5daa2c9..b468b04 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -3090,6 +3090,8 @@ mymain(void)
 DO_TEST_CPU_INFO("ppc64-hotplug-4", 24);
 DO_TEST_CPU_INFO("ppc64-no-threads", 16);
 
+DO_TEST_CPU_INFO_FAST("s390-fast", 2);
+
 #define DO_TEST_BLOCK_NODE_DETECT(testname) \
 do { \
 if (virTestRun("node-name-detect(" testname ")", \
-- 
1.9.1

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


[libvirt] [PATCHv3 1/6] qemu: add capability detection for query-cpus-fast

2018-04-04 Thread Viktor Mihajlovski
Detect whether QEMU supports the QMP query-cpus-fast API
and set QEMU_CAPS_QUERY_CPUS_FAST in this case.

Signed-off-by: Viktor Mihajlovski 
---
 src/qemu/qemu_capabilities.c   | 2 ++
 src/qemu/qemu_capabilities.h   | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml  | 1 +
 6 files changed, 7 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 959c27f..4034f1f 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -467,6 +467,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
   "virtio-mouse-ccw",
   "virtio-tablet-ccw",
   "qcow2-luks",
+  "query-cpus-fast",
 );
 
 
@@ -1588,6 +1589,7 @@ struct virQEMUCapsStringFlags virQEMUCapsCommands[] = {
 { "query-cpu-model-expansion", QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION },
 { "query-cpu-definitions", QEMU_CAPS_QUERY_CPU_DEFINITIONS },
 { "query-named-block-nodes", QEMU_CAPS_QUERY_NAMED_BLOCK_NODES },
+{ "query-cpus-fast", QEMU_CAPS_QUERY_CPUS_FAST },
 };
 
 struct virQEMUCapsStringFlags virQEMUCapsMigration[] = {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 2203c28..db6d42f 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -451,6 +451,7 @@ typedef enum {
 QEMU_CAPS_DEVICE_VIRTIO_MOUSE_CCW, /* -device virtio-mouse-ccw */
 QEMU_CAPS_DEVICE_VIRTIO_TABLET_CCW, /* -device virtio-tablet-ccw */
 QEMU_CAPS_QCOW2_LUKS, /* qcow2 format support LUKS encryption */
+QEMU_CAPS_QUERY_CPUS_FAST, /* query-cpus-fast command */
 
 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml 
b/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml
index ec2eec1..bf79777 100644
--- a/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml
@@ -188,6 +188,7 @@
   
   
   
+  
   2011090
   0
   342346
diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml 
b/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml
index 1122d64..9958d36 100644
--- a/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml
@@ -186,6 +186,7 @@
   
   
   
+  
   2011090
   0
   419215
diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml 
b/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml
index 191b1e0..272b77d 100644
--- a/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml
+++ b/tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml
@@ -151,6 +151,7 @@
   
   
   
+  
   2011090
   0
   0
diff --git a/tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml 
b/tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml
index aa5de81..b5f40cd 100644
--- a/tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml
@@ -226,6 +226,7 @@
   
   
   
+  
   2011090
   0
   390060
-- 
1.9.1

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


[libvirt] [PATCHv3 3/6] tests: add qemumonitorjson tests for query-cpus-fast

2018-04-04 Thread Viktor Mihajlovski
Extended the json monitor test program with support for query-cpus-fast
and added a sample file set for x86 data obtained using the it.
Also extend the test program to recognize the halted property.

Signed-off-by: Viktor Mihajlovski 
---
 .../qemumonitorjson-cpuinfo-ppc64-hotplug-4.data   |   8 ++
 ...emumonitorjson-cpuinfo-x86-basic-pluggable.data |   5 +
 ...qemumonitorjson-cpuinfo-x86-full-fast-cpus.json | 126 +
 ...umonitorjson-cpuinfo-x86-full-fast-hotplug.json | 115 +++
 .../qemumonitorjson-cpuinfo-x86-full-fast.data | 109 ++
 .../qemumonitorjson-cpuinfo-x86-node-full.data |   2 +
 tests/qemumonitorjsontest.c| 121 +++-
 tests/qemumonitortestutils.c   |   7 ++
 tests/qemumonitortestutils.h   |   1 +
 9 files changed, 468 insertions(+), 26 deletions(-)
 create mode 100644 
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-full-fast-cpus.json
 create mode 100644 
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-full-fast-hotplug.json
 create mode 100644 
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-full-fast.data

diff --git 
a/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-ppc64-hotplug-4.data 
b/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-ppc64-hotplug-4.data
index 7c90889..5f6b865 100644
--- a/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-ppc64-hotplug-4.data
+++ b/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-ppc64-hotplug-4.data
@@ -52,41 +52,49 @@
 alias='vcpu0'
 qom_path='/machine/peripheral/vcpu0'
 topology: core='8' vcpus='8'
+halted
 [vcpu libvirt-id='9']
 online=yes
 hotpluggable=yes
 thread-id='23171'
 query-cpus-id='17'
+halted
 [vcpu libvirt-id='10']
 online=yes
 hotpluggable=yes
 thread-id='23172'
 query-cpus-id='18'
+halted
 [vcpu libvirt-id='11']
 online=yes
 hotpluggable=yes
 thread-id='23173'
 query-cpus-id='19'
+halted
 [vcpu libvirt-id='12']
 online=yes
 hotpluggable=yes
 thread-id='23174'
 query-cpus-id='20'
+halted
 [vcpu libvirt-id='13']
 online=yes
 hotpluggable=yes
 thread-id='23175'
 query-cpus-id='21'
+halted
 [vcpu libvirt-id='14']
 online=yes
 hotpluggable=yes
 thread-id='23176'
 query-cpus-id='22'
+halted
 [vcpu libvirt-id='15']
 online=yes
 hotpluggable=yes
 thread-id='23177'
 query-cpus-id='23'
+halted
 [vcpu libvirt-id='16']
 online=yes
 hotpluggable=yes
diff --git 
a/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-basic-pluggable.data 
b/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-basic-pluggable.data
index 93cefb9..9a1788d 100644
--- a/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-basic-pluggable.data
+++ b/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-basic-pluggable.data
@@ -7,6 +7,7 @@
 type='qemu64-x86_64-cpu'
 qom_path='/machine/unattached/device[0]'
 topology: socket='0' core='0' thread='0' vcpus='1'
+halted
 [vcpu libvirt-id='1']
 online=yes
 hotpluggable=no
@@ -16,6 +17,7 @@
 type='qemu64-x86_64-cpu'
 qom_path='/machine/unattached/device[2]'
 topology: socket='0' core='0' thread='1' vcpus='1'
+halted
 [vcpu libvirt-id='2']
 online=yes
 hotpluggable=no
@@ -25,6 +27,7 @@
 type='qemu64-x86_64-cpu'
 qom_path='/machine/unattached/device[3]'
 topology: socket='0' core='1' thread='0' vcpus='1'
+halted
 [vcpu libvirt-id='3']
 online=yes
 hotpluggable=no
@@ -34,6 +37,7 @@
 type='qemu64-x86_64-cpu'
 qom_path='/machine/unattached/device[4]'
 topology: socket='0' core='1' thread='1' vcpus='1'
+halted
 [vcpu libvirt-id='4']
 online=yes
 hotpluggable=no
@@ -43,6 +47,7 @@
 type='qemu64-x86_64-cpu'
 qom_path='/machine/unattached/device[5]'
 topology: socket='1' core='0' thread='0' vcpus='1'
+halted
 [vcpu libvirt-id='5']
 online=no
 hotpluggable=yes
diff --git 
a/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-full-fast-cpus.json 
b/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-full-fast-cpus.json
new file mode 100644
index 000..b8c2553
--- /dev/null
+++ b/tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-full-fast-cpus.json
@@ -0,0 +1,126 @@
+{
+  "return": [
+{
+  "arch": "x86",
+  "cpu-index": 0,
+  "props": {
+"core-id": 0,
+"thread-id": 0,
+"socket-id": 0
+  },
+  "qom-path": "/machine/unattached/device[0]",
+  "thread-id": 895040
+},
+{
+  "arch": "x86",
+  "cpu-index": 1,
+  "props": {
+"core-id": 0,
+"thread-id": 0,
+"socket-id": 1
+  },
+  "qom-path": "/machine/peripheral/vcpu1",
+  "thread-id": 895056
+},
+{
+  "arch": "x86",
+  "cpu-index": 2,
+  "props": {
+"core-id": 0,
+"thread-id": 0,
+ 

[libvirt] [PATCHv3 0/6] Use query-cpus-fast instead of query-cpus

2018-04-04 Thread Viktor Mihajlovski
The QEMU monitor commmand query-cpus is deprecated starting
with QEMU 2.12.0 because it can adversely affect the performance of
a running virtual machine.

This series enables libvirt to use the new query-cpus-fast interface
if supported by the local QEMU instance and is required in order
to support QEMU once the interface has been removed.

query-cpus-fast doesn't return the halted state for a virtual CPU,
meaning that the vcpu..halted value won't be reported with
'virsh domstats' anymore. This is OK, as stats values are not
guaranteed to be reported under all circumstances and on all
architectures.

Upstream discussion consensus was that the halted state was
problematic anyway, as it had different semantics per architecture.
The only known exploitation happened for s390, for this architecture
the halted state will be computed based on an architecture-specific
cpu value returned in query-cpus-fast.

v2 -> v3:
=
  Patch changes:
  1/6:
  - formatting changes as requested by John Ferlan
  - updated the qemucapabilitiestest XML files
  - dropped A/R-bys (due to change above)
  
  2/6:
  - fixed comment to also account for query-cpus-fast

  3/6:
  - updated json monitor tests to account for props returned by
query-cpus and query-cpus-fast
  - updated json monitor tests to handle the halted property
(moved here from patch 5)

  4/6:
  - removed stale text (about callbacks) from commit message 
  - simplified qemuMonitorJSONExtractCPUArchInfo call
  - enhanced sample JSON response in comment
  - fixed inter-function spacing

  5/6:
  - kept s390-specific tests and moved the rest to patch 3
  - reformatted the JSON responses (indented "props")
  - dropped R-b

v1 -> v2:
=
  Patch changes:
  1/6:
  - add Acked-by: Peter Krempa  

  2/6:
  - evaluate capability outside of monitor code (changes signatures
of qemuMonitorGetCPUInfo and qemuMonitorGetCpuHalted)
  - remove ternary expressions as requested by review
  - remove Reviewed-bys due to code changes

  3/6 
  - adapt test cases to changes above
  - remove Reviewed-bys due to code changes

  4/6
  - replace callbacks for architecture data extraction with direct
function calls
  - remove Reviewed-bys due to code changes

Viktor Mihajlovski (6):
  qemu: add capability detection for query-cpus-fast
  qemu: use query-cpus-fast in JSON monitor
  tests: add qemumonitorjson tests for query-cpus-fast
  qemu: add architecture-specific CPU info handling
  tests: add testcase for s390 query-cpus-fast
  qemu: refresh vcpu halted state only via query-cpus-fast

 src/qemu/qemu_capabilities.c   |   2 +
 src/qemu/qemu_capabilities.h   |   1 +
 src/qemu/qemu_domain.c |  23 +++-
 src/qemu/qemu_monitor.c|  30 +++--
 src/qemu/qemu_monitor.h|   7 +-
 src/qemu/qemu_monitor_json.c   | 133 +++--
 src/qemu/qemu_monitor_json.h   |   3 +-
 tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml |   1 +
 tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml   |   1 +
 tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml   |   1 +
 tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml  |   1 +
 .../qemumonitorjson-cpuinfo-ppc64-hotplug-4.data   |   8 ++
 .../qemumonitorjson-cpuinfo-s390-fast-cpus.json|  25 
 .../qemumonitorjson-cpuinfo-s390-fast-hotplug.json |  21 
 .../qemumonitorjson-cpuinfo-s390-fast.data |  19 +++
 ...emumonitorjson-cpuinfo-x86-basic-pluggable.data |   5 +
 ...qemumonitorjson-cpuinfo-x86-full-fast-cpus.json | 126 +++
 ...umonitorjson-cpuinfo-x86-full-fast-hotplug.json | 115 ++
 .../qemumonitorjson-cpuinfo-x86-full-fast.data | 109 +
 .../qemumonitorjson-cpuinfo-x86-node-full.data |   2 +
 tests/qemumonitorjsontest.c| 123 +++
 tests/qemumonitortestutils.c   |   7 ++
 tests/qemumonitortestutils.h   |   1 +
 23 files changed, 706 insertions(+), 58 deletions(-)
 create mode 100644 
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast-cpus.json
 create mode 100644 
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast-hotplug.json
 create mode 100644 
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-s390-fast.data
 create mode 100644 
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-full-fast-cpus.json
 create mode 100644 
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-full-fast-hotplug.json
 create mode 100644 
tests/qemumonitorjsondata/qemumonitorjson-cpuinfo-x86-full-fast.data

-- 
1.9.1

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


[libvirt] [PATCHv3 4/6] qemu: add architecture-specific CPU info handling

2018-04-04 Thread Viktor Mihajlovski
Extract architecture specific data from query-cpus[-fast] if
available. A new function qemuMonitorJSONExtractCPUArchInfo()
can then call architecture-specific extraction handlers.

Initially, there's a handler for s390 cpu info to
set the halted property depending on the s390 cpu state
returned by QEMU. With this it's still possible to report
the halted condition even when using query-cpus-fast.

Signed-off-by: Viktor Mihajlovski 
---
 src/qemu/qemu_monitor.c  |  4 +-
 src/qemu/qemu_monitor_json.c | 96 +++-
 2 files changed, 96 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 2b4b7c7..5c4581a 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2076,7 +2076,7 @@ qemuMonitorGetCPUInfo(qemuMonitorPtr mon,
 virBitmapPtr
 qemuMonitorGetCpuHalted(qemuMonitorPtr mon,
 size_t maxvcpus,
-bool fast ATTRIBUTE_UNUSED)
+bool fast)
 {
 struct qemuMonitorQueryCpusEntry *cpuentries = NULL;
 size_t ncpuentries = 0;
@@ -2088,7 +2088,7 @@ qemuMonitorGetCpuHalted(qemuMonitorPtr mon,
 
 if (mon->json)
 rc = qemuMonitorJSONQueryCPUs(mon, , , false,
-  false);
+  fast);
 else
 rc = qemuMonitorTextQueryCPUs(mon, , );
 
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 4f2018d..a46e6cf 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1517,15 +1517,104 @@ int qemuMonitorJSONSystemReset(qemuMonitorPtr mon)
 }
 
 
-/*
+/**
+ * qemuMonitorJSONExtractCPUS390Info:
+ * @jsoncpu: pointer to a single JSON cpu entry
+ * @cpu: pointer to a single cpu entry
+ *
+ * Derive the legacy cpu info 'halted' information
+ * from the more accurate s390 cpu state. @cpu is
+ * modified only on success.
+ *
+ * Note: the 'uninitialized' s390 cpu state can't be
+ *   mapped to halted yes/no.
+ *
+ * A s390 cpu entry could look like this
+ *  { "arch": "s390",
+ *"cpu-index": 0,
+ *"qom-path": "/machine/unattached/device[0]",
+ *"thread_id": 3081,
+ *"cpu-state": "operating" }
+ *
+ */
+static void
+qemuMonitorJSONExtractCPUS390Info(virJSONValuePtr jsoncpu,
+  struct qemuMonitorQueryCpusEntry *cpu)
+{
+const char *cpu_state = virJSONValueObjectGetString(jsoncpu, "cpu-state");
+
+if (STREQ_NULLABLE(cpu_state, "operating") ||
+STREQ_NULLABLE(cpu_state, "load"))
+cpu->halted = false;
+else if (STREQ_NULLABLE(cpu_state, "stopped") ||
+ STREQ_NULLABLE(cpu_state, "check-stop"))
+cpu->halted = true;
+}
+
+
+/**
+ * qemuMonitorJSONExtractCPUArchInfo:
+ * @jsoncpu: pointer to a single JSON cpu entry
+ * @cpu: pointer to a single cpu entry
+ *
+ * Extracts architecure specific virtual CPU data for a single
+ * CPU from the QAPI response using an architecture specific
+ * function.
+ *
+ */
+static void
+qemuMonitorJSONExtractCPUArchInfo(virJSONValuePtr jsoncpu,
+  struct qemuMonitorQueryCpusEntry *cpu)
+{
+const char *arch = virJSONValueObjectGetString(jsoncpu, "arch");
+
+if (STREQ_NULLABLE(arch, "s390"))
+qemuMonitorJSONExtractCPUS390Info(jsoncpu, cpu);
+}
+
+
+/**
+ * qemuMonitorJSONExtractCPUInfo:
+ * @data: JSON response data
+ * @entries: filled with detected cpu entries on success
+ * @nentries: number of entries returned
+ * @fast: true if this is a response from query-cpus-fast
  *
+ * The JSON response @data will have the following format
+ * in case @fast == false
  * [{ "arch": "x86",
  *"current": true,
  *"CPU": 0,
  *"qom_path": "/machine/unattached/device[0]",
  *"pc": -2130415978,
  *"halted": true,
- *"thread_id": 2631237},
+ *"thread_id": 2631237,
+ *...},
+ *{...}
+ *  ]
+ * and for @fast == true
+ * [{ "arch": "x86",
+ *"cpu-index": 0,
+ *"props": {
+ *   "core-id": 0,
+ *   "thread-id": 0,
+ *   "socket-id": 0
+ *},
+ *"qom-path": "/machine/unattached/device[0]",
+ *"thread-id": 2631237,
+ *...},
+ *{...}
+ *  ]
+ * or for s390
+ * [{ "arch": "s390",
+ *"cpu-index": 0,
+ *"props": {
+ *   "core-id": 0
+ *},
+ *"qom-path": "/machine/unattached/device[0]",
+ *"thread-id": 1237,
+ *"cpu-state": "operating",
+ *...},
  *{...}
  *  ]
  */
@@ -1577,6 +1666,9 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data,
 cpus[i].halted = halted;
 if (VIR_STRDUP(cpus[i].qom_path, qom_path) < 0)
 goto cleanup;
+
+/* process optional architecture-specific data */
+qemuMonitorJSONExtractCPUArchInfo(entry, cpus + i);
 }
 
 VIR_STEAL_PTR(*entries, cpus);
-- 
1.9.1

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


[libvirt] [PATCHv3 2/6] qemu: use query-cpus-fast in JSON monitor

2018-04-04 Thread Viktor Mihajlovski
Use query-cpus-fast instead of query-cpus if supported by QEMU.
Based on the QEMU_CAPS_QUERY_CPUS_FAST capability.

Signed-off-by: Viktor Mihajlovski 
---
 src/qemu/qemu_domain.c   | 14 +++---
 src/qemu/qemu_monitor.c  | 30 ++
 src/qemu/qemu_monitor.h  |  7 +--
 src/qemu/qemu_monitor_json.c | 37 +++--
 src/qemu/qemu_monitor_json.h |  3 ++-
 tests/qemumonitorjsontest.c  |  4 ++--
 6 files changed, 65 insertions(+), 30 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 9d1c33b..662937b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -9006,7 +9006,12 @@ qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
 return -1;
 
-rc = qemuMonitorGetCPUInfo(qemuDomainGetMonitor(vm), , maxvcpus, 
hotplug);
+rc = qemuMonitorGetCPUInfo(qemuDomainGetMonitor(vm),
+   ,
+   maxvcpus,
+   hotplug,
+   
virQEMUCapsGet(QEMU_DOMAIN_PRIVATE(vm)->qemuCaps,
+  QEMU_CAPS_QUERY_CPUS_FAST));
 
 if (qemuDomainObjExitMonitor(driver, vm) < 0)
 goto cleanup;
@@ -9025,7 +9030,7 @@ qemuDomainRefreshVcpuInfo(virQEMUDriverPtr driver,
  * thread, but it runs every vCPU in that same thread. So it
  * is impossible to setup different affinity per thread.
  *
- * What's more the 'query-cpus' command returns bizarre
+ * What's more the 'query-cpus[-fast]' command returns bizarre
  * data for the threads. It gives the TCG thread for the
  * vCPU 0, but for vCPUs 1-> N, it actually replies with
  * the main process thread ID.
@@ -9126,7 +9131,10 @@ qemuDomainRefreshVcpuHalted(virQEMUDriverPtr driver,
 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
 return -1;
 
-haltedmap = qemuMonitorGetCpuHalted(qemuDomainGetMonitor(vm), maxvcpus);
+haltedmap = qemuMonitorGetCpuHalted(qemuDomainGetMonitor(vm),
+maxvcpus,
+
virQEMUCapsGet(QEMU_DOMAIN_PRIVATE(vm)->qemuCaps,
+   
QEMU_CAPS_QUERY_CPUS_FAST));
 
 if (qemuDomainObjExitMonitor(driver, vm) < 0 || !haltedmap)
 goto cleanup;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 7b64752..2b4b7c7 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1852,15 +1852,16 @@ qemuMonitorGetCPUInfoLegacy(struct 
qemuMonitorQueryCpusEntry *cpuentries,
  *
  * This function stitches together data retrieved via query-hotpluggable-cpus
  * which returns entities on the hotpluggable level (which may describe more
- * than one guest logical vcpu) with the output of query-cpus, having an entry
- * per enabled guest logical vcpu.
+ * than one guest logical vcpu) with the output of query-cpus (or
+ * query-cpus-fast), having an entry per enabled guest logical vcpu.
  *
  * query-hotpluggable-cpus conveys following information:
  * - topology information and number of logical vcpus this entry creates
  * - device type name of the entry that needs to be used when hotplugging
- * - qom path in qemu which can be used to map the entry against query-cpus
+ * - qom path in qemu which can be used to map the entry against
+ *   query-cpus[-fast]
  *
- * query-cpus conveys following information:
+ * query-cpus[-fast] conveys following information:
  * - thread id of a given guest logical vcpu
  * - order in which the vcpus were inserted
  * - qom path to allow mapping the two together
@@ -1895,7 +1896,7 @@ qemuMonitorGetCPUInfoHotplug(struct 
qemuMonitorQueryHotpluggableCpusEntry *hotpl
 for (i = 0; i < nhotplugvcpus; i++)
 totalvcpus += hotplugvcpus[i].vcpus;
 
-/* trim '/thread...' suffix from the data returned by query-cpus */
+/* trim '/thread...' suffix from the data returned by query-cpus[-fast] */
 for (i = 0; i < ncpuentries; i++) {
 if (cpuentries[i].qom_path &&
 (tmp = strstr(cpuentries[i].qom_path, "/thread")))
@@ -1908,7 +1909,7 @@ qemuMonitorGetCPUInfoHotplug(struct 
qemuMonitorQueryHotpluggableCpusEntry *hotpl
 }
 
 /* Note the order in which the hotpluggable entities are inserted by
- * matching them to the query-cpus entries */
+ * matching them to the query-cpus[-fast] entries */
 for (i = 0; i < ncpuentries; i++) {
 for (j = 0; j < nhotplugvcpus; j++) {
 if (!cpuentries[i].qom_path ||
@@ -1963,7 +1964,7 @@ qemuMonitorGetCPUInfoHotplug(struct 
qemuMonitorQueryHotpluggableCpusEntry *hotpl
 }
 
 if (anyvcpu == maxvcpus) {
-VIR_DEBUG("too many query-cpus entries for a given "
+VIR_DEBUG("too many query-cpus[-fast] entries for 

[libvirt] [PATCH 64/68] qemu: Drop priv->job.dump_memory_only bool

2018-04-04 Thread Jiri Denemark
We store the flags passed to the API which started QEMU_ASYNC_JOB_DUMP
and we can use them to check whether a memory-only dump is running.
There's no need for a specific bool flag.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_domain.c | 1 -
 src/qemu/qemu_domain.h | 1 -
 src/qemu/qemu_driver.c | 4 +---
 3 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3f3a49f064..d82c9aad23 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -329,7 +329,6 @@ qemuDomainObjResetAsyncJob(qemuDomainObjPrivatePtr priv)
 job->asyncStarted = 0;
 job->phase = 0;
 job->mask = QEMU_JOB_DEFAULT_MASK;
-job->dump_memory_only = false;
 job->abortJob = false;
 job->spiceMigration = false;
 job->spiceMigrated = false;
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 2146ff00a9..8d608da121 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -170,7 +170,6 @@ struct _qemuDomainJobObj {
 unsigned long long asyncStarted;/* When the current async job started 
*/
 int phase;  /* Job phase (mainly for migrations) */
 unsigned long long mask;/* Jobs allowed during async job */
-bool dump_memory_only;  /* use dump-guest-memory to do dump */
 qemuDomainJobInfoPtr current;   /* async job progress data */
 qemuDomainJobInfoPtr completed; /* statistics data of a recently 
completed job */
 bool abortJob;  /* abort of the job requested */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b9927b727b..04eb0b6929 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3794,8 +3794,6 @@ qemuDumpToFd(virQEMUDriverPtr driver,
 if (qemuSecuritySetImageFDLabel(driver->securityManager, vm->def, fd) < 0)
 return -1;
 
-priv->job.dump_memory_only = true;
-
 if (detach)
 priv->job.current->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_MEMDUMP;
 else
@@ -13486,7 +13484,7 @@ static int qemuDomainAbortJob(virDomainPtr dom)
 }
 
 if (priv->job.asyncJob == QEMU_ASYNC_JOB_DUMP &&
-priv->job.dump_memory_only) {
+priv->job.apiFlags & VIR_DUMP_MEMORY_ONLY) {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot abort memory-only dump"));
 goto endjob;
-- 
2.17.0

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


[libvirt] [PATCH 54/68] qemu: Refactor qemuMigrationParams

2018-04-04 Thread Jiri Denemark
Adding support for new migration parameter requires a lot of places to
be changed (most likely by copy engineering): new variables to
store the parameter value and the associated *_set bool, JSON formatter
and parser, XML formatter and parser (to be added soon), and the actual
code to set the parameter. It's pretty easy to forget about some of the
places which need to be updated and end up with incorrect support. The
goal of this patch is to let most of the places do their job without any
modifications when new parameters are added.

To achieve the goal, a new qemuMigrationParam enum is introduced and all
parameters are stored in an array indexed by the items of this enum.
This will also allow us to automatically set the migration parameters
which directly correspond to libvirt's typed parameters accepted by
virDomainMigrate* APIs.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 469 ---
 src/qemu/qemu_migration_params.h |  20 ++
 2 files changed, 327 insertions(+), 162 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 9f091ec693..50f69ee571 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -38,46 +38,29 @@ VIR_LOG_INIT("qemu.qemu_migration_params");
 
 #define QEMU_MIGRATION_TLS_ALIAS_BASE "libvirt_migrate"
 
-typedef struct _qemuMonitorMigrationParams qemuMonitorMigrationParams;
-typedef qemuMonitorMigrationParams *qemuMonitorMigrationParamsPtr;
-struct _qemuMonitorMigrationParams {
-bool compressLevel_set;
-int compressLevel;
+typedef enum {
+QEMU_MIGRATION_PARAM_TYPE_INT,
+QEMU_MIGRATION_PARAM_TYPE_ULL,
+QEMU_MIGRATION_PARAM_TYPE_BOOL,
+QEMU_MIGRATION_PARAM_TYPE_STRING,
+} qemuMigrationParamType;
 
-bool compressThreads_set;
-int compressThreads;
-
-bool decompressThreads_set;
-int decompressThreads;
-
-bool cpuThrottleInitial_set;
-int cpuThrottleInitial;
-
-bool cpuThrottleIncrement_set;
-int cpuThrottleIncrement;
-
-/* Value is either NULL, "", or some string. NULL indicates no support;
- * whereas, some string value indicates we can support setting/clearing */
-char *tlsCreds;
-char *tlsHostname;
-
-bool maxBandwidth_set;
-unsigned long long maxBandwidth;
-
-bool downtimeLimit_set;
-unsigned long long downtimeLimit;
-
-bool blockIncremental_set;
-bool blockIncremental;
-
-bool xbzrleCacheSize_set;
-unsigned long long xbzrleCacheSize;
+typedef struct _qemuMigrationParamValue qemuMigrationParamValue;
+typedef qemuMigrationParamValue *qemuMigrationParamValuePtr;
+struct _qemuMigrationParamValue {
+bool set;
+union {
+int i; /* exempt from syntax-check */
+unsigned long long ull;
+bool b;
+char *s;
+} value;
 };
 
 struct _qemuMigrationParams {
 unsigned long long compMethods; /* bit-wise OR of 
qemuMigrationCompressMethod */
 virBitmapPtr caps;
-qemuMonitorMigrationParams params;
+qemuMigrationParamValue params[QEMU_MIGRATION_PARAM_LAST];
 };
 
 typedef enum {
@@ -92,6 +75,19 @@ VIR_ENUM_IMPL(qemuMigrationCompressMethod, 
QEMU_MIGRATION_COMPRESS_LAST,
   "mt",
 );
 
+VIR_ENUM_DECL(qemuMigrationParam)
+VIR_ENUM_IMPL(qemuMigrationParam, QEMU_MIGRATION_PARAM_LAST,
+  "compress-level",
+  "compress-threads",
+  "decompress-threads",
+  "cpu-throttle-initial",
+  "cpu-throttle-increment",
+  "tls-creds",
+  "tls-hostname",
+  "max-bandwidth",
+  "downtime-limit",
+  "block-incremental",
+  "xbzrle-cache-size");
 
 typedef struct _qemuMigrationParamsAlwaysOnItem 
qemuMigrationParamsAlwaysOnItem;
 struct _qemuMigrationParamsAlwaysOnItem {
@@ -128,6 +124,21 @@ static const qemuMigrationParamsFlagMapItem 
qemuMigrationParamsFlagMap[] = {
  QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION},
 };
 
+static const qemuMigrationParamType qemuMigrationParamTypes[] = {
+[QEMU_MIGRATION_PARAM_COMPRESS_LEVEL] = QEMU_MIGRATION_PARAM_TYPE_INT,
+[QEMU_MIGRATION_PARAM_COMPRESS_THREADS] = QEMU_MIGRATION_PARAM_TYPE_INT,
+[QEMU_MIGRATION_PARAM_DECOMPRESS_THREADS] = QEMU_MIGRATION_PARAM_TYPE_INT,
+[QEMU_MIGRATION_PARAM_THROTTLE_INITIAL] = QEMU_MIGRATION_PARAM_TYPE_INT,
+[QEMU_MIGRATION_PARAM_THROTTLE_INCREMENT] = QEMU_MIGRATION_PARAM_TYPE_INT,
+[QEMU_MIGRATION_PARAM_TLS_CREDS] = QEMU_MIGRATION_PARAM_TYPE_STRING,
+[QEMU_MIGRATION_PARAM_TLS_HOSTNAME] = QEMU_MIGRATION_PARAM_TYPE_STRING,
+[QEMU_MIGRATION_PARAM_MAX_BANDWIDTH] = QEMU_MIGRATION_PARAM_TYPE_ULL,
+[QEMU_MIGRATION_PARAM_DOWNTIME_LIMIT] = QEMU_MIGRATION_PARAM_TYPE_ULL,
+[QEMU_MIGRATION_PARAM_BLOCK_INCREMENTAL] = QEMU_MIGRATION_PARAM_TYPE_BOOL,
+[QEMU_MIGRATION_PARAM_XBZRLE_CACHE_SIZE] = QEMU_MIGRATION_PARAM_TYPE_ULL,
+};

[libvirt] [PATCH 68/68] qemuxml2xmltest: Add status XML tests for migration params

2018-04-04 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 .../migration-in-params-in.xml| 400 +
 .../migration-in-params-out.xml   |   1 +
 .../migration-out-params-in.xml   | 414 ++
 .../migration-out-params-out.xml  |   1 +
 tests/qemuxml2xmltest.c   |   2 +
 5 files changed, 818 insertions(+)
 create mode 100644 tests/qemustatusxml2xmldata/migration-in-params-in.xml
 create mode 12 tests/qemustatusxml2xmldata/migration-in-params-out.xml
 create mode 100644 tests/qemustatusxml2xmldata/migration-out-params-in.xml
 create mode 12 tests/qemustatusxml2xmldata/migration-out-params-out.xml

diff --git a/tests/qemustatusxml2xmldata/migration-in-params-in.xml 
b/tests/qemustatusxml2xmldata/migration-in-params-in.xml
new file mode 100644
index 00..b0caa34e61
--- /dev/null
+++ b/tests/qemustatusxml2xmldata/migration-in-params-in.xml
@@ -0,0 +1,400 @@
+
+  
+  
+  
+  
+
+  
+  
+
+
+  
+  
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+  
+  
+
+  
+  
+  
+  
+  
+  
+  
+  
+  
+  
+
+  
+  
+  
+  
+  
+  
+  
+nest
+994cee0d-2a70-4937-9693-0431e39d20f7
+virt-builder
+524288
+524288
+2
+
+  /machine
+
+
+  hvm
+  
+
+
+  
+  
+  
+
+
+
+  
+  
+  
+
+destroy
+restart
+restart
+
+  
+  
+
+
+  /usr/bin/qemu-kvm
+  
+
+
+
+
+
+
+
+  
+  
+
+
+  
+  
+
+
+
+  
+  
+
+
+
+  
+  
+
+
+
+  
+  
+
+
+  
+  
+
+  
+  
+
+
+
+  
+
+
+
+
+
+  
+  
+
+
+  
+
+
+  
+  
+
+
+
+  
+  
+
+
+
+
+  
+  
+
+
+
+  
+  
+
+
+  
+  
+
+  
+  
+
+  
+  
+
+
+  
+  
+
+
+
+  
+  
+
+
+  
+  
+
+
+  
+  
+
+
+  unconfined_u:unconfined_r:svirt_t:s0:c708,c793
+  unconfined_u:object_r:svirt_image_t:s0:c708,c793
+
+
+  +0:+0
+  +0:+0
+
+  
+
diff --git a/tests/qemustatusxml2xmldata/migration-in-params-out.xml 
b/tests/qemustatusxml2xmldata/migration-in-params-out.xml
new file mode 12
index 00..384747c5b1
--- /dev/null
+++ b/tests/qemustatusxml2xmldata/migration-in-params-out.xml
@@ -0,0 +1 @@
+migration-in-params-in.xml
\ No newline at end of file
diff --git a/tests/qemustatusxml2xmldata/migration-out-params-in.xml 
b/tests/qemustatusxml2xmldata/migration-out-params-in.xml
new file mode 100644
index 00..17649796ff
--- /dev/null
+++ b/tests/qemustatusxml2xmldata/migration-out-params-in.xml
@@ -0,0 +1,414 @@
+
+  
+  
+  
+  
+
+  
+  
+
+
+  
+  
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

[libvirt] [PATCH 63/68] qemu: Properly avoid cancelling memory-only dump

2018-04-04 Thread Jiri Denemark
migrate_cancel QMP command cannot be used for cancelling memory-only
dumps and priv->job.dump_memory_only is used for reporting an error if
someone calls virDomainAbortJob when memory-only dump job is running.

Since commit 150930e3098 the dump_memory_only flag is set only
dump-guest-memory command was called without the detach parameter. This
would incorrectly allow libvirt to send migrate_cancel while the
detached memory-only dump is running.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e15eb49a5c..b9927b727b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3794,12 +3794,12 @@ qemuDumpToFd(virQEMUDriverPtr driver,
 if (qemuSecuritySetImageFDLabel(driver->securityManager, vm->def, fd) < 0)
 return -1;
 
-if (detach) {
+priv->job.dump_memory_only = true;
+
+if (detach)
 priv->job.current->statsType = QEMU_DOMAIN_JOB_STATS_TYPE_MEMDUMP;
-} else {
+else
 VIR_FREE(priv->job.current);
-priv->job.dump_memory_only = true;
-}
 
 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
 return -1;
@@ -13472,7 +13472,7 @@ static int qemuDomainAbortJob(virDomainPtr dom)
 
 priv = vm->privateData;
 
-if (!priv->job.asyncJob || priv->job.dump_memory_only) {
+if (!priv->job.asyncJob) {
 virReportError(VIR_ERR_OPERATION_INVALID,
"%s", _("no job is active on the domain"));
 goto endjob;
@@ -13485,6 +13485,13 @@ static int qemuDomainAbortJob(virDomainPtr dom)
 goto endjob;
 }
 
+if (priv->job.asyncJob == QEMU_ASYNC_JOB_DUMP &&
+priv->job.dump_memory_only) {
+virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+   _("cannot abort memory-only dump"));
+goto endjob;
+}
+
 if (priv->job.asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT &&
 (priv->job.current->status == QEMU_DOMAIN_JOB_STATUS_POSTCOPY ||
  (virDomainObjGetState(vm, ) == VIR_DOMAIN_PAUSED &&
-- 
2.17.0

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


[libvirt] [PATCH 31/68] qemu: Move ParamsCheck closer to ParamsApply on Src side

2018-04-04 Thread Jiri Denemark
We reached the point when qemuMigrationParamsApply is the only API which
sends migration parameters and capabilities to QEMU. Thus all but the
TLS parameters can be set before we ask QEMU for the current values of
all parameters in qemuMigrationParamsCheck.

Supported migration capabilities are queried as soon as libvirt connects
to QEMU monitor so we can check them anytime.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c | 67 +++
 1 file changed, 32 insertions(+), 35 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 5f50795c16..6c736796b4 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3338,6 +3338,34 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 if (qemuMigrationSrcGraphicsRelocate(driver, vm, mig, graphicsuri) < 0)
 VIR_WARN("unable to provide data for graphics client relocation");
 
+if (qemuMigrationParamsSetCompression(vm, compression, migParams) < 0)
+goto error;
+
+if (qemuMigrationParamsSetCapability(vm,
+ 
QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
+ flags & VIR_MIGRATE_AUTO_CONVERGE,
+ migParams) < 0)
+goto error;
+
+if (qemuMigrationParamsSetCapability(vm,
+ 
QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
+ flags & VIR_MIGRATE_RDMA_PIN_ALL,
+ migParams) < 0)
+goto error;
+
+if (qemuMigrationParamsSetPostCopy(vm, flags & VIR_MIGRATE_POSTCOPY,
+   migParams) < 0)
+goto error;
+
+if (qemuMigrationCapsGet(vm, 
QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER) &&
+qemuMigrationParamsSetCapability(vm,
+ 
QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER,
+ true, migParams) < 0)
+goto error;
+
+if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+goto error;
+
 if (flags & VIR_MIGRATE_TLS) {
 const char *hostname = NULL;
 
@@ -3357,6 +3385,10 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 goto error;
 }
 
+if (qemuMigrationParamsApply(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
+ migParams) < 0)
+goto error;
+
 if (migrate_flags & (QEMU_MONITOR_MIGRATE_NON_SHARED_DISK |
  QEMU_MONITOR_MIGRATE_NON_SHARED_INC)) {
 if (mig->nbd) {
@@ -3385,35 +3417,6 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 goto error;
 }
 
-if (qemuMigrationParamsSetCompression(vm, compression, migParams) < 0)
-goto error;
-
-if (qemuMigrationParamsSetCapability(vm,
- 
QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
- flags & VIR_MIGRATE_AUTO_CONVERGE,
- migParams) < 0)
-goto error;
-
-if (qemuMigrationParamsSetCapability(vm,
- 
QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
- flags & VIR_MIGRATE_RDMA_PIN_ALL,
- migParams) < 0)
-goto error;
-
-if (qemuMigrationParamsSetPostCopy(vm, flags & VIR_MIGRATE_POSTCOPY,
-   migParams) < 0)
-goto error;
-
-if (qemuMigrationCapsGet(vm, 
QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER) &&
-qemuMigrationParamsSetCapability(vm,
- 
QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER,
- true, migParams) < 0)
-goto error;
-
-if (qemuMigrationParamsApply(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
- migParams) < 0)
-goto error;
-
 if (qemuDomainObjEnterMonitorAsync(driver, vm,
QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
 goto error;
@@ -4511,9 +4514,6 @@ qemuMigrationSrcPerformJob(virQEMUDriverPtr driver,
 
 qemuMigrationSrcStoreDomainState(vm);
 
-if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
-goto endjob;
-
 if ((flags & (VIR_MIGRATE_TUNNELLED | VIR_MIGRATE_PEER2PEER))) {
 ret = qemuMigrationSrcPerformPeer2Peer(driver, conn, vm, xmlin, 
persist_xml,
dconnuri, uri, graphicsuri, 
listenAddress,
@@ -4619,9 +4619,6 @@ qemuMigrationSrcPerformPhase(virQEMUDriverPtr driver,
 virCloseCallbacksUnset(driver->closeCallbacks, vm,
qemuMigrationSrcCleanup);
 
-if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
-goto 

[libvirt] [PATCH 32/68] qemu: Check supported caps in qemuMigrationParamsCheck

2018-04-04 Thread Jiri Denemark
Instead of checking each capability at the time we want to set it in
qemuMigrationParamsSetCapability we can check all of them at once in
qemuMigrationParamsCheck.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c|  6 --
 src/qemu/qemu_migration_params.c | 33 ++--
 src/qemu/qemu_migration_params.h |  3 ++-
 3 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 6c736796b4..a6b2597461 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2401,7 +2401,8 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
migParams) < 0)
 goto stopjob;
 
-if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
+if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
+ migParams) < 0)
 goto stopjob;
 
 /* Migrations using TLS need to add the "tls-creds-x509" object and
@@ -3363,7 +3364,8 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
  true, migParams) < 0)
 goto error;
 
-if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
+ migParams) < 0)
 goto error;
 
 if (flags & VIR_MIGRATE_TLS) {
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index ec1d2be6a0..862bab1af9 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -182,23 +182,11 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
 
 
 int
-qemuMigrationParamsSetCapability(virDomainObjPtr vm,
+qemuMigrationParamsSetCapability(virDomainObjPtr vm ATTRIBUTE_UNUSED,
  qemuMonitorMigrationCaps capability,
  bool state,
  qemuMigrationParamsPtr migParams)
 {
-if (!qemuMigrationCapsGet(vm, capability)) {
-if (!state) {
-/* Unsupported but we want it off anyway */
-return 0;
-}
-
-virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
-   _("Migration option '%s' is not supported by QEMU 
binary"),
-   qemuMonitorMigrationCapsTypeToString(capability));
-return -1;
-}
-
 if (state)
 ignore_value(virBitmapSetBit(migParams->caps, capability));
 else
@@ -413,16 +401,33 @@ qemuMigrationParamsResetTLS(virQEMUDriverPtr driver,
  *
  * Check supported migration parameters and keep their original values in
  * qemuDomainJobObj so that we can properly reset them at the end of migration.
+ * Reports an error if any of the currently used capabilities in @migParams
+ * are unsupported by QEMU.
  */
 int
 qemuMigrationParamsCheck(virQEMUDriverPtr driver,
  virDomainObjPtr vm,
- int asyncJob)
+ int asyncJob,
+ qemuMigrationParamsPtr migParams)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
 qemuMigrationParamsPtr origParams = NULL;
+qemuMonitorMigrationCaps cap;
 int ret = -1;
 
+for (cap = 0; cap < QEMU_MONITOR_MIGRATION_CAPS_LAST; cap++) {
+bool state = false;
+
+ignore_value(virBitmapGetBit(migParams->caps, cap, ));
+
+if (state && !qemuMigrationCapsGet(vm, cap)) {
+virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
+   _("Migration option '%s' is not supported by QEMU 
binary"),
+   qemuMonitorMigrationCapsTypeToString(cap));
+return -1;
+}
+}
+
 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
 return -1;
 
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 6cfac1f78f..292b30b8e7 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -101,7 +101,8 @@ qemuMigrationParamsSetCompression(virDomainObjPtr vm,
 int
 qemuMigrationParamsCheck(virQEMUDriverPtr driver,
  virDomainObjPtr vm,
- int asyncJob);
+ int asyncJob,
+ qemuMigrationParamsPtr migParams);
 
 void
 qemuMigrationParamsReset(virQEMUDriverPtr driver,
-- 
2.17.0

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


[libvirt] [PATCH 56/68] qemu: Set migration parameters automatically

2018-04-04 Thread Jiri Denemark
Most QEMU migration parameters directly correspond to
VIR_MIGRATE_PARAM_* typed parameters and qemuMigrationParamsFromFlags
can automatically set them according to a static mapping between libvirt
and QEMU parameters.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 135 ++-
 1 file changed, 80 insertions(+), 55 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 82e8aeedc6..6f3555bc63 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -102,6 +102,13 @@ struct _qemuMigrationParamsFlagMapItem {
 int party; /* bit-wise OR of qemuMigrationParty */
 };
 
+typedef struct _qemuMigrationParamsTPMapItem qemuMigrationParamsTPMapItem;
+struct _qemuMigrationParamsTPMapItem {
+const char *typedParam;
+qemuMigrationParam param;
+int party; /* bit-wise OR of qemuMigrationParty */
+};
+
 /* Migration capabilities which should always be enabled as long as they
  * are supported by QEMU. */
 static const qemuMigrationParamsAlwaysOnItem qemuMigrationParamsAlwaysOn[] = {
@@ -124,6 +131,34 @@ static const qemuMigrationParamsFlagMapItem 
qemuMigrationParamsFlagMap[] = {
  QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION},
 };
 
+/* Translation from VIR_MIGRATE_PARAM_* typed parameters to
+ * qemuMigrationParams. */
+static const qemuMigrationParamsTPMapItem qemuMigrationParamsTPMap[] = {
+{VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL,
+ QEMU_MIGRATION_PARAM_THROTTLE_INITIAL,
+ QEMU_MIGRATION_SOURCE},
+
+{VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT,
+ QEMU_MIGRATION_PARAM_THROTTLE_INCREMENT,
+ QEMU_MIGRATION_SOURCE},
+
+{VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL,
+ QEMU_MIGRATION_PARAM_COMPRESS_LEVEL,
+ QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION},
+
+{VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS,
+ QEMU_MIGRATION_PARAM_COMPRESS_THREADS,
+ QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION},
+
+{VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS,
+ QEMU_MIGRATION_PARAM_DECOMPRESS_THREADS,
+ QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION},
+
+{VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE,
+ QEMU_MIGRATION_PARAM_XBZRLE_CACHE_SIZE,
+ QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION},
+};
+
 static const qemuMigrationParamType qemuMigrationParamTypes[] = {
 [QEMU_MIGRATION_PARAM_COMPRESS_LEVEL] = QEMU_MIGRATION_PARAM_TYPE_INT,
 [QEMU_MIGRATION_PARAM_COMPRESS_THREADS] = QEMU_MIGRATION_PARAM_TYPE_INT,
@@ -326,30 +361,6 @@ qemuMigrationParamsSetCompression(virTypedParameterPtr 
params,
 ignore_value(virBitmapSetBit(migParams->caps, cap));
 }
 
-if (qemuMigrationParamsGetTPInt(migParams,
-QEMU_MIGRATION_PARAM_COMPRESS_LEVEL,
-params, nparams,
-VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL) < 
0)
-goto error;
-
-if (qemuMigrationParamsGetTPInt(migParams,
-QEMU_MIGRATION_PARAM_COMPRESS_THREADS,
-params, nparams,
-VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS) 
< 0)
-goto error;
-
-if (qemuMigrationParamsGetTPInt(migParams,
-QEMU_MIGRATION_PARAM_DECOMPRESS_THREADS,
-params, nparams,
-VIR_MIGRATE_PARAM_COMPRESSION_MT_DTHREADS) 
< 0)
-goto error;
-
-if (qemuMigrationParamsGetTPULL(migParams,
-QEMU_MIGRATION_PARAM_XBZRLE_CACHE_SIZE,
-params, nparams,
-
VIR_MIGRATE_PARAM_COMPRESSION_XBZRLE_CACHE) < 0)
-goto error;
-
 if ((migParams->params[QEMU_MIGRATION_PARAM_COMPRESS_LEVEL].set ||
  migParams->params[QEMU_MIGRATION_PARAM_COMPRESS_THREADS].set ||
  migParams->params[QEMU_MIGRATION_PARAM_DECOMPRESS_THREADS].set) &&
@@ -399,18 +410,29 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
 }
 }
 
-if (party == QEMU_MIGRATION_SOURCE) {
-if (qemuMigrationParamsGetTPInt(migParams,
-QEMU_MIGRATION_PARAM_THROTTLE_INITIAL,
-params, nparams,
-
VIR_MIGRATE_PARAM_AUTO_CONVERGE_INITIAL) < 0)
-goto error;
+for (i = 0; i < ARRAY_CARDINALITY(qemuMigrationParamsTPMap); i++) {
+const qemuMigrationParamsTPMapItem *item = 
[i];
 
-if (qemuMigrationParamsGetTPInt(migParams,
-
QEMU_MIGRATION_PARAM_THROTTLE_INCREMENT,
-params, nparams,
-
VIR_MIGRATE_PARAM_AUTO_CONVERGE_INCREMENT) < 0)
-goto error;
+if 

[libvirt] [PATCH 02/68] qemu: Rename qemuMigrationAnyCapsGet as qemuMigrationCapsGet

2018-04-04 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c|  4 ++--
 src/qemu/qemu_migration.c | 10 +-
 src/qemu/qemu_migration.h |  4 ++--
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5c31dfdd58..cc431ae045 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13615,7 +13615,7 @@ qemuDomainMigrateGetCompressionCache(virDomainPtr dom,
 
 priv = vm->privateData;
 
-if (!qemuMigrationAnyCapsGet(vm, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE)) {
+if (!qemuMigrationCapsGet(vm, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE)) {
 virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("Compressed migration is not supported by "
  "QEMU binary"));
@@ -13666,7 +13666,7 @@ qemuDomainMigrateSetCompressionCache(virDomainPtr dom,
 
 priv = vm->privateData;
 
-if (!qemuMigrationAnyCapsGet(vm, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE)) {
+if (!qemuMigrationCapsGet(vm, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE)) {
 virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("Compressed migration is not supported by "
  "QEMU binary"));
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index a2a6616862..cc664c20d6 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1335,7 +1335,7 @@ qemuMigrationOptionSet(virQEMUDriverPtr driver,
 qemuDomainObjPrivatePtr priv = vm->privateData;
 int ret;
 
-if (!qemuMigrationAnyCapsGet(vm, capability)) {
+if (!qemuMigrationCapsGet(vm, capability)) {
 if (!state) {
 /* Unsupported but we want it off anyway */
 return 0;
@@ -3872,7 +3872,7 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
 goto error;
 
-if (qemuMigrationAnyCapsGet(vm, 
QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER) &&
+if (qemuMigrationCapsGet(vm, 
QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER) &&
 qemuMigrationOptionSet(driver, vm,

QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER,
true, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
@@ -6098,7 +6098,7 @@ qemuMigrationParamsReset(virQEMUDriverPtr driver,
 goto cleanup;
 
 for (cap = 0; cap < QEMU_MONITOR_MIGRATION_CAPS_LAST; cap++) {
-if (qemuMigrationAnyCapsGet(vm, cap) &&
+if (qemuMigrationCapsGet(vm, cap) &&
 qemuMigrationOptionSet(driver, vm, cap, false, job) < 0)
 goto cleanup;
 }
@@ -6235,8 +6235,8 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
 
 
 bool
-qemuMigrationAnyCapsGet(virDomainObjPtr vm,
-qemuMonitorMigrationCaps cap)
+qemuMigrationCapsGet(virDomainObjPtr vm,
+ qemuMonitorMigrationCaps cap)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
 bool enabled = false;
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 3dca8a1889..cccbf12652 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -315,7 +315,7 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
qemuDomainAsyncJob asyncJob);
 
 bool
-qemuMigrationAnyCapsGet(virDomainObjPtr vm,
-qemuMonitorMigrationCaps cap);
+qemuMigrationCapsGet(virDomainObjPtr vm,
+ qemuMonitorMigrationCaps cap);
 
 #endif /* __QEMU_MIGRATION_H__ */
-- 
2.17.0

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


[libvirt] [PATCH 48/68] qemu: Limit usage of qemuMonitorMigrationParams

2018-04-04 Thread Jiri Denemark
Use this internal structure only in qemu_migration_params.c and change
other non-test users to use the high level qemuMigrationParams struct.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c   | 26 +++---
 src/qemu/qemu_migration_params.c | 16 
 src/qemu/qemu_migration_params.h |  4 
 3 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8e880280ec..761f84ee7f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13555,8 +13555,7 @@ qemuDomainMigrateGetMaxDowntime(virDomainPtr dom,
 {
 virQEMUDriverPtr driver = dom->conn->privateData;
 virDomainObjPtr vm;
-qemuDomainObjPrivatePtr priv;
-qemuMonitorMigrationParams migparams = { 0 };
+qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
 
 virCheckFlags(0, -1);
@@ -13576,27 +13575,24 @@ qemuDomainMigrateGetMaxDowntime(virDomainPtr dom,
 goto endjob;
 }
 
-priv = vm->privateData;
-qemuDomainObjEnterMonitor(driver, vm);
+if (qemuMigrationParamsFetch(driver, vm, QEMU_ASYNC_JOB_NONE,
+ ) < 0)
+goto endjob;
 
-if (qemuMonitorGetMigrationParams(priv->mon, ) == 0) {
-if (migparams.downtimeLimit_set) {
-*downtime = migparams.downtimeLimit;
-ret = 0;
-} else {
-virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-   _("Querying migration downtime is not supported by "
- "QEMU binary"));
-}
+if (qemuMigrationParamsGetDowntimeLimit(migParams, downtime) == 1) {
+virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+   _("Querying migration downtime is not supported by "
+ "QEMU binary"));
+goto endjob;
 }
 
-if (qemuDomainObjExitMonitor(driver, vm) < 0)
-ret = -1;
+ret = 0;
 
  endjob:
 qemuDomainObjEndJob(driver, vm);
 
  cleanup:
+qemuMigrationParamsFree(migParams);
 virDomainObjEndAPI();
 return ret;
 }
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 642e4f314c..fd93d9cb39 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -550,6 +550,22 @@ qemuMigrationParamsFetch(virQEMUDriverPtr driver,
 }
 
 
+/**
+ * Returns  0 on success,
+ *  1 if the parameter is not supported by QEMU.
+ */
+int
+qemuMigrationParamsGetDowntimeLimit(qemuMigrationParamsPtr migParams,
+unsigned long long *value)
+{
+if (!migParams->params.downtimeLimit_set)
+return 1;
+
+*value = migParams->params.downtimeLimit;
+return 0;
+}
+
+
 /**
  * qemuMigrationParamsCheck:
  *
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index cabf4cebe6..9fcd9825c8 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -79,6 +79,10 @@ qemuMigrationParamsFetch(virQEMUDriverPtr driver,
  int asyncJob,
  qemuMigrationParamsPtr *migParams);
 
+int
+qemuMigrationParamsGetDowntimeLimit(qemuMigrationParamsPtr migParams,
+unsigned long long *value);
+
 int
 qemuMigrationParamsCheck(virQEMUDriverPtr driver,
  virDomainObjPtr vm,
-- 
2.17.0

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


[libvirt] [PATCH 35/68] qemu: Hide qemuMigrationParamsNew

2018-04-04 Thread Jiri Denemark
It is no longer used outside qemu_migration_params.c.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 2 +-
 src/qemu/qemu_migration_params.h | 3 ---
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 72e4e660b7..c79ea4fa91 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -44,7 +44,7 @@ struct _qemuMigrationParams {
 };
 
 
-qemuMigrationParamsPtr
+static qemuMigrationParamsPtr
 qemuMigrationParamsNew(void)
 {
 qemuMigrationParamsPtr params;
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 062e6f37a9..3620a4e36e 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -56,9 +56,6 @@ typedef enum {
 } qemuMigrationParty;
 
 
-qemuMigrationParamsPtr
-qemuMigrationParamsNew(void);
-
 qemuMigrationParamsPtr
 qemuMigrationParamsFromFlags(virTypedParameterPtr params,
  int nparams,
-- 
2.17.0

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


[libvirt] [PATCH 20/68] qemu: Set tlsHostname inside qemuMigrationParamsEnableTLS

2018-04-04 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c| 31 ---
 src/qemu/qemu_migration_params.c |  9 +++--
 src/qemu/qemu_migration_params.h |  1 +
 3 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 254239b18b..fe2fae8fba 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2457,13 +2457,9 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 cfg = virQEMUDriverGetConfig(driver);
 if (qemuMigrationParamsEnableTLS(driver, vm, cfg, true,
  QEMU_ASYNC_JOB_MIGRATION_IN,
- , , migParams) < 0)
+ , , NULL,
+ migParams) < 0)
 goto stopjob;
-
-/* Force reset of 'tls-hostname', it's a source only parameter */
-if (VIR_STRDUP(migParams->params.tlsHostname, "") < 0)
-goto stopjob;
-
 } else {
 if (qemuMigrationParamsDisableTLS(vm, migParams) < 0)
 goto stopjob;
@@ -3409,23 +3405,20 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 VIR_WARN("unable to provide data for graphics client relocation");
 
 if (flags & VIR_MIGRATE_TLS) {
-cfg = virQEMUDriverGetConfig(driver);
-if (qemuMigrationParamsEnableTLS(driver, vm, cfg, false,
- QEMU_ASYNC_JOB_MIGRATION_OUT,
- , , migParams) < 0)
-goto error;
+const char *hostname = NULL;
 
 /* We need to add tls-hostname whenever QEMU itself does not
  * connect directly to the destination. */
 if (spec->destType == MIGRATION_DEST_CONNECT_HOST ||
-spec->destType == MIGRATION_DEST_FD) {
-if (VIR_STRDUP(migParams->params.tlsHostname, 
spec->dest.host.name) < 0)
-goto error;
-} else {
-/* Be sure there's nothing from a previous migration */
-if (VIR_STRDUP(migParams->params.tlsHostname, "") < 0)
-goto error;
-}
+spec->destType == MIGRATION_DEST_FD)
+hostname = spec->dest.host.name;
+
+cfg = virQEMUDriverGetConfig(driver);
+if (qemuMigrationParamsEnableTLS(driver, vm, cfg, false,
+ QEMU_ASYNC_JOB_MIGRATION_OUT,
+ , , hostname,
+ migParams) < 0)
+goto error;
 } else {
 if (qemuMigrationParamsDisableTLS(vm, migParams) < 0)
 goto error;
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index a03239e2a2..812c35e13e 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -141,9 +141,12 @@ qemuMigrationParamsSet(virQEMUDriverPtr driver,
  * @asyncJob: Migration job to join
  * @tlsAlias: alias to be generated for TLS object
  * @secAlias: alias to be generated for a secinfo object
+ * @hostname: hostname of the migration destination
  * @migParams: migration parameters to set
  *
- * Create the TLS objects for the migration and set the migParams value
+ * Create the TLS objects for the migration and set the migParams value.
+ * If QEMU itself does not connect to the destination @hostname must be
+ * provided for certificate verification.
  *
  * Returns 0 on success, -1 on failure
  */
@@ -155,6 +158,7 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
  int asyncJob,
  char **tlsAlias,
  char **secAlias,
+ const char *hostname,
  qemuMigrationParamsPtr migParams)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
@@ -198,7 +202,8 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
 *tlsAlias, ) < 0)
 goto error;
 
-if (VIR_STRDUP(migParams->params.tlsCreds, *tlsAlias) < 0)
+if (VIR_STRDUP(migParams->params.tlsCreds, *tlsAlias) < 0 ||
+VIR_STRDUP(migParams->params.tlsHostname, hostname ? hostname : "") < 
0)
 goto error;
 
 return 0;
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 8aa6136508..2955bf7436 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -79,6 +79,7 @@ qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
  int asyncJob,
  char **tlsAlias,
  char **secAlias,
+ const char *hostname,
  qemuMigrationParamsPtr migParams);
 
 int
-- 
2.17.0

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


[libvirt] [PATCH 29/68] qemu: Set XBZRLE cache size via migration parameters

2018-04-04 Thread Jiri Denemark
Prefer xbzrle-cache-size migration parameter over the special
migrate-set-cache-size QMP command.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c|  6 ++---
 src/qemu/qemu_migration_params.c | 42 +---
 src/qemu/qemu_migration_params.h |  4 +--
 3 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 6b0c7545a1..9758d20d99 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2386,8 +2386,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
 goto stopjob;
 
-if (qemuMigrationParamsSetCompression(driver, vm, 
QEMU_ASYNC_JOB_MIGRATION_IN,
-  compression, migParams) < 0)
+if (qemuMigrationParamsSetCompression(vm, compression, migParams) < 0)
 goto stopjob;
 
 /* Migrations using TLS need to add the "tls-creds-x509" object and
@@ -3386,8 +3385,7 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 goto error;
 }
 
-if (qemuMigrationParamsSetCompression(driver, vm, 
QEMU_ASYNC_JOB_MIGRATION_OUT,
-  compression, migParams) < 0)
+if (qemuMigrationParamsSetCompression(vm, compression, migParams) < 0)
 goto error;
 
 if (qemuMigrationParamsSetCapability(vm,
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 83d3247017..ec1d2be6a0 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -141,6 +141,7 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
  qemuMigrationParamsPtr migParams)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
+bool xbzrleCacheSize_old = false;
 int ret = -1;
 
 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
@@ -150,6 +151,20 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
 migParams->caps) < 0)
 goto cleanup;
 
+/* If QEMU is too old to support xbzrle-cache-size migration parameter,
+ * we need to set it via migrate-set-cache-size and tell
+ * qemuMonitorSetMigrationParams to ignore this parameter.
+ */
+if (migParams->params.xbzrleCacheSize_set &&
+(!priv->job.migParams ||
+ !priv->job.migParams->params.xbzrleCacheSize_set)) {
+if (qemuMonitorSetMigrationCacheSize(priv->mon,
+ 
migParams->params.xbzrleCacheSize) < 0)
+goto cleanup;
+xbzrleCacheSize_old = true;
+migParams->params.xbzrleCacheSize_set = false;
+}
+
 if (qemuMonitorSetMigrationParams(priv->mon, >params) < 0)
 goto cleanup;
 
@@ -159,6 +174,9 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
 if (qemuDomainObjExitMonitor(driver, vm) < 0)
 ret = -1;
 
+if (xbzrleCacheSize_old)
+migParams->params.xbzrleCacheSize_set = true;
+
 return ret;
 }
 
@@ -321,15 +339,10 @@ qemuMigrationParamsDisableTLS(virDomainObjPtr vm,
 
 
 int
-qemuMigrationParamsSetCompression(virQEMUDriverPtr driver,
-  virDomainObjPtr vm,
-  int asyncJob,
+qemuMigrationParamsSetCompression(virDomainObjPtr vm,
   qemuMigrationCompressionPtr compression,
   qemuMigrationParamsPtr migParams)
 {
-int ret = -1;
-qemuDomainObjPrivatePtr priv = vm->privateData;
-
 if (qemuMigrationParamsSetCapability(vm,
  QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
  compression->methods &
@@ -344,9 +357,6 @@ qemuMigrationParamsSetCompression(virQEMUDriverPtr driver,
  migParams) < 0)
 return -1;
 
-if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
-return -1;
-
 migParams->params.compressLevel_set = compression->level_set;
 migParams->params.compressLevel = compression->level;
 
@@ -356,18 +366,10 @@ qemuMigrationParamsSetCompression(virQEMUDriverPtr driver,
 migParams->params.decompressThreads_set = compression->dthreads_set;
 migParams->params.decompressThreads = compression->dthreads;
 
-if (compression->xbzrle_cache_set &&
-qemuMonitorSetMigrationCacheSize(priv->mon,
- compression->xbzrle_cache) < 0)
-goto cleanup;
+migParams->params.xbzrleCacheSize_set = compression->xbzrle_cache_set;
+migParams->params.xbzrleCacheSize = compression->xbzrle_cache;
 
-ret = 0;
-
- cleanup:
-if (qemuDomainObjExitMonitor(driver, vm) < 0)
-ret = -1;
-
-return ret;
+return 0;
 }
 
 
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index e881ee202d..6cfac1f78f 100644
--- 

[libvirt] [PATCH 30/68] qemu: Move ParamsCheck closer to ParamsApply on Dst side

2018-04-04 Thread Jiri Denemark
We reached the point when qemuMigrationParamsApply is the only API which
sends migration parameters and capabilities to QEMU. Thus all but the
TLS parameters can be set before we ask QEMU for the current values of
all parameters in qemuMigrationParamsCheck.

Supported migration capabilities are queried as soon as libvirt connects
to QEMU monitor so we can check them anytime.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c | 32 
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 9758d20d99..5f50795c16 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2383,25 +2383,9 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 dataFD[1] = -1; /* 'st' owns the FD now & will close it */
 }
 
-if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
-goto stopjob;
-
 if (qemuMigrationParamsSetCompression(vm, compression, migParams) < 0)
 goto stopjob;
 
-/* Migrations using TLS need to add the "tls-creds-x509" object and
- * set the migration TLS parameters */
-if (flags & VIR_MIGRATE_TLS) {
-if (qemuMigrationParamsEnableTLS(driver, vm, true,
- QEMU_ASYNC_JOB_MIGRATION_IN,
- , , NULL,
- migParams) < 0)
-goto stopjob;
-} else {
-if (qemuMigrationParamsDisableTLS(vm, migParams) < 0)
-goto stopjob;
-}
-
 if (STREQ_NULLABLE(protocol, "rdma") &&
 virProcessSetMaxMemLock(vm->pid, vm->def->mem.hard_limit << 10) < 0) {
 goto stopjob;
@@ -2417,6 +2401,22 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
migParams) < 0)
 goto stopjob;
 
+if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
+goto stopjob;
+
+/* Migrations using TLS need to add the "tls-creds-x509" object and
+ * set the migration TLS parameters */
+if (flags & VIR_MIGRATE_TLS) {
+if (qemuMigrationParamsEnableTLS(driver, vm, true,
+ QEMU_ASYNC_JOB_MIGRATION_IN,
+ , , NULL,
+ migParams) < 0)
+goto stopjob;
+} else {
+if (qemuMigrationParamsDisableTLS(vm, migParams) < 0)
+goto stopjob;
+}
+
 if (qemuMigrationParamsApply(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
  migParams) < 0)
 goto stopjob;
-- 
2.17.0

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


[libvirt] [PATCH 03/68] qemu: Rename qemuMigrationParams

2018-04-04 Thread Jiri Denemark
The function is now called qemuMigrationParamsFromFlags to better
reflect what it is doing: taking migration flags and params and
producing a struct with QEMU migration parameters.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c| 2 +-
 src/qemu/qemu_migration.c | 6 +++---
 src/qemu/qemu_migration.h | 6 +++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index cc431ae045..f7ad211077 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12758,7 +12758,7 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
 if (nmigrate_disks < 0)
 goto cleanup;
 
-if (!(migParams = qemuMigrationParams(params, nparams, flags)))
+if (!(migParams = qemuMigrationParamsFromFlags(params, nparams, flags)))
 goto cleanup;
 
 if (!(compression = qemuMigrationAnyCompressionParse(params, nparams, 
flags)))
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index cc664c20d6..f88ac02f2f 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2474,9 +2474,9 @@ qemuMigrationParamsSetEmptyTLS(virQEMUDriverPtr driver,
 
 
 qemuMonitorMigrationParamsPtr
-qemuMigrationParams(virTypedParameterPtr params,
-int nparams,
-unsigned long flags)
+qemuMigrationParamsFromFlags(virTypedParameterPtr params,
+ int nparams,
+ unsigned long flags)
 {
 qemuMonitorMigrationParamsPtr migParams;
 
diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index cccbf12652..b9f7369784 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -144,9 +144,9 @@ void
 qemuMigrationParamsFree(qemuMonitorMigrationParamsPtr *migParams);
 
 qemuMonitorMigrationParamsPtr
-qemuMigrationParams(virTypedParameterPtr params,
-int nparams,
-unsigned long flags);
+qemuMigrationParamsFromFlags(virTypedParameterPtr params,
+ int nparams,
+ unsigned long flags);
 
 int
 qemuMigrationSrcSetOffline(virQEMUDriverPtr driver,
-- 
2.17.0

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


[libvirt] [PATCH 55/68] qemu: Generalize qemuMigrationParamsGetDowntimeLimit

2018-04-04 Thread Jiri Denemark
The API is renamed as qemuMigrationParamsGetULL and it can be used with
any migration parameter stored as unsigned long long.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c   |  9 -
 src/qemu/qemu_migration_params.c | 15 ++-
 src/qemu/qemu_migration_params.h |  5 +++--
 3 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 761f84ee7f..93dec7c2ce 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13557,6 +13557,7 @@ qemuDomainMigrateGetMaxDowntime(virDomainPtr dom,
 virDomainObjPtr vm;
 qemuMigrationParamsPtr migParams = NULL;
 int ret = -1;
+int rc;
 
 virCheckFlags(0, -1);
 
@@ -13579,7 +13580,13 @@ qemuDomainMigrateGetMaxDowntime(virDomainPtr dom,
  ) < 0)
 goto endjob;
 
-if (qemuMigrationParamsGetDowntimeLimit(migParams, downtime) == 1) {
+if ((rc = qemuMigrationParamsGetULL(migParams,
+QEMU_MIGRATION_PARAM_DOWNTIME_LIMIT,
+downtime)) < 0) {
+goto endjob;
+}
+
+if (rc == 1) {
 virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("Querying migration downtime is not supported by "
  "QEMU binary"));
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 50f69ee571..82e8aeedc6 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -856,17 +856,22 @@ qemuMigrationParamsSetString(qemuMigrationParamsPtr 
migParams,
 
 
 /**
- * Returns  0 on success,
+ * Returns -1 on error,
+ *  0 on success,
  *  1 if the parameter is not supported by QEMU.
  */
 int
-qemuMigrationParamsGetDowntimeLimit(qemuMigrationParamsPtr migParams,
-unsigned long long *value)
+qemuMigrationParamsGetULL(qemuMigrationParamsPtr migParams,
+  qemuMigrationParam param,
+  unsigned long long *value)
 {
-if (!migParams->params[QEMU_MIGRATION_PARAM_DOWNTIME_LIMIT].set)
+if (qemuMigrationParamsCheckType(param, QEMU_MIGRATION_PARAM_TYPE_ULL) < 0)
+return -1;
+
+if (!migParams->params[param].set)
 return 1;
 
-*value = migParams->params[QEMU_MIGRATION_PARAM_DOWNTIME_LIMIT].value.ull;
+*value = migParams->params[param].value.ull;
 return 0;
 }
 
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index c354c35d29..1540d72acb 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -100,8 +100,9 @@ qemuMigrationParamsSetString(qemuMigrationParamsPtr 
migParams,
  const char *value);
 
 int
-qemuMigrationParamsGetDowntimeLimit(qemuMigrationParamsPtr migParams,
-unsigned long long *value);
+qemuMigrationParamsGetULL(qemuMigrationParamsPtr migParams,
+  qemuMigrationParam param,
+  unsigned long long *value);
 
 int
 qemuMigrationParamsCheck(virQEMUDriverPtr driver,
-- 
2.17.0

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


[libvirt] [PATCH 16/68] qemu: Drop qemuMigrationParamsCheckSetupTLS

2018-04-04 Thread Jiri Denemark
The code can be merged directly in qemuMigrationParamsAddTLSObjects.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c| 15 ---
 src/qemu/qemu_migration_params.c | 73 ++--
 src/qemu/qemu_migration_params.h |  6 ---
 3 files changed, 23 insertions(+), 71 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 3c25e0e27f..072a5c95ae 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2045,7 +2045,6 @@ qemuMigrationSrcBegin(virConnectPtr conn,
   unsigned long flags)
 {
 virQEMUDriverPtr driver = conn->privateData;
-virQEMUDriverConfigPtr cfg = NULL;
 char *xml = NULL;
 qemuDomainAsyncJob asyncJob;
 
@@ -2079,12 +2078,6 @@ qemuMigrationSrcBegin(virConnectPtr conn,
nmigrate_disks, migrate_disks, 
flags)))
 goto endjob;
 
-if (flags & VIR_MIGRATE_TLS) {
-cfg = virQEMUDriverGetConfig(driver);
-if (qemuMigrationParamsCheckSetupTLS(driver, cfg, vm, asyncJob) < 0)
-goto endjob;
-}
-
 if ((flags & VIR_MIGRATE_CHANGE_PROTECTION)) {
 /* We keep the job active across API calls until the confirm() call.
  * This prevents any other APIs being invoked while migration is taking
@@ -2101,7 +2094,6 @@ qemuMigrationSrcBegin(virConnectPtr conn,
 }
 
  cleanup:
-virObjectUnref(cfg);
 virDomainObjEndAPI();
 return xml;
 
@@ -2463,10 +2455,6 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
  * set the migration TLS parameters */
 if (flags & VIR_MIGRATE_TLS) {
 cfg = virQEMUDriverGetConfig(driver);
-if (qemuMigrationParamsCheckSetupTLS(driver, cfg, vm,
- QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
-goto stopjob;
-
 if (qemuMigrationParamsAddTLSObjects(driver, vm, cfg, true,
  QEMU_ASYNC_JOB_MIGRATION_IN,
  , , migParams) 
< 0)
@@ -3424,9 +3412,6 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 
 if (flags & VIR_MIGRATE_TLS) {
 cfg = virQEMUDriverGetConfig(driver);
-
-/* Begin/CheckSetupTLS already set up migTLSAlias, the following
- * assumes that and adds the TLS objects to the domain. */
 if (qemuMigrationParamsAddTLSObjects(driver, vm, cfg, false,
  QEMU_ASYNC_JOB_MIGRATION_OUT,
  , , migParams) 
< 0)
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 43098de904..bee7d9796f 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -179,56 +179,6 @@ qemuMigrationParamsCheckTLSCreds(virQEMUDriverPtr driver,
 }
 
 
-/* qemuMigrationParamsCheckSetupTLS
- * @driver: pointer to qemu driver
- * @vm: domain object
- * @cfg: configuration pointer
- * @asyncJob: migration job to join
- *
- * Check if TLS is possible and set up the environment. Assumes the caller
- * desires to use TLS (e.g. caller found VIR_MIGRATE_TLS flag).
- *
- * Ensure the qemu.conf has been properly configured to add an entry for
- * "migrate_tls_x509_cert_dir". Also check if the "tls-creds" parameter
- * was present from a query of migration parameters
- *
- * Returns 0 on success, -1 on error/failure
- */
-int
-qemuMigrationParamsCheckSetupTLS(virQEMUDriverPtr driver,
- virQEMUDriverConfigPtr cfg,
- virDomainObjPtr vm,
- int asyncJob)
-{
-qemuDomainObjPrivatePtr priv = vm->privateData;
-
-if (!cfg->migrateTLSx509certdir) {
-virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-   _("host migration TLS directory not configured"));
-return -1;
-}
-
-if (qemuMigrationParamsCheckTLSCreds(driver, vm, asyncJob) < 0)
-return -1;
-
-if (!priv->migTLSAlias) {
-virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
-   _("TLS migration is not supported with this "
- "QEMU binary"));
-return -1;
-}
-
-/* If there's a secret, then grab/store it now using the connection */
-if (cfg->migrateTLSx509secretUUID &&
-!(priv->migSecinfo =
-  qemuDomainSecretInfoTLSNew(priv, QEMU_MIGRATION_TLS_ALIAS_BASE,
- cfg->migrateTLSx509secretUUID)))
-return -1;
-
-return 0;
-}
-
-
 /* qemuMigrationParamsAddTLSObjects
  * @driver: pointer to qemu driver
  * @vm: domain object
@@ -257,6 +207,29 @@ qemuMigrationParamsAddTLSObjects(virQEMUDriverPtr driver,
 virJSONValuePtr tlsProps = NULL;
 virJSONValuePtr secProps = NULL;
 
+if (!cfg->migrateTLSx509certdir) {
+virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+   _("host migration TLS 

[libvirt] [PATCH 38/68] qemu: Set migration capabilities automatically

2018-04-04 Thread Jiri Denemark
Most migration capabilities are directly connected with
virDomainMigrateFlags so qemuMigrationParamsFromFlags can automatically
enable them.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c| 30 ---
 src/qemu/qemu_migration_params.c | 42 +++-
 src/qemu/qemu_migration_params.h |  6 -
 3 files changed, 36 insertions(+), 42 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index bb8f506659..1c614f8c0d 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2388,18 +2388,6 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 goto stopjob;
 }
 
-if (qemuMigrationParamsSetCapability(vm,
- 
QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
- flags & VIR_MIGRATE_RDMA_PIN_ALL,
- migParams) < 0)
-goto stopjob;
-
-if (qemuMigrationParamsSetCapability(vm,
- QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
- flags & VIR_MIGRATE_POSTCOPY,
- migParams) < 0)
-goto stopjob;
-
 if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
  migParams) < 0)
 goto stopjob;
@@ -3344,24 +3332,6 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 if (qemuMigrationParamsSetCompression(vm, compression, migParams) < 0)
 goto error;
 
-if (qemuMigrationParamsSetCapability(vm,
- 
QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
- flags & VIR_MIGRATE_AUTO_CONVERGE,
- migParams) < 0)
-goto error;
-
-if (qemuMigrationParamsSetCapability(vm,
- 
QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
- flags & VIR_MIGRATE_RDMA_PIN_ALL,
- migParams) < 0)
-goto error;
-
-if (qemuMigrationParamsSetCapability(vm,
- QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
- flags & VIR_MIGRATE_POSTCOPY,
- migParams) < 0)
-goto error;
-
 if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
  migParams) < 0)
 goto error;
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 3837bf5b68..9d2ac6bee5 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -49,6 +49,13 @@ struct _qemuMigrationParamsAlwaysOnItem {
 int party; /* bit-wise OR of qemuMigrationParty */
 };
 
+typedef struct _qemuMigrationParamsFlagMapItem qemuMigrationParamsFlagMapItem;
+struct _qemuMigrationParamsFlagMapItem {
+virDomainMigrateFlags flag;
+qemuMonitorMigrationCaps cap;
+int party; /* bit-wise OR of qemuMigrationParty */
+};
+
 /* Migration capabilities which should always be enabled as long as they
  * are supported by QEMU. */
 static const qemuMigrationParamsAlwaysOnItem qemuMigrationParamsAlwaysOn[] = {
@@ -56,6 +63,21 @@ static const qemuMigrationParamsAlwaysOnItem 
qemuMigrationParamsAlwaysOn[] = {
  QEMU_MIGRATION_SOURCE},
 };
 
+/* Translation from virDomainMigrateFlags to qemuMonitorMigrationCaps. */
+static const qemuMigrationParamsFlagMapItem qemuMigrationParamsFlagMap[] = {
+{VIR_MIGRATE_RDMA_PIN_ALL,
+ QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
+ QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION},
+
+{VIR_MIGRATE_AUTO_CONVERGE,
+ QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
+ QEMU_MIGRATION_SOURCE},
+
+{VIR_MIGRATE_POSTCOPY,
+ QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
+ QEMU_MIGRATION_SOURCE | QEMU_MIGRATION_DESTINATION},
+};
+
 
 static qemuMigrationParamsPtr
 qemuMigrationParamsNew(void)
@@ -97,12 +119,18 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
  qemuMigrationParty party)
 {
 qemuMigrationParamsPtr migParams;
+size_t i;
 
 if (!(migParams = qemuMigrationParamsNew()))
 return NULL;
 
-if (!params)
-return migParams;
+for (i = 0; i < ARRAY_CARDINALITY(qemuMigrationParamsFlagMap); i++) {
+if (qemuMigrationParamsFlagMap[i].party & party &&
+flags & qemuMigrationParamsFlagMap[i].flag) {
+ignore_value(virBitmapSetBit(migParams->caps,
+ qemuMigrationParamsFlagMap[i].cap));
+}
+}
 
 #define GET(PARAM, VAR) \
 do { \
@@ -116,9 +144,11 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
 migParams->params.VAR ## _set = true; \
 } while (0)
 
-if (party == QEMU_MIGRATION_SOURCE) {
-

[libvirt] [PATCH 53/68] qemu: Move qemuMonitorMigrationParams structure

2018-04-04 Thread Jiri Denemark
It's no longer used by the monitor code so we can hide it inside
qemu_migration_params.c.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 36 
 src/qemu/qemu_monitor.h  | 36 
 2 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 0c8e44f644..9f091ec693 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -38,6 +38,42 @@ VIR_LOG_INIT("qemu.qemu_migration_params");
 
 #define QEMU_MIGRATION_TLS_ALIAS_BASE "libvirt_migrate"
 
+typedef struct _qemuMonitorMigrationParams qemuMonitorMigrationParams;
+typedef qemuMonitorMigrationParams *qemuMonitorMigrationParamsPtr;
+struct _qemuMonitorMigrationParams {
+bool compressLevel_set;
+int compressLevel;
+
+bool compressThreads_set;
+int compressThreads;
+
+bool decompressThreads_set;
+int decompressThreads;
+
+bool cpuThrottleInitial_set;
+int cpuThrottleInitial;
+
+bool cpuThrottleIncrement_set;
+int cpuThrottleIncrement;
+
+/* Value is either NULL, "", or some string. NULL indicates no support;
+ * whereas, some string value indicates we can support setting/clearing */
+char *tlsCreds;
+char *tlsHostname;
+
+bool maxBandwidth_set;
+unsigned long long maxBandwidth;
+
+bool downtimeLimit_set;
+unsigned long long downtimeLimit;
+
+bool blockIncremental_set;
+bool blockIncremental;
+
+bool xbzrleCacheSize_set;
+unsigned long long xbzrleCacheSize;
+};
+
 struct _qemuMigrationParams {
 unsigned long long compMethods; /* bit-wise OR of 
qemuMigrationCompressMethod */
 virBitmapPtr caps;
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index fd3c767dcf..1c49cc2370 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -642,42 +642,6 @@ int qemuMonitorGetMigrationCacheSize(qemuMonitorPtr mon,
 int qemuMonitorSetMigrationCacheSize(qemuMonitorPtr mon,
  unsigned long long cacheSize);
 
-typedef struct _qemuMonitorMigrationParams qemuMonitorMigrationParams;
-typedef qemuMonitorMigrationParams *qemuMonitorMigrationParamsPtr;
-struct _qemuMonitorMigrationParams {
-bool compressLevel_set;
-int compressLevel;
-
-bool compressThreads_set;
-int compressThreads;
-
-bool decompressThreads_set;
-int decompressThreads;
-
-bool cpuThrottleInitial_set;
-int cpuThrottleInitial;
-
-bool cpuThrottleIncrement_set;
-int cpuThrottleIncrement;
-
-/* Value is either NULL, "", or some string. NULL indicates no support;
- * whereas, some string value indicates we can support setting/clearing */
-char *tlsCreds;
-char *tlsHostname;
-
-bool maxBandwidth_set;
-unsigned long long maxBandwidth;
-
-bool downtimeLimit_set;
-unsigned long long downtimeLimit;
-
-bool blockIncremental_set;
-bool blockIncremental;
-
-bool xbzrleCacheSize_set;
-unsigned long long xbzrleCacheSize;
-};
-
 int qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
   virJSONValuePtr *params);
 int qemuMonitorSetMigrationParams(qemuMonitorPtr mon,
-- 
2.17.0

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


[libvirt] [PATCH 26/68] qemu: Do not use qemuMonitorSetMigrationCapability

2018-04-04 Thread Jiri Denemark
Rework all remaining callers of qemuMonitorSetMigrationCapability to use
the new qemuMonitorSetMigrationCapabilities API.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c   | 11 ---
 tests/qemumonitorjsontest.c | 16 +++-
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 3240e7d67b..6b0c7545a1 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -5681,6 +5681,7 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
qemuDomainAsyncJob asyncJob)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
+virBitmapPtr migEvent = NULL;
 char **caps = NULL;
 char **capStr;
 int ret = -1;
@@ -5715,12 +5716,16 @@ qemuMigrationCapsCheck(virQEMUDriverPtr driver,
 }
 
 if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_EVENT)) {
+migEvent = virBitmapNew(QEMU_MONITOR_MIGRATION_CAPS_LAST);
+if (!migEvent)
+goto cleanup;
+
+ignore_value(virBitmapSetBit(migEvent, 
QEMU_MONITOR_MIGRATION_CAPS_EVENTS));
+
 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
 goto cleanup;
 
-rc = qemuMonitorSetMigrationCapability(priv->mon,
-   
QEMU_MONITOR_MIGRATION_CAPS_EVENTS,
-   true);
+rc = qemuMonitorSetMigrationCapabilities(priv->mon, migEvent, 
migEvent);
 
 if (qemuDomainObjExitMonitor(driver, vm) < 0)
 goto cleanup;
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 0afdc80038..1cad383596 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -2229,13 +2229,14 @@ testQemuMonitorJSONqemuMonitorJSONGetTargetArch(const 
void *data)
 }
 
 static int
-testQemuMonitorJSONqemuMonitorJSONGetMigrationCapability(const void *data)
+testQemuMonitorJSONqemuMonitorJSONGetMigrationCapabilities(const void *data)
 {
 virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
 qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
 int ret = -1;
 const char *cap;
 char **caps = NULL;
+virBitmapPtr bitmap = NULL;
 const char *reply =
 "{"
 "\"return\": ["
@@ -2266,15 +2267,20 @@ 
testQemuMonitorJSONqemuMonitorJSONGetMigrationCapability(const void *data)
 goto cleanup;
 }
 
-if (qemuMonitorJSONSetMigrationCapability(qemuMonitorTestGetMonitor(test),
-  
QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
-  true) < 0)
+bitmap = virBitmapNew(QEMU_MONITOR_MIGRATION_CAPS_LAST);
+if (!bitmap)
+goto cleanup;
+
+ignore_value(virBitmapSetBit(bitmap, QEMU_MONITOR_MIGRATION_CAPS_XBZRLE));
+if 
(qemuMonitorJSONSetMigrationCapabilities(qemuMonitorTestGetMonitor(test),
+bitmap, bitmap) < 0)
 goto cleanup;
 
 ret = 0;
  cleanup:
 qemuMonitorTestFree(test);
 virStringListFree(caps);
+virBitmapFree(bitmap);
 return ret;
 }
 
@@ -2999,7 +3005,7 @@ mymain(void)
 DO_TEST(qemuMonitorJSONGetChardevInfo);
 DO_TEST(qemuMonitorJSONSetBlockIoThrottle);
 DO_TEST(qemuMonitorJSONGetTargetArch);
-DO_TEST(qemuMonitorJSONGetMigrationCapability);
+DO_TEST(qemuMonitorJSONGetMigrationCapabilities);
 DO_TEST(qemuMonitorJSONQueryCPUs);
 DO_TEST(qemuMonitorJSONGetVirtType);
 DO_TEST(qemuMonitorJSONSendKey);
-- 
2.17.0

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


[libvirt] [PATCH 44/68] qemu: Hide qemuMigrationParamsSetCompression

2018-04-04 Thread Jiri Denemark
There's no need to call this API explicitly in the migration code. We
can pass the compression parameters to qemuMigrationParamsFromFlags and
it can internally call qemuMigrationParamsSetCompression to apply them
to the qemuMigrationParams structure.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c   | 30 -
 src/qemu/qemu_migration.c| 38 ++--
 src/qemu/qemu_migration.h|  2 --
 src/qemu/qemu_migration_params.c | 11 +
 src/qemu/qemu_migration_params.h |  8 ++-
 5 files changed, 36 insertions(+), 53 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 85755257aa..3b0c3a3ffb 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12142,7 +12142,7 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 goto cleanup;
 
 if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
-   
QEMU_MIGRATION_DESTINATION)))
+   QEMU_MIGRATION_DESTINATION, 
compression)))
 goto cleanup;
 
 if (virLockManagerPluginUsesState(driver->lockManager)) {
@@ -12160,7 +12160,7 @@ qemuDomainMigratePrepareTunnel(virConnectPtr dconn,
 
 ret = qemuMigrationDstPrepareTunnel(driver, dconn,
 NULL, 0, NULL, NULL, /* No cookies in 
v2 */
-st, , origname, compression, 
migParams, flags);
+st, , origname, migParams, flags);
 
  cleanup:
 VIR_FREE(compression);
@@ -12208,7 +12208,7 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
 goto cleanup;
 
 if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
-   
QEMU_MIGRATION_DESTINATION)))
+   QEMU_MIGRATION_DESTINATION, 
compression)))
 goto cleanup;
 
 if (virLockManagerPluginUsesState(driver->lockManager)) {
@@ -12232,7 +12232,7 @@ qemuDomainMigratePrepare2(virConnectPtr dconn,
 NULL, 0, NULL, NULL, /* No cookies */
 uri_in, uri_out,
 , origname, NULL, 0, NULL, 0,
-compression, migParams, flags);
+migParams, flags);
 
  cleanup:
 qemuMigrationParamsFree(migParams);
@@ -12273,7 +12273,7 @@ qemuDomainMigratePerform(virDomainPtr dom,
 goto cleanup;
 
 if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
-   QEMU_MIGRATION_SOURCE)))
+   QEMU_MIGRATION_SOURCE, 
compression)))
 goto cleanup;
 
 if (!(vm = qemuDomObjFromDomain(dom)))
@@ -12467,7 +12467,7 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
 goto cleanup;
 
 if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
-   
QEMU_MIGRATION_DESTINATION)))
+   QEMU_MIGRATION_DESTINATION, 
compression)))
 goto cleanup;
 
 if (!(def = qemuMigrationAnyPrepareDef(driver, dom_xml, dname, )))
@@ -12481,7 +12481,7 @@ qemuDomainMigratePrepare3(virConnectPtr dconn,
 cookieout, cookieoutlen,
 uri_in, uri_out,
 , origname, NULL, 0, NULL, 0,
-compression, migParams, flags);
+migParams, flags);
 
  cleanup:
 qemuMigrationParamsFree(migParams);
@@ -12549,7 +12549,7 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
 goto cleanup;
 
 if (!(migParams = qemuMigrationParamsFromFlags(params, nparams, flags,
-   
QEMU_MIGRATION_DESTINATION)))
+   QEMU_MIGRATION_DESTINATION, 
compression)))
 goto cleanup;
 
 if (flags & VIR_MIGRATE_TUNNELLED) {
@@ -12574,7 +12574,7 @@ qemuDomainMigratePrepare3Params(virConnectPtr dconn,
 uri_in, uri_out,
 , origname, listenAddress,
 nmigrate_disks, migrate_disks, nbdPort,
-compression, migParams, flags);
+migParams, flags);
 
  cleanup:
 qemuMigrationParamsFree(migParams);
@@ -12618,7 +12618,7 @@ qemuDomainMigratePrepareTunnel3(virConnectPtr dconn,
 goto cleanup;
 
 if (!(migParams = qemuMigrationParamsFromFlags(NULL, 0, flags,
-   
QEMU_MIGRATION_DESTINATION)))
+  

[libvirt] [PATCH 60/68] qemumigparamstest: Add basic test data

2018-04-04 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 tests/qemumigparamsdata/basic.json  |  9 +
 tests/qemumigparamsdata/basic.reply | 12 
 tests/qemumigparamsdata/basic.xml   | 11 +++
 tests/qemumigparamsdata/empty.json  |  3 +++
 tests/qemumigparamsdata/empty.reply |  5 +
 tests/qemumigparamsdata/empty.xml   |  4 
 tests/qemumigparamstest.c   |  2 ++
 7 files changed, 46 insertions(+)
 create mode 100644 tests/qemumigparamsdata/basic.json
 create mode 100644 tests/qemumigparamsdata/basic.reply
 create mode 100644 tests/qemumigparamsdata/basic.xml
 create mode 100644 tests/qemumigparamsdata/empty.json
 create mode 100644 tests/qemumigparamsdata/empty.reply
 create mode 100644 tests/qemumigparamsdata/empty.xml

diff --git a/tests/qemumigparamsdata/basic.json 
b/tests/qemumigparamsdata/basic.json
new file mode 100644
index 00..b810d7cc87
--- /dev/null
+++ b/tests/qemumigparamsdata/basic.json
@@ -0,0 +1,9 @@
+{
+  "compress-level": 1,
+  "compress-threads": 8,
+  "decompress-threads": 2,
+  "cpu-throttle-initial": 20,
+  "cpu-throttle-increment": 10,
+  "max-bandwidth": 33554432,
+  "downtime-limit": 300
+}
diff --git a/tests/qemumigparamsdata/basic.reply 
b/tests/qemumigparamsdata/basic.reply
new file mode 100644
index 00..dd8c5287a5
--- /dev/null
+++ b/tests/qemumigparamsdata/basic.reply
@@ -0,0 +1,12 @@
+{
+  "id": "libvirt-1",
+  "return": {
+"decompress-threads": 2,
+"cpu-throttle-increment": 10,
+"compress-threads": 8,
+"compress-level": 1,
+"cpu-throttle-initial": 20,
+"max-bandwidth": 33554432,
+"downtime-limit": 300
+  }
+}
diff --git a/tests/qemumigparamsdata/basic.xml 
b/tests/qemumigparamsdata/basic.xml
new file mode 100644
index 00..2ca532eff5
--- /dev/null
+++ b/tests/qemumigparamsdata/basic.xml
@@ -0,0 +1,11 @@
+
+  
+
+
+
+
+
+
+
+  
+
diff --git a/tests/qemumigparamsdata/empty.json 
b/tests/qemumigparamsdata/empty.json
new file mode 100644
index 00..0db3279e44
--- /dev/null
+++ b/tests/qemumigparamsdata/empty.json
@@ -0,0 +1,3 @@
+{
+
+}
diff --git a/tests/qemumigparamsdata/empty.reply 
b/tests/qemumigparamsdata/empty.reply
new file mode 100644
index 00..7aae399ede
--- /dev/null
+++ b/tests/qemumigparamsdata/empty.reply
@@ -0,0 +1,5 @@
+{
+  "id": "libvirt-1",
+  "return": {
+  }
+}
diff --git a/tests/qemumigparamsdata/empty.xml 
b/tests/qemumigparamsdata/empty.xml
new file mode 100644
index 00..8aa3abefc0
--- /dev/null
+++ b/tests/qemumigparamsdata/empty.xml
@@ -0,0 +1,4 @@
+
+  
+  
+
diff --git a/tests/qemumigparamstest.c b/tests/qemumigparamstest.c
index 4cc27bcf52..6fb404c24d 100644
--- a/tests/qemumigparamstest.c
+++ b/tests/qemumigparamstest.c
@@ -228,6 +228,8 @@ mymain(void)
 } while (0)
 
 DO_TEST("unsupported");
+DO_TEST("empty");
+DO_TEST("basic");
 
 qemuTestDriverFree();
 
-- 
2.17.0

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


[libvirt] [PATCH 25/68] qemu: Set migration caps via migration params APIs

2018-04-04 Thread Jiri Denemark
Migration capabilities are closely related to migration parameters and
it makes sense to keep them in a single data structure. Similarly to
migration parameters the capabilities are all send to QEMU at once in
qemuMigrationParamsApply, all other APIs operate on the
qemuMigrationParams structure.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c| 100 ++-
 src/qemu/qemu_migration.h|   7 ---
 src/qemu/qemu_migration_params.c |  99 +++---
 src/qemu/qemu_migration_params.h |  11 
 4 files changed, 107 insertions(+), 110 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 3e775ea56b..3240e7d67b 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1174,66 +1174,6 @@ qemuMigrationAnyPostcopyFailed(virQEMUDriverPtr driver,
 }
 
 
-int
-qemuMigrationOptionSet(virQEMUDriverPtr driver,
-   virDomainObjPtr vm,
-   qemuMonitorMigrationCaps capability,
-   bool state,
-   qemuDomainAsyncJob job)
-{
-qemuDomainObjPrivatePtr priv = vm->privateData;
-int ret;
-
-if (!qemuMigrationCapsGet(vm, capability)) {
-if (!state) {
-/* Unsupported but we want it off anyway */
-return 0;
-}
-
-if (job == QEMU_ASYNC_JOB_MIGRATION_IN) {
-virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
-   _("Migration option '%s' is not supported by "
- "target QEMU binary"),
-   qemuMonitorMigrationCapsTypeToString(capability));
-} else {
-virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
-   _("Migration option '%s' is not supported by "
- "source QEMU binary"),
-   qemuMonitorMigrationCapsTypeToString(capability));
-}
-return -1;
-}
-
-if (qemuDomainObjEnterMonitorAsync(driver, vm, job) < 0)
-return -1;
-
-ret = qemuMonitorSetMigrationCapability(priv->mon, capability, state);
-
-if (qemuDomainObjExitMonitor(driver, vm) < 0)
-ret = -1;
-
-return ret;
-}
-
-
-static int
-qemuMigrationOptionSetPostCopy(virQEMUDriverPtr driver,
-   virDomainObjPtr vm,
-   bool state,
-   qemuDomainAsyncJob job)
-{
-qemuDomainObjPrivatePtr priv = vm->privateData;
-
-if (qemuMigrationOptionSet(driver, vm,
-   QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
-   state, job) < 0)
-return -1;
-
-priv->job.postcopyEnabled = state;
-return 0;
-}
-
-
 static int
 qemuMigrationSrcWaitForSpice(virDomainObjPtr vm)
 {
@@ -2468,15 +2408,14 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 goto stopjob;
 }
 
-if (qemuMigrationOptionSet(driver, vm,
-   QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
-   flags & VIR_MIGRATE_RDMA_PIN_ALL,
-   QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
+if (qemuMigrationParamsSetCapability(vm,
+ 
QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
+ flags & VIR_MIGRATE_RDMA_PIN_ALL,
+ migParams) < 0)
 goto stopjob;
 
-if (qemuMigrationOptionSetPostCopy(driver, vm,
-   flags & VIR_MIGRATE_POSTCOPY,
-   QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
+if (qemuMigrationParamsSetPostCopy(vm, flags & VIR_MIGRATE_POSTCOPY,
+   migParams) < 0)
 goto stopjob;
 
 if (qemuMigrationParamsApply(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
@@ -3451,27 +3390,26 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
   compression, migParams) < 0)
 goto error;
 
-if (qemuMigrationOptionSet(driver, vm,
-   QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
-   flags & VIR_MIGRATE_AUTO_CONVERGE,
-   QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+if (qemuMigrationParamsSetCapability(vm,
+ 
QEMU_MONITOR_MIGRATION_CAPS_AUTO_CONVERGE,
+ flags & VIR_MIGRATE_AUTO_CONVERGE,
+ migParams) < 0)
 goto error;
 
-if (qemuMigrationOptionSet(driver, vm,
-   QEMU_MONITOR_MIGRATION_CAPS_RDMA_PIN_ALL,
-   flags & VIR_MIGRATE_RDMA_PIN_ALL,
-   QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+if (qemuMigrationParamsSetCapability(vm,
+ 

[libvirt] [PATCH 36/68] qemu: Drop qemuMigrationParamsSetPostCopy

2018-04-04 Thread Jiri Denemark
It's just a tiny wrapper around qemuMigrationParamsSetCapability and
setting priv->job.postcopyEnabled is not something qemuMigrationParams
code should be doing anyway so let the callers do it.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c| 16 
 src/qemu/qemu_migration_params.c | 17 -
 src/qemu/qemu_migration_params.h |  5 -
 3 files changed, 12 insertions(+), 26 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index ceab035acf..f3006d8aa4 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2394,8 +2394,10 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
  migParams) < 0)
 goto stopjob;
 
-if (qemuMigrationParamsSetPostCopy(vm, flags & VIR_MIGRATE_POSTCOPY,
-   migParams) < 0)
+if (qemuMigrationParamsSetCapability(vm,
+ QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
+ flags & VIR_MIGRATE_POSTCOPY,
+ migParams) < 0)
 goto stopjob;
 
 if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
@@ -2419,6 +2421,8 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
  migParams) < 0)
 goto stopjob;
 
+priv->job.postcopyEnabled = flags & VIR_MIGRATE_POSTCOPY;
+
 if (mig->nbd &&
 flags & (VIR_MIGRATE_NON_SHARED_DISK | VIR_MIGRATE_NON_SHARED_INC) &&
 virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NBD_SERVER)) {
@@ -3352,8 +3356,10 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
  migParams) < 0)
 goto error;
 
-if (qemuMigrationParamsSetPostCopy(vm, flags & VIR_MIGRATE_POSTCOPY,
-   migParams) < 0)
+if (qemuMigrationParamsSetCapability(vm,
+ QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
+ flags & VIR_MIGRATE_POSTCOPY,
+ migParams) < 0)
 goto error;
 
 if (qemuMigrationCapsGet(vm, 
QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER) &&
@@ -3389,6 +3395,8 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
  migParams) < 0)
 goto error;
 
+priv->job.postcopyEnabled = flags & VIR_MIGRATE_POSTCOPY;
+
 if (migrate_flags & (QEMU_MONITOR_MIGRATE_NON_SHARED_DISK |
  QEMU_MONITOR_MIGRATE_NON_SHARED_INC)) {
 if (mig->nbd) {
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index c79ea4fa91..ac99fa29e1 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -199,23 +199,6 @@ qemuMigrationParamsSetCapability(virDomainObjPtr vm 
ATTRIBUTE_UNUSED,
 }
 
 
-int
-qemuMigrationParamsSetPostCopy(virDomainObjPtr vm,
-   bool state,
-   qemuMigrationParamsPtr migParams)
-{
-qemuDomainObjPrivatePtr priv = vm->privateData;
-
-if (qemuMigrationParamsSetCapability(vm,
- QEMU_MONITOR_MIGRATION_CAPS_POSTCOPY,
- state, migParams) < 0)
-return -1;
-
-priv->job.postcopyEnabled = state;
-return 0;
-}
-
-
 /* qemuMigrationParamsEnableTLS
  * @driver: pointer to qemu driver
  * @vm: domain object
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 3620a4e36e..a483211bdd 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -77,11 +77,6 @@ qemuMigrationParamsSetCapability(virDomainObjPtr vm,
  bool state,
  qemuMigrationParamsPtr migParams);
 
-int
-qemuMigrationParamsSetPostCopy(virDomainObjPtr vm,
-   bool state,
-   qemuMigrationParamsPtr migParams);
-
 int
 qemuMigrationParamsEnableTLS(virQEMUDriverPtr driver,
  virDomainObjPtr vm,
-- 
2.17.0

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


[libvirt] [PATCH 59/68] tests: Add tests for QEMU migration parameters

2018-04-04 Thread Jiri Denemark
This is an enhanced replacement for the original test from
qemumonitorjsontest which was dropped earlier in this series. More data
files with some real data will be added in the following patches.

Signed-off-by: Jiri Denemark 
---
 tests/Makefile.am |  12 ++
 tests/qemumigparamsdata/unsupported.json  |   3 +
 tests/qemumigparamsdata/unsupported.reply |   7 +
 tests/qemumigparamsdata/unsupported.xml   |   4 +
 tests/qemumigparamstest.c | 237 ++
 5 files changed, 263 insertions(+)
 create mode 100644 tests/qemumigparamsdata/unsupported.json
 create mode 100644 tests/qemumigparamsdata/unsupported.reply
 create mode 100644 tests/qemumigparamsdata/unsupported.xml
 create mode 100644 tests/qemumigparamstest.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index f2f5caed4f..2948ff7c87 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -125,6 +125,7 @@ EXTRA_DIST = \
qemuhotplugtestcpus \
qemuhotplugtestdevices \
qemuhotplugtestdomains \
+   qemumigparamsdata \
qemumonitorjsondata \
qemuxml2argvdata \
qemuxml2startupxmloutdata \
@@ -290,6 +291,7 @@ test_programs += qemuxml2argvtest qemuxml2xmltest \
qemumemlocktest \
qemucommandutiltest \
qemublocktest \
+   qemumigparamstest \
$(NULL)
 test_helpers += qemucapsprobe
 test_libraries += libqemumonitortestutils.la \
@@ -692,6 +694,15 @@ qemumemlocktest_SOURCES = \
testutilsqemu.c testutilsqemu.h \
testutils.c testutils.h
 qemumemlocktest_LDADD = $(qemu_LDADDS) $(LDADDS)
+
+qemumigparamstest_SOURCES = \
+   qemumigparamstest.c \
+   testutils.c testutils.h \
+   testutilsqemu.c testutilsqemu.h \
+   $(NULL)
+qemumigparamstest_LDADD = libqemumonitortestutils.la \
+   $(qemu_LDADDS) $(LDADDS)
+
 else ! WITH_QEMU
 EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \
qemuhelptest.c domainsnapshotxml2xmltest.c \
@@ -702,6 +713,7 @@ EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c 
qemuargv2xmltest.c \
qemucaps2xmltest.c qemucommandutiltest.c \
qemumemlocktest.c qemucpumock.c testutilshostcpus.h \
qemublocktest.c \
+   qemumigparamstest.c \
$(QEMUMONITORTESTUTILS_SOURCES)
 endif ! WITH_QEMU
 
diff --git a/tests/qemumigparamsdata/unsupported.json 
b/tests/qemumigparamsdata/unsupported.json
new file mode 100644
index 00..0db3279e44
--- /dev/null
+++ b/tests/qemumigparamsdata/unsupported.json
@@ -0,0 +1,3 @@
+{
+
+}
diff --git a/tests/qemumigparamsdata/unsupported.reply 
b/tests/qemumigparamsdata/unsupported.reply
new file mode 100644
index 00..2b88ba10c3
--- /dev/null
+++ b/tests/qemumigparamsdata/unsupported.reply
@@ -0,0 +1,7 @@
+{
+  "id": "libvirt-1",
+  "error": {
+"class": "CommandNotFound",
+"desc": "The command query-migrate-parameters has not been found"
+  }
+}
diff --git a/tests/qemumigparamsdata/unsupported.xml 
b/tests/qemumigparamsdata/unsupported.xml
new file mode 100644
index 00..8aa3abefc0
--- /dev/null
+++ b/tests/qemumigparamsdata/unsupported.xml
@@ -0,0 +1,4 @@
+
+  
+  
+
diff --git a/tests/qemumigparamstest.c b/tests/qemumigparamstest.c
new file mode 100644
index 00..4cc27bcf52
--- /dev/null
+++ b/tests/qemumigparamstest.c
@@ -0,0 +1,237 @@
+/*
+ * Copyright (C) 2011-2013 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ *
+ */
+
+#include 
+
+#include "virjson.h"
+#include "virbuffer.h"
+#include "virxml.h"
+#include "testutils.h"
+#include "testutilsqemu.h"
+#include "qemumonitortestutils.h"
+#include "qemu/qemu_migration_params.h"
+#include "qemu/qemu_migration_paramspriv.h"
+#include "qemu/qemu_monitor.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+typedef struct _qemuMigParamsData qemuMigParamsData;
+struct _qemuMigParamsData {
+virDomainXMLOptionPtr xmlopt;
+const char *name;
+};
+
+
+static void
+qemuMigParamsTestFormatXML(virBufferPtr buf,
+   qemuMigrationParamsPtr migParams)
+{
+virBufferAddLit(buf, "\n");
+virBufferAdjustIndent(buf, 2);
+
+if (migParams)
+qemuMigrationParamsFormat(buf, migParams);
+
+virBufferAdjustIndent(buf, -2);
+virBufferAddLit(buf, "\n");
+}
+
+
+static int
+qemuMigParamsTestXML2XML(const void *opaque)
+{

[libvirt] [PATCH 49/68] qemumonitorjsontest: Drop migration params test

2018-04-04 Thread Jiri Denemark
The test is mostly useless and we want to refactor migration parameters
even further. The refactoring will allow us to introduce enhanced tests
for migration parameters.

Signed-off-by: Jiri Denemark 
---
 tests/qemumonitorjsontest.c | 99 -
 1 file changed, 99 deletions(-)

diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 8a5b0be64b..dafcccebad 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1787,104 +1787,6 @@ 
testQemuMonitorJSONqemuMonitorJSONGetBlockStatsInfo(const void *data)
 return ret;
 }
 
-static int
-testQemuMonitorJSONqemuMonitorJSONGetMigrationParams(const void *data)
-{
-virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
-qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
-qemuMonitorMigrationParams params;
-int ret = -1;
-
-if (!test)
-return -1;
-
-if (qemuMonitorTestAddItem(test, "query-migrate-parameters",
-   "{"
-   "\"return\": {"
-   "\"decompress-threads\": 2,"
-   "\"cpu-throttle-increment\": 10,"
-   "\"compress-threads\": 8,"
-   "\"compress-level\": 1,"
-   "\"cpu-throttle-initial\": 20,"
-   "\"tls-creds\": \"tls0\","
-   "\"tls-hostname\": \"\","
-   "\"max-bandwidth\": 1234567890,"
-   "\"downtime-limit\": 500,"
-   "\"block-incremental\": true,"
-   "\"xbzrle-cache-size\": 67108864"
-   "}"
-   "}") < 0) {
-goto cleanup;
-}
-
-if (qemuMonitorJSONGetMigrationParams(qemuMonitorTestGetMonitor(test),
-  ) < 0)
-goto cleanup;
-
-#define CHECK_NUM(VAR, FIELD, VALUE, FMT) \
-do { \
-if (!params.VAR ## _set) { \
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s is not set", FIELD); \
-goto cleanup; \
-} \
-if (params.VAR != VALUE) { \
-virReportError(VIR_ERR_INTERNAL_ERROR, \
-   "Invalid %s: " FMT ", expected " FMT, \
-   FIELD, params.VAR, VALUE); \
-goto cleanup; \
-} \
-} while (0)
-
-#define CHECK_INT(VAR, FIELD, VALUE) \
-CHECK_NUM(VAR, FIELD, VALUE, "%d")
-
-#define CHECK_ULONG(VAR, FIELD, VALUE) \
-CHECK_NUM(VAR, FIELD, VALUE, "%llu")
-
-#define CHECK_BOOL(VAR, FIELD, VALUE) \
-CHECK_NUM(VAR, FIELD, VALUE, "%d")
-
-#define CHECK_STR(VAR, FIELD, VALUE) \
-do { \
-if (!params.VAR) { \
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s is not set", FIELD); \
-goto cleanup; \
-} \
-if (STRNEQ(params.VAR, VALUE)) { \
-virReportError(VIR_ERR_INTERNAL_ERROR, \
-   "Invalid %s:'%s', expected '%s'", \
-   FIELD, params.VAR, VALUE); \
-goto cleanup; \
-} \
-} while (0)
-
-CHECK_INT(compressLevel, "compress-level", 1);
-CHECK_INT(compressThreads, "compress-threads", 8);
-CHECK_INT(decompressThreads, "decompress-threads", 2);
-CHECK_INT(cpuThrottleInitial, "cpu-throttle-initial", 20);
-CHECK_INT(cpuThrottleIncrement, "cpu-throttle-increment", 10);
-CHECK_STR(tlsCreds, "tls-creds", "tls0");
-CHECK_STR(tlsHostname, "tls-hostname", "");
-CHECK_ULONG(maxBandwidth, "max-bandwidth", 1234567890ULL);
-CHECK_ULONG(downtimeLimit, "downtime-limit", 500ULL);
-CHECK_BOOL(blockIncremental, "block-incremental", true);
-CHECK_ULONG(xbzrleCacheSize, "xbzrle-cache-size", 67108864ULL);
-
-#undef CHECK_NUM
-#undef CHECK_INT
-#undef CHECK_ULONG
-#undef CHECK_BOOL
-#undef CHECK_STR
-
-ret = 0;
-
- cleanup:
-VIR_FREE(params.tlsCreds);
-VIR_FREE(params.tlsHostname);
-qemuMonitorTestFree(test);
-return ret;
-}
-
 
 static int
 testQemuMonitorJSONqemuMonitorJSONGetMigrationCacheSize(const void *data)
@@ -3002,7 +2904,6 @@ mymain(void)
 DO_TEST(qemuMonitorJSONGetBlockInfo);
 DO_TEST(qemuMonitorJSONGetBlockStatsInfo);
 DO_TEST(qemuMonitorJSONGetMigrationCacheSize);
-DO_TEST(qemuMonitorJSONGetMigrationParams);
 DO_TEST(qemuMonitorJSONGetMigrationStats);
 DO_TEST(qemuMonitorJSONGetChardevInfo);
 DO_TEST(qemuMonitorJSONSetBlockIoThrottle);
-- 
2.17.0

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


[libvirt] [PATCH 12/68] qemu: Store original migration params in job

2018-04-04 Thread Jiri Denemark
Any job which touches migration parameters will first store their
original values (i.e., QEMU defaults) to qemuDomainJobObj to make it
easier to reset them back once the job finishes.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_domain.c   |  3 +++
 src/qemu/qemu_domain.h   |  3 +++
 src/qemu/qemu_migration.c|  9 
 src/qemu/qemu_migration_params.c | 38 
 src/qemu/qemu_migration_params.h |  5 +
 5 files changed, 58 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index a1bbe256f5..e44073f441 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -336,6 +336,8 @@ qemuDomainObjResetAsyncJob(qemuDomainObjPrivatePtr priv)
 job->dumpCompleted = false;
 VIR_FREE(job->error);
 VIR_FREE(job->current);
+qemuMigrationParamsFree(job->migParams);
+job->migParams = NULL;
 }
 
 void
@@ -350,6 +352,7 @@ qemuDomainObjRestoreJob(virDomainObjPtr obj,
 job->asyncJob = priv->job.asyncJob;
 job->asyncOwner = priv->job.asyncOwner;
 job->phase = priv->job.phase;
+VIR_STEAL_PTR(job->migParams, priv->job.migParams);
 
 qemuDomainObjResetJob(priv);
 qemuDomainObjResetAsyncJob(priv);
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 415b2ca093..1828b64284 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -34,6 +34,7 @@
 # include "qemu_agent.h"
 # include "qemu_conf.h"
 # include "qemu_capabilities.h"
+# include "qemu_migration_params.h"
 # include "virmdev.h"
 # include "virchrdev.h"
 # include "virobject.h"
@@ -177,6 +178,8 @@ struct qemuDomainJobObj {
 bool postcopyEnabled;   /* post-copy migration was enabled */
 char *error;/* job event completion error */
 bool dumpCompleted; /* dump completed */
+
+qemuMigrationParamsPtr migParams;
 };
 
 typedef void (*qemuDomainCleanupCallback)(virQEMUDriverPtr driver,
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 73024d66c0..7fd85bc6c5 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2451,6 +2451,9 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 dataFD[1] = -1; /* 'st' owns the FD now & will close it */
 }
 
+if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN) < 0)
+goto stopjob;
+
 if (qemuMigrationParamsSetCompression(driver, vm, 
QEMU_ASYNC_JOB_MIGRATION_IN,
   compression, migParams) < 0)
 goto stopjob;
@@ -4600,6 +4603,9 @@ qemuMigrationSrcPerformJob(virQEMUDriverPtr driver,
 
 qemuMigrationSrcStoreDomainState(vm);
 
+if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+goto endjob;
+
 if ((flags & (VIR_MIGRATE_TUNNELLED | VIR_MIGRATE_PEER2PEER))) {
 ret = qemuMigrationSrcPerformPeer2Peer(driver, conn, vm, xmlin, 
persist_xml,
dconnuri, uri, graphicsuri, 
listenAddress,
@@ -4703,6 +4709,9 @@ qemuMigrationSrcPerformPhase(virQEMUDriverPtr driver,
 virCloseCallbacksUnset(driver->closeCallbacks, vm,
qemuMigrationSrcCleanup);
 
+if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
+goto endjob;
+
 ret = qemuMigrationSrcPerformNative(driver, vm, persist_xml, uri, 
cookiein, cookieinlen,
 cookieout, cookieoutlen,
 flags, resource, NULL, graphicsuri,
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 187c0c2258..4defc62ae5 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -428,6 +428,44 @@ qemuMigrationParamsResetTLS(virQEMUDriverPtr driver,
 }
 
 
+/**
+ * qemuMigrationParamsCheck:
+ *
+ * Check supported migration parameters and keep their original values in
+ * qemuDomainJobObj so that we can properly reset them at the end of migration.
+ */
+int
+qemuMigrationParamsCheck(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ int asyncJob)
+{
+qemuDomainObjPrivatePtr priv = vm->privateData;
+qemuMigrationParamsPtr origParams = NULL;
+int ret = -1;
+
+if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
+return -1;
+
+if (!(origParams = qemuMigrationParamsNew()))
+goto cleanup;
+
+if (qemuMonitorGetMigrationParams(priv->mon, >params) < 0)
+goto cleanup;
+
+ret = 0;
+
+ cleanup:
+if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ret = -1;
+
+if (ret == 0)
+VIR_STEAL_PTR(priv->job.migParams, origParams);
+qemuMigrationParamsFree(origParams);
+
+return ret;
+}
+
+
 /*
  * qemuMigrationParamsReset:
  *
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index f5e64dcc1d..a6125a6f3d 100644

[libvirt] [PATCH 09/68] qemu: Move qemuMigrationCompression struct

2018-04-04 Thread Jiri Denemark
It provides just another view on some migration parameters so let's move
it close to them. The end goal is to merge compression parameters with
the rest of migration parameters since it doesn't make any sense to
handle them differently.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.h| 20 +---
 src/qemu/qemu_migration_params.h | 19 +++
 2 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/src/qemu/qemu_migration.h b/src/qemu/qemu_migration.h
index 7342517ca6..32028845a7 100644
--- a/src/qemu/qemu_migration.h
+++ b/src/qemu/qemu_migration.h
@@ -24,6 +24,7 @@
 
 # include "qemu_conf.h"
 # include "qemu_domain.h"
+# include "qemu_migration_params.h"
 
 /*
  * General function naming conventions:
@@ -39,9 +40,6 @@
  *  - qemuMigrationCapsXXX - runs on source or dest host
  */
 
-typedef struct _qemuMigrationCompression qemuMigrationCompression;
-typedef qemuMigrationCompression *qemuMigrationCompressionPtr;
-
 /* All supported qemu migration flags.  */
 # define QEMU_MIGRATION_FLAGS \
 (VIR_MIGRATE_LIVE | \
@@ -109,22 +107,6 @@ typedef enum {
 } qemuMigrationCompressMethod;
 VIR_ENUM_DECL(qemuMigrationCompressMethod)
 
-struct _qemuMigrationCompression {
-unsigned long long methods;
-
-bool level_set;
-int level;
-
-bool threads_set;
-int threads;
-
-bool dthreads_set;
-int dthreads;
-
-bool xbzrle_cache_set;
-unsigned long long xbzrle_cache;
-};
-
 qemuMigrationCompressionPtr
 qemuMigrationAnyCompressionParse(virTypedParameterPtr params,
  int nparams,
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 18802ac3e4..247455b1cd 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -28,6 +28,25 @@
 # include "qemu_conf.h"
 
 
+typedef struct _qemuMigrationCompression qemuMigrationCompression;
+typedef qemuMigrationCompression *qemuMigrationCompressionPtr;
+struct _qemuMigrationCompression {
+unsigned long long methods;
+
+bool level_set;
+int level;
+
+bool threads_set;
+int threads;
+
+bool dthreads_set;
+int dthreads;
+
+bool xbzrle_cache_set;
+unsigned long long xbzrle_cache;
+};
+
+
 qemuMonitorMigrationParamsPtr
 qemuMigrationParamsNew(void);
 
-- 
2.17.0

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


[libvirt] [PATCH 41/68] qemu: Drop qemuMigrationParamsSetCapability

2018-04-04 Thread Jiri Denemark
It's become only a tiny wrapper around virBitmapSetBit, which can easily
be called directly. We don't need to call virBitmapClearBit since
migParams->caps bitmap is initialized with zeros.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 35 +++-
 1 file changed, 7 insertions(+), 28 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 2caf4dd1c9..b70229a156 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -226,21 +226,6 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
 }
 
 
-static int
-qemuMigrationParamsSetCapability(virDomainObjPtr vm ATTRIBUTE_UNUSED,
- qemuMonitorMigrationCaps capability,
- bool state,
- qemuMigrationParamsPtr migParams)
-{
-if (state)
-ignore_value(virBitmapSetBit(migParams->caps, capability));
-else
-ignore_value(virBitmapClearBit(migParams->caps, capability));
-
-return 0;
-}
-
-
 /* qemuMigrationParamsEnableTLS
  * @driver: pointer to qemu driver
  * @vm: domain object
@@ -355,23 +340,17 @@ qemuMigrationParamsDisableTLS(virDomainObjPtr vm,
 
 
 int
-qemuMigrationParamsSetCompression(virDomainObjPtr vm,
+qemuMigrationParamsSetCompression(virDomainObjPtr vm ATTRIBUTE_UNUSED,
   qemuMigrationCompressionPtr compression,
   qemuMigrationParamsPtr migParams)
 {
-if (qemuMigrationParamsSetCapability(vm,
- QEMU_MONITOR_MIGRATION_CAPS_XBZRLE,
- compression->methods &
- (1ULL << 
QEMU_MIGRATION_COMPRESS_XBZRLE),
- migParams) < 0)
-return -1;
+if (compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE))
+ignore_value(virBitmapSetBit(migParams->caps,
+ QEMU_MONITOR_MIGRATION_CAPS_XBZRLE));
 
-if (qemuMigrationParamsSetCapability(vm,
- QEMU_MONITOR_MIGRATION_CAPS_COMPRESS,
- compression->methods &
- (1ULL << QEMU_MIGRATION_COMPRESS_MT),
- migParams) < 0)
-return -1;
+if (compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_MT))
+ignore_value(virBitmapSetBit(migParams->caps,
+ QEMU_MONITOR_MIGRATION_CAPS_COMPRESS));
 
 migParams->params.compressLevel_set = compression->level_set;
 migParams->params.compressLevel = compression->level;
-- 
2.17.0

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


[libvirt] [PATCH 15/68] qemu: Reset all migration parameters

2018-04-04 Thread Jiri Denemark
Restore the original values of all migration parameters we store in
qemuDomainJobObj instead of explicitly resting only a limited set of
them.

The result is not strictly equivalent to the previous code wrt reseting
TLS state because the previous code would only reset it if we changed it
before while the new code will reset it always if QEMU supports TLS
migration. This is not a problem for the parameters themselves, but it
can cause spurious errors about missing TLS objects being logged at the
end of non-TLS migration. This issue will be fixed ~50 patches later.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c| 20 +
 src/qemu/qemu_migration_params.c | 48 +++-
 src/qemu/qemu_migration_params.h |  3 +-
 src/qemu/qemu_process.c  |  4 +--
 4 files changed, 34 insertions(+), 41 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 7fd85bc6c5..3c25e0e27f 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1834,7 +1834,8 @@ qemuMigrationSrcCleanup(virDomainObjPtr vm,
 VIR_WARN("Migration of domain %s finished but we don't know if the"
  " domain was successfully started on destination or not",
  vm->def->name);
-qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT);
+qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
+ priv->job.migParams);
 /* clear the job and let higher levels decide what to do */
 qemuDomainObjDiscardAsyncJob(driver, vm);
 break;
@@ -2596,7 +2597,8 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 return ret;
 
  stopjob:
-qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN);
+qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
+ priv->job.migParams);
 
 if (stopProcess) {
 unsigned int stopFlags = VIR_QEMU_PROCESS_STOP_MIGRATED;
@@ -2972,7 +2974,8 @@ qemuMigrationSrcConfirmPhase(virQEMUDriverPtr driver,
 qemuDomainEventQueue(driver, event);
 }
 
-qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT);
+qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
+ priv->job.migParams);
 
 if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, 
driver->caps) < 0)
 VIR_WARN("Failed to save status on vm %s", vm->def->name);
@@ -4584,6 +4587,7 @@ qemuMigrationSrcPerformJob(virQEMUDriverPtr driver,
 int ret = -1;
 virErrorPtr orig_err = NULL;
 virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+qemuDomainObjPrivatePtr priv = vm->privateData;
 
 if (qemuMigrationJobStart(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT) < 0)
 goto cleanup;
@@ -4644,7 +4648,8 @@ qemuMigrationSrcPerformJob(virQEMUDriverPtr driver,
  * here
  */
 if (!v3proto && ret < 0)
-qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT);
+qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
+ priv->job.migParams);
 
 if (qemuMigrationSrcRestoreDomainState(driver, vm)) {
 event = virDomainEventLifecycleNewFromObj(vm,
@@ -4694,6 +4699,7 @@ qemuMigrationSrcPerformPhase(virQEMUDriverPtr driver,
  unsigned long flags,
  unsigned long resource)
 {
+qemuDomainObjPrivatePtr priv = vm->privateData;
 virObjectEventPtr event = NULL;
 int ret = -1;
 
@@ -4734,7 +4740,8 @@ qemuMigrationSrcPerformPhase(virQEMUDriverPtr driver,
 
  endjob:
 if (ret < 0) {
-qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT);
+qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
+ priv->job.migParams);
 qemuMigrationJobFinish(driver, vm);
 } else {
 qemuMigrationJobContinue(vm);
@@ -5190,7 +5197,8 @@ qemuMigrationDstFinish(virQEMUDriverPtr driver,
 VIR_FREE(priv->job.completed);
 }
 
-qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN);
+qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_IN,
+ priv->job.migParams);
 
 qemuMigrationJobFinish(driver, vm);
 if (!virDomainObjIsActive(vm))
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 4defc62ae5..43098de904 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -378,30 +378,19 @@ qemuMigrationParamsSetCompression(virQEMUDriverPtr driver,
  *
  * Deconstruct all the setup possibly done for TLS - delete the TLS and
  * security objects, free the secinfo, and reset the migration params to "".
- *
- * Returns 0 on success, -1 on failure
  */
-static int
+static void
 

[libvirt] [PATCH 45/68] qemu: Replace qemuMigrationAnyCompressionDump

2018-04-04 Thread Jiri Denemark
Since every parameter or capability set in qemuMigrationCompression
structure is now reflected in qemuMigrationParams structure, we can
replace qemuMigrationAnyCompressionDump with a new API which will work
on qemuMigrationParams.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c   |  6 ++--
 src/qemu/qemu_migration.c| 16 --
 src/qemu/qemu_migration.h|  1 -
 src/qemu/qemu_migration_params.c | 52 ++--
 src/qemu/qemu_migration_params.h | 10 +++---
 5 files changed, 37 insertions(+), 48 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3b0c3a3ffb..5e79e90609 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12297,7 +12297,7 @@ qemuDomainMigratePerform(virDomainPtr dom,
  */
 ret = qemuMigrationSrcPerform(driver, dom->conn, vm, NULL,
   NULL, dconnuri, uri, NULL, NULL, 0, NULL, 0,
-  compression, migParams, cookie, cookielen,
+  migParams, cookie, cookielen,
   NULL, NULL, /* No output cookies in v2 */
   flags, dname, resource, false);
 
@@ -12743,7 +12743,7 @@ qemuDomainMigratePerform3(virDomainPtr dom,
 
 ret = qemuMigrationSrcPerform(driver, dom->conn, vm, xmlin, NULL,
   dconnuri, uri, NULL, NULL, 0, NULL, 0,
-  compression, migParams,
+  migParams,
   cookiein, cookieinlen,
   cookieout, cookieoutlen,
   flags, dname, resource, true);
@@ -12836,7 +12836,7 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
 ret = qemuMigrationSrcPerform(driver, dom->conn, vm, dom_xml, persist_xml,
   dconnuri, uri, graphicsuri, listenAddress,
   nmigrate_disks, migrate_disks, nbdPort,
-  compression, migParams,
+  migParams,
   cookiein, cookieinlen, cookieout, 
cookieoutlen,
   flags, dname, bandwidth, true);
  cleanup:
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 304eaf52c5..2a0431ea6f 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3894,7 +3894,6 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
   size_t nmigrate_disks,
   const char **migrate_disks,
   int nbdPort,
-  qemuMigrationCompressionPtr compression,
   qemuMigrationParamsPtr migParams,
   unsigned long long bandwidth,
   bool useParams,
@@ -3979,8 +3978,8 @@ qemuMigrationSrcPerformPeer2Peer3(virQEMUDriverPtr driver,
  nbdPort) < 0)
 goto cleanup;
 
-if (qemuMigrationAnyCompressionDump(compression, , ,
-, ) < 0)
+if (qemuMigrationParamsDump(migParams, , ,
+, ) < 0)
 goto cleanup;
 }
 
@@ -4253,7 +4252,6 @@ qemuMigrationSrcPerformPeer2Peer(virQEMUDriverPtr driver,
  size_t nmigrate_disks,
  const char **migrate_disks,
  int nbdPort,
- qemuMigrationCompressionPtr compression,
  qemuMigrationParamsPtr migParams,
  unsigned long flags,
  const char *dname,
@@ -4378,7 +4376,7 @@ qemuMigrationSrcPerformPeer2Peer(virQEMUDriverPtr driver,
 ret = qemuMigrationSrcPerformPeer2Peer3(driver, sconn, dconn, 
dconnuri, vm, xmlin,
 persist_xml, dname, uri, 
graphicsuri,
 listenAddress, nmigrate_disks, 
migrate_disks,
-nbdPort, compression, 
migParams, resource,
+nbdPort, migParams, resource,
 useParams, flags);
 } else {
 ret = qemuMigrationSrcPerformPeer2Peer2(driver, sconn, dconn, vm,
@@ -4419,7 +4417,6 @@ qemuMigrationSrcPerformJob(virQEMUDriverPtr driver,
size_t nmigrate_disks,
const char **migrate_disks,
int nbdPort,
-   qemuMigrationCompressionPtr compression,
qemuMigrationParamsPtr migParams,
const char 

[libvirt] [PATCH 24/68] qemu: Introduce qemuMonitorSetMigrationCapabilities

2018-04-04 Thread Jiri Denemark
Our current monitor API forces the caller to call
migrate-set-capabilities QMP command for each capability separately,
which is quite suboptimal. Let's add a new API for setting all
capabilities at once.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_monitor.c  | 19 +++
 src/qemu/qemu_monitor.h  |  3 ++
 src/qemu/qemu_monitor_json.c | 63 
 src/qemu/qemu_monitor_json.h |  3 ++
 4 files changed, 88 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 7b647525b3..7ea72af788 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3991,6 +3991,25 @@ qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
 }
 
 
+int
+qemuMonitorSetMigrationCapabilities(qemuMonitorPtr mon,
+virBitmapPtr caps,
+virBitmapPtr states)
+{
+char *capsStr = virBitmapFormat(caps);
+char *statesStr = virBitmapFormat(states);
+
+VIR_DEBUG("caps=%s, states=%s", NULLSTR(capsStr), NULLSTR(statesStr));
+
+VIR_FREE(capsStr);
+VIR_FREE(statesStr);
+
+QEMU_CHECK_MONITOR_JSON(mon);
+
+return qemuMonitorJSONSetMigrationCapabilities(mon, caps, states);
+}
+
+
 /**
  * qemuMonitorGetGICCapabilities:
  * @mon: QEMU monitor
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index d04148e568..870aae5cbd 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -763,6 +763,9 @@ int qemuMonitorGetMigrationCapabilities(qemuMonitorPtr mon,
 int qemuMonitorSetMigrationCapability(qemuMonitorPtr mon,
   qemuMonitorMigrationCaps capability,
   bool state);
+int qemuMonitorSetMigrationCapabilities(qemuMonitorPtr mon,
+virBitmapPtr caps,
+virBitmapPtr states);
 
 int qemuMonitorGetGICCapabilities(qemuMonitorPtr mon,
   virGICCapability **capabilities);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 57c2c4de0f..7ab73657a0 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6251,6 +6251,69 @@ qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon,
 }
 
 
+int
+qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
+virBitmapPtr caps,
+virBitmapPtr states)
+{
+int ret = -1;
+qemuMonitorMigrationCaps bit;
+virJSONValuePtr cmd = NULL;
+virJSONValuePtr reply = NULL;
+virJSONValuePtr cap = NULL;
+virJSONValuePtr array;
+
+if (!(array = virJSONValueNewArray()))
+goto cleanup;
+
+for (bit = 0; bit < QEMU_MONITOR_MIGRATION_CAPS_LAST; bit++) {
+bool supported = false;
+bool state = false;
+
+ignore_value(virBitmapGetBit(caps, bit, ));
+if (!supported)
+continue;
+
+ignore_value(virBitmapGetBit(states, bit, ));
+
+if (!(cap = virJSONValueNewObject()))
+goto cleanup;
+
+if (virJSONValueObjectAppendString(cap, "capability",
+   
qemuMonitorMigrationCapsTypeToString(bit)) < 0)
+goto cleanup;
+
+if (virJSONValueObjectAppendBoolean(cap, "state", state) < 0)
+goto cleanup;
+
+if (virJSONValueArrayAppend(array, cap) < 0)
+goto cleanup;
+
+cap = NULL;
+}
+
+cmd = qemuMonitorJSONMakeCommand("migrate-set-capabilities",
+ "a:capabilities", ,
+ NULL);
+if (!cmd)
+goto cleanup;
+
+if (qemuMonitorJSONCommand(mon, cmd, ) < 0)
+goto cleanup;
+
+if (qemuMonitorJSONCheckError(cmd, reply) < 0)
+goto cleanup;
+
+ret = 0;
+ cleanup:
+virJSONValueFree(array);
+virJSONValueFree(cap);
+virJSONValueFree(cmd);
+virJSONValueFree(reply);
+return ret;
+}
+
+
 /**
  * qemuMonitorJSONGetGICCapabilities:
  * @mon: QEMU JSON monitor
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 045df4919f..76e6738f44 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -148,6 +148,9 @@ int qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr 
mon,
 int qemuMonitorJSONSetMigrationCapability(qemuMonitorPtr mon,
   qemuMonitorMigrationCaps capability,
   bool state);
+int qemuMonitorJSONSetMigrationCapabilities(qemuMonitorPtr mon,
+virBitmapPtr caps,
+virBitmapPtr states);
 
 int qemuMonitorJSONGetGICCapabilities(qemuMonitorPtr mon,
   virGICCapability **capabilities);
-- 
2.17.0

--
libvir-list mailing list
libvir-list@redhat.com

[libvirt] [PATCH 33/68] qemu: Introduce qemuMigrationParty enum

2018-04-04 Thread Jiri Denemark
Some migration parameters and capabilities are supposed to be set on
both sides of migration while others should only be set on one side. For
example, CPU throttling parameters make no sense on the destination and
they can be used even if the destination is too old to support them.

To make qemuMigrationParamsFromFlags more general and usable on both
sides of migration, we need to tell it what side it's been called on.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_driver.c   | 3 ++-
 src/qemu/qemu_migration_params.c | 9 ++---
 src/qemu/qemu_migration_params.h | 8 +++-
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6e6fc130c5..d8a641f77d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12765,7 +12765,8 @@ qemuDomainMigratePerform3Params(virDomainPtr dom,
 if (nmigrate_disks < 0)
 goto cleanup;
 
-if (!(migParams = qemuMigrationParamsFromFlags(params, nparams, flags)))
+if (!(migParams = qemuMigrationParamsFromFlags(params, nparams, flags,
+   QEMU_MIGRATION_SOURCE)))
 goto cleanup;
 
 if (!(compression = qemuMigrationAnyCompressionParse(params, nparams, 
flags)))
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 862bab1af9..72e4e660b7 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -80,7 +80,8 @@ qemuMigrationParamsFree(qemuMigrationParamsPtr migParams)
 qemuMigrationParamsPtr
 qemuMigrationParamsFromFlags(virTypedParameterPtr params,
  int nparams,
- unsigned long flags)
+ unsigned long flags,
+ qemuMigrationParty party)
 {
 qemuMigrationParamsPtr migParams;
 
@@ -102,8 +103,10 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
 migParams->params.VAR ## _set = true; \
 } while (0)
 
-GET(AUTO_CONVERGE_INITIAL, cpuThrottleInitial);
-GET(AUTO_CONVERGE_INCREMENT, cpuThrottleIncrement);
+if (party == QEMU_MIGRATION_SOURCE) {
+GET(AUTO_CONVERGE_INITIAL, cpuThrottleInitial);
+GET(AUTO_CONVERGE_INCREMENT, cpuThrottleIncrement);
+}
 
 #undef GET
 
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index 292b30b8e7..062e6f37a9 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -50,6 +50,11 @@ struct _qemuMigrationCompression {
 typedef struct _qemuMigrationParams qemuMigrationParams;
 typedef qemuMigrationParams *qemuMigrationParamsPtr;
 
+typedef enum {
+QEMU_MIGRATION_SOURCE = (1 << 0),
+QEMU_MIGRATION_DESTINATION = (1 << 1),
+} qemuMigrationParty;
+
 
 qemuMigrationParamsPtr
 qemuMigrationParamsNew(void);
@@ -57,7 +62,8 @@ qemuMigrationParamsNew(void);
 qemuMigrationParamsPtr
 qemuMigrationParamsFromFlags(virTypedParameterPtr params,
  int nparams,
- unsigned long flags);
+ unsigned long flags,
+ qemuMigrationParty party);
 
 void
 qemuMigrationParamsFree(qemuMigrationParamsPtr migParams);
-- 
2.17.0

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


[libvirt] [PATCH 11/68] qemu: Reset migration parameters in qemuMigrationSrcCleanup

2018-04-04 Thread Jiri Denemark
When connection to the client which controls a non-p2p migration gets
closed between Perform and Confirm phase, we don't know whether the
domain was successfully migrated or not. Thus, we have to leave the
domain paused and just cleanup the migration job and reset migration
parameters.

Previously we didn't reset the parameters and future save or snapshot
operations would see wrong environment (and could fail because of it) in
case the domain stayed running on the source host.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index a6f8e66891..73024d66c0 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1834,6 +1834,7 @@ qemuMigrationSrcCleanup(virDomainObjPtr vm,
 VIR_WARN("Migration of domain %s finished but we don't know if the"
  " domain was successfully started on destination or not",
  vm->def->name);
+qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT);
 /* clear the job and let higher levels decide what to do */
 qemuDomainObjDiscardAsyncJob(driver, vm);
 break;
-- 
2.17.0

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


[libvirt] [PATCH 37/68] qemu: Set always-on migration caps in ParamsCheck

2018-04-04 Thread Jiri Denemark
Some migration capabilities are always enabled if QEMU supports them. We
can just drop the explicit code for them and let
qemuMigrationParamsCheck automatically set such capabilities.

QEMU_MONITOR_MIGRATION_CAPS_EVENTS would normally be one of the always
on features, but it is the only feature we want to enable even for other
jobs which internally use migration (such as save and snapshot). Hence
this capability is set very early after libvirtd connects to QEMU
monitor.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c|  6 --
 src/qemu/qemu_migration_params.c | 28 
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index f3006d8aa4..bb8f506659 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3362,12 +3362,6 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
  migParams) < 0)
 goto error;
 
-if (qemuMigrationCapsGet(vm, 
QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER) &&
-qemuMigrationParamsSetCapability(vm,
- 
QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER,
- true, migParams) < 0)
-goto error;
-
 if (qemuMigrationParamsCheck(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
  migParams) < 0)
 goto error;
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index ac99fa29e1..3837bf5b68 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -43,6 +43,19 @@ struct _qemuMigrationParams {
 qemuMonitorMigrationParams params;
 };
 
+typedef struct _qemuMigrationParamsAlwaysOnItem 
qemuMigrationParamsAlwaysOnItem;
+struct _qemuMigrationParamsAlwaysOnItem {
+qemuMonitorMigrationCaps cap;
+int party; /* bit-wise OR of qemuMigrationParty */
+};
+
+/* Migration capabilities which should always be enabled as long as they
+ * are supported by QEMU. */
+static const qemuMigrationParamsAlwaysOnItem qemuMigrationParamsAlwaysOn[] = {
+{QEMU_MONITOR_MIGRATION_CAPS_PAUSE_BEFORE_SWITCHOVER,
+ QEMU_MIGRATION_SOURCE},
+};
+
 
 static qemuMigrationParamsPtr
 qemuMigrationParamsNew(void)
@@ -399,8 +412,15 @@ qemuMigrationParamsCheck(virQEMUDriverPtr driver,
 qemuDomainObjPrivatePtr priv = vm->privateData;
 qemuMigrationParamsPtr origParams = NULL;
 qemuMonitorMigrationCaps cap;
+qemuMigrationParty party;
+size_t i;
 int ret = -1;
 
+if (asyncJob == QEMU_ASYNC_JOB_MIGRATION_OUT)
+party = QEMU_MIGRATION_SOURCE;
+else
+party = QEMU_MIGRATION_DESTINATION;
+
 for (cap = 0; cap < QEMU_MONITOR_MIGRATION_CAPS_LAST; cap++) {
 bool state = false;
 
@@ -414,6 +434,14 @@ qemuMigrationParamsCheck(virQEMUDriverPtr driver,
 }
 }
 
+for (i = 0; i < ARRAY_CARDINALITY(qemuMigrationParamsAlwaysOn); i++) {
+if (qemuMigrationParamsAlwaysOn[i].party & party &&
+qemuMigrationCapsGet(vm, qemuMigrationParamsAlwaysOn[i].cap)) {
+ignore_value(virBitmapSetBit(migParams->caps,
+ qemuMigrationParamsAlwaysOn[i].cap));
+}
+}
+
 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
 return -1;
 
-- 
2.17.0

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


[libvirt] [PATCH 43/68] qemu: Move qemuMigrationAnyCompression*

2018-04-04 Thread Jiri Denemark
The code really belongs to qemu_migration_params.c.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c| 140 -
 src/qemu/qemu_migration.h|  19 
 src/qemu/qemu_migration_params.c | 147 +++
 src/qemu/qemu_migration_params.h |  11 +++
 4 files changed, 158 insertions(+), 159 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index fa220d6ce4..e338bd05f6 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -77,11 +77,6 @@ VIR_ENUM_IMPL(qemuMigrationJobPhase, 
QEMU_MIGRATION_PHASE_LAST,
   "finish3",
 );
 
-VIR_ENUM_IMPL(qemuMigrationCompressMethod, QEMU_MIGRATION_COMPRESS_LAST,
-  "xbzrle",
-  "mt",
-);
-
 static int
 qemuMigrationJobStart(virQEMUDriverPtr driver,
   virDomainObjPtr vm,
@@ -5442,141 +5437,6 @@ qemuMigrationDstErrorReport(virQEMUDriverPtr driver,
 }
 
 
-/* don't ever pass NULL params with non zero nparams */
-qemuMigrationCompressionPtr
-qemuMigrationAnyCompressionParse(virTypedParameterPtr params,
- int nparams,
- unsigned long flags)
-{
-size_t i;
-qemuMigrationCompressionPtr compression = NULL;
-
-if (VIR_ALLOC(compression) < 0)
-return NULL;
-
-for (i = 0; i < nparams; i++) {
-int method;
-
-if (STRNEQ(params[i].field, VIR_MIGRATE_PARAM_COMPRESSION))
-continue;
-
-method = qemuMigrationCompressMethodTypeFromString(params[i].value.s);
-if (method < 0) {
-virReportError(VIR_ERR_INVALID_ARG,
-   _("Unsupported compression method '%s'"),
-   params[i].value.s);
-goto error;
-}
-
-if (compression->methods & (1ULL << method)) {
-virReportError(VIR_ERR_INVALID_ARG,
-   _("Compression method '%s' is specified twice"),
-   params[i].value.s);
-goto error;
-}
-
-compression->methods |= 1ULL << method;
-}
-
-#define GET_PARAM(PARAM, TYPE, VALUE) \
-do { \
-int rc; \
-const char *par = VIR_MIGRATE_PARAM_COMPRESSION_ ## PARAM; \
- \
-if ((rc = virTypedParamsGet ## TYPE(params, nparams, \
-par, >VALUE)) < 0) \
-goto error; \
- \
-if (rc == 1) \
-compression->VALUE ## _set = true; \
-} while (0)
-
-if (params) {
-GET_PARAM(MT_LEVEL, Int, level);
-GET_PARAM(MT_THREADS, Int, threads);
-GET_PARAM(MT_DTHREADS, Int, dthreads);
-GET_PARAM(XBZRLE_CACHE, ULLong, xbzrle_cache);
-}
-
-#undef GET_PARAM
-
-if ((compression->level_set ||
- compression->threads_set ||
- compression->dthreads_set) &&
-!(compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_MT))) {
-virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("Turn multithread compression on to tune it"));
-goto error;
-}
-
-if (compression->xbzrle_cache_set &&
-!(compression->methods & (1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE))) {
-virReportError(VIR_ERR_INVALID_ARG, "%s",
-   _("Turn xbzrle compression on to tune it"));
-goto error;
-}
-
-if (!compression->methods && (flags & VIR_MIGRATE_COMPRESSED))
-compression->methods = 1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE;
-
-return compression;
-
- error:
-VIR_FREE(compression);
-return NULL;
-}
-
-int
-qemuMigrationAnyCompressionDump(qemuMigrationCompressionPtr compression,
-virTypedParameterPtr *params,
-int *nparams,
-int *maxparams,
-unsigned long *flags)
-{
-size_t i;
-
-if (compression->methods == 1ULL << QEMU_MIGRATION_COMPRESS_XBZRLE &&
-!compression->xbzrle_cache_set) {
-*flags |= VIR_MIGRATE_COMPRESSED;
-return 0;
-}
-
-for (i = 0; i < QEMU_MIGRATION_COMPRESS_LAST; ++i) {
-if ((compression->methods & (1ULL << i)) &&
-virTypedParamsAddString(params, nparams, maxparams,
-VIR_MIGRATE_PARAM_COMPRESSION,
-
qemuMigrationCompressMethodTypeToString(i)) < 0)
-return -1;
-}
-
-if (compression->level_set &&
-virTypedParamsAddInt(params, nparams, maxparams,
- VIR_MIGRATE_PARAM_COMPRESSION_MT_LEVEL,
- compression->level) < 0)
-return -1;
-
-if (compression->threads_set &&
-virTypedParamsAddInt(params, nparams, maxparams,
- VIR_MIGRATE_PARAM_COMPRESSION_MT_THREADS,
- compression->threads) < 0)
-return 

[libvirt] [PATCH 51/68] qemu: Move migration parameters JSON parsing

2018-04-04 Thread Jiri Denemark
We want to have all migration parameters parsing and formatting at once
place, i.e., in qemu_migration_params.c.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 74 +---
 src/qemu/qemu_monitor.c  | 13 +-
 src/qemu/qemu_monitor.h  |  2 +-
 src/qemu/qemu_monitor_json.c | 51 ++
 src/qemu/qemu_monitor_json.h |  2 +-
 5 files changed, 85 insertions(+), 57 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index fd93d9cb39..6908aef24d 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -311,6 +311,67 @@ qemuMigrationParamsDump(qemuMigrationParamsPtr migParams,
 }
 
 
+static qemuMigrationParamsPtr
+qemuMigrationParamsFromJSON(virJSONValuePtr params)
+{
+qemuMigrationParamsPtr migParams = NULL;
+
+if (!(migParams = qemuMigrationParamsNew()))
+return NULL;
+
+if (!params)
+return migParams;
+
+#define PARSE_SET(API, VAR, FIELD) \
+do { \
+if (API(params, FIELD, >params.VAR) == 0) \
+migParams->params.VAR ## _set = true; \
+} while (0)
+
+#define PARSE_INT(VAR, FIELD) \
+PARSE_SET(virJSONValueObjectGetNumberInt, VAR, FIELD)
+
+#define PARSE_ULONG(VAR, FIELD) \
+PARSE_SET(virJSONValueObjectGetNumberUlong, VAR, FIELD)
+
+#define PARSE_BOOL(VAR, FIELD) \
+PARSE_SET(virJSONValueObjectGetBoolean, VAR, FIELD)
+
+#define PARSE_STR(VAR, FIELD) \
+do { \
+const char *str; \
+if ((str = virJSONValueObjectGetString(params, FIELD))) { \
+if (VIR_STRDUP(migParams->params.VAR, str) < 0) \
+goto error; \
+} \
+} while (0)
+
+PARSE_INT(compressLevel, "compress-level");
+PARSE_INT(compressThreads, "compress-threads");
+PARSE_INT(decompressThreads, "decompress-threads");
+PARSE_INT(cpuThrottleInitial, "cpu-throttle-initial");
+PARSE_INT(cpuThrottleIncrement, "cpu-throttle-increment");
+PARSE_STR(tlsCreds, "tls-creds");
+PARSE_STR(tlsHostname, "tls-hostname");
+PARSE_ULONG(maxBandwidth, "max-bandwidth");
+PARSE_ULONG(downtimeLimit, "downtime-limit");
+PARSE_BOOL(blockIncremental, "block-incremental");
+PARSE_ULONG(xbzrleCacheSize, "xbzrle-cache-size");
+
+#undef PARSE_SET
+#undef PARSE_INT
+#undef PARSE_ULONG
+#undef PARSE_BOOL
+#undef PARSE_STR
+
+return migParams;
+
+ error:
+qemuMigrationParamsFree(migParams);
+return NULL;
+}
+
+
 /**
  * qemuMigrationParamsApply
  * @driver: qemu driver
@@ -524,28 +585,27 @@ qemuMigrationParamsFetch(virQEMUDriverPtr driver,
  qemuMigrationParamsPtr *migParams)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
-qemuMigrationParamsPtr params = NULL;
+virJSONValuePtr jsonParams = NULL;
 int ret = -1;
 int rc;
 
 *migParams = NULL;
 
-if (!(params = qemuMigrationParamsNew()))
-return -1;
-
 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
 goto cleanup;
 
-rc = qemuMonitorGetMigrationParams(priv->mon, >params);
+rc = qemuMonitorGetMigrationParams(priv->mon, );
 
 if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
 goto cleanup;
 
-VIR_STEAL_PTR(*migParams, params);
+if (!(*migParams = qemuMigrationParamsFromJSON(jsonParams)))
+goto cleanup;
+
 ret = 0;
 
  cleanup:
-qemuMigrationParamsFree(params);
+virJSONValueFree(jsonParams);
 return ret;
 }
 
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 18b54e2da8..411ce28787 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2622,9 +2622,20 @@ qemuMonitorSetMigrationCacheSize(qemuMonitorPtr mon,
 }
 
 
+/**
+ * qemuMonitorGetMigrationParams:
+ * @mon: Pointer to the monitor object.
+ * @params: Where to store migration parameters.
+ *
+ * If QEMU does not support querying migration parameters, the function will
+ * set @params to NULL and return 0 (success). The caller is responsible for
+ * freeing @params.
+ *
+ * Returns 0 on success, -1 on error.
+ */
 int
 qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
-  qemuMonitorMigrationParamsPtr params)
+  virJSONValuePtr *params)
 {
 QEMU_CHECK_MONITOR_JSON(mon);
 
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 2bb4dbc667..261f3192f5 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -679,7 +679,7 @@ struct _qemuMonitorMigrationParams {
 };
 
 int qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
-  qemuMonitorMigrationParamsPtr params);
+  virJSONValuePtr *params);
 int qemuMonitorSetMigrationParams(qemuMonitorPtr mon,
   qemuMonitorMigrationParamsPtr params);
 
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 

[libvirt] [PATCH 52/68] qemu: Move migration parameters JSON formatting

2018-04-04 Thread Jiri Denemark
We want to have all migration parameters parsing and formatting at one
place, i.e., in qemu_migration_params.c.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 68 +++-
 src/qemu/qemu_monitor.c  | 35 
 src/qemu/qemu_monitor.h  |  2 +-
 src/qemu/qemu_monitor_json.c | 56 ++
 src/qemu/qemu_monitor_json.h |  2 +-
 5 files changed, 89 insertions(+), 74 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 6908aef24d..0c8e44f644 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -372,6 +372,61 @@ qemuMigrationParamsFromJSON(virJSONValuePtr params)
 }
 
 
+static virJSONValuePtr
+qemuMigrationParamsToJSON(qemuMigrationParamsPtr migParams)
+{
+virJSONValuePtr params = NULL;
+
+if (!(params = virJSONValueNewObject()))
+return NULL;
+
+#define APPEND(VALID, API, VAR, FIELD) \
+do { \
+if (VALID && API(params, FIELD, migParams->params.VAR) < 0) \
+goto error; \
+} while (0)
+
+#define APPEND_INT(VAR, FIELD) \
+APPEND(migParams->params.VAR ## _set, \
+   virJSONValueObjectAppendNumberInt, VAR, FIELD)
+
+#define APPEND_STR(VAR, FIELD) \
+APPEND(migParams->params.VAR, \
+   virJSONValueObjectAppendString, VAR, FIELD)
+
+#define APPEND_ULONG(VAR, FIELD) \
+APPEND(migParams->params.VAR ## _set, \
+   virJSONValueObjectAppendNumberUlong, VAR, FIELD)
+
+#define APPEND_BOOL(VAR, FIELD) \
+APPEND(migParams->params.VAR ## _set, \
+   virJSONValueObjectAppendBoolean, VAR, FIELD)
+
+APPEND_INT(compressLevel, "compress-level");
+APPEND_INT(compressThreads, "compress-threads");
+APPEND_INT(decompressThreads, "decompress-threads");
+APPEND_INT(cpuThrottleInitial, "cpu-throttle-initial");
+APPEND_INT(cpuThrottleIncrement, "cpu-throttle-increment");
+APPEND_STR(tlsCreds, "tls-creds");
+APPEND_STR(tlsHostname, "tls-hostname");
+APPEND_ULONG(maxBandwidth, "max-bandwidth");
+APPEND_ULONG(downtimeLimit, "downtime-limit");
+APPEND_BOOL(blockIncremental, "block-incremental");
+APPEND_ULONG(xbzrleCacheSize, "xbzrle-cache-size");
+
+#undef APPEND
+#undef APPEND_INT
+#undef APPEND_STR
+#undef APPEND_ULONG
+
+return params;
+
+ error:
+virJSONValueFree(params);
+return NULL;
+}
+
+
 /**
  * qemuMigrationParamsApply
  * @driver: qemu driver
@@ -391,6 +446,7 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
 bool xbzrleCacheSize_old = false;
+virJSONValuePtr params = NULL;
 int ret = -1;
 
 if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
@@ -414,10 +470,16 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
 migParams->params.xbzrleCacheSize_set = false;
 }
 
-if (qemuMonitorSetMigrationParams(priv->mon, >params) < 0)
+if (!(params = qemuMigrationParamsToJSON(migParams)))
 goto cleanup;
 
-ret = 0;
+if (virJSONValueObjectKeysNumber(params) == 0) {
+ret = 0;
+goto cleanup;
+}
+
+ret = qemuMonitorSetMigrationParams(priv->mon, params);
+params = NULL;
 
  cleanup:
 if (qemuDomainObjExitMonitor(driver, vm) < 0)
@@ -426,6 +488,8 @@ qemuMigrationParamsApply(virQEMUDriverPtr driver,
 if (xbzrleCacheSize_old)
 migParams->params.xbzrleCacheSize_set = true;
 
+virJSONValueFree(params);
+
 return ret;
 }
 
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 411ce28787..641465f227 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -2642,29 +2642,28 @@ qemuMonitorGetMigrationParams(qemuMonitorPtr mon,
 return qemuMonitorJSONGetMigrationParams(mon, params);
 }
 
+
+/**
+ * qemuMonitorSetMigrationParams:
+ * @mon: Pointer to the monitor object.
+ * @params: Migration parameters.
+ *
+ * The @params object is consumed and should not be referenced by the caller
+ * after this function returns.
+ *
+ * Returns 0 on success, -1 on error.
+ */
 int
 qemuMonitorSetMigrationParams(qemuMonitorPtr mon,
-  qemuMonitorMigrationParamsPtr params)
+  virJSONValuePtr params)
 {
-VIR_DEBUG("compressLevel=%d:%d compressThreads=%d:%d "
-  "decompressThreads=%d:%d cpuThrottleInitial=%d:%d "
-  "cpuThrottleIncrement=%d:%d tlsCreds=%s tlsHostname=%s "
-  "maxBandwidth=%d:%llu downtimeLimit=%d:%llu "
-  "blockIncremental=%d:%d xbzrleCacheSize=%d:%llu",
-  params->compressLevel_set, params->compressLevel,
-  params->compressThreads_set, params->compressThreads,
-  params->decompressThreads_set, params->decompressThreads,
-  params->cpuThrottleInitial_set, params->cpuThrottleInitial,
-  params->cpuThrottleIncrement_set, 

[libvirt] [PATCH 18/68] qemu: Rename qemuMigrationParamsSetEmptyTLS

2018-04-04 Thread Jiri Denemark
The new name is qemuMigrationParamsDisableTLS.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration.c| 4 ++--
 src/qemu/qemu_migration_params.c | 6 +++---
 src/qemu/qemu_migration_params.h | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 8cd5426ed9..f007f7e05a 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2465,7 +2465,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver,
 goto stopjob;
 
 } else {
-if (qemuMigrationParamsSetEmptyTLS(vm, migParams) < 0)
+if (qemuMigrationParamsDisableTLS(vm, migParams) < 0)
 goto stopjob;
 }
 
@@ -3427,7 +3427,7 @@ qemuMigrationSrcRun(virQEMUDriverPtr driver,
 goto error;
 }
 } else {
-if (qemuMigrationParamsSetEmptyTLS(vm, migParams) < 0)
+if (qemuMigrationParamsDisableTLS(vm, migParams) < 0)
 goto error;
 }
 
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index fd4fc6c6a8..26f3f29d16 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -210,7 +210,7 @@ qemuMigrationParamsAddTLSObjects(virQEMUDriverPtr driver,
 }
 
 
-/* qemuMigrationParamsSetEmptyTLS
+/* qemuMigrationParamsDisableTLS
  * @vm: domain object
  * @migParams: Pointer to a migration parameters block
  *
@@ -221,8 +221,8 @@ qemuMigrationParamsAddTLSObjects(virQEMUDriverPtr driver,
  * Returns 0 on success, -1 on failure
  */
 int
-qemuMigrationParamsSetEmptyTLS(virDomainObjPtr vm,
-   qemuMigrationParamsPtr migParams)
+qemuMigrationParamsDisableTLS(virDomainObjPtr vm,
+  qemuMigrationParamsPtr migParams)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
 
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index b8c29cddd8..281c2ae687 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -82,8 +82,8 @@ qemuMigrationParamsAddTLSObjects(virQEMUDriverPtr driver,
  qemuMigrationParamsPtr migParams);
 
 int
-qemuMigrationParamsSetEmptyTLS(virDomainObjPtr vm,
-   qemuMigrationParamsPtr migParams);
+qemuMigrationParamsDisableTLS(virDomainObjPtr vm,
+  qemuMigrationParamsPtr migParams);
 
 int
 qemuMigrationParamsSetCompression(virQEMUDriverPtr driver,
-- 
2.17.0

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


[libvirt] [PATCH 14/68] qemu: Pass job object to qemuProcessRecoverMigration{In, Out}

2018-04-04 Thread Jiri Denemark
Currently, only job->phase is passed and both APIs will need to look at
more details about the job.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_process.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 31aba16b31..871f1143f2 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3030,7 +3030,7 @@ qemuProcessUpdateState(virQEMUDriverPtr driver, 
virDomainObjPtr vm)
 static int
 qemuProcessRecoverMigrationIn(virQEMUDriverPtr driver,
   virDomainObjPtr vm,
-  qemuMigrationJobPhase phase,
+  const qemuDomainJobObj *job,
   virDomainState state,
   int reason)
 {
@@ -3039,7 +3039,7 @@ qemuProcessRecoverMigrationIn(virQEMUDriverPtr driver,
 (state == VIR_DOMAIN_RUNNING &&
  reason == VIR_DOMAIN_RUNNING_POSTCOPY);
 
-switch (phase) {
+switch ((qemuMigrationJobPhase) job->phase) {
 case QEMU_MIGRATION_PHASE_NONE:
 case QEMU_MIGRATION_PHASE_PERFORM2:
 case QEMU_MIGRATION_PHASE_BEGIN3:
@@ -3088,7 +3088,7 @@ qemuProcessRecoverMigrationIn(virQEMUDriverPtr driver,
 static int
 qemuProcessRecoverMigrationOut(virQEMUDriverPtr driver,
virDomainObjPtr vm,
-   qemuMigrationJobPhase phase,
+   const qemuDomainJobObj *job,
virDomainState state,
int reason,
unsigned int *stopFlags)
@@ -3098,7 +3098,7 @@ qemuProcessRecoverMigrationOut(virQEMUDriverPtr driver,
  reason == VIR_DOMAIN_PAUSED_POSTCOPY_FAILED);
 bool resume = false;
 
-switch (phase) {
+switch ((qemuMigrationJobPhase) job->phase) {
 case QEMU_MIGRATION_PHASE_NONE:
 case QEMU_MIGRATION_PHASE_PREPARE:
 case QEMU_MIGRATION_PHASE_FINISH2:
@@ -3193,13 +3193,13 @@ qemuProcessRecoverJob(virQEMUDriverPtr driver,
 
 switch (job->asyncJob) {
 case QEMU_ASYNC_JOB_MIGRATION_OUT:
-if (qemuProcessRecoverMigrationOut(driver, vm, job->phase,
+if (qemuProcessRecoverMigrationOut(driver, vm, job,
state, reason, stopFlags) < 0)
 return -1;
 break;
 
 case QEMU_ASYNC_JOB_MIGRATION_IN:
-if (qemuProcessRecoverMigrationIn(driver, vm, job->phase,
+if (qemuProcessRecoverMigrationIn(driver, vm, job,
   state, reason) < 0)
 return -1;
 break;
-- 
2.17.0

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


[libvirt] [PATCH 13/68] qemu: Typedef struct qemuDomainJobObj

2018-04-04 Thread Jiri Denemark
Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_domain.c  | 6 +++---
 src/qemu/qemu_domain.h  | 8 +---
 src/qemu/qemu_process.c | 4 ++--
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e44073f441..7528ec9dc8 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -309,7 +309,7 @@ qemuDomainObjInitJob(qemuDomainObjPrivatePtr priv)
 static void
 qemuDomainObjResetJob(qemuDomainObjPrivatePtr priv)
 {
-struct qemuDomainJobObj *job = >job;
+qemuDomainJobObjPtr job = >job;
 
 job->active = QEMU_JOB_NONE;
 job->owner = 0;
@@ -320,7 +320,7 @@ qemuDomainObjResetJob(qemuDomainObjPrivatePtr priv)
 static void
 qemuDomainObjResetAsyncJob(qemuDomainObjPrivatePtr priv)
 {
-struct qemuDomainJobObj *job = >job;
+qemuDomainJobObjPtr job = >job;
 
 job->asyncJob = QEMU_ASYNC_JOB_NONE;
 job->asyncOwner = 0;
@@ -342,7 +342,7 @@ qemuDomainObjResetAsyncJob(qemuDomainObjPrivatePtr priv)
 
 void
 qemuDomainObjRestoreJob(virDomainObjPtr obj,
-struct qemuDomainJobObj *job)
+qemuDomainJobObjPtr job)
 {
 qemuDomainObjPrivatePtr priv = obj->privateData;
 
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 1828b64284..2c474ae4a4 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -154,7 +154,9 @@ struct _qemuDomainJobInfo {
 qemuDomainMirrorStats mirrorStats;
 };
 
-struct qemuDomainJobObj {
+typedef struct _qemuDomainJobObj qemuDomainJobObj;
+typedef qemuDomainJobObj *qemuDomainJobObjPtr;
+struct _qemuDomainJobObj {
 virCond cond;   /* Use to coordinate jobs */
 qemuDomainJob active;   /* Currently running job */
 unsigned long long owner;   /* Thread id which set current job */
@@ -254,7 +256,7 @@ typedef qemuDomainObjPrivate *qemuDomainObjPrivatePtr;
 struct _qemuDomainObjPrivate {
 virQEMUDriverPtr driver;
 
-struct qemuDomainJobObj job;
+qemuDomainJobObj job;
 
 virBitmapPtr namespaces;
 
@@ -513,7 +515,7 @@ void qemuDomainObjSetJobPhase(virQEMUDriverPtr driver,
 void qemuDomainObjSetAsyncJobMask(virDomainObjPtr obj,
   unsigned long long allowedJobs);
 void qemuDomainObjRestoreJob(virDomainObjPtr obj,
- struct qemuDomainJobObj *job);
+ qemuDomainJobObjPtr job);
 void qemuDomainObjDiscardAsyncJob(virQEMUDriverPtr driver,
   virDomainObjPtr obj);
 void qemuDomainObjReleaseAsyncJob(virDomainObjPtr obj);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 3a7f8ed105..31aba16b31 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3182,7 +3182,7 @@ qemuProcessRecoverMigrationOut(virQEMUDriverPtr driver,
 static int
 qemuProcessRecoverJob(virQEMUDriverPtr driver,
   virDomainObjPtr vm,
-  const struct qemuDomainJobObj *job,
+  const qemuDomainJobObj *job,
   unsigned int *stopFlags)
 {
 qemuDomainObjPrivatePtr priv = vm->privateData;
@@ -7264,7 +7264,7 @@ qemuProcessReconnect(void *opaque)
 virQEMUDriverPtr driver = data->driver;
 virDomainObjPtr obj = data->obj;
 qemuDomainObjPrivatePtr priv;
-struct qemuDomainJobObj oldjob;
+qemuDomainJobObj oldjob;
 int state;
 int reason;
 virQEMUDriverConfigPtr cfg;
-- 
2.17.0

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


[libvirt] [PATCH 08/68] qemu: Drop qemuMigrationParamsClear

2018-04-04 Thread Jiri Denemark
It's no longer used since we do not store the struct on a stack anymore.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_migration_params.c | 12 +---
 src/qemu/qemu_migration_params.h |  3 ---
 2 files changed, 1 insertion(+), 14 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 1b4aa46854..c91216a2a4 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -51,23 +51,13 @@ qemuMigrationParamsNew(void)
 
 
 void
-qemuMigrationParamsClear(qemuMonitorMigrationParamsPtr migParams)
+qemuMigrationParamsFree(qemuMonitorMigrationParamsPtr migParams)
 {
 if (!migParams)
 return;
 
 VIR_FREE(migParams->tlsCreds);
 VIR_FREE(migParams->tlsHostname);
-}
-
-
-void
-qemuMigrationParamsFree(qemuMonitorMigrationParamsPtr migParams)
-{
-if (!migParams)
-return;
-
-qemuMigrationParamsClear(migParams);
 VIR_FREE(migParams);
 }
 
diff --git a/src/qemu/qemu_migration_params.h b/src/qemu/qemu_migration_params.h
index bc608905cc..18802ac3e4 100644
--- a/src/qemu/qemu_migration_params.h
+++ b/src/qemu/qemu_migration_params.h
@@ -36,9 +36,6 @@ qemuMigrationParamsFromFlags(virTypedParameterPtr params,
  int nparams,
  unsigned long flags);
 
-void
-qemuMigrationParamsClear(qemuMonitorMigrationParamsPtr migParams);
-
 void
 qemuMigrationParamsFree(qemuMonitorMigrationParamsPtr migParams);
 
-- 
2.17.0

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


[libvirt] [PATCH 00/68] qemu: Refactor migration parameters

2018-04-04 Thread Jiri Denemark
This series changes the way we handle migration parameters and
capabilities with several goals:

- make it all consistent and avoid storing the same parameters in
  several structs
- reduce the number of QMP commands we use for setting migration
  capabilities
- concentrate the logic in a separate file and make the code for
  migration parameters and capabilities in qemu_migration.c less
  complicated
- reset all parameters and capabilities at the end of migration
- make adding new parameters and capabilities easier

Jiri Denemark (68):
  qemu: Move qemuDomainCheckMigrationCapabilities
  qemu: Rename qemuMigrationAnyCapsGet as qemuMigrationCapsGet
  qemu: Rename qemuMigrationParams
  qemu: New file for all APIs related to migration parameters
  qemu: Reindent qemuMigrationParamsSetEmptyTLS
  qemu: Make qemuMigrationParamsFree follow common pattern
  qemu: Allocate struct for migration parameters
  qemu: Drop qemuMigrationParamsClear
  qemu: Move qemuMigrationCompression struct
  qemu: Introduce qemuMigrationParams struct
  qemu: Reset migration parameters in qemuMigrationSrcCleanup
  qemu: Store original migration params in job
  qemu: Typedef struct qemuDomainJobObj
  qemu: Pass job object to qemuProcessRecoverMigration{In,Out}
  qemu: Reset all migration parameters
  qemu: Drop qemuMigrationParamsCheckSetupTLS
  qemu: Drop qemuMigrationParamsCheckTLSCreds
  qemu: Rename qemuMigrationParamsSetEmptyTLS
  qemu: Rename qemuMigrationParamsAddTLSObjects
  qemu: Set tlsHostname inside qemuMigrationParamsEnableTLS
  qemu: Hide cfg inside qemuMigrationParamsEnableTLS
  qemu: Rename qemuMigrationParamsSet
  qemu: Hide internals of qemuMigrationParams struct
  qemu: Introduce qemuMonitorSetMigrationCapabilities
  qemu: Set migration caps via migration params APIs
  qemu: Do not use qemuMonitorSetMigrationCapability
  qemu: Drop unused qemuMonitorSetMigrationCapability
  qemu: Add support for xbzrle-cache-size migration parameter
  qemu: Set XBZRLE cache size via migration parameters
  qemu: Move ParamsCheck closer to ParamsApply on Dst side
  qemu: Move ParamsCheck closer to ParamsApply on Src side
  qemu: Check supported caps in qemuMigrationParamsCheck
  qemu: Introduce qemuMigrationParty enum
  qemu: Use qemuMigrationParamsFromFlags everywhere
  qemu: Hide qemuMigrationParamsNew
  qemu: Drop qemuMigrationParamsSetPostCopy
  qemu: Set always-on migration caps in ParamsCheck
  qemu: Set migration capabilities automatically
  qemu: Call qemuMigrationAnyCompressionParse only from driver
  qemu: Generalize macro for getting VIR_MIGRATE_* typed params
  qemu: Drop qemuMigrationParamsSetCapability
  qemu: Move qemuMigrationParamsSetCompression
  qemu: Move qemuMigrationAnyCompression*
  qemu: Hide qemuMigrationParamsSetCompression
  qemu: Replace qemuMigrationAnyCompressionDump
  qemu: Drop qemuMigrationCompression structure
  qemu: Introduce qemuMigrationParamsFetch
  qemu: Limit usage of qemuMonitorMigrationParams
  qemumonitorjsontest: Drop migration params test
  util: Introduce virJSONValueObjectStealObject
  qemu: Move migration parameters JSON parsing
  qemu: Move migration parameters JSON formatting
  qemu: Move qemuMonitorMigrationParams structure
  qemu: Refactor qemuMigrationParams
  qemu: Generalize qemuMigrationParamsGetDowntimeLimit
  qemu: Set migration parameters automatically
  qemu: Properly reset migration params when libvirtd restarts
  qemu: Export qemuMigrationParams{To,From}JSON for tests
  tests: Add tests for QEMU migration parameters
  qemumigparamstest: Add basic test data
  qemumigparamstest: Add test data for TLS parameters
  qemu: Store API flags for async jobs in qemuDomainJobObj
  qemu: Properly avoid cancelling memory-only dump
  qemu: Drop priv->job.dump_memory_only bool
  qemu: Drop priv->job.postcopyEnabled bool
  qemu: Store API flags for async jobs in status XML
  qemu: Don't delete TLS objects unless TLS migration was requested
  qemuxml2xmltest: Add status XML tests for migration params

 po/POTFILES.in|1 +
 src/libvirt_private.syms  |1 +
 src/qemu/Makefile.inc.am  |3 +
 src/qemu/qemu_domain.c|  110 +-
 src/qemu/qemu_domain.h|   25 +-
 src/qemu/qemu_driver.c|  175 +--
 src/qemu/qemu_migration.c |  965 +++---
 src/qemu/qemu_migration.h |   72 +-
 src/qemu/qemu_migration_params.c  | 1139 +
 src/qemu/qemu_migration_params.h  |  130 ++
 src/qemu/qemu_migration_paramspriv.h  |   31 +
 src/qemu/qemu_monitor.c   |   64 +-
 src/qemu/qemu_monitor.h   |   43 +-
 src/qemu/qemu_monitor_json.c  |  153 +--
 src/qemu/qemu_monitor_json.h  |   10 +-
 src/qemu/qemu_process.c   |   30 +-
 src/qemu/qemu_process.h   |3 +-
 

[libvirt] [PATCH 01/68] qemu: Move qemuDomainCheckMigrationCapabilities

2018-04-04 Thread Jiri Denemark
Since the function is tightly connected to migration, it was renamed as
qemuMigrationCapsCheck and moved to qemu_migration.c.

Signed-off-by: Jiri Denemark 
---
 src/qemu/qemu_domain.c| 72 ---
 src/qemu/qemu_domain.h|  4 ---
 src/qemu/qemu_migration.c | 72 +++
 src/qemu/qemu_migration.h |  6 
 src/qemu/qemu_process.c   |  2 +-
 5 files changed, 79 insertions(+), 77 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 9d1c33b54a..a1bbe256f5 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -11781,78 +11781,6 @@ qemuDomainCheckCCWS390AddressSupport(const 
virDomainDef *def,
 }
 
 
-int
-qemuDomainCheckMigrationCapabilities(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- qemuDomainAsyncJob asyncJob)
-{
-qemuDomainObjPrivatePtr priv = vm->privateData;
-char **caps = NULL;
-char **capStr;
-int ret = -1;
-int rc;
-
-if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
-return -1;
-
-rc = qemuMonitorGetMigrationCapabilities(priv->mon, );
-
-if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
-goto cleanup;
-
-if (!caps) {
-ret = 0;
-goto cleanup;
-}
-
-priv->migrationCaps = virBitmapNew(QEMU_MONITOR_MIGRATION_CAPS_LAST);
-if (!priv->migrationCaps)
-goto cleanup;
-
-for (capStr = caps; *capStr; capStr++) {
-int cap = qemuMonitorMigrationCapsTypeFromString(*capStr);
-
-if (cap < 0) {
-VIR_DEBUG("Unknown migration capability: '%s'", *capStr);
-} else {
-ignore_value(virBitmapSetBit(priv->migrationCaps, cap));
-VIR_DEBUG("Found migration capability: '%s'", *capStr);
-}
-}
-
-if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATION_EVENT)) {
-if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
-goto cleanup;
-
-rc = qemuMonitorSetMigrationCapability(priv->mon,
-   
QEMU_MONITOR_MIGRATION_CAPS_EVENTS,
-   true);
-
-if (qemuDomainObjExitMonitor(driver, vm) < 0)
-goto cleanup;
-
-if (rc < 0) {
-virResetLastError();
-VIR_DEBUG("Cannot enable migration events; clearing capability");
-virQEMUCapsClear(priv->qemuCaps, QEMU_CAPS_MIGRATION_EVENT);
-}
-}
-
-/* Migration events capability must always be enabled, clearing it from
- * migration capabilities bitmap makes sure it won't be touched anywhere
- * else.
- */
-ignore_value(virBitmapClearBit(priv->migrationCaps,
-   QEMU_MONITOR_MIGRATION_CAPS_EVENTS));
-
-ret = 0;
-
- cleanup:
-virStringListFree(caps);
-return ret;
-}
-
-
 /**
  * qemuDomainPrepareDiskSourceChain:
  *
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 21e12f6594..415b2ca093 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -988,10 +988,6 @@ bool qemuDomainCheckCCWS390AddressSupport(const 
virDomainDef *def,
 const char *devicename);
 
 int
-qemuDomainCheckMigrationCapabilities(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- qemuDomainAsyncJob asyncJob);
-int
 qemuDomainPrepareDiskSourceChain(virDomainDiskDefPtr disk,
  virStorageSourcePtr src,
  virQEMUDriverConfigPtr cfg,
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index e5231555de..a2a6616862 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -6162,6 +6162,78 @@ qemuMigrationSrcFetchMirrorStats(virQEMUDriverPtr driver,
 }
 
 
+int
+qemuMigrationCapsCheck(virQEMUDriverPtr driver,
+   virDomainObjPtr vm,
+   qemuDomainAsyncJob asyncJob)
+{
+qemuDomainObjPrivatePtr priv = vm->privateData;
+char **caps = NULL;
+char **capStr;
+int ret = -1;
+int rc;
+
+if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
+return -1;
+
+rc = qemuMonitorGetMigrationCapabilities(priv->mon, );
+
+if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
+goto cleanup;
+
+if (!caps) {
+ret = 0;
+goto cleanup;
+}
+
+priv->migrationCaps = virBitmapNew(QEMU_MONITOR_MIGRATION_CAPS_LAST);
+if (!priv->migrationCaps)
+goto cleanup;
+
+for (capStr = caps; *capStr; capStr++) {
+int cap = qemuMonitorMigrationCapsTypeFromString(*capStr);
+
+if (cap < 0) {
+VIR_DEBUG("Unknown migration capability: '%s'", *capStr);
+} else {
+ignore_value(virBitmapSetBit(priv->migrationCaps, cap));
+

[libvirt] [PATCH 04/68] qemu: New file for all APIs related to migration parameters

2018-04-04 Thread Jiri Denemark
In the end, this will allow us to have most of the logic around
migration parameters done in one place.

Signed-off-by: Jiri Denemark 
---
 po/POTFILES.in   |   1 +
 src/qemu/Makefile.inc.am |   2 +
 src/qemu/qemu_driver.c   |   1 +
 src/qemu/qemu_migration.c| 421 +---
 src/qemu/qemu_migration.h|  24 +-
 src/qemu/qemu_migration_params.c | 454 +++
 src/qemu/qemu_migration_params.h |  82 ++
 src/qemu/qemu_process.c  |   1 +
 8 files changed, 550 insertions(+), 436 deletions(-)
 create mode 100644 src/qemu/qemu_migration_params.c
 create mode 100644 src/qemu/qemu_migration_params.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index d84859a4e3..0b62126a19 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -136,6 +136,7 @@ src/qemu/qemu_hotplug.c
 src/qemu/qemu_interface.c
 src/qemu/qemu_migration.c
 src/qemu/qemu_migration_cookie.c
+src/qemu/qemu_migration_params.c
 src/qemu/qemu_monitor.c
 src/qemu/qemu_monitor_json.c
 src/qemu/qemu_monitor_text.c
diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am
index 8ef290a6c1..25706ba4bc 100644
--- a/src/qemu/Makefile.inc.am
+++ b/src/qemu/Makefile.inc.am
@@ -33,6 +33,8 @@ QEMU_DRIVER_SOURCES = \
qemu/qemu_migration.h \
qemu/qemu_migration_cookie.c \
qemu/qemu_migration_cookie.h \
+qemu/qemu_migration_params.c \
+qemu/qemu_migration_params.h \
qemu/qemu_monitor.c \
qemu/qemu_monitor.h \
qemu/qemu_monitor_text.c \
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f7ad211077..519bd767c1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -57,6 +57,7 @@
 #include "qemu_monitor.h"
 #include "qemu_process.h"
 #include "qemu_migration.h"
+#include "qemu_migration_params.h"
 #include "qemu_blockjob.h"
 #include "qemu_security.h"
 
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index f88ac02f2f..4bdaa67ea1 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -29,6 +29,7 @@
 
 #include "qemu_migration.h"
 #include "qemu_migration_cookie.h"
+#include "qemu_migration_params.h"
 #include "qemu_monitor.h"
 #include "qemu_domain.h"
 #include "qemu_process.h"
@@ -81,8 +82,6 @@ VIR_ENUM_IMPL(qemuMigrationCompressMethod, 
QEMU_MIGRATION_COMPRESS_LAST,
   "mt",
 );
 
-#define QEMU_MIGRATION_TLS_ALIAS_BASE "libvirt_migrate"
-
 static int
 qemuMigrationJobStart(virQEMUDriverPtr driver,
   virDomainObjPtr vm,
@@ -115,156 +114,6 @@ qemuMigrationJobFinish(virQEMUDriverPtr driver,
virDomainObjPtr obj)
 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
-/* qemuMigrationParamsCheckTLSCreds
- * @driver: pointer to qemu driver
- * @vm: domain object
- * @asyncJob: migration job to join
- *
- * Query the migration parameters looking for the 'tls-creds' parameter.
- * If found, then we can support setting or clearing the parameters and thus
- * can support TLS for migration.
- *
- * Returns 0 if we were able to successfully fetch the params and
- * additionally if the tls-creds parameter exists, saves it in the
- * private domain structure. Returns -1 on failure.
- */
-static int
-qemuMigrationParamsCheckTLSCreds(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
- qemuDomainAsyncJob asyncJob)
-{
-int ret = -1;
-qemuDomainObjPrivatePtr priv = vm->privateData;
-qemuMonitorMigrationParams migParams = { 0 };
-
-if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
-return -1;
-
-if (qemuMonitorGetMigrationParams(priv->mon, ) < 0)
-goto cleanup;
-
-/* NB: Could steal NULL pointer too! Let caller decide what to do. */
-VIR_STEAL_PTR(priv->migTLSAlias, migParams.tlsCreds);
-
-ret = 0;
-
- cleanup:
-if (qemuDomainObjExitMonitor(driver, vm) < 0)
-ret = -1;
-
-qemuMigrationParamsClear();
-
-return ret;
-}
-
-
-/* qemuMigrationParamsCheckSetupTLS
- * @driver: pointer to qemu driver
- * @vm: domain object
- * @cfg: configuration pointer
- * @asyncJob: migration job to join
- *
- * Check if TLS is possible and set up the environment. Assumes the caller
- * desires to use TLS (e.g. caller found VIR_MIGRATE_TLS flag).
- *
- * Ensure the qemu.conf has been properly configured to add an entry for
- * "migrate_tls_x509_cert_dir". Also check if the "tls-creds" parameter
- * was present from a query of migration parameters
- *
- * Returns 0 on success, -1 on error/failure
- */
-static int
-qemuMigrationParamsCheckSetupTLS(virQEMUDriverPtr driver,
- virQEMUDriverConfigPtr cfg,
- virDomainObjPtr vm,
- qemuDomainAsyncJob asyncJob)
-{
-qemuDomainObjPrivatePtr priv = vm->privateData;
-
-if (!cfg->migrateTLSx509certdir) {
-

Re: [libvirt] [PATCH v5 03/10] conf: introduce launch-security element in domain

2018-04-04 Thread John Ferlan


[...]

>>
>> Hopefully hexuint will suffice over time... On the other hand, this
>> patch uses virXPathULongHex in order to parse.
>>
> 
> IIRC, I was not able to find anything other than hexuint in
> basictypes.rng and also was not able to a function like
> virXPathUIntHex(..). If you can point me to the function which can be
> used to get the hexuint then I am good with it. Also, I am open to
> adding such function if it does not exist and anyone else sees the need
> for it.
> 
> 

Right - if they need to be created, then you can do so.

I think in the long run since field is defined as a 32 bit unsigned
quantity, then we should be OK with sticking with that. If you need to
invent a 'hexulong' which is a slight change from 'hexuint' that's also
a possibility.

OTOH: if 32 bits are fine, it's "OK" to use the virXPathULongHex as long
as you also test that the result isn't longer than 32 bits. I wouldn't
bother with a virXPathUIntHex API since in the long run all it "should"
do is call the Long one and do the max uint comparison.

> 
>>> +    
>>> +  
>>> +    
>>> +  
>>> +    
>>> +    
>>> +  
>>> +    
>>> +  
>>> +    
>>> +    
>>> +  
>>> +    
>>> +  
>>> +    
>>> +  
>>> +    
>>> +  
>>> +

[...]

>>> +
>>> +    if (virXPathULongHex("string(./policy)", ctxt, ) < 0)>
>>> +    policy = 0x1;
>>
>> Hmmm... This one is optional which makes things a bit interesting. How
>> do you know it was provided? Today the default could be 0x1, but
>> sometime in the future if you decide upon a different default, then
>> things get really complicated. Or for some other chip and/or hypervisor
>> the default won't be 1.
>>
> 
> Firmware does not have default policy, a caller must provide the policy
> value. In our cases, we are saying if caller does not provide a policy
> in xml then we default to 0x1.
> 

As noted in my 6/10 response - you could change to making policy
required and then not worry about a default. It is a gray area, but it
will be in the long run some sort of hypervisor and even chip dependent
type field.

>> Also virXPathULongHex returns -1 or -2 w/ different meanings - if it's
>> not there, You get a -1 when not provided and -2 when you have invalid
>> value in field, which should be an error.
>>
> 
> ah thats good information, I was not aware of -2 thing.
> 
> 
>> Finally, ULongHex returns 64 bits and your field is 32 bits leading to
>> possible overflow
>>
> 
> Right, this is where I was struggling because there is no such function
> as virXPathUIntHex(...) which ca be used to get uint32_t. Please let me
> know your thoughts on  how do you want me to handle this situation.
> 

See my note above - I think the code below covers the UINT_MAX case
while using the ULong API.

Obviously if you make policy required, then the code changes a bit to
get/return rc and check rc vs. -1 for not found and vs. -2 for found,
but invalid (common occurrence elsewhere).

John

> 
> 
> 
>> So, either you have to have a "policy_provided" boolean of some sort or
>> I think preferably leave it as 0 (zero) indicating not provided and then
>> when generating a command line check against 0 and provide the
>> hypervisor dependent value on the command line *OR* just don't provided
>> it an let the hypervisor choose it's default value because the value
>> wasn't provided (that's a later patch though)
>>
>> Also see [1] below...
>>
>> So my suggestion is:
>>
>>  if (virXPathULongHex("string(./policy)", ctxt, ) == -2 ||
>>  policy > UINT_MAX) {
>>  virReportError(VIR_ERR_XML_ERROR, "%s",
>>     _("invalid launch-security policy value"));
>>  goto error;
>>  }
>>  def->policy = policy;
>>
>> If -1 is returned, the def->policy = 0; otherwise, it's set to something.
>>

[...]

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

Re: [libvirt] [PATCH v5 05/10] qemu: add support to launch SEV guest

2018-04-04 Thread John Ferlan


[...]

>>> +VIR_DEBUG("policy=0x%x cbitpos=%d reduced_phys_bits=%d",
>>> +  sev->policy, sev->cbitpos, sev->reduced_phys_bits);
>>> +
>>> +virBufferAsprintf(, "sev-guest,id=sev0,cbitpos=%d", sev->cbitpos);
>>> +virBufferAsprintf(, ",reduced-phys-bits=%d", 
>>> sev->reduced_phys_bits);
>>> +virBufferAsprintf(, ",policy=0x%x", sev->policy);
>> Here I would say:
>>
>> if (sev->policy > 0)
>> virBufferAsprintf(, ",policy=0x%x", sev->policy);
>>
>> and let qemu pick the default (which is 0x1 as I read that code).
> 
> OK, then I will remove the comment from html about the default value
> since I was trying to not depend on QEMU default.
> 

I understand - your other option is to make required. This is one of
those cases where there is a gray area with respect to libvirt picking
some default or policy that we generally prefer to avoid.

As noted before/elsewhere - what happens when the default changes...

>>> +
>>> +if (sev->dh_cert) {
>>> +ignore_value(virAsprintf(, "%s/dh_cert.base64", 
>>> priv->libDir));
>>> +virBufferAsprintf(, ",dh-cert-file=%s", path);
>>> +VIR_FREE(path);
>>> +}
>>> +
>>> +if (sev->session) {
>>> +ignore_value(virAsprintf(, "%s/session.base64", 
>>> priv->libDir));
>>> +virBufferAsprintf(, ",session-file=%s", path);
>>> +VIR_FREE(path);
>>> +}
[...]

>>> +qemuBuildSevCreateFile(const char *configDir, const char *name,
>>> +   const char *data)
>> 3 lines for args
>>
>>> +{
>>> +char *configFile;
>>> +
>>> +if (!(configFile = virFileBuildPath(configDir, name, ".base64")))
>>> +return -1;
>>> +
>>> +if (virFileRewriteStr(configFile, S_IRUSR | S_IWUSR, data) < 0) {
>>> +virReportSystemError(errno, _("failed to write data to config 
>>> '%s'"),
>>> + configFile);
>>> +goto error;
>>> +}
>> Check out storageBackendCreateQemuImgSecretPath which just goes straight
>> to safewrite when writing to the file or qemuDomainWriteMasterKeyFile
>> which is a similar w/r/t a single key file for the domain.
>>
>> The one thing to think about being the privileges for the file being
>> created and written and the expectations for QEMU's usage. I think this
>> is more like the storage secret code, but I could be wrong!
> 
> The data is public in this case, we do not need to protect it with
> secret. Hence I am keeping all this certificate keys in unsecure place.

It wasn't so much the public keys as it was me (more or less) thinking
out loud about the protections on the file that you're "temporarily"
creating and using to pass the keys.

I noted two other areas which libvirt does something similarly - one is
the master public key file for decrypting the AES secrets for
libvirt/qemu secret manipulation.  The second is the "temporary" file we
create in the storage driver to handle the luks encryption password for
create/resize of a luks encrypted file when using qemu-img. Now that is
slightly different than using a temporary file for the emulator binary.

In any case, since you're creating in libDir it's probably OK as is, but
I know when reading files libvirt creates which qemu will use there have
been issues in the past - I always have to refresh my memory what those
issues are though.

John

[...]

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


  1   2   >