From: Mahmoud Mandour <ma.mandourr@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Mahmoud Mandour" <ma.mandourr@gmail.com>,
"Daniel P. Berrangé" <berrange@redhat.com>
Subject: [PATCH 4/9] util: Replaced qemu_mutex_lock with QEMU_LOCK_GUARDs
Date: Thu, 11 Mar 2021 05:15:33 +0200 [thread overview]
Message-ID: <20210311031538.5325-5-ma.mandourr@gmail.com> (raw)
In-Reply-To: <20210311031538.5325-1-ma.mandourr@gmail.com>
Removed various qemu_mutex_lock calls and their respective
qemu_mutex_unlock calls and used QEMU_LOCK_GUARD. This simplifies
the code by eliminating various goto paths and removes
qemu_mutex_unlock calls.
Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
---
util/filemonitor-inotify.c | 24 ++++++++----------------
util/vfio-helpers.c | 23 ++++++++++-------------
2 files changed, 18 insertions(+), 29 deletions(-)
diff --git a/util/filemonitor-inotify.c b/util/filemonitor-inotify.c
index 2c45f7f176..0e1a196088 100644
--- a/util/filemonitor-inotify.c
+++ b/util/filemonitor-inotify.c
@@ -59,10 +59,9 @@ static void qemu_file_monitor_watch(void *arg)
int used = 0;
int len;
- qemu_mutex_lock(&mon->lock);
+ QEMU_LOCK_GUARD(&mon->lock);
if (mon->fd == -1) {
- qemu_mutex_unlock(&mon->lock);
return;
}
@@ -72,11 +71,11 @@ static void qemu_file_monitor_watch(void *arg)
if (errno != EAGAIN) {
error_report("Failure monitoring inotify FD '%s',"
"disabling events", strerror(errno));
- goto cleanup;
+ return;
}
/* no more events right now */
- goto cleanup;
+ return;
}
/* Loop over all events in the buffer */
@@ -142,9 +141,6 @@ static void qemu_file_monitor_watch(void *arg)
}
}
}
-
- cleanup:
- qemu_mutex_unlock(&mon->lock);
}
@@ -250,7 +246,8 @@ qemu_file_monitor_add_watch(QFileMonitor *mon,
QFileMonitorWatch watch;
int64_t ret = -1;
- qemu_mutex_lock(&mon->lock);
+ QEMU_LOCK_GUARD(&mon->lock);
+
dir = g_hash_table_lookup(mon->dirs, dirpath);
if (!dir) {
int rv = inotify_add_watch(mon->fd, dirpath,
@@ -259,7 +256,7 @@ qemu_file_monitor_add_watch(QFileMonitor *mon,
if (rv < 0) {
error_setg_errno(errp, errno, "Unable to watch '%s'", dirpath);
- goto cleanup;
+ return ret;
}
trace_qemu_file_monitor_enable_watch(mon, dirpath, rv);
@@ -290,8 +287,6 @@ qemu_file_monitor_add_watch(QFileMonitor *mon,
ret = watch.id;
- cleanup:
- qemu_mutex_unlock(&mon->lock);
return ret;
}
@@ -303,13 +298,13 @@ void qemu_file_monitor_remove_watch(QFileMonitor *mon,
QFileMonitorDir *dir;
gsize i;
- qemu_mutex_lock(&mon->lock);
+ QEMU_LOCK_GUARD(&mon->lock);
trace_qemu_file_monitor_remove_watch(mon, dirpath, id);
dir = g_hash_table_lookup(mon->dirs, dirpath);
if (!dir) {
- goto cleanup;
+ return;
}
for (i = 0; i < dir->watches->len; i++) {
@@ -333,7 +328,4 @@ void qemu_file_monitor_remove_watch(QFileMonitor *mon,
qemu_set_fd_handler(mon->fd, NULL, NULL, NULL);
}
}
-
- cleanup:
- qemu_mutex_unlock(&mon->lock);
}
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index 97dfa3fd57..dc05755ef1 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -748,41 +748,41 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
assert(QEMU_PTR_IS_ALIGNED(host, qemu_real_host_page_size));
assert(QEMU_IS_ALIGNED(size, qemu_real_host_page_size));
trace_qemu_vfio_dma_map(s, host, size, temporary, iova);
- qemu_mutex_lock(&s->lock);
+ QEMU_LOCK_GUARD(&s->lock);
mapping = qemu_vfio_find_mapping(s, host, &index);
if (mapping) {
iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
} else {
if (s->high_water_mark - s->low_water_mark + 1 < size) {
ret = -ENOMEM;
- goto out;
+ return ret;
}
if (!temporary) {
if (qemu_vfio_find_fixed_iova(s, size, &iova0)) {
ret = -ENOMEM;
- goto out;
+ return ret;
}
mapping = qemu_vfio_add_mapping(s, host, size, index + 1, iova0);
if (!mapping) {
ret = -ENOMEM;
- goto out;
+ return ret;
}
assert(qemu_vfio_verify_mappings(s));
ret = qemu_vfio_do_mapping(s, host, size, iova0);
if (ret) {
qemu_vfio_undo_mapping(s, mapping, NULL);
- goto out;
+ return ret;
}
qemu_vfio_dump_mappings(s);
} else {
if (qemu_vfio_find_temp_iova(s, size, &iova0)) {
ret = -ENOMEM;
- goto out;
+ return ret;
}
ret = qemu_vfio_do_mapping(s, host, size, iova0);
if (ret) {
- goto out;
+ return ret;
}
}
}
@@ -790,8 +790,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
if (iova) {
*iova = iova0;
}
-out:
- qemu_mutex_unlock(&s->lock);
+
return ret;
}
@@ -826,14 +825,12 @@ void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host)
}
trace_qemu_vfio_dma_unmap(s, host);
- qemu_mutex_lock(&s->lock);
+ QEMU_LOCK_GUARD(&s->lock);
m = qemu_vfio_find_mapping(s, host, &index);
if (!m) {
- goto out;
+ return;
}
qemu_vfio_undo_mapping(s, m, NULL);
-out:
- qemu_mutex_unlock(&s->lock);
}
static void qemu_vfio_reset(QEMUVFIOState *s)
--
2.25.1
next prev parent reply other threads:[~2021-03-11 9:31 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-11 3:15 [PATCH 0/9] Changing qemu_mutex_locks to lock guard macros Mahmoud Mandour
2021-03-11 3:15 ` [PATCH 1/9] tpm: Changed a qemu_mutex_lock to QEMU_LOCK_GUARD Mahmoud Mandour
2021-03-11 10:04 ` Marc-André Lureau
2021-03-23 2:58 ` Stefan Berger
2021-03-11 3:15 ` [PATCH 2/9] block: Replaced qemu_mutex_lock calls with QEMU_LOCK_GUARD Mahmoud Mandour
2021-03-12 10:23 ` Vladimir Sementsov-Ogievskiy
2021-03-13 5:51 ` Mahmoud Mandour
2021-03-15 14:08 ` Vladimir Sementsov-Ogievskiy
2021-03-16 13:29 ` Eric Blake
2021-03-11 3:15 ` [PATCH 3/9] char: Replaced a qemu_mutex_lock " Mahmoud Mandour
2021-03-11 10:05 ` Marc-André Lureau
2021-03-11 3:15 ` Mahmoud Mandour [this message]
2021-03-11 3:15 ` [PATCH 5/9] monitor: Replaced qemu_mutex_lock calls " Mahmoud Mandour
2021-03-11 9:50 ` Dr. David Alan Gilbert
2021-03-11 3:15 ` [PATCH 6/9] migration: " Mahmoud Mandour
2021-03-11 9:44 ` Dr. David Alan Gilbert
2021-03-15 18:01 ` Dr. David Alan Gilbert
2021-03-11 3:15 ` [PATCH 7/9] virtio-iommu: " Mahmoud Mandour
2021-03-11 3:15 ` [PATCH 8/9] hw/9pfs/9p-synth: Replaced qemu_mutex_lock " Mahmoud Mandour
2021-03-11 7:43 ` Greg Kurz
2021-03-11 10:49 ` Christian Schoenebeck
2021-03-11 11:52 ` Greg Kurz
2021-03-11 11:59 ` Christian Schoenebeck
2021-03-13 5:43 ` Mahmoud Mandour
2021-03-13 7:51 ` Greg Kurz
2021-03-15 16:07 ` Christian Schoenebeck
2021-03-15 20:31 ` Greg Kurz
2021-03-11 3:15 ` [PATCH 9/9] hw/hyperv/vmbus: replaced " Mahmoud Mandour
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=20210311031538.5325-5-ma.mandourr@gmail.com \
--to=ma.mandourr@gmail.com \
--cc=berrange@redhat.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).