Re: [libvirt] hash: failed on concurrent iterating.

2018-04-04 Thread Michal Privoznik
On 04/04/2018 11:50 AM, Zhangzijian wrote:
>> -Original Message-
>> From: libvir-list-boun...@redhat.com [mailto:libvir-list-boun...@redhat.com]
>> On Behalf Of Michal Privoznik
>> Sent: Wednesday, April 04, 2018 5:21 PM
>> To: zhangzijian (Cloud); libvir-list@redhat.com
>> Cc: huangyong (Cloud)
>> Subject: Re: [libvirt] hash: failed on concurrent iterating.
>>
>> On 04/04/2018 11:10 AM, Zhangzijian wrote:
>>> In function 'virHashForEach/virHashSearch', 'table->iterating' prevent
>> concurrent iterating. But most caller evoke it, after hold a read lock.
>>> This will lead the second caller failed to iterate the table. So, the 
>>> caller should
>> hold a write lock, then iterate the table.
>>
>> Looks like there's another thread discussing this issue:
>>
> 
> Yes, the issue is still exist in v4.2.0.
> Is it applicable to using write lock instead?

Do you have a stack trace to share?

Michal

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


Re: [libvirt] hash: failed on concurrent iterating.

2018-04-04 Thread Erik Skultety
On Wed, Apr 04, 2018 at 12:05:34PM +0100, Daniel P. Berrangé wrote:
> On Wed, Apr 04, 2018 at 12:37:11PM +0200, Erik Skultety wrote:
> > On Wed, Apr 04, 2018 at 09:50:29AM +, Zhangzijian wrote:
> > > > -Original Message-
> > > > From: libvir-list-boun...@redhat.com 
> > > > [mailto:libvir-list-boun...@redhat.com]
> > > > On Behalf Of Michal Privoznik
> > > > Sent: Wednesday, April 04, 2018 5:21 PM
> > > > To: zhangzijian (Cloud); libvir-list@redhat.com
> > > > Cc: huangyong (Cloud)
> > > > Subject: Re: [libvirt] hash: failed on concurrent iterating.
> > > >
> > > > On 04/04/2018 11:10 AM, Zhangzijian wrote:
> > > > > In function 'virHashForEach/virHashSearch', 'table->iterating' prevent
> > > > concurrent iterating. But most caller evoke it, after hold a read lock.
> > > > > This will lead the second caller failed to iterate the table. So, the 
> > > > > caller should
> > > > hold a write lock, then iterate the table.
> > > >
> > > > Looks like there's another thread discussing this issue:
> > > >
> > >
> > > Yes, the issue is still exist in v4.2.0.
> > > Is it applicable to using write lock instead?
> >
> > I hit this a month ago when working on mediated devices and creating a ton 
> > of
> > them. You can't replace it with write lock because it would kill the sole
> > purpose of having RW locks in our lists using hash tables in the first 
> > place.
> > IMHO the correct way to fix this is to get rid of the table->iterating flag
> > completely. In order to do that, you need to convert hash tables to lockable
> > objects so that even modules that don't define any lockable abstractions on 
> > top
> > of hash tables could benefit from this. There are several caveats like 
> > dealing
> > with NWFilter and for example the virHashForEach method which allows calling
> > the 'Remove' callback which of course requires a write lock, however, if you
> > issue a standard query, this could have been (and also should)  achieved 
> > with a
> > read lock to allow concurrent reading of elements in the table. This would 
> > also
> > require basically having a *Locked version of each virHash API because the
> > existing APIs are being called both outside and inside of the module, so you
> > need to take into account that you might already be holding a lock, etc.
>
> There are very few places in the code which actually need to be able to
> call Remove from within an iterator. We should just change the way that
> works to have a virHashTableForEachRemove() where the function called

We already have such a method - virHashRemoveSet. What you propose could work,
but I still feel like, eventually, it should be the hash table object that
implements the locking primitives rather than the abstractions we build on top
of it.
But for the time being, we can approach this with small steps.

Erik

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

Re: [libvirt] hash: failed on concurrent iterating.

2018-04-04 Thread Zhangzijian
> -Original Message-
> From: libvir-list-boun...@redhat.com [mailto:libvir-list-boun...@redhat.com]
> On Behalf Of Michal Privoznik
> Sent: Wednesday, April 04, 2018 5:21 PM
> To: zhangzijian (Cloud); libvir-list@redhat.com
> Cc: huangyong (Cloud)
> Subject: Re: [libvirt] hash: failed on concurrent iterating.
> 
> On 04/04/2018 11:10 AM, Zhangzijian wrote:
> > In function 'virHashForEach/virHashSearch', 'table->iterating' prevent
> concurrent iterating. But most caller evoke it, after hold a read lock.
> > This will lead the second caller failed to iterate the table. So, the 
> > caller should
> hold a write lock, then iterate the table.
> 
> Looks like there's another thread discussing this issue:
> 

Yes, the issue is still exist in v4.2.0.
Is it applicable to using write lock instead?

> https://www.redhat.com/archives/libvirt-users/2018-April/msg4.html
> 
> Michal
> 
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

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


Re: [libvirt] hash: failed on concurrent iterating.

2018-04-04 Thread Erik Skultety
On Wed, Apr 04, 2018 at 09:50:29AM +, Zhangzijian wrote:
> > -Original Message-
> > From: libvir-list-boun...@redhat.com [mailto:libvir-list-boun...@redhat.com]
> > On Behalf Of Michal Privoznik
> > Sent: Wednesday, April 04, 2018 5:21 PM
> > To: zhangzijian (Cloud); libvir-list@redhat.com
> > Cc: huangyong (Cloud)
> > Subject: Re: [libvirt] hash: failed on concurrent iterating.
> >
> > On 04/04/2018 11:10 AM, Zhangzijian wrote:
> > > In function 'virHashForEach/virHashSearch', 'table->iterating' prevent
> > concurrent iterating. But most caller evoke it, after hold a read lock.
> > > This will lead the second caller failed to iterate the table. So, the 
> > > caller should
> > hold a write lock, then iterate the table.
> >
> > Looks like there's another thread discussing this issue:
> >
>
> Yes, the issue is still exist in v4.2.0.
> Is it applicable to using write lock instead?

I hit this a month ago when working on mediated devices and creating a ton of
them. You can't replace it with write lock because it would kill the sole
purpose of having RW locks in our lists using hash tables in the first place.
IMHO the correct way to fix this is to get rid of the table->iterating flag
completely. In order to do that, you need to convert hash tables to lockable
objects so that even modules that don't define any lockable abstractions on top
of hash tables could benefit from this. There are several caveats like dealing
with NWFilter and for example the virHashForEach method which allows calling
the 'Remove' callback which of course requires a write lock, however, if you
issue a standard query, this could have been (and also should)  achieved with a
read lock to allow concurrent reading of elements in the table. This would also
require basically having a *Locked version of each virHash API because the
existing APIs are being called both outside and inside of the module, so you
need to take into account that you might already be holding a lock, etc.

Erik

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


Re: [libvirt] [PATCH v1 2/2] tests: add qemu-img test for preallocation=falloc

2018-04-04 Thread Michal Privoznik
On 04/03/2018 04:14 PM, Wim Ten Have wrote:
> From: Wim ten Have 
> 
> Signed-off-by: Wim ten Have 
> ---
>  tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git 
> a/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv 
> b/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv
> index 9073b1b16..b151b9401 100644
> --- a/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv
> +++ b/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv
> @@ -1,4 +1,4 @@
>  qemu-img convert -f raw -O qcow2 \
> --o encryption=on,preallocation=metadata \
> +-o encryption=on,preallocation=falloc \
>  /var/lib/libvirt/images/sparse.img \
>  /var/lib/libvirt/images/OtherDemo.img
> 


Ah, if anything, this should be merged into the previous patch.

Michal

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


Re: [libvirt] hash: failed on concurrent iterating.

