From: Max Reitz <mreitz@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Fam Zheng <famz@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PATCH v4 2/6] block: Add ImageInfoSpecific to BlockDriverInfo
Date: Wed, 11 Sep 2013 10:00:30 +0200 [thread overview]
Message-ID: <1378886434-9411-3-git-send-email-mreitz@redhat.com> (raw)
In-Reply-To: <1378886434-9411-1-git-send-email-mreitz@redhat.com>
Add the new ImageInfoSpecific type also to BlockDriverInfo, as well as a
bdrv_put_info function which releases all data allocated by
bdrv_get_info from BlockDriverInfo (such as the new ImageInfoSpecific
field).
To prevent memory leaks, bdrv_put_info has to be called on every
BlockDriverInfo object when it is no longer required (and bdrv_get_info
has been successful).
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block.c | 16 +++++++++++++++-
block/mirror.c | 16 +++++++++++-----
block/qapi.c | 4 ++++
include/block/block.h | 3 +++
qemu-img.c | 1 +
qemu-io-cmds.c | 2 ++
6 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/block.c b/block.c
index b81d1e2..604bef0 100644
--- a/block.c
+++ b/block.c
@@ -1953,8 +1953,10 @@ void bdrv_round_to_clusters(BlockDriverState *bs,
int *cluster_nb_sectors)
{
BlockDriverInfo bdi;
+ int ret;
- if (bdrv_get_info(bs, &bdi) < 0 || bdi.cluster_size == 0) {
+ ret = bdrv_get_info(bs, &bdi);
+ if (ret < 0 || bdi.cluster_size == 0) {
*cluster_sector_num = sector_num;
*cluster_nb_sectors = nb_sectors;
} else {
@@ -1963,6 +1965,9 @@ void bdrv_round_to_clusters(BlockDriverState *bs,
*cluster_nb_sectors = QEMU_ALIGN_UP(sector_num - *cluster_sector_num +
nb_sectors, c);
}
+ if (ret >= 0) {
+ bdrv_put_info(bs, &bdi);
+ }
}
static bool tracked_request_overlaps(BdrvTrackedRequest *req,
@@ -3281,6 +3286,15 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
return drv->bdrv_get_info(bs, bdi);
}
+/**
+ * Releases all data which has been allocated through bdrv_get_info. This
+ * function should be called if and only if bdrv_get_info was successful.
+ */
+void bdrv_put_info(BlockDriverState *bs, BlockDriverInfo *bdi)
+{
+ qapi_free_ImageInfoSpecific(bdi->format_specific);
+}
+
int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
int64_t pos, int size)
{
diff --git a/block/mirror.c b/block/mirror.c
index f61a779..7d3eb29 100644
--- a/block/mirror.c
+++ b/block/mirror.c
@@ -320,10 +320,12 @@ static void coroutine_fn mirror_run(void *opaque)
bdrv_get_backing_filename(s->target, backing_filename,
sizeof(backing_filename));
if (backing_filename[0] && !s->target->backing_hd) {
- bdrv_get_info(s->target, &bdi);
- if (s->granularity < bdi.cluster_size) {
- s->buf_size = MAX(s->buf_size, bdi.cluster_size);
- s->cow_bitmap = bitmap_new(length);
+ if (bdrv_get_info(s->target, &bdi) >= 0) {
+ if (s->granularity < bdi.cluster_size) {
+ s->buf_size = MAX(s->buf_size, bdi.cluster_size);
+ s->cow_bitmap = bitmap_new(length);
+ }
+ bdrv_put_info(s->target, &bdi);
}
}
@@ -545,12 +547,16 @@ void mirror_start(BlockDriverState *bs, BlockDriverState *target,
/* Choose the default granularity based on the target file's cluster
* size, clamped between 4k and 64k. */
BlockDriverInfo bdi;
- if (bdrv_get_info(target, &bdi) >= 0 && bdi.cluster_size != 0) {
+ int ret = bdrv_get_info(target, &bdi);
+ if (ret >= 0 && bdi.cluster_size != 0) {
granularity = MAX(4096, bdi.cluster_size);
granularity = MIN(65536, granularity);
} else {
granularity = 65536;
}
+ if (ret >= 0) {
+ bdrv_put_info(target, &bdi);
+ }
}
assert ((granularity & (granularity - 1)) == 0);
diff --git a/block/qapi.c b/block/qapi.c
index 782051c..738469a 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -133,6 +133,10 @@ void bdrv_query_image_info(BlockDriverState *bs,
}
info->dirty_flag = bdi.is_dirty;
info->has_dirty_flag = true;
+ if (bdi.format_specific) {
+ info->format_specific = bdi.format_specific;
+ info->has_format_specific = true;
+ }
}
backing_filename = bs->backing_file;
if (backing_filename[0] != '\0') {
diff --git a/include/block/block.h b/include/block/block.h
index 1c5f939..a9b3b16 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -18,6 +18,8 @@ typedef struct BlockDriverInfo {
/* offset at which the VM state can be saved (0 if not possible) */
int64_t vm_state_offset;
bool is_dirty;
+ /* additional information; NULL if none */
+ ImageInfoSpecific *format_specific;
} BlockDriverInfo;
typedef struct BlockFragInfo {
@@ -334,6 +336,7 @@ int bdrv_get_flags(BlockDriverState *bs);
int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
const uint8_t *buf, int nb_sectors);
int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
+void bdrv_put_info(BlockDriverState *bs, BlockDriverInfo *bdi);
void bdrv_round_to_clusters(BlockDriverState *bs,
int64_t sector_num, int nb_sectors,
int64_t *cluster_sector_num,
diff --git a/qemu-img.c b/qemu-img.c
index 0cf6be2..66bc696 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1393,6 +1393,7 @@ static int img_convert(int argc, char **argv)
goto out;
}
cluster_size = bdi.cluster_size;
+ bdrv_put_info(out_bs, &bdi);
if (cluster_size <= 0 || cluster_size > IO_BUF_SIZE) {
error_report("invalid cluster size");
ret = -1;
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 8565d49..5029b19 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -1699,6 +1699,8 @@ static int info_f(BlockDriverState *bs, int argc, char **argv)
printf("cluster size: %s\n", s1);
printf("vm state offset: %s\n", s2);
+ bdrv_put_info(bs, &bdi);
+
return 0;
}
--
1.8.3.1
next prev parent reply other threads:[~2013-09-11 8:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-11 8:00 [Qemu-devel] [PATCH v4 0/6] Provide additional info through qemu-img info Max Reitz
2013-09-11 8:00 ` [Qemu-devel] [PATCH v4 1/6] qapi: Add ImageInfoSpecific type Max Reitz
2013-09-11 8:00 ` Max Reitz [this message]
2013-09-11 8:00 ` [Qemu-devel] [PATCH v4 3/6] block/qapi: Human-readable ImageInfoSpecific dump Max Reitz
2013-09-11 8:00 ` [Qemu-devel] [PATCH v4 4/6] qcow2: Add support for ImageInfoSpecific Max Reitz
2013-09-11 8:00 ` [Qemu-devel] [PATCH v4 5/6] qemu-iotests: Discard specific info in _img_info Max Reitz
2013-09-11 8:00 ` [Qemu-devel] [PATCH v4 6/6] qemu-iotests: Additional info from qemu-img info Max Reitz
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=1378886434-9411-3-git-send-email-mreitz@redhat.com \
--to=mreitz@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.