cleanup rbd driver
This commit is contained in:
2
Makefile
2
Makefile
@ -2,7 +2,7 @@ RELEASE=2.1
|
|||||||
|
|
||||||
VERSION=2.0
|
VERSION=2.0
|
||||||
PACKAGE=libpve-storage-perl
|
PACKAGE=libpve-storage-perl
|
||||||
PKGREL=22
|
PKGREL=23
|
||||||
|
|
||||||
DESTDIR=
|
DESTDIR=
|
||||||
PREFIX=/usr
|
PREFIX=/usr
|
||||||
|
|||||||
@ -9,48 +9,44 @@ use PVE::JSONSchema qw(get_standard_option);
|
|||||||
|
|
||||||
use base qw(PVE::Storage::Plugin);
|
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};
|
my $monhost = $scfg->{monhost};
|
||||||
$monhost =~ s/;/,/g;
|
$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 $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];
|
||||||
|
|
||||||
|
push @$cmd, @options if scalar(@options);
|
||||||
|
|
||||||
|
return $cmd;
|
||||||
|
};
|
||||||
|
|
||||||
|
sub rbd_ls {
|
||||||
|
my ($scfg, $storeid) = @_;
|
||||||
|
|
||||||
|
my $cmd = &$rbd_cmd($scfg, $storeid, 'ls');
|
||||||
|
|
||||||
my $list = {};
|
my $list = {};
|
||||||
|
|
||||||
my $errfunc = sub {
|
run_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => sub {
|
||||||
my $line = shift;
|
my $line = shift;
|
||||||
die $line if $line;
|
|
||||||
};
|
|
||||||
|
|
||||||
eval {
|
if ($line =~ m/^(vm-(\d+)-\S+)$/) {
|
||||||
run_command($cmd, errmsg => "rbd error", errfunc => $errfunc,outfunc => sub {
|
my ($image, $owner) = ($1, $2);
|
||||||
my $line = shift;
|
|
||||||
|
|
||||||
$line = trim($line);
|
$list->{$scfg->{pool}}->{$image} = {
|
||||||
my ($image) = $line;
|
name => $image,
|
||||||
|
size => 0,
|
||||||
my $owner;
|
vmid => $owner
|
||||||
if ($image =~ m/^(vm-(\d+)-\S+)$/) {
|
};
|
||||||
$owner = $2;
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
$list->{$rbdpool}->{$image} = {
|
|
||||||
name => $image,
|
|
||||||
size => "",
|
|
||||||
vmid => $owner
|
|
||||||
};
|
|
||||||
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
my $err = $@;
|
|
||||||
die $err if $err && $err !~ m/doesn't contain rbd images/ ;
|
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub addslashes {
|
sub addslashes {
|
||||||
@ -74,7 +70,6 @@ sub parse_monhost {
|
|||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub type {
|
sub type {
|
||||||
return 'rbd';
|
return 'rbd';
|
||||||
}
|
}
|
||||||
@ -149,16 +144,13 @@ sub alloc_image {
|
|||||||
|
|
||||||
die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
|
die "illegal name '$name' - sould be 'vm-$vmid-*'\n"
|
||||||
if $name && $name !~ m/^vm-$vmid-/;
|
if $name && $name !~ m/^vm-$vmid-/;
|
||||||
my $rbdpool = $scfg->{pool};
|
|
||||||
my $monhost = $scfg->{monhost};
|
|
||||||
$monhost =~ s/;/,/g;
|
|
||||||
|
|
||||||
if (!$name) {
|
if (!$name) {
|
||||||
my $rdb = rbd_ls($scfg, $storeid);
|
my $rdb = rbd_ls($scfg, $storeid);
|
||||||
|
|
||||||
for (my $i = 1; $i < 100; $i++) {
|
for (my $i = 1; $i < 100; $i++) {
|
||||||
my $tn = "vm-$vmid-disk-$i";
|
my $tn = "vm-$vmid-disk-$i";
|
||||||
if (!defined ($rdb->{$rbdpool}->{$tn})) {
|
if (!defined ($rdb->{$scfg->{pool}}->{$tn})) {
|
||||||
$name = $tn;
|
$name = $tn;
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
@ -168,8 +160,8 @@ sub alloc_image {
|
|||||||
die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
|
die "unable to allocate an image name for VM $vmid in storage '$storeid'\n"
|
||||||
if !$name;
|
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 ];
|
my $cmd = &$rbd_cmd($scfg, $storeid, 'create', '--size', ($size/1024), $name);
|
||||||
run_command($cmd, errmsg => "rbd create $name' error");
|
run_command($cmd, errmsg => "rbd create $name' error", errfunc => sub {});
|
||||||
|
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
@ -177,12 +169,8 @@ sub alloc_image {
|
|||||||
sub free_image {
|
sub free_image {
|
||||||
my ($class, $storeid, $scfg, $volname) = @_;
|
my ($class, $storeid, $scfg, $volname) = @_;
|
||||||
|
|
||||||
my $rbdpool = $scfg->{pool};
|
my $cmd = &$rbd_cmd($scfg, $storeid, 'rm', $volname);
|
||||||
my $monhost = $scfg->{monhost};
|
run_command($cmd, errmsg => "rbd rm $volname' error", outfunc => sub {}, errfunc => sub {});
|
||||||
$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");
|
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -191,17 +179,16 @@ sub list_images {
|
|||||||
my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
|
my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
|
||||||
|
|
||||||
$cache->{rbd} = rbd_ls($scfg, $storeid) if !$cache->{rbd};
|
$cache->{rbd} = rbd_ls($scfg, $storeid) if !$cache->{rbd};
|
||||||
my $rbdpool = $scfg->{pool};
|
|
||||||
my $res = [];
|
my $res = [];
|
||||||
|
|
||||||
if (my $dat = $cache->{rbd}->{$rbdpool}) {
|
if (my $dat = $cache->{rbd}->{$scfg->{pool}}) {
|
||||||
foreach my $image (keys %$dat) {
|
foreach my $image (keys %$dat) {
|
||||||
|
|
||||||
my $volname = $dat->{$image}->{name};
|
my $volname = $dat->{$image}->{name};
|
||||||
|
|
||||||
my $volid = "$storeid:$volname";
|
my $volid = "$storeid:$volname";
|
||||||
|
|
||||||
|
|
||||||
my $owner = $dat->{$volname}->{vmid};
|
my $owner = $dat->{$volname}->{vmid};
|
||||||
if ($vollist) {
|
if ($vollist) {
|
||||||
my $found = grep { $_ eq $volid } @$vollist;
|
my $found = grep { $_ eq $volid } @$vollist;
|
||||||
@ -212,15 +199,15 @@ sub list_images {
|
|||||||
|
|
||||||
my $info = $dat->{$volname};
|
my $info = $dat->{$volname};
|
||||||
$info->{volid} = $volid;
|
$info->{volid} = $volid;
|
||||||
|
$info->{format} = 'raw';
|
||||||
|
|
||||||
push @$res, $info;
|
push @$res, $info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub status {
|
sub status {
|
||||||
my ($class, $storeid, $scfg, $cache) = @_;
|
my ($class, $storeid, $scfg, $cache) = @_;
|
||||||
|
|
||||||
@ -228,9 +215,8 @@ sub status {
|
|||||||
my $free = 0;
|
my $free = 0;
|
||||||
my $used = 0;
|
my $used = 0;
|
||||||
my $active = 1;
|
my $active = 1;
|
||||||
return ($total,$free,$used,$active);
|
|
||||||
|
|
||||||
return undef;
|
return ($total, $free, $used, $active);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub activate_storage {
|
sub activate_storage {
|
||||||
|
|||||||
@ -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
|
libpve-storage-perl (2.0-22) unstable; urgency=low
|
||||||
|
|
||||||
* include iscsidirect and nexenta plugin (experimental)
|
* include iscsidirect and nexenta plugin (experimental)
|
||||||
|
|||||||
Reference in New Issue
Block a user