zfsdir: cleanup zfs_parse_size
This commit is contained in:
@ -10,33 +10,6 @@ use PVE::Storage::Plugin;
|
|||||||
|
|
||||||
use base qw(PVE::Storage::Plugin);
|
use base qw(PVE::Storage::Plugin);
|
||||||
|
|
||||||
sub zfs_parse_size {
|
|
||||||
my ($text) = @_;
|
|
||||||
|
|
||||||
return 0 if !$text;
|
|
||||||
|
|
||||||
if ($text =~ m/^(\d+(\.\d+)?)([TGMK])?$/) {
|
|
||||||
my ($size, $reminder, $unit) = ($1, $2, $3);
|
|
||||||
return $size if !$unit;
|
|
||||||
if ($unit eq 'K') {
|
|
||||||
$size *= 1024;
|
|
||||||
} elsif ($unit eq 'M') {
|
|
||||||
$size *= 1024*1024;
|
|
||||||
} elsif ($unit eq 'G') {
|
|
||||||
$size *= 1024*1024*1024;
|
|
||||||
} elsif ($unit eq 'T') {
|
|
||||||
$size *= 1024*1024*1024*1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($reminder) {
|
|
||||||
$size = ceil($size);
|
|
||||||
}
|
|
||||||
return $size;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub type {
|
sub type {
|
||||||
return 'zfsdir';
|
return 'zfsdir';
|
||||||
}
|
}
|
||||||
@ -58,6 +31,42 @@ sub options {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub zfs_parse_size {
|
||||||
|
my ($text) = @_;
|
||||||
|
|
||||||
|
return 0 if !$text;
|
||||||
|
|
||||||
|
if ($text =~ m/^(\d+(\.\d+)?)([TGMK])?$/) {
|
||||||
|
|
||||||
|
my ($size, $reminder, $unit) = ($1, $2, $3);
|
||||||
|
|
||||||
|
if ($unit) {
|
||||||
|
if ($unit eq 'K') {
|
||||||
|
$size *= 1024;
|
||||||
|
} elsif ($unit eq 'M') {
|
||||||
|
$size *= 1024*1024;
|
||||||
|
} elsif ($unit eq 'G') {
|
||||||
|
$size *= 1024*1024*1024;
|
||||||
|
} elsif ($unit eq 'T') {
|
||||||
|
$size *= 1024*1024*1024*1024;
|
||||||
|
} else {
|
||||||
|
die "got unknown zfs size unit '$unit'\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($reminder) {
|
||||||
|
$size = ceil($size);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $size;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
warn "unable to parse zfs size '$text'\n";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
# fixme: implement me
|
# fixme: implement me
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|||||||
Reference in New Issue
Block a user