[pve-devel] [RFC qemu-server] use enter_systemd_scope instead of systemd-run

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Jun 3 11:10:01 CEST 2016


With systemd-run qemu's --daemonize forks often happen
before systemd finishes setting up the scopes, which means
the limits we apply often don't work.
We now use enter_systemd_scope() to create the scope before
running qemu directly without systemd-run.

Note that vm_start() runs in a forked-worker or qm cli
command, so entering the scope in such a process should not
affect the rest of the pve daemon.
---
 PVE/QemuServer.pm | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index dd9cea7..d2c2f83 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2858,20 +2858,6 @@ sub config_to_command {
     my $cpuunits = defined($conf->{cpuunits}) ?
             $conf->{cpuunits} : $defaults->{cpuunits};
 
-    push @$cmd, '/usr/bin/systemd-run';
-    push @$cmd, '--scope';
-    push @$cmd, '--slice', "qemu";
-    push @$cmd, '--unit', $vmid;
-    push @$cmd, '--description', "'Proxmox VE VM $vmid'";
-    # set KillMode=none, so that systemd don't kill those scopes
-    # at shutdown (pve-manager service should stop the VMs instead)
-    push @$cmd, '-p', "KillMode=none";
-    push @$cmd, '-p', "CPUShares=$cpuunits";
-    if ($conf->{cpulimit}) {
-	my $cpulimit = int($conf->{cpulimit} * 100);
-	push @$cmd, '-p', "CPUQuota=$cpulimit\%";
-    }
-
     push @$cmd, '/usr/bin/kvm';
 
     push @$cmd, '-id', $vmid;
@@ -4499,8 +4485,22 @@ sub vm_start {
 	    eval  { run_command($cmd); };
 	}
 
-	eval  { run_command($cmd, timeout => $statefile ? undef : 30,
-		    umask => 0077); };
+	my $cpuunits = defined($conf->{cpuunits}) ? $conf->{cpuunits}
+	                                          : $defaults->{cpuunits};
+
+	eval  {
+	    my %properties = (
+		Slice => 'qemu.slice',
+		KillMode => 'none',
+		CPUShares => $cpuunits
+	    );
+	    if (my $cpulimit = $conf->{cpulimit}) {
+		$properties{CPUQuota} = int($cpulimit * 100);
+	    }
+	    $properties{timeout} = 10 if $statefile; # setting up the scope shoul be quick
+	    PVE::Tools::enter_systemd_scope($vmid, "Proxmox VE VM $vmid", %properties);
+	    run_command($cmd, timeout => $statefile ? undef : 30, umask => 0077);
+	};
 
 	if (my $err = $@) {
 	    # deactivate volumes if start fails
-- 
2.1.4





More information about the pve-devel mailing list