]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os: FileJournal::do_write: fix error handling
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 4 Feb 2011 18:02:22 +0000 (10:02 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 4 Feb 2011 18:02:22 +0000 (10:02 -0800)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/include/assert.h
src/os/FileJournal.cc
src/os/FileJournal.h

index 493d50d527341e4ae57315ce6ede494083b56680..ddbfe5bea212a854525a00a1820936a06fe12bde 100644 (file)
@@ -106,7 +106,7 @@ extern void __ceph_assert_warn(const char *assertion, const char *file, int line
  * Currently, it's the same as assert(0), but we may one day make assert a
  * debug-only thing, like it is in many projects.
  */
-#define ceph_abort assert(0)
+#define ceph_abort() assert(0)
 
 #endif
 
index 613ae83c2c3b536c60340e6a8f59c7d096d02126..0c9af1bea9c5551d45b7feb5a6060eb63bdfb814 100644 (file)
@@ -719,7 +719,7 @@ int FileJournal::prepare_single_write(bufferlist& bl, off64_t& queue_pos, uint64
   return 0;
 }
 
-void FileJournal::write_bl(off64_t& pos, bufferlist& bl)
+int FileJournal::write_bl(off64_t& pos, bufferlist& bl)
 {
   // make sure list segments are page aligned
   if (directio && (!bl.is_page_aligned() ||
@@ -733,12 +733,14 @@ void FileJournal::write_bl(off64_t& pos, bufferlist& bl)
   }
 
   ::lseek64(fd, pos, SEEK_SET);
-  int err = bl.write_fd(fd);
-  if (err) {
+  int ret = bl.write_fd(fd);
+  if (ret) {
     derr << "FileJournal::write_bl : write_fd failed: "
-        << cpp_strerror(err) << dendl;
+        << cpp_strerror(ret) << dendl;
+    return ret;
   }
   pos += bl.length();
+  return 0;
 }
 
 void FileJournal::do_write(bufferlist& bl)
@@ -779,7 +781,11 @@ void FileJournal::do_write(bufferlist& bl)
     dout(10) << "do_write wrapping, first bit at " << pos << " len " << first.length()
             << " second bit len " << second.length() << " (orig len " << bl.length() << ")" << dendl;
 
-    write_bl(pos, first);
+    if (write_bl(pos, first)) {
+      derr << "FileJournal::do_write: write_bl(pos=" << pos
+          << ") failed" << dendl;
+      ceph_abort();
+    }
     assert(pos == header.max_size);
     if (hbp.length()) {
       // be sneaky: include the header in the second fragment
@@ -787,13 +793,28 @@ void FileJournal::do_write(bufferlist& bl)
       pos = 0;          // we included the header
     } else
       pos = get_top();  // no header, start after that
-    write_bl(pos, second);
+    if (write_bl(pos, second)) {
+      derr << "FileJournal::do_write: write_bl(pos=" << pos
+          << ") failed" << dendl;
+      ceph_abort();
+    }
   } else {
     // header too?
-    if (hbp.length())
-      ::pwrite(fd, hbp.c_str(), hbp.length(), 0);
+    if (hbp.length()) {
+      if (TEMP_FAILURE_RETRY(::pwrite(fd, hbp.c_str(), hbp.length(), 0))) {
+       int err = errno;
+       derr << "FileJournal::do_write: pwrite(fd=" << fd
+            << ", hbp.length=" << hbp.length() << ") failed :"
+            << cpp_strerror(err) << dendl;
+       ceph_abort();
+      }
+    }
 
-    write_bl(pos, bl);
+    if (write_bl(pos, bl)) {
+      derr << "FileJournal::do_write: write_bl(pos=" << pos
+          << ") failed" << dendl;
+      ceph_abort();
+    }
   }
 
   if (!directio) {
index 6ffa3a30c0df7a67d239acb35fc01bc78a03d6fc..86464754e8d2915c68140bfe06ec6b4b3f863f7e 100644 (file)
@@ -143,7 +143,7 @@ private:
   int prepare_single_write(bufferlist& bl, off64_t& queue_pos, uint64_t& orig_ops, uint64_t& orig_bytes);
   void do_write(bufferlist& bl);
 
-  void write_bl(off64_t& pos, bufferlist& bl);
+  int write_bl(off64_t& pos, bufferlist& bl);
   void wrap_read_bl(off64_t& pos, int64_t len, bufferlist& bl);
 
   class Writer : public Thread {