Skip to contentSkip to conversation

lib: tst_virt: Add option to override virt detection

PATCH New Cyril Hrubis 2 participants 3 messages Sep 14, 2021 – Sep 15, 2021 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: tst_virt: Add option to override virt detection

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.

---
 lib/tst_virt.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
lib/tst_virt.c +12 -1
index d23d7f564..0fda20a17 100644
@@ -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;
 
Signature · 5 lines
2.26.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH 1/1 lib: tst_virt: Add option to override virt detection

Quoted 7 lines · Cyril Hrubis

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.

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210915/07263be2/attachment.htm>
#2 lore raw

PATCH 1/1 lib: tst_virt: Add option to override virt detection

Hi!

Quoted 9 lines
Quoted 7 lines

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.

I've added a description for the variable into doc/user-guide.txt and pushed, thanks.

Signature · 5 lines
Cyril Hrubis
[email protected]

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