[PVE-User] Submitting patches

Flavio Stanchina flavio.stanchina at ies.it
Wed Feb 3 16:01:47 CET 2010


Dietmar Maurer wrote:
>> Since there isn't a -dev mailing list, is it OK to post patches here?
> 
> Yes, please use this mailing list.

Here it is. Sorry for the delay but I got tangled in many other things, 
as it often happens.

With this patch, the "Hardware device list for VM xxx" and the "Content 
of Storage xxx" pages will show the used disk space for QCOW2 and raw 
disk images, as reported by "qemu-img info $file". This is IMHO a useful 
piece of information that was missing from the user interface, and very 
easy to add. If someone is wondering why this is useful for raw images, 
note that raw images are created as sparse files, so actual disk usage 
will grow as needed just like QCOW2 images.

Be aware that my knowledge of Perl is limited, to say the least. I just 
copied pieces from the surrounding code, so don't be afraid to tell me I 
made blatant mistakes. ;)

> BTW, it is a good idea to talk about changes/patches before implementing something.

Definitely. This was just a little hacking I did while browsing the PVE 
source code, so I didn't bother checking if something like this is 
already planned (or done).

-- 
Flavio Stanchina
Informatica e Servizi
Trento - Italy

-------------- next part --------------
--- /usr/share/perl5/PVE/Storage.pm.orig	2010-01-18 13:38:58.000000000 +0100
+++ /usr/share/perl5/PVE/Storage.pm	2010-01-22 14:54:27.000000000 +0100
@@ -1890,6 +1890,7 @@
 
     my $format;
     my $size = 0;
+    my $used = '?';
 
     eval {
 	run_command ($cmd, outfunc => sub {
@@ -1899,11 +1900,13 @@
 		$format = $1;
 	    } elsif ($line =~ m/^virtual size:\s\S+\s+\((\d+)\s+bytes\)$/) {
 		$size = int ($1/1024);
+	    } elsif ($line =~ m/^disk size:\s+(\S+)\s*$/) {
+		$used = $1;
 	    }
 	});
     };
 
-    return wantarray ? ($size, $format) : $size;
+    return wantarray ? ($size, $format, $used) : $size;
 }
 
 sub vdisk_list {
@@ -1975,11 +1978,12 @@
 		    next if defined ($vmid) && ($owner ne $vmid);
 		}
 
-		my ($size, $format) = file_size_info ($fn);
+		my ($size, $format, $used) = file_size_info ($fn);
 
 		if ($format && $size) {
 		    push @{$res->{$sid}}, { volname => $volname, format => $format,
-					    size => $size, vmid => $owner };
+					    size => $size, vmid => $owner,
+					    used => $used };
 		}
 
 	    }
--- /usr/share/perl5/PVE/Storage.pm.orig	2010-01-18 13:38:58.000000000 +0100
+++ /usr/share/perl5/PVE/Storage.pm	2010-01-22 14:54:27.000000000 +0100
@@ -1890,6 +1890,7 @@
 
     my $format;
     my $size = 0;
+    my $used = '?';
 
     eval {
 	run_command ($cmd, outfunc => sub {
@@ -1899,11 +1900,13 @@
 		$format = $1;
 	    } elsif ($line =~ m/^virtual size:\s\S+\s+\((\d+)\s+bytes\)$/) {
 		$size = int ($1/1024);
+	    } elsif ($line =~ m/^disk size:\s+(\S+)\s*$/) {
+		$used = $1;
 	    }
 	});
     };
 
-    return wantarray ? ($size, $format) : $size;
+    return wantarray ? ($size, $format, $used) : $size;
 }
 
 sub vdisk_list {
@@ -1975,11 +1978,12 @@
 		    next if defined ($vmid) && ($owner ne $vmid);
 		}
 
-		my ($size, $format) = file_size_info ($fn);
+		my ($size, $format, $used) = file_size_info ($fn);
 
 		if ($format && $size) {
 		    push @{$res->{$sid}}, { volname => $volname, format => $format,
-					    size => $size, vmid => $owner };
+					    size => $size, vmid => $owner,
+					    used => $used };
 		}
 
 	    }
--- /usr/share/pve-manager/root/storage/index.htm.orig	2010-01-22 14:28:17.000000000 +0100
+++ /usr/share/pve-manager/root/storage/index.htm	2010-01-22 14:47:39.000000000 +0100
@@ -428,6 +428,7 @@
        my @header = ('1', '590px', __('Volume ID'),
 		     '1', '50px', 'VMID',
 		     '1', '100px', __('Size (GB)'),
+		     '1', '100px', __('Used'),
 		    );
 
        $table->add_headline (\@header);
@@ -437,7 +438,7 @@
          my ($volid, $sid, $volname, $info) = @_;
 
 	 my $size = sprintf "%.2f", $info->{size} / (1024*1024);
-	 $table->add_row ('', $volid, $info->{vmid}, $size);
+	 $table->add_row ('', $volid, $info->{vmid}, $size, $info->{used});
 	 $found = 1;
        });
 
--- /usr/share/pve-manager/root/qemu/hardware.htm.orig	2010-01-20 10:17:43.000000000 +0100
+++ /usr/share/pve-manager/root/qemu/hardware.htm	2010-01-22 17:28:14.000000000 +0100
@@ -488,6 +488,7 @@
 		    '1', '60px', __("Bus"),
 		    '1', '60px', __('Device'),
 		    '1', '60px', __('Size') . " (GB)",
+		    '1', '60px', __('Used'),
 		    '1', '500px', __("Volume ID")];
 
 
@@ -501,13 +502,15 @@
    next if !$disk || PVE::QemuServer::drive_is_cdrom ($disk);
 
    my $size = '-';
+   my $used = '?';
    if ($vmconf->{diskinfo} && $vmconf->{diskinfo}->{$ds}) {
      $size = sprintf "%.2f", $vmconf->{diskinfo}->{$ds}->{disksize};
+     $used = $vmconf->{diskinfo}->{$ds}->{diskused};
    }
 
    my $devinfo = PVE::QemuServer::disk_devive_info ($ds);
    my $menu =  $ddown->out_symbol ('menudisk', '', "&aa=$ds");
-   $table->add_row ('' ,$menu, uc($devinfo->{bus}), $devinfo->{desc}, $size, $disk->{file});
+   $table->add_row ('' ,$menu, uc($devinfo->{bus}), $devinfo->{desc}, $size, $used, $disk->{file});
    $found = 1;
  }
 


More information about the pve-user mailing list