]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/RBDPlugin.pm
rbd : parse_volname : parse base
[pve-storage.git] / PVE / Storage / RBDPlugin.pm
index 1a2e91c6a1047af395d6a0b296e0dd4bd3bd90c4..2eb55bad42a9685e8a5c01d2e13129096bd16afa 100644 (file)
@@ -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 * rbd_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);
 }
 
@@ -166,8 +172,8 @@ sub options {
 sub parse_volname {
     my ($class, $volname) = @_;
 
-    if ($volname =~ m/^(vm-(\d+)-\S+)$/) {
-       return ('images', $1, $2);
+    if ($volname =~ m/^((base-(\d+)-\S+)\/)?((base)?(vm)?-(\d+)-\S+)$/) {
+       return ('images', $4, $7, $2, $3, $5);
     }
 
     die "unable to parse rbd volume name '$volname'\n";
@@ -188,6 +194,18 @@ sub path {
     return ($path, $vmid, $vtype);
 }
 
+sub create_base {
+    my ($class, $storeid, $scfg, $volname) = @_;
+
+    die "not implemented";
+}
+
+sub clone_image {
+    my ($class, $scfg, $storeid, $volname, $vmid) = @_;
+
+    die "not implemented";
+}
+
 sub alloc_image {
     my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
 
@@ -210,14 +228,14 @@ sub alloc_image {
     die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
        if !$name;
 
-    my $cmd = &$rbd_cmd($scfg, $storeid, 'create', '--size', ($size/1024), $name);
+    my $cmd = &$rbd_cmd($scfg, $storeid, 'create', '--format' , 2, '--size', ($size/1024), $name);
     run_command($cmd, errmsg => "rbd create $name' error", errfunc => sub {});
 
     return $name;
 }
 
 sub free_image {
-    my ($class, $storeid, $scfg, $volname) = @_;
+    my ($class, $storeid, $scfg, $volname, $isBase) = @_;
 
     my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'purge',  $volname);
     run_command($cmd, errmsg => "rbd snap purge $volname' error", outfunc => sub {}, errfunc => sub {});