virt: some modernizations

Reduce scope of certain allocations, add more debug logging, and improve
some log messages.
This commit is contained in:
Lennart Poettering
2025-03-07 15:11:09 +01:00
parent f63a4ef4a0
commit 4d53d76f5e
+6 -8
View File
@@ -103,32 +103,30 @@ static Virtualization detect_vm_device_tree(void) {
r = read_one_line_file("/proc/device-tree/hypervisor/compatible", &hvtype);
if (r == -ENOENT) {
_cleanup_closedir_ DIR *dir = NULL;
_cleanup_free_ char *compat = NULL;
if (access("/proc/device-tree/ibm,partition-name", F_OK) == 0 &&
access("/proc/device-tree/hmc-managed?", F_OK) == 0 &&
access("/proc/device-tree/chosen/qemu,graphic-width", F_OK) != 0)
return VIRTUALIZATION_POWERVM;
dir = opendir("/proc/device-tree");
_cleanup_closedir_ DIR *dir = opendir("/proc/device-tree");
if (!dir) {
if (errno == ENOENT) {
log_debug_errno(errno, "/proc/device-tree: %m");
log_debug_errno(errno, "/proc/device-tree/ does not exist");
return VIRTUALIZATION_NONE;
}
return -errno;
return log_debug_errno(errno, "Opening /proc/device-tree/ failed: %m");
}
FOREACH_DIRENT(de, dir, return -errno)
FOREACH_DIRENT(de, dir, return log_debug_errno(errno, "Failed to enumerate /proc/device-tree/ contents: %m"))
if (strstr(de->d_name, "fw-cfg")) {
log_debug("Virtualization QEMU: \"fw-cfg\" present in /proc/device-tree/%s", de->d_name);
return VIRTUALIZATION_QEMU;
}
_cleanup_free_ char *compat = NULL;
r = read_one_line_file("/proc/device-tree/compatible", &compat);
if (r < 0 && r != -ENOENT)
return r;
return log_debug_errno(r, "Failed to read /proc/device-tree/compatible: %m");
if (r >= 0 && streq(compat, "qemu,pseries")) {
log_debug("Virtualization %s found in /proc/device-tree/compatible", compat);
return VIRTUALIZATION_QEMU;