[libvirt] [PATCH 1/3] hyperv: Fix hypervInitConnection error reporting

Ladi Prosek posted 3 patches 8 years, 4 months ago
There is a newer version of this series
[libvirt] [PATCH 1/3] hyperv: Fix hypervInitConnection error reporting
Posted by Ladi Prosek 8 years, 4 months ago
"%s is not a Hyper-V server" is not a correct generalization of all possible
error conditions of hypervEnumAndPull. For example:

  $ virsh --connect hyperv://localhost/?transport=http
  Enter username for localhost [administrator]:
  Enter administrator's password for localhost: <enters incorrect password>
  error: failed to connect to the hypervisor
  error: internal error: localhost is not a Hyper-V server

This commit fixes hypervEnumAndPull to set a meaningful internal error on all
error paths and removes the general virReportError.

The same scenario with the fix:

  $ virsh --connect hyperv://localhost/?transport=http
  Enter username for localhost [administrator]:
  Enter administrator's password for localhost: <enters incorrect password>
  error: failed to connect to the hypervisor
  error: internal error: Transport error during enumeration: User, password or
  similar was not accepted (26)

Signed-off-by: Ladi Prosek <lprosek@redhat.com>
---
 src/hyperv/hyperv_driver.c | 2 --
 src/hyperv/hyperv_wmi.c    | 1 +
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 09912610c..52274239c 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -105,8 +105,6 @@ hypervInitConnection(virConnectPtr conn, hypervPrivate *priv,
         priv->wmiVersion = HYPERV_WMI_VERSION_V1;
 
         if (hypervEnumAndPull(priv, &wqlQuery, &computerSystem) < 0) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("%s is not a Hyper-V server"), conn->uri->server);
             goto cleanup;
         }
     }
diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
index 980a00e28..6a51eff20 100644
--- a/src/hyperv/hyperv_wmi.c
+++ b/src/hyperv/hyperv_wmi.c
@@ -985,6 +985,7 @@ hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery,
     hypervObject *object;
 
     if (virBufferCheckError(wqlQuery->query) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid query"));
         virBufferFreeAndReset(wqlQuery->query);
         return -1;
     }
-- 
2.13.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/3] hyperv: Fix hypervInitConnection error reporting
Posted by Daniel P. Berrange 8 years, 4 months ago
On Tue, Oct 03, 2017 at 11:04:56AM +0200, Ladi Prosek wrote:
> "%s is not a Hyper-V server" is not a correct generalization of all possible
> error conditions of hypervEnumAndPull. For example:
> 
>   $ virsh --connect hyperv://localhost/?transport=http
>   Enter username for localhost [administrator]:
>   Enter administrator's password for localhost: <enters incorrect password>
>   error: failed to connect to the hypervisor
>   error: internal error: localhost is not a Hyper-V server
> 
> This commit fixes hypervEnumAndPull to set a meaningful internal error on all
> error paths and removes the general virReportError.
> 
> The same scenario with the fix:
> 
>   $ virsh --connect hyperv://localhost/?transport=http
>   Enter username for localhost [administrator]:
>   Enter administrator's password for localhost: <enters incorrect password>
>   error: failed to connect to the hypervisor
>   error: internal error: Transport error during enumeration: User, password or
>   similar was not accepted (26)
> 
> Signed-off-by: Ladi Prosek <lprosek@redhat.com>
> ---
>  src/hyperv/hyperv_driver.c | 2 --
>  src/hyperv/hyperv_wmi.c    | 1 +
>  2 files changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
> index 09912610c..52274239c 100644
> --- a/src/hyperv/hyperv_driver.c
> +++ b/src/hyperv/hyperv_driver.c
> @@ -105,8 +105,6 @@ hypervInitConnection(virConnectPtr conn, hypervPrivate *priv,
>          priv->wmiVersion = HYPERV_WMI_VERSION_V1;
>  
>          if (hypervEnumAndPull(priv, &wqlQuery, &computerSystem) < 0) {
> -            virReportError(VIR_ERR_INTERNAL_ERROR,
> -                           _("%s is not a Hyper-V server"), conn->uri->server);

This bit is ok...

>              goto cleanup;
>          }
>      }
> diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
> index 980a00e28..6a51eff20 100644
> --- a/src/hyperv/hyperv_wmi.c
> +++ b/src/hyperv/hyperv_wmi.c
> @@ -985,6 +985,7 @@ hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery,
>      hypervObject *object;
>  
>      if (virBufferCheckError(wqlQuery->query) < 0) {
> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid query"));

...but virBufferCheckError already reports an error, so this is invalid.

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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/3] hyperv: Fix hypervInitConnection error reporting
Posted by Ladi Prosek 8 years, 4 months ago
On Tue, Oct 3, 2017 at 12:14 PM, Daniel P. Berrange <berrange@redhat.com> wrote:
> On Tue, Oct 03, 2017 at 11:04:56AM +0200, Ladi Prosek wrote:
>> "%s is not a Hyper-V server" is not a correct generalization of all possible
>> error conditions of hypervEnumAndPull. For example:
>>
>>   $ virsh --connect hyperv://localhost/?transport=http
>>   Enter username for localhost [administrator]:
>>   Enter administrator's password for localhost: <enters incorrect password>
>>   error: failed to connect to the hypervisor
>>   error: internal error: localhost is not a Hyper-V server
>>
>> This commit fixes hypervEnumAndPull to set a meaningful internal error on all
>> error paths and removes the general virReportError.
>>
>> The same scenario with the fix:
>>
>>   $ virsh --connect hyperv://localhost/?transport=http
>>   Enter username for localhost [administrator]:
>>   Enter administrator's password for localhost: <enters incorrect password>
>>   error: failed to connect to the hypervisor
>>   error: internal error: Transport error during enumeration: User, password or
>>   similar was not accepted (26)
>>
>> Signed-off-by: Ladi Prosek <lprosek@redhat.com>
>> ---
>>  src/hyperv/hyperv_driver.c | 2 --
>>  src/hyperv/hyperv_wmi.c    | 1 +
>>  2 files changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
>> index 09912610c..52274239c 100644
>> --- a/src/hyperv/hyperv_driver.c
>> +++ b/src/hyperv/hyperv_driver.c
>> @@ -105,8 +105,6 @@ hypervInitConnection(virConnectPtr conn, hypervPrivate *priv,
>>          priv->wmiVersion = HYPERV_WMI_VERSION_V1;
>>
>>          if (hypervEnumAndPull(priv, &wqlQuery, &computerSystem) < 0) {
>> -            virReportError(VIR_ERR_INTERNAL_ERROR,
>> -                           _("%s is not a Hyper-V server"), conn->uri->server);
>
> This bit is ok...
>
>>              goto cleanup;
>>          }
>>      }
>> diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c
>> index 980a00e28..6a51eff20 100644
>> --- a/src/hyperv/hyperv_wmi.c
>> +++ b/src/hyperv/hyperv_wmi.c
>> @@ -985,6 +985,7 @@ hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery,
>>      hypervObject *object;
>>
>>      if (virBufferCheckError(wqlQuery->query) < 0) {
>> +        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid query"));
>
> ...but virBufferCheckError already reports an error, so this is invalid.

I copied this pattern from hypervSerializeEprParam(), will fix both
places in next version. Thanks!

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

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