[pve-devel] r5706 - in pve-common/trunk/data: . PVE
svn-commits at proxmox.com
svn-commits at proxmox.com
Wed Mar 16 13:19:42 CET 2011
Author: dietmar
Date: 2011-03-16 13:19:42 +0100 (Wed, 16 Mar 2011)
New Revision: 5706
Modified:
pve-common/trunk/data/ChangeLog
pve-common/trunk/data/PVE/Tools.pm
Log:
add code to handle worker processes.
Modified: pve-common/trunk/data/ChangeLog
===================================================================
--- pve-common/trunk/data/ChangeLog 2011-03-15 07:38:19 UTC (rev 5705)
+++ pve-common/trunk/data/ChangeLog 2011-03-16 12:19:42 UTC (rev 5706)
@@ -1,3 +1,7 @@
+2011-03-16 Proxmox Support Team <support at proxmox.com>
+
+ * PVE/Tools.pm (upid_*): add code to handle worker processes.
+
2011-03-14 Proxmox Support Team <support at proxmox.com>
* PVE/Tools.pm (upid_encode,upid_decode): moved from
Modified: pve-common/trunk/data/PVE/Tools.pm
===================================================================
--- pve-common/trunk/data/PVE/Tools.pm 2011-03-15 07:38:19 UTC (rev 5705)
+++ pve-common/trunk/data/PVE/Tools.pm 2011-03-16 12:19:42 UTC (rev 5706)
@@ -4,6 +4,8 @@
use POSIX;
use IO::Socket::INET;
use IO::Select;
+use File::Basename;
+use File::Path qw(make_path);
use IO::File;
use IPC::Open3;
use Fcntl qw(:DEFAULT :flock);
@@ -27,6 +29,7 @@
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.
@@ -473,52 +476,71 @@
# 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"
+# "UPID:$node:$pid:$pstart:$startime:$dtype:$user"
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});
+ return sprintf("UPID:%s:%08X:%08X:%08X:%s:%s:", $d->{node}, $d->{pid},
+ $d->{pstart}, $d->{starttime}, $d->{type}, $d->{user});
}
sub upid_decode {
- my $upid = shift;
+ my ($upid, $noerr) = @_;
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]+):(.*)$/) {
+ # "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]+):$/) {
$res->{node} = $1;
$res->{pid} = hex($2);
$res->{pstart} = hex($3);
$res->{starttime} = hex($4);
$res->{type} = $5;
- $res->{data} = $6;
+ $res->{user} = $6;
- $res->{filename} = "$pvetaskdir/$2-$3";
+ my $subdir = substr($4, 7, 8);
+ $res->{filename} = "$pvetaskdir/$subdir/$upid";
- 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 {
+ return undef if $noerr;
die "unable to parse worker upid '$upid'\n";
}
return $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 $dirname = dirname($filename);
+ make_path($dirname);
+
+ my $outfh = IO::File->new ($filename, O_WRONLY|O_CREAT|O_EXCL) ||
+ 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;
+};
+
+
1;
More information about the pve-devel
mailing list