Blame SOURCES/kvm-block-file-posix-Pass-FD-to-locking-helpers.patch

357786
From 4667112e87999632688621951ce8c2ec8a0ebb8d Mon Sep 17 00:00:00 2001
357786
From: Max Reitz <mreitz@redhat.com>
357786
Date: Mon, 18 Jun 2018 14:53:35 +0200
357786
Subject: [PATCH 06/57] block/file-posix: Pass FD to locking helpers
357786
357786
RH-Author: Max Reitz <mreitz@redhat.com>
357786
Message-id: <20180618145337.633-2-mreitz@redhat.com>
357786
Patchwork-id: 80751
357786
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 1/3] block/file-posix: Pass FD to locking helpers
357786
Bugzilla: 1519144
357786
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
357786
RH-Acked-by: Fam Zheng <famz@redhat.com>
357786
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
357786
raw_apply_lock_bytes() and raw_check_lock_bytes() currently take a
357786
BDRVRawState *, but they only use the lock_fd field.  During image
357786
creation, we do not have a BDRVRawState, but we do have an FD; so if we
357786
want to reuse the functions there, we should modify them to receive only
357786
the FD.
357786
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
Reviewed-by: Fam Zheng <famz@redhat.com>
357786
Message-id: 20180509215336.31304-2-mreitz@redhat.com
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
(cherry picked from commit d0a96155de099d388f5e1f46277a54bdcfbb0bb2)
357786
Signed-off-by: Max Reitz <mreitz@redhat.com>
357786
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
357786
---
357786
 block/file-posix.c | 27 ++++++++++++++-------------
357786
 1 file changed, 14 insertions(+), 13 deletions(-)
