]> git.proxmox.com Git - pve-manager.git/commitdiff
ceph: mon destroy: add cfs lock
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 19 Jun 2019 11:45:52 +0000 (13:45 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 19 Jun 2019 13:26:33 +0000 (15:26 +0200)
so that multiple users cannot remove a monitor simultaniously

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/API2/Ceph/MON.pm

index 928667f4929fd70dc4e7ee808cc7d54d2ec3a086..37762f8663412c9368130f033d5a9e9c37f531a1 100644 (file)
@@ -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);