From a62d7bd966ae6ad64c5dbc77db2e2a1ecb692729 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 23 Nov 2018 18:49:46 +0100 Subject: [PATCH] api: cephfs: wait for MDS to become active A MDS gets only active once a FS is there, and we need an MDS active to be able to add a storage, as the CephFS plugin does an immediate mount check. As an MDS needs some time to get active we had a problematic time window where this mounting could fail. Wait for a MDS to get in active state. Signed-off-by: Thomas Lamprecht --- PVE/API2/Ceph/FS.pm | 15 ++++++++++++++- PVE/CephTools.pm | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/PVE/API2/Ceph/FS.pm b/PVE/API2/Ceph/FS.pm index a76d6a56..f934bbc1 100644 --- a/PVE/API2/Ceph/FS.pm +++ b/PVE/API2/Ceph/FS.pm @@ -185,9 +185,22 @@ __PACKAGE__->register_method ({ die "$err\n"; } + print "Successfully create CephFS '$fs_name'\n"; if ($param->{add_storage}) { - my $err; + print "Adding '$fs_name' to storage configuration...\n"; + + my $waittime = 0; + while (!PVE::CephTools::is_any_mds_active()) { + if ($waittime >= 10) { + die "Need MDS to add storage, but none got active!\n"; + } + + print "Waiting for an MDS to become active\n"; + sleep(1); + $waittime++; + } + eval { PVE::API2::Storage::Config->create({ type => 'cephfs', diff --git a/PVE/CephTools.pm b/PVE/CephTools.pm index 825fc22f..d80e2b65 100644 --- a/PVE/CephTools.pm +++ b/PVE/CephTools.pm @@ -364,6 +364,24 @@ sub get_cluster_mds_state { return $mds_state; } +sub is_any_mds_active { + my ($rados) = @_; + + if (!defined($rados)) { + $rados = PVE::RADOS->new(); + } + + my $mds_dump = $rados->mon_command({ prefix => 'mds stat' }); + my $fs = $mds_dump->{fsmap}->{filesystems}; + + if (!($fs && scalar(@$fs) > 0)) { + return undef; + } + my $active_mds = $fs->[0]->{mdsmap}->{info}; + + return scalar(keys %$active_mds) > 0; +} + sub create_mds { my ($id, $rados) = @_;