All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: [PULL 04/34] block/iscsi: Use lock guard macros
Date: Fri, 11 Dec 2020 18:07:42 +0100	[thread overview]
Message-ID: <20201211170812.228643-5-kwolf@redhat.com> (raw)
In-Reply-To: <20201211170812.228643-1-kwolf@redhat.com>

From: Gan Qixin <ganqixin@huawei.com>

Replace manual lock()/unlock() calls with lock guard macros
(QEMU_LOCK_GUARD/WITH_QEMU_LOCK_GUARD) in block/iscsi.

Signed-off-by: Gan Qixin <ganqixin@huawei.com>
Message-Id: <20201203075055.127773-5-ganqixin@huawei.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/iscsi.c | 50 ++++++++++++++++++++++++--------------------------
 1 file changed, 24 insertions(+), 26 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index e30a7e3606..7d4b3b56d5 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -322,25 +322,23 @@ iscsi_aio_cancel(BlockAIOCB *blockacb)
     IscsiAIOCB *acb = (IscsiAIOCB *)blockacb;
     IscsiLun *iscsilun = acb->iscsilun;
 
-    qemu_mutex_lock(&iscsilun->mutex);
+    WITH_QEMU_LOCK_GUARD(&iscsilun->mutex) {
 
-    /* If it was cancelled or completed already, our work is done here */
-    if (acb->cancelled || acb->status != -EINPROGRESS) {
-        qemu_mutex_unlock(&iscsilun->mutex);
-        return;
-    }
+        /* If it was cancelled or completed already, our work is done here */
+        if (acb->cancelled || acb->status != -EINPROGRESS) {
+            return;
+        }
 
-    acb->cancelled = true;
+        acb->cancelled = true;
 
-    qemu_aio_ref(acb); /* released in iscsi_abort_task_cb() */
+        qemu_aio_ref(acb); /* released in iscsi_abort_task_cb() */
 
-    /* send a task mgmt call to the target to cancel the task on the target */
-    if (iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task,
-                                         iscsi_abort_task_cb, acb) < 0) {
-        qemu_aio_unref(acb); /* since iscsi_abort_task_cb() won't be called */
+        /* send a task mgmt call to the target to cancel the task on the target */
+        if (iscsi_task_mgmt_abort_task_async(iscsilun->iscsi, acb->task,
+                                             iscsi_abort_task_cb, acb) < 0) {
+            qemu_aio_unref(acb); /* since iscsi_abort_task_cb() won't be called */
+        }
     }
