Re: [libvirt] [PATCH] add lock priv->lock protection in remoteClientCloseFunc()

2019-12-04 Thread Lance Liu
Hi:
Need any more informations about my patch?

LanceLiu  于2019年12月2日周一 上午11:16写道:

> sometimes, virsh console session may closed by virsh console existed
> session(when virsh console client
>  exit) and new virsh console --force session simutaneously. So in one
> thread(Job worker), it calls
> daemonStreamEvent() and referencing stream, and in another thread(main
> thread), virNetServerClientClose()
> was called, and the callback remoteClientCloseFunc() was called, without
> protect by priv->lock in
> remoteClientCloseFunc(), it may lead to daemonStreamEvent reference stream
> released by remoteClientCloseFunc(),
> and also need change virNetServerClientClose() to be
> virNetServerClientImmediateClose() in daemonStreamEvent(),
> or it lead to libvirt daemon deadlock by double lock priv->lock in
> daemonStreamEvent()
> ---
>  src/remote/remote_daemon_dispatch.c |  2 ++
>  src/remote/remote_daemon_stream.c   | 14 +++---
>  2 files changed, 9 insertions(+), 7 deletions(-)
>
> diff --git a/src/remote/remote_daemon_dispatch.c
> b/src/remote/remote_daemon_dispatch.c
> index f369ffb..b0982b7 100644
> --- a/src/remote/remote_daemon_dispatch.c
> +++ b/src/remote/remote_daemon_dispatch.c
> @@ -1724,7 +1724,9 @@ static void
> remoteClientCloseFunc(virNetServerClientPtr client)
>  {
>  struct daemonClientPrivate *priv =
> virNetServerClientGetPrivateData(client);
>
> +virMutexLock(>lock);
>  daemonRemoveAllClientStreams(priv->streams);
> +virMutexUnlock(>lock);
>
>  remoteClientFreePrivateCallbacks(priv);
>  }
> diff --git a/src/remote/remote_daemon_stream.c
> b/src/remote/remote_daemon_stream.c
> index 73e4d7b..6a84fdf 100644
> --- a/src/remote/remote_daemon_stream.c
> +++ b/src/remote/remote_daemon_stream.c
> @@ -141,7 +141,7 @@ daemonStreamEvent(virStreamPtr st, int events, void
> *opaque)
>  (events & VIR_STREAM_EVENT_WRITABLE)) {
>  if (daemonStreamHandleWrite(client, stream) < 0) {
>  daemonRemoveClientStream(client, stream);
> -virNetServerClientClose(client);
> +virNetServerClientImmediateClose(client);
>  goto cleanup;
>  }
>  }
> @@ -151,7 +151,7 @@ daemonStreamEvent(virStreamPtr st, int events, void
> *opaque)
>  events = events & ~(VIR_STREAM_EVENT_READABLE);
>  if (daemonStreamHandleRead(client, stream) < 0) {
>  daemonRemoveClientStream(client, stream);
> -virNetServerClientClose(client);
> +virNetServerClientImmediateClose(client);
>  goto cleanup;
>  }
>  /* If we detected EOF during read processing,
> @@ -176,7 +176,7 @@ daemonStreamEvent(virStreamPtr st, int events, void
> *opaque)
>  if (daemonStreamHandleFinish(client, stream, msg) < 0) {
>  virNetMessageFree(msg);
>  daemonRemoveClientStream(client, stream);
> -virNetServerClientClose(client);
> +virNetServerClientImmediateClose(client);
>  goto cleanup;
>  }
>  break;
> @@ -186,7 +186,7 @@ daemonStreamEvent(virStreamPtr st, int events, void
> *opaque)
>  if (daemonStreamHandleAbort(client, stream, msg) < 0) {
>  virNetMessageFree(msg);
>  daemonRemoveClientStream(client, stream);
> -virNetServerClientClose(client);
> +virNetServerClientImmediateClose(client);
>  goto cleanup;
>  }
>  break;
> @@ -205,7 +205,7 @@ daemonStreamEvent(virStreamPtr st, int events, void
> *opaque)
>  stream->recvEOF = true;
>  if (!(msg = virNetMessageNew(false))) {
>  daemonRemoveClientStream(client, stream);
> -virNetServerClientClose(client);
> +virNetServerClientImmediateClose(client);
>  goto cleanup;
>  }
>  msg->cb = daemonStreamMessageFinished;
> @@ -219,7 +219,7 @@ daemonStreamEvent(virStreamPtr st, int events, void
> *opaque)
>"", 0) < 0) {
>  virNetMessageFree(msg);
>  daemonRemoveClientStream(client, stream);
> -virNetServerClientClose(client);
> +virNetServerClientImmediateClose(client);
>  goto cleanup;
>  }
>  }
> @@ -262,7 +262,7 @@ daemonStreamEvent(virStreamPtr st, int events, void
> *opaque)
>  }
>  daemonRemoveClientStream(client, stream);
>  if (ret < 0)
> -virNetServerClientClose(client);
> +   virNetServerClientImmediateClose(client);
>  goto cleanup;
>  }
>
> --
> 1.8.3.1
>
>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2 20/25] qemu: Implement backup job APIs and qemu handling

2019-12-04 Thread Eric Blake

On 12/3/19 11:17 AM, Peter Krempa wrote:

This allows to start and manage the backup job.

Signed-off-by: Peter Krempa 
---
  po/POTFILES.in   |   1 +
  src/qemu/Makefile.inc.am |   2 +
  src/qemu/qemu_backup.c   | 941 +++


Large patch, but I'm not sure how it could be subdivided.


  src/qemu/qemu_backup.h   |  41 ++
  src/qemu/qemu_driver.c   |  47 ++
  5 files changed, 1032 insertions(+)
  create mode 100644 src/qemu/qemu_backup.c
  create mode 100644 src/qemu/qemu_backup.h




+++ b/src/qemu/qemu_backup.c



+static int
+qemuBackupPrepare(virDomainBackupDefPtr def)
+{
+
+if (def->type == VIR_DOMAIN_BACKUP_TYPE_PULL) {
+if (!def->server) {
+def->server = g_new(virStorageNetHostDef, 1);
+
+def->server->transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
+def->server->name = g_strdup("localhost");
+}
+
+switch ((virStorageNetHostTransport) def->server->transport) {
+case VIR_STORAGE_NET_HOST_TRANS_TCP:
+/* TODO: Update qemu.conf to provide a port range,
+ * probably starting at 10809, for obtaining automatic
+ * port via virPortAllocatorAcquire, as well as store
+ * somewhere if we need to call virPortAllocatorRelease
+ * during BackupEnd. Until then, user must provide port */


This TODO survives from my initial code, and does not seem to be 
addressed later in the series.  Not a show-stopper for the initial 
implementation, but something to remember for followup patches.



+if (!def->server->port) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+   _(" must specify TCP port for 
now"));
+return -1;
+}
+break;
+
+case VIR_STORAGE_NET_HOST_TRANS_UNIX:
+/* TODO: Do we need to mess with selinux? */


This should be addressed as well (or deleted, if it works out of the box).



+static int
+qemuBackupDiskPrepareOneBitmaps(struct qemuBackupDiskData *dd,
+virJSONValuePtr actions,
+virDomainMomentObjPtr *incremental)
+{
+g_autoptr(virJSONValue) mergebitmaps = NULL;
+g_autoptr(virJSONValue) mergebitmapsstore = NULL;
+
+if (!(mergebitmaps = virJSONValueNewArray()))
+return -1;
+
+/* TODO: this code works only if the bitmaps are present on a single node.
+ * The algorithm needs to be changed so that it looks into the backing 
chain
+ * so that we can combine all relevant bitmaps for a given backing chain */


Correct - but mixing incremental backup with external snapshots is 
something that we know is future work. It's okay for the initial 
implementation that we only support a single node.



+while (*incremental) {
+if (qemuMonitorTransactionBitmapMergeSourceAddBitmap(mergebitmaps,
+ 
dd->domdisk->src->nodeformat,
+ 
(*incremental)->def->name) < 0)
+return -1;
+
+incremental++;
+}
+
+if (!(mergebitmapsstore = virJSONValueCopy(mergebitmaps)))
+return -1;
+
+if (qemuMonitorTransactionBitmapAdd(actions,
+dd->domdisk->src->nodeformat,
+dd->incrementalBitmap,
+false,
+true) < 0)
+return -1;
+
+if (qemuMonitorTransactionBitmapMerge(actions,
+  dd->domdisk->src->nodeformat,
+  dd->incrementalBitmap,
+  ) < 0)
+return -1;
+
+if (qemuMonitorTransactionBitmapAdd(actions,
+dd->store->nodeformat,
+dd->incrementalBitmap,
+false,
+true) < 0)
+return -1;


Why do we need two of these calls?
/me reads on


+
+if (qemuMonitorTransactionBitmapMerge(actions,
+  dd->store->nodeformat,
+  dd->incrementalBitmap,
+  ) < 0)
+return -1;


okay, it looks like you are trying to merge the same bitmap into two 
different merge commands, which will all be part of the same 
transaction.  I guess it would be helpful to see a trace of the 
transaction in action to see if we can simplify it (using 2 instead of 4 
qemuMonitor* commands).



+
+
+return 0;
+}
+
+
+static int
+qemuBackupDiskPrepareDataOne(virDomainObjPtr vm,


and this is as far as my review got today.  I'll resume again as soon as 
I can.


Other than one obvious thing I saw in passing:


@@ -22953,6 +22998,8 @@ static 

Re: [libvirt] [PATCH v2 19/25] doc: Document quirk of getting block job info for a 'backup' blockjob

2019-12-04 Thread Eric Blake

On 12/3/19 11:17 AM, Peter Krempa wrote:

The stats reported for a blockjob which is member of a domain pull
backup refer to the utilization of the scratch file rather than the
progress of the backup as the progress of the backup depends on the
client. Note this quirk in the docs.

Signed-off-by: Peter Krempa 
---


Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

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



Re: [libvirt] [PATCH v2 18/25] conf: backup: Add fields for tracking stats of completed sub-jobs

2019-12-04 Thread Eric Blake

On 12/3/19 11:17 AM, Peter Krempa wrote:

We need a place to store stats of completed sub-jobs so that we can
later report accurate stats.

Signed-off-by: Peter Krempa 
---
  src/conf/backup_conf.h | 7 +++
  1 file changed, 7 insertions(+)

diff --git a/src/conf/backup_conf.h b/src/conf/backup_conf.h
index c970e01920..5dfc42e297 100644
--- a/src/conf/backup_conf.h
+++ b/src/conf/backup_conf.h
@@ -70,6 +70,13 @@ struct _virDomainBackupDef {

  size_t ndisks; /* should not exceed dom->ndisks */
  virDomainBackupDiskDef *disks;
+
+/* internal data */
+/* statistic totals for completed diks */


disks

With typo fix,
Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

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



Re: [libvirt] [PATCH v2 17/25] tests: qemustatusxml2xml: Add test for 'pull' type backup job

2019-12-04 Thread Eric Blake

On 12/3/19 11:17 AM, Peter Krempa wrote:

Signed-off-by: Peter Krempa 
---
  .../qemustatusxml2xmldata/backup-pull-in.xml  | 608 ++
  .../qemustatusxml2xmldata/backup-pull-out.xml |   1 +
  tests/qemuxml2xmltest.c   |   2 +
  3 files changed, 611 insertions(+)
  create mode 100644 tests/qemustatusxml2xmldata/backup-pull-in.xml
  create mode 12 tests/qemustatusxml2xmldata/backup-pull-out.xml


Reviewed-by: Eric Blake 


+++ b/tests/qemustatusxml2xmldata/backup-pull-out.xml
@@ -0,0 +1 @@
+backup-pull-in.xml
\ No newline at end of file


Odd that diff warns about this (empty files are an exception to the rule 
that a text file must end in a newline).  But harmless to the patch itself.


--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

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



Re: [libvirt] [PATCH v2 16/25] qemu: blockjob: Track internal data for 'backup' blockjob

2019-12-04 Thread Eric Blake

On 12/3/19 11:17 AM, Peter Krempa wrote:

A backup blockjob needs to be able to notify the parent backup job as
well as track all data to be able to clean up the bitmap and blockdev
used for the backup.

Add the data structure, job allocation function and status XML formatter
and parser.

Signed-off-by: Peter Krempa 
---


Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

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



Re: [libvirt] [PATCH v2 15/25] qemu: domain: Track backup job data in the status XML

2019-12-04 Thread Eric Blake

On 12/3/19 11:17 AM, Peter Krempa wrote:

Store the data of a backup job along with the index counter for new
backup jobs in the status XML. Currently we will support only one
backup job and thus there's no necessity to add arrays of jobs.

Signed-off-by: Peter Krempa 
---
  src/qemu/qemu_domain.c | 58 ++
  src/qemu/qemu_domain.h |  3 +++
  2 files changed, 61 insertions(+)



Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

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



Re: [libvirt] [PATCH v2 14/25] qemu: monitor: Add support for blockdev-backup via 'transaction'

2019-12-04 Thread Eric Blake

On 12/3/19 11:17 AM, Peter Krempa wrote:

Implement the transaction actions generator for blockdev-backup.

Signed-off-by: Peter Krempa 
---


Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

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



Re: [libvirt] [PATCH v2 13/25] Add 'backup' block job type

2019-12-04 Thread Eric Blake

On 12/3/19 11:17 AM, Peter Krempa wrote:

A backup job may consist of many backup sub-blockjobs. Add the new
blockjob type and add all type converter strings.

Signed-off-by: Peter Krempa 
---


Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

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



Re: [libvirt] [PATCH v2 12/25] qemu: domain: Introduce QEMU_ASYNC_JOB_BACKUP async job type

2019-12-04 Thread Eric Blake

On 12/3/19 11:17 AM, Peter Krempa wrote:

We will want to use the async job infrastructure along with all the APIs
and event for the backup job so add the backup job as a new async job
type.

Signed-off-by: Peter Krempa 
---


Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

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



Re: [libvirt] [PATCH v2 11/25] qemu: Add infrastructure for statistics of a backup job

2019-12-04 Thread Eric Blake

On 12/3/19 11:17 AM, Peter Krempa wrote:

Introduce QEMU_DOMAIN_JOB_STATS_TYPE_BACKUP and the convertors and other
plumbing to be able to report statistics for the backup job.

Signed-off-by: Peter Krempa 
---
  src/qemu/qemu_domain.c | 62 ++
  src/qemu/qemu_domain.h | 10 +++
  src/qemu/qemu_driver.c |  4 +++
  3 files changed, 76 insertions(+)




+++ b/src/qemu/qemu_driver.c
@@ -13905,6 +13905,10 @@ qemuDomainGetJobStatsInternal(virQEMUDriverPtr driver,
  goto cleanup;
  break;

+case QEMU_DOMAIN_JOB_STATS_TYPE_BACKUP:
+/* TODO implement for backup job */
+break;


The TODO goes away later in the series.

Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

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



Re: [libvirt] [PATCH v2 09/25] tests: genericxml2xml: Add testing of backup XML files

2019-12-04 Thread Eric Blake

On 12/3/19 11:17 AM, Peter Krempa wrote:

Now that the parser and formatter are in place we can excercise it on


exercise


the test files.

Signed-off-by: Peter Krempa 
---

Reviewed-by: Eric Blake 

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

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



Re: [libvirt] [python PATCH] Fix RPM deps for centos 7

2019-12-04 Thread Andrea Bolognani
On Wed, 2019-12-04 at 16:24 +, Daniel P. Berrangé wrote:
> +%if 0%{?rhel} == 7
> +BuildRequires: python36-nose
> +BuildRequires: python36-lxml
> +%else
>  BuildRequires: python3-nose
>  BuildRequires: python3-lxml
> +%endif

This should work just fine in an actual RHEL 7 machine, provided
that the user has installed the necessary Python 3 libraries through
EPEL and not for example Software Collections; I assume it would
simply fail to build in the latter case, which is not any worse than
what we had before.

Reviewed-by: Andrea Bolognani 

-- 
Andrea Bolognani / Red Hat / Virtualization

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

Re: [libvirt] [jenkins-ci PATCH] lcitool: Add 'install=' to the extra_arg

2019-12-04 Thread Andrea Bolognani
On Wed, 2019-12-04 at 17:19 +0100, Fabiano Fidêncio wrote:
> Add "install=" unconditionally to the extra_arg parameter passed to
> virt-install. It's needed as the virt-install present on CentOS CI host
> does not use the correct kernel URL argument when installing OpenSUSE.
> 
> This does not cause issues on other installations as the other distros
> will just ignore the argument passed.
> 
> Signed-off-by: Fabiano Fidêncio 
> ---
> I've verified this solution works on a CentOS 7 host. I've verified this
> solution doesn't cause regressions on a Fedora 31 host.
> ---
>  guests/lcitool | 9 +++--
>  1 file changed, 7 insertions(+), 2 deletions(-)

I've tweaked the comment and the code formatting a bit, added my

  Reviewed-by: Andrea Bolognani 

and pushed.

-- 
Andrea Bolognani / Red Hat / Virtualization

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

[libvirt] [PATCH] qemuProcessStop: Remove image metadata only when allowed

2019-12-04 Thread Michal Privoznik
In v5.9.0-370-g8fa0374c5b I've tried to fix a bug by removing
some stale XATTRs in qemuProcessStop(). However, I forgot to
do nothing when the VIR_QEMU_PROCESS_STOP_NO_RELABEL flag was
specified. 臘

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_process.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 75ee3893c6..df19977bb3 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -7648,13 +7648,15 @@ void qemuProcessStop(virQEMUDriverPtr driver,
 /* Do this explicitly after vm->pid is reset so that security drivers don't
  * try to enter the domain's namespace which is non-existent by now as qemu
  * is no longer running. */
-for (i = 0; i < def->ndisks; i++) {
-virDomainDiskDefPtr disk = def->disks[i];
+if ((flags & VIR_QEMU_PROCESS_STOP_NO_RELABEL)) {
+for (i = 0; i < def->ndisks; i++) {
+virDomainDiskDefPtr disk = def->disks[i];
 
-if (disk->mirror)
-qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->mirror);
+if (disk->mirror)
+qemuBlockRemoveImageMetadata(driver, vm, disk->dst, 
disk->mirror);
 
-qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->src);
+qemuBlockRemoveImageMetadata(driver, vm, disk->dst, disk->src);
+}
 }
 
 /* clear all private data entries which are no longer needed */
-- 
2.23.0

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

[libvirt] [python PATCH] Fix RPM deps for centos 7

2019-12-04 Thread Daniel P . Berrangé
Signed-off-by: Daniel P. Berrangé 
---
 libvirt-python.spec.in | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libvirt-python.spec.in b/libvirt-python.spec.in
index 1e92f3c..33d2775 100644
--- a/libvirt-python.spec.in
+++ b/libvirt-python.spec.in
@@ -21,8 +21,13 @@ Url: http://libvirt.org
 License: LGPLv2+
 BuildRequires: libvirt-devel == %{version}
 BuildRequires: python3-devel
+%if 0%{?rhel} == 7
+BuildRequires: python36-nose
+BuildRequires: python36-lxml
+%else
 BuildRequires: python3-nose
 BuildRequires: python3-lxml
+%endif
 BuildRequires: gcc
 
 # Don't want provides for python shared objects
-- 
2.23.0

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

[libvirt] [jenkins-ci PATCH] lcitool: Add 'install=' to the extra_arg

2019-12-04 Thread Fabiano Fidêncio
Add "install=" unconditionally to the extra_arg parameter passed to
virt-install. It's needed as the virt-install present on CentOS CI host
does not use the correct kernel URL argument when installing OpenSUSE.

This does not cause issues on other installations as the other distros
will just ignore the argument passed.

Signed-off-by: Fabiano Fidêncio 
---
I've verified this solution works on a CentOS 7 host. I've verified this
solution doesn't cause regressions on a Fedora 31 host.
---
 guests/lcitool | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/guests/lcitool b/guests/lcitool
index 0e27796..c7f949d 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -542,8 +542,13 @@ class Application:
 # but we need to point anaconda in the right direction through
 # the 'ks' kernel parameter. We can use 'ks' unconditionally
 # for simplicity's sake, because distributions that don't use
-# kickstart for unattended installation will simply ignore it
-extra_arg = "console=ttyS0 ks=file:/{}".format(install_config)
+# kickstart for unattended installation will simply ignore it.
+# Similarly to how we can use 'ks' unconditionally, we also can
+# do the same with 'install' argument, needed to workaround a
+# a bug on virt-install as it does not use the correct kernel
+# URL argument when installing an OpenSUSE guest.
+extra_arg = ("console=ttyS0 ks=file:/{} install={}".
+ format(install_config, facts["install_url"]))
 
 virt_install = distutils.spawn.find_executable("virt-install")
 if virt_install is None:
-- 
2.23.0

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

Re: [libvirt] [PATCH] build: only support python3 binary

2019-12-04 Thread Daniel P . Berrangé
On Wed, Dec 04, 2019 at 09:59:48AM -0600, Eric Blake wrote:
> On 12/4/19 4:14 AM, Daniel P. Berrangé wrote:
> > python2 will be end of life by the time of the next
> > libvirt release. All our supported build targets, including
> > CentOS7, have a python3 build available.
> > 
> > Signed-off-by: Daniel P. Berrangé 
> > ---
> 
> > +++ b/configure.ac
> > @@ -701,9 +701,9 @@ if test "$with_linux" = "yes"; then
> >   fi
> >   dnl Allow perl/python overrides
> > -AC_PATH_PROGS([PYTHON], [python3 python2 python])
> > +AC_PATH_PROGS([PYTHON], [python3])
> 
> Are there any systems with python version 3 installed only as the name
> 'python', or does everyone with python 3 follow the PEP recommendations and
> have a 'python3' available?  (It matters on whether your list needs two
> instead of one spelling for acceptable programs to attempt).

There is talk about allowing a plain 'python' to refer to python 3 as a
convenience for humans. Anywhere which does that will still also provide
a 'python3' binary. So ignoring existance of 'python' seems like the safer
option for scripts.

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] build: only support python3 binary

2019-12-04 Thread Eric Blake

On 12/4/19 4:14 AM, Daniel P. Berrangé wrote:

python2 will be end of life by the time of the next
libvirt release. All our supported build targets, including
CentOS7, have a python3 build available.

Signed-off-by: Daniel P. Berrangé 
---



+++ b/configure.ac
@@ -701,9 +701,9 @@ if test "$with_linux" = "yes"; then
  fi
  
  dnl Allow perl/python overrides

-AC_PATH_PROGS([PYTHON], [python3 python2 python])
+AC_PATH_PROGS([PYTHON], [python3])


Are there any systems with python version 3 installed only as the name 
'python', or does everyone with python 3 follow the PEP recommendations 
and have a 'python3' available?  (It matters on whether your list needs 
two instead of one spelling for acceptable programs to attempt).


--
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

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

Re: [libvirt] [jenkins-ci PATCH] Drop support for python 2

2019-12-04 Thread Andrea Bolognani
On Wed, 2019-12-04 at 13:26 +, Daniel P. Berrangé wrote:
[...]
> +++ b/guests/host_vars/libvirt-centos-7/main.yml
> @@ -16,5 +16,3 @@ package_format: 'rpm'
>  package_manager: 'yum'
>  os_name: 'CentOS'
>  os_version: '7'
> -
> -ansible_python_interpreter: /usr/bin/python2

This will not work: you need to explicitly point Ansible to a Python
3 interpreter, or it will still prefer Python 2 if available, which
it still is on CentOS 7.

Actually, it's more complicated than that: if you point Ansible to a
Python 3 interpreter, you will soon get

  TASK [Enable EPEL repository] *
  fatal: [libvirt-centos-7]: FAILED! => {"changed": false, "msg":
  "The Python 2 bindings for rpm are needed for this module. If you
  require Python 3 support use the `dnf` Ansible module instead.. The
  Python 2 yum module is needed for this module. If you require
  Python 3 support use the `dnf` Ansible module instead."}

I have posted

  https://www.redhat.com/archives/libvir-list/2019-December/msg00239.html

which addresses the issue. Please drop this hunk.

[...]
> +++ b/guests/playbooks/update/tasks/bootstrap.yml
> @@ -7,11 +7,5 @@
>  - set_fact:
>  python: python3
>  
> -- set_fact:
> -python: python2
> -  when:
> -- os_name == 'CentOS'
> -- os_version == '7'

We don't want this, because as mentioned above we still need Python 2
for Ansible. Please drop this hunk.

[...]
> +++ b/guests/vars/projects/libvirt-python.yml
> @@ -1,9 +1,5 @@
>  ---
>  packages:
> -  - python2
> -  - python2-devel
> -  - python2-lxml
> -  - python2-nose
>- python3-devel
>- python3-lxml
>- python3-nose

These other changes are fine, so

  Reviewed-by: Andrea Bolognani 

if you drop the first two hunks and push after the patch of mine
I mentioned above.

Note that the libvirt-python-rpm job will still fail with

  $ rpmbuild --clean --define "_topdir `pwd`/rpmbuild" -ta dist/*.tar.gz
  error: Failed build dependencies:
python3-nose is needed by libvirt-python-5.10.0-1.el7.x86_64

That's because on CentOS 7 we have python36-nose (from EPEL) instead
of python3-nose, and python36-lxml instead of python3-lxml. These
issues need to be fixed in libvirt-python, though.

-- 
Andrea Bolognani / Red Hat / Virtualization

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

Re: [libvirt] [jenkins-ci PATCH] lcitool: Decouple Python interpreters for Ansible and builds

2019-12-04 Thread Daniel P . Berrangé
On Wed, Dec 04, 2019 at 03:23:25PM +0100, Andrea Bolognani wrote:
> We need to keep using Python 2 for Ansible, because Python 3 is
> only supported by the dnf module and on CentOS 7 we have to use
> the yum module instead; at the same time, all libvirt projects
> have now dropped Python 2 support so we need to make sure we use
> Python 3 for building them.
> 
> Decouple the Python versions used for the two purposes so that
> we can keep everything working.
> 
> Signed-off-by: Andrea Bolognani 
> ---
>  guests/playbooks/update/tasks/paths.yml | 2 ++
>  guests/playbooks/update/templates/bashrc.j2 | 2 +-
>  2 files changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé 


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

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

[libvirt] [PATCH 13/30] conf: drop virCapsPtr param from post parse data alloc callback

2019-12-04 Thread Daniel P . Berrangé
The only user of this callback did not require the virCapsPtr parameter.

Signed-off-by: Daniel P. Berrangé 
---
 src/conf/domain_conf.c | 4 ++--
 src/conf/domain_conf.h | 1 -
 src/qemu/qemu_domain.c | 1 -
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7327752810..164c313ac6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5498,7 +5498,7 @@ virDomainDeviceDefPostParseOne(virDomainDeviceDefPtr dev,
 int ret;
 
 if (!parseOpaque && xmlopt->config.domainPostParseDataAlloc) {
-if (xmlopt->config.domainPostParseDataAlloc(def, caps, flags,
+if (xmlopt->config.domainPostParseDataAlloc(def, flags,
 xmlopt->config.priv,
 ) < 0)
 return -1;
@@ -5833,7 +5833,7 @@ virDomainDefPostParse(virDomainDefPtr def,
 
 if (!data.parseOpaque &&
 xmlopt->config.domainPostParseDataAlloc) {
-ret = xmlopt->config.domainPostParseDataAlloc(def, caps, parseFlags,
+ret = xmlopt->config.domainPostParseDataAlloc(def, parseFlags,
   xmlopt->config.priv,
   );
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index cdbd42351f..86d0b47a66 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2664,7 +2664,6 @@ typedef int 
(*virDomainDefAssignAddressesCallback)(virDomainDef *def,
void *parseOpaque);
 
 typedef int (*virDomainDefPostParseDataAlloc)(const virDomainDef *def,
-  virCapsPtr caps,
   unsigned int parseFlags,
   void *opaque,
   void **parseOpaque);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 3c06b8a104..70683eb83a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8143,7 +8143,6 @@ qemuDomainDefAssignAddresses(virDomainDef *def,
 
 static int
 qemuDomainPostParseDataAlloc(const virDomainDef *def,
- virCapsPtr caps G_GNUC_UNUSED,
  unsigned int parseFlags G_GNUC_UNUSED,
  void *opaque,
  void **parseOpaque)
-- 
2.23.0

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

[libvirt] [PATCH 30/30] qemu: stop creating capabilities at driver startup

2019-12-04 Thread Daniel P . Berrangé
Now that nearly all internal APIs use the QEMU capabilities or other
QEMU driver data directly, there's no compelling benefit to create
virCapsPtr at driver startup.

Skipping this means we don't probe capabilities for all 30 system
emulator targets at startup, only those emulators which are referenced
by an XML doc. This massively improves libvirtd startup time when the
capabilities cache is not populated. It even improves startup time
when the cache is up to date, as we don't bother to load files from
the cache until we need them.

Signed-off-by: Daniel P. Berrangé 
---
 src/qemu/qemu_conf.c   | 13 +++--
 src/qemu/qemu_driver.c |  3 ---
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 9df4ae1230..c24c99d129 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1318,13 +1318,14 @@ virCapsPtr 
virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
 driver->caps = caps;
 } else {
 qemuDriverLock(driver);
-}
 
-if (driver->caps->nguests == 0 && !refresh) {
-VIR_DEBUG("Capabilities didn't detect any guests. Forcing a "
-"refresh.");
-qemuDriverUnlock(driver);
-return virQEMUDriverGetCapabilities(driver, true);
+if (driver->caps == NULL ||
+driver->caps->nguests == 0) {
+VIR_DEBUG("Capabilities didn't detect any guests. Forcing a "
+  "refresh.");
+qemuDriverUnlock(driver);
+return virQEMUDriverGetCapabilities(driver, true);
+}
 }
 
 ret = virObjectRef(driver->caps);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1fe310e16c..f50af3ee94 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -907,9 +907,6 @@ qemuStateInitialize(bool privileged,
 if (!qemu_driver->qemuCapsCache)
 goto error;
 
-if ((qemu_driver->caps = virQEMUDriverCreateCapabilities(qemu_driver)) == 
NULL)
-goto error;
-
 if (!(sec_managers = qemuSecurityGetNested(qemu_driver->securityManager)))
 goto error;
 
-- 
2.23.0

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

[libvirt] [PATCH 05/30] conf: pass in default architecture via domain XML options

2019-12-04 Thread Daniel P . Berrangé
When parsing the guest XML we must fill in the default guest arch if it
is not already present because later parts of the parsing process need
this information.

If no arch is specified we lookup the first guest in the capabilities
data matching the os type and virt type. In most cases this will result
in picking the host architecture but there are some exceptions...

 - The test driver is hardcoded to always use i686 arch
 - The VMWare/ESX drivers will always place i686 guests ahead
   of x86_64 guests in capabilities, so effectively they always
   use i686
 - The QEMU driver can potentially return any arch at all
   depending on what combination of QEMU binaries are installed.

The domain XML hardware configurations are inherently architecture
specific in many places. As a result whomever/whatever created the
domain XML will have had a particular architecture in mind when
specifying the config. In pretty much any sensible case this arch
will have been the native host architecture. i686 on x86_64 is
the only sensible divergance because both these archs are
compatible from a domaain XML config POV.

IOW, although the QEMU driver can pick an almost arbitrary arch as its
default, in the real world no application or user is likely to be
relying on this default arch being anything other than native.

With all this in mind, it is reasonable to change the XML parser to
allow the default architecture to be passed via the domain XML options
struct. If no info is explicitly given then it is safe & sane to pick
the host native architecture as the default for the guest.

Signed-off-by: Daniel P. Berrangé 
---
 docs/formatdomain.html.in  |  6 +-
 src/conf/domain_conf.c | 12 +---
 src/conf/domain_conf.h |  1 +
 src/test/test_driver.c |  1 +
 src/vmware/vmware_driver.c |  1 +
 src/vmx/vmx.c  |  1 +
 6 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 6df4a8b26e..d7092761c5 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -175,7 +175,11 @@
 and machine referring
 to the machine type. The Capabilities XML
 provides details on allowed values for
-these. Since 0.0.1
+these. If arch is omitted then for most hypervisor
+drivers, the host native arch will be chosen. For the 
test,
+ESX and VMWare hypervisor drivers, however,
+the i686 arch will always be chosen even on an
+x86_64 host. Since 0.0.1
   loader
   The optional loader tag refers to a firmware blob,
 which is specified by absolute path,
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 781bf9d2d4..1c2b8f26ed 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19565,6 +19565,7 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
 static int
 virDomainDefParseCaps(virDomainDefPtr def,
   xmlXPathContextPtr ctxt,
+  virDomainXMLOptionPtr xmlopt,
   virCapsPtr caps,
   unsigned int flags)
 {
@@ -19625,6 +19626,13 @@ virDomainDefParseCaps(virDomainDefPtr def,
 return -1;
 }
 
+if (def->os.arch == VIR_ARCH_NONE) {
+if (xmlopt && xmlopt->config.defArch != VIR_ARCH_NONE)
+def->os.arch = xmlopt->config.defArch;
+else
+def->os.arch = virArchFromHost();
+}
+
 if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
  def->os.arch,
  def->virtType,
@@ -19633,8 +19641,6 @@ virDomainDefParseCaps(virDomainDefPtr def,
 return -1;
 virResetLastError();
 } else {
-if (!def->os.arch)
-def->os.arch = capsdata->arch;
 if (!def->os.machine)
 def->os.machine = g_strdup(capsdata->machinetype);
 }
@@ -19792,7 +19798,7 @@ virDomainDefParseXML(xmlDocPtr xml,
 id = -1;
 def->id = (int)id;
 
-if (virDomainDefParseCaps(def, ctxt, caps, flags) < 0)
+if (virDomainDefParseCaps(def, ctxt, xmlopt, caps, flags) < 0)
 goto error;
 
 /* Extract domain name */
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f7a611d5ef..e1622f2112 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2705,6 +2705,7 @@ struct _virDomainDefParserConfig {
 /* data */
 unsigned int features; /* virDomainDefFeatures */
 unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
+virArch defArch;
 };
 
 typedef void *(*virDomainXMLPrivateDataAllocFunc)(void *);
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index e7ec537bb0..f2700d90bc 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -424,6 +424,7 @@ testDriverNew(void)
 VIR_DOMAIN_DEF_FEATURE_USER_ALIAS |
 VIR_DOMAIN_DEF_FEATURE_FW_AUTOSELECT |
 

[libvirt] [PATCH 26/30] qemu: use NUMA capabilities object directly

2019-12-04 Thread Daniel P . Berrangé
Avoid grabbing the whole virCapsPtr object when we only need the
NUMA information.

Signed-off-by: Daniel P. Berrangé 
---
 src/qemu/qemu_capabilities.c |  7 ---
 src/qemu/qemu_conf.c | 17 +++
 src/qemu/qemu_conf.h |  6 ++
 src/qemu/qemu_domain.c   | 10 -
 src/qemu/qemu_process.c  | 40 +++-
 tests/testutilsqemu.c| 18 +++-
 6 files changed, 57 insertions(+), 41 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index ea3558a3db..66bee49d6f 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1032,13 +1032,6 @@ virQEMUCapsInit(virFileCachePtr cache)
true, true)) == NULL)
 goto error;
 
