]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
fixed antoher stupid get_num_blocks bug
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Wed, 25 Jul 2007 02:55:58 +0000 (02:55 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Wed, 25 Jul 2007 02:55:58 +0000 (02:55 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1547 29311d96-e01e-0410-9327-a35deaab8ce9

trunk/ceph/ebofs/BlockDevice.cc

index 2efb4246c92e223d2f6bed07d5c856c040a871ec..8fcb6bf549a8eb77675b06199e20ab88353c35ee 100644 (file)
@@ -273,32 +273,32 @@ block_t BlockDevice::get_num_blocks()
     // ioctl block device
     uint64_t bytes = 0;
     r = ioctl(fd, BLKGETSIZE64, &bytes);
-    num_blocks = bytes / 4096;
+    num_blocks = bytes / (uint64_t)EBOFS_BLOCK_SIZE;
     if (r == 0) {
       dout(1) << "get_num_blocks ioctl BLKGETSIZE64 reports "
-             << bytes << " bytes, " 
-             << num_blocks << " 4k blocks" 
+             << num_blocks << " 4k blocks, " 
+             << bytes << " bytes" 
              << endl;
 #else
     // hrm, try the 32 bit ioctl?
     unsigned long sectors = 0;
     r = ioctl(fd, BLKGETSIZE, &sectors);
-    num_blocks = sectors/8;
+    num_blocks = sectors/8ULL;
+    bytes = sectors*512ULL;
     if (r == 0) {
       dout(1) << "get_num_blocks ioctl BLKGETSIZE reports " << sectors << " sectors, "
-             << num_blocks << " 4k blocks, " << (num_blocks*4096) << " bytes" << endl;
+             << num_blocks << " 4k blocks, " << bytes << " bytes" << endl;
 #endif
     } else {
       // hmm, try stat!
       dout(10) << "get_num_blocks ioctl(2) failed with " << errno << " " << strerror(errno) << ", using stat(2)" << endl;
       struct stat st;
       fstat(fd, &st);
-      num_blocks = st.st_size;
-      dout(1) << "get_num_blocks stat reports " << num_blocks << " 4k blocks, " << (num_blocks*4096) << " bytes" << endl;
+      uint64_t bytes = st.st_size;
+      num_blocks = bytes / EBOFS_BLOCK_SIZE;
+      dout(1) << "get_num_blocks stat reports " << num_blocks << " 4k blocks, " << bytes << " bytes" << endl;
     }
     
-    num_blocks /= (uint64_t)EBOFS_BLOCK_SIZE;
-
     if (g_conf.bdev_fake_mb) {
       num_blocks = g_conf.bdev_fake_mb * 256;
       dout(0) << "faking dev size " << g_conf.bdev_fake_mb << " mb" << endl;