From fa12b9737dd4ab36c3b4abaf25eb79f692e6eba6 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Fri, 5 Feb 2016 18:25:58 -0800 Subject: Reboot and retry on I/O errors When I/O error happens, reboot and retry installation two times before we abort this OTA update. Bug: 25633753 Change-Id: Iba6d4203a343a725aa625a41d237606980d62f69 (cherry picked from commit 3c62b67faf8a25f1dd1c44dc19759c3997fdfd36) --- otafault/ota_io.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 10 deletions(-) (limited to 'otafault') diff --git a/otafault/ota_io.cpp b/otafault/ota_io.cpp index 02e80f9bf..a37804088 100644 --- a/otafault/ota_io.cpp +++ b/otafault/ota_io.cpp @@ -38,6 +38,8 @@ static std::string FaultFileName = #endif // defined (TARGET_READ_FAULT) #endif // defined (TARGET_INJECT_FAULTS) +bool have_eio_error = false; + int ota_open(const char* path, int oflags) { #if defined (TARGET_INJECT_FAULTS) // Let the caller handle errors; we do not care if open succeeds or fails @@ -90,12 +92,22 @@ size_t ota_fread(void* ptr, size_t size, size_t nitems, FILE* stream) { && FilenameCache[(intptr_t)stream] == FaultFileName) { FaultFileName = ""; errno = EIO; + have_eio_error = true; return 0; } else { - return fread(ptr, size, nitems, stream); + size_t status = fread(ptr, size, nitems, stream); + // If I/O error occurs, set the retry-update flag. + if (status != nitems && errno == EIO) { + have_eio_error = true; + } + return status; } #else - return fread(ptr, size, nitems, stream); + size_t status = fread(ptr, size, nitems, stream); + if (status != nitems && errno == EIO) { + have_eio_error = true; + } + return status; #endif } @@ -105,12 +117,21 @@ ssize_t ota_read(int fd, void* buf, size_t nbyte) { && FilenameCache[fd] == FaultFileName) { FaultFileName = ""; errno = EIO; + have_eio_error = true; return -1; } else { - return read(fd, buf, nbyte); + ssize_t status = read(fd, buf, nbyte); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; } #else - return read(fd, buf, nbyte); + ssize_t status = read(fd, buf, nbyte); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; #endif } @@ -120,12 +141,21 @@ size_t ota_fwrite(const void* ptr, size_t size, size_t count, FILE* stream) { && FilenameCache[(intptr_t)stream] == FaultFileName) { FaultFileName = ""; errno = EIO; + have_eio_error = true; return 0; } else { - return fwrite(ptr, size, count, stream); + size_t status = fwrite(ptr, size, count, stream); + if (status != count && errno == EIO) { + have_eio_error = true; + } + return status; } #else - return fwrite(ptr, size, count, stream); + size_t status = fwrite(ptr, size, count, stream); + if (status != count && errno == EIO) { + have_eio_error = true; + } + return status; #endif } @@ -135,12 +165,21 @@ ssize_t ota_write(int fd, const void* buf, size_t nbyte) { && FilenameCache[fd] == FaultFileName) { FaultFileName = ""; errno = EIO; + have_eio_error = true; return -1; } else { - return write(fd, buf, nbyte); + ssize_t status = write(fd, buf, nbyte); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; } #else - return write(fd, buf, nbyte); + ssize_t status = write(fd, buf, nbyte); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; #endif } @@ -151,10 +190,19 @@ int ota_fsync(int fd) { FaultFileName = ""; errno = EIO; return -1; + have_eio_error = true; } else { - return fsync(fd); + int status = fsync(fd); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; } #else - return fsync(fd); + int status = fsync(fd); + if (status == -1 && errno == EIO) { + have_eio_error = true; + } + return status; #endif } -- cgit v1.2.3