diff mbox

[RFC,5/5] qemu_aio_get used to clear all allocated buffer

Message ID 1311148624-5640-6-git-send-email-freddy77@gmail.com
State New
Headers show

Commit Message

Frediano Ziglio July 20, 2011, 7:57 a.m. UTC
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
---
 block/qcow.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Kevin Wolf July 20, 2011, 1:05 p.m. UTC | #1
Am 20.07.2011 09:57, schrieb Frediano Ziglio:
> Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
> ---
>  block/qcow.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/block/qcow.c b/block/qcow.c
> index 007fb57..8fd1ee5 100644
> --- a/block/qcow.c
> +++ b/block/qcow.c
> @@ -499,7 +499,6 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
>          int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
>          int is_write, QCowAIOCB *acb)
>  {
> -    memset(acb, 0, sizeof(*acb));
>      acb->bs = bs;
>      acb->sector_num = sector_num;
>      acb->qiov = qiov;
> @@ -509,6 +508,7 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
>          if (is_write)
>              qemu_iovec_to_buffer(qiov, acb->buf);
>      } else {
> +        acb->orig_buf = NULL;
>          acb->buf = (uint8_t *)qiov->iov->iov_base;
>      }
>      acb->nb_sectors = nb_sectors;

What does this fix? Removing the memset looks like changing code for no
obvious reason. Is there any state in acb that must survive qcow_aio_setup?

Kevin
Frediano Ziglio July 20, 2011, 1:45 p.m. UTC | #2
2011/7/20 Kevin Wolf <kwolf@redhat.com>:
> Am 20.07.2011 09:57, schrieb Frediano Ziglio:
>> Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
>> ---
>>  block/qcow.c |    2 +-
>>  1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/block/qcow.c b/block/qcow.c
>> index 007fb57..8fd1ee5 100644
>> --- a/block/qcow.c
>> +++ b/block/qcow.c
>> @@ -499,7 +499,6 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
>>          int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
>>          int is_write, QCowAIOCB *acb)
>>  {
>> -    memset(acb, 0, sizeof(*acb));
>>      acb->bs = bs;
>>      acb->sector_num = sector_num;
>>      acb->qiov = qiov;
>> @@ -509,6 +508,7 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
>>          if (is_write)
>>              qemu_iovec_to_buffer(qiov, acb->buf);
>>      } else {
>> +        acb->orig_buf = NULL;
>>          acb->buf = (uint8_t *)qiov->iov->iov_base;
>>      }
>>      acb->nb_sectors = nb_sectors;
>
> What does this fix? Removing the memset looks like changing code for no
> obvious reason. Is there any state in acb that must survive qcow_aio_setup?
>
> Kevin
>

No, this is not a fix, just an optimization, memset was used to clear
entire structure but all fields are set by qcow_aio_setup, only
orig_buf left.
The comment, I must admit is terrible! And it's mine! I'll rewrite all
comments, perhaps merge some commits and send all patches again.

Frediano
diff mbox

Patch

diff --git a/block/qcow.c b/block/qcow.c
index 007fb57..8fd1ee5 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -499,7 +499,6 @@  static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
         int is_write, QCowAIOCB *acb)
 {
-    memset(acb, 0, sizeof(*acb));
     acb->bs = bs;
     acb->sector_num = sector_num;
     acb->qiov = qiov;
@@ -509,6 +508,7 @@  static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs,
         if (is_write)
             qemu_iovec_to_buffer(qiov, acb->buf);
     } else {
+        acb->orig_buf = NULL;
         acb->buf = (uint8_t *)qiov->iov->iov_base;
     }
     acb->nb_sectors = nb_sectors;