2018-04-04 Thread Daniel P . Berrangé
On Wed, Apr 04, 2018 at 12:37:11PM +0200, Erik Skultety wrote:
> On Wed, Apr 04, 2018 at 09:50:29AM +, Zhangzijian wrote:
> > > -Original Message-
> > > From: libvir-list-boun...@redhat.com 
> > > [mailto:libvir-list-boun...@redhat.com]
> > > On Behalf Of Michal Privoznik
> > > Sent: Wednesday, April 04, 2018 5:21 PM
> > > To: zhangzijian (Cloud); libvir-list@redhat.com
> > > Cc: huangyong (Cloud)
> > > Subject: Re: [libvirt] hash: failed on concurrent iterating.
> > >
> > > On 04/04/2018 11:10 AM, Zhangzijian wrote:
> > > > In function 'virHashForEach/virHashSearch', 'table->iterating' prevent
> > > concurrent iterating. But most caller evoke it, after hold a read lock.
> > > > This will lead the second caller failed to iterate the table. So, the 
> > > > caller should
> > > hold a write lock, then iterate the table.
> > >
> > > Looks like there's another thread discussing this issue:
> > >
> >
> > Yes, the issue is still exist in v4.2.0.
> > Is it applicable to using write lock instead?
> 
> I hit this a month ago when working on mediated devices and creating a ton of
> them. You can't replace it with write lock because it would kill the sole
> purpose of having RW locks in our lists using hash tables in the first place.
> IMHO the correct way to fix this is to get rid of the table->iterating flag
> completely. In order to do that, you need to convert hash tables to lockable
> objects so that even modules that don't define any lockable abstractions on 
> top
> of hash tables could benefit from this. There are several caveats like dealing
> with NWFilter and for example the virHashForEach method which allows calling
> the 'Remove' callback which of course requires a write lock, however, if you
> issue a standard query, this could have been (and also should)  achieved with 
> a
> read lock to allow concurrent reading of elements in the table. This would 
> also
> require basically having a *Locked version of each virHash API because the
> existing APIs are being called both outside and inside of the module, so you
> need to take into account that you might already be holding a lock, etc.

There are very few places in the code which actually need to be able to
call Remove from within an iterator. We should just change the way that
works to have a virHashTableForEachRemove() where the function called
by the iterator returns 0 or 1 to indicate whether the currently pointed
entry should be removed. Then we can just kill the iterating flag from
the code

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

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


Re: [libvirt] [PATCH v1 1/2] storage: extend preallocation flags support for qemu-img

2018-04-04 Thread Michal Privoznik
On 04/03/2018 04:14 PM, Wim Ten Have wrote:
> From: Wim ten Have 
> 
> This patch adds support to qcow2 formatted filesystem object storage by
> instructing qemu-img to build them with preallocation=falloc whenever the
> XML described storage  matches its .  For all other
> cases the filesystem stored objects are built with preallocation=metadata.
> 
> Signed-off-by: Wim ten Have 
> ---
>  include/libvirt/libvirt-storage.h |  5 -
>  src/storage/storage_util.c| 21 +
>  2 files changed, 21 insertions(+), 5 deletions(-)
> 
> diff --git a/include/libvirt/libvirt-storage.h 
> b/include/libvirt/libvirt-storage.h
> index 413d9f6c4..2f22b388c 100644
> --- a/include/libvirt/libvirt-storage.h
> +++ b/include/libvirt/libvirt-storage.h
> @@ -337,8 +337,11 @@ const char* virStorageVolGetName
> (virStorageVolPtr vol);
>  const char* virStorageVolGetKey (virStorageVolPtr 
> vol);
>  
>  typedef enum {
> +VIR_STORAGE_VOL_CREATE_PREALLOC_NONE = 0 << 0,

This is okay.

>  VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA = 1 << 0,
> -VIR_STORAGE_VOL_CREATE_REFLINK = 1 << 1, /* perform a btrfs lightweight 
> copy */
> +VIR_STORAGE_VOL_CREATE_PREALLOC_FALLOC   = 1 << 1,
> +VIR_STORAGE_VOL_CREATE_PREALLOC_FULL = 1 << 2,
> +VIR_STORAGE_VOL_CREATE_REFLINK   = 1 << 3, /* perform a btrfs 
> lightweight copy */

This is not. Imagine there's a mgmt application already written and
compiled which calls:

virStorageVolCreateXML(flags = VIR_STORAGE_VOL_CREATE_REFLINK);

Because it is already compiled it is effectively calling:

virStorageVolCreateXML(flags = 1);

and everything works. However, if this change would be merged, the mgmt
application would be still making the same call but now it would have
different semantic, because you are changing the numbering. So
effectively mgmt app would be calling

virStorageVolCreateXML(flags = VIR_STORAGE_VOL_CREATE_PREALLOC_FALLOC)

which is obviously wrong. We can not expect mgmt applications to be
recompiled every time there's a new release of libvirt.

>  } virStorageVolCreateFlags;
>  
>  virStorageVolPtrvirStorageVolCreateXML  (virStoragePoolPtr 
> pool,
> diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
> index b4aed0f70..7728fb63e 100644
> --- a/src/storage/storage_util.c
> +++ b/src/storage/storage_util.c
> @@ -852,7 +852,7 @@ struct _virStorageBackendQemuImgInfo {
>  const char *path;
>  unsigned long long size_arg;
>  bool encryption;
> -bool preallocate;
> +unsigned int preallocate;
>  const char *compat;
>  virBitmapPtr features;
>  bool nocow;
> @@ -884,8 +884,15 @@ 
> storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr enc,
>
> virStorageFileFormatTypeToString(info.backingFormat));
>  if (info.encryption)
>  virBufferAddLit(, "encryption=on,");
> -if (info.preallocate)
> +
> +/* Handle various types of file-system storage pre-allocate sets.
> + */
> +if (info.preallocate & VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA)
>  virBufferAddLit(, "preallocation=metadata,");
> +else if (info.preallocate & VIR_STORAGE_VOL_CREATE_PREALLOC_FALLOC)
> +virBufferAddLit(, "preallocation=falloc,");
> +else if (info.preallocate & VIR_STORAGE_VOL_CREATE_PREALLOC_FULL)
> +virBufferAddLit(, "preallocation=full,");
>  }
>  
>  if (info.nocow)
> @@ -1183,7 +1190,7 @@ 
> virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
>  .format = vol->target.format,
>  .path = vol->target.path,
>  .encryption = vol->target.encryption != NULL,
> -.preallocate = !!(flags & VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA),
> +.preallocate = VIR_STORAGE_VOL_CREATE_PREALLOC_NONE,
>  .compat = vol->target.compat,
>  .features = vol->target.features,
>  .nocow = vol->target.nocow,
> @@ -1192,7 +1199,13 @@ 
> virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
>  };
>  virStorageEncryptionInfoDefPtr enc = NULL;
>  
> -virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
> +if (flags) {
> +info.preallocate = (vol->target.capacity == vol->target.allocation) ?
> +VIR_STORAGE_VOL_CREATE_PREALLOC_FALLOC : 
> VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
> +virCheckFlags((VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA|
> +   VIR_STORAGE_VOL_CREATE_PREALLOC_FALLOC|
> +   VIR_STORAGE_VOL_CREATE_PREALLOC_FULL), NULL);
> +}

virCheckFlags() should be checked outside of this if() statement.

But hold on. How can PREALLOC_FULL be used? How can any flag be
specified in the first place? I mean

virStorageVolCreateXML(flags = VIR_STORAGE_VOL_CREATE_PREALLOC_FULL)

boils down to


[libvirt] [dbus PATCH 0/5] Introduce Network Interface

2018-04-04 Thread Katerina Koukiou
This patchset introduces also some basic methods and properties for
Network interface.
More functionality will be added in following patchsets.
New functions are covered by the test suite.

Katerina Koukiou (5):
  Introduce Network Interface
  Implement ListNetworks method for Connect interface
  Implement virtDBusUtilVirNetworkFromBusPath helper function.
  Implement Name property for Network interface
  Implement NetworkLookupByName method for Connect interface

 data/Makefile.am |   3 +-
 data/org.libvirt.Connect.xml |  12 +
 data/org.libvirt.Network.xml |  11 +
 src/Makefile.am  |   3 +-
 src/connect.c|  75 ++
 src/connect.h|   1 +
 src/network.c| 107 +++
 src/network.h|   9 
 src/util.c   |  33 +
 src/util.h   |  15 ++
 test/Makefile.am |   3 +-
 test/libvirttest.py  |  12 +
 test/test_connect.py |  11 +
 13 files changed, 292 insertions(+), 3 deletions(-)
 create mode 100644 data/org.libvirt.Network.xml
 create mode 100644 src/network.c
 create mode 100644 src/network.h

