[pve-devel] [PATCH manager v2 5/7] ceph: mon destroy: add cfs lock

Dominik Csapak d.csapak at proxmox.com
Wed Jun 19 13:45:52 CEST 2019


so that multiple users cannot remove a monitor simultaniously

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 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 928667f4..37762f86 100644
--- a/PVE/API2/Ceph/MON.pm
+++ b/PVE/API2/Ceph/MON.pm
@@ -328,21 +328,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, $mondir);
 
-	    $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