lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments
PATCH v2 1/1 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.
---
v1 -> v2:
* Remove redundancy by merging is_ibmz_lpar() and is_ibmz_zvm() into is_ibmz_vm()
* Fix variable naming in is_ibmz_vm()
include/tst_cpu.h | 3 +++ lib/tst_virt.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-)
include/tst_cpu.h +3 -0
@@ -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);
lib/tst_virt.c +45 -1
68 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 1/1 lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments
Hi!
Actually we can simplify the code like this:
+static int is_ibmz(int virt_type)
+{
+ FILE *sysinfo;
+ char line[64];
+ int found_lpar, found_zvm;
+
+ if (virt_type != VIRT_IBMZ_LPAR && virt_type != VIRT_IBMZ_ZVM)
+ return 0;
+
+ if (access("/proc/sysinfo", F_OK) != 0)
+ return 0;
+
+ sysinfo = SAFE_FOPEN(NULL, "/proc/sysinfo", "r");
+ found_lpar = 0;
+ found_zvm = 0;
+ while (fgets(line, sizeof(line), sysinfo) != NULL) {
+ if (strstr(line, "LPAR"))
+ found_lpar = 1;
+ else if (strstr(line, "z/VM"))
+ found_zvm = 1;
+ }
+
+ SAFE_FCLOSE(NULL, sysinfo);
+
+ switch (virt_type) {
+ case VIRT_IBMZ:
+ return found_lpar;
+ case VIRT_IBMZ_LPAR:
+ return found_lpar && !found_zvm;
+ case VIRT_IBMZ_ZVM:
+ return found_lpar && found_zvm;
+ default:
+ return 0;
+ }
+}
+
static int try_systemd_detect_virt(void)
{
FILE *f;
@@ -102,6 +138,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 +157,15 @@ 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(VIRT_IBMZ);
case VIRT_XEN:
return is_xen();
case VIRT_KVM:
return is_kvm();
+ case VIRT_IBMZ:
+ case VIRT_IBMZ_LPAR:
+ case VIRT_IBMZ_ZVM:
+ return is_ibmz(virt_type);
case VIRT_OTHER:
return 0;
}
Do you agree with these changes?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/1 lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments
Quoted 71 lines · Cyril Hrubis
Hi!
Actually we can simplify the code like this:lib/tst_virt.c +44
-1+static int is_ibmz (int virt_type) +{ +FILE *sysinfo; +char line[64 ]; +int found_lpar, found_zvm; + +if (virt_type !=VIRT_IBMZ_LPAR && virt_type !=VIRT_IBMZ_ZVM ) +return 0 ; + +if (access ("/proc/sysinfo" ,F_OK ) !=0 ) +return 0 ; + + sysinfo =SAFE_FOPEN (NULL ,"/proc/sysinfo" ,"r" ); + found_lpar =0 ; + found_zvm =0 ; +while (fgets (line,sizeof (line), sysinfo) !=NULL ) { +if (strstr (line,"LPAR" )) + found_lpar =1 ; +else if (strstr (line,"z/VM" )) + found_zvm =1 ; + } + +SAFE_FCLOSE (NULL , sysinfo); + +switch (virt_type) { +case VIRT_IBMZ : +return found_lpar; +case VIRT_IBMZ_LPAR : +return found_lpar && !found_zvm; +case VIRT_IBMZ_ZVM : +return found_lpar && found_zvm; +default : +return 0 ; + } +} +static int try_systemd_detect_virt (void ) {FILE *f;@@ -102,6 +138,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 +157,15 @@ 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 (VIRT_IBMZ );case VIRT_XEN :return is_xen ();case VIRT_KVM :return is_kvm (); +case VIRT_IBMZ : +case VIRT_IBMZ_LPAR : +case VIRT_IBMZ_ZVM : +return is_ibmz (virt_type);case VIRT_OTHER :return 0 ; }
Quoted 5 lines
Do you agree with these changes?
Signature · 2 lines
Cyril Hrubis [email protected]
Hi, perfect.
Thanks
Regards
Alex
PATCH v2 1/1 lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments
Hi!
Pushed, thanks.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/1 lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments
In reply to Cyril Hrubislib/tst_virt.c static int is_xen(void) · line 74
Quoted 11 lines · Cyril Hrubis
Hi!
Actually we can simplify the code like this:lib/tst_virt.c +8
-0+static int is_ibmz (int virt_type) +{ +FILE *sysinfo; +char line[64 ]; +int found_lpar, found_zvm; + +if (virt_type !=VIRT_IBMZ_LPAR && virt_type !=VIRT_IBMZ_ZVM ) +return 0 ;
Missed VIRT_IBMZ.
Otherwise is good.
Shall i create a new patch ?
Regards
Alex