From d249194190b4c8db646f7dd2ef04e78e94eab5d2 Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Thu, 10 Feb 2011 06:19:10 -0800 Subject: [PATCH] MonitorStore::put_int: handle I/O errors Signed-off-by: Colin McCabe --- src/mon/MonitorStore.cc | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/mon/MonitorStore.cc b/src/mon/MonitorStore.cc index fd26cb07b15c..2d8753ad65e7 100644 --- a/src/mon/MonitorStore.cc +++ b/src/mon/MonitorStore.cc @@ -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(); + } } -- 2.47.3