[pve-devel] [PATCH manager 1/3] use special tmp upload dir for disk images

Timo Grodzinski t.grodzinski at profihost.ag
Mon Feb 15 14:29:52 CET 2016


Signed-off-by: Timo Grodzinski <t.grodzinski at profihost.ag>
---
 PVE/HTTPServer.pm                       | 24 +++++++++++++++++++++---
 www/manager/Utils.js                    |  3 +++
 www/manager/form/ContentTypeSelector.js |  2 +-
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/PVE/HTTPServer.pm b/PVE/HTTPServer.pm
index a96518a..1050634 100755
--- a/PVE/HTTPServer.pm
+++ b/PVE/HTTPServer.pm
@@ -21,10 +21,12 @@ use AnyEvent::IO;
 use AnyEvent::HTTP;
 use Fcntl ();
 use Compress::Zlib;
+use PVE::Cluster;
 use PVE::SafeSyslog;
 use PVE::INotify;
 use PVE::RPCEnvironment;
 use PVE::REST;
+use PVE::Storage;
 
 use Net::IP;
 use URI;
@@ -1144,10 +1146,26 @@ sub parse_content_disposition {
 my $tmpfile_seq_no = 0;
 
 sub get_upload_filename {
+    my ( $request ) = @_;
+
     # choose unpredictable tmpfile name
-  
     $tmpfile_seq_no++;
-    return "/var/tmp/pveupload-" . Digest::MD5::md5_hex($tmpfile_seq_no . time() . $$);
+    my $file = "pveupload-" . Digest::MD5::md5_hex($tmpfile_seq_no . time() . $$);
+
+    my $dir = '/var/tmp';
+
+    # other temp. storage dir for disk image uploads from datacenter.cfg (must be writable for www-data)
+    if ( ref $request && $request->method eq 'POST' && $request->uri =~ m|/upload_image$| ) {
+        my $datacenterconf = PVE::Cluster::cfs_read_file( 'datacenter.cfg' );
+        if ( my $storeid = $datacenterconf->{upload_image_temp_storage} ) {
+            my $storageconf = PVE::Cluster::cfs_read_file( "storage.cfg" );
+            my $scfg = PVE::Storage::storage_check_enabled( $storageconf, $storeid );
+            die "cant upload to storage type '$scfg->{type}'\n" if !grep { $scfg->{type} eq $_ } qw( dir nfs );
+            $dir = PVE::Storage::get_temp_dir( $storageconf, $storeid );
+        }
+    }
+
+    return "$dir/$file";
 }
 
 sub unshift_read_header {
@@ -1283,7 +1301,7 @@ sub unshift_read_header {
 
 			print "start upload $path $ct $boundary\n" if $self->{debug};
 
-			my $tmpfilename = get_upload_filename();
+			my $tmpfilename = get_upload_filename( $r );
 			my $outfh = IO::File->new($tmpfilename, O_RDWR|O_CREAT|O_EXCL, 0600) ||
 			    die "unable to create temporary upload file '$tmpfilename'";
 
diff --git a/www/manager/Utils.js b/www/manager/Utils.js
index 09788cf..de4493c 100644
--- a/www/manager/Utils.js
+++ b/www/manager/Utils.js
@@ -740,6 +740,7 @@ Ext.define('PVE.Utils', { statics: {
     vztmplText: gettext('Container template'),
     isoImageText: gettext('ISO image'),
     containersText: gettext('Container'),
+    tempText: gettext('Temp'),
 
     format_expire: function(date) {
 	if (!date) {
@@ -807,6 +808,8 @@ Ext.define('PVE.Utils', { statics: {
 		cta.push(PVE.Utils.isoImageText);
 	    } else if (ct === 'rootdir') {
 		cta.push(PVE.Utils.containersText);
+	    } else if (ct === 'temp') {
+		cta.push(PVE.Utils.tempText);
 	    }
 	});
 
diff --git a/www/manager/form/ContentTypeSelector.js b/www/manager/form/ContentTypeSelector.js
index 0c74524..1e280bf 100644
--- a/www/manager/form/ContentTypeSelector.js
+++ b/www/manager/form/ContentTypeSelector.js
@@ -10,7 +10,7 @@ Ext.define('PVE.form.ContentTypeSelector', {
 	me.data = [];
 
 	if (me.cts === undefined) {
-	    me.cts = ['images', 'iso', 'vztmpl', 'backup', 'rootdir'];
+	    me.cts = ['images', 'iso', 'vztmpl', 'backup', 'rootdir', 'temp'];
 	}
 
 	Ext.Array.each(me.cts, function(ct) {
-- 
2.1.4




More information about the pve-devel mailing list