From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, jsnow@redhat.com, jcody@redhat.com,
qemu-block@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v4 12/21] mirror: Switch mirror_do_read() to byte-based
Date: Wed, 5 Jul 2017 16:08:33 -0500 [thread overview]
Message-ID: <20170705210842.960-13-eblake@redhat.com> (raw)
In-Reply-To: <20170705210842.960-1-eblake@redhat.com>
We are gradually converting to byte-based interfaces, as they are
easier to reason about than sector-based. Convert another internal
function (no semantic change).
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Reviewed-by: Jeff Cody <jcody@redhat.com>
---
v3-v4: no change
v2: rebase to earlier changes
---
block/mirror.c | 75 ++++++++++++++++++++++++++--------------------------------
1 file changed, 33 insertions(+), 42 deletions(-)
diff --git a/block/mirror.c b/block/mirror.c
index 374cefd..d3325d0 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -196,7 +196,7 @@ static inline int mirror_clip_sectors(MirrorBlockJob *s,
/* Round offset and/or bytes to target cluster if COW is needed, and
* return the offset of the adjusted tail against original. */
static int mirror_cow_align(MirrorBlockJob *s, int64_t *offset,
- unsigned int *bytes)
+ uint64_t *bytes)
{
bool need_cow;
int ret = 0;
@@ -204,6 +204,7 @@ static int mirror_cow_align(MirrorBlockJob *s, int64_t *offset,
unsigned int align_bytes = *bytes;
int max_bytes = s->granularity * s->max_iov;
+ assert(*bytes < INT_MAX);
need_cow = !test_bit(*offset / s->granularity, s->cow_bitmap);
need_cow |= !test_bit((*offset + *bytes - 1) / s->granularity,
s->cow_bitmap);
@@ -239,59 +240,50 @@ static inline void mirror_wait_for_io(MirrorBlockJob *s)
}
/* Submit async read while handling COW.
- * Returns: The number of sectors copied after and including sector_num,
- * excluding any sectors copied prior to sector_num due to alignment.
- * This will be nb_sectors if no alignment is necessary, or
- * (new_end - sector_num) if tail is rounded up or down due to
+ * Returns: The number of bytes copied after and including offset,
+ * excluding any bytes copied prior to offset due to alignment.
+ * This will be @bytes if no alignment is necessary, or
+ * (new_end - offset) if tail is rounded up or down due to
* alignment or buffer limit.
*/
-static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num,
- int nb_sectors)
+static uint64_t mirror_do_read(MirrorBlockJob *s, int64_t offset,
+ uint64_t bytes)
{
BlockBackend *source = s->common.blk;
- int sectors_per_chunk, nb_chunks;
- int ret;
+ int nb_chunks;
+ uint64_t ret;
MirrorOp *op;
- int max_sectors;
+ uint64_t max_bytes;
- sectors_per_chunk = s->granularity >> BDRV_SECTOR_BITS;
- max_sectors = sectors_per_chunk * s->max_iov;
+ max_bytes = s->granularity * s->max_iov;
/* We can only handle as much as buf_size at a time. */
- nb_sectors = MIN(s->buf_size >> BDRV_SECTOR_BITS, nb_sectors);
- nb_sectors = MIN(max_sectors, nb_sectors);
- assert(nb_sectors);
- assert(nb_sectors < BDRV_REQUEST_MAX_SECTORS);
- ret = nb_sectors;
+ bytes = MIN(s->buf_size, MIN(max_bytes, bytes));
+ assert(bytes);
+ assert(bytes < BDRV_REQUEST_MAX_BYTES);
+ ret = bytes;
if (s->cow_bitmap) {
- int64_t offset = sector_num * BDRV_SECTOR_SIZE;
- unsigned int bytes = nb_sectors * BDRV_SECTOR_SIZE;
- int gap;
-
- gap = mirror_cow_align(s, &offset, &bytes);
- sector_num = offset / BDRV_SECTOR_SIZE;
- nb_sectors = bytes / BDRV_SECTOR_SIZE;
- ret += gap / BDRV_SECTOR_SIZE;
+ ret += mirror_cow_align(s, &offset, &bytes);
}
- assert(nb_sectors << BDRV_SECTOR_BITS <= s->buf_size);
- /* The sector range must meet granularity because:
+ assert(bytes <= s->buf_size);
+ /* The range will be sector-aligned because:
* 1) Caller passes in aligned values;
- * 2) mirror_cow_align is used only when target cluster is larger. */
- assert(!(sector_num % sectors_per_chunk));
- nb_chunks = DIV_ROUND_UP(nb_sectors, sectors_per_chunk);
+ * 2) mirror_cow_align is used only when target cluster is larger.
+ * But it might not be cluster-aligned at end-of-file. */
+ assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE));
+ nb_chunks = DIV_ROUND_UP(bytes, s->granularity);
while (s->buf_free_count < nb_chunks) {
- trace_mirror_yield_in_flight(s, sector_num * BDRV_SECTOR_SIZE,
- s->in_flight);
+ trace_mirror_yield_in_flight(s, offset, s->in_flight);
mirror_wait_for_io(s);
}
/* Allocate a MirrorOp that is used as an AIO callback. */
op = g_new(MirrorOp, 1);
op->s = s;
- op->offset = sector_num * BDRV_SECTOR_SIZE;
- op->bytes = nb_sectors * BDRV_SECTOR_SIZE;
+ op->offset = offset;
+ op->bytes = bytes;
/* Now make a QEMUIOVector taking enough granularity-sized chunks
* from s->buf_free.
@@ -299,7 +291,7 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num,
qemu_iovec_init(&op->qiov, nb_chunks);
while (nb_chunks-- > 0) {
MirrorBuffer *buf = QSIMPLEQ_FIRST(&s->buf_free);
- size_t remaining = nb_sectors * BDRV_SECTOR_SIZE - op->qiov.size;
+ size_t remaining = bytes - op->qiov.size;
QSIMPLEQ_REMOVE_HEAD(&s->buf_free, next);
s->buf_free_count--;
@@ -308,12 +300,10 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num,
/* Copy the dirty cluster. */
s->in_flight++;
- s->bytes_in_flight += nb_sectors * BDRV_SECTOR_SIZE;
- trace_mirror_one_iteration(s, sector_num * BDRV_SECTOR_SIZE,
- nb_sectors * BDRV_SECTOR_SIZE);
+ s->bytes_in_flight += bytes;
+ trace_mirror_one_iteration(s, offset, bytes);
- blk_aio_preadv(source, sector_num * BDRV_SECTOR_SIZE, &op->qiov, 0,
- mirror_read_complete, op);
+ blk_aio_preadv(source, offset, &op->qiov, 0, mirror_read_complete, op);
return ret;
}
@@ -461,8 +451,9 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s)
io_sectors = mirror_clip_sectors(s, sector_num, io_sectors);
switch (mirror_method) {
case MIRROR_METHOD_COPY:
- io_sectors = mirror_do_read(s, sector_num, io_sectors);
- io_bytes_acct = io_sectors * BDRV_SECTOR_SIZE;
+ io_bytes_acct = mirror_do_read(s, sector_num * BDRV_SECTOR_SIZE,
+ io_sectors * BDRV_SECTOR_SIZE);
+ io_sectors = io_bytes_acct / BDRV_SECTOR_SIZE;
break;
case MIRROR_METHOD_ZERO:
case MIRROR_METHOD_DISCARD:
--
2.9.4
next prev parent reply other threads:[~2017-07-05 21:09 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-05 21:08 [Qemu-devel] [PATCH v4 00/21] make bdrv_is_allocated[_above] byte-based Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 01/21] blockjob: Track job ratelimits via bytes, not sectors Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 02/21] trace: Show blockjob actions " Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 03/21] stream: Switch stream_populate() to byte-based Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 04/21] stream: Drop reached_end for stream_complete() Eric Blake
2017-07-06 0:05 ` John Snow
2017-07-06 10:38 ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 05/21] stream: Switch stream_run() to byte-based Eric Blake
2017-07-06 10:39 ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 06/21] commit: Switch commit_populate() " Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 07/21] commit: Switch commit_run() " Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 08/21] mirror: Switch MirrorBlockJob " Eric Blake
2017-07-06 0:14 ` John Snow
2017-07-06 10:42 ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 09/21] mirror: Switch mirror_do_zero_or_discard() " Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 10/21] mirror: Update signature of mirror_clip_sectors() Eric Blake
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 11/21] mirror: Switch mirror_cow_align() to byte-based Eric Blake
2017-07-06 11:16 ` Kevin Wolf
2017-07-05 21:08 ` Eric Blake [this message]
2017-07-06 13:30 ` [Qemu-devel] [PATCH v4 12/21] mirror: Switch mirror_do_read() " Kevin Wolf
2017-07-06 14:25 ` Eric Blake
2017-07-06 14:55 ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 13/21] mirror: Switch mirror_iteration() " Eric Blake
2017-07-06 13:47 ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 14/21] block: Drop unused bdrv_round_sectors_to_clusters() Eric Blake
2017-07-06 13:49 ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 15/21] backup: Switch BackupBlockJob to byte-based Eric Blake
2017-07-06 13:59 ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 16/21] backup: Switch block_backup.h " Eric Blake
2017-07-06 14:11 ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 17/21] backup: Switch backup_do_cow() " Eric Blake
2017-07-06 14:36 ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 18/21] backup: Switch backup_run() " Eric Blake
2017-07-06 14:43 ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 19/21] block: Make bdrv_is_allocated() byte-based Eric Blake
2017-07-06 16:02 ` Kevin Wolf
2017-07-06 16:24 ` Eric Blake
2017-07-07 2:55 ` Eric Blake
2017-07-07 9:25 ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 20/21] block: Minimize raw use of bds->total_sectors Eric Blake
2017-07-06 0:23 ` John Snow
2017-07-06 16:48 ` Kevin Wolf
2017-07-06 17:03 ` Eric Blake
2017-07-06 17:27 ` Kevin Wolf
2017-07-05 21:08 ` [Qemu-devel] [PATCH v4 21/21] block: Make bdrv_is_allocated_above() byte-based Eric Blake
2017-07-06 17:13 ` 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=20170705210842.960-13-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=jcody@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--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 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).