Run df on /proc/$pid/root instead of attaching to the
container and running its contained 'df' binary, as this
could create freezed processes of the container is frozen.
Also, since the container PIDs are now used in both loops
they're precached beforehand.
Fixes #793
---
src/PVE/LXC.pm | 36 ++++++++++--------------------------
1 file changed, 10 insertions(+), 26 deletions(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index e3160e4..8588779 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -737,31 +737,9 @@ sub check_running {
}
sub get_container_disk_usage {
- my ($vmid) = @_;
-
- my $cmd = ['lxc-attach', '-n', $vmid, '--', 'df', '-P', '-B', '1', '/'];
-
- my $res = {
- total => 0,
- used => 0,
- avail => 0,
- };
-
- my $parser = sub {
- my $line = shift;
- if (my ($fsid, $total, $used, $avail) = $line =~
- m/^(\S+.*)\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%\s.*$/) {
- $res = {
- total => $total,
- used => $used,
- avail => $avail,
- };
- }
- };
- eval { PVE::Tools::run_command($cmd, timeout => 1, outfunc => $parser); };
- warn $@ if $@;
+ my ($vmid, $pid, $timeout) = @_;
- return $res;
+ return PVE::Tools::df("/proc/$pid/root/", $timeout // 3);
}
my $last_proc_vmid_stat;
@@ -796,6 +774,12 @@ sub vmstatus {
my $uptime = (PVE::ProcFSTools::read_proc_uptime(1))[0];
+ # Cache the pids
+ my $pids = { map {
+ my $vmid = $_;
+ $vmid => ($active_hash->{$vmid} ? find_lxc_pid($vmid) : undef)
+ } keys %$list };
+
foreach my $vmid (keys %$list) {
my $d = $list->{$vmid};
@@ -812,7 +796,7 @@ sub vmstatus {
$d->{cpus} = $conf->{cpulimit} // 0;
if ($running) {
- my $res = get_container_disk_usage($vmid);
+ my $res = get_container_disk_usage($vmid, $pids->{$vmid});
$d->{disk} = $res->{used};
$d->{maxdisk} = $res->{total};
} else {
@@ -847,7 +831,7 @@ sub vmstatus {
my $d = $list->{$vmid};
next if $d->{status} ne 'running';
- my $pid = find_lxc_pid($vmid);
+ my $pid = $pids->{$vmid};
my $ctime = (stat("/proc/$pid"))[10]; # 10 = ctime
$d->{uptime} = time - $ctime; # the method lxcfs uses
--
2.1.4
_______________________________________________
pve-devel mailing list
[email protected]
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel