[pve-devel] [PATCH common] active tasks: add alternative meaning for endtime

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Jul 28 15:32:08 CEST 2016


add a new hash element for tasks called "stoptime", which
reuses the endtime column in the active task file.
differentiate between endtime and stoptime by prepending the
encoded stoptime with the letter 'S'. endtime has precedence
over stoptime (when a worker is finished, we don't care
about the stoptime anymore).
---
Note: this is not very elegant, and should probably be replaced with
a more future-proof format for PVE 5.0. better ideas more than welcome.

this patch is a requirement for a patch series for pve-access-control

 src/PVE/INotify.pm | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 7fb3490..884223c 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -619,15 +619,22 @@ sub read_active_workers {
 
     my $res = []; 
     while (defined (my $line = <$fh>)) {
-	if ($line =~ m/^(\S+)\s(0|1)(\s([0-9A-Za-z]{8})(\s(\s*\S.*))?)?$/) {
+	if ($line =~ m/^(\S+)\s(0|1)(\s(S)?([0-9A-Za-z]{8})(\s(\s*\S.*))?)?$/) {
 	    my $upid = $1;
 	    my $saved = $2;
-	    my $endtime = $4;
-	    my $status = $6;
+	    my $hextime = $5;
+	    my $status = $7;
 	    if ((my $task = PVE::Tools::upid_decode($upid, 1))) {
 		$task->{upid} = $upid;
 		$task->{saved} = $saved;
-		$task->{endtime} = hex($endtime) if $endtime;
+		if ($hextime) {
+		    my $time = hex($hextime);
+		    if ($4) {
+			$task->{stoptime} = $time;
+		    } else {
+			$task->{endtime} = $time;
+		    }
+		}
 		$task->{status} = $status if $status;
 		push @$res, $task;
 	    }
@@ -653,6 +660,8 @@ sub write_active_workers {
 	    } else {
 		$raw .= sprintf("%s %s %08X\n", $upid, $saved, $task->{endtime});
 	    }
+	} elsif ($task->{stoptime}) {
+		$raw .= sprintf("%s %s S%08X\n", $upid, $saved, $task->{stoptime});
 	} else {
 	    $raw .= "$upid $saved\n";
 	}
-- 
2.1.4





More information about the pve-devel mailing list