]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: disallow write operations when MDS is readonly
authorYan, Zheng <zyan@redhat.com>
Fri, 28 Nov 2014 07:55:16 +0000 (15:55 +0800)
committerYan, Zheng <zyan@redhat.com>
Tue, 2 Dec 2014 02:47:23 +0000 (10:47 +0800)
Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/mds/MDCache.cc
src/mds/MDCache.h
src/mds/Server.cc

index 067f360182bcc4c4aa3d9327ad095a8a0d2553f7..d48ec638b0dd269eb9b5fb8b7dd42a7731a98151 100644 (file)
@@ -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) {
index e0fdd4dc91bbc87f51ff1b1bd8d279a0b8d90c34..08a3210bc366204d55bf8cd4a3c4f992a5f1f207 100644 (file)
@@ -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;
 
index f8c211a11e47ed8b58abd4bcbb82105fb2597c2e..25400eba6443d921760933b6818477d35087b6fe 100644 (file)
@@ -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<SimpleLock*> rdlocks, wrlocks, xlocks;
   CInode *cur = rdlock_path_pin_ref(mdr, 0, rdlocks, need_auth);