aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiao He <xiao.he@intel.com>2021-03-16 15:45:16 +0800
committerHuang Yang <yang.huang@intel.com>2021-03-22 08:53:52 +0800
commita8b0103f75147eab09a59595535cb786ad9910a2 (patch)
treefe08255ada22e33dbc01b7c39e369fe2ad7f45fd
parent2ca2eca556152cdf276b265ec73d586d3ef70a00 (diff)
downloadltp-a8b0103f75147eab09a59595535cb786ad9910a2.tar.gz
Enhanced detection of KVM
Added additional detection for KVM by checking the existing of /dev/vda or /dev/block/vda and update is_kvm method accordingly Bug: 179100925 Test: vts-tradefed run vts -m vts_ltp_test_x86_64 Change-Id: I741d443da859c0d77f43a00dd34fc58b5c0df46d Signed-off-by: Xiao He <xiao.he@intel.com>
-rw-r--r--lib/tst_virt.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/tst_virt.c b/lib/tst_virt.c
index c05da0a3c..d21f74c1c 100644
--- a/lib/tst_virt.c
+++ b/lib/tst_virt.c
@@ -23,9 +23,20 @@
*/
#include <unistd.h>
+#include <sys/stat.h>
#include "test.h"
#include "safe_macros.h"
+static int file_exist(const char *path)
+{
+ struct stat st;
+
+ if (!access(path, R_OK) && !stat(path, &st))
+ return 1;
+
+ return 0;
+}
+
static int is_kvm(void)
{
FILE *cpuinfo;
@@ -44,6 +55,10 @@ static int is_kvm(void)
}
SAFE_FCLOSE(NULL, cpuinfo);
+
+ if (file_exist("/dev/vda") || file_exist("/dev/block/vda"))
+ found = 1;
+
return found;
}