]> git.proxmox.com Git - pve-container.git/commitdiff
cleanup mp size parameter (add units, same code as QemuServer)
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 10 Sep 2015 08:03:46 +0000 (10:03 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 10 Sep 2015 08:03:46 +0000 (10:03 +0200)
src/PVE/API2/LXC.pm
src/PVE/LXC.pm
src/PVE/VZDump/ConvertOVZ.pm

index c0cd022e044c662cd55e5bf1f5e4355fab1461b5..e1f57da3db3025590306264a1d1a1dfefebb3280 100644 (file)
@@ -258,7 +258,7 @@ __PACKAGE__->register_method({
                if (!defined($param->{rootfs})) {
                    if ($restore) {
                        my (undef, $disksize) = PVE::LXC::Create::recover_config($archive);
-                       $disksize /= 1024 * 1024; # create_disks expects GB as unit size
+                       $disksize /= 1024 * 1024 * 1024; # create_disks expects GB as unit size
                        die "unable to detect disk size - please specify rootfs (size)\n"
                            if !$disksize;
                        $param->{rootfs} = "$storage:$disksize";
index ebf5d23bda73247c144dbf0462b54e30c4050497..53f77a3a428ce256b21f25ec6b473f4d86a5aa5e 100644 (file)
@@ -755,6 +755,23 @@ my $parse_size = sub {
     return int($size);
 };
 
+my $format_size = sub {
+    my ($size) = @_;
+
+    $size = int($size);
+
+    my $kb = int($size/1024);
+    return $size if $kb*1024 != $size;
+
+    my $mb = int($kb/1024);
+    return "${kb}K" if $mb*1024 != $kb;
+
+    my $gb = int($mb/1024);
+    return "${mb}M" if $gb*1024 != $mb;
+
+    return "${gb}G";
+};
+
 sub parse_ct_mountpoint {
     my ($data) = @_;
 
@@ -796,9 +813,14 @@ sub print_ct_mountpoint {
 
     die "missing volume\n" if !$info->{volume};
 
-    foreach my $o ('size', 'backup') {
+    foreach my $o (qw(backup)) {
        $opts .= ",$o=$info->{$o}" if defined($info->{$o});
     }
+
+    if ($info->{size}) {
+       $opts .= ",size=" . &$format_size($info->{size});
+    }
+
     $opts .= ",mp=$info->{mp}" if !$nomp;
 
     return "$info->{volume}$opts";
@@ -2078,17 +2100,17 @@ sub create_disks {
            return if !$storage;
 
            if ($volid =~ m/^([^:\s]+):(\d+(\.\d+)?)$/) {
-               my ($storeid, $size) = ($1, $2);
+               my ($storeid, $size_gb) = ($1, $2);
 
-               $size = int($size*1024) * 1024;
+               my $size_kb = int(${size_gb}*1024) * 1024;
 
                my $scfg = PVE::Storage::storage_config($storecfg, $storage);
                # fixme: use better naming ct-$vmid-disk-X.raw?
 
                if ($scfg->{type} eq 'dir' || $scfg->{type} eq 'nfs') {
-                   if ($size > 0) {
+                   if ($size_kb > 0) {
                        $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw',
-                                                          undef, $size);
+                                                          undef, $size_kb);
                        format_disk($storecfg, $volid);
                    } else {
                        $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'subvol',
@@ -2097,22 +2119,22 @@ sub create_disks {
                } elsif ($scfg->{type} eq 'zfspool') {
 
                    $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'subvol',
-                                              undef, $size);
+                                                      undef, $size_kb);
                } elsif ($scfg->{type} eq 'drbd') {
 
-                   $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw', undef, $size);
+                   $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw', undef, $size_kb);
                    format_disk($storecfg, $volid);
 
                } elsif ($scfg->{type} eq 'rbd') {
 
                    die "krbd option must be enabled on storage type '$scfg->{type}'\n" if !$scfg->{krbd};
-                   $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw', undef, $size);
+                   $volid = PVE::Storage::vdisk_alloc($storecfg, $storage, $vmid, 'raw', undef, $size_kb);
                    format_disk($storecfg, $volid);
                } else {
                    die "unable to create containers on storage type '$scfg->{type}'\n";
                }
                push @$vollist, $volid;
-                my $new_mountpoint = { volume => $volid, size => $size, mp => $mp };
+                my $new_mountpoint = { volume => $volid, size => $size_kb*1024, mp => $mp };
                $conf->{$ms} = print_ct_mountpoint($new_mountpoint, $ms eq 'rootfs');
            } else {
                # use specified/existing volid
index dedd640dde5752baa482a2898516730091a3c8b9..2e29a483b73ceb7dac1e984dbd4ad6d2be1c0cff 100644 (file)
@@ -300,7 +300,7 @@ sub convert_ovz {
 
    my $ovz_conf = &$parse_ovz_config($raw);
 
-   my $disksize = $ovz_conf->{'diskspace'}->{'bar'} / 1024 / 1024;
+   my $disksize = $ovz_conf->{'diskspace'}->{'bar'} * 1024;
    
    my ($mem, $swap) = ovz_config_extract_mem_swap($ovz_conf, 0);