diff mbox series

[1/3] qcow2: Fix unaligned preallocated truncation

Message ID 20171009215533.12530-2-mreitz@redhat.com
State New
Headers show
Series qcow2: Fix preallocated truncation | expand

Commit Message

Max Reitz Oct. 9, 2017, 9:55 p.m. UTC
A qcow2 image file's length is not required to have a length that is a
multiple of the cluster size.  However, qcow2_refcount_area() expects an
aligned value for its @start_offset parameter, so we need to round
@old_file_size up to the next cluster boundary.

Reported-by: pingl <pingl@redhat.com>
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1414049
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/qcow2.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Max Reitz Oct. 9, 2017, 9:57 p.m. UTC | #1
On 2017-10-09 23:55, Max Reitz wrote:
> A qcow2 image file's length is not required to have a length that is a
> multiple of the cluster size.  However, qcow2_refcount_area() expects an
> aligned value for its @start_offset parameter, so we need to round
> @old_file_size up to the next cluster boundary.
> 
> Reported-by: pingl <pingl@redhat.com>
> Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1414049
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/qcow2.c | 1 +
>  1 file changed, 1 insertion(+)

Oops, forgot:

Cc: qemu-stable@nongnu.org

(2.10.1 is out by now, but you never know.)
Eric Blake Oct. 9, 2017, 10:25 p.m. UTC | #2
On 10/09/2017 04:55 PM, Max Reitz wrote:
> A qcow2 image file's length is not required to have a length that is a
> multiple of the cluster size.  However, qcow2_refcount_area() expects an
> aligned value for its @start_offset parameter, so we need to round
> @old_file_size up to the next cluster boundary.
> 
> Reported-by: pingl <pingl@redhat.com>

Should we use a real name? My autocomplete when adding cc suggests Ping Li.

(The upcoming git 2.15.0 adds my patch that auto-cc's anyone listed in
Reported-by, so we don't have to keep doing it manually:
https://github.com/git/git/commit/09ac6737 - but that doesn't help you
while you are still on 2.13.6)

> Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1414049
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/qcow2.c | 1 +
>  1 file changed, 1 insertion(+)
> 

Reviewed-by: Eric Blake <eblake@redhat.com>
Jeff Cody Oct. 9, 2017, 11:30 p.m. UTC | #3
On Mon, Oct 09, 2017 at 11:55:31PM +0200, Max Reitz wrote:
> A qcow2 image file's length is not required to have a length that is a
> multiple of the cluster size.  However, qcow2_refcount_area() expects an
> aligned value for its @start_offset parameter, so we need to round
> @old_file_size up to the next cluster boundary.
> 
> Reported-by: pingl <pingl@redhat.com>
> Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1414049
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
>  block/qcow2.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 2f6a8e1ff8..c3b312cdef 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -3193,6 +3193,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset,
>                               "Failed to inquire current file length");
>              return old_file_size;
>          }
> +        old_file_size = ROUND_UP(old_file_size, s->cluster_size);
>  
>          nb_new_data_clusters = DIV_ROUND_UP(offset - old_length,
>                                              s->cluster_size);
> -- 
> 2.13.6
> 
> 

Reviewed-by: Jeff Cody <jcody@redhat.com>
Max Reitz Oct. 11, 2017, 11:30 a.m. UTC | #4
On 2017-10-10 00:25, Eric Blake wrote:
> On 10/09/2017 04:55 PM, Max Reitz wrote:
>> A qcow2 image file's length is not required to have a length that is a
>> multiple of the cluster size.  However, qcow2_refcount_area() expects an
>> aligned value for its @start_offset parameter, so we need to round
>> @old_file_size up to the next cluster boundary.
>>
>> Reported-by: pingl <pingl@redhat.com>
> 
> Should we use a real name? My autocomplete when adding cc suggests Ping Li.

So does Red Hat's staff search. :-)

I thought I'd just take the name from the BZ, so I'd be safe -- pleading
the fact that real names are only required for S-o-bs.  But well, why not.

> (The upcoming git 2.15.0 adds my patch that auto-cc's anyone listed in
> Reported-by, so we don't have to keep doing it manually:
> https://github.com/git/git/commit/09ac6737 - but that doesn't help you
> while you are still on 2.13.6)

I like doing it manually because I don't like CC-ing only singular
patches of a series, though -- at least not without CC-ing the cover
letter, too.

So far I was lucky enough not to get into a situation where I didn't
want someone I wanted to CC on one patch not to see the whole series.
(In this case here I don't think Red Hat QA gains much from seeing the
upstream patch.)  If I get unlucky in the future, I guess I'll have to
extend my email sending script...

>> Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1414049
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>>  block/qcow2.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
> 
> Reviewed-by: Eric Blake <eblake@redhat.com>

Thanks!

Max
diff mbox series

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index 2f6a8e1ff8..c3b312cdef 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3193,6 +3193,7 @@  static int qcow2_truncate(BlockDriverState *bs, int64_t offset,
                              "Failed to inquire current file length");
             return old_file_size;
         }
+        old_file_size = ROUND_UP(old_file_size, s->cluster_size);
 
         nb_new_data_clusters = DIV_ROUND_UP(offset - old_length,
                                             s->cluster_size);