[pve-devel] [PATCH] added renderer for hd strings in hardware overview

Dietmar Maurer dietmar at proxmox.com
Wed Aug 29 13:46:35 CEST 2012


I just tried to add that to QemuServer.js, but it is really a mess.

What if we change 'bps' to 'mbps'. The following seems to work:

The new parser automatically converts old bps to mbps.
---
 PVE/API2/Qemu.pm  |   11 +++++++----
 PVE/QemuServer.pm |   25 ++++++++++++++++---------
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 71585a5..9ba1f4d 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -694,13 +694,16 @@ my $vmconfig_update_disk = sub {
 		$conf = PVE::QemuServer::load_config($vmid); # update/reload
 	    }
 
-            if(&$safe_int_ne($drive->{bps}, $old_drive->{bps}) ||
-               &$safe_int_ne($drive->{bps_rd}, $old_drive->{bps_rd}) ||
-               &$safe_int_ne($drive->{bps_wr}, $old_drive->{bps_wr}) ||
+            if(&$safe_int_ne($drive->{mbps}, $old_drive->{mbps}) ||
+               &$safe_int_ne($drive->{mbps_rd}, $old_drive->{mbps_rd}) ||
+               &$safe_int_ne($drive->{mbps_wr}, $old_drive->{mbps_wr}) ||
                &$safe_int_ne($drive->{iops}, $old_drive->{iops}) ||
                &$safe_int_ne($drive->{iops_rd}, $old_drive->{iops_rd}) ||
                &$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);
+               PVE::QemuServer::qemu_block_set_io_throttle($vmid,"drive-$opt", $drive->{mbps}*1024*1024, 
+							   $drive->{mbps_rd}*1024*1024, $drive->{mbps_wr}*1024*1024, 
+							   $drive->{iops}, $drive->{iops_rd}, $drive->{iops_wr}) 
+		   if !PVE::QemuServer::drive_is_cdrom($drive);
             }
 	}
     }
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index a52c249..0f8fa87 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -777,7 +777,7 @@ sub create_conf_nolock {
 my $parse_size = sub {
     my ($value) = @_;
 
-    return undef if $value !~ m/^([1-9]\d*(\.\d+)?)([KMG])?$/;
+    return undef if $value !~ m/^(\d+(\.\d+)?)([KMG])?$/;
     my ($size, $unit) = ($1, $3);
     if ($unit) {
 	if ($unit eq 'K') {
@@ -832,13 +832,18 @@ sub parse_drive {
     foreach my $p (split (/,/, $data)) {
 	next if $p =~ m/^\s*$/;
 
-	if ($p =~ m/^(file|volume|cyls|heads|secs|trans|media|snapshot|cache|format|rerror|werror|backup|aio|bps|bps_rd|bps_wr|iops|iops_rd|iops_wr|size)=(.+)$/) {
+	if ($p =~ m/^(file|volume|cyls|heads|secs|trans|media|snapshot|cache|format|rerror|werror|backup|aio|bps|mbps|bps_rd|mbps_rd|bps_wr|mbps_wr|iops|iops_rd|iops_wr|size)=(.+)$/) {
 	    my ($k, $v) = ($1, $2);
 
 	    $k = 'file' if $k eq 'volume';
 
 	    return undef if defined $res->{$k};
 
+	    if ($k eq 'bps' || $k eq 'bps_rd' || $k eq 'bps_wr') {
+		return undef if !$v || $v !~ m/^\d+/;
+		$k = "m$k";
+		$v = sprintf("%.3f", $v / (1024*1024));
+	    }
 	    $res->{$k} = $v;
 	} else {
 	    if (!$res->{file} && $p !~ m/=/) {
@@ -865,14 +870,16 @@ sub parse_drive {
     return undef if $res->{backup} && $res->{backup} !~ m/^(yes|no)$/;
     return undef if $res->{aio} && $res->{aio} !~ m/^(native|threads)$/;
 
-    return undef if $res->{bps_rd} && $res->{bps};
-    return undef if $res->{bps_wr} && $res->{bps};
+    
+    return undef if $res->{mbps_rd} && $res->{mbps};
+    return undef if $res->{mbps_wr} && $res->{mbps};
+
+    return undef if $res->{mbps} && $res->{mbps} !~ m/^\d+(\.\d+)?$/;
+    return undef if $res->{mbps_rd} && $res->{mbps_rd} !~ m/^\d+(\.\d+)?$/;
+    return undef if $res->{mbps_wr} && $res->{mbps_wr} !~ m/^\d+(\.\d+)?$/;
+
     return undef if $res->{iops_rd} && $res->{iops};
     return undef if $res->{iops_wr} && $res->{iops};
-
-    return undef if $res->{bps} && $res->{bps} !~ m/^\d+$/;
-    return undef if $res->{bps_rd} && $res->{bps_rd} !~ m/^\d+$/;
-    return undef if $res->{bps_wr} && $res->{bps_wr} !~ m/^\d+$/;
     return undef if $res->{iops} && $res->{iops} !~ m/^\d+$/;
     return undef if $res->{iops_rd} && $res->{iops_rd} !~ m/^\d+$/;
     return undef if $res->{iops_wr} && $res->{iops_wr} !~ m/^\d+$/;
@@ -896,7 +903,7 @@ sub parse_drive {
     return $res;
 }
 
-my @qemu_drive_options = qw(heads secs cyls trans media format cache snapshot rerror werror aio bps bps_rd bps_wr iops iops_rd iops_wr);
+my @qemu_drive_options = qw(heads secs cyls trans media format cache snapshot rerror werror aio mbps mbps_rd mbps_wr iops iops_rd iops_wr);
 
 sub print_drive {
     my ($vmid, $drive) = @_;
-- 
1.7.2.5




More information about the pve-devel mailing list