qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: kwolf@redhat.com, mrezanin@redhat.com, qemu-devel@nongnu.org,
	qemu-block@nongnu.org
Subject: Re: [PATCH 3/9] block/vpc: Don't abuse the footer buffer for dynamic header
Date: Fri, 18 Dec 2020 14:52:54 +0100	[thread overview]
Message-ID: <871rfn9q6h.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <7de13ad8-ab0c-3350-7bd0-c8d0fd0c7403@redhat.com> (Max Reitz's message of "Fri, 18 Dec 2020 11:52:58 +0100")

Max Reitz <mreitz@redhat.com> writes:

> On 17.12.20 17:19, Markus Armbruster wrote:
>> create_dynamic_disk() takes a buffer holding the footer as first
>> argument.  It writes out the footer (512 bytes), then reuses the
>> buffer to initialize and write out the dynamic header (1024 bytes).
>> Works, because the caller passes a buffer that is large enough for
>> both purposes.  I hate that.
>> Use a separate buffer for the dynamic header, and adjust the
>> caller's
>> buffer.
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>   block/vpc.c | 22 ++++++++++++----------
>>   1 file changed, 12 insertions(+), 10 deletions(-)
>> diff --git a/block/vpc.c b/block/vpc.c
>> index d18ecc3da1..34186640ee 100644
>> --- a/block/vpc.c
>> +++ b/block/vpc.c
>> @@ -822,8 +822,9 @@ static int calculate_geometry(int64_t total_sectors, uint16_t *cyls,
>>   static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,
>>                                  int64_t total_sectors)
>>   {
>> +    uint8_t dyndisk_header_buf[1024];
>>       VHDDynDiskHeader *dyndisk_header =
>> -        (VHDDynDiskHeader *) buf;
>> +        (VHDDynDiskHeader *)dyndisk_header_buf;
>>       uint8_t bat_sector[512];
>>       size_t block_size, num_bat_entries;
>>       int i;
>> @@ -858,7 +859,7 @@ static int create_dynamic_disk(BlockBackend *blk, uint8_t *buf,
>>       }
>>         /* Prepare the Dynamic Disk Header */
>> -    memset(buf, 0, 1024);
>> +    memset(dyndisk_header_buf, 0, 1024);
>>         memcpy(dyndisk_header->magic, "cxsparse", 8);
>
> I’d prefer something like
>
> *dyndisk_header = (VHDDynDiskHeader){
>     ...
> };
>
> but that isn’t possible before patch 5.

Yes.  And afterwards, using an initializer would be even simpler, I
guess.

>                                          (And can be done on top now
> anyway, especially given that Kevin probably wants to send a pull 
> request today.)

Yes, would be good to get this wrapped before the break.

> [...]
>
>> @@ -972,8 +974,8 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts,
>>       BlockBackend *blk = NULL;
>>       BlockDriverState *bs = NULL;
>>   -    uint8_t buf[1024];
>> -    VHDFooter *footer = (VHDFooter *) buf;
>> +    uint8_t footer_buf[HEADER_SIZE];
>> +    VHDFooter *footer = (VHDFooter *)footer_buf;
>>       uint16_t cyls = 0;
>>       uint8_t heads = 0;
>>       uint8_t secs_per_cyl = 0;
>> @@ -1036,7 +1038,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateOptions *opts,
>>       }
>>         /* Prepare the Hard Disk Footer */
>> -    memset(buf, 0, 1024);
>> +    memset(footer_buf, 0, HEADER_SIZE);
>>         memcpy(footer->creator, "conectix", 8);
>
> Same here, except here it’s patch 7.
>
> Reviewed-by: Max Reitz <mreitz@redhat.com>

Thanks!



  reply	other threads:[~2020-12-18 13:59 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-17 16:19 [PATCH 0/9] block/vpc: Clean up some buffer abuse Markus Armbruster
2020-12-17 16:19 ` [PATCH 1/9] block/vpc: Make vpc_open() read the full dynamic header Markus Armbruster
2020-12-18 10:19   ` Max Reitz
2020-12-18 13:49     ` Markus Armbruster
2020-12-18 14:29       ` Max Reitz
2020-12-17 16:19 ` [PATCH 2/9] block/vpc: Don't abuse the footer buffer as BAT sector buffer Markus Armbruster
2020-12-18 10:30   ` Max Reitz
2020-12-17 16:19 ` [PATCH 3/9] block/vpc: Don't abuse the footer buffer for dynamic header Markus Armbruster
2020-12-18 10:52   ` Max Reitz
2020-12-18 13:52     ` Markus Armbruster [this message]
2020-12-17 16:19 ` [PATCH 4/9] block/vpc: Make vpc_checksum() take void * Markus Armbruster
2020-12-18 10:54   ` Max Reitz
2020-12-18 13:54     ` Markus Armbruster
2020-12-17 16:19 ` [PATCH 5/9] block/vpc: Pad VHDDynDiskHeader, replace uint8_t[] buffers Markus Armbruster
2020-12-18 11:04   ` Max Reitz
2020-12-17 16:20 ` [PATCH 6/9] block/vpc: Use sizeof() instead of 1024 for dynamic header size Markus Armbruster
2020-12-18 11:06   ` Max Reitz
2020-12-17 16:20 ` [PATCH 7/9] block/vpc: Pad VHDFooter, replace uint8_t[] buffers Markus Armbruster
2020-12-18 11:10   ` Max Reitz
2020-12-17 16:20 ` [PATCH 8/9] block/vpc: Pass footer buffers as VHDFooter * instead of uint8_t * Markus Armbruster
2020-12-18 11:12   ` Max Reitz
2020-12-17 16:20 ` [PATCH 9/9] block/vpc: Use sizeof() instead of HEADER_SIZE for footer size Markus Armbruster
2020-12-18 11:14   ` Max Reitz
2020-12-18 10:43 ` [PATCH 0/9] block/vpc: Clean up some buffer abuse Kevin Wolf

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=871rfn9q6h.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=mrezanin@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 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).