* [LTP] [PATCH 0/2] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments
@ 2020-11-06 13:06 Alexander Egorenkov
2020-11-06 13:06 ` [LTP] [PATCH 1/2] lib/tst_virt: fix detection when systemd-detect-virt returns 1 Alexander Egorenkov
2020-11-06 13:06 ` [LTP] [PATCH 2/2] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments Alexander Egorenkov
0 siblings, 2 replies; 5+ messages in thread
From: Alexander Egorenkov @ 2020-11-06 13:06 UTC (permalink / raw)
To: ltp
Support detection of virtualization environment on IBM System Z.
Alexander Egorenkov (2):
lib/tst_virt: fix detection when systemd-detect-virt returns 1
lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments
include/tst_cpu.h | 3 +++
lib/tst_virt.c | 66 ++++++++++++++++++++++++++++++++++++++++++++---
2 files changed, 66 insertions(+), 3 deletions(-)
--
2.26.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [LTP] [PATCH 1/2] lib/tst_virt: fix detection when systemd-detect-virt returns 1
2020-11-06 13:06 [LTP] [PATCH 0/2] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments Alexander Egorenkov
@ 2020-11-06 13:06 ` Alexander Egorenkov
2020-11-09 14:31 ` Cyril Hrubis
2020-11-06 13:06 ` [LTP] [PATCH 2/2] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments Alexander Egorenkov
1 sibling, 1 reply; 5+ messages in thread
From: Alexander Egorenkov @ 2020-11-06 13:06 UTC (permalink / raw)
To: ltp
From: Alexander Egorenkov <Alexander.Egorenkov@ibm.com>
When systemd-detect-virt detects no virtualization environment,
it returns 1 as exit code. This leads to tst_is_virt not doing any
fallback tests.
The problem can be reproduced inside a IBM System Z LPAR virtualization
environment.
Signed-off-by: Alexander Egorenkov <egorenar@linux.ibm.com>
---
lib/tst_virt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/tst_virt.c b/lib/tst_virt.c
index 53d33e69c..914a08d96 100644
--- a/lib/tst_virt.c
+++ b/lib/tst_virt.c
@@ -109,9 +109,9 @@ int tst_is_virt(int virt_type)
{
int ret = try_systemd_detect_virt();
- if (ret >= 0) {
+ if (ret > 0) {
if (virt_type == VIRT_ANY)
- return ret != 0;
+ return 1;
else
return ret == virt_type;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH 2/2] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments
2020-11-06 13:06 [LTP] [PATCH 0/2] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments Alexander Egorenkov
2020-11-06 13:06 ` [LTP] [PATCH 1/2] lib/tst_virt: fix detection when systemd-detect-virt returns 1 Alexander Egorenkov
@ 2020-11-06 13:06 ` Alexander Egorenkov
2020-11-09 14:42 ` Cyril Hrubis
1 sibling, 1 reply; 5+ messages in thread
From: Alexander Egorenkov @ 2020-11-06 13:06 UTC (permalink / raw)
To: ltp
From: Alexander Egorenkov <Alexander.Egorenkov@ibm.com>
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 <egorenar@linux.ibm.com>
---
include/tst_cpu.h | 3 +++
lib/tst_virt.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 64 insertions(+), 1 deletion(-)
diff --git a/include/tst_cpu.h b/include/tst_cpu.h
index c83a58260..117e27087 100644
--- a/include/tst_cpu.h
+++ b/include/tst_cpu.h
@@ -12,6 +12,9 @@ long tst_ncpus_max(void);
#define VIRT_ANY 0 /* catch-all argument for tst_is_virt() */
#define VIRT_XEN 1 /* xen dom0/domU */
#define VIRT_KVM 2 /* only default virtual CPU */
+#define VIRT_IBMZ 3 /* ibm system z */
+#define VIRT_IBMZ_LPAR 4 /* ibm system z lpar */
+#define VIRT_IBMZ_ZVM 5 /* ibm system z zvm */
#define VIRT_OTHER 0xffff /* unrecognized hypervisor */
int tst_is_virt(int virt_type);
diff --git a/lib/tst_virt.c b/lib/tst_virt.c
index 914a08d96..c57d4fcfc 100644
--- a/lib/tst_virt.c
+++ b/lib/tst_virt.c
@@ -64,6 +64,57 @@ static int is_xen(void)
return 0;
}
+static int is_ibmz_lpar(void)
+{
+ FILE *cpuinfo;
+ char line[64];
+ int found_lpar, found_zvm;
+
+ if (access("/proc/sysinfo", F_OK) != 0)
+ return 0;
+
+ cpuinfo = SAFE_FOPEN(NULL, "/proc/sysinfo", "r");
+ found_lpar = 0;
+ found_zvm = 0;
+ while (fgets(line, sizeof(line), cpuinfo) != NULL) {
+ if (strstr(line, "LPAR"))
+ found_lpar = 1;
+ else if (strstr(line, "z/VM"))
+ found_zvm = 1;
+ }
+
+ SAFE_FCLOSE(NULL, cpuinfo);
+ return found_lpar && !found_zvm;
+}
+
+static int is_ibmz_zvm(void)
+{
+ FILE *cpuinfo;
+ char line[64];
+ int found_lpar, found_zvm;
+
+ if (access("/proc/sysinfo", F_OK) != 0)
+ return 0;
+
+ cpuinfo = SAFE_FOPEN(NULL, "/proc/sysinfo", "r");
+ found_lpar = 0;
+ found_zvm = 0;
+ while (fgets(line, sizeof(line), cpuinfo) != NULL) {
+ if (strstr(line, "LPAR"))
+ found_lpar = 1;
+ else if (strstr(line, "z/VM"))
+ found_zvm = 1;
+ }
+
+ SAFE_FCLOSE(NULL, cpuinfo);
+ return found_lpar && found_zvm;
+}
+
+static int is_ibmz(void)
+{
+ return is_ibmz_lpar() || is_ibmz_zvm();
+}
+
static int try_systemd_detect_virt(void)
{
FILE *f;
@@ -102,6 +153,9 @@ static int try_systemd_detect_virt(void)
if (!strncmp("xen", virt_type, 3))
return VIRT_XEN;
+ if (!strncmp("zvm", virt_type, 3))
+ return VIRT_IBMZ_ZVM;
+
return VIRT_OTHER;
}
@@ -118,11 +172,17 @@ int tst_is_virt(int virt_type)
switch (virt_type) {
case VIRT_ANY:
- return is_xen() || is_kvm();
+ return is_xen() || is_kvm() || is_ibmz();
case VIRT_XEN:
return is_xen();
case VIRT_KVM:
return is_kvm();
+ case VIRT_IBMZ:
+ return is_ibmz();
+ case VIRT_IBMZ_LPAR:
+ return is_ibmz_lpar();
+ case VIRT_IBMZ_ZVM:
+ return is_ibmz_zvm();
case VIRT_OTHER:
return 0;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH 1/2] lib/tst_virt: fix detection when systemd-detect-virt returns 1
2020-11-06 13:06 ` [LTP] [PATCH 1/2] lib/tst_virt: fix detection when systemd-detect-virt returns 1 Alexander Egorenkov
@ 2020-11-09 14:31 ` Cyril Hrubis
0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2020-11-09 14:31 UTC (permalink / raw)
To: ltp
Hi!
Good catch, applied, thanks.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 5+ messages in thread
* [LTP] [PATCH 2/2] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments
2020-11-06 13:06 ` [LTP] [PATCH 2/2] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments Alexander Egorenkov
@ 2020-11-09 14:42 ` Cyril Hrubis
0 siblings, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2020-11-09 14:42 UTC (permalink / raw)
To: ltp
Hi!
> +static int is_ibmz_lpar(void)
> +{
> + FILE *cpuinfo;
> + char line[64];
> + int found_lpar, found_zvm;
> +
> + if (access("/proc/sysinfo", F_OK) != 0)
> + return 0;
> +
> + cpuinfo = SAFE_FOPEN(NULL, "/proc/sysinfo", "r");
> + found_lpar = 0;
> + found_zvm = 0;
> + while (fgets(line, sizeof(line), cpuinfo) != NULL) {
> + if (strstr(line, "LPAR"))
> + found_lpar = 1;
> + else if (strstr(line, "z/VM"))
> + found_zvm = 1;
> + }
> +
> + SAFE_FCLOSE(NULL, cpuinfo);
> + return found_lpar && !found_zvm;
> +}
> +
> +static int is_ibmz_zvm(void)
> +{
> + FILE *cpuinfo;
> + char line[64];
> + int found_lpar, found_zvm;
> +
> + if (access("/proc/sysinfo", F_OK) != 0)
> + return 0;
> +
> + cpuinfo = SAFE_FOPEN(NULL, "/proc/sysinfo", "r");
> + found_lpar = 0;
> + found_zvm = 0;
> + while (fgets(line, sizeof(line), cpuinfo) != NULL) {
> + if (strstr(line, "LPAR"))
> + found_lpar = 1;
> + else if (strstr(line, "z/VM"))
> + found_zvm = 1;
> + }
> +
> + SAFE_FCLOSE(NULL, cpuinfo);
> + return found_lpar && found_zvm;
> +}
These two function are nearly identical apart from the last line, I
guess that it would be cleaner to have one function and pass the
VIRT_IBMZ_LPAR and VIRT_IBMZ_ZVM constants to select which result we
want.
Other than this, the rest looks good.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-11-09 14:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-06 13:06 [LTP] [PATCH 0/2] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments Alexander Egorenkov
2020-11-06 13:06 ` [LTP] [PATCH 1/2] lib/tst_virt: fix detection when systemd-detect-virt returns 1 Alexander Egorenkov
2020-11-09 14:31 ` Cyril Hrubis
2020-11-06 13:06 ` [LTP] [PATCH 2/2] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments Alexander Egorenkov
2020-11-09 14:42 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox