yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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