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 <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2018-11-23 18:49:46 +01:00
parent 34c1236c35
commit a62d7bd966
2 changed files with 32 additions and 1 deletions

View File

@ -185,9 +185,22 @@ __PACKAGE__->register_method ({
die "$err\n"; die "$err\n";
} }
print "Successfully create CephFS '$fs_name'\n";
if ($param->{add_storage}) { 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 { eval {
PVE::API2::Storage::Config->create({ PVE::API2::Storage::Config->create({
type => 'cephfs', type => 'cephfs',

View File

@ -364,6 +364,24 @@ sub get_cluster_mds_state {
return $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 { sub create_mds {
my ($id, $rados) = @_; my ($id, $rados) = @_;