From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: qemu-block@nongnu.org, kwolf@redhat.com,
Jeff Cody <jcody@redhat.com>, Max Reitz <mreitz@redhat.com>,
Wen Congyang <wency@cn.fujitsu.com>,
Changlong Xie <xiecl.fnst@cn.fujitsu.com>
Subject: [Qemu-devel] [PATCH 13/17] backup: Switch block_backup.h to byte-based
Date: Tue, 11 Apr 2017 17:29:41 -0500 [thread overview]
Message-ID: <20170411222945.11741-14-eblake@redhat.com> (raw)
In-Reply-To: <20170411222945.11741-1-eblake@redhat.com>
We are gradually converting to byte-based interfaces, as they are
easier to reason about than sector-based. Continue by converting
the public interface to backup jobs (no semantic change), including
a change to CowRequest to track by bytes instead of cluster indices.
Signed-off-by: Eric Blake <eblake@redhat.com>
---
include/block/block_backup.h | 11 +++++------
block/backup.c | 29 ++++++++++++++---------------
block/replication.c | 12 ++++++++----
3 files changed, 27 insertions(+), 25 deletions(-)
diff --git a/include/block/block_backup.h b/include/block/block_backup.h
index 8a75947..994a3bd 100644
--- a/include/block/block_backup.h
+++ b/include/block/block_backup.h
@@ -21,17 +21,16 @@
#include "block/block_int.h"
typedef struct CowRequest {
- int64_t start;
- int64_t end;
+ int64_t start_byte;
+ int64_t end_byte;
QLIST_ENTRY(CowRequest) list;
CoQueue wait_queue; /* coroutines blocked on this request */
} CowRequest;
-void backup_wait_for_overlapping_requests(BlockJob *job, int64_t sector_num,
- int nb_sectors);
+void backup_wait_for_overlapping_requests(BlockJob *job, int64_t offset,
+ uint64_t bytes);
void backup_cow_request_begin(CowRequest *req, BlockJob *job,
- int64_t sector_num,
- int nb_sectors);
+ int64_t offset, uint64_t bytes);
void backup_cow_request_end(CowRequest *req);
void backup_do_checkpoint(BlockJob *job, Error **errp);
diff --git a/block/backup.c b/block/backup.c
index a64a162..0502c1a 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -64,7 +64,7 @@ static void coroutine_fn wait_for_overlapping_requests(BackupBlockJob *job,
do {
retry = false;
QLIST_FOREACH(req, &job->inflight_reqs, list) {
- if (end > req->start && start < req->end) {
+ if (end > req->start_byte && start < req->end_byte) {
qemu_co_queue_wait(&req->wait_queue, NULL);
retry = true;
break;
@@ -77,8 +77,8 @@ static void coroutine_fn wait_for_overlapping_requests(BackupBlockJob *job,
static void cow_request_begin(CowRequest *req, BackupBlockJob *job,
int64_t start, int64_t end)
{
- req->start = start;
- req->end = end;
+ req->start_byte = start;
+ req->end_byte = end;
qemu_co_queue_init(&req->wait_queue);
QLIST_INSERT_HEAD(&job->inflight_reqs, req, list);
}
@@ -114,8 +114,10 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *job,
sector_num * BDRV_SECTOR_SIZE,
nb_sectors * BDRV_SECTOR_SIZE);
- wait_for_overlapping_requests(job, start, end);
- cow_request_begin(&cow_request, job, start, end);
+ wait_for_overlapping_requests(job, start * job->cluster_size,
+ end * job->cluster_size);
+ cow_request_begin(&cow_request, job, start * job->cluster_size,
+ end * job->cluster_size);
for (; start < end; start++) {
if (test_bit(start, job->done_bitmap)) {
@@ -277,32 +279,29 @@ void backup_do_checkpoint(BlockJob *job, Error **errp)
bitmap_zero(backup_job->done_bitmap, len);
}
-void backup_wait_for_overlapping_requests(BlockJob *job, int64_t sector_num,
- int nb_sectors)
+void backup_wait_for_overlapping_requests(BlockJob *job, int64_t offset,
+ uint64_t bytes)
{
BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common);
- int64_t sectors_per_cluster = cluster_size_sectors(backup_job);
int64_t start, end;
assert(job->driver->job_type == BLOCK_JOB_TYPE_BACKUP);
- start = sector_num / sectors_per_cluster;
- end = DIV_ROUND_UP(sector_num + nb_sectors, sectors_per_cluster);
+ start = QEMU_ALIGN_DOWN(offset, backup_job->cluster_size);
+ end = QEMU_ALIGN_UP(offset + bytes, backup_job->cluster_size);
wait_for_overlapping_requests(backup_job, start, end);
}
void backup_cow_request_begin(CowRequest *req, BlockJob *job,
- int64_t sector_num,
- int nb_sectors)
+ int64_t offset, uint64_t bytes)
{
BackupBlockJob *backup_job = container_of(job, BackupBlockJob, common);
- int64_t sectors_per_cluster = cluster_size_sectors(backup_job);
int64_t start, end;
assert(job->driver->job_type == BLOCK_JOB_TYPE_BACKUP);
- start = sector_num / sectors_per_cluster;
- end = DIV_ROUND_UP(sector_num + nb_sectors, sectors_per_cluster);
+ start = QEMU_ALIGN_DOWN(offset, backup_job->cluster_size);
+ end = QEMU_ALIGN_UP(offset + bytes, backup_job->cluster_size);
cow_request_begin(req, backup_job, start, end);
}
diff --git a/block/replication.c b/block/replication.c
index bf3c395..414ecc4 100644
--- a/block/replication.c
+++ b/block/replication.c
@@ -234,10 +234,14 @@ static coroutine_fn int replication_co_readv(BlockDriverState *bs,
}
if (job) {
- backup_wait_for_overlapping_requests(child->bs->job, sector_num,
- remaining_sectors);
- backup_cow_request_begin(&req, child->bs->job, sector_num,
- remaining_sectors);
+ uint64_t remaining_bytes = remaining_sectors * BDRV_SECTOR_SIZE;
+
+ backup_wait_for_overlapping_requests(child->bs->job,
+ sector_num * BDRV_SECTOR_SIZE,
+ remaining_bytes);
+ backup_cow_request_begin(&req, child->bs->job,
+ sector_num * BDRV_SECTOR_SIZE,
+ remaining_bytes);
ret = bdrv_co_readv(bs->file, sector_num, remaining_sectors,
qiov);
backup_cow_request_end(&req);
--
2.9.3
next prev parent reply other threads:[~2017-04-11 22:30 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-11 22:29 [Qemu-devel] [PATCH 00/17] make bdrv_is_allocated[_above] byte-based Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 01/17] blockjob: Track job ratelimits via bytes, not sectors Eric Blake
2017-04-17 19:18 ` [Qemu-devel] [Qemu-block] " John Snow
2017-04-17 19:51 ` Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 02/17] trace: Show blockjob actions " Eric Blake
2017-04-17 19:18 ` [Qemu-devel] [Qemu-block] " John Snow
2017-04-17 19:55 ` Eric Blake
2017-04-19 9:12 ` Stefan Hajnoczi
2017-04-11 22:29 ` [Qemu-devel] [PATCH 03/17] stream: Switch stream_populate() to byte-based Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 04/17] stream: Switch stream_run() " Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 05/17] commit: Switch commit_populate() " Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 06/17] commit: Switch commit_run() " Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 07/17] mirror: Switch MirrorBlockJob " Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 08/17] mirror: Switch mirror_do_zero_or_discard() " Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 09/17] mirror: Switch mirror_cow_align() " Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 10/17] mirror: Switch mirror_do_read() " Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 11/17] mirror: Switch mirror_iteration() " Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 12/17] backup: Switch BackupBlockJob " Eric Blake
2017-04-11 22:29 ` Eric Blake [this message]
2017-04-17 23:24 ` [Qemu-devel] [Qemu-block] [PATCH 13/17] backup: Switch block_backup.h " John Snow
2017-04-18 0:54 ` Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 14/17] backup: Switch backup_do_cow() " Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 15/17] backup: Switch backup_run() " Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 16/17] block: Make bdrv_is_allocated() byte-based Eric Blake
2017-04-18 22:15 ` [Qemu-devel] [Qemu-block] " John Snow
2017-04-19 17:54 ` Eric Blake
2017-04-19 19:37 ` John Snow
2017-04-19 20:32 ` John Snow
2017-04-19 21:12 ` Eric Blake
2017-04-19 21:40 ` John Snow
2017-05-10 22:33 ` Eric Blake
2017-04-11 22:29 ` [Qemu-devel] [PATCH 17/17] block: Make bdrv_is_allocated_above() byte-based Eric Blake
2017-04-24 23:06 ` [Qemu-devel] [Qemu-block] " John Snow
2017-04-25 1:48 ` Eric Blake
2017-05-10 15:42 ` Eric Blake
2017-05-10 22:11 ` Eric Blake
2017-04-17 23:42 ` [Qemu-devel] [Qemu-block] [PATCH 00/17] make bdrv_is_allocated[_above] byte-based John Snow
2017-04-18 1:04 ` Eric Blake
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=20170411222945.11741-14-eblake@redhat.com \
--to=eblake@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=wency@cn.fujitsu.com \
--cc=xiecl.fnst@cn.fujitsu.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).