]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: detect also QEMU emulation on ppc
authorKarel Zak <kzak@redhat.com>
Thu, 5 Feb 2015 15:50:29 +0000 (16:50 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 5 Feb 2015 15:52:43 +0000 (16:52 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu.c

index 82a7dbe05cdab50d129ba6cd9993a6fe975d04fa..7f2568d638086defd9b1855ac66f6c26e5cb6e82 100644 (file)
@@ -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;
 }