From: Yan, Zheng Date: Fri, 28 Nov 2014 07:55:16 +0000 (+0800) Subject: mds: disallow write operations when MDS is readonly X-Git-Tag: v0.91~52^2~14^2~13 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4f6474f2b7b8be00db8d3e457e6149bcec56fbbc;p=ceph.git mds: disallow write operations when MDS is readonly Signed-off-by: Yan, Zheng --- diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 067f360182b..d48ec638b0d 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 e0fdd4dc91b..08a3210bc36 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 f8c211a11e4..25400eba644 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);