-- 
2.15.0

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


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

2018-04-04 Thread Katerina Koukiou
On Wed, 2018-04-04 at 14:01 +0200, Katerina Koukiou wrote:
> This patchset introduces also some basic methods and properties for
> Network interface.
> More functionality will be added in following patchsets.
> New functions are covered by the test suite.
> 
> Katerina Koukiou (5):
>   Introduce Network Interface
>   Implement ListNetworks method for Connect interface
>   Implement virtDBusUtilVirNetworkFromBusPath helper function.
>   Implement Name property for Network interface
>   Implement NetworkLookupByName method for Connect interface
> 
>  data/Makefile.am |   3 +-
>  data/org.libvirt.Connect.xml |  12 +
>  data/org.libvirt.Network.xml |  11 +
>  src/Makefile.am  |   3 +-
>  src/connect.c|  75 ++
>  src/connect.h|   1 +
>  src/network.c| 107
> +++
>  src/network.h|   9 
>  src/util.c   |  33 +
>  src/util.h   |  15 ++
>  test/Makefile.am |   3 +-
>  test/libvirttest.py  |  12 +
>  test/test_connect.py |  11 +

I forgot to git add the test_network.py file. I 'll repost.

>  13 files changed, 292 insertions(+), 3 deletions(-)
>  create mode 100644 data/org.libvirt.Network.xml
>  create mode 100644 src/network.c
>  create mode 100644 src/network.h
> 

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


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

2018-04-04 Thread Katerina Koukiou
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 @@
   
   
 
+
+  https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByName"/>
+  
+  
+
   
 
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;
+
+network = virNetworkLookupByName(connect->connection, name);
+if (!network)
+return virtDBusUtilSetLastVirtError(error);
+
+path = virtDBusUtilBusPathForVirNetwork(network, connect->networkPath);
+
+*outArgs = g_variant_new("(o)", path);
+}
+
 static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
 { "Version", virtDBusConnectGetVersion, NULL },
 { 0 }
@@ -333,6 +361,7 @@ static virtDBusGDBusMethodTable 
virtDBusConnectMethodTable[] = {
 { "DomainLookupByName", virtDBusDomainLookupByName },
 { "DomainLookupByUUID", virtDBusDomainLookupByUUID },
 { "ListNetworks", virtDBusConnectListNetworks },
+{ "NetworkLookupByName", virtDBusNetworkLookupByName },
 { 0 }
 };
 
diff --git a/test/test_connect.py b/test/test_connect.py
index 5df7a5b..5f82259 100755
--- a/test/test_connect.py
+++ b/test/test_connect.py
@@ -74,6 +74,17 @@ class TestConnect(libvirttest.BaseTestClass):
 props = obj.GetAll('org.libvirt.Connect', 
dbus_interface=dbus.PROPERTIES_IFACE)
 assert isinstance(props[property_name], expected_type)
 
+@pytest.mark.parametrize("lookup_method_name,lookup_item", [
+("NetworkLookupByName", 'Name'),
+])
+def test_connect_network_lookup_by_property(self, lookup_method_name, 
lookup_item):
+"""Parameterized test for all NetworkLookupBy* API calls of Connect 
interface
+"""
+original_path, obj = self.test_network()
+prop = obj.Get('org.libvirt.Network', lookup_item, 
dbus_interface=dbus.PROPERTIES_IFACE)
+path = getattr(self.connect, lookup_method_name)(prop)
+assert original_path == path
+
 
 if __name__ == '__main__':
 libvirttest.run()
-- 
2.15.0

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


Re: [libvirt] [Question] Any plan about supporting MBA (Memory Bandwidth Allocation) in libvirt ?

2018-04-04 Thread Pavel Hrdina
On Wed, Apr 04, 2018 at 08:36:09AM +, Zhanghailiang wrote:
> Hi,
> 
> Intel RDT/MBA has been supported by kernel for a time, we also support CAT in 
> libvirt, which is part of RDT.
> but I didn't find any discussion or patches about MBA feature in Libvirt, 
> does anyone propose supporting it in
> libvirt ?

Hi,

There is a plan to implement it in libvirt, actually I have it on my
TODO list but if someone post the patches before me I'm happy to help
with review and getting it into libvirt.

So far there was no discussion about it.

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 v5 09/10] virsh: implement new command for launch security

2018-04-04 Thread Erik Skultety
On Wed, Apr 04, 2018 at 07:36:37AM -0500, Brijesh Singh wrote:
>
>
> On 4/3/18 9:32 AM, Erik Skultety wrote:
> > On Mon, Apr 02, 2018 at 09:18:55AM -0500, Brijesh Singh wrote:
> >> Add new 'launch-security' command, the command can be used to get or set
> >> the launch security information when booting encrypted VMs.
> >>
> >> Signed-off-by: Brijesh Singh 
> >> ---
> >>  tools/virsh-domain.c | 84 
> >> 
> >>  1 file changed, 84 insertions(+)
> >>
> >> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> >> index 2b775fc..4dca191 100644
> >> --- a/tools/virsh-domain.c
> >> +++ b/tools/virsh-domain.c
> >> @@ -13877,6 +13877,84 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
> >>  return ret >= 0;
> >>  }
> >>
> >> +/*
> >> + * "launch-security" command
> >> + */
> >> +static const vshCmdInfo info_launch_security[] = {
> >> +{.name = "help",
> >> +.data = N_("Get or set launch-security information")
> >> +},
> >> +{.name = "desc",
> >> +.data = N_("Get or set the current launch-security information 
> >> for a guest"
> >> +   " domain.\n"
> >> +   "To get the launch-security information use 
> >> following command: \n\n"
> >> +   "virsh # launch-security ")
> > As John has pointed out, you might want to shorten ^these 2 lines, however, 
> > I
> > think it makes sense to make it obvious that running without any
> > arguments/options this behaves like a getter, otherwise it's going to behave
> > like a setter, right? (it's a common practice in libvirt, so nothing against
> > conceptually).
> >
>
> Yes, without any command line it should be getter otherwise settter.
> Currently, we don't have anything in setter yet.
>
> >> +},
> >> +{.name = NULL}
> >> +};
> >> +
> >> +static const vshCmdOptDef opts_launch_security[] = {
> >> +VIRSH_COMMON_OPT_DOMAIN_FULL(0),
> >> +{.name = "get",
> >> + .type = VSH_OT_STRING,
> >> + .help = N_("Show the launch-security info")
> >> +},
> >> +VIRSH_COMMON_OPT_DOMAIN_CONFIG,
> >> +VIRSH_COMMON_OPT_DOMAIN_LIVE,
> >> +VIRSH_COMMON_OPT_DOMAIN_CURRENT,
> >> +{.name = NULL}
> >> +};
> > Sorry if I missed the obvious, but what exactly is the --get  
> > supposed
> > to do?
>
> The command will return a measurement of encrypted image. The
> measurement value can be used by guest owner to validate the image
> before it launches the VM. In a typical scenario we may have something
> like this:
>
> # virsh create guest.xml --paused
> # virsh launch-security --domain guest
> // validate the measurement obtained through above command
> if measurement is wrong then;
>  destory the guest
> else
>  // optionally inject secret in guest using virsh launch-security set <>
>  resume the guest

Yeah, but since you agreed that the command behaves like a getter without any
parameters, I don't see a reason for the --get  parameter, that's why I
asked about it. Also, the name of the command should be changed since this way,
it's a bit deceptive as it hints that it queries/modifies the launch-security
data which you got from querying qemu capabilities within the domain XML.
I'm also going to respond to the other email to this patch I sent yesterday,
because it's irrelevant given the fact that I got confused by the name (even
though I saw what API it called) and created a false association.
Other than what's already been noted, the logic in the virsh command itself
looks solid, not much to it since the setter part will come later I presume.

Erik

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

Re: [libvirt] [PATCH 01/11] docs: Tweak PCI controller model documentation

2018-04-04 Thread John Ferlan


