]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
journal: warn if we detect disk write cache is on
authorSage Weil <sage@newdream.net>
Mon, 1 Feb 2010 19:56:01 +0000 (11:56 -0800)
committerSage Weil <sage@newdream.net>
Mon, 1 Feb 2010 21:50:12 +0000 (13:50 -0800)
src/os/FileJournal.cc
src/os/FileJournal.h

index 796db99da45f1588287d5213d4baaad56bd968b7..2beb4fa138c82eed96b41fe3e8993196fc014698 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "config.h"
 #include "FileJournal.h"
+#include "include/color.h"
 
 #include <stdio.h>
 #include <sys/types.h>
@@ -81,7 +82,48 @@ int FileJournal::_open(bool forwrite, bool create)
     max_size = sectors * 512ULL;
 # endif
 #endif
-  }
+    is_bdev = true;
+  }
+
+  // try to check if the disk write cache is on
+  if (is_bdev) {
+    if (geteuid() == 0) {
+      char cmd[4096];
+      snprintf(cmd, sizeof(cmd), "/sbin/hdparm -W %s > /tmp/out.%d", fn.c_str(), getpid());
+      int r = system(cmd);
+      if (r == 0) {
+       snprintf(cmd, sizeof(cmd), "/tmp/out.%d", getpid());
+       FILE *f = fopen(cmd, "r");
+       if (f) {
+         while (!feof(f)) {
+           char s[100];
+           fgets(s, sizeof(s), f);
+           int on;
+           if (sscanf(s, " write-caching =  %d", &on) == 1) {
+             if (on) {
+               dout(0) << "WARNING: disk write cache is ON, journaling will not be reliable" << dendl;
+               dout(0) << "         disable with 'hdparm -W 0 " << fn << "'" << dendl;
+               cout << TEXT_RED
+                    << " ** WARNING: disk write cache is ON on " << fn << ".\n"
+                    << "    Journaling will not be reliable.  Disable write cache with\n"
+                    << "    'hdparm -W 0 " << fn << "'"
+                    << TEXT_NORMAL
+                    << std::endl;
+             } else {
+               dout(10) << "_open disk write cache is off (good) on " << fn << dendl;
+             }
+             break;
+           }
+         }
+         fclose(f);
+       }
+       ::unlink(cmd);
+      } else
+       dout(10) << "_open failed to run '" << cmd << "', NOT checking disk write cache on " << fn << dendl;      
+    } else
+      dout(10) << "_open not root, NOT checking disk write cache on " << fn << dendl;
+  } else
+    dout(10) << "_open journal is not a block device, NOT checking disk write cache on " << fn << dendl;
 
   // static zeroed buffer for alignment padding
   zero_buf = new char[header.alignment];
index 60ba57bfe6b1bd08d3ea607ee67b1a4c268b7f08..aa90153298388e552cba119b792c62a3a734fdaf 100644 (file)
@@ -73,6 +73,7 @@ private:
 
   off64_t max_size;
   size_t block_size;
+  bool is_bdev;
   bool directio;
   bool writing, must_write_header;
   off64_t write_pos;      // byte where the next entry to be written will go
@@ -140,7 +141,7 @@ private:
     Journal(fsid, fin, sync_cond), fn(f),
     zero_buf(NULL),
     max_size(0), block_size(0),
-    directio(dio),
+    is_bdev(false),directio(dio),
     writing(false), must_write_header(false),
     write_pos(0), read_pos(0),
     last_committed_seq(0),