[pve-devel] r5717 - in pve-access-control/trunk: . PVE
svn-commits at proxmox.com
svn-commits at proxmox.com
Thu Mar 17 09:55:50 CET 2011
Author: dietmar
Date: 2011-03-17 09:55:50 +0100 (Thu, 17 Mar 2011)
New Revision: 5717
Modified:
pve-access-control/trunk/ChangeLog
pve-access-control/trunk/PVE/RPCEnvironment.pm
Log:
update/get worker list
Modified: pve-access-control/trunk/ChangeLog
===================================================================
--- pve-access-control/trunk/ChangeLog 2011-03-17 08:53:26 UTC (rev 5716)
+++ pve-access-control/trunk/ChangeLog 2011-03-17 08:55:50 UTC (rev 5717)
@@ -1,3 +1,7 @@
+2011-03-17 Proxmox Support Team <support at proxmox.com>
+
+ * PVE/RPCEnvironment.pm (active_workers): update/get worker list
+
2011-03-16 Proxmox Support Team <support at proxmox.com>
* PVE/RPCEnvironment.pm (fork_worker): add code to simulate running
Modified: pve-access-control/trunk/PVE/RPCEnvironment.pm
===================================================================
--- pve-access-control/trunk/PVE/RPCEnvironment.pm 2011-03-17 08:53:26 UTC (rev 5716)
+++ pve-access-control/trunk/PVE/RPCEnvironment.pm 2011-03-17 08:55:50 UTC (rev 5717)
@@ -37,7 +37,6 @@
$msg = $ec ? "failed ($ec)" : "interrupted ($ic)";
$pri = 'err';
}
- PVE::Tools::upid_set_inactive($upid);
PVE::Cluster::log_msg($pri, $user, "end task $upid $msg");
};
@@ -290,6 +289,75 @@
return $self->{user};
}
+# read/update list of active workers
+sub active_workers {
+ my ($new_upid) = @_;
+
+ my $lkfn = "/var/log/pve/tasks/.active.lock";
+
+ my $timeout = 10;
+
+ my $code = sub {
+
+ my $tasklist = PVE::INotify::read_file('active');
+
+ if ($new_upid) {
+ my $task = PVE::Tools::upid_decode($new_upid);
+ $task->{upid} = $new_upid;
+ push @$tasklist, $task;
+ }
+
+ my @ta;
+ my $tlist = [];
+ my $thash = {}; # only list task once
+
+ foreach my $task (@$tasklist) {
+ my $upid = $task->{upid};
+ next if $thash->{$upid};
+ $thash->{$upid} = 1;
+
+ if (-d "/proc/$task->{pid}") {
+ my $pstart = PVE::ProcFSTools::read_proc_starttime($task->{pid});
+ if ($pstart && ($pstart == $task->{pstart})) {
+ push @$tlist, $task;
+ } else {
+ delete $task->{pid};
+ push @ta, $task;
+ }
+ } else {
+ delete $task->{pid};
+ push @ta, $task;
+ }
+ delete $task->{pstart};
+ }
+
+ @ta = sort { $b->{starttime} cmp $a->{starttime} } @ta;
+
+ # we try to reduce the amount of data
+ # only list running tasks and task not older than 5 minutes
+ # try to limit to 25 tasks
+ my $ctime = time();
+ my $max = 25 - scalar(@$tlist);
+ for (my $i = 0; $i < $max; $i++) {
+ my $task = $ta[$i];
+ last if !$task;
+ next if ($ctime - $task->{starttime}) > 60*5;
+ push @$tlist, $task;
+ }
+
+ PVE::INotify::write_file('active', $tlist) if $new_upid;
+
+ return $tlist;
+ };
+
+ my $res = PVE::Tools::lock_file($lkfn, $timeout, "active_workers", $code);
+ my $err = $@;
+
+ die $err if $err;
+
+ return $res;
+}
+
# start long running workers
# STDIN is redirected to /dev/null
# STDOUT,STDERR are redirected to the filename returned by upid_decode
@@ -365,7 +433,10 @@
die "unable to redirect STDIN - $!"
if !open(STDIN, "</dev/null");
- $outfh = PVE::Tools::upid_open($upid, $wwwid) if !$sync;
+ if (!$sync) {
+ $outfh = PVE::Tools::upid_open($upid, $wwwid);
+ active_workers($upid);
+ }
# redirect STDOUT
$fd = fileno(STDOUT);
@@ -450,7 +521,10 @@
die "got strange worker upid ('$readbuf' != '$upid') - start worker failed\n";
}
- $outfh = PVE::Tools::upid_open($upid, $wwwid) if $sync;
+ if ($sync) {
+ $outfh = PVE::Tools::upid_open($upid, $wwwid);
+ active_workers($upid);
+ }
};
my $err = $@;
More information about the pve-devel
mailing list