From f0ae4abd0d269215d02d3126cf25ac68099d1f0f Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Sun, 29 Dec 2013 13:10:12 +0100 Subject: [PATCH] mon: create mon-data directory on --mkfs If the mon-data directory does not exist when ceph-mon --mkfs runs, it is created. Signed-off-by: Loic Dachary --- src/ceph_mon.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/ceph_mon.cc b/src/ceph_mon.cc index e4e402991199f..517013bbb08ff 100644 --- a/src/ceph_mon.cc +++ b/src/ceph_mon.cc @@ -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); -- 2.39.5