qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH 1/3] qcow2: Fix unaligned preallocated truncation
Date: Mon,  9 Oct 2017 23:55:31 +0200	[thread overview]
Message-ID: <20171009215533.12530-2-mreitz@redhat.com> (raw)
In-Reply-To: <20171009215533.12530-1-mreitz@redhat.com>

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

  reply	other threads:[~2017-10-09 21:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-09 21:55 [Qemu-devel] [PATCH 0/3] qcow2: Fix preallocated truncation Max Reitz
2017-10-09 21:55 ` Max Reitz [this message]
2017-10-09 21:57   ` [Qemu-devel] [PATCH 1/3] qcow2: Fix unaligned " Max Reitz
2017-10-09 22:25   ` Eric Blake
2017-10-11 11:30     ` Max Reitz
2017-10-09 23:30   ` [Qemu-devel] [Qemu-block] " Jeff Cody
2017-10-09 21:55 ` [Qemu-devel] [PATCH 2/3] qcow2: Always execute preallocate() in a coroutine Max Reitz
2017-10-09 21:57   ` Max Reitz
2017-10-09 22:28   ` Eric Blake
2017-10-11 11:31     ` Max Reitz
2017-10-09 23:30   ` [Qemu-devel] [Qemu-block] " Jeff Cody
2017-10-09 21:55 ` [Qemu-devel] [PATCH 3/3] iotests: Add cluster_size=64k to 125 Max Reitz
2017-10-09 22:32   ` Eric Blake
2017-10-09 23:30   ` [Qemu-devel] [Qemu-block] " Jeff Cody
2017-10-11 13:23 ` [Qemu-devel] [PATCH 0/3] qcow2: Fix preallocated truncation Max Reitz
2017-10-11 15:05 ` Stefan Hajnoczi

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=20171009215533.12530-2-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /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).