357786
357786
diff --git a/block/file-posix.c b/block/file-posix.c
357786
index 3794c00..c98a4a1 100644
357786
--- a/block/file-posix.c
357786
+++ b/block/file-posix.c
357786
@@ -630,7 +630,7 @@ typedef enum {
357786
  * file; if @unlock == true, also unlock the unneeded bytes.
357786
  * @shared_perm_lock_bits is the mask of all permissions that are NOT shared.
357786
  */
357786
-static int raw_apply_lock_bytes(BDRVRawState *s,
357786
+static int raw_apply_lock_bytes(int fd,
357786
                                 uint64_t perm_lock_bits,
357786
                                 uint64_t shared_perm_lock_bits,
357786
                                 bool unlock, Error **errp)
357786
@@ -641,13 +641,13 @@ static int raw_apply_lock_bytes(BDRVRawState *s,
357786
     PERM_FOREACH(i) {
357786
         int off = RAW_LOCK_PERM_BASE + i;
357786
         if (perm_lock_bits & (1ULL << i)) {
357786
-            ret = qemu_lock_fd(s->lock_fd, off, 1, false);
357786
+            ret = qemu_lock_fd(fd, off, 1, false);
357786
             if (ret) {
357786
                 error_setg(errp, "Failed to lock byte %d", off);
357786
                 return ret;
357786
             }
357786
         } else if (unlock) {
357786
-            ret = qemu_unlock_fd(s->lock_fd, off, 1);
357786
+            ret = qemu_unlock_fd(fd, off, 1);
357786
             if (ret) {
357786
                 error_setg(errp, "Failed to unlock byte %d", off);
357786
                 return ret;
357786
@@ -657,13 +657,13 @@ static int raw_apply_lock_bytes(BDRVRawState *s,
357786
     PERM_FOREACH(i) {
357786
         int off = RAW_LOCK_SHARED_BASE + i;
357786
         if (shared_perm_lock_bits & (1ULL << i)) {
357786
-            ret = qemu_lock_fd(s->lock_fd, off, 1, false);
357786
+            ret = qemu_lock_fd(fd, off, 1, false);
357786
             if (ret) {
357786
                 error_setg(errp, "Failed to lock byte %d", off);
357786
                 return ret;
357786
             }
357786
         } else if (unlock) {
357786
-            ret = qemu_unlock_fd(s->lock_fd, off, 1);
357786
+            ret = qemu_unlock_fd(fd, off, 1);
357786
             if (ret) {
357786
                 error_setg(errp, "Failed to unlock byte %d", off);
357786
                 return ret;
357786
@@ -674,8 +674,7 @@ static int raw_apply_lock_bytes(BDRVRawState *s,
357786
 }
357786
 
357786
 /* Check "unshared" bytes implied by @perm and ~@shared_perm in the file. */
357786
-static int raw_check_lock_bytes(BDRVRawState *s,
357786
-                                uint64_t perm, uint64_t shared_perm,
357786
+static int raw_check_lock_bytes(int fd, uint64_t perm, uint64_t shared_perm,
357786
                                 Error **errp)
357786
 {
357786
     int ret;
357786
@@ -685,7 +684,7 @@ static int raw_check_lock_bytes(BDRVRawState *s,
357786
         int off = RAW_LOCK_SHARED_BASE + i;
357786
         uint64_t p = 1ULL << i;
357786
         if (perm & p) {
357786
-            ret = qemu_lock_fd_test(s->lock_fd, off, 1, true);
357786
+            ret = qemu_lock_fd_test(fd, off, 1, true);
357786
             if (ret) {
357786
                 char *perm_name = bdrv_perm_names(p);
357786
                 error_setg(errp,
357786
@@ -702,7 +701,7 @@ static int raw_check_lock_bytes(BDRVRawState *s,
357786
         int off = RAW_LOCK_PERM_BASE + i;
357786
         uint64_t p = 1ULL << i;
357786
         if (!(shared_perm & p)) {
357786
-            ret = qemu_lock_fd_test(s->lock_fd, off, 1, true);
357786
+            ret = qemu_lock_fd_test(fd, off, 1, true);
357786
             if (ret) {
357786
                 char *perm_name = bdrv_perm_names(p);
357786
                 error_setg(errp,
357786
@@ -739,11 +738,11 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
357786
 
357786
     switch (op) {
357786
     case RAW_PL_PREPARE:
357786
-        ret = raw_apply_lock_bytes(s, s->perm | new_perm,
357786
+        ret = raw_apply_lock_bytes(s->lock_fd, s->perm | new_perm,
357786
                                    ~s->shared_perm | ~new_shared,
357786
                                    false, errp);
357786
         if (!ret) {
357786
-            ret = raw_check_lock_bytes(s, new_perm, new_shared, errp);
357786
+            ret = raw_check_lock_bytes(s->lock_fd, new_perm, new_shared, errp);
357786
             if (!ret) {
357786
                 return 0;
357786
             }
357786
@@ -751,7 +750,8 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
357786
         op = RAW_PL_ABORT;
357786
         /* fall through to unlock bytes. */
357786
     case RAW_PL_ABORT:
357786
-        raw_apply_lock_bytes(s, s->perm, ~s->shared_perm, true, &local_err);
357786
+        raw_apply_lock_bytes(s->lock_fd, s->perm, ~s->shared_perm,
357786
+                             true, &local_err);
357786
         if (local_err) {
357786
             /* Theoretically the above call only unlocks bytes and it cannot
357786
              * fail. Something weird happened, report it.
357786
@@ -760,7 +760,8 @@ static int raw_handle_perm_lock(BlockDriverState *bs,
357786
         }
357786
         break;
357786
     case RAW_PL_COMMIT:
357786
-        raw_apply_lock_bytes(s, new_perm, ~new_shared, true, &local_err);
357786
+        raw_apply_lock_bytes(s->lock_fd, new_perm, ~new_shared,
357786
+                             true, &local_err);
357786
         if (local_err) {
357786
             /* Theoretically the above call only unlocks bytes and it cannot
357786
              * fail. Something weird happened, report it.
357786
-- 
357786
1.8.3.1
357786