]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: make peek_whoami verify fsid
authorSage Weil <sage@newdream.net>
Thu, 20 Nov 2008 21:54:44 +0000 (13:54 -0800)
committerSage Weil <sage@newdream.net>
Thu, 20 Nov 2008 21:54:58 +0000 (13:54 -0800)
src/cosd.cc
src/osd/OSD.cc
src/osd/OSD.h

index da74b80a13989eecbec1d41aec81f5a2456e7d61..1215ff8d45932c390ccc5ed1a8c2b0476562ebbd 100644 (file)
@@ -98,7 +98,7 @@ int main(int argc, const char **argv)
   }
 
   if (whoami < 0) {
-    whoami = OSD::peek_whoami(dev);
+    whoami = OSD::peek_whoami(monmap.fsid, dev);
     if (whoami < 0) {
       cerr << "unable to determine OSD identity from superblock on " << dev << ": " << strerror(-whoami) << std::endl;
       exit(1);
@@ -114,6 +114,7 @@ int main(int argc, const char **argv)
   cout << "starting osd" << whoami
        << " at " << rank.get_rank_addr() 
        << " dev " << dev
+       << " fsid " << monmap.fsid
        << std::endl;
 
   g_timer.shutdown();
index e64a8f7db0d6ca23b3c3c1c6321a8d0590a68b82..2f13e8924a85b4fcd25ebb63cfcc27d7d06f62db 100644 (file)
@@ -211,7 +211,7 @@ int OSD::mkfs(const char *dev, ceph_fsid fsid, int whoami)
   return 0;
 }
 
-int OSD::peek_whoami(const char *dev)
+int OSD::peek_whoami(ceph_fsid& fsid, const char *dev)
 {
   ObjectStore *store = create_object_store(dev);
   int err = store->mount();
@@ -223,10 +223,17 @@ int OSD::peek_whoami(const char *dev)
   err = store->read(0, OSD_SUPERBLOCK_POBJECT, 0, sizeof(sb), bl);
   if (err < 0) 
     return -ENOENT;
-  bl.copy(0, sizeof(sb), (char*)&sb);
-  store->umount();
   delete store;
 
+  bufferlist::iterator p = bl.begin();
+  ::decode(sb, p);
+  store->umount();
+
+  if (!ceph_fsid_equal(&sb.fsid, &fsid)) {
+    generic_dout(0) << "dev fsid " << sb.fsid << " != monmap fsid " << fsid << dendl;
+    return -EPERM;
+  }
+
   return sb.whoami;
 }
 
index d791e2b99140f2e50859280c5c7cca04b2adfdf7..4fdc323b240091d90165383aa11a3ab706b386f1 100644 (file)
@@ -557,7 +557,7 @@ private:
   static int find_osd_dev(char *result, int whoami);
   static ObjectStore *create_object_store(const char *dev);
   static int mkfs(const char *dev, ceph_fsid fsid, int whoami);
-  static int peek_whoami(const char *dev);
+  static int peek_whoami(ceph_fsid& fsid, const char *dev);
 
   // startup/shutdown
   int init();