summaryrefslogtreecommitdiffstats
path: root/sys-utils/lscpu.c
diff options
context:
space:
mode:
authorKarel Zak2015-02-05 16:50:29 +0100
committerKarel Zak2015-02-05 16:52:43 +0100
commit3565bd7aec78894eaf4aee7dd5602f29154ebf5a (patch)
tree87c65c459b9c924a424f211a3113868624915fcf /sys-utils/lscpu.c
parentbuild-sys: release++ (v2.26-rc2) (diff)
downloadkernel-qcow2-util-linux-3565bd7aec78894eaf4aee7dd5602f29154ebf5a.tar.gz
kernel-qcow2-util-linux-3565bd7aec78894eaf4aee7dd5602f29154ebf5a.tar.xz
kernel-qcow2-util-linux-3565bd7aec78894eaf4aee7dd5602f29154ebf5a.zip
lscpu: detect also QEMU emulation on ppc
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/lscpu.c')
-rw-r--r--sys-utils/lscpu.c56
1 files changed, 37 insertions, 19 deletions
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 82a7dbe05..7f2568d63 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -594,6 +594,30 @@ read_hypervisor_cpuid(struct lscpu_desc *desc __attribute__((__unused__)))
}
#endif
+static int is_compatible(const char *path, const char *str)
+{
+ FILE *fd;
+
+ fd = path_fopen("r", 0, path);
+ if (fd) {
+ char buf[256];
+ size_t i, len;
+
+ memset(buf, 0, sizeof(buf));
+ len = fread(buf, 1, sizeof(buf) - 1, fd);
+ fclose(fd);
+
+ for (i = 0; i < len;) {
+ if (!strcmp(&buf[i], str))
+ return 1;
+ i += strlen(&buf[i]);
+ i++;
+ }
+ }
+
+ return 0;
+}
+
static int
read_hypervisor_powerpc(struct lscpu_desc *desc)
{
@@ -605,7 +629,10 @@ read_hypervisor_powerpc(struct lscpu_desc *desc)
* if partition-name is "full", its kind of "bare-metal": full-system-partition
* otherwise its some partition created by Hardware Management Console
* in any case, its always some sort of HVM
- * Note that pSeries could also be emulated by qemu/KVM.
+ *
+ * Note that pSeries could also be emulated by qemu and it's
+ * indicated by 'qemu,pseries" in /compatible
+ *
* KVM: "linux,kvm" in /hypervisor/compatible indicates a KVM guest
* Xen: not in use, not detected
*/
@@ -626,26 +653,17 @@ read_hypervisor_powerpc(struct lscpu_desc *desc)
fclose(fd);
}
} else if (path_exist(_PATH_PROC_DEVICETREE "/hypervisor/compatible")) {
- FILE *fd;
- fd = path_fopen("r", 0, _PATH_PROC_DEVICETREE "/hypervisor/compatible");
- if (fd) {
- char buf[256];
- size_t i, len;
- memset(buf, 0, sizeof(buf));
- len = fread(buf, 1, sizeof(buf) - 1, fd);
- fclose(fd);
- for (i = 0; i < len;) {
- if (!strcmp(&buf[i], "linux,kvm")) {
- desc->hyper = HYPER_KVM;
- desc->virtype = VIRT_FULL;
- break;
- }
- i += strlen(&buf[i]);
- i++;
- }
+ if (is_compatible(_PATH_PROC_DEVICETREE "/hypervisor/compatible",
+ "linux,kvm")) {
+ desc->hyper = HYPER_KVM;
+ desc->virtype = VIRT_FULL;
+ }
+ } else if (path_exist(_PATH_PROC_DEVICETREE "/compatible")) {
+ if (is_compatible(_PATH_PROC_DEVICETREE "/compatible", "qemu,pseries")) {
+ desc->hyper = HYPER_KVM;
+ desc->virtype = VIRT_FULL;
}
}
-
return desc->hyper;
}