-/* Some machines have problematic NUMA topology causing
- * unexpected failures. We don't want to break the QEMU
- * driver in this scenario, so log errors & carry on
- */
-if (!(caps->host.numa = virCapabilitiesHostNUMANewHost()))
-goto error;
-
 if (virCapabilitiesInitCaches(caps) < 0)
 VIR_WARN("Failed to get host CPU cache info");
 
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 053bcc7e02..ba3001ccd0 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1204,6 +1204,22 @@ virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver,
 }
 
 
+virCapsHostNUMAPtr
+virQEMUDriverGetHostNUMACaps(virQEMUDriverPtr driver)
+{
+qemuDriverLock(driver);
+
+if (!driver->hostnuma)
+driver->hostnuma = virCapabilitiesHostNUMANewHost();
+
+qemuDriverUnlock(driver);
+
+virCapabilitiesHostNUMARef(driver->hostnuma);
+
+return driver->hostnuma;
+}
+
+
 virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver)
 {
 size_t i, j;
@@ -1255,6 +1271,7 @@ virCapsPtr 
virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver)
   "DOI \"%s\"", model, doi);
 }
 
+caps->host.numa = virQEMUDriverGetHostNUMACaps(driver);
 return g_steal_pointer();
 }
 
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 8b6c2a95d4..2d03df9171 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -262,6 +262,11 @@ struct _virQEMUDriver {
  */
 virCapsPtr caps;
 
+/* Lazy initialized on first use, immutable thereafter.
+ * Require lock to get the pointer & do optional initialization
+ */
+virCapsHostNUMAPtr hostnuma;
+
 /* Immutable value */
 virArch hostarch;
 
@@ -319,6 +324,7 @@ virQEMUDriverConfigSetDefaults(virQEMUDriverConfigPtr cfg);
 virQEMUDriverConfigPtr virQEMUDriverGetConfig(virQEMUDriverPtr driver);
 bool virQEMUDriverIsPrivileged(virQEMUDriverPtr driver);
 
+virCapsHostNUMAPtr virQEMUDriverGetHostNUMACaps(virQEMUDriverPtr driver);
 virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver);
 virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
 bool refresh);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index e1cbffa935..a18da01bf9 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2922,7 +2922,7 @@ 
