From 89f4a5ab26ccf534a10a0e856f9e41ffc396fb20 Mon Sep 17 00:00:00 2001 From: Alexander Bakker Date: Sat, 24 Dec 2022 18:45:04 +0100 Subject: [PATCH] libvirtd: add parallelShutdown option This adds a new ``parallelShutdown`` option that allows users to control how many guests can be shut down concurrently. Allowing multiple virtual machines to be shut down at the same time reduces the amount of time it takes to reboot the host. Upstream documentation: https://www.libvirt.org/manpages/libvirt-guests.html#files --- nixos/modules/virtualisation/libvirtd.nix | 12 ++++++++++++ pkgs/development/libraries/libvirt/default.nix | 1 + 2 files changed, 13 insertions(+) diff --git a/nixos/modules/virtualisation/libvirtd.nix b/nixos/modules/virtualisation/libvirtd.nix index 3b30bc8c4165..7c95405ed318 100644 --- a/nixos/modules/virtualisation/libvirtd.nix +++ b/nixos/modules/virtualisation/libvirtd.nix @@ -220,6 +220,17 @@ in ''; }; + parallelShutdown = mkOption { + type = types.ints.unsigned; + default = 0; + description = lib.mdDoc '' + Number of guests that will be shutdown concurrently, taking effect when onShutdown + is set to "shutdown". If set to 0, guests will be shutdown one after another. + Number of guests on shutdown at any time will not exceed number set in this + variable. + ''; + }; + allowedBridges = mkOption { type = types.listOf types.str; default = [ "virbr0" ]; @@ -373,6 +384,7 @@ in environment.ON_BOOT = "${cfg.onBoot}"; environment.ON_SHUTDOWN = "${cfg.onShutdown}"; + environment.PARALLEL_SHUTDOWN = "${toString cfg.parallelShutdown}"; }; systemd.sockets.virtlogd = { diff --git a/pkgs/development/libraries/libvirt/default.nix b/pkgs/development/libraries/libvirt/default.nix index 80c4393a96b5..8f4479a763be 100644 --- a/pkgs/development/libraries/libvirt/default.nix +++ b/pkgs/development/libraries/libvirt/default.nix @@ -341,6 +341,7 @@ stdenv.mkDerivation rec { substituteInPlace $out/libexec/libvirt-guests.sh \ --replace 'ON_BOOT="start"' 'ON_BOOT=''${ON_BOOT:-start}' \ --replace 'ON_SHUTDOWN="suspend"' 'ON_SHUTDOWN=''${ON_SHUTDOWN:-suspend}' \ + --replace 'PARALLEL_SHUTDOWN=0' 'PARALLEL_SHUTDOWN=''${PARALLEL_SHUTDOWN:-0}' \ --replace "$out/bin" '${gettext}/bin' \ --replace 'lock/subsys' 'lock' \ --replace 'gettext.sh' 'gettext.sh