-
-    qemu_mutex_unlock(&iscsilun->mutex);
 }
 
 static const AIOCBInfo iscsi_aiocb_info = {
@@ -375,22 +373,22 @@ static void iscsi_timed_check_events(void *opaque)
 {
     IscsiLun *iscsilun = opaque;
 
-    qemu_mutex_lock(&iscsilun->mutex);
+    WITH_QEMU_LOCK_GUARD(&iscsilun->mutex) {
+        /* check for timed out requests */
+        iscsi_service(iscsilun->iscsi, 0);
 
-    /* check for timed out requests */
-    iscsi_service(iscsilun->iscsi, 0);
+        if (iscsilun->request_timed_out) {
+            iscsilun->request_timed_out = false;
+            iscsi_reconnect(iscsilun->iscsi);
+        }
 
-    if (iscsilun->request_timed_out) {
-        iscsilun->request_timed_out = false;
-        iscsi_reconnect(iscsilun->iscsi);
+        /*
+         * newer versions of libiscsi may return zero events. Ensure we are
+         * able to return to service once this situation changes.
+         */
+        iscsi_set_events(iscsilun);
     }
 
-    /* newer versions of libiscsi may return zero events. Ensure we are able
-     * to return to service once this situation changes. */
-    iscsi_set_events(iscsilun);
-
-    qemu_mutex_unlock(&iscsilun->mutex);
-
     timer_mod(iscsilun->event_timer,
               qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + EVENT_INTERVAL);
 }
-- 
2.29.2



  parent reply	other threads:[~2020-12-11 17:25 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 17:07 [PULL 00/34] Block layer patches Kevin Wolf
2020-12-11 17:07 ` [PULL 01/34] block/accounting: Use lock guard macros Kevin Wolf
2020-12-11 17:07 ` [PULL 02/34] block/curl: " Kevin Wolf
2020-12-11 17:07 ` [PULL 03/34] block/throttle-groups: " Kevin Wolf
2020-12-11 17:07 ` Kevin Wolf [this message]
2020-12-11 17:07 ` [PULL 05/34] meson: Detect libfuse Kevin Wolf
2020-12-11 17:07 ` [PULL 06/34] fuse: Allow exporting BDSs via FUSE Kevin Wolf
2020-12-11 17:07 ` [PULL 07/34] fuse: Implement standard FUSE operations Kevin Wolf
2020-12-11 17:07 ` [PULL 08/34] fuse: Allow growable exports Kevin Wolf
2020-12-11 17:07 ` [PULL 09/34] fuse: (Partially) implement fallocate() Kevin Wolf
2020-12-11 17:07 ` [PULL 10/34] fuse: Implement hole detection through lseek Kevin Wolf
2020-12-11 17:07 ` [PULL 11/34] iotests: Do not needlessly filter _make_test_img Kevin Wolf
2020-12-11 17:07 ` [PULL 12/34] iotests: Do not pipe _make_test_img Kevin Wolf
2020-12-11 17:07 ` [PULL 13/34] iotests: Use convert -n in some cases Kevin Wolf
2020-12-11 17:07 ` [PULL 14/34] iotests/046: Avoid renaming images Kevin Wolf
2020-12-11 17:07 ` [PULL 15/34] iotests: Derive image names from $TEST_IMG Kevin Wolf
2020-12-11 17:07 ` [PULL 16/34] iotests/091: Use _cleanup_qemu instad of "wait" Kevin Wolf
2020-12-11 17:07 ` [PULL 17/34] iotests: Restrict some Python tests to file Kevin Wolf
2020-12-11 17:07 ` [PULL 18/34] iotests: Let _make_test_img guess $TEST_IMG_FILE Kevin Wolf
2020-12-11 17:07 ` [PULL 19/34] iotests/287: Clean up subshell test image Kevin Wolf
2020-12-11 17:07 ` [PULL 20/34] storage-daemon: Call bdrv_close_all() on exit Kevin Wolf
2020-12-11 17:07 ` [PULL 21/34] iotests: Give access to the qemu-storage-daemon Kevin Wolf
2020-12-11 17:08 ` [PULL 22/34] iotests: Allow testing FUSE exports Kevin Wolf
2020-12-11 17:08 ` [PULL 23/34] iotests: Enable fuse for many tests Kevin Wolf
2020-12-11 17:08 ` [PULL 24/34] iotests/308: Add test for FUSE exports Kevin Wolf
2020-12-11 17:08 ` [PULL 25/34] file-posix: check the use_lock before setting the file lock Kevin Wolf
2020-12-11 17:08 ` [PULL 26/34] iotests/221: Discard image before qemu-img map Kevin Wolf
2020-12-11 17:08 ` [PULL 27/34] can-host: Fix crash when 'canbus' property is not set Kevin Wolf
2020-12-11 17:08 ` [PULL 28/34] block/file-posix: fix workaround in raw_do_pwrite_zeroes() Kevin Wolf
2020-12-11 17:08 ` [PULL 29/34] block/io: bdrv_refresh_limits(): use ERRP_GUARD Kevin Wolf
2020-12-11 17:08 ` [PULL 30/34] block/io: bdrv_check_byte_request(): drop bdrv_is_inserted() Kevin Wolf
2020-12-11 17:08 ` [PULL 31/34] block: introduce BDRV_MAX_LENGTH Kevin Wolf
2020-12-11 17:08 ` [PULL 32/34] block: Simplify qmp_block_resize() error paths Kevin Wolf
2020-12-11 17:08 ` [PULL 33/34] block: Fix locking in qmp_block_resize() Kevin Wolf
2020-12-11 17:08 ` [PULL 34/34] block: Fix deadlock in bdrv_co_yield_to_drain() Kevin Wolf
2020-12-12 16:06 ` [PULL 00/34] Block layer patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201211170812.228643-5-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.