]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: add Hypervisor to output
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Tue, 6 Sep 2011 00:53:02 +0000 (02:53 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 9 Sep 2011 21:54:01 +0000 (23:54 +0200)
Some vendors have several hypervisors. Therefore it makes sense to not only
print out the hypervisor vendor but also the name of the hypervisor.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu.c
tests/expected/lscpu/lscpu-s390-lpar
tests/expected/lscpu/lscpu-s390-zvm

index 69e80eb3c1f2857bb657a833dbeecb76d5720da3..601c8729c8801f249782867787f36333434a3dd5 100644 (file)
@@ -137,6 +137,7 @@ struct lscpu_desc {
        char    *family;
        char    *model;
        char    *virtflag;      /* virtualization flag (vmx, svm) */
+       char    *hypervisor;    /* hypervisor software */
        int     hyper;          /* hypervisor vendor ID */
        int     virtype;        /* VIRT_PARA|FULL|NONE ? */
        char    *mhz;
@@ -672,14 +673,31 @@ read_hypervisor(struct lscpu_desc *desc)
                char buf[BUFSIZ];
 
                desc->hyper = HYPER_IBM;
+               desc->hypervisor = "PR/SM";
                desc->virtype = VIRT_FULL;
                while (fgets(buf, sizeof(buf), fd) != NULL) {
+                       char *str;
+
                        if (!strstr(buf, "Control Program:"))
                                continue;
                        if (!strstr(buf, "KVM"))
                                desc->hyper = HYPER_IBM;
                        else
                                desc->hyper = HYPER_KVM;
+                       str = strchr(buf, ':');
+                       if (!str)
+                               continue;
+                       if (asprintf(&str, str + 1) == -1)
+                               errx(EXIT_FAILURE, _("failed to allocate memory"));
+                       /* remove leading, trailing and repeating whitespace */
+                       while (*str == ' ')
+                               str++;
+                       desc->hypervisor = str;
+                       str += strlen(str) - 1;
+                       while ((*str == '\n') || (*str == ' '))
+                               *(str--) = '\0';
+                       while ((str = strstr(desc->hypervisor, "  ")))
+                               memmove(str, str + 1, strlen(str));
                }
                fclose(fd);
        }
@@ -1276,6 +1294,8 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
                else if (!strcmp(desc->virtflag, "vmx"))
                        print_s(_("Virtualization:"), "VT-x");
        }
+       if (desc->hypervisor)
+               print_s(_("Hypervisor:"), desc->hypervisor);
        if (desc->hyper) {
                print_s(_("Hypervisor vendor:"), hv_vendors[desc->hyper]);
                print_s(_("Virtualization type:"), virt_types[desc->virtype]);
index 600fd3f09b2839d220f8e7b5a357d56c5e036ab4..0799ab9c7d4c891c61bede0be8de8c42dc58f913 100644 (file)
@@ -8,6 +8,7 @@ Socket(s) per book:    6
 Book(s):               4
 Vendor ID:             IBM/S390
 BogoMIPS:              14367.00
+Hypervisor:            PR/SM
 Hypervisor vendor:     IBM
 Virtualization type:   full
 Dispatching mode:      vertical
index 9ce22d49bbdeb2203843a4c8332f7b715dac99f9..04dcf7698ac9564ffad2230a3ec201b36cb9640b 100644 (file)
@@ -7,6 +7,7 @@ Socket(s) per book:    1
 Book(s):               4
 Vendor ID:             IBM/S390
 BogoMIPS:              14367.00
+Hypervisor:            z/VM 6.1.0
 Hypervisor vendor:     IBM
 Virtualization type:   full
 Dispatching mode:      horizontal