qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Eric Blake <eblake@redhat.com>, qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/2] qcow2: Make size_to_clusters() return int64_t
Date: Tue, 8 Sep 2015 22:26:03 +0200	[thread overview]
Message-ID: <55EF445B.50108@redhat.com> (raw)
In-Reply-To: <55EF4387.9060503@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2089 bytes --]

On 08.09.2015 22:22, Eric Blake wrote:
> On 09/08/2015 02:09 PM, Max Reitz wrote:
>> Sadly, some images may have more clusters than what can be represented
>> using a plain int. We should be prepared for that case (in
>> qcow2_check_refcounts() we actually were trying to catch that case, but
>> since size_to_clusters() truncated the returned value, that check never
>> did anything useful).
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>  block/qcow2-cluster.c | 20 +++++++++++---------
>>  block/qcow2.h         |  2 +-
>>  2 files changed, 12 insertions(+), 10 deletions(-)
>>
>> diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
>> index 2975b83..a34f0b1 100644
>> --- a/block/qcow2-cluster.c
>> +++ b/block/qcow2-cluster.c
>> @@ -473,8 +473,8 @@ int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset,
>>      unsigned int l2_index;
>>      uint64_t l1_index, l2_offset, *l2_table;
>>      int l1_bits, c;
>> -    unsigned int index_in_cluster, nb_clusters;
>> -    uint64_t nb_available, nb_needed;
>> +    unsigned int index_in_cluster;
>> +    uint64_t nb_available, nb_needed, nb_clusters;
> 
> Most uses are storing the results unsigned...
> 
>>  
>> -static inline int size_to_clusters(BDRVQcow2State *s, int64_t size)
>> +static inline int64_t size_to_clusters(BDRVQcow2State *s, int64_t size)
>>  {
>>      return (size + (s->cluster_size - 1)) >> s->cluster_bits;
>>  }
> 
> ...and the function itself doesn't appear to intentionally return
> negative (unless size was passed in as negative, but then that may be
> accidental).  Should it just return uint64_t instead?

It won't matter in practice because we generally don't support any
offsets bigger than INT64_MAX anyway; the @size parameter has been an
int64_t all along, too.

If I have to respin for some reason (i.e. maintainer not willing to fix
up the comment in patch 2), I'll probably change the type, though.

> At any rate, I agree that 'int' is too small, so:
> Reviewed-by: Eric Blake <eblake@redhat.com>

Thanks!

Max


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

  reply	other threads:[~2015-09-08 20:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-08 20:09 [Qemu-devel] [PATCH 0/2] qcow2: Make size_to_clusters() return int64_t Max Reitz
2015-09-08 20:09 ` [Qemu-devel] [PATCH 1/2] " Max Reitz
2015-09-08 20:17   ` Max Reitz
2015-09-08 20:22   ` Eric Blake
2015-09-08 20:26     ` Max Reitz [this message]
2015-09-09  8:45   ` Kevin Wolf
2015-09-09 13:41     ` Max Reitz
2015-09-08 20:09 ` [Qemu-devel] [PATCH 2/2] iotests: Add test for checking large image files Max Reitz
2015-09-08 20:21   ` Eric Blake

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=55EF445B.50108@redhat.com \
    --to=mreitz@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@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).