From: Colin Patrick McCabe Date: Thu, 10 Feb 2011 14:19:10 +0000 (-0800) Subject: MonitorStore::put_int: handle I/O errors X-Git-Tag: v0.25~164 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d249194190b4c8db646f7dd2ef04e78e94eab5d2;p=ceph.git MonitorStore::put_int: handle I/O errors Signed-off-by: Colin McCabe --- 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(); + } }