[pve-devel] [PATCH] RBDPlugin: introduce rbd_unittobytes / rbd tends to be human readable
Stefan Priebe - Profihost AG
s.priebe at profihost.ag
Tue Jan 22 08:45:51 CET 2013
Hi,
sadly not... and there is no flag to force a specific unit. Sadly they
also use M and MB for megabytes...
But it's working fine with this patch. I just was no sure if unittobytes
should be a general function in PVE::Storage::Plugin as the ISCSIDirect
plugin uses something similiar.
Stefan
Am 22.01.2013 06:52, schrieb Alexandre DERUMIER:
> Good catch, I Thinked that values was always Megabytes :/
>
>
> ----- Mail original -----
>
> De: "Stefan Priebe" <s.priebe at profihost.ag>
> À: pve-devel at pve.proxmox.com
> Envoyé: Lundi 21 Janvier 2013 15:23:47
> Objet: [pve-devel] [PATCH] RBDPlugin: introduce rbd_unittobytes / rbd tends to be human readable
>
>
> Signed-off-by: Stefan Priebe <s.priebe at profihost.ag>
> ---
> PVE/Storage/RBDPlugin.pm | 20 +++++++++++++-------
> 1 file changed, 13 insertions(+), 7 deletions(-)
>
> diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
> index 1e27ccb..e77b768 100644
> --- a/PVE/Storage/RBDPlugin.pm
> +++ b/PVE/Storage/RBDPlugin.pm
> @@ -9,6 +9,14 @@ use PVE::JSONSchema qw(get_standard_option);
>
> use base qw(PVE::Storage::Plugin);
>
> +sub rbd_unittobytes {
> + {
> + "M" => 1024*1024,
> + "G" => 1024*1024*1024,
> + "T" => 1024*1024*1024*1024,
> + }
> +}
> +
> my $rbd_cmd = sub {
> my ($scfg, $storeid, $op, @options) = @_;
>
> @@ -51,12 +59,12 @@ sub rbd_ls {
> my $parser = sub {
> my $line = shift;
>
> - if ($line =~ m/^(vm-(\d+)-disk-\d+)\s+(\d+)M\s((\S+)\/(vm-\d+-\S+@\S+))?/) {
> - my ($image, $owner, $size, $parent) = ($1, $2, $3, $6);
> + if ($line =~ m/^(vm-(\d+)-disk-\d+)\s+(\d+)(M|G|T)\s((\S+)\/(vm-\d+-\S+@\S+))?/) {
> + my ($image, $owner, $size, $unit, $parent) = ($1, $2, $3, $4, $7);
>
> $list->{$scfg->{pool}}->{$image} = {
> name => $image,
> - size => $size*1024*1024,
> + size => $size*rbd_unittobytes()->{$unit},
> parent => $parent,
> vmid => $owner
> };
> @@ -83,8 +91,8 @@ sub rbd_volume_info {
> my $parser = sub {
> my $line = shift;
>
> - if ($line =~ m/size (\d+) MB in (\d+) objects/) {
> - $size = $1;
> + if ($line =~ m/size (\d+) (M|G|T)B in (\d+) objects/) {
> + $size = $1 * $unittobytes{$2} if ($1);
> } elsif ($line =~ m/parent:\s(\S+)\/(\S+)/) {
> $parent = $2;
> }
> @@ -92,8 +100,6 @@ sub rbd_volume_info {
>
> run_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => $parser);
>
> - $size = $size*1024*1024 if $size;
> -
> return ($size, $parent);
> }
>
More information about the pve-devel
mailing list