* [Qemu-devel] [PATCH v6 05/10] block: Add bdrv_copy_dirty_bitmap and bdrv_reset_dirty_bitmap
2014-10-30 3:22 [Qemu-devel] [PATCH v6 00/10] block: Incremental backup series Fam Zheng
@ 2014-10-30 3:22 ` Fam Zheng
2014-11-04 10:08 ` Max Reitz
0 siblings, 1 reply; 4+ messages in thread
From: Fam Zheng @ 2014-10-30 3:22 UTC (permalink / raw)
To: qemu-devel
Cc: Kevin Wolf, Benoit Canet, Vladimir Sementsov-Ogievskij,
Markus Armbruster, Max Reitz, John Snow, Stefan Hajnoczi, Jd,
Paolo Bonzini, Luiz Capitulino
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block.c | 26 +++++++++++++++++++++++++-
include/block/block.h | 4 ++++
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/block.c b/block.c
index 1b12541..39381cd 100644
--- a/block.c
+++ b/block.c
@@ -53,6 +53,8 @@
struct BdrvDirtyBitmap {
HBitmap *bitmap;
+ int64_t size;
+ int granularity;
char *name;
QLIST_ENTRY(BdrvDirtyBitmap) list;
};
@@ -5280,6 +5282,26 @@ void bdrv_dirty_bitmap_make_anon(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
bitmap->name = NULL;
}
+BdrvDirtyBitmap *bdrv_copy_dirty_bitmap(BlockDriverState *bs,
+ const BdrvDirtyBitmap *bitmap,
+ const char *name)
+{
+ BdrvDirtyBitmap *new_bitmap;
+
+ new_bitmap = g_malloc0(sizeof(BdrvDirtyBitmap));
+ new_bitmap->bitmap = hbitmap_copy(bitmap->bitmap);
+ new_bitmap->size = bitmap->size;
+ new_bitmap->granularity = bitmap->granularity;
+ new_bitmap->name = name ? g_strdup(name) : NULL;
+ QLIST_INSERT_HEAD(&bs->dirty_bitmaps, new_bitmap, list);
+ return new_bitmap;
+}
+
+void bdrv_reset_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
+{
+ hbitmap_reset(bitmap->bitmap, 0, bitmap->size);
+}
+
BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
int granularity,
const char *name,
@@ -5303,7 +5325,9 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
return NULL;
}
bitmap = g_new0(BdrvDirtyBitmap, 1);
- bitmap->bitmap = hbitmap_alloc(bitmap_size, ffs(granularity) - 1);
+ bitmap->size = bitmap_size;
+ bitmap->granularity = ffs(granularity) - 1;
+ bitmap->bitmap = hbitmap_alloc(bitmap->size, bitmap->granularity);
if (name) {
bitmap->name = g_strdup(name);
}
diff --git a/include/block/block.h b/include/block/block.h
index 87fa48e..c5a3aa6 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -426,6 +426,10 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
const char *name);
void bdrv_dirty_bitmap_make_anon(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
+void bdrv_reset_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
+BdrvDirtyBitmap *bdrv_copy_dirty_bitmap(BlockDriverState *bs,
+ const BdrvDirtyBitmap *bitmap,
+ const char *name);
void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
int bdrv_dirty_bitmap_granularity(BlockDriverState *bs,
--
1.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v6 05/10] block: Add bdrv_copy_dirty_bitmap and bdrv_reset_dirty_bitmap
2014-10-30 3:22 ` [Qemu-devel] [PATCH v6 05/10] block: Add bdrv_copy_dirty_bitmap and bdrv_reset_dirty_bitmap Fam Zheng
@ 2014-11-04 10:08 ` Max Reitz
0 siblings, 0 replies; 4+ messages in thread
From: Max Reitz @ 2014-11-04 10:08 UTC (permalink / raw)
To: Fam Zheng, qemu-devel
Cc: Kevin Wolf, Benoit Canet, Vladimir Sementsov-Ogievskij,
Markus Armbruster, Luiz Capitulino, John Snow, Stefan Hajnoczi,
Jd, Paolo Bonzini
On 2014-10-30 at 04:22, Fam Zheng wrote:
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> block.c | 26 +++++++++++++++++++++++++-
> include/block/block.h | 4 ++++
> 2 files changed, 29 insertions(+), 1 deletion(-)
>
> diff --git a/block.c b/block.c
> index 1b12541..39381cd 100644
> --- a/block.c
> +++ b/block.c
> @@ -53,6 +53,8 @@
>
> struct BdrvDirtyBitmap {
> HBitmap *bitmap;
> + int64_t size;
> + int granularity;
Why do you add this field when you never use it except for setting it in
bdrv_create_dirty_bitmap()? I at least couldn't find any place which
uses it by quickly scanning the rest of the series...
You could use it for bdrv_dirty_bitmap_granularity(), though.
> char *name;
> QLIST_ENTRY(BdrvDirtyBitmap) list;
> };
> @@ -5280,6 +5282,26 @@ void bdrv_dirty_bitmap_make_anon(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
> bitmap->name = NULL;
> }
>
> +BdrvDirtyBitmap *bdrv_copy_dirty_bitmap(BlockDriverState *bs,
> + const BdrvDirtyBitmap *bitmap,
> + const char *name)
> +{
> + BdrvDirtyBitmap *new_bitmap;
> +
> + new_bitmap = g_malloc0(sizeof(BdrvDirtyBitmap));
> + new_bitmap->bitmap = hbitmap_copy(bitmap->bitmap);
> + new_bitmap->size = bitmap->size;
> + new_bitmap->granularity = bitmap->granularity;
> + new_bitmap->name = name ? g_strdup(name) : NULL;
> + QLIST_INSERT_HEAD(&bs->dirty_bitmaps, new_bitmap, list);
> + return new_bitmap;
> +}
> +
> +void bdrv_reset_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap)
> +{
> + hbitmap_reset(bitmap->bitmap, 0, bitmap->size);
> +}
> +
> BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
> int granularity,
> const char *name,
> @@ -5303,7 +5325,9 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
> return NULL;
> }
> bitmap = g_new0(BdrvDirtyBitmap, 1);
> - bitmap->bitmap = hbitmap_alloc(bitmap_size, ffs(granularity) - 1);
> + bitmap->size = bitmap_size;
> + bitmap->granularity = ffs(granularity) - 1;
> + bitmap->bitmap = hbitmap_alloc(bitmap->size, bitmap->granularity);
> if (name) {
> bitmap->name = g_strdup(name);
> }
> diff --git a/include/block/block.h b/include/block/block.h
> index 87fa48e..c5a3aa6 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -426,6 +426,10 @@ BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
> BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
> const char *name);
> void bdrv_dirty_bitmap_make_anon(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
> +void bdrv_reset_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
> +BdrvDirtyBitmap *bdrv_copy_dirty_bitmap(BlockDriverState *bs,
> + const BdrvDirtyBitmap *bitmap,
> + const char *name);
> void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
> BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
> int bdrv_dirty_bitmap_granularity(BlockDriverState *bs,
Reviewed-by: Max Reitz <mreitz@redhat.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v6 05/10] block: Add bdrv_copy_dirty_bitmap and bdrv_reset_dirty_bitmap
@ 2014-11-07 15:16 Vladimir Sementsov-Ogievskiy
2014-11-17 19:18 ` John Snow
0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2014-11-07 15:16 UTC (permalink / raw)
To: famz
Cc: Kevin Wolf, Benoit Canet, John Snow, Markus Armbruster,
qemu-devel, Max Reitz, Stefan Hajnoczi, Jd, Paolo Bonzini,
Luiz Capitulino
[-- Attachment #1: Type: text/plain, Size: 3032 bytes --]
from [PATCH v6 02/10]
> +void qmp_block_dirty_bitmap_remove(const char *device, const char *name,
> + Error **errp)
> +{
> + BlockDriverState *bs;
> + BdrvDirtyBitmap *bitmap;
> +
> + bs = bdrv_find(device);
> + if (!bs) {
> + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
> + return;
> + }
> +
> + if (!name || name[0] == '\0') {
> + error_setg(errp, "Bitmap name cannot be empty");
> + return;
> + }
> + bitmap = bdrv_find_dirty_bitmap(bs, name);
> + if (!bitmap) {
> + error_setg(errp, "Dirty bitmap not found: %s", name);
> + return;
> + }
> +
> + bdrv_dirty_bitmap_make_anon(bs, bitmap);
> + bdrv_release_dirty_bitmap(bs, bitmap);
> +}
from [PATCH v6 05/10]:
> +void qmp_block_dirty_bitmap_enable(const char *device, const char *name,
> + Error **errp)
> +{
> + BlockDriverState *bs;
> + BdrvDirtyBitmap *bitmap;
> +
> + bs = bdrv_find(device);
> + if (!bs) {
> + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
> + return;
> + }
> +
> + bitmap = bdrv_find_dirty_bitmap(bs, name);
> + if (!bitmap) {
> + error_setg(errp, "Dirty bitmap not found: %s", name);
> + return;
> + }
> +
> + bdrv_enable_dirty_bitmap(bs, bitmap);
> +}
> +
> +void qmp_block_dirty_bitmap_disable(const char *device, const char *name,
> + Error **errp)
> +{
> + BlockDriverState *bs;
> + BdrvDirtyBitmap *bitmap;
> +
> + bs = bdrv_find(device);
> + if (!bs) {
> + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
> + return;
> + }
> +
> + bitmap = bdrv_find_dirty_bitmap(bs, name);
> + if (!bitmap) {
> + error_setg(errp, "Dirty bitmap not found: %s", name);
> + return;
> + }
> +
> + bdrv_disable_dirty_bitmap(bs, bitmap);
> +}
> +
there is one inconsistence:
you have check
> + if (!name || name[0] == '\0') {
> + error_setg(errp, "Bitmap name cannot be empty");
> + return;
> + }
when accessing bitmap in qmp_block_dirty_bitmap_remove, but not in
qmp_block_dirty_bitmap_{enable,disable}.
Also, I think it'll be better to put similar part of these three
functions into one separate function to avoid duplicates, like
static BdrvDirtyBitmap *bitmap find_dirty_bitmap(const char *device, const char *name,
Error **errp)
{
BlockDriverState *bs;
BdrvDirtyBitmap *bitmap;
// most simple error condition earlier
if (!name || name[0] == '\0') {
error_setg(errp, "Bitmap name cannot be empty");
return NULL;
}
bs = bdrv_find(device);
if (!bs) {
error_set(errp, QERR_DEVICE_NOT_FOUND, device);
return NULL;
}
bitmap = bdrv_find_dirty_bitmap(bs, name);
if (!bitmap) {
error_setg(errp, "Dirty bitmap not found: %s", name);
return NULL;
}
return bitmap;
}
--
Best regards,
Vladimir
[-- Attachment #2: Type: text/html, Size: 4637 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH v6 05/10] block: Add bdrv_copy_dirty_bitmap and bdrv_reset_dirty_bitmap
2014-11-07 15:16 [Qemu-devel] [PATCH v6 05/10] block: Add bdrv_copy_dirty_bitmap and bdrv_reset_dirty_bitmap Vladimir Sementsov-Ogievskiy
@ 2014-11-17 19:18 ` John Snow
0 siblings, 0 replies; 4+ messages in thread
From: John Snow @ 2014-11-17 19:18 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy, famz
Cc: Kevin Wolf, Benoit Canet, Markus Armbruster, qemu-devel,
Max Reitz, Stefan Hajnoczi, Jd, Paolo Bonzini, Luiz Capitulino
On 11/07/2014 10:16 AM, Vladimir Sementsov-Ogievskiy wrote:
> from [PATCH v6 02/10]
>> +void qmp_block_dirty_bitmap_remove(const char *device, const char *name,
>> + Error **errp)
>> +{
>> + BlockDriverState *bs;
>> + BdrvDirtyBitmap *bitmap;
>> +
>> + bs = bdrv_find(device);
>> + if (!bs) {
>> + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
>> + return;
>> + }
>> +
>> + if (!name || name[0] == '\0') {
>> + error_setg(errp, "Bitmap name cannot be empty");
>> + return;
>> + }
>> + bitmap = bdrv_find_dirty_bitmap(bs, name);
>> + if (!bitmap) {
>> + error_setg(errp, "Dirty bitmap not found: %s", name);
>> + return;
>> + }
>> +
>> + bdrv_dirty_bitmap_make_anon(bs, bitmap);
>> + bdrv_release_dirty_bitmap(bs, bitmap);
>> +}
>
> from [PATCH v6 05/10]:
>> +void qmp_block_dirty_bitmap_enable(const char *device, const char *name,
>> + Error **errp)
>> +{
>> + BlockDriverState *bs;
>> + BdrvDirtyBitmap *bitmap;
>> +
>> + bs = bdrv_find(device);
>> + if (!bs) {
>> + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
>> + return;
>> + }
>> +
>> + bitmap = bdrv_find_dirty_bitmap(bs, name);
>> + if (!bitmap) {
>> + error_setg(errp, "Dirty bitmap not found: %s", name);
>> + return;
>> + }
>> +
>> + bdrv_enable_dirty_bitmap(bs, bitmap);
>> +}
>> +
>> +void qmp_block_dirty_bitmap_disable(const char *device, const char *name,
>> + Error **errp)
>> +{
>> + BlockDriverState *bs;
>> + BdrvDirtyBitmap *bitmap;
>> +
>> + bs = bdrv_find(device);
>> + if (!bs) {
>> + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
>> + return;
>> + }
>> +
>> + bitmap = bdrv_find_dirty_bitmap(bs, name);
>> + if (!bitmap) {
>> + error_setg(errp, "Dirty bitmap not found: %s", name);
>> + return;
>> + }
>> +
>> + bdrv_disable_dirty_bitmap(bs, bitmap);
>> +}
>> +
>
> there is one inconsistence:
>
> you have check
>> + if (!name || name[0] == '\0') {
>> + error_setg(errp, "Bitmap name cannot be empty");
>> + return;
>> + }
> when accessing bitmap in qmp_block_dirty_bitmap_remove, but not in
> qmp_block_dirty_bitmap_{enable,disable}.
In qmp_block_dirty_bitmap_{enable,disable} I don't think it's a problem
if we don't check the name here -- it just means that we're not going to
be able to find the name (since it's invalid) and the function will
error out anyway.
I don't think a change is warranted, necessarily, unless we factor out
the error checking: see below.
> Also, I think it'll be better to put similar part of these three
> functions into one separate function to avoid duplicates, like
>
> static BdrvDirtyBitmap *bitmap find_dirty_bitmap(const char *device, const char *name,
> Error **errp)
> {
> BlockDriverState *bs;
> BdrvDirtyBitmap *bitmap;
>
> // most simple error condition earlier
> if (!name || name[0] == '\0') {
> error_setg(errp, "Bitmap name cannot be empty");
> return NULL;
> }
>
> bs = bdrv_find(device);
> if (!bs) {
> error_set(errp, QERR_DEVICE_NOT_FOUND, device);
> return NULL;
> }
>
> bitmap = bdrv_find_dirty_bitmap(bs, name);
> if (!bitmap) {
> error_setg(errp, "Dirty bitmap not found: %s", name);
> return NULL;
> }
>
> return bitmap;
> }
>
I think normally I would agree, but since qmp_block_dirty_bitmap_remove
needs to use the BlockDriverState anyway, part of this error-checking
routine gets duplicated regardless, unless you add another return
parameter to give you the BlockDriverState back as well, and you lose
the single purpose nature of factoring it out.
I will keep the redundancy of the error-checking of this patch in mind
as I clean it up for v7...
> --
> Best regards,
> Vladimir
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-11-17 19:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-07 15:16 [Qemu-devel] [PATCH v6 05/10] block: Add bdrv_copy_dirty_bitmap and bdrv_reset_dirty_bitmap Vladimir Sementsov-Ogievskiy
2014-11-17 19:18 ` John Snow
-- strict thread matches above, loose matches on Subject: below --
2014-10-30 3:22 [Qemu-devel] [PATCH v6 00/10] block: Incremental backup series Fam Zheng
2014-10-30 3:22 ` [Qemu-devel] [PATCH v6 05/10] block: Add bdrv_copy_dirty_bitmap and bdrv_reset_dirty_bitmap Fam Zheng
2014-11-04 10:08 ` Max Reitz
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).