On 04/04/2018 04:39 AM, Andrea Bolognani wrote:
> On Tue, 2018-04-03 at 19:11 -0400, John Ferlan wrote:
>> On 03/28/2018 10:06 AM, Andrea Bolognani wrote:
>>> Instead of first listing the models on their own, and then
>>> listing them again grouped by the libvirt release they were
>>> introduced in, have a single list.
>>>
>>> Signed-off-by: Andrea Bolognani 
>>> ---
>>>  docs/formatdomain.html.in | 20 
>>>  1 file changed, 8 insertions(+), 12 deletions(-)
>>
>> Personally I don't find it any easier to read ;-) - it's all a mash of
>> letters and dashes... Of course true of other parts on formatdomain too.
> 
> The goal was avoiding repeated information, not necessarily making
> the whole thing easier to read. But I agree that's a laudable goal
> as well :)
> 

Understood - to the degree of keeping since w/ the possible values is
better than the previous format. I guess I still found it difficult to
read so looked for something else more readable.

>>  Still, how about something like this:
>>
>>   
>> 
>>Value 
>>Since 
>> 
>> 
>>pci-root 
>>since 1.0.5 
> [...]
>> 
>>
>> You could choose different labels if you desired...
> 
> Using a table for this seems like a waste of vertical space to me,
> and there are no existing examples of anything like that in the
> documentation AFAICT. Maybe a  instead?
> 

Table or list is fine - I guess I just landed on a part of the page with
a table and thought this would be so much nicer than a paragraph of data
where there's multiple since labels. FWIW: The hyperv description of the
power management section uses a table w/ a since column.

>> Also consider the
>> possibilities for expansion w/r/t providing even a *little* bit more
>> "Description" details about what each of these things are and
>> when/how/why they'd be used (far beyond the scope of this patch though).
>> I would think some of that could be drawn from the descriptions that
>> exist "just above" the "Device leases" section.  IOW: a relationship
>> matrix...
> 
> Is the information already present below in free-text format not
> enough? I don't think we can compress that information in a format
> that would be suitable for a table.
> 
> In any case, I agree it would be entirely out of scope here.
> 

The information free form is sufficient of course it's easy to miss too,
but at this point baby steps and out of context.

In any case, if you want to not make any extra changes, then I guess
that's fine since your patch is better than the original; however,
taking the extra step for list or table I think would be better.

The R-b can stick with for whatever option you choose.

John

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


Re: [libvirt] [PATCH v5 09/10] virsh: implement new command for launch security

2018-04-04 Thread Brijesh Singh


On 4/2/18 6:31 PM, John Ferlan wrote:
>
> On 04/02/2018 10:18 AM, Brijesh Singh wrote:
>> Add new 'launch-security' command, the command can be used to get or set
>> the launch security information when booting encrypted VMs.
>>
>> Signed-off-by: Brijesh Singh 
>> ---
>>  tools/virsh-domain.c | 84 
>> 
>>  1 file changed, 84 insertions(+)
>>
> Need to modify tools/virsh.pod too in order to supply the man page
> information.

Ah, I missed that. Will add help in next rev.

>
>> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
>> index 2b775fc..4dca191 100644
>> --- a/tools/virsh-domain.c
>> +++ b/tools/virsh-domain.c
>> @@ -13877,6 +13877,84 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
>>  return ret >= 0;
>>  }
>>  
>> +/*
>> + * "launch-security" command
>> + */
>> +static const vshCmdInfo info_launch_security[] = {
>> +{.name = "help",
>> +.data = N_("Get or set launch-security information")
>> +},
>> +{.name = "desc",
>> +.data = N_("Get or set the current launch-security information for 
>> a guest"
>> +   " domain.\n"
>> +   "To get the launch-security information use 
>> following command: \n\n"
>> +   "virsh # launch-security ")
>> +},
> Rather lengthy...  don't think the last 2 lines are necessary. Is there
> another command doing the same?

Yes, I tried to follow other commands.

> Probably should fill in the ".help" entry too like other commands.

OK.
>> +{.name = NULL}
>> +};
>> +
>> +static const vshCmdOptDef opts_launch_security[] = {
>> +VIRSH_COMMON_OPT_DOMAIN_FULL(0),
>> +{.name = "get",
>> + .type = VSH_OT_STRING,
>> + .help = N_("Show the launch-security info")
>> +},
>> +VIRSH_COMMON_OPT_DOMAIN_CONFIG,
>> +VIRSH_COMMON_OPT_DOMAIN_LIVE,
>> +VIRSH_COMMON_OPT_DOMAIN_CURRENT,
>> +{.name = NULL}
>> +};
>> +
> 2 lines...
>
>> +static void
>> +virshPrintLaunchSecurityInfo(vshControl *ctl, virTypedParameterPtr params,
>> + int nparams)
>> +{
>> +size_t i;
>> +
> Should there perhaps be a header here for the columns?

For now we have only one column and I am not too sure if we need to add
a header file for it, if it grows then we can revisit.
>
>> +for (i = 0; i < nparams; i++) {
>> +if (params[i].type == VIR_TYPED_PARAM_STRING)
>> +vshPrintExtra(ctl, "%-15s: %s\n", params[i].field, 
>> params[i].value.s);
>> +}
>> +}
>> +
> 2 lines...
>
> John
>
>> +static bool
>> +cmdLaunchSecurity(vshControl *ctl, const vshCmd *cmd)
>> +{
>> +virDomainPtr dom;
>> +int nparams = 0;
>> +virTypedParameterPtr params = NULL;
>> +bool ret = false;
>> +unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
>> +bool current = vshCommandOptBool(cmd, "current");
>> +bool config = vshCommandOptBool(cmd, "config");
>> +bool live = vshCommandOptBool(cmd, "live");
>> +
>> +VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
>> +VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
>> +
>> +if (config)
>> +flags |= VIR_DOMAIN_AFFECT_CONFIG;
>> +if (live)
>> +flags |= VIR_DOMAIN_AFFECT_LIVE;
>> +
>> +if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
>> +return false;
>> +
>> +if (virDomainGetLaunchSecurityInfo(dom, , , flags) != 0) 
>> {
>> +vshError(ctl, "%s", _("Unable to get launch security info"));
>> +goto cleanup;
>> +}
>> +
>> +virshPrintLaunchSecurityInfo(ctl, params, nparams);
>> +
>> +ret = true;
>> + cleanup:
>> +virTypedParamsFree(params, nparams);
>> +virshDomainFree(dom);
>> +return ret;
>> +}
>> +
>> +
>>  const vshCmdDef domManagementCmds[] = {
>>  {.name = "attach-device",
>>   .handler = cmdAttachDevice,
>> @@ -14492,5 +14570,11 @@ const vshCmdDef domManagementCmds[] = {
>>   .info = info_domblkthreshold,
>>   .flags = 0
>>  },
>> +{.name = "launch-security",
>> + .handler = cmdLaunchSecurity,
>> + .opts = opts_launch_security,
>> + .info = info_launch_security,
>> + .flags = 0
>> +},
>>  {.name = NULL}
>>  };
>>

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


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

2018-04-04 Thread Katerina Koukiou
Signed-off-by: Katerina Koukiou 
---
 src/util.c | 13 +
 src/util.h |  5 +
 2 files changed, 18 insertions(+)

diff --git a/src/util.c b/src/util.c
index fe40a96..03a0f10 100644
--- a/src/util.c
+++ b/src/util.c
@@ -152,6 +152,19 @@ virtDBusUtilEnumFromString(const gchar *const *types,
 return -1;
 }
 
+virNetworkPtr
+virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
+ const gchar *path,
+ const gchar *networkPath)
+{
+g_autofree gchar *name = NULL;
+gsize prefixLen = strlen(networkPath) + 1;
+
+name = virtDBusUtilDecodeUUID(path+prefixLen);
+
+return virNetworkLookupByUUIDString(connection, name);
+}
+
 gchar *
 virtDBusUtilBusPathForVirNetwork(virNetworkPtr network,
  const gchar *networkPath)
diff --git a/src/util.h b/src/util.h
index fac080c..7bb4ad6 100644
--- a/src/util.h
+++ b/src/util.h
@@ -66,6 +66,11 @@ virtDBusUtilEnumToString(const gchar *const *types,
 const gchar *name ##TypeToString(gint type) G_GNUC_PURE; \
 gint name ##TypeFromString(const gchar *type) G_GNUC_PURE;
 
+virNetworkPtr
+virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
+ const gchar *path,
+ const gchar *networkPath);
+
 gchar *
 virtDBusUtilBusPathForVirNetwork(virNetworkPtr network,
  const gchar *networkPath);
-- 
2.15.0

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