qemuDomainObjPrivateXMLParseAutomaticPlacement(xmlXPathContextPtr ctxt,
qemuDomainObjPrivatePtr priv,
virQEMUDriverPtr driver)
 {
-virCapsPtr caps = NULL;
+g_autoptr(virCapsHostNUMA) caps = NULL;
 char *nodeset;
 char *cpuset;
 int nodesetSize = 0;
@@ -2935,15 +2935,15 @@ 
qemuDomainObjPrivateXMLParseAutomaticPlacement(xmlXPathContextPtr ctxt,
 if (!nodeset && !cpuset)
 return 0;
 
-if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+if (!(caps = virQEMUDriverGetHostNUMACaps(driver)))
 goto cleanup;
 
 /* Figure out how big the nodeset bitmap needs to be.
  * This is necessary because NUMA node IDs are not guaranteed to
  * start from 0 or be densely allocated */
-for (i = 0; i < caps->host.numa->cells->len; i++) {
+for (i = 0; i < caps->cells->len; i++) {
 virCapsHostNUMACellPtr cell =
-g_ptr_array_index(caps->host.numa->cells, i);
+g_ptr_array_index(caps->cells, i);
 nodesetSize = MAX(nodesetSize, cell->num + 1);
 }
 
@@ -2957,7 +2957,7 @@ 
qemuDomainObjPrivateXMLParseAutomaticPlacement(xmlXPathContextPtr ctxt,
 } else {
 /* autoNodeset is present in this case, since otherwise we wouldn't
  * reach this code */
-if (!(priv->autoCpuset = 
virCapabilitiesHostNUMAGetCpus(caps->host.numa,
+if (!(priv->autoCpuset = virCapabilitiesHostNUMAGetCpus(caps,
 
priv->autoNodeset)))
 goto cleanup;
 }
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 623ea761e1..cc89ff8571 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6129,14 

[libvirt] [jenkins-ci PATCH] lcitool: Decouple Python interpreters for Ansible and builds

2019-12-04 Thread Andrea Bolognani
We need to keep using Python 2 for Ansible, because Python 3 is
only supported by the dnf module and on CentOS 7 we have to use
the yum module instead; at the same time, all libvirt projects
have now dropped Python 2 support so we need to make sure we use
Python 3 for building them.

Decouple the Python versions used for the two purposes so that
we can keep everything working.

Signed-off-by: Andrea Bolognani 
---
 guests/playbooks/update/tasks/paths.yml | 2 ++
 guests/playbooks/update/templates/bashrc.j2 | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/guests/playbooks/update/tasks/paths.yml 
b/guests/playbooks/update/tasks/paths.yml
index aada1f3..c204462 100644
--- a/guests/playbooks/update/tasks/paths.yml
+++ b/guests/playbooks/update/tasks/paths.yml
@@ -14,6 +14,7 @@
 - make
 - ninja
 - ninja-build
+- python3
 - su
 
 - name: 'Look for files'
@@ -39,6 +40,7 @@
 bash: '{{ commands["bash"] }}'
 ccache: '{{ commands["ccache"] }}'
 java: '{{ commands["java"] }}'
+python: '{{ commands["python3"] }}'
 su: '{{ commands["su"] }}'
 sudoers: '{{ files["sudoers"] }}'
 
diff --git a/guests/playbooks/update/templates/bashrc.j2 
b/guests/playbooks/update/templates/bashrc.j2
index d3fc652..9cea90c 100644
--- a/guests/playbooks/update/templates/bashrc.j2
+++ b/guests/playbooks/update/templates/bashrc.j2
@@ -2,7 +2,7 @@ export PS1="[\u@\h \w]\$ "
 
 export MAKE="{{ make }}"
 export NINJA="{{ ninja }}"
-export PYTHON="{{ ansible_python_interpreter }}"
+export PYTHON="{{ python }}"
 
 export MAKEFLAGS="-j{{ install_vcpus|int + 1 }}"
 
-- 
2.23.0

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



[libvirt] [PATCH 04/30] conf: sanitize virDomainObjFormat & virDomainDefFormat* APIs

2019-12-04 Thread Daniel P . Berrangé
Moving their instance parameter to be the first one, and give consistent
ordering of other parameters across all functions. Ensure that the xml
options are passed into both functions in prep for future work.

Signed-off-by: Daniel P. Berrangé 
---
 src/bhyve/bhyve_driver.c |  4 +--
 src/conf/checkpoint_conf.c   |  4 +--
 src/conf/domain_conf.c   | 39 --
 src/conf/domain_conf.h   | 28 +++-
 src/conf/snapshot_conf.c | 10 +++---
 src/esx/esx_driver.c |  4 +--
 src/hyperv/hyperv_driver.c   |  3 +-
 src/libxl/libxl_domain.c | 12 +++
 src/libxl/libxl_driver.c |  8 ++---
 src/libxl/libxl_migration.c  |  4 +--
 src/lxc/lxc_driver.c |  4 +--
 src/lxc/lxc_process.c| 12 +++
 src/openvz/openvz_conf.c | 55 +++
 src/openvz/openvz_conf.h |  1 +
 src/openvz/openvz_driver.c   | 56 ++--
 src/phyp/phyp_driver.c   |  2 +-
 src/qemu/qemu_domain.c   |  5 ++-
 src/security/security_apparmor.c |  2 +-
 src/test/test_driver.c   |  8 +++--
 src/vbox/vbox_common.c   |  2 +-
 src/vmware/vmware_driver.c   |  4 +--
 src/vz/vz_driver.c   |  4 +--
 tests/Makefile.am|  3 +-
 tests/lxcconf2xmltest.c  |  2 +-
 tests/openvzutilstest.c  |  4 ++-
 tests/qemuhotplugtest.c  |  6 ++--
 tests/qemuxml2xmltest.c  |  2 +-
 tests/testutils.c|  2 +-
 tests/vmx2xmltest.c  |  2 +-
 tests/xlconfigtest.c |  3 +-
 tests/xmconfigtest.c |  2 +-
 31 files changed, 161 insertions(+), 136 deletions(-)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index b8a206bb1e..18b5d1e950 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -495,7 +495,7 @@ bhyveDomainGetXMLDesc(virDomainPtr domain, unsigned int 
flags)
 if (!caps)
 goto cleanup;
 
-ret = virDomainDefFormat(vm->def, caps,
+ret = virDomainDefFormat(vm->def, privconn->xmlopt, caps,
  virDomainDefFormatConvertXMLFlags(flags));
 
 virObjectUnref(caps);
@@ -1583,7 +1583,7 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn,
 if (def == NULL)
 goto cleanup;
 
-xml = virDomainDefFormat(def, capabilities, 0);
+xml = virDomainDefFormat(def, privconn->xmlopt, capabilities, 0);
 
  cleanup:
 virObjectUnref(capabilities);
diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c
index 36076c13df..cb2d83796c 100644
--- a/src/conf/checkpoint_conf.c
+++ b/src/conf/checkpoint_conf.c
@@ -489,8 +489,8 @@ virDomainCheckpointDefFormatInternal(virBufferPtr buf,
 }
 
 if (!(flags & VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN) &&
-virDomainDefFormatInternal(def->parent.dom, caps, domainflags, buf,
-   xmlopt) < 0)
+virDomainDefFormatInternal(def->parent.dom, xmlopt,
+   caps, buf, domainflags) < 0)
 goto error;
 
 virBufferAdjustIndent(buf, -2);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 87bbb2d263..781bf9d2d4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -23600,8 +23600,8 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr src,
  error:
 virErrorPreserveLast();
 
-strSrc = virDomainDefFormat(src, NULL, 0);
-strDst = virDomainDefFormat(dst, NULL, 0);
+strSrc = virDomainDefFormat(src, xmlopt, NULL, 0);
+strDst = virDomainDefFormat(dst, xmlopt, NULL, 0);
 VIR_DEBUG("XMLs that failed stability check were: src=\"%s\", dst=\"%s\"",
   NULLSTR(strSrc), NULLSTR(strDst));
 
@@ -28286,13 +28286,13 @@ virDomainDefFormatFeatures(virBufferPtr buf,
 
 int
 virDomainDefFormatInternal(virDomainDefPtr def,
+   virDomainXMLOptionPtr xmlopt,
virCapsPtr caps,
-   unsigned int flags,
virBufferPtr buf,
-   virDomainXMLOptionPtr xmlopt)
+   unsigned int flags)
 {
-return virDomainDefFormatInternalSetRootName(def, caps, flags, buf,
- xmlopt, "domain");
+return virDomainDefFormatInternalSetRootName(def, xmlopt, caps, buf,
+ "domain", flags);
 }
 
 
@@ -28302,11 +28302,11 @@ virDomainDefFormatInternal(virDomainDefPtr def,
  * Return -1 on failure.  */
 int
 virDomainDefFormatInternalSetRootName(virDomainDefPtr def,
+  virDomainXMLOptionPtr xmlopt,
   virCapsPtr caps,
-  unsigned int flags,
   virBufferPtr buf,
-  virDomainXMLOptionPtr xmlopt,
-   

[libvirt] [PATCH 17/30] conf: drop virCapsPtr param from domain formatting APIs

2019-12-04 Thread Daniel P . Berrangé
This parameter is now unused and can be removed entirely.

Signed-off-by: Daniel P. Berrangé 
---
 src/bhyve/bhyve_driver.c | 16 ++--
 src/conf/checkpoint_conf.c   |  4 ++--
 src/conf/domain_conf.c   | 26 +++---
 src/conf/domain_conf.h   |  4 
 src/conf/snapshot_conf.c |  6 +++---
 src/esx/esx_driver.c |  4 ++--
 src/hyperv/hyperv_driver.c   |  2 +-
 src/libxl/libxl_domain.c | 12 ++--
 src/libxl/libxl_driver.c |  8 
 src/libxl/libxl_migration.c  |  4 ++--
 src/lxc/lxc_driver.c |  4 ++--
 src/lxc/lxc_process.c| 12 ++--
 src/openvz/openvz_driver.c   |  4 ++--
 src/phyp/phyp_driver.c   |  2 +-
 src/qemu/qemu_domain.c   |  2 +-
 src/security/security_apparmor.c |  2 +-
 src/test/test_driver.c   |  6 +++---
 src/vbox/vbox_common.c   |  2 +-
 src/vmware/vmware_driver.c   |  4 ++--
 src/vz/vz_driver.c   |  4 ++--
 tests/bhyveargv2xmltest.c|  2 +-
 tests/lxcconf2xmltest.c  |  2 +-
 tests/openvzutilstest.c  |  2 +-
 tests/qemuhotplugtest.c  |  6 +++---
 tests/qemuxml2xmltest.c  |  2 +-
 tests/testutils.c|  2 +-
 tests/vmx2xmltest.c  |  2 +-
 tests/xlconfigtest.c |  2 +-
 tests/xmconfigtest.c |  2 +-
 29 files changed, 65 insertions(+), 85 deletions(-)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 18b5d1e950..8432044b60 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -480,7 +480,6 @@ bhyveDomainGetXMLDesc(virDomainPtr domain, unsigned int 
flags)
 {
 bhyveConnPtr privconn = domain->conn->privateData;
 virDomainObjPtr vm;
-virCapsPtr caps = NULL;
 char *ret = NULL;
 
 virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL);
@@ -491,14 +490,9 @@ bhyveDomainGetXMLDesc(virDomainPtr domain, unsigned int 
flags)
 if (virDomainGetXMLDescEnsureACL(domain->conn, vm->def, flags) < 0)
 goto cleanup;
 
-caps = bhyveDriverGetCapabilities(privconn);
-if (!caps)
-goto cleanup;
-
-ret = virDomainDefFormat(vm->def, privconn->xmlopt, caps,
+ret = virDomainDefFormat(vm->def, privconn->xmlopt,
  virDomainDefFormatConvertXMLFlags(flags));
 
-virObjectUnref(caps);
  cleanup:
 virDomainObjEndAPI();
 return ret;
@@ -1561,7 +1555,6 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn,
 char *xml = NULL;
 virDomainDefPtr def = NULL;
 bhyveConnPtr privconn = conn->privateData;
-virCapsPtr capabilities = NULL;
 unsigned caps = bhyveDriverGetCaps(conn);
 
 virCheckFlags(0, NULL);
@@ -1569,10 +1562,6 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn,
 if (virConnectDomainXMLFromNativeEnsureACL(conn) < 0)
 return NULL;
 
-capabilities = bhyveDriverGetCapabilities(privconn);
-if (!capabilities)
-return NULL;
-
 if (STRNEQ(nativeFormat, BHYVE_CONFIG_FORMAT_ARGV)) {
 virReportError(VIR_ERR_INVALID_ARG,
_("unsupported config type %s"), nativeFormat);
@@ -1583,10 +1572,9 @@ bhyveConnectDomainXMLFromNative(virConnectPtr conn,
 if (def == NULL)
 goto cleanup;
 
-xml = virDomainDefFormat(def, privconn->xmlopt, capabilities, 0);
+xml = virDomainDefFormat(def, privconn->xmlopt, 0);
 
  cleanup:
-virObjectUnref(capabilities);
 virDomainDefFree(def);
 return xml;
 }
diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c
index cb2d83796c..37cc8e5e6c 100644
--- a/src/conf/checkpoint_conf.c
+++ b/src/conf/checkpoint_conf.c
@@ -446,7 +446,7 @@ virDomainCheckpointDiskDefFormat(virBufferPtr buf,
 static int
 virDomainCheckpointDefFormatInternal(virBufferPtr buf,
  virDomainCheckpointDefPtr def,
- virCapsPtr caps,
+ virCapsPtr caps G_GNUC_UNUSED,
  virDomainXMLOptionPtr xmlopt,
  unsigned int flags)
 {
@@ -490,7 +490,7 @@ virDomainCheckpointDefFormatInternal(virBufferPtr buf,
 
 if (!(flags & VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN) &&
 virDomainDefFormatInternal(def->parent.dom, xmlopt,
-   caps, buf, domainflags) < 0)
+   buf, domainflags) < 0)
 goto error;
 
 virBufferAdjustIndent(buf, -2);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7431aad0cf..44e56976d9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -23559,8 +23559,8 @@ virDomainDefCheckABIStabilityFlags(virDomainDefPtr src,
  error:
 virErrorPreserveLast();
 
-strSrc = virDomainDefFormat(src, xmlopt, NULL, 0);
-strDst = virDomainDefFormat(dst, xmlopt, NULL, 0);
+strSrc = virDomainDefFormat(src, xmlopt, 0);
+strDst = 

[libvirt] [PATCH 24/30] qemu: drop virCapsPtr param & vars from many APIs

2019-12-04 Thread Daniel P . Berrangé
Now that the domain XML APIs don't use virCapsPtr we can stop passing it
around many QEMU driver methods.

Signed-off-by: Daniel P. Berrangé 
---
 src/qemu/qemu_checkpoint.c | 24 +++
 src/qemu/qemu_checkpoint.h |  1 -
 src/qemu/qemu_domain.c |  3 +--
 src/qemu/qemu_domain.h |  1 -
 src/qemu/qemu_driver.c | 39 +-
 src/qemu/qemu_process.c| 10 --
 6 files changed, 17 insertions(+), 61 deletions(-)

diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c
index 2101932a28..30f65630ca 100644
--- a/src/qemu/qemu_checkpoint.c
+++ b/src/qemu/qemu_checkpoint.c
@@ -78,7 +78,6 @@ qemuCheckpointObjFromCheckpoint(virDomainObjPtr vm,
 static int
 qemuCheckpointWriteMetadata(virDomainObjPtr vm,
 virDomainMomentObjPtr checkpoint,
-virCapsPtr caps G_GNUC_UNUSED,
 virDomainXMLOptionPtr xmlopt,
 const char *checkpointDir)
 {
@@ -197,7 +196,7 @@ qemuCheckpointDiscard(virQEMUDriverPtr driver,
 virDomainCheckpointSetCurrent(vm->checkpoints, NULL);
 if (update_parent && parent) {
 virDomainCheckpointSetCurrent(vm->checkpoints, parent);
-if (qemuCheckpointWriteMetadata(vm, parent, driver->caps,
+if (qemuCheckpointWriteMetadata(vm, parent,
 driver->xmlopt,
 cfg->checkpointDir) < 0) {
 VIR_WARN("failed to set parent checkpoint '%s' as current",
@@ -239,7 +238,6 @@ qemuCheckpointDiscardAllMetadata(virQEMUDriverPtr driver,
 /* Called inside job lock */
 static int
 qemuCheckpointPrepare(virQEMUDriverPtr driver,
-  virCapsPtr caps G_GNUC_UNUSED,
   virDomainObjPtr vm,
   virDomainCheckpointDefPtr def)
 {
@@ -373,7 +371,6 @@ qemuCheckpointRedefine(virQEMUDriverPtr driver,
 int
 qemuCheckpointCreateCommon(virQEMUDriverPtr driver,
virDomainObjPtr vm,
-   virCapsPtr caps,
virDomainCheckpointDefPtr *def,
virJSONValuePtr *actions,
virDomainMomentObjPtr *chk)
@@ -381,7 +378,7 @@ qemuCheckpointCreateCommon(virQEMUDriverPtr driver,
 g_autoptr(virJSONValue) tmpactions = NULL;
 virDomainMomentObjPtr parent;
 
-if (qemuCheckpointPrepare(driver, caps, vm, *def) < 0)
+if (qemuCheckpointPrepare(driver, vm, *def) < 0)
 return -1;
 
 if ((parent = virDomainCheckpointGetCurrent(vm->checkpoints)))
@@ -406,14 +403,13 @@ qemuCheckpointCreateCommon(virQEMUDriverPtr driver,
 static virDomainMomentObjPtr
 qemuCheckpointCreate(virQEMUDriverPtr driver,
  virDomainObjPtr vm,
- virCapsPtr caps,
  virDomainCheckpointDefPtr *def)
 {
 g_autoptr(virJSONValue) actions = NULL;
 virDomainMomentObjPtr chk = NULL;
 int rc;
 
-if (qemuCheckpointCreateCommon(driver, vm, caps, def, , ) < 0)
+if (qemuCheckpointCreateCommon(driver, vm, def, , ) < 0)
 return NULL;
 
 qemuDomainObjEnterMonitor(driver, vm);
@@ -437,7 +433,7 @@ qemuCheckpointCreateFinalize(virQEMUDriverPtr driver,
 if (update_current)
 virDomainCheckpointSetCurrent(vm->checkpoints, chk);
 
-if (qemuCheckpointWriteMetadata(vm, chk, driver->caps,
+if (qemuCheckpointWriteMetadata(vm, chk,
 driver->xmlopt,
 cfg->checkpointDir) < 0) {
 /* if writing of metadata fails, error out rather than trying
@@ -469,7 +465,6 @@ qemuCheckpointCreateXML(virDomainPtr domain,
 bool redefine = flags & VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE;
 unsigned int parse_flags = 0;
 g_autoptr(virQEMUDriverConfig) cfg = NULL;
-g_autoptr(virCaps) caps = NULL;
 g_autoptr(virDomainCheckpointDef) def = NULL;
 
 virCheckFlags(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE, NULL);
@@ -485,9 +480,6 @@ qemuCheckpointCreateXML(virDomainPtr domain,
 return NULL;
 }
 
-if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
-return NULL;
-
 if (!virDomainObjIsActive(vm)) {
 virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("cannot create checkpoint for inactive domain"));
@@ -506,7 +498,7 @@ qemuCheckpointCreateXML(virDomainPtr domain,
 if (redefine) {
 chk = qemuCheckpointRedefine(driver, vm, , _current);
 } else {
-chk = qemuCheckpointCreate(driver, vm, caps, );
+chk = qemuCheckpointCreate(driver, vm, );
 }
 
 if (!chk)
@@ -557,7 +549,6 @@ struct virQEMUCheckpointReparent {
 const char *dir;
 virDomainMomentObjPtr parent;
 virDomainObjPtr vm;
-virCapsPtr caps;
 virDomainXMLOptionPtr xmlopt;
 int err;
 };
@@ -579,7 +570,7 @@ 

[libvirt] [PATCH 25/30] conf: move NUMA capabilities into self contained object

2019-12-04 Thread Daniel P . Berrangé
The NUMA cells are stored directly in the virCapsHostPtr
struct. This moves them into their own struct allowing
them to be stored independantly of the rest of the host
capabilities. The change is used as an excuse to switch
the representation to use a GPtrArray too.

Signed-off-by: Daniel P. Berrangé 
---
 src/conf/capabilities.c| 200 +++--
 src/conf/capabilities.h|  27 +++--
 src/conf/virconftypes.h|   3 +
 src/libvirt_private.syms   |  10 +-
 src/libxl/libxl_capabilities.c |  20 ++--
 src/lxc/lxc_conf.c |   6 +-
 src/openvz/openvz_conf.c   |   2 +-
 src/phyp/phyp_driver.c |   7 +-
 src/qemu/qemu_capabilities.c   |   6 +-
 src/qemu/qemu_domain.c |  11 +-
 src/qemu/qemu_migration.c  |   5 -
 src/qemu/qemu_process.c|   2 +-
 src/test/test_driver.c |   9 +-
 src/vbox/vbox_common.c |   2 +-
 src/vmware/vmware_conf.c   |   2 +-
 src/vz/vz_driver.c |   2 +-
 tests/testutils.c  |  23 ++--
 tests/testutils.h  |   3 +-
 tests/testutilsqemu.c  |   2 +-
 tests/vircaps2xmltest.c|   6 +-
 tests/vircapstest.c|  11 +-
 21 files changed, 194 insertions(+), 165 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index 748dd64273..7021283310 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -182,14 +182,19 @@ virCapabilitiesFreeStoragePool(virCapsStoragePoolPtr pool)
 
 
 void
-virCapabilitiesFreeNUMAInfo(virCapsPtr caps)
+virCapabilitiesHostNUMAUnref(virCapsHostNUMAPtr caps)
 {
-size_t i;
+if (g_atomic_int_dec_and_test(>refs)) {
+g_ptr_array_unref(caps->cells);
+
+VIR_FREE(caps);
+}
+}
 
-for (i = 0; i < caps->host.nnumaCell; i++)
-virCapabilitiesFreeHostNUMACell(caps->host.numaCell[i]);
-VIR_FREE(caps->host.numaCell);
-caps->host.nnumaCell = 0;
+void
+virCapabilitiesHostNUMARef(virCapsHostNUMAPtr caps)
+{
+g_atomic_int_inc(>refs);
 }
 
 static void
@@ -234,7 +239,8 @@ virCapsDispose(void *object)
 VIR_FREE(caps->host.features[i]);
 VIR_FREE(caps->host.features);
 
-virCapabilitiesFreeNUMAInfo(caps);
+if (caps->host.numa)
+virCapabilitiesHostNUMAUnref(caps->host.numa);
 
 for (i = 0; i < caps->host.nmigrateTrans; i++)
 VIR_FREE(caps->host.migrateTrans[i]);
@@ -320,7 +326,7 @@ virCapabilitiesSetNetPrefix(virCapsPtr caps,
 
 
 /**
- * virCapabilitiesAddHostNUMACell:
+ * virCapabilitiesHostNUMAAddCell:
  * @caps: capabilities to extend
  * @num: ID number of NUMA cell
  * @mem: Total size of memory in the NUMA node (in KiB)
@@ -334,8 +340,8 @@ virCapabilitiesSetNetPrefix(virCapsPtr caps,
  * Registers a new NUMA cell for a host, passing in a
  * array of CPU IDs belonging to the cell
  */
-int
-virCapabilitiesAddHostNUMACell(virCapsPtr caps,
+void
+virCapabilitiesHostNUMAAddCell(virCapsHostNUMAPtr caps,
int num,
unsigned long long mem,
int ncpus,
@@ -345,14 +351,7 @@ virCapabilitiesAddHostNUMACell(virCapsPtr caps,
int npageinfo,
virCapsHostNUMACellPageInfoPtr pageinfo)
 {
-virCapsHostNUMACellPtr cell;
-
-if (VIR_RESIZE_N(caps->host.numaCell, caps->host.nnumaCell_max,
- caps->host.nnumaCell, 1) < 0)
-return -1;
-
-if (VIR_ALLOC(cell) < 0)
-return -1;
+virCapsHostNUMACellPtr cell = g_new0(virCapsHostNUMACell, 1);
 
 cell->num = num;
 cell->mem = mem;
@@ -363,9 +362,7 @@ virCapabilitiesAddHostNUMACell(virCapsPtr caps,
 cell->npageinfo = npageinfo;
 cell->pageinfo = pageinfo;
 
-caps->host.numaCell[caps->host.nnumaCell++] = cell;
-
-return 0;
+g_ptr_array_add(caps->cells, cell);
 }
 
 
@@ -857,9 +854,8 @@ virCapabilitiesAddStoragePool(virCapsPtr caps,
 
 
 static int
-virCapabilitiesFormatNUMATopology(virBufferPtr buf,
-  size_t ncells,
-  virCapsHostNUMACellPtr *cells)
+virCapabilitiesHostNUMAFormat(virCapsHostNUMAPtr caps,
+  virBufferPtr buf)
 {
 size_t i;
 size_t j;
@@ -867,48 +863,49 @@ virCapabilitiesFormatNUMATopology(virBufferPtr buf,
 
 virBufferAddLit(buf, "\n");
 virBufferAdjustIndent(buf, 2);
-virBufferAsprintf(buf, "\n", ncells);
+virBufferAsprintf(buf, "\n", caps->cells->len);
 virBufferAdjustIndent(buf, 2);
-for (i = 0; i < ncells; i++) {
-virBufferAsprintf(buf, "\n", cells[i]->num);
+for (i = 0; i < caps->cells->len; i++) {
+virCapsHostNUMACellPtr cell = g_ptr_array_index(caps->cells, i);
+virBufferAsprintf(buf, "\n", cell->num);
 virBufferAdjustIndent(buf, 2);
 
 /* Print out the numacell memory total if it is available */
-if (cells[i]->mem)
+if (cell->mem)
 

[libvirt] [PATCH 29/30] qemu: directly create virResctrlInfo ignoring capabilities

2019-12-04 Thread Daniel P . Berrangé
We always refresh the capabilities object when using virResctrlInfo
during process startup. This is undesirable overhead, because we can
just directly create a virResctrlInfo instead.

Signed-off-by: Daniel P. Berrangé 
---
 src/qemu/qemu_process.c | 24 
 src/util/virresctrl.h   |  2 ++
 2 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 3a3860b1a3..2b35680abc 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2724,29 +2724,24 @@ qemuProcessSetupEmulator(virDomainObjPtr vm)
 
 
 static int
-qemuProcessResctrlCreate(virQEMUDriverPtr driver,
- virDomainObjPtr vm)
+qemuProcessResctrlCreate(virDomainObjPtr vm)
 {
-int ret = -1;
 size_t i = 0;
-virCapsPtr caps = NULL;
 qemuDomainObjPrivatePtr priv = vm->privateData;
+g_autoptr(virResctrlInfo) resctrl = NULL;
 
 if (!vm->def->nresctrls)
 return 0;
 
-/* Force capability refresh since resctrl info can change
- * XXX: move cache info into virresctrl so caps are not needed */
-caps = virQEMUDriverGetCapabilities(driver, true);
-if (!caps)
+if (!(resctrl = virResctrlInfoNew()))
 return -1;
 
 for (i = 0; i < vm->def->nresctrls; i++) {
 size_t j = 0;
-if (virResctrlAllocCreate(caps->host.resctrl,
+if (virResctrlAllocCreate(resctrl,
   vm->def->resctrls[i]->alloc,
   priv->machineName) < 0)
-goto cleanup;
+return -1;
 
 for (j = 0; j < vm->def->resctrls[i]->nmonitors; j++) {
 virDomainResctrlMonDefPtr mon = NULL;
@@ -2754,14 +2749,11 @@ qemuProcessResctrlCreate(virQEMUDriverPtr driver,
 mon = vm->def->resctrls[i]->monitors[j];
 if (virResctrlMonitorCreate(mon->instance,
 priv->machineName) < 0)
-goto cleanup;
+return -1;
 }
 }
 
-ret = 0;
- cleanup:
-virObjectUnref(caps);
-return ret;
+return 0;
 }
 
 
@@ -6882,7 +6874,7 @@ qemuProcessLaunch(virConnectPtr conn,
 goto cleanup;
 
 VIR_DEBUG("Setting up resctrl");
-if (qemuProcessResctrlCreate(driver, vm) < 0)
+if (qemuProcessResctrlCreate(vm) < 0)
 goto cleanup;
 
 VIR_DEBUG("Setting up managed PR daemon");
diff --git a/src/util/virresctrl.h b/src/util/virresctrl.h
index 3dd7c96348..759320d0fd 100644
--- a/src/util/virresctrl.h
+++ b/src/util/virresctrl.h
@@ -100,6 +100,8 @@ typedef virResctrlInfo *virResctrlInfoPtr;
 virResctrlInfoPtr
 virResctrlInfoNew(void);
 
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virResctrlInfo, virObjectUnref);
+
 int
 virResctrlInfoGetCache(virResctrlInfoPtr resctrl,
unsigned int level,
-- 
2.23.0

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

[libvirt] [PATCH 28/30] qemu: use host CPU object directly

2019-12-04 Thread Daniel P . Berrangé
Avoid grabbing the whole virCapsPtr object when we only need the
host CPU information.

Signed-off-by: Daniel P. Berrangé 
---
 src/qemu/qemu_capabilities.c |  3 --
 src/qemu/qemu_conf.c | 17 +
 src/qemu/qemu_conf.h |  6 
 src/qemu/qemu_driver.c   |  6 ++--
 src/qemu/qemu_process.c  | 68 +++-
 tests/domaincapstest.c   | 14 +++-
 tests/qemucapabilitiestest.c |  9 ++---
 tests/qemuxml2argvtest.c |  8 ++---
 tests/testutilsqemu.c| 49 +++---
 tests/testutilsqemu.h|  5 ++-
 10 files changed, 89 insertions(+), 96 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 16c4331b13..1b395a2570 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1035,9 +1035,6 @@ virQEMUCapsInit(virFileCachePtr cache)
 if (virCapabilitiesInitCaches(caps) < 0)
 VIR_WARN("Failed to get host CPU cache info");
 
-if (!(caps->host.cpu = virCPUProbeHost(caps->host.arch)))
-VIR_WARN("Failed to get host CPU");
-
 /* Add the power management features of the host */
 if (virNodeSuspendGetTargetMask(>host.powerMgmt) < 0)
 VIR_WARN("Failed to get host power management capabilities");
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index ba3001ccd0..9df4ae1230 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1220,6 +1220,22 @@ virQEMUDriverGetHostNUMACaps(virQEMUDriverPtr driver)
 }
 
 
+virCPUDefPtr
+virQEMUDriverGetHostCPU(virQEMUDriverPtr driver)
+{
+qemuDriverLock(driver);
+
+if (!driver->hostcpu)
+driver->hostcpu = virCPUProbeHost(virArchFromHost());
+
+qemuDriverUnlock(driver);
+
+virCPUDefRef(driver->hostcpu);
+
+return driver->hostcpu;
+}
+
+
 virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver)
 {
 size_t i, j;
@@ -1272,6 +1288,7 @@ virCapsPtr 
virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver)
 }
 
 caps->host.numa = virQEMUDriverGetHostNUMACaps(driver);
+caps->host.cpu = virQEMUDriverGetHostCPU(driver);
 return g_steal_pointer();
 }
 
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 2d03df9171..d2e0bd97e1 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -267,6 +267,11 @@ struct _virQEMUDriver {
  */
 virCapsHostNUMAPtr hostnuma;
 
+/* Lazy initialized on first use, immutable thereafter.
+ * Require lock to get the pointer & do optional initialization
+ */
+virCPUDefPtr hostcpu;
+
 /* Immutable value */
 virArch hostarch;
 
@@ -325,6 +330,7 @@ virQEMUDriverConfigPtr 
virQEMUDriverGetConfig(virQEMUDriverPtr driver);
 bool virQEMUDriverIsPrivileged(virQEMUDriverPtr driver);
 
 virCapsHostNUMAPtr virQEMUDriverGetHostNUMACaps(virQEMUDriverPtr driver);
+virCPUDefPtr virQEMUDriverGetHostCPU(virQEMUDriverPtr driver);
 virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver);
 virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
 bool refresh);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ae6facc829..1fe310e16c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13354,7 +13354,7 @@ qemuConnectCompareCPU(virConnectPtr conn,
   unsigned int flags)
 {
 virQEMUDriverPtr driver = conn->privateData;
-g_autoptr(virCaps) caps = NULL;
+g_autoptr(virCPUDef) cpu = NULL;
 bool failIncompatible;
 
 virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE,
@@ -13365,10 +13365,10 @@ qemuConnectCompareCPU(virConnectPtr conn,
 
 failIncompatible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE);
 
-if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+if (!(cpu = virQEMUDriverGetHostCPU(driver)))
 return VIR_CPU_COMPARE_ERROR;
 
-return virCPUCompareXML(driver->hostarch, caps->host.cpu,
+return virCPUCompareXML(driver->hostarch, cpu,
 xmlDesc, failIncompatible);
 }
 
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index cc89ff8571..3a3860b1a3 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -5291,12 +5291,13 @@ qemuProcessStartValidateDisks(virDomainObjPtr vm,
 
 
 static int
-qemuProcessStartValidateTSC(virDomainObjPtr vm,
-virCapsPtr caps)
+qemuProcessStartValidateTSC(virQEMUDriverPtr driver,
+virDomainObjPtr vm)
 {
 size_t i;
 unsigned long long freq = 0;
 virHostCPUTscInfoPtr tsc;
+g_autoptr(virCPUDef) cpu = NULL;
 
 for (i = 0; i < vm->def->clock.ntimers; i++) {
 virDomainTimerDefPtr timer = vm->def->clock.timers[i];
@@ -5313,12 +5314,13 @@ qemuProcessStartValidateTSC(virDomainObjPtr vm,
 
 VIR_DEBUG("Requested TSC frequency %llu Hz", freq);
 
-if (!caps->host.cpu || !caps->host.cpu->tsc) {
+cpu = virQEMUDriverGetHostCPU(driver);
+if (!cpu || 

[libvirt] [PATCH 23/30] conf: drop virCapsPtr param from snapshot & checkpoint APIs

2019-12-04 Thread Daniel P . Berrangé
Signed-off-by: Daniel P. Berrangé 
---
 src/conf/checkpoint_conf.c  | 15 ---
 src/conf/checkpoint_conf.h  |  2 --
 src/conf/snapshot_conf.c| 14 --
 src/conf/snapshot_conf.h|  3 ---
 src/esx/esx_driver.c|  4 ++--
 src/qemu/qemu_checkpoint.c  |  8 
 src/qemu/qemu_domain.c  |  4 ++--
 src/qemu/qemu_driver.c  | 20 
 src/test/test_driver.c  |  8 +++-
 src/vbox/vbox_common.c  |  6 ++
 tests/qemudomaincheckpointxml2xmltest.c |  4 ++--
 tests/qemudomainsnapshotxml2xmltest.c   |  4 ++--
 12 files changed, 29 insertions(+), 63 deletions(-)

diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c
index 581e382b6d..26bcfc16b7 100644
--- a/src/conf/checkpoint_conf.c
+++ b/src/conf/checkpoint_conf.c
@@ -115,13 +115,10 @@ virDomainCheckpointDiskDefParseXML(xmlNodePtr node,
 return 0;
 }
 
-/* flags is bitwise-or of virDomainCheckpointParseFlags.  If flags
- * does not include VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE, then caps
- * is ignored.
+/* flags is bitwise-or of virDomainCheckpointParseFlags.
  */
 static virDomainCheckpointDefPtr
 virDomainCheckpointDefParse(xmlXPathContextPtr ctxt,
-virCapsPtr caps G_GNUC_UNUSED,
 virDomainXMLOptionPtr xmlopt,
 void *parseOpaque,
 unsigned int flags)
@@ -201,7 +198,6 @@ virDomainCheckpointDefParse(xmlXPathContextPtr ctxt,
 static virDomainCheckpointDefPtr
 virDomainCheckpointDefParseNode(xmlDocPtr xml,
 xmlNodePtr root,
-virCapsPtr caps,
 virDomainXMLOptionPtr xmlopt,
 void *parseOpaque,
 unsigned int flags)
@@ -227,12 +223,11 @@ virDomainCheckpointDefParseNode(xmlDocPtr xml,
 return NULL;
 
 ctxt->node = root;
-return virDomainCheckpointDefParse(ctxt, caps, xmlopt, parseOpaque, flags);
+return virDomainCheckpointDefParse(ctxt, xmlopt, parseOpaque, flags);
 }
 
 virDomainCheckpointDefPtr
 virDomainCheckpointDefParseString(const char *xmlStr,
-  virCapsPtr caps,
   virDomainXMLOptionPtr xmlopt,
   void *parseOpaque,
   unsigned int flags)
@@ -244,7 +239,7 @@ virDomainCheckpointDefParseString(const char *xmlStr,
 if ((xml = virXMLParse(NULL, xmlStr, _("(domain_checkpoint)" {
 xmlKeepBlanksDefault(keepBlanksDefault);
 ret = virDomainCheckpointDefParseNode(xml, xmlDocGetRootElement(xml),
-  caps, xmlopt, parseOpaque, 
flags);
+  xmlopt, parseOpaque, flags);
 xmlFreeDoc(xml);
 }
 xmlKeepBlanksDefault(keepBlanksDefault);
@@ -446,7 +441,6 @@ virDomainCheckpointDiskDefFormat(virBufferPtr buf,
 static int
 virDomainCheckpointDefFormatInternal(virBufferPtr buf,
  virDomainCheckpointDefPtr def,
- virCapsPtr caps G_GNUC_UNUSED,
  virDomainXMLOptionPtr xmlopt,
  unsigned int flags)
 {
@@ -505,7 +499,6 @@ virDomainCheckpointDefFormatInternal(virBufferPtr buf,
 
 char *
 virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def,
- virCapsPtr caps,
  virDomainXMLOptionPtr xmlopt,
  unsigned int flags)
 {
@@ -514,7 +507,7 @@ virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def,
 virCheckFlags(VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE |
   VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN |
   VIR_DOMAIN_CHECKPOINT_FORMAT_SIZE, NULL);
-if (virDomainCheckpointDefFormatInternal(, def, caps, xmlopt,
+if (virDomainCheckpointDefFormatInternal(, def, xmlopt,
  flags) < 0)
 return NULL;
 
diff --git a/src/conf/checkpoint_conf.h b/src/conf/checkpoint_conf.h
index 982096abed..ee5d210593 100644
--- a/src/conf/checkpoint_conf.h
+++ b/src/conf/checkpoint_conf.h
@@ -74,7 +74,6 @@ virDomainCheckpointFormatConvertXMLFlags(unsigned int flags);
 
 virDomainCheckpointDefPtr
 virDomainCheckpointDefParseString(const char *xmlStr,
-  virCapsPtr caps,
   virDomainXMLOptionPtr xmlopt,
   void *parseOpaque,
   unsigned int flags);
@@ -84,7 +83,6 @@ virDomainCheckpointDefNew(void);
 
 char *
 virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def,
- virCapsPtr caps,
  

[libvirt] [PATCH 18/30] conf: drop virCapsPtr param from domain post parse & validate APIs

2019-12-04 Thread Daniel P . Berrangé
Signed-off-by: Daniel P. Berrangé 
---
 src/conf/domain_conf.c  | 10 --
 src/conf/domain_conf.h  |  2 --
 src/libxl/xen_xl.c  |  2 +-
 src/libxl/xen_xm.c  |  2 +-
 src/lxc/lxc_native.c|  4 ++--
 src/qemu/qemu_driver.c  | 12 ++--
 src/qemu/qemu_process.c |  4 ++--
 src/vmx/vmx.c   |  4 ++--
 8 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 44e56976d9..b1384a1487 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5802,7 +5802,6 @@ virDomainDefPostParseCheckFailure(virDomainDefPtr def,
 
 int
 virDomainDefPostParse(virDomainDefPtr def,
-  virCapsPtr caps G_GNUC_UNUSED,
   unsigned int parseFlags,
   virDomainXMLOptionPtr xmlopt,
   void *parseOpaque)
@@ -7107,7 +7106,6 @@ virDomainDefValidateInternal(const virDomainDef *def,
  */
 int
 virDomainDefValidate(virDomainDefPtr def,
- virCapsPtr caps G_GNUC_UNUSED,
  unsigned int parseFlags,
  virDomainXMLOptionPtr xmlopt)
 {
@@ -21518,11 +21516,11 @@ virDomainObjParseXML(xmlDocPtr xml,
 parseOpaque = xmlopt->privateData.getParseOpaque(obj);
 
 /* callback to fill driver specific domain aspects */
-if (virDomainDefPostParse(obj->def, caps, flags, xmlopt, parseOpaque) < 0)
+if (virDomainDefPostParse(obj->def, flags, xmlopt, parseOpaque) < 0)
 goto error;
 
 /* validate configuration */
-if (virDomainDefValidate(obj->def, caps, flags, xmlopt) < 0)
+if (virDomainDefValidate(obj->def, flags, xmlopt) < 0)
 goto error;
 
 return obj;
@@ -21607,11 +21605,11 @@ virDomainDefParseNode(xmlDocPtr xml,
 return NULL;
 
 /* callback to fill driver specific domain aspects */
-if (virDomainDefPostParse(def, caps, flags, xmlopt, parseOpaque) < 0)
+if (virDomainDefPostParse(def, flags, xmlopt, parseOpaque) < 0)
 return NULL;
 
 /* validate configuration */
-if (virDomainDefValidate(def, caps, flags, xmlopt) < 0)
+if (virDomainDefValidate(def, flags, xmlopt) < 0)
 return NULL;
 
 return g_steal_pointer();
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index b98fe5eba5..4f3c9fdc8b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2783,7 +2783,6 @@ virDomainSCSIDriveAddressIsUsed(const virDomainDef *def,
 const virDomainDeviceDriveAddress *addr);
 
 int virDomainDefPostParse(virDomainDefPtr def,
-  virCapsPtr caps,
   unsigned int parseFlags,
   virDomainXMLOptionPtr xmlopt,
   void *parseOpaque);
@@ -2796,7 +2795,6 @@ int 
virDomainDeviceValidateAliasForHotplug(virDomainObjPtr vm,
 bool virDomainDeviceAliasIsUserAlias(const char *aliasStr);
 
 int virDomainDefValidate(virDomainDefPtr def,
- virCapsPtr caps,
  unsigned int parseFlags,
  virDomainXMLOptionPtr xmlopt);
 
diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c
index 396adf6dac..18ea4a8d95 100644
--- a/src/libxl/xen_xl.c
+++ b/src/libxl/xen_xl.c
@@ -1213,7 +1213,7 @@ xenParseXL(virConfPtr conf,
 if (xenParseXLChannel(conf, def) < 0)
 goto cleanup;
 
-if (virDomainDefPostParse(def, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
+if (virDomainDefPostParse(def, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
   xmlopt, NULL) < 0)
 goto cleanup;
 
diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c
index 88cf9ac5b0..1b462d0487 100644
--- a/src/libxl/xen_xm.c
+++ b/src/libxl/xen_xm.c
@@ -467,7 +467,7 @@ xenParseXM(virConfPtr conf,
 if (xenParseXMInputDevs(conf, def) < 0)
  goto cleanup;
 
-if (virDomainDefPostParse(def, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
+if (virDomainDefPostParse(def, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
   xmlopt, NULL) < 0)
 goto cleanup;
 
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 7e696fd2f0..e9b83653b5 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -1055,7 +1055,7 @@ lxcSetCapDrop(virDomainDefPtr def, virConfPtr properties)
 
 virDomainDefPtr
 lxcParseConfigString(const char *config,
- virCapsPtr caps,
+ virCapsPtr caps G_GNUC_UNUSED,
  virDomainXMLOptionPtr xmlopt)
 {
 virDomainDefPtr vmdef = NULL;
@@ -1166,7 +1166,7 @@ lxcParseConfigString(const char *config,
 /* lxc.cap.drop */
 lxcSetCapDrop(vmdef, properties);
 
-if (virDomainDefPostParse(vmdef, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
+if (virDomainDefPostParse(vmdef, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
   xmlopt, NULL) < 0)
 goto error;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 93a92dad36..32eae175ed 

[libvirt] [PATCH 27/30] conf: make virCPUDef into a ref counted struct

2019-12-04 Thread Daniel P . Berrangé
Annoyingly there was no existing constructor, and identifying all the
places which do a VIR_ALLOC(cpu) is a bit error prone. Hopefully this
has found & converted them all.

Signed-off-by: Daniel P. Berrangé 
---
 src/conf/cpu_conf.c| 29 ++---
 src/conf/cpu_conf.h|  4 
 src/cpu/cpu.c  |  3 +--
 src/cpu/cpu_arm.c  |  5 +
 src/cpu/cpu_ppc64.c|  3 +--
 src/cpu/cpu_x86.c  |  6 ++
 src/libvirt_private.syms   |  2 ++
 src/libxl/libxl_capabilities.c |  3 +--
 src/libxl/xen_xl.c | 11 +++
 src/qemu/qemu_capabilities.c   |  8 ++--
 src/qemu/qemu_domain.c |  2 +-
 src/vmx/vmx.c  |  3 +--
 tests/cputest.c| 11 +++
 13 files changed, 44 insertions(+), 46 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 4542bcb7bd..7490d6bf73 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -82,6 +82,13 @@ VIR_ENUM_IMPL(virCPUCacheMode,
 );
 
 
+virCPUDefPtr virCPUDefNew(void)
+{
+virCPUDefPtr cpu = g_new0(virCPUDef, 1);
+cpu->refs = 1;
+return cpu;
+}
+
 void
 virCPUDefFreeFeatures(virCPUDefPtr def)
 {
@@ -104,16 +111,24 @@ virCPUDefFreeModel(virCPUDefPtr def)
 virCPUDefFreeFeatures(def);
 }
 
+void
+virCPUDefRef(virCPUDefPtr def)
+{
+g_atomic_int_inc(>refs);
+}
+
 void
 virCPUDefFree(virCPUDefPtr def)
 {
 if (!def)
 return;
 
-virCPUDefFreeModel(def);
-VIR_FREE(def->cache);
-VIR_FREE(def->tsc);
-VIR_FREE(def);
+if (g_atomic_int_dec_and_test(>refs)) {
+virCPUDefFreeModel(def);
+VIR_FREE(def->cache);
+VIR_FREE(def->tsc);
+VIR_FREE(def);
+}
 }
 
 
@@ -214,9 +229,10 @@ virCPUDefCopyWithoutModel(const virCPUDef *cpu)
 {
 virCPUDefPtr copy;
 
-if (!cpu || VIR_ALLOC(copy) < 0)
+if (!cpu)
 return NULL;
 
+copy = virCPUDefNew();
 copy->type = cpu->type;
 copy->mode = cpu->mode;
 copy->match = cpu->match;
@@ -340,8 +356,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt,
 goto cleanup;
 }
 
-if (VIR_ALLOC(def) < 0)
-goto cleanup;
+def = virCPUDefNew();
 
 if (type == VIR_CPU_TYPE_AUTO) {
 if (virXPathBoolean("boolean(./arch)", ctxt)) {
diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h
index 96fda3e6b3..ec3d2379cf 100644
--- a/src/conf/cpu_conf.h
+++ b/src/conf/cpu_conf.h
@@ -122,6 +122,7 @@ struct _virCPUCacheDef {
 typedef struct _virCPUDef virCPUDef;
 typedef virCPUDef *virCPUDefPtr;
 struct _virCPUDef {
+int refs;
 int type;   /* enum virCPUType */
 int mode;   /* enum virCPUMode */
 int match;  /* enum virCPUMatch */
@@ -142,6 +143,7 @@ struct _virCPUDef {
 virHostCPUTscInfoPtr tsc;
 };
 
+virCPUDefPtr virCPUDefNew(void);
 
 void ATTRIBUTE_NONNULL(1)
 virCPUDefFreeFeatures(virCPUDefPtr def);
@@ -149,6 +151,8 @@ virCPUDefFreeFeatures(virCPUDefPtr def);
 void ATTRIBUTE_NONNULL(1)
 virCPUDefFreeModel(virCPUDefPtr def);
 
+void
+virCPUDefRef(virCPUDefPtr def);
 void
 virCPUDefFree(virCPUDefPtr def);
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virCPUDef, virCPUDefFree);
diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 40f725fd21..a2ae5b8c07 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -393,8 +393,7 @@ virCPUGetHost(virArch arch,
 if (!(driver = cpuGetSubDriver(arch)))
 return NULL;
 
-if (VIR_ALLOC(cpu) < 0)
-return NULL;
+cpu = virCPUDefNew();
 
 switch (type) {
 case VIR_CPU_TYPE_HOST:
diff --git a/src/cpu/cpu_arm.c b/src/cpu/cpu_arm.c
index 70dba6021c..ee5802198f 100644
--- a/src/cpu/cpu_arm.c
+++ b/src/cpu/cpu_arm.c
@@ -211,10 +211,7 @@ virCPUarmBaseline(virCPUDefPtr *cpus,
 {
 virCPUDefPtr cpu = NULL;
 
-if (VIR_ALLOC(cpu) < 0) {
-virCPUDefFree(cpu);
-return NULL;
-}
+cpu = virCPUDefNew();
 
 cpu->model = g_strdup(cpus[0]->model);
 
diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c
index 3236a9616e..818f1ec699 100644
--- a/src/cpu/cpu_ppc64.c
+++ b/src/cpu/cpu_ppc64.c
@@ -757,8 +757,7 @@ virCPUppc64Baseline(virCPUDefPtr *cpus,
 }
 }
 
-if (VIR_ALLOC(cpu) < 0)
-goto error;
+cpu = virCPUDefNew();
 
 cpu->model = g_strdup(model->name);
 
diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c
index c83cab0c53..1e913cc9fa 100644
--- a/src/cpu/cpu_x86.c
+++ b/src/cpu/cpu_x86.c
@@ -775,8 +775,7 @@ x86DataToCPU(const virCPUx86Data *data,
 virCPUx86Data modelData = VIR_CPU_X86_DATA_INIT;
 virCPUx86VendorPtr vendor;
 
-if (VIR_ALLOC(cpu) < 0)
-goto error;
+cpu = virCPUDefNew();
 
 cpu->model = g_strdup(model->name);
 
@@ -2807,8 +2806,7 @@ virCPUx86Baseline(virCPUDefPtr *cpus,
 if (!(base_model = x86ModelFromCPU(cpus[0], map, -1)))
 goto error;
 
-if (VIR_ALLOC(cpu) < 0)
-goto error;
+cpu = virCPUDefNew();
 
 cpu->type = VIR_CPU_TYPE_GUEST;
 cpu->match = 

[libvirt] [PATCH 11/30] conf: drop virCapsPtr param from assign addresses callback

2019-12-04 Thread Daniel P . Berrangé
The virCapsPtr param is not used by any of the virt drivers providing
this callback.

Signed-off-by: Daniel P. Berrangé 
---
 src/bhyve/bhyve_domain.c | 1 -
 src/conf/domain_conf.c   | 2 +-
 src/conf/domain_conf.h   | 1 -
 src/qemu/qemu_domain.c   | 1 -
 4 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c
index eebf5a7650..a321be54f4 100644
--- a/src/bhyve/bhyve_domain.c
+++ b/src/bhyve/bhyve_domain.c
@@ -167,7 +167,6 @@ bhyveDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 
 static int
 bhyveDomainDefAssignAddresses(virDomainDef *def,
-  virCapsPtr caps G_GNUC_UNUSED,
   unsigned int parseFlags G_GNUC_UNUSED,
   void *opaque G_GNUC_UNUSED,
   void *parseOpaque G_GNUC_UNUSED)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8acc91de74..8dd1ff1017 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5870,7 +5870,7 @@ virDomainDefPostParse(virDomainDefPtr def,
 goto cleanup;
 
 if (xmlopt->config.assignAddressesCallback) {
-ret = xmlopt->config.assignAddressesCallback(def, caps, parseFlags,
+ret = xmlopt->config.assignAddressesCallback(def, parseFlags,
  xmlopt->config.priv,
  data.parseOpaque);
 if (virDomainDefPostParseCheckFailure(def, parseFlags, ret) < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index af57e288e9..7e925f45d8 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2660,7 +2660,6 @@ typedef int 
(*virDomainDeviceDefPostParseCallback)(virDomainDeviceDefPtr dev,
  * @opaque is opaque data set by driver (usually pointer to driver
  * private data). */
 typedef int (*virDomainDefAssignAddressesCallback)(virDomainDef *def,
-   virCapsPtr caps,
unsigned int parseFlags,
void *opaque,
void *parseOpaque);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 0076349558..362d644475 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8116,7 +8116,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 
 static int
 qemuDomainDefAssignAddresses(virDomainDef *def,
- virCapsPtr caps G_GNUC_UNUSED,
  unsigned int parseFlags G_GNUC_UNUSED,
  void *opaque,
  void *parseOpaque)
-- 
2.23.0

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

[libvirt] [PATCH 22/30] conf: drop virCapsPtr param from domain obj list APIs

2019-12-04 Thread Daniel P . Berrangé
Signed-off-by: Daniel P. Berrangé 
---
 src/bhyve/bhyve_driver.c|  2 --
 src/conf/virdomainobjlist.c |  5 -
 src/conf/virdomainobjlist.h |  1 -
 src/libxl/libxl_driver.c|  3 ---
 src/lxc/lxc_driver.c| 14 --
 src/qemu/qemu_driver.c  |  8 +---
 6 files changed, 1 insertion(+), 32 deletions(-)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index eecd6532f7..a764b4d4ed 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1249,7 +1249,6 @@ bhyveStateInitialize(bool privileged,
 if (virDomainObjListLoadAllConfigs(bhyve_driver->domains,
BHYVE_STATE_DIR,
NULL, true,
-   bhyve_driver->caps,
bhyve_driver->xmlopt,
NULL, NULL) < 0)
 goto cleanup;
@@ -1257,7 +1256,6 @@ bhyveStateInitialize(bool privileged,
 if (virDomainObjListLoadAllConfigs(bhyve_driver->domains,
BHYVE_CONFIG_DIR,
BHYVE_AUTOSTART_DIR, false,
-   bhyve_driver->caps,
bhyve_driver->xmlopt,
NULL, NULL) < 0)
 goto cleanup;
diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index ae18a4544f..417025ae9f 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -483,7 +483,6 @@ virDomainObjListRename(virDomainObjListPtr doms,
 
 static virDomainObjPtr
 virDomainObjListLoadConfig(virDomainObjListPtr doms,
-   virCapsPtr caps G_GNUC_UNUSED,
virDomainXMLOptionPtr xmlopt,
const char *configDir,
const char *autostartDir,
@@ -536,7 +535,6 @@ static virDomainObjPtr
 virDomainObjListLoadStatus(virDomainObjListPtr doms,
const char *statusDir,
const char *name,
-   virCapsPtr caps G_GNUC_UNUSED,
virDomainXMLOptionPtr xmlopt,
virDomainLoadConfigNotify notify,
void *opaque)
@@ -586,7 +584,6 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
const char *configDir,
const char *autostartDir,
bool liveStatus,
-   virCapsPtr caps,
virDomainXMLOptionPtr xmlopt,
virDomainLoadConfigNotify notify,
void *opaque)
@@ -616,13 +613,11 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
 dom = virDomainObjListLoadStatus(doms,
  configDir,
  entry->d_name,
- caps,
  xmlopt,
  notify,
  opaque);
 else
 dom = virDomainObjListLoadConfig(doms,
- caps,
  xmlopt,
  configDir,
  autostartDir,
diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h
index da5ec8a57c..6150e13aa4 100644
--- a/src/conf/virdomainobjlist.h
+++ b/src/conf/virdomainobjlist.h
@@ -66,7 +66,6 @@ int virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
const char *configDir,
const char *autostartDir,
bool liveStatus,
-   virCapsPtr caps,
virDomainXMLOptionPtr xmlopt,
virDomainLoadConfigNotify notify,
void *opaque);
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index cdb1296aa3..568277c714 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -781,7 +781,6 @@ libxlStateInitialize(bool privileged,
cfg->stateDir,
cfg->autostartDir,
true,
-   cfg->caps,
libxl_driver->xmlopt,
NULL, NULL) < 0)
 goto error;
@@ -793,7 +792,6 @@ libxlStateInitialize(bool privileged,
cfg->configDir,
cfg->autostartDir,
 

[libvirt] [PATCH 19/30] conf: drop virCapsPtr param from domain parse APIs

2019-12-04 Thread Daniel P . Berrangé
Signed-off-by: Daniel P. Berrangé 
---
 src/bhyve/bhyve_driver.c | 17 +++-
 src/conf/checkpoint_conf.c   |  4 +--
 src/conf/domain_conf.c   | 29 +++-
 src/conf/domain_conf.h   |  6 -
 src/conf/snapshot_conf.c |  6 ++---
 src/conf/virdomainobjlist.c  |  8 +++---
 src/esx/esx_driver.c |  4 +--
 src/libxl/libxl_domain.c |  4 +--
 src/libxl/libxl_driver.c | 18 ++---
 src/libxl/libxl_migration.c  |  7 +++--
 src/lxc/lxc_controller.c |  2 +-
 src/lxc/lxc_driver.c | 10 +++
 src/openvz/openvz_driver.c   |  8 +++---
 src/phyp/phyp_driver.c   |  4 +--
 src/qemu/qemu_checkpoint.c   |  4 +--
 src/qemu/qemu_domain.c   |  7 +
 src/qemu/qemu_driver.c   | 46 
 src/qemu/qemu_migration.c| 21 +++
 src/qemu/qemu_migration_cookie.c |  8 +-
 src/security/virt-aa-helper.c|  2 +-
 src/test/test_driver.c   | 10 +++
 src/vbox/vbox_common.c   |  6 ++---
 src/vmware/vmware_driver.c   |  4 +--
 src/vz/vz_driver.c   |  4 +--
 tests/bhyvexml2argvtest.c|  2 +-
 tests/domainconftest.c   |  2 +-
 tests/libxlxml2domconfigtest.c   |  2 +-
 tests/qemuagenttest.c|  2 +-
 tests/qemuhotplugtest.c  |  3 +--
 tests/qemumemlocktest.c  |  2 +-
 tests/qemusecuritytest.c |  1 -
 tests/qemuxml2argvtest.c |  2 +-
 tests/qemuxml2xmltest.c  |  2 +-
 tests/securityselinuxlabeltest.c |  2 +-
 tests/testutils.c|  5 ++--
 tests/xlconfigtest.c |  4 +--
 tests/xmconfigtest.c |  2 +-
 tests/xml2vmxtest.c  |  2 +-
 38 files changed, 97 insertions(+), 175 deletions(-)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 8432044b60..0e627f2dc8 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -519,7 +519,7 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flag
 if (!caps)
 return NULL;
 
-if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt,
+if ((def = virDomainDefParseString(xml, privconn->xmlopt,
NULL, parse_flags)) == NULL)
 goto cleanup;
 
@@ -681,7 +681,6 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
 bhyveConnPtr privconn = conn->privateData;
 virDomainDefPtr def = NULL;
 virCommandPtr cmd = NULL, loadcmd = NULL;
-virCapsPtr caps = NULL;
 char *ret = NULL;
 
 virCheckFlags(0, NULL);
@@ -695,10 +694,7 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
 goto cleanup;
 }
 
-if (!(caps = bhyveDriverGetCapabilities(privconn)))
-goto cleanup;
-
-if (!(def = virDomainDefParseString(xmlData, caps, privconn->xmlopt,
+if (!(def = virDomainDefParseString(xmlData, privconn->xmlopt,
 NULL, VIR_DOMAIN_DEF_PARSE_INACTIVE)))
 goto cleanup;
 
@@ -741,7 +737,6 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
 virCommandFree(loadcmd);
 virCommandFree(cmd);
 virDomainDefFree(def);
-virObjectUnref(caps);
 return ret;
 }
 
@@ -898,7 +893,6 @@ bhyveDomainCreateXML(virConnectPtr conn,
 virDomainDefPtr def = NULL;
 virDomainObjPtr vm = NULL;
 virObjectEventPtr event = NULL;
-virCapsPtr caps = NULL;
 unsigned int start_flags = 0;
 unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
 
@@ -910,11 +904,7 @@ bhyveDomainCreateXML(virConnectPtr conn,
 if (flags & VIR_DOMAIN_START_AUTODESTROY)
 start_flags |= VIR_BHYVE_PROCESS_START_AUTODESTROY;
 
-caps = bhyveDriverGetCapabilities(privconn);
-if (!caps)
-return NULL;
-
-if ((def = virDomainDefParseString(xml, caps, privconn->xmlopt,
+if ((def = virDomainDefParseString(xml, privconn->xmlopt,
NULL, parse_flags)) == NULL)
 goto cleanup;
 
@@ -947,7 +937,6 @@ bhyveDomainCreateXML(virConnectPtr conn,
 dom = virGetDomain(conn, vm->def->name, vm->def->uuid, vm->def->id);
 
  cleanup:
-virObjectUnref(caps);
 virDomainDefFree(def);
 virDomainObjEndAPI();
 virObjectEventStateQueue(privconn->domainEventState, event);
diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c
index 37cc8e5e6c..581e382b6d 100644
--- a/src/conf/checkpoint_conf.c
+++ b/src/conf/checkpoint_conf.c
@@ -121,7 +121,7 @@ virDomainCheckpointDiskDefParseXML(xmlNodePtr node,
  */
 static virDomainCheckpointDefPtr
 virDomainCheckpointDefParse(xmlXPathContextPtr ctxt,
-virCapsPtr caps,
+virCapsPtr caps G_GNUC_UNUSED,
 virDomainXMLOptionPtr xmlopt,
 void *parseOpaque,
 unsigned int flags)
@@ -170,7 +170,7 @@ 

[libvirt] [PATCH 12/30] conf: drop virCapsPtr param from basic post parse callback

2019-12-04 Thread Daniel P . Berrangé
The QEMU impl of the callback can directly use the QEMU capabilities
cache to resolve the emulator binary name, allowing virCapsPtr to be
dropped.

Signed-off-by: Daniel P. Berrangé 
---
 src/conf/domain_conf.c   |  2 +-
 src/conf/domain_conf.h   |  1 -
 src/qemu/qemu_capabilities.c | 28 
 src/qemu/qemu_capabilities.h |  2 ++
 src/qemu/qemu_domain.c   | 11 +++
 tests/testutilsqemu.c| 16 
 6 files changed, 46 insertions(+), 14 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8dd1ff1017..7327752810 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5824,7 +5824,7 @@ virDomainDefPostParse(virDomainDefPtr def,
 
 /* call the basic post parse callback */
 if (xmlopt->config.domainPostParseBasicCallback) {
-ret = xmlopt->config.domainPostParseBasicCallback(def, caps,
+ret = xmlopt->config.domainPostParseBasicCallback(def,
   xmlopt->config.priv);
 
 if (virDomainDefPostParseCheckFailure(def, parseFlags, ret) < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 7e925f45d8..cdbd42351f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2627,7 +2627,6 @@ typedef enum {
  * parseOpaque is used. This callback is run prior to
  * virDomainDefPostParseCallback. */
 typedef int (*virDomainDefPostParseBasicCallback)(virDomainDefPtr def,
-  virCapsPtr caps,
   void *opaque);
 
 /* Called once after everything else has been parsed, for adjusting
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 7a62dfb1a2..bfe59a1eff 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -799,16 +799,12 @@ virQEMUCapsFindBinaryForArch(virArch hostarch,
 return ret;
 }
 
-static int
-virQEMUCapsInitGuest(virCapsPtr caps,
- virFileCachePtr cache,
- virArch hostarch,
- virArch guestarch)
+
+char *
+virQEMUCapsGetDefaultEmulator(virArch hostarch,
+  virArch guestarch)
 {
 char *binary = NULL;
-virQEMUCapsPtr qemuCaps = NULL;
-int ret = -1;
-
 /* Check for existence of base emulator, or alternate base
  * which can be used with magic cpu choice
  */
@@ -819,6 +815,22 @@ virQEMUCapsInitGuest(virCapsPtr caps,
 if (virQEMUCapsGuestIsNative(hostarch, guestarch) && !binary)
 binary = g_strdup("/usr/libexec/qemu-kvm");
 
+return binary;
+}
+
+
+static int
+virQEMUCapsInitGuest(virCapsPtr caps,
+ virFileCachePtr cache,
+ virArch hostarch,
+ virArch guestarch)
+{
+char *binary = NULL;
+virQEMUCapsPtr qemuCaps = NULL;
+int ret = -1;
+
+binary = virQEMUCapsGetDefaultEmulator(hostarch, guestarch);
+
 /* Ignore binary if extracting version info fails */
 if (binary) {
 if (!(qemuCaps = virQEMUCapsCacheLookup(cache, binary))) {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index a8a5c38d73..9b380574f5 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -627,6 +627,8 @@ const char *virQEMUCapsGetMachineDefaultCPU(virQEMUCapsPtr 
qemuCaps,
 void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
 virDomainVirtType virtType,
 const char *machineType);
+char * virQEMUCapsGetDefaultEmulator(virArch hostarch,
+ virArch guestarch);
 
 virFileCachePtr virQEMUCapsCacheNew(const char *libDir,
 const char *cacheDir,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 362d644475..3c06b8a104 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4677,13 +4677,16 @@ qemuDomainDefTsegPostParse(virDomainDefPtr def,
 
 static int
 qemuDomainDefPostParseBasic(virDomainDefPtr def,
-virCapsPtr caps,
 void *opaque G_GNUC_UNUSED)
 {
+virQEMUDriverPtr driver = opaque;
+
 /* check for emulator and create a default one if needed */
-if (!def->emulator &&
-!(def->emulator = virDomainDefGetDefaultEmulator(def, caps)))
-return 1;
+if (!def->emulator) {
+if (!(def->emulator = virQEMUCapsGetDefaultEmulator(
+  driver->hostarch, def->os.arch)))
+return 1;
+}
 
 return 0;
 }
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index c24b3098a5..38be2cfe42 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -93,6 +93,22 @@ static const char *const *kvm_machines[VIR_ARCH_LAST] = {
 [VIR_ARCH_S390X] = s390x_machines,
 };
 
+
+char *
+virFindFileInPath(const char *file)
+{
+if 

[libvirt] [PATCH 14/30] conf: drop virCapsPtr param from post parse callback

2019-12-04 Thread Daniel P . Berrangé
No impl of this callback requires the virCapsPtr anymore.

Signed-off-by: Daniel P. Berrangé 
---
 src/bhyve/bhyve_domain.c   | 1 -
 src/conf/domain_conf.c | 2 +-
 src/conf/domain_conf.h | 1 -
 src/libxl/libxl_domain.c   | 1 -
 src/lxc/lxc_domain.c   | 1 -
 src/openvz/openvz_conf.c   | 1 -
 src/phyp/phyp_driver.c | 1 -
 src/qemu/qemu_domain.c | 1 -
 src/vmware/vmware_driver.c | 1 -
 src/vmx/vmx.c  | 1 -
 src/vz/vz_driver.c | 1 -
 11 files changed, 1 insertion(+), 11 deletions(-)

diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c
index a321be54f4..c8d33b4e00 100644
--- a/src/bhyve/bhyve_domain.c
+++ b/src/bhyve/bhyve_domain.c
@@ -75,7 +75,6 @@ bhyveDomainDefNeedsISAController(virDomainDefPtr def)
 
 static int
 bhyveDomainDefPostParse(virDomainDefPtr def,
-virCapsPtr _caps G_GNUC_UNUSED,
 unsigned int parseFlags G_GNUC_UNUSED,
 void *opaque,
 void *parseOpaque G_GNUC_UNUSED)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 164c313ac6..f2452f6df2 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5849,7 +5849,7 @@ virDomainDefPostParse(virDomainDefPtr def,
 
 /* call the domain config callback */
 if (xmlopt->config.domainPostParseCallback) {
-ret = xmlopt->config.domainPostParseCallback(def, caps, parseFlags,
+ret = xmlopt->config.domainPostParseCallback(def, parseFlags,
  xmlopt->config.priv,
  data.parseOpaque);
 if (virDomainDefPostParseCheckFailure(def, parseFlags, ret) < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 86d0b47a66..7a5bfd00ed 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2638,7 +2638,6 @@ typedef int 
(*virDomainDefPostParseBasicCallback)(virDomainDefPtr def,
  * value and the failure is noted in def->postParseFailed. Drivers should then
  * re-run the post parse callback when attempting to use such definition. */
 typedef int (*virDomainDefPostParseCallback)(virDomainDefPtr def,
- virCapsPtr caps,
  unsigned int parseFlags,
  void *opaque,
  void *parseOpaque);
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index dfac04bf59..2524d17eb4 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -367,7 +367,6 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 
 static int
 libxlDomainDefPostParse(virDomainDefPtr def,
-virCapsPtr caps G_GNUC_UNUSED,
 unsigned int parseFlags G_GNUC_UNUSED,
 void *opaque,
 void *parseOpaque G_GNUC_UNUSED)
diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c
index bc54beeadf..8b27bc95af 100644
--- a/src/lxc/lxc_domain.c
+++ b/src/lxc/lxc_domain.c
@@ -351,7 +351,6 @@ virDomainXMLPrivateDataCallbacks 
virLXCDriverPrivateDataCallbacks = {
 
 static int
 virLXCDomainDefPostParse(virDomainDefPtr def,
- virCapsPtr _caps G_GNUC_UNUSED,
  unsigned int parseFlags G_GNUC_UNUSED,
  void *opaque,
  void *parseOpaque G_GNUC_UNUSED)
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 5060e704a5..5057f9652e 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -1082,7 +1082,6 @@ int openvzGetVEID(const char *name)
 
 static int
 openvzDomainDefPostParse(virDomainDefPtr def,
- virCapsPtr caps G_GNUC_UNUSED,
  unsigned int parseFlags G_GNUC_UNUSED,
  void *opaque,
  void *parseOpaque G_GNUC_UNUSED)
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 05860b7dbe..3c809378c3 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1062,7 +1062,6 @@ openSSHSession(virConnectPtr conn, virConnectAuthPtr auth,
 
 static int
 phypDomainDefPostParse(virDomainDefPtr def,
-   virCapsPtr caps G_GNUC_UNUSED,
unsigned int parseFlags G_GNUC_UNUSED,
void *opaque,
void *parseOpaque G_GNUC_UNUSED)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 70683eb83a..6aa50dda0b 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4694,7 +4694,6 @@ qemuDomainDefPostParseBasic(virDomainDefPtr def,
 
 static int
 qemuDomainDefPostParse(virDomainDefPtr def,
-   virCapsPtr caps G_GNUC_UNUSED,
unsigned int parseFlags,
void *opaque,
void *parseOpaque G_GNUC_UNUSED)
diff 

[libvirt] [PATCH 08/30] conf: pass netprefix in the domain parser config struct

2019-12-04 Thread Daniel P . Berrangé
Instead of using the virCapsPtr information, pass the driver specific
netprefix in the domain parser struct. This eliminates one more use of
virCapsPtr from the XML parsing/formatting code.

Signed-off-by: Daniel P. Berrangé 
---
 src/conf/domain_conf.c   | 24 +++-
 src/conf/domain_conf.h   |  3 ++-
 src/libxl/libxl_domain.c |  1 +
 3 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 6abe15f721..b45ca4a4d0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -11446,7 +11446,6 @@ static virDomainNetDefPtr
 virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 xmlNodePtr node,
 xmlXPathContextPtr ctxt,
-char *prefix,
 unsigned int flags)
 {
 virDomainNetDefPtr def;
@@ -11494,6 +11493,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 g_autofree char *vhostuser_type = NULL;
 g_autofree char *trustGuestRxFilters = NULL;
 g_autofree char *vhost_path = NULL;
+const char *prefix = xmlopt ? xmlopt->config.netPrefix : NULL;
 
 if (!(def = virDomainNetDefNew(xmlopt)))
 return NULL;
@@ -16385,7 +16385,6 @@ virDomainDeviceDefParse(const char *xmlStr,
 xmlNodePtr node;
 g_autoptr(xmlXPathContext) ctxt = NULL;
 g_autofree virDomainDeviceDefPtr dev = NULL;
-char *netprefix;
 
 if (!(xml = virXMLParseStringCtxt(xmlStr, _("(device_definition)"), 
)))
 return NULL;
@@ -16428,9 +16427,7 @@ virDomainDeviceDefParse(const char *xmlStr,
 return NULL;
 break;
 case VIR_DOMAIN_DEVICE_NET:
-netprefix = caps->host.netprefix;
-if (!(dev->data.net = virDomainNetDefParseXML(xmlopt, node, ctxt,
-  netprefix, flags)))
+if (!(dev->data.net = virDomainNetDefParseXML(xmlopt, node, ctxt, 
flags)))
 return NULL;
 break;
 case VIR_DOMAIN_DEVICE_INPUT:
@@ -19759,7 +19756,6 @@ virDomainDefParseXML(xmlDocPtr xml,
 bool usb_none = false;
 bool usb_other = false;
 bool usb_master = false;
-char *netprefix = NULL;
 g_autofree xmlNodePtr *nodes = NULL;
 g_autofree char *tmp = NULL;
 
@@ -20872,12 +20868,10 @@ virDomainDefParseXML(xmlDocPtr xml,
 goto error;
 if (n && VIR_ALLOC_N(def->nets, n) < 0)
 goto error;
-netprefix = caps->host.netprefix;
 for (i = 0; i < n; i++) {
 virDomainNetDefPtr net = virDomainNetDefParseXML(xmlopt,
  nodes[i],
  ctxt,
- netprefix,
  flags);
 if (!net)
 goto error;
@@ -25362,7 +25356,7 @@ virDomainChrSourceReconnectDefFormat(virBufferPtr buf,
 int
 virDomainNetDefFormat(virBufferPtr buf,
   virDomainNetDefPtr def,
-  char *prefix,
+  virDomainXMLOptionPtr xmlopt,
   unsigned int flags)
 {
 virDomainNetType actualType = virDomainNetGetActualType(def);
@@ -25372,6 +25366,7 @@ virDomainNetDefFormat(virBufferPtr buf,
 virDomainHostdevDefPtr hostdef = NULL;
 char macstr[VIR_MAC_STRING_BUFLEN];
 g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+const char *prefix = xmlopt ? xmlopt->config.netPrefix : NULL;
 
 /* publicActual is true if we should report the current state in
  * def->data.network.actual *instead of* the config (*not* in
@@ -28294,7 +28289,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
 int
 virDomainDefFormatInternalSetRootName(virDomainDefPtr def,
   virDomainXMLOptionPtr xmlopt,
-  virCapsPtr caps,
+  virCapsPtr caps G_GNUC_UNUSED,
   virBufferPtr buf,
   const char *rootname,
   unsigned int flags)
@@ -28304,7 +28299,6 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr 
def,
 const char *type = NULL;
 int n;
 size_t i;
-char *netprefix = NULL;
 
 virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS |
   VIR_DOMAIN_DEF_FORMAT_STATUS |
@@ -28660,10 +28654,8 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr 
def,
 if (virDomainFSDefFormat(buf, def->fss[n], flags) < 0)
 goto error;
 
-if (caps)
-netprefix = caps->host.netprefix;
 for (n = 0; n < def->nnets; n++)
-if (virDomainNetDefFormat(buf, def->nets[n], netprefix, flags) < 0)
+if (virDomainNetDefFormat(buf, def->nets[n], xmlopt, flags) < 0)
 goto error;
 
 for (n = 0; n < def->nsmartcards; n++)
@@ -29834,7 +29826,6 @@ 

[libvirt] [PATCH 15/30] conf: drop virCapsPtr param from device post parse callback

2019-12-04 Thread Daniel P . Berrangé
None of the impls of this callback require the virCapsPtr param.

Signed-off-by: Daniel P. Berrangé 
---
 src/bhyve/bhyve_domain.c   |  1 -
 src/conf/domain_conf.c | 20 +++-
 src/conf/domain_conf.h |  1 -
 src/libxl/libxl_domain.c   |  1 -
 src/lxc/lxc_domain.c   |  1 -
 src/openvz/openvz_conf.c   |  1 -
 src/phyp/phyp_driver.c |  1 -
 src/qemu/qemu_domain.c |  1 -
 src/vmware/vmware_driver.c |  1 -
 src/vmx/vmx.c  |  1 -
 src/vz/vz_driver.c |  1 -
 11 files changed, 7 insertions(+), 23 deletions(-)

diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c
index c8d33b4e00..82910ea261 100644
--- a/src/bhyve/bhyve_domain.c
+++ b/src/bhyve/bhyve_domain.c
@@ -132,7 +132,6 @@ bhyveDomainDiskDefAssignAddress(bhyveConnPtr driver,
 static int
 bhyveDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
   const virDomainDef *def,
-  virCapsPtr caps G_GNUC_UNUSED,
   unsigned int parseFlags G_GNUC_UNUSED,
   void *opaque,
   void *parseOpaque G_GNUC_UNUSED)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f2452f6df2..ef6c8d3f75 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5207,7 +5207,6 @@ virDomainVsockDefPostParse(virDomainVsockDefPtr vsock)
 static int
 virDomainDeviceDefPostParseCommon(virDomainDeviceDefPtr dev,
   const virDomainDef *def,
-  virCapsPtr caps G_GNUC_UNUSED,
   unsigned int parseFlags G_GNUC_UNUSED,
   virDomainXMLOptionPtr xmlopt)
 {
@@ -5462,7 +5461,6 @@ 
virDomainDeviceDefPostParseCheckFeatures(virDomainDeviceDefPtr dev,
 static int
 virDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 const virDomainDef *def,
-virCapsPtr caps,
 unsigned int flags,
 virDomainXMLOptionPtr xmlopt,
 void *parseOpaque)
@@ -5470,14 +5468,14 @@ virDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 int ret;
 
 if (xmlopt->config.devicesPostParseCallback) {
-ret = xmlopt->config.devicesPostParseCallback(dev, def, caps, flags,
+ret = xmlopt->config.devicesPostParseCallback(dev, def, flags,
   xmlopt->config.priv,
   parseOpaque);
 if (ret < 0)
 return ret;
 }
 
-if ((ret = virDomainDeviceDefPostParseCommon(dev, def, caps, flags, 
xmlopt)) < 0)
+if ((ret = virDomainDeviceDefPostParseCommon(dev, def, flags, xmlopt)) < 0)
 return ret;
 
 if (virDomainDeviceDefPostParseCheckFeatures(dev, xmlopt) < 0)
@@ -5489,7 +5487,6 @@ virDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 static int
 virDomainDeviceDefPostParseOne(virDomainDeviceDefPtr dev,
const virDomainDef *def,
-   virCapsPtr caps,
unsigned int flags,
virDomainXMLOptionPtr xmlopt,
void *parseOpaque)
@@ -5505,7 +5502,7 @@ virDomainDeviceDefPostParseOne(virDomainDeviceDefPtr dev,
 parseOpaque = data;
 }
 
-ret = virDomainDeviceDefPostParse(dev, def, caps, flags, xmlopt, 
parseOpaque);
+ret = virDomainDeviceDefPostParse(dev, def, flags, xmlopt, parseOpaque);
 
 if (data && xmlopt->config.domainPostParseDataFree)
 xmlopt->config.domainPostParseDataFree(data);
@@ -5515,7 +5512,6 @@ virDomainDeviceDefPostParseOne(virDomainDeviceDefPtr dev,
 
 
 struct virDomainDefPostParseDeviceIteratorData {
-virCapsPtr caps;
 virDomainXMLOptionPtr xmlopt;
 void *parseOpaque;
 unsigned int parseFlags;
@@ -5529,7 +5525,7 @@ virDomainDefPostParseDeviceIterator(virDomainDefPtr def,
 void *opaque)
 {
 struct virDomainDefPostParseDeviceIteratorData *data = opaque;
-return virDomainDeviceDefPostParse(dev, def, data->caps,
+return virDomainDeviceDefPostParse(dev, def,
data->parseFlags, data->xmlopt,
data->parseOpaque);
 }
@@ -5806,7 +5802,7 @@ virDomainDefPostParseCheckFailure(virDomainDefPtr def,
 
 int
 virDomainDefPostParse(virDomainDefPtr def,
-  virCapsPtr caps,
+  virCapsPtr caps G_GNUC_UNUSED,
   unsigned int parseFlags,
   virDomainXMLOptionPtr xmlopt,
   void *parseOpaque)
@@ -5814,7 +5810,6 @@ virDomainDefPostParse(virDomainDefPtr def,
 int ret = -1;
 bool localParseOpaque = false;
 struct virDomainDefPostParseDeviceIteratorData data = {
-.caps = caps,
 

[libvirt] [PATCH 21/30] conf: drop virCapsPtr param from APIs for saving domains

2019-12-04 Thread Daniel P . Berrangé
Signed-off-by: Daniel P. Berrangé 
---
 src/bhyve/bhyve_driver.c|   9 +--
 src/bhyve/bhyve_process.c   |  16 +-
 src/conf/domain_conf.c  |   7 +--
 src/conf/domain_conf.h  |   3 -
 src/libxl/libxl_domain.c|   2 +-
 src/libxl/libxl_driver.c|  34 +--
 src/libxl/libxl_migration.c |   6 +-
 src/lxc/lxc_driver.c|  39 ++---
 src/lxc/lxc_process.c   |   6 +-
 src/qemu/qemu_domain.c  |   6 +-
 src/qemu/qemu_driver.c  | 110 +---
 src/qemu/qemu_hotplug.c |   8 +--
 src/qemu/qemu_migration.c   |   8 +--
 src/qemu/qemu_process.c |  36 ++--
 src/test/test_driver.c  |   2 +-
 15 files changed, 128 insertions(+), 164 deletions(-)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 0e627f2dc8..eecd6532f7 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -540,7 +540,7 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flag
 vm->persistent = 1;
 
 if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def,
- privconn->xmlopt, caps, BHYVE_CONFIG_DIR) < 0) {
+ privconn->xmlopt, BHYVE_CONFIG_DIR) < 0) {
 virDomainObjListRemove(privconn->domains, vm);
 goto cleanup;
 }
@@ -1063,7 +1063,6 @@ bhyveDomainSetMetadata(virDomainPtr dom,
 {
 bhyveConnPtr privconn = dom->conn->privateData;
 virDomainObjPtr vm;
-virCapsPtr caps = NULL;
 int ret = -1;
 
 virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
@@ -1075,10 +1074,7 @@ bhyveDomainSetMetadata(virDomainPtr dom,
 if (virDomainSetMetadataEnsureACL(dom->conn, vm->def, flags) < 0)
 goto cleanup;
 
-if (!(caps = bhyveDriverGetCapabilities(privconn)))
-goto cleanup;
-
-ret = virDomainObjSetMetadata(vm, type, metadata, key, uri, caps,
+ret = virDomainObjSetMetadata(vm, type, metadata, key, uri,
   privconn->xmlopt, BHYVE_STATE_DIR,
   BHYVE_CONFIG_DIR, flags);
 
@@ -1090,7 +1086,6 @@ bhyveDomainSetMetadata(virDomainPtr dom,
 
 
  cleanup:
-virObjectUnref(caps);
 virDomainObjEndAPI();
 return ret;
 }
diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c
index c10e5500c9..519604f898 100644
--- a/src/bhyve/bhyve_process.c
+++ b/src/bhyve/bhyve_process.c
@@ -110,14 +110,9 @@ virBhyveProcessStart(virConnectPtr conn,
 bhyveConnPtr privconn = conn->privateData;
 bhyveDomainObjPrivatePtr priv = vm->privateData;
 int ret = -1, rc;
-virCapsPtr caps = NULL;
 
 logfile = g_strdup_printf("%s/%s.log", BHYVE_LOG_DIR, vm->def->name);
 
-caps = bhyveDriverGetCapabilities(privconn);
-if (!caps)
-goto cleanup;
-
 if ((logfd = open(logfile, O_WRONLY | O_APPEND | O_CREAT,
   S_IRUSR | S_IWUSR)) < 0) {
 virReportSystemError(errno,
@@ -211,14 +206,13 @@ virBhyveProcessStart(virConnectPtr conn,
 virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
 priv->mon = bhyveMonitorOpen(vm, driver);
 
-if (virDomainObjSave(vm, driver->xmlopt, caps,
+if (virDomainObjSave(vm, driver->xmlopt,
  BHYVE_STATE_DIR) < 0)
 goto cleanup;
 
 ret = 0;
 
  cleanup:
-virObjectUnref(caps);
 if (devicemap != NULL) {
 rc = unlink(devmap_file);
 if (rc < 0 && errno != ENOENT)
@@ -384,7 +378,6 @@ virBhyveProcessReconnect(virDomainObjPtr vm,
 char *expected_proctitle = NULL;
 bhyveDomainObjPrivatePtr priv = vm->privateData;
 int ret = -1;
-virCapsPtr caps = NULL;
 
 if (!virDomainObjIsActive(vm))
 return 0;
@@ -392,10 +385,6 @@ virBhyveProcessReconnect(virDomainObjPtr vm,
 if (!vm->pid)
 return 0;
 
-caps = bhyveDriverGetCapabilities(data->driver);
-if (!caps)
-return -1;
-
 virObjectLock(vm);
 
 kp = kvm_getprocs(data->kd, KERN_PROC_PID, vm->pid, );
@@ -429,11 +418,10 @@ virBhyveProcessReconnect(virDomainObjPtr vm,
 vm->def->id = -1;
 virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
  VIR_DOMAIN_SHUTOFF_UNKNOWN);
-ignore_value(virDomainObjSave(vm, data->driver->xmlopt, caps,
+ignore_value(virDomainObjSave(vm, data->driver->xmlopt,
   BHYVE_STATE_DIR));
 }
 
-virObjectUnref(caps);
 virObjectUnlock(vm);
 VIR_FREE(expected_proctitle);
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 011e104220..64084d37d5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -28987,7 +28987,6 @@ virDomainDefSaveXML(virDomainDefPtr def,
 int
 virDomainDefSave(virDomainDefPtr def,
  virDomainXMLOptionPtr xmlopt,
- virCapsPtr caps G_GNUC_UNUSED,
  const char *configDir)
 {
 g_autofree char *xml = NULL;
@@ -29001,7 +29000,6 @@ virDomainDefSave(virDomainDefPtr def,
 int
 

[libvirt] [PATCH 16/30] conf: drop virCapsPtr param from domain validate callback

2019-12-04 Thread Daniel P . Berrangé
None of the impls of this callback require the virCapsPtr param.

Signed-off-by: Daniel P. Berrangé 
---
 src/conf/domain_conf.c | 4 ++--
 src/conf/domain_conf.h | 1 -
 src/qemu/qemu_domain.c | 1 -
 src/vz/vz_driver.c | 1 -
 4 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ef6c8d3f75..7431aad0cf 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7107,7 +7107,7 @@ virDomainDefValidateInternal(const virDomainDef *def,
  */
 int
 virDomainDefValidate(virDomainDefPtr def,
- virCapsPtr caps,
+ virCapsPtr caps G_GNUC_UNUSED,
  unsigned int parseFlags,
  virDomainXMLOptionPtr xmlopt)
 {
@@ -7122,7 +7122,7 @@ virDomainDefValidate(virDomainDefPtr def,
 
 /* call the domain config callback */
 if (xmlopt->config.domainValidateCallback &&
-xmlopt->config.domainValidateCallback(def, caps, xmlopt->config.priv) 
< 0)
+xmlopt->config.domainValidateCallback(def, xmlopt->config.priv) < 0)
 return -1;
 
 /* iterate the devices */
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 9864296be1..bbe73f1182 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2671,7 +2671,6 @@ typedef void (*virDomainDefPostParseDataFree)(void 
*parseOpaque);
  * for configurations that were previously accepted. This shall not modify the
  * config. */
 typedef int (*virDomainDefValidateCallback)(const virDomainDef *def,
-virCapsPtr caps,
 void *opaque);
 
 /* Called once per device, for adjusting per-device settings while
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 8ac6a0f842..49b6008d5c 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4972,7 +4972,6 @@ qemuDomainValidateCpuCount(const virDomainDef *def,
 
 static int
 qemuDomainDefValidate(const virDomainDef *def,
-  virCapsPtr caps G_GNUC_UNUSED,
   void *opaque)
 {
 virQEMUDriverPtr driver = opaque;
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 78aa85825a..35baab1b82 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -259,7 +259,6 @@ vzDomainDefPostParse(virDomainDefPtr def,
 
 static int
 vzDomainDefValidate(const virDomainDef *def,
-virCapsPtr caps G_GNUC_UNUSED,
 void *opaque)
 {
 if (vzCheckUnsupportedControllers(def, opaque) < 0)
-- 
2.23.0

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

[libvirt] [PATCH 09/30] conf: move seclabel validation into post-parse phase

2019-12-04 Thread Daniel P . Berrangé
Currently the disk and chardev seclabels are validated immediately at
the time their data is parsed. This forces the parser to fill in the
top level secmodel at time of parsing which is an undesirable thing.
This validation conceptually should be done in the post-parse phase
instead.

Signed-off-by: Daniel P. Berrangé 
---
 src/conf/domain_conf.c | 196 ++---
 src/conf/domain_conf.h |   1 -
 src/qemu/qemu_driver.c |   2 +-
 tests/qemublocktest.c  |   2 +-
 4 files changed, 90 insertions(+), 111 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b45ca4a4d0..f037702ac2 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5936,8 +5936,42 @@ 
virDomainDiskAddressDiskBusCompatibility(virDomainDiskBus bus,
 
 
 static int
-virDomainDiskDefValidate(const virDomainDiskDef *disk)
+virSecurityDeviceLabelDefValidateXML(virSecurityDeviceLabelDefPtr *seclabels,
+ size_t nseclabels,
+ virSecurityLabelDefPtr *vmSeclabels,
+ size_t nvmSeclabels)
+{
+virSecurityDeviceLabelDefPtr seclabel;
+size_t i;
+size_t j;
+
+for (i = 0; i < nseclabels; i++) {
+seclabel = seclabels[i];
+
+/* find the security label that it's being overridden */
+for (j = 0; j < nvmSeclabels; j++) {
+if (STRNEQ_NULLABLE(vmSeclabels[j]->model, seclabel->model))
+continue;
+
+if (!vmSeclabels[j]->relabel) {
+virReportError(VIR_ERR_XML_ERROR, "%s",
+   _("label overrides require relabeling to be "
+ "enabled at the domain level"));
+return -1;
+}
+}
+}
+
+return 0;
+}
+
+
+static int
+virDomainDiskDefValidate(const virDomainDef *def,
+ const virDomainDiskDef *disk)
 {
+virStorageSourcePtr next;
+
 /* Validate LUN configuration */
 if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
 /* volumes haven't been translated at this point, so accept them */
@@ -5991,6 +6025,14 @@ virDomainDiskDefValidate(const virDomainDiskDef *disk)
 return -1;
 }
 
+for (next = disk->src; next; next = next->backingStore) {
+if (virSecurityDeviceLabelDefValidateXML(next->seclabels,
+ next->nseclabels,
+ def->seclabels,
+ def->nseclabels) < 0)
+return -1;
+}
+
 return 0;
 }
 
@@ -6014,10 +6056,11 @@ virDomainDefHasUSB(const virDomainDef *def)
 
 
 static int
-virDomainChrSourceDefValidate(const virDomainChrSourceDef *def,
-  const virDomainChrDef *chr_def)
+virDomainChrSourceDefValidate(const virDomainChrSourceDef *src_def,
+  const virDomainChrDef *chr_def,
+  const virDomainDef *def)
 {
-switch ((virDomainChrType) def->type) {
+switch ((virDomainChrType) src_def->type) {
 case VIR_DOMAIN_CHR_TYPE_NULL:
 case VIR_DOMAIN_CHR_TYPE_PTY:
 case VIR_DOMAIN_CHR_TYPE_VC:
@@ -6029,7 +6072,7 @@ virDomainChrSourceDefValidate(const virDomainChrSourceDef 
*def,
 case VIR_DOMAIN_CHR_TYPE_FILE:
 case VIR_DOMAIN_CHR_TYPE_DEV:
 case VIR_DOMAIN_CHR_TYPE_PIPE:
-if (!def->data.file.path) {
+if (!src_def->data.file.path) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing source path attribute for char device"));
 return -1;
@@ -6037,13 +6080,13 @@ virDomainChrSourceDefValidate(const 
virDomainChrSourceDef *def,
 break;
 
 case VIR_DOMAIN_CHR_TYPE_NMDM:
-if (!def->data.nmdm.master) {
+if (!src_def->data.nmdm.master) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing master path attribute for nmdm device"));
 return -1;
 }
 
-if (!def->data.nmdm.slave) {
+if (!src_def->data.nmdm.slave) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing slave path attribute for nmdm device"));
 return -1;
@@ -6051,19 +6094,19 @@ virDomainChrSourceDefValidate(const 
virDomainChrSourceDef *def,
 break;
 
 case VIR_DOMAIN_CHR_TYPE_TCP:
-if (!def->data.tcp.host) {
+if (!src_def->data.tcp.host) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing source host attribute for char device"));
 return -1;
 }
 
-if (!def->data.tcp.service) {
+if (!src_def->data.tcp.service) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing source service attribute for char 
device"));
 return -1;
 }
 
-  

[libvirt] [PATCH 20/30] conf: drop virCapsPtr param from domain APIs for copying config

2019-12-04 Thread Daniel P . Berrangé
Signed-off-by: Daniel P. Berrangé 
---
 src/conf/domain_conf.c  | 17 ++---
 src/conf/domain_conf.h  |  9 ++---
 src/libxl/libxl_domain.c|  6 +++---
 src/libxl/libxl_driver.c| 15 ++-
 src/libxl/libxl_migration.c |  3 +--
 src/lxc/lxc_driver.c| 22 ++
 src/lxc/lxc_process.c   |  2 +-
 src/qemu/qemu_domain.c  |  7 +--
 src/qemu/qemu_driver.c  | 26 +++---
 src/qemu/qemu_migration.c   |  2 +-
 src/qemu/qemu_process.c |  2 +-
 src/test/test_driver.c  |  7 ++-
 tests/qemuhotplugtest.c |  2 +-
 13 files changed, 42 insertions(+), 78 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 00b5da8d52..011e104220 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3670,8 +3670,7 @@ virDomainObjWaitUntil(virDomainObjPtr vm,
  * @return 0 on success, -1 on failure
  */
 int
-virDomainObjSetDefTransient(virCapsPtr caps,
-virDomainXMLOptionPtr xmlopt,
+virDomainObjSetDefTransient(virDomainXMLOptionPtr xmlopt,
 virDomainObjPtr domain,
 void *parseOpaque)
 {
@@ -3683,7 +3682,7 @@ virDomainObjSetDefTransient(virCapsPtr caps,
 if (domain->newDef)
 return 0;
 
-if (!(domain->newDef = virDomainDefCopy(domain->def, caps, xmlopt,
+if (!(domain->newDef = virDomainDefCopy(domain->def, xmlopt,
 parseOpaque, false)))
 goto out;
 
@@ -3721,13 +3720,12 @@ virDomainObjRemoveTransientDef(virDomainObjPtr domain)
  * @return NULL on error, virDOmainDefPtr on success
  */
 virDomainDefPtr
-virDomainObjGetPersistentDef(virCapsPtr caps,
- virDomainXMLOptionPtr xmlopt,
+virDomainObjGetPersistentDef(virDomainXMLOptionPtr xmlopt,
  virDomainObjPtr domain,
  void *parseOpaque)
 {
 if (virDomainObjIsActive(domain) &&
-virDomainObjSetDefTransient(caps, xmlopt, domain, parseOpaque) < 0)
+virDomainObjSetDefTransient(xmlopt, domain, parseOpaque) < 0)
 return NULL;
 
 if (domain->newDef)
@@ -29304,7 +29302,6 @@ virDomainUSBDeviceDefForeach(virDomainDefPtr def,
  * snapshots).  */
 virDomainDefPtr
 virDomainDefCopy(virDomainDefPtr src,
- virCapsPtr caps G_GNUC_UNUSED,
  virDomainXMLOptionPtr xmlopt,
  void *parseOpaque,
  bool migratable)
@@ -29326,14 +29323,13 @@ virDomainDefCopy(virDomainDefPtr src,
 
 virDomainDefPtr
 virDomainObjCopyPersistentDef(virDomainObjPtr dom,
-  virCapsPtr caps,
   virDomainXMLOptionPtr xmlopt,
   void *parseOpaque)
 {
 virDomainDefPtr cur;
 
-cur = virDomainObjGetPersistentDef(caps, xmlopt, dom, parseOpaque);
-return virDomainDefCopy(cur, caps, xmlopt, parseOpaque, false);
+cur = virDomainObjGetPersistentDef(xmlopt, dom, parseOpaque);
+return virDomainDefCopy(cur, xmlopt, parseOpaque, false);
 }
 
 
@@ -29778,7 +29774,6 @@ virDomainNetFindByName(virDomainDefPtr def,
 virDomainDeviceDefPtr
 virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
const virDomainDef *def,
-   virCapsPtr caps G_GNUC_UNUSED,
virDomainXMLOptionPtr xmlopt,
void *parseOpaque)
 {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 5255c8190e..1aac01a386 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2895,7 +2895,6 @@ void virDomainShmemDefFree(virDomainShmemDefPtr def);
 void virDomainDeviceDefFree(virDomainDeviceDefPtr def);
 virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
  const virDomainDef *def,
- virCapsPtr caps,
  virDomainXMLOptionPtr xmlopt,
  void *parseOpaque);
 virDomainDeviceInfoPtr virDomainDeviceGetInfo(virDomainDeviceDefPtr device);
@@ -2936,14 +2935,12 @@ void virDomainObjAssignDef(virDomainObjPtr domain,
virDomainDefPtr def,
bool live,
virDomainDefPtr *oldDef);
-int virDomainObjSetDefTransient(virCapsPtr caps,
-virDomainXMLOptionPtr xmlopt,
+int virDomainObjSetDefTransient(virDomainXMLOptionPtr xmlopt,
 virDomainObjPtr domain,
 void *parseOpaque);
 void virDomainObjRemoveTransientDef(virDomainObjPtr domain);
 virDomainDefPtr
-virDomainObjGetPersistentDef(virCapsPtr caps,
- virDomainXMLOptionPtr xmlopt,
+virDomainObjGetPersistentDef(virDomainXMLOptionPtr xmlopt,
  virDomainObjPtr domain,
  

[libvirt] [PATCH 03/30] conf: sanitize virDomainSaveStatus & virDomainSaveConfig APIs

2019-12-04 Thread Daniel P . Berrangé
Our normal practice is for the object type to be the name prefix, and
the object instance be the first parameter passed in.

Rename these to virDomainObjSave and virDomainDefSave moving their
primary parameter to be the first one. Ensure that the xml options
are passed into both functions in prep for future work.

Finally enforce checking of the return type and mark all parameters
as non-NULL.

Signed-off-by: Daniel P. Berrangé 
---
 src/bhyve/bhyve_driver.c|   4 +-
 src/bhyve/bhyve_process.c   |  10 ++-
 src/conf/domain_conf.c  |  31 +-
 src/conf/domain_conf.h  |  26 
 src/libvirt_private.syms|   5 +-
 src/libxl/libxl_domain.c|   2 +-
 src/libxl/libxl_driver.c|  35 ++-
 src/libxl/libxl_migration.c |   6 +-
 src/lxc/lxc_driver.c|  39 ++--
 src/lxc/lxc_process.c   |   6 +-
 src/qemu/qemu_domain.c  |   6 +-
 src/qemu/qemu_driver.c  | 119 ++--
 src/qemu/qemu_hotplug.c |   8 +--
 src/qemu/qemu_migration.c   |   8 +--
 src/qemu/qemu_process.c |  36 +--
 15 files changed, 171 insertions(+), 170 deletions(-)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index d40ae1cd23..b8a206bb1e 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -545,8 +545,8 @@ bhyveDomainDefineXMLFlags(virConnectPtr conn, const char 
*xml, unsigned int flag
 def = NULL;
 vm->persistent = 1;
 
-if (virDomainSaveConfig(BHYVE_CONFIG_DIR, caps,
-vm->newDef ? vm->newDef : vm->def) < 0) {
+if (virDomainDefSave(vm->newDef ? vm->newDef : vm->def,
+ privconn->xmlopt, caps, BHYVE_CONFIG_DIR) < 0) {
 virDomainObjListRemove(privconn->domains, vm);
 goto cleanup;
 }
diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c
index 13123fdce3..c10e5500c9 100644
--- a/src/bhyve/bhyve_process.c
+++ b/src/bhyve/bhyve_process.c
@@ -211,9 +211,8 @@ virBhyveProcessStart(virConnectPtr conn,
 virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, reason);
 priv->mon = bhyveMonitorOpen(vm, driver);
 
-if (virDomainSaveStatus(driver->xmlopt,
-BHYVE_STATE_DIR,
-vm, caps) < 0)
+if (virDomainObjSave(vm, driver->xmlopt, caps,
+ BHYVE_STATE_DIR) < 0)
 goto cleanup;
 
 ret = 0;
@@ -430,9 +429,8 @@ virBhyveProcessReconnect(virDomainObjPtr vm,
 vm->def->id = -1;
 virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF,
  VIR_DOMAIN_SHUTOFF_UNKNOWN);
-ignore_value(virDomainSaveStatus(data->driver->xmlopt,
- BHYVE_STATE_DIR,
- vm, caps));
+ignore_value(virDomainObjSave(vm, data->driver->xmlopt, caps,
+  BHYVE_STATE_DIR));
 }
 
 virObjectUnref(caps);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9580884747..87bbb2d263 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29014,10 +29014,10 @@ virDomainDefCompatibleDevice(virDomainDefPtr def,
 return 0;
 }
 
-int
-virDomainSaveXML(const char *configDir,
- virDomainDefPtr def,
- const char *xml)
+static int
+virDomainDefSaveXML(virDomainDefPtr def,
+const char *configDir,
+const char *xml)
 {
 char uuidstr[VIR_UUID_STRING_BUFLEN];
 g_autofree char *configFile = NULL;
@@ -29042,23 +29042,24 @@ virDomainSaveXML(const char *configDir,
 }
 
 int
-virDomainSaveConfig(const char *configDir,
-virCapsPtr caps,
-virDomainDefPtr def)
+virDomainDefSave(virDomainDefPtr def,
+ virDomainXMLOptionPtr xmlopt G_GNUC_UNUSED,
+ virCapsPtr caps,
+ const char *configDir)
 {
 g_autofree char *xml = NULL;
 
 if (!(xml = virDomainDefFormat(def, caps, VIR_DOMAIN_DEF_FORMAT_SECURE)))
 return -1;
 
-return virDomainSaveXML(configDir, def, xml);
+return virDomainDefSaveXML(def, configDir, xml);
 }
 
 int
-virDomainSaveStatus(virDomainXMLOptionPtr xmlopt,
-const char *statusDir,
-virDomainObjPtr obj,
-virCapsPtr caps)
+virDomainObjSave(virDomainObjPtr obj,
+ virDomainXMLOptionPtr xmlopt,
+ virCapsPtr caps,
+ const char *statusDir)
 {
 unsigned int flags = (VIR_DOMAIN_DEF_FORMAT_SECURE |
   VIR_DOMAIN_DEF_FORMAT_STATUS |
@@ -29071,7 +29072,7 @@ virDomainSaveStatus(virDomainXMLOptionPtr xmlopt,
 if (!(xml = virDomainObjFormat(xmlopt, obj, caps, flags)))
 return -1;
 
-return virDomainSaveXML(statusDir, obj->def, xml);
+return virDomainDefSaveXML(obj->def, statusDir, xml);
 }
 
 
@@ -30173,7 +30174,7 @@ virDomainObjSetMetadata(virDomainObjPtr vm,
 if 

[libvirt] [PATCH 02/30] qemu: add machines & arch to fake test capabilities cache

2019-12-04 Thread Daniel P . Berrangé
Currently the virQEMUCapsPtr objects are just empty. Future patches are
going to expect them to contain real data. Start off by populating the
machine types and arch information.

Signed-off-by: Daniel P. Berrangé 
---
 src/qemu/qemu_capabilities.c |  70 +++--
 src/qemu/qemu_capspriv.h |  10 +
 tests/qemuxml2argvtest.c |   9 +-
 tests/testutilsqemu.c| 594 ---
 4 files changed, 190 insertions(+), 493 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index cfc16ba63e..c02ff5b941 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2434,49 +2434,72 @@ static const char *preferredMachines[] =
 verify(G_N_ELEMENTS(preferredMachines) == VIR_ARCH_LAST);
 
 
+void
+virQEMUCapsAddMachine(virQEMUCapsPtr qemuCaps,
+  virDomainVirtType virtType,
+  const char *name,
+  const char *alias,
+  const char *defaultCPU,
+  int maxCpus,
+  bool hotplugCpus,
+  bool isDefault)
+{
+virQEMUCapsAccelPtr accel = virQEMUCapsGetAccel(qemuCaps, virtType);
+virQEMUCapsMachineTypePtr mach;
+
+accel->machineTypes = g_renew(virQEMUCapsMachineType,
+  accel->machineTypes,
+  ++accel->nmachineTypes);
+
+mach = &(accel->machineTypes[accel->nmachineTypes - 1]);
+
+mach->alias = g_strdup(alias);
+mach->name = g_strdup(name);
+mach->defaultCPU = g_strdup(defaultCPU);
+
+mach->maxCpus = maxCpus;
+mach->hotplugCpus = hotplugCpus;
+
+mach->qemuDefault = isDefault;
+}
+
 static int
 virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
-virQEMUCapsAccelPtr accel,
+virDomainVirtType virtType,
 qemuMonitorPtr mon)
 {
 qemuMonitorMachineInfoPtr *machines = NULL;
 int nmachines = 0;
-int ret = -1;
 size_t i;
 ssize_t defIdx = -1;
 ssize_t preferredIdx = -1;
 const char *preferredMachine = preferredMachines[qemuCaps->arch];
+virQEMUCapsAccelPtr accel = virQEMUCapsGetAccel(qemuCaps, virtType);
 
 if ((nmachines = qemuMonitorGetMachines(mon, )) < 0)
 return -1;
 
-if (VIR_ALLOC_N(accel->machineTypes, nmachines) < 0)
-goto cleanup;
-
 for (i = 0; i < nmachines; i++) {
-virQEMUCapsMachineTypePtr mach;
 if (STREQ(machines[i]->name, "none"))
 continue;
 
-mach = &(accel->machineTypes[accel->nmachineTypes++]);
-
-mach->alias = g_strdup(machines[i]->alias);
-mach->name = g_strdup(machines[i]->name);
-mach->defaultCPU = g_strdup(machines[i]->defaultCPU);
-
-mach->maxCpus = machines[i]->maxCpus;
-mach->hotplugCpus = machines[i]->hotplugCpus;
+virQEMUCapsAddMachine(qemuCaps,
+  virtType,
+  machines[i]->name,
+  machines[i]->alias,
+  machines[i]->defaultCPU,
+  machines[i]->maxCpus,
+  machines[i]->hotplugCpus,
+  machines[i]->isDefault);
 
 if (preferredMachine &&
-(STREQ_NULLABLE(mach->alias, preferredMachine) ||
- STREQ(mach->name, preferredMachine))) {
+(STREQ_NULLABLE(machines[i]->alias, preferredMachine) ||
+ STREQ(machines[i]->name, preferredMachine))) {
 preferredIdx = accel->nmachineTypes - 1;
 }
 
-if (machines[i]->isDefault) {
-mach->qemuDefault = true;
+if (machines[i]->isDefault)
 defIdx = accel->nmachineTypes - 1;
-}
 }
 
 /*
@@ -2493,13 +2516,10 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
 if (preferredIdx != -1)
 virQEMUCapsSetDefaultMachine(accel, preferredIdx);
 
-ret = 0;
-
- cleanup:
 for (i = 0; i < nmachines; i++)
 qemuMonitorMachineInfoFree(machines[i]);
 VIR_FREE(machines);
-return ret;
+return 0;
 }
 
 
@@ -4745,7 +4765,7 @@ virQEMUCapsInitQMPMonitor(virQEMUCapsPtr qemuCaps,
 return -1;
 if (virQEMUCapsProbeQMPDevices(qemuCaps, mon) < 0)
 return -1;
-if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, accel, mon) < 0)
+if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, type, mon) < 0)
 return -1;
 if (virQEMUCapsProbeQMPMachineProps(qemuCaps, type, mon) < 0)
 return -1;
@@ -4788,7 +4808,7 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps,
 if (virQEMUCapsProbeQMPHostCPU(qemuCaps, accel, mon, VIR_DOMAIN_VIRT_QEMU) 
< 0)
 return -1;
 
-if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, accel, mon) < 0)
+if (virQEMUCapsProbeQMPMachineTypes(qemuCaps, VIR_DOMAIN_VIRT_QEMU, mon) < 
0)
 return -1;
 
 return 

[libvirt] [PATCH 10/30] conf: pass default sec model in parser config

2019-12-04 Thread Daniel P . Berrangé
Instead of using the virCapsPtr to get the default security model,
pass this in via the parser config.

Signed-off-by: Daniel P. Berrangé 
---
 src/conf/domain_conf.c | 14 +++---
 src/conf/domain_conf.h |  1 +
 src/qemu/qemu_conf.c   |  4 +++-
 src/qemu/qemu_conf.h   |  3 ++-
 src/qemu/qemu_driver.c | 11 ++-
 tests/testutilsqemu.c  |  2 +-
 6 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index f037702ac2..8acc91de74 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8911,13 +8911,12 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt,
 static int
 virSecurityLabelDefsParseXML(virDomainDefPtr def,
  xmlXPathContextPtr ctxt,
- virCapsPtr caps,
+ virDomainXMLOptionPtr xmlopt,
  unsigned int flags)
 {
 VIR_XPATH_NODE_AUTORESTORE(ctxt);
 size_t i = 0, j;
 int n;
-virCapsHostPtr host = >host;
 g_autofree xmlNodePtr *list = NULL;
 
 /* Allocate a security labels based on XML */
@@ -8960,15 +8959,16 @@ virSecurityLabelDefsParseXML(virDomainDefPtr def,
  */
 if (def->nseclabels == 1 &&
 !def->seclabels[0]->model &&
-host->nsecModels > 0) {
+xmlopt != NULL &&
+xmlopt->config.defSecModel != NULL) {
 if (def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_NONE ||
 (def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_DYNAMIC &&
  !def->seclabels[0]->baselabel &&
  (flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))) {
 /* Copy model from host. */
 VIR_DEBUG("Found seclabel without a model, using '%s'",
-  host->secModels[0].model);
-def->seclabels[0]->model = g_strdup(host->secModels[0].model);
+  xmlopt->config.defSecModel);
+def->seclabels[0]->model = g_strdup(xmlopt->config.defSecModel);
 
 if (STREQ(def->seclabels[0]->model, "none") &&
 flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) {
@@ -19733,7 +19733,7 @@ virDomainMemorytuneDefParse(virDomainDefPtr def,
 static virDomainDefPtr
 virDomainDefParseXML(xmlDocPtr xml,
  xmlXPathContextPtr ctxt,
- virCapsPtr caps,
+ virCapsPtr caps G_GNUC_UNUSED,
  virDomainXMLOptionPtr xmlopt,
  unsigned int flags)
 {
@@ -19841,7 +19841,7 @@ virDomainDefParseXML(xmlDocPtr xml,
 /* analysis of security label, done early even though we format it
  * late, so devices can refer to this for defaults */
 if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL)) {
-if (virSecurityLabelDefsParseXML(def, ctxt, caps, flags) == -1)
+if (virSecurityLabelDefsParseXML(def, ctxt, xmlopt, flags) == -1)
 goto error;
 }
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e85d3bd5b5..af57e288e9 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2707,6 +2707,7 @@ struct _virDomainDefParserConfig {
 unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
 virArch defArch;
 const char *netPrefix;
+const char *defSecModel;
 };
 
 typedef void *(*virDomainXMLPrivateDataAllocFunc)(void *);
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 53658c80e8..053bcc7e02 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1191,9 +1191,11 @@ virQEMUDriverIsPrivileged(virQEMUDriverPtr driver)
 }
 
 virDomainXMLOptionPtr
-virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver)
+virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver,
+   const char *defsecmodel)
 {
 virQEMUDriverDomainDefParserConfig.priv = driver;
+virQEMUDriverDomainDefParserConfig.defSecModel = defsecmodel;
 return virDomainXMLOptionNew(,
  ,
  ,
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 7c56226b8c..8b6c2a95d4 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -366,7 +366,8 @@ int qemuRemoveSharedDisk(virQEMUDriverPtr driver,
 int qemuSetUnprivSGIO(virDomainDeviceDefPtr dev);
 
 int qemuDriverAllocateID(virQEMUDriverPtr driver);
-virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver);
+virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver,
+ const char *defsecmodel);
 
 int qemuTranslateSnapshotDiskSourcePool(virDomainSnapshotDiskDefPtr def);
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 891ca28d94..93a92dad36 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -656,6 +656,8 @@ qemuStateInitialize(bool privileged,
 g_autofree char *memoryBackingPath = NULL;
 bool autostart = true;
 size_t i;
+const char *defsecmodel = NULL;
+g_autofree virSecurityManagerPtr *sec_managers = NULL;
 
  

[libvirt] [PATCH 07/30] conf: don't use passed in caps in post parse method

2019-12-04 Thread Daniel P . Berrangé
To enable the virCapsPtr parameter to the post parse method to be
eliminated, the drivers must fetch the virCapsPtr from their own
driver via the opaque parameter, or use an alternative approach
to validate the parsed data.

Signed-off-by: Daniel P. Berrangé 
---
 src/bhyve/bhyve_domain.c   | 10 +--
 src/esx/esx_driver.c   |  2 +-
 src/libxl/libxl_conf.c |  3 ++-
 src/libxl/libxl_conf.h |  2 +-
 src/libxl/libxl_domain.c   |  9 ---
 src/libxl/libxl_driver.c   |  2 +-
 src/lxc/lxc_conf.c |  3 ++-
 src/lxc/lxc_conf.h |  2 +-
 src/lxc/lxc_controller.c   | 44 ---
 src/lxc/lxc_domain.c   |  8 --
 src/lxc/lxc_driver.c   |  2 +-
 src/openvz/openvz_conf.c   | 10 ---
 src/openvz/openvz_conf.h   |  2 +-
 src/openvz/openvz_driver.c |  2 +-
 src/phyp/phyp_driver.c |  8 +++---
 src/qemu/qemu_capabilities.c   | 38 +++
 src/qemu/qemu_capabilities.h   |  4 +++
 src/qemu/qemu_domain.c | 48 +-
 src/vmware/vmware_driver.c | 11 
 src/vmx/vmx.c  |  8 +++---
 src/vmx/vmx.h  |  2 +-
 src/vz/vz_driver.c | 15 ++-
 tests/Makefile.am  | 14 +++---
 tests/libxlxml2domconfigtest.c | 22 +---
 tests/lxcconf2xmltest.c| 17 
 tests/lxcxml2xmltest.c | 13 +++--
 tests/openvzutilstest.c| 10 ---
 tests/testutilslxc.c   | 34 +++-
 tests/testutilslxc.h   |  4 +++
 tests/testutilsxen.c   | 34 +++-
 tests/testutilsxen.h   |  9 ---
 tests/vmx2xmltest.c|  2 +-
 tests/xlconfigtest.c   | 26 --
 tests/xmconfigtest.c   | 23 +++-
 tests/xml2vmxtest.c|  2 +-
 35 files changed, 301 insertions(+), 144 deletions(-)

diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c
index 575f141b53..eebf5a7650 100644
--- a/src/bhyve/bhyve_domain.c
+++ b/src/bhyve/bhyve_domain.c
@@ -20,6 +20,7 @@
 
 #include 
 
+#include "bhyve_driver.h"
 #include "bhyve_conf.h"
 #include "bhyve_device.h"
 #include "bhyve_domain.h"
@@ -74,11 +75,16 @@ bhyveDomainDefNeedsISAController(virDomainDefPtr def)
 
 static int
 bhyveDomainDefPostParse(virDomainDefPtr def,
-virCapsPtr caps,
+virCapsPtr _caps G_GNUC_UNUSED,
 unsigned int parseFlags G_GNUC_UNUSED,
-void *opaque G_GNUC_UNUSED,
+void *opaque,
 void *parseOpaque G_GNUC_UNUSED)
 {
+bhyveConnPtr driver = opaque;
+g_autoptr(virCaps) caps = bhyveDriverGetCapabilities(driver);
+if (!caps)
+return -1;
+
 if (!virCapabilitiesDomainSupported(caps, def->os.type,
 def->os.arch,
 def->virtType))
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 81ff502769..2db89c7986 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -928,7 +928,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth,
 if (!priv->caps)
 goto cleanup;
 
-if (!(priv->xmlopt = virVMXDomainXMLConfInit()))
+if (!(priv->xmlopt = virVMXDomainXMLConfInit(priv->caps)))
 goto cleanup;
 
 conn->privateData = priv;
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 37fe360067..132e04b147 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -2470,8 +2470,9 @@ libxlBuildDomainConfig(virPortAllocatorRangePtr 
graphicsports,
 }
 
 virDomainXMLOptionPtr
-libxlCreateXMLConf(void)
+libxlCreateXMLConf(libxlDriverPrivatePtr driver)
 {
+libxlDomainDefParserConfig.priv = driver;
 return virDomainXMLOptionNew(,
  ,
  NULL, NULL, NULL);
diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h
index 305c8c41ef..4b5d240684 100644
--- a/src/libxl/libxl_conf.h
+++ b/src/libxl/libxl_conf.h
@@ -207,7 +207,7 @@ libxlMakeUSB(virDomainHostdevDefPtr hostdev, 
libxl_device_usbdev *usbdev);
 #endif
 
 virDomainXMLOptionPtr
-libxlCreateXMLConf(void);
+libxlCreateXMLConf(libxlDriverPrivatePtr driver);
 
 #ifdef LIBXL_HAVE_DEVICE_CHANNEL
 # define LIBXL_ATTR_UNUSED
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index ad9424155a..f202f0fc3e 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -367,12 +367,15 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
 
 static int
 libxlDomainDefPostParse(virDomainDefPtr def,
-virCapsPtr caps,
+virCapsPtr caps G_GNUC_UNUSED,
 unsigned int parseFlags G_GNUC_UNUSED,
-void *opaque G_GNUC_UNUSED,
+void *opaque,
  

[libvirt] [PATCH 06/30] conf: move virt type / os type / arch validation to post-parse

2019-12-04 Thread Daniel P . Berrangé
The XML parser currently calls virCapabilitiesDomainDataLookup during
parsing to find the domain capabilities matching the triple

  (virt type, os type, arch)

This is, however, bogus with the QEMU driver as it assumes that there
is an emulator known to the default driver capabilities that matches
this triple. It is entirely possible for the driver to be parsing an
XML file with a custom emulator path specified pointing to a binary
that doesn't exist in the default driver capabilities.  This will,
for example be the case on a RHEL host which only installs the host
native emulator to /usr/bin. The user can have built a custom QEMU
for non-native arches into $HOME and wish to use that.

Aside from validation, this call is also used to fill in a machine type
for the guest if not otherwise specified. Again, this data may be
incorrect for the QEMU driver because it is not taking account of
the emulator binary that is referenced.

To start fixing this, move the validation to the post-parse callbacks
where more intelligent driver specific logic can be applied.

Signed-off-by: Daniel P. Berrangé 
---
 src/bhyve/bhyve_domain.c   |  7 ++-
 src/conf/capabilities.c| 17 +
 src/conf/capabilities.h|  7 +++
 src/conf/domain_conf.c | 19 ++-
 src/libvirt_private.syms   |  1 +
 src/libxl/libxl_domain.c   |  7 ++-
 src/lxc/lxc_domain.c   |  5 +
 src/openvz/openvz_conf.c   |  7 ++-
 src/phyp/phyp_driver.c |  9 +++--
 src/qemu/qemu_domain.c | 19 +++
 src/vmware/vmware_driver.c |  9 +++--
 src/vmx/vmx.c  |  9 +++--
 src/vz/vz_driver.c |  7 ++-
 13 files changed, 92 insertions(+), 31 deletions(-)

diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c
index 7d24bb602f..575f141b53 100644
--- a/src/bhyve/bhyve_domain.c
+++ b/src/bhyve/bhyve_domain.c
@@ -74,11 +74,16 @@ bhyveDomainDefNeedsISAController(virDomainDefPtr def)
 
 static int
 bhyveDomainDefPostParse(virDomainDefPtr def,
-virCapsPtr caps G_GNUC_UNUSED,
+virCapsPtr caps,
 unsigned int parseFlags G_GNUC_UNUSED,
 void *opaque G_GNUC_UNUSED,
 void *parseOpaque G_GNUC_UNUSED)
 {
+if (!virCapabilitiesDomainSupported(caps, def->os.type,
+def->os.arch,
+def->virtType))
+return -1;
+
 /* Add an implicit PCI root controller */
 if (virDomainDefMaybeAddController(def, VIR_DOMAIN_CONTROLLER_TYPE_PCI, 0,
VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) < 
0)
diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index ff7d265621..748dd64273 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -816,6 +816,23 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps,
 }
 
 
+bool
+virCapabilitiesDomainSupported(virCapsPtr caps,
+   int ostype,
+   virArch arch,
+   int virttype)
+{
+g_autofree virCapsDomainDataPtr capsdata = NULL;
+
+capsdata = virCapabilitiesDomainDataLookup(caps, ostype,
+   arch,
+   virttype,
+   NULL, NULL);
+
+return capsdata != NULL;
+}
+
+
 int
 virCapabilitiesAddStoragePool(virCapsPtr caps,
   int poolType)
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 8a7137d7eb..c39fe0de08 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -309,6 +309,13 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps,
 const char *emulator,
 const char *machinetype);
 
+bool
+virCapabilitiesDomainSupported(virCapsPtr caps,
+   int ostype,
+   virArch arch,
+   int domaintype);
+
+
 void
 virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPUPtr cpu,
 size_t ncpus);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1c2b8f26ed..6abe15f721 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -19565,14 +19565,11 @@ virDomainCachetuneDefParse(virDomainDefPtr def,
 static int
 virDomainDefParseCaps(virDomainDefPtr def,
   xmlXPathContextPtr ctxt,
-  virDomainXMLOptionPtr xmlopt,
-  virCapsPtr caps,
-  unsigned int flags)
+  virDomainXMLOptionPtr xmlopt)
 {
 g_autofree char *virttype = NULL;
 g_autofree char *arch = NULL;
 g_autofree char *ostype = NULL;
-g_autofree virCapsDomainDataPtr capsdata = NULL;
 
 virttype = virXPathString("string(./@type)", 

[libvirt] [PATCH 01/30] qemu: cache host arch separately from virCapsPtr

2019-12-04 Thread Daniel P . Berrangé
As part of a goal to eliminate the need to use virCapsPtr for anything
other than the virConnectGetCapabilies() API impl, cache the host arch
against the QEMU driver struct and use that field directly.

In the tests we move virArchFromHost() globally in testutils.c so that
every test runs with a fixed default architecture reported.

Signed-off-by: Daniel P. Berrangé 
---
 src/qemu/qemu_capabilities.c | 20 ++--
 src/qemu/qemu_capabilities.h |  6 +++---
 src/qemu/qemu_command.c  |  6 +-
 src/qemu/qemu_conf.c |  6 +-
 src/qemu/qemu_conf.h |  3 +++
 src/qemu/qemu_domain.c   |  8 
 src/qemu/qemu_driver.c   |  3 ++-
 src/qemu/qemu_process.c  | 14 +++---
 tests/domaincapstest.c   |  2 +-
 tests/qemumemlocktest.c  |  4 ++--
 tests/qemuxml2argvtest.c | 16 
 tests/testutils.c|  9 +
 tests/testutils.h|  2 ++
 tests/testutilsqemu.c| 11 ---
 tests/testutilsqemu.h|  4 ++--
 15 files changed, 63 insertions(+), 51 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index edb128c881..cfc16ba63e 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2096,7 +2096,7 @@ virQEMUCapsSetHostModel(virQEMUCapsPtr qemuCaps,
 
 bool
 virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
-  virCapsPtr caps,
+  virArch hostarch,
   virDomainVirtType type,
   virCPUMode mode)
 {
@@ -2105,7 +2105,7 @@ virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
 switch (mode) {
 case VIR_CPU_MODE_HOST_PASSTHROUGH:
 return type == VIR_DOMAIN_VIRT_KVM &&
-   virQEMUCapsGuestIsNative(caps->host.arch, qemuCaps->arch);
+   virQEMUCapsGuestIsNative(hostarch, qemuCaps->arch);
 
 case VIR_CPU_MODE_HOST_MODEL:
 return !!virQEMUCapsGetHostModel(qemuCaps, type,
@@ -5412,22 +5412,22 @@ virQEMUCapsFillDomainOSCaps(virDomainCapsOSPtr os,
 
 
 static void
-virQEMUCapsFillDomainCPUCaps(virCapsPtr caps,
- virQEMUCapsPtr qemuCaps,
+virQEMUCapsFillDomainCPUCaps(virQEMUCapsPtr qemuCaps,
+ virArch hostarch,
  virDomainCapsPtr domCaps)
 {
-if (virQEMUCapsIsCPUModeSupported(qemuCaps, caps, domCaps->virttype,
+if (virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, domCaps->virttype,
   VIR_CPU_MODE_HOST_PASSTHROUGH))
 domCaps->cpu.hostPassthrough = true;
 
-if (virQEMUCapsIsCPUModeSupported(qemuCaps, caps, domCaps->virttype,
+if (virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, domCaps->virttype,
   VIR_CPU_MODE_HOST_MODEL)) {
 virCPUDefPtr cpu = virQEMUCapsGetHostModel(qemuCaps, domCaps->virttype,

VIR_QEMU_CAPS_HOST_CPU_REPORTED);
 domCaps->cpu.hostModel = virCPUDefCopy(cpu);
 }
 
-if (virQEMUCapsIsCPUModeSupported(qemuCaps, caps, domCaps->virttype,
+if (virQEMUCapsIsCPUModeSupported(qemuCaps, hostarch, domCaps->virttype,
   VIR_CPU_MODE_CUSTOM)) {
 const char *blacklist[] = { "host", NULL };
 VIR_AUTOSTRINGLIST models = NULL;
@@ -5746,9 +5746,9 @@ virQEMUCapsFillDomainFeatureSEVCaps(virQEMUCapsPtr 
qemuCaps,
 
 
 int
-virQEMUCapsFillDomainCaps(virCapsPtr caps,
+virQEMUCapsFillDomainCaps(virQEMUCapsPtr qemuCaps,
+  virArch hostarch,
   virDomainCapsPtr domCaps,
-  virQEMUCapsPtr qemuCaps,
   bool privileged,
   virFirmwarePtr *firmwares,
   size_t nfirmwares)
@@ -5781,7 +5781,7 @@ virQEMUCapsFillDomainCaps(virCapsPtr caps,
 firmwares, nfirmwares) < 0)
 return -1;
 
-virQEMUCapsFillDomainCPUCaps(caps, qemuCaps, domCaps);
+virQEMUCapsFillDomainCPUCaps(qemuCaps, hostarch, domCaps);
 virQEMUCapsFillDomainDeviceDiskCaps(qemuCaps, domCaps->machine, disk);
 virQEMUCapsFillDomainDeviceGraphicsCaps(qemuCaps, graphics);
 virQEMUCapsFillDomainDeviceVideoCaps(qemuCaps, video);
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 4d7d836e8c..399496796d 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -604,7 +604,7 @@ int virQEMUCapsGetCPUFeatures(virQEMUCapsPtr qemuCaps,
   char ***features);
 
 bool virQEMUCapsIsCPUModeSupported(virQEMUCapsPtr qemuCaps,
-   virCapsPtr caps,
+   virArch hostarch,
virDomainVirtType type,
virCPUMode mode);
 const char 

[libvirt] [PATCH 00/30] conf: eliminate use of virCapsPtr for parsing/formatting XML

2019-12-04 Thread Daniel P . Berrangé
The virCapsPtr object is a serious source of performance problems for
the QEMU driver, because populating it means probing every QEMU system
emulator binary installed on the host.

This is is crazy because parsing any single XML document only ever needs
information about a single QEMU binary.

We've already done a great job of untangling stuff with the post-parse
and validation functions, but the job was never quite finished. This
series tackles the last pieces so that parsing & formatting XML will
never use the virCapsPtr object directly. Some of the virt drivers will
still use virCapsPtr in their private callbacks, but the QEMU driver
will instead use the QEMU emulator capabilities cache directly.

The first ten patches are the key bits of work to remove use of the
virCapsPtr parameter from domain XML APIs.

The next thirteen patches remove the (now unused) virCapsPtr parameter
from the domain XML APIs & their callers.

The final six patches help various QEMU driver APIs stop relying
on the virCapsPtr, so that it is no longer even created at startup.

This has a nice benefit on libvirtd startup tie when all 30 QEMU
emulators are installed, reducing it from 4 seconds down to a
fraction of a second.

More work is still needed to follow on from this...

A couple of places in the QEMU driver still use virCapsPtr

 - The virConnectGetVersion API.
 - The virNodeGetSecurityModel API.
 - virDomainGetResctrlMonData API.

In all cases we just need to move to store the relevant data directly
in virQEMUDriverPtr, and not use the virCaps. 


next, apps can use virDomainGetCapabilities to fetch info about a
specific QEMU binary they care about to avoid the cost of the
virConnectGetCapabilities API.

There are still times when apps need info in virConnectGetCapabilities
and this will annoyingly probe all QEMU binaries, even though the app
doesn't want the guest info.

virConnectGetCapabilities is one of our very early APIs which now flags
parameter, so this problem is unfixable in that API.

I'm thus included to introduce a new virNodeGetCapabilities that is
specifically only returning information about the host hypervisor.
Essentially the  schema, but only the  sub-tree.

I do, however, wonder if even this is overkill & we should aim for a
much more fine grained way for reporting host capabilities.

eg if an app wants the host CPU, do they really want to pay the
penality to probe host cache nformation, or NUMA topology and
vica-verca.

I'm not sure what the right kind of tradeoff here is, whether we should
try individual APIs, or have one API and a set of flags to control what
info is filled in.

Daniel P. Berrangé (30):
  qemu: cache host arch separately from virCapsPtr
  qemu: add machines & arch to fake test capabilities cache
  conf: sanitize virDomainSaveStatus & virDomainSaveConfig APIs
  conf: sanitize virDomainObjFormat & virDomainDefFormat* APIs
  conf: pass in default architecture via domain XML options
  conf: move virt type / os type / arch validation to post-parse
  conf: don't use passed in caps in post parse method
  conf: pass netprefix in the domain parser config struct
  conf: move seclabel validation into post-parse phase
  conf: pass default sec model in parser config
  conf: drop virCapsPtr param from assign addresses callback
  conf: drop virCapsPtr param from basic post parse callback
  conf: drop virCapsPtr param from post parse data alloc callback
  conf: drop virCapsPtr param from post parse callback
  conf: drop virCapsPtr param from device post parse callback
  conf: drop virCapsPtr param from domain validate callback
  conf: drop virCapsPtr param from domain formatting APIs
  conf: drop virCapsPtr param from domain post parse & validate APIs
  conf: drop virCapsPtr param from domain parse APIs
  conf: drop virCapsPtr param from domain APIs for copying config
  conf: drop virCapsPtr param from APIs for saving domains
  conf: drop virCapsPtr param from domain obj list APIs
  conf: drop virCapsPtr param from snapshot & checkpoint APIs
  qemu: drop virCapsPtr param & vars from many APIs
  conf: move NUMA capabilities into self contained object
  qemu: use NUMA capabilities object directly
  conf: make virCPUDef into a ref counted struct
  qemu: use host CPU object directly
  qemu: directly create virResctrlInfo ignoring capabilities
  qemu: stop creating capabilities at driver startup

 docs/formatdomain.html.in   |   6 +-
 src/bhyve/bhyve_domain.c|  16 +-
 src/bhyve/bhyve_driver.c|  46 +-
 src/bhyve/bhyve_process.c   |  22 +-
 src/conf/capabilities.c | 217 +---
 src/conf/capabilities.h |  34 +-
 src/conf/checkpoint_conf.c  |  21 +-
 src/conf/checkpoint_conf.h  |   2 -
 src/conf/cpu_conf.c |  29 +-
 src/conf/cpu_conf.h |   4 +
 src/conf/domain_conf.c  | 404 ++
 src/conf/domain_conf.h  |  84 ++-
 

Re: [libvirt] [jenkins-ci PATCH] Drop support for python 2

2019-12-04 Thread Fabiano Fidêncio
Daniel,

[snip]

> diff --git a/guests/host_vars/libvirt-centos-7/main.yml 
> b/guests/host_vars/libvirt-centos-7/main.yml
> index 94e29af..d730aa2 100644
> --- a/guests/host_vars/libvirt-centos-7/main.yml
> +++ b/guests/host_vars/libvirt-centos-7/main.yml
> @@ -16,5 +16,3 @@ package_format: 'rpm'
>  package_manager: 'yum'
>  os_name: 'CentOS'
>  os_version: '7'
> -
> -ansible_python_interpreter: /usr/bin/python2

We cannot do that, unfortunately.

I've tried, in the past, but "yum" ansible module requires python2.

[snip]

Best Regards,
-- 
Fabiano Fidêncio


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

Re: [libvirt] [PATCH] tests: Make check-file-access.pl accept files through argv

2019-12-04 Thread Daniel P . Berrangé
On Wed, Dec 04, 2019 at 03:01:31PM +0100, Michal Privoznik wrote:
> The script needs two files to open:
> 
>   $(builddir)/test_file_access.txt, and
>   $(srcdir)/file_access_whitelist.txt.
> 
> However, the script is opening the files from the $CWD which
> won't work for a VPATH build. Make the script accept paths to the
> files through @ARGV and tune the Makefile.am to pass them.
> 
> Signed-off-by: Michal Privoznik 
> ---
>  tests/Makefile.am  | 4 +++-
>  tests/check-file-access.pl | 8 ++--
>  2 files changed, 9 insertions(+), 3 deletions(-)

Reviewed-by: Daniel P. Berrangé 

This matches what i've done in the next version of the python rewrite too

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 v5 17/23] tests: rewrite file access checker in Python

2019-12-04 Thread Michal Privoznik

On 12/4/19 2:19 PM, Daniel P. Berrangé wrote:

On Mon, Nov 18, 2019 at 02:11:33PM -0500, Cole Robinson wrote:

On 11/11/19 9:38 AM, Daniel P. Berrangé wrote:

As part of an goal to eliminate Perl from libvirt build tools,
rewrite the check-file-access.pl tool in Python.

This was a straight conversion, manually going line-by-line to
change the syntax from Perl to Python. Thus the overall structure
of the file and approach is the same.

Signed-off-by: Daniel P. Berrangé 
---
  Makefile.am |   1 +
  scripts/check-file-access.py| 123 +++
  tests/Makefile.am   |   3 +-
  tests/check-file-access.pl  | 126 
  tests/file_access_whitelist.txt |   2 +-
  5 files changed, 126 insertions(+), 129 deletions(-)
  create mode 100755 scripts/check-file-access.py
  delete mode 100755 tests/check-file-access.pl



`make -C builddir check-access` fails like:

LC_ALL= LANG=C LC_CTYPE=en_US.UTF-8 /usr/bin/python3
/home/crobinso/src/libvirt/scripts/check-file-access.py | sort -u
Traceback (most recent call last):
   File "/home/crobinso/src/libvirt/scripts/check-file-access.py", line
53, in 
 with open(whitelist_file, "r") as fh:
FileNotFoundError: [Errno 2] No such file or directory:
'file_access_whitelist.txt'
make[1]: Leaving directory '/home/crobinso/src/libvirt/builddir/tests'
make: Leaving directory '/home/crobinso/src/libvirt/builddir'


Looks like this is unrelated to this patch - the original script
has the same flaw wrt VPATH builds, and indeed even the Makefile.am
is currently broken.


Yes, I guess it never worked with VPATH. Anyway, patch proposed here:

https://www.redhat.com/archives/libvir-list/2019-December/msg00204.html

Michal

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

[libvirt] [PATCH] tests: Make check-file-access.pl accept files through argv

2019-12-04 Thread Michal Privoznik
The script needs two files to open:

  $(builddir)/test_file_access.txt, and
  $(srcdir)/file_access_whitelist.txt.

However, the script is opening the files from the $CWD which
won't work for a VPATH build. Make the script accept paths to the
files through @ARGV and tune the Makefile.am to pass them.

Signed-off-by: Michal Privoznik 
---
 tests/Makefile.am  | 4 +++-
 tests/check-file-access.pl | 8 ++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index cbe8e86224..4c2856bf97 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -454,7 +454,9 @@ EXTRA_DIST += $(test_scripts)
 if WITH_LINUX
 check-access: file-access-clean
VIR_TEST_FILE_ACCESS=1 $(MAKE) $(AM_MAKEFLAGS) check
-   $(PERL) check-file-access.pl | sort -u
+   $(PERL) $(abs_srcdir)/check-file-access.pl \
+   $(abs_builddir)/test_file_access.txt \
+   $(abs_srcdir)/file_access_whitelist.txt | sort -u
 
 file-access-clean:
> test_file_access.txt
diff --git a/tests/check-file-access.pl b/tests/check-file-access.pl
index ea0b7a18a2..2926126b14 100755
--- a/tests/check-file-access.pl
+++ b/tests/check-file-access.pl
@@ -24,8 +24,12 @@
 use strict;
 use warnings;
 
-my $access_file = "test_file_access.txt";
-my $whitelist_file = "file_access_whitelist.txt";
+sub usage {
+die "$0 access_file file_access_whitelist\n";
+}
+
+my $access_file = shift or usage();
+my $whitelist_file = shift or usage();
 
 my @known_actions = ("open", "fopen", "access", "stat", "lstat", "connect");
 
-- 
2.23.0

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



[libvirt] [jenkins-ci PATCH] Drop support for python 2

2019-12-04 Thread Daniel P . Berrangé
CentOS7 now has support for python 3 out of the box

Signed-off-by: Daniel P. Berrangé 
---
 guests/host_vars/libvirt-centos-7/main.yml  |  2 --
 guests/playbooks/update/tasks/bootstrap.yml |  6 --
 guests/vars/mappings.yml| 24 -
 guests/vars/projects/base.yml   |  1 -
 guests/vars/projects/libvirt-python.yml |  4 
 5 files changed, 37 deletions(-)

diff --git a/guests/host_vars/libvirt-centos-7/main.yml 
b/guests/host_vars/libvirt-centos-7/main.yml
index 94e29af..d730aa2 100644
--- a/guests/host_vars/libvirt-centos-7/main.yml
+++ b/guests/host_vars/libvirt-centos-7/main.yml
@@ -16,5 +16,3 @@ package_format: 'rpm'
 package_manager: 'yum'
 os_name: 'CentOS'
 os_version: '7'
-
-ansible_python_interpreter: /usr/bin/python2
diff --git a/guests/playbooks/update/tasks/bootstrap.yml 
b/guests/playbooks/update/tasks/bootstrap.yml
index 2e1dc42..c77d3a1 100644
--- a/guests/playbooks/update/tasks/bootstrap.yml
+++ b/guests/playbooks/update/tasks/bootstrap.yml
@@ -7,11 +7,5 @@
 - set_fact:
 python: python3
 
-- set_fact:
-python: python2
-  when:
-- os_name == 'CentOS'
-- os_version == '7'
-
 - name: Bootstrap Ansible
   raw: '{{ package_manager }} install -y {{ python }}'
diff --git a/guests/vars/mappings.yml b/guests/vars/mappings.yml
index 9c339f2..ce1294c 100644
--- a/guests/vars/mappings.yml
+++ b/guests/vars/mappings.yml
@@ -804,30 +804,6 @@ mappings:
 CentOS7: python36-docutils
 FreeBSD: py36-docutils
 
-  python2:
-default: python
-Fedora: python2
-FreeBSD: python2
-
-  python2-devel:
-deb: python-dev
-pkg: python2
-rpm: python2-devel
-cross-policy-deb: foreign
-
-  python2-lxml:
-default: python-lxml
-Fedora: python2-lxml
-FreeBSD: py27-lxml
-
-  python2-nose:
-default: python-nose
-Fedora: python2-nose
-FreeBSD: py27-nose
-
-  python2-setuptools:
-CentOS7: python2-setuptools
-
   python3:
 default: python3
 
diff --git a/guests/vars/projects/base.yml b/guests/vars/projects/base.yml
index 275211c..29c10b4 100644
--- a/guests/vars/projects/base.yml
+++ b/guests/vars/projects/base.yml
@@ -25,7 +25,6 @@ packages:
   - patch
   - perl
   - pkg-config
-  - python2-setuptools
   - python3
   - python3-pip
   - python3-setuptools
diff --git a/guests/vars/projects/libvirt-python.yml 
b/guests/vars/projects/libvirt-python.yml
index 86b5aab..71a0717 100644
--- a/guests/vars/projects/libvirt-python.yml
+++ b/guests/vars/projects/libvirt-python.yml
@@ -1,9 +1,5 @@
 ---
 packages:
-  - python2
-  - python2-devel
-  - python2-lxml
-  - python2-nose
   - python3-devel
   - python3-lxml
   - python3-nose
-- 
2.23.0

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

Re: [libvirt] [PATCH v5 17/23] tests: rewrite file access checker in Python

2019-12-04 Thread Daniel P . Berrangé
On Mon, Nov 18, 2019 at 02:11:33PM -0500, Cole Robinson wrote:
> On 11/11/19 9:38 AM, Daniel P. Berrangé wrote:
> > As part of an goal to eliminate Perl from libvirt build tools,
> > rewrite the check-file-access.pl tool in Python.
> > 
> > This was a straight conversion, manually going line-by-line to
> > change the syntax from Perl to Python. Thus the overall structure
> > of the file and approach is the same.
> > 
> > Signed-off-by: Daniel P. Berrangé 
> > ---
> >  Makefile.am |   1 +
> >  scripts/check-file-access.py| 123 +++
> >  tests/Makefile.am   |   3 +-
> >  tests/check-file-access.pl  | 126 
> >  tests/file_access_whitelist.txt |   2 +-
> >  5 files changed, 126 insertions(+), 129 deletions(-)
> >  create mode 100755 scripts/check-file-access.py
> >  delete mode 100755 tests/check-file-access.pl
> > 
> 
> `make -C builddir check-access` fails like:
> 
> LC_ALL= LANG=C LC_CTYPE=en_US.UTF-8 /usr/bin/python3
> /home/crobinso/src/libvirt/scripts/check-file-access.py | sort -u
> Traceback (most recent call last):
>   File "/home/crobinso/src/libvirt/scripts/check-file-access.py", line
> 53, in 
> with open(whitelist_file, "r") as fh:
> FileNotFoundError: [Errno 2] No such file or directory:
> 'file_access_whitelist.txt'
> make[1]: Leaving directory '/home/crobinso/src/libvirt/builddir/tests'
> make: Leaving directory '/home/crobinso/src/libvirt/builddir'

Looks like this is unrelated to this patch - the original script
has the same flaw wrt VPATH builds, and indeed even the Makefile.am
is currently broken.

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 v3 0/3] Update valid range of scsi unit

2019-12-04 Thread Michal Privoznik

On 12/4/19 10:35 AM, Han Han wrote:

Fix spelling typo. Separate virtio serial port and ccid slot from
driveUnit.
v2: https://www.redhat.com/archives/libvir-list/2019-December/msg4.html

Han Han (3):
   conf: fix logic error for scsi units
   rng: Separate virtio serial port and ccid slot from driveUnit
   rng: Extend the range of driveUnit

  docs/schemas/domaincommon.rng | 16 +---
  src/conf/domain_conf.c|  2 +-
  2 files changed, 14 insertions(+), 4 deletions(-)



Reviewed-by: Michal Privoznik 

Thanks for taking care of this. I've pushed these.

Micahl

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



Re: [libvirt] [PATCH v2 00/15] docs: some refactoring and new docs about RPM deployment

2019-12-04 Thread Michal Privoznik

On 11/22/19 3:46 PM, Daniel P. Berrangé wrote:

This refactors existing docs related to the remote driver/daemon and
URIs. It then also adds a kbase page about RPM package options.

This introduces the use of RST for docs as a replacement for HTML.
The intent is that all new docs should use RST from this point.
The POD man pages will also be converted to RST. I'll post this as
a different series.

Note this series only touches the main HTML content, not the
styling / templating using XSL. Tackling that is a separate
job I've not attempted. My guess is that we'd use either Sphinx
or Pelican to do the templating.

Existing HTML docs are candidates for conversion to RST, however,
people should *NOT* attempt todo this manually.

In this series I've converted docs/kbase/ files, using the pandoc
tool. This does a pretty good job in general but does need some
manual cleanups. First I post-processed its output to change the
heading highlighting to follow the documented style

$ cat convert.pl

my @in = <>;

my @out;
for (my $i ; $i <= $#in; $i++) {
 my $line = $in[$i];
 if ($line =~ /^=+$/) {
 my @newout = splice @out, 0, $i - 1;
 push @newout, $line;
 push @newout, $out[$i-1];
 push @newout, $out[$i];
 push @newout, $line;
 push @newout, "\n";
 push @newout, ".. contents::\n";
 @out = @newout;
 } elsif ($line =~ /^(-|~|^|')+$/) {
 $line =~ s/-/=/g;
 $line =~ s/~/-/g;
 $line =~ s/\^/~/g;
 $line =~ s/'/^/g;
 push @out, $line;
 } else {
 push @out, $line;
 }
}

print @out;

So I'm converting with

   pandoc -f html -t rst < foo.html.in | perl convert.pl > foo.rst
   $EDITOR foot.rst
   git rm -f foot.html.in
   git add foo.rst

After pandoc & the headings convert, there's usually manual fixes
needed to deal with a few oddities pandoc gets wrong, or looks
ugly. This is still way simpler than converting the doc to rst
manually.

Changed in v2:

  - Added a style guide for RST docs
  - Probe for rst2html's different names
  - Added make rules for building rst
  - Fixed permalinks in generated docs
  - Misc CSS fixes
  - Auto-converted all of kbase/ directory

Daniel P. Berrangé (15):
   docs: split TLS certificate setup into its own file
   docs: move docs about remote driver URIs into URI docs
   docs: introduce rst2html as a mandatory tool for building docs
   docs: adapt filling of  section for rst2html output
   docs: generate permalinks correctly for rst2html output
   docs: relax CSS context match for pretty tables
   docs: add styling for  element
   docs: add a minimal style guide for writing RST docs
   docs: convert kbase/domainstatecapture.html.in to RST
   docs: convert kbase/launch_security_sev.html.in to RST
   docs: convert kbase/secureusage.html.in to RST
   docs: convert kbase/locking.html.in to RST
   docs: convert kbase/locking-lockd.html.in to RST
   docs: convert kbase/locking-sanlock.html.in to RST
   docs: add a kbase page about RPM packaging options

  docs/Makefile.am   |  33 +-
  docs/aclpolkit.html.in |  20 +-
  docs/docs.html.in  |   6 +
  docs/genaclperms.pl|   2 +-
  docs/generic.css   |   4 +-
  docs/kbase.html.in |   4 +
  docs/kbase/domainstatecapture.html.in  | 303 ---
  docs/kbase/domainstatecapture.rst  | 255 +
  docs/kbase/launch_security_sev.html.in | 533 ---
  docs/kbase/launch_security_sev.rst | 529 +++
  docs/kbase/locking-lockd.html.in   | 160 --
  docs/kbase/locking-lockd.rst   | 121 +
  docs/kbase/locking-sanlock.html.in | 247 -
  docs/kbase/locking-sanlock.rst | 193 +++
  docs/kbase/locking.html.in |  48 --
  docs/kbase/locking.rst |  33 ++
  docs/kbase/rpm-deployment.rst  | 410 +++
  docs/kbase/secureusage.html.in | 171 ---
  docs/kbase/secureusage.rst | 131 +
  docs/libvirt.css   |  76 +--
  docs/migration.html.in |   2 +-
  docs/newapi.xsl|   4 +-
  docs/page.xsl  |   9 +-
  docs/remote.html.in| 684 +
  docs/styleguide.rst|  66 +++
  docs/tlscerts.html.in  | 413 +++
  docs/uri.html.in   | 263 --
  libvirt.spec.in|   2 +
  m4/virt-external-programs.m4   |   5 +
  mingw-libvirt.spec.in  |   1 +
  30 files changed, 2478 insertions(+), 2250 deletions(-)
  delete mode 100644 docs/kbase/domainstatecapture.html.in
  create mode 100644 docs/kbase/domainstatecapture.rst
  delete mode 100644 docs/kbase/launch_security_sev.html.in
  create mode 100644 docs/kbase/launch_security_sev.rst
  delete mode 100644 

Re: [libvirt] [PATCH v2 25/25] qemu: Add support for VIR_DOMAIN_CAPS_FEATURE_BACKUP

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:47PM +0100, Peter Krempa wrote:
> Signed-off-by: Peter Krempa 
> ---
>  src/qemu/qemu_capabilities.c  | 1 +
>  tests/domaincapsdata/qemu_1.5.3-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_1.5.3-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_1.5.3.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_1.6.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_1.6.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_1.6.0.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_1.7.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_1.7.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_1.7.0.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.1.1-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.1.1-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.1.1.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.10.0-q35.x86_64.xml   | 1 +
>  tests/domaincapsdata/qemu_2.10.0-tcg.x86_64.xml   | 1 +
>  tests/domaincapsdata/qemu_2.10.0-virt.aarch64.xml | 1 +
>  tests/domaincapsdata/qemu_2.10.0.aarch64.xml  | 1 +
>  tests/domaincapsdata/qemu_2.10.0.ppc64.xml| 1 +
>  tests/domaincapsdata/qemu_2.10.0.s390x.xml| 1 +
>  tests/domaincapsdata/qemu_2.10.0.x86_64.xml   | 1 +
>  tests/domaincapsdata/qemu_2.11.0-q35.x86_64.xml   | 1 +
>  tests/domaincapsdata/qemu_2.11.0-tcg.x86_64.xml   | 1 +
>  tests/domaincapsdata/qemu_2.11.0.s390x.xml| 1 +
>  tests/domaincapsdata/qemu_2.11.0.x86_64.xml   | 1 +
>  tests/domaincapsdata/qemu_2.12.0-q35.x86_64.xml   | 1 +
>  tests/domaincapsdata/qemu_2.12.0-tcg.x86_64.xml   | 1 +
>  tests/domaincapsdata/qemu_2.12.0-virt.aarch64.xml | 1 +
>  tests/domaincapsdata/qemu_2.12.0.aarch64.xml  | 1 +
>  tests/domaincapsdata/qemu_2.12.0.ppc64.xml| 1 +
>  tests/domaincapsdata/qemu_2.12.0.s390x.xml| 1 +
>  tests/domaincapsdata/qemu_2.12.0.x86_64.xml   | 1 +
>  tests/domaincapsdata/qemu_2.4.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.4.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.4.0.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.5.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.5.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.5.0.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.6.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.6.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.6.0-virt.aarch64.xml  | 1 +
>  tests/domaincapsdata/qemu_2.6.0.aarch64.xml   | 1 +
>  tests/domaincapsdata/qemu_2.6.0.ppc64.xml | 1 +
>  tests/domaincapsdata/qemu_2.6.0.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.7.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.7.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.7.0.s390x.xml | 1 +
>  tests/domaincapsdata/qemu_2.7.0.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.8.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.8.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.8.0.s390x.xml | 1 +
>  tests/domaincapsdata/qemu_2.8.0.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.9.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.9.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_2.9.0.ppc64.xml | 1 +
>  tests/domaincapsdata/qemu_2.9.0.s390x.xml | 1 +
>  tests/domaincapsdata/qemu_2.9.0.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_3.0.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_3.0.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_3.0.0.ppc64.xml | 1 +
>  tests/domaincapsdata/qemu_3.0.0.s390x.xml | 1 +
>  tests/domaincapsdata/qemu_3.0.0.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_3.1.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_3.1.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_3.1.0.ppc64.xml | 1 +
>  tests/domaincapsdata/qemu_3.1.0.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_4.0.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_4.0.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_4.0.0-virt.aarch64.xml  | 1 +
>  tests/domaincapsdata/qemu_4.0.0.aarch64.xml   | 1 +
>  tests/domaincapsdata/qemu_4.0.0.ppc64.xml | 1 +
>  tests/domaincapsdata/qemu_4.0.0.s390x.xml | 1 +
>  tests/domaincapsdata/qemu_4.0.0.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_4.1.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_4.1.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_4.1.0.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_4.2.0-q35.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_4.2.0-tcg.x86_64.xml| 1 +
>  tests/domaincapsdata/qemu_4.2.0-virt.aarch64.xml  | 1 +
>  tests/domaincapsdata/qemu_4.2.0.aarch64.xml   | 1 +
>  tests/domaincapsdata/qemu_4.2.0.ppc64.xml | 1 +
>  tests/domaincapsdata/qemu_4.2.0.s390x.xml | 1 +
>  tests/domaincapsdata/qemu_4.2.0.x86_64.xml| 1 +
>  82 files changed, 82 insertions(+)

Reviewed-by: Daniel P. 

Re: [libvirt] [PATCH v2 24/25] conf: domaincaps: Add 'backup' feature flag

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:46PM +0100, Peter Krempa wrote:
> This flag will allow figuring out whether the hypervisor supports the
> incremental backup and checkpoint features.
> 
> Signed-off-by: Peter Krempa 
> ---
>  docs/formatdomaincaps.html.in  | 8 
>  docs/schemas/domaincaps.rng| 9 +
>  src/conf/domain_capabilities.c | 1 +
>  src/conf/domain_capabilities.h | 1 +
>  4 files changed, 19 insertions(+)

Reviewed-by: Daniel P. Berrangé 


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 v2 22/25] qemu: driver: Allow cancellation of the backup job

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:44PM +0100, Peter Krempa wrote:
> Use the helper which cancels all blockjobs to perform the backup job
> cancellation in qemuDomainAbortJob.
> 
> Signed-off-by: Peter Krempa 
> ---
>  src/qemu/qemu_driver.c | 15 ++-
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 95882d9d14..2408b08106 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -14054,11 +14054,16 @@ static int qemuDomainAbortJob(virDomainPtr dom)
>  }
> 
>  VIR_DEBUG("Cancelling job at client request");
> -qemuDomainObjAbortAsyncJob(vm);
> -qemuDomainObjEnterMonitor(driver, vm);
> -ret = qemuMonitorMigrateCancel(priv->mon);
> -if (qemuDomainObjExitMonitor(driver, vm) < 0)
> -ret = -1;
> +if (priv->job.asyncJob == QEMU_ASYNC_JOB_BACKUP) {
> +qemuBackupJobCancelBlockjobs(vm, priv->backup, true);
> +ret = 0;
> +} else {
> +qemuDomainObjAbortAsyncJob(vm);
> +qemuDomainObjEnterMonitor(driver, vm);
> +ret = qemuMonitorMigrateCancel(priv->mon);
> +if (qemuDomainObjExitMonitor(driver, vm) < 0)
> +ret = -1;
> +}

Hmm, this makes me thing we should have had some better error checking
in here already. IIUC, we have other types async job that are not
related to either migration or backups, so should we do

   switch (priv->job.asyncJob) {
case QEMU_ASYNC_JOB_BACKUP:
   ...
case QEMU_ASYNC_JOB_MIGRATE:
   ...
case QEMU_ASYNC_JOB
default:
  report error
   }

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] tests: stop static linking to libvirt code in tests

2019-12-04 Thread Michal Privoznik

On 12/3/19 4:25 PM, Daniel P. Berrangé wrote:

If we static link to libvirt_util.la then we can't override functions in
this file by simply implementing them in the test code. Any tests should
dynamic link to the main libvirt.la and ensure symbols are exported.

Signed-off-by: Daniel P. Berrangé 
---
  src/libvirt_private.syms |  2 ++
  tests/Makefile.am| 11 +++
  2 files changed, 5 insertions(+), 8 deletions(-)


Reviewed-by: Michal Privoznik 

Michal

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

Re: [libvirt] [PATCH v2 19/25] doc: Document quirk of getting block job info for a 'backup' blockjob

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:41PM +0100, Peter Krempa wrote:
> The stats reported for a blockjob which is member of a domain pull
> backup refer to the utilization of the scratch file rather than the
> progress of the backup as the progress of the backup depends on the
> client. Note this quirk in the docs.
> 
> Signed-off-by: Peter Krempa 
> ---
>  src/libvirt-domain.c | 4 
>  tools/virsh.pod  | 4 
>  2 files changed, 8 insertions(+)

Reviewed-by: Daniel P. Berrangé 


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 v2 18/25] conf: backup: Add fields for tracking stats of completed sub-jobs

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:40PM +0100, Peter Krempa wrote:
> We need a place to store stats of completed sub-jobs so that we can
> later report accurate stats.

Its kind of gross using the public struct for internal only data
but I guess we can fix that any time we want to later.

> 
> Signed-off-by: Peter Krempa 
> ---
>  src/conf/backup_conf.h | 7 +++
>  1 file changed, 7 insertions(+)

Reviewed-by: Daniel P. Berrangé 

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 v2 17/25] tests: qemustatusxml2xml: Add test for 'pull' type backup job

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:39PM +0100, Peter Krempa wrote:
> Signed-off-by: Peter Krempa 
> ---
>  .../qemustatusxml2xmldata/backup-pull-in.xml  | 608 ++
>  .../qemustatusxml2xmldata/backup-pull-out.xml |   1 +
>  tests/qemuxml2xmltest.c   |   2 +
>  3 files changed, 611 insertions(+)
>  create mode 100644 tests/qemustatusxml2xmldata/backup-pull-in.xml
>  create mode 12 tests/qemustatusxml2xmldata/backup-pull-out.xml

Reviewed-by: Daniel P. Berrangé 


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 v2 16/25] qemu: blockjob: Track internal data for 'backup' blockjob

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:38PM +0100, Peter Krempa wrote:
> A backup blockjob needs to be able to notify the parent backup job as
> well as track all data to be able to clean up the bitmap and blockdev
> used for the backup.
> 
> Add the data structure, job allocation function and status XML formatter
> and parser.
> 
> Signed-off-by: Peter Krempa 
> ---
>  src/qemu/qemu_blockjob.c | 34 +-
>  src/qemu/qemu_blockjob.h | 18 ++
>  src/qemu/qemu_domain.c   | 21 +
>  3 files changed, 72 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé 


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 v2 15/25] qemu: domain: Track backup job data in the status XML

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:37PM +0100, Peter Krempa wrote:
> Store the data of a backup job along with the index counter for new
> backup jobs in the status XML. Currently we will support only one
> backup job and thus there's no necessity to add arrays of jobs.
> 
> Signed-off-by: Peter Krempa 
> ---
>  src/qemu/qemu_domain.c | 58 ++
>  src/qemu/qemu_domain.h |  3 +++
>  2 files changed, 61 insertions(+)

Reviewed-by: Daniel P. Berrangé 


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] scripts: fix list indexing when printing mis-ordered symbols

2019-12-04 Thread Michal Privoznik

On 12/3/19 6:15 PM, Daniel P. Berrangé wrote:

The python array slice syntax expects the first and last indexes,
not the first length and element count.

Signed-off-by: Daniel P. Berrangé 
---
  scripts/check-symsorting.py | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)


Reviewed-by: Michal Privoznik 

Michal

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

Re: [libvirt] [PATCH v2 14/25] qemu: monitor: Add support for blockdev-backup via 'transaction'

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:36PM +0100, Peter Krempa wrote:
> Implement the transaction actions generator for blockdev-backup.
> 
> Signed-off-by: Peter Krempa 
> ---
>  src/qemu/qemu_monitor.c  | 13 +
>  src/qemu/qemu_monitor.h  | 15 +++
>  src/qemu/qemu_monitor_json.c | 29 +
>  src/qemu/qemu_monitor_json.h |  8 
>  tests/qemumonitorjsontest.c  |  8 +++-
>  5 files changed, 72 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé 


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 v2 13/25] Add 'backup' block job type

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:35PM +0100, Peter Krempa wrote:
> A backup job may consist of many backup sub-blockjobs. Add the new
> blockjob type and add all type converter strings.
> 
> Signed-off-by: Peter Krempa 
> ---
>  examples/c/misc/event-test.c | 3 +++
>  include/libvirt/libvirt-domain.h | 3 +++
>  src/conf/domain_conf.c   | 2 +-
>  src/qemu/qemu_blockjob.c | 3 +++
>  src/qemu/qemu_blockjob.h | 1 +
>  src/qemu/qemu_domain.c   | 4 
>  src/qemu/qemu_driver.c   | 1 +
>  src/qemu/qemu_monitor_json.c | 4 
>  tools/virsh-domain.c | 4 +++-
>  9 files changed, 23 insertions(+), 2 deletions(-)

Reviewed-by: Daniel P. Berrangé 


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 v2 12/25] qemu: domain: Introduce QEMU_ASYNC_JOB_BACKUP async job type

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:34PM +0100, Peter Krempa wrote:
> We will want to use the async job infrastructure along with all the APIs
> and event for the backup job so add the backup job as a new async job
> type.
> 
> Signed-off-by: Peter Krempa 
> ---
>  src/qemu/qemu_domain.c|  3 +++
>  src/qemu/qemu_domain.h|  1 +
>  src/qemu/qemu_migration.c |  2 ++
>  src/qemu/qemu_process.c   | 25 +
>  4 files changed, 31 insertions(+)

Reviewed-by: Daniel P. Berrangé 


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 v2 11/25] qemu: Add infrastructure for statistics of a backup job

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:33PM +0100, Peter Krempa wrote:
> Introduce QEMU_DOMAIN_JOB_STATS_TYPE_BACKUP and the convertors and other
> plumbing to be able to report statistics for the backup job.
> 
> Signed-off-by: Peter Krempa 
> ---
>  src/qemu/qemu_domain.c | 62 ++
>  src/qemu/qemu_domain.h | 10 +++
>  src/qemu/qemu_driver.c |  4 +++
>  3 files changed, 76 insertions(+)

Reviewed-by: Daniel P. Berrangé 


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] [python PATCH] Drop support for python 2

2019-12-04 Thread Michal Privoznik

On 12/4/19 11:41 AM, Daniel P. Berrangé wrote:

Signed-off-by: Daniel P. Berrangé 
---
  examples/consolecallback.py   |   2 +-
  examples/dhcpleases.py|   2 +-
  examples/dominfo.py   |   2 +-
  examples/domipaddrs.py|   2 +-
  examples/domrestore.py|   2 +-
  examples/domsave.py   |   2 +-
  examples/domstart.py  |   2 +-
  examples/esxlist.py   |   2 +-
  examples/event-test.py|   2 +-
  examples/guest-vcpus/guest-vcpu-daemon.py |   2 +-
  examples/guest-vcpus/guest-vcpu.py|   2 +-
  examples/nodestats.py |   2 +-
  examples/sparsestream.py  |   2 +-
  examples/topology.py  |   2 +-
  generator.py  |   2 +-
  libvirt-lxc-override.c|  51 ++---
  libvirt-override.c|  51 ++---
  libvirt-python.spec.in|  96 +---
  libvirt-qemu-override.c   |  51 ++---
  libvirt-utils.c   |  17 +--
  libvirt-utils.h   |   6 +-
  sanitytest.py |   2 +-
  setup.py  |   9 +-
  typewrappers.c| 133 +++---
  typewrappers.h|   5 -
  25 files changed, 71 insertions(+), 380 deletions(-)


Reviewed-by: Michal Privoznik 

Michal

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

Re: [libvirt] [PATCH v2 10/25] backup: Implement virsh support for backup

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:32PM +0100, Peter Krempa wrote:
> From: Eric Blake 
> 
> Introduce virsh commands for performing backup jobs.
> 
> Signed-off-by: Eric Blake 
> Signed-off-by: Peter Krempa 
> ---
>  po/POTFILES.in   |   1 +
>  tools/Makefile.am|   1 +
>  tools/virsh-backup.c | 151 +++
>  tools/virsh-backup.h |  21 ++
>  tools/virsh.c|   2 +
>  tools/virsh.h|   1 +
>  tools/virsh.pod  |  31 +
>  7 files changed, 208 insertions(+)
>  create mode 100644 tools/virsh-backup.c
>  create mode 100644 tools/virsh-backup.h

Reviewed-by: Daniel P. Berrangé 


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] build: only support python3 binary

2019-12-04 Thread Michal Privoznik

On 12/4/19 11:14 AM, Daniel P. Berrangé wrote:

python2 will be end of life by the time of the next
libvirt release. All our supported build targets, including
CentOS7, have a python3 build available.

Signed-off-by: Daniel P. Berrangé 
---
  configure.ac |  4 ++--
  docs/apibuild.py |  4 +---
  docs/reformat-news.py|  4 +---
  libvirt.spec.in  | 10 +-
  scripts/augeas-gentest.py|  4 +---
  scripts/check-aclperms.py|  4 +---
  scripts/check-aclrules.py|  4 +---
  scripts/check-driverimpls.py |  4 +---
  scripts/check-drivername.py  |  4 +---
  scripts/check-symfile.py |  4 +---
  scripts/check-symsorting.py  |  4 +---
  scripts/dtrace2systemtap.py  |  4 +---
  scripts/genpolkit.py |  4 +---
  scripts/gensystemtap.py  |  4 +---
  scripts/header-ifdef.py  |  4 +---
  scripts/minimize-po.py   |  4 +---
  scripts/mock-noinline.py |  4 +---
  scripts/prohibit-duplicate-header.py |  4 +---
  src/esx/esx_vi_generator.py  |  4 +---
  src/hyperv/hyperv_wmi_generator.py   |  4 +---
  tests/cputestdata/cpu-gather.sh  |  9 +
  21 files changed, 22 insertions(+), 73 deletions(-)


Reviewed-by: Michal Privoznik 

Michal

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

Re: [libvirt] [PATCH v2 09/25] tests: genericxml2xml: Add testing of backup XML files

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:31PM +0100, Peter Krempa wrote:
> Now that the parser and formatter are in place we can excercise it on
> the test files.
> 
> Signed-off-by: Peter Krempa 
> ---
>  tests/Makefile.am |  1 +
>  .../backup-pull-seclabel.xml  | 18 
>  tests/domainbackupxml2xmlout/backup-pull.xml  | 10 
>  .../backup-push-seclabel.xml  | 17 +++
>  tests/domainbackupxml2xmlout/backup-push.xml  | 10 
>  tests/domainbackupxml2xmlout/empty.xml|  1 +
>  tests/genericxml2xmltest.c| 46 +++
>  tests/virschematest.c |  3 +-
>  8 files changed, 105 insertions(+), 1 deletion(-)
>  create mode 100644 tests/domainbackupxml2xmlout/backup-pull-seclabel.xml
>  create mode 100644 tests/domainbackupxml2xmlout/backup-pull.xml
>  create mode 100644 tests/domainbackupxml2xmlout/backup-push-seclabel.xml
>  create mode 100644 tests/domainbackupxml2xmlout/backup-push.xml
>  create mode 100644 tests/domainbackupxml2xmlout/empty.xml

Reviewed-by: Daniel P. Berrangé 


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 v2 08/25] backup: Parse and output backup XML

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:30PM +0100, Peter Krempa wrote:
> From: Eric Blake 
> 
> Accept XML describing a generic block job, and output it again as
> needed. This may still need a few tweaks to match the documented XML
> and RNG schema.
> 
> Signed-off-by: Eric Blake 
> ---
>  po/POTFILES.in   |   1 +
>  src/conf/Makefile.inc.am |   2 +
>  src/conf/backup_conf.c   | 499 +++
>  src/conf/backup_conf.h   | 101 
>  src/conf/virconftypes.h  |   3 +
>  src/libvirt_private.syms |   8 +
>  6 files changed, 614 insertions(+)
>  create mode 100644 src/conf/backup_conf.c
>  create mode 100644 src/conf/backup_conf.h

Reviewed-by: Daniel P. Berrangé 


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 v2 07/25] backup: Implement backup APIs for remote driver

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:29PM +0100, Peter Krempa wrote:
> From: Eric Blake 
> 
> This one is fairly straightforward - the generator already does what
> we need.
> 
> Signed-off-by: Eric Blake 
> Signed-off-by: Peter Krempa 
> ---
>  src/remote/remote_driver.c   |  2 ++
>  src/remote/remote_protocol.x | 33 -
>  src/remote_protocol-structs  | 15 +++
>  3 files changed, 49 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé 


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 v2 06/25] API: Add domain job operation for backups

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:28PM +0100, Peter Krempa wrote:
> Introduce VIR_DOMAIN_JOB_OPERATION_BACKUP into virDomainJobOperation.
> 
> Signed-off-by: Peter Krempa 
> ---
>  include/libvirt/libvirt-domain.h | 1 +
>  tools/virsh-domain.c | 4 +++-
>  2 files changed, 4 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé 


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 v2 05/25] backup: Introduce virDomainBackup APIs

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:27PM +0100, Peter Krempa wrote:
> From: Eric Blake 
> 
> Introduce a few new public APIs related to incremental backups.  This
> builds on the previous notion of a checkpoint (without an existing
> checkpoint, the new API is a full backup, differing from
> virDomainBlockCopy in the point of time chosen and in operation on
> multiple disks at once); and also allows creation of a new checkpoint
> at the same time as starting the backup (after all, an incremental
> backup is only useful if it covers the state since the previous
> backup).
> 
> A backup job also affects filtering a listing of domains, as well as
> adding event reporting for signaling when a push model backup
> completes (where the hypervisor creates the backup); note that the
> pull model does not have an event (starting the backup lets a third
> party access the data, and only the third party knows when it is
> finished).
> 
> The full list of new APIs:
> virDomainBackupBegin;
> virDomainBackupGetXMLDesc;
> 
> Signed-off-by: Eric Blake 
> Signed-off-by: Peter Krempa 
> ---
>  include/libvirt/libvirt-domain.h |  19 +++-
>  src/driver-hypervisor.h  |  12 +++
>  src/libvirt-domain-checkpoint.c  |   7 +-
>  src/libvirt-domain.c | 143 +++
>  src/libvirt_public.syms  |   6 ++
>  5 files changed, 183 insertions(+), 4 deletions(-)

Reviewed-by: Daniel P. Berrangé 


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 v2 00/15] docs: some refactoring and new docs about RPM deployment

2019-12-04 Thread Daniel P . Berrangé
ping

On Fri, Nov 22, 2019 at 02:46:47PM +, Daniel P. Berrangé wrote:
> This refactors existing docs related to the remote driver/daemon and
> URIs. It then also adds a kbase page about RPM package options.
> 
> This introduces the use of RST for docs as a replacement for HTML.
> The intent is that all new docs should use RST from this point.
> The POD man pages will also be converted to RST. I'll post this as
> a different series.
> 
> Note this series only touches the main HTML content, not the
> styling / templating using XSL. Tackling that is a separate
> job I've not attempted. My guess is that we'd use either Sphinx
> or Pelican to do the templating.
> 
> Existing HTML docs are candidates for conversion to RST, however,
> people should *NOT* attempt todo this manually.
> 
> In this series I've converted docs/kbase/ files, using the pandoc
> tool. This does a pretty good job in general but does need some
> manual cleanups. First I post-processed its output to change the
> heading highlighting to follow the documented style
> 
> $ cat convert.pl
> 
> my @in = <>;
> 
> my @out;
> for (my $i ; $i <= $#in; $i++) {
> my $line = $in[$i];
> if ($line =~ /^=+$/) {
> my @newout = splice @out, 0, $i - 1;
> push @newout, $line;
> push @newout, $out[$i-1];
> push @newout, $out[$i];
> push @newout, $line;
> push @newout, "\n";
> push @newout, ".. contents::\n";
> @out = @newout;
> } elsif ($line =~ /^(-|~|^|')+$/) {
> $line =~ s/-/=/g;
> $line =~ s/~/-/g;
> $line =~ s/\^/~/g;
> $line =~ s/'/^/g;
> push @out, $line;
> } else {
> push @out, $line;
> }
> }
> 
> print @out;
> 
> So I'm converting with
> 
>   pandoc -f html -t rst < foo.html.in | perl convert.pl > foo.rst
>   $EDITOR foot.rst
>   git rm -f foot.html.in
>   git add foo.rst
> 
> After pandoc & the headings convert, there's usually manual fixes
> needed to deal with a few oddities pandoc gets wrong, or looks
> ugly. This is still way simpler than converting the doc to rst
> manually.
> 
> Changed in v2:
> 
>  - Added a style guide for RST docs
>  - Probe for rst2html's different names
>  - Added make rules for building rst
>  - Fixed permalinks in generated docs
>  - Misc CSS fixes
>  - Auto-converted all of kbase/ directory
> 
> Daniel P. Berrangé (15):
>   docs: split TLS certificate setup into its own file
>   docs: move docs about remote driver URIs into URI docs
>   docs: introduce rst2html as a mandatory tool for building docs
>   docs: adapt filling of  section for rst2html output
>   docs: generate permalinks correctly for rst2html output
>   docs: relax CSS context match for pretty tables
>   docs: add styling for  element
>   docs: add a minimal style guide for writing RST docs
>   docs: convert kbase/domainstatecapture.html.in to RST
>   docs: convert kbase/launch_security_sev.html.in to RST
>   docs: convert kbase/secureusage.html.in to RST
>   docs: convert kbase/locking.html.in to RST
>   docs: convert kbase/locking-lockd.html.in to RST
>   docs: convert kbase/locking-sanlock.html.in to RST
>   docs: add a kbase page about RPM packaging options
> 
>  docs/Makefile.am   |  33 +-
>  docs/aclpolkit.html.in |  20 +-
>  docs/docs.html.in  |   6 +
>  docs/genaclperms.pl|   2 +-
>  docs/generic.css   |   4 +-
>  docs/kbase.html.in |   4 +
>  docs/kbase/domainstatecapture.html.in  | 303 ---
>  docs/kbase/domainstatecapture.rst  | 255 +
>  docs/kbase/launch_security_sev.html.in | 533 ---
>  docs/kbase/launch_security_sev.rst | 529 +++
>  docs/kbase/locking-lockd.html.in   | 160 --
>  docs/kbase/locking-lockd.rst   | 121 +
>  docs/kbase/locking-sanlock.html.in | 247 -
>  docs/kbase/locking-sanlock.rst | 193 +++
>  docs/kbase/locking.html.in |  48 --
>  docs/kbase/locking.rst |  33 ++
>  docs/kbase/rpm-deployment.rst  | 410 +++
>  docs/kbase/secureusage.html.in | 171 ---
>  docs/kbase/secureusage.rst | 131 +
>  docs/libvirt.css   |  76 +--
>  docs/migration.html.in |   2 +-
>  docs/newapi.xsl|   4 +-
>  docs/page.xsl  |   9 +-
>  docs/remote.html.in| 684 +
>  docs/styleguide.rst|  66 +++
>  docs/tlscerts.html.in  | 413 +++
>  docs/uri.html.in   | 263 --
>  libvirt.spec.in|   2 +
>  m4/virt-external-programs.m4   |   5 +
>  mingw-libvirt.spec.in  |   1 +
>  30 files changed, 2478 insertions(+), 2250 deletions(-)
>  delete mode 100644 docs/kbase/domainstatecapture.html.in
>  create mode 

Re: [libvirt] [PATCH v2 04/25] backup: Document new XML for backups

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:26PM +0100, Peter Krempa wrote:
> From: Eric Blake 
> 
> Prepare for new backup APIs by describing the XML that will represent
> a backup.  The XML resembles snapshots and checkpoints in being able
> to select actions for a set of disks, but has other differences.  It
> can support both push model (the hypervisor does the backup directly
> into the destination file) and pull model (the hypervisor exposes an
> access port for a third party to grab what is necessary).  Add
> testsuite coverage for some minimal uses of the XML.
> 
> The  element within  tries to model the same
> elements as a  under , but sharing the RNG grammar
> proved to be hairy. That is in part because while  use
>  to describe a host resource in use by the guest, a backup job
> is using a host resource that is not visible to the guest: a push
> backup action is instead describing a  (which ultimately could
> be a remote network resource, but for simplicity the RNG just
> validates a local file for now), and a pull backup action is instead
> describing a temporary local file  (which probably should not
> be a remote resource).  A future refactoring may thus introduce some
> way to parameterize RNG to accept ... so that
> the name of the subelement can be  for domain, or  or
>  as needed for backups. Future patches may improve this area
> of code.
> 
> Signed-off-by: Eric Blake 
> Signed-off-by: Peter Krempa 
> ---
>  docs/docs.html.in |   3 +-
>  docs/format.html.in   |   1 +
>  docs/formatbackup.html.in | 175 ++
>  docs/formatcheckpoint.html.in |  12 +-
>  docs/index.html.in|   3 +-
>  docs/schemas/domainbackup.rng | 223 ++
>  libvirt.spec.in   |   1 +
>  mingw-libvirt.spec.in |   2 +
>  tests/Makefile.am |   1 +
>  .../backup-pull-seclabel.xml  |  18 ++
>  tests/domainbackupxml2xmlin/backup-pull.xml   |  10 +
>  .../backup-push-seclabel.xml  |  17 ++
>  tests/domainbackupxml2xmlin/backup-push.xml   |  10 +
>  tests/domainbackupxml2xmlin/empty.xml |   1 +
>  tests/virschematest.c |   1 +
>  15 files changed, 470 insertions(+), 8 deletions(-)
>  create mode 100644 docs/formatbackup.html.in
>  create mode 100644 docs/schemas/domainbackup.rng
>  create mode 100644 tests/domainbackupxml2xmlin/backup-pull-seclabel.xml
>  create mode 100644 tests/domainbackupxml2xmlin/backup-pull.xml
>  create mode 100644 tests/domainbackupxml2xmlin/backup-push-seclabel.xml
>  create mode 100644 tests/domainbackupxml2xmlin/backup-push.xml
>  create mode 100644 tests/domainbackupxml2xmlin/empty.xml

Reviewed-by: Daniel P. Berrangé 


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 v2 01/25] qemu: domain: Export qemuDomainGetImageIds

2019-12-04 Thread Daniel P . Berrangé
On Tue, Dec 03, 2019 at 06:17:23PM +0100, Peter Krempa wrote:
> Signed-off-by: Peter Krempa 
> ---
>  src/qemu/qemu_domain.c | 2 +-
>  src/qemu/qemu_domain.h | 7 +++
>  2 files changed, 8 insertions(+), 1 deletion(-)

Reviewed-by: Daniel P. Berrangé 


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

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

[libvirt] [python PATCH] Drop support for python 2

2019-12-04 Thread Daniel P . Berrangé
Signed-off-by: Daniel P. Berrangé 
---
 examples/consolecallback.py   |   2 +-
 examples/dhcpleases.py|   2 +-
 examples/dominfo.py   |   2 +-
 examples/domipaddrs.py|   2 +-
 examples/domrestore.py|   2 +-
 examples/domsave.py   |   2 +-
 examples/domstart.py  |   2 +-
 examples/esxlist.py   |   2 +-
 examples/event-test.py|   2 +-
 examples/guest-vcpus/guest-vcpu-daemon.py |   2 +-
 examples/guest-vcpus/guest-vcpu.py|   2 +-
 examples/nodestats.py |   2 +-
 examples/sparsestream.py  |   2 +-
 examples/topology.py  |   2 +-
 generator.py  |   2 +-
 libvirt-lxc-override.c|  51 ++---
 libvirt-override.c|  51 ++---
 libvirt-python.spec.in|  96 +---
 libvirt-qemu-override.c   |  51 ++---
 libvirt-utils.c   |  17 +--
 libvirt-utils.h   |   6 +-
 sanitytest.py |   2 +-
 setup.py  |   9 +-
 typewrappers.c| 133 +++---
 typewrappers.h|   5 -
 25 files changed, 71 insertions(+), 380 deletions(-)

diff --git a/examples/consolecallback.py b/examples/consolecallback.py
index c539a92..1347384 100644
--- a/examples/consolecallback.py
+++ b/examples/consolecallback.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # consolecallback - provide a persistent console that survives guest reboots
 
 import sys, os, logging, libvirt, tty, termios, atexit
diff --git a/examples/dhcpleases.py b/examples/dhcpleases.py
index da51f52..f394541 100755
--- a/examples/dhcpleases.py
+++ b/examples/dhcpleases.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # netdhcpleases - print leases info for given virtual network
 
 import libvirt
diff --git a/examples/dominfo.py b/examples/dominfo.py
index d3049cd..0a39f4c 100755
--- a/examples/dominfo.py
+++ b/examples/dominfo.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # dominfo - print some information about a domain
 
 import libvirt
diff --git a/examples/domipaddrs.py b/examples/domipaddrs.py
index d6d5cac..bda308c 100755
--- a/examples/domipaddrs.py
+++ b/examples/domipaddrs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # domipaddrs - print domain interfaces along with their MAC and IP addresses
 
 import libvirt
diff --git a/examples/domrestore.py b/examples/domrestore.py
index 06fdfbc..96f4955 100755
--- a/examples/domrestore.py
+++ b/examples/domrestore.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # domstart - make sure a given domU is running, if not start it
 
 import libvirt
diff --git a/examples/domsave.py b/examples/domsave.py
index 727217c..4940cce 100755
--- a/examples/domsave.py
+++ b/examples/domsave.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # domstart - make sure a given domU is running, if not start it
 
 import libvirt
diff --git a/examples/domstart.py b/examples/domstart.py
index ce1b60c..7ff6cb9 100755
--- a/examples/domstart.py
+++ b/examples/domstart.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # domstart - make sure a given domU is running, if not start it
 
 import libvirt
diff --git a/examples/esxlist.py b/examples/esxlist.py
index 0d47b00..d86e064 100755
--- a/examples/esxlist.py
+++ b/examples/esxlist.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # esxlist - list active domains of an ESX host and print some info.
 #   also demonstrates how to use the libvirt.openAuth() method
 
diff --git a/examples/event-test.py b/examples/event-test.py
index 4458e22..fddef64 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 #
 #
diff --git a/examples/guest-vcpus/guest-vcpu-daemon.py 
b/examples/guest-vcpus/guest-vcpu-daemon.py
index c7c08a8..30fcb9c 100755
--- a/examples/guest-vcpus/guest-vcpu-daemon.py
+++ b/examples/guest-vcpus/guest-vcpu-daemon.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import libvirt
 import threading
diff --git a/examples/guest-vcpus/guest-vcpu.py 
b/examples/guest-vcpus/guest-vcpu.py
index 8faba87..479ec40 100755
--- a/examples/guest-vcpus/guest-vcpu.py
+++ b/examples/guest-vcpus/guest-vcpu.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import libvirt
 import sys
diff --git a/examples/nodestats.py b/examples/nodestats.py
index c01dead..ae2a442 100755
--- a/examples/nodestats.py
+++ b/examples/nodestats.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 # Print some host NUMA node statistics
 #
 # Authors:

[libvirt] [PATCH] build: only support python3 binary

2019-12-04 Thread Daniel P . Berrangé
python2 will be end of life by the time of the next
libvirt release. All our supported build targets, including
CentOS7, have a python3 build available.

Signed-off-by: Daniel P. Berrangé 
---
 configure.ac |  4 ++--
 docs/apibuild.py |  4 +---
 docs/reformat-news.py|  4 +---
 libvirt.spec.in  | 10 +-
 scripts/augeas-gentest.py|  4 +---
 scripts/check-aclperms.py|  4 +---
 scripts/check-aclrules.py|  4 +---
 scripts/check-driverimpls.py |  4 +---
 scripts/check-drivername.py  |  4 +---
 scripts/check-symfile.py |  4 +---
 scripts/check-symsorting.py  |  4 +---
 scripts/dtrace2systemtap.py  |  4 +---
 scripts/genpolkit.py |  4 +---
 scripts/gensystemtap.py  |  4 +---
 scripts/header-ifdef.py  |  4 +---
 scripts/minimize-po.py   |  4 +---
 scripts/mock-noinline.py |  4 +---
 scripts/prohibit-duplicate-header.py |  4 +---
 src/esx/esx_vi_generator.py  |  4 +---
 src/hyperv/hyperv_wmi_generator.py   |  4 +---
 tests/cputestdata/cpu-gather.sh  |  9 +
 21 files changed, 22 insertions(+), 73 deletions(-)

diff --git a/configure.ac b/configure.ac
index 76d28d2f67..2e5af075ea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -701,9 +701,9 @@ if test "$with_linux" = "yes"; then
 fi
 
 dnl Allow perl/python overrides
-AC_PATH_PROGS([PYTHON], [python3 python2 python])
+AC_PATH_PROGS([PYTHON], [python3])
 if test -z "$PYTHON"; then
-AC_MSG_ERROR(['python3', 'python2' or 'python' binary is required to build 
libvirt])
+AC_MSG_ERROR(['python3' binary is required to build libvirt])
 fi
 AC_PATH_PROG([FLAKE8], [flake8])
 if test -z "$FLAKE8"; then
diff --git a/docs/apibuild.py b/docs/apibuild.py
index 5a0224c1c6..2f7314b379 100755
--- a/docs/apibuild.py
+++ b/docs/apibuild.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # This is the API builder, it parses the C sources and build the
 # API formal description in XML.
@@ -8,8 +8,6 @@
 # dan...@veillard.com
 #
 
-from __future__ import print_function
-
 import os
 import sys
 import glob
diff --git a/docs/reformat-news.py b/docs/reformat-news.py
index a06f945c02..7bc752d821 100755
--- a/docs/reformat-news.py
+++ b/docs/reformat-news.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 # reformat-news.py: Reformat the NEWS file properly
 #
@@ -18,8 +18,6 @@
 # License along with this library.  If not, see
 # .
 
-from __future__ import print_function
-
 import sys
 
 COLUMNS = 80
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 4c6161a26f..72ed2fd96b 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -188,14 +188,6 @@
 
 %define with_bash_completion  0%{!?_without_bash_completion:1}
 
-# Use Python 3 when possible, Python 2 otherwise
-%if 0%{?fedora} || 0%{?rhel} > 7
-%define python python3
-%else
-%define python python2
-%endif
-
-
 %if %{with_qemu} || %{with_lxc}
 # numad is used to manage the CPU and memory placement dynamically,
 # it's not available on many non-x86 architectures.
@@ -281,7 +273,7 @@ BuildRequires: perl-interpreter
 %else
 BuildRequires: perl
 %endif
-BuildRequires: %{python}
+BuildRequires: python3
 BuildRequires: systemd-units
 %if %{with_libxl}
 BuildRequires: xen-devel
diff --git a/scripts/augeas-gentest.py b/scripts/augeas-gentest.py
index 60e12fb77e..8976785cad 100755
--- a/scripts/augeas-gentest.py
+++ b/scripts/augeas-gentest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright (C) 2012-2019 Red Hat, Inc.
 #
@@ -19,8 +19,6 @@
 # License along with this library.  If not, see
 # .
 
-from __future__ import print_function
-
 import re
 import sys
 
diff --git a/scripts/check-aclperms.py b/scripts/check-aclperms.py
index b1084a3758..67de0efabd 100755
--- a/scripts/check-aclperms.py
+++ b/scripts/check-aclperms.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright (C) 2013-2019 Red Hat, Inc.
 #
@@ -21,8 +21,6 @@
 # a lot of auto-generation of code, so when these don't match
 # problems occur, preventing auth from succeeding at all.
 
-from __future__ import print_function
-
 import re
 import sys
 
diff --git a/scripts/check-aclrules.py b/scripts/check-aclrules.py
index 5a7d275410..a1fa473174 100755
--- a/scripts/check-aclrules.py
+++ b/scripts/check-aclrules.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # Copyright (C) 2013-2019 Red Hat, Inc.
 #
@@ -32,8 +32,6 @@
 # detected EnsureACL call recorded.
 #
 
-from __future__ import print_function
-
 import re
 import sys
 
diff --git a/scripts/check-driverimpls.py b/scripts/check-driverimpls.py
index bc3f16a816..8289b8051e 100755
--- a/scripts/check-driverimpls.py
+++ b/scripts/check-driverimpls.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 

[libvirt] [PATCH] qemu: keep capabilities when running QEMU as root

2019-12-04 Thread Daniel P . Berrangé
When QEMU uid/gid is set to non-root this is pointless as if we just
used a regular setuid/setgid call, the process will have all its
capabilities cleared anyway by the kernel.

When QEMU uid/gid is set to root, this is almost (always?) never
what people actually want. People make QEMU run as root in order
to access some privileged resource that libvirt doesn't support
yet and this often requires capabilities. As a result they have
to go find the qemu.conf param to turn this off. This is not
viable for libguestfs - they want to control everything via the
XML security label to request running as root regardless of the
qemu.conf settings for user/group.

Clearing capabilities was implemented originally because there
was a proposal in Fedora to change permissions such that root,
with no capabilities would not be able to compromise the system.
ie a locked down root account. This never went anywhere though,
and as a result clearing capabilities when running as root does
not really get us any security benefit AFAICT. The root user
can easily do something like create a cronjob, which will then
faithfully be run with full capabilities, trivially bypassing
the restriction we place.

IOW, our clearing of capabilities is both useless from a security
POV, and breaks valid use cases when people need to run as root.

This removes the clear_emulator_capabilities configuration
option from qemu.conf, and always runs QEMU with capabilities
when root.  The behaviour when non-root is unchanged.

Signed-off-by: Daniel P. Berrangé 
---
 docs/drvqemu.html.in   | 46 +++---
 src/qemu/libvirtd_qemu.aug |  8 +-
 src/qemu/qemu.conf | 11 ---
 src/qemu/qemu_conf.c   |  4 ---
 src/qemu/qemu_conf.h   |  1 -
 src/qemu/qemu_domain.c |  3 +-
 src/qemu/qemu_process.c|  5 
 src/qemu/test_libvirtd_qemu.aug.in |  1 -
 8 files changed, 25 insertions(+), 54 deletions(-)

diff --git a/docs/drvqemu.html.in b/docs/drvqemu.html.in
index 294117ee1f..8beb28655c 100644
--- a/docs/drvqemu.html.in
+++ b/docs/drvqemu.html.in
@@ -187,41 +187,29 @@ chmod o+x /path/to/directory
   
 
 
-Linux process capabilities
-
 
-  The libvirt QEMU driver has a build time option allowing it to use
-  the http://people.redhat.com/sgrubb/libcap-ng/index.html;>libcap-ng
-  library to manage process capabilities. If this build option is
-  enabled, then the QEMU driver will use this to ensure that all
-  process capabilities are dropped before executing a QEMU virtual
-  machine. Process capabilities are what gives the 'root' account
-  its high power, in particular the CAP_DAC_OVERRIDE capability
-  is what allows a process running as 'root' to access files owned
-  by any user.
+  The libvirt maintainers strongly recommend against
+  running QEMU as the root user/group. This should not be required
+  in most supported usage scenarios, as libvirt will generally do the
+  right thing to grant QEMU access to files it is permitted to
+  use when it is running non-root.
 
 
+Linux process capabilities
+
 
-  If the QEMU driver is configured to run virtual machines as non-root,
-  then they will already lose all their process capabilities at time
-  of startup. The Linux capability feature is thus aimed primarily at
-  the scenario where the QEMU processes are running as root. In this
-  case, before launching a QEMU virtual machine, libvirtd will use
-  libcap-ng APIs to drop all process capabilities. It is important
-  for administrators to note that this implies the QEMU process will
-  only be able to access files owned by root, and
-  not files owned by any other user.
+  In versions of libvirt prior to 6.0.0, even if QEMU was configured
+  to run as the root user / group, libvirt would strip all process
+  capabilities. This meant that QEMU could only read/write files
+  owned by root, or with open permissions. In reality, stripping
+  capabilities did not have any security benefit, as it was trivial
+  to get commands to run in another context with full capabilities,
+  for example, by creating a cronjob.
 
-
 
-  Thus, if a vendor / distributor has configured their libvirt package
-  to run as 'qemu' by default, a number of changes will be required
-  before an administrator can change a host to run guests as root.
-  In particular it will be necessary to change ownership on the
-  directories /var/run/libvirt/qemu/,
-  /var/lib/libvirt/qemu/ and
-  /var/cache/libvirt/qemu/ back to root, in addition
-  to changing the /etc/libvirt/qemu.conf settings.
+  Thus since 6.0.0, if QEMU is running as root, it will keep all
+  process capabilities. Behaviour when QEMU is running non-root
+  is unchanged, it still has no capabilities.
 
 
 SELinux basic 

[libvirt] [PATCH 5/9] libxl: Don't use dom->conn to lookup virNetwork

2019-12-04 Thread Michal Privoznik
When using the monolithic daemon, then dom->conn has all driver
tables filled in properly and thus it's safe to call an API other
than virDomain*(). However, when using split daemons then
dom->conn has only hypervisor driver table set
(dom->conn->driver) and the rest is NULL. Therefore, if we want
to call a non-domain API (virNetworkLookupByName() in this case),
we have obtain the cached connection object accessible via
virGetConnectNetwork().

Signed-off-by: Michal Privoznik 
---
 src/libxl/libxl_driver.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 44a74e8779..ccef4f3955 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -6235,10 +6235,10 @@ static int libxlNodeGetSecurityModel(virConnectPtr conn,
 }
 
 static int
-libxlGetDHCPInterfaces(virDomainPtr dom,
-   virDomainObjPtr vm,
+libxlGetDHCPInterfaces(virDomainObjPtr vm,
virDomainInterfacePtr **ifaces)
 {
+g_autoptr(virConnect) conn = NULL;
 int rv = -1;
 int n_leases = 0;
 size_t i, j;
@@ -6249,12 +6249,8 @@ libxlGetDHCPInterfaces(virDomainPtr dom,
 virNetworkDHCPLeasePtr *leases = NULL;
 virDomainInterfacePtr *ifaces_ret = NULL;
 
-if (!dom->conn->networkDriver ||
-!dom->conn->networkDriver->networkGetDHCPLeases) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Network driver does not support DHCP lease query"));
+if (!(conn = virGetConnectNetwork()))
 return -1;
-}
 
 for (i = 0; i < vm->def->nnets; i++) {
 if (vm->def->nets[i]->type != VIR_DOMAIN_NET_TYPE_NETWORK)
@@ -6262,8 +6258,10 @@ libxlGetDHCPInterfaces(virDomainPtr dom,
 
 virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr);
 virObjectUnref(network);
-network = virNetworkLookupByName(dom->conn,
+network = virNetworkLookupByName(conn,
  vm->def->nets[i]->data.network.name);
+if (!network)
+goto error;
 
 if ((n_leases = virNetworkGetDHCPLeases(network, macaddr,
 , 0)) < 0)
@@ -6351,7 +6349,7 @@ libxlDomainInterfaceAddresses(virDomainPtr dom,
 
 switch (source) {
 case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE:
-ret = libxlGetDHCPInterfaces(dom, vm, ifaces);
+ret = libxlGetDHCPInterfaces(vm, ifaces);
 break;
 
 default:
-- 
2.23.0

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



[libvirt] [PATCH 4/9] qemuGetDHCPInterfaces: Switch to GLib

2019-12-04 Thread Michal Privoznik
If we use glib alloc functions, we can drop the 'cleanup' label
and @rv variable and also simplify the code a bit.

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_driver.c | 40 +++-
 1 file changed, 11 insertions(+), 29 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2bc2081d0b..2d2a83cd8b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -21555,9 +21555,6 @@ qemuGetDHCPInterfaces(virDomainObjPtr vm,
 g_autoptr(virConnect) conn = NULL;
 virDomainInterfacePtr *ifaces_ret = NULL;
 size_t ifaces_count = 0;
-int rv = -1;
-int n_leases = 0;
-virNetworkDHCPLeasePtr *leases = NULL;
 size_t i;
 
 if (!(conn = virGetConnectNetwork()))
@@ -21566,6 +21563,8 @@ qemuGetDHCPInterfaces(virDomainObjPtr vm,
 for (i = 0; i < vm->def->nnets; i++) {
 g_autoptr(virNetwork) network = NULL;
 char macaddr[VIR_MAC_STRING_BUFLEN];
+virNetworkDHCPLeasePtr *leases = NULL;
+int n_leases = 0;
 virDomainInterfacePtr iface = NULL;
 size_t j;
 
@@ -21584,21 +21583,15 @@ qemuGetDHCPInterfaces(virDomainObjPtr vm,
 goto error;
 
 if (n_leases) {
-if (VIR_EXPAND_N(ifaces_ret, ifaces_count, 1) < 0)
-goto error;
-
-if (VIR_ALLOC(ifaces_ret[ifaces_count - 1]) < 0)
-goto error;
+ifaces_ret = g_renew(typeof(*ifaces_ret), ifaces_ret, ifaces_count 
+ 1);
+ifaces_ret[ifaces_count] = g_new0(typeof(**ifaces_ret), 1);
+iface = ifaces_ret[ifaces_count];
+ifaces_count++;
 
-iface = ifaces_ret[ifaces_count - 1];
 /* Assuming each lease corresponds to a separate IP */
 iface->naddrs = n_leases;
-
-if (VIR_ALLOC_N(iface->addrs, iface->naddrs) < 0)
-goto error;
-
+iface->addrs = g_new0(typeof(*iface->addrs), iface->naddrs);
 iface->name = g_strdup(vm->def->nets[i]->ifname);
-
 iface->hwaddr = g_strdup(macaddr);
 }
 
@@ -21607,28 +21600,17 @@ qemuGetDHCPInterfaces(virDomainObjPtr vm,
 virDomainIPAddressPtr ip_addr = >addrs[j];
 
 ip_addr->addr = g_strdup(lease->ipaddr);
-
 ip_addr->type = lease->type;
 ip_addr->prefix = lease->prefix;
-}
 
-for (j = 0; j < n_leases; j++)
-virNetworkDHCPLeaseFree(leases[j]);
+virNetworkDHCPLeaseFree(lease);
+}
 
 VIR_FREE(leases);
 }
 
 *ifaces = g_steal_pointer(_ret);
-rv = ifaces_count;
-
- cleanup:
-if (leases) {
-for (i = 0; i < n_leases; i++)
-virNetworkDHCPLeaseFree(leases[i]);
-}
-VIR_FREE(leases);
-
-return rv;
+return ifaces_count;
 
  error:
 if (ifaces_ret) {
@@ -21637,7 +21619,7 @@ qemuGetDHCPInterfaces(virDomainObjPtr vm,
 }
 VIR_FREE(ifaces_ret);
 
-goto cleanup;
+return -1;
 }
 
 
-- 
2.23.0

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



[libvirt] [PATCH 0/9] Cleanup virConnectPtr usage

2019-12-04 Thread Michal Privoznik
I've noticed this problem when reviewing a patch on the list [1].

Long story short, dom->conn is not guaranteed to have all driver
pointers set (consider split daemons). I haven't identified any
other violation than what I'm fixing here. But something might have
slipped through my git grep.

1: https://www.redhat.com/archives/libvir-list/2019-December/msg00120.html

Michal Prívozník (9):
  qemu_driver: Push qemuDomainInterfaceAddresses() a few lines down
  qemu: Don't use dom->conn to lookup virNetwork
  qemuGetDHCPInterfaces: Move some variables inside the loop
  qemuGetDHCPInterfaces: Switch to GLib
  libxl: Don't use dom->conn to lookup virNetwork
  libxlGetDHCPInterfaces: Move some variables inside the loop
  libxlGetDHCPInterfaces: Switch to GLib
  lxc: Cleanup virConnectPtr usage
  get_nonnull_domain: Drop useless comment

 src/libxl/libxl_driver.c|  71 --
 src/lxc/lxc_driver.c|  12 +-
 src/lxc/lxc_process.c   |  40 +++---
 src/lxc/lxc_process.h   |   2 +-
 src/qemu/qemu_driver.c  | 193 
 src/remote/remote_daemon_dispatch.c |   3 -
 6 files changed, 139 insertions(+), 182 deletions(-)

-- 
2.23.0

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

[libvirt] [PATCH 8/9] lxc: Cleanup virConnectPtr usage

2019-12-04 Thread Michal Privoznik
There are some functions which pass virConnectPtr around for one
reason and one reason only: to obtain virLXCDriverPtr in the end.
Might replace the argument and pass a pointer to the driver right
from the start.

Signed-off-by: Michal Privoznik 
---
 src/lxc/lxc_driver.c  | 12 +---
 src/lxc/lxc_process.c | 40 ++--
 src/lxc/lxc_process.h |  2 +-
 3 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 826bf074e3..e4be45fca2 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -3803,9 +3803,8 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
 }
 
 
-/* XXX conn required for network -> bridge resolution */
 static int
-lxcDomainAttachDeviceNetLive(virConnectPtr conn,
+lxcDomainAttachDeviceNetLive(virLXCDriverPtr driver,
  virDomainObjPtr vm,
  virDomainNetDefPtr net)
 {
@@ -3866,7 +3865,7 @@ lxcDomainAttachDeviceNetLive(virConnectPtr conn,
 goto cleanup;
 break;
 case VIR_DOMAIN_NET_TYPE_DIRECT: {
-if (!(veth = virLXCProcessSetupInterfaceDirect(conn, vm->def, net)))
+if (!(veth = virLXCProcessSetupInterfaceDirect(driver, vm->def, net)))
 goto cleanup;
 }   break;
 case VIR_DOMAIN_NET_TYPE_USER:
@@ -4233,8 +4232,7 @@ lxcDomainAttachDeviceHostdevLive(virLXCDriverPtr driver,
 
 
 static int
-lxcDomainAttachDeviceLive(virConnectPtr conn,
-  virLXCDriverPtr driver,
+lxcDomainAttachDeviceLive(virLXCDriverPtr driver,
   virDomainObjPtr vm,
   virDomainDeviceDefPtr dev)
 {
@@ -4248,7 +4246,7 @@ lxcDomainAttachDeviceLive(virConnectPtr conn,
 break;
 
 case VIR_DOMAIN_DEVICE_NET:
-ret = lxcDomainAttachDeviceNetLive(conn, vm,
+ret = lxcDomainAttachDeviceNetLive(driver, vm,
dev->data.net);
 if (!ret)
 dev->data.net = NULL;
@@ -4736,7 +4734,7 @@ static int lxcDomainAttachDeviceFlags(virDomainPtr dom,
  true) < 0)
 goto endjob;
 
-if ((ret = lxcDomainAttachDeviceLive(dom->conn, driver, vm, dev_copy)) 
< 0)
+if ((ret = lxcDomainAttachDeviceLive(driver, vm, dev_copy)) < 0)
 goto endjob;
 /*
  * update domain status forcibly because the domain status may be
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 9b62a93096..f5d2fb0145 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -326,13 +326,13 @@ virLXCProcessSetupInterfaceTap(virDomainDefPtr vm,
 }
 
 
-char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
-virDomainDefPtr def,
-virDomainNetDefPtr net)
+char *
+virLXCProcessSetupInterfaceDirect(virLXCDriverPtr driver,
+  virDomainDefPtr def,
+  virDomainNetDefPtr net)
 {
 char *ret = NULL;
 char *res_ifname = NULL;
-virLXCDriverPtr driver = conn->privateData;
 const virNetDevBandwidth *bw;
 const virNetDevVPortProfile *prof;
 virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
@@ -392,9 +392,10 @@ static const char 
*nsInfoLocal[VIR_LXC_DOMAIN_NAMESPACE_LAST] = {
 [VIR_LXC_DOMAIN_NAMESPACE_SHAREUTS] = "uts",
 };
 
-static int virLXCProcessSetupNamespaceName(virConnectPtr conn, int ns_type, 
const char *name)
+static int virLXCProcessSetupNamespaceName(virLXCDriverPtr driver,
+   int ns_type,
+   const char *name)
 {
-virLXCDriverPtr driver = conn->privateData;
 int fd = -1;
 virDomainObjPtr vm;
 virLXCDomainObjPrivatePtr priv;
@@ -474,7 +475,7 @@ static int virLXCProcessSetupNamespaceNet(int ns_type, 
const char *name)
 
 /**
  * virLXCProcessSetupNamespaces:
- * @conn: pointer to connection
+ * @driver: pointer to driver structure
  * @def: pointer to virtual machines namespaceData
  * @nsFDs: out parameter to store the namespace FD
  *
@@ -483,9 +484,10 @@ static int virLXCProcessSetupNamespaceNet(int ns_type, 
const char *name)
  *
  * Returns 0 on success or -1 in case of error
  */
-static int virLXCProcessSetupNamespaces(virConnectPtr conn,
-lxcDomainDefPtr lxcDef,
-int *nsFDs)
+static int
+virLXCProcessSetupNamespaces(virLXCDriverPtr driver,
+ lxcDomainDefPtr lxcDef,
+ int *nsFDs)
 {
 size_t i;
 
@@ -500,7 +502,8 @@ static int virLXCProcessSetupNamespaces(virConnectPtr conn,
 case VIR_LXC_DOMAIN_NAMESPACE_SOURCE_NONE:
 continue;
 case VIR_LXC_DOMAIN_NAMESPACE_SOURCE_NAME:
-if ((nsFDs[i] = virLXCProcessSetupNamespaceName(conn, i, 

[libvirt] [PATCH 9/9] get_nonnull_domain: Drop useless comment

2019-12-04 Thread Michal Privoznik
The intent of get_nonnull_domain() is not to validate virDomain
as sent by the client but just to construct the virDomain
structure. The validation is then done in each API when looking
up the domain in our internal hash tables.

Signed-off-by: Michal Privoznik 
---
 src/remote/remote_daemon_dispatch.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/remote/remote_daemon_dispatch.c 
b/src/remote/remote_daemon_dispatch.c
index f369ffb02a..a96e008242 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -7240,9 +7240,6 @@ remoteDispatchNetworkPortGetParameters(virNetServerPtr 
server G_GNUC_UNUSED,
 static virDomainPtr
 get_nonnull_domain(virConnectPtr conn, remote_nonnull_domain domain)
 {
-/* Should we believe the domain.id sent by the client?  Maybe
- * this should be a check rather than an assignment? XXX
- */
 return virGetDomain(conn, domain.name, BAD_CAST domain.uuid, domain.id);
 }
 
-- 
2.23.0

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



[libvirt] [PATCH 1/9] qemu_driver: Push qemuDomainInterfaceAddresses() a few lines down

2019-12-04 Thread Michal Privoznik
If we place qemuDomainInterfaceAddresses() a few lines below the
two functions its using then we can drop forward declarations of
those functions.

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_driver.c | 125 -
 1 file changed, 60 insertions(+), 65 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1911073f3e..1b9d6d16a1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -151,13 +151,6 @@ static int qemuOpenFileAs(uid_t fallback_uid, gid_t 
fallback_gid,
   const char *path, int oflags,
   bool *needUnlink);
 
-static int qemuGetDHCPInterfaces(virDomainPtr dom,
- virDomainObjPtr vm,
- virDomainInterfacePtr **ifaces);
-
-static int qemuARPGetInterfaces(virDomainObjPtr vm,
-virDomainInterfacePtr **ifaces);
-
 static virQEMUDriverPtr qemu_driver;
 
 /* Looks up the domain object from snapshot and unlocks the
@@ -21554,64 +21547,6 @@ qemuDomainGetFSInfo(virDomainPtr dom,
 return ret;
 }
 
-static int
-qemuDomainInterfaceAddresses(virDomainPtr dom,
- virDomainInterfacePtr **ifaces,
- unsigned int source,
- unsigned int flags)
-{
-virQEMUDriverPtr driver = dom->conn->privateData;
-virDomainObjPtr vm = NULL;
-qemuAgentPtr agent;
-int ret = -1;
-
-virCheckFlags(0, -1);
-
-if (!(vm = qemuDomainObjFromDomain(dom)))
-goto cleanup;
-
-if (virDomainInterfaceAddressesEnsureACL(dom->conn, vm->def) < 0)
-goto cleanup;
-
-if (virDomainObjCheckActive(vm) < 0)
-goto cleanup;
-
-switch (source) {
-case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE:
-ret = qemuGetDHCPInterfaces(dom, vm, ifaces);
-break;
-
-case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT:
-if (qemuDomainObjBeginAgentJob(driver, vm, QEMU_AGENT_JOB_QUERY) < 0)
-goto cleanup;
-
-if (!qemuDomainAgentAvailable(vm, true))
-goto endjob;
-
-agent = qemuDomainObjEnterAgent(vm);
-ret = qemuAgentGetInterfaces(agent, ifaces);
-qemuDomainObjExitAgent(vm, agent);
-
-endjob:
-qemuDomainObjEndAgentJob(vm);
-
-break;
-
-case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP:
-ret = qemuARPGetInterfaces(vm, ifaces);
-break;
-
-default:
-virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
-   _("Unknown IP address data source %d"),
-   source);
-break;
-}
-
- cleanup:
-virDomainObjEndAPI();
-return ret;
-}
 
 static int
 qemuGetDHCPInterfaces(virDomainPtr dom,
@@ -21764,6 +21699,66 @@ qemuARPGetInterfaces(virDomainObjPtr vm,
 }
 
 
+static int
+qemuDomainInterfaceAddresses(virDomainPtr dom,
+ virDomainInterfacePtr **ifaces,
+ unsigned int source,
+ unsigned int flags)
+{
+virQEMUDriverPtr driver = dom->conn->privateData;
+virDomainObjPtr vm = NULL;
+qemuAgentPtr agent;
+int ret = -1;
+
+virCheckFlags(0, -1);
+
+if (!(vm = qemuDomainObjFromDomain(dom)))
+goto cleanup;
+
+if (virDomainInterfaceAddressesEnsureACL(dom->conn, vm->def) < 0)
+goto cleanup;
+
+if (virDomainObjCheckActive(vm) < 0)
+goto cleanup;
+
+switch (source) {
+case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE:
+ret = qemuGetDHCPInterfaces(dom, vm, ifaces);
+break;
+
+case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT:
+if (qemuDomainObjBeginAgentJob(driver, vm, QEMU_AGENT_JOB_QUERY) < 0)
+goto cleanup;
+
+if (!qemuDomainAgentAvailable(vm, true))
+goto endjob;
+
+agent = qemuDomainObjEnterAgent(vm);
+ret = qemuAgentGetInterfaces(agent, ifaces);
+qemuDomainObjExitAgent(vm, agent);
+
+endjob:
+qemuDomainObjEndAgentJob(vm);
+
+break;
+
+case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_ARP:
+ret = qemuARPGetInterfaces(vm, ifaces);
+break;
+
+default:
+virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
+   _("Unknown IP address data source %d"),
+   source);
+break;
+}
+
+ cleanup:
+virDomainObjEndAPI();
+return ret;
+}
+
+
 static int
 qemuDomainSetUserPassword(virDomainPtr dom,
   const char *user,
-- 
2.23.0

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



[libvirt] [PATCH 3/9] qemuGetDHCPInterfaces: Move some variables inside the loop

2019-12-04 Thread Michal Privoznik
Some variables are not used outside of the for() loop. Move their
declaration to clean up the code a bit.

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_driver.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e5be74c461..2bc2081d0b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -21553,26 +21553,27 @@ qemuGetDHCPInterfaces(virDomainObjPtr vm,
   virDomainInterfacePtr **ifaces)
 {
 g_autoptr(virConnect) conn = NULL;
+virDomainInterfacePtr *ifaces_ret = NULL;
+size_t ifaces_count = 0;
 int rv = -1;
 int n_leases = 0;
-size_t i, j;
-size_t ifaces_count = 0;
-g_autoptr(virNetwork) network = NULL;
-char macaddr[VIR_MAC_STRING_BUFLEN];
-virDomainInterfacePtr iface = NULL;
 virNetworkDHCPLeasePtr *leases = NULL;
-virDomainInterfacePtr *ifaces_ret = NULL;
+size_t i;
 
 if (!(conn = virGetConnectNetwork()))
 return -1;
 
 for (i = 0; i < vm->def->nnets; i++) {
+g_autoptr(virNetwork) network = NULL;
+char macaddr[VIR_MAC_STRING_BUFLEN];
+virDomainInterfacePtr iface = NULL;
+size_t j;
+
 if (vm->def->nets[i]->type != VIR_DOMAIN_NET_TYPE_NETWORK)
 continue;
 
 virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr);
 
-virObjectUnref(network);
 network = virNetworkLookupByName(conn,
  vm->def->nets[i]->data.network.name);
 if (!network)
-- 
2.23.0

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



[libvirt] [PATCH 6/9] libxlGetDHCPInterfaces: Move some variables inside the loop

2019-12-04 Thread Michal Privoznik
Some variables are not used outside of the for() loop. Move their
declaration to clean up the code a bit.

Signed-off-by: Michal Privoznik 
---
 src/libxl/libxl_driver.c | 16 +---
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index ccef4f3955..6064436681 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -6239,25 +6239,27 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm,
virDomainInterfacePtr **ifaces)
 {
 g_autoptr(virConnect) conn = NULL;
+virDomainInterfacePtr *ifaces_ret = NULL;
+size_t ifaces_count = 0;
 int rv = -1;
 int n_leases = 0;
-size_t i, j;
-size_t ifaces_count = 0;
-virNetworkPtr network = NULL;
-char macaddr[VIR_MAC_STRING_BUFLEN];
-virDomainInterfacePtr iface = NULL;
 virNetworkDHCPLeasePtr *leases = NULL;
-virDomainInterfacePtr *ifaces_ret = NULL;
+size_t i;
 
 if (!(conn = virGetConnectNetwork()))
 return -1;
 
 for (i = 0; i < vm->def->nnets; i++) {
+g_autoptr(virNetwork) network = NULL;
+char macaddr[VIR_MAC_STRING_BUFLEN];
+virDomainInterfacePtr iface = NULL;
+size_t j;
+
 if (vm->def->nets[i]->type != VIR_DOMAIN_NET_TYPE_NETWORK)
 continue;
 
 virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr);
-virObjectUnref(network);
+
 network = virNetworkLookupByName(conn,
  vm->def->nets[i]->data.network.name);
 if (!network)
-- 
2.23.0

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



[libvirt] [PATCH 2/9] qemu: Don't use dom->conn to lookup virNetwork

2019-12-04 Thread Michal Privoznik
When using the monolithic daemon, then dom->conn has all driver
tables filled in properly and thus it's safe to call an API other
than virDomain*(). However, when using split daemons then
dom->conn has only hypervisor driver table set
(dom->conn->driver) and the rest is NULL. Therefore, if we want
to call a non-domain API (virNetworkLookupByName() in this case),
we have obtain the cached connection object accessible via
virGetConnectNetwork().

Signed-off-by: Michal Privoznik 
---
 src/qemu/qemu_driver.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1b9d6d16a1..e5be74c461 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -21549,10 +21549,10 @@ qemuDomainGetFSInfo(virDomainPtr dom,
 
 
 static int
-qemuGetDHCPInterfaces(virDomainPtr dom,
-  virDomainObjPtr vm,
+qemuGetDHCPInterfaces(virDomainObjPtr vm,
   virDomainInterfacePtr **ifaces)
 {
+g_autoptr(virConnect) conn = NULL;
 int rv = -1;
 int n_leases = 0;
 size_t i, j;
@@ -21563,21 +21563,20 @@ qemuGetDHCPInterfaces(virDomainPtr dom,
 virNetworkDHCPLeasePtr *leases = NULL;
 virDomainInterfacePtr *ifaces_ret = NULL;
 
-if (!dom->conn->networkDriver ||
-!dom->conn->networkDriver->networkGetDHCPLeases) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Network driver does not support DHCP lease query"));
+if (!(conn = virGetConnectNetwork()))
 return -1;
-}
 
 for (i = 0; i < vm->def->nnets; i++) {
 if (vm->def->nets[i]->type != VIR_DOMAIN_NET_TYPE_NETWORK)
 continue;
 
 virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr);
+
 virObjectUnref(network);
-network = virNetworkLookupByName(dom->conn,
+network = virNetworkLookupByName(conn,
  vm->def->nets[i]->data.network.name);
+if (!network)
+goto error;
 
 if ((n_leases = virNetworkGetDHCPLeases(network, macaddr,
 , 0)) < 0)
@@ -21723,7 +21722,7 @@ qemuDomainInterfaceAddresses(virDomainPtr dom,
 
 switch (source) {
 case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE:
-ret = qemuGetDHCPInterfaces(dom, vm, ifaces);
+ret = qemuGetDHCPInterfaces(vm, ifaces);
 break;
 
 case VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT:
-- 
2.23.0

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



[libvirt] [PATCH 7/9] libxlGetDHCPInterfaces: Switch to GLib

2019-12-04 Thread Michal Privoznik
If we use glib alloc functions, we can drop the 'cleanup' label
and @rv variable and also simplify the code a bit.

Signed-off-by: Michal Privoznik 
---
 src/libxl/libxl_driver.c | 41 +++-
 1 file changed, 11 insertions(+), 30 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 6064436681..7467111618 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -6241,9 +6241,6 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm,
 g_autoptr(virConnect) conn = NULL;
 virDomainInterfacePtr *ifaces_ret = NULL;
 size_t ifaces_count = 0;
-int rv = -1;
-int n_leases = 0;
-virNetworkDHCPLeasePtr *leases = NULL;
 size_t i;
 
 if (!(conn = virGetConnectNetwork()))
@@ -6252,6 +6249,8 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm,
 for (i = 0; i < vm->def->nnets; i++) {
 g_autoptr(virNetwork) network = NULL;
 char macaddr[VIR_MAC_STRING_BUFLEN];
+virNetworkDHCPLeasePtr *leases = NULL;
+int n_leases = 0;
 virDomainInterfacePtr iface = NULL;
 size_t j;
 
@@ -6270,21 +6269,16 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm,
 goto error;
 
 if (n_leases) {
-if (VIR_EXPAND_N(ifaces_ret, ifaces_count, 1) < 0)
-goto error;
+ifaces_ret = g_renew(typeof(*ifaces_ret), ifaces_ret, ifaces_count 
+ 1);
+ifaces_ret[ifaces_count] = g_new0(typeof(**ifaces_ret), 1);
+iface = ifaces_ret[ifaces_count];
+ifaces_count++;
 
-if (VIR_ALLOC(ifaces_ret[ifaces_count - 1]) < 0)
-goto error;
-
-iface = ifaces_ret[ifaces_count - 1];
 /* Assuming each lease corresponds to a separate IP */
 iface->naddrs = n_leases;
 
-if (VIR_ALLOC_N(iface->addrs, iface->naddrs) < 0)
-goto error;
-
+iface->addrs = g_new0(typeof(*iface->addrs), iface->naddrs);
 iface->name = g_strdup(vm->def->nets[i]->ifname);
-
 iface->hwaddr = g_strdup(macaddr);
 }
 
@@ -6293,30 +6287,17 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm,
 virDomainIPAddressPtr ip_addr = >addrs[j];
 
 ip_addr->addr = g_strdup(lease->ipaddr);
-
 ip_addr->type = lease->type;
 ip_addr->prefix = lease->prefix;
-}
 
-for (j = 0; j < n_leases; j++)
 virNetworkDHCPLeaseFree(leases[j]);
+}
 
 VIR_FREE(leases);
 }
 
-*ifaces = ifaces_ret;
-ifaces_ret = NULL;
-rv = ifaces_count;
-
- cleanup:
-virObjectUnref(network);
-if (leases) {
-for (i = 0; i < n_leases; i++)
-virNetworkDHCPLeaseFree(leases[i]);
-}
-VIR_FREE(leases);
-
-return rv;
+*ifaces = g_steal_pointer(_ret);
+return ifaces_count;
 
  error:
 if (ifaces_ret) {
@@ -6325,7 +6306,7 @@ libxlGetDHCPInterfaces(virDomainObjPtr vm,
 }
 VIR_FREE(ifaces_ret);
 
-goto cleanup;
+return -1;
 }
 
 
-- 
2.23.0

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



[libvirt] [PATCH v3 1/3] conf: fix logic error for scsi units

2019-12-04 Thread Han Han
Introduced in c8007fdc5d2, it should use 'greater than max' instead of
'equal or greater than max' for the condition of checking invalid scsi
unit.

Signed-off-by: Han Han 
---
 src/conf/domain_conf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9580884747..badc2da487 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -4850,7 +4850,7 @@ virDomainSCSIDriveAddressIsUsed(const virDomainDef *def,
 break;
 }
 
-if (max != -1 && addr->unit >= max)
+if (max != -1 && addr->unit > max)
 return true;
 if (reserved != -1 && addr->unit == reserved)
 return true;
-- 
2.24.0.rc1

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



  1   2   >