]> git.proxmox.com Git - pve-storage.git/commitdiff
cleanup rbd driver
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 17 Jul 2012 11:26:36 +0000 (13:26 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 17 Jul 2012 11:26:36 +0000 (13:26 +0200)
Makefile
PVE/Storage/RBDPlugin.pm
changelog.Debian

index 4ed1f2f38ff6cb851f0e60cd4fb4f532a156ad92..baf3de57b9ef32d6df672446c141a5af4edcc2a3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ RELEASE=2.1
 
 VERSION=2.0
 PACKAGE=libpve-storage-perl
-PKGREL=22
+PKGREL=23
 
 DESTDIR=
 PREFIX=/usr
index ad56c177ea2c3d9412dea8db95b800f81727d15a..4046dc173a2a131c7271d913d95f4aba9e43a99a 100644 (file)
@@ -9,48 +9,44 @@ use PVE::JSONSchema qw(get_standard_option);
 
 use base qw(PVE::Storage::Plugin);
 
+my $rbd_cmd = sub {
+    my ($scfg, $storeid, $op, @options) = @_;
 
-sub rbd_ls{
- my ($scfg, $storeid) = @_;
-
-    my $rbdpool = $scfg->{pool};
     my $monhost = $scfg->{monhost};
     $monhost =~ s/;/,/g;
 
-    my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{username} ,'--keyring', '/etc/pve/priv/ceph/'.$storeid.'.keyring', '--auth_supported',$scfg->{authsupported}, 'ls' ];
-    my $list = {};
+    my $cmd = ['/usr/bin/rbd', '-p', $scfg->{pool}, '-m', $monhost, '-n', 
+              "client.$scfg->{username}", 
+              '--keyring', "/etc/pve/priv/ceph/${storeid}.keyring", 
+              '--auth_supported', $scfg->{authsupported}, $op];
 
-    my $errfunc = sub {
-        my $line = shift;
-       die $line if $line;     
-    };
+    push @$cmd, @options if scalar(@options);
 
-    eval {   
-       run_command($cmd, errmsg => "rbd error", errfunc => $errfunc,outfunc => sub {
-            my $line = shift;
+    return $cmd;
+};
 
-            $line = trim($line);
-            my ($image) = $line;
+sub rbd_ls {
+    my ($scfg, $storeid) = @_;
 
-           my $owner;
-           if ($image =~ m/^(vm-(\d+)-\S+)$/) {
-               $owner = $2;
-           }
+    my $cmd = &$rbd_cmd($scfg, $storeid, 'ls');
 
-           $list->{$rbdpool}->{$image} = {
-                name => $image,
-                size => "",
-                vmid => $owner
-            };
-       
-       });
-    };
+    my $list = {};
 
-    my $err = $@;
-    die $err if $err && $err !~ m/doesn't contain rbd images/ ;
+    run_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => sub {
+       my $line = shift;
 
-    return $list;
+       if ($line =~ m/^(vm-(\d+)-\S+)$/) {
+           my ($image, $owner) = ($1, $2);
 
+           $list->{$scfg->{pool}}->{$image} = {
+               name => $image,
+               size => 0,
+               vmid => $owner
+           };
+       }
+    });
+  
+    return $list;
 }
 
 sub addslashes {
@@ -74,7 +70,6 @@ sub parse_monhost {
     return $name;
 }
 
-
 sub type {
     return 'rbd';
 }
@@ -149,16 +144,13 @@ sub alloc_image {
 
     die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
        if  $name && $name !~ m/^vm-$vmid-/;
-    my $rbdpool = $scfg->{pool};
-    my $monhost = $scfg->{monhost};
-    $monhost =~ s/;/,/g;
 
     if (!$name) {
        my $rdb = rbd_ls($scfg, $storeid);
 
        for (my $i = 1; $i < 100; $i++) {
            my $tn = "vm-$vmid-disk-$i";
-           if (!defined ($rdb->{$rbdpool}->{$tn})) {
+           if (!defined ($rdb->{$scfg->{pool}}->{$tn})) {
                $name = $tn;
                last;
            }
@@ -168,8 +160,8 @@ sub alloc_image {
     die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
        if !$name;
 
-    my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{username}, '--keyring','/etc/pve/priv/ceph/'.$storeid.'.keyring','--auth_supported', $scfg->{authsupported}, 'create', '--size', ($size/1024), $name  ];
-    run_command($cmd, errmsg => "rbd create $name' error");
+    my $cmd = &$rbd_cmd($scfg, $storeid, 'create', '--size', ($size/1024), $name);
+    run_command($cmd, errmsg => "rbd create $name' error", errfunc => sub {});
 
     return $name;
 }
@@ -177,12 +169,8 @@ sub alloc_image {
 sub free_image {
     my ($class, $storeid, $scfg, $volname) = @_;
 
-    my $rbdpool = $scfg->{pool};
-    my $monhost = $scfg->{monhost};
-    $monhost =~ s/;/,/g;
-
-    my $cmd = ['/usr/bin/rbd', '-p', $rbdpool, '-m', $monhost, '-n', "client.".$scfg->{username}, '--keyring','/etc/pve/priv/ceph/'.$storeid.'.keyring','--auth_supported',$scfg->{authsupported}, 'rm', $volname  ];
-    run_command($cmd, errmsg => "rbd rm $volname' error");
+    my $cmd = &$rbd_cmd($scfg, $storeid, 'rm', $volname);
+    run_command($cmd, errmsg => "rbd rm $volname' error", outfunc => sub {}, errfunc => sub {});
 
     return undef;
 }
@@ -191,17 +179,16 @@ sub list_images {
     my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
 
     $cache->{rbd} = rbd_ls($scfg, $storeid) if !$cache->{rbd};
-    my $rbdpool = $scfg->{pool};
+
     my $res = [];
 
-    if (my $dat = $cache->{rbd}->{$rbdpool}) {
+    if (my $dat = $cache->{rbd}->{$scfg->{pool}}) {
         foreach my $image (keys %$dat) {
 
             my $volname = $dat->{$image}->{name};
 
             my $volid = "$storeid:$volname";
 
-
             my $owner = $dat->{$volname}->{vmid};
             if ($vollist) {
                 my $found = grep { $_ eq $volid } @$vollist;
@@ -212,15 +199,15 @@ sub list_images {
 
             my $info = $dat->{$volname};
             $info->{volid} = $volid;
+           $info->{format} = 'raw';
 
             push @$res, $info;
         }
     }
     
-   return $res;
+    return $res;
 }
 
-
 sub status {
     my ($class, $storeid, $scfg, $cache) = @_;
 
@@ -228,9 +215,8 @@ sub status {
     my $free = 0;
     my $used = 0;
     my $active = 1;
-    return ($total,$free,$used,$active);
 
-    return undef;
+    return ($total, $free, $used, $active);
 }
 
 sub activate_storage {
index 41eea14c395772676a73d3be46ca5af4104ef7e7..b999c16abd478650afa07ec2c8ce5495d3c560b3 100644 (file)
@@ -1,3 +1,9 @@
+libpve-storage-perl (2.0-23) unstable; urgency=low
+
+  * cleanup rbd driver
+
+ -- Proxmox Support Team <support@proxmox.com>  Tue, 17 Jul 2012 13:26:27 +0200
+
 libpve-storage-perl (2.0-22) unstable; urgency=low
 
   * include iscsidirect and nexenta plugin (experimental)