]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
journal: detect size of raw block devices properly v0.5
authorSage Weil <sage@newdream.net>
Fri, 14 Nov 2008 00:48:15 +0000 (16:48 -0800)
committerSage Weil <sage@newdream.net>
Fri, 14 Nov 2008 00:48:15 +0000 (16:48 -0800)
src/os/FileJournal.cc

index f9185e00a81adf7b2992387efa66400f49d709e8..dce6a1745314ad5df41fee8119312e3f8e626054 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/mount.h>
 #include <fcntl.h>
 
 
@@ -51,8 +52,28 @@ int FileJournal::_open(bool forwrite)
   assert(r == 0);
   max_size = st.st_size;
   block_size = st.st_blksize;
+
+  if (max_size == 0) {
+    // hmm, is this a raw block device?
+#ifdef BLKGETSIZE64
+    // ioctl block device
+    uint64_t bytes;
+    r = ::ioctl(fd, BLKGETSIZE64, &bytes);
+    assert(r == 0);
+    max_size = bytes;
+#else
+# ifdef BLKGETSIZE
+    // hrm, try the 32 bit ioctl?
+    unsigned long sectors = 0;
+    r = ioctl(fd, BLKGETSIZE, &sectors);
+    assert(r == 0);
+    max_size = sectors * 512ULL;
+# endif
+#endif
+  }
+
   dout(2) << "_open " << fn << " fd " << fd 
-         << ": " << st.st_size << " bytes, block size " << block_size << dendl;
+         << ": " << max_size << " bytes, block size " << block_size << dendl;
 
   return 0;
 }