[pve-devel] [PATCH 1/2] add qm disk resize

Alexandre Derumier aderumier at odiso.com
Mon Aug 6 11:56:33 CEST 2012


this add disk resizing if new size is bigger than old size.

if new size is lower than old size, we die (can't shrink).

if new size equal old size, we don't resize.

(shrinking should work in theory, but too dangerous)

qm set vmid -virtio0 storage:volume,size=XXG

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/API2/Qemu.pm |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 47c588f..b014e36 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -701,6 +701,14 @@ my $vmconfig_update_disk = sub {
                &$safe_int_ne($drive->{iops_wr}, $old_drive->{iops_wr})) {
                PVE::QemuServer::qemu_block_set_io_throttle($vmid,"drive-$opt",$drive->{bps}, $drive->{bps_rd}, $drive->{bps_wr}, $drive->{iops}, $drive->{iops_rd}, $drive->{iops_wr}) if !PVE::QemuServer::drive_is_cdrom($drive);
             }
+	    
+	    if ($old_drive->{size} && $drive->{size} && $drive->{size} > $old_drive->{size}) {
+               PVE::QemuServer::qemu_block_resize($vmid, "drive-$opt", $storecfg, $drive->{file}, $drive->{size});
+	    }
+	    elsif ($old_drive->{size} && $drive->{size} && $drive->{size} < $old_drive->{size}) {
+	       die "can't shrink drive size";
+	    }
+
 	}
     }
 
-- 
1.7.2.5



More information about the pve-devel mailing list