]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: create mon-data directory on --mkfs
authorLoic Dachary <loic@dachary.org>
Sun, 29 Dec 2013 12:10:12 +0000 (13:10 +0100)
committerLoic Dachary <loic@dachary.org>
Tue, 31 Dec 2013 17:58:25 +0000 (18:58 +0100)
If the mon-data directory does not exist when ceph-mon --mkfs runs, it
is created.

Signed-off-by: Loic Dachary <loic@dachary.org>
src/ceph_mon.cc

index e4e402991199fc5ddf1e1bfaa2c36806b5f68e82..517013bbb08ff94ced94132fd3a663482c45166e 100644 (file)
@@ -100,6 +100,22 @@ int obtain_monmap(MonitorDBStore &store, bufferlist &bl)
   return -ENOENT;
 }
 
+int mon_data_exists(bool *r)
+{
+  string mon_data = g_conf->mon_data;
+  struct stat buf;
+  if (::stat(mon_data.c_str(), &buf)) {
+    if (errno == ENOENT) {
+      *r = false;
+    } else {
+      cerr << "stat(" << mon_data << ") " << strerror(errno) << std::endl;
+      return -errno;
+    }
+  } else {
+    *r = true;
+  }
+  return 0;
+}
 
 void usage()
 {
@@ -188,8 +204,21 @@ int main(int argc, const char **argv)
     usage();
   }
 
+  bool exists;
   // -- mkfs --
   if (mkfs) {
+
+    if (mon_data_exists(&exists))
+      exit(1);
+
+    if (!exists) {
+      if (::mkdir(g_conf->mon_data.c_str(), 0755)) {
+       cerr << "mkdir(" << g_conf->mon_data << ") : "
+            << strerror(errno) << std::endl;
+       exit(1);
+      }
+    }
+
     // resolve public_network -> public_addr
     pick_addresses(g_ceph_context, CEPH_PICK_ADDRESS_PUBLIC);