From d8970f7e37ba8e9b3d5b6991219563fc994bb6b1 Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Tue, 25 Aug 2015 16:27:58 +0800 Subject: [PATCH] ceph-fuse: warn and shut down when there is no MDS present This patch checks the up MDS servers when mounting. If there's no MDS server up, report in the log then force quit. Fixes: #12204 Signed-off-by: Yuan Zhou --- src/ceph_fuse.cc | 4 +++- src/client/Client.cc | 16 +++++++++++++++- src/client/Client.h | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/ceph_fuse.cc b/src/ceph_fuse.cc index 4dde41772ff7..40bbd0a112df 100644 --- a/src/ceph_fuse.cc +++ b/src/ceph_fuse.cc @@ -206,8 +206,10 @@ int main(int argc, const char **argv, const char *envp[]) { // start up fuse // use my argc, argv (make sure you pass a mount point!) - r = client->mount(g_conf->client_mountpoint.c_str()); + r = client->mount(g_conf->client_mountpoint.c_str(), g_ceph_context->_conf->fuse_require_active_mds); if (r < 0) { + if (r == CEPH_FUSE_NO_MDS_UP) + cerr << "ceph-fuse[" << getpid() << "]: probably no MDS server is up?" << std::endl; cerr << "ceph-fuse[" << getpid() << "]: ceph mount failed with " << cpp_strerror(-r) << std::endl; goto out_shutdown; } diff --git a/src/client/Client.cc b/src/client/Client.cc index 4259c6ecdf60..486e8a565129 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -4834,7 +4834,7 @@ void Client::handle_command_reply(MCommandReply *m) // ------------------- // MOUNT -int Client::mount(const std::string &mount_root) +int Client::mount(const std::string &mount_root, bool require_mds) { Mutex::Locker lock(client_lock); @@ -4851,6 +4851,20 @@ int Client::mount(const std::string &mount_root) tick(); // start tick ldout(cct, 2) << "mounted: have mdsmap " << mdsmap->get_epoch() << dendl; + if (require_mds) { + while (1) { + if (mdsmap->get_epoch() > 0) { + if (mdsmap->get_num_mds(CEPH_MDS_STATE_ACTIVE) == 0) { + ldout(cct, 10) << "no mds up: epoch=" << mdsmap->get_epoch() << dendl; + return CEPH_FUSE_NO_MDS_UP; + } else { + break; + } + } else { + wait_on_list(waiting_for_mdsmap); + } + } + } // hack: get+pin root inode. // fuse assumes it's always there. diff --git a/src/client/Client.h b/src/client/Client.h index d8f2dc1d269b..add195d5f31d 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -765,7 +765,7 @@ private: void _release_filelocks(Fh *fh); void _update_lock_state(struct flock *fl, uint64_t owner, ceph_lock_state_t *lock_state); public: - int mount(const std::string &mount_root); + int mount(const std::string &mount_root, bool require_mds=false); void unmount(); int mds_command( -- 2.47.3