From 76dc2ad016f6c195db2e2f5d57f9bfcf8ede5cb1 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 30 Jun 2016 11:46:02 +0200 Subject: [PATCH] fix #1043: prevent ceph destroypool when in use also introduces a force parameter to this call if force is true, the call destroys the ceph pool even when it is use Signed-off-by: Dominik Csapak --- PVE/API2/Ceph.pm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/PVE/API2/Ceph.pm b/PVE/API2/Ceph.pm index 58e5b359..29b57c74 100644 --- a/PVE/API2/Ceph.pm +++ b/PVE/API2/Ceph.pm @@ -1321,6 +1321,12 @@ __PACKAGE__->register_method ({ description => "The name of the pool. It must be unique.", type => 'string', }, + force => { + description => "If true, destroys pool even if in use", + type => 'boolean', + optional => 1, + default => 0, + } }, }, returns => { type => 'null' }, @@ -1329,6 +1335,22 @@ __PACKAGE__->register_method ({ PVE::CephTools::check_ceph_inited(); + # if not forced, destroy ceph pool only when no + # vm disks are on it anymore + if (!$param->{force}) { + my $storagecfg = PVE::Storage::config(); + foreach my $storageid (keys %{$storagecfg->{ids}}) { + my $storage = $storagecfg->{ids}->{$storageid}; + next if $storage->{type} ne 'rbd'; + next if $storage->{pool} ne $param->{name}; + + # check if any vm disks are on the pool + my $res = PVE::Storage::vdisk_list($storagecfg, $storageid); + die "ceph pool '$param->{name}' still in use by storage '$storageid'\n" + if @{$res->{$storageid}} != 0; + } + } + my $rados = PVE::RADOS->new(); # fixme: '--yes-i-really-really-mean-it' $rados->mon_command({