Re: [libvirt] [PATCH 08/11] conf: Prefer pcie-to-pci-bridge to dmi-to-pci-bridge

2018-04-04 Thread John Ferlan


On 04/04/2018 05:04 AM, Andrea Bolognani wrote:
> On Tue, 2018-04-03 at 19:13 -0400, John Ferlan wrote:
> [...]
>>>  needDMIToPCIBridge = true;
>>> +needPCIeToPCIBridge = true;
>>>  for (i = 0; i < addrs->nbuses; i++) {
>>>  if (addrs->buses[i].flags & 
>>> VIR_PCI_CONNECT_TYPE_PCI_BRIDGE) {
>>>  needDMIToPCIBridge = false;
>>> +needPCIeToPCIBridge = false;
>>>  break;
>>>  }
>>>  }
>>> -if (needDMIToPCIBridge && add == 1) {
>>> +
>>> +/* Prefer pcie-to-pci-bridge, fall back to dmi-to-pci-bridge */
>>> +if (addrs->isPCIeToPCIBridgeSupported)
>>> +needDMIToPCIBridge = false;
>>> +else
>>> +needPCIeToPCIBridge = false;
>>
>> The above seems a bit extra work and is a bit hard to read...  Could the
>> previous for loop change to use a new bool "needXToPCIBridge"...
>>
>> Then, I think it would just be:
>>
>> if (addrs->isPCIeToPCIBridgeSupported)
>> needPCIeToPCIBridge = needXToPCIBridge;
>> else
>> needDMIToPCIBridge = needXToPCIBridge;
>>
>> with the following just being if (needXToPCIBridge && add == 1)
>>
>> What you have works, just seems to be overkill or maybe I'm missing
>> something subtle ;-).
> 
> I don't think you missed something, both version should work just
> as fine. I happen to find my version easier to read than yours, so
> I'd stick with that if you're okay with it - I guess it's just a
> matter of preference at the end of the day...
> 

I guess part of me is thinking of the "next" bridge that gets added
where someone just copies what you did and creates a needXXXToPCIBridge
boolean, adds another setting to true, another setting to false, and
then needs to decide which to prefer and thus has to muck with setting
the others based on the new one.

In the long run - it seems the setting of the bool is based on need,
then the second part is to decide what type of thing to add. That's why
I thought it would be easier to read with what I presented.

Again I'm fine with the way you had it, so it's your call.

John

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


Re: [libvirt] [PATCH v5 09/10] virsh: implement new command for launch security

2018-04-04 Thread Erik Skultety
On Tue, Apr 03, 2018 at 04:55:42PM +0200, Erik Skultety wrote:
> > > +},
> > > +{.name = NULL}
> > > +};
> > > +
> > > +static const vshCmdOptDef opts_launch_security[] = {
> > > +VIRSH_COMMON_OPT_DOMAIN_FULL(0),
> > > +{.name = "get",
> > > + .type = VSH_OT_STRING,
> > > + .help = N_("Show the launch-security info")
> > > +},
> > > +VIRSH_COMMON_OPT_DOMAIN_CONFIG,
> > > +VIRSH_COMMON_OPT_DOMAIN_LIVE,
> > > +VIRSH_COMMON_OPT_DOMAIN_CURRENT,
> > > +{.name = NULL}
> > > +};
> >
> > Sorry if I missed the obvious, but what exactly is the --get  
> > supposed
> > to do?
>
> Giving it another thought, why do we need the virsh part anyway, this is only
> relevant for the config, aka shut off domain, so virsh edit and virsh dumpxml
> will do the job of a getter and a setter just fine, the main purpose of the
> virsh commands is to tune the 'live' configuration of a domain.

Please disregard this, I got confused by the name and created an association
with the launch-security data formatted into the domain XML which we retrieved
from the hypervisor, where in fact, this command is necessary to obtain the SEV
measurement.

Erik

--
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 Brijesh Singh


On 4/2/18 6:04 PM, John Ferlan wrote:
>
> On 04/02/2018 10:18 AM, Brijesh Singh wrote:
>> QEMU >= 2.12 provides 'sev-guest' object which is used to launch encrypted
>> VMs on AMD platform using SEV feature. The various inputs required to
>> launch SEV guest is provided through the  tag. A typical
>> SEV guest launch command line looks like this:
>>
>> # $QEMU ...\
>>   -object sev-guest,id=sev0,cbitpos=47,reduced-phys-bits=5 ...\
>>   -machine memory-encryption=sev0 \
>>
>> Signed-off-by: Brijesh Singh 
>> ---
>>  src/qemu/qemu_command.c | 35 +
>>  src/qemu/qemu_process.c | 58 
>> +
>>  2 files changed, 93 insertions(+)
>>
> (slight delay for next part of review - today was rocket launch day and
> then we headed out for a bit ;-))
>
>> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
>> index 682d714..55bbfa2 100644
>> --- a/src/qemu/qemu_command.c
>> +++ b/src/qemu/qemu_command.c
>> @@ -7405,6 +7405,9 @@ qemuBuildMachineCommandLine(virCommandPtr cmd,
>>  virQEMUCapsGet(qemuCaps, QEMU_CAPS_LOADPARM))
>>  qemuAppendLoadparmMachineParm(, def);
>>  
>> +if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SEV_GUEST) && def->sev)
> Since we already checked sev-guest at prepare host storage (mostly
> unconditionally), I don't think we have to make the check here as well -
> although I could be wrong...


Yes, probably we can avoid the SEV_GUEST cap check in this case. I will
make the changes in next rev.

>> +virBufferAddLit(, ",memory-encryption=sev0");
>> +
>>  virCommandAddArgBuffer(cmd, );
>>  }
>>  
>> @@ -9750,6 +9753,35 @@ qemuBuildTPMCommandLine(virCommandPtr cmd,
>>  return 0;
>>  }
>>  
>> +static void
> This probably should be an int...

I think it will be unlikely that this function will fail hence I was
using void. The only time it can fail is when we fail to create a
dh-cert and session blob file (e.g disk is full). I will propagate the
error.

>> +qemuBuildSevCommandLine(virDomainObjPtr vm, virCommandPtr cmd,
>> +virDomainSevDefPtr sev)
>> +{
>> +virBuffer obj = VIR_BUFFER_INITIALIZER;
>> +qemuDomainObjPrivatePtr priv = vm->privateData;
>> +char *path = NULL;
>> +
> if (!dev->sev)
> return 0;
>
> again, since prepare host storage checked the sev-guest capability we
> should be good to go here...

OK.

>> +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.

>> +
>> +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);
>> +}
> ...since I don't believe we can ignore_value on the paths - especially
> since we're using it to create a path to a file containing some sort of
> session info or DH key (base64 encrypted).

Sure, will do.

>> +
>> +virCommandAddArgList(cmd, "-object", virBufferContentAndReset(), 
>> NULL);
>> +}
>>  
>>  static int
>>  qemuBuildVMCoreInfoCommandLine(virCommandPtr cmd,
>> @@ -10195,6 +10227,9 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
>>  if (qemuBuildVMCoreInfoCommandLine(cmd, def, qemuCaps) < 0)
>>  goto error;
>>  
>> +if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SEV_GUEST) && def->sev)
>> +qemuBuildSevCommandLine(vm, cmd, def->sev);
>> +
> I think we're save to change this to:
>
> if (qemuBuildSevCommandLine(vm, cmd, dev->sev) < 0)
> goto error;
>

Yep

