]> git.proxmox.com Git - qemu-server.git/commitdiff
fix bug 395: correctly handle unused disk with storage alias
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 27 May 2013 06:25:39 +0000 (08:25 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 27 May 2013 06:25:39 +0000 (08:25 +0200)
PVE/QemuServer.pm

index 4f633e63c7cdebe79f35d21822bb6081342b98e7..64c95f0de615c96bb912f9d83dc0d2d2ba92a39c 100644 (file)
@@ -3605,6 +3605,7 @@ sub scan_volids {
     foreach my $storeid (keys %$info) {
        foreach my $item (@{$info->{$storeid}}) {
            next if !($item->{volid} && $item->{size});
+           $item->{path} = PVE::Storage::path($cfg, $item->{volid});
            $volid_hash->{$item->{volid}} = $item;
        }
     }
@@ -3619,6 +3620,12 @@ sub update_disksize {
 
     my $used = {};
 
+    # Note: it is allowed to define multiple storages with same path (alias), so
+    # we need to check both 'volid' and real 'path' (two different volid can point
+    # to the same path).
+
+    my $usedpath = {};
+    
     # update size info
     foreach my $opt (keys %$conf) {
        if (valid_drivename($opt)) {
@@ -3627,6 +3634,10 @@ sub update_disksize {
            next if !$volid;
 
            $used->{$volid} = 1;
+           if ($volid_hash->{$volid} && 
+               (my $path = $volid_hash->{$volid}->{path})) {
+               $usedpath->{$path} = 1;
+           }
 
            next if drive_is_cdrom($drive);
            next if !$volid_hash->{$volid};
@@ -3637,9 +3648,23 @@ sub update_disksize {
        }
     }
 
+    # remove 'unusedX' entry if volume is used
+    foreach my $opt (keys %$conf) {
+       next if $opt !~ m/^unused\d+$/;
+       my $volid = $conf->{$opt};
+       my $path = $volid_hash->{$volid}->{path} if $volid_hash->{$volid};
+       if ($used->{$volid} || ($path && $usedpath->{$path})) { 
+           $changes = 1;
+           delete $conf->{$opt};
+       }
+    }
+
     foreach my $volid (sort keys %$volid_hash) {
        next if $volid =~ m/vm-$vmid-state-/;
        next if $used->{$volid};
+       my $path = $volid_hash->{$volid}->{path};
+       next if !$path; # just to be sure
+       next if $usedpath->{$path};
        $changes = 1;
        add_unused_volume($conf, $volid);
     }