]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
MonitorStore::put_int: handle I/O errors
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 10 Feb 2011 14:19:10 +0000 (06:19 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 10 Feb 2011 14:21:04 +0000 (06:21 -0800)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/mon/MonitorStore.cc

index fd26cb07b15c7aafd6a43f9e54a3e4e94540bd90..2d8753ad65e7c6d99f19f09f6f2dd61060f8fc1c 100644 (file)
@@ -14,8 +14,9 @@
 
 #include "MonitorStore.h"
 #include "common/Clock.h"
+#include "common/errno.h"
 #include "common/run_cmd.h"
-
+#include "common/safe_io.h"
 #include "config.h"
 
 #define DOUT_SUBSYS mon
@@ -177,14 +178,32 @@ void MonitorStore::put_int(version_t val, const char *a, const char *b, bool syn
   char tfn[1024];
   snprintf(tfn, sizeof(tfn), "%s.new", fn);
 
-  int fd = ::open(tfn, O_WRONLY|O_CREAT, 0644);
-  assert(fd >= 0);
-  int r = ::write(fd, vs, strlen(vs));
-  assert(r >= 0);
+  int fd = TEMP_FAILURE_RETRY(::open(tfn, O_WRONLY|O_CREAT, 0644));
+  if (fd < 0) {
+    int err = errno;
+    derr << "MonitorStore::put_int: failed to open '" << tfn << "': "
+        << cpp_strerror(err) << dendl;
+    ceph_abort();
+  }
+  int r = safe_write(fd, vs, strlen(vs));
+  if (r) {
+    derr << "MonitorStore::put_int: failed to write to '" << tfn << "': "
+        << cpp_strerror(r) << dendl;
+    ceph_abort();
+  }
   if (sync)
     ::fsync(fd);
-  ::close(fd);
-  ::rename(tfn, fn);
+  if (TEMP_FAILURE_RETRY(::close(fd))) {
+    derr << "MonitorStore::put_int: failed to close fd for '" << tfn << "': "
+        << cpp_strerror(r) << dendl;
+    ceph_abort();
+  }
+  if (::rename(tfn, fn)) {
+    int err = errno;
+    derr << "MonitorStore::put_int: failed to rename '" << tfn << "' to "
+        << "'" << fn << "': " << cpp_strerror(err) << dendl;
+    ceph_abort();
+  }
 }