>>  if (snapshot)
>>  virCommandAddArgList(cmd, "-loadvm", snapshot->def->name, NULL);
>>  
>> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
>> index c0105c8..0c93f15 100644
>> --- a/src/qemu/qemu_process.c
>> +++ b/src/qemu/qemu_process.c
>> @@ -5745,6 +5745,61 @@ qemuProcessPrepareDomain(virQEMUDriverPtr driver,
>>  return ret;
>>  }
>>  
> Two blank lines
>
>> +static int
>> +qemuBuildSevCreateFile(const char *configDir, const char *name,
>> +   const char *data)
> 3 lines for args
>
>> +{
>> +char *configFile;
>> +
>> +if (!(configFile = virFileBuildPath(configDir, name, ".base64")))
>> +  

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

2018-04-04 Thread Katerina Koukiou
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

diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml
index 2b7c4f7..1215ac3 100644
--- a/data/org.libvirt.Network.xml
+++ b/data/org.libvirt.Network.xml
@@ -3,5 +3,9 @@
 
 
   
+
+  https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetName"/>
+
   
 
diff --git a/src/network.c b/src/network.c
index 0d0e992..fdfaaa7 100644
--- a/src/network.c
+++ b/src/network.c
@@ -3,7 +3,50 @@
 
 #include 
 
+static virNetworkPtr
+virtDBusNetworkGetVirNetwork(virtDBusConnect *connect,
+ const gchar *objectPath,
+ GError **error)
+{
+virNetworkPtr network;
+
+if (virtDBusConnectOpen(connect, error) < 0)
+return NULL;
+
+network = virtDBusUtilVirNetworkFromBusPath(connect->connection,
+objectPath,
+connect->networkPath);
+if (!network) {
+virtDBusUtilSetLastVirtError(error);
+return NULL;
+}
+
+return network;
+}
+
+static void
+virtDBusNetworkGetName(const gchar *objectPath,
+   gpointer userData,
+   GVariant **value,
+   GError **error)
+{
+virtDBusConnect *connect = userData;
+g_autoptr(virNetwork) network = NULL;
+const gchar *name;
+
+network = virtDBusNetworkGetVirNetwork(connect, objectPath, error);
+if (!network)
+return;
+
+name = virNetworkGetName(network);
+if (!name)
+return virtDBusUtilSetLastVirtError(error);
+
+*value = g_variant_new("s", name);
+}
+
 static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = {
+{ "Name", virtDBusNetworkGetName, NULL },
 { 0 }
 };
 
diff --git a/test/Makefile.am b/test/Makefile.am
index acb2d33..089ade5 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -4,7 +4,8 @@ test_helpers = \
 
 test_programs = \
test_connect.py \
-   test_domain.py
+   test_domain.py \
+   test_network.py
 
 EXTRA_DIST = \
$(test_helpers) \
diff --git a/test/libvirttest.py b/test/libvirttest.py
index c4dc96f..ecd8aef 100644
--- a/test/libvirttest.py
+++ b/test/libvirttest.py
@@ -70,3 +70,15 @@ class BaseTestClass():
 path = self.connect.ListDomains(0)[0]
 obj = self.bus.get_object('org.libvirt', path)
 return obj, dbus.Interface(obj, 'org.libvirt.Domain')
+
+def test_network(self):
+"""Fetch information for the test network from test driver
+
+Returns:
+(dbus.proxies.ProxyObject, dbus.proxies.ProxyObject):
+Test Network Object, Local proxy for the test Network Object.
+
+"""
+path = self.connect.ListNetworks(0)[0]
+obj = self.bus.get_object('org.libvirt', path)
+return path, obj
diff --git a/test/test_network.py b/test/test_network.py
new file mode 100755
index 000..97ab0aa
--- /dev/null
+++ b/test/test_network.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python3
+
+import dbus
+import libvirttest
+
+
+class TestNetwork(libvirttest.BaseTestClass):
+""" Tests for methods and properties of the Network interface
+"""
+def test_network_properties_type(self):
+""" Ensure correct return type for Network properties
+"""
+_, obj = self.test_network()
+props = obj.GetAll('org.libvirt.Network', 
dbus_interface=dbus.PROPERTIES_IFACE)
+assert isinstance(props['Name'], dbus.String)
+
+
+if __name__ == '__main__':
+libvirttest.run()
-- 
2.15.0

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


Re: [libvirt] [PATCH v5 09/10] virsh: implement new command for launch security

2018-04-04 Thread Brijesh Singh


On 4/3/18 9:32 AM, Erik Skultety wrote:
> On Mon, Apr 02, 2018 at 09:18:55AM -0500, Brijesh Singh wrote:
>> Add new 'launch-security' command, the command can be used to get or set
>> the launch security information when booting encrypted VMs.
>>
>> Signed-off-by: Brijesh Singh 
>> ---
>>  tools/virsh-domain.c | 84 
>> 
>>  1 file changed, 84 insertions(+)
>>
>> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
>> index 2b775fc..4dca191 100644
>> --- a/tools/virsh-domain.c
>> +++ b/tools/virsh-domain.c
>> @@ -13877,6 +13877,84 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
>>  return ret >= 0;
>>  }
>>
>> +/*
>> + * "launch-security" command
>> + */
>> +static const vshCmdInfo info_launch_security[] = {
>> +{.name = "help",
>> +.data = N_("Get or set launch-security information")
>> +},
>> +{.name = "desc",
>> +.data = N_("Get or set the current launch-security information for 
>> a guest"
>> +   " domain.\n"
>> +   "To get the launch-security information use 
>> following command: \n\n"
>> +   "virsh # launch-security ")
> As John has pointed out, you might want to shorten ^these 2 lines, however, I
> think it makes sense to make it obvious that running without any
> arguments/options this behaves like a getter, otherwise it's going to behave
> like a setter, right? (it's a common practice in libvirt, so nothing against
> conceptually).
>

Yes, without any command line it should be getter otherwise settter.
Currently, we don't have anything in setter yet.

>> +},
>> +{.name = NULL}
>> +};
>> +
>> +static const vshCmdOptDef opts_launch_security[] = {
>> +VIRSH_COMMON_OPT_DOMAIN_FULL(0),
>> +{.name = "get",
>> + .type = VSH_OT_STRING,
>> + .help = N_("Show the launch-security info")
>> +},
>> +VIRSH_COMMON_OPT_DOMAIN_CONFIG,
>> +VIRSH_COMMON_OPT_DOMAIN_LIVE,
>> +VIRSH_COMMON_OPT_DOMAIN_CURRENT,
>> +{.name = NULL}
>> +};
> Sorry if I missed the obvious, but what exactly is the --get  supposed
> to do?

The command will return a measurement of encrypted image. The
measurement value can be used by guest owner to validate the image
before it launches the VM. In a typical scenario we may have something
like this:

# virsh create guest.xml --paused
# virsh launch-security --domain guest
// validate the measurement obtained through above command
if measurement is wrong then;
 destory the guest
else
 // optionally inject secret in guest using virsh launch-security set <>
 resume the guest



> Erik

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

[libvirt] [dbus PATCH 1/5] Introduce Network Interface

2018-04-04 Thread Katerina Koukiou
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 @@
+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)
+{
+connect->networkPath = g_strdup_printf("%s/network", connect->connectPath);
+
+if (!interfaceInfo) {
+interfaceInfo = 
virtDBusGDBusLoadIntrospectData(VIRT_DBUS_NETWORK_INTERFACE,
+error);
+if (!interfaceInfo)
+return;
+}
+
+virtDBusGDBusRegisterSubtree(connect->bus,
+ connect->networkPath,
+ interfaceInfo,
+ virtDBusNetworkEnumerate,
+ virtDBusNetworkMethodTable,
+ virtDBusNetworkPropertyTable,
+ connect);
+}
diff --git a/src/network.h b/src/network.h
new file mode 100644
index 000..fc53b28
--- /dev/null
+++ b/src/network.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "connect.h"
+
+#define VIRT_DBUS_NETWORK_INTERFACE "org.libvirt.Network"
+
+void
+virtDBusNetworkRegister(virtDBusConnect *connect,
+GError **error);
diff --git a/src/util.c b/src/util.c
index be65172..fe40a96 100644
--- a/src/util.c
+++ b/src/util.c
@@ -151,3 +151,23 @@ virtDBusUtilEnumFromString(const gchar *const *types,
 
 return -1;
 }
+
+gchar *
+virtDBusUtilBusPathForVirNetwork(virNetworkPtr network,
+  

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

2018-04-04 Thread Katerina Koukiou
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 @@
   
   
 
+
+  https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListAllNetworks"/>
+  
+  
+
   
 
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 }
 };
 
-- 
2.15.0

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


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

2018-04-04 Thread Katerina Koukiou
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 @@
   
   
 
+
+  https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByName"/>
+  
+  
+
   
 
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;
+
+network = virNetworkLookupByName(connect->connection, name);
+if (!network)
+return virtDBusUtilSetLastVirtError(error);
+
+path = virtDBusUtilBusPathForVirNetwork(network, connect->networkPath);
+
+*outArgs = g_variant_new("(o)", path);
+}
+
 static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
 { "Version", virtDBusConnectGetVersion, NULL },
 { 0 }
