]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
fixed bdev size detection; mount validates s_magic
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Fri, 20 Jul 2007 17:08:09 +0000 (17:08 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Fri, 20 Jul 2007 17:08:09 +0000 (17:08 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1534 29311d96-e01e-0410-9327-a35deaab8ce9

trunk/ceph/ebofs/BlockDevice.cc
trunk/ceph/ebofs/Ebofs.cc

index d7ffc906701b7039b510fef1a5c28945d2079399..2efb4246c92e223d2f6bed07d5c856c040a871ec 100644 (file)
@@ -268,22 +268,33 @@ block_t BlockDevice::get_num_blocks()
   if (!num_blocks) {
     assert(fd > 0);
 
+    int r;
 #ifdef BLKGETSIZE64
     // ioctl block device
-    ioctl(fd, BLKGETSIZE64, &num_blocks);
+    uint64_t bytes = 0;
+    r = ioctl(fd, BLKGETSIZE64, &bytes);
+    num_blocks = bytes / 4096;
+    if (r == 0) {
+      dout(1) << "get_num_blocks ioctl BLKGETSIZE64 reports "
+             << bytes << " bytes, " 
+             << num_blocks << " 4k blocks" 
+             << endl;
 #else
     // hrm, try the 32 bit ioctl?
-    dout(0) << "hrm, no BLKGETSIZE64, falling back to BLKGETSIZE" << endl;
-    long sectors = 0;
-    ioctl(fd, BLKGETSIZE, &sectors);
-    num_blocks = 512*sectors;
+    unsigned long sectors = 0;
+    r = ioctl(fd, BLKGETSIZE, &sectors);
+    num_blocks = sectors/8;
+    if (r == 0) {
+      dout(1) << "get_num_blocks ioctl BLKGETSIZE reports " << sectors << " sectors, "
+             << num_blocks << " 4k blocks, " << (num_blocks*4096) << " bytes" << endl;
 #endif
-
-    if (!num_blocks) {
+    } 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;
     }
     
     num_blocks /= (uint64_t)EBOFS_BLOCK_SIZE;
index 0e3b1df8ff381a3245be740b83e3bcced216e25c..86504b6fdb9494780cae95c76b80cfa40039125d 100644 (file)
@@ -69,6 +69,19 @@ int Ebofs::mount()
 
   struct ebofs_super *sb1 = (struct ebofs_super*)bp1.c_str();
   struct ebofs_super *sb2 = (struct ebofs_super*)bp2.c_str();
+
+  // valid superblocks?
+  if (sb1->s_magic != EBOFS_MAGIC ||
+      sb2->s_magic != EBOFS_MAGIC) {
+    derr(0) << "mount bad magic, not a valid EBOFS file system" << endl;
+    return -EINVAL;
+  }
+  if (sb1->num_blocks < dev.get_num_blocks() ||
+      sb2->num_blocks < dev.get_num_blocks()) {
+    derr(0) << "mount superblock size exceeds actual device size" << endl;
+    return -EINVAL;
+  }
+
   dout(3) << "mount super @0 epoch " << sb1->epoch << endl;
   dout(3) << "mount super @1 epoch " << sb2->epoch << endl;