]> git.proxmox.com Git - pve-manager.git/commitdiff
api: node status: cache boot mode info
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 22 Nov 2023 15:07:09 +0000 (16:07 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 22 Nov 2023 15:09:15 +0000 (16:09 +0100)
it's not that expensive but we call the endpoint that returns the boot
mode info very frequently, and EFI vars are provided by the firmware,
and there are lots of known cases where firmware was just a plain
mess.

So, don't risk that overly frequent reads will cause some weird side
effect and rather just cache the whole info, it cannot change without
a reboot anyway.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Nodes.pm

index c1d5f5ea7a7b1d2c2c907441b163972cd10c8d60..94b2017268994b8bb39c8543fe978c344434e52d 100644 (file)
@@ -355,10 +355,13 @@ my sub get_current_kernel_info {
     return ($current_kernel, $kernel_version_string);
 }
 
+my $boot_mode_info_cache;
 my sub get_boot_mode_info {
+    return $boot_mode_info_cache if defined($boot_mode_info_cache);
+
     my $is_efi_booted = -d "/sys/firmware/efi";
 
-    my $info = {
+    $boot_mode_info_cache = {
        mode => $is_efi_booted ? 'efi' : 'legacy-bios',
     };
 
@@ -368,10 +371,10 @@ my sub get_boot_mode_info {
            warn "Failed to read secure boot state: $@\n";
        } else {
            my @secureboot = unpack("CCCCC", $efi_var_sec_boot_entry);
-           $info->{secureboot} = $secureboot[4] == 1 ? 1 : 0;
+           $boot_mode_info_cache->{secureboot} = $secureboot[4] == 1 ? 1 : 0;
        }
     }
-    return $info;
+    return $boot_mode_info_cache;
 }
 
 __PACKAGE__->register_method({