From 005dd45479b86fa0887d1a54bb5753483208e419 Mon Sep 17 00:00:00 2001 From: sageweil Date: Wed, 25 Jul 2007 02:55:58 +0000 Subject: [PATCH] fixed antoher stupid get_num_blocks bug git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1547 29311d96-e01e-0410-9327-a35deaab8ce9 --- trunk/ceph/ebofs/BlockDevice.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/trunk/ceph/ebofs/BlockDevice.cc b/trunk/ceph/ebofs/BlockDevice.cc index 2efb4246c92e2..8fcb6bf549a8e 100644 --- a/trunk/ceph/ebofs/BlockDevice.cc +++ b/trunk/ceph/ebofs/BlockDevice.cc @@ -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, §ors); - 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; -- 2.39.5