From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: famz@redhat.com, stefanha@redhat.com, jcody@redhat.com,
mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com,
den@openvz.org, eblake@redhat.com
Subject: [Qemu-devel] [PATCH v4 10/11] block/backup: tiny refactor backup_job_create
Date: Mon, 15 Oct 2018 19:06:32 +0300 [thread overview]
Message-ID: <20181015160633.63130-11-vsementsov@virtuozzo.com> (raw)
In-Reply-To: <20181015160633.63130-1-vsementsov@virtuozzo.com>
Move copy-bitmap find/create code. It's needed for the following
commit, as we'll need copy_bitmap before actual block job creation. Do
it in a separate commit to simplify review.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
block/backup.c | 67 ++++++++++++++++++++++++++++----------------------
1 file changed, 38 insertions(+), 29 deletions(-)
diff --git a/block/backup.c b/block/backup.c
index 0b3fddeb6c..eda6f22318 100644
--- a/block/backup.c
+++ b/block/backup.c
@@ -561,6 +561,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
BlockDriverInfo bdi;
BackupBlockJob *job = NULL;
int ret;
+ int64_t cluster_size;
+ HBitmap *copy_bitmap = NULL;
assert(bs);
assert(target);
@@ -615,6 +617,33 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
return NULL;
}
+ /* If there is no backing file on the target, we cannot rely on COW if our
+ * backup cluster size is smaller than the target cluster size. Even for
+ * targets with a backing file, try to avoid COW if possible. */
+ ret = bdrv_get_info(target, &bdi);
+ if (ret == -ENOTSUP && !target->backing) {
+ /* Cluster size is not defined */
+ warn_report("The target block device doesn't provide "
+ "information about the block size and it doesn't have a "
+ "backing file. The default block size of %u bytes is "
+ "used. If the actual block size of the target exceeds "
+ "this default, the backup may be unusable",
+ BACKUP_CLUSTER_SIZE_DEFAULT);
+ cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
+ } else if (ret < 0 && !target->backing) {
+ error_setg_errno(errp, -ret,
+ "Couldn't determine the cluster size of the target image, "
+ "which has no backing file");
+ error_append_hint(errp,
+ "Aborting, since this may create an unusable destination image\n");
+ return NULL;
+ } else if (ret < 0 && target->backing) {
+ /* Not fatal; just trudge on ahead. */
+ cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
+ } else {
+ cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
+ }
+
len = bdrv_getlength(bs);
if (len < 0) {
error_setg_errno(errp, -len, "unable to get length for '%s'",
@@ -622,6 +651,8 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
goto error;
}
+ copy_bitmap = hbitmap_alloc(len, ctz32(cluster_size));
+
/* job->len is fixed, so we can't allow resize */
job = block_job_create(job_id, &backup_job_driver, txn, bs,
BLK_PERM_CONSISTENT_READ,
@@ -650,35 +681,9 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
/* Detect image-fleecing (and similar) schemes */
job->serialize_target_writes = bdrv_chain_contains(target, bs);
-
- /* If there is no backing file on the target, we cannot rely on COW if our
- * backup cluster size is smaller than the target cluster size. Even for
- * targets with a backing file, try to avoid COW if possible. */
- ret = bdrv_get_info(target, &bdi);
- if (ret == -ENOTSUP && !target->backing) {
- /* Cluster size is not defined */
- warn_report("The target block device doesn't provide "
- "information about the block size and it doesn't have a "
- "backing file. The default block size of %u bytes is "
- "used. If the actual block size of the target exceeds "
- "this default, the backup may be unusable",
- BACKUP_CLUSTER_SIZE_DEFAULT);
- job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
- } else if (ret < 0 && !target->backing) {
- error_setg_errno(errp, -ret,
- "Couldn't determine the cluster size of the target image, "
- "which has no backing file");
- error_append_hint(errp,
- "Aborting, since this may create an unusable destination image\n");
- goto error;
- } else if (ret < 0 && target->backing) {
- /* Not fatal; just trudge on ahead. */
- job->cluster_size = BACKUP_CLUSTER_SIZE_DEFAULT;
- } else {
- job->cluster_size = MAX(BACKUP_CLUSTER_SIZE_DEFAULT, bdi.cluster_size);
- }
-
- job->copy_bitmap = hbitmap_alloc(len, ctz32(job->cluster_size));
+ job->cluster_size = cluster_size;
+ job->copy_bitmap = copy_bitmap;
+ copy_bitmap = NULL;
job->use_copy_range = true;
job->copy_range_size = MIN_NON_ZERO(blk_get_max_transfer(job->common.blk),
blk_get_max_transfer(job->target));
@@ -694,6 +699,10 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
return &job->common;
error:
+ if (copy_bitmap) {
+ assert(!job || !job->copy_bitmap);
+ hbitmap_free(copy_bitmap);
+ }
if (sync_bitmap) {
bdrv_reclaim_dirty_bitmap(bs, sync_bitmap, NULL);
}
--
2.18.0
next prev parent reply other threads:[~2018-10-15 16:06 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-15 16:06 [Qemu-devel] [PATCH v4 00/11] backup-top filter driver for backup Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 01/11] block/backup: simplify backup_incremental_init_copy_bitmap Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 02/11] block/backup: move to copy_bitmap with granularity Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 03/11] block: allow serialized reads to intersect Vladimir Sementsov-Ogievskiy
2018-11-06 17:57 ` Kevin Wolf
2018-11-07 10:08 ` Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 04/11] block: improve should_update_child Vladimir Sementsov-Ogievskiy
2018-11-06 18:09 ` Kevin Wolf
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 05/11] iotests: handle -f argument correctly for qemu_io_silent Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 06/11] iotests: allow resume_drive by node name Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 07/11] iotests: prepare 055 to graph changes during backup job Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 08/11] block: introduce backup-top filter driver Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 09/11] block: add lock/unlock range functions Vladimir Sementsov-Ogievskiy
2018-10-15 16:06 ` Vladimir Sementsov-Ogievskiy [this message]
2018-10-15 16:06 ` [Qemu-devel] [PATCH v4 11/11] block/backup: use backup-top instead of write notifiers Vladimir Sementsov-Ogievskiy
2018-11-06 17:35 ` Kevin Wolf
2018-11-02 16:41 ` [Qemu-devel] ping Re: [PATCH v4 00/11] backup-top filter driver for backup Vladimir Sementsov-Ogievskiy
2018-11-06 17:21 ` Kevin Wolf
2018-11-06 22:35 ` [Qemu-devel] [Qemu-block] " John Snow
2018-11-07 10:16 ` Vladimir Sementsov-Ogievskiy
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=20181015160633.63130-11-vsementsov@virtuozzo.com \
--to=vsementsov@virtuozzo.com \
--cc=den@openvz.org \
--cc=eblake@redhat.com \
--cc=famz@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=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).