@@ -333,6 +361,7 @@ static virtDBusGDBusMethodTable 
virtDBusConnectMethodTable[] = {
 { "DomainLookupByName", virtDBusDomainLookupByName },
 { "DomainLookupByUUID", virtDBusDomainLookupByUUID },
 { "ListNetworks", virtDBusConnectListNetworks },
+{ "NetworkLookupByName", virtDBusNetworkLookupByName },
 { 0 }
 };
 
diff --git a/test/test_connect.py b/test/test_connect.py
index 5df7a5b..5f82259 100755
--- a/test/test_connect.py
+++ b/test/test_connect.py
@@ -74,6 +74,17 @@ class TestConnect(libvirttest.BaseTestClass):
 props = obj.GetAll('org.libvirt.Connect', 
dbus_interface=dbus.PROPERTIES_IFACE)
 assert isinstance(props[property_name], expected_type)
 
+@pytest.mark.parametrize("lookup_method_name,lookup_item", [
+("NetworkLookupByName", 'Name'),
+])
+def test_connect_network_lookup_by_property(self, lookup_method_name, 
lookup_item):
+"""Parameterized test for all NetworkLookupBy* API calls of Connect 
interface
+"""
+original_path, obj = self.test_network()
+prop = obj.Get('org.libvirt.Network', lookup_item, 
dbus_interface=dbus.PROPERTIES_IFACE)
+path = getattr(self.connect, lookup_method_name)(prop)
+assert original_path == path
+
 
 if __name__ == '__main__':
 libvirttest.run()
-- 
2.15.0

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


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

2018-04-04 Thread Katerina Koukiou
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 
 4 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml
index 2b7c4f7..1215ac3 100644
--- a/data/org.libvirt.Network.xml
+++ b/data/org.libvirt.Network.xml
@@ -3,5 +3,9 @@
 
 
   
+
+  https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetName"/>
+
   
 
diff --git a/src/network.c b/src/network.c
index 0d0e992..fdfaaa7 100644
--- a/src/network.c
+++ b/src/network.c
@@ -3,7 +3,50 @@
 
 #include 
 
+static virNetworkPtr
+virtDBusNetworkGetVirNetwork(virtDBusConnect *connect,
+ const gchar *objectPath,
+ GError **error)
+{
+virNetworkPtr network;
+
+if (virtDBusConnectOpen(connect, error) < 0)
+return NULL;
+
+network = virtDBusUtilVirNetworkFromBusPath(connect->connection,
+objectPath,
+connect->networkPath);
+if (!network) {
+virtDBusUtilSetLastVirtError(error);
+return NULL;
+}
+
+return network;
+}
+
+static void
+virtDBusNetworkGetName(const gchar *objectPath,
+   gpointer userData,
+   GVariant **value,
+   GError **error)
+{
+virtDBusConnect *connect = userData;
+g_autoptr(virNetwork) network = NULL;
+const gchar *name;
+
+network = virtDBusNetworkGetVirNetwork(connect, objectPath, error);
+if (!network)
+return;
+
+name = virNetworkGetName(network);
+if (!name)
+return virtDBusUtilSetLastVirtError(error);
+
+*value = g_variant_new("s", name);
+}
+
 static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = {
+{ "Name", virtDBusNetworkGetName, NULL },
 { 0 }
 };
 
diff --git a/test/Makefile.am b/test/Makefile.am
index acb2d33..089ade5 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -4,7 +4,8 @@ test_helpers = \
 
 test_programs = \
test_connect.py \
-   test_domain.py
+   test_domain.py \
+   test_network.py
 
 EXTRA_DIST = \
$(test_helpers) \
diff --git a/test/libvirttest.py b/test/libvirttest.py
index c4dc96f..ecd8aef 100644
--- a/test/libvirttest.py
+++ b/test/libvirttest.py
@@ -70,3 +70,15 @@ class BaseTestClass():
 path = self.connect.ListDomains(0)[0]
 obj = self.bus.get_object('org.libvirt', path)
 return obj, dbus.Interface(obj, 'org.libvirt.Domain')
+
+def test_network(self):
+"""Fetch information for the test network from test driver
+
+Returns:
+(dbus.proxies.ProxyObject, dbus.proxies.ProxyObject):
+Test Network Object, Local proxy for the test Network Object.
+
+"""
+path = self.connect.ListNetworks(0)[0]
+obj = self.bus.get_object('org.libvirt', path)
+return path, obj
-- 
2.15.0

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


[libvirt] how to expose missing libxl APIs in xml?

2018-04-04 Thread Olaf Hering
libvirt lacks support for various API interfaces provided by libxl.
There is probably no list to track the items not supported by libvirt.
Where should such list be maintained, in libvirt.git?

The specific case I have right now is this member of libxl_domain_build_info:

tools/libxl/libxl_types.idl:483:("max_grant_frames",uint32, 
{'init_val': 'LIBXL_MAX_GRANT_FRAMES_DEFAULT'}),

How should this be exposed in the guest xml?

Olaf


pgp68zDUhbmHv.pgp
Description: Digitale Signatur von OpenPGP
--
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 Katerina Koukiou
On Wed, 2018-04-04 at 14:26 +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 @@
> + Introspection 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;
>  }

I forgot here to adjust the freeing function.
Should be:

@@ -374,6 +403,7 @@ virtDBusConnectFree(virtDBusConnect *connect)
 virtDBusConnectClose(connect, TRUE);
 
 g_free(connect->domainPath);
+g_free(connect->networkPath);
 g_free(connect);
 }

I 'll wait for further review and repost again.

