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

svn-commits at proxmox.com svn-commits at proxmox.com
Mon Mar 14 10:34:30 CET 2011


Author: dietmar
Date: 2011-03-14 10:34:30 +0100 (Mon, 14 Mar 2011)
New Revision: 5693

Modified:
   pve-common/trunk/data/ChangeLog
   pve-common/trunk/data/PVE/Tools.pm
Log:
	* PVE/Tools.pm (upid_encode,upid_decode): moved from
	pve-access-control.



Modified: pve-common/trunk/data/ChangeLog
===================================================================
--- pve-common/trunk/data/ChangeLog	2011-03-14 06:08:58 UTC (rev 5692)
+++ pve-common/trunk/data/ChangeLog	2011-03-14 09:34:30 UTC (rev 5693)
@@ -1,3 +1,8 @@
+2011-03-14  Proxmox Support Team  <support at proxmox.com>
+
+	* PVE/Tools.pm (upid_encode,upid_decode): moved from
+	pve-access-control.
+
 2011-03-09  Proxmox Support Team  <support at proxmox.com>
 
 	* PVE/ProcFSTools.pm (read_proc_net_dev): first impl.

Modified: pve-common/trunk/data/PVE/Tools.pm
===================================================================
--- pve-common/trunk/data/PVE/Tools.pm	2011-03-14 06:08:58 UTC (rev 5692)
+++ pve-common/trunk/data/PVE/Tools.pm	2011-03-14 09:34:30 UTC (rev 5693)
@@ -22,6 +22,12 @@
 extract_param
 );
 
+my $pvelogdir = "/var/log/pve";
+my $pvetaskdir = "$pvelogdir/tasks";
+
+mkdir $pvelogdir;
+mkdir $pvetaskdir;
+
 # flock: we use one file handle per process, so lock file
 # can be called multiple times and succeeds for the same process.
 
@@ -464,4 +470,55 @@
     return $res;
 }
 
+# UPID helper
+# We use this to uniquely identify a process.
+# An 'Unique Process ID' has the following format: 
+# "UPID:$node:$pid:$pstart:$startime:$dtype:$data"
+
+sub upid_encode {
+    my $d = shift;
+
+    return sprintf("UPID:%s:%08X:%08X:%08X:%s:%s", $d->{node}, $d->{pid}, 
+		   $d->{pstart}, $d->{starttime}, $d->{type}, $d->{data});
+}
+
+sub upid_decode {
+    my $upid = shift;
+
+    my $res;
+
+    # "UPID:$node:$pid:$start:$type:$data"
+    if ($upid =~ m/^UPID:(\w+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8}):([^:\s]+):(.*)$/) {
+	$res->{node} = $1;
+	$res->{pid} = hex($2);
+	$res->{pstart} = hex($3);
+	$res->{starttime} = hex($4);
+	$res->{type} = $5;
+	$res->{data} = $6;
+
+	$res->{filename} = "$pvetaskdir/$2-$3";
+
+	if ($res->{type} eq 'vmops') {
+	    if ($res->{data} =~ m/^([^:\s]+):(\d+):(\S+)$/) {
+		$res->{command} = $1;
+		$res->{veid} = $2;
+		$res->{user} = $3;
+	    } else {
+		return undef;
+	    }
+	} elsif ($res->{type} eq 'apldownload') {
+	    if ($res->{data} =~ m/^([^:\s]+):(.+)$/) {
+		$res->{user} = $1;
+		$res->{apl} = $2;
+	    } else {
+		return undef;
+	    }	
+	}
+    } else {
+	die "unable to parse worker upid '$upid'\n";
+    }
+
+    return $res;
+}
+
 1;



More information about the pve-devel mailing list