* [Qemu-devel] [PATCH] vmdk: Switch to heap arrays for vmdk_write_cid
@ 2016-03-08 6:18 Fam Zheng
2016-03-08 7:10 ` Peter Xu
0 siblings, 1 reply; 3+ messages in thread
From: Fam Zheng @ 2016-03-08 6:18 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, pbonzini, Fam Zheng, qemu-block
It is only called once for each opened image, so we can do it the easy
way.
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/vmdk.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index a8db5d9..1ec2452 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -274,36 +274,39 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
{
- char desc[DESC_SIZE], tmp_desc[DESC_SIZE];
+ char *desc, *tmp_desc;
char *p_name, *tmp_str;
BDRVVmdkState *s = bs->opaque;
- int ret;
+ int ret = 0;
+ desc = g_malloc0(DESC_SIZE);
+ tmp_desc = g_malloc0(DESC_SIZE);
ret = bdrv_pread(bs->file->bs, s->desc_offset, desc, DESC_SIZE);
if (ret < 0) {
- return ret;
+ goto out;
}
desc[DESC_SIZE - 1] = '\0';
tmp_str = strstr(desc, "parentCID");
if (tmp_str == NULL) {
- return -EINVAL;
+ ret = -EINVAL;
+ goto out;
}
- pstrcpy(tmp_desc, sizeof(tmp_desc), tmp_str);
+ pstrcpy(tmp_desc, DESC_SIZE, tmp_str);
p_name = strstr(desc, "CID");
if (p_name != NULL) {
p_name += sizeof("CID");
- snprintf(p_name, sizeof(desc) - (p_name - desc), "%" PRIx32 "\n", cid);
- pstrcat(desc, sizeof(desc), tmp_desc);
+ snprintf(p_name, DESC_SIZE - (p_name - desc), "%" PRIx32 "\n", cid);
+ pstrcat(desc, DESC_SIZE, tmp_desc);
}
ret = bdrv_pwrite_sync(bs->file->bs, s->desc_offset, desc, DESC_SIZE);
- if (ret < 0) {
- return ret;
- }
- return 0;
+out:
+ g_free(desc);
+ g_free(tmp_desc);
+ return ret;
}
static int vmdk_is_cid_valid(BlockDriverState *bs)
--
2.4.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] vmdk: Switch to heap arrays for vmdk_write_cid
2016-03-08 6:18 [Qemu-devel] [PATCH] vmdk: Switch to heap arrays for vmdk_write_cid Fam Zheng
@ 2016-03-08 7:10 ` Peter Xu
2016-03-08 7:18 ` Fam Zheng
0 siblings, 1 reply; 3+ messages in thread
From: Peter Xu @ 2016-03-08 7:10 UTC (permalink / raw)
To: Fam Zheng; +Cc: Kevin Wolf, pbonzini, qemu-devel, qemu-block
On Tue, Mar 08, 2016 at 02:18:35PM +0800, Fam Zheng wrote:
> It is only called once for each opened image, so we can do it the easy
> way.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> block/vmdk.c | 25 ++++++++++++++-----------
> 1 file changed, 14 insertions(+), 11 deletions(-)
>
> diff --git a/block/vmdk.c b/block/vmdk.c
> index a8db5d9..1ec2452 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -274,36 +274,39 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
>
> static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
If to use heap in write, do we need to do the same for e.g.,
vmdk_parent_open() and vmdk_read_cid(), to make all things at least
aligned?
> {
> - char desc[DESC_SIZE], tmp_desc[DESC_SIZE];
> + char *desc, *tmp_desc;
> char *p_name, *tmp_str;
> BDRVVmdkState *s = bs->opaque;
> - int ret;
> + int ret = 0;
>
> + desc = g_malloc0(DESC_SIZE);
> + tmp_desc = g_malloc0(DESC_SIZE);
> ret = bdrv_pread(bs->file->bs, s->desc_offset, desc, DESC_SIZE);
> if (ret < 0) {
> - return ret;
> + goto out;
> }
>
> desc[DESC_SIZE - 1] = '\0';
> tmp_str = strstr(desc, "parentCID");
> if (tmp_str == NULL) {
> - return -EINVAL;
> + ret = -EINVAL;
> + goto out;
> }
>
> - pstrcpy(tmp_desc, sizeof(tmp_desc), tmp_str);
> + pstrcpy(tmp_desc, DESC_SIZE, tmp_str);
> p_name = strstr(desc, "CID");
> if (p_name != NULL) {
> p_name += sizeof("CID");
> - snprintf(p_name, sizeof(desc) - (p_name - desc), "%" PRIx32 "\n", cid);
> - pstrcat(desc, sizeof(desc), tmp_desc);
> + snprintf(p_name, DESC_SIZE - (p_name - desc), "%" PRIx32 "\n", cid);
> + pstrcat(desc, DESC_SIZE, tmp_desc);
> }
>
> ret = bdrv_pwrite_sync(bs->file->bs, s->desc_offset, desc, DESC_SIZE);
> - if (ret < 0) {
> - return ret;
> - }
>
> - return 0;
> +out:
> + g_free(desc);
> + g_free(tmp_desc);
> + return ret;
> }
>
> static int vmdk_is_cid_valid(BlockDriverState *bs)
> --
> 2.4.3
>
>
Besides the above nit-pick:
Reviewed-by: Peter Xu <peterx@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] vmdk: Switch to heap arrays for vmdk_write_cid
2016-03-08 7:10 ` Peter Xu
@ 2016-03-08 7:18 ` Fam Zheng
0 siblings, 0 replies; 3+ messages in thread
From: Fam Zheng @ 2016-03-08 7:18 UTC (permalink / raw)
To: Peter Xu; +Cc: Kevin Wolf, pbonzini, qemu-devel, qemu-block
On Tue, 03/08 15:10, Peter Xu wrote:
> On Tue, Mar 08, 2016 at 02:18:35PM +0800, Fam Zheng wrote:
> > It is only called once for each opened image, so we can do it the easy
> > way.
> >
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> > block/vmdk.c | 25 ++++++++++++++-----------
> > 1 file changed, 14 insertions(+), 11 deletions(-)
> >
> > diff --git a/block/vmdk.c b/block/vmdk.c
> > index a8db5d9..1ec2452 100644
> > --- a/block/vmdk.c
> > +++ b/block/vmdk.c
> > @@ -274,36 +274,39 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
> >
> > static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
>
> If to use heap in write, do we need to do the same for e.g.,
> vmdk_parent_open() and vmdk_read_cid(), to make all things at least
> aligned?
Yes, let's change them altogether.
Fam
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-03-08 7:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-08 6:18 [Qemu-devel] [PATCH] vmdk: Switch to heap arrays for vmdk_write_cid Fam Zheng
2016-03-08 7:10 ` Peter Xu
2016-03-08 7:18 ` Fam Zheng
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).