cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
26ba25
From 8c14192b6417a5f07658c9434c10c4fb296574c8 Mon Sep 17 00:00:00 2001
26ba25
From: Fam Zheng <famz@redhat.com>
26ba25
Date: Fri, 29 Jun 2018 06:11:53 +0200
26ba25
Subject: [PATCH 179/268] file-posix: Fix EINTR handling
26ba25
26ba25
RH-Author: Fam Zheng <famz@redhat.com>
26ba25
Message-id: <20180629061153.12687-14-famz@redhat.com>
26ba25
Patchwork-id: 81164
26ba25
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH v2 13/13] file-posix: Fix EINTR handling
26ba25
Bugzilla: 1482537
26ba25
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
26ba25
26ba25
EINTR should be checked against errno, not ret. While fixing the bug,
26ba25
collect the branches with a switch block.
26ba25
26ba25
Also, change the return value from -ENOSTUP to -ENOSPC when the actual
26ba25
issue is request range passes EOF, which should be distinguishable from
26ba25
the case of error == ENOSYS by the caller, so that it could still retry
26ba25
with other byte ranges, whereas it shouldn't retry anymore upon ENOSYS.
26ba25
26ba25
Signed-off-by: Fam Zheng <famz@redhat.com>
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 block/file-posix.c | 17 +++++++++--------
26ba25
 1 file changed, 9 insertions(+), 8 deletions(-)
26ba25
26ba25
diff --git a/block/file-posix.c b/block/file-posix.c
26ba25
index 29ff699..0a9df5b 100644
26ba25
--- a/block/file-posix.c
26ba25
+++ b/block/file-posix.c
26ba25
@@ -1449,20 +1449,21 @@ static ssize_t handle_aiocb_copy_range(RawPosixAIOData *aiocb)
26ba25
         ssize_t ret = copy_file_range(aiocb->aio_fildes, &in_off,
26ba25
                                       aiocb->aio_fd2, &out_off,
26ba25
                                       bytes, 0);
26ba25
-        if (ret == -EINTR) {
26ba25
-            continue;
26ba25
+        if (ret == 0) {
26ba25
+            /* No progress (e.g. when beyond EOF), let the caller fall back to
26ba25
+             * buffer I/O. */
26ba25
+            return -ENOSPC;
26ba25
         }
26ba25
         if (ret < 0) {
26ba25
-            if (errno == ENOSYS) {
26ba25
+            switch (errno) {
26ba25
+            case ENOSYS:
26ba25
                 return -ENOTSUP;
26ba25
-            } else {
26ba25
+            case EINTR:
26ba25
+                continue;
26ba25
+            default:
26ba25
                 return -errno;
26ba25
             }
26ba25
         }
26ba25
-        if (!ret) {
26ba25
-            /* No progress (e.g. when beyond EOF), fall back to buffer I/O. */
26ba25
-            return -ENOTSUP;
26ba25
-        }
26ba25
         bytes -= ret;
26ba25
     }
26ba25
     return 0;
26ba25
-- 
26ba25
1.8.3.1
26ba25