All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] lib: tst_virt: Add option to override virt detection
Date: Tue, 14 Sep 2021 17:02:20 +0200	[thread overview]
Message-ID: <20210914150220.2467-1-chrubis@suse.cz> (raw)
Message-ID: <20210914150220.dtkZWuvPhn-WBVe72xThQqUVLrVoHyJR0dyfgYjLsJ4@z> (raw)

There seems to be cases where systemd-detect-virt does not detect
virtualization correctly. To work around this bugs this commit adds a
a support for LTP_VIRT_OVERRIDE environment variable that if set is used
instead of the output from the systemd-detect-virt command.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
 lib/tst_virt.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/tst_virt.c b/lib/tst_virt.c
index d23d7f564..0fda20a17 100644
--- a/lib/tst_virt.c
+++ b/lib/tst_virt.c
@@ -100,8 +100,18 @@ static int is_ibmz(int virt_type)
 static int try_systemd_detect_virt(void)
 {
 	FILE *f;
-	char virt_type[64];
+	char virt_buf[64];
 	int ret;
+	char *virt_type = getenv("LTP_VIRT_OVERRIDE");
+
+	if (virt_type) {
+		if (!strcmp("", virt_type))
+			return 0;
+
+		goto cmp;
+	}
+
+	virt_type = virt_buf;
 
 	/* See tst_cmd.c */
 	void *old_handler = signal(SIGCHLD, SIG_DFL);
@@ -129,6 +139,7 @@ static int try_systemd_detect_virt(void)
 	if (ret)
 		return 0;
 
+cmp:
 	if (!strncmp("kvm", virt_type, 3))
 		return VIRT_KVM;
 
-- 
2.26.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2021-09-14 15:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-14 15:02 Cyril Hrubis [this message]
2021-09-14 15:02 ` [LTP] [PATCH] lib: tst_virt: Add option to override virt detection Cyril Hrubis
2021-09-15  4:13   ` Li Wang
2021-09-15  4:13     ` Li Wang
2021-09-15  8:14       ` Cyril Hrubis
2021-09-15  8:14         ` Cyril Hrubis

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=20210914150220.2467-1-chrubis@suse.cz \
    --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.