Re: [libvirt] [PATCH 17/41] cpu: Special case models == NULL in cpuGetModels

2016-09-14 Thread Jiri Denemark
On Mon, Aug 29, 2016 at 17:59:21 -0400, John Ferlan wrote:
...
> > @@ -1127,9 +1127,13 @@ cmdCPUModelNames(vshControl *ctl, const vshCmd *cmd)
> >  return false;
> >  }
> >  
> > -for (i = 0; i < nmodels; i++) {
> > -vshPrint(ctl, "%s\n", models[i]);
> > -VIR_FREE(models[i]);
> > +if (nmodels == 0) {
> > +vshPrint(ctl, "%s\n", _("all CPU models are accepted"));
> > +} else {
> > +for (i = 0; i < nmodels; i++) {
> > +vshPrint(ctl, "%s\n", models[i]);
> > +VIR_FREE(models[i]);
> > +}
> 
> I seem to recall some recent work around the -q[uiet] switch - is that
> something that this code needs to be concerned with?  (as silly as that
> seems while I'm typing it!)

Not silly at all. I replaced vshPrint with vshPrintExtra.

Jirka

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


Re: [libvirt] [PATCH 17/41] cpu: Special case models == NULL in cpuGetModels

2016-08-29 Thread John Ferlan


On 08/12/2016 09:33 AM, Jiri Denemark wrote:
> Some CPU drivers (such as arm) do not provide list of CPUs libvirt
> supports and just pass any CPU model from domain XML directly to QEMU.
> Such driver need to return models == NULL and success from cpuGetModels.
> 
> Signed-off-by: Jiri Denemark 
> ---
>  src/cpu/cpu.c  | 15 +--
>  src/libvirt-host.c |  3 ++-
>  tools/virsh-host.c | 10 +++---
>  3 files changed, 18 insertions(+), 10 deletions(-)
> 

[...]

> diff --git a/src/libvirt-host.c b/src/libvirt-host.c
> index 2a3de03..335798a 100644
> --- a/src/libvirt-host.c
> +++ b/src/libvirt-host.c
> @@ -1005,7 +1005,8 @@ virConnectCompareCPU(virConnectPtr conn,
>   *
>   * Get the list of supported CPU models for a specific architecture.
>   *
> - * Returns -1 on error, number of elements in @models on success.
> + * Returns -1 on error, number of elements in @models on success (0 means
> + * libvirt accepts any CPU model).
>   */
>  int
>  virConnectGetCPUModelNames(virConnectPtr conn, const char *arch, char 
> ***models,
> diff --git a/tools/virsh-host.c b/tools/virsh-host.c
> index 57f0c0e..7ac2812 100644
> --- a/tools/virsh-host.c
> +++ b/tools/virsh-host.c
> @@ -1127,9 +1127,13 @@ cmdCPUModelNames(vshControl *ctl, const vshCmd *cmd)
>  return false;
>  }
>  
> -for (i = 0; i < nmodels; i++) {
> -vshPrint(ctl, "%s\n", models[i]);
> -VIR_FREE(models[i]);
> +if (nmodels == 0) {
> +vshPrint(ctl, "%s\n", _("all CPU models are accepted"));
> +} else {
> +for (i = 0; i < nmodels; i++) {
> +vshPrint(ctl, "%s\n", models[i]);
> +VIR_FREE(models[i]);
> +}

I seem to recall some recent work around the -q[uiet] switch - is that
something that this code needs to be concerned with?  (as silly as that
seems while I'm typing it!)


>  }
>  VIR_FREE(models);
>  
> 

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


[libvirt] [PATCH 17/41] cpu: Special case models == NULL in cpuGetModels

2016-08-12 Thread Jiri Denemark
Some CPU drivers (such as arm) do not provide list of CPUs libvirt
supports and just pass any CPU model from domain XML directly to QEMU.
Such driver need to return models == NULL and success from cpuGetModels.

Signed-off-by: Jiri Denemark 
---
 src/cpu/cpu.c  | 15 +--
 src/libvirt-host.c |  3 ++-
 tools/virsh-host.c | 10 +++---
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c
index 19afeab..d2b7ce3 100644
--- a/src/cpu/cpu.c
+++ b/src/cpu/cpu.c
@@ -750,9 +750,13 @@ cpuModelIsAllowed(const char *model,
  * @arch: CPU architecture
  * @models: where to store the NULL-terminated list of supported models
  *
- * Fetches all CPU models supported by libvirt on @archName.
+ * Fetches all CPU models supported by libvirt on @archName. If there are
+ * no restrictions on CPU models on @archName (i.e., the CPU model is just
+ * passed directly to a hypervisor), this function returns 0 and sets
+ * @models to NULL.
  *
- * Returns number of supported CPU models or -1 on error.
+ * Returns number of supported CPU models, 0 if any CPU model is supported,
+ * or -1 on error.
  */
 int
 cpuGetModels(virArch arch, char ***models)
@@ -770,10 +774,9 @@ cpuGetModels(virArch arch, char ***models)
 }
 
 if (!driver->getModels) {
-virReportError(VIR_ERR_NO_SUPPORT,
-   _("CPU driver for %s has no CPU model support"),
-   virArchToString(arch));
-return -1;
+if (models)
+*models = NULL;
+return 0;
 }
 
 return driver->getModels(models);
diff --git a/src/libvirt-host.c b/src/libvirt-host.c
index 2a3de03..335798a 100644
--- a/src/libvirt-host.c
+++ b/src/libvirt-host.c
@@ -1005,7 +1005,8 @@ virConnectCompareCPU(virConnectPtr conn,
  *
  * Get the list of supported CPU models for a specific architecture.
  *
- * Returns -1 on error, number of elements in @models on success.
+ * Returns -1 on error, number of elements in @models on success (0 means
+ * libvirt accepts any CPU model).
  */
 int
 virConnectGetCPUModelNames(virConnectPtr conn, const char *arch, char 
***models,
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 57f0c0e..7ac2812 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -1127,9 +1127,13 @@ cmdCPUModelNames(vshControl *ctl, const vshCmd *cmd)
 return false;
 }
 
-for (i = 0; i < nmodels; i++) {
-vshPrint(ctl, "%s\n", models[i]);
-VIR_FREE(models[i]);
+if (nmodels == 0) {
+vshPrint(ctl, "%s\n", _("all CPU models are accepted"));
+} else {
+for (i = 0; i < nmodels; i++) {
+vshPrint(ctl, "%s\n", models[i]);
+VIR_FREE(models[i]);
+}
 }
 VIR_FREE(models);
 
-- 
2.9.2

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