From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-stable@nongnu.org, jcody@redhat.com, rjones@redhat.com
Subject: [Qemu-devel] [PATCH 4/4] curl: improve search for unused CURLState
Date: Tue, 9 May 2017 11:35:49 +0200 [thread overview]
Message-ID: <20170509093549.25157-5-pbonzini@redhat.com> (raw)
In-Reply-To: <20170509093549.25157-1-pbonzini@redhat.com>
The main change here is to pull the search loop to a new function,
making it easier to switch from aio_poll to BDRV_POLL_WHILE.
However, the "for (j...)" loop is also dead (there is no other
read of "j" outside the loop), so remove it.
Cc: jcody@redhat.com
Cc: qemu-stable@nongnu.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
block/curl.c | 52 ++++++++++++++++++++++++++++++++--------------------
1 file changed, 32 insertions(+), 20 deletions(-)
diff --git a/block/curl.c b/block/curl.c
index e8fcc5ca34..79e504a2cc 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -455,29 +455,41 @@ static void curl_multi_timeout_do(void *arg)
}
/* Called with s->mutex held. */
+static bool curl_find_unused_state_locked(BDRVCURLState *s, CURLState **state)
+{
+ int i;
+
+ for (i = 0; i < CURL_NUM_STATES; i++) {
+ if (!s->states[i].in_use) {
+ s->states[i].in_use = 1;
+ *state = &s->states[i];
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool curl_find_unused_state(BDRVCURLState *s, CURLState **state)
+{
+ bool ret;
+
+ qemu_mutex_lock(&s->mutex);
+ ret = curl_find_unused_state_locked(s, state);
+ qemu_mutex_unlock(&s->mutex);
+ return ret;
+}
+
+/* Called with s->mutex held. */
static CURLState *curl_init_state(BlockDriverState *bs, BDRVCURLState *s)
{
CURLState *state = NULL;
- int i, j;
-
- do {
- for (i=0; i<CURL_NUM_STATES; i++) {
- for (j=0; j<CURL_NUM_ACB; j++)
- if (s->states[i].acb[j])
- continue;
- if (s->states[i].in_use)
- continue;
-
- state = &s->states[i];
- state->in_use = 1;
- break;
- }
- if (!state) {
- qemu_mutex_unlock(&s->mutex);
- aio_poll(bdrv_get_aio_context(bs), true);
- qemu_mutex_lock(&s->mutex);
- }
- } while(!state);
+
+ if (!curl_find_unused_state_locked(s, &state)) {
+ qemu_mutex_unlock(&s->mutex);
+ BDRV_POLL_WHILE(bs, !curl_find_unused_state(s, &state));
+ qemu_mutex_lock(&s->mutex);
+ }
if (!state->curl) {
state->curl = curl_easy_init();
--
2.12.2
next prev parent reply other threads:[~2017-05-09 9:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-09 9:35 [Qemu-devel] [PATCH 0/4] curl: locking cleanups and fixes Paolo Bonzini
2017-05-09 9:35 ` [Qemu-devel] [PATCH 1/4] curl: strengthen assertion in curl_clean_state Paolo Bonzini
2017-05-09 9:35 ` [Qemu-devel] [PATCH 2/4] curl: never invoke callbacks with s->mutex held Paolo Bonzini
2017-05-09 9:35 ` [Qemu-devel] [PATCH 3/4] curl: avoid recursive locking of BDRVCURLState mutex Paolo Bonzini
2017-05-09 9:35 ` Paolo Bonzini [this message]
2017-05-09 10:15 ` [Qemu-devel] [PATCH 0/4] curl: locking cleanups and fixes Richard W.M. Jones
2017-05-09 16:03 ` Jeff Cody
2017-05-09 16:06 ` Paolo Bonzini
2017-05-09 16:15 ` Richard W.M. Jones
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=20170509093549.25157-5-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=jcody@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=rjones@redhat.com \
/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).