Signed-off-by: Alexandre Derumier <[email protected]>
---
 PVE/API2/Qemu.pm |   39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 24b57ad..2b06fc8 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -132,23 +132,34 @@ my $create_disks = sub {
 
            my $foundvolid = undef;
 
-           if ($storeid) {
-               PVE::Storage::activate_volumes($storecfg, [ $volid ]);
-               my $dl = PVE::Storage::vdisk_list($storecfg, $storeid, undef);
-
-               PVE::Storage::foreach_volid($dl, sub {
-                   my ($volumeid) = @_;
-                   if($volumeid eq $volid) {
-                       $foundvolid = 1;
-                       return;
-                   }
-               });
+           my $volid_is_new = 1; 
+           if ($conf->{$ds}) { 
+               my $olddrive = PVE::QemuServer::parse_drive($ds, $conf->{$ds}); 
+               $volid_is_new = undef if $olddrive->{file} && $olddrive->{file} 
eq $volid; 
            }
 
-           die "image '$path' does not exists\n" if (!(-f $path || -b $path || 
$foundvolid));
+           if($volid_is_new){
+
+               if ($storeid) {
+
+                   PVE::Storage::activate_volumes($storecfg, [ $volid ]);
+                   my $dl = PVE::Storage::vdisk_list($storecfg, $storeid, 
undef);
+
+                   PVE::Storage::foreach_volid($dl, sub {
+                       my ($volumeid) = @_;
+                       if($volumeid eq $volid) {
+                           $foundvolid = 1;
+                           return;
+                       }
+                   });
+               }
+
+               die "image '$path' does not exists\n" if (!(-f $path || -b 
$path || $foundvolid));
+
+               my ($size) = PVE::Storage::volume_size_info($storecfg, $volid, 
1);
+               $disk->{size} = $size;
+           }
 
-           my ($size) = PVE::Storage::volume_size_info($storecfg, $volid, 1);
-           $disk->{size} = $size;
            $res->{$ds} = PVE::QemuServer::print_drive($vmid, $disk);
        }
     });
-- 
1.7.10.4

_______________________________________________
pve-devel mailing list
[email protected]
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to