From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 1/1] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments
Date: Mon, 9 Nov 2020 16:09:43 +0100 [thread overview]
Message-ID: <20201109150943.GB25892@yuki.lan> (raw)
In-Reply-To: <20201109145657.602251-1-egorenar@linux.ibm.com>
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?
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2020-11-09 15:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-09 14:56 [LTP] [PATCH v2 1/1] lib/tst_virt: support IBM/Z LPAR and z/VM virtualization environments Alexander Egorenkov
2020-11-09 15:09 ` Cyril Hrubis [this message]
2020-11-09 15:11 ` Alexander Egorenkov
2020-11-09 15:14 ` Cyril Hrubis
2020-11-09 15:13 ` Alexander Egorenkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201109150943.GB25892@yuki.lan \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.