[pve-devel] [PATCH manager 12/14] ceph: mon destroy: add cfs lock
Dominik Csapak
d.csapak at proxmox.com
Tue Jun 18 15:42:56 CEST 2019
so that multiple users cannot remove a monitor simultaniously
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
best viewed with -w
PVE/API2/Ceph/MON.pm | 33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)
diff --git a/PVE/API2/Ceph/MON.pm b/PVE/API2/Ceph/MON.pm
index 2d116bb0..a8ece0b4 100644
--- a/PVE/API2/Ceph/MON.pm
+++ b/PVE/API2/Ceph/MON.pm
@@ -327,21 +327,32 @@ __PACKAGE__->register_method ({
my $worker = sub {
my $upid = shift;
+ PVE::Cluster::cfs_lock_file('ceph.conf', undef, sub {
+ # reload info and recheck
+ $cfg = cfs_read_file('ceph.conf');
+
+ # reopen with longer timeout
+ $rados = PVE::RADOS->new(timeout => PVE::Ceph::Tools::get_config('long_rados_timeout'));
+ $monhash = PVE::Ceph::Services::get_services_info('mon', $cfg, $rados);
+ $monstat = $rados->mon_command({ prefix => 'mon_status' });
+ $monlist = $monstat->{monmap}->{mons};
- # reopen with longer timeout
- $rados = PVE::RADOS->new(timeout => PVE::Ceph::Tools::get_config('long_rados_timeout'));
+ $assert_mon_can_remove->($monhash, $monlist, $monid);
- $rados->mon_command({ prefix => "mon remove", name => $monid, format => 'plain' });
+ $rados->mon_command({ prefix => "mon remove", name => $monid, format => 'plain' });
- eval { PVE::Ceph::Services::ceph_service_cmd('stop', $monsection); };
- warn $@ if $@;
+ eval { PVE::Ceph::Services::ceph_service_cmd('stop', $monsection); };
+ warn $@ if $@;
- delete $cfg->{$monsection};
- cfs_write_file('ceph.conf', $cfg);
- File::Path::remove_tree($mondir);
- eval { PVE::Ceph::Services::ceph_service_cmd('disable', $monsection) };
- warn $@ if $@;
- PVE::Ceph::Services::broadcast_ceph_services();
+ # delete section
+ delete $cfg->{$monsection};
+
+ cfs_write_file('ceph.conf', $cfg);
+ File::Path::remove_tree($mondir);
+ eval { PVE::Ceph::Services::ceph_service_cmd('disable', $monsection) };
+ warn $@ if $@;
+ PVE::Ceph::Services::broadcast_ceph_services();
+ });
};
return $rpcenv->fork_worker('cephdestroymon', $monsection, $authuser, $worker);
--
2.11.0
More information about the pve-devel
mailing list