]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
journaler: detect unexpected holes in journal objects 6025/head
authorYan, Zheng <zyan@redhat.com>
Tue, 22 Sep 2015 08:29:49 +0000 (16:29 +0800)
committerYan, Zheng <zyan@redhat.com>
Tue, 22 Sep 2015 13:39:28 +0000 (21:39 +0800)
Fixes: #13167
Signed-off-by: Yan, Zheng <zyan@redhat.com>
src/osdc/Journaler.cc
src/osdc/Journaler.h

index f021a7a7d3218645ee05e23fe2ecbfbbfef9c8ca..5b99517ad0692d4cfd696ee682ceffbd009ec1ec 100644 (file)
@@ -803,11 +803,12 @@ void Journaler::_finish_prezero(int r, uint64_t start, uint64_t len)
 class Journaler::C_Read : public Context {
   Journaler *ls;
   uint64_t offset;
+  uint64_t length;
 public:
   bufferlist bl;
-  C_Read(Journaler *l, uint64_t o) : ls(l), offset(o) {}
+  C_Read(Journaler *j, uint64_t o, uint64_t l) : ls(j), offset(o), length(l) {}
   void finish(int r) {
-    ls->_finish_read(r, offset, bl);
+    ls->_finish_read(r, offset, length, bl);
   }
 };
 
@@ -822,23 +823,30 @@ public:
   }  
 };
 
-void Journaler::_finish_read(int r, uint64_t offset, bufferlist& bl)
+void Journaler::_finish_read(int r, uint64_t offset, uint64_t length, bufferlist& bl)
 {
   Mutex::Locker l(lock);
 
   if (r < 0) {
     ldout(cct, 0) << "_finish_read got error " << r << dendl;
     error = r;
+  } else {
+    ldout(cct, 10) << "_finish_read got " << offset << "~" << bl.length() << dendl;
+    if (bl.length() < length) {
+      ldout(cct, 0) << "_finish_read got less than expected (" << length << ")" << dendl;
+      error = -EINVAL;
+    }
+  }
+
+  if (error) {
     if (on_readable) {
       C_OnFinisher *f = on_readable;
       on_readable = 0;
-      f->complete(r);
+      f->complete(error);
     }
     return;
   }
-  assert(r>=0);
 
-  ldout(cct, 10) << "_finish_read got " << offset << "~" << bl.length() << dendl;
   prefetch_buf[offset].swap(bl);
 
   try {
@@ -940,7 +948,7 @@ void Journaler::_issue_read(uint64_t len)
     uint64_t l = e - requested_pos;
     if (l > len)
       l = len;
-    C_Read *c = new C_Read(this, requested_pos);
+    C_Read *c = new C_Read(this, requested_pos, l);
     filer.read(ino, &layout, CEPH_NOSNAP, requested_pos, l, &c->bl, 0, wrap_finisher(c), CEPH_OSD_OP_FLAG_FADVISE_DONTNEED);
     requested_pos += l;
     len -= l;
index 5c3d4741bd98c8b8e03d63024e9c4f0e7a82ee6d..9db19c1b239628a01d2c019967b94e830a37e532 100644 (file)
@@ -321,7 +321,7 @@ private:
   C_OnFinisher    *on_write_error;
   bool             called_write_error;
 
-  void _finish_read(int r, uint64_t offset, bufferlist &bl); // read completion callback
+  void _finish_read(int r, uint64_t offset, uint64_t length, bufferlist &bl); // read completion callback
   void _finish_retry_read(int r);
   void _assimilate_prefetch();
   void _issue_read(uint64_t len);  // read some more