From: John Snow <jsnow@redhat.com>
To: qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>,
vsementsov@virtuozzo.com, Markus Armbruster <armbru@redhat.com>,
Max Reitz <mreitz@redhat.com>, John Snow <jsnow@redhat.com>
Subject: [Qemu-devel] [PATCH 5/5] block/qcow2-bitmap: Count queued bitmaps towards directory_size
Date: Thu, 6 Jun 2019 14:41:59 -0400 [thread overview]
Message-ID: <20190606184159.979-6-jsnow@redhat.com> (raw)
In-Reply-To: <20190606184159.979-1-jsnow@redhat.com>
Similarly to the previous commit, we need to also keep a ledger of the
additional directory size burden that we've not yet committed so we can
reject new additions sooner instead of later.
Signed-off-by: John Snow <jsnow@redhat.com>
---
block/qcow2.h | 1 +
block/qcow2-bitmap.c | 13 ++++++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/block/qcow2.h b/block/qcow2.h
index ebf60ac236..5aff97eb9c 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -318,6 +318,7 @@ typedef struct BDRVQcow2State {
uint32_t nb_bitmaps;
uint32_t nb_queued_bitmaps;
+ uint32_t queued_directory_size;
uint64_t bitmap_directory_size;
uint64_t bitmap_directory_offset;
diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c
index 7193c66787..b103fab362 100644
--- a/block/qcow2-bitmap.c
+++ b/block/qcow2-bitmap.c
@@ -1405,16 +1405,23 @@ static Qcow2Bitmap *find_bitmap_by_name(Qcow2BitmapList *bm_list,
static int qcow2_remove_queued_dirty_bitmap(
BlockDriverState *bs, const char *name, Error **errp)
{
+ uint32_t size_delta;
BDRVQcow2State *s = bs->opaque;
BdrvDirtyBitmap *bitmap = bdrv_find_dirty_bitmap(bs, name);
+
if (!bitmap) {
error_setg(errp, "Node '%s' has no stored or enqueued bitmap '%s'",
bdrv_get_node_name(bs), name);
return -ENOENT;
}
+
+ size_delta = calc_dir_entry_size(strlen(name), 0);
assert(s->nb_queued_bitmaps > 0);
assert(bdrv_dirty_bitmap_get_persistence(bitmap));
+ assert(s->queued_directory_size >= size_delta);
+
s->nb_queued_bitmaps -= 1;
+ s->queued_directory_size -= size_delta;
return 0;
}
@@ -1561,6 +1568,7 @@ void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **errp)
goto fail;
}
s->nb_queued_bitmaps = 0;
+ s->queued_directory_size = 0;
/* Bitmap directory was successfully updated, so, old data can be dropped.
* TODO it is better to reuse these clusters */
@@ -1636,6 +1644,7 @@ int qcow2_add_persistent_dirty_bitmap(BlockDriverState *bs,
const char *name = bdrv_dirty_bitmap_name(bitmap);
uint32_t granularity = bdrv_dirty_bitmap_granularity(bitmap);
uint32_t nb_bitmaps;
+ uint32_t size_delta;
int ret = 0;
if (s->qcow_version < 3) {
@@ -1666,7 +1675,8 @@ int qcow2_add_persistent_dirty_bitmap(BlockDriverState *bs,
goto fail;
}
- if (s->bitmap_directory_size + calc_dir_entry_size(strlen(name), 0) >
+ size_delta = calc_dir_entry_size(strlen(name), 0);
+ if (s->bitmap_directory_size + s->queued_directory_size + size_delta >
QCOW2_MAX_BITMAP_DIRECTORY_SIZE)
{
error_setg(errp, "Not enough space in the bitmap directory");
@@ -1687,6 +1697,7 @@ int qcow2_add_persistent_dirty_bitmap(BlockDriverState *bs,
}
s->nb_queued_bitmaps += 1;
+ s->queued_directory_size += size_delta;
return 0;
fail:
--
2.20.1
next prev parent reply other threads:[~2019-06-06 19:29 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-06 18:41 [Qemu-devel] [PATCH 0/5] block/dirty-bitmap: check number and size constraints against queued bitmaps John Snow
2019-06-06 18:41 ` [Qemu-devel] [PATCH 1/5] block/qcow2-bitmap: allow bitmap_list_load to return an error code John Snow
2019-06-07 2:07 ` Eric Blake
2019-06-07 12:36 ` Vladimir Sementsov-Ogievskiy
2019-06-06 18:41 ` [Qemu-devel] [PATCH 2/5] block/dirty-bitmap: Refactor bdrv_can_store_new_bitmap John Snow
2019-06-07 2:16 ` Eric Blake
2019-06-07 14:29 ` Vladimir Sementsov-Ogievskiy
2019-06-07 18:10 ` John Snow
2019-06-07 18:15 ` Eric Blake
2019-06-07 18:17 ` Vladimir Sementsov-Ogievskiy
2019-06-07 18:23 ` Vladimir Sementsov-Ogievskiy
2019-06-07 22:08 ` John Snow
2019-06-10 9:29 ` Vladimir Sementsov-Ogievskiy
2019-06-06 18:41 ` [Qemu-devel] [PATCH 3/5] block/dirty-bitmap: rework bdrv_remove_persistent_dirty_bitmap John Snow
2019-06-07 2:24 ` Eric Blake
2019-06-07 14:41 ` Vladimir Sementsov-Ogievskiy
2019-06-07 18:16 ` John Snow
2019-06-06 18:41 ` [Qemu-devel] [PATCH 4/5] block/qcow2-bitmap: Count queued bitmaps towards nb_bitmaps John Snow
2019-06-07 2:27 ` Eric Blake
2019-06-07 18:04 ` John Snow
2019-06-07 14:58 ` Vladimir Sementsov-Ogievskiy
2019-06-07 18:24 ` John Snow
2019-06-06 18:41 ` John Snow [this message]
2019-06-07 2:30 ` [Qemu-devel] [PATCH 5/5] block/qcow2-bitmap: Count queued bitmaps towards directory_size Eric Blake
2019-06-07 19:24 ` John Snow
2019-06-06 21:54 ` [Qemu-devel] [PATCH 0/5] block/dirty-bitmap: check number and size constraints against queued bitmaps no-reply
2019-06-06 22:26 ` John Snow
2019-10-09 18:57 ` Eric Blake
2019-10-09 20:44 ` John Snow
2019-10-10 6:23 ` 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=20190606184159.979-6-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=armbru@redhat.com \
--cc=fam@euphon.net \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=vsementsov@virtuozzo.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).