]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
monitorstore: return error codes for consistency
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 27 May 2011 22:41:17 +0000 (15:41 -0700)
committerSage Weil <sage@newdream.net>
Wed, 8 Jun 2011 19:05:15 +0000 (12:05 -0700)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/mon/Monitor.cc
src/mon/MonitorStore.cc
src/mon/MonitorStore.h

index 676fef47fd641b4241c06e908d5d37a73ea82434..256942846b941cfe99945294fbce5379f320bcd5 100644 (file)
@@ -43,6 +43,7 @@
 #include "common/Timer.h"
 #include "common/Clock.h"
 #include "common/DoutStreambuf.h"
+#include "common/errno.h"
 #include "include/color.h"
 
 #include "OSDMonitor.h"
@@ -1006,13 +1007,11 @@ int Monitor::mkfs(bufferlist& osdmapbl)
   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);
   }
 
index 7316a7604e23f757a196cb3764595ccc7133f625..95983dc3bd2ec2a2233a1967a75d5dd40d75a9dd 100644 (file)
@@ -39,28 +39,6 @@ static ostream& _prefix(const string& dir) {
 #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];
@@ -311,7 +289,8 @@ int MonitorStore::get_bl_ss(bufferlist& bl, const char *a, const char *b)
   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);
@@ -328,13 +307,20 @@ int MonitorStore::write_bl_ss(bufferlist& bl, const char *a, const char *b, bool
   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);
@@ -346,8 +332,13 @@ int MonitorStore::write_bl_ss(bufferlist& bl, const char *a, const char *b, bool
     ::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;
+}
index 01f27f48c98239f98ec60385fe325ed2b1d00334..8e931e19e079407e57bfe35675e2d0f695673cbd 100644 (file)
@@ -25,21 +25,11 @@ class MonitorStore {
   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() { }