From f1af13567f057801e77dcef10124cb81b0ec92d6 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 9 Nov 2010 15:18:25 +0000 Subject: [PATCH] 2010-11-10 Tatsuhiro Tsujikawa Retry open(2) and fallocate(2) when they are interrupted by signal. * src/AbstractDiskWriter.cc --- ChangeLog | 6 ++++++ src/AbstractDiskWriter.cc | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index fe8100b8..9d825935 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-11-10 Tatsuhiro Tsujikawa + + Retry open(2) and fallocate(2) when they are interrupted by + signal. + * src/AbstractDiskWriter.cc + 2010-11-09 Tatsuhiro Tsujikawa Capture errno right after system/library call to avoid it to get diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index 066c4e35..2385f7a9 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -98,7 +98,9 @@ void AbstractDiskWriter::openExistingFile(uint64_t totalLength) flags |= O_RDWR; } - if((fd_ = open(filename_.c_str(), flags, OPEN_MODE)) < 0) { + while((fd_ = open(filename_.c_str(), flags, OPEN_MODE)) == -1 && + errno == EINTR); + if(fd_ < 0) { int errNum = errno; throw DL_ABORT_EX2 (errNum, @@ -112,8 +114,10 @@ void AbstractDiskWriter::createFile(int addFlags) { assert(!filename_.empty()); util::mkdirs(File(filename_).getDirname()); - if((fd_ = open(filename_.c_str(), O_CREAT|O_RDWR|O_TRUNC|O_BINARY|addFlags, - OPEN_MODE)) < 0) { + + while((fd_ = open(filename_.c_str(), O_CREAT|O_RDWR|O_TRUNC|O_BINARY|addFlags, + OPEN_MODE)) == -1 && errno == EINTR); + if(fd_ < 0) { int errNum = errno; throw DL_ABORT_EX2 (errNum, @@ -222,7 +226,8 @@ void AbstractDiskWriter::allocate(off_t offset, uint64_t length) # ifdef HAVE_FALLOCATE // For linux, we use fallocate to detect file system supports // fallocate or not. - int r = fallocate(fd_, 0, offset, length); + int r; + while((r = fallocate(fd_, 0, offset, length)) == -1 && errno == EINTR); int errNum = errno; if(r == -1) { throw DL_ABORT_EX(StringFormat("fallocate failed. cause: %s",