> 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)
> +{
> +connect->networkPath = g_strdup_printf("%s/network", connect-
> >connectPath);
> +
> +if (!interfaceInfo) {
> +interfaceInfo =
> virtDBusGDBusLoadIntrospectData(VIRT_DBUS_NETWORK_INTERFACE,
> +error);
> +if (!interfaceInfo)
> +return;
> +}
> +
> +virtDBusGDBusRegisterSubtree(connect->bus,
> + connect->networkPath,
> + interfaceInfo,
> + virtDBusNetworkEnumerate,
> + virtDBusNetworkMethodTable,
> + 

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


Re: [libvirt] [PATCH v2 3/3] test: Need to relock afer virDomainObjListRemove

2018-04-04 Thread John Ferlan


On 04/04/2018 02:57 AM, Marc Hartmayer wrote:
> On Mon, Apr 02, 2018 at 02:27 PM +0200, John Ferlan  
> wrote:
>> For all @dom's fetched from a testDomObjFromDomain because
>> virDomainObjListRemove will return an unlocked domain object
>> we should relock it prior to the cleanup label which will use
>> virDomainObjEndAPI which would Unlock and Unref the passed
>> object (and we should avoid unlocking an unlocked object).
>>
>> Signed-off-by: John Ferlan 
>> ---
>>  src/test/test_driver.c | 26 +++---
>>  1 file changed, 19 insertions(+), 7 deletions(-)
>>
>> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
>> index 3c01aa50e1..5e39ae574c 100644
>> --- a/src/test/test_driver.c
>> +++ b/src/test/test_driver.c
>> @@ -1802,8 +1802,10 @@ static int testDomainDestroyFlags(virDomainPtr domain,
>>   VIR_DOMAIN_EVENT_STOPPED,
>>   VIR_DOMAIN_EVENT_STOPPED_DESTROYED);
>>
>> -if (!privdom->persistent)
>> +if (!privdom->persistent) {
>>  virDomainObjListRemove(privconn->domains, privdom);
>> +virObjectLock(privdom);
>> +}
>>
>>  ret = 0;
>>   cleanup:
>> @@ -1901,8 +1903,10 @@ static int testDomainShutdownFlags(virDomainPtr 
>> domain,
>>   VIR_DOMAIN_EVENT_STOPPED,
>>   VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
>>
>> -if (!privdom->persistent)
>> +if (!privdom->persistent) {
>>  virDomainObjListRemove(privconn->domains, privdom);
>> +virObjectLock(privdom);
>> +}
>>
>>  ret = 0;
>>   cleanup:
>> @@ -1971,8 +1975,10 @@ static int testDomainReboot(virDomainPtr domain,
>>   VIR_DOMAIN_EVENT_STOPPED,
>>   VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
>>
>> -if (!privdom->persistent)
>> +if (!privdom->persistent) {
>>  virDomainObjListRemove(privconn->domains, privdom);
>> +virObjectLock(privdom);
>> +}
>>  }
>>
>>  ret = 0;
>> @@ -2110,8 +2116,10 @@ testDomainSaveFlags(virDomainPtr domain, const char 
>> *path,
>>   VIR_DOMAIN_EVENT_STOPPED,
>>   VIR_DOMAIN_EVENT_STOPPED_SAVED);
>>
>> -if (!privdom->persistent)
>> +if (!privdom->persistent) {
>>  virDomainObjListRemove(privconn->domains, privdom);
>> +virObjectLock(privdom);
>> +}
>>
>>  ret = 0;
>>   cleanup:
>> @@ -2296,8 +2304,10 @@ static int testDomainCoreDumpWithFormat(virDomainPtr 
>> domain,
>>  event = virDomainEventLifecycleNewFromObj(privdom,
>>   VIR_DOMAIN_EVENT_STOPPED,
>>   VIR_DOMAIN_EVENT_STOPPED_CRASHED);
>> -if (!privdom->persistent)
>> +if (!privdom->persistent) {
>>  virDomainObjListRemove(privconn->domains, privdom);
>> +virObjectLock(privdom);
>> +}
>>  }
>>
>>  ret = 0;
>> @@ -3076,10 +3086,12 @@ static int testDomainUndefineFlags(virDomainPtr 
>> domain,
>>   VIR_DOMAIN_EVENT_UNDEFINED_REMOVED);
>>  privdom->hasManagedSave = false;
>>
>> -if (virDomainObjIsActive(privdom))
>> +if (virDomainObjIsActive(privdom)) {
>>  privdom->persistent = 0;
>> -else
>> +} else {
>>  virDomainObjListRemove(privconn->domains, privdom);
>> +virObjectLock(privdom);
>> +}
>>
>>  ret = 0;
>>
>> --
>> 2.13.6
>>
>> --
>> libvir-list mailing list
>> libvir-list@redhat.com
>> https://www.redhat.com/mailman/listinfo/libvir-list
>>
> 
> Reviewed-by: Marc Hartmayer 
> 
> I would change the order of this patch series as the last patch is a
> fix, no?

I can move it to be first as it's not related to the other two.

Thanks for the reviews!

John

> 
> --
> Beste Grüße / Kind regards
>Marc Hartmayer
> 
> IBM Deutschland Research & Development GmbH
> Vorsitzende des Aufsichtsrats: Martina Koederitz
> Geschäftsführung: Dirk Wittkopp
> Sitz der Gesellschaft: Böblingen
> Registergericht: Amtsgericht Stuttgart, HRB 243294
> 

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

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

2018-04-04 Thread Katerina Koukiou
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 @@
+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)
+{
+connect->networkPath = g_strdup_printf("%s/network", connect->connectPath);
+
+if (!interfaceInfo) {
+interfaceInfo = 
virtDBusGDBusLoadIntrospectData(VIRT_DBUS_NETWORK_INTERFACE,
+error);
+if (!interfaceInfo)
+return;
+}
+
+virtDBusGDBusRegisterSubtree(connect->bus,
+ connect->networkPath,
+ interfaceInfo,
+ virtDBusNetworkEnumerate,
+ virtDBusNetworkMethodTable,
+ virtDBusNetworkPropertyTable,
+ connect);
+}
diff --git a/src/network.h b/src/network.h
new file mode 100644
index 000..fc53b28
--- /dev/null
+++ b/src/network.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "connect.h"
+
+#define VIRT_DBUS_NETWORK_INTERFACE "org.libvirt.Network"
+
+void
+virtDBusNetworkRegister(virtDBusConnect *connect,
+GError **error);
diff --git a/src/util.c b/src/util.c
index be65172..fe40a96 100644
--- a/src/util.c
+++ b/src/util.c
@@ -151,3 +151,23 @@ virtDBusUtilEnumFromString(const gchar *const *types,
 
 return -1;
 }
+
+gchar *
+virtDBusUtilBusPathForVirNetwork(virNetworkPtr network,
+  

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

2018-04-04 Thread Katerina Koukiou
Signed-off-by: Katerina Koukiou 
---
 src/util.c | 13 +
 src/util.h |  5 +
 2 files changed, 18 insertions(+)

diff --git a/src/util.c b/src/util.c
index fe40a96..03a0f10 100644
--- a/src/util.c
+++ b/src/util.c
@@ -152,6 +152,19 @@ virtDBusUtilEnumFromString(const gchar *const *types,
 return -1;
 }
 
+virNetworkPtr
+virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
+ const gchar *path,
+ const gchar *networkPath)
+{
+g_autofree gchar *name = NULL;
+gsize prefixLen = strlen(networkPath) + 1;
+
+name = virtDBusUtilDecodeUUID(path+prefixLen);
+
+return virNetworkLookupByUUIDString(connection, name);
+}
+
 gchar *
 virtDBusUtilBusPathForVirNetwork(virNetworkPtr network,
  const gchar *networkPath)
diff --git a/src/util.h b/src/util.h
index fac080c..7bb4ad6 100644
--- a/src/util.h
+++ b/src/util.h
@@ -66,6 +66,11 @@ virtDBusUtilEnumToString(const gchar *const *types,
 const gchar *name ##TypeToString(gint type) G_GNUC_PURE; \
 gint name ##TypeFromString(const gchar *type) G_GNUC_PURE;
 
+virNetworkPtr
+virtDBusUtilVirNetworkFromBusPath(virConnectPtr connection,
+ const gchar *path,
+ const gchar *networkPath);
+
 gchar *
 virtDBusUtilBusPathForVirNetwork(virNetworkPtr network,
  const gchar *networkPath);
-- 
2.15.0

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


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

2018-04-04 Thread Katerina Koukiou
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 @@
   
   
 
+
+  https://libvirt.org/html/libvirt-libvirt-network.html#virConnectListAllNetworks"/>
+  
+  
+
   
 
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 }
 };
 
-- 
2.15.0

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


[libvirt] [dbus PATCH v2 0/5] Introduce Network Interface

2018-04-04 Thread Katerina Koukiou
This patchset introduces also some basic methods and properties for
Network interface.
More functionality will be added in following patchsets.
New functions are covered by the test suite.

Changes from v1: I forgot to the test_network.py in v1.

Katerina Koukiou (5):
  Introduce Network Interface
  Implement ListNetworks method for Connect interface
  Implement virtDBusUtilVirNetworkFromBusPath helper function.
  Implement Name property for Network interface
  Implement NetworkLookupByName method for Connect interface

 data/Makefile.am |   3 +-
 data/org.libvirt.Connect.xml |  12 +
 data/org.libvirt.Network.xml |  11 +
 src/Makefile.am  |   3 +-
 src/connect.c|  75 ++
 src/connect.h|   1 +
 src/network.c| 107 +++
 src/network.h|   9 
 src/util.c   |  33 +
 src/util.h   |  15 ++
 test/Makefile.am |   3 +-
 test/libvirttest.py  |  12 +
 test/test_connect.py |  11 +
 test/test_network.py |  19 
 14 files changed, 311 insertions(+), 3 deletions(-)
 create mode 100644 data/org.libvirt.Network.xml
 create mode 100644 src/network.c
 create mode 100644 src/network.h
 create mode 100755 test/test_network.py

-- 
2.15.0

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


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

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 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 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] [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
+
+  
+  
+
+
+
+
+  
+  
+
+
+
+
+
+
+
+
+  
+  
+
+
+  
+  
+
+
+
+  
+  
+
+
+
+  
+  
+
+
+
+  
+  
+
+  
+  
+
+
+  
+  
+
+
+  
+  
+
+
+  
+  
+
+  
+  
+
+
+
+  
+
+
+
+
+
+  
+  
+
+
+  
+
+
+  
+  
+
+
+
+  
+  
+
+
+
+
+  
+  
+
+
+
+  
+  
+
+
+  
+  
+
+  
+  
+
+  
+  
+
+
+  
+  
+
+
+  
+  
+   

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

[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 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 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 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 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 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 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 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 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 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 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] [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 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 @@
+
+  
+  
+  
+  
+
+  
+  
+
+
+  
+  
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

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

[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 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 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 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 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 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 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 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 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 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 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) {
-

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


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)
> +{
> +

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] [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

[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


  1   2   >