Blame SOURCES/kvm-file-posix-Lock-new-fd-in-raw_reopen_prepare.patch

7711c0
From ffe4f32d741439547577bc87e1f08df8f6f2a151 Mon Sep 17 00:00:00 2001
7711c0
From: Kevin Wolf <kwolf@redhat.com>
7711c0
Date: Fri, 15 Mar 2019 18:10:08 +0100
7711c0
Subject: [PATCH 012/163] file-posix: Lock new fd in raw_reopen_prepare()
7711c0
7711c0
RH-Author: Kevin Wolf <kwolf@redhat.com>
7711c0
Message-id: <20190315181010.14964-13-kwolf@redhat.com>
7711c0
Patchwork-id: 84889
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 12/14] file-posix: Lock new fd in raw_reopen_prepare()
7711c0
Bugzilla: 1685989
7711c0
RH-Acked-by: John Snow <jsnow@redhat.com>
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
7711c0
There is no reason why we can take locks on the new file descriptor only
7711c0
in raw_reopen_commit() where error handling isn't possible any more.
7711c0
Instead, we can already do this in raw_reopen_prepare().
7711c0
7711c0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7711c0
(cherry picked from commit a6aeca0ca530f104b5a5dd6704fca22b2c5edefa)
7711c0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 block/file-posix.c | 27 ++++++++++++++++-----------
7711c0
 1 file changed, 16 insertions(+), 11 deletions(-)
7711c0
7711c0
diff --git a/block/file-posix.c b/block/file-posix.c
7711c0
index b577d88..ae16f2f 100644
7711c0
--- a/block/file-posix.c
7711c0
+++ b/block/file-posix.c
7711c0
@@ -897,7 +897,7 @@ static int raw_reopen_prepare(BDRVReopenState *state,
7711c0
 {
7711c0
     BDRVRawState *s;
7711c0
     BDRVRawReopenState *rs;
7711c0
-    int ret = 0;
7711c0
+    int ret;
7711c0
     Error *local_err = NULL;
7711c0
 
7711c0
     assert(state != NULL);
7711c0
@@ -921,14 +921,27 @@ static int raw_reopen_prepare(BDRVReopenState *state,
7711c0
     if (rs->fd != -1) {
7711c0
         raw_probe_alignment(state->bs, rs->fd, &local_err);
7711c0
         if (local_err) {
7711c0
-            qemu_close(rs->fd);
7711c0
-            rs->fd = -1;
7711c0
             error_propagate(errp, local_err);
7711c0
             ret = -EINVAL;
7711c0
+            goto out_fd;
7711c0
+        }
7711c0
+
7711c0
+        /* Copy locks to the new fd */
7711c0
+        ret = raw_apply_lock_bytes(NULL, rs->fd, s->locked_perm,
7711c0
+                                   s->locked_shared_perm, false, errp);
7711c0
+        if (ret < 0) {
7711c0
+            ret = -EINVAL;
7711c0
+            goto out_fd;
7711c0
         }
7711c0
     }
7711c0
 
7711c0
     s->reopen_state = state;
7711c0
+    ret = 0;
7711c0
+out_fd:
7711c0
+    if (ret < 0) {
7711c0
+        qemu_close(rs->fd);
7711c0
+        rs->fd = -1;
7711c0
+    }
7711c0
 out:
7711c0
     return ret;
7711c0
 }
7711c0
@@ -937,17 +950,9 @@ static void raw_reopen_commit(BDRVReopenState *state)
7711c0
 {
7711c0
     BDRVRawReopenState *rs = state->opaque;
7711c0
     BDRVRawState *s = state->bs->opaque;
7711c0
-    Error *local_err = NULL;
7711c0
 
7711c0
     s->open_flags = rs->open_flags;
7711c0
 
7711c0
-    /* Copy locks to the new fd before closing the old one. */
7711c0
-    raw_apply_lock_bytes(NULL, rs->fd, s->locked_perm,
7711c0
-                         s->locked_shared_perm, false, &local_err);
7711c0
-    if (local_err) {
7711c0
-        /* shouldn't fail in a sane host, but report it just in case. */
7711c0
-        error_report_err(local_err);
7711c0
-    }
7711c0
     qemu_close(s->fd);
7711c0
     s->fd = rs->fd;
7711c0
 
7711c0
-- 
7711c0
1.8.3.1
7711c0