
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com> Since libvirt-cim doesn't handle nested KVM well now, so add this option to manually disable KVM and fall back to qemu. Signed-off-by: Xu Wang <cngesaint@outlook.com> --- libvirt-cim.conf | 9 +++++++++ libxkutil/misc_util.c | 8 ++++++++ libxkutil/misc_util.h | 1 + src/Virt_VirtualSystemManagementService.c | 7 +++++++ 4 files changed, 25 insertions(+), 0 deletions(-) diff --git a/libvirt-cim.conf b/libvirt-cim.conf index 37d7b0f..f6464c3 100644 --- a/libvirt-cim.conf +++ b/libvirt-cim.conf @@ -30,3 +30,12 @@ # Default value: NULL, that is not set. # # migrate_ssh_temp_key = "/root/vm_migrate_tmp_id_rsa"; + +# disable_kvm (bool) +# When executing in a nested KVM environment libvirt-cim may fail +# unexpectedly with some error. Setting "disable_kvm" option to true +# disables use of KVM and falls back to using QEMU directly. +# Possible values: {true,false} +# Default value: false +# +# disable_kvm = false; diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c index 00eb4b1..921604c 100644 --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -227,6 +227,14 @@ static int is_read_only(void) return prop.value_bool; } +bool get_disable_kvm(void) +{ + static LibvirtcimConfigProperty prop = { + "disable_kvm", CONFIG_BOOL, {0}, 0}; + libvirt_cim_config_get(&prop); + return prop.value_bool; +} + const char *get_mig_ssh_tmp_key(void) { static LibvirtcimConfigProperty prop = { diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h index 0f52290..8493005 100644 --- a/libxkutil/misc_util.h +++ b/libxkutil/misc_util.h @@ -154,6 +154,7 @@ int virt_set_status(const CMPIBroker *broker, /* get libvirt-cim config */ const char *get_mig_ssh_tmp_key(void); +bool get_disable_kvm(void); /* * Local Variables: diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c index cbb646d..1369c6a 100644 --- a/src/Virt_VirtualSystemManagementService.c +++ b/src/Virt_VirtualSystemManagementService.c @@ -394,6 +394,13 @@ static bool system_has_kvm(const char *pfx) virConnectPtr conn; char *caps = NULL; bool kvm = false; + bool disable_kvm = get_disable_kvm(); + + /* sometimes disable KVM to avoid problem in nested KVM */ + if (disable_kvm) { + CU_DEBUG("Enter disable kvm mode!"); + return false; + } conn = connect_by_classname(_BROKER, pfx, &s); if ((conn == NULL) || (s.rc != CMPI_RC_OK)) { -- 1.7.1