Bug 1589627 - Improve image locking error handling
Summary: Improve image locking error handling
Keywords:
Status: CLOSED DUPLICATE of bug 1703793
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: qemu-kvm
Version: ---
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: rc
: ---
Assignee: Hanna Czenczek
QA Contact: Tingting Mao
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-06-11 02:16 UTC by Fam Zheng
Modified: 2019-06-14 02:22 UTC (History)
14 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2019-06-14 02:22:51 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Bugzilla 1526313 0 medium CLOSED Improve QEMU lock error info for hot-plugging same qcow2 image file twice in different target to VM 2021-02-22 00:41:40 UTC
Red Hat Bugzilla 1584982 0 high CLOSED qemu abort()-s on lock failure even if it was running previously 2021-02-22 00:41:40 UTC
Red Hat Bugzilla 1588873 1 None None None 2021-09-09 14:28:39 UTC
Red Hat Knowledge Base (Solution) 3481211 0 None None None 2018-06-11 20:24:00 UTC

Internal Links: 1526313 1584982 1588873

Description Fam Zheng 2018-06-11 02:16:46 UTC
QEMU code uses "abort()" in certain cases where image locking acquisition options are not expected to fail. This is risky. One example is bug 1588873. Another is 1584982. Although when the abort happens, it is often a misbehave of some other parts of the system rather than QEMU itself, effectively asserting about the external resources is not robust program logic.

Specifically, the code in question is usually written as:

  blk_set_perm(blk, 0, BLK_PERM_ALL, &error_abort);

where error_abort should be replaced by local_err and error_report().

Comment 2 Fam Zheng 2018-06-11 02:18:43 UTC
Also, it's fairly easy to avoid the locked bits re-acquire waste as described in bug 1588873, like this:

commit 1986f53e8958cd8e893d5658f9cb7209551cf98b (image-lock-skip-bits)
Author: Fam Zheng <famz>
Date:   Tue Jun 5 13:11:36 2018 +0800

    file-posix: Skip already locked/unlocked bits

    Signed-off-by: Fam Zheng <famz>

diff --git a/block/file-posix.c b/block/file-posix.c
index 5a602cfe37..5cc9caaa23 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -650,13 +650,14 @@ static int raw_apply_lock_bytes(BDRVRawState *s,

     PERM_FOREACH(i) {
         int off = RAW_LOCK_PERM_BASE + i;
-        if (perm_lock_bits & (1ULL << i)) {
+        uint64_t bit = (1ULL << i);
+        if ((perm_lock_bits & bit) && !(s->perm & bit)) {
             ret = qemu_lock_fd(s->lock_fd, off, 1, false);
             if (ret) {
                 error_setg(errp, "Failed to lock byte %d", off);
                 return ret;
             }
-        } else if (unlock) {
+        } else if (unlock && (s->perm & bit)) {
             ret = qemu_unlock_fd(s->lock_fd, off, 1);
             if (ret) {
                 error_setg(errp, "Failed to unlock byte %d", off);
@@ -666,13 +667,14 @@ static int raw_apply_lock_bytes(BDRVRawState *s,
     }
     PERM_FOREACH(i) {
         int off = RAW_LOCK_SHARED_BASE + i;
-        if (shared_perm_lock_bits & (1ULL << i)) {
+        uint64_t bit = (1ULL << i);
+        if ((shared_perm_lock_bits & bit) && !(s->shared_perm & bit)) {
             ret = qemu_lock_fd(s->lock_fd, off, 1, false);
             if (ret) {
                 error_setg(errp, "Failed to lock byte %d", off);
                 return ret;
             }
-        } else if (unlock) {
+        } else if (unlock && (s->shared_perm & bit)) {
             ret = qemu_unlock_fd(s->lock_fd, off, 1);
             if (ret) {
                 error_setg(errp, "Failed to unlock byte %d", off);

Comment 4 Ademar Reis 2018-06-11 20:26:12 UTC
See also Bug 1526313


Note You need to log in before you can comment on or make changes to this bug.