[pve-devel] r5716 - in pve-common/trunk/data: . PVE

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Mar 17 09:53:27 CET 2011


Author: dietmar
Date: 2011-03-17 09:53:26 +0100 (Thu, 17 Mar 2011)
New Revision: 5716

Modified:
   pve-common/trunk/data/ChangeLog
   pve-common/trunk/data/PVE/INotify.pm
   pve-common/trunk/data/PVE/Tools.pm
Log:
list/update list of
	active/recent worker processes


Modified: pve-common/trunk/data/ChangeLog
===================================================================
--- pve-common/trunk/data/ChangeLog	2011-03-17 06:33:22 UTC (rev 5715)
+++ pve-common/trunk/data/ChangeLog	2011-03-17 08:53:26 UTC (rev 5716)
@@ -1,3 +1,8 @@
+2011-03-17  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/INotify.pm (read/write_active_workers): list/update list of
+	active/recent worker processes
+
 2011-03-16  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/Tools.pm (upid_*): add code to handle worker processes.

Modified: pve-common/trunk/data/PVE/INotify.pm
===================================================================
--- pve-common/trunk/data/PVE/INotify.pm	2011-03-17 06:33:22 UTC (rev 5715)
+++ pve-common/trunk/data/PVE/INotify.pm	2011-03-17 08:53:26 UTC (rev 5716)
@@ -607,4 +607,38 @@
 	      \&read_etc_timezone, 
 	      \&write_etc_timezone);
 
+sub read_active_workers {
+    my ($filename, $fh) = @_;
+
+    return [] if !$fh;
+
+    my $res = []; 
+    while (defined (my $upid = <$fh>)) {
+	chomp $upid;
+	if ((my $task = PVE::Tools::upid_decode ($upid))) {
+	    $task->{upid} = $upid;
+	    push @$res, $task;
+	}
+    }
+
+    return $res;
+
+}
+
+sub write_active_workers {
+    my ($filename, $fh, $tasklist) = @_;
+
+    my $raw = '';
+    foreach my $task (@$tasklist) {
+	my $upid = $task->{upid};
+	$raw .= "$upid\n";
+    }
+
+    PVE::Tools::safe_print($filename, $fh, $raw) if $raw;
+}
+
+register_file('active', "/var/log/pve/tasks/active", 
+	      \&read_active_workers,
+	      \&write_active_workers);
+
 1;

Modified: pve-common/trunk/data/PVE/Tools.pm
===================================================================
--- pve-common/trunk/data/PVE/Tools.pm	2011-03-17 06:33:22 UTC (rev 5715)
+++ pve-common/trunk/data/PVE/Tools.pm	2011-03-17 08:53:26 UTC (rev 5716)
@@ -29,7 +29,6 @@
 
 mkdir $pvelogdir;
 mkdir $pvetaskdir;
-mkdir "$pvetaskdir/active";
 
 # flock: we use one file handle per process, so lock file
 # can be called multiple times and succeeds for the same process.
@@ -489,6 +488,7 @@
     my ($upid, $noerr) = @_;
 
     my $res;
+    my $filename;
 
     # "UPID:$node:$pid:$start:$type:$user:"
     if ($upid =~ m/^UPID:(\w+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]+):$/) {
@@ -500,28 +500,20 @@
 	$res->{user} = $6;
 
 	my $subdir = substr($4, 7, 8);
-	$res->{filename} = "$pvetaskdir/$subdir/$upid";
+	$filename = "$pvetaskdir/$subdir/$upid";
 
     } else {
 	return undef if $noerr;
 	die "unable to parse worker upid '$upid'\n";
     }
 
-    return $res;
+    return wantarray ? ($res, $filename) : $res;
 }
 
-sub upid_set_inactive {
-    my ($upid) = @_;
-
-    my $linkname = "$pvetaskdir/active/$upid";
-    unlink $linkname;
-}
-
 sub upid_open {
     my ($upid, $ownerid) = @_;
 
-    my $task = upid_decode($upid); 
-    my $filename = $task->{filename};
+    my ($task, $filename) = upid_decode($upid); 
 
     my $dirname = dirname($filename);
     make_path($dirname);
@@ -530,15 +522,6 @@
 	die "unable to create output file '$filename' - $!\n";
     chown $ownerid, $outfh;
 
-    my $linkname = "$pvetaskdir/active/$upid";
-    link($filename, $linkname);
-
-    if (! -f $linkname) {
-	close($outfh);
-	unlink $filename;
-	die "unable to create link '$linkname' - $!\n";
-    }
-
     return $outfh;
 };
 




More information about the pve-devel mailing list