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) = @_;