I have not tested this patch, this patch should help prevent excessive libvirt connection failure messages clogging the logs.

+1

Sharad Mishra
Open Virtualization
Linux Technology Center
IBM

libvirt-cim-bounces@redhat.com wrote on 10/28/2011 01:03:57 PM:

> "Eduardo Lima (Etrunko)" <eblima@linux.vnet.ibm.com>

> Sent by: libvirt-cim-bounces@redhat.com
>

> 10/28/2011 01:03 PM
>
> Please respond to
> List for discussion and development of libvirt CIM <libvirt-cim@redhat.com>

>
> To

>
> libvirt-cim@redhat.com

>
> cc

>
> "Eduardo Lima \(Etrunko\)" <eblima@br.ibm.com>

>
> Subject

>
> [Libvirt-cim] [PATCH] Avoid connection to libvirt if previous attempt fails

>
> From: Eduardo Lima (Etrunko) <eblima@br.ibm.com>
>
> This is a workaround to avoid libvirt flooding error messages in syslog. This
> happens often if a client submits queries for CIM_ superclasses,
> which then will
> translate to a query for each registered class. In our case KVM_,
> LXC_ and XEN_.
>
> Ideally, there should be a way to ask libvirt if a given URI or hypervisor is
> enabled/supported. A patch for that feature is on the works, and as soon as it
> is integrated to libvirt tree this feature will be updated.
>
> Signed-off-by: Eduardo Lima (Etrunko) <eblima@br.ibm.com>
> ---
>  libxkutil/misc_util.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 48 insertions(+), 0 deletions(-)
>
> diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c
> index c2cc204..61893c3 100644
> --- a/libxkutil/misc_util.c
> +++ b/libxkutil/misc_util.c
> @@ -24,6 +24,7 @@
>  
>  #include <stdio.h>
>  #include <string.h>
> +#include <strings.h>
>  #include <stdlib.h>
>  #include <stdbool.h>
>  #include <stdarg.h>
> @@ -53,6 +54,46 @@ static int libvirt_initialized = 0;
>  
>  #define URI_ENV "HYPURI"
>  
> +struct _hypervisor_status_t {
> +        const char *name;
> +        bool enabled;
> +};
> +
> +typedef struct _hypervisor_status_t hypervisor_status_t;
> +
> +static hypervisor_status_t hypervisor_list[] = {
> +        { "xen", true },
> +        { "kvm", true },
> +        { "lxc", true },
> +        { NULL },
> +};
> +
> +static bool get_hypervisor_enabled(const char *hypervisor)
> +{
> +        hypervisor_status_t *h;
> +
> +        for (h = &hypervisor_list[0]; h != NULL; h++) {
> +                if (strncasecmp(hypervisor, h->name, strlen(h->name)) == 0) {
> +                        return h->enabled;
> +                }
> +        }
> +
> +        return false;
> +}
> +
> +static void set_hypervisor_disabled(const char *hypervisor)
> +{
> +        hypervisor_status_t *h;
> +
> +        for (h = &hypervisor_list[0]; h != NULL; h++) {
> +                if (strncasecmp(hypervisor, h->name, strlen(h->name)) == 0) {
> +                        CU_DEBUG("Setting '%s' hypervisor as
> DISABLED", h->name);
> +                        h->enabled = false;
> +                        return;
> +                }
> +        }
> +}
> +
>  static const char *cn_to_uri(const char *classname)
>  {
>          if (STARTS_WITH(classname, "Xen"))
> @@ -117,6 +158,9 @@ virConnectPtr connect_by_classname(const
> CMPIBroker *broker,
>                  return NULL;
>          }
>  
> +        if (!get_hypervisor_enabled(classname))
> +                return NULL;
> +
>          CU_DEBUG("Connecting to libvirt with uri `%s'", uri);
>  
>          pthread_mutex_lock(&libvirt_mutex);
> @@ -129,6 +173,10 @@ virConnectPtr connect_by_classname(const
> CMPIBroker *broker,
>          pthread_mutex_unlock(&libvirt_mutex);
>  
>          if (!conn) {
> +                virErrorPtr error = virGetLastError();
> +                if (error->code == VIR_ERR_NO_CONNECT)
> +                        set_hypervisor_disabled(classname);
> +
>                  CU_DEBUG("Unable to connect to `%s'", uri);
>                  return NULL;
>          }
> --
> 1.7.4.4
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim@redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
>