Very nice! This should keep things must simpler and quiet, especially
with brute force clients.
Thanks.
BTW - I ran tests before and after this patch with no diff in results:
# diff 01_run_report.txt 02_run_report.txt
9,10c9,10
< Libvirt-cim revision: 1156
< Libvirt-cim changeset: 555e122
---
Libvirt-cim revision: 1158
Libvirt-cim changeset: d0c6a89
So, +1 and pushed. Thanks!!!
On 10/28/2011 04:03 PM, Eduardo Lima (Etrunko) wrote:
From: Eduardo Lima (Etrunko)<eblima(a)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(a)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;
}
--
Chip Vincent
Open Virtualization
IBM Linux Technology Center
cvincent(a)linux.vnet.ibm.com