]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: create, verify cluster_fsid file in mon_data dir on mkfs
authorSage Weil <sage@inktank.com>
Mon, 20 Aug 2012 17:56:14 +0000 (10:56 -0700)
committerSage Weil <sage@inktank.com>
Thu, 23 Aug 2012 17:06:33 +0000 (10:06 -0700)
Having this present is convenient for external tools.

Signed-off-by: Sage Weil <sage@inktank.com>
src/mon/Monitor.cc
src/mon/Monitor.h

index 902d6d508f78a7db36fc0b5999c214cbfb0853a3..f6b3878dcf7009b6512a207b073138e6ee2bc110 100644 (file)
@@ -2015,6 +2015,45 @@ void Monitor::tick()
   new_tick();
 }
 
+int Monitor::check_fsid()
+{
+  ostringstream ss;
+  ss << monmap->get_fsid();
+  string us = ss.str();
+  bufferlist ebl;
+  int r = store->get_bl_ss(ebl, "cluster_fsid", 0);
+  if (r < 0)
+    return r;
+
+  string es(ebl.c_str(), ebl.length());
+
+  // only keep the first line
+  size_t pos = es.find_first_of('\n');
+  if (pos != string::npos)
+    es.resize(pos);
+
+  dout(10) << "check_fsid cluster_fsid contains '" << es << "'" << dendl;
+  if (es.length() < us.length() ||
+      strncmp(us.c_str(), es.c_str(), us.length()) != 0) {
+    derr << "error: cluster_fsid file exists with value '" << es
+        << "', != our uuid " << monmap->get_fsid() << dendl;
+    return -EEXIST;
+  }
+
+  return 0;
+}
+
+int Monitor::write_fsid()
+{
+  ostringstream ss;
+  ss << monmap->get_fsid() << "\n";
+  string us = ss.str();
+
+  bufferlist b;
+  b.append(us);
+  return store->put_bl_ss(b, "cluster_fsid", 0);
+}
+
 /*
  * this is the closest thing to a traditional 'mkfs' for ceph.
  * initialize the monitor state machines to their initial values.
@@ -2028,10 +2067,15 @@ int Monitor::mkfs(bufferlist& osdmapbl)
     return err;
   }
 
+  // verify cluster fsid
+  int r = check_fsid();
+  if (r < 0 && r != -ENOENT)
+    return r;
+
   bufferlist magicbl;
   magicbl.append(CEPH_MON_ONDISK_MAGIC);
   magicbl.append("\n");
-  int r = store->put_bl_ss(magicbl, "magic", 0);
+  r = store->put_bl_ss(magicbl, "magic", 0);
   if (r < 0)
     return r;
 
@@ -2073,6 +2117,12 @@ int Monitor::mkfs(bufferlist& osdmapbl)
   keyring.encode_plaintext(keyringbl);
   store->put_bl_ss(keyringbl, "mkfs", "keyring");
 
+  // sync and write out fsid to indicate completion.
+  store->sync();
+  r = write_fsid();
+  if (r < 0)
+    return r;
+
   return 0;
 }
 
index 5aeb16698f3d7eb8f2be8397d8ad9969f89e6086..c7cccf5c4c66ac6963dd302a0f1c48279b3cac28 100644 (file)
@@ -419,6 +419,20 @@ public:
 
   int mkfs(bufferlist& osdmapbl);
 
+  /**
+   * check cluster_fsid file
+   *
+   * @return EEXIST if file exists and doesn't match, 0 on match, or negative error code
+   */
+  int check_fsid();
+
+  /**
+   * write cluster_fsid file
+   *
+   * @return 0 on success, or negative error code
+   */
+  int write_fsid();
+
   void do_admin_command(std::string command, std::string args, ostream& ss);
 
 private: