Skip to content

Commit b2cc450

Browse files
eaibmzmetan-ucw
authored andcommitted
lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments
Add 3 new virtualization types for IBM System Z architecture: * VIRT_IBMZ (either LPAR ot z/VM) * VIRT_IBMZ_LPAR (LPAR only) * VIRT_IBMZ_ZVM (z/VM only) VIRT_IBMZ is true when either VIRT_IBMZ_LPAR or VIRT_IBMZ_ZVM is true. Signed-off-by: Alexander Egorenkov <[email protected]> Signed-off-by: Cyril Hrubis <[email protected]>
1 parent ffdd5ed commit b2cc450

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

include/tst_cpu.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ long tst_ncpus_max(void);
1212
#define VIRT_ANY 0 /* catch-all argument for tst_is_virt() */
1313
#define VIRT_XEN 1 /* xen dom0/domU */
1414
#define VIRT_KVM 2 /* only default virtual CPU */
15+
#define VIRT_IBMZ 3 /* ibm system z */
16+
#define VIRT_IBMZ_LPAR 4 /* ibm system z lpar */
17+
#define VIRT_IBMZ_ZVM 5 /* ibm system z zvm */
1518
#define VIRT_OTHER 0xffff /* unrecognized hypervisor */
1619

1720
int tst_is_virt(int virt_type);

lib/tst_virt.c

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,42 @@ static int is_xen(void)
6464
return 0;
6565
}
6666

67+
static int is_ibmz(int virt_type)
68+
{
69+
FILE *sysinfo;
70+
char line[64];
71+
int found_lpar, found_zvm;
72+
73+
if (virt_type != VIRT_IBMZ_LPAR && virt_type != VIRT_IBMZ_ZVM)
74+
return 0;
75+
76+
if (access("/proc/sysinfo", F_OK) != 0)
77+
return 0;
78+
79+
sysinfo = SAFE_FOPEN(NULL, "/proc/sysinfo", "r");
80+
found_lpar = 0;
81+
found_zvm = 0;
82+
while (fgets(line, sizeof(line), sysinfo) != NULL) {
83+
if (strstr(line, "LPAR"))
84+
found_lpar = 1;
85+
else if (strstr(line, "z/VM"))
86+
found_zvm = 1;
87+
}
88+
89+
SAFE_FCLOSE(NULL, sysinfo);
90+
91+
switch (virt_type) {
92+
case VIRT_IBMZ:
93+
return found_lpar;
94+
case VIRT_IBMZ_LPAR:
95+
return found_lpar && !found_zvm;
96+
case VIRT_IBMZ_ZVM:
97+
return found_lpar && found_zvm;
98+
default:
99+
return 0;
100+
}
101+
}
102+
67103
static int try_systemd_detect_virt(void)
68104
{
69105
FILE *f;
@@ -102,6 +138,9 @@ static int try_systemd_detect_virt(void)
102138
if (!strncmp("xen", virt_type, 3))
103139
return VIRT_XEN;
104140

141+
if (!strncmp("zvm", virt_type, 3))
142+
return VIRT_IBMZ_ZVM;
143+
105144
return VIRT_OTHER;
106145
}
107146

@@ -118,11 +157,15 @@ int tst_is_virt(int virt_type)
118157

119158
switch (virt_type) {
120159
case VIRT_ANY:
121-
return is_xen() || is_kvm();
160+
return is_xen() || is_kvm() || is_ibmz(VIRT_IBMZ);
122161
case VIRT_XEN:
123162
return is_xen();
124163
case VIRT_KVM:
125164
return is_kvm();
165+
case VIRT_IBMZ:
166+
case VIRT_IBMZ_LPAR:
167+
case VIRT_IBMZ_ZVM:
168+
return is_ibmz(virt_type);
126169
case VIRT_OTHER:
127170
return 0;
128171
}

0 commit comments

Comments
 (0)