thebeanogamer / rpms / qemu-kvm

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