am 89461623: Merge "Allow path to KVM to be overridden by environment." into idea133 automerge: 4ebb7b4
* commit '89461623ee2b7c0dc4019c43da575c3adf8497ee':
Allow path to KVM to be overridden by environment.
diff --git a/include/android/kvm.h b/include/android/kvm.h
index c0ad76a..a0bf579 100644
--- a/include/android/kvm.h
+++ b/include/android/kvm.h
@@ -1,6 +1,10 @@
#ifndef KVM_ANDROID_H
#define KVM_ANDROID_H
+// Name of environment variable used to control the name of the device
+// to use, when it is not /dev/kvm
+#define KVM_DEVICE_NAME_ENV "ANDROID_EMULATOR_KVM_DEVICE"
+
/* Returns 1 if we can use /dev/kvm on this machine */
extern int kvm_check_allowed(void);
diff --git a/kvm-all.c b/kvm-all.c
index 917cfcd..8f0838b 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -24,6 +24,7 @@
#include "qemu-common.h"
#include "sysemu/sysemu.h"
#include "hw/hw.h"
+#include "android/kvm.h"
#include "exec/gdbstub.h"
#include "sysemu/kvm.h"
@@ -442,8 +443,13 @@
for (i = 0; i < ARRAY_SIZE(s->slots); i++)
s->slots[i].slot = i;
+ char* kvm_device = getenv(KVM_DEVICE_NAME_ENV);
+ if (NULL == kvm_device) {
+ kvm_device = "/dev/kvm";
+ }
+
s->vmfd = -1;
- s->fd = open("/dev/kvm", O_RDWR);
+ s->fd = open(kvm_device, O_RDWR);
if (s->fd == -1) {
ret = -errno;
fprintf(stderr, "Could not access KVM kernel module: %m\n");
diff --git a/kvm-android.c b/kvm-android.c
index 76d5a55..6e5810e 100644
--- a/kvm-android.c
+++ b/kvm-android.c
@@ -1,6 +1,8 @@
#include <unistd.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/utsname.h>
+#include "android/kvm.h"
#include "android/utils/debug.h"
#define D(...) VERBOSE_PRINT(init,__VA_ARGS__)
@@ -17,15 +19,20 @@
int
kvm_check_allowed(void)
{
+
+ char* kvm_device = getenv(KVM_DEVICE_NAME_ENV);
+ if (NULL == kvm_device) {
+ kvm_device = "/dev/kvm";
+ }
/* Is there a /dev/kvm device file here? */
- if (access("/dev/kvm",F_OK)) {
+ if (access(kvm_device,F_OK)) {
/* no need to print a warning here */
D("No kvm device file detected");
return 0;
}
/* Can we access it? */
- if (access("/dev/kvm",R_OK)) {
+ if (access(kvm_device,R_OK)) {
D("KVM device file is not readable for this user.");
return 0;
}