summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2008-11-13 16:48:15 -0800
committerSage Weil <sage@newdream.net>2008-11-13 16:48:15 -0800
commit1dd420957f9ba0e3991512a4627748bf38592d53 (patch)
treeff7ca04c3bc126b92207e5ab108d1fcf2513b575
parent200c5699bb3b79fe9f237237206ded415c5d31b9 (diff)
downloadceph-0.5.tar.gz
journal: detect size of raw block devices properlyv0.5
-rw-r--r--src/os/FileJournal.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc
index f9185e00a81..dce6a174531 100644
--- a/src/os/FileJournal.cc
+++ b/src/os/FileJournal.cc
@@ -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;
}