Blame SOURCES/kvm-file-posix-Drop-s-lock_fd.patch

7711c0
From e56693b6f482bf594b39f751d17f371301e280b5 Mon Sep 17 00:00:00 2001
7711c0
From: Max Reitz <mreitz@redhat.com>
7711c0
Date: Mon, 4 Feb 2019 20:42:04 +0100
7711c0
Subject: [PATCH 04/33] file-posix: Drop s->lock_fd
7711c0
7711c0
RH-Author: Max Reitz <mreitz@redhat.com>
7711c0
Message-id: <20190204204207.18079-5-mreitz@redhat.com>
7711c0
Patchwork-id: 84223
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 4/7] file-posix: Drop s->lock_fd
7711c0
Bugzilla: 1551486
7711c0
RH-Acked-by: John Snow <jsnow@redhat.com>
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
7711c0
7711c0
From: Fam Zheng <famz@redhat.com>
7711c0
7711c0
The lock_fd field is not strictly necessary because transferring locked
7711c0
bytes from old fd to the new one shouldn't fail anyway. This spares the
7711c0
user one fd per image.
7711c0
7711c0
Signed-off-by: Fam Zheng <famz@redhat.com>
7711c0
Reviewed-by: Max Reitz <mreitz@redhat.com>
7711c0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
7711c0
(cherry picked from commit f2e3af29b70624659a50903bd075e1663b64c9da)
7711c0
Signed-off-by: Max Reitz <mreitz@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 block/file-posix.c | 37 +++++++++++++------------------------
7711c0
 1 file changed, 13 insertions(+), 24 deletions(-)
7711c0
7711c0
diff --git a/block/file-posix.c b/block/file-posix.c
7711c0
index 2a05193..97e7ff2 100644
7711c0
--- a/block/file-posix.c
7711c0
+++ b/block/file-posix.c
7711c0
@@ -142,7 +142,6 @@ do { \
7711c0
 
7711c0
 typedef struct BDRVRawState {
7711c0
     int fd;
7711c0
-    int lock_fd;
7711c0
     bool use_lock;
7711c0
     int type;
7711c0
     int open_flags;
7711c0
@@ -153,7 +152,7 @@ typedef struct BDRVRawState {
7711c0
     uint64_t shared_perm;
7711c0
 
7711c0
     /* The perms bits whose corresponding bytes are already locked in
7711c0
-     * s->lock_fd. */
7711c0
+     * s->fd. */
7711c0
     uint64_t locked_perm;
7711c0
     uint64_t locked_shared_perm;
7711c0
 
7711c0
@@ -545,18 +544,6 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
7711c0
     }
7711c0
     s->fd = fd;
7711c0
 
7711c0
-    s->lock_fd = -1;
7711c0
-    if (s->use_lock) {
7711c0
-        fd = qemu_open(filename, s->open_flags);
7711c0
-        if (fd < 0) {
7711c0
-            ret = -errno;
7711c0
-            error_setg_errno(errp, errno, "Could not open '%s' for locking",
7711c0
-                             filename);
7711c0
-            qemu_close(s->fd);
7711c0
-            goto fail;
7711c0
-        }
7711c0
-        s->lock_fd = fd;
7711c0
-    }
7711c0
     s->perm = 0;
7711c0
     s->shared_perm = BLK_PERM_ALL;
7711c0
 
7711c0
@@ -811,15 +798,13 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
7711c0
         return 0;
7711c0
     }
7711c0
 
7711c0
-    assert(s->lock_fd > 0);
7711c0
-
7711c0
     switch (op) {
7711c0
     case RAW_PL_PREPARE:
7711c0
-        ret = raw_apply_lock_bytes(s, s->lock_fd, s->perm | new_perm,
7711c0
+        ret = raw_apply_lock_bytes(s, s->fd, s->perm | new_perm,
7711c0
                                    ~s->shared_perm | ~new_shared,
7711c0
                                    false, errp);
7711c0
         if (!ret) {
7711c0
-            ret = raw_check_lock_bytes(s->lock_fd, new_perm, new_shared, errp);
7711c0
+            ret = raw_check_lock_bytes(s->fd, new_perm, new_shared, errp);
7711c0
             if (!ret) {
7711c0
                 return 0;
7711c0
             }
7711c0
@@ -830,7 +815,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
7711c0
         op = RAW_PL_ABORT;
7711c0
         /* fall through to unlock bytes. */
7711c0
     case RAW_PL_ABORT:
7711c0
-        raw_apply_lock_bytes(s, s->lock_fd, s->perm, ~s->shared_perm,
7711c0
+        raw_apply_lock_bytes(s, s->fd, s->perm, ~s->shared_perm,
7711c0
                              true, &local_err);
7711c0
         if (local_err) {
7711c0
             /* Theoretically the above call only unlocks bytes and it cannot
7711c0
@@ -840,7 +825,7 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
7711c0
         }
7711c0
         break;
7711c0
     case RAW_PL_COMMIT:
7711c0
-        raw_apply_lock_bytes(s, s->lock_fd, new_perm, ~new_shared,
7711c0
+        raw_apply_lock_bytes(s, s->fd, new_perm, ~new_shared,
7711c0
                              true, &local_err);
7711c0
         if (local_err) {
7711c0
             /* Theoretically the above call only unlocks bytes and it cannot
7711c0
@@ -938,9 +923,17 @@ 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
@@ -1903,10 +1896,6 @@ static void raw_close(BlockDriverState *bs)
7711c0
         qemu_close(s->fd);
7711c0
         s->fd = -1;
7711c0
     }
7711c0
-    if (s->lock_fd >= 0) {
7711c0
-        qemu_close(s->lock_fd);
7711c0
-        s->lock_fd = -1;
7711c0
-    }
7711c0
 }
7711c0
 
7711c0
 /**
7711c0
-- 
7711c0
1.8.3.1
7711c0