* [Qemu-devel] [PATCH v2 0/3] vmdk: Move descriptor buffers to heap
@ 2016-03-08 8:24 Fam Zheng
2016-03-08 8:24 ` [Qemu-devel] [PATCH v2 1/3] vmdk: Switch to heap arrays for vmdk_write_cid Fam Zheng
` (4 more replies)
0 siblings, 5 replies; 9+ messages in thread
From: Fam Zheng @ 2016-03-08 8:24 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, pbonzini, Fam Zheng, peterx, qemu-block
All three functions are not in hot path (all run once for the BDS lifecycle),
so it's okay to convert to g_malloc0.
Fam
Fam Zheng (3):
vmdk: Switch to heap arrays for vmdk_write_cid
vmdk: Switch to heap arrays for vmdk_read_cid
vmdk: Switch to heap arrays for vmdk_parent_open
block/vmdk.c | 47 +++++++++++++++++++++++++++++------------------
1 file changed, 29 insertions(+), 18 deletions(-)
--
2.4.3
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH v2 1/3] vmdk: Switch to heap arrays for vmdk_write_cid
2016-03-08 8:24 [Qemu-devel] [PATCH v2 0/3] vmdk: Move descriptor buffers to heap Fam Zheng
@ 2016-03-08 8:24 ` Fam Zheng
2016-03-08 8:24 ` [Qemu-devel] [PATCH v2 2/3] vmdk: Switch to heap arrays for vmdk_read_cid Fam Zheng
` (3 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Fam Zheng @ 2016-03-08 8:24 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, pbonzini, Fam Zheng, peterx, qemu-block
It is only called once for each opened image, so we can do it the easy
way.
Reviewed-by: Peter Xu <peterx@redhat.com>
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] 9+ messages in thread
* [Qemu-devel] [PATCH v2 2/3] vmdk: Switch to heap arrays for vmdk_read_cid
2016-03-08 8:24 [Qemu-devel] [PATCH v2 0/3] vmdk: Move descriptor buffers to heap Fam Zheng
2016-03-08 8:24 ` [Qemu-devel] [PATCH v2 1/3] vmdk: Switch to heap arrays for vmdk_write_cid Fam Zheng
@ 2016-03-08 8:24 ` Fam Zheng
2016-03-08 8:24 ` [Qemu-devel] [PATCH v2 3/3] vmdk: Switch to heap arrays for vmdk_parent_open Fam Zheng
` (2 subsequent siblings)
4 siblings, 0 replies; 9+ messages in thread
From: Fam Zheng @ 2016-03-08 8:24 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, pbonzini, Fam Zheng, peterx, qemu-block
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/vmdk.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index 1ec2452..c68f456 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -242,15 +242,17 @@ static void vmdk_free_last_extent(BlockDriverState *bs)
static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
{
- char desc[DESC_SIZE];
+ char *desc;
uint32_t cid = 0xffffffff;
const char *p_name, *cid_str;
size_t cid_str_size;
BDRVVmdkState *s = bs->opaque;
int ret;
+ desc = g_malloc0(DESC_SIZE);
ret = bdrv_pread(bs->file->bs, s->desc_offset, desc, DESC_SIZE);
if (ret < 0) {
+ g_free(desc);
return 0;
}
@@ -269,6 +271,7 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
sscanf(p_name, "%" SCNx32, &cid);
}
+ g_free(desc);
return cid;
}
--
2.4.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [Qemu-devel] [PATCH v2 3/3] vmdk: Switch to heap arrays for vmdk_parent_open
2016-03-08 8:24 [Qemu-devel] [PATCH v2 0/3] vmdk: Move descriptor buffers to heap Fam Zheng
2016-03-08 8:24 ` [Qemu-devel] [PATCH v2 1/3] vmdk: Switch to heap arrays for vmdk_write_cid Fam Zheng
2016-03-08 8:24 ` [Qemu-devel] [PATCH v2 2/3] vmdk: Switch to heap arrays for vmdk_read_cid Fam Zheng
@ 2016-03-08 8:24 ` Fam Zheng
2016-03-09 0:43 ` Fam Zheng
2016-03-08 12:36 ` [Qemu-devel] [PATCH v2 0/3] vmdk: Move descriptor buffers to heap Paolo Bonzini
2016-03-08 13:18 ` Kevin Wolf
4 siblings, 1 reply; 9+ messages in thread
From: Fam Zheng @ 2016-03-08 8:24 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, pbonzini, Fam Zheng, peterx, qemu-block
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/vmdk.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index c68f456..03be7f0 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -343,15 +343,16 @@ static int vmdk_reopen_prepare(BDRVReopenState *state,
static int vmdk_parent_open(BlockDriverState *bs)
{
char *p_name;
- char desc[DESC_SIZE + 1];
+ char *desc;
BDRVVmdkState *s = bs->opaque;
int ret;
- desc[DESC_SIZE] = '\0';
+ desc = g_malloc0(DESC_SIZE + 1);
ret = bdrv_pread(bs->file->bs, s->desc_offset, desc, DESC_SIZE);
if (ret < 0) {
- return ret;
+ goto out;
}
+ ret = 0;
p_name = strstr(desc, "parentFileNameHint");
if (p_name != NULL) {
@@ -360,16 +361,20 @@ static int vmdk_parent_open(BlockDriverState *bs)
p_name += sizeof("parentFileNameHint") + 1;
end_name = strchr(p_name, '\"');
if (end_name == NULL) {
- return -EINVAL;
+ ret = -EINVAL;
+ goto out;
}
if ((end_name - p_name) > sizeof(bs->backing_file) - 1) {
- return -EINVAL;
+ ret = -EINVAL;
+ goto out;
}
pstrcpy(bs->backing_file, end_name - p_name + 1, p_name);
}
- return 0;
+out:
+ g_free(desc);
+ return ret;
}
/* Create and append extent to the extent array. Return the added VmdkExtent
--
2.4.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/3] vmdk: Move descriptor buffers to heap
2016-03-08 8:24 [Qemu-devel] [PATCH v2 0/3] vmdk: Move descriptor buffers to heap Fam Zheng
` (2 preceding siblings ...)
2016-03-08 8:24 ` [Qemu-devel] [PATCH v2 3/3] vmdk: Switch to heap arrays for vmdk_parent_open Fam Zheng
@ 2016-03-08 12:36 ` Paolo Bonzini
2016-03-08 13:18 ` Kevin Wolf
4 siblings, 0 replies; 9+ messages in thread
From: Paolo Bonzini @ 2016-03-08 12:36 UTC (permalink / raw)
To: Fam Zheng, qemu-devel; +Cc: Kevin Wolf, peterx, qemu-block
On 08/03/2016 09:24, Fam Zheng wrote:
> All three functions are not in hot path (all run once for the BDS lifecycle),
> so it's okay to convert to g_malloc0.
>
> Fam
>
>
> Fam Zheng (3):
> vmdk: Switch to heap arrays for vmdk_write_cid
> vmdk: Switch to heap arrays for vmdk_read_cid
> vmdk: Switch to heap arrays for vmdk_parent_open
>
> block/vmdk.c | 47 +++++++++++++++++++++++++++++------------------
> 1 file changed, 29 insertions(+), 18 deletions(-)
>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/3] vmdk: Move descriptor buffers to heap
2016-03-08 8:24 [Qemu-devel] [PATCH v2 0/3] vmdk: Move descriptor buffers to heap Fam Zheng
` (3 preceding siblings ...)
2016-03-08 12:36 ` [Qemu-devel] [PATCH v2 0/3] vmdk: Move descriptor buffers to heap Paolo Bonzini
@ 2016-03-08 13:18 ` Kevin Wolf
4 siblings, 0 replies; 9+ messages in thread
From: Kevin Wolf @ 2016-03-08 13:18 UTC (permalink / raw)
To: Fam Zheng; +Cc: pbonzini, peterx, qemu-devel, qemu-block
Am 08.03.2016 um 09:24 hat Fam Zheng geschrieben:
> All three functions are not in hot path (all run once for the BDS lifecycle),
> so it's okay to convert to g_malloc0.
Yeah, it's okay, but still kind of useless to memset the whole buffer
before you overwrite it anyway. There's also a useless ret = 0 somewhere.
I'd prefer not to do that in the next series.
Anyway, thanks, applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2 3/3] vmdk: Switch to heap arrays for vmdk_parent_open
2016-03-08 8:24 ` [Qemu-devel] [PATCH v2 3/3] vmdk: Switch to heap arrays for vmdk_parent_open Fam Zheng
@ 2016-03-09 0:43 ` Fam Zheng
2016-03-09 9:50 ` Kevin Wolf
0 siblings, 1 reply; 9+ messages in thread
From: Fam Zheng @ 2016-03-09 0:43 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, qemu-block
On Tue, 03/08 16:24, Fam Zheng wrote:
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> block/vmdk.c | 17 +++++++++++------
> 1 file changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/block/vmdk.c b/block/vmdk.c
> index c68f456..03be7f0 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -343,15 +343,16 @@ static int vmdk_reopen_prepare(BDRVReopenState *state,
> static int vmdk_parent_open(BlockDriverState *bs)
> {
> char *p_name;
> - char desc[DESC_SIZE + 1];
> + char *desc;
> BDRVVmdkState *s = bs->opaque;
> int ret;
>
> - desc[DESC_SIZE] = '\0';
> + desc = g_malloc0(DESC_SIZE + 1);
> ret = bdrv_pread(bs->file->bs, s->desc_offset, desc, DESC_SIZE);
> if (ret < 0) {
> - return ret;
> + goto out;
> }
> + ret = 0;
Kevin, were you referring to this "ret = 0" in the cover letter? If so, it is
not useless, because ret was set to DESC_SIZE by bdrv_pread. :)
Fam
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2 3/3] vmdk: Switch to heap arrays for vmdk_parent_open
2016-03-09 0:43 ` Fam Zheng
@ 2016-03-09 9:50 ` Kevin Wolf
2016-03-10 1:53 ` Fam Zheng
0 siblings, 1 reply; 9+ messages in thread
From: Kevin Wolf @ 2016-03-09 9:50 UTC (permalink / raw)
To: Fam Zheng; +Cc: qemu-devel, qemu-block
Am 09.03.2016 um 01:43 hat Fam Zheng geschrieben:
> On Tue, 03/08 16:24, Fam Zheng wrote:
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> > block/vmdk.c | 17 +++++++++++------
> > 1 file changed, 11 insertions(+), 6 deletions(-)
> >
> > diff --git a/block/vmdk.c b/block/vmdk.c
> > index c68f456..03be7f0 100644
> > --- a/block/vmdk.c
> > +++ b/block/vmdk.c
> > @@ -343,15 +343,16 @@ static int vmdk_reopen_prepare(BDRVReopenState *state,
> > static int vmdk_parent_open(BlockDriverState *bs)
> > {
> > char *p_name;
> > - char desc[DESC_SIZE + 1];
> > + char *desc;
> > BDRVVmdkState *s = bs->opaque;
> > int ret;
> >
> > - desc[DESC_SIZE] = '\0';
> > + desc = g_malloc0(DESC_SIZE + 1);
> > ret = bdrv_pread(bs->file->bs, s->desc_offset, desc, DESC_SIZE);
> > if (ret < 0) {
> > - return ret;
> > + goto out;
> > }
> > + ret = 0;
>
> Kevin, were you referring to this "ret = 0" in the cover letter? If so, it is
> not useless, because ret was set to DESC_SIZE by bdrv_pread. :)
Nope, I meant the initialisation in patch 1.
Kevin
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Qemu-devel] [PATCH v2 3/3] vmdk: Switch to heap arrays for vmdk_parent_open
2016-03-09 9:50 ` Kevin Wolf
@ 2016-03-10 1:53 ` Fam Zheng
0 siblings, 0 replies; 9+ messages in thread
From: Fam Zheng @ 2016-03-10 1:53 UTC (permalink / raw)
To: Kevin Wolf; +Cc: qemu-devel, qemu-block
On Wed, 03/09 10:50, Kevin Wolf wrote:
> Am 09.03.2016 um 01:43 hat Fam Zheng geschrieben:
> > On Tue, 03/08 16:24, Fam Zheng wrote:
> > > Signed-off-by: Fam Zheng <famz@redhat.com>
> > > ---
> > > block/vmdk.c | 17 +++++++++++------
> > > 1 file changed, 11 insertions(+), 6 deletions(-)
> > >
> > > diff --git a/block/vmdk.c b/block/vmdk.c
> > > index c68f456..03be7f0 100644
> > > --- a/block/vmdk.c
> > > +++ b/block/vmdk.c
> > > @@ -343,15 +343,16 @@ static int vmdk_reopen_prepare(BDRVReopenState *state,
> > > static int vmdk_parent_open(BlockDriverState *bs)
> > > {
> > > char *p_name;
> > > - char desc[DESC_SIZE + 1];
> > > + char *desc;
> > > BDRVVmdkState *s = bs->opaque;
> > > int ret;
> > >
> > > - desc[DESC_SIZE] = '\0';
> > > + desc = g_malloc0(DESC_SIZE + 1);
> > > ret = bdrv_pread(bs->file->bs, s->desc_offset, desc, DESC_SIZE);
> > > if (ret < 0) {
> > > - return ret;
> > > + goto out;
> > > }
> > > + ret = 0;
> >
> > Kevin, were you referring to this "ret = 0" in the cover letter? If so, it is
> > not useless, because ret was set to DESC_SIZE by bdrv_pread. :)
>
> Nope, I meant the initialisation in patch 1.
You're right.
Fam
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2016-03-10 1:54 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-08 8:24 [Qemu-devel] [PATCH v2 0/3] vmdk: Move descriptor buffers to heap Fam Zheng
2016-03-08 8:24 ` [Qemu-devel] [PATCH v2 1/3] vmdk: Switch to heap arrays for vmdk_write_cid Fam Zheng
2016-03-08 8:24 ` [Qemu-devel] [PATCH v2 2/3] vmdk: Switch to heap arrays for vmdk_read_cid Fam Zheng
2016-03-08 8:24 ` [Qemu-devel] [PATCH v2 3/3] vmdk: Switch to heap arrays for vmdk_parent_open Fam Zheng
2016-03-09 0:43 ` Fam Zheng
2016-03-09 9:50 ` Kevin Wolf
2016-03-10 1:53 ` Fam Zheng
2016-03-08 12:36 ` [Qemu-devel] [PATCH v2 0/3] vmdk: Move descriptor buffers to heap Paolo Bonzini
2016-03-08 13:18 ` Kevin Wolf
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).