#include "common/Timer.h"
#include "common/Clock.h"
#include "common/DoutStreambuf.h"
+#include "common/errno.h"
#include "include/color.h"
#include "OSDMonitor.h"
bufferlist magicbl;
magicbl.append(CEPH_MON_ONDISK_MAGIC);
magicbl.append("\n");
- try {
- store->put_bl_ss(magicbl, "magic", 0);
- }
- catch (const MonitorStore::Error &e) {
+ int r = store->put_bl_ss(magicbl, "magic", 0);
+ if (r < 0) {
dout(0) << TEXT_RED << "** ERROR: initializing cmon failed: couldn't "
- << "initialize the monitor state machine: "
- << e.what() << TEXT_NORMAL << dendl;
+ << "initialize the monitor state machine: " << cpp_strerror(r)
+ << TEXT_NORMAL << dendl;
exit(1);
}
#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];
return len;
}
-int MonitorStore::write_bl_ss(bufferlist& bl, const char *a, const char *b, bool append, bool sync)
+int MonitorStore::
+write_bl_ss_impl(bufferlist& bl, const char *a, const char *b, bool append, bool sync)
{
char fn[1024];
snprintf(fn, sizeof(fn), "%s/%s", dir.c_str(), a);
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);
+ if (fd < 0) {
+ err = -errno;
+ derr << "failed to open " << fn << "for append: "
+ << cpp_strerror(err) << dendl;
+ return err;
+ }
} 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);
+ if (fd < 0) {
+ err = -errno;
+ derr << "failed to open " << tfn << ": " << cpp_strerror(err) << dendl;
+ return err;
+ }
}
err = bl.write_fd(fd);
::rename(tfn, fn);
}
- assert(!err); // for now
-
return err;
}
+int MonitorStore::
+write_bl_ss(bufferlist& bl, const char *a, const char *b, bool append, bool sync)
+{
+ int err = write_bl_ss_impl(bl, a, b, append,sync);
+ assert(!err); // for now
+ return 0;
+}
string dir;
int lock_fd;
- int write_bl_ss(bufferlist& bl, const char *a, const char *b, bool append, bool sync=true);
-
+ int write_bl_ss_impl(bufferlist& bl, const char *a, const char *b,
+ bool append, bool sync);
+ 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 std::string &d) : dir(d) { }
~MonitorStore() { }