-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 zfs_get_pool_stats {
- my ($scfg) = @_;
-
- my $available = 0;
- my $used = 0;
-
- my $text = zfs_request($scfg, undef, 'get', '-o', 'value', '-Hp',
- 'available,used', $scfg->{pool});
-
- my @lines = split /\n/, $text;
-
- if($lines[0] =~ /^(\d+)$/) {
- $available = $1;
- }
-
- if($lines[1] =~ /^(\d+)$/) {
- $used = $1;
- }
-
- return ($available, $used);
-}
-
-sub zfs_parse_zvol_list {
- my ($text) = @_;
-
- my $list = ();
-
- return $list if !$text;
-
- my @lines = split /\n/, $text;
- foreach my $line (@lines) {
- if ($line =~ /^(.+)\s+([a-zA-Z0-9\.]+|\-)\s+(.+)$/) {
- my $zvol = {};
- my @parts = split /\//, $1;
- my $name = pop @parts;
- my $pool = join('/', @parts);
-
- if ($pool !~ /^rpool$/) {
- next unless $name =~ m!^(\w+)-(\d+)-(\w+)-(\d+)$!;
- $name = $pool . '/' . $name;
- } else {
- next;
- }
-
- $zvol->{pool} = $pool;
- $zvol->{name} = $name;
- $zvol->{size} = zfs_parse_size($2);
- if ($3 !~ /^-$/) {
- $zvol->{origin} = $3;
- }
- push @$list, $zvol;
- }
- }
-
- return $list;
-}
-