#include "common/Timer.h"
#include "common/Clock.h"
+#include "include/color.h"
#include "OSDMonitor.h"
#include "MDSMonitor.h"
bufferlist magicbl;
magicbl.append(CEPH_MON_ONDISK_MAGIC);
magicbl.append("\n");
- store->put_bl_ss(magicbl, "magic", 0);
+ try {
+ store->put_bl_ss(magicbl, "magic", 0);
+ }
+ catch (const MonitorStore::Error &e) {
+ std::cerr << TEXT_RED << "** ERROR: initializing cmon failed: couldn't "
+ << "initialize the monitor state machine: "
+ << e.what() << TEXT_NORMAL << std::endl;
+ exit(1);
+ }
bufferlist features;
CompatSet mon_features(ceph_mon_feature_compat,
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
+#include <sstream>
#include <sys/file.h>
+MonitorStore::Error MonitorStore::Error::
+FromErrno(const char *prefix, const char *prefix2, int errno_)
+{
+ char buf[128];
+ const char *b2 = strerror_r(errno_, buf, sizeof(buf));
+ ostringstream oss;
+ oss << prefix << prefix2 << ": " << b2 << " (" << errno_ << ")";
+ return MonitorStore::Error(oss.str());
+}
+
+MonitorStore::Error::
+Error(const std::string &str_) : str(str_) { }
+
+MonitorStore::Error::
+~Error() throw () { }
+
+const char *MonitorStore::Error::
+what() const throw ()
+{
+ return str.c_str();
+}
+
int MonitorStore::mount()
{
char t[1024];
int fd;
if (append) {
fd = ::open(fn, O_WRONLY|O_CREAT|O_APPEND, 0644);
+ if (fd < 0)
+ throw Error::FromErrno("failed to open for append: ", fn, errno);
} else {
snprintf(tfn, sizeof(tfn), "%s.new", fn);
fd = ::open(tfn, O_WRONLY|O_CREAT, 0644);
+ if (fd < 0)
+ throw Error::FromErrno("failed to open: ", tfn, errno);
}
- assert(fd >= 0);
err = bl.write_fd(fd);
#include "include/types.h"
#include "include/buffer.h"
+#include <iosfwd>
#include <string.h>
class MonitorStore {
int lock_fd;
int write_bl_ss(bufferlist& bl, const char *a, const char *b, bool append, bool sync=true);
+
public:
+ class Error : public std::exception
+ {
+ public:
+ static Error FromErrno(const char *prefix,
+ const char *prefix2, int errno_);
+ Error(const std::string &str_);
+ virtual ~Error() throw ();
+ const char *what() const throw ();
+ private:
+ std::string str;
+ };
+
MonitorStore(const char *d) : dir(d) { }
~MonitorStore() { }