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

svn-commits at proxmox.com svn-commits at proxmox.com
Fri Mar 18 10:05:26 CET 2011


Author: dietmar
Date: 2011-03-18 10:05:26 +0100 (Fri, 18 Mar 2011)
New Revision: 5724

Modified:
   pve-common/trunk/data/ChangeLog
   pve-common/trunk/data/PVE/INotify.pm
   pve-common/trunk/data/PVE/Tools.pm
Log:
more worker related code


Modified: pve-common/trunk/data/ChangeLog
===================================================================
--- pve-common/trunk/data/ChangeLog	2011-03-18 05:53:52 UTC (rev 5723)
+++ pve-common/trunk/data/ChangeLog	2011-03-18 09:05:26 UTC (rev 5724)
@@ -1,3 +1,8 @@
+2011-03-18  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/Tools.pm (upid_read_status): read/parse last line from
+	worker output file.
+
 2011-03-17  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/INotify.pm (read/write_active_workers): list/update list of

Modified: pve-common/trunk/data/PVE/INotify.pm
===================================================================
--- pve-common/trunk/data/PVE/INotify.pm	2011-03-18 05:53:52 UTC (rev 5723)
+++ pve-common/trunk/data/PVE/INotify.pm	2011-03-18 09:05:26 UTC (rev 5724)
@@ -613,11 +613,21 @@
     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;
+    while (defined (my $line = <$fh>)) {
+	if ($line =~ m/^(\S+)(\s([0-9A-Za-z]{8})\s(\S.*))?$/) {
+	    my $upid = $1;
+	    my $endtime = $3;
+	    my $status = $4;
+	    if ((my $task = PVE::Tools::upid_decode ($upid))) {
+		$task->{upid} = $upid;
+		if ($endtime && $status) {
+		    $task->{endtime} = hex($endtime);
+		    $task->{status} = $status;
+		}
+		push @$res, $task;
+	    }
+	} else {
+	    warn "unable to parse line";
 	}
     }
 
@@ -631,7 +641,11 @@
     my $raw = '';
     foreach my $task (@$tasklist) {
 	my $upid = $task->{upid};
-	$raw .= "$upid\n";
+	if ($task->{endtime} && $task->{status}) {
+	    $raw .= sprintf("$upid %08X $task->{status}\n", $task->{endtime});
+	} else {
+	    $raw .= "$upid\n";
+	}
     }
 
     PVE::Tools::safe_print($filename, $fh, $raw) if $raw;

Modified: pve-common/trunk/data/PVE/Tools.pm
===================================================================
--- pve-common/trunk/data/PVE/Tools.pm	2011-03-18 05:53:52 UTC (rev 5723)
+++ pve-common/trunk/data/PVE/Tools.pm	2011-03-18 09:05:26 UTC (rev 5724)
@@ -525,5 +525,31 @@
     return $outfh;
 };
 
+sub upid_read_status {
+    my ($upid) = @_;
 
+    my ($task, $filename) = upid_decode($upid);
+    my $fh = IO::File->new($filename, "r");
+    return "unable to open file - $!" if !$fh;
+    my $maxlen = 1024;
+    sysseek($fh, -$maxlen, 2);
+    my $readbuf = '';
+    my $br = sysread($fh, $readbuf, $maxlen);
+    close($fh);
+    if ($br) {
+	return "unable to extract last line"
+	    if $readbuf !~ m/\n(.+)$/;
+	my $line = $1;
+	if ($line =~ m/^TASK OK$/) {
+	    return 'OK';
+	} elsif ($line =~ m/^TASK ERROR: (.+)$/) {
+	    return $1;
+	} else {
+	    return "unexpected status";
+	}
+    }
+    return "unable to read tail (got $br bytes)";
+}
+
+
 1;




More information about the pve-devel mailing list