From: Olaf Hering <olaf@aepfle.de>
To: Kevin Wolf <kwolf@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
qemu-block@nongnu.org, qemu-devel@nongnu.org,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] bogus bdrv_check_request in bdrv_co_discard
Date: Wed, 16 Mar 2016 11:18:40 +0100 [thread overview]
Message-ID: <20160316101840.GA9298@aepfle.de> (raw)
In-Reply-To: <20160309165026.GA14059@aepfle.de>
On Wed, Mar 09, Olaf Hering wrote:
> On Wed, Mar 09, Kevin Wolf wrote:
>
> > Removing integer overflow checks without removing the potentially
> > overflowing operation doesn't feel like a particularly good idea,
> > though.
>
> Why does the code use signed ints anyway for sectors and offset?!
Until this underlying bug is fixed a change like this works for me:
diff --git a/block/io.c b/block/io.c
index a69bfc4..df1e383 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2464,7 +2464,7 @@ static void coroutine_fn bdrv_discard_co_entry(void *opaque)
rwco->ret = bdrv_co_discard(rwco->bs, rwco->sector_num, rwco->nb_sectors);
}
-int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
+static int __bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
int nb_sectors)
{
BdrvTrackedRequest req;
@@ -2546,6 +2546,26 @@ out:
return ret;
}
+int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
+ int nb_sectors)
+{
+ int num, ret;
+ int limit = BDRV_REQUEST_MAX_SECTORS;
+ int remaining = nb_sectors;
+ int64_t sector_offset = sector_num;
+
+ do {
+ num = remaining > limit ? limit : remaining;
+ ret = __bdrv_co_discard(bs, sector_offset, num);
+ if (ret < 0)
+ break;
+ remaining -= num;
+ sector_offset += num;
+ } while (remaining > 0);
+
+ return ret;
+}
+
int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
{
Coroutine *co;
Olaf
prev parent reply other threads:[~2016-03-16 10:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-09 12:11 [Qemu-devel] bogus bdrv_check_request in bdrv_co_discard Olaf Hering
2016-03-09 12:29 ` Paolo Bonzini
[not found] ` <20160309144514.GA29027@aepfle.de>
2016-03-09 14:58 ` Kevin Wolf
2016-03-09 16:50 ` Olaf Hering
2016-03-09 17:03 ` Olaf Hering
2016-03-16 10:18 ` Olaf Hering [this message]
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=20160316101840.GA9298@aepfle.de \
--to=olaf@aepfle.de \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@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).