Re: [libvirt] [PATCH] test_driver: implement virDomainSetTime and update virDomainGetTime

2019-08-07 Thread Erik Skultety
On Tue, Aug 06, 2019 at 06:20:07PM +0200, Ilias Stamatis wrote:
> Until now, testDomainGetTime would always return the same fixed value
> everytime it was called. By using domain-private data we can make this
> API return the values previously set with testDomainSetTime, or use the
> same old fixed value in case testDomainSetTime hasn't been called at all.
> ---

As the commit subject already hints, this should be split in 2 patches.

>  src/test/test_driver.c | 45 --
>  1 file changed, 43 insertions(+), 2 deletions(-)
>
> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> index d9a7f815d5..6a75e63429 100755
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c
> @@ -392,6 +392,11 @@ struct _testDomainObjPrivate {
>  testDriverPtr driver;
>
>  bool frozen[2]; /* used by file system related calls */
> +

No need for another ^extra line :).

> +
> +/* used by get/set time APIs */
> +long long seconds;
> +unsigned int nseconds;

Looks like we're going to make more and more use of the private data, so at
some point it might be worth introducing helper structures to keep the master
structure (priv) tidy, but that's a patch for another day.

The code's alright, so once you split the changes it can go right in.

Erik

>  };
>
>
> @@ -406,6 +411,9 @@ testDomainObjPrivateAlloc(void *opaque)
>  priv->driver = opaque;
>  priv->frozen[0] = priv->frozen[1] = false;
>
> +priv->seconds = 627319920;
> +priv->nseconds = 0;
> +
>  return priv;
>  }
>
> @@ -2082,6 +2090,7 @@ testDomainGetTime(virDomainPtr dom,
>unsigned int flags)
>  {
>  virDomainObjPtr vm = NULL;
> +testDomainObjPrivatePtr priv;
>  int ret = -1;
>
>  virCheckFlags(0, -1);
> @@ -2095,8 +2104,39 @@ testDomainGetTime(virDomainPtr dom,
>  goto cleanup;
>  }
>
> -*seconds = 627319920;
> -*nseconds = 0;
> +priv = vm->privateData;
> +
> +*seconds = priv->seconds;
> +*nseconds = priv->nseconds;
> +
> +ret = 0;
> + cleanup:
> +virDomainObjEndAPI();
> +return ret;
> +}
> +
> +
> +static int
> +testDomainSetTime(virDomainPtr dom,
> +  long long seconds,
> +  unsigned int nseconds,
> +  unsigned int flags)
> +{
> +virDomainObjPtr vm = NULL;
> +testDomainObjPrivatePtr priv;
> +int ret = -1;
> +
> +virCheckFlags(VIR_DOMAIN_TIME_SYNC, ret);
> +
> +if (!(vm = testDomObjFromDomain(dom)))
> +return -1;
> +
> +if (virDomainObjCheckActive(vm) < 0)
> +goto cleanup;
> +
> +priv = vm->privateData;
> +priv->seconds = seconds;
> +priv->nseconds = nseconds;
>
>  ret = 0;
>   cleanup:
> @@ -8891,6 +8931,7 @@ static virHypervisorDriver testHypervisorDriver = {
>  .domainGetInfo = testDomainGetInfo, /* 0.1.1 */
>  .domainGetState = testDomainGetState, /* 0.9.2 */
>  .domainGetTime = testDomainGetTime, /* 5.4.0 */
> +.domainSetTime = testDomainSetTime, /* 5.7.0 */
>  .domainSave = testDomainSave, /* 0.3.2 */
>  .domainSaveFlags = testDomainSaveFlags, /* 0.9.4 */
>  .domainRestore = testDomainRestore, /* 0.3.2 */
> --
> 2.22.0
>
> --
> libvir-list mailing list
> libvir-list@redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list

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


Re: [libvirt] [PATCH] test_driver: implement virDomainReset

2019-08-07 Thread Erik Skultety
On Tue, Aug 06, 2019 at 05:56:23PM +0200, Ilias Stamatis wrote:
> The qemu and vz implementations don't emit any signals when this API is
> called, so we can do the same here for now and succeed by doing nothing.
>
> Signed-off-by: Ilias Stamatis 
> ---
Reviewed-by: Erik Skultety 

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


[libvirt] [PATCH v2 05/15] tools: Separate storage volume related completers into a file

2019-08-07 Thread Michal Privoznik
Mixing all completers in one file does not support
maintainability. Separate those completers which relate to
storage volumes (e.g. they complete various storage volume
aspects) into virsh-completer-volume.c

Signed-off-by: Michal Privoznik 
---
 tools/Makefile.am  |  1 +
 tools/virsh-completer-volume.c | 73 ++
 tools/virsh-completer-volume.h | 28 +
 tools/virsh-completer.c| 47 --
 tools/virsh-completer.h|  5 +--
 5 files changed, 103 insertions(+), 51 deletions(-)
 create mode 100644 tools/virsh-completer-volume.c
 create mode 100644 tools/virsh-completer-volume.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index a5ce6a45d4..06c05303ed 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -220,6 +220,7 @@ virsh_SOURCES = \
virsh-completer.c virsh-completer.h \
virsh-completer-domain.c virsh-completer-domain.h \
virsh-completer-pool.c virsh-completer-pool.h \
+   virsh-completer-volume.c virsh-completer-volume.h \
virsh-console.c virsh-console.h \
virsh-domain.c virsh-domain.h \
virsh-domain-monitor.c virsh-domain-monitor.h \
diff --git a/tools/virsh-completer-volume.c b/tools/virsh-completer-volume.c
new file mode 100644
index 00..2df0077d7a
--- /dev/null
+++ b/tools/virsh-completer-volume.c
@@ -0,0 +1,73 @@
+/*
+ * virsh-completer-volume.c: virsh completer callbacks related to volumes
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include "virsh-completer-volume.h"
+#include "viralloc.h"
+#include "virsh-pool.h"
+#include "virsh.h"
+#include "virstring.h"
+
+char **
+virshStorageVolNameCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+virStoragePoolPtr pool = NULL;
+virStorageVolPtr *vols = NULL;
+int rc;
+int nvols = 0;
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(0, NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
+return NULL;
+
+if ((rc = virStoragePoolListAllVolumes(pool, , flags)) < 0)
+goto cleanup;
+nvols = rc;
+
+if (VIR_ALLOC_N(tmp, nvols + 1) < 0)
+goto cleanup;
+
+for (i = 0; i < nvols; i++) {
+const char *name = virStorageVolGetName(vols[i]);
+
+if (VIR_STRDUP(tmp[i], name) < 0)
+goto cleanup;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+
+ cleanup:
+virStoragePoolFree(pool);
+for (i = 0; i < nvols; i++)
+virStorageVolFree(vols[i]);
+VIR_FREE(vols);
+return ret;
+}
diff --git a/tools/virsh-completer-volume.h b/tools/virsh-completer-volume.h
new file mode 100644
index 00..6591e13fdf
--- /dev/null
+++ b/tools/virsh-completer-volume.h
@@ -0,0 +1,28 @@
+/*
+ * virsh-completer-volume.h: virsh completer callbacks related to volumes
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#pragma once
+
+#include "vsh.h"
+
+
+char ** virshStorageVolNameCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int flags);
diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index 3b22688562..e6f04296a3 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -143,53 +143,6 @@ virshCommaStringListComplete(const char *input,
 }
 
 
-char **

[libvirt] [PATCH v2 07/15] tools: Separate network related completers into a file

2019-08-07 Thread Michal Privoznik
Mixing all completers in one file does not support
maintainability. Separate those completers which relate to
networks (e.g. they complete various network aspects)
into virsh-completer-network.c

Signed-off-by: Michal Privoznik 
---
 tools/Makefile.am   |   1 +
 tools/virsh-completer-network.c | 145 
 tools/virsh-completer-network.h |  35 
 tools/virsh-completer.c | 119 --
 tools/virsh-completer.h |  13 +--
 5 files changed, 182 insertions(+), 131 deletions(-)
 create mode 100644 tools/virsh-completer-network.c
 create mode 100644 tools/virsh-completer-network.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 7e3c9c35c9..fb42277269 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -220,6 +220,7 @@ virsh_SOURCES = \
virsh-completer.c virsh-completer.h \
virsh-completer-domain.c virsh-completer-domain.h \
virsh-completer-interface.c virsh-completer-interface.h \
+   virsh-completer-network.c virsh-completer-network.h \
virsh-completer-pool.c virsh-completer-pool.h \
virsh-completer-volume.c virsh-completer-volume.h \
virsh-console.c virsh-console.h \
diff --git a/tools/virsh-completer-network.c b/tools/virsh-completer-network.c
new file mode 100644
index 00..6f92780feb
--- /dev/null
+++ b/tools/virsh-completer-network.c
@@ -0,0 +1,145 @@
+/*
+ * virsh-completer-network.c: virsh completer callbacks related to networks
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include "virsh-completer-network.h"
+#include "viralloc.h"
+#include "virsh-network.h"
+#include "virsh.h"
+#include "virstring.h"
+
+char **
+virshNetworkNameCompleter(vshControl *ctl,
+  const vshCmd *cmd ATTRIBUTE_UNUSED,
+  unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+virNetworkPtr *nets = NULL;
+int nnets = 0;
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(VIR_CONNECT_LIST_NETWORKS_INACTIVE |
+  VIR_CONNECT_LIST_NETWORKS_ACTIVE |
+  VIR_CONNECT_LIST_NETWORKS_PERSISTENT,
+  NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if ((nnets = virConnectListAllNetworks(priv->conn, , flags)) < 0)
+return NULL;
+
+if (VIR_ALLOC_N(tmp, nnets + 1) < 0)
+goto cleanup;
+
+for (i = 0; i < nnets; i++) {
+const char *name = virNetworkGetName(nets[i]);
+
+if (VIR_STRDUP(tmp[i], name) < 0)
+goto cleanup;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+
+ cleanup:
+for (i = 0; i < nnets; i++)
+virNetworkFree(nets[i]);
+VIR_FREE(nets);
+return ret;
+}
+
+
+char **
+virshNetworkEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
+   const vshCmd *cmd ATTRIBUTE_UNUSED,
+   unsigned int flags)
+{
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(0, NULL);
+
+if (VIR_ALLOC_N(tmp, VIR_NETWORK_EVENT_ID_LAST + 1) < 0)
+goto cleanup;
+
+for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++) {
+if (VIR_STRDUP(tmp[i], virshNetworkEventCallbacks[i].name) < 0)
+goto cleanup;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+
+ cleanup:
+return ret;
+}
+
+
+char **
+virshNetworkPortUUIDCompleter(vshControl *ctl,
+  const vshCmd *cmd ATTRIBUTE_UNUSED,
+  unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+virNetworkPtr net = NULL;
+virNetworkPortPtr *ports = NULL;
+int nports = 0;
+size_t i = 0;
+char **ret = NULL;
+
+virCheckFlags(0, NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if (!(net = virshCommandOptNetwork(ctl, cmd, NULL)))
+return false;
+
+if ((nports = virNetworkListAllPorts(net, , flags)) < 0)
+return NULL;
+
+if (VIR_ALLOC_N(ret, nports + 1) < 0)
+goto error;
+
+for (i = 0; i < nports; i++) {
+char uuid[VIR_UUID_STRING_BUFLEN];
+
+if 

[libvirt] [PATCH v2 06/15] tools: Separate interface related completers into a file

2019-08-07 Thread Michal Privoznik
Mixing all completers in one file does not support
maintainability. Separate those completers which relate to
interfaces (e.g. they complete various interface aspects)
into virsh-completer-interface.c

Signed-off-by: Michal Privoznik 
---
 tools/Makefile.am |  1 +
 tools/virsh-completer-interface.c | 67 +++
 tools/virsh-completer-interface.h | 27 +
 tools/virsh-completer.c   | 42 ---
 tools/virsh-completer.h   |  5 +--
 5 files changed, 96 insertions(+), 46 deletions(-)
 create mode 100644 tools/virsh-completer-interface.c
 create mode 100644 tools/virsh-completer-interface.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 06c05303ed..7e3c9c35c9 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -219,6 +219,7 @@ virsh_SOURCES = \
virsh-checkpoint.c virsh-checkpoint.h \
virsh-completer.c virsh-completer.h \
virsh-completer-domain.c virsh-completer-domain.h \
+   virsh-completer-interface.c virsh-completer-interface.h \
virsh-completer-pool.c virsh-completer-pool.h \
virsh-completer-volume.c virsh-completer-volume.h \
virsh-console.c virsh-console.h \
diff --git a/tools/virsh-completer-interface.c 
b/tools/virsh-completer-interface.c
new file mode 100644
index 00..5dcdab8e92
--- /dev/null
+++ b/tools/virsh-completer-interface.c
@@ -0,0 +1,67 @@
+/*
+ * virsh-completer-interface.c: virsh completer callbacks related to interfaces
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include "virsh-completer-interface.h"
+#include "viralloc.h"
+#include "virsh.h"
+#include "virstring.h"
+
+char **
+virshInterfaceNameCompleter(vshControl *ctl,
+const vshCmd *cmd ATTRIBUTE_UNUSED,
+unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+virInterfacePtr *ifaces = NULL;
+int nifaces = 0;
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE |
+  VIR_CONNECT_LIST_INTERFACES_INACTIVE,
+  NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if ((nifaces = virConnectListAllInterfaces(priv->conn, , flags)) < 
0)
+return NULL;
+
+if (VIR_ALLOC_N(tmp, nifaces + 1) < 0)
+goto cleanup;
+
+for (i = 0; i < nifaces; i++) {
+const char *name = virInterfaceGetName(ifaces[i]);
+
+if (VIR_STRDUP(tmp[i], name) < 0)
+goto cleanup;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+
+ cleanup:
+for (i = 0; i < nifaces; i++)
+virInterfaceFree(ifaces[i]);
+VIR_FREE(ifaces);
+return ret;
+}
diff --git a/tools/virsh-completer-interface.h 
b/tools/virsh-completer-interface.h
new file mode 100644
index 00..893dee5a6b
--- /dev/null
+++ b/tools/virsh-completer-interface.h
@@ -0,0 +1,27 @@
+/*
+ * virsh-completer-interface.h: virsh completer callbacks related to interfaces
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#pragma once
+
+#include "vsh.h"
+
+char ** virshInterfaceNameCompleter(vshControl *ctl,
+const vshCmd *cmd,
+unsigned int flags);
diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index e6f04296a3..563ee180b6 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -143,48 +143,6 @@ virshCommaStringListComplete(const char *input,
 }
 
 
-char **

[libvirt] [PATCH v2 04/15] tools: Separate storage pool related completers into a file

2019-08-07 Thread Michal Privoznik
Mixing all completers in one file does not support
maintainability. Separate those completers which relate to
storage pools (e.g. they complete various storage pool aspects)
into virsh-completer-pool.c.

Signed-off-by: Michal Privoznik 
---
 tools/Makefile.am|  1 +
 tools/virsh-completer-pool.c | 93 
 tools/virsh-completer-pool.h | 31 
 tools/virsh-completer.c  | 67 --
 tools/virsh-completer.h  |  9 +---
 5 files changed, 126 insertions(+), 75 deletions(-)
 create mode 100644 tools/virsh-completer-pool.c
 create mode 100644 tools/virsh-completer-pool.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 4a3f72b357..a5ce6a45d4 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -219,6 +219,7 @@ virsh_SOURCES = \
virsh-checkpoint.c virsh-checkpoint.h \
virsh-completer.c virsh-completer.h \
virsh-completer-domain.c virsh-completer-domain.h \
+   virsh-completer-pool.c virsh-completer-pool.h \
virsh-console.c virsh-console.h \
virsh-domain.c virsh-domain.h \
virsh-domain-monitor.c virsh-domain-monitor.h \
diff --git a/tools/virsh-completer-pool.c b/tools/virsh-completer-pool.c
new file mode 100644
index 00..fc01550908
--- /dev/null
+++ b/tools/virsh-completer-pool.c
@@ -0,0 +1,93 @@
+/*
+ * virsh-completer-pool.c: virsh completer callbacks related to pools
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include "virsh-completer-pool.h"
+#include "viralloc.h"
+#include "virsh-pool.h"
+#include "virsh.h"
+#include "virstring.h"
+
+char **
+virshStoragePoolNameCompleter(vshControl *ctl,
+  const vshCmd *cmd ATTRIBUTE_UNUSED,
+  unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+virStoragePoolPtr *pools = NULL;
+int npools = 0;
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(VIR_CONNECT_LIST_STORAGE_POOLS_INACTIVE |
+  VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE |
+  VIR_CONNECT_LIST_STORAGE_POOLS_PERSISTENT,
+  NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if ((npools = virConnectListAllStoragePools(priv->conn, , flags)) < 
0)
+return NULL;
+
+if (VIR_ALLOC_N(tmp, npools + 1) < 0)
+goto cleanup;
+
+for (i = 0; i < npools; i++) {
+const char *name = virStoragePoolGetName(pools[i]);
+
+if (VIR_STRDUP(tmp[i], name) < 0)
+goto cleanup;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+
+ cleanup:
+for (i = 0; i < npools; i++)
+virStoragePoolFree(pools[i]);
+VIR_FREE(pools);
+return ret;
+}
+
+
+char **
+virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
+const vshCmd *cmd ATTRIBUTE_UNUSED,
+unsigned int flags)
+{
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(0, NULL);
+
+if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_EVENT_ID_LAST + 1) < 0)
+return NULL;
+
+for (i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) {
+if (VIR_STRDUP(tmp[i], virshPoolEventCallbacks[i].name) < 0)
+return NULL;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+return ret;
+}
diff --git a/tools/virsh-completer-pool.h b/tools/virsh-completer-pool.h
new file mode 100644
index 00..778ab25df2
--- /dev/null
+++ b/tools/virsh-completer-pool.h
@@ -0,0 +1,31 @@
+/*
+ * virsh-completer-pool.h: virsh completer callbacks related to pools
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should 

[libvirt] [PATCH v2 03/15] tools: Separate domain related completers into a file

2019-08-07 Thread Michal Privoznik
Mixing all completers in one file does not support
maintainability. Separate those completers which relate to
domains (e.g. they complete various domain aspects) into
virsh-completer-domain.c.

Signed-off-by: Michal Privoznik 
---
 tools/Makefile.am  |   1 +
 tools/virsh-completer-domain.c | 314 +
 tools/virsh-completer-domain.h |  55 ++
 tools/virsh-completer.c| 285 --
 tools/virsh-completer.h|  32 +---
 5 files changed, 371 insertions(+), 316 deletions(-)
 create mode 100644 tools/virsh-completer-domain.c
 create mode 100644 tools/virsh-completer-domain.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 2807b9f6fd..4a3f72b357 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -218,6 +218,7 @@ virsh_SOURCES = \
virsh.c virsh.h \
virsh-checkpoint.c virsh-checkpoint.h \
virsh-completer.c virsh-completer.h \
+   virsh-completer-domain.c virsh-completer-domain.h \
virsh-console.c virsh-console.h \
virsh-domain.c virsh-domain.h \
virsh-domain-monitor.c virsh-domain-monitor.h \
diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
new file mode 100644
index 00..9c10e38aba
--- /dev/null
+++ b/tools/virsh-completer-domain.c
@@ -0,0 +1,314 @@
+/*
+ * virsh-completer-domain.c: virsh completer callbacks related to domains
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include "virsh-completer-domain.h"
+#include "viralloc.h"
+#include "virmacaddr.h"
+#include "virsh-domain.h"
+#include "virsh-util.h"
+#include "virsh.h"
+#include "virstring.h"
+#include "virxml.h"
+
+char **
+virshDomainNameCompleter(vshControl *ctl,
+ const vshCmd *cmd ATTRIBUTE_UNUSED,
+ unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+virDomainPtr *domains = NULL;
+int ndomains = 0;
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(VIR_CONNECT_LIST_DOMAINS_ACTIVE |
+  VIR_CONNECT_LIST_DOMAINS_INACTIVE |
+  VIR_CONNECT_LIST_DOMAINS_OTHER |
+  VIR_CONNECT_LIST_DOMAINS_PAUSED |
+  VIR_CONNECT_LIST_DOMAINS_PERSISTENT |
+  VIR_CONNECT_LIST_DOMAINS_RUNNING |
+  VIR_CONNECT_LIST_DOMAINS_SHUTOFF,
+  NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if ((ndomains = virConnectListAllDomains(priv->conn, , flags)) < 0)
+return NULL;
+
+if (VIR_ALLOC_N(tmp, ndomains + 1) < 0)
+goto cleanup;
+
+for (i = 0; i < ndomains; i++) {
+const char *name = virDomainGetName(domains[i]);
+
+if (VIR_STRDUP(tmp[i], name) < 0)
+goto cleanup;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+
+ cleanup:
+for (i = 0; i < ndomains; i++)
+virshDomainFree(domains[i]);
+VIR_FREE(domains);
+return ret;
+}
+
+
+char **
+virshDomainInterfaceCompleter(vshControl *ctl,
+  const vshCmd *cmd,
+  unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+VIR_AUTOPTR(xmlDoc) xmldoc = NULL;
+VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
+int ninterfaces;
+VIR_AUTOFREE(xmlNodePtr *) interfaces = NULL;
+size_t i;
+unsigned int domainXMLFlags = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC, NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if (vshCommandOptBool(cmd, "config"))
+domainXMLFlags = VIR_DOMAIN_XML_INACTIVE;
+
+if (virshDomainGetXML(ctl, cmd, domainXMLFlags, , ) < 0)
+return NULL;
+
+ninterfaces = virXPathNodeSet("./devices/interface", ctxt, );
+if (ninterfaces < 0)
+return NULL;
+
+if (VIR_ALLOC_N(tmp, ninterfaces + 1) < 0)
+return NULL;
+
+for (i = 0; i < ninterfaces; i++) {
+ctxt->node = interfaces[i];
+
+if (!(flags & VIRSH_DOMAIN_INTERFACE_COMPLETER_MAC) &&
+(tmp[i] = virXPathString("string(./target/@dev)", ctxt)))
+   

[libvirt] [PATCH v2 02/15] tools: Expose virshCommaStringListComplete()

2019-08-07 Thread Michal Privoznik
In next commits the virsh-completer.c is going to be split into
smaller files. Expose virshCommaStringListComplete() so that it
can still be used from those new files.

Signed-off-by: Michal Privoznik 
---
 tools/virsh-completer.c | 2 +-
 tools/virsh-completer.h | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index 957db16003..476c3a95c4 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -96,7 +96,7 @@
  * Returns: string list of completions on success,
  *  NULL otherwise.
  */
-static char **
+char **
 virshCommaStringListComplete(const char *input,
  const char **options)
 {
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index fb41c2c89f..f7e638d67f 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -38,6 +38,9 @@ char ** virshDomainDiskTargetCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
 
+char ** virshCommaStringListComplete(const char *input,
+ const char **options);
+
 char ** virshStoragePoolNameCompleter(vshControl *ctl,
   const vshCmd *cmd,
   unsigned int flags);
-- 
2.21.0

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


[libvirt] [PATCH v2 11/15] tools: Separate snapshot related completers into a file

2019-08-07 Thread Michal Privoznik
Mixing all completers in one file does not support
maintainability. Separate those completers which relate to
snapshot (e.g. they complete various snapshot aspects)
into virsh-completer-snapshot.c

Signed-off-by: Michal Privoznik 
---
 tools/Makefile.am|  1 +
 tools/virsh-completer-snapshot.c | 73 
 tools/virsh-completer-snapshot.h | 27 
 tools/virsh-completer.c  | 45 
 tools/virsh-completer.h  |  5 +--
 5 files changed, 102 insertions(+), 49 deletions(-)
 create mode 100644 tools/virsh-completer-snapshot.c
 create mode 100644 tools/virsh-completer-snapshot.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index f229db39d8..3a89ec70a2 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -225,6 +225,7 @@ virsh_SOURCES = \
virsh-completer-nwfilter.c virsh-completer-nwfilter.h \
virsh-completer-pool.c virsh-completer-pool.h \
virsh-completer-secret.c virsh-completer-secret.h \
+   virsh-completer-snapshot.c virsh-completer-snapshot.h \
virsh-completer-volume.c virsh-completer-volume.h \
virsh-console.c virsh-console.h \
virsh-domain.c virsh-domain.h \
diff --git a/tools/virsh-completer-snapshot.c b/tools/virsh-completer-snapshot.c
new file mode 100644
index 00..cad56e2fba
--- /dev/null
+++ b/tools/virsh-completer-snapshot.c
@@ -0,0 +1,73 @@
+/*
+ * virsh-completer-snapshot.c: virsh completer callbacks related to snapshots
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include "virsh-completer-snapshot.h"
+#include "viralloc.h"
+#include "virsh-util.h"
+#include "virsh.h"
+#include "virstring.h"
+
+char **
+virshSnapshotNameCompleter(vshControl *ctl,
+   const vshCmd *cmd,
+   unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+virDomainPtr dom = NULL;
+virDomainSnapshotPtr *snapshots = NULL;
+int rc;
+int nsnapshots = 0;
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(0, NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+return NULL;
+
+if ((rc = virDomainListAllSnapshots(dom, , flags)) < 0)
+goto cleanup;
+nsnapshots = rc;
+
+if (VIR_ALLOC_N(tmp, nsnapshots + 1) < 0)
+goto cleanup;
+
+for (i = 0; i < nsnapshots; i++) {
+const char *name = virDomainSnapshotGetName(snapshots[i]);
+
+if (VIR_STRDUP(tmp[i], name) < 0)
+goto cleanup;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+
+ cleanup:
+virshDomainFree(dom);
+for (i = 0; i < nsnapshots; i++)
+virshDomainSnapshotFree(snapshots[i]);
+VIR_FREE(snapshots);
+return ret;
+}
diff --git a/tools/virsh-completer-snapshot.h b/tools/virsh-completer-snapshot.h
new file mode 100644
index 00..1af32e28ca
--- /dev/null
+++ b/tools/virsh-completer-snapshot.h
@@ -0,0 +1,27 @@
+/*
+ * virsh-completer-snapshot.h: virsh completer callbacks related to snapshots
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#pragma once
+
+#include "vsh.h"
+
+char ** virshSnapshotNameCompleter(vshControl *ctl,
+   const vshCmd *cmd,
+   unsigned int flags);
diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index 3489f8741a..72223803dd 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -194,51 

[libvirt] [PATCH v2 10/15] tools: Separate secret related completers into a file

2019-08-07 Thread Michal Privoznik
Mixing all completers in one file does not support
maintainability. Separate those completers which relate to
secret (e.g. they complete various secret aspects)
into virsh-completer-secret.c

Signed-off-by: Michal Privoznik 
---
 tools/Makefile.am  |  1 +
 tools/virsh-completer-secret.c | 91 ++
 tools/virsh-completer-secret.h | 31 
 tools/virsh-completer.c| 65 
 tools/virsh-completer.h|  9 +---
 5 files changed, 124 insertions(+), 73 deletions(-)
 create mode 100644 tools/virsh-completer-secret.c
 create mode 100644 tools/virsh-completer-secret.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 6e6d9a05cc..f229db39d8 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -224,6 +224,7 @@ virsh_SOURCES = \
virsh-completer-nodedev.c virsh-completer-nodedev.h \
virsh-completer-nwfilter.c virsh-completer-nwfilter.h \
virsh-completer-pool.c virsh-completer-pool.h \
+   virsh-completer-secret.c virsh-completer-secret.h \
virsh-completer-volume.c virsh-completer-volume.h \
virsh-console.c virsh-console.h \
virsh-domain.c virsh-domain.h \
diff --git a/tools/virsh-completer-secret.c b/tools/virsh-completer-secret.c
new file mode 100644
index 00..a6924b6b8c
--- /dev/null
+++ b/tools/virsh-completer-secret.c
@@ -0,0 +1,91 @@
+/*
+ * virsh-completer-secret.c: virsh completer callbacks related to secret
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include "virsh-completer-secret.h"
+#include "viralloc.h"
+#include "virsh-secret.h"
+#include "virsh.h"
+#include "virstring.h"
+
+char **
+virshSecretUUIDCompleter(vshControl *ctl,
+ const vshCmd *cmd ATTRIBUTE_UNUSED,
+ unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+virSecretPtr *secrets = NULL;
+int nsecrets = 0;
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(0, NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if ((nsecrets = virConnectListAllSecrets(priv->conn, , flags)) < 0)
+return NULL;
+
+if (VIR_ALLOC_N(tmp, nsecrets + 1) < 0)
+goto cleanup;
+
+for (i = 0; i < nsecrets; i++) {
+char uuid[VIR_UUID_STRING_BUFLEN];
+
+if (virSecretGetUUIDString(secrets[i], uuid) < 0 ||
+VIR_STRDUP(tmp[i], uuid) < 0)
+goto cleanup;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+
+ cleanup:
+for (i = 0; i < nsecrets; i++)
+virSecretFree(secrets[i]);
+VIR_FREE(secrets);
+return ret;
+}
+
+
+char **
+virshSecretEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
+  const vshCmd *cmd ATTRIBUTE_UNUSED,
+  unsigned int flags)
+{
+size_t i;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(0, NULL);
+
+if (VIR_ALLOC_N(tmp, VIR_SECRET_EVENT_ID_LAST + 1) < 0)
+return NULL;
+
+for (i = 0; i < VIR_SECRET_EVENT_ID_LAST; i++) {
+if (VIR_STRDUP(tmp[i], virshSecretEventCallbacks[i].name) < 0)
+return NULL;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+return ret;
+}
diff --git a/tools/virsh-completer-secret.h b/tools/virsh-completer-secret.h
new file mode 100644
index 00..3ed6ba5198
--- /dev/null
+++ b/tools/virsh-completer-secret.h
@@ -0,0 +1,31 @@
+/*
+ * virsh-completer-secret.h: virsh completer callbacks related to secret
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see

[libvirt] [PATCH v2 09/15] tools: Separate nwfilter related completers into a file

2019-08-07 Thread Michal Privoznik
Mixing all completers in one file does not support
maintainability. Separate those completers which relate to
nwfilter (e.g. they complete various nwfilter aspects)
into virsh-completer-nwfilter.c

Signed-off-by: Michal Privoznik 
---
 tools/Makefile.am|   1 +
 tools/virsh-completer-nwfilter.c | 105 +++
 tools/virsh-completer-nwfilter.h |  31 +
 tools/virsh-completer.c  |  80 ---
 tools/virsh-completer.h  |   9 +--
 5 files changed, 138 insertions(+), 88 deletions(-)
 create mode 100644 tools/virsh-completer-nwfilter.c
 create mode 100644 tools/virsh-completer-nwfilter.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index e31e0f636d..6e6d9a05cc 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -222,6 +222,7 @@ virsh_SOURCES = \
virsh-completer-interface.c virsh-completer-interface.h \
virsh-completer-network.c virsh-completer-network.h \
virsh-completer-nodedev.c virsh-completer-nodedev.h \
+   virsh-completer-nwfilter.c virsh-completer-nwfilter.h \
virsh-completer-pool.c virsh-completer-pool.h \
virsh-completer-volume.c virsh-completer-volume.h \
virsh-console.c virsh-console.h \
diff --git a/tools/virsh-completer-nwfilter.c b/tools/virsh-completer-nwfilter.c
new file mode 100644
index 00..0942526f22
--- /dev/null
+++ b/tools/virsh-completer-nwfilter.c
@@ -0,0 +1,105 @@
+/*
+ * virsh-completer-nwfilter.c: virsh completer callbacks related to nwfilters
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include "virsh-completer-nwfilter.h"
+#include "viralloc.h"
+#include "virsh.h"
+#include "virstring.h"
+
+char **
+virshNWFilterNameCompleter(vshControl *ctl,
+   const vshCmd *cmd ATTRIBUTE_UNUSED,
+   unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+virNWFilterPtr *nwfilters = NULL;
+int nnwfilters = 0;
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(0, NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if ((nnwfilters = virConnectListAllNWFilters(priv->conn, , 
flags)) < 0)
+return NULL;
+
+if (VIR_ALLOC_N(tmp, nnwfilters + 1) < 0)
+goto cleanup;
+
+for (i = 0; i < nnwfilters; i++) {
+const char *name = virNWFilterGetName(nwfilters[i]);
+
+if (VIR_STRDUP(tmp[i], name) < 0)
+goto cleanup;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+
+ cleanup:
+for (i = 0; i < nnwfilters; i++)
+virNWFilterFree(nwfilters[i]);
+VIR_FREE(nwfilters);
+return ret;
+}
+
+
+char **
+virshNWFilterBindingNameCompleter(vshControl *ctl,
+  const vshCmd *cmd ATTRIBUTE_UNUSED,
+  unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+virNWFilterBindingPtr *bindings = NULL;
+int nbindings = 0;
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(0, NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if ((nbindings = virConnectListAllNWFilterBindings(priv->conn, , 
flags)) < 0)
+return NULL;
+
+if (VIR_ALLOC_N(tmp, nbindings + 1) < 0)
+goto cleanup;
+
+for (i = 0; i < nbindings; i++) {
+const char *name = virNWFilterBindingGetPortDev(bindings[i]);
+
+if (VIR_STRDUP(tmp[i], name) < 0)
+goto cleanup;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+
+ cleanup:
+for (i = 0; i < nbindings; i++)
+virNWFilterBindingFree(bindings[i]);
+VIR_FREE(bindings);
+return ret;
+}
diff --git a/tools/virsh-completer-nwfilter.h b/tools/virsh-completer-nwfilter.h
new file mode 100644
index 00..86e7df7da4
--- /dev/null
+++ b/tools/virsh-completer-nwfilter.h
@@ -0,0 +1,31 @@
+/*
+ * virsh-completer-nwfilter.h: virsh completer callbacks related to nwfilters
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software 

[libvirt] [PATCH v2 00/15] Split and enhancement of virsh completer

2019-08-07 Thread Michal Privoznik
v2 of:

https://www.redhat.com/archives/libvir-list/2019-July/msg01225.html

diff to v1:
- Rebase and adapt to new checkpoint completer

Michal Prívozník (15):
  tools: s/Nodedev/NodeDevice/
  tools: Expose virshCommaStringListComplete()
  tools: Separate domain related completers into a file
  tools: Separate storage pool related completers into a file
  tools: Separate storage volume related completers into a file
  tools: Separate interface related completers into a file
  tools: Separate network related completers into a file
  tools: Separate nodedev related completers into a file
  tools: Separate nwfilter related completers into a file
  tools: Separate secret related completers into a file
  tools: Separate snapshot related completers into a file
  tools: Separate host related completers into a file
  tools: Separate checkpoint related completers into a file
  virsh-completer: Drop needless #include
  virsh: Introduce virshPoolTypeCompleter

 tools/Makefile.am  |   11 +
 tools/virsh-completer-checkpoint.c |   78 +++
 tools/virsh-completer-checkpoint.h |   27 +
 tools/virsh-completer-domain.c |  314 +
 tools/virsh-completer-domain.h |   55 ++
 tools/virsh-completer-host.c   |  148 
 tools/virsh-completer-host.h   |   31 +
 tools/virsh-completer-interface.c  |   67 ++
 tools/virsh-completer-interface.h  |   27 +
 tools/virsh-completer-network.c|  145 
 tools/virsh-completer-network.h|   35 +
 tools/virsh-completer-nodedev.c|  117 
 tools/virsh-completer-nodedev.h|   35 +
 tools/virsh-completer-nwfilter.c   |  105 +++
 tools/virsh-completer-nwfilter.h   |   31 +
 tools/virsh-completer-pool.c   |  120 
 tools/virsh-completer-pool.h   |   35 +
 tools/virsh-completer-secret.c |   91 +++
 tools/virsh-completer-secret.h |   31 +
 tools/virsh-completer-snapshot.c   |   73 ++
 tools/virsh-completer-snapshot.h   |   27 +
 tools/virsh-completer-volume.c |   73 ++
 tools/virsh-completer-volume.h |   28 +
 tools/virsh-completer.c| 1028 +---
 tools/virsh-completer.h|  114 +--
 tools/virsh-nodedev.c  |   16 +-
 tools/virsh-nodedev.h  |6 +-
 tools/virsh-pool.c |1 +
 28 files changed, 1730 insertions(+), 1139 deletions(-)
 create mode 100644 tools/virsh-completer-checkpoint.c
 create mode 100644 tools/virsh-completer-checkpoint.h
 create mode 100644 tools/virsh-completer-domain.c
 create mode 100644 tools/virsh-completer-domain.h
 create mode 100644 tools/virsh-completer-host.c
 create mode 100644 tools/virsh-completer-host.h
 create mode 100644 tools/virsh-completer-interface.c
 create mode 100644 tools/virsh-completer-interface.h
 create mode 100644 tools/virsh-completer-network.c
 create mode 100644 tools/virsh-completer-network.h
 create mode 100644 tools/virsh-completer-nodedev.c
 create mode 100644 tools/virsh-completer-nodedev.h
 create mode 100644 tools/virsh-completer-nwfilter.c
 create mode 100644 tools/virsh-completer-nwfilter.h
 create mode 100644 tools/virsh-completer-pool.c
 create mode 100644 tools/virsh-completer-pool.h
 create mode 100644 tools/virsh-completer-secret.c
 create mode 100644 tools/virsh-completer-secret.h
 create mode 100644 tools/virsh-completer-snapshot.c
 create mode 100644 tools/virsh-completer-snapshot.h
 create mode 100644 tools/virsh-completer-volume.c
 create mode 100644 tools/virsh-completer-volume.h

-- 
2.21.0

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

[libvirt] [PATCH v2 12/15] tools: Separate host related completers into a file

2019-08-07 Thread Michal Privoznik
Mixing all completers in one file does not support
maintainability. Separate those completers which relate to
host (e.g. they complete various host aspects)
into virsh-completer-host.c

Signed-off-by: Michal Privoznik 
---
 tools/Makefile.am|   1 +
 tools/virsh-completer-host.c | 148 +++
 tools/virsh-completer-host.h |  31 
 tools/virsh-completer.c  | 121 
 tools/virsh-completer.h  |   9 +--
 5 files changed, 181 insertions(+), 129 deletions(-)
 create mode 100644 tools/virsh-completer-host.c
 create mode 100644 tools/virsh-completer-host.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 3a89ec70a2..43083f4afa 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -219,6 +219,7 @@ virsh_SOURCES = \
virsh-checkpoint.c virsh-checkpoint.h \
virsh-completer.c virsh-completer.h \
virsh-completer-domain.c virsh-completer-domain.h \
+   virsh-completer-host.c virsh-completer-host.h \
virsh-completer-interface.c virsh-completer-interface.h \
virsh-completer-network.c virsh-completer-network.h \
virsh-completer-nodedev.c virsh-completer-nodedev.h \
diff --git a/tools/virsh-completer-host.c b/tools/virsh-completer-host.c
new file mode 100644
index 00..7e31ca2bf3
--- /dev/null
+++ b/tools/virsh-completer-host.c
@@ -0,0 +1,148 @@
+/*
+ * virsh-completer-host.c: virsh completer callbacks related to host
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include "virsh-completer-host.h"
+#include "viralloc.h"
+#include "virsh.h"
+#include "virstring.h"
+#include "virxml.h"
+#include "virutil.h"
+
+static char *
+virshPagesizeNodeToString(xmlNodePtr node)
+{
+VIR_AUTOFREE(char *) pagesize = NULL;
+VIR_AUTOFREE(char *) unit = NULL;
+unsigned long long byteval = 0;
+const char *suffix = NULL;
+double size = 0;
+char *ret;
+
+pagesize = virXMLPropString(node, "size");
+unit = virXMLPropString(node, "unit");
+if (virStrToLong_ull(pagesize, NULL, 10, ) < 0)
+return NULL;
+if (virScaleInteger(, unit, 1024, UINT_MAX) < 0)
+return NULL;
+size = vshPrettyCapacity(byteval, );
+if (virAsprintf(, "%.0f%s", size, suffix) < 0)
+return NULL;
+return ret;
+}
+
+char **
+virshAllocpagesPagesizeCompleter(vshControl *ctl,
+ const vshCmd *cmd ATTRIBUTE_UNUSED,
+ unsigned int flags)
+{
+VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
+virshControlPtr priv = ctl->privData;
+unsigned int npages = 0;
+VIR_AUTOFREE(xmlNodePtr *) pages = NULL;
+VIR_AUTOPTR(xmlDoc) doc = NULL;
+size_t i = 0;
+const char *cellnum = NULL;
+bool cellno = vshCommandOptBool(cmd, "cellno");
+VIR_AUTOFREE(char *) path = NULL;
+VIR_AUTOFREE(char *) cap_xml = NULL;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(0, NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if (!(cap_xml = virConnectGetCapabilities(priv->conn)))
+return NULL;
+
+if (!(doc = virXMLParseStringCtxt(cap_xml, _("capabilities"), )))
+return NULL;
+
+if (cellno && vshCommandOptStringQuiet(ctl, cmd, "cellno", ) > 0) {
+if (virAsprintf(,
+
"/capabilities/host/topology/cells/cell[@id=\"%s\"]/pages",
+cellnum) < 0)
+return NULL;
+} else {
+if (virAsprintf(, "/capabilities/host/cpu/pages") < 0)
+return NULL;
+}
+
+npages = virXPathNodeSet(path, ctxt, );
+if (npages <= 0)
+return NULL;
+
+if (VIR_ALLOC_N(tmp, npages + 1) < 0)
+return NULL;
+
+for (i = 0; i < npages; i++) {
+if (!(tmp[i] = virshPagesizeNodeToString(pages[i])))
+return NULL;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+return ret;
+}
+
+
+char **
+virshCellnoCompleter(vshControl *ctl,
+ const vshCmd *cmd ATTRIBUTE_UNUSED,
+ unsigned int flags)
+{
+VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
+virshControlPtr priv = ctl->privData;
+unsigned int ncells = 0;
+

[libvirt] [PATCH v2 15/15] virsh: Introduce virshPoolTypeCompleter

2019-08-07 Thread Michal Privoznik
This completer can be used to complete pool types.

Signed-off-by: Michal Privoznik 
---
 tools/virsh-completer-pool.c | 27 +++
 tools/virsh-completer-pool.h |  4 
 tools/virsh-pool.c   |  1 +
 3 files changed, 32 insertions(+)

diff --git a/tools/virsh-completer-pool.c b/tools/virsh-completer-pool.c
index fc01550908..9703589522 100644
--- a/tools/virsh-completer-pool.c
+++ b/tools/virsh-completer-pool.c
@@ -21,6 +21,7 @@
 #include 
 
 #include "virsh-completer-pool.h"
+#include "conf/storage_conf.h"
 #include "viralloc.h"
 #include "virsh-pool.h"
 #include "virsh.h"
@@ -91,3 +92,29 @@ virshPoolEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
 VIR_STEAL_PTR(ret, tmp);
 return ret;
 }
+
+
+char **
+virshPoolTypeCompleter(vshControl *ctl,
+   const vshCmd *cmd,
+   unsigned int flags)
+{
+VIR_AUTOSTRINGLIST tmp = NULL;
+const char *type_str = NULL;
+size_t i = 0;
+
+virCheckFlags(0, NULL);
+
+if (vshCommandOptStringQuiet(ctl, cmd, "type", _str) < 0)
+return NULL;
+
+if (VIR_ALLOC_N(tmp, VIR_STORAGE_POOL_LAST + 1) < 0)
+return NULL;
+
+for (i = 0; i < VIR_STORAGE_POOL_LAST; i++) {
+if (VIR_STRDUP(tmp[i], virStoragePoolTypeToString(i)) < 0)
+return NULL;
+}
+
+return virshCommaStringListComplete(type_str, (const char **)tmp);
+}
diff --git a/tools/virsh-completer-pool.h b/tools/virsh-completer-pool.h
index 778ab25df2..510233fb65 100644
--- a/tools/virsh-completer-pool.h
+++ b/tools/virsh-completer-pool.h
@@ -29,3 +29,7 @@ char ** virshStoragePoolNameCompleter(vshControl *ctl,
 char ** virshPoolEventNameCompleter(vshControl *ctl,
 const vshCmd *cmd,
 unsigned int flags);
+
+char ** virshPoolTypeCompleter(vshControl *ctl,
+   const vshCmd *cmd,
+   unsigned int flags);
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index 510d41b508..96ef626346 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -1095,6 +1095,7 @@ static const vshCmdOptDef opts_pool_list[] = {
 },
 {.name = "type",
  .type = VSH_OT_STRING,
+ .completer = virshPoolTypeCompleter,
  .help = N_("only list pool of specified type(s) (if supported)")
 },
 {.name = "details",
-- 
2.21.0

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


[libvirt] [PATCH v2 13/15] tools: Separate checkpoint related completers into a file

2019-08-07 Thread Michal Privoznik
Mixing all completers in one file does not support
maintainability. Separate those completers which relate to
host (e.g. they complete various checkpoint aspects)
into virsh-completer-checkpoint.c

Signed-off-by: Michal Privoznik 
---
 tools/Makefile.am  |  1 +
 tools/virsh-completer-checkpoint.c | 78 ++
 tools/virsh-completer-checkpoint.h | 27 +++
 tools/virsh-completer.c| 52 
 4 files changed, 106 insertions(+), 52 deletions(-)
 create mode 100644 tools/virsh-completer-checkpoint.c
 create mode 100644 tools/virsh-completer-checkpoint.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index 43083f4afa..274f941d74 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -219,6 +219,7 @@ virsh_SOURCES = \
virsh-checkpoint.c virsh-checkpoint.h \
virsh-completer.c virsh-completer.h \
virsh-completer-domain.c virsh-completer-domain.h \
+   virsh-completer-checkpoint.c virsh-completer-checkpoint.h \
virsh-completer-host.c virsh-completer-host.h \
virsh-completer-interface.c virsh-completer-interface.h \
virsh-completer-network.c virsh-completer-network.h \
diff --git a/tools/virsh-completer-checkpoint.c 
b/tools/virsh-completer-checkpoint.c
new file mode 100644
index 00..ce9d32844d
--- /dev/null
+++ b/tools/virsh-completer-checkpoint.c
@@ -0,0 +1,78 @@
+/*
+ * virsh-completer-checkpoint.c: virsh completer callbacks related to 
checkpoints
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include "virsh-completer-checkpoint.h"
+#include "viralloc.h"
+#include "virsh-util.h"
+#include "virsh.h"
+#include "virstring.h"
+
+char **
+virshCheckpointNameCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+virDomainPtr dom = NULL;
+virDomainCheckpointPtr *checkpoints = NULL;
+int ncheckpoints = 0;
+size_t i = 0;
+char **ret = NULL;
+
+virCheckFlags(0, NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+return NULL;
+
+if ((ncheckpoints = virDomainListAllCheckpoints(dom, ,
+flags)) < 0)
+goto error;
+
+if (VIR_ALLOC_N(ret, ncheckpoints + 1) < 0)
+goto error;
+
+for (i = 0; i < ncheckpoints; i++) {
+const char *name = virDomainCheckpointGetName(checkpoints[i]);
+
+if (VIR_STRDUP(ret[i], name) < 0)
+goto error;
+
+virshDomainCheckpointFree(checkpoints[i]);
+}
+VIR_FREE(checkpoints);
+virshDomainFree(dom);
+
+return ret;
+
+ error:
+for (; i < ncheckpoints; i++)
+virshDomainCheckpointFree(checkpoints[i]);
+VIR_FREE(checkpoints);
+for (i = 0; i < ncheckpoints; i++)
+VIR_FREE(ret[i]);
+VIR_FREE(ret);
+virshDomainFree(dom);
+return NULL;
+}
diff --git a/tools/virsh-completer-checkpoint.h 
b/tools/virsh-completer-checkpoint.h
new file mode 100644
index 00..c536a3ffda
--- /dev/null
+++ b/tools/virsh-completer-checkpoint.h
@@ -0,0 +1,27 @@
+/*
+ * virsh-completer-checkpoint.h: virsh completer callbacks related to 
checkpoints
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#pragma once
+
+#include "vsh.h"
+
+char ** virshCheckpointNameCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+   

[libvirt] [PATCH v2 08/15] tools: Separate nodedev related completers into a file

2019-08-07 Thread Michal Privoznik
Mixing all completers in one file does not support
maintainability. Separate those completers which relate to
nodedev (e.g. they complete various nodedev aspects)
into virsh-completer-nodedev.c

Signed-off-by: Michal Privoznik 
---
 tools/Makefile.am   |   1 +
 tools/virsh-completer-nodedev.c | 117 
 tools/virsh-completer-nodedev.h |  35 ++
 tools/virsh-completer.c |  90 
 tools/virsh-completer.h |  13 +---
 5 files changed, 154 insertions(+), 102 deletions(-)
 create mode 100644 tools/virsh-completer-nodedev.c
 create mode 100644 tools/virsh-completer-nodedev.h

diff --git a/tools/Makefile.am b/tools/Makefile.am
index fb42277269..e31e0f636d 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -221,6 +221,7 @@ virsh_SOURCES = \
virsh-completer-domain.c virsh-completer-domain.h \
virsh-completer-interface.c virsh-completer-interface.h \
virsh-completer-network.c virsh-completer-network.h \
+   virsh-completer-nodedev.c virsh-completer-nodedev.h \
virsh-completer-pool.c virsh-completer-pool.h \
virsh-completer-volume.c virsh-completer-volume.h \
virsh-console.c virsh-console.h \
diff --git a/tools/virsh-completer-nodedev.c b/tools/virsh-completer-nodedev.c
new file mode 100644
index 00..36f38acd57
--- /dev/null
+++ b/tools/virsh-completer-nodedev.c
@@ -0,0 +1,117 @@
+/*
+ * virsh-completer-nodedev.c: virsh completer callbacks related to nodedev
+ *
+ * Copyright (C) 2019 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include "virsh-completer-nodedev.h"
+#include "conf/node_device_conf.h"
+#include "viralloc.h"
+#include "virsh-nodedev.h"
+#include "virsh.h"
+#include "virstring.h"
+
+char **
+virshNodeDeviceNameCompleter(vshControl *ctl,
+ const vshCmd *cmd ATTRIBUTE_UNUSED,
+ unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+virNodeDevicePtr *devs = NULL;
+int ndevs = 0;
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(0, NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if ((ndevs = virConnectListAllNodeDevices(priv->conn, , flags)) < 0)
+return NULL;
+
+if (VIR_ALLOC_N(tmp, ndevs + 1) < 0)
+goto cleanup;
+
+for (i = 0; i < ndevs; i++) {
+const char *name = virNodeDeviceGetName(devs[i]);
+
+if (VIR_STRDUP(tmp[i], name) < 0)
+goto cleanup;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+
+ cleanup:
+for (i = 0; i < ndevs; i++)
+virNodeDeviceFree(devs[i]);
+VIR_FREE(devs);
+return ret;
+}
+
+
+char **
+virshNodeDeviceEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
+  const vshCmd *cmd ATTRIBUTE_UNUSED,
+  unsigned int flags)
+{
+size_t i = 0;
+char **ret = NULL;
+VIR_AUTOSTRINGLIST tmp = NULL;
+
+virCheckFlags(0, NULL);
+
+if (VIR_ALLOC_N(tmp, VIR_NODE_DEVICE_EVENT_ID_LAST + 1) < 0)
+return NULL;
+
+for (i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) {
+if (VIR_STRDUP(tmp[i], virshNodeDeviceEventCallbacks[i].name) < 0)
+return NULL;
+}
+
+VIR_STEAL_PTR(ret, tmp);
+return ret;
+}
+
+
+char **
+virshNodeDeviceCapabilityNameCompleter(vshControl *ctl,
+   const vshCmd *cmd,
+   unsigned int flags)
+{
+VIR_AUTOSTRINGLIST tmp = NULL;
+const char *cap_str = NULL;
+size_t i = 0;
+
+virCheckFlags(0, NULL);
+
+if (vshCommandOptStringQuiet(ctl, cmd, "cap", _str) < 0)
+return NULL;
+
+if (VIR_ALLOC_N(tmp, VIR_NODE_DEV_CAP_LAST + 1) < 0)
+return NULL;
+
+for (i = 0; i < VIR_NODE_DEV_CAP_LAST; i++) {
+if (VIR_STRDUP(tmp[i], virNodeDevCapTypeToString(i)) < 0)
+return NULL;
+}
+
+return virshCommaStringListComplete(cap_str, (const char **)tmp);
+}
diff --git a/tools/virsh-completer-nodedev.h b/tools/virsh-completer-nodedev.h
new file mode 100644
index 00..45c0b73c8c
--- /dev/null
+++ b/tools/virsh-completer-nodedev.h
@@ -0,0 +1,35 

[libvirt] [PATCH v2 01/15] tools: s/Nodedev/NodeDevice/

2019-08-07 Thread Michal Privoznik
The proper name is [vir|virsh]NodeDevice* and not Nodedev.
Fortunately, there are only handful of offenders.

Signed-off-by: Michal Privoznik 
---
 tools/virsh-completer.c | 14 +++---
 tools/virsh-completer.h | 12 ++--
 tools/virsh-nodedev.c   | 16 
 tools/virsh-nodedev.h   |  6 +++---
 4 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index 4fa6b19225..957db16003 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -1004,9 +1004,9 @@ virshDomainInterfaceStateCompleter(vshControl *ctl,
 
 
 char **
-virshNodedevEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
-   const vshCmd *cmd ATTRIBUTE_UNUSED,
-   unsigned int flags)
+virshNodeDeviceEventNameCompleter(vshControl *ctl ATTRIBUTE_UNUSED,
+  const vshCmd *cmd ATTRIBUTE_UNUSED,
+  unsigned int flags)
 {
 size_t i = 0;
 char **ret = NULL;
@@ -1018,7 +1018,7 @@ virshNodedevEventNameCompleter(vshControl *ctl 
ATTRIBUTE_UNUSED,
 return NULL;
 
 for (i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) {
-if (VIR_STRDUP(tmp[i], virshNodedevEventCallbacks[i].name) < 0)
+if (VIR_STRDUP(tmp[i], virshNodeDeviceEventCallbacks[i].name) < 0)
 return NULL;
 }
 
@@ -1028,9 +1028,9 @@ virshNodedevEventNameCompleter(vshControl *ctl 
ATTRIBUTE_UNUSED,
 
 
 char **
-virshNodedevCapabilityNameCompleter(vshControl *ctl,
-const vshCmd *cmd,
-unsigned int flags)
+virshNodeDeviceCapabilityNameCompleter(vshControl *ctl,
+   const vshCmd *cmd,
+   unsigned int flags)
 {
 VIR_AUTOSTRINGLIST tmp = NULL;
 const char *cap_str = NULL;
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index 2e54dddc05..fb41c2c89f 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -106,13 +106,13 @@ char ** virshDomainInterfaceStateCompleter(vshControl 
*ctl,
const vshCmd *cmd,
unsigned int flags);
 
-char ** virshNodedevEventNameCompleter(vshControl *ctl,
-   const vshCmd *cmd,
-   unsigned int flags);
+char ** virshNodeDeviceEventNameCompleter(vshControl *ctl,
+  const vshCmd *cmd,
+  unsigned int flags);
 
-char ** virshNodedevCapabilityNameCompleter(vshControl *ctl,
-const vshCmd *cmd,
-unsigned int flags);
+char ** virshNodeDeviceCapabilityNameCompleter(vshControl *ctl,
+   const vshCmd *cmd,
+   unsigned int flags);
 
 char ** virshDomainDeviceAliasCompleter(vshControl *ctl,
 const vshCmd *cmd,
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index e8372a4daf..b21e2e2fcc 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -375,7 +375,7 @@ static const vshCmdOptDef opts_node_list_devices[] = {
 },
 {.name = "cap",
  .type = VSH_OT_STRING,
- .completer = virshNodedevCapabilityNameCompleter,
+ .completer = virshNodeDeviceCapabilityNameCompleter,
  .help = N_("capability names, separated by comma")
 },
 {.name = NULL}
@@ -775,7 +775,7 @@ struct virshNodeDeviceEventData {
 bool loop;
 bool timestamp;
 int count;
-virshNodedevEventCallback *cb;
+virshNodeDeviceEventCallback *cb;
 };
 typedef struct virshNodeDeviceEventData virshNodeDeviceEventData;
 
@@ -841,12 +841,12 @@ vshEventGenericPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
 vshEventDone(data->ctl);
 }
 
-virshNodedevEventCallback virshNodedevEventCallbacks[] = {
+virshNodeDeviceEventCallback virshNodeDeviceEventCallbacks[] = {
 { "lifecycle",
   VIR_NODE_DEVICE_EVENT_CALLBACK(vshEventLifecyclePrint), },
 { "update", vshEventGenericPrint, }
 };
-verify(VIR_NODE_DEVICE_EVENT_ID_LAST == 
ARRAY_CARDINALITY(virshNodedevEventCallbacks));
+verify(VIR_NODE_DEVICE_EVENT_ID_LAST == 
ARRAY_CARDINALITY(virshNodeDeviceEventCallbacks));
 
 
 static const vshCmdInfo info_node_device_event[] = {
@@ -867,7 +867,7 @@ static const vshCmdOptDef opts_node_device_event[] = {
 },
 {.name = "event",
  .type = VSH_OT_STRING,
- .completer = virshNodedevEventNameCompleter,
+ .completer = virshNodeDeviceEventNameCompleter,
  .help = N_("which event type to wait for")
 },
 {.name = "loop",
@@ -906,7 +906,7 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cmd)
 size_t i;
 
 for (i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++)

[libvirt] [PATCH v2 14/15] virsh-completer: Drop needless #include

2019-08-07 Thread Michal Privoznik
Now that there is no code in virsh-completer.c it doesn't make
much sense to keep those #include-s around. Delete them.

Signed-off-by: Michal Privoznik 
---
 tools/virsh-completer.c | 13 -
 tools/virsh-completer.h |  2 --
 2 files changed, 15 deletions(-)

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index 0f1709b4ba..1fa66b4081 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -21,21 +21,8 @@
 #include 
 
 #include "virsh-completer.h"
-#include "virsh-domain.h"
-#include "virsh.h"
-#include "virsh-pool.h"
-#include "virsh-nodedev.h"
-#include "virsh-util.h"
-#include "virsh-secret.h"
-#include "virsh-network.h"
-#include "internal.h"
-#include "virutil.h"
 #include "viralloc.h"
-#include "virmacaddr.h"
 #include "virstring.h"
-#include "virxml.h"
-#include "conf/node_device_conf.h"
-
 
 /**
  * A completer callback is a function that accepts three arguments:
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index bfe304411b..7edb8e2f7e 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -20,8 +20,6 @@
 
 #pragma once
 
-#include "vsh.h"
-
 #include "virsh-completer-domain.h"
 #include "virsh-completer-host.h"
 #include "virsh-completer-interface.h"
-- 
2.21.0

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


Re: [libvirt] [PATCH 2/2] test_driver: implement virDomainSetBlockIoTune

2019-08-07 Thread Ilias Stamatis
On Sun, Aug 4, 2019 at 6:32 PM Erik Skultety  wrote:
>
> On Sat, Jul 27, 2019 at 05:04:38PM +0200, Ilias Stamatis wrote:
> > Signed-off-by: Ilias Stamatis 
> > ---
> >
> > I deliberately omitted the logic from qemuDomainSetBlockIoTuneDefaults
> > in order to leave the function simpler. I think that in the case of the
> > test driver it is ok.
> >
> > After all, how we handle the parameters it is supposed to be
> > hypervisor-specific.
> >
> >  src/test/test_driver.c | 196 +
> >  1 file changed, 196 insertions(+)
> >
> > diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> > index 9f4e255e35..3272ecf4b7 100755
> > --- a/src/test/test_driver.c
> > +++ b/src/test/test_driver.c
> > @@ -3502,6 +3502,201 @@ testDomainGetInterfaceParameters(virDomainPtr dom,
> >  }
> >
> >
> > +static int
> > +testDomainSetBlockIoTune(virDomainPtr dom,
> > + const char *path,
> > + virTypedParameterPtr params,
> > + int nparams,
> > + unsigned int flags)
> > +{
> > +virDomainObjPtr vm = NULL;
> > +virDomainDefPtr def = NULL;
> > +virDomainBlockIoTuneInfo info = {0};
> > +virDomainDiskDefPtr conf_disk = NULL;
> > +virTypedParameterPtr eventParams = NULL;
> > +int eventNparams = 0;
> > +int eventMaxparams = 0;
> > +size_t i;
> > +int ret = -1;
> > +
> > +virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
> > +  VIR_DOMAIN_AFFECT_CONFIG, -1);
> > +
> > +if (virTypedParamsValidate(params, nparams,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_SIZE_IOPS_SEC,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME,
> > +   VIR_TYPED_PARAM_STRING,
> > +   
> > VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC_MAX_LENGTH,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   
> > VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC_MAX_LENGTH,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   
> > VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC_MAX_LENGTH,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   
> > VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC_MAX_LENGTH,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   
> > VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC_MAX_LENGTH,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   
> > VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC_MAX_LENGTH,
> > +   VIR_TYPED_PARAM_ULLONG,
> > +   NULL) < 0)
> > +return -1;
> > +
> > +if (!(vm = testDomObjFromDomain(dom)))
> > +return -1;
> > +
> > +if (!(def = virDomainObjGetOneDef(vm, flags)))
> > +goto cleanup;
> > +
> > +if (!(conf_disk = virDomainDiskByName(def, path, true))) {
> > +virReportError(VIR_ERR_INVALID_ARG,
> > +   _("missing persistent configuration for disk '%s'"),
> > +   path);
> > +goto cleanup;
> > +}
> > +
> > +info = conf_disk->blkdeviotune;
> > +if 

Re: [libvirt] [PATCH] build: Solve mingw build clash with DATADIR

2019-08-07 Thread Eric Blake
On 7/31/19 2:30 PM, Eric Blake wrote:
> Commit fed58d83 was a hack to fix a mingw build failure due to header
> inclusion order resulting in a clash over the use of DATADIR, by
> repeating a trick made several other times in the past of tweaking
> inclusion order until it goes away.  Better is to revert that, and
> instead use pragmas to avoid the clash in the first place, regardless
> of header ordering, solving it for everyone in the future.
> 
> Signed-off-by: Eric Blake 
> ---
> 
> I tested that both gcc and clang on F29 support this; but it will take
> a full CI run to see if everywhere else is okay with it. Thus, it is
> not 5.6 material.

Ping now that we are in 5.7

> 
>  src/util/viratomic.h   | 3 +++
>  src/conf/checkpoint_conf.c | 2 --
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/src/util/viratomic.h b/src/util/viratomic.h
> index 35800dafcd..c6e7668324 100644
> --- a/src/util/viratomic.h
> +++ b/src/util/viratomic.h
> @@ -218,7 +218,10 @@ VIR_STATIC unsigned int virAtomicIntXor(volatile 
> unsigned int *atomic,
> 
>  # ifdef VIR_ATOMIC_OPS_WIN32
> 
> +#  pragma push_macro("DATADIR") /* If "configmake.h" was included first */
> +#  undef DATADIR
>  #  include 
> +#  pragma pop_macro("DATADIR")
>  #  include 
>  #  include 
>  #  if !defined(_M_AMD64) && !defined (_M_IA64) && !defined(_M_X64)
> diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c
> index 5ce4cc4853..5f4c275dd8 100644
> --- a/src/conf/checkpoint_conf.c
> +++ b/src/conf/checkpoint_conf.c
> @@ -21,8 +21,6 @@
> 
>  #include 
> 
> -#include 
> -
>  #include "configmake.h"
>  #include "internal.h"
>  #include "virbitmap.h"
> 

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



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

[libvirt] [PATCH v2 1/2] test_driver: make testDomainGetTime read time from vm-private data

2019-08-07 Thread Ilias Stamatis
Until now, testDomainGetTime would always return the same fixed values
everytime it was called. By using domain-private data we can make this
API return the values previously set with testDomainSetTime, or use the
same old fixed values in case testDomainSetTime hasn't been called at all.

Signed-off-by: Ilias Stamatis 
Reviewed-by: Erik Skultety 
---
 src/test/test_driver.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 6bca4e277f..3e2cd3a9a4 100755
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -392,6 +392,10 @@ struct _testDomainObjPrivate {
 testDriverPtr driver;

 bool frozen[2]; /* used by file system related calls */
+
+/* used by get/set time APIs */
+long long seconds;
+unsigned int nseconds;
 };


@@ -406,6 +410,9 @@ testDomainObjPrivateAlloc(void *opaque)
 priv->driver = opaque;
 priv->frozen[0] = priv->frozen[1] = false;

+priv->seconds = 627319920;
+priv->nseconds = 0;
+
 return priv;
 }

@@ -2104,6 +2111,7 @@ testDomainGetTime(virDomainPtr dom,
   unsigned int flags)
 {
 virDomainObjPtr vm = NULL;
+testDomainObjPrivatePtr priv;
 int ret = -1;

 virCheckFlags(0, -1);
@@ -2117,8 +2125,9 @@ testDomainGetTime(virDomainPtr dom,
 goto cleanup;
 }

-*seconds = 627319920;
-*nseconds = 0;
+priv = vm->privateData;
+*seconds = priv->seconds;
+*nseconds = priv->nseconds;

 ret = 0;
  cleanup:
--
2.22.0

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


[libvirt] [PATCH v2 2/2] test_driver: implement virDomainSetTime

2019-08-07 Thread Ilias Stamatis
Signed-off-by: Ilias Stamatis 
Reviewed-by: Erik Skultety 
---
 src/test/test_driver.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 3e2cd3a9a4..6f18baa265 100755
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2135,6 +2135,35 @@ testDomainGetTime(virDomainPtr dom,
 return ret;
 }

+
+static int
+testDomainSetTime(virDomainPtr dom,
+  long long seconds,
+  unsigned int nseconds,
+  unsigned int flags)
+{
+virDomainObjPtr vm = NULL;
+testDomainObjPrivatePtr priv;
+int ret = -1;
+
+virCheckFlags(VIR_DOMAIN_TIME_SYNC, ret);
+
+if (!(vm = testDomObjFromDomain(dom)))
+return -1;
+
+if (virDomainObjCheckActive(vm) < 0)
+goto cleanup;
+
+priv = vm->privateData;
+priv->seconds = seconds;
+priv->nseconds = nseconds;
+
+ret = 0;
+ cleanup:
+virDomainObjEndAPI();
+return ret;
+}
+
 #define TEST_SAVE_MAGIC "TestGuestMagic"


@@ -8923,6 +8952,7 @@ static virHypervisorDriver testHypervisorDriver = {
 .domainGetInfo = testDomainGetInfo, /* 0.1.1 */
 .domainGetState = testDomainGetState, /* 0.9.2 */
 .domainGetTime = testDomainGetTime, /* 5.4.0 */
+.domainSetTime = testDomainSetTime, /* 5.7.0 */
 .domainSave = testDomainSave, /* 0.3.2 */
 .domainSaveFlags = testDomainSaveFlags, /* 0.9.4 */
 .domainRestore = testDomainRestore, /* 0.3.2 */
--
2.22.0

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


[libvirt] [PATCH] src: security: Replace bitwise OR with logical OR

2019-08-07 Thread Erik Skultety
Typo introduced by commit d73f3f58360.

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

Signed-off-by: Erik Skultety 
---
Pushed as trivial.

 src/security/security_util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/security/security_util.c b/src/security/security_util.c
index ad265b0bc5..9d3f483f6b 100644
--- a/src/security/security_util.c
+++ b/src/security/security_util.c
@@ -268,7 +268,7 @@ virSecurityMoveRememberedLabel(const char *name,
 VIR_AUTOFREE(char *) attr_name = NULL;
 VIR_AUTOFREE(char *) attr_value = NULL;

-if (!(ref_name = virSecurityGetRefCountAttrName(name)) |
+if (!(ref_name = virSecurityGetRefCountAttrName(name)) ||
 !(attr_name = virSecurityGetAttrName(name)))
 return -1;

--
2.20.1

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


[libvirt] [PATCH v2 0/2] test_driver: implement virDomainSetTime and update virDomainGetTime

2019-08-07 Thread Ilias Stamatis
Ilias Stamatis (2):
  test_driver: make testDomainGetTime read time from vm-private data
  test_driver: implement virDomainSetTime

 src/test/test_driver.c | 43 --
 1 file changed, 41 insertions(+), 2 deletions(-)

--
2.22.0

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


[libvirt] [PATCH] tools: console: Relax stream EOF handling

2019-08-07 Thread Roman Bolshakov
An attempt to poweroff a VM from inside triggers the error for existing
session of virsh console and it returns with non-zero exit code:
  error: internal error: console stream EOF

The message and status code are misleading because there's no real
error.

Fixes: 29f2b5248c6 ("tools: console: pass stream/fd errors to user")
Signed-off-by: Roman Bolshakov 
---
 tools/virsh-console.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/tools/virsh-console.c b/tools/virsh-console.c
index e16f841e57..408a745b0f 100644
--- a/tools/virsh-console.c
+++ b/tools/virsh-console.c
@@ -172,10 +172,6 @@ virConsoleEventOnStream(virStreamPtr st,
 if (got == -2)
 goto cleanup; /* blocking */
 if (got <= 0) {
-if (got == 0)
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("console stream EOF"));
-
 virConsoleShutdown(con);
 goto cleanup;
 }
-- 
2.22.0

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


Re: [libvirt] [PATCH 1/2] test_driver: implement virDomainGetBlockIoTune

2019-08-07 Thread Ilias Stamatis
On Sun, Aug 4, 2019 at 5:32 PM Erik Skultety  wrote:
>
> On Sun, Aug 04, 2019 at 03:46:03PM +0200, Ilias Stamatis wrote:
> > On Sun, Aug 4, 2019 at 11:12 AM Erik Skultety  wrote:
> > >
> > > On Sat, Jul 27, 2019 at 05:04:37PM +0200, Ilias Stamatis wrote:
> > > > Signed-off-by: Ilias Stamatis 
> > > > ---
> > > >  src/test/test_driver.c | 90 ++
> > > >  1 file changed, 90 insertions(+)
> > > >
> > > > diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> > > > index ab0f8b06d6..9f4e255e35 100755
> > > > --- a/src/test/test_driver.c
> > > > +++ b/src/test/test_driver.c
> > > > @@ -3500,6 +3500,95 @@ testDomainGetInterfaceParameters(virDomainPtr 
> > > > dom,
> > > >  virDomainObjEndAPI();
> > > >  return ret;
> > > >  }
> > > > +
> > > > +
> > > > +static int
> > > > +testDomainGetBlockIoTune(virDomainPtr dom,
> > > > + const char *path,
> > > > + virTypedParameterPtr params,
> > > > + int *nparams,
> > > > + unsigned int flags)
> > > > +{
> > > > +virDomainObjPtr vm = NULL;
> > > > +virDomainDefPtr def = NULL;
> > > > +virDomainDiskDefPtr disk;
> > > > +virDomainBlockIoTuneInfo reply = {0};
> > > > +int ret = -1;
> > > > +
> > > > +virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
> > > > +  VIR_DOMAIN_AFFECT_CONFIG |
> > > > +  VIR_TYPED_PARAM_STRING_OKAY, -1);
> > > > +
> > > > +flags &= ~VIR_TYPED_PARAM_STRING_OKAY;
> > > > +
> > > > +if (*nparams == 0) {
> > > > +*nparams = 20;
> > > > +return 0;
> > > > +}
> > > > +
> > > > +if (!(vm = testDomObjFromDomain(dom)))
> > > > +return -1;
> > > > +
> > > > +if (!(def = virDomainObjGetOneDef(vm, flags)))
> > > > +goto cleanup;
> > > > +
> > > > +if (!(disk = virDomainDiskByName(def, path, true))) {
> > > > +virReportError(VIR_ERR_INVALID_ARG,
> > > > +   _("disk '%s' was not found in the domain 
> > > > config"),
> > > > +   path);
> > > > +goto cleanup;
> > > > +}
> > > > +
> > > > +reply = disk->blkdeviotune;
> > > > +if (VIR_STRDUP(reply.group_name, disk->blkdeviotune.group_name) < 
> > > > 0)
> > > > +goto cleanup;
> > > > +
> > > > +#define ULL VIR_TYPED_PARAM_ULLONG
> > >
> > > I don't see a point in doing ^this just to save a few characters, we're 
> > > way
> > > over the 80 columns already anyway, so wrap the long lines and span the 
> > > macro
> > > call over multiple lines.
> >
> > That's true that we're already over the 80 columns, but not by that
> > much so I thought that by doing it like that it allows us to "save" 13
> > new lines.
>
> Well, there isn't strictly a rule of thumb here. It's always a personal
> preference, but I look at it whether we gained anything by this "translation",
> we saved 13 lines, great. However, if you split the lines properly, are we
> really going to lose anything? No, not even in terms of readability.

Okay, I see your point and it makes sense.

>
> >
> > > Funny that I remember us having a discussion about macros doing string
> > > concatenation (which I don't really mind that much) but prevents you from 
> > > jumping
> > > directly to the symbol definition - that's exactly what the QEMU 
> > > alternative
> > > does, I guess just to save some common prefixes :D.
> >
> > Actually in this case it doesn't really prevent you. Just you need an
> > extra jump. One to jump to the definition of the ULL and from there to
> > jump to the next definition (even though all the ULL usage fits in a
> > single screen).
> >
> > Instead if there are many (instead of a single one) strings like like
> > "TOTAL_BYTES_SEC", "READ_BYTES_SEC" etc that are concatenated/extended
> > magically by some macro it makes it trickier to find the original
> > definitions. But that's just my opinion.
>
> Ironically, patch 2 does exactly the concatenation magic ;).

Haha, well played. ;D I didn't notice / remember that. I will reply to
this on the other e-mail.

So I will resend this after removing the ULL macro.

Thanks,
Ilias

>
> >
> > For me it's alright to use the QEMU macro as well, but we have already
> > the TEST_SET_PARAM which is used everywhere else so it makes more
> > sense to use it here too for consistency reasons I believe.
>
> I didn't object to using TEST_SET_PARAM, I merely suggested a minor adjustment
> to it with other potentially necessary minor adjustments along the way.
>
> Erik
>
> >
> > >
> > > Looking at the functions that use the typed parameters, an improvement we 
> > > could
> > > definitely do (in a standalone patch) is to ditch the index from the macro
> > > definition since it's quite fragile, by doing:
> > >
> > > int maxparams = X;
> > >
> > > if (*nparams == 0) {
> > > *nparams = maxparams;
> > > return 0;
> > > }
> > >
> > > *nparams = 0;
> > >
> > > 

Re: [libvirt] [PATCH 0/7] add virDomainGetGuestInfo()

2019-08-07 Thread Tomáš Golembiovský
On Thu, Aug 01, 2019 at 08:37:03AM -0500, Jonathon Jongsma wrote:
> This series adds several bits of guest information provided by a new API
> function virDomainGetGuestInfo(). There is an implementation for qemu using 
> the
> guest agent. In particular, it adds information about logged-in users, guest
> OS, and timezone.
> 
> I had previously submitted a patch series with a dedicated API function for
> querying guest users that returned an array of structures describing the 
> users.
> It was suggested that I convert his to a more futureproof design using typed
> parameters and also combine it with other bits of guest information similar to
> virDomainListGetStats(). In fact, there were several bugs that requested this
> information be added to the 'bulk stats' API, but Peter Krempa suggested 
> adding
> a new API for all data queried from the guest agent (see
> https://bugzilla.redhat.com/show_bug.cgi?id=1705514). This is that API
> proposal.

The reason we suggested 'bulk stats' approach is so that we can retrieve
information for all VMs in single call. This is not just about laziness
on side of management app, it is much easier for libvirt. We can either
fetch the info for all VMs one-by-one (which can take too long), or
resort to massive threading. On the other hand it seems that libvirt
with its async jobs can handle this in single thread. I am not libvirt
expert so please correct me if I am making wrong assumptions here. Also,
libvirt has pretty good knowledge whether the guest agent is running or
not. From application side we cannot get this information reliably and
we need to resort to trial-error approach.
 

> It follows the stats API quite closely, and tries to return data in
> similar ways (for example, the "users.N.*" field name scheme was inspired by
> various stats fields).
> 
> I plan to follow this series up with a patch that adds fsinfo to the returned
> information, but wanted to get comments on this approach now.

Apart from the above I have two other concerns.

With how the API call is designed you cannot pick which commands to run
(you always get them all). With the number of included commands growing
in the future the time to complete the call will grow as well and could
just take too long. Also, if you run the call periodically you always
don't want to run all the commands. For example, you don't need to check
the os-info as often as list of logged in users.

You cannot set the timeout on the guest agent commands. Instead you
block on them. As described in bug [1], rogue guest can potentially
block your call indefinitely. If you plan to address this problem in a
more general manner later that's probably fine too.

Tomas

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1705426



-- 
Tomáš Golembiovský 

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

Re: [libvirt] [PATCH 00/17] Refactor virt-login-shell and nss module

2019-08-07 Thread Michal Privoznik

On 8/1/19 5:00 PM, Daniel P. Berrangé wrote:
>
>

Very nice cleanup, which also makes NSS library smaller in size (I mean 
those .so.2 files).


I've found some mem leaks and mis-alignments, though. Please squash this 
into respective patches:


diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c
index a9814cf0dc..7122065b28 100644
--- a/tools/nss/libvirt_nss.c
+++ b/tools/nss/libvirt_nss.c
@@ -527,7 +527,7 @@ aiforaf(const char *name, int af, struct addrinfo 
*pai, struct addrinfo **aip)


 (*aip)->ai_next = res0;
 while ((*aip)->ai_next)
-   *aip = (*aip)->ai_next;
+*aip = (*aip)->ai_next;

 addrList++;
 }
diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c
index ddd50288d2..48a54d5841 100644
--- a/tools/nss/libvirt_nss_leases.c
+++ b/tools/nss/libvirt_nss_leases.c
@@ -108,7 +108,7 @@ appendAddr(const char *name ATTRIBUTE_UNUSED,
 return 0;
 }

- if (af != AF_UNSPEC && af != family) {
+if (af != AF_UNSPEC && af != family) {
 DEBUG("Skipping address which family is %d, %d requested", 
family, af);

 return 0;
 }
@@ -374,7 +374,7 @@ findLeases(const char *file,
 .addrs = addrs,
 .naddrs = naddrs,
 };
-yajl_handle parser;
+yajl_handle parser = NULL;
 char line[1024];
 int rv;

@@ -419,6 +419,7 @@ findLeases(const char *file,
 *addrs = NULL;
 *naddrs = 0;
 }
+yajl_free(parser);
 free(parserState.entry.ipaddr);
 free(parserState.entry.macaddr);
 free(parserState.entry.hostname);
diff --git a/tools/nss/libvirt_nss_macs.c b/tools/nss/libvirt_nss_macs.c
index 9fe5b83e86..fb5526bd7b 100644
--- a/tools/nss/libvirt_nss_macs.c
+++ b/tools/nss/libvirt_nss_macs.c
@@ -55,8 +55,8 @@ typedef struct {

 static int
 findMACsParserString(void *ctx,
-const unsigned char *stringVal,
-size_t stringLen)
+ const unsigned char *stringVal,
+ size_t stringLen)
 {
 findMACsParser *parser = ctx;

@@ -70,6 +70,7 @@ findMACsParserString(void *ctx,
 if (STRNEQ(parser->key, "domain"))
 return 0;

+free(parser->entry.name);
 if (!(parser->entry.name = strndup((char *)stringVal, stringLen)))
 return 0;
 } else if (parser->state == FIND_MACS_STATE_ENTRY_MACS) {
@@ -93,8 +94,8 @@ findMACsParserString(void *ctx,

 static int
 findMACsParserMapKey(void *ctx,
-const unsigned char *stringVal,
-size_t stringLen)
+ const unsigned char *stringVal,
+ size_t stringLen)
 {
 findMACsParser *parser = ctx;

@@ -226,7 +227,7 @@ findMACs(const char *file,
 .macs = macs,
 .nmacs = nmacs,
 };
-yajl_handle parser;
+yajl_handle parser = NULL;
 char line[1024];
 size_t i;
 int rv;
@@ -276,6 +277,7 @@ findMACs(const char *file,
 *macs = NULL;
 *nmacs = 0;
 }
+yajl_free(parser);
 for (i = 0; i < parserState.entry.nmacs; i++)
 free(parserState.entry.macs[i]);
 free(parserState.entry.macs);



With that:

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 0/2] test_driver: implement virDomainSetTime and update virDomainGetTime

2019-08-07 Thread Erik Skultety
On Wed, Aug 07, 2019 at 12:22:54PM +0200, Ilias Stamatis wrote:
> Ilias Stamatis (2):
>   test_driver: make testDomainGetTime read time from vm-private data
>   test_driver: implement virDomainSetTime
>
>  src/test/test_driver.c | 43 --
>  1 file changed, 41 insertions(+), 2 deletions(-)

Reviewed-by: Erik Skultety 

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


[libvirt] [PATCH 1/2] qemu: Fix possible NULL deref in qemuDomainGetResctrlMonData

2019-08-07 Thread John Ferlan
If virQEMUDriverGetCapabilities returns NULL, then a subsequent
deref of @caps would cause an error, so we just return failure.

Found by Coverity

Signed-off-by: John Ferlan 
---
 src/qemu/qemu_driver.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f1983f33e6..ff83d1c024 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -20728,7 +20728,8 @@ qemuDomainGetResctrlMonData(virQEMUDriverPtr driver,
 size_t i = 0;
 size_t j = 0;
 
-caps = virQEMUDriverGetCapabilities(driver, false);
+if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+return -1;
 
 switch (tag) {
 case VIR_RESCTRL_MONITOR_TYPE_CACHE:
-- 
2.20.1

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


[libvirt] [PATCH 0/2] Couple of Coverity fixes

2019-08-07 Thread John Ferlan
Both from recent changes, it was just as easy for me to post the patches
as write the annoying email that someone else needs to generate them ;-).

John Ferlan (2):
  qemu: Fix possible NULL deref in qemuDomainGetResctrlMonData
  tests: Fix memory leak in mymain

 src/qemu/qemu_driver.c | 3 ++-
 tests/virhostdevtest.c | 4 +---
 2 files changed, 3 insertions(+), 4 deletions(-)

-- 
2.20.1

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


[libvirt] [PATCH 2/2] tests: Fix memory leak in mymain

2019-08-07 Thread John Ferlan
Commit d2899a648 added a new exit path, but didn't free @fakerootdir.
Let's just use VIR_AUTOFREE instead to make life easier.

Found by Coverity

Signed-off-by: John Ferlan 
---
 tests/virhostdevtest.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c
index 7d15a87797..20984f3442 100644
--- a/tests/virhostdevtest.c
+++ b/tests/virhostdevtest.c
@@ -556,7 +556,7 @@ static int
 mymain(void)
 {
 int ret = 0;
-char *fakerootdir;
+VIR_AUTOFREE(char *) fakerootdir = NULL;
 
 if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
 fprintf(stderr, "Out of memory\n");
@@ -594,8 +594,6 @@ mymain(void)
 if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
 virFileDeleteTree(fakerootdir);
 
-VIR_FREE(fakerootdir);
-
 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
-- 
2.20.1

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


[libvirt] [PATCH 0/2] test_driver: implement the remaining ManagedSave APIs

2019-08-07 Thread Ilias Stamatis
Ilias Stamatis (2):
  test_driver: implement virDomainManagedSaveGetXMLDesc
  test_driver: implement virDomainManagedSaveDefineXML

 src/test/test_driver.c | 66 ++
 1 file changed, 66 insertions(+)

--
2.22.0

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


[libvirt] [dockerfiles PATCH v3 2/3] refresh: Add libosinfo project

2019-08-07 Thread Fabiano Fidêncio
libosinfo Dockerfile will consist on a single container that will be
able to build & test libosinfo, osinfo-db-tools, and osinfo-db. And from
those "subprojects", only libosinfo and osinfo-db-tools are subject for
mingw builds.

Signed-off-by: Fabiano Fidêncio 
---
 refresh | 5 +
 1 file changed, 5 insertions(+)

diff --git a/refresh b/refresh
index 20acb5e..8f99042 100755
--- a/refresh
+++ b/refresh
@@ -42,6 +42,11 @@ class Dockerfile:
 "libvirt" : {
 "libvirt" : True
 },
+"libosinfo" : {
+"libosinfo" : True,
+"osinfo-db" : False,
+"osinfo-db-tools" : True
+},
 }
 
 def __init__(self, path):
-- 
2.21.0

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

[libvirt] [dockerfiles PATCH v3 1/3] refresh: Learn how to deal with the project's name

2019-08-07 Thread Fabiano Fidêncio
Let's change the refresh script in order to take into consideration
Dockerfiles containing the project's name. This is needed in order to
add different projects to libvirt-dockerfiles.

An important change that deservers a mention here is that the PROJECTS
variable, part of Dockerfile class, has been added as a dictionary of
dictionaries as it has to store subprojects tied to a project, and each
of those subprojects may or may not be subject of a mingw build
(although this is not the case yet for libvirt, it may be for a other
projects, osinfo-db being one of them.

Together with this change, let's rename all the existent Dockerfiles to
mention their projects. So, 'buildenv-centos-7.Dockerfile' has been
renamed to 'buildenv-libvirt-centos-7.Dockerfile', for instance.

Signed-off-by: Fabiano Fidêncio 
---
 ...le => buildenv-libvirt-centos-7.Dockerfile |  0
 ...libvirt-debian-10-cross-aarch64.Dockerfile |  0
 ...-libvirt-debian-10-cross-armv6l.Dockerfile |  0
 ...-libvirt-debian-10-cross-armv7l.Dockerfile |  0
 ...nv-libvirt-debian-10-cross-i686.Dockerfile |  0
 ...nv-libvirt-debian-10-cross-mips.Dockerfile |  0
 ...ibvirt-debian-10-cross-mips64el.Dockerfile |  0
 ...-libvirt-debian-10-cross-mipsel.Dockerfile |  0
 ...libvirt-debian-10-cross-ppc64le.Dockerfile |  0
 ...v-libvirt-debian-10-cross-s390x.Dockerfile |  0
 ...e => buildenv-libvirt-debian-10.Dockerfile |  0
 ...-libvirt-debian-9-cross-aarch64.Dockerfile |  0
 ...v-libvirt-debian-9-cross-armv6l.Dockerfile |  0
 ...v-libvirt-debian-9-cross-armv7l.Dockerfile |  0
 ...env-libvirt-debian-9-cross-mips.Dockerfile |  0
 ...libvirt-debian-9-cross-mips64el.Dockerfile |  0
 ...v-libvirt-debian-9-cross-mipsel.Dockerfile |  0
 ...-libvirt-debian-9-cross-ppc64le.Dockerfile |  0
 ...nv-libvirt-debian-9-cross-s390x.Dockerfile |  0
 ...le => buildenv-libvirt-debian-9.Dockerfile |  0
 ...ibvirt-debian-sid-cross-aarch64.Dockerfile |  0
 ...libvirt-debian-sid-cross-armv6l.Dockerfile |  0
 ...libvirt-debian-sid-cross-armv7l.Dockerfile |  0
 ...v-libvirt-debian-sid-cross-i686.Dockerfile |  0
 ...v-libvirt-debian-sid-cross-mips.Dockerfile |  0
 ...bvirt-debian-sid-cross-mips64el.Dockerfile |  0
 ...libvirt-debian-sid-cross-mipsel.Dockerfile |  0
 ...ibvirt-debian-sid-cross-ppc64le.Dockerfile |  0
 ...-libvirt-debian-sid-cross-s390x.Dockerfile |  0
 ... => buildenv-libvirt-debian-sid.Dockerfile |  0
 ...e => buildenv-libvirt-fedora-29.Dockerfile |  0
 ...e => buildenv-libvirt-fedora-30.Dockerfile |  0
 ...buildenv-libvirt-fedora-rawhide.Dockerfile |  0
 ...e => buildenv-libvirt-ubuntu-16.Dockerfile |  0
 ...e => buildenv-libvirt-ubuntu-18.Dockerfile |  0
 refresh   | 52 ++-
 36 files changed, 40 insertions(+), 12 deletions(-)
 rename buildenv-centos-7.Dockerfile => buildenv-libvirt-centos-7.Dockerfile 
(100%)
 rename buildenv-debian-10-cross-aarch64.Dockerfile => 
buildenv-libvirt-debian-10-cross-aarch64.Dockerfile (100%)
 rename buildenv-debian-10-cross-armv6l.Dockerfile => 
buildenv-libvirt-debian-10-cross-armv6l.Dockerfile (100%)
 rename buildenv-debian-10-cross-armv7l.Dockerfile => 
buildenv-libvirt-debian-10-cross-armv7l.Dockerfile (100%)
 rename buildenv-debian-10-cross-i686.Dockerfile => 
buildenv-libvirt-debian-10-cross-i686.Dockerfile (100%)
 rename buildenv-debian-10-cross-mips.Dockerfile => 
buildenv-libvirt-debian-10-cross-mips.Dockerfile (100%)
 rename buildenv-debian-10-cross-mips64el.Dockerfile => 
buildenv-libvirt-debian-10-cross-mips64el.Dockerfile (100%)
 rename buildenv-debian-10-cross-mipsel.Dockerfile => 
buildenv-libvirt-debian-10-cross-mipsel.Dockerfile (100%)
 rename buildenv-debian-10-cross-ppc64le.Dockerfile => 
buildenv-libvirt-debian-10-cross-ppc64le.Dockerfile (100%)
 rename buildenv-debian-10-cross-s390x.Dockerfile => 
buildenv-libvirt-debian-10-cross-s390x.Dockerfile (100%)
 rename buildenv-debian-10.Dockerfile => buildenv-libvirt-debian-10.Dockerfile 
(100%)
 rename buildenv-debian-9-cross-aarch64.Dockerfile => 
buildenv-libvirt-debian-9-cross-aarch64.Dockerfile (100%)
 rename buildenv-debian-9-cross-armv6l.Dockerfile => 
buildenv-libvirt-debian-9-cross-armv6l.Dockerfile (100%)
 rename buildenv-debian-9-cross-armv7l.Dockerfile => 
buildenv-libvirt-debian-9-cross-armv7l.Dockerfile (100%)
 rename buildenv-debian-9-cross-mips.Dockerfile => 
buildenv-libvirt-debian-9-cross-mips.Dockerfile (100%)
 rename buildenv-debian-9-cross-mips64el.Dockerfile => 
buildenv-libvirt-debian-9-cross-mips64el.Dockerfile (100%)
 rename buildenv-debian-9-cross-mipsel.Dockerfile => 
buildenv-libvirt-debian-9-cross-mipsel.Dockerfile (100%)
 rename buildenv-debian-9-cross-ppc64le.Dockerfile => 
buildenv-libvirt-debian-9-cross-ppc64le.Dockerfile (100%)
 rename buildenv-debian-9-cross-s390x.Dockerfile => 
buildenv-libvirt-debian-9-cross-s390x.Dockerfile (100%)
 rename buildenv-debian-9.Dockerfile => buildenv-libvirt-debian-9.Dockerfile 
(100%)
 rename buildenv-debian-sid-cross-aarch64.Dockerfile => 

[libvirt] [dockerfiles PATCH v3 0/3] Add libosinfo Dockerfiles

2019-08-07 Thread Fabiano Fidêncio
This patch series aims to add libosinfo Dockerfiles to this project, so
those containers can be used by libosinfo projects' gitlab CI.

Please, take a look at each patch for more context of what has been done.

Changes since v2:
https://www.redhat.com/archives/libvir-list/2019-July/msg01934.html
- Cleaned up the code in order to avoid duplication, as pointed by
  Andrea;
- Raise an Exception in case a file doesn't match any of the existent
  projects, as pointed by Andrea;

Changes since v1:
https://www.redhat.com/archives/libvir-list/2019-July/msg01296.html
- Update libosinfo Dockerfiles after having libvirt-jenkins-ci's patches
  related to libosinfo/osinfo-db-tools dependencies merged.

Fabiano Fidêncio (3):
  refresh: Learn how to deal with the project's name
  refresh: Add libosinfo project
  Add Dockerfiles for libosinfo project

 buildenv-libosinfo-centos-7.Dockerfile| 43 +
 ...bosinfo-debian-10-cross-aarch64.Dockerfile | 64 +++
 ...ibosinfo-debian-10-cross-armv6l.Dockerfile | 64 +++
 ...ibosinfo-debian-10-cross-armv7l.Dockerfile | 64 +++
 ...-libosinfo-debian-10-cross-i686.Dockerfile | 64 +++
 ...-libosinfo-debian-10-cross-mips.Dockerfile | 64 +++
 ...osinfo-debian-10-cross-mips64el.Dockerfile | 64 +++
 ...ibosinfo-debian-10-cross-mipsel.Dockerfile | 64 +++
 ...bosinfo-debian-10-cross-ppc64le.Dockerfile | 64 +++
 ...libosinfo-debian-10-cross-s390x.Dockerfile | 64 +++
 buildenv-libosinfo-debian-10.Dockerfile   | 50 +++
 ...ibosinfo-debian-9-cross-aarch64.Dockerfile | 64 +++
 ...libosinfo-debian-9-cross-armv6l.Dockerfile | 64 +++
 ...libosinfo-debian-9-cross-armv7l.Dockerfile | 64 +++
 ...v-libosinfo-debian-9-cross-mips.Dockerfile | 64 +++
 ...bosinfo-debian-9-cross-mips64el.Dockerfile | 64 +++
 ...libosinfo-debian-9-cross-mipsel.Dockerfile | 64 +++
 ...ibosinfo-debian-9-cross-ppc64le.Dockerfile | 64 +++
 ...-libosinfo-debian-9-cross-s390x.Dockerfile | 64 +++
 buildenv-libosinfo-debian-9.Dockerfile| 50 +++
 ...osinfo-debian-sid-cross-aarch64.Dockerfile | 64 +++
 ...bosinfo-debian-sid-cross-armv6l.Dockerfile | 64 +++
 ...bosinfo-debian-sid-cross-armv7l.Dockerfile | 64 +++
 ...libosinfo-debian-sid-cross-i686.Dockerfile | 64 +++
 ...libosinfo-debian-sid-cross-mips.Dockerfile | 64 +++
 ...sinfo-debian-sid-cross-mips64el.Dockerfile | 64 +++
 ...bosinfo-debian-sid-cross-mipsel.Dockerfile | 64 +++
 ...osinfo-debian-sid-cross-ppc64le.Dockerfile | 64 +++
 ...ibosinfo-debian-sid-cross-s390x.Dockerfile | 64 +++
 buildenv-libosinfo-debian-sid.Dockerfile  | 50 +++
 buildenv-libosinfo-fedora-29.Dockerfile   | 49 ++
 buildenv-libosinfo-fedora-30.Dockerfile   | 49 ++
 buildenv-libosinfo-fedora-rawhide.Dockerfile  | 63 ++
 buildenv-libosinfo-ubuntu-16.Dockerfile   | 50 +++
 buildenv-libosinfo-ubuntu-18.Dockerfile   | 50 +++
 ...le => buildenv-libvirt-centos-7.Dockerfile |  0
 ...libvirt-debian-10-cross-aarch64.Dockerfile |  0
 ...-libvirt-debian-10-cross-armv6l.Dockerfile |  0
 ...-libvirt-debian-10-cross-armv7l.Dockerfile |  0
 ...nv-libvirt-debian-10-cross-i686.Dockerfile |  0
 ...nv-libvirt-debian-10-cross-mips.Dockerfile |  0
 ...ibvirt-debian-10-cross-mips64el.Dockerfile |  0
 ...-libvirt-debian-10-cross-mipsel.Dockerfile |  0
 ...libvirt-debian-10-cross-ppc64le.Dockerfile |  0
 ...v-libvirt-debian-10-cross-s390x.Dockerfile |  0
 ...e => buildenv-libvirt-debian-10.Dockerfile |  0
 ...-libvirt-debian-9-cross-aarch64.Dockerfile |  0
 ...v-libvirt-debian-9-cross-armv6l.Dockerfile |  0
 ...v-libvirt-debian-9-cross-armv7l.Dockerfile |  0
 ...env-libvirt-debian-9-cross-mips.Dockerfile |  0
 ...libvirt-debian-9-cross-mips64el.Dockerfile |  0
 ...v-libvirt-debian-9-cross-mipsel.Dockerfile |  0
 ...-libvirt-debian-9-cross-ppc64le.Dockerfile |  0
 ...nv-libvirt-debian-9-cross-s390x.Dockerfile |  0
 ...le => buildenv-libvirt-debian-9.Dockerfile |  0
 ...ibvirt-debian-sid-cross-aarch64.Dockerfile |  0
 ...libvirt-debian-sid-cross-armv6l.Dockerfile |  0
 ...libvirt-debian-sid-cross-armv7l.Dockerfile |  0
 ...v-libvirt-debian-sid-cross-i686.Dockerfile |  0
 ...v-libvirt-debian-sid-cross-mips.Dockerfile |  0
 ...bvirt-debian-sid-cross-mips64el.Dockerfile |  0
 ...libvirt-debian-sid-cross-mipsel.Dockerfile |  0
 ...ibvirt-debian-sid-cross-ppc64le.Dockerfile |  0
 ...-libvirt-debian-sid-cross-s390x.Dockerfile |  0
 ... => buildenv-libvirt-debian-sid.Dockerfile |  0
 ...e => buildenv-libvirt-fedora-29.Dockerfile |  0
 ...e => buildenv-libvirt-fedora-30.Dockerfile |  0
 

Re: [libvirt] [PATCH] build: Solve mingw build clash with DATADIR

2019-08-07 Thread Michal Privoznik

On 7/31/19 9:30 PM, Eric Blake wrote:

Commit fed58d83 was a hack to fix a mingw build failure due to header
inclusion order resulting in a clash over the use of DATADIR, by
repeating a trick made several other times in the past of tweaking
inclusion order until it goes away.  Better is to revert that, and
instead use pragmas to avoid the clash in the first place, regardless
of header ordering, solving it for everyone in the future.

Signed-off-by: Eric Blake 
---

I tested that both gcc and clang on F29 support this; but it will take
a full CI run to see if everywhere else is okay with it. Thus, it is
not 5.6 material.

  src/util/viratomic.h   | 3 +++
  src/conf/checkpoint_conf.c | 2 --
  2 files changed, 3 insertions(+), 2 deletions(-)


Reviewed-by: Michal Privoznik 

Michal

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


[libvirt] [dockerfiles PATCH v3 3/3] Add Dockerfiles for libosinfo project

2019-08-07 Thread Fabiano Fidêncio
The corresponding libvirt-jenkins-ci commit is 81eabc6f888a3.

Signed-off-by: Fabiano Fidêncio 
---
 buildenv-libosinfo-centos-7.Dockerfile| 43 +
 ...bosinfo-debian-10-cross-aarch64.Dockerfile | 64 +++
 ...ibosinfo-debian-10-cross-armv6l.Dockerfile | 64 +++
 ...ibosinfo-debian-10-cross-armv7l.Dockerfile | 64 +++
 ...-libosinfo-debian-10-cross-i686.Dockerfile | 64 +++
 ...-libosinfo-debian-10-cross-mips.Dockerfile | 64 +++
 ...osinfo-debian-10-cross-mips64el.Dockerfile | 64 +++
 ...ibosinfo-debian-10-cross-mipsel.Dockerfile | 64 +++
 ...bosinfo-debian-10-cross-ppc64le.Dockerfile | 64 +++
 ...libosinfo-debian-10-cross-s390x.Dockerfile | 64 +++
 buildenv-libosinfo-debian-10.Dockerfile   | 50 +++
 ...ibosinfo-debian-9-cross-aarch64.Dockerfile | 64 +++
 ...libosinfo-debian-9-cross-armv6l.Dockerfile | 64 +++
 ...libosinfo-debian-9-cross-armv7l.Dockerfile | 64 +++
 ...v-libosinfo-debian-9-cross-mips.Dockerfile | 64 +++
 ...bosinfo-debian-9-cross-mips64el.Dockerfile | 64 +++
 ...libosinfo-debian-9-cross-mipsel.Dockerfile | 64 +++
 ...ibosinfo-debian-9-cross-ppc64le.Dockerfile | 64 +++
 ...-libosinfo-debian-9-cross-s390x.Dockerfile | 64 +++
 buildenv-libosinfo-debian-9.Dockerfile| 50 +++
 ...osinfo-debian-sid-cross-aarch64.Dockerfile | 64 +++
 ...bosinfo-debian-sid-cross-armv6l.Dockerfile | 64 +++
 ...bosinfo-debian-sid-cross-armv7l.Dockerfile | 64 +++
 ...libosinfo-debian-sid-cross-i686.Dockerfile | 64 +++
 ...libosinfo-debian-sid-cross-mips.Dockerfile | 64 +++
 ...sinfo-debian-sid-cross-mips64el.Dockerfile | 64 +++
 ...bosinfo-debian-sid-cross-mipsel.Dockerfile | 64 +++
 ...osinfo-debian-sid-cross-ppc64le.Dockerfile | 64 +++
 ...ibosinfo-debian-sid-cross-s390x.Dockerfile | 64 +++
 buildenv-libosinfo-debian-sid.Dockerfile  | 50 +++
 buildenv-libosinfo-fedora-29.Dockerfile   | 49 ++
 buildenv-libosinfo-fedora-30.Dockerfile   | 49 ++
 buildenv-libosinfo-fedora-rawhide.Dockerfile  | 63 ++
 buildenv-libosinfo-ubuntu-16.Dockerfile   | 50 +++
 buildenv-libosinfo-ubuntu-18.Dockerfile   | 50 +++
 35 files changed, 2118 insertions(+)
 create mode 100644 buildenv-libosinfo-centos-7.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-10-cross-aarch64.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-10-cross-armv6l.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-10-cross-armv7l.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-10-cross-i686.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-10-cross-mips.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-10-cross-mips64el.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-10-cross-mipsel.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-10-cross-ppc64le.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-10-cross-s390x.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-10.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-9-cross-aarch64.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-9-cross-armv6l.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-9-cross-armv7l.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-9-cross-mips.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-9-cross-mips64el.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-9-cross-mipsel.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-9-cross-ppc64le.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-9-cross-s390x.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-9.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-sid-cross-aarch64.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-sid-cross-armv6l.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-sid-cross-armv7l.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-sid-cross-i686.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-sid-cross-mips.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-sid-cross-mips64el.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-sid-cross-mipsel.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-sid-cross-ppc64le.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-sid-cross-s390x.Dockerfile
 create mode 100644 buildenv-libosinfo-debian-sid.Dockerfile
 create mode 100644 buildenv-libosinfo-fedora-29.Dockerfile
 create mode 100644 buildenv-libosinfo-fedora-30.Dockerfile
 create mode 100644 buildenv-libosinfo-fedora-rawhide.Dockerfile
 create mode 100644 

Re: [libvirt] [PATCH 0/2] Couple of Coverity fixes

2019-08-07 Thread Michal Privoznik

On 8/7/19 4:45 PM, John Ferlan wrote:

Both from recent changes, it was just as easy for me to post the patches
as write the annoying email that someone else needs to generate them ;-).

John Ferlan (2):
   qemu: Fix possible NULL deref in qemuDomainGetResctrlMonData
   tests: Fix memory leak in mymain

  src/qemu/qemu_driver.c | 3 ++-
  tests/virhostdevtest.c | 4 +---
  2 files changed, 3 insertions(+), 4 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 0/7] add virDomainGetGuestInfo()

2019-08-07 Thread Jonathon Jongsma
On Wed, 2019-08-07 at 12:39 +0200, Tomáš Golembiovský wrote:
> On Thu, Aug 01, 2019 at 08:37:03AM -0500, Jonathon Jongsma wrote:
> > This series adds several bits of guest information provided by a
> > new API
> > function virDomainGetGuestInfo(). There is an implementation for
> > qemu using the
> > guest agent. In particular, it adds information about logged-in
> > users, guest
> > OS, and timezone.
> > 
> > I had previously submitted a patch series with a dedicated API
> > function for
> > querying guest users that returned an array of structures
> > describing the users.
> > It was suggested that I convert his to a more futureproof design
> > using typed
> > parameters and also combine it with other bits of guest information
> > similar to
> > virDomainListGetStats(). In fact, there were several bugs that
> > requested this
> > information be added to the 'bulk stats' API, but Peter Krempa
> > suggested adding
> > a new API for all data queried from the guest agent (see
> > https://bugzilla.redhat.com/show_bug.cgi?id=1705514). This is that
> > API
> > proposal.
> 
> The reason we suggested 'bulk stats' approach is so that we can
> retrieve
> information for all VMs in single call. This is not just about
> laziness
> on side of management app, it is much easier for libvirt. We can
> either
> fetch the info for all VMs one-by-one (which can take too long), or
> resort to massive threading. On the other hand it seems that libvirt
> with its async jobs can handle this in single thread. I am not
> libvirt
> expert so please correct me if I am making wrong assumptions here.
> Also,
> libvirt has pretty good knowledge whether the guest agent is running
> or
> not. From application side we cannot get this information reliably
> and
> we need to resort to trial-error approach.

It's not entirely clear to me what you are suggesting here. Are you
saying that this API is generally OK, but that you wish it would query
all domains at once? Or are you suggesting some additional changes?


> > It follows the stats API quite closely, and tries to return data in
> > similar ways (for example, the "users.N.*" field name scheme was
> > inspired by
> > various stats fields).
> > 
> > I plan to follow this series up with a patch that adds fsinfo to
> > the returned
> > information, but wanted to get comments on this approach now.
> 
> Apart from the above I have two other concerns.
> 
> With how the API call is designed you cannot pick which commands to
> run
> (you always get them all). With the number of included commands
> growing
> in the future the time to complete the call will grow as well and
> could
> just take too long. Also, if you run the call periodically you always
> don't want to run all the commands. For example, you don't need to
> check
> the os-info as often as list of logged in users.


If I understand what you're saying, I think it's incorrect. The API
that I proposed takes a 'types' parameter (similar to the 'stats'
parameter in the bulk stats API) which lets you specify which guest
information types you would like to query. So if you want, you can
query only a subset of the guest info categories.

> 
> You cannot set the timeout on the guest agent commands. Instead you
> block on them. As described in bug [1], rogue guest can potentially
> block your call indefinitely. If you plan to address this problem in
> a
> more general manner later that's probably fine too.

Yes, I think this issue is probably better addressed separately.

> 
> Tomas
> 
> [1] https://bugzilla.redhat.com/show_bug.cgi?id=1705426
> 
> 
> 

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

[libvirt] [PATCH 2/2] test_driver: implement virDomainManagedSaveDefineXML

2019-08-07 Thread Ilias Stamatis
Signed-off-by: Ilias Stamatis 
---
 src/test/test_driver.c | 38 ++
 1 file changed, 38 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 8715d6c0d6..360bdef373 100755
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -7633,6 +7633,43 @@ testDomainManagedSaveGetXMLDesc(virDomainPtr dom,
 }


+static int
+testDomainManagedSaveDefineXML(virDomainPtr dom,
+   const char *dxml,
+   unsigned int flags)
+{
+virDomainObjPtr vm = NULL;
+virDomainDefPtr newdef = NULL;
+testDriverPtr privconn = dom->conn->privateData;
+int ret = -1;
+
+virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE |
+  VIR_DOMAIN_SAVE_RUNNING |
+  VIR_DOMAIN_SAVE_PAUSED, -1);
+
+if (!(vm = testDomObjFromDomain(dom)))
+return -1;
+
+if (vm->hasManagedSave == false) {
+virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+   _("domain does not have managed save image"));
+goto cleanup;
+}
+
+if ((newdef = virDomainDefParseString(dxml, privconn->caps, 
privconn->xmlopt, NULL,
+  VIR_DOMAIN_DEF_PARSE_INACTIVE)) == 
NULL)
+goto cleanup;
+
+virDomainDefFree(vm->def);
+vm->def = newdef;
+
+ret = 0;
+ cleanup:
+virDomainObjEndAPI();
+return ret;
+}
+
+
 static int
 testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
 {
@@ -9055,6 +9092,7 @@ static virHypervisorDriver testHypervisorDriver = {
 .connectGetCPUModelNames = testConnectGetCPUModelNames, /* 1.1.3 */
 .domainManagedSave = testDomainManagedSave, /* 1.1.4 */
 .domainManagedSaveGetXMLDesc = testDomainManagedSaveGetXMLDesc, /* 5.7.0 */
+.domainManagedSaveDefineXML = testDomainManagedSaveDefineXML, /* 5.7.0 */
 .domainHasManagedSaveImage = testDomainHasManagedSaveImage, /* 1.1.4 */
 .domainManagedSaveRemove = testDomainManagedSaveRemove, /* 1.1.4 */
 .domainMemoryStats = testDomainMemoryStats, /* 5.7.0 */
--
2.22.0

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


[libvirt] [PATCH 1/2] test_driver: implement virDomainManagedSaveGetXMLDesc

2019-08-07 Thread Ilias Stamatis
The managedSave APIs according to the documentation are supposed to
operate on a disk file. However, this might not be appropriate in the
case of the test driver since:

* It's better if the test driver keeps all its state in memory only and
doesn't affect the host in any way.

* The test driver, apart from "emulating" the domains, it additionally
"emulates" a fake physical host. Every time we start a new test
connection that sort of means that a new physical host is created as
well. And this fake host isn't necessarily the same.

What we can do instead is operating on the already existing domain
definitions. So along as a connection remains open, a domain can
preserve the managed state between different shutdown / create calls.
When the test connection closes this means that the fake host is
destroyed as well, hence no other state is preserved after that.

This way we also make sure that we don't touch the real host's
filesystem.

Signed-off-by: Ilias Stamatis 
---
 src/test/test_driver.c | 28 
 1 file changed, 28 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 6f18baa265..8715d6c0d6 100755
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -7606,6 +7606,33 @@ testDomainManagedSave(virDomainPtr dom, unsigned int 
flags)
 }


+static char *
+testDomainManagedSaveGetXMLDesc(virDomainPtr dom,
+unsigned int flags)
+{
+virDomainObjPtr vm;
+testDriverPtr privconn = dom->conn->privateData;
+char *ret = NULL;
+
+virCheckFlags(VIR_DOMAIN_SAVE_IMAGE_XML_SECURE, NULL);
+
+if (!(vm = testDomObjFromDomain(dom)))
+return NULL;
+
+if (vm->hasManagedSave == false) {
+virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+   _("domain does not have managed save image"));
+goto cleanup;
+}
+
+ret = virDomainDefFormat(vm->def, privconn->caps, 
VIR_DOMAIN_DEF_FORMAT_SECURE);
+
+ cleanup:
+virDomainObjEndAPI();
+return ret;
+}
+
+
 static int
 testDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
 {
@@ -9027,6 +9054,7 @@ static virHypervisorDriver testHypervisorDriver = {
 .domainSendProcessSignal = testDomainSendProcessSignal, /* 5.5.0 */
 .connectGetCPUModelNames = testConnectGetCPUModelNames, /* 1.1.3 */
 .domainManagedSave = testDomainManagedSave, /* 1.1.4 */
+.domainManagedSaveGetXMLDesc = testDomainManagedSaveGetXMLDesc, /* 5.7.0 */
 .domainHasManagedSaveImage = testDomainHasManagedSaveImage, /* 1.1.4 */
 .domainManagedSaveRemove = testDomainManagedSaveRemove, /* 1.1.4 */
 .domainMemoryStats = testDomainMemoryStats, /* 5.7.0 */
--
2.22.0

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


Re: [libvirt] [PATCH] build: Solve mingw build clash with DATADIR

2019-08-07 Thread Eric Blake
On 8/7/19 9:59 AM, Michal Privoznik wrote:
> On 7/31/19 9:30 PM, Eric Blake wrote:
>> Commit fed58d83 was a hack to fix a mingw build failure due to header
>> inclusion order resulting in a clash over the use of DATADIR, by
>> repeating a trick made several other times in the past of tweaking
>> inclusion order until it goes away.  Better is to revert that, and
>> instead use pragmas to avoid the clash in the first place, regardless
>> of header ordering, solving it for everyone in the future.
>>
>> Signed-off-by: Eric Blake 
>> ---
>>
>> I tested that both gcc and clang on F29 support this; but it will take
>> a full CI run to see if everywhere else is okay with it. Thus, it is
>> not 5.6 material.

And the full CI run says I failed,
https://travis-ci.org/libvirt/libvirt/jobs/569132417

In file included from ../../src/conf/checkpoint_conf.c:24:

../gnulib/lib/configmake.h:8:17: error: expected identifier or '('
before string constant

8 | #define DATADIR "/usr/i686-w64-mingw32/sys-root/mingw/share"

  | ^~~~

make[3]: *** [Makefile:8803: conf/libvirt_conf_la-checkpoint_conf.lo]
Error 1

make[3]: *** Waiting for unfinished jobs

I'm reverting the patch under the build-breaker rules, while trying to
reproduce the cross-compilation locally rather than relying solely on
CI.  My local testing that proved that #pragma push_macro works with gcc
was obviously not enough; sorry for the churn while I prepare v2.

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



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