]> git.proxmox.com Git - qemu-server.git/commitdiff
create_disks : avoid storage scan v3
authorAlexandre Derumier <aderumier@odiso.com>
Mon, 10 Jun 2013 07:27:04 +0000 (09:27 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 11 Jun 2013 05:09:17 +0000 (07:09 +0200)
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/API2/Qemu.pm

index b99045e7066f6bdc7521906c56f85ab4ed530c3f..5b88ee77d906f294eb0811e9331b8e8c9c50e889 100644 (file)
@@ -130,25 +130,28 @@ my $create_disks = sub {
 
            my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
 
-           my $foundvolid = undef;
+           my $foundvolid = 1;
+           my $volid_is_new = 1; 
 
-           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;
-                   }
-               });
+           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){
+
+               PVE::Storage::activate_volumes($storecfg, [ $volid ]) if $storeid;
+               my $size = undef;
+               eval {
+                   $size = PVE::Storage::volume_size_info($storecfg, $volid);
+                   die if !$size;
+                   $disk->{size} = $size;
+               };
+               $foundvolid = undef if $@;
+
+               die "volume $volid does not exists\n" if (!(-f $path || -b $path || $foundvolid));
+           }
 
-           my ($size) = PVE::Storage::volume_size_info($storecfg, $volid, 1);
-           $disk->{size} = $size;
            $res->{$ds} = PVE::QemuServer::print_drive($vmid, $disk);
        }
     });