From 4f6474f2b7b8be00db8d3e457e6149bcec56fbbc Mon Sep 17 00:00:00 2001 From: "Yan, Zheng" Date: Fri, 28 Nov 2014 15:55:16 +0800 Subject: [PATCH] mds: disallow write operations when MDS is readonly Signed-off-by: Yan, Zheng --- src/mds/MDCache.cc | 1 + src/mds/MDCache.h | 5 +++++ src/mds/Server.cc | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 067f360182bcc..d48ec638b0dd2 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -172,6 +172,7 @@ MDCache::MDCache(MDS *m) : migrator = new Migrator(mds, this); root = NULL; myin = NULL; + readonly = false; stray_index = 0; for (int i = 0; i < NUM_STRAY; ++i) { diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index e0fdd4dc91bbc..08a3210bc3662 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -90,6 +90,9 @@ class MDCache { CInode *root; // root inode CInode *myin; // .ceph/mds%d dir + bool readonly; + void set_readonly() { readonly = true; } + CInode *strays[NUM_STRAY]; // my stray dir int stray_index; @@ -103,6 +106,8 @@ public: void advance_stray() { stray_index = (stray_index+1)%NUM_STRAY; } + bool is_readonly() { return readonly; } + DecayRate decayrate; diff --git a/src/mds/Server.cc b/src/mds/Server.cc index f8c211a11e47e..25400eba6443d 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -1289,6 +1289,14 @@ void Server::dispatch_client_request(MDRequestRef& mdr) // we shouldn't be waiting on anyone. assert(mdr->more()->waiting_on_slave.empty()); + + if (req->get_op() & CEPH_MDS_OP_WRITE) { + if (mdcache->is_readonly()) { + dout(10) << " read-only FS" << dendl; + respond_to_request(mdr, -EROFS); + return; + } + } switch (req->get_op()) { case CEPH_MDS_OP_LOOKUPHASH: @@ -2576,6 +2584,11 @@ void Server::handle_client_open(MDRequestRef& mdr) respond_to_request(mdr, -EINVAL); return; } + + if ((cmode & CEPH_FILE_MODE_WR) && mdcache->is_readonly()) { + dout(7) << "read-only FS" << dendl; + respond_to_request(mdr, -EROFS); + } set rdlocks, wrlocks, xlocks; CInode *cur = rdlock_path_pin_ref(mdr, 0, rdlocks, need_auth); -- 2.39.5