* [Qemu-devel] [PATCH] qcow2: Use pread for inactive L1 in overlap check
@ 2013-10-09 8:42 Max Reitz
2013-10-09 9:43 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: Max Reitz @ 2013-10-09 8:42 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Max Reitz
Currently, qcow2_check_metadata_overlap uses bdrv_read to read inactive
L1 tables from disk. The number of sectors to read is calculated through
a truncating integer division, therefore, if the L1 table size is not a
multiple of the sector size, the final entries will not be read and
their entries in memory remain undefined (from the g_malloc).
Using bdrv_pread fixes this.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/qcow2-refcount.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 2d67885..4cb9c23 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -1719,12 +1719,11 @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int chk, int64_t offset,
for (i = 0; i < s->nb_snapshots; i++) {
uint64_t l1_ofs = s->snapshots[i].l1_table_offset;
uint32_t l1_sz = s->snapshots[i].l1_size;
- uint64_t *l1 = g_malloc(l1_sz * sizeof(uint64_t));
+ uint64_t l1_sz2 = l1_sz * sizeof(uint64_t);
+ uint64_t *l1 = g_malloc(l1_sz2);
int ret;
- ret = bdrv_read(bs->file, l1_ofs / BDRV_SECTOR_SIZE, (uint8_t *)l1,
- l1_sz * sizeof(uint64_t) / BDRV_SECTOR_SIZE);
-
+ ret = bdrv_pread(bs->file, l1_ofs, l1, l1_sz2);
if (ret < 0) {
g_free(l1);
return ret;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] qcow2: Use pread for inactive L1 in overlap check
2013-10-09 8:42 [Qemu-devel] [PATCH] qcow2: Use pread for inactive L1 in overlap check Max Reitz
@ 2013-10-09 9:43 ` Kevin Wolf
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2013-10-09 9:43 UTC (permalink / raw)
To: Max Reitz; +Cc: qemu-devel, Stefan Hajnoczi
Am 09.10.2013 um 10:42 hat Max Reitz geschrieben:
> Currently, qcow2_check_metadata_overlap uses bdrv_read to read inactive
> L1 tables from disk. The number of sectors to read is calculated through
> a truncating integer division, therefore, if the L1 table size is not a
> multiple of the sector size, the final entries will not be read and
> their entries in memory remain undefined (from the g_malloc).
> Using bdrv_pread fixes this.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
Thanks, applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-10-09 9:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-09 8:42 [Qemu-devel] [PATCH] qcow2: Use pread for inactive L1 in overlap check Max Reitz
2013-10-09 9:43 ` Kevin Wolf
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).