Skip to content

Commit

Permalink
virt: Further improve detection of EC2 metal instances
Browse files Browse the repository at this point in the history
Commit f90eea7
virt: Improve detection of EC2 metal instances

Added support for detecting EC2 metal instances via the product
name in DMI by testing for the ".metal" suffix.

Unfortunately this doesn't cover all cases, as there are going to be
instance types where ".metal" is not a suffix (ie, .metal-16xl,
.metal-32xl, ...)

This modifies the logic to also allow those new forms.

Signed-off-by: Benjamin Herrenschmidt <benh@amazon.com>
  • Loading branch information
ozbenh authored and bluca committed Apr 17, 2023
1 parent c8ae0a8 commit aab896e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/basic/virt.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ static Virtualization detect_vm_dmi(void) {
* so we fallback to using the product name which is less restricted
* to distinguish metal systems from virtualized instances */
_cleanup_free_ char *s = NULL;
const char *e;

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
Expand All @@ -273,8 +274,9 @@ static Virtualization detect_vm_dmi(void) {
" assuming virtualized: %m");
return VIRTUALIZATION_AMAZON;
}
if (endswith(truncate_nl(s), ".metal")) {
log_debug("DMI product name ends with '.metal', assuming no virtualization");
e = strstrafter(truncate_nl(s), ".metal");
if (e && IN_SET(*e, 0, '-')) {
log_debug("DMI product name has '.metal', assuming no virtualization");
return VIRTUALIZATION_NONE;
} else
return VIRTUALIZATION_AMAZON;
Expand Down

0 comments on commit aab896e

Please sign in to comment.