[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 035/100] backup: Switch block_backup.h to byte-based
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PULL 035/100] backup: Switch block_backup.h to byte-based |
Date: |
Fri, 7 Jul 2017 19:07:50 +0200 |
From: Eric Blake <address@hidden>
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.
Note that this does not change the difference between the public
interface (starting point, and size of the subsequent range) and
the internal interface (starting and end points).
Signed-off-by: Eric Blake <address@hidden>
Reviewed-by: John Snow <address@hidden>
Reviewed-by: Xie Changlong <address@hidden>
Reviewed-by: Jeff Cody <address@hidden>
Reviewed-by: Kevin Wolf <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/backup.c | 31 +++++++++++++++----------------
block/replication.c | 12 ++++++++----
include/block/block_backup.h | 11 +++++------
3 files changed, 28 insertions(+), 26 deletions(-)
diff --git a/block/backup.c b/block/backup.c
index 4e64710..503fbec 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;
@@ -75,10 +75,10 @@ static void coroutine_fn
wait_for_overlapping_requests(BackupBlockJob *job,
/* Keep track of an in-flight request */
static void cow_request_begin(CowRequest *req, BackupBlockJob *job,
- int64_t start, int64_t end)
+ 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 3885f04..8f3aba7 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);
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);
--
1.8.3.1
- [Qemu-block] [PULL 028/100] mirror: Switch mirror_do_zero_or_discard() to byte-based, (continued)
- [Qemu-block] [PULL 028/100] mirror: Switch mirror_do_zero_or_discard() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 026/100] commit: Switch commit_run() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 029/100] mirror: Update signature of mirror_clip_sectors(), Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 027/100] mirror: Switch MirrorBlockJob to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 030/100] mirror: Switch mirror_cow_align() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 031/100] mirror: Switch mirror_do_read() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 032/100] mirror: Switch mirror_iteration() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 033/100] block: Drop unused bdrv_round_sectors_to_clusters(), Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 034/100] backup: Switch BackupBlockJob to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 037/100] backup: Switch backup_run() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 035/100] backup: Switch block_backup.h to byte-based,
Kevin Wolf <=
- [Qemu-block] [PULL 036/100] backup: Switch backup_do_cow() to byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 039/100] block: Minimize raw use of bds->total_sectors, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 040/100] block: Make bdrv_is_allocated_above() byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 038/100] block: Make bdrv_is_allocated() byte-based, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 044/100] qcow: require image size to be > 1 for new images, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 042/100] block: add ability to set a prefix for opt names, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 043/100] qcow: document another weakness of qcow AES encryption, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 046/100] iotests: skip 048 with qcow which doesn't support resize, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 041/100] block: expose crypto option names / defs to other drivers, Kevin Wolf, 2017/07/07
- [Qemu-block] [PULL 045/100] iotests: skip 042 with qcow which dosn't support zero sized images, Kevin Wolf, 2017/07/07