<html><body>
<p>I have not tested this patch, this  patch should help prevent excessive libvirt connection failure messages clogging the logs.<br>
<br>
+1<br>
 <br>
Sharad Mishra<br>
Open Virtualization<br>
Linux Technology Center<br>
IBM<br>
<br>
<tt>libvirt-cim-bounces@redhat.com wrote on 10/28/2011 01:03:57 PM:<br>
<br>
> "Eduardo Lima (Etrunko)" <eblima@linux.vnet.ibm.com> </tt><br>
<tt>> Sent by: libvirt-cim-bounces@redhat.com<br>
> </tt><br>
<tt>> 10/28/2011 01:03 PM</tt><br>
<tt>> <br>
> Please respond to<br>
> List for discussion and development of libvirt CIM <libvirt-cim@redhat.com></tt><br>
<tt>> <br>
> To</tt><br>
<tt>> <br>
> libvirt-cim@redhat.com</tt><br>
<tt>> <br>
> cc</tt><br>
<tt>> <br>
> "Eduardo Lima \(Etrunko\)" <eblima@br.ibm.com></tt><br>
<tt>> <br>
> Subject</tt><br>
<tt>> <br>
> [Libvirt-cim] [PATCH] Avoid connection to libvirt if previous attempt fails</tt><br>
<tt>> <br>
> From: Eduardo Lima (Etrunko) <eblima@br.ibm.com><br>
> <br>
> This is a workaround to avoid libvirt flooding error messages in syslog. This<br>
> happens often if a client submits queries for CIM_ superclasses, <br>
> which then will<br>
> translate to a query for each registered class. In our case KVM_, <br>
> LXC_ and XEN_.<br>
> <br>
> Ideally, there should be a way to ask libvirt if a given URI or hypervisor is<br>
> enabled/supported. A patch for that feature is on the works, and as soon as it<br>
> is integrated to libvirt tree this feature will be updated.<br>
> <br>
> Signed-off-by: Eduardo Lima (Etrunko) <eblima@br.ibm.com><br>
> ---<br>
>  libxkutil/misc_util.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++<br>
>  1 files changed, 48 insertions(+), 0 deletions(-)<br>
> <br>
> diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c<br>
> index c2cc204..61893c3 100644<br>
> --- a/libxkutil/misc_util.c<br>
> +++ b/libxkutil/misc_util.c<br>
> @@ -24,6 +24,7 @@<br>
>  <br>
>  #include <stdio.h><br>
>  #include <string.h><br>
> +#include <strings.h><br>
>  #include <stdlib.h><br>
>  #include <stdbool.h><br>
>  #include <stdarg.h><br>
> @@ -53,6 +54,46 @@ static int libvirt_initialized = 0;<br>
>  <br>
>  #define URI_ENV "HYPURI"<br>
>  <br>
> +struct _hypervisor_status_t {<br>
> +        const char *name;<br>
> +        bool enabled;<br>
> +};<br>
> +<br>
> +typedef struct _hypervisor_status_t hypervisor_status_t;<br>
> +<br>
> +static hypervisor_status_t hypervisor_list[] = {<br>
> +        { "xen", true },<br>
> +        { "kvm", true },<br>
> +        { "lxc", true },<br>
> +        { NULL },<br>
> +};<br>
> +<br>
> +static bool get_hypervisor_enabled(const char *hypervisor)<br>
> +{<br>
> +        hypervisor_status_t *h;<br>
> +<br>
> +        for (h = &hypervisor_list[0]; h != NULL; h++) {<br>
> +                if (strncasecmp(hypervisor, h->name, strlen(h->name)) == 0) {<br>
> +                        return h->enabled;<br>
> +                }<br>
> +        }<br>
> +<br>
> +        return false;<br>
> +}<br>
> +<br>
> +static void set_hypervisor_disabled(const char *hypervisor)<br>
> +{<br>
> +        hypervisor_status_t *h;<br>
> +<br>
> +        for (h = &hypervisor_list[0]; h != NULL; h++) {<br>
> +                if (strncasecmp(hypervisor, h->name, strlen(h->name)) == 0) {<br>
> +                        CU_DEBUG("Setting '%s' hypervisor as <br>
> DISABLED", h->name);<br>
> +                        h->enabled = false;<br>
> +                        return;<br>
> +                }<br>
> +        }<br>
> +}<br>
> +<br>
>  static const char *cn_to_uri(const char *classname)<br>
>  {<br>
>          if (STARTS_WITH(classname, "Xen"))<br>
> @@ -117,6 +158,9 @@ virConnectPtr connect_by_classname(const <br>
> CMPIBroker *broker,<br>
>                  return NULL;<br>
>          }<br>
>  <br>
> +        if (!get_hypervisor_enabled(classname))<br>
> +                return NULL;<br>
> +<br>
>          CU_DEBUG("Connecting to libvirt with uri `%s'", uri);<br>
>  <br>
>          pthread_mutex_lock(&libvirt_mutex);<br>
> @@ -129,6 +173,10 @@ virConnectPtr connect_by_classname(const <br>
> CMPIBroker *broker,<br>
>          pthread_mutex_unlock(&libvirt_mutex);<br>
>  <br>
>          if (!conn) {<br>
> +                virErrorPtr error = virGetLastError();<br>
> +                if (error->code == VIR_ERR_NO_CONNECT)<br>
> +                        set_hypervisor_disabled(classname);<br>
> +<br>
>                  CU_DEBUG("Unable to connect to `%s'", uri);<br>
>                  return NULL;<br>
>          }<br>
> -- <br>
> 1.7.4.4<br>
> <br>
> _______________________________________________<br>
> Libvirt-cim mailing list<br>
> Libvirt-cim@redhat.com<br>
> <a href="https://www.redhat.com/mailman/listinfo/libvirt-cim">https://www.redhat.com/mailman/listinfo/libvirt-cim</a><br>
> <br>
</tt></body></html>