From: Kevin Wolf <kwolf@redhat.com>
To: anthony@codemonkey.ws
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 6/9] qcow2: Don't hold cache references across yield
Date: Wed, 2 May 2012 19:16:15 +0200 [thread overview]
Message-ID: <1335978978-4940-7-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1335978978-4940-1-git-send-email-kwolf@redhat.com>
If cache references are held while the coroutine has yielded, the cache
may get used up and abort() when it can't find a free entry.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/qcow2-cluster.c | 21 +++++++++++++--------
1 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 7edc043..353889d 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -853,6 +853,7 @@ int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
n_start, n_end);
/* Find L2 entry for the first involved cluster */
+again:
ret = get_cluster_table(bs, offset, &l2_table, &l2_index);
if (ret < 0) {
return ret;
@@ -862,7 +863,6 @@ int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
* Calculate the number of clusters to look for. We stop at L2 table
* boundaries to keep things simple.
*/
-again:
nb_clusters = MIN(size_to_clusters(s, n_end << BDRV_SECTOR_BITS),
s->l2_size - l2_index);
@@ -896,6 +896,18 @@ again:
cluster_offset &= L2E_OFFSET_MASK;
+ /*
+ * The L2 table isn't used any more after this. As long as the cache works
+ * synchronously, it's important to release it before calling
+ * do_alloc_cluster_offset, which may yield if we need to wait for another
+ * request to complete. If we still had the reference, we could use up the
+ * whole cache with sleeping requests.
+ */
+ ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
+ if (ret < 0) {
+ return ret;
+ }
+
/* If there is something left to allocate, do that now */
*m = (QCowL2Meta) {
.cluster_offset = cluster_offset,
@@ -947,11 +959,6 @@ again:
}
/* Some cleanup work */
- ret = qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
- if (ret < 0) {
- goto fail_put;
- }
-
sectors = (keep_clusters + nb_clusters) << (s->cluster_bits - 9);
if (sectors > n_end) {
sectors = n_end;
@@ -963,8 +970,6 @@ again:
return 0;
fail:
- qcow2_cache_put(bs, s->l2_table_cache, (void**) &l2_table);
-fail_put:
if (m->nb_clusters > 0) {
QLIST_REMOVE(m, next_in_flight);
}
--
1.7.6.5
next prev parent reply other threads:[~2012-05-02 18:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-02 17:16 [Qemu-devel] [PULL 0/9] Block patches (master and 1.1) Kevin Wolf
2012-05-02 17:16 ` [Qemu-devel] [PATCH 1/9] qemu-iotests: ignore fragmentation information for qed Kevin Wolf
2012-05-02 17:16 ` [Qemu-devel] [PATCH 2/9] block/qcow2: Add missing GCC_FMT_ATTR to function report_unsupported() Kevin Wolf
2012-05-02 17:16 ` [Qemu-devel] [PATCH 3/9] docs: fix one issue in qcow2 specs Kevin Wolf
2012-05-02 17:16 ` [Qemu-devel] [PATCH 4/9] qemu-iotests: Many parallel allocating I/O requests Kevin Wolf
2012-05-02 17:16 ` [Qemu-devel] [PATCH 5/9] qcow2: Remove unused parameter in do_alloc_cluster_offset Kevin Wolf
2012-05-02 17:16 ` Kevin Wolf [this message]
2012-05-02 17:16 ` [Qemu-devel] [PATCH 7/9] qcow2: fix the return value -ENOENT -> -EEXIST Kevin Wolf
2012-05-02 17:16 ` [Qemu-devel] [PATCH 8/9] rbd: add discard support Kevin Wolf
2012-05-02 17:16 ` [Qemu-devel] [PATCH 9/9] ATA: Allow WIN_SECURITY_FREEZE_LOCK as nop Kevin Wolf
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=1335978978-4940-7-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=anthony@codemonkey.ws \
--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).