]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: clean up check_fsid() a bit
authorSage Weil <sage@inktank.com>
Fri, 12 Jul 2013 00:46:48 +0000 (17:46 -0700)
committerSage Weil <sage@inktank.com>
Fri, 12 Jul 2013 18:28:18 +0000 (11:28 -0700)
Use the uuid_d type instead of kludging string comparisons.

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

index e1dd354a430ad9886f1b59959b872a234d077086..e11fb8103821f3f919869318e93d53e9ab03e9b8 100644 (file)
@@ -3474,14 +3474,10 @@ void Monitor::tick()
 
 int Monitor::check_fsid()
 {
-  ostringstream ss;
-  ss << monmap->get_fsid();
-  string us = ss.str();
-  bufferlist ebl;
-
   if (!store->exists(MONITOR_NAME, "cluster_uuid"))
     return -ENOENT;
 
+  bufferlist ebl;
   int r = store->get(MONITOR_NAME, "cluster_uuid", ebl);
   assert(r == 0);
 
@@ -3493,10 +3489,15 @@ int Monitor::check_fsid()
     es.resize(pos);
 
   dout(10) << "check_fsid cluster_uuid contains '" << es << "'" << dendl;
-  if (es.length() < us.length() ||
-      strncmp(us.c_str(), es.c_str(), us.length()) != 0) {
-    derr << "error: cluster_uuid file exists with value '" << es
-        << "', != our uuid " << monmap->get_fsid() << dendl;
+  uuid_d ondisk;
+  if (!ondisk.parse(es.c_str())) {
+    derr << "error: unable to parse uuid" << dendl;
+    return -EINVAL;
+  }
+
+  if (monmap->get_fsid() != ondisk) {
+    derr << "error: cluster_uuid file exists with value " << ondisk
+        << ", != our uuid " << monmap->get_fsid() << dendl;
     return -EEXIST;
   }