代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/systemd 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 785e760653cf5249207caa80857956f0096525df Mon Sep 17 00:00:00 2001
From: Benjamin Herrenschmidt <benh@amazon.com>
Date: Fri, 3 Sep 2021 11:36:46 +1000
Subject: [PATCH] virt: Improve detection of EC2 metal instances
The current detection code relies on /sys/firmware/dmi/entries/0-0/raw
to disambiguate Amazon EC2 virtualized from metal instances.
Unfortunately this file is root only. Thus on a c6g.metal instance
(aarch64), we observe something like this:
$ systemd-detect-virt
amazon
$ sudo systemd-detect-virt
none
Only the latter is correct.
The right long term fix is to extend the kernel to expose the SMBIOS BIOS
Characteristics properly via /sys/class/dmi, but until this happens (and
for backwards compatibility when it does), we need a plan B.
This change implements such a workaround by falling back to using the
instance type from DMI and looking at the ".metal" string present on
metal instances.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
(cherry picked from commit f90eea7d18d9ebe88e6a66cd7a86b618def8945d)
Conflict:NA
Reference:https://github.com/systemd/systemd/commit/785e760653cf5249207caa80857956f0096525df
---
src/basic/virt.c | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/basic/virt.c b/src/basic/virt.c
index 7e88f09b48..7ed01ba3c9 100644
--- a/src/basic/virt.c
+++ b/src/basic/virt.c
@@ -235,8 +235,36 @@ static int detect_vm_dmi(void) {
/* The DMI vendor tables in /sys/class/dmi/id don't help us distinguish between Amazon EC2
* virtual machines and bare-metal instances, so we need to look at SMBIOS. */
- if (r == VIRTUALIZATION_AMAZON && detect_vm_smbios() == SMBIOS_VM_BIT_UNSET)
- return VIRTUALIZATION_NONE;
+ if (r == VIRTUALIZATION_AMAZON) {
+ switch (detect_vm_smbios()) {
+ case SMBIOS_VM_BIT_SET:
+ return VIRTUALIZATION_AMAZON;
+ case SMBIOS_VM_BIT_UNSET:
+ return VIRTUALIZATION_NONE;
+ case SMBIOS_VM_BIT_UNKNOWN: {
+ /* The DMI information we are after is only accessible to the root user,
+ * so we fallback to using the product name which is less restricted
+ * to distinguish metal systems from virtualized instances */
+ _cleanup_free_ char *s = NULL;
+
+ r = read_full_virtual_file("/sys/class/dmi/id/product_name", &s, NULL);
+ /* In EC2, virtualized is much more common than metal, so if for some reason
+ * we fail to read the DMI data, assume we are virtualized. */
+ if (r < 0) {
+ log_debug_errno(r, "Can't read /sys/class/dmi/id/product_name,"
+ " assuming virtualized: %m");
+ return VIRTUALIZATION_AMAZON;
+ }
+ if (endswith(truncate_nl(s), ".metal")) {
+ log_debug("DMI product name ends with '.metal', assuming no virtualization");
+ return VIRTUALIZATION_NONE;
+ } else
+ return VIRTUALIZATION_AMAZON;
+ }
+ default:
+ assert_not_reached("Bad virtualization value");
+ }
+ }
/* If we haven't identified a VM, but the firmware indicates that there is one, indicate as much. We
* have no further information about what it is. */
--
2.33.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。