[pve-devel] [PATCH storage] add new content type 'temp' to posix compat storages

Timo Grodzinski t.grodzinski at profihost.ag
Mon Feb 15 14:31:28 CET 2016


Temp folder can be used for temporary storage of big file uploads.
Ensures that folder 'temp' is writable by www-data.

Signed-off-by: Timo Grodzinski <t.grodzinski at profihost.ag>
---
 PVE/API2/Storage/Config.pm |  2 +-
 PVE/Storage.pm             | 17 +++++++++++++++--
 PVE/Storage/DirPlugin.pm   |  2 +-
 PVE/Storage/NFSPlugin.pm   |  2 +-
 PVE/Storage/Plugin.pm      | 11 ++++++++++-
 5 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/PVE/API2/Storage/Config.pm b/PVE/API2/Storage/Config.pm
index b9fdc0e..dca673a 100755
--- a/PVE/API2/Storage/Config.pm
+++ b/PVE/API2/Storage/Config.pm
@@ -17,7 +17,7 @@ use PVE::RESTHandler;
 
 use base qw(PVE::RESTHandler);
 
-my @ctypes = qw(images vztmpl iso backup);
+my @ctypes = qw(images vztmpl iso backup temp);
 
 my $storage_type_enum = PVE::Storage::Plugin->lookup_types();
 
diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index 140f8ae..441d7d9 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -274,6 +274,15 @@ sub get_backup_dir {
     return $plugin->get_subdir($scfg, 'backup');
 }
 
+sub get_temp_dir {
+    my ($cfg, $storeid) = @_;
+
+    my $scfg = storage_config($cfg, $storeid);
+    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+
+    return $plugin->get_subdir($scfg, 'temp');
+}
+
 # library implementation
 
 sub parse_vmid {
@@ -355,6 +364,7 @@ sub path_to_volume_id {
 	my $isodir = $plugin->get_subdir($scfg, 'iso');
 	my $tmpldir = $plugin->get_subdir($scfg, 'vztmpl');
 	my $backupdir = $plugin->get_subdir($scfg, 'backup');
+	my $tempdir = $plugin->get_subdir($scfg, 'temp');
 	my $privatedir = $plugin->get_subdir($scfg, 'rootdir');
 
 	if ($path =~ m!^$imagedir/(\d+)/([^/\s]+)$!) {
@@ -381,6 +391,9 @@ sub path_to_volume_id {
 	} elsif ($path =~ m!^$backupdir/([^/]+\.(tar|tar\.gz|tar\.lzo|tgz|vma|vma\.gz|vma\.lzo))$!) {
 	    my $name = $1;
 	    return ('iso', "$sid:backup/$name");
+	} elsif ($path =~ m!^$tempdir/([^/]+\.(raw|raw\.gz|qcow|qcow\.gz|qcow2|qcow2\.gz|cow|cow\.gz|vdi|vdi\.gz|vmdk|vmdk\.gz|vpc|vpc\.gz|cloop|cloop\.gz))$!) {
+	    my $name = $1;
+	    return ('temp', "$sid:temp/$name");
 	}
     }
 
@@ -764,7 +777,7 @@ sub vdisk_list {
 sub volume_list {
     my ($cfg, $storeid, $vmid, $content) = @_;
 
-    my @ctypes = qw(images vztmpl iso backup);
+    my @ctypes = qw(images vztmpl iso backup temp);
 
     my $cts = $content ? [ $content ] : [ @ctypes ];
 
@@ -1233,7 +1246,7 @@ sub complete_storage_enabled {
 sub complete_content_type {
     my ($cmdname, $pname, $cvalue) = @_;
 
-    return [qw(rootdir images vztmpl iso backup)];
+    return [qw(rootdir images vztmpl iso backup temp)];
 }
 
 sub complete_volume {
diff --git a/PVE/Storage/DirPlugin.pm b/PVE/Storage/DirPlugin.pm
index bc3c61f..e4c932d 100644
--- a/PVE/Storage/DirPlugin.pm
+++ b/PVE/Storage/DirPlugin.pm
@@ -16,7 +16,7 @@ sub type {
 
 sub plugindata {
     return {
-	content => [ { images => 1, rootdir => 1, vztmpl => 1, iso => 1, backup => 1, none => 1 },
+	content => [ { images => 1, rootdir => 1, vztmpl => 1, iso => 1, backup => 1, temp => 1, none => 1 },
 		     { images => 1,  rootdir => 1 }],
 	format => [ { raw => 1, qcow2 => 1, vmdk => 1, subvol => 1 } , 'raw' ],
     };
diff --git a/PVE/Storage/NFSPlugin.pm b/PVE/Storage/NFSPlugin.pm
index df00f37..19f9923 100644
--- a/PVE/Storage/NFSPlugin.pm
+++ b/PVE/Storage/NFSPlugin.pm
@@ -51,7 +51,7 @@ sub type {
 
 sub plugindata {
     return {
-	content => [ { images => 1, rootdir => 1, vztmpl => 1, iso => 1, backup => 1},
+	content => [ { images => 1, rootdir => 1, vztmpl => 1, iso => 1, backup => 1, temp => 1},
 		     { images => 1 }],
 	format => [ { raw => 1, qcow2 => 1, vmdk => 1 } , 'raw' ],
     };
diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 6aa71e0..559b08d 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -302,7 +302,7 @@ sub parse_config {
 	    priority => 0, # force first entry
 	    path => '/var/lib/vz',
 	    maxfiles => 0,
-	    content => { images => 1, rootdir => 1, vztmpl => 1, iso => 1},
+	    content => { images => 1, rootdir => 1, vztmpl => 1, iso => 1, temp => 1 },
 	};
     }
 
@@ -384,6 +384,8 @@ sub parse_volname {
 	    return ('backup', $fn, $2);
 	}
 	return ('backup', $fn);
+    } elsif ($volname =~ m!^temp/([^/]+\.(raw|qcow|qcow2|cow|vdi|vmdk|vpc|cloop|gz))$!) {
+        return ('temp', $1);
     }
 
     die "unable to parse directory volume name '$volname'\n";
@@ -395,6 +397,7 @@ my $vtype_subdirs = {
     iso => 'template/iso',
     vztmpl => 'template/cache',
     backup => 'dump',
+    temp => 'temp',
 };
 
 sub get_subdir {
@@ -836,6 +839,12 @@ sub activate_storage {
 		($vtype eq 'backup' && defined($scfg->{content}->{'rootdir'}))) {
 		my $subdir = $class->get_subdir($scfg, $vtype);
 		mkpath $subdir if $subdir ne $path;
+		# ensure temp volume is owned by www-data
+		if ( $vtype eq 'temp' ) {
+		    my $uid = getpwnam( 'www-data' );
+		    my $gid = getgrnam( 'www-data' );
+		    chown $uid, $gid, $subdir;
+		}
 	    }
 	}
     }
-- 
2.1.4




More information about the pve-devel mailing list