5
0
mirror of git://git.proxmox.com/git/pve-storage.git synced 2025-01-11 05:18:01 +03:00

refactor disk/storage checks for Disk API

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2018-09-25 10:38:00 +02:00 committed by Thomas Lamprecht
parent 94836d7b8c
commit 76c1e57be7
6 changed files with 27 additions and 21 deletions

View File

@ -201,13 +201,8 @@ __PACKAGE__->register_method ({
my $type = $param->{filesystem} // 'ext4';
$dev = PVE::Diskmanage::verify_blockdev_path($dev);
die "device $dev is already in use\n" if PVE::Diskmanage::disk_is_used($dev);
my $cfg = PVE::Storage::config();
if (my $scfg = PVE::Storage::storage_config($cfg, $name, 1)) {
die "storage ID '$name' already defined\n";
}
PVE::Diskmanage::check_unused($dev);
PVE::Storage::check_available($name);
my $worker = sub {
my $path = "/mnt/pve/$name";

View File

@ -149,7 +149,7 @@ __PACKAGE__->register_method ({
my $node = $param->{node};
$dev = PVE::Diskmanage::verify_blockdev_path($dev);
die "device $dev is already in use\n" if PVE::Diskmanage::disk_is_used($dev);
PVE::Diskmanage::check_unused($dev);
my $worker = sub {
PVE::Diskmanage::locked_disk_action(sub {

View File

@ -103,13 +103,8 @@ __PACKAGE__->register_method ({
my $node = $param->{node};
$dev = PVE::Diskmanage::verify_blockdev_path($dev);
die "device $dev is already in use\n" if PVE::Diskmanage::disk_is_used($dev);
my $cfg = PVE::Storage::config();
if (my $scfg = PVE::Storage::storage_config($cfg, $name, 1)) {
die "storage ID '$name' already defined\n";
}
PVE::Diskmanage::check_unused($dev);
PVE::Storage::check_available($name);
my $worker = sub {
PVE::Diskmanage::locked_disk_action(sub {

View File

@ -341,14 +341,10 @@ __PACKAGE__->register_method ({
foreach my $dev (@$devs) {
$dev = PVE::Diskmanage::verify_blockdev_path($dev);
die "device $dev is already in use\n" if PVE::Diskmanage::disk_is_used($dev);
PVE::Diskmanage::check_unused($dev);
}
my $cfg = PVE::Storage::config();
if (my $scfg = PVE::Storage::storage_config($cfg, $name, 1)) {
die "storage ID '$name' already defined\n";
}
PVE::Storage::check_available($name);
my $numdisks = scalar(@$devs);
my $mindisks = {

View File

@ -602,4 +602,12 @@ sub locked_disk_action {
return $res;
}
sub check_unused {
my ($dev) = @_;
die "device $dev is already in use\n" if disk_is_used($dev);
return undef;
}
1;

View File

@ -1647,4 +1647,16 @@ sub get_bandwidth_limit {
return $override;
}
# checks if the storage id is available and dies if not
sub check_available {
my ($id) = @_;
my $cfg = config();
if (my $scfg = storage_config($cfg, $id, 1)) {
die "storage ID '$id' already defined\n";
}
return undef;
}
1;